1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011 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. */
26 #include "libiberty.h"
29 #include "elf-vxworks.h"
32 /* Return the relocation section associated with NAME. HTAB is the
33 bfd's elf32_arm_link_hash_entry. */
34 #define RELOC_SECTION(HTAB, NAME) \
35 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
37 /* Return size of a relocation entry. HTAB is the bfd's
38 elf32_arm_link_hash_entry. */
39 #define RELOC_SIZE(HTAB) \
41 ? sizeof (Elf32_External_Rel) \
42 : sizeof (Elf32_External_Rela))
44 /* Return function to swap relocations in. HTAB is the bfd's
45 elf32_arm_link_hash_entry. */
46 #define SWAP_RELOC_IN(HTAB) \
48 ? bfd_elf32_swap_reloc_in \
49 : bfd_elf32_swap_reloca_in)
51 /* Return function to swap relocations out. HTAB is the bfd's
52 elf32_arm_link_hash_entry. */
53 #define SWAP_RELOC_OUT(HTAB) \
55 ? bfd_elf32_swap_reloc_out \
56 : bfd_elf32_swap_reloca_out)
58 #define elf_info_to_howto 0
59 #define elf_info_to_howto_rel elf32_arm_info_to_howto
61 #define ARM_ELF_ABI_VERSION 0
62 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
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 0x07ff2fff, /* src_mask */
233 0x07ff2fff, /* 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_TLS_DESC, /* type */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
268 FALSE, /* pc_relative */
270 complain_overflow_bitfield,/* complain_on_overflow */
271 bfd_elf_generic_reloc, /* special_function */
272 "R_ARM_TLS_DESC", /* name */
273 FALSE, /* partial_inplace */
274 0xffffffff, /* src_mask */
275 0xffffffff, /* 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 0x07ff2fff, /* src_mask */
319 0x07ff2fff, /* 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 HOWTO (R_ARM_TLS_GOTDESC, /* type */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE, /* pc_relative */
1361 complain_overflow_bitfield,/* complain_on_overflow */
1362 NULL, /* special_function */
1363 "R_ARM_TLS_GOTDESC", /* name */
1364 TRUE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 HOWTO (R_ARM_TLS_CALL, /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE, /* pc_relative */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_TLS_CALL", /* name */
1378 FALSE, /* partial_inplace */
1379 0x00ffffff, /* src_mask */
1380 0x00ffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1383 HOWTO (R_ARM_TLS_DESCSEQ, /* type */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE, /* pc_relative */
1389 complain_overflow_bitfield,/* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_TLS_DESCSEQ", /* name */
1392 FALSE, /* partial_inplace */
1393 0x00000000, /* src_mask */
1394 0x00000000, /* dst_mask */
1395 FALSE), /* pcrel_offset */
1397 HOWTO (R_ARM_THM_TLS_CALL, /* type */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE, /* pc_relative */
1403 complain_overflow_dont,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_THM_TLS_CALL", /* name */
1406 FALSE, /* partial_inplace */
1407 0x07ff07ff, /* src_mask */
1408 0x07ff07ff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1411 HOWTO (R_ARM_PLT32_ABS, /* type */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1415 FALSE, /* pc_relative */
1417 complain_overflow_dont,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_PLT32_ABS", /* name */
1420 FALSE, /* partial_inplace */
1421 0xffffffff, /* src_mask */
1422 0xffffffff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1425 HOWTO (R_ARM_GOT_ABS, /* type */
1427 2, /* size (0 = byte, 1 = short, 2 = long) */
1429 FALSE, /* pc_relative */
1431 complain_overflow_dont,/* complain_on_overflow */
1432 bfd_elf_generic_reloc, /* special_function */
1433 "R_ARM_GOT_ABS", /* name */
1434 FALSE, /* partial_inplace */
1435 0xffffffff, /* src_mask */
1436 0xffffffff, /* dst_mask */
1437 FALSE), /* pcrel_offset */
1439 HOWTO (R_ARM_GOT_PREL, /* type */
1441 2, /* size (0 = byte, 1 = short, 2 = long) */
1443 TRUE, /* pc_relative */
1445 complain_overflow_dont, /* complain_on_overflow */
1446 bfd_elf_generic_reloc, /* special_function */
1447 "R_ARM_GOT_PREL", /* name */
1448 FALSE, /* partial_inplace */
1449 0xffffffff, /* src_mask */
1450 0xffffffff, /* dst_mask */
1451 TRUE), /* pcrel_offset */
1453 HOWTO (R_ARM_GOT_BREL12, /* type */
1455 2, /* size (0 = byte, 1 = short, 2 = long) */
1457 FALSE, /* pc_relative */
1459 complain_overflow_bitfield,/* complain_on_overflow */
1460 bfd_elf_generic_reloc, /* special_function */
1461 "R_ARM_GOT_BREL12", /* name */
1462 FALSE, /* partial_inplace */
1463 0x00000fff, /* src_mask */
1464 0x00000fff, /* dst_mask */
1465 FALSE), /* pcrel_offset */
1467 HOWTO (R_ARM_GOTOFF12, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 FALSE, /* pc_relative */
1473 complain_overflow_bitfield,/* complain_on_overflow */
1474 bfd_elf_generic_reloc, /* special_function */
1475 "R_ARM_GOTOFF12", /* name */
1476 FALSE, /* partial_inplace */
1477 0x00000fff, /* src_mask */
1478 0x00000fff, /* dst_mask */
1479 FALSE), /* pcrel_offset */
1481 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1483 /* GNU extension to record C++ vtable member usage */
1484 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE, /* pc_relative */
1490 complain_overflow_dont, /* complain_on_overflow */
1491 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1492 "R_ARM_GNU_VTENTRY", /* name */
1493 FALSE, /* partial_inplace */
1496 FALSE), /* pcrel_offset */
1498 /* GNU extension to record C++ vtable hierarchy */
1499 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1501 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE, /* pc_relative */
1505 complain_overflow_dont, /* complain_on_overflow */
1506 NULL, /* special_function */
1507 "R_ARM_GNU_VTINHERIT", /* name */
1508 FALSE, /* partial_inplace */
1511 FALSE), /* pcrel_offset */
1513 HOWTO (R_ARM_THM_JUMP11, /* type */
1515 1, /* size (0 = byte, 1 = short, 2 = long) */
1517 TRUE, /* pc_relative */
1519 complain_overflow_signed, /* complain_on_overflow */
1520 bfd_elf_generic_reloc, /* special_function */
1521 "R_ARM_THM_JUMP11", /* name */
1522 FALSE, /* partial_inplace */
1523 0x000007ff, /* src_mask */
1524 0x000007ff, /* dst_mask */
1525 TRUE), /* pcrel_offset */
1527 HOWTO (R_ARM_THM_JUMP8, /* type */
1529 1, /* size (0 = byte, 1 = short, 2 = long) */
1531 TRUE, /* pc_relative */
1533 complain_overflow_signed, /* complain_on_overflow */
1534 bfd_elf_generic_reloc, /* special_function */
1535 "R_ARM_THM_JUMP8", /* name */
1536 FALSE, /* partial_inplace */
1537 0x000000ff, /* src_mask */
1538 0x000000ff, /* dst_mask */
1539 TRUE), /* pcrel_offset */
1541 /* TLS relocations */
1542 HOWTO (R_ARM_TLS_GD32, /* type */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE, /* pc_relative */
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 NULL, /* special_function */
1550 "R_ARM_TLS_GD32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
1556 HOWTO (R_ARM_TLS_LDM32, /* type */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE, /* pc_relative */
1562 complain_overflow_bitfield,/* complain_on_overflow */
1563 bfd_elf_generic_reloc, /* special_function */
1564 "R_ARM_TLS_LDM32", /* name */
1565 TRUE, /* partial_inplace */
1566 0xffffffff, /* src_mask */
1567 0xffffffff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1570 HOWTO (R_ARM_TLS_LDO32, /* type */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE, /* pc_relative */
1576 complain_overflow_bitfield,/* complain_on_overflow */
1577 bfd_elf_generic_reloc, /* special_function */
1578 "R_ARM_TLS_LDO32", /* name */
1579 TRUE, /* partial_inplace */
1580 0xffffffff, /* src_mask */
1581 0xffffffff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
1584 HOWTO (R_ARM_TLS_IE32, /* type */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE, /* pc_relative */
1590 complain_overflow_bitfield,/* complain_on_overflow */
1591 NULL, /* special_function */
1592 "R_ARM_TLS_IE32", /* name */
1593 TRUE, /* partial_inplace */
1594 0xffffffff, /* src_mask */
1595 0xffffffff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1598 HOWTO (R_ARM_TLS_LE32, /* type */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1602 FALSE, /* pc_relative */
1604 complain_overflow_bitfield,/* complain_on_overflow */
1605 bfd_elf_generic_reloc, /* special_function */
1606 "R_ARM_TLS_LE32", /* name */
1607 TRUE, /* partial_inplace */
1608 0xffffffff, /* src_mask */
1609 0xffffffff, /* dst_mask */
1610 FALSE), /* pcrel_offset */
1612 HOWTO (R_ARM_TLS_LDO12, /* type */
1614 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE, /* pc_relative */
1618 complain_overflow_bitfield,/* complain_on_overflow */
1619 bfd_elf_generic_reloc, /* special_function */
1620 "R_ARM_TLS_LDO12", /* name */
1621 FALSE, /* partial_inplace */
1622 0x00000fff, /* src_mask */
1623 0x00000fff, /* dst_mask */
1624 FALSE), /* pcrel_offset */
1626 HOWTO (R_ARM_TLS_LE12, /* type */
1628 2, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE, /* pc_relative */
1632 complain_overflow_bitfield,/* complain_on_overflow */
1633 bfd_elf_generic_reloc, /* special_function */
1634 "R_ARM_TLS_LE12", /* name */
1635 FALSE, /* partial_inplace */
1636 0x00000fff, /* src_mask */
1637 0x00000fff, /* dst_mask */
1638 FALSE), /* pcrel_offset */
1640 HOWTO (R_ARM_TLS_IE12GP, /* type */
1642 2, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE, /* pc_relative */
1646 complain_overflow_bitfield,/* complain_on_overflow */
1647 bfd_elf_generic_reloc, /* special_function */
1648 "R_ARM_TLS_IE12GP", /* name */
1649 FALSE, /* partial_inplace */
1650 0x00000fff, /* src_mask */
1651 0x00000fff, /* dst_mask */
1652 FALSE), /* pcrel_offset */
1654 /* 112-127 private relocations. */
1672 /* R_ARM_ME_TOO, obsolete. */
1675 HOWTO (R_ARM_THM_TLS_DESCSEQ, /* type */
1677 1, /* size (0 = byte, 1 = short, 2 = long) */
1679 FALSE, /* pc_relative */
1681 complain_overflow_bitfield,/* complain_on_overflow */
1682 bfd_elf_generic_reloc, /* special_function */
1683 "R_ARM_THM_TLS_DESCSEQ",/* name */
1684 FALSE, /* partial_inplace */
1685 0x00000000, /* src_mask */
1686 0x00000000, /* dst_mask */
1687 FALSE), /* pcrel_offset */
1691 static reloc_howto_type elf32_arm_howto_table_2[1] =
1693 HOWTO (R_ARM_IRELATIVE, /* type */
1695 2, /* size (0 = byte, 1 = short, 2 = long) */
1697 FALSE, /* pc_relative */
1699 complain_overflow_bitfield,/* complain_on_overflow */
1700 bfd_elf_generic_reloc, /* special_function */
1701 "R_ARM_IRELATIVE", /* name */
1702 TRUE, /* partial_inplace */
1703 0xffffffff, /* src_mask */
1704 0xffffffff, /* dst_mask */
1705 FALSE) /* pcrel_offset */
1708 /* 249-255 extended, currently unused, relocations: */
1709 static reloc_howto_type elf32_arm_howto_table_3[4] =
1711 HOWTO (R_ARM_RREL32, /* type */
1713 0, /* size (0 = byte, 1 = short, 2 = long) */
1715 FALSE, /* pc_relative */
1717 complain_overflow_dont,/* complain_on_overflow */
1718 bfd_elf_generic_reloc, /* special_function */
1719 "R_ARM_RREL32", /* name */
1720 FALSE, /* partial_inplace */
1723 FALSE), /* pcrel_offset */
1725 HOWTO (R_ARM_RABS32, /* type */
1727 0, /* size (0 = byte, 1 = short, 2 = long) */
1729 FALSE, /* pc_relative */
1731 complain_overflow_dont,/* complain_on_overflow */
1732 bfd_elf_generic_reloc, /* special_function */
1733 "R_ARM_RABS32", /* name */
1734 FALSE, /* partial_inplace */
1737 FALSE), /* pcrel_offset */
1739 HOWTO (R_ARM_RPC24, /* type */
1741 0, /* size (0 = byte, 1 = short, 2 = long) */
1743 FALSE, /* pc_relative */
1745 complain_overflow_dont,/* complain_on_overflow */
1746 bfd_elf_generic_reloc, /* special_function */
1747 "R_ARM_RPC24", /* name */
1748 FALSE, /* partial_inplace */
1751 FALSE), /* pcrel_offset */
1753 HOWTO (R_ARM_RBASE, /* type */
1755 0, /* size (0 = byte, 1 = short, 2 = long) */
1757 FALSE, /* pc_relative */
1759 complain_overflow_dont,/* complain_on_overflow */
1760 bfd_elf_generic_reloc, /* special_function */
1761 "R_ARM_RBASE", /* name */
1762 FALSE, /* partial_inplace */
1765 FALSE) /* pcrel_offset */
1768 static reloc_howto_type *
1769 elf32_arm_howto_from_type (unsigned int r_type)
1771 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1772 return &elf32_arm_howto_table_1[r_type];
1774 if (r_type == R_ARM_IRELATIVE)
1775 return &elf32_arm_howto_table_2[r_type - R_ARM_IRELATIVE];
1777 if (r_type >= R_ARM_RREL32
1778 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_3))
1779 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32];
1785 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1786 Elf_Internal_Rela * elf_reloc)
1788 unsigned int r_type;
1790 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1791 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1794 struct elf32_arm_reloc_map
1796 bfd_reloc_code_real_type bfd_reloc_val;
1797 unsigned char elf_reloc_val;
1800 /* All entries in this list must also be present in elf32_arm_howto_table. */
1801 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1803 {BFD_RELOC_NONE, R_ARM_NONE},
1804 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1805 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1806 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1807 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1808 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1809 {BFD_RELOC_32, R_ARM_ABS32},
1810 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1811 {BFD_RELOC_8, R_ARM_ABS8},
1812 {BFD_RELOC_16, R_ARM_ABS16},
1813 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1814 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1815 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1816 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1817 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1818 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1819 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1820 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1821 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1822 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1823 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1824 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1825 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1826 {BFD_RELOC_ARM_GOT_PREL, R_ARM_GOT_PREL},
1827 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1828 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1829 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1830 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1831 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1832 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1833 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1834 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1835 {BFD_RELOC_ARM_TLS_GOTDESC, R_ARM_TLS_GOTDESC},
1836 {BFD_RELOC_ARM_TLS_CALL, R_ARM_TLS_CALL},
1837 {BFD_RELOC_ARM_THM_TLS_CALL, R_ARM_THM_TLS_CALL},
1838 {BFD_RELOC_ARM_TLS_DESCSEQ, R_ARM_TLS_DESCSEQ},
1839 {BFD_RELOC_ARM_THM_TLS_DESCSEQ, R_ARM_THM_TLS_DESCSEQ},
1840 {BFD_RELOC_ARM_TLS_DESC, R_ARM_TLS_DESC},
1841 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1842 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1843 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1844 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1845 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1846 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1847 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1848 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1849 {BFD_RELOC_ARM_IRELATIVE, R_ARM_IRELATIVE},
1850 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1851 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1852 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1853 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1854 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1855 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1856 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1857 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1858 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1859 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1860 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1861 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1862 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1863 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1864 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1865 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1866 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1867 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1868 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1869 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1870 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1871 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1872 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1873 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1874 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1875 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1876 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1877 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1878 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1879 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1880 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1881 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1882 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1883 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1884 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1885 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1886 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1887 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1888 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
1891 static reloc_howto_type *
1892 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1893 bfd_reloc_code_real_type code)
1897 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
1898 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1899 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1904 static reloc_howto_type *
1905 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1910 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1911 if (elf32_arm_howto_table_1[i].name != NULL
1912 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1913 return &elf32_arm_howto_table_1[i];
1915 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1916 if (elf32_arm_howto_table_2[i].name != NULL
1917 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1918 return &elf32_arm_howto_table_2[i];
1920 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_3); i++)
1921 if (elf32_arm_howto_table_3[i].name != NULL
1922 && strcasecmp (elf32_arm_howto_table_3[i].name, r_name) == 0)
1923 return &elf32_arm_howto_table_3[i];
1928 /* Support for core dump NOTE sections. */
1931 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1936 switch (note->descsz)
1941 case 148: /* Linux/ARM 32-bit. */
1943 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1946 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
1955 /* Make a ".reg/999" section. */
1956 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1957 size, note->descpos + offset);
1961 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1963 switch (note->descsz)
1968 case 124: /* Linux/ARM elf_prpsinfo. */
1969 elf_tdata (abfd)->core_program
1970 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1971 elf_tdata (abfd)->core_command
1972 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1975 /* Note that for some reason, a spurious space is tacked
1976 onto the end of the args in some (at least one anyway)
1977 implementations, so strip it off if it exists. */
1979 char *command = elf_tdata (abfd)->core_command;
1980 int n = strlen (command);
1982 if (0 < n && command[n - 1] == ' ')
1983 command[n - 1] = '\0';
1989 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1990 #define TARGET_LITTLE_NAME "elf32-littlearm"
1991 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1992 #define TARGET_BIG_NAME "elf32-bigarm"
1994 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1995 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1997 typedef unsigned long int insn32;
1998 typedef unsigned short int insn16;
2000 /* In lieu of proper flags, assume all EABIv4 or later objects are
2002 #define INTERWORK_FLAG(abfd) \
2003 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
2004 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
2005 || ((abfd)->flags & BFD_LINKER_CREATED))
2007 /* The linker script knows the section names for placement.
2008 The entry_names are used to do simple name mangling on the stubs.
2009 Given a function name, and its type, the stub can be found. The
2010 name can be changed. The only requirement is the %s be present. */
2011 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
2012 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
2014 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
2015 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
2017 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
2018 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
2020 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
2021 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
2023 #define STUB_ENTRY_NAME "__%s_veneer"
2025 /* The name of the dynamic interpreter. This is put in the .interp
2027 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
2029 static const unsigned long tls_trampoline [] =
2031 0xe08e0000, /* add r0, lr, r0 */
2032 0xe5901004, /* ldr r1, [r0,#4] */
2033 0xe12fff11, /* bx r1 */
2036 static const unsigned long dl_tlsdesc_lazy_trampoline [] =
2038 0xe52d2004, /* push {r2} */
2039 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */
2040 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */
2041 0xe79f2002, /* 1: ldr r2, [pc, r2] */
2042 0xe081100f, /* 2: add r1, pc */
2043 0xe12fff12, /* bx r2 */
2044 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8
2045 + dl_tlsdesc_lazy_resolver(GOT) */
2046 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */
2049 #ifdef FOUR_WORD_PLT
2051 /* The first entry in a procedure linkage table looks like
2052 this. It is set up so that any shared library function that is
2053 called before the relocation has been set up calls the dynamic
2055 static const bfd_vma elf32_arm_plt0_entry [] =
2057 0xe52de004, /* str lr, [sp, #-4]! */
2058 0xe59fe010, /* ldr lr, [pc, #16] */
2059 0xe08fe00e, /* add lr, pc, lr */
2060 0xe5bef008, /* ldr pc, [lr, #8]! */
2063 /* Subsequent entries in a procedure linkage table look like
2065 static const bfd_vma elf32_arm_plt_entry [] =
2067 0xe28fc600, /* add ip, pc, #NN */
2068 0xe28cca00, /* add ip, ip, #NN */
2069 0xe5bcf000, /* ldr pc, [ip, #NN]! */
2070 0x00000000, /* unused */
2075 /* The first entry in a procedure linkage table looks like
2076 this. It is set up so that any shared library function that is
2077 called before the relocation has been set up calls the dynamic
2079 static const bfd_vma elf32_arm_plt0_entry [] =
2081 0xe52de004, /* str lr, [sp, #-4]! */
2082 0xe59fe004, /* ldr lr, [pc, #4] */
2083 0xe08fe00e, /* add lr, pc, lr */
2084 0xe5bef008, /* ldr pc, [lr, #8]! */
2085 0x00000000, /* &GOT[0] - . */
2088 /* Subsequent entries in a procedure linkage table look like
2090 static const bfd_vma elf32_arm_plt_entry [] =
2092 0xe28fc600, /* add ip, pc, #0xNN00000 */
2093 0xe28cca00, /* add ip, ip, #0xNN000 */
2094 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2099 /* The format of the first entry in the procedure linkage table
2100 for a VxWorks executable. */
2101 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
2103 0xe52dc008, /* str ip,[sp,#-8]! */
2104 0xe59fc000, /* ldr ip,[pc] */
2105 0xe59cf008, /* ldr pc,[ip,#8] */
2106 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2109 /* The format of subsequent entries in a VxWorks executable. */
2110 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
2112 0xe59fc000, /* ldr ip,[pc] */
2113 0xe59cf000, /* ldr pc,[ip] */
2114 0x00000000, /* .long @got */
2115 0xe59fc000, /* ldr ip,[pc] */
2116 0xea000000, /* b _PLT */
2117 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2120 /* The format of entries in a VxWorks shared library. */
2121 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
2123 0xe59fc000, /* ldr ip,[pc] */
2124 0xe79cf009, /* ldr pc,[ip,r9] */
2125 0x00000000, /* .long @got */
2126 0xe59fc000, /* ldr ip,[pc] */
2127 0xe599f008, /* ldr pc,[r9,#8] */
2128 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2131 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2132 #define PLT_THUMB_STUB_SIZE 4
2133 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2139 /* The entries in a PLT when using a DLL-based target with multiple
2141 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2143 0xe51ff004, /* ldr pc, [pc, #-4] */
2144 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2147 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2148 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2149 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2150 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2151 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2152 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2162 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2163 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2164 is inserted in arm_build_one_stub(). */
2165 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2166 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2167 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2168 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2169 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2170 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2175 enum stub_insn_type type;
2176 unsigned int r_type;
2180 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2181 to reach the stub if necessary. */
2182 static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
2184 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2185 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2188 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2190 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2192 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2193 ARM_INSN(0xe12fff1c), /* bx ip */
2194 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2197 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2198 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
2200 THUMB16_INSN(0xb401), /* push {r0} */
2201 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2202 THUMB16_INSN(0x4684), /* mov ip, r0 */
2203 THUMB16_INSN(0xbc01), /* pop {r0} */
2204 THUMB16_INSN(0x4760), /* bx ip */
2205 THUMB16_INSN(0xbf00), /* nop */
2206 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2209 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2211 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb[] =
2213 THUMB16_INSN(0x4778), /* bx pc */
2214 THUMB16_INSN(0x46c0), /* nop */
2215 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2216 ARM_INSN(0xe12fff1c), /* bx ip */
2217 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2220 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2222 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2224 THUMB16_INSN(0x4778), /* bx pc */
2225 THUMB16_INSN(0x46c0), /* nop */
2226 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2227 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2230 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2231 one, when the destination is close enough. */
2232 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2234 THUMB16_INSN(0x4778), /* bx pc */
2235 THUMB16_INSN(0x46c0), /* nop */
2236 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2239 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2240 blx to reach the stub if necessary. */
2241 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
2243 ARM_INSN(0xe59fc000), /* ldr ip, [pc] */
2244 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2245 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2248 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2249 blx to reach the stub if necessary. We can not add into pc;
2250 it is not guaranteed to mode switch (different in ARMv6 and
2252 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2254 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2255 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2256 ARM_INSN(0xe12fff1c), /* bx ip */
2257 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2260 /* V4T ARM -> ARM long branch stub, PIC. */
2261 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2263 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2264 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2265 ARM_INSN(0xe12fff1c), /* bx ip */
2266 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2269 /* V4T Thumb -> ARM long branch stub, PIC. */
2270 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2272 THUMB16_INSN(0x4778), /* bx pc */
2273 THUMB16_INSN(0x46c0), /* nop */
2274 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2275 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2276 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2279 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2281 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2283 THUMB16_INSN(0xb401), /* push {r0} */
2284 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2285 THUMB16_INSN(0x46fc), /* mov ip, pc */
2286 THUMB16_INSN(0x4484), /* add ip, r0 */
2287 THUMB16_INSN(0xbc01), /* pop {r0} */
2288 THUMB16_INSN(0x4760), /* bx ip */
2289 DATA_WORD(0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2292 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2294 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] =
2296 THUMB16_INSN(0x4778), /* bx pc */
2297 THUMB16_INSN(0x46c0), /* nop */
2298 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2299 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2300 ARM_INSN(0xe12fff1c), /* bx ip */
2301 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2304 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2305 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2306 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic[] =
2308 ARM_INSN(0xe59f1000), /* ldr r1, [pc] */
2309 ARM_INSN(0xe08ff001), /* add pc, pc, r1 */
2310 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2313 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2314 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2315 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic[] =
2317 THUMB16_INSN(0x4778), /* bx pc */
2318 THUMB16_INSN(0x46c0), /* nop */
2319 ARM_INSN(0xe59f1000), /* ldr r1, [pc, #0] */
2320 ARM_INSN(0xe081f00f), /* add pc, r1, pc */
2321 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2324 /* Cortex-A8 erratum-workaround stubs. */
2326 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2327 can't use a conditional branch to reach this stub). */
2329 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond[] =
2331 THUMB16_BCOND_INSN(0xd001), /* b<cond>.n true. */
2332 THUMB32_B_INSN(0xf000b800, -4), /* b.w insn_after_original_branch. */
2333 THUMB32_B_INSN(0xf000b800, -4) /* true: b.w original_branch_dest. */
2336 /* Stub used for b.w and bl.w instructions. */
2338 static const insn_sequence elf32_arm_stub_a8_veneer_b[] =
2340 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2343 static const insn_sequence elf32_arm_stub_a8_veneer_bl[] =
2345 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2348 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2349 instruction (which switches to ARM mode) to point to this stub. Jump to the
2350 real destination using an ARM-mode branch. */
2352 static const insn_sequence elf32_arm_stub_a8_veneer_blx[] =
2354 ARM_REL_INSN(0xea000000, -8) /* b original_branch_dest. */
2357 /* Section name for stubs is the associated section name plus this
2359 #define STUB_SUFFIX ".stub"
2361 /* One entry per long/short branch stub defined above. */
2363 DEF_STUB(long_branch_any_any) \
2364 DEF_STUB(long_branch_v4t_arm_thumb) \
2365 DEF_STUB(long_branch_thumb_only) \
2366 DEF_STUB(long_branch_v4t_thumb_thumb) \
2367 DEF_STUB(long_branch_v4t_thumb_arm) \
2368 DEF_STUB(short_branch_v4t_thumb_arm) \
2369 DEF_STUB(long_branch_any_arm_pic) \
2370 DEF_STUB(long_branch_any_thumb_pic) \
2371 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2372 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2373 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2374 DEF_STUB(long_branch_thumb_only_pic) \
2375 DEF_STUB(long_branch_any_tls_pic) \
2376 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2377 DEF_STUB(a8_veneer_b_cond) \
2378 DEF_STUB(a8_veneer_b) \
2379 DEF_STUB(a8_veneer_bl) \
2380 DEF_STUB(a8_veneer_blx)
2382 #define DEF_STUB(x) arm_stub_##x,
2383 enum elf32_arm_stub_type {
2386 /* Note the first a8_veneer type */
2387 arm_stub_a8_veneer_lwm = arm_stub_a8_veneer_b_cond
2393 const insn_sequence* template_sequence;
2397 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2398 static const stub_def stub_definitions[] = {
2403 struct elf32_arm_stub_hash_entry
2405 /* Base hash table entry structure. */
2406 struct bfd_hash_entry root;
2408 /* The stub section. */
2411 /* Offset within stub_sec of the beginning of this stub. */
2412 bfd_vma stub_offset;
2414 /* Given the symbol's value and its section we can determine its final
2415 value when building the stubs (so the stub knows where to jump). */
2416 bfd_vma target_value;
2417 asection *target_section;
2419 /* Offset to apply to relocation referencing target_value. */
2420 bfd_vma target_addend;
2422 /* The instruction which caused this stub to be generated (only valid for
2423 Cortex-A8 erratum workaround stubs at present). */
2424 unsigned long orig_insn;
2426 /* The stub type. */
2427 enum elf32_arm_stub_type stub_type;
2428 /* Its encoding size in bytes. */
2431 const insn_sequence *stub_template;
2432 /* The size of the template (number of entries). */
2433 int stub_template_size;
2435 /* The symbol table entry, if any, that this was derived from. */
2436 struct elf32_arm_link_hash_entry *h;
2438 /* Type of branch. */
2439 enum arm_st_branch_type branch_type;
2441 /* Where this stub is being called from, or, in the case of combined
2442 stub sections, the first input section in the group. */
2445 /* The name for the local symbol at the start of this stub. The
2446 stub name in the hash table has to be unique; this does not, so
2447 it can be friendlier. */
2451 /* Used to build a map of a section. This is required for mixed-endian
2454 typedef struct elf32_elf_section_map
2459 elf32_arm_section_map;
2461 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2465 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2466 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2467 VFP11_ERRATUM_ARM_VENEER,
2468 VFP11_ERRATUM_THUMB_VENEER
2470 elf32_vfp11_erratum_type;
2472 typedef struct elf32_vfp11_erratum_list
2474 struct elf32_vfp11_erratum_list *next;
2480 struct elf32_vfp11_erratum_list *veneer;
2481 unsigned int vfp_insn;
2485 struct elf32_vfp11_erratum_list *branch;
2489 elf32_vfp11_erratum_type type;
2491 elf32_vfp11_erratum_list;
2496 INSERT_EXIDX_CANTUNWIND_AT_END
2498 arm_unwind_edit_type;
2500 /* A (sorted) list of edits to apply to an unwind table. */
2501 typedef struct arm_unwind_table_edit
2503 arm_unwind_edit_type type;
2504 /* Note: we sometimes want to insert an unwind entry corresponding to a
2505 section different from the one we're currently writing out, so record the
2506 (text) section this edit relates to here. */
2507 asection *linked_section;
2509 struct arm_unwind_table_edit *next;
2511 arm_unwind_table_edit;
2513 typedef struct _arm_elf_section_data
2515 /* Information about mapping symbols. */
2516 struct bfd_elf_section_data elf;
2517 unsigned int mapcount;
2518 unsigned int mapsize;
2519 elf32_arm_section_map *map;
2520 /* Information about CPU errata. */
2521 unsigned int erratumcount;
2522 elf32_vfp11_erratum_list *erratumlist;
2523 /* Information about unwind tables. */
2526 /* Unwind info attached to a text section. */
2529 asection *arm_exidx_sec;
2532 /* Unwind info attached to an .ARM.exidx section. */
2535 arm_unwind_table_edit *unwind_edit_list;
2536 arm_unwind_table_edit *unwind_edit_tail;
2540 _arm_elf_section_data;
2542 #define elf32_arm_section_data(sec) \
2543 ((_arm_elf_section_data *) elf_section_data (sec))
2545 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2546 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2547 so may be created multiple times: we use an array of these entries whilst
2548 relaxing which we can refresh easily, then create stubs for each potentially
2549 erratum-triggering instruction once we've settled on a solution. */
2551 struct a8_erratum_fix {
2556 unsigned long orig_insn;
2558 enum elf32_arm_stub_type stub_type;
2559 enum arm_st_branch_type branch_type;
2562 /* A table of relocs applied to branches which might trigger Cortex-A8
2565 struct a8_erratum_reloc {
2567 bfd_vma destination;
2568 struct elf32_arm_link_hash_entry *hash;
2569 const char *sym_name;
2570 unsigned int r_type;
2571 enum arm_st_branch_type branch_type;
2572 bfd_boolean non_a8_stub;
2575 /* The size of the thread control block. */
2578 /* ARM-specific information about a PLT entry, over and above the usual
2580 struct arm_plt_info {
2581 /* We reference count Thumb references to a PLT entry separately,
2582 so that we can emit the Thumb trampoline only if needed. */
2583 bfd_signed_vma thumb_refcount;
2585 /* Some references from Thumb code may be eliminated by BL->BLX
2586 conversion, so record them separately. */
2587 bfd_signed_vma maybe_thumb_refcount;
2589 /* How many of the recorded PLT accesses were from non-call relocations.
2590 This information is useful when deciding whether anything takes the
2591 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
2592 non-call references to the function should resolve directly to the
2593 real runtime target. */
2594 unsigned int noncall_refcount;
2596 /* Since PLT entries have variable size if the Thumb prologue is
2597 used, we need to record the index into .got.plt instead of
2598 recomputing it from the PLT offset. */
2599 bfd_signed_vma got_offset;
2602 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
2603 struct arm_local_iplt_info {
2604 /* The information that is usually found in the generic ELF part of
2605 the hash table entry. */
2606 union gotplt_union root;
2608 /* The information that is usually found in the ARM-specific part of
2609 the hash table entry. */
2610 struct arm_plt_info arm;
2612 /* A list of all potential dynamic relocations against this symbol. */
2613 struct elf_dyn_relocs *dyn_relocs;
2616 struct elf_arm_obj_tdata
2618 struct elf_obj_tdata root;
2620 /* tls_type for each local got entry. */
2621 char *local_got_tls_type;
2623 /* GOTPLT entries for TLS descriptors. */
2624 bfd_vma *local_tlsdesc_gotent;
2626 /* Information for local symbols that need entries in .iplt. */
2627 struct arm_local_iplt_info **local_iplt;
2629 /* Zero to warn when linking objects with incompatible enum sizes. */
2630 int no_enum_size_warning;
2632 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2633 int no_wchar_size_warning;
2636 #define elf_arm_tdata(bfd) \
2637 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2639 #define elf32_arm_local_got_tls_type(bfd) \
2640 (elf_arm_tdata (bfd)->local_got_tls_type)
2642 #define elf32_arm_local_tlsdesc_gotent(bfd) \
2643 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
2645 #define elf32_arm_local_iplt(bfd) \
2646 (elf_arm_tdata (bfd)->local_iplt)
2648 #define is_arm_elf(bfd) \
2649 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2650 && elf_tdata (bfd) != NULL \
2651 && elf_object_id (bfd) == ARM_ELF_DATA)
2654 elf32_arm_mkobject (bfd *abfd)
2656 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2660 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2662 /* Arm ELF linker hash entry. */
2663 struct elf32_arm_link_hash_entry
2665 struct elf_link_hash_entry root;
2667 /* Track dynamic relocs copied for this symbol. */
2668 struct elf_dyn_relocs *dyn_relocs;
2670 /* ARM-specific PLT information. */
2671 struct arm_plt_info plt;
2673 #define GOT_UNKNOWN 0
2674 #define GOT_NORMAL 1
2675 #define GOT_TLS_GD 2
2676 #define GOT_TLS_IE 4
2677 #define GOT_TLS_GDESC 8
2678 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
2679 unsigned int tls_type : 8;
2681 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
2682 unsigned int is_iplt : 1;
2684 unsigned int unused : 23;
2686 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
2687 starting at the end of the jump table. */
2688 bfd_vma tlsdesc_got;
2690 /* The symbol marking the real symbol location for exported thumb
2691 symbols with Arm stubs. */
2692 struct elf_link_hash_entry *export_glue;
2694 /* A pointer to the most recently used stub hash entry against this
2696 struct elf32_arm_stub_hash_entry *stub_cache;
2699 /* Traverse an arm ELF linker hash table. */
2700 #define elf32_arm_link_hash_traverse(table, func, info) \
2701 (elf_link_hash_traverse \
2703 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2706 /* Get the ARM elf linker hash table from a link_info structure. */
2707 #define elf32_arm_hash_table(info) \
2708 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
2709 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
2711 #define arm_stub_hash_lookup(table, string, create, copy) \
2712 ((struct elf32_arm_stub_hash_entry *) \
2713 bfd_hash_lookup ((table), (string), (create), (copy)))
2715 /* Array to keep track of which stub sections have been created, and
2716 information on stub grouping. */
2719 /* This is the section to which stubs in the group will be
2722 /* The stub section. */
2726 #define elf32_arm_compute_jump_table_size(htab) \
2727 ((htab)->next_tls_desc_index * 4)
2729 /* ARM ELF linker hash table. */
2730 struct elf32_arm_link_hash_table
2732 /* The main hash table. */
2733 struct elf_link_hash_table root;
2735 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2736 bfd_size_type thumb_glue_size;
2738 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2739 bfd_size_type arm_glue_size;
2741 /* The size in bytes of section containing the ARMv4 BX veneers. */
2742 bfd_size_type bx_glue_size;
2744 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2745 veneer has been populated. */
2746 bfd_vma bx_glue_offset[15];
2748 /* The size in bytes of the section containing glue for VFP11 erratum
2750 bfd_size_type vfp11_erratum_glue_size;
2752 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
2753 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
2754 elf32_arm_write_section(). */
2755 struct a8_erratum_fix *a8_erratum_fixes;
2756 unsigned int num_a8_erratum_fixes;
2758 /* An arbitrary input BFD chosen to hold the glue sections. */
2759 bfd * bfd_of_glue_owner;
2761 /* Nonzero to output a BE8 image. */
2764 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2765 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2768 /* The relocation to use for R_ARM_TARGET2 relocations. */
2771 /* 0 = Ignore R_ARM_V4BX.
2772 1 = Convert BX to MOV PC.
2773 2 = Generate v4 interworing stubs. */
2776 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
2779 /* Whether we should fix the ARM1176 BLX immediate issue. */
2782 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2785 /* What sort of code sequences we should look for which may trigger the
2786 VFP11 denorm erratum. */
2787 bfd_arm_vfp11_fix vfp11_fix;
2789 /* Global counter for the number of fixes we have emitted. */
2790 int num_vfp11_fixes;
2792 /* Nonzero to force PIC branch veneers. */
2795 /* The number of bytes in the initial entry in the PLT. */
2796 bfd_size_type plt_header_size;
2798 /* The number of bytes in the subsequent PLT etries. */
2799 bfd_size_type plt_entry_size;
2801 /* True if the target system is VxWorks. */
2804 /* True if the target system is Symbian OS. */
2807 /* True if the target uses REL relocations. */
2810 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
2811 bfd_vma next_tls_desc_index;
2813 /* How many R_ARM_TLS_DESC relocations were generated so far. */
2814 bfd_vma num_tls_desc;
2816 /* Short-cuts to get to dynamic linker sections. */
2820 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2823 /* The offset into splt of the PLT entry for the TLS descriptor
2824 resolver. Special values are 0, if not necessary (or not found
2825 to be necessary yet), and -1 if needed but not determined
2827 bfd_vma dt_tlsdesc_plt;
2829 /* The offset into sgot of the GOT entry used by the PLT entry
2831 bfd_vma dt_tlsdesc_got;
2833 /* Offset in .plt section of tls_arm_trampoline. */
2834 bfd_vma tls_trampoline;
2836 /* Data for R_ARM_TLS_LDM32 relocations. */
2839 bfd_signed_vma refcount;
2843 /* Small local sym cache. */
2844 struct sym_cache sym_cache;
2846 /* For convenience in allocate_dynrelocs. */
2849 /* The amount of space used by the reserved portion of the sgotplt
2850 section, plus whatever space is used by the jump slots. */
2851 bfd_vma sgotplt_jump_table_size;
2853 /* The stub hash table. */
2854 struct bfd_hash_table stub_hash_table;
2856 /* Linker stub bfd. */
2859 /* Linker call-backs. */
2860 asection * (*add_stub_section) (const char *, asection *);
2861 void (*layout_sections_again) (void);
2863 /* Array to keep track of which stub sections have been created, and
2864 information on stub grouping. */
2865 struct map_stub *stub_group;
2867 /* Number of elements in stub_group. */
2870 /* Assorted information used by elf32_arm_size_stubs. */
2871 unsigned int bfd_count;
2873 asection **input_list;
2876 /* Create an entry in an ARM ELF linker hash table. */
2878 static struct bfd_hash_entry *
2879 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2880 struct bfd_hash_table * table,
2881 const char * string)
2883 struct elf32_arm_link_hash_entry * ret =
2884 (struct elf32_arm_link_hash_entry *) entry;
2886 /* Allocate the structure if it has not already been allocated by a
2889 ret = (struct elf32_arm_link_hash_entry *)
2890 bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2892 return (struct bfd_hash_entry *) ret;
2894 /* Call the allocation method of the superclass. */
2895 ret = ((struct elf32_arm_link_hash_entry *)
2896 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2900 ret->dyn_relocs = NULL;
2901 ret->tls_type = GOT_UNKNOWN;
2902 ret->tlsdesc_got = (bfd_vma) -1;
2903 ret->plt.thumb_refcount = 0;
2904 ret->plt.maybe_thumb_refcount = 0;
2905 ret->plt.noncall_refcount = 0;
2906 ret->plt.got_offset = -1;
2907 ret->is_iplt = FALSE;
2908 ret->export_glue = NULL;
2910 ret->stub_cache = NULL;
2913 return (struct bfd_hash_entry *) ret;
2916 /* Ensure that we have allocated bookkeeping structures for ABFD's local
2920 elf32_arm_allocate_local_sym_info (bfd *abfd)
2922 if (elf_local_got_refcounts (abfd) == NULL)
2924 bfd_size_type num_syms;
2928 num_syms = elf_tdata (abfd)->symtab_hdr.sh_info;
2929 size = num_syms * (sizeof (bfd_signed_vma)
2930 + sizeof (struct arm_local_iplt_info *)
2933 data = bfd_zalloc (abfd, size);
2937 elf_local_got_refcounts (abfd) = (bfd_signed_vma *) data;
2938 data += num_syms * sizeof (bfd_signed_vma);
2940 elf32_arm_local_iplt (abfd) = (struct arm_local_iplt_info **) data;
2941 data += num_syms * sizeof (struct arm_local_iplt_info *);
2943 elf32_arm_local_tlsdesc_gotent (abfd) = (bfd_vma *) data;
2944 data += num_syms * sizeof (bfd_vma);
2946 elf32_arm_local_got_tls_type (abfd) = data;
2951 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
2952 to input bfd ABFD. Create the information if it doesn't already exist.
2953 Return null if an allocation fails. */
2955 static struct arm_local_iplt_info *
2956 elf32_arm_create_local_iplt (bfd *abfd, unsigned long r_symndx)
2958 struct arm_local_iplt_info **ptr;
2960 if (!elf32_arm_allocate_local_sym_info (abfd))
2963 BFD_ASSERT (r_symndx < elf_tdata (abfd)->symtab_hdr.sh_info);
2964 ptr = &elf32_arm_local_iplt (abfd)[r_symndx];
2966 *ptr = bfd_zalloc (abfd, sizeof (**ptr));
2970 /* Try to obtain PLT information for the symbol with index R_SYMNDX
2971 in ABFD's symbol table. If the symbol is global, H points to its
2972 hash table entry, otherwise H is null.
2974 Return true if the symbol does have PLT information. When returning
2975 true, point *ROOT_PLT at the target-independent reference count/offset
2976 union and *ARM_PLT at the ARM-specific information. */
2979 elf32_arm_get_plt_info (bfd *abfd, struct elf32_arm_link_hash_entry *h,
2980 unsigned long r_symndx, union gotplt_union **root_plt,
2981 struct arm_plt_info **arm_plt)
2983 struct arm_local_iplt_info *local_iplt;
2987 *root_plt = &h->root.plt;
2992 if (elf32_arm_local_iplt (abfd) == NULL)
2995 local_iplt = elf32_arm_local_iplt (abfd)[r_symndx];
2996 if (local_iplt == NULL)
2999 *root_plt = &local_iplt->root;
3000 *arm_plt = &local_iplt->arm;
3004 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3008 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info *info,
3009 struct arm_plt_info *arm_plt)
3011 struct elf32_arm_link_hash_table *htab;
3013 htab = elf32_arm_hash_table (info);
3014 return (arm_plt->thumb_refcount != 0
3015 || (!htab->use_blx && arm_plt->maybe_thumb_refcount != 0));
3018 /* Return a pointer to the head of the dynamic reloc list that should
3019 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3020 ABFD's symbol table. Return null if an error occurs. */
3022 static struct elf_dyn_relocs **
3023 elf32_arm_get_local_dynreloc_list (bfd *abfd, unsigned long r_symndx,
3024 Elf_Internal_Sym *isym)
3026 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
3028 struct arm_local_iplt_info *local_iplt;
3030 local_iplt = elf32_arm_create_local_iplt (abfd, r_symndx);
3031 if (local_iplt == NULL)
3033 return &local_iplt->dyn_relocs;
3037 /* Track dynamic relocs needed for local syms too.
3038 We really need local syms available to do this
3043 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
3047 vpp = &elf_section_data (s)->local_dynrel;
3048 return (struct elf_dyn_relocs **) vpp;
3052 /* Initialize an entry in the stub hash table. */
3054 static struct bfd_hash_entry *
3055 stub_hash_newfunc (struct bfd_hash_entry *entry,
3056 struct bfd_hash_table *table,
3059 /* Allocate the structure if it has not already been allocated by a
3063 entry = (struct bfd_hash_entry *)
3064 bfd_hash_allocate (table, sizeof (struct elf32_arm_stub_hash_entry));
3069 /* Call the allocation method of the superclass. */
3070 entry = bfd_hash_newfunc (entry, table, string);
3073 struct elf32_arm_stub_hash_entry *eh;
3075 /* Initialize the local fields. */
3076 eh = (struct elf32_arm_stub_hash_entry *) entry;
3077 eh->stub_sec = NULL;
3078 eh->stub_offset = 0;
3079 eh->target_value = 0;
3080 eh->target_section = NULL;
3081 eh->target_addend = 0;
3083 eh->stub_type = arm_stub_none;
3085 eh->stub_template = NULL;
3086 eh->stub_template_size = 0;
3089 eh->output_name = NULL;
3095 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3096 shortcuts to them in our hash table. */
3099 create_got_section (bfd *dynobj, struct bfd_link_info *info)
3101 struct elf32_arm_link_hash_table *htab;
3103 htab = elf32_arm_hash_table (info);
3107 /* BPABI objects never have a GOT, or associated sections. */
3108 if (htab->symbian_p)
3111 if (! _bfd_elf_create_got_section (dynobj, info))
3117 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3120 create_ifunc_sections (struct bfd_link_info *info)
3122 struct elf32_arm_link_hash_table *htab;
3123 const struct elf_backend_data *bed;
3128 htab = elf32_arm_hash_table (info);
3129 dynobj = htab->root.dynobj;
3130 bed = get_elf_backend_data (dynobj);
3131 flags = bed->dynamic_sec_flags;
3133 if (htab->root.iplt == NULL)
3135 s = bfd_make_section_with_flags (dynobj, ".iplt",
3136 flags | SEC_READONLY | SEC_CODE);
3138 || !bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3140 htab->root.iplt = s;
3143 if (htab->root.irelplt == NULL)
3145 s = bfd_make_section_with_flags (dynobj, RELOC_SECTION (htab, ".iplt"),
3146 flags | SEC_READONLY);
3148 || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
3150 htab->root.irelplt = s;
3153 if (htab->root.igotplt == NULL)
3155 s = bfd_make_section_with_flags (dynobj, ".igot.plt", flags);
3157 || !bfd_set_section_alignment (dynobj, s, bed->s->log_file_align))
3159 htab->root.igotplt = s;
3164 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3165 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3169 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
3171 struct elf32_arm_link_hash_table *htab;
3173 htab = elf32_arm_hash_table (info);
3177 if (!htab->root.sgot && !create_got_section (dynobj, info))
3180 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
3183 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
3185 htab->srelbss = bfd_get_section_by_name (dynobj,
3186 RELOC_SECTION (htab, ".bss"));
3188 if (htab->vxworks_p)
3190 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
3195 htab->plt_header_size = 0;
3196 htab->plt_entry_size
3197 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
3201 htab->plt_header_size
3202 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
3203 htab->plt_entry_size
3204 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
3208 if (!htab->root.splt
3209 || !htab->root.srelplt
3211 || (!info->shared && !htab->srelbss))
3217 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3220 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
3221 struct elf_link_hash_entry *dir,
3222 struct elf_link_hash_entry *ind)
3224 struct elf32_arm_link_hash_entry *edir, *eind;
3226 edir = (struct elf32_arm_link_hash_entry *) dir;
3227 eind = (struct elf32_arm_link_hash_entry *) ind;
3229 if (eind->dyn_relocs != NULL)
3231 if (edir->dyn_relocs != NULL)
3233 struct elf_dyn_relocs **pp;
3234 struct elf_dyn_relocs *p;
3236 /* Add reloc counts against the indirect sym to the direct sym
3237 list. Merge any entries against the same section. */
3238 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3240 struct elf_dyn_relocs *q;
3242 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3243 if (q->sec == p->sec)
3245 q->pc_count += p->pc_count;
3246 q->count += p->count;
3253 *pp = edir->dyn_relocs;
3256 edir->dyn_relocs = eind->dyn_relocs;
3257 eind->dyn_relocs = NULL;
3260 if (ind->root.type == bfd_link_hash_indirect)
3262 /* Copy over PLT info. */
3263 edir->plt.thumb_refcount += eind->plt.thumb_refcount;
3264 eind->plt.thumb_refcount = 0;
3265 edir->plt.maybe_thumb_refcount += eind->plt.maybe_thumb_refcount;
3266 eind->plt.maybe_thumb_refcount = 0;
3267 edir->plt.noncall_refcount += eind->plt.noncall_refcount;
3268 eind->plt.noncall_refcount = 0;
3270 /* We should only allocate a function to .iplt once the final
3271 symbol information is known. */
3272 BFD_ASSERT (!eind->is_iplt);
3274 if (dir->got.refcount <= 0)
3276 edir->tls_type = eind->tls_type;
3277 eind->tls_type = GOT_UNKNOWN;
3281 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3284 /* Create an ARM elf linker hash table. */
3286 static struct bfd_link_hash_table *
3287 elf32_arm_link_hash_table_create (bfd *abfd)
3289 struct elf32_arm_link_hash_table *ret;
3290 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
3292 ret = (struct elf32_arm_link_hash_table *) bfd_malloc (amt);
3296 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
3297 elf32_arm_link_hash_newfunc,
3298 sizeof (struct elf32_arm_link_hash_entry),
3305 ret->sdynbss = NULL;
3306 ret->srelbss = NULL;
3307 ret->srelplt2 = NULL;
3308 ret->dt_tlsdesc_plt = 0;
3309 ret->dt_tlsdesc_got = 0;
3310 ret->tls_trampoline = 0;
3311 ret->next_tls_desc_index = 0;
3312 ret->num_tls_desc = 0;
3313 ret->thumb_glue_size = 0;
3314 ret->arm_glue_size = 0;
3315 ret->bx_glue_size = 0;
3316 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
3317 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3318 ret->vfp11_erratum_glue_size = 0;
3319 ret->num_vfp11_fixes = 0;
3320 ret->fix_cortex_a8 = 0;
3321 ret->fix_arm1176 = 0;
3322 ret->bfd_of_glue_owner = NULL;
3323 ret->byteswap_code = 0;
3324 ret->target1_is_rel = 0;
3325 ret->target2_reloc = R_ARM_NONE;
3326 #ifdef FOUR_WORD_PLT
3327 ret->plt_header_size = 16;
3328 ret->plt_entry_size = 16;
3330 ret->plt_header_size = 20;
3331 ret->plt_entry_size = 12;
3338 ret->sym_cache.abfd = NULL;
3340 ret->tls_ldm_got.refcount = 0;
3341 ret->stub_bfd = NULL;
3342 ret->add_stub_section = NULL;
3343 ret->layout_sections_again = NULL;
3344 ret->stub_group = NULL;
3348 ret->input_list = NULL;
3350 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
3351 sizeof (struct elf32_arm_stub_hash_entry)))
3357 return &ret->root.root;
3360 /* Free the derived linker hash table. */
3363 elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
3365 struct elf32_arm_link_hash_table *ret
3366 = (struct elf32_arm_link_hash_table *) hash;
3368 bfd_hash_table_free (&ret->stub_hash_table);
3369 _bfd_generic_link_hash_table_free (hash);
3372 /* Determine if we're dealing with a Thumb only architecture. */
3375 using_thumb_only (struct elf32_arm_link_hash_table *globals)
3377 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3381 if (arch == TAG_CPU_ARCH_V6_M || arch == TAG_CPU_ARCH_V6S_M)
3384 if (arch != TAG_CPU_ARCH_V7 && arch != TAG_CPU_ARCH_V7E_M)
3387 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3388 Tag_CPU_arch_profile);
3390 return profile == 'M';
3393 /* Determine if we're dealing with a Thumb-2 object. */
3396 using_thumb2 (struct elf32_arm_link_hash_table *globals)
3398 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3400 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
3403 /* Determine what kind of NOPs are available. */
3406 arch_has_arm_nop (struct elf32_arm_link_hash_table *globals)
3408 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3410 return arch == TAG_CPU_ARCH_V6T2
3411 || arch == TAG_CPU_ARCH_V6K
3412 || arch == TAG_CPU_ARCH_V7
3413 || arch == TAG_CPU_ARCH_V7E_M;
3417 arch_has_thumb2_nop (struct elf32_arm_link_hash_table *globals)
3419 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3421 return (arch == TAG_CPU_ARCH_V6T2 || arch == TAG_CPU_ARCH_V7
3422 || arch == TAG_CPU_ARCH_V7E_M);
3426 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
3430 case arm_stub_long_branch_thumb_only:
3431 case arm_stub_long_branch_v4t_thumb_arm:
3432 case arm_stub_short_branch_v4t_thumb_arm:
3433 case arm_stub_long_branch_v4t_thumb_arm_pic:
3434 case arm_stub_long_branch_v4t_thumb_tls_pic:
3435 case arm_stub_long_branch_thumb_only_pic:
3446 /* Determine the type of stub needed, if any, for a call. */
3448 static enum elf32_arm_stub_type
3449 arm_type_of_stub (struct bfd_link_info *info,
3450 asection *input_sec,
3451 const Elf_Internal_Rela *rel,
3452 unsigned char st_type,
3453 enum arm_st_branch_type *actual_branch_type,
3454 struct elf32_arm_link_hash_entry *hash,
3455 bfd_vma destination,
3461 bfd_signed_vma branch_offset;
3462 unsigned int r_type;
3463 struct elf32_arm_link_hash_table * globals;
3466 enum elf32_arm_stub_type stub_type = arm_stub_none;
3468 enum arm_st_branch_type branch_type = *actual_branch_type;
3469 union gotplt_union *root_plt;
3470 struct arm_plt_info *arm_plt;
3472 if (branch_type == ST_BRANCH_LONG)
3475 globals = elf32_arm_hash_table (info);
3476 if (globals == NULL)
3479 thumb_only = using_thumb_only (globals);
3481 thumb2 = using_thumb2 (globals);
3483 /* Determine where the call point is. */
3484 location = (input_sec->output_offset
3485 + input_sec->output_section->vma
3488 r_type = ELF32_R_TYPE (rel->r_info);
3490 /* For TLS call relocs, it is the caller's responsibility to provide
3491 the address of the appropriate trampoline. */
3492 if (r_type != R_ARM_TLS_CALL
3493 && r_type != R_ARM_THM_TLS_CALL
3494 && elf32_arm_get_plt_info (input_bfd, hash, ELF32_R_SYM (rel->r_info),
3495 &root_plt, &arm_plt)
3496 && root_plt->offset != (bfd_vma) -1)
3500 if (hash == NULL || hash->is_iplt)
3501 splt = globals->root.iplt;
3503 splt = globals->root.splt;
3508 /* Note when dealing with PLT entries: the main PLT stub is in
3509 ARM mode, so if the branch is in Thumb mode, another
3510 Thumb->ARM stub will be inserted later just before the ARM
3511 PLT stub. We don't take this extra distance into account
3512 here, because if a long branch stub is needed, we'll add a
3513 Thumb->Arm one and branch directly to the ARM PLT entry
3514 because it avoids spreading offset corrections in several
3517 destination = (splt->output_section->vma
3518 + splt->output_offset
3519 + root_plt->offset);
3521 branch_type = ST_BRANCH_TO_ARM;
3524 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
3525 BFD_ASSERT (st_type != STT_GNU_IFUNC);
3527 branch_offset = (bfd_signed_vma)(destination - location);
3529 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24
3530 || r_type == R_ARM_THM_TLS_CALL)
3532 /* Handle cases where:
3533 - this call goes too far (different Thumb/Thumb2 max
3535 - it's a Thumb->Arm call and blx is not available, or it's a
3536 Thumb->Arm branch (not bl). A stub is needed in this case,
3537 but only if this call is not through a PLT entry. Indeed,
3538 PLT stubs handle mode switching already.
3541 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
3542 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
3544 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
3545 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
3546 || (branch_type == ST_BRANCH_TO_ARM
3547 && (((r_type == R_ARM_THM_CALL
3548 || r_type == R_ARM_THM_TLS_CALL) && !globals->use_blx)
3549 || (r_type == R_ARM_THM_JUMP24))
3552 if (branch_type == ST_BRANCH_TO_THUMB)
3554 /* Thumb to thumb. */
3557 stub_type = (info->shared | globals->pic_veneer)
3559 ? ((globals->use_blx
3560 && (r_type ==R_ARM_THM_CALL))
3561 /* V5T and above. Stub starts with ARM code, so
3562 we must be able to switch mode before
3563 reaching it, which is only possible for 'bl'
3564 (ie R_ARM_THM_CALL relocation). */
3565 ? arm_stub_long_branch_any_thumb_pic
3566 /* On V4T, use Thumb code only. */
3567 : arm_stub_long_branch_v4t_thumb_thumb_pic)
3569 /* non-PIC stubs. */
3570 : ((globals->use_blx
3571 && (r_type ==R_ARM_THM_CALL))
3572 /* V5T and above. */
3573 ? arm_stub_long_branch_any_any
3575 : arm_stub_long_branch_v4t_thumb_thumb);
3579 stub_type = (info->shared | globals->pic_veneer)
3581 ? arm_stub_long_branch_thumb_only_pic
3583 : arm_stub_long_branch_thumb_only;
3590 && sym_sec->owner != NULL
3591 && !INTERWORK_FLAG (sym_sec->owner))
3593 (*_bfd_error_handler)
3594 (_("%B(%s): warning: interworking not enabled.\n"
3595 " first occurrence: %B: Thumb call to ARM"),
3596 sym_sec->owner, input_bfd, name);
3600 (info->shared | globals->pic_veneer)
3602 ? (r_type == R_ARM_THM_TLS_CALL
3604 ? (globals->use_blx ? arm_stub_long_branch_any_tls_pic
3605 : arm_stub_long_branch_v4t_thumb_tls_pic)
3606 : ((globals->use_blx && r_type == R_ARM_THM_CALL)
3607 /* V5T PIC and above. */
3608 ? arm_stub_long_branch_any_arm_pic
3610 : arm_stub_long_branch_v4t_thumb_arm_pic))
3612 /* non-PIC stubs. */
3613 : ((globals->use_blx && r_type == R_ARM_THM_CALL)
3614 /* V5T and above. */
3615 ? arm_stub_long_branch_any_any
3617 : arm_stub_long_branch_v4t_thumb_arm);
3619 /* Handle v4t short branches. */
3620 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
3621 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
3622 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
3623 stub_type = arm_stub_short_branch_v4t_thumb_arm;
3627 else if (r_type == R_ARM_CALL
3628 || r_type == R_ARM_JUMP24
3629 || r_type == R_ARM_PLT32
3630 || r_type == R_ARM_TLS_CALL)
3632 if (branch_type == ST_BRANCH_TO_THUMB)
3637 && sym_sec->owner != NULL
3638 && !INTERWORK_FLAG (sym_sec->owner))
3640 (*_bfd_error_handler)
3641 (_("%B(%s): warning: interworking not enabled.\n"
3642 " first occurrence: %B: ARM call to Thumb"),
3643 sym_sec->owner, input_bfd, name);
3646 /* We have an extra 2-bytes reach because of
3647 the mode change (bit 24 (H) of BLX encoding). */
3648 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
3649 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
3650 || (r_type == R_ARM_CALL && !globals->use_blx)
3651 || (r_type == R_ARM_JUMP24)
3652 || (r_type == R_ARM_PLT32))
3654 stub_type = (info->shared | globals->pic_veneer)
3656 ? ((globals->use_blx)
3657 /* V5T and above. */
3658 ? arm_stub_long_branch_any_thumb_pic
3660 : arm_stub_long_branch_v4t_arm_thumb_pic)
3662 /* non-PIC stubs. */
3663 : ((globals->use_blx)
3664 /* V5T and above. */
3665 ? arm_stub_long_branch_any_any
3667 : arm_stub_long_branch_v4t_arm_thumb);
3673 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3674 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3677 (info->shared | globals->pic_veneer)
3679 ? (r_type == R_ARM_TLS_CALL
3681 ? arm_stub_long_branch_any_tls_pic
3682 : arm_stub_long_branch_any_arm_pic)
3683 /* non-PIC stubs. */
3684 : arm_stub_long_branch_any_any;
3689 /* If a stub is needed, record the actual destination type. */
3690 if (stub_type != arm_stub_none)
3691 *actual_branch_type = branch_type;
3696 /* Build a name for an entry in the stub hash table. */
3699 elf32_arm_stub_name (const asection *input_section,
3700 const asection *sym_sec,
3701 const struct elf32_arm_link_hash_entry *hash,
3702 const Elf_Internal_Rela *rel,
3703 enum elf32_arm_stub_type stub_type)
3710 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1 + 2 + 1;
3711 stub_name = (char *) bfd_malloc (len);
3712 if (stub_name != NULL)
3713 sprintf (stub_name, "%08x_%s+%x_%d",
3714 input_section->id & 0xffffffff,
3715 hash->root.root.root.string,
3716 (int) rel->r_addend & 0xffffffff,
3721 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
3722 stub_name = (char *) bfd_malloc (len);
3723 if (stub_name != NULL)
3724 sprintf (stub_name, "%08x_%x:%x+%x_%d",
3725 input_section->id & 0xffffffff,
3726 sym_sec->id & 0xffffffff,
3727 ELF32_R_TYPE (rel->r_info) == R_ARM_TLS_CALL
3728 || ELF32_R_TYPE (rel->r_info) == R_ARM_THM_TLS_CALL
3729 ? 0 : (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3730 (int) rel->r_addend & 0xffffffff,
3737 /* Look up an entry in the stub hash. Stub entries are cached because
3738 creating the stub name takes a bit of time. */
3740 static struct elf32_arm_stub_hash_entry *
3741 elf32_arm_get_stub_entry (const asection *input_section,
3742 const asection *sym_sec,
3743 struct elf_link_hash_entry *hash,
3744 const Elf_Internal_Rela *rel,
3745 struct elf32_arm_link_hash_table *htab,
3746 enum elf32_arm_stub_type stub_type)
3748 struct elf32_arm_stub_hash_entry *stub_entry;
3749 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3750 const asection *id_sec;
3752 if ((input_section->flags & SEC_CODE) == 0)
3755 /* If this input section is part of a group of sections sharing one
3756 stub section, then use the id of the first section in the group.
3757 Stub names need to include a section id, as there may well be
3758 more than one stub used to reach say, printf, and we need to
3759 distinguish between them. */
3760 id_sec = htab->stub_group[input_section->id].link_sec;
3762 if (h != NULL && h->stub_cache != NULL
3763 && h->stub_cache->h == h
3764 && h->stub_cache->id_sec == id_sec
3765 && h->stub_cache->stub_type == stub_type)
3767 stub_entry = h->stub_cache;
3773 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel, stub_type);
3774 if (stub_name == NULL)
3777 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3778 stub_name, FALSE, FALSE);
3780 h->stub_cache = stub_entry;
3788 /* Find or create a stub section. Returns a pointer to the stub section, and
3789 the section to which the stub section will be attached (in *LINK_SEC_P).
3790 LINK_SEC_P may be NULL. */
3793 elf32_arm_create_or_find_stub_sec (asection **link_sec_p, asection *section,
3794 struct elf32_arm_link_hash_table *htab)
3799 link_sec = htab->stub_group[section->id].link_sec;
3800 stub_sec = htab->stub_group[section->id].stub_sec;
3801 if (stub_sec == NULL)
3803 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3804 if (stub_sec == NULL)
3810 namelen = strlen (link_sec->name);
3811 len = namelen + sizeof (STUB_SUFFIX);
3812 s_name = (char *) bfd_alloc (htab->stub_bfd, len);
3816 memcpy (s_name, link_sec->name, namelen);
3817 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3818 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3819 if (stub_sec == NULL)
3821 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3823 htab->stub_group[section->id].stub_sec = stub_sec;
3827 *link_sec_p = link_sec;
3832 /* Add a new stub entry to the stub hash. Not all fields of the new
3833 stub entry are initialised. */
3835 static struct elf32_arm_stub_hash_entry *
3836 elf32_arm_add_stub (const char *stub_name,
3838 struct elf32_arm_link_hash_table *htab)
3842 struct elf32_arm_stub_hash_entry *stub_entry;
3844 stub_sec = elf32_arm_create_or_find_stub_sec (&link_sec, section, htab);
3845 if (stub_sec == NULL)
3848 /* Enter this entry into the linker stub hash table. */
3849 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3851 if (stub_entry == NULL)
3853 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3859 stub_entry->stub_sec = stub_sec;
3860 stub_entry->stub_offset = 0;
3861 stub_entry->id_sec = link_sec;
3866 /* Store an Arm insn into an output section not processed by
3867 elf32_arm_write_section. */
3870 put_arm_insn (struct elf32_arm_link_hash_table * htab,
3871 bfd * output_bfd, bfd_vma val, void * ptr)
3873 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3874 bfd_putl32 (val, ptr);
3876 bfd_putb32 (val, ptr);
3879 /* Store a 16-bit Thumb insn into an output section not processed by
3880 elf32_arm_write_section. */
3883 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3884 bfd * output_bfd, bfd_vma val, void * ptr)
3886 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3887 bfd_putl16 (val, ptr);
3889 bfd_putb16 (val, ptr);
3892 /* If it's possible to change R_TYPE to a more efficient access
3893 model, return the new reloc type. */
3896 elf32_arm_tls_transition (struct bfd_link_info *info, int r_type,
3897 struct elf_link_hash_entry *h)
3899 int is_local = (h == NULL);
3901 if (info->shared || (h && h->root.type == bfd_link_hash_undefweak))
3904 /* We do not support relaxations for Old TLS models. */
3907 case R_ARM_TLS_GOTDESC:
3908 case R_ARM_TLS_CALL:
3909 case R_ARM_THM_TLS_CALL:
3910 case R_ARM_TLS_DESCSEQ:
3911 case R_ARM_THM_TLS_DESCSEQ:
3912 return is_local ? R_ARM_TLS_LE32 : R_ARM_TLS_IE32;
3918 static bfd_reloc_status_type elf32_arm_final_link_relocate
3919 (reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
3920 Elf_Internal_Rela *, bfd_vma, struct bfd_link_info *, asection *,
3921 const char *, unsigned char, enum arm_st_branch_type,
3922 struct elf_link_hash_entry *, bfd_boolean *, char **);
3925 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type)
3929 case arm_stub_a8_veneer_b_cond:
3930 case arm_stub_a8_veneer_b:
3931 case arm_stub_a8_veneer_bl:
3934 case arm_stub_long_branch_any_any:
3935 case arm_stub_long_branch_v4t_arm_thumb:
3936 case arm_stub_long_branch_thumb_only:
3937 case arm_stub_long_branch_v4t_thumb_thumb:
3938 case arm_stub_long_branch_v4t_thumb_arm:
3939 case arm_stub_short_branch_v4t_thumb_arm:
3940 case arm_stub_long_branch_any_arm_pic:
3941 case arm_stub_long_branch_any_thumb_pic:
3942 case arm_stub_long_branch_v4t_thumb_thumb_pic:
3943 case arm_stub_long_branch_v4t_arm_thumb_pic:
3944 case arm_stub_long_branch_v4t_thumb_arm_pic:
3945 case arm_stub_long_branch_thumb_only_pic:
3946 case arm_stub_long_branch_any_tls_pic:
3947 case arm_stub_long_branch_v4t_thumb_tls_pic:
3948 case arm_stub_a8_veneer_blx:
3952 abort (); /* Should be unreachable. */
3957 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3961 struct elf32_arm_stub_hash_entry *stub_entry;
3962 struct elf32_arm_link_hash_table *globals;
3963 struct bfd_link_info *info;
3970 const insn_sequence *template_sequence;
3972 int stub_reloc_idx[MAXRELOCS] = {-1, -1};
3973 int stub_reloc_offset[MAXRELOCS] = {0, 0};
3976 /* Massage our args to the form they really have. */
3977 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3978 info = (struct bfd_link_info *) in_arg;
3980 globals = elf32_arm_hash_table (info);
3981 if (globals == NULL)
3984 stub_sec = stub_entry->stub_sec;
3986 if ((globals->fix_cortex_a8 < 0)
3987 != (arm_stub_required_alignment (stub_entry->stub_type) == 2))
3988 /* We have to do less-strictly-aligned fixes last. */
3991 /* Make a note of the offset within the stubs for this entry. */
3992 stub_entry->stub_offset = stub_sec->size;
3993 loc = stub_sec->contents + stub_entry->stub_offset;
3995 stub_bfd = stub_sec->owner;
3997 /* This is the address of the stub destination. */
3998 sym_value = (stub_entry->target_value
3999 + stub_entry->target_section->output_offset
4000 + stub_entry->target_section->output_section->vma);
4002 template_sequence = stub_entry->stub_template;
4003 template_size = stub_entry->stub_template_size;
4006 for (i = 0; i < template_size; i++)
4008 switch (template_sequence[i].type)
4012 bfd_vma data = (bfd_vma) template_sequence[i].data;
4013 if (template_sequence[i].reloc_addend != 0)
4015 /* We've borrowed the reloc_addend field to mean we should
4016 insert a condition code into this (Thumb-1 branch)
4017 instruction. See THUMB16_BCOND_INSN. */
4018 BFD_ASSERT ((data & 0xff00) == 0xd000);
4019 data |= ((stub_entry->orig_insn >> 22) & 0xf) << 8;
4021 bfd_put_16 (stub_bfd, data, loc + size);
4027 bfd_put_16 (stub_bfd,
4028 (template_sequence[i].data >> 16) & 0xffff,
4030 bfd_put_16 (stub_bfd, template_sequence[i].data & 0xffff,
4032 if (template_sequence[i].r_type != R_ARM_NONE)
4034 stub_reloc_idx[nrelocs] = i;
4035 stub_reloc_offset[nrelocs++] = size;
4041 bfd_put_32 (stub_bfd, template_sequence[i].data,
4043 /* Handle cases where the target is encoded within the
4045 if (template_sequence[i].r_type == R_ARM_JUMP24)
4047 stub_reloc_idx[nrelocs] = i;
4048 stub_reloc_offset[nrelocs++] = size;
4054 bfd_put_32 (stub_bfd, template_sequence[i].data, loc + size);
4055 stub_reloc_idx[nrelocs] = i;
4056 stub_reloc_offset[nrelocs++] = size;
4066 stub_sec->size += size;
4068 /* Stub size has already been computed in arm_size_one_stub. Check
4070 BFD_ASSERT (size == stub_entry->stub_size);
4072 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
4073 if (stub_entry->branch_type == ST_BRANCH_TO_THUMB)
4076 /* Assume there is at least one and at most MAXRELOCS entries to relocate
4078 BFD_ASSERT (nrelocs != 0 && nrelocs <= MAXRELOCS);
4080 for (i = 0; i < nrelocs; i++)
4081 if (template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP24
4082 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP19
4083 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_CALL
4084 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_XPC22)
4086 Elf_Internal_Rela rel;
4087 bfd_boolean unresolved_reloc;
4088 char *error_message;
4089 enum arm_st_branch_type branch_type
4090 = (template_sequence[stub_reloc_idx[i]].r_type != R_ARM_THM_XPC22
4091 ? ST_BRANCH_TO_THUMB : ST_BRANCH_TO_ARM);
4092 bfd_vma points_to = sym_value + stub_entry->target_addend;
4094 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i];
4095 rel.r_info = ELF32_R_INFO (0,
4096 template_sequence[stub_reloc_idx[i]].r_type);
4097 rel.r_addend = template_sequence[stub_reloc_idx[i]].reloc_addend;
4099 if (stub_entry->stub_type == arm_stub_a8_veneer_b_cond && i == 0)
4100 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
4101 template should refer back to the instruction after the original
4103 points_to = sym_value;
4105 /* There may be unintended consequences if this is not true. */
4106 BFD_ASSERT (stub_entry->h == NULL);
4108 /* Note: _bfd_final_link_relocate doesn't handle these relocations
4109 properly. We should probably use this function unconditionally,
4110 rather than only for certain relocations listed in the enclosing
4111 conditional, for the sake of consistency. */
4112 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4113 (template_sequence[stub_reloc_idx[i]].r_type),
4114 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel,
4115 points_to, info, stub_entry->target_section, "", STT_FUNC,
4116 branch_type, (struct elf_link_hash_entry *) stub_entry->h,
4117 &unresolved_reloc, &error_message);
4121 Elf_Internal_Rela rel;
4122 bfd_boolean unresolved_reloc;
4123 char *error_message;
4124 bfd_vma points_to = sym_value + stub_entry->target_addend
4125 + template_sequence[stub_reloc_idx[i]].reloc_addend;
4127 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i];
4128 rel.r_info = ELF32_R_INFO (0,
4129 template_sequence[stub_reloc_idx[i]].r_type);
4132 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4133 (template_sequence[stub_reloc_idx[i]].r_type),
4134 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel,
4135 points_to, info, stub_entry->target_section, "", STT_FUNC,
4136 stub_entry->branch_type,
4137 (struct elf_link_hash_entry *) stub_entry->h, &unresolved_reloc,
4145 /* Calculate the template, template size and instruction size for a stub.
4146 Return value is the instruction size. */
4149 find_stub_size_and_template (enum elf32_arm_stub_type stub_type,
4150 const insn_sequence **stub_template,
4151 int *stub_template_size)
4153 const insn_sequence *template_sequence = NULL;
4154 int template_size = 0, i;
4157 template_sequence = stub_definitions[stub_type].template_sequence;
4159 *stub_template = template_sequence;
4161 template_size = stub_definitions[stub_type].template_size;
4162 if (stub_template_size)
4163 *stub_template_size = template_size;
4166 for (i = 0; i < template_size; i++)
4168 switch (template_sequence[i].type)
4189 /* As above, but don't actually build the stub. Just bump offset so
4190 we know stub section sizes. */
4193 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
4194 void *in_arg ATTRIBUTE_UNUSED)
4196 struct elf32_arm_stub_hash_entry *stub_entry;
4197 const insn_sequence *template_sequence;
4198 int template_size, size;
4200 /* Massage our args to the form they really have. */
4201 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
4203 BFD_ASSERT((stub_entry->stub_type > arm_stub_none)
4204 && stub_entry->stub_type < ARRAY_SIZE(stub_definitions));
4206 size = find_stub_size_and_template (stub_entry->stub_type, &template_sequence,
4209 stub_entry->stub_size = size;
4210 stub_entry->stub_template = template_sequence;
4211 stub_entry->stub_template_size = template_size;
4213 size = (size + 7) & ~7;
4214 stub_entry->stub_sec->size += size;
4219 /* External entry points for sizing and building linker stubs. */
4221 /* Set up various things so that we can make a list of input sections
4222 for each output section included in the link. Returns -1 on error,
4223 0 when no stubs will be needed, and 1 on success. */
4226 elf32_arm_setup_section_lists (bfd *output_bfd,
4227 struct bfd_link_info *info)
4230 unsigned int bfd_count;
4231 int top_id, top_index;
4233 asection **input_list, **list;
4235 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4239 if (! is_elf_hash_table (htab))
4242 /* Count the number of input BFDs and find the top input section id. */
4243 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
4245 input_bfd = input_bfd->link_next)
4248 for (section = input_bfd->sections;
4250 section = section->next)
4252 if (top_id < section->id)
4253 top_id = section->id;
4256 htab->bfd_count = bfd_count;
4258 amt = sizeof (struct map_stub) * (top_id + 1);
4259 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4260 if (htab->stub_group == NULL)
4262 htab->top_id = top_id;
4264 /* We can't use output_bfd->section_count here to find the top output
4265 section index as some sections may have been removed, and
4266 _bfd_strip_section_from_output doesn't renumber the indices. */
4267 for (section = output_bfd->sections, top_index = 0;
4269 section = section->next)
4271 if (top_index < section->index)
4272 top_index = section->index;
4275 htab->top_index = top_index;
4276 amt = sizeof (asection *) * (top_index + 1);
4277 input_list = (asection **) bfd_malloc (amt);
4278 htab->input_list = input_list;
4279 if (input_list == NULL)
4282 /* For sections we aren't interested in, mark their entries with a
4283 value we can check later. */
4284 list = input_list + top_index;
4286 *list = bfd_abs_section_ptr;
4287 while (list-- != input_list);
4289 for (section = output_bfd->sections;
4291 section = section->next)
4293 if ((section->flags & SEC_CODE) != 0)
4294 input_list[section->index] = NULL;
4300 /* The linker repeatedly calls this function for each input section,
4301 in the order that input sections are linked into output sections.
4302 Build lists of input sections to determine groupings between which
4303 we may insert linker stubs. */
4306 elf32_arm_next_input_section (struct bfd_link_info *info,
4309 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4314 if (isec->output_section->index <= htab->top_index)
4316 asection **list = htab->input_list + isec->output_section->index;
4318 if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0)
4320 /* Steal the link_sec pointer for our list. */
4321 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4322 /* This happens to make the list in reverse order,
4323 which we reverse later. */
4324 PREV_SEC (isec) = *list;
4330 /* See whether we can group stub sections together. Grouping stub
4331 sections may result in fewer stubs. More importantly, we need to
4332 put all .init* and .fini* stubs at the end of the .init or
4333 .fini output sections respectively, because glibc splits the
4334 _init and _fini functions into multiple parts. Putting a stub in
4335 the middle of a function is not a good idea. */
4338 group_sections (struct elf32_arm_link_hash_table *htab,
4339 bfd_size_type stub_group_size,
4340 bfd_boolean stubs_always_after_branch)
4342 asection **list = htab->input_list;
4346 asection *tail = *list;
4349 if (tail == bfd_abs_section_ptr)
4352 /* Reverse the list: we must avoid placing stubs at the
4353 beginning of the section because the beginning of the text
4354 section may be required for an interrupt vector in bare metal
4356 #define NEXT_SEC PREV_SEC
4358 while (tail != NULL)
4360 /* Pop from tail. */
4361 asection *item = tail;
4362 tail = PREV_SEC (item);
4365 NEXT_SEC (item) = head;
4369 while (head != NULL)
4373 bfd_vma stub_group_start = head->output_offset;
4374 bfd_vma end_of_next;
4377 while (NEXT_SEC (curr) != NULL)
4379 next = NEXT_SEC (curr);
4380 end_of_next = next->output_offset + next->size;
4381 if (end_of_next - stub_group_start >= stub_group_size)
4382 /* End of NEXT is too far from start, so stop. */
4384 /* Add NEXT to the group. */
4388 /* OK, the size from the start to the start of CURR is less
4389 than stub_group_size and thus can be handled by one stub
4390 section. (Or the head section is itself larger than
4391 stub_group_size, in which case we may be toast.)
4392 We should really be keeping track of the total size of
4393 stubs added here, as stubs contribute to the final output
4397 next = NEXT_SEC (head);
4398 /* Set up this stub group. */
4399 htab->stub_group[head->id].link_sec = curr;
4401 while (head != curr && (head = next) != NULL);
4403 /* But wait, there's more! Input sections up to stub_group_size
4404 bytes after the stub section can be handled by it too. */
4405 if (!stubs_always_after_branch)
4407 stub_group_start = curr->output_offset + curr->size;
4409 while (next != NULL)
4411 end_of_next = next->output_offset + next->size;
4412 if (end_of_next - stub_group_start >= stub_group_size)
4413 /* End of NEXT is too far from stubs, so stop. */
4415 /* Add NEXT to the stub group. */
4417 next = NEXT_SEC (head);
4418 htab->stub_group[head->id].link_sec = curr;
4424 while (list++ != htab->input_list + htab->top_index);
4426 free (htab->input_list);
4431 /* Comparison function for sorting/searching relocations relating to Cortex-A8
4435 a8_reloc_compare (const void *a, const void *b)
4437 const struct a8_erratum_reloc *ra = (const struct a8_erratum_reloc *) a;
4438 const struct a8_erratum_reloc *rb = (const struct a8_erratum_reloc *) b;
4440 if (ra->from < rb->from)
4442 else if (ra->from > rb->from)
4448 static struct elf_link_hash_entry *find_thumb_glue (struct bfd_link_info *,
4449 const char *, char **);
4451 /* Helper function to scan code for sequences which might trigger the Cortex-A8
4452 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
4453 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
4457 cortex_a8_erratum_scan (bfd *input_bfd,
4458 struct bfd_link_info *info,
4459 struct a8_erratum_fix **a8_fixes_p,
4460 unsigned int *num_a8_fixes_p,
4461 unsigned int *a8_fix_table_size_p,
4462 struct a8_erratum_reloc *a8_relocs,
4463 unsigned int num_a8_relocs,
4464 unsigned prev_num_a8_fixes,
4465 bfd_boolean *stub_changed_p)
4468 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4469 struct a8_erratum_fix *a8_fixes = *a8_fixes_p;
4470 unsigned int num_a8_fixes = *num_a8_fixes_p;
4471 unsigned int a8_fix_table_size = *a8_fix_table_size_p;
4476 for (section = input_bfd->sections;
4478 section = section->next)
4480 bfd_byte *contents = NULL;
4481 struct _arm_elf_section_data *sec_data;
4485 if (elf_section_type (section) != SHT_PROGBITS
4486 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
4487 || (section->flags & SEC_EXCLUDE) != 0
4488 || (section->sec_info_type == ELF_INFO_TYPE_JUST_SYMS)
4489 || (section->output_section == bfd_abs_section_ptr))
4492 base_vma = section->output_section->vma + section->output_offset;
4494 if (elf_section_data (section)->this_hdr.contents != NULL)
4495 contents = elf_section_data (section)->this_hdr.contents;
4496 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
4499 sec_data = elf32_arm_section_data (section);
4501 for (span = 0; span < sec_data->mapcount; span++)
4503 unsigned int span_start = sec_data->map[span].vma;
4504 unsigned int span_end = (span == sec_data->mapcount - 1)
4505 ? section->size : sec_data->map[span + 1].vma;
4507 char span_type = sec_data->map[span].type;
4508 bfd_boolean last_was_32bit = FALSE, last_was_branch = FALSE;
4510 if (span_type != 't')
4513 /* Span is entirely within a single 4KB region: skip scanning. */
4514 if (((base_vma + span_start) & ~0xfff)
4515 == ((base_vma + span_end) & ~0xfff))
4518 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
4520 * The opcode is BLX.W, BL.W, B.W, Bcc.W
4521 * The branch target is in the same 4KB region as the
4522 first half of the branch.
4523 * The instruction before the branch is a 32-bit
4524 length non-branch instruction. */
4525 for (i = span_start; i < span_end;)
4527 unsigned int insn = bfd_getl16 (&contents[i]);
4528 bfd_boolean insn_32bit = FALSE, is_blx = FALSE, is_b = FALSE;
4529 bfd_boolean is_bl = FALSE, is_bcc = FALSE, is_32bit_branch;
4531 if ((insn & 0xe000) == 0xe000 && (insn & 0x1800) != 0x0000)
4536 /* Load the rest of the insn (in manual-friendly order). */
4537 insn = (insn << 16) | bfd_getl16 (&contents[i + 2]);
4539 /* Encoding T4: B<c>.W. */
4540 is_b = (insn & 0xf800d000) == 0xf0009000;
4541 /* Encoding T1: BL<c>.W. */
4542 is_bl = (insn & 0xf800d000) == 0xf000d000;
4543 /* Encoding T2: BLX<c>.W. */
4544 is_blx = (insn & 0xf800d000) == 0xf000c000;
4545 /* Encoding T3: B<c>.W (not permitted in IT block). */
4546 is_bcc = (insn & 0xf800d000) == 0xf0008000
4547 && (insn & 0x07f00000) != 0x03800000;
4550 is_32bit_branch = is_b || is_bl || is_blx || is_bcc;
4552 if (((base_vma + i) & 0xfff) == 0xffe
4556 && ! last_was_branch)
4558 bfd_signed_vma offset = 0;
4559 bfd_boolean force_target_arm = FALSE;
4560 bfd_boolean force_target_thumb = FALSE;
4562 enum elf32_arm_stub_type stub_type = arm_stub_none;
4563 struct a8_erratum_reloc key, *found;
4564 bfd_boolean use_plt = FALSE;
4566 key.from = base_vma + i;
4567 found = (struct a8_erratum_reloc *)
4568 bsearch (&key, a8_relocs, num_a8_relocs,
4569 sizeof (struct a8_erratum_reloc),
4574 char *error_message = NULL;
4575 struct elf_link_hash_entry *entry;
4577 /* We don't care about the error returned from this
4578 function, only if there is glue or not. */
4579 entry = find_thumb_glue (info, found->sym_name,
4583 found->non_a8_stub = TRUE;
4585 /* Keep a simpler condition, for the sake of clarity. */
4586 if (htab->root.splt != NULL && found->hash != NULL
4587 && found->hash->root.plt.offset != (bfd_vma) -1)
4590 if (found->r_type == R_ARM_THM_CALL)
4592 if (found->branch_type == ST_BRANCH_TO_ARM
4594 force_target_arm = TRUE;
4596 force_target_thumb = TRUE;
4600 /* Check if we have an offending branch instruction. */
4602 if (found && found->non_a8_stub)
4603 /* We've already made a stub for this instruction, e.g.
4604 it's a long branch or a Thumb->ARM stub. Assume that
4605 stub will suffice to work around the A8 erratum (see
4606 setting of always_after_branch above). */
4610 offset = (insn & 0x7ff) << 1;
4611 offset |= (insn & 0x3f0000) >> 4;
4612 offset |= (insn & 0x2000) ? 0x40000 : 0;
4613 offset |= (insn & 0x800) ? 0x80000 : 0;
4614 offset |= (insn & 0x4000000) ? 0x100000 : 0;
4615 if (offset & 0x100000)
4616 offset |= ~ ((bfd_signed_vma) 0xfffff);
4617 stub_type = arm_stub_a8_veneer_b_cond;
4619 else if (is_b || is_bl || is_blx)
4621 int s = (insn & 0x4000000) != 0;
4622 int j1 = (insn & 0x2000) != 0;
4623 int j2 = (insn & 0x800) != 0;
4627 offset = (insn & 0x7ff) << 1;
4628 offset |= (insn & 0x3ff0000) >> 4;
4632 if (offset & 0x1000000)
4633 offset |= ~ ((bfd_signed_vma) 0xffffff);
4636 offset &= ~ ((bfd_signed_vma) 3);
4638 stub_type = is_blx ? arm_stub_a8_veneer_blx :
4639 is_bl ? arm_stub_a8_veneer_bl : arm_stub_a8_veneer_b;
4642 if (stub_type != arm_stub_none)
4644 bfd_vma pc_for_insn = base_vma + i + 4;
4646 /* The original instruction is a BL, but the target is
4647 an ARM instruction. If we were not making a stub,
4648 the BL would have been converted to a BLX. Use the
4649 BLX stub instead in that case. */
4650 if (htab->use_blx && force_target_arm
4651 && stub_type == arm_stub_a8_veneer_bl)
4653 stub_type = arm_stub_a8_veneer_blx;
4657 /* Conversely, if the original instruction was
4658 BLX but the target is Thumb mode, use the BL
4660 else if (force_target_thumb
4661 && stub_type == arm_stub_a8_veneer_blx)
4663 stub_type = arm_stub_a8_veneer_bl;
4669 pc_for_insn &= ~ ((bfd_vma) 3);
4671 /* If we found a relocation, use the proper destination,
4672 not the offset in the (unrelocated) instruction.
4673 Note this is always done if we switched the stub type
4677 (bfd_signed_vma) (found->destination - pc_for_insn);
4679 /* If the stub will use a Thumb-mode branch to a
4680 PLT target, redirect it to the preceding Thumb
4682 if (stub_type != arm_stub_a8_veneer_blx && use_plt)
4683 offset -= PLT_THUMB_STUB_SIZE;
4685 target = pc_for_insn + offset;
4687 /* The BLX stub is ARM-mode code. Adjust the offset to
4688 take the different PC value (+8 instead of +4) into
4690 if (stub_type == arm_stub_a8_veneer_blx)
4693 if (((base_vma + i) & ~0xfff) == (target & ~0xfff))
4695 char *stub_name = NULL;
4697 if (num_a8_fixes == a8_fix_table_size)
4699 a8_fix_table_size *= 2;
4700 a8_fixes = (struct a8_erratum_fix *)
4701 bfd_realloc (a8_fixes,
4702 sizeof (struct a8_erratum_fix)
4703 * a8_fix_table_size);
4706 if (num_a8_fixes < prev_num_a8_fixes)
4708 /* If we're doing a subsequent scan,
4709 check if we've found the same fix as
4710 before, and try and reuse the stub
4712 stub_name = a8_fixes[num_a8_fixes].stub_name;
4713 if ((a8_fixes[num_a8_fixes].section != section)
4714 || (a8_fixes[num_a8_fixes].offset != i))
4718 *stub_changed_p = TRUE;
4724 stub_name = (char *) bfd_malloc (8 + 1 + 8 + 1);
4725 if (stub_name != NULL)
4726 sprintf (stub_name, "%x:%x", section->id, i);
4729 a8_fixes[num_a8_fixes].input_bfd = input_bfd;
4730 a8_fixes[num_a8_fixes].section = section;
4731 a8_fixes[num_a8_fixes].offset = i;
4732 a8_fixes[num_a8_fixes].addend = offset;
4733 a8_fixes[num_a8_fixes].orig_insn = insn;
4734 a8_fixes[num_a8_fixes].stub_name = stub_name;
4735 a8_fixes[num_a8_fixes].stub_type = stub_type;
4736 a8_fixes[num_a8_fixes].branch_type =
4737 is_blx ? ST_BRANCH_TO_ARM : ST_BRANCH_TO_THUMB;
4744 i += insn_32bit ? 4 : 2;
4745 last_was_32bit = insn_32bit;
4746 last_was_branch = is_32bit_branch;
4750 if (elf_section_data (section)->this_hdr.contents == NULL)
4754 *a8_fixes_p = a8_fixes;
4755 *num_a8_fixes_p = num_a8_fixes;
4756 *a8_fix_table_size_p = a8_fix_table_size;
4761 /* Determine and set the size of the stub section for a final link.
4763 The basic idea here is to examine all the relocations looking for
4764 PC-relative calls to a target that is unreachable with a "bl"
4768 elf32_arm_size_stubs (bfd *output_bfd,
4770 struct bfd_link_info *info,
4771 bfd_signed_vma group_size,
4772 asection * (*add_stub_section) (const char *, asection *),
4773 void (*layout_sections_again) (void))
4775 bfd_size_type stub_group_size;
4776 bfd_boolean stubs_always_after_branch;
4777 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4778 struct a8_erratum_fix *a8_fixes = NULL;
4779 unsigned int num_a8_fixes = 0, a8_fix_table_size = 10;
4780 struct a8_erratum_reloc *a8_relocs = NULL;
4781 unsigned int num_a8_relocs = 0, a8_reloc_table_size = 10, i;
4786 if (htab->fix_cortex_a8)
4788 a8_fixes = (struct a8_erratum_fix *)
4789 bfd_zmalloc (sizeof (struct a8_erratum_fix) * a8_fix_table_size);
4790 a8_relocs = (struct a8_erratum_reloc *)
4791 bfd_zmalloc (sizeof (struct a8_erratum_reloc) * a8_reloc_table_size);
4794 /* Propagate mach to stub bfd, because it may not have been
4795 finalized when we created stub_bfd. */
4796 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
4797 bfd_get_mach (output_bfd));
4799 /* Stash our params away. */
4800 htab->stub_bfd = stub_bfd;
4801 htab->add_stub_section = add_stub_section;
4802 htab->layout_sections_again = layout_sections_again;
4803 stubs_always_after_branch = group_size < 0;
4805 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
4806 as the first half of a 32-bit branch straddling two 4K pages. This is a
4807 crude way of enforcing that. */
4808 if (htab->fix_cortex_a8)
4809 stubs_always_after_branch = 1;
4812 stub_group_size = -group_size;
4814 stub_group_size = group_size;
4816 if (stub_group_size == 1)
4818 /* Default values. */
4819 /* Thumb branch range is +-4MB has to be used as the default
4820 maximum size (a given section can contain both ARM and Thumb
4821 code, so the worst case has to be taken into account).
4823 This value is 24K less than that, which allows for 2025
4824 12-byte stubs. If we exceed that, then we will fail to link.
4825 The user will have to relink with an explicit group size
4827 stub_group_size = 4170000;
4830 group_sections (htab, stub_group_size, stubs_always_after_branch);
4832 /* If we're applying the cortex A8 fix, we need to determine the
4833 program header size now, because we cannot change it later --
4834 that could alter section placements. Notice the A8 erratum fix
4835 ends up requiring the section addresses to remain unchanged
4836 modulo the page size. That's something we cannot represent
4837 inside BFD, and we don't want to force the section alignment to
4838 be the page size. */
4839 if (htab->fix_cortex_a8)
4840 (*htab->layout_sections_again) ();
4845 unsigned int bfd_indx;
4847 bfd_boolean stub_changed = FALSE;
4848 unsigned prev_num_a8_fixes = num_a8_fixes;
4851 for (input_bfd = info->input_bfds, bfd_indx = 0;
4853 input_bfd = input_bfd->link_next, bfd_indx++)
4855 Elf_Internal_Shdr *symtab_hdr;
4857 Elf_Internal_Sym *local_syms = NULL;
4861 /* We'll need the symbol table in a second. */
4862 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4863 if (symtab_hdr->sh_info == 0)
4866 /* Walk over each section attached to the input bfd. */
4867 for (section = input_bfd->sections;
4869 section = section->next)
4871 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4873 /* If there aren't any relocs, then there's nothing more
4875 if ((section->flags & SEC_RELOC) == 0
4876 || section->reloc_count == 0
4877 || (section->flags & SEC_CODE) == 0)
4880 /* If this section is a link-once section that will be
4881 discarded, then don't create any stubs. */
4882 if (section->output_section == NULL
4883 || section->output_section->owner != output_bfd)
4886 /* Get the relocs. */
4888 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
4889 NULL, info->keep_memory);
4890 if (internal_relocs == NULL)
4891 goto error_ret_free_local;
4893 /* Now examine each relocation. */
4894 irela = internal_relocs;
4895 irelaend = irela + section->reloc_count;
4896 for (; irela < irelaend; irela++)
4898 unsigned int r_type, r_indx;
4899 enum elf32_arm_stub_type stub_type;
4900 struct elf32_arm_stub_hash_entry *stub_entry;
4903 bfd_vma destination;
4904 struct elf32_arm_link_hash_entry *hash;
4905 const char *sym_name;
4907 const asection *id_sec;
4908 unsigned char st_type;
4909 enum arm_st_branch_type branch_type;
4910 bfd_boolean created_stub = FALSE;
4912 r_type = ELF32_R_TYPE (irela->r_info);
4913 r_indx = ELF32_R_SYM (irela->r_info);
4915 if (r_type >= (unsigned int) R_ARM_max)
4917 bfd_set_error (bfd_error_bad_value);
4918 error_ret_free_internal:
4919 if (elf_section_data (section)->relocs == NULL)
4920 free (internal_relocs);
4921 goto error_ret_free_local;
4925 if (r_indx >= symtab_hdr->sh_info)
4926 hash = elf32_arm_hash_entry
4927 (elf_sym_hashes (input_bfd)
4928 [r_indx - symtab_hdr->sh_info]);
4930 /* Only look for stubs on branch instructions, or
4931 non-relaxed TLSCALL */
4932 if ((r_type != (unsigned int) R_ARM_CALL)
4933 && (r_type != (unsigned int) R_ARM_THM_CALL)
4934 && (r_type != (unsigned int) R_ARM_JUMP24)
4935 && (r_type != (unsigned int) R_ARM_THM_JUMP19)
4936 && (r_type != (unsigned int) R_ARM_THM_XPC22)
4937 && (r_type != (unsigned int) R_ARM_THM_JUMP24)
4938 && (r_type != (unsigned int) R_ARM_PLT32)
4939 && !((r_type == (unsigned int) R_ARM_TLS_CALL
4940 || r_type == (unsigned int) R_ARM_THM_TLS_CALL)
4941 && r_type == elf32_arm_tls_transition
4942 (info, r_type, &hash->root)
4943 && ((hash ? hash->tls_type
4944 : (elf32_arm_local_got_tls_type
4945 (input_bfd)[r_indx]))
4946 & GOT_TLS_GDESC) != 0))
4949 /* Now determine the call target, its name, value,
4956 if (r_type == (unsigned int) R_ARM_TLS_CALL
4957 || r_type == (unsigned int) R_ARM_THM_TLS_CALL)
4959 /* A non-relaxed TLS call. The target is the
4960 plt-resident trampoline and nothing to do
4962 BFD_ASSERT (htab->tls_trampoline > 0);
4963 sym_sec = htab->root.splt;
4964 sym_value = htab->tls_trampoline;
4967 branch_type = ST_BRANCH_TO_ARM;
4971 /* It's a local symbol. */
4972 Elf_Internal_Sym *sym;
4974 if (local_syms == NULL)
4977 = (Elf_Internal_Sym *) symtab_hdr->contents;
4978 if (local_syms == NULL)
4980 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4981 symtab_hdr->sh_info, 0,
4983 if (local_syms == NULL)
4984 goto error_ret_free_internal;
4987 sym = local_syms + r_indx;
4988 if (sym->st_shndx == SHN_UNDEF)
4989 sym_sec = bfd_und_section_ptr;
4990 else if (sym->st_shndx == SHN_ABS)
4991 sym_sec = bfd_abs_section_ptr;
4992 else if (sym->st_shndx == SHN_COMMON)
4993 sym_sec = bfd_com_section_ptr;
4996 bfd_section_from_elf_index (input_bfd, sym->st_shndx);
4999 /* This is an undefined symbol. It can never
5003 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
5004 sym_value = sym->st_value;
5005 destination = (sym_value + irela->r_addend
5006 + sym_sec->output_offset
5007 + sym_sec->output_section->vma);
5008 st_type = ELF_ST_TYPE (sym->st_info);
5009 branch_type = ARM_SYM_BRANCH_TYPE (sym);
5011 = bfd_elf_string_from_elf_section (input_bfd,
5012 symtab_hdr->sh_link,
5017 /* It's an external symbol. */
5018 while (hash->root.root.type == bfd_link_hash_indirect
5019 || hash->root.root.type == bfd_link_hash_warning)
5020 hash = ((struct elf32_arm_link_hash_entry *)
5021 hash->root.root.u.i.link);
5023 if (hash->root.root.type == bfd_link_hash_defined
5024 || hash->root.root.type == bfd_link_hash_defweak)
5026 sym_sec = hash->root.root.u.def.section;
5027 sym_value = hash->root.root.u.def.value;
5029 struct elf32_arm_link_hash_table *globals =
5030 elf32_arm_hash_table (info);
5032 /* For a destination in a shared library,
5033 use the PLT stub as target address to
5034 decide whether a branch stub is
5037 && globals->root.splt != NULL
5039 && hash->root.plt.offset != (bfd_vma) -1)
5041 sym_sec = globals->root.splt;
5042 sym_value = hash->root.plt.offset;
5043 if (sym_sec->output_section != NULL)
5044 destination = (sym_value
5045 + sym_sec->output_offset
5046 + sym_sec->output_section->vma);
5048 else if (sym_sec->output_section != NULL)
5049 destination = (sym_value + irela->r_addend
5050 + sym_sec->output_offset
5051 + sym_sec->output_section->vma);
5053 else if ((hash->root.root.type == bfd_link_hash_undefined)
5054 || (hash->root.root.type == bfd_link_hash_undefweak))
5056 /* For a shared library, use the PLT stub as
5057 target address to decide whether a long
5058 branch stub is needed.
5059 For absolute code, they cannot be handled. */
5060 struct elf32_arm_link_hash_table *globals =
5061 elf32_arm_hash_table (info);
5064 && globals->root.splt != NULL
5066 && hash->root.plt.offset != (bfd_vma) -1)
5068 sym_sec = globals->root.splt;
5069 sym_value = hash->root.plt.offset;
5070 if (sym_sec->output_section != NULL)
5071 destination = (sym_value
5072 + sym_sec->output_offset
5073 + sym_sec->output_section->vma);
5080 bfd_set_error (bfd_error_bad_value);
5081 goto error_ret_free_internal;
5083 st_type = hash->root.type;
5084 branch_type = hash->root.target_internal;
5085 sym_name = hash->root.root.root.string;
5090 /* Determine what (if any) linker stub is needed. */
5091 stub_type = arm_type_of_stub (info, section, irela,
5092 st_type, &branch_type,
5093 hash, destination, sym_sec,
5094 input_bfd, sym_name);
5095 if (stub_type == arm_stub_none)
5098 /* Support for grouping stub sections. */
5099 id_sec = htab->stub_group[section->id].link_sec;
5101 /* Get the name of this stub. */
5102 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash,
5105 goto error_ret_free_internal;
5107 /* We've either created a stub for this reloc already,
5108 or we are about to. */
5109 created_stub = TRUE;
5111 stub_entry = arm_stub_hash_lookup
5112 (&htab->stub_hash_table, stub_name,
5114 if (stub_entry != NULL)
5116 /* The proper stub has already been created. */
5118 stub_entry->target_value = sym_value;
5122 stub_entry = elf32_arm_add_stub (stub_name, section,
5124 if (stub_entry == NULL)
5127 goto error_ret_free_internal;
5130 stub_entry->target_value = sym_value;
5131 stub_entry->target_section = sym_sec;
5132 stub_entry->stub_type = stub_type;
5133 stub_entry->h = hash;
5134 stub_entry->branch_type = branch_type;
5136 if (sym_name == NULL)
5137 sym_name = "unnamed";
5138 stub_entry->output_name = (char *)
5139 bfd_alloc (htab->stub_bfd,
5140 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
5141 + strlen (sym_name));
5142 if (stub_entry->output_name == NULL)
5145 goto error_ret_free_internal;
5148 /* For historical reasons, use the existing names for
5149 ARM-to-Thumb and Thumb-to-ARM stubs. */
5150 if ((r_type == (unsigned int) R_ARM_THM_CALL
5151 || r_type == (unsigned int) R_ARM_THM_JUMP24)
5152 && branch_type == ST_BRANCH_TO_ARM)
5153 sprintf (stub_entry->output_name,
5154 THUMB2ARM_GLUE_ENTRY_NAME, sym_name);
5155 else if ((r_type == (unsigned int) R_ARM_CALL
5156 || r_type == (unsigned int) R_ARM_JUMP24)
5157 && branch_type == ST_BRANCH_TO_THUMB)
5158 sprintf (stub_entry->output_name,
5159 ARM2THUMB_GLUE_ENTRY_NAME, sym_name);
5161 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
5164 stub_changed = TRUE;
5168 /* Look for relocations which might trigger Cortex-A8
5170 if (htab->fix_cortex_a8
5171 && (r_type == (unsigned int) R_ARM_THM_JUMP24
5172 || r_type == (unsigned int) R_ARM_THM_JUMP19
5173 || r_type == (unsigned int) R_ARM_THM_CALL
5174 || r_type == (unsigned int) R_ARM_THM_XPC22))
5176 bfd_vma from = section->output_section->vma
5177 + section->output_offset
5180 if ((from & 0xfff) == 0xffe)
5182 /* Found a candidate. Note we haven't checked the
5183 destination is within 4K here: if we do so (and
5184 don't create an entry in a8_relocs) we can't tell
5185 that a branch should have been relocated when
5187 if (num_a8_relocs == a8_reloc_table_size)
5189 a8_reloc_table_size *= 2;
5190 a8_relocs = (struct a8_erratum_reloc *)
5191 bfd_realloc (a8_relocs,
5192 sizeof (struct a8_erratum_reloc)
5193 * a8_reloc_table_size);
5196 a8_relocs[num_a8_relocs].from = from;
5197 a8_relocs[num_a8_relocs].destination = destination;
5198 a8_relocs[num_a8_relocs].r_type = r_type;
5199 a8_relocs[num_a8_relocs].branch_type = branch_type;
5200 a8_relocs[num_a8_relocs].sym_name = sym_name;
5201 a8_relocs[num_a8_relocs].non_a8_stub = created_stub;
5202 a8_relocs[num_a8_relocs].hash = hash;
5209 /* We're done with the internal relocs, free them. */
5210 if (elf_section_data (section)->relocs == NULL)
5211 free (internal_relocs);
5214 if (htab->fix_cortex_a8)
5216 /* Sort relocs which might apply to Cortex-A8 erratum. */
5217 qsort (a8_relocs, num_a8_relocs,
5218 sizeof (struct a8_erratum_reloc),
5221 /* Scan for branches which might trigger Cortex-A8 erratum. */
5222 if (cortex_a8_erratum_scan (input_bfd, info, &a8_fixes,
5223 &num_a8_fixes, &a8_fix_table_size,
5224 a8_relocs, num_a8_relocs,
5225 prev_num_a8_fixes, &stub_changed)
5227 goto error_ret_free_local;
5231 if (prev_num_a8_fixes != num_a8_fixes)
5232 stub_changed = TRUE;
5237 /* OK, we've added some stubs. Find out the new size of the
5239 for (stub_sec = htab->stub_bfd->sections;
5241 stub_sec = stub_sec->next)
5243 /* Ignore non-stub sections. */
5244 if (!strstr (stub_sec->name, STUB_SUFFIX))
5250 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
5252 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
5253 if (htab->fix_cortex_a8)
5254 for (i = 0; i < num_a8_fixes; i++)
5256 stub_sec = elf32_arm_create_or_find_stub_sec (NULL,
5257 a8_fixes[i].section, htab);
5259 if (stub_sec == NULL)
5260 goto error_ret_free_local;
5263 += find_stub_size_and_template (a8_fixes[i].stub_type, NULL,
5268 /* Ask the linker to do its stuff. */
5269 (*htab->layout_sections_again) ();
5272 /* Add stubs for Cortex-A8 erratum fixes now. */
5273 if (htab->fix_cortex_a8)
5275 for (i = 0; i < num_a8_fixes; i++)
5277 struct elf32_arm_stub_hash_entry *stub_entry;
5278 char *stub_name = a8_fixes[i].stub_name;
5279 asection *section = a8_fixes[i].section;
5280 unsigned int section_id = a8_fixes[i].section->id;
5281 asection *link_sec = htab->stub_group[section_id].link_sec;
5282 asection *stub_sec = htab->stub_group[section_id].stub_sec;
5283 const insn_sequence *template_sequence;
5284 int template_size, size = 0;
5286 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
5288 if (stub_entry == NULL)
5290 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
5296 stub_entry->stub_sec = stub_sec;
5297 stub_entry->stub_offset = 0;
5298 stub_entry->id_sec = link_sec;
5299 stub_entry->stub_type = a8_fixes[i].stub_type;
5300 stub_entry->target_section = a8_fixes[i].section;
5301 stub_entry->target_value = a8_fixes[i].offset;
5302 stub_entry->target_addend = a8_fixes[i].addend;
5303 stub_entry->orig_insn = a8_fixes[i].orig_insn;
5304 stub_entry->branch_type = a8_fixes[i].branch_type;
5306 size = find_stub_size_and_template (a8_fixes[i].stub_type,
5310 stub_entry->stub_size = size;
5311 stub_entry->stub_template = template_sequence;
5312 stub_entry->stub_template_size = template_size;
5315 /* Stash the Cortex-A8 erratum fix array for use later in
5316 elf32_arm_write_section(). */
5317 htab->a8_erratum_fixes = a8_fixes;
5318 htab->num_a8_erratum_fixes = num_a8_fixes;
5322 htab->a8_erratum_fixes = NULL;
5323 htab->num_a8_erratum_fixes = 0;
5327 error_ret_free_local:
5331 /* Build all the stubs associated with the current output file. The
5332 stubs are kept in a hash table attached to the main linker hash
5333 table. We also set up the .plt entries for statically linked PIC
5334 functions here. This function is called via arm_elf_finish in the
5338 elf32_arm_build_stubs (struct bfd_link_info *info)
5341 struct bfd_hash_table *table;
5342 struct elf32_arm_link_hash_table *htab;
5344 htab = elf32_arm_hash_table (info);
5348 for (stub_sec = htab->stub_bfd->sections;
5350 stub_sec = stub_sec->next)
5354 /* Ignore non-stub sections. */
5355 if (!strstr (stub_sec->name, STUB_SUFFIX))
5358 /* Allocate memory to hold the linker stubs. */
5359 size = stub_sec->size;
5360 stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
5361 if (stub_sec->contents == NULL && size != 0)
5366 /* Build the stubs as directed by the stub hash table. */
5367 table = &htab->stub_hash_table;
5368 bfd_hash_traverse (table, arm_build_one_stub, info);
5369 if (htab->fix_cortex_a8)
5371 /* Place the cortex a8 stubs last. */
5372 htab->fix_cortex_a8 = -1;
5373 bfd_hash_traverse (table, arm_build_one_stub, info);
5379 /* Locate the Thumb encoded calling stub for NAME. */
5381 static struct elf_link_hash_entry *
5382 find_thumb_glue (struct bfd_link_info *link_info,
5384 char **error_message)
5387 struct elf_link_hash_entry *hash;
5388 struct elf32_arm_link_hash_table *hash_table;
5390 /* We need a pointer to the armelf specific hash table. */
5391 hash_table = elf32_arm_hash_table (link_info);
5392 if (hash_table == NULL)
5395 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5396 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
5398 BFD_ASSERT (tmp_name);
5400 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
5402 hash = elf_link_hash_lookup
5403 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
5406 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
5407 tmp_name, name) == -1)
5408 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
5415 /* Locate the ARM encoded calling stub for NAME. */
5417 static struct elf_link_hash_entry *
5418 find_arm_glue (struct bfd_link_info *link_info,
5420 char **error_message)
5423 struct elf_link_hash_entry *myh;
5424 struct elf32_arm_link_hash_table *hash_table;
5426 /* We need a pointer to the elfarm specific hash table. */
5427 hash_table = elf32_arm_hash_table (link_info);
5428 if (hash_table == NULL)
5431 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5432 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
5434 BFD_ASSERT (tmp_name);
5436 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
5438 myh = elf_link_hash_lookup
5439 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
5442 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
5443 tmp_name, name) == -1)
5444 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
5451 /* ARM->Thumb glue (static images):
5455 ldr r12, __func_addr
5458 .word func @ behave as if you saw a ARM_32 reloc.
5465 .word func @ behave as if you saw a ARM_32 reloc.
5467 (relocatable images)
5470 ldr r12, __func_offset
5476 #define ARM2THUMB_STATIC_GLUE_SIZE 12
5477 static const insn32 a2t1_ldr_insn = 0xe59fc000;
5478 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
5479 static const insn32 a2t3_func_addr_insn = 0x00000001;
5481 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
5482 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
5483 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
5485 #define ARM2THUMB_PIC_GLUE_SIZE 16
5486 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
5487 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
5488 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
5490 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
5494 __func_from_thumb: __func_from_thumb:
5496 nop ldr r6, __func_addr
5506 #define THUMB2ARM_GLUE_SIZE 8
5507 static const insn16 t2a1_bx_pc_insn = 0x4778;
5508 static const insn16 t2a2_noop_insn = 0x46c0;
5509 static const insn32 t2a3_b_insn = 0xea000000;
5511 #define VFP11_ERRATUM_VENEER_SIZE 8
5513 #define ARM_BX_VENEER_SIZE 12
5514 static const insn32 armbx1_tst_insn = 0xe3100001;
5515 static const insn32 armbx2_moveq_insn = 0x01a0f000;
5516 static const insn32 armbx3_bx_insn = 0xe12fff10;
5518 #ifndef ELFARM_NABI_C_INCLUDED
5520 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
5523 bfd_byte * contents;
5527 /* Do not include empty glue sections in the output. */
5530 s = bfd_get_section_by_name (abfd, name);
5532 s->flags |= SEC_EXCLUDE;
5537 BFD_ASSERT (abfd != NULL);
5539 s = bfd_get_section_by_name (abfd, name);
5540 BFD_ASSERT (s != NULL);
5542 contents = (bfd_byte *) bfd_alloc (abfd, size);
5544 BFD_ASSERT (s->size == size);
5545 s->contents = contents;
5549 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
5551 struct elf32_arm_link_hash_table * globals;
5553 globals = elf32_arm_hash_table (info);
5554 BFD_ASSERT (globals != NULL);
5556 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5557 globals->arm_glue_size,
5558 ARM2THUMB_GLUE_SECTION_NAME);
5560 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5561 globals->thumb_glue_size,
5562 THUMB2ARM_GLUE_SECTION_NAME);
5564 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5565 globals->vfp11_erratum_glue_size,
5566 VFP11_ERRATUM_VENEER_SECTION_NAME);
5568 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5569 globals->bx_glue_size,
5570 ARM_BX_GLUE_SECTION_NAME);
5575 /* Allocate space and symbols for calling a Thumb function from Arm mode.
5576 returns the symbol identifying the stub. */
5578 static struct elf_link_hash_entry *
5579 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
5580 struct elf_link_hash_entry * h)
5582 const char * name = h->root.root.string;
5585 struct elf_link_hash_entry * myh;
5586 struct bfd_link_hash_entry * bh;
5587 struct elf32_arm_link_hash_table * globals;
5591 globals = elf32_arm_hash_table (link_info);
5592 BFD_ASSERT (globals != NULL);
5593 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5595 s = bfd_get_section_by_name
5596 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
5598 BFD_ASSERT (s != NULL);
5600 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5601 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
5603 BFD_ASSERT (tmp_name);
5605 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
5607 myh = elf_link_hash_lookup
5608 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5612 /* We've already seen this guy. */
5617 /* The only trick here is using hash_table->arm_glue_size as the value.
5618 Even though the section isn't allocated yet, this is where we will be
5619 putting it. The +1 on the value marks that the stub has not been
5620 output yet - not that it is a Thumb function. */
5622 val = globals->arm_glue_size + 1;
5623 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
5624 tmp_name, BSF_GLOBAL, s, val,
5625 NULL, TRUE, FALSE, &bh);
5627 myh = (struct elf_link_hash_entry *) bh;
5628 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
5629 myh->forced_local = 1;
5633 if (link_info->shared || globals->root.is_relocatable_executable
5634 || globals->pic_veneer)
5635 size = ARM2THUMB_PIC_GLUE_SIZE;
5636 else if (globals->use_blx)
5637 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
5639 size = ARM2THUMB_STATIC_GLUE_SIZE;
5642 globals->arm_glue_size += size;
5647 /* Allocate space for ARMv4 BX veneers. */
5650 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
5653 struct elf32_arm_link_hash_table *globals;
5655 struct elf_link_hash_entry *myh;
5656 struct bfd_link_hash_entry *bh;
5659 /* BX PC does not need a veneer. */
5663 globals = elf32_arm_hash_table (link_info);
5664 BFD_ASSERT (globals != NULL);
5665 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5667 /* Check if this veneer has already been allocated. */
5668 if (globals->bx_glue_offset[reg])
5671 s = bfd_get_section_by_name
5672 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
5674 BFD_ASSERT (s != NULL);
5676 /* Add symbol for veneer. */
5678 bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
5680 BFD_ASSERT (tmp_name);
5682 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
5684 myh = elf_link_hash_lookup
5685 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
5687 BFD_ASSERT (myh == NULL);
5690 val = globals->bx_glue_size;
5691 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
5692 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
5693 NULL, TRUE, FALSE, &bh);
5695 myh = (struct elf_link_hash_entry *) bh;
5696 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
5697 myh->forced_local = 1;
5699 s->size += ARM_BX_VENEER_SIZE;
5700 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
5701 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
5705 /* Add an entry to the code/data map for section SEC. */
5708 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
5710 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5711 unsigned int newidx;
5713 if (sec_data->map == NULL)
5715 sec_data->map = (elf32_arm_section_map *)
5716 bfd_malloc (sizeof (elf32_arm_section_map));
5717 sec_data->mapcount = 0;
5718 sec_data->mapsize = 1;
5721 newidx = sec_data->mapcount++;
5723 if (sec_data->mapcount > sec_data->mapsize)
5725 sec_data->mapsize *= 2;
5726 sec_data->map = (elf32_arm_section_map *)
5727 bfd_realloc_or_free (sec_data->map, sec_data->mapsize
5728 * sizeof (elf32_arm_section_map));
5733 sec_data->map[newidx].vma = vma;
5734 sec_data->map[newidx].type = type;
5739 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
5740 veneers are handled for now. */
5743 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
5744 elf32_vfp11_erratum_list *branch,
5746 asection *branch_sec,
5747 unsigned int offset)
5750 struct elf32_arm_link_hash_table *hash_table;
5752 struct elf_link_hash_entry *myh;
5753 struct bfd_link_hash_entry *bh;
5755 struct _arm_elf_section_data *sec_data;
5756 elf32_vfp11_erratum_list *newerr;
5758 hash_table = elf32_arm_hash_table (link_info);
5759 BFD_ASSERT (hash_table != NULL);
5760 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
5762 s = bfd_get_section_by_name
5763 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
5765 sec_data = elf32_arm_section_data (s);
5767 BFD_ASSERT (s != NULL);
5769 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
5770 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5772 BFD_ASSERT (tmp_name);
5774 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5775 hash_table->num_vfp11_fixes);
5777 myh = elf_link_hash_lookup
5778 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
5780 BFD_ASSERT (myh == NULL);
5783 val = hash_table->vfp11_erratum_glue_size;
5784 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
5785 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
5786 NULL, TRUE, FALSE, &bh);
5788 myh = (struct elf_link_hash_entry *) bh;
5789 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
5790 myh->forced_local = 1;
5792 /* Link veneer back to calling location. */
5793 sec_data->erratumcount += 1;
5794 newerr = (elf32_vfp11_erratum_list *)
5795 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5797 newerr->type = VFP11_ERRATUM_ARM_VENEER;
5799 newerr->u.v.branch = branch;
5800 newerr->u.v.id = hash_table->num_vfp11_fixes;
5801 branch->u.b.veneer = newerr;
5803 newerr->next = sec_data->erratumlist;
5804 sec_data->erratumlist = newerr;
5806 /* A symbol for the return from the veneer. */
5807 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5808 hash_table->num_vfp11_fixes);
5810 myh = elf_link_hash_lookup
5811 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
5818 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
5819 branch_sec, val, NULL, TRUE, FALSE, &bh);
5821 myh = (struct elf_link_hash_entry *) bh;
5822 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
5823 myh->forced_local = 1;
5827 /* Generate a mapping symbol for the veneer section, and explicitly add an
5828 entry for that symbol to the code/data map for the section. */
5829 if (hash_table->vfp11_erratum_glue_size == 0)
5832 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
5833 ever requires this erratum fix. */
5834 _bfd_generic_link_add_one_symbol (link_info,
5835 hash_table->bfd_of_glue_owner, "$a",
5836 BSF_LOCAL, s, 0, NULL,
5839 myh = (struct elf_link_hash_entry *) bh;
5840 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
5841 myh->forced_local = 1;
5843 /* The elf32_arm_init_maps function only cares about symbols from input
5844 BFDs. We must make a note of this generated mapping symbol
5845 ourselves so that code byteswapping works properly in
5846 elf32_arm_write_section. */
5847 elf32_arm_section_map_add (s, 'a', 0);
5850 s->size += VFP11_ERRATUM_VENEER_SIZE;
5851 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
5852 hash_table->num_vfp11_fixes++;
5854 /* The offset of the veneer. */
5858 #define ARM_GLUE_SECTION_FLAGS \
5859 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
5860 | SEC_READONLY | SEC_LINKER_CREATED)
5862 /* Create a fake section for use by the ARM backend of the linker. */
5865 arm_make_glue_section (bfd * abfd, const char * name)
5869 sec = bfd_get_section_by_name (abfd, name);
5874 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
5877 || !bfd_set_section_alignment (abfd, sec, 2))
5880 /* Set the gc mark to prevent the section from being removed by garbage
5881 collection, despite the fact that no relocs refer to this section. */
5887 /* Add the glue sections to ABFD. This function is called from the
5888 linker scripts in ld/emultempl/{armelf}.em. */
5891 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
5892 struct bfd_link_info *info)
5894 /* If we are only performing a partial
5895 link do not bother adding the glue. */
5896 if (info->relocatable)
5899 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
5900 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
5901 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
5902 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
5905 /* Select a BFD to be used to hold the sections used by the glue code.
5906 This function is called from the linker scripts in ld/emultempl/
5910 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
5912 struct elf32_arm_link_hash_table *globals;
5914 /* If we are only performing a partial link
5915 do not bother getting a bfd to hold the glue. */
5916 if (info->relocatable)
5919 /* Make sure we don't attach the glue sections to a dynamic object. */
5920 BFD_ASSERT (!(abfd->flags & DYNAMIC));
5922 globals = elf32_arm_hash_table (info);
5923 BFD_ASSERT (globals != NULL);
5925 if (globals->bfd_of_glue_owner != NULL)
5928 /* Save the bfd for later use. */
5929 globals->bfd_of_glue_owner = abfd;
5935 check_use_blx (struct elf32_arm_link_hash_table *globals)
5939 cpu_arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
5942 if (globals->fix_arm1176)
5944 if (cpu_arch == TAG_CPU_ARCH_V6T2 || cpu_arch > TAG_CPU_ARCH_V6K)
5945 globals->use_blx = 1;
5949 if (cpu_arch > TAG_CPU_ARCH_V4T)
5950 globals->use_blx = 1;
5955 bfd_elf32_arm_process_before_allocation (bfd *abfd,
5956 struct bfd_link_info *link_info)
5958 Elf_Internal_Shdr *symtab_hdr;
5959 Elf_Internal_Rela *internal_relocs = NULL;
5960 Elf_Internal_Rela *irel, *irelend;
5961 bfd_byte *contents = NULL;
5964 struct elf32_arm_link_hash_table *globals;
5966 /* If we are only performing a partial link do not bother
5967 to construct any glue. */
5968 if (link_info->relocatable)
5971 /* Here we have a bfd that is to be included on the link. We have a
5972 hook to do reloc rummaging, before section sizes are nailed down. */
5973 globals = elf32_arm_hash_table (link_info);
5974 BFD_ASSERT (globals != NULL);
5976 check_use_blx (globals);
5978 if (globals->byteswap_code && !bfd_big_endian (abfd))
5980 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
5985 /* PR 5398: If we have not decided to include any loadable sections in
5986 the output then we will not have a glue owner bfd. This is OK, it
5987 just means that there is nothing else for us to do here. */
5988 if (globals->bfd_of_glue_owner == NULL)
5991 /* Rummage around all the relocs and map the glue vectors. */
5992 sec = abfd->sections;
5997 for (; sec != NULL; sec = sec->next)
5999 if (sec->reloc_count == 0)
6002 if ((sec->flags & SEC_EXCLUDE) != 0)
6005 symtab_hdr = & elf_symtab_hdr (abfd);
6007 /* Load the relocs. */
6009 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
6011 if (internal_relocs == NULL)
6014 irelend = internal_relocs + sec->reloc_count;
6015 for (irel = internal_relocs; irel < irelend; irel++)
6018 unsigned long r_index;
6020 struct elf_link_hash_entry *h;
6022 r_type = ELF32_R_TYPE (irel->r_info);
6023 r_index = ELF32_R_SYM (irel->r_info);
6025 /* These are the only relocation types we care about. */
6026 if ( r_type != R_ARM_PC24
6027 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
6030 /* Get the section contents if we haven't done so already. */
6031 if (contents == NULL)
6033 /* Get cached copy if it exists. */
6034 if (elf_section_data (sec)->this_hdr.contents != NULL)
6035 contents = elf_section_data (sec)->this_hdr.contents;
6038 /* Go get them off disk. */
6039 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
6044 if (r_type == R_ARM_V4BX)
6048 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
6049 record_arm_bx_glue (link_info, reg);
6053 /* If the relocation is not against a symbol it cannot concern us. */
6056 /* We don't care about local symbols. */
6057 if (r_index < symtab_hdr->sh_info)
6060 /* This is an external symbol. */
6061 r_index -= symtab_hdr->sh_info;
6062 h = (struct elf_link_hash_entry *)
6063 elf_sym_hashes (abfd)[r_index];
6065 /* If the relocation is against a static symbol it must be within
6066 the current section and so cannot be a cross ARM/Thumb relocation. */
6070 /* If the call will go through a PLT entry then we do not need
6072 if (globals->root.splt != NULL && h->plt.offset != (bfd_vma) -1)
6078 /* This one is a call from arm code. We need to look up
6079 the target of the call. If it is a thumb target, we
6081 if (h->target_internal == ST_BRANCH_TO_THUMB)
6082 record_arm_to_thumb_glue (link_info, h);
6090 if (contents != NULL
6091 && elf_section_data (sec)->this_hdr.contents != contents)
6095 if (internal_relocs != NULL
6096 && elf_section_data (sec)->relocs != internal_relocs)
6097 free (internal_relocs);
6098 internal_relocs = NULL;
6104 if (contents != NULL
6105 && elf_section_data (sec)->this_hdr.contents != contents)
6107 if (internal_relocs != NULL
6108 && elf_section_data (sec)->relocs != internal_relocs)
6109 free (internal_relocs);
6116 /* Initialise maps of ARM/Thumb/data for input BFDs. */
6119 bfd_elf32_arm_init_maps (bfd *abfd)
6121 Elf_Internal_Sym *isymbuf;
6122 Elf_Internal_Shdr *hdr;
6123 unsigned int i, localsyms;
6125 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
6126 if (! is_arm_elf (abfd))
6129 if ((abfd->flags & DYNAMIC) != 0)
6132 hdr = & elf_symtab_hdr (abfd);
6133 localsyms = hdr->sh_info;
6135 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
6136 should contain the number of local symbols, which should come before any
6137 global symbols. Mapping symbols are always local. */
6138 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
6141 /* No internal symbols read? Skip this BFD. */
6142 if (isymbuf == NULL)
6145 for (i = 0; i < localsyms; i++)
6147 Elf_Internal_Sym *isym = &isymbuf[i];
6148 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
6152 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
6154 name = bfd_elf_string_from_elf_section (abfd,
6155 hdr->sh_link, isym->st_name);
6157 if (bfd_is_arm_special_symbol_name (name,
6158 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
6159 elf32_arm_section_map_add (sec, name[1], isym->st_value);
6165 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
6166 say what they wanted. */
6169 bfd_elf32_arm_set_cortex_a8_fix (bfd *obfd, struct bfd_link_info *link_info)
6171 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6172 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
6174 if (globals == NULL)
6177 if (globals->fix_cortex_a8 == -1)
6179 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
6180 if (out_attr[Tag_CPU_arch].i == TAG_CPU_ARCH_V7
6181 && (out_attr[Tag_CPU_arch_profile].i == 'A'
6182 || out_attr[Tag_CPU_arch_profile].i == 0))
6183 globals->fix_cortex_a8 = 1;
6185 globals->fix_cortex_a8 = 0;
6191 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
6193 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6194 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
6196 if (globals == NULL)
6198 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
6199 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
6201 switch (globals->vfp11_fix)
6203 case BFD_ARM_VFP11_FIX_DEFAULT:
6204 case BFD_ARM_VFP11_FIX_NONE:
6205 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
6209 /* Give a warning, but do as the user requests anyway. */
6210 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
6211 "workaround is not necessary for target architecture"), obfd);
6214 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
6215 /* For earlier architectures, we might need the workaround, but do not
6216 enable it by default. If users is running with broken hardware, they
6217 must enable the erratum fix explicitly. */
6218 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
6222 enum bfd_arm_vfp11_pipe
6230 /* Return a VFP register number. This is encoded as RX:X for single-precision
6231 registers, or X:RX for double-precision registers, where RX is the group of
6232 four bits in the instruction encoding and X is the single extension bit.
6233 RX and X fields are specified using their lowest (starting) bit. The return
6236 0...31: single-precision registers s0...s31
6237 32...63: double-precision registers d0...d31.
6239 Although X should be zero for VFP11 (encoding d0...d15 only), we might
6240 encounter VFP3 instructions, so we allow the full range for DP registers. */
6243 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
6247 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
6249 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
6252 /* Set bits in *WMASK according to a register number REG as encoded by
6253 bfd_arm_vfp11_regno(). Ignore d16-d31. */
6256 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
6261 *wmask |= 3 << ((reg - 32) * 2);
6264 /* Return TRUE if WMASK overwrites anything in REGS. */
6267 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
6271 for (i = 0; i < numregs; i++)
6273 unsigned int reg = regs[i];
6275 if (reg < 32 && (wmask & (1 << reg)) != 0)
6283 if ((wmask & (3 << (reg * 2))) != 0)
6290 /* In this function, we're interested in two things: finding input registers
6291 for VFP data-processing instructions, and finding the set of registers which
6292 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
6293 hold the written set, so FLDM etc. are easy to deal with (we're only
6294 interested in 32 SP registers or 16 dp registers, due to the VFP version
6295 implemented by the chip in question). DP registers are marked by setting
6296 both SP registers in the write mask). */
6298 static enum bfd_arm_vfp11_pipe
6299 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
6302 enum bfd_arm_vfp11_pipe vpipe = VFP11_BAD;
6303 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
6305 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
6308 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
6309 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
6311 pqrs = ((insn & 0x00800000) >> 20)
6312 | ((insn & 0x00300000) >> 19)
6313 | ((insn & 0x00000040) >> 6);
6317 case 0: /* fmac[sd]. */
6318 case 1: /* fnmac[sd]. */
6319 case 2: /* fmsc[sd]. */
6320 case 3: /* fnmsc[sd]. */
6322 bfd_arm_vfp11_write_mask (destmask, fd);
6324 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
6329 case 4: /* fmul[sd]. */
6330 case 5: /* fnmul[sd]. */
6331 case 6: /* fadd[sd]. */
6332 case 7: /* fsub[sd]. */
6336 case 8: /* fdiv[sd]. */
6339 bfd_arm_vfp11_write_mask (destmask, fd);
6340 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
6345 case 15: /* extended opcode. */
6347 unsigned int extn = ((insn >> 15) & 0x1e)
6348 | ((insn >> 7) & 1);
6352 case 0: /* fcpy[sd]. */
6353 case 1: /* fabs[sd]. */
6354 case 2: /* fneg[sd]. */
6355 case 8: /* fcmp[sd]. */
6356 case 9: /* fcmpe[sd]. */
6357 case 10: /* fcmpz[sd]. */
6358 case 11: /* fcmpez[sd]. */
6359 case 16: /* fuito[sd]. */
6360 case 17: /* fsito[sd]. */
6361 case 24: /* ftoui[sd]. */
6362 case 25: /* ftouiz[sd]. */
6363 case 26: /* ftosi[sd]. */
6364 case 27: /* ftosiz[sd]. */
6365 /* These instructions will not bounce due to underflow. */
6370 case 3: /* fsqrt[sd]. */
6371 /* fsqrt cannot underflow, but it can (perhaps) overwrite
6372 registers to cause the erratum in previous instructions. */
6373 bfd_arm_vfp11_write_mask (destmask, fd);
6377 case 15: /* fcvt{ds,sd}. */
6381 bfd_arm_vfp11_write_mask (destmask, fd);
6383 /* Only FCVTSD can underflow. */
6384 if ((insn & 0x100) != 0)
6403 /* Two-register transfer. */
6404 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
6406 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
6408 if ((insn & 0x100000) == 0)
6411 bfd_arm_vfp11_write_mask (destmask, fm);
6414 bfd_arm_vfp11_write_mask (destmask, fm);
6415 bfd_arm_vfp11_write_mask (destmask, fm + 1);
6421 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
6423 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
6424 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
6428 case 0: /* Two-reg transfer. We should catch these above. */
6431 case 2: /* fldm[sdx]. */
6435 unsigned int i, offset = insn & 0xff;
6440 for (i = fd; i < fd + offset; i++)
6441 bfd_arm_vfp11_write_mask (destmask, i);
6445 case 4: /* fld[sd]. */
6447 bfd_arm_vfp11_write_mask (destmask, fd);
6456 /* Single-register transfer. Note L==0. */
6457 else if ((insn & 0x0f100e10) == 0x0e000a10)
6459 unsigned int opcode = (insn >> 21) & 7;
6460 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
6464 case 0: /* fmsr/fmdlr. */
6465 case 1: /* fmdhr. */
6466 /* Mark fmdhr and fmdlr as writing to the whole of the DP
6467 destination register. I don't know if this is exactly right,
6468 but it is the conservative choice. */
6469 bfd_arm_vfp11_write_mask (destmask, fn);
6483 static int elf32_arm_compare_mapping (const void * a, const void * b);
6486 /* Look for potentially-troublesome code sequences which might trigger the
6487 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
6488 (available from ARM) for details of the erratum. A short version is
6489 described in ld.texinfo. */
6492 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
6495 bfd_byte *contents = NULL;
6497 int regs[3], numregs = 0;
6498 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6499 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
6501 if (globals == NULL)
6504 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
6505 The states transition as follows:
6507 0 -> 1 (vector) or 0 -> 2 (scalar)
6508 A VFP FMAC-pipeline instruction has been seen. Fill
6509 regs[0]..regs[numregs-1] with its input operands. Remember this
6510 instruction in 'first_fmac'.
6513 Any instruction, except for a VFP instruction which overwrites
6518 A VFP instruction has been seen which overwrites any of regs[*].
6519 We must make a veneer! Reset state to 0 before examining next
6523 If we fail to match anything in state 2, reset to state 0 and reset
6524 the instruction pointer to the instruction after 'first_fmac'.
6526 If the VFP11 vector mode is in use, there must be at least two unrelated
6527 instructions between anti-dependent VFP11 instructions to properly avoid
6528 triggering the erratum, hence the use of the extra state 1. */
6530 /* If we are only performing a partial link do not bother
6531 to construct any glue. */
6532 if (link_info->relocatable)
6535 /* Skip if this bfd does not correspond to an ELF image. */
6536 if (! is_arm_elf (abfd))
6539 /* We should have chosen a fix type by the time we get here. */
6540 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
6542 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
6545 /* Skip this BFD if it corresponds to an executable or dynamic object. */
6546 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
6549 for (sec = abfd->sections; sec != NULL; sec = sec->next)
6551 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
6552 struct _arm_elf_section_data *sec_data;
6554 /* If we don't have executable progbits, we're not interested in this
6555 section. Also skip if section is to be excluded. */
6556 if (elf_section_type (sec) != SHT_PROGBITS
6557 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
6558 || (sec->flags & SEC_EXCLUDE) != 0
6559 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
6560 || sec->output_section == bfd_abs_section_ptr
6561 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
6564 sec_data = elf32_arm_section_data (sec);
6566 if (sec_data->mapcount == 0)
6569 if (elf_section_data (sec)->this_hdr.contents != NULL)
6570 contents = elf_section_data (sec)->this_hdr.contents;
6571 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
6574 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
6575 elf32_arm_compare_mapping);
6577 for (span = 0; span < sec_data->mapcount; span++)
6579 unsigned int span_start = sec_data->map[span].vma;
6580 unsigned int span_end = (span == sec_data->mapcount - 1)
6581 ? sec->size : sec_data->map[span + 1].vma;
6582 char span_type = sec_data->map[span].type;
6584 /* FIXME: Only ARM mode is supported at present. We may need to
6585 support Thumb-2 mode also at some point. */
6586 if (span_type != 'a')
6589 for (i = span_start; i < span_end;)
6591 unsigned int next_i = i + 4;
6592 unsigned int insn = bfd_big_endian (abfd)
6593 ? (contents[i] << 24)
6594 | (contents[i + 1] << 16)
6595 | (contents[i + 2] << 8)
6597 : (contents[i + 3] << 24)
6598 | (contents[i + 2] << 16)
6599 | (contents[i + 1] << 8)
6601 unsigned int writemask = 0;
6602 enum bfd_arm_vfp11_pipe vpipe;
6607 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
6609 /* I'm assuming the VFP11 erratum can trigger with denorm
6610 operands on either the FMAC or the DS pipeline. This might
6611 lead to slightly overenthusiastic veneer insertion. */
6612 if (vpipe == VFP11_FMAC || vpipe == VFP11_DS)
6614 state = use_vector ? 1 : 2;
6616 veneer_of_insn = insn;
6622 int other_regs[3], other_numregs;
6623 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
6626 if (vpipe != VFP11_BAD
6627 && bfd_arm_vfp11_antidependency (writemask, regs,
6637 int other_regs[3], other_numregs;
6638 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
6641 if (vpipe != VFP11_BAD
6642 && bfd_arm_vfp11_antidependency (writemask, regs,
6648 next_i = first_fmac + 4;
6654 abort (); /* Should be unreachable. */
6659 elf32_vfp11_erratum_list *newerr =(elf32_vfp11_erratum_list *)
6660 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
6662 elf32_arm_section_data (sec)->erratumcount += 1;
6664 newerr->u.b.vfp_insn = veneer_of_insn;
6669 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
6676 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
6681 newerr->next = sec_data->erratumlist;
6682 sec_data->erratumlist = newerr;
6691 if (contents != NULL
6692 && elf_section_data (sec)->this_hdr.contents != contents)
6700 if (contents != NULL
6701 && elf_section_data (sec)->this_hdr.contents != contents)
6707 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
6708 after sections have been laid out, using specially-named symbols. */
6711 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
6712 struct bfd_link_info *link_info)
6715 struct elf32_arm_link_hash_table *globals;
6718 if (link_info->relocatable)
6721 /* Skip if this bfd does not correspond to an ELF image. */
6722 if (! is_arm_elf (abfd))
6725 globals = elf32_arm_hash_table (link_info);
6726 if (globals == NULL)
6729 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
6730 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
6732 for (sec = abfd->sections; sec != NULL; sec = sec->next)
6734 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
6735 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
6737 for (; errnode != NULL; errnode = errnode->next)
6739 struct elf_link_hash_entry *myh;
6742 switch (errnode->type)
6744 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
6745 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
6746 /* Find veneer symbol. */
6747 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
6748 errnode->u.b.veneer->u.v.id);
6750 myh = elf_link_hash_lookup
6751 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
6754 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
6755 "`%s'"), abfd, tmp_name);
6757 vma = myh->root.u.def.section->output_section->vma
6758 + myh->root.u.def.section->output_offset
6759 + myh->root.u.def.value;
6761 errnode->u.b.veneer->vma = vma;
6764 case VFP11_ERRATUM_ARM_VENEER:
6765 case VFP11_ERRATUM_THUMB_VENEER:
6766 /* Find return location. */
6767 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
6770 myh = elf_link_hash_lookup
6771 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
6774 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
6775 "`%s'"), abfd, tmp_name);
6777 vma = myh->root.u.def.section->output_section->vma
6778 + myh->root.u.def.section->output_offset
6779 + myh->root.u.def.value;
6781 errnode->u.v.branch->vma = vma;
6794 /* Set target relocation values needed during linking. */
6797 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
6798 struct bfd_link_info *link_info,
6800 char * target2_type,
6803 bfd_arm_vfp11_fix vfp11_fix,
6804 int no_enum_warn, int no_wchar_warn,
6805 int pic_veneer, int fix_cortex_a8,
6808 struct elf32_arm_link_hash_table *globals;
6810 globals = elf32_arm_hash_table (link_info);
6811 if (globals == NULL)
6814 globals->target1_is_rel = target1_is_rel;
6815 if (strcmp (target2_type, "rel") == 0)
6816 globals->target2_reloc = R_ARM_REL32;
6817 else if (strcmp (target2_type, "abs") == 0)
6818 globals->target2_reloc = R_ARM_ABS32;
6819 else if (strcmp (target2_type, "got-rel") == 0)
6820 globals->target2_reloc = R_ARM_GOT_PREL;
6823 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
6826 globals->fix_v4bx = fix_v4bx;
6827 globals->use_blx |= use_blx;
6828 globals->vfp11_fix = vfp11_fix;
6829 globals->pic_veneer = pic_veneer;
6830 globals->fix_cortex_a8 = fix_cortex_a8;
6831 globals->fix_arm1176 = fix_arm1176;
6833 BFD_ASSERT (is_arm_elf (output_bfd));
6834 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
6835 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
6838 /* Replace the target offset of a Thumb bl or b.w instruction. */
6841 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
6847 BFD_ASSERT ((offset & 1) == 0);
6849 upper = bfd_get_16 (abfd, insn);
6850 lower = bfd_get_16 (abfd, insn + 2);
6851 reloc_sign = (offset < 0) ? 1 : 0;
6852 upper = (upper & ~(bfd_vma) 0x7ff)
6853 | ((offset >> 12) & 0x3ff)
6854 | (reloc_sign << 10);
6855 lower = (lower & ~(bfd_vma) 0x2fff)
6856 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
6857 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
6858 | ((offset >> 1) & 0x7ff);
6859 bfd_put_16 (abfd, upper, insn);
6860 bfd_put_16 (abfd, lower, insn + 2);
6863 /* Thumb code calling an ARM function. */
6866 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
6870 asection * input_section,
6871 bfd_byte * hit_data,
6874 bfd_signed_vma addend,
6876 char **error_message)
6880 long int ret_offset;
6881 struct elf_link_hash_entry * myh;
6882 struct elf32_arm_link_hash_table * globals;
6884 myh = find_thumb_glue (info, name, error_message);
6888 globals = elf32_arm_hash_table (info);
6889 BFD_ASSERT (globals != NULL);
6890 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
6892 my_offset = myh->root.u.def.value;
6894 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
6895 THUMB2ARM_GLUE_SECTION_NAME);
6897 BFD_ASSERT (s != NULL);
6898 BFD_ASSERT (s->contents != NULL);
6899 BFD_ASSERT (s->output_section != NULL);
6901 if ((my_offset & 0x01) == 0x01)
6904 && sym_sec->owner != NULL
6905 && !INTERWORK_FLAG (sym_sec->owner))
6907 (*_bfd_error_handler)
6908 (_("%B(%s): warning: interworking not enabled.\n"
6909 " first occurrence: %B: thumb call to arm"),
6910 sym_sec->owner, input_bfd, name);
6916 myh->root.u.def.value = my_offset;
6918 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
6919 s->contents + my_offset);
6921 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
6922 s->contents + my_offset + 2);
6925 /* Address of destination of the stub. */
6926 ((bfd_signed_vma) val)
6928 /* Offset from the start of the current section
6929 to the start of the stubs. */
6931 /* Offset of the start of this stub from the start of the stubs. */
6933 /* Address of the start of the current section. */
6934 + s->output_section->vma)
6935 /* The branch instruction is 4 bytes into the stub. */
6937 /* ARM branches work from the pc of the instruction + 8. */
6940 put_arm_insn (globals, output_bfd,
6941 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
6942 s->contents + my_offset + 4);
6945 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
6947 /* Now go back and fix up the original BL insn to point to here. */
6949 /* Address of where the stub is located. */
6950 (s->output_section->vma + s->output_offset + my_offset)
6951 /* Address of where the BL is located. */
6952 - (input_section->output_section->vma + input_section->output_offset
6954 /* Addend in the relocation. */
6956 /* Biassing for PC-relative addressing. */
6959 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
6964 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
6966 static struct elf_link_hash_entry *
6967 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
6974 char ** error_message)
6977 long int ret_offset;
6978 struct elf_link_hash_entry * myh;
6979 struct elf32_arm_link_hash_table * globals;
6981 myh = find_arm_glue (info, name, error_message);
6985 globals = elf32_arm_hash_table (info);
6986 BFD_ASSERT (globals != NULL);
6987 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
6989 my_offset = myh->root.u.def.value;
6991 if ((my_offset & 0x01) == 0x01)
6994 && sym_sec->owner != NULL
6995 && !INTERWORK_FLAG (sym_sec->owner))
6997 (*_bfd_error_handler)
6998 (_("%B(%s): warning: interworking not enabled.\n"
6999 " first occurrence: %B: arm call to thumb"),
7000 sym_sec->owner, input_bfd, name);
7004 myh->root.u.def.value = my_offset;
7006 if (info->shared || globals->root.is_relocatable_executable
7007 || globals->pic_veneer)
7009 /* For relocatable objects we can't use absolute addresses,
7010 so construct the address from a relative offset. */
7011 /* TODO: If the offset is small it's probably worth
7012 constructing the address with adds. */
7013 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
7014 s->contents + my_offset);
7015 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
7016 s->contents + my_offset + 4);
7017 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
7018 s->contents + my_offset + 8);
7019 /* Adjust the offset by 4 for the position of the add,
7020 and 8 for the pipeline offset. */
7021 ret_offset = (val - (s->output_offset
7022 + s->output_section->vma
7025 bfd_put_32 (output_bfd, ret_offset,
7026 s->contents + my_offset + 12);
7028 else if (globals->use_blx)
7030 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
7031 s->contents + my_offset);
7033 /* It's a thumb address. Add the low order bit. */
7034 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
7035 s->contents + my_offset + 4);
7039 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
7040 s->contents + my_offset);
7042 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
7043 s->contents + my_offset + 4);
7045 /* It's a thumb address. Add the low order bit. */
7046 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
7047 s->contents + my_offset + 8);
7053 BFD_ASSERT (my_offset <= globals->arm_glue_size);
7058 /* Arm code calling a Thumb function. */
7061 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
7065 asection * input_section,
7066 bfd_byte * hit_data,
7069 bfd_signed_vma addend,
7071 char **error_message)
7073 unsigned long int tmp;
7076 long int ret_offset;
7077 struct elf_link_hash_entry * myh;
7078 struct elf32_arm_link_hash_table * globals;
7080 globals = elf32_arm_hash_table (info);
7081 BFD_ASSERT (globals != NULL);
7082 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7084 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
7085 ARM2THUMB_GLUE_SECTION_NAME);
7086 BFD_ASSERT (s != NULL);
7087 BFD_ASSERT (s->contents != NULL);
7088 BFD_ASSERT (s->output_section != NULL);
7090 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
7091 sym_sec, val, s, error_message);
7095 my_offset = myh->root.u.def.value;
7096 tmp = bfd_get_32 (input_bfd, hit_data);
7097 tmp = tmp & 0xFF000000;
7099 /* Somehow these are both 4 too far, so subtract 8. */
7100 ret_offset = (s->output_offset
7102 + s->output_section->vma
7103 - (input_section->output_offset
7104 + input_section->output_section->vma
7108 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
7110 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
7115 /* Populate Arm stub for an exported Thumb function. */
7118 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
7120 struct bfd_link_info * info = (struct bfd_link_info *) inf;
7122 struct elf_link_hash_entry * myh;
7123 struct elf32_arm_link_hash_entry *eh;
7124 struct elf32_arm_link_hash_table * globals;
7127 char *error_message;
7129 eh = elf32_arm_hash_entry (h);
7130 /* Allocate stubs for exported Thumb functions on v4t. */
7131 if (eh->export_glue == NULL)
7134 globals = elf32_arm_hash_table (info);
7135 BFD_ASSERT (globals != NULL);
7136 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7138 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
7139 ARM2THUMB_GLUE_SECTION_NAME);
7140 BFD_ASSERT (s != NULL);
7141 BFD_ASSERT (s->contents != NULL);
7142 BFD_ASSERT (s->output_section != NULL);
7144 sec = eh->export_glue->root.u.def.section;
7146 BFD_ASSERT (sec->output_section != NULL);
7148 val = eh->export_glue->root.u.def.value + sec->output_offset
7149 + sec->output_section->vma;
7151 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
7152 h->root.u.def.section->owner,
7153 globals->obfd, sec, val, s,
7159 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
7162 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
7167 struct elf32_arm_link_hash_table *globals;
7169 globals = elf32_arm_hash_table (info);
7170 BFD_ASSERT (globals != NULL);
7171 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7173 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
7174 ARM_BX_GLUE_SECTION_NAME);
7175 BFD_ASSERT (s != NULL);
7176 BFD_ASSERT (s->contents != NULL);
7177 BFD_ASSERT (s->output_section != NULL);
7179 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
7181 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
7183 if ((globals->bx_glue_offset[reg] & 1) == 0)
7185 p = s->contents + glue_addr;
7186 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
7187 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
7188 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
7189 globals->bx_glue_offset[reg] |= 1;
7192 return glue_addr + s->output_section->vma + s->output_offset;
7195 /* Generate Arm stubs for exported Thumb symbols. */
7197 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
7198 struct bfd_link_info *link_info)
7200 struct elf32_arm_link_hash_table * globals;
7202 if (link_info == NULL)
7203 /* Ignore this if we are not called by the ELF backend linker. */
7206 globals = elf32_arm_hash_table (link_info);
7207 if (globals == NULL)
7210 /* If blx is available then exported Thumb symbols are OK and there is
7212 if (globals->use_blx)
7215 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
7219 /* Reserve space for COUNT dynamic relocations in relocation selection
7223 elf32_arm_allocate_dynrelocs (struct bfd_link_info *info, asection *sreloc,
7224 bfd_size_type count)
7226 struct elf32_arm_link_hash_table *htab;
7228 htab = elf32_arm_hash_table (info);
7229 BFD_ASSERT (htab->root.dynamic_sections_created);
7232 sreloc->size += RELOC_SIZE (htab) * count;
7235 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
7236 dynamic, the relocations should go in SRELOC, otherwise they should
7237 go in the special .rel.iplt section. */
7240 elf32_arm_allocate_irelocs (struct bfd_link_info *info, asection *sreloc,
7241 bfd_size_type count)
7243 struct elf32_arm_link_hash_table *htab;
7245 htab = elf32_arm_hash_table (info);
7246 if (!htab->root.dynamic_sections_created)
7247 htab->root.irelplt->size += RELOC_SIZE (htab) * count;
7250 BFD_ASSERT (sreloc != NULL);
7251 sreloc->size += RELOC_SIZE (htab) * count;
7255 /* Add relocation REL to the end of relocation section SRELOC. */
7258 elf32_arm_add_dynreloc (bfd *output_bfd, struct bfd_link_info *info,
7259 asection *sreloc, Elf_Internal_Rela *rel)
7262 struct elf32_arm_link_hash_table *htab;
7264 htab = elf32_arm_hash_table (info);
7265 if (!htab->root.dynamic_sections_created
7266 && ELF32_R_TYPE (rel->r_info) == R_ARM_IRELATIVE)
7267 sreloc = htab->root.irelplt;
7270 loc = sreloc->contents;
7271 loc += sreloc->reloc_count++ * RELOC_SIZE (htab);
7272 if (sreloc->reloc_count * RELOC_SIZE (htab) > sreloc->size)
7274 SWAP_RELOC_OUT (htab) (output_bfd, rel, loc);
7277 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
7278 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
7282 elf32_arm_allocate_plt_entry (struct bfd_link_info *info,
7283 bfd_boolean is_iplt_entry,
7284 union gotplt_union *root_plt,
7285 struct arm_plt_info *arm_plt)
7287 struct elf32_arm_link_hash_table *htab;
7291 htab = elf32_arm_hash_table (info);
7295 splt = htab->root.iplt;
7296 sgotplt = htab->root.igotplt;
7298 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
7299 elf32_arm_allocate_irelocs (info, htab->root.irelplt, 1);
7303 splt = htab->root.splt;
7304 sgotplt = htab->root.sgotplt;
7306 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
7307 elf32_arm_allocate_dynrelocs (info, htab->root.srelplt, 1);
7309 /* If this is the first .plt entry, make room for the special
7311 if (splt->size == 0)
7312 splt->size += htab->plt_header_size;
7315 /* Allocate the PLT entry itself, including any leading Thumb stub. */
7316 if (elf32_arm_plt_needs_thumb_stub_p (info, arm_plt))
7317 splt->size += PLT_THUMB_STUB_SIZE;
7318 root_plt->offset = splt->size;
7319 splt->size += htab->plt_entry_size;
7321 if (!htab->symbian_p)
7323 /* We also need to make an entry in the .got.plt section, which
7324 will be placed in the .got section by the linker script. */
7325 arm_plt->got_offset = sgotplt->size - 8 * htab->num_tls_desc;
7330 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
7331 the entry lives in .iplt and resolves to (*SYM_VALUE)().
7332 Otherwise, DYNINDX is the index of the symbol in the dynamic
7333 symbol table and SYM_VALUE is undefined.
7335 ROOT_PLT points to the offset of the PLT entry from the start of its
7336 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
7337 bookkeeping information. */
7340 elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
7341 union gotplt_union *root_plt,
7342 struct arm_plt_info *arm_plt,
7343 int dynindx, bfd_vma sym_value)
7345 struct elf32_arm_link_hash_table *htab;
7351 Elf_Internal_Rela rel;
7352 bfd_vma plt_header_size;
7353 bfd_vma got_header_size;
7355 htab = elf32_arm_hash_table (info);
7357 /* Pick the appropriate sections and sizes. */
7360 splt = htab->root.iplt;
7361 sgot = htab->root.igotplt;
7362 srel = htab->root.irelplt;
7364 /* There are no reserved entries in .igot.plt, and no special
7365 first entry in .iplt. */
7366 got_header_size = 0;
7367 plt_header_size = 0;
7371 splt = htab->root.splt;
7372 sgot = htab->root.sgotplt;
7373 srel = htab->root.srelplt;
7375 got_header_size = get_elf_backend_data (output_bfd)->got_header_size;
7376 plt_header_size = htab->plt_header_size;
7378 BFD_ASSERT (splt != NULL && srel != NULL);
7380 /* Fill in the entry in the procedure linkage table. */
7381 if (htab->symbian_p)
7383 BFD_ASSERT (dynindx >= 0);
7384 put_arm_insn (htab, output_bfd,
7385 elf32_arm_symbian_plt_entry[0],
7386 splt->contents + root_plt->offset);
7387 bfd_put_32 (output_bfd,
7388 elf32_arm_symbian_plt_entry[1],
7389 splt->contents + root_plt->offset + 4);
7391 /* Fill in the entry in the .rel.plt section. */
7392 rel.r_offset = (splt->output_section->vma
7393 + splt->output_offset
7394 + root_plt->offset + 4);
7395 rel.r_info = ELF32_R_INFO (dynindx, R_ARM_GLOB_DAT);
7397 /* Get the index in the procedure linkage table which
7398 corresponds to this symbol. This is the index of this symbol
7399 in all the symbols for which we are making plt entries. The
7400 first entry in the procedure linkage table is reserved. */
7401 plt_index = ((root_plt->offset - plt_header_size)
7402 / htab->plt_entry_size);
7406 bfd_vma got_offset, got_address, plt_address;
7407 bfd_vma got_displacement, initial_got_entry;
7410 BFD_ASSERT (sgot != NULL);
7412 /* Get the offset into the .(i)got.plt table of the entry that
7413 corresponds to this function. */
7414 got_offset = (arm_plt->got_offset & -2);
7416 /* Get the index in the procedure linkage table which
7417 corresponds to this symbol. This is the index of this symbol
7418 in all the symbols for which we are making plt entries.
7419 After the reserved .got.plt entries, all symbols appear in
7420 the same order as in .plt. */
7421 plt_index = (got_offset - got_header_size) / 4;
7423 /* Calculate the address of the GOT entry. */
7424 got_address = (sgot->output_section->vma
7425 + sgot->output_offset
7428 /* ...and the address of the PLT entry. */
7429 plt_address = (splt->output_section->vma
7430 + splt->output_offset
7431 + root_plt->offset);
7433 ptr = splt->contents + root_plt->offset;
7434 if (htab->vxworks_p && info->shared)
7439 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
7441 val = elf32_arm_vxworks_shared_plt_entry[i];
7443 val |= got_address - sgot->output_section->vma;
7445 val |= plt_index * RELOC_SIZE (htab);
7446 if (i == 2 || i == 5)
7447 bfd_put_32 (output_bfd, val, ptr);
7449 put_arm_insn (htab, output_bfd, val, ptr);
7452 else if (htab->vxworks_p)
7457 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
7459 val = elf32_arm_vxworks_exec_plt_entry[i];
7463 val |= 0xffffff & -((root_plt->offset + i * 4 + 8) >> 2);
7465 val |= plt_index * RELOC_SIZE (htab);
7466 if (i == 2 || i == 5)
7467 bfd_put_32 (output_bfd, val, ptr);
7469 put_arm_insn (htab, output_bfd, val, ptr);
7472 loc = (htab->srelplt2->contents
7473 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
7475 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
7476 referencing the GOT for this PLT entry. */
7477 rel.r_offset = plt_address + 8;
7478 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
7479 rel.r_addend = got_offset;
7480 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7481 loc += RELOC_SIZE (htab);
7483 /* Create the R_ARM_ABS32 relocation referencing the
7484 beginning of the PLT for this GOT entry. */
7485 rel.r_offset = got_address;
7486 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
7488 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7492 /* Calculate the displacement between the PLT slot and the
7493 entry in the GOT. The eight-byte offset accounts for the
7494 value produced by adding to pc in the first instruction
7496 got_displacement = got_address - (plt_address + 8);
7498 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
7500 if (elf32_arm_plt_needs_thumb_stub_p (info, arm_plt))
7502 put_thumb_insn (htab, output_bfd,
7503 elf32_arm_plt_thumb_stub[0], ptr - 4);
7504 put_thumb_insn (htab, output_bfd,
7505 elf32_arm_plt_thumb_stub[1], ptr - 2);
7508 put_arm_insn (htab, output_bfd,
7509 elf32_arm_plt_entry[0]
7510 | ((got_displacement & 0x0ff00000) >> 20),
7512 put_arm_insn (htab, output_bfd,
7513 elf32_arm_plt_entry[1]
7514 | ((got_displacement & 0x000ff000) >> 12),
7516 put_arm_insn (htab, output_bfd,
7517 elf32_arm_plt_entry[2]
7518 | (got_displacement & 0x00000fff),
7520 #ifdef FOUR_WORD_PLT
7521 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
7525 /* Fill in the entry in the .rel(a).(i)plt section. */
7526 rel.r_offset = got_address;
7530 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
7531 The dynamic linker or static executable then calls SYM_VALUE
7532 to determine the correct run-time value of the .igot.plt entry. */
7533 rel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
7534 initial_got_entry = sym_value;
7538 rel.r_info = ELF32_R_INFO (dynindx, R_ARM_JUMP_SLOT);
7539 initial_got_entry = (splt->output_section->vma
7540 + splt->output_offset);
7543 /* Fill in the entry in the global offset table. */
7544 bfd_put_32 (output_bfd, initial_got_entry,
7545 sgot->contents + got_offset);
7548 loc = srel->contents + plt_index * RELOC_SIZE (htab);
7549 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7552 /* Some relocations map to different relocations depending on the
7553 target. Return the real relocation. */
7556 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
7562 if (globals->target1_is_rel)
7568 return globals->target2_reloc;
7575 /* Return the base VMA address which should be subtracted from real addresses
7576 when resolving @dtpoff relocation.
7577 This is PT_TLS segment p_vaddr. */
7580 dtpoff_base (struct bfd_link_info *info)
7582 /* If tls_sec is NULL, we should have signalled an error already. */
7583 if (elf_hash_table (info)->tls_sec == NULL)
7585 return elf_hash_table (info)->tls_sec->vma;
7588 /* Return the relocation value for @tpoff relocation
7589 if STT_TLS virtual address is ADDRESS. */
7592 tpoff (struct bfd_link_info *info, bfd_vma address)
7594 struct elf_link_hash_table *htab = elf_hash_table (info);
7597 /* If tls_sec is NULL, we should have signalled an error already. */
7598 if (htab->tls_sec == NULL)
7600 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
7601 return address - htab->tls_sec->vma + base;
7604 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
7605 VALUE is the relocation value. */
7607 static bfd_reloc_status_type
7608 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
7611 return bfd_reloc_overflow;
7613 value |= bfd_get_32 (abfd, data) & 0xfffff000;
7614 bfd_put_32 (abfd, value, data);
7615 return bfd_reloc_ok;
7618 /* Handle TLS relaxations. Relaxing is possible for symbols that use
7619 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
7620 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
7622 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
7623 is to then call final_link_relocate. Return other values in the
7626 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
7627 the pre-relaxed code. It would be nice if the relocs were updated
7628 to match the optimization. */
7630 static bfd_reloc_status_type
7631 elf32_arm_tls_relax (struct elf32_arm_link_hash_table *globals,
7632 bfd *input_bfd, asection *input_sec, bfd_byte *contents,
7633 Elf_Internal_Rela *rel, unsigned long is_local)
7637 switch (ELF32_R_TYPE (rel->r_info))
7640 return bfd_reloc_notsupported;
7642 case R_ARM_TLS_GOTDESC:
7647 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
7649 insn -= 5; /* THUMB */
7651 insn -= 8; /* ARM */
7653 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
7654 return bfd_reloc_continue;
7656 case R_ARM_THM_TLS_DESCSEQ:
7658 insn = bfd_get_16 (input_bfd, contents + rel->r_offset);
7659 if ((insn & 0xff78) == 0x4478) /* add rx, pc */
7663 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
7665 else if ((insn & 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
7669 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
7672 bfd_put_16 (input_bfd, insn & 0xf83f, contents + rel->r_offset);
7674 else if ((insn & 0xff87) == 0x4780) /* blx rx */
7678 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
7681 bfd_put_16 (input_bfd, 0x4600 | (insn & 0x78),
7682 contents + rel->r_offset);
7686 if ((insn & 0xf000) == 0xf000 || (insn & 0xf800) == 0xe800)
7687 /* It's a 32 bit instruction, fetch the rest of it for
7688 error generation. */
7690 | bfd_get_16 (input_bfd, contents + rel->r_offset + 2);
7691 (*_bfd_error_handler)
7692 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' in TLS trampoline"),
7693 input_bfd, input_sec, (unsigned long)rel->r_offset, insn);
7694 return bfd_reloc_notsupported;
7698 case R_ARM_TLS_DESCSEQ:
7700 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
7701 if ((insn & 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
7705 bfd_put_32 (input_bfd, 0xe1a00000 | (insn & 0xffff),
7706 contents + rel->r_offset);
7708 else if ((insn & 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
7712 bfd_put_32 (input_bfd, 0xe1a00000, contents + rel->r_offset);
7715 bfd_put_32 (input_bfd, insn & 0xfffff000,
7716 contents + rel->r_offset);
7718 else if ((insn & 0xfffffff0) == 0xe12fff30) /* blx rx */
7722 bfd_put_32 (input_bfd, 0xe1a00000, contents + rel->r_offset);
7725 bfd_put_32 (input_bfd, 0xe1a00000 | (insn & 0xf),
7726 contents + rel->r_offset);
7730 (*_bfd_error_handler)
7731 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' in TLS trampoline"),
7732 input_bfd, input_sec, (unsigned long)rel->r_offset, insn);
7733 return bfd_reloc_notsupported;
7737 case R_ARM_TLS_CALL:
7738 /* GD->IE relaxation, turn the instruction into 'nop' or
7739 'ldr r0, [pc,r0]' */
7740 insn = is_local ? 0xe1a00000 : 0xe79f0000;
7741 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
7744 case R_ARM_THM_TLS_CALL:
7745 /* GD->IE relaxation */
7747 /* add r0,pc; ldr r0, [r0] */
7749 else if (arch_has_thumb2_nop (globals))
7756 bfd_put_16 (input_bfd, insn >> 16, contents + rel->r_offset);
7757 bfd_put_16 (input_bfd, insn & 0xffff, contents + rel->r_offset + 2);
7760 return bfd_reloc_ok;
7763 /* For a given value of n, calculate the value of G_n as required to
7764 deal with group relocations. We return it in the form of an
7765 encoded constant-and-rotation, together with the final residual. If n is
7766 specified as less than zero, then final_residual is filled with the
7767 input value and no further action is performed. */
7770 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
7774 bfd_vma encoded_g_n = 0;
7775 bfd_vma residual = value; /* Also known as Y_n. */
7777 for (current_n = 0; current_n <= n; current_n++)
7781 /* Calculate which part of the value to mask. */
7788 /* Determine the most significant bit in the residual and
7789 align the resulting value to a 2-bit boundary. */
7790 for (msb = 30; msb >= 0; msb -= 2)
7791 if (residual & (3 << msb))
7794 /* The desired shift is now (msb - 6), or zero, whichever
7801 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
7802 g_n = residual & (0xff << shift);
7803 encoded_g_n = (g_n >> shift)
7804 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
7806 /* Calculate the residual for the next time around. */
7810 *final_residual = residual;
7815 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
7816 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
7819 identify_add_or_sub (bfd_vma insn)
7821 int opcode = insn & 0x1e00000;
7823 if (opcode == 1 << 23) /* ADD */
7826 if (opcode == 1 << 22) /* SUB */
7832 /* Perform a relocation as part of a final link. */
7834 static bfd_reloc_status_type
7835 elf32_arm_final_link_relocate (reloc_howto_type * howto,
7838 asection * input_section,
7839 bfd_byte * contents,
7840 Elf_Internal_Rela * rel,
7842 struct bfd_link_info * info,
7844 const char * sym_name,
7845 unsigned char st_type,
7846 enum arm_st_branch_type branch_type,
7847 struct elf_link_hash_entry * h,
7848 bfd_boolean * unresolved_reloc_p,
7849 char ** error_message)
7851 unsigned long r_type = howto->type;
7852 unsigned long r_symndx;
7853 bfd_byte * hit_data = contents + rel->r_offset;
7854 bfd_vma * local_got_offsets;
7855 bfd_vma * local_tlsdesc_gotents;
7858 asection * sreloc = NULL;
7861 bfd_signed_vma signed_addend;
7862 unsigned char dynreloc_st_type;
7863 bfd_vma dynreloc_value;
7864 struct elf32_arm_link_hash_table * globals;
7865 struct elf32_arm_link_hash_entry *eh;
7866 union gotplt_union *root_plt;
7867 struct arm_plt_info *arm_plt;
7869 bfd_vma gotplt_offset;
7870 bfd_boolean has_iplt_entry;
7872 globals = elf32_arm_hash_table (info);
7873 if (globals == NULL)
7874 return bfd_reloc_notsupported;
7876 BFD_ASSERT (is_arm_elf (input_bfd));
7878 /* Some relocation types map to different relocations depending on the
7879 target. We pick the right one here. */
7880 r_type = arm_real_reloc_type (globals, r_type);
7882 /* It is possible to have linker relaxations on some TLS access
7883 models. Update our information here. */
7884 r_type = elf32_arm_tls_transition (info, r_type, h);
7886 if (r_type != howto->type)
7887 howto = elf32_arm_howto_from_type (r_type);
7889 /* If the start address has been set, then set the EF_ARM_HASENTRY
7890 flag. Setting this more than once is redundant, but the cost is
7891 not too high, and it keeps the code simple.
7893 The test is done here, rather than somewhere else, because the
7894 start address is only set just before the final link commences.
7896 Note - if the user deliberately sets a start address of 0, the
7897 flag will not be set. */
7898 if (bfd_get_start_address (output_bfd) != 0)
7899 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
7901 eh = (struct elf32_arm_link_hash_entry *) h;
7902 sgot = globals->root.sgot;
7903 local_got_offsets = elf_local_got_offsets (input_bfd);
7904 local_tlsdesc_gotents = elf32_arm_local_tlsdesc_gotent (input_bfd);
7906 if (globals->root.dynamic_sections_created)
7907 srelgot = globals->root.srelgot;
7911 r_symndx = ELF32_R_SYM (rel->r_info);
7913 if (globals->use_rel)
7915 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
7917 if (addend & ((howto->src_mask + 1) >> 1))
7920 signed_addend &= ~ howto->src_mask;
7921 signed_addend |= addend;
7924 signed_addend = addend;
7927 addend = signed_addend = rel->r_addend;
7929 /* Record the symbol information that should be used in dynamic
7931 dynreloc_st_type = st_type;
7932 dynreloc_value = value;
7933 if (branch_type == ST_BRANCH_TO_THUMB)
7934 dynreloc_value |= 1;
7936 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
7937 VALUE appropriately for relocations that we resolve at link time. */
7938 has_iplt_entry = FALSE;
7939 if (elf32_arm_get_plt_info (input_bfd, eh, r_symndx, &root_plt, &arm_plt)
7940 && root_plt->offset != (bfd_vma) -1)
7942 plt_offset = root_plt->offset;
7943 gotplt_offset = arm_plt->got_offset;
7945 if (h == NULL || eh->is_iplt)
7947 has_iplt_entry = TRUE;
7948 splt = globals->root.iplt;
7950 /* Populate .iplt entries here, because not all of them will
7951 be seen by finish_dynamic_symbol. The lower bit is set if
7952 we have already populated the entry. */
7957 elf32_arm_populate_plt_entry (output_bfd, info, root_plt, arm_plt,
7958 -1, dynreloc_value);
7959 root_plt->offset |= 1;
7962 /* Static relocations always resolve to the .iplt entry. */
7964 value = (splt->output_section->vma
7965 + splt->output_offset
7967 branch_type = ST_BRANCH_TO_ARM;
7969 /* If there are non-call relocations that resolve to the .iplt
7970 entry, then all dynamic ones must too. */
7971 if (arm_plt->noncall_refcount != 0)
7973 dynreloc_st_type = st_type;
7974 dynreloc_value = value;
7978 /* We populate the .plt entry in finish_dynamic_symbol. */
7979 splt = globals->root.splt;
7984 plt_offset = (bfd_vma) -1;
7985 gotplt_offset = (bfd_vma) -1;
7991 /* We don't need to find a value for this symbol. It's just a
7993 *unresolved_reloc_p = FALSE;
7994 return bfd_reloc_ok;
7997 if (!globals->vxworks_p)
7998 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
8002 case R_ARM_ABS32_NOI:
8004 case R_ARM_REL32_NOI:
8010 /* Handle relocations which should use the PLT entry. ABS32/REL32
8011 will use the symbol's value, which may point to a PLT entry, but we
8012 don't need to handle that here. If we created a PLT entry, all
8013 branches in this object should go to it, except if the PLT is too
8014 far away, in which case a long branch stub should be inserted. */
8015 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
8016 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI
8017 && r_type != R_ARM_CALL
8018 && r_type != R_ARM_JUMP24
8019 && r_type != R_ARM_PLT32)
8020 && plt_offset != (bfd_vma) -1)
8022 /* If we've created a .plt section, and assigned a PLT entry
8023 to this function, it must either be a STT_GNU_IFUNC reference
8024 or not be known to bind locally. In other cases, we should
8025 have cleared the PLT entry by now. */
8026 BFD_ASSERT (has_iplt_entry || !SYMBOL_CALLS_LOCAL (info, h));
8028 value = (splt->output_section->vma
8029 + splt->output_offset
8031 *unresolved_reloc_p = FALSE;
8032 return _bfd_final_link_relocate (howto, input_bfd, input_section,
8033 contents, rel->r_offset, value,
8037 /* When generating a shared object or relocatable executable, these
8038 relocations are copied into the output file to be resolved at
8040 if ((info->shared || globals->root.is_relocatable_executable)
8041 && (input_section->flags & SEC_ALLOC)
8042 && !(globals->vxworks_p
8043 && strcmp (input_section->output_section->name,
8045 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
8046 || !SYMBOL_CALLS_LOCAL (info, h))
8047 && (!strstr (input_section->name, STUB_SUFFIX))
8049 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8050 || h->root.type != bfd_link_hash_undefweak)
8051 && r_type != R_ARM_PC24
8052 && r_type != R_ARM_CALL
8053 && r_type != R_ARM_JUMP24
8054 && r_type != R_ARM_PREL31
8055 && r_type != R_ARM_PLT32)
8057 Elf_Internal_Rela outrel;
8058 bfd_boolean skip, relocate;
8060 *unresolved_reloc_p = FALSE;
8062 if (sreloc == NULL && globals->root.dynamic_sections_created)
8064 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
8065 ! globals->use_rel);
8068 return bfd_reloc_notsupported;
8074 outrel.r_addend = addend;
8076 _bfd_elf_section_offset (output_bfd, info, input_section,
8078 if (outrel.r_offset == (bfd_vma) -1)
8080 else if (outrel.r_offset == (bfd_vma) -2)
8081 skip = TRUE, relocate = TRUE;
8082 outrel.r_offset += (input_section->output_section->vma
8083 + input_section->output_offset);
8086 memset (&outrel, 0, sizeof outrel);
8091 || !h->def_regular))
8092 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
8097 /* This symbol is local, or marked to become local. */
8098 BFD_ASSERT (r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI);
8099 if (globals->symbian_p)
8103 /* On Symbian OS, the data segment and text segement
8104 can be relocated independently. Therefore, we
8105 must indicate the segment to which this
8106 relocation is relative. The BPABI allows us to
8107 use any symbol in the right segment; we just use
8108 the section symbol as it is convenient. (We
8109 cannot use the symbol given by "h" directly as it
8110 will not appear in the dynamic symbol table.)
8112 Note that the dynamic linker ignores the section
8113 symbol value, so we don't subtract osec->vma
8114 from the emitted reloc addend. */
8116 osec = sym_sec->output_section;
8118 osec = input_section->output_section;
8119 symbol = elf_section_data (osec)->dynindx;
8122 struct elf_link_hash_table *htab = elf_hash_table (info);
8124 if ((osec->flags & SEC_READONLY) == 0
8125 && htab->data_index_section != NULL)
8126 osec = htab->data_index_section;
8128 osec = htab->text_index_section;
8129 symbol = elf_section_data (osec)->dynindx;
8131 BFD_ASSERT (symbol != 0);
8134 /* On SVR4-ish systems, the dynamic loader cannot
8135 relocate the text and data segments independently,
8136 so the symbol does not matter. */
8138 if (dynreloc_st_type == STT_GNU_IFUNC)
8139 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
8140 to the .iplt entry. Instead, every non-call reference
8141 must use an R_ARM_IRELATIVE relocation to obtain the
8142 correct run-time address. */
8143 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_IRELATIVE);
8145 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
8146 if (globals->use_rel)
8149 outrel.r_addend += dynreloc_value;
8152 elf32_arm_add_dynreloc (output_bfd, info, sreloc, &outrel);
8154 /* If this reloc is against an external symbol, we do not want to
8155 fiddle with the addend. Otherwise, we need to include the symbol
8156 value so that it becomes an addend for the dynamic reloc. */
8158 return bfd_reloc_ok;
8160 return _bfd_final_link_relocate (howto, input_bfd, input_section,
8161 contents, rel->r_offset,
8162 dynreloc_value, (bfd_vma) 0);
8164 else switch (r_type)
8167 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
8169 case R_ARM_XPC25: /* Arm BLX instruction. */
8172 case R_ARM_PC24: /* Arm B/BL instruction. */
8175 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
8177 if (r_type == R_ARM_XPC25)
8179 /* Check for Arm calling Arm function. */
8180 /* FIXME: Should we translate the instruction into a BL
8181 instruction instead ? */
8182 if (branch_type != ST_BRANCH_TO_THUMB)
8183 (*_bfd_error_handler)
8184 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
8186 h ? h->root.root.string : "(local)");
8188 else if (r_type == R_ARM_PC24)
8190 /* Check for Arm calling Thumb function. */
8191 if (branch_type == ST_BRANCH_TO_THUMB)
8193 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
8194 output_bfd, input_section,
8195 hit_data, sym_sec, rel->r_offset,
8196 signed_addend, value,
8198 return bfd_reloc_ok;
8200 return bfd_reloc_dangerous;
8204 /* Check if a stub has to be inserted because the
8205 destination is too far or we are changing mode. */
8206 if ( r_type == R_ARM_CALL
8207 || r_type == R_ARM_JUMP24
8208 || r_type == R_ARM_PLT32)
8210 enum elf32_arm_stub_type stub_type = arm_stub_none;
8211 struct elf32_arm_link_hash_entry *hash;
8213 hash = (struct elf32_arm_link_hash_entry *) h;
8214 stub_type = arm_type_of_stub (info, input_section, rel,
8215 st_type, &branch_type,
8216 hash, value, sym_sec,
8217 input_bfd, sym_name);
8219 if (stub_type != arm_stub_none)
8221 /* The target is out of reach, so redirect the
8222 branch to the local stub for this function. */
8223 stub_entry = elf32_arm_get_stub_entry (input_section,
8228 if (stub_entry != NULL)
8229 value = (stub_entry->stub_offset
8230 + stub_entry->stub_sec->output_offset
8231 + stub_entry->stub_sec->output_section->vma);
8233 if (plt_offset != (bfd_vma) -1)
8234 *unresolved_reloc_p = FALSE;
8239 /* If the call goes through a PLT entry, make sure to
8240 check distance to the right destination address. */
8241 if (plt_offset != (bfd_vma) -1)
8243 value = (splt->output_section->vma
8244 + splt->output_offset
8246 *unresolved_reloc_p = FALSE;
8247 /* The PLT entry is in ARM mode, regardless of the
8249 branch_type = ST_BRANCH_TO_ARM;
8254 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
8256 S is the address of the symbol in the relocation.
8257 P is address of the instruction being relocated.
8258 A is the addend (extracted from the instruction) in bytes.
8260 S is held in 'value'.
8261 P is the base address of the section containing the
8262 instruction plus the offset of the reloc into that
8264 (input_section->output_section->vma +
8265 input_section->output_offset +
8267 A is the addend, converted into bytes, ie:
8270 Note: None of these operations have knowledge of the pipeline
8271 size of the processor, thus it is up to the assembler to
8272 encode this information into the addend. */
8273 value -= (input_section->output_section->vma
8274 + input_section->output_offset);
8275 value -= rel->r_offset;
8276 if (globals->use_rel)
8277 value += (signed_addend << howto->size);
8279 /* RELA addends do not have to be adjusted by howto->size. */
8280 value += signed_addend;
8282 signed_addend = value;
8283 signed_addend >>= howto->rightshift;
8285 /* A branch to an undefined weak symbol is turned into a jump to
8286 the next instruction unless a PLT entry will be created.
8287 Do the same for local undefined symbols (but not for STN_UNDEF).
8288 The jump to the next instruction is optimized as a NOP depending
8289 on the architecture. */
8290 if (h ? (h->root.type == bfd_link_hash_undefweak
8291 && plt_offset == (bfd_vma) -1)
8292 : r_symndx != STN_UNDEF && bfd_is_und_section (sym_sec))
8294 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000);
8296 if (arch_has_arm_nop (globals))
8297 value |= 0x0320f000;
8299 value |= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
8303 /* Perform a signed range check. */
8304 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
8305 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
8306 return bfd_reloc_overflow;
8308 addend = (value & 2);
8310 value = (signed_addend & howto->dst_mask)
8311 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
8313 if (r_type == R_ARM_CALL)
8315 /* Set the H bit in the BLX instruction. */
8316 if (branch_type == ST_BRANCH_TO_THUMB)
8321 value &= ~(bfd_vma)(1 << 24);
8324 /* Select the correct instruction (BL or BLX). */
8325 /* Only if we are not handling a BL to a stub. In this
8326 case, mode switching is performed by the stub. */
8327 if (branch_type == ST_BRANCH_TO_THUMB && !stub_entry)
8329 else if (stub_entry || branch_type != ST_BRANCH_UNKNOWN)
8331 value &= ~(bfd_vma)(1 << 28);
8341 if (branch_type == ST_BRANCH_TO_THUMB)
8345 case R_ARM_ABS32_NOI:
8351 if (branch_type == ST_BRANCH_TO_THUMB)
8353 value -= (input_section->output_section->vma
8354 + input_section->output_offset + rel->r_offset);
8357 case R_ARM_REL32_NOI:
8359 value -= (input_section->output_section->vma
8360 + input_section->output_offset + rel->r_offset);
8364 value -= (input_section->output_section->vma
8365 + input_section->output_offset + rel->r_offset);
8366 value += signed_addend;
8367 if (! h || h->root.type != bfd_link_hash_undefweak)
8369 /* Check for overflow. */
8370 if ((value ^ (value >> 1)) & (1 << 30))
8371 return bfd_reloc_overflow;
8373 value &= 0x7fffffff;
8374 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
8375 if (branch_type == ST_BRANCH_TO_THUMB)
8380 bfd_put_32 (input_bfd, value, hit_data);
8381 return bfd_reloc_ok;
8386 /* There is no way to tell whether the user intended to use a signed or
8387 unsigned addend. When checking for overflow we accept either,
8388 as specified by the AAELF. */
8389 if ((long) value > 0xff || (long) value < -0x80)
8390 return bfd_reloc_overflow;
8392 bfd_put_8 (input_bfd, value, hit_data);
8393 return bfd_reloc_ok;
8398 /* See comment for R_ARM_ABS8. */
8399 if ((long) value > 0xffff || (long) value < -0x8000)
8400 return bfd_reloc_overflow;
8402 bfd_put_16 (input_bfd, value, hit_data);
8403 return bfd_reloc_ok;
8405 case R_ARM_THM_ABS5:
8406 /* Support ldr and str instructions for the thumb. */
8407 if (globals->use_rel)
8409 /* Need to refetch addend. */
8410 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
8411 /* ??? Need to determine shift amount from operand size. */
8412 addend >>= howto->rightshift;
8416 /* ??? Isn't value unsigned? */
8417 if ((long) value > 0x1f || (long) value < -0x10)
8418 return bfd_reloc_overflow;
8420 /* ??? Value needs to be properly shifted into place first. */
8421 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
8422 bfd_put_16 (input_bfd, value, hit_data);
8423 return bfd_reloc_ok;
8425 case R_ARM_THM_ALU_PREL_11_0:
8426 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
8429 bfd_signed_vma relocation;
8431 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
8432 | bfd_get_16 (input_bfd, hit_data + 2);
8434 if (globals->use_rel)
8436 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
8437 | ((insn & (1 << 26)) >> 15);
8438 if (insn & 0xf00000)
8439 signed_addend = -signed_addend;
8442 relocation = value + signed_addend;
8443 relocation -= (input_section->output_section->vma
8444 + input_section->output_offset
8447 value = abs (relocation);
8449 if (value >= 0x1000)
8450 return bfd_reloc_overflow;
8452 insn = (insn & 0xfb0f8f00) | (value & 0xff)
8453 | ((value & 0x700) << 4)
8454 | ((value & 0x800) << 15);
8458 bfd_put_16 (input_bfd, insn >> 16, hit_data);
8459 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
8461 return bfd_reloc_ok;
8465 /* PR 10073: This reloc is not generated by the GNU toolchain,
8466 but it is supported for compatibility with third party libraries
8467 generated by other compilers, specifically the ARM/IAR. */
8470 bfd_signed_vma relocation;
8472 insn = bfd_get_16 (input_bfd, hit_data);
8474 if (globals->use_rel)
8475 addend = (insn & 0x00ff) << 2;
8477 relocation = value + addend;
8478 relocation -= (input_section->output_section->vma
8479 + input_section->output_offset
8482 value = abs (relocation);
8484 /* We do not check for overflow of this reloc. Although strictly
8485 speaking this is incorrect, it appears to be necessary in order
8486 to work with IAR generated relocs. Since GCC and GAS do not
8487 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
8488 a problem for them. */
8491 insn = (insn & 0xff00) | (value >> 2);
8493 bfd_put_16 (input_bfd, insn, hit_data);
8495 return bfd_reloc_ok;
8498 case R_ARM_THM_PC12:
8499 /* Corresponds to: ldr.w reg, [pc, #offset]. */
8502 bfd_signed_vma relocation;
8504 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
8505 | bfd_get_16 (input_bfd, hit_data + 2);
8507 if (globals->use_rel)
8509 signed_addend = insn & 0xfff;
8510 if (!(insn & (1 << 23)))
8511 signed_addend = -signed_addend;
8514 relocation = value + signed_addend;
8515 relocation -= (input_section->output_section->vma
8516 + input_section->output_offset
8519 value = abs (relocation);
8521 if (value >= 0x1000)
8522 return bfd_reloc_overflow;
8524 insn = (insn & 0xff7ff000) | value;
8525 if (relocation >= 0)
8528 bfd_put_16 (input_bfd, insn >> 16, hit_data);
8529 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
8531 return bfd_reloc_ok;
8534 case R_ARM_THM_XPC22:
8535 case R_ARM_THM_CALL:
8536 case R_ARM_THM_JUMP24:
8537 /* Thumb BL (branch long instruction). */
8541 bfd_boolean overflow = FALSE;
8542 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
8543 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
8544 bfd_signed_vma reloc_signed_max;
8545 bfd_signed_vma reloc_signed_min;
8547 bfd_signed_vma signed_check;
8549 const int thumb2 = using_thumb2 (globals);
8551 /* A branch to an undefined weak symbol is turned into a jump to
8552 the next instruction unless a PLT entry will be created.
8553 The jump to the next instruction is optimized as a NOP.W for
8554 Thumb-2 enabled architectures. */
8555 if (h && h->root.type == bfd_link_hash_undefweak
8556 && plt_offset == (bfd_vma) -1)
8558 if (arch_has_thumb2_nop (globals))
8560 bfd_put_16 (input_bfd, 0xf3af, hit_data);
8561 bfd_put_16 (input_bfd, 0x8000, hit_data + 2);
8565 bfd_put_16 (input_bfd, 0xe000, hit_data);
8566 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
8568 return bfd_reloc_ok;
8571 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
8572 with Thumb-1) involving the J1 and J2 bits. */
8573 if (globals->use_rel)
8575 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
8576 bfd_vma upper = upper_insn & 0x3ff;
8577 bfd_vma lower = lower_insn & 0x7ff;
8578 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
8579 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
8580 bfd_vma i1 = j1 ^ s ? 0 : 1;
8581 bfd_vma i2 = j2 ^ s ? 0 : 1;
8583 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
8585 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
8587 signed_addend = addend;
8590 if (r_type == R_ARM_THM_XPC22)
8592 /* Check for Thumb to Thumb call. */
8593 /* FIXME: Should we translate the instruction into a BL
8594 instruction instead ? */
8595 if (branch_type == ST_BRANCH_TO_THUMB)
8596 (*_bfd_error_handler)
8597 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
8599 h ? h->root.root.string : "(local)");
8603 /* If it is not a call to Thumb, assume call to Arm.
8604 If it is a call relative to a section name, then it is not a
8605 function call at all, but rather a long jump. Calls through
8606 the PLT do not require stubs. */
8607 if (branch_type == ST_BRANCH_TO_ARM && plt_offset == (bfd_vma) -1)
8609 if (globals->use_blx && r_type == R_ARM_THM_CALL)
8611 /* Convert BL to BLX. */
8612 lower_insn = (lower_insn & ~0x1000) | 0x0800;
8614 else if (( r_type != R_ARM_THM_CALL)
8615 && (r_type != R_ARM_THM_JUMP24))
8617 if (elf32_thumb_to_arm_stub
8618 (info, sym_name, input_bfd, output_bfd, input_section,
8619 hit_data, sym_sec, rel->r_offset, signed_addend, value,
8621 return bfd_reloc_ok;
8623 return bfd_reloc_dangerous;
8626 else if (branch_type == ST_BRANCH_TO_THUMB
8628 && r_type == R_ARM_THM_CALL)
8630 /* Make sure this is a BL. */
8631 lower_insn |= 0x1800;
8635 enum elf32_arm_stub_type stub_type = arm_stub_none;
8636 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24)
8638 /* Check if a stub has to be inserted because the destination
8640 struct elf32_arm_stub_hash_entry *stub_entry;
8641 struct elf32_arm_link_hash_entry *hash;
8643 hash = (struct elf32_arm_link_hash_entry *) h;
8645 stub_type = arm_type_of_stub (info, input_section, rel,
8646 st_type, &branch_type,
8647 hash, value, sym_sec,
8648 input_bfd, sym_name);
8650 if (stub_type != arm_stub_none)
8652 /* The target is out of reach or we are changing modes, so
8653 redirect the branch to the local stub for this
8655 stub_entry = elf32_arm_get_stub_entry (input_section,
8659 if (stub_entry != NULL)
8661 value = (stub_entry->stub_offset
8662 + stub_entry->stub_sec->output_offset
8663 + stub_entry->stub_sec->output_section->vma);
8665 if (plt_offset != (bfd_vma) -1)
8666 *unresolved_reloc_p = FALSE;
8669 /* If this call becomes a call to Arm, force BLX. */
8670 if (globals->use_blx && (r_type == R_ARM_THM_CALL))
8673 && !arm_stub_is_thumb (stub_entry->stub_type))
8674 || branch_type != ST_BRANCH_TO_THUMB)
8675 lower_insn = (lower_insn & ~0x1000) | 0x0800;
8680 /* Handle calls via the PLT. */
8681 if (stub_type == arm_stub_none && plt_offset != (bfd_vma) -1)
8683 value = (splt->output_section->vma
8684 + splt->output_offset
8687 if (globals->use_blx && r_type == R_ARM_THM_CALL)
8689 /* If the Thumb BLX instruction is available, convert
8690 the BL to a BLX instruction to call the ARM-mode
8692 lower_insn = (lower_insn & ~0x1000) | 0x0800;
8693 branch_type = ST_BRANCH_TO_ARM;
8697 /* Target the Thumb stub before the ARM PLT entry. */
8698 value -= PLT_THUMB_STUB_SIZE;
8699 branch_type = ST_BRANCH_TO_THUMB;
8701 *unresolved_reloc_p = FALSE;
8704 relocation = value + signed_addend;
8706 relocation -= (input_section->output_section->vma
8707 + input_section->output_offset
8710 check = relocation >> howto->rightshift;
8712 /* If this is a signed value, the rightshift just dropped
8713 leading 1 bits (assuming twos complement). */
8714 if ((bfd_signed_vma) relocation >= 0)
8715 signed_check = check;
8717 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
8719 /* Calculate the permissable maximum and minimum values for
8720 this relocation according to whether we're relocating for
8722 bitsize = howto->bitsize;
8725 reloc_signed_max = (1 << (bitsize - 1)) - 1;
8726 reloc_signed_min = ~reloc_signed_max;
8728 /* Assumes two's complement. */
8729 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
8732 if ((lower_insn & 0x5000) == 0x4000)
8733 /* For a BLX instruction, make sure that the relocation is rounded up
8734 to a word boundary. This follows the semantics of the instruction
8735 which specifies that bit 1 of the target address will come from bit
8736 1 of the base address. */
8737 relocation = (relocation + 2) & ~ 3;
8739 /* Put RELOCATION back into the insn. Assumes two's complement.
8740 We use the Thumb-2 encoding, which is safe even if dealing with
8741 a Thumb-1 instruction by virtue of our overflow check above. */
8742 reloc_sign = (signed_check < 0) ? 1 : 0;
8743 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
8744 | ((relocation >> 12) & 0x3ff)
8745 | (reloc_sign << 10);
8746 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
8747 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
8748 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
8749 | ((relocation >> 1) & 0x7ff);
8751 /* Put the relocated value back in the object file: */
8752 bfd_put_16 (input_bfd, upper_insn, hit_data);
8753 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
8755 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
8759 case R_ARM_THM_JUMP19:
8760 /* Thumb32 conditional branch instruction. */
8763 bfd_boolean overflow = FALSE;
8764 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
8765 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
8766 bfd_signed_vma reloc_signed_max = 0xffffe;
8767 bfd_signed_vma reloc_signed_min = -0x100000;
8768 bfd_signed_vma signed_check;
8770 /* Need to refetch the addend, reconstruct the top three bits,
8771 and squish the two 11 bit pieces together. */
8772 if (globals->use_rel)
8774 bfd_vma S = (upper_insn & 0x0400) >> 10;
8775 bfd_vma upper = (upper_insn & 0x003f);
8776 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
8777 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
8778 bfd_vma lower = (lower_insn & 0x07ff);
8783 upper -= 0x0100; /* Sign extend. */
8785 addend = (upper << 12) | (lower << 1);
8786 signed_addend = addend;
8789 /* Handle calls via the PLT. */
8790 if (plt_offset != (bfd_vma) -1)
8792 value = (splt->output_section->vma
8793 + splt->output_offset
8795 /* Target the Thumb stub before the ARM PLT entry. */
8796 value -= PLT_THUMB_STUB_SIZE;
8797 *unresolved_reloc_p = FALSE;
8800 /* ??? Should handle interworking? GCC might someday try to
8801 use this for tail calls. */
8803 relocation = value + signed_addend;
8804 relocation -= (input_section->output_section->vma
8805 + input_section->output_offset
8807 signed_check = (bfd_signed_vma) relocation;
8809 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
8812 /* Put RELOCATION back into the insn. */
8814 bfd_vma S = (relocation & 0x00100000) >> 20;
8815 bfd_vma J2 = (relocation & 0x00080000) >> 19;
8816 bfd_vma J1 = (relocation & 0x00040000) >> 18;
8817 bfd_vma hi = (relocation & 0x0003f000) >> 12;
8818 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
8820 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
8821 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
8824 /* Put the relocated value back in the object file: */
8825 bfd_put_16 (input_bfd, upper_insn, hit_data);
8826 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
8828 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
8831 case R_ARM_THM_JUMP11:
8832 case R_ARM_THM_JUMP8:
8833 case R_ARM_THM_JUMP6:
8834 /* Thumb B (branch) instruction). */
8836 bfd_signed_vma relocation;
8837 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
8838 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
8839 bfd_signed_vma signed_check;
8841 /* CZB cannot jump backward. */
8842 if (r_type == R_ARM_THM_JUMP6)
8843 reloc_signed_min = 0;
8845 if (globals->use_rel)
8847 /* Need to refetch addend. */
8848 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
8849 if (addend & ((howto->src_mask + 1) >> 1))
8852 signed_addend &= ~ howto->src_mask;
8853 signed_addend |= addend;
8856 signed_addend = addend;
8857 /* The value in the insn has been right shifted. We need to
8858 undo this, so that we can perform the address calculation
8859 in terms of bytes. */
8860 signed_addend <<= howto->rightshift;
8862 relocation = value + signed_addend;
8864 relocation -= (input_section->output_section->vma
8865 + input_section->output_offset
8868 relocation >>= howto->rightshift;
8869 signed_check = relocation;
8871 if (r_type == R_ARM_THM_JUMP6)
8872 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
8874 relocation &= howto->dst_mask;
8875 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
8877 bfd_put_16 (input_bfd, relocation, hit_data);
8879 /* Assumes two's complement. */
8880 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
8881 return bfd_reloc_overflow;
8883 return bfd_reloc_ok;
8886 case R_ARM_ALU_PCREL7_0:
8887 case R_ARM_ALU_PCREL15_8:
8888 case R_ARM_ALU_PCREL23_15:
8893 insn = bfd_get_32 (input_bfd, hit_data);
8894 if (globals->use_rel)
8896 /* Extract the addend. */
8897 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
8898 signed_addend = addend;
8900 relocation = value + signed_addend;
8902 relocation -= (input_section->output_section->vma
8903 + input_section->output_offset
8905 insn = (insn & ~0xfff)
8906 | ((howto->bitpos << 7) & 0xf00)
8907 | ((relocation >> howto->bitpos) & 0xff);
8908 bfd_put_32 (input_bfd, value, hit_data);
8910 return bfd_reloc_ok;
8912 case R_ARM_GNU_VTINHERIT:
8913 case R_ARM_GNU_VTENTRY:
8914 return bfd_reloc_ok;
8916 case R_ARM_GOTOFF32:
8917 /* Relocation is relative to the start of the
8918 global offset table. */
8920 BFD_ASSERT (sgot != NULL);
8922 return bfd_reloc_notsupported;
8924 /* If we are addressing a Thumb function, we need to adjust the
8925 address by one, so that attempts to call the function pointer will
8926 correctly interpret it as Thumb code. */
8927 if (branch_type == ST_BRANCH_TO_THUMB)
8930 /* Note that sgot->output_offset is not involved in this
8931 calculation. We always want the start of .got. If we
8932 define _GLOBAL_OFFSET_TABLE in a different way, as is
8933 permitted by the ABI, we might have to change this
8935 value -= sgot->output_section->vma;
8936 return _bfd_final_link_relocate (howto, input_bfd, input_section,
8937 contents, rel->r_offset, value,
8941 /* Use global offset table as symbol value. */
8942 BFD_ASSERT (sgot != NULL);
8945 return bfd_reloc_notsupported;
8947 *unresolved_reloc_p = FALSE;
8948 value = sgot->output_section->vma;
8949 return _bfd_final_link_relocate (howto, input_bfd, input_section,
8950 contents, rel->r_offset, value,
8954 case R_ARM_GOT_PREL:
8955 /* Relocation is to the entry for this symbol in the
8956 global offset table. */
8958 return bfd_reloc_notsupported;
8960 if (dynreloc_st_type == STT_GNU_IFUNC
8961 && plt_offset != (bfd_vma) -1
8962 && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, h)))
8964 /* We have a relocation against a locally-binding STT_GNU_IFUNC
8965 symbol, and the relocation resolves directly to the runtime
8966 target rather than to the .iplt entry. This means that any
8967 .got entry would be the same value as the .igot.plt entry,
8968 so there's no point creating both. */
8969 sgot = globals->root.igotplt;
8970 value = sgot->output_offset + gotplt_offset;
8976 off = h->got.offset;
8977 BFD_ASSERT (off != (bfd_vma) -1);
8980 /* We have already processsed one GOT relocation against
8983 if (globals->root.dynamic_sections_created
8984 && !SYMBOL_REFERENCES_LOCAL (info, h))
8985 *unresolved_reloc_p = FALSE;
8989 Elf_Internal_Rela outrel;
8991 if (!SYMBOL_REFERENCES_LOCAL (info, h))
8993 /* If the symbol doesn't resolve locally in a static
8994 object, we have an undefined reference. If the
8995 symbol doesn't resolve locally in a dynamic object,
8996 it should be resolved by the dynamic linker. */
8997 if (globals->root.dynamic_sections_created)
8999 outrel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9000 *unresolved_reloc_p = FALSE;
9004 outrel.r_addend = 0;
9008 if (dynreloc_st_type == STT_GNU_IFUNC)
9009 outrel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
9010 else if (info->shared)
9011 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9014 outrel.r_addend = dynreloc_value;
9017 /* The GOT entry is initialized to zero by default.
9018 See if we should install a different value. */
9019 if (outrel.r_addend != 0
9020 && (outrel.r_info == 0 || globals->use_rel))
9022 bfd_put_32 (output_bfd, outrel.r_addend,
9023 sgot->contents + off);
9024 outrel.r_addend = 0;
9027 if (outrel.r_info != 0)
9029 outrel.r_offset = (sgot->output_section->vma
9030 + sgot->output_offset
9032 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
9036 value = sgot->output_offset + off;
9042 BFD_ASSERT (local_got_offsets != NULL &&
9043 local_got_offsets[r_symndx] != (bfd_vma) -1);
9045 off = local_got_offsets[r_symndx];
9047 /* The offset must always be a multiple of 4. We use the
9048 least significant bit to record whether we have already
9049 generated the necessary reloc. */
9054 if (globals->use_rel)
9055 bfd_put_32 (output_bfd, dynreloc_value, sgot->contents + off);
9057 if (info->shared || dynreloc_st_type == STT_GNU_IFUNC)
9059 Elf_Internal_Rela outrel;
9061 outrel.r_addend = addend + dynreloc_value;
9062 outrel.r_offset = (sgot->output_section->vma
9063 + sgot->output_offset
9065 if (dynreloc_st_type == STT_GNU_IFUNC)
9066 outrel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
9068 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9069 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
9072 local_got_offsets[r_symndx] |= 1;
9075 value = sgot->output_offset + off;
9077 if (r_type != R_ARM_GOT32)
9078 value += sgot->output_section->vma;
9080 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9081 contents, rel->r_offset, value,
9084 case R_ARM_TLS_LDO32:
9085 value = value - dtpoff_base (info);
9087 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9088 contents, rel->r_offset, value,
9091 case R_ARM_TLS_LDM32:
9098 off = globals->tls_ldm_got.offset;
9104 /* If we don't know the module number, create a relocation
9108 Elf_Internal_Rela outrel;
9110 if (srelgot == NULL)
9113 outrel.r_addend = 0;
9114 outrel.r_offset = (sgot->output_section->vma
9115 + sgot->output_offset + off);
9116 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
9118 if (globals->use_rel)
9119 bfd_put_32 (output_bfd, outrel.r_addend,
9120 sgot->contents + off);
9122 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
9125 bfd_put_32 (output_bfd, 1, sgot->contents + off);
9127 globals->tls_ldm_got.offset |= 1;
9130 value = sgot->output_section->vma + sgot->output_offset + off
9131 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
9133 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9134 contents, rel->r_offset, value,
9138 case R_ARM_TLS_CALL:
9139 case R_ARM_THM_TLS_CALL:
9140 case R_ARM_TLS_GD32:
9141 case R_ARM_TLS_IE32:
9142 case R_ARM_TLS_GOTDESC:
9143 case R_ARM_TLS_DESCSEQ:
9144 case R_ARM_THM_TLS_DESCSEQ:
9146 bfd_vma off, offplt;
9150 BFD_ASSERT (sgot != NULL);
9155 dyn = globals->root.dynamic_sections_created;
9156 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
9158 || !SYMBOL_REFERENCES_LOCAL (info, h)))
9160 *unresolved_reloc_p = FALSE;
9163 off = h->got.offset;
9164 offplt = elf32_arm_hash_entry (h)->tlsdesc_got;
9165 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
9169 BFD_ASSERT (local_got_offsets != NULL);
9170 off = local_got_offsets[r_symndx];
9171 offplt = local_tlsdesc_gotents[r_symndx];
9172 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
9175 /* Linker relaxations happens from one of the
9176 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
9177 if (ELF32_R_TYPE(rel->r_info) != r_type)
9178 tls_type = GOT_TLS_IE;
9180 BFD_ASSERT (tls_type != GOT_UNKNOWN);
9186 bfd_boolean need_relocs = FALSE;
9187 Elf_Internal_Rela outrel;
9190 /* The GOT entries have not been initialized yet. Do it
9191 now, and emit any relocations. If both an IE GOT and a
9192 GD GOT are necessary, we emit the GD first. */
9194 if ((info->shared || indx != 0)
9196 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9197 || h->root.type != bfd_link_hash_undefweak))
9200 BFD_ASSERT (srelgot != NULL);
9203 if (tls_type & GOT_TLS_GDESC)
9207 /* We should have relaxed, unless this is an undefined
9209 BFD_ASSERT ((h && (h->root.type == bfd_link_hash_undefweak))
9211 BFD_ASSERT (globals->sgotplt_jump_table_size + offplt + 8
9212 <= globals->root.sgotplt->size);
9214 outrel.r_addend = 0;
9215 outrel.r_offset = (globals->root.sgotplt->output_section->vma
9216 + globals->root.sgotplt->output_offset
9218 + globals->sgotplt_jump_table_size);
9220 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DESC);
9221 sreloc = globals->root.srelplt;
9222 loc = sreloc->contents;
9223 loc += globals->next_tls_desc_index++ * RELOC_SIZE (globals);
9224 BFD_ASSERT (loc + RELOC_SIZE (globals)
9225 <= sreloc->contents + sreloc->size);
9227 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
9229 /* For globals, the first word in the relocation gets
9230 the relocation index and the top bit set, or zero,
9231 if we're binding now. For locals, it gets the
9232 symbol's offset in the tls section. */
9233 bfd_put_32 (output_bfd,
9234 !h ? value - elf_hash_table (info)->tls_sec->vma
9235 : info->flags & DF_BIND_NOW ? 0
9236 : 0x80000000 | ELF32_R_SYM (outrel.r_info),
9237 globals->root.sgotplt->contents + offplt +
9238 globals->sgotplt_jump_table_size);
9240 /* Second word in the relocation is always zero. */
9241 bfd_put_32 (output_bfd, 0,
9242 globals->root.sgotplt->contents + offplt +
9243 globals->sgotplt_jump_table_size + 4);
9245 if (tls_type & GOT_TLS_GD)
9249 outrel.r_addend = 0;
9250 outrel.r_offset = (sgot->output_section->vma
9251 + sgot->output_offset
9253 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
9255 if (globals->use_rel)
9256 bfd_put_32 (output_bfd, outrel.r_addend,
9257 sgot->contents + cur_off);
9259 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
9262 bfd_put_32 (output_bfd, value - dtpoff_base (info),
9263 sgot->contents + cur_off + 4);
9266 outrel.r_addend = 0;
9267 outrel.r_info = ELF32_R_INFO (indx,
9268 R_ARM_TLS_DTPOFF32);
9269 outrel.r_offset += 4;
9271 if (globals->use_rel)
9272 bfd_put_32 (output_bfd, outrel.r_addend,
9273 sgot->contents + cur_off + 4);
9275 elf32_arm_add_dynreloc (output_bfd, info,
9281 /* If we are not emitting relocations for a
9282 general dynamic reference, then we must be in a
9283 static link or an executable link with the
9284 symbol binding locally. Mark it as belonging
9285 to module 1, the executable. */
9286 bfd_put_32 (output_bfd, 1,
9287 sgot->contents + cur_off);
9288 bfd_put_32 (output_bfd, value - dtpoff_base (info),
9289 sgot->contents + cur_off + 4);
9295 if (tls_type & GOT_TLS_IE)
9300 outrel.r_addend = value - dtpoff_base (info);
9302 outrel.r_addend = 0;
9303 outrel.r_offset = (sgot->output_section->vma
9304 + sgot->output_offset
9306 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
9308 if (globals->use_rel)
9309 bfd_put_32 (output_bfd, outrel.r_addend,
9310 sgot->contents + cur_off);
9312 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
9315 bfd_put_32 (output_bfd, tpoff (info, value),
9316 sgot->contents + cur_off);
9323 local_got_offsets[r_symndx] |= 1;
9326 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
9328 else if (tls_type & GOT_TLS_GDESC)
9331 if (ELF32_R_TYPE(rel->r_info) == R_ARM_TLS_CALL
9332 || ELF32_R_TYPE(rel->r_info) == R_ARM_THM_TLS_CALL)
9334 bfd_signed_vma offset;
9335 /* TLS stubs are arm mode. The original symbol is a
9336 data object, so branch_type is bogus. */
9337 branch_type = ST_BRANCH_TO_ARM;
9338 enum elf32_arm_stub_type stub_type
9339 = arm_type_of_stub (info, input_section, rel,
9340 st_type, &branch_type,
9341 (struct elf32_arm_link_hash_entry *)h,
9342 globals->tls_trampoline, globals->root.splt,
9343 input_bfd, sym_name);
9345 if (stub_type != arm_stub_none)
9347 struct elf32_arm_stub_hash_entry *stub_entry
9348 = elf32_arm_get_stub_entry
9349 (input_section, globals->root.splt, 0, rel,
9350 globals, stub_type);
9351 offset = (stub_entry->stub_offset
9352 + stub_entry->stub_sec->output_offset
9353 + stub_entry->stub_sec->output_section->vma);
9356 offset = (globals->root.splt->output_section->vma
9357 + globals->root.splt->output_offset
9358 + globals->tls_trampoline);
9360 if (ELF32_R_TYPE(rel->r_info) == R_ARM_TLS_CALL)
9364 offset -= (input_section->output_section->vma +
9365 input_section->output_offset + rel->r_offset + 8);
9369 value = inst | (globals->use_blx ? 0xfa000000 : 0xeb000000);
9373 /* Thumb blx encodes the offset in a complicated
9375 unsigned upper_insn, lower_insn;
9378 offset -= (input_section->output_section->vma +
9379 input_section->output_offset
9380 + rel->r_offset + 4);
9382 if (stub_type != arm_stub_none
9383 && arm_stub_is_thumb (stub_type))
9385 lower_insn = 0xd000;
9389 lower_insn = 0xc000;
9390 /* Round up the offset to a word boundary */
9391 offset = (offset + 2) & ~2;
9395 upper_insn = (0xf000
9396 | ((offset >> 12) & 0x3ff)
9398 lower_insn |= (((!((offset >> 23) & 1)) ^ neg) << 13)
9399 | (((!((offset >> 22) & 1)) ^ neg) << 11)
9400 | ((offset >> 1) & 0x7ff);
9401 bfd_put_16 (input_bfd, upper_insn, hit_data);
9402 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
9403 return bfd_reloc_ok;
9406 /* These relocations needs special care, as besides the fact
9407 they point somewhere in .gotplt, the addend must be
9408 adjusted accordingly depending on the type of instruction
9410 else if ((r_type == R_ARM_TLS_GOTDESC) && (tls_type & GOT_TLS_GDESC))
9412 unsigned long data, insn;
9415 data = bfd_get_32 (input_bfd, hit_data);
9421 insn = bfd_get_16 (input_bfd, contents + rel->r_offset - data);
9422 if ((insn & 0xf000) == 0xf000 || (insn & 0xf800) == 0xe800)
9424 | bfd_get_16 (input_bfd,
9425 contents + rel->r_offset - data + 2);
9426 if ((insn & 0xf800c000) == 0xf000c000)
9429 else if ((insn & 0xffffff00) == 0x4400)
9434 (*_bfd_error_handler)
9435 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' referenced by TLS_GOTDESC"),
9436 input_bfd, input_section,
9437 (unsigned long)rel->r_offset, insn);
9438 return bfd_reloc_notsupported;
9443 insn = bfd_get_32 (input_bfd, contents + rel->r_offset - data);
9448 case 0xfa: /* blx */
9452 case 0xe0: /* add */
9457 (*_bfd_error_handler)
9458 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' referenced by TLS_GOTDESC"),
9459 input_bfd, input_section,
9460 (unsigned long)rel->r_offset, insn);
9461 return bfd_reloc_notsupported;
9465 value += ((globals->root.sgotplt->output_section->vma
9466 + globals->root.sgotplt->output_offset + off)
9467 - (input_section->output_section->vma
9468 + input_section->output_offset
9470 + globals->sgotplt_jump_table_size);
9473 value = ((globals->root.sgot->output_section->vma
9474 + globals->root.sgot->output_offset + off)
9475 - (input_section->output_section->vma
9476 + input_section->output_offset + rel->r_offset));
9478 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9479 contents, rel->r_offset, value,
9483 case R_ARM_TLS_LE32:
9484 if (info->shared && !info->pie)
9486 (*_bfd_error_handler)
9487 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
9488 input_bfd, input_section,
9489 (long) rel->r_offset, howto->name);
9490 return (bfd_reloc_status_type) FALSE;
9493 value = tpoff (info, value);
9495 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9496 contents, rel->r_offset, value,
9500 if (globals->fix_v4bx)
9502 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9504 /* Ensure that we have a BX instruction. */
9505 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
9507 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
9509 /* Branch to veneer. */
9511 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
9512 glue_addr -= input_section->output_section->vma
9513 + input_section->output_offset
9514 + rel->r_offset + 8;
9515 insn = (insn & 0xf0000000) | 0x0a000000
9516 | ((glue_addr >> 2) & 0x00ffffff);
9520 /* Preserve Rm (lowest four bits) and the condition code
9521 (highest four bits). Other bits encode MOV PC,Rm. */
9522 insn = (insn & 0xf000000f) | 0x01a0f000;
9525 bfd_put_32 (input_bfd, insn, hit_data);
9527 return bfd_reloc_ok;
9529 case R_ARM_MOVW_ABS_NC:
9530 case R_ARM_MOVT_ABS:
9531 case R_ARM_MOVW_PREL_NC:
9532 case R_ARM_MOVT_PREL:
9533 /* Until we properly support segment-base-relative addressing then
9534 we assume the segment base to be zero, as for the group relocations.
9535 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
9536 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
9537 case R_ARM_MOVW_BREL_NC:
9538 case R_ARM_MOVW_BREL:
9539 case R_ARM_MOVT_BREL:
9541 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9543 if (globals->use_rel)
9545 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
9546 signed_addend = (addend ^ 0x8000) - 0x8000;
9549 value += signed_addend;
9551 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
9552 value -= (input_section->output_section->vma
9553 + input_section->output_offset + rel->r_offset);
9555 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
9556 return bfd_reloc_overflow;
9558 if (branch_type == ST_BRANCH_TO_THUMB)
9561 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
9562 || r_type == R_ARM_MOVT_BREL)
9566 insn |= value & 0xfff;
9567 insn |= (value & 0xf000) << 4;
9568 bfd_put_32 (input_bfd, insn, hit_data);
9570 return bfd_reloc_ok;
9572 case R_ARM_THM_MOVW_ABS_NC:
9573 case R_ARM_THM_MOVT_ABS:
9574 case R_ARM_THM_MOVW_PREL_NC:
9575 case R_ARM_THM_MOVT_PREL:
9576 /* Until we properly support segment-base-relative addressing then
9577 we assume the segment base to be zero, as for the above relocations.
9578 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
9579 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
9580 as R_ARM_THM_MOVT_ABS. */
9581 case R_ARM_THM_MOVW_BREL_NC:
9582 case R_ARM_THM_MOVW_BREL:
9583 case R_ARM_THM_MOVT_BREL:
9587 insn = bfd_get_16 (input_bfd, hit_data) << 16;
9588 insn |= bfd_get_16 (input_bfd, hit_data + 2);
9590 if (globals->use_rel)
9592 addend = ((insn >> 4) & 0xf000)
9593 | ((insn >> 15) & 0x0800)
9594 | ((insn >> 4) & 0x0700)
9596 signed_addend = (addend ^ 0x8000) - 0x8000;
9599 value += signed_addend;
9601 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
9602 value -= (input_section->output_section->vma
9603 + input_section->output_offset + rel->r_offset);
9605 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
9606 return bfd_reloc_overflow;
9608 if (branch_type == ST_BRANCH_TO_THUMB)
9611 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
9612 || r_type == R_ARM_THM_MOVT_BREL)
9616 insn |= (value & 0xf000) << 4;
9617 insn |= (value & 0x0800) << 15;
9618 insn |= (value & 0x0700) << 4;
9619 insn |= (value & 0x00ff);
9621 bfd_put_16 (input_bfd, insn >> 16, hit_data);
9622 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
9624 return bfd_reloc_ok;
9626 case R_ARM_ALU_PC_G0_NC:
9627 case R_ARM_ALU_PC_G1_NC:
9628 case R_ARM_ALU_PC_G0:
9629 case R_ARM_ALU_PC_G1:
9630 case R_ARM_ALU_PC_G2:
9631 case R_ARM_ALU_SB_G0_NC:
9632 case R_ARM_ALU_SB_G1_NC:
9633 case R_ARM_ALU_SB_G0:
9634 case R_ARM_ALU_SB_G1:
9635 case R_ARM_ALU_SB_G2:
9637 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9638 bfd_vma pc = input_section->output_section->vma
9639 + input_section->output_offset + rel->r_offset;
9640 /* sb should be the origin of the *segment* containing the symbol.
9641 It is not clear how to obtain this OS-dependent value, so we
9642 make an arbitrary choice of zero. */
9646 bfd_signed_vma signed_value;
9649 /* Determine which group of bits to select. */
9652 case R_ARM_ALU_PC_G0_NC:
9653 case R_ARM_ALU_PC_G0:
9654 case R_ARM_ALU_SB_G0_NC:
9655 case R_ARM_ALU_SB_G0:
9659 case R_ARM_ALU_PC_G1_NC:
9660 case R_ARM_ALU_PC_G1:
9661 case R_ARM_ALU_SB_G1_NC:
9662 case R_ARM_ALU_SB_G1:
9666 case R_ARM_ALU_PC_G2:
9667 case R_ARM_ALU_SB_G2:
9675 /* If REL, extract the addend from the insn. If RELA, it will
9676 have already been fetched for us. */
9677 if (globals->use_rel)
9680 bfd_vma constant = insn & 0xff;
9681 bfd_vma rotation = (insn & 0xf00) >> 8;
9684 signed_addend = constant;
9687 /* Compensate for the fact that in the instruction, the
9688 rotation is stored in multiples of 2 bits. */
9691 /* Rotate "constant" right by "rotation" bits. */
9692 signed_addend = (constant >> rotation) |
9693 (constant << (8 * sizeof (bfd_vma) - rotation));
9696 /* Determine if the instruction is an ADD or a SUB.
9697 (For REL, this determines the sign of the addend.) */
9698 negative = identify_add_or_sub (insn);
9701 (*_bfd_error_handler)
9702 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
9703 input_bfd, input_section,
9704 (long) rel->r_offset, howto->name);
9705 return bfd_reloc_overflow;
9708 signed_addend *= negative;
9711 /* Compute the value (X) to go in the place. */
9712 if (r_type == R_ARM_ALU_PC_G0_NC
9713 || r_type == R_ARM_ALU_PC_G1_NC
9714 || r_type == R_ARM_ALU_PC_G0
9715 || r_type == R_ARM_ALU_PC_G1
9716 || r_type == R_ARM_ALU_PC_G2)
9718 signed_value = value - pc + signed_addend;
9720 /* Section base relative. */
9721 signed_value = value - sb + signed_addend;
9723 /* If the target symbol is a Thumb function, then set the
9724 Thumb bit in the address. */
9725 if (branch_type == ST_BRANCH_TO_THUMB)
9728 /* Calculate the value of the relevant G_n, in encoded
9729 constant-with-rotation format. */
9730 g_n = calculate_group_reloc_mask (abs (signed_value), group,
9733 /* Check for overflow if required. */
9734 if ((r_type == R_ARM_ALU_PC_G0
9735 || r_type == R_ARM_ALU_PC_G1
9736 || r_type == R_ARM_ALU_PC_G2
9737 || r_type == R_ARM_ALU_SB_G0
9738 || r_type == R_ARM_ALU_SB_G1
9739 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
9741 (*_bfd_error_handler)
9742 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9743 input_bfd, input_section,
9744 (long) rel->r_offset, abs (signed_value), howto->name);
9745 return bfd_reloc_overflow;
9748 /* Mask out the value and the ADD/SUB part of the opcode; take care
9749 not to destroy the S bit. */
9752 /* Set the opcode according to whether the value to go in the
9753 place is negative. */
9754 if (signed_value < 0)
9759 /* Encode the offset. */
9762 bfd_put_32 (input_bfd, insn, hit_data);
9764 return bfd_reloc_ok;
9766 case R_ARM_LDR_PC_G0:
9767 case R_ARM_LDR_PC_G1:
9768 case R_ARM_LDR_PC_G2:
9769 case R_ARM_LDR_SB_G0:
9770 case R_ARM_LDR_SB_G1:
9771 case R_ARM_LDR_SB_G2:
9773 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9774 bfd_vma pc = input_section->output_section->vma
9775 + input_section->output_offset + rel->r_offset;
9776 bfd_vma sb = 0; /* See note above. */
9778 bfd_signed_vma signed_value;
9781 /* Determine which groups of bits to calculate. */
9784 case R_ARM_LDR_PC_G0:
9785 case R_ARM_LDR_SB_G0:
9789 case R_ARM_LDR_PC_G1:
9790 case R_ARM_LDR_SB_G1:
9794 case R_ARM_LDR_PC_G2:
9795 case R_ARM_LDR_SB_G2:
9803 /* If REL, extract the addend from the insn. If RELA, it will
9804 have already been fetched for us. */
9805 if (globals->use_rel)
9807 int negative = (insn & (1 << 23)) ? 1 : -1;
9808 signed_addend = negative * (insn & 0xfff);
9811 /* Compute the value (X) to go in the place. */
9812 if (r_type == R_ARM_LDR_PC_G0
9813 || r_type == R_ARM_LDR_PC_G1
9814 || r_type == R_ARM_LDR_PC_G2)
9816 signed_value = value - pc + signed_addend;
9818 /* Section base relative. */
9819 signed_value = value - sb + signed_addend;
9821 /* Calculate the value of the relevant G_{n-1} to obtain
9822 the residual at that stage. */
9823 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
9825 /* Check for overflow. */
9826 if (residual >= 0x1000)
9828 (*_bfd_error_handler)
9829 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9830 input_bfd, input_section,
9831 (long) rel->r_offset, abs (signed_value), howto->name);
9832 return bfd_reloc_overflow;
9835 /* Mask out the value and U bit. */
9838 /* Set the U bit if the value to go in the place is non-negative. */
9839 if (signed_value >= 0)
9842 /* Encode the offset. */
9845 bfd_put_32 (input_bfd, insn, hit_data);
9847 return bfd_reloc_ok;
9849 case R_ARM_LDRS_PC_G0:
9850 case R_ARM_LDRS_PC_G1:
9851 case R_ARM_LDRS_PC_G2:
9852 case R_ARM_LDRS_SB_G0:
9853 case R_ARM_LDRS_SB_G1:
9854 case R_ARM_LDRS_SB_G2:
9856 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9857 bfd_vma pc = input_section->output_section->vma
9858 + input_section->output_offset + rel->r_offset;
9859 bfd_vma sb = 0; /* See note above. */
9861 bfd_signed_vma signed_value;
9864 /* Determine which groups of bits to calculate. */
9867 case R_ARM_LDRS_PC_G0:
9868 case R_ARM_LDRS_SB_G0:
9872 case R_ARM_LDRS_PC_G1:
9873 case R_ARM_LDRS_SB_G1:
9877 case R_ARM_LDRS_PC_G2:
9878 case R_ARM_LDRS_SB_G2:
9886 /* If REL, extract the addend from the insn. If RELA, it will
9887 have already been fetched for us. */
9888 if (globals->use_rel)
9890 int negative = (insn & (1 << 23)) ? 1 : -1;
9891 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
9894 /* Compute the value (X) to go in the place. */
9895 if (r_type == R_ARM_LDRS_PC_G0
9896 || r_type == R_ARM_LDRS_PC_G1
9897 || r_type == R_ARM_LDRS_PC_G2)
9899 signed_value = value - pc + signed_addend;
9901 /* Section base relative. */
9902 signed_value = value - sb + signed_addend;
9904 /* Calculate the value of the relevant G_{n-1} to obtain
9905 the residual at that stage. */
9906 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
9908 /* Check for overflow. */
9909 if (residual >= 0x100)
9911 (*_bfd_error_handler)
9912 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9913 input_bfd, input_section,
9914 (long) rel->r_offset, abs (signed_value), howto->name);
9915 return bfd_reloc_overflow;
9918 /* Mask out the value and U bit. */
9921 /* Set the U bit if the value to go in the place is non-negative. */
9922 if (signed_value >= 0)
9925 /* Encode the offset. */
9926 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
9928 bfd_put_32 (input_bfd, insn, hit_data);
9930 return bfd_reloc_ok;
9932 case R_ARM_LDC_PC_G0:
9933 case R_ARM_LDC_PC_G1:
9934 case R_ARM_LDC_PC_G2:
9935 case R_ARM_LDC_SB_G0:
9936 case R_ARM_LDC_SB_G1:
9937 case R_ARM_LDC_SB_G2:
9939 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
9940 bfd_vma pc = input_section->output_section->vma
9941 + input_section->output_offset + rel->r_offset;
9942 bfd_vma sb = 0; /* See note above. */
9944 bfd_signed_vma signed_value;
9947 /* Determine which groups of bits to calculate. */
9950 case R_ARM_LDC_PC_G0:
9951 case R_ARM_LDC_SB_G0:
9955 case R_ARM_LDC_PC_G1:
9956 case R_ARM_LDC_SB_G1:
9960 case R_ARM_LDC_PC_G2:
9961 case R_ARM_LDC_SB_G2:
9969 /* If REL, extract the addend from the insn. If RELA, it will
9970 have already been fetched for us. */
9971 if (globals->use_rel)
9973 int negative = (insn & (1 << 23)) ? 1 : -1;
9974 signed_addend = negative * ((insn & 0xff) << 2);
9977 /* Compute the value (X) to go in the place. */
9978 if (r_type == R_ARM_LDC_PC_G0
9979 || r_type == R_ARM_LDC_PC_G1
9980 || r_type == R_ARM_LDC_PC_G2)
9982 signed_value = value - pc + signed_addend;
9984 /* Section base relative. */
9985 signed_value = value - sb + signed_addend;
9987 /* Calculate the value of the relevant G_{n-1} to obtain
9988 the residual at that stage. */
9989 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
9991 /* Check for overflow. (The absolute value to go in the place must be
9992 divisible by four and, after having been divided by four, must
9993 fit in eight bits.) */
9994 if ((residual & 0x3) != 0 || residual >= 0x400)
9996 (*_bfd_error_handler)
9997 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9998 input_bfd, input_section,
9999 (long) rel->r_offset, abs (signed_value), howto->name);
10000 return bfd_reloc_overflow;
10003 /* Mask out the value and U bit. */
10004 insn &= 0xff7fff00;
10006 /* Set the U bit if the value to go in the place is non-negative. */
10007 if (signed_value >= 0)
10010 /* Encode the offset. */
10011 insn |= residual >> 2;
10013 bfd_put_32 (input_bfd, insn, hit_data);
10015 return bfd_reloc_ok;
10018 return bfd_reloc_notsupported;
10022 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
10024 arm_add_to_rel (bfd * abfd,
10025 bfd_byte * address,
10026 reloc_howto_type * howto,
10027 bfd_signed_vma increment)
10029 bfd_signed_vma addend;
10031 if (howto->type == R_ARM_THM_CALL
10032 || howto->type == R_ARM_THM_JUMP24)
10034 int upper_insn, lower_insn;
10037 upper_insn = bfd_get_16 (abfd, address);
10038 lower_insn = bfd_get_16 (abfd, address + 2);
10039 upper = upper_insn & 0x7ff;
10040 lower = lower_insn & 0x7ff;
10042 addend = (upper << 12) | (lower << 1);
10043 addend += increment;
10046 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
10047 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
10049 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
10050 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
10056 contents = bfd_get_32 (abfd, address);
10058 /* Get the (signed) value from the instruction. */
10059 addend = contents & howto->src_mask;
10060 if (addend & ((howto->src_mask + 1) >> 1))
10062 bfd_signed_vma mask;
10065 mask &= ~ howto->src_mask;
10069 /* Add in the increment, (which is a byte value). */
10070 switch (howto->type)
10073 addend += increment;
10080 addend <<= howto->size;
10081 addend += increment;
10083 /* Should we check for overflow here ? */
10085 /* Drop any undesired bits. */
10086 addend >>= howto->rightshift;
10090 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
10092 bfd_put_32 (abfd, contents, address);
10096 #define IS_ARM_TLS_RELOC(R_TYPE) \
10097 ((R_TYPE) == R_ARM_TLS_GD32 \
10098 || (R_TYPE) == R_ARM_TLS_LDO32 \
10099 || (R_TYPE) == R_ARM_TLS_LDM32 \
10100 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
10101 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
10102 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
10103 || (R_TYPE) == R_ARM_TLS_LE32 \
10104 || (R_TYPE) == R_ARM_TLS_IE32 \
10105 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
10107 /* Specific set of relocations for the gnu tls dialect. */
10108 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
10109 ((R_TYPE) == R_ARM_TLS_GOTDESC \
10110 || (R_TYPE) == R_ARM_TLS_CALL \
10111 || (R_TYPE) == R_ARM_THM_TLS_CALL \
10112 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
10113 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
10115 /* Relocate an ARM ELF section. */
10118 elf32_arm_relocate_section (bfd * output_bfd,
10119 struct bfd_link_info * info,
10121 asection * input_section,
10122 bfd_byte * contents,
10123 Elf_Internal_Rela * relocs,
10124 Elf_Internal_Sym * local_syms,
10125 asection ** local_sections)
10127 Elf_Internal_Shdr *symtab_hdr;
10128 struct elf_link_hash_entry **sym_hashes;
10129 Elf_Internal_Rela *rel;
10130 Elf_Internal_Rela *relend;
10132 struct elf32_arm_link_hash_table * globals;
10134 globals = elf32_arm_hash_table (info);
10135 if (globals == NULL)
10138 symtab_hdr = & elf_symtab_hdr (input_bfd);
10139 sym_hashes = elf_sym_hashes (input_bfd);
10142 relend = relocs + input_section->reloc_count;
10143 for (; rel < relend; rel++)
10146 reloc_howto_type * howto;
10147 unsigned long r_symndx;
10148 Elf_Internal_Sym * sym;
10150 struct elf_link_hash_entry * h;
10151 bfd_vma relocation;
10152 bfd_reloc_status_type r;
10155 bfd_boolean unresolved_reloc = FALSE;
10156 char *error_message = NULL;
10158 r_symndx = ELF32_R_SYM (rel->r_info);
10159 r_type = ELF32_R_TYPE (rel->r_info);
10160 r_type = arm_real_reloc_type (globals, r_type);
10162 if ( r_type == R_ARM_GNU_VTENTRY
10163 || r_type == R_ARM_GNU_VTINHERIT)
10166 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
10167 howto = bfd_reloc.howto;
10173 if (r_symndx < symtab_hdr->sh_info)
10175 sym = local_syms + r_symndx;
10176 sym_type = ELF32_ST_TYPE (sym->st_info);
10177 sec = local_sections[r_symndx];
10179 /* An object file might have a reference to a local
10180 undefined symbol. This is a daft object file, but we
10181 should at least do something about it. V4BX & NONE
10182 relocations do not use the symbol and are explicitly
10183 allowed to use the undefined symbol, so allow those.
10184 Likewise for relocations against STN_UNDEF. */
10185 if (r_type != R_ARM_V4BX
10186 && r_type != R_ARM_NONE
10187 && r_symndx != STN_UNDEF
10188 && bfd_is_und_section (sec)
10189 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
10191 if (!info->callbacks->undefined_symbol
10192 (info, bfd_elf_string_from_elf_section
10193 (input_bfd, symtab_hdr->sh_link, sym->st_name),
10194 input_bfd, input_section,
10195 rel->r_offset, TRUE))
10199 if (globals->use_rel)
10201 relocation = (sec->output_section->vma
10202 + sec->output_offset
10204 if (!info->relocatable
10205 && (sec->flags & SEC_MERGE)
10206 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
10209 bfd_vma addend, value;
10213 case R_ARM_MOVW_ABS_NC:
10214 case R_ARM_MOVT_ABS:
10215 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
10216 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
10217 addend = (addend ^ 0x8000) - 0x8000;
10220 case R_ARM_THM_MOVW_ABS_NC:
10221 case R_ARM_THM_MOVT_ABS:
10222 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
10224 value |= bfd_get_16 (input_bfd,
10225 contents + rel->r_offset + 2);
10226 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
10227 | ((value & 0x04000000) >> 15);
10228 addend = (addend ^ 0x8000) - 0x8000;
10232 if (howto->rightshift
10233 || (howto->src_mask & (howto->src_mask + 1)))
10235 (*_bfd_error_handler)
10236 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
10237 input_bfd, input_section,
10238 (long) rel->r_offset, howto->name);
10242 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
10244 /* Get the (signed) value from the instruction. */
10245 addend = value & howto->src_mask;
10246 if (addend & ((howto->src_mask + 1) >> 1))
10248 bfd_signed_vma mask;
10251 mask &= ~ howto->src_mask;
10259 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
10261 addend += msec->output_section->vma + msec->output_offset;
10263 /* Cases here must match those in the preceding
10264 switch statement. */
10267 case R_ARM_MOVW_ABS_NC:
10268 case R_ARM_MOVT_ABS:
10269 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
10270 | (addend & 0xfff);
10271 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
10274 case R_ARM_THM_MOVW_ABS_NC:
10275 case R_ARM_THM_MOVT_ABS:
10276 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
10277 | (addend & 0xff) | ((addend & 0x0800) << 15);
10278 bfd_put_16 (input_bfd, value >> 16,
10279 contents + rel->r_offset);
10280 bfd_put_16 (input_bfd, value,
10281 contents + rel->r_offset + 2);
10285 value = (value & ~ howto->dst_mask)
10286 | (addend & howto->dst_mask);
10287 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
10293 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
10297 bfd_boolean warned;
10299 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
10300 r_symndx, symtab_hdr, sym_hashes,
10301 h, sec, relocation,
10302 unresolved_reloc, warned);
10304 sym_type = h->type;
10307 if (sec != NULL && elf_discarded_section (sec))
10308 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
10309 rel, relend, howto, contents);
10311 if (info->relocatable)
10313 /* This is a relocatable link. We don't have to change
10314 anything, unless the reloc is against a section symbol,
10315 in which case we have to adjust according to where the
10316 section symbol winds up in the output section. */
10317 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
10319 if (globals->use_rel)
10320 arm_add_to_rel (input_bfd, contents + rel->r_offset,
10321 howto, (bfd_signed_vma) sec->output_offset);
10323 rel->r_addend += sec->output_offset;
10329 name = h->root.root.string;
10332 name = (bfd_elf_string_from_elf_section
10333 (input_bfd, symtab_hdr->sh_link, sym->st_name));
10334 if (name == NULL || *name == '\0')
10335 name = bfd_section_name (input_bfd, sec);
10338 if (r_symndx != STN_UNDEF
10339 && r_type != R_ARM_NONE
10341 || h->root.type == bfd_link_hash_defined
10342 || h->root.type == bfd_link_hash_defweak)
10343 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
10345 (*_bfd_error_handler)
10346 ((sym_type == STT_TLS
10347 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
10348 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
10351 (long) rel->r_offset,
10356 /* We call elf32_arm_final_link_relocate unless we're completely
10357 done, i.e., the relaxation produced the final output we want,
10358 and we won't let anybody mess with it. Also, we have to do
10359 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
10360 both in relaxed and non-relaxed cases */
10361 if ((elf32_arm_tls_transition (info, r_type, h) != (unsigned)r_type)
10362 || (IS_ARM_TLS_GNU_RELOC (r_type)
10363 && !((h ? elf32_arm_hash_entry (h)->tls_type :
10364 elf32_arm_local_got_tls_type (input_bfd)[r_symndx])
10367 r = elf32_arm_tls_relax (globals, input_bfd, input_section,
10368 contents, rel, h == NULL);
10369 /* This may have been marked unresolved because it came from
10370 a shared library. But we've just dealt with that. */
10371 unresolved_reloc = 0;
10374 r = bfd_reloc_continue;
10376 if (r == bfd_reloc_continue)
10377 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
10378 input_section, contents, rel,
10379 relocation, info, sec, name, sym_type,
10380 (h ? h->target_internal
10381 : ARM_SYM_BRANCH_TYPE (sym)), h,
10382 &unresolved_reloc, &error_message);
10384 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
10385 because such sections are not SEC_ALLOC and thus ld.so will
10386 not process them. */
10387 if (unresolved_reloc
10388 && !((input_section->flags & SEC_DEBUGGING) != 0
10390 && _bfd_elf_section_offset (output_bfd, info, input_section,
10391 rel->r_offset) != (bfd_vma) -1)
10393 (*_bfd_error_handler)
10394 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
10397 (long) rel->r_offset,
10399 h->root.root.string);
10403 if (r != bfd_reloc_ok)
10407 case bfd_reloc_overflow:
10408 /* If the overflowing reloc was to an undefined symbol,
10409 we have already printed one error message and there
10410 is no point complaining again. */
10412 h->root.type != bfd_link_hash_undefined)
10413 && (!((*info->callbacks->reloc_overflow)
10414 (info, (h ? &h->root : NULL), name, howto->name,
10415 (bfd_vma) 0, input_bfd, input_section,
10420 case bfd_reloc_undefined:
10421 if (!((*info->callbacks->undefined_symbol)
10422 (info, name, input_bfd, input_section,
10423 rel->r_offset, TRUE)))
10427 case bfd_reloc_outofrange:
10428 error_message = _("out of range");
10431 case bfd_reloc_notsupported:
10432 error_message = _("unsupported relocation");
10435 case bfd_reloc_dangerous:
10436 /* error_message should already be set. */
10440 error_message = _("unknown error");
10441 /* Fall through. */
10444 BFD_ASSERT (error_message != NULL);
10445 if (!((*info->callbacks->reloc_dangerous)
10446 (info, error_message, input_bfd, input_section,
10457 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
10458 adds the edit to the start of the list. (The list must be built in order of
10459 ascending TINDEX: the function's callers are primarily responsible for
10460 maintaining that condition). */
10463 add_unwind_table_edit (arm_unwind_table_edit **head,
10464 arm_unwind_table_edit **tail,
10465 arm_unwind_edit_type type,
10466 asection *linked_section,
10467 unsigned int tindex)
10469 arm_unwind_table_edit *new_edit = (arm_unwind_table_edit *)
10470 xmalloc (sizeof (arm_unwind_table_edit));
10472 new_edit->type = type;
10473 new_edit->linked_section = linked_section;
10474 new_edit->index = tindex;
10478 new_edit->next = NULL;
10481 (*tail)->next = new_edit;
10483 (*tail) = new_edit;
10486 (*head) = new_edit;
10490 new_edit->next = *head;
10499 static _arm_elf_section_data *get_arm_elf_section_data (asection *);
10501 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
10503 adjust_exidx_size(asection *exidx_sec, int adjust)
10507 if (!exidx_sec->rawsize)
10508 exidx_sec->rawsize = exidx_sec->size;
10510 bfd_set_section_size (exidx_sec->owner, exidx_sec, exidx_sec->size + adjust);
10511 out_sec = exidx_sec->output_section;
10512 /* Adjust size of output section. */
10513 bfd_set_section_size (out_sec->owner, out_sec, out_sec->size +adjust);
10516 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
10518 insert_cantunwind_after(asection *text_sec, asection *exidx_sec)
10520 struct _arm_elf_section_data *exidx_arm_data;
10522 exidx_arm_data = get_arm_elf_section_data (exidx_sec);
10523 add_unwind_table_edit (
10524 &exidx_arm_data->u.exidx.unwind_edit_list,
10525 &exidx_arm_data->u.exidx.unwind_edit_tail,
10526 INSERT_EXIDX_CANTUNWIND_AT_END, text_sec, UINT_MAX);
10528 adjust_exidx_size(exidx_sec, 8);
10531 /* Scan .ARM.exidx tables, and create a list describing edits which should be
10532 made to those tables, such that:
10534 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
10535 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
10536 codes which have been inlined into the index).
10538 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
10540 The edits are applied when the tables are written
10541 (in elf32_arm_write_section).
10545 elf32_arm_fix_exidx_coverage (asection **text_section_order,
10546 unsigned int num_text_sections,
10547 struct bfd_link_info *info,
10548 bfd_boolean merge_exidx_entries)
10551 unsigned int last_second_word = 0, i;
10552 asection *last_exidx_sec = NULL;
10553 asection *last_text_sec = NULL;
10554 int last_unwind_type = -1;
10556 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
10558 for (inp = info->input_bfds; inp != NULL; inp = inp->link_next)
10562 for (sec = inp->sections; sec != NULL; sec = sec->next)
10564 struct bfd_elf_section_data *elf_sec = elf_section_data (sec);
10565 Elf_Internal_Shdr *hdr = &elf_sec->this_hdr;
10567 if (!hdr || hdr->sh_type != SHT_ARM_EXIDX)
10570 if (elf_sec->linked_to)
10572 Elf_Internal_Shdr *linked_hdr
10573 = &elf_section_data (elf_sec->linked_to)->this_hdr;
10574 struct _arm_elf_section_data *linked_sec_arm_data
10575 = get_arm_elf_section_data (linked_hdr->bfd_section);
10577 if (linked_sec_arm_data == NULL)
10580 /* Link this .ARM.exidx section back from the text section it
10582 linked_sec_arm_data->u.text.arm_exidx_sec = sec;
10587 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
10588 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
10589 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
10591 for (i = 0; i < num_text_sections; i++)
10593 asection *sec = text_section_order[i];
10594 asection *exidx_sec;
10595 struct _arm_elf_section_data *arm_data = get_arm_elf_section_data (sec);
10596 struct _arm_elf_section_data *exidx_arm_data;
10597 bfd_byte *contents = NULL;
10598 int deleted_exidx_bytes = 0;
10600 arm_unwind_table_edit *unwind_edit_head = NULL;
10601 arm_unwind_table_edit *unwind_edit_tail = NULL;
10602 Elf_Internal_Shdr *hdr;
10605 if (arm_data == NULL)
10608 exidx_sec = arm_data->u.text.arm_exidx_sec;
10609 if (exidx_sec == NULL)
10611 /* Section has no unwind data. */
10612 if (last_unwind_type == 0 || !last_exidx_sec)
10615 /* Ignore zero sized sections. */
10616 if (sec->size == 0)
10619 insert_cantunwind_after(last_text_sec, last_exidx_sec);
10620 last_unwind_type = 0;
10624 /* Skip /DISCARD/ sections. */
10625 if (bfd_is_abs_section (exidx_sec->output_section))
10628 hdr = &elf_section_data (exidx_sec)->this_hdr;
10629 if (hdr->sh_type != SHT_ARM_EXIDX)
10632 exidx_arm_data = get_arm_elf_section_data (exidx_sec);
10633 if (exidx_arm_data == NULL)
10636 ibfd = exidx_sec->owner;
10638 if (hdr->contents != NULL)
10639 contents = hdr->contents;
10640 else if (! bfd_malloc_and_get_section (ibfd, exidx_sec, &contents))
10644 for (j = 0; j < hdr->sh_size; j += 8)
10646 unsigned int second_word = bfd_get_32 (ibfd, contents + j + 4);
10650 /* An EXIDX_CANTUNWIND entry. */
10651 if (second_word == 1)
10653 if (last_unwind_type == 0)
10657 /* Inlined unwinding data. Merge if equal to previous. */
10658 else if ((second_word & 0x80000000) != 0)
10660 if (merge_exidx_entries
10661 && last_second_word == second_word && last_unwind_type == 1)
10664 last_second_word = second_word;
10666 /* Normal table entry. In theory we could merge these too,
10667 but duplicate entries are likely to be much less common. */
10673 add_unwind_table_edit (&unwind_edit_head, &unwind_edit_tail,
10674 DELETE_EXIDX_ENTRY, NULL, j / 8);
10676 deleted_exidx_bytes += 8;
10679 last_unwind_type = unwind_type;
10682 /* Free contents if we allocated it ourselves. */
10683 if (contents != hdr->contents)
10686 /* Record edits to be applied later (in elf32_arm_write_section). */
10687 exidx_arm_data->u.exidx.unwind_edit_list = unwind_edit_head;
10688 exidx_arm_data->u.exidx.unwind_edit_tail = unwind_edit_tail;
10690 if (deleted_exidx_bytes > 0)
10691 adjust_exidx_size(exidx_sec, -deleted_exidx_bytes);
10693 last_exidx_sec = exidx_sec;
10694 last_text_sec = sec;
10697 /* Add terminating CANTUNWIND entry. */
10698 if (last_exidx_sec && last_unwind_type != 0)
10699 insert_cantunwind_after(last_text_sec, last_exidx_sec);
10705 elf32_arm_output_glue_section (struct bfd_link_info *info, bfd *obfd,
10706 bfd *ibfd, const char *name)
10708 asection *sec, *osec;
10710 sec = bfd_get_section_by_name (ibfd, name);
10711 if (sec == NULL || (sec->flags & SEC_EXCLUDE) != 0)
10714 osec = sec->output_section;
10715 if (elf32_arm_write_section (obfd, info, sec, sec->contents))
10718 if (! bfd_set_section_contents (obfd, osec, sec->contents,
10719 sec->output_offset, sec->size))
10726 elf32_arm_final_link (bfd *abfd, struct bfd_link_info *info)
10728 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
10729 asection *sec, *osec;
10731 if (globals == NULL)
10734 /* Invoke the regular ELF backend linker to do all the work. */
10735 if (!bfd_elf_final_link (abfd, info))
10738 /* Process stub sections (eg BE8 encoding, ...). */
10739 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
10741 for (i=0; i<htab->top_id; i++)
10743 sec = htab->stub_group[i].stub_sec;
10744 /* Only process it once, in its link_sec slot. */
10745 if (sec && i == htab->stub_group[i].link_sec->id)
10747 osec = sec->output_section;
10748 elf32_arm_write_section (abfd, info, sec, sec->contents);
10749 if (! bfd_set_section_contents (abfd, osec, sec->contents,
10750 sec->output_offset, sec->size))
10755 /* Write out any glue sections now that we have created all the
10757 if (globals->bfd_of_glue_owner != NULL)
10759 if (! elf32_arm_output_glue_section (info, abfd,
10760 globals->bfd_of_glue_owner,
10761 ARM2THUMB_GLUE_SECTION_NAME))
10764 if (! elf32_arm_output_glue_section (info, abfd,
10765 globals->bfd_of_glue_owner,
10766 THUMB2ARM_GLUE_SECTION_NAME))
10769 if (! elf32_arm_output_glue_section (info, abfd,
10770 globals->bfd_of_glue_owner,
10771 VFP11_ERRATUM_VENEER_SECTION_NAME))
10774 if (! elf32_arm_output_glue_section (info, abfd,
10775 globals->bfd_of_glue_owner,
10776 ARM_BX_GLUE_SECTION_NAME))
10783 /* Set the right machine number. */
10786 elf32_arm_object_p (bfd *abfd)
10790 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
10792 if (mach != bfd_mach_arm_unknown)
10793 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
10795 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
10796 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
10799 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
10804 /* Function to keep ARM specific flags in the ELF header. */
10807 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
10809 if (elf_flags_init (abfd)
10810 && elf_elfheader (abfd)->e_flags != flags)
10812 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
10814 if (flags & EF_ARM_INTERWORK)
10815 (*_bfd_error_handler)
10816 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
10820 (_("Warning: Clearing the interworking flag of %B due to outside request"),
10826 elf_elfheader (abfd)->e_flags = flags;
10827 elf_flags_init (abfd) = TRUE;
10833 /* Copy backend specific data from one object module to another. */
10836 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
10839 flagword out_flags;
10841 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
10844 in_flags = elf_elfheader (ibfd)->e_flags;
10845 out_flags = elf_elfheader (obfd)->e_flags;
10847 if (elf_flags_init (obfd)
10848 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
10849 && in_flags != out_flags)
10851 /* Cannot mix APCS26 and APCS32 code. */
10852 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
10855 /* Cannot mix float APCS and non-float APCS code. */
10856 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
10859 /* If the src and dest have different interworking flags
10860 then turn off the interworking bit. */
10861 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
10863 if (out_flags & EF_ARM_INTERWORK)
10865 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
10868 in_flags &= ~EF_ARM_INTERWORK;
10871 /* Likewise for PIC, though don't warn for this case. */
10872 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
10873 in_flags &= ~EF_ARM_PIC;
10876 elf_elfheader (obfd)->e_flags = in_flags;
10877 elf_flags_init (obfd) = TRUE;
10879 /* Also copy the EI_OSABI field. */
10880 elf_elfheader (obfd)->e_ident[EI_OSABI] =
10881 elf_elfheader (ibfd)->e_ident[EI_OSABI];
10883 /* Copy object attributes. */
10884 _bfd_elf_copy_obj_attributes (ibfd, obfd);
10889 /* Values for Tag_ABI_PCS_R9_use. */
10898 /* Values for Tag_ABI_PCS_RW_data. */
10901 AEABI_PCS_RW_data_absolute,
10902 AEABI_PCS_RW_data_PCrel,
10903 AEABI_PCS_RW_data_SBrel,
10904 AEABI_PCS_RW_data_unused
10907 /* Values for Tag_ABI_enum_size. */
10913 AEABI_enum_forced_wide
10916 /* Determine whether an object attribute tag takes an integer, a
10920 elf32_arm_obj_attrs_arg_type (int tag)
10922 if (tag == Tag_compatibility)
10923 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
10924 else if (tag == Tag_nodefaults)
10925 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
10926 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
10927 return ATTR_TYPE_FLAG_STR_VAL;
10929 return ATTR_TYPE_FLAG_INT_VAL;
10931 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
10934 /* The ABI defines that Tag_conformance should be emitted first, and that
10935 Tag_nodefaults should be second (if either is defined). This sets those
10936 two positions, and bumps up the position of all the remaining tags to
10939 elf32_arm_obj_attrs_order (int num)
10941 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
10942 return Tag_conformance;
10943 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE + 1)
10944 return Tag_nodefaults;
10945 if ((num - 2) < Tag_nodefaults)
10947 if ((num - 1) < Tag_conformance)
10952 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
10954 elf32_arm_obj_attrs_handle_unknown (bfd *abfd, int tag)
10956 if ((tag & 127) < 64)
10959 (_("%B: Unknown mandatory EABI object attribute %d"),
10961 bfd_set_error (bfd_error_bad_value);
10967 (_("Warning: %B: Unknown EABI object attribute %d"),
10973 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
10974 Returns -1 if no architecture could be read. */
10977 get_secondary_compatible_arch (bfd *abfd)
10979 obj_attribute *attr =
10980 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
10982 /* Note: the tag and its argument below are uleb128 values, though
10983 currently-defined values fit in one byte for each. */
10985 && attr->s[0] == Tag_CPU_arch
10986 && (attr->s[1] & 128) != 128
10987 && attr->s[2] == 0)
10990 /* This tag is "safely ignorable", so don't complain if it looks funny. */
10994 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
10995 The tag is removed if ARCH is -1. */
10998 set_secondary_compatible_arch (bfd *abfd, int arch)
11000 obj_attribute *attr =
11001 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
11009 /* Note: the tag and its argument below are uleb128 values, though
11010 currently-defined values fit in one byte for each. */
11012 attr->s = (char *) bfd_alloc (abfd, 3);
11013 attr->s[0] = Tag_CPU_arch;
11018 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
11022 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
11023 int newtag, int secondary_compat)
11025 #define T(X) TAG_CPU_ARCH_##X
11026 int tagl, tagh, result;
11029 T(V6T2), /* PRE_V4. */
11031 T(V6T2), /* V4T. */
11032 T(V6T2), /* V5T. */
11033 T(V6T2), /* V5TE. */
11034 T(V6T2), /* V5TEJ. */
11037 T(V6T2) /* V6T2. */
11041 T(V6K), /* PRE_V4. */
11045 T(V6K), /* V5TE. */
11046 T(V6K), /* V5TEJ. */
11048 T(V6KZ), /* V6KZ. */
11054 T(V7), /* PRE_V4. */
11059 T(V7), /* V5TEJ. */
11072 T(V6K), /* V5TE. */
11073 T(V6K), /* V5TEJ. */
11075 T(V6KZ), /* V6KZ. */
11079 T(V6_M) /* V6_M. */
11081 const int v6s_m[] =
11087 T(V6K), /* V5TE. */
11088 T(V6K), /* V5TEJ. */
11090 T(V6KZ), /* V6KZ. */
11094 T(V6S_M), /* V6_M. */
11095 T(V6S_M) /* V6S_M. */
11097 const int v7e_m[] =
11101 T(V7E_M), /* V4T. */
11102 T(V7E_M), /* V5T. */
11103 T(V7E_M), /* V5TE. */
11104 T(V7E_M), /* V5TEJ. */
11105 T(V7E_M), /* V6. */
11106 T(V7E_M), /* V6KZ. */
11107 T(V7E_M), /* V6T2. */
11108 T(V7E_M), /* V6K. */
11109 T(V7E_M), /* V7. */
11110 T(V7E_M), /* V6_M. */
11111 T(V7E_M), /* V6S_M. */
11112 T(V7E_M) /* V7E_M. */
11114 const int v4t_plus_v6_m[] =
11120 T(V5TE), /* V5TE. */
11121 T(V5TEJ), /* V5TEJ. */
11123 T(V6KZ), /* V6KZ. */
11124 T(V6T2), /* V6T2. */
11127 T(V6_M), /* V6_M. */
11128 T(V6S_M), /* V6S_M. */
11129 T(V7E_M), /* V7E_M. */
11130 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
11132 const int *comb[] =
11140 /* Pseudo-architecture. */
11144 /* Check we've not got a higher architecture than we know about. */
11146 if (oldtag > MAX_TAG_CPU_ARCH || newtag > MAX_TAG_CPU_ARCH)
11148 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd);
11152 /* Override old tag if we have a Tag_also_compatible_with on the output. */
11154 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
11155 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
11156 oldtag = T(V4T_PLUS_V6_M);
11158 /* And override the new tag if we have a Tag_also_compatible_with on the
11161 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
11162 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
11163 newtag = T(V4T_PLUS_V6_M);
11165 tagl = (oldtag < newtag) ? oldtag : newtag;
11166 result = tagh = (oldtag > newtag) ? oldtag : newtag;
11168 /* Architectures before V6KZ add features monotonically. */
11169 if (tagh <= TAG_CPU_ARCH_V6KZ)
11172 result = comb[tagh - T(V6T2)][tagl];
11174 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
11175 as the canonical version. */
11176 if (result == T(V4T_PLUS_V6_M))
11179 *secondary_compat_out = T(V6_M);
11182 *secondary_compat_out = -1;
11186 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
11187 ibfd, oldtag, newtag);
11195 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
11196 are conflicting attributes. */
11199 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
11201 obj_attribute *in_attr;
11202 obj_attribute *out_attr;
11203 /* Some tags have 0 = don't care, 1 = strong requirement,
11204 2 = weak requirement. */
11205 static const int order_021[3] = {0, 2, 1};
11207 bfd_boolean result = TRUE;
11209 /* Skip the linker stubs file. This preserves previous behavior
11210 of accepting unknown attributes in the first input file - but
11212 if (ibfd->flags & BFD_LINKER_CREATED)
11215 if (!elf_known_obj_attributes_proc (obfd)[0].i)
11217 /* This is the first object. Copy the attributes. */
11218 _bfd_elf_copy_obj_attributes (ibfd, obfd);
11220 out_attr = elf_known_obj_attributes_proc (obfd);
11222 /* Use the Tag_null value to indicate the attributes have been
11226 /* We do not output objects with Tag_MPextension_use_legacy - we move
11227 the attribute's value to Tag_MPextension_use. */
11228 if (out_attr[Tag_MPextension_use_legacy].i != 0)
11230 if (out_attr[Tag_MPextension_use].i != 0
11231 && out_attr[Tag_MPextension_use_legacy].i
11232 != out_attr[Tag_MPextension_use].i)
11235 (_("Error: %B has both the current and legacy "
11236 "Tag_MPextension_use attributes"), ibfd);
11240 out_attr[Tag_MPextension_use] =
11241 out_attr[Tag_MPextension_use_legacy];
11242 out_attr[Tag_MPextension_use_legacy].type = 0;
11243 out_attr[Tag_MPextension_use_legacy].i = 0;
11249 in_attr = elf_known_obj_attributes_proc (ibfd);
11250 out_attr = elf_known_obj_attributes_proc (obfd);
11251 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
11252 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
11254 /* Ignore mismatches if the object doesn't use floating point. */
11255 if (out_attr[Tag_ABI_FP_number_model].i == 0)
11256 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
11257 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
11260 (_("error: %B uses VFP register arguments, %B does not"),
11261 in_attr[Tag_ABI_VFP_args].i ? ibfd : obfd,
11262 in_attr[Tag_ABI_VFP_args].i ? obfd : ibfd);
11267 for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
11269 /* Merge this attribute with existing attributes. */
11272 case Tag_CPU_raw_name:
11274 /* These are merged after Tag_CPU_arch. */
11277 case Tag_ABI_optimization_goals:
11278 case Tag_ABI_FP_optimization_goals:
11279 /* Use the first value seen. */
11284 int secondary_compat = -1, secondary_compat_out = -1;
11285 unsigned int saved_out_attr = out_attr[i].i;
11286 static const char *name_table[] = {
11287 /* These aren't real CPU names, but we can't guess
11288 that from the architecture version alone. */
11304 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
11305 secondary_compat = get_secondary_compatible_arch (ibfd);
11306 secondary_compat_out = get_secondary_compatible_arch (obfd);
11307 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
11308 &secondary_compat_out,
11311 set_secondary_compatible_arch (obfd, secondary_compat_out);
11313 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
11314 if (out_attr[i].i == saved_out_attr)
11315 ; /* Leave the names alone. */
11316 else if (out_attr[i].i == in_attr[i].i)
11318 /* The output architecture has been changed to match the
11319 input architecture. Use the input names. */
11320 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
11321 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
11323 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
11324 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
11329 out_attr[Tag_CPU_name].s = NULL;
11330 out_attr[Tag_CPU_raw_name].s = NULL;
11333 /* If we still don't have a value for Tag_CPU_name,
11334 make one up now. Tag_CPU_raw_name remains blank. */
11335 if (out_attr[Tag_CPU_name].s == NULL
11336 && out_attr[i].i < ARRAY_SIZE (name_table))
11337 out_attr[Tag_CPU_name].s =
11338 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
11342 case Tag_ARM_ISA_use:
11343 case Tag_THUMB_ISA_use:
11344 case Tag_WMMX_arch:
11345 case Tag_Advanced_SIMD_arch:
11346 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
11347 case Tag_ABI_FP_rounding:
11348 case Tag_ABI_FP_exceptions:
11349 case Tag_ABI_FP_user_exceptions:
11350 case Tag_ABI_FP_number_model:
11351 case Tag_FP_HP_extension:
11352 case Tag_CPU_unaligned_access:
11354 case Tag_MPextension_use:
11355 /* Use the largest value specified. */
11356 if (in_attr[i].i > out_attr[i].i)
11357 out_attr[i].i = in_attr[i].i;
11360 case Tag_ABI_align_preserved:
11361 case Tag_ABI_PCS_RO_data:
11362 /* Use the smallest value specified. */
11363 if (in_attr[i].i < out_attr[i].i)
11364 out_attr[i].i = in_attr[i].i;
11367 case Tag_ABI_align_needed:
11368 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
11369 && (in_attr[Tag_ABI_align_preserved].i == 0
11370 || out_attr[Tag_ABI_align_preserved].i == 0))
11372 /* This error message should be enabled once all non-conformant
11373 binaries in the toolchain have had the attributes set
11376 (_("error: %B: 8-byte data alignment conflicts with %B"),
11380 /* Fall through. */
11381 case Tag_ABI_FP_denormal:
11382 case Tag_ABI_PCS_GOT_use:
11383 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
11384 value if greater than 2 (for future-proofing). */
11385 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
11386 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
11387 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
11388 out_attr[i].i = in_attr[i].i;
11391 case Tag_Virtualization_use:
11392 /* The virtualization tag effectively stores two bits of
11393 information: the intended use of TrustZone (in bit 0), and the
11394 intended use of Virtualization (in bit 1). */
11395 if (out_attr[i].i == 0)
11396 out_attr[i].i = in_attr[i].i;
11397 else if (in_attr[i].i != 0
11398 && in_attr[i].i != out_attr[i].i)
11400 if (in_attr[i].i <= 3 && out_attr[i].i <= 3)
11405 (_("error: %B: unable to merge virtualization attributes "
11413 case Tag_CPU_arch_profile:
11414 if (out_attr[i].i != in_attr[i].i)
11416 /* 0 will merge with anything.
11417 'A' and 'S' merge to 'A'.
11418 'R' and 'S' merge to 'R'.
11419 'M' and 'A|R|S' is an error. */
11420 if (out_attr[i].i == 0
11421 || (out_attr[i].i == 'S'
11422 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
11423 out_attr[i].i = in_attr[i].i;
11424 else if (in_attr[i].i == 0
11425 || (in_attr[i].i == 'S'
11426 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
11427 ; /* Do nothing. */
11431 (_("error: %B: Conflicting architecture profiles %c/%c"),
11433 in_attr[i].i ? in_attr[i].i : '0',
11434 out_attr[i].i ? out_attr[i].i : '0');
11441 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
11442 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
11443 when it's 0. It might mean absence of FP hardware if
11444 Tag_FP_arch is zero, otherwise it is effectively SP + DP. */
11446 static const struct
11450 } vfp_versions[7] =
11464 /* If the output has no requirement about FP hardware,
11465 follow the requirement of the input. */
11466 if (out_attr[i].i == 0)
11468 BFD_ASSERT (out_attr[Tag_ABI_HardFP_use].i == 0);
11469 out_attr[i].i = in_attr[i].i;
11470 out_attr[Tag_ABI_HardFP_use].i
11471 = in_attr[Tag_ABI_HardFP_use].i;
11474 /* If the input has no requirement about FP hardware, do
11476 else if (in_attr[i].i == 0)
11478 BFD_ASSERT (in_attr[Tag_ABI_HardFP_use].i == 0);
11482 /* Both the input and the output have nonzero Tag_FP_arch.
11483 So Tag_ABI_HardFP_use is (SP & DP) when it's zero. */
11485 /* If both the input and the output have zero Tag_ABI_HardFP_use,
11487 if (in_attr[Tag_ABI_HardFP_use].i == 0
11488 && out_attr[Tag_ABI_HardFP_use].i == 0)
11490 /* If the input and the output have different Tag_ABI_HardFP_use,
11491 the combination of them is 3 (SP & DP). */
11492 else if (in_attr[Tag_ABI_HardFP_use].i
11493 != out_attr[Tag_ABI_HardFP_use].i)
11494 out_attr[Tag_ABI_HardFP_use].i = 3;
11496 /* Now we can handle Tag_FP_arch. */
11498 /* Values greater than 6 aren't defined, so just pick the
11500 if (in_attr[i].i > 6 && in_attr[i].i > out_attr[i].i)
11502 out_attr[i] = in_attr[i];
11505 /* The output uses the superset of input features
11506 (ISA version) and registers. */
11507 ver = vfp_versions[in_attr[i].i].ver;
11508 if (ver < vfp_versions[out_attr[i].i].ver)
11509 ver = vfp_versions[out_attr[i].i].ver;
11510 regs = vfp_versions[in_attr[i].i].regs;
11511 if (regs < vfp_versions[out_attr[i].i].regs)
11512 regs = vfp_versions[out_attr[i].i].regs;
11513 /* This assumes all possible supersets are also a valid
11515 for (newval = 6; newval > 0; newval--)
11517 if (regs == vfp_versions[newval].regs
11518 && ver == vfp_versions[newval].ver)
11521 out_attr[i].i = newval;
11524 case Tag_PCS_config:
11525 if (out_attr[i].i == 0)
11526 out_attr[i].i = in_attr[i].i;
11527 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
11529 /* It's sometimes ok to mix different configs, so this is only
11532 (_("Warning: %B: Conflicting platform configuration"), ibfd);
11535 case Tag_ABI_PCS_R9_use:
11536 if (in_attr[i].i != out_attr[i].i
11537 && out_attr[i].i != AEABI_R9_unused
11538 && in_attr[i].i != AEABI_R9_unused)
11541 (_("error: %B: Conflicting use of R9"), ibfd);
11544 if (out_attr[i].i == AEABI_R9_unused)
11545 out_attr[i].i = in_attr[i].i;
11547 case Tag_ABI_PCS_RW_data:
11548 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
11549 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
11550 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
11553 (_("error: %B: SB relative addressing conflicts with use of R9"),
11557 /* Use the smallest value specified. */
11558 if (in_attr[i].i < out_attr[i].i)
11559 out_attr[i].i = in_attr[i].i;
11561 case Tag_ABI_PCS_wchar_t:
11562 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
11563 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
11566 (_("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"),
11567 ibfd, in_attr[i].i, out_attr[i].i);
11569 else if (in_attr[i].i && !out_attr[i].i)
11570 out_attr[i].i = in_attr[i].i;
11572 case Tag_ABI_enum_size:
11573 if (in_attr[i].i != AEABI_enum_unused)
11575 if (out_attr[i].i == AEABI_enum_unused
11576 || out_attr[i].i == AEABI_enum_forced_wide)
11578 /* The existing object is compatible with anything.
11579 Use whatever requirements the new object has. */
11580 out_attr[i].i = in_attr[i].i;
11582 else if (in_attr[i].i != AEABI_enum_forced_wide
11583 && out_attr[i].i != in_attr[i].i
11584 && !elf_arm_tdata (obfd)->no_enum_size_warning)
11586 static const char *aeabi_enum_names[] =
11587 { "", "variable-size", "32-bit", "" };
11588 const char *in_name =
11589 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
11590 ? aeabi_enum_names[in_attr[i].i]
11592 const char *out_name =
11593 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
11594 ? aeabi_enum_names[out_attr[i].i]
11597 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
11598 ibfd, in_name, out_name);
11602 case Tag_ABI_VFP_args:
11605 case Tag_ABI_WMMX_args:
11606 if (in_attr[i].i != out_attr[i].i)
11609 (_("error: %B uses iWMMXt register arguments, %B does not"),
11614 case Tag_compatibility:
11615 /* Merged in target-independent code. */
11617 case Tag_ABI_HardFP_use:
11618 /* This is handled along with Tag_FP_arch. */
11620 case Tag_ABI_FP_16bit_format:
11621 if (in_attr[i].i != 0 && out_attr[i].i != 0)
11623 if (in_attr[i].i != out_attr[i].i)
11626 (_("error: fp16 format mismatch between %B and %B"),
11631 if (in_attr[i].i != 0)
11632 out_attr[i].i = in_attr[i].i;
11636 /* This tag is set to zero if we can use UDIV and SDIV in Thumb
11637 mode on a v7-M or v7-R CPU; to one if we can not use UDIV or
11638 SDIV at all; and to two if we can use UDIV or SDIV on a v7-A
11639 CPU. We will merge as follows: If the input attribute's value
11640 is one then the output attribute's value remains unchanged. If
11641 the input attribute's value is zero or two then if the output
11642 attribute's value is one the output value is set to the input
11643 value, otherwise the output value must be the same as the
11645 if (in_attr[i].i != 1 && out_attr[i].i != 1)
11647 if (in_attr[i].i != out_attr[i].i)
11650 (_("DIV usage mismatch between %B and %B"),
11656 if (in_attr[i].i != 1)
11657 out_attr[i].i = in_attr[i].i;
11661 case Tag_MPextension_use_legacy:
11662 /* We don't output objects with Tag_MPextension_use_legacy - we
11663 move the value to Tag_MPextension_use. */
11664 if (in_attr[i].i != 0 && in_attr[Tag_MPextension_use].i != 0)
11666 if (in_attr[Tag_MPextension_use].i != in_attr[i].i)
11669 (_("%B has has both the current and legacy "
11670 "Tag_MPextension_use attributes"),
11676 if (in_attr[i].i > out_attr[Tag_MPextension_use].i)
11677 out_attr[Tag_MPextension_use] = in_attr[i];
11681 case Tag_nodefaults:
11682 /* This tag is set if it exists, but the value is unused (and is
11683 typically zero). We don't actually need to do anything here -
11684 the merge happens automatically when the type flags are merged
11687 case Tag_also_compatible_with:
11688 /* Already done in Tag_CPU_arch. */
11690 case Tag_conformance:
11691 /* Keep the attribute if it matches. Throw it away otherwise.
11692 No attribute means no claim to conform. */
11693 if (!in_attr[i].s || !out_attr[i].s
11694 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
11695 out_attr[i].s = NULL;
11700 = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
11703 /* If out_attr was copied from in_attr then it won't have a type yet. */
11704 if (in_attr[i].type && !out_attr[i].type)
11705 out_attr[i].type = in_attr[i].type;
11708 /* Merge Tag_compatibility attributes and any common GNU ones. */
11709 if (!_bfd_elf_merge_object_attributes (ibfd, obfd))
11712 /* Check for any attributes not known on ARM. */
11713 result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
11719 /* Return TRUE if the two EABI versions are incompatible. */
11722 elf32_arm_versions_compatible (unsigned iver, unsigned over)
11724 /* v4 and v5 are the same spec before and after it was released,
11725 so allow mixing them. */
11726 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
11727 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
11730 return (iver == over);
11733 /* Merge backend specific data from an object file to the output
11734 object file when linking. */
11737 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd);
11739 /* Display the flags field. */
11742 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
11744 FILE * file = (FILE *) ptr;
11745 unsigned long flags;
11747 BFD_ASSERT (abfd != NULL && ptr != NULL);
11749 /* Print normal ELF private data. */
11750 _bfd_elf_print_private_bfd_data (abfd, ptr);
11752 flags = elf_elfheader (abfd)->e_flags;
11753 /* Ignore init flag - it may not be set, despite the flags field
11754 containing valid data. */
11756 /* xgettext:c-format */
11757 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
11759 switch (EF_ARM_EABI_VERSION (flags))
11761 case EF_ARM_EABI_UNKNOWN:
11762 /* The following flag bits are GNU extensions and not part of the
11763 official ARM ELF extended ABI. Hence they are only decoded if
11764 the EABI version is not set. */
11765 if (flags & EF_ARM_INTERWORK)
11766 fprintf (file, _(" [interworking enabled]"));
11768 if (flags & EF_ARM_APCS_26)
11769 fprintf (file, " [APCS-26]");
11771 fprintf (file, " [APCS-32]");
11773 if (flags & EF_ARM_VFP_FLOAT)
11774 fprintf (file, _(" [VFP float format]"));
11775 else if (flags & EF_ARM_MAVERICK_FLOAT)
11776 fprintf (file, _(" [Maverick float format]"));
11778 fprintf (file, _(" [FPA float format]"));
11780 if (flags & EF_ARM_APCS_FLOAT)
11781 fprintf (file, _(" [floats passed in float registers]"));
11783 if (flags & EF_ARM_PIC)
11784 fprintf (file, _(" [position independent]"));
11786 if (flags & EF_ARM_NEW_ABI)
11787 fprintf (file, _(" [new ABI]"));
11789 if (flags & EF_ARM_OLD_ABI)
11790 fprintf (file, _(" [old ABI]"));
11792 if (flags & EF_ARM_SOFT_FLOAT)
11793 fprintf (file, _(" [software FP]"));
11795 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
11796 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
11797 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
11798 | EF_ARM_MAVERICK_FLOAT);
11801 case EF_ARM_EABI_VER1:
11802 fprintf (file, _(" [Version1 EABI]"));
11804 if (flags & EF_ARM_SYMSARESORTED)
11805 fprintf (file, _(" [sorted symbol table]"));
11807 fprintf (file, _(" [unsorted symbol table]"));
11809 flags &= ~ EF_ARM_SYMSARESORTED;
11812 case EF_ARM_EABI_VER2:
11813 fprintf (file, _(" [Version2 EABI]"));
11815 if (flags & EF_ARM_SYMSARESORTED)
11816 fprintf (file, _(" [sorted symbol table]"));
11818 fprintf (file, _(" [unsorted symbol table]"));
11820 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
11821 fprintf (file, _(" [dynamic symbols use segment index]"));
11823 if (flags & EF_ARM_MAPSYMSFIRST)
11824 fprintf (file, _(" [mapping symbols precede others]"));
11826 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
11827 | EF_ARM_MAPSYMSFIRST);
11830 case EF_ARM_EABI_VER3:
11831 fprintf (file, _(" [Version3 EABI]"));
11834 case EF_ARM_EABI_VER4:
11835 fprintf (file, _(" [Version4 EABI]"));
11838 case EF_ARM_EABI_VER5:
11839 fprintf (file, _(" [Version5 EABI]"));
11841 if (flags & EF_ARM_BE8)
11842 fprintf (file, _(" [BE8]"));
11844 if (flags & EF_ARM_LE8)
11845 fprintf (file, _(" [LE8]"));
11847 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
11851 fprintf (file, _(" <EABI version unrecognised>"));
11855 flags &= ~ EF_ARM_EABIMASK;
11857 if (flags & EF_ARM_RELEXEC)
11858 fprintf (file, _(" [relocatable executable]"));
11860 if (flags & EF_ARM_HASENTRY)
11861 fprintf (file, _(" [has entry point]"));
11863 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
11866 fprintf (file, _("<Unrecognised flag bits set>"));
11868 fputc ('\n', file);
11874 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
11876 switch (ELF_ST_TYPE (elf_sym->st_info))
11878 case STT_ARM_TFUNC:
11879 return ELF_ST_TYPE (elf_sym->st_info);
11881 case STT_ARM_16BIT:
11882 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
11883 This allows us to distinguish between data used by Thumb instructions
11884 and non-data (which is probably code) inside Thumb regions of an
11886 if (type != STT_OBJECT && type != STT_TLS)
11887 return ELF_ST_TYPE (elf_sym->st_info);
11898 elf32_arm_gc_mark_hook (asection *sec,
11899 struct bfd_link_info *info,
11900 Elf_Internal_Rela *rel,
11901 struct elf_link_hash_entry *h,
11902 Elf_Internal_Sym *sym)
11905 switch (ELF32_R_TYPE (rel->r_info))
11907 case R_ARM_GNU_VTINHERIT:
11908 case R_ARM_GNU_VTENTRY:
11912 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
11915 /* Update the got entry reference counts for the section being removed. */
11918 elf32_arm_gc_sweep_hook (bfd * abfd,
11919 struct bfd_link_info * info,
11921 const Elf_Internal_Rela * relocs)
11923 Elf_Internal_Shdr *symtab_hdr;
11924 struct elf_link_hash_entry **sym_hashes;
11925 bfd_signed_vma *local_got_refcounts;
11926 const Elf_Internal_Rela *rel, *relend;
11927 struct elf32_arm_link_hash_table * globals;
11929 if (info->relocatable)
11932 globals = elf32_arm_hash_table (info);
11933 if (globals == NULL)
11936 elf_section_data (sec)->local_dynrel = NULL;
11938 symtab_hdr = & elf_symtab_hdr (abfd);
11939 sym_hashes = elf_sym_hashes (abfd);
11940 local_got_refcounts = elf_local_got_refcounts (abfd);
11942 check_use_blx (globals);
11944 relend = relocs + sec->reloc_count;
11945 for (rel = relocs; rel < relend; rel++)
11947 unsigned long r_symndx;
11948 struct elf_link_hash_entry *h = NULL;
11949 struct elf32_arm_link_hash_entry *eh;
11951 bfd_boolean call_reloc_p;
11952 bfd_boolean may_become_dynamic_p;
11953 bfd_boolean may_need_local_target_p;
11954 union gotplt_union *root_plt;
11955 struct arm_plt_info *arm_plt;
11957 r_symndx = ELF32_R_SYM (rel->r_info);
11958 if (r_symndx >= symtab_hdr->sh_info)
11960 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
11961 while (h->root.type == bfd_link_hash_indirect
11962 || h->root.type == bfd_link_hash_warning)
11963 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11965 eh = (struct elf32_arm_link_hash_entry *) h;
11967 call_reloc_p = FALSE;
11968 may_become_dynamic_p = FALSE;
11969 may_need_local_target_p = FALSE;
11971 r_type = ELF32_R_TYPE (rel->r_info);
11972 r_type = arm_real_reloc_type (globals, r_type);
11976 case R_ARM_GOT_PREL:
11977 case R_ARM_TLS_GD32:
11978 case R_ARM_TLS_IE32:
11981 if (h->got.refcount > 0)
11982 h->got.refcount -= 1;
11984 else if (local_got_refcounts != NULL)
11986 if (local_got_refcounts[r_symndx] > 0)
11987 local_got_refcounts[r_symndx] -= 1;
11991 case R_ARM_TLS_LDM32:
11992 globals->tls_ldm_got.refcount -= 1;
12000 case R_ARM_THM_CALL:
12001 case R_ARM_THM_JUMP24:
12002 case R_ARM_THM_JUMP19:
12003 call_reloc_p = TRUE;
12004 may_need_local_target_p = TRUE;
12008 if (!globals->vxworks_p)
12010 may_need_local_target_p = TRUE;
12013 /* Fall through. */
12015 case R_ARM_ABS32_NOI:
12017 case R_ARM_REL32_NOI:
12018 case R_ARM_MOVW_ABS_NC:
12019 case R_ARM_MOVT_ABS:
12020 case R_ARM_MOVW_PREL_NC:
12021 case R_ARM_MOVT_PREL:
12022 case R_ARM_THM_MOVW_ABS_NC:
12023 case R_ARM_THM_MOVT_ABS:
12024 case R_ARM_THM_MOVW_PREL_NC:
12025 case R_ARM_THM_MOVT_PREL:
12026 /* Should the interworking branches be here also? */
12027 if ((info->shared || globals->root.is_relocatable_executable)
12028 && (sec->flags & SEC_ALLOC) != 0)
12031 && (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI))
12033 call_reloc_p = TRUE;
12034 may_need_local_target_p = TRUE;
12037 may_become_dynamic_p = TRUE;
12040 may_need_local_target_p = TRUE;
12047 if (may_need_local_target_p
12048 && elf32_arm_get_plt_info (abfd, eh, r_symndx, &root_plt, &arm_plt))
12050 BFD_ASSERT (root_plt->refcount > 0);
12051 root_plt->refcount -= 1;
12054 arm_plt->noncall_refcount--;
12056 if (r_type == R_ARM_THM_CALL)
12057 arm_plt->maybe_thumb_refcount--;
12059 if (r_type == R_ARM_THM_JUMP24
12060 || r_type == R_ARM_THM_JUMP19)
12061 arm_plt->thumb_refcount--;
12064 if (may_become_dynamic_p)
12066 struct elf_dyn_relocs **pp;
12067 struct elf_dyn_relocs *p;
12070 pp = &(eh->dyn_relocs);
12073 Elf_Internal_Sym *isym;
12075 isym = bfd_sym_from_r_symndx (&globals->sym_cache,
12079 pp = elf32_arm_get_local_dynreloc_list (abfd, r_symndx, isym);
12083 for (; (p = *pp) != NULL; pp = &p->next)
12086 /* Everything must go for SEC. */
12096 /* Look through the relocs for a section during the first phase. */
12099 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
12100 asection *sec, const Elf_Internal_Rela *relocs)
12102 Elf_Internal_Shdr *symtab_hdr;
12103 struct elf_link_hash_entry **sym_hashes;
12104 const Elf_Internal_Rela *rel;
12105 const Elf_Internal_Rela *rel_end;
12108 struct elf32_arm_link_hash_table *htab;
12109 bfd_boolean call_reloc_p;
12110 bfd_boolean may_become_dynamic_p;
12111 bfd_boolean may_need_local_target_p;
12112 unsigned long nsyms;
12114 if (info->relocatable)
12117 BFD_ASSERT (is_arm_elf (abfd));
12119 htab = elf32_arm_hash_table (info);
12125 /* Create dynamic sections for relocatable executables so that we can
12126 copy relocations. */
12127 if (htab->root.is_relocatable_executable
12128 && ! htab->root.dynamic_sections_created)
12130 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
12134 if (htab->root.dynobj == NULL)
12135 htab->root.dynobj = abfd;
12136 if (!create_ifunc_sections (info))
12139 dynobj = htab->root.dynobj;
12141 symtab_hdr = & elf_symtab_hdr (abfd);
12142 sym_hashes = elf_sym_hashes (abfd);
12143 nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
12145 rel_end = relocs + sec->reloc_count;
12146 for (rel = relocs; rel < rel_end; rel++)
12148 Elf_Internal_Sym *isym;
12149 struct elf_link_hash_entry *h;
12150 struct elf32_arm_link_hash_entry *eh;
12151 unsigned long r_symndx;
12154 r_symndx = ELF32_R_SYM (rel->r_info);
12155 r_type = ELF32_R_TYPE (rel->r_info);
12156 r_type = arm_real_reloc_type (htab, r_type);
12158 if (r_symndx >= nsyms
12159 /* PR 9934: It is possible to have relocations that do not
12160 refer to symbols, thus it is also possible to have an
12161 object file containing relocations but no symbol table. */
12162 && (r_symndx > STN_UNDEF || nsyms > 0))
12164 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
12173 if (r_symndx < symtab_hdr->sh_info)
12175 /* A local symbol. */
12176 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
12183 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
12184 while (h->root.type == bfd_link_hash_indirect
12185 || h->root.type == bfd_link_hash_warning)
12186 h = (struct elf_link_hash_entry *) h->root.u.i.link;
12190 eh = (struct elf32_arm_link_hash_entry *) h;
12192 call_reloc_p = FALSE;
12193 may_become_dynamic_p = FALSE;
12194 may_need_local_target_p = FALSE;
12196 /* Could be done earlier, if h were already available. */
12197 r_type = elf32_arm_tls_transition (info, r_type, h);
12201 case R_ARM_GOT_PREL:
12202 case R_ARM_TLS_GD32:
12203 case R_ARM_TLS_IE32:
12204 case R_ARM_TLS_GOTDESC:
12205 case R_ARM_TLS_DESCSEQ:
12206 case R_ARM_THM_TLS_DESCSEQ:
12207 case R_ARM_TLS_CALL:
12208 case R_ARM_THM_TLS_CALL:
12209 /* This symbol requires a global offset table entry. */
12211 int tls_type, old_tls_type;
12215 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
12217 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
12219 case R_ARM_TLS_GOTDESC:
12220 case R_ARM_TLS_CALL: case R_ARM_THM_TLS_CALL:
12221 case R_ARM_TLS_DESCSEQ: case R_ARM_THM_TLS_DESCSEQ:
12222 tls_type = GOT_TLS_GDESC; break;
12224 default: tls_type = GOT_NORMAL; break;
12230 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
12234 /* This is a global offset table entry for a local symbol. */
12235 if (!elf32_arm_allocate_local_sym_info (abfd))
12237 elf_local_got_refcounts (abfd)[r_symndx] += 1;
12238 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
12241 /* If a variable is accessed with both tls methods, two
12242 slots may be created. */
12243 if (GOT_TLS_GD_ANY_P (old_tls_type)
12244 && GOT_TLS_GD_ANY_P (tls_type))
12245 tls_type |= old_tls_type;
12247 /* We will already have issued an error message if there
12248 is a TLS/non-TLS mismatch, based on the symbol
12249 type. So just combine any TLS types needed. */
12250 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
12251 && tls_type != GOT_NORMAL)
12252 tls_type |= old_tls_type;
12254 /* If the symbol is accessed in both IE and GDESC
12255 method, we're able to relax. Turn off the GDESC flag,
12256 without messing up with any other kind of tls types
12257 that may be involved */
12258 if ((tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_GDESC))
12259 tls_type &= ~GOT_TLS_GDESC;
12261 if (old_tls_type != tls_type)
12264 elf32_arm_hash_entry (h)->tls_type = tls_type;
12266 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
12269 /* Fall through. */
12271 case R_ARM_TLS_LDM32:
12272 if (r_type == R_ARM_TLS_LDM32)
12273 htab->tls_ldm_got.refcount++;
12274 /* Fall through. */
12276 case R_ARM_GOTOFF32:
12278 if (htab->root.sgot == NULL
12279 && !create_got_section (htab->root.dynobj, info))
12288 case R_ARM_THM_CALL:
12289 case R_ARM_THM_JUMP24:
12290 case R_ARM_THM_JUMP19:
12291 call_reloc_p = TRUE;
12292 may_need_local_target_p = TRUE;
12296 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
12297 ldr __GOTT_INDEX__ offsets. */
12298 if (!htab->vxworks_p)
12300 may_need_local_target_p = TRUE;
12303 /* Fall through. */
12305 case R_ARM_MOVW_ABS_NC:
12306 case R_ARM_MOVT_ABS:
12307 case R_ARM_THM_MOVW_ABS_NC:
12308 case R_ARM_THM_MOVT_ABS:
12311 (*_bfd_error_handler)
12312 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
12313 abfd, elf32_arm_howto_table_1[r_type].name,
12314 (h) ? h->root.root.string : "a local symbol");
12315 bfd_set_error (bfd_error_bad_value);
12319 /* Fall through. */
12321 case R_ARM_ABS32_NOI:
12323 case R_ARM_REL32_NOI:
12324 case R_ARM_MOVW_PREL_NC:
12325 case R_ARM_MOVT_PREL:
12326 case R_ARM_THM_MOVW_PREL_NC:
12327 case R_ARM_THM_MOVT_PREL:
12329 /* Should the interworking branches be listed here? */
12330 if ((info->shared || htab->root.is_relocatable_executable)
12331 && (sec->flags & SEC_ALLOC) != 0)
12334 && (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI))
12336 /* In shared libraries and relocatable executables,
12337 we treat local relative references as calls;
12338 see the related SYMBOL_CALLS_LOCAL code in
12339 allocate_dynrelocs. */
12340 call_reloc_p = TRUE;
12341 may_need_local_target_p = TRUE;
12344 /* We are creating a shared library or relocatable
12345 executable, and this is a reloc against a global symbol,
12346 or a non-PC-relative reloc against a local symbol.
12347 We may need to copy the reloc into the output. */
12348 may_become_dynamic_p = TRUE;
12351 may_need_local_target_p = TRUE;
12354 /* This relocation describes the C++ object vtable hierarchy.
12355 Reconstruct it for later use during GC. */
12356 case R_ARM_GNU_VTINHERIT:
12357 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
12361 /* This relocation describes which C++ vtable entries are actually
12362 used. Record for later use during GC. */
12363 case R_ARM_GNU_VTENTRY:
12364 BFD_ASSERT (h != NULL);
12366 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
12374 /* We may need a .plt entry if the function this reloc
12375 refers to is in a different object, regardless of the
12376 symbol's type. We can't tell for sure yet, because
12377 something later might force the symbol local. */
12379 else if (may_need_local_target_p)
12380 /* If this reloc is in a read-only section, we might
12381 need a copy reloc. We can't check reliably at this
12382 stage whether the section is read-only, as input
12383 sections have not yet been mapped to output sections.
12384 Tentatively set the flag for now, and correct in
12385 adjust_dynamic_symbol. */
12386 h->non_got_ref = 1;
12389 if (may_need_local_target_p
12390 && (h != NULL || ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC))
12392 union gotplt_union *root_plt;
12393 struct arm_plt_info *arm_plt;
12394 struct arm_local_iplt_info *local_iplt;
12398 root_plt = &h->plt;
12399 arm_plt = &eh->plt;
12403 local_iplt = elf32_arm_create_local_iplt (abfd, r_symndx);
12404 if (local_iplt == NULL)
12406 root_plt = &local_iplt->root;
12407 arm_plt = &local_iplt->arm;
12410 /* If the symbol is a function that doesn't bind locally,
12411 this relocation will need a PLT entry. */
12412 root_plt->refcount += 1;
12415 arm_plt->noncall_refcount++;
12417 /* It's too early to use htab->use_blx here, so we have to
12418 record possible blx references separately from
12419 relocs that definitely need a thumb stub. */
12421 if (r_type == R_ARM_THM_CALL)
12422 arm_plt->maybe_thumb_refcount += 1;
12424 if (r_type == R_ARM_THM_JUMP24
12425 || r_type == R_ARM_THM_JUMP19)
12426 arm_plt->thumb_refcount += 1;
12429 if (may_become_dynamic_p)
12431 struct elf_dyn_relocs *p, **head;
12433 /* Create a reloc section in dynobj. */
12434 if (sreloc == NULL)
12436 sreloc = _bfd_elf_make_dynamic_reloc_section
12437 (sec, dynobj, 2, abfd, ! htab->use_rel);
12439 if (sreloc == NULL)
12442 /* BPABI objects never have dynamic relocations mapped. */
12443 if (htab->symbian_p)
12447 flags = bfd_get_section_flags (dynobj, sreloc);
12448 flags &= ~(SEC_LOAD | SEC_ALLOC);
12449 bfd_set_section_flags (dynobj, sreloc, flags);
12453 /* If this is a global symbol, count the number of
12454 relocations we need for this symbol. */
12456 head = &((struct elf32_arm_link_hash_entry *) h)->dyn_relocs;
12459 head = elf32_arm_get_local_dynreloc_list (abfd, r_symndx, isym);
12465 if (p == NULL || p->sec != sec)
12467 bfd_size_type amt = sizeof *p;
12469 p = (struct elf_dyn_relocs *) bfd_alloc (htab->root.dynobj, amt);
12479 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
12488 /* Unwinding tables are not referenced directly. This pass marks them as
12489 required if the corresponding code section is marked. */
12492 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
12493 elf_gc_mark_hook_fn gc_mark_hook)
12496 Elf_Internal_Shdr **elf_shdrp;
12499 _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
12501 /* Marking EH data may cause additional code sections to be marked,
12502 requiring multiple passes. */
12507 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
12511 if (! is_arm_elf (sub))
12514 elf_shdrp = elf_elfsections (sub);
12515 for (o = sub->sections; o != NULL; o = o->next)
12517 Elf_Internal_Shdr *hdr;
12519 hdr = &elf_section_data (o)->this_hdr;
12520 if (hdr->sh_type == SHT_ARM_EXIDX
12522 && hdr->sh_link < elf_numsections (sub)
12524 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
12527 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
12537 /* Treat mapping symbols as special target symbols. */
12540 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
12542 return bfd_is_arm_special_symbol_name (sym->name,
12543 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
12546 /* This is a copy of elf_find_function() from elf.c except that
12547 ARM mapping symbols are ignored when looking for function names
12548 and STT_ARM_TFUNC is considered to a function type. */
12551 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
12552 asection * section,
12553 asymbol ** symbols,
12555 const char ** filename_ptr,
12556 const char ** functionname_ptr)
12558 const char * filename = NULL;
12559 asymbol * func = NULL;
12560 bfd_vma low_func = 0;
12563 for (p = symbols; *p != NULL; p++)
12565 elf_symbol_type *q;
12567 q = (elf_symbol_type *) *p;
12569 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
12574 filename = bfd_asymbol_name (&q->symbol);
12577 case STT_ARM_TFUNC:
12579 /* Skip mapping symbols. */
12580 if ((q->symbol.flags & BSF_LOCAL)
12581 && bfd_is_arm_special_symbol_name (q->symbol.name,
12582 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
12584 /* Fall through. */
12585 if (bfd_get_section (&q->symbol) == section
12586 && q->symbol.value >= low_func
12587 && q->symbol.value <= offset)
12589 func = (asymbol *) q;
12590 low_func = q->symbol.value;
12600 *filename_ptr = filename;
12601 if (functionname_ptr)
12602 *functionname_ptr = bfd_asymbol_name (func);
12608 /* Find the nearest line to a particular section and offset, for error
12609 reporting. This code is a duplicate of the code in elf.c, except
12610 that it uses arm_elf_find_function. */
12613 elf32_arm_find_nearest_line (bfd * abfd,
12614 asection * section,
12615 asymbol ** symbols,
12617 const char ** filename_ptr,
12618 const char ** functionname_ptr,
12619 unsigned int * line_ptr)
12621 bfd_boolean found = FALSE;
12623 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
12625 if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
12626 section, symbols, offset,
12627 filename_ptr, functionname_ptr,
12629 & elf_tdata (abfd)->dwarf2_find_line_info))
12631 if (!*functionname_ptr)
12632 arm_elf_find_function (abfd, section, symbols, offset,
12633 *filename_ptr ? NULL : filename_ptr,
12639 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
12640 & found, filename_ptr,
12641 functionname_ptr, line_ptr,
12642 & elf_tdata (abfd)->line_info))
12645 if (found && (*functionname_ptr || *line_ptr))
12648 if (symbols == NULL)
12651 if (! arm_elf_find_function (abfd, section, symbols, offset,
12652 filename_ptr, functionname_ptr))
12660 elf32_arm_find_inliner_info (bfd * abfd,
12661 const char ** filename_ptr,
12662 const char ** functionname_ptr,
12663 unsigned int * line_ptr)
12666 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
12667 functionname_ptr, line_ptr,
12668 & elf_tdata (abfd)->dwarf2_find_line_info);
12672 /* Adjust a symbol defined by a dynamic object and referenced by a
12673 regular object. The current definition is in some section of the
12674 dynamic object, but we're not including those sections. We have to
12675 change the definition to something the rest of the link can
12679 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
12680 struct elf_link_hash_entry * h)
12684 struct elf32_arm_link_hash_entry * eh;
12685 struct elf32_arm_link_hash_table *globals;
12687 globals = elf32_arm_hash_table (info);
12688 if (globals == NULL)
12691 dynobj = elf_hash_table (info)->dynobj;
12693 /* Make sure we know what is going on here. */
12694 BFD_ASSERT (dynobj != NULL
12696 || h->type == STT_GNU_IFUNC
12697 || h->u.weakdef != NULL
12700 && !h->def_regular)));
12702 eh = (struct elf32_arm_link_hash_entry *) h;
12704 /* If this is a function, put it in the procedure linkage table. We
12705 will fill in the contents of the procedure linkage table later,
12706 when we know the address of the .got section. */
12707 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
12709 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
12710 symbol binds locally. */
12711 if (h->plt.refcount <= 0
12712 || (h->type != STT_GNU_IFUNC
12713 && (SYMBOL_CALLS_LOCAL (info, h)
12714 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
12715 && h->root.type == bfd_link_hash_undefweak))))
12717 /* This case can occur if we saw a PLT32 reloc in an input
12718 file, but the symbol was never referred to by a dynamic
12719 object, or if all references were garbage collected. In
12720 such a case, we don't actually need to build a procedure
12721 linkage table, and we can just do a PC24 reloc instead. */
12722 h->plt.offset = (bfd_vma) -1;
12723 eh->plt.thumb_refcount = 0;
12724 eh->plt.maybe_thumb_refcount = 0;
12725 eh->plt.noncall_refcount = 0;
12733 /* It's possible that we incorrectly decided a .plt reloc was
12734 needed for an R_ARM_PC24 or similar reloc to a non-function sym
12735 in check_relocs. We can't decide accurately between function
12736 and non-function syms in check-relocs; Objects loaded later in
12737 the link may change h->type. So fix it now. */
12738 h->plt.offset = (bfd_vma) -1;
12739 eh->plt.thumb_refcount = 0;
12740 eh->plt.maybe_thumb_refcount = 0;
12741 eh->plt.noncall_refcount = 0;
12744 /* If this is a weak symbol, and there is a real definition, the
12745 processor independent code will have arranged for us to see the
12746 real definition first, and we can just use the same value. */
12747 if (h->u.weakdef != NULL)
12749 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
12750 || h->u.weakdef->root.type == bfd_link_hash_defweak);
12751 h->root.u.def.section = h->u.weakdef->root.u.def.section;
12752 h->root.u.def.value = h->u.weakdef->root.u.def.value;
12756 /* If there are no non-GOT references, we do not need a copy
12758 if (!h->non_got_ref)
12761 /* This is a reference to a symbol defined by a dynamic object which
12762 is not a function. */
12764 /* If we are creating a shared library, we must presume that the
12765 only references to the symbol are via the global offset table.
12766 For such cases we need not do anything here; the relocations will
12767 be handled correctly by relocate_section. Relocatable executables
12768 can reference data in shared objects directly, so we don't need to
12769 do anything here. */
12770 if (info->shared || globals->root.is_relocatable_executable)
12775 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
12776 h->root.root.string);
12780 /* We must allocate the symbol in our .dynbss section, which will
12781 become part of the .bss section of the executable. There will be
12782 an entry for this symbol in the .dynsym section. The dynamic
12783 object will contain position independent code, so all references
12784 from the dynamic object to this symbol will go through the global
12785 offset table. The dynamic linker will use the .dynsym entry to
12786 determine the address it must put in the global offset table, so
12787 both the dynamic object and the regular object will refer to the
12788 same memory location for the variable. */
12789 s = bfd_get_section_by_name (dynobj, ".dynbss");
12790 BFD_ASSERT (s != NULL);
12792 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
12793 copy the initial value out of the dynamic object and into the
12794 runtime process image. We need to remember the offset into the
12795 .rel(a).bss section we are going to use. */
12796 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
12800 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
12801 elf32_arm_allocate_dynrelocs (info, srel, 1);
12805 return _bfd_elf_adjust_dynamic_copy (h, s);
12808 /* Allocate space in .plt, .got and associated reloc sections for
12812 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry *h, void * inf)
12814 struct bfd_link_info *info;
12815 struct elf32_arm_link_hash_table *htab;
12816 struct elf32_arm_link_hash_entry *eh;
12817 struct elf_dyn_relocs *p;
12819 if (h->root.type == bfd_link_hash_indirect)
12822 eh = (struct elf32_arm_link_hash_entry *) h;
12824 info = (struct bfd_link_info *) inf;
12825 htab = elf32_arm_hash_table (info);
12829 if ((htab->root.dynamic_sections_created || h->type == STT_GNU_IFUNC)
12830 && h->plt.refcount > 0)
12832 /* Make sure this symbol is output as a dynamic symbol.
12833 Undefined weak syms won't yet be marked as dynamic. */
12834 if (h->dynindx == -1
12835 && !h->forced_local)
12837 if (! bfd_elf_link_record_dynamic_symbol (info, h))
12841 /* If the call in the PLT entry binds locally, the associated
12842 GOT entry should use an R_ARM_IRELATIVE relocation instead of
12843 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
12844 than the .plt section. */
12845 if (h->type == STT_GNU_IFUNC && SYMBOL_CALLS_LOCAL (info, h))
12848 if (eh->plt.noncall_refcount == 0
12849 && SYMBOL_REFERENCES_LOCAL (info, h))
12850 /* All non-call references can be resolved directly.
12851 This means that they can (and in some cases, must)
12852 resolve directly to the run-time target, rather than
12853 to the PLT. That in turns means that any .got entry
12854 would be equal to the .igot.plt entry, so there's
12855 no point having both. */
12856 h->got.refcount = 0;
12861 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
12863 elf32_arm_allocate_plt_entry (info, eh->is_iplt, &h->plt, &eh->plt);
12865 /* If this symbol is not defined in a regular file, and we are
12866 not generating a shared library, then set the symbol to this
12867 location in the .plt. This is required to make function
12868 pointers compare as equal between the normal executable and
12869 the shared library. */
12871 && !h->def_regular)
12873 h->root.u.def.section = htab->root.splt;
12874 h->root.u.def.value = h->plt.offset;
12876 /* Make sure the function is not marked as Thumb, in case
12877 it is the target of an ABS32 relocation, which will
12878 point to the PLT entry. */
12879 h->target_internal = ST_BRANCH_TO_ARM;
12882 htab->next_tls_desc_index++;
12884 /* VxWorks executables have a second set of relocations for
12885 each PLT entry. They go in a separate relocation section,
12886 which is processed by the kernel loader. */
12887 if (htab->vxworks_p && !info->shared)
12889 /* There is a relocation for the initial PLT entry:
12890 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
12891 if (h->plt.offset == htab->plt_header_size)
12892 elf32_arm_allocate_dynrelocs (info, htab->srelplt2, 1);
12894 /* There are two extra relocations for each subsequent
12895 PLT entry: an R_ARM_32 relocation for the GOT entry,
12896 and an R_ARM_32 relocation for the PLT entry. */
12897 elf32_arm_allocate_dynrelocs (info, htab->srelplt2, 2);
12902 h->plt.offset = (bfd_vma) -1;
12908 h->plt.offset = (bfd_vma) -1;
12912 eh = (struct elf32_arm_link_hash_entry *) h;
12913 eh->tlsdesc_got = (bfd_vma) -1;
12915 if (h->got.refcount > 0)
12919 int tls_type = elf32_arm_hash_entry (h)->tls_type;
12922 /* Make sure this symbol is output as a dynamic symbol.
12923 Undefined weak syms won't yet be marked as dynamic. */
12924 if (h->dynindx == -1
12925 && !h->forced_local)
12927 if (! bfd_elf_link_record_dynamic_symbol (info, h))
12931 if (!htab->symbian_p)
12933 s = htab->root.sgot;
12934 h->got.offset = s->size;
12936 if (tls_type == GOT_UNKNOWN)
12939 if (tls_type == GOT_NORMAL)
12940 /* Non-TLS symbols need one GOT slot. */
12944 if (tls_type & GOT_TLS_GDESC)
12946 /* R_ARM_TLS_DESC needs 2 GOT slots. */
12948 = (htab->root.sgotplt->size
12949 - elf32_arm_compute_jump_table_size (htab));
12950 htab->root.sgotplt->size += 8;
12951 h->got.offset = (bfd_vma) -2;
12952 /* plt.got_offset needs to know there's a TLS_DESC
12953 reloc in the middle of .got.plt. */
12954 htab->num_tls_desc++;
12957 if (tls_type & GOT_TLS_GD)
12959 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. If
12960 the symbol is both GD and GDESC, got.offset may
12961 have been overwritten. */
12962 h->got.offset = s->size;
12966 if (tls_type & GOT_TLS_IE)
12967 /* R_ARM_TLS_IE32 needs one GOT slot. */
12971 dyn = htab->root.dynamic_sections_created;
12974 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
12976 || !SYMBOL_REFERENCES_LOCAL (info, h)))
12979 if (tls_type != GOT_NORMAL
12980 && (info->shared || indx != 0)
12981 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
12982 || h->root.type != bfd_link_hash_undefweak))
12984 if (tls_type & GOT_TLS_IE)
12985 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
12987 if (tls_type & GOT_TLS_GD)
12988 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
12990 if (tls_type & GOT_TLS_GDESC)
12992 elf32_arm_allocate_dynrelocs (info, htab->root.srelplt, 1);
12993 /* GDESC needs a trampoline to jump to. */
12994 htab->tls_trampoline = -1;
12997 /* Only GD needs it. GDESC just emits one relocation per
12999 if ((tls_type & GOT_TLS_GD) && indx != 0)
13000 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
13002 else if (!SYMBOL_REFERENCES_LOCAL (info, h))
13004 if (htab->root.dynamic_sections_created)
13005 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
13006 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
13008 else if (h->type == STT_GNU_IFUNC
13009 && eh->plt.noncall_refcount == 0)
13010 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
13011 they all resolve dynamically instead. Reserve room for the
13012 GOT entry's R_ARM_IRELATIVE relocation. */
13013 elf32_arm_allocate_irelocs (info, htab->root.srelgot, 1);
13014 else if (info->shared)
13015 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
13016 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
13020 h->got.offset = (bfd_vma) -1;
13022 /* Allocate stubs for exported Thumb functions on v4t. */
13023 if (!htab->use_blx && h->dynindx != -1
13025 && h->target_internal == ST_BRANCH_TO_THUMB
13026 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
13028 struct elf_link_hash_entry * th;
13029 struct bfd_link_hash_entry * bh;
13030 struct elf_link_hash_entry * myh;
13034 /* Create a new symbol to regist the real location of the function. */
13035 s = h->root.u.def.section;
13036 sprintf (name, "__real_%s", h->root.root.string);
13037 _bfd_generic_link_add_one_symbol (info, s->owner,
13038 name, BSF_GLOBAL, s,
13039 h->root.u.def.value,
13040 NULL, TRUE, FALSE, &bh);
13042 myh = (struct elf_link_hash_entry *) bh;
13043 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
13044 myh->forced_local = 1;
13045 myh->target_internal = ST_BRANCH_TO_THUMB;
13046 eh->export_glue = myh;
13047 th = record_arm_to_thumb_glue (info, h);
13048 /* Point the symbol at the stub. */
13049 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
13050 h->target_internal = ST_BRANCH_TO_ARM;
13051 h->root.u.def.section = th->root.u.def.section;
13052 h->root.u.def.value = th->root.u.def.value & ~1;
13055 if (eh->dyn_relocs == NULL)
13058 /* In the shared -Bsymbolic case, discard space allocated for
13059 dynamic pc-relative relocs against symbols which turn out to be
13060 defined in regular objects. For the normal shared case, discard
13061 space for pc-relative relocs that have become local due to symbol
13062 visibility changes. */
13064 if (info->shared || htab->root.is_relocatable_executable)
13066 /* The only relocs that use pc_count are R_ARM_REL32 and
13067 R_ARM_REL32_NOI, which will appear on something like
13068 ".long foo - .". We want calls to protected symbols to resolve
13069 directly to the function rather than going via the plt. If people
13070 want function pointer comparisons to work as expected then they
13071 should avoid writing assembly like ".long foo - .". */
13072 if (SYMBOL_CALLS_LOCAL (info, h))
13074 struct elf_dyn_relocs **pp;
13076 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
13078 p->count -= p->pc_count;
13087 if (htab->vxworks_p)
13089 struct elf_dyn_relocs **pp;
13091 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
13093 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
13100 /* Also discard relocs on undefined weak syms with non-default
13102 if (eh->dyn_relocs != NULL
13103 && h->root.type == bfd_link_hash_undefweak)
13105 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
13106 eh->dyn_relocs = NULL;
13108 /* Make sure undefined weak symbols are output as a dynamic
13110 else if (h->dynindx == -1
13111 && !h->forced_local)
13113 if (! bfd_elf_link_record_dynamic_symbol (info, h))
13118 else if (htab->root.is_relocatable_executable && h->dynindx == -1
13119 && h->root.type == bfd_link_hash_new)
13121 /* Output absolute symbols so that we can create relocations
13122 against them. For normal symbols we output a relocation
13123 against the section that contains them. */
13124 if (! bfd_elf_link_record_dynamic_symbol (info, h))
13131 /* For the non-shared case, discard space for relocs against
13132 symbols which turn out to need copy relocs or are not
13135 if (!h->non_got_ref
13136 && ((h->def_dynamic
13137 && !h->def_regular)
13138 || (htab->root.dynamic_sections_created
13139 && (h->root.type == bfd_link_hash_undefweak
13140 || h->root.type == bfd_link_hash_undefined))))
13142 /* Make sure this symbol is output as a dynamic symbol.
13143 Undefined weak syms won't yet be marked as dynamic. */
13144 if (h->dynindx == -1
13145 && !h->forced_local)
13147 if (! bfd_elf_link_record_dynamic_symbol (info, h))
13151 /* If that succeeded, we know we'll be keeping all the
13153 if (h->dynindx != -1)
13157 eh->dyn_relocs = NULL;
13162 /* Finally, allocate space. */
13163 for (p = eh->dyn_relocs; p != NULL; p = p->next)
13165 asection *sreloc = elf_section_data (p->sec)->sreloc;
13166 if (h->type == STT_GNU_IFUNC
13167 && eh->plt.noncall_refcount == 0
13168 && SYMBOL_REFERENCES_LOCAL (info, h))
13169 elf32_arm_allocate_irelocs (info, sreloc, p->count);
13171 elf32_arm_allocate_dynrelocs (info, sreloc, p->count);
13177 /* Find any dynamic relocs that apply to read-only sections. */
13180 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
13182 struct elf32_arm_link_hash_entry * eh;
13183 struct elf_dyn_relocs * p;
13185 eh = (struct elf32_arm_link_hash_entry *) h;
13186 for (p = eh->dyn_relocs; p != NULL; p = p->next)
13188 asection *s = p->sec;
13190 if (s != NULL && (s->flags & SEC_READONLY) != 0)
13192 struct bfd_link_info *info = (struct bfd_link_info *) inf;
13194 info->flags |= DF_TEXTREL;
13196 /* Not an error, just cut short the traversal. */
13204 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
13207 struct elf32_arm_link_hash_table *globals;
13209 globals = elf32_arm_hash_table (info);
13210 if (globals == NULL)
13213 globals->byteswap_code = byteswap_code;
13216 /* Set the sizes of the dynamic sections. */
13219 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
13220 struct bfd_link_info * info)
13225 bfd_boolean relocs;
13227 struct elf32_arm_link_hash_table *htab;
13229 htab = elf32_arm_hash_table (info);
13233 dynobj = elf_hash_table (info)->dynobj;
13234 BFD_ASSERT (dynobj != NULL);
13235 check_use_blx (htab);
13237 if (elf_hash_table (info)->dynamic_sections_created)
13239 /* Set the contents of the .interp section to the interpreter. */
13240 if (info->executable)
13242 s = bfd_get_section_by_name (dynobj, ".interp");
13243 BFD_ASSERT (s != NULL);
13244 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
13245 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
13249 /* Set up .got offsets for local syms, and space for local dynamic
13251 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
13253 bfd_signed_vma *local_got;
13254 bfd_signed_vma *end_local_got;
13255 struct arm_local_iplt_info **local_iplt_ptr, *local_iplt;
13256 char *local_tls_type;
13257 bfd_vma *local_tlsdesc_gotent;
13258 bfd_size_type locsymcount;
13259 Elf_Internal_Shdr *symtab_hdr;
13261 bfd_boolean is_vxworks = htab->vxworks_p;
13262 unsigned int symndx;
13264 if (! is_arm_elf (ibfd))
13267 for (s = ibfd->sections; s != NULL; s = s->next)
13269 struct elf_dyn_relocs *p;
13271 for (p = (struct elf_dyn_relocs *)
13272 elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
13274 if (!bfd_is_abs_section (p->sec)
13275 && bfd_is_abs_section (p->sec->output_section))
13277 /* Input section has been discarded, either because
13278 it is a copy of a linkonce section or due to
13279 linker script /DISCARD/, so we'll be discarding
13282 else if (is_vxworks
13283 && strcmp (p->sec->output_section->name,
13286 /* Relocations in vxworks .tls_vars sections are
13287 handled specially by the loader. */
13289 else if (p->count != 0)
13291 srel = elf_section_data (p->sec)->sreloc;
13292 elf32_arm_allocate_dynrelocs (info, srel, p->count);
13293 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
13294 info->flags |= DF_TEXTREL;
13299 local_got = elf_local_got_refcounts (ibfd);
13303 symtab_hdr = & elf_symtab_hdr (ibfd);
13304 locsymcount = symtab_hdr->sh_info;
13305 end_local_got = local_got + locsymcount;
13306 local_iplt_ptr = elf32_arm_local_iplt (ibfd);
13307 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
13308 local_tlsdesc_gotent = elf32_arm_local_tlsdesc_gotent (ibfd);
13310 s = htab->root.sgot;
13311 srel = htab->root.srelgot;
13312 for (; local_got < end_local_got;
13313 ++local_got, ++local_iplt_ptr, ++local_tls_type,
13314 ++local_tlsdesc_gotent, ++symndx)
13316 *local_tlsdesc_gotent = (bfd_vma) -1;
13317 local_iplt = *local_iplt_ptr;
13318 if (local_iplt != NULL)
13320 struct elf_dyn_relocs *p;
13322 if (local_iplt->root.refcount > 0)
13324 elf32_arm_allocate_plt_entry (info, TRUE,
13327 if (local_iplt->arm.noncall_refcount == 0)
13328 /* All references to the PLT are calls, so all
13329 non-call references can resolve directly to the
13330 run-time target. This means that the .got entry
13331 would be the same as the .igot.plt entry, so there's
13332 no point creating both. */
13337 BFD_ASSERT (local_iplt->arm.noncall_refcount == 0);
13338 local_iplt->root.offset = (bfd_vma) -1;
13341 for (p = local_iplt->dyn_relocs; p != NULL; p = p->next)
13345 psrel = elf_section_data (p->sec)->sreloc;
13346 if (local_iplt->arm.noncall_refcount == 0)
13347 elf32_arm_allocate_irelocs (info, psrel, p->count);
13349 elf32_arm_allocate_dynrelocs (info, psrel, p->count);
13352 if (*local_got > 0)
13354 Elf_Internal_Sym *isym;
13356 *local_got = s->size;
13357 if (*local_tls_type & GOT_TLS_GD)
13358 /* TLS_GD relocs need an 8-byte structure in the GOT. */
13360 if (*local_tls_type & GOT_TLS_GDESC)
13362 *local_tlsdesc_gotent = htab->root.sgotplt->size
13363 - elf32_arm_compute_jump_table_size (htab);
13364 htab->root.sgotplt->size += 8;
13365 *local_got = (bfd_vma) -2;
13366 /* plt.got_offset needs to know there's a TLS_DESC
13367 reloc in the middle of .got.plt. */
13368 htab->num_tls_desc++;
13370 if (*local_tls_type & GOT_TLS_IE)
13373 if (*local_tls_type & GOT_NORMAL)
13375 /* If the symbol is both GD and GDESC, *local_got
13376 may have been overwritten. */
13377 *local_got = s->size;
13381 isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, symndx);
13385 /* If all references to an STT_GNU_IFUNC PLT are calls,
13386 then all non-call references, including this GOT entry,
13387 resolve directly to the run-time target. */
13388 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
13389 && (local_iplt == NULL
13390 || local_iplt->arm.noncall_refcount == 0))
13391 elf32_arm_allocate_irelocs (info, srel, 1);
13392 else if ((info->shared && !(*local_tls_type & GOT_TLS_GDESC))
13393 || *local_tls_type & GOT_TLS_GD)
13394 elf32_arm_allocate_dynrelocs (info, srel, 1);
13396 if (info->shared && *local_tls_type & GOT_TLS_GDESC)
13398 elf32_arm_allocate_dynrelocs (info, htab->root.srelplt, 1);
13399 htab->tls_trampoline = -1;
13403 *local_got = (bfd_vma) -1;
13407 if (htab->tls_ldm_got.refcount > 0)
13409 /* Allocate two GOT entries and one dynamic relocation (if necessary)
13410 for R_ARM_TLS_LDM32 relocations. */
13411 htab->tls_ldm_got.offset = htab->root.sgot->size;
13412 htab->root.sgot->size += 8;
13414 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
13417 htab->tls_ldm_got.offset = -1;
13419 /* Allocate global sym .plt and .got entries, and space for global
13420 sym dynamic relocs. */
13421 elf_link_hash_traverse (& htab->root, allocate_dynrelocs_for_symbol, info);
13423 /* Here we rummage through the found bfds to collect glue information. */
13424 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
13426 if (! is_arm_elf (ibfd))
13429 /* Initialise mapping tables for code/data. */
13430 bfd_elf32_arm_init_maps (ibfd);
13432 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
13433 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
13434 /* xgettext:c-format */
13435 _bfd_error_handler (_("Errors encountered processing file %s"),
13439 /* Allocate space for the glue sections now that we've sized them. */
13440 bfd_elf32_arm_allocate_interworking_sections (info);
13442 /* For every jump slot reserved in the sgotplt, reloc_count is
13443 incremented. However, when we reserve space for TLS descriptors,
13444 it's not incremented, so in order to compute the space reserved
13445 for them, it suffices to multiply the reloc count by the jump
13447 if (htab->root.srelplt)
13448 htab->sgotplt_jump_table_size = elf32_arm_compute_jump_table_size(htab);
13450 if (htab->tls_trampoline)
13452 if (htab->root.splt->size == 0)
13453 htab->root.splt->size += htab->plt_header_size;
13455 htab->tls_trampoline = htab->root.splt->size;
13456 htab->root.splt->size += htab->plt_entry_size;
13458 /* If we're not using lazy TLS relocations, don't generate the
13459 PLT and GOT entries they require. */
13460 if (!(info->flags & DF_BIND_NOW))
13462 htab->dt_tlsdesc_got = htab->root.sgot->size;
13463 htab->root.sgot->size += 4;
13465 htab->dt_tlsdesc_plt = htab->root.splt->size;
13466 htab->root.splt->size += 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline);
13470 /* The check_relocs and adjust_dynamic_symbol entry points have
13471 determined the sizes of the various dynamic sections. Allocate
13472 memory for them. */
13475 for (s = dynobj->sections; s != NULL; s = s->next)
13479 if ((s->flags & SEC_LINKER_CREATED) == 0)
13482 /* It's OK to base decisions on the section name, because none
13483 of the dynobj section names depend upon the input files. */
13484 name = bfd_get_section_name (dynobj, s);
13486 if (s == htab->root.splt)
13488 /* Remember whether there is a PLT. */
13489 plt = s->size != 0;
13491 else if (CONST_STRNEQ (name, ".rel"))
13495 /* Remember whether there are any reloc sections other
13496 than .rel(a).plt and .rela.plt.unloaded. */
13497 if (s != htab->root.srelplt && s != htab->srelplt2)
13500 /* We use the reloc_count field as a counter if we need
13501 to copy relocs into the output file. */
13502 s->reloc_count = 0;
13505 else if (s != htab->root.sgot
13506 && s != htab->root.sgotplt
13507 && s != htab->root.iplt
13508 && s != htab->root.igotplt
13509 && s != htab->sdynbss)
13511 /* It's not one of our sections, so don't allocate space. */
13517 /* If we don't need this section, strip it from the
13518 output file. This is mostly to handle .rel(a).bss and
13519 .rel(a).plt. We must create both sections in
13520 create_dynamic_sections, because they must be created
13521 before the linker maps input sections to output
13522 sections. The linker does that before
13523 adjust_dynamic_symbol is called, and it is that
13524 function which decides whether anything needs to go
13525 into these sections. */
13526 s->flags |= SEC_EXCLUDE;
13530 if ((s->flags & SEC_HAS_CONTENTS) == 0)
13533 /* Allocate memory for the section contents. */
13534 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
13535 if (s->contents == NULL)
13539 if (elf_hash_table (info)->dynamic_sections_created)
13541 /* Add some entries to the .dynamic section. We fill in the
13542 values later, in elf32_arm_finish_dynamic_sections, but we
13543 must add the entries now so that we get the correct size for
13544 the .dynamic section. The DT_DEBUG entry is filled in by the
13545 dynamic linker and used by the debugger. */
13546 #define add_dynamic_entry(TAG, VAL) \
13547 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
13549 if (info->executable)
13551 if (!add_dynamic_entry (DT_DEBUG, 0))
13557 if ( !add_dynamic_entry (DT_PLTGOT, 0)
13558 || !add_dynamic_entry (DT_PLTRELSZ, 0)
13559 || !add_dynamic_entry (DT_PLTREL,
13560 htab->use_rel ? DT_REL : DT_RELA)
13561 || !add_dynamic_entry (DT_JMPREL, 0))
13564 if (htab->dt_tlsdesc_plt &&
13565 (!add_dynamic_entry (DT_TLSDESC_PLT,0)
13566 || !add_dynamic_entry (DT_TLSDESC_GOT,0)))
13574 if (!add_dynamic_entry (DT_REL, 0)
13575 || !add_dynamic_entry (DT_RELSZ, 0)
13576 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
13581 if (!add_dynamic_entry (DT_RELA, 0)
13582 || !add_dynamic_entry (DT_RELASZ, 0)
13583 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
13588 /* If any dynamic relocs apply to a read-only section,
13589 then we need a DT_TEXTREL entry. */
13590 if ((info->flags & DF_TEXTREL) == 0)
13591 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
13594 if ((info->flags & DF_TEXTREL) != 0)
13596 if (!add_dynamic_entry (DT_TEXTREL, 0))
13599 if (htab->vxworks_p
13600 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
13603 #undef add_dynamic_entry
13608 /* Size sections even though they're not dynamic. We use it to setup
13609 _TLS_MODULE_BASE_, if needed. */
13612 elf32_arm_always_size_sections (bfd *output_bfd,
13613 struct bfd_link_info *info)
13617 if (info->relocatable)
13620 tls_sec = elf_hash_table (info)->tls_sec;
13624 struct elf_link_hash_entry *tlsbase;
13626 tlsbase = elf_link_hash_lookup
13627 (elf_hash_table (info), "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
13631 struct bfd_link_hash_entry *bh = NULL;
13632 const struct elf_backend_data *bed
13633 = get_elf_backend_data (output_bfd);
13635 if (!(_bfd_generic_link_add_one_symbol
13636 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
13637 tls_sec, 0, NULL, FALSE,
13638 bed->collect, &bh)))
13641 tlsbase->type = STT_TLS;
13642 tlsbase = (struct elf_link_hash_entry *)bh;
13643 tlsbase->def_regular = 1;
13644 tlsbase->other = STV_HIDDEN;
13645 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
13651 /* Finish up dynamic symbol handling. We set the contents of various
13652 dynamic sections here. */
13655 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
13656 struct bfd_link_info * info,
13657 struct elf_link_hash_entry * h,
13658 Elf_Internal_Sym * sym)
13660 struct elf32_arm_link_hash_table *htab;
13661 struct elf32_arm_link_hash_entry *eh;
13663 htab = elf32_arm_hash_table (info);
13667 eh = (struct elf32_arm_link_hash_entry *) h;
13669 if (h->plt.offset != (bfd_vma) -1)
13673 BFD_ASSERT (h->dynindx != -1);
13674 elf32_arm_populate_plt_entry (output_bfd, info, &h->plt, &eh->plt,
13678 if (!h->def_regular)
13680 /* Mark the symbol as undefined, rather than as defined in
13681 the .plt section. Leave the value alone. */
13682 sym->st_shndx = SHN_UNDEF;
13683 /* If the symbol is weak, we do need to clear the value.
13684 Otherwise, the PLT entry would provide a definition for
13685 the symbol even if the symbol wasn't defined anywhere,
13686 and so the symbol would never be NULL. */
13687 if (!h->ref_regular_nonweak)
13690 else if (eh->is_iplt && eh->plt.noncall_refcount != 0)
13692 /* At least one non-call relocation references this .iplt entry,
13693 so the .iplt entry is the function's canonical address. */
13694 sym->st_info = ELF_ST_INFO (ELF_ST_BIND (sym->st_info), STT_FUNC);
13695 sym->st_target_internal = ST_BRANCH_TO_ARM;
13696 sym->st_shndx = (_bfd_elf_section_from_bfd_section
13697 (output_bfd, htab->root.iplt->output_section));
13698 sym->st_value = (h->plt.offset
13699 + htab->root.iplt->output_section->vma
13700 + htab->root.iplt->output_offset);
13707 Elf_Internal_Rela rel;
13709 /* This symbol needs a copy reloc. Set it up. */
13710 BFD_ASSERT (h->dynindx != -1
13711 && (h->root.type == bfd_link_hash_defined
13712 || h->root.type == bfd_link_hash_defweak));
13715 BFD_ASSERT (s != NULL);
13718 rel.r_offset = (h->root.u.def.value
13719 + h->root.u.def.section->output_section->vma
13720 + h->root.u.def.section->output_offset);
13721 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
13722 elf32_arm_add_dynreloc (output_bfd, info, s, &rel);
13725 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
13726 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
13727 to the ".got" section. */
13728 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
13729 || (!htab->vxworks_p && h == htab->root.hgot))
13730 sym->st_shndx = SHN_ABS;
13736 arm_put_trampoline (struct elf32_arm_link_hash_table *htab, bfd *output_bfd,
13738 const unsigned long *template, unsigned count)
13742 for (ix = 0; ix != count; ix++)
13744 unsigned long insn = template[ix];
13746 /* Emit mov pc,rx if bx is not permitted. */
13747 if (htab->fix_v4bx == 1 && (insn & 0x0ffffff0) == 0x012fff10)
13748 insn = (insn & 0xf000000f) | 0x01a0f000;
13749 put_arm_insn (htab, output_bfd, insn, (char *)contents + ix*4);
13753 /* Finish up the dynamic sections. */
13756 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
13761 struct elf32_arm_link_hash_table *htab;
13763 htab = elf32_arm_hash_table (info);
13767 dynobj = elf_hash_table (info)->dynobj;
13769 sgot = htab->root.sgotplt;
13770 /* A broken linker script might have discarded the dynamic sections.
13771 Catch this here so that we do not seg-fault later on. */
13772 if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
13774 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
13776 if (elf_hash_table (info)->dynamic_sections_created)
13779 Elf32_External_Dyn *dyncon, *dynconend;
13781 splt = htab->root.splt;
13782 BFD_ASSERT (splt != NULL && sdyn != NULL);
13783 BFD_ASSERT (htab->symbian_p || sgot != NULL);
13785 dyncon = (Elf32_External_Dyn *) sdyn->contents;
13786 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
13788 for (; dyncon < dynconend; dyncon++)
13790 Elf_Internal_Dyn dyn;
13794 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
13801 if (htab->vxworks_p
13802 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
13803 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13808 goto get_vma_if_bpabi;
13811 goto get_vma_if_bpabi;
13814 goto get_vma_if_bpabi;
13816 name = ".gnu.version";
13817 goto get_vma_if_bpabi;
13819 name = ".gnu.version_d";
13820 goto get_vma_if_bpabi;
13822 name = ".gnu.version_r";
13823 goto get_vma_if_bpabi;
13829 name = RELOC_SECTION (htab, ".plt");
13831 s = bfd_get_section_by_name (output_bfd, name);
13832 BFD_ASSERT (s != NULL);
13833 if (!htab->symbian_p)
13834 dyn.d_un.d_ptr = s->vma;
13836 /* In the BPABI, tags in the PT_DYNAMIC section point
13837 at the file offset, not the memory address, for the
13838 convenience of the post linker. */
13839 dyn.d_un.d_ptr = s->filepos;
13840 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13844 if (htab->symbian_p)
13849 s = htab->root.srelplt;
13850 BFD_ASSERT (s != NULL);
13851 dyn.d_un.d_val = s->size;
13852 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13857 if (!htab->symbian_p)
13859 /* My reading of the SVR4 ABI indicates that the
13860 procedure linkage table relocs (DT_JMPREL) should be
13861 included in the overall relocs (DT_REL). This is
13862 what Solaris does. However, UnixWare can not handle
13863 that case. Therefore, we override the DT_RELSZ entry
13864 here to make it not include the JMPREL relocs. Since
13865 the linker script arranges for .rel(a).plt to follow all
13866 other relocation sections, we don't have to worry
13867 about changing the DT_REL entry. */
13868 s = htab->root.srelplt;
13870 dyn.d_un.d_val -= s->size;
13871 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13874 /* Fall through. */
13878 /* In the BPABI, the DT_REL tag must point at the file
13879 offset, not the VMA, of the first relocation
13880 section. So, we use code similar to that in
13881 elflink.c, but do not check for SHF_ALLOC on the
13882 relcoation section, since relocations sections are
13883 never allocated under the BPABI. The comments above
13884 about Unixware notwithstanding, we include all of the
13885 relocations here. */
13886 if (htab->symbian_p)
13889 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
13890 ? SHT_REL : SHT_RELA);
13891 dyn.d_un.d_val = 0;
13892 for (i = 1; i < elf_numsections (output_bfd); i++)
13894 Elf_Internal_Shdr *hdr
13895 = elf_elfsections (output_bfd)[i];
13896 if (hdr->sh_type == type)
13898 if (dyn.d_tag == DT_RELSZ
13899 || dyn.d_tag == DT_RELASZ)
13900 dyn.d_un.d_val += hdr->sh_size;
13901 else if ((ufile_ptr) hdr->sh_offset
13902 <= dyn.d_un.d_val - 1)
13903 dyn.d_un.d_val = hdr->sh_offset;
13906 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13910 case DT_TLSDESC_PLT:
13911 s = htab->root.splt;
13912 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
13913 + htab->dt_tlsdesc_plt);
13914 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13917 case DT_TLSDESC_GOT:
13918 s = htab->root.sgot;
13919 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
13920 + htab->dt_tlsdesc_got);
13921 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13924 /* Set the bottom bit of DT_INIT/FINI if the
13925 corresponding function is Thumb. */
13927 name = info->init_function;
13930 name = info->fini_function;
13932 /* If it wasn't set by elf_bfd_final_link
13933 then there is nothing to adjust. */
13934 if (dyn.d_un.d_val != 0)
13936 struct elf_link_hash_entry * eh;
13938 eh = elf_link_hash_lookup (elf_hash_table (info), name,
13939 FALSE, FALSE, TRUE);
13940 if (eh != NULL && eh->target_internal == ST_BRANCH_TO_THUMB)
13942 dyn.d_un.d_val |= 1;
13943 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
13950 /* Fill in the first entry in the procedure linkage table. */
13951 if (splt->size > 0 && htab->plt_header_size)
13953 const bfd_vma *plt0_entry;
13954 bfd_vma got_address, plt_address, got_displacement;
13956 /* Calculate the addresses of the GOT and PLT. */
13957 got_address = sgot->output_section->vma + sgot->output_offset;
13958 plt_address = splt->output_section->vma + splt->output_offset;
13960 if (htab->vxworks_p)
13962 /* The VxWorks GOT is relocated by the dynamic linker.
13963 Therefore, we must emit relocations rather than simply
13964 computing the values now. */
13965 Elf_Internal_Rela rel;
13967 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
13968 put_arm_insn (htab, output_bfd, plt0_entry[0],
13969 splt->contents + 0);
13970 put_arm_insn (htab, output_bfd, plt0_entry[1],
13971 splt->contents + 4);
13972 put_arm_insn (htab, output_bfd, plt0_entry[2],
13973 splt->contents + 8);
13974 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
13976 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
13977 rel.r_offset = plt_address + 12;
13978 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
13980 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
13981 htab->srelplt2->contents);
13985 got_displacement = got_address - (plt_address + 16);
13987 plt0_entry = elf32_arm_plt0_entry;
13988 put_arm_insn (htab, output_bfd, plt0_entry[0],
13989 splt->contents + 0);
13990 put_arm_insn (htab, output_bfd, plt0_entry[1],
13991 splt->contents + 4);
13992 put_arm_insn (htab, output_bfd, plt0_entry[2],
13993 splt->contents + 8);
13994 put_arm_insn (htab, output_bfd, plt0_entry[3],
13995 splt->contents + 12);
13997 #ifdef FOUR_WORD_PLT
13998 /* The displacement value goes in the otherwise-unused
13999 last word of the second entry. */
14000 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
14002 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
14007 /* UnixWare sets the entsize of .plt to 4, although that doesn't
14008 really seem like the right value. */
14009 if (splt->output_section->owner == output_bfd)
14010 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
14012 if (htab->dt_tlsdesc_plt)
14014 bfd_vma got_address
14015 = sgot->output_section->vma + sgot->output_offset;
14016 bfd_vma gotplt_address = (htab->root.sgot->output_section->vma
14017 + htab->root.sgot->output_offset);
14018 bfd_vma plt_address
14019 = splt->output_section->vma + splt->output_offset;
14021 arm_put_trampoline (htab, output_bfd,
14022 splt->contents + htab->dt_tlsdesc_plt,
14023 dl_tlsdesc_lazy_trampoline, 6);
14025 bfd_put_32 (output_bfd,
14026 gotplt_address + htab->dt_tlsdesc_got
14027 - (plt_address + htab->dt_tlsdesc_plt)
14028 - dl_tlsdesc_lazy_trampoline[6],
14029 splt->contents + htab->dt_tlsdesc_plt + 24);
14030 bfd_put_32 (output_bfd,
14031 got_address - (plt_address + htab->dt_tlsdesc_plt)
14032 - dl_tlsdesc_lazy_trampoline[7],
14033 splt->contents + htab->dt_tlsdesc_plt + 24 + 4);
14036 if (htab->tls_trampoline)
14038 arm_put_trampoline (htab, output_bfd,
14039 splt->contents + htab->tls_trampoline,
14040 tls_trampoline, 3);
14041 #ifdef FOUR_WORD_PLT
14042 bfd_put_32 (output_bfd, 0x00000000,
14043 splt->contents + htab->tls_trampoline + 12);
14047 if (htab->vxworks_p && !info->shared && htab->root.splt->size > 0)
14049 /* Correct the .rel(a).plt.unloaded relocations. They will have
14050 incorrect symbol indexes. */
14054 num_plts = ((htab->root.splt->size - htab->plt_header_size)
14055 / htab->plt_entry_size);
14056 p = htab->srelplt2->contents + RELOC_SIZE (htab);
14058 for (; num_plts; num_plts--)
14060 Elf_Internal_Rela rel;
14062 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
14063 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
14064 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
14065 p += RELOC_SIZE (htab);
14067 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
14068 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
14069 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
14070 p += RELOC_SIZE (htab);
14075 /* Fill in the first three entries in the global offset table. */
14078 if (sgot->size > 0)
14081 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
14083 bfd_put_32 (output_bfd,
14084 sdyn->output_section->vma + sdyn->output_offset,
14086 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
14087 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
14090 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
14097 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
14099 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
14100 struct elf32_arm_link_hash_table *globals;
14102 i_ehdrp = elf_elfheader (abfd);
14104 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
14105 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
14107 i_ehdrp->e_ident[EI_OSABI] = 0;
14108 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
14112 globals = elf32_arm_hash_table (link_info);
14113 if (globals != NULL && globals->byteswap_code)
14114 i_ehdrp->e_flags |= EF_ARM_BE8;
14118 static enum elf_reloc_type_class
14119 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
14121 switch ((int) ELF32_R_TYPE (rela->r_info))
14123 case R_ARM_RELATIVE:
14124 return reloc_class_relative;
14125 case R_ARM_JUMP_SLOT:
14126 return reloc_class_plt;
14128 return reloc_class_copy;
14130 return reloc_class_normal;
14135 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
14137 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
14140 /* Return TRUE if this is an unwinding table entry. */
14143 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
14145 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
14146 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
14150 /* Set the type and flags for an ARM section. We do this by
14151 the section name, which is a hack, but ought to work. */
14154 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
14158 name = bfd_get_section_name (abfd, sec);
14160 if (is_arm_elf_unwind_section_name (abfd, name))
14162 hdr->sh_type = SHT_ARM_EXIDX;
14163 hdr->sh_flags |= SHF_LINK_ORDER;
14168 /* Handle an ARM specific section when reading an object file. This is
14169 called when bfd_section_from_shdr finds a section with an unknown
14173 elf32_arm_section_from_shdr (bfd *abfd,
14174 Elf_Internal_Shdr * hdr,
14178 /* There ought to be a place to keep ELF backend specific flags, but
14179 at the moment there isn't one. We just keep track of the
14180 sections by their name, instead. Fortunately, the ABI gives
14181 names for all the ARM specific sections, so we will probably get
14183 switch (hdr->sh_type)
14185 case SHT_ARM_EXIDX:
14186 case SHT_ARM_PREEMPTMAP:
14187 case SHT_ARM_ATTRIBUTES:
14194 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
14200 static _arm_elf_section_data *
14201 get_arm_elf_section_data (asection * sec)
14203 if (sec && sec->owner && is_arm_elf (sec->owner))
14204 return elf32_arm_section_data (sec);
14212 struct bfd_link_info *info;
14215 int (*func) (void *, const char *, Elf_Internal_Sym *,
14216 asection *, struct elf_link_hash_entry *);
14217 } output_arch_syminfo;
14219 enum map_symbol_type
14227 /* Output a single mapping symbol. */
14230 elf32_arm_output_map_sym (output_arch_syminfo *osi,
14231 enum map_symbol_type type,
14234 static const char *names[3] = {"$a", "$t", "$d"};
14235 Elf_Internal_Sym sym;
14237 sym.st_value = osi->sec->output_section->vma
14238 + osi->sec->output_offset
14242 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
14243 sym.st_shndx = osi->sec_shndx;
14244 sym.st_target_internal = 0;
14245 elf32_arm_section_map_add (osi->sec, names[type][1], offset);
14246 return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
14249 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
14250 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
14253 elf32_arm_output_plt_map_1 (output_arch_syminfo *osi,
14254 bfd_boolean is_iplt_entry_p,
14255 union gotplt_union *root_plt,
14256 struct arm_plt_info *arm_plt)
14258 struct elf32_arm_link_hash_table *htab;
14259 bfd_vma addr, plt_header_size;
14261 if (root_plt->offset == (bfd_vma) -1)
14264 htab = elf32_arm_hash_table (osi->info);
14268 if (is_iplt_entry_p)
14270 osi->sec = htab->root.iplt;
14271 plt_header_size = 0;
14275 osi->sec = htab->root.splt;
14276 plt_header_size = htab->plt_header_size;
14278 osi->sec_shndx = (_bfd_elf_section_from_bfd_section
14279 (osi->info->output_bfd, osi->sec->output_section));
14281 addr = root_plt->offset & -2;
14282 if (htab->symbian_p)
14284 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
14286 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
14289 else if (htab->vxworks_p)
14291 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
14293 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
14295 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
14297 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
14302 bfd_boolean thumb_stub_p;
14304 thumb_stub_p = elf32_arm_plt_needs_thumb_stub_p (osi->info, arm_plt);
14307 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
14310 #ifdef FOUR_WORD_PLT
14311 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
14313 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
14316 /* A three-word PLT with no Thumb thunk contains only Arm code,
14317 so only need to output a mapping symbol for the first PLT entry and
14318 entries with thumb thunks. */
14319 if (thumb_stub_p || addr == plt_header_size)
14321 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
14330 /* Output mapping symbols for PLT entries associated with H. */
14333 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
14335 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
14336 struct elf32_arm_link_hash_entry *eh;
14338 if (h->root.type == bfd_link_hash_indirect)
14341 if (h->root.type == bfd_link_hash_warning)
14342 /* When warning symbols are created, they **replace** the "real"
14343 entry in the hash table, thus we never get to see the real
14344 symbol in a hash traversal. So look at it now. */
14345 h = (struct elf_link_hash_entry *) h->root.u.i.link;
14347 eh = (struct elf32_arm_link_hash_entry *) h;
14348 return elf32_arm_output_plt_map_1 (osi, SYMBOL_CALLS_LOCAL (osi->info, h),
14349 &h->plt, &eh->plt);
14352 /* Output a single local symbol for a generated stub. */
14355 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
14356 bfd_vma offset, bfd_vma size)
14358 Elf_Internal_Sym sym;
14360 sym.st_value = osi->sec->output_section->vma
14361 + osi->sec->output_offset
14363 sym.st_size = size;
14365 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
14366 sym.st_shndx = osi->sec_shndx;
14367 sym.st_target_internal = 0;
14368 return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
14372 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
14375 struct elf32_arm_stub_hash_entry *stub_entry;
14376 asection *stub_sec;
14379 output_arch_syminfo *osi;
14380 const insn_sequence *template_sequence;
14381 enum stub_insn_type prev_type;
14384 enum map_symbol_type sym_type;
14386 /* Massage our args to the form they really have. */
14387 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
14388 osi = (output_arch_syminfo *) in_arg;
14390 stub_sec = stub_entry->stub_sec;
14392 /* Ensure this stub is attached to the current section being
14394 if (stub_sec != osi->sec)
14397 addr = (bfd_vma) stub_entry->stub_offset;
14398 stub_name = stub_entry->output_name;
14400 template_sequence = stub_entry->stub_template;
14401 switch (template_sequence[0].type)
14404 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
14409 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
14410 stub_entry->stub_size))
14418 prev_type = DATA_TYPE;
14420 for (i = 0; i < stub_entry->stub_template_size; i++)
14422 switch (template_sequence[i].type)
14425 sym_type = ARM_MAP_ARM;
14430 sym_type = ARM_MAP_THUMB;
14434 sym_type = ARM_MAP_DATA;
14442 if (template_sequence[i].type != prev_type)
14444 prev_type = template_sequence[i].type;
14445 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
14449 switch (template_sequence[i].type)
14473 /* Output mapping symbols for linker generated sections,
14474 and for those data-only sections that do not have a
14478 elf32_arm_output_arch_local_syms (bfd *output_bfd,
14479 struct bfd_link_info *info,
14481 int (*func) (void *, const char *,
14482 Elf_Internal_Sym *,
14484 struct elf_link_hash_entry *))
14486 output_arch_syminfo osi;
14487 struct elf32_arm_link_hash_table *htab;
14489 bfd_size_type size;
14492 htab = elf32_arm_hash_table (info);
14496 check_use_blx (htab);
14502 /* Add a $d mapping symbol to data-only sections that
14503 don't have any mapping symbol. This may result in (harmless) redundant
14504 mapping symbols. */
14505 for (input_bfd = info->input_bfds;
14507 input_bfd = input_bfd->link_next)
14509 if ((input_bfd->flags & (BFD_LINKER_CREATED | HAS_SYMS)) == HAS_SYMS)
14510 for (osi.sec = input_bfd->sections;
14512 osi.sec = osi.sec->next)
14514 if (osi.sec->output_section != NULL
14515 && ((osi.sec->output_section->flags & (SEC_ALLOC | SEC_CODE))
14517 && (osi.sec->flags & (SEC_HAS_CONTENTS | SEC_LINKER_CREATED))
14518 == SEC_HAS_CONTENTS
14519 && get_arm_elf_section_data (osi.sec) != NULL
14520 && get_arm_elf_section_data (osi.sec)->mapcount == 0
14521 && osi.sec->size > 0
14522 && (osi.sec->flags & SEC_EXCLUDE) == 0)
14524 osi.sec_shndx = _bfd_elf_section_from_bfd_section
14525 (output_bfd, osi.sec->output_section);
14526 if (osi.sec_shndx != (int)SHN_BAD)
14527 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 0);
14532 /* ARM->Thumb glue. */
14533 if (htab->arm_glue_size > 0)
14535 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
14536 ARM2THUMB_GLUE_SECTION_NAME);
14538 osi.sec_shndx = _bfd_elf_section_from_bfd_section
14539 (output_bfd, osi.sec->output_section);
14540 if (info->shared || htab->root.is_relocatable_executable
14541 || htab->pic_veneer)
14542 size = ARM2THUMB_PIC_GLUE_SIZE;
14543 else if (htab->use_blx)
14544 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
14546 size = ARM2THUMB_STATIC_GLUE_SIZE;
14548 for (offset = 0; offset < htab->arm_glue_size; offset += size)
14550 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
14551 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
14555 /* Thumb->ARM glue. */
14556 if (htab->thumb_glue_size > 0)
14558 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
14559 THUMB2ARM_GLUE_SECTION_NAME);
14561 osi.sec_shndx = _bfd_elf_section_from_bfd_section
14562 (output_bfd, osi.sec->output_section);
14563 size = THUMB2ARM_GLUE_SIZE;
14565 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
14567 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
14568 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
14572 /* ARMv4 BX veneers. */
14573 if (htab->bx_glue_size > 0)
14575 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
14576 ARM_BX_GLUE_SECTION_NAME);
14578 osi.sec_shndx = _bfd_elf_section_from_bfd_section
14579 (output_bfd, osi.sec->output_section);
14581 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
14584 /* Long calls stubs. */
14585 if (htab->stub_bfd && htab->stub_bfd->sections)
14587 asection* stub_sec;
14589 for (stub_sec = htab->stub_bfd->sections;
14591 stub_sec = stub_sec->next)
14593 /* Ignore non-stub sections. */
14594 if (!strstr (stub_sec->name, STUB_SUFFIX))
14597 osi.sec = stub_sec;
14599 osi.sec_shndx = _bfd_elf_section_from_bfd_section
14600 (output_bfd, osi.sec->output_section);
14602 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
14606 /* Finally, output mapping symbols for the PLT. */
14607 if (htab->root.splt && htab->root.splt->size > 0)
14609 osi.sec = htab->root.splt;
14610 osi.sec_shndx = (_bfd_elf_section_from_bfd_section
14611 (output_bfd, osi.sec->output_section));
14613 /* Output mapping symbols for the plt header. SymbianOS does not have a
14615 if (htab->vxworks_p)
14617 /* VxWorks shared libraries have no PLT header. */
14620 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
14622 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
14626 else if (!htab->symbian_p)
14628 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
14630 #ifndef FOUR_WORD_PLT
14631 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
14636 if ((htab->root.splt && htab->root.splt->size > 0)
14637 || (htab->root.iplt && htab->root.iplt->size > 0))
14639 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, &osi);
14640 for (input_bfd = info->input_bfds;
14642 input_bfd = input_bfd->link_next)
14644 struct arm_local_iplt_info **local_iplt;
14645 unsigned int i, num_syms;
14647 local_iplt = elf32_arm_local_iplt (input_bfd);
14648 if (local_iplt != NULL)
14650 num_syms = elf_symtab_hdr (input_bfd).sh_info;
14651 for (i = 0; i < num_syms; i++)
14652 if (local_iplt[i] != NULL
14653 && !elf32_arm_output_plt_map_1 (&osi, TRUE,
14654 &local_iplt[i]->root,
14655 &local_iplt[i]->arm))
14660 if (htab->dt_tlsdesc_plt != 0)
14662 /* Mapping symbols for the lazy tls trampoline. */
14663 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, htab->dt_tlsdesc_plt))
14666 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA,
14667 htab->dt_tlsdesc_plt + 24))
14670 if (htab->tls_trampoline != 0)
14672 /* Mapping symbols for the tls trampoline. */
14673 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, htab->tls_trampoline))
14675 #ifdef FOUR_WORD_PLT
14676 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA,
14677 htab->tls_trampoline + 12))
14685 /* Allocate target specific section data. */
14688 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
14690 if (!sec->used_by_bfd)
14692 _arm_elf_section_data *sdata;
14693 bfd_size_type amt = sizeof (*sdata);
14695 sdata = (_arm_elf_section_data *) bfd_zalloc (abfd, amt);
14698 sec->used_by_bfd = sdata;
14701 return _bfd_elf_new_section_hook (abfd, sec);
14705 /* Used to order a list of mapping symbols by address. */
14708 elf32_arm_compare_mapping (const void * a, const void * b)
14710 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
14711 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
14713 if (amap->vma > bmap->vma)
14715 else if (amap->vma < bmap->vma)
14717 else if (amap->type > bmap->type)
14718 /* Ensure results do not depend on the host qsort for objects with
14719 multiple mapping symbols at the same address by sorting on type
14722 else if (amap->type < bmap->type)
14728 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
14730 static unsigned long
14731 offset_prel31 (unsigned long addr, bfd_vma offset)
14733 return (addr & ~0x7ffffffful) | ((addr + offset) & 0x7ffffffful);
14736 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
14740 copy_exidx_entry (bfd *output_bfd, bfd_byte *to, bfd_byte *from, bfd_vma offset)
14742 unsigned long first_word = bfd_get_32 (output_bfd, from);
14743 unsigned long second_word = bfd_get_32 (output_bfd, from + 4);
14745 /* High bit of first word is supposed to be zero. */
14746 if ((first_word & 0x80000000ul) == 0)
14747 first_word = offset_prel31 (first_word, offset);
14749 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
14750 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
14751 if ((second_word != 0x1) && ((second_word & 0x80000000ul) == 0))
14752 second_word = offset_prel31 (second_word, offset);
14754 bfd_put_32 (output_bfd, first_word, to);
14755 bfd_put_32 (output_bfd, second_word, to + 4);
14758 /* Data for make_branch_to_a8_stub(). */
14760 struct a8_branch_to_stub_data {
14761 asection *writing_section;
14762 bfd_byte *contents;
14766 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
14767 places for a particular section. */
14770 make_branch_to_a8_stub (struct bfd_hash_entry *gen_entry,
14773 struct elf32_arm_stub_hash_entry *stub_entry;
14774 struct a8_branch_to_stub_data *data;
14775 bfd_byte *contents;
14776 unsigned long branch_insn;
14777 bfd_vma veneered_insn_loc, veneer_entry_loc;
14778 bfd_signed_vma branch_offset;
14780 unsigned int target;
14782 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
14783 data = (struct a8_branch_to_stub_data *) in_arg;
14785 if (stub_entry->target_section != data->writing_section
14786 || stub_entry->stub_type < arm_stub_a8_veneer_lwm)
14789 contents = data->contents;
14791 veneered_insn_loc = stub_entry->target_section->output_section->vma
14792 + stub_entry->target_section->output_offset
14793 + stub_entry->target_value;
14795 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
14796 + stub_entry->stub_sec->output_offset
14797 + stub_entry->stub_offset;
14799 if (stub_entry->stub_type == arm_stub_a8_veneer_blx)
14800 veneered_insn_loc &= ~3u;
14802 branch_offset = veneer_entry_loc - veneered_insn_loc - 4;
14804 abfd = stub_entry->target_section->owner;
14805 target = stub_entry->target_value;
14807 /* We attempt to avoid this condition by setting stubs_always_after_branch
14808 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
14809 This check is just to be on the safe side... */
14810 if ((veneered_insn_loc & ~0xfff) == (veneer_entry_loc & ~0xfff))
14812 (*_bfd_error_handler) (_("%B: error: Cortex-A8 erratum stub is "
14813 "allocated in unsafe location"), abfd);
14817 switch (stub_entry->stub_type)
14819 case arm_stub_a8_veneer_b:
14820 case arm_stub_a8_veneer_b_cond:
14821 branch_insn = 0xf0009000;
14824 case arm_stub_a8_veneer_blx:
14825 branch_insn = 0xf000e800;
14828 case arm_stub_a8_veneer_bl:
14830 unsigned int i1, j1, i2, j2, s;
14832 branch_insn = 0xf000d000;
14835 if (branch_offset < -16777216 || branch_offset > 16777214)
14837 /* There's not much we can do apart from complain if this
14839 (*_bfd_error_handler) (_("%B: error: Cortex-A8 erratum stub out "
14840 "of range (input file too large)"), abfd);
14844 /* i1 = not(j1 eor s), so:
14846 j1 = (not i1) eor s. */
14848 branch_insn |= (branch_offset >> 1) & 0x7ff;
14849 branch_insn |= ((branch_offset >> 12) & 0x3ff) << 16;
14850 i2 = (branch_offset >> 22) & 1;
14851 i1 = (branch_offset >> 23) & 1;
14852 s = (branch_offset >> 24) & 1;
14855 branch_insn |= j2 << 11;
14856 branch_insn |= j1 << 13;
14857 branch_insn |= s << 26;
14866 bfd_put_16 (abfd, (branch_insn >> 16) & 0xffff, &contents[target]);
14867 bfd_put_16 (abfd, branch_insn & 0xffff, &contents[target + 2]);
14872 /* Do code byteswapping. Return FALSE afterwards so that the section is
14873 written out as normal. */
14876 elf32_arm_write_section (bfd *output_bfd,
14877 struct bfd_link_info *link_info,
14879 bfd_byte *contents)
14881 unsigned int mapcount, errcount;
14882 _arm_elf_section_data *arm_data;
14883 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
14884 elf32_arm_section_map *map;
14885 elf32_vfp11_erratum_list *errnode;
14888 bfd_vma offset = sec->output_section->vma + sec->output_offset;
14892 if (globals == NULL)
14895 /* If this section has not been allocated an _arm_elf_section_data
14896 structure then we cannot record anything. */
14897 arm_data = get_arm_elf_section_data (sec);
14898 if (arm_data == NULL)
14901 mapcount = arm_data->mapcount;
14902 map = arm_data->map;
14903 errcount = arm_data->erratumcount;
14907 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
14909 for (errnode = arm_data->erratumlist; errnode != 0;
14910 errnode = errnode->next)
14912 bfd_vma target = errnode->vma - offset;
14914 switch (errnode->type)
14916 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
14918 bfd_vma branch_to_veneer;
14919 /* Original condition code of instruction, plus bit mask for
14920 ARM B instruction. */
14921 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
14924 /* The instruction is before the label. */
14927 /* Above offset included in -4 below. */
14928 branch_to_veneer = errnode->u.b.veneer->vma
14929 - errnode->vma - 4;
14931 if ((signed) branch_to_veneer < -(1 << 25)
14932 || (signed) branch_to_veneer >= (1 << 25))
14933 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
14934 "range"), output_bfd);
14936 insn |= (branch_to_veneer >> 2) & 0xffffff;
14937 contents[endianflip ^ target] = insn & 0xff;
14938 contents[endianflip ^ (target + 1)] = (insn >> 8) & 0xff;
14939 contents[endianflip ^ (target + 2)] = (insn >> 16) & 0xff;
14940 contents[endianflip ^ (target + 3)] = (insn >> 24) & 0xff;
14944 case VFP11_ERRATUM_ARM_VENEER:
14946 bfd_vma branch_from_veneer;
14949 /* Take size of veneer into account. */
14950 branch_from_veneer = errnode->u.v.branch->vma
14951 - errnode->vma - 12;
14953 if ((signed) branch_from_veneer < -(1 << 25)
14954 || (signed) branch_from_veneer >= (1 << 25))
14955 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
14956 "range"), output_bfd);
14958 /* Original instruction. */
14959 insn = errnode->u.v.branch->u.b.vfp_insn;
14960 contents[endianflip ^ target] = insn & 0xff;
14961 contents[endianflip ^ (target + 1)] = (insn >> 8) & 0xff;
14962 contents[endianflip ^ (target + 2)] = (insn >> 16) & 0xff;
14963 contents[endianflip ^ (target + 3)] = (insn >> 24) & 0xff;
14965 /* Branch back to insn after original insn. */
14966 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
14967 contents[endianflip ^ (target + 4)] = insn & 0xff;
14968 contents[endianflip ^ (target + 5)] = (insn >> 8) & 0xff;
14969 contents[endianflip ^ (target + 6)] = (insn >> 16) & 0xff;
14970 contents[endianflip ^ (target + 7)] = (insn >> 24) & 0xff;
14980 if (arm_data->elf.this_hdr.sh_type == SHT_ARM_EXIDX)
14982 arm_unwind_table_edit *edit_node
14983 = arm_data->u.exidx.unwind_edit_list;
14984 /* Now, sec->size is the size of the section we will write. The original
14985 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
14986 markers) was sec->rawsize. (This isn't the case if we perform no
14987 edits, then rawsize will be zero and we should use size). */
14988 bfd_byte *edited_contents = (bfd_byte *) bfd_malloc (sec->size);
14989 unsigned int input_size = sec->rawsize ? sec->rawsize : sec->size;
14990 unsigned int in_index, out_index;
14991 bfd_vma add_to_offsets = 0;
14993 for (in_index = 0, out_index = 0; in_index * 8 < input_size || edit_node;)
14997 unsigned int edit_index = edit_node->index;
14999 if (in_index < edit_index && in_index * 8 < input_size)
15001 copy_exidx_entry (output_bfd, edited_contents + out_index * 8,
15002 contents + in_index * 8, add_to_offsets);
15006 else if (in_index == edit_index
15007 || (in_index * 8 >= input_size
15008 && edit_index == UINT_MAX))
15010 switch (edit_node->type)
15012 case DELETE_EXIDX_ENTRY:
15014 add_to_offsets += 8;
15017 case INSERT_EXIDX_CANTUNWIND_AT_END:
15019 asection *text_sec = edit_node->linked_section;
15020 bfd_vma text_offset = text_sec->output_section->vma
15021 + text_sec->output_offset
15023 bfd_vma exidx_offset = offset + out_index * 8;
15024 unsigned long prel31_offset;
15026 /* Note: this is meant to be equivalent to an
15027 R_ARM_PREL31 relocation. These synthetic
15028 EXIDX_CANTUNWIND markers are not relocated by the
15029 usual BFD method. */
15030 prel31_offset = (text_offset - exidx_offset)
15033 /* First address we can't unwind. */
15034 bfd_put_32 (output_bfd, prel31_offset,
15035 &edited_contents[out_index * 8]);
15037 /* Code for EXIDX_CANTUNWIND. */
15038 bfd_put_32 (output_bfd, 0x1,
15039 &edited_contents[out_index * 8 + 4]);
15042 add_to_offsets -= 8;
15047 edit_node = edit_node->next;
15052 /* No more edits, copy remaining entries verbatim. */
15053 copy_exidx_entry (output_bfd, edited_contents + out_index * 8,
15054 contents + in_index * 8, add_to_offsets);
15060 if (!(sec->flags & SEC_EXCLUDE) && !(sec->flags & SEC_NEVER_LOAD))
15061 bfd_set_section_contents (output_bfd, sec->output_section,
15063 (file_ptr) sec->output_offset, sec->size);
15068 /* Fix code to point to Cortex-A8 erratum stubs. */
15069 if (globals->fix_cortex_a8)
15071 struct a8_branch_to_stub_data data;
15073 data.writing_section = sec;
15074 data.contents = contents;
15076 bfd_hash_traverse (&globals->stub_hash_table, make_branch_to_a8_stub,
15083 if (globals->byteswap_code)
15085 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
15088 for (i = 0; i < mapcount; i++)
15090 if (i == mapcount - 1)
15093 end = map[i + 1].vma;
15095 switch (map[i].type)
15098 /* Byte swap code words. */
15099 while (ptr + 3 < end)
15101 tmp = contents[ptr];
15102 contents[ptr] = contents[ptr + 3];
15103 contents[ptr + 3] = tmp;
15104 tmp = contents[ptr + 1];
15105 contents[ptr + 1] = contents[ptr + 2];
15106 contents[ptr + 2] = tmp;
15112 /* Byte swap code halfwords. */
15113 while (ptr + 1 < end)
15115 tmp = contents[ptr];
15116 contents[ptr] = contents[ptr + 1];
15117 contents[ptr + 1] = tmp;
15123 /* Leave data alone. */
15131 arm_data->mapcount = -1;
15132 arm_data->mapsize = 0;
15133 arm_data->map = NULL;
15138 /* Mangle thumb function symbols as we read them in. */
15141 elf32_arm_swap_symbol_in (bfd * abfd,
15144 Elf_Internal_Sym *dst)
15146 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
15149 /* New EABI objects mark thumb function symbols by setting the low bit of
15151 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
15152 || ELF_ST_TYPE (dst->st_info) == STT_GNU_IFUNC)
15154 if (dst->st_value & 1)
15156 dst->st_value &= ~(bfd_vma) 1;
15157 dst->st_target_internal = ST_BRANCH_TO_THUMB;
15160 dst->st_target_internal = ST_BRANCH_TO_ARM;
15162 else if (ELF_ST_TYPE (dst->st_info) == STT_ARM_TFUNC)
15164 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_FUNC);
15165 dst->st_target_internal = ST_BRANCH_TO_THUMB;
15167 else if (ELF_ST_TYPE (dst->st_info) == STT_SECTION)
15168 dst->st_target_internal = ST_BRANCH_LONG;
15170 dst->st_target_internal = ST_BRANCH_UNKNOWN;
15176 /* Mangle thumb function symbols as we write them out. */
15179 elf32_arm_swap_symbol_out (bfd *abfd,
15180 const Elf_Internal_Sym *src,
15184 Elf_Internal_Sym newsym;
15186 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
15187 of the address set, as per the new EABI. We do this unconditionally
15188 because objcopy does not set the elf header flags until after
15189 it writes out the symbol table. */
15190 if (src->st_target_internal == ST_BRANCH_TO_THUMB)
15193 if (ELF_ST_TYPE (src->st_info) != STT_GNU_IFUNC)
15194 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
15195 if (newsym.st_shndx != SHN_UNDEF)
15197 /* Do this only for defined symbols. At link type, the static
15198 linker will simulate the work of dynamic linker of resolving
15199 symbols and will carry over the thumbness of found symbols to
15200 the output symbol table. It's not clear how it happens, but
15201 the thumbness of undefined symbols can well be different at
15202 runtime, and writing '1' for them will be confusing for users
15203 and possibly for dynamic linker itself.
15205 newsym.st_value |= 1;
15210 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
15213 /* Add the PT_ARM_EXIDX program header. */
15216 elf32_arm_modify_segment_map (bfd *abfd,
15217 struct bfd_link_info *info ATTRIBUTE_UNUSED)
15219 struct elf_segment_map *m;
15222 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
15223 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
15225 /* If there is already a PT_ARM_EXIDX header, then we do not
15226 want to add another one. This situation arises when running
15227 "strip"; the input binary already has the header. */
15228 m = elf_tdata (abfd)->segment_map;
15229 while (m && m->p_type != PT_ARM_EXIDX)
15233 m = (struct elf_segment_map *)
15234 bfd_zalloc (abfd, sizeof (struct elf_segment_map));
15237 m->p_type = PT_ARM_EXIDX;
15239 m->sections[0] = sec;
15241 m->next = elf_tdata (abfd)->segment_map;
15242 elf_tdata (abfd)->segment_map = m;
15249 /* We may add a PT_ARM_EXIDX program header. */
15252 elf32_arm_additional_program_headers (bfd *abfd,
15253 struct bfd_link_info *info ATTRIBUTE_UNUSED)
15257 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
15258 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
15264 /* Hook called by the linker routine which adds symbols from an object
15268 elf32_arm_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
15269 Elf_Internal_Sym *sym, const char **namep,
15270 flagword *flagsp, asection **secp, bfd_vma *valp)
15272 if ((abfd->flags & DYNAMIC) == 0
15273 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
15274 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
15275 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
15277 if (elf32_arm_hash_table (info)->vxworks_p
15278 && !elf_vxworks_add_symbol_hook (abfd, info, sym, namep,
15279 flagsp, secp, valp))
15285 /* We use this to override swap_symbol_in and swap_symbol_out. */
15286 const struct elf_size_info elf32_arm_size_info =
15288 sizeof (Elf32_External_Ehdr),
15289 sizeof (Elf32_External_Phdr),
15290 sizeof (Elf32_External_Shdr),
15291 sizeof (Elf32_External_Rel),
15292 sizeof (Elf32_External_Rela),
15293 sizeof (Elf32_External_Sym),
15294 sizeof (Elf32_External_Dyn),
15295 sizeof (Elf_External_Note),
15299 ELFCLASS32, EV_CURRENT,
15300 bfd_elf32_write_out_phdrs,
15301 bfd_elf32_write_shdrs_and_ehdr,
15302 bfd_elf32_checksum_contents,
15303 bfd_elf32_write_relocs,
15304 elf32_arm_swap_symbol_in,
15305 elf32_arm_swap_symbol_out,
15306 bfd_elf32_slurp_reloc_table,
15307 bfd_elf32_slurp_symbol_table,
15308 bfd_elf32_swap_dyn_in,
15309 bfd_elf32_swap_dyn_out,
15310 bfd_elf32_swap_reloc_in,
15311 bfd_elf32_swap_reloc_out,
15312 bfd_elf32_swap_reloca_in,
15313 bfd_elf32_swap_reloca_out
15316 #define ELF_ARCH bfd_arch_arm
15317 #define ELF_TARGET_ID ARM_ELF_DATA
15318 #define ELF_MACHINE_CODE EM_ARM
15319 #ifdef __QNXTARGET__
15320 #define ELF_MAXPAGESIZE 0x1000
15322 #define ELF_MAXPAGESIZE 0x8000
15324 #define ELF_MINPAGESIZE 0x1000
15325 #define ELF_COMMONPAGESIZE 0x1000
15327 #define bfd_elf32_mkobject elf32_arm_mkobject
15329 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
15330 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
15331 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
15332 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
15333 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
15334 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
15335 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
15336 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
15337 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
15338 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
15339 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
15340 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
15341 #define bfd_elf32_bfd_final_link elf32_arm_final_link
15343 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
15344 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
15345 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
15346 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
15347 #define elf_backend_check_relocs elf32_arm_check_relocs
15348 #define elf_backend_relocate_section elf32_arm_relocate_section
15349 #define elf_backend_write_section elf32_arm_write_section
15350 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
15351 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
15352 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
15353 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
15354 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
15355 #define elf_backend_always_size_sections elf32_arm_always_size_sections
15356 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
15357 #define elf_backend_post_process_headers elf32_arm_post_process_headers
15358 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
15359 #define elf_backend_object_p elf32_arm_object_p
15360 #define elf_backend_fake_sections elf32_arm_fake_sections
15361 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
15362 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15363 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
15364 #define elf_backend_size_info elf32_arm_size_info
15365 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
15366 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
15367 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
15368 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
15369 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
15371 #define elf_backend_can_refcount 1
15372 #define elf_backend_can_gc_sections 1
15373 #define elf_backend_plt_readonly 1
15374 #define elf_backend_want_got_plt 1
15375 #define elf_backend_want_plt_sym 0
15376 #define elf_backend_may_use_rel_p 1
15377 #define elf_backend_may_use_rela_p 0
15378 #define elf_backend_default_use_rela_p 0
15380 #define elf_backend_got_header_size 12
15382 #undef elf_backend_obj_attrs_vendor
15383 #define elf_backend_obj_attrs_vendor "aeabi"
15384 #undef elf_backend_obj_attrs_section
15385 #define elf_backend_obj_attrs_section ".ARM.attributes"
15386 #undef elf_backend_obj_attrs_arg_type
15387 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
15388 #undef elf_backend_obj_attrs_section_type
15389 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
15390 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
15391 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
15393 #include "elf32-target.h"
15395 /* VxWorks Targets. */
15397 #undef TARGET_LITTLE_SYM
15398 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
15399 #undef TARGET_LITTLE_NAME
15400 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
15401 #undef TARGET_BIG_SYM
15402 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
15403 #undef TARGET_BIG_NAME
15404 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
15406 /* Like elf32_arm_link_hash_table_create -- but overrides
15407 appropriately for VxWorks. */
15409 static struct bfd_link_hash_table *
15410 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
15412 struct bfd_link_hash_table *ret;
15414 ret = elf32_arm_link_hash_table_create (abfd);
15417 struct elf32_arm_link_hash_table *htab
15418 = (struct elf32_arm_link_hash_table *) ret;
15420 htab->vxworks_p = 1;
15426 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
15428 elf32_arm_final_write_processing (abfd, linker);
15429 elf_vxworks_final_write_processing (abfd, linker);
15433 #define elf32_bed elf32_arm_vxworks_bed
15435 #undef bfd_elf32_bfd_link_hash_table_create
15436 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
15437 #undef elf_backend_final_write_processing
15438 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
15439 #undef elf_backend_emit_relocs
15440 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
15442 #undef elf_backend_may_use_rel_p
15443 #define elf_backend_may_use_rel_p 0
15444 #undef elf_backend_may_use_rela_p
15445 #define elf_backend_may_use_rela_p 1
15446 #undef elf_backend_default_use_rela_p
15447 #define elf_backend_default_use_rela_p 1
15448 #undef elf_backend_want_plt_sym
15449 #define elf_backend_want_plt_sym 1
15450 #undef ELF_MAXPAGESIZE
15451 #define ELF_MAXPAGESIZE 0x1000
15453 #include "elf32-target.h"
15456 /* Merge backend specific data from an object file to the output
15457 object file when linking. */
15460 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
15462 flagword out_flags;
15464 bfd_boolean flags_compatible = TRUE;
15467 /* Check if we have the same endianness. */
15468 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
15471 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
15474 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
15477 /* The input BFD must have had its flags initialised. */
15478 /* The following seems bogus to me -- The flags are initialized in
15479 the assembler but I don't think an elf_flags_init field is
15480 written into the object. */
15481 /* BFD_ASSERT (elf_flags_init (ibfd)); */
15483 in_flags = elf_elfheader (ibfd)->e_flags;
15484 out_flags = elf_elfheader (obfd)->e_flags;
15486 /* In theory there is no reason why we couldn't handle this. However
15487 in practice it isn't even close to working and there is no real
15488 reason to want it. */
15489 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
15490 && !(ibfd->flags & DYNAMIC)
15491 && (in_flags & EF_ARM_BE8))
15493 _bfd_error_handler (_("error: %B is already in final BE8 format"),
15498 if (!elf_flags_init (obfd))
15500 /* If the input is the default architecture and had the default
15501 flags then do not bother setting the flags for the output
15502 architecture, instead allow future merges to do this. If no
15503 future merges ever set these flags then they will retain their
15504 uninitialised values, which surprise surprise, correspond
15505 to the default values. */
15506 if (bfd_get_arch_info (ibfd)->the_default
15507 && elf_elfheader (ibfd)->e_flags == 0)
15510 elf_flags_init (obfd) = TRUE;
15511 elf_elfheader (obfd)->e_flags = in_flags;
15513 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
15514 && bfd_get_arch_info (obfd)->the_default)
15515 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
15520 /* Determine what should happen if the input ARM architecture
15521 does not match the output ARM architecture. */
15522 if (! bfd_arm_merge_machines (ibfd, obfd))
15525 /* Identical flags must be compatible. */
15526 if (in_flags == out_flags)
15529 /* Check to see if the input BFD actually contains any sections. If
15530 not, its flags may not have been initialised either, but it
15531 cannot actually cause any incompatiblity. Do not short-circuit
15532 dynamic objects; their section list may be emptied by
15533 elf_link_add_object_symbols.
15535 Also check to see if there are no code sections in the input.
15536 In this case there is no need to check for code specific flags.
15537 XXX - do we need to worry about floating-point format compatability
15538 in data sections ? */
15539 if (!(ibfd->flags & DYNAMIC))
15541 bfd_boolean null_input_bfd = TRUE;
15542 bfd_boolean only_data_sections = TRUE;
15544 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
15546 /* Ignore synthetic glue sections. */
15547 if (strcmp (sec->name, ".glue_7")
15548 && strcmp (sec->name, ".glue_7t"))
15550 if ((bfd_get_section_flags (ibfd, sec)
15551 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
15552 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
15553 only_data_sections = FALSE;
15555 null_input_bfd = FALSE;
15560 if (null_input_bfd || only_data_sections)
15564 /* Complain about various flag mismatches. */
15565 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
15566 EF_ARM_EABI_VERSION (out_flags)))
15569 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
15571 (in_flags & EF_ARM_EABIMASK) >> 24,
15572 (out_flags & EF_ARM_EABIMASK) >> 24);
15576 /* Not sure what needs to be checked for EABI versions >= 1. */
15577 /* VxWorks libraries do not use these flags. */
15578 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
15579 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
15580 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
15582 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
15585 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
15587 in_flags & EF_ARM_APCS_26 ? 26 : 32,
15588 out_flags & EF_ARM_APCS_26 ? 26 : 32);
15589 flags_compatible = FALSE;
15592 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
15594 if (in_flags & EF_ARM_APCS_FLOAT)
15596 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
15600 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
15603 flags_compatible = FALSE;
15606 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
15608 if (in_flags & EF_ARM_VFP_FLOAT)
15610 (_("error: %B uses VFP instructions, whereas %B does not"),
15614 (_("error: %B uses FPA instructions, whereas %B does not"),
15617 flags_compatible = FALSE;
15620 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
15622 if (in_flags & EF_ARM_MAVERICK_FLOAT)
15624 (_("error: %B uses Maverick instructions, whereas %B does not"),
15628 (_("error: %B does not use Maverick instructions, whereas %B does"),
15631 flags_compatible = FALSE;
15634 #ifdef EF_ARM_SOFT_FLOAT
15635 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
15637 /* We can allow interworking between code that is VFP format
15638 layout, and uses either soft float or integer regs for
15639 passing floating point arguments and results. We already
15640 know that the APCS_FLOAT flags match; similarly for VFP
15642 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
15643 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
15645 if (in_flags & EF_ARM_SOFT_FLOAT)
15647 (_("error: %B uses software FP, whereas %B uses hardware FP"),
15651 (_("error: %B uses hardware FP, whereas %B uses software FP"),
15654 flags_compatible = FALSE;
15659 /* Interworking mismatch is only a warning. */
15660 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
15662 if (in_flags & EF_ARM_INTERWORK)
15665 (_("Warning: %B supports interworking, whereas %B does not"),
15671 (_("Warning: %B does not support interworking, whereas %B does"),
15677 return flags_compatible;
15681 /* Symbian OS Targets. */
15683 #undef TARGET_LITTLE_SYM
15684 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
15685 #undef TARGET_LITTLE_NAME
15686 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
15687 #undef TARGET_BIG_SYM
15688 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
15689 #undef TARGET_BIG_NAME
15690 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
15692 /* Like elf32_arm_link_hash_table_create -- but overrides
15693 appropriately for Symbian OS. */
15695 static struct bfd_link_hash_table *
15696 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
15698 struct bfd_link_hash_table *ret;
15700 ret = elf32_arm_link_hash_table_create (abfd);
15703 struct elf32_arm_link_hash_table *htab
15704 = (struct elf32_arm_link_hash_table *)ret;
15705 /* There is no PLT header for Symbian OS. */
15706 htab->plt_header_size = 0;
15707 /* The PLT entries are each one instruction and one word. */
15708 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
15709 htab->symbian_p = 1;
15710 /* Symbian uses armv5t or above, so use_blx is always true. */
15712 htab->root.is_relocatable_executable = 1;
15717 static const struct bfd_elf_special_section
15718 elf32_arm_symbian_special_sections[] =
15720 /* In a BPABI executable, the dynamic linking sections do not go in
15721 the loadable read-only segment. The post-linker may wish to
15722 refer to these sections, but they are not part of the final
15724 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
15725 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
15726 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
15727 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
15728 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
15729 /* These sections do not need to be writable as the SymbianOS
15730 postlinker will arrange things so that no dynamic relocation is
15732 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
15733 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
15734 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
15735 { NULL, 0, 0, 0, 0 }
15739 elf32_arm_symbian_begin_write_processing (bfd *abfd,
15740 struct bfd_link_info *link_info)
15742 /* BPABI objects are never loaded directly by an OS kernel; they are
15743 processed by a postlinker first, into an OS-specific format. If
15744 the D_PAGED bit is set on the file, BFD will align segments on
15745 page boundaries, so that an OS can directly map the file. With
15746 BPABI objects, that just results in wasted space. In addition,
15747 because we clear the D_PAGED bit, map_sections_to_segments will
15748 recognize that the program headers should not be mapped into any
15749 loadable segment. */
15750 abfd->flags &= ~D_PAGED;
15751 elf32_arm_begin_write_processing (abfd, link_info);
15755 elf32_arm_symbian_modify_segment_map (bfd *abfd,
15756 struct bfd_link_info *info)
15758 struct elf_segment_map *m;
15761 /* BPABI shared libraries and executables should have a PT_DYNAMIC
15762 segment. However, because the .dynamic section is not marked
15763 with SEC_LOAD, the generic ELF code will not create such a
15765 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
15768 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
15769 if (m->p_type == PT_DYNAMIC)
15774 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
15775 m->next = elf_tdata (abfd)->segment_map;
15776 elf_tdata (abfd)->segment_map = m;
15780 /* Also call the generic arm routine. */
15781 return elf32_arm_modify_segment_map (abfd, info);
15784 /* Return address for Ith PLT stub in section PLT, for relocation REL
15785 or (bfd_vma) -1 if it should not be included. */
15788 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
15789 const arelent *rel ATTRIBUTE_UNUSED)
15791 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
15796 #define elf32_bed elf32_arm_symbian_bed
15798 /* The dynamic sections are not allocated on SymbianOS; the postlinker
15799 will process them and then discard them. */
15800 #undef ELF_DYNAMIC_SEC_FLAGS
15801 #define ELF_DYNAMIC_SEC_FLAGS \
15802 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
15804 #undef elf_backend_emit_relocs
15806 #undef bfd_elf32_bfd_link_hash_table_create
15807 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
15808 #undef elf_backend_special_sections
15809 #define elf_backend_special_sections elf32_arm_symbian_special_sections
15810 #undef elf_backend_begin_write_processing
15811 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
15812 #undef elf_backend_final_write_processing
15813 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15815 #undef elf_backend_modify_segment_map
15816 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
15818 /* There is no .got section for BPABI objects, and hence no header. */
15819 #undef elf_backend_got_header_size
15820 #define elf_backend_got_header_size 0
15822 /* Similarly, there is no .got.plt section. */
15823 #undef elf_backend_want_got_plt
15824 #define elf_backend_want_got_plt 0
15826 #undef elf_backend_plt_sym_val
15827 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
15829 #undef elf_backend_may_use_rel_p
15830 #define elf_backend_may_use_rel_p 1
15831 #undef elf_backend_may_use_rela_p
15832 #define elf_backend_may_use_rela_p 0
15833 #undef elf_backend_default_use_rela_p
15834 #define elf_backend_default_use_rela_p 0
15835 #undef elf_backend_want_plt_sym
15836 #define elf_backend_want_plt_sym 0
15837 #undef ELF_MAXPAGESIZE
15838 #define ELF_MAXPAGESIZE 0x8000
15840 #include "elf32-target.h"