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)
6798 (_("ERROR: %B uses VFP register arguments, %B does not"),
6804 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
6806 /* Merge this attribute with existing attributes. */
6809 case Tag_CPU_raw_name:
6811 /* Use whichever has the greatest architecture requirements. We
6812 won't necessarily have both the above tags, so make sure input
6813 name is non-NULL. */
6814 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6816 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
6819 case Tag_ABI_optimization_goals:
6820 case Tag_ABI_FP_optimization_goals:
6821 /* Use the first value seen. */
6825 case Tag_ARM_ISA_use:
6826 case Tag_THUMB_ISA_use:
6830 /* ??? Do NEON and WMMX conflict? */
6831 case Tag_ABI_FP_rounding:
6832 case Tag_ABI_FP_denormal:
6833 case Tag_ABI_FP_exceptions:
6834 case Tag_ABI_FP_user_exceptions:
6835 case Tag_ABI_FP_number_model:
6836 case Tag_ABI_align8_preserved:
6837 case Tag_ABI_HardFP_use:
6838 /* Use the largest value specified. */
6839 if (in_attr[i].i > out_attr[i].i)
6840 out_attr[i].i = in_attr[i].i;
6843 case Tag_CPU_arch_profile:
6844 /* Warn if conflicting architecture profiles used. */
6845 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6848 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6849 ibfd, in_attr[i].i, out_attr[i].i);
6853 out_attr[i].i = in_attr[i].i;
6855 case Tag_PCS_config:
6856 if (out_attr[i].i == 0)
6857 out_attr[i].i = in_attr[i].i;
6858 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6860 /* It's sometimes ok to mix different configs, so this is only
6863 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6866 case Tag_ABI_PCS_R9_use:
6867 if (in_attr[i].i != out_attr[i].i
6868 && out_attr[i].i != AEABI_R9_unused
6869 && in_attr[i].i != AEABI_R9_unused)
6872 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6875 if (out_attr[i].i == AEABI_R9_unused)
6876 out_attr[i].i = in_attr[i].i;
6878 case Tag_ABI_PCS_RW_data:
6879 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6880 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6881 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6884 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6888 /* Use the smallest value specified. */
6889 if (in_attr[i].i < out_attr[i].i)
6890 out_attr[i].i = in_attr[i].i;
6892 case Tag_ABI_PCS_RO_data:
6893 /* Use the smallest value specified. */
6894 if (in_attr[i].i < out_attr[i].i)
6895 out_attr[i].i = in_attr[i].i;
6897 case Tag_ABI_PCS_GOT_use:
6898 if (in_attr[i].i > 2 || out_attr[i].i > 2
6899 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6900 out_attr[i].i = in_attr[i].i;
6902 case Tag_ABI_PCS_wchar_t:
6903 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6906 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6910 out_attr[i].i = in_attr[i].i;
6912 case Tag_ABI_align8_needed:
6913 /* ??? Check against Tag_ABI_align8_preserved. */
6914 if (in_attr[i].i > 2 || out_attr[i].i > 2
6915 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6916 out_attr[i].i = in_attr[i].i;
6918 case Tag_ABI_enum_size:
6919 if (in_attr[i].i != AEABI_enum_unused)
6921 if (out_attr[i].i == AEABI_enum_unused
6922 || out_attr[i].i == AEABI_enum_forced_wide)
6924 /* The existing object is compatible with anything.
6925 Use whatever requirements the new object has. */
6926 out_attr[i].i = in_attr[i].i;
6928 else if (in_attr[i].i != AEABI_enum_forced_wide
6929 && out_attr[i].i != in_attr[i].i
6930 && !elf32_arm_tdata (obfd)->no_enum_size_warning)
6932 const char *aeabi_enum_names[] =
6933 { "", "variable-size", "32-bit", "" };
6935 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
6936 ibfd, aeabi_enum_names[in_attr[i].i],
6937 aeabi_enum_names[out_attr[i].i]);
6941 case Tag_ABI_VFP_args:
6944 case Tag_ABI_WMMX_args:
6945 if (in_attr[i].i != out_attr[i].i)
6948 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6953 default: /* All known attributes should be explicitly covered. */
6958 /* Merge Tag_compatibility attributes and any common GNU ones. */
6959 _bfd_elf_merge_object_attributes (ibfd, obfd);
6961 /* Check for any attributes not known on ARM. */
6962 in_list = elf_other_obj_attributes_proc (ibfd);
6963 while (in_list && in_list->tag == Tag_compatibility)
6964 in_list = in_list->next;
6966 for (; in_list; in_list = in_list->next)
6968 if ((in_list->tag & 128) < 64)
6971 (_("Warning: %B: Unknown EABI object attribute %d"),
6972 ibfd, in_list->tag);
6980 /* Return TRUE if the two EABI versions are incompatible. */
6983 elf32_arm_versions_compatible (unsigned iver, unsigned over)
6985 /* v4 and v5 are the same spec before and after it was released,
6986 so allow mixing them. */
6987 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
6988 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
6991 return (iver == over);
6994 /* Merge backend specific data from an object file to the output
6995 object file when linking. */
6998 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
7002 bfd_boolean flags_compatible = TRUE;
7005 /* Check if we have the same endianess. */
7006 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
7009 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7010 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7013 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
7016 /* The input BFD must have had its flags initialised. */
7017 /* The following seems bogus to me -- The flags are initialized in
7018 the assembler but I don't think an elf_flags_init field is
7019 written into the object. */
7020 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7022 in_flags = elf_elfheader (ibfd)->e_flags;
7023 out_flags = elf_elfheader (obfd)->e_flags;
7025 if (!elf_flags_init (obfd))
7027 /* If the input is the default architecture and had the default
7028 flags then do not bother setting the flags for the output
7029 architecture, instead allow future merges to do this. If no
7030 future merges ever set these flags then they will retain their
7031 uninitialised values, which surprise surprise, correspond
7032 to the default values. */
7033 if (bfd_get_arch_info (ibfd)->the_default
7034 && elf_elfheader (ibfd)->e_flags == 0)
7037 elf_flags_init (obfd) = TRUE;
7038 elf_elfheader (obfd)->e_flags = in_flags;
7040 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7041 && bfd_get_arch_info (obfd)->the_default)
7042 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
7047 /* Determine what should happen if the input ARM architecture
7048 does not match the output ARM architecture. */
7049 if (! bfd_arm_merge_machines (ibfd, obfd))
7052 /* Identical flags must be compatible. */
7053 if (in_flags == out_flags)
7056 /* Check to see if the input BFD actually contains any sections. If
7057 not, its flags may not have been initialised either, but it
7058 cannot actually cause any incompatiblity. Do not short-circuit
7059 dynamic objects; their section list may be emptied by
7060 elf_link_add_object_symbols.
7062 Also check to see if there are no code sections in the input.
7063 In this case there is no need to check for code specific flags.
7064 XXX - do we need to worry about floating-point format compatability
7065 in data sections ? */
7066 if (!(ibfd->flags & DYNAMIC))
7068 bfd_boolean null_input_bfd = TRUE;
7069 bfd_boolean only_data_sections = TRUE;
7071 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7073 /* Ignore synthetic glue sections. */
7074 if (strcmp (sec->name, ".glue_7")
7075 && strcmp (sec->name, ".glue_7t"))
7077 if ((bfd_get_section_flags (ibfd, sec)
7078 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7079 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7080 only_data_sections = FALSE;
7082 null_input_bfd = FALSE;
7087 if (null_input_bfd || only_data_sections)
7091 /* Complain about various flag mismatches. */
7092 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
7093 EF_ARM_EABI_VERSION (out_flags)))
7096 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
7098 (in_flags & EF_ARM_EABIMASK) >> 24,
7099 (out_flags & EF_ARM_EABIMASK) >> 24);
7103 /* Not sure what needs to be checked for EABI versions >= 1. */
7104 /* VxWorks libraries do not use these flags. */
7105 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
7106 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
7107 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
7109 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7112 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
7114 in_flags & EF_ARM_APCS_26 ? 26 : 32,
7115 out_flags & EF_ARM_APCS_26 ? 26 : 32);
7116 flags_compatible = FALSE;
7119 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7121 if (in_flags & EF_ARM_APCS_FLOAT)
7123 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
7127 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
7130 flags_compatible = FALSE;
7133 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
7135 if (in_flags & EF_ARM_VFP_FLOAT)
7137 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
7141 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
7144 flags_compatible = FALSE;
7147 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
7149 if (in_flags & EF_ARM_MAVERICK_FLOAT)
7151 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
7155 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
7158 flags_compatible = FALSE;
7161 #ifdef EF_ARM_SOFT_FLOAT
7162 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
7164 /* We can allow interworking between code that is VFP format
7165 layout, and uses either soft float or integer regs for
7166 passing floating point arguments and results. We already
7167 know that the APCS_FLOAT flags match; similarly for VFP
7169 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
7170 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
7172 if (in_flags & EF_ARM_SOFT_FLOAT)
7174 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
7178 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
7181 flags_compatible = FALSE;
7186 /* Interworking mismatch is only a warning. */
7187 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7189 if (in_flags & EF_ARM_INTERWORK)
7192 (_("Warning: %B supports interworking, whereas %B does not"),
7198 (_("Warning: %B does not support interworking, whereas %B does"),
7204 return flags_compatible;
7207 /* Display the flags field. */
7210 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
7212 FILE * file = (FILE *) ptr;
7213 unsigned long flags;
7215 BFD_ASSERT (abfd != NULL && ptr != NULL);
7217 /* Print normal ELF private data. */
7218 _bfd_elf_print_private_bfd_data (abfd, ptr);
7220 flags = elf_elfheader (abfd)->e_flags;
7221 /* Ignore init flag - it may not be set, despite the flags field
7222 containing valid data. */
7224 /* xgettext:c-format */
7225 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7227 switch (EF_ARM_EABI_VERSION (flags))
7229 case EF_ARM_EABI_UNKNOWN:
7230 /* The following flag bits are GNU extensions and not part of the
7231 official ARM ELF extended ABI. Hence they are only decoded if
7232 the EABI version is not set. */
7233 if (flags & EF_ARM_INTERWORK)
7234 fprintf (file, _(" [interworking enabled]"));
7236 if (flags & EF_ARM_APCS_26)
7237 fprintf (file, " [APCS-26]");
7239 fprintf (file, " [APCS-32]");
7241 if (flags & EF_ARM_VFP_FLOAT)
7242 fprintf (file, _(" [VFP float format]"));
7243 else if (flags & EF_ARM_MAVERICK_FLOAT)
7244 fprintf (file, _(" [Maverick float format]"));
7246 fprintf (file, _(" [FPA float format]"));
7248 if (flags & EF_ARM_APCS_FLOAT)
7249 fprintf (file, _(" [floats passed in float registers]"));
7251 if (flags & EF_ARM_PIC)
7252 fprintf (file, _(" [position independent]"));
7254 if (flags & EF_ARM_NEW_ABI)
7255 fprintf (file, _(" [new ABI]"));
7257 if (flags & EF_ARM_OLD_ABI)
7258 fprintf (file, _(" [old ABI]"));
7260 if (flags & EF_ARM_SOFT_FLOAT)
7261 fprintf (file, _(" [software FP]"));
7263 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
7264 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
7265 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
7266 | EF_ARM_MAVERICK_FLOAT);
7269 case EF_ARM_EABI_VER1:
7270 fprintf (file, _(" [Version1 EABI]"));
7272 if (flags & EF_ARM_SYMSARESORTED)
7273 fprintf (file, _(" [sorted symbol table]"));
7275 fprintf (file, _(" [unsorted symbol table]"));
7277 flags &= ~ EF_ARM_SYMSARESORTED;
7280 case EF_ARM_EABI_VER2:
7281 fprintf (file, _(" [Version2 EABI]"));
7283 if (flags & EF_ARM_SYMSARESORTED)
7284 fprintf (file, _(" [sorted symbol table]"));
7286 fprintf (file, _(" [unsorted symbol table]"));
7288 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
7289 fprintf (file, _(" [dynamic symbols use segment index]"));
7291 if (flags & EF_ARM_MAPSYMSFIRST)
7292 fprintf (file, _(" [mapping symbols precede others]"));
7294 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
7295 | EF_ARM_MAPSYMSFIRST);
7298 case EF_ARM_EABI_VER3:
7299 fprintf (file, _(" [Version3 EABI]"));
7302 case EF_ARM_EABI_VER4:
7303 fprintf (file, _(" [Version4 EABI]"));
7306 case EF_ARM_EABI_VER5:
7307 fprintf (file, _(" [Version5 EABI]"));
7309 if (flags & EF_ARM_BE8)
7310 fprintf (file, _(" [BE8]"));
7312 if (flags & EF_ARM_LE8)
7313 fprintf (file, _(" [LE8]"));
7315 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
7319 fprintf (file, _(" <EABI version unrecognised>"));
7323 flags &= ~ EF_ARM_EABIMASK;
7325 if (flags & EF_ARM_RELEXEC)
7326 fprintf (file, _(" [relocatable executable]"));
7328 if (flags & EF_ARM_HASENTRY)
7329 fprintf (file, _(" [has entry point]"));
7331 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
7334 fprintf (file, _("<Unrecognised flag bits set>"));
7342 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
7344 switch (ELF_ST_TYPE (elf_sym->st_info))
7347 return ELF_ST_TYPE (elf_sym->st_info);
7350 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
7351 This allows us to distinguish between data used by Thumb instructions
7352 and non-data (which is probably code) inside Thumb regions of an
7354 if (type != STT_OBJECT && type != STT_TLS)
7355 return ELF_ST_TYPE (elf_sym->st_info);
7366 elf32_arm_gc_mark_hook (asection *sec,
7367 struct bfd_link_info *info,
7368 Elf_Internal_Rela *rel,
7369 struct elf_link_hash_entry *h,
7370 Elf_Internal_Sym *sym)
7373 switch (ELF32_R_TYPE (rel->r_info))
7375 case R_ARM_GNU_VTINHERIT:
7376 case R_ARM_GNU_VTENTRY:
7380 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7383 /* Update the got entry reference counts for the section being removed. */
7386 elf32_arm_gc_sweep_hook (bfd * abfd,
7387 struct bfd_link_info * info,
7389 const Elf_Internal_Rela * relocs)
7391 Elf_Internal_Shdr *symtab_hdr;
7392 struct elf_link_hash_entry **sym_hashes;
7393 bfd_signed_vma *local_got_refcounts;
7394 const Elf_Internal_Rela *rel, *relend;
7395 struct elf32_arm_link_hash_table * globals;
7397 globals = elf32_arm_hash_table (info);
7399 elf_section_data (sec)->local_dynrel = NULL;
7401 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7402 sym_hashes = elf_sym_hashes (abfd);
7403 local_got_refcounts = elf_local_got_refcounts (abfd);
7405 relend = relocs + sec->reloc_count;
7406 for (rel = relocs; rel < relend; rel++)
7408 unsigned long r_symndx;
7409 struct elf_link_hash_entry *h = NULL;
7412 r_symndx = ELF32_R_SYM (rel->r_info);
7413 if (r_symndx >= symtab_hdr->sh_info)
7415 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7416 while (h->root.type == bfd_link_hash_indirect
7417 || h->root.type == bfd_link_hash_warning)
7418 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7421 r_type = ELF32_R_TYPE (rel->r_info);
7422 r_type = arm_real_reloc_type (globals, r_type);
7426 case R_ARM_GOT_PREL:
7427 case R_ARM_TLS_GD32:
7428 case R_ARM_TLS_IE32:
7431 if (h->got.refcount > 0)
7432 h->got.refcount -= 1;
7434 else if (local_got_refcounts != NULL)
7436 if (local_got_refcounts[r_symndx] > 0)
7437 local_got_refcounts[r_symndx] -= 1;
7441 case R_ARM_TLS_LDM32:
7442 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7446 case R_ARM_ABS32_NOI:
7448 case R_ARM_REL32_NOI:
7454 case R_ARM_THM_CALL:
7455 case R_ARM_MOVW_ABS_NC:
7456 case R_ARM_MOVT_ABS:
7457 case R_ARM_MOVW_PREL_NC:
7458 case R_ARM_MOVT_PREL:
7459 case R_ARM_THM_MOVW_ABS_NC:
7460 case R_ARM_THM_MOVT_ABS:
7461 case R_ARM_THM_MOVW_PREL_NC:
7462 case R_ARM_THM_MOVT_PREL:
7463 /* Should the interworking branches be here also? */
7467 struct elf32_arm_link_hash_entry *eh;
7468 struct elf32_arm_relocs_copied **pp;
7469 struct elf32_arm_relocs_copied *p;
7471 eh = (struct elf32_arm_link_hash_entry *) h;
7473 if (h->plt.refcount > 0)
7475 h->plt.refcount -= 1;
7476 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
7477 eh->plt_thumb_refcount--;
7480 if (r_type == R_ARM_ABS32
7481 || r_type == R_ARM_REL32
7482 || r_type == R_ARM_ABS32_NOI
7483 || r_type == R_ARM_REL32_NOI)
7485 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7487 if (p->section == sec)
7490 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7491 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
7509 /* Look through the relocs for a section during the first phase. */
7512 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7513 asection *sec, const Elf_Internal_Rela *relocs)
7515 Elf_Internal_Shdr *symtab_hdr;
7516 struct elf_link_hash_entry **sym_hashes;
7517 struct elf_link_hash_entry **sym_hashes_end;
7518 const Elf_Internal_Rela *rel;
7519 const Elf_Internal_Rela *rel_end;
7522 bfd_vma *local_got_offsets;
7523 struct elf32_arm_link_hash_table *htab;
7525 if (info->relocatable)
7528 htab = elf32_arm_hash_table (info);
7531 /* Create dynamic sections for relocatable executables so that we can
7532 copy relocations. */
7533 if (htab->root.is_relocatable_executable
7534 && ! htab->root.dynamic_sections_created)
7536 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7540 dynobj = elf_hash_table (info)->dynobj;
7541 local_got_offsets = elf_local_got_offsets (abfd);
7543 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7544 sym_hashes = elf_sym_hashes (abfd);
7545 sym_hashes_end = sym_hashes
7546 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7548 if (!elf_bad_symtab (abfd))
7549 sym_hashes_end -= symtab_hdr->sh_info;
7551 rel_end = relocs + sec->reloc_count;
7552 for (rel = relocs; rel < rel_end; rel++)
7554 struct elf_link_hash_entry *h;
7555 struct elf32_arm_link_hash_entry *eh;
7556 unsigned long r_symndx;
7559 r_symndx = ELF32_R_SYM (rel->r_info);
7560 r_type = ELF32_R_TYPE (rel->r_info);
7561 r_type = arm_real_reloc_type (htab, r_type);
7563 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7565 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7570 if (r_symndx < symtab_hdr->sh_info)
7574 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7575 while (h->root.type == bfd_link_hash_indirect
7576 || h->root.type == bfd_link_hash_warning)
7577 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7580 eh = (struct elf32_arm_link_hash_entry *) h;
7585 case R_ARM_GOT_PREL:
7586 case R_ARM_TLS_GD32:
7587 case R_ARM_TLS_IE32:
7588 /* This symbol requires a global offset table entry. */
7590 int tls_type, old_tls_type;
7594 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7595 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7596 default: tls_type = GOT_NORMAL; break;
7602 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7606 bfd_signed_vma *local_got_refcounts;
7608 /* This is a global offset table entry for a local symbol. */
7609 local_got_refcounts = elf_local_got_refcounts (abfd);
7610 if (local_got_refcounts == NULL)
7614 size = symtab_hdr->sh_info;
7615 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7616 local_got_refcounts = bfd_zalloc (abfd, size);
7617 if (local_got_refcounts == NULL)
7619 elf_local_got_refcounts (abfd) = local_got_refcounts;
7620 elf32_arm_local_got_tls_type (abfd)
7621 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7623 local_got_refcounts[r_symndx] += 1;
7624 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7627 /* We will already have issued an error message if there is a
7628 TLS / non-TLS mismatch, based on the symbol type. We don't
7629 support any linker relaxations. So just combine any TLS
7631 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7632 && tls_type != GOT_NORMAL)
7633 tls_type |= old_tls_type;
7635 if (old_tls_type != tls_type)
7638 elf32_arm_hash_entry (h)->tls_type = tls_type;
7640 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7645 case R_ARM_TLS_LDM32:
7646 if (r_type == R_ARM_TLS_LDM32)
7647 htab->tls_ldm_got.refcount++;
7650 case R_ARM_GOTOFF32:
7652 if (htab->sgot == NULL)
7654 if (htab->root.dynobj == NULL)
7655 htab->root.dynobj = abfd;
7656 if (!create_got_section (htab->root.dynobj, info))
7662 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7663 ldr __GOTT_INDEX__ offsets. */
7664 if (!htab->vxworks_p)
7669 case R_ARM_ABS32_NOI:
7671 case R_ARM_REL32_NOI:
7677 case R_ARM_THM_CALL:
7678 case R_ARM_MOVW_ABS_NC:
7679 case R_ARM_MOVT_ABS:
7680 case R_ARM_MOVW_PREL_NC:
7681 case R_ARM_MOVT_PREL:
7682 case R_ARM_THM_MOVW_ABS_NC:
7683 case R_ARM_THM_MOVT_ABS:
7684 case R_ARM_THM_MOVW_PREL_NC:
7685 case R_ARM_THM_MOVT_PREL:
7686 /* Should the interworking branches be listed here? */
7689 /* If this reloc is in a read-only section, we might
7690 need a copy reloc. We can't check reliably at this
7691 stage whether the section is read-only, as input
7692 sections have not yet been mapped to output sections.
7693 Tentatively set the flag for now, and correct in
7694 adjust_dynamic_symbol. */
7698 /* We may need a .plt entry if the function this reloc
7699 refers to is in a different object. We can't tell for
7700 sure yet, because something later might force the
7702 if (r_type != R_ARM_ABS32
7703 && r_type != R_ARM_REL32
7704 && r_type != R_ARM_ABS32_NOI
7705 && r_type != R_ARM_REL32_NOI
7706 && r_type != R_ARM_ABS12)
7709 /* If we create a PLT entry, this relocation will reference
7710 it, even if it's an ABS32 relocation. */
7711 h->plt.refcount += 1;
7713 if (r_type == R_ARM_THM_CALL)
7714 eh->plt_thumb_refcount += 1;
7717 /* If we are creating a shared library or relocatable executable,
7718 and this is a reloc against a global symbol, or a non PC
7719 relative reloc against a local symbol, then we need to copy
7720 the reloc into the shared library. However, if we are linking
7721 with -Bsymbolic, we do not need to copy a reloc against a
7722 global symbol which is defined in an object we are
7723 including in the link (i.e., DEF_REGULAR is set). At
7724 this point we have not seen all the input files, so it is
7725 possible that DEF_REGULAR is not set now but will be set
7726 later (it is never cleared). We account for that
7727 possibility below by storing information in the
7728 relocs_copied field of the hash table entry. */
7729 if ((info->shared || htab->root.is_relocatable_executable)
7730 && (sec->flags & SEC_ALLOC) != 0
7731 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
7732 || (h != NULL && ! h->needs_plt
7733 && (! info->symbolic || ! h->def_regular))))
7735 struct elf32_arm_relocs_copied *p, **head;
7737 /* When creating a shared object, we must copy these
7738 reloc types into the output file. We create a reloc
7739 section in dynobj and make room for this reloc. */
7744 name = (bfd_elf_string_from_elf_section
7746 elf_elfheader (abfd)->e_shstrndx,
7747 elf_section_data (sec)->rel_hdr.sh_name));
7751 BFD_ASSERT (reloc_section_p (htab, name, sec));
7753 sreloc = bfd_get_section_by_name (dynobj, name);
7758 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7759 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7760 if ((sec->flags & SEC_ALLOC) != 0
7761 /* BPABI objects never have dynamic
7762 relocations mapped. */
7763 && !htab->symbian_p)
7764 flags |= SEC_ALLOC | SEC_LOAD;
7765 sreloc = bfd_make_section_with_flags (dynobj,
7769 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7773 elf_section_data (sec)->sreloc = sreloc;
7776 /* If this is a global symbol, we count the number of
7777 relocations we need for this symbol. */
7780 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7784 /* Track dynamic relocs needed for local syms too.
7785 We really need local syms available to do this
7791 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7796 vpp = &elf_section_data (s)->local_dynrel;
7797 head = (struct elf32_arm_relocs_copied **) vpp;
7801 if (p == NULL || p->section != sec)
7803 bfd_size_type amt = sizeof *p;
7805 p = bfd_alloc (htab->root.dynobj, amt);
7815 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
7821 /* This relocation describes the C++ object vtable hierarchy.
7822 Reconstruct it for later use during GC. */
7823 case R_ARM_GNU_VTINHERIT:
7824 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7828 /* This relocation describes which C++ vtable entries are actually
7829 used. Record for later use during GC. */
7830 case R_ARM_GNU_VTENTRY:
7831 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7840 /* Unwinding tables are not referenced directly. This pass marks them as
7841 required if the corresponding code section is marked. */
7844 elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
7845 elf_gc_mark_hook_fn gc_mark_hook)
7848 Elf_Internal_Shdr **elf_shdrp;
7851 /* Marking EH data may cause additional code sections to be marked,
7852 requiring multiple passes. */
7857 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
7861 if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
7864 elf_shdrp = elf_elfsections (sub);
7865 for (o = sub->sections; o != NULL; o = o->next)
7867 Elf_Internal_Shdr *hdr;
7868 hdr = &elf_section_data (o)->this_hdr;
7869 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
7871 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
7874 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
7884 /* Treat mapping symbols as special target symbols. */
7887 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7889 return bfd_is_arm_special_symbol_name (sym->name,
7890 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7893 /* This is a copy of elf_find_function() from elf.c except that
7894 ARM mapping symbols are ignored when looking for function names
7895 and STT_ARM_TFUNC is considered to a function type. */
7898 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7902 const char ** filename_ptr,
7903 const char ** functionname_ptr)
7905 const char * filename = NULL;
7906 asymbol * func = NULL;
7907 bfd_vma low_func = 0;
7910 for (p = symbols; *p != NULL; p++)
7914 q = (elf_symbol_type *) *p;
7916 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7921 filename = bfd_asymbol_name (&q->symbol);
7926 /* Skip mapping symbols. */
7927 if ((q->symbol.flags & BSF_LOCAL)
7928 && bfd_is_arm_special_symbol_name (q->symbol.name,
7929 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7932 if (bfd_get_section (&q->symbol) == section
7933 && q->symbol.value >= low_func
7934 && q->symbol.value <= offset)
7936 func = (asymbol *) q;
7937 low_func = q->symbol.value;
7947 *filename_ptr = filename;
7948 if (functionname_ptr)
7949 *functionname_ptr = bfd_asymbol_name (func);
7955 /* Find the nearest line to a particular section and offset, for error
7956 reporting. This code is a duplicate of the code in elf.c, except
7957 that it uses arm_elf_find_function. */
7960 elf32_arm_find_nearest_line (bfd * abfd,
7964 const char ** filename_ptr,
7965 const char ** functionname_ptr,
7966 unsigned int * line_ptr)
7968 bfd_boolean found = FALSE;
7970 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7972 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
7973 filename_ptr, functionname_ptr,
7975 & elf_tdata (abfd)->dwarf2_find_line_info))
7977 if (!*functionname_ptr)
7978 arm_elf_find_function (abfd, section, symbols, offset,
7979 *filename_ptr ? NULL : filename_ptr,
7985 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7986 & found, filename_ptr,
7987 functionname_ptr, line_ptr,
7988 & elf_tdata (abfd)->line_info))
7991 if (found && (*functionname_ptr || *line_ptr))
7994 if (symbols == NULL)
7997 if (! arm_elf_find_function (abfd, section, symbols, offset,
7998 filename_ptr, functionname_ptr))
8006 elf32_arm_find_inliner_info (bfd * abfd,
8007 const char ** filename_ptr,
8008 const char ** functionname_ptr,
8009 unsigned int * line_ptr)
8012 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
8013 functionname_ptr, line_ptr,
8014 & elf_tdata (abfd)->dwarf2_find_line_info);
8018 /* Adjust a symbol defined by a dynamic object and referenced by a
8019 regular object. The current definition is in some section of the
8020 dynamic object, but we're not including those sections. We have to
8021 change the definition to something the rest of the link can
8025 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
8026 struct elf_link_hash_entry * h)
8030 struct elf32_arm_link_hash_entry * eh;
8031 struct elf32_arm_link_hash_table *globals;
8033 globals = elf32_arm_hash_table (info);
8034 dynobj = elf_hash_table (info)->dynobj;
8036 /* Make sure we know what is going on here. */
8037 BFD_ASSERT (dynobj != NULL
8039 || h->u.weakdef != NULL
8042 && !h->def_regular)));
8044 eh = (struct elf32_arm_link_hash_entry *) h;
8046 /* If this is a function, put it in the procedure linkage table. We
8047 will fill in the contents of the procedure linkage table later,
8048 when we know the address of the .got section. */
8049 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
8052 if (h->plt.refcount <= 0
8053 || SYMBOL_CALLS_LOCAL (info, h)
8054 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8055 && h->root.type == bfd_link_hash_undefweak))
8057 /* This case can occur if we saw a PLT32 reloc in an input
8058 file, but the symbol was never referred to by a dynamic
8059 object, or if all references were garbage collected. In
8060 such a case, we don't actually need to build a procedure
8061 linkage table, and we can just do a PC24 reloc instead. */
8062 h->plt.offset = (bfd_vma) -1;
8063 eh->plt_thumb_refcount = 0;
8071 /* It's possible that we incorrectly decided a .plt reloc was
8072 needed for an R_ARM_PC24 or similar reloc to a non-function sym
8073 in check_relocs. We can't decide accurately between function
8074 and non-function syms in check-relocs; Objects loaded later in
8075 the link may change h->type. So fix it now. */
8076 h->plt.offset = (bfd_vma) -1;
8077 eh->plt_thumb_refcount = 0;
8080 /* If this is a weak symbol, and there is a real definition, the
8081 processor independent code will have arranged for us to see the
8082 real definition first, and we can just use the same value. */
8083 if (h->u.weakdef != NULL)
8085 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8086 || h->u.weakdef->root.type == bfd_link_hash_defweak);
8087 h->root.u.def.section = h->u.weakdef->root.u.def.section;
8088 h->root.u.def.value = h->u.weakdef->root.u.def.value;
8092 /* If there are no non-GOT references, we do not need a copy
8094 if (!h->non_got_ref)
8097 /* This is a reference to a symbol defined by a dynamic object which
8098 is not a function. */
8100 /* If we are creating a shared library, we must presume that the
8101 only references to the symbol are via the global offset table.
8102 For such cases we need not do anything here; the relocations will
8103 be handled correctly by relocate_section. Relocatable executables
8104 can reference data in shared objects directly, so we don't need to
8105 do anything here. */
8106 if (info->shared || globals->root.is_relocatable_executable)
8111 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8112 h->root.root.string);
8116 /* We must allocate the symbol in our .dynbss section, which will
8117 become part of the .bss section of the executable. There will be
8118 an entry for this symbol in the .dynsym section. The dynamic
8119 object will contain position independent code, so all references
8120 from the dynamic object to this symbol will go through the global
8121 offset table. The dynamic linker will use the .dynsym entry to
8122 determine the address it must put in the global offset table, so
8123 both the dynamic object and the regular object will refer to the
8124 same memory location for the variable. */
8125 s = bfd_get_section_by_name (dynobj, ".dynbss");
8126 BFD_ASSERT (s != NULL);
8128 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8129 copy the initial value out of the dynamic object and into the
8130 runtime process image. We need to remember the offset into the
8131 .rel(a).bss section we are going to use. */
8132 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8136 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
8137 BFD_ASSERT (srel != NULL);
8138 srel->size += RELOC_SIZE (globals);
8142 return _bfd_elf_adjust_dynamic_copy (h, s);
8145 /* Allocate space in .plt, .got and associated reloc sections for
8149 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
8151 struct bfd_link_info *info;
8152 struct elf32_arm_link_hash_table *htab;
8153 struct elf32_arm_link_hash_entry *eh;
8154 struct elf32_arm_relocs_copied *p;
8156 eh = (struct elf32_arm_link_hash_entry *) h;
8158 if (h->root.type == bfd_link_hash_indirect)
8161 if (h->root.type == bfd_link_hash_warning)
8162 /* When warning symbols are created, they **replace** the "real"
8163 entry in the hash table, thus we never get to see the real
8164 symbol in a hash traversal. So look at it now. */
8165 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8167 info = (struct bfd_link_info *) inf;
8168 htab = elf32_arm_hash_table (info);
8170 if (htab->root.dynamic_sections_created
8171 && h->plt.refcount > 0)
8173 /* Make sure this symbol is output as a dynamic symbol.
8174 Undefined weak syms won't yet be marked as dynamic. */
8175 if (h->dynindx == -1
8176 && !h->forced_local)
8178 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8183 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8185 asection *s = htab->splt;
8187 /* If this is the first .plt entry, make room for the special
8190 s->size += htab->plt_header_size;
8192 h->plt.offset = s->size;
8194 /* If we will insert a Thumb trampoline before this PLT, leave room
8196 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8198 h->plt.offset += PLT_THUMB_STUB_SIZE;
8199 s->size += PLT_THUMB_STUB_SIZE;
8202 /* If this symbol is not defined in a regular file, and we are
8203 not generating a shared library, then set the symbol to this
8204 location in the .plt. This is required to make function
8205 pointers compare as equal between the normal executable and
8206 the shared library. */
8210 h->root.u.def.section = s;
8211 h->root.u.def.value = h->plt.offset;
8213 /* Make sure the function is not marked as Thumb, in case
8214 it is the target of an ABS32 relocation, which will
8215 point to the PLT entry. */
8216 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8217 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8220 /* Make room for this entry. */
8221 s->size += htab->plt_entry_size;
8223 if (!htab->symbian_p)
8225 /* We also need to make an entry in the .got.plt section, which
8226 will be placed in the .got section by the linker script. */
8227 eh->plt_got_offset = htab->sgotplt->size;
8228 htab->sgotplt->size += 4;
8231 /* We also need to make an entry in the .rel(a).plt section. */
8232 htab->srelplt->size += RELOC_SIZE (htab);
8234 /* VxWorks executables have a second set of relocations for
8235 each PLT entry. They go in a separate relocation section,
8236 which is processed by the kernel loader. */
8237 if (htab->vxworks_p && !info->shared)
8239 /* There is a relocation for the initial PLT entry:
8240 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
8241 if (h->plt.offset == htab->plt_header_size)
8242 htab->srelplt2->size += RELOC_SIZE (htab);
8244 /* There are two extra relocations for each subsequent
8245 PLT entry: an R_ARM_32 relocation for the GOT entry,
8246 and an R_ARM_32 relocation for the PLT entry. */
8247 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8252 h->plt.offset = (bfd_vma) -1;
8258 h->plt.offset = (bfd_vma) -1;
8262 if (h->got.refcount > 0)
8266 int tls_type = elf32_arm_hash_entry (h)->tls_type;
8269 /* Make sure this symbol is output as a dynamic symbol.
8270 Undefined weak syms won't yet be marked as dynamic. */
8271 if (h->dynindx == -1
8272 && !h->forced_local)
8274 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8278 if (!htab->symbian_p)
8281 h->got.offset = s->size;
8283 if (tls_type == GOT_UNKNOWN)
8286 if (tls_type == GOT_NORMAL)
8287 /* Non-TLS symbols need one GOT slot. */
8291 if (tls_type & GOT_TLS_GD)
8292 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
8294 if (tls_type & GOT_TLS_IE)
8295 /* R_ARM_TLS_IE32 needs one GOT slot. */
8299 dyn = htab->root.dynamic_sections_created;
8302 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8304 || !SYMBOL_REFERENCES_LOCAL (info, h)))
8307 if (tls_type != GOT_NORMAL
8308 && (info->shared || indx != 0)
8309 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8310 || h->root.type != bfd_link_hash_undefweak))
8312 if (tls_type & GOT_TLS_IE)
8313 htab->srelgot->size += RELOC_SIZE (htab);
8315 if (tls_type & GOT_TLS_GD)
8316 htab->srelgot->size += RELOC_SIZE (htab);
8318 if ((tls_type & GOT_TLS_GD) && indx != 0)
8319 htab->srelgot->size += RELOC_SIZE (htab);
8321 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8322 || h->root.type != bfd_link_hash_undefweak)
8324 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8325 htab->srelgot->size += RELOC_SIZE (htab);
8329 h->got.offset = (bfd_vma) -1;
8331 /* Allocate stubs for exported Thumb functions on v4t. */
8332 if (!htab->use_blx && h->dynindx != -1
8334 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8335 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8337 struct elf_link_hash_entry * th;
8338 struct bfd_link_hash_entry * bh;
8339 struct elf_link_hash_entry * myh;
8343 /* Create a new symbol to regist the real location of the function. */
8344 s = h->root.u.def.section;
8345 sprintf(name, "__real_%s", h->root.root.string);
8346 _bfd_generic_link_add_one_symbol (info, s->owner,
8347 name, BSF_GLOBAL, s,
8348 h->root.u.def.value,
8349 NULL, TRUE, FALSE, &bh);
8351 myh = (struct elf_link_hash_entry *) bh;
8352 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8353 myh->forced_local = 1;
8354 eh->export_glue = myh;
8355 th = record_arm_to_thumb_glue (info, h);
8356 /* Point the symbol at the stub. */
8357 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8358 h->root.u.def.section = th->root.u.def.section;
8359 h->root.u.def.value = th->root.u.def.value & ~1;
8362 if (eh->relocs_copied == NULL)
8365 /* In the shared -Bsymbolic case, discard space allocated for
8366 dynamic pc-relative relocs against symbols which turn out to be
8367 defined in regular objects. For the normal shared case, discard
8368 space for pc-relative relocs that have become local due to symbol
8369 visibility changes. */
8371 if (info->shared || htab->root.is_relocatable_executable)
8373 /* The only relocs that use pc_count are R_ARM_REL32 and
8374 R_ARM_REL32_NOI, which will appear on something like
8375 ".long foo - .". We want calls to protected symbols to resolve
8376 directly to the function rather than going via the plt. If people
8377 want function pointer comparisons to work as expected then they
8378 should avoid writing assembly like ".long foo - .". */
8379 if (SYMBOL_CALLS_LOCAL (info, h))
8381 struct elf32_arm_relocs_copied **pp;
8383 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8385 p->count -= p->pc_count;
8394 /* Also discard relocs on undefined weak syms with non-default
8396 if (eh->relocs_copied != NULL
8397 && h->root.type == bfd_link_hash_undefweak)
8399 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8400 eh->relocs_copied = NULL;
8402 /* Make sure undefined weak symbols are output as a dynamic
8404 else if (h->dynindx == -1
8405 && !h->forced_local)
8407 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8412 else if (htab->root.is_relocatable_executable && h->dynindx == -1
8413 && h->root.type == bfd_link_hash_new)
8415 /* Output absolute symbols so that we can create relocations
8416 against them. For normal symbols we output a relocation
8417 against the section that contains them. */
8418 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8425 /* For the non-shared case, discard space for relocs against
8426 symbols which turn out to need copy relocs or are not
8432 || (htab->root.dynamic_sections_created
8433 && (h->root.type == bfd_link_hash_undefweak
8434 || h->root.type == bfd_link_hash_undefined))))
8436 /* Make sure this symbol is output as a dynamic symbol.
8437 Undefined weak syms won't yet be marked as dynamic. */
8438 if (h->dynindx == -1
8439 && !h->forced_local)
8441 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8445 /* If that succeeded, we know we'll be keeping all the
8447 if (h->dynindx != -1)
8451 eh->relocs_copied = NULL;
8456 /* Finally, allocate space. */
8457 for (p = eh->relocs_copied; p != NULL; p = p->next)
8459 asection *sreloc = elf_section_data (p->section)->sreloc;
8460 sreloc->size += p->count * RELOC_SIZE (htab);
8466 /* Find any dynamic relocs that apply to read-only sections. */
8469 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8471 struct elf32_arm_link_hash_entry *eh;
8472 struct elf32_arm_relocs_copied *p;
8474 if (h->root.type == bfd_link_hash_warning)
8475 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8477 eh = (struct elf32_arm_link_hash_entry *) h;
8478 for (p = eh->relocs_copied; p != NULL; p = p->next)
8480 asection *s = p->section;
8482 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8484 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8486 info->flags |= DF_TEXTREL;
8488 /* Not an error, just cut short the traversal. */
8496 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8499 struct elf32_arm_link_hash_table *globals;
8501 globals = elf32_arm_hash_table (info);
8502 globals->byteswap_code = byteswap_code;
8505 /* Set the sizes of the dynamic sections. */
8508 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8509 struct bfd_link_info * info)
8516 struct elf32_arm_link_hash_table *htab;
8518 htab = elf32_arm_hash_table (info);
8519 dynobj = elf_hash_table (info)->dynobj;
8520 BFD_ASSERT (dynobj != NULL);
8521 check_use_blx (htab);
8523 if (elf_hash_table (info)->dynamic_sections_created)
8525 /* Set the contents of the .interp section to the interpreter. */
8526 if (info->executable)
8528 s = bfd_get_section_by_name (dynobj, ".interp");
8529 BFD_ASSERT (s != NULL);
8530 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8531 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8535 /* Set up .got offsets for local syms, and space for local dynamic
8537 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8539 bfd_signed_vma *local_got;
8540 bfd_signed_vma *end_local_got;
8541 char *local_tls_type;
8542 bfd_size_type locsymcount;
8543 Elf_Internal_Shdr *symtab_hdr;
8546 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8549 for (s = ibfd->sections; s != NULL; s = s->next)
8551 struct elf32_arm_relocs_copied *p;
8553 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
8555 if (!bfd_is_abs_section (p->section)
8556 && bfd_is_abs_section (p->section->output_section))
8558 /* Input section has been discarded, either because
8559 it is a copy of a linkonce section or due to
8560 linker script /DISCARD/, so we'll be discarding
8563 else if (p->count != 0)
8565 srel = elf_section_data (p->section)->sreloc;
8566 srel->size += p->count * RELOC_SIZE (htab);
8567 if ((p->section->output_section->flags & SEC_READONLY) != 0)
8568 info->flags |= DF_TEXTREL;
8573 local_got = elf_local_got_refcounts (ibfd);
8577 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8578 locsymcount = symtab_hdr->sh_info;
8579 end_local_got = local_got + locsymcount;
8580 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8582 srel = htab->srelgot;
8583 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8587 *local_got = s->size;
8588 if (*local_tls_type & GOT_TLS_GD)
8589 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8591 if (*local_tls_type & GOT_TLS_IE)
8593 if (*local_tls_type == GOT_NORMAL)
8596 if (info->shared || *local_tls_type == GOT_TLS_GD)
8597 srel->size += RELOC_SIZE (htab);
8600 *local_got = (bfd_vma) -1;
8604 if (htab->tls_ldm_got.refcount > 0)
8606 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8607 for R_ARM_TLS_LDM32 relocations. */
8608 htab->tls_ldm_got.offset = htab->sgot->size;
8609 htab->sgot->size += 8;
8611 htab->srelgot->size += RELOC_SIZE (htab);
8614 htab->tls_ldm_got.offset = -1;
8616 /* Allocate global sym .plt and .got entries, and space for global
8617 sym dynamic relocs. */
8618 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8620 /* Here we rummage through the found bfds to collect glue information. */
8621 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8623 /* Initialise mapping tables for code/data. */
8624 bfd_elf32_arm_init_maps (ibfd);
8626 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8627 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
8628 /* xgettext:c-format */
8629 _bfd_error_handler (_("Errors encountered processing file %s"),
8633 /* The check_relocs and adjust_dynamic_symbol entry points have
8634 determined the sizes of the various dynamic sections. Allocate
8638 for (s = dynobj->sections; s != NULL; s = s->next)
8642 if ((s->flags & SEC_LINKER_CREATED) == 0)
8645 /* It's OK to base decisions on the section name, because none
8646 of the dynobj section names depend upon the input files. */
8647 name = bfd_get_section_name (dynobj, s);
8649 if (strcmp (name, ".plt") == 0)
8651 /* Remember whether there is a PLT. */
8654 else if (CONST_STRNEQ (name, ".rel"))
8658 /* Remember whether there are any reloc sections other
8659 than .rel(a).plt and .rela.plt.unloaded. */
8660 if (s != htab->srelplt && s != htab->srelplt2)
8663 /* We use the reloc_count field as a counter if we need
8664 to copy relocs into the output file. */
8668 else if (! CONST_STRNEQ (name, ".got")
8669 && strcmp (name, ".dynbss") != 0)
8671 /* It's not one of our sections, so don't allocate space. */
8677 /* If we don't need this section, strip it from the
8678 output file. This is mostly to handle .rel(a).bss and
8679 .rel(a).plt. We must create both sections in
8680 create_dynamic_sections, because they must be created
8681 before the linker maps input sections to output
8682 sections. The linker does that before
8683 adjust_dynamic_symbol is called, and it is that
8684 function which decides whether anything needs to go
8685 into these sections. */
8686 s->flags |= SEC_EXCLUDE;
8690 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8693 /* Allocate memory for the section contents. */
8694 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8695 if (s->contents == NULL)
8699 if (elf_hash_table (info)->dynamic_sections_created)
8701 /* Add some entries to the .dynamic section. We fill in the
8702 values later, in elf32_arm_finish_dynamic_sections, but we
8703 must add the entries now so that we get the correct size for
8704 the .dynamic section. The DT_DEBUG entry is filled in by the
8705 dynamic linker and used by the debugger. */
8706 #define add_dynamic_entry(TAG, VAL) \
8707 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8709 if (info->executable)
8711 if (!add_dynamic_entry (DT_DEBUG, 0))
8717 if ( !add_dynamic_entry (DT_PLTGOT, 0)
8718 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8719 || !add_dynamic_entry (DT_PLTREL,
8720 htab->use_rel ? DT_REL : DT_RELA)
8721 || !add_dynamic_entry (DT_JMPREL, 0))
8729 if (!add_dynamic_entry (DT_REL, 0)
8730 || !add_dynamic_entry (DT_RELSZ, 0)
8731 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8736 if (!add_dynamic_entry (DT_RELA, 0)
8737 || !add_dynamic_entry (DT_RELASZ, 0)
8738 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8743 /* If any dynamic relocs apply to a read-only section,
8744 then we need a DT_TEXTREL entry. */
8745 if ((info->flags & DF_TEXTREL) == 0)
8746 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8749 if ((info->flags & DF_TEXTREL) != 0)
8751 if (!add_dynamic_entry (DT_TEXTREL, 0))
8755 #undef add_dynamic_entry
8760 /* Finish up dynamic symbol handling. We set the contents of various
8761 dynamic sections here. */
8764 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8765 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
8768 struct elf32_arm_link_hash_table *htab;
8769 struct elf32_arm_link_hash_entry *eh;
8771 dynobj = elf_hash_table (info)->dynobj;
8772 htab = elf32_arm_hash_table (info);
8773 eh = (struct elf32_arm_link_hash_entry *) h;
8775 if (h->plt.offset != (bfd_vma) -1)
8781 Elf_Internal_Rela rel;
8783 /* This symbol has an entry in the procedure linkage table. Set
8786 BFD_ASSERT (h->dynindx != -1);
8788 splt = bfd_get_section_by_name (dynobj, ".plt");
8789 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8790 BFD_ASSERT (splt != NULL && srel != NULL);
8792 /* Fill in the entry in the procedure linkage table. */
8793 if (htab->symbian_p)
8795 put_arm_insn (htab, output_bfd,
8796 elf32_arm_symbian_plt_entry[0],
8797 splt->contents + h->plt.offset);
8798 bfd_put_32 (output_bfd,
8799 elf32_arm_symbian_plt_entry[1],
8800 splt->contents + h->plt.offset + 4);
8802 /* Fill in the entry in the .rel.plt section. */
8803 rel.r_offset = (splt->output_section->vma
8804 + splt->output_offset
8805 + h->plt.offset + 4);
8806 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8808 /* Get the index in the procedure linkage table which
8809 corresponds to this symbol. This is the index of this symbol
8810 in all the symbols for which we are making plt entries. The
8811 first entry in the procedure linkage table is reserved. */
8812 plt_index = ((h->plt.offset - htab->plt_header_size)
8813 / htab->plt_entry_size);
8817 bfd_vma got_offset, got_address, plt_address;
8818 bfd_vma got_displacement;
8822 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8823 BFD_ASSERT (sgot != NULL);
8825 /* Get the offset into the .got.plt table of the entry that
8826 corresponds to this function. */
8827 got_offset = eh->plt_got_offset;
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 three entries in .got.plt are reserved; after that
8833 symbols appear in the same order as in .plt. */
8834 plt_index = (got_offset - 12) / 4;
8836 /* Calculate the address of the GOT entry. */
8837 got_address = (sgot->output_section->vma
8838 + sgot->output_offset
8841 /* ...and the address of the PLT entry. */
8842 plt_address = (splt->output_section->vma
8843 + splt->output_offset
8846 ptr = htab->splt->contents + h->plt.offset;
8847 if (htab->vxworks_p && info->shared)
8852 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8854 val = elf32_arm_vxworks_shared_plt_entry[i];
8856 val |= got_address - sgot->output_section->vma;
8858 val |= plt_index * RELOC_SIZE (htab);
8859 if (i == 2 || i == 5)
8860 bfd_put_32 (output_bfd, val, ptr);
8862 put_arm_insn (htab, output_bfd, val, ptr);
8865 else if (htab->vxworks_p)
8870 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8872 val = elf32_arm_vxworks_exec_plt_entry[i];
8876 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8878 val |= plt_index * RELOC_SIZE (htab);
8879 if (i == 2 || i == 5)
8880 bfd_put_32 (output_bfd, val, ptr);
8882 put_arm_insn (htab, output_bfd, val, ptr);
8885 loc = (htab->srelplt2->contents
8886 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8888 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8889 referencing the GOT for this PLT entry. */
8890 rel.r_offset = plt_address + 8;
8891 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8892 rel.r_addend = got_offset;
8893 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8894 loc += RELOC_SIZE (htab);
8896 /* Create the R_ARM_ABS32 relocation referencing the
8897 beginning of the PLT for this GOT entry. */
8898 rel.r_offset = got_address;
8899 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8901 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8905 /* Calculate the displacement between the PLT slot and the
8906 entry in the GOT. The eight-byte offset accounts for the
8907 value produced by adding to pc in the first instruction
8909 got_displacement = got_address - (plt_address + 8);
8911 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8913 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8915 put_thumb_insn (htab, output_bfd,
8916 elf32_arm_plt_thumb_stub[0], ptr - 4);
8917 put_thumb_insn (htab, output_bfd,
8918 elf32_arm_plt_thumb_stub[1], ptr - 2);
8921 put_arm_insn (htab, output_bfd,
8922 elf32_arm_plt_entry[0]
8923 | ((got_displacement & 0x0ff00000) >> 20),
8925 put_arm_insn (htab, output_bfd,
8926 elf32_arm_plt_entry[1]
8927 | ((got_displacement & 0x000ff000) >> 12),
8929 put_arm_insn (htab, output_bfd,
8930 elf32_arm_plt_entry[2]
8931 | (got_displacement & 0x00000fff),
8933 #ifdef FOUR_WORD_PLT
8934 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8938 /* Fill in the entry in the global offset table. */
8939 bfd_put_32 (output_bfd,
8940 (splt->output_section->vma
8941 + splt->output_offset),
8942 sgot->contents + got_offset);
8944 /* Fill in the entry in the .rel(a).plt section. */
8946 rel.r_offset = got_address;
8947 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8950 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8951 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8953 if (!h->def_regular)
8955 /* Mark the symbol as undefined, rather than as defined in
8956 the .plt section. Leave the value alone. */
8957 sym->st_shndx = SHN_UNDEF;
8958 /* If the symbol is weak, we do need to clear the value.
8959 Otherwise, the PLT entry would provide a definition for
8960 the symbol even if the symbol wasn't defined anywhere,
8961 and so the symbol would never be NULL. */
8962 if (!h->ref_regular_nonweak)
8967 if (h->got.offset != (bfd_vma) -1
8968 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8969 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
8973 Elf_Internal_Rela rel;
8977 /* This symbol has an entry in the global offset table. Set it
8979 sgot = bfd_get_section_by_name (dynobj, ".got");
8980 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
8981 BFD_ASSERT (sgot != NULL && srel != NULL);
8983 offset = (h->got.offset & ~(bfd_vma) 1);
8985 rel.r_offset = (sgot->output_section->vma
8986 + sgot->output_offset
8989 /* If this is a static link, or it is a -Bsymbolic link and the
8990 symbol is defined locally or was forced to be local because
8991 of a version file, we just want to emit a RELATIVE reloc.
8992 The entry in the global offset table will already have been
8993 initialized in the relocate_section function. */
8995 && SYMBOL_REFERENCES_LOCAL (info, h))
8997 BFD_ASSERT((h->got.offset & 1) != 0);
8998 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9001 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
9002 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9007 BFD_ASSERT((h->got.offset & 1) == 0);
9008 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9009 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9012 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
9013 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9019 Elf_Internal_Rela rel;
9022 /* This symbol needs a copy reloc. Set it up. */
9023 BFD_ASSERT (h->dynindx != -1
9024 && (h->root.type == bfd_link_hash_defined
9025 || h->root.type == bfd_link_hash_defweak));
9027 s = bfd_get_section_by_name (h->root.u.def.section->owner,
9028 RELOC_SECTION (htab, ".bss"));
9029 BFD_ASSERT (s != NULL);
9032 rel.r_offset = (h->root.u.def.value
9033 + h->root.u.def.section->output_section->vma
9034 + h->root.u.def.section->output_offset);
9035 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
9036 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9037 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9040 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
9041 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9042 to the ".got" section. */
9043 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
9044 || (!htab->vxworks_p && h == htab->root.hgot))
9045 sym->st_shndx = SHN_ABS;
9050 /* Finish up the dynamic sections. */
9053 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
9059 dynobj = elf_hash_table (info)->dynobj;
9061 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9062 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
9063 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9065 if (elf_hash_table (info)->dynamic_sections_created)
9068 Elf32_External_Dyn *dyncon, *dynconend;
9069 struct elf32_arm_link_hash_table *htab;
9071 htab = elf32_arm_hash_table (info);
9072 splt = bfd_get_section_by_name (dynobj, ".plt");
9073 BFD_ASSERT (splt != NULL && sdyn != NULL);
9075 dyncon = (Elf32_External_Dyn *) sdyn->contents;
9076 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9078 for (; dyncon < dynconend; dyncon++)
9080 Elf_Internal_Dyn dyn;
9084 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9095 goto get_vma_if_bpabi;
9098 goto get_vma_if_bpabi;
9101 goto get_vma_if_bpabi;
9103 name = ".gnu.version";
9104 goto get_vma_if_bpabi;
9106 name = ".gnu.version_d";
9107 goto get_vma_if_bpabi;
9109 name = ".gnu.version_r";
9110 goto get_vma_if_bpabi;
9116 name = RELOC_SECTION (htab, ".plt");
9118 s = bfd_get_section_by_name (output_bfd, name);
9119 BFD_ASSERT (s != NULL);
9120 if (!htab->symbian_p)
9121 dyn.d_un.d_ptr = s->vma;
9123 /* In the BPABI, tags in the PT_DYNAMIC section point
9124 at the file offset, not the memory address, for the
9125 convenience of the post linker. */
9126 dyn.d_un.d_ptr = s->filepos;
9127 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9131 if (htab->symbian_p)
9136 s = bfd_get_section_by_name (output_bfd,
9137 RELOC_SECTION (htab, ".plt"));
9138 BFD_ASSERT (s != NULL);
9139 dyn.d_un.d_val = s->size;
9140 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9145 if (!htab->symbian_p)
9147 /* My reading of the SVR4 ABI indicates that the
9148 procedure linkage table relocs (DT_JMPREL) should be
9149 included in the overall relocs (DT_REL). This is
9150 what Solaris does. However, UnixWare can not handle
9151 that case. Therefore, we override the DT_RELSZ entry
9152 here to make it not include the JMPREL relocs. Since
9153 the linker script arranges for .rel(a).plt to follow all
9154 other relocation sections, we don't have to worry
9155 about changing the DT_REL entry. */
9156 s = bfd_get_section_by_name (output_bfd,
9157 RELOC_SECTION (htab, ".plt"));
9159 dyn.d_un.d_val -= s->size;
9160 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9167 /* In the BPABI, the DT_REL tag must point at the file
9168 offset, not the VMA, of the first relocation
9169 section. So, we use code similar to that in
9170 elflink.c, but do not check for SHF_ALLOC on the
9171 relcoation section, since relocations sections are
9172 never allocated under the BPABI. The comments above
9173 about Unixware notwithstanding, we include all of the
9174 relocations here. */
9175 if (htab->symbian_p)
9178 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9179 ? SHT_REL : SHT_RELA);
9181 for (i = 1; i < elf_numsections (output_bfd); i++)
9183 Elf_Internal_Shdr *hdr
9184 = elf_elfsections (output_bfd)[i];
9185 if (hdr->sh_type == type)
9187 if (dyn.d_tag == DT_RELSZ
9188 || dyn.d_tag == DT_RELASZ)
9189 dyn.d_un.d_val += hdr->sh_size;
9190 else if ((ufile_ptr) hdr->sh_offset
9191 <= dyn.d_un.d_val - 1)
9192 dyn.d_un.d_val = hdr->sh_offset;
9195 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9199 /* Set the bottom bit of DT_INIT/FINI if the
9200 corresponding function is Thumb. */
9202 name = info->init_function;
9205 name = info->fini_function;
9207 /* If it wasn't set by elf_bfd_final_link
9208 then there is nothing to adjust. */
9209 if (dyn.d_un.d_val != 0)
9211 struct elf_link_hash_entry * eh;
9213 eh = elf_link_hash_lookup (elf_hash_table (info), name,
9214 FALSE, FALSE, TRUE);
9215 if (eh != (struct elf_link_hash_entry *) NULL
9216 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9218 dyn.d_un.d_val |= 1;
9219 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9226 /* Fill in the first entry in the procedure linkage table. */
9227 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
9229 const bfd_vma *plt0_entry;
9230 bfd_vma got_address, plt_address, got_displacement;
9232 /* Calculate the addresses of the GOT and PLT. */
9233 got_address = sgot->output_section->vma + sgot->output_offset;
9234 plt_address = splt->output_section->vma + splt->output_offset;
9236 if (htab->vxworks_p)
9238 /* The VxWorks GOT is relocated by the dynamic linker.
9239 Therefore, we must emit relocations rather than simply
9240 computing the values now. */
9241 Elf_Internal_Rela rel;
9243 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
9244 put_arm_insn (htab, output_bfd, plt0_entry[0],
9245 splt->contents + 0);
9246 put_arm_insn (htab, output_bfd, plt0_entry[1],
9247 splt->contents + 4);
9248 put_arm_insn (htab, output_bfd, plt0_entry[2],
9249 splt->contents + 8);
9250 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9252 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9253 rel.r_offset = plt_address + 12;
9254 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9256 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9257 htab->srelplt2->contents);
9261 got_displacement = got_address - (plt_address + 16);
9263 plt0_entry = elf32_arm_plt0_entry;
9264 put_arm_insn (htab, output_bfd, plt0_entry[0],
9265 splt->contents + 0);
9266 put_arm_insn (htab, output_bfd, plt0_entry[1],
9267 splt->contents + 4);
9268 put_arm_insn (htab, output_bfd, plt0_entry[2],
9269 splt->contents + 8);
9270 put_arm_insn (htab, output_bfd, plt0_entry[3],
9271 splt->contents + 12);
9273 #ifdef FOUR_WORD_PLT
9274 /* The displacement value goes in the otherwise-unused
9275 last word of the second entry. */
9276 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
9278 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
9283 /* UnixWare sets the entsize of .plt to 4, although that doesn't
9284 really seem like the right value. */
9285 if (splt->output_section->owner == output_bfd)
9286 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
9288 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9290 /* Correct the .rel(a).plt.unloaded relocations. They will have
9291 incorrect symbol indexes. */
9295 num_plts = ((htab->splt->size - htab->plt_header_size)
9296 / htab->plt_entry_size);
9297 p = htab->srelplt2->contents + RELOC_SIZE (htab);
9299 for (; num_plts; num_plts--)
9301 Elf_Internal_Rela rel;
9303 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9304 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9305 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9306 p += RELOC_SIZE (htab);
9308 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9309 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9310 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9311 p += RELOC_SIZE (htab);
9316 /* Fill in the first three entries in the global offset table. */
9322 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9324 bfd_put_32 (output_bfd,
9325 sdyn->output_section->vma + sdyn->output_offset,
9327 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9328 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9331 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9338 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9340 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
9341 struct elf32_arm_link_hash_table *globals;
9343 i_ehdrp = elf_elfheader (abfd);
9345 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
9346 i_ehdrp->e_ident[EI_OSABI] = ARM_ELF_OS_ABI_VERSION;
9348 i_ehdrp->e_ident[EI_OSABI] = 0;
9349 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
9353 globals = elf32_arm_hash_table (link_info);
9354 if (globals->byteswap_code)
9355 i_ehdrp->e_flags |= EF_ARM_BE8;
9359 static enum elf_reloc_type_class
9360 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
9362 switch ((int) ELF32_R_TYPE (rela->r_info))
9364 case R_ARM_RELATIVE:
9365 return reloc_class_relative;
9366 case R_ARM_JUMP_SLOT:
9367 return reloc_class_plt;
9369 return reloc_class_copy;
9371 return reloc_class_normal;
9375 /* Set the right machine number for an Arm ELF file. */
9378 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
9380 if (hdr->sh_type == SHT_NOTE)
9381 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9387 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
9389 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
9392 /* Return TRUE if this is an unwinding table entry. */
9395 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9397 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9398 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
9402 /* Set the type and flags for an ARM section. We do this by
9403 the section name, which is a hack, but ought to work. */
9406 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9410 name = bfd_get_section_name (abfd, sec);
9412 if (is_arm_elf_unwind_section_name (abfd, name))
9414 hdr->sh_type = SHT_ARM_EXIDX;
9415 hdr->sh_flags |= SHF_LINK_ORDER;
9420 /* Handle an ARM specific section when reading an object file. This is
9421 called when bfd_section_from_shdr finds a section with an unknown
9425 elf32_arm_section_from_shdr (bfd *abfd,
9426 Elf_Internal_Shdr * hdr,
9430 /* There ought to be a place to keep ELF backend specific flags, but
9431 at the moment there isn't one. We just keep track of the
9432 sections by their name, instead. Fortunately, the ABI gives
9433 names for all the ARM specific sections, so we will probably get
9435 switch (hdr->sh_type)
9438 case SHT_ARM_PREEMPTMAP:
9439 case SHT_ARM_ATTRIBUTES:
9446 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
9452 /* A structure used to record a list of sections, independently
9453 of the next and prev fields in the asection structure. */
9454 typedef struct section_list
9457 struct section_list * next;
9458 struct section_list * prev;
9462 /* Unfortunately we need to keep a list of sections for which
9463 an _arm_elf_section_data structure has been allocated. This
9464 is because it is possible for functions like elf32_arm_write_section
9465 to be called on a section which has had an elf_data_structure
9466 allocated for it (and so the used_by_bfd field is valid) but
9467 for which the ARM extended version of this structure - the
9468 _arm_elf_section_data structure - has not been allocated. */
9469 static section_list * sections_with_arm_elf_section_data = NULL;
9472 record_section_with_arm_elf_section_data (asection * sec)
9474 struct section_list * entry;
9476 entry = bfd_malloc (sizeof (* entry));
9480 entry->next = sections_with_arm_elf_section_data;
9482 if (entry->next != NULL)
9483 entry->next->prev = entry;
9484 sections_with_arm_elf_section_data = entry;
9487 static struct section_list *
9488 find_arm_elf_section_entry (asection * sec)
9490 struct section_list * entry;
9491 static struct section_list * last_entry = NULL;
9493 /* This is a short cut for the typical case where the sections are added
9494 to the sections_with_arm_elf_section_data list in forward order and
9495 then looked up here in backwards order. This makes a real difference
9496 to the ld-srec/sec64k.exp linker test. */
9497 entry = sections_with_arm_elf_section_data;
9498 if (last_entry != NULL)
9500 if (last_entry->sec == sec)
9502 else if (last_entry->next != NULL
9503 && last_entry->next->sec == sec)
9504 entry = last_entry->next;
9507 for (; entry; entry = entry->next)
9508 if (entry->sec == sec)
9512 /* Record the entry prior to this one - it is the entry we are most
9513 likely to want to locate next time. Also this way if we have been
9514 called from unrecord_section_with_arm_elf_section_data() we will not
9515 be caching a pointer that is about to be freed. */
9516 last_entry = entry->prev;
9521 static _arm_elf_section_data *
9522 get_arm_elf_section_data (asection * sec)
9524 struct section_list * entry;
9526 entry = find_arm_elf_section_entry (sec);
9529 return elf32_arm_section_data (entry->sec);
9535 unrecord_section_with_arm_elf_section_data (asection * sec)
9537 struct section_list * entry;
9539 entry = find_arm_elf_section_entry (sec);
9543 if (entry->prev != NULL)
9544 entry->prev->next = entry->next;
9545 if (entry->next != NULL)
9546 entry->next->prev = entry->prev;
9547 if (entry == sections_with_arm_elf_section_data)
9548 sections_with_arm_elf_section_data = entry->next;
9557 struct bfd_link_info *info;
9560 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9561 asection *, struct elf_link_hash_entry *);
9562 } output_arch_syminfo;
9564 enum map_symbol_type
9572 /* Output a single PLT mapping symbol. */
9575 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9576 enum map_symbol_type type,
9579 static const char *names[3] = {"$a", "$t", "$d"};
9580 struct elf32_arm_link_hash_table *htab;
9581 Elf_Internal_Sym sym;
9583 htab = elf32_arm_hash_table (osi->info);
9584 sym.st_value = osi->sec->output_section->vma
9585 + osi->sec->output_offset
9589 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
9590 sym.st_shndx = osi->sec_shndx;
9591 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
9597 /* Output mapping symbols for PLT entries associated with H. */
9600 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9602 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9603 struct elf32_arm_link_hash_table *htab;
9604 struct elf32_arm_link_hash_entry *eh;
9607 htab = elf32_arm_hash_table (osi->info);
9609 if (h->root.type == bfd_link_hash_indirect)
9612 if (h->root.type == bfd_link_hash_warning)
9613 /* When warning symbols are created, they **replace** the "real"
9614 entry in the hash table, thus we never get to see the real
9615 symbol in a hash traversal. So look at it now. */
9616 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9618 if (h->plt.offset == (bfd_vma) -1)
9621 eh = (struct elf32_arm_link_hash_entry *) h;
9622 addr = h->plt.offset;
9623 if (htab->symbian_p)
9625 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9627 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9630 else if (htab->vxworks_p)
9632 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9634 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9636 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9638 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9643 bfd_boolean thumb_stub;
9645 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9648 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9651 #ifdef FOUR_WORD_PLT
9652 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9654 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9657 /* A three-word PLT with no Thumb thunk contains only Arm code,
9658 so only need to output a mapping symbol for the first PLT entry and
9659 entries with thumb thunks. */
9660 if (thumb_stub || addr == 20)
9662 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9672 /* Output mapping symbols for linker generated sections. */
9675 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9676 struct bfd_link_info *info,
9677 void *finfo, bfd_boolean (*func) (void *, const char *,
9680 struct elf_link_hash_entry *))
9682 output_arch_syminfo osi;
9683 struct elf32_arm_link_hash_table *htab;
9687 htab = elf32_arm_hash_table (info);
9688 check_use_blx(htab);
9694 /* ARM->Thumb glue. */
9695 if (htab->arm_glue_size > 0)
9697 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9698 ARM2THUMB_GLUE_SECTION_NAME);
9700 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9701 (output_bfd, osi.sec->output_section);
9702 if (info->shared || htab->root.is_relocatable_executable
9703 || htab->pic_veneer)
9704 size = ARM2THUMB_PIC_GLUE_SIZE;
9705 else if (htab->use_blx)
9706 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
9708 size = ARM2THUMB_STATIC_GLUE_SIZE;
9710 for (offset = 0; offset < htab->arm_glue_size; offset += size)
9712 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset);
9713 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
9717 /* Thumb->ARM glue. */
9718 if (htab->thumb_glue_size > 0)
9720 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9721 THUMB2ARM_GLUE_SECTION_NAME);
9723 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9724 (output_bfd, osi.sec->output_section);
9725 size = THUMB2ARM_GLUE_SIZE;
9727 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
9729 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset);
9730 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4);
9734 /* Finally, output mapping symbols for the PLT. */
9735 if (!htab->splt || htab->splt->size == 0)
9738 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9739 htab->splt->output_section);
9740 osi.sec = htab->splt;
9741 /* Output mapping symbols for the plt header. SymbianOS does not have a
9743 if (htab->vxworks_p)
9745 /* VxWorks shared libraries have no PLT header. */
9748 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9750 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9754 else if (!htab->symbian_p)
9756 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9758 #ifndef FOUR_WORD_PLT
9759 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9764 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9768 /* Allocate target specific section data. */
9771 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9773 if (!sec->used_by_bfd)
9775 _arm_elf_section_data *sdata;
9776 bfd_size_type amt = sizeof (*sdata);
9778 sdata = bfd_zalloc (abfd, amt);
9781 sec->used_by_bfd = sdata;
9784 record_section_with_arm_elf_section_data (sec);
9786 return _bfd_elf_new_section_hook (abfd, sec);
9790 /* Used to order a list of mapping symbols by address. */
9793 elf32_arm_compare_mapping (const void * a, const void * b)
9795 return ((const elf32_arm_section_map *) a)->vma
9796 > ((const elf32_arm_section_map *) b)->vma;
9800 /* Do code byteswapping. Return FALSE afterwards so that the section is
9801 written out as normal. */
9804 elf32_arm_write_section (bfd *output_bfd,
9805 struct bfd_link_info *link_info, asection *sec,
9808 int mapcount, errcount;
9809 _arm_elf_section_data *arm_data;
9810 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
9811 elf32_arm_section_map *map;
9812 elf32_vfp11_erratum_list *errnode;
9815 bfd_vma offset = sec->output_section->vma + sec->output_offset;
9819 /* If this section has not been allocated an _arm_elf_section_data
9820 structure then we cannot record anything. */
9821 arm_data = get_arm_elf_section_data (sec);
9822 if (arm_data == NULL)
9825 mapcount = arm_data->mapcount;
9826 map = arm_data->map;
9827 errcount = arm_data->erratumcount;
9831 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
9833 for (errnode = arm_data->erratumlist; errnode != 0;
9834 errnode = errnode->next)
9836 bfd_vma index = errnode->vma - offset;
9838 switch (errnode->type)
9840 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
9842 bfd_vma branch_to_veneer;
9843 /* Original condition code of instruction, plus bit mask for
9844 ARM B instruction. */
9845 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
9848 /* The instruction is before the label. */
9851 /* Above offset included in -4 below. */
9852 branch_to_veneer = errnode->u.b.veneer->vma
9855 if ((signed) branch_to_veneer < -(1 << 25)
9856 || (signed) branch_to_veneer >= (1 << 25))
9857 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9858 "range"), output_bfd);
9860 insn |= (branch_to_veneer >> 2) & 0xffffff;
9861 contents[endianflip ^ index] = insn & 0xff;
9862 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9863 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9864 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9868 case VFP11_ERRATUM_ARM_VENEER:
9870 bfd_vma branch_from_veneer;
9873 /* Take size of veneer into account. */
9874 branch_from_veneer = errnode->u.v.branch->vma
9875 - errnode->vma - 12;
9877 if ((signed) branch_from_veneer < -(1 << 25)
9878 || (signed) branch_from_veneer >= (1 << 25))
9879 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9880 "range"), output_bfd);
9882 /* Original instruction. */
9883 insn = errnode->u.v.branch->u.b.vfp_insn;
9884 contents[endianflip ^ index] = insn & 0xff;
9885 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9886 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9887 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9889 /* Branch back to insn after original insn. */
9890 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
9891 contents[endianflip ^ (index + 4)] = insn & 0xff;
9892 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
9893 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
9894 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
9907 if (globals->byteswap_code)
9909 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9912 for (i = 0; i < mapcount; i++)
9914 if (i == mapcount - 1)
9917 end = map[i + 1].vma;
9919 switch (map[i].type)
9922 /* Byte swap code words. */
9923 while (ptr + 3 < end)
9925 tmp = contents[ptr];
9926 contents[ptr] = contents[ptr + 3];
9927 contents[ptr + 3] = tmp;
9928 tmp = contents[ptr + 1];
9929 contents[ptr + 1] = contents[ptr + 2];
9930 contents[ptr + 2] = tmp;
9936 /* Byte swap code halfwords. */
9937 while (ptr + 1 < end)
9939 tmp = contents[ptr];
9940 contents[ptr] = contents[ptr + 1];
9941 contents[ptr + 1] = tmp;
9947 /* Leave data alone. */
9955 arm_data->mapcount = 0;
9956 arm_data->mapsize = 0;
9957 arm_data->map = NULL;
9958 unrecord_section_with_arm_elf_section_data (sec);
9964 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
9966 void * ignore ATTRIBUTE_UNUSED)
9968 unrecord_section_with_arm_elf_section_data (sec);
9972 elf32_arm_close_and_cleanup (bfd * abfd)
9975 bfd_map_over_sections (abfd,
9976 unrecord_section_via_map_over_sections,
9979 return _bfd_elf_close_and_cleanup (abfd);
9983 elf32_arm_bfd_free_cached_info (bfd * abfd)
9986 bfd_map_over_sections (abfd,
9987 unrecord_section_via_map_over_sections,
9990 return _bfd_free_cached_info (abfd);
9993 /* Display STT_ARM_TFUNC symbols as functions. */
9996 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
9999 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10001 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10002 elfsym->symbol.flags |= BSF_FUNCTION;
10006 /* Mangle thumb function symbols as we read them in. */
10009 elf32_arm_swap_symbol_in (bfd * abfd,
10012 Elf_Internal_Sym *dst)
10014 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10017 /* New EABI objects mark thumb function symbols by setting the low bit of
10018 the address. Turn these into STT_ARM_TFUNC. */
10019 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10020 && (dst->st_value & 1))
10022 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10023 dst->st_value &= ~(bfd_vma) 1;
10029 /* Mangle thumb function symbols as we write them out. */
10032 elf32_arm_swap_symbol_out (bfd *abfd,
10033 const Elf_Internal_Sym *src,
10037 Elf_Internal_Sym newsym;
10039 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10040 of the address set, as per the new EABI. We do this unconditionally
10041 because objcopy does not set the elf header flags until after
10042 it writes out the symbol table. */
10043 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10046 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
10047 if (newsym.st_shndx != SHN_UNDEF)
10049 /* Do this only for defined symbols. At link type, the static
10050 linker will simulate the work of dynamic linker of resolving
10051 symbols and will carry over the thumbness of found symbols to
10052 the output symbol table. It's not clear how it happens, but
10053 the thumbness of undefined symbols can well be different at
10054 runtime, and writing '1' for them will be confusing for users
10055 and possibly for dynamic linker itself.
10057 newsym.st_value |= 1;
10062 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10065 /* Add the PT_ARM_EXIDX program header. */
10068 elf32_arm_modify_segment_map (bfd *abfd,
10069 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10071 struct elf_segment_map *m;
10074 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10075 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10077 /* If there is already a PT_ARM_EXIDX header, then we do not
10078 want to add another one. This situation arises when running
10079 "strip"; the input binary already has the header. */
10080 m = elf_tdata (abfd)->segment_map;
10081 while (m && m->p_type != PT_ARM_EXIDX)
10085 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10088 m->p_type = PT_ARM_EXIDX;
10090 m->sections[0] = sec;
10092 m->next = elf_tdata (abfd)->segment_map;
10093 elf_tdata (abfd)->segment_map = m;
10100 /* We may add a PT_ARM_EXIDX program header. */
10103 elf32_arm_additional_program_headers (bfd *abfd,
10104 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10108 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10109 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10115 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
10117 elf32_arm_is_function_type (unsigned int type)
10119 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10122 /* We use this to override swap_symbol_in and swap_symbol_out. */
10123 const struct elf_size_info elf32_arm_size_info = {
10124 sizeof (Elf32_External_Ehdr),
10125 sizeof (Elf32_External_Phdr),
10126 sizeof (Elf32_External_Shdr),
10127 sizeof (Elf32_External_Rel),
10128 sizeof (Elf32_External_Rela),
10129 sizeof (Elf32_External_Sym),
10130 sizeof (Elf32_External_Dyn),
10131 sizeof (Elf_External_Note),
10135 ELFCLASS32, EV_CURRENT,
10136 bfd_elf32_write_out_phdrs,
10137 bfd_elf32_write_shdrs_and_ehdr,
10138 bfd_elf32_write_relocs,
10139 elf32_arm_swap_symbol_in,
10140 elf32_arm_swap_symbol_out,
10141 bfd_elf32_slurp_reloc_table,
10142 bfd_elf32_slurp_symbol_table,
10143 bfd_elf32_swap_dyn_in,
10144 bfd_elf32_swap_dyn_out,
10145 bfd_elf32_swap_reloc_in,
10146 bfd_elf32_swap_reloc_out,
10147 bfd_elf32_swap_reloca_in,
10148 bfd_elf32_swap_reloca_out
10151 #define ELF_ARCH bfd_arch_arm
10152 #define ELF_MACHINE_CODE EM_ARM
10153 #ifdef __QNXTARGET__
10154 #define ELF_MAXPAGESIZE 0x1000
10156 #define ELF_MAXPAGESIZE 0x8000
10158 #define ELF_MINPAGESIZE 0x1000
10159 #define ELF_COMMONPAGESIZE 0x1000
10161 #define bfd_elf32_mkobject elf32_arm_mkobject
10163 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
10164 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
10165 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
10166 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
10167 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
10168 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
10169 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
10170 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
10171 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
10172 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
10173 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
10174 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
10175 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
10177 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
10178 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
10179 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
10180 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
10181 #define elf_backend_check_relocs elf32_arm_check_relocs
10182 #define elf_backend_relocate_section elf32_arm_relocate_section
10183 #define elf_backend_write_section elf32_arm_write_section
10184 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
10185 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
10186 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
10187 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
10188 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
10189 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
10190 #define elf_backend_post_process_headers elf32_arm_post_process_headers
10191 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
10192 #define elf_backend_object_p elf32_arm_object_p
10193 #define elf_backend_section_flags elf32_arm_section_flags
10194 #define elf_backend_fake_sections elf32_arm_fake_sections
10195 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
10196 #define elf_backend_final_write_processing elf32_arm_final_write_processing
10197 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
10198 #define elf_backend_symbol_processing elf32_arm_symbol_processing
10199 #define elf_backend_size_info elf32_arm_size_info
10200 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
10201 #define elf_backend_additional_program_headers \
10202 elf32_arm_additional_program_headers
10203 #define elf_backend_output_arch_local_syms \
10204 elf32_arm_output_arch_local_syms
10205 #define elf_backend_begin_write_processing \
10206 elf32_arm_begin_write_processing
10207 #define elf_backend_is_function_type elf32_arm_is_function_type
10209 #define elf_backend_can_refcount 1
10210 #define elf_backend_can_gc_sections 1
10211 #define elf_backend_plt_readonly 1
10212 #define elf_backend_want_got_plt 1
10213 #define elf_backend_want_plt_sym 0
10214 #define elf_backend_may_use_rel_p 1
10215 #define elf_backend_may_use_rela_p 0
10216 #define elf_backend_default_use_rela_p 0
10218 #define elf_backend_got_header_size 12
10220 #undef elf_backend_obj_attrs_vendor
10221 #define elf_backend_obj_attrs_vendor "aeabi"
10222 #undef elf_backend_obj_attrs_section
10223 #define elf_backend_obj_attrs_section ".ARM.attributes"
10224 #undef elf_backend_obj_attrs_arg_type
10225 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
10226 #undef elf_backend_obj_attrs_section_type
10227 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
10229 #include "elf32-target.h"
10231 /* VxWorks Targets */
10233 #undef TARGET_LITTLE_SYM
10234 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
10235 #undef TARGET_LITTLE_NAME
10236 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
10237 #undef TARGET_BIG_SYM
10238 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
10239 #undef TARGET_BIG_NAME
10240 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
10242 /* Like elf32_arm_link_hash_table_create -- but overrides
10243 appropriately for VxWorks. */
10244 static struct bfd_link_hash_table *
10245 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10247 struct bfd_link_hash_table *ret;
10249 ret = elf32_arm_link_hash_table_create (abfd);
10252 struct elf32_arm_link_hash_table *htab
10253 = (struct elf32_arm_link_hash_table *) ret;
10255 htab->vxworks_p = 1;
10261 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10263 elf32_arm_final_write_processing (abfd, linker);
10264 elf_vxworks_final_write_processing (abfd, linker);
10268 #define elf32_bed elf32_arm_vxworks_bed
10270 #undef bfd_elf32_bfd_link_hash_table_create
10271 #define bfd_elf32_bfd_link_hash_table_create \
10272 elf32_arm_vxworks_link_hash_table_create
10273 #undef elf_backend_add_symbol_hook
10274 #define elf_backend_add_symbol_hook \
10275 elf_vxworks_add_symbol_hook
10276 #undef elf_backend_final_write_processing
10277 #define elf_backend_final_write_processing \
10278 elf32_arm_vxworks_final_write_processing
10279 #undef elf_backend_emit_relocs
10280 #define elf_backend_emit_relocs \
10281 elf_vxworks_emit_relocs
10283 #undef elf_backend_may_use_rel_p
10284 #define elf_backend_may_use_rel_p 0
10285 #undef elf_backend_may_use_rela_p
10286 #define elf_backend_may_use_rela_p 1
10287 #undef elf_backend_default_use_rela_p
10288 #define elf_backend_default_use_rela_p 1
10289 #undef elf_backend_want_plt_sym
10290 #define elf_backend_want_plt_sym 1
10291 #undef ELF_MAXPAGESIZE
10292 #define ELF_MAXPAGESIZE 0x1000
10294 #include "elf32-target.h"
10297 /* Symbian OS Targets */
10299 #undef TARGET_LITTLE_SYM
10300 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
10301 #undef TARGET_LITTLE_NAME
10302 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
10303 #undef TARGET_BIG_SYM
10304 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
10305 #undef TARGET_BIG_NAME
10306 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
10308 /* Like elf32_arm_link_hash_table_create -- but overrides
10309 appropriately for Symbian OS. */
10310 static struct bfd_link_hash_table *
10311 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10313 struct bfd_link_hash_table *ret;
10315 ret = elf32_arm_link_hash_table_create (abfd);
10318 struct elf32_arm_link_hash_table *htab
10319 = (struct elf32_arm_link_hash_table *)ret;
10320 /* There is no PLT header for Symbian OS. */
10321 htab->plt_header_size = 0;
10322 /* The PLT entries are each three instructions. */
10323 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10324 htab->symbian_p = 1;
10325 /* Symbian uses armv5t or above, so use_blx is always true. */
10327 htab->root.is_relocatable_executable = 1;
10332 static const struct bfd_elf_special_section
10333 elf32_arm_symbian_special_sections[] =
10335 /* In a BPABI executable, the dynamic linking sections do not go in
10336 the loadable read-only segment. The post-linker may wish to
10337 refer to these sections, but they are not part of the final
10339 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
10340 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
10341 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
10342 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
10343 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
10344 /* These sections do not need to be writable as the SymbianOS
10345 postlinker will arrange things so that no dynamic relocation is
10347 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
10348 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
10349 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10350 { NULL, 0, 0, 0, 0 }
10354 elf32_arm_symbian_begin_write_processing (bfd *abfd,
10355 struct bfd_link_info *link_info)
10357 /* BPABI objects are never loaded directly by an OS kernel; they are
10358 processed by a postlinker first, into an OS-specific format. If
10359 the D_PAGED bit is set on the file, BFD will align segments on
10360 page boundaries, so that an OS can directly map the file. With
10361 BPABI objects, that just results in wasted space. In addition,
10362 because we clear the D_PAGED bit, map_sections_to_segments will
10363 recognize that the program headers should not be mapped into any
10364 loadable segment. */
10365 abfd->flags &= ~D_PAGED;
10366 elf32_arm_begin_write_processing(abfd, link_info);
10370 elf32_arm_symbian_modify_segment_map (bfd *abfd,
10371 struct bfd_link_info *info)
10373 struct elf_segment_map *m;
10376 /* BPABI shared libraries and executables should have a PT_DYNAMIC
10377 segment. However, because the .dynamic section is not marked
10378 with SEC_LOAD, the generic ELF code will not create such a
10380 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10383 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10384 if (m->p_type == PT_DYNAMIC)
10389 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10390 m->next = elf_tdata (abfd)->segment_map;
10391 elf_tdata (abfd)->segment_map = m;
10395 /* Also call the generic arm routine. */
10396 return elf32_arm_modify_segment_map (abfd, info);
10400 #define elf32_bed elf32_arm_symbian_bed
10402 /* The dynamic sections are not allocated on SymbianOS; the postlinker
10403 will process them and then discard them. */
10404 #undef ELF_DYNAMIC_SEC_FLAGS
10405 #define ELF_DYNAMIC_SEC_FLAGS \
10406 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10408 #undef bfd_elf32_bfd_link_hash_table_create
10409 #define bfd_elf32_bfd_link_hash_table_create \
10410 elf32_arm_symbian_link_hash_table_create
10411 #undef elf_backend_add_symbol_hook
10413 #undef elf_backend_special_sections
10414 #define elf_backend_special_sections elf32_arm_symbian_special_sections
10416 #undef elf_backend_begin_write_processing
10417 #define elf_backend_begin_write_processing \
10418 elf32_arm_symbian_begin_write_processing
10419 #undef elf_backend_final_write_processing
10420 #define elf_backend_final_write_processing \
10421 elf32_arm_final_write_processing
10422 #undef elf_backend_emit_relocs
10424 #undef elf_backend_modify_segment_map
10425 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10427 /* There is no .got section for BPABI objects, and hence no header. */
10428 #undef elf_backend_got_header_size
10429 #define elf_backend_got_header_size 0
10431 /* Similarly, there is no .got.plt section. */
10432 #undef elf_backend_want_got_plt
10433 #define elf_backend_want_got_plt 0
10435 #undef elf_backend_may_use_rel_p
10436 #define elf_backend_may_use_rel_p 1
10437 #undef elf_backend_may_use_rela_p
10438 #define elf_backend_may_use_rela_p 0
10439 #undef elf_backend_default_use_rela_p
10440 #define elf_backend_default_use_rela_p 0
10441 #undef elf_backend_want_plt_sym
10442 #define elf_backend_want_plt_sym 0
10443 #undef ELF_MAXPAGESIZE
10444 #define ELF_MAXPAGESIZE 0x8000
10446 #include "elf32-target.h"