2009-04-11 H.J. Lu <hongjiu.lu@intel.com>
[binutils.git] / bfd / elf32-arm.c
bloba47d02c020df4b666669b448dc90a1c351bbc749
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf-vxworks.h"
28 #include "elf/arm.h"
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
38 ((HTAB)->use_rel \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
45 ((HTAB)->use_rel \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
52 ((HTAB)->use_rel \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
62 static struct elf_backend_data elf32_arm_vxworks_bed;
64 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
66 in that slot. */
68 static reloc_howto_type elf32_arm_howto_table_1[] =
70 /* No relocation. */
71 HOWTO (R_ARM_NONE, /* type */
72 0, /* rightshift */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
74 0, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_dont,/* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE, /* partial_inplace */
81 0, /* src_mask */
82 0, /* dst_mask */
83 FALSE), /* pcrel_offset */
85 HOWTO (R_ARM_PC24, /* type */
86 2, /* rightshift */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
88 24, /* bitsize */
89 TRUE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_signed,/* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE), /* pcrel_offset */
99 /* 32 bit absolute */
100 HOWTO (R_ARM_ABS32, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield,/* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32, /* type */
116 0, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 32, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield,/* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
130 HOWTO (R_ARM_LDR_PC_G0, /* type */
131 0, /* rightshift */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
133 32, /* bitsize */
134 TRUE, /* pc_relative */
135 0, /* bitpos */
136 complain_overflow_dont,/* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_ARM_LDR_PC_G0", /* name */
139 FALSE, /* partial_inplace */
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
149 FALSE, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield,/* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12, /* type */
161 0, /* rightshift */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
163 12, /* bitsize */
164 FALSE, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE, /* partial_inplace */
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
172 FALSE), /* pcrel_offset */
174 HOWTO (R_ARM_THM_ABS5, /* type */
175 6, /* rightshift */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
177 5, /* bitsize */
178 FALSE, /* pc_relative */
179 0, /* bitpos */
180 complain_overflow_bitfield,/* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE), /* pcrel_offset */
188 /* 8 bit absolute */
189 HOWTO (R_ARM_ABS8, /* type */
190 0, /* rightshift */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
192 8, /* bitsize */
193 FALSE, /* pc_relative */
194 0, /* bitpos */
195 complain_overflow_bitfield,/* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE), /* pcrel_offset */
203 HOWTO (R_ARM_SBREL32, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 32, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont,/* complain_on_overflow */
210 bfd_elf_generic_reloc, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
217 HOWTO (R_ARM_THM_CALL, /* type */
218 1, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
220 25, /* bitsize */
221 TRUE, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed,/* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
225 "R_ARM_THM_CALL", /* name */
226 FALSE, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE), /* pcrel_offset */
231 HOWTO (R_ARM_THM_PC8, /* type */
232 1, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
235 TRUE, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_signed,/* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE), /* pcrel_offset */
245 HOWTO (R_ARM_BREL_ADJ, /* type */
246 1, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
248 32, /* bitsize */
249 FALSE, /* pc_relative */
250 0, /* bitpos */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_ARM_BREL_ADJ", /* name */
254 FALSE, /* partial_inplace */
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE), /* pcrel_offset */
259 HOWTO (R_ARM_SWI24, /* type */
260 0, /* rightshift */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
262 0, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
265 complain_overflow_signed,/* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 HOWTO (R_ARM_THM_SWI8, /* type */
274 0, /* rightshift */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
276 0, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_signed,/* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE), /* pcrel_offset */
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25, /* type */
289 2, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 25, /* bitsize */
292 TRUE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_signed,/* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE), /* pcrel_offset */
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22, /* type */
304 2, /* rightshift */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
306 22, /* bitsize */
307 TRUE, /* pc_relative */
308 0, /* bitpos */
309 complain_overflow_signed,/* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE), /* pcrel_offset */
317 /* Dynamic TLS relocations. */
319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 32, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield,/* complain_on_overflow */
326 bfd_elf_generic_reloc, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield,/* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
347 HOWTO (R_ARM_TLS_TPOFF32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield,/* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
361 /* Relocs used in ARM Linux */
363 HOWTO (R_ARM_COPY, /* type */
364 0, /* rightshift */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
366 32, /* bitsize */
367 FALSE, /* pc_relative */
368 0, /* bitpos */
369 complain_overflow_bitfield,/* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
377 HOWTO (R_ARM_GLOB_DAT, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 FALSE, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield,/* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
391 HOWTO (R_ARM_JUMP_SLOT, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 32, /* bitsize */
395 FALSE, /* pc_relative */
396 0, /* bitpos */
397 complain_overflow_bitfield,/* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE), /* pcrel_offset */
405 HOWTO (R_ARM_RELATIVE, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 32, /* bitsize */
409 FALSE, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield,/* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE), /* pcrel_offset */
419 HOWTO (R_ARM_GOTOFF32, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 32, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_bitfield,/* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
427 "R_ARM_GOTOFF32", /* name */
428 TRUE, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
433 HOWTO (R_ARM_GOTPC, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 32, /* bitsize */
437 TRUE, /* pc_relative */
438 0, /* bitpos */
439 complain_overflow_bitfield,/* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
447 HOWTO (R_ARM_GOT32, /* type */
448 0, /* rightshift */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
450 32, /* bitsize */
451 FALSE, /* pc_relative */
452 0, /* bitpos */
453 complain_overflow_bitfield,/* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
461 HOWTO (R_ARM_PLT32, /* type */
462 2, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
464 24, /* bitsize */
465 TRUE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_bitfield,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_ARM_PLT32", /* name */
470 FALSE, /* partial_inplace */
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE), /* pcrel_offset */
475 HOWTO (R_ARM_CALL, /* type */
476 2, /* rightshift */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
478 24, /* bitsize */
479 TRUE, /* pc_relative */
480 0, /* bitpos */
481 complain_overflow_signed,/* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE), /* pcrel_offset */
489 HOWTO (R_ARM_JUMP24, /* type */
490 2, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 24, /* bitsize */
493 TRUE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_signed,/* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE), /* pcrel_offset */
503 HOWTO (R_ARM_THM_JUMP24, /* type */
504 1, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 24, /* bitsize */
507 TRUE, /* pc_relative */
508 0, /* bitpos */
509 complain_overflow_signed,/* complain_on_overflow */
510 bfd_elf_generic_reloc, /* special_function */
511 "R_ARM_THM_JUMP24", /* name */
512 FALSE, /* partial_inplace */
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE), /* pcrel_offset */
517 HOWTO (R_ARM_BASE_ABS, /* type */
518 0, /* rightshift */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
521 FALSE, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_dont,/* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_ARM_BASE_ABS", /* name */
526 FALSE, /* partial_inplace */
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
529 FALSE), /* pcrel_offset */
531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
532 0, /* rightshift */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
534 12, /* bitsize */
535 TRUE, /* pc_relative */
536 0, /* bitpos */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE), /* pcrel_offset */
545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
546 0, /* rightshift */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
548 12, /* bitsize */
549 TRUE, /* pc_relative */
550 8, /* bitpos */
551 complain_overflow_dont,/* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE), /* pcrel_offset */
559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
560 0, /* rightshift */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
562 12, /* bitsize */
563 TRUE, /* pc_relative */
564 16, /* bitpos */
565 complain_overflow_dont,/* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE), /* pcrel_offset */
573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
574 0, /* rightshift */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
576 12, /* bitsize */
577 FALSE, /* pc_relative */
578 0, /* bitpos */
579 complain_overflow_dont,/* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE), /* pcrel_offset */
587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
588 0, /* rightshift */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
590 8, /* bitsize */
591 FALSE, /* pc_relative */
592 12, /* bitpos */
593 complain_overflow_dont,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE), /* pcrel_offset */
601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
602 0, /* rightshift */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
604 8, /* bitsize */
605 FALSE, /* pc_relative */
606 20, /* bitpos */
607 complain_overflow_dont,/* complain_on_overflow */
608 bfd_elf_generic_reloc, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE), /* pcrel_offset */
615 HOWTO (R_ARM_TARGET1, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 FALSE, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_dont,/* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE), /* pcrel_offset */
629 HOWTO (R_ARM_ROSEGREL32, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 32, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_dont,/* complain_on_overflow */
636 bfd_elf_generic_reloc, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
643 HOWTO (R_ARM_V4BX, /* type */
644 0, /* rightshift */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
646 32, /* bitsize */
647 FALSE, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_dont,/* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 HOWTO (R_ARM_TARGET2, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_signed,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE), /* pcrel_offset */
671 HOWTO (R_ARM_PREL31, /* type */
672 0, /* rightshift */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
674 31, /* bitsize */
675 TRUE, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_signed,/* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE), /* pcrel_offset */
685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
686 0, /* rightshift */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
688 16, /* bitsize */
689 FALSE, /* pc_relative */
690 0, /* bitpos */
691 complain_overflow_dont,/* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE, /* partial_inplace */
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
697 FALSE), /* pcrel_offset */
699 HOWTO (R_ARM_MOVT_ABS, /* type */
700 0, /* rightshift */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 FALSE, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_bitfield,/* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE, /* partial_inplace */
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
711 FALSE), /* pcrel_offset */
713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
714 0, /* rightshift */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
716 16, /* bitsize */
717 TRUE, /* pc_relative */
718 0, /* bitpos */
719 complain_overflow_dont,/* complain_on_overflow */
720 bfd_elf_generic_reloc, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE, /* partial_inplace */
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
725 TRUE), /* pcrel_offset */
727 HOWTO (R_ARM_MOVT_PREL, /* type */
728 0, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE, /* partial_inplace */
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
739 TRUE), /* pcrel_offset */
741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
742 0, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 FALSE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont,/* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE), /* pcrel_offset */
755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 FALSE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield,/* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE), /* pcrel_offset */
769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
770 0, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_dont,/* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE), /* pcrel_offset */
783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
784 0, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_bitfield,/* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE), /* pcrel_offset */
797 HOWTO (R_ARM_THM_JUMP19, /* type */
798 1, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 19, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_signed,/* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE), /* pcrel_offset */
811 HOWTO (R_ARM_THM_JUMP6, /* type */
812 1, /* rightshift */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
814 6, /* bitsize */
815 TRUE, /* pc_relative */
816 0, /* bitpos */
817 complain_overflow_unsigned,/* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE), /* pcrel_offset */
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
827 versa. */
828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
829 0, /* rightshift */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
831 13, /* bitsize */
832 TRUE, /* pc_relative */
833 0, /* bitpos */
834 complain_overflow_dont,/* complain_on_overflow */
835 bfd_elf_generic_reloc, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE, /* partial_inplace */
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
840 TRUE), /* pcrel_offset */
842 HOWTO (R_ARM_THM_PC12, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 13, /* bitsize */
846 TRUE, /* pc_relative */
847 0, /* bitpos */
848 complain_overflow_dont,/* complain_on_overflow */
849 bfd_elf_generic_reloc, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE, /* partial_inplace */
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
854 TRUE), /* pcrel_offset */
856 HOWTO (R_ARM_ABS32_NOI, /* type */
857 0, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 32, /* bitsize */
860 FALSE, /* pc_relative */
861 0, /* bitpos */
862 complain_overflow_dont,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 HOWTO (R_ARM_REL32_NOI, /* type */
871 0, /* rightshift */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
873 32, /* bitsize */
874 TRUE, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont,/* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* Group relocations. */
886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
887 0, /* rightshift */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
889 32, /* bitsize */
890 TRUE, /* pc_relative */
891 0, /* bitpos */
892 complain_overflow_dont,/* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE), /* pcrel_offset */
900 HOWTO (R_ARM_ALU_PC_G0, /* type */
901 0, /* rightshift */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
903 32, /* bitsize */
904 TRUE, /* pc_relative */
905 0, /* bitpos */
906 complain_overflow_dont,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE), /* pcrel_offset */
914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 32, /* bitsize */
918 TRUE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont,/* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE), /* pcrel_offset */
928 HOWTO (R_ARM_ALU_PC_G1, /* type */
929 0, /* rightshift */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
931 32, /* bitsize */
932 TRUE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_dont,/* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE), /* pcrel_offset */
942 HOWTO (R_ARM_ALU_PC_G2, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 32, /* bitsize */
946 TRUE, /* pc_relative */
947 0, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE), /* pcrel_offset */
956 HOWTO (R_ARM_LDR_PC_G1, /* type */
957 0, /* rightshift */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
959 32, /* bitsize */
960 TRUE, /* pc_relative */
961 0, /* bitpos */
962 complain_overflow_dont,/* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE), /* pcrel_offset */
970 HOWTO (R_ARM_LDR_PC_G2, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 32, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont,/* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
984 HOWTO (R_ARM_LDRS_PC_G0, /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 32, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont,/* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
998 HOWTO (R_ARM_LDRS_PC_G1, /* type */
999 0, /* rightshift */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 32, /* bitsize */
1002 TRUE, /* pc_relative */
1003 0, /* bitpos */
1004 complain_overflow_dont,/* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE), /* pcrel_offset */
1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1013 0, /* rightshift */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 32, /* bitsize */
1016 TRUE, /* pc_relative */
1017 0, /* bitpos */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1026 HOWTO (R_ARM_LDC_PC_G0, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 32, /* bitsize */
1030 TRUE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE), /* pcrel_offset */
1040 HOWTO (R_ARM_LDC_PC_G1, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 32, /* bitsize */
1044 TRUE, /* pc_relative */
1045 0, /* bitpos */
1046 complain_overflow_dont,/* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE), /* pcrel_offset */
1054 HOWTO (R_ARM_LDC_PC_G2, /* type */
1055 0, /* rightshift */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 32, /* bitsize */
1058 TRUE, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont,/* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE), /* pcrel_offset */
1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 TRUE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont,/* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE), /* pcrel_offset */
1082 HOWTO (R_ARM_ALU_SB_G0, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 TRUE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE), /* pcrel_offset */
1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1097 0, /* rightshift */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 32, /* bitsize */
1100 TRUE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_dont,/* complain_on_overflow */
1103 bfd_elf_generic_reloc, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE), /* pcrel_offset */
1110 HOWTO (R_ARM_ALU_SB_G1, /* type */
1111 0, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 32, /* bitsize */
1114 TRUE, /* pc_relative */
1115 0, /* bitpos */
1116 complain_overflow_dont,/* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE), /* pcrel_offset */
1124 HOWTO (R_ARM_ALU_SB_G2, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 32, /* bitsize */
1128 TRUE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont,/* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE), /* pcrel_offset */
1138 HOWTO (R_ARM_LDR_SB_G0, /* type */
1139 0, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 32, /* bitsize */
1142 TRUE, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont,/* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE), /* pcrel_offset */
1152 HOWTO (R_ARM_LDR_SB_G1, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 32, /* bitsize */
1156 TRUE, /* pc_relative */
1157 0, /* bitpos */
1158 complain_overflow_dont,/* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE), /* pcrel_offset */
1166 HOWTO (R_ARM_LDR_SB_G2, /* type */
1167 0, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 32, /* bitsize */
1170 TRUE, /* pc_relative */
1171 0, /* bitpos */
1172 complain_overflow_dont,/* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE), /* pcrel_offset */
1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1181 0, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 32, /* bitsize */
1184 TRUE, /* pc_relative */
1185 0, /* bitpos */
1186 complain_overflow_dont,/* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE), /* pcrel_offset */
1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1195 0, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 32, /* bitsize */
1198 TRUE, /* pc_relative */
1199 0, /* bitpos */
1200 complain_overflow_dont,/* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1209 0, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 32, /* bitsize */
1212 TRUE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont,/* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1222 HOWTO (R_ARM_LDC_SB_G0, /* type */
1223 0, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 32, /* bitsize */
1226 TRUE, /* pc_relative */
1227 0, /* bitpos */
1228 complain_overflow_dont,/* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1236 HOWTO (R_ARM_LDC_SB_G1, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 32, /* bitsize */
1240 TRUE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE), /* pcrel_offset */
1250 HOWTO (R_ARM_LDC_SB_G2, /* type */
1251 0, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 32, /* bitsize */
1254 TRUE, /* pc_relative */
1255 0, /* bitpos */
1256 complain_overflow_dont,/* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1264 /* End of group relocations. */
1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1280 HOWTO (R_ARM_MOVT_BREL, /* type */
1281 0, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 16, /* bitsize */
1284 FALSE, /* pc_relative */
1285 0, /* bitpos */
1286 complain_overflow_bitfield,/* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1294 HOWTO (R_ARM_MOVW_BREL, /* type */
1295 0, /* rightshift */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 16, /* bitsize */
1298 FALSE, /* pc_relative */
1299 0, /* bitpos */
1300 complain_overflow_dont,/* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 16, /* bitsize */
1312 FALSE, /* pc_relative */
1313 0, /* bitpos */
1314 complain_overflow_dont,/* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1323 0, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
1328 complain_overflow_bitfield,/* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1337 0, /* rightshift */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 16, /* bitsize */
1340 FALSE, /* pc_relative */
1341 0, /* bitpos */
1342 complain_overflow_dont,/* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1350 EMPTY_HOWTO (90), /* Unallocated. */
1351 EMPTY_HOWTO (91),
1352 EMPTY_HOWTO (92),
1353 EMPTY_HOWTO (93),
1355 HOWTO (R_ARM_PLT32_ABS, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 32, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_dont,/* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 HOWTO (R_ARM_GOT_ABS, /* type */
1370 0, /* rightshift */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 32, /* bitsize */
1373 FALSE, /* pc_relative */
1374 0, /* bitpos */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1383 HOWTO (R_ARM_GOT_PREL, /* type */
1384 0, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 32, /* bitsize */
1387 TRUE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE), /* pcrel_offset */
1397 HOWTO (R_ARM_GOT_BREL12, /* type */
1398 0, /* rightshift */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 12, /* bitsize */
1401 FALSE, /* pc_relative */
1402 0, /* bitpos */
1403 complain_overflow_bitfield,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1411 HOWTO (R_ARM_GOTOFF12, /* type */
1412 0, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 12, /* bitsize */
1415 FALSE, /* pc_relative */
1416 0, /* bitpos */
1417 complain_overflow_bitfield,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1429 0, /* rightshift */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
1431 0, /* bitsize */
1432 FALSE, /* pc_relative */
1433 0, /* bitpos */
1434 complain_overflow_dont, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE, /* partial_inplace */
1438 0, /* src_mask */
1439 0, /* dst_mask */
1440 FALSE), /* pcrel_offset */
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1444 0, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1446 0, /* bitsize */
1447 FALSE, /* pc_relative */
1448 0, /* bitpos */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 NULL, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE, /* partial_inplace */
1453 0, /* src_mask */
1454 0, /* dst_mask */
1455 FALSE), /* pcrel_offset */
1457 HOWTO (R_ARM_THM_JUMP11, /* type */
1458 1, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 11, /* bitsize */
1461 TRUE, /* pc_relative */
1462 0, /* bitpos */
1463 complain_overflow_signed, /* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE), /* pcrel_offset */
1471 HOWTO (R_ARM_THM_JUMP8, /* type */
1472 1, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 8, /* bitsize */
1475 TRUE, /* pc_relative */
1476 0, /* bitpos */
1477 complain_overflow_signed, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE), /* pcrel_offset */
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32, /* type */
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 32, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_bitfield,/* complain_on_overflow */
1493 NULL, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
1495 TRUE, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1500 HOWTO (R_ARM_TLS_LDM32, /* type */
1501 0, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 32, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_bitfield,/* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
1512 FALSE), /* pcrel_offset */
1514 HOWTO (R_ARM_TLS_LDO32, /* type */
1515 0, /* rightshift */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 32, /* bitsize */
1518 FALSE, /* pc_relative */
1519 0, /* bitpos */
1520 complain_overflow_bitfield,/* complain_on_overflow */
1521 bfd_elf_generic_reloc, /* special_function */
1522 "R_ARM_TLS_LDO32", /* name */
1523 TRUE, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
1526 FALSE), /* pcrel_offset */
1528 HOWTO (R_ARM_TLS_IE32, /* type */
1529 0, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 32, /* bitsize */
1532 FALSE, /* pc_relative */
1533 0, /* bitpos */
1534 complain_overflow_bitfield,/* complain_on_overflow */
1535 NULL, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
1540 FALSE), /* pcrel_offset */
1542 HOWTO (R_ARM_TLS_LE32, /* type */
1543 0, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 32, /* bitsize */
1546 FALSE, /* pc_relative */
1547 0, /* bitpos */
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
1556 HOWTO (R_ARM_TLS_LDO12, /* type */
1557 0, /* rightshift */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 12, /* bitsize */
1560 FALSE, /* pc_relative */
1561 0, /* bitpos */
1562 complain_overflow_bitfield,/* complain_on_overflow */
1563 bfd_elf_generic_reloc, /* special_function */
1564 "R_ARM_TLS_LDO12", /* name */
1565 FALSE, /* partial_inplace */
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1570 HOWTO (R_ARM_TLS_LE12, /* type */
1571 0, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 12, /* bitsize */
1574 FALSE, /* pc_relative */
1575 0, /* bitpos */
1576 complain_overflow_bitfield,/* complain_on_overflow */
1577 bfd_elf_generic_reloc, /* special_function */
1578 "R_ARM_TLS_LE12", /* name */
1579 FALSE, /* partial_inplace */
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
1584 HOWTO (R_ARM_TLS_IE12GP, /* type */
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
1589 0, /* bitpos */
1590 complain_overflow_bitfield,/* complain_on_overflow */
1591 bfd_elf_generic_reloc, /* special_function */
1592 "R_ARM_TLS_IE12GP", /* name */
1593 FALSE, /* partial_inplace */
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1599 /* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
1603 249-255 extended, currently unused, relocations: */
1605 static reloc_howto_type elf32_arm_howto_table_2[4] =
1607 HOWTO (R_ARM_RREL32, /* type */
1608 0, /* rightshift */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1610 0, /* bitsize */
1611 FALSE, /* pc_relative */
1612 0, /* bitpos */
1613 complain_overflow_dont,/* complain_on_overflow */
1614 bfd_elf_generic_reloc, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE, /* partial_inplace */
1617 0, /* src_mask */
1618 0, /* dst_mask */
1619 FALSE), /* pcrel_offset */
1621 HOWTO (R_ARM_RABS32, /* type */
1622 0, /* rightshift */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1624 0, /* bitsize */
1625 FALSE, /* pc_relative */
1626 0, /* bitpos */
1627 complain_overflow_dont,/* complain_on_overflow */
1628 bfd_elf_generic_reloc, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE, /* partial_inplace */
1631 0, /* src_mask */
1632 0, /* dst_mask */
1633 FALSE), /* pcrel_offset */
1635 HOWTO (R_ARM_RPC24, /* type */
1636 0, /* rightshift */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1638 0, /* bitsize */
1639 FALSE, /* pc_relative */
1640 0, /* bitpos */
1641 complain_overflow_dont,/* complain_on_overflow */
1642 bfd_elf_generic_reloc, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE, /* partial_inplace */
1645 0, /* src_mask */
1646 0, /* dst_mask */
1647 FALSE), /* pcrel_offset */
1649 HOWTO (R_ARM_RBASE, /* type */
1650 0, /* rightshift */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1652 0, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_dont,/* complain_on_overflow */
1656 bfd_elf_generic_reloc, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0, /* dst_mask */
1661 FALSE) /* pcrel_offset */
1664 static reloc_howto_type *
1665 elf32_arm_howto_from_type (unsigned int r_type)
1667 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1668 return &elf32_arm_howto_table_1[r_type];
1670 if (r_type >= R_ARM_RREL32
1671 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1674 return NULL;
1677 static void
1678 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1679 Elf_Internal_Rela * elf_reloc)
1681 unsigned int r_type;
1683 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1687 struct elf32_arm_reloc_map
1689 bfd_reloc_code_real_type bfd_reloc_val;
1690 unsigned char elf_reloc_val;
1693 /* All entries in this list must also be present in elf32_arm_howto_table. */
1694 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1696 {BFD_RELOC_NONE, R_ARM_NONE},
1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1702 {BFD_RELOC_32, R_ARM_ABS32},
1703 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1704 {BFD_RELOC_8, R_ARM_ABS8},
1705 {BFD_RELOC_16, R_ARM_ABS16},
1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1773 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
1776 static reloc_howto_type *
1777 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1778 bfd_reloc_code_real_type code)
1780 unsigned int i;
1782 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
1783 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1784 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1786 return NULL;
1789 static reloc_howto_type *
1790 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1791 const char *r_name)
1793 unsigned int i;
1795 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1796 if (elf32_arm_howto_table_1[i].name != NULL
1797 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1798 return &elf32_arm_howto_table_1[i];
1800 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1801 if (elf32_arm_howto_table_2[i].name != NULL
1802 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1803 return &elf32_arm_howto_table_2[i];
1805 return NULL;
1808 /* Support for core dump NOTE sections. */
1810 static bfd_boolean
1811 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1813 int offset;
1814 size_t size;
1816 switch (note->descsz)
1818 default:
1819 return FALSE;
1821 case 148: /* Linux/ARM 32-bit. */
1822 /* pr_cursig */
1823 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1825 /* pr_pid */
1826 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1828 /* pr_reg */
1829 offset = 72;
1830 size = 72;
1832 break;
1835 /* Make a ".reg/999" section. */
1836 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1837 size, note->descpos + offset);
1840 static bfd_boolean
1841 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1843 switch (note->descsz)
1845 default:
1846 return FALSE;
1848 case 124: /* Linux/ARM elf_prpsinfo. */
1849 elf_tdata (abfd)->core_program
1850 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1851 elf_tdata (abfd)->core_command
1852 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1855 /* Note that for some reason, a spurious space is tacked
1856 onto the end of the args in some (at least one anyway)
1857 implementations, so strip it off if it exists. */
1859 char *command = elf_tdata (abfd)->core_command;
1860 int n = strlen (command);
1862 if (0 < n && command[n - 1] == ' ')
1863 command[n - 1] = '\0';
1866 return TRUE;
1869 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1870 #define TARGET_LITTLE_NAME "elf32-littlearm"
1871 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1872 #define TARGET_BIG_NAME "elf32-bigarm"
1874 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1875 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1877 typedef unsigned long int insn32;
1878 typedef unsigned short int insn16;
1880 /* In lieu of proper flags, assume all EABIv4 or later objects are
1881 interworkable. */
1882 #define INTERWORK_FLAG(abfd) \
1883 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1884 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1886 /* The linker script knows the section names for placement.
1887 The entry_names are used to do simple name mangling on the stubs.
1888 Given a function name, and its type, the stub can be found. The
1889 name can be changed. The only requirement is the %s be present. */
1890 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1891 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1893 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1894 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1896 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1897 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1899 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1900 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1902 #define STUB_ENTRY_NAME "__%s_veneer"
1904 /* The name of the dynamic interpreter. This is put in the .interp
1905 section. */
1906 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1908 #ifdef FOUR_WORD_PLT
1910 /* The first entry in a procedure linkage table looks like
1911 this. It is set up so that any shared library function that is
1912 called before the relocation has been set up calls the dynamic
1913 linker first. */
1914 static const bfd_vma elf32_arm_plt0_entry [] =
1916 0xe52de004, /* str lr, [sp, #-4]! */
1917 0xe59fe010, /* ldr lr, [pc, #16] */
1918 0xe08fe00e, /* add lr, pc, lr */
1919 0xe5bef008, /* ldr pc, [lr, #8]! */
1922 /* Subsequent entries in a procedure linkage table look like
1923 this. */
1924 static const bfd_vma elf32_arm_plt_entry [] =
1926 0xe28fc600, /* add ip, pc, #NN */
1927 0xe28cca00, /* add ip, ip, #NN */
1928 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1929 0x00000000, /* unused */
1932 #else
1934 /* The first entry in a procedure linkage table looks like
1935 this. It is set up so that any shared library function that is
1936 called before the relocation has been set up calls the dynamic
1937 linker first. */
1938 static const bfd_vma elf32_arm_plt0_entry [] =
1940 0xe52de004, /* str lr, [sp, #-4]! */
1941 0xe59fe004, /* ldr lr, [pc, #4] */
1942 0xe08fe00e, /* add lr, pc, lr */
1943 0xe5bef008, /* ldr pc, [lr, #8]! */
1944 0x00000000, /* &GOT[0] - . */
1947 /* Subsequent entries in a procedure linkage table look like
1948 this. */
1949 static const bfd_vma elf32_arm_plt_entry [] =
1951 0xe28fc600, /* add ip, pc, #0xNN00000 */
1952 0xe28cca00, /* add ip, ip, #0xNN000 */
1953 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1956 #endif
1958 /* The format of the first entry in the procedure linkage table
1959 for a VxWorks executable. */
1960 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1962 0xe52dc008, /* str ip,[sp,#-8]! */
1963 0xe59fc000, /* ldr ip,[pc] */
1964 0xe59cf008, /* ldr pc,[ip,#8] */
1965 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1968 /* The format of subsequent entries in a VxWorks executable. */
1969 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1971 0xe59fc000, /* ldr ip,[pc] */
1972 0xe59cf000, /* ldr pc,[ip] */
1973 0x00000000, /* .long @got */
1974 0xe59fc000, /* ldr ip,[pc] */
1975 0xea000000, /* b _PLT */
1976 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1979 /* The format of entries in a VxWorks shared library. */
1980 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xe79cf009, /* ldr pc,[ip,r9] */
1984 0x00000000, /* .long @got */
1985 0xe59fc000, /* ldr ip,[pc] */
1986 0xe599f008, /* ldr pc,[r9,#8] */
1987 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1990 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1991 #define PLT_THUMB_STUB_SIZE 4
1992 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1994 0x4778, /* bx pc */
1995 0x46c0 /* nop */
1998 /* The entries in a PLT when using a DLL-based target with multiple
1999 address spaces. */
2000 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2002 0xe51ff004, /* ldr pc, [pc, #-4] */
2003 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2006 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2007 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2008 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2009 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2010 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2011 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2013 enum stub_insn_type
2015 THUMB16_TYPE = 1,
2016 THUMB32_TYPE,
2017 ARM_TYPE,
2018 DATA_TYPE
2021 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2022 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2023 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2024 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2025 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2027 typedef struct
2029 bfd_vma data;
2030 enum stub_insn_type type;
2031 unsigned int r_type;
2032 int reloc_addend;
2033 } insn_sequence;
2035 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2036 to reach the stub if necessary. */
2037 static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
2039 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2040 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2043 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2044 available. */
2045 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2047 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2048 ARM_INSN(0xe12fff1c), /* bx ip */
2049 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2052 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2053 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
2055 THUMB16_INSN(0xb401), /* push {r0} */
2056 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2057 THUMB16_INSN(0x4684), /* mov ip, r0 */
2058 THUMB16_INSN(0xbc01), /* pop {r0} */
2059 THUMB16_INSN(0x4760), /* bx ip */
2060 THUMB16_INSN(0xbf00), /* nop */
2061 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2064 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2065 allowed. */
2066 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb[] =
2068 THUMB16_INSN(0x4778), /* bx pc */
2069 THUMB16_INSN(0x46c0), /* nop */
2070 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2071 ARM_INSN(0xe12fff1c), /* bx ip */
2072 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2075 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2076 available. */
2077 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2079 THUMB16_INSN(0x4778), /* bx pc */
2080 THUMB16_INSN(0x46c0), /* nop */
2081 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2082 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2085 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2086 one, when the destination is close enough. */
2087 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2089 THUMB16_INSN(0x4778), /* bx pc */
2090 THUMB16_INSN(0x46c0), /* nop */
2091 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2094 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2095 blx to reach the stub if necessary. */
2096 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
2098 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2099 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2100 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2103 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2104 blx to reach the stub if necessary. We can not add into pc;
2105 it is not guaranteed to mode switch (different in ARMv6 and
2106 ARMv7). */
2107 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2109 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2110 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2111 ARM_INSN(0xe12fff1c), /* bx ip */
2112 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2115 /* V4T ARM -> ARM long branch stub, PIC. */
2116 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2118 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2119 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2120 ARM_INSN(0xe12fff1c), /* bx ip */
2121 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2124 /* V4T Thumb -> ARM long branch stub, PIC. */
2125 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2127 THUMB16_INSN(0x4778), /* bx pc */
2128 THUMB16_INSN(0x46c0), /* nop */
2129 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2130 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2131 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2134 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2135 architectures. */
2136 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2138 THUMB16_INSN(0xb401), /* push {r0} */
2139 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2140 THUMB16_INSN(0x46fc), /* mov ip, pc */
2141 THUMB16_INSN(0x4484), /* add ip, r0 */
2142 THUMB16_INSN(0xbc01), /* pop {r0} */
2143 THUMB16_INSN(0x4760), /* bx ip */
2144 DATA_WORD(0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2147 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2148 allowed. */
2149 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] =
2151 THUMB16_INSN(0x4778), /* bx pc */
2152 THUMB16_INSN(0x46c0), /* nop */
2153 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2154 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2155 ARM_INSN(0xe12fff1c), /* bx ip */
2156 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2159 /* Section name for stubs is the associated section name plus this
2160 string. */
2161 #define STUB_SUFFIX ".stub"
2163 enum elf32_arm_stub_type
2165 arm_stub_none,
2166 arm_stub_long_branch_any_any,
2167 arm_stub_long_branch_v4t_arm_thumb,
2168 arm_stub_long_branch_thumb_only,
2169 arm_stub_long_branch_v4t_thumb_thumb,
2170 arm_stub_long_branch_v4t_thumb_arm,
2171 arm_stub_short_branch_v4t_thumb_arm,
2172 arm_stub_long_branch_any_arm_pic,
2173 arm_stub_long_branch_any_thumb_pic,
2174 arm_stub_long_branch_v4t_arm_thumb_pic,
2175 arm_stub_long_branch_v4t_thumb_arm_pic,
2176 arm_stub_long_branch_thumb_only_pic,
2177 arm_stub_long_branch_v4t_thumb_thumb_pic,
2180 struct elf32_arm_stub_hash_entry
2182 /* Base hash table entry structure. */
2183 struct bfd_hash_entry root;
2185 /* The stub section. */
2186 asection *stub_sec;
2188 /* Offset within stub_sec of the beginning of this stub. */
2189 bfd_vma stub_offset;
2191 /* Given the symbol's value and its section we can determine its final
2192 value when building the stubs (so the stub knows where to jump). */
2193 bfd_vma target_value;
2194 asection *target_section;
2196 /* The stub type. */
2197 enum elf32_arm_stub_type stub_type;
2198 /* Its encoding size in bytes. */
2199 int stub_size;
2200 /* Its template. */
2201 const insn_sequence *stub_template;
2202 /* The size of the template (number of entries). */
2203 int stub_template_size;
2205 /* The symbol table entry, if any, that this was derived from. */
2206 struct elf32_arm_link_hash_entry *h;
2208 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2209 unsigned char st_type;
2211 /* Where this stub is being called from, or, in the case of combined
2212 stub sections, the first input section in the group. */
2213 asection *id_sec;
2215 /* The name for the local symbol at the start of this stub. The
2216 stub name in the hash table has to be unique; this does not, so
2217 it can be friendlier. */
2218 char *output_name;
2221 /* Used to build a map of a section. This is required for mixed-endian
2222 code/data. */
2224 typedef struct elf32_elf_section_map
2226 bfd_vma vma;
2227 char type;
2229 elf32_arm_section_map;
2231 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2233 typedef enum
2235 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2236 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2237 VFP11_ERRATUM_ARM_VENEER,
2238 VFP11_ERRATUM_THUMB_VENEER
2240 elf32_vfp11_erratum_type;
2242 typedef struct elf32_vfp11_erratum_list
2244 struct elf32_vfp11_erratum_list *next;
2245 bfd_vma vma;
2246 union
2248 struct
2250 struct elf32_vfp11_erratum_list *veneer;
2251 unsigned int vfp_insn;
2252 } b;
2253 struct
2255 struct elf32_vfp11_erratum_list *branch;
2256 unsigned int id;
2257 } v;
2258 } u;
2259 elf32_vfp11_erratum_type type;
2261 elf32_vfp11_erratum_list;
2263 typedef struct _arm_elf_section_data
2265 struct bfd_elf_section_data elf;
2266 unsigned int mapcount;
2267 unsigned int mapsize;
2268 elf32_arm_section_map *map;
2269 unsigned int erratumcount;
2270 elf32_vfp11_erratum_list *erratumlist;
2272 _arm_elf_section_data;
2274 #define elf32_arm_section_data(sec) \
2275 ((_arm_elf_section_data *) elf_section_data (sec))
2277 /* The size of the thread control block. */
2278 #define TCB_SIZE 8
2280 struct elf_arm_obj_tdata
2282 struct elf_obj_tdata root;
2284 /* tls_type for each local got entry. */
2285 char *local_got_tls_type;
2287 /* Zero to warn when linking objects with incompatible enum sizes. */
2288 int no_enum_size_warning;
2290 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2291 int no_wchar_size_warning;
2294 #define elf_arm_tdata(bfd) \
2295 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2297 #define elf32_arm_local_got_tls_type(bfd) \
2298 (elf_arm_tdata (bfd)->local_got_tls_type)
2300 #define is_arm_elf(bfd) \
2301 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2302 && elf_tdata (bfd) != NULL \
2303 && elf_object_id (bfd) == ARM_ELF_TDATA)
2305 static bfd_boolean
2306 elf32_arm_mkobject (bfd *abfd)
2308 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2309 ARM_ELF_TDATA);
2312 /* The ARM linker needs to keep track of the number of relocs that it
2313 decides to copy in check_relocs for each symbol. This is so that
2314 it can discard PC relative relocs if it doesn't need them when
2315 linking with -Bsymbolic. We store the information in a field
2316 extending the regular ELF linker hash table. */
2318 /* This structure keeps track of the number of relocs we have copied
2319 for a given symbol. */
2320 struct elf32_arm_relocs_copied
2322 /* Next section. */
2323 struct elf32_arm_relocs_copied * next;
2324 /* A section in dynobj. */
2325 asection * section;
2326 /* Number of relocs copied in this section. */
2327 bfd_size_type count;
2328 /* Number of PC-relative relocs copied in this section. */
2329 bfd_size_type pc_count;
2332 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2334 /* Arm ELF linker hash entry. */
2335 struct elf32_arm_link_hash_entry
2337 struct elf_link_hash_entry root;
2339 /* Number of PC relative relocs copied for this symbol. */
2340 struct elf32_arm_relocs_copied * relocs_copied;
2342 /* We reference count Thumb references to a PLT entry separately,
2343 so that we can emit the Thumb trampoline only if needed. */
2344 bfd_signed_vma plt_thumb_refcount;
2346 /* Some references from Thumb code may be eliminated by BL->BLX
2347 conversion, so record them separately. */
2348 bfd_signed_vma plt_maybe_thumb_refcount;
2350 /* Since PLT entries have variable size if the Thumb prologue is
2351 used, we need to record the index into .got.plt instead of
2352 recomputing it from the PLT offset. */
2353 bfd_signed_vma plt_got_offset;
2355 #define GOT_UNKNOWN 0
2356 #define GOT_NORMAL 1
2357 #define GOT_TLS_GD 2
2358 #define GOT_TLS_IE 4
2359 unsigned char tls_type;
2361 /* The symbol marking the real symbol location for exported thumb
2362 symbols with Arm stubs. */
2363 struct elf_link_hash_entry *export_glue;
2365 /* A pointer to the most recently used stub hash entry against this
2366 symbol. */
2367 struct elf32_arm_stub_hash_entry *stub_cache;
2370 /* Traverse an arm ELF linker hash table. */
2371 #define elf32_arm_link_hash_traverse(table, func, info) \
2372 (elf_link_hash_traverse \
2373 (&(table)->root, \
2374 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2375 (info)))
2377 /* Get the ARM elf linker hash table from a link_info structure. */
2378 #define elf32_arm_hash_table(info) \
2379 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2381 #define arm_stub_hash_lookup(table, string, create, copy) \
2382 ((struct elf32_arm_stub_hash_entry *) \
2383 bfd_hash_lookup ((table), (string), (create), (copy)))
2385 /* ARM ELF linker hash table. */
2386 struct elf32_arm_link_hash_table
2388 /* The main hash table. */
2389 struct elf_link_hash_table root;
2391 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2392 bfd_size_type thumb_glue_size;
2394 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2395 bfd_size_type arm_glue_size;
2397 /* The size in bytes of section containing the ARMv4 BX veneers. */
2398 bfd_size_type bx_glue_size;
2400 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2401 veneer has been populated. */
2402 bfd_vma bx_glue_offset[15];
2404 /* The size in bytes of the section containing glue for VFP11 erratum
2405 veneers. */
2406 bfd_size_type vfp11_erratum_glue_size;
2408 /* An arbitrary input BFD chosen to hold the glue sections. */
2409 bfd * bfd_of_glue_owner;
2411 /* Nonzero to output a BE8 image. */
2412 int byteswap_code;
2414 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2415 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2416 int target1_is_rel;
2418 /* The relocation to use for R_ARM_TARGET2 relocations. */
2419 int target2_reloc;
2421 /* 0 = Ignore R_ARM_V4BX.
2422 1 = Convert BX to MOV PC.
2423 2 = Generate v4 interworing stubs. */
2424 int fix_v4bx;
2426 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2427 int use_blx;
2429 /* What sort of code sequences we should look for which may trigger the
2430 VFP11 denorm erratum. */
2431 bfd_arm_vfp11_fix vfp11_fix;
2433 /* Global counter for the number of fixes we have emitted. */
2434 int num_vfp11_fixes;
2436 /* Nonzero to force PIC branch veneers. */
2437 int pic_veneer;
2439 /* The number of bytes in the initial entry in the PLT. */
2440 bfd_size_type plt_header_size;
2442 /* The number of bytes in the subsequent PLT etries. */
2443 bfd_size_type plt_entry_size;
2445 /* True if the target system is VxWorks. */
2446 int vxworks_p;
2448 /* True if the target system is Symbian OS. */
2449 int symbian_p;
2451 /* True if the target uses REL relocations. */
2452 int use_rel;
2454 /* Short-cuts to get to dynamic linker sections. */
2455 asection *sgot;
2456 asection *sgotplt;
2457 asection *srelgot;
2458 asection *splt;
2459 asection *srelplt;
2460 asection *sdynbss;
2461 asection *srelbss;
2463 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2464 asection *srelplt2;
2466 /* Data for R_ARM_TLS_LDM32 relocations. */
2467 union
2469 bfd_signed_vma refcount;
2470 bfd_vma offset;
2471 } tls_ldm_got;
2473 /* Small local sym to section mapping cache. */
2474 struct sym_sec_cache sym_sec;
2476 /* For convenience in allocate_dynrelocs. */
2477 bfd * obfd;
2479 /* The stub hash table. */
2480 struct bfd_hash_table stub_hash_table;
2482 /* Linker stub bfd. */
2483 bfd *stub_bfd;
2485 /* Linker call-backs. */
2486 asection * (*add_stub_section) (const char *, asection *);
2487 void (*layout_sections_again) (void);
2489 /* Array to keep track of which stub sections have been created, and
2490 information on stub grouping. */
2491 struct map_stub
2493 /* This is the section to which stubs in the group will be
2494 attached. */
2495 asection *link_sec;
2496 /* The stub section. */
2497 asection *stub_sec;
2498 } *stub_group;
2500 /* Assorted information used by elf32_arm_size_stubs. */
2501 unsigned int bfd_count;
2502 int top_index;
2503 asection **input_list;
2506 /* Create an entry in an ARM ELF linker hash table. */
2508 static struct bfd_hash_entry *
2509 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2510 struct bfd_hash_table * table,
2511 const char * string)
2513 struct elf32_arm_link_hash_entry * ret =
2514 (struct elf32_arm_link_hash_entry *) entry;
2516 /* Allocate the structure if it has not already been allocated by a
2517 subclass. */
2518 if (ret == NULL)
2519 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2520 if (ret == NULL)
2521 return (struct bfd_hash_entry *) ret;
2523 /* Call the allocation method of the superclass. */
2524 ret = ((struct elf32_arm_link_hash_entry *)
2525 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2526 table, string));
2527 if (ret != NULL)
2529 ret->relocs_copied = NULL;
2530 ret->tls_type = GOT_UNKNOWN;
2531 ret->plt_thumb_refcount = 0;
2532 ret->plt_maybe_thumb_refcount = 0;
2533 ret->plt_got_offset = -1;
2534 ret->export_glue = NULL;
2536 ret->stub_cache = NULL;
2539 return (struct bfd_hash_entry *) ret;
2542 /* Initialize an entry in the stub hash table. */
2544 static struct bfd_hash_entry *
2545 stub_hash_newfunc (struct bfd_hash_entry *entry,
2546 struct bfd_hash_table *table,
2547 const char *string)
2549 /* Allocate the structure if it has not already been allocated by a
2550 subclass. */
2551 if (entry == NULL)
2553 entry = bfd_hash_allocate (table,
2554 sizeof (struct elf32_arm_stub_hash_entry));
2555 if (entry == NULL)
2556 return entry;
2559 /* Call the allocation method of the superclass. */
2560 entry = bfd_hash_newfunc (entry, table, string);
2561 if (entry != NULL)
2563 struct elf32_arm_stub_hash_entry *eh;
2565 /* Initialize the local fields. */
2566 eh = (struct elf32_arm_stub_hash_entry *) entry;
2567 eh->stub_sec = NULL;
2568 eh->stub_offset = 0;
2569 eh->target_value = 0;
2570 eh->target_section = NULL;
2571 eh->stub_type = arm_stub_none;
2572 eh->stub_size = 0;
2573 eh->stub_template = NULL;
2574 eh->stub_template_size = 0;
2575 eh->h = NULL;
2576 eh->id_sec = NULL;
2579 return entry;
2582 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2583 shortcuts to them in our hash table. */
2585 static bfd_boolean
2586 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2588 struct elf32_arm_link_hash_table *htab;
2590 htab = elf32_arm_hash_table (info);
2591 /* BPABI objects never have a GOT, or associated sections. */
2592 if (htab->symbian_p)
2593 return TRUE;
2595 if (! _bfd_elf_create_got_section (dynobj, info))
2596 return FALSE;
2598 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2599 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2600 if (!htab->sgot || !htab->sgotplt)
2601 abort ();
2603 htab->srelgot = bfd_make_section_with_flags (dynobj,
2604 RELOC_SECTION (htab, ".got"),
2605 (SEC_ALLOC | SEC_LOAD
2606 | SEC_HAS_CONTENTS
2607 | SEC_IN_MEMORY
2608 | SEC_LINKER_CREATED
2609 | SEC_READONLY));
2610 if (htab->srelgot == NULL
2611 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2612 return FALSE;
2613 return TRUE;
2616 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2617 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2618 hash table. */
2620 static bfd_boolean
2621 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2623 struct elf32_arm_link_hash_table *htab;
2625 htab = elf32_arm_hash_table (info);
2626 if (!htab->sgot && !create_got_section (dynobj, info))
2627 return FALSE;
2629 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2630 return FALSE;
2632 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2633 htab->srelplt = bfd_get_section_by_name (dynobj,
2634 RELOC_SECTION (htab, ".plt"));
2635 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2636 if (!info->shared)
2637 htab->srelbss = bfd_get_section_by_name (dynobj,
2638 RELOC_SECTION (htab, ".bss"));
2640 if (htab->vxworks_p)
2642 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2643 return FALSE;
2645 if (info->shared)
2647 htab->plt_header_size = 0;
2648 htab->plt_entry_size
2649 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2651 else
2653 htab->plt_header_size
2654 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2655 htab->plt_entry_size
2656 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2660 if (!htab->splt
2661 || !htab->srelplt
2662 || !htab->sdynbss
2663 || (!info->shared && !htab->srelbss))
2664 abort ();
2666 return TRUE;
2669 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2671 static void
2672 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2673 struct elf_link_hash_entry *dir,
2674 struct elf_link_hash_entry *ind)
2676 struct elf32_arm_link_hash_entry *edir, *eind;
2678 edir = (struct elf32_arm_link_hash_entry *) dir;
2679 eind = (struct elf32_arm_link_hash_entry *) ind;
2681 if (eind->relocs_copied != NULL)
2683 if (edir->relocs_copied != NULL)
2685 struct elf32_arm_relocs_copied **pp;
2686 struct elf32_arm_relocs_copied *p;
2688 /* Add reloc counts against the indirect sym to the direct sym
2689 list. Merge any entries against the same section. */
2690 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2692 struct elf32_arm_relocs_copied *q;
2694 for (q = edir->relocs_copied; q != NULL; q = q->next)
2695 if (q->section == p->section)
2697 q->pc_count += p->pc_count;
2698 q->count += p->count;
2699 *pp = p->next;
2700 break;
2702 if (q == NULL)
2703 pp = &p->next;
2705 *pp = edir->relocs_copied;
2708 edir->relocs_copied = eind->relocs_copied;
2709 eind->relocs_copied = NULL;
2712 if (ind->root.type == bfd_link_hash_indirect)
2714 /* Copy over PLT info. */
2715 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2716 eind->plt_thumb_refcount = 0;
2717 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2718 eind->plt_maybe_thumb_refcount = 0;
2720 if (dir->got.refcount <= 0)
2722 edir->tls_type = eind->tls_type;
2723 eind->tls_type = GOT_UNKNOWN;
2727 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2730 /* Create an ARM elf linker hash table. */
2732 static struct bfd_link_hash_table *
2733 elf32_arm_link_hash_table_create (bfd *abfd)
2735 struct elf32_arm_link_hash_table *ret;
2736 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2738 ret = bfd_malloc (amt);
2739 if (ret == NULL)
2740 return NULL;
2742 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2743 elf32_arm_link_hash_newfunc,
2744 sizeof (struct elf32_arm_link_hash_entry)))
2746 free (ret);
2747 return NULL;
2750 ret->sgot = NULL;
2751 ret->sgotplt = NULL;
2752 ret->srelgot = NULL;
2753 ret->splt = NULL;
2754 ret->srelplt = NULL;
2755 ret->sdynbss = NULL;
2756 ret->srelbss = NULL;
2757 ret->srelplt2 = NULL;
2758 ret->thumb_glue_size = 0;
2759 ret->arm_glue_size = 0;
2760 ret->bx_glue_size = 0;
2761 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2762 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2763 ret->vfp11_erratum_glue_size = 0;
2764 ret->num_vfp11_fixes = 0;
2765 ret->bfd_of_glue_owner = NULL;
2766 ret->byteswap_code = 0;
2767 ret->target1_is_rel = 0;
2768 ret->target2_reloc = R_ARM_NONE;
2769 #ifdef FOUR_WORD_PLT
2770 ret->plt_header_size = 16;
2771 ret->plt_entry_size = 16;
2772 #else
2773 ret->plt_header_size = 20;
2774 ret->plt_entry_size = 12;
2775 #endif
2776 ret->fix_v4bx = 0;
2777 ret->use_blx = 0;
2778 ret->vxworks_p = 0;
2779 ret->symbian_p = 0;
2780 ret->use_rel = 1;
2781 ret->sym_sec.abfd = NULL;
2782 ret->obfd = abfd;
2783 ret->tls_ldm_got.refcount = 0;
2784 ret->stub_bfd = NULL;
2785 ret->add_stub_section = NULL;
2786 ret->layout_sections_again = NULL;
2787 ret->stub_group = NULL;
2788 ret->bfd_count = 0;
2789 ret->top_index = 0;
2790 ret->input_list = NULL;
2792 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2793 sizeof (struct elf32_arm_stub_hash_entry)))
2795 free (ret);
2796 return NULL;
2799 return &ret->root.root;
2802 /* Free the derived linker hash table. */
2804 static void
2805 elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2807 struct elf32_arm_link_hash_table *ret
2808 = (struct elf32_arm_link_hash_table *) hash;
2810 bfd_hash_table_free (&ret->stub_hash_table);
2811 _bfd_generic_link_hash_table_free (hash);
2814 /* Determine if we're dealing with a Thumb only architecture. */
2816 static bfd_boolean
2817 using_thumb_only (struct elf32_arm_link_hash_table *globals)
2819 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2820 Tag_CPU_arch);
2821 int profile;
2823 if (arch != TAG_CPU_ARCH_V7)
2824 return FALSE;
2826 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2827 Tag_CPU_arch_profile);
2829 return profile == 'M';
2832 /* Determine if we're dealing with a Thumb-2 object. */
2834 static bfd_boolean
2835 using_thumb2 (struct elf32_arm_link_hash_table *globals)
2837 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2838 Tag_CPU_arch);
2839 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2842 static bfd_boolean
2843 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2845 switch (stub_type)
2847 case arm_stub_long_branch_thumb_only:
2848 case arm_stub_long_branch_v4t_thumb_arm:
2849 case arm_stub_short_branch_v4t_thumb_arm:
2850 case arm_stub_long_branch_v4t_thumb_arm_pic:
2851 case arm_stub_long_branch_thumb_only_pic:
2852 return TRUE;
2853 case arm_stub_none:
2854 BFD_FAIL ();
2855 return FALSE;
2856 break;
2857 default:
2858 return FALSE;
2862 /* Determine the type of stub needed, if any, for a call. */
2864 static enum elf32_arm_stub_type
2865 arm_type_of_stub (struct bfd_link_info *info,
2866 asection *input_sec,
2867 const Elf_Internal_Rela *rel,
2868 unsigned char st_type,
2869 struct elf32_arm_link_hash_entry *hash,
2870 bfd_vma destination,
2871 asection *sym_sec,
2872 bfd *input_bfd,
2873 const char *name)
2875 bfd_vma location;
2876 bfd_signed_vma branch_offset;
2877 unsigned int r_type;
2878 struct elf32_arm_link_hash_table * globals;
2879 int thumb2;
2880 int thumb_only;
2881 enum elf32_arm_stub_type stub_type = arm_stub_none;
2882 int use_plt = 0;
2884 /* We don't know the actual type of destination in case it is of
2885 type STT_SECTION: give up. */
2886 if (st_type == STT_SECTION)
2887 return stub_type;
2889 globals = elf32_arm_hash_table (info);
2891 thumb_only = using_thumb_only (globals);
2893 thumb2 = using_thumb2 (globals);
2895 /* Determine where the call point is. */
2896 location = (input_sec->output_offset
2897 + input_sec->output_section->vma
2898 + rel->r_offset);
2900 branch_offset = (bfd_signed_vma)(destination - location);
2902 r_type = ELF32_R_TYPE (rel->r_info);
2904 /* Keep a simpler condition, for the sake of clarity. */
2905 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
2907 use_plt = 1;
2908 /* Note when dealing with PLT entries: the main PLT stub is in
2909 ARM mode, so if the branch is in Thumb mode, another
2910 Thumb->ARM stub will be inserted later just before the ARM
2911 PLT stub. We don't take this extra distance into account
2912 here, because if a long branch stub is needed, we'll add a
2913 Thumb->Arm one and branch directly to the ARM PLT entry
2914 because it avoids spreading offset corrections in several
2915 places. */
2918 if (r_type == R_ARM_THM_CALL)
2920 /* Handle cases where:
2921 - this call goes too far (different Thumb/Thumb2 max
2922 distance)
2923 - it's a Thumb->Arm call and blx is not available. A stub is
2924 needed in this case, but only if this call is not through a
2925 PLT entry. Indeed, PLT stubs handle mode switching already.
2927 if ((!thumb2
2928 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2929 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2930 || (thumb2
2931 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2932 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2933 || ((st_type != STT_ARM_TFUNC)
2934 && ((r_type == R_ARM_THM_CALL) && !globals->use_blx)
2935 && !use_plt))
2937 if (st_type == STT_ARM_TFUNC)
2939 /* Thumb to thumb. */
2940 if (!thumb_only)
2942 stub_type = (info->shared | globals->pic_veneer)
2943 /* PIC stubs. */
2944 ? ((globals->use_blx)
2945 /* V5T and above. */
2946 ? arm_stub_long_branch_any_thumb_pic
2947 /* On V4T, use Thumb code only. */
2948 : arm_stub_long_branch_v4t_thumb_thumb_pic)
2950 /* non-PIC stubs. */
2951 : ((globals->use_blx)
2952 /* V5T and above. */
2953 ? arm_stub_long_branch_any_any
2954 /* V4T. */
2955 : arm_stub_long_branch_v4t_thumb_thumb);
2957 else
2959 stub_type = (info->shared | globals->pic_veneer)
2960 /* PIC stub. */
2961 ? arm_stub_long_branch_thumb_only_pic
2962 /* non-PIC stub. */
2963 : arm_stub_long_branch_thumb_only;
2966 else
2968 /* Thumb to arm. */
2969 if (sym_sec != NULL
2970 && sym_sec->owner != NULL
2971 && !INTERWORK_FLAG (sym_sec->owner))
2973 (*_bfd_error_handler)
2974 (_("%B(%s): warning: interworking not enabled.\n"
2975 " first occurrence: %B: Thumb call to ARM"),
2976 sym_sec->owner, input_bfd, name);
2979 stub_type = (info->shared | globals->pic_veneer)
2980 /* PIC stubs. */
2981 ? ((globals->use_blx)
2982 /* V5T and above. */
2983 ? arm_stub_long_branch_any_arm_pic
2984 /* V4T PIC stub. */
2985 : arm_stub_long_branch_v4t_thumb_arm_pic)
2987 /* non-PIC stubs. */
2988 : ((globals->use_blx)
2989 /* V5T and above. */
2990 ? arm_stub_long_branch_any_any
2991 /* V4T. */
2992 : arm_stub_long_branch_v4t_thumb_arm);
2994 /* Handle v4t short branches. */
2995 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
2996 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
2997 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
2998 stub_type = arm_stub_short_branch_v4t_thumb_arm;
3002 else if (r_type == R_ARM_CALL)
3004 if (st_type == STT_ARM_TFUNC)
3006 /* Arm to thumb. */
3008 if (sym_sec != NULL
3009 && sym_sec->owner != NULL
3010 && !INTERWORK_FLAG (sym_sec->owner))
3012 (*_bfd_error_handler)
3013 (_("%B(%s): warning: interworking not enabled.\n"
3014 " first occurrence: %B: ARM call to Thumb"),
3015 sym_sec->owner, input_bfd, name);
3018 /* We have an extra 2-bytes reach because of
3019 the mode change (bit 24 (H) of BLX encoding). */
3020 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
3021 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
3022 || !globals->use_blx)
3024 stub_type = (info->shared | globals->pic_veneer)
3025 /* PIC stubs. */
3026 ? ((globals->use_blx)
3027 /* V5T and above. */
3028 ? arm_stub_long_branch_any_thumb_pic
3029 /* V4T stub. */
3030 : arm_stub_long_branch_v4t_arm_thumb_pic)
3032 /* non-PIC stubs. */
3033 : ((globals->use_blx)
3034 /* V5T and above. */
3035 ? arm_stub_long_branch_any_any
3036 /* V4T. */
3037 : arm_stub_long_branch_v4t_arm_thumb);
3040 else
3042 /* Arm to arm. */
3043 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3044 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3046 stub_type = (info->shared | globals->pic_veneer)
3047 /* PIC stubs. */
3048 ? arm_stub_long_branch_any_arm_pic
3049 /* non-PIC stubs. */
3050 : arm_stub_long_branch_any_any;
3055 return stub_type;
3058 /* Build a name for an entry in the stub hash table. */
3060 static char *
3061 elf32_arm_stub_name (const asection *input_section,
3062 const asection *sym_sec,
3063 const struct elf32_arm_link_hash_entry *hash,
3064 const Elf_Internal_Rela *rel)
3066 char *stub_name;
3067 bfd_size_type len;
3069 if (hash)
3071 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
3072 stub_name = bfd_malloc (len);
3073 if (stub_name != NULL)
3074 sprintf (stub_name, "%08x_%s+%x",
3075 input_section->id & 0xffffffff,
3076 hash->root.root.root.string,
3077 (int) rel->r_addend & 0xffffffff);
3079 else
3081 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3082 stub_name = bfd_malloc (len);
3083 if (stub_name != NULL)
3084 sprintf (stub_name, "%08x_%x:%x+%x",
3085 input_section->id & 0xffffffff,
3086 sym_sec->id & 0xffffffff,
3087 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3088 (int) rel->r_addend & 0xffffffff);
3091 return stub_name;
3094 /* Look up an entry in the stub hash. Stub entries are cached because
3095 creating the stub name takes a bit of time. */
3097 static struct elf32_arm_stub_hash_entry *
3098 elf32_arm_get_stub_entry (const asection *input_section,
3099 const asection *sym_sec,
3100 struct elf_link_hash_entry *hash,
3101 const Elf_Internal_Rela *rel,
3102 struct elf32_arm_link_hash_table *htab)
3104 struct elf32_arm_stub_hash_entry *stub_entry;
3105 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3106 const asection *id_sec;
3108 if ((input_section->flags & SEC_CODE) == 0)
3109 return NULL;
3111 /* If this input section is part of a group of sections sharing one
3112 stub section, then use the id of the first section in the group.
3113 Stub names need to include a section id, as there may well be
3114 more than one stub used to reach say, printf, and we need to
3115 distinguish between them. */
3116 id_sec = htab->stub_group[input_section->id].link_sec;
3118 if (h != NULL && h->stub_cache != NULL
3119 && h->stub_cache->h == h
3120 && h->stub_cache->id_sec == id_sec)
3122 stub_entry = h->stub_cache;
3124 else
3126 char *stub_name;
3128 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
3129 if (stub_name == NULL)
3130 return NULL;
3132 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3133 stub_name, FALSE, FALSE);
3134 if (h != NULL)
3135 h->stub_cache = stub_entry;
3137 free (stub_name);
3140 return stub_entry;
3143 /* Add a new stub entry to the stub hash. Not all fields of the new
3144 stub entry are initialised. */
3146 static struct elf32_arm_stub_hash_entry *
3147 elf32_arm_add_stub (const char *stub_name,
3148 asection *section,
3149 struct elf32_arm_link_hash_table *htab)
3151 asection *link_sec;
3152 asection *stub_sec;
3153 struct elf32_arm_stub_hash_entry *stub_entry;
3155 link_sec = htab->stub_group[section->id].link_sec;
3156 stub_sec = htab->stub_group[section->id].stub_sec;
3157 if (stub_sec == NULL)
3159 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3160 if (stub_sec == NULL)
3162 size_t namelen;
3163 bfd_size_type len;
3164 char *s_name;
3166 namelen = strlen (link_sec->name);
3167 len = namelen + sizeof (STUB_SUFFIX);
3168 s_name = bfd_alloc (htab->stub_bfd, len);
3169 if (s_name == NULL)
3170 return NULL;
3172 memcpy (s_name, link_sec->name, namelen);
3173 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3174 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3175 if (stub_sec == NULL)
3176 return NULL;
3177 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3179 htab->stub_group[section->id].stub_sec = stub_sec;
3182 /* Enter this entry into the linker stub hash table. */
3183 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3184 TRUE, FALSE);
3185 if (stub_entry == NULL)
3187 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3188 section->owner,
3189 stub_name);
3190 return NULL;
3193 stub_entry->stub_sec = stub_sec;
3194 stub_entry->stub_offset = 0;
3195 stub_entry->id_sec = link_sec;
3197 return stub_entry;
3200 /* Store an Arm insn into an output section not processed by
3201 elf32_arm_write_section. */
3203 static void
3204 put_arm_insn (struct elf32_arm_link_hash_table * htab,
3205 bfd * output_bfd, bfd_vma val, void * ptr)
3207 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3208 bfd_putl32 (val, ptr);
3209 else
3210 bfd_putb32 (val, ptr);
3213 /* Store a 16-bit Thumb insn into an output section not processed by
3214 elf32_arm_write_section. */
3216 static void
3217 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3218 bfd * output_bfd, bfd_vma val, void * ptr)
3220 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3221 bfd_putl16 (val, ptr);
3222 else
3223 bfd_putb16 (val, ptr);
3226 static bfd_boolean
3227 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3228 void * in_arg)
3230 struct elf32_arm_stub_hash_entry *stub_entry;
3231 struct bfd_link_info *info;
3232 struct elf32_arm_link_hash_table *htab;
3233 asection *stub_sec;
3234 bfd *stub_bfd;
3235 bfd_vma stub_addr;
3236 bfd_byte *loc;
3237 bfd_vma sym_value;
3238 int template_size;
3239 int size;
3240 const insn_sequence *template;
3241 int i;
3242 struct elf32_arm_link_hash_table * globals;
3243 int stub_reloc_idx = -1;
3244 int stub_reloc_offset = 0;
3246 /* Massage our args to the form they really have. */
3247 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3248 info = (struct bfd_link_info *) in_arg;
3250 globals = elf32_arm_hash_table (info);
3252 htab = elf32_arm_hash_table (info);
3253 stub_sec = stub_entry->stub_sec;
3255 /* Make a note of the offset within the stubs for this entry. */
3256 stub_entry->stub_offset = stub_sec->size;
3257 loc = stub_sec->contents + stub_entry->stub_offset;
3259 stub_bfd = stub_sec->owner;
3261 /* This is the address of the start of the stub. */
3262 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3263 + stub_entry->stub_offset;
3265 /* This is the address of the stub destination. */
3266 sym_value = (stub_entry->target_value
3267 + stub_entry->target_section->output_offset
3268 + stub_entry->target_section->output_section->vma);
3270 template = stub_entry->stub_template;
3271 template_size = stub_entry->stub_template_size;
3273 size = 0;
3274 for (i = 0; i < template_size; i++)
3276 switch (template[i].type)
3278 case THUMB16_TYPE:
3279 put_thumb_insn (globals, stub_bfd, template[i].data, loc + size);
3280 size += 2;
3281 break;
3283 case ARM_TYPE:
3284 put_arm_insn (globals, stub_bfd, template[i].data, loc + size);
3285 /* Handle cases where the target is encoded within the
3286 instruction. */
3287 if (template[i].r_type == R_ARM_JUMP24)
3289 stub_reloc_idx = i;
3290 stub_reloc_offset = size;
3292 size += 4;
3293 break;
3295 case DATA_TYPE:
3296 bfd_put_32 (stub_bfd, template[i].data, loc + size);
3297 stub_reloc_idx = i;
3298 stub_reloc_offset = size;
3299 size += 4;
3300 break;
3302 default:
3303 BFD_FAIL ();
3304 return FALSE;
3308 stub_sec->size += size;
3310 /* Stub size has already been computed in arm_size_one_stub. Check
3311 consistency. */
3312 BFD_ASSERT (size == stub_entry->stub_size);
3314 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3315 if (stub_entry->st_type == STT_ARM_TFUNC)
3316 sym_value |= 1;
3318 /* Assume there is one and only one entry to relocate in each stub. */
3319 BFD_ASSERT (stub_reloc_idx != -1);
3321 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx].r_type),
3322 stub_bfd, stub_sec, stub_sec->contents,
3323 stub_entry->stub_offset + stub_reloc_offset,
3324 sym_value, template[stub_reloc_idx].reloc_addend);
3326 return TRUE;
3329 /* As above, but don't actually build the stub. Just bump offset so
3330 we know stub section sizes. */
3332 static bfd_boolean
3333 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3334 void * in_arg)
3336 struct elf32_arm_stub_hash_entry *stub_entry;
3337 struct elf32_arm_link_hash_table *htab;
3338 const insn_sequence *template;
3339 int template_size;
3340 int size;
3341 int i;
3343 /* Massage our args to the form they really have. */
3344 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3345 htab = (struct elf32_arm_link_hash_table *) in_arg;
3347 switch (stub_entry->stub_type)
3349 case arm_stub_long_branch_any_any:
3350 template = elf32_arm_stub_long_branch_any_any;
3351 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
3352 break;
3353 case arm_stub_long_branch_v4t_arm_thumb:
3354 template = elf32_arm_stub_long_branch_v4t_arm_thumb;
3355 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
3356 break;
3357 case arm_stub_long_branch_thumb_only:
3358 template = elf32_arm_stub_long_branch_thumb_only;
3359 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
3360 break;
3361 case arm_stub_long_branch_v4t_thumb_thumb:
3362 template = elf32_arm_stub_long_branch_v4t_thumb_thumb;
3363 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb);
3364 break;
3365 case arm_stub_long_branch_v4t_thumb_arm:
3366 template = elf32_arm_stub_long_branch_v4t_thumb_arm;
3367 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
3368 break;
3369 case arm_stub_short_branch_v4t_thumb_arm:
3370 template = elf32_arm_stub_short_branch_v4t_thumb_arm;
3371 template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
3372 break;
3373 case arm_stub_long_branch_any_arm_pic:
3374 template = elf32_arm_stub_long_branch_any_arm_pic;
3375 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
3376 break;
3377 case arm_stub_long_branch_any_thumb_pic:
3378 template = elf32_arm_stub_long_branch_any_thumb_pic;
3379 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
3380 break;
3381 case arm_stub_long_branch_v4t_arm_thumb_pic:
3382 template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
3383 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
3384 break;
3385 case arm_stub_long_branch_v4t_thumb_arm_pic:
3386 template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
3387 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
3388 break;
3389 case arm_stub_long_branch_thumb_only_pic:
3390 template = elf32_arm_stub_long_branch_thumb_only_pic;
3391 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
3392 break;
3393 case arm_stub_long_branch_v4t_thumb_thumb_pic:
3394 template = elf32_arm_stub_long_branch_v4t_thumb_thumb_pic;
3395 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb_pic);
3396 break;
3397 default:
3398 BFD_FAIL ();
3399 return FALSE;
3402 size = 0;
3403 for (i = 0; i < template_size; i++)
3405 switch (template[i].type)
3407 case THUMB16_TYPE:
3408 size += 2;
3409 break;
3411 case ARM_TYPE:
3412 size += 4;
3413 break;
3415 case DATA_TYPE:
3416 size += 4;
3417 break;
3419 default:
3420 BFD_FAIL ();
3421 return FALSE;
3425 stub_entry->stub_size = size;
3426 stub_entry->stub_template = template;
3427 stub_entry->stub_template_size = template_size;
3429 size = (size + 7) & ~7;
3430 stub_entry->stub_sec->size += size;
3432 return TRUE;
3435 /* External entry points for sizing and building linker stubs. */
3437 /* Set up various things so that we can make a list of input sections
3438 for each output section included in the link. Returns -1 on error,
3439 0 when no stubs will be needed, and 1 on success. */
3442 elf32_arm_setup_section_lists (bfd *output_bfd,
3443 struct bfd_link_info *info)
3445 bfd *input_bfd;
3446 unsigned int bfd_count;
3447 int top_id, top_index;
3448 asection *section;
3449 asection **input_list, **list;
3450 bfd_size_type amt;
3451 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3453 if (! is_elf_hash_table (htab))
3454 return 0;
3456 /* Count the number of input BFDs and find the top input section id. */
3457 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3458 input_bfd != NULL;
3459 input_bfd = input_bfd->link_next)
3461 bfd_count += 1;
3462 for (section = input_bfd->sections;
3463 section != NULL;
3464 section = section->next)
3466 if (top_id < section->id)
3467 top_id = section->id;
3470 htab->bfd_count = bfd_count;
3472 amt = sizeof (struct map_stub) * (top_id + 1);
3473 htab->stub_group = bfd_zmalloc (amt);
3474 if (htab->stub_group == NULL)
3475 return -1;
3477 /* We can't use output_bfd->section_count here to find the top output
3478 section index as some sections may have been removed, and
3479 _bfd_strip_section_from_output doesn't renumber the indices. */
3480 for (section = output_bfd->sections, top_index = 0;
3481 section != NULL;
3482 section = section->next)
3484 if (top_index < section->index)
3485 top_index = section->index;
3488 htab->top_index = top_index;
3489 amt = sizeof (asection *) * (top_index + 1);
3490 input_list = bfd_malloc (amt);
3491 htab->input_list = input_list;
3492 if (input_list == NULL)
3493 return -1;
3495 /* For sections we aren't interested in, mark their entries with a
3496 value we can check later. */
3497 list = input_list + top_index;
3499 *list = bfd_abs_section_ptr;
3500 while (list-- != input_list);
3502 for (section = output_bfd->sections;
3503 section != NULL;
3504 section = section->next)
3506 if ((section->flags & SEC_CODE) != 0)
3507 input_list[section->index] = NULL;
3510 return 1;
3513 /* The linker repeatedly calls this function for each input section,
3514 in the order that input sections are linked into output sections.
3515 Build lists of input sections to determine groupings between which
3516 we may insert linker stubs. */
3518 void
3519 elf32_arm_next_input_section (struct bfd_link_info *info,
3520 asection *isec)
3522 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3524 if (isec->output_section->index <= htab->top_index)
3526 asection **list = htab->input_list + isec->output_section->index;
3528 if (*list != bfd_abs_section_ptr)
3530 /* Steal the link_sec pointer for our list. */
3531 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3532 /* This happens to make the list in reverse order,
3533 which we reverse later. */
3534 PREV_SEC (isec) = *list;
3535 *list = isec;
3540 /* See whether we can group stub sections together. Grouping stub
3541 sections may result in fewer stubs. More importantly, we need to
3542 put all .init* and .fini* stubs at the end of the .init or
3543 .fini output sections respectively, because glibc splits the
3544 _init and _fini functions into multiple parts. Putting a stub in
3545 the middle of a function is not a good idea. */
3547 static void
3548 group_sections (struct elf32_arm_link_hash_table *htab,
3549 bfd_size_type stub_group_size,
3550 bfd_boolean stubs_always_after_branch)
3552 asection **list = htab->input_list;
3556 asection *tail = *list;
3557 asection *head;
3559 if (tail == bfd_abs_section_ptr)
3560 continue;
3562 /* Reverse the list: we must avoid placing stubs at the
3563 beginning of the section because the beginning of the text
3564 section may be required for an interrupt vector in bare metal
3565 code. */
3566 #define NEXT_SEC PREV_SEC
3567 head = NULL;
3568 while (tail != NULL)
3570 /* Pop from tail. */
3571 asection *item = tail;
3572 tail = PREV_SEC (item);
3574 /* Push on head. */
3575 NEXT_SEC (item) = head;
3576 head = item;
3579 while (head != NULL)
3581 asection *curr;
3582 asection *next;
3583 bfd_vma stub_group_start = head->output_offset;
3584 bfd_vma end_of_next;
3586 curr = head;
3587 while (NEXT_SEC (curr) != NULL)
3589 next = NEXT_SEC (curr);
3590 end_of_next = next->output_offset + next->size;
3591 if (end_of_next - stub_group_start >= stub_group_size)
3592 /* End of NEXT is too far from start, so stop. */
3593 break;
3594 /* Add NEXT to the group. */
3595 curr = next;
3598 /* OK, the size from the start to the start of CURR is less
3599 than stub_group_size and thus can be handled by one stub
3600 section. (Or the head section is itself larger than
3601 stub_group_size, in which case we may be toast.)
3602 We should really be keeping track of the total size of
3603 stubs added here, as stubs contribute to the final output
3604 section size. */
3607 next = NEXT_SEC (head);
3608 /* Set up this stub group. */
3609 htab->stub_group[head->id].link_sec = curr;
3611 while (head != curr && (head = next) != NULL);
3613 /* But wait, there's more! Input sections up to stub_group_size
3614 bytes after the stub section can be handled by it too. */
3615 if (!stubs_always_after_branch)
3617 stub_group_start = curr->output_offset + curr->size;
3619 while (next != NULL)
3621 end_of_next = next->output_offset + next->size;
3622 if (end_of_next - stub_group_start >= stub_group_size)
3623 /* End of NEXT is too far from stubs, so stop. */
3624 break;
3625 /* Add NEXT to the stub group. */
3626 head = next;
3627 next = NEXT_SEC (head);
3628 htab->stub_group[head->id].link_sec = curr;
3631 head = next;
3634 while (list++ != htab->input_list + htab->top_index);
3636 free (htab->input_list);
3637 #undef PREV_SEC
3638 #undef NEXT_SEC
3641 /* Determine and set the size of the stub section for a final link.
3643 The basic idea here is to examine all the relocations looking for
3644 PC-relative calls to a target that is unreachable with a "bl"
3645 instruction. */
3647 bfd_boolean
3648 elf32_arm_size_stubs (bfd *output_bfd,
3649 bfd *stub_bfd,
3650 struct bfd_link_info *info,
3651 bfd_signed_vma group_size,
3652 asection * (*add_stub_section) (const char *, asection *),
3653 void (*layout_sections_again) (void))
3655 bfd_size_type stub_group_size;
3656 bfd_boolean stubs_always_after_branch;
3657 bfd_boolean stub_changed = 0;
3658 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3660 /* Propagate mach to stub bfd, because it may not have been
3661 finalized when we created stub_bfd. */
3662 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3663 bfd_get_mach (output_bfd));
3665 /* Stash our params away. */
3666 htab->stub_bfd = stub_bfd;
3667 htab->add_stub_section = add_stub_section;
3668 htab->layout_sections_again = layout_sections_again;
3669 stubs_always_after_branch = group_size < 0;
3670 if (group_size < 0)
3671 stub_group_size = -group_size;
3672 else
3673 stub_group_size = group_size;
3675 if (stub_group_size == 1)
3677 /* Default values. */
3678 /* Thumb branch range is +-4MB has to be used as the default
3679 maximum size (a given section can contain both ARM and Thumb
3680 code, so the worst case has to be taken into account).
3682 This value is 24K less than that, which allows for 2025
3683 12-byte stubs. If we exceed that, then we will fail to link.
3684 The user will have to relink with an explicit group size
3685 option. */
3686 stub_group_size = 4170000;
3689 group_sections (htab, stub_group_size, stubs_always_after_branch);
3691 while (1)
3693 bfd *input_bfd;
3694 unsigned int bfd_indx;
3695 asection *stub_sec;
3697 for (input_bfd = info->input_bfds, bfd_indx = 0;
3698 input_bfd != NULL;
3699 input_bfd = input_bfd->link_next, bfd_indx++)
3701 Elf_Internal_Shdr *symtab_hdr;
3702 asection *section;
3703 Elf_Internal_Sym *local_syms = NULL;
3705 /* We'll need the symbol table in a second. */
3706 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3707 if (symtab_hdr->sh_info == 0)
3708 continue;
3710 /* Walk over each section attached to the input bfd. */
3711 for (section = input_bfd->sections;
3712 section != NULL;
3713 section = section->next)
3715 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3717 /* If there aren't any relocs, then there's nothing more
3718 to do. */
3719 if ((section->flags & SEC_RELOC) == 0
3720 || section->reloc_count == 0
3721 || (section->flags & SEC_CODE) == 0)
3722 continue;
3724 /* If this section is a link-once section that will be
3725 discarded, then don't create any stubs. */
3726 if (section->output_section == NULL
3727 || section->output_section->owner != output_bfd)
3728 continue;
3730 /* Get the relocs. */
3731 internal_relocs
3732 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3733 NULL, info->keep_memory);
3734 if (internal_relocs == NULL)
3735 goto error_ret_free_local;
3737 /* Now examine each relocation. */
3738 irela = internal_relocs;
3739 irelaend = irela + section->reloc_count;
3740 for (; irela < irelaend; irela++)
3742 unsigned int r_type, r_indx;
3743 enum elf32_arm_stub_type stub_type;
3744 struct elf32_arm_stub_hash_entry *stub_entry;
3745 asection *sym_sec;
3746 bfd_vma sym_value;
3747 bfd_vma destination;
3748 struct elf32_arm_link_hash_entry *hash;
3749 const char *sym_name;
3750 char *stub_name;
3751 const asection *id_sec;
3752 unsigned char st_type;
3754 r_type = ELF32_R_TYPE (irela->r_info);
3755 r_indx = ELF32_R_SYM (irela->r_info);
3757 if (r_type >= (unsigned int) R_ARM_max)
3759 bfd_set_error (bfd_error_bad_value);
3760 error_ret_free_internal:
3761 if (elf_section_data (section)->relocs == NULL)
3762 free (internal_relocs);
3763 goto error_ret_free_local;
3766 /* Only look for stubs on call instructions. */
3767 if ((r_type != (unsigned int) R_ARM_CALL)
3768 && (r_type != (unsigned int) R_ARM_THM_CALL))
3769 continue;
3771 /* Now determine the call target, its name, value,
3772 section. */
3773 sym_sec = NULL;
3774 sym_value = 0;
3775 destination = 0;
3776 hash = NULL;
3777 sym_name = NULL;
3778 if (r_indx < symtab_hdr->sh_info)
3780 /* It's a local symbol. */
3781 Elf_Internal_Sym *sym;
3782 Elf_Internal_Shdr *hdr;
3784 if (local_syms == NULL)
3786 local_syms
3787 = (Elf_Internal_Sym *) symtab_hdr->contents;
3788 if (local_syms == NULL)
3789 local_syms
3790 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3791 symtab_hdr->sh_info, 0,
3792 NULL, NULL, NULL);
3793 if (local_syms == NULL)
3794 goto error_ret_free_internal;
3797 sym = local_syms + r_indx;
3798 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3799 sym_sec = hdr->bfd_section;
3800 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3801 sym_value = sym->st_value;
3802 destination = (sym_value + irela->r_addend
3803 + sym_sec->output_offset
3804 + sym_sec->output_section->vma);
3805 st_type = ELF_ST_TYPE (sym->st_info);
3806 sym_name
3807 = bfd_elf_string_from_elf_section (input_bfd,
3808 symtab_hdr->sh_link,
3809 sym->st_name);
3811 else
3813 /* It's an external symbol. */
3814 int e_indx;
3816 e_indx = r_indx - symtab_hdr->sh_info;
3817 hash = ((struct elf32_arm_link_hash_entry *)
3818 elf_sym_hashes (input_bfd)[e_indx]);
3820 while (hash->root.root.type == bfd_link_hash_indirect
3821 || hash->root.root.type == bfd_link_hash_warning)
3822 hash = ((struct elf32_arm_link_hash_entry *)
3823 hash->root.root.u.i.link);
3825 if (hash->root.root.type == bfd_link_hash_defined
3826 || hash->root.root.type == bfd_link_hash_defweak)
3828 sym_sec = hash->root.root.u.def.section;
3829 sym_value = hash->root.root.u.def.value;
3830 if (sym_sec->output_section != NULL)
3831 destination = (sym_value + irela->r_addend
3832 + sym_sec->output_offset
3833 + sym_sec->output_section->vma);
3835 else if (hash->root.root.type == bfd_link_hash_undefweak
3836 || hash->root.root.type == bfd_link_hash_undefined)
3837 /* For a shared library, these will need a PLT stub,
3838 which is treated separately.
3839 For absolute code, they cannot be handled. */
3840 continue;
3841 else
3843 bfd_set_error (bfd_error_bad_value);
3844 goto error_ret_free_internal;
3846 st_type = ELF_ST_TYPE (hash->root.type);
3847 sym_name = hash->root.root.root.string;
3850 /* Determine what (if any) linker stub is needed. */
3851 stub_type = arm_type_of_stub (info, section, irela, st_type,
3852 hash, destination, sym_sec,
3853 input_bfd, sym_name);
3854 if (stub_type == arm_stub_none)
3855 continue;
3857 /* Support for grouping stub sections. */
3858 id_sec = htab->stub_group[section->id].link_sec;
3860 /* Get the name of this stub. */
3861 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3862 if (!stub_name)
3863 goto error_ret_free_internal;
3865 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3866 stub_name,
3867 FALSE, FALSE);
3868 if (stub_entry != NULL)
3870 /* The proper stub has already been created. */
3871 free (stub_name);
3872 continue;
3875 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
3876 if (stub_entry == NULL)
3878 free (stub_name);
3879 goto error_ret_free_internal;
3882 stub_entry->target_value = sym_value;
3883 stub_entry->target_section = sym_sec;
3884 stub_entry->stub_type = stub_type;
3885 stub_entry->h = hash;
3886 stub_entry->st_type = st_type;
3888 if (sym_name == NULL)
3889 sym_name = "unnamed";
3890 stub_entry->output_name
3891 = bfd_alloc (htab->stub_bfd,
3892 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3893 + strlen (sym_name));
3894 if (stub_entry->output_name == NULL)
3896 free (stub_name);
3897 goto error_ret_free_internal;
3900 /* For historical reasons, use the existing names for
3901 ARM-to-Thumb and Thumb-to-ARM stubs. */
3902 if (r_type == (unsigned int) R_ARM_THM_CALL
3903 && st_type != STT_ARM_TFUNC)
3904 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3905 sym_name);
3906 else if (r_type == (unsigned int) R_ARM_CALL
3907 && st_type == STT_ARM_TFUNC)
3908 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3909 sym_name);
3910 else
3911 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3912 sym_name);
3914 stub_changed = TRUE;
3917 /* We're done with the internal relocs, free them. */
3918 if (elf_section_data (section)->relocs == NULL)
3919 free (internal_relocs);
3923 if (!stub_changed)
3924 break;
3926 /* OK, we've added some stubs. Find out the new size of the
3927 stub sections. */
3928 for (stub_sec = htab->stub_bfd->sections;
3929 stub_sec != NULL;
3930 stub_sec = stub_sec->next)
3931 stub_sec->size = 0;
3933 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3935 /* Ask the linker to do its stuff. */
3936 (*htab->layout_sections_again) ();
3937 stub_changed = FALSE;
3940 return TRUE;
3942 error_ret_free_local:
3943 return FALSE;
3946 /* Build all the stubs associated with the current output file. The
3947 stubs are kept in a hash table attached to the main linker hash
3948 table. We also set up the .plt entries for statically linked PIC
3949 functions here. This function is called via arm_elf_finish in the
3950 linker. */
3952 bfd_boolean
3953 elf32_arm_build_stubs (struct bfd_link_info *info)
3955 asection *stub_sec;
3956 struct bfd_hash_table *table;
3957 struct elf32_arm_link_hash_table *htab;
3959 htab = elf32_arm_hash_table (info);
3961 for (stub_sec = htab->stub_bfd->sections;
3962 stub_sec != NULL;
3963 stub_sec = stub_sec->next)
3965 bfd_size_type size;
3967 /* Ignore non-stub sections. */
3968 if (!strstr (stub_sec->name, STUB_SUFFIX))
3969 continue;
3971 /* Allocate memory to hold the linker stubs. */
3972 size = stub_sec->size;
3973 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3974 if (stub_sec->contents == NULL && size != 0)
3975 return FALSE;
3976 stub_sec->size = 0;
3979 /* Build the stubs as directed by the stub hash table. */
3980 table = &htab->stub_hash_table;
3981 bfd_hash_traverse (table, arm_build_one_stub, info);
3983 return TRUE;
3986 /* Locate the Thumb encoded calling stub for NAME. */
3988 static struct elf_link_hash_entry *
3989 find_thumb_glue (struct bfd_link_info *link_info,
3990 const char *name,
3991 char **error_message)
3993 char *tmp_name;
3994 struct elf_link_hash_entry *hash;
3995 struct elf32_arm_link_hash_table *hash_table;
3997 /* We need a pointer to the armelf specific hash table. */
3998 hash_table = elf32_arm_hash_table (link_info);
4000 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4001 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4003 BFD_ASSERT (tmp_name);
4005 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4007 hash = elf_link_hash_lookup
4008 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4010 if (hash == NULL
4011 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
4012 tmp_name, name) == -1)
4013 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4015 free (tmp_name);
4017 return hash;
4020 /* Locate the ARM encoded calling stub for NAME. */
4022 static struct elf_link_hash_entry *
4023 find_arm_glue (struct bfd_link_info *link_info,
4024 const char *name,
4025 char **error_message)
4027 char *tmp_name;
4028 struct elf_link_hash_entry *myh;
4029 struct elf32_arm_link_hash_table *hash_table;
4031 /* We need a pointer to the elfarm specific hash table. */
4032 hash_table = elf32_arm_hash_table (link_info);
4034 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4035 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4037 BFD_ASSERT (tmp_name);
4039 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4041 myh = elf_link_hash_lookup
4042 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4044 if (myh == NULL
4045 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
4046 tmp_name, name) == -1)
4047 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4049 free (tmp_name);
4051 return myh;
4054 /* ARM->Thumb glue (static images):
4056 .arm
4057 __func_from_arm:
4058 ldr r12, __func_addr
4059 bx r12
4060 __func_addr:
4061 .word func @ behave as if you saw a ARM_32 reloc.
4063 (v5t static images)
4064 .arm
4065 __func_from_arm:
4066 ldr pc, __func_addr
4067 __func_addr:
4068 .word func @ behave as if you saw a ARM_32 reloc.
4070 (relocatable images)
4071 .arm
4072 __func_from_arm:
4073 ldr r12, __func_offset
4074 add r12, r12, pc
4075 bx r12
4076 __func_offset:
4077 .word func - . */
4079 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4080 static const insn32 a2t1_ldr_insn = 0xe59fc000;
4081 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
4082 static const insn32 a2t3_func_addr_insn = 0x00000001;
4084 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4085 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
4086 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
4088 #define ARM2THUMB_PIC_GLUE_SIZE 16
4089 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
4090 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
4091 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
4093 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4095 .thumb .thumb
4096 .align 2 .align 2
4097 __func_from_thumb: __func_from_thumb:
4098 bx pc push {r6, lr}
4099 nop ldr r6, __func_addr
4100 .arm mov lr, pc
4101 b func bx r6
4102 .arm
4103 ;; back_to_thumb
4104 ldmia r13! {r6, lr}
4105 bx lr
4106 __func_addr:
4107 .word func */
4109 #define THUMB2ARM_GLUE_SIZE 8
4110 static const insn16 t2a1_bx_pc_insn = 0x4778;
4111 static const insn16 t2a2_noop_insn = 0x46c0;
4112 static const insn32 t2a3_b_insn = 0xea000000;
4114 #define VFP11_ERRATUM_VENEER_SIZE 8
4116 #define ARM_BX_VENEER_SIZE 12
4117 static const insn32 armbx1_tst_insn = 0xe3100001;
4118 static const insn32 armbx2_moveq_insn = 0x01a0f000;
4119 static const insn32 armbx3_bx_insn = 0xe12fff10;
4121 #ifndef ELFARM_NABI_C_INCLUDED
4122 static void
4123 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
4125 asection * s;
4126 bfd_byte * contents;
4128 if (size == 0)
4129 return;
4131 BFD_ASSERT (abfd != NULL);
4133 s = bfd_get_section_by_name (abfd, name);
4134 BFD_ASSERT (s != NULL);
4136 contents = bfd_alloc (abfd, size);
4138 BFD_ASSERT (s->size == size);
4139 s->contents = contents;
4142 bfd_boolean
4143 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
4145 struct elf32_arm_link_hash_table * globals;
4147 globals = elf32_arm_hash_table (info);
4148 BFD_ASSERT (globals != NULL);
4150 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4151 globals->arm_glue_size,
4152 ARM2THUMB_GLUE_SECTION_NAME);
4154 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4155 globals->thumb_glue_size,
4156 THUMB2ARM_GLUE_SECTION_NAME);
4158 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4159 globals->vfp11_erratum_glue_size,
4160 VFP11_ERRATUM_VENEER_SECTION_NAME);
4162 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4163 globals->bx_glue_size,
4164 ARM_BX_GLUE_SECTION_NAME);
4166 return TRUE;
4169 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4170 returns the symbol identifying the stub. */
4172 static struct elf_link_hash_entry *
4173 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
4174 struct elf_link_hash_entry * h)
4176 const char * name = h->root.root.string;
4177 asection * s;
4178 char * tmp_name;
4179 struct elf_link_hash_entry * myh;
4180 struct bfd_link_hash_entry * bh;
4181 struct elf32_arm_link_hash_table * globals;
4182 bfd_vma val;
4183 bfd_size_type size;
4185 globals = elf32_arm_hash_table (link_info);
4187 BFD_ASSERT (globals != NULL);
4188 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4190 s = bfd_get_section_by_name
4191 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
4193 BFD_ASSERT (s != NULL);
4195 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4197 BFD_ASSERT (tmp_name);
4199 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4201 myh = elf_link_hash_lookup
4202 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
4204 if (myh != NULL)
4206 /* We've already seen this guy. */
4207 free (tmp_name);
4208 return myh;
4211 /* The only trick here is using hash_table->arm_glue_size as the value.
4212 Even though the section isn't allocated yet, this is where we will be
4213 putting it. The +1 on the value marks that the stub has not been
4214 output yet - not that it is a Thumb function. */
4215 bh = NULL;
4216 val = globals->arm_glue_size + 1;
4217 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4218 tmp_name, BSF_GLOBAL, s, val,
4219 NULL, TRUE, FALSE, &bh);
4221 myh = (struct elf_link_hash_entry *) bh;
4222 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4223 myh->forced_local = 1;
4225 free (tmp_name);
4227 if (link_info->shared || globals->root.is_relocatable_executable
4228 || globals->pic_veneer)
4229 size = ARM2THUMB_PIC_GLUE_SIZE;
4230 else if (globals->use_blx)
4231 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
4232 else
4233 size = ARM2THUMB_STATIC_GLUE_SIZE;
4235 s->size += size;
4236 globals->arm_glue_size += size;
4238 return myh;
4241 static void
4242 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4243 struct elf_link_hash_entry *h)
4245 const char *name = h->root.root.string;
4246 asection *s;
4247 char *tmp_name;
4248 struct elf_link_hash_entry *myh;
4249 struct bfd_link_hash_entry *bh;
4250 struct elf32_arm_link_hash_table *hash_table;
4251 bfd_vma val;
4253 hash_table = elf32_arm_hash_table (link_info);
4255 BFD_ASSERT (hash_table != NULL);
4256 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4258 s = bfd_get_section_by_name
4259 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4261 BFD_ASSERT (s != NULL);
4263 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4264 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4266 BFD_ASSERT (tmp_name);
4268 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4270 myh = elf_link_hash_lookup
4271 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4273 if (myh != NULL)
4275 /* We've already seen this guy. */
4276 free (tmp_name);
4277 return;
4280 /* The only trick here is using hash_table->thumb_glue_size as the value.
4281 Even though the section isn't allocated yet, this is where we will be
4282 putting it. The +1 on the value marks that the stub has not been
4283 output yet - not that it is a Thumb function. */
4284 bh = NULL;
4285 val = hash_table->thumb_glue_size + 1;
4286 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4287 tmp_name, BSF_GLOBAL, s, val,
4288 NULL, TRUE, FALSE, &bh);
4290 /* If we mark it 'Thumb', the disassembler will do a better job. */
4291 myh = (struct elf_link_hash_entry *) bh;
4292 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4293 myh->forced_local = 1;
4295 free (tmp_name);
4297 #define CHANGE_TO_ARM "__%s_change_to_arm"
4298 #define BACK_FROM_ARM "__%s_back_from_arm"
4300 /* Allocate another symbol to mark where we switch to Arm mode. */
4301 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4302 + strlen (CHANGE_TO_ARM) + 1);
4304 BFD_ASSERT (tmp_name);
4306 sprintf (tmp_name, CHANGE_TO_ARM, name);
4308 bh = NULL;
4309 val = hash_table->thumb_glue_size + 4,
4310 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4311 tmp_name, BSF_LOCAL, s, val,
4312 NULL, TRUE, FALSE, &bh);
4314 free (tmp_name);
4316 s->size += THUMB2ARM_GLUE_SIZE;
4317 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
4321 /* Allocate space for ARMv4 BX veneers. */
4323 static void
4324 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4326 asection * s;
4327 struct elf32_arm_link_hash_table *globals;
4328 char *tmp_name;
4329 struct elf_link_hash_entry *myh;
4330 struct bfd_link_hash_entry *bh;
4331 bfd_vma val;
4333 /* BX PC does not need a veneer. */
4334 if (reg == 15)
4335 return;
4337 globals = elf32_arm_hash_table (link_info);
4339 BFD_ASSERT (globals != NULL);
4340 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4342 /* Check if this veneer has already been allocated. */
4343 if (globals->bx_glue_offset[reg])
4344 return;
4346 s = bfd_get_section_by_name
4347 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4349 BFD_ASSERT (s != NULL);
4351 /* Add symbol for veneer. */
4352 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
4354 BFD_ASSERT (tmp_name);
4356 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
4358 myh = elf_link_hash_lookup
4359 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
4361 BFD_ASSERT (myh == NULL);
4363 bh = NULL;
4364 val = globals->bx_glue_size;
4365 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4366 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4367 NULL, TRUE, FALSE, &bh);
4369 myh = (struct elf_link_hash_entry *) bh;
4370 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4371 myh->forced_local = 1;
4373 s->size += ARM_BX_VENEER_SIZE;
4374 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4375 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4379 /* Add an entry to the code/data map for section SEC. */
4381 static void
4382 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4384 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4385 unsigned int newidx;
4387 if (sec_data->map == NULL)
4389 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4390 sec_data->mapcount = 0;
4391 sec_data->mapsize = 1;
4394 newidx = sec_data->mapcount++;
4396 if (sec_data->mapcount > sec_data->mapsize)
4398 sec_data->mapsize *= 2;
4399 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4400 * sizeof (elf32_arm_section_map));
4403 if (sec_data->map)
4405 sec_data->map[newidx].vma = vma;
4406 sec_data->map[newidx].type = type;
4411 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4412 veneers are handled for now. */
4414 static bfd_vma
4415 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4416 elf32_vfp11_erratum_list *branch,
4417 bfd *branch_bfd,
4418 asection *branch_sec,
4419 unsigned int offset)
4421 asection *s;
4422 struct elf32_arm_link_hash_table *hash_table;
4423 char *tmp_name;
4424 struct elf_link_hash_entry *myh;
4425 struct bfd_link_hash_entry *bh;
4426 bfd_vma val;
4427 struct _arm_elf_section_data *sec_data;
4428 int errcount;
4429 elf32_vfp11_erratum_list *newerr;
4431 hash_table = elf32_arm_hash_table (link_info);
4433 BFD_ASSERT (hash_table != NULL);
4434 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4436 s = bfd_get_section_by_name
4437 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
4439 sec_data = elf32_arm_section_data (s);
4441 BFD_ASSERT (s != NULL);
4443 tmp_name = bfd_malloc ((bfd_size_type) strlen
4444 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
4446 BFD_ASSERT (tmp_name);
4448 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4449 hash_table->num_vfp11_fixes);
4451 myh = elf_link_hash_lookup
4452 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4454 BFD_ASSERT (myh == NULL);
4456 bh = NULL;
4457 val = hash_table->vfp11_erratum_glue_size;
4458 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4459 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4460 NULL, TRUE, FALSE, &bh);
4462 myh = (struct elf_link_hash_entry *) bh;
4463 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4464 myh->forced_local = 1;
4466 /* Link veneer back to calling location. */
4467 errcount = ++(sec_data->erratumcount);
4468 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
4470 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4471 newerr->vma = -1;
4472 newerr->u.v.branch = branch;
4473 newerr->u.v.id = hash_table->num_vfp11_fixes;
4474 branch->u.b.veneer = newerr;
4476 newerr->next = sec_data->erratumlist;
4477 sec_data->erratumlist = newerr;
4479 /* A symbol for the return from the veneer. */
4480 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4481 hash_table->num_vfp11_fixes);
4483 myh = elf_link_hash_lookup
4484 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4486 if (myh != NULL)
4487 abort ();
4489 bh = NULL;
4490 val = offset + 4;
4491 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4492 branch_sec, val, NULL, TRUE, FALSE, &bh);
4494 myh = (struct elf_link_hash_entry *) bh;
4495 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4496 myh->forced_local = 1;
4498 free (tmp_name);
4500 /* Generate a mapping symbol for the veneer section, and explicitly add an
4501 entry for that symbol to the code/data map for the section. */
4502 if (hash_table->vfp11_erratum_glue_size == 0)
4504 bh = NULL;
4505 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4506 ever requires this erratum fix. */
4507 _bfd_generic_link_add_one_symbol (link_info,
4508 hash_table->bfd_of_glue_owner, "$a",
4509 BSF_LOCAL, s, 0, NULL,
4510 TRUE, FALSE, &bh);
4512 myh = (struct elf_link_hash_entry *) bh;
4513 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4514 myh->forced_local = 1;
4516 /* The elf32_arm_init_maps function only cares about symbols from input
4517 BFDs. We must make a note of this generated mapping symbol
4518 ourselves so that code byteswapping works properly in
4519 elf32_arm_write_section. */
4520 elf32_arm_section_map_add (s, 'a', 0);
4523 s->size += VFP11_ERRATUM_VENEER_SIZE;
4524 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4525 hash_table->num_vfp11_fixes++;
4527 /* The offset of the veneer. */
4528 return val;
4531 /* Note: we do not include the flag SEC_LINKER_CREATED, as that
4532 would prevent elf_link_input_bfd() from processing the contents
4533 of the section. */
4534 #define ARM_GLUE_SECTION_FLAGS \
4535 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY)
4537 /* Create a fake section for use by the ARM backend of the linker. */
4539 static bfd_boolean
4540 arm_make_glue_section (bfd * abfd, const char * name)
4542 asection * sec;
4544 sec = bfd_get_section_by_name (abfd, name);
4545 if (sec != NULL)
4546 /* Already made. */
4547 return TRUE;
4549 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
4551 if (sec == NULL
4552 || !bfd_set_section_alignment (abfd, sec, 2))
4553 return FALSE;
4555 /* Set the gc mark to prevent the section from being removed by garbage
4556 collection, despite the fact that no relocs refer to this section. */
4557 sec->gc_mark = 1;
4559 return TRUE;
4562 /* Add the glue sections to ABFD. This function is called from the
4563 linker scripts in ld/emultempl/{armelf}.em. */
4565 bfd_boolean
4566 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4567 struct bfd_link_info *info)
4569 /* If we are only performing a partial
4570 link do not bother adding the glue. */
4571 if (info->relocatable)
4572 return TRUE;
4574 /* Linker stubs don't need glue. */
4575 if (!strcmp (abfd->filename, "linker stubs"))
4576 return TRUE;
4578 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
4579 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
4580 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
4581 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
4584 /* Select a BFD to be used to hold the sections used by the glue code.
4585 This function is called from the linker scripts in ld/emultempl/
4586 {armelf/pe}.em. */
4588 bfd_boolean
4589 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
4591 struct elf32_arm_link_hash_table *globals;
4593 /* If we are only performing a partial link
4594 do not bother getting a bfd to hold the glue. */
4595 if (info->relocatable)
4596 return TRUE;
4598 /* Make sure we don't attach the glue sections to a dynamic object. */
4599 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4601 globals = elf32_arm_hash_table (info);
4603 BFD_ASSERT (globals != NULL);
4605 if (globals->bfd_of_glue_owner != NULL)
4606 return TRUE;
4608 /* Save the bfd for later use. */
4609 globals->bfd_of_glue_owner = abfd;
4611 return TRUE;
4614 static void
4615 check_use_blx (struct elf32_arm_link_hash_table *globals)
4617 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4618 Tag_CPU_arch) > 2)
4619 globals->use_blx = 1;
4622 bfd_boolean
4623 bfd_elf32_arm_process_before_allocation (bfd *abfd,
4624 struct bfd_link_info *link_info)
4626 Elf_Internal_Shdr *symtab_hdr;
4627 Elf_Internal_Rela *internal_relocs = NULL;
4628 Elf_Internal_Rela *irel, *irelend;
4629 bfd_byte *contents = NULL;
4631 asection *sec;
4632 struct elf32_arm_link_hash_table *globals;
4634 /* If we are only performing a partial link do not bother
4635 to construct any glue. */
4636 if (link_info->relocatable)
4637 return TRUE;
4639 /* Here we have a bfd that is to be included on the link. We have a
4640 hook to do reloc rummaging, before section sizes are nailed down. */
4641 globals = elf32_arm_hash_table (link_info);
4643 BFD_ASSERT (globals != NULL);
4645 check_use_blx (globals);
4647 if (globals->byteswap_code && !bfd_big_endian (abfd))
4649 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4650 abfd);
4651 return FALSE;
4654 /* PR 5398: If we have not decided to include any loadable sections in
4655 the output then we will not have a glue owner bfd. This is OK, it
4656 just means that there is nothing else for us to do here. */
4657 if (globals->bfd_of_glue_owner == NULL)
4658 return TRUE;
4660 /* Rummage around all the relocs and map the glue vectors. */
4661 sec = abfd->sections;
4663 if (sec == NULL)
4664 return TRUE;
4666 for (; sec != NULL; sec = sec->next)
4668 if (sec->reloc_count == 0)
4669 continue;
4671 if ((sec->flags & SEC_EXCLUDE) != 0)
4672 continue;
4674 symtab_hdr = & elf_symtab_hdr (abfd);
4676 /* Load the relocs. */
4677 internal_relocs
4678 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
4680 if (internal_relocs == NULL)
4681 goto error_return;
4683 irelend = internal_relocs + sec->reloc_count;
4684 for (irel = internal_relocs; irel < irelend; irel++)
4686 long r_type;
4687 unsigned long r_index;
4689 struct elf_link_hash_entry *h;
4691 r_type = ELF32_R_TYPE (irel->r_info);
4692 r_index = ELF32_R_SYM (irel->r_info);
4694 /* These are the only relocation types we care about. */
4695 if ( r_type != R_ARM_PC24
4696 && r_type != R_ARM_PLT32
4697 && r_type != R_ARM_JUMP24
4698 && r_type != R_ARM_THM_JUMP24
4699 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
4700 continue;
4702 /* Get the section contents if we haven't done so already. */
4703 if (contents == NULL)
4705 /* Get cached copy if it exists. */
4706 if (elf_section_data (sec)->this_hdr.contents != NULL)
4707 contents = elf_section_data (sec)->this_hdr.contents;
4708 else
4710 /* Go get them off disk. */
4711 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
4712 goto error_return;
4716 if (r_type == R_ARM_V4BX)
4718 int reg;
4720 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4721 record_arm_bx_glue (link_info, reg);
4722 continue;
4725 /* If the relocation is not against a symbol it cannot concern us. */
4726 h = NULL;
4728 /* We don't care about local symbols. */
4729 if (r_index < symtab_hdr->sh_info)
4730 continue;
4732 /* This is an external symbol. */
4733 r_index -= symtab_hdr->sh_info;
4734 h = (struct elf_link_hash_entry *)
4735 elf_sym_hashes (abfd)[r_index];
4737 /* If the relocation is against a static symbol it must be within
4738 the current section and so cannot be a cross ARM/Thumb relocation. */
4739 if (h == NULL)
4740 continue;
4742 /* If the call will go through a PLT entry then we do not need
4743 glue. */
4744 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
4745 continue;
4747 switch (r_type)
4749 case R_ARM_PC24:
4750 case R_ARM_PLT32:
4751 case R_ARM_JUMP24:
4752 /* This one is a call from arm code. We need to look up
4753 the target of the call. If it is a thumb target, we
4754 insert glue. */
4755 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
4756 record_arm_to_thumb_glue (link_info, h);
4757 break;
4759 case R_ARM_THM_JUMP24:
4760 /* This one is a call from thumb code. We look
4761 up the target of the call. If it is not a thumb
4762 target, we insert glue. */
4763 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4764 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
4765 && h->root.type != bfd_link_hash_undefweak)
4766 record_thumb_to_arm_glue (link_info, h);
4767 break;
4769 default:
4770 abort ();
4774 if (contents != NULL
4775 && elf_section_data (sec)->this_hdr.contents != contents)
4776 free (contents);
4777 contents = NULL;
4779 if (internal_relocs != NULL
4780 && elf_section_data (sec)->relocs != internal_relocs)
4781 free (internal_relocs);
4782 internal_relocs = NULL;
4785 return TRUE;
4787 error_return:
4788 if (contents != NULL
4789 && elf_section_data (sec)->this_hdr.contents != contents)
4790 free (contents);
4791 if (internal_relocs != NULL
4792 && elf_section_data (sec)->relocs != internal_relocs)
4793 free (internal_relocs);
4795 return FALSE;
4797 #endif
4800 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4802 void
4803 bfd_elf32_arm_init_maps (bfd *abfd)
4805 Elf_Internal_Sym *isymbuf;
4806 Elf_Internal_Shdr *hdr;
4807 unsigned int i, localsyms;
4809 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4810 if (! is_arm_elf (abfd))
4811 return;
4813 if ((abfd->flags & DYNAMIC) != 0)
4814 return;
4816 hdr = & elf_symtab_hdr (abfd);
4817 localsyms = hdr->sh_info;
4819 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4820 should contain the number of local symbols, which should come before any
4821 global symbols. Mapping symbols are always local. */
4822 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4823 NULL);
4825 /* No internal symbols read? Skip this BFD. */
4826 if (isymbuf == NULL)
4827 return;
4829 for (i = 0; i < localsyms; i++)
4831 Elf_Internal_Sym *isym = &isymbuf[i];
4832 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4833 const char *name;
4835 if (sec != NULL
4836 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4838 name = bfd_elf_string_from_elf_section (abfd,
4839 hdr->sh_link, isym->st_name);
4841 if (bfd_is_arm_special_symbol_name (name,
4842 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4843 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4849 void
4850 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4852 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4853 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
4855 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4856 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4858 switch (globals->vfp11_fix)
4860 case BFD_ARM_VFP11_FIX_DEFAULT:
4861 case BFD_ARM_VFP11_FIX_NONE:
4862 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4863 break;
4865 default:
4866 /* Give a warning, but do as the user requests anyway. */
4867 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4868 "workaround is not necessary for target architecture"), obfd);
4871 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4872 /* For earlier architectures, we might need the workaround, but do not
4873 enable it by default. If users is running with broken hardware, they
4874 must enable the erratum fix explicitly. */
4875 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4879 enum bfd_arm_vfp11_pipe
4881 VFP11_FMAC,
4882 VFP11_LS,
4883 VFP11_DS,
4884 VFP11_BAD
4887 /* Return a VFP register number. This is encoded as RX:X for single-precision
4888 registers, or X:RX for double-precision registers, where RX is the group of
4889 four bits in the instruction encoding and X is the single extension bit.
4890 RX and X fields are specified using their lowest (starting) bit. The return
4891 value is:
4893 0...31: single-precision registers s0...s31
4894 32...63: double-precision registers d0...d31.
4896 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4897 encounter VFP3 instructions, so we allow the full range for DP registers. */
4899 static unsigned int
4900 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4901 unsigned int x)
4903 if (is_double)
4904 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4905 else
4906 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4909 /* Set bits in *WMASK according to a register number REG as encoded by
4910 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4912 static void
4913 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4915 if (reg < 32)
4916 *wmask |= 1 << reg;
4917 else if (reg < 48)
4918 *wmask |= 3 << ((reg - 32) * 2);
4921 /* Return TRUE if WMASK overwrites anything in REGS. */
4923 static bfd_boolean
4924 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4926 int i;
4928 for (i = 0; i < numregs; i++)
4930 unsigned int reg = regs[i];
4932 if (reg < 32 && (wmask & (1 << reg)) != 0)
4933 return TRUE;
4935 reg -= 32;
4937 if (reg >= 16)
4938 continue;
4940 if ((wmask & (3 << (reg * 2))) != 0)
4941 return TRUE;
4944 return FALSE;
4947 /* In this function, we're interested in two things: finding input registers
4948 for VFP data-processing instructions, and finding the set of registers which
4949 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4950 hold the written set, so FLDM etc. are easy to deal with (we're only
4951 interested in 32 SP registers or 16 dp registers, due to the VFP version
4952 implemented by the chip in question). DP registers are marked by setting
4953 both SP registers in the write mask). */
4955 static enum bfd_arm_vfp11_pipe
4956 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4957 int *numregs)
4959 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4960 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4962 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4964 unsigned int pqrs;
4965 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4966 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4968 pqrs = ((insn & 0x00800000) >> 20)
4969 | ((insn & 0x00300000) >> 19)
4970 | ((insn & 0x00000040) >> 6);
4972 switch (pqrs)
4974 case 0: /* fmac[sd]. */
4975 case 1: /* fnmac[sd]. */
4976 case 2: /* fmsc[sd]. */
4977 case 3: /* fnmsc[sd]. */
4978 pipe = VFP11_FMAC;
4979 bfd_arm_vfp11_write_mask (destmask, fd);
4980 regs[0] = fd;
4981 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4982 regs[2] = fm;
4983 *numregs = 3;
4984 break;
4986 case 4: /* fmul[sd]. */
4987 case 5: /* fnmul[sd]. */
4988 case 6: /* fadd[sd]. */
4989 case 7: /* fsub[sd]. */
4990 pipe = VFP11_FMAC;
4991 goto vfp_binop;
4993 case 8: /* fdiv[sd]. */
4994 pipe = VFP11_DS;
4995 vfp_binop:
4996 bfd_arm_vfp11_write_mask (destmask, fd);
4997 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4998 regs[1] = fm;
4999 *numregs = 2;
5000 break;
5002 case 15: /* extended opcode. */
5004 unsigned int extn = ((insn >> 15) & 0x1e)
5005 | ((insn >> 7) & 1);
5007 switch (extn)
5009 case 0: /* fcpy[sd]. */
5010 case 1: /* fabs[sd]. */
5011 case 2: /* fneg[sd]. */
5012 case 8: /* fcmp[sd]. */
5013 case 9: /* fcmpe[sd]. */
5014 case 10: /* fcmpz[sd]. */
5015 case 11: /* fcmpez[sd]. */
5016 case 16: /* fuito[sd]. */
5017 case 17: /* fsito[sd]. */
5018 case 24: /* ftoui[sd]. */
5019 case 25: /* ftouiz[sd]. */
5020 case 26: /* ftosi[sd]. */
5021 case 27: /* ftosiz[sd]. */
5022 /* These instructions will not bounce due to underflow. */
5023 *numregs = 0;
5024 pipe = VFP11_FMAC;
5025 break;
5027 case 3: /* fsqrt[sd]. */
5028 /* fsqrt cannot underflow, but it can (perhaps) overwrite
5029 registers to cause the erratum in previous instructions. */
5030 bfd_arm_vfp11_write_mask (destmask, fd);
5031 pipe = VFP11_DS;
5032 break;
5034 case 15: /* fcvt{ds,sd}. */
5036 int rnum = 0;
5038 bfd_arm_vfp11_write_mask (destmask, fd);
5040 /* Only FCVTSD can underflow. */
5041 if ((insn & 0x100) != 0)
5042 regs[rnum++] = fm;
5044 *numregs = rnum;
5046 pipe = VFP11_FMAC;
5048 break;
5050 default:
5051 return VFP11_BAD;
5054 break;
5056 default:
5057 return VFP11_BAD;
5060 /* Two-register transfer. */
5061 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
5063 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
5065 if ((insn & 0x100000) == 0)
5067 if (is_double)
5068 bfd_arm_vfp11_write_mask (destmask, fm);
5069 else
5071 bfd_arm_vfp11_write_mask (destmask, fm);
5072 bfd_arm_vfp11_write_mask (destmask, fm + 1);
5076 pipe = VFP11_LS;
5078 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
5080 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
5081 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
5083 switch (puw)
5085 case 0: /* Two-reg transfer. We should catch these above. */
5086 abort ();
5088 case 2: /* fldm[sdx]. */
5089 case 3:
5090 case 5:
5092 unsigned int i, offset = insn & 0xff;
5094 if (is_double)
5095 offset >>= 1;
5097 for (i = fd; i < fd + offset; i++)
5098 bfd_arm_vfp11_write_mask (destmask, i);
5100 break;
5102 case 4: /* fld[sd]. */
5103 case 6:
5104 bfd_arm_vfp11_write_mask (destmask, fd);
5105 break;
5107 default:
5108 return VFP11_BAD;
5111 pipe = VFP11_LS;
5113 /* Single-register transfer. Note L==0. */
5114 else if ((insn & 0x0f100e10) == 0x0e000a10)
5116 unsigned int opcode = (insn >> 21) & 7;
5117 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
5119 switch (opcode)
5121 case 0: /* fmsr/fmdlr. */
5122 case 1: /* fmdhr. */
5123 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5124 destination register. I don't know if this is exactly right,
5125 but it is the conservative choice. */
5126 bfd_arm_vfp11_write_mask (destmask, fn);
5127 break;
5129 case 7: /* fmxr. */
5130 break;
5133 pipe = VFP11_LS;
5136 return pipe;
5140 static int elf32_arm_compare_mapping (const void * a, const void * b);
5143 /* Look for potentially-troublesome code sequences which might trigger the
5144 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5145 (available from ARM) for details of the erratum. A short version is
5146 described in ld.texinfo. */
5148 bfd_boolean
5149 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
5151 asection *sec;
5152 bfd_byte *contents = NULL;
5153 int state = 0;
5154 int regs[3], numregs = 0;
5155 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
5156 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
5158 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5159 The states transition as follows:
5161 0 -> 1 (vector) or 0 -> 2 (scalar)
5162 A VFP FMAC-pipeline instruction has been seen. Fill
5163 regs[0]..regs[numregs-1] with its input operands. Remember this
5164 instruction in 'first_fmac'.
5166 1 -> 2
5167 Any instruction, except for a VFP instruction which overwrites
5168 regs[*].
5170 1 -> 3 [ -> 0 ] or
5171 2 -> 3 [ -> 0 ]
5172 A VFP instruction has been seen which overwrites any of regs[*].
5173 We must make a veneer! Reset state to 0 before examining next
5174 instruction.
5176 2 -> 0
5177 If we fail to match anything in state 2, reset to state 0 and reset
5178 the instruction pointer to the instruction after 'first_fmac'.
5180 If the VFP11 vector mode is in use, there must be at least two unrelated
5181 instructions between anti-dependent VFP11 instructions to properly avoid
5182 triggering the erratum, hence the use of the extra state 1. */
5184 /* If we are only performing a partial link do not bother
5185 to construct any glue. */
5186 if (link_info->relocatable)
5187 return TRUE;
5189 /* Skip if this bfd does not correspond to an ELF image. */
5190 if (! is_arm_elf (abfd))
5191 return TRUE;
5193 /* We should have chosen a fix type by the time we get here. */
5194 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5196 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5197 return TRUE;
5199 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5200 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
5201 return TRUE;
5203 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5205 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5206 struct _arm_elf_section_data *sec_data;
5208 /* If we don't have executable progbits, we're not interested in this
5209 section. Also skip if section is to be excluded. */
5210 if (elf_section_type (sec) != SHT_PROGBITS
5211 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5212 || (sec->flags & SEC_EXCLUDE) != 0
5213 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
5214 || sec->output_section == bfd_abs_section_ptr
5215 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5216 continue;
5218 sec_data = elf32_arm_section_data (sec);
5220 if (sec_data->mapcount == 0)
5221 continue;
5223 if (elf_section_data (sec)->this_hdr.contents != NULL)
5224 contents = elf_section_data (sec)->this_hdr.contents;
5225 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5226 goto error_return;
5228 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5229 elf32_arm_compare_mapping);
5231 for (span = 0; span < sec_data->mapcount; span++)
5233 unsigned int span_start = sec_data->map[span].vma;
5234 unsigned int span_end = (span == sec_data->mapcount - 1)
5235 ? sec->size : sec_data->map[span + 1].vma;
5236 char span_type = sec_data->map[span].type;
5238 /* FIXME: Only ARM mode is supported at present. We may need to
5239 support Thumb-2 mode also at some point. */
5240 if (span_type != 'a')
5241 continue;
5243 for (i = span_start; i < span_end;)
5245 unsigned int next_i = i + 4;
5246 unsigned int insn = bfd_big_endian (abfd)
5247 ? (contents[i] << 24)
5248 | (contents[i + 1] << 16)
5249 | (contents[i + 2] << 8)
5250 | contents[i + 3]
5251 : (contents[i + 3] << 24)
5252 | (contents[i + 2] << 16)
5253 | (contents[i + 1] << 8)
5254 | contents[i];
5255 unsigned int writemask = 0;
5256 enum bfd_arm_vfp11_pipe pipe;
5258 switch (state)
5260 case 0:
5261 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5262 &numregs);
5263 /* I'm assuming the VFP11 erratum can trigger with denorm
5264 operands on either the FMAC or the DS pipeline. This might
5265 lead to slightly overenthusiastic veneer insertion. */
5266 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5268 state = use_vector ? 1 : 2;
5269 first_fmac = i;
5270 veneer_of_insn = insn;
5272 break;
5274 case 1:
5276 int other_regs[3], other_numregs;
5277 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5278 other_regs,
5279 &other_numregs);
5280 if (pipe != VFP11_BAD
5281 && bfd_arm_vfp11_antidependency (writemask, regs,
5282 numregs))
5283 state = 3;
5284 else
5285 state = 2;
5287 break;
5289 case 2:
5291 int other_regs[3], other_numregs;
5292 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5293 other_regs,
5294 &other_numregs);
5295 if (pipe != VFP11_BAD
5296 && bfd_arm_vfp11_antidependency (writemask, regs,
5297 numregs))
5298 state = 3;
5299 else
5301 state = 0;
5302 next_i = first_fmac + 4;
5305 break;
5307 case 3:
5308 abort (); /* Should be unreachable. */
5311 if (state == 3)
5313 elf32_vfp11_erratum_list *newerr
5314 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5315 int errcount;
5317 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5319 newerr->u.b.vfp_insn = veneer_of_insn;
5321 switch (span_type)
5323 case 'a':
5324 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5325 break;
5327 default:
5328 abort ();
5331 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5332 first_fmac);
5334 newerr->vma = -1;
5336 newerr->next = sec_data->erratumlist;
5337 sec_data->erratumlist = newerr;
5339 state = 0;
5342 i = next_i;
5346 if (contents != NULL
5347 && elf_section_data (sec)->this_hdr.contents != contents)
5348 free (contents);
5349 contents = NULL;
5352 return TRUE;
5354 error_return:
5355 if (contents != NULL
5356 && elf_section_data (sec)->this_hdr.contents != contents)
5357 free (contents);
5359 return FALSE;
5362 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5363 after sections have been laid out, using specially-named symbols. */
5365 void
5366 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5367 struct bfd_link_info *link_info)
5369 asection *sec;
5370 struct elf32_arm_link_hash_table *globals;
5371 char *tmp_name;
5373 if (link_info->relocatable)
5374 return;
5376 /* Skip if this bfd does not correspond to an ELF image. */
5377 if (! is_arm_elf (abfd))
5378 return;
5380 globals = elf32_arm_hash_table (link_info);
5382 tmp_name = bfd_malloc ((bfd_size_type) strlen
5383 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5385 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5387 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5388 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
5390 for (; errnode != NULL; errnode = errnode->next)
5392 struct elf_link_hash_entry *myh;
5393 bfd_vma vma;
5395 switch (errnode->type)
5397 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5398 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5399 /* Find veneer symbol. */
5400 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5401 errnode->u.b.veneer->u.v.id);
5403 myh = elf_link_hash_lookup
5404 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5406 if (myh == NULL)
5407 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5408 "`%s'"), abfd, tmp_name);
5410 vma = myh->root.u.def.section->output_section->vma
5411 + myh->root.u.def.section->output_offset
5412 + myh->root.u.def.value;
5414 errnode->u.b.veneer->vma = vma;
5415 break;
5417 case VFP11_ERRATUM_ARM_VENEER:
5418 case VFP11_ERRATUM_THUMB_VENEER:
5419 /* Find return location. */
5420 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5421 errnode->u.v.id);
5423 myh = elf_link_hash_lookup
5424 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5426 if (myh == NULL)
5427 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5428 "`%s'"), abfd, tmp_name);
5430 vma = myh->root.u.def.section->output_section->vma
5431 + myh->root.u.def.section->output_offset
5432 + myh->root.u.def.value;
5434 errnode->u.v.branch->vma = vma;
5435 break;
5437 default:
5438 abort ();
5443 free (tmp_name);
5447 /* Set target relocation values needed during linking. */
5449 void
5450 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5451 struct bfd_link_info *link_info,
5452 int target1_is_rel,
5453 char * target2_type,
5454 int fix_v4bx,
5455 int use_blx,
5456 bfd_arm_vfp11_fix vfp11_fix,
5457 int no_enum_warn, int no_wchar_warn,
5458 int pic_veneer)
5460 struct elf32_arm_link_hash_table *globals;
5462 globals = elf32_arm_hash_table (link_info);
5464 globals->target1_is_rel = target1_is_rel;
5465 if (strcmp (target2_type, "rel") == 0)
5466 globals->target2_reloc = R_ARM_REL32;
5467 else if (strcmp (target2_type, "abs") == 0)
5468 globals->target2_reloc = R_ARM_ABS32;
5469 else if (strcmp (target2_type, "got-rel") == 0)
5470 globals->target2_reloc = R_ARM_GOT_PREL;
5471 else
5473 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5474 target2_type);
5476 globals->fix_v4bx = fix_v4bx;
5477 globals->use_blx |= use_blx;
5478 globals->vfp11_fix = vfp11_fix;
5479 globals->pic_veneer = pic_veneer;
5481 BFD_ASSERT (is_arm_elf (output_bfd));
5482 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
5483 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
5486 /* Replace the target offset of a Thumb bl or b.w instruction. */
5488 static void
5489 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5491 bfd_vma upper;
5492 bfd_vma lower;
5493 int reloc_sign;
5495 BFD_ASSERT ((offset & 1) == 0);
5497 upper = bfd_get_16 (abfd, insn);
5498 lower = bfd_get_16 (abfd, insn + 2);
5499 reloc_sign = (offset < 0) ? 1 : 0;
5500 upper = (upper & ~(bfd_vma) 0x7ff)
5501 | ((offset >> 12) & 0x3ff)
5502 | (reloc_sign << 10);
5503 lower = (lower & ~(bfd_vma) 0x2fff)
5504 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5505 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5506 | ((offset >> 1) & 0x7ff);
5507 bfd_put_16 (abfd, upper, insn);
5508 bfd_put_16 (abfd, lower, insn + 2);
5511 /* Thumb code calling an ARM function. */
5513 static int
5514 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5515 const char * name,
5516 bfd * input_bfd,
5517 bfd * output_bfd,
5518 asection * input_section,
5519 bfd_byte * hit_data,
5520 asection * sym_sec,
5521 bfd_vma offset,
5522 bfd_signed_vma addend,
5523 bfd_vma val,
5524 char **error_message)
5526 asection * s = 0;
5527 bfd_vma my_offset;
5528 long int ret_offset;
5529 struct elf_link_hash_entry * myh;
5530 struct elf32_arm_link_hash_table * globals;
5532 myh = find_thumb_glue (info, name, error_message);
5533 if (myh == NULL)
5534 return FALSE;
5536 globals = elf32_arm_hash_table (info);
5538 BFD_ASSERT (globals != NULL);
5539 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5541 my_offset = myh->root.u.def.value;
5543 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5544 THUMB2ARM_GLUE_SECTION_NAME);
5546 BFD_ASSERT (s != NULL);
5547 BFD_ASSERT (s->contents != NULL);
5548 BFD_ASSERT (s->output_section != NULL);
5550 if ((my_offset & 0x01) == 0x01)
5552 if (sym_sec != NULL
5553 && sym_sec->owner != NULL
5554 && !INTERWORK_FLAG (sym_sec->owner))
5556 (*_bfd_error_handler)
5557 (_("%B(%s): warning: interworking not enabled.\n"
5558 " first occurrence: %B: thumb call to arm"),
5559 sym_sec->owner, input_bfd, name);
5561 return FALSE;
5564 --my_offset;
5565 myh->root.u.def.value = my_offset;
5567 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5568 s->contents + my_offset);
5570 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5571 s->contents + my_offset + 2);
5573 ret_offset =
5574 /* Address of destination of the stub. */
5575 ((bfd_signed_vma) val)
5576 - ((bfd_signed_vma)
5577 /* Offset from the start of the current section
5578 to the start of the stubs. */
5579 (s->output_offset
5580 /* Offset of the start of this stub from the start of the stubs. */
5581 + my_offset
5582 /* Address of the start of the current section. */
5583 + s->output_section->vma)
5584 /* The branch instruction is 4 bytes into the stub. */
5586 /* ARM branches work from the pc of the instruction + 8. */
5587 + 8);
5589 put_arm_insn (globals, output_bfd,
5590 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5591 s->contents + my_offset + 4);
5594 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5596 /* Now go back and fix up the original BL insn to point to here. */
5597 ret_offset =
5598 /* Address of where the stub is located. */
5599 (s->output_section->vma + s->output_offset + my_offset)
5600 /* Address of where the BL is located. */
5601 - (input_section->output_section->vma + input_section->output_offset
5602 + offset)
5603 /* Addend in the relocation. */
5604 - addend
5605 /* Biassing for PC-relative addressing. */
5606 - 8;
5608 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
5610 return TRUE;
5613 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5615 static struct elf_link_hash_entry *
5616 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5617 const char * name,
5618 bfd * input_bfd,
5619 bfd * output_bfd,
5620 asection * sym_sec,
5621 bfd_vma val,
5622 asection * s,
5623 char ** error_message)
5625 bfd_vma my_offset;
5626 long int ret_offset;
5627 struct elf_link_hash_entry * myh;
5628 struct elf32_arm_link_hash_table * globals;
5630 myh = find_arm_glue (info, name, error_message);
5631 if (myh == NULL)
5632 return NULL;
5634 globals = elf32_arm_hash_table (info);
5636 BFD_ASSERT (globals != NULL);
5637 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5639 my_offset = myh->root.u.def.value;
5641 if ((my_offset & 0x01) == 0x01)
5643 if (sym_sec != NULL
5644 && sym_sec->owner != NULL
5645 && !INTERWORK_FLAG (sym_sec->owner))
5647 (*_bfd_error_handler)
5648 (_("%B(%s): warning: interworking not enabled.\n"
5649 " first occurrence: %B: arm call to thumb"),
5650 sym_sec->owner, input_bfd, name);
5653 --my_offset;
5654 myh->root.u.def.value = my_offset;
5656 if (info->shared || globals->root.is_relocatable_executable
5657 || globals->pic_veneer)
5659 /* For relocatable objects we can't use absolute addresses,
5660 so construct the address from a relative offset. */
5661 /* TODO: If the offset is small it's probably worth
5662 constructing the address with adds. */
5663 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5664 s->contents + my_offset);
5665 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5666 s->contents + my_offset + 4);
5667 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5668 s->contents + my_offset + 8);
5669 /* Adjust the offset by 4 for the position of the add,
5670 and 8 for the pipeline offset. */
5671 ret_offset = (val - (s->output_offset
5672 + s->output_section->vma
5673 + my_offset + 12))
5674 | 1;
5675 bfd_put_32 (output_bfd, ret_offset,
5676 s->contents + my_offset + 12);
5678 else if (globals->use_blx)
5680 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5681 s->contents + my_offset);
5683 /* It's a thumb address. Add the low order bit. */
5684 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5685 s->contents + my_offset + 4);
5687 else
5689 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5690 s->contents + my_offset);
5692 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5693 s->contents + my_offset + 4);
5695 /* It's a thumb address. Add the low order bit. */
5696 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5697 s->contents + my_offset + 8);
5699 my_offset += 12;
5703 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5705 return myh;
5708 /* Arm code calling a Thumb function. */
5710 static int
5711 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5712 const char * name,
5713 bfd * input_bfd,
5714 bfd * output_bfd,
5715 asection * input_section,
5716 bfd_byte * hit_data,
5717 asection * sym_sec,
5718 bfd_vma offset,
5719 bfd_signed_vma addend,
5720 bfd_vma val,
5721 char **error_message)
5723 unsigned long int tmp;
5724 bfd_vma my_offset;
5725 asection * s;
5726 long int ret_offset;
5727 struct elf_link_hash_entry * myh;
5728 struct elf32_arm_link_hash_table * globals;
5730 globals = elf32_arm_hash_table (info);
5732 BFD_ASSERT (globals != NULL);
5733 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5735 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5736 ARM2THUMB_GLUE_SECTION_NAME);
5737 BFD_ASSERT (s != NULL);
5738 BFD_ASSERT (s->contents != NULL);
5739 BFD_ASSERT (s->output_section != NULL);
5741 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
5742 sym_sec, val, s, error_message);
5743 if (!myh)
5744 return FALSE;
5746 my_offset = myh->root.u.def.value;
5747 tmp = bfd_get_32 (input_bfd, hit_data);
5748 tmp = tmp & 0xFF000000;
5750 /* Somehow these are both 4 too far, so subtract 8. */
5751 ret_offset = (s->output_offset
5752 + my_offset
5753 + s->output_section->vma
5754 - (input_section->output_offset
5755 + input_section->output_section->vma
5756 + offset + addend)
5757 - 8);
5759 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5761 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
5763 return TRUE;
5766 /* Populate Arm stub for an exported Thumb function. */
5768 static bfd_boolean
5769 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5771 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5772 asection * s;
5773 struct elf_link_hash_entry * myh;
5774 struct elf32_arm_link_hash_entry *eh;
5775 struct elf32_arm_link_hash_table * globals;
5776 asection *sec;
5777 bfd_vma val;
5778 char *error_message;
5780 eh = elf32_arm_hash_entry (h);
5781 /* Allocate stubs for exported Thumb functions on v4t. */
5782 if (eh->export_glue == NULL)
5783 return TRUE;
5785 globals = elf32_arm_hash_table (info);
5787 BFD_ASSERT (globals != NULL);
5788 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5790 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5791 ARM2THUMB_GLUE_SECTION_NAME);
5792 BFD_ASSERT (s != NULL);
5793 BFD_ASSERT (s->contents != NULL);
5794 BFD_ASSERT (s->output_section != NULL);
5796 sec = eh->export_glue->root.u.def.section;
5798 BFD_ASSERT (sec->output_section != NULL);
5800 val = eh->export_glue->root.u.def.value + sec->output_offset
5801 + sec->output_section->vma;
5803 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5804 h->root.u.def.section->owner,
5805 globals->obfd, sec, val, s,
5806 &error_message);
5807 BFD_ASSERT (myh);
5808 return TRUE;
5811 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5813 static bfd_vma
5814 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5816 bfd_byte *p;
5817 bfd_vma glue_addr;
5818 asection *s;
5819 struct elf32_arm_link_hash_table *globals;
5821 globals = elf32_arm_hash_table (info);
5823 BFD_ASSERT (globals != NULL);
5824 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5826 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5827 ARM_BX_GLUE_SECTION_NAME);
5828 BFD_ASSERT (s != NULL);
5829 BFD_ASSERT (s->contents != NULL);
5830 BFD_ASSERT (s->output_section != NULL);
5832 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5834 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5836 if ((globals->bx_glue_offset[reg] & 1) == 0)
5838 p = s->contents + glue_addr;
5839 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5840 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5841 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5842 globals->bx_glue_offset[reg] |= 1;
5845 return glue_addr + s->output_section->vma + s->output_offset;
5848 /* Generate Arm stubs for exported Thumb symbols. */
5849 static void
5850 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
5851 struct bfd_link_info *link_info)
5853 struct elf32_arm_link_hash_table * globals;
5855 if (link_info == NULL)
5856 /* Ignore this if we are not called by the ELF backend linker. */
5857 return;
5859 globals = elf32_arm_hash_table (link_info);
5860 /* If blx is available then exported Thumb symbols are OK and there is
5861 nothing to do. */
5862 if (globals->use_blx)
5863 return;
5865 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5866 link_info);
5869 /* Some relocations map to different relocations depending on the
5870 target. Return the real relocation. */
5872 static int
5873 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5874 int r_type)
5876 switch (r_type)
5878 case R_ARM_TARGET1:
5879 if (globals->target1_is_rel)
5880 return R_ARM_REL32;
5881 else
5882 return R_ARM_ABS32;
5884 case R_ARM_TARGET2:
5885 return globals->target2_reloc;
5887 default:
5888 return r_type;
5892 /* Return the base VMA address which should be subtracted from real addresses
5893 when resolving @dtpoff relocation.
5894 This is PT_TLS segment p_vaddr. */
5896 static bfd_vma
5897 dtpoff_base (struct bfd_link_info *info)
5899 /* If tls_sec is NULL, we should have signalled an error already. */
5900 if (elf_hash_table (info)->tls_sec == NULL)
5901 return 0;
5902 return elf_hash_table (info)->tls_sec->vma;
5905 /* Return the relocation value for @tpoff relocation
5906 if STT_TLS virtual address is ADDRESS. */
5908 static bfd_vma
5909 tpoff (struct bfd_link_info *info, bfd_vma address)
5911 struct elf_link_hash_table *htab = elf_hash_table (info);
5912 bfd_vma base;
5914 /* If tls_sec is NULL, we should have signalled an error already. */
5915 if (htab->tls_sec == NULL)
5916 return 0;
5917 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5918 return address - htab->tls_sec->vma + base;
5921 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5922 VALUE is the relocation value. */
5924 static bfd_reloc_status_type
5925 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5927 if (value > 0xfff)
5928 return bfd_reloc_overflow;
5930 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5931 bfd_put_32 (abfd, value, data);
5932 return bfd_reloc_ok;
5935 /* For a given value of n, calculate the value of G_n as required to
5936 deal with group relocations. We return it in the form of an
5937 encoded constant-and-rotation, together with the final residual. If n is
5938 specified as less than zero, then final_residual is filled with the
5939 input value and no further action is performed. */
5941 static bfd_vma
5942 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5944 int current_n;
5945 bfd_vma g_n;
5946 bfd_vma encoded_g_n = 0;
5947 bfd_vma residual = value; /* Also known as Y_n. */
5949 for (current_n = 0; current_n <= n; current_n++)
5951 int shift;
5953 /* Calculate which part of the value to mask. */
5954 if (residual == 0)
5955 shift = 0;
5956 else
5958 int msb;
5960 /* Determine the most significant bit in the residual and
5961 align the resulting value to a 2-bit boundary. */
5962 for (msb = 30; msb >= 0; msb -= 2)
5963 if (residual & (3 << msb))
5964 break;
5966 /* The desired shift is now (msb - 6), or zero, whichever
5967 is the greater. */
5968 shift = msb - 6;
5969 if (shift < 0)
5970 shift = 0;
5973 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5974 g_n = residual & (0xff << shift);
5975 encoded_g_n = (g_n >> shift)
5976 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5978 /* Calculate the residual for the next time around. */
5979 residual &= ~g_n;
5982 *final_residual = residual;
5984 return encoded_g_n;
5987 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5988 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5990 static int
5991 identify_add_or_sub (bfd_vma insn)
5993 int opcode = insn & 0x1e00000;
5995 if (opcode == 1 << 23) /* ADD */
5996 return 1;
5998 if (opcode == 1 << 22) /* SUB */
5999 return -1;
6001 return 0;
6004 /* Perform a relocation as part of a final link. */
6006 static bfd_reloc_status_type
6007 elf32_arm_final_link_relocate (reloc_howto_type * howto,
6008 bfd * input_bfd,
6009 bfd * output_bfd,
6010 asection * input_section,
6011 bfd_byte * contents,
6012 Elf_Internal_Rela * rel,
6013 bfd_vma value,
6014 struct bfd_link_info * info,
6015 asection * sym_sec,
6016 const char * sym_name,
6017 int sym_flags,
6018 struct elf_link_hash_entry * h,
6019 bfd_boolean * unresolved_reloc_p,
6020 char ** error_message)
6022 unsigned long r_type = howto->type;
6023 unsigned long r_symndx;
6024 bfd_byte * hit_data = contents + rel->r_offset;
6025 bfd * dynobj = NULL;
6026 Elf_Internal_Shdr * symtab_hdr;
6027 struct elf_link_hash_entry ** sym_hashes;
6028 bfd_vma * local_got_offsets;
6029 asection * sgot = NULL;
6030 asection * splt = NULL;
6031 asection * sreloc = NULL;
6032 bfd_vma addend;
6033 bfd_signed_vma signed_addend;
6034 struct elf32_arm_link_hash_table * globals;
6036 globals = elf32_arm_hash_table (info);
6038 BFD_ASSERT (is_arm_elf (input_bfd));
6040 /* Some relocation types map to different relocations depending on the
6041 target. We pick the right one here. */
6042 r_type = arm_real_reloc_type (globals, r_type);
6043 if (r_type != howto->type)
6044 howto = elf32_arm_howto_from_type (r_type);
6046 /* If the start address has been set, then set the EF_ARM_HASENTRY
6047 flag. Setting this more than once is redundant, but the cost is
6048 not too high, and it keeps the code simple.
6050 The test is done here, rather than somewhere else, because the
6051 start address is only set just before the final link commences.
6053 Note - if the user deliberately sets a start address of 0, the
6054 flag will not be set. */
6055 if (bfd_get_start_address (output_bfd) != 0)
6056 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
6058 dynobj = elf_hash_table (info)->dynobj;
6059 if (dynobj)
6061 sgot = bfd_get_section_by_name (dynobj, ".got");
6062 splt = bfd_get_section_by_name (dynobj, ".plt");
6064 symtab_hdr = & elf_symtab_hdr (input_bfd);
6065 sym_hashes = elf_sym_hashes (input_bfd);
6066 local_got_offsets = elf_local_got_offsets (input_bfd);
6067 r_symndx = ELF32_R_SYM (rel->r_info);
6069 if (globals->use_rel)
6071 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
6073 if (addend & ((howto->src_mask + 1) >> 1))
6075 signed_addend = -1;
6076 signed_addend &= ~ howto->src_mask;
6077 signed_addend |= addend;
6079 else
6080 signed_addend = addend;
6082 else
6083 addend = signed_addend = rel->r_addend;
6085 switch (r_type)
6087 case R_ARM_NONE:
6088 /* We don't need to find a value for this symbol. It's just a
6089 marker. */
6090 *unresolved_reloc_p = FALSE;
6091 return bfd_reloc_ok;
6093 case R_ARM_ABS12:
6094 if (!globals->vxworks_p)
6095 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6097 case R_ARM_PC24:
6098 case R_ARM_ABS32:
6099 case R_ARM_ABS32_NOI:
6100 case R_ARM_REL32:
6101 case R_ARM_REL32_NOI:
6102 case R_ARM_CALL:
6103 case R_ARM_JUMP24:
6104 case R_ARM_XPC25:
6105 case R_ARM_PREL31:
6106 case R_ARM_PLT32:
6107 /* Handle relocations which should use the PLT entry. ABS32/REL32
6108 will use the symbol's value, which may point to a PLT entry, but we
6109 don't need to handle that here. If we created a PLT entry, all
6110 branches in this object should go to it, except if the PLT is too
6111 far away, in which case a long branch stub should be inserted. */
6112 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
6113 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI
6114 && r_type != R_ARM_CALL)
6115 && h != NULL
6116 && splt != NULL
6117 && h->plt.offset != (bfd_vma) -1)
6119 /* If we've created a .plt section, and assigned a PLT entry to
6120 this function, it should not be known to bind locally. If
6121 it were, we would have cleared the PLT entry. */
6122 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
6124 value = (splt->output_section->vma
6125 + splt->output_offset
6126 + h->plt.offset);
6127 *unresolved_reloc_p = FALSE;
6128 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6129 contents, rel->r_offset, value,
6130 rel->r_addend);
6133 /* When generating a shared object or relocatable executable, these
6134 relocations are copied into the output file to be resolved at
6135 run time. */
6136 if ((info->shared || globals->root.is_relocatable_executable)
6137 && (input_section->flags & SEC_ALLOC)
6138 && !(elf32_arm_hash_table (info)->vxworks_p
6139 && strcmp (input_section->output_section->name,
6140 ".tls_vars") == 0)
6141 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
6142 || !SYMBOL_CALLS_LOCAL (info, h))
6143 && (h == NULL
6144 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6145 || h->root.type != bfd_link_hash_undefweak)
6146 && r_type != R_ARM_PC24
6147 && r_type != R_ARM_CALL
6148 && r_type != R_ARM_JUMP24
6149 && r_type != R_ARM_PREL31
6150 && r_type != R_ARM_PLT32)
6152 Elf_Internal_Rela outrel;
6153 bfd_byte *loc;
6154 bfd_boolean skip, relocate;
6156 *unresolved_reloc_p = FALSE;
6158 if (sreloc == NULL)
6160 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
6161 ! globals->use_rel);
6163 if (sreloc == NULL)
6164 return bfd_reloc_notsupported;
6167 skip = FALSE;
6168 relocate = FALSE;
6170 outrel.r_addend = addend;
6171 outrel.r_offset =
6172 _bfd_elf_section_offset (output_bfd, info, input_section,
6173 rel->r_offset);
6174 if (outrel.r_offset == (bfd_vma) -1)
6175 skip = TRUE;
6176 else if (outrel.r_offset == (bfd_vma) -2)
6177 skip = TRUE, relocate = TRUE;
6178 outrel.r_offset += (input_section->output_section->vma
6179 + input_section->output_offset);
6181 if (skip)
6182 memset (&outrel, 0, sizeof outrel);
6183 else if (h != NULL
6184 && h->dynindx != -1
6185 && (!info->shared
6186 || !info->symbolic
6187 || !h->def_regular))
6188 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6189 else
6191 int symbol;
6193 /* This symbol is local, or marked to become local. */
6194 if (sym_flags == STT_ARM_TFUNC)
6195 value |= 1;
6196 if (globals->symbian_p)
6198 asection *osec;
6200 /* On Symbian OS, the data segment and text segement
6201 can be relocated independently. Therefore, we
6202 must indicate the segment to which this
6203 relocation is relative. The BPABI allows us to
6204 use any symbol in the right segment; we just use
6205 the section symbol as it is convenient. (We
6206 cannot use the symbol given by "h" directly as it
6207 will not appear in the dynamic symbol table.)
6209 Note that the dynamic linker ignores the section
6210 symbol value, so we don't subtract osec->vma
6211 from the emitted reloc addend. */
6212 if (sym_sec)
6213 osec = sym_sec->output_section;
6214 else
6215 osec = input_section->output_section;
6216 symbol = elf_section_data (osec)->dynindx;
6217 if (symbol == 0)
6219 struct elf_link_hash_table *htab = elf_hash_table (info);
6221 if ((osec->flags & SEC_READONLY) == 0
6222 && htab->data_index_section != NULL)
6223 osec = htab->data_index_section;
6224 else
6225 osec = htab->text_index_section;
6226 symbol = elf_section_data (osec)->dynindx;
6228 BFD_ASSERT (symbol != 0);
6230 else
6231 /* On SVR4-ish systems, the dynamic loader cannot
6232 relocate the text and data segments independently,
6233 so the symbol does not matter. */
6234 symbol = 0;
6235 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
6236 if (globals->use_rel)
6237 relocate = TRUE;
6238 else
6239 outrel.r_addend += value;
6242 loc = sreloc->contents;
6243 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6244 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6246 /* If this reloc is against an external symbol, we do not want to
6247 fiddle with the addend. Otherwise, we need to include the symbol
6248 value so that it becomes an addend for the dynamic reloc. */
6249 if (! relocate)
6250 return bfd_reloc_ok;
6252 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6253 contents, rel->r_offset, value,
6254 (bfd_vma) 0);
6256 else switch (r_type)
6258 case R_ARM_ABS12:
6259 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6261 case R_ARM_XPC25: /* Arm BLX instruction. */
6262 case R_ARM_CALL:
6263 case R_ARM_JUMP24:
6264 case R_ARM_PC24: /* Arm B/BL instruction. */
6265 case R_ARM_PLT32:
6267 bfd_vma from;
6268 bfd_signed_vma branch_offset;
6269 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6271 if (r_type == R_ARM_XPC25)
6273 /* Check for Arm calling Arm function. */
6274 /* FIXME: Should we translate the instruction into a BL
6275 instruction instead ? */
6276 if (sym_flags != STT_ARM_TFUNC)
6277 (*_bfd_error_handler)
6278 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6279 input_bfd,
6280 h ? h->root.root.string : "(local)");
6282 else if (r_type != R_ARM_CALL)
6284 /* Check for Arm calling Thumb function. */
6285 if (sym_flags == STT_ARM_TFUNC)
6287 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6288 output_bfd, input_section,
6289 hit_data, sym_sec, rel->r_offset,
6290 signed_addend, value,
6291 error_message))
6292 return bfd_reloc_ok;
6293 else
6294 return bfd_reloc_dangerous;
6298 /* Check if a stub has to be inserted because the
6299 destination is too far or we are changing mode. */
6300 if (r_type == R_ARM_CALL)
6302 /* If the call goes through a PLT entry, make sure to
6303 check distance to the right destination address. */
6304 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6306 value = (splt->output_section->vma
6307 + splt->output_offset
6308 + h->plt.offset);
6309 *unresolved_reloc_p = FALSE;
6312 from = (input_section->output_section->vma
6313 + input_section->output_offset
6314 + rel->r_offset);
6315 branch_offset = (bfd_signed_vma)(value - from);
6317 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6318 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6319 || sym_flags == STT_ARM_TFUNC)
6321 /* The target is out of reach, so redirect the
6322 branch to the local stub for this function. */
6324 stub_entry = elf32_arm_get_stub_entry (input_section,
6325 sym_sec, h,
6326 rel, globals);
6327 if (stub_entry != NULL)
6328 value = (stub_entry->stub_offset
6329 + stub_entry->stub_sec->output_offset
6330 + stub_entry->stub_sec->output_section->vma);
6334 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6335 where:
6336 S is the address of the symbol in the relocation.
6337 P is address of the instruction being relocated.
6338 A is the addend (extracted from the instruction) in bytes.
6340 S is held in 'value'.
6341 P is the base address of the section containing the
6342 instruction plus the offset of the reloc into that
6343 section, ie:
6344 (input_section->output_section->vma +
6345 input_section->output_offset +
6346 rel->r_offset).
6347 A is the addend, converted into bytes, ie:
6348 (signed_addend * 4)
6350 Note: None of these operations have knowledge of the pipeline
6351 size of the processor, thus it is up to the assembler to
6352 encode this information into the addend. */
6353 value -= (input_section->output_section->vma
6354 + input_section->output_offset);
6355 value -= rel->r_offset;
6356 if (globals->use_rel)
6357 value += (signed_addend << howto->size);
6358 else
6359 /* RELA addends do not have to be adjusted by howto->size. */
6360 value += signed_addend;
6362 signed_addend = value;
6363 signed_addend >>= howto->rightshift;
6365 /* A branch to an undefined weak symbol is turned into a jump to
6366 the next instruction. */
6367 if (h && h->root.type == bfd_link_hash_undefweak)
6369 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6370 | 0x0affffff;
6372 else
6374 /* Perform a signed range check. */
6375 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
6376 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6377 return bfd_reloc_overflow;
6379 addend = (value & 2);
6381 value = (signed_addend & howto->dst_mask)
6382 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
6384 /* Set the H bit in the BLX instruction. */
6385 if (sym_flags == STT_ARM_TFUNC)
6387 if (addend)
6388 value |= (1 << 24);
6389 else
6390 value &= ~(bfd_vma)(1 << 24);
6392 if (r_type == R_ARM_CALL)
6394 /* Select the correct instruction (BL or BLX). */
6395 /* Only if we are not handling a BL to a stub. In this
6396 case, mode switching is performed by the stub. */
6397 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
6398 value |= (1 << 28);
6399 else
6401 value &= ~(bfd_vma)(1 << 28);
6402 value |= (1 << 24);
6407 break;
6409 case R_ARM_ABS32:
6410 value += addend;
6411 if (sym_flags == STT_ARM_TFUNC)
6412 value |= 1;
6413 break;
6415 case R_ARM_ABS32_NOI:
6416 value += addend;
6417 break;
6419 case R_ARM_REL32:
6420 value += addend;
6421 if (sym_flags == STT_ARM_TFUNC)
6422 value |= 1;
6423 value -= (input_section->output_section->vma
6424 + input_section->output_offset + rel->r_offset);
6425 break;
6427 case R_ARM_REL32_NOI:
6428 value += addend;
6429 value -= (input_section->output_section->vma
6430 + input_section->output_offset + rel->r_offset);
6431 break;
6433 case R_ARM_PREL31:
6434 value -= (input_section->output_section->vma
6435 + input_section->output_offset + rel->r_offset);
6436 value += signed_addend;
6437 if (! h || h->root.type != bfd_link_hash_undefweak)
6439 /* Check for overflow. */
6440 if ((value ^ (value >> 1)) & (1 << 30))
6441 return bfd_reloc_overflow;
6443 value &= 0x7fffffff;
6444 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6445 if (sym_flags == STT_ARM_TFUNC)
6446 value |= 1;
6447 break;
6450 bfd_put_32 (input_bfd, value, hit_data);
6451 return bfd_reloc_ok;
6453 case R_ARM_ABS8:
6454 value += addend;
6455 if ((long) value > 0x7f || (long) value < -0x80)
6456 return bfd_reloc_overflow;
6458 bfd_put_8 (input_bfd, value, hit_data);
6459 return bfd_reloc_ok;
6461 case R_ARM_ABS16:
6462 value += addend;
6464 if ((long) value > 0x7fff || (long) value < -0x8000)
6465 return bfd_reloc_overflow;
6467 bfd_put_16 (input_bfd, value, hit_data);
6468 return bfd_reloc_ok;
6470 case R_ARM_THM_ABS5:
6471 /* Support ldr and str instructions for the thumb. */
6472 if (globals->use_rel)
6474 /* Need to refetch addend. */
6475 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6476 /* ??? Need to determine shift amount from operand size. */
6477 addend >>= howto->rightshift;
6479 value += addend;
6481 /* ??? Isn't value unsigned? */
6482 if ((long) value > 0x1f || (long) value < -0x10)
6483 return bfd_reloc_overflow;
6485 /* ??? Value needs to be properly shifted into place first. */
6486 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6487 bfd_put_16 (input_bfd, value, hit_data);
6488 return bfd_reloc_ok;
6490 case R_ARM_THM_ALU_PREL_11_0:
6491 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6493 bfd_vma insn;
6494 bfd_signed_vma relocation;
6496 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6497 | bfd_get_16 (input_bfd, hit_data + 2);
6499 if (globals->use_rel)
6501 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6502 | ((insn & (1 << 26)) >> 15);
6503 if (insn & 0xf00000)
6504 signed_addend = -signed_addend;
6507 relocation = value + signed_addend;
6508 relocation -= (input_section->output_section->vma
6509 + input_section->output_offset
6510 + rel->r_offset);
6512 value = abs (relocation);
6514 if (value >= 0x1000)
6515 return bfd_reloc_overflow;
6517 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6518 | ((value & 0x700) << 4)
6519 | ((value & 0x800) << 15);
6520 if (relocation < 0)
6521 insn |= 0xa00000;
6523 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6524 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6526 return bfd_reloc_ok;
6529 case R_ARM_THM_PC12:
6530 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6532 bfd_vma insn;
6533 bfd_signed_vma relocation;
6535 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6536 | bfd_get_16 (input_bfd, hit_data + 2);
6538 if (globals->use_rel)
6540 signed_addend = insn & 0xfff;
6541 if (!(insn & (1 << 23)))
6542 signed_addend = -signed_addend;
6545 relocation = value + signed_addend;
6546 relocation -= (input_section->output_section->vma
6547 + input_section->output_offset
6548 + rel->r_offset);
6550 value = abs (relocation);
6552 if (value >= 0x1000)
6553 return bfd_reloc_overflow;
6555 insn = (insn & 0xff7ff000) | value;
6556 if (relocation >= 0)
6557 insn |= (1 << 23);
6559 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6560 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6562 return bfd_reloc_ok;
6565 case R_ARM_THM_XPC22:
6566 case R_ARM_THM_CALL:
6567 case R_ARM_THM_JUMP24:
6568 /* Thumb BL (branch long instruction). */
6570 bfd_vma relocation;
6571 bfd_vma reloc_sign;
6572 bfd_boolean overflow = FALSE;
6573 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6574 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6575 bfd_signed_vma reloc_signed_max;
6576 bfd_signed_vma reloc_signed_min;
6577 bfd_vma check;
6578 bfd_signed_vma signed_check;
6579 int bitsize;
6580 int thumb2 = using_thumb2 (globals);
6582 /* A branch to an undefined weak symbol is turned into a jump to
6583 the next instruction unless a PLT entry will be created. */
6584 if (h && h->root.type == bfd_link_hash_undefweak
6585 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6587 bfd_put_16 (input_bfd, 0xe000, hit_data);
6588 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6589 return bfd_reloc_ok;
6592 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6593 with Thumb-1) involving the J1 and J2 bits. */
6594 if (globals->use_rel)
6596 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6597 bfd_vma upper = upper_insn & 0x3ff;
6598 bfd_vma lower = lower_insn & 0x7ff;
6599 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6600 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6601 bfd_vma i1 = j1 ^ s ? 0 : 1;
6602 bfd_vma i2 = j2 ^ s ? 0 : 1;
6604 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6605 /* Sign extend. */
6606 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6608 signed_addend = addend;
6611 if (r_type == R_ARM_THM_XPC22)
6613 /* Check for Thumb to Thumb call. */
6614 /* FIXME: Should we translate the instruction into a BL
6615 instruction instead ? */
6616 if (sym_flags == STT_ARM_TFUNC)
6617 (*_bfd_error_handler)
6618 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6619 input_bfd,
6620 h ? h->root.root.string : "(local)");
6622 else
6624 /* If it is not a call to Thumb, assume call to Arm.
6625 If it is a call relative to a section name, then it is not a
6626 function call at all, but rather a long jump. Calls through
6627 the PLT do not require stubs. */
6628 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6629 && (h == NULL || splt == NULL
6630 || h->plt.offset == (bfd_vma) -1))
6632 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6634 /* Convert BL to BLX. */
6635 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6637 else if (r_type != R_ARM_THM_CALL)
6639 if (elf32_thumb_to_arm_stub
6640 (info, sym_name, input_bfd, output_bfd, input_section,
6641 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6642 error_message))
6643 return bfd_reloc_ok;
6644 else
6645 return bfd_reloc_dangerous;
6648 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6649 && r_type == R_ARM_THM_CALL)
6651 /* Make sure this is a BL. */
6652 lower_insn |= 0x1800;
6656 /* Handle calls via the PLT. */
6657 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6659 value = (splt->output_section->vma
6660 + splt->output_offset
6661 + h->plt.offset);
6662 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6664 /* If the Thumb BLX instruction is available, convert the
6665 BL to a BLX instruction to call the ARM-mode PLT entry. */
6666 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6668 else
6669 /* Target the Thumb stub before the ARM PLT entry. */
6670 value -= PLT_THUMB_STUB_SIZE;
6671 *unresolved_reloc_p = FALSE;
6674 if (r_type == R_ARM_THM_CALL)
6676 /* Check if a stub has to be inserted because the destination
6677 is too far. */
6678 bfd_vma from;
6679 bfd_signed_vma branch_offset;
6680 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6682 from = (input_section->output_section->vma
6683 + input_section->output_offset
6684 + rel->r_offset);
6685 branch_offset = (bfd_signed_vma)(value - from);
6687 if ((!thumb2
6688 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6689 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6691 (thumb2
6692 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
6693 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6694 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
6696 /* The target is out of reach or we are changing modes, so
6697 redirect the branch to the local stub for this
6698 function. */
6699 stub_entry = elf32_arm_get_stub_entry (input_section,
6700 sym_sec, h,
6701 rel, globals);
6702 if (stub_entry != NULL)
6703 value = (stub_entry->stub_offset
6704 + stub_entry->stub_sec->output_offset
6705 + stub_entry->stub_sec->output_section->vma);
6707 /* If this call becomes a call to Arm, force BLX. */
6708 if (globals->use_blx)
6710 if ((stub_entry
6711 && !arm_stub_is_thumb (stub_entry->stub_type))
6712 || (sym_flags != STT_ARM_TFUNC))
6713 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6718 relocation = value + signed_addend;
6720 relocation -= (input_section->output_section->vma
6721 + input_section->output_offset
6722 + rel->r_offset);
6724 check = relocation >> howto->rightshift;
6726 /* If this is a signed value, the rightshift just dropped
6727 leading 1 bits (assuming twos complement). */
6728 if ((bfd_signed_vma) relocation >= 0)
6729 signed_check = check;
6730 else
6731 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6733 /* Calculate the permissable maximum and minimum values for
6734 this relocation according to whether we're relocating for
6735 Thumb-2 or not. */
6736 bitsize = howto->bitsize;
6737 if (!thumb2)
6738 bitsize -= 2;
6739 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6740 reloc_signed_min = ~reloc_signed_max;
6742 /* Assumes two's complement. */
6743 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6744 overflow = TRUE;
6746 if ((lower_insn & 0x5000) == 0x4000)
6747 /* For a BLX instruction, make sure that the relocation is rounded up
6748 to a word boundary. This follows the semantics of the instruction
6749 which specifies that bit 1 of the target address will come from bit
6750 1 of the base address. */
6751 relocation = (relocation + 2) & ~ 3;
6753 /* Put RELOCATION back into the insn. Assumes two's complement.
6754 We use the Thumb-2 encoding, which is safe even if dealing with
6755 a Thumb-1 instruction by virtue of our overflow check above. */
6756 reloc_sign = (signed_check < 0) ? 1 : 0;
6757 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6758 | ((relocation >> 12) & 0x3ff)
6759 | (reloc_sign << 10);
6760 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
6761 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6762 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6763 | ((relocation >> 1) & 0x7ff);
6765 /* Put the relocated value back in the object file: */
6766 bfd_put_16 (input_bfd, upper_insn, hit_data);
6767 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6769 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6771 break;
6773 case R_ARM_THM_JUMP19:
6774 /* Thumb32 conditional branch instruction. */
6776 bfd_vma relocation;
6777 bfd_boolean overflow = FALSE;
6778 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6779 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6780 bfd_signed_vma reloc_signed_max = 0xffffe;
6781 bfd_signed_vma reloc_signed_min = -0x100000;
6782 bfd_signed_vma signed_check;
6784 /* Need to refetch the addend, reconstruct the top three bits,
6785 and squish the two 11 bit pieces together. */
6786 if (globals->use_rel)
6788 bfd_vma S = (upper_insn & 0x0400) >> 10;
6789 bfd_vma upper = (upper_insn & 0x003f);
6790 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6791 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6792 bfd_vma lower = (lower_insn & 0x07ff);
6794 upper |= J1 << 6;
6795 upper |= J2 << 7;
6796 upper |= (!S) << 8;
6797 upper -= 0x0100; /* Sign extend. */
6799 addend = (upper << 12) | (lower << 1);
6800 signed_addend = addend;
6803 /* Handle calls via the PLT. */
6804 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6806 value = (splt->output_section->vma
6807 + splt->output_offset
6808 + h->plt.offset);
6809 /* Target the Thumb stub before the ARM PLT entry. */
6810 value -= PLT_THUMB_STUB_SIZE;
6811 *unresolved_reloc_p = FALSE;
6814 /* ??? Should handle interworking? GCC might someday try to
6815 use this for tail calls. */
6817 relocation = value + signed_addend;
6818 relocation -= (input_section->output_section->vma
6819 + input_section->output_offset
6820 + rel->r_offset);
6821 signed_check = (bfd_signed_vma) relocation;
6823 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6824 overflow = TRUE;
6826 /* Put RELOCATION back into the insn. */
6828 bfd_vma S = (relocation & 0x00100000) >> 20;
6829 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6830 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6831 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6832 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6834 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
6835 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6838 /* Put the relocated value back in the object file: */
6839 bfd_put_16 (input_bfd, upper_insn, hit_data);
6840 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6842 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6845 case R_ARM_THM_JUMP11:
6846 case R_ARM_THM_JUMP8:
6847 case R_ARM_THM_JUMP6:
6848 /* Thumb B (branch) instruction). */
6850 bfd_signed_vma relocation;
6851 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6852 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
6853 bfd_signed_vma signed_check;
6855 /* CZB cannot jump backward. */
6856 if (r_type == R_ARM_THM_JUMP6)
6857 reloc_signed_min = 0;
6859 if (globals->use_rel)
6861 /* Need to refetch addend. */
6862 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6863 if (addend & ((howto->src_mask + 1) >> 1))
6865 signed_addend = -1;
6866 signed_addend &= ~ howto->src_mask;
6867 signed_addend |= addend;
6869 else
6870 signed_addend = addend;
6871 /* The value in the insn has been right shifted. We need to
6872 undo this, so that we can perform the address calculation
6873 in terms of bytes. */
6874 signed_addend <<= howto->rightshift;
6876 relocation = value + signed_addend;
6878 relocation -= (input_section->output_section->vma
6879 + input_section->output_offset
6880 + rel->r_offset);
6882 relocation >>= howto->rightshift;
6883 signed_check = relocation;
6885 if (r_type == R_ARM_THM_JUMP6)
6886 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6887 else
6888 relocation &= howto->dst_mask;
6889 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
6891 bfd_put_16 (input_bfd, relocation, hit_data);
6893 /* Assumes two's complement. */
6894 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6895 return bfd_reloc_overflow;
6897 return bfd_reloc_ok;
6900 case R_ARM_ALU_PCREL7_0:
6901 case R_ARM_ALU_PCREL15_8:
6902 case R_ARM_ALU_PCREL23_15:
6904 bfd_vma insn;
6905 bfd_vma relocation;
6907 insn = bfd_get_32 (input_bfd, hit_data);
6908 if (globals->use_rel)
6910 /* Extract the addend. */
6911 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6912 signed_addend = addend;
6914 relocation = value + signed_addend;
6916 relocation -= (input_section->output_section->vma
6917 + input_section->output_offset
6918 + rel->r_offset);
6919 insn = (insn & ~0xfff)
6920 | ((howto->bitpos << 7) & 0xf00)
6921 | ((relocation >> howto->bitpos) & 0xff);
6922 bfd_put_32 (input_bfd, value, hit_data);
6924 return bfd_reloc_ok;
6926 case R_ARM_GNU_VTINHERIT:
6927 case R_ARM_GNU_VTENTRY:
6928 return bfd_reloc_ok;
6930 case R_ARM_GOTOFF32:
6931 /* Relocation is relative to the start of the
6932 global offset table. */
6934 BFD_ASSERT (sgot != NULL);
6935 if (sgot == NULL)
6936 return bfd_reloc_notsupported;
6938 /* If we are addressing a Thumb function, we need to adjust the
6939 address by one, so that attempts to call the function pointer will
6940 correctly interpret it as Thumb code. */
6941 if (sym_flags == STT_ARM_TFUNC)
6942 value += 1;
6944 /* Note that sgot->output_offset is not involved in this
6945 calculation. We always want the start of .got. If we
6946 define _GLOBAL_OFFSET_TABLE in a different way, as is
6947 permitted by the ABI, we might have to change this
6948 calculation. */
6949 value -= sgot->output_section->vma;
6950 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6951 contents, rel->r_offset, value,
6952 rel->r_addend);
6954 case R_ARM_GOTPC:
6955 /* Use global offset table as symbol value. */
6956 BFD_ASSERT (sgot != NULL);
6958 if (sgot == NULL)
6959 return bfd_reloc_notsupported;
6961 *unresolved_reloc_p = FALSE;
6962 value = sgot->output_section->vma;
6963 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6964 contents, rel->r_offset, value,
6965 rel->r_addend);
6967 case R_ARM_GOT32:
6968 case R_ARM_GOT_PREL:
6969 /* Relocation is to the entry for this symbol in the
6970 global offset table. */
6971 if (sgot == NULL)
6972 return bfd_reloc_notsupported;
6974 if (h != NULL)
6976 bfd_vma off;
6977 bfd_boolean dyn;
6979 off = h->got.offset;
6980 BFD_ASSERT (off != (bfd_vma) -1);
6981 dyn = globals->root.dynamic_sections_created;
6983 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6984 || (info->shared
6985 && SYMBOL_REFERENCES_LOCAL (info, h))
6986 || (ELF_ST_VISIBILITY (h->other)
6987 && h->root.type == bfd_link_hash_undefweak))
6989 /* This is actually a static link, or it is a -Bsymbolic link
6990 and the symbol is defined locally. We must initialize this
6991 entry in the global offset table. Since the offset must
6992 always be a multiple of 4, we use the least significant bit
6993 to record whether we have initialized it already.
6995 When doing a dynamic link, we create a .rel(a).got relocation
6996 entry to initialize the value. This is done in the
6997 finish_dynamic_symbol routine. */
6998 if ((off & 1) != 0)
6999 off &= ~1;
7000 else
7002 /* If we are addressing a Thumb function, we need to
7003 adjust the address by one, so that attempts to
7004 call the function pointer will correctly
7005 interpret it as Thumb code. */
7006 if (sym_flags == STT_ARM_TFUNC)
7007 value |= 1;
7009 bfd_put_32 (output_bfd, value, sgot->contents + off);
7010 h->got.offset |= 1;
7013 else
7014 *unresolved_reloc_p = FALSE;
7016 value = sgot->output_offset + off;
7018 else
7020 bfd_vma off;
7022 BFD_ASSERT (local_got_offsets != NULL &&
7023 local_got_offsets[r_symndx] != (bfd_vma) -1);
7025 off = local_got_offsets[r_symndx];
7027 /* The offset must always be a multiple of 4. We use the
7028 least significant bit to record whether we have already
7029 generated the necessary reloc. */
7030 if ((off & 1) != 0)
7031 off &= ~1;
7032 else
7034 /* If we are addressing a Thumb function, we need to
7035 adjust the address by one, so that attempts to
7036 call the function pointer will correctly
7037 interpret it as Thumb code. */
7038 if (sym_flags == STT_ARM_TFUNC)
7039 value |= 1;
7041 if (globals->use_rel)
7042 bfd_put_32 (output_bfd, value, sgot->contents + off);
7044 if (info->shared)
7046 asection * srelgot;
7047 Elf_Internal_Rela outrel;
7048 bfd_byte *loc;
7050 srelgot = (bfd_get_section_by_name
7051 (dynobj, RELOC_SECTION (globals, ".got")));
7052 BFD_ASSERT (srelgot != NULL);
7054 outrel.r_addend = addend + value;
7055 outrel.r_offset = (sgot->output_section->vma
7056 + sgot->output_offset
7057 + off);
7058 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
7059 loc = srelgot->contents;
7060 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
7061 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7064 local_got_offsets[r_symndx] |= 1;
7067 value = sgot->output_offset + off;
7069 if (r_type != R_ARM_GOT32)
7070 value += sgot->output_section->vma;
7072 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7073 contents, rel->r_offset, value,
7074 rel->r_addend);
7076 case R_ARM_TLS_LDO32:
7077 value = value - dtpoff_base (info);
7079 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7080 contents, rel->r_offset, value,
7081 rel->r_addend);
7083 case R_ARM_TLS_LDM32:
7085 bfd_vma off;
7087 if (globals->sgot == NULL)
7088 abort ();
7090 off = globals->tls_ldm_got.offset;
7092 if ((off & 1) != 0)
7093 off &= ~1;
7094 else
7096 /* If we don't know the module number, create a relocation
7097 for it. */
7098 if (info->shared)
7100 Elf_Internal_Rela outrel;
7101 bfd_byte *loc;
7103 if (globals->srelgot == NULL)
7104 abort ();
7106 outrel.r_addend = 0;
7107 outrel.r_offset = (globals->sgot->output_section->vma
7108 + globals->sgot->output_offset + off);
7109 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
7111 if (globals->use_rel)
7112 bfd_put_32 (output_bfd, outrel.r_addend,
7113 globals->sgot->contents + off);
7115 loc = globals->srelgot->contents;
7116 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
7117 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7119 else
7120 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
7122 globals->tls_ldm_got.offset |= 1;
7125 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7126 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7128 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7129 contents, rel->r_offset, value,
7130 rel->r_addend);
7133 case R_ARM_TLS_GD32:
7134 case R_ARM_TLS_IE32:
7136 bfd_vma off;
7137 int indx;
7138 char tls_type;
7140 if (globals->sgot == NULL)
7141 abort ();
7143 indx = 0;
7144 if (h != NULL)
7146 bfd_boolean dyn;
7147 dyn = globals->root.dynamic_sections_created;
7148 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7149 && (!info->shared
7150 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7152 *unresolved_reloc_p = FALSE;
7153 indx = h->dynindx;
7155 off = h->got.offset;
7156 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
7158 else
7160 if (local_got_offsets == NULL)
7161 abort ();
7162 off = local_got_offsets[r_symndx];
7163 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
7166 if (tls_type == GOT_UNKNOWN)
7167 abort ();
7169 if ((off & 1) != 0)
7170 off &= ~1;
7171 else
7173 bfd_boolean need_relocs = FALSE;
7174 Elf_Internal_Rela outrel;
7175 bfd_byte *loc = NULL;
7176 int cur_off = off;
7178 /* The GOT entries have not been initialized yet. Do it
7179 now, and emit any relocations. If both an IE GOT and a
7180 GD GOT are necessary, we emit the GD first. */
7182 if ((info->shared || indx != 0)
7183 && (h == NULL
7184 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7185 || h->root.type != bfd_link_hash_undefweak))
7187 need_relocs = TRUE;
7188 if (globals->srelgot == NULL)
7189 abort ();
7190 loc = globals->srelgot->contents;
7191 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
7194 if (tls_type & GOT_TLS_GD)
7196 if (need_relocs)
7198 outrel.r_addend = 0;
7199 outrel.r_offset = (globals->sgot->output_section->vma
7200 + globals->sgot->output_offset
7201 + cur_off);
7202 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
7204 if (globals->use_rel)
7205 bfd_put_32 (output_bfd, outrel.r_addend,
7206 globals->sgot->contents + cur_off);
7208 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7209 globals->srelgot->reloc_count++;
7210 loc += RELOC_SIZE (globals);
7212 if (indx == 0)
7213 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7214 globals->sgot->contents + cur_off + 4);
7215 else
7217 outrel.r_addend = 0;
7218 outrel.r_info = ELF32_R_INFO (indx,
7219 R_ARM_TLS_DTPOFF32);
7220 outrel.r_offset += 4;
7222 if (globals->use_rel)
7223 bfd_put_32 (output_bfd, outrel.r_addend,
7224 globals->sgot->contents + cur_off + 4);
7227 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7228 globals->srelgot->reloc_count++;
7229 loc += RELOC_SIZE (globals);
7232 else
7234 /* If we are not emitting relocations for a
7235 general dynamic reference, then we must be in a
7236 static link or an executable link with the
7237 symbol binding locally. Mark it as belonging
7238 to module 1, the executable. */
7239 bfd_put_32 (output_bfd, 1,
7240 globals->sgot->contents + cur_off);
7241 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7242 globals->sgot->contents + cur_off + 4);
7245 cur_off += 8;
7248 if (tls_type & GOT_TLS_IE)
7250 if (need_relocs)
7252 if (indx == 0)
7253 outrel.r_addend = value - dtpoff_base (info);
7254 else
7255 outrel.r_addend = 0;
7256 outrel.r_offset = (globals->sgot->output_section->vma
7257 + globals->sgot->output_offset
7258 + cur_off);
7259 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7261 if (globals->use_rel)
7262 bfd_put_32 (output_bfd, outrel.r_addend,
7263 globals->sgot->contents + cur_off);
7265 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7266 globals->srelgot->reloc_count++;
7267 loc += RELOC_SIZE (globals);
7269 else
7270 bfd_put_32 (output_bfd, tpoff (info, value),
7271 globals->sgot->contents + cur_off);
7272 cur_off += 4;
7275 if (h != NULL)
7276 h->got.offset |= 1;
7277 else
7278 local_got_offsets[r_symndx] |= 1;
7281 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7282 off += 8;
7283 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7284 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7286 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7287 contents, rel->r_offset, value,
7288 rel->r_addend);
7291 case R_ARM_TLS_LE32:
7292 if (info->shared)
7294 (*_bfd_error_handler)
7295 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7296 input_bfd, input_section,
7297 (long) rel->r_offset, howto->name);
7298 return FALSE;
7300 else
7301 value = tpoff (info, value);
7303 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7304 contents, rel->r_offset, value,
7305 rel->r_addend);
7307 case R_ARM_V4BX:
7308 if (globals->fix_v4bx)
7310 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7312 /* Ensure that we have a BX instruction. */
7313 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
7315 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7317 /* Branch to veneer. */
7318 bfd_vma glue_addr;
7319 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7320 glue_addr -= input_section->output_section->vma
7321 + input_section->output_offset
7322 + rel->r_offset + 8;
7323 insn = (insn & 0xf0000000) | 0x0a000000
7324 | ((glue_addr >> 2) & 0x00ffffff);
7326 else
7328 /* Preserve Rm (lowest four bits) and the condition code
7329 (highest four bits). Other bits encode MOV PC,Rm. */
7330 insn = (insn & 0xf000000f) | 0x01a0f000;
7333 bfd_put_32 (input_bfd, insn, hit_data);
7335 return bfd_reloc_ok;
7337 case R_ARM_MOVW_ABS_NC:
7338 case R_ARM_MOVT_ABS:
7339 case R_ARM_MOVW_PREL_NC:
7340 case R_ARM_MOVT_PREL:
7341 /* Until we properly support segment-base-relative addressing then
7342 we assume the segment base to be zero, as for the group relocations.
7343 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7344 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7345 case R_ARM_MOVW_BREL_NC:
7346 case R_ARM_MOVW_BREL:
7347 case R_ARM_MOVT_BREL:
7349 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7351 if (globals->use_rel)
7353 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
7354 signed_addend = (addend ^ 0x8000) - 0x8000;
7357 value += signed_addend;
7359 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7360 value -= (input_section->output_section->vma
7361 + input_section->output_offset + rel->r_offset);
7363 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7364 return bfd_reloc_overflow;
7366 if (sym_flags == STT_ARM_TFUNC)
7367 value |= 1;
7369 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7370 || r_type == R_ARM_MOVT_BREL)
7371 value >>= 16;
7373 insn &= 0xfff0f000;
7374 insn |= value & 0xfff;
7375 insn |= (value & 0xf000) << 4;
7376 bfd_put_32 (input_bfd, insn, hit_data);
7378 return bfd_reloc_ok;
7380 case R_ARM_THM_MOVW_ABS_NC:
7381 case R_ARM_THM_MOVT_ABS:
7382 case R_ARM_THM_MOVW_PREL_NC:
7383 case R_ARM_THM_MOVT_PREL:
7384 /* Until we properly support segment-base-relative addressing then
7385 we assume the segment base to be zero, as for the above relocations.
7386 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7387 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7388 as R_ARM_THM_MOVT_ABS. */
7389 case R_ARM_THM_MOVW_BREL_NC:
7390 case R_ARM_THM_MOVW_BREL:
7391 case R_ARM_THM_MOVT_BREL:
7393 bfd_vma insn;
7395 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7396 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7398 if (globals->use_rel)
7400 addend = ((insn >> 4) & 0xf000)
7401 | ((insn >> 15) & 0x0800)
7402 | ((insn >> 4) & 0x0700)
7403 | (insn & 0x00ff);
7404 signed_addend = (addend ^ 0x8000) - 0x8000;
7407 value += signed_addend;
7409 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7410 value -= (input_section->output_section->vma
7411 + input_section->output_offset + rel->r_offset);
7413 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7414 return bfd_reloc_overflow;
7416 if (sym_flags == STT_ARM_TFUNC)
7417 value |= 1;
7419 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7420 || r_type == R_ARM_THM_MOVT_BREL)
7421 value >>= 16;
7423 insn &= 0xfbf08f00;
7424 insn |= (value & 0xf000) << 4;
7425 insn |= (value & 0x0800) << 15;
7426 insn |= (value & 0x0700) << 4;
7427 insn |= (value & 0x00ff);
7429 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7430 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7432 return bfd_reloc_ok;
7434 case R_ARM_ALU_PC_G0_NC:
7435 case R_ARM_ALU_PC_G1_NC:
7436 case R_ARM_ALU_PC_G0:
7437 case R_ARM_ALU_PC_G1:
7438 case R_ARM_ALU_PC_G2:
7439 case R_ARM_ALU_SB_G0_NC:
7440 case R_ARM_ALU_SB_G1_NC:
7441 case R_ARM_ALU_SB_G0:
7442 case R_ARM_ALU_SB_G1:
7443 case R_ARM_ALU_SB_G2:
7445 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7446 bfd_vma pc = input_section->output_section->vma
7447 + input_section->output_offset + rel->r_offset;
7448 /* sb should be the origin of the *segment* containing the symbol.
7449 It is not clear how to obtain this OS-dependent value, so we
7450 make an arbitrary choice of zero. */
7451 bfd_vma sb = 0;
7452 bfd_vma residual;
7453 bfd_vma g_n;
7454 bfd_signed_vma signed_value;
7455 int group = 0;
7457 /* Determine which group of bits to select. */
7458 switch (r_type)
7460 case R_ARM_ALU_PC_G0_NC:
7461 case R_ARM_ALU_PC_G0:
7462 case R_ARM_ALU_SB_G0_NC:
7463 case R_ARM_ALU_SB_G0:
7464 group = 0;
7465 break;
7467 case R_ARM_ALU_PC_G1_NC:
7468 case R_ARM_ALU_PC_G1:
7469 case R_ARM_ALU_SB_G1_NC:
7470 case R_ARM_ALU_SB_G1:
7471 group = 1;
7472 break;
7474 case R_ARM_ALU_PC_G2:
7475 case R_ARM_ALU_SB_G2:
7476 group = 2;
7477 break;
7479 default:
7480 abort ();
7483 /* If REL, extract the addend from the insn. If RELA, it will
7484 have already been fetched for us. */
7485 if (globals->use_rel)
7487 int negative;
7488 bfd_vma constant = insn & 0xff;
7489 bfd_vma rotation = (insn & 0xf00) >> 8;
7491 if (rotation == 0)
7492 signed_addend = constant;
7493 else
7495 /* Compensate for the fact that in the instruction, the
7496 rotation is stored in multiples of 2 bits. */
7497 rotation *= 2;
7499 /* Rotate "constant" right by "rotation" bits. */
7500 signed_addend = (constant >> rotation) |
7501 (constant << (8 * sizeof (bfd_vma) - rotation));
7504 /* Determine if the instruction is an ADD or a SUB.
7505 (For REL, this determines the sign of the addend.) */
7506 negative = identify_add_or_sub (insn);
7507 if (negative == 0)
7509 (*_bfd_error_handler)
7510 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7511 input_bfd, input_section,
7512 (long) rel->r_offset, howto->name);
7513 return bfd_reloc_overflow;
7516 signed_addend *= negative;
7519 /* Compute the value (X) to go in the place. */
7520 if (r_type == R_ARM_ALU_PC_G0_NC
7521 || r_type == R_ARM_ALU_PC_G1_NC
7522 || r_type == R_ARM_ALU_PC_G0
7523 || r_type == R_ARM_ALU_PC_G1
7524 || r_type == R_ARM_ALU_PC_G2)
7525 /* PC relative. */
7526 signed_value = value - pc + signed_addend;
7527 else
7528 /* Section base relative. */
7529 signed_value = value - sb + signed_addend;
7531 /* If the target symbol is a Thumb function, then set the
7532 Thumb bit in the address. */
7533 if (sym_flags == STT_ARM_TFUNC)
7534 signed_value |= 1;
7536 /* Calculate the value of the relevant G_n, in encoded
7537 constant-with-rotation format. */
7538 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7539 &residual);
7541 /* Check for overflow if required. */
7542 if ((r_type == R_ARM_ALU_PC_G0
7543 || r_type == R_ARM_ALU_PC_G1
7544 || r_type == R_ARM_ALU_PC_G2
7545 || r_type == R_ARM_ALU_SB_G0
7546 || r_type == R_ARM_ALU_SB_G1
7547 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7549 (*_bfd_error_handler)
7550 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7551 input_bfd, input_section,
7552 (long) rel->r_offset, abs (signed_value), howto->name);
7553 return bfd_reloc_overflow;
7556 /* Mask out the value and the ADD/SUB part of the opcode; take care
7557 not to destroy the S bit. */
7558 insn &= 0xff1ff000;
7560 /* Set the opcode according to whether the value to go in the
7561 place is negative. */
7562 if (signed_value < 0)
7563 insn |= 1 << 22;
7564 else
7565 insn |= 1 << 23;
7567 /* Encode the offset. */
7568 insn |= g_n;
7570 bfd_put_32 (input_bfd, insn, hit_data);
7572 return bfd_reloc_ok;
7574 case R_ARM_LDR_PC_G0:
7575 case R_ARM_LDR_PC_G1:
7576 case R_ARM_LDR_PC_G2:
7577 case R_ARM_LDR_SB_G0:
7578 case R_ARM_LDR_SB_G1:
7579 case R_ARM_LDR_SB_G2:
7581 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7582 bfd_vma pc = input_section->output_section->vma
7583 + input_section->output_offset + rel->r_offset;
7584 bfd_vma sb = 0; /* See note above. */
7585 bfd_vma residual;
7586 bfd_signed_vma signed_value;
7587 int group = 0;
7589 /* Determine which groups of bits to calculate. */
7590 switch (r_type)
7592 case R_ARM_LDR_PC_G0:
7593 case R_ARM_LDR_SB_G0:
7594 group = 0;
7595 break;
7597 case R_ARM_LDR_PC_G1:
7598 case R_ARM_LDR_SB_G1:
7599 group = 1;
7600 break;
7602 case R_ARM_LDR_PC_G2:
7603 case R_ARM_LDR_SB_G2:
7604 group = 2;
7605 break;
7607 default:
7608 abort ();
7611 /* If REL, extract the addend from the insn. If RELA, it will
7612 have already been fetched for us. */
7613 if (globals->use_rel)
7615 int negative = (insn & (1 << 23)) ? 1 : -1;
7616 signed_addend = negative * (insn & 0xfff);
7619 /* Compute the value (X) to go in the place. */
7620 if (r_type == R_ARM_LDR_PC_G0
7621 || r_type == R_ARM_LDR_PC_G1
7622 || r_type == R_ARM_LDR_PC_G2)
7623 /* PC relative. */
7624 signed_value = value - pc + signed_addend;
7625 else
7626 /* Section base relative. */
7627 signed_value = value - sb + signed_addend;
7629 /* Calculate the value of the relevant G_{n-1} to obtain
7630 the residual at that stage. */
7631 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7633 /* Check for overflow. */
7634 if (residual >= 0x1000)
7636 (*_bfd_error_handler)
7637 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7638 input_bfd, input_section,
7639 (long) rel->r_offset, abs (signed_value), howto->name);
7640 return bfd_reloc_overflow;
7643 /* Mask out the value and U bit. */
7644 insn &= 0xff7ff000;
7646 /* Set the U bit if the value to go in the place is non-negative. */
7647 if (signed_value >= 0)
7648 insn |= 1 << 23;
7650 /* Encode the offset. */
7651 insn |= residual;
7653 bfd_put_32 (input_bfd, insn, hit_data);
7655 return bfd_reloc_ok;
7657 case R_ARM_LDRS_PC_G0:
7658 case R_ARM_LDRS_PC_G1:
7659 case R_ARM_LDRS_PC_G2:
7660 case R_ARM_LDRS_SB_G0:
7661 case R_ARM_LDRS_SB_G1:
7662 case R_ARM_LDRS_SB_G2:
7664 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7665 bfd_vma pc = input_section->output_section->vma
7666 + input_section->output_offset + rel->r_offset;
7667 bfd_vma sb = 0; /* See note above. */
7668 bfd_vma residual;
7669 bfd_signed_vma signed_value;
7670 int group = 0;
7672 /* Determine which groups of bits to calculate. */
7673 switch (r_type)
7675 case R_ARM_LDRS_PC_G0:
7676 case R_ARM_LDRS_SB_G0:
7677 group = 0;
7678 break;
7680 case R_ARM_LDRS_PC_G1:
7681 case R_ARM_LDRS_SB_G1:
7682 group = 1;
7683 break;
7685 case R_ARM_LDRS_PC_G2:
7686 case R_ARM_LDRS_SB_G2:
7687 group = 2;
7688 break;
7690 default:
7691 abort ();
7694 /* If REL, extract the addend from the insn. If RELA, it will
7695 have already been fetched for us. */
7696 if (globals->use_rel)
7698 int negative = (insn & (1 << 23)) ? 1 : -1;
7699 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7702 /* Compute the value (X) to go in the place. */
7703 if (r_type == R_ARM_LDRS_PC_G0
7704 || r_type == R_ARM_LDRS_PC_G1
7705 || r_type == R_ARM_LDRS_PC_G2)
7706 /* PC relative. */
7707 signed_value = value - pc + signed_addend;
7708 else
7709 /* Section base relative. */
7710 signed_value = value - sb + signed_addend;
7712 /* Calculate the value of the relevant G_{n-1} to obtain
7713 the residual at that stage. */
7714 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7716 /* Check for overflow. */
7717 if (residual >= 0x100)
7719 (*_bfd_error_handler)
7720 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7721 input_bfd, input_section,
7722 (long) rel->r_offset, abs (signed_value), howto->name);
7723 return bfd_reloc_overflow;
7726 /* Mask out the value and U bit. */
7727 insn &= 0xff7ff0f0;
7729 /* Set the U bit if the value to go in the place is non-negative. */
7730 if (signed_value >= 0)
7731 insn |= 1 << 23;
7733 /* Encode the offset. */
7734 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7736 bfd_put_32 (input_bfd, insn, hit_data);
7738 return bfd_reloc_ok;
7740 case R_ARM_LDC_PC_G0:
7741 case R_ARM_LDC_PC_G1:
7742 case R_ARM_LDC_PC_G2:
7743 case R_ARM_LDC_SB_G0:
7744 case R_ARM_LDC_SB_G1:
7745 case R_ARM_LDC_SB_G2:
7747 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7748 bfd_vma pc = input_section->output_section->vma
7749 + input_section->output_offset + rel->r_offset;
7750 bfd_vma sb = 0; /* See note above. */
7751 bfd_vma residual;
7752 bfd_signed_vma signed_value;
7753 int group = 0;
7755 /* Determine which groups of bits to calculate. */
7756 switch (r_type)
7758 case R_ARM_LDC_PC_G0:
7759 case R_ARM_LDC_SB_G0:
7760 group = 0;
7761 break;
7763 case R_ARM_LDC_PC_G1:
7764 case R_ARM_LDC_SB_G1:
7765 group = 1;
7766 break;
7768 case R_ARM_LDC_PC_G2:
7769 case R_ARM_LDC_SB_G2:
7770 group = 2;
7771 break;
7773 default:
7774 abort ();
7777 /* If REL, extract the addend from the insn. If RELA, it will
7778 have already been fetched for us. */
7779 if (globals->use_rel)
7781 int negative = (insn & (1 << 23)) ? 1 : -1;
7782 signed_addend = negative * ((insn & 0xff) << 2);
7785 /* Compute the value (X) to go in the place. */
7786 if (r_type == R_ARM_LDC_PC_G0
7787 || r_type == R_ARM_LDC_PC_G1
7788 || r_type == R_ARM_LDC_PC_G2)
7789 /* PC relative. */
7790 signed_value = value - pc + signed_addend;
7791 else
7792 /* Section base relative. */
7793 signed_value = value - sb + signed_addend;
7795 /* Calculate the value of the relevant G_{n-1} to obtain
7796 the residual at that stage. */
7797 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7799 /* Check for overflow. (The absolute value to go in the place must be
7800 divisible by four and, after having been divided by four, must
7801 fit in eight bits.) */
7802 if ((residual & 0x3) != 0 || residual >= 0x400)
7804 (*_bfd_error_handler)
7805 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7806 input_bfd, input_section,
7807 (long) rel->r_offset, abs (signed_value), howto->name);
7808 return bfd_reloc_overflow;
7811 /* Mask out the value and U bit. */
7812 insn &= 0xff7fff00;
7814 /* Set the U bit if the value to go in the place is non-negative. */
7815 if (signed_value >= 0)
7816 insn |= 1 << 23;
7818 /* Encode the offset. */
7819 insn |= residual >> 2;
7821 bfd_put_32 (input_bfd, insn, hit_data);
7823 return bfd_reloc_ok;
7825 default:
7826 return bfd_reloc_notsupported;
7830 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7831 static void
7832 arm_add_to_rel (bfd * abfd,
7833 bfd_byte * address,
7834 reloc_howto_type * howto,
7835 bfd_signed_vma increment)
7837 bfd_signed_vma addend;
7839 if (howto->type == R_ARM_THM_CALL
7840 || howto->type == R_ARM_THM_JUMP24)
7842 int upper_insn, lower_insn;
7843 int upper, lower;
7845 upper_insn = bfd_get_16 (abfd, address);
7846 lower_insn = bfd_get_16 (abfd, address + 2);
7847 upper = upper_insn & 0x7ff;
7848 lower = lower_insn & 0x7ff;
7850 addend = (upper << 12) | (lower << 1);
7851 addend += increment;
7852 addend >>= 1;
7854 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7855 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7857 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7858 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
7860 else
7862 bfd_vma contents;
7864 contents = bfd_get_32 (abfd, address);
7866 /* Get the (signed) value from the instruction. */
7867 addend = contents & howto->src_mask;
7868 if (addend & ((howto->src_mask + 1) >> 1))
7870 bfd_signed_vma mask;
7872 mask = -1;
7873 mask &= ~ howto->src_mask;
7874 addend |= mask;
7877 /* Add in the increment, (which is a byte value). */
7878 switch (howto->type)
7880 default:
7881 addend += increment;
7882 break;
7884 case R_ARM_PC24:
7885 case R_ARM_PLT32:
7886 case R_ARM_CALL:
7887 case R_ARM_JUMP24:
7888 addend <<= howto->size;
7889 addend += increment;
7891 /* Should we check for overflow here ? */
7893 /* Drop any undesired bits. */
7894 addend >>= howto->rightshift;
7895 break;
7898 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7900 bfd_put_32 (abfd, contents, address);
7904 #define IS_ARM_TLS_RELOC(R_TYPE) \
7905 ((R_TYPE) == R_ARM_TLS_GD32 \
7906 || (R_TYPE) == R_ARM_TLS_LDO32 \
7907 || (R_TYPE) == R_ARM_TLS_LDM32 \
7908 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7909 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7910 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7911 || (R_TYPE) == R_ARM_TLS_LE32 \
7912 || (R_TYPE) == R_ARM_TLS_IE32)
7914 /* Relocate an ARM ELF section. */
7916 static bfd_boolean
7917 elf32_arm_relocate_section (bfd * output_bfd,
7918 struct bfd_link_info * info,
7919 bfd * input_bfd,
7920 asection * input_section,
7921 bfd_byte * contents,
7922 Elf_Internal_Rela * relocs,
7923 Elf_Internal_Sym * local_syms,
7924 asection ** local_sections)
7926 Elf_Internal_Shdr *symtab_hdr;
7927 struct elf_link_hash_entry **sym_hashes;
7928 Elf_Internal_Rela *rel;
7929 Elf_Internal_Rela *relend;
7930 const char *name;
7931 struct elf32_arm_link_hash_table * globals;
7933 globals = elf32_arm_hash_table (info);
7935 symtab_hdr = & elf_symtab_hdr (input_bfd);
7936 sym_hashes = elf_sym_hashes (input_bfd);
7938 rel = relocs;
7939 relend = relocs + input_section->reloc_count;
7940 for (; rel < relend; rel++)
7942 int r_type;
7943 reloc_howto_type * howto;
7944 unsigned long r_symndx;
7945 Elf_Internal_Sym * sym;
7946 asection * sec;
7947 struct elf_link_hash_entry * h;
7948 bfd_vma relocation;
7949 bfd_reloc_status_type r;
7950 arelent bfd_reloc;
7951 char sym_type;
7952 bfd_boolean unresolved_reloc = FALSE;
7953 char *error_message = NULL;
7955 r_symndx = ELF32_R_SYM (rel->r_info);
7956 r_type = ELF32_R_TYPE (rel->r_info);
7957 r_type = arm_real_reloc_type (globals, r_type);
7959 if ( r_type == R_ARM_GNU_VTENTRY
7960 || r_type == R_ARM_GNU_VTINHERIT)
7961 continue;
7963 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
7964 howto = bfd_reloc.howto;
7966 h = NULL;
7967 sym = NULL;
7968 sec = NULL;
7970 if (r_symndx < symtab_hdr->sh_info)
7972 sym = local_syms + r_symndx;
7973 sym_type = ELF32_ST_TYPE (sym->st_info);
7974 sec = local_sections[r_symndx];
7975 if (globals->use_rel)
7977 relocation = (sec->output_section->vma
7978 + sec->output_offset
7979 + sym->st_value);
7980 if (!info->relocatable
7981 && (sec->flags & SEC_MERGE)
7982 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7984 asection *msec;
7985 bfd_vma addend, value;
7987 switch (r_type)
7989 case R_ARM_MOVW_ABS_NC:
7990 case R_ARM_MOVT_ABS:
7991 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7992 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7993 addend = (addend ^ 0x8000) - 0x8000;
7994 break;
7996 case R_ARM_THM_MOVW_ABS_NC:
7997 case R_ARM_THM_MOVT_ABS:
7998 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7999 << 16;
8000 value |= bfd_get_16 (input_bfd,
8001 contents + rel->r_offset + 2);
8002 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
8003 | ((value & 0x04000000) >> 15);
8004 addend = (addend ^ 0x8000) - 0x8000;
8005 break;
8007 default:
8008 if (howto->rightshift
8009 || (howto->src_mask & (howto->src_mask + 1)))
8011 (*_bfd_error_handler)
8012 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
8013 input_bfd, input_section,
8014 (long) rel->r_offset, howto->name);
8015 return FALSE;
8018 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
8020 /* Get the (signed) value from the instruction. */
8021 addend = value & howto->src_mask;
8022 if (addend & ((howto->src_mask + 1) >> 1))
8024 bfd_signed_vma mask;
8026 mask = -1;
8027 mask &= ~ howto->src_mask;
8028 addend |= mask;
8030 break;
8033 msec = sec;
8034 addend =
8035 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
8036 - relocation;
8037 addend += msec->output_section->vma + msec->output_offset;
8039 /* Cases here must match those in the preceeding
8040 switch statement. */
8041 switch (r_type)
8043 case R_ARM_MOVW_ABS_NC:
8044 case R_ARM_MOVT_ABS:
8045 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
8046 | (addend & 0xfff);
8047 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8048 break;
8050 case R_ARM_THM_MOVW_ABS_NC:
8051 case R_ARM_THM_MOVT_ABS:
8052 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
8053 | (addend & 0xff) | ((addend & 0x0800) << 15);
8054 bfd_put_16 (input_bfd, value >> 16,
8055 contents + rel->r_offset);
8056 bfd_put_16 (input_bfd, value,
8057 contents + rel->r_offset + 2);
8058 break;
8060 default:
8061 value = (value & ~ howto->dst_mask)
8062 | (addend & howto->dst_mask);
8063 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8064 break;
8068 else
8069 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
8071 else
8073 bfd_boolean warned;
8075 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
8076 r_symndx, symtab_hdr, sym_hashes,
8077 h, sec, relocation,
8078 unresolved_reloc, warned);
8080 sym_type = h->type;
8083 if (sec != NULL && elf_discarded_section (sec))
8085 /* For relocs against symbols from removed linkonce sections,
8086 or sections discarded by a linker script, we just want the
8087 section contents zeroed. Avoid any special processing. */
8088 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
8089 rel->r_info = 0;
8090 rel->r_addend = 0;
8091 continue;
8094 if (info->relocatable)
8096 /* This is a relocatable link. We don't have to change
8097 anything, unless the reloc is against a section symbol,
8098 in which case we have to adjust according to where the
8099 section symbol winds up in the output section. */
8100 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8102 if (globals->use_rel)
8103 arm_add_to_rel (input_bfd, contents + rel->r_offset,
8104 howto, (bfd_signed_vma) sec->output_offset);
8105 else
8106 rel->r_addend += sec->output_offset;
8108 continue;
8111 if (h != NULL)
8112 name = h->root.root.string;
8113 else
8115 name = (bfd_elf_string_from_elf_section
8116 (input_bfd, symtab_hdr->sh_link, sym->st_name));
8117 if (name == NULL || *name == '\0')
8118 name = bfd_section_name (input_bfd, sec);
8121 if (r_symndx != 0
8122 && r_type != R_ARM_NONE
8123 && (h == NULL
8124 || h->root.type == bfd_link_hash_defined
8125 || h->root.type == bfd_link_hash_defweak)
8126 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
8128 (*_bfd_error_handler)
8129 ((sym_type == STT_TLS
8130 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8131 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8132 input_bfd,
8133 input_section,
8134 (long) rel->r_offset,
8135 howto->name,
8136 name);
8139 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
8140 input_section, contents, rel,
8141 relocation, info, sec, name,
8142 (h ? ELF_ST_TYPE (h->type) :
8143 ELF_ST_TYPE (sym->st_info)), h,
8144 &unresolved_reloc, &error_message);
8146 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8147 because such sections are not SEC_ALLOC and thus ld.so will
8148 not process them. */
8149 if (unresolved_reloc
8150 && !((input_section->flags & SEC_DEBUGGING) != 0
8151 && h->def_dynamic))
8153 (*_bfd_error_handler)
8154 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8155 input_bfd,
8156 input_section,
8157 (long) rel->r_offset,
8158 howto->name,
8159 h->root.root.string);
8160 return FALSE;
8163 if (r != bfd_reloc_ok)
8165 switch (r)
8167 case bfd_reloc_overflow:
8168 /* If the overflowing reloc was to an undefined symbol,
8169 we have already printed one error message and there
8170 is no point complaining again. */
8171 if ((! h ||
8172 h->root.type != bfd_link_hash_undefined)
8173 && (!((*info->callbacks->reloc_overflow)
8174 (info, (h ? &h->root : NULL), name, howto->name,
8175 (bfd_vma) 0, input_bfd, input_section,
8176 rel->r_offset))))
8177 return FALSE;
8178 break;
8180 case bfd_reloc_undefined:
8181 if (!((*info->callbacks->undefined_symbol)
8182 (info, name, input_bfd, input_section,
8183 rel->r_offset, TRUE)))
8184 return FALSE;
8185 break;
8187 case bfd_reloc_outofrange:
8188 error_message = _("out of range");
8189 goto common_error;
8191 case bfd_reloc_notsupported:
8192 error_message = _("unsupported relocation");
8193 goto common_error;
8195 case bfd_reloc_dangerous:
8196 /* error_message should already be set. */
8197 goto common_error;
8199 default:
8200 error_message = _("unknown error");
8201 /* Fall through. */
8203 common_error:
8204 BFD_ASSERT (error_message != NULL);
8205 if (!((*info->callbacks->reloc_dangerous)
8206 (info, error_message, input_bfd, input_section,
8207 rel->r_offset)))
8208 return FALSE;
8209 break;
8214 return TRUE;
8217 /* Set the right machine number. */
8219 static bfd_boolean
8220 elf32_arm_object_p (bfd *abfd)
8222 unsigned int mach;
8224 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
8226 if (mach != bfd_mach_arm_unknown)
8227 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8229 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8230 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
8232 else
8233 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8235 return TRUE;
8238 /* Function to keep ARM specific flags in the ELF header. */
8240 static bfd_boolean
8241 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
8243 if (elf_flags_init (abfd)
8244 && elf_elfheader (abfd)->e_flags != flags)
8246 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8248 if (flags & EF_ARM_INTERWORK)
8249 (*_bfd_error_handler)
8250 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8251 abfd);
8252 else
8253 _bfd_error_handler
8254 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8255 abfd);
8258 else
8260 elf_elfheader (abfd)->e_flags = flags;
8261 elf_flags_init (abfd) = TRUE;
8264 return TRUE;
8267 /* Copy backend specific data from one object module to another. */
8269 static bfd_boolean
8270 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
8272 flagword in_flags;
8273 flagword out_flags;
8275 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8276 return TRUE;
8278 in_flags = elf_elfheader (ibfd)->e_flags;
8279 out_flags = elf_elfheader (obfd)->e_flags;
8281 if (elf_flags_init (obfd)
8282 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8283 && in_flags != out_flags)
8285 /* Cannot mix APCS26 and APCS32 code. */
8286 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8287 return FALSE;
8289 /* Cannot mix float APCS and non-float APCS code. */
8290 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8291 return FALSE;
8293 /* If the src and dest have different interworking flags
8294 then turn off the interworking bit. */
8295 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8297 if (out_flags & EF_ARM_INTERWORK)
8298 _bfd_error_handler
8299 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8300 obfd, ibfd);
8302 in_flags &= ~EF_ARM_INTERWORK;
8305 /* Likewise for PIC, though don't warn for this case. */
8306 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8307 in_flags &= ~EF_ARM_PIC;
8310 elf_elfheader (obfd)->e_flags = in_flags;
8311 elf_flags_init (obfd) = TRUE;
8313 /* Also copy the EI_OSABI field. */
8314 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8315 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8317 /* Copy object attributes. */
8318 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8320 return TRUE;
8323 /* Values for Tag_ABI_PCS_R9_use. */
8324 enum
8326 AEABI_R9_V6,
8327 AEABI_R9_SB,
8328 AEABI_R9_TLS,
8329 AEABI_R9_unused
8332 /* Values for Tag_ABI_PCS_RW_data. */
8333 enum
8335 AEABI_PCS_RW_data_absolute,
8336 AEABI_PCS_RW_data_PCrel,
8337 AEABI_PCS_RW_data_SBrel,
8338 AEABI_PCS_RW_data_unused
8341 /* Values for Tag_ABI_enum_size. */
8342 enum
8344 AEABI_enum_unused,
8345 AEABI_enum_short,
8346 AEABI_enum_wide,
8347 AEABI_enum_forced_wide
8350 /* Determine whether an object attribute tag takes an integer, a
8351 string or both. */
8353 static int
8354 elf32_arm_obj_attrs_arg_type (int tag)
8356 if (tag == Tag_compatibility)
8357 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
8358 else if (tag == Tag_nodefaults)
8359 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
8360 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
8361 return ATTR_TYPE_FLAG_STR_VAL;
8362 else if (tag < 32)
8363 return ATTR_TYPE_FLAG_INT_VAL;
8364 else
8365 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
8368 /* The ABI defines that Tag_conformance should be emitted first, and that
8369 Tag_nodefaults should be second (if either is defined). This sets those
8370 two positions, and bumps up the position of all the remaining tags to
8371 compensate. */
8372 static int
8373 elf32_arm_obj_attrs_order (int num)
8375 if (num == 4)
8376 return Tag_conformance;
8377 if (num == 5)
8378 return Tag_nodefaults;
8379 if ((num - 2) < Tag_nodefaults)
8380 return num - 2;
8381 if ((num - 1) < Tag_conformance)
8382 return num - 1;
8383 return num;
8386 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
8387 Returns -1 if no architecture could be read. */
8389 static int
8390 get_secondary_compatible_arch (bfd *abfd)
8392 obj_attribute *attr =
8393 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8395 /* Note: the tag and its argument below are uleb128 values, though
8396 currently-defined values fit in one byte for each. */
8397 if (attr->s
8398 && attr->s[0] == Tag_CPU_arch
8399 && (attr->s[1] & 128) != 128
8400 && attr->s[2] == 0)
8401 return attr->s[1];
8403 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8404 return -1;
8407 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8408 The tag is removed if ARCH is -1. */
8410 static void
8411 set_secondary_compatible_arch (bfd *abfd, int arch)
8413 obj_attribute *attr =
8414 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8416 if (arch == -1)
8418 attr->s = NULL;
8419 return;
8422 /* Note: the tag and its argument below are uleb128 values, though
8423 currently-defined values fit in one byte for each. */
8424 if (!attr->s)
8425 attr->s = bfd_alloc (abfd, 3);
8426 attr->s[0] = Tag_CPU_arch;
8427 attr->s[1] = arch;
8428 attr->s[2] = '\0';
8431 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8432 into account. */
8434 static int
8435 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
8436 int newtag, int secondary_compat)
8438 #define T(X) TAG_CPU_ARCH_##X
8439 int tagl, tagh, result;
8440 const int v6t2[] =
8442 T(V6T2), /* PRE_V4. */
8443 T(V6T2), /* V4. */
8444 T(V6T2), /* V4T. */
8445 T(V6T2), /* V5T. */
8446 T(V6T2), /* V5TE. */
8447 T(V6T2), /* V5TEJ. */
8448 T(V6T2), /* V6. */
8449 T(V7), /* V6KZ. */
8450 T(V6T2) /* V6T2. */
8452 const int v6k[] =
8454 T(V6K), /* PRE_V4. */
8455 T(V6K), /* V4. */
8456 T(V6K), /* V4T. */
8457 T(V6K), /* V5T. */
8458 T(V6K), /* V5TE. */
8459 T(V6K), /* V5TEJ. */
8460 T(V6K), /* V6. */
8461 T(V6KZ), /* V6KZ. */
8462 T(V7), /* V6T2. */
8463 T(V6K) /* V6K. */
8465 const int v7[] =
8467 T(V7), /* PRE_V4. */
8468 T(V7), /* V4. */
8469 T(V7), /* V4T. */
8470 T(V7), /* V5T. */
8471 T(V7), /* V5TE. */
8472 T(V7), /* V5TEJ. */
8473 T(V7), /* V6. */
8474 T(V7), /* V6KZ. */
8475 T(V7), /* V6T2. */
8476 T(V7), /* V6K. */
8477 T(V7) /* V7. */
8479 const int v6_m[] =
8481 -1, /* PRE_V4. */
8482 -1, /* V4. */
8483 T(V6K), /* V4T. */
8484 T(V6K), /* V5T. */
8485 T(V6K), /* V5TE. */
8486 T(V6K), /* V5TEJ. */
8487 T(V6K), /* V6. */
8488 T(V6KZ), /* V6KZ. */
8489 T(V7), /* V6T2. */
8490 T(V6K), /* V6K. */
8491 T(V7), /* V7. */
8492 T(V6_M) /* V6_M. */
8494 const int v6s_m[] =
8496 -1, /* PRE_V4. */
8497 -1, /* V4. */
8498 T(V6K), /* V4T. */
8499 T(V6K), /* V5T. */
8500 T(V6K), /* V5TE. */
8501 T(V6K), /* V5TEJ. */
8502 T(V6K), /* V6. */
8503 T(V6KZ), /* V6KZ. */
8504 T(V7), /* V6T2. */
8505 T(V6K), /* V6K. */
8506 T(V7), /* V7. */
8507 T(V6S_M), /* V6_M. */
8508 T(V6S_M) /* V6S_M. */
8510 const int v4t_plus_v6_m[] =
8512 -1, /* PRE_V4. */
8513 -1, /* V4. */
8514 T(V4T), /* V4T. */
8515 T(V5T), /* V5T. */
8516 T(V5TE), /* V5TE. */
8517 T(V5TEJ), /* V5TEJ. */
8518 T(V6), /* V6. */
8519 T(V6KZ), /* V6KZ. */
8520 T(V6T2), /* V6T2. */
8521 T(V6K), /* V6K. */
8522 T(V7), /* V7. */
8523 T(V6_M), /* V6_M. */
8524 T(V6S_M), /* V6S_M. */
8525 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
8527 const int *comb[] =
8529 v6t2,
8530 v6k,
8532 v6_m,
8533 v6s_m,
8534 /* Pseudo-architecture. */
8535 v4t_plus_v6_m
8538 /* Check we've not got a higher architecture than we know about. */
8540 if (oldtag >= MAX_TAG_CPU_ARCH || newtag >= MAX_TAG_CPU_ARCH)
8542 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd);
8543 return -1;
8546 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8548 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
8549 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
8550 oldtag = T(V4T_PLUS_V6_M);
8552 /* And override the new tag if we have a Tag_also_compatible_with on the
8553 input. */
8555 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
8556 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
8557 newtag = T(V4T_PLUS_V6_M);
8559 tagl = (oldtag < newtag) ? oldtag : newtag;
8560 result = tagh = (oldtag > newtag) ? oldtag : newtag;
8562 /* Architectures before V6KZ add features monotonically. */
8563 if (tagh <= TAG_CPU_ARCH_V6KZ)
8564 return result;
8566 result = comb[tagh - T(V6T2)][tagl];
8568 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8569 as the canonical version. */
8570 if (result == T(V4T_PLUS_V6_M))
8572 result = T(V4T);
8573 *secondary_compat_out = T(V6_M);
8575 else
8576 *secondary_compat_out = -1;
8578 if (result == -1)
8580 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
8581 ibfd, oldtag, newtag);
8582 return -1;
8585 return result;
8586 #undef T
8589 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8590 are conflicting attributes. */
8592 static bfd_boolean
8593 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8595 obj_attribute *in_attr;
8596 obj_attribute *out_attr;
8597 obj_attribute_list *in_list;
8598 obj_attribute_list *out_list;
8599 obj_attribute_list **out_listp;
8600 /* Some tags have 0 = don't care, 1 = strong requirement,
8601 2 = weak requirement. */
8602 static const int order_021[3] = {0, 2, 1};
8603 /* For use with Tag_VFP_arch. */
8604 static const int order_01243[5] = {0, 1, 2, 4, 3};
8605 int i;
8606 bfd_boolean result = TRUE;
8608 if (!elf_known_obj_attributes_proc (obfd)[0].i)
8610 /* This is the first object. Copy the attributes. */
8611 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8613 /* Use the Tag_null value to indicate the attributes have been
8614 initialized. */
8615 elf_known_obj_attributes_proc (obfd)[0].i = 1;
8617 return TRUE;
8620 in_attr = elf_known_obj_attributes_proc (ibfd);
8621 out_attr = elf_known_obj_attributes_proc (obfd);
8622 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8623 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8625 /* Ignore mismatches if the object doesn't use floating point. */
8626 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8627 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8628 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8630 _bfd_error_handler
8631 (_("error: %B uses VFP register arguments, %B does not"),
8632 ibfd, obfd);
8633 result = FALSE;
8637 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
8639 /* Merge this attribute with existing attributes. */
8640 switch (i)
8642 case Tag_CPU_raw_name:
8643 case Tag_CPU_name:
8644 /* These are merged after Tag_CPU_arch. */
8645 break;
8647 case Tag_ABI_optimization_goals:
8648 case Tag_ABI_FP_optimization_goals:
8649 /* Use the first value seen. */
8650 break;
8652 case Tag_CPU_arch:
8654 int secondary_compat = -1, secondary_compat_out = -1;
8655 unsigned int saved_out_attr = out_attr[i].i;
8656 static const char *name_table[] = {
8657 /* These aren't real CPU names, but we can't guess
8658 that from the architecture version alone. */
8659 "Pre v4",
8660 "ARM v4",
8661 "ARM v4T",
8662 "ARM v5T",
8663 "ARM v5TE",
8664 "ARM v5TEJ",
8665 "ARM v6",
8666 "ARM v6KZ",
8667 "ARM v6T2",
8668 "ARM v6K",
8669 "ARM v7",
8670 "ARM v6-M",
8671 "ARM v6S-M"
8674 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8675 secondary_compat = get_secondary_compatible_arch (ibfd);
8676 secondary_compat_out = get_secondary_compatible_arch (obfd);
8677 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
8678 &secondary_compat_out,
8679 in_attr[i].i,
8680 secondary_compat);
8681 set_secondary_compatible_arch (obfd, secondary_compat_out);
8683 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8684 if (out_attr[i].i == saved_out_attr)
8685 ; /* Leave the names alone. */
8686 else if (out_attr[i].i == in_attr[i].i)
8688 /* The output architecture has been changed to match the
8689 input architecture. Use the input names. */
8690 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
8691 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
8692 : NULL;
8693 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
8694 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
8695 : NULL;
8697 else
8699 out_attr[Tag_CPU_name].s = NULL;
8700 out_attr[Tag_CPU_raw_name].s = NULL;
8703 /* If we still don't have a value for Tag_CPU_name,
8704 make one up now. Tag_CPU_raw_name remains blank. */
8705 if (out_attr[Tag_CPU_name].s == NULL
8706 && out_attr[i].i < ARRAY_SIZE (name_table))
8707 out_attr[Tag_CPU_name].s =
8708 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
8710 break;
8712 case Tag_ARM_ISA_use:
8713 case Tag_THUMB_ISA_use:
8714 case Tag_WMMX_arch:
8715 case Tag_Advanced_SIMD_arch:
8716 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
8717 case Tag_ABI_FP_rounding:
8718 case Tag_ABI_FP_exceptions:
8719 case Tag_ABI_FP_user_exceptions:
8720 case Tag_ABI_FP_number_model:
8721 case Tag_VFP_HP_extension:
8722 case Tag_CPU_unaligned_access:
8723 case Tag_T2EE_use:
8724 case Tag_Virtualization_use:
8725 case Tag_MPextension_use:
8726 /* Use the largest value specified. */
8727 if (in_attr[i].i > out_attr[i].i)
8728 out_attr[i].i = in_attr[i].i;
8729 break;
8731 case Tag_ABI_align8_preserved:
8732 case Tag_ABI_PCS_RO_data:
8733 /* Use the smallest value specified. */
8734 if (in_attr[i].i < out_attr[i].i)
8735 out_attr[i].i = in_attr[i].i;
8736 break;
8738 case Tag_ABI_align8_needed:
8739 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
8740 && (in_attr[Tag_ABI_align8_preserved].i == 0
8741 || out_attr[Tag_ABI_align8_preserved].i == 0))
8743 /* This error message should be enabled once all non-conformant
8744 binaries in the toolchain have had the attributes set
8745 properly.
8746 _bfd_error_handler
8747 (_("error: %B: 8-byte data alignment conflicts with %B"),
8748 obfd, ibfd);
8749 result = FALSE; */
8751 /* Fall through. */
8752 case Tag_ABI_FP_denormal:
8753 case Tag_ABI_PCS_GOT_use:
8754 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8755 value if greater than 2 (for future-proofing). */
8756 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
8757 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
8758 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
8759 out_attr[i].i = in_attr[i].i;
8760 break;
8763 case Tag_CPU_arch_profile:
8764 if (out_attr[i].i != in_attr[i].i)
8766 /* 0 will merge with anything.
8767 'A' and 'S' merge to 'A'.
8768 'R' and 'S' merge to 'R'.
8769 'M' and 'A|R|S' is an error. */
8770 if (out_attr[i].i == 0
8771 || (out_attr[i].i == 'S'
8772 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
8773 out_attr[i].i = in_attr[i].i;
8774 else if (in_attr[i].i == 0
8775 || (in_attr[i].i == 'S'
8776 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
8777 ; /* Do nothing. */
8778 else
8780 _bfd_error_handler
8781 (_("error: %B: Conflicting architecture profiles %c/%c"),
8782 ibfd,
8783 in_attr[i].i ? in_attr[i].i : '0',
8784 out_attr[i].i ? out_attr[i].i : '0');
8785 result = FALSE;
8788 break;
8789 case Tag_VFP_arch:
8790 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8791 largest value if greater than 4 (for future-proofing). */
8792 if ((in_attr[i].i > 4 && in_attr[i].i > out_attr[i].i)
8793 || (in_attr[i].i <= 4 && out_attr[i].i <= 4
8794 && order_01243[in_attr[i].i] > order_01243[out_attr[i].i]))
8795 out_attr[i].i = in_attr[i].i;
8796 break;
8797 case Tag_PCS_config:
8798 if (out_attr[i].i == 0)
8799 out_attr[i].i = in_attr[i].i;
8800 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8802 /* It's sometimes ok to mix different configs, so this is only
8803 a warning. */
8804 _bfd_error_handler
8805 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8807 break;
8808 case Tag_ABI_PCS_R9_use:
8809 if (in_attr[i].i != out_attr[i].i
8810 && out_attr[i].i != AEABI_R9_unused
8811 && in_attr[i].i != AEABI_R9_unused)
8813 _bfd_error_handler
8814 (_("error: %B: Conflicting use of R9"), ibfd);
8815 result = FALSE;
8817 if (out_attr[i].i == AEABI_R9_unused)
8818 out_attr[i].i = in_attr[i].i;
8819 break;
8820 case Tag_ABI_PCS_RW_data:
8821 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8822 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8823 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8825 _bfd_error_handler
8826 (_("error: %B: SB relative addressing conflicts with use of R9"),
8827 ibfd);
8828 result = FALSE;
8830 /* Use the smallest value specified. */
8831 if (in_attr[i].i < out_attr[i].i)
8832 out_attr[i].i = in_attr[i].i;
8833 break;
8834 case Tag_ABI_PCS_wchar_t:
8835 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8836 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
8838 _bfd_error_handler
8839 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8840 ibfd, in_attr[i].i, out_attr[i].i);
8842 else if (in_attr[i].i && !out_attr[i].i)
8843 out_attr[i].i = in_attr[i].i;
8844 break;
8845 case Tag_ABI_enum_size:
8846 if (in_attr[i].i != AEABI_enum_unused)
8848 if (out_attr[i].i == AEABI_enum_unused
8849 || out_attr[i].i == AEABI_enum_forced_wide)
8851 /* The existing object is compatible with anything.
8852 Use whatever requirements the new object has. */
8853 out_attr[i].i = in_attr[i].i;
8855 else if (in_attr[i].i != AEABI_enum_forced_wide
8856 && out_attr[i].i != in_attr[i].i
8857 && !elf_arm_tdata (obfd)->no_enum_size_warning)
8859 static const char *aeabi_enum_names[] =
8860 { "", "variable-size", "32-bit", "" };
8861 const char *in_name =
8862 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8863 ? aeabi_enum_names[in_attr[i].i]
8864 : "<unknown>";
8865 const char *out_name =
8866 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8867 ? aeabi_enum_names[out_attr[i].i]
8868 : "<unknown>";
8869 _bfd_error_handler
8870 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8871 ibfd, in_name, out_name);
8874 break;
8875 case Tag_ABI_VFP_args:
8876 /* Aready done. */
8877 break;
8878 case Tag_ABI_WMMX_args:
8879 if (in_attr[i].i != out_attr[i].i)
8881 _bfd_error_handler
8882 (_("error: %B uses iWMMXt register arguments, %B does not"),
8883 ibfd, obfd);
8884 result = FALSE;
8886 break;
8887 case Tag_compatibility:
8888 /* Merged in target-independent code. */
8889 break;
8890 case Tag_ABI_HardFP_use:
8891 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8892 if ((in_attr[i].i == 1 && out_attr[i].i == 2)
8893 || (in_attr[i].i == 2 && out_attr[i].i == 1))
8894 out_attr[i].i = 3;
8895 else if (in_attr[i].i > out_attr[i].i)
8896 out_attr[i].i = in_attr[i].i;
8897 break;
8898 case Tag_ABI_FP_16bit_format:
8899 if (in_attr[i].i != 0 && out_attr[i].i != 0)
8901 if (in_attr[i].i != out_attr[i].i)
8903 _bfd_error_handler
8904 (_("error: fp16 format mismatch between %B and %B"),
8905 ibfd, obfd);
8906 result = FALSE;
8909 if (in_attr[i].i != 0)
8910 out_attr[i].i = in_attr[i].i;
8911 break;
8913 case Tag_nodefaults:
8914 /* This tag is set if it exists, but the value is unused (and is
8915 typically zero). We don't actually need to do anything here -
8916 the merge happens automatically when the type flags are merged
8917 below. */
8918 break;
8919 case Tag_also_compatible_with:
8920 /* Already done in Tag_CPU_arch. */
8921 break;
8922 case Tag_conformance:
8923 /* Keep the attribute if it matches. Throw it away otherwise.
8924 No attribute means no claim to conform. */
8925 if (!in_attr[i].s || !out_attr[i].s
8926 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
8927 out_attr[i].s = NULL;
8928 break;
8930 default:
8932 bfd *err_bfd = NULL;
8934 /* The "known_obj_attributes" table does contain some undefined
8935 attributes. Ensure that there are unused. */
8936 if (out_attr[i].i != 0 || out_attr[i].s != NULL)
8937 err_bfd = obfd;
8938 else if (in_attr[i].i != 0 || in_attr[i].s != NULL)
8939 err_bfd = ibfd;
8941 if (err_bfd != NULL)
8943 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8944 if ((i & 127) < 64)
8946 _bfd_error_handler
8947 (_("%B: Unknown mandatory EABI object attribute %d"),
8948 err_bfd, i);
8949 bfd_set_error (bfd_error_bad_value);
8950 result = FALSE;
8952 else
8954 _bfd_error_handler
8955 (_("Warning: %B: Unknown EABI object attribute %d"),
8956 err_bfd, i);
8960 /* Only pass on attributes that match in both inputs. */
8961 if (in_attr[i].i != out_attr[i].i
8962 || in_attr[i].s != out_attr[i].s
8963 || (in_attr[i].s != NULL && out_attr[i].s != NULL
8964 && strcmp (in_attr[i].s, out_attr[i].s) != 0))
8966 out_attr[i].i = 0;
8967 out_attr[i].s = NULL;
8972 /* If out_attr was copied from in_attr then it won't have a type yet. */
8973 if (in_attr[i].type && !out_attr[i].type)
8974 out_attr[i].type = in_attr[i].type;
8977 /* Merge Tag_compatibility attributes and any common GNU ones. */
8978 _bfd_elf_merge_object_attributes (ibfd, obfd);
8980 /* Check for any attributes not known on ARM. */
8981 in_list = elf_other_obj_attributes_proc (ibfd);
8982 out_listp = &elf_other_obj_attributes_proc (obfd);
8983 out_list = *out_listp;
8985 for (; in_list || out_list; )
8987 bfd *err_bfd = NULL;
8988 int err_tag = 0;
8990 /* The tags for each list are in numerical order. */
8991 /* If the tags are equal, then merge. */
8992 if (out_list && (!in_list || in_list->tag > out_list->tag))
8994 /* This attribute only exists in obfd. We can't merge, and we don't
8995 know what the tag means, so delete it. */
8996 err_bfd = obfd;
8997 err_tag = out_list->tag;
8998 *out_listp = out_list->next;
8999 out_list = *out_listp;
9001 else if (in_list && (!out_list || in_list->tag < out_list->tag))
9003 /* This attribute only exists in ibfd. We can't merge, and we don't
9004 know what the tag means, so ignore it. */
9005 err_bfd = ibfd;
9006 err_tag = in_list->tag;
9007 in_list = in_list->next;
9009 else /* The tags are equal. */
9011 /* As present, all attributes in the list are unknown, and
9012 therefore can't be merged meaningfully. */
9013 err_bfd = obfd;
9014 err_tag = out_list->tag;
9016 /* Only pass on attributes that match in both inputs. */
9017 if (in_list->attr.i != out_list->attr.i
9018 || in_list->attr.s != out_list->attr.s
9019 || (in_list->attr.s && out_list->attr.s
9020 && strcmp (in_list->attr.s, out_list->attr.s) != 0))
9022 /* No match. Delete the attribute. */
9023 *out_listp = out_list->next;
9024 out_list = *out_listp;
9026 else
9028 /* Matched. Keep the attribute and move to the next. */
9029 out_list = out_list->next;
9030 in_list = in_list->next;
9034 if (err_bfd)
9036 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9037 if ((err_tag & 127) < 64)
9039 _bfd_error_handler
9040 (_("%B: Unknown mandatory EABI object attribute %d"),
9041 err_bfd, err_tag);
9042 bfd_set_error (bfd_error_bad_value);
9043 result = FALSE;
9045 else
9047 _bfd_error_handler
9048 (_("Warning: %B: Unknown EABI object attribute %d"),
9049 err_bfd, err_tag);
9053 return result;
9057 /* Return TRUE if the two EABI versions are incompatible. */
9059 static bfd_boolean
9060 elf32_arm_versions_compatible (unsigned iver, unsigned over)
9062 /* v4 and v5 are the same spec before and after it was released,
9063 so allow mixing them. */
9064 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
9065 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
9066 return TRUE;
9068 return (iver == over);
9071 /* Merge backend specific data from an object file to the output
9072 object file when linking. */
9074 static bfd_boolean
9075 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
9077 flagword out_flags;
9078 flagword in_flags;
9079 bfd_boolean flags_compatible = TRUE;
9080 asection *sec;
9082 /* Check if we have the same endianess. */
9083 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
9084 return FALSE;
9086 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
9087 return TRUE;
9089 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
9090 return FALSE;
9092 /* The input BFD must have had its flags initialised. */
9093 /* The following seems bogus to me -- The flags are initialized in
9094 the assembler but I don't think an elf_flags_init field is
9095 written into the object. */
9096 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9098 in_flags = elf_elfheader (ibfd)->e_flags;
9099 out_flags = elf_elfheader (obfd)->e_flags;
9101 /* In theory there is no reason why we couldn't handle this. However
9102 in practice it isn't even close to working and there is no real
9103 reason to want it. */
9104 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
9105 && !(ibfd->flags & DYNAMIC)
9106 && (in_flags & EF_ARM_BE8))
9108 _bfd_error_handler (_("error: %B is already in final BE8 format"),
9109 ibfd);
9110 return FALSE;
9113 if (!elf_flags_init (obfd))
9115 /* If the input is the default architecture and had the default
9116 flags then do not bother setting the flags for the output
9117 architecture, instead allow future merges to do this. If no
9118 future merges ever set these flags then they will retain their
9119 uninitialised values, which surprise surprise, correspond
9120 to the default values. */
9121 if (bfd_get_arch_info (ibfd)->the_default
9122 && elf_elfheader (ibfd)->e_flags == 0)
9123 return TRUE;
9125 elf_flags_init (obfd) = TRUE;
9126 elf_elfheader (obfd)->e_flags = in_flags;
9128 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
9129 && bfd_get_arch_info (obfd)->the_default)
9130 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
9132 return TRUE;
9135 /* Determine what should happen if the input ARM architecture
9136 does not match the output ARM architecture. */
9137 if (! bfd_arm_merge_machines (ibfd, obfd))
9138 return FALSE;
9140 /* Identical flags must be compatible. */
9141 if (in_flags == out_flags)
9142 return TRUE;
9144 /* Check to see if the input BFD actually contains any sections. If
9145 not, its flags may not have been initialised either, but it
9146 cannot actually cause any incompatiblity. Do not short-circuit
9147 dynamic objects; their section list may be emptied by
9148 elf_link_add_object_symbols.
9150 Also check to see if there are no code sections in the input.
9151 In this case there is no need to check for code specific flags.
9152 XXX - do we need to worry about floating-point format compatability
9153 in data sections ? */
9154 if (!(ibfd->flags & DYNAMIC))
9156 bfd_boolean null_input_bfd = TRUE;
9157 bfd_boolean only_data_sections = TRUE;
9159 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9161 /* Ignore synthetic glue sections. */
9162 if (strcmp (sec->name, ".glue_7")
9163 && strcmp (sec->name, ".glue_7t"))
9165 if ((bfd_get_section_flags (ibfd, sec)
9166 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9167 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9168 only_data_sections = FALSE;
9170 null_input_bfd = FALSE;
9171 break;
9175 if (null_input_bfd || only_data_sections)
9176 return TRUE;
9179 /* Complain about various flag mismatches. */
9180 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
9181 EF_ARM_EABI_VERSION (out_flags)))
9183 _bfd_error_handler
9184 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
9185 ibfd, obfd,
9186 (in_flags & EF_ARM_EABIMASK) >> 24,
9187 (out_flags & EF_ARM_EABIMASK) >> 24);
9188 return FALSE;
9191 /* Not sure what needs to be checked for EABI versions >= 1. */
9192 /* VxWorks libraries do not use these flags. */
9193 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
9194 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
9195 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
9197 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
9199 _bfd_error_handler
9200 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9201 ibfd, obfd,
9202 in_flags & EF_ARM_APCS_26 ? 26 : 32,
9203 out_flags & EF_ARM_APCS_26 ? 26 : 32);
9204 flags_compatible = FALSE;
9207 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
9209 if (in_flags & EF_ARM_APCS_FLOAT)
9210 _bfd_error_handler
9211 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
9212 ibfd, obfd);
9213 else
9214 _bfd_error_handler
9215 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
9216 ibfd, obfd);
9218 flags_compatible = FALSE;
9221 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
9223 if (in_flags & EF_ARM_VFP_FLOAT)
9224 _bfd_error_handler
9225 (_("error: %B uses VFP instructions, whereas %B does not"),
9226 ibfd, obfd);
9227 else
9228 _bfd_error_handler
9229 (_("error: %B uses FPA instructions, whereas %B does not"),
9230 ibfd, obfd);
9232 flags_compatible = FALSE;
9235 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
9237 if (in_flags & EF_ARM_MAVERICK_FLOAT)
9238 _bfd_error_handler
9239 (_("error: %B uses Maverick instructions, whereas %B does not"),
9240 ibfd, obfd);
9241 else
9242 _bfd_error_handler
9243 (_("error: %B does not use Maverick instructions, whereas %B does"),
9244 ibfd, obfd);
9246 flags_compatible = FALSE;
9249 #ifdef EF_ARM_SOFT_FLOAT
9250 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
9252 /* We can allow interworking between code that is VFP format
9253 layout, and uses either soft float or integer regs for
9254 passing floating point arguments and results. We already
9255 know that the APCS_FLOAT flags match; similarly for VFP
9256 flags. */
9257 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
9258 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
9260 if (in_flags & EF_ARM_SOFT_FLOAT)
9261 _bfd_error_handler
9262 (_("error: %B uses software FP, whereas %B uses hardware FP"),
9263 ibfd, obfd);
9264 else
9265 _bfd_error_handler
9266 (_("error: %B uses hardware FP, whereas %B uses software FP"),
9267 ibfd, obfd);
9269 flags_compatible = FALSE;
9272 #endif
9274 /* Interworking mismatch is only a warning. */
9275 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
9277 if (in_flags & EF_ARM_INTERWORK)
9279 _bfd_error_handler
9280 (_("Warning: %B supports interworking, whereas %B does not"),
9281 ibfd, obfd);
9283 else
9285 _bfd_error_handler
9286 (_("Warning: %B does not support interworking, whereas %B does"),
9287 ibfd, obfd);
9292 return flags_compatible;
9295 /* Display the flags field. */
9297 static bfd_boolean
9298 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
9300 FILE * file = (FILE *) ptr;
9301 unsigned long flags;
9303 BFD_ASSERT (abfd != NULL && ptr != NULL);
9305 /* Print normal ELF private data. */
9306 _bfd_elf_print_private_bfd_data (abfd, ptr);
9308 flags = elf_elfheader (abfd)->e_flags;
9309 /* Ignore init flag - it may not be set, despite the flags field
9310 containing valid data. */
9312 /* xgettext:c-format */
9313 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
9315 switch (EF_ARM_EABI_VERSION (flags))
9317 case EF_ARM_EABI_UNKNOWN:
9318 /* The following flag bits are GNU extensions and not part of the
9319 official ARM ELF extended ABI. Hence they are only decoded if
9320 the EABI version is not set. */
9321 if (flags & EF_ARM_INTERWORK)
9322 fprintf (file, _(" [interworking enabled]"));
9324 if (flags & EF_ARM_APCS_26)
9325 fprintf (file, " [APCS-26]");
9326 else
9327 fprintf (file, " [APCS-32]");
9329 if (flags & EF_ARM_VFP_FLOAT)
9330 fprintf (file, _(" [VFP float format]"));
9331 else if (flags & EF_ARM_MAVERICK_FLOAT)
9332 fprintf (file, _(" [Maverick float format]"));
9333 else
9334 fprintf (file, _(" [FPA float format]"));
9336 if (flags & EF_ARM_APCS_FLOAT)
9337 fprintf (file, _(" [floats passed in float registers]"));
9339 if (flags & EF_ARM_PIC)
9340 fprintf (file, _(" [position independent]"));
9342 if (flags & EF_ARM_NEW_ABI)
9343 fprintf (file, _(" [new ABI]"));
9345 if (flags & EF_ARM_OLD_ABI)
9346 fprintf (file, _(" [old ABI]"));
9348 if (flags & EF_ARM_SOFT_FLOAT)
9349 fprintf (file, _(" [software FP]"));
9351 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
9352 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
9353 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
9354 | EF_ARM_MAVERICK_FLOAT);
9355 break;
9357 case EF_ARM_EABI_VER1:
9358 fprintf (file, _(" [Version1 EABI]"));
9360 if (flags & EF_ARM_SYMSARESORTED)
9361 fprintf (file, _(" [sorted symbol table]"));
9362 else
9363 fprintf (file, _(" [unsorted symbol table]"));
9365 flags &= ~ EF_ARM_SYMSARESORTED;
9366 break;
9368 case EF_ARM_EABI_VER2:
9369 fprintf (file, _(" [Version2 EABI]"));
9371 if (flags & EF_ARM_SYMSARESORTED)
9372 fprintf (file, _(" [sorted symbol table]"));
9373 else
9374 fprintf (file, _(" [unsorted symbol table]"));
9376 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
9377 fprintf (file, _(" [dynamic symbols use segment index]"));
9379 if (flags & EF_ARM_MAPSYMSFIRST)
9380 fprintf (file, _(" [mapping symbols precede others]"));
9382 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
9383 | EF_ARM_MAPSYMSFIRST);
9384 break;
9386 case EF_ARM_EABI_VER3:
9387 fprintf (file, _(" [Version3 EABI]"));
9388 break;
9390 case EF_ARM_EABI_VER4:
9391 fprintf (file, _(" [Version4 EABI]"));
9392 goto eabi;
9394 case EF_ARM_EABI_VER5:
9395 fprintf (file, _(" [Version5 EABI]"));
9396 eabi:
9397 if (flags & EF_ARM_BE8)
9398 fprintf (file, _(" [BE8]"));
9400 if (flags & EF_ARM_LE8)
9401 fprintf (file, _(" [LE8]"));
9403 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
9404 break;
9406 default:
9407 fprintf (file, _(" <EABI version unrecognised>"));
9408 break;
9411 flags &= ~ EF_ARM_EABIMASK;
9413 if (flags & EF_ARM_RELEXEC)
9414 fprintf (file, _(" [relocatable executable]"));
9416 if (flags & EF_ARM_HASENTRY)
9417 fprintf (file, _(" [has entry point]"));
9419 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
9421 if (flags)
9422 fprintf (file, _("<Unrecognised flag bits set>"));
9424 fputc ('\n', file);
9426 return TRUE;
9429 static int
9430 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
9432 switch (ELF_ST_TYPE (elf_sym->st_info))
9434 case STT_ARM_TFUNC:
9435 return ELF_ST_TYPE (elf_sym->st_info);
9437 case STT_ARM_16BIT:
9438 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9439 This allows us to distinguish between data used by Thumb instructions
9440 and non-data (which is probably code) inside Thumb regions of an
9441 executable. */
9442 if (type != STT_OBJECT && type != STT_TLS)
9443 return ELF_ST_TYPE (elf_sym->st_info);
9444 break;
9446 default:
9447 break;
9450 return type;
9453 static asection *
9454 elf32_arm_gc_mark_hook (asection *sec,
9455 struct bfd_link_info *info,
9456 Elf_Internal_Rela *rel,
9457 struct elf_link_hash_entry *h,
9458 Elf_Internal_Sym *sym)
9460 if (h != NULL)
9461 switch (ELF32_R_TYPE (rel->r_info))
9463 case R_ARM_GNU_VTINHERIT:
9464 case R_ARM_GNU_VTENTRY:
9465 return NULL;
9468 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
9471 /* Update the got entry reference counts for the section being removed. */
9473 static bfd_boolean
9474 elf32_arm_gc_sweep_hook (bfd * abfd,
9475 struct bfd_link_info * info,
9476 asection * sec,
9477 const Elf_Internal_Rela * relocs)
9479 Elf_Internal_Shdr *symtab_hdr;
9480 struct elf_link_hash_entry **sym_hashes;
9481 bfd_signed_vma *local_got_refcounts;
9482 const Elf_Internal_Rela *rel, *relend;
9483 struct elf32_arm_link_hash_table * globals;
9485 if (info->relocatable)
9486 return TRUE;
9488 globals = elf32_arm_hash_table (info);
9490 elf_section_data (sec)->local_dynrel = NULL;
9492 symtab_hdr = & elf_symtab_hdr (abfd);
9493 sym_hashes = elf_sym_hashes (abfd);
9494 local_got_refcounts = elf_local_got_refcounts (abfd);
9496 check_use_blx (globals);
9498 relend = relocs + sec->reloc_count;
9499 for (rel = relocs; rel < relend; rel++)
9501 unsigned long r_symndx;
9502 struct elf_link_hash_entry *h = NULL;
9503 int r_type;
9505 r_symndx = ELF32_R_SYM (rel->r_info);
9506 if (r_symndx >= symtab_hdr->sh_info)
9508 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9509 while (h->root.type == bfd_link_hash_indirect
9510 || h->root.type == bfd_link_hash_warning)
9511 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9514 r_type = ELF32_R_TYPE (rel->r_info);
9515 r_type = arm_real_reloc_type (globals, r_type);
9516 switch (r_type)
9518 case R_ARM_GOT32:
9519 case R_ARM_GOT_PREL:
9520 case R_ARM_TLS_GD32:
9521 case R_ARM_TLS_IE32:
9522 if (h != NULL)
9524 if (h->got.refcount > 0)
9525 h->got.refcount -= 1;
9527 else if (local_got_refcounts != NULL)
9529 if (local_got_refcounts[r_symndx] > 0)
9530 local_got_refcounts[r_symndx] -= 1;
9532 break;
9534 case R_ARM_TLS_LDM32:
9535 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
9536 break;
9538 case R_ARM_ABS32:
9539 case R_ARM_ABS32_NOI:
9540 case R_ARM_REL32:
9541 case R_ARM_REL32_NOI:
9542 case R_ARM_PC24:
9543 case R_ARM_PLT32:
9544 case R_ARM_CALL:
9545 case R_ARM_JUMP24:
9546 case R_ARM_PREL31:
9547 case R_ARM_THM_CALL:
9548 case R_ARM_THM_JUMP24:
9549 case R_ARM_THM_JUMP19:
9550 case R_ARM_MOVW_ABS_NC:
9551 case R_ARM_MOVT_ABS:
9552 case R_ARM_MOVW_PREL_NC:
9553 case R_ARM_MOVT_PREL:
9554 case R_ARM_THM_MOVW_ABS_NC:
9555 case R_ARM_THM_MOVT_ABS:
9556 case R_ARM_THM_MOVW_PREL_NC:
9557 case R_ARM_THM_MOVT_PREL:
9558 /* Should the interworking branches be here also? */
9560 if (h != NULL)
9562 struct elf32_arm_link_hash_entry *eh;
9563 struct elf32_arm_relocs_copied **pp;
9564 struct elf32_arm_relocs_copied *p;
9566 eh = (struct elf32_arm_link_hash_entry *) h;
9568 if (h->plt.refcount > 0)
9570 h->plt.refcount -= 1;
9571 if (r_type == R_ARM_THM_CALL)
9572 eh->plt_maybe_thumb_refcount--;
9574 if (r_type == R_ARM_THM_JUMP24
9575 || r_type == R_ARM_THM_JUMP19)
9576 eh->plt_thumb_refcount--;
9579 if (r_type == R_ARM_ABS32
9580 || r_type == R_ARM_REL32
9581 || r_type == R_ARM_ABS32_NOI
9582 || r_type == R_ARM_REL32_NOI)
9584 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
9585 pp = &p->next)
9586 if (p->section == sec)
9588 p->count -= 1;
9589 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
9590 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
9591 p->pc_count -= 1;
9592 if (p->count == 0)
9593 *pp = p->next;
9594 break;
9598 break;
9600 default:
9601 break;
9605 return TRUE;
9608 /* Look through the relocs for a section during the first phase. */
9610 static bfd_boolean
9611 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
9612 asection *sec, const Elf_Internal_Rela *relocs)
9614 Elf_Internal_Shdr *symtab_hdr;
9615 struct elf_link_hash_entry **sym_hashes;
9616 const Elf_Internal_Rela *rel;
9617 const Elf_Internal_Rela *rel_end;
9618 bfd *dynobj;
9619 asection *sreloc;
9620 bfd_vma *local_got_offsets;
9621 struct elf32_arm_link_hash_table *htab;
9622 bfd_boolean needs_plt;
9623 unsigned long nsyms;
9625 if (info->relocatable)
9626 return TRUE;
9628 BFD_ASSERT (is_arm_elf (abfd));
9630 htab = elf32_arm_hash_table (info);
9631 sreloc = NULL;
9633 /* Create dynamic sections for relocatable executables so that we can
9634 copy relocations. */
9635 if (htab->root.is_relocatable_executable
9636 && ! htab->root.dynamic_sections_created)
9638 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
9639 return FALSE;
9642 dynobj = elf_hash_table (info)->dynobj;
9643 local_got_offsets = elf_local_got_offsets (abfd);
9645 symtab_hdr = & elf_symtab_hdr (abfd);
9646 sym_hashes = elf_sym_hashes (abfd);
9647 nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
9649 rel_end = relocs + sec->reloc_count;
9650 for (rel = relocs; rel < rel_end; rel++)
9652 struct elf_link_hash_entry *h;
9653 struct elf32_arm_link_hash_entry *eh;
9654 unsigned long r_symndx;
9655 int r_type;
9657 r_symndx = ELF32_R_SYM (rel->r_info);
9658 r_type = ELF32_R_TYPE (rel->r_info);
9659 r_type = arm_real_reloc_type (htab, r_type);
9661 if (r_symndx >= nsyms
9662 /* PR 9934: It is possible to have relocations that do not
9663 refer to symbols, thus it is also possible to have an
9664 object file containing relocations but no symbol table. */
9665 && (r_symndx > 0 || nsyms > 0))
9667 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9668 r_symndx);
9669 return FALSE;
9672 if (nsyms == 0 || r_symndx < symtab_hdr->sh_info)
9673 h = NULL;
9674 else
9676 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9677 while (h->root.type == bfd_link_hash_indirect
9678 || h->root.type == bfd_link_hash_warning)
9679 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9682 eh = (struct elf32_arm_link_hash_entry *) h;
9684 switch (r_type)
9686 case R_ARM_GOT32:
9687 case R_ARM_GOT_PREL:
9688 case R_ARM_TLS_GD32:
9689 case R_ARM_TLS_IE32:
9690 /* This symbol requires a global offset table entry. */
9692 int tls_type, old_tls_type;
9694 switch (r_type)
9696 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9697 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9698 default: tls_type = GOT_NORMAL; break;
9701 if (h != NULL)
9703 h->got.refcount++;
9704 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9706 else
9708 bfd_signed_vma *local_got_refcounts;
9710 /* This is a global offset table entry for a local symbol. */
9711 local_got_refcounts = elf_local_got_refcounts (abfd);
9712 if (local_got_refcounts == NULL)
9714 bfd_size_type size;
9716 size = symtab_hdr->sh_info;
9717 size *= (sizeof (bfd_signed_vma) + sizeof (char));
9718 local_got_refcounts = bfd_zalloc (abfd, size);
9719 if (local_got_refcounts == NULL)
9720 return FALSE;
9721 elf_local_got_refcounts (abfd) = local_got_refcounts;
9722 elf32_arm_local_got_tls_type (abfd)
9723 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9725 local_got_refcounts[r_symndx] += 1;
9726 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9729 /* We will already have issued an error message if there is a
9730 TLS / non-TLS mismatch, based on the symbol type. We don't
9731 support any linker relaxations. So just combine any TLS
9732 types needed. */
9733 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9734 && tls_type != GOT_NORMAL)
9735 tls_type |= old_tls_type;
9737 if (old_tls_type != tls_type)
9739 if (h != NULL)
9740 elf32_arm_hash_entry (h)->tls_type = tls_type;
9741 else
9742 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9745 /* Fall through. */
9747 case R_ARM_TLS_LDM32:
9748 if (r_type == R_ARM_TLS_LDM32)
9749 htab->tls_ldm_got.refcount++;
9750 /* Fall through. */
9752 case R_ARM_GOTOFF32:
9753 case R_ARM_GOTPC:
9754 if (htab->sgot == NULL)
9756 if (htab->root.dynobj == NULL)
9757 htab->root.dynobj = abfd;
9758 if (!create_got_section (htab->root.dynobj, info))
9759 return FALSE;
9761 break;
9763 case R_ARM_ABS12:
9764 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9765 ldr __GOTT_INDEX__ offsets. */
9766 if (!htab->vxworks_p)
9767 break;
9768 /* Fall through. */
9770 case R_ARM_PC24:
9771 case R_ARM_PLT32:
9772 case R_ARM_CALL:
9773 case R_ARM_JUMP24:
9774 case R_ARM_PREL31:
9775 case R_ARM_THM_CALL:
9776 case R_ARM_THM_JUMP24:
9777 case R_ARM_THM_JUMP19:
9778 needs_plt = 1;
9779 goto normal_reloc;
9781 case R_ARM_ABS32:
9782 case R_ARM_ABS32_NOI:
9783 case R_ARM_REL32:
9784 case R_ARM_REL32_NOI:
9785 case R_ARM_MOVW_ABS_NC:
9786 case R_ARM_MOVT_ABS:
9787 case R_ARM_MOVW_PREL_NC:
9788 case R_ARM_MOVT_PREL:
9789 case R_ARM_THM_MOVW_ABS_NC:
9790 case R_ARM_THM_MOVT_ABS:
9791 case R_ARM_THM_MOVW_PREL_NC:
9792 case R_ARM_THM_MOVT_PREL:
9793 needs_plt = 0;
9794 normal_reloc:
9796 /* Should the interworking branches be listed here? */
9797 if (h != NULL)
9799 /* If this reloc is in a read-only section, we might
9800 need a copy reloc. We can't check reliably at this
9801 stage whether the section is read-only, as input
9802 sections have not yet been mapped to output sections.
9803 Tentatively set the flag for now, and correct in
9804 adjust_dynamic_symbol. */
9805 if (!info->shared)
9806 h->non_got_ref = 1;
9808 /* We may need a .plt entry if the function this reloc
9809 refers to is in a different object. We can't tell for
9810 sure yet, because something later might force the
9811 symbol local. */
9812 if (needs_plt)
9813 h->needs_plt = 1;
9815 /* If we create a PLT entry, this relocation will reference
9816 it, even if it's an ABS32 relocation. */
9817 h->plt.refcount += 1;
9819 /* It's too early to use htab->use_blx here, so we have to
9820 record possible blx references separately from
9821 relocs that definitely need a thumb stub. */
9823 if (r_type == R_ARM_THM_CALL)
9824 eh->plt_maybe_thumb_refcount += 1;
9826 if (r_type == R_ARM_THM_JUMP24
9827 || r_type == R_ARM_THM_JUMP19)
9828 eh->plt_thumb_refcount += 1;
9831 /* If we are creating a shared library or relocatable executable,
9832 and this is a reloc against a global symbol, or a non PC
9833 relative reloc against a local symbol, then we need to copy
9834 the reloc into the shared library. However, if we are linking
9835 with -Bsymbolic, we do not need to copy a reloc against a
9836 global symbol which is defined in an object we are
9837 including in the link (i.e., DEF_REGULAR is set). At
9838 this point we have not seen all the input files, so it is
9839 possible that DEF_REGULAR is not set now but will be set
9840 later (it is never cleared). We account for that
9841 possibility below by storing information in the
9842 relocs_copied field of the hash table entry. */
9843 if ((info->shared || htab->root.is_relocatable_executable)
9844 && (sec->flags & SEC_ALLOC) != 0
9845 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
9846 || (h != NULL && ! h->needs_plt
9847 && (! info->symbolic || ! h->def_regular))))
9849 struct elf32_arm_relocs_copied *p, **head;
9851 /* When creating a shared object, we must copy these
9852 reloc types into the output file. We create a reloc
9853 section in dynobj and make room for this reloc. */
9854 if (sreloc == NULL)
9856 sreloc = _bfd_elf_make_dynamic_reloc_section
9857 (sec, dynobj, 2, abfd, ! htab->use_rel);
9859 if (sreloc == NULL)
9860 return FALSE;
9862 /* BPABI objects never have dynamic relocations mapped. */
9863 if (htab->symbian_p)
9865 flagword flags;
9867 flags = bfd_get_section_flags (dynobj, sreloc);
9868 flags &= ~(SEC_LOAD | SEC_ALLOC);
9869 bfd_set_section_flags (dynobj, sreloc, flags);
9873 /* If this is a global symbol, we count the number of
9874 relocations we need for this symbol. */
9875 if (h != NULL)
9877 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9879 else
9881 /* Track dynamic relocs needed for local syms too.
9882 We really need local syms available to do this
9883 easily. Oh well. */
9885 asection *s;
9886 void *vpp;
9888 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9889 sec, r_symndx);
9890 if (s == NULL)
9891 return FALSE;
9893 vpp = &elf_section_data (s)->local_dynrel;
9894 head = (struct elf32_arm_relocs_copied **) vpp;
9897 p = *head;
9898 if (p == NULL || p->section != sec)
9900 bfd_size_type amt = sizeof *p;
9902 p = bfd_alloc (htab->root.dynobj, amt);
9903 if (p == NULL)
9904 return FALSE;
9905 p->next = *head;
9906 *head = p;
9907 p->section = sec;
9908 p->count = 0;
9909 p->pc_count = 0;
9912 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
9913 p->pc_count += 1;
9914 p->count += 1;
9916 break;
9918 /* This relocation describes the C++ object vtable hierarchy.
9919 Reconstruct it for later use during GC. */
9920 case R_ARM_GNU_VTINHERIT:
9921 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
9922 return FALSE;
9923 break;
9925 /* This relocation describes which C++ vtable entries are actually
9926 used. Record for later use during GC. */
9927 case R_ARM_GNU_VTENTRY:
9928 BFD_ASSERT (h != NULL);
9929 if (h != NULL
9930 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
9931 return FALSE;
9932 break;
9936 return TRUE;
9939 /* Unwinding tables are not referenced directly. This pass marks them as
9940 required if the corresponding code section is marked. */
9942 static bfd_boolean
9943 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9944 elf_gc_mark_hook_fn gc_mark_hook)
9946 bfd *sub;
9947 Elf_Internal_Shdr **elf_shdrp;
9948 bfd_boolean again;
9950 /* Marking EH data may cause additional code sections to be marked,
9951 requiring multiple passes. */
9952 again = TRUE;
9953 while (again)
9955 again = FALSE;
9956 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9958 asection *o;
9960 if (! is_arm_elf (sub))
9961 continue;
9963 elf_shdrp = elf_elfsections (sub);
9964 for (o = sub->sections; o != NULL; o = o->next)
9966 Elf_Internal_Shdr *hdr;
9968 hdr = &elf_section_data (o)->this_hdr;
9969 if (hdr->sh_type == SHT_ARM_EXIDX
9970 && hdr->sh_link
9971 && hdr->sh_link < elf_numsections (sub)
9972 && !o->gc_mark
9973 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
9975 again = TRUE;
9976 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
9977 return FALSE;
9983 return TRUE;
9986 /* Treat mapping symbols as special target symbols. */
9988 static bfd_boolean
9989 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
9991 return bfd_is_arm_special_symbol_name (sym->name,
9992 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
9995 /* This is a copy of elf_find_function() from elf.c except that
9996 ARM mapping symbols are ignored when looking for function names
9997 and STT_ARM_TFUNC is considered to a function type. */
9999 static bfd_boolean
10000 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
10001 asection * section,
10002 asymbol ** symbols,
10003 bfd_vma offset,
10004 const char ** filename_ptr,
10005 const char ** functionname_ptr)
10007 const char * filename = NULL;
10008 asymbol * func = NULL;
10009 bfd_vma low_func = 0;
10010 asymbol ** p;
10012 for (p = symbols; *p != NULL; p++)
10014 elf_symbol_type *q;
10016 q = (elf_symbol_type *) *p;
10018 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
10020 default:
10021 break;
10022 case STT_FILE:
10023 filename = bfd_asymbol_name (&q->symbol);
10024 break;
10025 case STT_FUNC:
10026 case STT_ARM_TFUNC:
10027 case STT_NOTYPE:
10028 /* Skip mapping symbols. */
10029 if ((q->symbol.flags & BSF_LOCAL)
10030 && bfd_is_arm_special_symbol_name (q->symbol.name,
10031 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
10032 continue;
10033 /* Fall through. */
10034 if (bfd_get_section (&q->symbol) == section
10035 && q->symbol.value >= low_func
10036 && q->symbol.value <= offset)
10038 func = (asymbol *) q;
10039 low_func = q->symbol.value;
10041 break;
10045 if (func == NULL)
10046 return FALSE;
10048 if (filename_ptr)
10049 *filename_ptr = filename;
10050 if (functionname_ptr)
10051 *functionname_ptr = bfd_asymbol_name (func);
10053 return TRUE;
10057 /* Find the nearest line to a particular section and offset, for error
10058 reporting. This code is a duplicate of the code in elf.c, except
10059 that it uses arm_elf_find_function. */
10061 static bfd_boolean
10062 elf32_arm_find_nearest_line (bfd * abfd,
10063 asection * section,
10064 asymbol ** symbols,
10065 bfd_vma offset,
10066 const char ** filename_ptr,
10067 const char ** functionname_ptr,
10068 unsigned int * line_ptr)
10070 bfd_boolean found = FALSE;
10072 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
10074 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
10075 filename_ptr, functionname_ptr,
10076 line_ptr, 0,
10077 & elf_tdata (abfd)->dwarf2_find_line_info))
10079 if (!*functionname_ptr)
10080 arm_elf_find_function (abfd, section, symbols, offset,
10081 *filename_ptr ? NULL : filename_ptr,
10082 functionname_ptr);
10084 return TRUE;
10087 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
10088 & found, filename_ptr,
10089 functionname_ptr, line_ptr,
10090 & elf_tdata (abfd)->line_info))
10091 return FALSE;
10093 if (found && (*functionname_ptr || *line_ptr))
10094 return TRUE;
10096 if (symbols == NULL)
10097 return FALSE;
10099 if (! arm_elf_find_function (abfd, section, symbols, offset,
10100 filename_ptr, functionname_ptr))
10101 return FALSE;
10103 *line_ptr = 0;
10104 return TRUE;
10107 static bfd_boolean
10108 elf32_arm_find_inliner_info (bfd * abfd,
10109 const char ** filename_ptr,
10110 const char ** functionname_ptr,
10111 unsigned int * line_ptr)
10113 bfd_boolean found;
10114 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
10115 functionname_ptr, line_ptr,
10116 & elf_tdata (abfd)->dwarf2_find_line_info);
10117 return found;
10120 /* Adjust a symbol defined by a dynamic object and referenced by a
10121 regular object. The current definition is in some section of the
10122 dynamic object, but we're not including those sections. We have to
10123 change the definition to something the rest of the link can
10124 understand. */
10126 static bfd_boolean
10127 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
10128 struct elf_link_hash_entry * h)
10130 bfd * dynobj;
10131 asection * s;
10132 struct elf32_arm_link_hash_entry * eh;
10133 struct elf32_arm_link_hash_table *globals;
10135 globals = elf32_arm_hash_table (info);
10136 dynobj = elf_hash_table (info)->dynobj;
10138 /* Make sure we know what is going on here. */
10139 BFD_ASSERT (dynobj != NULL
10140 && (h->needs_plt
10141 || h->u.weakdef != NULL
10142 || (h->def_dynamic
10143 && h->ref_regular
10144 && !h->def_regular)));
10146 eh = (struct elf32_arm_link_hash_entry *) h;
10148 /* If this is a function, put it in the procedure linkage table. We
10149 will fill in the contents of the procedure linkage table later,
10150 when we know the address of the .got section. */
10151 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
10152 || h->needs_plt)
10154 if (h->plt.refcount <= 0
10155 || SYMBOL_CALLS_LOCAL (info, h)
10156 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
10157 && h->root.type == bfd_link_hash_undefweak))
10159 /* This case can occur if we saw a PLT32 reloc in an input
10160 file, but the symbol was never referred to by a dynamic
10161 object, or if all references were garbage collected. In
10162 such a case, we don't actually need to build a procedure
10163 linkage table, and we can just do a PC24 reloc instead. */
10164 h->plt.offset = (bfd_vma) -1;
10165 eh->plt_thumb_refcount = 0;
10166 eh->plt_maybe_thumb_refcount = 0;
10167 h->needs_plt = 0;
10170 return TRUE;
10172 else
10174 /* It's possible that we incorrectly decided a .plt reloc was
10175 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10176 in check_relocs. We can't decide accurately between function
10177 and non-function syms in check-relocs; Objects loaded later in
10178 the link may change h->type. So fix it now. */
10179 h->plt.offset = (bfd_vma) -1;
10180 eh->plt_thumb_refcount = 0;
10181 eh->plt_maybe_thumb_refcount = 0;
10184 /* If this is a weak symbol, and there is a real definition, the
10185 processor independent code will have arranged for us to see the
10186 real definition first, and we can just use the same value. */
10187 if (h->u.weakdef != NULL)
10189 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
10190 || h->u.weakdef->root.type == bfd_link_hash_defweak);
10191 h->root.u.def.section = h->u.weakdef->root.u.def.section;
10192 h->root.u.def.value = h->u.weakdef->root.u.def.value;
10193 return TRUE;
10196 /* If there are no non-GOT references, we do not need a copy
10197 relocation. */
10198 if (!h->non_got_ref)
10199 return TRUE;
10201 /* This is a reference to a symbol defined by a dynamic object which
10202 is not a function. */
10204 /* If we are creating a shared library, we must presume that the
10205 only references to the symbol are via the global offset table.
10206 For such cases we need not do anything here; the relocations will
10207 be handled correctly by relocate_section. Relocatable executables
10208 can reference data in shared objects directly, so we don't need to
10209 do anything here. */
10210 if (info->shared || globals->root.is_relocatable_executable)
10211 return TRUE;
10213 if (h->size == 0)
10215 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
10216 h->root.root.string);
10217 return TRUE;
10220 /* We must allocate the symbol in our .dynbss section, which will
10221 become part of the .bss section of the executable. There will be
10222 an entry for this symbol in the .dynsym section. The dynamic
10223 object will contain position independent code, so all references
10224 from the dynamic object to this symbol will go through the global
10225 offset table. The dynamic linker will use the .dynsym entry to
10226 determine the address it must put in the global offset table, so
10227 both the dynamic object and the regular object will refer to the
10228 same memory location for the variable. */
10229 s = bfd_get_section_by_name (dynobj, ".dynbss");
10230 BFD_ASSERT (s != NULL);
10232 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10233 copy the initial value out of the dynamic object and into the
10234 runtime process image. We need to remember the offset into the
10235 .rel(a).bss section we are going to use. */
10236 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
10238 asection *srel;
10240 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
10241 BFD_ASSERT (srel != NULL);
10242 srel->size += RELOC_SIZE (globals);
10243 h->needs_copy = 1;
10246 return _bfd_elf_adjust_dynamic_copy (h, s);
10249 /* Allocate space in .plt, .got and associated reloc sections for
10250 dynamic relocs. */
10252 static bfd_boolean
10253 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
10255 struct bfd_link_info *info;
10256 struct elf32_arm_link_hash_table *htab;
10257 struct elf32_arm_link_hash_entry *eh;
10258 struct elf32_arm_relocs_copied *p;
10259 bfd_signed_vma thumb_refs;
10261 eh = (struct elf32_arm_link_hash_entry *) h;
10263 if (h->root.type == bfd_link_hash_indirect)
10264 return TRUE;
10266 if (h->root.type == bfd_link_hash_warning)
10267 /* When warning symbols are created, they **replace** the "real"
10268 entry in the hash table, thus we never get to see the real
10269 symbol in a hash traversal. So look at it now. */
10270 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10272 info = (struct bfd_link_info *) inf;
10273 htab = elf32_arm_hash_table (info);
10275 if (htab->root.dynamic_sections_created
10276 && h->plt.refcount > 0)
10278 /* Make sure this symbol is output as a dynamic symbol.
10279 Undefined weak syms won't yet be marked as dynamic. */
10280 if (h->dynindx == -1
10281 && !h->forced_local)
10283 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10284 return FALSE;
10287 if (info->shared
10288 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
10290 asection *s = htab->splt;
10292 /* If this is the first .plt entry, make room for the special
10293 first entry. */
10294 if (s->size == 0)
10295 s->size += htab->plt_header_size;
10297 h->plt.offset = s->size;
10299 /* If we will insert a Thumb trampoline before this PLT, leave room
10300 for it. */
10301 thumb_refs = eh->plt_thumb_refcount;
10302 if (!htab->use_blx)
10303 thumb_refs += eh->plt_maybe_thumb_refcount;
10305 if (thumb_refs > 0)
10307 h->plt.offset += PLT_THUMB_STUB_SIZE;
10308 s->size += PLT_THUMB_STUB_SIZE;
10311 /* If this symbol is not defined in a regular file, and we are
10312 not generating a shared library, then set the symbol to this
10313 location in the .plt. This is required to make function
10314 pointers compare as equal between the normal executable and
10315 the shared library. */
10316 if (! info->shared
10317 && !h->def_regular)
10319 h->root.u.def.section = s;
10320 h->root.u.def.value = h->plt.offset;
10322 /* Make sure the function is not marked as Thumb, in case
10323 it is the target of an ABS32 relocation, which will
10324 point to the PLT entry. */
10325 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
10326 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10329 /* Make room for this entry. */
10330 s->size += htab->plt_entry_size;
10332 if (!htab->symbian_p)
10334 /* We also need to make an entry in the .got.plt section, which
10335 will be placed in the .got section by the linker script. */
10336 eh->plt_got_offset = htab->sgotplt->size;
10337 htab->sgotplt->size += 4;
10340 /* We also need to make an entry in the .rel(a).plt section. */
10341 htab->srelplt->size += RELOC_SIZE (htab);
10343 /* VxWorks executables have a second set of relocations for
10344 each PLT entry. They go in a separate relocation section,
10345 which is processed by the kernel loader. */
10346 if (htab->vxworks_p && !info->shared)
10348 /* There is a relocation for the initial PLT entry:
10349 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10350 if (h->plt.offset == htab->plt_header_size)
10351 htab->srelplt2->size += RELOC_SIZE (htab);
10353 /* There are two extra relocations for each subsequent
10354 PLT entry: an R_ARM_32 relocation for the GOT entry,
10355 and an R_ARM_32 relocation for the PLT entry. */
10356 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
10359 else
10361 h->plt.offset = (bfd_vma) -1;
10362 h->needs_plt = 0;
10365 else
10367 h->plt.offset = (bfd_vma) -1;
10368 h->needs_plt = 0;
10371 if (h->got.refcount > 0)
10373 asection *s;
10374 bfd_boolean dyn;
10375 int tls_type = elf32_arm_hash_entry (h)->tls_type;
10376 int indx;
10378 /* Make sure this symbol is output as a dynamic symbol.
10379 Undefined weak syms won't yet be marked as dynamic. */
10380 if (h->dynindx == -1
10381 && !h->forced_local)
10383 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10384 return FALSE;
10387 if (!htab->symbian_p)
10389 s = htab->sgot;
10390 h->got.offset = s->size;
10392 if (tls_type == GOT_UNKNOWN)
10393 abort ();
10395 if (tls_type == GOT_NORMAL)
10396 /* Non-TLS symbols need one GOT slot. */
10397 s->size += 4;
10398 else
10400 if (tls_type & GOT_TLS_GD)
10401 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10402 s->size += 8;
10403 if (tls_type & GOT_TLS_IE)
10404 /* R_ARM_TLS_IE32 needs one GOT slot. */
10405 s->size += 4;
10408 dyn = htab->root.dynamic_sections_created;
10410 indx = 0;
10411 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
10412 && (!info->shared
10413 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10414 indx = h->dynindx;
10416 if (tls_type != GOT_NORMAL
10417 && (info->shared || indx != 0)
10418 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10419 || h->root.type != bfd_link_hash_undefweak))
10421 if (tls_type & GOT_TLS_IE)
10422 htab->srelgot->size += RELOC_SIZE (htab);
10424 if (tls_type & GOT_TLS_GD)
10425 htab->srelgot->size += RELOC_SIZE (htab);
10427 if ((tls_type & GOT_TLS_GD) && indx != 0)
10428 htab->srelgot->size += RELOC_SIZE (htab);
10430 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10431 || h->root.type != bfd_link_hash_undefweak)
10432 && (info->shared
10433 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
10434 htab->srelgot->size += RELOC_SIZE (htab);
10437 else
10438 h->got.offset = (bfd_vma) -1;
10440 /* Allocate stubs for exported Thumb functions on v4t. */
10441 if (!htab->use_blx && h->dynindx != -1
10442 && h->def_regular
10443 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
10444 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
10446 struct elf_link_hash_entry * th;
10447 struct bfd_link_hash_entry * bh;
10448 struct elf_link_hash_entry * myh;
10449 char name[1024];
10450 asection *s;
10451 bh = NULL;
10452 /* Create a new symbol to regist the real location of the function. */
10453 s = h->root.u.def.section;
10454 sprintf (name, "__real_%s", h->root.root.string);
10455 _bfd_generic_link_add_one_symbol (info, s->owner,
10456 name, BSF_GLOBAL, s,
10457 h->root.u.def.value,
10458 NULL, TRUE, FALSE, &bh);
10460 myh = (struct elf_link_hash_entry *) bh;
10461 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
10462 myh->forced_local = 1;
10463 eh->export_glue = myh;
10464 th = record_arm_to_thumb_glue (info, h);
10465 /* Point the symbol at the stub. */
10466 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10467 h->root.u.def.section = th->root.u.def.section;
10468 h->root.u.def.value = th->root.u.def.value & ~1;
10471 if (eh->relocs_copied == NULL)
10472 return TRUE;
10474 /* In the shared -Bsymbolic case, discard space allocated for
10475 dynamic pc-relative relocs against symbols which turn out to be
10476 defined in regular objects. For the normal shared case, discard
10477 space for pc-relative relocs that have become local due to symbol
10478 visibility changes. */
10480 if (info->shared || htab->root.is_relocatable_executable)
10482 /* The only relocs that use pc_count are R_ARM_REL32 and
10483 R_ARM_REL32_NOI, which will appear on something like
10484 ".long foo - .". We want calls to protected symbols to resolve
10485 directly to the function rather than going via the plt. If people
10486 want function pointer comparisons to work as expected then they
10487 should avoid writing assembly like ".long foo - .". */
10488 if (SYMBOL_CALLS_LOCAL (info, h))
10490 struct elf32_arm_relocs_copied **pp;
10492 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10494 p->count -= p->pc_count;
10495 p->pc_count = 0;
10496 if (p->count == 0)
10497 *pp = p->next;
10498 else
10499 pp = &p->next;
10503 if (elf32_arm_hash_table (info)->vxworks_p)
10505 struct elf32_arm_relocs_copied **pp;
10507 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10509 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
10510 *pp = p->next;
10511 else
10512 pp = &p->next;
10516 /* Also discard relocs on undefined weak syms with non-default
10517 visibility. */
10518 if (eh->relocs_copied != NULL
10519 && h->root.type == bfd_link_hash_undefweak)
10521 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
10522 eh->relocs_copied = NULL;
10524 /* Make sure undefined weak symbols are output as a dynamic
10525 symbol in PIEs. */
10526 else if (h->dynindx == -1
10527 && !h->forced_local)
10529 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10530 return FALSE;
10534 else if (htab->root.is_relocatable_executable && h->dynindx == -1
10535 && h->root.type == bfd_link_hash_new)
10537 /* Output absolute symbols so that we can create relocations
10538 against them. For normal symbols we output a relocation
10539 against the section that contains them. */
10540 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10541 return FALSE;
10545 else
10547 /* For the non-shared case, discard space for relocs against
10548 symbols which turn out to need copy relocs or are not
10549 dynamic. */
10551 if (!h->non_got_ref
10552 && ((h->def_dynamic
10553 && !h->def_regular)
10554 || (htab->root.dynamic_sections_created
10555 && (h->root.type == bfd_link_hash_undefweak
10556 || h->root.type == bfd_link_hash_undefined))))
10558 /* Make sure this symbol is output as a dynamic symbol.
10559 Undefined weak syms won't yet be marked as dynamic. */
10560 if (h->dynindx == -1
10561 && !h->forced_local)
10563 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10564 return FALSE;
10567 /* If that succeeded, we know we'll be keeping all the
10568 relocs. */
10569 if (h->dynindx != -1)
10570 goto keep;
10573 eh->relocs_copied = NULL;
10575 keep: ;
10578 /* Finally, allocate space. */
10579 for (p = eh->relocs_copied; p != NULL; p = p->next)
10581 asection *sreloc = elf_section_data (p->section)->sreloc;
10582 sreloc->size += p->count * RELOC_SIZE (htab);
10585 return TRUE;
10588 /* Find any dynamic relocs that apply to read-only sections. */
10590 static bfd_boolean
10591 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
10593 struct elf32_arm_link_hash_entry * eh;
10594 struct elf32_arm_relocs_copied * p;
10596 if (h->root.type == bfd_link_hash_warning)
10597 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10599 eh = (struct elf32_arm_link_hash_entry *) h;
10600 for (p = eh->relocs_copied; p != NULL; p = p->next)
10602 asection *s = p->section;
10604 if (s != NULL && (s->flags & SEC_READONLY) != 0)
10606 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10608 info->flags |= DF_TEXTREL;
10610 /* Not an error, just cut short the traversal. */
10611 return FALSE;
10614 return TRUE;
10617 void
10618 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
10619 int byteswap_code)
10621 struct elf32_arm_link_hash_table *globals;
10623 globals = elf32_arm_hash_table (info);
10624 globals->byteswap_code = byteswap_code;
10627 /* Set the sizes of the dynamic sections. */
10629 static bfd_boolean
10630 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10631 struct bfd_link_info * info)
10633 bfd * dynobj;
10634 asection * s;
10635 bfd_boolean plt;
10636 bfd_boolean relocs;
10637 bfd *ibfd;
10638 struct elf32_arm_link_hash_table *htab;
10640 htab = elf32_arm_hash_table (info);
10641 dynobj = elf_hash_table (info)->dynobj;
10642 BFD_ASSERT (dynobj != NULL);
10643 check_use_blx (htab);
10645 if (elf_hash_table (info)->dynamic_sections_created)
10647 /* Set the contents of the .interp section to the interpreter. */
10648 if (info->executable)
10650 s = bfd_get_section_by_name (dynobj, ".interp");
10651 BFD_ASSERT (s != NULL);
10652 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10653 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10657 /* Set up .got offsets for local syms, and space for local dynamic
10658 relocs. */
10659 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10661 bfd_signed_vma *local_got;
10662 bfd_signed_vma *end_local_got;
10663 char *local_tls_type;
10664 bfd_size_type locsymcount;
10665 Elf_Internal_Shdr *symtab_hdr;
10666 asection *srel;
10667 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
10669 if (! is_arm_elf (ibfd))
10670 continue;
10672 for (s = ibfd->sections; s != NULL; s = s->next)
10674 struct elf32_arm_relocs_copied *p;
10676 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10678 if (!bfd_is_abs_section (p->section)
10679 && bfd_is_abs_section (p->section->output_section))
10681 /* Input section has been discarded, either because
10682 it is a copy of a linkonce section or due to
10683 linker script /DISCARD/, so we'll be discarding
10684 the relocs too. */
10686 else if (is_vxworks
10687 && strcmp (p->section->output_section->name,
10688 ".tls_vars") == 0)
10690 /* Relocations in vxworks .tls_vars sections are
10691 handled specially by the loader. */
10693 else if (p->count != 0)
10695 srel = elf_section_data (p->section)->sreloc;
10696 srel->size += p->count * RELOC_SIZE (htab);
10697 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10698 info->flags |= DF_TEXTREL;
10703 local_got = elf_local_got_refcounts (ibfd);
10704 if (!local_got)
10705 continue;
10707 symtab_hdr = & elf_symtab_hdr (ibfd);
10708 locsymcount = symtab_hdr->sh_info;
10709 end_local_got = local_got + locsymcount;
10710 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
10711 s = htab->sgot;
10712 srel = htab->srelgot;
10713 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10715 if (*local_got > 0)
10717 *local_got = s->size;
10718 if (*local_tls_type & GOT_TLS_GD)
10719 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10720 s->size += 8;
10721 if (*local_tls_type & GOT_TLS_IE)
10722 s->size += 4;
10723 if (*local_tls_type == GOT_NORMAL)
10724 s->size += 4;
10726 if (info->shared || *local_tls_type == GOT_TLS_GD)
10727 srel->size += RELOC_SIZE (htab);
10729 else
10730 *local_got = (bfd_vma) -1;
10734 if (htab->tls_ldm_got.refcount > 0)
10736 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10737 for R_ARM_TLS_LDM32 relocations. */
10738 htab->tls_ldm_got.offset = htab->sgot->size;
10739 htab->sgot->size += 8;
10740 if (info->shared)
10741 htab->srelgot->size += RELOC_SIZE (htab);
10743 else
10744 htab->tls_ldm_got.offset = -1;
10746 /* Allocate global sym .plt and .got entries, and space for global
10747 sym dynamic relocs. */
10748 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
10750 /* Here we rummage through the found bfds to collect glue information. */
10751 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10753 if (! is_arm_elf (ibfd))
10754 continue;
10756 /* Initialise mapping tables for code/data. */
10757 bfd_elf32_arm_init_maps (ibfd);
10759 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10760 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10761 /* xgettext:c-format */
10762 _bfd_error_handler (_("Errors encountered processing file %s"),
10763 ibfd->filename);
10766 /* The check_relocs and adjust_dynamic_symbol entry points have
10767 determined the sizes of the various dynamic sections. Allocate
10768 memory for them. */
10769 plt = FALSE;
10770 relocs = FALSE;
10771 for (s = dynobj->sections; s != NULL; s = s->next)
10773 const char * name;
10775 if ((s->flags & SEC_LINKER_CREATED) == 0)
10776 continue;
10778 /* It's OK to base decisions on the section name, because none
10779 of the dynobj section names depend upon the input files. */
10780 name = bfd_get_section_name (dynobj, s);
10782 if (strcmp (name, ".plt") == 0)
10784 /* Remember whether there is a PLT. */
10785 plt = s->size != 0;
10787 else if (CONST_STRNEQ (name, ".rel"))
10789 if (s->size != 0)
10791 /* Remember whether there are any reloc sections other
10792 than .rel(a).plt and .rela.plt.unloaded. */
10793 if (s != htab->srelplt && s != htab->srelplt2)
10794 relocs = TRUE;
10796 /* We use the reloc_count field as a counter if we need
10797 to copy relocs into the output file. */
10798 s->reloc_count = 0;
10801 else if (! CONST_STRNEQ (name, ".got")
10802 && strcmp (name, ".dynbss") != 0)
10804 /* It's not one of our sections, so don't allocate space. */
10805 continue;
10808 if (s->size == 0)
10810 /* If we don't need this section, strip it from the
10811 output file. This is mostly to handle .rel(a).bss and
10812 .rel(a).plt. We must create both sections in
10813 create_dynamic_sections, because they must be created
10814 before the linker maps input sections to output
10815 sections. The linker does that before
10816 adjust_dynamic_symbol is called, and it is that
10817 function which decides whether anything needs to go
10818 into these sections. */
10819 s->flags |= SEC_EXCLUDE;
10820 continue;
10823 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10824 continue;
10826 /* Allocate memory for the section contents. */
10827 s->contents = bfd_zalloc (dynobj, s->size);
10828 if (s->contents == NULL)
10829 return FALSE;
10832 if (elf_hash_table (info)->dynamic_sections_created)
10834 /* Add some entries to the .dynamic section. We fill in the
10835 values later, in elf32_arm_finish_dynamic_sections, but we
10836 must add the entries now so that we get the correct size for
10837 the .dynamic section. The DT_DEBUG entry is filled in by the
10838 dynamic linker and used by the debugger. */
10839 #define add_dynamic_entry(TAG, VAL) \
10840 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10842 if (info->executable)
10844 if (!add_dynamic_entry (DT_DEBUG, 0))
10845 return FALSE;
10848 if (plt)
10850 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10851 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10852 || !add_dynamic_entry (DT_PLTREL,
10853 htab->use_rel ? DT_REL : DT_RELA)
10854 || !add_dynamic_entry (DT_JMPREL, 0))
10855 return FALSE;
10858 if (relocs)
10860 if (htab->use_rel)
10862 if (!add_dynamic_entry (DT_REL, 0)
10863 || !add_dynamic_entry (DT_RELSZ, 0)
10864 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10865 return FALSE;
10867 else
10869 if (!add_dynamic_entry (DT_RELA, 0)
10870 || !add_dynamic_entry (DT_RELASZ, 0)
10871 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10872 return FALSE;
10876 /* If any dynamic relocs apply to a read-only section,
10877 then we need a DT_TEXTREL entry. */
10878 if ((info->flags & DF_TEXTREL) == 0)
10879 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
10880 info);
10882 if ((info->flags & DF_TEXTREL) != 0)
10884 if (!add_dynamic_entry (DT_TEXTREL, 0))
10885 return FALSE;
10887 if (htab->vxworks_p
10888 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10889 return FALSE;
10891 #undef add_dynamic_entry
10893 return TRUE;
10896 /* Finish up dynamic symbol handling. We set the contents of various
10897 dynamic sections here. */
10899 static bfd_boolean
10900 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10901 struct bfd_link_info * info,
10902 struct elf_link_hash_entry * h,
10903 Elf_Internal_Sym * sym)
10905 bfd * dynobj;
10906 struct elf32_arm_link_hash_table *htab;
10907 struct elf32_arm_link_hash_entry *eh;
10909 dynobj = elf_hash_table (info)->dynobj;
10910 htab = elf32_arm_hash_table (info);
10911 eh = (struct elf32_arm_link_hash_entry *) h;
10913 if (h->plt.offset != (bfd_vma) -1)
10915 asection * splt;
10916 asection * srel;
10917 bfd_byte *loc;
10918 bfd_vma plt_index;
10919 Elf_Internal_Rela rel;
10921 /* This symbol has an entry in the procedure linkage table. Set
10922 it up. */
10924 BFD_ASSERT (h->dynindx != -1);
10926 splt = bfd_get_section_by_name (dynobj, ".plt");
10927 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
10928 BFD_ASSERT (splt != NULL && srel != NULL);
10930 /* Fill in the entry in the procedure linkage table. */
10931 if (htab->symbian_p)
10933 put_arm_insn (htab, output_bfd,
10934 elf32_arm_symbian_plt_entry[0],
10935 splt->contents + h->plt.offset);
10936 bfd_put_32 (output_bfd,
10937 elf32_arm_symbian_plt_entry[1],
10938 splt->contents + h->plt.offset + 4);
10940 /* Fill in the entry in the .rel.plt section. */
10941 rel.r_offset = (splt->output_section->vma
10942 + splt->output_offset
10943 + h->plt.offset + 4);
10944 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10946 /* Get the index in the procedure linkage table which
10947 corresponds to this symbol. This is the index of this symbol
10948 in all the symbols for which we are making plt entries. The
10949 first entry in the procedure linkage table is reserved. */
10950 plt_index = ((h->plt.offset - htab->plt_header_size)
10951 / htab->plt_entry_size);
10953 else
10955 bfd_vma got_offset, got_address, plt_address;
10956 bfd_vma got_displacement;
10957 asection * sgot;
10958 bfd_byte * ptr;
10960 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10961 BFD_ASSERT (sgot != NULL);
10963 /* Get the offset into the .got.plt table of the entry that
10964 corresponds to this function. */
10965 got_offset = eh->plt_got_offset;
10967 /* Get the index in the procedure linkage table which
10968 corresponds to this symbol. This is the index of this symbol
10969 in all the symbols for which we are making plt entries. The
10970 first three entries in .got.plt are reserved; after that
10971 symbols appear in the same order as in .plt. */
10972 plt_index = (got_offset - 12) / 4;
10974 /* Calculate the address of the GOT entry. */
10975 got_address = (sgot->output_section->vma
10976 + sgot->output_offset
10977 + got_offset);
10979 /* ...and the address of the PLT entry. */
10980 plt_address = (splt->output_section->vma
10981 + splt->output_offset
10982 + h->plt.offset);
10984 ptr = htab->splt->contents + h->plt.offset;
10985 if (htab->vxworks_p && info->shared)
10987 unsigned int i;
10988 bfd_vma val;
10990 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
10992 val = elf32_arm_vxworks_shared_plt_entry[i];
10993 if (i == 2)
10994 val |= got_address - sgot->output_section->vma;
10995 if (i == 5)
10996 val |= plt_index * RELOC_SIZE (htab);
10997 if (i == 2 || i == 5)
10998 bfd_put_32 (output_bfd, val, ptr);
10999 else
11000 put_arm_insn (htab, output_bfd, val, ptr);
11003 else if (htab->vxworks_p)
11005 unsigned int i;
11006 bfd_vma val;
11008 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
11010 val = elf32_arm_vxworks_exec_plt_entry[i];
11011 if (i == 2)
11012 val |= got_address;
11013 if (i == 4)
11014 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
11015 if (i == 5)
11016 val |= plt_index * RELOC_SIZE (htab);
11017 if (i == 2 || i == 5)
11018 bfd_put_32 (output_bfd, val, ptr);
11019 else
11020 put_arm_insn (htab, output_bfd, val, ptr);
11023 loc = (htab->srelplt2->contents
11024 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
11026 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
11027 referencing the GOT for this PLT entry. */
11028 rel.r_offset = plt_address + 8;
11029 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11030 rel.r_addend = got_offset;
11031 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11032 loc += RELOC_SIZE (htab);
11034 /* Create the R_ARM_ABS32 relocation referencing the
11035 beginning of the PLT for this GOT entry. */
11036 rel.r_offset = got_address;
11037 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11038 rel.r_addend = 0;
11039 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11041 else
11043 bfd_signed_vma thumb_refs;
11044 /* Calculate the displacement between the PLT slot and the
11045 entry in the GOT. The eight-byte offset accounts for the
11046 value produced by adding to pc in the first instruction
11047 of the PLT stub. */
11048 got_displacement = got_address - (plt_address + 8);
11050 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
11052 thumb_refs = eh->plt_thumb_refcount;
11053 if (!htab->use_blx)
11054 thumb_refs += eh->plt_maybe_thumb_refcount;
11056 if (thumb_refs > 0)
11058 put_thumb_insn (htab, output_bfd,
11059 elf32_arm_plt_thumb_stub[0], ptr - 4);
11060 put_thumb_insn (htab, output_bfd,
11061 elf32_arm_plt_thumb_stub[1], ptr - 2);
11064 put_arm_insn (htab, output_bfd,
11065 elf32_arm_plt_entry[0]
11066 | ((got_displacement & 0x0ff00000) >> 20),
11067 ptr + 0);
11068 put_arm_insn (htab, output_bfd,
11069 elf32_arm_plt_entry[1]
11070 | ((got_displacement & 0x000ff000) >> 12),
11071 ptr+ 4);
11072 put_arm_insn (htab, output_bfd,
11073 elf32_arm_plt_entry[2]
11074 | (got_displacement & 0x00000fff),
11075 ptr + 8);
11076 #ifdef FOUR_WORD_PLT
11077 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
11078 #endif
11081 /* Fill in the entry in the global offset table. */
11082 bfd_put_32 (output_bfd,
11083 (splt->output_section->vma
11084 + splt->output_offset),
11085 sgot->contents + got_offset);
11087 /* Fill in the entry in the .rel(a).plt section. */
11088 rel.r_addend = 0;
11089 rel.r_offset = got_address;
11090 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
11093 loc = srel->contents + plt_index * RELOC_SIZE (htab);
11094 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11096 if (!h->def_regular)
11098 /* Mark the symbol as undefined, rather than as defined in
11099 the .plt section. Leave the value alone. */
11100 sym->st_shndx = SHN_UNDEF;
11101 /* If the symbol is weak, we do need to clear the value.
11102 Otherwise, the PLT entry would provide a definition for
11103 the symbol even if the symbol wasn't defined anywhere,
11104 and so the symbol would never be NULL. */
11105 if (!h->ref_regular_nonweak)
11106 sym->st_value = 0;
11110 if (h->got.offset != (bfd_vma) -1
11111 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
11112 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
11114 asection * sgot;
11115 asection * srel;
11116 Elf_Internal_Rela rel;
11117 bfd_byte *loc;
11118 bfd_vma offset;
11120 /* This symbol has an entry in the global offset table. Set it
11121 up. */
11122 sgot = bfd_get_section_by_name (dynobj, ".got");
11123 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
11124 BFD_ASSERT (sgot != NULL && srel != NULL);
11126 offset = (h->got.offset & ~(bfd_vma) 1);
11127 rel.r_addend = 0;
11128 rel.r_offset = (sgot->output_section->vma
11129 + sgot->output_offset
11130 + offset);
11132 /* If this is a static link, or it is a -Bsymbolic link and the
11133 symbol is defined locally or was forced to be local because
11134 of a version file, we just want to emit a RELATIVE reloc.
11135 The entry in the global offset table will already have been
11136 initialized in the relocate_section function. */
11137 if (info->shared
11138 && SYMBOL_REFERENCES_LOCAL (info, h))
11140 BFD_ASSERT ((h->got.offset & 1) != 0);
11141 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
11142 if (!htab->use_rel)
11144 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
11145 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11148 else
11150 BFD_ASSERT ((h->got.offset & 1) == 0);
11151 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11152 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11155 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
11156 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11159 if (h->needs_copy)
11161 asection * s;
11162 Elf_Internal_Rela rel;
11163 bfd_byte *loc;
11165 /* This symbol needs a copy reloc. Set it up. */
11166 BFD_ASSERT (h->dynindx != -1
11167 && (h->root.type == bfd_link_hash_defined
11168 || h->root.type == bfd_link_hash_defweak));
11170 s = bfd_get_section_by_name (h->root.u.def.section->owner,
11171 RELOC_SECTION (htab, ".bss"));
11172 BFD_ASSERT (s != NULL);
11174 rel.r_addend = 0;
11175 rel.r_offset = (h->root.u.def.value
11176 + h->root.u.def.section->output_section->vma
11177 + h->root.u.def.section->output_offset);
11178 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
11179 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
11180 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11183 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11184 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11185 to the ".got" section. */
11186 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
11187 || (!htab->vxworks_p && h == htab->root.hgot))
11188 sym->st_shndx = SHN_ABS;
11190 return TRUE;
11193 /* Finish up the dynamic sections. */
11195 static bfd_boolean
11196 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
11198 bfd * dynobj;
11199 asection * sgot;
11200 asection * sdyn;
11202 dynobj = elf_hash_table (info)->dynobj;
11204 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
11205 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
11206 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11208 if (elf_hash_table (info)->dynamic_sections_created)
11210 asection *splt;
11211 Elf32_External_Dyn *dyncon, *dynconend;
11212 struct elf32_arm_link_hash_table *htab;
11214 htab = elf32_arm_hash_table (info);
11215 splt = bfd_get_section_by_name (dynobj, ".plt");
11216 BFD_ASSERT (splt != NULL && sdyn != NULL);
11218 dyncon = (Elf32_External_Dyn *) sdyn->contents;
11219 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
11221 for (; dyncon < dynconend; dyncon++)
11223 Elf_Internal_Dyn dyn;
11224 const char * name;
11225 asection * s;
11227 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
11229 switch (dyn.d_tag)
11231 unsigned int type;
11233 default:
11234 if (htab->vxworks_p
11235 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
11236 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11237 break;
11239 case DT_HASH:
11240 name = ".hash";
11241 goto get_vma_if_bpabi;
11242 case DT_STRTAB:
11243 name = ".dynstr";
11244 goto get_vma_if_bpabi;
11245 case DT_SYMTAB:
11246 name = ".dynsym";
11247 goto get_vma_if_bpabi;
11248 case DT_VERSYM:
11249 name = ".gnu.version";
11250 goto get_vma_if_bpabi;
11251 case DT_VERDEF:
11252 name = ".gnu.version_d";
11253 goto get_vma_if_bpabi;
11254 case DT_VERNEED:
11255 name = ".gnu.version_r";
11256 goto get_vma_if_bpabi;
11258 case DT_PLTGOT:
11259 name = ".got";
11260 goto get_vma;
11261 case DT_JMPREL:
11262 name = RELOC_SECTION (htab, ".plt");
11263 get_vma:
11264 s = bfd_get_section_by_name (output_bfd, name);
11265 BFD_ASSERT (s != NULL);
11266 if (!htab->symbian_p)
11267 dyn.d_un.d_ptr = s->vma;
11268 else
11269 /* In the BPABI, tags in the PT_DYNAMIC section point
11270 at the file offset, not the memory address, for the
11271 convenience of the post linker. */
11272 dyn.d_un.d_ptr = s->filepos;
11273 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11274 break;
11276 get_vma_if_bpabi:
11277 if (htab->symbian_p)
11278 goto get_vma;
11279 break;
11281 case DT_PLTRELSZ:
11282 s = bfd_get_section_by_name (output_bfd,
11283 RELOC_SECTION (htab, ".plt"));
11284 BFD_ASSERT (s != NULL);
11285 dyn.d_un.d_val = s->size;
11286 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11287 break;
11289 case DT_RELSZ:
11290 case DT_RELASZ:
11291 if (!htab->symbian_p)
11293 /* My reading of the SVR4 ABI indicates that the
11294 procedure linkage table relocs (DT_JMPREL) should be
11295 included in the overall relocs (DT_REL). This is
11296 what Solaris does. However, UnixWare can not handle
11297 that case. Therefore, we override the DT_RELSZ entry
11298 here to make it not include the JMPREL relocs. Since
11299 the linker script arranges for .rel(a).plt to follow all
11300 other relocation sections, we don't have to worry
11301 about changing the DT_REL entry. */
11302 s = bfd_get_section_by_name (output_bfd,
11303 RELOC_SECTION (htab, ".plt"));
11304 if (s != NULL)
11305 dyn.d_un.d_val -= s->size;
11306 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11307 break;
11309 /* Fall through. */
11311 case DT_REL:
11312 case DT_RELA:
11313 /* In the BPABI, the DT_REL tag must point at the file
11314 offset, not the VMA, of the first relocation
11315 section. So, we use code similar to that in
11316 elflink.c, but do not check for SHF_ALLOC on the
11317 relcoation section, since relocations sections are
11318 never allocated under the BPABI. The comments above
11319 about Unixware notwithstanding, we include all of the
11320 relocations here. */
11321 if (htab->symbian_p)
11323 unsigned int i;
11324 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
11325 ? SHT_REL : SHT_RELA);
11326 dyn.d_un.d_val = 0;
11327 for (i = 1; i < elf_numsections (output_bfd); i++)
11329 Elf_Internal_Shdr *hdr
11330 = elf_elfsections (output_bfd)[i];
11331 if (hdr->sh_type == type)
11333 if (dyn.d_tag == DT_RELSZ
11334 || dyn.d_tag == DT_RELASZ)
11335 dyn.d_un.d_val += hdr->sh_size;
11336 else if ((ufile_ptr) hdr->sh_offset
11337 <= dyn.d_un.d_val - 1)
11338 dyn.d_un.d_val = hdr->sh_offset;
11341 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11343 break;
11345 /* Set the bottom bit of DT_INIT/FINI if the
11346 corresponding function is Thumb. */
11347 case DT_INIT:
11348 name = info->init_function;
11349 goto get_sym;
11350 case DT_FINI:
11351 name = info->fini_function;
11352 get_sym:
11353 /* If it wasn't set by elf_bfd_final_link
11354 then there is nothing to adjust. */
11355 if (dyn.d_un.d_val != 0)
11357 struct elf_link_hash_entry * eh;
11359 eh = elf_link_hash_lookup (elf_hash_table (info), name,
11360 FALSE, FALSE, TRUE);
11361 if (eh != NULL
11362 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
11364 dyn.d_un.d_val |= 1;
11365 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11368 break;
11372 /* Fill in the first entry in the procedure linkage table. */
11373 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
11375 const bfd_vma *plt0_entry;
11376 bfd_vma got_address, plt_address, got_displacement;
11378 /* Calculate the addresses of the GOT and PLT. */
11379 got_address = sgot->output_section->vma + sgot->output_offset;
11380 plt_address = splt->output_section->vma + splt->output_offset;
11382 if (htab->vxworks_p)
11384 /* The VxWorks GOT is relocated by the dynamic linker.
11385 Therefore, we must emit relocations rather than simply
11386 computing the values now. */
11387 Elf_Internal_Rela rel;
11389 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
11390 put_arm_insn (htab, output_bfd, plt0_entry[0],
11391 splt->contents + 0);
11392 put_arm_insn (htab, output_bfd, plt0_entry[1],
11393 splt->contents + 4);
11394 put_arm_insn (htab, output_bfd, plt0_entry[2],
11395 splt->contents + 8);
11396 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
11398 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
11399 rel.r_offset = plt_address + 12;
11400 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11401 rel.r_addend = 0;
11402 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
11403 htab->srelplt2->contents);
11405 else
11407 got_displacement = got_address - (plt_address + 16);
11409 plt0_entry = elf32_arm_plt0_entry;
11410 put_arm_insn (htab, output_bfd, plt0_entry[0],
11411 splt->contents + 0);
11412 put_arm_insn (htab, output_bfd, plt0_entry[1],
11413 splt->contents + 4);
11414 put_arm_insn (htab, output_bfd, plt0_entry[2],
11415 splt->contents + 8);
11416 put_arm_insn (htab, output_bfd, plt0_entry[3],
11417 splt->contents + 12);
11419 #ifdef FOUR_WORD_PLT
11420 /* The displacement value goes in the otherwise-unused
11421 last word of the second entry. */
11422 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
11423 #else
11424 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
11425 #endif
11429 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11430 really seem like the right value. */
11431 if (splt->output_section->owner == output_bfd)
11432 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
11434 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
11436 /* Correct the .rel(a).plt.unloaded relocations. They will have
11437 incorrect symbol indexes. */
11438 int num_plts;
11439 unsigned char *p;
11441 num_plts = ((htab->splt->size - htab->plt_header_size)
11442 / htab->plt_entry_size);
11443 p = htab->srelplt2->contents + RELOC_SIZE (htab);
11445 for (; num_plts; num_plts--)
11447 Elf_Internal_Rela rel;
11449 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11450 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11451 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11452 p += RELOC_SIZE (htab);
11454 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11455 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11456 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11457 p += RELOC_SIZE (htab);
11462 /* Fill in the first three entries in the global offset table. */
11463 if (sgot)
11465 if (sgot->size > 0)
11467 if (sdyn == NULL)
11468 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
11469 else
11470 bfd_put_32 (output_bfd,
11471 sdyn->output_section->vma + sdyn->output_offset,
11472 sgot->contents);
11473 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
11474 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
11477 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
11480 return TRUE;
11483 static void
11484 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
11486 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
11487 struct elf32_arm_link_hash_table *globals;
11489 i_ehdrp = elf_elfheader (abfd);
11491 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
11492 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
11493 else
11494 i_ehdrp->e_ident[EI_OSABI] = 0;
11495 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
11497 if (link_info)
11499 globals = elf32_arm_hash_table (link_info);
11500 if (globals->byteswap_code)
11501 i_ehdrp->e_flags |= EF_ARM_BE8;
11505 static enum elf_reloc_type_class
11506 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
11508 switch ((int) ELF32_R_TYPE (rela->r_info))
11510 case R_ARM_RELATIVE:
11511 return reloc_class_relative;
11512 case R_ARM_JUMP_SLOT:
11513 return reloc_class_plt;
11514 case R_ARM_COPY:
11515 return reloc_class_copy;
11516 default:
11517 return reloc_class_normal;
11521 /* Set the right machine number for an Arm ELF file. */
11523 static bfd_boolean
11524 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
11526 if (hdr->sh_type == SHT_NOTE)
11527 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
11529 return TRUE;
11532 static void
11533 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
11535 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
11538 /* Return TRUE if this is an unwinding table entry. */
11540 static bfd_boolean
11541 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
11543 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
11544 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
11548 /* Set the type and flags for an ARM section. We do this by
11549 the section name, which is a hack, but ought to work. */
11551 static bfd_boolean
11552 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
11554 const char * name;
11556 name = bfd_get_section_name (abfd, sec);
11558 if (is_arm_elf_unwind_section_name (abfd, name))
11560 hdr->sh_type = SHT_ARM_EXIDX;
11561 hdr->sh_flags |= SHF_LINK_ORDER;
11563 return TRUE;
11566 /* Handle an ARM specific section when reading an object file. This is
11567 called when bfd_section_from_shdr finds a section with an unknown
11568 type. */
11570 static bfd_boolean
11571 elf32_arm_section_from_shdr (bfd *abfd,
11572 Elf_Internal_Shdr * hdr,
11573 const char *name,
11574 int shindex)
11576 /* There ought to be a place to keep ELF backend specific flags, but
11577 at the moment there isn't one. We just keep track of the
11578 sections by their name, instead. Fortunately, the ABI gives
11579 names for all the ARM specific sections, so we will probably get
11580 away with this. */
11581 switch (hdr->sh_type)
11583 case SHT_ARM_EXIDX:
11584 case SHT_ARM_PREEMPTMAP:
11585 case SHT_ARM_ATTRIBUTES:
11586 break;
11588 default:
11589 return FALSE;
11592 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
11593 return FALSE;
11595 return TRUE;
11598 /* A structure used to record a list of sections, independently
11599 of the next and prev fields in the asection structure. */
11600 typedef struct section_list
11602 asection * sec;
11603 struct section_list * next;
11604 struct section_list * prev;
11606 section_list;
11608 /* Unfortunately we need to keep a list of sections for which
11609 an _arm_elf_section_data structure has been allocated. This
11610 is because it is possible for functions like elf32_arm_write_section
11611 to be called on a section which has had an elf_data_structure
11612 allocated for it (and so the used_by_bfd field is valid) but
11613 for which the ARM extended version of this structure - the
11614 _arm_elf_section_data structure - has not been allocated. */
11615 static section_list * sections_with_arm_elf_section_data = NULL;
11617 static void
11618 record_section_with_arm_elf_section_data (asection * sec)
11620 struct section_list * entry;
11622 entry = bfd_malloc (sizeof (* entry));
11623 if (entry == NULL)
11624 return;
11625 entry->sec = sec;
11626 entry->next = sections_with_arm_elf_section_data;
11627 entry->prev = NULL;
11628 if (entry->next != NULL)
11629 entry->next->prev = entry;
11630 sections_with_arm_elf_section_data = entry;
11633 static struct section_list *
11634 find_arm_elf_section_entry (asection * sec)
11636 struct section_list * entry;
11637 static struct section_list * last_entry = NULL;
11639 /* This is a short cut for the typical case where the sections are added
11640 to the sections_with_arm_elf_section_data list in forward order and
11641 then looked up here in backwards order. This makes a real difference
11642 to the ld-srec/sec64k.exp linker test. */
11643 entry = sections_with_arm_elf_section_data;
11644 if (last_entry != NULL)
11646 if (last_entry->sec == sec)
11647 entry = last_entry;
11648 else if (last_entry->next != NULL
11649 && last_entry->next->sec == sec)
11650 entry = last_entry->next;
11653 for (; entry; entry = entry->next)
11654 if (entry->sec == sec)
11655 break;
11657 if (entry)
11658 /* Record the entry prior to this one - it is the entry we are most
11659 likely to want to locate next time. Also this way if we have been
11660 called from unrecord_section_with_arm_elf_section_data() we will not
11661 be caching a pointer that is about to be freed. */
11662 last_entry = entry->prev;
11664 return entry;
11667 static _arm_elf_section_data *
11668 get_arm_elf_section_data (asection * sec)
11670 struct section_list * entry;
11672 entry = find_arm_elf_section_entry (sec);
11674 if (entry)
11675 return elf32_arm_section_data (entry->sec);
11676 else
11677 return NULL;
11680 static void
11681 unrecord_section_with_arm_elf_section_data (asection * sec)
11683 struct section_list * entry;
11685 entry = find_arm_elf_section_entry (sec);
11687 if (entry)
11689 if (entry->prev != NULL)
11690 entry->prev->next = entry->next;
11691 if (entry->next != NULL)
11692 entry->next->prev = entry->prev;
11693 if (entry == sections_with_arm_elf_section_data)
11694 sections_with_arm_elf_section_data = entry->next;
11695 free (entry);
11700 typedef struct
11702 void *finfo;
11703 struct bfd_link_info *info;
11704 asection *sec;
11705 int sec_shndx;
11706 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11707 asection *, struct elf_link_hash_entry *);
11708 } output_arch_syminfo;
11710 enum map_symbol_type
11712 ARM_MAP_ARM,
11713 ARM_MAP_THUMB,
11714 ARM_MAP_DATA
11718 /* Output a single mapping symbol. */
11720 static bfd_boolean
11721 elf32_arm_output_map_sym (output_arch_syminfo *osi,
11722 enum map_symbol_type type,
11723 bfd_vma offset)
11725 static const char *names[3] = {"$a", "$t", "$d"};
11726 struct elf32_arm_link_hash_table *htab;
11727 Elf_Internal_Sym sym;
11729 htab = elf32_arm_hash_table (osi->info);
11730 sym.st_value = osi->sec->output_section->vma
11731 + osi->sec->output_offset
11732 + offset;
11733 sym.st_size = 0;
11734 sym.st_other = 0;
11735 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
11736 sym.st_shndx = osi->sec_shndx;
11737 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
11738 return FALSE;
11739 return TRUE;
11743 /* Output mapping symbols for PLT entries associated with H. */
11745 static bfd_boolean
11746 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11748 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11749 struct elf32_arm_link_hash_table *htab;
11750 struct elf32_arm_link_hash_entry *eh;
11751 bfd_vma addr;
11753 htab = elf32_arm_hash_table (osi->info);
11755 if (h->root.type == bfd_link_hash_indirect)
11756 return TRUE;
11758 if (h->root.type == bfd_link_hash_warning)
11759 /* When warning symbols are created, they **replace** the "real"
11760 entry in the hash table, thus we never get to see the real
11761 symbol in a hash traversal. So look at it now. */
11762 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11764 if (h->plt.offset == (bfd_vma) -1)
11765 return TRUE;
11767 eh = (struct elf32_arm_link_hash_entry *) h;
11768 addr = h->plt.offset;
11769 if (htab->symbian_p)
11771 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11772 return FALSE;
11773 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11774 return FALSE;
11776 else if (htab->vxworks_p)
11778 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11779 return FALSE;
11780 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11781 return FALSE;
11782 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
11783 return FALSE;
11784 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
11785 return FALSE;
11787 else
11789 bfd_signed_vma thumb_refs;
11791 thumb_refs = eh->plt_thumb_refcount;
11792 if (!htab->use_blx)
11793 thumb_refs += eh->plt_maybe_thumb_refcount;
11795 if (thumb_refs > 0)
11797 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
11798 return FALSE;
11800 #ifdef FOUR_WORD_PLT
11801 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11802 return FALSE;
11803 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11804 return FALSE;
11805 #else
11806 /* A three-word PLT with no Thumb thunk contains only Arm code,
11807 so only need to output a mapping symbol for the first PLT entry and
11808 entries with thumb thunks. */
11809 if (thumb_refs > 0 || addr == 20)
11811 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11812 return FALSE;
11814 #endif
11817 return TRUE;
11820 /* Output a single local symbol for a generated stub. */
11822 static bfd_boolean
11823 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11824 bfd_vma offset, bfd_vma size)
11826 struct elf32_arm_link_hash_table *htab;
11827 Elf_Internal_Sym sym;
11829 htab = elf32_arm_hash_table (osi->info);
11830 sym.st_value = osi->sec->output_section->vma
11831 + osi->sec->output_offset
11832 + offset;
11833 sym.st_size = size;
11834 sym.st_other = 0;
11835 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11836 sym.st_shndx = osi->sec_shndx;
11837 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11838 return FALSE;
11839 return TRUE;
11842 static bfd_boolean
11843 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
11844 void * in_arg)
11846 struct elf32_arm_stub_hash_entry *stub_entry;
11847 struct bfd_link_info *info;
11848 struct elf32_arm_link_hash_table *htab;
11849 asection *stub_sec;
11850 bfd_vma addr;
11851 char *stub_name;
11852 output_arch_syminfo *osi;
11853 const insn_sequence *template;
11854 enum stub_insn_type prev_type;
11855 int size;
11856 int i;
11857 enum map_symbol_type sym_type;
11859 /* Massage our args to the form they really have. */
11860 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11861 osi = (output_arch_syminfo *) in_arg;
11863 info = osi->info;
11865 htab = elf32_arm_hash_table (info);
11866 stub_sec = stub_entry->stub_sec;
11868 /* Ensure this stub is attached to the current section being
11869 processed. */
11870 if (stub_sec != osi->sec)
11871 return TRUE;
11873 addr = (bfd_vma) stub_entry->stub_offset;
11874 stub_name = stub_entry->output_name;
11876 template = stub_entry->stub_template;
11877 switch (template[0].type)
11879 case ARM_TYPE:
11880 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
11881 return FALSE;
11882 break;
11883 case THUMB16_TYPE:
11884 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
11885 stub_entry->stub_size))
11886 return FALSE;
11887 break;
11888 default:
11889 BFD_FAIL ();
11890 return FALSE;
11893 prev_type = DATA_TYPE;
11894 size = 0;
11895 for (i = 0; i < stub_entry->stub_template_size; i++)
11897 switch (template[i].type)
11899 case ARM_TYPE:
11900 sym_type = ARM_MAP_ARM;
11901 break;
11903 case THUMB16_TYPE:
11904 sym_type = ARM_MAP_THUMB;
11905 break;
11907 case DATA_TYPE:
11908 sym_type = ARM_MAP_DATA;
11909 break;
11911 default:
11912 BFD_FAIL ();
11913 return FALSE;
11916 if (template[i].type != prev_type)
11918 prev_type = template[i].type;
11919 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
11920 return FALSE;
11923 switch (template[i].type)
11925 case ARM_TYPE:
11926 size += 4;
11927 break;
11929 case THUMB16_TYPE:
11930 size += 2;
11931 break;
11933 case DATA_TYPE:
11934 size += 4;
11935 break;
11937 default:
11938 BFD_FAIL ();
11939 return FALSE;
11943 return TRUE;
11946 /* Output mapping symbols for linker generated sections. */
11948 static bfd_boolean
11949 elf32_arm_output_arch_local_syms (bfd *output_bfd,
11950 struct bfd_link_info *info,
11951 void *finfo,
11952 bfd_boolean (*func) (void *, const char *,
11953 Elf_Internal_Sym *,
11954 asection *,
11955 struct elf_link_hash_entry *))
11957 output_arch_syminfo osi;
11958 struct elf32_arm_link_hash_table *htab;
11959 bfd_vma offset;
11960 bfd_size_type size;
11962 htab = elf32_arm_hash_table (info);
11963 check_use_blx (htab);
11965 osi.finfo = finfo;
11966 osi.info = info;
11967 osi.func = func;
11969 /* ARM->Thumb glue. */
11970 if (htab->arm_glue_size > 0)
11972 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11973 ARM2THUMB_GLUE_SECTION_NAME);
11975 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11976 (output_bfd, osi.sec->output_section);
11977 if (info->shared || htab->root.is_relocatable_executable
11978 || htab->pic_veneer)
11979 size = ARM2THUMB_PIC_GLUE_SIZE;
11980 else if (htab->use_blx)
11981 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
11982 else
11983 size = ARM2THUMB_STATIC_GLUE_SIZE;
11985 for (offset = 0; offset < htab->arm_glue_size; offset += size)
11987 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
11988 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
11992 /* Thumb->ARM glue. */
11993 if (htab->thumb_glue_size > 0)
11995 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11996 THUMB2ARM_GLUE_SECTION_NAME);
11998 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11999 (output_bfd, osi.sec->output_section);
12000 size = THUMB2ARM_GLUE_SIZE;
12002 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
12004 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
12005 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
12009 /* ARMv4 BX veneers. */
12010 if (htab->bx_glue_size > 0)
12012 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12013 ARM_BX_GLUE_SECTION_NAME);
12015 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12016 (output_bfd, osi.sec->output_section);
12018 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
12021 /* Long calls stubs. */
12022 if (htab->stub_bfd && htab->stub_bfd->sections)
12024 asection* stub_sec;
12026 for (stub_sec = htab->stub_bfd->sections;
12027 stub_sec != NULL;
12028 stub_sec = stub_sec->next)
12030 /* Ignore non-stub sections. */
12031 if (!strstr (stub_sec->name, STUB_SUFFIX))
12032 continue;
12034 osi.sec = stub_sec;
12036 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12037 (output_bfd, osi.sec->output_section);
12039 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
12043 /* Finally, output mapping symbols for the PLT. */
12044 if (!htab->splt || htab->splt->size == 0)
12045 return TRUE;
12047 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
12048 htab->splt->output_section);
12049 osi.sec = htab->splt;
12050 /* Output mapping symbols for the plt header. SymbianOS does not have a
12051 plt header. */
12052 if (htab->vxworks_p)
12054 /* VxWorks shared libraries have no PLT header. */
12055 if (!info->shared)
12057 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12058 return FALSE;
12059 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
12060 return FALSE;
12063 else if (!htab->symbian_p)
12065 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12066 return FALSE;
12067 #ifndef FOUR_WORD_PLT
12068 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
12069 return FALSE;
12070 #endif
12073 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
12074 return TRUE;
12077 /* Allocate target specific section data. */
12079 static bfd_boolean
12080 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
12082 if (!sec->used_by_bfd)
12084 _arm_elf_section_data *sdata;
12085 bfd_size_type amt = sizeof (*sdata);
12087 sdata = bfd_zalloc (abfd, amt);
12088 if (sdata == NULL)
12089 return FALSE;
12090 sec->used_by_bfd = sdata;
12093 record_section_with_arm_elf_section_data (sec);
12095 return _bfd_elf_new_section_hook (abfd, sec);
12099 /* Used to order a list of mapping symbols by address. */
12101 static int
12102 elf32_arm_compare_mapping (const void * a, const void * b)
12104 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
12105 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
12107 if (amap->vma > bmap->vma)
12108 return 1;
12109 else if (amap->vma < bmap->vma)
12110 return -1;
12111 else if (amap->type > bmap->type)
12112 /* Ensure results do not depend on the host qsort for objects with
12113 multiple mapping symbols at the same address by sorting on type
12114 after vma. */
12115 return 1;
12116 else if (amap->type < bmap->type)
12117 return -1;
12118 else
12119 return 0;
12123 /* Do code byteswapping. Return FALSE afterwards so that the section is
12124 written out as normal. */
12126 static bfd_boolean
12127 elf32_arm_write_section (bfd *output_bfd,
12128 struct bfd_link_info *link_info,
12129 asection *sec,
12130 bfd_byte *contents)
12132 int mapcount, errcount;
12133 _arm_elf_section_data *arm_data;
12134 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
12135 elf32_arm_section_map *map;
12136 elf32_vfp11_erratum_list *errnode;
12137 bfd_vma ptr;
12138 bfd_vma end;
12139 bfd_vma offset = sec->output_section->vma + sec->output_offset;
12140 bfd_byte tmp;
12141 int i;
12143 /* If this section has not been allocated an _arm_elf_section_data
12144 structure then we cannot record anything. */
12145 arm_data = get_arm_elf_section_data (sec);
12146 if (arm_data == NULL)
12147 return FALSE;
12149 mapcount = arm_data->mapcount;
12150 map = arm_data->map;
12151 errcount = arm_data->erratumcount;
12153 if (errcount != 0)
12155 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
12157 for (errnode = arm_data->erratumlist; errnode != 0;
12158 errnode = errnode->next)
12160 bfd_vma index = errnode->vma - offset;
12162 switch (errnode->type)
12164 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
12166 bfd_vma branch_to_veneer;
12167 /* Original condition code of instruction, plus bit mask for
12168 ARM B instruction. */
12169 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
12170 | 0x0a000000;
12172 /* The instruction is before the label. */
12173 index -= 4;
12175 /* Above offset included in -4 below. */
12176 branch_to_veneer = errnode->u.b.veneer->vma
12177 - errnode->vma - 4;
12179 if ((signed) branch_to_veneer < -(1 << 25)
12180 || (signed) branch_to_veneer >= (1 << 25))
12181 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12182 "range"), output_bfd);
12184 insn |= (branch_to_veneer >> 2) & 0xffffff;
12185 contents[endianflip ^ index] = insn & 0xff;
12186 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12187 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12188 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12190 break;
12192 case VFP11_ERRATUM_ARM_VENEER:
12194 bfd_vma branch_from_veneer;
12195 unsigned int insn;
12197 /* Take size of veneer into account. */
12198 branch_from_veneer = errnode->u.v.branch->vma
12199 - errnode->vma - 12;
12201 if ((signed) branch_from_veneer < -(1 << 25)
12202 || (signed) branch_from_veneer >= (1 << 25))
12203 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12204 "range"), output_bfd);
12206 /* Original instruction. */
12207 insn = errnode->u.v.branch->u.b.vfp_insn;
12208 contents[endianflip ^ index] = insn & 0xff;
12209 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12210 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12211 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12213 /* Branch back to insn after original insn. */
12214 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
12215 contents[endianflip ^ (index + 4)] = insn & 0xff;
12216 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
12217 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
12218 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
12220 break;
12222 default:
12223 abort ();
12228 if (mapcount == 0)
12229 return FALSE;
12231 if (globals->byteswap_code)
12233 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
12235 ptr = map[0].vma;
12236 for (i = 0; i < mapcount; i++)
12238 if (i == mapcount - 1)
12239 end = sec->size;
12240 else
12241 end = map[i + 1].vma;
12243 switch (map[i].type)
12245 case 'a':
12246 /* Byte swap code words. */
12247 while (ptr + 3 < end)
12249 tmp = contents[ptr];
12250 contents[ptr] = contents[ptr + 3];
12251 contents[ptr + 3] = tmp;
12252 tmp = contents[ptr + 1];
12253 contents[ptr + 1] = contents[ptr + 2];
12254 contents[ptr + 2] = tmp;
12255 ptr += 4;
12257 break;
12259 case 't':
12260 /* Byte swap code halfwords. */
12261 while (ptr + 1 < end)
12263 tmp = contents[ptr];
12264 contents[ptr] = contents[ptr + 1];
12265 contents[ptr + 1] = tmp;
12266 ptr += 2;
12268 break;
12270 case 'd':
12271 /* Leave data alone. */
12272 break;
12274 ptr = end;
12278 free (map);
12279 arm_data->mapcount = 0;
12280 arm_data->mapsize = 0;
12281 arm_data->map = NULL;
12282 unrecord_section_with_arm_elf_section_data (sec);
12284 return FALSE;
12287 static void
12288 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
12289 asection * sec,
12290 void * ignore ATTRIBUTE_UNUSED)
12292 unrecord_section_with_arm_elf_section_data (sec);
12295 static bfd_boolean
12296 elf32_arm_close_and_cleanup (bfd * abfd)
12298 if (abfd->sections)
12299 bfd_map_over_sections (abfd,
12300 unrecord_section_via_map_over_sections,
12301 NULL);
12303 return _bfd_elf_close_and_cleanup (abfd);
12306 static bfd_boolean
12307 elf32_arm_bfd_free_cached_info (bfd * abfd)
12309 if (abfd->sections)
12310 bfd_map_over_sections (abfd,
12311 unrecord_section_via_map_over_sections,
12312 NULL);
12314 return _bfd_free_cached_info (abfd);
12317 /* Display STT_ARM_TFUNC symbols as functions. */
12319 static void
12320 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
12321 asymbol *asym)
12323 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
12325 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
12326 elfsym->symbol.flags |= BSF_FUNCTION;
12330 /* Mangle thumb function symbols as we read them in. */
12332 static bfd_boolean
12333 elf32_arm_swap_symbol_in (bfd * abfd,
12334 const void *psrc,
12335 const void *pshn,
12336 Elf_Internal_Sym *dst)
12338 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
12339 return FALSE;
12341 /* New EABI objects mark thumb function symbols by setting the low bit of
12342 the address. Turn these into STT_ARM_TFUNC. */
12343 if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC)
12344 && (dst->st_value & 1))
12346 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
12347 dst->st_value &= ~(bfd_vma) 1;
12349 return TRUE;
12353 /* Mangle thumb function symbols as we write them out. */
12355 static void
12356 elf32_arm_swap_symbol_out (bfd *abfd,
12357 const Elf_Internal_Sym *src,
12358 void *cdst,
12359 void *shndx)
12361 Elf_Internal_Sym newsym;
12363 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12364 of the address set, as per the new EABI. We do this unconditionally
12365 because objcopy does not set the elf header flags until after
12366 it writes out the symbol table. */
12367 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
12369 newsym = *src;
12370 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
12371 if (newsym.st_shndx != SHN_UNDEF)
12373 /* Do this only for defined symbols. At link type, the static
12374 linker will simulate the work of dynamic linker of resolving
12375 symbols and will carry over the thumbness of found symbols to
12376 the output symbol table. It's not clear how it happens, but
12377 the thumbness of undefined symbols can well be different at
12378 runtime, and writing '1' for them will be confusing for users
12379 and possibly for dynamic linker itself.
12381 newsym.st_value |= 1;
12384 src = &newsym;
12386 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
12389 /* Add the PT_ARM_EXIDX program header. */
12391 static bfd_boolean
12392 elf32_arm_modify_segment_map (bfd *abfd,
12393 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12395 struct elf_segment_map *m;
12396 asection *sec;
12398 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12399 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12401 /* If there is already a PT_ARM_EXIDX header, then we do not
12402 want to add another one. This situation arises when running
12403 "strip"; the input binary already has the header. */
12404 m = elf_tdata (abfd)->segment_map;
12405 while (m && m->p_type != PT_ARM_EXIDX)
12406 m = m->next;
12407 if (!m)
12409 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
12410 if (m == NULL)
12411 return FALSE;
12412 m->p_type = PT_ARM_EXIDX;
12413 m->count = 1;
12414 m->sections[0] = sec;
12416 m->next = elf_tdata (abfd)->segment_map;
12417 elf_tdata (abfd)->segment_map = m;
12421 return TRUE;
12424 /* We may add a PT_ARM_EXIDX program header. */
12426 static int
12427 elf32_arm_additional_program_headers (bfd *abfd,
12428 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12430 asection *sec;
12432 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12433 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12434 return 1;
12435 else
12436 return 0;
12439 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
12441 static bfd_boolean
12442 elf32_arm_is_function_type (unsigned int type)
12444 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
12447 /* We use this to override swap_symbol_in and swap_symbol_out. */
12448 const struct elf_size_info elf32_arm_size_info =
12450 sizeof (Elf32_External_Ehdr),
12451 sizeof (Elf32_External_Phdr),
12452 sizeof (Elf32_External_Shdr),
12453 sizeof (Elf32_External_Rel),
12454 sizeof (Elf32_External_Rela),
12455 sizeof (Elf32_External_Sym),
12456 sizeof (Elf32_External_Dyn),
12457 sizeof (Elf_External_Note),
12460 32, 2,
12461 ELFCLASS32, EV_CURRENT,
12462 bfd_elf32_write_out_phdrs,
12463 bfd_elf32_write_shdrs_and_ehdr,
12464 bfd_elf32_checksum_contents,
12465 bfd_elf32_write_relocs,
12466 elf32_arm_swap_symbol_in,
12467 elf32_arm_swap_symbol_out,
12468 bfd_elf32_slurp_reloc_table,
12469 bfd_elf32_slurp_symbol_table,
12470 bfd_elf32_swap_dyn_in,
12471 bfd_elf32_swap_dyn_out,
12472 bfd_elf32_swap_reloc_in,
12473 bfd_elf32_swap_reloc_out,
12474 bfd_elf32_swap_reloca_in,
12475 bfd_elf32_swap_reloca_out
12478 #define ELF_ARCH bfd_arch_arm
12479 #define ELF_MACHINE_CODE EM_ARM
12480 #ifdef __QNXTARGET__
12481 #define ELF_MAXPAGESIZE 0x1000
12482 #else
12483 #define ELF_MAXPAGESIZE 0x8000
12484 #endif
12485 #define ELF_MINPAGESIZE 0x1000
12486 #define ELF_COMMONPAGESIZE 0x1000
12488 #define bfd_elf32_mkobject elf32_arm_mkobject
12490 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12491 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
12492 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12493 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12494 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
12495 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
12496 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
12497 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
12498 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
12499 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
12500 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
12501 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
12502 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
12503 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
12505 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12506 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
12507 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
12508 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12509 #define elf_backend_check_relocs elf32_arm_check_relocs
12510 #define elf_backend_relocate_section elf32_arm_relocate_section
12511 #define elf_backend_write_section elf32_arm_write_section
12512 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
12513 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
12514 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12515 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12516 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
12517 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
12518 #define elf_backend_post_process_headers elf32_arm_post_process_headers
12519 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
12520 #define elf_backend_object_p elf32_arm_object_p
12521 #define elf_backend_section_flags elf32_arm_section_flags
12522 #define elf_backend_fake_sections elf32_arm_fake_sections
12523 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
12524 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12525 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
12526 #define elf_backend_symbol_processing elf32_arm_symbol_processing
12527 #define elf_backend_size_info elf32_arm_size_info
12528 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
12529 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12530 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12531 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12532 #define elf_backend_is_function_type elf32_arm_is_function_type
12534 #define elf_backend_can_refcount 1
12535 #define elf_backend_can_gc_sections 1
12536 #define elf_backend_plt_readonly 1
12537 #define elf_backend_want_got_plt 1
12538 #define elf_backend_want_plt_sym 0
12539 #define elf_backend_may_use_rel_p 1
12540 #define elf_backend_may_use_rela_p 0
12541 #define elf_backend_default_use_rela_p 0
12543 #define elf_backend_got_header_size 12
12545 #undef elf_backend_obj_attrs_vendor
12546 #define elf_backend_obj_attrs_vendor "aeabi"
12547 #undef elf_backend_obj_attrs_section
12548 #define elf_backend_obj_attrs_section ".ARM.attributes"
12549 #undef elf_backend_obj_attrs_arg_type
12550 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12551 #undef elf_backend_obj_attrs_section_type
12552 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
12553 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
12555 #include "elf32-target.h"
12557 /* VxWorks Targets. */
12559 #undef TARGET_LITTLE_SYM
12560 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
12561 #undef TARGET_LITTLE_NAME
12562 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
12563 #undef TARGET_BIG_SYM
12564 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
12565 #undef TARGET_BIG_NAME
12566 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12568 /* Like elf32_arm_link_hash_table_create -- but overrides
12569 appropriately for VxWorks. */
12571 static struct bfd_link_hash_table *
12572 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
12574 struct bfd_link_hash_table *ret;
12576 ret = elf32_arm_link_hash_table_create (abfd);
12577 if (ret)
12579 struct elf32_arm_link_hash_table *htab
12580 = (struct elf32_arm_link_hash_table *) ret;
12581 htab->use_rel = 0;
12582 htab->vxworks_p = 1;
12584 return ret;
12587 static void
12588 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
12590 elf32_arm_final_write_processing (abfd, linker);
12591 elf_vxworks_final_write_processing (abfd, linker);
12594 #undef elf32_bed
12595 #define elf32_bed elf32_arm_vxworks_bed
12597 #undef bfd_elf32_bfd_link_hash_table_create
12598 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12599 #undef elf_backend_add_symbol_hook
12600 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12601 #undef elf_backend_final_write_processing
12602 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12603 #undef elf_backend_emit_relocs
12604 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
12606 #undef elf_backend_may_use_rel_p
12607 #define elf_backend_may_use_rel_p 0
12608 #undef elf_backend_may_use_rela_p
12609 #define elf_backend_may_use_rela_p 1
12610 #undef elf_backend_default_use_rela_p
12611 #define elf_backend_default_use_rela_p 1
12612 #undef elf_backend_want_plt_sym
12613 #define elf_backend_want_plt_sym 1
12614 #undef ELF_MAXPAGESIZE
12615 #define ELF_MAXPAGESIZE 0x1000
12617 #include "elf32-target.h"
12620 /* Symbian OS Targets. */
12622 #undef TARGET_LITTLE_SYM
12623 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
12624 #undef TARGET_LITTLE_NAME
12625 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
12626 #undef TARGET_BIG_SYM
12627 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
12628 #undef TARGET_BIG_NAME
12629 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
12631 /* Like elf32_arm_link_hash_table_create -- but overrides
12632 appropriately for Symbian OS. */
12634 static struct bfd_link_hash_table *
12635 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
12637 struct bfd_link_hash_table *ret;
12639 ret = elf32_arm_link_hash_table_create (abfd);
12640 if (ret)
12642 struct elf32_arm_link_hash_table *htab
12643 = (struct elf32_arm_link_hash_table *)ret;
12644 /* There is no PLT header for Symbian OS. */
12645 htab->plt_header_size = 0;
12646 /* The PLT entries are each one instruction and one word. */
12647 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
12648 htab->symbian_p = 1;
12649 /* Symbian uses armv5t or above, so use_blx is always true. */
12650 htab->use_blx = 1;
12651 htab->root.is_relocatable_executable = 1;
12653 return ret;
12656 static const struct bfd_elf_special_section
12657 elf32_arm_symbian_special_sections[] =
12659 /* In a BPABI executable, the dynamic linking sections do not go in
12660 the loadable read-only segment. The post-linker may wish to
12661 refer to these sections, but they are not part of the final
12662 program image. */
12663 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12664 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12665 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12666 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12667 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
12668 /* These sections do not need to be writable as the SymbianOS
12669 postlinker will arrange things so that no dynamic relocation is
12670 required. */
12671 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12672 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12673 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12674 { NULL, 0, 0, 0, 0 }
12677 static void
12678 elf32_arm_symbian_begin_write_processing (bfd *abfd,
12679 struct bfd_link_info *link_info)
12681 /* BPABI objects are never loaded directly by an OS kernel; they are
12682 processed by a postlinker first, into an OS-specific format. If
12683 the D_PAGED bit is set on the file, BFD will align segments on
12684 page boundaries, so that an OS can directly map the file. With
12685 BPABI objects, that just results in wasted space. In addition,
12686 because we clear the D_PAGED bit, map_sections_to_segments will
12687 recognize that the program headers should not be mapped into any
12688 loadable segment. */
12689 abfd->flags &= ~D_PAGED;
12690 elf32_arm_begin_write_processing (abfd, link_info);
12693 static bfd_boolean
12694 elf32_arm_symbian_modify_segment_map (bfd *abfd,
12695 struct bfd_link_info *info)
12697 struct elf_segment_map *m;
12698 asection *dynsec;
12700 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12701 segment. However, because the .dynamic section is not marked
12702 with SEC_LOAD, the generic ELF code will not create such a
12703 segment. */
12704 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12705 if (dynsec)
12707 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12708 if (m->p_type == PT_DYNAMIC)
12709 break;
12711 if (m == NULL)
12713 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12714 m->next = elf_tdata (abfd)->segment_map;
12715 elf_tdata (abfd)->segment_map = m;
12719 /* Also call the generic arm routine. */
12720 return elf32_arm_modify_segment_map (abfd, info);
12723 /* Return address for Ith PLT stub in section PLT, for relocation REL
12724 or (bfd_vma) -1 if it should not be included. */
12726 static bfd_vma
12727 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12728 const arelent *rel ATTRIBUTE_UNUSED)
12730 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12734 #undef elf32_bed
12735 #define elf32_bed elf32_arm_symbian_bed
12737 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12738 will process them and then discard them. */
12739 #undef ELF_DYNAMIC_SEC_FLAGS
12740 #define ELF_DYNAMIC_SEC_FLAGS \
12741 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12743 #undef elf_backend_add_symbol_hook
12744 #undef elf_backend_emit_relocs
12746 #undef bfd_elf32_bfd_link_hash_table_create
12747 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12748 #undef elf_backend_special_sections
12749 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12750 #undef elf_backend_begin_write_processing
12751 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12752 #undef elf_backend_final_write_processing
12753 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12755 #undef elf_backend_modify_segment_map
12756 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12758 /* There is no .got section for BPABI objects, and hence no header. */
12759 #undef elf_backend_got_header_size
12760 #define elf_backend_got_header_size 0
12762 /* Similarly, there is no .got.plt section. */
12763 #undef elf_backend_want_got_plt
12764 #define elf_backend_want_got_plt 0
12766 #undef elf_backend_plt_sym_val
12767 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12769 #undef elf_backend_may_use_rel_p
12770 #define elf_backend_may_use_rel_p 1
12771 #undef elf_backend_may_use_rela_p
12772 #define elf_backend_may_use_rela_p 0
12773 #undef elf_backend_default_use_rela_p
12774 #define elf_backend_default_use_rela_p 0
12775 #undef elf_backend_want_plt_sym
12776 #define elf_backend_want_plt_sym 0
12777 #undef ELF_MAXPAGESIZE
12778 #define ELF_MAXPAGESIZE 0x8000
12780 #include "elf32-target.h"