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 || r_type == R_ARM_THM_JUMP24)
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, or it's a
2930 Thumb->Arm branch (not bl). A stub is needed in this case,
2931 but only if this call is not through a PLT entry. Indeed,
2932 PLT stubs handle mode switching already.
2935 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2936 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2938 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2939 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2940 || ((st_type != STT_ARM_TFUNC)
2941 && (((r_type == R_ARM_THM_CALL) && !globals->use_blx)
2942 || (r_type == R_ARM_THM_JUMP24))
2945 if (st_type == STT_ARM_TFUNC)
2947 /* Thumb to thumb. */
2950 stub_type = (info->shared | globals->pic_veneer)
2952 ? ((globals->use_blx
2953 && (r_type ==R_ARM_THM_CALL))
2954 /* V5T and above. Stub starts with ARM code, so
2955 we must be able to switch mode before
2956 reaching it, which is only possible for 'bl'
2957 (ie R_ARM_THM_CALL relocation). */
2958 ? arm_stub_long_branch_any_thumb_pic
2959 /* On V4T, use Thumb code only. */
2960 : arm_stub_long_branch_v4t_thumb_thumb_pic)
2962 /* non-PIC stubs. */
2963 : ((globals->use_blx
2964 && (r_type ==R_ARM_THM_CALL))
2965 /* V5T and above. */
2966 ? arm_stub_long_branch_any_any
2968 : arm_stub_long_branch_v4t_thumb_thumb);
2972 stub_type = (info->shared | globals->pic_veneer)
2974 ? arm_stub_long_branch_thumb_only_pic
2976 : arm_stub_long_branch_thumb_only;
2983 && sym_sec->owner != NULL
2984 && !INTERWORK_FLAG (sym_sec->owner))
2986 (*_bfd_error_handler)
2987 (_("%B(%s): warning: interworking not enabled.\n"
2988 " first occurrence: %B: Thumb call to ARM"),
2989 sym_sec->owner, input_bfd, name);
2992 stub_type = (info->shared | globals->pic_veneer)
2994 ? ((globals->use_blx
2995 && (r_type ==R_ARM_THM_CALL))
2996 /* V5T and above. */
2997 ? arm_stub_long_branch_any_arm_pic
2999 : arm_stub_long_branch_v4t_thumb_arm_pic)
3001 /* non-PIC stubs. */
3002 : ((globals->use_blx
3003 && (r_type ==R_ARM_THM_CALL))
3004 /* V5T and above. */
3005 ? arm_stub_long_branch_any_any
3007 : arm_stub_long_branch_v4t_thumb_arm);
3009 /* Handle v4t short branches. */
3010 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
3011 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
3012 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
3013 stub_type = arm_stub_short_branch_v4t_thumb_arm;
3017 else if (r_type == R_ARM_CALL || r_type == R_ARM_JUMP24 || r_type == R_ARM_PLT32)
3019 if (st_type == STT_ARM_TFUNC)
3024 && sym_sec->owner != NULL
3025 && !INTERWORK_FLAG (sym_sec->owner))
3027 (*_bfd_error_handler)
3028 (_("%B(%s): warning: interworking not enabled.\n"
3029 " first occurrence: %B: ARM call to Thumb"),
3030 sym_sec->owner, input_bfd, name);
3033 /* We have an extra 2-bytes reach because of
3034 the mode change (bit 24 (H) of BLX encoding). */
3035 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
3036 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
3037 || ((r_type == R_ARM_CALL) && !globals->use_blx)
3038 || (r_type == R_ARM_JUMP24)
3039 || (r_type == R_ARM_PLT32))
3041 stub_type = (info->shared | globals->pic_veneer)
3043 ? ((globals->use_blx)
3044 /* V5T and above. */
3045 ? arm_stub_long_branch_any_thumb_pic
3047 : arm_stub_long_branch_v4t_arm_thumb_pic)
3049 /* non-PIC stubs. */
3050 : ((globals->use_blx)
3051 /* V5T and above. */
3052 ? arm_stub_long_branch_any_any
3054 : arm_stub_long_branch_v4t_arm_thumb);
3060 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3061 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3063 stub_type = (info->shared | globals->pic_veneer)
3065 ? arm_stub_long_branch_any_arm_pic
3066 /* non-PIC stubs. */
3067 : arm_stub_long_branch_any_any;
3075 /* Build a name for an entry in the stub hash table. */
3078 elf32_arm_stub_name (const asection *input_section,
3079 const asection *sym_sec,
3080 const struct elf32_arm_link_hash_entry *hash,
3081 const Elf_Internal_Rela *rel)
3088 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
3089 stub_name = bfd_malloc (len);
3090 if (stub_name != NULL)
3091 sprintf (stub_name, "%08x_%s+%x",
3092 input_section->id & 0xffffffff,
3093 hash->root.root.root.string,
3094 (int) rel->r_addend & 0xffffffff);
3098 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3099 stub_name = bfd_malloc (len);
3100 if (stub_name != NULL)
3101 sprintf (stub_name, "%08x_%x:%x+%x",
3102 input_section->id & 0xffffffff,
3103 sym_sec->id & 0xffffffff,
3104 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3105 (int) rel->r_addend & 0xffffffff);
3111 /* Look up an entry in the stub hash. Stub entries are cached because
3112 creating the stub name takes a bit of time. */
3114 static struct elf32_arm_stub_hash_entry *
3115 elf32_arm_get_stub_entry (const asection *input_section,
3116 const asection *sym_sec,
3117 struct elf_link_hash_entry *hash,
3118 const Elf_Internal_Rela *rel,
3119 struct elf32_arm_link_hash_table *htab)
3121 struct elf32_arm_stub_hash_entry *stub_entry;
3122 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3123 const asection *id_sec;
3125 if ((input_section->flags & SEC_CODE) == 0)
3128 /* If this input section is part of a group of sections sharing one
3129 stub section, then use the id of the first section in the group.
3130 Stub names need to include a section id, as there may well be
3131 more than one stub used to reach say, printf, and we need to
3132 distinguish between them. */
3133 id_sec = htab->stub_group[input_section->id].link_sec;
3135 if (h != NULL && h->stub_cache != NULL
3136 && h->stub_cache->h == h
3137 && h->stub_cache->id_sec == id_sec)
3139 stub_entry = h->stub_cache;
3145 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
3146 if (stub_name == NULL)
3149 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3150 stub_name, FALSE, FALSE);
3152 h->stub_cache = stub_entry;
3160 /* Add a new stub entry to the stub hash. Not all fields of the new
3161 stub entry are initialised. */
3163 static struct elf32_arm_stub_hash_entry *
3164 elf32_arm_add_stub (const char *stub_name,
3166 struct elf32_arm_link_hash_table *htab)
3170 struct elf32_arm_stub_hash_entry *stub_entry;
3172 link_sec = htab->stub_group[section->id].link_sec;
3173 stub_sec = htab->stub_group[section->id].stub_sec;
3174 if (stub_sec == NULL)
3176 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3177 if (stub_sec == NULL)
3183 namelen = strlen (link_sec->name);
3184 len = namelen + sizeof (STUB_SUFFIX);
3185 s_name = bfd_alloc (htab->stub_bfd, len);
3189 memcpy (s_name, link_sec->name, namelen);
3190 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3191 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3192 if (stub_sec == NULL)
3194 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3196 htab->stub_group[section->id].stub_sec = stub_sec;
3199 /* Enter this entry into the linker stub hash table. */
3200 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3202 if (stub_entry == NULL)
3204 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3210 stub_entry->stub_sec = stub_sec;
3211 stub_entry->stub_offset = 0;
3212 stub_entry->id_sec = link_sec;
3217 /* Store an Arm insn into an output section not processed by
3218 elf32_arm_write_section. */
3221 put_arm_insn (struct elf32_arm_link_hash_table * htab,
3222 bfd * output_bfd, bfd_vma val, void * ptr)
3224 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3225 bfd_putl32 (val, ptr);
3227 bfd_putb32 (val, ptr);
3230 /* Store a 16-bit Thumb insn into an output section not processed by
3231 elf32_arm_write_section. */
3234 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3235 bfd * output_bfd, bfd_vma val, void * ptr)
3237 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3238 bfd_putl16 (val, ptr);
3240 bfd_putb16 (val, ptr);
3244 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3247 struct elf32_arm_stub_hash_entry *stub_entry;
3248 struct bfd_link_info *info;
3249 struct elf32_arm_link_hash_table *htab;
3257 const insn_sequence *template;
3259 struct elf32_arm_link_hash_table * globals;
3260 int stub_reloc_idx = -1;
3261 int stub_reloc_offset = 0;
3263 /* Massage our args to the form they really have. */
3264 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3265 info = (struct bfd_link_info *) in_arg;
3267 globals = elf32_arm_hash_table (info);
3269 htab = elf32_arm_hash_table (info);
3270 stub_sec = stub_entry->stub_sec;
3272 /* Make a note of the offset within the stubs for this entry. */
3273 stub_entry->stub_offset = stub_sec->size;
3274 loc = stub_sec->contents + stub_entry->stub_offset;
3276 stub_bfd = stub_sec->owner;
3278 /* This is the address of the start of the stub. */
3279 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3280 + stub_entry->stub_offset;
3282 /* This is the address of the stub destination. */
3283 sym_value = (stub_entry->target_value
3284 + stub_entry->target_section->output_offset
3285 + stub_entry->target_section->output_section->vma);
3287 template = stub_entry->stub_template;
3288 template_size = stub_entry->stub_template_size;
3291 for (i = 0; i < template_size; i++)
3293 switch (template[i].type)
3296 put_thumb_insn (globals, stub_bfd, template[i].data, loc + size);
3301 put_arm_insn (globals, stub_bfd, template[i].data, loc + size);
3302 /* Handle cases where the target is encoded within the
3304 if (template[i].r_type == R_ARM_JUMP24)
3307 stub_reloc_offset = size;
3313 bfd_put_32 (stub_bfd, template[i].data, loc + size);
3315 stub_reloc_offset = size;
3325 stub_sec->size += size;
3327 /* Stub size has already been computed in arm_size_one_stub. Check
3329 BFD_ASSERT (size == stub_entry->stub_size);
3331 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3332 if (stub_entry->st_type == STT_ARM_TFUNC)
3335 /* Assume there is one and only one entry to relocate in each stub. */
3336 BFD_ASSERT (stub_reloc_idx != -1);
3338 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx].r_type),
3339 stub_bfd, stub_sec, stub_sec->contents,
3340 stub_entry->stub_offset + stub_reloc_offset,
3341 sym_value, template[stub_reloc_idx].reloc_addend);
3346 /* As above, but don't actually build the stub. Just bump offset so
3347 we know stub section sizes. */
3350 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3353 struct elf32_arm_stub_hash_entry *stub_entry;
3354 struct elf32_arm_link_hash_table *htab;
3355 const insn_sequence *template;
3360 /* Massage our args to the form they really have. */
3361 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3362 htab = (struct elf32_arm_link_hash_table *) in_arg;
3364 switch (stub_entry->stub_type)
3366 case arm_stub_long_branch_any_any:
3367 template = elf32_arm_stub_long_branch_any_any;
3368 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
3370 case arm_stub_long_branch_v4t_arm_thumb:
3371 template = elf32_arm_stub_long_branch_v4t_arm_thumb;
3372 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
3374 case arm_stub_long_branch_thumb_only:
3375 template = elf32_arm_stub_long_branch_thumb_only;
3376 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
3378 case arm_stub_long_branch_v4t_thumb_thumb:
3379 template = elf32_arm_stub_long_branch_v4t_thumb_thumb;
3380 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb);
3382 case arm_stub_long_branch_v4t_thumb_arm:
3383 template = elf32_arm_stub_long_branch_v4t_thumb_arm;
3384 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
3386 case arm_stub_short_branch_v4t_thumb_arm:
3387 template = elf32_arm_stub_short_branch_v4t_thumb_arm;
3388 template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
3390 case arm_stub_long_branch_any_arm_pic:
3391 template = elf32_arm_stub_long_branch_any_arm_pic;
3392 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
3394 case arm_stub_long_branch_any_thumb_pic:
3395 template = elf32_arm_stub_long_branch_any_thumb_pic;
3396 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
3398 case arm_stub_long_branch_v4t_arm_thumb_pic:
3399 template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
3400 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
3402 case arm_stub_long_branch_v4t_thumb_arm_pic:
3403 template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
3404 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
3406 case arm_stub_long_branch_thumb_only_pic:
3407 template = elf32_arm_stub_long_branch_thumb_only_pic;
3408 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
3410 case arm_stub_long_branch_v4t_thumb_thumb_pic:
3411 template = elf32_arm_stub_long_branch_v4t_thumb_thumb_pic;
3412 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_thumb_pic);
3420 for (i = 0; i < template_size; i++)
3422 switch (template[i].type)
3442 stub_entry->stub_size = size;
3443 stub_entry->stub_template = template;
3444 stub_entry->stub_template_size = template_size;
3446 size = (size + 7) & ~7;
3447 stub_entry->stub_sec->size += size;
3452 /* External entry points for sizing and building linker stubs. */
3454 /* Set up various things so that we can make a list of input sections
3455 for each output section included in the link. Returns -1 on error,
3456 0 when no stubs will be needed, and 1 on success. */
3459 elf32_arm_setup_section_lists (bfd *output_bfd,
3460 struct bfd_link_info *info)
3463 unsigned int bfd_count;
3464 int top_id, top_index;
3466 asection **input_list, **list;
3468 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3470 if (! is_elf_hash_table (htab))
3473 /* Count the number of input BFDs and find the top input section id. */
3474 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3476 input_bfd = input_bfd->link_next)
3479 for (section = input_bfd->sections;
3481 section = section->next)
3483 if (top_id < section->id)
3484 top_id = section->id;
3487 htab->bfd_count = bfd_count;
3489 amt = sizeof (struct map_stub) * (top_id + 1);
3490 htab->stub_group = bfd_zmalloc (amt);
3491 if (htab->stub_group == NULL)
3494 /* We can't use output_bfd->section_count here to find the top output
3495 section index as some sections may have been removed, and
3496 _bfd_strip_section_from_output doesn't renumber the indices. */
3497 for (section = output_bfd->sections, top_index = 0;
3499 section = section->next)
3501 if (top_index < section->index)
3502 top_index = section->index;
3505 htab->top_index = top_index;
3506 amt = sizeof (asection *) * (top_index + 1);
3507 input_list = bfd_malloc (amt);
3508 htab->input_list = input_list;
3509 if (input_list == NULL)
3512 /* For sections we aren't interested in, mark their entries with a
3513 value we can check later. */
3514 list = input_list + top_index;
3516 *list = bfd_abs_section_ptr;
3517 while (list-- != input_list);
3519 for (section = output_bfd->sections;
3521 section = section->next)
3523 if ((section->flags & SEC_CODE) != 0)
3524 input_list[section->index] = NULL;
3530 /* The linker repeatedly calls this function for each input section,
3531 in the order that input sections are linked into output sections.
3532 Build lists of input sections to determine groupings between which
3533 we may insert linker stubs. */
3536 elf32_arm_next_input_section (struct bfd_link_info *info,
3539 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3541 if (isec->output_section->index <= htab->top_index)
3543 asection **list = htab->input_list + isec->output_section->index;
3545 if (*list != bfd_abs_section_ptr)
3547 /* Steal the link_sec pointer for our list. */
3548 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3549 /* This happens to make the list in reverse order,
3550 which we reverse later. */
3551 PREV_SEC (isec) = *list;
3557 /* See whether we can group stub sections together. Grouping stub
3558 sections may result in fewer stubs. More importantly, we need to
3559 put all .init* and .fini* stubs at the end of the .init or
3560 .fini output sections respectively, because glibc splits the
3561 _init and _fini functions into multiple parts. Putting a stub in
3562 the middle of a function is not a good idea. */
3565 group_sections (struct elf32_arm_link_hash_table *htab,
3566 bfd_size_type stub_group_size,
3567 bfd_boolean stubs_always_after_branch)
3569 asection **list = htab->input_list;
3573 asection *tail = *list;
3576 if (tail == bfd_abs_section_ptr)
3579 /* Reverse the list: we must avoid placing stubs at the
3580 beginning of the section because the beginning of the text
3581 section may be required for an interrupt vector in bare metal
3583 #define NEXT_SEC PREV_SEC
3585 while (tail != NULL)
3587 /* Pop from tail. */
3588 asection *item = tail;
3589 tail = PREV_SEC (item);
3592 NEXT_SEC (item) = head;
3596 while (head != NULL)
3600 bfd_vma stub_group_start = head->output_offset;
3601 bfd_vma end_of_next;
3604 while (NEXT_SEC (curr) != NULL)
3606 next = NEXT_SEC (curr);
3607 end_of_next = next->output_offset + next->size;
3608 if (end_of_next - stub_group_start >= stub_group_size)
3609 /* End of NEXT is too far from start, so stop. */
3611 /* Add NEXT to the group. */
3615 /* OK, the size from the start to the start of CURR is less
3616 than stub_group_size and thus can be handled by one stub
3617 section. (Or the head section is itself larger than
3618 stub_group_size, in which case we may be toast.)
3619 We should really be keeping track of the total size of
3620 stubs added here, as stubs contribute to the final output
3624 next = NEXT_SEC (head);
3625 /* Set up this stub group. */
3626 htab->stub_group[head->id].link_sec = curr;
3628 while (head != curr && (head = next) != NULL);
3630 /* But wait, there's more! Input sections up to stub_group_size
3631 bytes after the stub section can be handled by it too. */
3632 if (!stubs_always_after_branch)
3634 stub_group_start = curr->output_offset + curr->size;
3636 while (next != NULL)
3638 end_of_next = next->output_offset + next->size;
3639 if (end_of_next - stub_group_start >= stub_group_size)
3640 /* End of NEXT is too far from stubs, so stop. */
3642 /* Add NEXT to the stub group. */
3644 next = NEXT_SEC (head);
3645 htab->stub_group[head->id].link_sec = curr;
3651 while (list++ != htab->input_list + htab->top_index);
3653 free (htab->input_list);
3658 /* Determine and set the size of the stub section for a final link.
3660 The basic idea here is to examine all the relocations looking for
3661 PC-relative calls to a target that is unreachable with a "bl"
3665 elf32_arm_size_stubs (bfd *output_bfd,
3667 struct bfd_link_info *info,
3668 bfd_signed_vma group_size,
3669 asection * (*add_stub_section) (const char *, asection *),
3670 void (*layout_sections_again) (void))
3672 bfd_size_type stub_group_size;
3673 bfd_boolean stubs_always_after_branch;
3674 bfd_boolean stub_changed = 0;
3675 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3677 /* Propagate mach to stub bfd, because it may not have been
3678 finalized when we created stub_bfd. */
3679 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3680 bfd_get_mach (output_bfd));
3682 /* Stash our params away. */
3683 htab->stub_bfd = stub_bfd;
3684 htab->add_stub_section = add_stub_section;
3685 htab->layout_sections_again = layout_sections_again;
3686 stubs_always_after_branch = group_size < 0;
3688 stub_group_size = -group_size;
3690 stub_group_size = group_size;
3692 if (stub_group_size == 1)
3694 /* Default values. */
3695 /* Thumb branch range is +-4MB has to be used as the default
3696 maximum size (a given section can contain both ARM and Thumb
3697 code, so the worst case has to be taken into account).
3699 This value is 24K less than that, which allows for 2025
3700 12-byte stubs. If we exceed that, then we will fail to link.
3701 The user will have to relink with an explicit group size
3703 stub_group_size = 4170000;
3706 group_sections (htab, stub_group_size, stubs_always_after_branch);
3711 unsigned int bfd_indx;
3714 for (input_bfd = info->input_bfds, bfd_indx = 0;
3716 input_bfd = input_bfd->link_next, bfd_indx++)
3718 Elf_Internal_Shdr *symtab_hdr;
3720 Elf_Internal_Sym *local_syms = NULL;
3722 /* We'll need the symbol table in a second. */
3723 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3724 if (symtab_hdr->sh_info == 0)
3727 /* Walk over each section attached to the input bfd. */
3728 for (section = input_bfd->sections;
3730 section = section->next)
3732 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3734 /* If there aren't any relocs, then there's nothing more
3736 if ((section->flags & SEC_RELOC) == 0
3737 || section->reloc_count == 0
3738 || (section->flags & SEC_CODE) == 0)
3741 /* If this section is a link-once section that will be
3742 discarded, then don't create any stubs. */
3743 if (section->output_section == NULL
3744 || section->output_section->owner != output_bfd)
3747 /* Get the relocs. */
3749 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3750 NULL, info->keep_memory);
3751 if (internal_relocs == NULL)
3752 goto error_ret_free_local;
3754 /* Now examine each relocation. */
3755 irela = internal_relocs;
3756 irelaend = irela + section->reloc_count;
3757 for (; irela < irelaend; irela++)
3759 unsigned int r_type, r_indx;
3760 enum elf32_arm_stub_type stub_type;
3761 struct elf32_arm_stub_hash_entry *stub_entry;
3764 bfd_vma destination;
3765 struct elf32_arm_link_hash_entry *hash;
3766 const char *sym_name;
3768 const asection *id_sec;
3769 unsigned char st_type;
3771 r_type = ELF32_R_TYPE (irela->r_info);
3772 r_indx = ELF32_R_SYM (irela->r_info);
3774 if (r_type >= (unsigned int) R_ARM_max)
3776 bfd_set_error (bfd_error_bad_value);
3777 error_ret_free_internal:
3778 if (elf_section_data (section)->relocs == NULL)
3779 free (internal_relocs);
3780 goto error_ret_free_local;
3783 /* Only look for stubs on branch instructions. */
3784 if ((r_type != (unsigned int) R_ARM_CALL)
3785 && (r_type != (unsigned int) R_ARM_THM_CALL)
3786 && (r_type != (unsigned int) R_ARM_JUMP24)
3787 && (r_type != (unsigned int) R_ARM_THM_JUMP24)
3788 && (r_type != (unsigned int) R_ARM_PLT32))
3791 /* Now determine the call target, its name, value,
3798 if (r_indx < symtab_hdr->sh_info)
3800 /* It's a local symbol. */
3801 Elf_Internal_Sym *sym;
3802 Elf_Internal_Shdr *hdr;
3804 if (local_syms == NULL)
3807 = (Elf_Internal_Sym *) symtab_hdr->contents;
3808 if (local_syms == NULL)
3810 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3811 symtab_hdr->sh_info, 0,
3813 if (local_syms == NULL)
3814 goto error_ret_free_internal;
3817 sym = local_syms + r_indx;
3818 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3819 sym_sec = hdr->bfd_section;
3820 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3821 sym_value = sym->st_value;
3822 destination = (sym_value + irela->r_addend
3823 + sym_sec->output_offset
3824 + sym_sec->output_section->vma);
3825 st_type = ELF_ST_TYPE (sym->st_info);
3827 = bfd_elf_string_from_elf_section (input_bfd,
3828 symtab_hdr->sh_link,
3833 /* It's an external symbol. */
3836 e_indx = r_indx - symtab_hdr->sh_info;
3837 hash = ((struct elf32_arm_link_hash_entry *)
3838 elf_sym_hashes (input_bfd)[e_indx]);
3840 while (hash->root.root.type == bfd_link_hash_indirect
3841 || hash->root.root.type == bfd_link_hash_warning)
3842 hash = ((struct elf32_arm_link_hash_entry *)
3843 hash->root.root.u.i.link);
3845 if (hash->root.root.type == bfd_link_hash_defined
3846 || hash->root.root.type == bfd_link_hash_defweak)
3848 sym_sec = hash->root.root.u.def.section;
3849 sym_value = hash->root.root.u.def.value;
3850 if (sym_sec->output_section != NULL)
3851 destination = (sym_value + irela->r_addend
3852 + sym_sec->output_offset
3853 + sym_sec->output_section->vma);
3855 else if ((hash->root.root.type == bfd_link_hash_undefined)
3856 || (hash->root.root.type == bfd_link_hash_undefweak))
3858 /* For a shared library, use the PLT stub as
3859 target address to decide whether a long
3860 branch stub is needed.
3861 For absolute code, they cannot be handled. */
3862 struct elf32_arm_link_hash_table *globals =
3863 elf32_arm_hash_table (info);
3865 if (globals->splt != NULL && hash != NULL
3866 && hash->root.plt.offset != (bfd_vma) -1)
3868 sym_sec = globals->splt;
3869 sym_value = hash->root.plt.offset;
3870 if (sym_sec->output_section != NULL)
3871 destination = (sym_value
3872 + sym_sec->output_offset
3873 + sym_sec->output_section->vma);
3880 bfd_set_error (bfd_error_bad_value);
3881 goto error_ret_free_internal;
3883 st_type = ELF_ST_TYPE (hash->root.type);
3884 sym_name = hash->root.root.root.string;
3887 /* Determine what (if any) linker stub is needed. */
3888 stub_type = arm_type_of_stub (info, section, irela, st_type,
3889 hash, destination, sym_sec,
3890 input_bfd, sym_name);
3891 if (stub_type == arm_stub_none)
3894 /* Support for grouping stub sections. */
3895 id_sec = htab->stub_group[section->id].link_sec;
3897 /* Get the name of this stub. */
3898 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3900 goto error_ret_free_internal;
3902 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3905 if (stub_entry != NULL)
3907 /* The proper stub has already been created. */
3912 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
3913 if (stub_entry == NULL)
3916 goto error_ret_free_internal;
3919 stub_entry->target_value = sym_value;
3920 stub_entry->target_section = sym_sec;
3921 stub_entry->stub_type = stub_type;
3922 stub_entry->h = hash;
3923 stub_entry->st_type = st_type;
3925 if (sym_name == NULL)
3926 sym_name = "unnamed";
3927 stub_entry->output_name
3928 = bfd_alloc (htab->stub_bfd,
3929 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3930 + strlen (sym_name));
3931 if (stub_entry->output_name == NULL)
3934 goto error_ret_free_internal;
3937 /* For historical reasons, use the existing names for
3938 ARM-to-Thumb and Thumb-to-ARM stubs. */
3939 if ( ((r_type == (unsigned int) R_ARM_THM_CALL)
3940 || (r_type == (unsigned int) R_ARM_THM_JUMP24))
3941 && st_type != STT_ARM_TFUNC)
3942 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3944 else if ( ((r_type == (unsigned int) R_ARM_CALL)
3945 || (r_type == (unsigned int) R_ARM_JUMP24))
3946 && st_type == STT_ARM_TFUNC)
3947 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3950 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3953 stub_changed = TRUE;
3956 /* We're done with the internal relocs, free them. */
3957 if (elf_section_data (section)->relocs == NULL)
3958 free (internal_relocs);
3965 /* OK, we've added some stubs. Find out the new size of the
3967 for (stub_sec = htab->stub_bfd->sections;
3969 stub_sec = stub_sec->next)
3971 /* Ignore non-stub sections. */
3972 if (!strstr (stub_sec->name, STUB_SUFFIX))
3978 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3980 /* Ask the linker to do its stuff. */
3981 (*htab->layout_sections_again) ();
3982 stub_changed = FALSE;
3987 error_ret_free_local:
3991 /* Build all the stubs associated with the current output file. The
3992 stubs are kept in a hash table attached to the main linker hash
3993 table. We also set up the .plt entries for statically linked PIC
3994 functions here. This function is called via arm_elf_finish in the
3998 elf32_arm_build_stubs (struct bfd_link_info *info)
4001 struct bfd_hash_table *table;
4002 struct elf32_arm_link_hash_table *htab;
4004 htab = elf32_arm_hash_table (info);
4006 for (stub_sec = htab->stub_bfd->sections;
4008 stub_sec = stub_sec->next)
4012 /* Ignore non-stub sections. */
4013 if (!strstr (stub_sec->name, STUB_SUFFIX))
4016 /* Allocate memory to hold the linker stubs. */
4017 size = stub_sec->size;
4018 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
4019 if (stub_sec->contents == NULL && size != 0)
4024 /* Build the stubs as directed by the stub hash table. */
4025 table = &htab->stub_hash_table;
4026 bfd_hash_traverse (table, arm_build_one_stub, info);
4031 /* Locate the Thumb encoded calling stub for NAME. */
4033 static struct elf_link_hash_entry *
4034 find_thumb_glue (struct bfd_link_info *link_info,
4036 char **error_message)
4039 struct elf_link_hash_entry *hash;
4040 struct elf32_arm_link_hash_table *hash_table;
4042 /* We need a pointer to the armelf specific hash table. */
4043 hash_table = elf32_arm_hash_table (link_info);
4045 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4046 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4048 BFD_ASSERT (tmp_name);
4050 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4052 hash = elf_link_hash_lookup
4053 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4056 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
4057 tmp_name, name) == -1)
4058 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4065 /* Locate the ARM encoded calling stub for NAME. */
4067 static struct elf_link_hash_entry *
4068 find_arm_glue (struct bfd_link_info *link_info,
4070 char **error_message)
4073 struct elf_link_hash_entry *myh;
4074 struct elf32_arm_link_hash_table *hash_table;
4076 /* We need a pointer to the elfarm specific hash table. */
4077 hash_table = elf32_arm_hash_table (link_info);
4079 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4080 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4082 BFD_ASSERT (tmp_name);
4084 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4086 myh = elf_link_hash_lookup
4087 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4090 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
4091 tmp_name, name) == -1)
4092 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
4099 /* ARM->Thumb glue (static images):
4103 ldr r12, __func_addr
4106 .word func @ behave as if you saw a ARM_32 reloc.
4113 .word func @ behave as if you saw a ARM_32 reloc.
4115 (relocatable images)
4118 ldr r12, __func_offset
4124 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4125 static const insn32 a2t1_ldr_insn = 0xe59fc000;
4126 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
4127 static const insn32 a2t3_func_addr_insn = 0x00000001;
4129 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4130 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
4131 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
4133 #define ARM2THUMB_PIC_GLUE_SIZE 16
4134 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
4135 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
4136 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
4138 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4142 __func_from_thumb: __func_from_thumb:
4144 nop ldr r6, __func_addr
4154 #define THUMB2ARM_GLUE_SIZE 8
4155 static const insn16 t2a1_bx_pc_insn = 0x4778;
4156 static const insn16 t2a2_noop_insn = 0x46c0;
4157 static const insn32 t2a3_b_insn = 0xea000000;
4159 #define VFP11_ERRATUM_VENEER_SIZE 8
4161 #define ARM_BX_VENEER_SIZE 12
4162 static const insn32 armbx1_tst_insn = 0xe3100001;
4163 static const insn32 armbx2_moveq_insn = 0x01a0f000;
4164 static const insn32 armbx3_bx_insn = 0xe12fff10;
4166 #ifndef ELFARM_NABI_C_INCLUDED
4168 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
4171 bfd_byte * contents;
4175 /* Do not include empty glue sections in the output. */
4178 s = bfd_get_section_by_name (abfd, name);
4180 s->flags |= SEC_EXCLUDE;
4185 BFD_ASSERT (abfd != NULL);
4187 s = bfd_get_section_by_name (abfd, name);
4188 BFD_ASSERT (s != NULL);
4190 contents = bfd_alloc (abfd, size);
4192 BFD_ASSERT (s->size == size);
4193 s->contents = contents;
4197 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
4199 struct elf32_arm_link_hash_table * globals;
4201 globals = elf32_arm_hash_table (info);
4202 BFD_ASSERT (globals != NULL);
4204 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4205 globals->arm_glue_size,
4206 ARM2THUMB_GLUE_SECTION_NAME);
4208 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4209 globals->thumb_glue_size,
4210 THUMB2ARM_GLUE_SECTION_NAME);
4212 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4213 globals->vfp11_erratum_glue_size,
4214 VFP11_ERRATUM_VENEER_SECTION_NAME);
4216 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4217 globals->bx_glue_size,
4218 ARM_BX_GLUE_SECTION_NAME);
4223 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4224 returns the symbol identifying the stub. */
4226 static struct elf_link_hash_entry *
4227 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
4228 struct elf_link_hash_entry * h)
4230 const char * name = h->root.root.string;
4233 struct elf_link_hash_entry * myh;
4234 struct bfd_link_hash_entry * bh;
4235 struct elf32_arm_link_hash_table * globals;
4239 globals = elf32_arm_hash_table (link_info);
4241 BFD_ASSERT (globals != NULL);
4242 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4244 s = bfd_get_section_by_name
4245 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
4247 BFD_ASSERT (s != NULL);
4249 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4251 BFD_ASSERT (tmp_name);
4253 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4255 myh = elf_link_hash_lookup
4256 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
4260 /* We've already seen this guy. */
4265 /* The only trick here is using hash_table->arm_glue_size as the value.
4266 Even though the section isn't allocated yet, this is where we will be
4267 putting it. The +1 on the value marks that the stub has not been
4268 output yet - not that it is a Thumb function. */
4270 val = globals->arm_glue_size + 1;
4271 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4272 tmp_name, BSF_GLOBAL, s, val,
4273 NULL, TRUE, FALSE, &bh);
4275 myh = (struct elf_link_hash_entry *) bh;
4276 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4277 myh->forced_local = 1;
4281 if (link_info->shared || globals->root.is_relocatable_executable
4282 || globals->pic_veneer)
4283 size = ARM2THUMB_PIC_GLUE_SIZE;
4284 else if (globals->use_blx)
4285 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
4287 size = ARM2THUMB_STATIC_GLUE_SIZE;
4290 globals->arm_glue_size += size;
4295 /* Allocate space for ARMv4 BX veneers. */
4298 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4301 struct elf32_arm_link_hash_table *globals;
4303 struct elf_link_hash_entry *myh;
4304 struct bfd_link_hash_entry *bh;
4307 /* BX PC does not need a veneer. */
4311 globals = elf32_arm_hash_table (link_info);
4313 BFD_ASSERT (globals != NULL);
4314 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4316 /* Check if this veneer has already been allocated. */
4317 if (globals->bx_glue_offset[reg])
4320 s = bfd_get_section_by_name
4321 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4323 BFD_ASSERT (s != NULL);
4325 /* Add symbol for veneer. */
4326 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
4328 BFD_ASSERT (tmp_name);
4330 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
4332 myh = elf_link_hash_lookup
4333 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
4335 BFD_ASSERT (myh == NULL);
4338 val = globals->bx_glue_size;
4339 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4340 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4341 NULL, TRUE, FALSE, &bh);
4343 myh = (struct elf_link_hash_entry *) bh;
4344 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4345 myh->forced_local = 1;
4347 s->size += ARM_BX_VENEER_SIZE;
4348 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4349 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4353 /* Add an entry to the code/data map for section SEC. */
4356 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4358 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4359 unsigned int newidx;
4361 if (sec_data->map == NULL)
4363 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4364 sec_data->mapcount = 0;
4365 sec_data->mapsize = 1;
4368 newidx = sec_data->mapcount++;
4370 if (sec_data->mapcount > sec_data->mapsize)
4372 sec_data->mapsize *= 2;
4373 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4374 * sizeof (elf32_arm_section_map));
4379 sec_data->map[newidx].vma = vma;
4380 sec_data->map[newidx].type = type;
4385 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4386 veneers are handled for now. */
4389 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4390 elf32_vfp11_erratum_list *branch,
4392 asection *branch_sec,
4393 unsigned int offset)
4396 struct elf32_arm_link_hash_table *hash_table;
4398 struct elf_link_hash_entry *myh;
4399 struct bfd_link_hash_entry *bh;
4401 struct _arm_elf_section_data *sec_data;
4403 elf32_vfp11_erratum_list *newerr;
4405 hash_table = elf32_arm_hash_table (link_info);
4407 BFD_ASSERT (hash_table != NULL);
4408 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4410 s = bfd_get_section_by_name
4411 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
4413 sec_data = elf32_arm_section_data (s);
4415 BFD_ASSERT (s != NULL);
4417 tmp_name = bfd_malloc ((bfd_size_type) strlen
4418 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
4420 BFD_ASSERT (tmp_name);
4422 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4423 hash_table->num_vfp11_fixes);
4425 myh = elf_link_hash_lookup
4426 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4428 BFD_ASSERT (myh == NULL);
4431 val = hash_table->vfp11_erratum_glue_size;
4432 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4433 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4434 NULL, TRUE, FALSE, &bh);
4436 myh = (struct elf_link_hash_entry *) bh;
4437 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4438 myh->forced_local = 1;
4440 /* Link veneer back to calling location. */
4441 errcount = ++(sec_data->erratumcount);
4442 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
4444 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4446 newerr->u.v.branch = branch;
4447 newerr->u.v.id = hash_table->num_vfp11_fixes;
4448 branch->u.b.veneer = newerr;
4450 newerr->next = sec_data->erratumlist;
4451 sec_data->erratumlist = newerr;
4453 /* A symbol for the return from the veneer. */
4454 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4455 hash_table->num_vfp11_fixes);
4457 myh = elf_link_hash_lookup
4458 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4465 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4466 branch_sec, val, NULL, TRUE, FALSE, &bh);
4468 myh = (struct elf_link_hash_entry *) bh;
4469 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4470 myh->forced_local = 1;
4474 /* Generate a mapping symbol for the veneer section, and explicitly add an
4475 entry for that symbol to the code/data map for the section. */
4476 if (hash_table->vfp11_erratum_glue_size == 0)
4479 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4480 ever requires this erratum fix. */
4481 _bfd_generic_link_add_one_symbol (link_info,
4482 hash_table->bfd_of_glue_owner, "$a",
4483 BSF_LOCAL, s, 0, NULL,
4486 myh = (struct elf_link_hash_entry *) bh;
4487 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4488 myh->forced_local = 1;
4490 /* The elf32_arm_init_maps function only cares about symbols from input
4491 BFDs. We must make a note of this generated mapping symbol
4492 ourselves so that code byteswapping works properly in
4493 elf32_arm_write_section. */
4494 elf32_arm_section_map_add (s, 'a', 0);
4497 s->size += VFP11_ERRATUM_VENEER_SIZE;
4498 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4499 hash_table->num_vfp11_fixes++;
4501 /* The offset of the veneer. */
4505 #define ARM_GLUE_SECTION_FLAGS \
4506 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
4507 | SEC_READONLY | SEC_LINKER_CREATED)
4509 /* Create a fake section for use by the ARM backend of the linker. */
4512 arm_make_glue_section (bfd * abfd, const char * name)
4516 sec = bfd_get_section_by_name (abfd, name);
4521 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
4524 || !bfd_set_section_alignment (abfd, sec, 2))
4527 /* Set the gc mark to prevent the section from being removed by garbage
4528 collection, despite the fact that no relocs refer to this section. */
4534 /* Add the glue sections to ABFD. This function is called from the
4535 linker scripts in ld/emultempl/{armelf}.em. */
4538 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4539 struct bfd_link_info *info)
4541 /* If we are only performing a partial
4542 link do not bother adding the glue. */
4543 if (info->relocatable)
4546 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
4547 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
4548 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
4549 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
4552 /* Select a BFD to be used to hold the sections used by the glue code.
4553 This function is called from the linker scripts in ld/emultempl/
4557 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
4559 struct elf32_arm_link_hash_table *globals;
4561 /* If we are only performing a partial link
4562 do not bother getting a bfd to hold the glue. */
4563 if (info->relocatable)
4566 /* Make sure we don't attach the glue sections to a dynamic object. */
4567 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4569 globals = elf32_arm_hash_table (info);
4571 BFD_ASSERT (globals != NULL);
4573 if (globals->bfd_of_glue_owner != NULL)
4576 /* Save the bfd for later use. */
4577 globals->bfd_of_glue_owner = abfd;
4583 check_use_blx (struct elf32_arm_link_hash_table *globals)
4585 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4587 globals->use_blx = 1;
4591 bfd_elf32_arm_process_before_allocation (bfd *abfd,
4592 struct bfd_link_info *link_info)
4594 Elf_Internal_Shdr *symtab_hdr;
4595 Elf_Internal_Rela *internal_relocs = NULL;
4596 Elf_Internal_Rela *irel, *irelend;
4597 bfd_byte *contents = NULL;
4600 struct elf32_arm_link_hash_table *globals;
4602 /* If we are only performing a partial link do not bother
4603 to construct any glue. */
4604 if (link_info->relocatable)
4607 /* Here we have a bfd that is to be included on the link. We have a
4608 hook to do reloc rummaging, before section sizes are nailed down. */
4609 globals = elf32_arm_hash_table (link_info);
4611 BFD_ASSERT (globals != NULL);
4613 check_use_blx (globals);
4615 if (globals->byteswap_code && !bfd_big_endian (abfd))
4617 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4622 /* PR 5398: If we have not decided to include any loadable sections in
4623 the output then we will not have a glue owner bfd. This is OK, it
4624 just means that there is nothing else for us to do here. */
4625 if (globals->bfd_of_glue_owner == NULL)
4628 /* Rummage around all the relocs and map the glue vectors. */
4629 sec = abfd->sections;
4634 for (; sec != NULL; sec = sec->next)
4636 if (sec->reloc_count == 0)
4639 if ((sec->flags & SEC_EXCLUDE) != 0)
4642 symtab_hdr = & elf_symtab_hdr (abfd);
4644 /* Load the relocs. */
4646 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
4648 if (internal_relocs == NULL)
4651 irelend = internal_relocs + sec->reloc_count;
4652 for (irel = internal_relocs; irel < irelend; irel++)
4655 unsigned long r_index;
4657 struct elf_link_hash_entry *h;
4659 r_type = ELF32_R_TYPE (irel->r_info);
4660 r_index = ELF32_R_SYM (irel->r_info);
4662 /* These are the only relocation types we care about. */
4663 if ( r_type != R_ARM_PC24
4664 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
4667 /* Get the section contents if we haven't done so already. */
4668 if (contents == NULL)
4670 /* Get cached copy if it exists. */
4671 if (elf_section_data (sec)->this_hdr.contents != NULL)
4672 contents = elf_section_data (sec)->this_hdr.contents;
4675 /* Go get them off disk. */
4676 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
4681 if (r_type == R_ARM_V4BX)
4685 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4686 record_arm_bx_glue (link_info, reg);
4690 /* If the relocation is not against a symbol it cannot concern us. */
4693 /* We don't care about local symbols. */
4694 if (r_index < symtab_hdr->sh_info)
4697 /* This is an external symbol. */
4698 r_index -= symtab_hdr->sh_info;
4699 h = (struct elf_link_hash_entry *)
4700 elf_sym_hashes (abfd)[r_index];
4702 /* If the relocation is against a static symbol it must be within
4703 the current section and so cannot be a cross ARM/Thumb relocation. */
4707 /* If the call will go through a PLT entry then we do not need
4709 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
4715 /* This one is a call from arm code. We need to look up
4716 the target of the call. If it is a thumb target, we
4718 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
4719 record_arm_to_thumb_glue (link_info, h);
4727 if (contents != NULL
4728 && elf_section_data (sec)->this_hdr.contents != contents)
4732 if (internal_relocs != NULL
4733 && elf_section_data (sec)->relocs != internal_relocs)
4734 free (internal_relocs);
4735 internal_relocs = NULL;
4741 if (contents != NULL
4742 && elf_section_data (sec)->this_hdr.contents != contents)
4744 if (internal_relocs != NULL
4745 && elf_section_data (sec)->relocs != internal_relocs)
4746 free (internal_relocs);
4753 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4756 bfd_elf32_arm_init_maps (bfd *abfd)
4758 Elf_Internal_Sym *isymbuf;
4759 Elf_Internal_Shdr *hdr;
4760 unsigned int i, localsyms;
4762 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4763 if (! is_arm_elf (abfd))
4766 if ((abfd->flags & DYNAMIC) != 0)
4769 hdr = & elf_symtab_hdr (abfd);
4770 localsyms = hdr->sh_info;
4772 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4773 should contain the number of local symbols, which should come before any
4774 global symbols. Mapping symbols are always local. */
4775 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4778 /* No internal symbols read? Skip this BFD. */
4779 if (isymbuf == NULL)
4782 for (i = 0; i < localsyms; i++)
4784 Elf_Internal_Sym *isym = &isymbuf[i];
4785 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4789 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4791 name = bfd_elf_string_from_elf_section (abfd,
4792 hdr->sh_link, isym->st_name);
4794 if (bfd_is_arm_special_symbol_name (name,
4795 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4796 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4803 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4805 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4806 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
4808 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4809 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4811 switch (globals->vfp11_fix)
4813 case BFD_ARM_VFP11_FIX_DEFAULT:
4814 case BFD_ARM_VFP11_FIX_NONE:
4815 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4819 /* Give a warning, but do as the user requests anyway. */
4820 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4821 "workaround is not necessary for target architecture"), obfd);
4824 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4825 /* For earlier architectures, we might need the workaround, but do not
4826 enable it by default. If users is running with broken hardware, they
4827 must enable the erratum fix explicitly. */
4828 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4832 enum bfd_arm_vfp11_pipe
4840 /* Return a VFP register number. This is encoded as RX:X for single-precision
4841 registers, or X:RX for double-precision registers, where RX is the group of
4842 four bits in the instruction encoding and X is the single extension bit.
4843 RX and X fields are specified using their lowest (starting) bit. The return
4846 0...31: single-precision registers s0...s31
4847 32...63: double-precision registers d0...d31.
4849 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4850 encounter VFP3 instructions, so we allow the full range for DP registers. */
4853 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4857 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4859 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4862 /* Set bits in *WMASK according to a register number REG as encoded by
4863 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4866 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4871 *wmask |= 3 << ((reg - 32) * 2);
4874 /* Return TRUE if WMASK overwrites anything in REGS. */
4877 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4881 for (i = 0; i < numregs; i++)
4883 unsigned int reg = regs[i];
4885 if (reg < 32 && (wmask & (1 << reg)) != 0)
4893 if ((wmask & (3 << (reg * 2))) != 0)
4900 /* In this function, we're interested in two things: finding input registers
4901 for VFP data-processing instructions, and finding the set of registers which
4902 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4903 hold the written set, so FLDM etc. are easy to deal with (we're only
4904 interested in 32 SP registers or 16 dp registers, due to the VFP version
4905 implemented by the chip in question). DP registers are marked by setting
4906 both SP registers in the write mask). */
4908 static enum bfd_arm_vfp11_pipe
4909 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4912 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4913 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4915 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4918 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4919 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4921 pqrs = ((insn & 0x00800000) >> 20)
4922 | ((insn & 0x00300000) >> 19)
4923 | ((insn & 0x00000040) >> 6);
4927 case 0: /* fmac[sd]. */
4928 case 1: /* fnmac[sd]. */
4929 case 2: /* fmsc[sd]. */
4930 case 3: /* fnmsc[sd]. */
4932 bfd_arm_vfp11_write_mask (destmask, fd);
4934 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4939 case 4: /* fmul[sd]. */
4940 case 5: /* fnmul[sd]. */
4941 case 6: /* fadd[sd]. */
4942 case 7: /* fsub[sd]. */
4946 case 8: /* fdiv[sd]. */
4949 bfd_arm_vfp11_write_mask (destmask, fd);
4950 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4955 case 15: /* extended opcode. */
4957 unsigned int extn = ((insn >> 15) & 0x1e)
4958 | ((insn >> 7) & 1);
4962 case 0: /* fcpy[sd]. */
4963 case 1: /* fabs[sd]. */
4964 case 2: /* fneg[sd]. */
4965 case 8: /* fcmp[sd]. */
4966 case 9: /* fcmpe[sd]. */
4967 case 10: /* fcmpz[sd]. */
4968 case 11: /* fcmpez[sd]. */
4969 case 16: /* fuito[sd]. */
4970 case 17: /* fsito[sd]. */
4971 case 24: /* ftoui[sd]. */
4972 case 25: /* ftouiz[sd]. */
4973 case 26: /* ftosi[sd]. */
4974 case 27: /* ftosiz[sd]. */
4975 /* These instructions will not bounce due to underflow. */
4980 case 3: /* fsqrt[sd]. */
4981 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4982 registers to cause the erratum in previous instructions. */
4983 bfd_arm_vfp11_write_mask (destmask, fd);
4987 case 15: /* fcvt{ds,sd}. */
4991 bfd_arm_vfp11_write_mask (destmask, fd);
4993 /* Only FCVTSD can underflow. */
4994 if ((insn & 0x100) != 0)
5013 /* Two-register transfer. */
5014 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
5016 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
5018 if ((insn & 0x100000) == 0)
5021 bfd_arm_vfp11_write_mask (destmask, fm);
5024 bfd_arm_vfp11_write_mask (destmask, fm);
5025 bfd_arm_vfp11_write_mask (destmask, fm + 1);
5031 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
5033 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
5034 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
5038 case 0: /* Two-reg transfer. We should catch these above. */
5041 case 2: /* fldm[sdx]. */
5045 unsigned int i, offset = insn & 0xff;
5050 for (i = fd; i < fd + offset; i++)
5051 bfd_arm_vfp11_write_mask (destmask, i);
5055 case 4: /* fld[sd]. */
5057 bfd_arm_vfp11_write_mask (destmask, fd);
5066 /* Single-register transfer. Note L==0. */
5067 else if ((insn & 0x0f100e10) == 0x0e000a10)
5069 unsigned int opcode = (insn >> 21) & 7;
5070 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
5074 case 0: /* fmsr/fmdlr. */
5075 case 1: /* fmdhr. */
5076 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5077 destination register. I don't know if this is exactly right,
5078 but it is the conservative choice. */
5079 bfd_arm_vfp11_write_mask (destmask, fn);
5093 static int elf32_arm_compare_mapping (const void * a, const void * b);
5096 /* Look for potentially-troublesome code sequences which might trigger the
5097 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5098 (available from ARM) for details of the erratum. A short version is
5099 described in ld.texinfo. */
5102 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
5105 bfd_byte *contents = NULL;
5107 int regs[3], numregs = 0;
5108 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
5109 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
5111 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5112 The states transition as follows:
5114 0 -> 1 (vector) or 0 -> 2 (scalar)
5115 A VFP FMAC-pipeline instruction has been seen. Fill
5116 regs[0]..regs[numregs-1] with its input operands. Remember this
5117 instruction in 'first_fmac'.
5120 Any instruction, except for a VFP instruction which overwrites
5125 A VFP instruction has been seen which overwrites any of regs[*].
5126 We must make a veneer! Reset state to 0 before examining next
5130 If we fail to match anything in state 2, reset to state 0 and reset
5131 the instruction pointer to the instruction after 'first_fmac'.
5133 If the VFP11 vector mode is in use, there must be at least two unrelated
5134 instructions between anti-dependent VFP11 instructions to properly avoid
5135 triggering the erratum, hence the use of the extra state 1. */
5137 /* If we are only performing a partial link do not bother
5138 to construct any glue. */
5139 if (link_info->relocatable)
5142 /* Skip if this bfd does not correspond to an ELF image. */
5143 if (! is_arm_elf (abfd))
5146 /* We should have chosen a fix type by the time we get here. */
5147 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5149 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5152 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5153 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
5156 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5158 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5159 struct _arm_elf_section_data *sec_data;
5161 /* If we don't have executable progbits, we're not interested in this
5162 section. Also skip if section is to be excluded. */
5163 if (elf_section_type (sec) != SHT_PROGBITS
5164 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5165 || (sec->flags & SEC_EXCLUDE) != 0
5166 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
5167 || sec->output_section == bfd_abs_section_ptr
5168 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5171 sec_data = elf32_arm_section_data (sec);
5173 if (sec_data->mapcount == 0)
5176 if (elf_section_data (sec)->this_hdr.contents != NULL)
5177 contents = elf_section_data (sec)->this_hdr.contents;
5178 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5181 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5182 elf32_arm_compare_mapping);
5184 for (span = 0; span < sec_data->mapcount; span++)
5186 unsigned int span_start = sec_data->map[span].vma;
5187 unsigned int span_end = (span == sec_data->mapcount - 1)
5188 ? sec->size : sec_data->map[span + 1].vma;
5189 char span_type = sec_data->map[span].type;
5191 /* FIXME: Only ARM mode is supported at present. We may need to
5192 support Thumb-2 mode also at some point. */
5193 if (span_type != 'a')
5196 for (i = span_start; i < span_end;)
5198 unsigned int next_i = i + 4;
5199 unsigned int insn = bfd_big_endian (abfd)
5200 ? (contents[i] << 24)
5201 | (contents[i + 1] << 16)
5202 | (contents[i + 2] << 8)
5204 : (contents[i + 3] << 24)
5205 | (contents[i + 2] << 16)
5206 | (contents[i + 1] << 8)
5208 unsigned int writemask = 0;
5209 enum bfd_arm_vfp11_pipe pipe;
5214 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5216 /* I'm assuming the VFP11 erratum can trigger with denorm
5217 operands on either the FMAC or the DS pipeline. This might
5218 lead to slightly overenthusiastic veneer insertion. */
5219 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5221 state = use_vector ? 1 : 2;
5223 veneer_of_insn = insn;
5229 int other_regs[3], other_numregs;
5230 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5233 if (pipe != VFP11_BAD
5234 && bfd_arm_vfp11_antidependency (writemask, regs,
5244 int other_regs[3], other_numregs;
5245 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5248 if (pipe != VFP11_BAD
5249 && bfd_arm_vfp11_antidependency (writemask, regs,
5255 next_i = first_fmac + 4;
5261 abort (); /* Should be unreachable. */
5266 elf32_vfp11_erratum_list *newerr
5267 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5270 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5272 newerr->u.b.vfp_insn = veneer_of_insn;
5277 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5284 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5289 newerr->next = sec_data->erratumlist;
5290 sec_data->erratumlist = newerr;
5299 if (contents != NULL
5300 && elf_section_data (sec)->this_hdr.contents != contents)
5308 if (contents != NULL
5309 && elf_section_data (sec)->this_hdr.contents != contents)
5315 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5316 after sections have been laid out, using specially-named symbols. */
5319 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5320 struct bfd_link_info *link_info)
5323 struct elf32_arm_link_hash_table *globals;
5326 if (link_info->relocatable)
5329 /* Skip if this bfd does not correspond to an ELF image. */
5330 if (! is_arm_elf (abfd))
5333 globals = elf32_arm_hash_table (link_info);
5335 tmp_name = bfd_malloc ((bfd_size_type) strlen
5336 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5338 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5340 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5341 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
5343 for (; errnode != NULL; errnode = errnode->next)
5345 struct elf_link_hash_entry *myh;
5348 switch (errnode->type)
5350 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5351 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5352 /* Find veneer symbol. */
5353 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5354 errnode->u.b.veneer->u.v.id);
5356 myh = elf_link_hash_lookup
5357 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5360 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5361 "`%s'"), abfd, tmp_name);
5363 vma = myh->root.u.def.section->output_section->vma
5364 + myh->root.u.def.section->output_offset
5365 + myh->root.u.def.value;
5367 errnode->u.b.veneer->vma = vma;
5370 case VFP11_ERRATUM_ARM_VENEER:
5371 case VFP11_ERRATUM_THUMB_VENEER:
5372 /* Find return location. */
5373 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5376 myh = elf_link_hash_lookup
5377 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5380 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5381 "`%s'"), abfd, tmp_name);
5383 vma = myh->root.u.def.section->output_section->vma
5384 + myh->root.u.def.section->output_offset
5385 + myh->root.u.def.value;
5387 errnode->u.v.branch->vma = vma;
5400 /* Set target relocation values needed during linking. */
5403 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5404 struct bfd_link_info *link_info,
5406 char * target2_type,
5409 bfd_arm_vfp11_fix vfp11_fix,
5410 int no_enum_warn, int no_wchar_warn,
5413 struct elf32_arm_link_hash_table *globals;
5415 globals = elf32_arm_hash_table (link_info);
5417 globals->target1_is_rel = target1_is_rel;
5418 if (strcmp (target2_type, "rel") == 0)
5419 globals->target2_reloc = R_ARM_REL32;
5420 else if (strcmp (target2_type, "abs") == 0)
5421 globals->target2_reloc = R_ARM_ABS32;
5422 else if (strcmp (target2_type, "got-rel") == 0)
5423 globals->target2_reloc = R_ARM_GOT_PREL;
5426 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5429 globals->fix_v4bx = fix_v4bx;
5430 globals->use_blx |= use_blx;
5431 globals->vfp11_fix = vfp11_fix;
5432 globals->pic_veneer = pic_veneer;
5434 BFD_ASSERT (is_arm_elf (output_bfd));
5435 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
5436 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
5439 /* Replace the target offset of a Thumb bl or b.w instruction. */
5442 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5448 BFD_ASSERT ((offset & 1) == 0);
5450 upper = bfd_get_16 (abfd, insn);
5451 lower = bfd_get_16 (abfd, insn + 2);
5452 reloc_sign = (offset < 0) ? 1 : 0;
5453 upper = (upper & ~(bfd_vma) 0x7ff)
5454 | ((offset >> 12) & 0x3ff)
5455 | (reloc_sign << 10);
5456 lower = (lower & ~(bfd_vma) 0x2fff)
5457 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5458 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5459 | ((offset >> 1) & 0x7ff);
5460 bfd_put_16 (abfd, upper, insn);
5461 bfd_put_16 (abfd, lower, insn + 2);
5464 /* Thumb code calling an ARM function. */
5467 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5471 asection * input_section,
5472 bfd_byte * hit_data,
5475 bfd_signed_vma addend,
5477 char **error_message)
5481 long int ret_offset;
5482 struct elf_link_hash_entry * myh;
5483 struct elf32_arm_link_hash_table * globals;
5485 myh = find_thumb_glue (info, name, error_message);
5489 globals = elf32_arm_hash_table (info);
5491 BFD_ASSERT (globals != NULL);
5492 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5494 my_offset = myh->root.u.def.value;
5496 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5497 THUMB2ARM_GLUE_SECTION_NAME);
5499 BFD_ASSERT (s != NULL);
5500 BFD_ASSERT (s->contents != NULL);
5501 BFD_ASSERT (s->output_section != NULL);
5503 if ((my_offset & 0x01) == 0x01)
5506 && sym_sec->owner != NULL
5507 && !INTERWORK_FLAG (sym_sec->owner))
5509 (*_bfd_error_handler)
5510 (_("%B(%s): warning: interworking not enabled.\n"
5511 " first occurrence: %B: thumb call to arm"),
5512 sym_sec->owner, input_bfd, name);
5518 myh->root.u.def.value = my_offset;
5520 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5521 s->contents + my_offset);
5523 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5524 s->contents + my_offset + 2);
5527 /* Address of destination of the stub. */
5528 ((bfd_signed_vma) val)
5530 /* Offset from the start of the current section
5531 to the start of the stubs. */
5533 /* Offset of the start of this stub from the start of the stubs. */
5535 /* Address of the start of the current section. */
5536 + s->output_section->vma)
5537 /* The branch instruction is 4 bytes into the stub. */
5539 /* ARM branches work from the pc of the instruction + 8. */
5542 put_arm_insn (globals, output_bfd,
5543 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5544 s->contents + my_offset + 4);
5547 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5549 /* Now go back and fix up the original BL insn to point to here. */
5551 /* Address of where the stub is located. */
5552 (s->output_section->vma + s->output_offset + my_offset)
5553 /* Address of where the BL is located. */
5554 - (input_section->output_section->vma + input_section->output_offset
5556 /* Addend in the relocation. */
5558 /* Biassing for PC-relative addressing. */
5561 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
5566 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5568 static struct elf_link_hash_entry *
5569 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5576 char ** error_message)
5579 long int ret_offset;
5580 struct elf_link_hash_entry * myh;
5581 struct elf32_arm_link_hash_table * globals;
5583 myh = find_arm_glue (info, name, error_message);
5587 globals = elf32_arm_hash_table (info);
5589 BFD_ASSERT (globals != NULL);
5590 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5592 my_offset = myh->root.u.def.value;
5594 if ((my_offset & 0x01) == 0x01)
5597 && sym_sec->owner != NULL
5598 && !INTERWORK_FLAG (sym_sec->owner))
5600 (*_bfd_error_handler)
5601 (_("%B(%s): warning: interworking not enabled.\n"
5602 " first occurrence: %B: arm call to thumb"),
5603 sym_sec->owner, input_bfd, name);
5607 myh->root.u.def.value = my_offset;
5609 if (info->shared || globals->root.is_relocatable_executable
5610 || globals->pic_veneer)
5612 /* For relocatable objects we can't use absolute addresses,
5613 so construct the address from a relative offset. */
5614 /* TODO: If the offset is small it's probably worth
5615 constructing the address with adds. */
5616 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5617 s->contents + my_offset);
5618 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5619 s->contents + my_offset + 4);
5620 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5621 s->contents + my_offset + 8);
5622 /* Adjust the offset by 4 for the position of the add,
5623 and 8 for the pipeline offset. */
5624 ret_offset = (val - (s->output_offset
5625 + s->output_section->vma
5628 bfd_put_32 (output_bfd, ret_offset,
5629 s->contents + my_offset + 12);
5631 else if (globals->use_blx)
5633 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5634 s->contents + my_offset);
5636 /* It's a thumb address. Add the low order bit. */
5637 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5638 s->contents + my_offset + 4);
5642 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5643 s->contents + my_offset);
5645 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5646 s->contents + my_offset + 4);
5648 /* It's a thumb address. Add the low order bit. */
5649 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5650 s->contents + my_offset + 8);
5656 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5661 /* Arm code calling a Thumb function. */
5664 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5668 asection * input_section,
5669 bfd_byte * hit_data,
5672 bfd_signed_vma addend,
5674 char **error_message)
5676 unsigned long int tmp;
5679 long int ret_offset;
5680 struct elf_link_hash_entry * myh;
5681 struct elf32_arm_link_hash_table * globals;
5683 globals = elf32_arm_hash_table (info);
5685 BFD_ASSERT (globals != NULL);
5686 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5688 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5689 ARM2THUMB_GLUE_SECTION_NAME);
5690 BFD_ASSERT (s != NULL);
5691 BFD_ASSERT (s->contents != NULL);
5692 BFD_ASSERT (s->output_section != NULL);
5694 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
5695 sym_sec, val, s, error_message);
5699 my_offset = myh->root.u.def.value;
5700 tmp = bfd_get_32 (input_bfd, hit_data);
5701 tmp = tmp & 0xFF000000;
5703 /* Somehow these are both 4 too far, so subtract 8. */
5704 ret_offset = (s->output_offset
5706 + s->output_section->vma
5707 - (input_section->output_offset
5708 + input_section->output_section->vma
5712 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5714 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
5719 /* Populate Arm stub for an exported Thumb function. */
5722 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5724 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5726 struct elf_link_hash_entry * myh;
5727 struct elf32_arm_link_hash_entry *eh;
5728 struct elf32_arm_link_hash_table * globals;
5731 char *error_message;
5733 eh = elf32_arm_hash_entry (h);
5734 /* Allocate stubs for exported Thumb functions on v4t. */
5735 if (eh->export_glue == NULL)
5738 globals = elf32_arm_hash_table (info);
5740 BFD_ASSERT (globals != NULL);
5741 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5743 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5744 ARM2THUMB_GLUE_SECTION_NAME);
5745 BFD_ASSERT (s != NULL);
5746 BFD_ASSERT (s->contents != NULL);
5747 BFD_ASSERT (s->output_section != NULL);
5749 sec = eh->export_glue->root.u.def.section;
5751 BFD_ASSERT (sec->output_section != NULL);
5753 val = eh->export_glue->root.u.def.value + sec->output_offset
5754 + sec->output_section->vma;
5756 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5757 h->root.u.def.section->owner,
5758 globals->obfd, sec, val, s,
5764 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5767 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5772 struct elf32_arm_link_hash_table *globals;
5774 globals = elf32_arm_hash_table (info);
5776 BFD_ASSERT (globals != NULL);
5777 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5779 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5780 ARM_BX_GLUE_SECTION_NAME);
5781 BFD_ASSERT (s != NULL);
5782 BFD_ASSERT (s->contents != NULL);
5783 BFD_ASSERT (s->output_section != NULL);
5785 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5787 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5789 if ((globals->bx_glue_offset[reg] & 1) == 0)
5791 p = s->contents + glue_addr;
5792 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5793 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5794 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5795 globals->bx_glue_offset[reg] |= 1;
5798 return glue_addr + s->output_section->vma + s->output_offset;
5801 /* Generate Arm stubs for exported Thumb symbols. */
5803 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
5804 struct bfd_link_info *link_info)
5806 struct elf32_arm_link_hash_table * globals;
5808 if (link_info == NULL)
5809 /* Ignore this if we are not called by the ELF backend linker. */
5812 globals = elf32_arm_hash_table (link_info);
5813 /* If blx is available then exported Thumb symbols are OK and there is
5815 if (globals->use_blx)
5818 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5822 /* Some relocations map to different relocations depending on the
5823 target. Return the real relocation. */
5826 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5832 if (globals->target1_is_rel)
5838 return globals->target2_reloc;
5845 /* Return the base VMA address which should be subtracted from real addresses
5846 when resolving @dtpoff relocation.
5847 This is PT_TLS segment p_vaddr. */
5850 dtpoff_base (struct bfd_link_info *info)
5852 /* If tls_sec is NULL, we should have signalled an error already. */
5853 if (elf_hash_table (info)->tls_sec == NULL)
5855 return elf_hash_table (info)->tls_sec->vma;
5858 /* Return the relocation value for @tpoff relocation
5859 if STT_TLS virtual address is ADDRESS. */
5862 tpoff (struct bfd_link_info *info, bfd_vma address)
5864 struct elf_link_hash_table *htab = elf_hash_table (info);
5867 /* If tls_sec is NULL, we should have signalled an error already. */
5868 if (htab->tls_sec == NULL)
5870 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5871 return address - htab->tls_sec->vma + base;
5874 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5875 VALUE is the relocation value. */
5877 static bfd_reloc_status_type
5878 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5881 return bfd_reloc_overflow;
5883 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5884 bfd_put_32 (abfd, value, data);
5885 return bfd_reloc_ok;
5888 /* For a given value of n, calculate the value of G_n as required to
5889 deal with group relocations. We return it in the form of an
5890 encoded constant-and-rotation, together with the final residual. If n is
5891 specified as less than zero, then final_residual is filled with the
5892 input value and no further action is performed. */
5895 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5899 bfd_vma encoded_g_n = 0;
5900 bfd_vma residual = value; /* Also known as Y_n. */
5902 for (current_n = 0; current_n <= n; current_n++)
5906 /* Calculate which part of the value to mask. */
5913 /* Determine the most significant bit in the residual and
5914 align the resulting value to a 2-bit boundary. */
5915 for (msb = 30; msb >= 0; msb -= 2)
5916 if (residual & (3 << msb))
5919 /* The desired shift is now (msb - 6), or zero, whichever
5926 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5927 g_n = residual & (0xff << shift);
5928 encoded_g_n = (g_n >> shift)
5929 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5931 /* Calculate the residual for the next time around. */
5935 *final_residual = residual;
5940 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5941 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5944 identify_add_or_sub (bfd_vma insn)
5946 int opcode = insn & 0x1e00000;
5948 if (opcode == 1 << 23) /* ADD */
5951 if (opcode == 1 << 22) /* SUB */
5957 /* Perform a relocation as part of a final link. */
5959 static bfd_reloc_status_type
5960 elf32_arm_final_link_relocate (reloc_howto_type * howto,
5963 asection * input_section,
5964 bfd_byte * contents,
5965 Elf_Internal_Rela * rel,
5967 struct bfd_link_info * info,
5969 const char * sym_name,
5971 struct elf_link_hash_entry * h,
5972 bfd_boolean * unresolved_reloc_p,
5973 char ** error_message)
5975 unsigned long r_type = howto->type;
5976 unsigned long r_symndx;
5977 bfd_byte * hit_data = contents + rel->r_offset;
5978 bfd * dynobj = NULL;
5979 Elf_Internal_Shdr * symtab_hdr;
5980 struct elf_link_hash_entry ** sym_hashes;
5981 bfd_vma * local_got_offsets;
5982 asection * sgot = NULL;
5983 asection * splt = NULL;
5984 asection * sreloc = NULL;
5986 bfd_signed_vma signed_addend;
5987 struct elf32_arm_link_hash_table * globals;
5989 globals = elf32_arm_hash_table (info);
5991 BFD_ASSERT (is_arm_elf (input_bfd));
5993 /* Some relocation types map to different relocations depending on the
5994 target. We pick the right one here. */
5995 r_type = arm_real_reloc_type (globals, r_type);
5996 if (r_type != howto->type)
5997 howto = elf32_arm_howto_from_type (r_type);
5999 /* If the start address has been set, then set the EF_ARM_HASENTRY
6000 flag. Setting this more than once is redundant, but the cost is
6001 not too high, and it keeps the code simple.
6003 The test is done here, rather than somewhere else, because the
6004 start address is only set just before the final link commences.
6006 Note - if the user deliberately sets a start address of 0, the
6007 flag will not be set. */
6008 if (bfd_get_start_address (output_bfd) != 0)
6009 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
6011 dynobj = elf_hash_table (info)->dynobj;
6014 sgot = bfd_get_section_by_name (dynobj, ".got");
6015 splt = bfd_get_section_by_name (dynobj, ".plt");
6017 symtab_hdr = & elf_symtab_hdr (input_bfd);
6018 sym_hashes = elf_sym_hashes (input_bfd);
6019 local_got_offsets = elf_local_got_offsets (input_bfd);
6020 r_symndx = ELF32_R_SYM (rel->r_info);
6022 if (globals->use_rel)
6024 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
6026 if (addend & ((howto->src_mask + 1) >> 1))
6029 signed_addend &= ~ howto->src_mask;
6030 signed_addend |= addend;
6033 signed_addend = addend;
6036 addend = signed_addend = rel->r_addend;
6041 /* We don't need to find a value for this symbol. It's just a
6043 *unresolved_reloc_p = FALSE;
6044 return bfd_reloc_ok;
6047 if (!globals->vxworks_p)
6048 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6052 case R_ARM_ABS32_NOI:
6054 case R_ARM_REL32_NOI:
6060 /* Handle relocations which should use the PLT entry. ABS32/REL32
6061 will use the symbol's value, which may point to a PLT entry, but we
6062 don't need to handle that here. If we created a PLT entry, all
6063 branches in this object should go to it, except if the PLT is too
6064 far away, in which case a long branch stub should be inserted. */
6065 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
6066 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI
6067 && r_type != R_ARM_CALL
6068 && r_type != R_ARM_JUMP24
6069 && r_type != R_ARM_PLT32)
6072 && h->plt.offset != (bfd_vma) -1)
6074 /* If we've created a .plt section, and assigned a PLT entry to
6075 this function, it should not be known to bind locally. If
6076 it were, we would have cleared the PLT entry. */
6077 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
6079 value = (splt->output_section->vma
6080 + splt->output_offset
6082 *unresolved_reloc_p = FALSE;
6083 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6084 contents, rel->r_offset, value,
6088 /* When generating a shared object or relocatable executable, these
6089 relocations are copied into the output file to be resolved at
6091 if ((info->shared || globals->root.is_relocatable_executable)
6092 && (input_section->flags & SEC_ALLOC)
6093 && !(elf32_arm_hash_table (info)->vxworks_p
6094 && strcmp (input_section->output_section->name,
6096 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
6097 || !SYMBOL_CALLS_LOCAL (info, h))
6099 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6100 || h->root.type != bfd_link_hash_undefweak)
6101 && r_type != R_ARM_PC24
6102 && r_type != R_ARM_CALL
6103 && r_type != R_ARM_JUMP24
6104 && r_type != R_ARM_PREL31
6105 && r_type != R_ARM_PLT32)
6107 Elf_Internal_Rela outrel;
6109 bfd_boolean skip, relocate;
6111 *unresolved_reloc_p = FALSE;
6115 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
6116 ! globals->use_rel);
6119 return bfd_reloc_notsupported;
6125 outrel.r_addend = addend;
6127 _bfd_elf_section_offset (output_bfd, info, input_section,
6129 if (outrel.r_offset == (bfd_vma) -1)
6131 else if (outrel.r_offset == (bfd_vma) -2)
6132 skip = TRUE, relocate = TRUE;
6133 outrel.r_offset += (input_section->output_section->vma
6134 + input_section->output_offset);
6137 memset (&outrel, 0, sizeof outrel);
6142 || !h->def_regular))
6143 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6148 /* This symbol is local, or marked to become local. */
6149 if (sym_flags == STT_ARM_TFUNC)
6151 if (globals->symbian_p)
6155 /* On Symbian OS, the data segment and text segement
6156 can be relocated independently. Therefore, we
6157 must indicate the segment to which this
6158 relocation is relative. The BPABI allows us to
6159 use any symbol in the right segment; we just use
6160 the section symbol as it is convenient. (We
6161 cannot use the symbol given by "h" directly as it
6162 will not appear in the dynamic symbol table.)
6164 Note that the dynamic linker ignores the section
6165 symbol value, so we don't subtract osec->vma
6166 from the emitted reloc addend. */
6168 osec = sym_sec->output_section;
6170 osec = input_section->output_section;
6171 symbol = elf_section_data (osec)->dynindx;
6174 struct elf_link_hash_table *htab = elf_hash_table (info);
6176 if ((osec->flags & SEC_READONLY) == 0
6177 && htab->data_index_section != NULL)
6178 osec = htab->data_index_section;
6180 osec = htab->text_index_section;
6181 symbol = elf_section_data (osec)->dynindx;
6183 BFD_ASSERT (symbol != 0);
6186 /* On SVR4-ish systems, the dynamic loader cannot
6187 relocate the text and data segments independently,
6188 so the symbol does not matter. */
6190 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
6191 if (globals->use_rel)
6194 outrel.r_addend += value;
6197 loc = sreloc->contents;
6198 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6199 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6201 /* If this reloc is against an external symbol, we do not want to
6202 fiddle with the addend. Otherwise, we need to include the symbol
6203 value so that it becomes an addend for the dynamic reloc. */
6205 return bfd_reloc_ok;
6207 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6208 contents, rel->r_offset, value,
6211 else switch (r_type)
6214 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6216 case R_ARM_XPC25: /* Arm BLX instruction. */
6219 case R_ARM_PC24: /* Arm B/BL instruction. */
6223 bfd_signed_vma branch_offset;
6224 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6226 if (r_type == R_ARM_XPC25)
6228 /* Check for Arm calling Arm function. */
6229 /* FIXME: Should we translate the instruction into a BL
6230 instruction instead ? */
6231 if (sym_flags != STT_ARM_TFUNC)
6232 (*_bfd_error_handler)
6233 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6235 h ? h->root.root.string : "(local)");
6237 else if (r_type == R_ARM_PC24)
6239 /* Check for Arm calling Thumb function. */
6240 if (sym_flags == STT_ARM_TFUNC)
6242 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6243 output_bfd, input_section,
6244 hit_data, sym_sec, rel->r_offset,
6245 signed_addend, value,
6247 return bfd_reloc_ok;
6249 return bfd_reloc_dangerous;
6253 /* Check if a stub has to be inserted because the
6254 destination is too far or we are changing mode. */
6255 if ( r_type == R_ARM_CALL
6256 || r_type == R_ARM_JUMP24
6257 || r_type == R_ARM_PLT32)
6259 /* If the call goes through a PLT entry, make sure to
6260 check distance to the right destination address. */
6261 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6263 value = (splt->output_section->vma
6264 + splt->output_offset
6266 *unresolved_reloc_p = FALSE;
6269 from = (input_section->output_section->vma
6270 + input_section->output_offset
6272 branch_offset = (bfd_signed_vma)(value - from);
6274 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6275 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6276 || ((sym_flags == STT_ARM_TFUNC)
6277 && (((r_type == R_ARM_CALL) && !globals->use_blx)
6278 || (r_type == R_ARM_JUMP24)
6279 || (r_type == R_ARM_PLT32) ))
6282 /* The target is out of reach, so redirect the
6283 branch to the local stub for this function. */
6285 stub_entry = elf32_arm_get_stub_entry (input_section,
6288 if (stub_entry != NULL)
6289 value = (stub_entry->stub_offset
6290 + stub_entry->stub_sec->output_offset
6291 + stub_entry->stub_sec->output_section->vma);
6295 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6297 S is the address of the symbol in the relocation.
6298 P is address of the instruction being relocated.
6299 A is the addend (extracted from the instruction) in bytes.
6301 S is held in 'value'.
6302 P is the base address of the section containing the
6303 instruction plus the offset of the reloc into that
6305 (input_section->output_section->vma +
6306 input_section->output_offset +
6308 A is the addend, converted into bytes, ie:
6311 Note: None of these operations have knowledge of the pipeline
6312 size of the processor, thus it is up to the assembler to
6313 encode this information into the addend. */
6314 value -= (input_section->output_section->vma
6315 + input_section->output_offset);
6316 value -= rel->r_offset;
6317 if (globals->use_rel)
6318 value += (signed_addend << howto->size);
6320 /* RELA addends do not have to be adjusted by howto->size. */
6321 value += signed_addend;
6323 signed_addend = value;
6324 signed_addend >>= howto->rightshift;
6326 /* A branch to an undefined weak symbol is turned into a jump to
6327 the next instruction unless a PLT entry will be created. */
6328 if (h && h->root.type == bfd_link_hash_undefweak
6329 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6331 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6336 /* Perform a signed range check. */
6337 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
6338 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6339 return bfd_reloc_overflow;
6341 addend = (value & 2);
6343 value = (signed_addend & howto->dst_mask)
6344 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
6346 if (r_type == R_ARM_CALL)
6348 /* Set the H bit in the BLX instruction. */
6349 if (sym_flags == STT_ARM_TFUNC)
6354 value &= ~(bfd_vma)(1 << 24);
6357 /* Select the correct instruction (BL or BLX). */
6358 /* Only if we are not handling a BL to a stub. In this
6359 case, mode switching is performed by the stub. */
6360 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
6364 value &= ~(bfd_vma)(1 << 28);
6374 if (sym_flags == STT_ARM_TFUNC)
6378 case R_ARM_ABS32_NOI:
6384 if (sym_flags == STT_ARM_TFUNC)
6386 value -= (input_section->output_section->vma
6387 + input_section->output_offset + rel->r_offset);
6390 case R_ARM_REL32_NOI:
6392 value -= (input_section->output_section->vma
6393 + input_section->output_offset + rel->r_offset);
6397 value -= (input_section->output_section->vma
6398 + input_section->output_offset + rel->r_offset);
6399 value += signed_addend;
6400 if (! h || h->root.type != bfd_link_hash_undefweak)
6402 /* Check for overflow. */
6403 if ((value ^ (value >> 1)) & (1 << 30))
6404 return bfd_reloc_overflow;
6406 value &= 0x7fffffff;
6407 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6408 if (sym_flags == STT_ARM_TFUNC)
6413 bfd_put_32 (input_bfd, value, hit_data);
6414 return bfd_reloc_ok;
6418 if ((long) value > 0x7f || (long) value < -0x80)
6419 return bfd_reloc_overflow;
6421 bfd_put_8 (input_bfd, value, hit_data);
6422 return bfd_reloc_ok;
6427 if ((long) value > 0x7fff || (long) value < -0x8000)
6428 return bfd_reloc_overflow;
6430 bfd_put_16 (input_bfd, value, hit_data);
6431 return bfd_reloc_ok;
6433 case R_ARM_THM_ABS5:
6434 /* Support ldr and str instructions for the thumb. */
6435 if (globals->use_rel)
6437 /* Need to refetch addend. */
6438 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6439 /* ??? Need to determine shift amount from operand size. */
6440 addend >>= howto->rightshift;
6444 /* ??? Isn't value unsigned? */
6445 if ((long) value > 0x1f || (long) value < -0x10)
6446 return bfd_reloc_overflow;
6448 /* ??? Value needs to be properly shifted into place first. */
6449 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6450 bfd_put_16 (input_bfd, value, hit_data);
6451 return bfd_reloc_ok;
6453 case R_ARM_THM_ALU_PREL_11_0:
6454 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6457 bfd_signed_vma relocation;
6459 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6460 | bfd_get_16 (input_bfd, hit_data + 2);
6462 if (globals->use_rel)
6464 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6465 | ((insn & (1 << 26)) >> 15);
6466 if (insn & 0xf00000)
6467 signed_addend = -signed_addend;
6470 relocation = value + signed_addend;
6471 relocation -= (input_section->output_section->vma
6472 + input_section->output_offset
6475 value = abs (relocation);
6477 if (value >= 0x1000)
6478 return bfd_reloc_overflow;
6480 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6481 | ((value & 0x700) << 4)
6482 | ((value & 0x800) << 15);
6486 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6487 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6489 return bfd_reloc_ok;
6492 case R_ARM_THM_PC12:
6493 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6496 bfd_signed_vma relocation;
6498 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6499 | bfd_get_16 (input_bfd, hit_data + 2);
6501 if (globals->use_rel)
6503 signed_addend = insn & 0xfff;
6504 if (!(insn & (1 << 23)))
6505 signed_addend = -signed_addend;
6508 relocation = value + signed_addend;
6509 relocation -= (input_section->output_section->vma
6510 + input_section->output_offset
6513 value = abs (relocation);
6515 if (value >= 0x1000)
6516 return bfd_reloc_overflow;
6518 insn = (insn & 0xff7ff000) | value;
6519 if (relocation >= 0)
6522 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6523 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6525 return bfd_reloc_ok;
6528 case R_ARM_THM_XPC22:
6529 case R_ARM_THM_CALL:
6530 case R_ARM_THM_JUMP24:
6531 /* Thumb BL (branch long instruction). */
6535 bfd_boolean overflow = FALSE;
6536 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6537 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6538 bfd_signed_vma reloc_signed_max;
6539 bfd_signed_vma reloc_signed_min;
6541 bfd_signed_vma signed_check;
6543 int thumb2 = using_thumb2 (globals);
6545 /* A branch to an undefined weak symbol is turned into a jump to
6546 the next instruction unless a PLT entry will be created. */
6547 if (h && h->root.type == bfd_link_hash_undefweak
6548 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6550 bfd_put_16 (input_bfd, 0xe000, hit_data);
6551 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6552 return bfd_reloc_ok;
6555 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6556 with Thumb-1) involving the J1 and J2 bits. */
6557 if (globals->use_rel)
6559 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6560 bfd_vma upper = upper_insn & 0x3ff;
6561 bfd_vma lower = lower_insn & 0x7ff;
6562 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6563 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6564 bfd_vma i1 = j1 ^ s ? 0 : 1;
6565 bfd_vma i2 = j2 ^ s ? 0 : 1;
6567 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6569 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6571 signed_addend = addend;
6574 if (r_type == R_ARM_THM_XPC22)
6576 /* Check for Thumb to Thumb call. */
6577 /* FIXME: Should we translate the instruction into a BL
6578 instruction instead ? */
6579 if (sym_flags == STT_ARM_TFUNC)
6580 (*_bfd_error_handler)
6581 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6583 h ? h->root.root.string : "(local)");
6587 /* If it is not a call to Thumb, assume call to Arm.
6588 If it is a call relative to a section name, then it is not a
6589 function call at all, but rather a long jump. Calls through
6590 the PLT do not require stubs. */
6591 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6592 && (h == NULL || splt == NULL
6593 || h->plt.offset == (bfd_vma) -1))
6595 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6597 /* Convert BL to BLX. */
6598 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6600 else if (( r_type != R_ARM_THM_CALL)
6601 && (r_type != R_ARM_THM_JUMP24))
6603 if (elf32_thumb_to_arm_stub
6604 (info, sym_name, input_bfd, output_bfd, input_section,
6605 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6607 return bfd_reloc_ok;
6609 return bfd_reloc_dangerous;
6612 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6613 && r_type == R_ARM_THM_CALL)
6615 /* Make sure this is a BL. */
6616 lower_insn |= 0x1800;
6620 /* Handle calls via the PLT. */
6621 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6623 value = (splt->output_section->vma
6624 + splt->output_offset
6626 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6628 /* If the Thumb BLX instruction is available, convert the
6629 BL to a BLX instruction to call the ARM-mode PLT entry. */
6630 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6633 /* Target the Thumb stub before the ARM PLT entry. */
6634 value -= PLT_THUMB_STUB_SIZE;
6635 *unresolved_reloc_p = FALSE;
6638 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24)
6640 /* Check if a stub has to be inserted because the destination
6643 bfd_signed_vma branch_offset;
6644 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6646 from = (input_section->output_section->vma
6647 + input_section->output_offset
6649 branch_offset = (bfd_signed_vma)(value - from);
6652 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6653 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6656 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
6657 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6658 || ((sym_flags != STT_ARM_TFUNC)
6659 && (((r_type == R_ARM_THM_CALL) && !globals->use_blx)
6660 || r_type == R_ARM_THM_JUMP24)))
6662 /* The target is out of reach or we are changing modes, so
6663 redirect the branch to the local stub for this
6665 stub_entry = elf32_arm_get_stub_entry (input_section,
6668 if (stub_entry != NULL)
6669 value = (stub_entry->stub_offset
6670 + stub_entry->stub_sec->output_offset
6671 + stub_entry->stub_sec->output_section->vma);
6673 /* If this call becomes a call to Arm, force BLX. */
6674 if (globals->use_blx && (r_type == R_ARM_THM_CALL))
6677 && !arm_stub_is_thumb (stub_entry->stub_type))
6678 || (sym_flags != STT_ARM_TFUNC))
6679 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6684 relocation = value + signed_addend;
6686 relocation -= (input_section->output_section->vma
6687 + input_section->output_offset
6690 check = relocation >> howto->rightshift;
6692 /* If this is a signed value, the rightshift just dropped
6693 leading 1 bits (assuming twos complement). */
6694 if ((bfd_signed_vma) relocation >= 0)
6695 signed_check = check;
6697 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6699 /* Calculate the permissable maximum and minimum values for
6700 this relocation according to whether we're relocating for
6702 bitsize = howto->bitsize;
6705 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6706 reloc_signed_min = ~reloc_signed_max;
6708 /* Assumes two's complement. */
6709 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6712 if ((lower_insn & 0x5000) == 0x4000)
6713 /* For a BLX instruction, make sure that the relocation is rounded up
6714 to a word boundary. This follows the semantics of the instruction
6715 which specifies that bit 1 of the target address will come from bit
6716 1 of the base address. */
6717 relocation = (relocation + 2) & ~ 3;
6719 /* Put RELOCATION back into the insn. Assumes two's complement.
6720 We use the Thumb-2 encoding, which is safe even if dealing with
6721 a Thumb-1 instruction by virtue of our overflow check above. */
6722 reloc_sign = (signed_check < 0) ? 1 : 0;
6723 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6724 | ((relocation >> 12) & 0x3ff)
6725 | (reloc_sign << 10);
6726 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
6727 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6728 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6729 | ((relocation >> 1) & 0x7ff);
6731 /* Put the relocated value back in the object file: */
6732 bfd_put_16 (input_bfd, upper_insn, hit_data);
6733 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6735 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6739 case R_ARM_THM_JUMP19:
6740 /* Thumb32 conditional branch instruction. */
6743 bfd_boolean overflow = FALSE;
6744 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6745 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6746 bfd_signed_vma reloc_signed_max = 0xffffe;
6747 bfd_signed_vma reloc_signed_min = -0x100000;
6748 bfd_signed_vma signed_check;
6750 /* Need to refetch the addend, reconstruct the top three bits,
6751 and squish the two 11 bit pieces together. */
6752 if (globals->use_rel)
6754 bfd_vma S = (upper_insn & 0x0400) >> 10;
6755 bfd_vma upper = (upper_insn & 0x003f);
6756 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6757 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6758 bfd_vma lower = (lower_insn & 0x07ff);
6763 upper -= 0x0100; /* Sign extend. */
6765 addend = (upper << 12) | (lower << 1);
6766 signed_addend = addend;
6769 /* Handle calls via the PLT. */
6770 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6772 value = (splt->output_section->vma
6773 + splt->output_offset
6775 /* Target the Thumb stub before the ARM PLT entry. */
6776 value -= PLT_THUMB_STUB_SIZE;
6777 *unresolved_reloc_p = FALSE;
6780 /* ??? Should handle interworking? GCC might someday try to
6781 use this for tail calls. */
6783 relocation = value + signed_addend;
6784 relocation -= (input_section->output_section->vma
6785 + input_section->output_offset
6787 signed_check = (bfd_signed_vma) relocation;
6789 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6792 /* Put RELOCATION back into the insn. */
6794 bfd_vma S = (relocation & 0x00100000) >> 20;
6795 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6796 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6797 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6798 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6800 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
6801 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6804 /* Put the relocated value back in the object file: */
6805 bfd_put_16 (input_bfd, upper_insn, hit_data);
6806 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6808 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6811 case R_ARM_THM_JUMP11:
6812 case R_ARM_THM_JUMP8:
6813 case R_ARM_THM_JUMP6:
6814 /* Thumb B (branch) instruction). */
6816 bfd_signed_vma relocation;
6817 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6818 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
6819 bfd_signed_vma signed_check;
6821 /* CZB cannot jump backward. */
6822 if (r_type == R_ARM_THM_JUMP6)
6823 reloc_signed_min = 0;
6825 if (globals->use_rel)
6827 /* Need to refetch addend. */
6828 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6829 if (addend & ((howto->src_mask + 1) >> 1))
6832 signed_addend &= ~ howto->src_mask;
6833 signed_addend |= addend;
6836 signed_addend = addend;
6837 /* The value in the insn has been right shifted. We need to
6838 undo this, so that we can perform the address calculation
6839 in terms of bytes. */
6840 signed_addend <<= howto->rightshift;
6842 relocation = value + signed_addend;
6844 relocation -= (input_section->output_section->vma
6845 + input_section->output_offset
6848 relocation >>= howto->rightshift;
6849 signed_check = relocation;
6851 if (r_type == R_ARM_THM_JUMP6)
6852 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6854 relocation &= howto->dst_mask;
6855 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
6857 bfd_put_16 (input_bfd, relocation, hit_data);
6859 /* Assumes two's complement. */
6860 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6861 return bfd_reloc_overflow;
6863 return bfd_reloc_ok;
6866 case R_ARM_ALU_PCREL7_0:
6867 case R_ARM_ALU_PCREL15_8:
6868 case R_ARM_ALU_PCREL23_15:
6873 insn = bfd_get_32 (input_bfd, hit_data);
6874 if (globals->use_rel)
6876 /* Extract the addend. */
6877 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6878 signed_addend = addend;
6880 relocation = value + signed_addend;
6882 relocation -= (input_section->output_section->vma
6883 + input_section->output_offset
6885 insn = (insn & ~0xfff)
6886 | ((howto->bitpos << 7) & 0xf00)
6887 | ((relocation >> howto->bitpos) & 0xff);
6888 bfd_put_32 (input_bfd, value, hit_data);
6890 return bfd_reloc_ok;
6892 case R_ARM_GNU_VTINHERIT:
6893 case R_ARM_GNU_VTENTRY:
6894 return bfd_reloc_ok;
6896 case R_ARM_GOTOFF32:
6897 /* Relocation is relative to the start of the
6898 global offset table. */
6900 BFD_ASSERT (sgot != NULL);
6902 return bfd_reloc_notsupported;
6904 /* If we are addressing a Thumb function, we need to adjust the
6905 address by one, so that attempts to call the function pointer will
6906 correctly interpret it as Thumb code. */
6907 if (sym_flags == STT_ARM_TFUNC)
6910 /* Note that sgot->output_offset is not involved in this
6911 calculation. We always want the start of .got. If we
6912 define _GLOBAL_OFFSET_TABLE in a different way, as is
6913 permitted by the ABI, we might have to change this
6915 value -= sgot->output_section->vma;
6916 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6917 contents, rel->r_offset, value,
6921 /* Use global offset table as symbol value. */
6922 BFD_ASSERT (sgot != NULL);
6925 return bfd_reloc_notsupported;
6927 *unresolved_reloc_p = FALSE;
6928 value = sgot->output_section->vma;
6929 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6930 contents, rel->r_offset, value,
6934 case R_ARM_GOT_PREL:
6935 /* Relocation is to the entry for this symbol in the
6936 global offset table. */
6938 return bfd_reloc_notsupported;
6945 off = h->got.offset;
6946 BFD_ASSERT (off != (bfd_vma) -1);
6947 dyn = globals->root.dynamic_sections_created;
6949 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6951 && SYMBOL_REFERENCES_LOCAL (info, h))
6952 || (ELF_ST_VISIBILITY (h->other)
6953 && h->root.type == bfd_link_hash_undefweak))
6955 /* This is actually a static link, or it is a -Bsymbolic link
6956 and the symbol is defined locally. We must initialize this
6957 entry in the global offset table. Since the offset must
6958 always be a multiple of 4, we use the least significant bit
6959 to record whether we have initialized it already.
6961 When doing a dynamic link, we create a .rel(a).got relocation
6962 entry to initialize the value. This is done in the
6963 finish_dynamic_symbol routine. */
6968 /* If we are addressing a Thumb function, we need to
6969 adjust the address by one, so that attempts to
6970 call the function pointer will correctly
6971 interpret it as Thumb code. */
6972 if (sym_flags == STT_ARM_TFUNC)
6975 bfd_put_32 (output_bfd, value, sgot->contents + off);
6980 *unresolved_reloc_p = FALSE;
6982 value = sgot->output_offset + off;
6988 BFD_ASSERT (local_got_offsets != NULL &&
6989 local_got_offsets[r_symndx] != (bfd_vma) -1);
6991 off = local_got_offsets[r_symndx];
6993 /* The offset must always be a multiple of 4. We use the
6994 least significant bit to record whether we have already
6995 generated the necessary reloc. */
7000 /* If we are addressing a Thumb function, we need to
7001 adjust the address by one, so that attempts to
7002 call the function pointer will correctly
7003 interpret it as Thumb code. */
7004 if (sym_flags == STT_ARM_TFUNC)
7007 if (globals->use_rel)
7008 bfd_put_32 (output_bfd, value, sgot->contents + off);
7013 Elf_Internal_Rela outrel;
7016 srelgot = (bfd_get_section_by_name
7017 (dynobj, RELOC_SECTION (globals, ".got")));
7018 BFD_ASSERT (srelgot != NULL);
7020 outrel.r_addend = addend + value;
7021 outrel.r_offset = (sgot->output_section->vma
7022 + sgot->output_offset
7024 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
7025 loc = srelgot->contents;
7026 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
7027 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7030 local_got_offsets[r_symndx] |= 1;
7033 value = sgot->output_offset + off;
7035 if (r_type != R_ARM_GOT32)
7036 value += sgot->output_section->vma;
7038 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7039 contents, rel->r_offset, value,
7042 case R_ARM_TLS_LDO32:
7043 value = value - dtpoff_base (info);
7045 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7046 contents, rel->r_offset, value,
7049 case R_ARM_TLS_LDM32:
7053 if (globals->sgot == NULL)
7056 off = globals->tls_ldm_got.offset;
7062 /* If we don't know the module number, create a relocation
7066 Elf_Internal_Rela outrel;
7069 if (globals->srelgot == NULL)
7072 outrel.r_addend = 0;
7073 outrel.r_offset = (globals->sgot->output_section->vma
7074 + globals->sgot->output_offset + off);
7075 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
7077 if (globals->use_rel)
7078 bfd_put_32 (output_bfd, outrel.r_addend,
7079 globals->sgot->contents + off);
7081 loc = globals->srelgot->contents;
7082 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
7083 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7086 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
7088 globals->tls_ldm_got.offset |= 1;
7091 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7092 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7094 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7095 contents, rel->r_offset, value,
7099 case R_ARM_TLS_GD32:
7100 case R_ARM_TLS_IE32:
7106 if (globals->sgot == NULL)
7113 dyn = globals->root.dynamic_sections_created;
7114 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7116 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7118 *unresolved_reloc_p = FALSE;
7121 off = h->got.offset;
7122 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
7126 if (local_got_offsets == NULL)
7128 off = local_got_offsets[r_symndx];
7129 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
7132 if (tls_type == GOT_UNKNOWN)
7139 bfd_boolean need_relocs = FALSE;
7140 Elf_Internal_Rela outrel;
7141 bfd_byte *loc = NULL;
7144 /* The GOT entries have not been initialized yet. Do it
7145 now, and emit any relocations. If both an IE GOT and a
7146 GD GOT are necessary, we emit the GD first. */
7148 if ((info->shared || indx != 0)
7150 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7151 || h->root.type != bfd_link_hash_undefweak))
7154 if (globals->srelgot == NULL)
7156 loc = globals->srelgot->contents;
7157 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
7160 if (tls_type & GOT_TLS_GD)
7164 outrel.r_addend = 0;
7165 outrel.r_offset = (globals->sgot->output_section->vma
7166 + globals->sgot->output_offset
7168 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
7170 if (globals->use_rel)
7171 bfd_put_32 (output_bfd, outrel.r_addend,
7172 globals->sgot->contents + cur_off);
7174 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7175 globals->srelgot->reloc_count++;
7176 loc += RELOC_SIZE (globals);
7179 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7180 globals->sgot->contents + cur_off + 4);
7183 outrel.r_addend = 0;
7184 outrel.r_info = ELF32_R_INFO (indx,
7185 R_ARM_TLS_DTPOFF32);
7186 outrel.r_offset += 4;
7188 if (globals->use_rel)
7189 bfd_put_32 (output_bfd, outrel.r_addend,
7190 globals->sgot->contents + cur_off + 4);
7193 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7194 globals->srelgot->reloc_count++;
7195 loc += RELOC_SIZE (globals);
7200 /* If we are not emitting relocations for a
7201 general dynamic reference, then we must be in a
7202 static link or an executable link with the
7203 symbol binding locally. Mark it as belonging
7204 to module 1, the executable. */
7205 bfd_put_32 (output_bfd, 1,
7206 globals->sgot->contents + cur_off);
7207 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7208 globals->sgot->contents + cur_off + 4);
7214 if (tls_type & GOT_TLS_IE)
7219 outrel.r_addend = value - dtpoff_base (info);
7221 outrel.r_addend = 0;
7222 outrel.r_offset = (globals->sgot->output_section->vma
7223 + globals->sgot->output_offset
7225 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7227 if (globals->use_rel)
7228 bfd_put_32 (output_bfd, outrel.r_addend,
7229 globals->sgot->contents + cur_off);
7231 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7232 globals->srelgot->reloc_count++;
7233 loc += RELOC_SIZE (globals);
7236 bfd_put_32 (output_bfd, tpoff (info, value),
7237 globals->sgot->contents + cur_off);
7244 local_got_offsets[r_symndx] |= 1;
7247 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7249 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7250 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7252 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7253 contents, rel->r_offset, value,
7257 case R_ARM_TLS_LE32:
7260 (*_bfd_error_handler)
7261 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7262 input_bfd, input_section,
7263 (long) rel->r_offset, howto->name);
7267 value = tpoff (info, value);
7269 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7270 contents, rel->r_offset, value,
7274 if (globals->fix_v4bx)
7276 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7278 /* Ensure that we have a BX instruction. */
7279 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
7281 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7283 /* Branch to veneer. */
7285 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7286 glue_addr -= input_section->output_section->vma
7287 + input_section->output_offset
7288 + rel->r_offset + 8;
7289 insn = (insn & 0xf0000000) | 0x0a000000
7290 | ((glue_addr >> 2) & 0x00ffffff);
7294 /* Preserve Rm (lowest four bits) and the condition code
7295 (highest four bits). Other bits encode MOV PC,Rm. */
7296 insn = (insn & 0xf000000f) | 0x01a0f000;
7299 bfd_put_32 (input_bfd, insn, hit_data);
7301 return bfd_reloc_ok;
7303 case R_ARM_MOVW_ABS_NC:
7304 case R_ARM_MOVT_ABS:
7305 case R_ARM_MOVW_PREL_NC:
7306 case R_ARM_MOVT_PREL:
7307 /* Until we properly support segment-base-relative addressing then
7308 we assume the segment base to be zero, as for the group relocations.
7309 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7310 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7311 case R_ARM_MOVW_BREL_NC:
7312 case R_ARM_MOVW_BREL:
7313 case R_ARM_MOVT_BREL:
7315 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7317 if (globals->use_rel)
7319 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
7320 signed_addend = (addend ^ 0x8000) - 0x8000;
7323 value += signed_addend;
7325 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7326 value -= (input_section->output_section->vma
7327 + input_section->output_offset + rel->r_offset);
7329 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7330 return bfd_reloc_overflow;
7332 if (sym_flags == STT_ARM_TFUNC)
7335 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7336 || r_type == R_ARM_MOVT_BREL)
7340 insn |= value & 0xfff;
7341 insn |= (value & 0xf000) << 4;
7342 bfd_put_32 (input_bfd, insn, hit_data);
7344 return bfd_reloc_ok;
7346 case R_ARM_THM_MOVW_ABS_NC:
7347 case R_ARM_THM_MOVT_ABS:
7348 case R_ARM_THM_MOVW_PREL_NC:
7349 case R_ARM_THM_MOVT_PREL:
7350 /* Until we properly support segment-base-relative addressing then
7351 we assume the segment base to be zero, as for the above relocations.
7352 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7353 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7354 as R_ARM_THM_MOVT_ABS. */
7355 case R_ARM_THM_MOVW_BREL_NC:
7356 case R_ARM_THM_MOVW_BREL:
7357 case R_ARM_THM_MOVT_BREL:
7361 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7362 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7364 if (globals->use_rel)
7366 addend = ((insn >> 4) & 0xf000)
7367 | ((insn >> 15) & 0x0800)
7368 | ((insn >> 4) & 0x0700)
7370 signed_addend = (addend ^ 0x8000) - 0x8000;
7373 value += signed_addend;
7375 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7376 value -= (input_section->output_section->vma
7377 + input_section->output_offset + rel->r_offset);
7379 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7380 return bfd_reloc_overflow;
7382 if (sym_flags == STT_ARM_TFUNC)
7385 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7386 || r_type == R_ARM_THM_MOVT_BREL)
7390 insn |= (value & 0xf000) << 4;
7391 insn |= (value & 0x0800) << 15;
7392 insn |= (value & 0x0700) << 4;
7393 insn |= (value & 0x00ff);
7395 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7396 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7398 return bfd_reloc_ok;
7400 case R_ARM_ALU_PC_G0_NC:
7401 case R_ARM_ALU_PC_G1_NC:
7402 case R_ARM_ALU_PC_G0:
7403 case R_ARM_ALU_PC_G1:
7404 case R_ARM_ALU_PC_G2:
7405 case R_ARM_ALU_SB_G0_NC:
7406 case R_ARM_ALU_SB_G1_NC:
7407 case R_ARM_ALU_SB_G0:
7408 case R_ARM_ALU_SB_G1:
7409 case R_ARM_ALU_SB_G2:
7411 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7412 bfd_vma pc = input_section->output_section->vma
7413 + input_section->output_offset + rel->r_offset;
7414 /* sb should be the origin of the *segment* containing the symbol.
7415 It is not clear how to obtain this OS-dependent value, so we
7416 make an arbitrary choice of zero. */
7420 bfd_signed_vma signed_value;
7423 /* Determine which group of bits to select. */
7426 case R_ARM_ALU_PC_G0_NC:
7427 case R_ARM_ALU_PC_G0:
7428 case R_ARM_ALU_SB_G0_NC:
7429 case R_ARM_ALU_SB_G0:
7433 case R_ARM_ALU_PC_G1_NC:
7434 case R_ARM_ALU_PC_G1:
7435 case R_ARM_ALU_SB_G1_NC:
7436 case R_ARM_ALU_SB_G1:
7440 case R_ARM_ALU_PC_G2:
7441 case R_ARM_ALU_SB_G2:
7449 /* If REL, extract the addend from the insn. If RELA, it will
7450 have already been fetched for us. */
7451 if (globals->use_rel)
7454 bfd_vma constant = insn & 0xff;
7455 bfd_vma rotation = (insn & 0xf00) >> 8;
7458 signed_addend = constant;
7461 /* Compensate for the fact that in the instruction, the
7462 rotation is stored in multiples of 2 bits. */
7465 /* Rotate "constant" right by "rotation" bits. */
7466 signed_addend = (constant >> rotation) |
7467 (constant << (8 * sizeof (bfd_vma) - rotation));
7470 /* Determine if the instruction is an ADD or a SUB.
7471 (For REL, this determines the sign of the addend.) */
7472 negative = identify_add_or_sub (insn);
7475 (*_bfd_error_handler)
7476 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7477 input_bfd, input_section,
7478 (long) rel->r_offset, howto->name);
7479 return bfd_reloc_overflow;
7482 signed_addend *= negative;
7485 /* Compute the value (X) to go in the place. */
7486 if (r_type == R_ARM_ALU_PC_G0_NC
7487 || r_type == R_ARM_ALU_PC_G1_NC
7488 || r_type == R_ARM_ALU_PC_G0
7489 || r_type == R_ARM_ALU_PC_G1
7490 || r_type == R_ARM_ALU_PC_G2)
7492 signed_value = value - pc + signed_addend;
7494 /* Section base relative. */
7495 signed_value = value - sb + signed_addend;
7497 /* If the target symbol is a Thumb function, then set the
7498 Thumb bit in the address. */
7499 if (sym_flags == STT_ARM_TFUNC)
7502 /* Calculate the value of the relevant G_n, in encoded
7503 constant-with-rotation format. */
7504 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7507 /* Check for overflow if required. */
7508 if ((r_type == R_ARM_ALU_PC_G0
7509 || r_type == R_ARM_ALU_PC_G1
7510 || r_type == R_ARM_ALU_PC_G2
7511 || r_type == R_ARM_ALU_SB_G0
7512 || r_type == R_ARM_ALU_SB_G1
7513 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7515 (*_bfd_error_handler)
7516 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7517 input_bfd, input_section,
7518 (long) rel->r_offset, abs (signed_value), howto->name);
7519 return bfd_reloc_overflow;
7522 /* Mask out the value and the ADD/SUB part of the opcode; take care
7523 not to destroy the S bit. */
7526 /* Set the opcode according to whether the value to go in the
7527 place is negative. */
7528 if (signed_value < 0)
7533 /* Encode the offset. */
7536 bfd_put_32 (input_bfd, insn, hit_data);
7538 return bfd_reloc_ok;
7540 case R_ARM_LDR_PC_G0:
7541 case R_ARM_LDR_PC_G1:
7542 case R_ARM_LDR_PC_G2:
7543 case R_ARM_LDR_SB_G0:
7544 case R_ARM_LDR_SB_G1:
7545 case R_ARM_LDR_SB_G2:
7547 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7548 bfd_vma pc = input_section->output_section->vma
7549 + input_section->output_offset + rel->r_offset;
7550 bfd_vma sb = 0; /* See note above. */
7552 bfd_signed_vma signed_value;
7555 /* Determine which groups of bits to calculate. */
7558 case R_ARM_LDR_PC_G0:
7559 case R_ARM_LDR_SB_G0:
7563 case R_ARM_LDR_PC_G1:
7564 case R_ARM_LDR_SB_G1:
7568 case R_ARM_LDR_PC_G2:
7569 case R_ARM_LDR_SB_G2:
7577 /* If REL, extract the addend from the insn. If RELA, it will
7578 have already been fetched for us. */
7579 if (globals->use_rel)
7581 int negative = (insn & (1 << 23)) ? 1 : -1;
7582 signed_addend = negative * (insn & 0xfff);
7585 /* Compute the value (X) to go in the place. */
7586 if (r_type == R_ARM_LDR_PC_G0
7587 || r_type == R_ARM_LDR_PC_G1
7588 || r_type == R_ARM_LDR_PC_G2)
7590 signed_value = value - pc + signed_addend;
7592 /* Section base relative. */
7593 signed_value = value - sb + signed_addend;
7595 /* Calculate the value of the relevant G_{n-1} to obtain
7596 the residual at that stage. */
7597 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7599 /* Check for overflow. */
7600 if (residual >= 0x1000)
7602 (*_bfd_error_handler)
7603 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7604 input_bfd, input_section,
7605 (long) rel->r_offset, abs (signed_value), howto->name);
7606 return bfd_reloc_overflow;
7609 /* Mask out the value and U bit. */
7612 /* Set the U bit if the value to go in the place is non-negative. */
7613 if (signed_value >= 0)
7616 /* Encode the offset. */
7619 bfd_put_32 (input_bfd, insn, hit_data);
7621 return bfd_reloc_ok;
7623 case R_ARM_LDRS_PC_G0:
7624 case R_ARM_LDRS_PC_G1:
7625 case R_ARM_LDRS_PC_G2:
7626 case R_ARM_LDRS_SB_G0:
7627 case R_ARM_LDRS_SB_G1:
7628 case R_ARM_LDRS_SB_G2:
7630 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7631 bfd_vma pc = input_section->output_section->vma
7632 + input_section->output_offset + rel->r_offset;
7633 bfd_vma sb = 0; /* See note above. */
7635 bfd_signed_vma signed_value;
7638 /* Determine which groups of bits to calculate. */
7641 case R_ARM_LDRS_PC_G0:
7642 case R_ARM_LDRS_SB_G0:
7646 case R_ARM_LDRS_PC_G1:
7647 case R_ARM_LDRS_SB_G1:
7651 case R_ARM_LDRS_PC_G2:
7652 case R_ARM_LDRS_SB_G2:
7660 /* If REL, extract the addend from the insn. If RELA, it will
7661 have already been fetched for us. */
7662 if (globals->use_rel)
7664 int negative = (insn & (1 << 23)) ? 1 : -1;
7665 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7668 /* Compute the value (X) to go in the place. */
7669 if (r_type == R_ARM_LDRS_PC_G0
7670 || r_type == R_ARM_LDRS_PC_G1
7671 || r_type == R_ARM_LDRS_PC_G2)
7673 signed_value = value - pc + signed_addend;
7675 /* Section base relative. */
7676 signed_value = value - sb + signed_addend;
7678 /* Calculate the value of the relevant G_{n-1} to obtain
7679 the residual at that stage. */
7680 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7682 /* Check for overflow. */
7683 if (residual >= 0x100)
7685 (*_bfd_error_handler)
7686 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7687 input_bfd, input_section,
7688 (long) rel->r_offset, abs (signed_value), howto->name);
7689 return bfd_reloc_overflow;
7692 /* Mask out the value and U bit. */
7695 /* Set the U bit if the value to go in the place is non-negative. */
7696 if (signed_value >= 0)
7699 /* Encode the offset. */
7700 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7702 bfd_put_32 (input_bfd, insn, hit_data);
7704 return bfd_reloc_ok;
7706 case R_ARM_LDC_PC_G0:
7707 case R_ARM_LDC_PC_G1:
7708 case R_ARM_LDC_PC_G2:
7709 case R_ARM_LDC_SB_G0:
7710 case R_ARM_LDC_SB_G1:
7711 case R_ARM_LDC_SB_G2:
7713 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7714 bfd_vma pc = input_section->output_section->vma
7715 + input_section->output_offset + rel->r_offset;
7716 bfd_vma sb = 0; /* See note above. */
7718 bfd_signed_vma signed_value;
7721 /* Determine which groups of bits to calculate. */
7724 case R_ARM_LDC_PC_G0:
7725 case R_ARM_LDC_SB_G0:
7729 case R_ARM_LDC_PC_G1:
7730 case R_ARM_LDC_SB_G1:
7734 case R_ARM_LDC_PC_G2:
7735 case R_ARM_LDC_SB_G2:
7743 /* If REL, extract the addend from the insn. If RELA, it will
7744 have already been fetched for us. */
7745 if (globals->use_rel)
7747 int negative = (insn & (1 << 23)) ? 1 : -1;
7748 signed_addend = negative * ((insn & 0xff) << 2);
7751 /* Compute the value (X) to go in the place. */
7752 if (r_type == R_ARM_LDC_PC_G0
7753 || r_type == R_ARM_LDC_PC_G1
7754 || r_type == R_ARM_LDC_PC_G2)
7756 signed_value = value - pc + signed_addend;
7758 /* Section base relative. */
7759 signed_value = value - sb + signed_addend;
7761 /* Calculate the value of the relevant G_{n-1} to obtain
7762 the residual at that stage. */
7763 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7765 /* Check for overflow. (The absolute value to go in the place must be
7766 divisible by four and, after having been divided by four, must
7767 fit in eight bits.) */
7768 if ((residual & 0x3) != 0 || residual >= 0x400)
7770 (*_bfd_error_handler)
7771 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7772 input_bfd, input_section,
7773 (long) rel->r_offset, abs (signed_value), howto->name);
7774 return bfd_reloc_overflow;
7777 /* Mask out the value and U bit. */
7780 /* Set the U bit if the value to go in the place is non-negative. */
7781 if (signed_value >= 0)
7784 /* Encode the offset. */
7785 insn |= residual >> 2;
7787 bfd_put_32 (input_bfd, insn, hit_data);
7789 return bfd_reloc_ok;
7792 return bfd_reloc_notsupported;
7796 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7798 arm_add_to_rel (bfd * abfd,
7800 reloc_howto_type * howto,
7801 bfd_signed_vma increment)
7803 bfd_signed_vma addend;
7805 if (howto->type == R_ARM_THM_CALL
7806 || howto->type == R_ARM_THM_JUMP24)
7808 int upper_insn, lower_insn;
7811 upper_insn = bfd_get_16 (abfd, address);
7812 lower_insn = bfd_get_16 (abfd, address + 2);
7813 upper = upper_insn & 0x7ff;
7814 lower = lower_insn & 0x7ff;
7816 addend = (upper << 12) | (lower << 1);
7817 addend += increment;
7820 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7821 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7823 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7824 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
7830 contents = bfd_get_32 (abfd, address);
7832 /* Get the (signed) value from the instruction. */
7833 addend = contents & howto->src_mask;
7834 if (addend & ((howto->src_mask + 1) >> 1))
7836 bfd_signed_vma mask;
7839 mask &= ~ howto->src_mask;
7843 /* Add in the increment, (which is a byte value). */
7844 switch (howto->type)
7847 addend += increment;
7854 addend <<= howto->size;
7855 addend += increment;
7857 /* Should we check for overflow here ? */
7859 /* Drop any undesired bits. */
7860 addend >>= howto->rightshift;
7864 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7866 bfd_put_32 (abfd, contents, address);
7870 #define IS_ARM_TLS_RELOC(R_TYPE) \
7871 ((R_TYPE) == R_ARM_TLS_GD32 \
7872 || (R_TYPE) == R_ARM_TLS_LDO32 \
7873 || (R_TYPE) == R_ARM_TLS_LDM32 \
7874 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7875 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7876 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7877 || (R_TYPE) == R_ARM_TLS_LE32 \
7878 || (R_TYPE) == R_ARM_TLS_IE32)
7880 /* Relocate an ARM ELF section. */
7883 elf32_arm_relocate_section (bfd * output_bfd,
7884 struct bfd_link_info * info,
7886 asection * input_section,
7887 bfd_byte * contents,
7888 Elf_Internal_Rela * relocs,
7889 Elf_Internal_Sym * local_syms,
7890 asection ** local_sections)
7892 Elf_Internal_Shdr *symtab_hdr;
7893 struct elf_link_hash_entry **sym_hashes;
7894 Elf_Internal_Rela *rel;
7895 Elf_Internal_Rela *relend;
7897 struct elf32_arm_link_hash_table * globals;
7899 globals = elf32_arm_hash_table (info);
7901 symtab_hdr = & elf_symtab_hdr (input_bfd);
7902 sym_hashes = elf_sym_hashes (input_bfd);
7905 relend = relocs + input_section->reloc_count;
7906 for (; rel < relend; rel++)
7909 reloc_howto_type * howto;
7910 unsigned long r_symndx;
7911 Elf_Internal_Sym * sym;
7913 struct elf_link_hash_entry * h;
7915 bfd_reloc_status_type r;
7918 bfd_boolean unresolved_reloc = FALSE;
7919 char *error_message = NULL;
7921 r_symndx = ELF32_R_SYM (rel->r_info);
7922 r_type = ELF32_R_TYPE (rel->r_info);
7923 r_type = arm_real_reloc_type (globals, r_type);
7925 if ( r_type == R_ARM_GNU_VTENTRY
7926 || r_type == R_ARM_GNU_VTINHERIT)
7929 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
7930 howto = bfd_reloc.howto;
7936 if (r_symndx < symtab_hdr->sh_info)
7938 sym = local_syms + r_symndx;
7939 sym_type = ELF32_ST_TYPE (sym->st_info);
7940 sec = local_sections[r_symndx];
7941 if (globals->use_rel)
7943 relocation = (sec->output_section->vma
7944 + sec->output_offset
7946 if (!info->relocatable
7947 && (sec->flags & SEC_MERGE)
7948 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7951 bfd_vma addend, value;
7955 case R_ARM_MOVW_ABS_NC:
7956 case R_ARM_MOVT_ABS:
7957 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7958 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7959 addend = (addend ^ 0x8000) - 0x8000;
7962 case R_ARM_THM_MOVW_ABS_NC:
7963 case R_ARM_THM_MOVT_ABS:
7964 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7966 value |= bfd_get_16 (input_bfd,
7967 contents + rel->r_offset + 2);
7968 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
7969 | ((value & 0x04000000) >> 15);
7970 addend = (addend ^ 0x8000) - 0x8000;
7974 if (howto->rightshift
7975 || (howto->src_mask & (howto->src_mask + 1)))
7977 (*_bfd_error_handler)
7978 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7979 input_bfd, input_section,
7980 (long) rel->r_offset, howto->name);
7984 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7986 /* Get the (signed) value from the instruction. */
7987 addend = value & howto->src_mask;
7988 if (addend & ((howto->src_mask + 1) >> 1))
7990 bfd_signed_vma mask;
7993 mask &= ~ howto->src_mask;
8001 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
8003 addend += msec->output_section->vma + msec->output_offset;
8005 /* Cases here must match those in the preceeding
8006 switch statement. */
8009 case R_ARM_MOVW_ABS_NC:
8010 case R_ARM_MOVT_ABS:
8011 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
8013 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8016 case R_ARM_THM_MOVW_ABS_NC:
8017 case R_ARM_THM_MOVT_ABS:
8018 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
8019 | (addend & 0xff) | ((addend & 0x0800) << 15);
8020 bfd_put_16 (input_bfd, value >> 16,
8021 contents + rel->r_offset);
8022 bfd_put_16 (input_bfd, value,
8023 contents + rel->r_offset + 2);
8027 value = (value & ~ howto->dst_mask)
8028 | (addend & howto->dst_mask);
8029 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
8035 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
8041 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
8042 r_symndx, symtab_hdr, sym_hashes,
8044 unresolved_reloc, warned);
8049 if (sec != NULL && elf_discarded_section (sec))
8051 /* For relocs against symbols from removed linkonce sections,
8052 or sections discarded by a linker script, we just want the
8053 section contents zeroed. Avoid any special processing. */
8054 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
8060 if (info->relocatable)
8062 /* This is a relocatable link. We don't have to change
8063 anything, unless the reloc is against a section symbol,
8064 in which case we have to adjust according to where the
8065 section symbol winds up in the output section. */
8066 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8068 if (globals->use_rel)
8069 arm_add_to_rel (input_bfd, contents + rel->r_offset,
8070 howto, (bfd_signed_vma) sec->output_offset);
8072 rel->r_addend += sec->output_offset;
8078 name = h->root.root.string;
8081 name = (bfd_elf_string_from_elf_section
8082 (input_bfd, symtab_hdr->sh_link, sym->st_name));
8083 if (name == NULL || *name == '\0')
8084 name = bfd_section_name (input_bfd, sec);
8088 && r_type != R_ARM_NONE
8090 || h->root.type == bfd_link_hash_defined
8091 || h->root.type == bfd_link_hash_defweak)
8092 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
8094 (*_bfd_error_handler)
8095 ((sym_type == STT_TLS
8096 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8097 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8100 (long) rel->r_offset,
8105 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
8106 input_section, contents, rel,
8107 relocation, info, sec, name,
8108 (h ? ELF_ST_TYPE (h->type) :
8109 ELF_ST_TYPE (sym->st_info)), h,
8110 &unresolved_reloc, &error_message);
8112 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8113 because such sections are not SEC_ALLOC and thus ld.so will
8114 not process them. */
8115 if (unresolved_reloc
8116 && !((input_section->flags & SEC_DEBUGGING) != 0
8119 (*_bfd_error_handler)
8120 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8123 (long) rel->r_offset,
8125 h->root.root.string);
8129 if (r != bfd_reloc_ok)
8133 case bfd_reloc_overflow:
8134 /* If the overflowing reloc was to an undefined symbol,
8135 we have already printed one error message and there
8136 is no point complaining again. */
8138 h->root.type != bfd_link_hash_undefined)
8139 && (!((*info->callbacks->reloc_overflow)
8140 (info, (h ? &h->root : NULL), name, howto->name,
8141 (bfd_vma) 0, input_bfd, input_section,
8146 case bfd_reloc_undefined:
8147 if (!((*info->callbacks->undefined_symbol)
8148 (info, name, input_bfd, input_section,
8149 rel->r_offset, TRUE)))
8153 case bfd_reloc_outofrange:
8154 error_message = _("out of range");
8157 case bfd_reloc_notsupported:
8158 error_message = _("unsupported relocation");
8161 case bfd_reloc_dangerous:
8162 /* error_message should already be set. */
8166 error_message = _("unknown error");
8170 BFD_ASSERT (error_message != NULL);
8171 if (!((*info->callbacks->reloc_dangerous)
8172 (info, error_message, input_bfd, input_section,
8184 elf32_arm_output_glue_section (struct bfd_link_info *info, bfd *obfd,
8185 bfd *ibfd, const char *name)
8187 asection *sec, *osec;
8189 sec = bfd_get_section_by_name (ibfd, name);
8190 if (sec == NULL || (sec->flags & SEC_EXCLUDE) != 0)
8193 osec = sec->output_section;
8194 if (elf32_arm_write_section (obfd, info, sec, sec->contents))
8197 if (! bfd_set_section_contents (obfd, osec, sec->contents,
8198 sec->output_offset, sec->size))
8205 elf32_arm_final_link (bfd *abfd, struct bfd_link_info *info)
8207 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
8209 /* Invoke the regular ELF backend linker to do all the work. */
8210 if (!bfd_elf_final_link (abfd, info))
8213 /* Write out any glue sections now that we have created all the
8215 if (globals->bfd_of_glue_owner != NULL)
8217 if (! elf32_arm_output_glue_section (info, abfd,
8218 globals->bfd_of_glue_owner,
8219 ARM2THUMB_GLUE_SECTION_NAME))
8222 if (! elf32_arm_output_glue_section (info, abfd,
8223 globals->bfd_of_glue_owner,
8224 THUMB2ARM_GLUE_SECTION_NAME))
8227 if (! elf32_arm_output_glue_section (info, abfd,
8228 globals->bfd_of_glue_owner,
8229 VFP11_ERRATUM_VENEER_SECTION_NAME))
8232 if (! elf32_arm_output_glue_section (info, abfd,
8233 globals->bfd_of_glue_owner,
8234 ARM_BX_GLUE_SECTION_NAME))
8241 /* Set the right machine number. */
8244 elf32_arm_object_p (bfd *abfd)
8248 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
8250 if (mach != bfd_mach_arm_unknown)
8251 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8253 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8254 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
8257 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8262 /* Function to keep ARM specific flags in the ELF header. */
8265 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
8267 if (elf_flags_init (abfd)
8268 && elf_elfheader (abfd)->e_flags != flags)
8270 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8272 if (flags & EF_ARM_INTERWORK)
8273 (*_bfd_error_handler)
8274 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8278 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8284 elf_elfheader (abfd)->e_flags = flags;
8285 elf_flags_init (abfd) = TRUE;
8291 /* Copy backend specific data from one object module to another. */
8294 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
8299 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8302 in_flags = elf_elfheader (ibfd)->e_flags;
8303 out_flags = elf_elfheader (obfd)->e_flags;
8305 if (elf_flags_init (obfd)
8306 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8307 && in_flags != out_flags)
8309 /* Cannot mix APCS26 and APCS32 code. */
8310 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8313 /* Cannot mix float APCS and non-float APCS code. */
8314 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8317 /* If the src and dest have different interworking flags
8318 then turn off the interworking bit. */
8319 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8321 if (out_flags & EF_ARM_INTERWORK)
8323 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8326 in_flags &= ~EF_ARM_INTERWORK;
8329 /* Likewise for PIC, though don't warn for this case. */
8330 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8331 in_flags &= ~EF_ARM_PIC;
8334 elf_elfheader (obfd)->e_flags = in_flags;
8335 elf_flags_init (obfd) = TRUE;
8337 /* Also copy the EI_OSABI field. */
8338 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8339 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8341 /* Copy object attributes. */
8342 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8347 /* Values for Tag_ABI_PCS_R9_use. */
8356 /* Values for Tag_ABI_PCS_RW_data. */
8359 AEABI_PCS_RW_data_absolute,
8360 AEABI_PCS_RW_data_PCrel,
8361 AEABI_PCS_RW_data_SBrel,
8362 AEABI_PCS_RW_data_unused
8365 /* Values for Tag_ABI_enum_size. */
8371 AEABI_enum_forced_wide
8374 /* Determine whether an object attribute tag takes an integer, a
8378 elf32_arm_obj_attrs_arg_type (int tag)
8380 if (tag == Tag_compatibility)
8381 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
8382 else if (tag == Tag_nodefaults)
8383 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
8384 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
8385 return ATTR_TYPE_FLAG_STR_VAL;
8387 return ATTR_TYPE_FLAG_INT_VAL;
8389 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
8392 /* The ABI defines that Tag_conformance should be emitted first, and that
8393 Tag_nodefaults should be second (if either is defined). This sets those
8394 two positions, and bumps up the position of all the remaining tags to
8397 elf32_arm_obj_attrs_order (int num)
8400 return Tag_conformance;
8402 return Tag_nodefaults;
8403 if ((num - 2) < Tag_nodefaults)
8405 if ((num - 1) < Tag_conformance)
8410 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
8411 Returns -1 if no architecture could be read. */
8414 get_secondary_compatible_arch (bfd *abfd)
8416 obj_attribute *attr =
8417 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8419 /* Note: the tag and its argument below are uleb128 values, though
8420 currently-defined values fit in one byte for each. */
8422 && attr->s[0] == Tag_CPU_arch
8423 && (attr->s[1] & 128) != 128
8427 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8431 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8432 The tag is removed if ARCH is -1. */
8435 set_secondary_compatible_arch (bfd *abfd, int arch)
8437 obj_attribute *attr =
8438 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8446 /* Note: the tag and its argument below are uleb128 values, though
8447 currently-defined values fit in one byte for each. */
8449 attr->s = bfd_alloc (abfd, 3);
8450 attr->s[0] = Tag_CPU_arch;
8455 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8459 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
8460 int newtag, int secondary_compat)
8462 #define T(X) TAG_CPU_ARCH_##X
8463 int tagl, tagh, result;
8466 T(V6T2), /* PRE_V4. */
8470 T(V6T2), /* V5TE. */
8471 T(V6T2), /* V5TEJ. */
8478 T(V6K), /* PRE_V4. */
8483 T(V6K), /* V5TEJ. */
8485 T(V6KZ), /* V6KZ. */
8491 T(V7), /* PRE_V4. */
8510 T(V6K), /* V5TEJ. */
8512 T(V6KZ), /* V6KZ. */
8525 T(V6K), /* V5TEJ. */
8527 T(V6KZ), /* V6KZ. */
8531 T(V6S_M), /* V6_M. */
8532 T(V6S_M) /* V6S_M. */
8534 const int v4t_plus_v6_m[] =
8540 T(V5TE), /* V5TE. */
8541 T(V5TEJ), /* V5TEJ. */
8543 T(V6KZ), /* V6KZ. */
8544 T(V6T2), /* V6T2. */
8547 T(V6_M), /* V6_M. */
8548 T(V6S_M), /* V6S_M. */
8549 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
8558 /* Pseudo-architecture. */
8562 /* Check we've not got a higher architecture than we know about. */
8564 if (oldtag >= MAX_TAG_CPU_ARCH || newtag >= MAX_TAG_CPU_ARCH)
8566 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd);
8570 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8572 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
8573 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
8574 oldtag = T(V4T_PLUS_V6_M);
8576 /* And override the new tag if we have a Tag_also_compatible_with on the
8579 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
8580 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
8581 newtag = T(V4T_PLUS_V6_M);
8583 tagl = (oldtag < newtag) ? oldtag : newtag;
8584 result = tagh = (oldtag > newtag) ? oldtag : newtag;
8586 /* Architectures before V6KZ add features monotonically. */
8587 if (tagh <= TAG_CPU_ARCH_V6KZ)
8590 result = comb[tagh - T(V6T2)][tagl];
8592 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8593 as the canonical version. */
8594 if (result == T(V4T_PLUS_V6_M))
8597 *secondary_compat_out = T(V6_M);
8600 *secondary_compat_out = -1;
8604 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
8605 ibfd, oldtag, newtag);
8613 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8614 are conflicting attributes. */
8617 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8619 obj_attribute *in_attr;
8620 obj_attribute *out_attr;
8621 obj_attribute_list *in_list;
8622 obj_attribute_list *out_list;
8623 obj_attribute_list **out_listp;
8624 /* Some tags have 0 = don't care, 1 = strong requirement,
8625 2 = weak requirement. */
8626 static const int order_021[3] = {0, 2, 1};
8627 /* For use with Tag_VFP_arch. */
8628 static const int order_01243[5] = {0, 1, 2, 4, 3};
8630 bfd_boolean result = TRUE;
8632 /* Skip the linker stubs file. This preserves previous behavior
8633 of accepting unknown attributes in the first input file - but
8635 if (ibfd->flags & BFD_LINKER_CREATED)
8638 if (!elf_known_obj_attributes_proc (obfd)[0].i)
8640 /* This is the first object. Copy the attributes. */
8641 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8643 /* Use the Tag_null value to indicate the attributes have been
8645 elf_known_obj_attributes_proc (obfd)[0].i = 1;
8650 in_attr = elf_known_obj_attributes_proc (ibfd);
8651 out_attr = elf_known_obj_attributes_proc (obfd);
8652 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8653 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8655 /* Ignore mismatches if the object doesn't use floating point. */
8656 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8657 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8658 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8661 (_("error: %B uses VFP register arguments, %B does not"),
8667 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
8669 /* Merge this attribute with existing attributes. */
8672 case Tag_CPU_raw_name:
8674 /* These are merged after Tag_CPU_arch. */
8677 case Tag_ABI_optimization_goals:
8678 case Tag_ABI_FP_optimization_goals:
8679 /* Use the first value seen. */
8684 int secondary_compat = -1, secondary_compat_out = -1;
8685 unsigned int saved_out_attr = out_attr[i].i;
8686 static const char *name_table[] = {
8687 /* These aren't real CPU names, but we can't guess
8688 that from the architecture version alone. */
8704 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8705 secondary_compat = get_secondary_compatible_arch (ibfd);
8706 secondary_compat_out = get_secondary_compatible_arch (obfd);
8707 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
8708 &secondary_compat_out,
8711 set_secondary_compatible_arch (obfd, secondary_compat_out);
8713 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8714 if (out_attr[i].i == saved_out_attr)
8715 ; /* Leave the names alone. */
8716 else if (out_attr[i].i == in_attr[i].i)
8718 /* The output architecture has been changed to match the
8719 input architecture. Use the input names. */
8720 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
8721 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
8723 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
8724 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
8729 out_attr[Tag_CPU_name].s = NULL;
8730 out_attr[Tag_CPU_raw_name].s = NULL;
8733 /* If we still don't have a value for Tag_CPU_name,
8734 make one up now. Tag_CPU_raw_name remains blank. */
8735 if (out_attr[Tag_CPU_name].s == NULL
8736 && out_attr[i].i < ARRAY_SIZE (name_table))
8737 out_attr[Tag_CPU_name].s =
8738 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
8742 case Tag_ARM_ISA_use:
8743 case Tag_THUMB_ISA_use:
8745 case Tag_Advanced_SIMD_arch:
8746 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
8747 case Tag_ABI_FP_rounding:
8748 case Tag_ABI_FP_exceptions:
8749 case Tag_ABI_FP_user_exceptions:
8750 case Tag_ABI_FP_number_model:
8751 case Tag_VFP_HP_extension:
8752 case Tag_CPU_unaligned_access:
8754 case Tag_Virtualization_use:
8755 case Tag_MPextension_use:
8756 /* Use the largest value specified. */
8757 if (in_attr[i].i > out_attr[i].i)
8758 out_attr[i].i = in_attr[i].i;
8761 case Tag_ABI_align8_preserved:
8762 case Tag_ABI_PCS_RO_data:
8763 /* Use the smallest value specified. */
8764 if (in_attr[i].i < out_attr[i].i)
8765 out_attr[i].i = in_attr[i].i;
8768 case Tag_ABI_align8_needed:
8769 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
8770 && (in_attr[Tag_ABI_align8_preserved].i == 0
8771 || out_attr[Tag_ABI_align8_preserved].i == 0))
8773 /* This error message should be enabled once all non-conformant
8774 binaries in the toolchain have had the attributes set
8777 (_("error: %B: 8-byte data alignment conflicts with %B"),
8782 case Tag_ABI_FP_denormal:
8783 case Tag_ABI_PCS_GOT_use:
8784 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8785 value if greater than 2 (for future-proofing). */
8786 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
8787 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
8788 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
8789 out_attr[i].i = in_attr[i].i;
8793 case Tag_CPU_arch_profile:
8794 if (out_attr[i].i != in_attr[i].i)
8796 /* 0 will merge with anything.
8797 'A' and 'S' merge to 'A'.
8798 'R' and 'S' merge to 'R'.
8799 'M' and 'A|R|S' is an error. */
8800 if (out_attr[i].i == 0
8801 || (out_attr[i].i == 'S'
8802 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
8803 out_attr[i].i = in_attr[i].i;
8804 else if (in_attr[i].i == 0
8805 || (in_attr[i].i == 'S'
8806 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
8811 (_("error: %B: Conflicting architecture profiles %c/%c"),
8813 in_attr[i].i ? in_attr[i].i : '0',
8814 out_attr[i].i ? out_attr[i].i : '0');
8820 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8821 largest value if greater than 4 (for future-proofing). */
8822 if ((in_attr[i].i > 4 && in_attr[i].i > out_attr[i].i)
8823 || (in_attr[i].i <= 4 && out_attr[i].i <= 4
8824 && order_01243[in_attr[i].i] > order_01243[out_attr[i].i]))
8825 out_attr[i].i = in_attr[i].i;
8827 case Tag_PCS_config:
8828 if (out_attr[i].i == 0)
8829 out_attr[i].i = in_attr[i].i;
8830 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8832 /* It's sometimes ok to mix different configs, so this is only
8835 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8838 case Tag_ABI_PCS_R9_use:
8839 if (in_attr[i].i != out_attr[i].i
8840 && out_attr[i].i != AEABI_R9_unused
8841 && in_attr[i].i != AEABI_R9_unused)
8844 (_("error: %B: Conflicting use of R9"), ibfd);
8847 if (out_attr[i].i == AEABI_R9_unused)
8848 out_attr[i].i = in_attr[i].i;
8850 case Tag_ABI_PCS_RW_data:
8851 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8852 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8853 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8856 (_("error: %B: SB relative addressing conflicts with use of R9"),
8860 /* Use the smallest value specified. */
8861 if (in_attr[i].i < out_attr[i].i)
8862 out_attr[i].i = in_attr[i].i;
8864 case Tag_ABI_PCS_wchar_t:
8865 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8866 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
8869 (_("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"),
8870 ibfd, in_attr[i].i, out_attr[i].i);
8872 else if (in_attr[i].i && !out_attr[i].i)
8873 out_attr[i].i = in_attr[i].i;
8875 case Tag_ABI_enum_size:
8876 if (in_attr[i].i != AEABI_enum_unused)
8878 if (out_attr[i].i == AEABI_enum_unused
8879 || out_attr[i].i == AEABI_enum_forced_wide)
8881 /* The existing object is compatible with anything.
8882 Use whatever requirements the new object has. */
8883 out_attr[i].i = in_attr[i].i;
8885 else if (in_attr[i].i != AEABI_enum_forced_wide
8886 && out_attr[i].i != in_attr[i].i
8887 && !elf_arm_tdata (obfd)->no_enum_size_warning)
8889 static const char *aeabi_enum_names[] =
8890 { "", "variable-size", "32-bit", "" };
8891 const char *in_name =
8892 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8893 ? aeabi_enum_names[in_attr[i].i]
8895 const char *out_name =
8896 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8897 ? aeabi_enum_names[out_attr[i].i]
8900 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8901 ibfd, in_name, out_name);
8905 case Tag_ABI_VFP_args:
8908 case Tag_ABI_WMMX_args:
8909 if (in_attr[i].i != out_attr[i].i)
8912 (_("error: %B uses iWMMXt register arguments, %B does not"),
8917 case Tag_compatibility:
8918 /* Merged in target-independent code. */
8920 case Tag_ABI_HardFP_use:
8921 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8922 if ((in_attr[i].i == 1 && out_attr[i].i == 2)
8923 || (in_attr[i].i == 2 && out_attr[i].i == 1))
8925 else if (in_attr[i].i > out_attr[i].i)
8926 out_attr[i].i = in_attr[i].i;
8928 case Tag_ABI_FP_16bit_format:
8929 if (in_attr[i].i != 0 && out_attr[i].i != 0)
8931 if (in_attr[i].i != out_attr[i].i)
8934 (_("error: fp16 format mismatch between %B and %B"),
8939 if (in_attr[i].i != 0)
8940 out_attr[i].i = in_attr[i].i;
8943 case Tag_nodefaults:
8944 /* This tag is set if it exists, but the value is unused (and is
8945 typically zero). We don't actually need to do anything here -
8946 the merge happens automatically when the type flags are merged
8949 case Tag_also_compatible_with:
8950 /* Already done in Tag_CPU_arch. */
8952 case Tag_conformance:
8953 /* Keep the attribute if it matches. Throw it away otherwise.
8954 No attribute means no claim to conform. */
8955 if (!in_attr[i].s || !out_attr[i].s
8956 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
8957 out_attr[i].s = NULL;
8962 bfd *err_bfd = NULL;
8964 /* The "known_obj_attributes" table does contain some undefined
8965 attributes. Ensure that there are unused. */
8966 if (out_attr[i].i != 0 || out_attr[i].s != NULL)
8968 else if (in_attr[i].i != 0 || in_attr[i].s != NULL)
8971 if (err_bfd != NULL)
8973 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8977 (_("%B: Unknown mandatory EABI object attribute %d"),
8979 bfd_set_error (bfd_error_bad_value);
8985 (_("Warning: %B: Unknown EABI object attribute %d"),
8990 /* Only pass on attributes that match in both inputs. */
8991 if (in_attr[i].i != out_attr[i].i
8992 || in_attr[i].s != out_attr[i].s
8993 || (in_attr[i].s != NULL && out_attr[i].s != NULL
8994 && strcmp (in_attr[i].s, out_attr[i].s) != 0))
8997 out_attr[i].s = NULL;
9002 /* If out_attr was copied from in_attr then it won't have a type yet. */
9003 if (in_attr[i].type && !out_attr[i].type)
9004 out_attr[i].type = in_attr[i].type;
9007 /* Merge Tag_compatibility attributes and any common GNU ones. */
9008 _bfd_elf_merge_object_attributes (ibfd, obfd);
9010 /* Check for any attributes not known on ARM. */
9011 in_list = elf_other_obj_attributes_proc (ibfd);
9012 out_listp = &elf_other_obj_attributes_proc (obfd);
9013 out_list = *out_listp;
9015 for (; in_list || out_list; )
9017 bfd *err_bfd = NULL;
9020 /* The tags for each list are in numerical order. */
9021 /* If the tags are equal, then merge. */
9022 if (out_list && (!in_list || in_list->tag > out_list->tag))
9024 /* This attribute only exists in obfd. We can't merge, and we don't
9025 know what the tag means, so delete it. */
9027 err_tag = out_list->tag;
9028 *out_listp = out_list->next;
9029 out_list = *out_listp;
9031 else if (in_list && (!out_list || in_list->tag < out_list->tag))
9033 /* This attribute only exists in ibfd. We can't merge, and we don't
9034 know what the tag means, so ignore it. */
9036 err_tag = in_list->tag;
9037 in_list = in_list->next;
9039 else /* The tags are equal. */
9041 /* As present, all attributes in the list are unknown, and
9042 therefore can't be merged meaningfully. */
9044 err_tag = out_list->tag;
9046 /* Only pass on attributes that match in both inputs. */
9047 if (in_list->attr.i != out_list->attr.i
9048 || in_list->attr.s != out_list->attr.s
9049 || (in_list->attr.s && out_list->attr.s
9050 && strcmp (in_list->attr.s, out_list->attr.s) != 0))
9052 /* No match. Delete the attribute. */
9053 *out_listp = out_list->next;
9054 out_list = *out_listp;
9058 /* Matched. Keep the attribute and move to the next. */
9059 out_list = out_list->next;
9060 in_list = in_list->next;
9066 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9067 if ((err_tag & 127) < 64)
9070 (_("%B: Unknown mandatory EABI object attribute %d"),
9072 bfd_set_error (bfd_error_bad_value);
9078 (_("Warning: %B: Unknown EABI object attribute %d"),
9087 /* Return TRUE if the two EABI versions are incompatible. */
9090 elf32_arm_versions_compatible (unsigned iver, unsigned over)
9092 /* v4 and v5 are the same spec before and after it was released,
9093 so allow mixing them. */
9094 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
9095 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
9098 return (iver == over);
9101 /* Merge backend specific data from an object file to the output
9102 object file when linking. */
9105 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
9109 bfd_boolean flags_compatible = TRUE;
9112 /* Check if we have the same endianess. */
9113 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
9116 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
9119 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
9122 /* The input BFD must have had its flags initialised. */
9123 /* The following seems bogus to me -- The flags are initialized in
9124 the assembler but I don't think an elf_flags_init field is
9125 written into the object. */
9126 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9128 in_flags = elf_elfheader (ibfd)->e_flags;
9129 out_flags = elf_elfheader (obfd)->e_flags;
9131 /* In theory there is no reason why we couldn't handle this. However
9132 in practice it isn't even close to working and there is no real
9133 reason to want it. */
9134 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
9135 && !(ibfd->flags & DYNAMIC)
9136 && (in_flags & EF_ARM_BE8))
9138 _bfd_error_handler (_("error: %B is already in final BE8 format"),
9143 if (!elf_flags_init (obfd))
9145 /* If the input is the default architecture and had the default
9146 flags then do not bother setting the flags for the output
9147 architecture, instead allow future merges to do this. If no
9148 future merges ever set these flags then they will retain their
9149 uninitialised values, which surprise surprise, correspond
9150 to the default values. */
9151 if (bfd_get_arch_info (ibfd)->the_default
9152 && elf_elfheader (ibfd)->e_flags == 0)
9155 elf_flags_init (obfd) = TRUE;
9156 elf_elfheader (obfd)->e_flags = in_flags;
9158 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
9159 && bfd_get_arch_info (obfd)->the_default)
9160 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
9165 /* Determine what should happen if the input ARM architecture
9166 does not match the output ARM architecture. */
9167 if (! bfd_arm_merge_machines (ibfd, obfd))
9170 /* Identical flags must be compatible. */
9171 if (in_flags == out_flags)
9174 /* Check to see if the input BFD actually contains any sections. If
9175 not, its flags may not have been initialised either, but it
9176 cannot actually cause any incompatiblity. Do not short-circuit
9177 dynamic objects; their section list may be emptied by
9178 elf_link_add_object_symbols.
9180 Also check to see if there are no code sections in the input.
9181 In this case there is no need to check for code specific flags.
9182 XXX - do we need to worry about floating-point format compatability
9183 in data sections ? */
9184 if (!(ibfd->flags & DYNAMIC))
9186 bfd_boolean null_input_bfd = TRUE;
9187 bfd_boolean only_data_sections = TRUE;
9189 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9191 /* Ignore synthetic glue sections. */
9192 if (strcmp (sec->name, ".glue_7")
9193 && strcmp (sec->name, ".glue_7t"))
9195 if ((bfd_get_section_flags (ibfd, sec)
9196 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9197 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9198 only_data_sections = FALSE;
9200 null_input_bfd = FALSE;
9205 if (null_input_bfd || only_data_sections)
9209 /* Complain about various flag mismatches. */
9210 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
9211 EF_ARM_EABI_VERSION (out_flags)))
9214 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
9216 (in_flags & EF_ARM_EABIMASK) >> 24,
9217 (out_flags & EF_ARM_EABIMASK) >> 24);
9221 /* Not sure what needs to be checked for EABI versions >= 1. */
9222 /* VxWorks libraries do not use these flags. */
9223 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
9224 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
9225 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
9227 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
9230 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9232 in_flags & EF_ARM_APCS_26 ? 26 : 32,
9233 out_flags & EF_ARM_APCS_26 ? 26 : 32);
9234 flags_compatible = FALSE;
9237 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
9239 if (in_flags & EF_ARM_APCS_FLOAT)
9241 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
9245 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
9248 flags_compatible = FALSE;
9251 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
9253 if (in_flags & EF_ARM_VFP_FLOAT)
9255 (_("error: %B uses VFP instructions, whereas %B does not"),
9259 (_("error: %B uses FPA instructions, whereas %B does not"),
9262 flags_compatible = FALSE;
9265 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
9267 if (in_flags & EF_ARM_MAVERICK_FLOAT)
9269 (_("error: %B uses Maverick instructions, whereas %B does not"),
9273 (_("error: %B does not use Maverick instructions, whereas %B does"),
9276 flags_compatible = FALSE;
9279 #ifdef EF_ARM_SOFT_FLOAT
9280 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
9282 /* We can allow interworking between code that is VFP format
9283 layout, and uses either soft float or integer regs for
9284 passing floating point arguments and results. We already
9285 know that the APCS_FLOAT flags match; similarly for VFP
9287 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
9288 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
9290 if (in_flags & EF_ARM_SOFT_FLOAT)
9292 (_("error: %B uses software FP, whereas %B uses hardware FP"),
9296 (_("error: %B uses hardware FP, whereas %B uses software FP"),
9299 flags_compatible = FALSE;
9304 /* Interworking mismatch is only a warning. */
9305 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
9307 if (in_flags & EF_ARM_INTERWORK)
9310 (_("Warning: %B supports interworking, whereas %B does not"),
9316 (_("Warning: %B does not support interworking, whereas %B does"),
9322 return flags_compatible;
9325 /* Display the flags field. */
9328 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
9330 FILE * file = (FILE *) ptr;
9331 unsigned long flags;
9333 BFD_ASSERT (abfd != NULL && ptr != NULL);
9335 /* Print normal ELF private data. */
9336 _bfd_elf_print_private_bfd_data (abfd, ptr);
9338 flags = elf_elfheader (abfd)->e_flags;
9339 /* Ignore init flag - it may not be set, despite the flags field
9340 containing valid data. */
9342 /* xgettext:c-format */
9343 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
9345 switch (EF_ARM_EABI_VERSION (flags))
9347 case EF_ARM_EABI_UNKNOWN:
9348 /* The following flag bits are GNU extensions and not part of the
9349 official ARM ELF extended ABI. Hence they are only decoded if
9350 the EABI version is not set. */
9351 if (flags & EF_ARM_INTERWORK)
9352 fprintf (file, _(" [interworking enabled]"));
9354 if (flags & EF_ARM_APCS_26)
9355 fprintf (file, " [APCS-26]");
9357 fprintf (file, " [APCS-32]");
9359 if (flags & EF_ARM_VFP_FLOAT)
9360 fprintf (file, _(" [VFP float format]"));
9361 else if (flags & EF_ARM_MAVERICK_FLOAT)
9362 fprintf (file, _(" [Maverick float format]"));
9364 fprintf (file, _(" [FPA float format]"));
9366 if (flags & EF_ARM_APCS_FLOAT)
9367 fprintf (file, _(" [floats passed in float registers]"));
9369 if (flags & EF_ARM_PIC)
9370 fprintf (file, _(" [position independent]"));
9372 if (flags & EF_ARM_NEW_ABI)
9373 fprintf (file, _(" [new ABI]"));
9375 if (flags & EF_ARM_OLD_ABI)
9376 fprintf (file, _(" [old ABI]"));
9378 if (flags & EF_ARM_SOFT_FLOAT)
9379 fprintf (file, _(" [software FP]"));
9381 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
9382 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
9383 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
9384 | EF_ARM_MAVERICK_FLOAT);
9387 case EF_ARM_EABI_VER1:
9388 fprintf (file, _(" [Version1 EABI]"));
9390 if (flags & EF_ARM_SYMSARESORTED)
9391 fprintf (file, _(" [sorted symbol table]"));
9393 fprintf (file, _(" [unsorted symbol table]"));
9395 flags &= ~ EF_ARM_SYMSARESORTED;
9398 case EF_ARM_EABI_VER2:
9399 fprintf (file, _(" [Version2 EABI]"));
9401 if (flags & EF_ARM_SYMSARESORTED)
9402 fprintf (file, _(" [sorted symbol table]"));
9404 fprintf (file, _(" [unsorted symbol table]"));
9406 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
9407 fprintf (file, _(" [dynamic symbols use segment index]"));
9409 if (flags & EF_ARM_MAPSYMSFIRST)
9410 fprintf (file, _(" [mapping symbols precede others]"));
9412 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
9413 | EF_ARM_MAPSYMSFIRST);
9416 case EF_ARM_EABI_VER3:
9417 fprintf (file, _(" [Version3 EABI]"));
9420 case EF_ARM_EABI_VER4:
9421 fprintf (file, _(" [Version4 EABI]"));
9424 case EF_ARM_EABI_VER5:
9425 fprintf (file, _(" [Version5 EABI]"));
9427 if (flags & EF_ARM_BE8)
9428 fprintf (file, _(" [BE8]"));
9430 if (flags & EF_ARM_LE8)
9431 fprintf (file, _(" [LE8]"));
9433 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
9437 fprintf (file, _(" <EABI version unrecognised>"));
9441 flags &= ~ EF_ARM_EABIMASK;
9443 if (flags & EF_ARM_RELEXEC)
9444 fprintf (file, _(" [relocatable executable]"));
9446 if (flags & EF_ARM_HASENTRY)
9447 fprintf (file, _(" [has entry point]"));
9449 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
9452 fprintf (file, _("<Unrecognised flag bits set>"));
9460 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
9462 switch (ELF_ST_TYPE (elf_sym->st_info))
9465 return ELF_ST_TYPE (elf_sym->st_info);
9468 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9469 This allows us to distinguish between data used by Thumb instructions
9470 and non-data (which is probably code) inside Thumb regions of an
9472 if (type != STT_OBJECT && type != STT_TLS)
9473 return ELF_ST_TYPE (elf_sym->st_info);
9484 elf32_arm_gc_mark_hook (asection *sec,
9485 struct bfd_link_info *info,
9486 Elf_Internal_Rela *rel,
9487 struct elf_link_hash_entry *h,
9488 Elf_Internal_Sym *sym)
9491 switch (ELF32_R_TYPE (rel->r_info))
9493 case R_ARM_GNU_VTINHERIT:
9494 case R_ARM_GNU_VTENTRY:
9498 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
9501 /* Update the got entry reference counts for the section being removed. */
9504 elf32_arm_gc_sweep_hook (bfd * abfd,
9505 struct bfd_link_info * info,
9507 const Elf_Internal_Rela * relocs)
9509 Elf_Internal_Shdr *symtab_hdr;
9510 struct elf_link_hash_entry **sym_hashes;
9511 bfd_signed_vma *local_got_refcounts;
9512 const Elf_Internal_Rela *rel, *relend;
9513 struct elf32_arm_link_hash_table * globals;
9515 if (info->relocatable)
9518 globals = elf32_arm_hash_table (info);
9520 elf_section_data (sec)->local_dynrel = NULL;
9522 symtab_hdr = & elf_symtab_hdr (abfd);
9523 sym_hashes = elf_sym_hashes (abfd);
9524 local_got_refcounts = elf_local_got_refcounts (abfd);
9526 check_use_blx (globals);
9528 relend = relocs + sec->reloc_count;
9529 for (rel = relocs; rel < relend; rel++)
9531 unsigned long r_symndx;
9532 struct elf_link_hash_entry *h = NULL;
9535 r_symndx = ELF32_R_SYM (rel->r_info);
9536 if (r_symndx >= symtab_hdr->sh_info)
9538 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9539 while (h->root.type == bfd_link_hash_indirect
9540 || h->root.type == bfd_link_hash_warning)
9541 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9544 r_type = ELF32_R_TYPE (rel->r_info);
9545 r_type = arm_real_reloc_type (globals, r_type);
9549 case R_ARM_GOT_PREL:
9550 case R_ARM_TLS_GD32:
9551 case R_ARM_TLS_IE32:
9554 if (h->got.refcount > 0)
9555 h->got.refcount -= 1;
9557 else if (local_got_refcounts != NULL)
9559 if (local_got_refcounts[r_symndx] > 0)
9560 local_got_refcounts[r_symndx] -= 1;
9564 case R_ARM_TLS_LDM32:
9565 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
9569 case R_ARM_ABS32_NOI:
9571 case R_ARM_REL32_NOI:
9577 case R_ARM_THM_CALL:
9578 case R_ARM_THM_JUMP24:
9579 case R_ARM_THM_JUMP19:
9580 case R_ARM_MOVW_ABS_NC:
9581 case R_ARM_MOVT_ABS:
9582 case R_ARM_MOVW_PREL_NC:
9583 case R_ARM_MOVT_PREL:
9584 case R_ARM_THM_MOVW_ABS_NC:
9585 case R_ARM_THM_MOVT_ABS:
9586 case R_ARM_THM_MOVW_PREL_NC:
9587 case R_ARM_THM_MOVT_PREL:
9588 /* Should the interworking branches be here also? */
9592 struct elf32_arm_link_hash_entry *eh;
9593 struct elf32_arm_relocs_copied **pp;
9594 struct elf32_arm_relocs_copied *p;
9596 eh = (struct elf32_arm_link_hash_entry *) h;
9598 if (h->plt.refcount > 0)
9600 h->plt.refcount -= 1;
9601 if (r_type == R_ARM_THM_CALL)
9602 eh->plt_maybe_thumb_refcount--;
9604 if (r_type == R_ARM_THM_JUMP24
9605 || r_type == R_ARM_THM_JUMP19)
9606 eh->plt_thumb_refcount--;
9609 if (r_type == R_ARM_ABS32
9610 || r_type == R_ARM_REL32
9611 || r_type == R_ARM_ABS32_NOI
9612 || r_type == R_ARM_REL32_NOI)
9614 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
9616 if (p->section == sec)
9619 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
9620 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
9638 /* Look through the relocs for a section during the first phase. */
9641 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
9642 asection *sec, const Elf_Internal_Rela *relocs)
9644 Elf_Internal_Shdr *symtab_hdr;
9645 struct elf_link_hash_entry **sym_hashes;
9646 const Elf_Internal_Rela *rel;
9647 const Elf_Internal_Rela *rel_end;
9650 bfd_vma *local_got_offsets;
9651 struct elf32_arm_link_hash_table *htab;
9652 bfd_boolean needs_plt;
9653 unsigned long nsyms;
9655 if (info->relocatable)
9658 BFD_ASSERT (is_arm_elf (abfd));
9660 htab = elf32_arm_hash_table (info);
9663 /* Create dynamic sections for relocatable executables so that we can
9664 copy relocations. */
9665 if (htab->root.is_relocatable_executable
9666 && ! htab->root.dynamic_sections_created)
9668 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
9672 dynobj = elf_hash_table (info)->dynobj;
9673 local_got_offsets = elf_local_got_offsets (abfd);
9675 symtab_hdr = & elf_symtab_hdr (abfd);
9676 sym_hashes = elf_sym_hashes (abfd);
9677 nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
9679 rel_end = relocs + sec->reloc_count;
9680 for (rel = relocs; rel < rel_end; rel++)
9682 struct elf_link_hash_entry *h;
9683 struct elf32_arm_link_hash_entry *eh;
9684 unsigned long r_symndx;
9687 r_symndx = ELF32_R_SYM (rel->r_info);
9688 r_type = ELF32_R_TYPE (rel->r_info);
9689 r_type = arm_real_reloc_type (htab, r_type);
9691 if (r_symndx >= nsyms
9692 /* PR 9934: It is possible to have relocations that do not
9693 refer to symbols, thus it is also possible to have an
9694 object file containing relocations but no symbol table. */
9695 && (r_symndx > 0 || nsyms > 0))
9697 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9702 if (nsyms == 0 || r_symndx < symtab_hdr->sh_info)
9706 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9707 while (h->root.type == bfd_link_hash_indirect
9708 || h->root.type == bfd_link_hash_warning)
9709 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9712 eh = (struct elf32_arm_link_hash_entry *) h;
9717 case R_ARM_GOT_PREL:
9718 case R_ARM_TLS_GD32:
9719 case R_ARM_TLS_IE32:
9720 /* This symbol requires a global offset table entry. */
9722 int tls_type, old_tls_type;
9726 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9727 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9728 default: tls_type = GOT_NORMAL; break;
9734 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9738 bfd_signed_vma *local_got_refcounts;
9740 /* This is a global offset table entry for a local symbol. */
9741 local_got_refcounts = elf_local_got_refcounts (abfd);
9742 if (local_got_refcounts == NULL)
9746 size = symtab_hdr->sh_info;
9747 size *= (sizeof (bfd_signed_vma) + sizeof (char));
9748 local_got_refcounts = bfd_zalloc (abfd, size);
9749 if (local_got_refcounts == NULL)
9751 elf_local_got_refcounts (abfd) = local_got_refcounts;
9752 elf32_arm_local_got_tls_type (abfd)
9753 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9755 local_got_refcounts[r_symndx] += 1;
9756 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9759 /* We will already have issued an error message if there is a
9760 TLS / non-TLS mismatch, based on the symbol type. We don't
9761 support any linker relaxations. So just combine any TLS
9763 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9764 && tls_type != GOT_NORMAL)
9765 tls_type |= old_tls_type;
9767 if (old_tls_type != tls_type)
9770 elf32_arm_hash_entry (h)->tls_type = tls_type;
9772 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9777 case R_ARM_TLS_LDM32:
9778 if (r_type == R_ARM_TLS_LDM32)
9779 htab->tls_ldm_got.refcount++;
9782 case R_ARM_GOTOFF32:
9784 if (htab->sgot == NULL)
9786 if (htab->root.dynobj == NULL)
9787 htab->root.dynobj = abfd;
9788 if (!create_got_section (htab->root.dynobj, info))
9794 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9795 ldr __GOTT_INDEX__ offsets. */
9796 if (!htab->vxworks_p)
9805 case R_ARM_THM_CALL:
9806 case R_ARM_THM_JUMP24:
9807 case R_ARM_THM_JUMP19:
9812 case R_ARM_ABS32_NOI:
9814 case R_ARM_REL32_NOI:
9815 case R_ARM_MOVW_ABS_NC:
9816 case R_ARM_MOVT_ABS:
9817 case R_ARM_MOVW_PREL_NC:
9818 case R_ARM_MOVT_PREL:
9819 case R_ARM_THM_MOVW_ABS_NC:
9820 case R_ARM_THM_MOVT_ABS:
9821 case R_ARM_THM_MOVW_PREL_NC:
9822 case R_ARM_THM_MOVT_PREL:
9826 /* Should the interworking branches be listed here? */
9829 /* If this reloc is in a read-only section, we might
9830 need a copy reloc. We can't check reliably at this
9831 stage whether the section is read-only, as input
9832 sections have not yet been mapped to output sections.
9833 Tentatively set the flag for now, and correct in
9834 adjust_dynamic_symbol. */
9838 /* We may need a .plt entry if the function this reloc
9839 refers to is in a different object. We can't tell for
9840 sure yet, because something later might force the
9845 /* If we create a PLT entry, this relocation will reference
9846 it, even if it's an ABS32 relocation. */
9847 h->plt.refcount += 1;
9849 /* It's too early to use htab->use_blx here, so we have to
9850 record possible blx references separately from
9851 relocs that definitely need a thumb stub. */
9853 if (r_type == R_ARM_THM_CALL)
9854 eh->plt_maybe_thumb_refcount += 1;
9856 if (r_type == R_ARM_THM_JUMP24
9857 || r_type == R_ARM_THM_JUMP19)
9858 eh->plt_thumb_refcount += 1;
9861 /* If we are creating a shared library or relocatable executable,
9862 and this is a reloc against a global symbol, or a non PC
9863 relative reloc against a local symbol, then we need to copy
9864 the reloc into the shared library. However, if we are linking
9865 with -Bsymbolic, we do not need to copy a reloc against a
9866 global symbol which is defined in an object we are
9867 including in the link (i.e., DEF_REGULAR is set). At
9868 this point we have not seen all the input files, so it is
9869 possible that DEF_REGULAR is not set now but will be set
9870 later (it is never cleared). We account for that
9871 possibility below by storing information in the
9872 relocs_copied field of the hash table entry. */
9873 if ((info->shared || htab->root.is_relocatable_executable)
9874 && (sec->flags & SEC_ALLOC) != 0
9875 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
9876 || (h != NULL && ! h->needs_plt
9877 && (! info->symbolic || ! h->def_regular))))
9879 struct elf32_arm_relocs_copied *p, **head;
9881 /* When creating a shared object, we must copy these
9882 reloc types into the output file. We create a reloc
9883 section in dynobj and make room for this reloc. */
9886 sreloc = _bfd_elf_make_dynamic_reloc_section
9887 (sec, dynobj, 2, abfd, ! htab->use_rel);
9892 /* BPABI objects never have dynamic relocations mapped. */
9893 if (htab->symbian_p)
9897 flags = bfd_get_section_flags (dynobj, sreloc);
9898 flags &= ~(SEC_LOAD | SEC_ALLOC);
9899 bfd_set_section_flags (dynobj, sreloc, flags);
9903 /* If this is a global symbol, we count the number of
9904 relocations we need for this symbol. */
9907 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9911 /* Track dynamic relocs needed for local syms too.
9912 We really need local syms available to do this
9918 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9923 vpp = &elf_section_data (s)->local_dynrel;
9924 head = (struct elf32_arm_relocs_copied **) vpp;
9928 if (p == NULL || p->section != sec)
9930 bfd_size_type amt = sizeof *p;
9932 p = bfd_alloc (htab->root.dynobj, amt);
9942 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
9948 /* This relocation describes the C++ object vtable hierarchy.
9949 Reconstruct it for later use during GC. */
9950 case R_ARM_GNU_VTINHERIT:
9951 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
9955 /* This relocation describes which C++ vtable entries are actually
9956 used. Record for later use during GC. */
9957 case R_ARM_GNU_VTENTRY:
9958 BFD_ASSERT (h != NULL);
9960 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
9969 /* Unwinding tables are not referenced directly. This pass marks them as
9970 required if the corresponding code section is marked. */
9973 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9974 elf_gc_mark_hook_fn gc_mark_hook)
9977 Elf_Internal_Shdr **elf_shdrp;
9980 /* Marking EH data may cause additional code sections to be marked,
9981 requiring multiple passes. */
9986 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9990 if (! is_arm_elf (sub))
9993 elf_shdrp = elf_elfsections (sub);
9994 for (o = sub->sections; o != NULL; o = o->next)
9996 Elf_Internal_Shdr *hdr;
9998 hdr = &elf_section_data (o)->this_hdr;
9999 if (hdr->sh_type == SHT_ARM_EXIDX
10001 && hdr->sh_link < elf_numsections (sub)
10003 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
10006 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
10016 /* Treat mapping symbols as special target symbols. */
10019 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
10021 return bfd_is_arm_special_symbol_name (sym->name,
10022 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
10025 /* This is a copy of elf_find_function() from elf.c except that
10026 ARM mapping symbols are ignored when looking for function names
10027 and STT_ARM_TFUNC is considered to a function type. */
10030 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
10031 asection * section,
10032 asymbol ** symbols,
10034 const char ** filename_ptr,
10035 const char ** functionname_ptr)
10037 const char * filename = NULL;
10038 asymbol * func = NULL;
10039 bfd_vma low_func = 0;
10042 for (p = symbols; *p != NULL; p++)
10044 elf_symbol_type *q;
10046 q = (elf_symbol_type *) *p;
10048 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
10053 filename = bfd_asymbol_name (&q->symbol);
10056 case STT_ARM_TFUNC:
10058 /* Skip mapping symbols. */
10059 if ((q->symbol.flags & BSF_LOCAL)
10060 && bfd_is_arm_special_symbol_name (q->symbol.name,
10061 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
10063 /* Fall through. */
10064 if (bfd_get_section (&q->symbol) == section
10065 && q->symbol.value >= low_func
10066 && q->symbol.value <= offset)
10068 func = (asymbol *) q;
10069 low_func = q->symbol.value;
10079 *filename_ptr = filename;
10080 if (functionname_ptr)
10081 *functionname_ptr = bfd_asymbol_name (func);
10087 /* Find the nearest line to a particular section and offset, for error
10088 reporting. This code is a duplicate of the code in elf.c, except
10089 that it uses arm_elf_find_function. */
10092 elf32_arm_find_nearest_line (bfd * abfd,
10093 asection * section,
10094 asymbol ** symbols,
10096 const char ** filename_ptr,
10097 const char ** functionname_ptr,
10098 unsigned int * line_ptr)
10100 bfd_boolean found = FALSE;
10102 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
10104 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
10105 filename_ptr, functionname_ptr,
10107 & elf_tdata (abfd)->dwarf2_find_line_info))
10109 if (!*functionname_ptr)
10110 arm_elf_find_function (abfd, section, symbols, offset,
10111 *filename_ptr ? NULL : filename_ptr,
10117 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
10118 & found, filename_ptr,
10119 functionname_ptr, line_ptr,
10120 & elf_tdata (abfd)->line_info))
10123 if (found && (*functionname_ptr || *line_ptr))
10126 if (symbols == NULL)
10129 if (! arm_elf_find_function (abfd, section, symbols, offset,
10130 filename_ptr, functionname_ptr))
10138 elf32_arm_find_inliner_info (bfd * abfd,
10139 const char ** filename_ptr,
10140 const char ** functionname_ptr,
10141 unsigned int * line_ptr)
10144 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
10145 functionname_ptr, line_ptr,
10146 & elf_tdata (abfd)->dwarf2_find_line_info);
10150 /* Adjust a symbol defined by a dynamic object and referenced by a
10151 regular object. The current definition is in some section of the
10152 dynamic object, but we're not including those sections. We have to
10153 change the definition to something the rest of the link can
10157 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
10158 struct elf_link_hash_entry * h)
10162 struct elf32_arm_link_hash_entry * eh;
10163 struct elf32_arm_link_hash_table *globals;
10165 globals = elf32_arm_hash_table (info);
10166 dynobj = elf_hash_table (info)->dynobj;
10168 /* Make sure we know what is going on here. */
10169 BFD_ASSERT (dynobj != NULL
10171 || h->u.weakdef != NULL
10174 && !h->def_regular)));
10176 eh = (struct elf32_arm_link_hash_entry *) h;
10178 /* If this is a function, put it in the procedure linkage table. We
10179 will fill in the contents of the procedure linkage table later,
10180 when we know the address of the .got section. */
10181 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
10184 if (h->plt.refcount <= 0
10185 || SYMBOL_CALLS_LOCAL (info, h)
10186 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
10187 && h->root.type == bfd_link_hash_undefweak))
10189 /* This case can occur if we saw a PLT32 reloc in an input
10190 file, but the symbol was never referred to by a dynamic
10191 object, or if all references were garbage collected. In
10192 such a case, we don't actually need to build a procedure
10193 linkage table, and we can just do a PC24 reloc instead. */
10194 h->plt.offset = (bfd_vma) -1;
10195 eh->plt_thumb_refcount = 0;
10196 eh->plt_maybe_thumb_refcount = 0;
10204 /* It's possible that we incorrectly decided a .plt reloc was
10205 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10206 in check_relocs. We can't decide accurately between function
10207 and non-function syms in check-relocs; Objects loaded later in
10208 the link may change h->type. So fix it now. */
10209 h->plt.offset = (bfd_vma) -1;
10210 eh->plt_thumb_refcount = 0;
10211 eh->plt_maybe_thumb_refcount = 0;
10214 /* If this is a weak symbol, and there is a real definition, the
10215 processor independent code will have arranged for us to see the
10216 real definition first, and we can just use the same value. */
10217 if (h->u.weakdef != NULL)
10219 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
10220 || h->u.weakdef->root.type == bfd_link_hash_defweak);
10221 h->root.u.def.section = h->u.weakdef->root.u.def.section;
10222 h->root.u.def.value = h->u.weakdef->root.u.def.value;
10226 /* If there are no non-GOT references, we do not need a copy
10228 if (!h->non_got_ref)
10231 /* This is a reference to a symbol defined by a dynamic object which
10232 is not a function. */
10234 /* If we are creating a shared library, we must presume that the
10235 only references to the symbol are via the global offset table.
10236 For such cases we need not do anything here; the relocations will
10237 be handled correctly by relocate_section. Relocatable executables
10238 can reference data in shared objects directly, so we don't need to
10239 do anything here. */
10240 if (info->shared || globals->root.is_relocatable_executable)
10245 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
10246 h->root.root.string);
10250 /* We must allocate the symbol in our .dynbss section, which will
10251 become part of the .bss section of the executable. There will be
10252 an entry for this symbol in the .dynsym section. The dynamic
10253 object will contain position independent code, so all references
10254 from the dynamic object to this symbol will go through the global
10255 offset table. The dynamic linker will use the .dynsym entry to
10256 determine the address it must put in the global offset table, so
10257 both the dynamic object and the regular object will refer to the
10258 same memory location for the variable. */
10259 s = bfd_get_section_by_name (dynobj, ".dynbss");
10260 BFD_ASSERT (s != NULL);
10262 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10263 copy the initial value out of the dynamic object and into the
10264 runtime process image. We need to remember the offset into the
10265 .rel(a).bss section we are going to use. */
10266 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
10270 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
10271 BFD_ASSERT (srel != NULL);
10272 srel->size += RELOC_SIZE (globals);
10276 return _bfd_elf_adjust_dynamic_copy (h, s);
10279 /* Allocate space in .plt, .got and associated reloc sections for
10283 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
10285 struct bfd_link_info *info;
10286 struct elf32_arm_link_hash_table *htab;
10287 struct elf32_arm_link_hash_entry *eh;
10288 struct elf32_arm_relocs_copied *p;
10289 bfd_signed_vma thumb_refs;
10291 eh = (struct elf32_arm_link_hash_entry *) h;
10293 if (h->root.type == bfd_link_hash_indirect)
10296 if (h->root.type == bfd_link_hash_warning)
10297 /* When warning symbols are created, they **replace** the "real"
10298 entry in the hash table, thus we never get to see the real
10299 symbol in a hash traversal. So look at it now. */
10300 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10302 info = (struct bfd_link_info *) inf;
10303 htab = elf32_arm_hash_table (info);
10305 if (htab->root.dynamic_sections_created
10306 && h->plt.refcount > 0)
10308 /* Make sure this symbol is output as a dynamic symbol.
10309 Undefined weak syms won't yet be marked as dynamic. */
10310 if (h->dynindx == -1
10311 && !h->forced_local)
10313 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10318 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
10320 asection *s = htab->splt;
10322 /* If this is the first .plt entry, make room for the special
10325 s->size += htab->plt_header_size;
10327 h->plt.offset = s->size;
10329 /* If we will insert a Thumb trampoline before this PLT, leave room
10331 thumb_refs = eh->plt_thumb_refcount;
10332 if (!htab->use_blx)
10333 thumb_refs += eh->plt_maybe_thumb_refcount;
10335 if (thumb_refs > 0)
10337 h->plt.offset += PLT_THUMB_STUB_SIZE;
10338 s->size += PLT_THUMB_STUB_SIZE;
10341 /* If this symbol is not defined in a regular file, and we are
10342 not generating a shared library, then set the symbol to this
10343 location in the .plt. This is required to make function
10344 pointers compare as equal between the normal executable and
10345 the shared library. */
10347 && !h->def_regular)
10349 h->root.u.def.section = s;
10350 h->root.u.def.value = h->plt.offset;
10352 /* Make sure the function is not marked as Thumb, in case
10353 it is the target of an ABS32 relocation, which will
10354 point to the PLT entry. */
10355 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
10356 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10359 /* Make room for this entry. */
10360 s->size += htab->plt_entry_size;
10362 if (!htab->symbian_p)
10364 /* We also need to make an entry in the .got.plt section, which
10365 will be placed in the .got section by the linker script. */
10366 eh->plt_got_offset = htab->sgotplt->size;
10367 htab->sgotplt->size += 4;
10370 /* We also need to make an entry in the .rel(a).plt section. */
10371 htab->srelplt->size += RELOC_SIZE (htab);
10373 /* VxWorks executables have a second set of relocations for
10374 each PLT entry. They go in a separate relocation section,
10375 which is processed by the kernel loader. */
10376 if (htab->vxworks_p && !info->shared)
10378 /* There is a relocation for the initial PLT entry:
10379 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10380 if (h->plt.offset == htab->plt_header_size)
10381 htab->srelplt2->size += RELOC_SIZE (htab);
10383 /* There are two extra relocations for each subsequent
10384 PLT entry: an R_ARM_32 relocation for the GOT entry,
10385 and an R_ARM_32 relocation for the PLT entry. */
10386 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
10391 h->plt.offset = (bfd_vma) -1;
10397 h->plt.offset = (bfd_vma) -1;
10401 if (h->got.refcount > 0)
10405 int tls_type = elf32_arm_hash_entry (h)->tls_type;
10408 /* Make sure this symbol is output as a dynamic symbol.
10409 Undefined weak syms won't yet be marked as dynamic. */
10410 if (h->dynindx == -1
10411 && !h->forced_local)
10413 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10417 if (!htab->symbian_p)
10420 h->got.offset = s->size;
10422 if (tls_type == GOT_UNKNOWN)
10425 if (tls_type == GOT_NORMAL)
10426 /* Non-TLS symbols need one GOT slot. */
10430 if (tls_type & GOT_TLS_GD)
10431 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10433 if (tls_type & GOT_TLS_IE)
10434 /* R_ARM_TLS_IE32 needs one GOT slot. */
10438 dyn = htab->root.dynamic_sections_created;
10441 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
10443 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10446 if (tls_type != GOT_NORMAL
10447 && (info->shared || indx != 0)
10448 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10449 || h->root.type != bfd_link_hash_undefweak))
10451 if (tls_type & GOT_TLS_IE)
10452 htab->srelgot->size += RELOC_SIZE (htab);
10454 if (tls_type & GOT_TLS_GD)
10455 htab->srelgot->size += RELOC_SIZE (htab);
10457 if ((tls_type & GOT_TLS_GD) && indx != 0)
10458 htab->srelgot->size += RELOC_SIZE (htab);
10460 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10461 || h->root.type != bfd_link_hash_undefweak)
10463 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
10464 htab->srelgot->size += RELOC_SIZE (htab);
10468 h->got.offset = (bfd_vma) -1;
10470 /* Allocate stubs for exported Thumb functions on v4t. */
10471 if (!htab->use_blx && h->dynindx != -1
10473 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
10474 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
10476 struct elf_link_hash_entry * th;
10477 struct bfd_link_hash_entry * bh;
10478 struct elf_link_hash_entry * myh;
10482 /* Create a new symbol to regist the real location of the function. */
10483 s = h->root.u.def.section;
10484 sprintf (name, "__real_%s", h->root.root.string);
10485 _bfd_generic_link_add_one_symbol (info, s->owner,
10486 name, BSF_GLOBAL, s,
10487 h->root.u.def.value,
10488 NULL, TRUE, FALSE, &bh);
10490 myh = (struct elf_link_hash_entry *) bh;
10491 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
10492 myh->forced_local = 1;
10493 eh->export_glue = myh;
10494 th = record_arm_to_thumb_glue (info, h);
10495 /* Point the symbol at the stub. */
10496 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10497 h->root.u.def.section = th->root.u.def.section;
10498 h->root.u.def.value = th->root.u.def.value & ~1;
10501 if (eh->relocs_copied == NULL)
10504 /* In the shared -Bsymbolic case, discard space allocated for
10505 dynamic pc-relative relocs against symbols which turn out to be
10506 defined in regular objects. For the normal shared case, discard
10507 space for pc-relative relocs that have become local due to symbol
10508 visibility changes. */
10510 if (info->shared || htab->root.is_relocatable_executable)
10512 /* The only relocs that use pc_count are R_ARM_REL32 and
10513 R_ARM_REL32_NOI, which will appear on something like
10514 ".long foo - .". We want calls to protected symbols to resolve
10515 directly to the function rather than going via the plt. If people
10516 want function pointer comparisons to work as expected then they
10517 should avoid writing assembly like ".long foo - .". */
10518 if (SYMBOL_CALLS_LOCAL (info, h))
10520 struct elf32_arm_relocs_copied **pp;
10522 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10524 p->count -= p->pc_count;
10533 if (elf32_arm_hash_table (info)->vxworks_p)
10535 struct elf32_arm_relocs_copied **pp;
10537 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10539 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
10546 /* Also discard relocs on undefined weak syms with non-default
10548 if (eh->relocs_copied != NULL
10549 && h->root.type == bfd_link_hash_undefweak)
10551 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
10552 eh->relocs_copied = NULL;
10554 /* Make sure undefined weak symbols are output as a dynamic
10556 else if (h->dynindx == -1
10557 && !h->forced_local)
10559 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10564 else if (htab->root.is_relocatable_executable && h->dynindx == -1
10565 && h->root.type == bfd_link_hash_new)
10567 /* Output absolute symbols so that we can create relocations
10568 against them. For normal symbols we output a relocation
10569 against the section that contains them. */
10570 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10577 /* For the non-shared case, discard space for relocs against
10578 symbols which turn out to need copy relocs or are not
10581 if (!h->non_got_ref
10582 && ((h->def_dynamic
10583 && !h->def_regular)
10584 || (htab->root.dynamic_sections_created
10585 && (h->root.type == bfd_link_hash_undefweak
10586 || h->root.type == bfd_link_hash_undefined))))
10588 /* Make sure this symbol is output as a dynamic symbol.
10589 Undefined weak syms won't yet be marked as dynamic. */
10590 if (h->dynindx == -1
10591 && !h->forced_local)
10593 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10597 /* If that succeeded, we know we'll be keeping all the
10599 if (h->dynindx != -1)
10603 eh->relocs_copied = NULL;
10608 /* Finally, allocate space. */
10609 for (p = eh->relocs_copied; p != NULL; p = p->next)
10611 asection *sreloc = elf_section_data (p->section)->sreloc;
10612 sreloc->size += p->count * RELOC_SIZE (htab);
10618 /* Find any dynamic relocs that apply to read-only sections. */
10621 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
10623 struct elf32_arm_link_hash_entry * eh;
10624 struct elf32_arm_relocs_copied * p;
10626 if (h->root.type == bfd_link_hash_warning)
10627 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10629 eh = (struct elf32_arm_link_hash_entry *) h;
10630 for (p = eh->relocs_copied; p != NULL; p = p->next)
10632 asection *s = p->section;
10634 if (s != NULL && (s->flags & SEC_READONLY) != 0)
10636 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10638 info->flags |= DF_TEXTREL;
10640 /* Not an error, just cut short the traversal. */
10648 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
10651 struct elf32_arm_link_hash_table *globals;
10653 globals = elf32_arm_hash_table (info);
10654 globals->byteswap_code = byteswap_code;
10657 /* Set the sizes of the dynamic sections. */
10660 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10661 struct bfd_link_info * info)
10666 bfd_boolean relocs;
10668 struct elf32_arm_link_hash_table *htab;
10670 htab = elf32_arm_hash_table (info);
10671 dynobj = elf_hash_table (info)->dynobj;
10672 BFD_ASSERT (dynobj != NULL);
10673 check_use_blx (htab);
10675 if (elf_hash_table (info)->dynamic_sections_created)
10677 /* Set the contents of the .interp section to the interpreter. */
10678 if (info->executable)
10680 s = bfd_get_section_by_name (dynobj, ".interp");
10681 BFD_ASSERT (s != NULL);
10682 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10683 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10687 /* Set up .got offsets for local syms, and space for local dynamic
10689 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10691 bfd_signed_vma *local_got;
10692 bfd_signed_vma *end_local_got;
10693 char *local_tls_type;
10694 bfd_size_type locsymcount;
10695 Elf_Internal_Shdr *symtab_hdr;
10697 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
10699 if (! is_arm_elf (ibfd))
10702 for (s = ibfd->sections; s != NULL; s = s->next)
10704 struct elf32_arm_relocs_copied *p;
10706 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10708 if (!bfd_is_abs_section (p->section)
10709 && bfd_is_abs_section (p->section->output_section))
10711 /* Input section has been discarded, either because
10712 it is a copy of a linkonce section or due to
10713 linker script /DISCARD/, so we'll be discarding
10716 else if (is_vxworks
10717 && strcmp (p->section->output_section->name,
10720 /* Relocations in vxworks .tls_vars sections are
10721 handled specially by the loader. */
10723 else if (p->count != 0)
10725 srel = elf_section_data (p->section)->sreloc;
10726 srel->size += p->count * RELOC_SIZE (htab);
10727 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10728 info->flags |= DF_TEXTREL;
10733 local_got = elf_local_got_refcounts (ibfd);
10737 symtab_hdr = & elf_symtab_hdr (ibfd);
10738 locsymcount = symtab_hdr->sh_info;
10739 end_local_got = local_got + locsymcount;
10740 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
10742 srel = htab->srelgot;
10743 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10745 if (*local_got > 0)
10747 *local_got = s->size;
10748 if (*local_tls_type & GOT_TLS_GD)
10749 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10751 if (*local_tls_type & GOT_TLS_IE)
10753 if (*local_tls_type == GOT_NORMAL)
10756 if (info->shared || *local_tls_type == GOT_TLS_GD)
10757 srel->size += RELOC_SIZE (htab);
10760 *local_got = (bfd_vma) -1;
10764 if (htab->tls_ldm_got.refcount > 0)
10766 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10767 for R_ARM_TLS_LDM32 relocations. */
10768 htab->tls_ldm_got.offset = htab->sgot->size;
10769 htab->sgot->size += 8;
10771 htab->srelgot->size += RELOC_SIZE (htab);
10774 htab->tls_ldm_got.offset = -1;
10776 /* Allocate global sym .plt and .got entries, and space for global
10777 sym dynamic relocs. */
10778 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
10780 /* Here we rummage through the found bfds to collect glue information. */
10781 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10783 if (! is_arm_elf (ibfd))
10786 /* Initialise mapping tables for code/data. */
10787 bfd_elf32_arm_init_maps (ibfd);
10789 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10790 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10791 /* xgettext:c-format */
10792 _bfd_error_handler (_("Errors encountered processing file %s"),
10796 /* Allocate space for the glue sections now that we've sized them. */
10797 bfd_elf32_arm_allocate_interworking_sections (info);
10799 /* The check_relocs and adjust_dynamic_symbol entry points have
10800 determined the sizes of the various dynamic sections. Allocate
10801 memory for them. */
10804 for (s = dynobj->sections; s != NULL; s = s->next)
10808 if ((s->flags & SEC_LINKER_CREATED) == 0)
10811 /* It's OK to base decisions on the section name, because none
10812 of the dynobj section names depend upon the input files. */
10813 name = bfd_get_section_name (dynobj, s);
10815 if (strcmp (name, ".plt") == 0)
10817 /* Remember whether there is a PLT. */
10818 plt = s->size != 0;
10820 else if (CONST_STRNEQ (name, ".rel"))
10824 /* Remember whether there are any reloc sections other
10825 than .rel(a).plt and .rela.plt.unloaded. */
10826 if (s != htab->srelplt && s != htab->srelplt2)
10829 /* We use the reloc_count field as a counter if we need
10830 to copy relocs into the output file. */
10831 s->reloc_count = 0;
10834 else if (! CONST_STRNEQ (name, ".got")
10835 && strcmp (name, ".dynbss") != 0)
10837 /* It's not one of our sections, so don't allocate space. */
10843 /* If we don't need this section, strip it from the
10844 output file. This is mostly to handle .rel(a).bss and
10845 .rel(a).plt. We must create both sections in
10846 create_dynamic_sections, because they must be created
10847 before the linker maps input sections to output
10848 sections. The linker does that before
10849 adjust_dynamic_symbol is called, and it is that
10850 function which decides whether anything needs to go
10851 into these sections. */
10852 s->flags |= SEC_EXCLUDE;
10856 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10859 /* Allocate memory for the section contents. */
10860 s->contents = bfd_zalloc (dynobj, s->size);
10861 if (s->contents == NULL)
10865 if (elf_hash_table (info)->dynamic_sections_created)
10867 /* Add some entries to the .dynamic section. We fill in the
10868 values later, in elf32_arm_finish_dynamic_sections, but we
10869 must add the entries now so that we get the correct size for
10870 the .dynamic section. The DT_DEBUG entry is filled in by the
10871 dynamic linker and used by the debugger. */
10872 #define add_dynamic_entry(TAG, VAL) \
10873 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10875 if (info->executable)
10877 if (!add_dynamic_entry (DT_DEBUG, 0))
10883 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10884 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10885 || !add_dynamic_entry (DT_PLTREL,
10886 htab->use_rel ? DT_REL : DT_RELA)
10887 || !add_dynamic_entry (DT_JMPREL, 0))
10895 if (!add_dynamic_entry (DT_REL, 0)
10896 || !add_dynamic_entry (DT_RELSZ, 0)
10897 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10902 if (!add_dynamic_entry (DT_RELA, 0)
10903 || !add_dynamic_entry (DT_RELASZ, 0)
10904 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10909 /* If any dynamic relocs apply to a read-only section,
10910 then we need a DT_TEXTREL entry. */
10911 if ((info->flags & DF_TEXTREL) == 0)
10912 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
10915 if ((info->flags & DF_TEXTREL) != 0)
10917 if (!add_dynamic_entry (DT_TEXTREL, 0))
10920 if (htab->vxworks_p
10921 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10924 #undef add_dynamic_entry
10929 /* Finish up dynamic symbol handling. We set the contents of various
10930 dynamic sections here. */
10933 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10934 struct bfd_link_info * info,
10935 struct elf_link_hash_entry * h,
10936 Elf_Internal_Sym * sym)
10939 struct elf32_arm_link_hash_table *htab;
10940 struct elf32_arm_link_hash_entry *eh;
10942 dynobj = elf_hash_table (info)->dynobj;
10943 htab = elf32_arm_hash_table (info);
10944 eh = (struct elf32_arm_link_hash_entry *) h;
10946 if (h->plt.offset != (bfd_vma) -1)
10952 Elf_Internal_Rela rel;
10954 /* This symbol has an entry in the procedure linkage table. Set
10957 BFD_ASSERT (h->dynindx != -1);
10959 splt = bfd_get_section_by_name (dynobj, ".plt");
10960 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
10961 BFD_ASSERT (splt != NULL && srel != NULL);
10963 /* Fill in the entry in the procedure linkage table. */
10964 if (htab->symbian_p)
10966 put_arm_insn (htab, output_bfd,
10967 elf32_arm_symbian_plt_entry[0],
10968 splt->contents + h->plt.offset);
10969 bfd_put_32 (output_bfd,
10970 elf32_arm_symbian_plt_entry[1],
10971 splt->contents + h->plt.offset + 4);
10973 /* Fill in the entry in the .rel.plt section. */
10974 rel.r_offset = (splt->output_section->vma
10975 + splt->output_offset
10976 + h->plt.offset + 4);
10977 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10979 /* Get the index in the procedure linkage table which
10980 corresponds to this symbol. This is the index of this symbol
10981 in all the symbols for which we are making plt entries. The
10982 first entry in the procedure linkage table is reserved. */
10983 plt_index = ((h->plt.offset - htab->plt_header_size)
10984 / htab->plt_entry_size);
10988 bfd_vma got_offset, got_address, plt_address;
10989 bfd_vma got_displacement;
10993 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10994 BFD_ASSERT (sgot != NULL);
10996 /* Get the offset into the .got.plt table of the entry that
10997 corresponds to this function. */
10998 got_offset = eh->plt_got_offset;
11000 /* Get the index in the procedure linkage table which
11001 corresponds to this symbol. This is the index of this symbol
11002 in all the symbols for which we are making plt entries. The
11003 first three entries in .got.plt are reserved; after that
11004 symbols appear in the same order as in .plt. */
11005 plt_index = (got_offset - 12) / 4;
11007 /* Calculate the address of the GOT entry. */
11008 got_address = (sgot->output_section->vma
11009 + sgot->output_offset
11012 /* ...and the address of the PLT entry. */
11013 plt_address = (splt->output_section->vma
11014 + splt->output_offset
11017 ptr = htab->splt->contents + h->plt.offset;
11018 if (htab->vxworks_p && info->shared)
11023 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
11025 val = elf32_arm_vxworks_shared_plt_entry[i];
11027 val |= got_address - sgot->output_section->vma;
11029 val |= plt_index * RELOC_SIZE (htab);
11030 if (i == 2 || i == 5)
11031 bfd_put_32 (output_bfd, val, ptr);
11033 put_arm_insn (htab, output_bfd, val, ptr);
11036 else if (htab->vxworks_p)
11041 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
11043 val = elf32_arm_vxworks_exec_plt_entry[i];
11045 val |= got_address;
11047 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
11049 val |= plt_index * RELOC_SIZE (htab);
11050 if (i == 2 || i == 5)
11051 bfd_put_32 (output_bfd, val, ptr);
11053 put_arm_insn (htab, output_bfd, val, ptr);
11056 loc = (htab->srelplt2->contents
11057 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
11059 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
11060 referencing the GOT for this PLT entry. */
11061 rel.r_offset = plt_address + 8;
11062 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11063 rel.r_addend = got_offset;
11064 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11065 loc += RELOC_SIZE (htab);
11067 /* Create the R_ARM_ABS32 relocation referencing the
11068 beginning of the PLT for this GOT entry. */
11069 rel.r_offset = got_address;
11070 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11072 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11076 bfd_signed_vma thumb_refs;
11077 /* Calculate the displacement between the PLT slot and the
11078 entry in the GOT. The eight-byte offset accounts for the
11079 value produced by adding to pc in the first instruction
11080 of the PLT stub. */
11081 got_displacement = got_address - (plt_address + 8);
11083 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
11085 thumb_refs = eh->plt_thumb_refcount;
11086 if (!htab->use_blx)
11087 thumb_refs += eh->plt_maybe_thumb_refcount;
11089 if (thumb_refs > 0)
11091 put_thumb_insn (htab, output_bfd,
11092 elf32_arm_plt_thumb_stub[0], ptr - 4);
11093 put_thumb_insn (htab, output_bfd,
11094 elf32_arm_plt_thumb_stub[1], ptr - 2);
11097 put_arm_insn (htab, output_bfd,
11098 elf32_arm_plt_entry[0]
11099 | ((got_displacement & 0x0ff00000) >> 20),
11101 put_arm_insn (htab, output_bfd,
11102 elf32_arm_plt_entry[1]
11103 | ((got_displacement & 0x000ff000) >> 12),
11105 put_arm_insn (htab, output_bfd,
11106 elf32_arm_plt_entry[2]
11107 | (got_displacement & 0x00000fff),
11109 #ifdef FOUR_WORD_PLT
11110 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
11114 /* Fill in the entry in the global offset table. */
11115 bfd_put_32 (output_bfd,
11116 (splt->output_section->vma
11117 + splt->output_offset),
11118 sgot->contents + got_offset);
11120 /* Fill in the entry in the .rel(a).plt section. */
11122 rel.r_offset = got_address;
11123 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
11126 loc = srel->contents + plt_index * RELOC_SIZE (htab);
11127 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11129 if (!h->def_regular)
11131 /* Mark the symbol as undefined, rather than as defined in
11132 the .plt section. Leave the value alone. */
11133 sym->st_shndx = SHN_UNDEF;
11134 /* If the symbol is weak, we do need to clear the value.
11135 Otherwise, the PLT entry would provide a definition for
11136 the symbol even if the symbol wasn't defined anywhere,
11137 and so the symbol would never be NULL. */
11138 if (!h->ref_regular_nonweak)
11143 if (h->got.offset != (bfd_vma) -1
11144 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
11145 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
11149 Elf_Internal_Rela rel;
11153 /* This symbol has an entry in the global offset table. Set it
11155 sgot = bfd_get_section_by_name (dynobj, ".got");
11156 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
11157 BFD_ASSERT (sgot != NULL && srel != NULL);
11159 offset = (h->got.offset & ~(bfd_vma) 1);
11161 rel.r_offset = (sgot->output_section->vma
11162 + sgot->output_offset
11165 /* If this is a static link, or it is a -Bsymbolic link and the
11166 symbol is defined locally or was forced to be local because
11167 of a version file, we just want to emit a RELATIVE reloc.
11168 The entry in the global offset table will already have been
11169 initialized in the relocate_section function. */
11171 && SYMBOL_REFERENCES_LOCAL (info, h))
11173 BFD_ASSERT ((h->got.offset & 1) != 0);
11174 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
11175 if (!htab->use_rel)
11177 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
11178 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11183 BFD_ASSERT ((h->got.offset & 1) == 0);
11184 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11185 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11188 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
11189 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11195 Elf_Internal_Rela rel;
11198 /* This symbol needs a copy reloc. Set it up. */
11199 BFD_ASSERT (h->dynindx != -1
11200 && (h->root.type == bfd_link_hash_defined
11201 || h->root.type == bfd_link_hash_defweak));
11203 s = bfd_get_section_by_name (h->root.u.def.section->owner,
11204 RELOC_SECTION (htab, ".bss"));
11205 BFD_ASSERT (s != NULL);
11208 rel.r_offset = (h->root.u.def.value
11209 + h->root.u.def.section->output_section->vma
11210 + h->root.u.def.section->output_offset);
11211 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
11212 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
11213 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11216 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11217 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11218 to the ".got" section. */
11219 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
11220 || (!htab->vxworks_p && h == htab->root.hgot))
11221 sym->st_shndx = SHN_ABS;
11226 /* Finish up the dynamic sections. */
11229 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
11235 dynobj = elf_hash_table (info)->dynobj;
11237 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
11238 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
11239 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11241 if (elf_hash_table (info)->dynamic_sections_created)
11244 Elf32_External_Dyn *dyncon, *dynconend;
11245 struct elf32_arm_link_hash_table *htab;
11247 htab = elf32_arm_hash_table (info);
11248 splt = bfd_get_section_by_name (dynobj, ".plt");
11249 BFD_ASSERT (splt != NULL && sdyn != NULL);
11251 dyncon = (Elf32_External_Dyn *) sdyn->contents;
11252 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
11254 for (; dyncon < dynconend; dyncon++)
11256 Elf_Internal_Dyn dyn;
11260 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
11267 if (htab->vxworks_p
11268 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
11269 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11274 goto get_vma_if_bpabi;
11277 goto get_vma_if_bpabi;
11280 goto get_vma_if_bpabi;
11282 name = ".gnu.version";
11283 goto get_vma_if_bpabi;
11285 name = ".gnu.version_d";
11286 goto get_vma_if_bpabi;
11288 name = ".gnu.version_r";
11289 goto get_vma_if_bpabi;
11295 name = RELOC_SECTION (htab, ".plt");
11297 s = bfd_get_section_by_name (output_bfd, name);
11298 BFD_ASSERT (s != NULL);
11299 if (!htab->symbian_p)
11300 dyn.d_un.d_ptr = s->vma;
11302 /* In the BPABI, tags in the PT_DYNAMIC section point
11303 at the file offset, not the memory address, for the
11304 convenience of the post linker. */
11305 dyn.d_un.d_ptr = s->filepos;
11306 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11310 if (htab->symbian_p)
11315 s = bfd_get_section_by_name (output_bfd,
11316 RELOC_SECTION (htab, ".plt"));
11317 BFD_ASSERT (s != NULL);
11318 dyn.d_un.d_val = s->size;
11319 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11324 if (!htab->symbian_p)
11326 /* My reading of the SVR4 ABI indicates that the
11327 procedure linkage table relocs (DT_JMPREL) should be
11328 included in the overall relocs (DT_REL). This is
11329 what Solaris does. However, UnixWare can not handle
11330 that case. Therefore, we override the DT_RELSZ entry
11331 here to make it not include the JMPREL relocs. Since
11332 the linker script arranges for .rel(a).plt to follow all
11333 other relocation sections, we don't have to worry
11334 about changing the DT_REL entry. */
11335 s = bfd_get_section_by_name (output_bfd,
11336 RELOC_SECTION (htab, ".plt"));
11338 dyn.d_un.d_val -= s->size;
11339 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11342 /* Fall through. */
11346 /* In the BPABI, the DT_REL tag must point at the file
11347 offset, not the VMA, of the first relocation
11348 section. So, we use code similar to that in
11349 elflink.c, but do not check for SHF_ALLOC on the
11350 relcoation section, since relocations sections are
11351 never allocated under the BPABI. The comments above
11352 about Unixware notwithstanding, we include all of the
11353 relocations here. */
11354 if (htab->symbian_p)
11357 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
11358 ? SHT_REL : SHT_RELA);
11359 dyn.d_un.d_val = 0;
11360 for (i = 1; i < elf_numsections (output_bfd); i++)
11362 Elf_Internal_Shdr *hdr
11363 = elf_elfsections (output_bfd)[i];
11364 if (hdr->sh_type == type)
11366 if (dyn.d_tag == DT_RELSZ
11367 || dyn.d_tag == DT_RELASZ)
11368 dyn.d_un.d_val += hdr->sh_size;
11369 else if ((ufile_ptr) hdr->sh_offset
11370 <= dyn.d_un.d_val - 1)
11371 dyn.d_un.d_val = hdr->sh_offset;
11374 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11378 /* Set the bottom bit of DT_INIT/FINI if the
11379 corresponding function is Thumb. */
11381 name = info->init_function;
11384 name = info->fini_function;
11386 /* If it wasn't set by elf_bfd_final_link
11387 then there is nothing to adjust. */
11388 if (dyn.d_un.d_val != 0)
11390 struct elf_link_hash_entry * eh;
11392 eh = elf_link_hash_lookup (elf_hash_table (info), name,
11393 FALSE, FALSE, TRUE);
11395 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
11397 dyn.d_un.d_val |= 1;
11398 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11405 /* Fill in the first entry in the procedure linkage table. */
11406 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
11408 const bfd_vma *plt0_entry;
11409 bfd_vma got_address, plt_address, got_displacement;
11411 /* Calculate the addresses of the GOT and PLT. */
11412 got_address = sgot->output_section->vma + sgot->output_offset;
11413 plt_address = splt->output_section->vma + splt->output_offset;
11415 if (htab->vxworks_p)
11417 /* The VxWorks GOT is relocated by the dynamic linker.
11418 Therefore, we must emit relocations rather than simply
11419 computing the values now. */
11420 Elf_Internal_Rela rel;
11422 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
11423 put_arm_insn (htab, output_bfd, plt0_entry[0],
11424 splt->contents + 0);
11425 put_arm_insn (htab, output_bfd, plt0_entry[1],
11426 splt->contents + 4);
11427 put_arm_insn (htab, output_bfd, plt0_entry[2],
11428 splt->contents + 8);
11429 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
11431 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
11432 rel.r_offset = plt_address + 12;
11433 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11435 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
11436 htab->srelplt2->contents);
11440 got_displacement = got_address - (plt_address + 16);
11442 plt0_entry = elf32_arm_plt0_entry;
11443 put_arm_insn (htab, output_bfd, plt0_entry[0],
11444 splt->contents + 0);
11445 put_arm_insn (htab, output_bfd, plt0_entry[1],
11446 splt->contents + 4);
11447 put_arm_insn (htab, output_bfd, plt0_entry[2],
11448 splt->contents + 8);
11449 put_arm_insn (htab, output_bfd, plt0_entry[3],
11450 splt->contents + 12);
11452 #ifdef FOUR_WORD_PLT
11453 /* The displacement value goes in the otherwise-unused
11454 last word of the second entry. */
11455 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
11457 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
11462 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11463 really seem like the right value. */
11464 if (splt->output_section->owner == output_bfd)
11465 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
11467 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
11469 /* Correct the .rel(a).plt.unloaded relocations. They will have
11470 incorrect symbol indexes. */
11474 num_plts = ((htab->splt->size - htab->plt_header_size)
11475 / htab->plt_entry_size);
11476 p = htab->srelplt2->contents + RELOC_SIZE (htab);
11478 for (; num_plts; num_plts--)
11480 Elf_Internal_Rela rel;
11482 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11483 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11484 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11485 p += RELOC_SIZE (htab);
11487 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11488 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11489 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11490 p += RELOC_SIZE (htab);
11495 /* Fill in the first three entries in the global offset table. */
11498 if (sgot->size > 0)
11501 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
11503 bfd_put_32 (output_bfd,
11504 sdyn->output_section->vma + sdyn->output_offset,
11506 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
11507 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
11510 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
11517 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
11519 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
11520 struct elf32_arm_link_hash_table *globals;
11522 i_ehdrp = elf_elfheader (abfd);
11524 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
11525 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
11527 i_ehdrp->e_ident[EI_OSABI] = 0;
11528 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
11532 globals = elf32_arm_hash_table (link_info);
11533 if (globals->byteswap_code)
11534 i_ehdrp->e_flags |= EF_ARM_BE8;
11538 static enum elf_reloc_type_class
11539 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
11541 switch ((int) ELF32_R_TYPE (rela->r_info))
11543 case R_ARM_RELATIVE:
11544 return reloc_class_relative;
11545 case R_ARM_JUMP_SLOT:
11546 return reloc_class_plt;
11548 return reloc_class_copy;
11550 return reloc_class_normal;
11554 /* Set the right machine number for an Arm ELF file. */
11557 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
11559 if (hdr->sh_type == SHT_NOTE)
11560 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
11566 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
11568 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
11571 /* Return TRUE if this is an unwinding table entry. */
11574 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
11576 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
11577 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
11581 /* Set the type and flags for an ARM section. We do this by
11582 the section name, which is a hack, but ought to work. */
11585 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
11589 name = bfd_get_section_name (abfd, sec);
11591 if (is_arm_elf_unwind_section_name (abfd, name))
11593 hdr->sh_type = SHT_ARM_EXIDX;
11594 hdr->sh_flags |= SHF_LINK_ORDER;
11599 /* Handle an ARM specific section when reading an object file. This is
11600 called when bfd_section_from_shdr finds a section with an unknown
11604 elf32_arm_section_from_shdr (bfd *abfd,
11605 Elf_Internal_Shdr * hdr,
11609 /* There ought to be a place to keep ELF backend specific flags, but
11610 at the moment there isn't one. We just keep track of the
11611 sections by their name, instead. Fortunately, the ABI gives
11612 names for all the ARM specific sections, so we will probably get
11614 switch (hdr->sh_type)
11616 case SHT_ARM_EXIDX:
11617 case SHT_ARM_PREEMPTMAP:
11618 case SHT_ARM_ATTRIBUTES:
11625 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
11631 /* A structure used to record a list of sections, independently
11632 of the next and prev fields in the asection structure. */
11633 typedef struct section_list
11636 struct section_list * next;
11637 struct section_list * prev;
11641 /* Unfortunately we need to keep a list of sections for which
11642 an _arm_elf_section_data structure has been allocated. This
11643 is because it is possible for functions like elf32_arm_write_section
11644 to be called on a section which has had an elf_data_structure
11645 allocated for it (and so the used_by_bfd field is valid) but
11646 for which the ARM extended version of this structure - the
11647 _arm_elf_section_data structure - has not been allocated. */
11648 static section_list * sections_with_arm_elf_section_data = NULL;
11651 record_section_with_arm_elf_section_data (asection * sec)
11653 struct section_list * entry;
11655 entry = bfd_malloc (sizeof (* entry));
11659 entry->next = sections_with_arm_elf_section_data;
11660 entry->prev = NULL;
11661 if (entry->next != NULL)
11662 entry->next->prev = entry;
11663 sections_with_arm_elf_section_data = entry;
11666 static struct section_list *
11667 find_arm_elf_section_entry (asection * sec)
11669 struct section_list * entry;
11670 static struct section_list * last_entry = NULL;
11672 /* This is a short cut for the typical case where the sections are added
11673 to the sections_with_arm_elf_section_data list in forward order and
11674 then looked up here in backwards order. This makes a real difference
11675 to the ld-srec/sec64k.exp linker test. */
11676 entry = sections_with_arm_elf_section_data;
11677 if (last_entry != NULL)
11679 if (last_entry->sec == sec)
11680 entry = last_entry;
11681 else if (last_entry->next != NULL
11682 && last_entry->next->sec == sec)
11683 entry = last_entry->next;
11686 for (; entry; entry = entry->next)
11687 if (entry->sec == sec)
11691 /* Record the entry prior to this one - it is the entry we are most
11692 likely to want to locate next time. Also this way if we have been
11693 called from unrecord_section_with_arm_elf_section_data() we will not
11694 be caching a pointer that is about to be freed. */
11695 last_entry = entry->prev;
11700 static _arm_elf_section_data *
11701 get_arm_elf_section_data (asection * sec)
11703 struct section_list * entry;
11705 entry = find_arm_elf_section_entry (sec);
11708 return elf32_arm_section_data (entry->sec);
11714 unrecord_section_with_arm_elf_section_data (asection * sec)
11716 struct section_list * entry;
11718 entry = find_arm_elf_section_entry (sec);
11722 if (entry->prev != NULL)
11723 entry->prev->next = entry->next;
11724 if (entry->next != NULL)
11725 entry->next->prev = entry->prev;
11726 if (entry == sections_with_arm_elf_section_data)
11727 sections_with_arm_elf_section_data = entry->next;
11736 struct bfd_link_info *info;
11739 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11740 asection *, struct elf_link_hash_entry *);
11741 } output_arch_syminfo;
11743 enum map_symbol_type
11751 /* Output a single mapping symbol. */
11754 elf32_arm_output_map_sym (output_arch_syminfo *osi,
11755 enum map_symbol_type type,
11758 static const char *names[3] = {"$a", "$t", "$d"};
11759 struct elf32_arm_link_hash_table *htab;
11760 Elf_Internal_Sym sym;
11762 htab = elf32_arm_hash_table (osi->info);
11763 sym.st_value = osi->sec->output_section->vma
11764 + osi->sec->output_offset
11768 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
11769 sym.st_shndx = osi->sec_shndx;
11770 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
11776 /* Output mapping symbols for PLT entries associated with H. */
11779 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11781 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11782 struct elf32_arm_link_hash_table *htab;
11783 struct elf32_arm_link_hash_entry *eh;
11786 htab = elf32_arm_hash_table (osi->info);
11788 if (h->root.type == bfd_link_hash_indirect)
11791 if (h->root.type == bfd_link_hash_warning)
11792 /* When warning symbols are created, they **replace** the "real"
11793 entry in the hash table, thus we never get to see the real
11794 symbol in a hash traversal. So look at it now. */
11795 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11797 if (h->plt.offset == (bfd_vma) -1)
11800 eh = (struct elf32_arm_link_hash_entry *) h;
11801 addr = h->plt.offset;
11802 if (htab->symbian_p)
11804 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11806 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11809 else if (htab->vxworks_p)
11811 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11813 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11815 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
11817 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
11822 bfd_signed_vma thumb_refs;
11824 thumb_refs = eh->plt_thumb_refcount;
11825 if (!htab->use_blx)
11826 thumb_refs += eh->plt_maybe_thumb_refcount;
11828 if (thumb_refs > 0)
11830 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
11833 #ifdef FOUR_WORD_PLT
11834 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11836 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11839 /* A three-word PLT with no Thumb thunk contains only Arm code,
11840 so only need to output a mapping symbol for the first PLT entry and
11841 entries with thumb thunks. */
11842 if (thumb_refs > 0 || addr == 20)
11844 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11853 /* Output a single local symbol for a generated stub. */
11856 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11857 bfd_vma offset, bfd_vma size)
11859 struct elf32_arm_link_hash_table *htab;
11860 Elf_Internal_Sym sym;
11862 htab = elf32_arm_hash_table (osi->info);
11863 sym.st_value = osi->sec->output_section->vma
11864 + osi->sec->output_offset
11866 sym.st_size = size;
11868 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11869 sym.st_shndx = osi->sec_shndx;
11870 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11876 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
11879 struct elf32_arm_stub_hash_entry *stub_entry;
11880 struct bfd_link_info *info;
11881 struct elf32_arm_link_hash_table *htab;
11882 asection *stub_sec;
11885 output_arch_syminfo *osi;
11886 const insn_sequence *template;
11887 enum stub_insn_type prev_type;
11890 enum map_symbol_type sym_type;
11892 /* Massage our args to the form they really have. */
11893 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11894 osi = (output_arch_syminfo *) in_arg;
11898 htab = elf32_arm_hash_table (info);
11899 stub_sec = stub_entry->stub_sec;
11901 /* Ensure this stub is attached to the current section being
11903 if (stub_sec != osi->sec)
11906 addr = (bfd_vma) stub_entry->stub_offset;
11907 stub_name = stub_entry->output_name;
11909 template = stub_entry->stub_template;
11910 switch (template[0].type)
11913 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
11917 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
11918 stub_entry->stub_size))
11926 prev_type = DATA_TYPE;
11928 for (i = 0; i < stub_entry->stub_template_size; i++)
11930 switch (template[i].type)
11933 sym_type = ARM_MAP_ARM;
11937 sym_type = ARM_MAP_THUMB;
11941 sym_type = ARM_MAP_DATA;
11949 if (template[i].type != prev_type)
11951 prev_type = template[i].type;
11952 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
11956 switch (template[i].type)
11979 /* Output mapping symbols for linker generated sections. */
11982 elf32_arm_output_arch_local_syms (bfd *output_bfd,
11983 struct bfd_link_info *info,
11985 bfd_boolean (*func) (void *, const char *,
11986 Elf_Internal_Sym *,
11988 struct elf_link_hash_entry *))
11990 output_arch_syminfo osi;
11991 struct elf32_arm_link_hash_table *htab;
11993 bfd_size_type size;
11995 htab = elf32_arm_hash_table (info);
11996 check_use_blx (htab);
12002 /* ARM->Thumb glue. */
12003 if (htab->arm_glue_size > 0)
12005 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12006 ARM2THUMB_GLUE_SECTION_NAME);
12008 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12009 (output_bfd, osi.sec->output_section);
12010 if (info->shared || htab->root.is_relocatable_executable
12011 || htab->pic_veneer)
12012 size = ARM2THUMB_PIC_GLUE_SIZE;
12013 else if (htab->use_blx)
12014 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
12016 size = ARM2THUMB_STATIC_GLUE_SIZE;
12018 for (offset = 0; offset < htab->arm_glue_size; offset += size)
12020 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
12021 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
12025 /* Thumb->ARM glue. */
12026 if (htab->thumb_glue_size > 0)
12028 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12029 THUMB2ARM_GLUE_SECTION_NAME);
12031 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12032 (output_bfd, osi.sec->output_section);
12033 size = THUMB2ARM_GLUE_SIZE;
12035 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
12037 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
12038 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
12042 /* ARMv4 BX veneers. */
12043 if (htab->bx_glue_size > 0)
12045 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
12046 ARM_BX_GLUE_SECTION_NAME);
12048 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12049 (output_bfd, osi.sec->output_section);
12051 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
12054 /* Long calls stubs. */
12055 if (htab->stub_bfd && htab->stub_bfd->sections)
12057 asection* stub_sec;
12059 for (stub_sec = htab->stub_bfd->sections;
12061 stub_sec = stub_sec->next)
12063 /* Ignore non-stub sections. */
12064 if (!strstr (stub_sec->name, STUB_SUFFIX))
12067 osi.sec = stub_sec;
12069 osi.sec_shndx = _bfd_elf_section_from_bfd_section
12070 (output_bfd, osi.sec->output_section);
12072 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
12076 /* Finally, output mapping symbols for the PLT. */
12077 if (!htab->splt || htab->splt->size == 0)
12080 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
12081 htab->splt->output_section);
12082 osi.sec = htab->splt;
12083 /* Output mapping symbols for the plt header. SymbianOS does not have a
12085 if (htab->vxworks_p)
12087 /* VxWorks shared libraries have no PLT header. */
12090 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12092 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
12096 else if (!htab->symbian_p)
12098 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
12100 #ifndef FOUR_WORD_PLT
12101 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
12106 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
12110 /* Allocate target specific section data. */
12113 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
12115 if (!sec->used_by_bfd)
12117 _arm_elf_section_data *sdata;
12118 bfd_size_type amt = sizeof (*sdata);
12120 sdata = bfd_zalloc (abfd, amt);
12123 sec->used_by_bfd = sdata;
12126 record_section_with_arm_elf_section_data (sec);
12128 return _bfd_elf_new_section_hook (abfd, sec);
12132 /* Used to order a list of mapping symbols by address. */
12135 elf32_arm_compare_mapping (const void * a, const void * b)
12137 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
12138 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
12140 if (amap->vma > bmap->vma)
12142 else if (amap->vma < bmap->vma)
12144 else if (amap->type > bmap->type)
12145 /* Ensure results do not depend on the host qsort for objects with
12146 multiple mapping symbols at the same address by sorting on type
12149 else if (amap->type < bmap->type)
12156 /* Do code byteswapping. Return FALSE afterwards so that the section is
12157 written out as normal. */
12160 elf32_arm_write_section (bfd *output_bfd,
12161 struct bfd_link_info *link_info,
12163 bfd_byte *contents)
12165 int mapcount, errcount;
12166 _arm_elf_section_data *arm_data;
12167 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
12168 elf32_arm_section_map *map;
12169 elf32_vfp11_erratum_list *errnode;
12172 bfd_vma offset = sec->output_section->vma + sec->output_offset;
12176 /* If this section has not been allocated an _arm_elf_section_data
12177 structure then we cannot record anything. */
12178 arm_data = get_arm_elf_section_data (sec);
12179 if (arm_data == NULL)
12182 mapcount = arm_data->mapcount;
12183 map = arm_data->map;
12184 errcount = arm_data->erratumcount;
12188 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
12190 for (errnode = arm_data->erratumlist; errnode != 0;
12191 errnode = errnode->next)
12193 bfd_vma index = errnode->vma - offset;
12195 switch (errnode->type)
12197 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
12199 bfd_vma branch_to_veneer;
12200 /* Original condition code of instruction, plus bit mask for
12201 ARM B instruction. */
12202 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
12205 /* The instruction is before the label. */
12208 /* Above offset included in -4 below. */
12209 branch_to_veneer = errnode->u.b.veneer->vma
12210 - errnode->vma - 4;
12212 if ((signed) branch_to_veneer < -(1 << 25)
12213 || (signed) branch_to_veneer >= (1 << 25))
12214 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12215 "range"), output_bfd);
12217 insn |= (branch_to_veneer >> 2) & 0xffffff;
12218 contents[endianflip ^ index] = insn & 0xff;
12219 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12220 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12221 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12225 case VFP11_ERRATUM_ARM_VENEER:
12227 bfd_vma branch_from_veneer;
12230 /* Take size of veneer into account. */
12231 branch_from_veneer = errnode->u.v.branch->vma
12232 - errnode->vma - 12;
12234 if ((signed) branch_from_veneer < -(1 << 25)
12235 || (signed) branch_from_veneer >= (1 << 25))
12236 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12237 "range"), output_bfd);
12239 /* Original instruction. */
12240 insn = errnode->u.v.branch->u.b.vfp_insn;
12241 contents[endianflip ^ index] = insn & 0xff;
12242 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12243 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12244 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12246 /* Branch back to insn after original insn. */
12247 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
12248 contents[endianflip ^ (index + 4)] = insn & 0xff;
12249 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
12250 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
12251 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
12264 if (globals->byteswap_code)
12266 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
12269 for (i = 0; i < mapcount; i++)
12271 if (i == mapcount - 1)
12274 end = map[i + 1].vma;
12276 switch (map[i].type)
12279 /* Byte swap code words. */
12280 while (ptr + 3 < end)
12282 tmp = contents[ptr];
12283 contents[ptr] = contents[ptr + 3];
12284 contents[ptr + 3] = tmp;
12285 tmp = contents[ptr + 1];
12286 contents[ptr + 1] = contents[ptr + 2];
12287 contents[ptr + 2] = tmp;
12293 /* Byte swap code halfwords. */
12294 while (ptr + 1 < end)
12296 tmp = contents[ptr];
12297 contents[ptr] = contents[ptr + 1];
12298 contents[ptr + 1] = tmp;
12304 /* Leave data alone. */
12312 arm_data->mapcount = 0;
12313 arm_data->mapsize = 0;
12314 arm_data->map = NULL;
12315 unrecord_section_with_arm_elf_section_data (sec);
12321 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
12323 void * ignore ATTRIBUTE_UNUSED)
12325 unrecord_section_with_arm_elf_section_data (sec);
12329 elf32_arm_close_and_cleanup (bfd * abfd)
12331 if (abfd->sections)
12332 bfd_map_over_sections (abfd,
12333 unrecord_section_via_map_over_sections,
12336 return _bfd_elf_close_and_cleanup (abfd);
12340 elf32_arm_bfd_free_cached_info (bfd * abfd)
12342 if (abfd->sections)
12343 bfd_map_over_sections (abfd,
12344 unrecord_section_via_map_over_sections,
12347 return _bfd_free_cached_info (abfd);
12350 /* Display STT_ARM_TFUNC symbols as functions. */
12353 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
12356 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
12358 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
12359 elfsym->symbol.flags |= BSF_FUNCTION;
12363 /* Mangle thumb function symbols as we read them in. */
12366 elf32_arm_swap_symbol_in (bfd * abfd,
12369 Elf_Internal_Sym *dst)
12371 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
12374 /* New EABI objects mark thumb function symbols by setting the low bit of
12375 the address. Turn these into STT_ARM_TFUNC. */
12376 if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC)
12377 && (dst->st_value & 1))
12379 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
12380 dst->st_value &= ~(bfd_vma) 1;
12386 /* Mangle thumb function symbols as we write them out. */
12389 elf32_arm_swap_symbol_out (bfd *abfd,
12390 const Elf_Internal_Sym *src,
12394 Elf_Internal_Sym newsym;
12396 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12397 of the address set, as per the new EABI. We do this unconditionally
12398 because objcopy does not set the elf header flags until after
12399 it writes out the symbol table. */
12400 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
12403 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
12404 if (newsym.st_shndx != SHN_UNDEF)
12406 /* Do this only for defined symbols. At link type, the static
12407 linker will simulate the work of dynamic linker of resolving
12408 symbols and will carry over the thumbness of found symbols to
12409 the output symbol table. It's not clear how it happens, but
12410 the thumbness of undefined symbols can well be different at
12411 runtime, and writing '1' for them will be confusing for users
12412 and possibly for dynamic linker itself.
12414 newsym.st_value |= 1;
12419 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
12422 /* Add the PT_ARM_EXIDX program header. */
12425 elf32_arm_modify_segment_map (bfd *abfd,
12426 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12428 struct elf_segment_map *m;
12431 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12432 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12434 /* If there is already a PT_ARM_EXIDX header, then we do not
12435 want to add another one. This situation arises when running
12436 "strip"; the input binary already has the header. */
12437 m = elf_tdata (abfd)->segment_map;
12438 while (m && m->p_type != PT_ARM_EXIDX)
12442 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
12445 m->p_type = PT_ARM_EXIDX;
12447 m->sections[0] = sec;
12449 m->next = elf_tdata (abfd)->segment_map;
12450 elf_tdata (abfd)->segment_map = m;
12457 /* We may add a PT_ARM_EXIDX program header. */
12460 elf32_arm_additional_program_headers (bfd *abfd,
12461 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12465 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12466 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12472 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
12475 elf32_arm_is_function_type (unsigned int type)
12477 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
12480 /* We use this to override swap_symbol_in and swap_symbol_out. */
12481 const struct elf_size_info elf32_arm_size_info =
12483 sizeof (Elf32_External_Ehdr),
12484 sizeof (Elf32_External_Phdr),
12485 sizeof (Elf32_External_Shdr),
12486 sizeof (Elf32_External_Rel),
12487 sizeof (Elf32_External_Rela),
12488 sizeof (Elf32_External_Sym),
12489 sizeof (Elf32_External_Dyn),
12490 sizeof (Elf_External_Note),
12494 ELFCLASS32, EV_CURRENT,
12495 bfd_elf32_write_out_phdrs,
12496 bfd_elf32_write_shdrs_and_ehdr,
12497 bfd_elf32_checksum_contents,
12498 bfd_elf32_write_relocs,
12499 elf32_arm_swap_symbol_in,
12500 elf32_arm_swap_symbol_out,
12501 bfd_elf32_slurp_reloc_table,
12502 bfd_elf32_slurp_symbol_table,
12503 bfd_elf32_swap_dyn_in,
12504 bfd_elf32_swap_dyn_out,
12505 bfd_elf32_swap_reloc_in,
12506 bfd_elf32_swap_reloc_out,
12507 bfd_elf32_swap_reloca_in,
12508 bfd_elf32_swap_reloca_out
12511 #define ELF_ARCH bfd_arch_arm
12512 #define ELF_MACHINE_CODE EM_ARM
12513 #ifdef __QNXTARGET__
12514 #define ELF_MAXPAGESIZE 0x1000
12516 #define ELF_MAXPAGESIZE 0x8000
12518 #define ELF_MINPAGESIZE 0x1000
12519 #define ELF_COMMONPAGESIZE 0x1000
12521 #define bfd_elf32_mkobject elf32_arm_mkobject
12523 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12524 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
12525 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12526 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12527 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
12528 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
12529 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
12530 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
12531 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
12532 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
12533 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
12534 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
12535 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
12536 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
12537 #define bfd_elf32_bfd_final_link elf32_arm_final_link
12539 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12540 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
12541 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
12542 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12543 #define elf_backend_check_relocs elf32_arm_check_relocs
12544 #define elf_backend_relocate_section elf32_arm_relocate_section
12545 #define elf_backend_write_section elf32_arm_write_section
12546 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
12547 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
12548 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12549 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12550 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
12551 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
12552 #define elf_backend_post_process_headers elf32_arm_post_process_headers
12553 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
12554 #define elf_backend_object_p elf32_arm_object_p
12555 #define elf_backend_section_flags elf32_arm_section_flags
12556 #define elf_backend_fake_sections elf32_arm_fake_sections
12557 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
12558 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12559 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
12560 #define elf_backend_symbol_processing elf32_arm_symbol_processing
12561 #define elf_backend_size_info elf32_arm_size_info
12562 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
12563 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12564 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12565 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12566 #define elf_backend_is_function_type elf32_arm_is_function_type
12568 #define elf_backend_can_refcount 1
12569 #define elf_backend_can_gc_sections 1
12570 #define elf_backend_plt_readonly 1
12571 #define elf_backend_want_got_plt 1
12572 #define elf_backend_want_plt_sym 0
12573 #define elf_backend_may_use_rel_p 1
12574 #define elf_backend_may_use_rela_p 0
12575 #define elf_backend_default_use_rela_p 0
12577 #define elf_backend_got_header_size 12
12579 #undef elf_backend_obj_attrs_vendor
12580 #define elf_backend_obj_attrs_vendor "aeabi"
12581 #undef elf_backend_obj_attrs_section
12582 #define elf_backend_obj_attrs_section ".ARM.attributes"
12583 #undef elf_backend_obj_attrs_arg_type
12584 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12585 #undef elf_backend_obj_attrs_section_type
12586 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
12587 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
12589 #include "elf32-target.h"
12591 /* VxWorks Targets. */
12593 #undef TARGET_LITTLE_SYM
12594 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
12595 #undef TARGET_LITTLE_NAME
12596 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
12597 #undef TARGET_BIG_SYM
12598 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
12599 #undef TARGET_BIG_NAME
12600 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12602 /* Like elf32_arm_link_hash_table_create -- but overrides
12603 appropriately for VxWorks. */
12605 static struct bfd_link_hash_table *
12606 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
12608 struct bfd_link_hash_table *ret;
12610 ret = elf32_arm_link_hash_table_create (abfd);
12613 struct elf32_arm_link_hash_table *htab
12614 = (struct elf32_arm_link_hash_table *) ret;
12616 htab->vxworks_p = 1;
12622 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
12624 elf32_arm_final_write_processing (abfd, linker);
12625 elf_vxworks_final_write_processing (abfd, linker);
12629 #define elf32_bed elf32_arm_vxworks_bed
12631 #undef bfd_elf32_bfd_link_hash_table_create
12632 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12633 #undef elf_backend_add_symbol_hook
12634 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12635 #undef elf_backend_final_write_processing
12636 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12637 #undef elf_backend_emit_relocs
12638 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
12640 #undef elf_backend_may_use_rel_p
12641 #define elf_backend_may_use_rel_p 0
12642 #undef elf_backend_may_use_rela_p
12643 #define elf_backend_may_use_rela_p 1
12644 #undef elf_backend_default_use_rela_p
12645 #define elf_backend_default_use_rela_p 1
12646 #undef elf_backend_want_plt_sym
12647 #define elf_backend_want_plt_sym 1
12648 #undef ELF_MAXPAGESIZE
12649 #define ELF_MAXPAGESIZE 0x1000
12651 #include "elf32-target.h"
12654 /* Symbian OS Targets. */
12656 #undef TARGET_LITTLE_SYM
12657 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
12658 #undef TARGET_LITTLE_NAME
12659 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
12660 #undef TARGET_BIG_SYM
12661 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
12662 #undef TARGET_BIG_NAME
12663 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
12665 /* Like elf32_arm_link_hash_table_create -- but overrides
12666 appropriately for Symbian OS. */
12668 static struct bfd_link_hash_table *
12669 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
12671 struct bfd_link_hash_table *ret;
12673 ret = elf32_arm_link_hash_table_create (abfd);
12676 struct elf32_arm_link_hash_table *htab
12677 = (struct elf32_arm_link_hash_table *)ret;
12678 /* There is no PLT header for Symbian OS. */
12679 htab->plt_header_size = 0;
12680 /* The PLT entries are each one instruction and one word. */
12681 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
12682 htab->symbian_p = 1;
12683 /* Symbian uses armv5t or above, so use_blx is always true. */
12685 htab->root.is_relocatable_executable = 1;
12690 static const struct bfd_elf_special_section
12691 elf32_arm_symbian_special_sections[] =
12693 /* In a BPABI executable, the dynamic linking sections do not go in
12694 the loadable read-only segment. The post-linker may wish to
12695 refer to these sections, but they are not part of the final
12697 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12698 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12699 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12700 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12701 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
12702 /* These sections do not need to be writable as the SymbianOS
12703 postlinker will arrange things so that no dynamic relocation is
12705 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12706 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12707 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12708 { NULL, 0, 0, 0, 0 }
12712 elf32_arm_symbian_begin_write_processing (bfd *abfd,
12713 struct bfd_link_info *link_info)
12715 /* BPABI objects are never loaded directly by an OS kernel; they are
12716 processed by a postlinker first, into an OS-specific format. If
12717 the D_PAGED bit is set on the file, BFD will align segments on
12718 page boundaries, so that an OS can directly map the file. With
12719 BPABI objects, that just results in wasted space. In addition,
12720 because we clear the D_PAGED bit, map_sections_to_segments will
12721 recognize that the program headers should not be mapped into any
12722 loadable segment. */
12723 abfd->flags &= ~D_PAGED;
12724 elf32_arm_begin_write_processing (abfd, link_info);
12728 elf32_arm_symbian_modify_segment_map (bfd *abfd,
12729 struct bfd_link_info *info)
12731 struct elf_segment_map *m;
12734 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12735 segment. However, because the .dynamic section is not marked
12736 with SEC_LOAD, the generic ELF code will not create such a
12738 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12741 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12742 if (m->p_type == PT_DYNAMIC)
12747 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12748 m->next = elf_tdata (abfd)->segment_map;
12749 elf_tdata (abfd)->segment_map = m;
12753 /* Also call the generic arm routine. */
12754 return elf32_arm_modify_segment_map (abfd, info);
12757 /* Return address for Ith PLT stub in section PLT, for relocation REL
12758 or (bfd_vma) -1 if it should not be included. */
12761 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12762 const arelent *rel ATTRIBUTE_UNUSED)
12764 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12769 #define elf32_bed elf32_arm_symbian_bed
12771 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12772 will process them and then discard them. */
12773 #undef ELF_DYNAMIC_SEC_FLAGS
12774 #define ELF_DYNAMIC_SEC_FLAGS \
12775 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12777 #undef elf_backend_add_symbol_hook
12778 #undef elf_backend_emit_relocs
12780 #undef bfd_elf32_bfd_link_hash_table_create
12781 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12782 #undef elf_backend_special_sections
12783 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12784 #undef elf_backend_begin_write_processing
12785 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12786 #undef elf_backend_final_write_processing
12787 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12789 #undef elf_backend_modify_segment_map
12790 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12792 /* There is no .got section for BPABI objects, and hence no header. */
12793 #undef elf_backend_got_header_size
12794 #define elf_backend_got_header_size 0
12796 /* Similarly, there is no .got.plt section. */
12797 #undef elf_backend_want_got_plt
12798 #define elf_backend_want_got_plt 0
12800 #undef elf_backend_plt_sym_val
12801 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12803 #undef elf_backend_may_use_rel_p
12804 #define elf_backend_may_use_rel_p 1
12805 #undef elf_backend_may_use_rela_p
12806 #define elf_backend_may_use_rela_p 0
12807 #undef elf_backend_default_use_rela_p
12808 #define elf_backend_default_use_rela_p 0
12809 #undef elf_backend_want_plt_sym
12810 #define elf_backend_want_plt_sym 0
12811 #undef ELF_MAXPAGESIZE
12812 #define ELF_MAXPAGESIZE 0x8000
12814 #include "elf32-target.h"