1 /* 32-bit ELF support for ARM
2 Copyright (C) 1998-2015 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "bfd_stdint.h"
26 #include "libiberty.h"
30 #include "elf-vxworks.h"
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
62 #define ARM_ELF_ABI_VERSION 0
63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
65 /* The Adjusted Place, as defined by AAELF. */
66 #define Pa(X) ((X) & 0xfffffffc)
68 static bfd_boolean elf32_arm_write_section (bfd *output_bfd,
69 struct bfd_link_info *link_info,
73 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
74 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
77 static reloc_howto_type elf32_arm_howto_table_1[] =
80 HOWTO (R_ARM_NONE, /* type */
82 3, /* size (0 = byte, 1 = short, 2 = long) */
84 FALSE, /* pc_relative */
86 complain_overflow_dont,/* complain_on_overflow */
87 bfd_elf_generic_reloc, /* special_function */
88 "R_ARM_NONE", /* name */
89 FALSE, /* partial_inplace */
92 FALSE), /* pcrel_offset */
94 HOWTO (R_ARM_PC24, /* type */
96 2, /* size (0 = byte, 1 = short, 2 = long) */
98 TRUE, /* pc_relative */
100 complain_overflow_signed,/* complain_on_overflow */
101 bfd_elf_generic_reloc, /* special_function */
102 "R_ARM_PC24", /* name */
103 FALSE, /* partial_inplace */
104 0x00ffffff, /* src_mask */
105 0x00ffffff, /* dst_mask */
106 TRUE), /* pcrel_offset */
108 /* 32 bit absolute */
109 HOWTO (R_ARM_ABS32, /* type */
111 2, /* size (0 = byte, 1 = short, 2 = long) */
113 FALSE, /* pc_relative */
115 complain_overflow_bitfield,/* complain_on_overflow */
116 bfd_elf_generic_reloc, /* special_function */
117 "R_ARM_ABS32", /* name */
118 FALSE, /* partial_inplace */
119 0xffffffff, /* src_mask */
120 0xffffffff, /* dst_mask */
121 FALSE), /* pcrel_offset */
123 /* standard 32bit pc-relative reloc */
124 HOWTO (R_ARM_REL32, /* type */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
128 TRUE, /* pc_relative */
130 complain_overflow_bitfield,/* complain_on_overflow */
131 bfd_elf_generic_reloc, /* special_function */
132 "R_ARM_REL32", /* name */
133 FALSE, /* partial_inplace */
134 0xffffffff, /* src_mask */
135 0xffffffff, /* dst_mask */
136 TRUE), /* pcrel_offset */
138 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
139 HOWTO (R_ARM_LDR_PC_G0, /* type */
141 0, /* size (0 = byte, 1 = short, 2 = long) */
143 TRUE, /* pc_relative */
145 complain_overflow_dont,/* complain_on_overflow */
146 bfd_elf_generic_reloc, /* special_function */
147 "R_ARM_LDR_PC_G0", /* name */
148 FALSE, /* partial_inplace */
149 0xffffffff, /* src_mask */
150 0xffffffff, /* dst_mask */
151 TRUE), /* pcrel_offset */
153 /* 16 bit absolute */
154 HOWTO (R_ARM_ABS16, /* type */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE, /* pc_relative */
160 complain_overflow_bitfield,/* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_ARM_ABS16", /* name */
163 FALSE, /* partial_inplace */
164 0x0000ffff, /* src_mask */
165 0x0000ffff, /* dst_mask */
166 FALSE), /* pcrel_offset */
168 /* 12 bit absolute */
169 HOWTO (R_ARM_ABS12, /* type */
171 2, /* size (0 = byte, 1 = short, 2 = long) */
173 FALSE, /* pc_relative */
175 complain_overflow_bitfield,/* complain_on_overflow */
176 bfd_elf_generic_reloc, /* special_function */
177 "R_ARM_ABS12", /* name */
178 FALSE, /* partial_inplace */
179 0x00000fff, /* src_mask */
180 0x00000fff, /* dst_mask */
181 FALSE), /* pcrel_offset */
183 HOWTO (R_ARM_THM_ABS5, /* type */
185 1, /* size (0 = byte, 1 = short, 2 = long) */
187 FALSE, /* pc_relative */
189 complain_overflow_bitfield,/* complain_on_overflow */
190 bfd_elf_generic_reloc, /* special_function */
191 "R_ARM_THM_ABS5", /* name */
192 FALSE, /* partial_inplace */
193 0x000007e0, /* src_mask */
194 0x000007e0, /* dst_mask */
195 FALSE), /* pcrel_offset */
198 HOWTO (R_ARM_ABS8, /* type */
200 0, /* size (0 = byte, 1 = short, 2 = long) */
202 FALSE, /* pc_relative */
204 complain_overflow_bitfield,/* complain_on_overflow */
205 bfd_elf_generic_reloc, /* special_function */
206 "R_ARM_ABS8", /* name */
207 FALSE, /* partial_inplace */
208 0x000000ff, /* src_mask */
209 0x000000ff, /* dst_mask */
210 FALSE), /* pcrel_offset */
212 HOWTO (R_ARM_SBREL32, /* type */
214 2, /* size (0 = byte, 1 = short, 2 = long) */
216 FALSE, /* pc_relative */
218 complain_overflow_dont,/* complain_on_overflow */
219 bfd_elf_generic_reloc, /* special_function */
220 "R_ARM_SBREL32", /* name */
221 FALSE, /* partial_inplace */
222 0xffffffff, /* src_mask */
223 0xffffffff, /* dst_mask */
224 FALSE), /* pcrel_offset */
226 HOWTO (R_ARM_THM_CALL, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 TRUE, /* pc_relative */
232 complain_overflow_signed,/* complain_on_overflow */
233 bfd_elf_generic_reloc, /* special_function */
234 "R_ARM_THM_CALL", /* name */
235 FALSE, /* partial_inplace */
236 0x07ff2fff, /* src_mask */
237 0x07ff2fff, /* dst_mask */
238 TRUE), /* pcrel_offset */
240 HOWTO (R_ARM_THM_PC8, /* type */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
244 TRUE, /* pc_relative */
246 complain_overflow_signed,/* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_ARM_THM_PC8", /* name */
249 FALSE, /* partial_inplace */
250 0x000000ff, /* src_mask */
251 0x000000ff, /* dst_mask */
252 TRUE), /* pcrel_offset */
254 HOWTO (R_ARM_BREL_ADJ, /* type */
256 1, /* size (0 = byte, 1 = short, 2 = long) */
258 FALSE, /* pc_relative */
260 complain_overflow_signed,/* complain_on_overflow */
261 bfd_elf_generic_reloc, /* special_function */
262 "R_ARM_BREL_ADJ", /* name */
263 FALSE, /* partial_inplace */
264 0xffffffff, /* src_mask */
265 0xffffffff, /* dst_mask */
266 FALSE), /* pcrel_offset */
268 HOWTO (R_ARM_TLS_DESC, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE, /* pc_relative */
274 complain_overflow_bitfield,/* complain_on_overflow */
275 bfd_elf_generic_reloc, /* special_function */
276 "R_ARM_TLS_DESC", /* name */
277 FALSE, /* partial_inplace */
278 0xffffffff, /* src_mask */
279 0xffffffff, /* dst_mask */
280 FALSE), /* pcrel_offset */
282 HOWTO (R_ARM_THM_SWI8, /* type */
284 0, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE, /* pc_relative */
288 complain_overflow_signed,/* complain_on_overflow */
289 bfd_elf_generic_reloc, /* special_function */
290 "R_ARM_SWI8", /* name */
291 FALSE, /* partial_inplace */
292 0x00000000, /* src_mask */
293 0x00000000, /* dst_mask */
294 FALSE), /* pcrel_offset */
296 /* BLX instruction for the ARM. */
297 HOWTO (R_ARM_XPC25, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 TRUE, /* pc_relative */
303 complain_overflow_signed,/* complain_on_overflow */
304 bfd_elf_generic_reloc, /* special_function */
305 "R_ARM_XPC25", /* name */
306 FALSE, /* partial_inplace */
307 0x00ffffff, /* src_mask */
308 0x00ffffff, /* dst_mask */
309 TRUE), /* pcrel_offset */
311 /* BLX instruction for the Thumb. */
312 HOWTO (R_ARM_THM_XPC22, /* type */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
316 TRUE, /* pc_relative */
318 complain_overflow_signed,/* complain_on_overflow */
319 bfd_elf_generic_reloc, /* special_function */
320 "R_ARM_THM_XPC22", /* name */
321 FALSE, /* partial_inplace */
322 0x07ff2fff, /* src_mask */
323 0x07ff2fff, /* dst_mask */
324 TRUE), /* pcrel_offset */
326 /* Dynamic TLS relocations. */
328 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 FALSE, /* pc_relative */
334 complain_overflow_bitfield,/* complain_on_overflow */
335 bfd_elf_generic_reloc, /* special_function */
336 "R_ARM_TLS_DTPMOD32", /* name */
337 TRUE, /* partial_inplace */
338 0xffffffff, /* src_mask */
339 0xffffffff, /* dst_mask */
340 FALSE), /* pcrel_offset */
342 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 FALSE, /* pc_relative */
348 complain_overflow_bitfield,/* complain_on_overflow */
349 bfd_elf_generic_reloc, /* special_function */
350 "R_ARM_TLS_DTPOFF32", /* name */
351 TRUE, /* partial_inplace */
352 0xffffffff, /* src_mask */
353 0xffffffff, /* dst_mask */
354 FALSE), /* pcrel_offset */
356 HOWTO (R_ARM_TLS_TPOFF32, /* type */
358 2, /* size (0 = byte, 1 = short, 2 = long) */
360 FALSE, /* pc_relative */
362 complain_overflow_bitfield,/* complain_on_overflow */
363 bfd_elf_generic_reloc, /* special_function */
364 "R_ARM_TLS_TPOFF32", /* name */
365 TRUE, /* partial_inplace */
366 0xffffffff, /* src_mask */
367 0xffffffff, /* dst_mask */
368 FALSE), /* pcrel_offset */
370 /* Relocs used in ARM Linux */
372 HOWTO (R_ARM_COPY, /* type */
374 2, /* size (0 = byte, 1 = short, 2 = long) */
376 FALSE, /* pc_relative */
378 complain_overflow_bitfield,/* complain_on_overflow */
379 bfd_elf_generic_reloc, /* special_function */
380 "R_ARM_COPY", /* name */
381 TRUE, /* partial_inplace */
382 0xffffffff, /* src_mask */
383 0xffffffff, /* dst_mask */
384 FALSE), /* pcrel_offset */
386 HOWTO (R_ARM_GLOB_DAT, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_bitfield,/* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_ARM_GLOB_DAT", /* name */
395 TRUE, /* partial_inplace */
396 0xffffffff, /* src_mask */
397 0xffffffff, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 HOWTO (R_ARM_JUMP_SLOT, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE, /* pc_relative */
406 complain_overflow_bitfield,/* complain_on_overflow */
407 bfd_elf_generic_reloc, /* special_function */
408 "R_ARM_JUMP_SLOT", /* name */
409 TRUE, /* partial_inplace */
410 0xffffffff, /* src_mask */
411 0xffffffff, /* dst_mask */
412 FALSE), /* pcrel_offset */
414 HOWTO (R_ARM_RELATIVE, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 FALSE, /* pc_relative */
420 complain_overflow_bitfield,/* complain_on_overflow */
421 bfd_elf_generic_reloc, /* special_function */
422 "R_ARM_RELATIVE", /* name */
423 TRUE, /* partial_inplace */
424 0xffffffff, /* src_mask */
425 0xffffffff, /* dst_mask */
426 FALSE), /* pcrel_offset */
428 HOWTO (R_ARM_GOTOFF32, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE, /* pc_relative */
434 complain_overflow_bitfield,/* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
436 "R_ARM_GOTOFF32", /* name */
437 TRUE, /* partial_inplace */
438 0xffffffff, /* src_mask */
439 0xffffffff, /* dst_mask */
440 FALSE), /* pcrel_offset */
442 HOWTO (R_ARM_GOTPC, /* type */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
446 TRUE, /* pc_relative */
448 complain_overflow_bitfield,/* complain_on_overflow */
449 bfd_elf_generic_reloc, /* special_function */
450 "R_ARM_GOTPC", /* name */
451 TRUE, /* partial_inplace */
452 0xffffffff, /* src_mask */
453 0xffffffff, /* dst_mask */
454 TRUE), /* pcrel_offset */
456 HOWTO (R_ARM_GOT32, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE, /* pc_relative */
462 complain_overflow_bitfield,/* complain_on_overflow */
463 bfd_elf_generic_reloc, /* special_function */
464 "R_ARM_GOT32", /* name */
465 TRUE, /* partial_inplace */
466 0xffffffff, /* src_mask */
467 0xffffffff, /* dst_mask */
468 FALSE), /* pcrel_offset */
470 HOWTO (R_ARM_PLT32, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 TRUE, /* pc_relative */
476 complain_overflow_bitfield,/* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 "R_ARM_PLT32", /* name */
479 FALSE, /* partial_inplace */
480 0x00ffffff, /* src_mask */
481 0x00ffffff, /* dst_mask */
482 TRUE), /* pcrel_offset */
484 HOWTO (R_ARM_CALL, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 TRUE, /* pc_relative */
490 complain_overflow_signed,/* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 "R_ARM_CALL", /* name */
493 FALSE, /* partial_inplace */
494 0x00ffffff, /* src_mask */
495 0x00ffffff, /* dst_mask */
496 TRUE), /* pcrel_offset */
498 HOWTO (R_ARM_JUMP24, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 TRUE, /* pc_relative */
504 complain_overflow_signed,/* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 "R_ARM_JUMP24", /* name */
507 FALSE, /* partial_inplace */
508 0x00ffffff, /* src_mask */
509 0x00ffffff, /* dst_mask */
510 TRUE), /* pcrel_offset */
512 HOWTO (R_ARM_THM_JUMP24, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 TRUE, /* pc_relative */
518 complain_overflow_signed,/* complain_on_overflow */
519 bfd_elf_generic_reloc, /* special_function */
520 "R_ARM_THM_JUMP24", /* name */
521 FALSE, /* partial_inplace */
522 0x07ff2fff, /* src_mask */
523 0x07ff2fff, /* dst_mask */
524 TRUE), /* pcrel_offset */
526 HOWTO (R_ARM_BASE_ABS, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE, /* pc_relative */
532 complain_overflow_dont,/* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_ARM_BASE_ABS", /* name */
535 FALSE, /* partial_inplace */
536 0xffffffff, /* src_mask */
537 0xffffffff, /* dst_mask */
538 FALSE), /* pcrel_offset */
540 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 TRUE, /* pc_relative */
546 complain_overflow_dont,/* complain_on_overflow */
547 bfd_elf_generic_reloc, /* special_function */
548 "R_ARM_ALU_PCREL_7_0", /* name */
549 FALSE, /* partial_inplace */
550 0x00000fff, /* src_mask */
551 0x00000fff, /* dst_mask */
552 TRUE), /* pcrel_offset */
554 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 TRUE, /* pc_relative */
560 complain_overflow_dont,/* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_ARM_ALU_PCREL_15_8",/* name */
563 FALSE, /* partial_inplace */
564 0x00000fff, /* src_mask */
565 0x00000fff, /* dst_mask */
566 TRUE), /* pcrel_offset */
568 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 TRUE, /* pc_relative */
574 complain_overflow_dont,/* complain_on_overflow */
575 bfd_elf_generic_reloc, /* special_function */
576 "R_ARM_ALU_PCREL_23_15",/* name */
577 FALSE, /* partial_inplace */
578 0x00000fff, /* src_mask */
579 0x00000fff, /* dst_mask */
580 TRUE), /* pcrel_offset */
582 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE, /* pc_relative */
588 complain_overflow_dont,/* complain_on_overflow */
589 bfd_elf_generic_reloc, /* special_function */
590 "R_ARM_LDR_SBREL_11_0",/* name */
591 FALSE, /* partial_inplace */
592 0x00000fff, /* src_mask */
593 0x00000fff, /* dst_mask */
594 FALSE), /* pcrel_offset */
596 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE, /* pc_relative */
602 complain_overflow_dont,/* complain_on_overflow */
603 bfd_elf_generic_reloc, /* special_function */
604 "R_ARM_ALU_SBREL_19_12",/* name */
605 FALSE, /* partial_inplace */
606 0x000ff000, /* src_mask */
607 0x000ff000, /* dst_mask */
608 FALSE), /* pcrel_offset */
610 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE, /* pc_relative */
616 complain_overflow_dont,/* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_ARM_ALU_SBREL_27_20",/* name */
619 FALSE, /* partial_inplace */
620 0x0ff00000, /* src_mask */
621 0x0ff00000, /* dst_mask */
622 FALSE), /* pcrel_offset */
624 HOWTO (R_ARM_TARGET1, /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 FALSE, /* pc_relative */
630 complain_overflow_dont,/* complain_on_overflow */
631 bfd_elf_generic_reloc, /* special_function */
632 "R_ARM_TARGET1", /* name */
633 FALSE, /* partial_inplace */
634 0xffffffff, /* src_mask */
635 0xffffffff, /* dst_mask */
636 FALSE), /* pcrel_offset */
638 HOWTO (R_ARM_ROSEGREL32, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE, /* pc_relative */
644 complain_overflow_dont,/* complain_on_overflow */
645 bfd_elf_generic_reloc, /* special_function */
646 "R_ARM_ROSEGREL32", /* name */
647 FALSE, /* partial_inplace */
648 0xffffffff, /* src_mask */
649 0xffffffff, /* dst_mask */
650 FALSE), /* pcrel_offset */
652 HOWTO (R_ARM_V4BX, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE, /* pc_relative */
658 complain_overflow_dont,/* complain_on_overflow */
659 bfd_elf_generic_reloc, /* special_function */
660 "R_ARM_V4BX", /* name */
661 FALSE, /* partial_inplace */
662 0xffffffff, /* src_mask */
663 0xffffffff, /* dst_mask */
664 FALSE), /* pcrel_offset */
666 HOWTO (R_ARM_TARGET2, /* type */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
670 FALSE, /* pc_relative */
672 complain_overflow_signed,/* complain_on_overflow */
673 bfd_elf_generic_reloc, /* special_function */
674 "R_ARM_TARGET2", /* name */
675 FALSE, /* partial_inplace */
676 0xffffffff, /* src_mask */
677 0xffffffff, /* dst_mask */
678 TRUE), /* pcrel_offset */
680 HOWTO (R_ARM_PREL31, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 TRUE, /* pc_relative */
686 complain_overflow_signed,/* complain_on_overflow */
687 bfd_elf_generic_reloc, /* special_function */
688 "R_ARM_PREL31", /* name */
689 FALSE, /* partial_inplace */
690 0x7fffffff, /* src_mask */
691 0x7fffffff, /* dst_mask */
692 TRUE), /* pcrel_offset */
694 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 FALSE, /* pc_relative */
700 complain_overflow_dont,/* complain_on_overflow */
701 bfd_elf_generic_reloc, /* special_function */
702 "R_ARM_MOVW_ABS_NC", /* name */
703 FALSE, /* partial_inplace */
704 0x000f0fff, /* src_mask */
705 0x000f0fff, /* dst_mask */
706 FALSE), /* pcrel_offset */
708 HOWTO (R_ARM_MOVT_ABS, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 FALSE, /* pc_relative */
714 complain_overflow_bitfield,/* complain_on_overflow */
715 bfd_elf_generic_reloc, /* special_function */
716 "R_ARM_MOVT_ABS", /* name */
717 FALSE, /* partial_inplace */
718 0x000f0fff, /* src_mask */
719 0x000f0fff, /* dst_mask */
720 FALSE), /* pcrel_offset */
722 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 TRUE, /* pc_relative */
728 complain_overflow_dont,/* complain_on_overflow */
729 bfd_elf_generic_reloc, /* special_function */
730 "R_ARM_MOVW_PREL_NC", /* name */
731 FALSE, /* partial_inplace */
732 0x000f0fff, /* src_mask */
733 0x000f0fff, /* dst_mask */
734 TRUE), /* pcrel_offset */
736 HOWTO (R_ARM_MOVT_PREL, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 TRUE, /* pc_relative */
742 complain_overflow_bitfield,/* complain_on_overflow */
743 bfd_elf_generic_reloc, /* special_function */
744 "R_ARM_MOVT_PREL", /* name */
745 FALSE, /* partial_inplace */
746 0x000f0fff, /* src_mask */
747 0x000f0fff, /* dst_mask */
748 TRUE), /* pcrel_offset */
750 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE, /* pc_relative */
756 complain_overflow_dont,/* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_ARM_THM_MOVW_ABS_NC",/* name */
759 FALSE, /* partial_inplace */
760 0x040f70ff, /* src_mask */
761 0x040f70ff, /* dst_mask */
762 FALSE), /* pcrel_offset */
764 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE, /* pc_relative */
770 complain_overflow_bitfield,/* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 "R_ARM_THM_MOVT_ABS", /* name */
773 FALSE, /* partial_inplace */
774 0x040f70ff, /* src_mask */
775 0x040f70ff, /* dst_mask */
776 FALSE), /* pcrel_offset */
778 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 TRUE, /* pc_relative */
784 complain_overflow_dont,/* complain_on_overflow */
785 bfd_elf_generic_reloc, /* special_function */
786 "R_ARM_THM_MOVW_PREL_NC",/* name */
787 FALSE, /* partial_inplace */
788 0x040f70ff, /* src_mask */
789 0x040f70ff, /* dst_mask */
790 TRUE), /* pcrel_offset */
792 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
794 2, /* size (0 = byte, 1 = short, 2 = long) */
796 TRUE, /* pc_relative */
798 complain_overflow_bitfield,/* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_ARM_THM_MOVT_PREL", /* name */
801 FALSE, /* partial_inplace */
802 0x040f70ff, /* src_mask */
803 0x040f70ff, /* dst_mask */
804 TRUE), /* pcrel_offset */
806 HOWTO (R_ARM_THM_JUMP19, /* type */
808 2, /* size (0 = byte, 1 = short, 2 = long) */
810 TRUE, /* pc_relative */
812 complain_overflow_signed,/* complain_on_overflow */
813 bfd_elf_generic_reloc, /* special_function */
814 "R_ARM_THM_JUMP19", /* name */
815 FALSE, /* partial_inplace */
816 0x043f2fff, /* src_mask */
817 0x043f2fff, /* dst_mask */
818 TRUE), /* pcrel_offset */
820 HOWTO (R_ARM_THM_JUMP6, /* type */
822 1, /* size (0 = byte, 1 = short, 2 = long) */
824 TRUE, /* pc_relative */
826 complain_overflow_unsigned,/* complain_on_overflow */
827 bfd_elf_generic_reloc, /* special_function */
828 "R_ARM_THM_JUMP6", /* name */
829 FALSE, /* partial_inplace */
830 0x02f8, /* src_mask */
831 0x02f8, /* dst_mask */
832 TRUE), /* pcrel_offset */
834 /* These are declared as 13-bit signed relocations because we can
835 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
837 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 TRUE, /* pc_relative */
843 complain_overflow_dont,/* complain_on_overflow */
844 bfd_elf_generic_reloc, /* special_function */
845 "R_ARM_THM_ALU_PREL_11_0",/* name */
846 FALSE, /* partial_inplace */
847 0xffffffff, /* src_mask */
848 0xffffffff, /* dst_mask */
849 TRUE), /* pcrel_offset */
851 HOWTO (R_ARM_THM_PC12, /* type */
853 2, /* size (0 = byte, 1 = short, 2 = long) */
855 TRUE, /* pc_relative */
857 complain_overflow_dont,/* complain_on_overflow */
858 bfd_elf_generic_reloc, /* special_function */
859 "R_ARM_THM_PC12", /* name */
860 FALSE, /* partial_inplace */
861 0xffffffff, /* src_mask */
862 0xffffffff, /* dst_mask */
863 TRUE), /* pcrel_offset */
865 HOWTO (R_ARM_ABS32_NOI, /* type */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE, /* pc_relative */
871 complain_overflow_dont,/* complain_on_overflow */
872 bfd_elf_generic_reloc, /* special_function */
873 "R_ARM_ABS32_NOI", /* name */
874 FALSE, /* partial_inplace */
875 0xffffffff, /* src_mask */
876 0xffffffff, /* dst_mask */
877 FALSE), /* pcrel_offset */
879 HOWTO (R_ARM_REL32_NOI, /* type */
881 2, /* size (0 = byte, 1 = short, 2 = long) */
883 TRUE, /* pc_relative */
885 complain_overflow_dont,/* complain_on_overflow */
886 bfd_elf_generic_reloc, /* special_function */
887 "R_ARM_REL32_NOI", /* name */
888 FALSE, /* partial_inplace */
889 0xffffffff, /* src_mask */
890 0xffffffff, /* dst_mask */
891 FALSE), /* pcrel_offset */
893 /* Group relocations. */
895 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 TRUE, /* pc_relative */
901 complain_overflow_dont,/* complain_on_overflow */
902 bfd_elf_generic_reloc, /* special_function */
903 "R_ARM_ALU_PC_G0_NC", /* name */
904 FALSE, /* partial_inplace */
905 0xffffffff, /* src_mask */
906 0xffffffff, /* dst_mask */
907 TRUE), /* pcrel_offset */
909 HOWTO (R_ARM_ALU_PC_G0, /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 TRUE, /* pc_relative */
915 complain_overflow_dont,/* complain_on_overflow */
916 bfd_elf_generic_reloc, /* special_function */
917 "R_ARM_ALU_PC_G0", /* name */
918 FALSE, /* partial_inplace */
919 0xffffffff, /* src_mask */
920 0xffffffff, /* dst_mask */
921 TRUE), /* pcrel_offset */
923 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
925 2, /* size (0 = byte, 1 = short, 2 = long) */
927 TRUE, /* pc_relative */
929 complain_overflow_dont,/* complain_on_overflow */
930 bfd_elf_generic_reloc, /* special_function */
931 "R_ARM_ALU_PC_G1_NC", /* name */
932 FALSE, /* partial_inplace */
933 0xffffffff, /* src_mask */
934 0xffffffff, /* dst_mask */
935 TRUE), /* pcrel_offset */
937 HOWTO (R_ARM_ALU_PC_G1, /* type */
939 2, /* size (0 = byte, 1 = short, 2 = long) */
941 TRUE, /* pc_relative */
943 complain_overflow_dont,/* complain_on_overflow */
944 bfd_elf_generic_reloc, /* special_function */
945 "R_ARM_ALU_PC_G1", /* name */
946 FALSE, /* partial_inplace */
947 0xffffffff, /* src_mask */
948 0xffffffff, /* dst_mask */
949 TRUE), /* pcrel_offset */
951 HOWTO (R_ARM_ALU_PC_G2, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 TRUE, /* pc_relative */
957 complain_overflow_dont,/* complain_on_overflow */
958 bfd_elf_generic_reloc, /* special_function */
959 "R_ARM_ALU_PC_G2", /* name */
960 FALSE, /* partial_inplace */
961 0xffffffff, /* src_mask */
962 0xffffffff, /* dst_mask */
963 TRUE), /* pcrel_offset */
965 HOWTO (R_ARM_LDR_PC_G1, /* type */
967 2, /* size (0 = byte, 1 = short, 2 = long) */
969 TRUE, /* pc_relative */
971 complain_overflow_dont,/* complain_on_overflow */
972 bfd_elf_generic_reloc, /* special_function */
973 "R_ARM_LDR_PC_G1", /* name */
974 FALSE, /* partial_inplace */
975 0xffffffff, /* src_mask */
976 0xffffffff, /* dst_mask */
977 TRUE), /* pcrel_offset */
979 HOWTO (R_ARM_LDR_PC_G2, /* type */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 TRUE, /* pc_relative */
985 complain_overflow_dont,/* complain_on_overflow */
986 bfd_elf_generic_reloc, /* special_function */
987 "R_ARM_LDR_PC_G2", /* name */
988 FALSE, /* partial_inplace */
989 0xffffffff, /* src_mask */
990 0xffffffff, /* dst_mask */
991 TRUE), /* pcrel_offset */
993 HOWTO (R_ARM_LDRS_PC_G0, /* type */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 TRUE, /* pc_relative */
999 complain_overflow_dont,/* complain_on_overflow */
1000 bfd_elf_generic_reloc, /* special_function */
1001 "R_ARM_LDRS_PC_G0", /* name */
1002 FALSE, /* partial_inplace */
1003 0xffffffff, /* src_mask */
1004 0xffffffff, /* dst_mask */
1005 TRUE), /* pcrel_offset */
1007 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1009 2, /* size (0 = byte, 1 = short, 2 = long) */
1011 TRUE, /* pc_relative */
1013 complain_overflow_dont,/* complain_on_overflow */
1014 bfd_elf_generic_reloc, /* special_function */
1015 "R_ARM_LDRS_PC_G1", /* name */
1016 FALSE, /* partial_inplace */
1017 0xffffffff, /* src_mask */
1018 0xffffffff, /* dst_mask */
1019 TRUE), /* pcrel_offset */
1021 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1023 2, /* size (0 = byte, 1 = short, 2 = long) */
1025 TRUE, /* pc_relative */
1027 complain_overflow_dont,/* complain_on_overflow */
1028 bfd_elf_generic_reloc, /* special_function */
1029 "R_ARM_LDRS_PC_G2", /* name */
1030 FALSE, /* partial_inplace */
1031 0xffffffff, /* src_mask */
1032 0xffffffff, /* dst_mask */
1033 TRUE), /* pcrel_offset */
1035 HOWTO (R_ARM_LDC_PC_G0, /* type */
1037 2, /* size (0 = byte, 1 = short, 2 = long) */
1039 TRUE, /* pc_relative */
1041 complain_overflow_dont,/* complain_on_overflow */
1042 bfd_elf_generic_reloc, /* special_function */
1043 "R_ARM_LDC_PC_G0", /* name */
1044 FALSE, /* partial_inplace */
1045 0xffffffff, /* src_mask */
1046 0xffffffff, /* dst_mask */
1047 TRUE), /* pcrel_offset */
1049 HOWTO (R_ARM_LDC_PC_G1, /* type */
1051 2, /* size (0 = byte, 1 = short, 2 = long) */
1053 TRUE, /* pc_relative */
1055 complain_overflow_dont,/* complain_on_overflow */
1056 bfd_elf_generic_reloc, /* special_function */
1057 "R_ARM_LDC_PC_G1", /* name */
1058 FALSE, /* partial_inplace */
1059 0xffffffff, /* src_mask */
1060 0xffffffff, /* dst_mask */
1061 TRUE), /* pcrel_offset */
1063 HOWTO (R_ARM_LDC_PC_G2, /* type */
1065 2, /* size (0 = byte, 1 = short, 2 = long) */
1067 TRUE, /* pc_relative */
1069 complain_overflow_dont,/* complain_on_overflow */
1070 bfd_elf_generic_reloc, /* special_function */
1071 "R_ARM_LDC_PC_G2", /* name */
1072 FALSE, /* partial_inplace */
1073 0xffffffff, /* src_mask */
1074 0xffffffff, /* dst_mask */
1075 TRUE), /* pcrel_offset */
1077 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 TRUE, /* pc_relative */
1083 complain_overflow_dont,/* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 "R_ARM_ALU_SB_G0_NC", /* name */
1086 FALSE, /* partial_inplace */
1087 0xffffffff, /* src_mask */
1088 0xffffffff, /* dst_mask */
1089 TRUE), /* pcrel_offset */
1091 HOWTO (R_ARM_ALU_SB_G0, /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 TRUE, /* pc_relative */
1097 complain_overflow_dont,/* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 "R_ARM_ALU_SB_G0", /* name */
1100 FALSE, /* partial_inplace */
1101 0xffffffff, /* src_mask */
1102 0xffffffff, /* dst_mask */
1103 TRUE), /* pcrel_offset */
1105 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 TRUE, /* pc_relative */
1111 complain_overflow_dont,/* complain_on_overflow */
1112 bfd_elf_generic_reloc, /* special_function */
1113 "R_ARM_ALU_SB_G1_NC", /* name */
1114 FALSE, /* partial_inplace */
1115 0xffffffff, /* src_mask */
1116 0xffffffff, /* dst_mask */
1117 TRUE), /* pcrel_offset */
1119 HOWTO (R_ARM_ALU_SB_G1, /* type */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 TRUE, /* pc_relative */
1125 complain_overflow_dont,/* complain_on_overflow */
1126 bfd_elf_generic_reloc, /* special_function */
1127 "R_ARM_ALU_SB_G1", /* name */
1128 FALSE, /* partial_inplace */
1129 0xffffffff, /* src_mask */
1130 0xffffffff, /* dst_mask */
1131 TRUE), /* pcrel_offset */
1133 HOWTO (R_ARM_ALU_SB_G2, /* type */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 TRUE, /* pc_relative */
1139 complain_overflow_dont,/* complain_on_overflow */
1140 bfd_elf_generic_reloc, /* special_function */
1141 "R_ARM_ALU_SB_G2", /* name */
1142 FALSE, /* partial_inplace */
1143 0xffffffff, /* src_mask */
1144 0xffffffff, /* dst_mask */
1145 TRUE), /* pcrel_offset */
1147 HOWTO (R_ARM_LDR_SB_G0, /* type */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 TRUE, /* pc_relative */
1153 complain_overflow_dont,/* complain_on_overflow */
1154 bfd_elf_generic_reloc, /* special_function */
1155 "R_ARM_LDR_SB_G0", /* name */
1156 FALSE, /* partial_inplace */
1157 0xffffffff, /* src_mask */
1158 0xffffffff, /* dst_mask */
1159 TRUE), /* pcrel_offset */
1161 HOWTO (R_ARM_LDR_SB_G1, /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 TRUE, /* pc_relative */
1167 complain_overflow_dont,/* complain_on_overflow */
1168 bfd_elf_generic_reloc, /* special_function */
1169 "R_ARM_LDR_SB_G1", /* name */
1170 FALSE, /* partial_inplace */
1171 0xffffffff, /* src_mask */
1172 0xffffffff, /* dst_mask */
1173 TRUE), /* pcrel_offset */
1175 HOWTO (R_ARM_LDR_SB_G2, /* type */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 TRUE, /* pc_relative */
1181 complain_overflow_dont,/* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 "R_ARM_LDR_SB_G2", /* name */
1184 FALSE, /* partial_inplace */
1185 0xffffffff, /* src_mask */
1186 0xffffffff, /* dst_mask */
1187 TRUE), /* pcrel_offset */
1189 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1193 TRUE, /* pc_relative */
1195 complain_overflow_dont,/* complain_on_overflow */
1196 bfd_elf_generic_reloc, /* special_function */
1197 "R_ARM_LDRS_SB_G0", /* name */
1198 FALSE, /* partial_inplace */
1199 0xffffffff, /* src_mask */
1200 0xffffffff, /* dst_mask */
1201 TRUE), /* pcrel_offset */
1203 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 TRUE, /* pc_relative */
1209 complain_overflow_dont,/* complain_on_overflow */
1210 bfd_elf_generic_reloc, /* special_function */
1211 "R_ARM_LDRS_SB_G1", /* name */
1212 FALSE, /* partial_inplace */
1213 0xffffffff, /* src_mask */
1214 0xffffffff, /* dst_mask */
1215 TRUE), /* pcrel_offset */
1217 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1219 2, /* size (0 = byte, 1 = short, 2 = long) */
1221 TRUE, /* pc_relative */
1223 complain_overflow_dont,/* complain_on_overflow */
1224 bfd_elf_generic_reloc, /* special_function */
1225 "R_ARM_LDRS_SB_G2", /* name */
1226 FALSE, /* partial_inplace */
1227 0xffffffff, /* src_mask */
1228 0xffffffff, /* dst_mask */
1229 TRUE), /* pcrel_offset */
1231 HOWTO (R_ARM_LDC_SB_G0, /* type */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 TRUE, /* pc_relative */
1237 complain_overflow_dont,/* complain_on_overflow */
1238 bfd_elf_generic_reloc, /* special_function */
1239 "R_ARM_LDC_SB_G0", /* name */
1240 FALSE, /* partial_inplace */
1241 0xffffffff, /* src_mask */
1242 0xffffffff, /* dst_mask */
1243 TRUE), /* pcrel_offset */
1245 HOWTO (R_ARM_LDC_SB_G1, /* type */
1247 2, /* size (0 = byte, 1 = short, 2 = long) */
1249 TRUE, /* pc_relative */
1251 complain_overflow_dont,/* complain_on_overflow */
1252 bfd_elf_generic_reloc, /* special_function */
1253 "R_ARM_LDC_SB_G1", /* name */
1254 FALSE, /* partial_inplace */
1255 0xffffffff, /* src_mask */
1256 0xffffffff, /* dst_mask */
1257 TRUE), /* pcrel_offset */
1259 HOWTO (R_ARM_LDC_SB_G2, /* type */
1261 2, /* size (0 = byte, 1 = short, 2 = long) */
1263 TRUE, /* pc_relative */
1265 complain_overflow_dont,/* complain_on_overflow */
1266 bfd_elf_generic_reloc, /* special_function */
1267 "R_ARM_LDC_SB_G2", /* name */
1268 FALSE, /* partial_inplace */
1269 0xffffffff, /* src_mask */
1270 0xffffffff, /* dst_mask */
1271 TRUE), /* pcrel_offset */
1273 /* End of group relocations. */
1275 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1277 2, /* size (0 = byte, 1 = short, 2 = long) */
1279 FALSE, /* pc_relative */
1281 complain_overflow_dont,/* complain_on_overflow */
1282 bfd_elf_generic_reloc, /* special_function */
1283 "R_ARM_MOVW_BREL_NC", /* name */
1284 FALSE, /* partial_inplace */
1285 0x0000ffff, /* src_mask */
1286 0x0000ffff, /* dst_mask */
1287 FALSE), /* pcrel_offset */
1289 HOWTO (R_ARM_MOVT_BREL, /* type */
1291 2, /* size (0 = byte, 1 = short, 2 = long) */
1293 FALSE, /* pc_relative */
1295 complain_overflow_bitfield,/* complain_on_overflow */
1296 bfd_elf_generic_reloc, /* special_function */
1297 "R_ARM_MOVT_BREL", /* name */
1298 FALSE, /* partial_inplace */
1299 0x0000ffff, /* src_mask */
1300 0x0000ffff, /* dst_mask */
1301 FALSE), /* pcrel_offset */
1303 HOWTO (R_ARM_MOVW_BREL, /* type */
1305 2, /* size (0 = byte, 1 = short, 2 = long) */
1307 FALSE, /* pc_relative */
1309 complain_overflow_dont,/* complain_on_overflow */
1310 bfd_elf_generic_reloc, /* special_function */
1311 "R_ARM_MOVW_BREL", /* name */
1312 FALSE, /* partial_inplace */
1313 0x0000ffff, /* src_mask */
1314 0x0000ffff, /* dst_mask */
1315 FALSE), /* pcrel_offset */
1317 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1319 2, /* size (0 = byte, 1 = short, 2 = long) */
1321 FALSE, /* pc_relative */
1323 complain_overflow_dont,/* complain_on_overflow */
1324 bfd_elf_generic_reloc, /* special_function */
1325 "R_ARM_THM_MOVW_BREL_NC",/* name */
1326 FALSE, /* partial_inplace */
1327 0x040f70ff, /* src_mask */
1328 0x040f70ff, /* dst_mask */
1329 FALSE), /* pcrel_offset */
1331 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1333 2, /* size (0 = byte, 1 = short, 2 = long) */
1335 FALSE, /* pc_relative */
1337 complain_overflow_bitfield,/* complain_on_overflow */
1338 bfd_elf_generic_reloc, /* special_function */
1339 "R_ARM_THM_MOVT_BREL", /* name */
1340 FALSE, /* partial_inplace */
1341 0x040f70ff, /* src_mask */
1342 0x040f70ff, /* dst_mask */
1343 FALSE), /* pcrel_offset */
1345 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1347 2, /* size (0 = byte, 1 = short, 2 = long) */
1349 FALSE, /* pc_relative */
1351 complain_overflow_dont,/* complain_on_overflow */
1352 bfd_elf_generic_reloc, /* special_function */
1353 "R_ARM_THM_MOVW_BREL", /* name */
1354 FALSE, /* partial_inplace */
1355 0x040f70ff, /* src_mask */
1356 0x040f70ff, /* dst_mask */
1357 FALSE), /* pcrel_offset */
1359 HOWTO (R_ARM_TLS_GOTDESC, /* type */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE, /* pc_relative */
1365 complain_overflow_bitfield,/* complain_on_overflow */
1366 NULL, /* special_function */
1367 "R_ARM_TLS_GOTDESC", /* name */
1368 TRUE, /* partial_inplace */
1369 0xffffffff, /* src_mask */
1370 0xffffffff, /* dst_mask */
1371 FALSE), /* pcrel_offset */
1373 HOWTO (R_ARM_TLS_CALL, /* type */
1375 2, /* size (0 = byte, 1 = short, 2 = long) */
1377 FALSE, /* pc_relative */
1379 complain_overflow_dont,/* complain_on_overflow */
1380 bfd_elf_generic_reloc, /* special_function */
1381 "R_ARM_TLS_CALL", /* name */
1382 FALSE, /* partial_inplace */
1383 0x00ffffff, /* src_mask */
1384 0x00ffffff, /* dst_mask */
1385 FALSE), /* pcrel_offset */
1387 HOWTO (R_ARM_TLS_DESCSEQ, /* type */
1389 2, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE, /* pc_relative */
1393 complain_overflow_bitfield,/* complain_on_overflow */
1394 bfd_elf_generic_reloc, /* special_function */
1395 "R_ARM_TLS_DESCSEQ", /* name */
1396 FALSE, /* partial_inplace */
1397 0x00000000, /* src_mask */
1398 0x00000000, /* dst_mask */
1399 FALSE), /* pcrel_offset */
1401 HOWTO (R_ARM_THM_TLS_CALL, /* type */
1403 2, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE, /* pc_relative */
1407 complain_overflow_dont,/* complain_on_overflow */
1408 bfd_elf_generic_reloc, /* special_function */
1409 "R_ARM_THM_TLS_CALL", /* name */
1410 FALSE, /* partial_inplace */
1411 0x07ff07ff, /* src_mask */
1412 0x07ff07ff, /* dst_mask */
1413 FALSE), /* pcrel_offset */
1415 HOWTO (R_ARM_PLT32_ABS, /* type */
1417 2, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE, /* pc_relative */
1421 complain_overflow_dont,/* complain_on_overflow */
1422 bfd_elf_generic_reloc, /* special_function */
1423 "R_ARM_PLT32_ABS", /* name */
1424 FALSE, /* partial_inplace */
1425 0xffffffff, /* src_mask */
1426 0xffffffff, /* dst_mask */
1427 FALSE), /* pcrel_offset */
1429 HOWTO (R_ARM_GOT_ABS, /* type */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE, /* pc_relative */
1435 complain_overflow_dont,/* complain_on_overflow */
1436 bfd_elf_generic_reloc, /* special_function */
1437 "R_ARM_GOT_ABS", /* name */
1438 FALSE, /* partial_inplace */
1439 0xffffffff, /* src_mask */
1440 0xffffffff, /* dst_mask */
1441 FALSE), /* pcrel_offset */
1443 HOWTO (R_ARM_GOT_PREL, /* type */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 TRUE, /* pc_relative */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 bfd_elf_generic_reloc, /* special_function */
1451 "R_ARM_GOT_PREL", /* name */
1452 FALSE, /* partial_inplace */
1453 0xffffffff, /* src_mask */
1454 0xffffffff, /* dst_mask */
1455 TRUE), /* pcrel_offset */
1457 HOWTO (R_ARM_GOT_BREL12, /* type */
1459 2, /* size (0 = byte, 1 = short, 2 = long) */
1461 FALSE, /* pc_relative */
1463 complain_overflow_bitfield,/* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_GOT_BREL12", /* name */
1466 FALSE, /* partial_inplace */
1467 0x00000fff, /* src_mask */
1468 0x00000fff, /* dst_mask */
1469 FALSE), /* pcrel_offset */
1471 HOWTO (R_ARM_GOTOFF12, /* type */
1473 2, /* size (0 = byte, 1 = short, 2 = long) */
1475 FALSE, /* pc_relative */
1477 complain_overflow_bitfield,/* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_GOTOFF12", /* name */
1480 FALSE, /* partial_inplace */
1481 0x00000fff, /* src_mask */
1482 0x00000fff, /* dst_mask */
1483 FALSE), /* pcrel_offset */
1485 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1487 /* GNU extension to record C++ vtable member usage */
1488 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1490 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 FALSE, /* pc_relative */
1494 complain_overflow_dont, /* complain_on_overflow */
1495 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1496 "R_ARM_GNU_VTENTRY", /* name */
1497 FALSE, /* partial_inplace */
1500 FALSE), /* pcrel_offset */
1502 /* GNU extension to record C++ vtable hierarchy */
1503 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1505 2, /* size (0 = byte, 1 = short, 2 = long) */
1507 FALSE, /* pc_relative */
1509 complain_overflow_dont, /* complain_on_overflow */
1510 NULL, /* special_function */
1511 "R_ARM_GNU_VTINHERIT", /* name */
1512 FALSE, /* partial_inplace */
1515 FALSE), /* pcrel_offset */
1517 HOWTO (R_ARM_THM_JUMP11, /* type */
1519 1, /* size (0 = byte, 1 = short, 2 = long) */
1521 TRUE, /* pc_relative */
1523 complain_overflow_signed, /* complain_on_overflow */
1524 bfd_elf_generic_reloc, /* special_function */
1525 "R_ARM_THM_JUMP11", /* name */
1526 FALSE, /* partial_inplace */
1527 0x000007ff, /* src_mask */
1528 0x000007ff, /* dst_mask */
1529 TRUE), /* pcrel_offset */
1531 HOWTO (R_ARM_THM_JUMP8, /* type */
1533 1, /* size (0 = byte, 1 = short, 2 = long) */
1535 TRUE, /* pc_relative */
1537 complain_overflow_signed, /* complain_on_overflow */
1538 bfd_elf_generic_reloc, /* special_function */
1539 "R_ARM_THM_JUMP8", /* name */
1540 FALSE, /* partial_inplace */
1541 0x000000ff, /* src_mask */
1542 0x000000ff, /* dst_mask */
1543 TRUE), /* pcrel_offset */
1545 /* TLS relocations */
1546 HOWTO (R_ARM_TLS_GD32, /* type */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1550 FALSE, /* pc_relative */
1552 complain_overflow_bitfield,/* complain_on_overflow */
1553 NULL, /* special_function */
1554 "R_ARM_TLS_GD32", /* name */
1555 TRUE, /* partial_inplace */
1556 0xffffffff, /* src_mask */
1557 0xffffffff, /* dst_mask */
1558 FALSE), /* pcrel_offset */
1560 HOWTO (R_ARM_TLS_LDM32, /* type */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE, /* pc_relative */
1566 complain_overflow_bitfield,/* complain_on_overflow */
1567 bfd_elf_generic_reloc, /* special_function */
1568 "R_ARM_TLS_LDM32", /* name */
1569 TRUE, /* partial_inplace */
1570 0xffffffff, /* src_mask */
1571 0xffffffff, /* dst_mask */
1572 FALSE), /* pcrel_offset */
1574 HOWTO (R_ARM_TLS_LDO32, /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE, /* pc_relative */
1580 complain_overflow_bitfield,/* complain_on_overflow */
1581 bfd_elf_generic_reloc, /* special_function */
1582 "R_ARM_TLS_LDO32", /* name */
1583 TRUE, /* partial_inplace */
1584 0xffffffff, /* src_mask */
1585 0xffffffff, /* dst_mask */
1586 FALSE), /* pcrel_offset */
1588 HOWTO (R_ARM_TLS_IE32, /* type */
1590 2, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE, /* pc_relative */
1594 complain_overflow_bitfield,/* complain_on_overflow */
1595 NULL, /* special_function */
1596 "R_ARM_TLS_IE32", /* name */
1597 TRUE, /* partial_inplace */
1598 0xffffffff, /* src_mask */
1599 0xffffffff, /* dst_mask */
1600 FALSE), /* pcrel_offset */
1602 HOWTO (R_ARM_TLS_LE32, /* type */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE, /* pc_relative */
1608 complain_overflow_bitfield,/* complain_on_overflow */
1609 NULL, /* special_function */
1610 "R_ARM_TLS_LE32", /* name */
1611 TRUE, /* partial_inplace */
1612 0xffffffff, /* src_mask */
1613 0xffffffff, /* dst_mask */
1614 FALSE), /* pcrel_offset */
1616 HOWTO (R_ARM_TLS_LDO12, /* type */
1618 2, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE, /* pc_relative */
1622 complain_overflow_bitfield,/* complain_on_overflow */
1623 bfd_elf_generic_reloc, /* special_function */
1624 "R_ARM_TLS_LDO12", /* name */
1625 FALSE, /* partial_inplace */
1626 0x00000fff, /* src_mask */
1627 0x00000fff, /* dst_mask */
1628 FALSE), /* pcrel_offset */
1630 HOWTO (R_ARM_TLS_LE12, /* type */
1632 2, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE, /* pc_relative */
1636 complain_overflow_bitfield,/* complain_on_overflow */
1637 bfd_elf_generic_reloc, /* special_function */
1638 "R_ARM_TLS_LE12", /* name */
1639 FALSE, /* partial_inplace */
1640 0x00000fff, /* src_mask */
1641 0x00000fff, /* dst_mask */
1642 FALSE), /* pcrel_offset */
1644 HOWTO (R_ARM_TLS_IE12GP, /* type */
1646 2, /* size (0 = byte, 1 = short, 2 = long) */
1648 FALSE, /* pc_relative */
1650 complain_overflow_bitfield,/* complain_on_overflow */
1651 bfd_elf_generic_reloc, /* special_function */
1652 "R_ARM_TLS_IE12GP", /* name */
1653 FALSE, /* partial_inplace */
1654 0x00000fff, /* src_mask */
1655 0x00000fff, /* dst_mask */
1656 FALSE), /* pcrel_offset */
1658 /* 112-127 private relocations. */
1676 /* R_ARM_ME_TOO, obsolete. */
1679 HOWTO (R_ARM_THM_TLS_DESCSEQ, /* type */
1681 1, /* size (0 = byte, 1 = short, 2 = long) */
1683 FALSE, /* pc_relative */
1685 complain_overflow_bitfield,/* complain_on_overflow */
1686 bfd_elf_generic_reloc, /* special_function */
1687 "R_ARM_THM_TLS_DESCSEQ",/* name */
1688 FALSE, /* partial_inplace */
1689 0x00000000, /* src_mask */
1690 0x00000000, /* dst_mask */
1691 FALSE), /* pcrel_offset */
1694 HOWTO (R_ARM_THM_ALU_ABS_G0_NC,/* type. */
1695 0, /* rightshift. */
1696 1, /* size (0 = byte, 1 = short, 2 = long). */
1698 FALSE, /* pc_relative. */
1700 complain_overflow_bitfield,/* complain_on_overflow. */
1701 bfd_elf_generic_reloc, /* special_function. */
1702 "R_ARM_THM_ALU_ABS_G0_NC",/* name. */
1703 FALSE, /* partial_inplace. */
1704 0x00000000, /* src_mask. */
1705 0x00000000, /* dst_mask. */
1706 FALSE), /* pcrel_offset. */
1707 HOWTO (R_ARM_THM_ALU_ABS_G1_NC,/* type. */
1708 0, /* rightshift. */
1709 1, /* size (0 = byte, 1 = short, 2 = long). */
1711 FALSE, /* pc_relative. */
1713 complain_overflow_bitfield,/* complain_on_overflow. */
1714 bfd_elf_generic_reloc, /* special_function. */
1715 "R_ARM_THM_ALU_ABS_G1_NC",/* name. */
1716 FALSE, /* partial_inplace. */
1717 0x00000000, /* src_mask. */
1718 0x00000000, /* dst_mask. */
1719 FALSE), /* pcrel_offset. */
1720 HOWTO (R_ARM_THM_ALU_ABS_G2_NC,/* type. */
1721 0, /* rightshift. */
1722 1, /* size (0 = byte, 1 = short, 2 = long). */
1724 FALSE, /* pc_relative. */
1726 complain_overflow_bitfield,/* complain_on_overflow. */
1727 bfd_elf_generic_reloc, /* special_function. */
1728 "R_ARM_THM_ALU_ABS_G2_NC",/* name. */
1729 FALSE, /* partial_inplace. */
1730 0x00000000, /* src_mask. */
1731 0x00000000, /* dst_mask. */
1732 FALSE), /* pcrel_offset. */
1733 HOWTO (R_ARM_THM_ALU_ABS_G3_NC,/* type. */
1734 0, /* rightshift. */
1735 1, /* size (0 = byte, 1 = short, 2 = long). */
1737 FALSE, /* pc_relative. */
1739 complain_overflow_bitfield,/* complain_on_overflow. */
1740 bfd_elf_generic_reloc, /* special_function. */
1741 "R_ARM_THM_ALU_ABS_G3_NC",/* name. */
1742 FALSE, /* partial_inplace. */
1743 0x00000000, /* src_mask. */
1744 0x00000000, /* dst_mask. */
1745 FALSE), /* pcrel_offset. */
1749 static reloc_howto_type elf32_arm_howto_table_2[1] =
1751 HOWTO (R_ARM_IRELATIVE, /* type */
1753 2, /* size (0 = byte, 1 = short, 2 = long) */
1755 FALSE, /* pc_relative */
1757 complain_overflow_bitfield,/* complain_on_overflow */
1758 bfd_elf_generic_reloc, /* special_function */
1759 "R_ARM_IRELATIVE", /* name */
1760 TRUE, /* partial_inplace */
1761 0xffffffff, /* src_mask */
1762 0xffffffff, /* dst_mask */
1763 FALSE) /* pcrel_offset */
1766 /* 249-255 extended, currently unused, relocations: */
1767 static reloc_howto_type elf32_arm_howto_table_3[4] =
1769 HOWTO (R_ARM_RREL32, /* type */
1771 0, /* size (0 = byte, 1 = short, 2 = long) */
1773 FALSE, /* pc_relative */
1775 complain_overflow_dont,/* complain_on_overflow */
1776 bfd_elf_generic_reloc, /* special_function */
1777 "R_ARM_RREL32", /* name */
1778 FALSE, /* partial_inplace */
1781 FALSE), /* pcrel_offset */
1783 HOWTO (R_ARM_RABS32, /* type */
1785 0, /* size (0 = byte, 1 = short, 2 = long) */
1787 FALSE, /* pc_relative */
1789 complain_overflow_dont,/* complain_on_overflow */
1790 bfd_elf_generic_reloc, /* special_function */
1791 "R_ARM_RABS32", /* name */
1792 FALSE, /* partial_inplace */
1795 FALSE), /* pcrel_offset */
1797 HOWTO (R_ARM_RPC24, /* type */
1799 0, /* size (0 = byte, 1 = short, 2 = long) */
1801 FALSE, /* pc_relative */
1803 complain_overflow_dont,/* complain_on_overflow */
1804 bfd_elf_generic_reloc, /* special_function */
1805 "R_ARM_RPC24", /* name */
1806 FALSE, /* partial_inplace */
1809 FALSE), /* pcrel_offset */
1811 HOWTO (R_ARM_RBASE, /* type */
1813 0, /* size (0 = byte, 1 = short, 2 = long) */
1815 FALSE, /* pc_relative */
1817 complain_overflow_dont,/* complain_on_overflow */
1818 bfd_elf_generic_reloc, /* special_function */
1819 "R_ARM_RBASE", /* name */
1820 FALSE, /* partial_inplace */
1823 FALSE) /* pcrel_offset */
1826 static reloc_howto_type *
1827 elf32_arm_howto_from_type (unsigned int r_type)
1829 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1830 return &elf32_arm_howto_table_1[r_type];
1832 if (r_type == R_ARM_IRELATIVE)
1833 return &elf32_arm_howto_table_2[r_type - R_ARM_IRELATIVE];
1835 if (r_type >= R_ARM_RREL32
1836 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_3))
1837 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32];
1843 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1844 Elf_Internal_Rela * elf_reloc)
1846 unsigned int r_type;
1848 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1849 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1852 struct elf32_arm_reloc_map
1854 bfd_reloc_code_real_type bfd_reloc_val;
1855 unsigned char elf_reloc_val;
1858 /* All entries in this list must also be present in elf32_arm_howto_table. */
1859 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1861 {BFD_RELOC_NONE, R_ARM_NONE},
1862 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1863 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1864 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1865 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1866 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1867 {BFD_RELOC_32, R_ARM_ABS32},
1868 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1869 {BFD_RELOC_8, R_ARM_ABS8},
1870 {BFD_RELOC_16, R_ARM_ABS16},
1871 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1872 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1873 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1874 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1875 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1876 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1877 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1878 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1879 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1880 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1881 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1882 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1883 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1884 {BFD_RELOC_ARM_GOT_PREL, R_ARM_GOT_PREL},
1885 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1886 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1887 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1888 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1889 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1890 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1891 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1892 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1893 {BFD_RELOC_ARM_TLS_GOTDESC, R_ARM_TLS_GOTDESC},
1894 {BFD_RELOC_ARM_TLS_CALL, R_ARM_TLS_CALL},
1895 {BFD_RELOC_ARM_THM_TLS_CALL, R_ARM_THM_TLS_CALL},
1896 {BFD_RELOC_ARM_TLS_DESCSEQ, R_ARM_TLS_DESCSEQ},
1897 {BFD_RELOC_ARM_THM_TLS_DESCSEQ, R_ARM_THM_TLS_DESCSEQ},
1898 {BFD_RELOC_ARM_TLS_DESC, R_ARM_TLS_DESC},
1899 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1900 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1901 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1902 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1903 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1904 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1905 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1906 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1907 {BFD_RELOC_ARM_IRELATIVE, R_ARM_IRELATIVE},
1908 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1909 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1910 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1911 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1912 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1913 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1914 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1915 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1916 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1917 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1918 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1919 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1920 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1921 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1922 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1923 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1924 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1925 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1926 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1927 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1928 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1929 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1930 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1931 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1932 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1933 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1934 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1935 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1936 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1937 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1938 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1939 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1940 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1941 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1942 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1943 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1944 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1945 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1946 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX},
1947 {BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC, R_ARM_THM_ALU_ABS_G3_NC},
1948 {BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC, R_ARM_THM_ALU_ABS_G2_NC},
1949 {BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC, R_ARM_THM_ALU_ABS_G1_NC},
1950 {BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC, R_ARM_THM_ALU_ABS_G0_NC}
1953 static reloc_howto_type *
1954 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1955 bfd_reloc_code_real_type code)
1959 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
1960 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1961 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1966 static reloc_howto_type *
1967 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1972 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1973 if (elf32_arm_howto_table_1[i].name != NULL
1974 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1975 return &elf32_arm_howto_table_1[i];
1977 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1978 if (elf32_arm_howto_table_2[i].name != NULL
1979 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1980 return &elf32_arm_howto_table_2[i];
1982 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_3); i++)
1983 if (elf32_arm_howto_table_3[i].name != NULL
1984 && strcasecmp (elf32_arm_howto_table_3[i].name, r_name) == 0)
1985 return &elf32_arm_howto_table_3[i];
1990 /* Support for core dump NOTE sections. */
1993 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1998 switch (note->descsz)
2003 case 148: /* Linux/ARM 32-bit. */
2005 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2008 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
2017 /* Make a ".reg/999" section. */
2018 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2019 size, note->descpos + offset);
2023 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2025 switch (note->descsz)
2030 case 124: /* Linux/ARM elf_prpsinfo. */
2031 elf_tdata (abfd)->core->pid
2032 = bfd_get_32 (abfd, note->descdata + 12);
2033 elf_tdata (abfd)->core->program
2034 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
2035 elf_tdata (abfd)->core->command
2036 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
2039 /* Note that for some reason, a spurious space is tacked
2040 onto the end of the args in some (at least one anyway)
2041 implementations, so strip it off if it exists. */
2043 char *command = elf_tdata (abfd)->core->command;
2044 int n = strlen (command);
2046 if (0 < n && command[n - 1] == ' ')
2047 command[n - 1] = '\0';
2054 elf32_arm_nabi_write_core_note (bfd *abfd, char *buf, int *bufsiz,
2067 va_start (ap, note_type);
2068 memset (data, 0, sizeof (data));
2069 strncpy (data + 28, va_arg (ap, const char *), 16);
2070 strncpy (data + 44, va_arg (ap, const char *), 80);
2073 return elfcore_write_note (abfd, buf, bufsiz,
2074 "CORE", note_type, data, sizeof (data));
2085 va_start (ap, note_type);
2086 memset (data, 0, sizeof (data));
2087 pid = va_arg (ap, long);
2088 bfd_put_32 (abfd, pid, data + 24);
2089 cursig = va_arg (ap, int);
2090 bfd_put_16 (abfd, cursig, data + 12);
2091 greg = va_arg (ap, const void *);
2092 memcpy (data + 72, greg, 72);
2095 return elfcore_write_note (abfd, buf, bufsiz,
2096 "CORE", note_type, data, sizeof (data));
2101 #define TARGET_LITTLE_SYM arm_elf32_le_vec
2102 #define TARGET_LITTLE_NAME "elf32-littlearm"
2103 #define TARGET_BIG_SYM arm_elf32_be_vec
2104 #define TARGET_BIG_NAME "elf32-bigarm"
2106 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
2107 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
2108 #define elf_backend_write_core_note elf32_arm_nabi_write_core_note
2110 typedef unsigned long int insn32;
2111 typedef unsigned short int insn16;
2113 /* In lieu of proper flags, assume all EABIv4 or later objects are
2115 #define INTERWORK_FLAG(abfd) \
2116 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
2117 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
2118 || ((abfd)->flags & BFD_LINKER_CREATED))
2120 /* The linker script knows the section names for placement.
2121 The entry_names are used to do simple name mangling on the stubs.
2122 Given a function name, and its type, the stub can be found. The
2123 name can be changed. The only requirement is the %s be present. */
2124 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
2125 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
2127 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
2128 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
2130 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
2131 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
2133 #define STM32L4XX_ERRATUM_VENEER_SECTION_NAME ".text.stm32l4xx_veneer"
2134 #define STM32L4XX_ERRATUM_VENEER_ENTRY_NAME "__stm32l4xx_veneer_%x"
2136 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
2137 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
2139 #define STUB_ENTRY_NAME "__%s_veneer"
2141 /* The name of the dynamic interpreter. This is put in the .interp
2143 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
2145 static const unsigned long tls_trampoline [] =
2147 0xe08e0000, /* add r0, lr, r0 */
2148 0xe5901004, /* ldr r1, [r0,#4] */
2149 0xe12fff11, /* bx r1 */
2152 static const unsigned long dl_tlsdesc_lazy_trampoline [] =
2154 0xe52d2004, /* push {r2} */
2155 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */
2156 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */
2157 0xe79f2002, /* 1: ldr r2, [pc, r2] */
2158 0xe081100f, /* 2: add r1, pc */
2159 0xe12fff12, /* bx r2 */
2160 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8
2161 + dl_tlsdesc_lazy_resolver(GOT) */
2162 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */
2165 #ifdef FOUR_WORD_PLT
2167 /* The first entry in a procedure linkage table looks like
2168 this. It is set up so that any shared library function that is
2169 called before the relocation has been set up calls the dynamic
2171 static const bfd_vma elf32_arm_plt0_entry [] =
2173 0xe52de004, /* str lr, [sp, #-4]! */
2174 0xe59fe010, /* ldr lr, [pc, #16] */
2175 0xe08fe00e, /* add lr, pc, lr */
2176 0xe5bef008, /* ldr pc, [lr, #8]! */
2179 /* Subsequent entries in a procedure linkage table look like
2181 static const bfd_vma elf32_arm_plt_entry [] =
2183 0xe28fc600, /* add ip, pc, #NN */
2184 0xe28cca00, /* add ip, ip, #NN */
2185 0xe5bcf000, /* ldr pc, [ip, #NN]! */
2186 0x00000000, /* unused */
2189 #else /* not FOUR_WORD_PLT */
2191 /* The first entry in a procedure linkage table looks like
2192 this. It is set up so that any shared library function that is
2193 called before the relocation has been set up calls the dynamic
2195 static const bfd_vma elf32_arm_plt0_entry [] =
2197 0xe52de004, /* str lr, [sp, #-4]! */
2198 0xe59fe004, /* ldr lr, [pc, #4] */
2199 0xe08fe00e, /* add lr, pc, lr */
2200 0xe5bef008, /* ldr pc, [lr, #8]! */
2201 0x00000000, /* &GOT[0] - . */
2204 /* By default subsequent entries in a procedure linkage table look like
2205 this. Offsets that don't fit into 28 bits will cause link error. */
2206 static const bfd_vma elf32_arm_plt_entry_short [] =
2208 0xe28fc600, /* add ip, pc, #0xNN00000 */
2209 0xe28cca00, /* add ip, ip, #0xNN000 */
2210 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2213 /* When explicitly asked, we'll use this "long" entry format
2214 which can cope with arbitrary displacements. */
2215 static const bfd_vma elf32_arm_plt_entry_long [] =
2217 0xe28fc200, /* add ip, pc, #0xN0000000 */
2218 0xe28cc600, /* add ip, ip, #0xNN00000 */
2219 0xe28cca00, /* add ip, ip, #0xNN000 */
2220 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2223 static bfd_boolean elf32_arm_use_long_plt_entry = FALSE;
2225 #endif /* not FOUR_WORD_PLT */
2227 /* The first entry in a procedure linkage table looks like this.
2228 It is set up so that any shared library function that is called before the
2229 relocation has been set up calls the dynamic linker first. */
2230 static const bfd_vma elf32_thumb2_plt0_entry [] =
2232 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2233 an instruction maybe encoded to one or two array elements. */
2234 0xf8dfb500, /* push {lr} */
2235 0x44fee008, /* ldr.w lr, [pc, #8] */
2237 0xff08f85e, /* ldr.w pc, [lr, #8]! */
2238 0x00000000, /* &GOT[0] - . */
2241 /* Subsequent entries in a procedure linkage table for thumb only target
2243 static const bfd_vma elf32_thumb2_plt_entry [] =
2245 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2246 an instruction maybe encoded to one or two array elements. */
2247 0x0c00f240, /* movw ip, #0xNNNN */
2248 0x0c00f2c0, /* movt ip, #0xNNNN */
2249 0xf8dc44fc, /* add ip, pc */
2250 0xbf00f000 /* ldr.w pc, [ip] */
2254 /* The format of the first entry in the procedure linkage table
2255 for a VxWorks executable. */
2256 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
2258 0xe52dc008, /* str ip,[sp,#-8]! */
2259 0xe59fc000, /* ldr ip,[pc] */
2260 0xe59cf008, /* ldr pc,[ip,#8] */
2261 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2264 /* The format of subsequent entries in a VxWorks executable. */
2265 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
2267 0xe59fc000, /* ldr ip,[pc] */
2268 0xe59cf000, /* ldr pc,[ip] */
2269 0x00000000, /* .long @got */
2270 0xe59fc000, /* ldr ip,[pc] */
2271 0xea000000, /* b _PLT */
2272 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2275 /* The format of entries in a VxWorks shared library. */
2276 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
2278 0xe59fc000, /* ldr ip,[pc] */
2279 0xe79cf009, /* ldr pc,[ip,r9] */
2280 0x00000000, /* .long @got */
2281 0xe59fc000, /* ldr ip,[pc] */
2282 0xe599f008, /* ldr pc,[r9,#8] */
2283 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2286 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2287 #define PLT_THUMB_STUB_SIZE 4
2288 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2294 /* The entries in a PLT when using a DLL-based target with multiple
2296 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2298 0xe51ff004, /* ldr pc, [pc, #-4] */
2299 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2302 /* The first entry in a procedure linkage table looks like
2303 this. It is set up so that any shared library function that is
2304 called before the relocation has been set up calls the dynamic
2306 static const bfd_vma elf32_arm_nacl_plt0_entry [] =
2309 0xe300c000, /* movw ip, #:lower16:&GOT[2]-.+8 */
2310 0xe340c000, /* movt ip, #:upper16:&GOT[2]-.+8 */
2311 0xe08cc00f, /* add ip, ip, pc */
2312 0xe52dc008, /* str ip, [sp, #-8]! */
2313 /* Second bundle: */
2314 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2315 0xe59cc000, /* ldr ip, [ip] */
2316 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2317 0xe12fff1c, /* bx ip */
2319 0xe320f000, /* nop */
2320 0xe320f000, /* nop */
2321 0xe320f000, /* nop */
2323 0xe50dc004, /* str ip, [sp, #-4] */
2324 /* Fourth bundle: */
2325 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2326 0xe59cc000, /* ldr ip, [ip] */
2327 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2328 0xe12fff1c, /* bx ip */
2330 #define ARM_NACL_PLT_TAIL_OFFSET (11 * 4)
2332 /* Subsequent entries in a procedure linkage table look like this. */
2333 static const bfd_vma elf32_arm_nacl_plt_entry [] =
2335 0xe300c000, /* movw ip, #:lower16:&GOT[n]-.+8 */
2336 0xe340c000, /* movt ip, #:upper16:&GOT[n]-.+8 */
2337 0xe08cc00f, /* add ip, ip, pc */
2338 0xea000000, /* b .Lplt_tail */
2341 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2342 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2343 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2344 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2345 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2346 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2347 #define THM2_MAX_FWD_COND_BRANCH_OFFSET (((1 << 20) -2) + 4)
2348 #define THM2_MAX_BWD_COND_BRANCH_OFFSET (-(1 << 20) + 4)
2358 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2359 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2360 is inserted in arm_build_one_stub(). */
2361 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2362 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2363 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2364 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2365 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2366 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2371 enum stub_insn_type type;
2372 unsigned int r_type;
2376 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2377 to reach the stub if necessary. */
2378 static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
2380 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2381 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2384 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2386 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2388 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2389 ARM_INSN (0xe12fff1c), /* bx ip */
2390 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2393 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2394 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
2396 THUMB16_INSN (0xb401), /* push {r0} */
2397 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2398 THUMB16_INSN (0x4684), /* mov ip, r0 */
2399 THUMB16_INSN (0xbc01), /* pop {r0} */
2400 THUMB16_INSN (0x4760), /* bx ip */
2401 THUMB16_INSN (0xbf00), /* nop */
2402 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2405 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2407 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb[] =
2409 THUMB16_INSN (0x4778), /* bx pc */
2410 THUMB16_INSN (0x46c0), /* nop */
2411 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2412 ARM_INSN (0xe12fff1c), /* bx ip */
2413 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2416 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2418 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2420 THUMB16_INSN (0x4778), /* bx pc */
2421 THUMB16_INSN (0x46c0), /* nop */
2422 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2423 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2426 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2427 one, when the destination is close enough. */
2428 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2430 THUMB16_INSN (0x4778), /* bx pc */
2431 THUMB16_INSN (0x46c0), /* nop */
2432 ARM_REL_INSN (0xea000000, -8), /* b (X-8) */
2435 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2436 blx to reach the stub if necessary. */
2437 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
2439 ARM_INSN (0xe59fc000), /* ldr ip, [pc] */
2440 ARM_INSN (0xe08ff00c), /* add pc, pc, ip */
2441 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2444 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2445 blx to reach the stub if necessary. We can not add into pc;
2446 it is not guaranteed to mode switch (different in ARMv6 and
2448 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2450 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2451 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2452 ARM_INSN (0xe12fff1c), /* bx ip */
2453 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2456 /* V4T ARM -> ARM long branch stub, PIC. */
2457 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2459 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2460 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2461 ARM_INSN (0xe12fff1c), /* bx ip */
2462 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2465 /* V4T Thumb -> ARM long branch stub, PIC. */
2466 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2468 THUMB16_INSN (0x4778), /* bx pc */
2469 THUMB16_INSN (0x46c0), /* nop */
2470 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2471 ARM_INSN (0xe08cf00f), /* add pc, ip, pc */
2472 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2475 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2477 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2479 THUMB16_INSN (0xb401), /* push {r0} */
2480 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2481 THUMB16_INSN (0x46fc), /* mov ip, pc */
2482 THUMB16_INSN (0x4484), /* add ip, r0 */
2483 THUMB16_INSN (0xbc01), /* pop {r0} */
2484 THUMB16_INSN (0x4760), /* bx ip */
2485 DATA_WORD (0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2488 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2490 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic[] =
2492 THUMB16_INSN (0x4778), /* bx pc */
2493 THUMB16_INSN (0x46c0), /* nop */
2494 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2495 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2496 ARM_INSN (0xe12fff1c), /* bx ip */
2497 DATA_WORD (0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2500 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2501 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2502 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic[] =
2504 ARM_INSN (0xe59f1000), /* ldr r1, [pc] */
2505 ARM_INSN (0xe08ff001), /* add pc, pc, r1 */
2506 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2509 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2510 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2511 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic[] =
2513 THUMB16_INSN (0x4778), /* bx pc */
2514 THUMB16_INSN (0x46c0), /* nop */
2515 ARM_INSN (0xe59f1000), /* ldr r1, [pc, #0] */
2516 ARM_INSN (0xe081f00f), /* add pc, r1, pc */
2517 DATA_WORD (0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2520 /* NaCl ARM -> ARM long branch stub. */
2521 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl[] =
2523 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2524 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2525 ARM_INSN (0xe12fff1c), /* bx ip */
2526 ARM_INSN (0xe320f000), /* nop */
2527 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2528 DATA_WORD (0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2529 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */
2530 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */
2533 /* NaCl ARM -> ARM long branch stub, PIC. */
2534 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl_pic[] =
2536 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2537 ARM_INSN (0xe08cc00f), /* add ip, ip, pc */
2538 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2539 ARM_INSN (0xe12fff1c), /* bx ip */
2540 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2541 DATA_WORD (0, R_ARM_REL32, 8), /* dcd R_ARM_REL32(X+8) */
2542 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */
2543 DATA_WORD (0, R_ARM_NONE, 0), /* .word 0 */
2547 /* Cortex-A8 erratum-workaround stubs. */
2549 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2550 can't use a conditional branch to reach this stub). */
2552 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond[] =
2554 THUMB16_BCOND_INSN (0xd001), /* b<cond>.n true. */
2555 THUMB32_B_INSN (0xf000b800, -4), /* b.w insn_after_original_branch. */
2556 THUMB32_B_INSN (0xf000b800, -4) /* true: b.w original_branch_dest. */
2559 /* Stub used for b.w and bl.w instructions. */
2561 static const insn_sequence elf32_arm_stub_a8_veneer_b[] =
2563 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2566 static const insn_sequence elf32_arm_stub_a8_veneer_bl[] =
2568 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2571 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2572 instruction (which switches to ARM mode) to point to this stub. Jump to the
2573 real destination using an ARM-mode branch. */
2575 static const insn_sequence elf32_arm_stub_a8_veneer_blx[] =
2577 ARM_REL_INSN (0xea000000, -8) /* b original_branch_dest. */
2580 /* For each section group there can be a specially created linker section
2581 to hold the stubs for that group. The name of the stub section is based
2582 upon the name of another section within that group with the suffix below
2585 PR 13049: STUB_SUFFIX used to be ".stub", but this allowed the user to
2586 create what appeared to be a linker stub section when it actually
2587 contained user code/data. For example, consider this fragment:
2589 const char * stubborn_problems[] = { "np" };
2591 If this is compiled with "-fPIC -fdata-sections" then gcc produces a
2594 .data.rel.local.stubborn_problems
2596 This then causes problems in arm32_arm_build_stubs() as it triggers:
2598 // Ignore non-stub sections.
2599 if (!strstr (stub_sec->name, STUB_SUFFIX))
2602 And so the section would be ignored instead of being processed. Hence
2603 the change in definition of STUB_SUFFIX to a name that cannot be a valid
2605 #define STUB_SUFFIX ".__stub"
2607 /* One entry per long/short branch stub defined above. */
2609 DEF_STUB(long_branch_any_any) \
2610 DEF_STUB(long_branch_v4t_arm_thumb) \
2611 DEF_STUB(long_branch_thumb_only) \
2612 DEF_STUB(long_branch_v4t_thumb_thumb) \
2613 DEF_STUB(long_branch_v4t_thumb_arm) \
2614 DEF_STUB(short_branch_v4t_thumb_arm) \
2615 DEF_STUB(long_branch_any_arm_pic) \
2616 DEF_STUB(long_branch_any_thumb_pic) \
2617 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2618 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2619 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2620 DEF_STUB(long_branch_thumb_only_pic) \
2621 DEF_STUB(long_branch_any_tls_pic) \
2622 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2623 DEF_STUB(long_branch_arm_nacl) \
2624 DEF_STUB(long_branch_arm_nacl_pic) \
2625 DEF_STUB(a8_veneer_b_cond) \
2626 DEF_STUB(a8_veneer_b) \
2627 DEF_STUB(a8_veneer_bl) \
2628 DEF_STUB(a8_veneer_blx)
2630 #define DEF_STUB(x) arm_stub_##x,
2631 enum elf32_arm_stub_type
2635 /* Note the first a8_veneer type. */
2636 arm_stub_a8_veneer_lwm = arm_stub_a8_veneer_b_cond
2642 const insn_sequence* template_sequence;
2646 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2647 static const stub_def stub_definitions[] =
2653 struct elf32_arm_stub_hash_entry
2655 /* Base hash table entry structure. */
2656 struct bfd_hash_entry root;
2658 /* The stub section. */
2661 /* Offset within stub_sec of the beginning of this stub. */
2662 bfd_vma stub_offset;
2664 /* Given the symbol's value and its section we can determine its final
2665 value when building the stubs (so the stub knows where to jump). */
2666 bfd_vma target_value;
2667 asection *target_section;
2669 /* Offset to apply to relocation referencing target_value. */
2670 bfd_vma target_addend;
2672 /* The instruction which caused this stub to be generated (only valid for
2673 Cortex-A8 erratum workaround stubs at present). */
2674 unsigned long orig_insn;
2676 /* The stub type. */
2677 enum elf32_arm_stub_type stub_type;
2678 /* Its encoding size in bytes. */
2681 const insn_sequence *stub_template;
2682 /* The size of the template (number of entries). */
2683 int stub_template_size;
2685 /* The symbol table entry, if any, that this was derived from. */
2686 struct elf32_arm_link_hash_entry *h;
2688 /* Type of branch. */
2689 enum arm_st_branch_type branch_type;
2691 /* Where this stub is being called from, or, in the case of combined
2692 stub sections, the first input section in the group. */
2695 /* The name for the local symbol at the start of this stub. The
2696 stub name in the hash table has to be unique; this does not, so
2697 it can be friendlier. */
2701 /* Used to build a map of a section. This is required for mixed-endian
2704 typedef struct elf32_elf_section_map
2709 elf32_arm_section_map;
2711 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2715 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2716 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2717 VFP11_ERRATUM_ARM_VENEER,
2718 VFP11_ERRATUM_THUMB_VENEER
2720 elf32_vfp11_erratum_type;
2722 typedef struct elf32_vfp11_erratum_list
2724 struct elf32_vfp11_erratum_list *next;
2730 struct elf32_vfp11_erratum_list *veneer;
2731 unsigned int vfp_insn;
2735 struct elf32_vfp11_erratum_list *branch;
2739 elf32_vfp11_erratum_type type;
2741 elf32_vfp11_erratum_list;
2743 /* Information about a STM32L4XX erratum veneer, or a branch to such a
2747 STM32L4XX_ERRATUM_BRANCH_TO_VENEER,
2748 STM32L4XX_ERRATUM_VENEER
2750 elf32_stm32l4xx_erratum_type;
2752 typedef struct elf32_stm32l4xx_erratum_list
2754 struct elf32_stm32l4xx_erratum_list *next;
2760 struct elf32_stm32l4xx_erratum_list *veneer;
2765 struct elf32_stm32l4xx_erratum_list *branch;
2769 elf32_stm32l4xx_erratum_type type;
2771 elf32_stm32l4xx_erratum_list;
2776 INSERT_EXIDX_CANTUNWIND_AT_END
2778 arm_unwind_edit_type;
2780 /* A (sorted) list of edits to apply to an unwind table. */
2781 typedef struct arm_unwind_table_edit
2783 arm_unwind_edit_type type;
2784 /* Note: we sometimes want to insert an unwind entry corresponding to a
2785 section different from the one we're currently writing out, so record the
2786 (text) section this edit relates to here. */
2787 asection *linked_section;
2789 struct arm_unwind_table_edit *next;
2791 arm_unwind_table_edit;
2793 typedef struct _arm_elf_section_data
2795 /* Information about mapping symbols. */
2796 struct bfd_elf_section_data elf;
2797 unsigned int mapcount;
2798 unsigned int mapsize;
2799 elf32_arm_section_map *map;
2800 /* Information about CPU errata. */
2801 unsigned int erratumcount;
2802 elf32_vfp11_erratum_list *erratumlist;
2803 unsigned int stm32l4xx_erratumcount;
2804 elf32_stm32l4xx_erratum_list *stm32l4xx_erratumlist;
2805 unsigned int additional_reloc_count;
2806 /* Information about unwind tables. */
2809 /* Unwind info attached to a text section. */
2812 asection *arm_exidx_sec;
2815 /* Unwind info attached to an .ARM.exidx section. */
2818 arm_unwind_table_edit *unwind_edit_list;
2819 arm_unwind_table_edit *unwind_edit_tail;
2823 _arm_elf_section_data;
2825 #define elf32_arm_section_data(sec) \
2826 ((_arm_elf_section_data *) elf_section_data (sec))
2828 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2829 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2830 so may be created multiple times: we use an array of these entries whilst
2831 relaxing which we can refresh easily, then create stubs for each potentially
2832 erratum-triggering instruction once we've settled on a solution. */
2834 struct a8_erratum_fix
2840 unsigned long orig_insn;
2842 enum elf32_arm_stub_type stub_type;
2843 enum arm_st_branch_type branch_type;
2846 /* A table of relocs applied to branches which might trigger Cortex-A8
2849 struct a8_erratum_reloc
2852 bfd_vma destination;
2853 struct elf32_arm_link_hash_entry *hash;
2854 const char *sym_name;
2855 unsigned int r_type;
2856 enum arm_st_branch_type branch_type;
2857 bfd_boolean non_a8_stub;
2860 /* The size of the thread control block. */
2863 /* ARM-specific information about a PLT entry, over and above the usual
2867 /* We reference count Thumb references to a PLT entry separately,
2868 so that we can emit the Thumb trampoline only if needed. */
2869 bfd_signed_vma thumb_refcount;
2871 /* Some references from Thumb code may be eliminated by BL->BLX
2872 conversion, so record them separately. */
2873 bfd_signed_vma maybe_thumb_refcount;
2875 /* How many of the recorded PLT accesses were from non-call relocations.
2876 This information is useful when deciding whether anything takes the
2877 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
2878 non-call references to the function should resolve directly to the
2879 real runtime target. */
2880 unsigned int noncall_refcount;
2882 /* Since PLT entries have variable size if the Thumb prologue is
2883 used, we need to record the index into .got.plt instead of
2884 recomputing it from the PLT offset. */
2885 bfd_signed_vma got_offset;
2888 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
2889 struct arm_local_iplt_info
2891 /* The information that is usually found in the generic ELF part of
2892 the hash table entry. */
2893 union gotplt_union root;
2895 /* The information that is usually found in the ARM-specific part of
2896 the hash table entry. */
2897 struct arm_plt_info arm;
2899 /* A list of all potential dynamic relocations against this symbol. */
2900 struct elf_dyn_relocs *dyn_relocs;
2903 struct elf_arm_obj_tdata
2905 struct elf_obj_tdata root;
2907 /* tls_type for each local got entry. */
2908 char *local_got_tls_type;
2910 /* GOTPLT entries for TLS descriptors. */
2911 bfd_vma *local_tlsdesc_gotent;
2913 /* Information for local symbols that need entries in .iplt. */
2914 struct arm_local_iplt_info **local_iplt;
2916 /* Zero to warn when linking objects with incompatible enum sizes. */
2917 int no_enum_size_warning;
2919 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2920 int no_wchar_size_warning;
2923 #define elf_arm_tdata(bfd) \
2924 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2926 #define elf32_arm_local_got_tls_type(bfd) \
2927 (elf_arm_tdata (bfd)->local_got_tls_type)
2929 #define elf32_arm_local_tlsdesc_gotent(bfd) \
2930 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
2932 #define elf32_arm_local_iplt(bfd) \
2933 (elf_arm_tdata (bfd)->local_iplt)
2935 #define is_arm_elf(bfd) \
2936 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2937 && elf_tdata (bfd) != NULL \
2938 && elf_object_id (bfd) == ARM_ELF_DATA)
2941 elf32_arm_mkobject (bfd *abfd)
2943 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2947 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2949 /* Arm ELF linker hash entry. */
2950 struct elf32_arm_link_hash_entry
2952 struct elf_link_hash_entry root;
2954 /* Track dynamic relocs copied for this symbol. */
2955 struct elf_dyn_relocs *dyn_relocs;
2957 /* ARM-specific PLT information. */
2958 struct arm_plt_info plt;
2960 #define GOT_UNKNOWN 0
2961 #define GOT_NORMAL 1
2962 #define GOT_TLS_GD 2
2963 #define GOT_TLS_IE 4
2964 #define GOT_TLS_GDESC 8
2965 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
2966 unsigned int tls_type : 8;
2968 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
2969 unsigned int is_iplt : 1;
2971 unsigned int unused : 23;
2973 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
2974 starting at the end of the jump table. */
2975 bfd_vma tlsdesc_got;
2977 /* The symbol marking the real symbol location for exported thumb
2978 symbols with Arm stubs. */
2979 struct elf_link_hash_entry *export_glue;
2981 /* A pointer to the most recently used stub hash entry against this
2983 struct elf32_arm_stub_hash_entry *stub_cache;
2986 /* Traverse an arm ELF linker hash table. */
2987 #define elf32_arm_link_hash_traverse(table, func, info) \
2988 (elf_link_hash_traverse \
2990 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2993 /* Get the ARM elf linker hash table from a link_info structure. */
2994 #define elf32_arm_hash_table(info) \
2995 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
2996 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
2998 #define arm_stub_hash_lookup(table, string, create, copy) \
2999 ((struct elf32_arm_stub_hash_entry *) \
3000 bfd_hash_lookup ((table), (string), (create), (copy)))
3002 /* Array to keep track of which stub sections have been created, and
3003 information on stub grouping. */
3006 /* This is the section to which stubs in the group will be
3009 /* The stub section. */
3013 #define elf32_arm_compute_jump_table_size(htab) \
3014 ((htab)->next_tls_desc_index * 4)
3016 /* ARM ELF linker hash table. */
3017 struct elf32_arm_link_hash_table
3019 /* The main hash table. */
3020 struct elf_link_hash_table root;
3022 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
3023 bfd_size_type thumb_glue_size;
3025 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
3026 bfd_size_type arm_glue_size;
3028 /* The size in bytes of section containing the ARMv4 BX veneers. */
3029 bfd_size_type bx_glue_size;
3031 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
3032 veneer has been populated. */
3033 bfd_vma bx_glue_offset[15];
3035 /* The size in bytes of the section containing glue for VFP11 erratum
3037 bfd_size_type vfp11_erratum_glue_size;
3039 /* The size in bytes of the section containing glue for STM32L4XX erratum
3041 bfd_size_type stm32l4xx_erratum_glue_size;
3043 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
3044 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
3045 elf32_arm_write_section(). */
3046 struct a8_erratum_fix *a8_erratum_fixes;
3047 unsigned int num_a8_erratum_fixes;
3049 /* An arbitrary input BFD chosen to hold the glue sections. */
3050 bfd * bfd_of_glue_owner;
3052 /* Nonzero to output a BE8 image. */
3055 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
3056 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
3059 /* The relocation to use for R_ARM_TARGET2 relocations. */
3062 /* 0 = Ignore R_ARM_V4BX.
3063 1 = Convert BX to MOV PC.
3064 2 = Generate v4 interworing stubs. */
3067 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
3070 /* Whether we should fix the ARM1176 BLX immediate issue. */
3073 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
3076 /* What sort of code sequences we should look for which may trigger the
3077 VFP11 denorm erratum. */
3078 bfd_arm_vfp11_fix vfp11_fix;
3080 /* Global counter for the number of fixes we have emitted. */
3081 int num_vfp11_fixes;
3083 /* What sort of code sequences we should look for which may trigger the
3084 STM32L4XX erratum. */
3085 bfd_arm_stm32l4xx_fix stm32l4xx_fix;
3087 /* Global counter for the number of fixes we have emitted. */
3088 int num_stm32l4xx_fixes;
3090 /* Nonzero to force PIC branch veneers. */
3093 /* The number of bytes in the initial entry in the PLT. */
3094 bfd_size_type plt_header_size;
3096 /* The number of bytes in the subsequent PLT etries. */
3097 bfd_size_type plt_entry_size;
3099 /* True if the target system is VxWorks. */
3102 /* True if the target system is Symbian OS. */
3105 /* True if the target system is Native Client. */
3108 /* True if the target uses REL relocations. */
3111 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
3112 bfd_vma next_tls_desc_index;
3114 /* How many R_ARM_TLS_DESC relocations were generated so far. */
3115 bfd_vma num_tls_desc;
3117 /* Short-cuts to get to dynamic linker sections. */
3121 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
3124 /* The offset into splt of the PLT entry for the TLS descriptor
3125 resolver. Special values are 0, if not necessary (or not found
3126 to be necessary yet), and -1 if needed but not determined
3128 bfd_vma dt_tlsdesc_plt;
3130 /* The offset into sgot of the GOT entry used by the PLT entry
3132 bfd_vma dt_tlsdesc_got;
3134 /* Offset in .plt section of tls_arm_trampoline. */
3135 bfd_vma tls_trampoline;
3137 /* Data for R_ARM_TLS_LDM32 relocations. */
3140 bfd_signed_vma refcount;
3144 /* Small local sym cache. */
3145 struct sym_cache sym_cache;
3147 /* For convenience in allocate_dynrelocs. */
3150 /* The amount of space used by the reserved portion of the sgotplt
3151 section, plus whatever space is used by the jump slots. */
3152 bfd_vma sgotplt_jump_table_size;
3154 /* The stub hash table. */
3155 struct bfd_hash_table stub_hash_table;
3157 /* Linker stub bfd. */
3160 /* Linker call-backs. */
3161 asection * (*add_stub_section) (const char *, asection *, unsigned int);
3162 void (*layout_sections_again) (void);
3164 /* Array to keep track of which stub sections have been created, and
3165 information on stub grouping. */
3166 struct map_stub *stub_group;
3168 /* Number of elements in stub_group. */
3169 unsigned int top_id;
3171 /* Assorted information used by elf32_arm_size_stubs. */
3172 unsigned int bfd_count;
3173 unsigned int top_index;
3174 asection **input_list;
3178 ctz (unsigned int mask)
3180 #if GCC_VERSION >= 3004
3181 return __builtin_ctz (mask);
3185 for (i = 0; i < 8 * sizeof (mask); i++)
3196 popcount (unsigned int mask)
3198 #if GCC_VERSION >= 3004
3199 return __builtin_popcount (mask);
3201 unsigned int i, sum = 0;
3203 for (i = 0; i < 8 * sizeof (mask); i++)
3213 /* Create an entry in an ARM ELF linker hash table. */
3215 static struct bfd_hash_entry *
3216 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
3217 struct bfd_hash_table * table,
3218 const char * string)
3220 struct elf32_arm_link_hash_entry * ret =
3221 (struct elf32_arm_link_hash_entry *) entry;
3223 /* Allocate the structure if it has not already been allocated by a
3226 ret = (struct elf32_arm_link_hash_entry *)
3227 bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
3229 return (struct bfd_hash_entry *) ret;
3231 /* Call the allocation method of the superclass. */
3232 ret = ((struct elf32_arm_link_hash_entry *)
3233 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3237 ret->dyn_relocs = NULL;
3238 ret->tls_type = GOT_UNKNOWN;
3239 ret->tlsdesc_got = (bfd_vma) -1;
3240 ret->plt.thumb_refcount = 0;
3241 ret->plt.maybe_thumb_refcount = 0;
3242 ret->plt.noncall_refcount = 0;
3243 ret->plt.got_offset = -1;
3244 ret->is_iplt = FALSE;
3245 ret->export_glue = NULL;
3247 ret->stub_cache = NULL;
3250 return (struct bfd_hash_entry *) ret;
3253 /* Ensure that we have allocated bookkeeping structures for ABFD's local
3257 elf32_arm_allocate_local_sym_info (bfd *abfd)
3259 if (elf_local_got_refcounts (abfd) == NULL)
3261 bfd_size_type num_syms;
3265 num_syms = elf_tdata (abfd)->symtab_hdr.sh_info;
3266 size = num_syms * (sizeof (bfd_signed_vma)
3267 + sizeof (struct arm_local_iplt_info *)
3270 data = bfd_zalloc (abfd, size);
3274 elf_local_got_refcounts (abfd) = (bfd_signed_vma *) data;
3275 data += num_syms * sizeof (bfd_signed_vma);
3277 elf32_arm_local_iplt (abfd) = (struct arm_local_iplt_info **) data;
3278 data += num_syms * sizeof (struct arm_local_iplt_info *);
3280 elf32_arm_local_tlsdesc_gotent (abfd) = (bfd_vma *) data;
3281 data += num_syms * sizeof (bfd_vma);
3283 elf32_arm_local_got_tls_type (abfd) = data;
3288 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
3289 to input bfd ABFD. Create the information if it doesn't already exist.
3290 Return null if an allocation fails. */
3292 static struct arm_local_iplt_info *
3293 elf32_arm_create_local_iplt (bfd *abfd, unsigned long r_symndx)
3295 struct arm_local_iplt_info **ptr;
3297 if (!elf32_arm_allocate_local_sym_info (abfd))
3300 BFD_ASSERT (r_symndx < elf_tdata (abfd)->symtab_hdr.sh_info);
3301 ptr = &elf32_arm_local_iplt (abfd)[r_symndx];
3303 *ptr = bfd_zalloc (abfd, sizeof (**ptr));
3307 /* Try to obtain PLT information for the symbol with index R_SYMNDX
3308 in ABFD's symbol table. If the symbol is global, H points to its
3309 hash table entry, otherwise H is null.
3311 Return true if the symbol does have PLT information. When returning
3312 true, point *ROOT_PLT at the target-independent reference count/offset
3313 union and *ARM_PLT at the ARM-specific information. */
3316 elf32_arm_get_plt_info (bfd *abfd, struct elf32_arm_link_hash_entry *h,
3317 unsigned long r_symndx, union gotplt_union **root_plt,
3318 struct arm_plt_info **arm_plt)
3320 struct arm_local_iplt_info *local_iplt;
3324 *root_plt = &h->root.plt;
3329 if (elf32_arm_local_iplt (abfd) == NULL)
3332 local_iplt = elf32_arm_local_iplt (abfd)[r_symndx];
3333 if (local_iplt == NULL)
3336 *root_plt = &local_iplt->root;
3337 *arm_plt = &local_iplt->arm;
3341 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3345 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info *info,
3346 struct arm_plt_info *arm_plt)
3348 struct elf32_arm_link_hash_table *htab;
3350 htab = elf32_arm_hash_table (info);
3351 return (arm_plt->thumb_refcount != 0
3352 || (!htab->use_blx && arm_plt->maybe_thumb_refcount != 0));
3355 /* Return a pointer to the head of the dynamic reloc list that should
3356 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3357 ABFD's symbol table. Return null if an error occurs. */
3359 static struct elf_dyn_relocs **
3360 elf32_arm_get_local_dynreloc_list (bfd *abfd, unsigned long r_symndx,
3361 Elf_Internal_Sym *isym)
3363 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
3365 struct arm_local_iplt_info *local_iplt;
3367 local_iplt = elf32_arm_create_local_iplt (abfd, r_symndx);
3368 if (local_iplt == NULL)
3370 return &local_iplt->dyn_relocs;
3374 /* Track dynamic relocs needed for local syms too.
3375 We really need local syms available to do this
3380 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
3384 vpp = &elf_section_data (s)->local_dynrel;
3385 return (struct elf_dyn_relocs **) vpp;
3389 /* Initialize an entry in the stub hash table. */
3391 static struct bfd_hash_entry *
3392 stub_hash_newfunc (struct bfd_hash_entry *entry,
3393 struct bfd_hash_table *table,
3396 /* Allocate the structure if it has not already been allocated by a
3400 entry = (struct bfd_hash_entry *)
3401 bfd_hash_allocate (table, sizeof (struct elf32_arm_stub_hash_entry));
3406 /* Call the allocation method of the superclass. */
3407 entry = bfd_hash_newfunc (entry, table, string);
3410 struct elf32_arm_stub_hash_entry *eh;
3412 /* Initialize the local fields. */
3413 eh = (struct elf32_arm_stub_hash_entry *) entry;
3414 eh->stub_sec = NULL;
3415 eh->stub_offset = 0;
3416 eh->target_value = 0;
3417 eh->target_section = NULL;
3418 eh->target_addend = 0;
3420 eh->stub_type = arm_stub_none;
3422 eh->stub_template = NULL;
3423 eh->stub_template_size = 0;
3426 eh->output_name = NULL;
3432 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3433 shortcuts to them in our hash table. */
3436 create_got_section (bfd *dynobj, struct bfd_link_info *info)
3438 struct elf32_arm_link_hash_table *htab;
3440 htab = elf32_arm_hash_table (info);
3444 /* BPABI objects never have a GOT, or associated sections. */
3445 if (htab->symbian_p)
3448 if (! _bfd_elf_create_got_section (dynobj, info))
3454 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3457 create_ifunc_sections (struct bfd_link_info *info)
3459 struct elf32_arm_link_hash_table *htab;
3460 const struct elf_backend_data *bed;
3465 htab = elf32_arm_hash_table (info);
3466 dynobj = htab->root.dynobj;
3467 bed = get_elf_backend_data (dynobj);
3468 flags = bed->dynamic_sec_flags;
3470 if (htab->root.iplt == NULL)
3472 s = bfd_make_section_anyway_with_flags (dynobj, ".iplt",
3473 flags | SEC_READONLY | SEC_CODE);
3475 || !bfd_set_section_alignment (dynobj, s, bed->plt_alignment))
3477 htab->root.iplt = s;
3480 if (htab->root.irelplt == NULL)
3482 s = bfd_make_section_anyway_with_flags (dynobj,
3483 RELOC_SECTION (htab, ".iplt"),
3484 flags | SEC_READONLY);
3486 || !bfd_set_section_alignment (dynobj, s, bed->s->log_file_align))
3488 htab->root.irelplt = s;
3491 if (htab->root.igotplt == NULL)
3493 s = bfd_make_section_anyway_with_flags (dynobj, ".igot.plt", flags);
3495 || !bfd_set_section_alignment (dynobj, s, bed->s->log_file_align))
3497 htab->root.igotplt = s;
3502 /* Determine if we're dealing with a Thumb only architecture. */
3505 using_thumb_only (struct elf32_arm_link_hash_table *globals)
3507 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3511 if (arch == TAG_CPU_ARCH_V6_M || arch == TAG_CPU_ARCH_V6S_M)
3514 if (arch != TAG_CPU_ARCH_V7 && arch != TAG_CPU_ARCH_V7E_M)
3517 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3518 Tag_CPU_arch_profile);
3520 return profile == 'M';
3523 /* Determine if we're dealing with a Thumb-2 object. */
3526 using_thumb2 (struct elf32_arm_link_hash_table *globals)
3528 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3530 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
3533 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3534 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3538 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
3540 struct elf32_arm_link_hash_table *htab;
3542 htab = elf32_arm_hash_table (info);
3546 if (!htab->root.sgot && !create_got_section (dynobj, info))
3549 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
3552 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
3553 if (!bfd_link_pic (info))
3554 htab->srelbss = bfd_get_linker_section (dynobj,
3555 RELOC_SECTION (htab, ".bss"));
3557 if (htab->vxworks_p)
3559 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
3562 if (bfd_link_pic (info))
3564 htab->plt_header_size = 0;
3565 htab->plt_entry_size
3566 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
3570 htab->plt_header_size
3571 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
3572 htab->plt_entry_size
3573 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
3579 Test for thumb only architectures. Note - we cannot just call
3580 using_thumb_only() as the attributes in the output bfd have not been
3581 initialised at this point, so instead we use the input bfd. */
3582 bfd * saved_obfd = htab->obfd;
3584 htab->obfd = dynobj;
3585 if (using_thumb_only (htab))
3587 htab->plt_header_size = 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry);
3588 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_thumb2_plt_entry);
3590 htab->obfd = saved_obfd;
3593 if (!htab->root.splt
3594 || !htab->root.srelplt
3596 || (!bfd_link_pic (info) && !htab->srelbss))
3602 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3605 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
3606 struct elf_link_hash_entry *dir,
3607 struct elf_link_hash_entry *ind)
3609 struct elf32_arm_link_hash_entry *edir, *eind;
3611 edir = (struct elf32_arm_link_hash_entry *) dir;
3612 eind = (struct elf32_arm_link_hash_entry *) ind;
3614 if (eind->dyn_relocs != NULL)
3616 if (edir->dyn_relocs != NULL)
3618 struct elf_dyn_relocs **pp;
3619 struct elf_dyn_relocs *p;
3621 /* Add reloc counts against the indirect sym to the direct sym
3622 list. Merge any entries against the same section. */
3623 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3625 struct elf_dyn_relocs *q;
3627 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3628 if (q->sec == p->sec)
3630 q->pc_count += p->pc_count;
3631 q->count += p->count;
3638 *pp = edir->dyn_relocs;
3641 edir->dyn_relocs = eind->dyn_relocs;
3642 eind->dyn_relocs = NULL;
3645 if (ind->root.type == bfd_link_hash_indirect)
3647 /* Copy over PLT info. */
3648 edir->plt.thumb_refcount += eind->plt.thumb_refcount;
3649 eind->plt.thumb_refcount = 0;
3650 edir->plt.maybe_thumb_refcount += eind->plt.maybe_thumb_refcount;
3651 eind->plt.maybe_thumb_refcount = 0;
3652 edir->plt.noncall_refcount += eind->plt.noncall_refcount;
3653 eind->plt.noncall_refcount = 0;
3655 /* We should only allocate a function to .iplt once the final
3656 symbol information is known. */
3657 BFD_ASSERT (!eind->is_iplt);
3659 if (dir->got.refcount <= 0)
3661 edir->tls_type = eind->tls_type;
3662 eind->tls_type = GOT_UNKNOWN;
3666 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3669 /* Destroy an ARM elf linker hash table. */
3672 elf32_arm_link_hash_table_free (bfd *obfd)
3674 struct elf32_arm_link_hash_table *ret
3675 = (struct elf32_arm_link_hash_table *) obfd->link.hash;
3677 bfd_hash_table_free (&ret->stub_hash_table);
3678 _bfd_elf_link_hash_table_free (obfd);
3681 /* Create an ARM elf linker hash table. */
3683 static struct bfd_link_hash_table *
3684 elf32_arm_link_hash_table_create (bfd *abfd)
3686 struct elf32_arm_link_hash_table *ret;
3687 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
3689 ret = (struct elf32_arm_link_hash_table *) bfd_zmalloc (amt);
3693 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
3694 elf32_arm_link_hash_newfunc,
3695 sizeof (struct elf32_arm_link_hash_entry),
3702 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3703 ret->stm32l4xx_fix = BFD_ARM_STM32L4XX_FIX_NONE;
3704 #ifdef FOUR_WORD_PLT
3705 ret->plt_header_size = 16;
3706 ret->plt_entry_size = 16;
3708 ret->plt_header_size = 20;
3709 ret->plt_entry_size = elf32_arm_use_long_plt_entry ? 16 : 12;
3714 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
3715 sizeof (struct elf32_arm_stub_hash_entry)))
3717 _bfd_elf_link_hash_table_free (abfd);
3720 ret->root.root.hash_table_free = elf32_arm_link_hash_table_free;
3722 return &ret->root.root;
3725 /* Determine what kind of NOPs are available. */
3728 arch_has_arm_nop (struct elf32_arm_link_hash_table *globals)
3730 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3732 return arch == TAG_CPU_ARCH_V6T2
3733 || arch == TAG_CPU_ARCH_V6K
3734 || arch == TAG_CPU_ARCH_V7
3735 || arch == TAG_CPU_ARCH_V7E_M;
3739 arch_has_thumb2_nop (struct elf32_arm_link_hash_table *globals)
3741 const int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3743 return (arch == TAG_CPU_ARCH_V6T2 || arch == TAG_CPU_ARCH_V7
3744 || arch == TAG_CPU_ARCH_V7E_M);
3748 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
3752 case arm_stub_long_branch_thumb_only:
3753 case arm_stub_long_branch_v4t_thumb_arm:
3754 case arm_stub_short_branch_v4t_thumb_arm:
3755 case arm_stub_long_branch_v4t_thumb_arm_pic:
3756 case arm_stub_long_branch_v4t_thumb_tls_pic:
3757 case arm_stub_long_branch_thumb_only_pic:
3768 /* Determine the type of stub needed, if any, for a call. */
3770 static enum elf32_arm_stub_type
3771 arm_type_of_stub (struct bfd_link_info *info,
3772 asection *input_sec,
3773 const Elf_Internal_Rela *rel,
3774 unsigned char st_type,
3775 enum arm_st_branch_type *actual_branch_type,
3776 struct elf32_arm_link_hash_entry *hash,
3777 bfd_vma destination,
3783 bfd_signed_vma branch_offset;
3784 unsigned int r_type;
3785 struct elf32_arm_link_hash_table * globals;
3788 enum elf32_arm_stub_type stub_type = arm_stub_none;
3790 enum arm_st_branch_type branch_type = *actual_branch_type;
3791 union gotplt_union *root_plt;
3792 struct arm_plt_info *arm_plt;
3794 if (branch_type == ST_BRANCH_LONG)
3797 globals = elf32_arm_hash_table (info);
3798 if (globals == NULL)
3801 thumb_only = using_thumb_only (globals);
3803 thumb2 = using_thumb2 (globals);
3805 /* Determine where the call point is. */
3806 location = (input_sec->output_offset
3807 + input_sec->output_section->vma
3810 r_type = ELF32_R_TYPE (rel->r_info);
3812 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
3813 are considering a function call relocation. */
3814 if (thumb_only && (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24
3815 || r_type == R_ARM_THM_JUMP19)
3816 && branch_type == ST_BRANCH_TO_ARM)
3817 branch_type = ST_BRANCH_TO_THUMB;
3819 /* For TLS call relocs, it is the caller's responsibility to provide
3820 the address of the appropriate trampoline. */
3821 if (r_type != R_ARM_TLS_CALL
3822 && r_type != R_ARM_THM_TLS_CALL
3823 && elf32_arm_get_plt_info (input_bfd, hash, ELF32_R_SYM (rel->r_info),
3824 &root_plt, &arm_plt)
3825 && root_plt->offset != (bfd_vma) -1)
3829 if (hash == NULL || hash->is_iplt)
3830 splt = globals->root.iplt;
3832 splt = globals->root.splt;
3837 /* Note when dealing with PLT entries: the main PLT stub is in
3838 ARM mode, so if the branch is in Thumb mode, another
3839 Thumb->ARM stub will be inserted later just before the ARM
3840 PLT stub. We don't take this extra distance into account
3841 here, because if a long branch stub is needed, we'll add a
3842 Thumb->Arm one and branch directly to the ARM PLT entry
3843 because it avoids spreading offset corrections in several
3846 destination = (splt->output_section->vma
3847 + splt->output_offset
3848 + root_plt->offset);
3850 branch_type = ST_BRANCH_TO_ARM;
3853 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
3854 BFD_ASSERT (st_type != STT_GNU_IFUNC);
3856 branch_offset = (bfd_signed_vma)(destination - location);
3858 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24
3859 || r_type == R_ARM_THM_TLS_CALL || r_type == R_ARM_THM_JUMP19)
3861 /* Handle cases where:
3862 - this call goes too far (different Thumb/Thumb2 max
3864 - it's a Thumb->Arm call and blx is not available, or it's a
3865 Thumb->Arm branch (not bl). A stub is needed in this case,
3866 but only if this call is not through a PLT entry. Indeed,
3867 PLT stubs handle mode switching already.
3870 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
3871 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
3873 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
3874 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
3876 && (branch_offset > THM2_MAX_FWD_COND_BRANCH_OFFSET
3877 || (branch_offset < THM2_MAX_BWD_COND_BRANCH_OFFSET))
3878 && (r_type == R_ARM_THM_JUMP19))
3879 || (branch_type == ST_BRANCH_TO_ARM
3880 && (((r_type == R_ARM_THM_CALL
3881 || r_type == R_ARM_THM_TLS_CALL) && !globals->use_blx)
3882 || (r_type == R_ARM_THM_JUMP24)
3883 || (r_type == R_ARM_THM_JUMP19))
3886 if (branch_type == ST_BRANCH_TO_THUMB)
3888 /* Thumb to thumb. */
3891 stub_type = (bfd_link_pic (info) | globals->pic_veneer)
3893 ? ((globals->use_blx
3894 && (r_type == R_ARM_THM_CALL))
3895 /* V5T and above. Stub starts with ARM code, so
3896 we must be able to switch mode before
3897 reaching it, which is only possible for 'bl'
3898 (ie R_ARM_THM_CALL relocation). */
3899 ? arm_stub_long_branch_any_thumb_pic
3900 /* On V4T, use Thumb code only. */
3901 : arm_stub_long_branch_v4t_thumb_thumb_pic)
3903 /* non-PIC stubs. */
3904 : ((globals->use_blx
3905 && (r_type == R_ARM_THM_CALL))
3906 /* V5T and above. */
3907 ? arm_stub_long_branch_any_any
3909 : arm_stub_long_branch_v4t_thumb_thumb);
3913 stub_type = (bfd_link_pic (info) | globals->pic_veneer)
3915 ? arm_stub_long_branch_thumb_only_pic
3917 : arm_stub_long_branch_thumb_only;
3924 && sym_sec->owner != NULL
3925 && !INTERWORK_FLAG (sym_sec->owner))
3927 (*_bfd_error_handler)
3928 (_("%B(%s): warning: interworking not enabled.\n"
3929 " first occurrence: %B: Thumb call to ARM"),
3930 sym_sec->owner, input_bfd, name);
3934 (bfd_link_pic (info) | globals->pic_veneer)
3936 ? (r_type == R_ARM_THM_TLS_CALL
3937 /* TLS PIC stubs. */
3938 ? (globals->use_blx ? arm_stub_long_branch_any_tls_pic
3939 : arm_stub_long_branch_v4t_thumb_tls_pic)
3940 : ((globals->use_blx && r_type == R_ARM_THM_CALL)
3941 /* V5T PIC and above. */
3942 ? arm_stub_long_branch_any_arm_pic
3944 : arm_stub_long_branch_v4t_thumb_arm_pic))
3946 /* non-PIC stubs. */
3947 : ((globals->use_blx && r_type == R_ARM_THM_CALL)
3948 /* V5T and above. */
3949 ? arm_stub_long_branch_any_any
3951 : arm_stub_long_branch_v4t_thumb_arm);
3953 /* Handle v4t short branches. */
3954 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
3955 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
3956 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
3957 stub_type = arm_stub_short_branch_v4t_thumb_arm;
3961 else if (r_type == R_ARM_CALL
3962 || r_type == R_ARM_JUMP24
3963 || r_type == R_ARM_PLT32
3964 || r_type == R_ARM_TLS_CALL)
3966 if (branch_type == ST_BRANCH_TO_THUMB)
3971 && sym_sec->owner != NULL
3972 && !INTERWORK_FLAG (sym_sec->owner))
3974 (*_bfd_error_handler)
3975 (_("%B(%s): warning: interworking not enabled.\n"
3976 " first occurrence: %B: ARM call to Thumb"),
3977 sym_sec->owner, input_bfd, name);
3980 /* We have an extra 2-bytes reach because of
3981 the mode change (bit 24 (H) of BLX encoding). */
3982 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
3983 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
3984 || (r_type == R_ARM_CALL && !globals->use_blx)
3985 || (r_type == R_ARM_JUMP24)
3986 || (r_type == R_ARM_PLT32))
3988 stub_type = (bfd_link_pic (info) | globals->pic_veneer)
3990 ? ((globals->use_blx)
3991 /* V5T and above. */
3992 ? arm_stub_long_branch_any_thumb_pic
3994 : arm_stub_long_branch_v4t_arm_thumb_pic)
3996 /* non-PIC stubs. */
3997 : ((globals->use_blx)
3998 /* V5T and above. */
3999 ? arm_stub_long_branch_any_any
4001 : arm_stub_long_branch_v4t_arm_thumb);
4007 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
4008 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
4011 (bfd_link_pic (info) | globals->pic_veneer)
4013 ? (r_type == R_ARM_TLS_CALL
4015 ? arm_stub_long_branch_any_tls_pic
4017 ? arm_stub_long_branch_arm_nacl_pic
4018 : arm_stub_long_branch_any_arm_pic))
4019 /* non-PIC stubs. */
4021 ? arm_stub_long_branch_arm_nacl
4022 : arm_stub_long_branch_any_any);
4027 /* If a stub is needed, record the actual destination type. */
4028 if (stub_type != arm_stub_none)
4029 *actual_branch_type = branch_type;
4034 /* Build a name for an entry in the stub hash table. */
4037 elf32_arm_stub_name (const asection *input_section,
4038 const asection *sym_sec,
4039 const struct elf32_arm_link_hash_entry *hash,
4040 const Elf_Internal_Rela *rel,
4041 enum elf32_arm_stub_type stub_type)
4048 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1 + 2 + 1;
4049 stub_name = (char *) bfd_malloc (len);
4050 if (stub_name != NULL)
4051 sprintf (stub_name, "%08x_%s+%x_%d",
4052 input_section->id & 0xffffffff,
4053 hash->root.root.root.string,
4054 (int) rel->r_addend & 0xffffffff,
4059 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
4060 stub_name = (char *) bfd_malloc (len);
4061 if (stub_name != NULL)
4062 sprintf (stub_name, "%08x_%x:%x+%x_%d",
4063 input_section->id & 0xffffffff,
4064 sym_sec->id & 0xffffffff,
4065 ELF32_R_TYPE (rel->r_info) == R_ARM_TLS_CALL
4066 || ELF32_R_TYPE (rel->r_info) == R_ARM_THM_TLS_CALL
4067 ? 0 : (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
4068 (int) rel->r_addend & 0xffffffff,
4075 /* Look up an entry in the stub hash. Stub entries are cached because
4076 creating the stub name takes a bit of time. */
4078 static struct elf32_arm_stub_hash_entry *
4079 elf32_arm_get_stub_entry (const asection *input_section,
4080 const asection *sym_sec,
4081 struct elf_link_hash_entry *hash,
4082 const Elf_Internal_Rela *rel,
4083 struct elf32_arm_link_hash_table *htab,
4084 enum elf32_arm_stub_type stub_type)
4086 struct elf32_arm_stub_hash_entry *stub_entry;
4087 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
4088 const asection *id_sec;
4090 if ((input_section->flags & SEC_CODE) == 0)
4093 /* If this input section is part of a group of sections sharing one
4094 stub section, then use the id of the first section in the group.
4095 Stub names need to include a section id, as there may well be
4096 more than one stub used to reach say, printf, and we need to
4097 distinguish between them. */
4098 id_sec = htab->stub_group[input_section->id].link_sec;
4100 if (h != NULL && h->stub_cache != NULL
4101 && h->stub_cache->h == h
4102 && h->stub_cache->id_sec == id_sec
4103 && h->stub_cache->stub_type == stub_type)
4105 stub_entry = h->stub_cache;
4111 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel, stub_type);
4112 if (stub_name == NULL)
4115 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
4116 stub_name, FALSE, FALSE);
4118 h->stub_cache = stub_entry;
4126 /* Find or create a stub section. Returns a pointer to the stub section, and
4127 the section to which the stub section will be attached (in *LINK_SEC_P).
4128 LINK_SEC_P may be NULL. */
4131 elf32_arm_create_or_find_stub_sec (asection **link_sec_p, asection *section,
4132 struct elf32_arm_link_hash_table *htab)
4137 link_sec = htab->stub_group[section->id].link_sec;
4138 BFD_ASSERT (link_sec != NULL);
4139 stub_sec = htab->stub_group[section->id].stub_sec;
4141 if (stub_sec == NULL)
4143 stub_sec = htab->stub_group[link_sec->id].stub_sec;
4144 if (stub_sec == NULL)
4150 namelen = strlen (link_sec->name);
4151 len = namelen + sizeof (STUB_SUFFIX);
4152 s_name = (char *) bfd_alloc (htab->stub_bfd, len);
4156 memcpy (s_name, link_sec->name, namelen);
4157 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
4158 stub_sec = (*htab->add_stub_section) (s_name, link_sec,
4159 htab->nacl_p ? 4 : 3);
4160 if (stub_sec == NULL)
4162 htab->stub_group[link_sec->id].stub_sec = stub_sec;
4164 htab->stub_group[section->id].stub_sec = stub_sec;
4168 *link_sec_p = link_sec;
4173 /* Add a new stub entry to the stub hash. Not all fields of the new
4174 stub entry are initialised. */
4176 static struct elf32_arm_stub_hash_entry *
4177 elf32_arm_add_stub (const char *stub_name,
4179 struct elf32_arm_link_hash_table *htab)
4183 struct elf32_arm_stub_hash_entry *stub_entry;
4185 stub_sec = elf32_arm_create_or_find_stub_sec (&link_sec, section, htab);
4186 if (stub_sec == NULL)
4189 /* Enter this entry into the linker stub hash table. */
4190 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4192 if (stub_entry == NULL)
4194 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
4200 stub_entry->stub_sec = stub_sec;
4201 stub_entry->stub_offset = 0;
4202 stub_entry->id_sec = link_sec;
4207 /* Store an Arm insn into an output section not processed by
4208 elf32_arm_write_section. */
4211 put_arm_insn (struct elf32_arm_link_hash_table * htab,
4212 bfd * output_bfd, bfd_vma val, void * ptr)
4214 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4215 bfd_putl32 (val, ptr);
4217 bfd_putb32 (val, ptr);
4220 /* Store a 16-bit Thumb insn into an output section not processed by
4221 elf32_arm_write_section. */
4224 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
4225 bfd * output_bfd, bfd_vma val, void * ptr)
4227 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4228 bfd_putl16 (val, ptr);
4230 bfd_putb16 (val, ptr);
4233 /* Store a Thumb2 insn into an output section not processed by
4234 elf32_arm_write_section. */
4237 put_thumb2_insn (struct elf32_arm_link_hash_table * htab,
4238 bfd * output_bfd, bfd_vma val, void * ptr)
4240 /* T2 instructions are 16-bit streamed. */
4241 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4243 bfd_putl16 ((val >> 16) & 0xffff, ptr);
4244 bfd_putl16 ((val & 0xffff), ptr + 2);
4248 bfd_putb16 ((val >> 16) & 0xffff, ptr);
4249 bfd_putb16 ((val & 0xffff), ptr + 2);
4253 /* If it's possible to change R_TYPE to a more efficient access
4254 model, return the new reloc type. */
4257 elf32_arm_tls_transition (struct bfd_link_info *info, int r_type,
4258 struct elf_link_hash_entry *h)
4260 int is_local = (h == NULL);
4262 if (bfd_link_pic (info)
4263 || (h && h->root.type == bfd_link_hash_undefweak))
4266 /* We do not support relaxations for Old TLS models. */
4269 case R_ARM_TLS_GOTDESC:
4270 case R_ARM_TLS_CALL:
4271 case R_ARM_THM_TLS_CALL:
4272 case R_ARM_TLS_DESCSEQ:
4273 case R_ARM_THM_TLS_DESCSEQ:
4274 return is_local ? R_ARM_TLS_LE32 : R_ARM_TLS_IE32;
4280 static bfd_reloc_status_type elf32_arm_final_link_relocate
4281 (reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
4282 Elf_Internal_Rela *, bfd_vma, struct bfd_link_info *, asection *,
4283 const char *, unsigned char, enum arm_st_branch_type,
4284 struct elf_link_hash_entry *, bfd_boolean *, char **);
4287 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type)
4291 case arm_stub_a8_veneer_b_cond:
4292 case arm_stub_a8_veneer_b:
4293 case arm_stub_a8_veneer_bl:
4296 case arm_stub_long_branch_any_any:
4297 case arm_stub_long_branch_v4t_arm_thumb:
4298 case arm_stub_long_branch_thumb_only:
4299 case arm_stub_long_branch_v4t_thumb_thumb:
4300 case arm_stub_long_branch_v4t_thumb_arm:
4301 case arm_stub_short_branch_v4t_thumb_arm:
4302 case arm_stub_long_branch_any_arm_pic:
4303 case arm_stub_long_branch_any_thumb_pic:
4304 case arm_stub_long_branch_v4t_thumb_thumb_pic:
4305 case arm_stub_long_branch_v4t_arm_thumb_pic:
4306 case arm_stub_long_branch_v4t_thumb_arm_pic:
4307 case arm_stub_long_branch_thumb_only_pic:
4308 case arm_stub_long_branch_any_tls_pic:
4309 case arm_stub_long_branch_v4t_thumb_tls_pic:
4310 case arm_stub_a8_veneer_blx:
4313 case arm_stub_long_branch_arm_nacl:
4314 case arm_stub_long_branch_arm_nacl_pic:
4318 abort (); /* Should be unreachable. */
4323 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
4327 struct elf32_arm_stub_hash_entry *stub_entry;
4328 struct elf32_arm_link_hash_table *globals;
4329 struct bfd_link_info *info;
4336 const insn_sequence *template_sequence;
4338 int stub_reloc_idx[MAXRELOCS] = {-1, -1};
4339 int stub_reloc_offset[MAXRELOCS] = {0, 0};
4342 /* Massage our args to the form they really have. */
4343 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
4344 info = (struct bfd_link_info *) in_arg;
4346 globals = elf32_arm_hash_table (info);
4347 if (globals == NULL)
4350 stub_sec = stub_entry->stub_sec;
4352 if ((globals->fix_cortex_a8 < 0)
4353 != (arm_stub_required_alignment (stub_entry->stub_type) == 2))
4354 /* We have to do less-strictly-aligned fixes last. */
4357 /* Make a note of the offset within the stubs for this entry. */
4358 stub_entry->stub_offset = stub_sec->size;
4359 loc = stub_sec->contents + stub_entry->stub_offset;
4361 stub_bfd = stub_sec->owner;
4363 /* This is the address of the stub destination. */
4364 sym_value = (stub_entry->target_value
4365 + stub_entry->target_section->output_offset
4366 + stub_entry->target_section->output_section->vma);
4368 template_sequence = stub_entry->stub_template;
4369 template_size = stub_entry->stub_template_size;
4372 for (i = 0; i < template_size; i++)
4374 switch (template_sequence[i].type)
4378 bfd_vma data = (bfd_vma) template_sequence[i].data;
4379 if (template_sequence[i].reloc_addend != 0)
4381 /* We've borrowed the reloc_addend field to mean we should
4382 insert a condition code into this (Thumb-1 branch)
4383 instruction. See THUMB16_BCOND_INSN. */
4384 BFD_ASSERT ((data & 0xff00) == 0xd000);
4385 data |= ((stub_entry->orig_insn >> 22) & 0xf) << 8;
4387 bfd_put_16 (stub_bfd, data, loc + size);
4393 bfd_put_16 (stub_bfd,
4394 (template_sequence[i].data >> 16) & 0xffff,
4396 bfd_put_16 (stub_bfd, template_sequence[i].data & 0xffff,
4398 if (template_sequence[i].r_type != R_ARM_NONE)
4400 stub_reloc_idx[nrelocs] = i;
4401 stub_reloc_offset[nrelocs++] = size;
4407 bfd_put_32 (stub_bfd, template_sequence[i].data,
4409 /* Handle cases where the target is encoded within the
4411 if (template_sequence[i].r_type == R_ARM_JUMP24)
4413 stub_reloc_idx[nrelocs] = i;
4414 stub_reloc_offset[nrelocs++] = size;
4420 bfd_put_32 (stub_bfd, template_sequence[i].data, loc + size);
4421 stub_reloc_idx[nrelocs] = i;
4422 stub_reloc_offset[nrelocs++] = size;
4432 stub_sec->size += size;
4434 /* Stub size has already been computed in arm_size_one_stub. Check
4436 BFD_ASSERT (size == stub_entry->stub_size);
4438 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
4439 if (stub_entry->branch_type == ST_BRANCH_TO_THUMB)
4442 /* Assume there is at least one and at most MAXRELOCS entries to relocate
4444 BFD_ASSERT (nrelocs != 0 && nrelocs <= MAXRELOCS);
4446 for (i = 0; i < nrelocs; i++)
4447 if (template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP24
4448 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_JUMP19
4449 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_CALL
4450 || template_sequence[stub_reloc_idx[i]].r_type == R_ARM_THM_XPC22)
4452 Elf_Internal_Rela rel;
4453 bfd_boolean unresolved_reloc;
4454 char *error_message;
4455 enum arm_st_branch_type branch_type
4456 = (template_sequence[stub_reloc_idx[i]].r_type != R_ARM_THM_XPC22
4457 ? ST_BRANCH_TO_THUMB : ST_BRANCH_TO_ARM);
4458 bfd_vma points_to = sym_value + stub_entry->target_addend;
4460 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i];
4461 rel.r_info = ELF32_R_INFO (0,
4462 template_sequence[stub_reloc_idx[i]].r_type);
4463 rel.r_addend = template_sequence[stub_reloc_idx[i]].reloc_addend;
4465 if (stub_entry->stub_type == arm_stub_a8_veneer_b_cond && i == 0)
4466 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
4467 template should refer back to the instruction after the original
4469 points_to = sym_value;
4471 /* There may be unintended consequences if this is not true. */
4472 BFD_ASSERT (stub_entry->h == NULL);
4474 /* Note: _bfd_final_link_relocate doesn't handle these relocations
4475 properly. We should probably use this function unconditionally,
4476 rather than only for certain relocations listed in the enclosing
4477 conditional, for the sake of consistency. */
4478 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4479 (template_sequence[stub_reloc_idx[i]].r_type),
4480 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel,
4481 points_to, info, stub_entry->target_section, "", STT_FUNC,
4482 branch_type, (struct elf_link_hash_entry *) stub_entry->h,
4483 &unresolved_reloc, &error_message);
4487 Elf_Internal_Rela rel;
4488 bfd_boolean unresolved_reloc;
4489 char *error_message;
4490 bfd_vma points_to = sym_value + stub_entry->target_addend
4491 + template_sequence[stub_reloc_idx[i]].reloc_addend;
4493 rel.r_offset = stub_entry->stub_offset + stub_reloc_offset[i];
4494 rel.r_info = ELF32_R_INFO (0,
4495 template_sequence[stub_reloc_idx[i]].r_type);
4498 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4499 (template_sequence[stub_reloc_idx[i]].r_type),
4500 stub_bfd, info->output_bfd, stub_sec, stub_sec->contents, &rel,
4501 points_to, info, stub_entry->target_section, "", STT_FUNC,
4502 stub_entry->branch_type,
4503 (struct elf_link_hash_entry *) stub_entry->h, &unresolved_reloc,
4511 /* Calculate the template, template size and instruction size for a stub.
4512 Return value is the instruction size. */
4515 find_stub_size_and_template (enum elf32_arm_stub_type stub_type,
4516 const insn_sequence **stub_template,
4517 int *stub_template_size)
4519 const insn_sequence *template_sequence = NULL;
4520 int template_size = 0, i;
4523 template_sequence = stub_definitions[stub_type].template_sequence;
4525 *stub_template = template_sequence;
4527 template_size = stub_definitions[stub_type].template_size;
4528 if (stub_template_size)
4529 *stub_template_size = template_size;
4532 for (i = 0; i < template_size; i++)
4534 switch (template_sequence[i].type)
4555 /* As above, but don't actually build the stub. Just bump offset so
4556 we know stub section sizes. */
4559 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
4560 void *in_arg ATTRIBUTE_UNUSED)
4562 struct elf32_arm_stub_hash_entry *stub_entry;
4563 const insn_sequence *template_sequence;
4564 int template_size, size;
4566 /* Massage our args to the form they really have. */
4567 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
4569 BFD_ASSERT((stub_entry->stub_type > arm_stub_none)
4570 && stub_entry->stub_type < ARRAY_SIZE(stub_definitions));
4572 size = find_stub_size_and_template (stub_entry->stub_type, &template_sequence,
4575 stub_entry->stub_size = size;
4576 stub_entry->stub_template = template_sequence;
4577 stub_entry->stub_template_size = template_size;
4579 size = (size + 7) & ~7;
4580 stub_entry->stub_sec->size += size;
4585 /* External entry points for sizing and building linker stubs. */
4587 /* Set up various things so that we can make a list of input sections
4588 for each output section included in the link. Returns -1 on error,
4589 0 when no stubs will be needed, and 1 on success. */
4592 elf32_arm_setup_section_lists (bfd *output_bfd,
4593 struct bfd_link_info *info)
4596 unsigned int bfd_count;
4597 unsigned int top_id, top_index;
4599 asection **input_list, **list;
4601 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4605 if (! is_elf_hash_table (htab))
4608 /* Count the number of input BFDs and find the top input section id. */
4609 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
4611 input_bfd = input_bfd->link.next)
4614 for (section = input_bfd->sections;
4616 section = section->next)
4618 if (top_id < section->id)
4619 top_id = section->id;
4622 htab->bfd_count = bfd_count;
4624 amt = sizeof (struct map_stub) * (top_id + 1);
4625 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4626 if (htab->stub_group == NULL)
4628 htab->top_id = top_id;
4630 /* We can't use output_bfd->section_count here to find the top output
4631 section index as some sections may have been removed, and
4632 _bfd_strip_section_from_output doesn't renumber the indices. */
4633 for (section = output_bfd->sections, top_index = 0;
4635 section = section->next)
4637 if (top_index < section->index)
4638 top_index = section->index;
4641 htab->top_index = top_index;
4642 amt = sizeof (asection *) * (top_index + 1);
4643 input_list = (asection **) bfd_malloc (amt);
4644 htab->input_list = input_list;
4645 if (input_list == NULL)
4648 /* For sections we aren't interested in, mark their entries with a
4649 value we can check later. */
4650 list = input_list + top_index;
4652 *list = bfd_abs_section_ptr;
4653 while (list-- != input_list);
4655 for (section = output_bfd->sections;
4657 section = section->next)
4659 if ((section->flags & SEC_CODE) != 0)
4660 input_list[section->index] = NULL;
4666 /* The linker repeatedly calls this function for each input section,
4667 in the order that input sections are linked into output sections.
4668 Build lists of input sections to determine groupings between which
4669 we may insert linker stubs. */
4672 elf32_arm_next_input_section (struct bfd_link_info *info,
4675 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4680 if (isec->output_section->index <= htab->top_index)
4682 asection **list = htab->input_list + isec->output_section->index;
4684 if (*list != bfd_abs_section_ptr && (isec->flags & SEC_CODE) != 0)
4686 /* Steal the link_sec pointer for our list. */
4687 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4688 /* This happens to make the list in reverse order,
4689 which we reverse later. */
4690 PREV_SEC (isec) = *list;
4696 /* See whether we can group stub sections together. Grouping stub
4697 sections may result in fewer stubs. More importantly, we need to
4698 put all .init* and .fini* stubs at the end of the .init or
4699 .fini output sections respectively, because glibc splits the
4700 _init and _fini functions into multiple parts. Putting a stub in
4701 the middle of a function is not a good idea. */
4704 group_sections (struct elf32_arm_link_hash_table *htab,
4705 bfd_size_type stub_group_size,
4706 bfd_boolean stubs_always_after_branch)
4708 asection **list = htab->input_list;
4712 asection *tail = *list;
4715 if (tail == bfd_abs_section_ptr)
4718 /* Reverse the list: we must avoid placing stubs at the
4719 beginning of the section because the beginning of the text
4720 section may be required for an interrupt vector in bare metal
4722 #define NEXT_SEC PREV_SEC
4724 while (tail != NULL)
4726 /* Pop from tail. */
4727 asection *item = tail;
4728 tail = PREV_SEC (item);
4731 NEXT_SEC (item) = head;
4735 while (head != NULL)
4739 bfd_vma stub_group_start = head->output_offset;
4740 bfd_vma end_of_next;
4743 while (NEXT_SEC (curr) != NULL)
4745 next = NEXT_SEC (curr);
4746 end_of_next = next->output_offset + next->size;
4747 if (end_of_next - stub_group_start >= stub_group_size)
4748 /* End of NEXT is too far from start, so stop. */
4750 /* Add NEXT to the group. */
4754 /* OK, the size from the start to the start of CURR is less
4755 than stub_group_size and thus can be handled by one stub
4756 section. (Or the head section is itself larger than
4757 stub_group_size, in which case we may be toast.)
4758 We should really be keeping track of the total size of
4759 stubs added here, as stubs contribute to the final output
4763 next = NEXT_SEC (head);
4764 /* Set up this stub group. */
4765 htab->stub_group[head->id].link_sec = curr;
4767 while (head != curr && (head = next) != NULL);
4769 /* But wait, there's more! Input sections up to stub_group_size
4770 bytes after the stub section can be handled by it too. */
4771 if (!stubs_always_after_branch)
4773 stub_group_start = curr->output_offset + curr->size;
4775 while (next != NULL)
4777 end_of_next = next->output_offset + next->size;
4778 if (end_of_next - stub_group_start >= stub_group_size)
4779 /* End of NEXT is too far from stubs, so stop. */
4781 /* Add NEXT to the stub group. */
4783 next = NEXT_SEC (head);
4784 htab->stub_group[head->id].link_sec = curr;
4790 while (list++ != htab->input_list + htab->top_index);
4792 free (htab->input_list);
4797 /* Comparison function for sorting/searching relocations relating to Cortex-A8
4801 a8_reloc_compare (const void *a, const void *b)
4803 const struct a8_erratum_reloc *ra = (const struct a8_erratum_reloc *) a;
4804 const struct a8_erratum_reloc *rb = (const struct a8_erratum_reloc *) b;
4806 if (ra->from < rb->from)
4808 else if (ra->from > rb->from)
4814 static struct elf_link_hash_entry *find_thumb_glue (struct bfd_link_info *,
4815 const char *, char **);
4817 /* Helper function to scan code for sequences which might trigger the Cortex-A8
4818 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
4819 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
4823 cortex_a8_erratum_scan (bfd *input_bfd,
4824 struct bfd_link_info *info,
4825 struct a8_erratum_fix **a8_fixes_p,
4826 unsigned int *num_a8_fixes_p,
4827 unsigned int *a8_fix_table_size_p,
4828 struct a8_erratum_reloc *a8_relocs,
4829 unsigned int num_a8_relocs,
4830 unsigned prev_num_a8_fixes,
4831 bfd_boolean *stub_changed_p)
4834 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
4835 struct a8_erratum_fix *a8_fixes = *a8_fixes_p;
4836 unsigned int num_a8_fixes = *num_a8_fixes_p;
4837 unsigned int a8_fix_table_size = *a8_fix_table_size_p;
4842 for (section = input_bfd->sections;
4844 section = section->next)
4846 bfd_byte *contents = NULL;
4847 struct _arm_elf_section_data *sec_data;
4851 if (elf_section_type (section) != SHT_PROGBITS
4852 || (elf_section_flags (section) & SHF_EXECINSTR) == 0
4853 || (section->flags & SEC_EXCLUDE) != 0
4854 || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
4855 || (section->output_section == bfd_abs_section_ptr))
4858 base_vma = section->output_section->vma + section->output_offset;
4860 if (elf_section_data (section)->this_hdr.contents != NULL)
4861 contents = elf_section_data (section)->this_hdr.contents;
4862 else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
4865 sec_data = elf32_arm_section_data (section);
4867 for (span = 0; span < sec_data->mapcount; span++)
4869 unsigned int span_start = sec_data->map[span].vma;
4870 unsigned int span_end = (span == sec_data->mapcount - 1)
4871 ? section->size : sec_data->map[span + 1].vma;
4873 char span_type = sec_data->map[span].type;
4874 bfd_boolean last_was_32bit = FALSE, last_was_branch = FALSE;
4876 if (span_type != 't')
4879 /* Span is entirely within a single 4KB region: skip scanning. */
4880 if (((base_vma + span_start) & ~0xfff)
4881 == ((base_vma + span_end) & ~0xfff))
4884 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
4886 * The opcode is BLX.W, BL.W, B.W, Bcc.W
4887 * The branch target is in the same 4KB region as the
4888 first half of the branch.
4889 * The instruction before the branch is a 32-bit
4890 length non-branch instruction. */
4891 for (i = span_start; i < span_end;)
4893 unsigned int insn = bfd_getl16 (&contents[i]);
4894 bfd_boolean insn_32bit = FALSE, is_blx = FALSE, is_b = FALSE;
4895 bfd_boolean is_bl = FALSE, is_bcc = FALSE, is_32bit_branch;
4897 if ((insn & 0xe000) == 0xe000 && (insn & 0x1800) != 0x0000)
4902 /* Load the rest of the insn (in manual-friendly order). */
4903 insn = (insn << 16) | bfd_getl16 (&contents[i + 2]);
4905 /* Encoding T4: B<c>.W. */
4906 is_b = (insn & 0xf800d000) == 0xf0009000;
4907 /* Encoding T1: BL<c>.W. */
4908 is_bl = (insn & 0xf800d000) == 0xf000d000;
4909 /* Encoding T2: BLX<c>.W. */
4910 is_blx = (insn & 0xf800d000) == 0xf000c000;
4911 /* Encoding T3: B<c>.W (not permitted in IT block). */
4912 is_bcc = (insn & 0xf800d000) == 0xf0008000
4913 && (insn & 0x07f00000) != 0x03800000;
4916 is_32bit_branch = is_b || is_bl || is_blx || is_bcc;
4918 if (((base_vma + i) & 0xfff) == 0xffe
4922 && ! last_was_branch)
4924 bfd_signed_vma offset = 0;
4925 bfd_boolean force_target_arm = FALSE;
4926 bfd_boolean force_target_thumb = FALSE;
4928 enum elf32_arm_stub_type stub_type = arm_stub_none;
4929 struct a8_erratum_reloc key, *found;
4930 bfd_boolean use_plt = FALSE;
4932 key.from = base_vma + i;
4933 found = (struct a8_erratum_reloc *)
4934 bsearch (&key, a8_relocs, num_a8_relocs,
4935 sizeof (struct a8_erratum_reloc),
4940 char *error_message = NULL;
4941 struct elf_link_hash_entry *entry;
4943 /* We don't care about the error returned from this
4944 function, only if there is glue or not. */
4945 entry = find_thumb_glue (info, found->sym_name,
4949 found->non_a8_stub = TRUE;
4951 /* Keep a simpler condition, for the sake of clarity. */
4952 if (htab->root.splt != NULL && found->hash != NULL
4953 && found->hash->root.plt.offset != (bfd_vma) -1)
4956 if (found->r_type == R_ARM_THM_CALL)
4958 if (found->branch_type == ST_BRANCH_TO_ARM
4960 force_target_arm = TRUE;
4962 force_target_thumb = TRUE;
4966 /* Check if we have an offending branch instruction. */
4968 if (found && found->non_a8_stub)
4969 /* We've already made a stub for this instruction, e.g.
4970 it's a long branch or a Thumb->ARM stub. Assume that
4971 stub will suffice to work around the A8 erratum (see
4972 setting of always_after_branch above). */
4976 offset = (insn & 0x7ff) << 1;
4977 offset |= (insn & 0x3f0000) >> 4;
4978 offset |= (insn & 0x2000) ? 0x40000 : 0;
4979 offset |= (insn & 0x800) ? 0x80000 : 0;
4980 offset |= (insn & 0x4000000) ? 0x100000 : 0;
4981 if (offset & 0x100000)
4982 offset |= ~ ((bfd_signed_vma) 0xfffff);
4983 stub_type = arm_stub_a8_veneer_b_cond;
4985 else if (is_b || is_bl || is_blx)
4987 int s = (insn & 0x4000000) != 0;
4988 int j1 = (insn & 0x2000) != 0;
4989 int j2 = (insn & 0x800) != 0;
4993 offset = (insn & 0x7ff) << 1;
4994 offset |= (insn & 0x3ff0000) >> 4;
4998 if (offset & 0x1000000)
4999 offset |= ~ ((bfd_signed_vma) 0xffffff);
5002 offset &= ~ ((bfd_signed_vma) 3);
5004 stub_type = is_blx ? arm_stub_a8_veneer_blx :
5005 is_bl ? arm_stub_a8_veneer_bl : arm_stub_a8_veneer_b;
5008 if (stub_type != arm_stub_none)
5010 bfd_vma pc_for_insn = base_vma + i + 4;
5012 /* The original instruction is a BL, but the target is
5013 an ARM instruction. If we were not making a stub,
5014 the BL would have been converted to a BLX. Use the
5015 BLX stub instead in that case. */
5016 if (htab->use_blx && force_target_arm
5017 && stub_type == arm_stub_a8_veneer_bl)
5019 stub_type = arm_stub_a8_veneer_blx;
5023 /* Conversely, if the original instruction was
5024 BLX but the target is Thumb mode, use the BL
5026 else if (force_target_thumb
5027 && stub_type == arm_stub_a8_veneer_blx)
5029 stub_type = arm_stub_a8_veneer_bl;
5035 pc_for_insn &= ~ ((bfd_vma) 3);
5037 /* If we found a relocation, use the proper destination,
5038 not the offset in the (unrelocated) instruction.
5039 Note this is always done if we switched the stub type
5043 (bfd_signed_vma) (found->destination - pc_for_insn);
5045 /* If the stub will use a Thumb-mode branch to a
5046 PLT target, redirect it to the preceding Thumb
5048 if (stub_type != arm_stub_a8_veneer_blx && use_plt)
5049 offset -= PLT_THUMB_STUB_SIZE;
5051 target = pc_for_insn + offset;
5053 /* The BLX stub is ARM-mode code. Adjust the offset to
5054 take the different PC value (+8 instead of +4) into
5056 if (stub_type == arm_stub_a8_veneer_blx)
5059 if (((base_vma + i) & ~0xfff) == (target & ~0xfff))
5061 char *stub_name = NULL;
5063 if (num_a8_fixes == a8_fix_table_size)
5065 a8_fix_table_size *= 2;
5066 a8_fixes = (struct a8_erratum_fix *)
5067 bfd_realloc (a8_fixes,
5068 sizeof (struct a8_erratum_fix)
5069 * a8_fix_table_size);
5072 if (num_a8_fixes < prev_num_a8_fixes)
5074 /* If we're doing a subsequent scan,
5075 check if we've found the same fix as
5076 before, and try and reuse the stub
5078 stub_name = a8_fixes[num_a8_fixes].stub_name;
5079 if ((a8_fixes[num_a8_fixes].section != section)
5080 || (a8_fixes[num_a8_fixes].offset != i))
5084 *stub_changed_p = TRUE;
5090 stub_name = (char *) bfd_malloc (8 + 1 + 8 + 1);
5091 if (stub_name != NULL)
5092 sprintf (stub_name, "%x:%x", section->id, i);
5095 a8_fixes[num_a8_fixes].input_bfd = input_bfd;
5096 a8_fixes[num_a8_fixes].section = section;
5097 a8_fixes[num_a8_fixes].offset = i;
5098 a8_fixes[num_a8_fixes].addend = offset;
5099 a8_fixes[num_a8_fixes].orig_insn = insn;
5100 a8_fixes[num_a8_fixes].stub_name = stub_name;
5101 a8_fixes[num_a8_fixes].stub_type = stub_type;
5102 a8_fixes[num_a8_fixes].branch_type =
5103 is_blx ? ST_BRANCH_TO_ARM : ST_BRANCH_TO_THUMB;
5110 i += insn_32bit ? 4 : 2;
5111 last_was_32bit = insn_32bit;
5112 last_was_branch = is_32bit_branch;
5116 if (elf_section_data (section)->this_hdr.contents == NULL)
5120 *a8_fixes_p = a8_fixes;
5121 *num_a8_fixes_p = num_a8_fixes;
5122 *a8_fix_table_size_p = a8_fix_table_size;
5127 /* Determine and set the size of the stub section for a final link.
5129 The basic idea here is to examine all the relocations looking for
5130 PC-relative calls to a target that is unreachable with a "bl"
5134 elf32_arm_size_stubs (bfd *output_bfd,
5136 struct bfd_link_info *info,
5137 bfd_signed_vma group_size,
5138 asection * (*add_stub_section) (const char *, asection *,
5140 void (*layout_sections_again) (void))
5142 bfd_size_type stub_group_size;
5143 bfd_boolean stubs_always_after_branch;
5144 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
5145 struct a8_erratum_fix *a8_fixes = NULL;
5146 unsigned int num_a8_fixes = 0, a8_fix_table_size = 10;
5147 struct a8_erratum_reloc *a8_relocs = NULL;
5148 unsigned int num_a8_relocs = 0, a8_reloc_table_size = 10, i;
5153 if (htab->fix_cortex_a8)
5155 a8_fixes = (struct a8_erratum_fix *)
5156 bfd_zmalloc (sizeof (struct a8_erratum_fix) * a8_fix_table_size);
5157 a8_relocs = (struct a8_erratum_reloc *)
5158 bfd_zmalloc (sizeof (struct a8_erratum_reloc) * a8_reloc_table_size);
5161 /* Propagate mach to stub bfd, because it may not have been
5162 finalized when we created stub_bfd. */
5163 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
5164 bfd_get_mach (output_bfd));
5166 /* Stash our params away. */
5167 htab->stub_bfd = stub_bfd;
5168 htab->add_stub_section = add_stub_section;
5169 htab->layout_sections_again = layout_sections_again;
5170 stubs_always_after_branch = group_size < 0;
5172 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
5173 as the first half of a 32-bit branch straddling two 4K pages. This is a
5174 crude way of enforcing that. */
5175 if (htab->fix_cortex_a8)
5176 stubs_always_after_branch = 1;
5179 stub_group_size = -group_size;
5181 stub_group_size = group_size;
5183 if (stub_group_size == 1)
5185 /* Default values. */
5186 /* Thumb branch range is +-4MB has to be used as the default
5187 maximum size (a given section can contain both ARM and Thumb
5188 code, so the worst case has to be taken into account).
5190 This value is 24K less than that, which allows for 2025
5191 12-byte stubs. If we exceed that, then we will fail to link.
5192 The user will have to relink with an explicit group size
5194 stub_group_size = 4170000;
5197 group_sections (htab, stub_group_size, stubs_always_after_branch);
5199 /* If we're applying the cortex A8 fix, we need to determine the
5200 program header size now, because we cannot change it later --
5201 that could alter section placements. Notice the A8 erratum fix
5202 ends up requiring the section addresses to remain unchanged
5203 modulo the page size. That's something we cannot represent
5204 inside BFD, and we don't want to force the section alignment to
5205 be the page size. */
5206 if (htab->fix_cortex_a8)
5207 (*htab->layout_sections_again) ();
5212 unsigned int bfd_indx;
5214 bfd_boolean stub_changed = FALSE;
5215 unsigned prev_num_a8_fixes = num_a8_fixes;
5218 for (input_bfd = info->input_bfds, bfd_indx = 0;
5220 input_bfd = input_bfd->link.next, bfd_indx++)
5222 Elf_Internal_Shdr *symtab_hdr;
5224 Elf_Internal_Sym *local_syms = NULL;
5226 if (!is_arm_elf (input_bfd))
5231 /* We'll need the symbol table in a second. */
5232 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5233 if (symtab_hdr->sh_info == 0)
5236 /* Walk over each section attached to the input bfd. */
5237 for (section = input_bfd->sections;
5239 section = section->next)
5241 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
5243 /* If there aren't any relocs, then there's nothing more
5245 if ((section->flags & SEC_RELOC) == 0
5246 || section->reloc_count == 0
5247 || (section->flags & SEC_CODE) == 0)
5250 /* If this section is a link-once section that will be
5251 discarded, then don't create any stubs. */
5252 if (section->output_section == NULL
5253 || section->output_section->owner != output_bfd)
5256 /* Get the relocs. */
5258 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
5259 NULL, info->keep_memory);
5260 if (internal_relocs == NULL)
5261 goto error_ret_free_local;
5263 /* Now examine each relocation. */
5264 irela = internal_relocs;
5265 irelaend = irela + section->reloc_count;
5266 for (; irela < irelaend; irela++)
5268 unsigned int r_type, r_indx;
5269 enum elf32_arm_stub_type stub_type;
5270 struct elf32_arm_stub_hash_entry *stub_entry;
5273 bfd_vma destination;
5274 struct elf32_arm_link_hash_entry *hash;
5275 const char *sym_name;
5277 const asection *id_sec;
5278 unsigned char st_type;
5279 enum arm_st_branch_type branch_type;
5280 bfd_boolean created_stub = FALSE;
5282 r_type = ELF32_R_TYPE (irela->r_info);
5283 r_indx = ELF32_R_SYM (irela->r_info);
5285 if (r_type >= (unsigned int) R_ARM_max)
5287 bfd_set_error (bfd_error_bad_value);
5288 error_ret_free_internal:
5289 if (elf_section_data (section)->relocs == NULL)
5290 free (internal_relocs);
5291 goto error_ret_free_local;
5295 if (r_indx >= symtab_hdr->sh_info)
5296 hash = elf32_arm_hash_entry
5297 (elf_sym_hashes (input_bfd)
5298 [r_indx - symtab_hdr->sh_info]);
5300 /* Only look for stubs on branch instructions, or
5301 non-relaxed TLSCALL */
5302 if ((r_type != (unsigned int) R_ARM_CALL)
5303 && (r_type != (unsigned int) R_ARM_THM_CALL)
5304 && (r_type != (unsigned int) R_ARM_JUMP24)
5305 && (r_type != (unsigned int) R_ARM_THM_JUMP19)
5306 && (r_type != (unsigned int) R_ARM_THM_XPC22)
5307 && (r_type != (unsigned int) R_ARM_THM_JUMP24)
5308 && (r_type != (unsigned int) R_ARM_PLT32)
5309 && !((r_type == (unsigned int) R_ARM_TLS_CALL
5310 || r_type == (unsigned int) R_ARM_THM_TLS_CALL)
5311 && r_type == elf32_arm_tls_transition
5312 (info, r_type, &hash->root)
5313 && ((hash ? hash->tls_type
5314 : (elf32_arm_local_got_tls_type
5315 (input_bfd)[r_indx]))
5316 & GOT_TLS_GDESC) != 0))
5319 /* Now determine the call target, its name, value,
5326 if (r_type == (unsigned int) R_ARM_TLS_CALL
5327 || r_type == (unsigned int) R_ARM_THM_TLS_CALL)
5329 /* A non-relaxed TLS call. The target is the
5330 plt-resident trampoline and nothing to do
5332 BFD_ASSERT (htab->tls_trampoline > 0);
5333 sym_sec = htab->root.splt;
5334 sym_value = htab->tls_trampoline;
5337 branch_type = ST_BRANCH_TO_ARM;
5341 /* It's a local symbol. */
5342 Elf_Internal_Sym *sym;
5344 if (local_syms == NULL)
5347 = (Elf_Internal_Sym *) symtab_hdr->contents;
5348 if (local_syms == NULL)
5350 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5351 symtab_hdr->sh_info, 0,
5353 if (local_syms == NULL)
5354 goto error_ret_free_internal;
5357 sym = local_syms + r_indx;
5358 if (sym->st_shndx == SHN_UNDEF)
5359 sym_sec = bfd_und_section_ptr;
5360 else if (sym->st_shndx == SHN_ABS)
5361 sym_sec = bfd_abs_section_ptr;
5362 else if (sym->st_shndx == SHN_COMMON)
5363 sym_sec = bfd_com_section_ptr;
5366 bfd_section_from_elf_index (input_bfd, sym->st_shndx);
5369 /* This is an undefined symbol. It can never
5373 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
5374 sym_value = sym->st_value;
5375 destination = (sym_value + irela->r_addend
5376 + sym_sec->output_offset
5377 + sym_sec->output_section->vma);
5378 st_type = ELF_ST_TYPE (sym->st_info);
5379 branch_type = ARM_SYM_BRANCH_TYPE (sym);
5381 = bfd_elf_string_from_elf_section (input_bfd,
5382 symtab_hdr->sh_link,
5387 /* It's an external symbol. */
5388 while (hash->root.root.type == bfd_link_hash_indirect
5389 || hash->root.root.type == bfd_link_hash_warning)
5390 hash = ((struct elf32_arm_link_hash_entry *)
5391 hash->root.root.u.i.link);
5393 if (hash->root.root.type == bfd_link_hash_defined
5394 || hash->root.root.type == bfd_link_hash_defweak)
5396 sym_sec = hash->root.root.u.def.section;
5397 sym_value = hash->root.root.u.def.value;
5399 struct elf32_arm_link_hash_table *globals =
5400 elf32_arm_hash_table (info);
5402 /* For a destination in a shared library,
5403 use the PLT stub as target address to
5404 decide whether a branch stub is
5407 && globals->root.splt != NULL
5409 && hash->root.plt.offset != (bfd_vma) -1)
5411 sym_sec = globals->root.splt;
5412 sym_value = hash->root.plt.offset;
5413 if (sym_sec->output_section != NULL)
5414 destination = (sym_value
5415 + sym_sec->output_offset
5416 + sym_sec->output_section->vma);
5418 else if (sym_sec->output_section != NULL)
5419 destination = (sym_value + irela->r_addend
5420 + sym_sec->output_offset
5421 + sym_sec->output_section->vma);
5423 else if ((hash->root.root.type == bfd_link_hash_undefined)
5424 || (hash->root.root.type == bfd_link_hash_undefweak))
5426 /* For a shared library, use the PLT stub as
5427 target address to decide whether a long
5428 branch stub is needed.
5429 For absolute code, they cannot be handled. */
5430 struct elf32_arm_link_hash_table *globals =
5431 elf32_arm_hash_table (info);
5434 && globals->root.splt != NULL
5436 && hash->root.plt.offset != (bfd_vma) -1)
5438 sym_sec = globals->root.splt;
5439 sym_value = hash->root.plt.offset;
5440 if (sym_sec->output_section != NULL)
5441 destination = (sym_value
5442 + sym_sec->output_offset
5443 + sym_sec->output_section->vma);
5450 bfd_set_error (bfd_error_bad_value);
5451 goto error_ret_free_internal;
5453 st_type = hash->root.type;
5454 branch_type = hash->root.target_internal;
5455 sym_name = hash->root.root.root.string;
5460 /* Determine what (if any) linker stub is needed. */
5461 stub_type = arm_type_of_stub (info, section, irela,
5462 st_type, &branch_type,
5463 hash, destination, sym_sec,
5464 input_bfd, sym_name);
5465 if (stub_type == arm_stub_none)
5468 /* Support for grouping stub sections. */
5469 id_sec = htab->stub_group[section->id].link_sec;
5471 /* Get the name of this stub. */
5472 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash,
5475 goto error_ret_free_internal;
5477 /* We've either created a stub for this reloc already,
5478 or we are about to. */
5479 created_stub = TRUE;
5481 stub_entry = arm_stub_hash_lookup
5482 (&htab->stub_hash_table, stub_name,
5484 if (stub_entry != NULL)
5486 /* The proper stub has already been created. */
5488 stub_entry->target_value = sym_value;
5492 stub_entry = elf32_arm_add_stub (stub_name, section,
5494 if (stub_entry == NULL)
5497 goto error_ret_free_internal;
5500 stub_entry->target_value = sym_value;
5501 stub_entry->target_section = sym_sec;
5502 stub_entry->stub_type = stub_type;
5503 stub_entry->h = hash;
5504 stub_entry->branch_type = branch_type;
5506 if (sym_name == NULL)
5507 sym_name = "unnamed";
5508 stub_entry->output_name = (char *)
5509 bfd_alloc (htab->stub_bfd,
5510 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
5511 + strlen (sym_name));
5512 if (stub_entry->output_name == NULL)
5515 goto error_ret_free_internal;
5518 /* For historical reasons, use the existing names for
5519 ARM-to-Thumb and Thumb-to-ARM stubs. */
5520 if ((r_type == (unsigned int) R_ARM_THM_CALL
5521 || r_type == (unsigned int) R_ARM_THM_JUMP24
5522 || r_type == (unsigned int) R_ARM_THM_JUMP19)
5523 && branch_type == ST_BRANCH_TO_ARM)
5524 sprintf (stub_entry->output_name,
5525 THUMB2ARM_GLUE_ENTRY_NAME, sym_name);
5526 else if ((r_type == (unsigned int) R_ARM_CALL
5527 || r_type == (unsigned int) R_ARM_JUMP24)
5528 && branch_type == ST_BRANCH_TO_THUMB)
5529 sprintf (stub_entry->output_name,
5530 ARM2THUMB_GLUE_ENTRY_NAME, sym_name);
5532 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
5535 stub_changed = TRUE;
5539 /* Look for relocations which might trigger Cortex-A8
5541 if (htab->fix_cortex_a8
5542 && (r_type == (unsigned int) R_ARM_THM_JUMP24
5543 || r_type == (unsigned int) R_ARM_THM_JUMP19
5544 || r_type == (unsigned int) R_ARM_THM_CALL
5545 || r_type == (unsigned int) R_ARM_THM_XPC22))
5547 bfd_vma from = section->output_section->vma
5548 + section->output_offset
5551 if ((from & 0xfff) == 0xffe)
5553 /* Found a candidate. Note we haven't checked the
5554 destination is within 4K here: if we do so (and
5555 don't create an entry in a8_relocs) we can't tell
5556 that a branch should have been relocated when
5558 if (num_a8_relocs == a8_reloc_table_size)
5560 a8_reloc_table_size *= 2;
5561 a8_relocs = (struct a8_erratum_reloc *)
5562 bfd_realloc (a8_relocs,
5563 sizeof (struct a8_erratum_reloc)
5564 * a8_reloc_table_size);
5567 a8_relocs[num_a8_relocs].from = from;
5568 a8_relocs[num_a8_relocs].destination = destination;
5569 a8_relocs[num_a8_relocs].r_type = r_type;
5570 a8_relocs[num_a8_relocs].branch_type = branch_type;
5571 a8_relocs[num_a8_relocs].sym_name = sym_name;
5572 a8_relocs[num_a8_relocs].non_a8_stub = created_stub;
5573 a8_relocs[num_a8_relocs].hash = hash;
5580 /* We're done with the internal relocs, free them. */
5581 if (elf_section_data (section)->relocs == NULL)
5582 free (internal_relocs);
5585 if (htab->fix_cortex_a8)
5587 /* Sort relocs which might apply to Cortex-A8 erratum. */
5588 qsort (a8_relocs, num_a8_relocs,
5589 sizeof (struct a8_erratum_reloc),
5592 /* Scan for branches which might trigger Cortex-A8 erratum. */
5593 if (cortex_a8_erratum_scan (input_bfd, info, &a8_fixes,
5594 &num_a8_fixes, &a8_fix_table_size,
5595 a8_relocs, num_a8_relocs,
5596 prev_num_a8_fixes, &stub_changed)
5598 goto error_ret_free_local;
5602 if (prev_num_a8_fixes != num_a8_fixes)
5603 stub_changed = TRUE;
5608 /* OK, we've added some stubs. Find out the new size of the
5610 for (stub_sec = htab->stub_bfd->sections;
5612 stub_sec = stub_sec->next)
5614 /* Ignore non-stub sections. */
5615 if (!strstr (stub_sec->name, STUB_SUFFIX))
5621 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
5623 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
5624 if (htab->fix_cortex_a8)
5625 for (i = 0; i < num_a8_fixes; i++)
5627 stub_sec = elf32_arm_create_or_find_stub_sec (NULL,
5628 a8_fixes[i].section, htab);
5630 if (stub_sec == NULL)
5631 goto error_ret_free_local;
5634 += find_stub_size_and_template (a8_fixes[i].stub_type, NULL,
5639 /* Ask the linker to do its stuff. */
5640 (*htab->layout_sections_again) ();
5643 /* Add stubs for Cortex-A8 erratum fixes now. */
5644 if (htab->fix_cortex_a8)
5646 for (i = 0; i < num_a8_fixes; i++)
5648 struct elf32_arm_stub_hash_entry *stub_entry;
5649 char *stub_name = a8_fixes[i].stub_name;
5650 asection *section = a8_fixes[i].section;
5651 unsigned int section_id = a8_fixes[i].section->id;
5652 asection *link_sec = htab->stub_group[section_id].link_sec;
5653 asection *stub_sec = htab->stub_group[section_id].stub_sec;
5654 const insn_sequence *template_sequence;
5655 int template_size, size = 0;
5657 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
5659 if (stub_entry == NULL)
5661 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
5667 stub_entry->stub_sec = stub_sec;
5668 stub_entry->stub_offset = 0;
5669 stub_entry->id_sec = link_sec;
5670 stub_entry->stub_type = a8_fixes[i].stub_type;
5671 stub_entry->target_section = a8_fixes[i].section;
5672 stub_entry->target_value = a8_fixes[i].offset;
5673 stub_entry->target_addend = a8_fixes[i].addend;
5674 stub_entry->orig_insn = a8_fixes[i].orig_insn;
5675 stub_entry->branch_type = a8_fixes[i].branch_type;
5677 size = find_stub_size_and_template (a8_fixes[i].stub_type,
5681 stub_entry->stub_size = size;
5682 stub_entry->stub_template = template_sequence;
5683 stub_entry->stub_template_size = template_size;
5686 /* Stash the Cortex-A8 erratum fix array for use later in
5687 elf32_arm_write_section(). */
5688 htab->a8_erratum_fixes = a8_fixes;
5689 htab->num_a8_erratum_fixes = num_a8_fixes;
5693 htab->a8_erratum_fixes = NULL;
5694 htab->num_a8_erratum_fixes = 0;
5698 error_ret_free_local:
5702 /* Build all the stubs associated with the current output file. The
5703 stubs are kept in a hash table attached to the main linker hash
5704 table. We also set up the .plt entries for statically linked PIC
5705 functions here. This function is called via arm_elf_finish in the
5709 elf32_arm_build_stubs (struct bfd_link_info *info)
5712 struct bfd_hash_table *table;
5713 struct elf32_arm_link_hash_table *htab;
5715 htab = elf32_arm_hash_table (info);
5719 for (stub_sec = htab->stub_bfd->sections;
5721 stub_sec = stub_sec->next)
5725 /* Ignore non-stub sections. */
5726 if (!strstr (stub_sec->name, STUB_SUFFIX))
5729 /* Allocate memory to hold the linker stubs. */
5730 size = stub_sec->size;
5731 stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
5732 if (stub_sec->contents == NULL && size != 0)
5737 /* Build the stubs as directed by the stub hash table. */
5738 table = &htab->stub_hash_table;
5739 bfd_hash_traverse (table, arm_build_one_stub, info);
5740 if (htab->fix_cortex_a8)
5742 /* Place the cortex a8 stubs last. */
5743 htab->fix_cortex_a8 = -1;
5744 bfd_hash_traverse (table, arm_build_one_stub, info);
5750 /* Locate the Thumb encoded calling stub for NAME. */
5752 static struct elf_link_hash_entry *
5753 find_thumb_glue (struct bfd_link_info *link_info,
5755 char **error_message)
5758 struct elf_link_hash_entry *hash;
5759 struct elf32_arm_link_hash_table *hash_table;
5761 /* We need a pointer to the armelf specific hash table. */
5762 hash_table = elf32_arm_hash_table (link_info);
5763 if (hash_table == NULL)
5766 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5767 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
5769 BFD_ASSERT (tmp_name);
5771 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
5773 hash = elf_link_hash_lookup
5774 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
5777 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
5778 tmp_name, name) == -1)
5779 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
5786 /* Locate the ARM encoded calling stub for NAME. */
5788 static struct elf_link_hash_entry *
5789 find_arm_glue (struct bfd_link_info *link_info,
5791 char **error_message)
5794 struct elf_link_hash_entry *myh;
5795 struct elf32_arm_link_hash_table *hash_table;
5797 /* We need a pointer to the elfarm specific hash table. */
5798 hash_table = elf32_arm_hash_table (link_info);
5799 if (hash_table == NULL)
5802 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5803 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
5805 BFD_ASSERT (tmp_name);
5807 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
5809 myh = elf_link_hash_lookup
5810 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
5813 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
5814 tmp_name, name) == -1)
5815 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
5822 /* ARM->Thumb glue (static images):
5826 ldr r12, __func_addr
5829 .word func @ behave as if you saw a ARM_32 reloc.
5836 .word func @ behave as if you saw a ARM_32 reloc.
5838 (relocatable images)
5841 ldr r12, __func_offset
5847 #define ARM2THUMB_STATIC_GLUE_SIZE 12
5848 static const insn32 a2t1_ldr_insn = 0xe59fc000;
5849 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
5850 static const insn32 a2t3_func_addr_insn = 0x00000001;
5852 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
5853 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
5854 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
5856 #define ARM2THUMB_PIC_GLUE_SIZE 16
5857 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
5858 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
5859 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
5861 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
5865 __func_from_thumb: __func_from_thumb:
5867 nop ldr r6, __func_addr
5877 #define THUMB2ARM_GLUE_SIZE 8
5878 static const insn16 t2a1_bx_pc_insn = 0x4778;
5879 static const insn16 t2a2_noop_insn = 0x46c0;
5880 static const insn32 t2a3_b_insn = 0xea000000;
5882 #define VFP11_ERRATUM_VENEER_SIZE 8
5883 #define STM32L4XX_ERRATUM_LDM_VENEER_SIZE 16
5884 #define STM32L4XX_ERRATUM_VLDM_VENEER_SIZE 24
5886 #define ARM_BX_VENEER_SIZE 12
5887 static const insn32 armbx1_tst_insn = 0xe3100001;
5888 static const insn32 armbx2_moveq_insn = 0x01a0f000;
5889 static const insn32 armbx3_bx_insn = 0xe12fff10;
5891 #ifndef ELFARM_NABI_C_INCLUDED
5893 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
5896 bfd_byte * contents;
5900 /* Do not include empty glue sections in the output. */
5903 s = bfd_get_linker_section (abfd, name);
5905 s->flags |= SEC_EXCLUDE;
5910 BFD_ASSERT (abfd != NULL);
5912 s = bfd_get_linker_section (abfd, name);
5913 BFD_ASSERT (s != NULL);
5915 contents = (bfd_byte *) bfd_alloc (abfd, size);
5917 BFD_ASSERT (s->size == size);
5918 s->contents = contents;
5922 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
5924 struct elf32_arm_link_hash_table * globals;
5926 globals = elf32_arm_hash_table (info);
5927 BFD_ASSERT (globals != NULL);
5929 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5930 globals->arm_glue_size,
5931 ARM2THUMB_GLUE_SECTION_NAME);
5933 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5934 globals->thumb_glue_size,
5935 THUMB2ARM_GLUE_SECTION_NAME);
5937 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5938 globals->vfp11_erratum_glue_size,
5939 VFP11_ERRATUM_VENEER_SECTION_NAME);
5941 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5942 globals->stm32l4xx_erratum_glue_size,
5943 STM32L4XX_ERRATUM_VENEER_SECTION_NAME);
5945 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
5946 globals->bx_glue_size,
5947 ARM_BX_GLUE_SECTION_NAME);
5952 /* Allocate space and symbols for calling a Thumb function from Arm mode.
5953 returns the symbol identifying the stub. */
5955 static struct elf_link_hash_entry *
5956 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
5957 struct elf_link_hash_entry * h)
5959 const char * name = h->root.root.string;
5962 struct elf_link_hash_entry * myh;
5963 struct bfd_link_hash_entry * bh;
5964 struct elf32_arm_link_hash_table * globals;
5968 globals = elf32_arm_hash_table (link_info);
5969 BFD_ASSERT (globals != NULL);
5970 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5972 s = bfd_get_linker_section
5973 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
5975 BFD_ASSERT (s != NULL);
5977 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
5978 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
5980 BFD_ASSERT (tmp_name);
5982 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
5984 myh = elf_link_hash_lookup
5985 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5989 /* We've already seen this guy. */
5994 /* The only trick here is using hash_table->arm_glue_size as the value.
5995 Even though the section isn't allocated yet, this is where we will be
5996 putting it. The +1 on the value marks that the stub has not been
5997 output yet - not that it is a Thumb function. */
5999 val = globals->arm_glue_size + 1;
6000 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
6001 tmp_name, BSF_GLOBAL, s, val,
6002 NULL, TRUE, FALSE, &bh);
6004 myh = (struct elf_link_hash_entry *) bh;
6005 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6006 myh->forced_local = 1;
6010 if (bfd_link_pic (link_info)
6011 || globals->root.is_relocatable_executable
6012 || globals->pic_veneer)
6013 size = ARM2THUMB_PIC_GLUE_SIZE;
6014 else if (globals->use_blx)
6015 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
6017 size = ARM2THUMB_STATIC_GLUE_SIZE;
6020 globals->arm_glue_size += size;
6025 /* Allocate space for ARMv4 BX veneers. */
6028 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
6031 struct elf32_arm_link_hash_table *globals;
6033 struct elf_link_hash_entry *myh;
6034 struct bfd_link_hash_entry *bh;
6037 /* BX PC does not need a veneer. */
6041 globals = elf32_arm_hash_table (link_info);
6042 BFD_ASSERT (globals != NULL);
6043 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
6045 /* Check if this veneer has already been allocated. */
6046 if (globals->bx_glue_offset[reg])
6049 s = bfd_get_linker_section
6050 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
6052 BFD_ASSERT (s != NULL);
6054 /* Add symbol for veneer. */
6056 bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
6058 BFD_ASSERT (tmp_name);
6060 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
6062 myh = elf_link_hash_lookup
6063 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
6065 BFD_ASSERT (myh == NULL);
6068 val = globals->bx_glue_size;
6069 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
6070 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
6071 NULL, TRUE, FALSE, &bh);
6073 myh = (struct elf_link_hash_entry *) bh;
6074 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6075 myh->forced_local = 1;
6077 s->size += ARM_BX_VENEER_SIZE;
6078 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
6079 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
6083 /* Add an entry to the code/data map for section SEC. */
6086 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
6088 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
6089 unsigned int newidx;
6091 if (sec_data->map == NULL)
6093 sec_data->map = (elf32_arm_section_map *)
6094 bfd_malloc (sizeof (elf32_arm_section_map));
6095 sec_data->mapcount = 0;
6096 sec_data->mapsize = 1;
6099 newidx = sec_data->mapcount++;
6101 if (sec_data->mapcount > sec_data->mapsize)
6103 sec_data->mapsize *= 2;
6104 sec_data->map = (elf32_arm_section_map *)
6105 bfd_realloc_or_free (sec_data->map, sec_data->mapsize
6106 * sizeof (elf32_arm_section_map));
6111 sec_data->map[newidx].vma = vma;
6112 sec_data->map[newidx].type = type;
6117 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
6118 veneers are handled for now. */
6121 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
6122 elf32_vfp11_erratum_list *branch,
6124 asection *branch_sec,
6125 unsigned int offset)
6128 struct elf32_arm_link_hash_table *hash_table;
6130 struct elf_link_hash_entry *myh;
6131 struct bfd_link_hash_entry *bh;
6133 struct _arm_elf_section_data *sec_data;
6134 elf32_vfp11_erratum_list *newerr;
6136 hash_table = elf32_arm_hash_table (link_info);
6137 BFD_ASSERT (hash_table != NULL);
6138 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
6140 s = bfd_get_linker_section
6141 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
6143 sec_data = elf32_arm_section_data (s);
6145 BFD_ASSERT (s != NULL);
6147 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
6148 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
6150 BFD_ASSERT (tmp_name);
6152 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
6153 hash_table->num_vfp11_fixes);
6155 myh = elf_link_hash_lookup
6156 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
6158 BFD_ASSERT (myh == NULL);
6161 val = hash_table->vfp11_erratum_glue_size;
6162 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
6163 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
6164 NULL, TRUE, FALSE, &bh);
6166 myh = (struct elf_link_hash_entry *) bh;
6167 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6168 myh->forced_local = 1;
6170 /* Link veneer back to calling location. */
6171 sec_data->erratumcount += 1;
6172 newerr = (elf32_vfp11_erratum_list *)
6173 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
6175 newerr->type = VFP11_ERRATUM_ARM_VENEER;
6177 newerr->u.v.branch = branch;
6178 newerr->u.v.id = hash_table->num_vfp11_fixes;
6179 branch->u.b.veneer = newerr;
6181 newerr->next = sec_data->erratumlist;
6182 sec_data->erratumlist = newerr;
6184 /* A symbol for the return from the veneer. */
6185 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
6186 hash_table->num_vfp11_fixes);
6188 myh = elf_link_hash_lookup
6189 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
6196 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
6197 branch_sec, val, NULL, TRUE, FALSE, &bh);
6199 myh = (struct elf_link_hash_entry *) bh;
6200 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6201 myh->forced_local = 1;
6205 /* Generate a mapping symbol for the veneer section, and explicitly add an
6206 entry for that symbol to the code/data map for the section. */
6207 if (hash_table->vfp11_erratum_glue_size == 0)
6210 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
6211 ever requires this erratum fix. */
6212 _bfd_generic_link_add_one_symbol (link_info,
6213 hash_table->bfd_of_glue_owner, "$a",
6214 BSF_LOCAL, s, 0, NULL,
6217 myh = (struct elf_link_hash_entry *) bh;
6218 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
6219 myh->forced_local = 1;
6221 /* The elf32_arm_init_maps function only cares about symbols from input
6222 BFDs. We must make a note of this generated mapping symbol
6223 ourselves so that code byteswapping works properly in
6224 elf32_arm_write_section. */
6225 elf32_arm_section_map_add (s, 'a', 0);
6228 s->size += VFP11_ERRATUM_VENEER_SIZE;
6229 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
6230 hash_table->num_vfp11_fixes++;
6232 /* The offset of the veneer. */
6236 /* Record information about a STM32L4XX STM erratum veneer. Only THUMB-mode
6237 veneers need to be handled because used only in Cortex-M. */
6240 record_stm32l4xx_erratum_veneer (struct bfd_link_info *link_info,
6241 elf32_stm32l4xx_erratum_list *branch,
6243 asection *branch_sec,
6244 unsigned int offset,
6245 bfd_size_type veneer_size)
6248 struct elf32_arm_link_hash_table *hash_table;
6250 struct elf_link_hash_entry *myh;
6251 struct bfd_link_hash_entry *bh;
6253 struct _arm_elf_section_data *sec_data;
6254 elf32_stm32l4xx_erratum_list *newerr;
6256 hash_table = elf32_arm_hash_table (link_info);
6257 BFD_ASSERT (hash_table != NULL);
6258 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
6260 s = bfd_get_linker_section
6261 (hash_table->bfd_of_glue_owner, STM32L4XX_ERRATUM_VENEER_SECTION_NAME);
6263 BFD_ASSERT (s != NULL);
6265 sec_data = elf32_arm_section_data (s);
6267 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
6268 (STM32L4XX_ERRATUM_VENEER_ENTRY_NAME) + 10);
6270 BFD_ASSERT (tmp_name);
6272 sprintf (tmp_name, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME,
6273 hash_table->num_stm32l4xx_fixes);
6275 myh = elf_link_hash_lookup
6276 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
6278 BFD_ASSERT (myh == NULL);
6281 val = hash_table->stm32l4xx_erratum_glue_size;
6282 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
6283 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
6284 NULL, TRUE, FALSE, &bh);
6286 myh = (struct elf_link_hash_entry *) bh;
6287 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6288 myh->forced_local = 1;
6290 /* Link veneer back to calling location. */
6291 sec_data->stm32l4xx_erratumcount += 1;
6292 newerr = (elf32_stm32l4xx_erratum_list *)
6293 bfd_zmalloc (sizeof (elf32_stm32l4xx_erratum_list));
6295 newerr->type = STM32L4XX_ERRATUM_VENEER;
6297 newerr->u.v.branch = branch;
6298 newerr->u.v.id = hash_table->num_stm32l4xx_fixes;
6299 branch->u.b.veneer = newerr;
6301 newerr->next = sec_data->stm32l4xx_erratumlist;
6302 sec_data->stm32l4xx_erratumlist = newerr;
6304 /* A symbol for the return from the veneer. */
6305 sprintf (tmp_name, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME "_r",
6306 hash_table->num_stm32l4xx_fixes);
6308 myh = elf_link_hash_lookup
6309 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
6316 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
6317 branch_sec, val, NULL, TRUE, FALSE, &bh);
6319 myh = (struct elf_link_hash_entry *) bh;
6320 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
6321 myh->forced_local = 1;
6325 /* Generate a mapping symbol for the veneer section, and explicitly add an
6326 entry for that symbol to the code/data map for the section. */
6327 if (hash_table->stm32l4xx_erratum_glue_size == 0)
6330 /* Creates a THUMB symbol since there is no other choice. */
6331 _bfd_generic_link_add_one_symbol (link_info,
6332 hash_table->bfd_of_glue_owner, "$t",
6333 BSF_LOCAL, s, 0, NULL,
6336 myh = (struct elf_link_hash_entry *) bh;
6337 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
6338 myh->forced_local = 1;
6340 /* The elf32_arm_init_maps function only cares about symbols from input
6341 BFDs. We must make a note of this generated mapping symbol
6342 ourselves so that code byteswapping works properly in
6343 elf32_arm_write_section. */
6344 elf32_arm_section_map_add (s, 't', 0);
6347 s->size += veneer_size;
6348 hash_table->stm32l4xx_erratum_glue_size += veneer_size;
6349 hash_table->num_stm32l4xx_fixes++;
6351 /* The offset of the veneer. */
6355 #define ARM_GLUE_SECTION_FLAGS \
6356 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
6357 | SEC_READONLY | SEC_LINKER_CREATED)
6359 /* Create a fake section for use by the ARM backend of the linker. */
6362 arm_make_glue_section (bfd * abfd, const char * name)
6366 sec = bfd_get_linker_section (abfd, name);
6371 sec = bfd_make_section_anyway_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
6374 || !bfd_set_section_alignment (abfd, sec, 2))
6377 /* Set the gc mark to prevent the section from being removed by garbage
6378 collection, despite the fact that no relocs refer to this section. */
6384 /* Set size of .plt entries. This function is called from the
6385 linker scripts in ld/emultempl/{armelf}.em. */
6388 bfd_elf32_arm_use_long_plt (void)
6390 elf32_arm_use_long_plt_entry = TRUE;
6393 /* Add the glue sections to ABFD. This function is called from the
6394 linker scripts in ld/emultempl/{armelf}.em. */
6397 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
6398 struct bfd_link_info *info)
6400 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
6401 bfd_boolean dostm32l4xx = globals
6402 && globals->stm32l4xx_fix != BFD_ARM_STM32L4XX_FIX_NONE;
6403 bfd_boolean addglue;
6405 /* If we are only performing a partial
6406 link do not bother adding the glue. */
6407 if (bfd_link_relocatable (info))
6410 addglue = arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
6411 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
6412 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
6413 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
6419 && arm_make_glue_section (abfd, STM32L4XX_ERRATUM_VENEER_SECTION_NAME);
6422 /* Select a BFD to be used to hold the sections used by the glue code.
6423 This function is called from the linker scripts in ld/emultempl/
6427 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
6429 struct elf32_arm_link_hash_table *globals;
6431 /* If we are only performing a partial link
6432 do not bother getting a bfd to hold the glue. */
6433 if (bfd_link_relocatable (info))
6436 /* Make sure we don't attach the glue sections to a dynamic object. */
6437 BFD_ASSERT (!(abfd->flags & DYNAMIC));
6439 globals = elf32_arm_hash_table (info);
6440 BFD_ASSERT (globals != NULL);
6442 if (globals->bfd_of_glue_owner != NULL)
6445 /* Save the bfd for later use. */
6446 globals->bfd_of_glue_owner = abfd;
6452 check_use_blx (struct elf32_arm_link_hash_table *globals)
6456 cpu_arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
6459 if (globals->fix_arm1176)
6461 if (cpu_arch == TAG_CPU_ARCH_V6T2 || cpu_arch > TAG_CPU_ARCH_V6K)
6462 globals->use_blx = 1;
6466 if (cpu_arch > TAG_CPU_ARCH_V4T)
6467 globals->use_blx = 1;
6472 bfd_elf32_arm_process_before_allocation (bfd *abfd,
6473 struct bfd_link_info *link_info)
6475 Elf_Internal_Shdr *symtab_hdr;
6476 Elf_Internal_Rela *internal_relocs = NULL;
6477 Elf_Internal_Rela *irel, *irelend;
6478 bfd_byte *contents = NULL;
6481 struct elf32_arm_link_hash_table *globals;
6483 /* If we are only performing a partial link do not bother
6484 to construct any glue. */
6485 if (bfd_link_relocatable (link_info))
6488 /* Here we have a bfd that is to be included on the link. We have a
6489 hook to do reloc rummaging, before section sizes are nailed down. */
6490 globals = elf32_arm_hash_table (link_info);
6491 BFD_ASSERT (globals != NULL);
6493 check_use_blx (globals);
6495 if (globals->byteswap_code && !bfd_big_endian (abfd))
6497 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
6502 /* PR 5398: If we have not decided to include any loadable sections in
6503 the output then we will not have a glue owner bfd. This is OK, it
6504 just means that there is nothing else for us to do here. */
6505 if (globals->bfd_of_glue_owner == NULL)
6508 /* Rummage around all the relocs and map the glue vectors. */
6509 sec = abfd->sections;
6514 for (; sec != NULL; sec = sec->next)
6516 if (sec->reloc_count == 0)
6519 if ((sec->flags & SEC_EXCLUDE) != 0)
6522 symtab_hdr = & elf_symtab_hdr (abfd);
6524 /* Load the relocs. */
6526 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
6528 if (internal_relocs == NULL)
6531 irelend = internal_relocs + sec->reloc_count;
6532 for (irel = internal_relocs; irel < irelend; irel++)
6535 unsigned long r_index;
6537 struct elf_link_hash_entry *h;
6539 r_type = ELF32_R_TYPE (irel->r_info);
6540 r_index = ELF32_R_SYM (irel->r_info);
6542 /* These are the only relocation types we care about. */
6543 if ( r_type != R_ARM_PC24
6544 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
6547 /* Get the section contents if we haven't done so already. */
6548 if (contents == NULL)
6550 /* Get cached copy if it exists. */
6551 if (elf_section_data (sec)->this_hdr.contents != NULL)
6552 contents = elf_section_data (sec)->this_hdr.contents;
6555 /* Go get them off disk. */
6556 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
6561 if (r_type == R_ARM_V4BX)
6565 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
6566 record_arm_bx_glue (link_info, reg);
6570 /* If the relocation is not against a symbol it cannot concern us. */
6573 /* We don't care about local symbols. */
6574 if (r_index < symtab_hdr->sh_info)
6577 /* This is an external symbol. */
6578 r_index -= symtab_hdr->sh_info;
6579 h = (struct elf_link_hash_entry *)
6580 elf_sym_hashes (abfd)[r_index];
6582 /* If the relocation is against a static symbol it must be within
6583 the current section and so cannot be a cross ARM/Thumb relocation. */
6587 /* If the call will go through a PLT entry then we do not need
6589 if (globals->root.splt != NULL && h->plt.offset != (bfd_vma) -1)
6595 /* This one is a call from arm code. We need to look up
6596 the target of the call. If it is a thumb target, we
6598 if (h->target_internal == ST_BRANCH_TO_THUMB)
6599 record_arm_to_thumb_glue (link_info, h);
6607 if (contents != NULL
6608 && elf_section_data (sec)->this_hdr.contents != contents)
6612 if (internal_relocs != NULL
6613 && elf_section_data (sec)->relocs != internal_relocs)
6614 free (internal_relocs);
6615 internal_relocs = NULL;
6621 if (contents != NULL
6622 && elf_section_data (sec)->this_hdr.contents != contents)
6624 if (internal_relocs != NULL
6625 && elf_section_data (sec)->relocs != internal_relocs)
6626 free (internal_relocs);
6633 /* Initialise maps of ARM/Thumb/data for input BFDs. */
6636 bfd_elf32_arm_init_maps (bfd *abfd)
6638 Elf_Internal_Sym *isymbuf;
6639 Elf_Internal_Shdr *hdr;
6640 unsigned int i, localsyms;
6642 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
6643 if (! is_arm_elf (abfd))
6646 if ((abfd->flags & DYNAMIC) != 0)
6649 hdr = & elf_symtab_hdr (abfd);
6650 localsyms = hdr->sh_info;
6652 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
6653 should contain the number of local symbols, which should come before any
6654 global symbols. Mapping symbols are always local. */
6655 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
6658 /* No internal symbols read? Skip this BFD. */
6659 if (isymbuf == NULL)
6662 for (i = 0; i < localsyms; i++)
6664 Elf_Internal_Sym *isym = &isymbuf[i];
6665 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
6669 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
6671 name = bfd_elf_string_from_elf_section (abfd,
6672 hdr->sh_link, isym->st_name);
6674 if (bfd_is_arm_special_symbol_name (name,
6675 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
6676 elf32_arm_section_map_add (sec, name[1], isym->st_value);
6682 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
6683 say what they wanted. */
6686 bfd_elf32_arm_set_cortex_a8_fix (bfd *obfd, struct bfd_link_info *link_info)
6688 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6689 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
6691 if (globals == NULL)
6694 if (globals->fix_cortex_a8 == -1)
6696 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
6697 if (out_attr[Tag_CPU_arch].i == TAG_CPU_ARCH_V7
6698 && (out_attr[Tag_CPU_arch_profile].i == 'A'
6699 || out_attr[Tag_CPU_arch_profile].i == 0))
6700 globals->fix_cortex_a8 = 1;
6702 globals->fix_cortex_a8 = 0;
6708 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
6710 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6711 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
6713 if (globals == NULL)
6715 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
6716 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
6718 switch (globals->vfp11_fix)
6720 case BFD_ARM_VFP11_FIX_DEFAULT:
6721 case BFD_ARM_VFP11_FIX_NONE:
6722 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
6726 /* Give a warning, but do as the user requests anyway. */
6727 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
6728 "workaround is not necessary for target architecture"), obfd);
6731 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
6732 /* For earlier architectures, we might need the workaround, but do not
6733 enable it by default. If users is running with broken hardware, they
6734 must enable the erratum fix explicitly. */
6735 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
6739 bfd_elf32_arm_set_stm32l4xx_fix (bfd *obfd, struct bfd_link_info *link_info)
6741 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
6742 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
6744 if (globals == NULL)
6747 /* We assume only Cortex-M4 may require the fix. */
6748 if (out_attr[Tag_CPU_arch].i != TAG_CPU_ARCH_V7E_M
6749 || out_attr[Tag_CPU_arch_profile].i != 'M')
6751 if (globals->stm32l4xx_fix != BFD_ARM_STM32L4XX_FIX_NONE)
6752 /* Give a warning, but do as the user requests anyway. */
6753 (*_bfd_error_handler)
6754 (_("%B: warning: selected STM32L4XX erratum "
6755 "workaround is not necessary for target architecture"), obfd);
6759 enum bfd_arm_vfp11_pipe
6767 /* Return a VFP register number. This is encoded as RX:X for single-precision
6768 registers, or X:RX for double-precision registers, where RX is the group of
6769 four bits in the instruction encoding and X is the single extension bit.
6770 RX and X fields are specified using their lowest (starting) bit. The return
6773 0...31: single-precision registers s0...s31
6774 32...63: double-precision registers d0...d31.
6776 Although X should be zero for VFP11 (encoding d0...d15 only), we might
6777 encounter VFP3 instructions, so we allow the full range for DP registers. */
6780 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
6784 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
6786 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
6789 /* Set bits in *WMASK according to a register number REG as encoded by
6790 bfd_arm_vfp11_regno(). Ignore d16-d31. */
6793 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
6798 *wmask |= 3 << ((reg - 32) * 2);
6801 /* Return TRUE if WMASK overwrites anything in REGS. */
6804 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
6808 for (i = 0; i < numregs; i++)
6810 unsigned int reg = regs[i];
6812 if (reg < 32 && (wmask & (1 << reg)) != 0)
6820 if ((wmask & (3 << (reg * 2))) != 0)
6827 /* In this function, we're interested in two things: finding input registers
6828 for VFP data-processing instructions, and finding the set of registers which
6829 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
6830 hold the written set, so FLDM etc. are easy to deal with (we're only
6831 interested in 32 SP registers or 16 dp registers, due to the VFP version
6832 implemented by the chip in question). DP registers are marked by setting
6833 both SP registers in the write mask). */
6835 static enum bfd_arm_vfp11_pipe
6836 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
6839 enum bfd_arm_vfp11_pipe vpipe = VFP11_BAD;
6840 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
6842 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
6845 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
6846 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
6848 pqrs = ((insn & 0x00800000) >> 20)
6849 | ((insn & 0x00300000) >> 19)
6850 | ((insn & 0x00000040) >> 6);
6854 case 0: /* fmac[sd]. */
6855 case 1: /* fnmac[sd]. */
6856 case 2: /* fmsc[sd]. */
6857 case 3: /* fnmsc[sd]. */
6859 bfd_arm_vfp11_write_mask (destmask, fd);
6861 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
6866 case 4: /* fmul[sd]. */
6867 case 5: /* fnmul[sd]. */
6868 case 6: /* fadd[sd]. */
6869 case 7: /* fsub[sd]. */
6873 case 8: /* fdiv[sd]. */
6876 bfd_arm_vfp11_write_mask (destmask, fd);
6877 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
6882 case 15: /* extended opcode. */
6884 unsigned int extn = ((insn >> 15) & 0x1e)
6885 | ((insn >> 7) & 1);
6889 case 0: /* fcpy[sd]. */
6890 case 1: /* fabs[sd]. */
6891 case 2: /* fneg[sd]. */
6892 case 8: /* fcmp[sd]. */
6893 case 9: /* fcmpe[sd]. */
6894 case 10: /* fcmpz[sd]. */
6895 case 11: /* fcmpez[sd]. */
6896 case 16: /* fuito[sd]. */
6897 case 17: /* fsito[sd]. */
6898 case 24: /* ftoui[sd]. */
6899 case 25: /* ftouiz[sd]. */
6900 case 26: /* ftosi[sd]. */
6901 case 27: /* ftosiz[sd]. */
6902 /* These instructions will not bounce due to underflow. */
6907 case 3: /* fsqrt[sd]. */
6908 /* fsqrt cannot underflow, but it can (perhaps) overwrite
6909 registers to cause the erratum in previous instructions. */
6910 bfd_arm_vfp11_write_mask (destmask, fd);
6914 case 15: /* fcvt{ds,sd}. */
6918 bfd_arm_vfp11_write_mask (destmask, fd);
6920 /* Only FCVTSD can underflow. */
6921 if ((insn & 0x100) != 0)
6940 /* Two-register transfer. */
6941 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
6943 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
6945 if ((insn & 0x100000) == 0)
6948 bfd_arm_vfp11_write_mask (destmask, fm);
6951 bfd_arm_vfp11_write_mask (destmask, fm);
6952 bfd_arm_vfp11_write_mask (destmask, fm + 1);
6958 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
6960 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
6961 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
6965 case 0: /* Two-reg transfer. We should catch these above. */
6968 case 2: /* fldm[sdx]. */
6972 unsigned int i, offset = insn & 0xff;
6977 for (i = fd; i < fd + offset; i++)
6978 bfd_arm_vfp11_write_mask (destmask, i);
6982 case 4: /* fld[sd]. */
6984 bfd_arm_vfp11_write_mask (destmask, fd);
6993 /* Single-register transfer. Note L==0. */
6994 else if ((insn & 0x0f100e10) == 0x0e000a10)
6996 unsigned int opcode = (insn >> 21) & 7;
6997 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
7001 case 0: /* fmsr/fmdlr. */
7002 case 1: /* fmdhr. */
7003 /* Mark fmdhr and fmdlr as writing to the whole of the DP
7004 destination register. I don't know if this is exactly right,
7005 but it is the conservative choice. */
7006 bfd_arm_vfp11_write_mask (destmask, fn);
7020 static int elf32_arm_compare_mapping (const void * a, const void * b);
7023 /* Look for potentially-troublesome code sequences which might trigger the
7024 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
7025 (available from ARM) for details of the erratum. A short version is
7026 described in ld.texinfo. */
7029 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
7032 bfd_byte *contents = NULL;
7034 int regs[3], numregs = 0;
7035 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
7036 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
7038 if (globals == NULL)
7041 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
7042 The states transition as follows:
7044 0 -> 1 (vector) or 0 -> 2 (scalar)
7045 A VFP FMAC-pipeline instruction has been seen. Fill
7046 regs[0]..regs[numregs-1] with its input operands. Remember this
7047 instruction in 'first_fmac'.
7050 Any instruction, except for a VFP instruction which overwrites
7055 A VFP instruction has been seen which overwrites any of regs[*].
7056 We must make a veneer! Reset state to 0 before examining next
7060 If we fail to match anything in state 2, reset to state 0 and reset
7061 the instruction pointer to the instruction after 'first_fmac'.
7063 If the VFP11 vector mode is in use, there must be at least two unrelated
7064 instructions between anti-dependent VFP11 instructions to properly avoid
7065 triggering the erratum, hence the use of the extra state 1. */
7067 /* If we are only performing a partial link do not bother
7068 to construct any glue. */
7069 if (bfd_link_relocatable (link_info))
7072 /* Skip if this bfd does not correspond to an ELF image. */
7073 if (! is_arm_elf (abfd))
7076 /* We should have chosen a fix type by the time we get here. */
7077 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
7079 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
7082 /* Skip this BFD if it corresponds to an executable or dynamic object. */
7083 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
7086 for (sec = abfd->sections; sec != NULL; sec = sec->next)
7088 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
7089 struct _arm_elf_section_data *sec_data;
7091 /* If we don't have executable progbits, we're not interested in this
7092 section. Also skip if section is to be excluded. */
7093 if (elf_section_type (sec) != SHT_PROGBITS
7094 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
7095 || (sec->flags & SEC_EXCLUDE) != 0
7096 || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
7097 || sec->output_section == bfd_abs_section_ptr
7098 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
7101 sec_data = elf32_arm_section_data (sec);
7103 if (sec_data->mapcount == 0)
7106 if (elf_section_data (sec)->this_hdr.contents != NULL)
7107 contents = elf_section_data (sec)->this_hdr.contents;
7108 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
7111 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
7112 elf32_arm_compare_mapping);
7114 for (span = 0; span < sec_data->mapcount; span++)
7116 unsigned int span_start = sec_data->map[span].vma;
7117 unsigned int span_end = (span == sec_data->mapcount - 1)
7118 ? sec->size : sec_data->map[span + 1].vma;
7119 char span_type = sec_data->map[span].type;
7121 /* FIXME: Only ARM mode is supported at present. We may need to
7122 support Thumb-2 mode also at some point. */
7123 if (span_type != 'a')
7126 for (i = span_start; i < span_end;)
7128 unsigned int next_i = i + 4;
7129 unsigned int insn = bfd_big_endian (abfd)
7130 ? (contents[i] << 24)
7131 | (contents[i + 1] << 16)
7132 | (contents[i + 2] << 8)
7134 : (contents[i + 3] << 24)
7135 | (contents[i + 2] << 16)
7136 | (contents[i + 1] << 8)
7138 unsigned int writemask = 0;
7139 enum bfd_arm_vfp11_pipe vpipe;
7144 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
7146 /* I'm assuming the VFP11 erratum can trigger with denorm
7147 operands on either the FMAC or the DS pipeline. This might
7148 lead to slightly overenthusiastic veneer insertion. */
7149 if (vpipe == VFP11_FMAC || vpipe == VFP11_DS)
7151 state = use_vector ? 1 : 2;
7153 veneer_of_insn = insn;
7159 int other_regs[3], other_numregs;
7160 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
7163 if (vpipe != VFP11_BAD
7164 && bfd_arm_vfp11_antidependency (writemask, regs,
7174 int other_regs[3], other_numregs;
7175 vpipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
7178 if (vpipe != VFP11_BAD
7179 && bfd_arm_vfp11_antidependency (writemask, regs,
7185 next_i = first_fmac + 4;
7191 abort (); /* Should be unreachable. */
7196 elf32_vfp11_erratum_list *newerr =(elf32_vfp11_erratum_list *)
7197 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
7199 elf32_arm_section_data (sec)->erratumcount += 1;
7201 newerr->u.b.vfp_insn = veneer_of_insn;
7206 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
7213 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
7218 newerr->next = sec_data->erratumlist;
7219 sec_data->erratumlist = newerr;
7228 if (contents != NULL
7229 && elf_section_data (sec)->this_hdr.contents != contents)
7237 if (contents != NULL
7238 && elf_section_data (sec)->this_hdr.contents != contents)
7244 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
7245 after sections have been laid out, using specially-named symbols. */
7248 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
7249 struct bfd_link_info *link_info)
7252 struct elf32_arm_link_hash_table *globals;
7255 if (bfd_link_relocatable (link_info))
7258 /* Skip if this bfd does not correspond to an ELF image. */
7259 if (! is_arm_elf (abfd))
7262 globals = elf32_arm_hash_table (link_info);
7263 if (globals == NULL)
7266 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
7267 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
7269 for (sec = abfd->sections; sec != NULL; sec = sec->next)
7271 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
7272 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
7274 for (; errnode != NULL; errnode = errnode->next)
7276 struct elf_link_hash_entry *myh;
7279 switch (errnode->type)
7281 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
7282 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
7283 /* Find veneer symbol. */
7284 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
7285 errnode->u.b.veneer->u.v.id);
7287 myh = elf_link_hash_lookup
7288 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
7291 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
7292 "`%s'"), abfd, tmp_name);
7294 vma = myh->root.u.def.section->output_section->vma
7295 + myh->root.u.def.section->output_offset
7296 + myh->root.u.def.value;
7298 errnode->u.b.veneer->vma = vma;
7301 case VFP11_ERRATUM_ARM_VENEER:
7302 case VFP11_ERRATUM_THUMB_VENEER:
7303 /* Find return location. */
7304 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
7307 myh = elf_link_hash_lookup
7308 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
7311 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
7312 "`%s'"), abfd, tmp_name);
7314 vma = myh->root.u.def.section->output_section->vma
7315 + myh->root.u.def.section->output_offset
7316 + myh->root.u.def.value;
7318 errnode->u.v.branch->vma = vma;
7330 /* Find virtual-memory addresses for STM32L4XX erratum veneers and
7331 return locations after sections have been laid out, using
7332 specially-named symbols. */
7335 bfd_elf32_arm_stm32l4xx_fix_veneer_locations (bfd *abfd,
7336 struct bfd_link_info *link_info)
7339 struct elf32_arm_link_hash_table *globals;
7342 if (bfd_link_relocatable (link_info))
7345 /* Skip if this bfd does not correspond to an ELF image. */
7346 if (! is_arm_elf (abfd))
7349 globals = elf32_arm_hash_table (link_info);
7350 if (globals == NULL)
7353 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen
7354 (STM32L4XX_ERRATUM_VENEER_ENTRY_NAME) + 10);
7356 for (sec = abfd->sections; sec != NULL; sec = sec->next)
7358 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
7359 elf32_stm32l4xx_erratum_list *errnode = sec_data->stm32l4xx_erratumlist;
7361 for (; errnode != NULL; errnode = errnode->next)
7363 struct elf_link_hash_entry *myh;
7366 switch (errnode->type)
7368 case STM32L4XX_ERRATUM_BRANCH_TO_VENEER:
7369 /* Find veneer symbol. */
7370 sprintf (tmp_name, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME,
7371 errnode->u.b.veneer->u.v.id);
7373 myh = elf_link_hash_lookup
7374 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
7377 (*_bfd_error_handler) (_("%B: unable to find STM32L4XX veneer "
7378 "`%s'"), abfd, tmp_name);
7380 vma = myh->root.u.def.section->output_section->vma
7381 + myh->root.u.def.section->output_offset
7382 + myh->root.u.def.value;
7384 errnode->u.b.veneer->vma = vma;
7387 case STM32L4XX_ERRATUM_VENEER:
7388 /* Find return location. */
7389 sprintf (tmp_name, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME "_r",
7392 myh = elf_link_hash_lookup
7393 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
7396 (*_bfd_error_handler) (_("%B: unable to find STM32L4XX veneer "
7397 "`%s'"), abfd, tmp_name);
7399 vma = myh->root.u.def.section->output_section->vma
7400 + myh->root.u.def.section->output_offset
7401 + myh->root.u.def.value;
7403 errnode->u.v.branch->vma = vma;
7415 static inline bfd_boolean
7416 is_thumb2_ldmia (const insn32 insn)
7418 /* Encoding T2: LDM<c>.W <Rn>{!},<registers>
7419 1110 - 1000 - 10W1 - rrrr - PM (0) l - llll - llll - llll. */
7420 return (insn & 0xffd02000) == 0xe8900000;
7423 static inline bfd_boolean
7424 is_thumb2_ldmdb (const insn32 insn)
7426 /* Encoding T1: LDMDB<c> <Rn>{!},<registers>
7427 1110 - 1001 - 00W1 - rrrr - PM (0) l - llll - llll - llll. */
7428 return (insn & 0xffd02000) == 0xe9100000;
7431 static inline bfd_boolean
7432 is_thumb2_vldm (const insn32 insn)
7434 /* A6.5 Extension register load or store instruction
7436 We look only for the 32-bit registers case since the DP (64-bit
7437 registers) are not supported for STM32L4XX
7438 Encoding T2 VLDM{mode}<c> <Rn>{!}, <list>
7439 <list> is consecutive 32-bit registers
7440 1110 - 110P - UDW1 - rrrr - vvvv - 1010 - iiii - iiii
7441 if P==0 && U==1 && W==1 && Rn=1101 VPOP
7442 if PUW=010 || PUW=011 || PUW=101 VLDM. */
7444 ((insn & 0xfe100f00) == 0xec100a00)
7445 && /* (IA without !). */
7446 (((((insn << 7) >> 28) & 0xd) == 0x4)
7447 /* (IA with !), includes VPOP (when reg number is SP). */
7448 || ((((insn << 7) >> 28) & 0xd) == 0x5)
7450 || ((((insn << 7) >> 28) & 0xd) == 0x9));
7453 /* STM STM32L4XX erratum : This function assumes that it receives an LDM or
7455 - computes the number and the mode of memory accesses
7456 - decides if the replacement should be done:
7457 . replaces only if > 8-word accesses
7458 . or (testing purposes only) replaces all accesses. */
7461 stm32l4xx_need_create_replacing_stub (const insn32 insn,
7462 bfd_arm_stm32l4xx_fix stm32l4xx_fix)
7466 /* The field encoding the register list is the same for both LDMIA
7467 and LDMDB encodings. */
7468 if (is_thumb2_ldmia (insn) || is_thumb2_ldmdb (insn))
7469 nb_regs = popcount (insn & 0x0000ffff);
7470 else if (is_thumb2_vldm (insn))
7471 nb_regs = (insn & 0xff);
7473 /* DEFAULT mode accounts for the real bug condition situation,
7474 ALL mode inserts stubs for each LDM/VLDM instruction (testing). */
7476 (stm32l4xx_fix == BFD_ARM_STM32L4XX_FIX_DEFAULT) ? nb_regs > 8 :
7477 (stm32l4xx_fix == BFD_ARM_STM32L4XX_FIX_ALL) ? TRUE : FALSE;
7480 /* Look for potentially-troublesome code sequences which might trigger
7481 the STM STM32L4XX erratum. */
7484 bfd_elf32_arm_stm32l4xx_erratum_scan (bfd *abfd,
7485 struct bfd_link_info *link_info)
7488 bfd_byte *contents = NULL;
7489 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
7491 if (globals == NULL)
7494 /* If we are only performing a partial link do not bother
7495 to construct any glue. */
7496 if (bfd_link_relocatable (link_info))
7499 /* Skip if this bfd does not correspond to an ELF image. */
7500 if (! is_arm_elf (abfd))
7503 if (globals->stm32l4xx_fix == BFD_ARM_STM32L4XX_FIX_NONE)
7506 /* Skip this BFD if it corresponds to an executable or dynamic object. */
7507 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
7510 for (sec = abfd->sections; sec != NULL; sec = sec->next)
7512 unsigned int i, span;
7513 struct _arm_elf_section_data *sec_data;
7515 /* If we don't have executable progbits, we're not interested in this
7516 section. Also skip if section is to be excluded. */
7517 if (elf_section_type (sec) != SHT_PROGBITS
7518 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
7519 || (sec->flags & SEC_EXCLUDE) != 0
7520 || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
7521 || sec->output_section == bfd_abs_section_ptr
7522 || strcmp (sec->name, STM32L4XX_ERRATUM_VENEER_SECTION_NAME) == 0)
7525 sec_data = elf32_arm_section_data (sec);
7527 if (sec_data->mapcount == 0)
7530 if (elf_section_data (sec)->this_hdr.contents != NULL)
7531 contents = elf_section_data (sec)->this_hdr.contents;
7532 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
7535 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
7536 elf32_arm_compare_mapping);
7538 for (span = 0; span < sec_data->mapcount; span++)
7540 unsigned int span_start = sec_data->map[span].vma;
7541 unsigned int span_end = (span == sec_data->mapcount - 1)
7542 ? sec->size : sec_data->map[span + 1].vma;
7543 char span_type = sec_data->map[span].type;
7544 int itblock_current_pos = 0;
7546 /* Only Thumb2 mode need be supported with this CM4 specific
7547 code, we should not encounter any arm mode eg span_type
7549 if (span_type != 't')
7552 for (i = span_start; i < span_end;)
7554 unsigned int insn = bfd_get_16 (abfd, &contents[i]);
7555 bfd_boolean insn_32bit = FALSE;
7556 bfd_boolean is_ldm = FALSE;
7557 bfd_boolean is_vldm = FALSE;
7558 bfd_boolean is_not_last_in_it_block = FALSE;
7560 /* The first 16-bits of all 32-bit thumb2 instructions start
7561 with opcode[15..13]=0b111 and the encoded op1 can be anything
7562 except opcode[12..11]!=0b00.
7563 See 32-bit Thumb instruction encoding. */
7564 if ((insn & 0xe000) == 0xe000 && (insn & 0x1800) != 0x0000)
7567 /* Compute the predicate that tells if the instruction
7568 is concerned by the IT block
7569 - Creates an error if there is a ldm that is not
7570 last in the IT block thus cannot be replaced
7571 - Otherwise we can create a branch at the end of the
7572 IT block, it will be controlled naturally by IT
7573 with the proper pseudo-predicate
7574 - So the only interesting predicate is the one that
7575 tells that we are not on the last item of an IT
7577 if (itblock_current_pos != 0)
7578 is_not_last_in_it_block = !!--itblock_current_pos;
7582 /* Load the rest of the insn (in manual-friendly order). */
7583 insn = (insn << 16) | bfd_get_16 (abfd, &contents[i + 2]);
7584 is_ldm = is_thumb2_ldmia (insn) || is_thumb2_ldmdb (insn);
7585 is_vldm = is_thumb2_vldm (insn);
7587 /* Veneers are created for (v)ldm depending on
7588 option flags and memory accesses conditions; but
7589 if the instruction is not the last instruction of
7590 an IT block, we cannot create a jump there, so we
7592 if ((is_ldm || is_vldm) &&
7593 stm32l4xx_need_create_replacing_stub
7594 (insn, globals->stm32l4xx_fix))
7596 if (is_not_last_in_it_block)
7598 (*_bfd_error_handler)
7599 /* Note - overlong line used here to allow for translation. */
7601 %B(%A+0x%lx): error: multiple load detected in non-last IT block instruction : STM32L4XX veneer cannot be generated.\n"
7602 "Use gcc option -mrestrict-it to generate only one instruction per IT block.\n"),
7603 abfd, sec, (long)i);
7607 elf32_stm32l4xx_erratum_list *newerr =
7608 (elf32_stm32l4xx_erratum_list *)
7610 (sizeof (elf32_stm32l4xx_erratum_list));
7612 elf32_arm_section_data (sec)
7613 ->stm32l4xx_erratumcount += 1;
7614 newerr->u.b.insn = insn;
7615 /* We create only thumb branches. */
7617 STM32L4XX_ERRATUM_BRANCH_TO_VENEER;
7618 record_stm32l4xx_erratum_veneer
7619 (link_info, newerr, abfd, sec,
7622 STM32L4XX_ERRATUM_LDM_VENEER_SIZE:
7623 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE);
7625 newerr->next = sec_data->stm32l4xx_erratumlist;
7626 sec_data->stm32l4xx_erratumlist = newerr;
7633 IT blocks are only encoded in T1
7634 Encoding T1: IT{x{y{z}}} <firstcond>
7635 1 0 1 1 - 1 1 1 1 - firstcond - mask
7636 if mask = '0000' then see 'related encodings'
7637 We don't deal with UNPREDICTABLE, just ignore these.
7638 There can be no nested IT blocks so an IT block
7639 is naturally a new one for which it is worth
7640 computing its size. */
7641 bfd_boolean is_newitblock = ((insn & 0xff00) == 0xbf00) &&
7642 ((insn & 0x000f) != 0x0000);
7643 /* If we have a new IT block we compute its size. */
7646 /* Compute the number of instructions controlled
7647 by the IT block, it will be used to decide
7648 whether we are inside an IT block or not. */
7649 unsigned int mask = insn & 0x000f;
7650 itblock_current_pos = 4 - ctz (mask);
7654 i += insn_32bit ? 4 : 2;
7658 if (contents != NULL
7659 && elf_section_data (sec)->this_hdr.contents != contents)
7667 if (contents != NULL
7668 && elf_section_data (sec)->this_hdr.contents != contents)
7674 /* Set target relocation values needed during linking. */
7677 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
7678 struct bfd_link_info *link_info,
7680 char * target2_type,
7683 bfd_arm_vfp11_fix vfp11_fix,
7684 bfd_arm_stm32l4xx_fix stm32l4xx_fix,
7685 int no_enum_warn, int no_wchar_warn,
7686 int pic_veneer, int fix_cortex_a8,
7689 struct elf32_arm_link_hash_table *globals;
7691 globals = elf32_arm_hash_table (link_info);
7692 if (globals == NULL)
7695 globals->target1_is_rel = target1_is_rel;
7696 if (strcmp (target2_type, "rel") == 0)
7697 globals->target2_reloc = R_ARM_REL32;
7698 else if (strcmp (target2_type, "abs") == 0)
7699 globals->target2_reloc = R_ARM_ABS32;
7700 else if (strcmp (target2_type, "got-rel") == 0)
7701 globals->target2_reloc = R_ARM_GOT_PREL;
7704 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
7707 globals->fix_v4bx = fix_v4bx;
7708 globals->use_blx |= use_blx;
7709 globals->vfp11_fix = vfp11_fix;
7710 globals->stm32l4xx_fix = stm32l4xx_fix;
7711 globals->pic_veneer = pic_veneer;
7712 globals->fix_cortex_a8 = fix_cortex_a8;
7713 globals->fix_arm1176 = fix_arm1176;
7715 BFD_ASSERT (is_arm_elf (output_bfd));
7716 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
7717 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
7720 /* Replace the target offset of a Thumb bl or b.w instruction. */
7723 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
7729 BFD_ASSERT ((offset & 1) == 0);
7731 upper = bfd_get_16 (abfd, insn);
7732 lower = bfd_get_16 (abfd, insn + 2);
7733 reloc_sign = (offset < 0) ? 1 : 0;
7734 upper = (upper & ~(bfd_vma) 0x7ff)
7735 | ((offset >> 12) & 0x3ff)
7736 | (reloc_sign << 10);
7737 lower = (lower & ~(bfd_vma) 0x2fff)
7738 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
7739 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
7740 | ((offset >> 1) & 0x7ff);
7741 bfd_put_16 (abfd, upper, insn);
7742 bfd_put_16 (abfd, lower, insn + 2);
7745 /* Thumb code calling an ARM function. */
7748 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
7752 asection * input_section,
7753 bfd_byte * hit_data,
7756 bfd_signed_vma addend,
7758 char **error_message)
7762 long int ret_offset;
7763 struct elf_link_hash_entry * myh;
7764 struct elf32_arm_link_hash_table * globals;
7766 myh = find_thumb_glue (info, name, error_message);
7770 globals = elf32_arm_hash_table (info);
7771 BFD_ASSERT (globals != NULL);
7772 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7774 my_offset = myh->root.u.def.value;
7776 s = bfd_get_linker_section (globals->bfd_of_glue_owner,
7777 THUMB2ARM_GLUE_SECTION_NAME);
7779 BFD_ASSERT (s != NULL);
7780 BFD_ASSERT (s->contents != NULL);
7781 BFD_ASSERT (s->output_section != NULL);
7783 if ((my_offset & 0x01) == 0x01)
7786 && sym_sec->owner != NULL
7787 && !INTERWORK_FLAG (sym_sec->owner))
7789 (*_bfd_error_handler)
7790 (_("%B(%s): warning: interworking not enabled.\n"
7791 " first occurrence: %B: Thumb call to ARM"),
7792 sym_sec->owner, input_bfd, name);
7798 myh->root.u.def.value = my_offset;
7800 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
7801 s->contents + my_offset);
7803 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
7804 s->contents + my_offset + 2);
7807 /* Address of destination of the stub. */
7808 ((bfd_signed_vma) val)
7810 /* Offset from the start of the current section
7811 to the start of the stubs. */
7813 /* Offset of the start of this stub from the start of the stubs. */
7815 /* Address of the start of the current section. */
7816 + s->output_section->vma)
7817 /* The branch instruction is 4 bytes into the stub. */
7819 /* ARM branches work from the pc of the instruction + 8. */
7822 put_arm_insn (globals, output_bfd,
7823 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
7824 s->contents + my_offset + 4);
7827 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
7829 /* Now go back and fix up the original BL insn to point to here. */
7831 /* Address of where the stub is located. */
7832 (s->output_section->vma + s->output_offset + my_offset)
7833 /* Address of where the BL is located. */
7834 - (input_section->output_section->vma + input_section->output_offset
7836 /* Addend in the relocation. */
7838 /* Biassing for PC-relative addressing. */
7841 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
7846 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
7848 static struct elf_link_hash_entry *
7849 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
7856 char ** error_message)
7859 long int ret_offset;
7860 struct elf_link_hash_entry * myh;
7861 struct elf32_arm_link_hash_table * globals;
7863 myh = find_arm_glue (info, name, error_message);
7867 globals = elf32_arm_hash_table (info);
7868 BFD_ASSERT (globals != NULL);
7869 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7871 my_offset = myh->root.u.def.value;
7873 if ((my_offset & 0x01) == 0x01)
7876 && sym_sec->owner != NULL
7877 && !INTERWORK_FLAG (sym_sec->owner))
7879 (*_bfd_error_handler)
7880 (_("%B(%s): warning: interworking not enabled.\n"
7881 " first occurrence: %B: arm call to thumb"),
7882 sym_sec->owner, input_bfd, name);
7886 myh->root.u.def.value = my_offset;
7888 if (bfd_link_pic (info)
7889 || globals->root.is_relocatable_executable
7890 || globals->pic_veneer)
7892 /* For relocatable objects we can't use absolute addresses,
7893 so construct the address from a relative offset. */
7894 /* TODO: If the offset is small it's probably worth
7895 constructing the address with adds. */
7896 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
7897 s->contents + my_offset);
7898 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
7899 s->contents + my_offset + 4);
7900 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
7901 s->contents + my_offset + 8);
7902 /* Adjust the offset by 4 for the position of the add,
7903 and 8 for the pipeline offset. */
7904 ret_offset = (val - (s->output_offset
7905 + s->output_section->vma
7908 bfd_put_32 (output_bfd, ret_offset,
7909 s->contents + my_offset + 12);
7911 else if (globals->use_blx)
7913 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
7914 s->contents + my_offset);
7916 /* It's a thumb address. Add the low order bit. */
7917 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
7918 s->contents + my_offset + 4);
7922 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
7923 s->contents + my_offset);
7925 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
7926 s->contents + my_offset + 4);
7928 /* It's a thumb address. Add the low order bit. */
7929 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
7930 s->contents + my_offset + 8);
7936 BFD_ASSERT (my_offset <= globals->arm_glue_size);
7941 /* Arm code calling a Thumb function. */
7944 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
7948 asection * input_section,
7949 bfd_byte * hit_data,
7952 bfd_signed_vma addend,
7954 char **error_message)
7956 unsigned long int tmp;
7959 long int ret_offset;
7960 struct elf_link_hash_entry * myh;
7961 struct elf32_arm_link_hash_table * globals;
7963 globals = elf32_arm_hash_table (info);
7964 BFD_ASSERT (globals != NULL);
7965 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
7967 s = bfd_get_linker_section (globals->bfd_of_glue_owner,
7968 ARM2THUMB_GLUE_SECTION_NAME);
7969 BFD_ASSERT (s != NULL);
7970 BFD_ASSERT (s->contents != NULL);
7971 BFD_ASSERT (s->output_section != NULL);
7973 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
7974 sym_sec, val, s, error_message);
7978 my_offset = myh->root.u.def.value;
7979 tmp = bfd_get_32 (input_bfd, hit_data);
7980 tmp = tmp & 0xFF000000;
7982 /* Somehow these are both 4 too far, so subtract 8. */
7983 ret_offset = (s->output_offset
7985 + s->output_section->vma
7986 - (input_section->output_offset
7987 + input_section->output_section->vma
7991 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
7993 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
7998 /* Populate Arm stub for an exported Thumb function. */
8001 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
8003 struct bfd_link_info * info = (struct bfd_link_info *) inf;
8005 struct elf_link_hash_entry * myh;
8006 struct elf32_arm_link_hash_entry *eh;
8007 struct elf32_arm_link_hash_table * globals;
8010 char *error_message;
8012 eh = elf32_arm_hash_entry (h);
8013 /* Allocate stubs for exported Thumb functions on v4t. */
8014 if (eh->export_glue == NULL)
8017 globals = elf32_arm_hash_table (info);
8018 BFD_ASSERT (globals != NULL);
8019 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
8021 s = bfd_get_linker_section (globals->bfd_of_glue_owner,
8022 ARM2THUMB_GLUE_SECTION_NAME);
8023 BFD_ASSERT (s != NULL);
8024 BFD_ASSERT (s->contents != NULL);
8025 BFD_ASSERT (s->output_section != NULL);
8027 sec = eh->export_glue->root.u.def.section;
8029 BFD_ASSERT (sec->output_section != NULL);
8031 val = eh->export_glue->root.u.def.value + sec->output_offset
8032 + sec->output_section->vma;
8034 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
8035 h->root.u.def.section->owner,
8036 globals->obfd, sec, val, s,
8042 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
8045 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
8050 struct elf32_arm_link_hash_table *globals;
8052 globals = elf32_arm_hash_table (info);
8053 BFD_ASSERT (globals != NULL);
8054 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
8056 s = bfd_get_linker_section (globals->bfd_of_glue_owner,
8057 ARM_BX_GLUE_SECTION_NAME);
8058 BFD_ASSERT (s != NULL);
8059 BFD_ASSERT (s->contents != NULL);
8060 BFD_ASSERT (s->output_section != NULL);
8062 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
8064 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
8066 if ((globals->bx_glue_offset[reg] & 1) == 0)
8068 p = s->contents + glue_addr;
8069 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
8070 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
8071 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
8072 globals->bx_glue_offset[reg] |= 1;
8075 return glue_addr + s->output_section->vma + s->output_offset;
8078 /* Generate Arm stubs for exported Thumb symbols. */
8080 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
8081 struct bfd_link_info *link_info)
8083 struct elf32_arm_link_hash_table * globals;
8085 if (link_info == NULL)
8086 /* Ignore this if we are not called by the ELF backend linker. */
8089 globals = elf32_arm_hash_table (link_info);
8090 if (globals == NULL)
8093 /* If blx is available then exported Thumb symbols are OK and there is
8095 if (globals->use_blx)
8098 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
8102 /* Reserve space for COUNT dynamic relocations in relocation selection
8106 elf32_arm_allocate_dynrelocs (struct bfd_link_info *info, asection *sreloc,
8107 bfd_size_type count)
8109 struct elf32_arm_link_hash_table *htab;
8111 htab = elf32_arm_hash_table (info);
8112 BFD_ASSERT (htab->root.dynamic_sections_created);
8115 sreloc->size += RELOC_SIZE (htab) * count;
8118 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
8119 dynamic, the relocations should go in SRELOC, otherwise they should
8120 go in the special .rel.iplt section. */
8123 elf32_arm_allocate_irelocs (struct bfd_link_info *info, asection *sreloc,
8124 bfd_size_type count)
8126 struct elf32_arm_link_hash_table *htab;
8128 htab = elf32_arm_hash_table (info);
8129 if (!htab->root.dynamic_sections_created)
8130 htab->root.irelplt->size += RELOC_SIZE (htab) * count;
8133 BFD_ASSERT (sreloc != NULL);
8134 sreloc->size += RELOC_SIZE (htab) * count;
8138 /* Add relocation REL to the end of relocation section SRELOC. */
8141 elf32_arm_add_dynreloc (bfd *output_bfd, struct bfd_link_info *info,
8142 asection *sreloc, Elf_Internal_Rela *rel)
8145 struct elf32_arm_link_hash_table *htab;
8147 htab = elf32_arm_hash_table (info);
8148 if (!htab->root.dynamic_sections_created
8149 && ELF32_R_TYPE (rel->r_info) == R_ARM_IRELATIVE)
8150 sreloc = htab->root.irelplt;
8153 loc = sreloc->contents;
8154 loc += sreloc->reloc_count++ * RELOC_SIZE (htab);
8155 if (sreloc->reloc_count * RELOC_SIZE (htab) > sreloc->size)
8157 SWAP_RELOC_OUT (htab) (output_bfd, rel, loc);
8160 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
8161 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
8165 elf32_arm_allocate_plt_entry (struct bfd_link_info *info,
8166 bfd_boolean is_iplt_entry,
8167 union gotplt_union *root_plt,
8168 struct arm_plt_info *arm_plt)
8170 struct elf32_arm_link_hash_table *htab;
8174 htab = elf32_arm_hash_table (info);
8178 splt = htab->root.iplt;
8179 sgotplt = htab->root.igotplt;
8181 /* NaCl uses a special first entry in .iplt too. */
8182 if (htab->nacl_p && splt->size == 0)
8183 splt->size += htab->plt_header_size;
8185 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
8186 elf32_arm_allocate_irelocs (info, htab->root.irelplt, 1);
8190 splt = htab->root.splt;
8191 sgotplt = htab->root.sgotplt;
8193 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
8194 elf32_arm_allocate_dynrelocs (info, htab->root.srelplt, 1);
8196 /* If this is the first .plt entry, make room for the special
8198 if (splt->size == 0)
8199 splt->size += htab->plt_header_size;
8201 htab->next_tls_desc_index++;
8204 /* Allocate the PLT entry itself, including any leading Thumb stub. */
8205 if (elf32_arm_plt_needs_thumb_stub_p (info, arm_plt))
8206 splt->size += PLT_THUMB_STUB_SIZE;
8207 root_plt->offset = splt->size;
8208 splt->size += htab->plt_entry_size;
8210 if (!htab->symbian_p)
8212 /* We also need to make an entry in the .got.plt section, which
8213 will be placed in the .got section by the linker script. */
8215 arm_plt->got_offset = sgotplt->size;
8217 arm_plt->got_offset = sgotplt->size - 8 * htab->num_tls_desc;
8223 arm_movw_immediate (bfd_vma value)
8225 return (value & 0x00000fff) | ((value & 0x0000f000) << 4);
8229 arm_movt_immediate (bfd_vma value)
8231 return ((value & 0x0fff0000) >> 16) | ((value & 0xf0000000) >> 12);
8234 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
8235 the entry lives in .iplt and resolves to (*SYM_VALUE)().
8236 Otherwise, DYNINDX is the index of the symbol in the dynamic
8237 symbol table and SYM_VALUE is undefined.
8239 ROOT_PLT points to the offset of the PLT entry from the start of its
8240 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
8241 bookkeeping information.
8243 Returns FALSE if there was a problem. */
8246 elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
8247 union gotplt_union *root_plt,
8248 struct arm_plt_info *arm_plt,
8249 int dynindx, bfd_vma sym_value)
8251 struct elf32_arm_link_hash_table *htab;
8257 Elf_Internal_Rela rel;
8258 bfd_vma plt_header_size;
8259 bfd_vma got_header_size;
8261 htab = elf32_arm_hash_table (info);
8263 /* Pick the appropriate sections and sizes. */
8266 splt = htab->root.iplt;
8267 sgot = htab->root.igotplt;
8268 srel = htab->root.irelplt;
8270 /* There are no reserved entries in .igot.plt, and no special
8271 first entry in .iplt. */
8272 got_header_size = 0;
8273 plt_header_size = 0;
8277 splt = htab->root.splt;
8278 sgot = htab->root.sgotplt;
8279 srel = htab->root.srelplt;
8281 got_header_size = get_elf_backend_data (output_bfd)->got_header_size;
8282 plt_header_size = htab->plt_header_size;
8284 BFD_ASSERT (splt != NULL && srel != NULL);
8286 /* Fill in the entry in the procedure linkage table. */
8287 if (htab->symbian_p)
8289 BFD_ASSERT (dynindx >= 0);
8290 put_arm_insn (htab, output_bfd,
8291 elf32_arm_symbian_plt_entry[0],
8292 splt->contents + root_plt->offset);
8293 bfd_put_32 (output_bfd,
8294 elf32_arm_symbian_plt_entry[1],
8295 splt->contents + root_plt->offset + 4);
8297 /* Fill in the entry in the .rel.plt section. */
8298 rel.r_offset = (splt->output_section->vma
8299 + splt->output_offset
8300 + root_plt->offset + 4);
8301 rel.r_info = ELF32_R_INFO (dynindx, R_ARM_GLOB_DAT);
8303 /* Get the index in the procedure linkage table which
8304 corresponds to this symbol. This is the index of this symbol
8305 in all the symbols for which we are making plt entries. The
8306 first entry in the procedure linkage table is reserved. */
8307 plt_index = ((root_plt->offset - plt_header_size)
8308 / htab->plt_entry_size);
8312 bfd_vma got_offset, got_address, plt_address;
8313 bfd_vma got_displacement, initial_got_entry;
8316 BFD_ASSERT (sgot != NULL);
8318 /* Get the offset into the .(i)got.plt table of the entry that
8319 corresponds to this function. */
8320 got_offset = (arm_plt->got_offset & -2);
8322 /* Get the index in the procedure linkage table which
8323 corresponds to this symbol. This is the index of this symbol
8324 in all the symbols for which we are making plt entries.
8325 After the reserved .got.plt entries, all symbols appear in
8326 the same order as in .plt. */
8327 plt_index = (got_offset - got_header_size) / 4;
8329 /* Calculate the address of the GOT entry. */
8330 got_address = (sgot->output_section->vma
8331 + sgot->output_offset
8334 /* ...and the address of the PLT entry. */
8335 plt_address = (splt->output_section->vma
8336 + splt->output_offset
8337 + root_plt->offset);
8339 ptr = splt->contents + root_plt->offset;
8340 if (htab->vxworks_p && bfd_link_pic (info))
8345 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8347 val = elf32_arm_vxworks_shared_plt_entry[i];
8349 val |= got_address - sgot->output_section->vma;
8351 val |= plt_index * RELOC_SIZE (htab);
8352 if (i == 2 || i == 5)
8353 bfd_put_32 (output_bfd, val, ptr);
8355 put_arm_insn (htab, output_bfd, val, ptr);
8358 else if (htab->vxworks_p)
8363 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8365 val = elf32_arm_vxworks_exec_plt_entry[i];
8369 val |= 0xffffff & -((root_plt->offset + i * 4 + 8) >> 2);
8371 val |= plt_index * RELOC_SIZE (htab);
8372 if (i == 2 || i == 5)
8373 bfd_put_32 (output_bfd, val, ptr);
8375 put_arm_insn (htab, output_bfd, val, ptr);
8378 loc = (htab->srelplt2->contents
8379 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8381 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8382 referencing the GOT for this PLT entry. */
8383 rel.r_offset = plt_address + 8;
8384 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8385 rel.r_addend = got_offset;
8386 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8387 loc += RELOC_SIZE (htab);
8389 /* Create the R_ARM_ABS32 relocation referencing the
8390 beginning of the PLT for this GOT entry. */
8391 rel.r_offset = got_address;
8392 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8394 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8396 else if (htab->nacl_p)
8398 /* Calculate the displacement between the PLT slot and the
8399 common tail that's part of the special initial PLT slot. */
8400 int32_t tail_displacement
8401 = ((splt->output_section->vma + splt->output_offset
8402 + ARM_NACL_PLT_TAIL_OFFSET)
8403 - (plt_address + htab->plt_entry_size + 4));
8404 BFD_ASSERT ((tail_displacement & 3) == 0);
8405 tail_displacement >>= 2;
8407 BFD_ASSERT ((tail_displacement & 0xff000000) == 0
8408 || (-tail_displacement & 0xff000000) == 0);
8410 /* Calculate the displacement between the PLT slot and the entry
8411 in the GOT. The offset accounts for the value produced by
8412 adding to pc in the penultimate instruction of the PLT stub. */
8413 got_displacement = (got_address
8414 - (plt_address + htab->plt_entry_size));
8416 /* NaCl does not support interworking at all. */
8417 BFD_ASSERT (!elf32_arm_plt_needs_thumb_stub_p (info, arm_plt));
8419 put_arm_insn (htab, output_bfd,
8420 elf32_arm_nacl_plt_entry[0]
8421 | arm_movw_immediate (got_displacement),
8423 put_arm_insn (htab, output_bfd,
8424 elf32_arm_nacl_plt_entry[1]
8425 | arm_movt_immediate (got_displacement),
8427 put_arm_insn (htab, output_bfd,
8428 elf32_arm_nacl_plt_entry[2],
8430 put_arm_insn (htab, output_bfd,
8431 elf32_arm_nacl_plt_entry[3]
8432 | (tail_displacement & 0x00ffffff),
8435 else if (using_thumb_only (htab))
8437 /* PR ld/16017: Generate thumb only PLT entries. */
8438 if (!using_thumb2 (htab))
8440 /* FIXME: We ought to be able to generate thumb-1 PLT
8442 _bfd_error_handler (_("%B: Warning: thumb-1 mode PLT generation not currently supported"),
8447 /* Calculate the displacement between the PLT slot and the entry in
8448 the GOT. The 12-byte offset accounts for the value produced by
8449 adding to pc in the 3rd instruction of the PLT stub. */
8450 got_displacement = got_address - (plt_address + 12);
8452 /* As we are using 32 bit instructions we have to use 'put_arm_insn'
8453 instead of 'put_thumb_insn'. */
8454 put_arm_insn (htab, output_bfd,
8455 elf32_thumb2_plt_entry[0]
8456 | ((got_displacement & 0x000000ff) << 16)
8457 | ((got_displacement & 0x00000700) << 20)
8458 | ((got_displacement & 0x00000800) >> 1)
8459 | ((got_displacement & 0x0000f000) >> 12),
8461 put_arm_insn (htab, output_bfd,
8462 elf32_thumb2_plt_entry[1]
8463 | ((got_displacement & 0x00ff0000) )
8464 | ((got_displacement & 0x07000000) << 4)
8465 | ((got_displacement & 0x08000000) >> 17)
8466 | ((got_displacement & 0xf0000000) >> 28),
8468 put_arm_insn (htab, output_bfd,
8469 elf32_thumb2_plt_entry[2],
8471 put_arm_insn (htab, output_bfd,
8472 elf32_thumb2_plt_entry[3],
8477 /* Calculate the displacement between the PLT slot and the
8478 entry in the GOT. The eight-byte offset accounts for the
8479 value produced by adding to pc in the first instruction
8481 got_displacement = got_address - (plt_address + 8);
8483 if (elf32_arm_plt_needs_thumb_stub_p (info, arm_plt))
8485 put_thumb_insn (htab, output_bfd,
8486 elf32_arm_plt_thumb_stub[0], ptr - 4);
8487 put_thumb_insn (htab, output_bfd,
8488 elf32_arm_plt_thumb_stub[1], ptr - 2);
8491 if (!elf32_arm_use_long_plt_entry)
8493 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8495 put_arm_insn (htab, output_bfd,
8496 elf32_arm_plt_entry_short[0]
8497 | ((got_displacement & 0x0ff00000) >> 20),
8499 put_arm_insn (htab, output_bfd,
8500 elf32_arm_plt_entry_short[1]
8501 | ((got_displacement & 0x000ff000) >> 12),
8503 put_arm_insn (htab, output_bfd,
8504 elf32_arm_plt_entry_short[2]
8505 | (got_displacement & 0x00000fff),
8507 #ifdef FOUR_WORD_PLT
8508 bfd_put_32 (output_bfd, elf32_arm_plt_entry_short[3], ptr + 12);
8513 put_arm_insn (htab, output_bfd,
8514 elf32_arm_plt_entry_long[0]
8515 | ((got_displacement & 0xf0000000) >> 28),
8517 put_arm_insn (htab, output_bfd,
8518 elf32_arm_plt_entry_long[1]
8519 | ((got_displacement & 0x0ff00000) >> 20),
8521 put_arm_insn (htab, output_bfd,
8522 elf32_arm_plt_entry_long[2]
8523 | ((got_displacement & 0x000ff000) >> 12),
8525 put_arm_insn (htab, output_bfd,
8526 elf32_arm_plt_entry_long[3]
8527 | (got_displacement & 0x00000fff),
8532 /* Fill in the entry in the .rel(a).(i)plt section. */
8533 rel.r_offset = got_address;
8537 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
8538 The dynamic linker or static executable then calls SYM_VALUE
8539 to determine the correct run-time value of the .igot.plt entry. */
8540 rel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
8541 initial_got_entry = sym_value;
8545 rel.r_info = ELF32_R_INFO (dynindx, R_ARM_JUMP_SLOT);
8546 initial_got_entry = (splt->output_section->vma
8547 + splt->output_offset);
8550 /* Fill in the entry in the global offset table. */
8551 bfd_put_32 (output_bfd, initial_got_entry,
8552 sgot->contents + got_offset);
8556 elf32_arm_add_dynreloc (output_bfd, info, srel, &rel);
8559 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8560 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8566 /* Some relocations map to different relocations depending on the
8567 target. Return the real relocation. */
8570 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
8576 if (globals->target1_is_rel)
8582 return globals->target2_reloc;
8589 /* Return the base VMA address which should be subtracted from real addresses
8590 when resolving @dtpoff relocation.
8591 This is PT_TLS segment p_vaddr. */
8594 dtpoff_base (struct bfd_link_info *info)
8596 /* If tls_sec is NULL, we should have signalled an error already. */
8597 if (elf_hash_table (info)->tls_sec == NULL)
8599 return elf_hash_table (info)->tls_sec->vma;
8602 /* Return the relocation value for @tpoff relocation
8603 if STT_TLS virtual address is ADDRESS. */
8606 tpoff (struct bfd_link_info *info, bfd_vma address)
8608 struct elf_link_hash_table *htab = elf_hash_table (info);
8611 /* If tls_sec is NULL, we should have signalled an error already. */
8612 if (htab->tls_sec == NULL)
8614 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
8615 return address - htab->tls_sec->vma + base;
8618 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
8619 VALUE is the relocation value. */
8621 static bfd_reloc_status_type
8622 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
8625 return bfd_reloc_overflow;
8627 value |= bfd_get_32 (abfd, data) & 0xfffff000;
8628 bfd_put_32 (abfd, value, data);
8629 return bfd_reloc_ok;
8632 /* Handle TLS relaxations. Relaxing is possible for symbols that use
8633 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
8634 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
8636 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
8637 is to then call final_link_relocate. Return other values in the
8640 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
8641 the pre-relaxed code. It would be nice if the relocs were updated
8642 to match the optimization. */
8644 static bfd_reloc_status_type
8645 elf32_arm_tls_relax (struct elf32_arm_link_hash_table *globals,
8646 bfd *input_bfd, asection *input_sec, bfd_byte *contents,
8647 Elf_Internal_Rela *rel, unsigned long is_local)
8651 switch (ELF32_R_TYPE (rel->r_info))
8654 return bfd_reloc_notsupported;
8656 case R_ARM_TLS_GOTDESC:
8661 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
8663 insn -= 5; /* THUMB */
8665 insn -= 8; /* ARM */
8667 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
8668 return bfd_reloc_continue;
8670 case R_ARM_THM_TLS_DESCSEQ:
8672 insn = bfd_get_16 (input_bfd, contents + rel->r_offset);
8673 if ((insn & 0xff78) == 0x4478) /* add rx, pc */
8677 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
8679 else if ((insn & 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
8683 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
8686 bfd_put_16 (input_bfd, insn & 0xf83f, contents + rel->r_offset);
8688 else if ((insn & 0xff87) == 0x4780) /* blx rx */
8692 bfd_put_16 (input_bfd, 0x46c0, contents + rel->r_offset);
8695 bfd_put_16 (input_bfd, 0x4600 | (insn & 0x78),
8696 contents + rel->r_offset);
8700 if ((insn & 0xf000) == 0xf000 || (insn & 0xf800) == 0xe800)
8701 /* It's a 32 bit instruction, fetch the rest of it for
8702 error generation. */
8704 | bfd_get_16 (input_bfd, contents + rel->r_offset + 2);
8705 (*_bfd_error_handler)
8706 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' in TLS trampoline"),
8707 input_bfd, input_sec, (unsigned long)rel->r_offset, insn);
8708 return bfd_reloc_notsupported;
8712 case R_ARM_TLS_DESCSEQ:
8714 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
8715 if ((insn & 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
8719 bfd_put_32 (input_bfd, 0xe1a00000 | (insn & 0xffff),
8720 contents + rel->r_offset);
8722 else if ((insn & 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
8726 bfd_put_32 (input_bfd, 0xe1a00000, contents + rel->r_offset);
8729 bfd_put_32 (input_bfd, insn & 0xfffff000,
8730 contents + rel->r_offset);
8732 else if ((insn & 0xfffffff0) == 0xe12fff30) /* blx rx */
8736 bfd_put_32 (input_bfd, 0xe1a00000, contents + rel->r_offset);
8739 bfd_put_32 (input_bfd, 0xe1a00000 | (insn & 0xf),
8740 contents + rel->r_offset);
8744 (*_bfd_error_handler)
8745 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' in TLS trampoline"),
8746 input_bfd, input_sec, (unsigned long)rel->r_offset, insn);
8747 return bfd_reloc_notsupported;
8751 case R_ARM_TLS_CALL:
8752 /* GD->IE relaxation, turn the instruction into 'nop' or
8753 'ldr r0, [pc,r0]' */
8754 insn = is_local ? 0xe1a00000 : 0xe79f0000;
8755 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
8758 case R_ARM_THM_TLS_CALL:
8759 /* GD->IE relaxation. */
8761 /* add r0,pc; ldr r0, [r0] */
8763 else if (arch_has_thumb2_nop (globals))
8770 bfd_put_16 (input_bfd, insn >> 16, contents + rel->r_offset);
8771 bfd_put_16 (input_bfd, insn & 0xffff, contents + rel->r_offset + 2);
8774 return bfd_reloc_ok;
8777 /* For a given value of n, calculate the value of G_n as required to
8778 deal with group relocations. We return it in the form of an
8779 encoded constant-and-rotation, together with the final residual. If n is
8780 specified as less than zero, then final_residual is filled with the
8781 input value and no further action is performed. */
8784 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
8788 bfd_vma encoded_g_n = 0;
8789 bfd_vma residual = value; /* Also known as Y_n. */
8791 for (current_n = 0; current_n <= n; current_n++)
8795 /* Calculate which part of the value to mask. */
8802 /* Determine the most significant bit in the residual and
8803 align the resulting value to a 2-bit boundary. */
8804 for (msb = 30; msb >= 0; msb -= 2)
8805 if (residual & (3 << msb))
8808 /* The desired shift is now (msb - 6), or zero, whichever
8815 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
8816 g_n = residual & (0xff << shift);
8817 encoded_g_n = (g_n >> shift)
8818 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
8820 /* Calculate the residual for the next time around. */
8824 *final_residual = residual;
8829 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
8830 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
8833 identify_add_or_sub (bfd_vma insn)
8835 int opcode = insn & 0x1e00000;
8837 if (opcode == 1 << 23) /* ADD */
8840 if (opcode == 1 << 22) /* SUB */
8846 /* Perform a relocation as part of a final link. */
8848 static bfd_reloc_status_type
8849 elf32_arm_final_link_relocate (reloc_howto_type * howto,
8852 asection * input_section,
8853 bfd_byte * contents,
8854 Elf_Internal_Rela * rel,
8856 struct bfd_link_info * info,
8858 const char * sym_name,
8859 unsigned char st_type,
8860 enum arm_st_branch_type branch_type,
8861 struct elf_link_hash_entry * h,
8862 bfd_boolean * unresolved_reloc_p,
8863 char ** error_message)
8865 unsigned long r_type = howto->type;
8866 unsigned long r_symndx;
8867 bfd_byte * hit_data = contents + rel->r_offset;
8868 bfd_vma * local_got_offsets;
8869 bfd_vma * local_tlsdesc_gotents;
8872 asection * sreloc = NULL;
8875 bfd_signed_vma signed_addend;
8876 unsigned char dynreloc_st_type;
8877 bfd_vma dynreloc_value;
8878 struct elf32_arm_link_hash_table * globals;
8879 struct elf32_arm_link_hash_entry *eh;
8880 union gotplt_union *root_plt;
8881 struct arm_plt_info *arm_plt;
8883 bfd_vma gotplt_offset;
8884 bfd_boolean has_iplt_entry;
8886 globals = elf32_arm_hash_table (info);
8887 if (globals == NULL)
8888 return bfd_reloc_notsupported;
8890 BFD_ASSERT (is_arm_elf (input_bfd));
8892 /* Some relocation types map to different relocations depending on the
8893 target. We pick the right one here. */
8894 r_type = arm_real_reloc_type (globals, r_type);
8896 /* It is possible to have linker relaxations on some TLS access
8897 models. Update our information here. */
8898 r_type = elf32_arm_tls_transition (info, r_type, h);
8900 if (r_type != howto->type)
8901 howto = elf32_arm_howto_from_type (r_type);
8903 eh = (struct elf32_arm_link_hash_entry *) h;
8904 sgot = globals->root.sgot;
8905 local_got_offsets = elf_local_got_offsets (input_bfd);
8906 local_tlsdesc_gotents = elf32_arm_local_tlsdesc_gotent (input_bfd);
8908 if (globals->root.dynamic_sections_created)
8909 srelgot = globals->root.srelgot;
8913 r_symndx = ELF32_R_SYM (rel->r_info);
8915 if (globals->use_rel)
8917 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
8919 if (addend & ((howto->src_mask + 1) >> 1))
8922 signed_addend &= ~ howto->src_mask;
8923 signed_addend |= addend;
8926 signed_addend = addend;
8929 addend = signed_addend = rel->r_addend;
8931 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
8932 are resolving a function call relocation. */
8933 if (using_thumb_only (globals)
8934 && (r_type == R_ARM_THM_CALL
8935 || r_type == R_ARM_THM_JUMP24)
8936 && branch_type == ST_BRANCH_TO_ARM)
8937 branch_type = ST_BRANCH_TO_THUMB;
8939 /* Record the symbol information that should be used in dynamic
8941 dynreloc_st_type = st_type;
8942 dynreloc_value = value;
8943 if (branch_type == ST_BRANCH_TO_THUMB)
8944 dynreloc_value |= 1;
8946 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
8947 VALUE appropriately for relocations that we resolve at link time. */
8948 has_iplt_entry = FALSE;
8949 if (elf32_arm_get_plt_info (input_bfd, eh, r_symndx, &root_plt, &arm_plt)
8950 && root_plt->offset != (bfd_vma) -1)
8952 plt_offset = root_plt->offset;
8953 gotplt_offset = arm_plt->got_offset;
8955 if (h == NULL || eh->is_iplt)
8957 has_iplt_entry = TRUE;
8958 splt = globals->root.iplt;
8960 /* Populate .iplt entries here, because not all of them will
8961 be seen by finish_dynamic_symbol. The lower bit is set if
8962 we have already populated the entry. */
8967 if (elf32_arm_populate_plt_entry (output_bfd, info, root_plt, arm_plt,
8968 -1, dynreloc_value))
8969 root_plt->offset |= 1;
8971 return bfd_reloc_notsupported;
8974 /* Static relocations always resolve to the .iplt entry. */
8976 value = (splt->output_section->vma
8977 + splt->output_offset
8979 branch_type = ST_BRANCH_TO_ARM;
8981 /* If there are non-call relocations that resolve to the .iplt
8982 entry, then all dynamic ones must too. */
8983 if (arm_plt->noncall_refcount != 0)
8985 dynreloc_st_type = st_type;
8986 dynreloc_value = value;
8990 /* We populate the .plt entry in finish_dynamic_symbol. */
8991 splt = globals->root.splt;
8996 plt_offset = (bfd_vma) -1;
8997 gotplt_offset = (bfd_vma) -1;
9003 /* We don't need to find a value for this symbol. It's just a
9005 *unresolved_reloc_p = FALSE;
9006 return bfd_reloc_ok;
9009 if (!globals->vxworks_p)
9010 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
9014 case R_ARM_ABS32_NOI:
9016 case R_ARM_REL32_NOI:
9022 /* Handle relocations which should use the PLT entry. ABS32/REL32
9023 will use the symbol's value, which may point to a PLT entry, but we
9024 don't need to handle that here. If we created a PLT entry, all
9025 branches in this object should go to it, except if the PLT is too
9026 far away, in which case a long branch stub should be inserted. */
9027 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
9028 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI
9029 && r_type != R_ARM_CALL
9030 && r_type != R_ARM_JUMP24
9031 && r_type != R_ARM_PLT32)
9032 && plt_offset != (bfd_vma) -1)
9034 /* If we've created a .plt section, and assigned a PLT entry
9035 to this function, it must either be a STT_GNU_IFUNC reference
9036 or not be known to bind locally. In other cases, we should
9037 have cleared the PLT entry by now. */
9038 BFD_ASSERT (has_iplt_entry || !SYMBOL_CALLS_LOCAL (info, h));
9040 value = (splt->output_section->vma
9041 + splt->output_offset
9043 *unresolved_reloc_p = FALSE;
9044 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9045 contents, rel->r_offset, value,
9049 /* When generating a shared object or relocatable executable, these
9050 relocations are copied into the output file to be resolved at
9052 if ((bfd_link_pic (info)
9053 || globals->root.is_relocatable_executable)
9054 && (input_section->flags & SEC_ALLOC)
9055 && !(globals->vxworks_p
9056 && strcmp (input_section->output_section->name,
9058 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
9059 || !SYMBOL_CALLS_LOCAL (info, h))
9060 && !(input_bfd == globals->stub_bfd
9061 && strstr (input_section->name, STUB_SUFFIX))
9063 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9064 || h->root.type != bfd_link_hash_undefweak)
9065 && r_type != R_ARM_PC24
9066 && r_type != R_ARM_CALL
9067 && r_type != R_ARM_JUMP24
9068 && r_type != R_ARM_PREL31
9069 && r_type != R_ARM_PLT32)
9071 Elf_Internal_Rela outrel;
9072 bfd_boolean skip, relocate;
9074 if ((r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
9077 char *v = _("shared object");
9079 if (bfd_link_executable (info))
9080 v = _("PIE executable");
9082 (*_bfd_error_handler)
9083 (_("%B: relocation %s against external or undefined symbol `%s'"
9084 " can not be used when making a %s; recompile with -fPIC"), input_bfd,
9085 elf32_arm_howto_table_1[r_type].name, h->root.root.string, v);
9086 return bfd_reloc_notsupported;
9089 *unresolved_reloc_p = FALSE;
9091 if (sreloc == NULL && globals->root.dynamic_sections_created)
9093 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
9094 ! globals->use_rel);
9097 return bfd_reloc_notsupported;
9103 outrel.r_addend = addend;
9105 _bfd_elf_section_offset (output_bfd, info, input_section,
9107 if (outrel.r_offset == (bfd_vma) -1)
9109 else if (outrel.r_offset == (bfd_vma) -2)
9110 skip = TRUE, relocate = TRUE;
9111 outrel.r_offset += (input_section->output_section->vma
9112 + input_section->output_offset);
9115 memset (&outrel, 0, sizeof outrel);
9118 && (!bfd_link_pic (info)
9119 || !SYMBOLIC_BIND (info, h)
9120 || !h->def_regular))
9121 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
9126 /* This symbol is local, or marked to become local. */
9127 BFD_ASSERT (r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI);
9128 if (globals->symbian_p)
9132 /* On Symbian OS, the data segment and text segement
9133 can be relocated independently. Therefore, we
9134 must indicate the segment to which this
9135 relocation is relative. The BPABI allows us to
9136 use any symbol in the right segment; we just use
9137 the section symbol as it is convenient. (We
9138 cannot use the symbol given by "h" directly as it
9139 will not appear in the dynamic symbol table.)
9141 Note that the dynamic linker ignores the section
9142 symbol value, so we don't subtract osec->vma
9143 from the emitted reloc addend. */
9145 osec = sym_sec->output_section;
9147 osec = input_section->output_section;
9148 symbol = elf_section_data (osec)->dynindx;
9151 struct elf_link_hash_table *htab = elf_hash_table (info);
9153 if ((osec->flags & SEC_READONLY) == 0
9154 && htab->data_index_section != NULL)
9155 osec = htab->data_index_section;
9157 osec = htab->text_index_section;
9158 symbol = elf_section_data (osec)->dynindx;
9160 BFD_ASSERT (symbol != 0);
9163 /* On SVR4-ish systems, the dynamic loader cannot
9164 relocate the text and data segments independently,
9165 so the symbol does not matter. */
9167 if (dynreloc_st_type == STT_GNU_IFUNC)
9168 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
9169 to the .iplt entry. Instead, every non-call reference
9170 must use an R_ARM_IRELATIVE relocation to obtain the
9171 correct run-time address. */
9172 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_IRELATIVE);
9174 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
9175 if (globals->use_rel)
9178 outrel.r_addend += dynreloc_value;
9181 elf32_arm_add_dynreloc (output_bfd, info, sreloc, &outrel);
9183 /* If this reloc is against an external symbol, we do not want to
9184 fiddle with the addend. Otherwise, we need to include the symbol
9185 value so that it becomes an addend for the dynamic reloc. */
9187 return bfd_reloc_ok;
9189 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9190 contents, rel->r_offset,
9191 dynreloc_value, (bfd_vma) 0);
9193 else switch (r_type)
9196 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
9198 case R_ARM_XPC25: /* Arm BLX instruction. */
9201 case R_ARM_PC24: /* Arm B/BL instruction. */
9204 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
9206 if (r_type == R_ARM_XPC25)
9208 /* Check for Arm calling Arm function. */
9209 /* FIXME: Should we translate the instruction into a BL
9210 instruction instead ? */
9211 if (branch_type != ST_BRANCH_TO_THUMB)
9212 (*_bfd_error_handler)
9213 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
9215 h ? h->root.root.string : "(local)");
9217 else if (r_type == R_ARM_PC24)
9219 /* Check for Arm calling Thumb function. */
9220 if (branch_type == ST_BRANCH_TO_THUMB)
9222 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
9223 output_bfd, input_section,
9224 hit_data, sym_sec, rel->r_offset,
9225 signed_addend, value,
9227 return bfd_reloc_ok;
9229 return bfd_reloc_dangerous;
9233 /* Check if a stub has to be inserted because the
9234 destination is too far or we are changing mode. */
9235 if ( r_type == R_ARM_CALL
9236 || r_type == R_ARM_JUMP24
9237 || r_type == R_ARM_PLT32)
9239 enum elf32_arm_stub_type stub_type = arm_stub_none;
9240 struct elf32_arm_link_hash_entry *hash;
9242 hash = (struct elf32_arm_link_hash_entry *) h;
9243 stub_type = arm_type_of_stub (info, input_section, rel,
9244 st_type, &branch_type,
9245 hash, value, sym_sec,
9246 input_bfd, sym_name);
9248 if (stub_type != arm_stub_none)
9250 /* The target is out of reach, so redirect the
9251 branch to the local stub for this function. */
9252 stub_entry = elf32_arm_get_stub_entry (input_section,
9257 if (stub_entry != NULL)
9258 value = (stub_entry->stub_offset
9259 + stub_entry->stub_sec->output_offset
9260 + stub_entry->stub_sec->output_section->vma);
9262 if (plt_offset != (bfd_vma) -1)
9263 *unresolved_reloc_p = FALSE;
9268 /* If the call goes through a PLT entry, make sure to
9269 check distance to the right destination address. */
9270 if (plt_offset != (bfd_vma) -1)
9272 value = (splt->output_section->vma
9273 + splt->output_offset
9275 *unresolved_reloc_p = FALSE;
9276 /* The PLT entry is in ARM mode, regardless of the
9278 branch_type = ST_BRANCH_TO_ARM;
9283 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
9285 S is the address of the symbol in the relocation.
9286 P is address of the instruction being relocated.
9287 A is the addend (extracted from the instruction) in bytes.
9289 S is held in 'value'.
9290 P is the base address of the section containing the
9291 instruction plus the offset of the reloc into that
9293 (input_section->output_section->vma +
9294 input_section->output_offset +
9296 A is the addend, converted into bytes, ie:
9299 Note: None of these operations have knowledge of the pipeline
9300 size of the processor, thus it is up to the assembler to
9301 encode this information into the addend. */
9302 value -= (input_section->output_section->vma
9303 + input_section->output_offset);
9304 value -= rel->r_offset;
9305 if (globals->use_rel)
9306 value += (signed_addend << howto->size);
9308 /* RELA addends do not have to be adjusted by howto->size. */
9309 value += signed_addend;
9311 signed_addend = value;
9312 signed_addend >>= howto->rightshift;
9314 /* A branch to an undefined weak symbol is turned into a jump to
9315 the next instruction unless a PLT entry will be created.
9316 Do the same for local undefined symbols (but not for STN_UNDEF).
9317 The jump to the next instruction is optimized as a NOP depending
9318 on the architecture. */
9319 if (h ? (h->root.type == bfd_link_hash_undefweak
9320 && plt_offset == (bfd_vma) -1)
9321 : r_symndx != STN_UNDEF && bfd_is_und_section (sym_sec))
9323 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000);
9325 if (arch_has_arm_nop (globals))
9326 value |= 0x0320f000;
9328 value |= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
9332 /* Perform a signed range check. */
9333 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
9334 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
9335 return bfd_reloc_overflow;
9337 addend = (value & 2);
9339 value = (signed_addend & howto->dst_mask)
9340 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
9342 if (r_type == R_ARM_CALL)
9344 /* Set the H bit in the BLX instruction. */
9345 if (branch_type == ST_BRANCH_TO_THUMB)
9350 value &= ~(bfd_vma)(1 << 24);
9353 /* Select the correct instruction (BL or BLX). */
9354 /* Only if we are not handling a BL to a stub. In this
9355 case, mode switching is performed by the stub. */
9356 if (branch_type == ST_BRANCH_TO_THUMB && !stub_entry)
9358 else if (stub_entry || branch_type != ST_BRANCH_UNKNOWN)
9360 value &= ~(bfd_vma)(1 << 28);
9370 if (branch_type == ST_BRANCH_TO_THUMB)
9374 case R_ARM_ABS32_NOI:
9380 if (branch_type == ST_BRANCH_TO_THUMB)
9382 value -= (input_section->output_section->vma
9383 + input_section->output_offset + rel->r_offset);
9386 case R_ARM_REL32_NOI:
9388 value -= (input_section->output_section->vma
9389 + input_section->output_offset + rel->r_offset);
9393 value -= (input_section->output_section->vma
9394 + input_section->output_offset + rel->r_offset);
9395 value += signed_addend;
9396 if (! h || h->root.type != bfd_link_hash_undefweak)
9398 /* Check for overflow. */
9399 if ((value ^ (value >> 1)) & (1 << 30))
9400 return bfd_reloc_overflow;
9402 value &= 0x7fffffff;
9403 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
9404 if (branch_type == ST_BRANCH_TO_THUMB)
9409 bfd_put_32 (input_bfd, value, hit_data);
9410 return bfd_reloc_ok;
9413 /* PR 16202: Refectch the addend using the correct size. */
9414 if (globals->use_rel)
9415 addend = bfd_get_8 (input_bfd, hit_data);
9418 /* There is no way to tell whether the user intended to use a signed or
9419 unsigned addend. When checking for overflow we accept either,
9420 as specified by the AAELF. */
9421 if ((long) value > 0xff || (long) value < -0x80)
9422 return bfd_reloc_overflow;
9424 bfd_put_8 (input_bfd, value, hit_data);
9425 return bfd_reloc_ok;
9428 /* PR 16202: Refectch the addend using the correct size. */
9429 if (globals->use_rel)
9430 addend = bfd_get_16 (input_bfd, hit_data);
9433 /* See comment for R_ARM_ABS8. */
9434 if ((long) value > 0xffff || (long) value < -0x8000)
9435 return bfd_reloc_overflow;
9437 bfd_put_16 (input_bfd, value, hit_data);
9438 return bfd_reloc_ok;
9440 case R_ARM_THM_ABS5:
9441 /* Support ldr and str instructions for the thumb. */
9442 if (globals->use_rel)
9444 /* Need to refetch addend. */
9445 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
9446 /* ??? Need to determine shift amount from operand size. */
9447 addend >>= howto->rightshift;
9451 /* ??? Isn't value unsigned? */
9452 if ((long) value > 0x1f || (long) value < -0x10)
9453 return bfd_reloc_overflow;
9455 /* ??? Value needs to be properly shifted into place first. */
9456 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
9457 bfd_put_16 (input_bfd, value, hit_data);
9458 return bfd_reloc_ok;
9460 case R_ARM_THM_ALU_PREL_11_0:
9461 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
9464 bfd_signed_vma relocation;
9466 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
9467 | bfd_get_16 (input_bfd, hit_data + 2);
9469 if (globals->use_rel)
9471 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
9472 | ((insn & (1 << 26)) >> 15);
9473 if (insn & 0xf00000)
9474 signed_addend = -signed_addend;
9477 relocation = value + signed_addend;
9478 relocation -= Pa (input_section->output_section->vma
9479 + input_section->output_offset
9484 if (value >= 0x1000)
9485 return bfd_reloc_overflow;
9487 insn = (insn & 0xfb0f8f00) | (value & 0xff)
9488 | ((value & 0x700) << 4)
9489 | ((value & 0x800) << 15);
9493 bfd_put_16 (input_bfd, insn >> 16, hit_data);
9494 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
9496 return bfd_reloc_ok;
9500 /* PR 10073: This reloc is not generated by the GNU toolchain,
9501 but it is supported for compatibility with third party libraries
9502 generated by other compilers, specifically the ARM/IAR. */
9505 bfd_signed_vma relocation;
9507 insn = bfd_get_16 (input_bfd, hit_data);
9509 if (globals->use_rel)
9510 addend = ((((insn & 0x00ff) << 2) + 4) & 0x3ff) -4;
9512 relocation = value + addend;
9513 relocation -= Pa (input_section->output_section->vma
9514 + input_section->output_offset
9519 /* We do not check for overflow of this reloc. Although strictly
9520 speaking this is incorrect, it appears to be necessary in order
9521 to work with IAR generated relocs. Since GCC and GAS do not
9522 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
9523 a problem for them. */
9526 insn = (insn & 0xff00) | (value >> 2);
9528 bfd_put_16 (input_bfd, insn, hit_data);
9530 return bfd_reloc_ok;
9533 case R_ARM_THM_PC12:
9534 /* Corresponds to: ldr.w reg, [pc, #offset]. */
9537 bfd_signed_vma relocation;
9539 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
9540 | bfd_get_16 (input_bfd, hit_data + 2);
9542 if (globals->use_rel)
9544 signed_addend = insn & 0xfff;
9545 if (!(insn & (1 << 23)))
9546 signed_addend = -signed_addend;
9549 relocation = value + signed_addend;
9550 relocation -= Pa (input_section->output_section->vma
9551 + input_section->output_offset
9556 if (value >= 0x1000)
9557 return bfd_reloc_overflow;
9559 insn = (insn & 0xff7ff000) | value;
9560 if (relocation >= 0)
9563 bfd_put_16 (input_bfd, insn >> 16, hit_data);
9564 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
9566 return bfd_reloc_ok;
9569 case R_ARM_THM_XPC22:
9570 case R_ARM_THM_CALL:
9571 case R_ARM_THM_JUMP24:
9572 /* Thumb BL (branch long instruction). */
9576 bfd_boolean overflow = FALSE;
9577 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
9578 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
9579 bfd_signed_vma reloc_signed_max;
9580 bfd_signed_vma reloc_signed_min;
9582 bfd_signed_vma signed_check;
9584 const int thumb2 = using_thumb2 (globals);
9586 /* A branch to an undefined weak symbol is turned into a jump to
9587 the next instruction unless a PLT entry will be created.
9588 The jump to the next instruction is optimized as a NOP.W for
9589 Thumb-2 enabled architectures. */
9590 if (h && h->root.type == bfd_link_hash_undefweak
9591 && plt_offset == (bfd_vma) -1)
9593 if (arch_has_thumb2_nop (globals))
9595 bfd_put_16 (input_bfd, 0xf3af, hit_data);
9596 bfd_put_16 (input_bfd, 0x8000, hit_data + 2);
9600 bfd_put_16 (input_bfd, 0xe000, hit_data);
9601 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
9603 return bfd_reloc_ok;
9606 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
9607 with Thumb-1) involving the J1 and J2 bits. */
9608 if (globals->use_rel)
9610 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
9611 bfd_vma upper = upper_insn & 0x3ff;
9612 bfd_vma lower = lower_insn & 0x7ff;
9613 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
9614 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
9615 bfd_vma i1 = j1 ^ s ? 0 : 1;
9616 bfd_vma i2 = j2 ^ s ? 0 : 1;
9618 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
9620 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
9622 signed_addend = addend;
9625 if (r_type == R_ARM_THM_XPC22)
9627 /* Check for Thumb to Thumb call. */
9628 /* FIXME: Should we translate the instruction into a BL
9629 instruction instead ? */
9630 if (branch_type == ST_BRANCH_TO_THUMB)
9631 (*_bfd_error_handler)
9632 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
9634 h ? h->root.root.string : "(local)");
9638 /* If it is not a call to Thumb, assume call to Arm.
9639 If it is a call relative to a section name, then it is not a
9640 function call at all, but rather a long jump. Calls through
9641 the PLT do not require stubs. */
9642 if (branch_type == ST_BRANCH_TO_ARM && plt_offset == (bfd_vma) -1)
9644 if (globals->use_blx && r_type == R_ARM_THM_CALL)
9646 /* Convert BL to BLX. */
9647 lower_insn = (lower_insn & ~0x1000) | 0x0800;
9649 else if (( r_type != R_ARM_THM_CALL)
9650 && (r_type != R_ARM_THM_JUMP24))
9652 if (elf32_thumb_to_arm_stub
9653 (info, sym_name, input_bfd, output_bfd, input_section,
9654 hit_data, sym_sec, rel->r_offset, signed_addend, value,
9656 return bfd_reloc_ok;
9658 return bfd_reloc_dangerous;
9661 else if (branch_type == ST_BRANCH_TO_THUMB
9663 && r_type == R_ARM_THM_CALL)
9665 /* Make sure this is a BL. */
9666 lower_insn |= 0x1800;
9670 enum elf32_arm_stub_type stub_type = arm_stub_none;
9671 if (r_type == R_ARM_THM_CALL || r_type == R_ARM_THM_JUMP24)
9673 /* Check if a stub has to be inserted because the destination
9675 struct elf32_arm_stub_hash_entry *stub_entry;
9676 struct elf32_arm_link_hash_entry *hash;
9678 hash = (struct elf32_arm_link_hash_entry *) h;
9680 stub_type = arm_type_of_stub (info, input_section, rel,
9681 st_type, &branch_type,
9682 hash, value, sym_sec,
9683 input_bfd, sym_name);
9685 if (stub_type != arm_stub_none)
9687 /* The target is out of reach or we are changing modes, so
9688 redirect the branch to the local stub for this
9690 stub_entry = elf32_arm_get_stub_entry (input_section,
9694 if (stub_entry != NULL)
9696 value = (stub_entry->stub_offset
9697 + stub_entry->stub_sec->output_offset
9698 + stub_entry->stub_sec->output_section->vma);
9700 if (plt_offset != (bfd_vma) -1)
9701 *unresolved_reloc_p = FALSE;
9704 /* If this call becomes a call to Arm, force BLX. */
9705 if (globals->use_blx && (r_type == R_ARM_THM_CALL))
9708 && !arm_stub_is_thumb (stub_entry->stub_type))
9709 || branch_type != ST_BRANCH_TO_THUMB)
9710 lower_insn = (lower_insn & ~0x1000) | 0x0800;
9715 /* Handle calls via the PLT. */
9716 if (stub_type == arm_stub_none && plt_offset != (bfd_vma) -1)
9718 value = (splt->output_section->vma
9719 + splt->output_offset
9722 if (globals->use_blx
9723 && r_type == R_ARM_THM_CALL
9724 && ! using_thumb_only (globals))
9726 /* If the Thumb BLX instruction is available, convert
9727 the BL to a BLX instruction to call the ARM-mode
9729 lower_insn = (lower_insn & ~0x1000) | 0x0800;
9730 branch_type = ST_BRANCH_TO_ARM;
9734 if (! using_thumb_only (globals))
9735 /* Target the Thumb stub before the ARM PLT entry. */
9736 value -= PLT_THUMB_STUB_SIZE;
9737 branch_type = ST_BRANCH_TO_THUMB;
9739 *unresolved_reloc_p = FALSE;
9742 relocation = value + signed_addend;
9744 relocation -= (input_section->output_section->vma
9745 + input_section->output_offset
9748 check = relocation >> howto->rightshift;
9750 /* If this is a signed value, the rightshift just dropped
9751 leading 1 bits (assuming twos complement). */
9752 if ((bfd_signed_vma) relocation >= 0)
9753 signed_check = check;
9755 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
9757 /* Calculate the permissable maximum and minimum values for
9758 this relocation according to whether we're relocating for
9760 bitsize = howto->bitsize;
9763 reloc_signed_max = (1 << (bitsize - 1)) - 1;
9764 reloc_signed_min = ~reloc_signed_max;
9766 /* Assumes two's complement. */
9767 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
9770 if ((lower_insn & 0x5000) == 0x4000)
9771 /* For a BLX instruction, make sure that the relocation is rounded up
9772 to a word boundary. This follows the semantics of the instruction
9773 which specifies that bit 1 of the target address will come from bit
9774 1 of the base address. */
9775 relocation = (relocation + 2) & ~ 3;
9777 /* Put RELOCATION back into the insn. Assumes two's complement.
9778 We use the Thumb-2 encoding, which is safe even if dealing with
9779 a Thumb-1 instruction by virtue of our overflow check above. */
9780 reloc_sign = (signed_check < 0) ? 1 : 0;
9781 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
9782 | ((relocation >> 12) & 0x3ff)
9783 | (reloc_sign << 10);
9784 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
9785 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
9786 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
9787 | ((relocation >> 1) & 0x7ff);
9789 /* Put the relocated value back in the object file: */
9790 bfd_put_16 (input_bfd, upper_insn, hit_data);
9791 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
9793 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
9797 case R_ARM_THM_JUMP19:
9798 /* Thumb32 conditional branch instruction. */
9801 bfd_boolean overflow = FALSE;
9802 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
9803 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
9804 bfd_signed_vma reloc_signed_max = 0xffffe;
9805 bfd_signed_vma reloc_signed_min = -0x100000;
9806 bfd_signed_vma signed_check;
9807 enum elf32_arm_stub_type stub_type = arm_stub_none;
9808 struct elf32_arm_stub_hash_entry *stub_entry;
9809 struct elf32_arm_link_hash_entry *hash;
9811 /* Need to refetch the addend, reconstruct the top three bits,
9812 and squish the two 11 bit pieces together. */
9813 if (globals->use_rel)
9815 bfd_vma S = (upper_insn & 0x0400) >> 10;
9816 bfd_vma upper = (upper_insn & 0x003f);
9817 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
9818 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
9819 bfd_vma lower = (lower_insn & 0x07ff);
9824 upper -= 0x0100; /* Sign extend. */
9826 addend = (upper << 12) | (lower << 1);
9827 signed_addend = addend;
9830 /* Handle calls via the PLT. */
9831 if (plt_offset != (bfd_vma) -1)
9833 value = (splt->output_section->vma
9834 + splt->output_offset
9836 /* Target the Thumb stub before the ARM PLT entry. */
9837 value -= PLT_THUMB_STUB_SIZE;
9838 *unresolved_reloc_p = FALSE;
9841 hash = (struct elf32_arm_link_hash_entry *)h;
9843 stub_type = arm_type_of_stub (info, input_section, rel,
9844 st_type, &branch_type,
9845 hash, value, sym_sec,
9846 input_bfd, sym_name);
9847 if (stub_type != arm_stub_none)
9849 stub_entry = elf32_arm_get_stub_entry (input_section,
9853 if (stub_entry != NULL)
9855 value = (stub_entry->stub_offset
9856 + stub_entry->stub_sec->output_offset
9857 + stub_entry->stub_sec->output_section->vma);
9861 relocation = value + signed_addend;
9862 relocation -= (input_section->output_section->vma
9863 + input_section->output_offset
9865 signed_check = (bfd_signed_vma) relocation;
9867 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
9870 /* Put RELOCATION back into the insn. */
9872 bfd_vma S = (relocation & 0x00100000) >> 20;
9873 bfd_vma J2 = (relocation & 0x00080000) >> 19;
9874 bfd_vma J1 = (relocation & 0x00040000) >> 18;
9875 bfd_vma hi = (relocation & 0x0003f000) >> 12;
9876 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
9878 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
9879 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
9882 /* Put the relocated value back in the object file: */
9883 bfd_put_16 (input_bfd, upper_insn, hit_data);
9884 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
9886 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
9889 case R_ARM_THM_JUMP11:
9890 case R_ARM_THM_JUMP8:
9891 case R_ARM_THM_JUMP6:
9892 /* Thumb B (branch) instruction). */
9894 bfd_signed_vma relocation;
9895 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
9896 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
9897 bfd_signed_vma signed_check;
9899 /* CZB cannot jump backward. */
9900 if (r_type == R_ARM_THM_JUMP6)
9901 reloc_signed_min = 0;
9903 if (globals->use_rel)
9905 /* Need to refetch addend. */
9906 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
9907 if (addend & ((howto->src_mask + 1) >> 1))
9910 signed_addend &= ~ howto->src_mask;
9911 signed_addend |= addend;
9914 signed_addend = addend;
9915 /* The value in the insn has been right shifted. We need to
9916 undo this, so that we can perform the address calculation
9917 in terms of bytes. */
9918 signed_addend <<= howto->rightshift;
9920 relocation = value + signed_addend;
9922 relocation -= (input_section->output_section->vma
9923 + input_section->output_offset
9926 relocation >>= howto->rightshift;
9927 signed_check = relocation;
9929 if (r_type == R_ARM_THM_JUMP6)
9930 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
9932 relocation &= howto->dst_mask;
9933 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
9935 bfd_put_16 (input_bfd, relocation, hit_data);
9937 /* Assumes two's complement. */
9938 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
9939 return bfd_reloc_overflow;
9941 return bfd_reloc_ok;
9944 case R_ARM_ALU_PCREL7_0:
9945 case R_ARM_ALU_PCREL15_8:
9946 case R_ARM_ALU_PCREL23_15:
9951 insn = bfd_get_32 (input_bfd, hit_data);
9952 if (globals->use_rel)
9954 /* Extract the addend. */
9955 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
9956 signed_addend = addend;
9958 relocation = value + signed_addend;
9960 relocation -= (input_section->output_section->vma
9961 + input_section->output_offset
9963 insn = (insn & ~0xfff)
9964 | ((howto->bitpos << 7) & 0xf00)
9965 | ((relocation >> howto->bitpos) & 0xff);
9966 bfd_put_32 (input_bfd, value, hit_data);
9968 return bfd_reloc_ok;
9970 case R_ARM_GNU_VTINHERIT:
9971 case R_ARM_GNU_VTENTRY:
9972 return bfd_reloc_ok;
9974 case R_ARM_GOTOFF32:
9975 /* Relocation is relative to the start of the
9976 global offset table. */
9978 BFD_ASSERT (sgot != NULL);
9980 return bfd_reloc_notsupported;
9982 /* If we are addressing a Thumb function, we need to adjust the
9983 address by one, so that attempts to call the function pointer will
9984 correctly interpret it as Thumb code. */
9985 if (branch_type == ST_BRANCH_TO_THUMB)
9988 /* Note that sgot->output_offset is not involved in this
9989 calculation. We always want the start of .got. If we
9990 define _GLOBAL_OFFSET_TABLE in a different way, as is
9991 permitted by the ABI, we might have to change this
9993 value -= sgot->output_section->vma;
9994 return _bfd_final_link_relocate (howto, input_bfd, input_section,
9995 contents, rel->r_offset, value,
9999 /* Use global offset table as symbol value. */
10000 BFD_ASSERT (sgot != NULL);
10003 return bfd_reloc_notsupported;
10005 *unresolved_reloc_p = FALSE;
10006 value = sgot->output_section->vma;
10007 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10008 contents, rel->r_offset, value,
10012 case R_ARM_GOT_PREL:
10013 /* Relocation is to the entry for this symbol in the
10014 global offset table. */
10016 return bfd_reloc_notsupported;
10018 if (dynreloc_st_type == STT_GNU_IFUNC
10019 && plt_offset != (bfd_vma) -1
10020 && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, h)))
10022 /* We have a relocation against a locally-binding STT_GNU_IFUNC
10023 symbol, and the relocation resolves directly to the runtime
10024 target rather than to the .iplt entry. This means that any
10025 .got entry would be the same value as the .igot.plt entry,
10026 so there's no point creating both. */
10027 sgot = globals->root.igotplt;
10028 value = sgot->output_offset + gotplt_offset;
10030 else if (h != NULL)
10034 off = h->got.offset;
10035 BFD_ASSERT (off != (bfd_vma) -1);
10036 if ((off & 1) != 0)
10038 /* We have already processsed one GOT relocation against
10041 if (globals->root.dynamic_sections_created
10042 && !SYMBOL_REFERENCES_LOCAL (info, h))
10043 *unresolved_reloc_p = FALSE;
10047 Elf_Internal_Rela outrel;
10049 if (h->dynindx != -1 && !SYMBOL_REFERENCES_LOCAL (info, h))
10051 /* If the symbol doesn't resolve locally in a static
10052 object, we have an undefined reference. If the
10053 symbol doesn't resolve locally in a dynamic object,
10054 it should be resolved by the dynamic linker. */
10055 if (globals->root.dynamic_sections_created)
10057 outrel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10058 *unresolved_reloc_p = FALSE;
10062 outrel.r_addend = 0;
10066 if (dynreloc_st_type == STT_GNU_IFUNC)
10067 outrel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
10068 else if (bfd_link_pic (info) &&
10069 (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10070 || h->root.type != bfd_link_hash_undefweak))
10071 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
10074 outrel.r_addend = dynreloc_value;
10077 /* The GOT entry is initialized to zero by default.
10078 See if we should install a different value. */
10079 if (outrel.r_addend != 0
10080 && (outrel.r_info == 0 || globals->use_rel))
10082 bfd_put_32 (output_bfd, outrel.r_addend,
10083 sgot->contents + off);
10084 outrel.r_addend = 0;
10087 if (outrel.r_info != 0)
10089 outrel.r_offset = (sgot->output_section->vma
10090 + sgot->output_offset
10092 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
10094 h->got.offset |= 1;
10096 value = sgot->output_offset + off;
10102 BFD_ASSERT (local_got_offsets != NULL &&
10103 local_got_offsets[r_symndx] != (bfd_vma) -1);
10105 off = local_got_offsets[r_symndx];
10107 /* The offset must always be a multiple of 4. We use the
10108 least significant bit to record whether we have already
10109 generated the necessary reloc. */
10110 if ((off & 1) != 0)
10114 if (globals->use_rel)
10115 bfd_put_32 (output_bfd, dynreloc_value, sgot->contents + off);
10117 if (bfd_link_pic (info) || dynreloc_st_type == STT_GNU_IFUNC)
10119 Elf_Internal_Rela outrel;
10121 outrel.r_addend = addend + dynreloc_value;
10122 outrel.r_offset = (sgot->output_section->vma
10123 + sgot->output_offset
10125 if (dynreloc_st_type == STT_GNU_IFUNC)
10126 outrel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
10128 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
10129 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
10132 local_got_offsets[r_symndx] |= 1;
10135 value = sgot->output_offset + off;
10137 if (r_type != R_ARM_GOT32)
10138 value += sgot->output_section->vma;
10140 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10141 contents, rel->r_offset, value,
10144 case R_ARM_TLS_LDO32:
10145 value = value - dtpoff_base (info);
10147 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10148 contents, rel->r_offset, value,
10151 case R_ARM_TLS_LDM32:
10158 off = globals->tls_ldm_got.offset;
10160 if ((off & 1) != 0)
10164 /* If we don't know the module number, create a relocation
10166 if (bfd_link_pic (info))
10168 Elf_Internal_Rela outrel;
10170 if (srelgot == NULL)
10173 outrel.r_addend = 0;
10174 outrel.r_offset = (sgot->output_section->vma
10175 + sgot->output_offset + off);
10176 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
10178 if (globals->use_rel)
10179 bfd_put_32 (output_bfd, outrel.r_addend,
10180 sgot->contents + off);
10182 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
10185 bfd_put_32 (output_bfd, 1, sgot->contents + off);
10187 globals->tls_ldm_got.offset |= 1;
10190 value = sgot->output_section->vma + sgot->output_offset + off
10191 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
10193 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10194 contents, rel->r_offset, value,
10198 case R_ARM_TLS_CALL:
10199 case R_ARM_THM_TLS_CALL:
10200 case R_ARM_TLS_GD32:
10201 case R_ARM_TLS_IE32:
10202 case R_ARM_TLS_GOTDESC:
10203 case R_ARM_TLS_DESCSEQ:
10204 case R_ARM_THM_TLS_DESCSEQ:
10206 bfd_vma off, offplt;
10210 BFD_ASSERT (sgot != NULL);
10215 dyn = globals->root.dynamic_sections_created;
10216 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
10217 bfd_link_pic (info),
10219 && (!bfd_link_pic (info)
10220 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10222 *unresolved_reloc_p = FALSE;
10225 off = h->got.offset;
10226 offplt = elf32_arm_hash_entry (h)->tlsdesc_got;
10227 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
10231 BFD_ASSERT (local_got_offsets != NULL);
10232 off = local_got_offsets[r_symndx];
10233 offplt = local_tlsdesc_gotents[r_symndx];
10234 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
10237 /* Linker relaxations happens from one of the
10238 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
10239 if (ELF32_R_TYPE(rel->r_info) != r_type)
10240 tls_type = GOT_TLS_IE;
10242 BFD_ASSERT (tls_type != GOT_UNKNOWN);
10244 if ((off & 1) != 0)
10248 bfd_boolean need_relocs = FALSE;
10249 Elf_Internal_Rela outrel;
10252 /* The GOT entries have not been initialized yet. Do it
10253 now, and emit any relocations. If both an IE GOT and a
10254 GD GOT are necessary, we emit the GD first. */
10256 if ((bfd_link_pic (info) || indx != 0)
10258 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10259 || h->root.type != bfd_link_hash_undefweak))
10261 need_relocs = TRUE;
10262 BFD_ASSERT (srelgot != NULL);
10265 if (tls_type & GOT_TLS_GDESC)
10269 /* We should have relaxed, unless this is an undefined
10271 BFD_ASSERT ((h && (h->root.type == bfd_link_hash_undefweak))
10272 || bfd_link_pic (info));
10273 BFD_ASSERT (globals->sgotplt_jump_table_size + offplt + 8
10274 <= globals->root.sgotplt->size);
10276 outrel.r_addend = 0;
10277 outrel.r_offset = (globals->root.sgotplt->output_section->vma
10278 + globals->root.sgotplt->output_offset
10280 + globals->sgotplt_jump_table_size);
10282 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DESC);
10283 sreloc = globals->root.srelplt;
10284 loc = sreloc->contents;
10285 loc += globals->next_tls_desc_index++ * RELOC_SIZE (globals);
10286 BFD_ASSERT (loc + RELOC_SIZE (globals)
10287 <= sreloc->contents + sreloc->size);
10289 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
10291 /* For globals, the first word in the relocation gets
10292 the relocation index and the top bit set, or zero,
10293 if we're binding now. For locals, it gets the
10294 symbol's offset in the tls section. */
10295 bfd_put_32 (output_bfd,
10296 !h ? value - elf_hash_table (info)->tls_sec->vma
10297 : info->flags & DF_BIND_NOW ? 0
10298 : 0x80000000 | ELF32_R_SYM (outrel.r_info),
10299 globals->root.sgotplt->contents + offplt
10300 + globals->sgotplt_jump_table_size);
10302 /* Second word in the relocation is always zero. */
10303 bfd_put_32 (output_bfd, 0,
10304 globals->root.sgotplt->contents + offplt
10305 + globals->sgotplt_jump_table_size + 4);
10307 if (tls_type & GOT_TLS_GD)
10311 outrel.r_addend = 0;
10312 outrel.r_offset = (sgot->output_section->vma
10313 + sgot->output_offset
10315 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
10317 if (globals->use_rel)
10318 bfd_put_32 (output_bfd, outrel.r_addend,
10319 sgot->contents + cur_off);
10321 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
10324 bfd_put_32 (output_bfd, value - dtpoff_base (info),
10325 sgot->contents + cur_off + 4);
10328 outrel.r_addend = 0;
10329 outrel.r_info = ELF32_R_INFO (indx,
10330 R_ARM_TLS_DTPOFF32);
10331 outrel.r_offset += 4;
10333 if (globals->use_rel)
10334 bfd_put_32 (output_bfd, outrel.r_addend,
10335 sgot->contents + cur_off + 4);
10337 elf32_arm_add_dynreloc (output_bfd, info,
10343 /* If we are not emitting relocations for a
10344 general dynamic reference, then we must be in a
10345 static link or an executable link with the
10346 symbol binding locally. Mark it as belonging
10347 to module 1, the executable. */
10348 bfd_put_32 (output_bfd, 1,
10349 sgot->contents + cur_off);
10350 bfd_put_32 (output_bfd, value - dtpoff_base (info),
10351 sgot->contents + cur_off + 4);
10357 if (tls_type & GOT_TLS_IE)
10362 outrel.r_addend = value - dtpoff_base (info);
10364 outrel.r_addend = 0;
10365 outrel.r_offset = (sgot->output_section->vma
10366 + sgot->output_offset
10368 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
10370 if (globals->use_rel)
10371 bfd_put_32 (output_bfd, outrel.r_addend,
10372 sgot->contents + cur_off);
10374 elf32_arm_add_dynreloc (output_bfd, info, srelgot, &outrel);
10377 bfd_put_32 (output_bfd, tpoff (info, value),
10378 sgot->contents + cur_off);
10383 h->got.offset |= 1;
10385 local_got_offsets[r_symndx] |= 1;
10388 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
10390 else if (tls_type & GOT_TLS_GDESC)
10393 if (ELF32_R_TYPE(rel->r_info) == R_ARM_TLS_CALL
10394 || ELF32_R_TYPE(rel->r_info) == R_ARM_THM_TLS_CALL)
10396 bfd_signed_vma offset;
10397 /* TLS stubs are arm mode. The original symbol is a
10398 data object, so branch_type is bogus. */
10399 branch_type = ST_BRANCH_TO_ARM;
10400 enum elf32_arm_stub_type stub_type
10401 = arm_type_of_stub (info, input_section, rel,
10402 st_type, &branch_type,
10403 (struct elf32_arm_link_hash_entry *)h,
10404 globals->tls_trampoline, globals->root.splt,
10405 input_bfd, sym_name);
10407 if (stub_type != arm_stub_none)
10409 struct elf32_arm_stub_hash_entry *stub_entry
10410 = elf32_arm_get_stub_entry
10411 (input_section, globals->root.splt, 0, rel,
10412 globals, stub_type);
10413 offset = (stub_entry->stub_offset
10414 + stub_entry->stub_sec->output_offset
10415 + stub_entry->stub_sec->output_section->vma);
10418 offset = (globals->root.splt->output_section->vma
10419 + globals->root.splt->output_offset
10420 + globals->tls_trampoline);
10422 if (ELF32_R_TYPE(rel->r_info) == R_ARM_TLS_CALL)
10424 unsigned long inst;
10426 offset -= (input_section->output_section->vma
10427 + input_section->output_offset
10428 + rel->r_offset + 8);
10430 inst = offset >> 2;
10431 inst &= 0x00ffffff;
10432 value = inst | (globals->use_blx ? 0xfa000000 : 0xeb000000);
10436 /* Thumb blx encodes the offset in a complicated
10438 unsigned upper_insn, lower_insn;
10441 offset -= (input_section->output_section->vma
10442 + input_section->output_offset
10443 + rel->r_offset + 4);
10445 if (stub_type != arm_stub_none
10446 && arm_stub_is_thumb (stub_type))
10448 lower_insn = 0xd000;
10452 lower_insn = 0xc000;
10453 /* Round up the offset to a word boundary. */
10454 offset = (offset + 2) & ~2;
10458 upper_insn = (0xf000
10459 | ((offset >> 12) & 0x3ff)
10461 lower_insn |= (((!((offset >> 23) & 1)) ^ neg) << 13)
10462 | (((!((offset >> 22) & 1)) ^ neg) << 11)
10463 | ((offset >> 1) & 0x7ff);
10464 bfd_put_16 (input_bfd, upper_insn, hit_data);
10465 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
10466 return bfd_reloc_ok;
10469 /* These relocations needs special care, as besides the fact
10470 they point somewhere in .gotplt, the addend must be
10471 adjusted accordingly depending on the type of instruction
10473 else if ((r_type == R_ARM_TLS_GOTDESC) && (tls_type & GOT_TLS_GDESC))
10475 unsigned long data, insn;
10478 data = bfd_get_32 (input_bfd, hit_data);
10484 insn = bfd_get_16 (input_bfd, contents + rel->r_offset - data);
10485 if ((insn & 0xf000) == 0xf000 || (insn & 0xf800) == 0xe800)
10486 insn = (insn << 16)
10487 | bfd_get_16 (input_bfd,
10488 contents + rel->r_offset - data + 2);
10489 if ((insn & 0xf800c000) == 0xf000c000)
10492 else if ((insn & 0xffffff00) == 0x4400)
10497 (*_bfd_error_handler)
10498 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' referenced by TLS_GOTDESC"),
10499 input_bfd, input_section,
10500 (unsigned long)rel->r_offset, insn);
10501 return bfd_reloc_notsupported;
10506 insn = bfd_get_32 (input_bfd, contents + rel->r_offset - data);
10508 switch (insn >> 24)
10510 case 0xeb: /* bl */
10511 case 0xfa: /* blx */
10515 case 0xe0: /* add */
10520 (*_bfd_error_handler)
10521 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' referenced by TLS_GOTDESC"),
10522 input_bfd, input_section,
10523 (unsigned long)rel->r_offset, insn);
10524 return bfd_reloc_notsupported;
10528 value += ((globals->root.sgotplt->output_section->vma
10529 + globals->root.sgotplt->output_offset + off)
10530 - (input_section->output_section->vma
10531 + input_section->output_offset
10533 + globals->sgotplt_jump_table_size);
10536 value = ((globals->root.sgot->output_section->vma
10537 + globals->root.sgot->output_offset + off)
10538 - (input_section->output_section->vma
10539 + input_section->output_offset + rel->r_offset));
10541 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10542 contents, rel->r_offset, value,
10546 case R_ARM_TLS_LE32:
10547 if (bfd_link_dll (info))
10549 (*_bfd_error_handler)
10550 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
10551 input_bfd, input_section,
10552 (long) rel->r_offset, howto->name);
10553 return bfd_reloc_notsupported;
10556 value = tpoff (info, value);
10558 return _bfd_final_link_relocate (howto, input_bfd, input_section,
10559 contents, rel->r_offset, value,
10563 if (globals->fix_v4bx)
10565 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
10567 /* Ensure that we have a BX instruction. */
10568 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
10570 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
10572 /* Branch to veneer. */
10574 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
10575 glue_addr -= input_section->output_section->vma
10576 + input_section->output_offset
10577 + rel->r_offset + 8;
10578 insn = (insn & 0xf0000000) | 0x0a000000
10579 | ((glue_addr >> 2) & 0x00ffffff);
10583 /* Preserve Rm (lowest four bits) and the condition code
10584 (highest four bits). Other bits encode MOV PC,Rm. */
10585 insn = (insn & 0xf000000f) | 0x01a0f000;
10588 bfd_put_32 (input_bfd, insn, hit_data);
10590 return bfd_reloc_ok;
10592 case R_ARM_MOVW_ABS_NC:
10593 case R_ARM_MOVT_ABS:
10594 case R_ARM_MOVW_PREL_NC:
10595 case R_ARM_MOVT_PREL:
10596 /* Until we properly support segment-base-relative addressing then
10597 we assume the segment base to be zero, as for the group relocations.
10598 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
10599 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
10600 case R_ARM_MOVW_BREL_NC:
10601 case R_ARM_MOVW_BREL:
10602 case R_ARM_MOVT_BREL:
10604 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
10606 if (globals->use_rel)
10608 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
10609 signed_addend = (addend ^ 0x8000) - 0x8000;
10612 value += signed_addend;
10614 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
10615 value -= (input_section->output_section->vma
10616 + input_section->output_offset + rel->r_offset);
10618 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
10619 return bfd_reloc_overflow;
10621 if (branch_type == ST_BRANCH_TO_THUMB)
10624 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
10625 || r_type == R_ARM_MOVT_BREL)
10628 insn &= 0xfff0f000;
10629 insn |= value & 0xfff;
10630 insn |= (value & 0xf000) << 4;
10631 bfd_put_32 (input_bfd, insn, hit_data);
10633 return bfd_reloc_ok;
10635 case R_ARM_THM_MOVW_ABS_NC:
10636 case R_ARM_THM_MOVT_ABS:
10637 case R_ARM_THM_MOVW_PREL_NC:
10638 case R_ARM_THM_MOVT_PREL:
10639 /* Until we properly support segment-base-relative addressing then
10640 we assume the segment base to be zero, as for the above relocations.
10641 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
10642 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
10643 as R_ARM_THM_MOVT_ABS. */
10644 case R_ARM_THM_MOVW_BREL_NC:
10645 case R_ARM_THM_MOVW_BREL:
10646 case R_ARM_THM_MOVT_BREL:
10650 insn = bfd_get_16 (input_bfd, hit_data) << 16;
10651 insn |= bfd_get_16 (input_bfd, hit_data + 2);
10653 if (globals->use_rel)
10655 addend = ((insn >> 4) & 0xf000)
10656 | ((insn >> 15) & 0x0800)
10657 | ((insn >> 4) & 0x0700)
10659 signed_addend = (addend ^ 0x8000) - 0x8000;
10662 value += signed_addend;
10664 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
10665 value -= (input_section->output_section->vma
10666 + input_section->output_offset + rel->r_offset);
10668 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
10669 return bfd_reloc_overflow;
10671 if (branch_type == ST_BRANCH_TO_THUMB)
10674 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
10675 || r_type == R_ARM_THM_MOVT_BREL)
10678 insn &= 0xfbf08f00;
10679 insn |= (value & 0xf000) << 4;
10680 insn |= (value & 0x0800) << 15;
10681 insn |= (value & 0x0700) << 4;
10682 insn |= (value & 0x00ff);
10684 bfd_put_16 (input_bfd, insn >> 16, hit_data);
10685 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
10687 return bfd_reloc_ok;
10689 case R_ARM_ALU_PC_G0_NC:
10690 case R_ARM_ALU_PC_G1_NC:
10691 case R_ARM_ALU_PC_G0:
10692 case R_ARM_ALU_PC_G1:
10693 case R_ARM_ALU_PC_G2:
10694 case R_ARM_ALU_SB_G0_NC:
10695 case R_ARM_ALU_SB_G1_NC:
10696 case R_ARM_ALU_SB_G0:
10697 case R_ARM_ALU_SB_G1:
10698 case R_ARM_ALU_SB_G2:
10700 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
10701 bfd_vma pc = input_section->output_section->vma
10702 + input_section->output_offset + rel->r_offset;
10703 /* sb is the origin of the *segment* containing the symbol. */
10704 bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
10707 bfd_signed_vma signed_value;
10710 /* Determine which group of bits to select. */
10713 case R_ARM_ALU_PC_G0_NC:
10714 case R_ARM_ALU_PC_G0:
10715 case R_ARM_ALU_SB_G0_NC:
10716 case R_ARM_ALU_SB_G0:
10720 case R_ARM_ALU_PC_G1_NC:
10721 case R_ARM_ALU_PC_G1:
10722 case R_ARM_ALU_SB_G1_NC:
10723 case R_ARM_ALU_SB_G1:
10727 case R_ARM_ALU_PC_G2:
10728 case R_ARM_ALU_SB_G2:
10736 /* If REL, extract the addend from the insn. If RELA, it will
10737 have already been fetched for us. */
10738 if (globals->use_rel)
10741 bfd_vma constant = insn & 0xff;
10742 bfd_vma rotation = (insn & 0xf00) >> 8;
10745 signed_addend = constant;
10748 /* Compensate for the fact that in the instruction, the
10749 rotation is stored in multiples of 2 bits. */
10752 /* Rotate "constant" right by "rotation" bits. */
10753 signed_addend = (constant >> rotation) |
10754 (constant << (8 * sizeof (bfd_vma) - rotation));
10757 /* Determine if the instruction is an ADD or a SUB.
10758 (For REL, this determines the sign of the addend.) */
10759 negative = identify_add_or_sub (insn);
10762 (*_bfd_error_handler)
10763 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
10764 input_bfd, input_section,
10765 (long) rel->r_offset, howto->name);
10766 return bfd_reloc_overflow;
10769 signed_addend *= negative;
10772 /* Compute the value (X) to go in the place. */
10773 if (r_type == R_ARM_ALU_PC_G0_NC
10774 || r_type == R_ARM_ALU_PC_G1_NC
10775 || r_type == R_ARM_ALU_PC_G0
10776 || r_type == R_ARM_ALU_PC_G1
10777 || r_type == R_ARM_ALU_PC_G2)
10779 signed_value = value - pc + signed_addend;
10781 /* Section base relative. */
10782 signed_value = value - sb + signed_addend;
10784 /* If the target symbol is a Thumb function, then set the
10785 Thumb bit in the address. */
10786 if (branch_type == ST_BRANCH_TO_THUMB)
10789 /* Calculate the value of the relevant G_n, in encoded
10790 constant-with-rotation format. */
10791 g_n = calculate_group_reloc_mask (signed_value < 0 ? - signed_value : signed_value,
10794 /* Check for overflow if required. */
10795 if ((r_type == R_ARM_ALU_PC_G0
10796 || r_type == R_ARM_ALU_PC_G1
10797 || r_type == R_ARM_ALU_PC_G2
10798 || r_type == R_ARM_ALU_SB_G0
10799 || r_type == R_ARM_ALU_SB_G1
10800 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
10802 (*_bfd_error_handler)
10803 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10804 input_bfd, input_section,
10805 (long) rel->r_offset, signed_value < 0 ? - signed_value : signed_value,
10807 return bfd_reloc_overflow;
10810 /* Mask out the value and the ADD/SUB part of the opcode; take care
10811 not to destroy the S bit. */
10812 insn &= 0xff1ff000;
10814 /* Set the opcode according to whether the value to go in the
10815 place is negative. */
10816 if (signed_value < 0)
10821 /* Encode the offset. */
10824 bfd_put_32 (input_bfd, insn, hit_data);
10826 return bfd_reloc_ok;
10828 case R_ARM_LDR_PC_G0:
10829 case R_ARM_LDR_PC_G1:
10830 case R_ARM_LDR_PC_G2:
10831 case R_ARM_LDR_SB_G0:
10832 case R_ARM_LDR_SB_G1:
10833 case R_ARM_LDR_SB_G2:
10835 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
10836 bfd_vma pc = input_section->output_section->vma
10837 + input_section->output_offset + rel->r_offset;
10838 /* sb is the origin of the *segment* containing the symbol. */
10839 bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
10841 bfd_signed_vma signed_value;
10844 /* Determine which groups of bits to calculate. */
10847 case R_ARM_LDR_PC_G0:
10848 case R_ARM_LDR_SB_G0:
10852 case R_ARM_LDR_PC_G1:
10853 case R_ARM_LDR_SB_G1:
10857 case R_ARM_LDR_PC_G2:
10858 case R_ARM_LDR_SB_G2:
10866 /* If REL, extract the addend from the insn. If RELA, it will
10867 have already been fetched for us. */
10868 if (globals->use_rel)
10870 int negative = (insn & (1 << 23)) ? 1 : -1;
10871 signed_addend = negative * (insn & 0xfff);
10874 /* Compute the value (X) to go in the place. */
10875 if (r_type == R_ARM_LDR_PC_G0
10876 || r_type == R_ARM_LDR_PC_G1
10877 || r_type == R_ARM_LDR_PC_G2)
10879 signed_value = value - pc + signed_addend;
10881 /* Section base relative. */
10882 signed_value = value - sb + signed_addend;
10884 /* Calculate the value of the relevant G_{n-1} to obtain
10885 the residual at that stage. */
10886 calculate_group_reloc_mask (signed_value < 0 ? - signed_value : signed_value,
10887 group - 1, &residual);
10889 /* Check for overflow. */
10890 if (residual >= 0x1000)
10892 (*_bfd_error_handler)
10893 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10894 input_bfd, input_section,
10895 (long) rel->r_offset, labs (signed_value), howto->name);
10896 return bfd_reloc_overflow;
10899 /* Mask out the value and U bit. */
10900 insn &= 0xff7ff000;
10902 /* Set the U bit if the value to go in the place is non-negative. */
10903 if (signed_value >= 0)
10906 /* Encode the offset. */
10909 bfd_put_32 (input_bfd, insn, hit_data);
10911 return bfd_reloc_ok;
10913 case R_ARM_LDRS_PC_G0:
10914 case R_ARM_LDRS_PC_G1:
10915 case R_ARM_LDRS_PC_G2:
10916 case R_ARM_LDRS_SB_G0:
10917 case R_ARM_LDRS_SB_G1:
10918 case R_ARM_LDRS_SB_G2:
10920 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
10921 bfd_vma pc = input_section->output_section->vma
10922 + input_section->output_offset + rel->r_offset;
10923 /* sb is the origin of the *segment* containing the symbol. */
10924 bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
10926 bfd_signed_vma signed_value;
10929 /* Determine which groups of bits to calculate. */
10932 case R_ARM_LDRS_PC_G0:
10933 case R_ARM_LDRS_SB_G0:
10937 case R_ARM_LDRS_PC_G1:
10938 case R_ARM_LDRS_SB_G1:
10942 case R_ARM_LDRS_PC_G2:
10943 case R_ARM_LDRS_SB_G2:
10951 /* If REL, extract the addend from the insn. If RELA, it will
10952 have already been fetched for us. */
10953 if (globals->use_rel)
10955 int negative = (insn & (1 << 23)) ? 1 : -1;
10956 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
10959 /* Compute the value (X) to go in the place. */
10960 if (r_type == R_ARM_LDRS_PC_G0
10961 || r_type == R_ARM_LDRS_PC_G1
10962 || r_type == R_ARM_LDRS_PC_G2)
10964 signed_value = value - pc + signed_addend;
10966 /* Section base relative. */
10967 signed_value = value - sb + signed_addend;
10969 /* Calculate the value of the relevant G_{n-1} to obtain
10970 the residual at that stage. */
10971 calculate_group_reloc_mask (signed_value < 0 ? - signed_value : signed_value,
10972 group - 1, &residual);
10974 /* Check for overflow. */
10975 if (residual >= 0x100)
10977 (*_bfd_error_handler)
10978 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10979 input_bfd, input_section,
10980 (long) rel->r_offset, labs (signed_value), howto->name);
10981 return bfd_reloc_overflow;
10984 /* Mask out the value and U bit. */
10985 insn &= 0xff7ff0f0;
10987 /* Set the U bit if the value to go in the place is non-negative. */
10988 if (signed_value >= 0)
10991 /* Encode the offset. */
10992 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
10994 bfd_put_32 (input_bfd, insn, hit_data);
10996 return bfd_reloc_ok;
10998 case R_ARM_LDC_PC_G0:
10999 case R_ARM_LDC_PC_G1:
11000 case R_ARM_LDC_PC_G2:
11001 case R_ARM_LDC_SB_G0:
11002 case R_ARM_LDC_SB_G1:
11003 case R_ARM_LDC_SB_G2:
11005 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
11006 bfd_vma pc = input_section->output_section->vma
11007 + input_section->output_offset + rel->r_offset;
11008 /* sb is the origin of the *segment* containing the symbol. */
11009 bfd_vma sb = sym_sec ? sym_sec->output_section->vma : 0;
11011 bfd_signed_vma signed_value;
11014 /* Determine which groups of bits to calculate. */
11017 case R_ARM_LDC_PC_G0:
11018 case R_ARM_LDC_SB_G0:
11022 case R_ARM_LDC_PC_G1:
11023 case R_ARM_LDC_SB_G1:
11027 case R_ARM_LDC_PC_G2:
11028 case R_ARM_LDC_SB_G2:
11036 /* If REL, extract the addend from the insn. If RELA, it will
11037 have already been fetched for us. */
11038 if (globals->use_rel)
11040 int negative = (insn & (1 << 23)) ? 1 : -1;
11041 signed_addend = negative * ((insn & 0xff) << 2);
11044 /* Compute the value (X) to go in the place. */
11045 if (r_type == R_ARM_LDC_PC_G0
11046 || r_type == R_ARM_LDC_PC_G1
11047 || r_type == R_ARM_LDC_PC_G2)
11049 signed_value = value - pc + signed_addend;
11051 /* Section base relative. */
11052 signed_value = value - sb + signed_addend;
11054 /* Calculate the value of the relevant G_{n-1} to obtain
11055 the residual at that stage. */
11056 calculate_group_reloc_mask (signed_value < 0 ? - signed_value : signed_value,
11057 group - 1, &residual);
11059 /* Check for overflow. (The absolute value to go in the place must be
11060 divisible by four and, after having been divided by four, must
11061 fit in eight bits.) */
11062 if ((residual & 0x3) != 0 || residual >= 0x400)
11064 (*_bfd_error_handler)
11065 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
11066 input_bfd, input_section,
11067 (long) rel->r_offset, labs (signed_value), howto->name);
11068 return bfd_reloc_overflow;
11071 /* Mask out the value and U bit. */
11072 insn &= 0xff7fff00;
11074 /* Set the U bit if the value to go in the place is non-negative. */
11075 if (signed_value >= 0)
11078 /* Encode the offset. */
11079 insn |= residual >> 2;
11081 bfd_put_32 (input_bfd, insn, hit_data);
11083 return bfd_reloc_ok;
11085 case R_ARM_THM_ALU_ABS_G0_NC:
11086 case R_ARM_THM_ALU_ABS_G1_NC:
11087 case R_ARM_THM_ALU_ABS_G2_NC:
11088 case R_ARM_THM_ALU_ABS_G3_NC:
11090 const int shift_array[4] = {0, 8, 16, 24};
11091 bfd_vma insn = bfd_get_16 (input_bfd, hit_data);
11092 bfd_vma addr = value;
11093 int shift = shift_array[r_type - R_ARM_THM_ALU_ABS_G0_NC];
11095 /* Compute address. */
11096 if (globals->use_rel)
11097 signed_addend = insn & 0xff;
11098 addr += signed_addend;
11099 if (branch_type == ST_BRANCH_TO_THUMB)
11101 /* Clean imm8 insn. */
11103 /* And update with correct part of address. */
11104 insn |= (addr >> shift) & 0xff;
11106 bfd_put_16 (input_bfd, insn, hit_data);
11109 *unresolved_reloc_p = FALSE;
11110 return bfd_reloc_ok;
11113 return bfd_reloc_notsupported;
11117 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
11119 arm_add_to_rel (bfd * abfd,
11120 bfd_byte * address,
11121 reloc_howto_type * howto,
11122 bfd_signed_vma increment)
11124 bfd_signed_vma addend;
11126 if (howto->type == R_ARM_THM_CALL
11127 || howto->type == R_ARM_THM_JUMP24)
11129 int upper_insn, lower_insn;
11132 upper_insn = bfd_get_16 (abfd, address);
11133 lower_insn = bfd_get_16 (abfd, address + 2);
11134 upper = upper_insn & 0x7ff;
11135 lower = lower_insn & 0x7ff;
11137 addend = (upper << 12) | (lower << 1);
11138 addend += increment;
11141 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
11142 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
11144 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
11145 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
11151 contents = bfd_get_32 (abfd, address);
11153 /* Get the (signed) value from the instruction. */
11154 addend = contents & howto->src_mask;
11155 if (addend & ((howto->src_mask + 1) >> 1))
11157 bfd_signed_vma mask;
11160 mask &= ~ howto->src_mask;
11164 /* Add in the increment, (which is a byte value). */
11165 switch (howto->type)
11168 addend += increment;
11175 addend <<= howto->size;
11176 addend += increment;
11178 /* Should we check for overflow here ? */
11180 /* Drop any undesired bits. */
11181 addend >>= howto->rightshift;
11185 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
11187 bfd_put_32 (abfd, contents, address);
11191 #define IS_ARM_TLS_RELOC(R_TYPE) \
11192 ((R_TYPE) == R_ARM_TLS_GD32 \
11193 || (R_TYPE) == R_ARM_TLS_LDO32 \
11194 || (R_TYPE) == R_ARM_TLS_LDM32 \
11195 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
11196 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
11197 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
11198 || (R_TYPE) == R_ARM_TLS_LE32 \
11199 || (R_TYPE) == R_ARM_TLS_IE32 \
11200 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
11202 /* Specific set of relocations for the gnu tls dialect. */
11203 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
11204 ((R_TYPE) == R_ARM_TLS_GOTDESC \
11205 || (R_TYPE) == R_ARM_TLS_CALL \
11206 || (R_TYPE) == R_ARM_THM_TLS_CALL \
11207 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
11208 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
11210 /* Relocate an ARM ELF section. */
11213 elf32_arm_relocate_section (bfd * output_bfd,
11214 struct bfd_link_info * info,
11216 asection * input_section,
11217 bfd_byte * contents,
11218 Elf_Internal_Rela * relocs,
11219 Elf_Internal_Sym * local_syms,
11220 asection ** local_sections)
11222 Elf_Internal_Shdr *symtab_hdr;
11223 struct elf_link_hash_entry **sym_hashes;
11224 Elf_Internal_Rela *rel;
11225 Elf_Internal_Rela *relend;
11227 struct elf32_arm_link_hash_table * globals;
11229 globals = elf32_arm_hash_table (info);
11230 if (globals == NULL)
11233 symtab_hdr = & elf_symtab_hdr (input_bfd);
11234 sym_hashes = elf_sym_hashes (input_bfd);
11237 relend = relocs + input_section->reloc_count;
11238 for (; rel < relend; rel++)
11241 reloc_howto_type * howto;
11242 unsigned long r_symndx;
11243 Elf_Internal_Sym * sym;
11245 struct elf_link_hash_entry * h;
11246 bfd_vma relocation;
11247 bfd_reloc_status_type r;
11250 bfd_boolean unresolved_reloc = FALSE;
11251 char *error_message = NULL;
11253 r_symndx = ELF32_R_SYM (rel->r_info);
11254 r_type = ELF32_R_TYPE (rel->r_info);
11255 r_type = arm_real_reloc_type (globals, r_type);
11257 if ( r_type == R_ARM_GNU_VTENTRY
11258 || r_type == R_ARM_GNU_VTINHERIT)
11261 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
11262 howto = bfd_reloc.howto;
11268 if (r_symndx < symtab_hdr->sh_info)
11270 sym = local_syms + r_symndx;
11271 sym_type = ELF32_ST_TYPE (sym->st_info);
11272 sec = local_sections[r_symndx];
11274 /* An object file might have a reference to a local
11275 undefined symbol. This is a daft object file, but we
11276 should at least do something about it. V4BX & NONE
11277 relocations do not use the symbol and are explicitly
11278 allowed to use the undefined symbol, so allow those.
11279 Likewise for relocations against STN_UNDEF. */
11280 if (r_type != R_ARM_V4BX
11281 && r_type != R_ARM_NONE
11282 && r_symndx != STN_UNDEF
11283 && bfd_is_und_section (sec)
11284 && ELF_ST_BIND (sym->st_info) != STB_WEAK)
11286 if (!info->callbacks->undefined_symbol
11287 (info, bfd_elf_string_from_elf_section
11288 (input_bfd, symtab_hdr->sh_link, sym->st_name),
11289 input_bfd, input_section,
11290 rel->r_offset, TRUE))
11294 if (globals->use_rel)
11296 relocation = (sec->output_section->vma
11297 + sec->output_offset
11299 if (!bfd_link_relocatable (info)
11300 && (sec->flags & SEC_MERGE)
11301 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
11304 bfd_vma addend, value;
11308 case R_ARM_MOVW_ABS_NC:
11309 case R_ARM_MOVT_ABS:
11310 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
11311 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
11312 addend = (addend ^ 0x8000) - 0x8000;
11315 case R_ARM_THM_MOVW_ABS_NC:
11316 case R_ARM_THM_MOVT_ABS:
11317 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
11319 value |= bfd_get_16 (input_bfd,
11320 contents + rel->r_offset + 2);
11321 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
11322 | ((value & 0x04000000) >> 15);
11323 addend = (addend ^ 0x8000) - 0x8000;
11327 if (howto->rightshift
11328 || (howto->src_mask & (howto->src_mask + 1)))
11330 (*_bfd_error_handler)
11331 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
11332 input_bfd, input_section,
11333 (long) rel->r_offset, howto->name);
11337 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
11339 /* Get the (signed) value from the instruction. */
11340 addend = value & howto->src_mask;
11341 if (addend & ((howto->src_mask + 1) >> 1))
11343 bfd_signed_vma mask;
11346 mask &= ~ howto->src_mask;
11354 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
11356 addend += msec->output_section->vma + msec->output_offset;
11358 /* Cases here must match those in the preceding
11359 switch statement. */
11362 case R_ARM_MOVW_ABS_NC:
11363 case R_ARM_MOVT_ABS:
11364 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
11365 | (addend & 0xfff);
11366 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
11369 case R_ARM_THM_MOVW_ABS_NC:
11370 case R_ARM_THM_MOVT_ABS:
11371 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
11372 | (addend & 0xff) | ((addend & 0x0800) << 15);
11373 bfd_put_16 (input_bfd, value >> 16,
11374 contents + rel->r_offset);
11375 bfd_put_16 (input_bfd, value,
11376 contents + rel->r_offset + 2);
11380 value = (value & ~ howto->dst_mask)
11381 | (addend & howto->dst_mask);
11382 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
11388 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
11392 bfd_boolean warned, ignored;
11394 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
11395 r_symndx, symtab_hdr, sym_hashes,
11396 h, sec, relocation,
11397 unresolved_reloc, warned, ignored);
11399 sym_type = h->type;
11402 if (sec != NULL && discarded_section (sec))
11403 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
11404 rel, 1, relend, howto, 0, contents);
11406 if (bfd_link_relocatable (info))
11408 /* This is a relocatable link. We don't have to change
11409 anything, unless the reloc is against a section symbol,
11410 in which case we have to adjust according to where the
11411 section symbol winds up in the output section. */
11412 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
11414 if (globals->use_rel)
11415 arm_add_to_rel (input_bfd, contents + rel->r_offset,
11416 howto, (bfd_signed_vma) sec->output_offset);
11418 rel->r_addend += sec->output_offset;
11424 name = h->root.root.string;
11427 name = (bfd_elf_string_from_elf_section
11428 (input_bfd, symtab_hdr->sh_link, sym->st_name));
11429 if (name == NULL || *name == '\0')
11430 name = bfd_section_name (input_bfd, sec);
11433 if (r_symndx != STN_UNDEF
11434 && r_type != R_ARM_NONE
11436 || h->root.type == bfd_link_hash_defined
11437 || h->root.type == bfd_link_hash_defweak)
11438 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
11440 (*_bfd_error_handler)
11441 ((sym_type == STT_TLS
11442 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
11443 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
11446 (long) rel->r_offset,
11451 /* We call elf32_arm_final_link_relocate unless we're completely
11452 done, i.e., the relaxation produced the final output we want,
11453 and we won't let anybody mess with it. Also, we have to do
11454 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
11455 both in relaxed and non-relaxed cases. */
11456 if ((elf32_arm_tls_transition (info, r_type, h) != (unsigned)r_type)
11457 || (IS_ARM_TLS_GNU_RELOC (r_type)
11458 && !((h ? elf32_arm_hash_entry (h)->tls_type :
11459 elf32_arm_local_got_tls_type (input_bfd)[r_symndx])
11462 r = elf32_arm_tls_relax (globals, input_bfd, input_section,
11463 contents, rel, h == NULL);
11464 /* This may have been marked unresolved because it came from
11465 a shared library. But we've just dealt with that. */
11466 unresolved_reloc = 0;
11469 r = bfd_reloc_continue;
11471 if (r == bfd_reloc_continue)
11472 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
11473 input_section, contents, rel,
11474 relocation, info, sec, name, sym_type,
11475 (h ? h->target_internal
11476 : ARM_SYM_BRANCH_TYPE (sym)), h,
11477 &unresolved_reloc, &error_message);
11479 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
11480 because such sections are not SEC_ALLOC and thus ld.so will
11481 not process them. */
11482 if (unresolved_reloc
11483 && !((input_section->flags & SEC_DEBUGGING) != 0
11485 && _bfd_elf_section_offset (output_bfd, info, input_section,
11486 rel->r_offset) != (bfd_vma) -1)
11488 (*_bfd_error_handler)
11489 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
11492 (long) rel->r_offset,
11494 h->root.root.string);
11498 if (r != bfd_reloc_ok)
11502 case bfd_reloc_overflow:
11503 /* If the overflowing reloc was to an undefined symbol,
11504 we have already printed one error message and there
11505 is no point complaining again. */
11507 h->root.type != bfd_link_hash_undefined)
11508 && (!((*info->callbacks->reloc_overflow)
11509 (info, (h ? &h->root : NULL), name, howto->name,
11510 (bfd_vma) 0, input_bfd, input_section,
11515 case bfd_reloc_undefined:
11516 if (!((*info->callbacks->undefined_symbol)
11517 (info, name, input_bfd, input_section,
11518 rel->r_offset, TRUE)))
11522 case bfd_reloc_outofrange:
11523 error_message = _("out of range");
11526 case bfd_reloc_notsupported:
11527 error_message = _("unsupported relocation");
11530 case bfd_reloc_dangerous:
11531 /* error_message should already be set. */
11535 error_message = _("unknown error");
11536 /* Fall through. */
11539 BFD_ASSERT (error_message != NULL);
11540 if (!((*info->callbacks->reloc_dangerous)
11541 (info, error_message, input_bfd, input_section,
11552 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
11553 adds the edit to the start of the list. (The list must be built in order of
11554 ascending TINDEX: the function's callers are primarily responsible for
11555 maintaining that condition). */
11558 add_unwind_table_edit (arm_unwind_table_edit **head,
11559 arm_unwind_table_edit **tail,
11560 arm_unwind_edit_type type,
11561 asection *linked_section,
11562 unsigned int tindex)
11564 arm_unwind_table_edit *new_edit = (arm_unwind_table_edit *)
11565 xmalloc (sizeof (arm_unwind_table_edit));
11567 new_edit->type = type;
11568 new_edit->linked_section = linked_section;
11569 new_edit->index = tindex;
11573 new_edit->next = NULL;
11576 (*tail)->next = new_edit;
11578 (*tail) = new_edit;
11581 (*head) = new_edit;
11585 new_edit->next = *head;
11594 static _arm_elf_section_data *get_arm_elf_section_data (asection *);
11596 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
11598 adjust_exidx_size(asection *exidx_sec, int adjust)
11602 if (!exidx_sec->rawsize)
11603 exidx_sec->rawsize = exidx_sec->size;
11605 bfd_set_section_size (exidx_sec->owner, exidx_sec, exidx_sec->size + adjust);
11606 out_sec = exidx_sec->output_section;
11607 /* Adjust size of output section. */
11608 bfd_set_section_size (out_sec->owner, out_sec, out_sec->size +adjust);
11611 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
11613 insert_cantunwind_after(asection *text_sec, asection *exidx_sec)
11615 struct _arm_elf_section_data *exidx_arm_data;
11617 exidx_arm_data = get_arm_elf_section_data (exidx_sec);
11618 add_unwind_table_edit (
11619 &exidx_arm_data->u.exidx.unwind_edit_list,
11620 &exidx_arm_data->u.exidx.unwind_edit_tail,
11621 INSERT_EXIDX_CANTUNWIND_AT_END, text_sec, UINT_MAX);
11623 exidx_arm_data->additional_reloc_count++;
11625 adjust_exidx_size(exidx_sec, 8);
11628 /* Scan .ARM.exidx tables, and create a list describing edits which should be
11629 made to those tables, such that:
11631 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
11632 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
11633 codes which have been inlined into the index).
11635 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
11637 The edits are applied when the tables are written
11638 (in elf32_arm_write_section). */
11641 elf32_arm_fix_exidx_coverage (asection **text_section_order,
11642 unsigned int num_text_sections,
11643 struct bfd_link_info *info,
11644 bfd_boolean merge_exidx_entries)
11647 unsigned int last_second_word = 0, i;
11648 asection *last_exidx_sec = NULL;
11649 asection *last_text_sec = NULL;
11650 int last_unwind_type = -1;
11652 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
11654 for (inp = info->input_bfds; inp != NULL; inp = inp->link.next)
11658 for (sec = inp->sections; sec != NULL; sec = sec->next)
11660 struct bfd_elf_section_data *elf_sec = elf_section_data (sec);
11661 Elf_Internal_Shdr *hdr = &elf_sec->this_hdr;
11663 if (!hdr || hdr->sh_type != SHT_ARM_EXIDX)
11666 if (elf_sec->linked_to)
11668 Elf_Internal_Shdr *linked_hdr
11669 = &elf_section_data (elf_sec->linked_to)->this_hdr;
11670 struct _arm_elf_section_data *linked_sec_arm_data
11671 = get_arm_elf_section_data (linked_hdr->bfd_section);
11673 if (linked_sec_arm_data == NULL)
11676 /* Link this .ARM.exidx section back from the text section it
11678 linked_sec_arm_data->u.text.arm_exidx_sec = sec;
11683 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
11684 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
11685 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
11687 for (i = 0; i < num_text_sections; i++)
11689 asection *sec = text_section_order[i];
11690 asection *exidx_sec;
11691 struct _arm_elf_section_data *arm_data = get_arm_elf_section_data (sec);
11692 struct _arm_elf_section_data *exidx_arm_data;
11693 bfd_byte *contents = NULL;
11694 int deleted_exidx_bytes = 0;
11696 arm_unwind_table_edit *unwind_edit_head = NULL;
11697 arm_unwind_table_edit *unwind_edit_tail = NULL;
11698 Elf_Internal_Shdr *hdr;
11701 if (arm_data == NULL)
11704 exidx_sec = arm_data->u.text.arm_exidx_sec;
11705 if (exidx_sec == NULL)
11707 /* Section has no unwind data. */
11708 if (last_unwind_type == 0 || !last_exidx_sec)
11711 /* Ignore zero sized sections. */
11712 if (sec->size == 0)
11715 insert_cantunwind_after(last_text_sec, last_exidx_sec);
11716 last_unwind_type = 0;
11720 /* Skip /DISCARD/ sections. */
11721 if (bfd_is_abs_section (exidx_sec->output_section))
11724 hdr = &elf_section_data (exidx_sec)->this_hdr;
11725 if (hdr->sh_type != SHT_ARM_EXIDX)
11728 exidx_arm_data = get_arm_elf_section_data (exidx_sec);
11729 if (exidx_arm_data == NULL)
11732 ibfd = exidx_sec->owner;
11734 if (hdr->contents != NULL)
11735 contents = hdr->contents;
11736 else if (! bfd_malloc_and_get_section (ibfd, exidx_sec, &contents))
11740 for (j = 0; j < hdr->sh_size; j += 8)
11742 unsigned int second_word = bfd_get_32 (ibfd, contents + j + 4);
11746 /* An EXIDX_CANTUNWIND entry. */
11747 if (second_word == 1)
11749 if (last_unwind_type == 0)
11753 /* Inlined unwinding data. Merge if equal to previous. */
11754 else if ((second_word & 0x80000000) != 0)
11756 if (merge_exidx_entries
11757 && last_second_word == second_word && last_unwind_type == 1)
11760 last_second_word = second_word;
11762 /* Normal table entry. In theory we could merge these too,
11763 but duplicate entries are likely to be much less common. */
11767 if (elide && !bfd_link_relocatable (info))
11769 add_unwind_table_edit (&unwind_edit_head, &unwind_edit_tail,
11770 DELETE_EXIDX_ENTRY, NULL, j / 8);
11772 deleted_exidx_bytes += 8;
11775 last_unwind_type = unwind_type;
11778 /* Free contents if we allocated it ourselves. */
11779 if (contents != hdr->contents)
11782 /* Record edits to be applied later (in elf32_arm_write_section). */
11783 exidx_arm_data->u.exidx.unwind_edit_list = unwind_edit_head;
11784 exidx_arm_data->u.exidx.unwind_edit_tail = unwind_edit_tail;
11786 if (deleted_exidx_bytes > 0)
11787 adjust_exidx_size(exidx_sec, -deleted_exidx_bytes);
11789 last_exidx_sec = exidx_sec;
11790 last_text_sec = sec;
11793 /* Add terminating CANTUNWIND entry. */
11794 if (!bfd_link_relocatable (info) && last_exidx_sec
11795 && last_unwind_type != 0)
11796 insert_cantunwind_after(last_text_sec, last_exidx_sec);
11802 elf32_arm_output_glue_section (struct bfd_link_info *info, bfd *obfd,
11803 bfd *ibfd, const char *name)
11805 asection *sec, *osec;
11807 sec = bfd_get_linker_section (ibfd, name);
11808 if (sec == NULL || (sec->flags & SEC_EXCLUDE) != 0)
11811 osec = sec->output_section;
11812 if (elf32_arm_write_section (obfd, info, sec, sec->contents))
11815 if (! bfd_set_section_contents (obfd, osec, sec->contents,
11816 sec->output_offset, sec->size))
11823 elf32_arm_final_link (bfd *abfd, struct bfd_link_info *info)
11825 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
11826 asection *sec, *osec;
11828 if (globals == NULL)
11831 /* Invoke the regular ELF backend linker to do all the work. */
11832 if (!bfd_elf_final_link (abfd, info))
11835 /* Process stub sections (eg BE8 encoding, ...). */
11836 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
11838 for (i=0; i<htab->top_id; i++)
11840 sec = htab->stub_group[i].stub_sec;
11841 /* Only process it once, in its link_sec slot. */
11842 if (sec && i == htab->stub_group[i].link_sec->id)
11844 osec = sec->output_section;
11845 elf32_arm_write_section (abfd, info, sec, sec->contents);
11846 if (! bfd_set_section_contents (abfd, osec, sec->contents,
11847 sec->output_offset, sec->size))
11852 /* Write out any glue sections now that we have created all the
11854 if (globals->bfd_of_glue_owner != NULL)
11856 if (! elf32_arm_output_glue_section (info, abfd,
11857 globals->bfd_of_glue_owner,
11858 ARM2THUMB_GLUE_SECTION_NAME))
11861 if (! elf32_arm_output_glue_section (info, abfd,
11862 globals->bfd_of_glue_owner,
11863 THUMB2ARM_GLUE_SECTION_NAME))
11866 if (! elf32_arm_output_glue_section (info, abfd,
11867 globals->bfd_of_glue_owner,
11868 VFP11_ERRATUM_VENEER_SECTION_NAME))
11871 if (! elf32_arm_output_glue_section (info, abfd,
11872 globals->bfd_of_glue_owner,
11873 STM32L4XX_ERRATUM_VENEER_SECTION_NAME))
11876 if (! elf32_arm_output_glue_section (info, abfd,
11877 globals->bfd_of_glue_owner,
11878 ARM_BX_GLUE_SECTION_NAME))
11885 /* Return a best guess for the machine number based on the attributes. */
11887 static unsigned int
11888 bfd_arm_get_mach_from_attributes (bfd * abfd)
11890 int arch = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_CPU_arch);
11894 case TAG_CPU_ARCH_V4: return bfd_mach_arm_4;
11895 case TAG_CPU_ARCH_V4T: return bfd_mach_arm_4T;
11896 case TAG_CPU_ARCH_V5T: return bfd_mach_arm_5T;
11898 case TAG_CPU_ARCH_V5TE:
11902 BFD_ASSERT (Tag_CPU_name < NUM_KNOWN_OBJ_ATTRIBUTES);
11903 name = elf_known_obj_attributes (abfd) [OBJ_ATTR_PROC][Tag_CPU_name].s;
11907 if (strcmp (name, "IWMMXT2") == 0)
11908 return bfd_mach_arm_iWMMXt2;
11910 if (strcmp (name, "IWMMXT") == 0)
11911 return bfd_mach_arm_iWMMXt;
11913 if (strcmp (name, "XSCALE") == 0)
11917 BFD_ASSERT (Tag_WMMX_arch < NUM_KNOWN_OBJ_ATTRIBUTES);
11918 wmmx = elf_known_obj_attributes (abfd) [OBJ_ATTR_PROC][Tag_WMMX_arch].i;
11921 case 1: return bfd_mach_arm_iWMMXt;
11922 case 2: return bfd_mach_arm_iWMMXt2;
11923 default: return bfd_mach_arm_XScale;
11928 return bfd_mach_arm_5TE;
11932 return bfd_mach_arm_unknown;
11936 /* Set the right machine number. */
11939 elf32_arm_object_p (bfd *abfd)
11943 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
11945 if (mach == bfd_mach_arm_unknown)
11947 if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
11948 mach = bfd_mach_arm_ep9312;
11950 mach = bfd_arm_get_mach_from_attributes (abfd);
11953 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
11957 /* Function to keep ARM specific flags in the ELF header. */
11960 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
11962 if (elf_flags_init (abfd)
11963 && elf_elfheader (abfd)->e_flags != flags)
11965 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
11967 if (flags & EF_ARM_INTERWORK)
11968 (*_bfd_error_handler)
11969 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
11973 (_("Warning: Clearing the interworking flag of %B due to outside request"),
11979 elf_elfheader (abfd)->e_flags = flags;
11980 elf_flags_init (abfd) = TRUE;
11986 /* Copy backend specific data from one object module to another. */
11989 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
11992 flagword out_flags;
11994 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
11997 in_flags = elf_elfheader (ibfd)->e_flags;
11998 out_flags = elf_elfheader (obfd)->e_flags;
12000 if (elf_flags_init (obfd)
12001 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
12002 && in_flags != out_flags)
12004 /* Cannot mix APCS26 and APCS32 code. */
12005 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
12008 /* Cannot mix float APCS and non-float APCS code. */
12009 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
12012 /* If the src and dest have different interworking flags
12013 then turn off the interworking bit. */
12014 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
12016 if (out_flags & EF_ARM_INTERWORK)
12018 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
12021 in_flags &= ~EF_ARM_INTERWORK;
12024 /* Likewise for PIC, though don't warn for this case. */
12025 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
12026 in_flags &= ~EF_ARM_PIC;
12029 elf_elfheader (obfd)->e_flags = in_flags;
12030 elf_flags_init (obfd) = TRUE;
12032 return _bfd_elf_copy_private_bfd_data (ibfd, obfd);
12035 /* Values for Tag_ABI_PCS_R9_use. */
12044 /* Values for Tag_ABI_PCS_RW_data. */
12047 AEABI_PCS_RW_data_absolute,
12048 AEABI_PCS_RW_data_PCrel,
12049 AEABI_PCS_RW_data_SBrel,
12050 AEABI_PCS_RW_data_unused
12053 /* Values for Tag_ABI_enum_size. */
12059 AEABI_enum_forced_wide
12062 /* Determine whether an object attribute tag takes an integer, a
12066 elf32_arm_obj_attrs_arg_type (int tag)
12068 if (tag == Tag_compatibility)
12069 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
12070 else if (tag == Tag_nodefaults)
12071 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
12072 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
12073 return ATTR_TYPE_FLAG_STR_VAL;
12075 return ATTR_TYPE_FLAG_INT_VAL;
12077 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
12080 /* The ABI defines that Tag_conformance should be emitted first, and that
12081 Tag_nodefaults should be second (if either is defined). This sets those
12082 two positions, and bumps up the position of all the remaining tags to
12085 elf32_arm_obj_attrs_order (int num)
12087 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
12088 return Tag_conformance;
12089 if (num == LEAST_KNOWN_OBJ_ATTRIBUTE + 1)
12090 return Tag_nodefaults;
12091 if ((num - 2) < Tag_nodefaults)
12093 if ((num - 1) < Tag_conformance)
12098 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
12100 elf32_arm_obj_attrs_handle_unknown (bfd *abfd, int tag)
12102 if ((tag & 127) < 64)
12105 (_("%B: Unknown mandatory EABI object attribute %d"),
12107 bfd_set_error (bfd_error_bad_value);
12113 (_("Warning: %B: Unknown EABI object attribute %d"),
12119 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
12120 Returns -1 if no architecture could be read. */
12123 get_secondary_compatible_arch (bfd *abfd)
12125 obj_attribute *attr =
12126 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
12128 /* Note: the tag and its argument below are uleb128 values, though
12129 currently-defined values fit in one byte for each. */
12131 && attr->s[0] == Tag_CPU_arch
12132 && (attr->s[1] & 128) != 128
12133 && attr->s[2] == 0)
12136 /* This tag is "safely ignorable", so don't complain if it looks funny. */
12140 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
12141 The tag is removed if ARCH is -1. */
12144 set_secondary_compatible_arch (bfd *abfd, int arch)
12146 obj_attribute *attr =
12147 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
12155 /* Note: the tag and its argument below are uleb128 values, though
12156 currently-defined values fit in one byte for each. */
12158 attr->s = (char *) bfd_alloc (abfd, 3);
12159 attr->s[0] = Tag_CPU_arch;
12164 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
12168 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
12169 int newtag, int secondary_compat)
12171 #define T(X) TAG_CPU_ARCH_##X
12172 int tagl, tagh, result;
12175 T(V6T2), /* PRE_V4. */
12177 T(V6T2), /* V4T. */
12178 T(V6T2), /* V5T. */
12179 T(V6T2), /* V5TE. */
12180 T(V6T2), /* V5TEJ. */
12183 T(V6T2) /* V6T2. */
12187 T(V6K), /* PRE_V4. */
12191 T(V6K), /* V5TE. */
12192 T(V6K), /* V5TEJ. */
12194 T(V6KZ), /* V6KZ. */
12200 T(V7), /* PRE_V4. */
12205 T(V7), /* V5TEJ. */
12218 T(V6K), /* V5TE. */
12219 T(V6K), /* V5TEJ. */
12221 T(V6KZ), /* V6KZ. */
12225 T(V6_M) /* V6_M. */
12227 const int v6s_m[] =
12233 T(V6K), /* V5TE. */
12234 T(V6K), /* V5TEJ. */
12236 T(V6KZ), /* V6KZ. */
12240 T(V6S_M), /* V6_M. */
12241 T(V6S_M) /* V6S_M. */
12243 const int v7e_m[] =
12247 T(V7E_M), /* V4T. */
12248 T(V7E_M), /* V5T. */
12249 T(V7E_M), /* V5TE. */
12250 T(V7E_M), /* V5TEJ. */
12251 T(V7E_M), /* V6. */
12252 T(V7E_M), /* V6KZ. */
12253 T(V7E_M), /* V6T2. */
12254 T(V7E_M), /* V6K. */
12255 T(V7E_M), /* V7. */
12256 T(V7E_M), /* V6_M. */
12257 T(V7E_M), /* V6S_M. */
12258 T(V7E_M) /* V7E_M. */
12262 T(V8), /* PRE_V4. */
12267 T(V8), /* V5TEJ. */
12274 T(V8), /* V6S_M. */
12275 T(V8), /* V7E_M. */
12278 const int v4t_plus_v6_m[] =
12284 T(V5TE), /* V5TE. */
12285 T(V5TEJ), /* V5TEJ. */
12287 T(V6KZ), /* V6KZ. */
12288 T(V6T2), /* V6T2. */
12291 T(V6_M), /* V6_M. */
12292 T(V6S_M), /* V6S_M. */
12293 T(V7E_M), /* V7E_M. */
12296 -1, /* V8-M BASELINE. */
12297 -1, /* V8-M MAINLINE. */
12298 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
12300 const int *comb[] =
12312 /* Pseudo-architecture. */
12316 /* Check we've not got a higher architecture than we know about. */
12318 if (oldtag > MAX_TAG_CPU_ARCH || newtag > MAX_TAG_CPU_ARCH)
12320 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd);
12324 /* Override old tag if we have a Tag_also_compatible_with on the output. */
12326 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
12327 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
12328 oldtag = T(V4T_PLUS_V6_M);
12330 /* And override the new tag if we have a Tag_also_compatible_with on the
12333 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
12334 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
12335 newtag = T(V4T_PLUS_V6_M);
12337 tagl = (oldtag < newtag) ? oldtag : newtag;
12338 result = tagh = (oldtag > newtag) ? oldtag : newtag;
12340 /* Architectures before V6KZ add features monotonically. */
12341 if (tagh <= TAG_CPU_ARCH_V6KZ)
12344 result = comb[tagh - T(V6T2)] ? comb[tagh - T(V6T2)][tagl] : -1;
12346 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
12347 as the canonical version. */
12348 if (result == T(V4T_PLUS_V6_M))
12351 *secondary_compat_out = T(V6_M);
12354 *secondary_compat_out = -1;
12358 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
12359 ibfd, oldtag, newtag);
12367 /* Query attributes object to see if integer divide instructions may be
12368 present in an object. */
12370 elf32_arm_attributes_accept_div (const obj_attribute *attr)
12372 int arch = attr[Tag_CPU_arch].i;
12373 int profile = attr[Tag_CPU_arch_profile].i;
12375 switch (attr[Tag_DIV_use].i)
12378 /* Integer divide allowed if instruction contained in archetecture. */
12379 if (arch == TAG_CPU_ARCH_V7 && (profile == 'R' || profile == 'M'))
12381 else if (arch >= TAG_CPU_ARCH_V7E_M)
12387 /* Integer divide explicitly prohibited. */
12391 /* Unrecognised case - treat as allowing divide everywhere. */
12393 /* Integer divide allowed in ARM state. */
12398 /* Query attributes object to see if integer divide instructions are
12399 forbidden to be in the object. This is not the inverse of
12400 elf32_arm_attributes_accept_div. */
12402 elf32_arm_attributes_forbid_div (const obj_attribute *attr)
12404 return attr[Tag_DIV_use].i == 1;
12407 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
12408 are conflicting attributes. */
12411 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
12413 obj_attribute *in_attr;
12414 obj_attribute *out_attr;
12415 /* Some tags have 0 = don't care, 1 = strong requirement,
12416 2 = weak requirement. */
12417 static const int order_021[3] = {0, 2, 1};
12419 bfd_boolean result = TRUE;
12420 const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
12422 /* Skip the linker stubs file. This preserves previous behavior
12423 of accepting unknown attributes in the first input file - but
12425 if (ibfd->flags & BFD_LINKER_CREATED)
12428 /* Skip any input that hasn't attribute section.
12429 This enables to link object files without attribute section with
12431 if (bfd_get_section_by_name (ibfd, sec_name) == NULL)
12434 if (!elf_known_obj_attributes_proc (obfd)[0].i)
12436 /* This is the first object. Copy the attributes. */
12437 _bfd_elf_copy_obj_attributes (ibfd, obfd);
12439 out_attr = elf_known_obj_attributes_proc (obfd);
12441 /* Use the Tag_null value to indicate the attributes have been
12445 /* We do not output objects with Tag_MPextension_use_legacy - we move
12446 the attribute's value to Tag_MPextension_use. */
12447 if (out_attr[Tag_MPextension_use_legacy].i != 0)
12449 if (out_attr[Tag_MPextension_use].i != 0
12450 && out_attr[Tag_MPextension_use_legacy].i
12451 != out_attr[Tag_MPextension_use].i)
12454 (_("Error: %B has both the current and legacy "
12455 "Tag_MPextension_use attributes"), ibfd);
12459 out_attr[Tag_MPextension_use] =
12460 out_attr[Tag_MPextension_use_legacy];
12461 out_attr[Tag_MPextension_use_legacy].type = 0;
12462 out_attr[Tag_MPextension_use_legacy].i = 0;
12468 in_attr = elf_known_obj_attributes_proc (ibfd);
12469 out_attr = elf_known_obj_attributes_proc (obfd);
12470 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
12471 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
12473 /* Ignore mismatches if the object doesn't use floating point or is
12474 floating point ABI independent. */
12475 if (out_attr[Tag_ABI_FP_number_model].i == AEABI_FP_number_model_none
12476 || (in_attr[Tag_ABI_FP_number_model].i != AEABI_FP_number_model_none
12477 && out_attr[Tag_ABI_VFP_args].i == AEABI_VFP_args_compatible))
12478 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
12479 else if (in_attr[Tag_ABI_FP_number_model].i != AEABI_FP_number_model_none
12480 && in_attr[Tag_ABI_VFP_args].i != AEABI_VFP_args_compatible)
12483 (_("error: %B uses VFP register arguments, %B does not"),
12484 in_attr[Tag_ABI_VFP_args].i ? ibfd : obfd,
12485 in_attr[Tag_ABI_VFP_args].i ? obfd : ibfd);
12490 for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
12492 /* Merge this attribute with existing attributes. */
12495 case Tag_CPU_raw_name:
12497 /* These are merged after Tag_CPU_arch. */
12500 case Tag_ABI_optimization_goals:
12501 case Tag_ABI_FP_optimization_goals:
12502 /* Use the first value seen. */
12507 int secondary_compat = -1, secondary_compat_out = -1;
12508 unsigned int saved_out_attr = out_attr[i].i;
12510 static const char *name_table[] =
12512 /* These aren't real CPU names, but we can't guess
12513 that from the architecture version alone. */
12530 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
12531 secondary_compat = get_secondary_compatible_arch (ibfd);
12532 secondary_compat_out = get_secondary_compatible_arch (obfd);
12533 arch_attr = tag_cpu_arch_combine (ibfd, out_attr[i].i,
12534 &secondary_compat_out,
12538 /* Return with error if failed to merge. */
12539 if (arch_attr == -1)
12542 out_attr[i].i = arch_attr;
12544 set_secondary_compatible_arch (obfd, secondary_compat_out);
12546 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
12547 if (out_attr[i].i == saved_out_attr)
12548 ; /* Leave the names alone. */
12549 else if (out_attr[i].i == in_attr[i].i)
12551 /* The output architecture has been changed to match the
12552 input architecture. Use the input names. */
12553 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
12554 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
12556 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
12557 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
12562 out_attr[Tag_CPU_name].s = NULL;
12563 out_attr[Tag_CPU_raw_name].s = NULL;
12566 /* If we still don't have a value for Tag_CPU_name,
12567 make one up now. Tag_CPU_raw_name remains blank. */
12568 if (out_attr[Tag_CPU_name].s == NULL
12569 && out_attr[i].i < ARRAY_SIZE (name_table))
12570 out_attr[Tag_CPU_name].s =
12571 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
12575 case Tag_ARM_ISA_use:
12576 case Tag_THUMB_ISA_use:
12577 case Tag_WMMX_arch:
12578 case Tag_Advanced_SIMD_arch:
12579 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
12580 case Tag_ABI_FP_rounding:
12581 case Tag_ABI_FP_exceptions:
12582 case Tag_ABI_FP_user_exceptions:
12583 case Tag_ABI_FP_number_model:
12584 case Tag_FP_HP_extension:
12585 case Tag_CPU_unaligned_access:
12587 case Tag_MPextension_use:
12588 /* Use the largest value specified. */
12589 if (in_attr[i].i > out_attr[i].i)
12590 out_attr[i].i = in_attr[i].i;
12593 case Tag_ABI_align_preserved:
12594 case Tag_ABI_PCS_RO_data:
12595 /* Use the smallest value specified. */
12596 if (in_attr[i].i < out_attr[i].i)
12597 out_attr[i].i = in_attr[i].i;
12600 case Tag_ABI_align_needed:
12601 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
12602 && (in_attr[Tag_ABI_align_preserved].i == 0
12603 || out_attr[Tag_ABI_align_preserved].i == 0))
12605 /* This error message should be enabled once all non-conformant
12606 binaries in the toolchain have had the attributes set
12609 (_("error: %B: 8-byte data alignment conflicts with %B"),
12613 /* Fall through. */
12614 case Tag_ABI_FP_denormal:
12615 case Tag_ABI_PCS_GOT_use:
12616 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
12617 value if greater than 2 (for future-proofing). */
12618 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
12619 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
12620 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
12621 out_attr[i].i = in_attr[i].i;
12624 case Tag_Virtualization_use:
12625 /* The virtualization tag effectively stores two bits of
12626 information: the intended use of TrustZone (in bit 0), and the
12627 intended use of Virtualization (in bit 1). */
12628 if (out_attr[i].i == 0)
12629 out_attr[i].i = in_attr[i].i;
12630 else if (in_attr[i].i != 0
12631 && in_attr[i].i != out_attr[i].i)
12633 if (in_attr[i].i <= 3 && out_attr[i].i <= 3)
12638 (_("error: %B: unable to merge virtualization attributes "
12646 case Tag_CPU_arch_profile:
12647 if (out_attr[i].i != in_attr[i].i)
12649 /* 0 will merge with anything.
12650 'A' and 'S' merge to 'A'.
12651 'R' and 'S' merge to 'R'.
12652 'M' and 'A|R|S' is an error. */
12653 if (out_attr[i].i == 0
12654 || (out_attr[i].i == 'S'
12655 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
12656 out_attr[i].i = in_attr[i].i;
12657 else if (in_attr[i].i == 0
12658 || (in_attr[i].i == 'S'
12659 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
12660 ; /* Do nothing. */
12664 (_("error: %B: Conflicting architecture profiles %c/%c"),
12666 in_attr[i].i ? in_attr[i].i : '0',
12667 out_attr[i].i ? out_attr[i].i : '0');
12674 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
12675 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
12676 when it's 0. It might mean absence of FP hardware if
12677 Tag_FP_arch is zero. */
12679 #define VFP_VERSION_COUNT 9
12680 static const struct
12684 } vfp_versions[VFP_VERSION_COUNT] =
12700 /* If the output has no requirement about FP hardware,
12701 follow the requirement of the input. */
12702 if (out_attr[i].i == 0)
12704 BFD_ASSERT (out_attr[Tag_ABI_HardFP_use].i == 0);
12705 out_attr[i].i = in_attr[i].i;
12706 out_attr[Tag_ABI_HardFP_use].i
12707 = in_attr[Tag_ABI_HardFP_use].i;
12710 /* If the input has no requirement about FP hardware, do
12712 else if (in_attr[i].i == 0)
12714 BFD_ASSERT (in_attr[Tag_ABI_HardFP_use].i == 0);
12718 /* Both the input and the output have nonzero Tag_FP_arch.
12719 So Tag_ABI_HardFP_use is implied by Tag_FP_arch when it's zero. */
12721 /* If both the input and the output have zero Tag_ABI_HardFP_use,
12723 if (in_attr[Tag_ABI_HardFP_use].i == 0
12724 && out_attr[Tag_ABI_HardFP_use].i == 0)
12726 /* If the input and the output have different Tag_ABI_HardFP_use,
12727 the combination of them is 0 (implied by Tag_FP_arch). */
12728 else if (in_attr[Tag_ABI_HardFP_use].i
12729 != out_attr[Tag_ABI_HardFP_use].i)
12730 out_attr[Tag_ABI_HardFP_use].i = 0;
12732 /* Now we can handle Tag_FP_arch. */
12734 /* Values of VFP_VERSION_COUNT or more aren't defined, so just
12735 pick the biggest. */
12736 if (in_attr[i].i >= VFP_VERSION_COUNT
12737 && in_attr[i].i > out_attr[i].i)
12739 out_attr[i] = in_attr[i];
12742 /* The output uses the superset of input features
12743 (ISA version) and registers. */
12744 ver = vfp_versions[in_attr[i].i].ver;
12745 if (ver < vfp_versions[out_attr[i].i].ver)
12746 ver = vfp_versions[out_attr[i].i].ver;
12747 regs = vfp_versions[in_attr[i].i].regs;
12748 if (regs < vfp_versions[out_attr[i].i].regs)
12749 regs = vfp_versions[out_attr[i].i].regs;
12750 /* This assumes all possible supersets are also a valid
12752 for (newval = VFP_VERSION_COUNT - 1; newval > 0; newval--)
12754 if (regs == vfp_versions[newval].regs
12755 && ver == vfp_versions[newval].ver)
12758 out_attr[i].i = newval;
12761 case Tag_PCS_config:
12762 if (out_attr[i].i == 0)
12763 out_attr[i].i = in_attr[i].i;
12764 else if (in_attr[i].i != 0 && out_attr[i].i != in_attr[i].i)
12766 /* It's sometimes ok to mix different configs, so this is only
12769 (_("Warning: %B: Conflicting platform configuration"), ibfd);
12772 case Tag_ABI_PCS_R9_use:
12773 if (in_attr[i].i != out_attr[i].i
12774 && out_attr[i].i != AEABI_R9_unused
12775 && in_attr[i].i != AEABI_R9_unused)
12778 (_("error: %B: Conflicting use of R9"), ibfd);
12781 if (out_attr[i].i == AEABI_R9_unused)
12782 out_attr[i].i = in_attr[i].i;
12784 case Tag_ABI_PCS_RW_data:
12785 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
12786 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
12787 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
12790 (_("error: %B: SB relative addressing conflicts with use of R9"),
12794 /* Use the smallest value specified. */
12795 if (in_attr[i].i < out_attr[i].i)
12796 out_attr[i].i = in_attr[i].i;
12798 case Tag_ABI_PCS_wchar_t:
12799 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
12800 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
12803 (_("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"),
12804 ibfd, in_attr[i].i, out_attr[i].i);
12806 else if (in_attr[i].i && !out_attr[i].i)
12807 out_attr[i].i = in_attr[i].i;
12809 case Tag_ABI_enum_size:
12810 if (in_attr[i].i != AEABI_enum_unused)
12812 if (out_attr[i].i == AEABI_enum_unused
12813 || out_attr[i].i == AEABI_enum_forced_wide)
12815 /* The existing object is compatible with anything.
12816 Use whatever requirements the new object has. */
12817 out_attr[i].i = in_attr[i].i;
12819 else if (in_attr[i].i != AEABI_enum_forced_wide
12820 && out_attr[i].i != in_attr[i].i
12821 && !elf_arm_tdata (obfd)->no_enum_size_warning)
12823 static const char *aeabi_enum_names[] =
12824 { "", "variable-size", "32-bit", "" };
12825 const char *in_name =
12826 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
12827 ? aeabi_enum_names[in_attr[i].i]
12829 const char *out_name =
12830 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
12831 ? aeabi_enum_names[out_attr[i].i]
12834 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
12835 ibfd, in_name, out_name);
12839 case Tag_ABI_VFP_args:
12842 case Tag_ABI_WMMX_args:
12843 if (in_attr[i].i != out_attr[i].i)
12846 (_("error: %B uses iWMMXt register arguments, %B does not"),
12851 case Tag_compatibility:
12852 /* Merged in target-independent code. */
12854 case Tag_ABI_HardFP_use:
12855 /* This is handled along with Tag_FP_arch. */
12857 case Tag_ABI_FP_16bit_format:
12858 if (in_attr[i].i != 0 && out_attr[i].i != 0)
12860 if (in_attr[i].i != out_attr[i].i)
12863 (_("error: fp16 format mismatch between %B and %B"),
12868 if (in_attr[i].i != 0)
12869 out_attr[i].i = in_attr[i].i;
12873 /* A value of zero on input means that the divide instruction may
12874 be used if available in the base architecture as specified via
12875 Tag_CPU_arch and Tag_CPU_arch_profile. A value of 1 means that
12876 the user did not want divide instructions. A value of 2
12877 explicitly means that divide instructions were allowed in ARM
12878 and Thumb state. */
12879 if (in_attr[i].i == out_attr[i].i)
12880 /* Do nothing. */ ;
12881 else if (elf32_arm_attributes_forbid_div (in_attr)
12882 && !elf32_arm_attributes_accept_div (out_attr))
12884 else if (elf32_arm_attributes_forbid_div (out_attr)
12885 && elf32_arm_attributes_accept_div (in_attr))
12886 out_attr[i].i = in_attr[i].i;
12887 else if (in_attr[i].i == 2)
12888 out_attr[i].i = in_attr[i].i;
12891 case Tag_MPextension_use_legacy:
12892 /* We don't output objects with Tag_MPextension_use_legacy - we
12893 move the value to Tag_MPextension_use. */
12894 if (in_attr[i].i != 0 && in_attr[Tag_MPextension_use].i != 0)
12896 if (in_attr[Tag_MPextension_use].i != in_attr[i].i)
12899 (_("%B has has both the current and legacy "
12900 "Tag_MPextension_use attributes"),
12906 if (in_attr[i].i > out_attr[Tag_MPextension_use].i)
12907 out_attr[Tag_MPextension_use] = in_attr[i];
12911 case Tag_nodefaults:
12912 /* This tag is set if it exists, but the value is unused (and is
12913 typically zero). We don't actually need to do anything here -
12914 the merge happens automatically when the type flags are merged
12917 case Tag_also_compatible_with:
12918 /* Already done in Tag_CPU_arch. */
12920 case Tag_conformance:
12921 /* Keep the attribute if it matches. Throw it away otherwise.
12922 No attribute means no claim to conform. */
12923 if (!in_attr[i].s || !out_attr[i].s
12924 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
12925 out_attr[i].s = NULL;
12930 = result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
12933 /* If out_attr was copied from in_attr then it won't have a type yet. */
12934 if (in_attr[i].type && !out_attr[i].type)
12935 out_attr[i].type = in_attr[i].type;
12938 /* Merge Tag_compatibility attributes and any common GNU ones. */
12939 if (!_bfd_elf_merge_object_attributes (ibfd, obfd))
12942 /* Check for any attributes not known on ARM. */
12943 result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
12949 /* Return TRUE if the two EABI versions are incompatible. */
12952 elf32_arm_versions_compatible (unsigned iver, unsigned over)
12954 /* v4 and v5 are the same spec before and after it was released,
12955 so allow mixing them. */
12956 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
12957 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
12960 return (iver == over);
12963 /* Merge backend specific data from an object file to the output
12964 object file when linking. */
12967 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd);
12969 /* Display the flags field. */
12972 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
12974 FILE * file = (FILE *) ptr;
12975 unsigned long flags;
12977 BFD_ASSERT (abfd != NULL && ptr != NULL);
12979 /* Print normal ELF private data. */
12980 _bfd_elf_print_private_bfd_data (abfd, ptr);
12982 flags = elf_elfheader (abfd)->e_flags;
12983 /* Ignore init flag - it may not be set, despite the flags field
12984 containing valid data. */
12986 /* xgettext:c-format */
12987 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
12989 switch (EF_ARM_EABI_VERSION (flags))
12991 case EF_ARM_EABI_UNKNOWN:
12992 /* The following flag bits are GNU extensions and not part of the
12993 official ARM ELF extended ABI. Hence they are only decoded if
12994 the EABI version is not set. */
12995 if (flags & EF_ARM_INTERWORK)
12996 fprintf (file, _(" [interworking enabled]"));
12998 if (flags & EF_ARM_APCS_26)
12999 fprintf (file, " [APCS-26]");
13001 fprintf (file, " [APCS-32]");
13003 if (flags & EF_ARM_VFP_FLOAT)
13004 fprintf (file, _(" [VFP float format]"));
13005 else if (flags & EF_ARM_MAVERICK_FLOAT)
13006 fprintf (file, _(" [Maverick float format]"));
13008 fprintf (file, _(" [FPA float format]"));
13010 if (flags & EF_ARM_APCS_FLOAT)
13011 fprintf (file, _(" [floats passed in float registers]"));
13013 if (flags & EF_ARM_PIC)
13014 fprintf (file, _(" [position independent]"));
13016 if (flags & EF_ARM_NEW_ABI)
13017 fprintf (file, _(" [new ABI]"));
13019 if (flags & EF_ARM_OLD_ABI)
13020 fprintf (file, _(" [old ABI]"));
13022 if (flags & EF_ARM_SOFT_FLOAT)
13023 fprintf (file, _(" [software FP]"));
13025 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
13026 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
13027 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
13028 | EF_ARM_MAVERICK_FLOAT);
13031 case EF_ARM_EABI_VER1:
13032 fprintf (file, _(" [Version1 EABI]"));
13034 if (flags & EF_ARM_SYMSARESORTED)
13035 fprintf (file, _(" [sorted symbol table]"));
13037 fprintf (file, _(" [unsorted symbol table]"));
13039 flags &= ~ EF_ARM_SYMSARESORTED;
13042 case EF_ARM_EABI_VER2:
13043 fprintf (file, _(" [Version2 EABI]"));
13045 if (flags & EF_ARM_SYMSARESORTED)
13046 fprintf (file, _(" [sorted symbol table]"));
13048 fprintf (file, _(" [unsorted symbol table]"));
13050 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
13051 fprintf (file, _(" [dynamic symbols use segment index]"));
13053 if (flags & EF_ARM_MAPSYMSFIRST)
13054 fprintf (file, _(" [mapping symbols precede others]"));
13056 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
13057 | EF_ARM_MAPSYMSFIRST);
13060 case EF_ARM_EABI_VER3:
13061 fprintf (file, _(" [Version3 EABI]"));
13064 case EF_ARM_EABI_VER4:
13065 fprintf (file, _(" [Version4 EABI]"));
13068 case EF_ARM_EABI_VER5:
13069 fprintf (file, _(" [Version5 EABI]"));
13071 if (flags & EF_ARM_ABI_FLOAT_SOFT)
13072 fprintf (file, _(" [soft-float ABI]"));
13074 if (flags & EF_ARM_ABI_FLOAT_HARD)
13075 fprintf (file, _(" [hard-float ABI]"));
13077 flags &= ~(EF_ARM_ABI_FLOAT_SOFT | EF_ARM_ABI_FLOAT_HARD);
13080 if (flags & EF_ARM_BE8)
13081 fprintf (file, _(" [BE8]"));
13083 if (flags & EF_ARM_LE8)
13084 fprintf (file, _(" [LE8]"));
13086 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
13090 fprintf (file, _(" <EABI version unrecognised>"));
13094 flags &= ~ EF_ARM_EABIMASK;
13096 if (flags & EF_ARM_RELEXEC)
13097 fprintf (file, _(" [relocatable executable]"));
13099 flags &= ~EF_ARM_RELEXEC;
13102 fprintf (file, _("<Unrecognised flag bits set>"));
13104 fputc ('\n', file);
13110 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
13112 switch (ELF_ST_TYPE (elf_sym->st_info))
13114 case STT_ARM_TFUNC:
13115 return ELF_ST_TYPE (elf_sym->st_info);
13117 case STT_ARM_16BIT:
13118 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
13119 This allows us to distinguish between data used by Thumb instructions
13120 and non-data (which is probably code) inside Thumb regions of an
13122 if (type != STT_OBJECT && type != STT_TLS)
13123 return ELF_ST_TYPE (elf_sym->st_info);
13134 elf32_arm_gc_mark_hook (asection *sec,
13135 struct bfd_link_info *info,
13136 Elf_Internal_Rela *rel,
13137 struct elf_link_hash_entry *h,
13138 Elf_Internal_Sym *sym)
13141 switch (ELF32_R_TYPE (rel->r_info))
13143 case R_ARM_GNU_VTINHERIT:
13144 case R_ARM_GNU_VTENTRY:
13148 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
13151 /* Update the got entry reference counts for the section being removed. */
13154 elf32_arm_gc_sweep_hook (bfd * abfd,
13155 struct bfd_link_info * info,
13157 const Elf_Internal_Rela * relocs)
13159 Elf_Internal_Shdr *symtab_hdr;
13160 struct elf_link_hash_entry **sym_hashes;
13161 bfd_signed_vma *local_got_refcounts;
13162 const Elf_Internal_Rela *rel, *relend;
13163 struct elf32_arm_link_hash_table * globals;
13165 if (bfd_link_relocatable (info))
13168 globals = elf32_arm_hash_table (info);
13169 if (globals == NULL)
13172 elf_section_data (sec)->local_dynrel = NULL;
13174 symtab_hdr = & elf_symtab_hdr (abfd);
13175 sym_hashes = elf_sym_hashes (abfd);
13176 local_got_refcounts = elf_local_got_refcounts (abfd);
13178 check_use_blx (globals);
13180 relend = relocs + sec->reloc_count;
13181 for (rel = relocs; rel < relend; rel++)
13183 unsigned long r_symndx;
13184 struct elf_link_hash_entry *h = NULL;
13185 struct elf32_arm_link_hash_entry *eh;
13187 bfd_boolean call_reloc_p;
13188 bfd_boolean may_become_dynamic_p;
13189 bfd_boolean may_need_local_target_p;
13190 union gotplt_union *root_plt;
13191 struct arm_plt_info *arm_plt;
13193 r_symndx = ELF32_R_SYM (rel->r_info);
13194 if (r_symndx >= symtab_hdr->sh_info)
13196 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
13197 while (h->root.type == bfd_link_hash_indirect
13198 || h->root.type == bfd_link_hash_warning)
13199 h = (struct elf_link_hash_entry *) h->root.u.i.link;
13201 eh = (struct elf32_arm_link_hash_entry *) h;
13203 call_reloc_p = FALSE;
13204 may_become_dynamic_p = FALSE;
13205 may_need_local_target_p = FALSE;
13207 r_type = ELF32_R_TYPE (rel->r_info);
13208 r_type = arm_real_reloc_type (globals, r_type);
13212 case R_ARM_GOT_PREL:
13213 case R_ARM_TLS_GD32:
13214 case R_ARM_TLS_IE32:
13217 if (h->got.refcount > 0)
13218 h->got.refcount -= 1;
13220 else if (local_got_refcounts != NULL)
13222 if (local_got_refcounts[r_symndx] > 0)
13223 local_got_refcounts[r_symndx] -= 1;
13227 case R_ARM_TLS_LDM32:
13228 globals->tls_ldm_got.refcount -= 1;
13236 case R_ARM_THM_CALL:
13237 case R_ARM_THM_JUMP24:
13238 case R_ARM_THM_JUMP19:
13239 call_reloc_p = TRUE;
13240 may_need_local_target_p = TRUE;
13244 if (!globals->vxworks_p)
13246 may_need_local_target_p = TRUE;
13249 /* Fall through. */
13251 case R_ARM_ABS32_NOI:
13253 case R_ARM_REL32_NOI:
13254 case R_ARM_MOVW_ABS_NC:
13255 case R_ARM_MOVT_ABS:
13256 case R_ARM_MOVW_PREL_NC:
13257 case R_ARM_MOVT_PREL:
13258 case R_ARM_THM_MOVW_ABS_NC:
13259 case R_ARM_THM_MOVT_ABS:
13260 case R_ARM_THM_MOVW_PREL_NC:
13261 case R_ARM_THM_MOVT_PREL:
13262 /* Should the interworking branches be here also? */
13263 if ((bfd_link_pic (info) || globals->root.is_relocatable_executable)
13264 && (sec->flags & SEC_ALLOC) != 0)
13267 && elf32_arm_howto_from_type (r_type)->pc_relative)
13269 call_reloc_p = TRUE;
13270 may_need_local_target_p = TRUE;
13273 may_become_dynamic_p = TRUE;
13276 may_need_local_target_p = TRUE;
13283 if (may_need_local_target_p
13284 && elf32_arm_get_plt_info (abfd, eh, r_symndx, &root_plt, &arm_plt))
13286 /* If PLT refcount book-keeping is wrong and too low, we'll
13287 see a zero value (going to -1) for the root PLT reference
13289 if (root_plt->refcount >= 0)
13291 BFD_ASSERT (root_plt->refcount != 0);
13292 root_plt->refcount -= 1;
13295 /* A value of -1 means the symbol has become local, forced
13296 or seeing a hidden definition. Any other negative value
13298 BFD_ASSERT (root_plt->refcount == -1);
13301 arm_plt->noncall_refcount--;
13303 if (r_type == R_ARM_THM_CALL)
13304 arm_plt->maybe_thumb_refcount--;
13306 if (r_type == R_ARM_THM_JUMP24
13307 || r_type == R_ARM_THM_JUMP19)
13308 arm_plt->thumb_refcount--;
13311 if (may_become_dynamic_p)
13313 struct elf_dyn_relocs **pp;
13314 struct elf_dyn_relocs *p;
13317 pp = &(eh->dyn_relocs);
13320 Elf_Internal_Sym *isym;
13322 isym = bfd_sym_from_r_symndx (&globals->sym_cache,
13326 pp = elf32_arm_get_local_dynreloc_list (abfd, r_symndx, isym);
13330 for (; (p = *pp) != NULL; pp = &p->next)
13333 /* Everything must go for SEC. */
13343 /* Look through the relocs for a section during the first phase. */
13346 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
13347 asection *sec, const Elf_Internal_Rela *relocs)
13349 Elf_Internal_Shdr *symtab_hdr;
13350 struct elf_link_hash_entry **sym_hashes;
13351 const Elf_Internal_Rela *rel;
13352 const Elf_Internal_Rela *rel_end;
13355 struct elf32_arm_link_hash_table *htab;
13356 bfd_boolean call_reloc_p;
13357 bfd_boolean may_become_dynamic_p;
13358 bfd_boolean may_need_local_target_p;
13359 unsigned long nsyms;
13361 if (bfd_link_relocatable (info))
13364 BFD_ASSERT (is_arm_elf (abfd));
13366 htab = elf32_arm_hash_table (info);
13372 /* Create dynamic sections for relocatable executables so that we can
13373 copy relocations. */
13374 if (htab->root.is_relocatable_executable
13375 && ! htab->root.dynamic_sections_created)
13377 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
13381 if (htab->root.dynobj == NULL)
13382 htab->root.dynobj = abfd;
13383 if (!create_ifunc_sections (info))
13386 dynobj = htab->root.dynobj;
13388 symtab_hdr = & elf_symtab_hdr (abfd);
13389 sym_hashes = elf_sym_hashes (abfd);
13390 nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
13392 rel_end = relocs + sec->reloc_count;
13393 for (rel = relocs; rel < rel_end; rel++)
13395 Elf_Internal_Sym *isym;
13396 struct elf_link_hash_entry *h;
13397 struct elf32_arm_link_hash_entry *eh;
13398 unsigned long r_symndx;
13401 r_symndx = ELF32_R_SYM (rel->r_info);
13402 r_type = ELF32_R_TYPE (rel->r_info);
13403 r_type = arm_real_reloc_type (htab, r_type);
13405 if (r_symndx >= nsyms
13406 /* PR 9934: It is possible to have relocations that do not
13407 refer to symbols, thus it is also possible to have an
13408 object file containing relocations but no symbol table. */
13409 && (r_symndx > STN_UNDEF || nsyms > 0))
13411 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
13420 if (r_symndx < symtab_hdr->sh_info)
13422 /* A local symbol. */
13423 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
13430 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
13431 while (h->root.type == bfd_link_hash_indirect
13432 || h->root.type == bfd_link_hash_warning)
13433 h = (struct elf_link_hash_entry *) h->root.u.i.link;
13435 /* PR15323, ref flags aren't set for references in the
13437 h->root.non_ir_ref = 1;
13441 eh = (struct elf32_arm_link_hash_entry *) h;
13443 call_reloc_p = FALSE;
13444 may_become_dynamic_p = FALSE;
13445 may_need_local_target_p = FALSE;
13447 /* Could be done earlier, if h were already available. */
13448 r_type = elf32_arm_tls_transition (info, r_type, h);
13452 case R_ARM_GOT_PREL:
13453 case R_ARM_TLS_GD32:
13454 case R_ARM_TLS_IE32:
13455 case R_ARM_TLS_GOTDESC:
13456 case R_ARM_TLS_DESCSEQ:
13457 case R_ARM_THM_TLS_DESCSEQ:
13458 case R_ARM_TLS_CALL:
13459 case R_ARM_THM_TLS_CALL:
13460 /* This symbol requires a global offset table entry. */
13462 int tls_type, old_tls_type;
13466 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
13468 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
13470 case R_ARM_TLS_GOTDESC:
13471 case R_ARM_TLS_CALL: case R_ARM_THM_TLS_CALL:
13472 case R_ARM_TLS_DESCSEQ: case R_ARM_THM_TLS_DESCSEQ:
13473 tls_type = GOT_TLS_GDESC; break;
13475 default: tls_type = GOT_NORMAL; break;
13478 if (!bfd_link_executable (info) && (tls_type & GOT_TLS_IE))
13479 info->flags |= DF_STATIC_TLS;
13484 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
13488 /* This is a global offset table entry for a local symbol. */
13489 if (!elf32_arm_allocate_local_sym_info (abfd))
13491 elf_local_got_refcounts (abfd)[r_symndx] += 1;
13492 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
13495 /* If a variable is accessed with both tls methods, two
13496 slots may be created. */
13497 if (GOT_TLS_GD_ANY_P (old_tls_type)
13498 && GOT_TLS_GD_ANY_P (tls_type))
13499 tls_type |= old_tls_type;
13501 /* We will already have issued an error message if there
13502 is a TLS/non-TLS mismatch, based on the symbol
13503 type. So just combine any TLS types needed. */
13504 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
13505 && tls_type != GOT_NORMAL)
13506 tls_type |= old_tls_type;
13508 /* If the symbol is accessed in both IE and GDESC
13509 method, we're able to relax. Turn off the GDESC flag,
13510 without messing up with any other kind of tls types
13511 that may be involved. */
13512 if ((tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_GDESC))
13513 tls_type &= ~GOT_TLS_GDESC;
13515 if (old_tls_type != tls_type)
13518 elf32_arm_hash_entry (h)->tls_type = tls_type;
13520 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
13523 /* Fall through. */
13525 case R_ARM_TLS_LDM32:
13526 if (r_type == R_ARM_TLS_LDM32)
13527 htab->tls_ldm_got.refcount++;
13528 /* Fall through. */
13530 case R_ARM_GOTOFF32:
13532 if (htab->root.sgot == NULL
13533 && !create_got_section (htab->root.dynobj, info))
13542 case R_ARM_THM_CALL:
13543 case R_ARM_THM_JUMP24:
13544 case R_ARM_THM_JUMP19:
13545 call_reloc_p = TRUE;
13546 may_need_local_target_p = TRUE;
13550 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
13551 ldr __GOTT_INDEX__ offsets. */
13552 if (!htab->vxworks_p)
13554 may_need_local_target_p = TRUE;
13557 /* Fall through. */
13559 case R_ARM_MOVW_ABS_NC:
13560 case R_ARM_MOVT_ABS:
13561 case R_ARM_THM_MOVW_ABS_NC:
13562 case R_ARM_THM_MOVT_ABS:
13563 if (bfd_link_pic (info))
13565 (*_bfd_error_handler)
13566 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
13567 abfd, elf32_arm_howto_table_1[r_type].name,
13568 (h) ? h->root.root.string : "a local symbol");
13569 bfd_set_error (bfd_error_bad_value);
13573 /* Fall through. */
13575 case R_ARM_ABS32_NOI:
13576 if (h != NULL && bfd_link_executable (info))
13578 h->pointer_equality_needed = 1;
13580 /* Fall through. */
13582 case R_ARM_REL32_NOI:
13583 case R_ARM_MOVW_PREL_NC:
13584 case R_ARM_MOVT_PREL:
13585 case R_ARM_THM_MOVW_PREL_NC:
13586 case R_ARM_THM_MOVT_PREL:
13588 /* Should the interworking branches be listed here? */
13589 if ((bfd_link_pic (info) || htab->root.is_relocatable_executable)
13590 && (sec->flags & SEC_ALLOC) != 0)
13593 && elf32_arm_howto_from_type (r_type)->pc_relative)
13595 /* In shared libraries and relocatable executables,
13596 we treat local relative references as calls;
13597 see the related SYMBOL_CALLS_LOCAL code in
13598 allocate_dynrelocs. */
13599 call_reloc_p = TRUE;
13600 may_need_local_target_p = TRUE;
13603 /* We are creating a shared library or relocatable
13604 executable, and this is a reloc against a global symbol,
13605 or a non-PC-relative reloc against a local symbol.
13606 We may need to copy the reloc into the output. */
13607 may_become_dynamic_p = TRUE;
13610 may_need_local_target_p = TRUE;
13613 /* This relocation describes the C++ object vtable hierarchy.
13614 Reconstruct it for later use during GC. */
13615 case R_ARM_GNU_VTINHERIT:
13616 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
13620 /* This relocation describes which C++ vtable entries are actually
13621 used. Record for later use during GC. */
13622 case R_ARM_GNU_VTENTRY:
13623 BFD_ASSERT (h != NULL);
13625 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
13633 /* We may need a .plt entry if the function this reloc
13634 refers to is in a different object, regardless of the
13635 symbol's type. We can't tell for sure yet, because
13636 something later might force the symbol local. */
13638 else if (may_need_local_target_p)
13639 /* If this reloc is in a read-only section, we might
13640 need a copy reloc. We can't check reliably at this
13641 stage whether the section is read-only, as input
13642 sections have not yet been mapped to output sections.
13643 Tentatively set the flag for now, and correct in
13644 adjust_dynamic_symbol. */
13645 h->non_got_ref = 1;
13648 if (may_need_local_target_p
13649 && (h != NULL || ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC))
13651 union gotplt_union *root_plt;
13652 struct arm_plt_info *arm_plt;
13653 struct arm_local_iplt_info *local_iplt;
13657 root_plt = &h->plt;
13658 arm_plt = &eh->plt;
13662 local_iplt = elf32_arm_create_local_iplt (abfd, r_symndx);
13663 if (local_iplt == NULL)
13665 root_plt = &local_iplt->root;
13666 arm_plt = &local_iplt->arm;
13669 /* If the symbol is a function that doesn't bind locally,
13670 this relocation will need a PLT entry. */
13671 if (root_plt->refcount != -1)
13672 root_plt->refcount += 1;
13675 arm_plt->noncall_refcount++;
13677 /* It's too early to use htab->use_blx here, so we have to
13678 record possible blx references separately from
13679 relocs that definitely need a thumb stub. */
13681 if (r_type == R_ARM_THM_CALL)
13682 arm_plt->maybe_thumb_refcount += 1;
13684 if (r_type == R_ARM_THM_JUMP24
13685 || r_type == R_ARM_THM_JUMP19)
13686 arm_plt->thumb_refcount += 1;
13689 if (may_become_dynamic_p)
13691 struct elf_dyn_relocs *p, **head;
13693 /* Create a reloc section in dynobj. */
13694 if (sreloc == NULL)
13696 sreloc = _bfd_elf_make_dynamic_reloc_section
13697 (sec, dynobj, 2, abfd, ! htab->use_rel);
13699 if (sreloc == NULL)
13702 /* BPABI objects never have dynamic relocations mapped. */
13703 if (htab->symbian_p)
13707 flags = bfd_get_section_flags (dynobj, sreloc);
13708 flags &= ~(SEC_LOAD | SEC_ALLOC);
13709 bfd_set_section_flags (dynobj, sreloc, flags);
13713 /* If this is a global symbol, count the number of
13714 relocations we need for this symbol. */
13716 head = &((struct elf32_arm_link_hash_entry *) h)->dyn_relocs;
13719 head = elf32_arm_get_local_dynreloc_list (abfd, r_symndx, isym);
13725 if (p == NULL || p->sec != sec)
13727 bfd_size_type amt = sizeof *p;
13729 p = (struct elf_dyn_relocs *) bfd_alloc (htab->root.dynobj, amt);
13739 if (elf32_arm_howto_from_type (r_type)->pc_relative)
13748 /* Unwinding tables are not referenced directly. This pass marks them as
13749 required if the corresponding code section is marked. */
13752 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
13753 elf_gc_mark_hook_fn gc_mark_hook)
13756 Elf_Internal_Shdr **elf_shdrp;
13759 _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
13761 /* Marking EH data may cause additional code sections to be marked,
13762 requiring multiple passes. */
13767 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
13771 if (! is_arm_elf (sub))
13774 elf_shdrp = elf_elfsections (sub);
13775 for (o = sub->sections; o != NULL; o = o->next)
13777 Elf_Internal_Shdr *hdr;
13779 hdr = &elf_section_data (o)->this_hdr;
13780 if (hdr->sh_type == SHT_ARM_EXIDX
13782 && hdr->sh_link < elf_numsections (sub)
13784 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
13787 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
13797 /* Treat mapping symbols as special target symbols. */
13800 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
13802 return bfd_is_arm_special_symbol_name (sym->name,
13803 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
13806 /* This is a copy of elf_find_function() from elf.c except that
13807 ARM mapping symbols are ignored when looking for function names
13808 and STT_ARM_TFUNC is considered to a function type. */
13811 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
13812 asymbol ** symbols,
13813 asection * section,
13815 const char ** filename_ptr,
13816 const char ** functionname_ptr)
13818 const char * filename = NULL;
13819 asymbol * func = NULL;
13820 bfd_vma low_func = 0;
13823 for (p = symbols; *p != NULL; p++)
13825 elf_symbol_type *q;
13827 q = (elf_symbol_type *) *p;
13829 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
13834 filename = bfd_asymbol_name (&q->symbol);
13837 case STT_ARM_TFUNC:
13839 /* Skip mapping symbols. */
13840 if ((q->symbol.flags & BSF_LOCAL)
13841 && bfd_is_arm_special_symbol_name (q->symbol.name,
13842 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
13844 /* Fall through. */
13845 if (bfd_get_section (&q->symbol) == section
13846 && q->symbol.value >= low_func
13847 && q->symbol.value <= offset)
13849 func = (asymbol *) q;
13850 low_func = q->symbol.value;
13860 *filename_ptr = filename;
13861 if (functionname_ptr)
13862 *functionname_ptr = bfd_asymbol_name (func);
13868 /* Find the nearest line to a particular section and offset, for error
13869 reporting. This code is a duplicate of the code in elf.c, except
13870 that it uses arm_elf_find_function. */
13873 elf32_arm_find_nearest_line (bfd * abfd,
13874 asymbol ** symbols,
13875 asection * section,
13877 const char ** filename_ptr,
13878 const char ** functionname_ptr,
13879 unsigned int * line_ptr,
13880 unsigned int * discriminator_ptr)
13882 bfd_boolean found = FALSE;
13884 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
13885 filename_ptr, functionname_ptr,
13886 line_ptr, discriminator_ptr,
13887 dwarf_debug_sections, 0,
13888 & elf_tdata (abfd)->dwarf2_find_line_info))
13890 if (!*functionname_ptr)
13891 arm_elf_find_function (abfd, symbols, section, offset,
13892 *filename_ptr ? NULL : filename_ptr,
13898 /* Skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain
13901 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
13902 & found, filename_ptr,
13903 functionname_ptr, line_ptr,
13904 & elf_tdata (abfd)->line_info))
13907 if (found && (*functionname_ptr || *line_ptr))
13910 if (symbols == NULL)
13913 if (! arm_elf_find_function (abfd, symbols, section, offset,
13914 filename_ptr, functionname_ptr))
13922 elf32_arm_find_inliner_info (bfd * abfd,
13923 const char ** filename_ptr,
13924 const char ** functionname_ptr,
13925 unsigned int * line_ptr)
13928 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
13929 functionname_ptr, line_ptr,
13930 & elf_tdata (abfd)->dwarf2_find_line_info);
13934 /* Adjust a symbol defined by a dynamic object and referenced by a
13935 regular object. The current definition is in some section of the
13936 dynamic object, but we're not including those sections. We have to
13937 change the definition to something the rest of the link can
13941 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
13942 struct elf_link_hash_entry * h)
13946 struct elf32_arm_link_hash_entry * eh;
13947 struct elf32_arm_link_hash_table *globals;
13949 globals = elf32_arm_hash_table (info);
13950 if (globals == NULL)
13953 dynobj = elf_hash_table (info)->dynobj;
13955 /* Make sure we know what is going on here. */
13956 BFD_ASSERT (dynobj != NULL
13958 || h->type == STT_GNU_IFUNC
13959 || h->u.weakdef != NULL
13962 && !h->def_regular)));
13964 eh = (struct elf32_arm_link_hash_entry *) h;
13966 /* If this is a function, put it in the procedure linkage table. We
13967 will fill in the contents of the procedure linkage table later,
13968 when we know the address of the .got section. */
13969 if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
13971 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
13972 symbol binds locally. */
13973 if (h->plt.refcount <= 0
13974 || (h->type != STT_GNU_IFUNC
13975 && (SYMBOL_CALLS_LOCAL (info, h)
13976 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
13977 && h->root.type == bfd_link_hash_undefweak))))
13979 /* This case can occur if we saw a PLT32 reloc in an input
13980 file, but the symbol was never referred to by a dynamic
13981 object, or if all references were garbage collected. In
13982 such a case, we don't actually need to build a procedure
13983 linkage table, and we can just do a PC24 reloc instead. */
13984 h->plt.offset = (bfd_vma) -1;
13985 eh->plt.thumb_refcount = 0;
13986 eh->plt.maybe_thumb_refcount = 0;
13987 eh->plt.noncall_refcount = 0;
13995 /* It's possible that we incorrectly decided a .plt reloc was
13996 needed for an R_ARM_PC24 or similar reloc to a non-function sym
13997 in check_relocs. We can't decide accurately between function
13998 and non-function syms in check-relocs; Objects loaded later in
13999 the link may change h->type. So fix it now. */
14000 h->plt.offset = (bfd_vma) -1;
14001 eh->plt.thumb_refcount = 0;
14002 eh->plt.maybe_thumb_refcount = 0;
14003 eh->plt.noncall_refcount = 0;
14006 /* If this is a weak symbol, and there is a real definition, the
14007 processor independent code will have arranged for us to see the
14008 real definition first, and we can just use the same value. */
14009 if (h->u.weakdef != NULL)
14011 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
14012 || h->u.weakdef->root.type == bfd_link_hash_defweak);
14013 h->root.u.def.section = h->u.weakdef->root.u.def.section;
14014 h->root.u.def.value = h->u.weakdef->root.u.def.value;
14018 /* If there are no non-GOT references, we do not need a copy
14020 if (!h->non_got_ref)
14023 /* This is a reference to a symbol defined by a dynamic object which
14024 is not a function. */
14026 /* If we are creating a shared library, we must presume that the
14027 only references to the symbol are via the global offset table.
14028 For such cases we need not do anything here; the relocations will
14029 be handled correctly by relocate_section. Relocatable executables
14030 can reference data in shared objects directly, so we don't need to
14031 do anything here. */
14032 if (bfd_link_pic (info) || globals->root.is_relocatable_executable)
14035 /* We must allocate the symbol in our .dynbss section, which will
14036 become part of the .bss section of the executable. There will be
14037 an entry for this symbol in the .dynsym section. The dynamic
14038 object will contain position independent code, so all references
14039 from the dynamic object to this symbol will go through the global
14040 offset table. The dynamic linker will use the .dynsym entry to
14041 determine the address it must put in the global offset table, so
14042 both the dynamic object and the regular object will refer to the
14043 same memory location for the variable. */
14044 s = bfd_get_linker_section (dynobj, ".dynbss");
14045 BFD_ASSERT (s != NULL);
14047 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
14048 copy the initial value out of the dynamic object and into the
14049 runtime process image. We need to remember the offset into the
14050 .rel(a).bss section we are going to use. */
14051 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
14055 srel = bfd_get_linker_section (dynobj, RELOC_SECTION (globals, ".bss"));
14056 elf32_arm_allocate_dynrelocs (info, srel, 1);
14060 return _bfd_elf_adjust_dynamic_copy (info, h, s);
14063 /* Allocate space in .plt, .got and associated reloc sections for
14067 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry *h, void * inf)
14069 struct bfd_link_info *info;
14070 struct elf32_arm_link_hash_table *htab;
14071 struct elf32_arm_link_hash_entry *eh;
14072 struct elf_dyn_relocs *p;
14074 if (h->root.type == bfd_link_hash_indirect)
14077 eh = (struct elf32_arm_link_hash_entry *) h;
14079 info = (struct bfd_link_info *) inf;
14080 htab = elf32_arm_hash_table (info);
14084 if ((htab->root.dynamic_sections_created || h->type == STT_GNU_IFUNC)
14085 && h->plt.refcount > 0)
14087 /* Make sure this symbol is output as a dynamic symbol.
14088 Undefined weak syms won't yet be marked as dynamic. */
14089 if (h->dynindx == -1
14090 && !h->forced_local)
14092 if (! bfd_elf_link_record_dynamic_symbol (info, h))
14096 /* If the call in the PLT entry binds locally, the associated
14097 GOT entry should use an R_ARM_IRELATIVE relocation instead of
14098 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
14099 than the .plt section. */
14100 if (h->type == STT_GNU_IFUNC && SYMBOL_CALLS_LOCAL (info, h))
14103 if (eh->plt.noncall_refcount == 0
14104 && SYMBOL_REFERENCES_LOCAL (info, h))
14105 /* All non-call references can be resolved directly.
14106 This means that they can (and in some cases, must)
14107 resolve directly to the run-time target, rather than
14108 to the PLT. That in turns means that any .got entry
14109 would be equal to the .igot.plt entry, so there's
14110 no point having both. */
14111 h->got.refcount = 0;
14114 if (bfd_link_pic (info)
14116 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
14118 elf32_arm_allocate_plt_entry (info, eh->is_iplt, &h->plt, &eh->plt);
14120 /* If this symbol is not defined in a regular file, and we are
14121 not generating a shared library, then set the symbol to this
14122 location in the .plt. This is required to make function
14123 pointers compare as equal between the normal executable and
14124 the shared library. */
14125 if (! bfd_link_pic (info)
14126 && !h->def_regular)
14128 h->root.u.def.section = htab->root.splt;
14129 h->root.u.def.value = h->plt.offset;
14131 /* Make sure the function is not marked as Thumb, in case
14132 it is the target of an ABS32 relocation, which will
14133 point to the PLT entry. */
14134 h->target_internal = ST_BRANCH_TO_ARM;
14137 /* VxWorks executables have a second set of relocations for
14138 each PLT entry. They go in a separate relocation section,
14139 which is processed by the kernel loader. */
14140 if (htab->vxworks_p && !bfd_link_pic (info))
14142 /* There is a relocation for the initial PLT entry:
14143 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
14144 if (h->plt.offset == htab->plt_header_size)
14145 elf32_arm_allocate_dynrelocs (info, htab->srelplt2, 1);
14147 /* There are two extra relocations for each subsequent
14148 PLT entry: an R_ARM_32 relocation for the GOT entry,
14149 and an R_ARM_32 relocation for the PLT entry. */
14150 elf32_arm_allocate_dynrelocs (info, htab->srelplt2, 2);
14155 h->plt.offset = (bfd_vma) -1;
14161 h->plt.offset = (bfd_vma) -1;
14165 eh = (struct elf32_arm_link_hash_entry *) h;
14166 eh->tlsdesc_got = (bfd_vma) -1;
14168 if (h->got.refcount > 0)
14172 int tls_type = elf32_arm_hash_entry (h)->tls_type;
14175 /* Make sure this symbol is output as a dynamic symbol.
14176 Undefined weak syms won't yet be marked as dynamic. */
14177 if (h->dynindx == -1
14178 && !h->forced_local)
14180 if (! bfd_elf_link_record_dynamic_symbol (info, h))
14184 if (!htab->symbian_p)
14186 s = htab->root.sgot;
14187 h->got.offset = s->size;
14189 if (tls_type == GOT_UNKNOWN)
14192 if (tls_type == GOT_NORMAL)
14193 /* Non-TLS symbols need one GOT slot. */
14197 if (tls_type & GOT_TLS_GDESC)
14199 /* R_ARM_TLS_DESC needs 2 GOT slots. */
14201 = (htab->root.sgotplt->size
14202 - elf32_arm_compute_jump_table_size (htab));
14203 htab->root.sgotplt->size += 8;
14204 h->got.offset = (bfd_vma) -2;
14205 /* plt.got_offset needs to know there's a TLS_DESC
14206 reloc in the middle of .got.plt. */
14207 htab->num_tls_desc++;
14210 if (tls_type & GOT_TLS_GD)
14212 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. If
14213 the symbol is both GD and GDESC, got.offset may
14214 have been overwritten. */
14215 h->got.offset = s->size;
14219 if (tls_type & GOT_TLS_IE)
14220 /* R_ARM_TLS_IE32 needs one GOT slot. */
14224 dyn = htab->root.dynamic_sections_created;
14227 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
14228 bfd_link_pic (info),
14230 && (!bfd_link_pic (info)
14231 || !SYMBOL_REFERENCES_LOCAL (info, h)))
14234 if (tls_type != GOT_NORMAL
14235 && (bfd_link_pic (info) || indx != 0)
14236 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
14237 || h->root.type != bfd_link_hash_undefweak))
14239 if (tls_type & GOT_TLS_IE)
14240 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14242 if (tls_type & GOT_TLS_GD)
14243 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14245 if (tls_type & GOT_TLS_GDESC)
14247 elf32_arm_allocate_dynrelocs (info, htab->root.srelplt, 1);
14248 /* GDESC needs a trampoline to jump to. */
14249 htab->tls_trampoline = -1;
14252 /* Only GD needs it. GDESC just emits one relocation per
14254 if ((tls_type & GOT_TLS_GD) && indx != 0)
14255 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14257 else if (indx != -1 && !SYMBOL_REFERENCES_LOCAL (info, h))
14259 if (htab->root.dynamic_sections_created)
14260 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
14261 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14263 else if (h->type == STT_GNU_IFUNC
14264 && eh->plt.noncall_refcount == 0)
14265 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
14266 they all resolve dynamically instead. Reserve room for the
14267 GOT entry's R_ARM_IRELATIVE relocation. */
14268 elf32_arm_allocate_irelocs (info, htab->root.srelgot, 1);
14269 else if (bfd_link_pic (info)
14270 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
14271 || h->root.type != bfd_link_hash_undefweak))
14272 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
14273 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14277 h->got.offset = (bfd_vma) -1;
14279 /* Allocate stubs for exported Thumb functions on v4t. */
14280 if (!htab->use_blx && h->dynindx != -1
14282 && h->target_internal == ST_BRANCH_TO_THUMB
14283 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
14285 struct elf_link_hash_entry * th;
14286 struct bfd_link_hash_entry * bh;
14287 struct elf_link_hash_entry * myh;
14291 /* Create a new symbol to regist the real location of the function. */
14292 s = h->root.u.def.section;
14293 sprintf (name, "__real_%s", h->root.root.string);
14294 _bfd_generic_link_add_one_symbol (info, s->owner,
14295 name, BSF_GLOBAL, s,
14296 h->root.u.def.value,
14297 NULL, TRUE, FALSE, &bh);
14299 myh = (struct elf_link_hash_entry *) bh;
14300 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
14301 myh->forced_local = 1;
14302 myh->target_internal = ST_BRANCH_TO_THUMB;
14303 eh->export_glue = myh;
14304 th = record_arm_to_thumb_glue (info, h);
14305 /* Point the symbol at the stub. */
14306 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
14307 h->target_internal = ST_BRANCH_TO_ARM;
14308 h->root.u.def.section = th->root.u.def.section;
14309 h->root.u.def.value = th->root.u.def.value & ~1;
14312 if (eh->dyn_relocs == NULL)
14315 /* In the shared -Bsymbolic case, discard space allocated for
14316 dynamic pc-relative relocs against symbols which turn out to be
14317 defined in regular objects. For the normal shared case, discard
14318 space for pc-relative relocs that have become local due to symbol
14319 visibility changes. */
14321 if (bfd_link_pic (info) || htab->root.is_relocatable_executable)
14323 /* Relocs that use pc_count are PC-relative forms, which will appear
14324 on something like ".long foo - ." or "movw REG, foo - .". We want
14325 calls to protected symbols to resolve directly to the function
14326 rather than going via the plt. If people want function pointer
14327 comparisons to work as expected then they should avoid writing
14328 assembly like ".long foo - .". */
14329 if (SYMBOL_CALLS_LOCAL (info, h))
14331 struct elf_dyn_relocs **pp;
14333 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
14335 p->count -= p->pc_count;
14344 if (htab->vxworks_p)
14346 struct elf_dyn_relocs **pp;
14348 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
14350 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
14357 /* Also discard relocs on undefined weak syms with non-default
14359 if (eh->dyn_relocs != NULL
14360 && h->root.type == bfd_link_hash_undefweak)
14362 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
14363 eh->dyn_relocs = NULL;
14365 /* Make sure undefined weak symbols are output as a dynamic
14367 else if (h->dynindx == -1
14368 && !h->forced_local)
14370 if (! bfd_elf_link_record_dynamic_symbol (info, h))
14375 else if (htab->root.is_relocatable_executable && h->dynindx == -1
14376 && h->root.type == bfd_link_hash_new)
14378 /* Output absolute symbols so that we can create relocations
14379 against them. For normal symbols we output a relocation
14380 against the section that contains them. */
14381 if (! bfd_elf_link_record_dynamic_symbol (info, h))
14388 /* For the non-shared case, discard space for relocs against
14389 symbols which turn out to need copy relocs or are not
14392 if (!h->non_got_ref
14393 && ((h->def_dynamic
14394 && !h->def_regular)
14395 || (htab->root.dynamic_sections_created
14396 && (h->root.type == bfd_link_hash_undefweak
14397 || h->root.type == bfd_link_hash_undefined))))
14399 /* Make sure this symbol is output as a dynamic symbol.
14400 Undefined weak syms won't yet be marked as dynamic. */
14401 if (h->dynindx == -1
14402 && !h->forced_local)
14404 if (! bfd_elf_link_record_dynamic_symbol (info, h))
14408 /* If that succeeded, we know we'll be keeping all the
14410 if (h->dynindx != -1)
14414 eh->dyn_relocs = NULL;
14419 /* Finally, allocate space. */
14420 for (p = eh->dyn_relocs; p != NULL; p = p->next)
14422 asection *sreloc = elf_section_data (p->sec)->sreloc;
14423 if (h->type == STT_GNU_IFUNC
14424 && eh->plt.noncall_refcount == 0
14425 && SYMBOL_REFERENCES_LOCAL (info, h))
14426 elf32_arm_allocate_irelocs (info, sreloc, p->count);
14428 elf32_arm_allocate_dynrelocs (info, sreloc, p->count);
14434 /* Find any dynamic relocs that apply to read-only sections. */
14437 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
14439 struct elf32_arm_link_hash_entry * eh;
14440 struct elf_dyn_relocs * p;
14442 eh = (struct elf32_arm_link_hash_entry *) h;
14443 for (p = eh->dyn_relocs; p != NULL; p = p->next)
14445 asection *s = p->sec;
14447 if (s != NULL && (s->flags & SEC_READONLY) != 0)
14449 struct bfd_link_info *info = (struct bfd_link_info *) inf;
14451 info->flags |= DF_TEXTREL;
14453 /* Not an error, just cut short the traversal. */
14461 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
14464 struct elf32_arm_link_hash_table *globals;
14466 globals = elf32_arm_hash_table (info);
14467 if (globals == NULL)
14470 globals->byteswap_code = byteswap_code;
14473 /* Set the sizes of the dynamic sections. */
14476 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
14477 struct bfd_link_info * info)
14482 bfd_boolean relocs;
14484 struct elf32_arm_link_hash_table *htab;
14486 htab = elf32_arm_hash_table (info);
14490 dynobj = elf_hash_table (info)->dynobj;
14491 BFD_ASSERT (dynobj != NULL);
14492 check_use_blx (htab);
14494 if (elf_hash_table (info)->dynamic_sections_created)
14496 /* Set the contents of the .interp section to the interpreter. */
14497 if (bfd_link_executable (info) && !info->nointerp)
14499 s = bfd_get_linker_section (dynobj, ".interp");
14500 BFD_ASSERT (s != NULL);
14501 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
14502 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
14506 /* Set up .got offsets for local syms, and space for local dynamic
14508 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
14510 bfd_signed_vma *local_got;
14511 bfd_signed_vma *end_local_got;
14512 struct arm_local_iplt_info **local_iplt_ptr, *local_iplt;
14513 char *local_tls_type;
14514 bfd_vma *local_tlsdesc_gotent;
14515 bfd_size_type locsymcount;
14516 Elf_Internal_Shdr *symtab_hdr;
14518 bfd_boolean is_vxworks = htab->vxworks_p;
14519 unsigned int symndx;
14521 if (! is_arm_elf (ibfd))
14524 for (s = ibfd->sections; s != NULL; s = s->next)
14526 struct elf_dyn_relocs *p;
14528 for (p = (struct elf_dyn_relocs *)
14529 elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
14531 if (!bfd_is_abs_section (p->sec)
14532 && bfd_is_abs_section (p->sec->output_section))
14534 /* Input section has been discarded, either because
14535 it is a copy of a linkonce section or due to
14536 linker script /DISCARD/, so we'll be discarding
14539 else if (is_vxworks
14540 && strcmp (p->sec->output_section->name,
14543 /* Relocations in vxworks .tls_vars sections are
14544 handled specially by the loader. */
14546 else if (p->count != 0)
14548 srel = elf_section_data (p->sec)->sreloc;
14549 elf32_arm_allocate_dynrelocs (info, srel, p->count);
14550 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
14551 info->flags |= DF_TEXTREL;
14556 local_got = elf_local_got_refcounts (ibfd);
14560 symtab_hdr = & elf_symtab_hdr (ibfd);
14561 locsymcount = symtab_hdr->sh_info;
14562 end_local_got = local_got + locsymcount;
14563 local_iplt_ptr = elf32_arm_local_iplt (ibfd);
14564 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
14565 local_tlsdesc_gotent = elf32_arm_local_tlsdesc_gotent (ibfd);
14567 s = htab->root.sgot;
14568 srel = htab->root.srelgot;
14569 for (; local_got < end_local_got;
14570 ++local_got, ++local_iplt_ptr, ++local_tls_type,
14571 ++local_tlsdesc_gotent, ++symndx)
14573 *local_tlsdesc_gotent = (bfd_vma) -1;
14574 local_iplt = *local_iplt_ptr;
14575 if (local_iplt != NULL)
14577 struct elf_dyn_relocs *p;
14579 if (local_iplt->root.refcount > 0)
14581 elf32_arm_allocate_plt_entry (info, TRUE,
14584 if (local_iplt->arm.noncall_refcount == 0)
14585 /* All references to the PLT are calls, so all
14586 non-call references can resolve directly to the
14587 run-time target. This means that the .got entry
14588 would be the same as the .igot.plt entry, so there's
14589 no point creating both. */
14594 BFD_ASSERT (local_iplt->arm.noncall_refcount == 0);
14595 local_iplt->root.offset = (bfd_vma) -1;
14598 for (p = local_iplt->dyn_relocs; p != NULL; p = p->next)
14602 psrel = elf_section_data (p->sec)->sreloc;
14603 if (local_iplt->arm.noncall_refcount == 0)
14604 elf32_arm_allocate_irelocs (info, psrel, p->count);
14606 elf32_arm_allocate_dynrelocs (info, psrel, p->count);
14609 if (*local_got > 0)
14611 Elf_Internal_Sym *isym;
14613 *local_got = s->size;
14614 if (*local_tls_type & GOT_TLS_GD)
14615 /* TLS_GD relocs need an 8-byte structure in the GOT. */
14617 if (*local_tls_type & GOT_TLS_GDESC)
14619 *local_tlsdesc_gotent = htab->root.sgotplt->size
14620 - elf32_arm_compute_jump_table_size (htab);
14621 htab->root.sgotplt->size += 8;
14622 *local_got = (bfd_vma) -2;
14623 /* plt.got_offset needs to know there's a TLS_DESC
14624 reloc in the middle of .got.plt. */
14625 htab->num_tls_desc++;
14627 if (*local_tls_type & GOT_TLS_IE)
14630 if (*local_tls_type & GOT_NORMAL)
14632 /* If the symbol is both GD and GDESC, *local_got
14633 may have been overwritten. */
14634 *local_got = s->size;
14638 isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, symndx);
14642 /* If all references to an STT_GNU_IFUNC PLT are calls,
14643 then all non-call references, including this GOT entry,
14644 resolve directly to the run-time target. */
14645 if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
14646 && (local_iplt == NULL
14647 || local_iplt->arm.noncall_refcount == 0))
14648 elf32_arm_allocate_irelocs (info, srel, 1);
14649 else if (bfd_link_pic (info) || output_bfd->flags & DYNAMIC)
14651 if ((bfd_link_pic (info) && !(*local_tls_type & GOT_TLS_GDESC))
14652 || *local_tls_type & GOT_TLS_GD)
14653 elf32_arm_allocate_dynrelocs (info, srel, 1);
14655 if (bfd_link_pic (info) && *local_tls_type & GOT_TLS_GDESC)
14657 elf32_arm_allocate_dynrelocs (info,
14658 htab->root.srelplt, 1);
14659 htab->tls_trampoline = -1;
14664 *local_got = (bfd_vma) -1;
14668 if (htab->tls_ldm_got.refcount > 0)
14670 /* Allocate two GOT entries and one dynamic relocation (if necessary)
14671 for R_ARM_TLS_LDM32 relocations. */
14672 htab->tls_ldm_got.offset = htab->root.sgot->size;
14673 htab->root.sgot->size += 8;
14674 if (bfd_link_pic (info))
14675 elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
14678 htab->tls_ldm_got.offset = -1;
14680 /* Allocate global sym .plt and .got entries, and space for global
14681 sym dynamic relocs. */
14682 elf_link_hash_traverse (& htab->root, allocate_dynrelocs_for_symbol, info);
14684 /* Here we rummage through the found bfds to collect glue information. */
14685 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
14687 if (! is_arm_elf (ibfd))
14690 /* Initialise mapping tables for code/data. */
14691 bfd_elf32_arm_init_maps (ibfd);
14693 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
14694 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info)
14695 || !bfd_elf32_arm_stm32l4xx_erratum_scan (ibfd, info))
14696 /* xgettext:c-format */
14697 _bfd_error_handler (_("Errors encountered processing file %s"),
14701 /* Allocate space for the glue sections now that we've sized them. */
14702 bfd_elf32_arm_allocate_interworking_sections (info);
14704 /* For every jump slot reserved in the sgotplt, reloc_count is
14705 incremented. However, when we reserve space for TLS descriptors,
14706 it's not incremented, so in order to compute the space reserved
14707 for them, it suffices to multiply the reloc count by the jump
14709 if (htab->root.srelplt)
14710 htab->sgotplt_jump_table_size = elf32_arm_compute_jump_table_size(htab);
14712 if (htab->tls_trampoline)
14714 if (htab->root.splt->size == 0)
14715 htab->root.splt->size += htab->plt_header_size;
14717 htab->tls_trampoline = htab->root.splt->size;
14718 htab->root.splt->size += htab->plt_entry_size;
14720 /* If we're not using lazy TLS relocations, don't generate the
14721 PLT and GOT entries they require. */
14722 if (!(info->flags & DF_BIND_NOW))
14724 htab->dt_tlsdesc_got = htab->root.sgot->size;
14725 htab->root.sgot->size += 4;
14727 htab->dt_tlsdesc_plt = htab->root.splt->size;
14728 htab->root.splt->size += 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline);
14732 /* The check_relocs and adjust_dynamic_symbol entry points have
14733 determined the sizes of the various dynamic sections. Allocate
14734 memory for them. */
14737 for (s = dynobj->sections; s != NULL; s = s->next)
14741 if ((s->flags & SEC_LINKER_CREATED) == 0)
14744 /* It's OK to base decisions on the section name, because none
14745 of the dynobj section names depend upon the input files. */
14746 name = bfd_get_section_name (dynobj, s);
14748 if (s == htab->root.splt)
14750 /* Remember whether there is a PLT. */
14751 plt = s->size != 0;
14753 else if (CONST_STRNEQ (name, ".rel"))
14757 /* Remember whether there are any reloc sections other
14758 than .rel(a).plt and .rela.plt.unloaded. */
14759 if (s != htab->root.srelplt && s != htab->srelplt2)
14762 /* We use the reloc_count field as a counter if we need
14763 to copy relocs into the output file. */
14764 s->reloc_count = 0;
14767 else if (s != htab->root.sgot
14768 && s != htab->root.sgotplt
14769 && s != htab->root.iplt
14770 && s != htab->root.igotplt
14771 && s != htab->sdynbss)
14773 /* It's not one of our sections, so don't allocate space. */
14779 /* If we don't need this section, strip it from the
14780 output file. This is mostly to handle .rel(a).bss and
14781 .rel(a).plt. We must create both sections in
14782 create_dynamic_sections, because they must be created
14783 before the linker maps input sections to output
14784 sections. The linker does that before
14785 adjust_dynamic_symbol is called, and it is that
14786 function which decides whether anything needs to go
14787 into these sections. */
14788 s->flags |= SEC_EXCLUDE;
14792 if ((s->flags & SEC_HAS_CONTENTS) == 0)
14795 /* Allocate memory for the section contents. */
14796 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
14797 if (s->contents == NULL)
14801 if (elf_hash_table (info)->dynamic_sections_created)
14803 /* Add some entries to the .dynamic section. We fill in the
14804 values later, in elf32_arm_finish_dynamic_sections, but we
14805 must add the entries now so that we get the correct size for
14806 the .dynamic section. The DT_DEBUG entry is filled in by the
14807 dynamic linker and used by the debugger. */
14808 #define add_dynamic_entry(TAG, VAL) \
14809 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
14811 if (bfd_link_executable (info))
14813 if (!add_dynamic_entry (DT_DEBUG, 0))
14819 if ( !add_dynamic_entry (DT_PLTGOT, 0)
14820 || !add_dynamic_entry (DT_PLTRELSZ, 0)
14821 || !add_dynamic_entry (DT_PLTREL,
14822 htab->use_rel ? DT_REL : DT_RELA)
14823 || !add_dynamic_entry (DT_JMPREL, 0))
14826 if (htab->dt_tlsdesc_plt &&
14827 (!add_dynamic_entry (DT_TLSDESC_PLT,0)
14828 || !add_dynamic_entry (DT_TLSDESC_GOT,0)))
14836 if (!add_dynamic_entry (DT_REL, 0)
14837 || !add_dynamic_entry (DT_RELSZ, 0)
14838 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
14843 if (!add_dynamic_entry (DT_RELA, 0)
14844 || !add_dynamic_entry (DT_RELASZ, 0)
14845 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
14850 /* If any dynamic relocs apply to a read-only section,
14851 then we need a DT_TEXTREL entry. */
14852 if ((info->flags & DF_TEXTREL) == 0)
14853 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
14856 if ((info->flags & DF_TEXTREL) != 0)
14858 if (!add_dynamic_entry (DT_TEXTREL, 0))
14861 if (htab->vxworks_p
14862 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
14865 #undef add_dynamic_entry
14870 /* Size sections even though they're not dynamic. We use it to setup
14871 _TLS_MODULE_BASE_, if needed. */
14874 elf32_arm_always_size_sections (bfd *output_bfd,
14875 struct bfd_link_info *info)
14879 if (bfd_link_relocatable (info))
14882 tls_sec = elf_hash_table (info)->tls_sec;
14886 struct elf_link_hash_entry *tlsbase;
14888 tlsbase = elf_link_hash_lookup
14889 (elf_hash_table (info), "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
14893 struct bfd_link_hash_entry *bh = NULL;
14894 const struct elf_backend_data *bed
14895 = get_elf_backend_data (output_bfd);
14897 if (!(_bfd_generic_link_add_one_symbol
14898 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
14899 tls_sec, 0, NULL, FALSE,
14900 bed->collect, &bh)))
14903 tlsbase->type = STT_TLS;
14904 tlsbase = (struct elf_link_hash_entry *)bh;
14905 tlsbase->def_regular = 1;
14906 tlsbase->other = STV_HIDDEN;
14907 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
14913 /* Finish up dynamic symbol handling. We set the contents of various
14914 dynamic sections here. */
14917 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
14918 struct bfd_link_info * info,
14919 struct elf_link_hash_entry * h,
14920 Elf_Internal_Sym * sym)
14922 struct elf32_arm_link_hash_table *htab;
14923 struct elf32_arm_link_hash_entry *eh;
14925 htab = elf32_arm_hash_table (info);
14929 eh = (struct elf32_arm_link_hash_entry *) h;
14931 if (h->plt.offset != (bfd_vma) -1)
14935 BFD_ASSERT (h->dynindx != -1);
14936 if (! elf32_arm_populate_plt_entry (output_bfd, info, &h->plt, &eh->plt,
14941 if (!h->def_regular)
14943 /* Mark the symbol as undefined, rather than as defined in
14944 the .plt section. */
14945 sym->st_shndx = SHN_UNDEF;
14946 /* If the symbol is weak we need to clear the value.
14947 Otherwise, the PLT entry would provide a definition for
14948 the symbol even if the symbol wasn't defined anywhere,
14949 and so the symbol would never be NULL. Leave the value if
14950 there were any relocations where pointer equality matters
14951 (this is a clue for the dynamic linker, to make function
14952 pointer comparisons work between an application and shared
14954 if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
14957 else if (eh->is_iplt && eh->plt.noncall_refcount != 0)
14959 /* At least one non-call relocation references this .iplt entry,
14960 so the .iplt entry is the function's canonical address. */
14961 sym->st_info = ELF_ST_INFO (ELF_ST_BIND (sym->st_info), STT_FUNC);
14962 sym->st_target_internal = ST_BRANCH_TO_ARM;
14963 sym->st_shndx = (_bfd_elf_section_from_bfd_section
14964 (output_bfd, htab->root.iplt->output_section));
14965 sym->st_value = (h->plt.offset
14966 + htab->root.iplt->output_section->vma
14967 + htab->root.iplt->output_offset);
14974 Elf_Internal_Rela rel;
14976 /* This symbol needs a copy reloc. Set it up. */
14977 BFD_ASSERT (h->dynindx != -1
14978 && (h->root.type == bfd_link_hash_defined
14979 || h->root.type == bfd_link_hash_defweak));
14982 BFD_ASSERT (s != NULL);
14985 rel.r_offset = (h->root.u.def.value
14986 + h->root.u.def.section->output_section->vma
14987 + h->root.u.def.section->output_offset);
14988 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
14989 elf32_arm_add_dynreloc (output_bfd, info, s, &rel);
14992 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
14993 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
14994 to the ".got" section. */
14995 if (h == htab->root.hdynamic
14996 || (!htab->vxworks_p && h == htab->root.hgot))
14997 sym->st_shndx = SHN_ABS;
15003 arm_put_trampoline (struct elf32_arm_link_hash_table *htab, bfd *output_bfd,
15005 const unsigned long *template, unsigned count)
15009 for (ix = 0; ix != count; ix++)
15011 unsigned long insn = template[ix];
15013 /* Emit mov pc,rx if bx is not permitted. */
15014 if (htab->fix_v4bx == 1 && (insn & 0x0ffffff0) == 0x012fff10)
15015 insn = (insn & 0xf000000f) | 0x01a0f000;
15016 put_arm_insn (htab, output_bfd, insn, (char *)contents + ix*4);
15020 /* Install the special first PLT entry for elf32-arm-nacl. Unlike
15021 other variants, NaCl needs this entry in a static executable's
15022 .iplt too. When we're handling that case, GOT_DISPLACEMENT is
15023 zero. For .iplt really only the last bundle is useful, and .iplt
15024 could have a shorter first entry, with each individual PLT entry's
15025 relative branch calculated differently so it targets the last
15026 bundle instead of the instruction before it (labelled .Lplt_tail
15027 above). But it's simpler to keep the size and layout of PLT0
15028 consistent with the dynamic case, at the cost of some dead code at
15029 the start of .iplt and the one dead store to the stack at the start
15032 arm_nacl_put_plt0 (struct elf32_arm_link_hash_table *htab, bfd *output_bfd,
15033 asection *plt, bfd_vma got_displacement)
15037 put_arm_insn (htab, output_bfd,
15038 elf32_arm_nacl_plt0_entry[0]
15039 | arm_movw_immediate (got_displacement),
15040 plt->contents + 0);
15041 put_arm_insn (htab, output_bfd,
15042 elf32_arm_nacl_plt0_entry[1]
15043 | arm_movt_immediate (got_displacement),
15044 plt->contents + 4);
15046 for (i = 2; i < ARRAY_SIZE (elf32_arm_nacl_plt0_entry); ++i)
15047 put_arm_insn (htab, output_bfd,
15048 elf32_arm_nacl_plt0_entry[i],
15049 plt->contents + (i * 4));
15052 /* Finish up the dynamic sections. */
15055 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
15060 struct elf32_arm_link_hash_table *htab;
15062 htab = elf32_arm_hash_table (info);
15066 dynobj = elf_hash_table (info)->dynobj;
15068 sgot = htab->root.sgotplt;
15069 /* A broken linker script might have discarded the dynamic sections.
15070 Catch this here so that we do not seg-fault later on. */
15071 if (sgot != NULL && bfd_is_abs_section (sgot->output_section))
15073 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
15075 if (elf_hash_table (info)->dynamic_sections_created)
15078 Elf32_External_Dyn *dyncon, *dynconend;
15080 splt = htab->root.splt;
15081 BFD_ASSERT (splt != NULL && sdyn != NULL);
15082 BFD_ASSERT (htab->symbian_p || sgot != NULL);
15084 dyncon = (Elf32_External_Dyn *) sdyn->contents;
15085 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
15087 for (; dyncon < dynconend; dyncon++)
15089 Elf_Internal_Dyn dyn;
15093 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
15100 if (htab->vxworks_p
15101 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
15102 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15107 goto get_vma_if_bpabi;
15110 goto get_vma_if_bpabi;
15113 goto get_vma_if_bpabi;
15115 name = ".gnu.version";
15116 goto get_vma_if_bpabi;
15118 name = ".gnu.version_d";
15119 goto get_vma_if_bpabi;
15121 name = ".gnu.version_r";
15122 goto get_vma_if_bpabi;
15128 name = RELOC_SECTION (htab, ".plt");
15130 s = bfd_get_section_by_name (output_bfd, name);
15133 /* PR ld/14397: Issue an error message if a required section is missing. */
15134 (*_bfd_error_handler)
15135 (_("error: required section '%s' not found in the linker script"), name);
15136 bfd_set_error (bfd_error_invalid_operation);
15139 if (!htab->symbian_p)
15140 dyn.d_un.d_ptr = s->vma;
15142 /* In the BPABI, tags in the PT_DYNAMIC section point
15143 at the file offset, not the memory address, for the
15144 convenience of the post linker. */
15145 dyn.d_un.d_ptr = s->filepos;
15146 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15150 if (htab->symbian_p)
15155 s = htab->root.srelplt;
15156 BFD_ASSERT (s != NULL);
15157 dyn.d_un.d_val = s->size;
15158 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15163 if (!htab->symbian_p)
15165 /* My reading of the SVR4 ABI indicates that the
15166 procedure linkage table relocs (DT_JMPREL) should be
15167 included in the overall relocs (DT_REL). This is
15168 what Solaris does. However, UnixWare can not handle
15169 that case. Therefore, we override the DT_RELSZ entry
15170 here to make it not include the JMPREL relocs. Since
15171 the linker script arranges for .rel(a).plt to follow all
15172 other relocation sections, we don't have to worry
15173 about changing the DT_REL entry. */
15174 s = htab->root.srelplt;
15176 dyn.d_un.d_val -= s->size;
15177 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15180 /* Fall through. */
15184 /* In the BPABI, the DT_REL tag must point at the file
15185 offset, not the VMA, of the first relocation
15186 section. So, we use code similar to that in
15187 elflink.c, but do not check for SHF_ALLOC on the
15188 relcoation section, since relocations sections are
15189 never allocated under the BPABI. The comments above
15190 about Unixware notwithstanding, we include all of the
15191 relocations here. */
15192 if (htab->symbian_p)
15195 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
15196 ? SHT_REL : SHT_RELA);
15197 dyn.d_un.d_val = 0;
15198 for (i = 1; i < elf_numsections (output_bfd); i++)
15200 Elf_Internal_Shdr *hdr
15201 = elf_elfsections (output_bfd)[i];
15202 if (hdr->sh_type == type)
15204 if (dyn.d_tag == DT_RELSZ
15205 || dyn.d_tag == DT_RELASZ)
15206 dyn.d_un.d_val += hdr->sh_size;
15207 else if ((ufile_ptr) hdr->sh_offset
15208 <= dyn.d_un.d_val - 1)
15209 dyn.d_un.d_val = hdr->sh_offset;
15212 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15216 case DT_TLSDESC_PLT:
15217 s = htab->root.splt;
15218 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
15219 + htab->dt_tlsdesc_plt);
15220 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15223 case DT_TLSDESC_GOT:
15224 s = htab->root.sgot;
15225 dyn.d_un.d_ptr = (s->output_section->vma + s->output_offset
15226 + htab->dt_tlsdesc_got);
15227 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15230 /* Set the bottom bit of DT_INIT/FINI if the
15231 corresponding function is Thumb. */
15233 name = info->init_function;
15236 name = info->fini_function;
15238 /* If it wasn't set by elf_bfd_final_link
15239 then there is nothing to adjust. */
15240 if (dyn.d_un.d_val != 0)
15242 struct elf_link_hash_entry * eh;
15244 eh = elf_link_hash_lookup (elf_hash_table (info), name,
15245 FALSE, FALSE, TRUE);
15246 if (eh != NULL && eh->target_internal == ST_BRANCH_TO_THUMB)
15248 dyn.d_un.d_val |= 1;
15249 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
15256 /* Fill in the first entry in the procedure linkage table. */
15257 if (splt->size > 0 && htab->plt_header_size)
15259 const bfd_vma *plt0_entry;
15260 bfd_vma got_address, plt_address, got_displacement;
15262 /* Calculate the addresses of the GOT and PLT. */
15263 got_address = sgot->output_section->vma + sgot->output_offset;
15264 plt_address = splt->output_section->vma + splt->output_offset;
15266 if (htab->vxworks_p)
15268 /* The VxWorks GOT is relocated by the dynamic linker.
15269 Therefore, we must emit relocations rather than simply
15270 computing the values now. */
15271 Elf_Internal_Rela rel;
15273 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
15274 put_arm_insn (htab, output_bfd, plt0_entry[0],
15275 splt->contents + 0);
15276 put_arm_insn (htab, output_bfd, plt0_entry[1],
15277 splt->contents + 4);
15278 put_arm_insn (htab, output_bfd, plt0_entry[2],
15279 splt->contents + 8);
15280 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
15282 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
15283 rel.r_offset = plt_address + 12;
15284 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
15286 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
15287 htab->srelplt2->contents);
15289 else if (htab->nacl_p)
15290 arm_nacl_put_plt0 (htab, output_bfd, splt,
15291 got_address + 8 - (plt_address + 16));
15292 else if (using_thumb_only (htab))
15294 got_displacement = got_address - (plt_address + 12);
15296 plt0_entry = elf32_thumb2_plt0_entry;
15297 put_arm_insn (htab, output_bfd, plt0_entry[0],
15298 splt->contents + 0);
15299 put_arm_insn (htab, output_bfd, plt0_entry[1],
15300 splt->contents + 4);
15301 put_arm_insn (htab, output_bfd, plt0_entry[2],
15302 splt->contents + 8);
15304 bfd_put_32 (output_bfd, got_displacement, splt->contents + 12);
15308 got_displacement = got_address - (plt_address + 16);
15310 plt0_entry = elf32_arm_plt0_entry;
15311 put_arm_insn (htab, output_bfd, plt0_entry[0],
15312 splt->contents + 0);
15313 put_arm_insn (htab, output_bfd, plt0_entry[1],
15314 splt->contents + 4);
15315 put_arm_insn (htab, output_bfd, plt0_entry[2],
15316 splt->contents + 8);
15317 put_arm_insn (htab, output_bfd, plt0_entry[3],
15318 splt->contents + 12);
15320 #ifdef FOUR_WORD_PLT
15321 /* The displacement value goes in the otherwise-unused
15322 last word of the second entry. */
15323 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
15325 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
15330 /* UnixWare sets the entsize of .plt to 4, although that doesn't
15331 really seem like the right value. */
15332 if (splt->output_section->owner == output_bfd)
15333 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
15335 if (htab->dt_tlsdesc_plt)
15337 bfd_vma got_address
15338 = sgot->output_section->vma + sgot->output_offset;
15339 bfd_vma gotplt_address = (htab->root.sgot->output_section->vma
15340 + htab->root.sgot->output_offset);
15341 bfd_vma plt_address
15342 = splt->output_section->vma + splt->output_offset;
15344 arm_put_trampoline (htab, output_bfd,
15345 splt->contents + htab->dt_tlsdesc_plt,
15346 dl_tlsdesc_lazy_trampoline, 6);
15348 bfd_put_32 (output_bfd,
15349 gotplt_address + htab->dt_tlsdesc_got
15350 - (plt_address + htab->dt_tlsdesc_plt)
15351 - dl_tlsdesc_lazy_trampoline[6],
15352 splt->contents + htab->dt_tlsdesc_plt + 24);
15353 bfd_put_32 (output_bfd,
15354 got_address - (plt_address + htab->dt_tlsdesc_plt)
15355 - dl_tlsdesc_lazy_trampoline[7],
15356 splt->contents + htab->dt_tlsdesc_plt + 24 + 4);
15359 if (htab->tls_trampoline)
15361 arm_put_trampoline (htab, output_bfd,
15362 splt->contents + htab->tls_trampoline,
15363 tls_trampoline, 3);
15364 #ifdef FOUR_WORD_PLT
15365 bfd_put_32 (output_bfd, 0x00000000,
15366 splt->contents + htab->tls_trampoline + 12);
15370 if (htab->vxworks_p
15371 && !bfd_link_pic (info)
15372 && htab->root.splt->size > 0)
15374 /* Correct the .rel(a).plt.unloaded relocations. They will have
15375 incorrect symbol indexes. */
15379 num_plts = ((htab->root.splt->size - htab->plt_header_size)
15380 / htab->plt_entry_size);
15381 p = htab->srelplt2->contents + RELOC_SIZE (htab);
15383 for (; num_plts; num_plts--)
15385 Elf_Internal_Rela rel;
15387 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
15388 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
15389 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
15390 p += RELOC_SIZE (htab);
15392 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
15393 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
15394 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
15395 p += RELOC_SIZE (htab);
15400 if (htab->nacl_p && htab->root.iplt != NULL && htab->root.iplt->size > 0)
15401 /* NaCl uses a special first entry in .iplt too. */
15402 arm_nacl_put_plt0 (htab, output_bfd, htab->root.iplt, 0);
15404 /* Fill in the first three entries in the global offset table. */
15407 if (sgot->size > 0)
15410 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
15412 bfd_put_32 (output_bfd,
15413 sdyn->output_section->vma + sdyn->output_offset,
15415 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
15416 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
15419 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
15426 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
15428 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
15429 struct elf32_arm_link_hash_table *globals;
15430 struct elf_segment_map *m;
15432 i_ehdrp = elf_elfheader (abfd);
15434 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
15435 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
15437 _bfd_elf_post_process_headers (abfd, link_info);
15438 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
15442 globals = elf32_arm_hash_table (link_info);
15443 if (globals != NULL && globals->byteswap_code)
15444 i_ehdrp->e_flags |= EF_ARM_BE8;
15447 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_VER5
15448 && ((i_ehdrp->e_type == ET_DYN) || (i_ehdrp->e_type == ET_EXEC)))
15450 int abi = bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ABI_VFP_args);
15451 if (abi == AEABI_VFP_args_vfp)
15452 i_ehdrp->e_flags |= EF_ARM_ABI_FLOAT_HARD;
15454 i_ehdrp->e_flags |= EF_ARM_ABI_FLOAT_SOFT;
15457 /* Scan segment to set p_flags attribute if it contains only sections with
15458 SHF_ARM_NOREAD flag. */
15459 for (m = elf_seg_map (abfd); m != NULL; m = m->next)
15465 for (j = 0; j < m->count; j++)
15467 if (!(elf_section_flags (m->sections[j]) & SHF_ARM_NOREAD))
15473 m->p_flags_valid = 1;
15478 static enum elf_reloc_type_class
15479 elf32_arm_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
15480 const asection *rel_sec ATTRIBUTE_UNUSED,
15481 const Elf_Internal_Rela *rela)
15483 switch ((int) ELF32_R_TYPE (rela->r_info))
15485 case R_ARM_RELATIVE:
15486 return reloc_class_relative;
15487 case R_ARM_JUMP_SLOT:
15488 return reloc_class_plt;
15490 return reloc_class_copy;
15492 return reloc_class_normal;
15497 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
15499 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
15502 /* Return TRUE if this is an unwinding table entry. */
15505 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
15507 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
15508 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
15512 /* Set the type and flags for an ARM section. We do this by
15513 the section name, which is a hack, but ought to work. */
15516 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
15520 name = bfd_get_section_name (abfd, sec);
15522 if (is_arm_elf_unwind_section_name (abfd, name))
15524 hdr->sh_type = SHT_ARM_EXIDX;
15525 hdr->sh_flags |= SHF_LINK_ORDER;
15528 if (sec->flags & SEC_ELF_NOREAD)
15529 hdr->sh_flags |= SHF_ARM_NOREAD;
15534 /* Handle an ARM specific section when reading an object file. This is
15535 called when bfd_section_from_shdr finds a section with an unknown
15539 elf32_arm_section_from_shdr (bfd *abfd,
15540 Elf_Internal_Shdr * hdr,
15544 /* There ought to be a place to keep ELF backend specific flags, but
15545 at the moment there isn't one. We just keep track of the
15546 sections by their name, instead. Fortunately, the ABI gives
15547 names for all the ARM specific sections, so we will probably get
15549 switch (hdr->sh_type)
15551 case SHT_ARM_EXIDX:
15552 case SHT_ARM_PREEMPTMAP:
15553 case SHT_ARM_ATTRIBUTES:
15560 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
15566 static _arm_elf_section_data *
15567 get_arm_elf_section_data (asection * sec)
15569 if (sec && sec->owner && is_arm_elf (sec->owner))
15570 return elf32_arm_section_data (sec);
15578 struct bfd_link_info *info;
15581 int (*func) (void *, const char *, Elf_Internal_Sym *,
15582 asection *, struct elf_link_hash_entry *);
15583 } output_arch_syminfo;
15585 enum map_symbol_type
15593 /* Output a single mapping symbol. */
15596 elf32_arm_output_map_sym (output_arch_syminfo *osi,
15597 enum map_symbol_type type,
15600 static const char *names[3] = {"$a", "$t", "$d"};
15601 Elf_Internal_Sym sym;
15603 sym.st_value = osi->sec->output_section->vma
15604 + osi->sec->output_offset
15608 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
15609 sym.st_shndx = osi->sec_shndx;
15610 sym.st_target_internal = 0;
15611 elf32_arm_section_map_add (osi->sec, names[type][1], offset);
15612 return osi->func (osi->flaginfo, names[type], &sym, osi->sec, NULL) == 1;
15615 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
15616 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
15619 elf32_arm_output_plt_map_1 (output_arch_syminfo *osi,
15620 bfd_boolean is_iplt_entry_p,
15621 union gotplt_union *root_plt,
15622 struct arm_plt_info *arm_plt)
15624 struct elf32_arm_link_hash_table *htab;
15625 bfd_vma addr, plt_header_size;
15627 if (root_plt->offset == (bfd_vma) -1)
15630 htab = elf32_arm_hash_table (osi->info);
15634 if (is_iplt_entry_p)
15636 osi->sec = htab->root.iplt;
15637 plt_header_size = 0;
15641 osi->sec = htab->root.splt;
15642 plt_header_size = htab->plt_header_size;
15644 osi->sec_shndx = (_bfd_elf_section_from_bfd_section
15645 (osi->info->output_bfd, osi->sec->output_section));
15647 addr = root_plt->offset & -2;
15648 if (htab->symbian_p)
15650 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
15652 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
15655 else if (htab->vxworks_p)
15657 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
15659 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
15661 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
15663 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
15666 else if (htab->nacl_p)
15668 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
15671 else if (using_thumb_only (htab))
15673 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr))
15678 bfd_boolean thumb_stub_p;
15680 thumb_stub_p = elf32_arm_plt_needs_thumb_stub_p (osi->info, arm_plt);
15683 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
15686 #ifdef FOUR_WORD_PLT
15687 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
15689 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
15692 /* A three-word PLT with no Thumb thunk contains only Arm code,
15693 so only need to output a mapping symbol for the first PLT entry and
15694 entries with thumb thunks. */
15695 if (thumb_stub_p || addr == plt_header_size)
15697 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
15706 /* Output mapping symbols for PLT entries associated with H. */
15709 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
15711 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
15712 struct elf32_arm_link_hash_entry *eh;
15714 if (h->root.type == bfd_link_hash_indirect)
15717 if (h->root.type == bfd_link_hash_warning)
15718 /* When warning symbols are created, they **replace** the "real"
15719 entry in the hash table, thus we never get to see the real
15720 symbol in a hash traversal. So look at it now. */
15721 h = (struct elf_link_hash_entry *) h->root.u.i.link;
15723 eh = (struct elf32_arm_link_hash_entry *) h;
15724 return elf32_arm_output_plt_map_1 (osi, SYMBOL_CALLS_LOCAL (osi->info, h),
15725 &h->plt, &eh->plt);
15728 /* Output a single local symbol for a generated stub. */
15731 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
15732 bfd_vma offset, bfd_vma size)
15734 Elf_Internal_Sym sym;
15736 sym.st_value = osi->sec->output_section->vma
15737 + osi->sec->output_offset
15739 sym.st_size = size;
15741 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
15742 sym.st_shndx = osi->sec_shndx;
15743 sym.st_target_internal = 0;
15744 return osi->func (osi->flaginfo, name, &sym, osi->sec, NULL) == 1;
15748 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
15751 struct elf32_arm_stub_hash_entry *stub_entry;
15752 asection *stub_sec;
15755 output_arch_syminfo *osi;
15756 const insn_sequence *template_sequence;
15757 enum stub_insn_type prev_type;
15760 enum map_symbol_type sym_type;
15762 /* Massage our args to the form they really have. */
15763 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
15764 osi = (output_arch_syminfo *) in_arg;
15766 stub_sec = stub_entry->stub_sec;
15768 /* Ensure this stub is attached to the current section being
15770 if (stub_sec != osi->sec)
15773 addr = (bfd_vma) stub_entry->stub_offset;
15774 stub_name = stub_entry->output_name;
15776 template_sequence = stub_entry->stub_template;
15777 switch (template_sequence[0].type)
15780 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
15785 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
15786 stub_entry->stub_size))
15794 prev_type = DATA_TYPE;
15796 for (i = 0; i < stub_entry->stub_template_size; i++)
15798 switch (template_sequence[i].type)
15801 sym_type = ARM_MAP_ARM;
15806 sym_type = ARM_MAP_THUMB;
15810 sym_type = ARM_MAP_DATA;
15818 if (template_sequence[i].type != prev_type)
15820 prev_type = template_sequence[i].type;
15821 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
15825 switch (template_sequence[i].type)
15849 /* Output mapping symbols for linker generated sections,
15850 and for those data-only sections that do not have a
15854 elf32_arm_output_arch_local_syms (bfd *output_bfd,
15855 struct bfd_link_info *info,
15857 int (*func) (void *, const char *,
15858 Elf_Internal_Sym *,
15860 struct elf_link_hash_entry *))
15862 output_arch_syminfo osi;
15863 struct elf32_arm_link_hash_table *htab;
15865 bfd_size_type size;
15868 htab = elf32_arm_hash_table (info);
15872 check_use_blx (htab);
15874 osi.flaginfo = flaginfo;
15878 /* Add a $d mapping symbol to data-only sections that
15879 don't have any mapping symbol. This may result in (harmless) redundant
15880 mapping symbols. */
15881 for (input_bfd = info->input_bfds;
15883 input_bfd = input_bfd->link.next)
15885 if ((input_bfd->flags & (BFD_LINKER_CREATED | HAS_SYMS)) == HAS_SYMS)
15886 for (osi.sec = input_bfd->sections;
15888 osi.sec = osi.sec->next)
15890 if (osi.sec->output_section != NULL
15891 && ((osi.sec->output_section->flags & (SEC_ALLOC | SEC_CODE))
15893 && (osi.sec->flags & (SEC_HAS_CONTENTS | SEC_LINKER_CREATED))
15894 == SEC_HAS_CONTENTS
15895 && get_arm_elf_section_data (osi.sec) != NULL
15896 && get_arm_elf_section_data (osi.sec)->mapcount == 0
15897 && osi.sec->size > 0
15898 && (osi.sec->flags & SEC_EXCLUDE) == 0)
15900 osi.sec_shndx = _bfd_elf_section_from_bfd_section
15901 (output_bfd, osi.sec->output_section);
15902 if (osi.sec_shndx != (int)SHN_BAD)
15903 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 0);
15908 /* ARM->Thumb glue. */
15909 if (htab->arm_glue_size > 0)
15911 osi.sec = bfd_get_linker_section (htab->bfd_of_glue_owner,
15912 ARM2THUMB_GLUE_SECTION_NAME);
15914 osi.sec_shndx = _bfd_elf_section_from_bfd_section
15915 (output_bfd, osi.sec->output_section);
15916 if (bfd_link_pic (info) || htab->root.is_relocatable_executable
15917 || htab->pic_veneer)
15918 size = ARM2THUMB_PIC_GLUE_SIZE;
15919 else if (htab->use_blx)
15920 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
15922 size = ARM2THUMB_STATIC_GLUE_SIZE;
15924 for (offset = 0; offset < htab->arm_glue_size; offset += size)
15926 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
15927 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
15931 /* Thumb->ARM glue. */
15932 if (htab->thumb_glue_size > 0)
15934 osi.sec = bfd_get_linker_section (htab->bfd_of_glue_owner,
15935 THUMB2ARM_GLUE_SECTION_NAME);
15937 osi.sec_shndx = _bfd_elf_section_from_bfd_section
15938 (output_bfd, osi.sec->output_section);
15939 size = THUMB2ARM_GLUE_SIZE;
15941 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
15943 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
15944 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
15948 /* ARMv4 BX veneers. */
15949 if (htab->bx_glue_size > 0)
15951 osi.sec = bfd_get_linker_section (htab->bfd_of_glue_owner,
15952 ARM_BX_GLUE_SECTION_NAME);
15954 osi.sec_shndx = _bfd_elf_section_from_bfd_section
15955 (output_bfd, osi.sec->output_section);
15957 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
15960 /* Long calls stubs. */
15961 if (htab->stub_bfd && htab->stub_bfd->sections)
15963 asection* stub_sec;
15965 for (stub_sec = htab->stub_bfd->sections;
15967 stub_sec = stub_sec->next)
15969 /* Ignore non-stub sections. */
15970 if (!strstr (stub_sec->name, STUB_SUFFIX))
15973 osi.sec = stub_sec;
15975 osi.sec_shndx = _bfd_elf_section_from_bfd_section
15976 (output_bfd, osi.sec->output_section);
15978 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
15982 /* Finally, output mapping symbols for the PLT. */
15983 if (htab->root.splt && htab->root.splt->size > 0)
15985 osi.sec = htab->root.splt;
15986 osi.sec_shndx = (_bfd_elf_section_from_bfd_section
15987 (output_bfd, osi.sec->output_section));
15989 /* Output mapping symbols for the plt header. SymbianOS does not have a
15991 if (htab->vxworks_p)
15993 /* VxWorks shared libraries have no PLT header. */
15994 if (!bfd_link_pic (info))
15996 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
15998 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
16002 else if (htab->nacl_p)
16004 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
16007 else if (using_thumb_only (htab))
16009 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, 0))
16011 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
16013 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, 16))
16016 else if (!htab->symbian_p)
16018 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
16020 #ifndef FOUR_WORD_PLT
16021 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
16026 if (htab->nacl_p && htab->root.iplt && htab->root.iplt->size > 0)
16028 /* NaCl uses a special first entry in .iplt too. */
16029 osi.sec = htab->root.iplt;
16030 osi.sec_shndx = (_bfd_elf_section_from_bfd_section
16031 (output_bfd, osi.sec->output_section));
16032 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
16035 if ((htab->root.splt && htab->root.splt->size > 0)
16036 || (htab->root.iplt && htab->root.iplt->size > 0))
16038 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, &osi);
16039 for (input_bfd = info->input_bfds;
16041 input_bfd = input_bfd->link.next)
16043 struct arm_local_iplt_info **local_iplt;
16044 unsigned int i, num_syms;
16046 local_iplt = elf32_arm_local_iplt (input_bfd);
16047 if (local_iplt != NULL)
16049 num_syms = elf_symtab_hdr (input_bfd).sh_info;
16050 for (i = 0; i < num_syms; i++)
16051 if (local_iplt[i] != NULL
16052 && !elf32_arm_output_plt_map_1 (&osi, TRUE,
16053 &local_iplt[i]->root,
16054 &local_iplt[i]->arm))
16059 if (htab->dt_tlsdesc_plt != 0)
16061 /* Mapping symbols for the lazy tls trampoline. */
16062 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, htab->dt_tlsdesc_plt))
16065 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA,
16066 htab->dt_tlsdesc_plt + 24))
16069 if (htab->tls_trampoline != 0)
16071 /* Mapping symbols for the tls trampoline. */
16072 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, htab->tls_trampoline))
16074 #ifdef FOUR_WORD_PLT
16075 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA,
16076 htab->tls_trampoline + 12))
16084 /* Allocate target specific section data. */
16087 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
16089 if (!sec->used_by_bfd)
16091 _arm_elf_section_data *sdata;
16092 bfd_size_type amt = sizeof (*sdata);
16094 sdata = (_arm_elf_section_data *) bfd_zalloc (abfd, amt);
16097 sec->used_by_bfd = sdata;
16100 return _bfd_elf_new_section_hook (abfd, sec);
16104 /* Used to order a list of mapping symbols by address. */
16107 elf32_arm_compare_mapping (const void * a, const void * b)
16109 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
16110 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
16112 if (amap->vma > bmap->vma)
16114 else if (amap->vma < bmap->vma)
16116 else if (amap->type > bmap->type)
16117 /* Ensure results do not depend on the host qsort for objects with
16118 multiple mapping symbols at the same address by sorting on type
16121 else if (amap->type < bmap->type)
16127 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
16129 static unsigned long
16130 offset_prel31 (unsigned long addr, bfd_vma offset)
16132 return (addr & ~0x7ffffffful) | ((addr + offset) & 0x7ffffffful);
16135 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
16139 copy_exidx_entry (bfd *output_bfd, bfd_byte *to, bfd_byte *from, bfd_vma offset)
16141 unsigned long first_word = bfd_get_32 (output_bfd, from);
16142 unsigned long second_word = bfd_get_32 (output_bfd, from + 4);
16144 /* High bit of first word is supposed to be zero. */
16145 if ((first_word & 0x80000000ul) == 0)
16146 first_word = offset_prel31 (first_word, offset);
16148 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
16149 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
16150 if ((second_word != 0x1) && ((second_word & 0x80000000ul) == 0))
16151 second_word = offset_prel31 (second_word, offset);
16153 bfd_put_32 (output_bfd, first_word, to);
16154 bfd_put_32 (output_bfd, second_word, to + 4);
16157 /* Data for make_branch_to_a8_stub(). */
16159 struct a8_branch_to_stub_data
16161 asection *writing_section;
16162 bfd_byte *contents;
16166 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
16167 places for a particular section. */
16170 make_branch_to_a8_stub (struct bfd_hash_entry *gen_entry,
16173 struct elf32_arm_stub_hash_entry *stub_entry;
16174 struct a8_branch_to_stub_data *data;
16175 bfd_byte *contents;
16176 unsigned long branch_insn;
16177 bfd_vma veneered_insn_loc, veneer_entry_loc;
16178 bfd_signed_vma branch_offset;
16180 unsigned int target;
16182 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
16183 data = (struct a8_branch_to_stub_data *) in_arg;
16185 if (stub_entry->target_section != data->writing_section
16186 || stub_entry->stub_type < arm_stub_a8_veneer_lwm)
16189 contents = data->contents;
16191 veneered_insn_loc = stub_entry->target_section->output_section->vma
16192 + stub_entry->target_section->output_offset
16193 + stub_entry->target_value;
16195 veneer_entry_loc = stub_entry->stub_sec->output_section->vma
16196 + stub_entry->stub_sec->output_offset
16197 + stub_entry->stub_offset;
16199 if (stub_entry->stub_type == arm_stub_a8_veneer_blx)
16200 veneered_insn_loc &= ~3u;
16202 branch_offset = veneer_entry_loc - veneered_insn_loc - 4;
16204 abfd = stub_entry->target_section->owner;
16205 target = stub_entry->target_value;
16207 /* We attempt to avoid this condition by setting stubs_always_after_branch
16208 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
16209 This check is just to be on the safe side... */
16210 if ((veneered_insn_loc & ~0xfff) == (veneer_entry_loc & ~0xfff))
16212 (*_bfd_error_handler) (_("%B: error: Cortex-A8 erratum stub is "
16213 "allocated in unsafe location"), abfd);
16217 switch (stub_entry->stub_type)
16219 case arm_stub_a8_veneer_b:
16220 case arm_stub_a8_veneer_b_cond:
16221 branch_insn = 0xf0009000;
16224 case arm_stub_a8_veneer_blx:
16225 branch_insn = 0xf000e800;
16228 case arm_stub_a8_veneer_bl:
16230 unsigned int i1, j1, i2, j2, s;
16232 branch_insn = 0xf000d000;
16235 if (branch_offset < -16777216 || branch_offset > 16777214)
16237 /* There's not much we can do apart from complain if this
16239 (*_bfd_error_handler) (_("%B: error: Cortex-A8 erratum stub out "
16240 "of range (input file too large)"), abfd);
16244 /* i1 = not(j1 eor s), so:
16246 j1 = (not i1) eor s. */
16248 branch_insn |= (branch_offset >> 1) & 0x7ff;
16249 branch_insn |= ((branch_offset >> 12) & 0x3ff) << 16;
16250 i2 = (branch_offset >> 22) & 1;
16251 i1 = (branch_offset >> 23) & 1;
16252 s = (branch_offset >> 24) & 1;
16255 branch_insn |= j2 << 11;
16256 branch_insn |= j1 << 13;
16257 branch_insn |= s << 26;
16266 bfd_put_16 (abfd, (branch_insn >> 16) & 0xffff, &contents[target]);
16267 bfd_put_16 (abfd, branch_insn & 0xffff, &contents[target + 2]);
16272 /* Beginning of stm32l4xx work-around. */
16274 /* Functions encoding instructions necessary for the emission of the
16275 fix-stm32l4xx-629360.
16276 Encoding is extracted from the
16277 ARM (C) Architecture Reference Manual
16278 ARMv7-A and ARMv7-R edition
16279 ARM DDI 0406C.b (ID072512). */
16281 static inline bfd_vma
16282 create_instruction_branch_absolute (int branch_offset)
16284 /* A8.8.18 B (A8-334)
16285 B target_address (Encoding T4). */
16286 /* 1111 - 0Sii - iiii - iiii - 10J1 - Jiii - iiii - iiii. */
16287 /* jump offset is: S:I1:I2:imm10:imm11:0. */
16288 /* with : I1 = NOT (J1 EOR S) I2 = NOT (J2 EOR S). */
16290 int s = ((branch_offset & 0x1000000) >> 24);
16291 int j1 = s ^ !((branch_offset & 0x800000) >> 23);
16292 int j2 = s ^ !((branch_offset & 0x400000) >> 22);
16294 if (branch_offset < -(1 << 24) || branch_offset >= (1 << 24))
16295 BFD_ASSERT (0 && "Error: branch out of range. Cannot create branch.");
16297 bfd_vma patched_inst = 0xf0009000
16299 | (((unsigned long) (branch_offset) >> 12) & 0x3ff) << 16 /* imm10. */
16300 | j1 << 13 /* J1. */
16301 | j2 << 11 /* J2. */
16302 | (((unsigned long) (branch_offset) >> 1) & 0x7ff); /* imm11. */
16304 return patched_inst;
16307 static inline bfd_vma
16308 create_instruction_ldmia (int base_reg, int wback, int reg_mask)
16310 /* A8.8.57 LDM/LDMIA/LDMFD (A8-396)
16311 LDMIA Rn!, {Ra, Rb, Rc, ...} (Encoding T2). */
16312 bfd_vma patched_inst = 0xe8900000
16313 | (/*W=*/wback << 21)
16315 | (reg_mask & 0x0000ffff);
16317 return patched_inst;
16320 static inline bfd_vma
16321 create_instruction_ldmdb (int base_reg, int wback, int reg_mask)
16323 /* A8.8.60 LDMDB/LDMEA (A8-402)
16324 LDMDB Rn!, {Ra, Rb, Rc, ...} (Encoding T1). */
16325 bfd_vma patched_inst = 0xe9100000
16326 | (/*W=*/wback << 21)
16328 | (reg_mask & 0x0000ffff);
16330 return patched_inst;
16333 static inline bfd_vma
16334 create_instruction_mov (int target_reg, int source_reg)
16336 /* A8.8.103 MOV (register) (A8-486)
16337 MOV Rd, Rm (Encoding T1). */
16338 bfd_vma patched_inst = 0x4600
16339 | (target_reg & 0x7)
16340 | ((target_reg & 0x8) >> 3) << 7
16341 | (source_reg << 3);
16343 return patched_inst;
16346 static inline bfd_vma
16347 create_instruction_sub (int target_reg, int source_reg, int value)
16349 /* A8.8.221 SUB (immediate) (A8-708)
16350 SUB Rd, Rn, #value (Encoding T3). */
16351 bfd_vma patched_inst = 0xf1a00000
16352 | (target_reg << 8)
16353 | (source_reg << 16)
16355 | ((value & 0x800) >> 11) << 26
16356 | ((value & 0x700) >> 8) << 12
16359 return patched_inst;
16362 static inline bfd_vma
16363 create_instruction_vldmia (int base_reg, int wback, int num_regs,
16366 /* A8.8.332 VLDM (A8-922)
16367 VLMD{MODE} Rn{!}, {list} (Encoding T2). */
16368 bfd_vma patched_inst = 0xec900a00
16369 | (/*W=*/wback << 21)
16371 | (num_regs & 0x000000ff)
16372 | (((unsigned)first_reg>>1) & 0x0000000f) << 12
16373 | (first_reg & 0x00000001) << 22;
16375 return patched_inst;
16378 static inline bfd_vma
16379 create_instruction_vldmdb (int base_reg, int num_regs, int first_reg)
16381 /* A8.8.332 VLDM (A8-922)
16382 VLMD{MODE} Rn!, {} (Encoding T2). */
16383 bfd_vma patched_inst = 0xed300a00
16385 | (num_regs & 0x000000ff)
16386 | (((unsigned)first_reg>>1) & 0x0000000f) << 12
16387 | (first_reg & 0x00000001) << 22;
16389 return patched_inst;
16392 static inline bfd_vma
16393 create_instruction_udf_w (int value)
16395 /* A8.8.247 UDF (A8-758)
16396 Undefined (Encoding T2). */
16397 bfd_vma patched_inst = 0xf7f0a000
16398 | (value & 0x00000fff)
16399 | (value & 0x000f0000) << 16;
16401 return patched_inst;
16404 static inline bfd_vma
16405 create_instruction_udf (int value)
16407 /* A8.8.247 UDF (A8-758)
16408 Undefined (Encoding T1). */
16409 bfd_vma patched_inst = 0xde00
16412 return patched_inst;
16415 /* Functions writing an instruction in memory, returning the next
16416 memory position to write to. */
16418 static inline bfd_byte *
16419 push_thumb2_insn32 (struct elf32_arm_link_hash_table * htab,
16420 bfd * output_bfd, bfd_byte *pt, insn32 insn)
16422 put_thumb2_insn (htab, output_bfd, insn, pt);
16426 static inline bfd_byte *
16427 push_thumb2_insn16 (struct elf32_arm_link_hash_table * htab,
16428 bfd * output_bfd, bfd_byte *pt, insn32 insn)
16430 put_thumb_insn (htab, output_bfd, insn, pt);
16434 /* Function filling up a region in memory with T1 and T2 UDFs taking
16435 care of alignment. */
16438 stm32l4xx_fill_stub_udf (struct elf32_arm_link_hash_table * htab,
16440 const bfd_byte * const base_stub_contents,
16441 bfd_byte * const from_stub_contents,
16442 const bfd_byte * const end_stub_contents)
16444 bfd_byte *current_stub_contents = from_stub_contents;
16446 /* Fill the remaining of the stub with deterministic contents : UDF
16448 Check if realignment is needed on modulo 4 frontier using T1, to
16450 if ((current_stub_contents < end_stub_contents)
16451 && !((current_stub_contents - base_stub_contents) % 2)
16452 && ((current_stub_contents - base_stub_contents) % 4))
16453 current_stub_contents =
16454 push_thumb2_insn16 (htab, output_bfd, current_stub_contents,
16455 create_instruction_udf (0));
16457 for (; current_stub_contents < end_stub_contents;)
16458 current_stub_contents =
16459 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16460 create_instruction_udf_w (0));
16462 return current_stub_contents;
16465 /* Functions writing the stream of instructions equivalent to the
16466 derived sequence for ldmia, ldmdb, vldm respectively. */
16469 stm32l4xx_create_replacing_stub_ldmia (struct elf32_arm_link_hash_table * htab,
16471 const insn32 initial_insn,
16472 const bfd_byte *const initial_insn_addr,
16473 bfd_byte *const base_stub_contents)
16475 int wback = (initial_insn & 0x00200000) >> 21;
16476 int ri, rn = (initial_insn & 0x000F0000) >> 16;
16477 int insn_all_registers = initial_insn & 0x0000ffff;
16478 int insn_low_registers, insn_high_registers;
16479 int usable_register_mask;
16480 int nb_registers = popcount (insn_all_registers);
16481 int restore_pc = (insn_all_registers & (1 << 15)) ? 1 : 0;
16482 int restore_rn = (insn_all_registers & (1 << rn)) ? 1 : 0;
16483 bfd_byte *current_stub_contents = base_stub_contents;
16485 BFD_ASSERT (is_thumb2_ldmia (initial_insn));
16487 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
16488 smaller than 8 registers load sequences that do not cause the
16490 if (nb_registers <= 8)
16492 /* UNTOUCHED : LDMIA Rn{!}, {R-all-register-list}. */
16493 current_stub_contents =
16494 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16497 /* B initial_insn_addr+4. */
16499 current_stub_contents =
16500 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16501 create_instruction_branch_absolute
16502 (initial_insn_addr - current_stub_contents));
16505 /* Fill the remaining of the stub with deterministic contents. */
16506 current_stub_contents =
16507 stm32l4xx_fill_stub_udf (htab, output_bfd,
16508 base_stub_contents, current_stub_contents,
16509 base_stub_contents +
16510 STM32L4XX_ERRATUM_LDM_VENEER_SIZE);
16515 /* - reg_list[13] == 0. */
16516 BFD_ASSERT ((insn_all_registers & (1 << 13))==0);
16518 /* - reg_list[14] & reg_list[15] != 1. */
16519 BFD_ASSERT ((insn_all_registers & 0xC000) != 0xC000);
16521 /* - if (wback==1) reg_list[rn] == 0. */
16522 BFD_ASSERT (!wback || !restore_rn);
16524 /* - nb_registers > 8. */
16525 BFD_ASSERT (popcount (insn_all_registers) > 8);
16527 /* At this point, LDMxx initial insn loads between 9 and 14 registers. */
16529 /* In the following algorithm, we split this wide LDM using 2 LDM insns:
16530 - One with the 7 lowest registers (register mask 0x007F)
16531 This LDM will finally contain between 2 and 7 registers
16532 - One with the 7 highest registers (register mask 0xDF80)
16533 This ldm will finally contain between 2 and 7 registers. */
16534 insn_low_registers = insn_all_registers & 0x007F;
16535 insn_high_registers = insn_all_registers & 0xDF80;
16537 /* A spare register may be needed during this veneer to temporarily
16538 handle the base register. This register will be restored with the
16539 last LDM operation.
16540 The usable register may be any general purpose register (that
16541 excludes PC, SP, LR : register mask is 0x1FFF). */
16542 usable_register_mask = 0x1FFF;
16544 /* Generate the stub function. */
16547 /* LDMIA Rn!, {R-low-register-list} : (Encoding T2). */
16548 current_stub_contents =
16549 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16550 create_instruction_ldmia
16551 (rn, /*wback=*/1, insn_low_registers));
16553 /* LDMIA Rn!, {R-high-register-list} : (Encoding T2). */
16554 current_stub_contents =
16555 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16556 create_instruction_ldmia
16557 (rn, /*wback=*/1, insn_high_registers));
16560 /* B initial_insn_addr+4. */
16561 current_stub_contents =
16562 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16563 create_instruction_branch_absolute
16564 (initial_insn_addr - current_stub_contents));
16567 else /* if (!wback). */
16571 /* If Rn is not part of the high-register-list, move it there. */
16572 if (!(insn_high_registers & (1 << rn)))
16574 /* Choose a Ri in the high-register-list that will be restored. */
16575 ri = ctz (insn_high_registers & usable_register_mask & ~(1 << rn));
16578 current_stub_contents =
16579 push_thumb2_insn16 (htab, output_bfd, current_stub_contents,
16580 create_instruction_mov (ri, rn));
16583 /* LDMIA Ri!, {R-low-register-list} : (Encoding T2). */
16584 current_stub_contents =
16585 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16586 create_instruction_ldmia
16587 (ri, /*wback=*/1, insn_low_registers));
16589 /* LDMIA Ri, {R-high-register-list} : (Encoding T2). */
16590 current_stub_contents =
16591 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16592 create_instruction_ldmia
16593 (ri, /*wback=*/0, insn_high_registers));
16597 /* B initial_insn_addr+4. */
16598 current_stub_contents =
16599 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16600 create_instruction_branch_absolute
16601 (initial_insn_addr - current_stub_contents));
16605 /* Fill the remaining of the stub with deterministic contents. */
16606 current_stub_contents =
16607 stm32l4xx_fill_stub_udf (htab, output_bfd,
16608 base_stub_contents, current_stub_contents,
16609 base_stub_contents +
16610 STM32L4XX_ERRATUM_LDM_VENEER_SIZE);
16614 stm32l4xx_create_replacing_stub_ldmdb (struct elf32_arm_link_hash_table * htab,
16616 const insn32 initial_insn,
16617 const bfd_byte *const initial_insn_addr,
16618 bfd_byte *const base_stub_contents)
16620 int wback = (initial_insn & 0x00200000) >> 21;
16621 int ri, rn = (initial_insn & 0x000f0000) >> 16;
16622 int insn_all_registers = initial_insn & 0x0000ffff;
16623 int insn_low_registers, insn_high_registers;
16624 int usable_register_mask;
16625 int restore_pc = (insn_all_registers & (1 << 15)) ? 1 : 0;
16626 int restore_rn = (insn_all_registers & (1 << rn)) ? 1 : 0;
16627 int nb_registers = popcount (insn_all_registers);
16628 bfd_byte *current_stub_contents = base_stub_contents;
16630 BFD_ASSERT (is_thumb2_ldmdb (initial_insn));
16632 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
16633 smaller than 8 registers load sequences that do not cause the
16635 if (nb_registers <= 8)
16637 /* UNTOUCHED : LDMIA Rn{!}, {R-all-register-list}. */
16638 current_stub_contents =
16639 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16642 /* B initial_insn_addr+4. */
16643 current_stub_contents =
16644 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16645 create_instruction_branch_absolute
16646 (initial_insn_addr - current_stub_contents));
16648 /* Fill the remaining of the stub with deterministic contents. */
16649 current_stub_contents =
16650 stm32l4xx_fill_stub_udf (htab, output_bfd,
16651 base_stub_contents, current_stub_contents,
16652 base_stub_contents +
16653 STM32L4XX_ERRATUM_LDM_VENEER_SIZE);
16658 /* - reg_list[13] == 0. */
16659 BFD_ASSERT ((insn_all_registers & (1 << 13)) == 0);
16661 /* - reg_list[14] & reg_list[15] != 1. */
16662 BFD_ASSERT ((insn_all_registers & 0xC000) != 0xC000);
16664 /* - if (wback==1) reg_list[rn] == 0. */
16665 BFD_ASSERT (!wback || !restore_rn);
16667 /* - nb_registers > 8. */
16668 BFD_ASSERT (popcount (insn_all_registers) > 8);
16670 /* At this point, LDMxx initial insn loads between 9 and 14 registers. */
16672 /* In the following algorithm, we split this wide LDM using 2 LDM insn:
16673 - One with the 7 lowest registers (register mask 0x007F)
16674 This LDM will finally contain between 2 and 7 registers
16675 - One with the 7 highest registers (register mask 0xDF80)
16676 This ldm will finally contain between 2 and 7 registers. */
16677 insn_low_registers = insn_all_registers & 0x007F;
16678 insn_high_registers = insn_all_registers & 0xDF80;
16680 /* A spare register may be needed during this veneer to temporarily
16681 handle the base register. This register will be restored with
16682 the last LDM operation.
16683 The usable register may be any general purpose register (that excludes
16684 PC, SP, LR : register mask is 0x1FFF). */
16685 usable_register_mask = 0x1FFF;
16687 /* Generate the stub function. */
16688 if (!wback && !restore_pc && !restore_rn)
16690 /* Choose a Ri in the low-register-list that will be restored. */
16691 ri = ctz (insn_low_registers & usable_register_mask & ~(1 << rn));
16694 current_stub_contents =
16695 push_thumb2_insn16 (htab, output_bfd, current_stub_contents,
16696 create_instruction_mov (ri, rn));
16698 /* LDMDB Ri!, {R-high-register-list}. */
16699 current_stub_contents =
16700 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16701 create_instruction_ldmdb
16702 (ri, /*wback=*/1, insn_high_registers));
16704 /* LDMDB Ri, {R-low-register-list}. */
16705 current_stub_contents =
16706 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16707 create_instruction_ldmdb
16708 (ri, /*wback=*/0, insn_low_registers));
16710 /* B initial_insn_addr+4. */
16711 current_stub_contents =
16712 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16713 create_instruction_branch_absolute
16714 (initial_insn_addr - current_stub_contents));
16716 else if (wback && !restore_pc && !restore_rn)
16718 /* LDMDB Rn!, {R-high-register-list}. */
16719 current_stub_contents =
16720 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16721 create_instruction_ldmdb
16722 (rn, /*wback=*/1, insn_high_registers));
16724 /* LDMDB Rn!, {R-low-register-list}. */
16725 current_stub_contents =
16726 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16727 create_instruction_ldmdb
16728 (rn, /*wback=*/1, insn_low_registers));
16730 /* B initial_insn_addr+4. */
16731 current_stub_contents =
16732 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16733 create_instruction_branch_absolute
16734 (initial_insn_addr - current_stub_contents));
16736 else if (!wback && restore_pc && !restore_rn)
16738 /* Choose a Ri in the high-register-list that will be restored. */
16739 ri = ctz (insn_high_registers & usable_register_mask & ~(1 << rn));
16741 /* SUB Ri, Rn, #(4*nb_registers). */
16742 current_stub_contents =
16743 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16744 create_instruction_sub (ri, rn, (4 * nb_registers)));
16746 /* LDMIA Ri!, {R-low-register-list}. */
16747 current_stub_contents =
16748 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16749 create_instruction_ldmia
16750 (ri, /*wback=*/1, insn_low_registers));
16752 /* LDMIA Ri, {R-high-register-list}. */
16753 current_stub_contents =
16754 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16755 create_instruction_ldmia
16756 (ri, /*wback=*/0, insn_high_registers));
16758 else if (wback && restore_pc && !restore_rn)
16760 /* Choose a Ri in the high-register-list that will be restored. */
16761 ri = ctz (insn_high_registers & usable_register_mask & ~(1 << rn));
16763 /* SUB Rn, Rn, #(4*nb_registers) */
16764 current_stub_contents =
16765 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16766 create_instruction_sub (rn, rn, (4 * nb_registers)));
16769 current_stub_contents =
16770 push_thumb2_insn16 (htab, output_bfd, current_stub_contents,
16771 create_instruction_mov (ri, rn));
16773 /* LDMIA Ri!, {R-low-register-list}. */
16774 current_stub_contents =
16775 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16776 create_instruction_ldmia
16777 (ri, /*wback=*/1, insn_low_registers));
16779 /* LDMIA Ri, {R-high-register-list}. */
16780 current_stub_contents =
16781 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16782 create_instruction_ldmia
16783 (ri, /*wback=*/0, insn_high_registers));
16785 else if (!wback && !restore_pc && restore_rn)
16788 if (!(insn_low_registers & (1 << rn)))
16790 /* Choose a Ri in the low-register-list that will be restored. */
16791 ri = ctz (insn_low_registers & usable_register_mask & ~(1 << rn));
16794 current_stub_contents =
16795 push_thumb2_insn16 (htab, output_bfd, current_stub_contents,
16796 create_instruction_mov (ri, rn));
16799 /* LDMDB Ri!, {R-high-register-list}. */
16800 current_stub_contents =
16801 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16802 create_instruction_ldmdb
16803 (ri, /*wback=*/1, insn_high_registers));
16805 /* LDMDB Ri, {R-low-register-list}. */
16806 current_stub_contents =
16807 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16808 create_instruction_ldmdb
16809 (ri, /*wback=*/0, insn_low_registers));
16811 /* B initial_insn_addr+4. */
16812 current_stub_contents =
16813 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16814 create_instruction_branch_absolute
16815 (initial_insn_addr - current_stub_contents));
16817 else if (!wback && restore_pc && restore_rn)
16820 if (!(insn_high_registers & (1 << rn)))
16822 /* Choose a Ri in the high-register-list that will be restored. */
16823 ri = ctz (insn_high_registers & usable_register_mask & ~(1 << rn));
16826 /* SUB Ri, Rn, #(4*nb_registers). */
16827 current_stub_contents =
16828 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16829 create_instruction_sub (ri, rn, (4 * nb_registers)));
16831 /* LDMIA Ri!, {R-low-register-list}. */
16832 current_stub_contents =
16833 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16834 create_instruction_ldmia
16835 (ri, /*wback=*/1, insn_low_registers));
16837 /* LDMIA Ri, {R-high-register-list}. */
16838 current_stub_contents =
16839 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16840 create_instruction_ldmia
16841 (ri, /*wback=*/0, insn_high_registers));
16843 else if (wback && restore_rn)
16845 /* The assembler should not have accepted to encode this. */
16846 BFD_ASSERT (0 && "Cannot patch an instruction that has an "
16847 "undefined behavior.\n");
16850 /* Fill the remaining of the stub with deterministic contents. */
16851 current_stub_contents =
16852 stm32l4xx_fill_stub_udf (htab, output_bfd,
16853 base_stub_contents, current_stub_contents,
16854 base_stub_contents +
16855 STM32L4XX_ERRATUM_LDM_VENEER_SIZE);
16860 stm32l4xx_create_replacing_stub_vldm (struct elf32_arm_link_hash_table * htab,
16862 const insn32 initial_insn,
16863 const bfd_byte *const initial_insn_addr,
16864 bfd_byte *const base_stub_contents)
16866 int num_regs = ((unsigned int)initial_insn << 24) >> 24;
16867 bfd_byte *current_stub_contents = base_stub_contents;
16869 BFD_ASSERT (is_thumb2_vldm (initial_insn));
16871 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
16872 smaller than 8 registers load sequences that do not cause the
16876 /* Untouched instruction. */
16877 current_stub_contents =
16878 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16881 /* B initial_insn_addr+4. */
16882 current_stub_contents =
16883 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16884 create_instruction_branch_absolute
16885 (initial_insn_addr - current_stub_contents));
16889 bfd_boolean is_ia_nobang = /* (IA without !). */
16890 (((initial_insn << 7) >> 28) & 0xd) == 0x4;
16891 bfd_boolean is_ia_bang = /* (IA with !) - includes VPOP. */
16892 (((initial_insn << 7) >> 28) & 0xd) == 0x5;
16893 bfd_boolean is_db_bang = /* (DB with !). */
16894 (((initial_insn << 7) >> 28) & 0xd) == 0x9;
16895 int base_reg = ((unsigned int)initial_insn << 12) >> 28;
16896 /* d = UInt (Vd:D);. */
16897 int first_reg = ((((unsigned int)initial_insn << 16) >> 28) << 1)
16898 | (((unsigned int)initial_insn << 9) >> 31);
16900 /* Compute the number of 8-register chunks needed to split. */
16901 int chunks = (num_regs%8) ? (num_regs/8 + 1) : (num_regs/8);
16904 /* The test coverage has been done assuming the following
16905 hypothesis that exactly one of the previous is_ predicates is
16907 BFD_ASSERT ((is_ia_nobang ^ is_ia_bang ^ is_db_bang) &&
16908 !(is_ia_nobang & is_ia_bang & is_db_bang));
16910 /* We treat the cutting of the register in one pass for all
16911 cases, then we emit the adjustments:
16914 -> vldm rx!, {8_words_or_less} for each needed 8_word
16915 -> sub rx, rx, #size (list)
16918 -> vldm rx!, {8_words_or_less} for each needed 8_word
16919 This also handles vpop instruction (when rx is sp)
16922 -> vldmb rx!, {8_words_or_less} for each needed 8_word. */
16923 for (chunk = 0; chunk<chunks; ++chunk)
16925 if (is_ia_nobang || is_ia_bang)
16927 current_stub_contents =
16928 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16929 create_instruction_vldmia
16932 chunks - (chunk + 1) ?
16933 8 : num_regs - chunk * 8,
16934 first_reg + chunk * 8));
16936 else if (is_db_bang)
16938 current_stub_contents =
16939 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16940 create_instruction_vldmdb
16942 chunks - (chunk + 1) ?
16943 8 : num_regs - chunk * 8,
16944 first_reg + chunk * 8));
16948 /* Only this case requires the base register compensation
16952 current_stub_contents =
16953 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16954 create_instruction_sub
16955 (base_reg, base_reg, 4*num_regs));
16958 /* B initial_insn_addr+4. */
16959 current_stub_contents =
16960 push_thumb2_insn32 (htab, output_bfd, current_stub_contents,
16961 create_instruction_branch_absolute
16962 (initial_insn_addr - current_stub_contents));
16965 /* Fill the remaining of the stub with deterministic contents. */
16966 current_stub_contents =
16967 stm32l4xx_fill_stub_udf (htab, output_bfd,
16968 base_stub_contents, current_stub_contents,
16969 base_stub_contents +
16970 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE);
16974 stm32l4xx_create_replacing_stub (struct elf32_arm_link_hash_table * htab,
16976 const insn32 wrong_insn,
16977 const bfd_byte *const wrong_insn_addr,
16978 bfd_byte *const stub_contents)
16980 if (is_thumb2_ldmia (wrong_insn))
16981 stm32l4xx_create_replacing_stub_ldmia (htab, output_bfd,
16982 wrong_insn, wrong_insn_addr,
16984 else if (is_thumb2_ldmdb (wrong_insn))
16985 stm32l4xx_create_replacing_stub_ldmdb (htab, output_bfd,
16986 wrong_insn, wrong_insn_addr,
16988 else if (is_thumb2_vldm (wrong_insn))
16989 stm32l4xx_create_replacing_stub_vldm (htab, output_bfd,
16990 wrong_insn, wrong_insn_addr,
16994 /* End of stm32l4xx work-around. */
16998 elf32_arm_add_relocation (bfd *output_bfd, struct bfd_link_info *info,
16999 asection *output_sec, Elf_Internal_Rela *rel)
17001 BFD_ASSERT (output_sec && rel);
17002 struct bfd_elf_section_reloc_data *output_reldata;
17003 struct elf32_arm_link_hash_table *htab;
17004 struct bfd_elf_section_data *oesd = elf_section_data (output_sec);
17005 Elf_Internal_Shdr *rel_hdr;
17010 rel_hdr = oesd->rel.hdr;
17011 output_reldata = &(oesd->rel);
17013 else if (oesd->rela.hdr)
17015 rel_hdr = oesd->rela.hdr;
17016 output_reldata = &(oesd->rela);
17023 bfd_byte *erel = rel_hdr->contents;
17024 erel += output_reldata->count * rel_hdr->sh_entsize;
17025 htab = elf32_arm_hash_table (info);
17026 SWAP_RELOC_OUT (htab) (output_bfd, rel, erel);
17027 output_reldata->count++;
17030 /* Do code byteswapping. Return FALSE afterwards so that the section is
17031 written out as normal. */
17034 elf32_arm_write_section (bfd *output_bfd,
17035 struct bfd_link_info *link_info,
17037 bfd_byte *contents)
17039 unsigned int mapcount, errcount;
17040 _arm_elf_section_data *arm_data;
17041 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
17042 elf32_arm_section_map *map;
17043 elf32_vfp11_erratum_list *errnode;
17044 elf32_stm32l4xx_erratum_list *stm32l4xx_errnode;
17047 bfd_vma offset = sec->output_section->vma + sec->output_offset;
17051 if (globals == NULL)
17054 /* If this section has not been allocated an _arm_elf_section_data
17055 structure then we cannot record anything. */
17056 arm_data = get_arm_elf_section_data (sec);
17057 if (arm_data == NULL)
17060 mapcount = arm_data->mapcount;
17061 map = arm_data->map;
17062 errcount = arm_data->erratumcount;
17066 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
17068 for (errnode = arm_data->erratumlist; errnode != 0;
17069 errnode = errnode->next)
17071 bfd_vma target = errnode->vma - offset;
17073 switch (errnode->type)
17075 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
17077 bfd_vma branch_to_veneer;
17078 /* Original condition code of instruction, plus bit mask for
17079 ARM B instruction. */
17080 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
17083 /* The instruction is before the label. */
17086 /* Above offset included in -4 below. */
17087 branch_to_veneer = errnode->u.b.veneer->vma
17088 - errnode->vma - 4;
17090 if ((signed) branch_to_veneer < -(1 << 25)
17091 || (signed) branch_to_veneer >= (1 << 25))
17092 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
17093 "range"), output_bfd);
17095 insn |= (branch_to_veneer >> 2) & 0xffffff;
17096 contents[endianflip ^ target] = insn & 0xff;
17097 contents[endianflip ^ (target + 1)] = (insn >> 8) & 0xff;
17098 contents[endianflip ^ (target + 2)] = (insn >> 16) & 0xff;
17099 contents[endianflip ^ (target + 3)] = (insn >> 24) & 0xff;
17103 case VFP11_ERRATUM_ARM_VENEER:
17105 bfd_vma branch_from_veneer;
17108 /* Take size of veneer into account. */
17109 branch_from_veneer = errnode->u.v.branch->vma
17110 - errnode->vma - 12;
17112 if ((signed) branch_from_veneer < -(1 << 25)
17113 || (signed) branch_from_veneer >= (1 << 25))
17114 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
17115 "range"), output_bfd);
17117 /* Original instruction. */
17118 insn = errnode->u.v.branch->u.b.vfp_insn;
17119 contents[endianflip ^ target] = insn & 0xff;
17120 contents[endianflip ^ (target + 1)] = (insn >> 8) & 0xff;
17121 contents[endianflip ^ (target + 2)] = (insn >> 16) & 0xff;
17122 contents[endianflip ^ (target + 3)] = (insn >> 24) & 0xff;
17124 /* Branch back to insn after original insn. */
17125 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
17126 contents[endianflip ^ (target + 4)] = insn & 0xff;
17127 contents[endianflip ^ (target + 5)] = (insn >> 8) & 0xff;
17128 contents[endianflip ^ (target + 6)] = (insn >> 16) & 0xff;
17129 contents[endianflip ^ (target + 7)] = (insn >> 24) & 0xff;
17139 if (arm_data->stm32l4xx_erratumcount != 0)
17141 for (stm32l4xx_errnode = arm_data->stm32l4xx_erratumlist;
17142 stm32l4xx_errnode != 0;
17143 stm32l4xx_errnode = stm32l4xx_errnode->next)
17145 bfd_vma target = stm32l4xx_errnode->vma - offset;
17147 switch (stm32l4xx_errnode->type)
17149 case STM32L4XX_ERRATUM_BRANCH_TO_VENEER:
17152 bfd_vma branch_to_veneer =
17153 stm32l4xx_errnode->u.b.veneer->vma - stm32l4xx_errnode->vma;
17155 if ((signed) branch_to_veneer < -(1 << 24)
17156 || (signed) branch_to_veneer >= (1 << 24))
17158 bfd_vma out_of_range =
17159 ((signed) branch_to_veneer < -(1 << 24)) ?
17160 - branch_to_veneer - (1 << 24) :
17161 ((signed) branch_to_veneer >= (1 << 24)) ?
17162 branch_to_veneer - (1 << 24) : 0;
17164 (*_bfd_error_handler)
17165 (_("%B(%#x): error: Cannot create STM32L4XX veneer. "
17166 "Jump out of range by %ld bytes. "
17167 "Cannot encode branch instruction. "),
17169 (long) (stm32l4xx_errnode->vma - 4),
17174 insn = create_instruction_branch_absolute
17175 (stm32l4xx_errnode->u.b.veneer->vma - stm32l4xx_errnode->vma);
17177 /* The instruction is before the label. */
17180 put_thumb2_insn (globals, output_bfd,
17181 (bfd_vma) insn, contents + target);
17185 case STM32L4XX_ERRATUM_VENEER:
17188 bfd_byte * veneer_r;
17191 veneer = contents + target;
17193 + stm32l4xx_errnode->u.b.veneer->vma
17194 - stm32l4xx_errnode->vma - 4;
17196 if ((signed) (veneer_r - veneer -
17197 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE >
17198 STM32L4XX_ERRATUM_LDM_VENEER_SIZE ?
17199 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE :
17200 STM32L4XX_ERRATUM_LDM_VENEER_SIZE) < -(1 << 24)
17201 || (signed) (veneer_r - veneer) >= (1 << 24))
17203 (*_bfd_error_handler) (_("%B: error: Cannot create STM32L4XX "
17204 "veneer."), output_bfd);
17208 /* Original instruction. */
17209 insn = stm32l4xx_errnode->u.v.branch->u.b.insn;
17211 stm32l4xx_create_replacing_stub
17212 (globals, output_bfd, insn, (void*)veneer_r, (void*)veneer);
17222 if (arm_data->elf.this_hdr.sh_type == SHT_ARM_EXIDX)
17224 arm_unwind_table_edit *edit_node
17225 = arm_data->u.exidx.unwind_edit_list;
17226 /* Now, sec->size is the size of the section we will write. The original
17227 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
17228 markers) was sec->rawsize. (This isn't the case if we perform no
17229 edits, then rawsize will be zero and we should use size). */
17230 bfd_byte *edited_contents = (bfd_byte *) bfd_malloc (sec->size);
17231 unsigned int input_size = sec->rawsize ? sec->rawsize : sec->size;
17232 unsigned int in_index, out_index;
17233 bfd_vma add_to_offsets = 0;
17235 for (in_index = 0, out_index = 0; in_index * 8 < input_size || edit_node;)
17239 unsigned int edit_index = edit_node->index;
17241 if (in_index < edit_index && in_index * 8 < input_size)
17243 copy_exidx_entry (output_bfd, edited_contents + out_index * 8,
17244 contents + in_index * 8, add_to_offsets);
17248 else if (in_index == edit_index
17249 || (in_index * 8 >= input_size
17250 && edit_index == UINT_MAX))
17252 switch (edit_node->type)
17254 case DELETE_EXIDX_ENTRY:
17256 add_to_offsets += 8;
17259 case INSERT_EXIDX_CANTUNWIND_AT_END:
17261 asection *text_sec = edit_node->linked_section;
17262 bfd_vma text_offset = text_sec->output_section->vma
17263 + text_sec->output_offset
17265 bfd_vma exidx_offset = offset + out_index * 8;
17266 unsigned long prel31_offset;
17268 /* Note: this is meant to be equivalent to an
17269 R_ARM_PREL31 relocation. These synthetic
17270 EXIDX_CANTUNWIND markers are not relocated by the
17271 usual BFD method. */
17272 prel31_offset = (text_offset - exidx_offset)
17274 if (bfd_link_relocatable (link_info))
17276 /* Here relocation for new EXIDX_CANTUNWIND is
17277 created, so there is no need to
17278 adjust offset by hand. */
17279 prel31_offset = text_sec->output_offset
17282 /* New relocation entity. */
17283 asection *text_out = text_sec->output_section;
17284 Elf_Internal_Rela rel;
17286 rel.r_offset = exidx_offset;
17287 rel.r_info = ELF32_R_INFO (text_out->target_index,
17290 elf32_arm_add_relocation (output_bfd, link_info,
17291 sec->output_section,
17295 /* First address we can't unwind. */
17296 bfd_put_32 (output_bfd, prel31_offset,
17297 &edited_contents[out_index * 8]);
17299 /* Code for EXIDX_CANTUNWIND. */
17300 bfd_put_32 (output_bfd, 0x1,
17301 &edited_contents[out_index * 8 + 4]);
17304 add_to_offsets -= 8;
17309 edit_node = edit_node->next;
17314 /* No more edits, copy remaining entries verbatim. */
17315 copy_exidx_entry (output_bfd, edited_contents + out_index * 8,
17316 contents + in_index * 8, add_to_offsets);
17322 if (!(sec->flags & SEC_EXCLUDE) && !(sec->flags & SEC_NEVER_LOAD))
17323 bfd_set_section_contents (output_bfd, sec->output_section,
17325 (file_ptr) sec->output_offset, sec->size);
17330 /* Fix code to point to Cortex-A8 erratum stubs. */
17331 if (globals->fix_cortex_a8)
17333 struct a8_branch_to_stub_data data;
17335 data.writing_section = sec;
17336 data.contents = contents;
17338 bfd_hash_traverse (& globals->stub_hash_table, make_branch_to_a8_stub,
17345 if (globals->byteswap_code)
17347 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
17350 for (i = 0; i < mapcount; i++)
17352 if (i == mapcount - 1)
17355 end = map[i + 1].vma;
17357 switch (map[i].type)
17360 /* Byte swap code words. */
17361 while (ptr + 3 < end)
17363 tmp = contents[ptr];
17364 contents[ptr] = contents[ptr + 3];
17365 contents[ptr + 3] = tmp;
17366 tmp = contents[ptr + 1];
17367 contents[ptr + 1] = contents[ptr + 2];
17368 contents[ptr + 2] = tmp;
17374 /* Byte swap code halfwords. */
17375 while (ptr + 1 < end)
17377 tmp = contents[ptr];
17378 contents[ptr] = contents[ptr + 1];
17379 contents[ptr + 1] = tmp;
17385 /* Leave data alone. */
17393 arm_data->mapcount = -1;
17394 arm_data->mapsize = 0;
17395 arm_data->map = NULL;
17400 /* Mangle thumb function symbols as we read them in. */
17403 elf32_arm_swap_symbol_in (bfd * abfd,
17406 Elf_Internal_Sym *dst)
17408 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
17411 /* New EABI objects mark thumb function symbols by setting the low bit of
17413 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
17414 || ELF_ST_TYPE (dst->st_info) == STT_GNU_IFUNC)
17416 if (dst->st_value & 1)
17418 dst->st_value &= ~(bfd_vma) 1;
17419 dst->st_target_internal = ST_BRANCH_TO_THUMB;
17422 dst->st_target_internal = ST_BRANCH_TO_ARM;
17424 else if (ELF_ST_TYPE (dst->st_info) == STT_ARM_TFUNC)
17426 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_FUNC);
17427 dst->st_target_internal = ST_BRANCH_TO_THUMB;
17429 else if (ELF_ST_TYPE (dst->st_info) == STT_SECTION)
17430 dst->st_target_internal = ST_BRANCH_LONG;
17432 dst->st_target_internal = ST_BRANCH_UNKNOWN;
17438 /* Mangle thumb function symbols as we write them out. */
17441 elf32_arm_swap_symbol_out (bfd *abfd,
17442 const Elf_Internal_Sym *src,
17446 Elf_Internal_Sym newsym;
17448 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
17449 of the address set, as per the new EABI. We do this unconditionally
17450 because objcopy does not set the elf header flags until after
17451 it writes out the symbol table. */
17452 if (src->st_target_internal == ST_BRANCH_TO_THUMB)
17455 if (ELF_ST_TYPE (src->st_info) != STT_GNU_IFUNC)
17456 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
17457 if (newsym.st_shndx != SHN_UNDEF)
17459 /* Do this only for defined symbols. At link type, the static
17460 linker will simulate the work of dynamic linker of resolving
17461 symbols and will carry over the thumbness of found symbols to
17462 the output symbol table. It's not clear how it happens, but
17463 the thumbness of undefined symbols can well be different at
17464 runtime, and writing '1' for them will be confusing for users
17465 and possibly for dynamic linker itself.
17467 newsym.st_value |= 1;
17472 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
17475 /* Add the PT_ARM_EXIDX program header. */
17478 elf32_arm_modify_segment_map (bfd *abfd,
17479 struct bfd_link_info *info ATTRIBUTE_UNUSED)
17481 struct elf_segment_map *m;
17484 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
17485 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
17487 /* If there is already a PT_ARM_EXIDX header, then we do not
17488 want to add another one. This situation arises when running
17489 "strip"; the input binary already has the header. */
17490 m = elf_seg_map (abfd);
17491 while (m && m->p_type != PT_ARM_EXIDX)
17495 m = (struct elf_segment_map *)
17496 bfd_zalloc (abfd, sizeof (struct elf_segment_map));
17499 m->p_type = PT_ARM_EXIDX;
17501 m->sections[0] = sec;
17503 m->next = elf_seg_map (abfd);
17504 elf_seg_map (abfd) = m;
17511 /* We may add a PT_ARM_EXIDX program header. */
17514 elf32_arm_additional_program_headers (bfd *abfd,
17515 struct bfd_link_info *info ATTRIBUTE_UNUSED)
17519 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
17520 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
17526 /* Hook called by the linker routine which adds symbols from an object
17530 elf32_arm_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
17531 Elf_Internal_Sym *sym, const char **namep,
17532 flagword *flagsp, asection **secp, bfd_vma *valp)
17534 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
17535 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
17536 && (abfd->flags & DYNAMIC) == 0
17537 && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
17538 elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
17540 if (elf32_arm_hash_table (info) == NULL)
17543 if (elf32_arm_hash_table (info)->vxworks_p
17544 && !elf_vxworks_add_symbol_hook (abfd, info, sym, namep,
17545 flagsp, secp, valp))
17551 /* We use this to override swap_symbol_in and swap_symbol_out. */
17552 const struct elf_size_info elf32_arm_size_info =
17554 sizeof (Elf32_External_Ehdr),
17555 sizeof (Elf32_External_Phdr),
17556 sizeof (Elf32_External_Shdr),
17557 sizeof (Elf32_External_Rel),
17558 sizeof (Elf32_External_Rela),
17559 sizeof (Elf32_External_Sym),
17560 sizeof (Elf32_External_Dyn),
17561 sizeof (Elf_External_Note),
17565 ELFCLASS32, EV_CURRENT,
17566 bfd_elf32_write_out_phdrs,
17567 bfd_elf32_write_shdrs_and_ehdr,
17568 bfd_elf32_checksum_contents,
17569 bfd_elf32_write_relocs,
17570 elf32_arm_swap_symbol_in,
17571 elf32_arm_swap_symbol_out,
17572 bfd_elf32_slurp_reloc_table,
17573 bfd_elf32_slurp_symbol_table,
17574 bfd_elf32_swap_dyn_in,
17575 bfd_elf32_swap_dyn_out,
17576 bfd_elf32_swap_reloc_in,
17577 bfd_elf32_swap_reloc_out,
17578 bfd_elf32_swap_reloca_in,
17579 bfd_elf32_swap_reloca_out
17583 read_code32 (const bfd *abfd, const bfd_byte *addr)
17585 /* V7 BE8 code is always little endian. */
17586 if ((elf_elfheader (abfd)->e_flags & EF_ARM_BE8) != 0)
17587 return bfd_getl32 (addr);
17589 return bfd_get_32 (abfd, addr);
17593 read_code16 (const bfd *abfd, const bfd_byte *addr)
17595 /* V7 BE8 code is always little endian. */
17596 if ((elf_elfheader (abfd)->e_flags & EF_ARM_BE8) != 0)
17597 return bfd_getl16 (addr);
17599 return bfd_get_16 (abfd, addr);
17602 /* Return size of plt0 entry starting at ADDR
17603 or (bfd_vma) -1 if size can not be determined. */
17606 elf32_arm_plt0_size (const bfd *abfd, const bfd_byte *addr)
17608 bfd_vma first_word;
17611 first_word = read_code32 (abfd, addr);
17613 if (first_word == elf32_arm_plt0_entry[0])
17614 plt0_size = 4 * ARRAY_SIZE (elf32_arm_plt0_entry);
17615 else if (first_word == elf32_thumb2_plt0_entry[0])
17616 plt0_size = 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry);
17618 /* We don't yet handle this PLT format. */
17619 return (bfd_vma) -1;
17624 /* Return size of plt entry starting at offset OFFSET
17625 of plt section located at address START
17626 or (bfd_vma) -1 if size can not be determined. */
17629 elf32_arm_plt_size (const bfd *abfd, const bfd_byte *start, bfd_vma offset)
17631 bfd_vma first_insn;
17632 bfd_vma plt_size = 0;
17633 const bfd_byte *addr = start + offset;
17635 /* PLT entry size if fixed on Thumb-only platforms. */
17636 if (read_code32 (abfd, start) == elf32_thumb2_plt0_entry[0])
17637 return 4 * ARRAY_SIZE (elf32_thumb2_plt_entry);
17639 /* Respect Thumb stub if necessary. */
17640 if (read_code16 (abfd, addr) == elf32_arm_plt_thumb_stub[0])
17642 plt_size += 2 * ARRAY_SIZE(elf32_arm_plt_thumb_stub);
17645 /* Strip immediate from first add. */
17646 first_insn = read_code32 (abfd, addr + plt_size) & 0xffffff00;
17648 #ifdef FOUR_WORD_PLT
17649 if (first_insn == elf32_arm_plt_entry[0])
17650 plt_size += 4 * ARRAY_SIZE (elf32_arm_plt_entry);
17652 if (first_insn == elf32_arm_plt_entry_long[0])
17653 plt_size += 4 * ARRAY_SIZE (elf32_arm_plt_entry_long);
17654 else if (first_insn == elf32_arm_plt_entry_short[0])
17655 plt_size += 4 * ARRAY_SIZE (elf32_arm_plt_entry_short);
17658 /* We don't yet handle this PLT format. */
17659 return (bfd_vma) -1;
17664 /* Implementation is shamelessly borrowed from _bfd_elf_get_synthetic_symtab. */
17667 elf32_arm_get_synthetic_symtab (bfd *abfd,
17668 long symcount ATTRIBUTE_UNUSED,
17669 asymbol **syms ATTRIBUTE_UNUSED,
17679 Elf_Internal_Shdr *hdr;
17687 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
17690 if (dynsymcount <= 0)
17693 relplt = bfd_get_section_by_name (abfd, ".rel.plt");
17694 if (relplt == NULL)
17697 hdr = &elf_section_data (relplt)->this_hdr;
17698 if (hdr->sh_link != elf_dynsymtab (abfd)
17699 || (hdr->sh_type != SHT_REL && hdr->sh_type != SHT_RELA))
17702 plt = bfd_get_section_by_name (abfd, ".plt");
17706 if (!elf32_arm_size_info.slurp_reloc_table (abfd, relplt, dynsyms, TRUE))
17709 data = plt->contents;
17712 if (!bfd_get_full_section_contents(abfd, (asection *) plt, &data) || data == NULL)
17714 bfd_cache_section_contents((asection *) plt, data);
17717 count = relplt->size / hdr->sh_entsize;
17718 size = count * sizeof (asymbol);
17719 p = relplt->relocation;
17720 for (i = 0; i < count; i++, p += elf32_arm_size_info.int_rels_per_ext_rel)
17722 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
17723 if (p->addend != 0)
17724 size += sizeof ("+0x") - 1 + 8;
17727 s = *ret = (asymbol *) bfd_malloc (size);
17731 offset = elf32_arm_plt0_size (abfd, data);
17732 if (offset == (bfd_vma) -1)
17735 names = (char *) (s + count);
17736 p = relplt->relocation;
17738 for (i = 0; i < count; i++, p += elf32_arm_size_info.int_rels_per_ext_rel)
17742 bfd_vma plt_size = elf32_arm_plt_size (abfd, data, offset);
17743 if (plt_size == (bfd_vma) -1)
17746 *s = **p->sym_ptr_ptr;
17747 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
17748 we are defining a symbol, ensure one of them is set. */
17749 if ((s->flags & BSF_LOCAL) == 0)
17750 s->flags |= BSF_GLOBAL;
17751 s->flags |= BSF_SYNTHETIC;
17756 len = strlen ((*p->sym_ptr_ptr)->name);
17757 memcpy (names, (*p->sym_ptr_ptr)->name, len);
17759 if (p->addend != 0)
17763 memcpy (names, "+0x", sizeof ("+0x") - 1);
17764 names += sizeof ("+0x") - 1;
17765 bfd_sprintf_vma (abfd, buf, p->addend);
17766 for (a = buf; *a == '0'; ++a)
17769 memcpy (names, a, len);
17772 memcpy (names, "@plt", sizeof ("@plt"));
17773 names += sizeof ("@plt");
17775 offset += plt_size;
17781 static const struct bfd_elf_special_section
17782 elf32_arm_special_sections[] =
17784 /* Catch sections with .text.noread prefix and apply allocate, execute and
17785 noread section attributes. */
17786 { STRING_COMMA_LEN (".text.noread"), -2, SHT_PROGBITS,
17787 SHF_ALLOC + SHF_EXECINSTR + SHF_ARM_NOREAD },
17788 { NULL, 0, 0, 0, 0 }
17792 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr * hdr)
17794 if (hdr->sh_flags & SHF_ARM_NOREAD)
17795 *flags |= SEC_ELF_NOREAD;
17800 elf32_arm_lookup_section_flags (char *flag_name)
17802 if (!strcmp (flag_name, "SHF_ARM_NOREAD"))
17803 return SHF_ARM_NOREAD;
17805 return SEC_NO_FLAGS;
17808 static unsigned int
17809 elf32_arm_count_additional_relocs (asection *sec)
17811 struct _arm_elf_section_data *arm_data;
17812 arm_data = get_arm_elf_section_data (sec);
17813 return arm_data->additional_reloc_count;
17816 #define ELF_ARCH bfd_arch_arm
17817 #define ELF_TARGET_ID ARM_ELF_DATA
17818 #define ELF_MACHINE_CODE EM_ARM
17819 #ifdef __QNXTARGET__
17820 #define ELF_MAXPAGESIZE 0x1000
17822 #define ELF_MAXPAGESIZE 0x10000
17824 #define ELF_MINPAGESIZE 0x1000
17825 #define ELF_COMMONPAGESIZE 0x1000
17827 #define bfd_elf32_mkobject elf32_arm_mkobject
17829 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
17830 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
17831 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
17832 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
17833 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
17834 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
17835 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
17836 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
17837 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
17838 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
17839 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
17840 #define bfd_elf32_bfd_final_link elf32_arm_final_link
17841 #define bfd_elf32_get_synthetic_symtab elf32_arm_get_synthetic_symtab
17843 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
17844 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
17845 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
17846 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
17847 #define elf_backend_check_relocs elf32_arm_check_relocs
17848 #define elf_backend_relocate_section elf32_arm_relocate_section
17849 #define elf_backend_write_section elf32_arm_write_section
17850 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
17851 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
17852 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
17853 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
17854 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
17855 #define elf_backend_always_size_sections elf32_arm_always_size_sections
17856 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
17857 #define elf_backend_post_process_headers elf32_arm_post_process_headers
17858 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
17859 #define elf_backend_object_p elf32_arm_object_p
17860 #define elf_backend_fake_sections elf32_arm_fake_sections
17861 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
17862 #define elf_backend_final_write_processing elf32_arm_final_write_processing
17863 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
17864 #define elf_backend_size_info elf32_arm_size_info
17865 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
17866 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
17867 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
17868 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
17869 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
17870 #define elf_backend_count_additional_relocs elf32_arm_count_additional_relocs
17872 #define elf_backend_can_refcount 1
17873 #define elf_backend_can_gc_sections 1
17874 #define elf_backend_plt_readonly 1
17875 #define elf_backend_want_got_plt 1
17876 #define elf_backend_want_plt_sym 0
17877 #define elf_backend_may_use_rel_p 1
17878 #define elf_backend_may_use_rela_p 0
17879 #define elf_backend_default_use_rela_p 0
17881 #define elf_backend_got_header_size 12
17882 #define elf_backend_extern_protected_data 1
17884 #undef elf_backend_obj_attrs_vendor
17885 #define elf_backend_obj_attrs_vendor "aeabi"
17886 #undef elf_backend_obj_attrs_section
17887 #define elf_backend_obj_attrs_section ".ARM.attributes"
17888 #undef elf_backend_obj_attrs_arg_type
17889 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
17890 #undef elf_backend_obj_attrs_section_type
17891 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
17892 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
17893 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
17895 #undef elf_backend_special_sections
17896 #define elf_backend_special_sections elf32_arm_special_sections
17897 #undef elf_backend_section_flags
17898 #define elf_backend_section_flags elf32_arm_section_flags
17899 #undef elf_backend_lookup_section_flags_hook
17900 #define elf_backend_lookup_section_flags_hook elf32_arm_lookup_section_flags
17902 #include "elf32-target.h"
17904 /* Native Client targets. */
17906 #undef TARGET_LITTLE_SYM
17907 #define TARGET_LITTLE_SYM arm_elf32_nacl_le_vec
17908 #undef TARGET_LITTLE_NAME
17909 #define TARGET_LITTLE_NAME "elf32-littlearm-nacl"
17910 #undef TARGET_BIG_SYM
17911 #define TARGET_BIG_SYM arm_elf32_nacl_be_vec
17912 #undef TARGET_BIG_NAME
17913 #define TARGET_BIG_NAME "elf32-bigarm-nacl"
17915 /* Like elf32_arm_link_hash_table_create -- but overrides
17916 appropriately for NaCl. */
17918 static struct bfd_link_hash_table *
17919 elf32_arm_nacl_link_hash_table_create (bfd *abfd)
17921 struct bfd_link_hash_table *ret;
17923 ret = elf32_arm_link_hash_table_create (abfd);
17926 struct elf32_arm_link_hash_table *htab
17927 = (struct elf32_arm_link_hash_table *) ret;
17931 htab->plt_header_size = 4 * ARRAY_SIZE (elf32_arm_nacl_plt0_entry);
17932 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_nacl_plt_entry);
17937 /* Since NaCl doesn't use the ARM-specific unwind format, we don't
17938 really need to use elf32_arm_modify_segment_map. But we do it
17939 anyway just to reduce gratuitous differences with the stock ARM backend. */
17942 elf32_arm_nacl_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
17944 return (elf32_arm_modify_segment_map (abfd, info)
17945 && nacl_modify_segment_map (abfd, info));
17949 elf32_arm_nacl_final_write_processing (bfd *abfd, bfd_boolean linker)
17951 elf32_arm_final_write_processing (abfd, linker);
17952 nacl_final_write_processing (abfd, linker);
17956 elf32_arm_nacl_plt_sym_val (bfd_vma i, const asection *plt,
17957 const arelent *rel ATTRIBUTE_UNUSED)
17960 + 4 * (ARRAY_SIZE (elf32_arm_nacl_plt0_entry) +
17961 i * ARRAY_SIZE (elf32_arm_nacl_plt_entry));
17965 #define elf32_bed elf32_arm_nacl_bed
17966 #undef bfd_elf32_bfd_link_hash_table_create
17967 #define bfd_elf32_bfd_link_hash_table_create \
17968 elf32_arm_nacl_link_hash_table_create
17969 #undef elf_backend_plt_alignment
17970 #define elf_backend_plt_alignment 4
17971 #undef elf_backend_modify_segment_map
17972 #define elf_backend_modify_segment_map elf32_arm_nacl_modify_segment_map
17973 #undef elf_backend_modify_program_headers
17974 #define elf_backend_modify_program_headers nacl_modify_program_headers
17975 #undef elf_backend_final_write_processing
17976 #define elf_backend_final_write_processing elf32_arm_nacl_final_write_processing
17977 #undef bfd_elf32_get_synthetic_symtab
17978 #undef elf_backend_plt_sym_val
17979 #define elf_backend_plt_sym_val elf32_arm_nacl_plt_sym_val
17981 #undef ELF_MINPAGESIZE
17982 #undef ELF_COMMONPAGESIZE
17985 #include "elf32-target.h"
17987 /* Reset to defaults. */
17988 #undef elf_backend_plt_alignment
17989 #undef elf_backend_modify_segment_map
17990 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
17991 #undef elf_backend_modify_program_headers
17992 #undef elf_backend_final_write_processing
17993 #define elf_backend_final_write_processing elf32_arm_final_write_processing
17994 #undef ELF_MINPAGESIZE
17995 #define ELF_MINPAGESIZE 0x1000
17996 #undef ELF_COMMONPAGESIZE
17997 #define ELF_COMMONPAGESIZE 0x1000
18000 /* VxWorks Targets. */
18002 #undef TARGET_LITTLE_SYM
18003 #define TARGET_LITTLE_SYM arm_elf32_vxworks_le_vec
18004 #undef TARGET_LITTLE_NAME
18005 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
18006 #undef TARGET_BIG_SYM
18007 #define TARGET_BIG_SYM arm_elf32_vxworks_be_vec
18008 #undef TARGET_BIG_NAME
18009 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
18011 /* Like elf32_arm_link_hash_table_create -- but overrides
18012 appropriately for VxWorks. */
18014 static struct bfd_link_hash_table *
18015 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
18017 struct bfd_link_hash_table *ret;
18019 ret = elf32_arm_link_hash_table_create (abfd);
18022 struct elf32_arm_link_hash_table *htab
18023 = (struct elf32_arm_link_hash_table *) ret;
18025 htab->vxworks_p = 1;
18031 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
18033 elf32_arm_final_write_processing (abfd, linker);
18034 elf_vxworks_final_write_processing (abfd, linker);
18038 #define elf32_bed elf32_arm_vxworks_bed
18040 #undef bfd_elf32_bfd_link_hash_table_create
18041 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
18042 #undef elf_backend_final_write_processing
18043 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
18044 #undef elf_backend_emit_relocs
18045 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
18047 #undef elf_backend_may_use_rel_p
18048 #define elf_backend_may_use_rel_p 0
18049 #undef elf_backend_may_use_rela_p
18050 #define elf_backend_may_use_rela_p 1
18051 #undef elf_backend_default_use_rela_p
18052 #define elf_backend_default_use_rela_p 1
18053 #undef elf_backend_want_plt_sym
18054 #define elf_backend_want_plt_sym 1
18055 #undef ELF_MAXPAGESIZE
18056 #define ELF_MAXPAGESIZE 0x1000
18058 #include "elf32-target.h"
18061 /* Merge backend specific data from an object file to the output
18062 object file when linking. */
18065 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
18067 flagword out_flags;
18069 bfd_boolean flags_compatible = TRUE;
18072 /* Check if we have the same endianness. */
18073 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
18076 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
18079 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
18082 /* The input BFD must have had its flags initialised. */
18083 /* The following seems bogus to me -- The flags are initialized in
18084 the assembler but I don't think an elf_flags_init field is
18085 written into the object. */
18086 /* BFD_ASSERT (elf_flags_init (ibfd)); */
18088 in_flags = elf_elfheader (ibfd)->e_flags;
18089 out_flags = elf_elfheader (obfd)->e_flags;
18091 /* In theory there is no reason why we couldn't handle this. However
18092 in practice it isn't even close to working and there is no real
18093 reason to want it. */
18094 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
18095 && !(ibfd->flags & DYNAMIC)
18096 && (in_flags & EF_ARM_BE8))
18098 _bfd_error_handler (_("error: %B is already in final BE8 format"),
18103 if (!elf_flags_init (obfd))
18105 /* If the input is the default architecture and had the default
18106 flags then do not bother setting the flags for the output
18107 architecture, instead allow future merges to do this. If no
18108 future merges ever set these flags then they will retain their
18109 uninitialised values, which surprise surprise, correspond
18110 to the default values. */
18111 if (bfd_get_arch_info (ibfd)->the_default
18112 && elf_elfheader (ibfd)->e_flags == 0)
18115 elf_flags_init (obfd) = TRUE;
18116 elf_elfheader (obfd)->e_flags = in_flags;
18118 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
18119 && bfd_get_arch_info (obfd)->the_default)
18120 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
18125 /* Determine what should happen if the input ARM architecture
18126 does not match the output ARM architecture. */
18127 if (! bfd_arm_merge_machines (ibfd, obfd))
18130 /* Identical flags must be compatible. */
18131 if (in_flags == out_flags)
18134 /* Check to see if the input BFD actually contains any sections. If
18135 not, its flags may not have been initialised either, but it
18136 cannot actually cause any incompatiblity. Do not short-circuit
18137 dynamic objects; their section list may be emptied by
18138 elf_link_add_object_symbols.
18140 Also check to see if there are no code sections in the input.
18141 In this case there is no need to check for code specific flags.
18142 XXX - do we need to worry about floating-point format compatability
18143 in data sections ? */
18144 if (!(ibfd->flags & DYNAMIC))
18146 bfd_boolean null_input_bfd = TRUE;
18147 bfd_boolean only_data_sections = TRUE;
18149 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
18151 /* Ignore synthetic glue sections. */
18152 if (strcmp (sec->name, ".glue_7")
18153 && strcmp (sec->name, ".glue_7t"))
18155 if ((bfd_get_section_flags (ibfd, sec)
18156 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
18157 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
18158 only_data_sections = FALSE;
18160 null_input_bfd = FALSE;
18165 if (null_input_bfd || only_data_sections)
18169 /* Complain about various flag mismatches. */
18170 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
18171 EF_ARM_EABI_VERSION (out_flags)))
18174 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
18176 (in_flags & EF_ARM_EABIMASK) >> 24,
18177 (out_flags & EF_ARM_EABIMASK) >> 24);
18181 /* Not sure what needs to be checked for EABI versions >= 1. */
18182 /* VxWorks libraries do not use these flags. */
18183 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
18184 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
18185 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
18187 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
18190 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
18192 in_flags & EF_ARM_APCS_26 ? 26 : 32,
18193 out_flags & EF_ARM_APCS_26 ? 26 : 32);
18194 flags_compatible = FALSE;
18197 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
18199 if (in_flags & EF_ARM_APCS_FLOAT)
18201 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
18205 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
18208 flags_compatible = FALSE;
18211 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
18213 if (in_flags & EF_ARM_VFP_FLOAT)
18215 (_("error: %B uses VFP instructions, whereas %B does not"),
18219 (_("error: %B uses FPA instructions, whereas %B does not"),
18222 flags_compatible = FALSE;
18225 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
18227 if (in_flags & EF_ARM_MAVERICK_FLOAT)
18229 (_("error: %B uses Maverick instructions, whereas %B does not"),
18233 (_("error: %B does not use Maverick instructions, whereas %B does"),
18236 flags_compatible = FALSE;
18239 #ifdef EF_ARM_SOFT_FLOAT
18240 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
18242 /* We can allow interworking between code that is VFP format
18243 layout, and uses either soft float or integer regs for
18244 passing floating point arguments and results. We already
18245 know that the APCS_FLOAT flags match; similarly for VFP
18247 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
18248 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
18250 if (in_flags & EF_ARM_SOFT_FLOAT)
18252 (_("error: %B uses software FP, whereas %B uses hardware FP"),
18256 (_("error: %B uses hardware FP, whereas %B uses software FP"),
18259 flags_compatible = FALSE;
18264 /* Interworking mismatch is only a warning. */
18265 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
18267 if (in_flags & EF_ARM_INTERWORK)
18270 (_("Warning: %B supports interworking, whereas %B does not"),
18276 (_("Warning: %B does not support interworking, whereas %B does"),
18282 return flags_compatible;
18286 /* Symbian OS Targets. */
18288 #undef TARGET_LITTLE_SYM
18289 #define TARGET_LITTLE_SYM arm_elf32_symbian_le_vec
18290 #undef TARGET_LITTLE_NAME
18291 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
18292 #undef TARGET_BIG_SYM
18293 #define TARGET_BIG_SYM arm_elf32_symbian_be_vec
18294 #undef TARGET_BIG_NAME
18295 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
18297 /* Like elf32_arm_link_hash_table_create -- but overrides
18298 appropriately for Symbian OS. */
18300 static struct bfd_link_hash_table *
18301 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
18303 struct bfd_link_hash_table *ret;
18305 ret = elf32_arm_link_hash_table_create (abfd);
18308 struct elf32_arm_link_hash_table *htab
18309 = (struct elf32_arm_link_hash_table *)ret;
18310 /* There is no PLT header for Symbian OS. */
18311 htab->plt_header_size = 0;
18312 /* The PLT entries are each one instruction and one word. */
18313 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
18314 htab->symbian_p = 1;
18315 /* Symbian uses armv5t or above, so use_blx is always true. */
18317 htab->root.is_relocatable_executable = 1;
18322 static const struct bfd_elf_special_section
18323 elf32_arm_symbian_special_sections[] =
18325 /* In a BPABI executable, the dynamic linking sections do not go in
18326 the loadable read-only segment. The post-linker may wish to
18327 refer to these sections, but they are not part of the final
18329 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
18330 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
18331 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
18332 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
18333 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
18334 /* These sections do not need to be writable as the SymbianOS
18335 postlinker will arrange things so that no dynamic relocation is
18337 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
18338 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
18339 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
18340 { NULL, 0, 0, 0, 0 }
18344 elf32_arm_symbian_begin_write_processing (bfd *abfd,
18345 struct bfd_link_info *link_info)
18347 /* BPABI objects are never loaded directly by an OS kernel; they are
18348 processed by a postlinker first, into an OS-specific format. If
18349 the D_PAGED bit is set on the file, BFD will align segments on
18350 page boundaries, so that an OS can directly map the file. With
18351 BPABI objects, that just results in wasted space. In addition,
18352 because we clear the D_PAGED bit, map_sections_to_segments will
18353 recognize that the program headers should not be mapped into any
18354 loadable segment. */
18355 abfd->flags &= ~D_PAGED;
18356 elf32_arm_begin_write_processing (abfd, link_info);
18360 elf32_arm_symbian_modify_segment_map (bfd *abfd,
18361 struct bfd_link_info *info)
18363 struct elf_segment_map *m;
18366 /* BPABI shared libraries and executables should have a PT_DYNAMIC
18367 segment. However, because the .dynamic section is not marked
18368 with SEC_LOAD, the generic ELF code will not create such a
18370 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
18373 for (m = elf_seg_map (abfd); m != NULL; m = m->next)
18374 if (m->p_type == PT_DYNAMIC)
18379 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
18380 m->next = elf_seg_map (abfd);
18381 elf_seg_map (abfd) = m;
18385 /* Also call the generic arm routine. */
18386 return elf32_arm_modify_segment_map (abfd, info);
18389 /* Return address for Ith PLT stub in section PLT, for relocation REL
18390 or (bfd_vma) -1 if it should not be included. */
18393 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
18394 const arelent *rel ATTRIBUTE_UNUSED)
18396 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
18401 #define elf32_bed elf32_arm_symbian_bed
18403 /* The dynamic sections are not allocated on SymbianOS; the postlinker
18404 will process them and then discard them. */
18405 #undef ELF_DYNAMIC_SEC_FLAGS
18406 #define ELF_DYNAMIC_SEC_FLAGS \
18407 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
18409 #undef elf_backend_emit_relocs
18411 #undef bfd_elf32_bfd_link_hash_table_create
18412 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
18413 #undef elf_backend_special_sections
18414 #define elf_backend_special_sections elf32_arm_symbian_special_sections
18415 #undef elf_backend_begin_write_processing
18416 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
18417 #undef elf_backend_final_write_processing
18418 #define elf_backend_final_write_processing elf32_arm_final_write_processing
18420 #undef elf_backend_modify_segment_map
18421 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
18423 /* There is no .got section for BPABI objects, and hence no header. */
18424 #undef elf_backend_got_header_size
18425 #define elf_backend_got_header_size 0
18427 /* Similarly, there is no .got.plt section. */
18428 #undef elf_backend_want_got_plt
18429 #define elf_backend_want_got_plt 0
18431 #undef elf_backend_plt_sym_val
18432 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
18434 #undef elf_backend_may_use_rel_p
18435 #define elf_backend_may_use_rel_p 1
18436 #undef elf_backend_may_use_rela_p
18437 #define elf_backend_may_use_rela_p 0
18438 #undef elf_backend_default_use_rela_p
18439 #define elf_backend_default_use_rela_p 0
18440 #undef elf_backend_want_plt_sym
18441 #define elf_backend_want_plt_sym 0
18442 #undef ELF_MAXPAGESIZE
18443 #define ELF_MAXPAGESIZE 0x8000
18445 #include "elf32-target.h"