1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
24 #include "libiberty.h"
27 #include "elf-vxworks.h"
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
62 static struct elf_backend_data elf32_arm_vxworks_bed;
64 static bfd_boolean elf32_arm_write_section (bfd *output_bfd,
65 struct bfd_link_info *link_info,
69 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
70 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
73 static reloc_howto_type elf32_arm_howto_table_1[] =
76 HOWTO (R_ARM_NONE, /* type */
78 0, /* size (0 = byte, 1 = short, 2 = long) */
80 FALSE, /* pc_relative */
82 complain_overflow_dont,/* complain_on_overflow */
83 bfd_elf_generic_reloc, /* special_function */
84 "R_ARM_NONE", /* name */
85 FALSE, /* partial_inplace */
88 FALSE), /* pcrel_offset */
90 HOWTO (R_ARM_PC24, /* type */
92 2, /* size (0 = byte, 1 = short, 2 = long) */
94 TRUE, /* pc_relative */
96 complain_overflow_signed,/* complain_on_overflow */
97 bfd_elf_generic_reloc, /* special_function */
98 "R_ARM_PC24", /* name */
99 FALSE, /* partial_inplace */
100 0x00ffffff, /* src_mask */
101 0x00ffffff, /* dst_mask */
102 TRUE), /* pcrel_offset */
104 /* 32 bit absolute */
105 HOWTO (R_ARM_ABS32, /* type */
107 2, /* size (0 = byte, 1 = short, 2 = long) */
109 FALSE, /* pc_relative */
111 complain_overflow_bitfield,/* complain_on_overflow */
112 bfd_elf_generic_reloc, /* special_function */
113 "R_ARM_ABS32", /* name */
114 FALSE, /* partial_inplace */
115 0xffffffff, /* src_mask */
116 0xffffffff, /* dst_mask */
117 FALSE), /* pcrel_offset */
119 /* standard 32bit pc-relative reloc */
120 HOWTO (R_ARM_REL32, /* type */
122 2, /* size (0 = byte, 1 = short, 2 = long) */
124 TRUE, /* pc_relative */
126 complain_overflow_bitfield,/* complain_on_overflow */
127 bfd_elf_generic_reloc, /* special_function */
128 "R_ARM_REL32", /* name */
129 FALSE, /* partial_inplace */
130 0xffffffff, /* src_mask */
131 0xffffffff, /* dst_mask */
132 TRUE), /* pcrel_offset */
134 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
135 HOWTO (R_ARM_LDR_PC_G0, /* type */
137 0, /* size (0 = byte, 1 = short, 2 = long) */
139 TRUE, /* pc_relative */
141 complain_overflow_dont,/* complain_on_overflow */
142 bfd_elf_generic_reloc, /* special_function */
143 "R_ARM_LDR_PC_G0", /* name */
144 FALSE, /* partial_inplace */
145 0xffffffff, /* src_mask */
146 0xffffffff, /* dst_mask */
147 TRUE), /* pcrel_offset */
149 /* 16 bit absolute */
150 HOWTO (R_ARM_ABS16, /* type */
152 1, /* size (0 = byte, 1 = short, 2 = long) */
154 FALSE, /* pc_relative */
156 complain_overflow_bitfield,/* complain_on_overflow */
157 bfd_elf_generic_reloc, /* special_function */
158 "R_ARM_ABS16", /* name */
159 FALSE, /* partial_inplace */
160 0x0000ffff, /* src_mask */
161 0x0000ffff, /* dst_mask */
162 FALSE), /* pcrel_offset */
164 /* 12 bit absolute */
165 HOWTO (R_ARM_ABS12, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 FALSE, /* pc_relative */
171 complain_overflow_bitfield,/* complain_on_overflow */
172 bfd_elf_generic_reloc, /* special_function */
173 "R_ARM_ABS12", /* name */
174 FALSE, /* partial_inplace */
175 0x00000fff, /* src_mask */
176 0x00000fff, /* dst_mask */
177 FALSE), /* pcrel_offset */
179 HOWTO (R_ARM_THM_ABS5, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE, /* pc_relative */
185 complain_overflow_bitfield,/* complain_on_overflow */
186 bfd_elf_generic_reloc, /* special_function */
187 "R_ARM_THM_ABS5", /* name */
188 FALSE, /* partial_inplace */
189 0x000007e0, /* src_mask */
190 0x000007e0, /* dst_mask */
191 FALSE), /* pcrel_offset */
194 HOWTO (R_ARM_ABS8, /* type */
196 0, /* size (0 = byte, 1 = short, 2 = long) */
198 FALSE, /* pc_relative */
200 complain_overflow_bitfield,/* complain_on_overflow */
201 bfd_elf_generic_reloc, /* special_function */
202 "R_ARM_ABS8", /* name */
203 FALSE, /* partial_inplace */
204 0x000000ff, /* src_mask */
205 0x000000ff, /* dst_mask */
206 FALSE), /* pcrel_offset */
208 HOWTO (R_ARM_SBREL32, /* type */
210 2, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE, /* pc_relative */
214 complain_overflow_dont,/* complain_on_overflow */
215 bfd_elf_generic_reloc, /* special_function */
216 "R_ARM_SBREL32", /* name */
217 FALSE, /* partial_inplace */
218 0xffffffff, /* src_mask */
219 0xffffffff, /* dst_mask */
220 FALSE), /* pcrel_offset */
222 HOWTO (R_ARM_THM_CALL, /* type */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
226 TRUE, /* pc_relative */
228 complain_overflow_signed,/* complain_on_overflow */
229 bfd_elf_generic_reloc, /* special_function */
230 "R_ARM_THM_CALL", /* name */
231 FALSE, /* partial_inplace */
232 0x07ff07ff, /* src_mask */
233 0x07ff07ff, /* dst_mask */
234 TRUE), /* pcrel_offset */
236 HOWTO (R_ARM_THM_PC8, /* type */
238 1, /* size (0 = byte, 1 = short, 2 = long) */
240 TRUE, /* pc_relative */
242 complain_overflow_signed,/* complain_on_overflow */
243 bfd_elf_generic_reloc, /* special_function */
244 "R_ARM_THM_PC8", /* name */
245 FALSE, /* partial_inplace */
246 0x000000ff, /* src_mask */
247 0x000000ff, /* dst_mask */
248 TRUE), /* pcrel_offset */
250 HOWTO (R_ARM_BREL_ADJ, /* type */
252 1, /* size (0 = byte, 1 = short, 2 = long) */
254 FALSE, /* pc_relative */
256 complain_overflow_signed,/* complain_on_overflow */
257 bfd_elf_generic_reloc, /* special_function */
258 "R_ARM_BREL_ADJ", /* name */
259 FALSE, /* partial_inplace */
260 0xffffffff, /* src_mask */
261 0xffffffff, /* dst_mask */
262 FALSE), /* pcrel_offset */
264 HOWTO (R_ARM_SWI24, /* type */
266 0, /* size (0 = byte, 1 = short, 2 = long) */
268 FALSE, /* pc_relative */
270 complain_overflow_signed,/* complain_on_overflow */
271 bfd_elf_generic_reloc, /* special_function */
272 "R_ARM_SWI24", /* name */
273 FALSE, /* partial_inplace */
274 0x00000000, /* src_mask */
275 0x00000000, /* dst_mask */
276 FALSE), /* pcrel_offset */
278 HOWTO (R_ARM_THM_SWI8, /* type */
280 0, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE, /* pc_relative */
284 complain_overflow_signed,/* complain_on_overflow */
285 bfd_elf_generic_reloc, /* special_function */
286 "R_ARM_SWI8", /* name */
287 FALSE, /* partial_inplace */
288 0x00000000, /* src_mask */
289 0x00000000, /* dst_mask */
290 FALSE), /* pcrel_offset */
292 /* BLX instruction for the ARM. */
293 HOWTO (R_ARM_XPC25, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 TRUE, /* pc_relative */
299 complain_overflow_signed,/* complain_on_overflow */
300 bfd_elf_generic_reloc, /* special_function */
301 "R_ARM_XPC25", /* name */
302 FALSE, /* partial_inplace */
303 0x00ffffff, /* src_mask */
304 0x00ffffff, /* dst_mask */
305 TRUE), /* pcrel_offset */
307 /* BLX instruction for the Thumb. */
308 HOWTO (R_ARM_THM_XPC22, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 TRUE, /* pc_relative */
314 complain_overflow_signed,/* complain_on_overflow */
315 bfd_elf_generic_reloc, /* special_function */
316 "R_ARM_THM_XPC22", /* name */
317 FALSE, /* partial_inplace */
318 0x07ff07ff, /* src_mask */
319 0x07ff07ff, /* dst_mask */
320 TRUE), /* pcrel_offset */
322 /* Dynamic TLS relocations. */
324 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 FALSE, /* pc_relative */
330 complain_overflow_bitfield,/* complain_on_overflow */
331 bfd_elf_generic_reloc, /* special_function */
332 "R_ARM_TLS_DTPMOD32", /* name */
333 TRUE, /* partial_inplace */
334 0xffffffff, /* src_mask */
335 0xffffffff, /* dst_mask */
336 FALSE), /* pcrel_offset */
338 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE, /* pc_relative */
344 complain_overflow_bitfield,/* complain_on_overflow */
345 bfd_elf_generic_reloc, /* special_function */
346 "R_ARM_TLS_DTPOFF32", /* name */
347 TRUE, /* partial_inplace */
348 0xffffffff, /* src_mask */
349 0xffffffff, /* dst_mask */
350 FALSE), /* pcrel_offset */
352 HOWTO (R_ARM_TLS_TPOFF32, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE, /* pc_relative */
358 complain_overflow_bitfield,/* complain_on_overflow */
359 bfd_elf_generic_reloc, /* special_function */
360 "R_ARM_TLS_TPOFF32", /* name */
361 TRUE, /* partial_inplace */
362 0xffffffff, /* src_mask */
363 0xffffffff, /* dst_mask */
364 FALSE), /* pcrel_offset */
366 /* Relocs used in ARM Linux */
368 HOWTO (R_ARM_COPY, /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE, /* pc_relative */
374 complain_overflow_bitfield,/* complain_on_overflow */
375 bfd_elf_generic_reloc, /* special_function */
376 "R_ARM_COPY", /* name */
377 TRUE, /* partial_inplace */
378 0xffffffff, /* src_mask */
379 0xffffffff, /* dst_mask */
380 FALSE), /* pcrel_offset */
382 HOWTO (R_ARM_GLOB_DAT, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 FALSE, /* pc_relative */
388 complain_overflow_bitfield,/* complain_on_overflow */
389 bfd_elf_generic_reloc, /* special_function */
390 "R_ARM_GLOB_DAT", /* name */
391 TRUE, /* partial_inplace */
392 0xffffffff, /* src_mask */
393 0xffffffff, /* dst_mask */
394 FALSE), /* pcrel_offset */
396 HOWTO (R_ARM_JUMP_SLOT, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE, /* pc_relative */
402 complain_overflow_bitfield,/* complain_on_overflow */
403 bfd_elf_generic_reloc, /* special_function */
404 "R_ARM_JUMP_SLOT", /* name */
405 TRUE, /* partial_inplace */
406 0xffffffff, /* src_mask */
407 0xffffffff, /* dst_mask */
408 FALSE), /* pcrel_offset */
410 HOWTO (R_ARM_RELATIVE, /* type */
412 2, /* size (0 = byte, 1 = short, 2 = long) */
414 FALSE, /* pc_relative */
416 complain_overflow_bitfield,/* complain_on_overflow */
417 bfd_elf_generic_reloc, /* special_function */
418 "R_ARM_RELATIVE", /* name */
419 TRUE, /* partial_inplace */
420 0xffffffff, /* src_mask */
421 0xffffffff, /* dst_mask */
422 FALSE), /* pcrel_offset */
424 HOWTO (R_ARM_GOTOFF32, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE, /* pc_relative */
430 complain_overflow_bitfield,/* complain_on_overflow */
431 bfd_elf_generic_reloc, /* special_function */
432 "R_ARM_GOTOFF32", /* name */
433 TRUE, /* partial_inplace */
434 0xffffffff, /* src_mask */
435 0xffffffff, /* dst_mask */
436 FALSE), /* pcrel_offset */
438 HOWTO (R_ARM_GOTPC, /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 TRUE, /* pc_relative */
444 complain_overflow_bitfield,/* complain_on_overflow */
445 bfd_elf_generic_reloc, /* special_function */
446 "R_ARM_GOTPC", /* name */
447 TRUE, /* partial_inplace */
448 0xffffffff, /* src_mask */
449 0xffffffff, /* dst_mask */
450 TRUE), /* pcrel_offset */
452 HOWTO (R_ARM_GOT32, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE, /* pc_relative */
458 complain_overflow_bitfield,/* complain_on_overflow */
459 bfd_elf_generic_reloc, /* special_function */
460 "R_ARM_GOT32", /* name */
461 TRUE, /* partial_inplace */
462 0xffffffff, /* src_mask */
463 0xffffffff, /* dst_mask */
464 FALSE), /* pcrel_offset */
466 HOWTO (R_ARM_PLT32, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE, /* pc_relative */
472 complain_overflow_bitfield,/* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 "R_ARM_PLT32", /* name */
475 FALSE, /* partial_inplace */
476 0x00ffffff, /* src_mask */
477 0x00ffffff, /* dst_mask */
478 TRUE), /* pcrel_offset */
480 HOWTO (R_ARM_CALL, /* type */
482 2, /* size (0 = byte, 1 = short, 2 = long) */
484 TRUE, /* pc_relative */
486 complain_overflow_signed,/* complain_on_overflow */
487 bfd_elf_generic_reloc, /* special_function */
488 "R_ARM_CALL", /* name */
489 FALSE, /* partial_inplace */
490 0x00ffffff, /* src_mask */
491 0x00ffffff, /* dst_mask */
492 TRUE), /* pcrel_offset */
494 HOWTO (R_ARM_JUMP24, /* type */
496 2, /* size (0 = byte, 1 = short, 2 = long) */
498 TRUE, /* pc_relative */
500 complain_overflow_signed,/* complain_on_overflow */
501 bfd_elf_generic_reloc, /* special_function */
502 "R_ARM_JUMP24", /* name */
503 FALSE, /* partial_inplace */
504 0x00ffffff, /* src_mask */
505 0x00ffffff, /* dst_mask */
506 TRUE), /* pcrel_offset */
508 HOWTO (R_ARM_THM_JUMP24, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 TRUE, /* pc_relative */
514 complain_overflow_signed,/* complain_on_overflow */
515 bfd_elf_generic_reloc, /* special_function */
516 "R_ARM_THM_JUMP24", /* name */
517 FALSE, /* partial_inplace */
518 0x07ff2fff, /* src_mask */
519 0x07ff2fff, /* dst_mask */
520 TRUE), /* pcrel_offset */
522 HOWTO (R_ARM_BASE_ABS, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 FALSE, /* pc_relative */
528 complain_overflow_dont,/* complain_on_overflow */
529 bfd_elf_generic_reloc, /* special_function */
530 "R_ARM_BASE_ABS", /* name */
531 FALSE, /* partial_inplace */
532 0xffffffff, /* src_mask */
533 0xffffffff, /* dst_mask */
534 FALSE), /* pcrel_offset */
536 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 TRUE, /* pc_relative */
542 complain_overflow_dont,/* complain_on_overflow */
543 bfd_elf_generic_reloc, /* special_function */
544 "R_ARM_ALU_PCREL_7_0", /* name */
545 FALSE, /* partial_inplace */
546 0x00000fff, /* src_mask */
547 0x00000fff, /* dst_mask */
548 TRUE), /* pcrel_offset */
550 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 TRUE, /* pc_relative */
556 complain_overflow_dont,/* complain_on_overflow */
557 bfd_elf_generic_reloc, /* special_function */
558 "R_ARM_ALU_PCREL_15_8",/* name */
559 FALSE, /* partial_inplace */
560 0x00000fff, /* src_mask */
561 0x00000fff, /* dst_mask */
562 TRUE), /* pcrel_offset */
564 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 TRUE, /* pc_relative */
570 complain_overflow_dont,/* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 "R_ARM_ALU_PCREL_23_15",/* name */
573 FALSE, /* partial_inplace */
574 0x00000fff, /* src_mask */
575 0x00000fff, /* dst_mask */
576 TRUE), /* pcrel_offset */
578 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE, /* pc_relative */
584 complain_overflow_dont,/* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_ARM_LDR_SBREL_11_0",/* name */
587 FALSE, /* partial_inplace */
588 0x00000fff, /* src_mask */
589 0x00000fff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 FALSE, /* pc_relative */
598 complain_overflow_dont,/* complain_on_overflow */
599 bfd_elf_generic_reloc, /* special_function */
600 "R_ARM_ALU_SBREL_19_12",/* name */
601 FALSE, /* partial_inplace */
602 0x000ff000, /* src_mask */
603 0x000ff000, /* dst_mask */
604 FALSE), /* pcrel_offset */
606 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 FALSE, /* pc_relative */
612 complain_overflow_dont,/* complain_on_overflow */
613 bfd_elf_generic_reloc, /* special_function */
614 "R_ARM_ALU_SBREL_27_20",/* name */
615 FALSE, /* partial_inplace */
616 0x0ff00000, /* src_mask */
617 0x0ff00000, /* dst_mask */
618 FALSE), /* pcrel_offset */
620 HOWTO (R_ARM_TARGET1, /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE, /* pc_relative */
626 complain_overflow_dont,/* complain_on_overflow */
627 bfd_elf_generic_reloc, /* special_function */
628 "R_ARM_TARGET1", /* name */
629 FALSE, /* partial_inplace */
630 0xffffffff, /* src_mask */
631 0xffffffff, /* dst_mask */
632 FALSE), /* pcrel_offset */
634 HOWTO (R_ARM_ROSEGREL32, /* type */
636 2, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE, /* pc_relative */
640 complain_overflow_dont,/* complain_on_overflow */
641 bfd_elf_generic_reloc, /* special_function */
642 "R_ARM_ROSEGREL32", /* name */
643 FALSE, /* partial_inplace */
644 0xffffffff, /* src_mask */
645 0xffffffff, /* dst_mask */
646 FALSE), /* pcrel_offset */
648 HOWTO (R_ARM_V4BX, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 FALSE, /* pc_relative */
654 complain_overflow_dont,/* complain_on_overflow */
655 bfd_elf_generic_reloc, /* special_function */
656 "R_ARM_V4BX", /* name */
657 FALSE, /* partial_inplace */
658 0xffffffff, /* src_mask */
659 0xffffffff, /* dst_mask */
660 FALSE), /* pcrel_offset */
662 HOWTO (R_ARM_TARGET2, /* type */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 FALSE, /* pc_relative */
668 complain_overflow_signed,/* complain_on_overflow */
669 bfd_elf_generic_reloc, /* special_function */
670 "R_ARM_TARGET2", /* name */
671 FALSE, /* partial_inplace */
672 0xffffffff, /* src_mask */
673 0xffffffff, /* dst_mask */
674 TRUE), /* pcrel_offset */
676 HOWTO (R_ARM_PREL31, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE, /* pc_relative */
682 complain_overflow_signed,/* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_ARM_PREL31", /* name */
685 FALSE, /* partial_inplace */
686 0x7fffffff, /* src_mask */
687 0x7fffffff, /* dst_mask */
688 TRUE), /* pcrel_offset */
690 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE, /* pc_relative */
696 complain_overflow_dont,/* complain_on_overflow */
697 bfd_elf_generic_reloc, /* special_function */
698 "R_ARM_MOVW_ABS_NC", /* name */
699 FALSE, /* partial_inplace */
700 0x000f0fff, /* src_mask */
701 0x000f0fff, /* dst_mask */
702 FALSE), /* pcrel_offset */
704 HOWTO (R_ARM_MOVT_ABS, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 FALSE, /* pc_relative */
710 complain_overflow_bitfield,/* complain_on_overflow */
711 bfd_elf_generic_reloc, /* special_function */
712 "R_ARM_MOVT_ABS", /* name */
713 FALSE, /* partial_inplace */
714 0x000f0fff, /* src_mask */
715 0x000f0fff, /* dst_mask */
716 FALSE), /* pcrel_offset */
718 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 TRUE, /* pc_relative */
724 complain_overflow_dont,/* complain_on_overflow */
725 bfd_elf_generic_reloc, /* special_function */
726 "R_ARM_MOVW_PREL_NC", /* name */
727 FALSE, /* partial_inplace */
728 0x000f0fff, /* src_mask */
729 0x000f0fff, /* dst_mask */
730 TRUE), /* pcrel_offset */
732 HOWTO (R_ARM_MOVT_PREL, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 TRUE, /* pc_relative */
738 complain_overflow_bitfield,/* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 "R_ARM_MOVT_PREL", /* name */
741 FALSE, /* partial_inplace */
742 0x000f0fff, /* src_mask */
743 0x000f0fff, /* dst_mask */
744 TRUE), /* pcrel_offset */
746 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 FALSE, /* pc_relative */
752 complain_overflow_dont,/* complain_on_overflow */
753 bfd_elf_generic_reloc, /* special_function */
754 "R_ARM_THM_MOVW_ABS_NC",/* name */
755 FALSE, /* partial_inplace */
756 0x040f70ff, /* src_mask */
757 0x040f70ff, /* dst_mask */
758 FALSE), /* pcrel_offset */
760 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE, /* pc_relative */
766 complain_overflow_bitfield,/* complain_on_overflow */
767 bfd_elf_generic_reloc, /* special_function */
768 "R_ARM_THM_MOVT_ABS", /* name */
769 FALSE, /* partial_inplace */
770 0x040f70ff, /* src_mask */
771 0x040f70ff, /* dst_mask */
772 FALSE), /* pcrel_offset */
774 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 TRUE, /* pc_relative */
780 complain_overflow_dont,/* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 "R_ARM_THM_MOVW_PREL_NC",/* name */
783 FALSE, /* partial_inplace */
784 0x040f70ff, /* src_mask */
785 0x040f70ff, /* dst_mask */
786 TRUE), /* pcrel_offset */
788 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 TRUE, /* pc_relative */
794 complain_overflow_bitfield,/* complain_on_overflow */
795 bfd_elf_generic_reloc, /* special_function */
796 "R_ARM_THM_MOVT_PREL", /* name */
797 FALSE, /* partial_inplace */
798 0x040f70ff, /* src_mask */
799 0x040f70ff, /* dst_mask */
800 TRUE), /* pcrel_offset */
802 HOWTO (R_ARM_THM_JUMP19, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 TRUE, /* pc_relative */
808 complain_overflow_signed,/* complain_on_overflow */
809 bfd_elf_generic_reloc, /* special_function */
810 "R_ARM_THM_JUMP19", /* name */
811 FALSE, /* partial_inplace */
812 0x043f2fff, /* src_mask */
813 0x043f2fff, /* dst_mask */
814 TRUE), /* pcrel_offset */
816 HOWTO (R_ARM_THM_JUMP6, /* type */
818 1, /* size (0 = byte, 1 = short, 2 = long) */
820 TRUE, /* pc_relative */
822 complain_overflow_unsigned,/* complain_on_overflow */
823 bfd_elf_generic_reloc, /* special_function */
824 "R_ARM_THM_JUMP6", /* name */
825 FALSE, /* partial_inplace */
826 0x02f8, /* src_mask */
827 0x02f8, /* dst_mask */
828 TRUE), /* pcrel_offset */
830 /* These are declared as 13-bit signed relocations because we can
831 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
833 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 TRUE, /* pc_relative */
839 complain_overflow_dont,/* complain_on_overflow */
840 bfd_elf_generic_reloc, /* special_function */
841 "R_ARM_THM_ALU_PREL_11_0",/* name */
842 FALSE, /* partial_inplace */
843 0xffffffff, /* src_mask */
844 0xffffffff, /* dst_mask */
845 TRUE), /* pcrel_offset */
847 HOWTO (R_ARM_THM_PC12, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 TRUE, /* pc_relative */
853 complain_overflow_dont,/* complain_on_overflow */
854 bfd_elf_generic_reloc, /* special_function */
855 "R_ARM_THM_PC12", /* name */
856 FALSE, /* partial_inplace */
857 0xffffffff, /* src_mask */
858 0xffffffff, /* dst_mask */
859 TRUE), /* pcrel_offset */
861 HOWTO (R_ARM_ABS32_NOI, /* type */
863 2, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE, /* pc_relative */
867 complain_overflow_dont,/* complain_on_overflow */
868 bfd_elf_generic_reloc, /* special_function */
869 "R_ARM_ABS32_NOI", /* name */
870 FALSE, /* partial_inplace */
871 0xffffffff, /* src_mask */
872 0xffffffff, /* dst_mask */
873 FALSE), /* pcrel_offset */
875 HOWTO (R_ARM_REL32_NOI, /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 TRUE, /* pc_relative */
881 complain_overflow_dont,/* complain_on_overflow */
882 bfd_elf_generic_reloc, /* special_function */
883 "R_ARM_REL32_NOI", /* name */
884 FALSE, /* partial_inplace */
885 0xffffffff, /* src_mask */
886 0xffffffff, /* dst_mask */
887 FALSE), /* pcrel_offset */
889 /* Group relocations. */
891 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 TRUE, /* pc_relative */
897 complain_overflow_dont,/* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 "R_ARM_ALU_PC_G0_NC", /* name */
900 FALSE, /* partial_inplace */
901 0xffffffff, /* src_mask */
902 0xffffffff, /* dst_mask */
903 TRUE), /* pcrel_offset */
905 HOWTO (R_ARM_ALU_PC_G0, /* type */
907 2, /* size (0 = byte, 1 = short, 2 = long) */
909 TRUE, /* pc_relative */
911 complain_overflow_dont,/* complain_on_overflow */
912 bfd_elf_generic_reloc, /* special_function */
913 "R_ARM_ALU_PC_G0", /* name */
914 FALSE, /* partial_inplace */
915 0xffffffff, /* src_mask */
916 0xffffffff, /* dst_mask */
917 TRUE), /* pcrel_offset */
919 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 TRUE, /* pc_relative */
925 complain_overflow_dont,/* complain_on_overflow */
926 bfd_elf_generic_reloc, /* special_function */
927 "R_ARM_ALU_PC_G1_NC", /* name */
928 FALSE, /* partial_inplace */
929 0xffffffff, /* src_mask */
930 0xffffffff, /* dst_mask */
931 TRUE), /* pcrel_offset */
933 HOWTO (R_ARM_ALU_PC_G1, /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 TRUE, /* pc_relative */
939 complain_overflow_dont,/* complain_on_overflow */
940 bfd_elf_generic_reloc, /* special_function */
941 "R_ARM_ALU_PC_G1", /* name */
942 FALSE, /* partial_inplace */
943 0xffffffff, /* src_mask */
944 0xffffffff, /* dst_mask */
945 TRUE), /* pcrel_offset */
947 HOWTO (R_ARM_ALU_PC_G2, /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 TRUE, /* pc_relative */
953 complain_overflow_dont,/* complain_on_overflow */
954 bfd_elf_generic_reloc, /* special_function */
955 "R_ARM_ALU_PC_G2", /* name */
956 FALSE, /* partial_inplace */
957 0xffffffff, /* src_mask */
958 0xffffffff, /* dst_mask */
959 TRUE), /* pcrel_offset */
961 HOWTO (R_ARM_LDR_PC_G1, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 TRUE, /* pc_relative */
967 complain_overflow_dont,/* complain_on_overflow */
968 bfd_elf_generic_reloc, /* special_function */
969 "R_ARM_LDR_PC_G1", /* name */
970 FALSE, /* partial_inplace */
971 0xffffffff, /* src_mask */
972 0xffffffff, /* dst_mask */
973 TRUE), /* pcrel_offset */
975 HOWTO (R_ARM_LDR_PC_G2, /* type */
977 2, /* size (0 = byte, 1 = short, 2 = long) */
979 TRUE, /* pc_relative */
981 complain_overflow_dont,/* complain_on_overflow */
982 bfd_elf_generic_reloc, /* special_function */
983 "R_ARM_LDR_PC_G2", /* name */
984 FALSE, /* partial_inplace */
985 0xffffffff, /* src_mask */
986 0xffffffff, /* dst_mask */
987 TRUE), /* pcrel_offset */
989 HOWTO (R_ARM_LDRS_PC_G0, /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 TRUE, /* pc_relative */
995 complain_overflow_dont,/* complain_on_overflow */
996 bfd_elf_generic_reloc, /* special_function */
997 "R_ARM_LDRS_PC_G0", /* name */
998 FALSE, /* partial_inplace */
999 0xffffffff, /* src_mask */
1000 0xffffffff, /* dst_mask */
1001 TRUE), /* pcrel_offset */
1003 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 TRUE, /* pc_relative */
1009 complain_overflow_dont,/* complain_on_overflow */
1010 bfd_elf_generic_reloc, /* special_function */
1011 "R_ARM_LDRS_PC_G1", /* name */
1012 FALSE, /* partial_inplace */
1013 0xffffffff, /* src_mask */
1014 0xffffffff, /* dst_mask */
1015 TRUE), /* pcrel_offset */
1017 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 TRUE, /* pc_relative */
1023 complain_overflow_dont,/* complain_on_overflow */
1024 bfd_elf_generic_reloc, /* special_function */
1025 "R_ARM_LDRS_PC_G2", /* name */
1026 FALSE, /* partial_inplace */
1027 0xffffffff, /* src_mask */
1028 0xffffffff, /* dst_mask */
1029 TRUE), /* pcrel_offset */
1031 HOWTO (R_ARM_LDC_PC_G0, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 TRUE, /* pc_relative */
1037 complain_overflow_dont,/* complain_on_overflow */
1038 bfd_elf_generic_reloc, /* special_function */
1039 "R_ARM_LDC_PC_G0", /* name */
1040 FALSE, /* partial_inplace */
1041 0xffffffff, /* src_mask */
1042 0xffffffff, /* dst_mask */
1043 TRUE), /* pcrel_offset */
1045 HOWTO (R_ARM_LDC_PC_G1, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 TRUE, /* pc_relative */
1051 complain_overflow_dont,/* complain_on_overflow */
1052 bfd_elf_generic_reloc, /* special_function */
1053 "R_ARM_LDC_PC_G1", /* name */
1054 FALSE, /* partial_inplace */
1055 0xffffffff, /* src_mask */
1056 0xffffffff, /* dst_mask */
1057 TRUE), /* pcrel_offset */
1059 HOWTO (R_ARM_LDC_PC_G2, /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 TRUE, /* pc_relative */
1065 complain_overflow_dont,/* complain_on_overflow */
1066 bfd_elf_generic_reloc, /* special_function */
1067 "R_ARM_LDC_PC_G2", /* name */
1068 FALSE, /* partial_inplace */
1069 0xffffffff, /* src_mask */
1070 0xffffffff, /* dst_mask */
1071 TRUE), /* pcrel_offset */
1073 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 TRUE, /* pc_relative */
1079 complain_overflow_dont,/* complain_on_overflow */
1080 bfd_elf_generic_reloc, /* special_function */
1081 "R_ARM_ALU_SB_G0_NC", /* name */
1082 FALSE, /* partial_inplace */
1083 0xffffffff, /* src_mask */
1084 0xffffffff, /* dst_mask */
1085 TRUE), /* pcrel_offset */
1087 HOWTO (R_ARM_ALU_SB_G0, /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 TRUE, /* pc_relative */
1093 complain_overflow_dont,/* complain_on_overflow */
1094 bfd_elf_generic_reloc, /* special_function */
1095 "R_ARM_ALU_SB_G0", /* name */
1096 FALSE, /* partial_inplace */
1097 0xffffffff, /* src_mask */
1098 0xffffffff, /* dst_mask */
1099 TRUE), /* pcrel_offset */
1101 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1103 2, /* size (0 = byte, 1 = short, 2 = long) */
1105 TRUE, /* pc_relative */
1107 complain_overflow_dont,/* complain_on_overflow */
1108 bfd_elf_generic_reloc, /* special_function */
1109 "R_ARM_ALU_SB_G1_NC", /* name */
1110 FALSE, /* partial_inplace */
1111 0xffffffff, /* src_mask */
1112 0xffffffff, /* dst_mask */
1113 TRUE), /* pcrel_offset */
1115 HOWTO (R_ARM_ALU_SB_G1, /* type */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 TRUE, /* pc_relative */
1121 complain_overflow_dont,/* complain_on_overflow */
1122 bfd_elf_generic_reloc, /* special_function */
1123 "R_ARM_ALU_SB_G1", /* name */
1124 FALSE, /* partial_inplace */
1125 0xffffffff, /* src_mask */
1126 0xffffffff, /* dst_mask */
1127 TRUE), /* pcrel_offset */
1129 HOWTO (R_ARM_ALU_SB_G2, /* type */
1131 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 TRUE, /* pc_relative */
1135 complain_overflow_dont,/* complain_on_overflow */
1136 bfd_elf_generic_reloc, /* special_function */
1137 "R_ARM_ALU_SB_G2", /* name */
1138 FALSE, /* partial_inplace */
1139 0xffffffff, /* src_mask */
1140 0xffffffff, /* dst_mask */
1141 TRUE), /* pcrel_offset */
1143 HOWTO (R_ARM_LDR_SB_G0, /* type */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 TRUE, /* pc_relative */
1149 complain_overflow_dont,/* complain_on_overflow */
1150 bfd_elf_generic_reloc, /* special_function */
1151 "R_ARM_LDR_SB_G0", /* name */
1152 FALSE, /* partial_inplace */
1153 0xffffffff, /* src_mask */
1154 0xffffffff, /* dst_mask */
1155 TRUE), /* pcrel_offset */
1157 HOWTO (R_ARM_LDR_SB_G1, /* type */
1159 2, /* size (0 = byte, 1 = short, 2 = long) */
1161 TRUE, /* pc_relative */
1163 complain_overflow_dont,/* complain_on_overflow */
1164 bfd_elf_generic_reloc, /* special_function */
1165 "R_ARM_LDR_SB_G1", /* name */
1166 FALSE, /* partial_inplace */
1167 0xffffffff, /* src_mask */
1168 0xffffffff, /* dst_mask */
1169 TRUE), /* pcrel_offset */
1171 HOWTO (R_ARM_LDR_SB_G2, /* type */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 TRUE, /* pc_relative */
1177 complain_overflow_dont,/* complain_on_overflow */
1178 bfd_elf_generic_reloc, /* special_function */
1179 "R_ARM_LDR_SB_G2", /* name */
1180 FALSE, /* partial_inplace */
1181 0xffffffff, /* src_mask */
1182 0xffffffff, /* dst_mask */
1183 TRUE), /* pcrel_offset */
1185 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1187 2, /* size (0 = byte, 1 = short, 2 = long) */
1189 TRUE, /* pc_relative */
1191 complain_overflow_dont,/* complain_on_overflow */
1192 bfd_elf_generic_reloc, /* special_function */
1193 "R_ARM_LDRS_SB_G0", /* name */
1194 FALSE, /* partial_inplace */
1195 0xffffffff, /* src_mask */
1196 0xffffffff, /* dst_mask */
1197 TRUE), /* pcrel_offset */
1199 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1201 2, /* size (0 = byte, 1 = short, 2 = long) */
1203 TRUE, /* pc_relative */
1205 complain_overflow_dont,/* complain_on_overflow */
1206 bfd_elf_generic_reloc, /* special_function */
1207 "R_ARM_LDRS_SB_G1", /* name */
1208 FALSE, /* partial_inplace */
1209 0xffffffff, /* src_mask */
1210 0xffffffff, /* dst_mask */
1211 TRUE), /* pcrel_offset */
1213 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1215 2, /* size (0 = byte, 1 = short, 2 = long) */
1217 TRUE, /* pc_relative */
1219 complain_overflow_dont,/* complain_on_overflow */
1220 bfd_elf_generic_reloc, /* special_function */
1221 "R_ARM_LDRS_SB_G2", /* name */
1222 FALSE, /* partial_inplace */
1223 0xffffffff, /* src_mask */
1224 0xffffffff, /* dst_mask */
1225 TRUE), /* pcrel_offset */
1227 HOWTO (R_ARM_LDC_SB_G0, /* type */
1229 2, /* size (0 = byte, 1 = short, 2 = long) */
1231 TRUE, /* pc_relative */
1233 complain_overflow_dont,/* complain_on_overflow */
1234 bfd_elf_generic_reloc, /* special_function */
1235 "R_ARM_LDC_SB_G0", /* name */
1236 FALSE, /* partial_inplace */
1237 0xffffffff, /* src_mask */
1238 0xffffffff, /* dst_mask */
1239 TRUE), /* pcrel_offset */
1241 HOWTO (R_ARM_LDC_SB_G1, /* type */
1243 2, /* size (0 = byte, 1 = short, 2 = long) */
1245 TRUE, /* pc_relative */
1247 complain_overflow_dont,/* complain_on_overflow */
1248 bfd_elf_generic_reloc, /* special_function */
1249 "R_ARM_LDC_SB_G1", /* name */
1250 FALSE, /* partial_inplace */
1251 0xffffffff, /* src_mask */
1252 0xffffffff, /* dst_mask */
1253 TRUE), /* pcrel_offset */
1255 HOWTO (R_ARM_LDC_SB_G2, /* type */
1257 2, /* size (0 = byte, 1 = short, 2 = long) */
1259 TRUE, /* pc_relative */
1261 complain_overflow_dont,/* complain_on_overflow */
1262 bfd_elf_generic_reloc, /* special_function */
1263 "R_ARM_LDC_SB_G2", /* name */
1264 FALSE, /* partial_inplace */
1265 0xffffffff, /* src_mask */
1266 0xffffffff, /* dst_mask */
1267 TRUE), /* pcrel_offset */
1269 /* End of group relocations. */
1271 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1273 2, /* size (0 = byte, 1 = short, 2 = long) */
1275 FALSE, /* pc_relative */
1277 complain_overflow_dont,/* complain_on_overflow */
1278 bfd_elf_generic_reloc, /* special_function */
1279 "R_ARM_MOVW_BREL_NC", /* name */
1280 FALSE, /* partial_inplace */
1281 0x0000ffff, /* src_mask */
1282 0x0000ffff, /* dst_mask */
1283 FALSE), /* pcrel_offset */
1285 HOWTO (R_ARM_MOVT_BREL, /* type */
1287 2, /* size (0 = byte, 1 = short, 2 = long) */
1289 FALSE, /* pc_relative */
1291 complain_overflow_bitfield,/* complain_on_overflow */
1292 bfd_elf_generic_reloc, /* special_function */
1293 "R_ARM_MOVT_BREL", /* name */
1294 FALSE, /* partial_inplace */
1295 0x0000ffff, /* src_mask */
1296 0x0000ffff, /* dst_mask */
1297 FALSE), /* pcrel_offset */
1299 HOWTO (R_ARM_MOVW_BREL, /* type */
1301 2, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE, /* pc_relative */
1305 complain_overflow_dont,/* complain_on_overflow */
1306 bfd_elf_generic_reloc, /* special_function */
1307 "R_ARM_MOVW_BREL", /* name */
1308 FALSE, /* partial_inplace */
1309 0x0000ffff, /* src_mask */
1310 0x0000ffff, /* dst_mask */
1311 FALSE), /* pcrel_offset */
1313 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1315 2, /* size (0 = byte, 1 = short, 2 = long) */
1317 FALSE, /* pc_relative */
1319 complain_overflow_dont,/* complain_on_overflow */
1320 bfd_elf_generic_reloc, /* special_function */
1321 "R_ARM_THM_MOVW_BREL_NC",/* name */
1322 FALSE, /* partial_inplace */
1323 0x040f70ff, /* src_mask */
1324 0x040f70ff, /* dst_mask */
1325 FALSE), /* pcrel_offset */
1327 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1329 2, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE, /* pc_relative */
1333 complain_overflow_bitfield,/* complain_on_overflow */
1334 bfd_elf_generic_reloc, /* special_function */
1335 "R_ARM_THM_MOVT_BREL", /* name */
1336 FALSE, /* partial_inplace */
1337 0x040f70ff, /* src_mask */
1338 0x040f70ff, /* dst_mask */
1339 FALSE), /* pcrel_offset */
1341 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE, /* pc_relative */
1347 complain_overflow_dont,/* complain_on_overflow */
1348 bfd_elf_generic_reloc, /* special_function */
1349 "R_ARM_THM_MOVW_BREL", /* name */
1350 FALSE, /* partial_inplace */
1351 0x040f70ff, /* src_mask */
1352 0x040f70ff, /* dst_mask */
1353 FALSE), /* pcrel_offset */
1355 EMPTY_HOWTO (90), /* Unallocated. */
1360 HOWTO (R_ARM_PLT32_ABS, /* type */
1362 2, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE, /* pc_relative */
1366 complain_overflow_dont,/* complain_on_overflow */
1367 bfd_elf_generic_reloc, /* special_function */
1368 "R_ARM_PLT32_ABS", /* name */
1369 FALSE, /* partial_inplace */
1370 0xffffffff, /* src_mask */
1371 0xffffffff, /* dst_mask */
1372 FALSE), /* pcrel_offset */
1374 HOWTO (R_ARM_GOT_ABS, /* type */
1376 2, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE, /* pc_relative */
1380 complain_overflow_dont,/* complain_on_overflow */
1381 bfd_elf_generic_reloc, /* special_function */
1382 "R_ARM_GOT_ABS", /* name */
1383 FALSE, /* partial_inplace */
1384 0xffffffff, /* src_mask */
1385 0xffffffff, /* dst_mask */
1386 FALSE), /* pcrel_offset */
1388 HOWTO (R_ARM_GOT_PREL, /* type */
1390 2, /* size (0 = byte, 1 = short, 2 = long) */
1392 TRUE, /* pc_relative */
1394 complain_overflow_dont, /* complain_on_overflow */
1395 bfd_elf_generic_reloc, /* special_function */
1396 "R_ARM_GOT_PREL", /* name */
1397 FALSE, /* partial_inplace */
1398 0xffffffff, /* src_mask */
1399 0xffffffff, /* dst_mask */
1400 TRUE), /* pcrel_offset */
1402 HOWTO (R_ARM_GOT_BREL12, /* type */
1404 2, /* size (0 = byte, 1 = short, 2 = long) */
1406 FALSE, /* pc_relative */
1408 complain_overflow_bitfield,/* complain_on_overflow */
1409 bfd_elf_generic_reloc, /* special_function */
1410 "R_ARM_GOT_BREL12", /* name */
1411 FALSE, /* partial_inplace */
1412 0x00000fff, /* src_mask */
1413 0x00000fff, /* dst_mask */
1414 FALSE), /* pcrel_offset */
1416 HOWTO (R_ARM_GOTOFF12, /* type */
1418 2, /* size (0 = byte, 1 = short, 2 = long) */
1420 FALSE, /* pc_relative */
1422 complain_overflow_bitfield,/* complain_on_overflow */
1423 bfd_elf_generic_reloc, /* special_function */
1424 "R_ARM_GOTOFF12", /* name */
1425 FALSE, /* partial_inplace */
1426 0x00000fff, /* src_mask */
1427 0x00000fff, /* dst_mask */
1428 FALSE), /* pcrel_offset */
1430 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1432 /* GNU extension to record C++ vtable member usage */
1433 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1435 2, /* size (0 = byte, 1 = short, 2 = long) */
1437 FALSE, /* pc_relative */
1439 complain_overflow_dont, /* complain_on_overflow */
1440 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1441 "R_ARM_GNU_VTENTRY", /* name */
1442 FALSE, /* partial_inplace */
1445 FALSE), /* pcrel_offset */
1447 /* GNU extension to record C++ vtable hierarchy */
1448 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1450 2, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE, /* pc_relative */
1454 complain_overflow_dont, /* complain_on_overflow */
1455 NULL, /* special_function */
1456 "R_ARM_GNU_VTINHERIT", /* name */
1457 FALSE, /* partial_inplace */
1460 FALSE), /* pcrel_offset */
1462 HOWTO (R_ARM_THM_JUMP11, /* type */
1464 1, /* size (0 = byte, 1 = short, 2 = long) */
1466 TRUE, /* pc_relative */
1468 complain_overflow_signed, /* complain_on_overflow */
1469 bfd_elf_generic_reloc, /* special_function */
1470 "R_ARM_THM_JUMP11", /* name */
1471 FALSE, /* partial_inplace */
1472 0x000007ff, /* src_mask */
1473 0x000007ff, /* dst_mask */
1474 TRUE), /* pcrel_offset */
1476 HOWTO (R_ARM_THM_JUMP8, /* type */
1478 1, /* size (0 = byte, 1 = short, 2 = long) */
1480 TRUE, /* pc_relative */
1482 complain_overflow_signed, /* complain_on_overflow */
1483 bfd_elf_generic_reloc, /* special_function */
1484 "R_ARM_THM_JUMP8", /* name */
1485 FALSE, /* partial_inplace */
1486 0x000000ff, /* src_mask */
1487 0x000000ff, /* dst_mask */
1488 TRUE), /* pcrel_offset */
1490 /* TLS relocations */
1491 HOWTO (R_ARM_TLS_GD32, /* type */
1493 2, /* size (0 = byte, 1 = short, 2 = long) */
1495 FALSE, /* pc_relative */
1497 complain_overflow_bitfield,/* complain_on_overflow */
1498 NULL, /* special_function */
1499 "R_ARM_TLS_GD32", /* name */
1500 TRUE, /* partial_inplace */
1501 0xffffffff, /* src_mask */
1502 0xffffffff, /* dst_mask */
1503 FALSE), /* pcrel_offset */
1505 HOWTO (R_ARM_TLS_LDM32, /* type */
1507 2, /* size (0 = byte, 1 = short, 2 = long) */
1509 FALSE, /* pc_relative */
1511 complain_overflow_bitfield,/* complain_on_overflow */
1512 bfd_elf_generic_reloc, /* special_function */
1513 "R_ARM_TLS_LDM32", /* name */
1514 TRUE, /* partial_inplace */
1515 0xffffffff, /* src_mask */
1516 0xffffffff, /* dst_mask */
1517 FALSE), /* pcrel_offset */
1519 HOWTO (R_ARM_TLS_LDO32, /* type */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 FALSE, /* pc_relative */
1525 complain_overflow_bitfield,/* complain_on_overflow */
1526 bfd_elf_generic_reloc, /* special_function */
1527 "R_ARM_TLS_LDO32", /* name */
1528 TRUE, /* partial_inplace */
1529 0xffffffff, /* src_mask */
1530 0xffffffff, /* dst_mask */
1531 FALSE), /* pcrel_offset */
1533 HOWTO (R_ARM_TLS_IE32, /* type */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE, /* pc_relative */
1539 complain_overflow_bitfield,/* complain_on_overflow */
1540 NULL, /* special_function */
1541 "R_ARM_TLS_IE32", /* name */
1542 TRUE, /* partial_inplace */
1543 0xffffffff, /* src_mask */
1544 0xffffffff, /* dst_mask */
1545 FALSE), /* pcrel_offset */
1547 HOWTO (R_ARM_TLS_LE32, /* type */
1549 2, /* size (0 = byte, 1 = short, 2 = long) */
1551 FALSE, /* pc_relative */
1553 complain_overflow_bitfield,/* complain_on_overflow */
1554 bfd_elf_generic_reloc, /* special_function */
1555 "R_ARM_TLS_LE32", /* name */
1556 TRUE, /* partial_inplace */
1557 0xffffffff, /* src_mask */
1558 0xffffffff, /* dst_mask */
1559 FALSE), /* pcrel_offset */
1561 HOWTO (R_ARM_TLS_LDO12, /* type */
1563 2, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE, /* pc_relative */
1567 complain_overflow_bitfield,/* complain_on_overflow */
1568 bfd_elf_generic_reloc, /* special_function */
1569 "R_ARM_TLS_LDO12", /* name */
1570 FALSE, /* partial_inplace */
1571 0x00000fff, /* src_mask */
1572 0x00000fff, /* dst_mask */
1573 FALSE), /* pcrel_offset */
1575 HOWTO (R_ARM_TLS_LE12, /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE, /* pc_relative */
1581 complain_overflow_bitfield,/* complain_on_overflow */
1582 bfd_elf_generic_reloc, /* special_function */
1583 "R_ARM_TLS_LE12", /* name */
1584 FALSE, /* partial_inplace */
1585 0x00000fff, /* src_mask */
1586 0x00000fff, /* dst_mask */
1587 FALSE), /* pcrel_offset */
1589 HOWTO (R_ARM_TLS_IE12GP, /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE, /* pc_relative */
1595 complain_overflow_bitfield,/* complain_on_overflow */
1596 bfd_elf_generic_reloc, /* special_function */
1597 "R_ARM_TLS_IE12GP", /* name */
1598 FALSE, /* partial_inplace */
1599 0x00000fff, /* src_mask */
1600 0x00000fff, /* dst_mask */
1601 FALSE), /* pcrel_offset */
1604 /* 112-127 private relocations
1605 128 R_ARM_ME_TOO, obsolete
1606 129-255 unallocated in AAELF.
1608 249-255 extended, currently unused, relocations: */
1610 static reloc_howto_type elf32_arm_howto_table_2[4] =
1612 HOWTO (R_ARM_RREL32, /* type */
1614 0, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE, /* pc_relative */
1618 complain_overflow_dont,/* complain_on_overflow */
1619 bfd_elf_generic_reloc, /* special_function */
1620 "R_ARM_RREL32", /* name */
1621 FALSE, /* partial_inplace */
1624 FALSE), /* pcrel_offset */
1626 HOWTO (R_ARM_RABS32, /* type */
1628 0, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE, /* pc_relative */
1632 complain_overflow_dont,/* complain_on_overflow */
1633 bfd_elf_generic_reloc, /* special_function */
1634 "R_ARM_RABS32", /* name */
1635 FALSE, /* partial_inplace */
1638 FALSE), /* pcrel_offset */
1640 HOWTO (R_ARM_RPC24, /* type */
1642 0, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE, /* pc_relative */
1646 complain_overflow_dont,/* complain_on_overflow */
1647 bfd_elf_generic_reloc, /* special_function */
1648 "R_ARM_RPC24", /* name */
1649 FALSE, /* partial_inplace */
1652 FALSE), /* pcrel_offset */
1654 HOWTO (R_ARM_RBASE, /* type */
1656 0, /* size (0 = byte, 1 = short, 2 = long) */
1658 FALSE, /* pc_relative */
1660 complain_overflow_dont,/* complain_on_overflow */
1661 bfd_elf_generic_reloc, /* special_function */
1662 "R_ARM_RBASE", /* name */
1663 FALSE, /* partial_inplace */
1666 FALSE) /* pcrel_offset */
1669 static reloc_howto_type *
1670 elf32_arm_howto_from_type (unsigned int r_type)
1672 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1673 return &elf32_arm_howto_table_1[r_type];
1675 if (r_type >= R_ARM_RREL32
1676 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
1677 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1683 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1684 Elf_Internal_Rela * elf_reloc)
1686 unsigned int r_type;
1688 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1689 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1692 struct elf32_arm_reloc_map
1694 bfd_reloc_code_real_type bfd_reloc_val;
1695 unsigned char elf_reloc_val;
1698 /* All entries in this list must also be present in elf32_arm_howto_table. */
1699 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1701 {BFD_RELOC_NONE, R_ARM_NONE},
1702 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1703 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1704 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1705 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1706 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1707 {BFD_RELOC_32, R_ARM_ABS32},
1708 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1709 {BFD_RELOC_8, R_ARM_ABS8},
1710 {BFD_RELOC_16, R_ARM_ABS16},
1711 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1712 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1718 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1719 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1720 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1721 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1722 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1723 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1724 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1725 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1726 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1727 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1728 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1729 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1730 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1731 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1732 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1733 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1734 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1735 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1736 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1737 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1738 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1739 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1740 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1741 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1742 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1743 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1744 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1745 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1746 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1747 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1748 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1749 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1750 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1751 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1752 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1753 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1754 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1755 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1756 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1757 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1758 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1759 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1760 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1761 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1762 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1763 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1764 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1765 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1766 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1767 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1768 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1769 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1770 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1771 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1772 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1773 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1774 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1775 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1776 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1777 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1778 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
1781 static reloc_howto_type *
1782 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1783 bfd_reloc_code_real_type code)
1787 for (i = 0; i < ARRAY_SIZE (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,
1800 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1801 if (elf32_arm_howto_table_1[i].name != NULL
1802 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1803 return &elf32_arm_howto_table_1[i];
1805 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1806 if (elf32_arm_howto_table_2[i].name != NULL
1807 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1808 return &elf32_arm_howto_table_2[i];
1813 /* Support for core dump NOTE sections. */
1816 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1821 switch (note->descsz)
1826 case 148: /* Linux/ARM 32-bit. */
1828 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1831 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1840 /* Make a ".reg/999" section. */
1841 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1842 size, note->descpos + offset);
1846 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1848 switch (note->descsz)
1853 case 124: /* Linux/ARM elf_prpsinfo. */
1854 elf_tdata (abfd)->core_program
1855 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1856 elf_tdata (abfd)->core_command
1857 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1860 /* Note that for some reason, a spurious space is tacked
1861 onto the end of the args in some (at least one anyway)
1862 implementations, so strip it off if it exists. */
1864 char *command = elf_tdata (abfd)->core_command;
1865 int n = strlen (command);
1867 if (0 < n && command[n - 1] == ' ')
1868 command[n - 1] = '\0';
1874 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1875 #define TARGET_LITTLE_NAME "elf32-littlearm"
1876 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1877 #define TARGET_BIG_NAME "elf32-bigarm"
1879 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1880 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1882 typedef unsigned long int insn32;
1883 typedef unsigned short int insn16;
1885 /* In lieu of proper flags, assume all EABIv4 or later objects are
1887 #define INTERWORK_FLAG(abfd) \
1888 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1889 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
1890 || ((abfd)->flags & BFD_LINKER_CREATED))
1892 /* The linker script knows the section names for placement.
1893 The entry_names are used to do simple name mangling on the stubs.
1894 Given a function name, and its type, the stub can be found. The
1895 name can be changed. The only requirement is the %s be present. */
1896 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1897 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1899 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1900 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1902 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1903 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1905 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1906 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1908 #define STUB_ENTRY_NAME "__%s_veneer"
1910 /* The name of the dynamic interpreter. This is put in the .interp
1912 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1914 #ifdef FOUR_WORD_PLT
1916 /* The first entry in a procedure linkage table looks like
1917 this. It is set up so that any shared library function that is
1918 called before the relocation has been set up calls the dynamic
1920 static const bfd_vma elf32_arm_plt0_entry [] =
1922 0xe52de004, /* str lr, [sp, #-4]! */
1923 0xe59fe010, /* ldr lr, [pc, #16] */
1924 0xe08fe00e, /* add lr, pc, lr */
1925 0xe5bef008, /* ldr pc, [lr, #8]! */
1928 /* Subsequent entries in a procedure linkage table look like
1930 static const bfd_vma elf32_arm_plt_entry [] =
1932 0xe28fc600, /* add ip, pc, #NN */
1933 0xe28cca00, /* add ip, ip, #NN */
1934 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1935 0x00000000, /* unused */
1940 /* The first entry in a procedure linkage table looks like
1941 this. It is set up so that any shared library function that is
1942 called before the relocation has been set up calls the dynamic
1944 static const bfd_vma elf32_arm_plt0_entry [] =
1946 0xe52de004, /* str lr, [sp, #-4]! */
1947 0xe59fe004, /* ldr lr, [pc, #4] */
1948 0xe08fe00e, /* add lr, pc, lr */
1949 0xe5bef008, /* ldr pc, [lr, #8]! */
1950 0x00000000, /* &GOT[0] - . */
1953 /* Subsequent entries in a procedure linkage table look like
1955 static const bfd_vma elf32_arm_plt_entry [] =
1957 0xe28fc600, /* add ip, pc, #0xNN00000 */
1958 0xe28cca00, /* add ip, ip, #0xNN000 */
1959 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1964 /* The format of the first entry in the procedure linkage table
1965 for a VxWorks executable. */
1966 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1968 0xe52dc008, /* str ip,[sp,#-8]! */
1969 0xe59fc000, /* ldr ip,[pc] */
1970 0xe59cf008, /* ldr pc,[ip,#8] */
1971 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1974 /* The format of subsequent entries in a VxWorks executable. */
1975 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1977 0xe59fc000, /* ldr ip,[pc] */
1978 0xe59cf000, /* ldr pc,[ip] */
1979 0x00000000, /* .long @got */
1980 0xe59fc000, /* ldr ip,[pc] */
1981 0xea000000, /* b _PLT */
1982 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1985 /* The format of entries in a VxWorks shared library. */
1986 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1988 0xe59fc000, /* ldr ip,[pc] */
1989 0xe79cf009, /* ldr pc,[ip,r9] */
1990 0x00000000, /* .long @got */
1991 0xe59fc000, /* ldr ip,[pc] */
1992 0xe599f008, /* ldr pc,[r9,#8] */
1993 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1996 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1997 #define PLT_THUMB_STUB_SIZE 4
1998 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2004 /* The entries in a PLT when using a DLL-based target with multiple
2006 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2008 0xe51ff004, /* ldr pc, [pc, #-4] */
2009 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2012 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2013 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2014 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2015 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2016 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2017 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2027 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2028 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2029 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2030 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2031 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2036 enum stub_insn_type type;
2037 unsigned int r_type;
2041 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2042 to reach the stub if necessary. */
2043 static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
2045 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2046 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2049 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2051 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2053 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2054 ARM_INSN(0xe12fff1c), /* bx ip */
2055 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2058 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2059 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
2061 THUMB16_INSN(0xb401), /* push {r0} */
2062 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2063 THUMB16_INSN(0x4684), /* mov ip, r0 */
2064 THUMB16_INSN(0xbc01), /* pop {r0} */
2065 THUMB16_INSN(0x4760), /* bx ip */
2066 THUMB16_INSN(0xbf00), /* nop */
2067 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2070 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2072 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb[] =
2074 THUMB16_INSN(0x4778), /* bx pc */
2075 THUMB16_INSN(0x46c0), /* nop */
2076 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2077 ARM_INSN(0xe12fff1c), /* bx ip */
2078 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2081 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2083 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2085 THUMB16_INSN(0x4778), /* bx pc */
2086 THUMB16_INSN(0x46c0), /* nop */
2087 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2088 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2091 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2092 one, when the destination is close enough. */
2093 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2095 THUMB16_INSN(0x4778), /* bx pc */
2096 THUMB16_INSN(0x46c0), /* nop */
2097 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2100 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2101 blx to reach the stub if necessary. */
2102 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
2104 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2105 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2106 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2109 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2110 blx to reach the stub if necessary. We can not add into pc;
2111 it is not guaranteed to mode switch (different in ARMv6 and
2113 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2115 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2116 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2117 ARM_INSN(0xe12fff1c), /* bx ip */
2118 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2121 /* V4T ARM -> ARM long branch stub, PIC. */
2122 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2124 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2125 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2126 ARM_INSN(0xe12fff1c), /* bx ip */
2127 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2130 /* V4T Thumb -> ARM long branch stub, PIC. */
2131 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2133 THUMB16_INSN(0x4778), /* bx pc */
2134 THUMB16_INSN(0x46c0), /* nop */
2135 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2136 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2137 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2140 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2142 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2144 THUMB16_INSN(0xb401), /* push {r0} */
2145 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2146 THUMB16_INSN(0x46fc), /* mov ip, pc */
2147 THUMB16_INSN(0x4484), /* add ip, r0 */
2148 THUMB16_INSN(0xbc01), /* pop {r0} */
2149 THUMB16_INSN(0x4760), /* bx ip */
2150 DATA_WORD(0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2153 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2155 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] =
2157 THUMB16_INSN(0x4778), /* bx pc */
2158 THUMB16_INSN(0x46c0), /* nop */
2159 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2160 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2161 ARM_INSN(0xe12fff1c), /* bx ip */
2162 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2165 /* Section name for stubs is the associated section name plus this
2167 #define STUB_SUFFIX ".stub"
2169 enum elf32_arm_stub_type
2172 arm_stub_long_branch_any_any,
2173 arm_stub_long_branch_v4t_arm_thumb,
2174 arm_stub_long_branch_thumb_only,
2175 arm_stub_long_branch_v4t_thumb_thumb,
2176 arm_stub_long_branch_v4t_thumb_arm,
2177 arm_stub_short_branch_v4t_thumb_arm,
2178 arm_stub_long_branch_any_arm_pic,
2179 arm_stub_long_branch_any_thumb_pic,
2180 arm_stub_long_branch_v4t_arm_thumb_pic,
2181 arm_stub_long_branch_v4t_thumb_arm_pic,
2182 arm_stub_long_branch_thumb_only_pic,
2183 arm_stub_long_branch_v4t_thumb_thumb_pic,
2186 struct elf32_arm_stub_hash_entry
2188 /* Base hash table entry structure. */
2189 struct bfd_hash_entry root;
2191 /* The stub section. */
2194 /* Offset within stub_sec of the beginning of this stub. */
2195 bfd_vma stub_offset;
2197 /* Given the symbol's value and its section we can determine its final
2198 value when building the stubs (so the stub knows where to jump). */
2199 bfd_vma target_value;
2200 asection *target_section;
2202 /* The stub type. */
2203 enum elf32_arm_stub_type stub_type;
2204 /* Its encoding size in bytes. */
2207 const insn_sequence *stub_template;
2208 /* The size of the template (number of entries). */
2209 int stub_template_size;
2211 /* The symbol table entry, if any, that this was derived from. */
2212 struct elf32_arm_link_hash_entry *h;
2214 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2215 unsigned char st_type;
2217 /* Where this stub is being called from, or, in the case of combined
2218 stub sections, the first input section in the group. */
2221 /* The name for the local symbol at the start of this stub. The
2222 stub name in the hash table has to be unique; this does not, so
2223 it can be friendlier. */
2227 /* Used to build a map of a section. This is required for mixed-endian
2230 typedef struct elf32_elf_section_map
2235 elf32_arm_section_map;
2237 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2241 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2242 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2243 VFP11_ERRATUM_ARM_VENEER,
2244 VFP11_ERRATUM_THUMB_VENEER
2246 elf32_vfp11_erratum_type;
2248 typedef struct elf32_vfp11_erratum_list
2250 struct elf32_vfp11_erratum_list *next;
2256 struct elf32_vfp11_erratum_list *veneer;
2257 unsigned int vfp_insn;
2261 struct elf32_vfp11_erratum_list *branch;
2265 elf32_vfp11_erratum_type type;
2267 elf32_vfp11_erratum_list;
2269 typedef struct _arm_elf_section_data
2271 struct bfd_elf_section_data elf;
2272 unsigned int mapcount;
2273 unsigned int mapsize;
2274 elf32_arm_section_map *map;
2275 unsigned int erratumcount;
2276 elf32_vfp11_erratum_list *erratumlist;
2278 _arm_elf_section_data;
2280 #define elf32_arm_section_data(sec) \
2281 ((_arm_elf_section_data *) elf_section_data (sec))
2283 /* The size of the thread control block. */
2286 struct elf_arm_obj_tdata
2288 struct elf_obj_tdata root;
2290 /* tls_type for each local got entry. */
2291 char *local_got_tls_type;
2293 /* Zero to warn when linking objects with incompatible enum sizes. */
2294 int no_enum_size_warning;
2296 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2297 int no_wchar_size_warning;
2300 #define elf_arm_tdata(bfd) \
2301 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2303 #define elf32_arm_local_got_tls_type(bfd) \
2304 (elf_arm_tdata (bfd)->local_got_tls_type)
2306 #define is_arm_elf(bfd) \
2307 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2308 && elf_tdata (bfd) != NULL \
2309 && elf_object_id (bfd) == ARM_ELF_TDATA)
2312 elf32_arm_mkobject (bfd *abfd)
2314 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2318 /* The ARM linker needs to keep track of the number of relocs that it
2319 decides to copy in check_relocs for each symbol. This is so that
2320 it can discard PC relative relocs if it doesn't need them when
2321 linking with -Bsymbolic. We store the information in a field
2322 extending the regular ELF linker hash table. */
2324 /* This structure keeps track of the number of relocs we have copied
2325 for a given symbol. */
2326 struct elf32_arm_relocs_copied
2329 struct elf32_arm_relocs_copied * next;
2330 /* A section in dynobj. */
2332 /* Number of relocs copied in this section. */
2333 bfd_size_type count;
2334 /* Number of PC-relative relocs copied in this section. */
2335 bfd_size_type pc_count;
2338 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2340 /* Arm ELF linker hash entry. */
2341 struct elf32_arm_link_hash_entry
2343 struct elf_link_hash_entry root;
2345 /* Number of PC relative relocs copied for this symbol. */
2346 struct elf32_arm_relocs_copied * relocs_copied;
2348 /* We reference count Thumb references to a PLT entry separately,
2349 so that we can emit the Thumb trampoline only if needed. */
2350 bfd_signed_vma plt_thumb_refcount;
2352 /* Some references from Thumb code may be eliminated by BL->BLX
2353 conversion, so record them separately. */
2354 bfd_signed_vma plt_maybe_thumb_refcount;
2356 /* Since PLT entries have variable size if the Thumb prologue is
2357 used, we need to record the index into .got.plt instead of
2358 recomputing it from the PLT offset. */
2359 bfd_signed_vma plt_got_offset;
2361 #define GOT_UNKNOWN 0
2362 #define GOT_NORMAL 1
2363 #define GOT_TLS_GD 2
2364 #define GOT_TLS_IE 4
2365 unsigned char tls_type;
2367 /* The symbol marking the real symbol location for exported thumb
2368 symbols with Arm stubs. */
2369 struct elf_link_hash_entry *export_glue;
2371 /* A pointer to the most recently used stub hash entry against this
2373 struct elf32_arm_stub_hash_entry *stub_cache;
2376 /* Traverse an arm ELF linker hash table. */
2377 #define elf32_arm_link_hash_traverse(table, func, info) \
2378 (elf_link_hash_traverse \
2380 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2383 /* Get the ARM elf linker hash table from a link_info structure. */
2384 #define elf32_arm_hash_table(info) \
2385 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2387 #define arm_stub_hash_lookup(table, string, create, copy) \
2388 ((struct elf32_arm_stub_hash_entry *) \
2389 bfd_hash_lookup ((table), (string), (create), (copy)))
2391 /* ARM ELF linker hash table. */
2392 struct elf32_arm_link_hash_table
2394 /* The main hash table. */
2395 struct elf_link_hash_table root;
2397 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2398 bfd_size_type thumb_glue_size;
2400 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2401 bfd_size_type arm_glue_size;
2403 /* The size in bytes of section containing the ARMv4 BX veneers. */
2404 bfd_size_type bx_glue_size;
2406 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2407 veneer has been populated. */
2408 bfd_vma bx_glue_offset[15];
2410 /* The size in bytes of the section containing glue for VFP11 erratum
2412 bfd_size_type vfp11_erratum_glue_size;
2414 /* An arbitrary input BFD chosen to hold the glue sections. */
2415 bfd * bfd_of_glue_owner;
2417 /* Nonzero to output a BE8 image. */
2420 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2421 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2424 /* The relocation to use for R_ARM_TARGET2 relocations. */
2427 /* 0 = Ignore R_ARM_V4BX.
2428 1 = Convert BX to MOV PC.
2429 2 = Generate v4 interworing stubs. */
2432 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2435 /* What sort of code sequences we should look for which may trigger the
2436 VFP11 denorm erratum. */
2437 bfd_arm_vfp11_fix vfp11_fix;
2439 /* Global counter for the number of fixes we have emitted. */
2440 int num_vfp11_fixes;
2442 /* Nonzero to force PIC branch veneers. */
2445 /* The number of bytes in the initial entry in the PLT. */
2446 bfd_size_type plt_header_size;
2448 /* The number of bytes in the subsequent PLT etries. */
2449 bfd_size_type plt_entry_size;
2451 /* True if the target system is VxWorks. */
2454 /* True if the target system is Symbian OS. */
2457 /* True if the target uses REL relocations. */
2460 /* Short-cuts to get to dynamic linker sections. */
2469 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2472 /* Data for R_ARM_TLS_LDM32 relocations. */
2475 bfd_signed_vma refcount;
2479 /* Small local sym to section mapping cache. */
2480 struct sym_sec_cache sym_sec;
2482 /* For convenience in allocate_dynrelocs. */
2485 /* The stub hash table. */
2486 struct bfd_hash_table stub_hash_table;
2488 /* Linker stub bfd. */
2491 /* Linker call-backs. */
2492 asection * (*add_stub_section) (const char *, asection *);
2493 void (*layout_sections_again) (void);
2495 /* Array to keep track of which stub sections have been created, and
2496 information on stub grouping. */
2499 /* This is the section to which stubs in the group will be
2502 /* The stub section. */
2506 /* Assorted information used by elf32_arm_size_stubs. */
2507 unsigned int bfd_count;
2509 asection **input_list;
2512 /* Create an entry in an ARM ELF linker hash table. */
2514 static struct bfd_hash_entry *
2515 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2516 struct bfd_hash_table * table,
2517 const char * string)
2519 struct elf32_arm_link_hash_entry * ret =
2520 (struct elf32_arm_link_hash_entry *) entry;
2522 /* Allocate the structure if it has not already been allocated by a
2525 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2527 return (struct bfd_hash_entry *) ret;
2529 /* Call the allocation method of the superclass. */
2530 ret = ((struct elf32_arm_link_hash_entry *)
2531 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2535 ret->relocs_copied = NULL;
2536 ret->tls_type = GOT_UNKNOWN;
2537 ret->plt_thumb_refcount = 0;
2538 ret->plt_maybe_thumb_refcount = 0;
2539 ret->plt_got_offset = -1;
2540 ret->export_glue = NULL;
2542 ret->stub_cache = NULL;
2545 return (struct bfd_hash_entry *) ret;
2548 /* Initialize an entry in the stub hash table. */
2550 static struct bfd_hash_entry *
2551 stub_hash_newfunc (struct bfd_hash_entry *entry,
2552 struct bfd_hash_table *table,
2555 /* Allocate the structure if it has not already been allocated by a
2559 entry = bfd_hash_allocate (table,
2560 sizeof (struct elf32_arm_stub_hash_entry));
2565 /* Call the allocation method of the superclass. */
2566 entry = bfd_hash_newfunc (entry, table, string);
2569 struct elf32_arm_stub_hash_entry *eh;
2571 /* Initialize the local fields. */
2572 eh = (struct elf32_arm_stub_hash_entry *) entry;
2573 eh->stub_sec = NULL;
2574 eh->stub_offset = 0;
2575 eh->target_value = 0;
2576 eh->target_section = NULL;
2577 eh->stub_type = arm_stub_none;
2579 eh->stub_template = NULL;
2580 eh->stub_template_size = 0;
2588 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2589 shortcuts to them in our hash table. */
2592 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2594 struct elf32_arm_link_hash_table *htab;
2596 htab = elf32_arm_hash_table (info);
2597 /* BPABI objects never have a GOT, or associated sections. */
2598 if (htab->symbian_p)
2601 if (! _bfd_elf_create_got_section (dynobj, info))
2604 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2605 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2606 if (!htab->sgot || !htab->sgotplt)
2609 htab->srelgot = bfd_make_section_with_flags (dynobj,
2610 RELOC_SECTION (htab, ".got"),
2611 (SEC_ALLOC | SEC_LOAD
2614 | SEC_LINKER_CREATED
2616 if (htab->srelgot == NULL
2617 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2622 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2623 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2627 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2629 struct elf32_arm_link_hash_table *htab;
2631 htab = elf32_arm_hash_table (info);
2632 if (!htab->sgot && !create_got_section (dynobj, info))
2635 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2638 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2639 htab->srelplt = bfd_get_section_by_name (dynobj,
2640 RELOC_SECTION (htab, ".plt"));
2641 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2643 htab->srelbss = bfd_get_section_by_name (dynobj,
2644 RELOC_SECTION (htab, ".bss"));
2646 if (htab->vxworks_p)
2648 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2653 htab->plt_header_size = 0;
2654 htab->plt_entry_size
2655 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2659 htab->plt_header_size
2660 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2661 htab->plt_entry_size
2662 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2669 || (!info->shared && !htab->srelbss))
2675 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2678 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2679 struct elf_link_hash_entry *dir,
2680 struct elf_link_hash_entry *ind)
2682 struct elf32_arm_link_hash_entry *edir, *eind;
2684 edir = (struct elf32_arm_link_hash_entry *) dir;
2685 eind = (struct elf32_arm_link_hash_entry *) ind;
2687 if (eind->relocs_copied != NULL)
2689 if (edir->relocs_copied != NULL)
2691 struct elf32_arm_relocs_copied **pp;
2692 struct elf32_arm_relocs_copied *p;
2694 /* Add reloc counts against the indirect sym to the direct sym
2695 list. Merge any entries against the same section. */
2696 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2698 struct elf32_arm_relocs_copied *q;
2700 for (q = edir->relocs_copied; q != NULL; q = q->next)
2701 if (q->section == p->section)
2703 q->pc_count += p->pc_count;
2704 q->count += p->count;
2711 *pp = edir->relocs_copied;
2714 edir->relocs_copied = eind->relocs_copied;
2715 eind->relocs_copied = NULL;
2718 if (ind->root.type == bfd_link_hash_indirect)
2720 /* Copy over PLT info. */
2721 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2722 eind->plt_thumb_refcount = 0;
2723 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2724 eind->plt_maybe_thumb_refcount = 0;
2726 if (dir->got.refcount <= 0)
2728 edir->tls_type = eind->tls_type;
2729 eind->tls_type = GOT_UNKNOWN;
2733 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2736 /* Create an ARM elf linker hash table. */
2738 static struct bfd_link_hash_table *
2739 elf32_arm_link_hash_table_create (bfd *abfd)
2741 struct elf32_arm_link_hash_table *ret;
2742 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2744 ret = bfd_malloc (amt);
2748 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2749 elf32_arm_link_hash_newfunc,
2750 sizeof (struct elf32_arm_link_hash_entry)))
2757 ret->sgotplt = NULL;
2758 ret->srelgot = NULL;
2760 ret->srelplt = NULL;
2761 ret->sdynbss = NULL;
2762 ret->srelbss = NULL;
2763 ret->srelplt2 = NULL;
2764 ret->thumb_glue_size = 0;
2765 ret->arm_glue_size = 0;
2766 ret->bx_glue_size = 0;
2767 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2768 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2769 ret->vfp11_erratum_glue_size = 0;
2770 ret->num_vfp11_fixes = 0;
2771 ret->bfd_of_glue_owner = NULL;
2772 ret->byteswap_code = 0;
2773 ret->target1_is_rel = 0;
2774 ret->target2_reloc = R_ARM_NONE;
2775 #ifdef FOUR_WORD_PLT
2776 ret->plt_header_size = 16;
2777 ret->plt_entry_size = 16;
2779 ret->plt_header_size = 20;
2780 ret->plt_entry_size = 12;
2787 ret->sym_sec.abfd = NULL;
2789 ret->tls_ldm_got.refcount = 0;
2790 ret->stub_bfd = NULL;
2791 ret->add_stub_section = NULL;
2792 ret->layout_sections_again = NULL;
2793 ret->stub_group = NULL;
2796 ret->input_list = NULL;
2798 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2799 sizeof (struct elf32_arm_stub_hash_entry)))
2805 return &ret->root.root;
2808 /* Free the derived linker hash table. */
2811 elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2813 struct elf32_arm_link_hash_table *ret
2814 = (struct elf32_arm_link_hash_table *) hash;
2816 bfd_hash_table_free (&ret->stub_hash_table);
2817 _bfd_generic_link_hash_table_free (hash);
2820 /* Determine if we're dealing with a Thumb only architecture. */
2823 using_thumb_only (struct elf32_arm_link_hash_table *globals)
2825 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2829 if (arch != TAG_CPU_ARCH_V7)
2832 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2833 Tag_CPU_arch_profile);
2835 return profile == 'M';
2838 /* Determine if we're dealing with a Thumb-2 object. */
2841 using_thumb2 (struct elf32_arm_link_hash_table *globals)
2843 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2845 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2849 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2853 case arm_stub_long_branch_thumb_only:
2854 case arm_stub_long_branch_v4t_thumb_arm:
2855 case arm_stub_short_branch_v4t_thumb_arm:
2856 case arm_stub_long_branch_v4t_thumb_arm_pic:
2857 case arm_stub_long_branch_thumb_only_pic:
2868 /* Determine the type of stub needed, if any, for a call. */
2870 static enum elf32_arm_stub_type
2871 arm_type_of_stub (struct bfd_link_info *info,
2872 asection *input_sec,
2873 const Elf_Internal_Rela *rel,
2874 unsigned char st_type,
2875 struct elf32_arm_link_hash_entry *hash,
2876 bfd_vma destination,
2882 bfd_signed_vma branch_offset;
2883 unsigned int r_type;
2884 struct elf32_arm_link_hash_table * globals;
2887 enum elf32_arm_stub_type stub_type = arm_stub_none;
2890 /* We don't know the actual type of destination in case it is of
2891 type STT_SECTION: give up. */
2892 if (st_type == STT_SECTION)
2895 globals = elf32_arm_hash_table (info);
2897 thumb_only = using_thumb_only (globals);
2899 thumb2 = using_thumb2 (globals);
2901 /* Determine where the call point is. */
2902 location = (input_sec->output_offset
2903 + input_sec->output_section->vma
2906 branch_offset = (bfd_signed_vma)(destination - location);
2908 r_type = ELF32_R_TYPE (rel->r_info);
2910 /* Keep a simpler condition, for the sake of clarity. */
2911 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
2914 /* Note when dealing with PLT entries: the main PLT stub is in
2915 ARM mode, so if the branch is in Thumb mode, another
2916 Thumb->ARM stub will be inserted later just before the ARM
2917 PLT stub. We don't take this extra distance into account
2918 here, because if a long branch stub is needed, we'll add a
2919 Thumb->Arm one and branch directly to the ARM PLT entry
2920 because it avoids spreading offset corrections in several
2924 if (r_type == R_ARM_THM_CALL)
2926 /* Handle cases where:
2927 - this call goes too far (different Thumb/Thumb2 max
2929 - it's a Thumb->Arm call and blx is not available. A stub is
2930 needed in this case, but only if this call is not through a
2931 PLT entry. Indeed, PLT stubs handle mode switching already.
2934 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2935 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2937 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2938 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2939 || ((st_type != STT_ARM_TFUNC)
2940 && ((r_type == R_ARM_THM_CALL) && !globals->use_blx)
2943 if (st_type == STT_ARM_TFUNC)
2945 /* Thumb to thumb. */
2948 stub_type = (info->shared | globals->pic_veneer)
2950 ? ((globals->use_blx)
2951 /* V5T and above. */
2952 ? arm_stub_long_branch_any_thumb_pic
2953 /* On V4T, use Thumb code only. */
2954 : arm_stub_long_branch_v4t_thumb_thumb_pic)
2956 /* non-PIC stubs. */
2957 : ((globals->use_blx)
2958 /* V5T and above. */
2959 ? arm_stub_long_branch_any_any
2961 : arm_stub_long_branch_v4t_thumb_thumb);
2965 stub_type = (info->shared | globals->pic_veneer)
2967 ? arm_stub_long_branch_thumb_only_pic
2969 : arm_stub_long_branch_thumb_only;
2976 && sym_sec->owner != NULL
2977 && !INTERWORK_FLAG (sym_sec->owner))
2979 (*_bfd_error_handler)
2980 (_("%B(%s): warning: interworking not enabled.\n"
2981 " first occurrence: %B: Thumb call to ARM"),
2982 sym_sec->owner, input_bfd, name);
2985 stub_type = (info->shared | globals->pic_veneer)
2987 ? ((globals->use_blx)
2988 /* V5T and above. */
2989 ? arm_stub_long_branch_any_arm_pic
2991 : arm_stub_long_branch_v4t_thumb_arm_pic)
2993 /* non-PIC stubs. */
2994 : ((globals->use_blx)
2995 /* V5T and above. */
2996 ? arm_stub_long_branch_any_any
2998 : arm_stub_long_branch_v4t_thumb_arm);
3000 /* Handle v4t short branches. */
3001 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
3002 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
3003 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
3004 stub_type = arm_stub_short_branch_v4t_thumb_arm;
3008 else if (r_type == R_ARM_CALL)
3010 if (st_type == STT_ARM_TFUNC)
3015 && sym_sec->owner != NULL
3016 && !INTERWORK_FLAG (sym_sec->owner))
3018 (*_bfd_error_handler)
3019 (_("%B(%s): warning: interworking not enabled.\n"
3020 " first occurrence: %B: ARM call to Thumb"),
3021 sym_sec->owner, input_bfd, name);
3024 /* We have an extra 2-bytes reach because of
3025 the mode change (bit 24 (H) of BLX encoding). */
3026 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
3027 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
3028 || !globals->use_blx)
3030 stub_type = (info->shared | globals->pic_veneer)
3032 ? ((globals->use_blx)
3033 /* V5T and above. */
3034 ? arm_stub_long_branch_any_thumb_pic
3036 : arm_stub_long_branch_v4t_arm_thumb_pic)
3038 /* non-PIC stubs. */
3039 : ((globals->use_blx)
3040 /* V5T and above. */
3041 ? arm_stub_long_branch_any_any
3043 : arm_stub_long_branch_v4t_arm_thumb);
3049 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3050 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3052 stub_type = (info->shared | globals->pic_veneer)
3054 ? arm_stub_long_branch_any_arm_pic
3055 /* non-PIC stubs. */
3056 : arm_stub_long_branch_any_any;
3064 /* Build a name for an entry in the stub hash table. */
3067 elf32_arm_stub_name (const asection *input_section,
3068 const asection *sym_sec,
3069 const struct elf32_arm_link_hash_entry *hash,
3070 const Elf_Internal_Rela *rel)
3077 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
3078 stub_name = bfd_malloc (len);
3079 if (stub_name != NULL)
3080 sprintf (stub_name, "%08x_%s+%x",
3081 input_section->id & 0xffffffff,
3082 hash->root.root.root.string,
3083 (int) rel->r_addend & 0xffffffff);
3087 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3088 stub_name = bfd_malloc (len);
3089 if (stub_name != NULL)
3090 sprintf (stub_name, "%08x_%x:%x+%x",
3091 input_section->id & 0xffffffff,
3092 sym_sec->id & 0xffffffff,
3093 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3094 (int) rel->r_addend & 0xffffffff);
3100 /* Look up an entry in the stub hash. Stub entries are cached because
3101 creating the stub name takes a bit of time. */
3103 static struct elf32_arm_stub_hash_entry *
3104 elf32_arm_get_stub_entry (const asection *input_section,
3105 const asection *sym_sec,
3106 struct elf_link_hash_entry *hash,
3107 const Elf_Internal_Rela *rel,
3108 struct elf32_arm_link_hash_table *htab)
3110 struct elf32_arm_stub_hash_entry *stub_entry;
3111 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3112 const asection *id_sec;
3114 if ((input_section->flags & SEC_CODE) == 0)
3117 /* If this input section is part of a group of sections sharing one
3118 stub section, then use the id of the first section in the group.
3119 Stub names need to include a section id, as there may well be
3120 more than one stub used to reach say, printf, and we need to
3121 distinguish between them. */
3122 id_sec = htab->stub_group[input_section->id].link_sec;
3124 if (h != NULL && h->stub_cache != NULL
3125 && h->stub_cache->h == h
3126 && h->stub_cache->id_sec == id_sec)
3128 stub_entry = h->stub_cache;
3134 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
3135 if (stub_name == NULL)
3138 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3139 stub_name, FALSE, FALSE);
3141 h->stub_cache = stub_entry;
3149 /* Add a new stub entry to the stub hash. Not all fields of the new
3150 stub entry are initialised. */
3152 static struct elf32_arm_stub_hash_entry *
3153 elf32_arm_add_stub (const char *stub_name,
3155 struct elf32_arm_link_hash_table *htab)
3159 struct elf32_arm_stub_hash_entry *stub_entry;
3161 link_sec = htab->stub_group[section->id].link_sec;
3162 stub_sec = htab->stub_group[section->id].stub_sec;
3163 if (stub_sec == NULL)
3165 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3166 if (stub_sec == NULL)
3172 namelen = strlen (link_sec->name);
3173 len = namelen + sizeof (STUB_SUFFIX);
3174 s_name = bfd_alloc (htab->stub_bfd, len);
3178 memcpy (s_name, link_sec->name, namelen);
3179 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3180 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3181 if (stub_sec == NULL)
3183 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3185 htab->stub_group[section->id].stub_sec = stub_sec;
3188 /* Enter this entry into the linker stub hash table. */
3189 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3191 if (stub_entry == NULL)
3193 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3199 stub_entry->stub_sec = stub_sec;
3200 stub_entry->stub_offset = 0;
3201 stub_entry->id_sec = link_sec;
3206 /* Store an Arm insn into an output section not processed by
3207 elf32_arm_write_section. */
3210 put_arm_insn (struct elf32_arm_link_hash_table * htab,
3211 bfd * output_bfd, bfd_vma val, void * ptr)
3213 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3214 bfd_putl32 (val, ptr);
3216 bfd_putb32 (val, ptr);
3219 /* Store a 16-bit Thumb insn into an output section not processed by
3220 elf32_arm_write_section. */
3223 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3224 bfd * output_bfd, bfd_vma val, void * ptr)
3226 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3227 bfd_putl16 (val, ptr);
3229 bfd_putb16 (val, ptr);
3233 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3236 struct elf32_arm_stub_hash_entry *stub_entry;
3237 struct bfd_link_info *info;
3238 struct elf32_arm_link_hash_table *htab;
3246 const insn_sequence *template;
3248 struct elf32_arm_link_hash_table * globals;
3249 int stub_reloc_idx = -1;
3250 int stub_reloc_offset = 0;
3252 /* Massage our args to the form they really have. */
3253 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3254 info = (struct bfd_link_info *) in_arg;
3256 globals = elf32_arm_hash_table (info);
3258 htab = elf32_arm_hash_table (info);
3259 stub_sec = stub_entry->stub_sec;
3261 /* Make a note of the offset within the stubs for this entry. */
3262 stub_entry->stub_offset = stub_sec->size;
3263 loc = stub_sec->contents + stub_entry->stub_offset;
3265 stub_bfd = stub_sec->owner;
3267 /* This is the address of the start of the stub. */
3268 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3269 + stub_entry->stub_offset;
3271 /* This is the address of the stub destination. */
3272 sym_value = (stub_entry->target_value
3273 + stub_entry->target_section->output_offset
3274 + stub_entry->target_section->output_section->vma);
3276 template = stub_entry->stub_template;
3277 template_size = stub_entry->stub_template_size;
3280 for (i = 0; i < template_size; i++)
3282 switch (template[i].type)
3285 put_thumb_insn (globals, stub_bfd, template[i].data, loc + size);
3290 put_arm_insn (globals, stub_bfd, template[i].data, loc + size);
3291 /* Handle cases where the target is encoded within the
3293 if (template[i].r_type == R_ARM_JUMP24)
3296 stub_reloc_offset = size;
3302 bfd_put_32 (stub_bfd, template[i].data, loc + size);
3304 stub_reloc_offset = size;
3314 stub_sec->size += size;
3316 /* Stub size has already been computed in arm_size_one_stub. Check
3318 BFD_ASSERT (size == stub_entry->stub_size);
3320 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3321 if (stub_entry->st_type == STT_ARM_TFUNC)
3324 /* Assume there is one and only one entry to relocate in each stub. */
3325 BFD_ASSERT (stub_reloc_idx != -1);
3327 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx].r_type),
3328 stub_bfd, stub_sec, stub_sec->contents,
3329 stub_entry->stub_offset + stub_reloc_offset,
3330 sym_value, template[stub_reloc_idx].reloc_addend);
3335 /* As above, but don't actually build the stub. Just bump offset so
3336 we know stub section sizes. */
3339 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3342 struct elf32_arm_stub_hash_entry *stub_entry;
3343 struct elf32_arm_link_hash_table *htab;
3344 const insn_sequence *template;
3349 /* Massage our args to the form they really have. */
3350 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3351 htab = (struct elf32_arm_link_hash_table *) in_arg;
3353 switch (stub_entry->stub_type)
3355 case arm_stub_long_branch_any_any:
3356 template = elf32_arm_stub_long_branch_any_any;
3357 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
3359 case arm_stub_long_branch_v4t_arm_thumb:
3360 template = elf32_arm_stub_long_branch_v4t_arm_thumb;
3361 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
3363 case arm_stub_long_branch_thumb_only:
3364 template = elf32_arm_stub_long_branch_thumb_only;
3365 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
3367 case arm_stub_long_branch_v4t_thumb_thumb:
3368 template = elf32_arm_stub_long_branch_v4t_thumb_thumb;
3369 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb);
3371 case arm_stub_long_branch_v4t_thumb_arm:
3372 template = elf32_arm_stub_long_branch_v4t_thumb_arm;
3373 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
3375 case arm_stub_short_branch_v4t_thumb_arm:
3376 template = elf32_arm_stub_short_branch_v4t_thumb_arm;
3377 template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
3379 case arm_stub_long_branch_any_arm_pic:
3380 template = elf32_arm_stub_long_branch_any_arm_pic;
3381 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
3383 case arm_stub_long_branch_any_thumb_pic:
3384 template = elf32_arm_stub_long_branch_any_thumb_pic;
3385 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
3387 case arm_stub_long_branch_v4t_arm_thumb_pic:
3388 template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
3389 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
3391 case arm_stub_long_branch_v4t_thumb_arm_pic:
3392 template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
3393 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
3395 case arm_stub_long_branch_thumb_only_pic:
3396 template = elf32_arm_stub_long_branch_thumb_only_pic;
3397 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
3399 case arm_stub_long_branch_v4t_thumb_thumb_pic:
3400 template = elf32_arm_stub_long_branch_v4t_thumb_thumb_pic;
3401 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb_pic);
3409 for (i = 0; i < template_size; i++)
3411 switch (template[i].type)
3431 stub_entry->stub_size = size;
3432 stub_entry->stub_template = template;
3433 stub_entry->stub_template_size = template_size;
3435 size = (size + 7) & ~7;
3436 stub_entry->stub_sec->size += size;
3441 /* External entry points for sizing and building linker stubs. */
3443 /* Set up various things so that we can make a list of input sections
3444 for each output section included in the link. Returns -1 on error,
3445 0 when no stubs will be needed, and 1 on success. */
3448 elf32_arm_setup_section_lists (bfd *output_bfd,
3449 struct bfd_link_info *info)
3452 unsigned int bfd_count;
3453 int top_id, top_index;
3455 asection **input_list, **list;
3457 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3459 if (! is_elf_hash_table (htab))
3462 /* Count the number of input BFDs and find the top input section id. */
3463 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3465 input_bfd = input_bfd->link_next)
3468 for (section = input_bfd->sections;
3470 section = section->next)
3472 if (top_id < section->id)
3473 top_id = section->id;
3476 htab->bfd_count = bfd_count;
3478 amt = sizeof (struct map_stub) * (top_id + 1);
3479 htab->stub_group = bfd_zmalloc (amt);
3480 if (htab->stub_group == NULL)
3483 /* We can't use output_bfd->section_count here to find the top output
3484 section index as some sections may have been removed, and
3485 _bfd_strip_section_from_output doesn't renumber the indices. */
3486 for (section = output_bfd->sections, top_index = 0;
3488 section = section->next)
3490 if (top_index < section->index)
3491 top_index = section->index;
3494 htab->top_index = top_index;
3495 amt = sizeof (asection *) * (top_index + 1);
3496 input_list = bfd_malloc (amt);
3497 htab->input_list = input_list;
3498 if (input_list == NULL)
3501 /* For sections we aren't interested in, mark their entries with a
3502 value we can check later. */
3503 list = input_list + top_index;
3505 *list = bfd_abs_section_ptr;
3506 while (list-- != input_list);
3508 for (section = output_bfd->sections;
3510 section = section->next)
3512 if ((section->flags & SEC_CODE) != 0)
3513 input_list[section->index] = NULL;
3519 /* The linker repeatedly calls this function for each input section,
3520 in the order that input sections are linked into output sections.
3521 Build lists of input sections to determine groupings between which
3522 we may insert linker stubs. */
3525 elf32_arm_next_input_section (struct bfd_link_info *info,
3528 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3530 if (isec->output_section->index <= htab->top_index)
3532 asection **list = htab->input_list + isec->output_section->index;
3534 if (*list != bfd_abs_section_ptr)
3536 /* Steal the link_sec pointer for our list. */
3537 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3538 /* This happens to make the list in reverse order,
3539 which we reverse later. */
3540 PREV_SEC (isec) = *list;
3546 /* See whether we can group stub sections together. Grouping stub
3547 sections may result in fewer stubs. More importantly, we need to
3548 put all .init* and .fini* stubs at the end of the .init or
3549 .fini output sections respectively, because glibc splits the
3550 _init and _fini functions into multiple parts. Putting a stub in
3551 the middle of a function is not a good idea. */
3554 group_sections (struct elf32_arm_link_hash_table *htab,
3555 bfd_size_type stub_group_size,
3556 bfd_boolean stubs_always_after_branch)
3558 asection **list = htab->input_list;
3562 asection *tail = *list;
3565 if (tail == bfd_abs_section_ptr)
3568 /* Reverse the list: we must avoid placing stubs at the
3569 beginning of the section because the beginning of the text
3570 section may be required for an interrupt vector in bare metal
3572 #define NEXT_SEC PREV_SEC
3574 while (tail != NULL)
3576 /* Pop from tail. */
3577 asection *item = tail;
3578 tail = PREV_SEC (item);
3581 NEXT_SEC (item) = head;
3585 while (head != NULL)
3589 bfd_vma stub_group_start = head->output_offset;
3590 bfd_vma end_of_next;
3593 while (NEXT_SEC (curr) != NULL)
3595 next = NEXT_SEC (curr);
3596 end_of_next = next->output_offset + next->size;
3597 if (end_of_next - stub_group_start >= stub_group_size)
3598 /* End of NEXT is too far from start, so stop. */
3600 /* Add NEXT to the group. */
3604 /* OK, the size from the start to the start of CURR is less
3605 than stub_group_size and thus can be handled by one stub
3606 section. (Or the head section is itself larger than
3607 stub_group_size, in which case we may be toast.)
3608 We should really be keeping track of the total size of
3609 stubs added here, as stubs contribute to the final output
3613 next = NEXT_SEC (head);
3614 /* Set up this stub group. */
3615 htab->stub_group[head->id].link_sec = curr;
3617 while (head != curr && (head = next) != NULL);
3619 /* But wait, there's more! Input sections up to stub_group_size
3620 bytes after the stub section can be handled by it too. */
3621 if (!stubs_always_after_branch)
3623 stub_group_start = curr->output_offset + curr->size;
3625 while (next != NULL)
3627 end_of_next = next->output_offset + next->size;
3628 if (end_of_next - stub_group_start >= stub_group_size)
3629 /* End of NEXT is too far from stubs, so stop. */
3631 /* Add NEXT to the stub group. */
3633 next = NEXT_SEC (head);
3634 htab->stub_group[head->id].link_sec = curr;
3640 while (list++ != htab->input_list + htab->top_index);
3642 free (htab->input_list);
3647 /* Determine and set the size of the stub section for a final link.
3649 The basic idea here is to examine all the relocations looking for
3650 PC-relative calls to a target that is unreachable with a "bl"
3654 elf32_arm_size_stubs (bfd *output_bfd,
3656 struct bfd_link_info *info,
3657 bfd_signed_vma group_size,
3658 asection * (*add_stub_section) (const char *, asection *),
3659 void (*layout_sections_again) (void))
3661 bfd_size_type stub_group_size;
3662 bfd_boolean stubs_always_after_branch;
3663 bfd_boolean stub_changed = 0;
3664 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3666 /* Propagate mach to stub bfd, because it may not have been
3667 finalized when we created stub_bfd. */
3668 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3669 bfd_get_mach (output_bfd));
3671 /* Stash our params away. */
3672 htab->stub_bfd = stub_bfd;
3673 htab->add_stub_section = add_stub_section;
3674 htab->layout_sections_again = layout_sections_again;
3675 stubs_always_after_branch = group_size < 0;
3677 stub_group_size = -group_size;
3679 stub_group_size = group_size;
3681 if (stub_group_size == 1)
3683 /* Default values. */
3684 /* Thumb branch range is +-4MB has to be used as the default
3685 maximum size (a given section can contain both ARM and Thumb
3686 code, so the worst case has to be taken into account).
3688 This value is 24K less than that, which allows for 2025
3689 12-byte stubs. If we exceed that, then we will fail to link.
3690 The user will have to relink with an explicit group size
3692 stub_group_size = 4170000;
3695 group_sections (htab, stub_group_size, stubs_always_after_branch);
3700 unsigned int bfd_indx;
3703 for (input_bfd = info->input_bfds, bfd_indx = 0;
3705 input_bfd = input_bfd->link_next, bfd_indx++)
3707 Elf_Internal_Shdr *symtab_hdr;
3709 Elf_Internal_Sym *local_syms = NULL;
3711 /* We'll need the symbol table in a second. */
3712 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3713 if (symtab_hdr->sh_info == 0)
3716 /* Walk over each section attached to the input bfd. */
3717 for (section = input_bfd->sections;
3719 section = section->next)
3721 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3723 /* If there aren't any relocs, then there's nothing more
3725 if ((section->flags & SEC_RELOC) == 0
3726 || section->reloc_count == 0
3727 || (section->flags & SEC_CODE) == 0)
3730 /* If this section is a link-once section that will be
3731 discarded, then don't create any stubs. */
3732 if (section->output_section == NULL
3733 || section->output_section->owner != output_bfd)
3736 /* Get the relocs. */
3738 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3739 NULL, info->keep_memory);
3740 if (internal_relocs == NULL)
3741 goto error_ret_free_local;
3743 /* Now examine each relocation. */
3744 irela = internal_relocs;
3745 irelaend = irela + section->reloc_count;
3746 for (; irela < irelaend; irela++)
3748 unsigned int r_type, r_indx;
3749 enum elf32_arm_stub_type stub_type;
3750 struct elf32_arm_stub_hash_entry *stub_entry;
3753 bfd_vma destination;
3754 struct elf32_arm_link_hash_entry *hash;
3755 const char *sym_name;
3757 const asection *id_sec;
3758 unsigned char st_type;
3760 r_type = ELF32_R_TYPE (irela->r_info);
3761 r_indx = ELF32_R_SYM (irela->r_info);
3763 if (r_type >= (unsigned int) R_ARM_max)
3765 bfd_set_error (bfd_error_bad_value);
3766 error_ret_free_internal:
3767 if (elf_section_data (section)->relocs == NULL)
3768 free (internal_relocs);
3769 goto error_ret_free_local;
3772 /* Only look for stubs on call instructions. */
3773 if ((r_type != (unsigned int) R_ARM_CALL)
3774 && (r_type != (unsigned int) R_ARM_THM_CALL))
3777 /* Now determine the call target, its name, value,
3784 if (r_indx < symtab_hdr->sh_info)
3786 /* It's a local symbol. */
3787 Elf_Internal_Sym *sym;
3788 Elf_Internal_Shdr *hdr;
3790 if (local_syms == NULL)
3793 = (Elf_Internal_Sym *) symtab_hdr->contents;
3794 if (local_syms == NULL)
3796 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3797 symtab_hdr->sh_info, 0,
3799 if (local_syms == NULL)
3800 goto error_ret_free_internal;
3803 sym = local_syms + r_indx;
3804 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3805 sym_sec = hdr->bfd_section;
3806 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3807 sym_value = sym->st_value;
3808 destination = (sym_value + irela->r_addend
3809 + sym_sec->output_offset
3810 + sym_sec->output_section->vma);
3811 st_type = ELF_ST_TYPE (sym->st_info);
3813 = bfd_elf_string_from_elf_section (input_bfd,
3814 symtab_hdr->sh_link,
3819 /* It's an external symbol. */
3822 e_indx = r_indx - symtab_hdr->sh_info;
3823 hash = ((struct elf32_arm_link_hash_entry *)
3824 elf_sym_hashes (input_bfd)[e_indx]);
3826 while (hash->root.root.type == bfd_link_hash_indirect
3827 || hash->root.root.type == bfd_link_hash_warning)
3828 hash = ((struct elf32_arm_link_hash_entry *)
3829 hash->root.root.u.i.link);
3831 if (hash->root.root.type == bfd_link_hash_defined
3832 || hash->root.root.type == bfd_link_hash_defweak)
3834 sym_sec = hash->root.root.u.def.section;
3835 sym_value = hash->root.root.u.def.value;
3836 if (sym_sec->output_section != NULL)
3837 destination = (sym_value + irela->r_addend
3838 + sym_sec->output_offset
3839 + sym_sec->output_section->vma);
3841 else if ((hash->root.root.type == bfd_link_hash_undefined)
3842 || (hash->root.root.type == bfd_link_hash_undefweak))
3844 /* For a shared library, use the PLT stub as
3845 target address to decide whether a long
3846 branch stub is needed.
3847 For absolute code, they cannot be handled. */
3848 struct elf32_arm_link_hash_table *globals =
3849 elf32_arm_hash_table (info);
3851 if (globals->splt != NULL && hash != NULL
3852 && hash->root.plt.offset != (bfd_vma) -1)
3854 sym_sec = globals->splt;
3855 sym_value = hash->root.plt.offset;
3856 if (sym_sec->output_section != NULL)
3857 destination = (sym_value
3858 + sym_sec->output_offset
3859 + sym_sec->output_section->vma);
3866 bfd_set_error (bfd_error_bad_value);
3867 goto error_ret_free_internal;
3869 st_type = ELF_ST_TYPE (hash->root.type);
3870 sym_name = hash->root.root.root.string;
3873 /* Determine what (if any) linker stub is needed. */
3874 stub_type = arm_type_of_stub (info, section, irela, st_type,
3875 hash, destination, sym_sec,
3876 input_bfd, sym_name);
3877 if (stub_type == arm_stub_none)
3880 /* Support for grouping stub sections. */
3881 id_sec = htab->stub_group[section->id].link_sec;
3883 /* Get the name of this stub. */
3884 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3886 goto error_ret_free_internal;
3888 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3891 if (stub_entry != NULL)
3893 /* The proper stub has already been created. */
3898 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
3899 if (stub_entry == NULL)
3902 goto error_ret_free_internal;
3905 stub_entry->target_value = sym_value;
3906 stub_entry->target_section = sym_sec;
3907 stub_entry->stub_type = stub_type;
3908 stub_entry->h = hash;
3909 stub_entry->st_type = st_type;
3911 if (sym_name == NULL)
3912 sym_name = "unnamed";
3913 stub_entry->output_name
3914 = bfd_alloc (htab->stub_bfd,
3915 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3916 + strlen (sym_name));
3917 if (stub_entry->output_name == NULL)
3920 goto error_ret_free_internal;
3923 /* For historical reasons, use the existing names for
3924 ARM-to-Thumb and Thumb-to-ARM stubs. */
3925 if (r_type == (unsigned int) R_ARM_THM_CALL
3926 && st_type != STT_ARM_TFUNC)
3927 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3929 else if (r_type == (unsigned int) R_ARM_CALL
3930 && st_type == STT_ARM_TFUNC)
3931 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3934 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3937 stub_changed = TRUE;
3940 /* We're done with the internal relocs, free them. */
3941 if (elf_section_data (section)->relocs == NULL)
3942 free (internal_relocs);
3949 /* OK, we've added some stubs. Find out the new size of the
3951 for (stub_sec = htab->stub_bfd->sections;
3953 stub_sec = stub_sec->next)
3955 /* Ignore non-stub sections. */
3956 if (!strstr (stub_sec->name, STUB_SUFFIX))
3962 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3964 /* Ask the linker to do its stuff. */
3965 (*htab->layout_sections_again) ();
3966 stub_changed = FALSE;
3971 error_ret_free_local:
3975 /* Build all the stubs associated with the current output file. The
3976 stubs are kept in a hash table attached to the main linker hash
3977 table. We also set up the .plt entries for statically linked PIC
3978 functions here. This function is called via arm_elf_finish in the
3982 elf32_arm_build_stubs (struct bfd_link_info *info)
3985 struct bfd_hash_table *table;
3986 struct elf32_arm_link_hash_table *htab;
3988 htab = elf32_arm_hash_table (info);
3990 for (stub_sec = htab->stub_bfd->sections;
3992 stub_sec = stub_sec->next)
3996 /* Ignore non-stub sections. */
3997 if (!strstr (stub_sec->name, STUB_SUFFIX))
4000 /* Allocate memory to hold the linker stubs. */
4001 size = stub_sec->size;
4002 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4003 if (stub_sec->contents == NULL && size != 0)
4008 /* Build the stubs as directed by the stub hash table. */
4009 table = &htab->stub_hash_table;
4010 bfd_hash_traverse (table, arm_build_one_stub, info);
4015 /* Locate the Thumb encoded calling stub for NAME. */
4017 static struct elf_link_hash_entry *
4018 find_thumb_glue (struct bfd_link_info *link_info,
4020 char **error_message)
4023 struct elf_link_hash_entry *hash;
4024 struct elf32_arm_link_hash_table *hash_table;
4026 /* We need a pointer to the armelf specific hash table. */
4027 hash_table = elf32_arm_hash_table (link_info);
4029 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4030 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4032 BFD_ASSERT (tmp_name);
4034 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4036 hash = elf_link_hash_lookup
4037 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4040 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
4041 tmp_name, name) == -1)
4042 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4049 /* Locate the ARM encoded calling stub for NAME. */
4051 static struct elf_link_hash_entry *
4052 find_arm_glue (struct bfd_link_info *link_info,
4054 char **error_message)
4057 struct elf_link_hash_entry *myh;
4058 struct elf32_arm_link_hash_table *hash_table;
4060 /* We need a pointer to the elfarm specific hash table. */
4061 hash_table = elf32_arm_hash_table (link_info);
4063 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4064 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4066 BFD_ASSERT (tmp_name);
4068 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4070 myh = elf_link_hash_lookup
4071 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4074 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
4075 tmp_name, name) == -1)
4076 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4083 /* ARM->Thumb glue (static images):
4087 ldr r12, __func_addr
4090 .word func @ behave as if you saw a ARM_32 reloc.
4097 .word func @ behave as if you saw a ARM_32 reloc.
4099 (relocatable images)
4102 ldr r12, __func_offset
4108 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4109 static const insn32 a2t1_ldr_insn = 0xe59fc000;
4110 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
4111 static const insn32 a2t3_func_addr_insn = 0x00000001;
4113 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4114 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
4115 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
4117 #define ARM2THUMB_PIC_GLUE_SIZE 16
4118 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
4119 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
4120 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
4122 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4126 __func_from_thumb: __func_from_thumb:
4128 nop ldr r6, __func_addr
4138 #define THUMB2ARM_GLUE_SIZE 8
4139 static const insn16 t2a1_bx_pc_insn = 0x4778;
4140 static const insn16 t2a2_noop_insn = 0x46c0;
4141 static const insn32 t2a3_b_insn = 0xea000000;
4143 #define VFP11_ERRATUM_VENEER_SIZE 8
4145 #define ARM_BX_VENEER_SIZE 12
4146 static const insn32 armbx1_tst_insn = 0xe3100001;
4147 static const insn32 armbx2_moveq_insn = 0x01a0f000;
4148 static const insn32 armbx3_bx_insn = 0xe12fff10;
4150 #ifndef ELFARM_NABI_C_INCLUDED
4152 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
4155 bfd_byte * contents;
4159 /* Do not include empty glue sections in the output. */
4162 s = bfd_get_section_by_name (abfd, name);
4164 s->flags |= SEC_EXCLUDE;
4169 BFD_ASSERT (abfd != NULL);
4171 s = bfd_get_section_by_name (abfd, name);
4172 BFD_ASSERT (s != NULL);
4174 contents = bfd_alloc (abfd, size);
4176 BFD_ASSERT (s->size == size);
4177 s->contents = contents;
4181 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
4183 struct elf32_arm_link_hash_table * globals;
4185 globals = elf32_arm_hash_table (info);
4186 BFD_ASSERT (globals != NULL);
4188 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4189 globals->arm_glue_size,
4190 ARM2THUMB_GLUE_SECTION_NAME);
4192 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4193 globals->thumb_glue_size,
4194 THUMB2ARM_GLUE_SECTION_NAME);
4196 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4197 globals->vfp11_erratum_glue_size,
4198 VFP11_ERRATUM_VENEER_SECTION_NAME);
4200 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4201 globals->bx_glue_size,
4202 ARM_BX_GLUE_SECTION_NAME);
4207 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4208 returns the symbol identifying the stub. */
4210 static struct elf_link_hash_entry *
4211 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
4212 struct elf_link_hash_entry * h)
4214 const char * name = h->root.root.string;
4217 struct elf_link_hash_entry * myh;
4218 struct bfd_link_hash_entry * bh;
4219 struct elf32_arm_link_hash_table * globals;
4223 globals = elf32_arm_hash_table (link_info);
4225 BFD_ASSERT (globals != NULL);
4226 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4228 s = bfd_get_section_by_name
4229 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
4231 BFD_ASSERT (s != NULL);
4233 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4235 BFD_ASSERT (tmp_name);
4237 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4239 myh = elf_link_hash_lookup
4240 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
4244 /* We've already seen this guy. */
4249 /* The only trick here is using hash_table->arm_glue_size as the value.
4250 Even though the section isn't allocated yet, this is where we will be
4251 putting it. The +1 on the value marks that the stub has not been
4252 output yet - not that it is a Thumb function. */
4254 val = globals->arm_glue_size + 1;
4255 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4256 tmp_name, BSF_GLOBAL, s, val,
4257 NULL, TRUE, FALSE, &bh);
4259 myh = (struct elf_link_hash_entry *) bh;
4260 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4261 myh->forced_local = 1;
4265 if (link_info->shared || globals->root.is_relocatable_executable
4266 || globals->pic_veneer)
4267 size = ARM2THUMB_PIC_GLUE_SIZE;
4268 else if (globals->use_blx)
4269 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
4271 size = ARM2THUMB_STATIC_GLUE_SIZE;
4274 globals->arm_glue_size += size;
4280 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4281 struct elf_link_hash_entry *h)
4283 const char *name = h->root.root.string;
4286 struct elf_link_hash_entry *myh;
4287 struct bfd_link_hash_entry *bh;
4288 struct elf32_arm_link_hash_table *hash_table;
4291 hash_table = elf32_arm_hash_table (link_info);
4293 BFD_ASSERT (hash_table != NULL);
4294 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4296 s = bfd_get_section_by_name
4297 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4299 BFD_ASSERT (s != NULL);
4301 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4302 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4304 BFD_ASSERT (tmp_name);
4306 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4308 myh = elf_link_hash_lookup
4309 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4313 /* We've already seen this guy. */
4318 /* The only trick here is using hash_table->thumb_glue_size as the value.
4319 Even though the section isn't allocated yet, this is where we will be
4320 putting it. The +1 on the value marks that the stub has not been
4321 output yet - not that it is a Thumb function. */
4323 val = hash_table->thumb_glue_size + 1;
4324 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4325 tmp_name, BSF_GLOBAL, s, val,
4326 NULL, TRUE, FALSE, &bh);
4328 /* If we mark it 'Thumb', the disassembler will do a better job. */
4329 myh = (struct elf_link_hash_entry *) bh;
4330 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4331 myh->forced_local = 1;
4335 #define CHANGE_TO_ARM "__%s_change_to_arm"
4336 #define BACK_FROM_ARM "__%s_back_from_arm"
4338 /* Allocate another symbol to mark where we switch to Arm mode. */
4339 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4340 + strlen (CHANGE_TO_ARM) + 1);
4342 BFD_ASSERT (tmp_name);
4344 sprintf (tmp_name, CHANGE_TO_ARM, name);
4347 val = hash_table->thumb_glue_size + 4,
4348 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4349 tmp_name, BSF_LOCAL, s, val,
4350 NULL, TRUE, FALSE, &bh);
4354 s->size += THUMB2ARM_GLUE_SIZE;
4355 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
4359 /* Allocate space for ARMv4 BX veneers. */
4362 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4365 struct elf32_arm_link_hash_table *globals;
4367 struct elf_link_hash_entry *myh;
4368 struct bfd_link_hash_entry *bh;
4371 /* BX PC does not need a veneer. */
4375 globals = elf32_arm_hash_table (link_info);
4377 BFD_ASSERT (globals != NULL);
4378 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4380 /* Check if this veneer has already been allocated. */
4381 if (globals->bx_glue_offset[reg])
4384 s = bfd_get_section_by_name
4385 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4387 BFD_ASSERT (s != NULL);
4389 /* Add symbol for veneer. */
4390 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
4392 BFD_ASSERT (tmp_name);
4394 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
4396 myh = elf_link_hash_lookup
4397 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
4399 BFD_ASSERT (myh == NULL);
4402 val = globals->bx_glue_size;
4403 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4404 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4405 NULL, TRUE, FALSE, &bh);
4407 myh = (struct elf_link_hash_entry *) bh;
4408 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4409 myh->forced_local = 1;
4411 s->size += ARM_BX_VENEER_SIZE;
4412 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4413 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4417 /* Add an entry to the code/data map for section SEC. */
4420 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4422 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4423 unsigned int newidx;
4425 if (sec_data->map == NULL)
4427 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4428 sec_data->mapcount = 0;
4429 sec_data->mapsize = 1;
4432 newidx = sec_data->mapcount++;
4434 if (sec_data->mapcount > sec_data->mapsize)
4436 sec_data->mapsize *= 2;
4437 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4438 * sizeof (elf32_arm_section_map));
4443 sec_data->map[newidx].vma = vma;
4444 sec_data->map[newidx].type = type;
4449 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4450 veneers are handled for now. */
4453 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4454 elf32_vfp11_erratum_list *branch,
4456 asection *branch_sec,
4457 unsigned int offset)
4460 struct elf32_arm_link_hash_table *hash_table;
4462 struct elf_link_hash_entry *myh;
4463 struct bfd_link_hash_entry *bh;
4465 struct _arm_elf_section_data *sec_data;
4467 elf32_vfp11_erratum_list *newerr;
4469 hash_table = elf32_arm_hash_table (link_info);
4471 BFD_ASSERT (hash_table != NULL);
4472 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4474 s = bfd_get_section_by_name
4475 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
4477 sec_data = elf32_arm_section_data (s);
4479 BFD_ASSERT (s != NULL);
4481 tmp_name = bfd_malloc ((bfd_size_type) strlen
4482 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
4484 BFD_ASSERT (tmp_name);
4486 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4487 hash_table->num_vfp11_fixes);
4489 myh = elf_link_hash_lookup
4490 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4492 BFD_ASSERT (myh == NULL);
4495 val = hash_table->vfp11_erratum_glue_size;
4496 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4497 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4498 NULL, TRUE, FALSE, &bh);
4500 myh = (struct elf_link_hash_entry *) bh;
4501 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4502 myh->forced_local = 1;
4504 /* Link veneer back to calling location. */
4505 errcount = ++(sec_data->erratumcount);
4506 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
4508 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4510 newerr->u.v.branch = branch;
4511 newerr->u.v.id = hash_table->num_vfp11_fixes;
4512 branch->u.b.veneer = newerr;
4514 newerr->next = sec_data->erratumlist;
4515 sec_data->erratumlist = newerr;
4517 /* A symbol for the return from the veneer. */
4518 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4519 hash_table->num_vfp11_fixes);
4521 myh = elf_link_hash_lookup
4522 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4529 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4530 branch_sec, val, NULL, TRUE, FALSE, &bh);
4532 myh = (struct elf_link_hash_entry *) bh;
4533 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4534 myh->forced_local = 1;
4538 /* Generate a mapping symbol for the veneer section, and explicitly add an
4539 entry for that symbol to the code/data map for the section. */
4540 if (hash_table->vfp11_erratum_glue_size == 0)
4543 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4544 ever requires this erratum fix. */
4545 _bfd_generic_link_add_one_symbol (link_info,
4546 hash_table->bfd_of_glue_owner, "$a",
4547 BSF_LOCAL, s, 0, NULL,
4550 myh = (struct elf_link_hash_entry *) bh;
4551 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4552 myh->forced_local = 1;
4554 /* The elf32_arm_init_maps function only cares about symbols from input
4555 BFDs. We must make a note of this generated mapping symbol
4556 ourselves so that code byteswapping works properly in
4557 elf32_arm_write_section. */
4558 elf32_arm_section_map_add (s, 'a', 0);
4561 s->size += VFP11_ERRATUM_VENEER_SIZE;
4562 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4563 hash_table->num_vfp11_fixes++;
4565 /* The offset of the veneer. */
4569 #define ARM_GLUE_SECTION_FLAGS \
4570 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
4571 | SEC_READONLY | SEC_LINKER_CREATED)
4573 /* Create a fake section for use by the ARM backend of the linker. */
4576 arm_make_glue_section (bfd * abfd, const char * name)
4580 sec = bfd_get_section_by_name (abfd, name);
4585 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
4588 || !bfd_set_section_alignment (abfd, sec, 2))
4591 /* Set the gc mark to prevent the section from being removed by garbage
4592 collection, despite the fact that no relocs refer to this section. */
4598 /* Add the glue sections to ABFD. This function is called from the
4599 linker scripts in ld/emultempl/{armelf}.em. */
4602 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4603 struct bfd_link_info *info)
4605 /* If we are only performing a partial
4606 link do not bother adding the glue. */
4607 if (info->relocatable)
4610 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
4611 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
4612 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
4613 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
4616 /* Select a BFD to be used to hold the sections used by the glue code.
4617 This function is called from the linker scripts in ld/emultempl/
4621 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
4623 struct elf32_arm_link_hash_table *globals;
4625 /* If we are only performing a partial link
4626 do not bother getting a bfd to hold the glue. */
4627 if (info->relocatable)
4630 /* Make sure we don't attach the glue sections to a dynamic object. */
4631 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4633 globals = elf32_arm_hash_table (info);
4635 BFD_ASSERT (globals != NULL);
4637 if (globals->bfd_of_glue_owner != NULL)
4640 /* Save the bfd for later use. */
4641 globals->bfd_of_glue_owner = abfd;
4647 check_use_blx (struct elf32_arm_link_hash_table *globals)
4649 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4651 globals->use_blx = 1;
4655 bfd_elf32_arm_process_before_allocation (bfd *abfd,
4656 struct bfd_link_info *link_info)
4658 Elf_Internal_Shdr *symtab_hdr;
4659 Elf_Internal_Rela *internal_relocs = NULL;
4660 Elf_Internal_Rela *irel, *irelend;
4661 bfd_byte *contents = NULL;
4664 struct elf32_arm_link_hash_table *globals;
4666 /* If we are only performing a partial link do not bother
4667 to construct any glue. */
4668 if (link_info->relocatable)
4671 /* Here we have a bfd that is to be included on the link. We have a
4672 hook to do reloc rummaging, before section sizes are nailed down. */
4673 globals = elf32_arm_hash_table (link_info);
4675 BFD_ASSERT (globals != NULL);
4677 check_use_blx (globals);
4679 if (globals->byteswap_code && !bfd_big_endian (abfd))
4681 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4686 /* PR 5398: If we have not decided to include any loadable sections in
4687 the output then we will not have a glue owner bfd. This is OK, it
4688 just means that there is nothing else for us to do here. */
4689 if (globals->bfd_of_glue_owner == NULL)
4692 /* Rummage around all the relocs and map the glue vectors. */
4693 sec = abfd->sections;
4698 for (; sec != NULL; sec = sec->next)
4700 if (sec->reloc_count == 0)
4703 if ((sec->flags & SEC_EXCLUDE) != 0)
4706 symtab_hdr = & elf_symtab_hdr (abfd);
4708 /* Load the relocs. */
4710 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
4712 if (internal_relocs == NULL)
4715 irelend = internal_relocs + sec->reloc_count;
4716 for (irel = internal_relocs; irel < irelend; irel++)
4719 unsigned long r_index;
4721 struct elf_link_hash_entry *h;
4723 r_type = ELF32_R_TYPE (irel->r_info);
4724 r_index = ELF32_R_SYM (irel->r_info);
4726 /* These are the only relocation types we care about. */
4727 if ( r_type != R_ARM_PC24
4728 && r_type != R_ARM_PLT32
4729 && r_type != R_ARM_JUMP24
4730 && r_type != R_ARM_THM_JUMP24
4731 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
4734 /* Get the section contents if we haven't done so already. */
4735 if (contents == NULL)
4737 /* Get cached copy if it exists. */
4738 if (elf_section_data (sec)->this_hdr.contents != NULL)
4739 contents = elf_section_data (sec)->this_hdr.contents;
4742 /* Go get them off disk. */
4743 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
4748 if (r_type == R_ARM_V4BX)
4752 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4753 record_arm_bx_glue (link_info, reg);
4757 /* If the relocation is not against a symbol it cannot concern us. */
4760 /* We don't care about local symbols. */
4761 if (r_index < symtab_hdr->sh_info)
4764 /* This is an external symbol. */
4765 r_index -= symtab_hdr->sh_info;
4766 h = (struct elf_link_hash_entry *)
4767 elf_sym_hashes (abfd)[r_index];
4769 /* If the relocation is against a static symbol it must be within
4770 the current section and so cannot be a cross ARM/Thumb relocation. */
4774 /* If the call will go through a PLT entry then we do not need
4776 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
4784 /* This one is a call from arm code. We need to look up
4785 the target of the call. If it is a thumb target, we
4787 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
4788 record_arm_to_thumb_glue (link_info, h);
4791 case R_ARM_THM_JUMP24:
4792 /* This one is a call from thumb code. We look
4793 up the target of the call. If it is not a thumb
4794 target, we insert glue. */
4795 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4796 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
4797 && h->root.type != bfd_link_hash_undefweak)
4798 record_thumb_to_arm_glue (link_info, h);
4806 if (contents != NULL
4807 && elf_section_data (sec)->this_hdr.contents != contents)
4811 if (internal_relocs != NULL
4812 && elf_section_data (sec)->relocs != internal_relocs)
4813 free (internal_relocs);
4814 internal_relocs = NULL;
4820 if (contents != NULL
4821 && elf_section_data (sec)->this_hdr.contents != contents)
4823 if (internal_relocs != NULL
4824 && elf_section_data (sec)->relocs != internal_relocs)
4825 free (internal_relocs);
4832 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4835 bfd_elf32_arm_init_maps (bfd *abfd)
4837 Elf_Internal_Sym *isymbuf;
4838 Elf_Internal_Shdr *hdr;
4839 unsigned int i, localsyms;
4841 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4842 if (! is_arm_elf (abfd))
4845 if ((abfd->flags & DYNAMIC) != 0)
4848 hdr = & elf_symtab_hdr (abfd);
4849 localsyms = hdr->sh_info;
4851 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4852 should contain the number of local symbols, which should come before any
4853 global symbols. Mapping symbols are always local. */
4854 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4857 /* No internal symbols read? Skip this BFD. */
4858 if (isymbuf == NULL)
4861 for (i = 0; i < localsyms; i++)
4863 Elf_Internal_Sym *isym = &isymbuf[i];
4864 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4868 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4870 name = bfd_elf_string_from_elf_section (abfd,
4871 hdr->sh_link, isym->st_name);
4873 if (bfd_is_arm_special_symbol_name (name,
4874 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4875 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4882 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4884 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4885 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
4887 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4888 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4890 switch (globals->vfp11_fix)
4892 case BFD_ARM_VFP11_FIX_DEFAULT:
4893 case BFD_ARM_VFP11_FIX_NONE:
4894 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4898 /* Give a warning, but do as the user requests anyway. */
4899 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4900 "workaround is not necessary for target architecture"), obfd);
4903 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4904 /* For earlier architectures, we might need the workaround, but do not
4905 enable it by default. If users is running with broken hardware, they
4906 must enable the erratum fix explicitly. */
4907 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4911 enum bfd_arm_vfp11_pipe
4919 /* Return a VFP register number. This is encoded as RX:X for single-precision
4920 registers, or X:RX for double-precision registers, where RX is the group of
4921 four bits in the instruction encoding and X is the single extension bit.
4922 RX and X fields are specified using their lowest (starting) bit. The return
4925 0...31: single-precision registers s0...s31
4926 32...63: double-precision registers d0...d31.
4928 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4929 encounter VFP3 instructions, so we allow the full range for DP registers. */
4932 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4936 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4938 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4941 /* Set bits in *WMASK according to a register number REG as encoded by
4942 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4945 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4950 *wmask |= 3 << ((reg - 32) * 2);
4953 /* Return TRUE if WMASK overwrites anything in REGS. */
4956 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4960 for (i = 0; i < numregs; i++)
4962 unsigned int reg = regs[i];
4964 if (reg < 32 && (wmask & (1 << reg)) != 0)
4972 if ((wmask & (3 << (reg * 2))) != 0)
4979 /* In this function, we're interested in two things: finding input registers
4980 for VFP data-processing instructions, and finding the set of registers which
4981 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4982 hold the written set, so FLDM etc. are easy to deal with (we're only
4983 interested in 32 SP registers or 16 dp registers, due to the VFP version
4984 implemented by the chip in question). DP registers are marked by setting
4985 both SP registers in the write mask). */
4987 static enum bfd_arm_vfp11_pipe
4988 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4991 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4992 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4994 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4997 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4998 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
5000 pqrs = ((insn & 0x00800000) >> 20)
5001 | ((insn & 0x00300000) >> 19)
5002 | ((insn & 0x00000040) >> 6);
5006 case 0: /* fmac[sd]. */
5007 case 1: /* fnmac[sd]. */
5008 case 2: /* fmsc[sd]. */
5009 case 3: /* fnmsc[sd]. */
5011 bfd_arm_vfp11_write_mask (destmask, fd);
5013 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
5018 case 4: /* fmul[sd]. */
5019 case 5: /* fnmul[sd]. */
5020 case 6: /* fadd[sd]. */
5021 case 7: /* fsub[sd]. */
5025 case 8: /* fdiv[sd]. */
5028 bfd_arm_vfp11_write_mask (destmask, fd);
5029 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
5034 case 15: /* extended opcode. */
5036 unsigned int extn = ((insn >> 15) & 0x1e)
5037 | ((insn >> 7) & 1);
5041 case 0: /* fcpy[sd]. */
5042 case 1: /* fabs[sd]. */
5043 case 2: /* fneg[sd]. */
5044 case 8: /* fcmp[sd]. */
5045 case 9: /* fcmpe[sd]. */
5046 case 10: /* fcmpz[sd]. */
5047 case 11: /* fcmpez[sd]. */
5048 case 16: /* fuito[sd]. */
5049 case 17: /* fsito[sd]. */
5050 case 24: /* ftoui[sd]. */
5051 case 25: /* ftouiz[sd]. */
5052 case 26: /* ftosi[sd]. */
5053 case 27: /* ftosiz[sd]. */
5054 /* These instructions will not bounce due to underflow. */
5059 case 3: /* fsqrt[sd]. */
5060 /* fsqrt cannot underflow, but it can (perhaps) overwrite
5061 registers to cause the erratum in previous instructions. */
5062 bfd_arm_vfp11_write_mask (destmask, fd);
5066 case 15: /* fcvt{ds,sd}. */
5070 bfd_arm_vfp11_write_mask (destmask, fd);
5072 /* Only FCVTSD can underflow. */
5073 if ((insn & 0x100) != 0)
5092 /* Two-register transfer. */
5093 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
5095 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
5097 if ((insn & 0x100000) == 0)
5100 bfd_arm_vfp11_write_mask (destmask, fm);
5103 bfd_arm_vfp11_write_mask (destmask, fm);
5104 bfd_arm_vfp11_write_mask (destmask, fm + 1);
5110 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
5112 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
5113 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
5117 case 0: /* Two-reg transfer. We should catch these above. */
5120 case 2: /* fldm[sdx]. */
5124 unsigned int i, offset = insn & 0xff;
5129 for (i = fd; i < fd + offset; i++)
5130 bfd_arm_vfp11_write_mask (destmask, i);
5134 case 4: /* fld[sd]. */
5136 bfd_arm_vfp11_write_mask (destmask, fd);
5145 /* Single-register transfer. Note L==0. */
5146 else if ((insn & 0x0f100e10) == 0x0e000a10)
5148 unsigned int opcode = (insn >> 21) & 7;
5149 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
5153 case 0: /* fmsr/fmdlr. */
5154 case 1: /* fmdhr. */
5155 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5156 destination register. I don't know if this is exactly right,
5157 but it is the conservative choice. */
5158 bfd_arm_vfp11_write_mask (destmask, fn);
5172 static int elf32_arm_compare_mapping (const void * a, const void * b);
5175 /* Look for potentially-troublesome code sequences which might trigger the
5176 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5177 (available from ARM) for details of the erratum. A short version is
5178 described in ld.texinfo. */
5181 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
5184 bfd_byte *contents = NULL;
5186 int regs[3], numregs = 0;
5187 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
5188 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
5190 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5191 The states transition as follows:
5193 0 -> 1 (vector) or 0 -> 2 (scalar)
5194 A VFP FMAC-pipeline instruction has been seen. Fill
5195 regs[0]..regs[numregs-1] with its input operands. Remember this
5196 instruction in 'first_fmac'.
5199 Any instruction, except for a VFP instruction which overwrites
5204 A VFP instruction has been seen which overwrites any of regs[*].
5205 We must make a veneer! Reset state to 0 before examining next
5209 If we fail to match anything in state 2, reset to state 0 and reset
5210 the instruction pointer to the instruction after 'first_fmac'.
5212 If the VFP11 vector mode is in use, there must be at least two unrelated
5213 instructions between anti-dependent VFP11 instructions to properly avoid
5214 triggering the erratum, hence the use of the extra state 1. */
5216 /* If we are only performing a partial link do not bother
5217 to construct any glue. */
5218 if (link_info->relocatable)
5221 /* Skip if this bfd does not correspond to an ELF image. */
5222 if (! is_arm_elf (abfd))
5225 /* We should have chosen a fix type by the time we get here. */
5226 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5228 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5231 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5232 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
5235 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5237 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5238 struct _arm_elf_section_data *sec_data;
5240 /* If we don't have executable progbits, we're not interested in this
5241 section. Also skip if section is to be excluded. */
5242 if (elf_section_type (sec) != SHT_PROGBITS
5243 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5244 || (sec->flags & SEC_EXCLUDE) != 0
5245 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
5246 || sec->output_section == bfd_abs_section_ptr
5247 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5250 sec_data = elf32_arm_section_data (sec);
5252 if (sec_data->mapcount == 0)
5255 if (elf_section_data (sec)->this_hdr.contents != NULL)
5256 contents = elf_section_data (sec)->this_hdr.contents;
5257 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5260 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5261 elf32_arm_compare_mapping);
5263 for (span = 0; span < sec_data->mapcount; span++)
5265 unsigned int span_start = sec_data->map[span].vma;
5266 unsigned int span_end = (span == sec_data->mapcount - 1)
5267 ? sec->size : sec_data->map[span + 1].vma;
5268 char span_type = sec_data->map[span].type;
5270 /* FIXME: Only ARM mode is supported at present. We may need to
5271 support Thumb-2 mode also at some point. */
5272 if (span_type != 'a')
5275 for (i = span_start; i < span_end;)
5277 unsigned int next_i = i + 4;
5278 unsigned int insn = bfd_big_endian (abfd)
5279 ? (contents[i] << 24)
5280 | (contents[i + 1] << 16)
5281 | (contents[i + 2] << 8)
5283 : (contents[i + 3] << 24)
5284 | (contents[i + 2] << 16)
5285 | (contents[i + 1] << 8)
5287 unsigned int writemask = 0;
5288 enum bfd_arm_vfp11_pipe pipe;
5293 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5295 /* I'm assuming the VFP11 erratum can trigger with denorm
5296 operands on either the FMAC or the DS pipeline. This might
5297 lead to slightly overenthusiastic veneer insertion. */
5298 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5300 state = use_vector ? 1 : 2;
5302 veneer_of_insn = insn;
5308 int other_regs[3], other_numregs;
5309 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5312 if (pipe != VFP11_BAD
5313 && bfd_arm_vfp11_antidependency (writemask, regs,
5323 int other_regs[3], other_numregs;
5324 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5327 if (pipe != VFP11_BAD
5328 && bfd_arm_vfp11_antidependency (writemask, regs,
5334 next_i = first_fmac + 4;
5340 abort (); /* Should be unreachable. */
5345 elf32_vfp11_erratum_list *newerr
5346 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5349 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5351 newerr->u.b.vfp_insn = veneer_of_insn;
5356 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5363 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5368 newerr->next = sec_data->erratumlist;
5369 sec_data->erratumlist = newerr;
5378 if (contents != NULL
5379 && elf_section_data (sec)->this_hdr.contents != contents)
5387 if (contents != NULL
5388 && elf_section_data (sec)->this_hdr.contents != contents)
5394 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5395 after sections have been laid out, using specially-named symbols. */
5398 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5399 struct bfd_link_info *link_info)
5402 struct elf32_arm_link_hash_table *globals;
5405 if (link_info->relocatable)
5408 /* Skip if this bfd does not correspond to an ELF image. */
5409 if (! is_arm_elf (abfd))
5412 globals = elf32_arm_hash_table (link_info);
5414 tmp_name = bfd_malloc ((bfd_size_type) strlen
5415 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5417 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5419 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5420 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
5422 for (; errnode != NULL; errnode = errnode->next)
5424 struct elf_link_hash_entry *myh;
5427 switch (errnode->type)
5429 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5430 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5431 /* Find veneer symbol. */
5432 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5433 errnode->u.b.veneer->u.v.id);
5435 myh = elf_link_hash_lookup
5436 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5439 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5440 "`%s'"), abfd, tmp_name);
5442 vma = myh->root.u.def.section->output_section->vma
5443 + myh->root.u.def.section->output_offset
5444 + myh->root.u.def.value;
5446 errnode->u.b.veneer->vma = vma;
5449 case VFP11_ERRATUM_ARM_VENEER:
5450 case VFP11_ERRATUM_THUMB_VENEER:
5451 /* Find return location. */
5452 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5455 myh = elf_link_hash_lookup
5456 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5459 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5460 "`%s'"), abfd, tmp_name);
5462 vma = myh->root.u.def.section->output_section->vma
5463 + myh->root.u.def.section->output_offset
5464 + myh->root.u.def.value;
5466 errnode->u.v.branch->vma = vma;
5479 /* Set target relocation values needed during linking. */
5482 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5483 struct bfd_link_info *link_info,
5485 char * target2_type,
5488 bfd_arm_vfp11_fix vfp11_fix,
5489 int no_enum_warn, int no_wchar_warn,
5492 struct elf32_arm_link_hash_table *globals;
5494 globals = elf32_arm_hash_table (link_info);
5496 globals->target1_is_rel = target1_is_rel;
5497 if (strcmp (target2_type, "rel") == 0)
5498 globals->target2_reloc = R_ARM_REL32;
5499 else if (strcmp (target2_type, "abs") == 0)
5500 globals->target2_reloc = R_ARM_ABS32;
5501 else if (strcmp (target2_type, "got-rel") == 0)
5502 globals->target2_reloc = R_ARM_GOT_PREL;
5505 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5508 globals->fix_v4bx = fix_v4bx;
5509 globals->use_blx |= use_blx;
5510 globals->vfp11_fix = vfp11_fix;
5511 globals->pic_veneer = pic_veneer;
5513 BFD_ASSERT (is_arm_elf (output_bfd));
5514 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
5515 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
5518 /* Replace the target offset of a Thumb bl or b.w instruction. */
5521 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5527 BFD_ASSERT ((offset & 1) == 0);
5529 upper = bfd_get_16 (abfd, insn);
5530 lower = bfd_get_16 (abfd, insn + 2);
5531 reloc_sign = (offset < 0) ? 1 : 0;
5532 upper = (upper & ~(bfd_vma) 0x7ff)
5533 | ((offset >> 12) & 0x3ff)
5534 | (reloc_sign << 10);
5535 lower = (lower & ~(bfd_vma) 0x2fff)
5536 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5537 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5538 | ((offset >> 1) & 0x7ff);
5539 bfd_put_16 (abfd, upper, insn);
5540 bfd_put_16 (abfd, lower, insn + 2);
5543 /* Thumb code calling an ARM function. */
5546 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5550 asection * input_section,
5551 bfd_byte * hit_data,
5554 bfd_signed_vma addend,
5556 char **error_message)
5560 long int ret_offset;
5561 struct elf_link_hash_entry * myh;
5562 struct elf32_arm_link_hash_table * globals;
5564 myh = find_thumb_glue (info, name, error_message);
5568 globals = elf32_arm_hash_table (info);
5570 BFD_ASSERT (globals != NULL);
5571 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5573 my_offset = myh->root.u.def.value;
5575 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5576 THUMB2ARM_GLUE_SECTION_NAME);
5578 BFD_ASSERT (s != NULL);
5579 BFD_ASSERT (s->contents != NULL);
5580 BFD_ASSERT (s->output_section != NULL);
5582 if ((my_offset & 0x01) == 0x01)
5585 && sym_sec->owner != NULL
5586 && !INTERWORK_FLAG (sym_sec->owner))
5588 (*_bfd_error_handler)
5589 (_("%B(%s): warning: interworking not enabled.\n"
5590 " first occurrence: %B: thumb call to arm"),
5591 sym_sec->owner, input_bfd, name);
5597 myh->root.u.def.value = my_offset;
5599 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5600 s->contents + my_offset);
5602 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5603 s->contents + my_offset + 2);
5606 /* Address of destination of the stub. */
5607 ((bfd_signed_vma) val)
5609 /* Offset from the start of the current section
5610 to the start of the stubs. */
5612 /* Offset of the start of this stub from the start of the stubs. */
5614 /* Address of the start of the current section. */
5615 + s->output_section->vma)
5616 /* The branch instruction is 4 bytes into the stub. */
5618 /* ARM branches work from the pc of the instruction + 8. */
5621 put_arm_insn (globals, output_bfd,
5622 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5623 s->contents + my_offset + 4);
5626 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5628 /* Now go back and fix up the original BL insn to point to here. */
5630 /* Address of where the stub is located. */
5631 (s->output_section->vma + s->output_offset + my_offset)
5632 /* Address of where the BL is located. */
5633 - (input_section->output_section->vma + input_section->output_offset
5635 /* Addend in the relocation. */
5637 /* Biassing for PC-relative addressing. */
5640 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
5645 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5647 static struct elf_link_hash_entry *
5648 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5655 char ** error_message)
5658 long int ret_offset;
5659 struct elf_link_hash_entry * myh;
5660 struct elf32_arm_link_hash_table * globals;
5662 myh = find_arm_glue (info, name, error_message);
5666 globals = elf32_arm_hash_table (info);
5668 BFD_ASSERT (globals != NULL);
5669 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5671 my_offset = myh->root.u.def.value;
5673 if ((my_offset & 0x01) == 0x01)
5676 && sym_sec->owner != NULL
5677 && !INTERWORK_FLAG (sym_sec->owner))
5679 (*_bfd_error_handler)
5680 (_("%B(%s): warning: interworking not enabled.\n"
5681 " first occurrence: %B: arm call to thumb"),
5682 sym_sec->owner, input_bfd, name);
5686 myh->root.u.def.value = my_offset;
5688 if (info->shared || globals->root.is_relocatable_executable
5689 || globals->pic_veneer)
5691 /* For relocatable objects we can't use absolute addresses,
5692 so construct the address from a relative offset. */
5693 /* TODO: If the offset is small it's probably worth
5694 constructing the address with adds. */
5695 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5696 s->contents + my_offset);
5697 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5698 s->contents + my_offset + 4);
5699 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5700 s->contents + my_offset + 8);
5701 /* Adjust the offset by 4 for the position of the add,
5702 and 8 for the pipeline offset. */
5703 ret_offset = (val - (s->output_offset
5704 + s->output_section->vma
5707 bfd_put_32 (output_bfd, ret_offset,
5708 s->contents + my_offset + 12);
5710 else if (globals->use_blx)
5712 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5713 s->contents + my_offset);
5715 /* It's a thumb address. Add the low order bit. */
5716 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5717 s->contents + my_offset + 4);
5721 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5722 s->contents + my_offset);
5724 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5725 s->contents + my_offset + 4);
5727 /* It's a thumb address. Add the low order bit. */
5728 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5729 s->contents + my_offset + 8);
5735 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5740 /* Arm code calling a Thumb function. */
5743 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5747 asection * input_section,
5748 bfd_byte * hit_data,
5751 bfd_signed_vma addend,
5753 char **error_message)
5755 unsigned long int tmp;
5758 long int ret_offset;
5759 struct elf_link_hash_entry * myh;
5760 struct elf32_arm_link_hash_table * globals;
5762 globals = elf32_arm_hash_table (info);
5764 BFD_ASSERT (globals != NULL);
5765 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5767 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5768 ARM2THUMB_GLUE_SECTION_NAME);
5769 BFD_ASSERT (s != NULL);
5770 BFD_ASSERT (s->contents != NULL);
5771 BFD_ASSERT (s->output_section != NULL);
5773 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
5774 sym_sec, val, s, error_message);
5778 my_offset = myh->root.u.def.value;
5779 tmp = bfd_get_32 (input_bfd, hit_data);
5780 tmp = tmp & 0xFF000000;
5782 /* Somehow these are both 4 too far, so subtract 8. */
5783 ret_offset = (s->output_offset
5785 + s->output_section->vma
5786 - (input_section->output_offset
5787 + input_section->output_section->vma
5791 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5793 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
5798 /* Populate Arm stub for an exported Thumb function. */
5801 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5803 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5805 struct elf_link_hash_entry * myh;
5806 struct elf32_arm_link_hash_entry *eh;
5807 struct elf32_arm_link_hash_table * globals;
5810 char *error_message;
5812 eh = elf32_arm_hash_entry (h);
5813 /* Allocate stubs for exported Thumb functions on v4t. */
5814 if (eh->export_glue == NULL)
5817 globals = elf32_arm_hash_table (info);
5819 BFD_ASSERT (globals != NULL);
5820 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5822 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5823 ARM2THUMB_GLUE_SECTION_NAME);
5824 BFD_ASSERT (s != NULL);
5825 BFD_ASSERT (s->contents != NULL);
5826 BFD_ASSERT (s->output_section != NULL);
5828 sec = eh->export_glue->root.u.def.section;
5830 BFD_ASSERT (sec->output_section != NULL);
5832 val = eh->export_glue->root.u.def.value + sec->output_offset
5833 + sec->output_section->vma;
5835 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5836 h->root.u.def.section->owner,
5837 globals->obfd, sec, val, s,
5843 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5846 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5851 struct elf32_arm_link_hash_table *globals;
5853 globals = elf32_arm_hash_table (info);
5855 BFD_ASSERT (globals != NULL);
5856 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5858 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5859 ARM_BX_GLUE_SECTION_NAME);
5860 BFD_ASSERT (s != NULL);
5861 BFD_ASSERT (s->contents != NULL);
5862 BFD_ASSERT (s->output_section != NULL);
5864 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5866 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5868 if ((globals->bx_glue_offset[reg] & 1) == 0)
5870 p = s->contents + glue_addr;
5871 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5872 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5873 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5874 globals->bx_glue_offset[reg] |= 1;
5877 return glue_addr + s->output_section->vma + s->output_offset;
5880 /* Generate Arm stubs for exported Thumb symbols. */
5882 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
5883 struct bfd_link_info *link_info)
5885 struct elf32_arm_link_hash_table * globals;
5887 if (link_info == NULL)
5888 /* Ignore this if we are not called by the ELF backend linker. */
5891 globals = elf32_arm_hash_table (link_info);
5892 /* If blx is available then exported Thumb symbols are OK and there is
5894 if (globals->use_blx)
5897 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5901 /* Some relocations map to different relocations depending on the
5902 target. Return the real relocation. */
5905 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5911 if (globals->target1_is_rel)
5917 return globals->target2_reloc;
5924 /* Return the base VMA address which should be subtracted from real addresses
5925 when resolving @dtpoff relocation.
5926 This is PT_TLS segment p_vaddr. */
5929 dtpoff_base (struct bfd_link_info *info)
5931 /* If tls_sec is NULL, we should have signalled an error already. */
5932 if (elf_hash_table (info)->tls_sec == NULL)
5934 return elf_hash_table (info)->tls_sec->vma;
5937 /* Return the relocation value for @tpoff relocation
5938 if STT_TLS virtual address is ADDRESS. */
5941 tpoff (struct bfd_link_info *info, bfd_vma address)
5943 struct elf_link_hash_table *htab = elf_hash_table (info);
5946 /* If tls_sec is NULL, we should have signalled an error already. */
5947 if (htab->tls_sec == NULL)
5949 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5950 return address - htab->tls_sec->vma + base;
5953 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5954 VALUE is the relocation value. */
5956 static bfd_reloc_status_type
5957 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5960 return bfd_reloc_overflow;
5962 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5963 bfd_put_32 (abfd, value, data);
5964 return bfd_reloc_ok;
5967 /* For a given value of n, calculate the value of G_n as required to
5968 deal with group relocations. We return it in the form of an
5969 encoded constant-and-rotation, together with the final residual. If n is
5970 specified as less than zero, then final_residual is filled with the
5971 input value and no further action is performed. */
5974 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5978 bfd_vma encoded_g_n = 0;
5979 bfd_vma residual = value; /* Also known as Y_n. */
5981 for (current_n = 0; current_n <= n; current_n++)
5985 /* Calculate which part of the value to mask. */
5992 /* Determine the most significant bit in the residual and
5993 align the resulting value to a 2-bit boundary. */
5994 for (msb = 30; msb >= 0; msb -= 2)
5995 if (residual & (3 << msb))
5998 /* The desired shift is now (msb - 6), or zero, whichever
6005 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
6006 g_n = residual & (0xff << shift);
6007 encoded_g_n = (g_n >> shift)
6008 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
6010 /* Calculate the residual for the next time around. */
6014 *final_residual = residual;
6019 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
6020 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
6023 identify_add_or_sub (bfd_vma insn)
6025 int opcode = insn & 0x1e00000;
6027 if (opcode == 1 << 23) /* ADD */
6030 if (opcode == 1 << 22) /* SUB */
6036 /* Perform a relocation as part of a final link. */
6038 static bfd_reloc_status_type
6039 elf32_arm_final_link_relocate (reloc_howto_type * howto,
6042 asection * input_section,
6043 bfd_byte * contents,
6044 Elf_Internal_Rela * rel,
6046 struct bfd_link_info * info,
6048 const char * sym_name,
6050 struct elf_link_hash_entry * h,
6051 bfd_boolean * unresolved_reloc_p,
6052 char ** error_message)
6054 unsigned long r_type = howto->type;
6055 unsigned long r_symndx;
6056 bfd_byte * hit_data = contents + rel->r_offset;
6057 bfd * dynobj = NULL;
6058 Elf_Internal_Shdr * symtab_hdr;
6059 struct elf_link_hash_entry ** sym_hashes;
6060 bfd_vma * local_got_offsets;
6061 asection * sgot = NULL;
6062 asection * splt = NULL;
6063 asection * sreloc = NULL;
6065 bfd_signed_vma signed_addend;
6066 struct elf32_arm_link_hash_table * globals;
6068 globals = elf32_arm_hash_table (info);
6070 BFD_ASSERT (is_arm_elf (input_bfd));
6072 /* Some relocation types map to different relocations depending on the
6073 target. We pick the right one here. */
6074 r_type = arm_real_reloc_type (globals, r_type);
6075 if (r_type != howto->type)
6076 howto = elf32_arm_howto_from_type (r_type);
6078 /* If the start address has been set, then set the EF_ARM_HASENTRY
6079 flag. Setting this more than once is redundant, but the cost is
6080 not too high, and it keeps the code simple.
6082 The test is done here, rather than somewhere else, because the
6083 start address is only set just before the final link commences.
6085 Note - if the user deliberately sets a start address of 0, the
6086 flag will not be set. */
6087 if (bfd_get_start_address (output_bfd) != 0)
6088 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
6090 dynobj = elf_hash_table (info)->dynobj;
6093 sgot = bfd_get_section_by_name (dynobj, ".got");
6094 splt = bfd_get_section_by_name (dynobj, ".plt");
6096 symtab_hdr = & elf_symtab_hdr (input_bfd);
6097 sym_hashes = elf_sym_hashes (input_bfd);
6098 local_got_offsets = elf_local_got_offsets (input_bfd);
6099 r_symndx = ELF32_R_SYM (rel->r_info);
6101 if (globals->use_rel)
6103 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
6105 if (addend & ((howto->src_mask + 1) >> 1))
6108 signed_addend &= ~ howto->src_mask;
6109 signed_addend |= addend;
6112 signed_addend = addend;
6115 addend = signed_addend = rel->r_addend;
6120 /* We don't need to find a value for this symbol. It's just a
6122 *unresolved_reloc_p = FALSE;
6123 return bfd_reloc_ok;
6126 if (!globals->vxworks_p)
6127 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6131 case R_ARM_ABS32_NOI:
6133 case R_ARM_REL32_NOI:
6139 /* Handle relocations which should use the PLT entry. ABS32/REL32
6140 will use the symbol's value, which may point to a PLT entry, but we
6141 don't need to handle that here. If we created a PLT entry, all
6142 branches in this object should go to it, except if the PLT is too
6143 far away, in which case a long branch stub should be inserted. */
6144 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
6145 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI
6146 && r_type != R_ARM_CALL)
6149 && h->plt.offset != (bfd_vma) -1)
6151 /* If we've created a .plt section, and assigned a PLT entry to
6152 this function, it should not be known to bind locally. If
6153 it were, we would have cleared the PLT entry. */
6154 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
6156 value = (splt->output_section->vma
6157 + splt->output_offset
6159 *unresolved_reloc_p = FALSE;
6160 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6161 contents, rel->r_offset, value,
6165 /* When generating a shared object or relocatable executable, these
6166 relocations are copied into the output file to be resolved at
6168 if ((info->shared || globals->root.is_relocatable_executable)
6169 && (input_section->flags & SEC_ALLOC)
6170 && !(elf32_arm_hash_table (info)->vxworks_p
6171 && strcmp (input_section->output_section->name,
6173 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
6174 || !SYMBOL_CALLS_LOCAL (info, h))
6176 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6177 || h->root.type != bfd_link_hash_undefweak)
6178 && r_type != R_ARM_PC24
6179 && r_type != R_ARM_CALL
6180 && r_type != R_ARM_JUMP24
6181 && r_type != R_ARM_PREL31
6182 && r_type != R_ARM_PLT32)
6184 Elf_Internal_Rela outrel;
6186 bfd_boolean skip, relocate;
6188 *unresolved_reloc_p = FALSE;
6192 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
6193 ! globals->use_rel);
6196 return bfd_reloc_notsupported;
6202 outrel.r_addend = addend;
6204 _bfd_elf_section_offset (output_bfd, info, input_section,
6206 if (outrel.r_offset == (bfd_vma) -1)
6208 else if (outrel.r_offset == (bfd_vma) -2)
6209 skip = TRUE, relocate = TRUE;
6210 outrel.r_offset += (input_section->output_section->vma
6211 + input_section->output_offset);
6214 memset (&outrel, 0, sizeof outrel);
6219 || !h->def_regular))
6220 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6225 /* This symbol is local, or marked to become local. */
6226 if (sym_flags == STT_ARM_TFUNC)
6228 if (globals->symbian_p)
6232 /* On Symbian OS, the data segment and text segement
6233 can be relocated independently. Therefore, we
6234 must indicate the segment to which this
6235 relocation is relative. The BPABI allows us to
6236 use any symbol in the right segment; we just use
6237 the section symbol as it is convenient. (We
6238 cannot use the symbol given by "h" directly as it
6239 will not appear in the dynamic symbol table.)
6241 Note that the dynamic linker ignores the section
6242 symbol value, so we don't subtract osec->vma
6243 from the emitted reloc addend. */
6245 osec = sym_sec->output_section;
6247 osec = input_section->output_section;
6248 symbol = elf_section_data (osec)->dynindx;
6251 struct elf_link_hash_table *htab = elf_hash_table (info);
6253 if ((osec->flags & SEC_READONLY) == 0
6254 && htab->data_index_section != NULL)
6255 osec = htab->data_index_section;
6257 osec = htab->text_index_section;
6258 symbol = elf_section_data (osec)->dynindx;
6260 BFD_ASSERT (symbol != 0);
6263 /* On SVR4-ish systems, the dynamic loader cannot
6264 relocate the text and data segments independently,
6265 so the symbol does not matter. */
6267 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
6268 if (globals->use_rel)
6271 outrel.r_addend += value;
6274 loc = sreloc->contents;
6275 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6276 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6278 /* If this reloc is against an external symbol, we do not want to
6279 fiddle with the addend. Otherwise, we need to include the symbol
6280 value so that it becomes an addend for the dynamic reloc. */
6282 return bfd_reloc_ok;
6284 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6285 contents, rel->r_offset, value,
6288 else switch (r_type)
6291 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6293 case R_ARM_XPC25: /* Arm BLX instruction. */
6296 case R_ARM_PC24: /* Arm B/BL instruction. */
6300 bfd_signed_vma branch_offset;
6301 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6303 if (r_type == R_ARM_XPC25)
6305 /* Check for Arm calling Arm function. */
6306 /* FIXME: Should we translate the instruction into a BL
6307 instruction instead ? */
6308 if (sym_flags != STT_ARM_TFUNC)
6309 (*_bfd_error_handler)
6310 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6312 h ? h->root.root.string : "(local)");
6314 else if (r_type != R_ARM_CALL)
6316 /* Check for Arm calling Thumb function. */
6317 if (sym_flags == STT_ARM_TFUNC)
6319 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6320 output_bfd, input_section,
6321 hit_data, sym_sec, rel->r_offset,
6322 signed_addend, value,
6324 return bfd_reloc_ok;
6326 return bfd_reloc_dangerous;
6330 /* Check if a stub has to be inserted because the
6331 destination is too far or we are changing mode. */
6332 if (r_type == R_ARM_CALL)
6334 /* If the call goes through a PLT entry, make sure to
6335 check distance to the right destination address. */
6336 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6338 value = (splt->output_section->vma
6339 + splt->output_offset
6341 *unresolved_reloc_p = FALSE;
6344 from = (input_section->output_section->vma
6345 + input_section->output_offset
6347 branch_offset = (bfd_signed_vma)(value - from);
6349 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6350 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6351 || sym_flags == STT_ARM_TFUNC)
6353 /* The target is out of reach, so redirect the
6354 branch to the local stub for this function. */
6356 stub_entry = elf32_arm_get_stub_entry (input_section,
6359 if (stub_entry != NULL)
6360 value = (stub_entry->stub_offset
6361 + stub_entry->stub_sec->output_offset
6362 + stub_entry->stub_sec->output_section->vma);
6366 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6368 S is the address of the symbol in the relocation.
6369 P is address of the instruction being relocated.
6370 A is the addend (extracted from the instruction) in bytes.
6372 S is held in 'value'.
6373 P is the base address of the section containing the
6374 instruction plus the offset of the reloc into that
6376 (input_section->output_section->vma +
6377 input_section->output_offset +
6379 A is the addend, converted into bytes, ie:
6382 Note: None of these operations have knowledge of the pipeline
6383 size of the processor, thus it is up to the assembler to
6384 encode this information into the addend. */
6385 value -= (input_section->output_section->vma
6386 + input_section->output_offset);
6387 value -= rel->r_offset;
6388 if (globals->use_rel)
6389 value += (signed_addend << howto->size);
6391 /* RELA addends do not have to be adjusted by howto->size. */
6392 value += signed_addend;
6394 signed_addend = value;
6395 signed_addend >>= howto->rightshift;
6397 /* A branch to an undefined weak symbol is turned into a jump to
6398 the next instruction unless a PLT entry will be created. */
6399 if (h && h->root.type == bfd_link_hash_undefweak
6400 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6402 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6407 /* Perform a signed range check. */
6408 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
6409 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6410 return bfd_reloc_overflow;
6412 addend = (value & 2);
6414 value = (signed_addend & howto->dst_mask)
6415 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
6417 /* Set the H bit in the BLX instruction. */
6418 if (sym_flags == STT_ARM_TFUNC)
6423 value &= ~(bfd_vma)(1 << 24);
6425 if (r_type == R_ARM_CALL)
6427 /* Select the correct instruction (BL or BLX). */
6428 /* Only if we are not handling a BL to a stub. In this
6429 case, mode switching is performed by the stub. */
6430 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
6434 value &= ~(bfd_vma)(1 << 28);
6444 if (sym_flags == STT_ARM_TFUNC)
6448 case R_ARM_ABS32_NOI:
6454 if (sym_flags == STT_ARM_TFUNC)
6456 value -= (input_section->output_section->vma
6457 + input_section->output_offset + rel->r_offset);
6460 case R_ARM_REL32_NOI:
6462 value -= (input_section->output_section->vma
6463 + input_section->output_offset + rel->r_offset);
6467 value -= (input_section->output_section->vma
6468 + input_section->output_offset + rel->r_offset);
6469 value += signed_addend;
6470 if (! h || h->root.type != bfd_link_hash_undefweak)
6472 /* Check for overflow. */
6473 if ((value ^ (value >> 1)) & (1 << 30))
6474 return bfd_reloc_overflow;
6476 value &= 0x7fffffff;
6477 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6478 if (sym_flags == STT_ARM_TFUNC)
6483 bfd_put_32 (input_bfd, value, hit_data);
6484 return bfd_reloc_ok;
6488 if ((long) value > 0x7f || (long) value < -0x80)
6489 return bfd_reloc_overflow;
6491 bfd_put_8 (input_bfd, value, hit_data);
6492 return bfd_reloc_ok;
6497 if ((long) value > 0x7fff || (long) value < -0x8000)
6498 return bfd_reloc_overflow;
6500 bfd_put_16 (input_bfd, value, hit_data);
6501 return bfd_reloc_ok;
6503 case R_ARM_THM_ABS5:
6504 /* Support ldr and str instructions for the thumb. */
6505 if (globals->use_rel)
6507 /* Need to refetch addend. */
6508 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6509 /* ??? Need to determine shift amount from operand size. */
6510 addend >>= howto->rightshift;
6514 /* ??? Isn't value unsigned? */
6515 if ((long) value > 0x1f || (long) value < -0x10)
6516 return bfd_reloc_overflow;
6518 /* ??? Value needs to be properly shifted into place first. */
6519 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6520 bfd_put_16 (input_bfd, value, hit_data);
6521 return bfd_reloc_ok;
6523 case R_ARM_THM_ALU_PREL_11_0:
6524 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6527 bfd_signed_vma relocation;
6529 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6530 | bfd_get_16 (input_bfd, hit_data + 2);
6532 if (globals->use_rel)
6534 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6535 | ((insn & (1 << 26)) >> 15);
6536 if (insn & 0xf00000)
6537 signed_addend = -signed_addend;
6540 relocation = value + signed_addend;
6541 relocation -= (input_section->output_section->vma
6542 + input_section->output_offset
6545 value = abs (relocation);
6547 if (value >= 0x1000)
6548 return bfd_reloc_overflow;
6550 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6551 | ((value & 0x700) << 4)
6552 | ((value & 0x800) << 15);
6556 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6557 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6559 return bfd_reloc_ok;
6562 case R_ARM_THM_PC12:
6563 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6566 bfd_signed_vma relocation;
6568 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6569 | bfd_get_16 (input_bfd, hit_data + 2);
6571 if (globals->use_rel)
6573 signed_addend = insn & 0xfff;
6574 if (!(insn & (1 << 23)))
6575 signed_addend = -signed_addend;
6578 relocation = value + signed_addend;
6579 relocation -= (input_section->output_section->vma
6580 + input_section->output_offset
6583 value = abs (relocation);
6585 if (value >= 0x1000)
6586 return bfd_reloc_overflow;
6588 insn = (insn & 0xff7ff000) | value;
6589 if (relocation >= 0)
6592 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6593 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6595 return bfd_reloc_ok;
6598 case R_ARM_THM_XPC22:
6599 case R_ARM_THM_CALL:
6600 case R_ARM_THM_JUMP24:
6601 /* Thumb BL (branch long instruction). */
6605 bfd_boolean overflow = FALSE;
6606 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6607 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6608 bfd_signed_vma reloc_signed_max;
6609 bfd_signed_vma reloc_signed_min;
6611 bfd_signed_vma signed_check;
6613 int thumb2 = using_thumb2 (globals);
6615 /* A branch to an undefined weak symbol is turned into a jump to
6616 the next instruction unless a PLT entry will be created. */
6617 if (h && h->root.type == bfd_link_hash_undefweak
6618 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6620 bfd_put_16 (input_bfd, 0xe000, hit_data);
6621 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6622 return bfd_reloc_ok;
6625 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6626 with Thumb-1) involving the J1 and J2 bits. */
6627 if (globals->use_rel)
6629 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6630 bfd_vma upper = upper_insn & 0x3ff;
6631 bfd_vma lower = lower_insn & 0x7ff;
6632 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6633 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6634 bfd_vma i1 = j1 ^ s ? 0 : 1;
6635 bfd_vma i2 = j2 ^ s ? 0 : 1;
6637 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6639 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6641 signed_addend = addend;
6644 if (r_type == R_ARM_THM_XPC22)
6646 /* Check for Thumb to Thumb call. */
6647 /* FIXME: Should we translate the instruction into a BL
6648 instruction instead ? */
6649 if (sym_flags == STT_ARM_TFUNC)
6650 (*_bfd_error_handler)
6651 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6653 h ? h->root.root.string : "(local)");
6657 /* If it is not a call to Thumb, assume call to Arm.
6658 If it is a call relative to a section name, then it is not a
6659 function call at all, but rather a long jump. Calls through
6660 the PLT do not require stubs. */
6661 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6662 && (h == NULL || splt == NULL
6663 || h->plt.offset == (bfd_vma) -1))
6665 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6667 /* Convert BL to BLX. */
6668 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6670 else if (r_type != R_ARM_THM_CALL)
6672 if (elf32_thumb_to_arm_stub
6673 (info, sym_name, input_bfd, output_bfd, input_section,
6674 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6676 return bfd_reloc_ok;
6678 return bfd_reloc_dangerous;
6681 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6682 && r_type == R_ARM_THM_CALL)
6684 /* Make sure this is a BL. */
6685 lower_insn |= 0x1800;
6689 /* Handle calls via the PLT. */
6690 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6692 value = (splt->output_section->vma
6693 + splt->output_offset
6695 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6697 /* If the Thumb BLX instruction is available, convert the
6698 BL to a BLX instruction to call the ARM-mode PLT entry. */
6699 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6702 /* Target the Thumb stub before the ARM PLT entry. */
6703 value -= PLT_THUMB_STUB_SIZE;
6704 *unresolved_reloc_p = FALSE;
6707 if (r_type == R_ARM_THM_CALL)
6709 /* Check if a stub has to be inserted because the destination
6712 bfd_signed_vma branch_offset;
6713 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6715 from = (input_section->output_section->vma
6716 + input_section->output_offset
6718 branch_offset = (bfd_signed_vma)(value - from);
6721 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6722 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6725 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
6726 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6727 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
6729 /* The target is out of reach or we are changing modes, so
6730 redirect the branch to the local stub for this
6732 stub_entry = elf32_arm_get_stub_entry (input_section,
6735 if (stub_entry != NULL)
6736 value = (stub_entry->stub_offset
6737 + stub_entry->stub_sec->output_offset
6738 + stub_entry->stub_sec->output_section->vma);
6740 /* If this call becomes a call to Arm, force BLX. */
6741 if (globals->use_blx)
6744 && !arm_stub_is_thumb (stub_entry->stub_type))
6745 || (sym_flags != STT_ARM_TFUNC))
6746 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6751 relocation = value + signed_addend;
6753 relocation -= (input_section->output_section->vma
6754 + input_section->output_offset
6757 check = relocation >> howto->rightshift;
6759 /* If this is a signed value, the rightshift just dropped
6760 leading 1 bits (assuming twos complement). */
6761 if ((bfd_signed_vma) relocation >= 0)
6762 signed_check = check;
6764 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6766 /* Calculate the permissable maximum and minimum values for
6767 this relocation according to whether we're relocating for
6769 bitsize = howto->bitsize;
6772 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6773 reloc_signed_min = ~reloc_signed_max;
6775 /* Assumes two's complement. */
6776 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6779 if ((lower_insn & 0x5000) == 0x4000)
6780 /* For a BLX instruction, make sure that the relocation is rounded up
6781 to a word boundary. This follows the semantics of the instruction
6782 which specifies that bit 1 of the target address will come from bit
6783 1 of the base address. */
6784 relocation = (relocation + 2) & ~ 3;
6786 /* Put RELOCATION back into the insn. Assumes two's complement.
6787 We use the Thumb-2 encoding, which is safe even if dealing with
6788 a Thumb-1 instruction by virtue of our overflow check above. */
6789 reloc_sign = (signed_check < 0) ? 1 : 0;
6790 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6791 | ((relocation >> 12) & 0x3ff)
6792 | (reloc_sign << 10);
6793 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
6794 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6795 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6796 | ((relocation >> 1) & 0x7ff);
6798 /* Put the relocated value back in the object file: */
6799 bfd_put_16 (input_bfd, upper_insn, hit_data);
6800 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6802 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6806 case R_ARM_THM_JUMP19:
6807 /* Thumb32 conditional branch instruction. */
6810 bfd_boolean overflow = FALSE;
6811 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6812 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6813 bfd_signed_vma reloc_signed_max = 0xffffe;
6814 bfd_signed_vma reloc_signed_min = -0x100000;
6815 bfd_signed_vma signed_check;
6817 /* Need to refetch the addend, reconstruct the top three bits,
6818 and squish the two 11 bit pieces together. */
6819 if (globals->use_rel)
6821 bfd_vma S = (upper_insn & 0x0400) >> 10;
6822 bfd_vma upper = (upper_insn & 0x003f);
6823 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6824 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6825 bfd_vma lower = (lower_insn & 0x07ff);
6830 upper -= 0x0100; /* Sign extend. */
6832 addend = (upper << 12) | (lower << 1);
6833 signed_addend = addend;
6836 /* Handle calls via the PLT. */
6837 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6839 value = (splt->output_section->vma
6840 + splt->output_offset
6842 /* Target the Thumb stub before the ARM PLT entry. */
6843 value -= PLT_THUMB_STUB_SIZE;
6844 *unresolved_reloc_p = FALSE;
6847 /* ??? Should handle interworking? GCC might someday try to
6848 use this for tail calls. */
6850 relocation = value + signed_addend;
6851 relocation -= (input_section->output_section->vma
6852 + input_section->output_offset
6854 signed_check = (bfd_signed_vma) relocation;
6856 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6859 /* Put RELOCATION back into the insn. */
6861 bfd_vma S = (relocation & 0x00100000) >> 20;
6862 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6863 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6864 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6865 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6867 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
6868 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6871 /* Put the relocated value back in the object file: */
6872 bfd_put_16 (input_bfd, upper_insn, hit_data);
6873 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6875 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6878 case R_ARM_THM_JUMP11:
6879 case R_ARM_THM_JUMP8:
6880 case R_ARM_THM_JUMP6:
6881 /* Thumb B (branch) instruction). */
6883 bfd_signed_vma relocation;
6884 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6885 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
6886 bfd_signed_vma signed_check;
6888 /* CZB cannot jump backward. */
6889 if (r_type == R_ARM_THM_JUMP6)
6890 reloc_signed_min = 0;
6892 if (globals->use_rel)
6894 /* Need to refetch addend. */
6895 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6896 if (addend & ((howto->src_mask + 1) >> 1))
6899 signed_addend &= ~ howto->src_mask;
6900 signed_addend |= addend;
6903 signed_addend = addend;
6904 /* The value in the insn has been right shifted. We need to
6905 undo this, so that we can perform the address calculation
6906 in terms of bytes. */
6907 signed_addend <<= howto->rightshift;
6909 relocation = value + signed_addend;
6911 relocation -= (input_section->output_section->vma
6912 + input_section->output_offset
6915 relocation >>= howto->rightshift;
6916 signed_check = relocation;
6918 if (r_type == R_ARM_THM_JUMP6)
6919 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6921 relocation &= howto->dst_mask;
6922 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
6924 bfd_put_16 (input_bfd, relocation, hit_data);
6926 /* Assumes two's complement. */
6927 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6928 return bfd_reloc_overflow;
6930 return bfd_reloc_ok;
6933 case R_ARM_ALU_PCREL7_0:
6934 case R_ARM_ALU_PCREL15_8:
6935 case R_ARM_ALU_PCREL23_15:
6940 insn = bfd_get_32 (input_bfd, hit_data);
6941 if (globals->use_rel)
6943 /* Extract the addend. */
6944 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6945 signed_addend = addend;
6947 relocation = value + signed_addend;
6949 relocation -= (input_section->output_section->vma
6950 + input_section->output_offset
6952 insn = (insn & ~0xfff)
6953 | ((howto->bitpos << 7) & 0xf00)
6954 | ((relocation >> howto->bitpos) & 0xff);
6955 bfd_put_32 (input_bfd, value, hit_data);
6957 return bfd_reloc_ok;
6959 case R_ARM_GNU_VTINHERIT:
6960 case R_ARM_GNU_VTENTRY:
6961 return bfd_reloc_ok;
6963 case R_ARM_GOTOFF32:
6964 /* Relocation is relative to the start of the
6965 global offset table. */
6967 BFD_ASSERT (sgot != NULL);
6969 return bfd_reloc_notsupported;
6971 /* If we are addressing a Thumb function, we need to adjust the
6972 address by one, so that attempts to call the function pointer will
6973 correctly interpret it as Thumb code. */
6974 if (sym_flags == STT_ARM_TFUNC)
6977 /* Note that sgot->output_offset is not involved in this
6978 calculation. We always want the start of .got. If we
6979 define _GLOBAL_OFFSET_TABLE in a different way, as is
6980 permitted by the ABI, we might have to change this
6982 value -= sgot->output_section->vma;
6983 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6984 contents, rel->r_offset, value,
6988 /* Use global offset table as symbol value. */
6989 BFD_ASSERT (sgot != NULL);
6992 return bfd_reloc_notsupported;
6994 *unresolved_reloc_p = FALSE;
6995 value = sgot->output_section->vma;
6996 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6997 contents, rel->r_offset, value,
7001 case R_ARM_GOT_PREL:
7002 /* Relocation is to the entry for this symbol in the
7003 global offset table. */
7005 return bfd_reloc_notsupported;
7012 off = h->got.offset;
7013 BFD_ASSERT (off != (bfd_vma) -1);
7014 dyn = globals->root.dynamic_sections_created;
7016 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7018 && SYMBOL_REFERENCES_LOCAL (info, h))
7019 || (ELF_ST_VISIBILITY (h->other)
7020 && h->root.type == bfd_link_hash_undefweak))
7022 /* This is actually a static link, or it is a -Bsymbolic link
7023 and the symbol is defined locally. We must initialize this
7024 entry in the global offset table. Since the offset must
7025 always be a multiple of 4, we use the least significant bit
7026 to record whether we have initialized it already.
7028 When doing a dynamic link, we create a .rel(a).got relocation
7029 entry to initialize the value. This is done in the
7030 finish_dynamic_symbol routine. */
7035 /* If we are addressing a Thumb function, we need to
7036 adjust the address by one, so that attempts to
7037 call the function pointer will correctly
7038 interpret it as Thumb code. */
7039 if (sym_flags == STT_ARM_TFUNC)
7042 bfd_put_32 (output_bfd, value, sgot->contents + off);
7047 *unresolved_reloc_p = FALSE;
7049 value = sgot->output_offset + off;
7055 BFD_ASSERT (local_got_offsets != NULL &&
7056 local_got_offsets[r_symndx] != (bfd_vma) -1);
7058 off = local_got_offsets[r_symndx];
7060 /* The offset must always be a multiple of 4. We use the
7061 least significant bit to record whether we have already
7062 generated the necessary reloc. */
7067 /* If we are addressing a Thumb function, we need to
7068 adjust the address by one, so that attempts to
7069 call the function pointer will correctly
7070 interpret it as Thumb code. */
7071 if (sym_flags == STT_ARM_TFUNC)
7074 if (globals->use_rel)
7075 bfd_put_32 (output_bfd, value, sgot->contents + off);
7080 Elf_Internal_Rela outrel;
7083 srelgot = (bfd_get_section_by_name
7084 (dynobj, RELOC_SECTION (globals, ".got")));
7085 BFD_ASSERT (srelgot != NULL);
7087 outrel.r_addend = addend + value;
7088 outrel.r_offset = (sgot->output_section->vma
7089 + sgot->output_offset
7091 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
7092 loc = srelgot->contents;
7093 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
7094 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7097 local_got_offsets[r_symndx] |= 1;
7100 value = sgot->output_offset + off;
7102 if (r_type != R_ARM_GOT32)
7103 value += sgot->output_section->vma;
7105 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7106 contents, rel->r_offset, value,
7109 case R_ARM_TLS_LDO32:
7110 value = value - dtpoff_base (info);
7112 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7113 contents, rel->r_offset, value,
7116 case R_ARM_TLS_LDM32:
7120 if (globals->sgot == NULL)
7123 off = globals->tls_ldm_got.offset;
7129 /* If we don't know the module number, create a relocation
7133 Elf_Internal_Rela outrel;
7136 if (globals->srelgot == NULL)
7139 outrel.r_addend = 0;
7140 outrel.r_offset = (globals->sgot->output_section->vma
7141 + globals->sgot->output_offset + off);
7142 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
7144 if (globals->use_rel)
7145 bfd_put_32 (output_bfd, outrel.r_addend,
7146 globals->sgot->contents + off);
7148 loc = globals->srelgot->contents;
7149 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
7150 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7153 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
7155 globals->tls_ldm_got.offset |= 1;
7158 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7159 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7161 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7162 contents, rel->r_offset, value,
7166 case R_ARM_TLS_GD32:
7167 case R_ARM_TLS_IE32:
7173 if (globals->sgot == NULL)
7180 dyn = globals->root.dynamic_sections_created;
7181 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7183 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7185 *unresolved_reloc_p = FALSE;
7188 off = h->got.offset;
7189 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
7193 if (local_got_offsets == NULL)
7195 off = local_got_offsets[r_symndx];
7196 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
7199 if (tls_type == GOT_UNKNOWN)
7206 bfd_boolean need_relocs = FALSE;
7207 Elf_Internal_Rela outrel;
7208 bfd_byte *loc = NULL;
7211 /* The GOT entries have not been initialized yet. Do it
7212 now, and emit any relocations. If both an IE GOT and a
7213 GD GOT are necessary, we emit the GD first. */
7215 if ((info->shared || indx != 0)
7217 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7218 || h->root.type != bfd_link_hash_undefweak))
7221 if (globals->srelgot == NULL)
7223 loc = globals->srelgot->contents;
7224 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
7227 if (tls_type & GOT_TLS_GD)
7231 outrel.r_addend = 0;
7232 outrel.r_offset = (globals->sgot->output_section->vma
7233 + globals->sgot->output_offset
7235 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
7237 if (globals->use_rel)
7238 bfd_put_32 (output_bfd, outrel.r_addend,
7239 globals->sgot->contents + cur_off);
7241 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7242 globals->srelgot->reloc_count++;
7243 loc += RELOC_SIZE (globals);
7246 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7247 globals->sgot->contents + cur_off + 4);
7250 outrel.r_addend = 0;
7251 outrel.r_info = ELF32_R_INFO (indx,
7252 R_ARM_TLS_DTPOFF32);
7253 outrel.r_offset += 4;
7255 if (globals->use_rel)
7256 bfd_put_32 (output_bfd, outrel.r_addend,
7257 globals->sgot->contents + cur_off + 4);
7260 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7261 globals->srelgot->reloc_count++;
7262 loc += RELOC_SIZE (globals);
7267 /* If we are not emitting relocations for a
7268 general dynamic reference, then we must be in a
7269 static link or an executable link with the
7270 symbol binding locally. Mark it as belonging
7271 to module 1, the executable. */
7272 bfd_put_32 (output_bfd, 1,
7273 globals->sgot->contents + cur_off);
7274 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7275 globals->sgot->contents + cur_off + 4);
7281 if (tls_type & GOT_TLS_IE)
7286 outrel.r_addend = value - dtpoff_base (info);
7288 outrel.r_addend = 0;
7289 outrel.r_offset = (globals->sgot->output_section->vma
7290 + globals->sgot->output_offset
7292 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7294 if (globals->use_rel)
7295 bfd_put_32 (output_bfd, outrel.r_addend,
7296 globals->sgot->contents + cur_off);
7298 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7299 globals->srelgot->reloc_count++;
7300 loc += RELOC_SIZE (globals);
7303 bfd_put_32 (output_bfd, tpoff (info, value),
7304 globals->sgot->contents + cur_off);
7311 local_got_offsets[r_symndx] |= 1;
7314 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7316 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7317 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7319 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7320 contents, rel->r_offset, value,
7324 case R_ARM_TLS_LE32:
7327 (*_bfd_error_handler)
7328 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7329 input_bfd, input_section,
7330 (long) rel->r_offset, howto->name);
7334 value = tpoff (info, value);
7336 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7337 contents, rel->r_offset, value,
7341 if (globals->fix_v4bx)
7343 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7345 /* Ensure that we have a BX instruction. */
7346 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
7348 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7350 /* Branch to veneer. */
7352 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7353 glue_addr -= input_section->output_section->vma
7354 + input_section->output_offset
7355 + rel->r_offset + 8;
7356 insn = (insn & 0xf0000000) | 0x0a000000
7357 | ((glue_addr >> 2) & 0x00ffffff);
7361 /* Preserve Rm (lowest four bits) and the condition code
7362 (highest four bits). Other bits encode MOV PC,Rm. */
7363 insn = (insn & 0xf000000f) | 0x01a0f000;
7366 bfd_put_32 (input_bfd, insn, hit_data);
7368 return bfd_reloc_ok;
7370 case R_ARM_MOVW_ABS_NC:
7371 case R_ARM_MOVT_ABS:
7372 case R_ARM_MOVW_PREL_NC:
7373 case R_ARM_MOVT_PREL:
7374 /* Until we properly support segment-base-relative addressing then
7375 we assume the segment base to be zero, as for the group relocations.
7376 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7377 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7378 case R_ARM_MOVW_BREL_NC:
7379 case R_ARM_MOVW_BREL:
7380 case R_ARM_MOVT_BREL:
7382 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7384 if (globals->use_rel)
7386 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
7387 signed_addend = (addend ^ 0x8000) - 0x8000;
7390 value += signed_addend;
7392 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7393 value -= (input_section->output_section->vma
7394 + input_section->output_offset + rel->r_offset);
7396 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7397 return bfd_reloc_overflow;
7399 if (sym_flags == STT_ARM_TFUNC)
7402 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7403 || r_type == R_ARM_MOVT_BREL)
7407 insn |= value & 0xfff;
7408 insn |= (value & 0xf000) << 4;
7409 bfd_put_32 (input_bfd, insn, hit_data);
7411 return bfd_reloc_ok;
7413 case R_ARM_THM_MOVW_ABS_NC:
7414 case R_ARM_THM_MOVT_ABS:
7415 case R_ARM_THM_MOVW_PREL_NC:
7416 case R_ARM_THM_MOVT_PREL:
7417 /* Until we properly support segment-base-relative addressing then
7418 we assume the segment base to be zero, as for the above relocations.
7419 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7420 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7421 as R_ARM_THM_MOVT_ABS. */
7422 case R_ARM_THM_MOVW_BREL_NC:
7423 case R_ARM_THM_MOVW_BREL:
7424 case R_ARM_THM_MOVT_BREL:
7428 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7429 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7431 if (globals->use_rel)
7433 addend = ((insn >> 4) & 0xf000)
7434 | ((insn >> 15) & 0x0800)
7435 | ((insn >> 4) & 0x0700)
7437 signed_addend = (addend ^ 0x8000) - 0x8000;
7440 value += signed_addend;
7442 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7443 value -= (input_section->output_section->vma
7444 + input_section->output_offset + rel->r_offset);
7446 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7447 return bfd_reloc_overflow;
7449 if (sym_flags == STT_ARM_TFUNC)
7452 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7453 || r_type == R_ARM_THM_MOVT_BREL)
7457 insn |= (value & 0xf000) << 4;
7458 insn |= (value & 0x0800) << 15;
7459 insn |= (value & 0x0700) << 4;
7460 insn |= (value & 0x00ff);
7462 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7463 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7465 return bfd_reloc_ok;
7467 case R_ARM_ALU_PC_G0_NC:
7468 case R_ARM_ALU_PC_G1_NC:
7469 case R_ARM_ALU_PC_G0:
7470 case R_ARM_ALU_PC_G1:
7471 case R_ARM_ALU_PC_G2:
7472 case R_ARM_ALU_SB_G0_NC:
7473 case R_ARM_ALU_SB_G1_NC:
7474 case R_ARM_ALU_SB_G0:
7475 case R_ARM_ALU_SB_G1:
7476 case R_ARM_ALU_SB_G2:
7478 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7479 bfd_vma pc = input_section->output_section->vma
7480 + input_section->output_offset + rel->r_offset;
7481 /* sb should be the origin of the *segment* containing the symbol.
7482 It is not clear how to obtain this OS-dependent value, so we
7483 make an arbitrary choice of zero. */
7487 bfd_signed_vma signed_value;
7490 /* Determine which group of bits to select. */
7493 case R_ARM_ALU_PC_G0_NC:
7494 case R_ARM_ALU_PC_G0:
7495 case R_ARM_ALU_SB_G0_NC:
7496 case R_ARM_ALU_SB_G0:
7500 case R_ARM_ALU_PC_G1_NC:
7501 case R_ARM_ALU_PC_G1:
7502 case R_ARM_ALU_SB_G1_NC:
7503 case R_ARM_ALU_SB_G1:
7507 case R_ARM_ALU_PC_G2:
7508 case R_ARM_ALU_SB_G2:
7516 /* If REL, extract the addend from the insn. If RELA, it will
7517 have already been fetched for us. */
7518 if (globals->use_rel)
7521 bfd_vma constant = insn & 0xff;
7522 bfd_vma rotation = (insn & 0xf00) >> 8;
7525 signed_addend = constant;
7528 /* Compensate for the fact that in the instruction, the
7529 rotation is stored in multiples of 2 bits. */
7532 /* Rotate "constant" right by "rotation" bits. */
7533 signed_addend = (constant >> rotation) |
7534 (constant << (8 * sizeof (bfd_vma) - rotation));
7537 /* Determine if the instruction is an ADD or a SUB.
7538 (For REL, this determines the sign of the addend.) */
7539 negative = identify_add_or_sub (insn);
7542 (*_bfd_error_handler)
7543 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7544 input_bfd, input_section,
7545 (long) rel->r_offset, howto->name);
7546 return bfd_reloc_overflow;
7549 signed_addend *= negative;
7552 /* Compute the value (X) to go in the place. */
7553 if (r_type == R_ARM_ALU_PC_G0_NC
7554 || r_type == R_ARM_ALU_PC_G1_NC
7555 || r_type == R_ARM_ALU_PC_G0
7556 || r_type == R_ARM_ALU_PC_G1
7557 || r_type == R_ARM_ALU_PC_G2)
7559 signed_value = value - pc + signed_addend;
7561 /* Section base relative. */
7562 signed_value = value - sb + signed_addend;
7564 /* If the target symbol is a Thumb function, then set the
7565 Thumb bit in the address. */
7566 if (sym_flags == STT_ARM_TFUNC)
7569 /* Calculate the value of the relevant G_n, in encoded
7570 constant-with-rotation format. */
7571 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7574 /* Check for overflow if required. */
7575 if ((r_type == R_ARM_ALU_PC_G0
7576 || r_type == R_ARM_ALU_PC_G1
7577 || r_type == R_ARM_ALU_PC_G2
7578 || r_type == R_ARM_ALU_SB_G0
7579 || r_type == R_ARM_ALU_SB_G1
7580 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7582 (*_bfd_error_handler)
7583 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7584 input_bfd, input_section,
7585 (long) rel->r_offset, abs (signed_value), howto->name);
7586 return bfd_reloc_overflow;
7589 /* Mask out the value and the ADD/SUB part of the opcode; take care
7590 not to destroy the S bit. */
7593 /* Set the opcode according to whether the value to go in the
7594 place is negative. */
7595 if (signed_value < 0)
7600 /* Encode the offset. */
7603 bfd_put_32 (input_bfd, insn, hit_data);
7605 return bfd_reloc_ok;
7607 case R_ARM_LDR_PC_G0:
7608 case R_ARM_LDR_PC_G1:
7609 case R_ARM_LDR_PC_G2:
7610 case R_ARM_LDR_SB_G0:
7611 case R_ARM_LDR_SB_G1:
7612 case R_ARM_LDR_SB_G2:
7614 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7615 bfd_vma pc = input_section->output_section->vma
7616 + input_section->output_offset + rel->r_offset;
7617 bfd_vma sb = 0; /* See note above. */
7619 bfd_signed_vma signed_value;
7622 /* Determine which groups of bits to calculate. */
7625 case R_ARM_LDR_PC_G0:
7626 case R_ARM_LDR_SB_G0:
7630 case R_ARM_LDR_PC_G1:
7631 case R_ARM_LDR_SB_G1:
7635 case R_ARM_LDR_PC_G2:
7636 case R_ARM_LDR_SB_G2:
7644 /* If REL, extract the addend from the insn. If RELA, it will
7645 have already been fetched for us. */
7646 if (globals->use_rel)
7648 int negative = (insn & (1 << 23)) ? 1 : -1;
7649 signed_addend = negative * (insn & 0xfff);
7652 /* Compute the value (X) to go in the place. */
7653 if (r_type == R_ARM_LDR_PC_G0
7654 || r_type == R_ARM_LDR_PC_G1
7655 || r_type == R_ARM_LDR_PC_G2)
7657 signed_value = value - pc + signed_addend;
7659 /* Section base relative. */
7660 signed_value = value - sb + signed_addend;
7662 /* Calculate the value of the relevant G_{n-1} to obtain
7663 the residual at that stage. */
7664 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7666 /* Check for overflow. */
7667 if (residual >= 0x1000)
7669 (*_bfd_error_handler)
7670 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7671 input_bfd, input_section,
7672 (long) rel->r_offset, abs (signed_value), howto->name);
7673 return bfd_reloc_overflow;
7676 /* Mask out the value and U bit. */
7679 /* Set the U bit if the value to go in the place is non-negative. */
7680 if (signed_value >= 0)
7683 /* Encode the offset. */
7686 bfd_put_32 (input_bfd, insn, hit_data);
7688 return bfd_reloc_ok;
7690 case R_ARM_LDRS_PC_G0:
7691 case R_ARM_LDRS_PC_G1:
7692 case R_ARM_LDRS_PC_G2:
7693 case R_ARM_LDRS_SB_G0:
7694 case R_ARM_LDRS_SB_G1:
7695 case R_ARM_LDRS_SB_G2:
7697 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7698 bfd_vma pc = input_section->output_section->vma
7699 + input_section->output_offset + rel->r_offset;
7700 bfd_vma sb = 0; /* See note above. */
7702 bfd_signed_vma signed_value;
7705 /* Determine which groups of bits to calculate. */
7708 case R_ARM_LDRS_PC_G0:
7709 case R_ARM_LDRS_SB_G0:
7713 case R_ARM_LDRS_PC_G1:
7714 case R_ARM_LDRS_SB_G1:
7718 case R_ARM_LDRS_PC_G2:
7719 case R_ARM_LDRS_SB_G2:
7727 /* If REL, extract the addend from the insn. If RELA, it will
7728 have already been fetched for us. */
7729 if (globals->use_rel)
7731 int negative = (insn & (1 << 23)) ? 1 : -1;
7732 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7735 /* Compute the value (X) to go in the place. */
7736 if (r_type == R_ARM_LDRS_PC_G0
7737 || r_type == R_ARM_LDRS_PC_G1
7738 || r_type == R_ARM_LDRS_PC_G2)
7740 signed_value = value - pc + signed_addend;
7742 /* Section base relative. */
7743 signed_value = value - sb + signed_addend;
7745 /* Calculate the value of the relevant G_{n-1} to obtain
7746 the residual at that stage. */
7747 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7749 /* Check for overflow. */
7750 if (residual >= 0x100)
7752 (*_bfd_error_handler)
7753 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7754 input_bfd, input_section,
7755 (long) rel->r_offset, abs (signed_value), howto->name);
7756 return bfd_reloc_overflow;
7759 /* Mask out the value and U bit. */
7762 /* Set the U bit if the value to go in the place is non-negative. */
7763 if (signed_value >= 0)
7766 /* Encode the offset. */
7767 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7769 bfd_put_32 (input_bfd, insn, hit_data);
7771 return bfd_reloc_ok;
7773 case R_ARM_LDC_PC_G0:
7774 case R_ARM_LDC_PC_G1:
7775 case R_ARM_LDC_PC_G2:
7776 case R_ARM_LDC_SB_G0:
7777 case R_ARM_LDC_SB_G1:
7778 case R_ARM_LDC_SB_G2:
7780 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7781 bfd_vma pc = input_section->output_section->vma
7782 + input_section->output_offset + rel->r_offset;
7783 bfd_vma sb = 0; /* See note above. */
7785 bfd_signed_vma signed_value;
7788 /* Determine which groups of bits to calculate. */
7791 case R_ARM_LDC_PC_G0:
7792 case R_ARM_LDC_SB_G0:
7796 case R_ARM_LDC_PC_G1:
7797 case R_ARM_LDC_SB_G1:
7801 case R_ARM_LDC_PC_G2:
7802 case R_ARM_LDC_SB_G2:
7810 /* If REL, extract the addend from the insn. If RELA, it will
7811 have already been fetched for us. */
7812 if (globals->use_rel)
7814 int negative = (insn & (1 << 23)) ? 1 : -1;
7815 signed_addend = negative * ((insn & 0xff) << 2);
7818 /* Compute the value (X) to go in the place. */
7819 if (r_type == R_ARM_LDC_PC_G0
7820 || r_type == R_ARM_LDC_PC_G1
7821 || r_type == R_ARM_LDC_PC_G2)
7823 signed_value = value - pc + signed_addend;
7825 /* Section base relative. */
7826 signed_value = value - sb + signed_addend;
7828 /* Calculate the value of the relevant G_{n-1} to obtain
7829 the residual at that stage. */
7830 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7832 /* Check for overflow. (The absolute value to go in the place must be
7833 divisible by four and, after having been divided by four, must
7834 fit in eight bits.) */
7835 if ((residual & 0x3) != 0 || residual >= 0x400)
7837 (*_bfd_error_handler)
7838 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7839 input_bfd, input_section,
7840 (long) rel->r_offset, abs (signed_value), howto->name);
7841 return bfd_reloc_overflow;
7844 /* Mask out the value and U bit. */
7847 /* Set the U bit if the value to go in the place is non-negative. */
7848 if (signed_value >= 0)
7851 /* Encode the offset. */
7852 insn |= residual >> 2;
7854 bfd_put_32 (input_bfd, insn, hit_data);
7856 return bfd_reloc_ok;
7859 return bfd_reloc_notsupported;
7863 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7865 arm_add_to_rel (bfd * abfd,
7867 reloc_howto_type * howto,
7868 bfd_signed_vma increment)
7870 bfd_signed_vma addend;
7872 if (howto->type == R_ARM_THM_CALL
7873 || howto->type == R_ARM_THM_JUMP24)
7875 int upper_insn, lower_insn;
7878 upper_insn = bfd_get_16 (abfd, address);
7879 lower_insn = bfd_get_16 (abfd, address + 2);
7880 upper = upper_insn & 0x7ff;
7881 lower = lower_insn & 0x7ff;
7883 addend = (upper << 12) | (lower << 1);
7884 addend += increment;
7887 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7888 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7890 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7891 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
7897 contents = bfd_get_32 (abfd, address);
7899 /* Get the (signed) value from the instruction. */
7900 addend = contents & howto->src_mask;
7901 if (addend & ((howto->src_mask + 1) >> 1))
7903 bfd_signed_vma mask;
7906 mask &= ~ howto->src_mask;
7910 /* Add in the increment, (which is a byte value). */
7911 switch (howto->type)
7914 addend += increment;
7921 addend <<= howto->size;
7922 addend += increment;
7924 /* Should we check for overflow here ? */
7926 /* Drop any undesired bits. */
7927 addend >>= howto->rightshift;
7931 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7933 bfd_put_32 (abfd, contents, address);
7937 #define IS_ARM_TLS_RELOC(R_TYPE) \
7938 ((R_TYPE) == R_ARM_TLS_GD32 \
7939 || (R_TYPE) == R_ARM_TLS_LDO32 \
7940 || (R_TYPE) == R_ARM_TLS_LDM32 \
7941 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7942 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7943 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7944 || (R_TYPE) == R_ARM_TLS_LE32 \
7945 || (R_TYPE) == R_ARM_TLS_IE32)
7947 /* Relocate an ARM ELF section. */
7950 elf32_arm_relocate_section (bfd * output_bfd,
7951 struct bfd_link_info * info,
7953 asection * input_section,
7954 bfd_byte * contents,
7955 Elf_Internal_Rela * relocs,
7956 Elf_Internal_Sym * local_syms,
7957 asection ** local_sections)
7959 Elf_Internal_Shdr *symtab_hdr;
7960 struct elf_link_hash_entry **sym_hashes;
7961 Elf_Internal_Rela *rel;
7962 Elf_Internal_Rela *relend;
7964 struct elf32_arm_link_hash_table * globals;
7966 globals = elf32_arm_hash_table (info);
7968 symtab_hdr = & elf_symtab_hdr (input_bfd);
7969 sym_hashes = elf_sym_hashes (input_bfd);
7972 relend = relocs + input_section->reloc_count;
7973 for (; rel < relend; rel++)
7976 reloc_howto_type * howto;
7977 unsigned long r_symndx;
7978 Elf_Internal_Sym * sym;
7980 struct elf_link_hash_entry * h;
7982 bfd_reloc_status_type r;
7985 bfd_boolean unresolved_reloc = FALSE;
7986 char *error_message = NULL;
7988 r_symndx = ELF32_R_SYM (rel->r_info);
7989 r_type = ELF32_R_TYPE (rel->r_info);
7990 r_type = arm_real_reloc_type (globals, r_type);
7992 if ( r_type == R_ARM_GNU_VTENTRY
7993 || r_type == R_ARM_GNU_VTINHERIT)
7996 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
7997 howto = bfd_reloc.howto;
8003 if (r_symndx < symtab_hdr->sh_info)
8005 sym = local_syms + r_symndx;
8006 sym_type = ELF32_ST_TYPE (sym->st_info);
8007 sec = local_sections[r_symndx];
8008 if (globals->use_rel)
8010 relocation = (sec->output_section->vma
8011 + sec->output_offset
8013 if (!info->relocatable
8014 && (sec->flags & SEC_MERGE)
8015 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8018 bfd_vma addend, value;
8022 case R_ARM_MOVW_ABS_NC:
8023 case R_ARM_MOVT_ABS:
8024 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
8025 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
8026 addend = (addend ^ 0x8000) - 0x8000;
8029 case R_ARM_THM_MOVW_ABS_NC:
8030 case R_ARM_THM_MOVT_ABS:
8031 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
8033 value |= bfd_get_16 (input_bfd,
8034 contents + rel->r_offset + 2);
8035 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
8036 | ((value & 0x04000000) >> 15);
8037 addend = (addend ^ 0x8000) - 0x8000;
8041 if (howto->rightshift
8042 || (howto->src_mask & (howto->src_mask + 1)))
8044 (*_bfd_error_handler)
8045 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
8046 input_bfd, input_section,
8047 (long) rel->r_offset, howto->name);
8051 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
8053 /* Get the (signed) value from the instruction. */
8054 addend = value & howto->src_mask;
8055 if (addend & ((howto->src_mask + 1) >> 1))
8057 bfd_signed_vma mask;
8060 mask &= ~ howto->src_mask;
8068 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
8070 addend += msec->output_section->vma + msec->output_offset;
8072 /* Cases here must match those in the preceeding
8073 switch statement. */
8076 case R_ARM_MOVW_ABS_NC:
8077 case R_ARM_MOVT_ABS:
8078 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
8080 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8083 case R_ARM_THM_MOVW_ABS_NC:
8084 case R_ARM_THM_MOVT_ABS:
8085 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
8086 | (addend & 0xff) | ((addend & 0x0800) << 15);
8087 bfd_put_16 (input_bfd, value >> 16,
8088 contents + rel->r_offset);
8089 bfd_put_16 (input_bfd, value,
8090 contents + rel->r_offset + 2);
8094 value = (value & ~ howto->dst_mask)
8095 | (addend & howto->dst_mask);
8096 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8102 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
8108 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
8109 r_symndx, symtab_hdr, sym_hashes,
8111 unresolved_reloc, warned);
8116 if (sec != NULL && elf_discarded_section (sec))
8118 /* For relocs against symbols from removed linkonce sections,
8119 or sections discarded by a linker script, we just want the
8120 section contents zeroed. Avoid any special processing. */
8121 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
8127 if (info->relocatable)
8129 /* This is a relocatable link. We don't have to change
8130 anything, unless the reloc is against a section symbol,
8131 in which case we have to adjust according to where the
8132 section symbol winds up in the output section. */
8133 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8135 if (globals->use_rel)
8136 arm_add_to_rel (input_bfd, contents + rel->r_offset,
8137 howto, (bfd_signed_vma) sec->output_offset);
8139 rel->r_addend += sec->output_offset;
8145 name = h->root.root.string;
8148 name = (bfd_elf_string_from_elf_section
8149 (input_bfd, symtab_hdr->sh_link, sym->st_name));
8150 if (name == NULL || *name == '\0')
8151 name = bfd_section_name (input_bfd, sec);
8155 && r_type != R_ARM_NONE
8157 || h->root.type == bfd_link_hash_defined
8158 || h->root.type == bfd_link_hash_defweak)
8159 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
8161 (*_bfd_error_handler)
8162 ((sym_type == STT_TLS
8163 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8164 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8167 (long) rel->r_offset,
8172 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
8173 input_section, contents, rel,
8174 relocation, info, sec, name,
8175 (h ? ELF_ST_TYPE (h->type) :
8176 ELF_ST_TYPE (sym->st_info)), h,
8177 &unresolved_reloc, &error_message);
8179 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8180 because such sections are not SEC_ALLOC and thus ld.so will
8181 not process them. */
8182 if (unresolved_reloc
8183 && !((input_section->flags & SEC_DEBUGGING) != 0
8186 (*_bfd_error_handler)
8187 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8190 (long) rel->r_offset,
8192 h->root.root.string);
8196 if (r != bfd_reloc_ok)
8200 case bfd_reloc_overflow:
8201 /* If the overflowing reloc was to an undefined symbol,
8202 we have already printed one error message and there
8203 is no point complaining again. */
8205 h->root.type != bfd_link_hash_undefined)
8206 && (!((*info->callbacks->reloc_overflow)
8207 (info, (h ? &h->root : NULL), name, howto->name,
8208 (bfd_vma) 0, input_bfd, input_section,
8213 case bfd_reloc_undefined:
8214 if (!((*info->callbacks->undefined_symbol)
8215 (info, name, input_bfd, input_section,
8216 rel->r_offset, TRUE)))
8220 case bfd_reloc_outofrange:
8221 error_message = _("out of range");
8224 case bfd_reloc_notsupported:
8225 error_message = _("unsupported relocation");
8228 case bfd_reloc_dangerous:
8229 /* error_message should already be set. */
8233 error_message = _("unknown error");
8237 BFD_ASSERT (error_message != NULL);
8238 if (!((*info->callbacks->reloc_dangerous)
8239 (info, error_message, input_bfd, input_section,
8251 elf32_arm_output_glue_section (struct bfd_link_info *info, bfd *obfd,
8252 bfd *ibfd, const char *name)
8254 asection *sec, *osec;
8256 sec = bfd_get_section_by_name (ibfd, name);
8257 if (sec == NULL || (sec->flags & SEC_EXCLUDE) != 0)
8260 osec = sec->output_section;
8261 if (elf32_arm_write_section (obfd, info, sec, sec->contents))
8264 if (! bfd_set_section_contents (obfd, osec, sec->contents,
8265 sec->output_offset, sec->size))
8272 elf32_arm_final_link (bfd *abfd, struct bfd_link_info *info)
8274 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
8276 /* Invoke the regular ELF backend linker to do all the work. */
8277 if (!bfd_elf_final_link (abfd, info))
8280 /* Write out any glue sections now that we have created all the
8282 if (globals->bfd_of_glue_owner != NULL)
8284 if (! elf32_arm_output_glue_section (info, abfd,
8285 globals->bfd_of_glue_owner,
8286 ARM2THUMB_GLUE_SECTION_NAME))
8289 if (! elf32_arm_output_glue_section (info, abfd,
8290 globals->bfd_of_glue_owner,
8291 THUMB2ARM_GLUE_SECTION_NAME))
8294 if (! elf32_arm_output_glue_section (info, abfd,
8295 globals->bfd_of_glue_owner,
8296 VFP11_ERRATUM_VENEER_SECTION_NAME))
8299 if (! elf32_arm_output_glue_section (info, abfd,
8300 globals->bfd_of_glue_owner,
8301 ARM_BX_GLUE_SECTION_NAME))
8308 /* Set the right machine number. */
8311 elf32_arm_object_p (bfd *abfd)
8315 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
8317 if (mach != bfd_mach_arm_unknown)
8318 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8320 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8321 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
8324 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8329 /* Function to keep ARM specific flags in the ELF header. */
8332 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
8334 if (elf_flags_init (abfd)
8335 && elf_elfheader (abfd)->e_flags != flags)
8337 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8339 if (flags & EF_ARM_INTERWORK)
8340 (*_bfd_error_handler)
8341 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8345 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8351 elf_elfheader (abfd)->e_flags = flags;
8352 elf_flags_init (abfd) = TRUE;
8358 /* Copy backend specific data from one object module to another. */
8361 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
8366 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8369 in_flags = elf_elfheader (ibfd)->e_flags;
8370 out_flags = elf_elfheader (obfd)->e_flags;
8372 if (elf_flags_init (obfd)
8373 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8374 && in_flags != out_flags)
8376 /* Cannot mix APCS26 and APCS32 code. */
8377 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8380 /* Cannot mix float APCS and non-float APCS code. */
8381 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8384 /* If the src and dest have different interworking flags
8385 then turn off the interworking bit. */
8386 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8388 if (out_flags & EF_ARM_INTERWORK)
8390 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8393 in_flags &= ~EF_ARM_INTERWORK;
8396 /* Likewise for PIC, though don't warn for this case. */
8397 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8398 in_flags &= ~EF_ARM_PIC;
8401 elf_elfheader (obfd)->e_flags = in_flags;
8402 elf_flags_init (obfd) = TRUE;
8404 /* Also copy the EI_OSABI field. */
8405 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8406 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8408 /* Copy object attributes. */
8409 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8414 /* Values for Tag_ABI_PCS_R9_use. */
8423 /* Values for Tag_ABI_PCS_RW_data. */
8426 AEABI_PCS_RW_data_absolute,
8427 AEABI_PCS_RW_data_PCrel,
8428 AEABI_PCS_RW_data_SBrel,
8429 AEABI_PCS_RW_data_unused
8432 /* Values for Tag_ABI_enum_size. */
8438 AEABI_enum_forced_wide
8441 /* Determine whether an object attribute tag takes an integer, a
8445 elf32_arm_obj_attrs_arg_type (int tag)
8447 if (tag == Tag_compatibility)
8448 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
8449 else if (tag == Tag_nodefaults)
8450 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
8451 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
8452 return ATTR_TYPE_FLAG_STR_VAL;
8454 return ATTR_TYPE_FLAG_INT_VAL;
8456 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
8459 /* The ABI defines that Tag_conformance should be emitted first, and that
8460 Tag_nodefaults should be second (if either is defined). This sets those
8461 two positions, and bumps up the position of all the remaining tags to
8464 elf32_arm_obj_attrs_order (int num)
8467 return Tag_conformance;
8469 return Tag_nodefaults;
8470 if ((num - 2) < Tag_nodefaults)
8472 if ((num - 1) < Tag_conformance)
8477 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
8478 Returns -1 if no architecture could be read. */
8481 get_secondary_compatible_arch (bfd *abfd)
8483 obj_attribute *attr =
8484 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8486 /* Note: the tag and its argument below are uleb128 values, though
8487 currently-defined values fit in one byte for each. */
8489 && attr->s[0] == Tag_CPU_arch
8490 && (attr->s[1] & 128) != 128
8494 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8498 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8499 The tag is removed if ARCH is -1. */
8502 set_secondary_compatible_arch (bfd *abfd, int arch)
8504 obj_attribute *attr =
8505 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8513 /* Note: the tag and its argument below are uleb128 values, though
8514 currently-defined values fit in one byte for each. */
8516 attr->s = bfd_alloc (abfd, 3);
8517 attr->s[0] = Tag_CPU_arch;
8522 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8526 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
8527 int newtag, int secondary_compat)
8529 #define T(X) TAG_CPU_ARCH_##X
8530 int tagl, tagh, result;
8533 T(V6T2), /* PRE_V4. */
8537 T(V6T2), /* V5TE. */
8538 T(V6T2), /* V5TEJ. */
8545 T(V6K), /* PRE_V4. */
8550 T(V6K), /* V5TEJ. */
8552 T(V6KZ), /* V6KZ. */
8558 T(V7), /* PRE_V4. */
8577 T(V6K), /* V5TEJ. */
8579 T(V6KZ), /* V6KZ. */
8592 T(V6K), /* V5TEJ. */
8594 T(V6KZ), /* V6KZ. */
8598 T(V6S_M), /* V6_M. */
8599 T(V6S_M) /* V6S_M. */
8601 const int v4t_plus_v6_m[] =
8607 T(V5TE), /* V5TE. */
8608 T(V5TEJ), /* V5TEJ. */
8610 T(V6KZ), /* V6KZ. */
8611 T(V6T2), /* V6T2. */
8614 T(V6_M), /* V6_M. */
8615 T(V6S_M), /* V6S_M. */
8616 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
8625 /* Pseudo-architecture. */
8629 /* Check we've not got a higher architecture than we know about. */
8631 if (oldtag >= MAX_TAG_CPU_ARCH || newtag >= MAX_TAG_CPU_ARCH)
8633 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd);
8637 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8639 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
8640 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
8641 oldtag = T(V4T_PLUS_V6_M);
8643 /* And override the new tag if we have a Tag_also_compatible_with on the
8646 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
8647 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
8648 newtag = T(V4T_PLUS_V6_M);
8650 tagl = (oldtag < newtag) ? oldtag : newtag;
8651 result = tagh = (oldtag > newtag) ? oldtag : newtag;
8653 /* Architectures before V6KZ add features monotonically. */
8654 if (tagh <= TAG_CPU_ARCH_V6KZ)
8657 result = comb[tagh - T(V6T2)][tagl];
8659 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8660 as the canonical version. */
8661 if (result == T(V4T_PLUS_V6_M))
8664 *secondary_compat_out = T(V6_M);
8667 *secondary_compat_out = -1;
8671 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
8672 ibfd, oldtag, newtag);
8680 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8681 are conflicting attributes. */
8684 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8686 obj_attribute *in_attr;
8687 obj_attribute *out_attr;
8688 obj_attribute_list *in_list;
8689 obj_attribute_list *out_list;
8690 obj_attribute_list **out_listp;
8691 /* Some tags have 0 = don't care, 1 = strong requirement,
8692 2 = weak requirement. */
8693 static const int order_021[3] = {0, 2, 1};
8694 /* For use with Tag_VFP_arch. */
8695 static const int order_01243[5] = {0, 1, 2, 4, 3};
8697 bfd_boolean result = TRUE;
8699 /* Skip the linker stubs file. This preserves previous behavior
8700 of accepting unknown attributes in the first input file - but
8702 if (ibfd->flags & BFD_LINKER_CREATED)
8705 if (!elf_known_obj_attributes_proc (obfd)[0].i)
8707 /* This is the first object. Copy the attributes. */
8708 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8710 /* Use the Tag_null value to indicate the attributes have been
8712 elf_known_obj_attributes_proc (obfd)[0].i = 1;
8717 in_attr = elf_known_obj_attributes_proc (ibfd);
8718 out_attr = elf_known_obj_attributes_proc (obfd);
8719 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8720 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8722 /* Ignore mismatches if the object doesn't use floating point. */
8723 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8724 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8725 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8728 (_("error: %B uses VFP register arguments, %B does not"),
8734 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
8736 /* Merge this attribute with existing attributes. */
8739 case Tag_CPU_raw_name:
8741 /* These are merged after Tag_CPU_arch. */
8744 case Tag_ABI_optimization_goals:
8745 case Tag_ABI_FP_optimization_goals:
8746 /* Use the first value seen. */
8751 int secondary_compat = -1, secondary_compat_out = -1;
8752 unsigned int saved_out_attr = out_attr[i].i;
8753 static const char *name_table[] = {
8754 /* These aren't real CPU names, but we can't guess
8755 that from the architecture version alone. */
8771 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8772 secondary_compat = get_secondary_compatible_arch (ibfd);
8773 secondary_compat_out = get_secondary_compatible_arch (obfd);
8774 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
8775 &secondary_compat_out,
8778 set_secondary_compatible_arch (obfd, secondary_compat_out);
8780 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8781 if (out_attr[i].i == saved_out_attr)
8782 ; /* Leave the names alone. */
8783 else if (out_attr[i].i == in_attr[i].i)
8785 /* The output architecture has been changed to match the
8786 input architecture. Use the input names. */
8787 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
8788 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
8790 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
8791 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
8796 out_attr[Tag_CPU_name].s = NULL;
8797 out_attr[Tag_CPU_raw_name].s = NULL;
8800 /* If we still don't have a value for Tag_CPU_name,
8801 make one up now. Tag_CPU_raw_name remains blank. */
8802 if (out_attr[Tag_CPU_name].s == NULL
8803 && out_attr[i].i < ARRAY_SIZE (name_table))
8804 out_attr[Tag_CPU_name].s =
8805 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
8809 case Tag_ARM_ISA_use:
8810 case Tag_THUMB_ISA_use:
8812 case Tag_Advanced_SIMD_arch:
8813 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
8814 case Tag_ABI_FP_rounding:
8815 case Tag_ABI_FP_exceptions:
8816 case Tag_ABI_FP_user_exceptions:
8817 case Tag_ABI_FP_number_model:
8818 case Tag_VFP_HP_extension:
8819 case Tag_CPU_unaligned_access:
8821 case Tag_Virtualization_use:
8822 case Tag_MPextension_use:
8823 /* Use the largest value specified. */
8824 if (in_attr[i].i > out_attr[i].i)
8825 out_attr[i].i = in_attr[i].i;
8828 case Tag_ABI_align8_preserved:
8829 case Tag_ABI_PCS_RO_data:
8830 /* Use the smallest value specified. */
8831 if (in_attr[i].i < out_attr[i].i)
8832 out_attr[i].i = in_attr[i].i;
8835 case Tag_ABI_align8_needed:
8836 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
8837 && (in_attr[Tag_ABI_align8_preserved].i == 0
8838 || out_attr[Tag_ABI_align8_preserved].i == 0))
8840 /* This error message should be enabled once all non-conformant
8841 binaries in the toolchain have had the attributes set
8844 (_("error: %B: 8-byte data alignment conflicts with %B"),
8849 case Tag_ABI_FP_denormal:
8850 case Tag_ABI_PCS_GOT_use:
8851 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8852 value if greater than 2 (for future-proofing). */
8853 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
8854 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
8855 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
8856 out_attr[i].i = in_attr[i].i;
8860 case Tag_CPU_arch_profile:
8861 if (out_attr[i].i != in_attr[i].i)
8863 /* 0 will merge with anything.
8864 'A' and 'S' merge to 'A'.
8865 'R' and 'S' merge to 'R'.
8866 'M' and 'A|R|S' is an error. */
8867 if (out_attr[i].i == 0
8868 || (out_attr[i].i == 'S'
8869 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
8870 out_attr[i].i = in_attr[i].i;
8871 else if (in_attr[i].i == 0
8872 || (in_attr[i].i == 'S'
8873 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
8878 (_("error: %B: Conflicting architecture profiles %c/%c"),
8880 in_attr[i].i ? in_attr[i].i : '0',
8881 out_attr[i].i ? out_attr[i].i : '0');
8887 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8888 largest value if greater than 4 (for future-proofing). */
8889 if ((in_attr[i].i > 4 && in_attr[i].i > out_attr[i].i)
8890 || (in_attr[i].i <= 4 && out_attr[i].i <= 4
8891 && order_01243[in_attr[i].i] > order_01243[out_attr[i].i]))
8892 out_attr[i].i = in_attr[i].i;
8894 case Tag_PCS_config:
8895 if (out_attr[i].i == 0)
8896 out_attr[i].i = in_attr[i].i;
8897 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8899 /* It's sometimes ok to mix different configs, so this is only
8902 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8905 case Tag_ABI_PCS_R9_use:
8906 if (in_attr[i].i != out_attr[i].i
8907 && out_attr[i].i != AEABI_R9_unused
8908 && in_attr[i].i != AEABI_R9_unused)
8911 (_("error: %B: Conflicting use of R9"), ibfd);
8914 if (out_attr[i].i == AEABI_R9_unused)
8915 out_attr[i].i = in_attr[i].i;
8917 case Tag_ABI_PCS_RW_data:
8918 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8919 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8920 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8923 (_("error: %B: SB relative addressing conflicts with use of R9"),
8927 /* Use the smallest value specified. */
8928 if (in_attr[i].i < out_attr[i].i)
8929 out_attr[i].i = in_attr[i].i;
8931 case Tag_ABI_PCS_wchar_t:
8932 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8933 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
8936 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8937 ibfd, in_attr[i].i, out_attr[i].i);
8939 else if (in_attr[i].i && !out_attr[i].i)
8940 out_attr[i].i = in_attr[i].i;
8942 case Tag_ABI_enum_size:
8943 if (in_attr[i].i != AEABI_enum_unused)
8945 if (out_attr[i].i == AEABI_enum_unused
8946 || out_attr[i].i == AEABI_enum_forced_wide)
8948 /* The existing object is compatible with anything.
8949 Use whatever requirements the new object has. */
8950 out_attr[i].i = in_attr[i].i;
8952 else if (in_attr[i].i != AEABI_enum_forced_wide
8953 && out_attr[i].i != in_attr[i].i
8954 && !elf_arm_tdata (obfd)->no_enum_size_warning)
8956 static const char *aeabi_enum_names[] =
8957 { "", "variable-size", "32-bit", "" };
8958 const char *in_name =
8959 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8960 ? aeabi_enum_names[in_attr[i].i]
8962 const char *out_name =
8963 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8964 ? aeabi_enum_names[out_attr[i].i]
8967 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8968 ibfd, in_name, out_name);
8972 case Tag_ABI_VFP_args:
8975 case Tag_ABI_WMMX_args:
8976 if (in_attr[i].i != out_attr[i].i)
8979 (_("error: %B uses iWMMXt register arguments, %B does not"),
8984 case Tag_compatibility:
8985 /* Merged in target-independent code. */
8987 case Tag_ABI_HardFP_use:
8988 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8989 if ((in_attr[i].i == 1 && out_attr[i].i == 2)
8990 || (in_attr[i].i == 2 && out_attr[i].i == 1))
8992 else if (in_attr[i].i > out_attr[i].i)
8993 out_attr[i].i = in_attr[i].i;
8995 case Tag_ABI_FP_16bit_format:
8996 if (in_attr[i].i != 0 && out_attr[i].i != 0)
8998 if (in_attr[i].i != out_attr[i].i)
9001 (_("error: fp16 format mismatch between %B and %B"),
9006 if (in_attr[i].i != 0)
9007 out_attr[i].i = in_attr[i].i;
9010 case Tag_nodefaults:
9011 /* This tag is set if it exists, but the value is unused (and is
9012 typically zero). We don't actually need to do anything here -
9013 the merge happens automatically when the type flags are merged
9016 case Tag_also_compatible_with:
9017 /* Already done in Tag_CPU_arch. */
9019 case Tag_conformance:
9020 /* Keep the attribute if it matches. Throw it away otherwise.
9021 No attribute means no claim to conform. */
9022 if (!in_attr[i].s || !out_attr[i].s
9023 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
9024 out_attr[i].s = NULL;
9029 bfd *err_bfd = NULL;
9031 /* The "known_obj_attributes" table does contain some undefined
9032 attributes. Ensure that there are unused. */
9033 if (out_attr[i].i != 0 || out_attr[i].s != NULL)
9035 else if (in_attr[i].i != 0 || in_attr[i].s != NULL)
9038 if (err_bfd != NULL)
9040 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9044 (_("%B: Unknown mandatory EABI object attribute %d"),
9046 bfd_set_error (bfd_error_bad_value);
9052 (_("Warning: %B: Unknown EABI object attribute %d"),
9057 /* Only pass on attributes that match in both inputs. */
9058 if (in_attr[i].i != out_attr[i].i
9059 || in_attr[i].s != out_attr[i].s
9060 || (in_attr[i].s != NULL && out_attr[i].s != NULL
9061 && strcmp (in_attr[i].s, out_attr[i].s) != 0))
9064 out_attr[i].s = NULL;
9069 /* If out_attr was copied from in_attr then it won't have a type yet. */
9070 if (in_attr[i].type && !out_attr[i].type)
9071 out_attr[i].type = in_attr[i].type;
9074 /* Merge Tag_compatibility attributes and any common GNU ones. */
9075 _bfd_elf_merge_object_attributes (ibfd, obfd);
9077 /* Check for any attributes not known on ARM. */
9078 in_list = elf_other_obj_attributes_proc (ibfd);
9079 out_listp = &elf_other_obj_attributes_proc (obfd);
9080 out_list = *out_listp;
9082 for (; in_list || out_list; )
9084 bfd *err_bfd = NULL;
9087 /* The tags for each list are in numerical order. */
9088 /* If the tags are equal, then merge. */
9089 if (out_list && (!in_list || in_list->tag > out_list->tag))
9091 /* This attribute only exists in obfd. We can't merge, and we don't
9092 know what the tag means, so delete it. */
9094 err_tag = out_list->tag;
9095 *out_listp = out_list->next;
9096 out_list = *out_listp;
9098 else if (in_list && (!out_list || in_list->tag < out_list->tag))
9100 /* This attribute only exists in ibfd. We can't merge, and we don't
9101 know what the tag means, so ignore it. */
9103 err_tag = in_list->tag;
9104 in_list = in_list->next;
9106 else /* The tags are equal. */
9108 /* As present, all attributes in the list are unknown, and
9109 therefore can't be merged meaningfully. */
9111 err_tag = out_list->tag;
9113 /* Only pass on attributes that match in both inputs. */
9114 if (in_list->attr.i != out_list->attr.i
9115 || in_list->attr.s != out_list->attr.s
9116 || (in_list->attr.s && out_list->attr.s
9117 && strcmp (in_list->attr.s, out_list->attr.s) != 0))
9119 /* No match. Delete the attribute. */
9120 *out_listp = out_list->next;
9121 out_list = *out_listp;
9125 /* Matched. Keep the attribute and move to the next. */
9126 out_list = out_list->next;
9127 in_list = in_list->next;
9133 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9134 if ((err_tag & 127) < 64)
9137 (_("%B: Unknown mandatory EABI object attribute %d"),
9139 bfd_set_error (bfd_error_bad_value);
9145 (_("Warning: %B: Unknown EABI object attribute %d"),
9154 /* Return TRUE if the two EABI versions are incompatible. */
9157 elf32_arm_versions_compatible (unsigned iver, unsigned over)
9159 /* v4 and v5 are the same spec before and after it was released,
9160 so allow mixing them. */
9161 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
9162 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
9165 return (iver == over);
9168 /* Merge backend specific data from an object file to the output
9169 object file when linking. */
9172 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
9176 bfd_boolean flags_compatible = TRUE;
9179 /* Check if we have the same endianess. */
9180 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
9183 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
9186 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
9189 /* The input BFD must have had its flags initialised. */
9190 /* The following seems bogus to me -- The flags are initialized in
9191 the assembler but I don't think an elf_flags_init field is
9192 written into the object. */
9193 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9195 in_flags = elf_elfheader (ibfd)->e_flags;
9196 out_flags = elf_elfheader (obfd)->e_flags;
9198 /* In theory there is no reason why we couldn't handle this. However
9199 in practice it isn't even close to working and there is no real
9200 reason to want it. */
9201 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
9202 && !(ibfd->flags & DYNAMIC)
9203 && (in_flags & EF_ARM_BE8))
9205 _bfd_error_handler (_("error: %B is already in final BE8 format"),
9210 if (!elf_flags_init (obfd))
9212 /* If the input is the default architecture and had the default
9213 flags then do not bother setting the flags for the output
9214 architecture, instead allow future merges to do this. If no
9215 future merges ever set these flags then they will retain their
9216 uninitialised values, which surprise surprise, correspond
9217 to the default values. */
9218 if (bfd_get_arch_info (ibfd)->the_default
9219 && elf_elfheader (ibfd)->e_flags == 0)
9222 elf_flags_init (obfd) = TRUE;
9223 elf_elfheader (obfd)->e_flags = in_flags;
9225 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
9226 && bfd_get_arch_info (obfd)->the_default)
9227 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
9232 /* Determine what should happen if the input ARM architecture
9233 does not match the output ARM architecture. */
9234 if (! bfd_arm_merge_machines (ibfd, obfd))
9237 /* Identical flags must be compatible. */
9238 if (in_flags == out_flags)
9241 /* Check to see if the input BFD actually contains any sections. If
9242 not, its flags may not have been initialised either, but it
9243 cannot actually cause any incompatiblity. Do not short-circuit
9244 dynamic objects; their section list may be emptied by
9245 elf_link_add_object_symbols.
9247 Also check to see if there are no code sections in the input.
9248 In this case there is no need to check for code specific flags.
9249 XXX - do we need to worry about floating-point format compatability
9250 in data sections ? */
9251 if (!(ibfd->flags & DYNAMIC))
9253 bfd_boolean null_input_bfd = TRUE;
9254 bfd_boolean only_data_sections = TRUE;
9256 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9258 /* Ignore synthetic glue sections. */
9259 if (strcmp (sec->name, ".glue_7")
9260 && strcmp (sec->name, ".glue_7t"))
9262 if ((bfd_get_section_flags (ibfd, sec)
9263 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9264 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9265 only_data_sections = FALSE;
9267 null_input_bfd = FALSE;
9272 if (null_input_bfd || only_data_sections)
9276 /* Complain about various flag mismatches. */
9277 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
9278 EF_ARM_EABI_VERSION (out_flags)))
9281 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
9283 (in_flags & EF_ARM_EABIMASK) >> 24,
9284 (out_flags & EF_ARM_EABIMASK) >> 24);
9288 /* Not sure what needs to be checked for EABI versions >= 1. */
9289 /* VxWorks libraries do not use these flags. */
9290 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
9291 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
9292 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
9294 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
9297 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9299 in_flags & EF_ARM_APCS_26 ? 26 : 32,
9300 out_flags & EF_ARM_APCS_26 ? 26 : 32);
9301 flags_compatible = FALSE;
9304 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
9306 if (in_flags & EF_ARM_APCS_FLOAT)
9308 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
9312 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
9315 flags_compatible = FALSE;
9318 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
9320 if (in_flags & EF_ARM_VFP_FLOAT)
9322 (_("error: %B uses VFP instructions, whereas %B does not"),
9326 (_("error: %B uses FPA instructions, whereas %B does not"),
9329 flags_compatible = FALSE;
9332 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
9334 if (in_flags & EF_ARM_MAVERICK_FLOAT)
9336 (_("error: %B uses Maverick instructions, whereas %B does not"),
9340 (_("error: %B does not use Maverick instructions, whereas %B does"),
9343 flags_compatible = FALSE;
9346 #ifdef EF_ARM_SOFT_FLOAT
9347 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
9349 /* We can allow interworking between code that is VFP format
9350 layout, and uses either soft float or integer regs for
9351 passing floating point arguments and results. We already
9352 know that the APCS_FLOAT flags match; similarly for VFP
9354 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
9355 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
9357 if (in_flags & EF_ARM_SOFT_FLOAT)
9359 (_("error: %B uses software FP, whereas %B uses hardware FP"),
9363 (_("error: %B uses hardware FP, whereas %B uses software FP"),
9366 flags_compatible = FALSE;
9371 /* Interworking mismatch is only a warning. */
9372 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
9374 if (in_flags & EF_ARM_INTERWORK)
9377 (_("Warning: %B supports interworking, whereas %B does not"),
9383 (_("Warning: %B does not support interworking, whereas %B does"),
9389 return flags_compatible;
9392 /* Display the flags field. */
9395 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
9397 FILE * file = (FILE *) ptr;
9398 unsigned long flags;
9400 BFD_ASSERT (abfd != NULL && ptr != NULL);
9402 /* Print normal ELF private data. */
9403 _bfd_elf_print_private_bfd_data (abfd, ptr);
9405 flags = elf_elfheader (abfd)->e_flags;
9406 /* Ignore init flag - it may not be set, despite the flags field
9407 containing valid data. */
9409 /* xgettext:c-format */
9410 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
9412 switch (EF_ARM_EABI_VERSION (flags))
9414 case EF_ARM_EABI_UNKNOWN:
9415 /* The following flag bits are GNU extensions and not part of the
9416 official ARM ELF extended ABI. Hence they are only decoded if
9417 the EABI version is not set. */
9418 if (flags & EF_ARM_INTERWORK)
9419 fprintf (file, _(" [interworking enabled]"));
9421 if (flags & EF_ARM_APCS_26)
9422 fprintf (file, " [APCS-26]");
9424 fprintf (file, " [APCS-32]");
9426 if (flags & EF_ARM_VFP_FLOAT)
9427 fprintf (file, _(" [VFP float format]"));
9428 else if (flags & EF_ARM_MAVERICK_FLOAT)
9429 fprintf (file, _(" [Maverick float format]"));
9431 fprintf (file, _(" [FPA float format]"));
9433 if (flags & EF_ARM_APCS_FLOAT)
9434 fprintf (file, _(" [floats passed in float registers]"));
9436 if (flags & EF_ARM_PIC)
9437 fprintf (file, _(" [position independent]"));
9439 if (flags & EF_ARM_NEW_ABI)
9440 fprintf (file, _(" [new ABI]"));
9442 if (flags & EF_ARM_OLD_ABI)
9443 fprintf (file, _(" [old ABI]"));
9445 if (flags & EF_ARM_SOFT_FLOAT)
9446 fprintf (file, _(" [software FP]"));
9448 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
9449 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
9450 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
9451 | EF_ARM_MAVERICK_FLOAT);
9454 case EF_ARM_EABI_VER1:
9455 fprintf (file, _(" [Version1 EABI]"));
9457 if (flags & EF_ARM_SYMSARESORTED)
9458 fprintf (file, _(" [sorted symbol table]"));
9460 fprintf (file, _(" [unsorted symbol table]"));
9462 flags &= ~ EF_ARM_SYMSARESORTED;
9465 case EF_ARM_EABI_VER2:
9466 fprintf (file, _(" [Version2 EABI]"));
9468 if (flags & EF_ARM_SYMSARESORTED)
9469 fprintf (file, _(" [sorted symbol table]"));
9471 fprintf (file, _(" [unsorted symbol table]"));
9473 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
9474 fprintf (file, _(" [dynamic symbols use segment index]"));
9476 if (flags & EF_ARM_MAPSYMSFIRST)
9477 fprintf (file, _(" [mapping symbols precede others]"));
9479 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
9480 | EF_ARM_MAPSYMSFIRST);
9483 case EF_ARM_EABI_VER3:
9484 fprintf (file, _(" [Version3 EABI]"));
9487 case EF_ARM_EABI_VER4:
9488 fprintf (file, _(" [Version4 EABI]"));
9491 case EF_ARM_EABI_VER5:
9492 fprintf (file, _(" [Version5 EABI]"));
9494 if (flags & EF_ARM_BE8)
9495 fprintf (file, _(" [BE8]"));
9497 if (flags & EF_ARM_LE8)
9498 fprintf (file, _(" [LE8]"));
9500 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
9504 fprintf (file, _(" <EABI version unrecognised>"));
9508 flags &= ~ EF_ARM_EABIMASK;
9510 if (flags & EF_ARM_RELEXEC)
9511 fprintf (file, _(" [relocatable executable]"));
9513 if (flags & EF_ARM_HASENTRY)
9514 fprintf (file, _(" [has entry point]"));
9516 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
9519 fprintf (file, _("<Unrecognised flag bits set>"));
9527 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
9529 switch (ELF_ST_TYPE (elf_sym->st_info))
9532 return ELF_ST_TYPE (elf_sym->st_info);
9535 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9536 This allows us to distinguish between data used by Thumb instructions
9537 and non-data (which is probably code) inside Thumb regions of an
9539 if (type != STT_OBJECT && type != STT_TLS)
9540 return ELF_ST_TYPE (elf_sym->st_info);
9551 elf32_arm_gc_mark_hook (asection *sec,
9552 struct bfd_link_info *info,
9553 Elf_Internal_Rela *rel,
9554 struct elf_link_hash_entry *h,
9555 Elf_Internal_Sym *sym)
9558 switch (ELF32_R_TYPE (rel->r_info))
9560 case R_ARM_GNU_VTINHERIT:
9561 case R_ARM_GNU_VTENTRY:
9565 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
9568 /* Update the got entry reference counts for the section being removed. */
9571 elf32_arm_gc_sweep_hook (bfd * abfd,
9572 struct bfd_link_info * info,
9574 const Elf_Internal_Rela * relocs)
9576 Elf_Internal_Shdr *symtab_hdr;
9577 struct elf_link_hash_entry **sym_hashes;
9578 bfd_signed_vma *local_got_refcounts;
9579 const Elf_Internal_Rela *rel, *relend;
9580 struct elf32_arm_link_hash_table * globals;
9582 if (info->relocatable)
9585 globals = elf32_arm_hash_table (info);
9587 elf_section_data (sec)->local_dynrel = NULL;
9589 symtab_hdr = & elf_symtab_hdr (abfd);
9590 sym_hashes = elf_sym_hashes (abfd);
9591 local_got_refcounts = elf_local_got_refcounts (abfd);
9593 check_use_blx (globals);
9595 relend = relocs + sec->reloc_count;
9596 for (rel = relocs; rel < relend; rel++)
9598 unsigned long r_symndx;
9599 struct elf_link_hash_entry *h = NULL;
9602 r_symndx = ELF32_R_SYM (rel->r_info);
9603 if (r_symndx >= symtab_hdr->sh_info)
9605 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9606 while (h->root.type == bfd_link_hash_indirect
9607 || h->root.type == bfd_link_hash_warning)
9608 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9611 r_type = ELF32_R_TYPE (rel->r_info);
9612 r_type = arm_real_reloc_type (globals, r_type);
9616 case R_ARM_GOT_PREL:
9617 case R_ARM_TLS_GD32:
9618 case R_ARM_TLS_IE32:
9621 if (h->got.refcount > 0)
9622 h->got.refcount -= 1;
9624 else if (local_got_refcounts != NULL)
9626 if (local_got_refcounts[r_symndx] > 0)
9627 local_got_refcounts[r_symndx] -= 1;
9631 case R_ARM_TLS_LDM32:
9632 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
9636 case R_ARM_ABS32_NOI:
9638 case R_ARM_REL32_NOI:
9644 case R_ARM_THM_CALL:
9645 case R_ARM_THM_JUMP24:
9646 case R_ARM_THM_JUMP19:
9647 case R_ARM_MOVW_ABS_NC:
9648 case R_ARM_MOVT_ABS:
9649 case R_ARM_MOVW_PREL_NC:
9650 case R_ARM_MOVT_PREL:
9651 case R_ARM_THM_MOVW_ABS_NC:
9652 case R_ARM_THM_MOVT_ABS:
9653 case R_ARM_THM_MOVW_PREL_NC:
9654 case R_ARM_THM_MOVT_PREL:
9655 /* Should the interworking branches be here also? */
9659 struct elf32_arm_link_hash_entry *eh;
9660 struct elf32_arm_relocs_copied **pp;
9661 struct elf32_arm_relocs_copied *p;
9663 eh = (struct elf32_arm_link_hash_entry *) h;
9665 if (h->plt.refcount > 0)
9667 h->plt.refcount -= 1;
9668 if (r_type == R_ARM_THM_CALL)
9669 eh->plt_maybe_thumb_refcount--;
9671 if (r_type == R_ARM_THM_JUMP24
9672 || r_type == R_ARM_THM_JUMP19)
9673 eh->plt_thumb_refcount--;
9676 if (r_type == R_ARM_ABS32
9677 || r_type == R_ARM_REL32
9678 || r_type == R_ARM_ABS32_NOI
9679 || r_type == R_ARM_REL32_NOI)
9681 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
9683 if (p->section == sec)
9686 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
9687 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
9705 /* Look through the relocs for a section during the first phase. */
9708 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
9709 asection *sec, const Elf_Internal_Rela *relocs)
9711 Elf_Internal_Shdr *symtab_hdr;
9712 struct elf_link_hash_entry **sym_hashes;
9713 const Elf_Internal_Rela *rel;
9714 const Elf_Internal_Rela *rel_end;
9717 bfd_vma *local_got_offsets;
9718 struct elf32_arm_link_hash_table *htab;
9719 bfd_boolean needs_plt;
9720 unsigned long nsyms;
9722 if (info->relocatable)
9725 BFD_ASSERT (is_arm_elf (abfd));
9727 htab = elf32_arm_hash_table (info);
9730 /* Create dynamic sections for relocatable executables so that we can
9731 copy relocations. */
9732 if (htab->root.is_relocatable_executable
9733 && ! htab->root.dynamic_sections_created)
9735 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
9739 dynobj = elf_hash_table (info)->dynobj;
9740 local_got_offsets = elf_local_got_offsets (abfd);
9742 symtab_hdr = & elf_symtab_hdr (abfd);
9743 sym_hashes = elf_sym_hashes (abfd);
9744 nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
9746 rel_end = relocs + sec->reloc_count;
9747 for (rel = relocs; rel < rel_end; rel++)
9749 struct elf_link_hash_entry *h;
9750 struct elf32_arm_link_hash_entry *eh;
9751 unsigned long r_symndx;
9754 r_symndx = ELF32_R_SYM (rel->r_info);
9755 r_type = ELF32_R_TYPE (rel->r_info);
9756 r_type = arm_real_reloc_type (htab, r_type);
9758 if (r_symndx >= nsyms
9759 /* PR 9934: It is possible to have relocations that do not
9760 refer to symbols, thus it is also possible to have an
9761 object file containing relocations but no symbol table. */
9762 && (r_symndx > 0 || nsyms > 0))
9764 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9769 if (nsyms == 0 || r_symndx < symtab_hdr->sh_info)
9773 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9774 while (h->root.type == bfd_link_hash_indirect
9775 || h->root.type == bfd_link_hash_warning)
9776 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9779 eh = (struct elf32_arm_link_hash_entry *) h;
9784 case R_ARM_GOT_PREL:
9785 case R_ARM_TLS_GD32:
9786 case R_ARM_TLS_IE32:
9787 /* This symbol requires a global offset table entry. */
9789 int tls_type, old_tls_type;
9793 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9794 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9795 default: tls_type = GOT_NORMAL; break;
9801 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9805 bfd_signed_vma *local_got_refcounts;
9807 /* This is a global offset table entry for a local symbol. */
9808 local_got_refcounts = elf_local_got_refcounts (abfd);
9809 if (local_got_refcounts == NULL)
9813 size = symtab_hdr->sh_info;
9814 size *= (sizeof (bfd_signed_vma) + sizeof (char));
9815 local_got_refcounts = bfd_zalloc (abfd, size);
9816 if (local_got_refcounts == NULL)
9818 elf_local_got_refcounts (abfd) = local_got_refcounts;
9819 elf32_arm_local_got_tls_type (abfd)
9820 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9822 local_got_refcounts[r_symndx] += 1;
9823 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9826 /* We will already have issued an error message if there is a
9827 TLS / non-TLS mismatch, based on the symbol type. We don't
9828 support any linker relaxations. So just combine any TLS
9830 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9831 && tls_type != GOT_NORMAL)
9832 tls_type |= old_tls_type;
9834 if (old_tls_type != tls_type)
9837 elf32_arm_hash_entry (h)->tls_type = tls_type;
9839 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9844 case R_ARM_TLS_LDM32:
9845 if (r_type == R_ARM_TLS_LDM32)
9846 htab->tls_ldm_got.refcount++;
9849 case R_ARM_GOTOFF32:
9851 if (htab->sgot == NULL)
9853 if (htab->root.dynobj == NULL)
9854 htab->root.dynobj = abfd;
9855 if (!create_got_section (htab->root.dynobj, info))
9861 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9862 ldr __GOTT_INDEX__ offsets. */
9863 if (!htab->vxworks_p)
9872 case R_ARM_THM_CALL:
9873 case R_ARM_THM_JUMP24:
9874 case R_ARM_THM_JUMP19:
9879 case R_ARM_ABS32_NOI:
9881 case R_ARM_REL32_NOI:
9882 case R_ARM_MOVW_ABS_NC:
9883 case R_ARM_MOVT_ABS:
9884 case R_ARM_MOVW_PREL_NC:
9885 case R_ARM_MOVT_PREL:
9886 case R_ARM_THM_MOVW_ABS_NC:
9887 case R_ARM_THM_MOVT_ABS:
9888 case R_ARM_THM_MOVW_PREL_NC:
9889 case R_ARM_THM_MOVT_PREL:
9893 /* Should the interworking branches be listed here? */
9896 /* If this reloc is in a read-only section, we might
9897 need a copy reloc. We can't check reliably at this
9898 stage whether the section is read-only, as input
9899 sections have not yet been mapped to output sections.
9900 Tentatively set the flag for now, and correct in
9901 adjust_dynamic_symbol. */
9905 /* We may need a .plt entry if the function this reloc
9906 refers to is in a different object. We can't tell for
9907 sure yet, because something later might force the
9912 /* If we create a PLT entry, this relocation will reference
9913 it, even if it's an ABS32 relocation. */
9914 h->plt.refcount += 1;
9916 /* It's too early to use htab->use_blx here, so we have to
9917 record possible blx references separately from
9918 relocs that definitely need a thumb stub. */
9920 if (r_type == R_ARM_THM_CALL)
9921 eh->plt_maybe_thumb_refcount += 1;
9923 if (r_type == R_ARM_THM_JUMP24
9924 || r_type == R_ARM_THM_JUMP19)
9925 eh->plt_thumb_refcount += 1;
9928 /* If we are creating a shared library or relocatable executable,
9929 and this is a reloc against a global symbol, or a non PC
9930 relative reloc against a local symbol, then we need to copy
9931 the reloc into the shared library. However, if we are linking
9932 with -Bsymbolic, we do not need to copy a reloc against a
9933 global symbol which is defined in an object we are
9934 including in the link (i.e., DEF_REGULAR is set). At
9935 this point we have not seen all the input files, so it is
9936 possible that DEF_REGULAR is not set now but will be set
9937 later (it is never cleared). We account for that
9938 possibility below by storing information in the
9939 relocs_copied field of the hash table entry. */
9940 if ((info->shared || htab->root.is_relocatable_executable)
9941 && (sec->flags & SEC_ALLOC) != 0
9942 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
9943 || (h != NULL && ! h->needs_plt
9944 && (! info->symbolic || ! h->def_regular))))
9946 struct elf32_arm_relocs_copied *p, **head;
9948 /* When creating a shared object, we must copy these
9949 reloc types into the output file. We create a reloc
9950 section in dynobj and make room for this reloc. */
9953 sreloc = _bfd_elf_make_dynamic_reloc_section
9954 (sec, dynobj, 2, abfd, ! htab->use_rel);
9959 /* BPABI objects never have dynamic relocations mapped. */
9960 if (htab->symbian_p)
9964 flags = bfd_get_section_flags (dynobj, sreloc);
9965 flags &= ~(SEC_LOAD | SEC_ALLOC);
9966 bfd_set_section_flags (dynobj, sreloc, flags);
9970 /* If this is a global symbol, we count the number of
9971 relocations we need for this symbol. */
9974 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9978 /* Track dynamic relocs needed for local syms too.
9979 We really need local syms available to do this
9985 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9990 vpp = &elf_section_data (s)->local_dynrel;
9991 head = (struct elf32_arm_relocs_copied **) vpp;
9995 if (p == NULL || p->section != sec)
9997 bfd_size_type amt = sizeof *p;
9999 p = bfd_alloc (htab->root.dynobj, amt);
10009 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
10015 /* This relocation describes the C++ object vtable hierarchy.
10016 Reconstruct it for later use during GC. */
10017 case R_ARM_GNU_VTINHERIT:
10018 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
10022 /* This relocation describes which C++ vtable entries are actually
10023 used. Record for later use during GC. */
10024 case R_ARM_GNU_VTENTRY:
10025 BFD_ASSERT (h != NULL);
10027 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
10036 /* Unwinding tables are not referenced directly. This pass marks them as
10037 required if the corresponding code section is marked. */
10040 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
10041 elf_gc_mark_hook_fn gc_mark_hook)
10044 Elf_Internal_Shdr **elf_shdrp;
10047 /* Marking EH data may cause additional code sections to be marked,
10048 requiring multiple passes. */
10053 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
10057 if (! is_arm_elf (sub))
10060 elf_shdrp = elf_elfsections (sub);
10061 for (o = sub->sections; o != NULL; o = o->next)
10063 Elf_Internal_Shdr *hdr;
10065 hdr = &elf_section_data (o)->this_hdr;
10066 if (hdr->sh_type == SHT_ARM_EXIDX
10068 && hdr->sh_link < elf_numsections (sub)
10070 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
10073 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
10083 /* Treat mapping symbols as special target symbols. */
10086 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
10088 return bfd_is_arm_special_symbol_name (sym->name,
10089 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
10092 /* This is a copy of elf_find_function() from elf.c except that
10093 ARM mapping symbols are ignored when looking for function names
10094 and STT_ARM_TFUNC is considered to a function type. */
10097 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
10098 asection * section,
10099 asymbol ** symbols,
10101 const char ** filename_ptr,
10102 const char ** functionname_ptr)
10104 const char * filename = NULL;
10105 asymbol * func = NULL;
10106 bfd_vma low_func = 0;
10109 for (p = symbols; *p != NULL; p++)
10111 elf_symbol_type *q;
10113 q = (elf_symbol_type *) *p;
10115 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
10120 filename = bfd_asymbol_name (&q->symbol);
10123 case STT_ARM_TFUNC:
10125 /* Skip mapping symbols. */
10126 if ((q->symbol.flags & BSF_LOCAL)
10127 && bfd_is_arm_special_symbol_name (q->symbol.name,
10128 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
10130 /* Fall through. */
10131 if (bfd_get_section (&q->symbol) == section
10132 && q->symbol.value >= low_func
10133 && q->symbol.value <= offset)
10135 func = (asymbol *) q;
10136 low_func = q->symbol.value;
10146 *filename_ptr = filename;
10147 if (functionname_ptr)
10148 *functionname_ptr = bfd_asymbol_name (func);
10154 /* Find the nearest line to a particular section and offset, for error
10155 reporting. This code is a duplicate of the code in elf.c, except
10156 that it uses arm_elf_find_function. */
10159 elf32_arm_find_nearest_line (bfd * abfd,
10160 asection * section,
10161 asymbol ** symbols,
10163 const char ** filename_ptr,
10164 const char ** functionname_ptr,
10165 unsigned int * line_ptr)
10167 bfd_boolean found = FALSE;
10169 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
10171 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
10172 filename_ptr, functionname_ptr,
10174 & elf_tdata (abfd)->dwarf2_find_line_info))
10176 if (!*functionname_ptr)
10177 arm_elf_find_function (abfd, section, symbols, offset,
10178 *filename_ptr ? NULL : filename_ptr,
10184 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
10185 & found, filename_ptr,
10186 functionname_ptr, line_ptr,
10187 & elf_tdata (abfd)->line_info))
10190 if (found && (*functionname_ptr || *line_ptr))
10193 if (symbols == NULL)
10196 if (! arm_elf_find_function (abfd, section, symbols, offset,
10197 filename_ptr, functionname_ptr))
10205 elf32_arm_find_inliner_info (bfd * abfd,
10206 const char ** filename_ptr,
10207 const char ** functionname_ptr,
10208 unsigned int * line_ptr)
10211 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
10212 functionname_ptr, line_ptr,
10213 & elf_tdata (abfd)->dwarf2_find_line_info);
10217 /* Adjust a symbol defined by a dynamic object and referenced by a
10218 regular object. The current definition is in some section of the
10219 dynamic object, but we're not including those sections. We have to
10220 change the definition to something the rest of the link can
10224 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
10225 struct elf_link_hash_entry * h)
10229 struct elf32_arm_link_hash_entry * eh;
10230 struct elf32_arm_link_hash_table *globals;
10232 globals = elf32_arm_hash_table (info);
10233 dynobj = elf_hash_table (info)->dynobj;
10235 /* Make sure we know what is going on here. */
10236 BFD_ASSERT (dynobj != NULL
10238 || h->u.weakdef != NULL
10241 && !h->def_regular)));
10243 eh = (struct elf32_arm_link_hash_entry *) h;
10245 /* If this is a function, put it in the procedure linkage table. We
10246 will fill in the contents of the procedure linkage table later,
10247 when we know the address of the .got section. */
10248 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
10251 if (h->plt.refcount <= 0
10252 || SYMBOL_CALLS_LOCAL (info, h)
10253 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
10254 && h->root.type == bfd_link_hash_undefweak))
10256 /* This case can occur if we saw a PLT32 reloc in an input
10257 file, but the symbol was never referred to by a dynamic
10258 object, or if all references were garbage collected. In
10259 such a case, we don't actually need to build a procedure
10260 linkage table, and we can just do a PC24 reloc instead. */
10261 h->plt.offset = (bfd_vma) -1;
10262 eh->plt_thumb_refcount = 0;
10263 eh->plt_maybe_thumb_refcount = 0;
10271 /* It's possible that we incorrectly decided a .plt reloc was
10272 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10273 in check_relocs. We can't decide accurately between function
10274 and non-function syms in check-relocs; Objects loaded later in
10275 the link may change h->type. So fix it now. */
10276 h->plt.offset = (bfd_vma) -1;
10277 eh->plt_thumb_refcount = 0;
10278 eh->plt_maybe_thumb_refcount = 0;
10281 /* If this is a weak symbol, and there is a real definition, the
10282 processor independent code will have arranged for us to see the
10283 real definition first, and we can just use the same value. */
10284 if (h->u.weakdef != NULL)
10286 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
10287 || h->u.weakdef->root.type == bfd_link_hash_defweak);
10288 h->root.u.def.section = h->u.weakdef->root.u.def.section;
10289 h->root.u.def.value = h->u.weakdef->root.u.def.value;
10293 /* If there are no non-GOT references, we do not need a copy
10295 if (!h->non_got_ref)
10298 /* This is a reference to a symbol defined by a dynamic object which
10299 is not a function. */
10301 /* If we are creating a shared library, we must presume that the
10302 only references to the symbol are via the global offset table.
10303 For such cases we need not do anything here; the relocations will
10304 be handled correctly by relocate_section. Relocatable executables
10305 can reference data in shared objects directly, so we don't need to
10306 do anything here. */
10307 if (info->shared || globals->root.is_relocatable_executable)
10312 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
10313 h->root.root.string);
10317 /* We must allocate the symbol in our .dynbss section, which will
10318 become part of the .bss section of the executable. There will be
10319 an entry for this symbol in the .dynsym section. The dynamic
10320 object will contain position independent code, so all references
10321 from the dynamic object to this symbol will go through the global
10322 offset table. The dynamic linker will use the .dynsym entry to
10323 determine the address it must put in the global offset table, so
10324 both the dynamic object and the regular object will refer to the
10325 same memory location for the variable. */
10326 s = bfd_get_section_by_name (dynobj, ".dynbss");
10327 BFD_ASSERT (s != NULL);
10329 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10330 copy the initial value out of the dynamic object and into the
10331 runtime process image. We need to remember the offset into the
10332 .rel(a).bss section we are going to use. */
10333 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
10337 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
10338 BFD_ASSERT (srel != NULL);
10339 srel->size += RELOC_SIZE (globals);
10343 return _bfd_elf_adjust_dynamic_copy (h, s);
10346 /* Allocate space in .plt, .got and associated reloc sections for
10350 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
10352 struct bfd_link_info *info;
10353 struct elf32_arm_link_hash_table *htab;
10354 struct elf32_arm_link_hash_entry *eh;
10355 struct elf32_arm_relocs_copied *p;
10356 bfd_signed_vma thumb_refs;
10358 eh = (struct elf32_arm_link_hash_entry *) h;
10360 if (h->root.type == bfd_link_hash_indirect)
10363 if (h->root.type == bfd_link_hash_warning)
10364 /* When warning symbols are created, they **replace** the "real"
10365 entry in the hash table, thus we never get to see the real
10366 symbol in a hash traversal. So look at it now. */
10367 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10369 info = (struct bfd_link_info *) inf;
10370 htab = elf32_arm_hash_table (info);
10372 if (htab->root.dynamic_sections_created
10373 && h->plt.refcount > 0)
10375 /* Make sure this symbol is output as a dynamic symbol.
10376 Undefined weak syms won't yet be marked as dynamic. */
10377 if (h->dynindx == -1
10378 && !h->forced_local)
10380 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10385 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
10387 asection *s = htab->splt;
10389 /* If this is the first .plt entry, make room for the special
10392 s->size += htab->plt_header_size;
10394 h->plt.offset = s->size;
10396 /* If we will insert a Thumb trampoline before this PLT, leave room
10398 thumb_refs = eh->plt_thumb_refcount;
10399 if (!htab->use_blx)
10400 thumb_refs += eh->plt_maybe_thumb_refcount;
10402 if (thumb_refs > 0)
10404 h->plt.offset += PLT_THUMB_STUB_SIZE;
10405 s->size += PLT_THUMB_STUB_SIZE;
10408 /* If this symbol is not defined in a regular file, and we are
10409 not generating a shared library, then set the symbol to this
10410 location in the .plt. This is required to make function
10411 pointers compare as equal between the normal executable and
10412 the shared library. */
10414 && !h->def_regular)
10416 h->root.u.def.section = s;
10417 h->root.u.def.value = h->plt.offset;
10419 /* Make sure the function is not marked as Thumb, in case
10420 it is the target of an ABS32 relocation, which will
10421 point to the PLT entry. */
10422 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
10423 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10426 /* Make room for this entry. */
10427 s->size += htab->plt_entry_size;
10429 if (!htab->symbian_p)
10431 /* We also need to make an entry in the .got.plt section, which
10432 will be placed in the .got section by the linker script. */
10433 eh->plt_got_offset = htab->sgotplt->size;
10434 htab->sgotplt->size += 4;
10437 /* We also need to make an entry in the .rel(a).plt section. */
10438 htab->srelplt->size += RELOC_SIZE (htab);
10440 /* VxWorks executables have a second set of relocations for
10441 each PLT entry. They go in a separate relocation section,
10442 which is processed by the kernel loader. */
10443 if (htab->vxworks_p && !info->shared)
10445 /* There is a relocation for the initial PLT entry:
10446 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10447 if (h->plt.offset == htab->plt_header_size)
10448 htab->srelplt2->size += RELOC_SIZE (htab);
10450 /* There are two extra relocations for each subsequent
10451 PLT entry: an R_ARM_32 relocation for the GOT entry,
10452 and an R_ARM_32 relocation for the PLT entry. */
10453 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
10458 h->plt.offset = (bfd_vma) -1;
10464 h->plt.offset = (bfd_vma) -1;
10468 if (h->got.refcount > 0)
10472 int tls_type = elf32_arm_hash_entry (h)->tls_type;
10475 /* Make sure this symbol is output as a dynamic symbol.
10476 Undefined weak syms won't yet be marked as dynamic. */
10477 if (h->dynindx == -1
10478 && !h->forced_local)
10480 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10484 if (!htab->symbian_p)
10487 h->got.offset = s->size;
10489 if (tls_type == GOT_UNKNOWN)
10492 if (tls_type == GOT_NORMAL)
10493 /* Non-TLS symbols need one GOT slot. */
10497 if (tls_type & GOT_TLS_GD)
10498 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10500 if (tls_type & GOT_TLS_IE)
10501 /* R_ARM_TLS_IE32 needs one GOT slot. */
10505 dyn = htab->root.dynamic_sections_created;
10508 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
10510 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10513 if (tls_type != GOT_NORMAL
10514 && (info->shared || indx != 0)
10515 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10516 || h->root.type != bfd_link_hash_undefweak))
10518 if (tls_type & GOT_TLS_IE)
10519 htab->srelgot->size += RELOC_SIZE (htab);
10521 if (tls_type & GOT_TLS_GD)
10522 htab->srelgot->size += RELOC_SIZE (htab);
10524 if ((tls_type & GOT_TLS_GD) && indx != 0)
10525 htab->srelgot->size += RELOC_SIZE (htab);
10527 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10528 || h->root.type != bfd_link_hash_undefweak)
10530 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
10531 htab->srelgot->size += RELOC_SIZE (htab);
10535 h->got.offset = (bfd_vma) -1;
10537 /* Allocate stubs for exported Thumb functions on v4t. */
10538 if (!htab->use_blx && h->dynindx != -1
10540 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
10541 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
10543 struct elf_link_hash_entry * th;
10544 struct bfd_link_hash_entry * bh;
10545 struct elf_link_hash_entry * myh;
10549 /* Create a new symbol to regist the real location of the function. */
10550 s = h->root.u.def.section;
10551 sprintf (name, "__real_%s", h->root.root.string);
10552 _bfd_generic_link_add_one_symbol (info, s->owner,
10553 name, BSF_GLOBAL, s,
10554 h->root.u.def.value,
10555 NULL, TRUE, FALSE, &bh);
10557 myh = (struct elf_link_hash_entry *) bh;
10558 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
10559 myh->forced_local = 1;
10560 eh->export_glue = myh;
10561 th = record_arm_to_thumb_glue (info, h);
10562 /* Point the symbol at the stub. */
10563 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10564 h->root.u.def.section = th->root.u.def.section;
10565 h->root.u.def.value = th->root.u.def.value & ~1;
10568 if (eh->relocs_copied == NULL)
10571 /* In the shared -Bsymbolic case, discard space allocated for
10572 dynamic pc-relative relocs against symbols which turn out to be
10573 defined in regular objects. For the normal shared case, discard
10574 space for pc-relative relocs that have become local due to symbol
10575 visibility changes. */
10577 if (info->shared || htab->root.is_relocatable_executable)
10579 /* The only relocs that use pc_count are R_ARM_REL32 and
10580 R_ARM_REL32_NOI, which will appear on something like
10581 ".long foo - .". We want calls to protected symbols to resolve
10582 directly to the function rather than going via the plt. If people
10583 want function pointer comparisons to work as expected then they
10584 should avoid writing assembly like ".long foo - .". */
10585 if (SYMBOL_CALLS_LOCAL (info, h))
10587 struct elf32_arm_relocs_copied **pp;
10589 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10591 p->count -= p->pc_count;
10600 if (elf32_arm_hash_table (info)->vxworks_p)
10602 struct elf32_arm_relocs_copied **pp;
10604 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10606 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
10613 /* Also discard relocs on undefined weak syms with non-default
10615 if (eh->relocs_copied != NULL
10616 && h->root.type == bfd_link_hash_undefweak)
10618 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
10619 eh->relocs_copied = NULL;
10621 /* Make sure undefined weak symbols are output as a dynamic
10623 else if (h->dynindx == -1
10624 && !h->forced_local)
10626 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10631 else if (htab->root.is_relocatable_executable && h->dynindx == -1
10632 && h->root.type == bfd_link_hash_new)
10634 /* Output absolute symbols so that we can create relocations
10635 against them. For normal symbols we output a relocation
10636 against the section that contains them. */
10637 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10644 /* For the non-shared case, discard space for relocs against
10645 symbols which turn out to need copy relocs or are not
10648 if (!h->non_got_ref
10649 && ((h->def_dynamic
10650 && !h->def_regular)
10651 || (htab->root.dynamic_sections_created
10652 && (h->root.type == bfd_link_hash_undefweak
10653 || h->root.type == bfd_link_hash_undefined))))
10655 /* Make sure this symbol is output as a dynamic symbol.
10656 Undefined weak syms won't yet be marked as dynamic. */
10657 if (h->dynindx == -1
10658 && !h->forced_local)
10660 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10664 /* If that succeeded, we know we'll be keeping all the
10666 if (h->dynindx != -1)
10670 eh->relocs_copied = NULL;
10675 /* Finally, allocate space. */
10676 for (p = eh->relocs_copied; p != NULL; p = p->next)
10678 asection *sreloc = elf_section_data (p->section)->sreloc;
10679 sreloc->size += p->count * RELOC_SIZE (htab);
10685 /* Find any dynamic relocs that apply to read-only sections. */
10688 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
10690 struct elf32_arm_link_hash_entry * eh;
10691 struct elf32_arm_relocs_copied * p;
10693 if (h->root.type == bfd_link_hash_warning)
10694 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10696 eh = (struct elf32_arm_link_hash_entry *) h;
10697 for (p = eh->relocs_copied; p != NULL; p = p->next)
10699 asection *s = p->section;
10701 if (s != NULL && (s->flags & SEC_READONLY) != 0)
10703 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10705 info->flags |= DF_TEXTREL;
10707 /* Not an error, just cut short the traversal. */
10715 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
10718 struct elf32_arm_link_hash_table *globals;
10720 globals = elf32_arm_hash_table (info);
10721 globals->byteswap_code = byteswap_code;
10724 /* Set the sizes of the dynamic sections. */
10727 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10728 struct bfd_link_info * info)
10733 bfd_boolean relocs;
10735 struct elf32_arm_link_hash_table *htab;
10737 htab = elf32_arm_hash_table (info);
10738 dynobj = elf_hash_table (info)->dynobj;
10739 BFD_ASSERT (dynobj != NULL);
10740 check_use_blx (htab);
10742 if (elf_hash_table (info)->dynamic_sections_created)
10744 /* Set the contents of the .interp section to the interpreter. */
10745 if (info->executable)
10747 s = bfd_get_section_by_name (dynobj, ".interp");
10748 BFD_ASSERT (s != NULL);
10749 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10750 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10754 /* Set up .got offsets for local syms, and space for local dynamic
10756 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10758 bfd_signed_vma *local_got;
10759 bfd_signed_vma *end_local_got;
10760 char *local_tls_type;
10761 bfd_size_type locsymcount;
10762 Elf_Internal_Shdr *symtab_hdr;
10764 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
10766 if (! is_arm_elf (ibfd))
10769 for (s = ibfd->sections; s != NULL; s = s->next)
10771 struct elf32_arm_relocs_copied *p;
10773 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10775 if (!bfd_is_abs_section (p->section)
10776 && bfd_is_abs_section (p->section->output_section))
10778 /* Input section has been discarded, either because
10779 it is a copy of a linkonce section or due to
10780 linker script /DISCARD/, so we'll be discarding
10783 else if (is_vxworks
10784 && strcmp (p->section->output_section->name,
10787 /* Relocations in vxworks .tls_vars sections are
10788 handled specially by the loader. */
10790 else if (p->count != 0)
10792 srel = elf_section_data (p->section)->sreloc;
10793 srel->size += p->count * RELOC_SIZE (htab);
10794 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10795 info->flags |= DF_TEXTREL;
10800 local_got = elf_local_got_refcounts (ibfd);
10804 symtab_hdr = & elf_symtab_hdr (ibfd);
10805 locsymcount = symtab_hdr->sh_info;
10806 end_local_got = local_got + locsymcount;
10807 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
10809 srel = htab->srelgot;
10810 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10812 if (*local_got > 0)
10814 *local_got = s->size;
10815 if (*local_tls_type & GOT_TLS_GD)
10816 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10818 if (*local_tls_type & GOT_TLS_IE)
10820 if (*local_tls_type == GOT_NORMAL)
10823 if (info->shared || *local_tls_type == GOT_TLS_GD)
10824 srel->size += RELOC_SIZE (htab);
10827 *local_got = (bfd_vma) -1;
10831 if (htab->tls_ldm_got.refcount > 0)
10833 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10834 for R_ARM_TLS_LDM32 relocations. */
10835 htab->tls_ldm_got.offset = htab->sgot->size;
10836 htab->sgot->size += 8;
10838 htab->srelgot->size += RELOC_SIZE (htab);
10841 htab->tls_ldm_got.offset = -1;
10843 /* Allocate global sym .plt and .got entries, and space for global
10844 sym dynamic relocs. */
10845 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
10847 /* Here we rummage through the found bfds to collect glue information. */
10848 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10850 if (! is_arm_elf (ibfd))
10853 /* Initialise mapping tables for code/data. */
10854 bfd_elf32_arm_init_maps (ibfd);
10856 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10857 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10858 /* xgettext:c-format */
10859 _bfd_error_handler (_("Errors encountered processing file %s"),
10863 /* Allocate space for the glue sections now that we've sized them. */
10864 bfd_elf32_arm_allocate_interworking_sections (info);
10866 /* The check_relocs and adjust_dynamic_symbol entry points have
10867 determined the sizes of the various dynamic sections. Allocate
10868 memory for them. */
10871 for (s = dynobj->sections; s != NULL; s = s->next)
10875 if ((s->flags & SEC_LINKER_CREATED) == 0)
10878 /* It's OK to base decisions on the section name, because none
10879 of the dynobj section names depend upon the input files. */
10880 name = bfd_get_section_name (dynobj, s);
10882 if (strcmp (name, ".plt") == 0)
10884 /* Remember whether there is a PLT. */
10885 plt = s->size != 0;
10887 else if (CONST_STRNEQ (name, ".rel"))
10891 /* Remember whether there are any reloc sections other
10892 than .rel(a).plt and .rela.plt.unloaded. */
10893 if (s != htab->srelplt && s != htab->srelplt2)
10896 /* We use the reloc_count field as a counter if we need
10897 to copy relocs into the output file. */
10898 s->reloc_count = 0;
10901 else if (! CONST_STRNEQ (name, ".got")
10902 && strcmp (name, ".dynbss") != 0)
10904 /* It's not one of our sections, so don't allocate space. */
10910 /* If we don't need this section, strip it from the
10911 output file. This is mostly to handle .rel(a).bss and
10912 .rel(a).plt. We must create both sections in
10913 create_dynamic_sections, because they must be created
10914 before the linker maps input sections to output
10915 sections. The linker does that before
10916 adjust_dynamic_symbol is called, and it is that
10917 function which decides whether anything needs to go
10918 into these sections. */
10919 s->flags |= SEC_EXCLUDE;
10923 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10926 /* Allocate memory for the section contents. */
10927 s->contents = bfd_zalloc (dynobj, s->size);
10928 if (s->contents == NULL)
10932 if (elf_hash_table (info)->dynamic_sections_created)
10934 /* Add some entries to the .dynamic section. We fill in the
10935 values later, in elf32_arm_finish_dynamic_sections, but we
10936 must add the entries now so that we get the correct size for
10937 the .dynamic section. The DT_DEBUG entry is filled in by the
10938 dynamic linker and used by the debugger. */
10939 #define add_dynamic_entry(TAG, VAL) \
10940 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10942 if (info->executable)
10944 if (!add_dynamic_entry (DT_DEBUG, 0))
10950 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10951 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10952 || !add_dynamic_entry (DT_PLTREL,
10953 htab->use_rel ? DT_REL : DT_RELA)
10954 || !add_dynamic_entry (DT_JMPREL, 0))
10962 if (!add_dynamic_entry (DT_REL, 0)
10963 || !add_dynamic_entry (DT_RELSZ, 0)
10964 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10969 if (!add_dynamic_entry (DT_RELA, 0)
10970 || !add_dynamic_entry (DT_RELASZ, 0)
10971 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10976 /* If any dynamic relocs apply to a read-only section,
10977 then we need a DT_TEXTREL entry. */
10978 if ((info->flags & DF_TEXTREL) == 0)
10979 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
10982 if ((info->flags & DF_TEXTREL) != 0)
10984 if (!add_dynamic_entry (DT_TEXTREL, 0))
10987 if (htab->vxworks_p
10988 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10991 #undef add_dynamic_entry
10996 /* Finish up dynamic symbol handling. We set the contents of various
10997 dynamic sections here. */
11000 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
11001 struct bfd_link_info * info,
11002 struct elf_link_hash_entry * h,
11003 Elf_Internal_Sym * sym)
11006 struct elf32_arm_link_hash_table *htab;
11007 struct elf32_arm_link_hash_entry *eh;
11009 dynobj = elf_hash_table (info)->dynobj;
11010 htab = elf32_arm_hash_table (info);
11011 eh = (struct elf32_arm_link_hash_entry *) h;
11013 if (h->plt.offset != (bfd_vma) -1)
11019 Elf_Internal_Rela rel;
11021 /* This symbol has an entry in the procedure linkage table. Set
11024 BFD_ASSERT (h->dynindx != -1);
11026 splt = bfd_get_section_by_name (dynobj, ".plt");
11027 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
11028 BFD_ASSERT (splt != NULL && srel != NULL);
11030 /* Fill in the entry in the procedure linkage table. */
11031 if (htab->symbian_p)
11033 put_arm_insn (htab, output_bfd,
11034 elf32_arm_symbian_plt_entry[0],
11035 splt->contents + h->plt.offset);
11036 bfd_put_32 (output_bfd,
11037 elf32_arm_symbian_plt_entry[1],
11038 splt->contents + h->plt.offset + 4);
11040 /* Fill in the entry in the .rel.plt section. */
11041 rel.r_offset = (splt->output_section->vma
11042 + splt->output_offset
11043 + h->plt.offset + 4);
11044 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11046 /* Get the index in the procedure linkage table which
11047 corresponds to this symbol. This is the index of this symbol
11048 in all the symbols for which we are making plt entries. The
11049 first entry in the procedure linkage table is reserved. */
11050 plt_index = ((h->plt.offset - htab->plt_header_size)
11051 / htab->plt_entry_size);
11055 bfd_vma got_offset, got_address, plt_address;
11056 bfd_vma got_displacement;
11060 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
11061 BFD_ASSERT (sgot != NULL);
11063 /* Get the offset into the .got.plt table of the entry that
11064 corresponds to this function. */
11065 got_offset = eh->plt_got_offset;
11067 /* Get the index in the procedure linkage table which
11068 corresponds to this symbol. This is the index of this symbol
11069 in all the symbols for which we are making plt entries. The
11070 first three entries in .got.plt are reserved; after that
11071 symbols appear in the same order as in .plt. */
11072 plt_index = (got_offset - 12) / 4;
11074 /* Calculate the address of the GOT entry. */
11075 got_address = (sgot->output_section->vma
11076 + sgot->output_offset
11079 /* ...and the address of the PLT entry. */
11080 plt_address = (splt->output_section->vma
11081 + splt->output_offset
11084 ptr = htab->splt->contents + h->plt.offset;
11085 if (htab->vxworks_p && info->shared)
11090 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
11092 val = elf32_arm_vxworks_shared_plt_entry[i];
11094 val |= got_address - sgot->output_section->vma;
11096 val |= plt_index * RELOC_SIZE (htab);
11097 if (i == 2 || i == 5)
11098 bfd_put_32 (output_bfd, val, ptr);
11100 put_arm_insn (htab, output_bfd, val, ptr);
11103 else if (htab->vxworks_p)
11108 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
11110 val = elf32_arm_vxworks_exec_plt_entry[i];
11112 val |= got_address;
11114 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
11116 val |= plt_index * RELOC_SIZE (htab);
11117 if (i == 2 || i == 5)
11118 bfd_put_32 (output_bfd, val, ptr);
11120 put_arm_insn (htab, output_bfd, val, ptr);
11123 loc = (htab->srelplt2->contents
11124 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
11126 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
11127 referencing the GOT for this PLT entry. */
11128 rel.r_offset = plt_address + 8;
11129 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11130 rel.r_addend = got_offset;
11131 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11132 loc += RELOC_SIZE (htab);
11134 /* Create the R_ARM_ABS32 relocation referencing the
11135 beginning of the PLT for this GOT entry. */
11136 rel.r_offset = got_address;
11137 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11139 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11143 bfd_signed_vma thumb_refs;
11144 /* Calculate the displacement between the PLT slot and the
11145 entry in the GOT. The eight-byte offset accounts for the
11146 value produced by adding to pc in the first instruction
11147 of the PLT stub. */
11148 got_displacement = got_address - (plt_address + 8);
11150 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
11152 thumb_refs = eh->plt_thumb_refcount;
11153 if (!htab->use_blx)
11154 thumb_refs += eh->plt_maybe_thumb_refcount;
11156 if (thumb_refs > 0)
11158 put_thumb_insn (htab, output_bfd,
11159 elf32_arm_plt_thumb_stub[0], ptr - 4);
11160 put_thumb_insn (htab, output_bfd,
11161 elf32_arm_plt_thumb_stub[1], ptr - 2);
11164 put_arm_insn (htab, output_bfd,
11165 elf32_arm_plt_entry[0]
11166 | ((got_displacement & 0x0ff00000) >> 20),
11168 put_arm_insn (htab, output_bfd,
11169 elf32_arm_plt_entry[1]
11170 | ((got_displacement & 0x000ff000) >> 12),
11172 put_arm_insn (htab, output_bfd,
11173 elf32_arm_plt_entry[2]
11174 | (got_displacement & 0x00000fff),
11176 #ifdef FOUR_WORD_PLT
11177 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
11181 /* Fill in the entry in the global offset table. */
11182 bfd_put_32 (output_bfd,
11183 (splt->output_section->vma
11184 + splt->output_offset),
11185 sgot->contents + got_offset);
11187 /* Fill in the entry in the .rel(a).plt section. */
11189 rel.r_offset = got_address;
11190 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
11193 loc = srel->contents + plt_index * RELOC_SIZE (htab);
11194 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11196 if (!h->def_regular)
11198 /* Mark the symbol as undefined, rather than as defined in
11199 the .plt section. Leave the value alone. */
11200 sym->st_shndx = SHN_UNDEF;
11201 /* If the symbol is weak, we do need to clear the value.
11202 Otherwise, the PLT entry would provide a definition for
11203 the symbol even if the symbol wasn't defined anywhere,
11204 and so the symbol would never be NULL. */
11205 if (!h->ref_regular_nonweak)
11210 if (h->got.offset != (bfd_vma) -1
11211 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
11212 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
11216 Elf_Internal_Rela rel;
11220 /* This symbol has an entry in the global offset table. Set it
11222 sgot = bfd_get_section_by_name (dynobj, ".got");
11223 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
11224 BFD_ASSERT (sgot != NULL && srel != NULL);
11226 offset = (h->got.offset & ~(bfd_vma) 1);
11228 rel.r_offset = (sgot->output_section->vma
11229 + sgot->output_offset
11232 /* If this is a static link, or it is a -Bsymbolic link and the
11233 symbol is defined locally or was forced to be local because
11234 of a version file, we just want to emit a RELATIVE reloc.
11235 The entry in the global offset table will already have been
11236 initialized in the relocate_section function. */
11238 && SYMBOL_REFERENCES_LOCAL (info, h))
11240 BFD_ASSERT ((h->got.offset & 1) != 0);
11241 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
11242 if (!htab->use_rel)
11244 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
11245 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11250 BFD_ASSERT ((h->got.offset & 1) == 0);
11251 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11252 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11255 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
11256 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11262 Elf_Internal_Rela rel;
11265 /* This symbol needs a copy reloc. Set it up. */
11266 BFD_ASSERT (h->dynindx != -1
11267 && (h->root.type == bfd_link_hash_defined
11268 || h->root.type == bfd_link_hash_defweak));
11270 s = bfd_get_section_by_name (h->root.u.def.section->owner,
11271 RELOC_SECTION (htab, ".bss"));
11272 BFD_ASSERT (s != NULL);
11275 rel.r_offset = (h->root.u.def.value
11276 + h->root.u.def.section->output_section->vma
11277 + h->root.u.def.section->output_offset);
11278 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
11279 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
11280 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11283 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11284 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11285 to the ".got" section. */
11286 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
11287 || (!htab->vxworks_p && h == htab->root.hgot))
11288 sym->st_shndx = SHN_ABS;
11293 /* Finish up the dynamic sections. */
11296 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
11302 dynobj = elf_hash_table (info)->dynobj;
11304 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
11305 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
11306 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11308 if (elf_hash_table (info)->dynamic_sections_created)
11311 Elf32_External_Dyn *dyncon, *dynconend;
11312 struct elf32_arm_link_hash_table *htab;
11314 htab = elf32_arm_hash_table (info);
11315 splt = bfd_get_section_by_name (dynobj, ".plt");
11316 BFD_ASSERT (splt != NULL && sdyn != NULL);
11318 dyncon = (Elf32_External_Dyn *) sdyn->contents;
11319 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
11321 for (; dyncon < dynconend; dyncon++)
11323 Elf_Internal_Dyn dyn;
11327 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
11334 if (htab->vxworks_p
11335 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
11336 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11341 goto get_vma_if_bpabi;
11344 goto get_vma_if_bpabi;
11347 goto get_vma_if_bpabi;
11349 name = ".gnu.version";
11350 goto get_vma_if_bpabi;
11352 name = ".gnu.version_d";
11353 goto get_vma_if_bpabi;
11355 name = ".gnu.version_r";
11356 goto get_vma_if_bpabi;
11362 name = RELOC_SECTION (htab, ".plt");
11364 s = bfd_get_section_by_name (output_bfd, name);
11365 BFD_ASSERT (s != NULL);
11366 if (!htab->symbian_p)
11367 dyn.d_un.d_ptr = s->vma;
11369 /* In the BPABI, tags in the PT_DYNAMIC section point
11370 at the file offset, not the memory address, for the
11371 convenience of the post linker. */
11372 dyn.d_un.d_ptr = s->filepos;
11373 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11377 if (htab->symbian_p)
11382 s = bfd_get_section_by_name (output_bfd,
11383 RELOC_SECTION (htab, ".plt"));
11384 BFD_ASSERT (s != NULL);
11385 dyn.d_un.d_val = s->size;
11386 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11391 if (!htab->symbian_p)
11393 /* My reading of the SVR4 ABI indicates that the
11394 procedure linkage table relocs (DT_JMPREL) should be
11395 included in the overall relocs (DT_REL). This is
11396 what Solaris does. However, UnixWare can not handle
11397 that case. Therefore, we override the DT_RELSZ entry
11398 here to make it not include the JMPREL relocs. Since
11399 the linker script arranges for .rel(a).plt to follow all
11400 other relocation sections, we don't have to worry
11401 about changing the DT_REL entry. */
11402 s = bfd_get_section_by_name (output_bfd,
11403 RELOC_SECTION (htab, ".plt"));
11405 dyn.d_un.d_val -= s->size;
11406 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11409 /* Fall through. */
11413 /* In the BPABI, the DT_REL tag must point at the file
11414 offset, not the VMA, of the first relocation
11415 section. So, we use code similar to that in
11416 elflink.c, but do not check for SHF_ALLOC on the
11417 relcoation section, since relocations sections are
11418 never allocated under the BPABI. The comments above
11419 about Unixware notwithstanding, we include all of the
11420 relocations here. */
11421 if (htab->symbian_p)
11424 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
11425 ? SHT_REL : SHT_RELA);
11426 dyn.d_un.d_val = 0;
11427 for (i = 1; i < elf_numsections (output_bfd); i++)
11429 Elf_Internal_Shdr *hdr
11430 = elf_elfsections (output_bfd)[i];
11431 if (hdr->sh_type == type)
11433 if (dyn.d_tag == DT_RELSZ
11434 || dyn.d_tag == DT_RELASZ)
11435 dyn.d_un.d_val += hdr->sh_size;
11436 else if ((ufile_ptr) hdr->sh_offset
11437 <= dyn.d_un.d_val - 1)
11438 dyn.d_un.d_val = hdr->sh_offset;
11441 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11445 /* Set the bottom bit of DT_INIT/FINI if the
11446 corresponding function is Thumb. */
11448 name = info->init_function;
11451 name = info->fini_function;
11453 /* If it wasn't set by elf_bfd_final_link
11454 then there is nothing to adjust. */
11455 if (dyn.d_un.d_val != 0)
11457 struct elf_link_hash_entry * eh;
11459 eh = elf_link_hash_lookup (elf_hash_table (info), name,
11460 FALSE, FALSE, TRUE);
11462 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
11464 dyn.d_un.d_val |= 1;
11465 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11472 /* Fill in the first entry in the procedure linkage table. */
11473 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
11475 const bfd_vma *plt0_entry;
11476 bfd_vma got_address, plt_address, got_displacement;
11478 /* Calculate the addresses of the GOT and PLT. */
11479 got_address = sgot->output_section->vma + sgot->output_offset;
11480 plt_address = splt->output_section->vma + splt->output_offset;
11482 if (htab->vxworks_p)
11484 /* The VxWorks GOT is relocated by the dynamic linker.
11485 Therefore, we must emit relocations rather than simply
11486 computing the values now. */
11487 Elf_Internal_Rela rel;
11489 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
11490 put_arm_insn (htab, output_bfd, plt0_entry[0],
11491 splt->contents + 0);
11492 put_arm_insn (htab, output_bfd, plt0_entry[1],
11493 splt->contents + 4);
11494 put_arm_insn (htab, output_bfd, plt0_entry[2],
11495 splt->contents + 8);
11496 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
11498 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
11499 rel.r_offset = plt_address + 12;
11500 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11502 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
11503 htab->srelplt2->contents);
11507 got_displacement = got_address - (plt_address + 16);
11509 plt0_entry = elf32_arm_plt0_entry;
11510 put_arm_insn (htab, output_bfd, plt0_entry[0],
11511 splt->contents + 0);
11512 put_arm_insn (htab, output_bfd, plt0_entry[1],
11513 splt->contents + 4);
11514 put_arm_insn (htab, output_bfd, plt0_entry[2],
11515 splt->contents + 8);
11516 put_arm_insn (htab, output_bfd, plt0_entry[3],
11517 splt->contents + 12);
11519 #ifdef FOUR_WORD_PLT
11520 /* The displacement value goes in the otherwise-unused
11521 last word of the second entry. */
11522 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
11524 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
11529 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11530 really seem like the right value. */
11531 if (splt->output_section->owner == output_bfd)
11532 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
11534 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
11536 /* Correct the .rel(a).plt.unloaded relocations. They will have
11537 incorrect symbol indexes. */
11541 num_plts = ((htab->splt->size - htab->plt_header_size)
11542 / htab->plt_entry_size);
11543 p = htab->srelplt2->contents + RELOC_SIZE (htab);
11545 for (; num_plts; num_plts--)
11547 Elf_Internal_Rela rel;
11549 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11550 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11551 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11552 p += RELOC_SIZE (htab);
11554 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11555 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11556 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11557 p += RELOC_SIZE (htab);
11562 /* Fill in the first three entries in the global offset table. */
11565 if (sgot->size > 0)
11568 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
11570 bfd_put_32 (output_bfd,
11571 sdyn->output_section->vma + sdyn->output_offset,
11573 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
11574 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
11577 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
11584 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
11586 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
11587 struct elf32_arm_link_hash_table *globals;
11589 i_ehdrp = elf_elfheader (abfd);
11591 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
11592 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
11594 i_ehdrp->e_ident[EI_OSABI] = 0;
11595 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
11599 globals = elf32_arm_hash_table (link_info);
11600 if (globals->byteswap_code)
11601 i_ehdrp->e_flags |= EF_ARM_BE8;
11605 static enum elf_reloc_type_class
11606 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
11608 switch ((int) ELF32_R_TYPE (rela->r_info))
11610 case R_ARM_RELATIVE:
11611 return reloc_class_relative;
11612 case R_ARM_JUMP_SLOT:
11613 return reloc_class_plt;
11615 return reloc_class_copy;
11617 return reloc_class_normal;
11621 /* Set the right machine number for an Arm ELF file. */
11624 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
11626 if (hdr->sh_type == SHT_NOTE)
11627 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
11633 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
11635 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
11638 /* Return TRUE if this is an unwinding table entry. */
11641 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
11643 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
11644 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
11648 /* Set the type and flags for an ARM section. We do this by
11649 the section name, which is a hack, but ought to work. */
11652 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
11656 name = bfd_get_section_name (abfd, sec);
11658 if (is_arm_elf_unwind_section_name (abfd, name))
11660 hdr->sh_type = SHT_ARM_EXIDX;
11661 hdr->sh_flags |= SHF_LINK_ORDER;
11666 /* Handle an ARM specific section when reading an object file. This is
11667 called when bfd_section_from_shdr finds a section with an unknown
11671 elf32_arm_section_from_shdr (bfd *abfd,
11672 Elf_Internal_Shdr * hdr,
11676 /* There ought to be a place to keep ELF backend specific flags, but
11677 at the moment there isn't one. We just keep track of the
11678 sections by their name, instead. Fortunately, the ABI gives
11679 names for all the ARM specific sections, so we will probably get
11681 switch (hdr->sh_type)
11683 case SHT_ARM_EXIDX:
11684 case SHT_ARM_PREEMPTMAP:
11685 case SHT_ARM_ATTRIBUTES:
11692 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
11698 /* A structure used to record a list of sections, independently
11699 of the next and prev fields in the asection structure. */
11700 typedef struct section_list
11703 struct section_list * next;
11704 struct section_list * prev;
11708 /* Unfortunately we need to keep a list of sections for which
11709 an _arm_elf_section_data structure has been allocated. This
11710 is because it is possible for functions like elf32_arm_write_section
11711 to be called on a section which has had an elf_data_structure
11712 allocated for it (and so the used_by_bfd field is valid) but
11713 for which the ARM extended version of this structure - the
11714 _arm_elf_section_data structure - has not been allocated. */
11715 static section_list * sections_with_arm_elf_section_data = NULL;
11718 record_section_with_arm_elf_section_data (asection * sec)
11720 struct section_list * entry;
11722 entry = bfd_malloc (sizeof (* entry));
11726 entry->next = sections_with_arm_elf_section_data;
11727 entry->prev = NULL;
11728 if (entry->next != NULL)
11729 entry->next->prev = entry;
11730 sections_with_arm_elf_section_data = entry;
11733 static struct section_list *
11734 find_arm_elf_section_entry (asection * sec)
11736 struct section_list * entry;
11737 static struct section_list * last_entry = NULL;
11739 /* This is a short cut for the typical case where the sections are added
11740 to the sections_with_arm_elf_section_data list in forward order and
11741 then looked up here in backwards order. This makes a real difference
11742 to the ld-srec/sec64k.exp linker test. */
11743 entry = sections_with_arm_elf_section_data;
11744 if (last_entry != NULL)
11746 if (last_entry->sec == sec)
11747 entry = last_entry;
11748 else if (last_entry->next != NULL
11749 && last_entry->next->sec == sec)
11750 entry = last_entry->next;
11753 for (; entry; entry = entry->next)
11754 if (entry->sec == sec)
11758 /* Record the entry prior to this one - it is the entry we are most
11759 likely to want to locate next time. Also this way if we have been
11760 called from unrecord_section_with_arm_elf_section_data() we will not
11761 be caching a pointer that is about to be freed. */
11762 last_entry = entry->prev;
11767 static _arm_elf_section_data *
11768 get_arm_elf_section_data (asection * sec)
11770 struct section_list * entry;
11772 entry = find_arm_elf_section_entry (sec);
11775 return elf32_arm_section_data (entry->sec);
11781 unrecord_section_with_arm_elf_section_data (asection * sec)
11783 struct section_list * entry;
11785 entry = find_arm_elf_section_entry (sec);
11789 if (entry->prev != NULL)
11790 entry->prev->next = entry->next;
11791 if (entry->next != NULL)
11792 entry->next->prev = entry->prev;
11793 if (entry == sections_with_arm_elf_section_data)
11794 sections_with_arm_elf_section_data = entry->next;
11803 struct bfd_link_info *info;
11806 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11807 asection *, struct elf_link_hash_entry *);
11808 } output_arch_syminfo;
11810 enum map_symbol_type
11818 /* Output a single mapping symbol. */
11821 elf32_arm_output_map_sym (output_arch_syminfo *osi,
11822 enum map_symbol_type type,
11825 static const char *names[3] = {"$a", "$t", "$d"};
11826 struct elf32_arm_link_hash_table *htab;
11827 Elf_Internal_Sym sym;
11829 htab = elf32_arm_hash_table (osi->info);
11830 sym.st_value = osi->sec->output_section->vma
11831 + osi->sec->output_offset
11835 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
11836 sym.st_shndx = osi->sec_shndx;
11837 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
11843 /* Output mapping symbols for PLT entries associated with H. */
11846 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11848 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11849 struct elf32_arm_link_hash_table *htab;
11850 struct elf32_arm_link_hash_entry *eh;
11853 htab = elf32_arm_hash_table (osi->info);
11855 if (h->root.type == bfd_link_hash_indirect)
11858 if (h->root.type == bfd_link_hash_warning)
11859 /* When warning symbols are created, they **replace** the "real"
11860 entry in the hash table, thus we never get to see the real
11861 symbol in a hash traversal. So look at it now. */
11862 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11864 if (h->plt.offset == (bfd_vma) -1)
11867 eh = (struct elf32_arm_link_hash_entry *) h;
11868 addr = h->plt.offset;
11869 if (htab->symbian_p)
11871 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11873 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11876 else if (htab->vxworks_p)
11878 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11880 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11882 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
11884 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
11889 bfd_signed_vma thumb_refs;
11891 thumb_refs = eh->plt_thumb_refcount;
11892 if (!htab->use_blx)
11893 thumb_refs += eh->plt_maybe_thumb_refcount;
11895 if (thumb_refs > 0)
11897 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
11900 #ifdef FOUR_WORD_PLT
11901 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11903 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11906 /* A three-word PLT with no Thumb thunk contains only Arm code,
11907 so only need to output a mapping symbol for the first PLT entry and
11908 entries with thumb thunks. */
11909 if (thumb_refs > 0 || addr == 20)
11911 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11920 /* Output a single local symbol for a generated stub. */
11923 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11924 bfd_vma offset, bfd_vma size)
11926 struct elf32_arm_link_hash_table *htab;
11927 Elf_Internal_Sym sym;
11929 htab = elf32_arm_hash_table (osi->info);
11930 sym.st_value = osi->sec->output_section->vma
11931 + osi->sec->output_offset
11933 sym.st_size = size;
11935 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11936 sym.st_shndx = osi->sec_shndx;
11937 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11943 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
11946 struct elf32_arm_stub_hash_entry *stub_entry;
11947 struct bfd_link_info *info;
11948 struct elf32_arm_link_hash_table *htab;
11949 asection *stub_sec;
11952 output_arch_syminfo *osi;
11953 const insn_sequence *template;
11954 enum stub_insn_type prev_type;
11957 enum map_symbol_type sym_type;
11959 /* Massage our args to the form they really have. */
11960 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11961 osi = (output_arch_syminfo *) in_arg;
11965 htab = elf32_arm_hash_table (info);
11966 stub_sec = stub_entry->stub_sec;
11968 /* Ensure this stub is attached to the current section being
11970 if (stub_sec != osi->sec)
11973 addr = (bfd_vma) stub_entry->stub_offset;
11974 stub_name = stub_entry->output_name;
11976 template = stub_entry->stub_template;
11977 switch (template[0].type)
11980 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
11984 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
11985 stub_entry->stub_size))
11993 prev_type = DATA_TYPE;
11995 for (i = 0; i < stub_entry->stub_template_size; i++)
11997 switch (template[i].type)
12000 sym_type = ARM_MAP_ARM;
12004 sym_type = ARM_MAP_THUMB;
12008 sym_type = ARM_MAP_DATA;
12016 if (template[i].type != prev_type)
12018 prev_type = template[i].type;
12019 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
12023 switch (template[i].type)
12046 /* Output mapping symbols for linker generated sections. */
12049 elf32_arm_output_arch_local_syms (bfd *output_bfd,
12050 struct bfd_link_info *info,
12052 bfd_boolean (*func) (void *, const char *,
12053 Elf_Internal_Sym *,
12055 struct elf_link_hash_entry *))
12057 output_arch_syminfo osi;
12058 struct elf32_arm_link_hash_table *htab;
12060 bfd_size_type size;
12062 htab = elf32_arm_hash_table (info);
12063 check_use_blx (htab);
12069 /* ARM->Thumb glue. */
12070 if (htab->arm_glue_size > 0)
12072 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12073 ARM2THUMB_GLUE_SECTION_NAME);
12075 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12076 (output_bfd, osi.sec->output_section);
12077 if (info->shared || htab->root.is_relocatable_executable
12078 || htab->pic_veneer)
12079 size = ARM2THUMB_PIC_GLUE_SIZE;
12080 else if (htab->use_blx)
12081 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
12083 size = ARM2THUMB_STATIC_GLUE_SIZE;
12085 for (offset = 0; offset < htab->arm_glue_size; offset += size)
12087 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
12088 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
12092 /* Thumb->ARM glue. */
12093 if (htab->thumb_glue_size > 0)
12095 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12096 THUMB2ARM_GLUE_SECTION_NAME);
12098 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12099 (output_bfd, osi.sec->output_section);
12100 size = THUMB2ARM_GLUE_SIZE;
12102 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
12104 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
12105 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
12109 /* ARMv4 BX veneers. */
12110 if (htab->bx_glue_size > 0)
12112 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12113 ARM_BX_GLUE_SECTION_NAME);
12115 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12116 (output_bfd, osi.sec->output_section);
12118 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
12121 /* Long calls stubs. */
12122 if (htab->stub_bfd && htab->stub_bfd->sections)
12124 asection* stub_sec;
12126 for (stub_sec = htab->stub_bfd->sections;
12128 stub_sec = stub_sec->next)
12130 /* Ignore non-stub sections. */
12131 if (!strstr (stub_sec->name, STUB_SUFFIX))
12134 osi.sec = stub_sec;
12136 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12137 (output_bfd, osi.sec->output_section);
12139 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
12143 /* Finally, output mapping symbols for the PLT. */
12144 if (!htab->splt || htab->splt->size == 0)
12147 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
12148 htab->splt->output_section);
12149 osi.sec = htab->splt;
12150 /* Output mapping symbols for the plt header. SymbianOS does not have a
12152 if (htab->vxworks_p)
12154 /* VxWorks shared libraries have no PLT header. */
12157 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12159 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
12163 else if (!htab->symbian_p)
12165 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12167 #ifndef FOUR_WORD_PLT
12168 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
12173 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
12177 /* Allocate target specific section data. */
12180 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
12182 if (!sec->used_by_bfd)
12184 _arm_elf_section_data *sdata;
12185 bfd_size_type amt = sizeof (*sdata);
12187 sdata = bfd_zalloc (abfd, amt);
12190 sec->used_by_bfd = sdata;
12193 record_section_with_arm_elf_section_data (sec);
12195 return _bfd_elf_new_section_hook (abfd, sec);
12199 /* Used to order a list of mapping symbols by address. */
12202 elf32_arm_compare_mapping (const void * a, const void * b)
12204 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
12205 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
12207 if (amap->vma > bmap->vma)
12209 else if (amap->vma < bmap->vma)
12211 else if (amap->type > bmap->type)
12212 /* Ensure results do not depend on the host qsort for objects with
12213 multiple mapping symbols at the same address by sorting on type
12216 else if (amap->type < bmap->type)
12223 /* Do code byteswapping. Return FALSE afterwards so that the section is
12224 written out as normal. */
12227 elf32_arm_write_section (bfd *output_bfd,
12228 struct bfd_link_info *link_info,
12230 bfd_byte *contents)
12232 int mapcount, errcount;
12233 _arm_elf_section_data *arm_data;
12234 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
12235 elf32_arm_section_map *map;
12236 elf32_vfp11_erratum_list *errnode;
12239 bfd_vma offset = sec->output_section->vma + sec->output_offset;
12243 /* If this section has not been allocated an _arm_elf_section_data
12244 structure then we cannot record anything. */
12245 arm_data = get_arm_elf_section_data (sec);
12246 if (arm_data == NULL)
12249 mapcount = arm_data->mapcount;
12250 map = arm_data->map;
12251 errcount = arm_data->erratumcount;
12255 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
12257 for (errnode = arm_data->erratumlist; errnode != 0;
12258 errnode = errnode->next)
12260 bfd_vma index = errnode->vma - offset;
12262 switch (errnode->type)
12264 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
12266 bfd_vma branch_to_veneer;
12267 /* Original condition code of instruction, plus bit mask for
12268 ARM B instruction. */
12269 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
12272 /* The instruction is before the label. */
12275 /* Above offset included in -4 below. */
12276 branch_to_veneer = errnode->u.b.veneer->vma
12277 - errnode->vma - 4;
12279 if ((signed) branch_to_veneer < -(1 << 25)
12280 || (signed) branch_to_veneer >= (1 << 25))
12281 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12282 "range"), output_bfd);
12284 insn |= (branch_to_veneer >> 2) & 0xffffff;
12285 contents[endianflip ^ index] = insn & 0xff;
12286 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12287 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12288 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12292 case VFP11_ERRATUM_ARM_VENEER:
12294 bfd_vma branch_from_veneer;
12297 /* Take size of veneer into account. */
12298 branch_from_veneer = errnode->u.v.branch->vma
12299 - errnode->vma - 12;
12301 if ((signed) branch_from_veneer < -(1 << 25)
12302 || (signed) branch_from_veneer >= (1 << 25))
12303 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12304 "range"), output_bfd);
12306 /* Original instruction. */
12307 insn = errnode->u.v.branch->u.b.vfp_insn;
12308 contents[endianflip ^ index] = insn & 0xff;
12309 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12310 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12311 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12313 /* Branch back to insn after original insn. */
12314 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
12315 contents[endianflip ^ (index + 4)] = insn & 0xff;
12316 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
12317 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
12318 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
12331 if (globals->byteswap_code)
12333 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
12336 for (i = 0; i < mapcount; i++)
12338 if (i == mapcount - 1)
12341 end = map[i + 1].vma;
12343 switch (map[i].type)
12346 /* Byte swap code words. */
12347 while (ptr + 3 < end)
12349 tmp = contents[ptr];
12350 contents[ptr] = contents[ptr + 3];
12351 contents[ptr + 3] = tmp;
12352 tmp = contents[ptr + 1];
12353 contents[ptr + 1] = contents[ptr + 2];
12354 contents[ptr + 2] = tmp;
12360 /* Byte swap code halfwords. */
12361 while (ptr + 1 < end)
12363 tmp = contents[ptr];
12364 contents[ptr] = contents[ptr + 1];
12365 contents[ptr + 1] = tmp;
12371 /* Leave data alone. */
12379 arm_data->mapcount = 0;
12380 arm_data->mapsize = 0;
12381 arm_data->map = NULL;
12382 unrecord_section_with_arm_elf_section_data (sec);
12388 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
12390 void * ignore ATTRIBUTE_UNUSED)
12392 unrecord_section_with_arm_elf_section_data (sec);
12396 elf32_arm_close_and_cleanup (bfd * abfd)
12398 if (abfd->sections)
12399 bfd_map_over_sections (abfd,
12400 unrecord_section_via_map_over_sections,
12403 return _bfd_elf_close_and_cleanup (abfd);
12407 elf32_arm_bfd_free_cached_info (bfd * abfd)
12409 if (abfd->sections)
12410 bfd_map_over_sections (abfd,
12411 unrecord_section_via_map_over_sections,
12414 return _bfd_free_cached_info (abfd);
12417 /* Display STT_ARM_TFUNC symbols as functions. */
12420 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
12423 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
12425 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
12426 elfsym->symbol.flags |= BSF_FUNCTION;
12430 /* Mangle thumb function symbols as we read them in. */
12433 elf32_arm_swap_symbol_in (bfd * abfd,
12436 Elf_Internal_Sym *dst)
12438 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
12441 /* New EABI objects mark thumb function symbols by setting the low bit of
12442 the address. Turn these into STT_ARM_TFUNC. */
12443 if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC)
12444 && (dst->st_value & 1))
12446 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
12447 dst->st_value &= ~(bfd_vma) 1;
12453 /* Mangle thumb function symbols as we write them out. */
12456 elf32_arm_swap_symbol_out (bfd *abfd,
12457 const Elf_Internal_Sym *src,
12461 Elf_Internal_Sym newsym;
12463 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12464 of the address set, as per the new EABI. We do this unconditionally
12465 because objcopy does not set the elf header flags until after
12466 it writes out the symbol table. */
12467 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
12470 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
12471 if (newsym.st_shndx != SHN_UNDEF)
12473 /* Do this only for defined symbols. At link type, the static
12474 linker will simulate the work of dynamic linker of resolving
12475 symbols and will carry over the thumbness of found symbols to
12476 the output symbol table. It's not clear how it happens, but
12477 the thumbness of undefined symbols can well be different at
12478 runtime, and writing '1' for them will be confusing for users
12479 and possibly for dynamic linker itself.
12481 newsym.st_value |= 1;
12486 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
12489 /* Add the PT_ARM_EXIDX program header. */
12492 elf32_arm_modify_segment_map (bfd *abfd,
12493 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12495 struct elf_segment_map *m;
12498 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12499 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12501 /* If there is already a PT_ARM_EXIDX header, then we do not
12502 want to add another one. This situation arises when running
12503 "strip"; the input binary already has the header. */
12504 m = elf_tdata (abfd)->segment_map;
12505 while (m && m->p_type != PT_ARM_EXIDX)
12509 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
12512 m->p_type = PT_ARM_EXIDX;
12514 m->sections[0] = sec;
12516 m->next = elf_tdata (abfd)->segment_map;
12517 elf_tdata (abfd)->segment_map = m;
12524 /* We may add a PT_ARM_EXIDX program header. */
12527 elf32_arm_additional_program_headers (bfd *abfd,
12528 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12532 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12533 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12539 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
12542 elf32_arm_is_function_type (unsigned int type)
12544 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
12547 /* We use this to override swap_symbol_in and swap_symbol_out. */
12548 const struct elf_size_info elf32_arm_size_info =
12550 sizeof (Elf32_External_Ehdr),
12551 sizeof (Elf32_External_Phdr),
12552 sizeof (Elf32_External_Shdr),
12553 sizeof (Elf32_External_Rel),
12554 sizeof (Elf32_External_Rela),
12555 sizeof (Elf32_External_Sym),
12556 sizeof (Elf32_External_Dyn),
12557 sizeof (Elf_External_Note),
12561 ELFCLASS32, EV_CURRENT,
12562 bfd_elf32_write_out_phdrs,
12563 bfd_elf32_write_shdrs_and_ehdr,
12564 bfd_elf32_checksum_contents,
12565 bfd_elf32_write_relocs,
12566 elf32_arm_swap_symbol_in,
12567 elf32_arm_swap_symbol_out,
12568 bfd_elf32_slurp_reloc_table,
12569 bfd_elf32_slurp_symbol_table,
12570 bfd_elf32_swap_dyn_in,
12571 bfd_elf32_swap_dyn_out,
12572 bfd_elf32_swap_reloc_in,
12573 bfd_elf32_swap_reloc_out,
12574 bfd_elf32_swap_reloca_in,
12575 bfd_elf32_swap_reloca_out
12578 #define ELF_ARCH bfd_arch_arm
12579 #define ELF_MACHINE_CODE EM_ARM
12580 #ifdef __QNXTARGET__
12581 #define ELF_MAXPAGESIZE 0x1000
12583 #define ELF_MAXPAGESIZE 0x8000
12585 #define ELF_MINPAGESIZE 0x1000
12586 #define ELF_COMMONPAGESIZE 0x1000
12588 #define bfd_elf32_mkobject elf32_arm_mkobject
12590 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12591 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
12592 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12593 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12594 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
12595 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
12596 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
12597 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
12598 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
12599 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
12600 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
12601 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
12602 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
12603 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
12604 #define bfd_elf32_bfd_final_link elf32_arm_final_link
12606 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12607 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
12608 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
12609 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12610 #define elf_backend_check_relocs elf32_arm_check_relocs
12611 #define elf_backend_relocate_section elf32_arm_relocate_section
12612 #define elf_backend_write_section elf32_arm_write_section
12613 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
12614 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
12615 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12616 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12617 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
12618 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
12619 #define elf_backend_post_process_headers elf32_arm_post_process_headers
12620 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
12621 #define elf_backend_object_p elf32_arm_object_p
12622 #define elf_backend_section_flags elf32_arm_section_flags
12623 #define elf_backend_fake_sections elf32_arm_fake_sections
12624 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
12625 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12626 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
12627 #define elf_backend_symbol_processing elf32_arm_symbol_processing
12628 #define elf_backend_size_info elf32_arm_size_info
12629 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
12630 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12631 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12632 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12633 #define elf_backend_is_function_type elf32_arm_is_function_type
12635 #define elf_backend_can_refcount 1
12636 #define elf_backend_can_gc_sections 1
12637 #define elf_backend_plt_readonly 1
12638 #define elf_backend_want_got_plt 1
12639 #define elf_backend_want_plt_sym 0
12640 #define elf_backend_may_use_rel_p 1
12641 #define elf_backend_may_use_rela_p 0
12642 #define elf_backend_default_use_rela_p 0
12644 #define elf_backend_got_header_size 12
12646 #undef elf_backend_obj_attrs_vendor
12647 #define elf_backend_obj_attrs_vendor "aeabi"
12648 #undef elf_backend_obj_attrs_section
12649 #define elf_backend_obj_attrs_section ".ARM.attributes"
12650 #undef elf_backend_obj_attrs_arg_type
12651 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12652 #undef elf_backend_obj_attrs_section_type
12653 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
12654 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
12656 #include "elf32-target.h"
12658 /* VxWorks Targets. */
12660 #undef TARGET_LITTLE_SYM
12661 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
12662 #undef TARGET_LITTLE_NAME
12663 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
12664 #undef TARGET_BIG_SYM
12665 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
12666 #undef TARGET_BIG_NAME
12667 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12669 /* Like elf32_arm_link_hash_table_create -- but overrides
12670 appropriately for VxWorks. */
12672 static struct bfd_link_hash_table *
12673 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
12675 struct bfd_link_hash_table *ret;
12677 ret = elf32_arm_link_hash_table_create (abfd);
12680 struct elf32_arm_link_hash_table *htab
12681 = (struct elf32_arm_link_hash_table *) ret;
12683 htab->vxworks_p = 1;
12689 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
12691 elf32_arm_final_write_processing (abfd, linker);
12692 elf_vxworks_final_write_processing (abfd, linker);
12696 #define elf32_bed elf32_arm_vxworks_bed
12698 #undef bfd_elf32_bfd_link_hash_table_create
12699 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12700 #undef elf_backend_add_symbol_hook
12701 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12702 #undef elf_backend_final_write_processing
12703 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12704 #undef elf_backend_emit_relocs
12705 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
12707 #undef elf_backend_may_use_rel_p
12708 #define elf_backend_may_use_rel_p 0
12709 #undef elf_backend_may_use_rela_p
12710 #define elf_backend_may_use_rela_p 1
12711 #undef elf_backend_default_use_rela_p
12712 #define elf_backend_default_use_rela_p 1
12713 #undef elf_backend_want_plt_sym
12714 #define elf_backend_want_plt_sym 1
12715 #undef ELF_MAXPAGESIZE
12716 #define ELF_MAXPAGESIZE 0x1000
12718 #include "elf32-target.h"
12721 /* Symbian OS Targets. */
12723 #undef TARGET_LITTLE_SYM
12724 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
12725 #undef TARGET_LITTLE_NAME
12726 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
12727 #undef TARGET_BIG_SYM
12728 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
12729 #undef TARGET_BIG_NAME
12730 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
12732 /* Like elf32_arm_link_hash_table_create -- but overrides
12733 appropriately for Symbian OS. */
12735 static struct bfd_link_hash_table *
12736 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
12738 struct bfd_link_hash_table *ret;
12740 ret = elf32_arm_link_hash_table_create (abfd);
12743 struct elf32_arm_link_hash_table *htab
12744 = (struct elf32_arm_link_hash_table *)ret;
12745 /* There is no PLT header for Symbian OS. */
12746 htab->plt_header_size = 0;
12747 /* The PLT entries are each one instruction and one word. */
12748 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
12749 htab->symbian_p = 1;
12750 /* Symbian uses armv5t or above, so use_blx is always true. */
12752 htab->root.is_relocatable_executable = 1;
12757 static const struct bfd_elf_special_section
12758 elf32_arm_symbian_special_sections[] =
12760 /* In a BPABI executable, the dynamic linking sections do not go in
12761 the loadable read-only segment. The post-linker may wish to
12762 refer to these sections, but they are not part of the final
12764 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12765 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12766 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12767 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12768 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
12769 /* These sections do not need to be writable as the SymbianOS
12770 postlinker will arrange things so that no dynamic relocation is
12772 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12773 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12774 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12775 { NULL, 0, 0, 0, 0 }
12779 elf32_arm_symbian_begin_write_processing (bfd *abfd,
12780 struct bfd_link_info *link_info)
12782 /* BPABI objects are never loaded directly by an OS kernel; they are
12783 processed by a postlinker first, into an OS-specific format. If
12784 the D_PAGED bit is set on the file, BFD will align segments on
12785 page boundaries, so that an OS can directly map the file. With
12786 BPABI objects, that just results in wasted space. In addition,
12787 because we clear the D_PAGED bit, map_sections_to_segments will
12788 recognize that the program headers should not be mapped into any
12789 loadable segment. */
12790 abfd->flags &= ~D_PAGED;
12791 elf32_arm_begin_write_processing (abfd, link_info);
12795 elf32_arm_symbian_modify_segment_map (bfd *abfd,
12796 struct bfd_link_info *info)
12798 struct elf_segment_map *m;
12801 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12802 segment. However, because the .dynamic section is not marked
12803 with SEC_LOAD, the generic ELF code will not create such a
12805 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12808 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12809 if (m->p_type == PT_DYNAMIC)
12814 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12815 m->next = elf_tdata (abfd)->segment_map;
12816 elf_tdata (abfd)->segment_map = m;
12820 /* Also call the generic arm routine. */
12821 return elf32_arm_modify_segment_map (abfd, info);
12824 /* Return address for Ith PLT stub in section PLT, for relocation REL
12825 or (bfd_vma) -1 if it should not be included. */
12828 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12829 const arelent *rel ATTRIBUTE_UNUSED)
12831 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12836 #define elf32_bed elf32_arm_symbian_bed
12838 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12839 will process them and then discard them. */
12840 #undef ELF_DYNAMIC_SEC_FLAGS
12841 #define ELF_DYNAMIC_SEC_FLAGS \
12842 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12844 #undef elf_backend_add_symbol_hook
12845 #undef elf_backend_emit_relocs
12847 #undef bfd_elf32_bfd_link_hash_table_create
12848 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12849 #undef elf_backend_special_sections
12850 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12851 #undef elf_backend_begin_write_processing
12852 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12853 #undef elf_backend_final_write_processing
12854 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12856 #undef elf_backend_modify_segment_map
12857 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12859 /* There is no .got section for BPABI objects, and hence no header. */
12860 #undef elf_backend_got_header_size
12861 #define elf_backend_got_header_size 0
12863 /* Similarly, there is no .got.plt section. */
12864 #undef elf_backend_want_got_plt
12865 #define elf_backend_want_got_plt 0
12867 #undef elf_backend_plt_sym_val
12868 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12870 #undef elf_backend_may_use_rel_p
12871 #define elf_backend_may_use_rel_p 1
12872 #undef elf_backend_may_use_rela_p
12873 #define elf_backend_may_use_rela_p 0
12874 #undef elf_backend_default_use_rela_p
12875 #define elf_backend_default_use_rela_p 0
12876 #undef elf_backend_want_plt_sym
12877 #define elf_backend_want_plt_sym 0
12878 #undef ELF_MAXPAGESIZE
12879 #define ELF_MAXPAGESIZE 0x8000
12881 #include "elf32-target.h"