1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 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 2 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, MA 02110-1301, USA. */
23 #include "libiberty.h"
26 #include "elf-vxworks.h"
30 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
62 #define ARM_ELF_ABI_VERSION 0
64 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_FREEBSD
66 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
69 static struct elf_backend_data elf32_arm_vxworks_bed;
71 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
72 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
75 static reloc_howto_type elf32_arm_howto_table_1[] =
78 HOWTO (R_ARM_NONE, /* type */
80 0, /* size (0 = byte, 1 = short, 2 = long) */
82 FALSE, /* pc_relative */
84 complain_overflow_dont,/* complain_on_overflow */
85 bfd_elf_generic_reloc, /* special_function */
86 "R_ARM_NONE", /* name */
87 FALSE, /* partial_inplace */
90 FALSE), /* pcrel_offset */
92 HOWTO (R_ARM_PC24, /* type */
94 2, /* size (0 = byte, 1 = short, 2 = long) */
96 TRUE, /* pc_relative */
98 complain_overflow_signed,/* complain_on_overflow */
99 bfd_elf_generic_reloc, /* special_function */
100 "R_ARM_PC24", /* name */
101 FALSE, /* partial_inplace */
102 0x00ffffff, /* src_mask */
103 0x00ffffff, /* dst_mask */
104 TRUE), /* pcrel_offset */
106 /* 32 bit absolute */
107 HOWTO (R_ARM_ABS32, /* type */
109 2, /* size (0 = byte, 1 = short, 2 = long) */
111 FALSE, /* pc_relative */
113 complain_overflow_bitfield,/* complain_on_overflow */
114 bfd_elf_generic_reloc, /* special_function */
115 "R_ARM_ABS32", /* name */
116 FALSE, /* partial_inplace */
117 0xffffffff, /* src_mask */
118 0xffffffff, /* dst_mask */
119 FALSE), /* pcrel_offset */
121 /* standard 32bit pc-relative reloc */
122 HOWTO (R_ARM_REL32, /* type */
124 2, /* size (0 = byte, 1 = short, 2 = long) */
126 TRUE, /* pc_relative */
128 complain_overflow_bitfield,/* complain_on_overflow */
129 bfd_elf_generic_reloc, /* special_function */
130 "R_ARM_REL32", /* name */
131 FALSE, /* partial_inplace */
132 0xffffffff, /* src_mask */
133 0xffffffff, /* dst_mask */
134 TRUE), /* pcrel_offset */
136 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
137 HOWTO (R_ARM_LDR_PC_G0, /* type */
139 0, /* size (0 = byte, 1 = short, 2 = long) */
141 TRUE, /* pc_relative */
143 complain_overflow_dont,/* complain_on_overflow */
144 bfd_elf_generic_reloc, /* special_function */
145 "R_ARM_LDR_PC_G0", /* name */
146 FALSE, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 TRUE), /* pcrel_offset */
151 /* 16 bit absolute */
152 HOWTO (R_ARM_ABS16, /* type */
154 1, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE, /* pc_relative */
158 complain_overflow_bitfield,/* complain_on_overflow */
159 bfd_elf_generic_reloc, /* special_function */
160 "R_ARM_ABS16", /* name */
161 FALSE, /* partial_inplace */
162 0x0000ffff, /* src_mask */
163 0x0000ffff, /* dst_mask */
164 FALSE), /* pcrel_offset */
166 /* 12 bit absolute */
167 HOWTO (R_ARM_ABS12, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE, /* pc_relative */
173 complain_overflow_bitfield,/* complain_on_overflow */
174 bfd_elf_generic_reloc, /* special_function */
175 "R_ARM_ABS12", /* name */
176 FALSE, /* partial_inplace */
177 0x00000fff, /* src_mask */
178 0x00000fff, /* dst_mask */
179 FALSE), /* pcrel_offset */
181 HOWTO (R_ARM_THM_ABS5, /* type */
183 1, /* size (0 = byte, 1 = short, 2 = long) */
185 FALSE, /* pc_relative */
187 complain_overflow_bitfield,/* complain_on_overflow */
188 bfd_elf_generic_reloc, /* special_function */
189 "R_ARM_THM_ABS5", /* name */
190 FALSE, /* partial_inplace */
191 0x000007e0, /* src_mask */
192 0x000007e0, /* dst_mask */
193 FALSE), /* pcrel_offset */
196 HOWTO (R_ARM_ABS8, /* type */
198 0, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE, /* pc_relative */
202 complain_overflow_bitfield,/* complain_on_overflow */
203 bfd_elf_generic_reloc, /* special_function */
204 "R_ARM_ABS8", /* name */
205 FALSE, /* partial_inplace */
206 0x000000ff, /* src_mask */
207 0x000000ff, /* dst_mask */
208 FALSE), /* pcrel_offset */
210 HOWTO (R_ARM_SBREL32, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE, /* pc_relative */
216 complain_overflow_dont,/* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_ARM_SBREL32", /* name */
219 FALSE, /* partial_inplace */
220 0xffffffff, /* src_mask */
221 0xffffffff, /* dst_mask */
222 FALSE), /* pcrel_offset */
224 HOWTO (R_ARM_THM_CALL, /* type */
226 2, /* size (0 = byte, 1 = short, 2 = long) */
228 TRUE, /* pc_relative */
230 complain_overflow_signed,/* complain_on_overflow */
231 bfd_elf_generic_reloc, /* special_function */
232 "R_ARM_THM_CALL", /* name */
233 FALSE, /* partial_inplace */
234 0x07ff07ff, /* src_mask */
235 0x07ff07ff, /* dst_mask */
236 TRUE), /* pcrel_offset */
238 HOWTO (R_ARM_THM_PC8, /* type */
240 1, /* size (0 = byte, 1 = short, 2 = long) */
242 TRUE, /* pc_relative */
244 complain_overflow_signed,/* complain_on_overflow */
245 bfd_elf_generic_reloc, /* special_function */
246 "R_ARM_THM_PC8", /* name */
247 FALSE, /* partial_inplace */
248 0x000000ff, /* src_mask */
249 0x000000ff, /* dst_mask */
250 TRUE), /* pcrel_offset */
252 HOWTO (R_ARM_BREL_ADJ, /* type */
254 1, /* size (0 = byte, 1 = short, 2 = long) */
256 FALSE, /* pc_relative */
258 complain_overflow_signed,/* complain_on_overflow */
259 bfd_elf_generic_reloc, /* special_function */
260 "R_ARM_BREL_ADJ", /* name */
261 FALSE, /* partial_inplace */
262 0xffffffff, /* src_mask */
263 0xffffffff, /* dst_mask */
264 FALSE), /* pcrel_offset */
266 HOWTO (R_ARM_SWI24, /* type */
268 0, /* size (0 = byte, 1 = short, 2 = long) */
270 FALSE, /* pc_relative */
272 complain_overflow_signed,/* complain_on_overflow */
273 bfd_elf_generic_reloc, /* special_function */
274 "R_ARM_SWI24", /* name */
275 FALSE, /* partial_inplace */
276 0x00000000, /* src_mask */
277 0x00000000, /* dst_mask */
278 FALSE), /* pcrel_offset */
280 HOWTO (R_ARM_THM_SWI8, /* type */
282 0, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE, /* pc_relative */
286 complain_overflow_signed,/* complain_on_overflow */
287 bfd_elf_generic_reloc, /* special_function */
288 "R_ARM_SWI8", /* name */
289 FALSE, /* partial_inplace */
290 0x00000000, /* src_mask */
291 0x00000000, /* dst_mask */
292 FALSE), /* pcrel_offset */
294 /* BLX instruction for the ARM. */
295 HOWTO (R_ARM_XPC25, /* type */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
299 TRUE, /* pc_relative */
301 complain_overflow_signed,/* complain_on_overflow */
302 bfd_elf_generic_reloc, /* special_function */
303 "R_ARM_XPC25", /* name */
304 FALSE, /* partial_inplace */
305 0x00ffffff, /* src_mask */
306 0x00ffffff, /* dst_mask */
307 TRUE), /* pcrel_offset */
309 /* BLX instruction for the Thumb. */
310 HOWTO (R_ARM_THM_XPC22, /* type */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 TRUE, /* pc_relative */
316 complain_overflow_signed,/* complain_on_overflow */
317 bfd_elf_generic_reloc, /* special_function */
318 "R_ARM_THM_XPC22", /* name */
319 FALSE, /* partial_inplace */
320 0x07ff07ff, /* src_mask */
321 0x07ff07ff, /* dst_mask */
322 TRUE), /* pcrel_offset */
324 /* Dynamic TLS relocations. */
326 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE, /* pc_relative */
332 complain_overflow_bitfield,/* complain_on_overflow */
333 bfd_elf_generic_reloc, /* special_function */
334 "R_ARM_TLS_DTPMOD32", /* name */
335 TRUE, /* partial_inplace */
336 0xffffffff, /* src_mask */
337 0xffffffff, /* dst_mask */
338 FALSE), /* pcrel_offset */
340 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
342 2, /* size (0 = byte, 1 = short, 2 = long) */
344 FALSE, /* pc_relative */
346 complain_overflow_bitfield,/* complain_on_overflow */
347 bfd_elf_generic_reloc, /* special_function */
348 "R_ARM_TLS_DTPOFF32", /* name */
349 TRUE, /* partial_inplace */
350 0xffffffff, /* src_mask */
351 0xffffffff, /* dst_mask */
352 FALSE), /* pcrel_offset */
354 HOWTO (R_ARM_TLS_TPOFF32, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE, /* pc_relative */
360 complain_overflow_bitfield,/* complain_on_overflow */
361 bfd_elf_generic_reloc, /* special_function */
362 "R_ARM_TLS_TPOFF32", /* name */
363 TRUE, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE), /* pcrel_offset */
368 /* Relocs used in ARM Linux */
370 HOWTO (R_ARM_COPY, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE, /* pc_relative */
376 complain_overflow_bitfield,/* complain_on_overflow */
377 bfd_elf_generic_reloc, /* special_function */
378 "R_ARM_COPY", /* name */
379 TRUE, /* partial_inplace */
380 0xffffffff, /* src_mask */
381 0xffffffff, /* dst_mask */
382 FALSE), /* pcrel_offset */
384 HOWTO (R_ARM_GLOB_DAT, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 FALSE, /* pc_relative */
390 complain_overflow_bitfield,/* complain_on_overflow */
391 bfd_elf_generic_reloc, /* special_function */
392 "R_ARM_GLOB_DAT", /* name */
393 TRUE, /* partial_inplace */
394 0xffffffff, /* src_mask */
395 0xffffffff, /* dst_mask */
396 FALSE), /* pcrel_offset */
398 HOWTO (R_ARM_JUMP_SLOT, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE, /* pc_relative */
404 complain_overflow_bitfield,/* complain_on_overflow */
405 bfd_elf_generic_reloc, /* special_function */
406 "R_ARM_JUMP_SLOT", /* name */
407 TRUE, /* partial_inplace */
408 0xffffffff, /* src_mask */
409 0xffffffff, /* dst_mask */
410 FALSE), /* pcrel_offset */
412 HOWTO (R_ARM_RELATIVE, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE, /* pc_relative */
418 complain_overflow_bitfield,/* complain_on_overflow */
419 bfd_elf_generic_reloc, /* special_function */
420 "R_ARM_RELATIVE", /* name */
421 TRUE, /* partial_inplace */
422 0xffffffff, /* src_mask */
423 0xffffffff, /* dst_mask */
424 FALSE), /* pcrel_offset */
426 HOWTO (R_ARM_GOTOFF32, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 FALSE, /* pc_relative */
432 complain_overflow_bitfield,/* complain_on_overflow */
433 bfd_elf_generic_reloc, /* special_function */
434 "R_ARM_GOTOFF32", /* name */
435 TRUE, /* partial_inplace */
436 0xffffffff, /* src_mask */
437 0xffffffff, /* dst_mask */
438 FALSE), /* pcrel_offset */
440 HOWTO (R_ARM_GOTPC, /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 TRUE, /* pc_relative */
446 complain_overflow_bitfield,/* complain_on_overflow */
447 bfd_elf_generic_reloc, /* special_function */
448 "R_ARM_GOTPC", /* name */
449 TRUE, /* partial_inplace */
450 0xffffffff, /* src_mask */
451 0xffffffff, /* dst_mask */
452 TRUE), /* pcrel_offset */
454 HOWTO (R_ARM_GOT32, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE, /* pc_relative */
460 complain_overflow_bitfield,/* complain_on_overflow */
461 bfd_elf_generic_reloc, /* special_function */
462 "R_ARM_GOT32", /* name */
463 TRUE, /* partial_inplace */
464 0xffffffff, /* src_mask */
465 0xffffffff, /* dst_mask */
466 FALSE), /* pcrel_offset */
468 HOWTO (R_ARM_PLT32, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 TRUE, /* pc_relative */
474 complain_overflow_bitfield,/* complain_on_overflow */
475 bfd_elf_generic_reloc, /* special_function */
476 "R_ARM_PLT32", /* name */
477 FALSE, /* partial_inplace */
478 0x00ffffff, /* src_mask */
479 0x00ffffff, /* dst_mask */
480 TRUE), /* pcrel_offset */
482 HOWTO (R_ARM_CALL, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 TRUE, /* pc_relative */
488 complain_overflow_signed,/* complain_on_overflow */
489 bfd_elf_generic_reloc, /* special_function */
490 "R_ARM_CALL", /* name */
491 FALSE, /* partial_inplace */
492 0x00ffffff, /* src_mask */
493 0x00ffffff, /* dst_mask */
494 TRUE), /* pcrel_offset */
496 HOWTO (R_ARM_JUMP24, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 TRUE, /* pc_relative */
502 complain_overflow_signed,/* complain_on_overflow */
503 bfd_elf_generic_reloc, /* special_function */
504 "R_ARM_JUMP24", /* name */
505 FALSE, /* partial_inplace */
506 0x00ffffff, /* src_mask */
507 0x00ffffff, /* dst_mask */
508 TRUE), /* pcrel_offset */
510 HOWTO (R_ARM_THM_JUMP24, /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 TRUE, /* pc_relative */
516 complain_overflow_signed,/* complain_on_overflow */
517 bfd_elf_generic_reloc, /* special_function */
518 "R_ARM_THM_JUMP24", /* name */
519 FALSE, /* partial_inplace */
520 0x07ff2fff, /* src_mask */
521 0x07ff2fff, /* dst_mask */
522 TRUE), /* pcrel_offset */
524 HOWTO (R_ARM_BASE_ABS, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE, /* pc_relative */
530 complain_overflow_dont,/* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_ARM_BASE_ABS", /* name */
533 FALSE, /* partial_inplace */
534 0xffffffff, /* src_mask */
535 0xffffffff, /* dst_mask */
536 FALSE), /* pcrel_offset */
538 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 TRUE, /* pc_relative */
544 complain_overflow_dont,/* complain_on_overflow */
545 bfd_elf_generic_reloc, /* special_function */
546 "R_ARM_ALU_PCREL_7_0", /* name */
547 FALSE, /* partial_inplace */
548 0x00000fff, /* src_mask */
549 0x00000fff, /* dst_mask */
550 TRUE), /* pcrel_offset */
552 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 TRUE, /* pc_relative */
558 complain_overflow_dont,/* complain_on_overflow */
559 bfd_elf_generic_reloc, /* special_function */
560 "R_ARM_ALU_PCREL_15_8",/* name */
561 FALSE, /* partial_inplace */
562 0x00000fff, /* src_mask */
563 0x00000fff, /* dst_mask */
564 TRUE), /* pcrel_offset */
566 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
570 TRUE, /* pc_relative */
572 complain_overflow_dont,/* complain_on_overflow */
573 bfd_elf_generic_reloc, /* special_function */
574 "R_ARM_ALU_PCREL_23_15",/* name */
575 FALSE, /* partial_inplace */
576 0x00000fff, /* src_mask */
577 0x00000fff, /* dst_mask */
578 TRUE), /* pcrel_offset */
580 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE, /* pc_relative */
586 complain_overflow_dont,/* complain_on_overflow */
587 bfd_elf_generic_reloc, /* special_function */
588 "R_ARM_LDR_SBREL_11_0",/* name */
589 FALSE, /* partial_inplace */
590 0x00000fff, /* src_mask */
591 0x00000fff, /* dst_mask */
592 FALSE), /* pcrel_offset */
594 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE, /* pc_relative */
600 complain_overflow_dont,/* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_ARM_ALU_SBREL_19_12",/* name */
603 FALSE, /* partial_inplace */
604 0x000ff000, /* src_mask */
605 0x000ff000, /* dst_mask */
606 FALSE), /* pcrel_offset */
608 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 FALSE, /* pc_relative */
614 complain_overflow_dont,/* complain_on_overflow */
615 bfd_elf_generic_reloc, /* special_function */
616 "R_ARM_ALU_SBREL_27_20",/* name */
617 FALSE, /* partial_inplace */
618 0x0ff00000, /* src_mask */
619 0x0ff00000, /* dst_mask */
620 FALSE), /* pcrel_offset */
622 HOWTO (R_ARM_TARGET1, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE, /* pc_relative */
628 complain_overflow_dont,/* complain_on_overflow */
629 bfd_elf_generic_reloc, /* special_function */
630 "R_ARM_TARGET1", /* name */
631 FALSE, /* partial_inplace */
632 0xffffffff, /* src_mask */
633 0xffffffff, /* dst_mask */
634 FALSE), /* pcrel_offset */
636 HOWTO (R_ARM_ROSEGREL32, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 FALSE, /* pc_relative */
642 complain_overflow_dont,/* complain_on_overflow */
643 bfd_elf_generic_reloc, /* special_function */
644 "R_ARM_ROSEGREL32", /* name */
645 FALSE, /* partial_inplace */
646 0xffffffff, /* src_mask */
647 0xffffffff, /* dst_mask */
648 FALSE), /* pcrel_offset */
650 HOWTO (R_ARM_V4BX, /* type */
652 2, /* size (0 = byte, 1 = short, 2 = long) */
654 FALSE, /* pc_relative */
656 complain_overflow_dont,/* complain_on_overflow */
657 bfd_elf_generic_reloc, /* special_function */
658 "R_ARM_V4BX", /* name */
659 FALSE, /* partial_inplace */
660 0xffffffff, /* src_mask */
661 0xffffffff, /* dst_mask */
662 FALSE), /* pcrel_offset */
664 HOWTO (R_ARM_TARGET2, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 FALSE, /* pc_relative */
670 complain_overflow_signed,/* complain_on_overflow */
671 bfd_elf_generic_reloc, /* special_function */
672 "R_ARM_TARGET2", /* name */
673 FALSE, /* partial_inplace */
674 0xffffffff, /* src_mask */
675 0xffffffff, /* dst_mask */
676 TRUE), /* pcrel_offset */
678 HOWTO (R_ARM_PREL31, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 TRUE, /* pc_relative */
684 complain_overflow_signed,/* complain_on_overflow */
685 bfd_elf_generic_reloc, /* special_function */
686 "R_ARM_PREL31", /* name */
687 FALSE, /* partial_inplace */
688 0x7fffffff, /* src_mask */
689 0x7fffffff, /* dst_mask */
690 TRUE), /* pcrel_offset */
692 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE, /* pc_relative */
698 complain_overflow_dont,/* complain_on_overflow */
699 bfd_elf_generic_reloc, /* special_function */
700 "R_ARM_MOVW_ABS_NC", /* name */
701 FALSE, /* partial_inplace */
702 0x0000ffff, /* src_mask */
703 0x0000ffff, /* dst_mask */
704 FALSE), /* pcrel_offset */
706 HOWTO (R_ARM_MOVT_ABS, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE, /* pc_relative */
712 complain_overflow_bitfield,/* complain_on_overflow */
713 bfd_elf_generic_reloc, /* special_function */
714 "R_ARM_MOVT_ABS", /* name */
715 FALSE, /* partial_inplace */
716 0x0000ffff, /* src_mask */
717 0x0000ffff, /* dst_mask */
718 FALSE), /* pcrel_offset */
720 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 TRUE, /* pc_relative */
726 complain_overflow_dont,/* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_ARM_MOVW_PREL_NC", /* name */
729 FALSE, /* partial_inplace */
730 0x0000ffff, /* src_mask */
731 0x0000ffff, /* dst_mask */
732 TRUE), /* pcrel_offset */
734 HOWTO (R_ARM_MOVT_PREL, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 TRUE, /* pc_relative */
740 complain_overflow_bitfield,/* complain_on_overflow */
741 bfd_elf_generic_reloc, /* special_function */
742 "R_ARM_MOVT_PREL", /* name */
743 FALSE, /* partial_inplace */
744 0x0000ffff, /* src_mask */
745 0x0000ffff, /* dst_mask */
746 TRUE), /* pcrel_offset */
748 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE, /* pc_relative */
754 complain_overflow_dont,/* complain_on_overflow */
755 bfd_elf_generic_reloc, /* special_function */
756 "R_ARM_THM_MOVW_ABS_NC",/* name */
757 FALSE, /* partial_inplace */
758 0x040f70ff, /* src_mask */
759 0x040f70ff, /* dst_mask */
760 FALSE), /* pcrel_offset */
762 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 FALSE, /* pc_relative */
768 complain_overflow_bitfield,/* complain_on_overflow */
769 bfd_elf_generic_reloc, /* special_function */
770 "R_ARM_THM_MOVT_ABS", /* name */
771 FALSE, /* partial_inplace */
772 0x040f70ff, /* src_mask */
773 0x040f70ff, /* dst_mask */
774 FALSE), /* pcrel_offset */
776 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 TRUE, /* pc_relative */
782 complain_overflow_dont,/* complain_on_overflow */
783 bfd_elf_generic_reloc, /* special_function */
784 "R_ARM_THM_MOVW_PREL_NC",/* name */
785 FALSE, /* partial_inplace */
786 0x040f70ff, /* src_mask */
787 0x040f70ff, /* dst_mask */
788 TRUE), /* pcrel_offset */
790 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 TRUE, /* pc_relative */
796 complain_overflow_bitfield,/* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 "R_ARM_THM_MOVT_PREL", /* name */
799 FALSE, /* partial_inplace */
800 0x040f70ff, /* src_mask */
801 0x040f70ff, /* dst_mask */
802 TRUE), /* pcrel_offset */
804 HOWTO (R_ARM_THM_JUMP19, /* type */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 TRUE, /* pc_relative */
810 complain_overflow_signed,/* complain_on_overflow */
811 bfd_elf_generic_reloc, /* special_function */
812 "R_ARM_THM_JUMP19", /* name */
813 FALSE, /* partial_inplace */
814 0x043f2fff, /* src_mask */
815 0x043f2fff, /* dst_mask */
816 TRUE), /* pcrel_offset */
818 HOWTO (R_ARM_THM_JUMP6, /* type */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 TRUE, /* pc_relative */
824 complain_overflow_unsigned,/* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_ARM_THM_JUMP6", /* name */
827 FALSE, /* partial_inplace */
828 0x02f8, /* src_mask */
829 0x02f8, /* dst_mask */
830 TRUE), /* pcrel_offset */
832 /* These are declared as 13-bit signed relocations because we can
833 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
835 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
839 TRUE, /* pc_relative */
841 complain_overflow_dont,/* complain_on_overflow */
842 bfd_elf_generic_reloc, /* special_function */
843 "R_ARM_THM_ALU_PREL_11_0",/* name */
844 FALSE, /* partial_inplace */
845 0xffffffff, /* src_mask */
846 0xffffffff, /* dst_mask */
847 TRUE), /* pcrel_offset */
849 HOWTO (R_ARM_THM_PC12, /* type */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
853 TRUE, /* pc_relative */
855 complain_overflow_dont,/* complain_on_overflow */
856 bfd_elf_generic_reloc, /* special_function */
857 "R_ARM_THM_PC12", /* name */
858 FALSE, /* partial_inplace */
859 0xffffffff, /* src_mask */
860 0xffffffff, /* dst_mask */
861 TRUE), /* pcrel_offset */
863 HOWTO (R_ARM_ABS32_NOI, /* type */
865 2, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE, /* pc_relative */
869 complain_overflow_dont,/* complain_on_overflow */
870 bfd_elf_generic_reloc, /* special_function */
871 "R_ARM_ABS32_NOI", /* name */
872 FALSE, /* partial_inplace */
873 0xffffffff, /* src_mask */
874 0xffffffff, /* dst_mask */
875 FALSE), /* pcrel_offset */
877 HOWTO (R_ARM_REL32_NOI, /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 TRUE, /* pc_relative */
883 complain_overflow_dont,/* complain_on_overflow */
884 bfd_elf_generic_reloc, /* special_function */
885 "R_ARM_REL32_NOI", /* name */
886 FALSE, /* partial_inplace */
887 0xffffffff, /* src_mask */
888 0xffffffff, /* dst_mask */
889 FALSE), /* pcrel_offset */
891 /* Group relocations. */
893 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
897 TRUE, /* pc_relative */
899 complain_overflow_dont,/* complain_on_overflow */
900 bfd_elf_generic_reloc, /* special_function */
901 "R_ARM_ALU_PC_G0_NC", /* name */
902 FALSE, /* partial_inplace */
903 0xffffffff, /* src_mask */
904 0xffffffff, /* dst_mask */
905 TRUE), /* pcrel_offset */
907 HOWTO (R_ARM_ALU_PC_G0, /* type */
909 2, /* size (0 = byte, 1 = short, 2 = long) */
911 TRUE, /* pc_relative */
913 complain_overflow_dont,/* complain_on_overflow */
914 bfd_elf_generic_reloc, /* special_function */
915 "R_ARM_ALU_PC_G0", /* name */
916 FALSE, /* partial_inplace */
917 0xffffffff, /* src_mask */
918 0xffffffff, /* dst_mask */
919 TRUE), /* pcrel_offset */
921 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 TRUE, /* pc_relative */
927 complain_overflow_dont,/* complain_on_overflow */
928 bfd_elf_generic_reloc, /* special_function */
929 "R_ARM_ALU_PC_G1_NC", /* name */
930 FALSE, /* partial_inplace */
931 0xffffffff, /* src_mask */
932 0xffffffff, /* dst_mask */
933 TRUE), /* pcrel_offset */
935 HOWTO (R_ARM_ALU_PC_G1, /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 TRUE, /* pc_relative */
941 complain_overflow_dont,/* complain_on_overflow */
942 bfd_elf_generic_reloc, /* special_function */
943 "R_ARM_ALU_PC_G1", /* name */
944 FALSE, /* partial_inplace */
945 0xffffffff, /* src_mask */
946 0xffffffff, /* dst_mask */
947 TRUE), /* pcrel_offset */
949 HOWTO (R_ARM_ALU_PC_G2, /* type */
951 2, /* size (0 = byte, 1 = short, 2 = long) */
953 TRUE, /* pc_relative */
955 complain_overflow_dont,/* complain_on_overflow */
956 bfd_elf_generic_reloc, /* special_function */
957 "R_ARM_ALU_PC_G2", /* name */
958 FALSE, /* partial_inplace */
959 0xffffffff, /* src_mask */
960 0xffffffff, /* dst_mask */
961 TRUE), /* pcrel_offset */
963 HOWTO (R_ARM_LDR_PC_G1, /* type */
965 2, /* size (0 = byte, 1 = short, 2 = long) */
967 TRUE, /* pc_relative */
969 complain_overflow_dont,/* complain_on_overflow */
970 bfd_elf_generic_reloc, /* special_function */
971 "R_ARM_LDR_PC_G1", /* name */
972 FALSE, /* partial_inplace */
973 0xffffffff, /* src_mask */
974 0xffffffff, /* dst_mask */
975 TRUE), /* pcrel_offset */
977 HOWTO (R_ARM_LDR_PC_G2, /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 TRUE, /* pc_relative */
983 complain_overflow_dont,/* complain_on_overflow */
984 bfd_elf_generic_reloc, /* special_function */
985 "R_ARM_LDR_PC_G2", /* name */
986 FALSE, /* partial_inplace */
987 0xffffffff, /* src_mask */
988 0xffffffff, /* dst_mask */
989 TRUE), /* pcrel_offset */
991 HOWTO (R_ARM_LDRS_PC_G0, /* type */
993 2, /* size (0 = byte, 1 = short, 2 = long) */
995 TRUE, /* pc_relative */
997 complain_overflow_dont,/* complain_on_overflow */
998 bfd_elf_generic_reloc, /* special_function */
999 "R_ARM_LDRS_PC_G0", /* name */
1000 FALSE, /* partial_inplace */
1001 0xffffffff, /* src_mask */
1002 0xffffffff, /* dst_mask */
1003 TRUE), /* pcrel_offset */
1005 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1007 2, /* size (0 = byte, 1 = short, 2 = long) */
1009 TRUE, /* pc_relative */
1011 complain_overflow_dont,/* complain_on_overflow */
1012 bfd_elf_generic_reloc, /* special_function */
1013 "R_ARM_LDRS_PC_G1", /* name */
1014 FALSE, /* partial_inplace */
1015 0xffffffff, /* src_mask */
1016 0xffffffff, /* dst_mask */
1017 TRUE), /* pcrel_offset */
1019 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1023 TRUE, /* pc_relative */
1025 complain_overflow_dont,/* complain_on_overflow */
1026 bfd_elf_generic_reloc, /* special_function */
1027 "R_ARM_LDRS_PC_G2", /* name */
1028 FALSE, /* partial_inplace */
1029 0xffffffff, /* src_mask */
1030 0xffffffff, /* dst_mask */
1031 TRUE), /* pcrel_offset */
1033 HOWTO (R_ARM_LDC_PC_G0, /* type */
1035 2, /* size (0 = byte, 1 = short, 2 = long) */
1037 TRUE, /* pc_relative */
1039 complain_overflow_dont,/* complain_on_overflow */
1040 bfd_elf_generic_reloc, /* special_function */
1041 "R_ARM_LDC_PC_G0", /* name */
1042 FALSE, /* partial_inplace */
1043 0xffffffff, /* src_mask */
1044 0xffffffff, /* dst_mask */
1045 TRUE), /* pcrel_offset */
1047 HOWTO (R_ARM_LDC_PC_G1, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 TRUE, /* pc_relative */
1053 complain_overflow_dont,/* complain_on_overflow */
1054 bfd_elf_generic_reloc, /* special_function */
1055 "R_ARM_LDC_PC_G1", /* name */
1056 FALSE, /* partial_inplace */
1057 0xffffffff, /* src_mask */
1058 0xffffffff, /* dst_mask */
1059 TRUE), /* pcrel_offset */
1061 HOWTO (R_ARM_LDC_PC_G2, /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 TRUE, /* pc_relative */
1067 complain_overflow_dont,/* complain_on_overflow */
1068 bfd_elf_generic_reloc, /* special_function */
1069 "R_ARM_LDC_PC_G2", /* name */
1070 FALSE, /* partial_inplace */
1071 0xffffffff, /* src_mask */
1072 0xffffffff, /* dst_mask */
1073 TRUE), /* pcrel_offset */
1075 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 TRUE, /* pc_relative */
1081 complain_overflow_dont,/* complain_on_overflow */
1082 bfd_elf_generic_reloc, /* special_function */
1083 "R_ARM_ALU_SB_G0_NC", /* name */
1084 FALSE, /* partial_inplace */
1085 0xffffffff, /* src_mask */
1086 0xffffffff, /* dst_mask */
1087 TRUE), /* pcrel_offset */
1089 HOWTO (R_ARM_ALU_SB_G0, /* type */
1091 2, /* size (0 = byte, 1 = short, 2 = long) */
1093 TRUE, /* pc_relative */
1095 complain_overflow_dont,/* complain_on_overflow */
1096 bfd_elf_generic_reloc, /* special_function */
1097 "R_ARM_ALU_SB_G0", /* name */
1098 FALSE, /* partial_inplace */
1099 0xffffffff, /* src_mask */
1100 0xffffffff, /* dst_mask */
1101 TRUE), /* pcrel_offset */
1103 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 TRUE, /* pc_relative */
1109 complain_overflow_dont,/* complain_on_overflow */
1110 bfd_elf_generic_reloc, /* special_function */
1111 "R_ARM_ALU_SB_G1_NC", /* name */
1112 FALSE, /* partial_inplace */
1113 0xffffffff, /* src_mask */
1114 0xffffffff, /* dst_mask */
1115 TRUE), /* pcrel_offset */
1117 HOWTO (R_ARM_ALU_SB_G1, /* type */
1119 2, /* size (0 = byte, 1 = short, 2 = long) */
1121 TRUE, /* pc_relative */
1123 complain_overflow_dont,/* complain_on_overflow */
1124 bfd_elf_generic_reloc, /* special_function */
1125 "R_ARM_ALU_SB_G1", /* name */
1126 FALSE, /* partial_inplace */
1127 0xffffffff, /* src_mask */
1128 0xffffffff, /* dst_mask */
1129 TRUE), /* pcrel_offset */
1131 HOWTO (R_ARM_ALU_SB_G2, /* type */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 TRUE, /* pc_relative */
1137 complain_overflow_dont,/* complain_on_overflow */
1138 bfd_elf_generic_reloc, /* special_function */
1139 "R_ARM_ALU_SB_G2", /* name */
1140 FALSE, /* partial_inplace */
1141 0xffffffff, /* src_mask */
1142 0xffffffff, /* dst_mask */
1143 TRUE), /* pcrel_offset */
1145 HOWTO (R_ARM_LDR_SB_G0, /* type */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1149 TRUE, /* pc_relative */
1151 complain_overflow_dont,/* complain_on_overflow */
1152 bfd_elf_generic_reloc, /* special_function */
1153 "R_ARM_LDR_SB_G0", /* name */
1154 FALSE, /* partial_inplace */
1155 0xffffffff, /* src_mask */
1156 0xffffffff, /* dst_mask */
1157 TRUE), /* pcrel_offset */
1159 HOWTO (R_ARM_LDR_SB_G1, /* type */
1161 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 TRUE, /* pc_relative */
1165 complain_overflow_dont,/* complain_on_overflow */
1166 bfd_elf_generic_reloc, /* special_function */
1167 "R_ARM_LDR_SB_G1", /* name */
1168 FALSE, /* partial_inplace */
1169 0xffffffff, /* src_mask */
1170 0xffffffff, /* dst_mask */
1171 TRUE), /* pcrel_offset */
1173 HOWTO (R_ARM_LDR_SB_G2, /* type */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1177 TRUE, /* pc_relative */
1179 complain_overflow_dont,/* complain_on_overflow */
1180 bfd_elf_generic_reloc, /* special_function */
1181 "R_ARM_LDR_SB_G2", /* name */
1182 FALSE, /* partial_inplace */
1183 0xffffffff, /* src_mask */
1184 0xffffffff, /* dst_mask */
1185 TRUE), /* pcrel_offset */
1187 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1189 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 TRUE, /* pc_relative */
1193 complain_overflow_dont,/* complain_on_overflow */
1194 bfd_elf_generic_reloc, /* special_function */
1195 "R_ARM_LDRS_SB_G0", /* name */
1196 FALSE, /* partial_inplace */
1197 0xffffffff, /* src_mask */
1198 0xffffffff, /* dst_mask */
1199 TRUE), /* pcrel_offset */
1201 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1203 2, /* size (0 = byte, 1 = short, 2 = long) */
1205 TRUE, /* pc_relative */
1207 complain_overflow_dont,/* complain_on_overflow */
1208 bfd_elf_generic_reloc, /* special_function */
1209 "R_ARM_LDRS_SB_G1", /* name */
1210 FALSE, /* partial_inplace */
1211 0xffffffff, /* src_mask */
1212 0xffffffff, /* dst_mask */
1213 TRUE), /* pcrel_offset */
1215 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1217 2, /* size (0 = byte, 1 = short, 2 = long) */
1219 TRUE, /* pc_relative */
1221 complain_overflow_dont,/* complain_on_overflow */
1222 bfd_elf_generic_reloc, /* special_function */
1223 "R_ARM_LDRS_SB_G2", /* name */
1224 FALSE, /* partial_inplace */
1225 0xffffffff, /* src_mask */
1226 0xffffffff, /* dst_mask */
1227 TRUE), /* pcrel_offset */
1229 HOWTO (R_ARM_LDC_SB_G0, /* type */
1231 2, /* size (0 = byte, 1 = short, 2 = long) */
1233 TRUE, /* pc_relative */
1235 complain_overflow_dont,/* complain_on_overflow */
1236 bfd_elf_generic_reloc, /* special_function */
1237 "R_ARM_LDC_SB_G0", /* name */
1238 FALSE, /* partial_inplace */
1239 0xffffffff, /* src_mask */
1240 0xffffffff, /* dst_mask */
1241 TRUE), /* pcrel_offset */
1243 HOWTO (R_ARM_LDC_SB_G1, /* type */
1245 2, /* size (0 = byte, 1 = short, 2 = long) */
1247 TRUE, /* pc_relative */
1249 complain_overflow_dont,/* complain_on_overflow */
1250 bfd_elf_generic_reloc, /* special_function */
1251 "R_ARM_LDC_SB_G1", /* name */
1252 FALSE, /* partial_inplace */
1253 0xffffffff, /* src_mask */
1254 0xffffffff, /* dst_mask */
1255 TRUE), /* pcrel_offset */
1257 HOWTO (R_ARM_LDC_SB_G2, /* type */
1259 2, /* size (0 = byte, 1 = short, 2 = long) */
1261 TRUE, /* pc_relative */
1263 complain_overflow_dont,/* complain_on_overflow */
1264 bfd_elf_generic_reloc, /* special_function */
1265 "R_ARM_LDC_SB_G2", /* name */
1266 FALSE, /* partial_inplace */
1267 0xffffffff, /* src_mask */
1268 0xffffffff, /* dst_mask */
1269 TRUE), /* pcrel_offset */
1271 /* End of group relocations. */
1273 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1275 2, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE, /* pc_relative */
1279 complain_overflow_dont,/* complain_on_overflow */
1280 bfd_elf_generic_reloc, /* special_function */
1281 "R_ARM_MOVW_BREL_NC", /* name */
1282 FALSE, /* partial_inplace */
1283 0x0000ffff, /* src_mask */
1284 0x0000ffff, /* dst_mask */
1285 FALSE), /* pcrel_offset */
1287 HOWTO (R_ARM_MOVT_BREL, /* type */
1289 2, /* size (0 = byte, 1 = short, 2 = long) */
1291 FALSE, /* pc_relative */
1293 complain_overflow_bitfield,/* complain_on_overflow */
1294 bfd_elf_generic_reloc, /* special_function */
1295 "R_ARM_MOVT_BREL", /* name */
1296 FALSE, /* partial_inplace */
1297 0x0000ffff, /* src_mask */
1298 0x0000ffff, /* dst_mask */
1299 FALSE), /* pcrel_offset */
1301 HOWTO (R_ARM_MOVW_BREL, /* type */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1305 FALSE, /* pc_relative */
1307 complain_overflow_dont,/* complain_on_overflow */
1308 bfd_elf_generic_reloc, /* special_function */
1309 "R_ARM_MOVW_BREL", /* name */
1310 FALSE, /* partial_inplace */
1311 0x0000ffff, /* src_mask */
1312 0x0000ffff, /* dst_mask */
1313 FALSE), /* pcrel_offset */
1315 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1317 2, /* size (0 = byte, 1 = short, 2 = long) */
1319 FALSE, /* pc_relative */
1321 complain_overflow_dont,/* complain_on_overflow */
1322 bfd_elf_generic_reloc, /* special_function */
1323 "R_ARM_THM_MOVW_BREL_NC",/* name */
1324 FALSE, /* partial_inplace */
1325 0x040f70ff, /* src_mask */
1326 0x040f70ff, /* dst_mask */
1327 FALSE), /* pcrel_offset */
1329 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1331 2, /* size (0 = byte, 1 = short, 2 = long) */
1333 FALSE, /* pc_relative */
1335 complain_overflow_bitfield,/* complain_on_overflow */
1336 bfd_elf_generic_reloc, /* special_function */
1337 "R_ARM_THM_MOVT_BREL", /* name */
1338 FALSE, /* partial_inplace */
1339 0x040f70ff, /* src_mask */
1340 0x040f70ff, /* dst_mask */
1341 FALSE), /* pcrel_offset */
1343 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1345 2, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE, /* pc_relative */
1349 complain_overflow_dont,/* complain_on_overflow */
1350 bfd_elf_generic_reloc, /* special_function */
1351 "R_ARM_THM_MOVW_BREL", /* name */
1352 FALSE, /* partial_inplace */
1353 0x040f70ff, /* src_mask */
1354 0x040f70ff, /* dst_mask */
1355 FALSE), /* pcrel_offset */
1357 EMPTY_HOWTO (90), /* unallocated */
1362 HOWTO (R_ARM_PLT32_ABS, /* type */
1364 2, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE, /* pc_relative */
1368 complain_overflow_dont,/* complain_on_overflow */
1369 bfd_elf_generic_reloc, /* special_function */
1370 "R_ARM_PLT32_ABS", /* name */
1371 FALSE, /* partial_inplace */
1372 0xffffffff, /* src_mask */
1373 0xffffffff, /* dst_mask */
1374 FALSE), /* pcrel_offset */
1376 HOWTO (R_ARM_GOT_ABS, /* type */
1378 2, /* size (0 = byte, 1 = short, 2 = long) */
1380 FALSE, /* pc_relative */
1382 complain_overflow_dont,/* complain_on_overflow */
1383 bfd_elf_generic_reloc, /* special_function */
1384 "R_ARM_GOT_ABS", /* name */
1385 FALSE, /* partial_inplace */
1386 0xffffffff, /* src_mask */
1387 0xffffffff, /* dst_mask */
1388 FALSE), /* pcrel_offset */
1390 HOWTO (R_ARM_GOT_PREL, /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 TRUE, /* pc_relative */
1396 complain_overflow_dont, /* complain_on_overflow */
1397 bfd_elf_generic_reloc, /* special_function */
1398 "R_ARM_GOT_PREL", /* name */
1399 FALSE, /* partial_inplace */
1400 0xffffffff, /* src_mask */
1401 0xffffffff, /* dst_mask */
1402 TRUE), /* pcrel_offset */
1404 HOWTO (R_ARM_GOT_BREL12, /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE, /* pc_relative */
1410 complain_overflow_bitfield,/* complain_on_overflow */
1411 bfd_elf_generic_reloc, /* special_function */
1412 "R_ARM_GOT_BREL12", /* name */
1413 FALSE, /* partial_inplace */
1414 0x00000fff, /* src_mask */
1415 0x00000fff, /* dst_mask */
1416 FALSE), /* pcrel_offset */
1418 HOWTO (R_ARM_GOTOFF12, /* type */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE, /* pc_relative */
1424 complain_overflow_bitfield,/* complain_on_overflow */
1425 bfd_elf_generic_reloc, /* special_function */
1426 "R_ARM_GOTOFF12", /* name */
1427 FALSE, /* partial_inplace */
1428 0x00000fff, /* src_mask */
1429 0x00000fff, /* dst_mask */
1430 FALSE), /* pcrel_offset */
1432 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1434 /* GNU extension to record C++ vtable member usage */
1435 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1437 2, /* size (0 = byte, 1 = short, 2 = long) */
1439 FALSE, /* pc_relative */
1441 complain_overflow_dont, /* complain_on_overflow */
1442 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1443 "R_ARM_GNU_VTENTRY", /* name */
1444 FALSE, /* partial_inplace */
1447 FALSE), /* pcrel_offset */
1449 /* GNU extension to record C++ vtable hierarchy */
1450 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE, /* pc_relative */
1456 complain_overflow_dont, /* complain_on_overflow */
1457 NULL, /* special_function */
1458 "R_ARM_GNU_VTINHERIT", /* name */
1459 FALSE, /* partial_inplace */
1462 FALSE), /* pcrel_offset */
1464 HOWTO (R_ARM_THM_JUMP11, /* type */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1468 TRUE, /* pc_relative */
1470 complain_overflow_signed, /* complain_on_overflow */
1471 bfd_elf_generic_reloc, /* special_function */
1472 "R_ARM_THM_JUMP11", /* name */
1473 FALSE, /* partial_inplace */
1474 0x000007ff, /* src_mask */
1475 0x000007ff, /* dst_mask */
1476 TRUE), /* pcrel_offset */
1478 HOWTO (R_ARM_THM_JUMP8, /* type */
1480 1, /* size (0 = byte, 1 = short, 2 = long) */
1482 TRUE, /* pc_relative */
1484 complain_overflow_signed, /* complain_on_overflow */
1485 bfd_elf_generic_reloc, /* special_function */
1486 "R_ARM_THM_JUMP8", /* name */
1487 FALSE, /* partial_inplace */
1488 0x000000ff, /* src_mask */
1489 0x000000ff, /* dst_mask */
1490 TRUE), /* pcrel_offset */
1492 /* TLS relocations */
1493 HOWTO (R_ARM_TLS_GD32, /* type */
1495 2, /* size (0 = byte, 1 = short, 2 = long) */
1497 FALSE, /* pc_relative */
1499 complain_overflow_bitfield,/* complain_on_overflow */
1500 NULL, /* special_function */
1501 "R_ARM_TLS_GD32", /* name */
1502 TRUE, /* partial_inplace */
1503 0xffffffff, /* src_mask */
1504 0xffffffff, /* dst_mask */
1505 FALSE), /* pcrel_offset */
1507 HOWTO (R_ARM_TLS_LDM32, /* type */
1509 2, /* size (0 = byte, 1 = short, 2 = long) */
1511 FALSE, /* pc_relative */
1513 complain_overflow_bitfield,/* complain_on_overflow */
1514 bfd_elf_generic_reloc, /* special_function */
1515 "R_ARM_TLS_LDM32", /* name */
1516 TRUE, /* partial_inplace */
1517 0xffffffff, /* src_mask */
1518 0xffffffff, /* dst_mask */
1519 FALSE), /* pcrel_offset */
1521 HOWTO (R_ARM_TLS_LDO32, /* type */
1523 2, /* size (0 = byte, 1 = short, 2 = long) */
1525 FALSE, /* pc_relative */
1527 complain_overflow_bitfield,/* complain_on_overflow */
1528 bfd_elf_generic_reloc, /* special_function */
1529 "R_ARM_TLS_LDO32", /* name */
1530 TRUE, /* partial_inplace */
1531 0xffffffff, /* src_mask */
1532 0xffffffff, /* dst_mask */
1533 FALSE), /* pcrel_offset */
1535 HOWTO (R_ARM_TLS_IE32, /* type */
1537 2, /* size (0 = byte, 1 = short, 2 = long) */
1539 FALSE, /* pc_relative */
1541 complain_overflow_bitfield,/* complain_on_overflow */
1542 NULL, /* special_function */
1543 "R_ARM_TLS_IE32", /* name */
1544 TRUE, /* partial_inplace */
1545 0xffffffff, /* src_mask */
1546 0xffffffff, /* dst_mask */
1547 FALSE), /* pcrel_offset */
1549 HOWTO (R_ARM_TLS_LE32, /* type */
1551 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 FALSE, /* pc_relative */
1555 complain_overflow_bitfield,/* complain_on_overflow */
1556 bfd_elf_generic_reloc, /* special_function */
1557 "R_ARM_TLS_LE32", /* name */
1558 TRUE, /* partial_inplace */
1559 0xffffffff, /* src_mask */
1560 0xffffffff, /* dst_mask */
1561 FALSE), /* pcrel_offset */
1563 HOWTO (R_ARM_TLS_LDO12, /* type */
1565 2, /* size (0 = byte, 1 = short, 2 = long) */
1567 FALSE, /* pc_relative */
1569 complain_overflow_bitfield,/* complain_on_overflow */
1570 bfd_elf_generic_reloc, /* special_function */
1571 "R_ARM_TLS_LDO12", /* name */
1572 FALSE, /* partial_inplace */
1573 0x00000fff, /* src_mask */
1574 0x00000fff, /* dst_mask */
1575 FALSE), /* pcrel_offset */
1577 HOWTO (R_ARM_TLS_LE12, /* type */
1579 2, /* size (0 = byte, 1 = short, 2 = long) */
1581 FALSE, /* pc_relative */
1583 complain_overflow_bitfield,/* complain_on_overflow */
1584 bfd_elf_generic_reloc, /* special_function */
1585 "R_ARM_TLS_LE12", /* name */
1586 FALSE, /* partial_inplace */
1587 0x00000fff, /* src_mask */
1588 0x00000fff, /* dst_mask */
1589 FALSE), /* pcrel_offset */
1591 HOWTO (R_ARM_TLS_IE12GP, /* type */
1593 2, /* size (0 = byte, 1 = short, 2 = long) */
1595 FALSE, /* pc_relative */
1597 complain_overflow_bitfield,/* complain_on_overflow */
1598 bfd_elf_generic_reloc, /* special_function */
1599 "R_ARM_TLS_IE12GP", /* name */
1600 FALSE, /* partial_inplace */
1601 0x00000fff, /* src_mask */
1602 0x00000fff, /* dst_mask */
1603 FALSE), /* pcrel_offset */
1606 /* 112-127 private relocations
1607 128 R_ARM_ME_TOO, obsolete
1608 129-255 unallocated in AAELF.
1610 249-255 extended, currently unused, relocations: */
1612 static reloc_howto_type elf32_arm_howto_table_2[4] =
1614 HOWTO (R_ARM_RREL32, /* type */
1616 0, /* size (0 = byte, 1 = short, 2 = long) */
1618 FALSE, /* pc_relative */
1620 complain_overflow_dont,/* complain_on_overflow */
1621 bfd_elf_generic_reloc, /* special_function */
1622 "R_ARM_RREL32", /* name */
1623 FALSE, /* partial_inplace */
1626 FALSE), /* pcrel_offset */
1628 HOWTO (R_ARM_RABS32, /* type */
1630 0, /* size (0 = byte, 1 = short, 2 = long) */
1632 FALSE, /* pc_relative */
1634 complain_overflow_dont,/* complain_on_overflow */
1635 bfd_elf_generic_reloc, /* special_function */
1636 "R_ARM_RABS32", /* name */
1637 FALSE, /* partial_inplace */
1640 FALSE), /* pcrel_offset */
1642 HOWTO (R_ARM_RPC24, /* type */
1644 0, /* size (0 = byte, 1 = short, 2 = long) */
1646 FALSE, /* pc_relative */
1648 complain_overflow_dont,/* complain_on_overflow */
1649 bfd_elf_generic_reloc, /* special_function */
1650 "R_ARM_RPC24", /* name */
1651 FALSE, /* partial_inplace */
1654 FALSE), /* pcrel_offset */
1656 HOWTO (R_ARM_RBASE, /* type */
1658 0, /* size (0 = byte, 1 = short, 2 = long) */
1660 FALSE, /* pc_relative */
1662 complain_overflow_dont,/* complain_on_overflow */
1663 bfd_elf_generic_reloc, /* special_function */
1664 "R_ARM_RBASE", /* name */
1665 FALSE, /* partial_inplace */
1668 FALSE) /* pcrel_offset */
1671 static reloc_howto_type *
1672 elf32_arm_howto_from_type (unsigned int r_type)
1674 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1675 return &elf32_arm_howto_table_1[r_type];
1677 if (r_type >= R_ARM_RREL32
1678 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1679 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1685 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1686 Elf_Internal_Rela * elf_reloc)
1688 unsigned int r_type;
1690 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1691 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1694 struct elf32_arm_reloc_map
1696 bfd_reloc_code_real_type bfd_reloc_val;
1697 unsigned char elf_reloc_val;
1700 /* All entries in this list must also be present in elf32_arm_howto_table. */
1701 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1703 {BFD_RELOC_NONE, R_ARM_NONE},
1704 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1705 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1706 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1707 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1708 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1709 {BFD_RELOC_32, R_ARM_ABS32},
1710 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1711 {BFD_RELOC_8, R_ARM_ABS8},
1712 {BFD_RELOC_16, R_ARM_ABS16},
1713 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1714 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1718 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1719 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1720 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1721 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1722 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1723 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1724 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1725 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1726 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1727 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1728 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1729 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1730 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1731 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1732 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1733 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1734 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1735 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1736 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1737 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1738 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1739 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1740 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1741 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1742 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1743 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1744 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1745 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1746 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1747 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1748 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1749 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1750 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1751 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1752 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1753 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1754 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1755 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1756 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1757 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1758 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1759 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1760 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1761 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1762 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1763 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1764 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1765 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1766 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1767 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1768 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1769 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1770 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1771 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1772 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1773 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1774 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1775 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1776 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1777 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1778 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1779 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}
1782 static reloc_howto_type *
1783 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1784 bfd_reloc_code_real_type code)
1787 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1788 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1789 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1794 static reloc_howto_type *
1795 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1801 i < (sizeof (elf32_arm_howto_table_1)
1802 / sizeof (elf32_arm_howto_table_1[0]));
1804 if (elf32_arm_howto_table_1[i].name != NULL
1805 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1806 return &elf32_arm_howto_table_1[i];
1809 i < (sizeof (elf32_arm_howto_table_2)
1810 / sizeof (elf32_arm_howto_table_2[0]));
1812 if (elf32_arm_howto_table_2[i].name != NULL
1813 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1814 return &elf32_arm_howto_table_2[i];
1819 /* Support for core dump NOTE sections */
1821 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1826 switch (note->descsz)
1831 case 148: /* Linux/ARM 32-bit*/
1833 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1836 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1844 case 96: /* FreeBSD/ARM */
1846 if (elf_tdata(abfd)->core_signal == 0)
1847 elf_tdata (abfd)->core_signal = ((int *)(note->descdata))[5];
1850 elf_tdata (abfd)->core_pid = ((int *)(note->descdata))[6];
1858 /* Make a ".reg/999" section. */
1859 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1860 size, note->descpos + offset);
1864 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1866 switch (note->descsz)
1871 case 124: /* Linux/ARM elf_prpsinfo */
1872 elf_tdata (abfd)->core_program
1873 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1874 elf_tdata (abfd)->core_command
1875 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1878 /* Note that for some reason, a spurious space is tacked
1879 onto the end of the args in some (at least one anyway)
1880 implementations, so strip it off if it exists. */
1883 char *command = elf_tdata (abfd)->core_command;
1884 int n = strlen (command);
1886 if (0 < n && command[n - 1] == ' ')
1887 command[n - 1] = '\0';
1893 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1894 #define TARGET_LITTLE_NAME "elf32-littlearm"
1895 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1896 #define TARGET_BIG_NAME "elf32-bigarm"
1898 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1899 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1901 typedef unsigned long int insn32;
1902 typedef unsigned short int insn16;
1904 /* In lieu of proper flags, assume all EABIv4 or later objects are
1906 #define INTERWORK_FLAG(abfd) \
1907 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1908 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1910 /* The linker script knows the section names for placement.
1911 The entry_names are used to do simple name mangling on the stubs.
1912 Given a function name, and its type, the stub can be found. The
1913 name can be changed. The only requirement is the %s be present. */
1914 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1915 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1917 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1918 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1920 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1921 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1923 /* The name of the dynamic interpreter. This is put in the .interp
1925 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1927 #ifdef FOUR_WORD_PLT
1929 /* The first entry in a procedure linkage table looks like
1930 this. It is set up so that any shared library function that is
1931 called before the relocation has been set up calls the dynamic
1933 static const bfd_vma elf32_arm_plt0_entry [] =
1935 0xe52de004, /* str lr, [sp, #-4]! */
1936 0xe59fe010, /* ldr lr, [pc, #16] */
1937 0xe08fe00e, /* add lr, pc, lr */
1938 0xe5bef008, /* ldr pc, [lr, #8]! */
1941 /* Subsequent entries in a procedure linkage table look like
1943 static const bfd_vma elf32_arm_plt_entry [] =
1945 0xe28fc600, /* add ip, pc, #NN */
1946 0xe28cca00, /* add ip, ip, #NN */
1947 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1948 0x00000000, /* unused */
1953 /* The first entry in a procedure linkage table looks like
1954 this. It is set up so that any shared library function that is
1955 called before the relocation has been set up calls the dynamic
1957 static const bfd_vma elf32_arm_plt0_entry [] =
1959 0xe52de004, /* str lr, [sp, #-4]! */
1960 0xe59fe004, /* ldr lr, [pc, #4] */
1961 0xe08fe00e, /* add lr, pc, lr */
1962 0xe5bef008, /* ldr pc, [lr, #8]! */
1963 0x00000000, /* &GOT[0] - . */
1966 /* Subsequent entries in a procedure linkage table look like
1968 static const bfd_vma elf32_arm_plt_entry [] =
1970 0xe28fc600, /* add ip, pc, #0xNN00000 */
1971 0xe28cca00, /* add ip, ip, #0xNN000 */
1972 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1977 /* The format of the first entry in the procedure linkage table
1978 for a VxWorks executable. */
1979 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1981 0xe52dc008, /* str ip,[sp,#-8]! */
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xe59cf008, /* ldr pc,[ip,#8] */
1984 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1987 /* The format of subsequent entries in a VxWorks executable. */
1988 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1990 0xe59fc000, /* ldr ip,[pc] */
1991 0xe59cf000, /* ldr pc,[ip] */
1992 0x00000000, /* .long @got */
1993 0xe59fc000, /* ldr ip,[pc] */
1994 0xea000000, /* b _PLT */
1995 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1998 /* The format of entries in a VxWorks shared library. */
1999 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
2001 0xe59fc000, /* ldr ip,[pc] */
2002 0xe79cf009, /* ldr pc,[ip,r9] */
2003 0x00000000, /* .long @got */
2004 0xe59fc000, /* ldr ip,[pc] */
2005 0xe599f008, /* ldr pc,[r9,#8] */
2006 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2009 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2010 #define PLT_THUMB_STUB_SIZE 4
2011 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2017 /* The entries in a PLT when using a DLL-based target with multiple
2019 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2021 0xe51ff004, /* ldr pc, [pc, #-4] */
2022 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2025 /* Used to build a map of a section. This is required for mixed-endian
2028 typedef struct elf32_elf_section_map
2033 elf32_arm_section_map;
2035 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2039 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2040 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2041 VFP11_ERRATUM_ARM_VENEER,
2042 VFP11_ERRATUM_THUMB_VENEER
2044 elf32_vfp11_erratum_type;
2046 typedef struct elf32_vfp11_erratum_list
2048 struct elf32_vfp11_erratum_list *next;
2054 struct elf32_vfp11_erratum_list *veneer;
2055 unsigned int vfp_insn;
2059 struct elf32_vfp11_erratum_list *branch;
2063 elf32_vfp11_erratum_type type;
2065 elf32_vfp11_erratum_list;
2067 typedef struct _arm_elf_section_data
2069 struct bfd_elf_section_data elf;
2070 unsigned int mapcount;
2071 unsigned int mapsize;
2072 elf32_arm_section_map *map;
2073 unsigned int erratumcount;
2074 elf32_vfp11_erratum_list *erratumlist;
2076 _arm_elf_section_data;
2078 #define elf32_arm_section_data(sec) \
2079 ((_arm_elf_section_data *) elf_section_data (sec))
2081 /* The size of the thread control block. */
2084 struct elf32_arm_obj_tdata
2086 struct elf_obj_tdata root;
2088 /* tls_type for each local got entry. */
2089 char *local_got_tls_type;
2091 /* Zero to warn when linking objects with incompatible enum sizes. */
2092 int no_enum_size_warning;
2095 #define elf32_arm_tdata(abfd) \
2096 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2098 #define elf32_arm_local_got_tls_type(abfd) \
2099 (elf32_arm_tdata (abfd)->local_got_tls_type)
2102 elf32_arm_mkobject (bfd *abfd)
2104 if (abfd->tdata.any == NULL)
2106 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2107 abfd->tdata.any = bfd_zalloc (abfd, amt);
2108 if (abfd->tdata.any == NULL)
2111 return bfd_elf_mkobject (abfd);
2114 /* The ARM linker needs to keep track of the number of relocs that it
2115 decides to copy in check_relocs for each symbol. This is so that
2116 it can discard PC relative relocs if it doesn't need them when
2117 linking with -Bsymbolic. We store the information in a field
2118 extending the regular ELF linker hash table. */
2120 /* This structure keeps track of the number of relocs we have copied
2121 for a given symbol. */
2122 struct elf32_arm_relocs_copied
2125 struct elf32_arm_relocs_copied * next;
2126 /* A section in dynobj. */
2128 /* Number of relocs copied in this section. */
2129 bfd_size_type count;
2130 /* Number of PC-relative relocs copied in this section. */
2131 bfd_size_type pc_count;
2134 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2136 /* Arm ELF linker hash entry. */
2137 struct elf32_arm_link_hash_entry
2139 struct elf_link_hash_entry root;
2141 /* Number of PC relative relocs copied for this symbol. */
2142 struct elf32_arm_relocs_copied * relocs_copied;
2144 /* We reference count Thumb references to a PLT entry separately,
2145 so that we can emit the Thumb trampoline only if needed. */
2146 bfd_signed_vma plt_thumb_refcount;
2148 /* Since PLT entries have variable size if the Thumb prologue is
2149 used, we need to record the index into .got.plt instead of
2150 recomputing it from the PLT offset. */
2151 bfd_signed_vma plt_got_offset;
2153 #define GOT_UNKNOWN 0
2154 #define GOT_NORMAL 1
2155 #define GOT_TLS_GD 2
2156 #define GOT_TLS_IE 4
2157 unsigned char tls_type;
2159 /* The symbol marking the real symbol location for exported thumb
2160 symbols with Arm stubs. */
2161 struct elf_link_hash_entry *export_glue;
2164 /* Traverse an arm ELF linker hash table. */
2165 #define elf32_arm_link_hash_traverse(table, func, info) \
2166 (elf_link_hash_traverse \
2168 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2171 /* Get the ARM elf linker hash table from a link_info structure. */
2172 #define elf32_arm_hash_table(info) \
2173 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2175 /* ARM ELF linker hash table. */
2176 struct elf32_arm_link_hash_table
2178 /* The main hash table. */
2179 struct elf_link_hash_table root;
2181 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2182 bfd_size_type thumb_glue_size;
2184 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2185 bfd_size_type arm_glue_size;
2187 /* The size in bytes of the section containing glue for VFP11 erratum
2189 bfd_size_type vfp11_erratum_glue_size;
2191 /* An arbitrary input BFD chosen to hold the glue sections. */
2192 bfd * bfd_of_glue_owner;
2194 /* Nonzero to output a BE8 image. */
2197 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2198 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2201 /* The relocation to use for R_ARM_TARGET2 relocations. */
2204 /* Nonzero to fix BX instructions for ARMv4 targets. */
2207 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2210 /* What sort of code sequences we should look for which may trigger the
2211 VFP11 denorm erratum. */
2212 bfd_arm_vfp11_fix vfp11_fix;
2214 /* Global counter for the number of fixes we have emitted. */
2215 int num_vfp11_fixes;
2217 /* Nonzero to force PIC branch veneers. */
2220 /* The number of bytes in the initial entry in the PLT. */
2221 bfd_size_type plt_header_size;
2223 /* The number of bytes in the subsequent PLT etries. */
2224 bfd_size_type plt_entry_size;
2226 /* True if the target system is VxWorks. */
2229 /* True if the target system is Symbian OS. */
2232 /* True if the target uses REL relocations. */
2235 /* Short-cuts to get to dynamic linker sections. */
2244 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2247 /* Data for R_ARM_TLS_LDM32 relocations. */
2249 bfd_signed_vma refcount;
2253 /* Small local sym to section mapping cache. */
2254 struct sym_sec_cache sym_sec;
2256 /* For convenience in allocate_dynrelocs. */
2260 /* Create an entry in an ARM ELF linker hash table. */
2262 static struct bfd_hash_entry *
2263 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2264 struct bfd_hash_table * table,
2265 const char * string)
2267 struct elf32_arm_link_hash_entry * ret =
2268 (struct elf32_arm_link_hash_entry *) entry;
2270 /* Allocate the structure if it has not already been allocated by a
2272 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2273 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2275 return (struct bfd_hash_entry *) ret;
2277 /* Call the allocation method of the superclass. */
2278 ret = ((struct elf32_arm_link_hash_entry *)
2279 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2283 ret->relocs_copied = NULL;
2284 ret->tls_type = GOT_UNKNOWN;
2285 ret->plt_thumb_refcount = 0;
2286 ret->plt_got_offset = -1;
2287 ret->export_glue = NULL;
2290 return (struct bfd_hash_entry *) ret;
2293 /* Return true if NAME is the name of the relocation section associated
2297 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2298 const char *name, asection *s)
2301 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2303 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2306 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2307 shortcuts to them in our hash table. */
2310 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2312 struct elf32_arm_link_hash_table *htab;
2314 htab = elf32_arm_hash_table (info);
2315 /* BPABI objects never have a GOT, or associated sections. */
2316 if (htab->symbian_p)
2319 if (! _bfd_elf_create_got_section (dynobj, info))
2322 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2323 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2324 if (!htab->sgot || !htab->sgotplt)
2327 htab->srelgot = bfd_make_section_with_flags (dynobj,
2328 RELOC_SECTION (htab, ".got"),
2329 (SEC_ALLOC | SEC_LOAD
2332 | SEC_LINKER_CREATED
2334 if (htab->srelgot == NULL
2335 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2340 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2341 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2345 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2347 struct elf32_arm_link_hash_table *htab;
2349 htab = elf32_arm_hash_table (info);
2350 if (!htab->sgot && !create_got_section (dynobj, info))
2353 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2356 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2357 htab->srelplt = bfd_get_section_by_name (dynobj,
2358 RELOC_SECTION (htab, ".plt"));
2359 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2361 htab->srelbss = bfd_get_section_by_name (dynobj,
2362 RELOC_SECTION (htab, ".bss"));
2364 if (htab->vxworks_p)
2366 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2371 htab->plt_header_size = 0;
2372 htab->plt_entry_size
2373 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2377 htab->plt_header_size
2378 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2379 htab->plt_entry_size
2380 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2387 || (!info->shared && !htab->srelbss))
2393 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2396 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2397 struct elf_link_hash_entry *dir,
2398 struct elf_link_hash_entry *ind)
2400 struct elf32_arm_link_hash_entry *edir, *eind;
2402 edir = (struct elf32_arm_link_hash_entry *) dir;
2403 eind = (struct elf32_arm_link_hash_entry *) ind;
2405 if (eind->relocs_copied != NULL)
2407 if (edir->relocs_copied != NULL)
2409 struct elf32_arm_relocs_copied **pp;
2410 struct elf32_arm_relocs_copied *p;
2412 /* Add reloc counts against the indirect sym to the direct sym
2413 list. Merge any entries against the same section. */
2414 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2416 struct elf32_arm_relocs_copied *q;
2418 for (q = edir->relocs_copied; q != NULL; q = q->next)
2419 if (q->section == p->section)
2421 q->pc_count += p->pc_count;
2422 q->count += p->count;
2429 *pp = edir->relocs_copied;
2432 edir->relocs_copied = eind->relocs_copied;
2433 eind->relocs_copied = NULL;
2436 if (ind->root.type == bfd_link_hash_indirect)
2438 /* Copy over PLT info. */
2439 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2440 eind->plt_thumb_refcount = 0;
2442 if (dir->got.refcount <= 0)
2444 edir->tls_type = eind->tls_type;
2445 eind->tls_type = GOT_UNKNOWN;
2449 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2452 /* Create an ARM elf linker hash table. */
2454 static struct bfd_link_hash_table *
2455 elf32_arm_link_hash_table_create (bfd *abfd)
2457 struct elf32_arm_link_hash_table *ret;
2458 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2460 ret = bfd_malloc (amt);
2464 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2465 elf32_arm_link_hash_newfunc,
2466 sizeof (struct elf32_arm_link_hash_entry)))
2473 ret->sgotplt = NULL;
2474 ret->srelgot = NULL;
2476 ret->srelplt = NULL;
2477 ret->sdynbss = NULL;
2478 ret->srelbss = NULL;
2479 ret->srelplt2 = NULL;
2480 ret->thumb_glue_size = 0;
2481 ret->arm_glue_size = 0;
2482 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2483 ret->vfp11_erratum_glue_size = 0;
2484 ret->num_vfp11_fixes = 0;
2485 ret->bfd_of_glue_owner = NULL;
2486 ret->byteswap_code = 0;
2487 ret->target1_is_rel = 0;
2488 ret->target2_reloc = R_ARM_NONE;
2489 #ifdef FOUR_WORD_PLT
2490 ret->plt_header_size = 16;
2491 ret->plt_entry_size = 16;
2493 ret->plt_header_size = 20;
2494 ret->plt_entry_size = 12;
2501 ret->sym_sec.abfd = NULL;
2503 ret->tls_ldm_got.refcount = 0;
2505 return &ret->root.root;
2508 /* Locate the Thumb encoded calling stub for NAME. */
2510 static struct elf_link_hash_entry *
2511 find_thumb_glue (struct bfd_link_info *link_info,
2513 char **error_message)
2516 struct elf_link_hash_entry *hash;
2517 struct elf32_arm_link_hash_table *hash_table;
2519 /* We need a pointer to the armelf specific hash table. */
2520 hash_table = elf32_arm_hash_table (link_info);
2522 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2523 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2525 BFD_ASSERT (tmp_name);
2527 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2529 hash = elf_link_hash_lookup
2530 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2533 asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2541 /* Locate the ARM encoded calling stub for NAME. */
2543 static struct elf_link_hash_entry *
2544 find_arm_glue (struct bfd_link_info *link_info,
2546 char **error_message)
2549 struct elf_link_hash_entry *myh;
2550 struct elf32_arm_link_hash_table *hash_table;
2552 /* We need a pointer to the elfarm specific hash table. */
2553 hash_table = elf32_arm_hash_table (link_info);
2555 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2556 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2558 BFD_ASSERT (tmp_name);
2560 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2562 myh = elf_link_hash_lookup
2563 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2566 asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2574 /* ARM->Thumb glue (static images):
2578 ldr r12, __func_addr
2581 .word func @ behave as if you saw a ARM_32 reloc.
2588 .word func @ behave as if you saw a ARM_32 reloc.
2590 (relocatable images)
2593 ldr r12, __func_offset
2600 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2601 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2602 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2603 static const insn32 a2t3_func_addr_insn = 0x00000001;
2605 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
2606 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
2607 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
2609 #define ARM2THUMB_PIC_GLUE_SIZE 16
2610 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2611 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2612 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2614 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2618 __func_from_thumb: __func_from_thumb:
2620 nop ldr r6, __func_addr
2622 __func_change_to_arm: bx r6
2624 __func_back_to_thumb:
2630 #define THUMB2ARM_GLUE_SIZE 8
2631 static const insn16 t2a1_bx_pc_insn = 0x4778;
2632 static const insn16 t2a2_noop_insn = 0x46c0;
2633 static const insn32 t2a3_b_insn = 0xea000000;
2635 #define VFP11_ERRATUM_VENEER_SIZE 8
2637 #ifndef ELFARM_NABI_C_INCLUDED
2639 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2643 struct elf32_arm_link_hash_table * globals;
2645 globals = elf32_arm_hash_table (info);
2647 BFD_ASSERT (globals != NULL);
2649 if (globals->arm_glue_size != 0)
2651 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2653 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2654 ARM2THUMB_GLUE_SECTION_NAME);
2656 BFD_ASSERT (s != NULL);
2658 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2660 BFD_ASSERT (s->size == globals->arm_glue_size);
2664 if (globals->thumb_glue_size != 0)
2666 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2668 s = bfd_get_section_by_name
2669 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2671 BFD_ASSERT (s != NULL);
2673 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2675 BFD_ASSERT (s->size == globals->thumb_glue_size);
2679 if (globals->vfp11_erratum_glue_size != 0)
2681 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2683 s = bfd_get_section_by_name
2684 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2686 BFD_ASSERT (s != NULL);
2688 foo = bfd_alloc (globals->bfd_of_glue_owner,
2689 globals->vfp11_erratum_glue_size);
2691 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
2698 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2699 returns the symbol identifying teh stub. */
2700 static struct elf_link_hash_entry *
2701 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2702 struct elf_link_hash_entry * h)
2704 const char * name = h->root.root.string;
2707 struct elf_link_hash_entry * myh;
2708 struct bfd_link_hash_entry * bh;
2709 struct elf32_arm_link_hash_table * globals;
2713 globals = elf32_arm_hash_table (link_info);
2715 BFD_ASSERT (globals != NULL);
2716 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2718 s = bfd_get_section_by_name
2719 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2721 BFD_ASSERT (s != NULL);
2723 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2725 BFD_ASSERT (tmp_name);
2727 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2729 myh = elf_link_hash_lookup
2730 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2734 /* We've already seen this guy. */
2739 /* The only trick here is using hash_table->arm_glue_size as the value.
2740 Even though the section isn't allocated yet, this is where we will be
2743 val = globals->arm_glue_size + 1;
2744 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2745 tmp_name, BSF_GLOBAL, s, val,
2746 NULL, TRUE, FALSE, &bh);
2748 myh = (struct elf_link_hash_entry *) bh;
2749 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2750 myh->forced_local = 1;
2754 if (link_info->shared || globals->root.is_relocatable_executable
2755 || globals->pic_veneer)
2756 size = ARM2THUMB_PIC_GLUE_SIZE;
2757 else if (globals->use_blx)
2758 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
2760 size = ARM2THUMB_STATIC_GLUE_SIZE;
2763 globals->arm_glue_size += size;
2769 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2770 struct elf_link_hash_entry *h)
2772 const char *name = h->root.root.string;
2775 struct elf_link_hash_entry *myh;
2776 struct bfd_link_hash_entry *bh;
2777 struct elf32_arm_link_hash_table *hash_table;
2780 hash_table = elf32_arm_hash_table (link_info);
2782 BFD_ASSERT (hash_table != NULL);
2783 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2785 s = bfd_get_section_by_name
2786 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2788 BFD_ASSERT (s != NULL);
2790 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2791 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2793 BFD_ASSERT (tmp_name);
2795 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2797 myh = elf_link_hash_lookup
2798 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2802 /* We've already seen this guy. */
2808 val = hash_table->thumb_glue_size + 1;
2809 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2810 tmp_name, BSF_GLOBAL, s, val,
2811 NULL, TRUE, FALSE, &bh);
2813 /* If we mark it 'Thumb', the disassembler will do a better job. */
2814 myh = (struct elf_link_hash_entry *) bh;
2815 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2816 myh->forced_local = 1;
2820 #define CHANGE_TO_ARM "__%s_change_to_arm"
2821 #define BACK_FROM_ARM "__%s_back_from_arm"
2823 /* Allocate another symbol to mark where we switch to Arm mode. */
2824 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2825 + strlen (CHANGE_TO_ARM) + 1);
2827 BFD_ASSERT (tmp_name);
2829 sprintf (tmp_name, CHANGE_TO_ARM, name);
2832 val = hash_table->thumb_glue_size + 4,
2833 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2834 tmp_name, BSF_LOCAL, s, val,
2835 NULL, TRUE, FALSE, &bh);
2839 s->size += THUMB2ARM_GLUE_SIZE;
2840 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2846 /* Add an entry to the code/data map for section SEC. */
2849 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
2851 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
2852 unsigned int newidx;
2854 if (sec_data->map == NULL)
2856 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
2857 sec_data->mapcount = 0;
2858 sec_data->mapsize = 1;
2861 newidx = sec_data->mapcount++;
2863 if (sec_data->mapcount > sec_data->mapsize)
2865 sec_data->mapsize *= 2;
2866 sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize
2867 * sizeof (elf32_arm_section_map));
2870 sec_data->map[newidx].vma = vma;
2871 sec_data->map[newidx].type = type;
2875 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
2876 veneers are handled for now. */
2879 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
2880 elf32_vfp11_erratum_list *branch,
2882 asection *branch_sec,
2883 unsigned int offset)
2886 struct elf32_arm_link_hash_table *hash_table;
2888 struct elf_link_hash_entry *myh;
2889 struct bfd_link_hash_entry *bh;
2891 struct _arm_elf_section_data *sec_data;
2893 elf32_vfp11_erratum_list *newerr;
2895 hash_table = elf32_arm_hash_table (link_info);
2897 BFD_ASSERT (hash_table != NULL);
2898 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2900 s = bfd_get_section_by_name
2901 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2903 sec_data = elf32_arm_section_data (s);
2905 BFD_ASSERT (s != NULL);
2907 tmp_name = bfd_malloc ((bfd_size_type) strlen
2908 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
2910 BFD_ASSERT (tmp_name);
2912 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
2913 hash_table->num_vfp11_fixes);
2915 myh = elf_link_hash_lookup
2916 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2918 BFD_ASSERT (myh == NULL);
2921 val = hash_table->vfp11_erratum_glue_size;
2922 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2923 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
2924 NULL, TRUE, FALSE, &bh);
2926 myh = (struct elf_link_hash_entry *) bh;
2927 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2928 myh->forced_local = 1;
2930 /* Link veneer back to calling location. */
2931 errcount = ++(sec_data->erratumcount);
2932 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
2934 newerr->type = VFP11_ERRATUM_ARM_VENEER;
2936 newerr->u.v.branch = branch;
2937 newerr->u.v.id = hash_table->num_vfp11_fixes;
2938 branch->u.b.veneer = newerr;
2940 newerr->next = sec_data->erratumlist;
2941 sec_data->erratumlist = newerr;
2943 /* A symbol for the return from the veneer. */
2944 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
2945 hash_table->num_vfp11_fixes);
2947 myh = elf_link_hash_lookup
2948 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2955 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
2956 branch_sec, val, NULL, TRUE, FALSE, &bh);
2958 myh = (struct elf_link_hash_entry *) bh;
2959 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2960 myh->forced_local = 1;
2964 /* Generate a mapping symbol for the veneer section, and explicitly add an
2965 entry for that symbol to the code/data map for the section. */
2966 if (hash_table->vfp11_erratum_glue_size == 0)
2969 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
2970 ever requires this erratum fix. */
2971 _bfd_generic_link_add_one_symbol (link_info,
2972 hash_table->bfd_of_glue_owner, "$a",
2973 BSF_LOCAL, s, 0, NULL,
2976 myh = (struct elf_link_hash_entry *) bh;
2977 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
2978 myh->forced_local = 1;
2980 /* The elf32_arm_init_maps function only cares about symbols from input
2981 BFDs. We must make a note of this generated mapping symbol
2982 ourselves so that code byteswapping works properly in
2983 elf32_arm_write_section. */
2984 elf32_arm_section_map_add (s, 'a', 0);
2987 s->size += VFP11_ERRATUM_VENEER_SIZE;
2988 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
2989 hash_table->num_vfp11_fixes++;
2991 /* The offset of the veneer. */
2995 /* Add the glue sections to ABFD. This function is called from the
2996 linker scripts in ld/emultempl/{armelf}.em. */
2999 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
3000 struct bfd_link_info *info)
3005 /* If we are only performing a partial
3006 link do not bother adding the glue. */
3007 if (info->relocatable)
3010 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
3014 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
3015 will prevent elf_link_input_bfd() from processing the contents
3017 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3018 | SEC_CODE | SEC_READONLY);
3020 sec = bfd_make_section_with_flags (abfd,
3021 ARM2THUMB_GLUE_SECTION_NAME,
3025 || !bfd_set_section_alignment (abfd, sec, 2))
3028 /* Set the gc mark to prevent the section from being removed by garbage
3029 collection, despite the fact that no relocs refer to this section. */
3033 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
3037 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3038 | SEC_CODE | SEC_READONLY);
3040 sec = bfd_make_section_with_flags (abfd,
3041 THUMB2ARM_GLUE_SECTION_NAME,
3045 || !bfd_set_section_alignment (abfd, sec, 2))
3051 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
3055 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3056 | SEC_CODE | SEC_READONLY);
3058 sec = bfd_make_section_with_flags (abfd,
3059 VFP11_ERRATUM_VENEER_SECTION_NAME,
3063 || !bfd_set_section_alignment (abfd, sec, 2))
3072 /* Select a BFD to be used to hold the sections used by the glue code.
3073 This function is called from the linker scripts in ld/emultempl/
3077 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
3079 struct elf32_arm_link_hash_table *globals;
3081 /* If we are only performing a partial link
3082 do not bother getting a bfd to hold the glue. */
3083 if (info->relocatable)
3086 /* Make sure we don't attach the glue sections to a dynamic object. */
3087 BFD_ASSERT (!(abfd->flags & DYNAMIC));
3089 globals = elf32_arm_hash_table (info);
3091 BFD_ASSERT (globals != NULL);
3093 if (globals->bfd_of_glue_owner != NULL)
3096 /* Save the bfd for later use. */
3097 globals->bfd_of_glue_owner = abfd;
3102 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
3104 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3106 globals->use_blx = 1;
3110 bfd_elf32_arm_process_before_allocation (bfd *abfd,
3111 struct bfd_link_info *link_info)
3113 Elf_Internal_Shdr *symtab_hdr;
3114 Elf_Internal_Rela *internal_relocs = NULL;
3115 Elf_Internal_Rela *irel, *irelend;
3116 bfd_byte *contents = NULL;
3119 struct elf32_arm_link_hash_table *globals;
3121 /* If we are only performing a partial link do not bother
3122 to construct any glue. */
3123 if (link_info->relocatable)
3126 /* Here we have a bfd that is to be included on the link. We have a hook
3127 to do reloc rummaging, before section sizes are nailed down. */
3128 globals = elf32_arm_hash_table (link_info);
3129 check_use_blx (globals);
3131 BFD_ASSERT (globals != NULL);
3132 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3134 if (globals->byteswap_code && !bfd_big_endian (abfd))
3136 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
3141 /* Rummage around all the relocs and map the glue vectors. */
3142 sec = abfd->sections;
3147 for (; sec != NULL; sec = sec->next)
3149 if (sec->reloc_count == 0)
3152 if ((sec->flags & SEC_EXCLUDE) != 0)
3155 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3157 /* Load the relocs. */
3159 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
3160 (Elf_Internal_Rela *) NULL, FALSE);
3162 if (internal_relocs == NULL)
3165 irelend = internal_relocs + sec->reloc_count;
3166 for (irel = internal_relocs; irel < irelend; irel++)
3169 unsigned long r_index;
3171 struct elf_link_hash_entry *h;
3173 r_type = ELF32_R_TYPE (irel->r_info);
3174 r_index = ELF32_R_SYM (irel->r_info);
3176 /* These are the only relocation types we care about. */
3177 if ( r_type != R_ARM_PC24
3178 && r_type != R_ARM_PLT32
3179 && r_type != R_ARM_CALL
3180 && r_type != R_ARM_JUMP24
3181 && r_type != R_ARM_THM_CALL)
3184 /* Get the section contents if we haven't done so already. */
3185 if (contents == NULL)
3187 /* Get cached copy if it exists. */
3188 if (elf_section_data (sec)->this_hdr.contents != NULL)
3189 contents = elf_section_data (sec)->this_hdr.contents;
3192 /* Go get them off disk. */
3193 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3198 /* If the relocation is not against a symbol it cannot concern us. */
3201 /* We don't care about local symbols. */
3202 if (r_index < symtab_hdr->sh_info)
3205 /* This is an external symbol. */
3206 r_index -= symtab_hdr->sh_info;
3207 h = (struct elf_link_hash_entry *)
3208 elf_sym_hashes (abfd)[r_index];
3210 /* If the relocation is against a static symbol it must be within
3211 the current section and so cannot be a cross ARM/Thumb relocation. */
3215 /* If the call will go through a PLT entry then we do not need
3217 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
3226 /* This one is a call from arm code. We need to look up
3227 the target of the call. If it is a thumb target, we
3229 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
3230 && !(r_type == R_ARM_CALL && globals->use_blx))
3231 record_arm_to_thumb_glue (link_info, h);
3234 case R_ARM_THM_CALL:
3235 /* This one is a call from thumb code. We look
3236 up the target of the call. If it is not a thumb
3237 target, we insert glue. */
3238 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx
3239 && h->root.type != bfd_link_hash_undefweak)
3240 record_thumb_to_arm_glue (link_info, h);
3248 if (contents != NULL
3249 && elf_section_data (sec)->this_hdr.contents != contents)
3253 if (internal_relocs != NULL
3254 && elf_section_data (sec)->relocs != internal_relocs)
3255 free (internal_relocs);
3256 internal_relocs = NULL;
3262 if (contents != NULL
3263 && elf_section_data (sec)->this_hdr.contents != contents)
3265 if (internal_relocs != NULL
3266 && elf_section_data (sec)->relocs != internal_relocs)
3267 free (internal_relocs);
3274 /* Initialise maps of ARM/Thumb/data for input BFDs. */
3277 bfd_elf32_arm_init_maps (bfd *abfd)
3279 Elf_Internal_Sym *isymbuf;
3280 Elf_Internal_Shdr *hdr;
3281 unsigned int i, localsyms;
3283 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour || elf_tdata (abfd) == NULL)
3286 if ((abfd->flags & DYNAMIC) != 0)
3289 hdr = &elf_tdata (abfd)->symtab_hdr;
3290 localsyms = hdr->sh_info;
3292 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3293 should contain the number of local symbols, which should come before any
3294 global symbols. Mapping symbols are always local. */
3295 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
3298 /* No internal symbols read? Skip this BFD. */
3299 if (isymbuf == NULL)
3302 for (i = 0; i < localsyms; i++)
3304 Elf_Internal_Sym *isym = &isymbuf[i];
3305 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3309 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3311 name = bfd_elf_string_from_elf_section (abfd,
3312 hdr->sh_link, isym->st_name);
3314 if (bfd_is_arm_special_symbol_name (name,
3315 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
3316 elf32_arm_section_map_add (sec, name[1], isym->st_value);
3323 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
3325 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3326 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
3328 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
3329 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
3331 switch (globals->vfp11_fix)
3333 case BFD_ARM_VFP11_FIX_DEFAULT:
3334 case BFD_ARM_VFP11_FIX_NONE:
3335 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3339 /* Give a warning, but do as the user requests anyway. */
3340 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
3341 "workaround is not necessary for target architecture"), obfd);
3344 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
3345 /* For earlier architectures, we might need the workaround, but do not
3346 enable it by default. If users is running with broken hardware, they
3347 must enable the erratum fix explicitly. */
3348 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3352 enum bfd_arm_vfp11_pipe {
3359 /* Return a VFP register number. This is encoded as RX:X for single-precision
3360 registers, or X:RX for double-precision registers, where RX is the group of
3361 four bits in the instruction encoding and X is the single extension bit.
3362 RX and X fields are specified using their lowest (starting) bit. The return
3365 0...31: single-precision registers s0...s31
3366 32...63: double-precision registers d0...d31.
3368 Although X should be zero for VFP11 (encoding d0...d15 only), we might
3369 encounter VFP3 instructions, so we allow the full range for DP registers. */
3372 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
3376 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
3378 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
3381 /* Set bits in *WMASK according to a register number REG as encoded by
3382 bfd_arm_vfp11_regno(). Ignore d16-d31. */
3385 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
3390 *wmask |= 3 << ((reg - 32) * 2);
3393 /* Return TRUE if WMASK overwrites anything in REGS. */
3396 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
3400 for (i = 0; i < numregs; i++)
3402 unsigned int reg = regs[i];
3404 if (reg < 32 && (wmask & (1 << reg)) != 0)
3412 if ((wmask & (3 << (reg * 2))) != 0)
3419 /* In this function, we're interested in two things: finding input registers
3420 for VFP data-processing instructions, and finding the set of registers which
3421 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
3422 hold the written set, so FLDM etc. are easy to deal with (we're only
3423 interested in 32 SP registers or 16 dp registers, due to the VFP version
3424 implemented by the chip in question). DP registers are marked by setting
3425 both SP registers in the write mask). */
3427 static enum bfd_arm_vfp11_pipe
3428 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
3431 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
3432 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
3434 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
3437 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3438 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3440 pqrs = ((insn & 0x00800000) >> 20)
3441 | ((insn & 0x00300000) >> 19)
3442 | ((insn & 0x00000040) >> 6);
3446 case 0: /* fmac[sd]. */
3447 case 1: /* fnmac[sd]. */
3448 case 2: /* fmsc[sd]. */
3449 case 3: /* fnmsc[sd]. */
3451 bfd_arm_vfp11_write_mask (destmask, fd);
3453 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3458 case 4: /* fmul[sd]. */
3459 case 5: /* fnmul[sd]. */
3460 case 6: /* fadd[sd]. */
3461 case 7: /* fsub[sd]. */
3465 case 8: /* fdiv[sd]. */
3468 bfd_arm_vfp11_write_mask (destmask, fd);
3469 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3474 case 15: /* extended opcode. */
3476 unsigned int extn = ((insn >> 15) & 0x1e)
3477 | ((insn >> 7) & 1);
3481 case 0: /* fcpy[sd]. */
3482 case 1: /* fabs[sd]. */
3483 case 2: /* fneg[sd]. */
3484 case 8: /* fcmp[sd]. */
3485 case 9: /* fcmpe[sd]. */
3486 case 10: /* fcmpz[sd]. */
3487 case 11: /* fcmpez[sd]. */
3488 case 16: /* fuito[sd]. */
3489 case 17: /* fsito[sd]. */
3490 case 24: /* ftoui[sd]. */
3491 case 25: /* ftouiz[sd]. */
3492 case 26: /* ftosi[sd]. */
3493 case 27: /* ftosiz[sd]. */
3494 /* These instructions will not bounce due to underflow. */
3499 case 3: /* fsqrt[sd]. */
3500 /* fsqrt cannot underflow, but it can (perhaps) overwrite
3501 registers to cause the erratum in previous instructions. */
3502 bfd_arm_vfp11_write_mask (destmask, fd);
3506 case 15: /* fcvt{ds,sd}. */
3510 bfd_arm_vfp11_write_mask (destmask, fd);
3512 /* Only FCVTSD can underflow. */
3513 if ((insn & 0x100) != 0)
3532 /* Two-register transfer. */
3533 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
3535 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3537 if ((insn & 0x100000) == 0)
3540 bfd_arm_vfp11_write_mask (destmask, fm);
3543 bfd_arm_vfp11_write_mask (destmask, fm);
3544 bfd_arm_vfp11_write_mask (destmask, fm + 1);
3550 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
3552 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3553 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
3557 case 0: /* Two-reg transfer. We should catch these above. */
3560 case 2: /* fldm[sdx]. */
3564 unsigned int i, offset = insn & 0xff;
3569 for (i = fd; i < fd + offset; i++)
3570 bfd_arm_vfp11_write_mask (destmask, i);
3574 case 4: /* fld[sd]. */
3576 bfd_arm_vfp11_write_mask (destmask, fd);
3585 /* Single-register transfer. Note L==0. */
3586 else if ((insn & 0x0f100e10) == 0x0e000a10)
3588 unsigned int opcode = (insn >> 21) & 7;
3589 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
3593 case 0: /* fmsr/fmdlr. */
3594 case 1: /* fmdhr. */
3595 /* Mark fmdhr and fmdlr as writing to the whole of the DP
3596 destination register. I don't know if this is exactly right,
3597 but it is the conservative choice. */
3598 bfd_arm_vfp11_write_mask (destmask, fn);
3612 static int elf32_arm_compare_mapping (const void * a, const void * b);
3615 /* Look for potentially-troublesome code sequences which might trigger the
3616 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
3617 (available from ARM) for details of the erratum. A short version is
3618 described in ld.texinfo. */
3621 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
3624 bfd_byte *contents = NULL;
3626 int regs[3], numregs = 0;
3627 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3628 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
3630 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
3631 The states transition as follows:
3633 0 -> 1 (vector) or 0 -> 2 (scalar)
3634 A VFP FMAC-pipeline instruction has been seen. Fill
3635 regs[0]..regs[numregs-1] with its input operands. Remember this
3636 instruction in 'first_fmac'.
3639 Any instruction, except for a VFP instruction which overwrites
3644 A VFP instruction has been seen which overwrites any of regs[*].
3645 We must make a veneer! Reset state to 0 before examining next
3649 If we fail to match anything in state 2, reset to state 0 and reset
3650 the instruction pointer to the instruction after 'first_fmac'.
3652 If the VFP11 vector mode is in use, there must be at least two unrelated
3653 instructions between anti-dependent VFP11 instructions to properly avoid
3654 triggering the erratum, hence the use of the extra state 1.
3657 /* If we are only performing a partial link do not bother
3658 to construct any glue. */
3659 if (link_info->relocatable)
3662 /* We should have chosen a fix type by the time we get here. */
3663 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
3665 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
3668 /* Skip if this bfd does not correspond to an ELF image. */
3669 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3672 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3674 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
3675 struct _arm_elf_section_data *sec_data;
3677 /* If we don't have executable progbits, we're not interested in this
3678 section. Also skip if section is to be excluded. */
3679 if (elf_section_type (sec) != SHT_PROGBITS
3680 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
3681 || (sec->flags & SEC_EXCLUDE) != 0
3682 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
3685 sec_data = elf32_arm_section_data (sec);
3687 if (sec_data->mapcount == 0)
3690 if (elf_section_data (sec)->this_hdr.contents != NULL)
3691 contents = elf_section_data (sec)->this_hdr.contents;
3692 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3695 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
3696 elf32_arm_compare_mapping);
3698 for (span = 0; span < sec_data->mapcount; span++)
3700 unsigned int span_start = sec_data->map[span].vma;
3701 unsigned int span_end = (span == sec_data->mapcount - 1)
3702 ? sec->size : sec_data->map[span + 1].vma;
3703 char span_type = sec_data->map[span].type;
3705 /* FIXME: Only ARM mode is supported at present. We may need to
3706 support Thumb-2 mode also at some point. */
3707 if (span_type != 'a')
3710 for (i = span_start; i < span_end;)
3712 unsigned int next_i = i + 4;
3713 unsigned int insn = bfd_big_endian (abfd)
3714 ? (contents[i] << 24)
3715 | (contents[i + 1] << 16)
3716 | (contents[i + 2] << 8)
3718 : (contents[i + 3] << 24)
3719 | (contents[i + 2] << 16)
3720 | (contents[i + 1] << 8)
3722 unsigned int writemask = 0;
3723 enum bfd_arm_vfp11_pipe pipe;
3728 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
3730 /* I'm assuming the VFP11 erratum can trigger with denorm
3731 operands on either the FMAC or the DS pipeline. This might
3732 lead to slightly overenthusiastic veneer insertion. */
3733 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
3735 state = use_vector ? 1 : 2;
3737 veneer_of_insn = insn;
3743 int other_regs[3], other_numregs;
3744 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3747 if (pipe != VFP11_BAD
3748 && bfd_arm_vfp11_antidependency (writemask, regs,
3758 int other_regs[3], other_numregs;
3759 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3762 if (pipe != VFP11_BAD
3763 && bfd_arm_vfp11_antidependency (writemask, regs,
3769 next_i = first_fmac + 4;
3775 abort (); /* Should be unreachable. */
3780 elf32_vfp11_erratum_list *newerr
3781 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
3784 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
3786 newerr->u.b.vfp_insn = veneer_of_insn;
3791 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
3798 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
3803 newerr->next = sec_data->erratumlist;
3804 sec_data->erratumlist = newerr;
3813 if (contents != NULL
3814 && elf_section_data (sec)->this_hdr.contents != contents)
3822 if (contents != NULL
3823 && elf_section_data (sec)->this_hdr.contents != contents)
3829 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
3830 after sections have been laid out, using specially-named symbols. */
3833 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
3834 struct bfd_link_info *link_info)
3837 struct elf32_arm_link_hash_table *globals;
3840 if (link_info->relocatable)
3843 /* Skip if this bfd does not correspond to an ELF image. */
3844 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3847 globals = elf32_arm_hash_table (link_info);
3849 tmp_name = bfd_malloc ((bfd_size_type) strlen
3850 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
3852 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3854 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
3855 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
3857 for (; errnode != NULL; errnode = errnode->next)
3859 struct elf_link_hash_entry *myh;
3862 switch (errnode->type)
3864 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
3865 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
3866 /* Find veneer symbol. */
3867 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
3868 errnode->u.b.veneer->u.v.id);
3870 myh = elf_link_hash_lookup
3871 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3874 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3875 "`%s'"), abfd, tmp_name);
3877 vma = myh->root.u.def.section->output_section->vma
3878 + myh->root.u.def.section->output_offset
3879 + myh->root.u.def.value;
3881 errnode->u.b.veneer->vma = vma;
3884 case VFP11_ERRATUM_ARM_VENEER:
3885 case VFP11_ERRATUM_THUMB_VENEER:
3886 /* Find return location. */
3887 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
3890 myh = elf_link_hash_lookup
3891 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3894 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3895 "`%s'"), abfd, tmp_name);
3897 vma = myh->root.u.def.section->output_section->vma
3898 + myh->root.u.def.section->output_offset
3899 + myh->root.u.def.value;
3901 errnode->u.v.branch->vma = vma;
3914 /* Set target relocation values needed during linking. */
3917 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
3918 struct bfd_link_info *link_info,
3920 char * target2_type,
3923 bfd_arm_vfp11_fix vfp11_fix,
3924 int no_enum_warn, int pic_veneer)
3926 struct elf32_arm_link_hash_table *globals;
3928 globals = elf32_arm_hash_table (link_info);
3930 globals->target1_is_rel = target1_is_rel;
3931 if (strcmp (target2_type, "rel") == 0)
3932 globals->target2_reloc = R_ARM_REL32;
3933 else if (strcmp (target2_type, "abs") == 0)
3934 globals->target2_reloc = R_ARM_ABS32;
3935 else if (strcmp (target2_type, "got-rel") == 0)
3936 globals->target2_reloc = R_ARM_GOT_PREL;
3939 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3942 globals->fix_v4bx = fix_v4bx;
3943 globals->use_blx |= use_blx;
3944 globals->vfp11_fix = vfp11_fix;
3945 globals->pic_veneer = pic_veneer;
3947 elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
3950 /* The thumb form of a long branch is a bit finicky, because the offset
3951 encoding is split over two fields, each in it's own instruction. They
3952 can occur in any order. So given a thumb form of long branch, and an
3953 offset, insert the offset into the thumb branch and return finished
3956 It takes two thumb instructions to encode the target address. Each has
3957 11 bits to invest. The upper 11 bits are stored in one (identified by
3958 H-0.. see below), the lower 11 bits are stored in the other (identified
3961 Combine together and shifted left by 1 (it's a half word address) and
3965 H-0, upper address-0 = 000
3967 H-1, lower address-0 = 800
3969 They can be ordered either way, but the arm tools I've seen always put
3970 the lower one first. It probably doesn't matter. krk@cygnus.com
3972 XXX: Actually the order does matter. The second instruction (H-1)
3973 moves the computed address into the PC, so it must be the second one
3974 in the sequence. The problem, however is that whilst little endian code
3975 stores the instructions in HI then LOW order, big endian code does the
3976 reverse. nickc@cygnus.com. */
3978 #define LOW_HI_ORDER 0xF800F000
3979 #define HI_LOW_ORDER 0xF000F800
3982 insert_thumb_branch (insn32 br_insn, int rel_off)
3984 unsigned int low_bits;
3985 unsigned int high_bits;
3987 BFD_ASSERT ((rel_off & 1) != 1);
3989 rel_off >>= 1; /* Half word aligned address. */
3990 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
3991 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
3993 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3994 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3995 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3996 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3998 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3999 abort (); /* Error - not a valid branch instruction form. */
4005 /* Store an Arm insn into an output section not processed by
4006 elf32_arm_write_section. */
4009 put_arm_insn (struct elf32_arm_link_hash_table *htab,
4010 bfd * output_bfd, bfd_vma val, void * ptr)
4012 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4013 bfd_putl32 (val, ptr);
4015 bfd_putb32 (val, ptr);
4019 /* Store a 16-bit Thumb insn into an output section not processed by
4020 elf32_arm_write_section. */
4023 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
4024 bfd * output_bfd, bfd_vma val, void * ptr)
4026 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4027 bfd_putl16 (val, ptr);
4029 bfd_putb16 (val, ptr);
4033 /* Thumb code calling an ARM function. */
4036 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
4040 asection * input_section,
4041 bfd_byte * hit_data,
4044 bfd_signed_vma addend,
4046 char **error_message)
4050 unsigned long int tmp;
4051 long int ret_offset;
4052 struct elf_link_hash_entry * myh;
4053 struct elf32_arm_link_hash_table * globals;
4055 myh = find_thumb_glue (info, name, error_message);
4059 globals = elf32_arm_hash_table (info);
4061 BFD_ASSERT (globals != NULL);
4062 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4064 my_offset = myh->root.u.def.value;
4066 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4067 THUMB2ARM_GLUE_SECTION_NAME);
4069 BFD_ASSERT (s != NULL);
4070 BFD_ASSERT (s->contents != NULL);
4071 BFD_ASSERT (s->output_section != NULL);
4073 if ((my_offset & 0x01) == 0x01)
4076 && sym_sec->owner != NULL
4077 && !INTERWORK_FLAG (sym_sec->owner))
4079 (*_bfd_error_handler)
4080 (_("%B(%s): warning: interworking not enabled.\n"
4081 " first occurrence: %B: thumb call to arm"),
4082 sym_sec->owner, input_bfd, name);
4088 myh->root.u.def.value = my_offset;
4090 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
4091 s->contents + my_offset);
4093 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
4094 s->contents + my_offset + 2);
4097 /* Address of destination of the stub. */
4098 ((bfd_signed_vma) val)
4100 /* Offset from the start of the current section
4101 to the start of the stubs. */
4103 /* Offset of the start of this stub from the start of the stubs. */
4105 /* Address of the start of the current section. */
4106 + s->output_section->vma)
4107 /* The branch instruction is 4 bytes into the stub. */
4109 /* ARM branches work from the pc of the instruction + 8. */
4112 put_arm_insn (globals, output_bfd,
4113 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
4114 s->contents + my_offset + 4);
4117 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
4119 /* Now go back and fix up the original BL insn to point to here. */
4121 /* Address of where the stub is located. */
4122 (s->output_section->vma + s->output_offset + my_offset)
4123 /* Address of where the BL is located. */
4124 - (input_section->output_section->vma + input_section->output_offset
4126 /* Addend in the relocation. */
4128 /* Biassing for PC-relative addressing. */
4131 tmp = bfd_get_32 (input_bfd, hit_data
4132 - input_section->vma);
4134 bfd_put_32 (output_bfd,
4135 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
4136 hit_data - input_section->vma);
4141 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
4143 static struct elf_link_hash_entry *
4144 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
4151 char **error_message)
4154 long int ret_offset;
4155 struct elf_link_hash_entry * myh;
4156 struct elf32_arm_link_hash_table * globals;
4158 myh = find_arm_glue (info, name, error_message);
4162 globals = elf32_arm_hash_table (info);
4164 BFD_ASSERT (globals != NULL);
4165 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4167 my_offset = myh->root.u.def.value;
4169 if ((my_offset & 0x01) == 0x01)
4172 && sym_sec->owner != NULL
4173 && !INTERWORK_FLAG (sym_sec->owner))
4175 (*_bfd_error_handler)
4176 (_("%B(%s): warning: interworking not enabled.\n"
4177 " first occurrence: %B: arm call to thumb"),
4178 sym_sec->owner, input_bfd, name);
4182 myh->root.u.def.value = my_offset;
4184 if (info->shared || globals->root.is_relocatable_executable
4185 || globals->pic_veneer)
4187 /* For relocatable objects we can't use absolute addresses,
4188 so construct the address from a relative offset. */
4189 /* TODO: If the offset is small it's probably worth
4190 constructing the address with adds. */
4191 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
4192 s->contents + my_offset);
4193 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
4194 s->contents + my_offset + 4);
4195 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
4196 s->contents + my_offset + 8);
4197 /* Adjust the offset by 4 for the position of the add,
4198 and 8 for the pipeline offset. */
4199 ret_offset = (val - (s->output_offset
4200 + s->output_section->vma
4203 bfd_put_32 (output_bfd, ret_offset,
4204 s->contents + my_offset + 12);
4206 else if (globals->use_blx)
4208 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
4209 s->contents + my_offset);
4211 /* It's a thumb address. Add the low order bit. */
4212 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
4213 s->contents + my_offset + 4);
4217 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
4218 s->contents + my_offset);
4220 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
4221 s->contents + my_offset + 4);
4223 /* It's a thumb address. Add the low order bit. */
4224 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
4225 s->contents + my_offset + 8);
4229 BFD_ASSERT (my_offset <= globals->arm_glue_size);
4234 /* Arm code calling a Thumb function. */
4237 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
4241 asection * input_section,
4242 bfd_byte * hit_data,
4245 bfd_signed_vma addend,
4247 char **error_message)
4249 unsigned long int tmp;
4252 long int ret_offset;
4253 struct elf_link_hash_entry * myh;
4254 struct elf32_arm_link_hash_table * globals;
4256 globals = elf32_arm_hash_table (info);
4258 BFD_ASSERT (globals != NULL);
4259 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4261 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4262 ARM2THUMB_GLUE_SECTION_NAME);
4263 BFD_ASSERT (s != NULL);
4264 BFD_ASSERT (s->contents != NULL);
4265 BFD_ASSERT (s->output_section != NULL);
4267 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
4268 sym_sec, val, s, error_message);
4272 my_offset = myh->root.u.def.value;
4273 tmp = bfd_get_32 (input_bfd, hit_data);
4274 tmp = tmp & 0xFF000000;
4276 /* Somehow these are both 4 too far, so subtract 8. */
4277 ret_offset = (s->output_offset
4279 + s->output_section->vma
4280 - (input_section->output_offset
4281 + input_section->output_section->vma
4285 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
4287 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
4292 /* Populate Arm stub for an exported Thumb function. */
4295 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
4297 struct bfd_link_info * info = (struct bfd_link_info *) inf;
4299 struct elf_link_hash_entry * myh;
4300 struct elf32_arm_link_hash_entry *eh;
4301 struct elf32_arm_link_hash_table * globals;
4304 char *error_message;
4306 eh = elf32_arm_hash_entry(h);
4307 /* Allocate stubs for exported Thumb functions on v4t. */
4308 if (eh->export_glue == NULL)
4311 globals = elf32_arm_hash_table (info);
4313 BFD_ASSERT (globals != NULL);
4314 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4316 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4317 ARM2THUMB_GLUE_SECTION_NAME);
4318 BFD_ASSERT (s != NULL);
4319 BFD_ASSERT (s->contents != NULL);
4320 BFD_ASSERT (s->output_section != NULL);
4322 sec = eh->export_glue->root.u.def.section;
4324 BFD_ASSERT (sec->output_section != NULL);
4326 val = eh->export_glue->root.u.def.value + sec->output_offset
4327 + sec->output_section->vma;
4328 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
4329 h->root.u.def.section->owner,
4330 globals->obfd, sec, val, s,
4336 /* Generate Arm stubs for exported Thumb symbols. */
4338 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
4339 struct bfd_link_info *link_info)
4341 struct elf32_arm_link_hash_table * globals;
4346 globals = elf32_arm_hash_table (link_info);
4347 /* If blx is available then exported Thumb symbols are OK and there is
4349 if (globals->use_blx)
4352 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
4356 /* Some relocations map to different relocations depending on the
4357 target. Return the real relocation. */
4359 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
4365 if (globals->target1_is_rel)
4371 return globals->target2_reloc;
4378 /* Return the base VMA address which should be subtracted from real addresses
4379 when resolving @dtpoff relocation.
4380 This is PT_TLS segment p_vaddr. */
4383 dtpoff_base (struct bfd_link_info *info)
4385 /* If tls_sec is NULL, we should have signalled an error already. */
4386 if (elf_hash_table (info)->tls_sec == NULL)
4388 return elf_hash_table (info)->tls_sec->vma;
4391 /* Return the relocation value for @tpoff relocation
4392 if STT_TLS virtual address is ADDRESS. */
4395 tpoff (struct bfd_link_info *info, bfd_vma address)
4397 struct elf_link_hash_table *htab = elf_hash_table (info);
4400 /* If tls_sec is NULL, we should have signalled an error already. */
4401 if (htab->tls_sec == NULL)
4403 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
4404 return address - htab->tls_sec->vma + base;
4407 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
4408 VALUE is the relocation value. */
4410 static bfd_reloc_status_type
4411 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
4414 return bfd_reloc_overflow;
4416 value |= bfd_get_32 (abfd, data) & 0xfffff000;
4417 bfd_put_32 (abfd, value, data);
4418 return bfd_reloc_ok;
4421 /* For a given value of n, calculate the value of G_n as required to
4422 deal with group relocations. We return it in the form of an
4423 encoded constant-and-rotation, together with the final residual. If n is
4424 specified as less than zero, then final_residual is filled with the
4425 input value and no further action is performed. */
4428 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
4432 bfd_vma encoded_g_n = 0;
4433 bfd_vma residual = value; /* Also known as Y_n. */
4435 for (current_n = 0; current_n <= n; current_n++)
4439 /* Calculate which part of the value to mask. */
4446 /* Determine the most significant bit in the residual and
4447 align the resulting value to a 2-bit boundary. */
4448 for (msb = 30; msb >= 0; msb -= 2)
4449 if (residual & (3 << msb))
4452 /* The desired shift is now (msb - 6), or zero, whichever
4459 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
4460 g_n = residual & (0xff << shift);
4461 encoded_g_n = (g_n >> shift)
4462 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
4464 /* Calculate the residual for the next time around. */
4468 *final_residual = residual;
4473 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
4474 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
4476 identify_add_or_sub(bfd_vma insn)
4478 int opcode = insn & 0x1e00000;
4480 if (opcode == 1 << 23) /* ADD */
4483 if (opcode == 1 << 22) /* SUB */
4489 /* Determine if we're dealing with a Thumb-2 object. */
4491 static int using_thumb2 (struct elf32_arm_link_hash_table *globals)
4493 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4495 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
4498 /* Perform a relocation as part of a final link. */
4500 static bfd_reloc_status_type
4501 elf32_arm_final_link_relocate (reloc_howto_type * howto,
4504 asection * input_section,
4505 bfd_byte * contents,
4506 Elf_Internal_Rela * rel,
4508 struct bfd_link_info * info,
4510 const char * sym_name,
4512 struct elf_link_hash_entry * h,
4513 bfd_boolean * unresolved_reloc_p,
4514 char **error_message)
4516 unsigned long r_type = howto->type;
4517 unsigned long r_symndx;
4518 bfd_byte * hit_data = contents + rel->r_offset;
4519 bfd * dynobj = NULL;
4520 Elf_Internal_Shdr * symtab_hdr;
4521 struct elf_link_hash_entry ** sym_hashes;
4522 bfd_vma * local_got_offsets;
4523 asection * sgot = NULL;
4524 asection * splt = NULL;
4525 asection * sreloc = NULL;
4527 bfd_signed_vma signed_addend;
4528 struct elf32_arm_link_hash_table * globals;
4530 globals = elf32_arm_hash_table (info);
4532 /* Some relocation type map to different relocations depending on the
4533 target. We pick the right one here. */
4534 r_type = arm_real_reloc_type (globals, r_type);
4535 if (r_type != howto->type)
4536 howto = elf32_arm_howto_from_type (r_type);
4538 /* If the start address has been set, then set the EF_ARM_HASENTRY
4539 flag. Setting this more than once is redundant, but the cost is
4540 not too high, and it keeps the code simple.
4542 The test is done here, rather than somewhere else, because the
4543 start address is only set just before the final link commences.
4545 Note - if the user deliberately sets a start address of 0, the
4546 flag will not be set. */
4547 if (bfd_get_start_address (output_bfd) != 0)
4548 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
4550 dynobj = elf_hash_table (info)->dynobj;
4553 sgot = bfd_get_section_by_name (dynobj, ".got");
4554 splt = bfd_get_section_by_name (dynobj, ".plt");
4556 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4557 sym_hashes = elf_sym_hashes (input_bfd);
4558 local_got_offsets = elf_local_got_offsets (input_bfd);
4559 r_symndx = ELF32_R_SYM (rel->r_info);
4561 if (globals->use_rel)
4563 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
4565 if (addend & ((howto->src_mask + 1) >> 1))
4568 signed_addend &= ~ howto->src_mask;
4569 signed_addend |= addend;
4572 signed_addend = addend;
4575 addend = signed_addend = rel->r_addend;
4580 /* We don't need to find a value for this symbol. It's just a
4582 *unresolved_reloc_p = FALSE;
4583 return bfd_reloc_ok;
4586 if (!globals->vxworks_p)
4587 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4591 case R_ARM_ABS32_NOI:
4593 case R_ARM_REL32_NOI:
4599 /* Handle relocations which should use the PLT entry. ABS32/REL32
4600 will use the symbol's value, which may point to a PLT entry, but we
4601 don't need to handle that here. If we created a PLT entry, all
4602 branches in this object should go to it. */
4603 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
4604 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
4607 && h->plt.offset != (bfd_vma) -1)
4609 /* If we've created a .plt section, and assigned a PLT entry to
4610 this function, it should not be known to bind locally. If
4611 it were, we would have cleared the PLT entry. */
4612 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
4614 value = (splt->output_section->vma
4615 + splt->output_offset
4617 *unresolved_reloc_p = FALSE;
4618 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4619 contents, rel->r_offset, value,
4623 /* When generating a shared object or relocatable executable, these
4624 relocations are copied into the output file to be resolved at
4626 if ((info->shared || globals->root.is_relocatable_executable)
4627 && (input_section->flags & SEC_ALLOC)
4628 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
4629 || !SYMBOL_CALLS_LOCAL (info, h))
4631 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4632 || h->root.type != bfd_link_hash_undefweak)
4633 && r_type != R_ARM_PC24
4634 && r_type != R_ARM_CALL
4635 && r_type != R_ARM_JUMP24
4636 && r_type != R_ARM_PREL31
4637 && r_type != R_ARM_PLT32)
4639 Elf_Internal_Rela outrel;
4641 bfd_boolean skip, relocate;
4643 *unresolved_reloc_p = FALSE;
4649 name = (bfd_elf_string_from_elf_section
4651 elf_elfheader (input_bfd)->e_shstrndx,
4652 elf_section_data (input_section)->rel_hdr.sh_name));
4654 return bfd_reloc_notsupported;
4656 BFD_ASSERT (reloc_section_p (globals, name, input_section));
4658 sreloc = bfd_get_section_by_name (dynobj, name);
4659 BFD_ASSERT (sreloc != NULL);
4665 outrel.r_addend = addend;
4667 _bfd_elf_section_offset (output_bfd, info, input_section,
4669 if (outrel.r_offset == (bfd_vma) -1)
4671 else if (outrel.r_offset == (bfd_vma) -2)
4672 skip = TRUE, relocate = TRUE;
4673 outrel.r_offset += (input_section->output_section->vma
4674 + input_section->output_offset);
4677 memset (&outrel, 0, sizeof outrel);
4682 || !h->def_regular))
4683 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4688 /* This symbol is local, or marked to become local. */
4689 if (sym_flags == STT_ARM_TFUNC)
4691 if (globals->symbian_p)
4695 /* On Symbian OS, the data segment and text segement
4696 can be relocated independently. Therefore, we
4697 must indicate the segment to which this
4698 relocation is relative. The BPABI allows us to
4699 use any symbol in the right segment; we just use
4700 the section symbol as it is convenient. (We
4701 cannot use the symbol given by "h" directly as it
4702 will not appear in the dynamic symbol table.)
4704 Note that the dynamic linker ignores the section
4705 symbol value, so we don't subtract osec->vma
4706 from the emitted reloc addend. */
4708 osec = sym_sec->output_section;
4710 osec = input_section->output_section;
4711 symbol = elf_section_data (osec)->dynindx;
4714 struct elf_link_hash_table *htab = elf_hash_table (info);
4716 if ((osec->flags & SEC_READONLY) == 0
4717 && htab->data_index_section != NULL)
4718 osec = htab->data_index_section;
4720 osec = htab->text_index_section;
4721 symbol = elf_section_data (osec)->dynindx;
4723 BFD_ASSERT (symbol != 0);
4726 /* On SVR4-ish systems, the dynamic loader cannot
4727 relocate the text and data segments independently,
4728 so the symbol does not matter. */
4730 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
4731 if (globals->use_rel)
4734 outrel.r_addend += value;
4737 loc = sreloc->contents;
4738 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
4739 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4741 /* If this reloc is against an external symbol, we do not want to
4742 fiddle with the addend. Otherwise, we need to include the symbol
4743 value so that it becomes an addend for the dynamic reloc. */
4745 return bfd_reloc_ok;
4747 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4748 contents, rel->r_offset, value,
4751 else switch (r_type)
4754 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4756 case R_ARM_XPC25: /* Arm BLX instruction. */
4759 case R_ARM_PC24: /* Arm B/BL instruction */
4761 if (r_type == R_ARM_XPC25)
4763 /* Check for Arm calling Arm function. */
4764 /* FIXME: Should we translate the instruction into a BL
4765 instruction instead ? */
4766 if (sym_flags != STT_ARM_TFUNC)
4767 (*_bfd_error_handler)
4768 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
4770 h ? h->root.root.string : "(local)");
4772 else if (r_type != R_ARM_CALL || !globals->use_blx)
4774 /* Check for Arm calling Thumb function. */
4775 if (sym_flags == STT_ARM_TFUNC)
4777 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
4778 output_bfd, input_section,
4779 hit_data, sym_sec, rel->r_offset,
4780 signed_addend, value,
4782 return bfd_reloc_ok;
4784 return bfd_reloc_dangerous;
4788 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
4790 S is the address of the symbol in the relocation.
4791 P is address of the instruction being relocated.
4792 A is the addend (extracted from the instruction) in bytes.
4794 S is held in 'value'.
4795 P is the base address of the section containing the
4796 instruction plus the offset of the reloc into that
4798 (input_section->output_section->vma +
4799 input_section->output_offset +
4801 A is the addend, converted into bytes, ie:
4804 Note: None of these operations have knowledge of the pipeline
4805 size of the processor, thus it is up to the assembler to
4806 encode this information into the addend. */
4807 value -= (input_section->output_section->vma
4808 + input_section->output_offset);
4809 value -= rel->r_offset;
4810 if (globals->use_rel)
4811 value += (signed_addend << howto->size);
4813 /* RELA addends do not have to be adjusted by howto->size. */
4814 value += signed_addend;
4816 signed_addend = value;
4817 signed_addend >>= howto->rightshift;
4819 /* A branch to an undefined weak symbol is turned into a jump to
4820 the next instruction. */
4821 if (h && h->root.type == bfd_link_hash_undefweak)
4823 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
4828 /* Perform a signed range check. */
4829 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
4830 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
4831 return bfd_reloc_overflow;
4833 addend = (value & 2);
4835 value = (signed_addend & howto->dst_mask)
4836 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
4838 /* Set the H bit in the BLX instruction. */
4839 if (sym_flags == STT_ARM_TFUNC)
4844 value &= ~(bfd_vma)(1 << 24);
4846 if (r_type == R_ARM_CALL)
4848 /* Select the correct instruction (BL or BLX). */
4849 if (sym_flags == STT_ARM_TFUNC)
4853 value &= ~(bfd_vma)(1 << 28);
4862 if (sym_flags == STT_ARM_TFUNC)
4866 case R_ARM_ABS32_NOI:
4872 if (sym_flags == STT_ARM_TFUNC)
4874 value -= (input_section->output_section->vma
4875 + input_section->output_offset + rel->r_offset);
4878 case R_ARM_REL32_NOI:
4880 value -= (input_section->output_section->vma
4881 + input_section->output_offset + rel->r_offset);
4885 value -= (input_section->output_section->vma
4886 + input_section->output_offset + rel->r_offset);
4887 value += signed_addend;
4888 if (! h || h->root.type != bfd_link_hash_undefweak)
4890 /* Check for overflow */
4891 if ((value ^ (value >> 1)) & (1 << 30))
4892 return bfd_reloc_overflow;
4894 value &= 0x7fffffff;
4895 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
4896 if (sym_flags == STT_ARM_TFUNC)
4901 bfd_put_32 (input_bfd, value, hit_data);
4902 return bfd_reloc_ok;
4906 if ((long) value > 0x7f || (long) value < -0x80)
4907 return bfd_reloc_overflow;
4909 bfd_put_8 (input_bfd, value, hit_data);
4910 return bfd_reloc_ok;
4915 if ((long) value > 0x7fff || (long) value < -0x8000)
4916 return bfd_reloc_overflow;
4918 bfd_put_16 (input_bfd, value, hit_data);
4919 return bfd_reloc_ok;
4921 case R_ARM_THM_ABS5:
4922 /* Support ldr and str instructions for the thumb. */
4923 if (globals->use_rel)
4925 /* Need to refetch addend. */
4926 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4927 /* ??? Need to determine shift amount from operand size. */
4928 addend >>= howto->rightshift;
4932 /* ??? Isn't value unsigned? */
4933 if ((long) value > 0x1f || (long) value < -0x10)
4934 return bfd_reloc_overflow;
4936 /* ??? Value needs to be properly shifted into place first. */
4937 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4938 bfd_put_16 (input_bfd, value, hit_data);
4939 return bfd_reloc_ok;
4941 case R_ARM_THM_ALU_PREL_11_0:
4942 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
4945 bfd_signed_vma relocation;
4947 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4948 | bfd_get_16 (input_bfd, hit_data + 2);
4950 if (globals->use_rel)
4952 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4953 | ((insn & (1 << 26)) >> 15);
4954 if (insn & 0xf00000)
4955 signed_addend = -signed_addend;
4958 relocation = value + signed_addend;
4959 relocation -= (input_section->output_section->vma
4960 + input_section->output_offset
4963 value = llabs (relocation);
4965 if (value >= 0x1000)
4966 return bfd_reloc_overflow;
4968 insn = (insn & 0xfb0f8f00) | (value & 0xff)
4969 | ((value & 0x700) << 4)
4970 | ((value & 0x800) << 15);
4974 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4975 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4977 return bfd_reloc_ok;
4980 case R_ARM_THM_PC12:
4981 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4984 bfd_signed_vma relocation;
4986 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4987 | bfd_get_16 (input_bfd, hit_data + 2);
4989 if (globals->use_rel)
4991 signed_addend = insn & 0xfff;
4992 if (!(insn & (1 << 23)))
4993 signed_addend = -signed_addend;
4996 relocation = value + signed_addend;
4997 relocation -= (input_section->output_section->vma
4998 + input_section->output_offset
5001 value = llabs (relocation);
5003 if (value >= 0x1000)
5004 return bfd_reloc_overflow;
5006 insn = (insn & 0xff7ff000) | value;
5007 if (relocation >= 0)
5010 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5011 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5013 return bfd_reloc_ok;
5016 case R_ARM_THM_XPC22:
5017 case R_ARM_THM_CALL:
5018 /* Thumb BL (branch long instruction). */
5022 bfd_boolean overflow = FALSE;
5023 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5024 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5025 bfd_signed_vma reloc_signed_max;
5026 bfd_signed_vma reloc_signed_min;
5028 bfd_signed_vma signed_check;
5030 int thumb2 = using_thumb2 (globals);
5032 /* A branch to an undefined weak symbol is turned into a jump to
5033 the next instruction. */
5034 if (h && h->root.type == bfd_link_hash_undefweak)
5036 bfd_put_16 (input_bfd, 0xe000, hit_data);
5037 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
5038 return bfd_reloc_ok;
5041 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
5042 with Thumb-1) involving the J1 and J2 bits. */
5043 if (globals->use_rel)
5045 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
5046 bfd_vma upper = upper_insn & 0x3ff;
5047 bfd_vma lower = lower_insn & 0x7ff;
5048 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
5049 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
5050 bfd_vma i1 = j1 ^ s ? 0 : 1;
5051 bfd_vma i2 = j2 ^ s ? 0 : 1;
5053 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
5055 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
5057 signed_addend = addend;
5060 if (r_type == R_ARM_THM_XPC22)
5062 /* Check for Thumb to Thumb call. */
5063 /* FIXME: Should we translate the instruction into a BL
5064 instruction instead ? */
5065 if (sym_flags == STT_ARM_TFUNC)
5066 (*_bfd_error_handler)
5067 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
5069 h ? h->root.root.string : "(local)");
5073 /* If it is not a call to Thumb, assume call to Arm.
5074 If it is a call relative to a section name, then it is not a
5075 function call at all, but rather a long jump. Calls through
5076 the PLT do not require stubs. */
5077 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
5078 && (h == NULL || splt == NULL
5079 || h->plt.offset == (bfd_vma) -1))
5081 if (globals->use_blx)
5083 /* Convert BL to BLX. */
5084 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5086 else if (elf32_thumb_to_arm_stub
5087 (info, sym_name, input_bfd, output_bfd, input_section,
5088 hit_data, sym_sec, rel->r_offset, signed_addend, value,
5090 return bfd_reloc_ok;
5092 return bfd_reloc_dangerous;
5094 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
5096 /* Make sure this is a BL. */
5097 lower_insn |= 0x1800;
5101 /* Handle calls via the PLT. */
5102 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5104 value = (splt->output_section->vma
5105 + splt->output_offset
5107 if (globals->use_blx)
5109 /* If the Thumb BLX instruction is available, convert the
5110 BL to a BLX instruction to call the ARM-mode PLT entry. */
5111 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5114 /* Target the Thumb stub before the ARM PLT entry. */
5115 value -= PLT_THUMB_STUB_SIZE;
5116 *unresolved_reloc_p = FALSE;
5119 relocation = value + signed_addend;
5121 relocation -= (input_section->output_section->vma
5122 + input_section->output_offset
5125 check = relocation >> howto->rightshift;
5127 /* If this is a signed value, the rightshift just dropped
5128 leading 1 bits (assuming twos complement). */
5129 if ((bfd_signed_vma) relocation >= 0)
5130 signed_check = check;
5132 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5134 /* Calculate the permissable maximum and minimum values for
5135 this relocation according to whether we're relocating for
5137 bitsize = howto->bitsize;
5140 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
5141 reloc_signed_min = ~reloc_signed_max;
5143 /* Assumes two's complement. */
5144 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5147 if ((lower_insn & 0x1800) == 0x0800)
5148 /* For a BLX instruction, make sure that the relocation is rounded up
5149 to a word boundary. This follows the semantics of the instruction
5150 which specifies that bit 1 of the target address will come from bit
5151 1 of the base address. */
5152 relocation = (relocation + 2) & ~ 3;
5154 /* Put RELOCATION back into the insn. Assumes two's complement.
5155 We use the Thumb-2 encoding, which is safe even if dealing with
5156 a Thumb-1 instruction by virtue of our overflow check above. */
5157 reloc_sign = (signed_check < 0) ? 1 : 0;
5158 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
5159 | ((relocation >> 12) & 0x3ff)
5160 | (reloc_sign << 10);
5161 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
5162 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
5163 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
5164 | ((relocation >> 1) & 0x7ff);
5166 /* Put the relocated value back in the object file: */
5167 bfd_put_16 (input_bfd, upper_insn, hit_data);
5168 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5170 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5174 case R_ARM_THM_JUMP24:
5175 /* Thumb32 unconditional branch instruction. */
5178 bfd_boolean overflow = FALSE;
5179 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5180 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5181 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
5182 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5184 bfd_signed_vma signed_check;
5186 /* Need to refetch the addend, reconstruct the top three bits, and glue the
5187 two pieces together. */
5188 if (globals->use_rel)
5190 bfd_vma S = (upper_insn & 0x0400) >> 10;
5191 bfd_vma hi = (upper_insn & 0x03ff);
5192 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
5193 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
5194 bfd_vma lo = (lower_insn & 0x07ff);
5200 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
5201 signed_addend -= (1 << 24); /* Sign extend. */
5204 /* ??? Should handle interworking? GCC might someday try to
5205 use this for tail calls. */
5207 relocation = value + signed_addend;
5208 relocation -= (input_section->output_section->vma
5209 + input_section->output_offset
5212 check = relocation >> howto->rightshift;
5214 /* If this is a signed value, the rightshift just dropped
5215 leading 1 bits (assuming twos complement). */
5216 if ((bfd_signed_vma) relocation >= 0)
5217 signed_check = check;
5219 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5221 /* Assumes two's complement. */
5222 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5225 /* Put RELOCATION back into the insn. */
5227 bfd_vma S = (relocation & 0x01000000) >> 24;
5228 bfd_vma I1 = (relocation & 0x00800000) >> 23;
5229 bfd_vma I2 = (relocation & 0x00400000) >> 22;
5230 bfd_vma hi = (relocation & 0x003ff000) >> 12;
5231 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5236 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
5237 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
5240 /* Put the relocated value back in the object file: */
5241 bfd_put_16 (input_bfd, upper_insn, hit_data);
5242 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5244 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5247 case R_ARM_THM_JUMP19:
5248 /* Thumb32 conditional branch instruction. */
5251 bfd_boolean overflow = FALSE;
5252 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5253 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5254 bfd_signed_vma reloc_signed_max = 0xffffe;
5255 bfd_signed_vma reloc_signed_min = -0x100000;
5256 bfd_signed_vma signed_check;
5258 /* Need to refetch the addend, reconstruct the top three bits,
5259 and squish the two 11 bit pieces together. */
5260 if (globals->use_rel)
5262 bfd_vma S = (upper_insn & 0x0400) >> 10;
5263 bfd_vma upper = (upper_insn & 0x003f);
5264 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
5265 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
5266 bfd_vma lower = (lower_insn & 0x07ff);
5271 upper -= 0x0100; /* Sign extend. */
5273 addend = (upper << 12) | (lower << 1);
5274 signed_addend = addend;
5277 /* ??? Should handle interworking? GCC might someday try to
5278 use this for tail calls. */
5280 relocation = value + signed_addend;
5281 relocation -= (input_section->output_section->vma
5282 + input_section->output_offset
5284 signed_check = (bfd_signed_vma) relocation;
5286 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5289 /* Put RELOCATION back into the insn. */
5291 bfd_vma S = (relocation & 0x00100000) >> 20;
5292 bfd_vma J2 = (relocation & 0x00080000) >> 19;
5293 bfd_vma J1 = (relocation & 0x00040000) >> 18;
5294 bfd_vma hi = (relocation & 0x0003f000) >> 12;
5295 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5297 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
5298 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
5301 /* Put the relocated value back in the object file: */
5302 bfd_put_16 (input_bfd, upper_insn, hit_data);
5303 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5305 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5308 case R_ARM_THM_JUMP11:
5309 case R_ARM_THM_JUMP8:
5310 case R_ARM_THM_JUMP6:
5311 /* Thumb B (branch) instruction). */
5313 bfd_signed_vma relocation;
5314 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
5315 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5316 bfd_signed_vma signed_check;
5318 /* CZB cannot jump backward. */
5319 if (r_type == R_ARM_THM_JUMP6)
5320 reloc_signed_min = 0;
5322 if (globals->use_rel)
5324 /* Need to refetch addend. */
5325 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
5326 if (addend & ((howto->src_mask + 1) >> 1))
5329 signed_addend &= ~ howto->src_mask;
5330 signed_addend |= addend;
5333 signed_addend = addend;
5334 /* The value in the insn has been right shifted. We need to
5335 undo this, so that we can perform the address calculation
5336 in terms of bytes. */
5337 signed_addend <<= howto->rightshift;
5339 relocation = value + signed_addend;
5341 relocation -= (input_section->output_section->vma
5342 + input_section->output_offset
5345 relocation >>= howto->rightshift;
5346 signed_check = relocation;
5348 if (r_type == R_ARM_THM_JUMP6)
5349 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
5351 relocation &= howto->dst_mask;
5352 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
5354 bfd_put_16 (input_bfd, relocation, hit_data);
5356 /* Assumes two's complement. */
5357 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5358 return bfd_reloc_overflow;
5360 return bfd_reloc_ok;
5363 case R_ARM_ALU_PCREL7_0:
5364 case R_ARM_ALU_PCREL15_8:
5365 case R_ARM_ALU_PCREL23_15:
5370 insn = bfd_get_32 (input_bfd, hit_data);
5371 if (globals->use_rel)
5373 /* Extract the addend. */
5374 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
5375 signed_addend = addend;
5377 relocation = value + signed_addend;
5379 relocation -= (input_section->output_section->vma
5380 + input_section->output_offset
5382 insn = (insn & ~0xfff)
5383 | ((howto->bitpos << 7) & 0xf00)
5384 | ((relocation >> howto->bitpos) & 0xff);
5385 bfd_put_32 (input_bfd, value, hit_data);
5387 return bfd_reloc_ok;
5389 case R_ARM_GNU_VTINHERIT:
5390 case R_ARM_GNU_VTENTRY:
5391 return bfd_reloc_ok;
5393 case R_ARM_GOTOFF32:
5394 /* Relocation is relative to the start of the
5395 global offset table. */
5397 BFD_ASSERT (sgot != NULL);
5399 return bfd_reloc_notsupported;
5401 /* If we are addressing a Thumb function, we need to adjust the
5402 address by one, so that attempts to call the function pointer will
5403 correctly interpret it as Thumb code. */
5404 if (sym_flags == STT_ARM_TFUNC)
5407 /* Note that sgot->output_offset is not involved in this
5408 calculation. We always want the start of .got. If we
5409 define _GLOBAL_OFFSET_TABLE in a different way, as is
5410 permitted by the ABI, we might have to change this
5412 value -= sgot->output_section->vma;
5413 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5414 contents, rel->r_offset, value,
5418 /* Use global offset table as symbol value. */
5419 BFD_ASSERT (sgot != NULL);
5422 return bfd_reloc_notsupported;
5424 *unresolved_reloc_p = FALSE;
5425 value = sgot->output_section->vma;
5426 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5427 contents, rel->r_offset, value,
5431 case R_ARM_GOT_PREL:
5432 /* Relocation is to the entry for this symbol in the
5433 global offset table. */
5435 return bfd_reloc_notsupported;
5442 off = h->got.offset;
5443 BFD_ASSERT (off != (bfd_vma) -1);
5444 dyn = globals->root.dynamic_sections_created;
5446 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5448 && SYMBOL_REFERENCES_LOCAL (info, h))
5449 || (ELF_ST_VISIBILITY (h->other)
5450 && h->root.type == bfd_link_hash_undefweak))
5452 /* This is actually a static link, or it is a -Bsymbolic link
5453 and the symbol is defined locally. We must initialize this
5454 entry in the global offset table. Since the offset must
5455 always be a multiple of 4, we use the least significant bit
5456 to record whether we have initialized it already.
5458 When doing a dynamic link, we create a .rel(a).got relocation
5459 entry to initialize the value. This is done in the
5460 finish_dynamic_symbol routine. */
5465 /* If we are addressing a Thumb function, we need to
5466 adjust the address by one, so that attempts to
5467 call the function pointer will correctly
5468 interpret it as Thumb code. */
5469 if (sym_flags == STT_ARM_TFUNC)
5472 bfd_put_32 (output_bfd, value, sgot->contents + off);
5477 *unresolved_reloc_p = FALSE;
5479 value = sgot->output_offset + off;
5485 BFD_ASSERT (local_got_offsets != NULL &&
5486 local_got_offsets[r_symndx] != (bfd_vma) -1);
5488 off = local_got_offsets[r_symndx];
5490 /* The offset must always be a multiple of 4. We use the
5491 least significant bit to record whether we have already
5492 generated the necessary reloc. */
5497 /* If we are addressing a Thumb function, we need to
5498 adjust the address by one, so that attempts to
5499 call the function pointer will correctly
5500 interpret it as Thumb code. */
5501 if (sym_flags == STT_ARM_TFUNC)
5504 if (globals->use_rel)
5505 bfd_put_32 (output_bfd, value, sgot->contents + off);
5510 Elf_Internal_Rela outrel;
5513 srelgot = (bfd_get_section_by_name
5514 (dynobj, RELOC_SECTION (globals, ".got")));
5515 BFD_ASSERT (srelgot != NULL);
5517 outrel.r_addend = addend + value;
5518 outrel.r_offset = (sgot->output_section->vma
5519 + sgot->output_offset
5521 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5522 loc = srelgot->contents;
5523 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
5524 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5527 local_got_offsets[r_symndx] |= 1;
5530 value = sgot->output_offset + off;
5532 if (r_type != R_ARM_GOT32)
5533 value += sgot->output_section->vma;
5535 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5536 contents, rel->r_offset, value,
5539 case R_ARM_TLS_LDO32:
5540 value = value - dtpoff_base (info);
5542 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5543 contents, rel->r_offset, value,
5546 case R_ARM_TLS_LDM32:
5550 if (globals->sgot == NULL)
5553 off = globals->tls_ldm_got.offset;
5559 /* If we don't know the module number, create a relocation
5563 Elf_Internal_Rela outrel;
5566 if (globals->srelgot == NULL)
5569 outrel.r_addend = 0;
5570 outrel.r_offset = (globals->sgot->output_section->vma
5571 + globals->sgot->output_offset + off);
5572 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
5574 if (globals->use_rel)
5575 bfd_put_32 (output_bfd, outrel.r_addend,
5576 globals->sgot->contents + off);
5578 loc = globals->srelgot->contents;
5579 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
5580 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5583 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
5585 globals->tls_ldm_got.offset |= 1;
5588 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5589 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5591 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5592 contents, rel->r_offset, value,
5596 case R_ARM_TLS_GD32:
5597 case R_ARM_TLS_IE32:
5603 if (globals->sgot == NULL)
5610 dyn = globals->root.dynamic_sections_created;
5611 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5613 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5615 *unresolved_reloc_p = FALSE;
5618 off = h->got.offset;
5619 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
5623 if (local_got_offsets == NULL)
5625 off = local_got_offsets[r_symndx];
5626 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
5629 if (tls_type == GOT_UNKNOWN)
5636 bfd_boolean need_relocs = FALSE;
5637 Elf_Internal_Rela outrel;
5638 bfd_byte *loc = NULL;
5641 /* The GOT entries have not been initialized yet. Do it
5642 now, and emit any relocations. If both an IE GOT and a
5643 GD GOT are necessary, we emit the GD first. */
5645 if ((info->shared || indx != 0)
5647 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5648 || h->root.type != bfd_link_hash_undefweak))
5651 if (globals->srelgot == NULL)
5653 loc = globals->srelgot->contents;
5654 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
5657 if (tls_type & GOT_TLS_GD)
5661 outrel.r_addend = 0;
5662 outrel.r_offset = (globals->sgot->output_section->vma
5663 + globals->sgot->output_offset
5665 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
5667 if (globals->use_rel)
5668 bfd_put_32 (output_bfd, outrel.r_addend,
5669 globals->sgot->contents + cur_off);
5671 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5672 globals->srelgot->reloc_count++;
5673 loc += RELOC_SIZE (globals);
5676 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5677 globals->sgot->contents + cur_off + 4);
5680 outrel.r_addend = 0;
5681 outrel.r_info = ELF32_R_INFO (indx,
5682 R_ARM_TLS_DTPOFF32);
5683 outrel.r_offset += 4;
5685 if (globals->use_rel)
5686 bfd_put_32 (output_bfd, outrel.r_addend,
5687 globals->sgot->contents + cur_off + 4);
5690 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5691 globals->srelgot->reloc_count++;
5692 loc += RELOC_SIZE (globals);
5697 /* If we are not emitting relocations for a
5698 general dynamic reference, then we must be in a
5699 static link or an executable link with the
5700 symbol binding locally. Mark it as belonging
5701 to module 1, the executable. */
5702 bfd_put_32 (output_bfd, 1,
5703 globals->sgot->contents + cur_off);
5704 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5705 globals->sgot->contents + cur_off + 4);
5711 if (tls_type & GOT_TLS_IE)
5716 outrel.r_addend = value - dtpoff_base (info);
5718 outrel.r_addend = 0;
5719 outrel.r_offset = (globals->sgot->output_section->vma
5720 + globals->sgot->output_offset
5722 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
5724 if (globals->use_rel)
5725 bfd_put_32 (output_bfd, outrel.r_addend,
5726 globals->sgot->contents + cur_off);
5728 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5729 globals->srelgot->reloc_count++;
5730 loc += RELOC_SIZE (globals);
5733 bfd_put_32 (output_bfd, tpoff (info, value),
5734 globals->sgot->contents + cur_off);
5741 local_got_offsets[r_symndx] |= 1;
5744 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
5746 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5747 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5749 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5750 contents, rel->r_offset, value,
5754 case R_ARM_TLS_LE32:
5757 (*_bfd_error_handler)
5758 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
5759 input_bfd, input_section,
5760 (long) rel->r_offset, howto->name);
5764 value = tpoff (info, value);
5766 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5767 contents, rel->r_offset, value,
5771 if (globals->fix_v4bx)
5773 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5775 /* Ensure that we have a BX instruction. */
5776 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
5778 /* Preserve Rm (lowest four bits) and the condition code
5779 (highest four bits). Other bits encode MOV PC,Rm. */
5780 insn = (insn & 0xf000000f) | 0x01a0f000;
5782 bfd_put_32 (input_bfd, insn, hit_data);
5784 return bfd_reloc_ok;
5786 case R_ARM_MOVW_ABS_NC:
5787 case R_ARM_MOVT_ABS:
5788 case R_ARM_MOVW_PREL_NC:
5789 case R_ARM_MOVT_PREL:
5790 /* Until we properly support segment-base-relative addressing then
5791 we assume the segment base to be zero, as for the group relocations.
5792 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
5793 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
5794 case R_ARM_MOVW_BREL_NC:
5795 case R_ARM_MOVW_BREL:
5796 case R_ARM_MOVT_BREL:
5798 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5800 if (globals->use_rel)
5802 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
5803 signed_addend = (addend ^ 0x10000) - 0x10000;
5806 value += signed_addend;
5808 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
5809 value -= (input_section->output_section->vma
5810 + input_section->output_offset + rel->r_offset);
5812 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
5813 return bfd_reloc_overflow;
5815 if (sym_flags == STT_ARM_TFUNC)
5818 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
5819 || r_type == R_ARM_MOVT_BREL)
5823 insn |= value & 0xfff;
5824 insn |= (value & 0xf000) << 4;
5825 bfd_put_32 (input_bfd, insn, hit_data);
5827 return bfd_reloc_ok;
5829 case R_ARM_THM_MOVW_ABS_NC:
5830 case R_ARM_THM_MOVT_ABS:
5831 case R_ARM_THM_MOVW_PREL_NC:
5832 case R_ARM_THM_MOVT_PREL:
5833 /* Until we properly support segment-base-relative addressing then
5834 we assume the segment base to be zero, as for the above relocations.
5835 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
5836 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
5837 as R_ARM_THM_MOVT_ABS. */
5838 case R_ARM_THM_MOVW_BREL_NC:
5839 case R_ARM_THM_MOVW_BREL:
5840 case R_ARM_THM_MOVT_BREL:
5844 insn = bfd_get_16 (input_bfd, hit_data) << 16;
5845 insn |= bfd_get_16 (input_bfd, hit_data + 2);
5847 if (globals->use_rel)
5849 addend = ((insn >> 4) & 0xf000)
5850 | ((insn >> 15) & 0x0800)
5851 | ((insn >> 4) & 0x0700)
5853 signed_addend = (addend ^ 0x10000) - 0x10000;
5856 value += signed_addend;
5858 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
5859 value -= (input_section->output_section->vma
5860 + input_section->output_offset + rel->r_offset);
5862 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
5863 return bfd_reloc_overflow;
5865 if (sym_flags == STT_ARM_TFUNC)
5868 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
5869 || r_type == R_ARM_THM_MOVT_BREL)
5873 insn |= (value & 0xf000) << 4;
5874 insn |= (value & 0x0800) << 15;
5875 insn |= (value & 0x0700) << 4;
5876 insn |= (value & 0x00ff);
5878 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5879 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5881 return bfd_reloc_ok;
5883 case R_ARM_ALU_PC_G0_NC:
5884 case R_ARM_ALU_PC_G1_NC:
5885 case R_ARM_ALU_PC_G0:
5886 case R_ARM_ALU_PC_G1:
5887 case R_ARM_ALU_PC_G2:
5888 case R_ARM_ALU_SB_G0_NC:
5889 case R_ARM_ALU_SB_G1_NC:
5890 case R_ARM_ALU_SB_G0:
5891 case R_ARM_ALU_SB_G1:
5892 case R_ARM_ALU_SB_G2:
5894 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5895 bfd_vma pc = input_section->output_section->vma
5896 + input_section->output_offset + rel->r_offset;
5897 /* sb should be the origin of the *segment* containing the symbol.
5898 It is not clear how to obtain this OS-dependent value, so we
5899 make an arbitrary choice of zero. */
5903 bfd_signed_vma signed_value;
5906 /* Determine which group of bits to select. */
5909 case R_ARM_ALU_PC_G0_NC:
5910 case R_ARM_ALU_PC_G0:
5911 case R_ARM_ALU_SB_G0_NC:
5912 case R_ARM_ALU_SB_G0:
5916 case R_ARM_ALU_PC_G1_NC:
5917 case R_ARM_ALU_PC_G1:
5918 case R_ARM_ALU_SB_G1_NC:
5919 case R_ARM_ALU_SB_G1:
5923 case R_ARM_ALU_PC_G2:
5924 case R_ARM_ALU_SB_G2:
5932 /* If REL, extract the addend from the insn. If RELA, it will
5933 have already been fetched for us. */
5934 if (globals->use_rel)
5937 bfd_vma constant = insn & 0xff;
5938 bfd_vma rotation = (insn & 0xf00) >> 8;
5941 signed_addend = constant;
5944 /* Compensate for the fact that in the instruction, the
5945 rotation is stored in multiples of 2 bits. */
5948 /* Rotate "constant" right by "rotation" bits. */
5949 signed_addend = (constant >> rotation) |
5950 (constant << (8 * sizeof (bfd_vma) - rotation));
5953 /* Determine if the instruction is an ADD or a SUB.
5954 (For REL, this determines the sign of the addend.) */
5955 negative = identify_add_or_sub (insn);
5958 (*_bfd_error_handler)
5959 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5960 input_bfd, input_section,
5961 (long) rel->r_offset, howto->name);
5962 return bfd_reloc_overflow;
5965 signed_addend *= negative;
5968 /* Compute the value (X) to go in the place. */
5969 if (r_type == R_ARM_ALU_PC_G0_NC
5970 || r_type == R_ARM_ALU_PC_G1_NC
5971 || r_type == R_ARM_ALU_PC_G0
5972 || r_type == R_ARM_ALU_PC_G1
5973 || r_type == R_ARM_ALU_PC_G2)
5975 signed_value = value - pc + signed_addend;
5977 /* Section base relative. */
5978 signed_value = value - sb + signed_addend;
5980 /* If the target symbol is a Thumb function, then set the
5981 Thumb bit in the address. */
5982 if (sym_flags == STT_ARM_TFUNC)
5985 /* Calculate the value of the relevant G_n, in encoded
5986 constant-with-rotation format. */
5987 g_n = calculate_group_reloc_mask (llabs (signed_value), group,
5990 /* Check for overflow if required. */
5991 if ((r_type == R_ARM_ALU_PC_G0
5992 || r_type == R_ARM_ALU_PC_G1
5993 || r_type == R_ARM_ALU_PC_G2
5994 || r_type == R_ARM_ALU_SB_G0
5995 || r_type == R_ARM_ALU_SB_G1
5996 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5998 (*_bfd_error_handler)
5999 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6000 input_bfd, input_section,
6001 (long) rel->r_offset, llabs (signed_value), howto->name);
6002 return bfd_reloc_overflow;
6005 /* Mask out the value and the ADD/SUB part of the opcode; take care
6006 not to destroy the S bit. */
6009 /* Set the opcode according to whether the value to go in the
6010 place is negative. */
6011 if (signed_value < 0)
6016 /* Encode the offset. */
6019 bfd_put_32 (input_bfd, insn, hit_data);
6021 return bfd_reloc_ok;
6023 case R_ARM_LDR_PC_G0:
6024 case R_ARM_LDR_PC_G1:
6025 case R_ARM_LDR_PC_G2:
6026 case R_ARM_LDR_SB_G0:
6027 case R_ARM_LDR_SB_G1:
6028 case R_ARM_LDR_SB_G2:
6030 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6031 bfd_vma pc = input_section->output_section->vma
6032 + input_section->output_offset + rel->r_offset;
6033 bfd_vma sb = 0; /* See note above. */
6035 bfd_signed_vma signed_value;
6038 /* Determine which groups of bits to calculate. */
6041 case R_ARM_LDR_PC_G0:
6042 case R_ARM_LDR_SB_G0:
6046 case R_ARM_LDR_PC_G1:
6047 case R_ARM_LDR_SB_G1:
6051 case R_ARM_LDR_PC_G2:
6052 case R_ARM_LDR_SB_G2:
6060 /* If REL, extract the addend from the insn. If RELA, it will
6061 have already been fetched for us. */
6062 if (globals->use_rel)
6064 int negative = (insn & (1 << 23)) ? 1 : -1;
6065 signed_addend = negative * (insn & 0xfff);
6068 /* Compute the value (X) to go in the place. */
6069 if (r_type == R_ARM_LDR_PC_G0
6070 || r_type == R_ARM_LDR_PC_G1
6071 || r_type == R_ARM_LDR_PC_G2)
6073 signed_value = value - pc + signed_addend;
6075 /* Section base relative. */
6076 signed_value = value - sb + signed_addend;
6078 /* Calculate the value of the relevant G_{n-1} to obtain
6079 the residual at that stage. */
6080 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6082 /* Check for overflow. */
6083 if (residual >= 0x1000)
6085 (*_bfd_error_handler)
6086 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6087 input_bfd, input_section,
6088 (long) rel->r_offset, llabs (signed_value), howto->name);
6089 return bfd_reloc_overflow;
6092 /* Mask out the value and U bit. */
6095 /* Set the U bit if the value to go in the place is non-negative. */
6096 if (signed_value >= 0)
6099 /* Encode the offset. */
6102 bfd_put_32 (input_bfd, insn, hit_data);
6104 return bfd_reloc_ok;
6106 case R_ARM_LDRS_PC_G0:
6107 case R_ARM_LDRS_PC_G1:
6108 case R_ARM_LDRS_PC_G2:
6109 case R_ARM_LDRS_SB_G0:
6110 case R_ARM_LDRS_SB_G1:
6111 case R_ARM_LDRS_SB_G2:
6113 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6114 bfd_vma pc = input_section->output_section->vma
6115 + input_section->output_offset + rel->r_offset;
6116 bfd_vma sb = 0; /* See note above. */
6118 bfd_signed_vma signed_value;
6121 /* Determine which groups of bits to calculate. */
6124 case R_ARM_LDRS_PC_G0:
6125 case R_ARM_LDRS_SB_G0:
6129 case R_ARM_LDRS_PC_G1:
6130 case R_ARM_LDRS_SB_G1:
6134 case R_ARM_LDRS_PC_G2:
6135 case R_ARM_LDRS_SB_G2:
6143 /* If REL, extract the addend from the insn. If RELA, it will
6144 have already been fetched for us. */
6145 if (globals->use_rel)
6147 int negative = (insn & (1 << 23)) ? 1 : -1;
6148 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
6151 /* Compute the value (X) to go in the place. */
6152 if (r_type == R_ARM_LDRS_PC_G0
6153 || r_type == R_ARM_LDRS_PC_G1
6154 || r_type == R_ARM_LDRS_PC_G2)
6156 signed_value = value - pc + signed_addend;
6158 /* Section base relative. */
6159 signed_value = value - sb + signed_addend;
6161 /* Calculate the value of the relevant G_{n-1} to obtain
6162 the residual at that stage. */
6163 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6165 /* Check for overflow. */
6166 if (residual >= 0x100)
6168 (*_bfd_error_handler)
6169 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6170 input_bfd, input_section,
6171 (long) rel->r_offset, llabs (signed_value), howto->name);
6172 return bfd_reloc_overflow;
6175 /* Mask out the value and U bit. */
6178 /* Set the U bit if the value to go in the place is non-negative. */
6179 if (signed_value >= 0)
6182 /* Encode the offset. */
6183 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
6185 bfd_put_32 (input_bfd, insn, hit_data);
6187 return bfd_reloc_ok;
6189 case R_ARM_LDC_PC_G0:
6190 case R_ARM_LDC_PC_G1:
6191 case R_ARM_LDC_PC_G2:
6192 case R_ARM_LDC_SB_G0:
6193 case R_ARM_LDC_SB_G1:
6194 case R_ARM_LDC_SB_G2:
6196 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6197 bfd_vma pc = input_section->output_section->vma
6198 + input_section->output_offset + rel->r_offset;
6199 bfd_vma sb = 0; /* See note above. */
6201 bfd_signed_vma signed_value;
6204 /* Determine which groups of bits to calculate. */
6207 case R_ARM_LDC_PC_G0:
6208 case R_ARM_LDC_SB_G0:
6212 case R_ARM_LDC_PC_G1:
6213 case R_ARM_LDC_SB_G1:
6217 case R_ARM_LDC_PC_G2:
6218 case R_ARM_LDC_SB_G2:
6226 /* If REL, extract the addend from the insn. If RELA, it will
6227 have already been fetched for us. */
6228 if (globals->use_rel)
6230 int negative = (insn & (1 << 23)) ? 1 : -1;
6231 signed_addend = negative * ((insn & 0xff) << 2);
6234 /* Compute the value (X) to go in the place. */
6235 if (r_type == R_ARM_LDC_PC_G0
6236 || r_type == R_ARM_LDC_PC_G1
6237 || r_type == R_ARM_LDC_PC_G2)
6239 signed_value = value - pc + signed_addend;
6241 /* Section base relative. */
6242 signed_value = value - sb + signed_addend;
6244 /* Calculate the value of the relevant G_{n-1} to obtain
6245 the residual at that stage. */
6246 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6248 /* Check for overflow. (The absolute value to go in the place must be
6249 divisible by four and, after having been divided by four, must
6250 fit in eight bits.) */
6251 if ((residual & 0x3) != 0 || residual >= 0x400)
6253 (*_bfd_error_handler)
6254 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6255 input_bfd, input_section,
6256 (long) rel->r_offset, llabs (signed_value), howto->name);
6257 return bfd_reloc_overflow;
6260 /* Mask out the value and U bit. */
6263 /* Set the U bit if the value to go in the place is non-negative. */
6264 if (signed_value >= 0)
6267 /* Encode the offset. */
6268 insn |= residual >> 2;
6270 bfd_put_32 (input_bfd, insn, hit_data);
6272 return bfd_reloc_ok;
6275 return bfd_reloc_notsupported;
6279 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
6281 arm_add_to_rel (bfd * abfd,
6283 reloc_howto_type * howto,
6284 bfd_signed_vma increment)
6286 bfd_signed_vma addend;
6288 if (howto->type == R_ARM_THM_CALL)
6290 int upper_insn, lower_insn;
6293 upper_insn = bfd_get_16 (abfd, address);
6294 lower_insn = bfd_get_16 (abfd, address + 2);
6295 upper = upper_insn & 0x7ff;
6296 lower = lower_insn & 0x7ff;
6298 addend = (upper << 12) | (lower << 1);
6299 addend += increment;
6302 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
6303 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
6305 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
6306 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
6312 contents = bfd_get_32 (abfd, address);
6314 /* Get the (signed) value from the instruction. */
6315 addend = contents & howto->src_mask;
6316 if (addend & ((howto->src_mask + 1) >> 1))
6318 bfd_signed_vma mask;
6321 mask &= ~ howto->src_mask;
6325 /* Add in the increment, (which is a byte value). */
6326 switch (howto->type)
6329 addend += increment;
6336 addend <<= howto->size;
6337 addend += increment;
6339 /* Should we check for overflow here ? */
6341 /* Drop any undesired bits. */
6342 addend >>= howto->rightshift;
6346 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
6348 bfd_put_32 (abfd, contents, address);
6352 #define IS_ARM_TLS_RELOC(R_TYPE) \
6353 ((R_TYPE) == R_ARM_TLS_GD32 \
6354 || (R_TYPE) == R_ARM_TLS_LDO32 \
6355 || (R_TYPE) == R_ARM_TLS_LDM32 \
6356 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
6357 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
6358 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
6359 || (R_TYPE) == R_ARM_TLS_LE32 \
6360 || (R_TYPE) == R_ARM_TLS_IE32)
6362 /* Relocate an ARM ELF section. */
6364 elf32_arm_relocate_section (bfd * output_bfd,
6365 struct bfd_link_info * info,
6367 asection * input_section,
6368 bfd_byte * contents,
6369 Elf_Internal_Rela * relocs,
6370 Elf_Internal_Sym * local_syms,
6371 asection ** local_sections)
6373 Elf_Internal_Shdr *symtab_hdr;
6374 struct elf_link_hash_entry **sym_hashes;
6375 Elf_Internal_Rela *rel;
6376 Elf_Internal_Rela *relend;
6378 struct elf32_arm_link_hash_table * globals;
6380 globals = elf32_arm_hash_table (info);
6382 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
6383 sym_hashes = elf_sym_hashes (input_bfd);
6386 relend = relocs + input_section->reloc_count;
6387 for (; rel < relend; rel++)
6390 reloc_howto_type * howto;
6391 unsigned long r_symndx;
6392 Elf_Internal_Sym * sym;
6394 struct elf_link_hash_entry * h;
6396 bfd_reloc_status_type r;
6399 bfd_boolean unresolved_reloc = FALSE;
6400 char *error_message = NULL;
6402 r_symndx = ELF32_R_SYM (rel->r_info);
6403 r_type = ELF32_R_TYPE (rel->r_info);
6404 r_type = arm_real_reloc_type (globals, r_type);
6406 if ( r_type == R_ARM_GNU_VTENTRY
6407 || r_type == R_ARM_GNU_VTINHERIT)
6410 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
6411 howto = bfd_reloc.howto;
6417 if (r_symndx < symtab_hdr->sh_info)
6419 sym = local_syms + r_symndx;
6420 sym_type = ELF32_ST_TYPE (sym->st_info);
6421 sec = local_sections[r_symndx];
6422 if (globals->use_rel)
6424 relocation = (sec->output_section->vma
6425 + sec->output_offset
6427 if (!info->relocatable
6428 && (sec->flags & SEC_MERGE)
6429 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6432 bfd_vma addend, value;
6434 if (howto->rightshift)
6436 (*_bfd_error_handler)
6437 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
6438 input_bfd, input_section,
6439 (long) rel->r_offset, howto->name);
6443 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
6445 /* Get the (signed) value from the instruction. */
6446 addend = value & howto->src_mask;
6447 if (addend & ((howto->src_mask + 1) >> 1))
6449 bfd_signed_vma mask;
6452 mask &= ~ howto->src_mask;
6457 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
6459 addend += msec->output_section->vma + msec->output_offset;
6460 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
6461 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
6465 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6471 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6472 r_symndx, symtab_hdr, sym_hashes,
6474 unresolved_reloc, warned);
6479 if (sec != NULL && elf_discarded_section (sec))
6481 /* For relocs against symbols from removed linkonce sections,
6482 or sections discarded by a linker script, we just want the
6483 section contents zeroed. Avoid any special processing. */
6484 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
6490 if (info->relocatable)
6492 /* This is a relocatable link. We don't have to change
6493 anything, unless the reloc is against a section symbol,
6494 in which case we have to adjust according to where the
6495 section symbol winds up in the output section. */
6496 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6498 if (globals->use_rel)
6499 arm_add_to_rel (input_bfd, contents + rel->r_offset,
6500 howto, (bfd_signed_vma) sec->output_offset);
6502 rel->r_addend += sec->output_offset;
6508 name = h->root.root.string;
6511 name = (bfd_elf_string_from_elf_section
6512 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6513 if (name == NULL || *name == '\0')
6514 name = bfd_section_name (input_bfd, sec);
6518 && r_type != R_ARM_NONE
6520 || h->root.type == bfd_link_hash_defined
6521 || h->root.type == bfd_link_hash_defweak)
6522 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
6524 (*_bfd_error_handler)
6525 ((sym_type == STT_TLS
6526 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6527 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6530 (long) rel->r_offset,
6535 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
6536 input_section, contents, rel,
6537 relocation, info, sec, name,
6538 (h ? ELF_ST_TYPE (h->type) :
6539 ELF_ST_TYPE (sym->st_info)), h,
6540 &unresolved_reloc, &error_message);
6542 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6543 because such sections are not SEC_ALLOC and thus ld.so will
6544 not process them. */
6545 if (unresolved_reloc
6546 && !((input_section->flags & SEC_DEBUGGING) != 0
6549 (*_bfd_error_handler)
6550 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6553 (long) rel->r_offset,
6555 h->root.root.string);
6559 if (r != bfd_reloc_ok)
6563 case bfd_reloc_overflow:
6564 /* If the overflowing reloc was to an undefined symbol,
6565 we have already printed one error message and there
6566 is no point complaining again. */
6568 h->root.type != bfd_link_hash_undefined)
6569 && (!((*info->callbacks->reloc_overflow)
6570 (info, (h ? &h->root : NULL), name, howto->name,
6571 (bfd_vma) 0, input_bfd, input_section,
6576 case bfd_reloc_undefined:
6577 if (!((*info->callbacks->undefined_symbol)
6578 (info, name, input_bfd, input_section,
6579 rel->r_offset, TRUE)))
6583 case bfd_reloc_outofrange:
6584 error_message = _("out of range");
6587 case bfd_reloc_notsupported:
6588 error_message = _("unsupported relocation");
6591 case bfd_reloc_dangerous:
6592 /* error_message should already be set. */
6596 error_message = _("unknown error");
6600 BFD_ASSERT (error_message != NULL);
6601 if (!((*info->callbacks->reloc_dangerous)
6602 (info, error_message, input_bfd, input_section,
6613 /* Set the right machine number. */
6616 elf32_arm_object_p (bfd *abfd)
6620 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
6622 if (mach != bfd_mach_arm_unknown)
6623 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6625 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6626 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
6629 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6634 /* Function to keep ARM specific flags in the ELF header. */
6637 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
6639 if (elf_flags_init (abfd)
6640 && elf_elfheader (abfd)->e_flags != flags)
6642 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6644 if (flags & EF_ARM_INTERWORK)
6645 (*_bfd_error_handler)
6646 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6650 (_("Warning: Clearing the interworking flag of %B due to outside request"),
6656 elf_elfheader (abfd)->e_flags = flags;
6657 elf_flags_init (abfd) = TRUE;
6663 /* Copy backend specific data from one object module to another. */
6666 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6671 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6672 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6675 in_flags = elf_elfheader (ibfd)->e_flags;
6676 out_flags = elf_elfheader (obfd)->e_flags;
6678 if (elf_flags_init (obfd)
6679 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
6680 && in_flags != out_flags)
6682 /* Cannot mix APCS26 and APCS32 code. */
6683 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6686 /* Cannot mix float APCS and non-float APCS code. */
6687 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6690 /* If the src and dest have different interworking flags
6691 then turn off the interworking bit. */
6692 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6694 if (out_flags & EF_ARM_INTERWORK)
6696 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6699 in_flags &= ~EF_ARM_INTERWORK;
6702 /* Likewise for PIC, though don't warn for this case. */
6703 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
6704 in_flags &= ~EF_ARM_PIC;
6707 elf_elfheader (obfd)->e_flags = in_flags;
6708 elf_flags_init (obfd) = TRUE;
6710 /* Also copy the EI_OSABI field. */
6711 elf_elfheader (obfd)->e_ident[EI_OSABI] =
6712 elf_elfheader (ibfd)->e_ident[EI_OSABI];
6714 /* Copy object attributes. */
6715 _bfd_elf_copy_obj_attributes (ibfd, obfd);
6720 /* Values for Tag_ABI_PCS_R9_use. */
6729 /* Values for Tag_ABI_PCS_RW_data. */
6732 AEABI_PCS_RW_data_absolute,
6733 AEABI_PCS_RW_data_PCrel,
6734 AEABI_PCS_RW_data_SBrel,
6735 AEABI_PCS_RW_data_unused
6738 /* Values for Tag_ABI_enum_size. */
6744 AEABI_enum_forced_wide
6747 /* Determine whether an object attribute tag takes an integer, a
6750 elf32_arm_obj_attrs_arg_type (int tag)
6752 if (tag == Tag_compatibility)
6754 else if (tag == 4 || tag == 5)
6759 return (tag & 1) != 0 ? 2 : 1;
6762 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
6763 are conflicting attributes. */
6765 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
6767 obj_attribute *in_attr;
6768 obj_attribute *out_attr;
6769 obj_attribute_list *in_list;
6770 /* Some tags have 0 = don't care, 1 = strong requirement,
6771 2 = weak requirement. */
6772 static const int order_312[3] = {3, 1, 2};
6775 if (!elf_known_obj_attributes_proc (obfd)[0].i)
6777 /* This is the first object. Copy the attributes. */
6778 _bfd_elf_copy_obj_attributes (ibfd, obfd);
6780 /* Use the Tag_null value to indicate the attributes have been
6782 elf_known_obj_attributes_proc (obfd)[0].i = 1;
6787 in_attr = elf_known_obj_attributes_proc (ibfd);
6788 out_attr = elf_known_obj_attributes_proc (obfd);
6789 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6790 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6792 /* Ignore mismatches if teh object doesn't use floating point. */
6793 if (out_attr[Tag_ABI_FP_number_model].i == 0)
6794 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6795 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6797 bfd *hasbfd, *hasnotbfd;
6799 if (in_attr[Tag_ABI_VFP_args].i)
6811 (_("ERROR: %B uses VFP register arguments, %B does not"),
6817 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
6819 if (out_attr[i].type == 0)
6820 out_attr[i].type = in_attr[i].type;
6822 /* Merge this attribute with existing attributes. */
6825 case Tag_CPU_raw_name:
6827 /* Use whichever has the greatest architecture requirements. We
6828 won't necessarily have both the above tags, so make sure input
6829 name is non-NULL. */
6830 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6832 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
6835 case Tag_ABI_optimization_goals:
6836 case Tag_ABI_FP_optimization_goals:
6837 /* Use the first value seen. */
6841 case Tag_ARM_ISA_use:
6842 case Tag_THUMB_ISA_use:
6846 /* ??? Do NEON and WMMX conflict? */
6847 case Tag_ABI_FP_rounding:
6848 case Tag_ABI_FP_denormal:
6849 case Tag_ABI_FP_exceptions:
6850 case Tag_ABI_FP_user_exceptions:
6851 case Tag_ABI_FP_number_model:
6852 case Tag_ABI_align8_preserved:
6853 case Tag_ABI_HardFP_use:
6854 case Tag_CPU_unaligned_access:
6855 case Tag_FP_HP_extension:
6856 /* Use the largest value specified. */
6857 if (in_attr[i].i > out_attr[i].i)
6858 out_attr[i].i = in_attr[i].i;
6861 case Tag_CPU_arch_profile:
6862 /* Warn if conflicting architecture profiles used. */
6863 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6866 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6867 ibfd, in_attr[i].i, out_attr[i].i);
6871 out_attr[i].i = in_attr[i].i;
6873 case Tag_PCS_config:
6874 if (out_attr[i].i == 0)
6875 out_attr[i].i = in_attr[i].i;
6876 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6878 /* It's sometimes ok to mix different configs, so this is only
6881 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6884 case Tag_ABI_PCS_R9_use:
6885 if (in_attr[i].i != out_attr[i].i
6886 && out_attr[i].i != AEABI_R9_unused
6887 && in_attr[i].i != AEABI_R9_unused)
6890 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6893 if (out_attr[i].i == AEABI_R9_unused)
6894 out_attr[i].i = in_attr[i].i;
6896 case Tag_ABI_PCS_RW_data:
6897 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6898 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6899 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6902 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6906 /* Use the smallest value specified. */
6907 if (in_attr[i].i < out_attr[i].i)
6908 out_attr[i].i = in_attr[i].i;
6910 case Tag_ABI_PCS_RO_data:
6911 /* Use the smallest value specified. */
6912 if (in_attr[i].i < out_attr[i].i)
6913 out_attr[i].i = in_attr[i].i;
6915 case Tag_ABI_PCS_GOT_use:
6916 if (in_attr[i].i > 2 || out_attr[i].i > 2
6917 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6918 out_attr[i].i = in_attr[i].i;
6920 case Tag_ABI_PCS_wchar_t:
6921 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6924 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6928 out_attr[i].i = in_attr[i].i;
6930 case Tag_ABI_align8_needed:
6931 /* ??? Check against Tag_ABI_align8_preserved. */
6932 if (in_attr[i].i > 2 || out_attr[i].i > 2
6933 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6934 out_attr[i].i = in_attr[i].i;
6936 case Tag_ABI_enum_size:
6937 if (in_attr[i].i != AEABI_enum_unused)
6939 if (out_attr[i].i == AEABI_enum_unused
6940 || out_attr[i].i == AEABI_enum_forced_wide)
6942 /* The existing object is compatible with anything.
6943 Use whatever requirements the new object has. */
6944 out_attr[i].i = in_attr[i].i;
6946 else if (in_attr[i].i != AEABI_enum_forced_wide
6947 && out_attr[i].i != in_attr[i].i
6948 && !elf32_arm_tdata (obfd)->no_enum_size_warning)
6950 const char *aeabi_enum_names[] =
6951 { "", "variable-size", "32-bit", "" };
6953 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
6954 ibfd, aeabi_enum_names[in_attr[i].i],
6955 aeabi_enum_names[out_attr[i].i]);
6959 case Tag_ABI_VFP_args:
6962 case Tag_ABI_WMMX_args:
6963 if (in_attr[i].i != out_attr[i].i)
6966 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6971 default: /* All known attributes should be explicitly covered. */
6978 /* Merge Tag_compatibility attributes and any common GNU ones. */
6979 _bfd_elf_merge_object_attributes (ibfd, obfd);
6981 /* Check for any attributes not known on ARM. */
6982 in_list = elf_other_obj_attributes_proc (ibfd);
6983 while (in_list && in_list->tag == Tag_compatibility)
6984 in_list = in_list->next;
6986 for (; in_list; in_list = in_list->next)
6988 if ((in_list->tag & 128) < 64
6989 && in_list->tag != Tag_Virtualization_use)
6992 (_("Warning: %B: Unknown EABI object attribute %d"),
6993 ibfd, in_list->tag);
7001 /* Return TRUE if the two EABI versions are incompatible. */
7004 elf32_arm_versions_compatible (unsigned iver, unsigned over)
7006 /* v4 and v5 are the same spec before and after it was released,
7007 so allow mixing them. */
7008 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
7009 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
7012 return (iver == over);
7015 /* Merge backend specific data from an object file to the output
7016 object file when linking. */
7019 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
7023 bfd_boolean flags_compatible = TRUE;
7026 /* Check if we have the same endianess. */
7027 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
7030 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7031 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7034 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
7037 /* The input BFD must have had its flags initialised. */
7038 /* The following seems bogus to me -- The flags are initialized in
7039 the assembler but I don't think an elf_flags_init field is
7040 written into the object. */
7041 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7043 in_flags = elf_elfheader (ibfd)->e_flags;
7044 out_flags = elf_elfheader (obfd)->e_flags;
7046 if (!elf_flags_init (obfd))
7048 /* If the input is the default architecture and had the default
7049 flags then do not bother setting the flags for the output
7050 architecture, instead allow future merges to do this. If no
7051 future merges ever set these flags then they will retain their
7052 uninitialised values, which surprise surprise, correspond
7053 to the default values. */
7054 if (bfd_get_arch_info (ibfd)->the_default
7055 && elf_elfheader (ibfd)->e_flags == 0)
7058 elf_flags_init (obfd) = TRUE;
7059 elf_elfheader (obfd)->e_flags = in_flags;
7061 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7062 && bfd_get_arch_info (obfd)->the_default)
7063 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
7068 /* Determine what should happen if the input ARM architecture
7069 does not match the output ARM architecture. */
7070 if (! bfd_arm_merge_machines (ibfd, obfd))
7073 /* Identical flags must be compatible. */
7074 if (in_flags == out_flags)
7077 /* Check to see if the input BFD actually contains any sections. If
7078 not, its flags may not have been initialised either, but it
7079 cannot actually cause any incompatiblity. Do not short-circuit
7080 dynamic objects; their section list may be emptied by
7081 elf_link_add_object_symbols.
7083 Also check to see if there are no code sections in the input.
7084 In this case there is no need to check for code specific flags.
7085 XXX - do we need to worry about floating-point format compatability
7086 in data sections ? */
7087 if (!(ibfd->flags & DYNAMIC))
7089 bfd_boolean null_input_bfd = TRUE;
7090 bfd_boolean only_data_sections = TRUE;
7092 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7094 /* Ignore synthetic glue sections. */
7095 if (strcmp (sec->name, ".glue_7")
7096 && strcmp (sec->name, ".glue_7t"))
7098 if ((bfd_get_section_flags (ibfd, sec)
7099 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7100 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7101 only_data_sections = FALSE;
7103 null_input_bfd = FALSE;
7108 if (null_input_bfd || only_data_sections)
7112 /* Complain about various flag mismatches. */
7113 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
7114 EF_ARM_EABI_VERSION (out_flags)))
7117 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
7119 (in_flags & EF_ARM_EABIMASK) >> 24,
7120 (out_flags & EF_ARM_EABIMASK) >> 24);
7124 /* Not sure what needs to be checked for EABI versions >= 1. */
7125 /* VxWorks libraries do not use these flags. */
7126 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
7127 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
7128 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
7130 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7133 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
7135 in_flags & EF_ARM_APCS_26 ? 26 : 32,
7136 out_flags & EF_ARM_APCS_26 ? 26 : 32);
7137 flags_compatible = FALSE;
7140 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7142 if (in_flags & EF_ARM_APCS_FLOAT)
7144 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
7148 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
7151 flags_compatible = FALSE;
7154 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
7156 if (in_flags & EF_ARM_VFP_FLOAT)
7158 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
7162 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
7165 flags_compatible = FALSE;
7168 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
7170 if (in_flags & EF_ARM_MAVERICK_FLOAT)
7172 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
7176 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
7179 flags_compatible = FALSE;
7182 #ifdef EF_ARM_SOFT_FLOAT
7183 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
7185 /* We can allow interworking between code that is VFP format
7186 layout, and uses either soft float or integer regs for
7187 passing floating point arguments and results. We already
7188 know that the APCS_FLOAT flags match; similarly for VFP
7190 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
7191 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
7193 if (in_flags & EF_ARM_SOFT_FLOAT)
7195 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
7199 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
7202 flags_compatible = FALSE;
7207 /* Interworking mismatch is only a warning. */
7208 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7210 if (in_flags & EF_ARM_INTERWORK)
7213 (_("Warning: %B supports interworking, whereas %B does not"),
7219 (_("Warning: %B does not support interworking, whereas %B does"),
7225 return flags_compatible;
7228 /* Display the flags field. */
7231 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
7233 FILE * file = (FILE *) ptr;
7234 unsigned long flags;
7236 BFD_ASSERT (abfd != NULL && ptr != NULL);
7238 /* Print normal ELF private data. */
7239 _bfd_elf_print_private_bfd_data (abfd, ptr);
7241 flags = elf_elfheader (abfd)->e_flags;
7242 /* Ignore init flag - it may not be set, despite the flags field
7243 containing valid data. */
7245 /* xgettext:c-format */
7246 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7248 switch (EF_ARM_EABI_VERSION (flags))
7250 case EF_ARM_EABI_UNKNOWN:
7251 /* The following flag bits are GNU extensions and not part of the
7252 official ARM ELF extended ABI. Hence they are only decoded if
7253 the EABI version is not set. */
7254 if (flags & EF_ARM_INTERWORK)
7255 fprintf (file, _(" [interworking enabled]"));
7257 if (flags & EF_ARM_APCS_26)
7258 fprintf (file, " [APCS-26]");
7260 fprintf (file, " [APCS-32]");
7262 if (flags & EF_ARM_VFP_FLOAT)
7263 fprintf (file, _(" [VFP float format]"));
7264 else if (flags & EF_ARM_MAVERICK_FLOAT)
7265 fprintf (file, _(" [Maverick float format]"));
7267 fprintf (file, _(" [FPA float format]"));
7269 if (flags & EF_ARM_APCS_FLOAT)
7270 fprintf (file, _(" [floats passed in float registers]"));
7272 if (flags & EF_ARM_PIC)
7273 fprintf (file, _(" [position independent]"));
7275 if (flags & EF_ARM_NEW_ABI)
7276 fprintf (file, _(" [new ABI]"));
7278 if (flags & EF_ARM_OLD_ABI)
7279 fprintf (file, _(" [old ABI]"));
7281 if (flags & EF_ARM_SOFT_FLOAT)
7282 fprintf (file, _(" [software FP]"));
7284 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
7285 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
7286 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
7287 | EF_ARM_MAVERICK_FLOAT);
7290 case EF_ARM_EABI_VER1:
7291 fprintf (file, _(" [Version1 EABI]"));
7293 if (flags & EF_ARM_SYMSARESORTED)
7294 fprintf (file, _(" [sorted symbol table]"));
7296 fprintf (file, _(" [unsorted symbol table]"));
7298 flags &= ~ EF_ARM_SYMSARESORTED;
7301 case EF_ARM_EABI_VER2:
7302 fprintf (file, _(" [Version2 EABI]"));
7304 if (flags & EF_ARM_SYMSARESORTED)
7305 fprintf (file, _(" [sorted symbol table]"));
7307 fprintf (file, _(" [unsorted symbol table]"));
7309 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
7310 fprintf (file, _(" [dynamic symbols use segment index]"));
7312 if (flags & EF_ARM_MAPSYMSFIRST)
7313 fprintf (file, _(" [mapping symbols precede others]"));
7315 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
7316 | EF_ARM_MAPSYMSFIRST);
7319 case EF_ARM_EABI_VER3:
7320 fprintf (file, _(" [Version3 EABI]"));
7323 case EF_ARM_EABI_VER4:
7324 fprintf (file, _(" [Version4 EABI]"));
7327 case EF_ARM_EABI_VER5:
7328 fprintf (file, _(" [Version5 EABI]"));
7330 if (flags & EF_ARM_BE8)
7331 fprintf (file, _(" [BE8]"));
7333 if (flags & EF_ARM_LE8)
7334 fprintf (file, _(" [LE8]"));
7336 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
7340 fprintf (file, _(" <EABI version unrecognised>"));
7344 flags &= ~ EF_ARM_EABIMASK;
7346 if (flags & EF_ARM_RELEXEC)
7347 fprintf (file, _(" [relocatable executable]"));
7349 if (flags & EF_ARM_HASENTRY)
7350 fprintf (file, _(" [has entry point]"));
7352 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
7355 fprintf (file, _("<Unrecognised flag bits set>"));
7363 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
7365 switch (ELF_ST_TYPE (elf_sym->st_info))
7368 return ELF_ST_TYPE (elf_sym->st_info);
7371 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
7372 This allows us to distinguish between data used by Thumb instructions
7373 and non-data (which is probably code) inside Thumb regions of an
7375 if (type != STT_OBJECT && type != STT_TLS)
7376 return ELF_ST_TYPE (elf_sym->st_info);
7387 elf32_arm_gc_mark_hook (asection *sec,
7388 struct bfd_link_info *info,
7389 Elf_Internal_Rela *rel,
7390 struct elf_link_hash_entry *h,
7391 Elf_Internal_Sym *sym)
7394 switch (ELF32_R_TYPE (rel->r_info))
7396 case R_ARM_GNU_VTINHERIT:
7397 case R_ARM_GNU_VTENTRY:
7401 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7404 /* Update the got entry reference counts for the section being removed. */
7407 elf32_arm_gc_sweep_hook (bfd * abfd,
7408 struct bfd_link_info * info,
7410 const Elf_Internal_Rela * relocs)
7412 Elf_Internal_Shdr *symtab_hdr;
7413 struct elf_link_hash_entry **sym_hashes;
7414 bfd_signed_vma *local_got_refcounts;
7415 const Elf_Internal_Rela *rel, *relend;
7416 struct elf32_arm_link_hash_table * globals;
7418 globals = elf32_arm_hash_table (info);
7420 elf_section_data (sec)->local_dynrel = NULL;
7422 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7423 sym_hashes = elf_sym_hashes (abfd);
7424 local_got_refcounts = elf_local_got_refcounts (abfd);
7426 relend = relocs + sec->reloc_count;
7427 for (rel = relocs; rel < relend; rel++)
7429 unsigned long r_symndx;
7430 struct elf_link_hash_entry *h = NULL;
7433 r_symndx = ELF32_R_SYM (rel->r_info);
7434 if (r_symndx >= symtab_hdr->sh_info)
7436 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7437 while (h->root.type == bfd_link_hash_indirect
7438 || h->root.type == bfd_link_hash_warning)
7439 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7442 r_type = ELF32_R_TYPE (rel->r_info);
7443 r_type = arm_real_reloc_type (globals, r_type);
7447 case R_ARM_GOT_PREL:
7448 case R_ARM_TLS_GD32:
7449 case R_ARM_TLS_IE32:
7452 if (h->got.refcount > 0)
7453 h->got.refcount -= 1;
7455 else if (local_got_refcounts != NULL)
7457 if (local_got_refcounts[r_symndx] > 0)
7458 local_got_refcounts[r_symndx] -= 1;
7462 case R_ARM_TLS_LDM32:
7463 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7467 case R_ARM_ABS32_NOI:
7469 case R_ARM_REL32_NOI:
7475 case R_ARM_THM_CALL:
7476 case R_ARM_MOVW_ABS_NC:
7477 case R_ARM_MOVT_ABS:
7478 case R_ARM_MOVW_PREL_NC:
7479 case R_ARM_MOVT_PREL:
7480 case R_ARM_THM_MOVW_ABS_NC:
7481 case R_ARM_THM_MOVT_ABS:
7482 case R_ARM_THM_MOVW_PREL_NC:
7483 case R_ARM_THM_MOVT_PREL:
7484 /* Should the interworking branches be here also? */
7488 struct elf32_arm_link_hash_entry *eh;
7489 struct elf32_arm_relocs_copied **pp;
7490 struct elf32_arm_relocs_copied *p;
7492 eh = (struct elf32_arm_link_hash_entry *) h;
7494 if (h->plt.refcount > 0)
7496 h->plt.refcount -= 1;
7497 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
7498 eh->plt_thumb_refcount--;
7501 if (r_type == R_ARM_ABS32
7502 || r_type == R_ARM_REL32
7503 || r_type == R_ARM_ABS32_NOI
7504 || r_type == R_ARM_REL32_NOI)
7506 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7508 if (p->section == sec)
7511 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7512 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
7530 /* Look through the relocs for a section during the first phase. */
7533 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7534 asection *sec, const Elf_Internal_Rela *relocs)
7536 Elf_Internal_Shdr *symtab_hdr;
7537 struct elf_link_hash_entry **sym_hashes;
7538 struct elf_link_hash_entry **sym_hashes_end;
7539 const Elf_Internal_Rela *rel;
7540 const Elf_Internal_Rela *rel_end;
7543 bfd_vma *local_got_offsets;
7544 struct elf32_arm_link_hash_table *htab;
7546 if (info->relocatable)
7549 htab = elf32_arm_hash_table (info);
7552 /* Create dynamic sections for relocatable executables so that we can
7553 copy relocations. */
7554 if (htab->root.is_relocatable_executable
7555 && ! htab->root.dynamic_sections_created)
7557 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7561 dynobj = elf_hash_table (info)->dynobj;
7562 local_got_offsets = elf_local_got_offsets (abfd);
7564 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7565 sym_hashes = elf_sym_hashes (abfd);
7566 sym_hashes_end = sym_hashes
7567 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7569 if (!elf_bad_symtab (abfd))
7570 sym_hashes_end -= symtab_hdr->sh_info;
7572 rel_end = relocs + sec->reloc_count;
7573 for (rel = relocs; rel < rel_end; rel++)
7575 struct elf_link_hash_entry *h;
7576 struct elf32_arm_link_hash_entry *eh;
7577 unsigned long r_symndx;
7580 r_symndx = ELF32_R_SYM (rel->r_info);
7581 r_type = ELF32_R_TYPE (rel->r_info);
7582 r_type = arm_real_reloc_type (htab, r_type);
7584 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7586 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7591 if (r_symndx < symtab_hdr->sh_info)
7595 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7596 while (h->root.type == bfd_link_hash_indirect
7597 || h->root.type == bfd_link_hash_warning)
7598 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7601 eh = (struct elf32_arm_link_hash_entry *) h;
7606 case R_ARM_GOT_PREL:
7607 case R_ARM_TLS_GD32:
7608 case R_ARM_TLS_IE32:
7609 /* This symbol requires a global offset table entry. */
7611 int tls_type, old_tls_type;
7615 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7616 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7617 default: tls_type = GOT_NORMAL; break;
7623 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7627 bfd_signed_vma *local_got_refcounts;
7629 /* This is a global offset table entry for a local symbol. */
7630 local_got_refcounts = elf_local_got_refcounts (abfd);
7631 if (local_got_refcounts == NULL)
7635 size = symtab_hdr->sh_info;
7636 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7637 local_got_refcounts = bfd_zalloc (abfd, size);
7638 if (local_got_refcounts == NULL)
7640 elf_local_got_refcounts (abfd) = local_got_refcounts;
7641 elf32_arm_local_got_tls_type (abfd)
7642 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7644 local_got_refcounts[r_symndx] += 1;
7645 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7648 /* We will already have issued an error message if there is a
7649 TLS / non-TLS mismatch, based on the symbol type. We don't
7650 support any linker relaxations. So just combine any TLS
7652 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7653 && tls_type != GOT_NORMAL)
7654 tls_type |= old_tls_type;
7656 if (old_tls_type != tls_type)
7659 elf32_arm_hash_entry (h)->tls_type = tls_type;
7661 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7666 case R_ARM_TLS_LDM32:
7667 if (r_type == R_ARM_TLS_LDM32)
7668 htab->tls_ldm_got.refcount++;
7671 case R_ARM_GOTOFF32:
7673 if (htab->sgot == NULL)
7675 if (htab->root.dynobj == NULL)
7676 htab->root.dynobj = abfd;
7677 if (!create_got_section (htab->root.dynobj, info))
7683 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7684 ldr __GOTT_INDEX__ offsets. */
7685 if (!htab->vxworks_p)
7690 case R_ARM_ABS32_NOI:
7692 case R_ARM_REL32_NOI:
7698 case R_ARM_THM_CALL:
7699 case R_ARM_MOVW_ABS_NC:
7700 case R_ARM_MOVT_ABS:
7701 case R_ARM_MOVW_PREL_NC:
7702 case R_ARM_MOVT_PREL:
7703 case R_ARM_THM_MOVW_ABS_NC:
7704 case R_ARM_THM_MOVT_ABS:
7705 case R_ARM_THM_MOVW_PREL_NC:
7706 case R_ARM_THM_MOVT_PREL:
7707 /* Should the interworking branches be listed here? */
7710 /* If this reloc is in a read-only section, we might
7711 need a copy reloc. We can't check reliably at this
7712 stage whether the section is read-only, as input
7713 sections have not yet been mapped to output sections.
7714 Tentatively set the flag for now, and correct in
7715 adjust_dynamic_symbol. */
7719 /* We may need a .plt entry if the function this reloc
7720 refers to is in a different object. We can't tell for
7721 sure yet, because something later might force the
7723 if (r_type != R_ARM_ABS32
7724 && r_type != R_ARM_REL32
7725 && r_type != R_ARM_ABS32_NOI
7726 && r_type != R_ARM_REL32_NOI
7727 && r_type != R_ARM_ABS12)
7730 /* If we create a PLT entry, this relocation will reference
7731 it, even if it's an ABS32 relocation. */
7732 h->plt.refcount += 1;
7734 if (r_type == R_ARM_THM_CALL)
7735 eh->plt_thumb_refcount += 1;
7738 /* If we are creating a shared library or relocatable executable,
7739 and this is a reloc against a global symbol, or a non PC
7740 relative reloc against a local symbol, then we need to copy
7741 the reloc into the shared library. However, if we are linking
7742 with -Bsymbolic, we do not need to copy a reloc against a
7743 global symbol which is defined in an object we are
7744 including in the link (i.e., DEF_REGULAR is set). At
7745 this point we have not seen all the input files, so it is
7746 possible that DEF_REGULAR is not set now but will be set
7747 later (it is never cleared). We account for that
7748 possibility below by storing information in the
7749 relocs_copied field of the hash table entry. */
7750 if ((info->shared || htab->root.is_relocatable_executable)
7751 && (sec->flags & SEC_ALLOC) != 0
7752 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
7753 || (h != NULL && ! h->needs_plt
7754 && (! info->symbolic || ! h->def_regular))))
7756 struct elf32_arm_relocs_copied *p, **head;
7758 /* When creating a shared object, we must copy these
7759 reloc types into the output file. We create a reloc
7760 section in dynobj and make room for this reloc. */
7765 name = (bfd_elf_string_from_elf_section
7767 elf_elfheader (abfd)->e_shstrndx,
7768 elf_section_data (sec)->rel_hdr.sh_name));
7772 BFD_ASSERT (reloc_section_p (htab, name, sec));
7774 sreloc = bfd_get_section_by_name (dynobj, name);
7779 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7780 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7781 if ((sec->flags & SEC_ALLOC) != 0
7782 /* BPABI objects never have dynamic
7783 relocations mapped. */
7784 && !htab->symbian_p)
7785 flags |= SEC_ALLOC | SEC_LOAD;
7786 sreloc = bfd_make_section_with_flags (dynobj,
7790 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7794 elf_section_data (sec)->sreloc = sreloc;
7797 /* If this is a global symbol, we count the number of
7798 relocations we need for this symbol. */
7801 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7805 /* Track dynamic relocs needed for local syms too.
7806 We really need local syms available to do this
7812 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7817 vpp = &elf_section_data (s)->local_dynrel;
7818 head = (struct elf32_arm_relocs_copied **) vpp;
7822 if (p == NULL || p->section != sec)
7824 bfd_size_type amt = sizeof *p;
7826 p = bfd_alloc (htab->root.dynobj, amt);
7836 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
7842 /* This relocation describes the C++ object vtable hierarchy.
7843 Reconstruct it for later use during GC. */
7844 case R_ARM_GNU_VTINHERIT:
7845 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7849 /* This relocation describes which C++ vtable entries are actually
7850 used. Record for later use during GC. */
7851 case R_ARM_GNU_VTENTRY:
7852 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7861 /* Unwinding tables are not referenced directly. This pass marks them as
7862 required if the corresponding code section is marked. */
7865 elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
7866 elf_gc_mark_hook_fn gc_mark_hook)
7869 Elf_Internal_Shdr **elf_shdrp;
7872 /* Marking EH data may cause additional code sections to be marked,
7873 requiring multiple passes. */
7878 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
7882 if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
7885 elf_shdrp = elf_elfsections (sub);
7886 for (o = sub->sections; o != NULL; o = o->next)
7888 Elf_Internal_Shdr *hdr;
7889 hdr = &elf_section_data (o)->this_hdr;
7890 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
7892 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
7895 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
7905 /* Treat mapping symbols as special target symbols. */
7908 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7910 return bfd_is_arm_special_symbol_name (sym->name,
7911 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7914 /* This is a copy of elf_find_function() from elf.c except that
7915 ARM mapping symbols are ignored when looking for function names
7916 and STT_ARM_TFUNC is considered to a function type. */
7919 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7923 const char ** filename_ptr,
7924 const char ** functionname_ptr)
7926 const char * filename = NULL;
7927 asymbol * func = NULL;
7928 bfd_vma low_func = 0;
7931 for (p = symbols; *p != NULL; p++)
7935 q = (elf_symbol_type *) *p;
7937 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7942 filename = bfd_asymbol_name (&q->symbol);
7947 /* Skip mapping symbols. */
7948 if ((q->symbol.flags & BSF_LOCAL)
7949 && bfd_is_arm_special_symbol_name (q->symbol.name,
7950 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7953 if (bfd_get_section (&q->symbol) == section
7954 && q->symbol.value >= low_func
7955 && q->symbol.value <= offset)
7957 func = (asymbol *) q;
7958 low_func = q->symbol.value;
7968 *filename_ptr = filename;
7969 if (functionname_ptr)
7970 *functionname_ptr = bfd_asymbol_name (func);
7976 /* Find the nearest line to a particular section and offset, for error
7977 reporting. This code is a duplicate of the code in elf.c, except
7978 that it uses arm_elf_find_function. */
7981 elf32_arm_find_nearest_line (bfd * abfd,
7985 const char ** filename_ptr,
7986 const char ** functionname_ptr,
7987 unsigned int * line_ptr)
7989 bfd_boolean found = FALSE;
7991 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7993 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
7994 filename_ptr, functionname_ptr,
7996 & elf_tdata (abfd)->dwarf2_find_line_info))
7998 if (!*functionname_ptr)
7999 arm_elf_find_function (abfd, section, symbols, offset,
8000 *filename_ptr ? NULL : filename_ptr,
8006 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
8007 & found, filename_ptr,
8008 functionname_ptr, line_ptr,
8009 & elf_tdata (abfd)->line_info))
8012 if (found && (*functionname_ptr || *line_ptr))
8015 if (symbols == NULL)
8018 if (! arm_elf_find_function (abfd, section, symbols, offset,
8019 filename_ptr, functionname_ptr))
8027 elf32_arm_find_inliner_info (bfd * abfd,
8028 const char ** filename_ptr,
8029 const char ** functionname_ptr,
8030 unsigned int * line_ptr)
8033 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
8034 functionname_ptr, line_ptr,
8035 & elf_tdata (abfd)->dwarf2_find_line_info);
8039 /* Adjust a symbol defined by a dynamic object and referenced by a
8040 regular object. The current definition is in some section of the
8041 dynamic object, but we're not including those sections. We have to
8042 change the definition to something the rest of the link can
8046 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
8047 struct elf_link_hash_entry * h)
8051 struct elf32_arm_link_hash_entry * eh;
8052 struct elf32_arm_link_hash_table *globals;
8054 globals = elf32_arm_hash_table (info);
8055 dynobj = elf_hash_table (info)->dynobj;
8057 /* Make sure we know what is going on here. */
8058 BFD_ASSERT (dynobj != NULL
8060 || h->u.weakdef != NULL
8063 && !h->def_regular)));
8065 eh = (struct elf32_arm_link_hash_entry *) h;
8067 /* If this is a function, put it in the procedure linkage table. We
8068 will fill in the contents of the procedure linkage table later,
8069 when we know the address of the .got section. */
8070 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
8073 if (h->plt.refcount <= 0
8074 || SYMBOL_CALLS_LOCAL (info, h)
8075 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8076 && h->root.type == bfd_link_hash_undefweak))
8078 /* This case can occur if we saw a PLT32 reloc in an input
8079 file, but the symbol was never referred to by a dynamic
8080 object, or if all references were garbage collected. In
8081 such a case, we don't actually need to build a procedure
8082 linkage table, and we can just do a PC24 reloc instead. */
8083 h->plt.offset = (bfd_vma) -1;
8084 eh->plt_thumb_refcount = 0;
8092 /* It's possible that we incorrectly decided a .plt reloc was
8093 needed for an R_ARM_PC24 or similar reloc to a non-function sym
8094 in check_relocs. We can't decide accurately between function
8095 and non-function syms in check-relocs; Objects loaded later in
8096 the link may change h->type. So fix it now. */
8097 h->plt.offset = (bfd_vma) -1;
8098 eh->plt_thumb_refcount = 0;
8101 /* If this is a weak symbol, and there is a real definition, the
8102 processor independent code will have arranged for us to see the
8103 real definition first, and we can just use the same value. */
8104 if (h->u.weakdef != NULL)
8106 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8107 || h->u.weakdef->root.type == bfd_link_hash_defweak);
8108 h->root.u.def.section = h->u.weakdef->root.u.def.section;
8109 h->root.u.def.value = h->u.weakdef->root.u.def.value;
8113 /* If there are no non-GOT references, we do not need a copy
8115 if (!h->non_got_ref)
8118 /* This is a reference to a symbol defined by a dynamic object which
8119 is not a function. */
8121 /* If we are creating a shared library, we must presume that the
8122 only references to the symbol are via the global offset table.
8123 For such cases we need not do anything here; the relocations will
8124 be handled correctly by relocate_section. Relocatable executables
8125 can reference data in shared objects directly, so we don't need to
8126 do anything here. */
8127 if (info->shared || globals->root.is_relocatable_executable)
8132 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8133 h->root.root.string);
8137 /* We must allocate the symbol in our .dynbss section, which will
8138 become part of the .bss section of the executable. There will be
8139 an entry for this symbol in the .dynsym section. The dynamic
8140 object will contain position independent code, so all references
8141 from the dynamic object to this symbol will go through the global
8142 offset table. The dynamic linker will use the .dynsym entry to
8143 determine the address it must put in the global offset table, so
8144 both the dynamic object and the regular object will refer to the
8145 same memory location for the variable. */
8146 s = bfd_get_section_by_name (dynobj, ".dynbss");
8147 BFD_ASSERT (s != NULL);
8149 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8150 copy the initial value out of the dynamic object and into the
8151 runtime process image. We need to remember the offset into the
8152 .rel(a).bss section we are going to use. */
8153 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8157 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
8158 BFD_ASSERT (srel != NULL);
8159 srel->size += RELOC_SIZE (globals);
8163 return _bfd_elf_adjust_dynamic_copy (h, s);
8166 /* Allocate space in .plt, .got and associated reloc sections for
8170 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
8172 struct bfd_link_info *info;
8173 struct elf32_arm_link_hash_table *htab;
8174 struct elf32_arm_link_hash_entry *eh;
8175 struct elf32_arm_relocs_copied *p;
8177 eh = (struct elf32_arm_link_hash_entry *) h;
8179 if (h->root.type == bfd_link_hash_indirect)
8182 if (h->root.type == bfd_link_hash_warning)
8183 /* When warning symbols are created, they **replace** the "real"
8184 entry in the hash table, thus we never get to see the real
8185 symbol in a hash traversal. So look at it now. */
8186 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8188 info = (struct bfd_link_info *) inf;
8189 htab = elf32_arm_hash_table (info);
8191 if (htab->root.dynamic_sections_created
8192 && h->plt.refcount > 0)
8194 /* Make sure this symbol is output as a dynamic symbol.
8195 Undefined weak syms won't yet be marked as dynamic. */
8196 if (h->dynindx == -1
8197 && !h->forced_local)
8199 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8204 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8206 asection *s = htab->splt;
8208 /* If this is the first .plt entry, make room for the special
8211 s->size += htab->plt_header_size;
8213 h->plt.offset = s->size;
8215 /* If we will insert a Thumb trampoline before this PLT, leave room
8217 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8219 h->plt.offset += PLT_THUMB_STUB_SIZE;
8220 s->size += PLT_THUMB_STUB_SIZE;
8223 /* If this symbol is not defined in a regular file, and we are
8224 not generating a shared library, then set the symbol to this
8225 location in the .plt. This is required to make function
8226 pointers compare as equal between the normal executable and
8227 the shared library. */
8231 h->root.u.def.section = s;
8232 h->root.u.def.value = h->plt.offset;
8234 /* Make sure the function is not marked as Thumb, in case
8235 it is the target of an ABS32 relocation, which will
8236 point to the PLT entry. */
8237 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8238 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8241 /* Make room for this entry. */
8242 s->size += htab->plt_entry_size;
8244 if (!htab->symbian_p)
8246 /* We also need to make an entry in the .got.plt section, which
8247 will be placed in the .got section by the linker script. */
8248 eh->plt_got_offset = htab->sgotplt->size;
8249 htab->sgotplt->size += 4;
8252 /* We also need to make an entry in the .rel(a).plt section. */
8253 htab->srelplt->size += RELOC_SIZE (htab);
8255 /* VxWorks executables have a second set of relocations for
8256 each PLT entry. They go in a separate relocation section,
8257 which is processed by the kernel loader. */
8258 if (htab->vxworks_p && !info->shared)
8260 /* There is a relocation for the initial PLT entry:
8261 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
8262 if (h->plt.offset == htab->plt_header_size)
8263 htab->srelplt2->size += RELOC_SIZE (htab);
8265 /* There are two extra relocations for each subsequent
8266 PLT entry: an R_ARM_32 relocation for the GOT entry,
8267 and an R_ARM_32 relocation for the PLT entry. */
8268 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8273 h->plt.offset = (bfd_vma) -1;
8279 h->plt.offset = (bfd_vma) -1;
8283 if (h->got.refcount > 0)
8287 int tls_type = elf32_arm_hash_entry (h)->tls_type;
8290 /* Make sure this symbol is output as a dynamic symbol.
8291 Undefined weak syms won't yet be marked as dynamic. */
8292 if (h->dynindx == -1
8293 && !h->forced_local)
8295 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8299 if (!htab->symbian_p)
8302 h->got.offset = s->size;
8304 if (tls_type == GOT_UNKNOWN)
8307 if (tls_type == GOT_NORMAL)
8308 /* Non-TLS symbols need one GOT slot. */
8312 if (tls_type & GOT_TLS_GD)
8313 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
8315 if (tls_type & GOT_TLS_IE)
8316 /* R_ARM_TLS_IE32 needs one GOT slot. */
8320 dyn = htab->root.dynamic_sections_created;
8323 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8325 || !SYMBOL_REFERENCES_LOCAL (info, h)))
8328 if (tls_type != GOT_NORMAL
8329 && (info->shared || indx != 0)
8330 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8331 || h->root.type != bfd_link_hash_undefweak))
8333 if (tls_type & GOT_TLS_IE)
8334 htab->srelgot->size += RELOC_SIZE (htab);
8336 if (tls_type & GOT_TLS_GD)
8337 htab->srelgot->size += RELOC_SIZE (htab);
8339 if ((tls_type & GOT_TLS_GD) && indx != 0)
8340 htab->srelgot->size += RELOC_SIZE (htab);
8342 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8343 || h->root.type != bfd_link_hash_undefweak)
8345 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8346 htab->srelgot->size += RELOC_SIZE (htab);
8350 h->got.offset = (bfd_vma) -1;
8352 /* Allocate stubs for exported Thumb functions on v4t. */
8353 if (!htab->use_blx && h->dynindx != -1
8355 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8356 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8358 struct elf_link_hash_entry * th;
8359 struct bfd_link_hash_entry * bh;
8360 struct elf_link_hash_entry * myh;
8364 /* Create a new symbol to regist the real location of the function. */
8365 s = h->root.u.def.section;
8366 sprintf(name, "__real_%s", h->root.root.string);
8367 _bfd_generic_link_add_one_symbol (info, s->owner,
8368 name, BSF_GLOBAL, s,
8369 h->root.u.def.value,
8370 NULL, TRUE, FALSE, &bh);
8372 myh = (struct elf_link_hash_entry *) bh;
8373 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8374 myh->forced_local = 1;
8375 eh->export_glue = myh;
8376 th = record_arm_to_thumb_glue (info, h);
8377 /* Point the symbol at the stub. */
8378 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8379 h->root.u.def.section = th->root.u.def.section;
8380 h->root.u.def.value = th->root.u.def.value & ~1;
8383 if (eh->relocs_copied == NULL)
8386 /* In the shared -Bsymbolic case, discard space allocated for
8387 dynamic pc-relative relocs against symbols which turn out to be
8388 defined in regular objects. For the normal shared case, discard
8389 space for pc-relative relocs that have become local due to symbol
8390 visibility changes. */
8392 if (info->shared || htab->root.is_relocatable_executable)
8394 /* The only relocs that use pc_count are R_ARM_REL32 and
8395 R_ARM_REL32_NOI, which will appear on something like
8396 ".long foo - .". We want calls to protected symbols to resolve
8397 directly to the function rather than going via the plt. If people
8398 want function pointer comparisons to work as expected then they
8399 should avoid writing assembly like ".long foo - .". */
8400 if (SYMBOL_CALLS_LOCAL (info, h))
8402 struct elf32_arm_relocs_copied **pp;
8404 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8406 p->count -= p->pc_count;
8415 /* Also discard relocs on undefined weak syms with non-default
8417 if (eh->relocs_copied != NULL
8418 && h->root.type == bfd_link_hash_undefweak)
8420 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8421 eh->relocs_copied = NULL;
8423 /* Make sure undefined weak symbols are output as a dynamic
8425 else if (h->dynindx == -1
8426 && !h->forced_local)
8428 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8433 else if (htab->root.is_relocatable_executable && h->dynindx == -1
8434 && h->root.type == bfd_link_hash_new)
8436 /* Output absolute symbols so that we can create relocations
8437 against them. For normal symbols we output a relocation
8438 against the section that contains them. */
8439 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8446 /* For the non-shared case, discard space for relocs against
8447 symbols which turn out to need copy relocs or are not
8453 || (htab->root.dynamic_sections_created
8454 && (h->root.type == bfd_link_hash_undefweak
8455 || h->root.type == bfd_link_hash_undefined))))
8457 /* Make sure this symbol is output as a dynamic symbol.
8458 Undefined weak syms won't yet be marked as dynamic. */
8459 if (h->dynindx == -1
8460 && !h->forced_local)
8462 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8466 /* If that succeeded, we know we'll be keeping all the
8468 if (h->dynindx != -1)
8472 eh->relocs_copied = NULL;
8477 /* Finally, allocate space. */
8478 for (p = eh->relocs_copied; p != NULL; p = p->next)
8480 asection *sreloc = elf_section_data (p->section)->sreloc;
8481 sreloc->size += p->count * RELOC_SIZE (htab);
8487 /* Find any dynamic relocs that apply to read-only sections. */
8490 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8492 struct elf32_arm_link_hash_entry *eh;
8493 struct elf32_arm_relocs_copied *p;
8495 if (h->root.type == bfd_link_hash_warning)
8496 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8498 eh = (struct elf32_arm_link_hash_entry *) h;
8499 for (p = eh->relocs_copied; p != NULL; p = p->next)
8501 asection *s = p->section;
8503 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8505 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8507 info->flags |= DF_TEXTREL;
8509 /* Not an error, just cut short the traversal. */
8517 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8520 struct elf32_arm_link_hash_table *globals;
8522 globals = elf32_arm_hash_table (info);
8523 globals->byteswap_code = byteswap_code;
8526 /* Set the sizes of the dynamic sections. */
8529 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8530 struct bfd_link_info * info)
8537 struct elf32_arm_link_hash_table *htab;
8539 htab = elf32_arm_hash_table (info);
8540 dynobj = elf_hash_table (info)->dynobj;
8541 BFD_ASSERT (dynobj != NULL);
8542 check_use_blx (htab);
8544 if (elf_hash_table (info)->dynamic_sections_created)
8546 /* Set the contents of the .interp section to the interpreter. */
8547 if (info->executable)
8549 s = bfd_get_section_by_name (dynobj, ".interp");
8550 BFD_ASSERT (s != NULL);
8551 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8552 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8556 /* Set up .got offsets for local syms, and space for local dynamic
8558 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8560 bfd_signed_vma *local_got;
8561 bfd_signed_vma *end_local_got;
8562 char *local_tls_type;
8563 bfd_size_type locsymcount;
8564 Elf_Internal_Shdr *symtab_hdr;
8567 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8570 for (s = ibfd->sections; s != NULL; s = s->next)
8572 struct elf32_arm_relocs_copied *p;
8574 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
8576 if (!bfd_is_abs_section (p->section)
8577 && bfd_is_abs_section (p->section->output_section))
8579 /* Input section has been discarded, either because
8580 it is a copy of a linkonce section or due to
8581 linker script /DISCARD/, so we'll be discarding
8584 else if (p->count != 0)
8586 srel = elf_section_data (p->section)->sreloc;
8587 srel->size += p->count * RELOC_SIZE (htab);
8588 if ((p->section->output_section->flags & SEC_READONLY) != 0)
8589 info->flags |= DF_TEXTREL;
8594 local_got = elf_local_got_refcounts (ibfd);
8598 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8599 locsymcount = symtab_hdr->sh_info;
8600 end_local_got = local_got + locsymcount;
8601 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8603 srel = htab->srelgot;
8604 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8608 *local_got = s->size;
8609 if (*local_tls_type & GOT_TLS_GD)
8610 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8612 if (*local_tls_type & GOT_TLS_IE)
8614 if (*local_tls_type == GOT_NORMAL)
8617 if (info->shared || *local_tls_type == GOT_TLS_GD)
8618 srel->size += RELOC_SIZE (htab);
8621 *local_got = (bfd_vma) -1;
8625 if (htab->tls_ldm_got.refcount > 0)
8627 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8628 for R_ARM_TLS_LDM32 relocations. */
8629 htab->tls_ldm_got.offset = htab->sgot->size;
8630 htab->sgot->size += 8;
8632 htab->srelgot->size += RELOC_SIZE (htab);
8635 htab->tls_ldm_got.offset = -1;
8637 /* Allocate global sym .plt and .got entries, and space for global
8638 sym dynamic relocs. */
8639 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8641 /* Here we rummage through the found bfds to collect glue information. */
8642 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8644 /* Initialise mapping tables for code/data. */
8645 bfd_elf32_arm_init_maps (ibfd);
8647 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8648 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
8649 /* xgettext:c-format */
8650 _bfd_error_handler (_("Errors encountered processing file %s"),
8654 /* The check_relocs and adjust_dynamic_symbol entry points have
8655 determined the sizes of the various dynamic sections. Allocate
8659 for (s = dynobj->sections; s != NULL; s = s->next)
8663 if ((s->flags & SEC_LINKER_CREATED) == 0)
8666 /* It's OK to base decisions on the section name, because none
8667 of the dynobj section names depend upon the input files. */
8668 name = bfd_get_section_name (dynobj, s);
8670 if (strcmp (name, ".plt") == 0)
8672 /* Remember whether there is a PLT. */
8675 else if (CONST_STRNEQ (name, ".rel"))
8679 /* Remember whether there are any reloc sections other
8680 than .rel(a).plt and .rela.plt.unloaded. */
8681 if (s != htab->srelplt && s != htab->srelplt2)
8684 /* We use the reloc_count field as a counter if we need
8685 to copy relocs into the output file. */
8689 else if (! CONST_STRNEQ (name, ".got")
8690 && strcmp (name, ".dynbss") != 0)
8692 /* It's not one of our sections, so don't allocate space. */
8698 /* If we don't need this section, strip it from the
8699 output file. This is mostly to handle .rel(a).bss and
8700 .rel(a).plt. We must create both sections in
8701 create_dynamic_sections, because they must be created
8702 before the linker maps input sections to output
8703 sections. The linker does that before
8704 adjust_dynamic_symbol is called, and it is that
8705 function which decides whether anything needs to go
8706 into these sections. */
8707 s->flags |= SEC_EXCLUDE;
8711 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8714 /* Allocate memory for the section contents. */
8715 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8716 if (s->contents == NULL)
8720 if (elf_hash_table (info)->dynamic_sections_created)
8722 /* Add some entries to the .dynamic section. We fill in the
8723 values later, in elf32_arm_finish_dynamic_sections, but we
8724 must add the entries now so that we get the correct size for
8725 the .dynamic section. The DT_DEBUG entry is filled in by the
8726 dynamic linker and used by the debugger. */
8727 #define add_dynamic_entry(TAG, VAL) \
8728 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8730 if (info->executable)
8732 if (!add_dynamic_entry (DT_DEBUG, 0))
8738 if ( !add_dynamic_entry (DT_PLTGOT, 0)
8739 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8740 || !add_dynamic_entry (DT_PLTREL,
8741 htab->use_rel ? DT_REL : DT_RELA)
8742 || !add_dynamic_entry (DT_JMPREL, 0))
8750 if (!add_dynamic_entry (DT_REL, 0)
8751 || !add_dynamic_entry (DT_RELSZ, 0)
8752 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8757 if (!add_dynamic_entry (DT_RELA, 0)
8758 || !add_dynamic_entry (DT_RELASZ, 0)
8759 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8764 /* If any dynamic relocs apply to a read-only section,
8765 then we need a DT_TEXTREL entry. */
8766 if ((info->flags & DF_TEXTREL) == 0)
8767 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8770 if ((info->flags & DF_TEXTREL) != 0)
8772 if (!add_dynamic_entry (DT_TEXTREL, 0))
8776 #undef add_dynamic_entry
8781 /* Finish up dynamic symbol handling. We set the contents of various
8782 dynamic sections here. */
8785 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8786 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
8789 struct elf32_arm_link_hash_table *htab;
8790 struct elf32_arm_link_hash_entry *eh;
8792 dynobj = elf_hash_table (info)->dynobj;
8793 htab = elf32_arm_hash_table (info);
8794 eh = (struct elf32_arm_link_hash_entry *) h;
8796 if (h->plt.offset != (bfd_vma) -1)
8802 Elf_Internal_Rela rel;
8804 /* This symbol has an entry in the procedure linkage table. Set
8807 BFD_ASSERT (h->dynindx != -1);
8809 splt = bfd_get_section_by_name (dynobj, ".plt");
8810 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8811 BFD_ASSERT (splt != NULL && srel != NULL);
8813 /* Fill in the entry in the procedure linkage table. */
8814 if (htab->symbian_p)
8816 put_arm_insn (htab, output_bfd,
8817 elf32_arm_symbian_plt_entry[0],
8818 splt->contents + h->plt.offset);
8819 bfd_put_32 (output_bfd,
8820 elf32_arm_symbian_plt_entry[1],
8821 splt->contents + h->plt.offset + 4);
8823 /* Fill in the entry in the .rel.plt section. */
8824 rel.r_offset = (splt->output_section->vma
8825 + splt->output_offset
8826 + h->plt.offset + 4);
8827 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8829 /* Get the index in the procedure linkage table which
8830 corresponds to this symbol. This is the index of this symbol
8831 in all the symbols for which we are making plt entries. The
8832 first entry in the procedure linkage table is reserved. */
8833 plt_index = ((h->plt.offset - htab->plt_header_size)
8834 / htab->plt_entry_size);
8838 bfd_vma got_offset, got_address, plt_address;
8839 bfd_vma got_displacement;
8843 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8844 BFD_ASSERT (sgot != NULL);
8846 /* Get the offset into the .got.plt table of the entry that
8847 corresponds to this function. */
8848 got_offset = eh->plt_got_offset;
8850 /* Get the index in the procedure linkage table which
8851 corresponds to this symbol. This is the index of this symbol
8852 in all the symbols for which we are making plt entries. The
8853 first three entries in .got.plt are reserved; after that
8854 symbols appear in the same order as in .plt. */
8855 plt_index = (got_offset - 12) / 4;
8857 /* Calculate the address of the GOT entry. */
8858 got_address = (sgot->output_section->vma
8859 + sgot->output_offset
8862 /* ...and the address of the PLT entry. */
8863 plt_address = (splt->output_section->vma
8864 + splt->output_offset
8867 ptr = htab->splt->contents + h->plt.offset;
8868 if (htab->vxworks_p && info->shared)
8873 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8875 val = elf32_arm_vxworks_shared_plt_entry[i];
8877 val |= got_address - sgot->output_section->vma;
8879 val |= plt_index * RELOC_SIZE (htab);
8880 if (i == 2 || i == 5)
8881 bfd_put_32 (output_bfd, val, ptr);
8883 put_arm_insn (htab, output_bfd, val, ptr);
8886 else if (htab->vxworks_p)
8891 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8893 val = elf32_arm_vxworks_exec_plt_entry[i];
8897 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8899 val |= plt_index * RELOC_SIZE (htab);
8900 if (i == 2 || i == 5)
8901 bfd_put_32 (output_bfd, val, ptr);
8903 put_arm_insn (htab, output_bfd, val, ptr);
8906 loc = (htab->srelplt2->contents
8907 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8909 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8910 referencing the GOT for this PLT entry. */
8911 rel.r_offset = plt_address + 8;
8912 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8913 rel.r_addend = got_offset;
8914 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8915 loc += RELOC_SIZE (htab);
8917 /* Create the R_ARM_ABS32 relocation referencing the
8918 beginning of the PLT for this GOT entry. */
8919 rel.r_offset = got_address;
8920 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8922 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8926 /* Calculate the displacement between the PLT slot and the
8927 entry in the GOT. The eight-byte offset accounts for the
8928 value produced by adding to pc in the first instruction
8930 got_displacement = got_address - (plt_address + 8);
8932 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8934 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8936 put_thumb_insn (htab, output_bfd,
8937 elf32_arm_plt_thumb_stub[0], ptr - 4);
8938 put_thumb_insn (htab, output_bfd,
8939 elf32_arm_plt_thumb_stub[1], ptr - 2);
8942 put_arm_insn (htab, output_bfd,
8943 elf32_arm_plt_entry[0]
8944 | ((got_displacement & 0x0ff00000) >> 20),
8946 put_arm_insn (htab, output_bfd,
8947 elf32_arm_plt_entry[1]
8948 | ((got_displacement & 0x000ff000) >> 12),
8950 put_arm_insn (htab, output_bfd,
8951 elf32_arm_plt_entry[2]
8952 | (got_displacement & 0x00000fff),
8954 #ifdef FOUR_WORD_PLT
8955 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8959 /* Fill in the entry in the global offset table. */
8960 bfd_put_32 (output_bfd,
8961 (splt->output_section->vma
8962 + splt->output_offset),
8963 sgot->contents + got_offset);
8965 /* Fill in the entry in the .rel(a).plt section. */
8967 rel.r_offset = got_address;
8968 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8971 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8972 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8974 if (!h->def_regular)
8976 /* Mark the symbol as undefined, rather than as defined in
8977 the .plt section. Leave the value alone. */
8978 sym->st_shndx = SHN_UNDEF;
8979 /* If the symbol is weak, we do need to clear the value.
8980 Otherwise, the PLT entry would provide a definition for
8981 the symbol even if the symbol wasn't defined anywhere,
8982 and so the symbol would never be NULL. */
8983 if (!h->ref_regular_nonweak)
8988 if (h->got.offset != (bfd_vma) -1
8989 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8990 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
8994 Elf_Internal_Rela rel;
8998 /* This symbol has an entry in the global offset table. Set it
9000 sgot = bfd_get_section_by_name (dynobj, ".got");
9001 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
9002 BFD_ASSERT (sgot != NULL && srel != NULL);
9004 offset = (h->got.offset & ~(bfd_vma) 1);
9006 rel.r_offset = (sgot->output_section->vma
9007 + sgot->output_offset
9010 /* If this is a static link, or it is a -Bsymbolic link and the
9011 symbol is defined locally or was forced to be local because
9012 of a version file, we just want to emit a RELATIVE reloc.
9013 The entry in the global offset table will already have been
9014 initialized in the relocate_section function. */
9016 && SYMBOL_REFERENCES_LOCAL (info, h))
9018 BFD_ASSERT((h->got.offset & 1) != 0);
9019 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9022 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
9023 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9028 BFD_ASSERT((h->got.offset & 1) == 0);
9029 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9030 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9033 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
9034 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9040 Elf_Internal_Rela rel;
9043 /* This symbol needs a copy reloc. Set it up. */
9044 BFD_ASSERT (h->dynindx != -1
9045 && (h->root.type == bfd_link_hash_defined
9046 || h->root.type == bfd_link_hash_defweak));
9048 s = bfd_get_section_by_name (h->root.u.def.section->owner,
9049 RELOC_SECTION (htab, ".bss"));
9050 BFD_ASSERT (s != NULL);
9053 rel.r_offset = (h->root.u.def.value
9054 + h->root.u.def.section->output_section->vma
9055 + h->root.u.def.section->output_offset);
9056 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
9057 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9058 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9061 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
9062 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9063 to the ".got" section. */
9064 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
9065 || (!htab->vxworks_p && h == htab->root.hgot))
9066 sym->st_shndx = SHN_ABS;
9071 /* Finish up the dynamic sections. */
9074 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
9080 dynobj = elf_hash_table (info)->dynobj;
9082 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9083 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
9084 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9086 if (elf_hash_table (info)->dynamic_sections_created)
9089 Elf32_External_Dyn *dyncon, *dynconend;
9090 struct elf32_arm_link_hash_table *htab;
9092 htab = elf32_arm_hash_table (info);
9093 splt = bfd_get_section_by_name (dynobj, ".plt");
9094 BFD_ASSERT (splt != NULL && sdyn != NULL);
9096 dyncon = (Elf32_External_Dyn *) sdyn->contents;
9097 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9099 for (; dyncon < dynconend; dyncon++)
9101 Elf_Internal_Dyn dyn;
9105 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9116 goto get_vma_if_bpabi;
9119 goto get_vma_if_bpabi;
9122 goto get_vma_if_bpabi;
9124 name = ".gnu.version";
9125 goto get_vma_if_bpabi;
9127 name = ".gnu.version_d";
9128 goto get_vma_if_bpabi;
9130 name = ".gnu.version_r";
9131 goto get_vma_if_bpabi;
9137 name = RELOC_SECTION (htab, ".plt");
9139 s = bfd_get_section_by_name (output_bfd, name);
9140 BFD_ASSERT (s != NULL);
9141 if (!htab->symbian_p)
9142 dyn.d_un.d_ptr = s->vma;
9144 /* In the BPABI, tags in the PT_DYNAMIC section point
9145 at the file offset, not the memory address, for the
9146 convenience of the post linker. */
9147 dyn.d_un.d_ptr = s->filepos;
9148 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9152 if (htab->symbian_p)
9157 s = bfd_get_section_by_name (output_bfd,
9158 RELOC_SECTION (htab, ".plt"));
9159 BFD_ASSERT (s != NULL);
9160 dyn.d_un.d_val = s->size;
9161 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9166 if (!htab->symbian_p)
9168 /* My reading of the SVR4 ABI indicates that the
9169 procedure linkage table relocs (DT_JMPREL) should be
9170 included in the overall relocs (DT_REL). This is
9171 what Solaris does. However, UnixWare can not handle
9172 that case. Therefore, we override the DT_RELSZ entry
9173 here to make it not include the JMPREL relocs. Since
9174 the linker script arranges for .rel(a).plt to follow all
9175 other relocation sections, we don't have to worry
9176 about changing the DT_REL entry. */
9177 s = bfd_get_section_by_name (output_bfd,
9178 RELOC_SECTION (htab, ".plt"));
9180 dyn.d_un.d_val -= s->size;
9181 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9188 /* In the BPABI, the DT_REL tag must point at the file
9189 offset, not the VMA, of the first relocation
9190 section. So, we use code similar to that in
9191 elflink.c, but do not check for SHF_ALLOC on the
9192 relcoation section, since relocations sections are
9193 never allocated under the BPABI. The comments above
9194 about Unixware notwithstanding, we include all of the
9195 relocations here. */
9196 if (htab->symbian_p)
9199 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9200 ? SHT_REL : SHT_RELA);
9202 for (i = 1; i < elf_numsections (output_bfd); i++)
9204 Elf_Internal_Shdr *hdr
9205 = elf_elfsections (output_bfd)[i];
9206 if (hdr->sh_type == type)
9208 if (dyn.d_tag == DT_RELSZ
9209 || dyn.d_tag == DT_RELASZ)
9210 dyn.d_un.d_val += hdr->sh_size;
9211 else if ((ufile_ptr) hdr->sh_offset
9212 <= dyn.d_un.d_val - 1)
9213 dyn.d_un.d_val = hdr->sh_offset;
9216 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9220 /* Set the bottom bit of DT_INIT/FINI if the
9221 corresponding function is Thumb. */
9223 name = info->init_function;
9226 name = info->fini_function;
9228 /* If it wasn't set by elf_bfd_final_link
9229 then there is nothing to adjust. */
9230 if (dyn.d_un.d_val != 0)
9232 struct elf_link_hash_entry * eh;
9234 eh = elf_link_hash_lookup (elf_hash_table (info), name,
9235 FALSE, FALSE, TRUE);
9236 if (eh != (struct elf_link_hash_entry *) NULL
9237 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9239 dyn.d_un.d_val |= 1;
9240 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9247 /* Fill in the first entry in the procedure linkage table. */
9248 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
9250 const bfd_vma *plt0_entry;
9251 bfd_vma got_address, plt_address, got_displacement;
9253 /* Calculate the addresses of the GOT and PLT. */
9254 got_address = sgot->output_section->vma + sgot->output_offset;
9255 plt_address = splt->output_section->vma + splt->output_offset;
9257 if (htab->vxworks_p)
9259 /* The VxWorks GOT is relocated by the dynamic linker.
9260 Therefore, we must emit relocations rather than simply
9261 computing the values now. */
9262 Elf_Internal_Rela rel;
9264 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
9265 put_arm_insn (htab, output_bfd, plt0_entry[0],
9266 splt->contents + 0);
9267 put_arm_insn (htab, output_bfd, plt0_entry[1],
9268 splt->contents + 4);
9269 put_arm_insn (htab, output_bfd, plt0_entry[2],
9270 splt->contents + 8);
9271 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9273 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9274 rel.r_offset = plt_address + 12;
9275 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9277 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9278 htab->srelplt2->contents);
9282 got_displacement = got_address - (plt_address + 16);
9284 plt0_entry = elf32_arm_plt0_entry;
9285 put_arm_insn (htab, output_bfd, plt0_entry[0],
9286 splt->contents + 0);
9287 put_arm_insn (htab, output_bfd, plt0_entry[1],
9288 splt->contents + 4);
9289 put_arm_insn (htab, output_bfd, plt0_entry[2],
9290 splt->contents + 8);
9291 put_arm_insn (htab, output_bfd, plt0_entry[3],
9292 splt->contents + 12);
9294 #ifdef FOUR_WORD_PLT
9295 /* The displacement value goes in the otherwise-unused
9296 last word of the second entry. */
9297 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
9299 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
9304 /* UnixWare sets the entsize of .plt to 4, although that doesn't
9305 really seem like the right value. */
9306 if (splt->output_section->owner == output_bfd)
9307 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
9309 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9311 /* Correct the .rel(a).plt.unloaded relocations. They will have
9312 incorrect symbol indexes. */
9316 num_plts = ((htab->splt->size - htab->plt_header_size)
9317 / htab->plt_entry_size);
9318 p = htab->srelplt2->contents + RELOC_SIZE (htab);
9320 for (; num_plts; num_plts--)
9322 Elf_Internal_Rela rel;
9324 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9325 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9326 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9327 p += RELOC_SIZE (htab);
9329 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9330 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9331 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9332 p += RELOC_SIZE (htab);
9337 /* Fill in the first three entries in the global offset table. */
9343 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9345 bfd_put_32 (output_bfd,
9346 sdyn->output_section->vma + sdyn->output_offset,
9348 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9349 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9352 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9359 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9361 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
9362 struct elf32_arm_link_hash_table *globals;
9364 i_ehdrp = elf_elfheader (abfd);
9366 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
9367 i_ehdrp->e_ident[EI_OSABI] = ARM_ELF_OS_ABI_VERSION;
9369 i_ehdrp->e_ident[EI_OSABI] = 0;
9370 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
9374 globals = elf32_arm_hash_table (link_info);
9375 if (globals->byteswap_code)
9376 i_ehdrp->e_flags |= EF_ARM_BE8;
9380 * For EABI 5, we have to tag dynamic binaries and execs as either
9381 * soft float or hard float.
9383 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_VER5 &&
9384 (i_ehdrp->e_type == ET_DYN || i_ehdrp->e_type == ET_EXEC))
9386 bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ABI_VFP_args) ?
9387 EF_ARM_VFP_FLOAT : EF_ARM_SOFT_FLOAT;
9390 static enum elf_reloc_type_class
9391 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
9393 switch ((int) ELF32_R_TYPE (rela->r_info))
9395 case R_ARM_RELATIVE:
9396 return reloc_class_relative;
9397 case R_ARM_JUMP_SLOT:
9398 return reloc_class_plt;
9400 return reloc_class_copy;
9402 return reloc_class_normal;
9406 /* Set the right machine number for an Arm ELF file. */
9409 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
9411 if (hdr->sh_type == SHT_NOTE)
9412 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9418 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
9420 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
9423 /* Return TRUE if this is an unwinding table entry. */
9426 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9428 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9429 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
9433 /* Set the type and flags for an ARM section. We do this by
9434 the section name, which is a hack, but ought to work. */
9437 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9441 name = bfd_get_section_name (abfd, sec);
9443 if (is_arm_elf_unwind_section_name (abfd, name))
9445 hdr->sh_type = SHT_ARM_EXIDX;
9446 hdr->sh_flags |= SHF_LINK_ORDER;
9451 /* Handle an ARM specific section when reading an object file. This is
9452 called when bfd_section_from_shdr finds a section with an unknown
9456 elf32_arm_section_from_shdr (bfd *abfd,
9457 Elf_Internal_Shdr * hdr,
9461 /* There ought to be a place to keep ELF backend specific flags, but
9462 at the moment there isn't one. We just keep track of the
9463 sections by their name, instead. Fortunately, the ABI gives
9464 names for all the ARM specific sections, so we will probably get
9466 switch (hdr->sh_type)
9469 case SHT_ARM_PREEMPTMAP:
9470 case SHT_ARM_ATTRIBUTES:
9477 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
9483 /* A structure used to record a list of sections, independently
9484 of the next and prev fields in the asection structure. */
9485 typedef struct section_list
9488 struct section_list * next;
9489 struct section_list * prev;
9493 /* Unfortunately we need to keep a list of sections for which
9494 an _arm_elf_section_data structure has been allocated. This
9495 is because it is possible for functions like elf32_arm_write_section
9496 to be called on a section which has had an elf_data_structure
9497 allocated for it (and so the used_by_bfd field is valid) but
9498 for which the ARM extended version of this structure - the
9499 _arm_elf_section_data structure - has not been allocated. */
9500 static section_list * sections_with_arm_elf_section_data = NULL;
9503 record_section_with_arm_elf_section_data (asection * sec)
9505 struct section_list * entry;
9507 entry = bfd_malloc (sizeof (* entry));
9511 entry->next = sections_with_arm_elf_section_data;
9513 if (entry->next != NULL)
9514 entry->next->prev = entry;
9515 sections_with_arm_elf_section_data = entry;
9518 static struct section_list *
9519 find_arm_elf_section_entry (asection * sec)
9521 struct section_list * entry;
9522 static struct section_list * last_entry = NULL;
9524 /* This is a short cut for the typical case where the sections are added
9525 to the sections_with_arm_elf_section_data list in forward order and
9526 then looked up here in backwards order. This makes a real difference
9527 to the ld-srec/sec64k.exp linker test. */
9528 entry = sections_with_arm_elf_section_data;
9529 if (last_entry != NULL)
9531 if (last_entry->sec == sec)
9533 else if (last_entry->next != NULL
9534 && last_entry->next->sec == sec)
9535 entry = last_entry->next;
9538 for (; entry; entry = entry->next)
9539 if (entry->sec == sec)
9543 /* Record the entry prior to this one - it is the entry we are most
9544 likely to want to locate next time. Also this way if we have been
9545 called from unrecord_section_with_arm_elf_section_data() we will not
9546 be caching a pointer that is about to be freed. */
9547 last_entry = entry->prev;
9552 static _arm_elf_section_data *
9553 get_arm_elf_section_data (asection * sec)
9555 struct section_list * entry;
9557 entry = find_arm_elf_section_entry (sec);
9560 return elf32_arm_section_data (entry->sec);
9566 unrecord_section_with_arm_elf_section_data (asection * sec)
9568 struct section_list * entry;
9570 entry = find_arm_elf_section_entry (sec);
9574 if (entry->prev != NULL)
9575 entry->prev->next = entry->next;
9576 if (entry->next != NULL)
9577 entry->next->prev = entry->prev;
9578 if (entry == sections_with_arm_elf_section_data)
9579 sections_with_arm_elf_section_data = entry->next;
9588 struct bfd_link_info *info;
9591 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9592 asection *, struct elf_link_hash_entry *);
9593 } output_arch_syminfo;
9595 enum map_symbol_type
9603 /* Output a single PLT mapping symbol. */
9606 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9607 enum map_symbol_type type,
9610 static const char *names[3] = {"$a", "$t", "$d"};
9611 struct elf32_arm_link_hash_table *htab;
9612 Elf_Internal_Sym sym;
9614 htab = elf32_arm_hash_table (osi->info);
9615 sym.st_value = osi->sec->output_section->vma
9616 + osi->sec->output_offset
9620 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
9621 sym.st_shndx = osi->sec_shndx;
9622 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
9628 /* Output mapping symbols for PLT entries associated with H. */
9631 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9633 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9634 struct elf32_arm_link_hash_table *htab;
9635 struct elf32_arm_link_hash_entry *eh;
9638 htab = elf32_arm_hash_table (osi->info);
9640 if (h->root.type == bfd_link_hash_indirect)
9643 if (h->root.type == bfd_link_hash_warning)
9644 /* When warning symbols are created, they **replace** the "real"
9645 entry in the hash table, thus we never get to see the real
9646 symbol in a hash traversal. So look at it now. */
9647 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9649 if (h->plt.offset == (bfd_vma) -1)
9652 eh = (struct elf32_arm_link_hash_entry *) h;
9653 addr = h->plt.offset;
9654 if (htab->symbian_p)
9656 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9658 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9661 else if (htab->vxworks_p)
9663 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9665 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9667 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9669 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9674 bfd_boolean thumb_stub;
9676 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9679 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9682 #ifdef FOUR_WORD_PLT
9683 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9685 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9688 /* A three-word PLT with no Thumb thunk contains only Arm code,
9689 so only need to output a mapping symbol for the first PLT entry and
9690 entries with thumb thunks. */
9691 if (thumb_stub || addr == 20)
9693 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9703 /* Output mapping symbols for linker generated sections. */
9706 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9707 struct bfd_link_info *info,
9708 void *finfo, bfd_boolean (*func) (void *, const char *,
9711 struct elf_link_hash_entry *))
9713 output_arch_syminfo osi;
9714 struct elf32_arm_link_hash_table *htab;
9718 htab = elf32_arm_hash_table (info);
9719 check_use_blx(htab);
9725 /* ARM->Thumb glue. */
9726 if (htab->arm_glue_size > 0)
9728 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9729 ARM2THUMB_GLUE_SECTION_NAME);
9731 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9732 (output_bfd, osi.sec->output_section);
9733 if (info->shared || htab->root.is_relocatable_executable
9734 || htab->pic_veneer)
9735 size = ARM2THUMB_PIC_GLUE_SIZE;
9736 else if (htab->use_blx)
9737 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
9739 size = ARM2THUMB_STATIC_GLUE_SIZE;
9741 for (offset = 0; offset < htab->arm_glue_size; offset += size)
9743 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset);
9744 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
9748 /* Thumb->ARM glue. */
9749 if (htab->thumb_glue_size > 0)
9751 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9752 THUMB2ARM_GLUE_SECTION_NAME);
9754 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9755 (output_bfd, osi.sec->output_section);
9756 size = THUMB2ARM_GLUE_SIZE;
9758 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
9760 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset);
9761 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4);
9765 /* Finally, output mapping symbols for the PLT. */
9766 if (!htab->splt || htab->splt->size == 0)
9769 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9770 htab->splt->output_section);
9771 osi.sec = htab->splt;
9772 /* Output mapping symbols for the plt header. SymbianOS does not have a
9774 if (htab->vxworks_p)
9776 /* VxWorks shared libraries have no PLT header. */
9779 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9781 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9785 else if (!htab->symbian_p)
9787 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9789 #ifndef FOUR_WORD_PLT
9790 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9795 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9799 /* Allocate target specific section data. */
9802 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9804 if (!sec->used_by_bfd)
9806 _arm_elf_section_data *sdata;
9807 bfd_size_type amt = sizeof (*sdata);
9809 sdata = bfd_zalloc (abfd, amt);
9812 sec->used_by_bfd = sdata;
9815 record_section_with_arm_elf_section_data (sec);
9817 return _bfd_elf_new_section_hook (abfd, sec);
9821 /* Used to order a list of mapping symbols by address. */
9824 elf32_arm_compare_mapping (const void * a, const void * b)
9826 return ((const elf32_arm_section_map *) a)->vma
9827 > ((const elf32_arm_section_map *) b)->vma;
9831 /* Do code byteswapping. Return FALSE afterwards so that the section is
9832 written out as normal. */
9835 elf32_arm_write_section (bfd *output_bfd,
9836 struct bfd_link_info *link_info, asection *sec,
9839 int mapcount, errcount;
9840 _arm_elf_section_data *arm_data;
9841 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
9842 elf32_arm_section_map *map;
9843 elf32_vfp11_erratum_list *errnode;
9846 bfd_vma offset = sec->output_section->vma + sec->output_offset;
9850 /* If this section has not been allocated an _arm_elf_section_data
9851 structure then we cannot record anything. */
9852 arm_data = get_arm_elf_section_data (sec);
9853 if (arm_data == NULL)
9856 mapcount = arm_data->mapcount;
9857 map = arm_data->map;
9858 errcount = arm_data->erratumcount;
9862 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
9864 for (errnode = arm_data->erratumlist; errnode != 0;
9865 errnode = errnode->next)
9867 bfd_vma index = errnode->vma - offset;
9869 switch (errnode->type)
9871 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
9873 bfd_vma branch_to_veneer;
9874 /* Original condition code of instruction, plus bit mask for
9875 ARM B instruction. */
9876 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
9879 /* The instruction is before the label. */
9882 /* Above offset included in -4 below. */
9883 branch_to_veneer = errnode->u.b.veneer->vma
9886 if ((signed) branch_to_veneer < -(1 << 25)
9887 || (signed) branch_to_veneer >= (1 << 25))
9888 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9889 "range"), output_bfd);
9891 insn |= (branch_to_veneer >> 2) & 0xffffff;
9892 contents[endianflip ^ index] = insn & 0xff;
9893 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9894 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9895 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9899 case VFP11_ERRATUM_ARM_VENEER:
9901 bfd_vma branch_from_veneer;
9904 /* Take size of veneer into account. */
9905 branch_from_veneer = errnode->u.v.branch->vma
9906 - errnode->vma - 12;
9908 if ((signed) branch_from_veneer < -(1 << 25)
9909 || (signed) branch_from_veneer >= (1 << 25))
9910 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9911 "range"), output_bfd);
9913 /* Original instruction. */
9914 insn = errnode->u.v.branch->u.b.vfp_insn;
9915 contents[endianflip ^ index] = insn & 0xff;
9916 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9917 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9918 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9920 /* Branch back to insn after original insn. */
9921 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
9922 contents[endianflip ^ (index + 4)] = insn & 0xff;
9923 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
9924 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
9925 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
9938 if (globals->byteswap_code)
9940 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9943 for (i = 0; i < mapcount; i++)
9945 if (i == mapcount - 1)
9948 end = map[i + 1].vma;
9950 switch (map[i].type)
9953 /* Byte swap code words. */
9954 while (ptr + 3 < end)
9956 tmp = contents[ptr];
9957 contents[ptr] = contents[ptr + 3];
9958 contents[ptr + 3] = tmp;
9959 tmp = contents[ptr + 1];
9960 contents[ptr + 1] = contents[ptr + 2];
9961 contents[ptr + 2] = tmp;
9967 /* Byte swap code halfwords. */
9968 while (ptr + 1 < end)
9970 tmp = contents[ptr];
9971 contents[ptr] = contents[ptr + 1];
9972 contents[ptr + 1] = tmp;
9978 /* Leave data alone. */
9986 arm_data->mapcount = 0;
9987 arm_data->mapsize = 0;
9988 arm_data->map = NULL;
9989 unrecord_section_with_arm_elf_section_data (sec);
9995 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
9997 void * ignore ATTRIBUTE_UNUSED)
9999 unrecord_section_with_arm_elf_section_data (sec);
10003 elf32_arm_close_and_cleanup (bfd * abfd)
10005 if (abfd->sections)
10006 bfd_map_over_sections (abfd,
10007 unrecord_section_via_map_over_sections,
10010 return _bfd_elf_close_and_cleanup (abfd);
10014 elf32_arm_bfd_free_cached_info (bfd * abfd)
10016 if (abfd->sections)
10017 bfd_map_over_sections (abfd,
10018 unrecord_section_via_map_over_sections,
10021 return _bfd_free_cached_info (abfd);
10024 /* Display STT_ARM_TFUNC symbols as functions. */
10027 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
10030 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10032 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10033 elfsym->symbol.flags |= BSF_FUNCTION;
10037 /* Mangle thumb function symbols as we read them in. */
10040 elf32_arm_swap_symbol_in (bfd * abfd,
10043 Elf_Internal_Sym *dst)
10045 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10048 /* New EABI objects mark thumb function symbols by setting the low bit of
10049 the address. Turn these into STT_ARM_TFUNC. */
10050 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10051 && (dst->st_value & 1))
10053 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10054 dst->st_value &= ~(bfd_vma) 1;
10060 /* Mangle thumb function symbols as we write them out. */
10063 elf32_arm_swap_symbol_out (bfd *abfd,
10064 const Elf_Internal_Sym *src,
10068 Elf_Internal_Sym newsym;
10070 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10071 of the address set, as per the new EABI. We do this unconditionally
10072 because objcopy does not set the elf header flags until after
10073 it writes out the symbol table. */
10074 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10077 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
10078 if (newsym.st_shndx != SHN_UNDEF)
10080 /* Do this only for defined symbols. At link type, the static
10081 linker will simulate the work of dynamic linker of resolving
10082 symbols and will carry over the thumbness of found symbols to
10083 the output symbol table. It's not clear how it happens, but
10084 the thumbness of undefined symbols can well be different at
10085 runtime, and writing '1' for them will be confusing for users
10086 and possibly for dynamic linker itself.
10088 newsym.st_value |= 1;
10093 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10096 /* Add the PT_ARM_EXIDX program header. */
10099 elf32_arm_modify_segment_map (bfd *abfd,
10100 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10102 struct elf_segment_map *m;
10105 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10106 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10108 /* If there is already a PT_ARM_EXIDX header, then we do not
10109 want to add another one. This situation arises when running
10110 "strip"; the input binary already has the header. */
10111 m = elf_tdata (abfd)->segment_map;
10112 while (m && m->p_type != PT_ARM_EXIDX)
10116 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10119 m->p_type = PT_ARM_EXIDX;
10121 m->sections[0] = sec;
10123 m->next = elf_tdata (abfd)->segment_map;
10124 elf_tdata (abfd)->segment_map = m;
10131 /* We may add a PT_ARM_EXIDX program header. */
10134 elf32_arm_additional_program_headers (bfd *abfd,
10135 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10139 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10140 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10146 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
10148 elf32_arm_is_function_type (unsigned int type)
10150 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10153 /* We use this to override swap_symbol_in and swap_symbol_out. */
10154 const struct elf_size_info elf32_arm_size_info = {
10155 sizeof (Elf32_External_Ehdr),
10156 sizeof (Elf32_External_Phdr),
10157 sizeof (Elf32_External_Shdr),
10158 sizeof (Elf32_External_Rel),
10159 sizeof (Elf32_External_Rela),
10160 sizeof (Elf32_External_Sym),
10161 sizeof (Elf32_External_Dyn),
10162 sizeof (Elf_External_Note),
10166 ELFCLASS32, EV_CURRENT,
10167 bfd_elf32_write_out_phdrs,
10168 bfd_elf32_write_shdrs_and_ehdr,
10169 bfd_elf32_write_relocs,
10170 elf32_arm_swap_symbol_in,
10171 elf32_arm_swap_symbol_out,
10172 bfd_elf32_slurp_reloc_table,
10173 bfd_elf32_slurp_symbol_table,
10174 bfd_elf32_swap_dyn_in,
10175 bfd_elf32_swap_dyn_out,
10176 bfd_elf32_swap_reloc_in,
10177 bfd_elf32_swap_reloc_out,
10178 bfd_elf32_swap_reloca_in,
10179 bfd_elf32_swap_reloca_out
10182 #define ELF_ARCH bfd_arch_arm
10183 #define ELF_MACHINE_CODE EM_ARM
10184 #ifdef __QNXTARGET__
10185 #define ELF_MAXPAGESIZE 0x1000
10187 #define ELF_MAXPAGESIZE 0x8000
10189 #define ELF_MINPAGESIZE 0x1000
10190 #define ELF_COMMONPAGESIZE 0x1000
10192 #define bfd_elf32_mkobject elf32_arm_mkobject
10194 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
10195 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
10196 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
10197 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
10198 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
10199 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
10200 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
10201 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
10202 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
10203 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
10204 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
10205 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
10206 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
10208 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
10209 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
10210 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
10211 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
10212 #define elf_backend_check_relocs elf32_arm_check_relocs
10213 #define elf_backend_relocate_section elf32_arm_relocate_section
10214 #define elf_backend_write_section elf32_arm_write_section
10215 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
10216 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
10217 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
10218 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
10219 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
10220 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
10221 #define elf_backend_post_process_headers elf32_arm_post_process_headers
10222 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
10223 #define elf_backend_object_p elf32_arm_object_p
10224 #define elf_backend_section_flags elf32_arm_section_flags
10225 #define elf_backend_fake_sections elf32_arm_fake_sections
10226 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
10227 #define elf_backend_final_write_processing elf32_arm_final_write_processing
10228 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
10229 #define elf_backend_symbol_processing elf32_arm_symbol_processing
10230 #define elf_backend_size_info elf32_arm_size_info
10231 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
10232 #define elf_backend_additional_program_headers \
10233 elf32_arm_additional_program_headers
10234 #define elf_backend_output_arch_local_syms \
10235 elf32_arm_output_arch_local_syms
10236 #define elf_backend_begin_write_processing \
10237 elf32_arm_begin_write_processing
10238 #define elf_backend_is_function_type elf32_arm_is_function_type
10240 #define elf_backend_can_refcount 1
10241 #define elf_backend_can_gc_sections 1
10242 #define elf_backend_plt_readonly 1
10243 #define elf_backend_want_got_plt 1
10244 #define elf_backend_want_plt_sym 0
10245 #define elf_backend_may_use_rel_p 1
10246 #define elf_backend_may_use_rela_p 0
10247 #define elf_backend_default_use_rela_p 0
10249 #define elf_backend_got_header_size 12
10251 #undef elf_backend_obj_attrs_vendor
10252 #define elf_backend_obj_attrs_vendor "aeabi"
10253 #undef elf_backend_obj_attrs_section
10254 #define elf_backend_obj_attrs_section ".ARM.attributes"
10255 #undef elf_backend_obj_attrs_arg_type
10256 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
10257 #undef elf_backend_obj_attrs_section_type
10258 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
10260 #include "elf32-target.h"
10262 /* VxWorks Targets */
10264 #undef TARGET_LITTLE_SYM
10265 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
10266 #undef TARGET_LITTLE_NAME
10267 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
10268 #undef TARGET_BIG_SYM
10269 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
10270 #undef TARGET_BIG_NAME
10271 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
10273 /* Like elf32_arm_link_hash_table_create -- but overrides
10274 appropriately for VxWorks. */
10275 static struct bfd_link_hash_table *
10276 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10278 struct bfd_link_hash_table *ret;
10280 ret = elf32_arm_link_hash_table_create (abfd);
10283 struct elf32_arm_link_hash_table *htab
10284 = (struct elf32_arm_link_hash_table *) ret;
10286 htab->vxworks_p = 1;
10292 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10294 elf32_arm_final_write_processing (abfd, linker);
10295 elf_vxworks_final_write_processing (abfd, linker);
10299 #define elf32_bed elf32_arm_vxworks_bed
10301 #undef bfd_elf32_bfd_link_hash_table_create
10302 #define bfd_elf32_bfd_link_hash_table_create \
10303 elf32_arm_vxworks_link_hash_table_create
10304 #undef elf_backend_add_symbol_hook
10305 #define elf_backend_add_symbol_hook \
10306 elf_vxworks_add_symbol_hook
10307 #undef elf_backend_final_write_processing
10308 #define elf_backend_final_write_processing \
10309 elf32_arm_vxworks_final_write_processing
10310 #undef elf_backend_emit_relocs
10311 #define elf_backend_emit_relocs \
10312 elf_vxworks_emit_relocs
10314 #undef elf_backend_may_use_rel_p
10315 #define elf_backend_may_use_rel_p 0
10316 #undef elf_backend_may_use_rela_p
10317 #define elf_backend_may_use_rela_p 1
10318 #undef elf_backend_default_use_rela_p
10319 #define elf_backend_default_use_rela_p 1
10320 #undef elf_backend_want_plt_sym
10321 #define elf_backend_want_plt_sym 1
10322 #undef ELF_MAXPAGESIZE
10323 #define ELF_MAXPAGESIZE 0x1000
10325 #include "elf32-target.h"
10328 /* Symbian OS Targets */
10330 #undef TARGET_LITTLE_SYM
10331 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
10332 #undef TARGET_LITTLE_NAME
10333 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
10334 #undef TARGET_BIG_SYM
10335 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
10336 #undef TARGET_BIG_NAME
10337 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
10339 /* Like elf32_arm_link_hash_table_create -- but overrides
10340 appropriately for Symbian OS. */
10341 static struct bfd_link_hash_table *
10342 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10344 struct bfd_link_hash_table *ret;
10346 ret = elf32_arm_link_hash_table_create (abfd);
10349 struct elf32_arm_link_hash_table *htab
10350 = (struct elf32_arm_link_hash_table *)ret;
10351 /* There is no PLT header for Symbian OS. */
10352 htab->plt_header_size = 0;
10353 /* The PLT entries are each three instructions. */
10354 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10355 htab->symbian_p = 1;
10356 /* Symbian uses armv5t or above, so use_blx is always true. */
10358 htab->root.is_relocatable_executable = 1;
10363 static const struct bfd_elf_special_section
10364 elf32_arm_symbian_special_sections[] =
10366 /* In a BPABI executable, the dynamic linking sections do not go in
10367 the loadable read-only segment. The post-linker may wish to
10368 refer to these sections, but they are not part of the final
10370 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
10371 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
10372 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
10373 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
10374 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
10375 /* These sections do not need to be writable as the SymbianOS
10376 postlinker will arrange things so that no dynamic relocation is
10378 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
10379 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
10380 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10381 { NULL, 0, 0, 0, 0 }
10385 elf32_arm_symbian_begin_write_processing (bfd *abfd,
10386 struct bfd_link_info *link_info)
10388 /* BPABI objects are never loaded directly by an OS kernel; they are
10389 processed by a postlinker first, into an OS-specific format. If
10390 the D_PAGED bit is set on the file, BFD will align segments on
10391 page boundaries, so that an OS can directly map the file. With
10392 BPABI objects, that just results in wasted space. In addition,
10393 because we clear the D_PAGED bit, map_sections_to_segments will
10394 recognize that the program headers should not be mapped into any
10395 loadable segment. */
10396 abfd->flags &= ~D_PAGED;
10397 elf32_arm_begin_write_processing(abfd, link_info);
10401 elf32_arm_symbian_modify_segment_map (bfd *abfd,
10402 struct bfd_link_info *info)
10404 struct elf_segment_map *m;
10407 /* BPABI shared libraries and executables should have a PT_DYNAMIC
10408 segment. However, because the .dynamic section is not marked
10409 with SEC_LOAD, the generic ELF code will not create such a
10411 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10414 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10415 if (m->p_type == PT_DYNAMIC)
10420 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10421 m->next = elf_tdata (abfd)->segment_map;
10422 elf_tdata (abfd)->segment_map = m;
10426 /* Also call the generic arm routine. */
10427 return elf32_arm_modify_segment_map (abfd, info);
10431 #define elf32_bed elf32_arm_symbian_bed
10433 /* The dynamic sections are not allocated on SymbianOS; the postlinker
10434 will process them and then discard them. */
10435 #undef ELF_DYNAMIC_SEC_FLAGS
10436 #define ELF_DYNAMIC_SEC_FLAGS \
10437 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10439 #undef bfd_elf32_bfd_link_hash_table_create
10440 #define bfd_elf32_bfd_link_hash_table_create \
10441 elf32_arm_symbian_link_hash_table_create
10442 #undef elf_backend_add_symbol_hook
10444 #undef elf_backend_special_sections
10445 #define elf_backend_special_sections elf32_arm_symbian_special_sections
10447 #undef elf_backend_begin_write_processing
10448 #define elf_backend_begin_write_processing \
10449 elf32_arm_symbian_begin_write_processing
10450 #undef elf_backend_final_write_processing
10451 #define elf_backend_final_write_processing \
10452 elf32_arm_final_write_processing
10453 #undef elf_backend_emit_relocs
10455 #undef elf_backend_modify_segment_map
10456 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10458 /* There is no .got section for BPABI objects, and hence no header. */
10459 #undef elf_backend_got_header_size
10460 #define elf_backend_got_header_size 0
10462 /* Similarly, there is no .got.plt section. */
10463 #undef elf_backend_want_got_plt
10464 #define elf_backend_want_got_plt 0
10466 #undef elf_backend_may_use_rel_p
10467 #define elf_backend_may_use_rel_p 1
10468 #undef elf_backend_may_use_rela_p
10469 #define elf_backend_may_use_rela_p 0
10470 #undef elf_backend_default_use_rela_p
10471 #define elf_backend_default_use_rela_p 0
10472 #undef elf_backend_want_plt_sym
10473 #define elf_backend_want_plt_sym 0
10474 #undef ELF_MAXPAGESIZE
10475 #define ELF_MAXPAGESIZE 0x8000
10477 #include "elf32-target.h"