1 /* 32-bit ELF support for ARM
2 Copyright (C) 1998-2018 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 NULL
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
[8] =
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 */
1764 HOWTO (R_ARM_GOTFUNCDESC
, /* type */
1766 2, /* size (0 = byte, 1 = short, 2 = long) */
1768 FALSE
, /* pc_relative */
1770 complain_overflow_bitfield
,/* complain_on_overflow */
1771 bfd_elf_generic_reloc
, /* special_function */
1772 "R_ARM_GOTFUNCDESC", /* name */
1773 FALSE
, /* partial_inplace */
1775 0xffffffff, /* dst_mask */
1776 FALSE
), /* pcrel_offset */
1777 HOWTO (R_ARM_GOTOFFFUNCDESC
, /* type */
1779 2, /* size (0 = byte, 1 = short, 2 = long) */
1781 FALSE
, /* pc_relative */
1783 complain_overflow_bitfield
,/* complain_on_overflow */
1784 bfd_elf_generic_reloc
, /* special_function */
1785 "R_ARM_GOTOFFFUNCDESC",/* name */
1786 FALSE
, /* partial_inplace */
1788 0xffffffff, /* dst_mask */
1789 FALSE
), /* pcrel_offset */
1790 HOWTO (R_ARM_FUNCDESC
, /* type */
1792 2, /* size (0 = byte, 1 = short, 2 = long) */
1794 FALSE
, /* pc_relative */
1796 complain_overflow_bitfield
,/* complain_on_overflow */
1797 bfd_elf_generic_reloc
, /* special_function */
1798 "R_ARM_FUNCDESC", /* name */
1799 FALSE
, /* partial_inplace */
1801 0xffffffff, /* dst_mask */
1802 FALSE
), /* pcrel_offset */
1803 HOWTO (R_ARM_FUNCDESC_VALUE
, /* type */
1805 2, /* size (0 = byte, 1 = short, 2 = long) */
1807 FALSE
, /* pc_relative */
1809 complain_overflow_bitfield
,/* complain_on_overflow */
1810 bfd_elf_generic_reloc
, /* special_function */
1811 "R_ARM_FUNCDESC_VALUE",/* name */
1812 FALSE
, /* partial_inplace */
1814 0xffffffff, /* dst_mask */
1815 FALSE
), /* pcrel_offset */
1816 HOWTO (R_ARM_TLS_GD32_FDPIC
, /* type */
1818 2, /* size (0 = byte, 1 = short, 2 = long) */
1820 FALSE
, /* pc_relative */
1822 complain_overflow_bitfield
,/* complain_on_overflow */
1823 bfd_elf_generic_reloc
, /* special_function */
1824 "R_ARM_TLS_GD32_FDPIC",/* name */
1825 FALSE
, /* partial_inplace */
1827 0xffffffff, /* dst_mask */
1828 FALSE
), /* pcrel_offset */
1829 HOWTO (R_ARM_TLS_LDM32_FDPIC
, /* type */
1831 2, /* size (0 = byte, 1 = short, 2 = long) */
1833 FALSE
, /* pc_relative */
1835 complain_overflow_bitfield
,/* complain_on_overflow */
1836 bfd_elf_generic_reloc
, /* special_function */
1837 "R_ARM_TLS_LDM32_FDPIC",/* name */
1838 FALSE
, /* partial_inplace */
1840 0xffffffff, /* dst_mask */
1841 FALSE
), /* pcrel_offset */
1842 HOWTO (R_ARM_TLS_IE32_FDPIC
, /* type */
1844 2, /* size (0 = byte, 1 = short, 2 = long) */
1846 FALSE
, /* pc_relative */
1848 complain_overflow_bitfield
,/* complain_on_overflow */
1849 bfd_elf_generic_reloc
, /* special_function */
1850 "R_ARM_TLS_IE32_FDPIC",/* name */
1851 FALSE
, /* partial_inplace */
1853 0xffffffff, /* dst_mask */
1854 FALSE
), /* pcrel_offset */
1857 /* 249-255 extended, currently unused, relocations: */
1858 static reloc_howto_type elf32_arm_howto_table_3
[4] =
1860 HOWTO (R_ARM_RREL32
, /* type */
1862 0, /* size (0 = byte, 1 = short, 2 = long) */
1864 FALSE
, /* pc_relative */
1866 complain_overflow_dont
,/* complain_on_overflow */
1867 bfd_elf_generic_reloc
, /* special_function */
1868 "R_ARM_RREL32", /* name */
1869 FALSE
, /* partial_inplace */
1872 FALSE
), /* pcrel_offset */
1874 HOWTO (R_ARM_RABS32
, /* type */
1876 0, /* size (0 = byte, 1 = short, 2 = long) */
1878 FALSE
, /* pc_relative */
1880 complain_overflow_dont
,/* complain_on_overflow */
1881 bfd_elf_generic_reloc
, /* special_function */
1882 "R_ARM_RABS32", /* name */
1883 FALSE
, /* partial_inplace */
1886 FALSE
), /* pcrel_offset */
1888 HOWTO (R_ARM_RPC24
, /* type */
1890 0, /* size (0 = byte, 1 = short, 2 = long) */
1892 FALSE
, /* pc_relative */
1894 complain_overflow_dont
,/* complain_on_overflow */
1895 bfd_elf_generic_reloc
, /* special_function */
1896 "R_ARM_RPC24", /* name */
1897 FALSE
, /* partial_inplace */
1900 FALSE
), /* pcrel_offset */
1902 HOWTO (R_ARM_RBASE
, /* type */
1904 0, /* size (0 = byte, 1 = short, 2 = long) */
1906 FALSE
, /* pc_relative */
1908 complain_overflow_dont
,/* complain_on_overflow */
1909 bfd_elf_generic_reloc
, /* special_function */
1910 "R_ARM_RBASE", /* name */
1911 FALSE
, /* partial_inplace */
1914 FALSE
) /* pcrel_offset */
1917 static reloc_howto_type
*
1918 elf32_arm_howto_from_type (unsigned int r_type
)
1920 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1921 return &elf32_arm_howto_table_1
[r_type
];
1923 if (r_type
>= R_ARM_IRELATIVE
1924 && r_type
< R_ARM_IRELATIVE
+ ARRAY_SIZE (elf32_arm_howto_table_2
))
1925 return &elf32_arm_howto_table_2
[r_type
- R_ARM_IRELATIVE
];
1927 if (r_type
>= R_ARM_RREL32
1928 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_3
))
1929 return &elf32_arm_howto_table_3
[r_type
- R_ARM_RREL32
];
1935 elf32_arm_info_to_howto (bfd
* abfd
, arelent
* bfd_reloc
,
1936 Elf_Internal_Rela
* elf_reloc
)
1938 unsigned int r_type
;
1940 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1941 if ((bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
)) == NULL
)
1943 /* xgettext:c-format */
1944 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1946 bfd_set_error (bfd_error_bad_value
);
1952 struct elf32_arm_reloc_map
1954 bfd_reloc_code_real_type bfd_reloc_val
;
1955 unsigned char elf_reloc_val
;
1958 /* All entries in this list must also be present in elf32_arm_howto_table. */
1959 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1961 {BFD_RELOC_NONE
, R_ARM_NONE
},
1962 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1963 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1964 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1965 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1966 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1967 {BFD_RELOC_32
, R_ARM_ABS32
},
1968 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1969 {BFD_RELOC_8
, R_ARM_ABS8
},
1970 {BFD_RELOC_16
, R_ARM_ABS16
},
1971 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1972 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1973 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1974 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1975 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1976 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1977 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1978 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1979 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1980 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1981 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1982 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1983 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1984 {BFD_RELOC_ARM_GOT_PREL
, R_ARM_GOT_PREL
},
1985 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1986 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1987 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1988 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1989 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1990 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1991 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1992 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1993 {BFD_RELOC_ARM_TLS_GOTDESC
, R_ARM_TLS_GOTDESC
},
1994 {BFD_RELOC_ARM_TLS_CALL
, R_ARM_TLS_CALL
},
1995 {BFD_RELOC_ARM_THM_TLS_CALL
, R_ARM_THM_TLS_CALL
},
1996 {BFD_RELOC_ARM_TLS_DESCSEQ
, R_ARM_TLS_DESCSEQ
},
1997 {BFD_RELOC_ARM_THM_TLS_DESCSEQ
, R_ARM_THM_TLS_DESCSEQ
},
1998 {BFD_RELOC_ARM_TLS_DESC
, R_ARM_TLS_DESC
},
1999 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
2000 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
2001 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
2002 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
2003 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
2004 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
2005 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
2006 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
2007 {BFD_RELOC_ARM_IRELATIVE
, R_ARM_IRELATIVE
},
2008 {BFD_RELOC_ARM_GOTFUNCDESC
, R_ARM_GOTFUNCDESC
},
2009 {BFD_RELOC_ARM_GOTOFFFUNCDESC
, R_ARM_GOTOFFFUNCDESC
},
2010 {BFD_RELOC_ARM_FUNCDESC
, R_ARM_FUNCDESC
},
2011 {BFD_RELOC_ARM_FUNCDESC_VALUE
, R_ARM_FUNCDESC_VALUE
},
2012 {BFD_RELOC_ARM_TLS_GD32_FDPIC
, R_ARM_TLS_GD32_FDPIC
},
2013 {BFD_RELOC_ARM_TLS_LDM32_FDPIC
, R_ARM_TLS_LDM32_FDPIC
},
2014 {BFD_RELOC_ARM_TLS_IE32_FDPIC
, R_ARM_TLS_IE32_FDPIC
},
2015 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
2016 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
2017 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
2018 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
2019 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
2020 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
2021 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
2022 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
2023 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
2024 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
2025 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
2026 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
2027 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
2028 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
2029 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
2030 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
2031 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
2032 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
2033 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
2034 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
2035 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
2036 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
2037 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
2038 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
2039 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
2040 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
2041 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
2042 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
2043 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
2044 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
2045 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
2046 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
2047 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
2048 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
2049 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
2050 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
2051 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
2052 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
2053 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
},
2054 {BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC
, R_ARM_THM_ALU_ABS_G3_NC
},
2055 {BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC
, R_ARM_THM_ALU_ABS_G2_NC
},
2056 {BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC
, R_ARM_THM_ALU_ABS_G1_NC
},
2057 {BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
, R_ARM_THM_ALU_ABS_G0_NC
}
2060 static reloc_howto_type
*
2061 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2062 bfd_reloc_code_real_type code
)
2066 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
2067 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
2068 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
2073 static reloc_howto_type
*
2074 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2079 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
2080 if (elf32_arm_howto_table_1
[i
].name
!= NULL
2081 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
2082 return &elf32_arm_howto_table_1
[i
];
2084 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
2085 if (elf32_arm_howto_table_2
[i
].name
!= NULL
2086 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
2087 return &elf32_arm_howto_table_2
[i
];
2089 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_3
); i
++)
2090 if (elf32_arm_howto_table_3
[i
].name
!= NULL
2091 && strcasecmp (elf32_arm_howto_table_3
[i
].name
, r_name
) == 0)
2092 return &elf32_arm_howto_table_3
[i
];
2097 /* Support for core dump NOTE sections. */
2100 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2105 switch (note
->descsz
)
2110 case 148: /* Linux/ARM 32-bit. */
2112 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2115 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
2124 /* Make a ".reg/999" section. */
2125 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2126 size
, note
->descpos
+ offset
);
2130 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2132 switch (note
->descsz
)
2137 case 124: /* Linux/ARM elf_prpsinfo. */
2138 elf_tdata (abfd
)->core
->pid
2139 = bfd_get_32 (abfd
, note
->descdata
+ 12);
2140 elf_tdata (abfd
)->core
->program
2141 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
2142 elf_tdata (abfd
)->core
->command
2143 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
2146 /* Note that for some reason, a spurious space is tacked
2147 onto the end of the args in some (at least one anyway)
2148 implementations, so strip it off if it exists. */
2150 char *command
= elf_tdata (abfd
)->core
->command
;
2151 int n
= strlen (command
);
2153 if (0 < n
&& command
[n
- 1] == ' ')
2154 command
[n
- 1] = '\0';
2161 elf32_arm_nabi_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
2174 va_start (ap
, note_type
);
2175 memset (data
, 0, sizeof (data
));
2176 strncpy (data
+ 28, va_arg (ap
, const char *), 16);
2177 strncpy (data
+ 44, va_arg (ap
, const char *), 80);
2180 return elfcore_write_note (abfd
, buf
, bufsiz
,
2181 "CORE", note_type
, data
, sizeof (data
));
2192 va_start (ap
, note_type
);
2193 memset (data
, 0, sizeof (data
));
2194 pid
= va_arg (ap
, long);
2195 bfd_put_32 (abfd
, pid
, data
+ 24);
2196 cursig
= va_arg (ap
, int);
2197 bfd_put_16 (abfd
, cursig
, data
+ 12);
2198 greg
= va_arg (ap
, const void *);
2199 memcpy (data
+ 72, greg
, 72);
2202 return elfcore_write_note (abfd
, buf
, bufsiz
,
2203 "CORE", note_type
, data
, sizeof (data
));
2208 #define TARGET_LITTLE_SYM arm_elf32_le_vec
2209 #define TARGET_LITTLE_NAME "elf32-littlearm"
2210 #define TARGET_BIG_SYM arm_elf32_be_vec
2211 #define TARGET_BIG_NAME "elf32-bigarm"
2213 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
2214 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
2215 #define elf_backend_write_core_note elf32_arm_nabi_write_core_note
2217 typedef unsigned long int insn32
;
2218 typedef unsigned short int insn16
;
2220 /* In lieu of proper flags, assume all EABIv4 or later objects are
2222 #define INTERWORK_FLAG(abfd) \
2223 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
2224 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
2225 || ((abfd)->flags & BFD_LINKER_CREATED))
2227 /* The linker script knows the section names for placement.
2228 The entry_names are used to do simple name mangling on the stubs.
2229 Given a function name, and its type, the stub can be found. The
2230 name can be changed. The only requirement is the %s be present. */
2231 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
2232 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
2234 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
2235 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
2237 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
2238 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
2240 #define STM32L4XX_ERRATUM_VENEER_SECTION_NAME ".text.stm32l4xx_veneer"
2241 #define STM32L4XX_ERRATUM_VENEER_ENTRY_NAME "__stm32l4xx_veneer_%x"
2243 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
2244 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
2246 #define STUB_ENTRY_NAME "__%s_veneer"
2248 #define CMSE_PREFIX "__acle_se_"
2250 /* The name of the dynamic interpreter. This is put in the .interp
2252 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
2254 /* FDPIC default stack size. */
2255 #define DEFAULT_STACK_SIZE 0x8000
2257 static const unsigned long tls_trampoline
[] =
2259 0xe08e0000, /* add r0, lr, r0 */
2260 0xe5901004, /* ldr r1, [r0,#4] */
2261 0xe12fff11, /* bx r1 */
2264 static const unsigned long dl_tlsdesc_lazy_trampoline
[] =
2266 0xe52d2004, /* push {r2} */
2267 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */
2268 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */
2269 0xe79f2002, /* 1: ldr r2, [pc, r2] */
2270 0xe081100f, /* 2: add r1, pc */
2271 0xe12fff12, /* bx r2 */
2272 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8
2273 + dl_tlsdesc_lazy_resolver(GOT) */
2274 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */
2277 /* ARM FDPIC PLT entry. */
2278 /* The last 5 words contain PLT lazy fragment code and data. */
2279 static const bfd_vma elf32_arm_fdpic_plt_entry
[] =
2281 0xe59fc008, /* ldr r12, .L1 */
2282 0xe08cc009, /* add r12, r12, r9 */
2283 0xe59c9004, /* ldr r9, [r12, #4] */
2284 0xe59cf000, /* ldr pc, [r12] */
2285 0x00000000, /* L1. .word foo(GOTOFFFUNCDESC) */
2286 0x00000000, /* L1. .word foo(funcdesc_value_reloc_offset) */
2287 0xe51fc00c, /* ldr r12, [pc, #-12] */
2288 0xe92d1000, /* push {r12} */
2289 0xe599c004, /* ldr r12, [r9, #4] */
2290 0xe599f000, /* ldr pc, [r9] */
2293 #ifdef FOUR_WORD_PLT
2295 /* The first entry in a procedure linkage table looks like
2296 this. It is set up so that any shared library function that is
2297 called before the relocation has been set up calls the dynamic
2299 static const bfd_vma elf32_arm_plt0_entry
[] =
2301 0xe52de004, /* str lr, [sp, #-4]! */
2302 0xe59fe010, /* ldr lr, [pc, #16] */
2303 0xe08fe00e, /* add lr, pc, lr */
2304 0xe5bef008, /* ldr pc, [lr, #8]! */
2307 /* Subsequent entries in a procedure linkage table look like
2309 static const bfd_vma elf32_arm_plt_entry
[] =
2311 0xe28fc600, /* add ip, pc, #NN */
2312 0xe28cca00, /* add ip, ip, #NN */
2313 0xe5bcf000, /* ldr pc, [ip, #NN]! */
2314 0x00000000, /* unused */
2317 #else /* not FOUR_WORD_PLT */
2319 /* The first entry in a procedure linkage table looks like
2320 this. It is set up so that any shared library function that is
2321 called before the relocation has been set up calls the dynamic
2323 static const bfd_vma elf32_arm_plt0_entry
[] =
2325 0xe52de004, /* str lr, [sp, #-4]! */
2326 0xe59fe004, /* ldr lr, [pc, #4] */
2327 0xe08fe00e, /* add lr, pc, lr */
2328 0xe5bef008, /* ldr pc, [lr, #8]! */
2329 0x00000000, /* &GOT[0] - . */
2332 /* By default subsequent entries in a procedure linkage table look like
2333 this. Offsets that don't fit into 28 bits will cause link error. */
2334 static const bfd_vma elf32_arm_plt_entry_short
[] =
2336 0xe28fc600, /* add ip, pc, #0xNN00000 */
2337 0xe28cca00, /* add ip, ip, #0xNN000 */
2338 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2341 /* When explicitly asked, we'll use this "long" entry format
2342 which can cope with arbitrary displacements. */
2343 static const bfd_vma elf32_arm_plt_entry_long
[] =
2345 0xe28fc200, /* add ip, pc, #0xN0000000 */
2346 0xe28cc600, /* add ip, ip, #0xNN00000 */
2347 0xe28cca00, /* add ip, ip, #0xNN000 */
2348 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2351 static bfd_boolean elf32_arm_use_long_plt_entry
= FALSE
;
2353 #endif /* not FOUR_WORD_PLT */
2355 /* The first entry in a procedure linkage table looks like this.
2356 It is set up so that any shared library function that is called before the
2357 relocation has been set up calls the dynamic linker first. */
2358 static const bfd_vma elf32_thumb2_plt0_entry
[] =
2360 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2361 an instruction maybe encoded to one or two array elements. */
2362 0xf8dfb500, /* push {lr} */
2363 0x44fee008, /* ldr.w lr, [pc, #8] */
2365 0xff08f85e, /* ldr.w pc, [lr, #8]! */
2366 0x00000000, /* &GOT[0] - . */
2369 /* Subsequent entries in a procedure linkage table for thumb only target
2371 static const bfd_vma elf32_thumb2_plt_entry
[] =
2373 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2374 an instruction maybe encoded to one or two array elements. */
2375 0x0c00f240, /* movw ip, #0xNNNN */
2376 0x0c00f2c0, /* movt ip, #0xNNNN */
2377 0xf8dc44fc, /* add ip, pc */
2378 0xbf00f000 /* ldr.w pc, [ip] */
2382 /* The format of the first entry in the procedure linkage table
2383 for a VxWorks executable. */
2384 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
2386 0xe52dc008, /* str ip,[sp,#-8]! */
2387 0xe59fc000, /* ldr ip,[pc] */
2388 0xe59cf008, /* ldr pc,[ip,#8] */
2389 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2392 /* The format of subsequent entries in a VxWorks executable. */
2393 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
2395 0xe59fc000, /* ldr ip,[pc] */
2396 0xe59cf000, /* ldr pc,[ip] */
2397 0x00000000, /* .long @got */
2398 0xe59fc000, /* ldr ip,[pc] */
2399 0xea000000, /* b _PLT */
2400 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2403 /* The format of entries in a VxWorks shared library. */
2404 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
2406 0xe59fc000, /* ldr ip,[pc] */
2407 0xe79cf009, /* ldr pc,[ip,r9] */
2408 0x00000000, /* .long @got */
2409 0xe59fc000, /* ldr ip,[pc] */
2410 0xe599f008, /* ldr pc,[r9,#8] */
2411 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2414 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2415 #define PLT_THUMB_STUB_SIZE 4
2416 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2422 /* The entries in a PLT when using a DLL-based target with multiple
2424 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2426 0xe51ff004, /* ldr pc, [pc, #-4] */
2427 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2430 /* The first entry in a procedure linkage table looks like
2431 this. It is set up so that any shared library function that is
2432 called before the relocation has been set up calls the dynamic
2434 static const bfd_vma elf32_arm_nacl_plt0_entry
[] =
2437 0xe300c000, /* movw ip, #:lower16:&GOT[2]-.+8 */
2438 0xe340c000, /* movt ip, #:upper16:&GOT[2]-.+8 */
2439 0xe08cc00f, /* add ip, ip, pc */
2440 0xe52dc008, /* str ip, [sp, #-8]! */
2441 /* Second bundle: */
2442 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2443 0xe59cc000, /* ldr ip, [ip] */
2444 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2445 0xe12fff1c, /* bx ip */
2447 0xe320f000, /* nop */
2448 0xe320f000, /* nop */
2449 0xe320f000, /* nop */
2451 0xe50dc004, /* str ip, [sp, #-4] */
2452 /* Fourth bundle: */
2453 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2454 0xe59cc000, /* ldr ip, [ip] */
2455 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2456 0xe12fff1c, /* bx ip */
2458 #define ARM_NACL_PLT_TAIL_OFFSET (11 * 4)
2460 /* Subsequent entries in a procedure linkage table look like this. */
2461 static const bfd_vma elf32_arm_nacl_plt_entry
[] =
2463 0xe300c000, /* movw ip, #:lower16:&GOT[n]-.+8 */
2464 0xe340c000, /* movt ip, #:upper16:&GOT[n]-.+8 */
2465 0xe08cc00f, /* add ip, ip, pc */
2466 0xea000000, /* b .Lplt_tail */
2469 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2470 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2471 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2472 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2473 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2474 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2475 #define THM2_MAX_FWD_COND_BRANCH_OFFSET (((1 << 20) -2) + 4)
2476 #define THM2_MAX_BWD_COND_BRANCH_OFFSET (-(1 << 20) + 4)
2486 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2487 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2488 is inserted in arm_build_one_stub(). */
2489 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2490 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2491 #define THUMB32_MOVT(X) {(X), THUMB32_TYPE, R_ARM_THM_MOVT_ABS, 0}
2492 #define THUMB32_MOVW(X) {(X), THUMB32_TYPE, R_ARM_THM_MOVW_ABS_NC, 0}
2493 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2494 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2495 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2496 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2501 enum stub_insn_type type
;
2502 unsigned int r_type
;
2506 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2507 to reach the stub if necessary. */
2508 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2510 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2511 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2514 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2516 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2518 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2519 ARM_INSN (0xe12fff1c), /* bx ip */
2520 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2523 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2524 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2526 THUMB16_INSN (0xb401), /* push {r0} */
2527 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2528 THUMB16_INSN (0x4684), /* mov ip, r0 */
2529 THUMB16_INSN (0xbc01), /* pop {r0} */
2530 THUMB16_INSN (0x4760), /* bx ip */
2531 THUMB16_INSN (0xbf00), /* nop */
2532 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2535 /* Thumb -> Thumb long branch stub in thumb2 encoding. Used on armv7. */
2536 static const insn_sequence elf32_arm_stub_long_branch_thumb2_only
[] =
2538 THUMB32_INSN (0xf85ff000), /* ldr.w pc, [pc, #-0] */
2539 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(x) */
2542 /* Thumb -> Thumb long branch stub. Used for PureCode sections on Thumb2
2543 M-profile architectures. */
2544 static const insn_sequence elf32_arm_stub_long_branch_thumb2_only_pure
[] =
2546 THUMB32_MOVW (0xf2400c00), /* mov.w ip, R_ARM_MOVW_ABS_NC */
2547 THUMB32_MOVT (0xf2c00c00), /* movt ip, R_ARM_MOVT_ABS << 16 */
2548 THUMB16_INSN (0x4760), /* bx ip */
2551 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2553 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2555 THUMB16_INSN (0x4778), /* bx pc */
2556 THUMB16_INSN (0x46c0), /* nop */
2557 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2558 ARM_INSN (0xe12fff1c), /* bx ip */
2559 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2562 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2564 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2566 THUMB16_INSN (0x4778), /* bx pc */
2567 THUMB16_INSN (0x46c0), /* nop */
2568 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2569 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2572 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2573 one, when the destination is close enough. */
2574 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2576 THUMB16_INSN (0x4778), /* bx pc */
2577 THUMB16_INSN (0x46c0), /* nop */
2578 ARM_REL_INSN (0xea000000, -8), /* b (X-8) */
2581 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2582 blx to reach the stub if necessary. */
2583 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2585 ARM_INSN (0xe59fc000), /* ldr ip, [pc] */
2586 ARM_INSN (0xe08ff00c), /* add pc, pc, ip */
2587 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2590 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2591 blx to reach the stub if necessary. We can not add into pc;
2592 it is not guaranteed to mode switch (different in ARMv6 and
2594 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2596 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2597 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2598 ARM_INSN (0xe12fff1c), /* bx ip */
2599 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2602 /* V4T ARM -> ARM long branch stub, PIC. */
2603 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2605 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2606 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2607 ARM_INSN (0xe12fff1c), /* bx ip */
2608 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2611 /* V4T Thumb -> ARM long branch stub, PIC. */
2612 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2614 THUMB16_INSN (0x4778), /* bx pc */
2615 THUMB16_INSN (0x46c0), /* nop */
2616 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2617 ARM_INSN (0xe08cf00f), /* add pc, ip, pc */
2618 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2621 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2623 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2625 THUMB16_INSN (0xb401), /* push {r0} */
2626 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2627 THUMB16_INSN (0x46fc), /* mov ip, pc */
2628 THUMB16_INSN (0x4484), /* add ip, r0 */
2629 THUMB16_INSN (0xbc01), /* pop {r0} */
2630 THUMB16_INSN (0x4760), /* bx ip */
2631 DATA_WORD (0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2634 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2636 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2638 THUMB16_INSN (0x4778), /* bx pc */
2639 THUMB16_INSN (0x46c0), /* nop */
2640 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2641 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2642 ARM_INSN (0xe12fff1c), /* bx ip */
2643 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2646 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2647 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2648 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic
[] =
2650 ARM_INSN (0xe59f1000), /* ldr r1, [pc] */
2651 ARM_INSN (0xe08ff001), /* add pc, pc, r1 */
2652 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2655 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2656 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2657 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic
[] =
2659 THUMB16_INSN (0x4778), /* bx pc */
2660 THUMB16_INSN (0x46c0), /* nop */
2661 ARM_INSN (0xe59f1000), /* ldr r1, [pc, #0] */
2662 ARM_INSN (0xe081f00f), /* add pc, r1, pc */
2663 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2666 /* NaCl ARM -> ARM long branch stub. */
2667 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl
[] =
2669 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2670 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2671 ARM_INSN (0xe12fff1c), /* bx ip */
2672 ARM_INSN (0xe320f000), /* nop */
2673 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2674 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2675 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2676 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2679 /* NaCl ARM -> ARM long branch stub, PIC. */
2680 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl_pic
[] =
2682 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2683 ARM_INSN (0xe08cc00f), /* add ip, ip, pc */
2684 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2685 ARM_INSN (0xe12fff1c), /* bx ip */
2686 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2687 DATA_WORD (0, R_ARM_REL32
, 8), /* dcd R_ARM_REL32(X+8) */
2688 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2689 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2692 /* Stub used for transition to secure state (aka SG veneer). */
2693 static const insn_sequence elf32_arm_stub_cmse_branch_thumb_only
[] =
2695 THUMB32_INSN (0xe97fe97f), /* sg. */
2696 THUMB32_B_INSN (0xf000b800, -4), /* b.w original_branch_dest. */
2700 /* Cortex-A8 erratum-workaround stubs. */
2702 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2703 can't use a conditional branch to reach this stub). */
2705 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond
[] =
2707 THUMB16_BCOND_INSN (0xd001), /* b<cond>.n true. */
2708 THUMB32_B_INSN (0xf000b800, -4), /* b.w insn_after_original_branch. */
2709 THUMB32_B_INSN (0xf000b800, -4) /* true: b.w original_branch_dest. */
2712 /* Stub used for b.w and bl.w instructions. */
2714 static const insn_sequence elf32_arm_stub_a8_veneer_b
[] =
2716 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2719 static const insn_sequence elf32_arm_stub_a8_veneer_bl
[] =
2721 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2724 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2725 instruction (which switches to ARM mode) to point to this stub. Jump to the
2726 real destination using an ARM-mode branch. */
2728 static const insn_sequence elf32_arm_stub_a8_veneer_blx
[] =
2730 ARM_REL_INSN (0xea000000, -8) /* b original_branch_dest. */
2733 /* For each section group there can be a specially created linker section
2734 to hold the stubs for that group. The name of the stub section is based
2735 upon the name of another section within that group with the suffix below
2738 PR 13049: STUB_SUFFIX used to be ".stub", but this allowed the user to
2739 create what appeared to be a linker stub section when it actually
2740 contained user code/data. For example, consider this fragment:
2742 const char * stubborn_problems[] = { "np" };
2744 If this is compiled with "-fPIC -fdata-sections" then gcc produces a
2747 .data.rel.local.stubborn_problems
2749 This then causes problems in arm32_arm_build_stubs() as it triggers:
2751 // Ignore non-stub sections.
2752 if (!strstr (stub_sec->name, STUB_SUFFIX))
2755 And so the section would be ignored instead of being processed. Hence
2756 the change in definition of STUB_SUFFIX to a name that cannot be a valid
2758 #define STUB_SUFFIX ".__stub"
2760 /* One entry per long/short branch stub defined above. */
2762 DEF_STUB(long_branch_any_any) \
2763 DEF_STUB(long_branch_v4t_arm_thumb) \
2764 DEF_STUB(long_branch_thumb_only) \
2765 DEF_STUB(long_branch_v4t_thumb_thumb) \
2766 DEF_STUB(long_branch_v4t_thumb_arm) \
2767 DEF_STUB(short_branch_v4t_thumb_arm) \
2768 DEF_STUB(long_branch_any_arm_pic) \
2769 DEF_STUB(long_branch_any_thumb_pic) \
2770 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2771 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2772 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2773 DEF_STUB(long_branch_thumb_only_pic) \
2774 DEF_STUB(long_branch_any_tls_pic) \
2775 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2776 DEF_STUB(long_branch_arm_nacl) \
2777 DEF_STUB(long_branch_arm_nacl_pic) \
2778 DEF_STUB(cmse_branch_thumb_only) \
2779 DEF_STUB(a8_veneer_b_cond) \
2780 DEF_STUB(a8_veneer_b) \
2781 DEF_STUB(a8_veneer_bl) \
2782 DEF_STUB(a8_veneer_blx) \
2783 DEF_STUB(long_branch_thumb2_only) \
2784 DEF_STUB(long_branch_thumb2_only_pure)
2786 #define DEF_STUB(x) arm_stub_##x,
2787 enum elf32_arm_stub_type
2795 /* Note the first a8_veneer type. */
2796 const unsigned arm_stub_a8_veneer_lwm
= arm_stub_a8_veneer_b_cond
;
2800 const insn_sequence
* template_sequence
;
2804 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2805 static const stub_def stub_definitions
[] =
2811 struct elf32_arm_stub_hash_entry
2813 /* Base hash table entry structure. */
2814 struct bfd_hash_entry root
;
2816 /* The stub section. */
2819 /* Offset within stub_sec of the beginning of this stub. */
2820 bfd_vma stub_offset
;
2822 /* Given the symbol's value and its section we can determine its final
2823 value when building the stubs (so the stub knows where to jump). */
2824 bfd_vma target_value
;
2825 asection
*target_section
;
2827 /* Same as above but for the source of the branch to the stub. Used for
2828 Cortex-A8 erratum workaround to patch it to branch to the stub. As
2829 such, source section does not need to be recorded since Cortex-A8 erratum
2830 workaround stubs are only generated when both source and target are in the
2832 bfd_vma source_value
;
2834 /* The instruction which caused this stub to be generated (only valid for
2835 Cortex-A8 erratum workaround stubs at present). */
2836 unsigned long orig_insn
;
2838 /* The stub type. */
2839 enum elf32_arm_stub_type stub_type
;
2840 /* Its encoding size in bytes. */
2843 const insn_sequence
*stub_template
;
2844 /* The size of the template (number of entries). */
2845 int stub_template_size
;
2847 /* The symbol table entry, if any, that this was derived from. */
2848 struct elf32_arm_link_hash_entry
*h
;
2850 /* Type of branch. */
2851 enum arm_st_branch_type branch_type
;
2853 /* Where this stub is being called from, or, in the case of combined
2854 stub sections, the first input section in the group. */
2857 /* The name for the local symbol at the start of this stub. The
2858 stub name in the hash table has to be unique; this does not, so
2859 it can be friendlier. */
2863 /* Used to build a map of a section. This is required for mixed-endian
2866 typedef struct elf32_elf_section_map
2871 elf32_arm_section_map
;
2873 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2877 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2878 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2879 VFP11_ERRATUM_ARM_VENEER
,
2880 VFP11_ERRATUM_THUMB_VENEER
2882 elf32_vfp11_erratum_type
;
2884 typedef struct elf32_vfp11_erratum_list
2886 struct elf32_vfp11_erratum_list
*next
;
2892 struct elf32_vfp11_erratum_list
*veneer
;
2893 unsigned int vfp_insn
;
2897 struct elf32_vfp11_erratum_list
*branch
;
2901 elf32_vfp11_erratum_type type
;
2903 elf32_vfp11_erratum_list
;
2905 /* Information about a STM32L4XX erratum veneer, or a branch to such a
2909 STM32L4XX_ERRATUM_BRANCH_TO_VENEER
,
2910 STM32L4XX_ERRATUM_VENEER
2912 elf32_stm32l4xx_erratum_type
;
2914 typedef struct elf32_stm32l4xx_erratum_list
2916 struct elf32_stm32l4xx_erratum_list
*next
;
2922 struct elf32_stm32l4xx_erratum_list
*veneer
;
2927 struct elf32_stm32l4xx_erratum_list
*branch
;
2931 elf32_stm32l4xx_erratum_type type
;
2933 elf32_stm32l4xx_erratum_list
;
2938 INSERT_EXIDX_CANTUNWIND_AT_END
2940 arm_unwind_edit_type
;
2942 /* A (sorted) list of edits to apply to an unwind table. */
2943 typedef struct arm_unwind_table_edit
2945 arm_unwind_edit_type type
;
2946 /* Note: we sometimes want to insert an unwind entry corresponding to a
2947 section different from the one we're currently writing out, so record the
2948 (text) section this edit relates to here. */
2949 asection
*linked_section
;
2951 struct arm_unwind_table_edit
*next
;
2953 arm_unwind_table_edit
;
2955 typedef struct _arm_elf_section_data
2957 /* Information about mapping symbols. */
2958 struct bfd_elf_section_data elf
;
2959 unsigned int mapcount
;
2960 unsigned int mapsize
;
2961 elf32_arm_section_map
*map
;
2962 /* Information about CPU errata. */
2963 unsigned int erratumcount
;
2964 elf32_vfp11_erratum_list
*erratumlist
;
2965 unsigned int stm32l4xx_erratumcount
;
2966 elf32_stm32l4xx_erratum_list
*stm32l4xx_erratumlist
;
2967 unsigned int additional_reloc_count
;
2968 /* Information about unwind tables. */
2971 /* Unwind info attached to a text section. */
2974 asection
*arm_exidx_sec
;
2977 /* Unwind info attached to an .ARM.exidx section. */
2980 arm_unwind_table_edit
*unwind_edit_list
;
2981 arm_unwind_table_edit
*unwind_edit_tail
;
2985 _arm_elf_section_data
;
2987 #define elf32_arm_section_data(sec) \
2988 ((_arm_elf_section_data *) elf_section_data (sec))
2990 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2991 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2992 so may be created multiple times: we use an array of these entries whilst
2993 relaxing which we can refresh easily, then create stubs for each potentially
2994 erratum-triggering instruction once we've settled on a solution. */
2996 struct a8_erratum_fix
3001 bfd_vma target_offset
;
3002 unsigned long orig_insn
;
3004 enum elf32_arm_stub_type stub_type
;
3005 enum arm_st_branch_type branch_type
;
3008 /* A table of relocs applied to branches which might trigger Cortex-A8
3011 struct a8_erratum_reloc
3014 bfd_vma destination
;
3015 struct elf32_arm_link_hash_entry
*hash
;
3016 const char *sym_name
;
3017 unsigned int r_type
;
3018 enum arm_st_branch_type branch_type
;
3019 bfd_boolean non_a8_stub
;
3022 /* The size of the thread control block. */
3025 /* ARM-specific information about a PLT entry, over and above the usual
3029 /* We reference count Thumb references to a PLT entry separately,
3030 so that we can emit the Thumb trampoline only if needed. */
3031 bfd_signed_vma thumb_refcount
;
3033 /* Some references from Thumb code may be eliminated by BL->BLX
3034 conversion, so record them separately. */
3035 bfd_signed_vma maybe_thumb_refcount
;
3037 /* How many of the recorded PLT accesses were from non-call relocations.
3038 This information is useful when deciding whether anything takes the
3039 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
3040 non-call references to the function should resolve directly to the
3041 real runtime target. */
3042 unsigned int noncall_refcount
;
3044 /* Since PLT entries have variable size if the Thumb prologue is
3045 used, we need to record the index into .got.plt instead of
3046 recomputing it from the PLT offset. */
3047 bfd_signed_vma got_offset
;
3050 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
3051 struct arm_local_iplt_info
3053 /* The information that is usually found in the generic ELF part of
3054 the hash table entry. */
3055 union gotplt_union root
;
3057 /* The information that is usually found in the ARM-specific part of
3058 the hash table entry. */
3059 struct arm_plt_info arm
;
3061 /* A list of all potential dynamic relocations against this symbol. */
3062 struct elf_dyn_relocs
*dyn_relocs
;
3065 /* Structure to handle FDPIC support for local functions. */
3066 struct fdpic_local
{
3067 unsigned int funcdesc_cnt
;
3068 unsigned int gotofffuncdesc_cnt
;
3069 int funcdesc_offset
;
3072 struct elf_arm_obj_tdata
3074 struct elf_obj_tdata root
;
3076 /* tls_type for each local got entry. */
3077 char *local_got_tls_type
;
3079 /* GOTPLT entries for TLS descriptors. */
3080 bfd_vma
*local_tlsdesc_gotent
;
3082 /* Information for local symbols that need entries in .iplt. */
3083 struct arm_local_iplt_info
**local_iplt
;
3085 /* Zero to warn when linking objects with incompatible enum sizes. */
3086 int no_enum_size_warning
;
3088 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
3089 int no_wchar_size_warning
;
3091 /* Maintains FDPIC counters and funcdesc info. */
3092 struct fdpic_local
*local_fdpic_cnts
;
3095 #define elf_arm_tdata(bfd) \
3096 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
3098 #define elf32_arm_local_got_tls_type(bfd) \
3099 (elf_arm_tdata (bfd)->local_got_tls_type)
3101 #define elf32_arm_local_tlsdesc_gotent(bfd) \
3102 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
3104 #define elf32_arm_local_iplt(bfd) \
3105 (elf_arm_tdata (bfd)->local_iplt)
3107 #define elf32_arm_local_fdpic_cnts(bfd) \
3108 (elf_arm_tdata (bfd)->local_fdpic_cnts)
3110 #define is_arm_elf(bfd) \
3111 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
3112 && elf_tdata (bfd) != NULL \
3113 && elf_object_id (bfd) == ARM_ELF_DATA)
3116 elf32_arm_mkobject (bfd
*abfd
)
3118 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
3122 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
3124 /* Structure to handle FDPIC support for extern functions. */
3125 struct fdpic_global
{
3126 unsigned int gotofffuncdesc_cnt
;
3127 unsigned int gotfuncdesc_cnt
;
3128 unsigned int funcdesc_cnt
;
3129 int funcdesc_offset
;
3130 int gotfuncdesc_offset
;
3133 /* Arm ELF linker hash entry. */
3134 struct elf32_arm_link_hash_entry
3136 struct elf_link_hash_entry root
;
3138 /* Track dynamic relocs copied for this symbol. */
3139 struct elf_dyn_relocs
*dyn_relocs
;
3141 /* ARM-specific PLT information. */
3142 struct arm_plt_info plt
;
3144 #define GOT_UNKNOWN 0
3145 #define GOT_NORMAL 1
3146 #define GOT_TLS_GD 2
3147 #define GOT_TLS_IE 4
3148 #define GOT_TLS_GDESC 8
3149 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
3150 unsigned int tls_type
: 8;
3152 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
3153 unsigned int is_iplt
: 1;
3155 unsigned int unused
: 23;
3157 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
3158 starting at the end of the jump table. */
3159 bfd_vma tlsdesc_got
;
3161 /* The symbol marking the real symbol location for exported thumb
3162 symbols with Arm stubs. */
3163 struct elf_link_hash_entry
*export_glue
;
3165 /* A pointer to the most recently used stub hash entry against this
3167 struct elf32_arm_stub_hash_entry
*stub_cache
;
3169 /* Counter for FDPIC relocations against this symbol. */
3170 struct fdpic_global fdpic_cnts
;
3173 /* Traverse an arm ELF linker hash table. */
3174 #define elf32_arm_link_hash_traverse(table, func, info) \
3175 (elf_link_hash_traverse \
3177 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3180 /* Get the ARM elf linker hash table from a link_info structure. */
3181 #define elf32_arm_hash_table(info) \
3182 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
3183 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
3185 #define arm_stub_hash_lookup(table, string, create, copy) \
3186 ((struct elf32_arm_stub_hash_entry *) \
3187 bfd_hash_lookup ((table), (string), (create), (copy)))
3189 /* Array to keep track of which stub sections have been created, and
3190 information on stub grouping. */
3193 /* This is the section to which stubs in the group will be
3196 /* The stub section. */
3200 #define elf32_arm_compute_jump_table_size(htab) \
3201 ((htab)->next_tls_desc_index * 4)
3203 /* ARM ELF linker hash table. */
3204 struct elf32_arm_link_hash_table
3206 /* The main hash table. */
3207 struct elf_link_hash_table root
;
3209 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
3210 bfd_size_type thumb_glue_size
;
3212 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
3213 bfd_size_type arm_glue_size
;
3215 /* The size in bytes of section containing the ARMv4 BX veneers. */
3216 bfd_size_type bx_glue_size
;
3218 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
3219 veneer has been populated. */
3220 bfd_vma bx_glue_offset
[15];
3222 /* The size in bytes of the section containing glue for VFP11 erratum
3224 bfd_size_type vfp11_erratum_glue_size
;
3226 /* The size in bytes of the section containing glue for STM32L4XX erratum
3228 bfd_size_type stm32l4xx_erratum_glue_size
;
3230 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
3231 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
3232 elf32_arm_write_section(). */
3233 struct a8_erratum_fix
*a8_erratum_fixes
;
3234 unsigned int num_a8_erratum_fixes
;
3236 /* An arbitrary input BFD chosen to hold the glue sections. */
3237 bfd
* bfd_of_glue_owner
;
3239 /* Nonzero to output a BE8 image. */
3242 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
3243 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
3246 /* The relocation to use for R_ARM_TARGET2 relocations. */
3249 /* 0 = Ignore R_ARM_V4BX.
3250 1 = Convert BX to MOV PC.
3251 2 = Generate v4 interworing stubs. */
3254 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
3257 /* Whether we should fix the ARM1176 BLX immediate issue. */
3260 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
3263 /* What sort of code sequences we should look for which may trigger the
3264 VFP11 denorm erratum. */
3265 bfd_arm_vfp11_fix vfp11_fix
;
3267 /* Global counter for the number of fixes we have emitted. */
3268 int num_vfp11_fixes
;
3270 /* What sort of code sequences we should look for which may trigger the
3271 STM32L4XX erratum. */
3272 bfd_arm_stm32l4xx_fix stm32l4xx_fix
;
3274 /* Global counter for the number of fixes we have emitted. */
3275 int num_stm32l4xx_fixes
;
3277 /* Nonzero to force PIC branch veneers. */
3280 /* The number of bytes in the initial entry in the PLT. */
3281 bfd_size_type plt_header_size
;
3283 /* The number of bytes in the subsequent PLT etries. */
3284 bfd_size_type plt_entry_size
;
3286 /* True if the target system is VxWorks. */
3289 /* True if the target system is Symbian OS. */
3292 /* True if the target system is Native Client. */
3295 /* True if the target uses REL relocations. */
3296 bfd_boolean use_rel
;
3298 /* Nonzero if import library must be a secure gateway import library
3299 as per ARMv8-M Security Extensions. */
3302 /* The import library whose symbols' address must remain stable in
3303 the import library generated. */
3306 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
3307 bfd_vma next_tls_desc_index
;
3309 /* How many R_ARM_TLS_DESC relocations were generated so far. */
3310 bfd_vma num_tls_desc
;
3312 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
3315 /* The offset into splt of the PLT entry for the TLS descriptor
3316 resolver. Special values are 0, if not necessary (or not found
3317 to be necessary yet), and -1 if needed but not determined
3319 bfd_vma dt_tlsdesc_plt
;
3321 /* The offset into sgot of the GOT entry used by the PLT entry
3323 bfd_vma dt_tlsdesc_got
;
3325 /* Offset in .plt section of tls_arm_trampoline. */
3326 bfd_vma tls_trampoline
;
3328 /* Data for R_ARM_TLS_LDM32/R_ARM_TLS_LDM32_FDPIC relocations. */
3331 bfd_signed_vma refcount
;
3335 /* Small local sym cache. */
3336 struct sym_cache sym_cache
;
3338 /* For convenience in allocate_dynrelocs. */
3341 /* The amount of space used by the reserved portion of the sgotplt
3342 section, plus whatever space is used by the jump slots. */
3343 bfd_vma sgotplt_jump_table_size
;
3345 /* The stub hash table. */
3346 struct bfd_hash_table stub_hash_table
;
3348 /* Linker stub bfd. */
3351 /* Linker call-backs. */
3352 asection
* (*add_stub_section
) (const char *, asection
*, asection
*,
3354 void (*layout_sections_again
) (void);
3356 /* Array to keep track of which stub sections have been created, and
3357 information on stub grouping. */
3358 struct map_stub
*stub_group
;
3360 /* Input stub section holding secure gateway veneers. */
3361 asection
*cmse_stub_sec
;
3363 /* Offset in cmse_stub_sec where new SG veneers (not in input import library)
3364 start to be allocated. */
3365 bfd_vma new_cmse_stub_offset
;
3367 /* Number of elements in stub_group. */
3368 unsigned int top_id
;
3370 /* Assorted information used by elf32_arm_size_stubs. */
3371 unsigned int bfd_count
;
3372 unsigned int top_index
;
3373 asection
**input_list
;
3375 /* True if the target system uses FDPIC. */
3378 /* Fixup section. Used for FDPIC. */
3382 /* Add an FDPIC read-only fixup. */
3384 arm_elf_add_rofixup (bfd
*output_bfd
, asection
*srofixup
, bfd_vma offset
)
3386 bfd_vma fixup_offset
;
3388 fixup_offset
= srofixup
->reloc_count
++ * 4;
3389 BFD_ASSERT (fixup_offset
< srofixup
->size
);
3390 bfd_put_32 (output_bfd
, offset
, srofixup
->contents
+ fixup_offset
);
3394 ctz (unsigned int mask
)
3396 #if GCC_VERSION >= 3004
3397 return __builtin_ctz (mask
);
3401 for (i
= 0; i
< 8 * sizeof (mask
); i
++)
3412 elf32_arm_popcount (unsigned int mask
)
3414 #if GCC_VERSION >= 3004
3415 return __builtin_popcount (mask
);
3420 for (i
= 0; i
< 8 * sizeof (mask
); i
++)
3430 static void elf32_arm_add_dynreloc (bfd
*output_bfd
, struct bfd_link_info
*info
,
3431 asection
*sreloc
, Elf_Internal_Rela
*rel
);
3434 arm_elf_fill_funcdesc(bfd
*output_bfd
,
3435 struct bfd_link_info
*info
,
3436 int *funcdesc_offset
,
3440 bfd_vma dynreloc_value
,
3443 if ((*funcdesc_offset
& 1) == 0)
3445 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
3446 asection
*sgot
= globals
->root
.sgot
;
3448 if (bfd_link_pic(info
))
3450 asection
*srelgot
= globals
->root
.srelgot
;
3451 Elf_Internal_Rela outrel
;
3453 outrel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_FUNCDESC_VALUE
);
3454 outrel
.r_offset
= sgot
->output_section
->vma
+ sgot
->output_offset
+ offset
;
3455 outrel
.r_addend
= 0;
3457 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
3458 bfd_put_32 (output_bfd
, addr
, sgot
->contents
+ offset
);
3459 bfd_put_32 (output_bfd
, seg
, sgot
->contents
+ offset
+ 4);
3463 struct elf_link_hash_entry
*hgot
= globals
->root
.hgot
;
3464 bfd_vma got_value
= hgot
->root
.u
.def
.value
3465 + hgot
->root
.u
.def
.section
->output_section
->vma
3466 + hgot
->root
.u
.def
.section
->output_offset
;
3468 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
,
3469 sgot
->output_section
->vma
+ sgot
->output_offset
3471 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
,
3472 sgot
->output_section
->vma
+ sgot
->output_offset
3474 bfd_put_32 (output_bfd
, dynreloc_value
, sgot
->contents
+ offset
);
3475 bfd_put_32 (output_bfd
, got_value
, sgot
->contents
+ offset
+ 4);
3477 *funcdesc_offset
|= 1;
3481 /* Create an entry in an ARM ELF linker hash table. */
3483 static struct bfd_hash_entry
*
3484 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
3485 struct bfd_hash_table
* table
,
3486 const char * string
)
3488 struct elf32_arm_link_hash_entry
* ret
=
3489 (struct elf32_arm_link_hash_entry
*) entry
;
3491 /* Allocate the structure if it has not already been allocated by a
3494 ret
= (struct elf32_arm_link_hash_entry
*)
3495 bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
3497 return (struct bfd_hash_entry
*) ret
;
3499 /* Call the allocation method of the superclass. */
3500 ret
= ((struct elf32_arm_link_hash_entry
*)
3501 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3505 ret
->dyn_relocs
= NULL
;
3506 ret
->tls_type
= GOT_UNKNOWN
;
3507 ret
->tlsdesc_got
= (bfd_vma
) -1;
3508 ret
->plt
.thumb_refcount
= 0;
3509 ret
->plt
.maybe_thumb_refcount
= 0;
3510 ret
->plt
.noncall_refcount
= 0;
3511 ret
->plt
.got_offset
= -1;
3512 ret
->is_iplt
= FALSE
;
3513 ret
->export_glue
= NULL
;
3515 ret
->stub_cache
= NULL
;
3517 ret
->fdpic_cnts
.gotofffuncdesc_cnt
= 0;
3518 ret
->fdpic_cnts
.gotfuncdesc_cnt
= 0;
3519 ret
->fdpic_cnts
.funcdesc_cnt
= 0;
3520 ret
->fdpic_cnts
.funcdesc_offset
= -1;
3521 ret
->fdpic_cnts
.gotfuncdesc_offset
= -1;
3524 return (struct bfd_hash_entry
*) ret
;
3527 /* Ensure that we have allocated bookkeeping structures for ABFD's local
3531 elf32_arm_allocate_local_sym_info (bfd
*abfd
)
3533 if (elf_local_got_refcounts (abfd
) == NULL
)
3535 bfd_size_type num_syms
;
3539 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
3540 size
= num_syms
* (sizeof (bfd_signed_vma
)
3541 + sizeof (struct arm_local_iplt_info
*)
3544 + sizeof (struct fdpic_local
));
3545 data
= bfd_zalloc (abfd
, size
);
3549 elf32_arm_local_fdpic_cnts (abfd
) = (struct fdpic_local
*) data
;
3550 data
+= num_syms
* sizeof (struct fdpic_local
);
3552 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
3553 data
+= num_syms
* sizeof (bfd_signed_vma
);
3555 elf32_arm_local_iplt (abfd
) = (struct arm_local_iplt_info
**) data
;
3556 data
+= num_syms
* sizeof (struct arm_local_iplt_info
*);
3558 elf32_arm_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
3559 data
+= num_syms
* sizeof (bfd_vma
);
3561 elf32_arm_local_got_tls_type (abfd
) = data
;
3566 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
3567 to input bfd ABFD. Create the information if it doesn't already exist.
3568 Return null if an allocation fails. */
3570 static struct arm_local_iplt_info
*
3571 elf32_arm_create_local_iplt (bfd
*abfd
, unsigned long r_symndx
)
3573 struct arm_local_iplt_info
**ptr
;
3575 if (!elf32_arm_allocate_local_sym_info (abfd
))
3578 BFD_ASSERT (r_symndx
< elf_tdata (abfd
)->symtab_hdr
.sh_info
);
3579 ptr
= &elf32_arm_local_iplt (abfd
)[r_symndx
];
3581 *ptr
= bfd_zalloc (abfd
, sizeof (**ptr
));
3585 /* Try to obtain PLT information for the symbol with index R_SYMNDX
3586 in ABFD's symbol table. If the symbol is global, H points to its
3587 hash table entry, otherwise H is null.
3589 Return true if the symbol does have PLT information. When returning
3590 true, point *ROOT_PLT at the target-independent reference count/offset
3591 union and *ARM_PLT at the ARM-specific information. */
3594 elf32_arm_get_plt_info (bfd
*abfd
, struct elf32_arm_link_hash_table
*globals
,
3595 struct elf32_arm_link_hash_entry
*h
,
3596 unsigned long r_symndx
, union gotplt_union
**root_plt
,
3597 struct arm_plt_info
**arm_plt
)
3599 struct arm_local_iplt_info
*local_iplt
;
3601 if (globals
->root
.splt
== NULL
&& globals
->root
.iplt
== NULL
)
3606 *root_plt
= &h
->root
.plt
;
3611 if (elf32_arm_local_iplt (abfd
) == NULL
)
3614 local_iplt
= elf32_arm_local_iplt (abfd
)[r_symndx
];
3615 if (local_iplt
== NULL
)
3618 *root_plt
= &local_iplt
->root
;
3619 *arm_plt
= &local_iplt
->arm
;
3623 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3627 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info
*info
,
3628 struct arm_plt_info
*arm_plt
)
3630 struct elf32_arm_link_hash_table
*htab
;
3632 htab
= elf32_arm_hash_table (info
);
3633 return (arm_plt
->thumb_refcount
!= 0
3634 || (!htab
->use_blx
&& arm_plt
->maybe_thumb_refcount
!= 0));
3637 /* Return a pointer to the head of the dynamic reloc list that should
3638 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3639 ABFD's symbol table. Return null if an error occurs. */
3641 static struct elf_dyn_relocs
**
3642 elf32_arm_get_local_dynreloc_list (bfd
*abfd
, unsigned long r_symndx
,
3643 Elf_Internal_Sym
*isym
)
3645 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
3647 struct arm_local_iplt_info
*local_iplt
;
3649 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
3650 if (local_iplt
== NULL
)
3652 return &local_iplt
->dyn_relocs
;
3656 /* Track dynamic relocs needed for local syms too.
3657 We really need local syms available to do this
3662 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3666 vpp
= &elf_section_data (s
)->local_dynrel
;
3667 return (struct elf_dyn_relocs
**) vpp
;
3671 /* Initialize an entry in the stub hash table. */
3673 static struct bfd_hash_entry
*
3674 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3675 struct bfd_hash_table
*table
,
3678 /* Allocate the structure if it has not already been allocated by a
3682 entry
= (struct bfd_hash_entry
*)
3683 bfd_hash_allocate (table
, sizeof (struct elf32_arm_stub_hash_entry
));
3688 /* Call the allocation method of the superclass. */
3689 entry
= bfd_hash_newfunc (entry
, table
, string
);
3692 struct elf32_arm_stub_hash_entry
*eh
;
3694 /* Initialize the local fields. */
3695 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
3696 eh
->stub_sec
= NULL
;
3697 eh
->stub_offset
= (bfd_vma
) -1;
3698 eh
->source_value
= 0;
3699 eh
->target_value
= 0;
3700 eh
->target_section
= NULL
;
3702 eh
->stub_type
= arm_stub_none
;
3704 eh
->stub_template
= NULL
;
3705 eh
->stub_template_size
= -1;
3708 eh
->output_name
= NULL
;
3714 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3715 shortcuts to them in our hash table. */
3718 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3720 struct elf32_arm_link_hash_table
*htab
;
3722 htab
= elf32_arm_hash_table (info
);
3726 /* BPABI objects never have a GOT, or associated sections. */
3727 if (htab
->symbian_p
)
3730 if (! _bfd_elf_create_got_section (dynobj
, info
))
3733 /* Also create .rofixup. */
3736 htab
->srofixup
= bfd_make_section_with_flags (dynobj
, ".rofixup",
3737 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3738 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
| SEC_READONLY
));
3739 if (htab
->srofixup
== NULL
|| ! bfd_set_section_alignment (dynobj
, htab
->srofixup
, 2))
3746 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3749 create_ifunc_sections (struct bfd_link_info
*info
)
3751 struct elf32_arm_link_hash_table
*htab
;
3752 const struct elf_backend_data
*bed
;
3757 htab
= elf32_arm_hash_table (info
);
3758 dynobj
= htab
->root
.dynobj
;
3759 bed
= get_elf_backend_data (dynobj
);
3760 flags
= bed
->dynamic_sec_flags
;
3762 if (htab
->root
.iplt
== NULL
)
3764 s
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt",
3765 flags
| SEC_READONLY
| SEC_CODE
);
3767 || !bfd_set_section_alignment (dynobj
, s
, bed
->plt_alignment
))
3769 htab
->root
.iplt
= s
;
3772 if (htab
->root
.irelplt
== NULL
)
3774 s
= bfd_make_section_anyway_with_flags (dynobj
,
3775 RELOC_SECTION (htab
, ".iplt"),
3776 flags
| SEC_READONLY
);
3778 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3780 htab
->root
.irelplt
= s
;
3783 if (htab
->root
.igotplt
== NULL
)
3785 s
= bfd_make_section_anyway_with_flags (dynobj
, ".igot.plt", flags
);
3787 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3789 htab
->root
.igotplt
= s
;
3794 /* Determine if we're dealing with a Thumb only architecture. */
3797 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
3800 int profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3801 Tag_CPU_arch_profile
);
3804 return profile
== 'M';
3806 arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
3808 /* Force return logic to be reviewed for each new architecture. */
3809 BFD_ASSERT (arch
<= TAG_CPU_ARCH_V8M_MAIN
);
3811 if (arch
== TAG_CPU_ARCH_V6_M
3812 || arch
== TAG_CPU_ARCH_V6S_M
3813 || arch
== TAG_CPU_ARCH_V7E_M
3814 || arch
== TAG_CPU_ARCH_V8M_BASE
3815 || arch
== TAG_CPU_ARCH_V8M_MAIN
)
3821 /* Determine if we're dealing with a Thumb-2 object. */
3824 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
3827 int thumb_isa
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3831 return thumb_isa
== 2;
3833 arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
3835 /* Force return logic to be reviewed for each new architecture. */
3836 BFD_ASSERT (arch
<= TAG_CPU_ARCH_V8M_MAIN
);
3838 return (arch
== TAG_CPU_ARCH_V6T2
3839 || arch
== TAG_CPU_ARCH_V7
3840 || arch
== TAG_CPU_ARCH_V7E_M
3841 || arch
== TAG_CPU_ARCH_V8
3842 || arch
== TAG_CPU_ARCH_V8R
3843 || arch
== TAG_CPU_ARCH_V8M_MAIN
);
3846 /* Determine whether Thumb-2 BL instruction is available. */
3849 using_thumb2_bl (struct elf32_arm_link_hash_table
*globals
)
3852 bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
3854 /* Force return logic to be reviewed for each new architecture. */
3855 BFD_ASSERT (arch
<= TAG_CPU_ARCH_V8M_MAIN
);
3857 /* Architecture was introduced after ARMv6T2 (eg. ARMv6-M). */
3858 return (arch
== TAG_CPU_ARCH_V6T2
3859 || arch
>= TAG_CPU_ARCH_V7
);
3862 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3863 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3867 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3869 struct elf32_arm_link_hash_table
*htab
;
3871 htab
= elf32_arm_hash_table (info
);
3875 if (!htab
->root
.sgot
&& !create_got_section (dynobj
, info
))
3878 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3881 if (htab
->vxworks_p
)
3883 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
3886 if (bfd_link_pic (info
))
3888 htab
->plt_header_size
= 0;
3889 htab
->plt_entry_size
3890 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
3894 htab
->plt_header_size
3895 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
3896 htab
->plt_entry_size
3897 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
3900 if (elf_elfheader (dynobj
))
3901 elf_elfheader (dynobj
)->e_ident
[EI_CLASS
] = ELFCLASS32
;
3906 Test for thumb only architectures. Note - we cannot just call
3907 using_thumb_only() as the attributes in the output bfd have not been
3908 initialised at this point, so instead we use the input bfd. */
3909 bfd
* saved_obfd
= htab
->obfd
;
3911 htab
->obfd
= dynobj
;
3912 if (using_thumb_only (htab
))
3914 htab
->plt_header_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry
);
3915 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt_entry
);
3917 htab
->obfd
= saved_obfd
;
3920 if (htab
->fdpic_p
) {
3921 htab
->plt_header_size
= 0;
3922 if (info
->flags
& DF_BIND_NOW
)
3923 htab
->plt_entry_size
= 4 * (ARRAY_SIZE(elf32_arm_fdpic_plt_entry
) - 5);
3925 htab
->plt_entry_size
= 4 * ARRAY_SIZE(elf32_arm_fdpic_plt_entry
);
3928 if (!htab
->root
.splt
3929 || !htab
->root
.srelplt
3930 || !htab
->root
.sdynbss
3931 || (!bfd_link_pic (info
) && !htab
->root
.srelbss
))
3937 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3940 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
3941 struct elf_link_hash_entry
*dir
,
3942 struct elf_link_hash_entry
*ind
)
3944 struct elf32_arm_link_hash_entry
*edir
, *eind
;
3946 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
3947 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
3949 if (eind
->dyn_relocs
!= NULL
)
3951 if (edir
->dyn_relocs
!= NULL
)
3953 struct elf_dyn_relocs
**pp
;
3954 struct elf_dyn_relocs
*p
;
3956 /* Add reloc counts against the indirect sym to the direct sym
3957 list. Merge any entries against the same section. */
3958 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3960 struct elf_dyn_relocs
*q
;
3962 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3963 if (q
->sec
== p
->sec
)
3965 q
->pc_count
+= p
->pc_count
;
3966 q
->count
+= p
->count
;
3973 *pp
= edir
->dyn_relocs
;
3976 edir
->dyn_relocs
= eind
->dyn_relocs
;
3977 eind
->dyn_relocs
= NULL
;
3980 if (ind
->root
.type
== bfd_link_hash_indirect
)
3982 /* Copy over PLT info. */
3983 edir
->plt
.thumb_refcount
+= eind
->plt
.thumb_refcount
;
3984 eind
->plt
.thumb_refcount
= 0;
3985 edir
->plt
.maybe_thumb_refcount
+= eind
->plt
.maybe_thumb_refcount
;
3986 eind
->plt
.maybe_thumb_refcount
= 0;
3987 edir
->plt
.noncall_refcount
+= eind
->plt
.noncall_refcount
;
3988 eind
->plt
.noncall_refcount
= 0;
3990 /* Copy FDPIC counters. */
3991 edir
->fdpic_cnts
.gotofffuncdesc_cnt
+= eind
->fdpic_cnts
.gotofffuncdesc_cnt
;
3992 edir
->fdpic_cnts
.gotfuncdesc_cnt
+= eind
->fdpic_cnts
.gotfuncdesc_cnt
;
3993 edir
->fdpic_cnts
.funcdesc_cnt
+= eind
->fdpic_cnts
.funcdesc_cnt
;
3995 /* We should only allocate a function to .iplt once the final
3996 symbol information is known. */
3997 BFD_ASSERT (!eind
->is_iplt
);
3999 if (dir
->got
.refcount
<= 0)
4001 edir
->tls_type
= eind
->tls_type
;
4002 eind
->tls_type
= GOT_UNKNOWN
;
4006 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
4009 /* Destroy an ARM elf linker hash table. */
4012 elf32_arm_link_hash_table_free (bfd
*obfd
)
4014 struct elf32_arm_link_hash_table
*ret
4015 = (struct elf32_arm_link_hash_table
*) obfd
->link
.hash
;
4017 bfd_hash_table_free (&ret
->stub_hash_table
);
4018 _bfd_elf_link_hash_table_free (obfd
);
4021 /* Create an ARM elf linker hash table. */
4023 static struct bfd_link_hash_table
*
4024 elf32_arm_link_hash_table_create (bfd
*abfd
)
4026 struct elf32_arm_link_hash_table
*ret
;
4027 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
4029 ret
= (struct elf32_arm_link_hash_table
*) bfd_zmalloc (amt
);
4033 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
4034 elf32_arm_link_hash_newfunc
,
4035 sizeof (struct elf32_arm_link_hash_entry
),
4042 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
4043 ret
->stm32l4xx_fix
= BFD_ARM_STM32L4XX_FIX_NONE
;
4044 #ifdef FOUR_WORD_PLT
4045 ret
->plt_header_size
= 16;
4046 ret
->plt_entry_size
= 16;
4048 ret
->plt_header_size
= 20;
4049 ret
->plt_entry_size
= elf32_arm_use_long_plt_entry
? 16 : 12;
4051 ret
->use_rel
= TRUE
;
4055 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
4056 sizeof (struct elf32_arm_stub_hash_entry
)))
4058 _bfd_elf_link_hash_table_free (abfd
);
4061 ret
->root
.root
.hash_table_free
= elf32_arm_link_hash_table_free
;
4063 return &ret
->root
.root
;
4066 /* Determine what kind of NOPs are available. */
4069 arch_has_arm_nop (struct elf32_arm_link_hash_table
*globals
)
4071 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
4074 /* Force return logic to be reviewed for each new architecture. */
4075 BFD_ASSERT (arch
<= TAG_CPU_ARCH_V8M_MAIN
);
4077 return (arch
== TAG_CPU_ARCH_V6T2
4078 || arch
== TAG_CPU_ARCH_V6K
4079 || arch
== TAG_CPU_ARCH_V7
4080 || arch
== TAG_CPU_ARCH_V8
4081 || arch
== TAG_CPU_ARCH_V8R
);
4085 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
4089 case arm_stub_long_branch_thumb_only
:
4090 case arm_stub_long_branch_thumb2_only
:
4091 case arm_stub_long_branch_thumb2_only_pure
:
4092 case arm_stub_long_branch_v4t_thumb_arm
:
4093 case arm_stub_short_branch_v4t_thumb_arm
:
4094 case arm_stub_long_branch_v4t_thumb_arm_pic
:
4095 case arm_stub_long_branch_v4t_thumb_tls_pic
:
4096 case arm_stub_long_branch_thumb_only_pic
:
4097 case arm_stub_cmse_branch_thumb_only
:
4108 /* Determine the type of stub needed, if any, for a call. */
4110 static enum elf32_arm_stub_type
4111 arm_type_of_stub (struct bfd_link_info
*info
,
4112 asection
*input_sec
,
4113 const Elf_Internal_Rela
*rel
,
4114 unsigned char st_type
,
4115 enum arm_st_branch_type
*actual_branch_type
,
4116 struct elf32_arm_link_hash_entry
*hash
,
4117 bfd_vma destination
,
4123 bfd_signed_vma branch_offset
;
4124 unsigned int r_type
;
4125 struct elf32_arm_link_hash_table
* globals
;
4126 bfd_boolean thumb2
, thumb2_bl
, thumb_only
;
4127 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
4129 enum arm_st_branch_type branch_type
= *actual_branch_type
;
4130 union gotplt_union
*root_plt
;
4131 struct arm_plt_info
*arm_plt
;
4135 if (branch_type
== ST_BRANCH_LONG
)
4138 globals
= elf32_arm_hash_table (info
);
4139 if (globals
== NULL
)
4142 thumb_only
= using_thumb_only (globals
);
4143 thumb2
= using_thumb2 (globals
);
4144 thumb2_bl
= using_thumb2_bl (globals
);
4146 arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
4148 /* True for architectures that implement the thumb2 movw instruction. */
4149 thumb2_movw
= thumb2
|| (arch
== TAG_CPU_ARCH_V8M_BASE
);
4151 /* Determine where the call point is. */
4152 location
= (input_sec
->output_offset
4153 + input_sec
->output_section
->vma
4156 r_type
= ELF32_R_TYPE (rel
->r_info
);
4158 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
4159 are considering a function call relocation. */
4160 if (thumb_only
&& (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
4161 || r_type
== R_ARM_THM_JUMP19
)
4162 && branch_type
== ST_BRANCH_TO_ARM
)
4163 branch_type
= ST_BRANCH_TO_THUMB
;
4165 /* For TLS call relocs, it is the caller's responsibility to provide
4166 the address of the appropriate trampoline. */
4167 if (r_type
!= R_ARM_TLS_CALL
4168 && r_type
!= R_ARM_THM_TLS_CALL
4169 && elf32_arm_get_plt_info (input_bfd
, globals
, hash
,
4170 ELF32_R_SYM (rel
->r_info
), &root_plt
,
4172 && root_plt
->offset
!= (bfd_vma
) -1)
4176 if (hash
== NULL
|| hash
->is_iplt
)
4177 splt
= globals
->root
.iplt
;
4179 splt
= globals
->root
.splt
;
4184 /* Note when dealing with PLT entries: the main PLT stub is in
4185 ARM mode, so if the branch is in Thumb mode, another
4186 Thumb->ARM stub will be inserted later just before the ARM
4187 PLT stub. If a long branch stub is needed, we'll add a
4188 Thumb->Arm one and branch directly to the ARM PLT entry.
4189 Here, we have to check if a pre-PLT Thumb->ARM stub
4190 is needed and if it will be close enough. */
4192 destination
= (splt
->output_section
->vma
4193 + splt
->output_offset
4194 + root_plt
->offset
);
4197 /* Thumb branch/call to PLT: it can become a branch to ARM
4198 or to Thumb. We must perform the same checks and
4199 corrections as in elf32_arm_final_link_relocate. */
4200 if ((r_type
== R_ARM_THM_CALL
)
4201 || (r_type
== R_ARM_THM_JUMP24
))
4203 if (globals
->use_blx
4204 && r_type
== R_ARM_THM_CALL
4207 /* If the Thumb BLX instruction is available, convert
4208 the BL to a BLX instruction to call the ARM-mode
4210 branch_type
= ST_BRANCH_TO_ARM
;
4215 /* Target the Thumb stub before the ARM PLT entry. */
4216 destination
-= PLT_THUMB_STUB_SIZE
;
4217 branch_type
= ST_BRANCH_TO_THUMB
;
4222 branch_type
= ST_BRANCH_TO_ARM
;
4226 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
4227 BFD_ASSERT (st_type
!= STT_GNU_IFUNC
);
4229 branch_offset
= (bfd_signed_vma
)(destination
- location
);
4231 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
4232 || r_type
== R_ARM_THM_TLS_CALL
|| r_type
== R_ARM_THM_JUMP19
)
4234 /* Handle cases where:
4235 - this call goes too far (different Thumb/Thumb2 max
4237 - it's a Thumb->Arm call and blx is not available, or it's a
4238 Thumb->Arm branch (not bl). A stub is needed in this case,
4239 but only if this call is not through a PLT entry. Indeed,
4240 PLT stubs handle mode switching already. */
4242 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
4243 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
4245 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
4246 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
4248 && (branch_offset
> THM2_MAX_FWD_COND_BRANCH_OFFSET
4249 || (branch_offset
< THM2_MAX_BWD_COND_BRANCH_OFFSET
))
4250 && (r_type
== R_ARM_THM_JUMP19
))
4251 || (branch_type
== ST_BRANCH_TO_ARM
4252 && (((r_type
== R_ARM_THM_CALL
4253 || r_type
== R_ARM_THM_TLS_CALL
) && !globals
->use_blx
)
4254 || (r_type
== R_ARM_THM_JUMP24
)
4255 || (r_type
== R_ARM_THM_JUMP19
))
4258 /* If we need to insert a Thumb-Thumb long branch stub to a
4259 PLT, use one that branches directly to the ARM PLT
4260 stub. If we pretended we'd use the pre-PLT Thumb->ARM
4261 stub, undo this now. */
4262 if ((branch_type
== ST_BRANCH_TO_THUMB
) && use_plt
&& !thumb_only
)
4264 branch_type
= ST_BRANCH_TO_ARM
;
4265 branch_offset
+= PLT_THUMB_STUB_SIZE
;
4268 if (branch_type
== ST_BRANCH_TO_THUMB
)
4270 /* Thumb to thumb. */
4273 if (input_sec
->flags
& SEC_ELF_PURECODE
)
4275 (_("%pB(%pA): warning: long branch veneers used in"
4276 " section with SHF_ARM_PURECODE section"
4277 " attribute is only supported for M-profile"
4278 " targets that implement the movw instruction"),
4279 input_bfd
, input_sec
);
4281 stub_type
= (bfd_link_pic (info
) | globals
->pic_veneer
)
4283 ? ((globals
->use_blx
4284 && (r_type
== R_ARM_THM_CALL
))
4285 /* V5T and above. Stub starts with ARM code, so
4286 we must be able to switch mode before
4287 reaching it, which is only possible for 'bl'
4288 (ie R_ARM_THM_CALL relocation). */
4289 ? arm_stub_long_branch_any_thumb_pic
4290 /* On V4T, use Thumb code only. */
4291 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
4293 /* non-PIC stubs. */
4294 : ((globals
->use_blx
4295 && (r_type
== R_ARM_THM_CALL
))
4296 /* V5T and above. */
4297 ? arm_stub_long_branch_any_any
4299 : arm_stub_long_branch_v4t_thumb_thumb
);
4303 if (thumb2_movw
&& (input_sec
->flags
& SEC_ELF_PURECODE
))
4304 stub_type
= arm_stub_long_branch_thumb2_only_pure
;
4307 if (input_sec
->flags
& SEC_ELF_PURECODE
)
4309 (_("%pB(%pA): warning: long branch veneers used in"
4310 " section with SHF_ARM_PURECODE section"
4311 " attribute is only supported for M-profile"
4312 " targets that implement the movw instruction"),
4313 input_bfd
, input_sec
);
4315 stub_type
= (bfd_link_pic (info
) | globals
->pic_veneer
)
4317 ? arm_stub_long_branch_thumb_only_pic
4319 : (thumb2
? arm_stub_long_branch_thumb2_only
4320 : arm_stub_long_branch_thumb_only
);
4326 if (input_sec
->flags
& SEC_ELF_PURECODE
)
4328 (_("%pB(%pA): warning: long branch veneers used in"
4329 " section with SHF_ARM_PURECODE section"
4330 " attribute is only supported" " for M-profile"
4331 " targets that implement the movw instruction"),
4332 input_bfd
, input_sec
);
4336 && sym_sec
->owner
!= NULL
4337 && !INTERWORK_FLAG (sym_sec
->owner
))
4340 (_("%pB(%s): warning: interworking not enabled;"
4341 " first occurrence: %pB: %s call to %s"),
4342 sym_sec
->owner
, name
, input_bfd
, "Thumb", "ARM");
4346 (bfd_link_pic (info
) | globals
->pic_veneer
)
4348 ? (r_type
== R_ARM_THM_TLS_CALL
4349 /* TLS PIC stubs. */
4350 ? (globals
->use_blx
? arm_stub_long_branch_any_tls_pic
4351 : arm_stub_long_branch_v4t_thumb_tls_pic
)
4352 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
4353 /* V5T PIC and above. */
4354 ? arm_stub_long_branch_any_arm_pic
4356 : arm_stub_long_branch_v4t_thumb_arm_pic
))
4358 /* non-PIC stubs. */
4359 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
4360 /* V5T and above. */
4361 ? arm_stub_long_branch_any_any
4363 : arm_stub_long_branch_v4t_thumb_arm
);
4365 /* Handle v4t short branches. */
4366 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
4367 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
4368 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
4369 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
4373 else if (r_type
== R_ARM_CALL
4374 || r_type
== R_ARM_JUMP24
4375 || r_type
== R_ARM_PLT32
4376 || r_type
== R_ARM_TLS_CALL
)
4378 if (input_sec
->flags
& SEC_ELF_PURECODE
)
4380 (_("%pB(%pA): warning: long branch veneers used in"
4381 " section with SHF_ARM_PURECODE section"
4382 " attribute is only supported for M-profile"
4383 " targets that implement the movw instruction"),
4384 input_bfd
, input_sec
);
4385 if (branch_type
== ST_BRANCH_TO_THUMB
)
4390 && sym_sec
->owner
!= NULL
4391 && !INTERWORK_FLAG (sym_sec
->owner
))
4394 (_("%pB(%s): warning: interworking not enabled;"
4395 " first occurrence: %pB: %s call to %s"),
4396 sym_sec
->owner
, name
, input_bfd
, "ARM", "Thumb");
4399 /* We have an extra 2-bytes reach because of
4400 the mode change (bit 24 (H) of BLX encoding). */
4401 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
4402 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
4403 || (r_type
== R_ARM_CALL
&& !globals
->use_blx
)
4404 || (r_type
== R_ARM_JUMP24
)
4405 || (r_type
== R_ARM_PLT32
))
4407 stub_type
= (bfd_link_pic (info
) | globals
->pic_veneer
)
4409 ? ((globals
->use_blx
)
4410 /* V5T and above. */
4411 ? arm_stub_long_branch_any_thumb_pic
4413 : arm_stub_long_branch_v4t_arm_thumb_pic
)
4415 /* non-PIC stubs. */
4416 : ((globals
->use_blx
)
4417 /* V5T and above. */
4418 ? arm_stub_long_branch_any_any
4420 : arm_stub_long_branch_v4t_arm_thumb
);
4426 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
4427 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
4430 (bfd_link_pic (info
) | globals
->pic_veneer
)
4432 ? (r_type
== R_ARM_TLS_CALL
4434 ? arm_stub_long_branch_any_tls_pic
4436 ? arm_stub_long_branch_arm_nacl_pic
4437 : arm_stub_long_branch_any_arm_pic
))
4438 /* non-PIC stubs. */
4440 ? arm_stub_long_branch_arm_nacl
4441 : arm_stub_long_branch_any_any
);
4446 /* If a stub is needed, record the actual destination type. */
4447 if (stub_type
!= arm_stub_none
)
4448 *actual_branch_type
= branch_type
;
4453 /* Build a name for an entry in the stub hash table. */
4456 elf32_arm_stub_name (const asection
*input_section
,
4457 const asection
*sym_sec
,
4458 const struct elf32_arm_link_hash_entry
*hash
,
4459 const Elf_Internal_Rela
*rel
,
4460 enum elf32_arm_stub_type stub_type
)
4467 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1 + 2 + 1;
4468 stub_name
= (char *) bfd_malloc (len
);
4469 if (stub_name
!= NULL
)
4470 sprintf (stub_name
, "%08x_%s+%x_%d",
4471 input_section
->id
& 0xffffffff,
4472 hash
->root
.root
.root
.string
,
4473 (int) rel
->r_addend
& 0xffffffff,
4478 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
4479 stub_name
= (char *) bfd_malloc (len
);
4480 if (stub_name
!= NULL
)
4481 sprintf (stub_name
, "%08x_%x:%x+%x_%d",
4482 input_section
->id
& 0xffffffff,
4483 sym_sec
->id
& 0xffffffff,
4484 ELF32_R_TYPE (rel
->r_info
) == R_ARM_TLS_CALL
4485 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_TLS_CALL
4486 ? 0 : (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
4487 (int) rel
->r_addend
& 0xffffffff,
4494 /* Look up an entry in the stub hash. Stub entries are cached because
4495 creating the stub name takes a bit of time. */
4497 static struct elf32_arm_stub_hash_entry
*
4498 elf32_arm_get_stub_entry (const asection
*input_section
,
4499 const asection
*sym_sec
,
4500 struct elf_link_hash_entry
*hash
,
4501 const Elf_Internal_Rela
*rel
,
4502 struct elf32_arm_link_hash_table
*htab
,
4503 enum elf32_arm_stub_type stub_type
)
4505 struct elf32_arm_stub_hash_entry
*stub_entry
;
4506 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
4507 const asection
*id_sec
;
4509 if ((input_section
->flags
& SEC_CODE
) == 0)
4512 /* If this input section is part of a group of sections sharing one
4513 stub section, then use the id of the first section in the group.
4514 Stub names need to include a section id, as there may well be
4515 more than one stub used to reach say, printf, and we need to
4516 distinguish between them. */
4517 BFD_ASSERT (input_section
->id
<= htab
->top_id
);
4518 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
4520 if (h
!= NULL
&& h
->stub_cache
!= NULL
4521 && h
->stub_cache
->h
== h
4522 && h
->stub_cache
->id_sec
== id_sec
4523 && h
->stub_cache
->stub_type
== stub_type
)
4525 stub_entry
= h
->stub_cache
;
4531 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
, stub_type
);
4532 if (stub_name
== NULL
)
4535 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
4536 stub_name
, FALSE
, FALSE
);
4538 h
->stub_cache
= stub_entry
;
4546 /* Whether veneers of type STUB_TYPE require to be in a dedicated output
4550 arm_dedicated_stub_output_section_required (enum elf32_arm_stub_type stub_type
)
4552 if (stub_type
>= max_stub_type
)
4553 abort (); /* Should be unreachable. */
4557 case arm_stub_cmse_branch_thumb_only
:
4564 abort (); /* Should be unreachable. */
4567 /* Required alignment (as a power of 2) for the dedicated section holding
4568 veneers of type STUB_TYPE, or 0 if veneers of this type are interspersed
4569 with input sections. */
4572 arm_dedicated_stub_output_section_required_alignment
4573 (enum elf32_arm_stub_type stub_type
)
4575 if (stub_type
>= max_stub_type
)
4576 abort (); /* Should be unreachable. */
4580 /* Vectors of Secure Gateway veneers must be aligned on 32byte
4582 case arm_stub_cmse_branch_thumb_only
:
4586 BFD_ASSERT (!arm_dedicated_stub_output_section_required (stub_type
));
4590 abort (); /* Should be unreachable. */
4593 /* Name of the dedicated output section to put veneers of type STUB_TYPE, or
4594 NULL if veneers of this type are interspersed with input sections. */
4597 arm_dedicated_stub_output_section_name (enum elf32_arm_stub_type stub_type
)
4599 if (stub_type
>= max_stub_type
)
4600 abort (); /* Should be unreachable. */
4604 case arm_stub_cmse_branch_thumb_only
:
4605 return ".gnu.sgstubs";
4608 BFD_ASSERT (!arm_dedicated_stub_output_section_required (stub_type
));
4612 abort (); /* Should be unreachable. */
4615 /* If veneers of type STUB_TYPE should go in a dedicated output section,
4616 returns the address of the hash table field in HTAB holding a pointer to the
4617 corresponding input section. Otherwise, returns NULL. */
4620 arm_dedicated_stub_input_section_ptr (struct elf32_arm_link_hash_table
*htab
,
4621 enum elf32_arm_stub_type stub_type
)
4623 if (stub_type
>= max_stub_type
)
4624 abort (); /* Should be unreachable. */
4628 case arm_stub_cmse_branch_thumb_only
:
4629 return &htab
->cmse_stub_sec
;
4632 BFD_ASSERT (!arm_dedicated_stub_output_section_required (stub_type
));
4636 abort (); /* Should be unreachable. */
4639 /* Find or create a stub section to contain a stub of type STUB_TYPE. SECTION
4640 is the section that branch into veneer and can be NULL if stub should go in
4641 a dedicated output section. Returns a pointer to the stub section, and the
4642 section to which the stub section will be attached (in *LINK_SEC_P).
4643 LINK_SEC_P may be NULL. */
4646 elf32_arm_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
4647 struct elf32_arm_link_hash_table
*htab
,
4648 enum elf32_arm_stub_type stub_type
)
4650 asection
*link_sec
, *out_sec
, **stub_sec_p
;
4651 const char *stub_sec_prefix
;
4652 bfd_boolean dedicated_output_section
=
4653 arm_dedicated_stub_output_section_required (stub_type
);
4656 if (dedicated_output_section
)
4658 bfd
*output_bfd
= htab
->obfd
;
4659 const char *out_sec_name
=
4660 arm_dedicated_stub_output_section_name (stub_type
);
4662 stub_sec_p
= arm_dedicated_stub_input_section_ptr (htab
, stub_type
);
4663 stub_sec_prefix
= out_sec_name
;
4664 align
= arm_dedicated_stub_output_section_required_alignment (stub_type
);
4665 out_sec
= bfd_get_section_by_name (output_bfd
, out_sec_name
);
4666 if (out_sec
== NULL
)
4668 _bfd_error_handler (_("no address assigned to the veneers output "
4669 "section %s"), out_sec_name
);
4675 BFD_ASSERT (section
->id
<= htab
->top_id
);
4676 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
4677 BFD_ASSERT (link_sec
!= NULL
);
4678 stub_sec_p
= &htab
->stub_group
[section
->id
].stub_sec
;
4679 if (*stub_sec_p
== NULL
)
4680 stub_sec_p
= &htab
->stub_group
[link_sec
->id
].stub_sec
;
4681 stub_sec_prefix
= link_sec
->name
;
4682 out_sec
= link_sec
->output_section
;
4683 align
= htab
->nacl_p
? 4 : 3;
4686 if (*stub_sec_p
== NULL
)
4692 namelen
= strlen (stub_sec_prefix
);
4693 len
= namelen
+ sizeof (STUB_SUFFIX
);
4694 s_name
= (char *) bfd_alloc (htab
->stub_bfd
, len
);
4698 memcpy (s_name
, stub_sec_prefix
, namelen
);
4699 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4700 *stub_sec_p
= (*htab
->add_stub_section
) (s_name
, out_sec
, link_sec
,
4702 if (*stub_sec_p
== NULL
)
4705 out_sec
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
4706 | SEC_HAS_CONTENTS
| SEC_RELOC
| SEC_IN_MEMORY
4710 if (!dedicated_output_section
)
4711 htab
->stub_group
[section
->id
].stub_sec
= *stub_sec_p
;
4714 *link_sec_p
= link_sec
;
4719 /* Add a new stub entry to the stub hash. Not all fields of the new
4720 stub entry are initialised. */
4722 static struct elf32_arm_stub_hash_entry
*
4723 elf32_arm_add_stub (const char *stub_name
, asection
*section
,
4724 struct elf32_arm_link_hash_table
*htab
,
4725 enum elf32_arm_stub_type stub_type
)
4729 struct elf32_arm_stub_hash_entry
*stub_entry
;
4731 stub_sec
= elf32_arm_create_or_find_stub_sec (&link_sec
, section
, htab
,
4733 if (stub_sec
== NULL
)
4736 /* Enter this entry into the linker stub hash table. */
4737 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4739 if (stub_entry
== NULL
)
4741 if (section
== NULL
)
4743 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
4744 section
->owner
, stub_name
);
4748 stub_entry
->stub_sec
= stub_sec
;
4749 stub_entry
->stub_offset
= (bfd_vma
) -1;
4750 stub_entry
->id_sec
= link_sec
;
4755 /* Store an Arm insn into an output section not processed by
4756 elf32_arm_write_section. */
4759 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
4760 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4762 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4763 bfd_putl32 (val
, ptr
);
4765 bfd_putb32 (val
, ptr
);
4768 /* Store a 16-bit Thumb insn into an output section not processed by
4769 elf32_arm_write_section. */
4772 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
4773 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4775 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4776 bfd_putl16 (val
, ptr
);
4778 bfd_putb16 (val
, ptr
);
4781 /* Store a Thumb2 insn into an output section not processed by
4782 elf32_arm_write_section. */
4785 put_thumb2_insn (struct elf32_arm_link_hash_table
* htab
,
4786 bfd
* output_bfd
, bfd_vma val
, bfd_byte
* ptr
)
4788 /* T2 instructions are 16-bit streamed. */
4789 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4791 bfd_putl16 ((val
>> 16) & 0xffff, ptr
);
4792 bfd_putl16 ((val
& 0xffff), ptr
+ 2);
4796 bfd_putb16 ((val
>> 16) & 0xffff, ptr
);
4797 bfd_putb16 ((val
& 0xffff), ptr
+ 2);
4801 /* If it's possible to change R_TYPE to a more efficient access
4802 model, return the new reloc type. */
4805 elf32_arm_tls_transition (struct bfd_link_info
*info
, int r_type
,
4806 struct elf_link_hash_entry
*h
)
4808 int is_local
= (h
== NULL
);
4810 if (bfd_link_pic (info
)
4811 || (h
&& h
->root
.type
== bfd_link_hash_undefweak
))
4814 /* We do not support relaxations for Old TLS models. */
4817 case R_ARM_TLS_GOTDESC
:
4818 case R_ARM_TLS_CALL
:
4819 case R_ARM_THM_TLS_CALL
:
4820 case R_ARM_TLS_DESCSEQ
:
4821 case R_ARM_THM_TLS_DESCSEQ
:
4822 return is_local
? R_ARM_TLS_LE32
: R_ARM_TLS_IE32
;
4828 static bfd_reloc_status_type elf32_arm_final_link_relocate
4829 (reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
4830 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
4831 const char *, unsigned char, enum arm_st_branch_type
,
4832 struct elf_link_hash_entry
*, bfd_boolean
*, char **);
4835 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type
)
4839 case arm_stub_a8_veneer_b_cond
:
4840 case arm_stub_a8_veneer_b
:
4841 case arm_stub_a8_veneer_bl
:
4844 case arm_stub_long_branch_any_any
:
4845 case arm_stub_long_branch_v4t_arm_thumb
:
4846 case arm_stub_long_branch_thumb_only
:
4847 case arm_stub_long_branch_thumb2_only
:
4848 case arm_stub_long_branch_thumb2_only_pure
:
4849 case arm_stub_long_branch_v4t_thumb_thumb
:
4850 case arm_stub_long_branch_v4t_thumb_arm
:
4851 case arm_stub_short_branch_v4t_thumb_arm
:
4852 case arm_stub_long_branch_any_arm_pic
:
4853 case arm_stub_long_branch_any_thumb_pic
:
4854 case arm_stub_long_branch_v4t_thumb_thumb_pic
:
4855 case arm_stub_long_branch_v4t_arm_thumb_pic
:
4856 case arm_stub_long_branch_v4t_thumb_arm_pic
:
4857 case arm_stub_long_branch_thumb_only_pic
:
4858 case arm_stub_long_branch_any_tls_pic
:
4859 case arm_stub_long_branch_v4t_thumb_tls_pic
:
4860 case arm_stub_cmse_branch_thumb_only
:
4861 case arm_stub_a8_veneer_blx
:
4864 case arm_stub_long_branch_arm_nacl
:
4865 case arm_stub_long_branch_arm_nacl_pic
:
4869 abort (); /* Should be unreachable. */
4873 /* Returns whether stubs of type STUB_TYPE take over the symbol they are
4874 veneering (TRUE) or have their own symbol (FALSE). */
4877 arm_stub_sym_claimed (enum elf32_arm_stub_type stub_type
)
4879 if (stub_type
>= max_stub_type
)
4880 abort (); /* Should be unreachable. */
4884 case arm_stub_cmse_branch_thumb_only
:
4891 abort (); /* Should be unreachable. */
4894 /* Returns the padding needed for the dedicated section used stubs of type
4898 arm_dedicated_stub_section_padding (enum elf32_arm_stub_type stub_type
)
4900 if (stub_type
>= max_stub_type
)
4901 abort (); /* Should be unreachable. */
4905 case arm_stub_cmse_branch_thumb_only
:
4912 abort (); /* Should be unreachable. */
4915 /* If veneers of type STUB_TYPE should go in a dedicated output section,
4916 returns the address of the hash table field in HTAB holding the offset at
4917 which new veneers should be layed out in the stub section. */
4920 arm_new_stubs_start_offset_ptr (struct elf32_arm_link_hash_table
*htab
,
4921 enum elf32_arm_stub_type stub_type
)
4925 case arm_stub_cmse_branch_thumb_only
:
4926 return &htab
->new_cmse_stub_offset
;
4929 BFD_ASSERT (!arm_dedicated_stub_output_section_required (stub_type
));
4935 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
4939 bfd_boolean removed_sg_veneer
;
4940 struct elf32_arm_stub_hash_entry
*stub_entry
;
4941 struct elf32_arm_link_hash_table
*globals
;
4942 struct bfd_link_info
*info
;
4949 const insn_sequence
*template_sequence
;
4951 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
4952 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
4954 int just_allocated
= 0;
4956 /* Massage our args to the form they really have. */
4957 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4958 info
= (struct bfd_link_info
*) in_arg
;
4960 globals
= elf32_arm_hash_table (info
);
4961 if (globals
== NULL
)
4964 stub_sec
= stub_entry
->stub_sec
;
4966 if ((globals
->fix_cortex_a8
< 0)
4967 != (arm_stub_required_alignment (stub_entry
->stub_type
) == 2))
4968 /* We have to do less-strictly-aligned fixes last. */
4971 /* Assign a slot at the end of section if none assigned yet. */
4972 if (stub_entry
->stub_offset
== (bfd_vma
) -1)
4974 stub_entry
->stub_offset
= stub_sec
->size
;
4977 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4979 stub_bfd
= stub_sec
->owner
;
4981 /* This is the address of the stub destination. */
4982 sym_value
= (stub_entry
->target_value
4983 + stub_entry
->target_section
->output_offset
4984 + stub_entry
->target_section
->output_section
->vma
);
4986 template_sequence
= stub_entry
->stub_template
;
4987 template_size
= stub_entry
->stub_template_size
;
4990 for (i
= 0; i
< template_size
; i
++)
4992 switch (template_sequence
[i
].type
)
4996 bfd_vma data
= (bfd_vma
) template_sequence
[i
].data
;
4997 if (template_sequence
[i
].reloc_addend
!= 0)
4999 /* We've borrowed the reloc_addend field to mean we should
5000 insert a condition code into this (Thumb-1 branch)
5001 instruction. See THUMB16_BCOND_INSN. */
5002 BFD_ASSERT ((data
& 0xff00) == 0xd000);
5003 data
|= ((stub_entry
->orig_insn
>> 22) & 0xf) << 8;
5005 bfd_put_16 (stub_bfd
, data
, loc
+ size
);
5011 bfd_put_16 (stub_bfd
,
5012 (template_sequence
[i
].data
>> 16) & 0xffff,
5014 bfd_put_16 (stub_bfd
, template_sequence
[i
].data
& 0xffff,
5016 if (template_sequence
[i
].r_type
!= R_ARM_NONE
)
5018 stub_reloc_idx
[nrelocs
] = i
;
5019 stub_reloc_offset
[nrelocs
++] = size
;
5025 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
,
5027 /* Handle cases where the target is encoded within the
5029 if (template_sequence
[i
].r_type
== R_ARM_JUMP24
)
5031 stub_reloc_idx
[nrelocs
] = i
;
5032 stub_reloc_offset
[nrelocs
++] = size
;
5038 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
, loc
+ size
);
5039 stub_reloc_idx
[nrelocs
] = i
;
5040 stub_reloc_offset
[nrelocs
++] = size
;
5051 stub_sec
->size
+= size
;
5053 /* Stub size has already been computed in arm_size_one_stub. Check
5055 BFD_ASSERT (size
== stub_entry
->stub_size
);
5057 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
5058 if (stub_entry
->branch_type
== ST_BRANCH_TO_THUMB
)
5061 /* Assume non empty slots have at least one and at most MAXRELOCS entries
5062 to relocate in each stub. */
5064 (size
== 0 && stub_entry
->stub_type
== arm_stub_cmse_branch_thumb_only
);
5065 BFD_ASSERT (removed_sg_veneer
|| (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
));
5067 for (i
= 0; i
< nrelocs
; i
++)
5069 Elf_Internal_Rela rel
;
5070 bfd_boolean unresolved_reloc
;
5071 char *error_message
;
5073 sym_value
+ template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
5075 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
5076 rel
.r_info
= ELF32_R_INFO (0,
5077 template_sequence
[stub_reloc_idx
[i
]].r_type
);
5080 if (stub_entry
->stub_type
== arm_stub_a8_veneer_b_cond
&& i
== 0)
5081 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
5082 template should refer back to the instruction after the original
5083 branch. We use target_section as Cortex-A8 erratum workaround stubs
5084 are only generated when both source and target are in the same
5086 points_to
= stub_entry
->target_section
->output_section
->vma
5087 + stub_entry
->target_section
->output_offset
5088 + stub_entry
->source_value
;
5090 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
5091 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
5092 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
5093 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
5094 stub_entry
->branch_type
,
5095 (struct elf_link_hash_entry
*) stub_entry
->h
, &unresolved_reloc
,
5103 /* Calculate the template, template size and instruction size for a stub.
5104 Return value is the instruction size. */
5107 find_stub_size_and_template (enum elf32_arm_stub_type stub_type
,
5108 const insn_sequence
**stub_template
,
5109 int *stub_template_size
)
5111 const insn_sequence
*template_sequence
= NULL
;
5112 int template_size
= 0, i
;
5115 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
5117 *stub_template
= template_sequence
;
5119 template_size
= stub_definitions
[stub_type
].template_size
;
5120 if (stub_template_size
)
5121 *stub_template_size
= template_size
;
5124 for (i
= 0; i
< template_size
; i
++)
5126 switch (template_sequence
[i
].type
)
5147 /* As above, but don't actually build the stub. Just bump offset so
5148 we know stub section sizes. */
5151 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
5152 void *in_arg ATTRIBUTE_UNUSED
)
5154 struct elf32_arm_stub_hash_entry
*stub_entry
;
5155 const insn_sequence
*template_sequence
;
5156 int template_size
, size
;
5158 /* Massage our args to the form they really have. */
5159 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
5161 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
5162 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
5164 size
= find_stub_size_and_template (stub_entry
->stub_type
, &template_sequence
,
5167 /* Initialized to -1. Null size indicates an empty slot full of zeros. */
5168 if (stub_entry
->stub_template_size
)
5170 stub_entry
->stub_size
= size
;
5171 stub_entry
->stub_template
= template_sequence
;
5172 stub_entry
->stub_template_size
= template_size
;
5175 /* Already accounted for. */
5176 if (stub_entry
->stub_offset
!= (bfd_vma
) -1)
5179 size
= (size
+ 7) & ~7;
5180 stub_entry
->stub_sec
->size
+= size
;
5185 /* External entry points for sizing and building linker stubs. */
5187 /* Set up various things so that we can make a list of input sections
5188 for each output section included in the link. Returns -1 on error,
5189 0 when no stubs will be needed, and 1 on success. */
5192 elf32_arm_setup_section_lists (bfd
*output_bfd
,
5193 struct bfd_link_info
*info
)
5196 unsigned int bfd_count
;
5197 unsigned int top_id
, top_index
;
5199 asection
**input_list
, **list
;
5201 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
5205 if (! is_elf_hash_table (htab
))
5208 /* Count the number of input BFDs and find the top input section id. */
5209 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
5211 input_bfd
= input_bfd
->link
.next
)
5214 for (section
= input_bfd
->sections
;
5216 section
= section
->next
)
5218 if (top_id
< section
->id
)
5219 top_id
= section
->id
;
5222 htab
->bfd_count
= bfd_count
;
5224 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
5225 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
5226 if (htab
->stub_group
== NULL
)
5228 htab
->top_id
= top_id
;
5230 /* We can't use output_bfd->section_count here to find the top output
5231 section index as some sections may have been removed, and
5232 _bfd_strip_section_from_output doesn't renumber the indices. */
5233 for (section
= output_bfd
->sections
, top_index
= 0;
5235 section
= section
->next
)
5237 if (top_index
< section
->index
)
5238 top_index
= section
->index
;
5241 htab
->top_index
= top_index
;
5242 amt
= sizeof (asection
*) * (top_index
+ 1);
5243 input_list
= (asection
**) bfd_malloc (amt
);
5244 htab
->input_list
= input_list
;
5245 if (input_list
== NULL
)
5248 /* For sections we aren't interested in, mark their entries with a
5249 value we can check later. */
5250 list
= input_list
+ top_index
;
5252 *list
= bfd_abs_section_ptr
;
5253 while (list
-- != input_list
);
5255 for (section
= output_bfd
->sections
;
5257 section
= section
->next
)
5259 if ((section
->flags
& SEC_CODE
) != 0)
5260 input_list
[section
->index
] = NULL
;
5266 /* The linker repeatedly calls this function for each input section,
5267 in the order that input sections are linked into output sections.
5268 Build lists of input sections to determine groupings between which
5269 we may insert linker stubs. */
5272 elf32_arm_next_input_section (struct bfd_link_info
*info
,
5275 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
5280 if (isec
->output_section
->index
<= htab
->top_index
)
5282 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
5284 if (*list
!= bfd_abs_section_ptr
&& (isec
->flags
& SEC_CODE
) != 0)
5286 /* Steal the link_sec pointer for our list. */
5287 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
5288 /* This happens to make the list in reverse order,
5289 which we reverse later. */
5290 PREV_SEC (isec
) = *list
;
5296 /* See whether we can group stub sections together. Grouping stub
5297 sections may result in fewer stubs. More importantly, we need to
5298 put all .init* and .fini* stubs at the end of the .init or
5299 .fini output sections respectively, because glibc splits the
5300 _init and _fini functions into multiple parts. Putting a stub in
5301 the middle of a function is not a good idea. */
5304 group_sections (struct elf32_arm_link_hash_table
*htab
,
5305 bfd_size_type stub_group_size
,
5306 bfd_boolean stubs_always_after_branch
)
5308 asection
**list
= htab
->input_list
;
5312 asection
*tail
= *list
;
5315 if (tail
== bfd_abs_section_ptr
)
5318 /* Reverse the list: we must avoid placing stubs at the
5319 beginning of the section because the beginning of the text
5320 section may be required for an interrupt vector in bare metal
5322 #define NEXT_SEC PREV_SEC
5324 while (tail
!= NULL
)
5326 /* Pop from tail. */
5327 asection
*item
= tail
;
5328 tail
= PREV_SEC (item
);
5331 NEXT_SEC (item
) = head
;
5335 while (head
!= NULL
)
5339 bfd_vma stub_group_start
= head
->output_offset
;
5340 bfd_vma end_of_next
;
5343 while (NEXT_SEC (curr
) != NULL
)
5345 next
= NEXT_SEC (curr
);
5346 end_of_next
= next
->output_offset
+ next
->size
;
5347 if (end_of_next
- stub_group_start
>= stub_group_size
)
5348 /* End of NEXT is too far from start, so stop. */
5350 /* Add NEXT to the group. */
5354 /* OK, the size from the start to the start of CURR is less
5355 than stub_group_size and thus can be handled by one stub
5356 section. (Or the head section is itself larger than
5357 stub_group_size, in which case we may be toast.)
5358 We should really be keeping track of the total size of
5359 stubs added here, as stubs contribute to the final output
5363 next
= NEXT_SEC (head
);
5364 /* Set up this stub group. */
5365 htab
->stub_group
[head
->id
].link_sec
= curr
;
5367 while (head
!= curr
&& (head
= next
) != NULL
);
5369 /* But wait, there's more! Input sections up to stub_group_size
5370 bytes after the stub section can be handled by it too. */
5371 if (!stubs_always_after_branch
)
5373 stub_group_start
= curr
->output_offset
+ curr
->size
;
5375 while (next
!= NULL
)
5377 end_of_next
= next
->output_offset
+ next
->size
;
5378 if (end_of_next
- stub_group_start
>= stub_group_size
)
5379 /* End of NEXT is too far from stubs, so stop. */
5381 /* Add NEXT to the stub group. */
5383 next
= NEXT_SEC (head
);
5384 htab
->stub_group
[head
->id
].link_sec
= curr
;
5390 while (list
++ != htab
->input_list
+ htab
->top_index
);
5392 free (htab
->input_list
);
5397 /* Comparison function for sorting/searching relocations relating to Cortex-A8
5401 a8_reloc_compare (const void *a
, const void *b
)
5403 const struct a8_erratum_reloc
*ra
= (const struct a8_erratum_reloc
*) a
;
5404 const struct a8_erratum_reloc
*rb
= (const struct a8_erratum_reloc
*) b
;
5406 if (ra
->from
< rb
->from
)
5408 else if (ra
->from
> rb
->from
)
5414 static struct elf_link_hash_entry
*find_thumb_glue (struct bfd_link_info
*,
5415 const char *, char **);
5417 /* Helper function to scan code for sequences which might trigger the Cortex-A8
5418 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
5419 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
5423 cortex_a8_erratum_scan (bfd
*input_bfd
,
5424 struct bfd_link_info
*info
,
5425 struct a8_erratum_fix
**a8_fixes_p
,
5426 unsigned int *num_a8_fixes_p
,
5427 unsigned int *a8_fix_table_size_p
,
5428 struct a8_erratum_reloc
*a8_relocs
,
5429 unsigned int num_a8_relocs
,
5430 unsigned prev_num_a8_fixes
,
5431 bfd_boolean
*stub_changed_p
)
5434 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
5435 struct a8_erratum_fix
*a8_fixes
= *a8_fixes_p
;
5436 unsigned int num_a8_fixes
= *num_a8_fixes_p
;
5437 unsigned int a8_fix_table_size
= *a8_fix_table_size_p
;
5442 for (section
= input_bfd
->sections
;
5444 section
= section
->next
)
5446 bfd_byte
*contents
= NULL
;
5447 struct _arm_elf_section_data
*sec_data
;
5451 if (elf_section_type (section
) != SHT_PROGBITS
5452 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
5453 || (section
->flags
& SEC_EXCLUDE
) != 0
5454 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
5455 || (section
->output_section
== bfd_abs_section_ptr
))
5458 base_vma
= section
->output_section
->vma
+ section
->output_offset
;
5460 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
5461 contents
= elf_section_data (section
)->this_hdr
.contents
;
5462 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
5465 sec_data
= elf32_arm_section_data (section
);
5467 for (span
= 0; span
< sec_data
->mapcount
; span
++)
5469 unsigned int span_start
= sec_data
->map
[span
].vma
;
5470 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
5471 ? section
->size
: sec_data
->map
[span
+ 1].vma
;
5473 char span_type
= sec_data
->map
[span
].type
;
5474 bfd_boolean last_was_32bit
= FALSE
, last_was_branch
= FALSE
;
5476 if (span_type
!= 't')
5479 /* Span is entirely within a single 4KB region: skip scanning. */
5480 if (((base_vma
+ span_start
) & ~0xfff)
5481 == ((base_vma
+ span_end
) & ~0xfff))
5484 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
5486 * The opcode is BLX.W, BL.W, B.W, Bcc.W
5487 * The branch target is in the same 4KB region as the
5488 first half of the branch.
5489 * The instruction before the branch is a 32-bit
5490 length non-branch instruction. */
5491 for (i
= span_start
; i
< span_end
;)
5493 unsigned int insn
= bfd_getl16 (&contents
[i
]);
5494 bfd_boolean insn_32bit
= FALSE
, is_blx
= FALSE
, is_b
= FALSE
;
5495 bfd_boolean is_bl
= FALSE
, is_bcc
= FALSE
, is_32bit_branch
;
5497 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
5502 /* Load the rest of the insn (in manual-friendly order). */
5503 insn
= (insn
<< 16) | bfd_getl16 (&contents
[i
+ 2]);
5505 /* Encoding T4: B<c>.W. */
5506 is_b
= (insn
& 0xf800d000) == 0xf0009000;
5507 /* Encoding T1: BL<c>.W. */
5508 is_bl
= (insn
& 0xf800d000) == 0xf000d000;
5509 /* Encoding T2: BLX<c>.W. */
5510 is_blx
= (insn
& 0xf800d000) == 0xf000c000;
5511 /* Encoding T3: B<c>.W (not permitted in IT block). */
5512 is_bcc
= (insn
& 0xf800d000) == 0xf0008000
5513 && (insn
& 0x07f00000) != 0x03800000;
5516 is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
5518 if (((base_vma
+ i
) & 0xfff) == 0xffe
5522 && ! last_was_branch
)
5524 bfd_signed_vma offset
= 0;
5525 bfd_boolean force_target_arm
= FALSE
;
5526 bfd_boolean force_target_thumb
= FALSE
;
5528 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
5529 struct a8_erratum_reloc key
, *found
;
5530 bfd_boolean use_plt
= FALSE
;
5532 key
.from
= base_vma
+ i
;
5533 found
= (struct a8_erratum_reloc
*)
5534 bsearch (&key
, a8_relocs
, num_a8_relocs
,
5535 sizeof (struct a8_erratum_reloc
),
5540 char *error_message
= NULL
;
5541 struct elf_link_hash_entry
*entry
;
5543 /* We don't care about the error returned from this
5544 function, only if there is glue or not. */
5545 entry
= find_thumb_glue (info
, found
->sym_name
,
5549 found
->non_a8_stub
= TRUE
;
5551 /* Keep a simpler condition, for the sake of clarity. */
5552 if (htab
->root
.splt
!= NULL
&& found
->hash
!= NULL
5553 && found
->hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5556 if (found
->r_type
== R_ARM_THM_CALL
)
5558 if (found
->branch_type
== ST_BRANCH_TO_ARM
5560 force_target_arm
= TRUE
;
5562 force_target_thumb
= TRUE
;
5566 /* Check if we have an offending branch instruction. */
5568 if (found
&& found
->non_a8_stub
)
5569 /* We've already made a stub for this instruction, e.g.
5570 it's a long branch or a Thumb->ARM stub. Assume that
5571 stub will suffice to work around the A8 erratum (see
5572 setting of always_after_branch above). */
5576 offset
= (insn
& 0x7ff) << 1;
5577 offset
|= (insn
& 0x3f0000) >> 4;
5578 offset
|= (insn
& 0x2000) ? 0x40000 : 0;
5579 offset
|= (insn
& 0x800) ? 0x80000 : 0;
5580 offset
|= (insn
& 0x4000000) ? 0x100000 : 0;
5581 if (offset
& 0x100000)
5582 offset
|= ~ ((bfd_signed_vma
) 0xfffff);
5583 stub_type
= arm_stub_a8_veneer_b_cond
;
5585 else if (is_b
|| is_bl
|| is_blx
)
5587 int s
= (insn
& 0x4000000) != 0;
5588 int j1
= (insn
& 0x2000) != 0;
5589 int j2
= (insn
& 0x800) != 0;
5593 offset
= (insn
& 0x7ff) << 1;
5594 offset
|= (insn
& 0x3ff0000) >> 4;
5598 if (offset
& 0x1000000)
5599 offset
|= ~ ((bfd_signed_vma
) 0xffffff);
5602 offset
&= ~ ((bfd_signed_vma
) 3);
5604 stub_type
= is_blx
? arm_stub_a8_veneer_blx
:
5605 is_bl
? arm_stub_a8_veneer_bl
: arm_stub_a8_veneer_b
;
5608 if (stub_type
!= arm_stub_none
)
5610 bfd_vma pc_for_insn
= base_vma
+ i
+ 4;
5612 /* The original instruction is a BL, but the target is
5613 an ARM instruction. If we were not making a stub,
5614 the BL would have been converted to a BLX. Use the
5615 BLX stub instead in that case. */
5616 if (htab
->use_blx
&& force_target_arm
5617 && stub_type
== arm_stub_a8_veneer_bl
)
5619 stub_type
= arm_stub_a8_veneer_blx
;
5623 /* Conversely, if the original instruction was
5624 BLX but the target is Thumb mode, use the BL
5626 else if (force_target_thumb
5627 && stub_type
== arm_stub_a8_veneer_blx
)
5629 stub_type
= arm_stub_a8_veneer_bl
;
5635 pc_for_insn
&= ~ ((bfd_vma
) 3);
5637 /* If we found a relocation, use the proper destination,
5638 not the offset in the (unrelocated) instruction.
5639 Note this is always done if we switched the stub type
5643 (bfd_signed_vma
) (found
->destination
- pc_for_insn
);
5645 /* If the stub will use a Thumb-mode branch to a
5646 PLT target, redirect it to the preceding Thumb
5648 if (stub_type
!= arm_stub_a8_veneer_blx
&& use_plt
)
5649 offset
-= PLT_THUMB_STUB_SIZE
;
5651 target
= pc_for_insn
+ offset
;
5653 /* The BLX stub is ARM-mode code. Adjust the offset to
5654 take the different PC value (+8 instead of +4) into
5656 if (stub_type
== arm_stub_a8_veneer_blx
)
5659 if (((base_vma
+ i
) & ~0xfff) == (target
& ~0xfff))
5661 char *stub_name
= NULL
;
5663 if (num_a8_fixes
== a8_fix_table_size
)
5665 a8_fix_table_size
*= 2;
5666 a8_fixes
= (struct a8_erratum_fix
*)
5667 bfd_realloc (a8_fixes
,
5668 sizeof (struct a8_erratum_fix
)
5669 * a8_fix_table_size
);
5672 if (num_a8_fixes
< prev_num_a8_fixes
)
5674 /* If we're doing a subsequent scan,
5675 check if we've found the same fix as
5676 before, and try and reuse the stub
5678 stub_name
= a8_fixes
[num_a8_fixes
].stub_name
;
5679 if ((a8_fixes
[num_a8_fixes
].section
!= section
)
5680 || (a8_fixes
[num_a8_fixes
].offset
!= i
))
5684 *stub_changed_p
= TRUE
;
5690 stub_name
= (char *) bfd_malloc (8 + 1 + 8 + 1);
5691 if (stub_name
!= NULL
)
5692 sprintf (stub_name
, "%x:%x", section
->id
, i
);
5695 a8_fixes
[num_a8_fixes
].input_bfd
= input_bfd
;
5696 a8_fixes
[num_a8_fixes
].section
= section
;
5697 a8_fixes
[num_a8_fixes
].offset
= i
;
5698 a8_fixes
[num_a8_fixes
].target_offset
=
5700 a8_fixes
[num_a8_fixes
].orig_insn
= insn
;
5701 a8_fixes
[num_a8_fixes
].stub_name
= stub_name
;
5702 a8_fixes
[num_a8_fixes
].stub_type
= stub_type
;
5703 a8_fixes
[num_a8_fixes
].branch_type
=
5704 is_blx
? ST_BRANCH_TO_ARM
: ST_BRANCH_TO_THUMB
;
5711 i
+= insn_32bit
? 4 : 2;
5712 last_was_32bit
= insn_32bit
;
5713 last_was_branch
= is_32bit_branch
;
5717 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
5721 *a8_fixes_p
= a8_fixes
;
5722 *num_a8_fixes_p
= num_a8_fixes
;
5723 *a8_fix_table_size_p
= a8_fix_table_size
;
5728 /* Create or update a stub entry depending on whether the stub can already be
5729 found in HTAB. The stub is identified by:
5730 - its type STUB_TYPE
5731 - its source branch (note that several can share the same stub) whose
5732 section and relocation (if any) are given by SECTION and IRELA
5734 - its target symbol whose input section, hash, name, value and branch type
5735 are given in SYM_SEC, HASH, SYM_NAME, SYM_VALUE and BRANCH_TYPE
5738 If found, the value of the stub's target symbol is updated from SYM_VALUE
5739 and *NEW_STUB is set to FALSE. Otherwise, *NEW_STUB is set to
5740 TRUE and the stub entry is initialized.
5742 Returns the stub that was created or updated, or NULL if an error
5745 static struct elf32_arm_stub_hash_entry
*
5746 elf32_arm_create_stub (struct elf32_arm_link_hash_table
*htab
,
5747 enum elf32_arm_stub_type stub_type
, asection
*section
,
5748 Elf_Internal_Rela
*irela
, asection
*sym_sec
,
5749 struct elf32_arm_link_hash_entry
*hash
, char *sym_name
,
5750 bfd_vma sym_value
, enum arm_st_branch_type branch_type
,
5751 bfd_boolean
*new_stub
)
5753 const asection
*id_sec
;
5755 struct elf32_arm_stub_hash_entry
*stub_entry
;
5756 unsigned int r_type
;
5757 bfd_boolean sym_claimed
= arm_stub_sym_claimed (stub_type
);
5759 BFD_ASSERT (stub_type
!= arm_stub_none
);
5763 stub_name
= sym_name
;
5767 BFD_ASSERT (section
);
5768 BFD_ASSERT (section
->id
<= htab
->top_id
);
5770 /* Support for grouping stub sections. */
5771 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5773 /* Get the name of this stub. */
5774 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
, irela
,
5780 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
, FALSE
,
5782 /* The proper stub has already been created, just update its value. */
5783 if (stub_entry
!= NULL
)
5787 stub_entry
->target_value
= sym_value
;
5791 stub_entry
= elf32_arm_add_stub (stub_name
, section
, htab
, stub_type
);
5792 if (stub_entry
== NULL
)
5799 stub_entry
->target_value
= sym_value
;
5800 stub_entry
->target_section
= sym_sec
;
5801 stub_entry
->stub_type
= stub_type
;
5802 stub_entry
->h
= hash
;
5803 stub_entry
->branch_type
= branch_type
;
5806 stub_entry
->output_name
= sym_name
;
5809 if (sym_name
== NULL
)
5810 sym_name
= "unnamed";
5811 stub_entry
->output_name
= (char *)
5812 bfd_alloc (htab
->stub_bfd
, sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
5813 + strlen (sym_name
));
5814 if (stub_entry
->output_name
== NULL
)
5820 /* For historical reasons, use the existing names for ARM-to-Thumb and
5821 Thumb-to-ARM stubs. */
5822 r_type
= ELF32_R_TYPE (irela
->r_info
);
5823 if ((r_type
== (unsigned int) R_ARM_THM_CALL
5824 || r_type
== (unsigned int) R_ARM_THM_JUMP24
5825 || r_type
== (unsigned int) R_ARM_THM_JUMP19
)
5826 && branch_type
== ST_BRANCH_TO_ARM
)
5827 sprintf (stub_entry
->output_name
, THUMB2ARM_GLUE_ENTRY_NAME
, sym_name
);
5828 else if ((r_type
== (unsigned int) R_ARM_CALL
5829 || r_type
== (unsigned int) R_ARM_JUMP24
)
5830 && branch_type
== ST_BRANCH_TO_THUMB
)
5831 sprintf (stub_entry
->output_name
, ARM2THUMB_GLUE_ENTRY_NAME
, sym_name
);
5833 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
, sym_name
);
5840 /* Scan symbols in INPUT_BFD to identify secure entry functions needing a
5841 gateway veneer to transition from non secure to secure state and create them
5844 "ARMv8-M Security Extensions: Requirements on Development Tools" document
5845 defines the conditions that govern Secure Gateway veneer creation for a
5846 given symbol <SYM> as follows:
5847 - it has function type
5848 - it has non local binding
5849 - a symbol named __acle_se_<SYM> (called special symbol) exists with the
5850 same type, binding and value as <SYM> (called normal symbol).
5851 An entry function can handle secure state transition itself in which case
5852 its special symbol would have a different value from the normal symbol.
5854 OUT_ATTR gives the output attributes, SYM_HASHES the symbol index to hash
5855 entry mapping while HTAB gives the name to hash entry mapping.
5856 *CMSE_STUB_CREATED is increased by the number of secure gateway veneer
5859 The return value gives whether a stub failed to be allocated. */
5862 cmse_scan (bfd
*input_bfd
, struct elf32_arm_link_hash_table
*htab
,
5863 obj_attribute
*out_attr
, struct elf_link_hash_entry
**sym_hashes
,
5864 int *cmse_stub_created
)
5866 const struct elf_backend_data
*bed
;
5867 Elf_Internal_Shdr
*symtab_hdr
;
5868 unsigned i
, j
, sym_count
, ext_start
;
5869 Elf_Internal_Sym
*cmse_sym
, *local_syms
;
5870 struct elf32_arm_link_hash_entry
*hash
, *cmse_hash
= NULL
;
5871 enum arm_st_branch_type branch_type
;
5872 char *sym_name
, *lsym_name
;
5875 struct elf32_arm_stub_hash_entry
*stub_entry
;
5876 bfd_boolean is_v8m
, new_stub
, cmse_invalid
, ret
= TRUE
;
5878 bed
= get_elf_backend_data (input_bfd
);
5879 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5880 sym_count
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
5881 ext_start
= symtab_hdr
->sh_info
;
5882 is_v8m
= (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V8M_BASE
5883 && out_attr
[Tag_CPU_arch_profile
].i
== 'M');
5885 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5886 if (local_syms
== NULL
)
5887 local_syms
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5888 symtab_hdr
->sh_info
, 0, NULL
, NULL
,
5890 if (symtab_hdr
->sh_info
&& local_syms
== NULL
)
5894 for (i
= 0; i
< sym_count
; i
++)
5896 cmse_invalid
= FALSE
;
5900 cmse_sym
= &local_syms
[i
];
5901 /* Not a special symbol. */
5902 if (!ARM_GET_SYM_CMSE_SPCL (cmse_sym
->st_target_internal
))
5904 sym_name
= bfd_elf_string_from_elf_section (input_bfd
,
5905 symtab_hdr
->sh_link
,
5907 /* Special symbol with local binding. */
5908 cmse_invalid
= TRUE
;
5912 cmse_hash
= elf32_arm_hash_entry (sym_hashes
[i
- ext_start
]);
5913 sym_name
= (char *) cmse_hash
->root
.root
.root
.string
;
5915 /* Not a special symbol. */
5916 if (!ARM_GET_SYM_CMSE_SPCL (cmse_hash
->root
.target_internal
))
5919 /* Special symbol has incorrect binding or type. */
5920 if ((cmse_hash
->root
.root
.type
!= bfd_link_hash_defined
5921 && cmse_hash
->root
.root
.type
!= bfd_link_hash_defweak
)
5922 || cmse_hash
->root
.type
!= STT_FUNC
)
5923 cmse_invalid
= TRUE
;
5928 _bfd_error_handler (_("%pB: special symbol `%s' only allowed for "
5929 "ARMv8-M architecture or later"),
5930 input_bfd
, sym_name
);
5931 is_v8m
= TRUE
; /* Avoid multiple warning. */
5937 _bfd_error_handler (_("%pB: invalid special symbol `%s'; it must be"
5938 " a global or weak function symbol"),
5939 input_bfd
, sym_name
);
5945 sym_name
+= strlen (CMSE_PREFIX
);
5946 hash
= (struct elf32_arm_link_hash_entry
*)
5947 elf_link_hash_lookup (&(htab
)->root
, sym_name
, FALSE
, FALSE
, TRUE
);
5949 /* No associated normal symbol or it is neither global nor weak. */
5951 || (hash
->root
.root
.type
!= bfd_link_hash_defined
5952 && hash
->root
.root
.type
!= bfd_link_hash_defweak
)
5953 || hash
->root
.type
!= STT_FUNC
)
5955 /* Initialize here to avoid warning about use of possibly
5956 uninitialized variable. */
5961 /* Searching for a normal symbol with local binding. */
5962 for (; j
< ext_start
; j
++)
5965 bfd_elf_string_from_elf_section (input_bfd
,
5966 symtab_hdr
->sh_link
,
5967 local_syms
[j
].st_name
);
5968 if (!strcmp (sym_name
, lsym_name
))
5973 if (hash
|| j
< ext_start
)
5976 (_("%pB: invalid standard symbol `%s'; it must be "
5977 "a global or weak function symbol"),
5978 input_bfd
, sym_name
);
5982 (_("%pB: absent standard symbol `%s'"), input_bfd
, sym_name
);
5988 sym_value
= hash
->root
.root
.u
.def
.value
;
5989 section
= hash
->root
.root
.u
.def
.section
;
5991 if (cmse_hash
->root
.root
.u
.def
.section
!= section
)
5994 (_("%pB: `%s' and its special symbol are in different sections"),
5995 input_bfd
, sym_name
);
5998 if (cmse_hash
->root
.root
.u
.def
.value
!= sym_value
)
5999 continue; /* Ignore: could be an entry function starting with SG. */
6001 /* If this section is a link-once section that will be discarded, then
6002 don't create any stubs. */
6003 if (section
->output_section
== NULL
)
6006 (_("%pB: entry function `%s' not output"), input_bfd
, sym_name
);
6010 if (hash
->root
.size
== 0)
6013 (_("%pB: entry function `%s' is empty"), input_bfd
, sym_name
);
6019 branch_type
= ARM_GET_SYM_BRANCH_TYPE (hash
->root
.target_internal
);
6021 = elf32_arm_create_stub (htab
, arm_stub_cmse_branch_thumb_only
,
6022 NULL
, NULL
, section
, hash
, sym_name
,
6023 sym_value
, branch_type
, &new_stub
);
6025 if (stub_entry
== NULL
)
6029 BFD_ASSERT (new_stub
);
6030 (*cmse_stub_created
)++;
6034 if (!symtab_hdr
->contents
)
6039 /* Return TRUE iff a symbol identified by its linker HASH entry is a secure
6040 code entry function, ie can be called from non secure code without using a
6044 cmse_entry_fct_p (struct elf32_arm_link_hash_entry
*hash
)
6046 bfd_byte contents
[4];
6047 uint32_t first_insn
;
6052 /* Defined symbol of function type. */
6053 if (hash
->root
.root
.type
!= bfd_link_hash_defined
6054 && hash
->root
.root
.type
!= bfd_link_hash_defweak
)
6056 if (hash
->root
.type
!= STT_FUNC
)
6059 /* Read first instruction. */
6060 section
= hash
->root
.root
.u
.def
.section
;
6061 abfd
= section
->owner
;
6062 offset
= hash
->root
.root
.u
.def
.value
- section
->vma
;
6063 if (!bfd_get_section_contents (abfd
, section
, contents
, offset
,
6067 first_insn
= bfd_get_32 (abfd
, contents
);
6069 /* Starts by SG instruction. */
6070 return first_insn
== 0xe97fe97f;
6073 /* Output the name (in symbol table) of the veneer GEN_ENTRY if it is a new
6074 secure gateway veneers (ie. the veneers was not in the input import library)
6075 and there is no output import library (GEN_INFO->out_implib_bfd is NULL. */
6078 arm_list_new_cmse_stub (struct bfd_hash_entry
*gen_entry
, void *gen_info
)
6080 struct elf32_arm_stub_hash_entry
*stub_entry
;
6081 struct bfd_link_info
*info
;
6083 /* Massage our args to the form they really have. */
6084 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
6085 info
= (struct bfd_link_info
*) gen_info
;
6087 if (info
->out_implib_bfd
)
6090 if (stub_entry
->stub_type
!= arm_stub_cmse_branch_thumb_only
)
6093 if (stub_entry
->stub_offset
== (bfd_vma
) -1)
6094 _bfd_error_handler (" %s", stub_entry
->output_name
);
6099 /* Set offset of each secure gateway veneers so that its address remain
6100 identical to the one in the input import library referred by
6101 HTAB->in_implib_bfd. A warning is issued for veneers that disappeared
6102 (present in input import library but absent from the executable being
6103 linked) or if new veneers appeared and there is no output import library
6104 (INFO->out_implib_bfd is NULL and *CMSE_STUB_CREATED is bigger than the
6105 number of secure gateway veneers found in the input import library.
6107 The function returns whether an error occurred. If no error occurred,
6108 *CMSE_STUB_CREATED gives the number of SG veneers created by both cmse_scan
6109 and this function and HTAB->new_cmse_stub_offset is set to the biggest
6110 veneer observed set for new veneers to be layed out after. */
6113 set_cmse_veneer_addr_from_implib (struct bfd_link_info
*info
,
6114 struct elf32_arm_link_hash_table
*htab
,
6115 int *cmse_stub_created
)
6122 asection
*stub_out_sec
;
6123 bfd_boolean ret
= TRUE
;
6124 Elf_Internal_Sym
*intsym
;
6125 const char *out_sec_name
;
6126 bfd_size_type cmse_stub_size
;
6127 asymbol
**sympp
= NULL
, *sym
;
6128 struct elf32_arm_link_hash_entry
*hash
;
6129 const insn_sequence
*cmse_stub_template
;
6130 struct elf32_arm_stub_hash_entry
*stub_entry
;
6131 int cmse_stub_template_size
, new_cmse_stubs_created
= *cmse_stub_created
;
6132 bfd_vma veneer_value
, stub_offset
, next_cmse_stub_offset
;
6133 bfd_vma cmse_stub_array_start
= (bfd_vma
) -1, cmse_stub_sec_vma
= 0;
6135 /* No input secure gateway import library. */
6136 if (!htab
->in_implib_bfd
)
6139 in_implib_bfd
= htab
->in_implib_bfd
;
6140 if (!htab
->cmse_implib
)
6142 _bfd_error_handler (_("%pB: --in-implib only supported for Secure "
6143 "Gateway import libraries"), in_implib_bfd
);
6147 /* Get symbol table size. */
6148 symsize
= bfd_get_symtab_upper_bound (in_implib_bfd
);
6152 /* Read in the input secure gateway import library's symbol table. */
6153 sympp
= (asymbol
**) xmalloc (symsize
);
6154 symcount
= bfd_canonicalize_symtab (in_implib_bfd
, sympp
);
6161 htab
->new_cmse_stub_offset
= 0;
6163 find_stub_size_and_template (arm_stub_cmse_branch_thumb_only
,
6164 &cmse_stub_template
,
6165 &cmse_stub_template_size
);
6167 arm_dedicated_stub_output_section_name (arm_stub_cmse_branch_thumb_only
);
6169 bfd_get_section_by_name (htab
->obfd
, out_sec_name
);
6170 if (stub_out_sec
!= NULL
)
6171 cmse_stub_sec_vma
= stub_out_sec
->vma
;
6173 /* Set addresses of veneers mentionned in input secure gateway import
6174 library's symbol table. */
6175 for (i
= 0; i
< symcount
; i
++)
6179 sym_name
= (char *) bfd_asymbol_name (sym
);
6180 intsym
= &((elf_symbol_type
*) sym
)->internal_elf_sym
;
6182 if (sym
->section
!= bfd_abs_section_ptr
6183 || !(flags
& (BSF_GLOBAL
| BSF_WEAK
))
6184 || (flags
& BSF_FUNCTION
) != BSF_FUNCTION
6185 || (ARM_GET_SYM_BRANCH_TYPE (intsym
->st_target_internal
)
6186 != ST_BRANCH_TO_THUMB
))
6188 _bfd_error_handler (_("%pB: invalid import library entry: `%s'; "
6189 "symbol should be absolute, global and "
6190 "refer to Thumb functions"),
6191 in_implib_bfd
, sym_name
);
6196 veneer_value
= bfd_asymbol_value (sym
);
6197 stub_offset
= veneer_value
- cmse_stub_sec_vma
;
6198 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, sym_name
,
6200 hash
= (struct elf32_arm_link_hash_entry
*)
6201 elf_link_hash_lookup (&(htab
)->root
, sym_name
, FALSE
, FALSE
, TRUE
);
6203 /* Stub entry should have been created by cmse_scan or the symbol be of
6204 a secure function callable from non secure code. */
6205 if (!stub_entry
&& !hash
)
6207 bfd_boolean new_stub
;
6210 (_("entry function `%s' disappeared from secure code"), sym_name
);
6211 hash
= (struct elf32_arm_link_hash_entry
*)
6212 elf_link_hash_lookup (&(htab
)->root
, sym_name
, TRUE
, TRUE
, TRUE
);
6214 = elf32_arm_create_stub (htab
, arm_stub_cmse_branch_thumb_only
,
6215 NULL
, NULL
, bfd_abs_section_ptr
, hash
,
6216 sym_name
, veneer_value
,
6217 ST_BRANCH_TO_THUMB
, &new_stub
);
6218 if (stub_entry
== NULL
)
6222 BFD_ASSERT (new_stub
);
6223 new_cmse_stubs_created
++;
6224 (*cmse_stub_created
)++;
6226 stub_entry
->stub_template_size
= stub_entry
->stub_size
= 0;
6227 stub_entry
->stub_offset
= stub_offset
;
6229 /* Symbol found is not callable from non secure code. */
6230 else if (!stub_entry
)
6232 if (!cmse_entry_fct_p (hash
))
6234 _bfd_error_handler (_("`%s' refers to a non entry function"),
6242 /* Only stubs for SG veneers should have been created. */
6243 BFD_ASSERT (stub_entry
->stub_type
== arm_stub_cmse_branch_thumb_only
);
6245 /* Check visibility hasn't changed. */
6246 if (!!(flags
& BSF_GLOBAL
)
6247 != (hash
->root
.root
.type
== bfd_link_hash_defined
))
6249 (_("%pB: visibility of symbol `%s' has changed"), in_implib_bfd
,
6252 stub_entry
->stub_offset
= stub_offset
;
6255 /* Size should match that of a SG veneer. */
6256 if (intsym
->st_size
!= cmse_stub_size
)
6258 _bfd_error_handler (_("%pB: incorrect size for symbol `%s'"),
6259 in_implib_bfd
, sym_name
);
6263 /* Previous veneer address is before current SG veneer section. */
6264 if (veneer_value
< cmse_stub_sec_vma
)
6266 /* Avoid offset underflow. */
6268 stub_entry
->stub_offset
= 0;
6273 /* Complain if stub offset not a multiple of stub size. */
6274 if (stub_offset
% cmse_stub_size
)
6277 (_("offset of veneer for entry function `%s' not a multiple of "
6278 "its size"), sym_name
);
6285 new_cmse_stubs_created
--;
6286 if (veneer_value
< cmse_stub_array_start
)
6287 cmse_stub_array_start
= veneer_value
;
6288 next_cmse_stub_offset
= stub_offset
+ ((cmse_stub_size
+ 7) & ~7);
6289 if (next_cmse_stub_offset
> htab
->new_cmse_stub_offset
)
6290 htab
->new_cmse_stub_offset
= next_cmse_stub_offset
;
6293 if (!info
->out_implib_bfd
&& new_cmse_stubs_created
!= 0)
6295 BFD_ASSERT (new_cmse_stubs_created
> 0);
6297 (_("new entry function(s) introduced but no output import library "
6299 bfd_hash_traverse (&htab
->stub_hash_table
, arm_list_new_cmse_stub
, info
);
6302 if (cmse_stub_array_start
!= cmse_stub_sec_vma
)
6305 (_("start address of `%s' is different from previous link"),
6315 /* Determine and set the size of the stub section for a final link.
6317 The basic idea here is to examine all the relocations looking for
6318 PC-relative calls to a target that is unreachable with a "bl"
6322 elf32_arm_size_stubs (bfd
*output_bfd
,
6324 struct bfd_link_info
*info
,
6325 bfd_signed_vma group_size
,
6326 asection
* (*add_stub_section
) (const char *, asection
*,
6329 void (*layout_sections_again
) (void))
6331 bfd_boolean ret
= TRUE
;
6332 obj_attribute
*out_attr
;
6333 int cmse_stub_created
= 0;
6334 bfd_size_type stub_group_size
;
6335 bfd_boolean m_profile
, stubs_always_after_branch
, first_veneer_scan
= TRUE
;
6336 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
6337 struct a8_erratum_fix
*a8_fixes
= NULL
;
6338 unsigned int num_a8_fixes
= 0, a8_fix_table_size
= 10;
6339 struct a8_erratum_reloc
*a8_relocs
= NULL
;
6340 unsigned int num_a8_relocs
= 0, a8_reloc_table_size
= 10, i
;
6345 if (htab
->fix_cortex_a8
)
6347 a8_fixes
= (struct a8_erratum_fix
*)
6348 bfd_zmalloc (sizeof (struct a8_erratum_fix
) * a8_fix_table_size
);
6349 a8_relocs
= (struct a8_erratum_reloc
*)
6350 bfd_zmalloc (sizeof (struct a8_erratum_reloc
) * a8_reloc_table_size
);
6353 /* Propagate mach to stub bfd, because it may not have been
6354 finalized when we created stub_bfd. */
6355 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
6356 bfd_get_mach (output_bfd
));
6358 /* Stash our params away. */
6359 htab
->stub_bfd
= stub_bfd
;
6360 htab
->add_stub_section
= add_stub_section
;
6361 htab
->layout_sections_again
= layout_sections_again
;
6362 stubs_always_after_branch
= group_size
< 0;
6364 out_attr
= elf_known_obj_attributes_proc (output_bfd
);
6365 m_profile
= out_attr
[Tag_CPU_arch_profile
].i
== 'M';
6367 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
6368 as the first half of a 32-bit branch straddling two 4K pages. This is a
6369 crude way of enforcing that. */
6370 if (htab
->fix_cortex_a8
)
6371 stubs_always_after_branch
= 1;
6374 stub_group_size
= -group_size
;
6376 stub_group_size
= group_size
;
6378 if (stub_group_size
== 1)
6380 /* Default values. */
6381 /* Thumb branch range is +-4MB has to be used as the default
6382 maximum size (a given section can contain both ARM and Thumb
6383 code, so the worst case has to be taken into account).
6385 This value is 24K less than that, which allows for 2025
6386 12-byte stubs. If we exceed that, then we will fail to link.
6387 The user will have to relink with an explicit group size
6389 stub_group_size
= 4170000;
6392 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
6394 /* If we're applying the cortex A8 fix, we need to determine the
6395 program header size now, because we cannot change it later --
6396 that could alter section placements. Notice the A8 erratum fix
6397 ends up requiring the section addresses to remain unchanged
6398 modulo the page size. That's something we cannot represent
6399 inside BFD, and we don't want to force the section alignment to
6400 be the page size. */
6401 if (htab
->fix_cortex_a8
)
6402 (*htab
->layout_sections_again
) ();
6407 unsigned int bfd_indx
;
6409 enum elf32_arm_stub_type stub_type
;
6410 bfd_boolean stub_changed
= FALSE
;
6411 unsigned prev_num_a8_fixes
= num_a8_fixes
;
6414 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
6416 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
6418 Elf_Internal_Shdr
*symtab_hdr
;
6420 Elf_Internal_Sym
*local_syms
= NULL
;
6422 if (!is_arm_elf (input_bfd
))
6427 /* We'll need the symbol table in a second. */
6428 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6429 if (symtab_hdr
->sh_info
== 0)
6432 /* Limit scan of symbols to object file whose profile is
6433 Microcontroller to not hinder performance in the general case. */
6434 if (m_profile
&& first_veneer_scan
)
6436 struct elf_link_hash_entry
**sym_hashes
;
6438 sym_hashes
= elf_sym_hashes (input_bfd
);
6439 if (!cmse_scan (input_bfd
, htab
, out_attr
, sym_hashes
,
6440 &cmse_stub_created
))
6441 goto error_ret_free_local
;
6443 if (cmse_stub_created
!= 0)
6444 stub_changed
= TRUE
;
6447 /* Walk over each section attached to the input bfd. */
6448 for (section
= input_bfd
->sections
;
6450 section
= section
->next
)
6452 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
6454 /* If there aren't any relocs, then there's nothing more
6456 if ((section
->flags
& SEC_RELOC
) == 0
6457 || section
->reloc_count
== 0
6458 || (section
->flags
& SEC_CODE
) == 0)
6461 /* If this section is a link-once section that will be
6462 discarded, then don't create any stubs. */
6463 if (section
->output_section
== NULL
6464 || section
->output_section
->owner
!= output_bfd
)
6467 /* Get the relocs. */
6469 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
6470 NULL
, info
->keep_memory
);
6471 if (internal_relocs
== NULL
)
6472 goto error_ret_free_local
;
6474 /* Now examine each relocation. */
6475 irela
= internal_relocs
;
6476 irelaend
= irela
+ section
->reloc_count
;
6477 for (; irela
< irelaend
; irela
++)
6479 unsigned int r_type
, r_indx
;
6482 bfd_vma destination
;
6483 struct elf32_arm_link_hash_entry
*hash
;
6484 const char *sym_name
;
6485 unsigned char st_type
;
6486 enum arm_st_branch_type branch_type
;
6487 bfd_boolean created_stub
= FALSE
;
6489 r_type
= ELF32_R_TYPE (irela
->r_info
);
6490 r_indx
= ELF32_R_SYM (irela
->r_info
);
6492 if (r_type
>= (unsigned int) R_ARM_max
)
6494 bfd_set_error (bfd_error_bad_value
);
6495 error_ret_free_internal
:
6496 if (elf_section_data (section
)->relocs
== NULL
)
6497 free (internal_relocs
);
6499 error_ret_free_local
:
6500 if (local_syms
!= NULL
6501 && (symtab_hdr
->contents
6502 != (unsigned char *) local_syms
))
6508 if (r_indx
>= symtab_hdr
->sh_info
)
6509 hash
= elf32_arm_hash_entry
6510 (elf_sym_hashes (input_bfd
)
6511 [r_indx
- symtab_hdr
->sh_info
]);
6513 /* Only look for stubs on branch instructions, or
6514 non-relaxed TLSCALL */
6515 if ((r_type
!= (unsigned int) R_ARM_CALL
)
6516 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
6517 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
6518 && (r_type
!= (unsigned int) R_ARM_THM_JUMP19
)
6519 && (r_type
!= (unsigned int) R_ARM_THM_XPC22
)
6520 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
6521 && (r_type
!= (unsigned int) R_ARM_PLT32
)
6522 && !((r_type
== (unsigned int) R_ARM_TLS_CALL
6523 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
6524 && r_type
== elf32_arm_tls_transition
6525 (info
, r_type
, &hash
->root
)
6526 && ((hash
? hash
->tls_type
6527 : (elf32_arm_local_got_tls_type
6528 (input_bfd
)[r_indx
]))
6529 & GOT_TLS_GDESC
) != 0))
6532 /* Now determine the call target, its name, value,
6539 if (r_type
== (unsigned int) R_ARM_TLS_CALL
6540 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
6542 /* A non-relaxed TLS call. The target is the
6543 plt-resident trampoline and nothing to do
6545 BFD_ASSERT (htab
->tls_trampoline
> 0);
6546 sym_sec
= htab
->root
.splt
;
6547 sym_value
= htab
->tls_trampoline
;
6550 branch_type
= ST_BRANCH_TO_ARM
;
6554 /* It's a local symbol. */
6555 Elf_Internal_Sym
*sym
;
6557 if (local_syms
== NULL
)
6560 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6561 if (local_syms
== NULL
)
6563 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
6564 symtab_hdr
->sh_info
, 0,
6566 if (local_syms
== NULL
)
6567 goto error_ret_free_internal
;
6570 sym
= local_syms
+ r_indx
;
6571 if (sym
->st_shndx
== SHN_UNDEF
)
6572 sym_sec
= bfd_und_section_ptr
;
6573 else if (sym
->st_shndx
== SHN_ABS
)
6574 sym_sec
= bfd_abs_section_ptr
;
6575 else if (sym
->st_shndx
== SHN_COMMON
)
6576 sym_sec
= bfd_com_section_ptr
;
6579 bfd_section_from_elf_index (input_bfd
, sym
->st_shndx
);
6582 /* This is an undefined symbol. It can never
6586 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
6587 sym_value
= sym
->st_value
;
6588 destination
= (sym_value
+ irela
->r_addend
6589 + sym_sec
->output_offset
6590 + sym_sec
->output_section
->vma
);
6591 st_type
= ELF_ST_TYPE (sym
->st_info
);
6593 ARM_GET_SYM_BRANCH_TYPE (sym
->st_target_internal
);
6595 = bfd_elf_string_from_elf_section (input_bfd
,
6596 symtab_hdr
->sh_link
,
6601 /* It's an external symbol. */
6602 while (hash
->root
.root
.type
== bfd_link_hash_indirect
6603 || hash
->root
.root
.type
== bfd_link_hash_warning
)
6604 hash
= ((struct elf32_arm_link_hash_entry
*)
6605 hash
->root
.root
.u
.i
.link
);
6607 if (hash
->root
.root
.type
== bfd_link_hash_defined
6608 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
6610 sym_sec
= hash
->root
.root
.u
.def
.section
;
6611 sym_value
= hash
->root
.root
.u
.def
.value
;
6613 struct elf32_arm_link_hash_table
*globals
=
6614 elf32_arm_hash_table (info
);
6616 /* For a destination in a shared library,
6617 use the PLT stub as target address to
6618 decide whether a branch stub is
6621 && globals
->root
.splt
!= NULL
6623 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
6625 sym_sec
= globals
->root
.splt
;
6626 sym_value
= hash
->root
.plt
.offset
;
6627 if (sym_sec
->output_section
!= NULL
)
6628 destination
= (sym_value
6629 + sym_sec
->output_offset
6630 + sym_sec
->output_section
->vma
);
6632 else if (sym_sec
->output_section
!= NULL
)
6633 destination
= (sym_value
+ irela
->r_addend
6634 + sym_sec
->output_offset
6635 + sym_sec
->output_section
->vma
);
6637 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
6638 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
6640 /* For a shared library, use the PLT stub as
6641 target address to decide whether a long
6642 branch stub is needed.
6643 For absolute code, they cannot be handled. */
6644 struct elf32_arm_link_hash_table
*globals
=
6645 elf32_arm_hash_table (info
);
6648 && globals
->root
.splt
!= NULL
6650 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
6652 sym_sec
= globals
->root
.splt
;
6653 sym_value
= hash
->root
.plt
.offset
;
6654 if (sym_sec
->output_section
!= NULL
)
6655 destination
= (sym_value
6656 + sym_sec
->output_offset
6657 + sym_sec
->output_section
->vma
);
6664 bfd_set_error (bfd_error_bad_value
);
6665 goto error_ret_free_internal
;
6667 st_type
= hash
->root
.type
;
6669 ARM_GET_SYM_BRANCH_TYPE (hash
->root
.target_internal
);
6670 sym_name
= hash
->root
.root
.root
.string
;
6675 bfd_boolean new_stub
;
6676 struct elf32_arm_stub_hash_entry
*stub_entry
;
6678 /* Determine what (if any) linker stub is needed. */
6679 stub_type
= arm_type_of_stub (info
, section
, irela
,
6680 st_type
, &branch_type
,
6681 hash
, destination
, sym_sec
,
6682 input_bfd
, sym_name
);
6683 if (stub_type
== arm_stub_none
)
6686 /* We've either created a stub for this reloc already,
6687 or we are about to. */
6689 elf32_arm_create_stub (htab
, stub_type
, section
, irela
,
6691 (char *) sym_name
, sym_value
,
6692 branch_type
, &new_stub
);
6694 created_stub
= stub_entry
!= NULL
;
6696 goto error_ret_free_internal
;
6700 stub_changed
= TRUE
;
6704 /* Look for relocations which might trigger Cortex-A8
6706 if (htab
->fix_cortex_a8
6707 && (r_type
== (unsigned int) R_ARM_THM_JUMP24
6708 || r_type
== (unsigned int) R_ARM_THM_JUMP19
6709 || r_type
== (unsigned int) R_ARM_THM_CALL
6710 || r_type
== (unsigned int) R_ARM_THM_XPC22
))
6712 bfd_vma from
= section
->output_section
->vma
6713 + section
->output_offset
6716 if ((from
& 0xfff) == 0xffe)
6718 /* Found a candidate. Note we haven't checked the
6719 destination is within 4K here: if we do so (and
6720 don't create an entry in a8_relocs) we can't tell
6721 that a branch should have been relocated when
6723 if (num_a8_relocs
== a8_reloc_table_size
)
6725 a8_reloc_table_size
*= 2;
6726 a8_relocs
= (struct a8_erratum_reloc
*)
6727 bfd_realloc (a8_relocs
,
6728 sizeof (struct a8_erratum_reloc
)
6729 * a8_reloc_table_size
);
6732 a8_relocs
[num_a8_relocs
].from
= from
;
6733 a8_relocs
[num_a8_relocs
].destination
= destination
;
6734 a8_relocs
[num_a8_relocs
].r_type
= r_type
;
6735 a8_relocs
[num_a8_relocs
].branch_type
= branch_type
;
6736 a8_relocs
[num_a8_relocs
].sym_name
= sym_name
;
6737 a8_relocs
[num_a8_relocs
].non_a8_stub
= created_stub
;
6738 a8_relocs
[num_a8_relocs
].hash
= hash
;
6745 /* We're done with the internal relocs, free them. */
6746 if (elf_section_data (section
)->relocs
== NULL
)
6747 free (internal_relocs
);
6750 if (htab
->fix_cortex_a8
)
6752 /* Sort relocs which might apply to Cortex-A8 erratum. */
6753 qsort (a8_relocs
, num_a8_relocs
,
6754 sizeof (struct a8_erratum_reloc
),
6757 /* Scan for branches which might trigger Cortex-A8 erratum. */
6758 if (cortex_a8_erratum_scan (input_bfd
, info
, &a8_fixes
,
6759 &num_a8_fixes
, &a8_fix_table_size
,
6760 a8_relocs
, num_a8_relocs
,
6761 prev_num_a8_fixes
, &stub_changed
)
6763 goto error_ret_free_local
;
6766 if (local_syms
!= NULL
6767 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6769 if (!info
->keep_memory
)
6772 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6776 if (first_veneer_scan
6777 && !set_cmse_veneer_addr_from_implib (info
, htab
,
6778 &cmse_stub_created
))
6781 if (prev_num_a8_fixes
!= num_a8_fixes
)
6782 stub_changed
= TRUE
;
6787 /* OK, we've added some stubs. Find out the new size of the
6789 for (stub_sec
= htab
->stub_bfd
->sections
;
6791 stub_sec
= stub_sec
->next
)
6793 /* Ignore non-stub sections. */
6794 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
6800 /* Add new SG veneers after those already in the input import
6802 for (stub_type
= arm_stub_none
+ 1; stub_type
< max_stub_type
;
6805 bfd_vma
*start_offset_p
;
6806 asection
**stub_sec_p
;
6808 start_offset_p
= arm_new_stubs_start_offset_ptr (htab
, stub_type
);
6809 stub_sec_p
= arm_dedicated_stub_input_section_ptr (htab
, stub_type
);
6810 if (start_offset_p
== NULL
)
6813 BFD_ASSERT (stub_sec_p
!= NULL
);
6814 if (*stub_sec_p
!= NULL
)
6815 (*stub_sec_p
)->size
= *start_offset_p
;
6818 /* Compute stub section size, considering padding. */
6819 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
6820 for (stub_type
= arm_stub_none
+ 1; stub_type
< max_stub_type
;
6824 asection
**stub_sec_p
;
6826 padding
= arm_dedicated_stub_section_padding (stub_type
);
6827 stub_sec_p
= arm_dedicated_stub_input_section_ptr (htab
, stub_type
);
6828 /* Skip if no stub input section or no stub section padding
6830 if ((stub_sec_p
!= NULL
&& *stub_sec_p
== NULL
) || padding
== 0)
6832 /* Stub section padding required but no dedicated section. */
6833 BFD_ASSERT (stub_sec_p
);
6835 size
= (*stub_sec_p
)->size
;
6836 size
= (size
+ padding
- 1) & ~(padding
- 1);
6837 (*stub_sec_p
)->size
= size
;
6840 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
6841 if (htab
->fix_cortex_a8
)
6842 for (i
= 0; i
< num_a8_fixes
; i
++)
6844 stub_sec
= elf32_arm_create_or_find_stub_sec (NULL
,
6845 a8_fixes
[i
].section
, htab
, a8_fixes
[i
].stub_type
);
6847 if (stub_sec
== NULL
)
6851 += find_stub_size_and_template (a8_fixes
[i
].stub_type
, NULL
,
6856 /* Ask the linker to do its stuff. */
6857 (*htab
->layout_sections_again
) ();
6858 first_veneer_scan
= FALSE
;
6861 /* Add stubs for Cortex-A8 erratum fixes now. */
6862 if (htab
->fix_cortex_a8
)
6864 for (i
= 0; i
< num_a8_fixes
; i
++)
6866 struct elf32_arm_stub_hash_entry
*stub_entry
;
6867 char *stub_name
= a8_fixes
[i
].stub_name
;
6868 asection
*section
= a8_fixes
[i
].section
;
6869 unsigned int section_id
= a8_fixes
[i
].section
->id
;
6870 asection
*link_sec
= htab
->stub_group
[section_id
].link_sec
;
6871 asection
*stub_sec
= htab
->stub_group
[section_id
].stub_sec
;
6872 const insn_sequence
*template_sequence
;
6873 int template_size
, size
= 0;
6875 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
6877 if (stub_entry
== NULL
)
6879 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
6880 section
->owner
, stub_name
);
6884 stub_entry
->stub_sec
= stub_sec
;
6885 stub_entry
->stub_offset
= (bfd_vma
) -1;
6886 stub_entry
->id_sec
= link_sec
;
6887 stub_entry
->stub_type
= a8_fixes
[i
].stub_type
;
6888 stub_entry
->source_value
= a8_fixes
[i
].offset
;
6889 stub_entry
->target_section
= a8_fixes
[i
].section
;
6890 stub_entry
->target_value
= a8_fixes
[i
].target_offset
;
6891 stub_entry
->orig_insn
= a8_fixes
[i
].orig_insn
;
6892 stub_entry
->branch_type
= a8_fixes
[i
].branch_type
;
6894 size
= find_stub_size_and_template (a8_fixes
[i
].stub_type
,
6898 stub_entry
->stub_size
= size
;
6899 stub_entry
->stub_template
= template_sequence
;
6900 stub_entry
->stub_template_size
= template_size
;
6903 /* Stash the Cortex-A8 erratum fix array for use later in
6904 elf32_arm_write_section(). */
6905 htab
->a8_erratum_fixes
= a8_fixes
;
6906 htab
->num_a8_erratum_fixes
= num_a8_fixes
;
6910 htab
->a8_erratum_fixes
= NULL
;
6911 htab
->num_a8_erratum_fixes
= 0;
6916 /* Build all the stubs associated with the current output file. The
6917 stubs are kept in a hash table attached to the main linker hash
6918 table. We also set up the .plt entries for statically linked PIC
6919 functions here. This function is called via arm_elf_finish in the
6923 elf32_arm_build_stubs (struct bfd_link_info
*info
)
6926 struct bfd_hash_table
*table
;
6927 enum elf32_arm_stub_type stub_type
;
6928 struct elf32_arm_link_hash_table
*htab
;
6930 htab
= elf32_arm_hash_table (info
);
6934 for (stub_sec
= htab
->stub_bfd
->sections
;
6936 stub_sec
= stub_sec
->next
)
6940 /* Ignore non-stub sections. */
6941 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
6944 /* Allocate memory to hold the linker stubs. Zeroing the stub sections
6945 must at least be done for stub section requiring padding and for SG
6946 veneers to ensure that a non secure code branching to a removed SG
6947 veneer causes an error. */
6948 size
= stub_sec
->size
;
6949 stub_sec
->contents
= (unsigned char *) bfd_zalloc (htab
->stub_bfd
, size
);
6950 if (stub_sec
->contents
== NULL
&& size
!= 0)
6956 /* Add new SG veneers after those already in the input import library. */
6957 for (stub_type
= arm_stub_none
+ 1; stub_type
< max_stub_type
; stub_type
++)
6959 bfd_vma
*start_offset_p
;
6960 asection
**stub_sec_p
;
6962 start_offset_p
= arm_new_stubs_start_offset_ptr (htab
, stub_type
);
6963 stub_sec_p
= arm_dedicated_stub_input_section_ptr (htab
, stub_type
);
6964 if (start_offset_p
== NULL
)
6967 BFD_ASSERT (stub_sec_p
!= NULL
);
6968 if (*stub_sec_p
!= NULL
)
6969 (*stub_sec_p
)->size
= *start_offset_p
;
6972 /* Build the stubs as directed by the stub hash table. */
6973 table
= &htab
->stub_hash_table
;
6974 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
6975 if (htab
->fix_cortex_a8
)
6977 /* Place the cortex a8 stubs last. */
6978 htab
->fix_cortex_a8
= -1;
6979 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
6985 /* Locate the Thumb encoded calling stub for NAME. */
6987 static struct elf_link_hash_entry
*
6988 find_thumb_glue (struct bfd_link_info
*link_info
,
6990 char **error_message
)
6993 struct elf_link_hash_entry
*hash
;
6994 struct elf32_arm_link_hash_table
*hash_table
;
6996 /* We need a pointer to the armelf specific hash table. */
6997 hash_table
= elf32_arm_hash_table (link_info
);
6998 if (hash_table
== NULL
)
7001 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
7002 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
7004 BFD_ASSERT (tmp_name
);
7006 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
7008 hash
= elf_link_hash_lookup
7009 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
7012 && asprintf (error_message
, _("unable to find %s glue '%s' for '%s'"),
7013 "Thumb", tmp_name
, name
) == -1)
7014 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
7021 /* Locate the ARM encoded calling stub for NAME. */
7023 static struct elf_link_hash_entry
*
7024 find_arm_glue (struct bfd_link_info
*link_info
,
7026 char **error_message
)
7029 struct elf_link_hash_entry
*myh
;
7030 struct elf32_arm_link_hash_table
*hash_table
;
7032 /* We need a pointer to the elfarm specific hash table. */
7033 hash_table
= elf32_arm_hash_table (link_info
);
7034 if (hash_table
== NULL
)
7037 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
7038 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
7040 BFD_ASSERT (tmp_name
);
7042 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
7044 myh
= elf_link_hash_lookup
7045 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
7048 && asprintf (error_message
, _("unable to find %s glue '%s' for '%s'"),
7049 "ARM", tmp_name
, name
) == -1)
7050 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
7057 /* ARM->Thumb glue (static images):
7061 ldr r12, __func_addr
7064 .word func @ behave as if you saw a ARM_32 reloc.
7071 .word func @ behave as if you saw a ARM_32 reloc.
7073 (relocatable images)
7076 ldr r12, __func_offset
7082 #define ARM2THUMB_STATIC_GLUE_SIZE 12
7083 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
7084 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
7085 static const insn32 a2t3_func_addr_insn
= 0x00000001;
7087 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
7088 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
7089 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
7091 #define ARM2THUMB_PIC_GLUE_SIZE 16
7092 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
7093 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
7094 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
7096 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
7100 __func_from_thumb: __func_from_thumb:
7102 nop ldr r6, __func_addr
7112 #define THUMB2ARM_GLUE_SIZE 8
7113 static const insn16 t2a1_bx_pc_insn
= 0x4778;
7114 static const insn16 t2a2_noop_insn
= 0x46c0;
7115 static const insn32 t2a3_b_insn
= 0xea000000;
7117 #define VFP11_ERRATUM_VENEER_SIZE 8
7118 #define STM32L4XX_ERRATUM_LDM_VENEER_SIZE 16
7119 #define STM32L4XX_ERRATUM_VLDM_VENEER_SIZE 24
7121 #define ARM_BX_VENEER_SIZE 12
7122 static const insn32 armbx1_tst_insn
= 0xe3100001;
7123 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
7124 static const insn32 armbx3_bx_insn
= 0xe12fff10;
7126 #ifndef ELFARM_NABI_C_INCLUDED
7128 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
7131 bfd_byte
* contents
;
7135 /* Do not include empty glue sections in the output. */
7138 s
= bfd_get_linker_section (abfd
, name
);
7140 s
->flags
|= SEC_EXCLUDE
;
7145 BFD_ASSERT (abfd
!= NULL
);
7147 s
= bfd_get_linker_section (abfd
, name
);
7148 BFD_ASSERT (s
!= NULL
);
7150 contents
= (bfd_byte
*) bfd_alloc (abfd
, size
);
7152 BFD_ASSERT (s
->size
== size
);
7153 s
->contents
= contents
;
7157 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
7159 struct elf32_arm_link_hash_table
* globals
;
7161 globals
= elf32_arm_hash_table (info
);
7162 BFD_ASSERT (globals
!= NULL
);
7164 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
7165 globals
->arm_glue_size
,
7166 ARM2THUMB_GLUE_SECTION_NAME
);
7168 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
7169 globals
->thumb_glue_size
,
7170 THUMB2ARM_GLUE_SECTION_NAME
);
7172 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
7173 globals
->vfp11_erratum_glue_size
,
7174 VFP11_ERRATUM_VENEER_SECTION_NAME
);
7176 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
7177 globals
->stm32l4xx_erratum_glue_size
,
7178 STM32L4XX_ERRATUM_VENEER_SECTION_NAME
);
7180 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
7181 globals
->bx_glue_size
,
7182 ARM_BX_GLUE_SECTION_NAME
);
7187 /* Allocate space and symbols for calling a Thumb function from Arm mode.
7188 returns the symbol identifying the stub. */
7190 static struct elf_link_hash_entry
*
7191 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
7192 struct elf_link_hash_entry
* h
)
7194 const char * name
= h
->root
.root
.string
;
7197 struct elf_link_hash_entry
* myh
;
7198 struct bfd_link_hash_entry
* bh
;
7199 struct elf32_arm_link_hash_table
* globals
;
7203 globals
= elf32_arm_hash_table (link_info
);
7204 BFD_ASSERT (globals
!= NULL
);
7205 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7207 s
= bfd_get_linker_section
7208 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
7210 BFD_ASSERT (s
!= NULL
);
7212 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
7213 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
7215 BFD_ASSERT (tmp_name
);
7217 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
7219 myh
= elf_link_hash_lookup
7220 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
7224 /* We've already seen this guy. */
7229 /* The only trick here is using hash_table->arm_glue_size as the value.
7230 Even though the section isn't allocated yet, this is where we will be
7231 putting it. The +1 on the value marks that the stub has not been
7232 output yet - not that it is a Thumb function. */
7234 val
= globals
->arm_glue_size
+ 1;
7235 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
7236 tmp_name
, BSF_GLOBAL
, s
, val
,
7237 NULL
, TRUE
, FALSE
, &bh
);
7239 myh
= (struct elf_link_hash_entry
*) bh
;
7240 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7241 myh
->forced_local
= 1;
7245 if (bfd_link_pic (link_info
)
7246 || globals
->root
.is_relocatable_executable
7247 || globals
->pic_veneer
)
7248 size
= ARM2THUMB_PIC_GLUE_SIZE
;
7249 else if (globals
->use_blx
)
7250 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
7252 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
7255 globals
->arm_glue_size
+= size
;
7260 /* Allocate space for ARMv4 BX veneers. */
7263 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
7266 struct elf32_arm_link_hash_table
*globals
;
7268 struct elf_link_hash_entry
*myh
;
7269 struct bfd_link_hash_entry
*bh
;
7272 /* BX PC does not need a veneer. */
7276 globals
= elf32_arm_hash_table (link_info
);
7277 BFD_ASSERT (globals
!= NULL
);
7278 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7280 /* Check if this veneer has already been allocated. */
7281 if (globals
->bx_glue_offset
[reg
])
7284 s
= bfd_get_linker_section
7285 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
7287 BFD_ASSERT (s
!= NULL
);
7289 /* Add symbol for veneer. */
7291 bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
7293 BFD_ASSERT (tmp_name
);
7295 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
7297 myh
= elf_link_hash_lookup
7298 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
7300 BFD_ASSERT (myh
== NULL
);
7303 val
= globals
->bx_glue_size
;
7304 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
7305 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
7306 NULL
, TRUE
, FALSE
, &bh
);
7308 myh
= (struct elf_link_hash_entry
*) bh
;
7309 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7310 myh
->forced_local
= 1;
7312 s
->size
+= ARM_BX_VENEER_SIZE
;
7313 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
7314 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
7318 /* Add an entry to the code/data map for section SEC. */
7321 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
7323 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
7324 unsigned int newidx
;
7326 if (sec_data
->map
== NULL
)
7328 sec_data
->map
= (elf32_arm_section_map
*)
7329 bfd_malloc (sizeof (elf32_arm_section_map
));
7330 sec_data
->mapcount
= 0;
7331 sec_data
->mapsize
= 1;
7334 newidx
= sec_data
->mapcount
++;
7336 if (sec_data
->mapcount
> sec_data
->mapsize
)
7338 sec_data
->mapsize
*= 2;
7339 sec_data
->map
= (elf32_arm_section_map
*)
7340 bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
7341 * sizeof (elf32_arm_section_map
));
7346 sec_data
->map
[newidx
].vma
= vma
;
7347 sec_data
->map
[newidx
].type
= type
;
7352 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
7353 veneers are handled for now. */
7356 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
7357 elf32_vfp11_erratum_list
*branch
,
7359 asection
*branch_sec
,
7360 unsigned int offset
)
7363 struct elf32_arm_link_hash_table
*hash_table
;
7365 struct elf_link_hash_entry
*myh
;
7366 struct bfd_link_hash_entry
*bh
;
7368 struct _arm_elf_section_data
*sec_data
;
7369 elf32_vfp11_erratum_list
*newerr
;
7371 hash_table
= elf32_arm_hash_table (link_info
);
7372 BFD_ASSERT (hash_table
!= NULL
);
7373 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
7375 s
= bfd_get_linker_section
7376 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
7378 sec_data
= elf32_arm_section_data (s
);
7380 BFD_ASSERT (s
!= NULL
);
7382 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
7383 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
7385 BFD_ASSERT (tmp_name
);
7387 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
7388 hash_table
->num_vfp11_fixes
);
7390 myh
= elf_link_hash_lookup
7391 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
7393 BFD_ASSERT (myh
== NULL
);
7396 val
= hash_table
->vfp11_erratum_glue_size
;
7397 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
7398 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
7399 NULL
, TRUE
, FALSE
, &bh
);
7401 myh
= (struct elf_link_hash_entry
*) bh
;
7402 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7403 myh
->forced_local
= 1;
7405 /* Link veneer back to calling location. */
7406 sec_data
->erratumcount
+= 1;
7407 newerr
= (elf32_vfp11_erratum_list
*)
7408 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
7410 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
7412 newerr
->u
.v
.branch
= branch
;
7413 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
7414 branch
->u
.b
.veneer
= newerr
;
7416 newerr
->next
= sec_data
->erratumlist
;
7417 sec_data
->erratumlist
= newerr
;
7419 /* A symbol for the return from the veneer. */
7420 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
7421 hash_table
->num_vfp11_fixes
);
7423 myh
= elf_link_hash_lookup
7424 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
7431 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
7432 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
7434 myh
= (struct elf_link_hash_entry
*) bh
;
7435 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7436 myh
->forced_local
= 1;
7440 /* Generate a mapping symbol for the veneer section, and explicitly add an
7441 entry for that symbol to the code/data map for the section. */
7442 if (hash_table
->vfp11_erratum_glue_size
== 0)
7445 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
7446 ever requires this erratum fix. */
7447 _bfd_generic_link_add_one_symbol (link_info
,
7448 hash_table
->bfd_of_glue_owner
, "$a",
7449 BSF_LOCAL
, s
, 0, NULL
,
7452 myh
= (struct elf_link_hash_entry
*) bh
;
7453 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7454 myh
->forced_local
= 1;
7456 /* The elf32_arm_init_maps function only cares about symbols from input
7457 BFDs. We must make a note of this generated mapping symbol
7458 ourselves so that code byteswapping works properly in
7459 elf32_arm_write_section. */
7460 elf32_arm_section_map_add (s
, 'a', 0);
7463 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
7464 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
7465 hash_table
->num_vfp11_fixes
++;
7467 /* The offset of the veneer. */
7471 /* Record information about a STM32L4XX STM erratum veneer. Only THUMB-mode
7472 veneers need to be handled because used only in Cortex-M. */
7475 record_stm32l4xx_erratum_veneer (struct bfd_link_info
*link_info
,
7476 elf32_stm32l4xx_erratum_list
*branch
,
7478 asection
*branch_sec
,
7479 unsigned int offset
,
7480 bfd_size_type veneer_size
)
7483 struct elf32_arm_link_hash_table
*hash_table
;
7485 struct elf_link_hash_entry
*myh
;
7486 struct bfd_link_hash_entry
*bh
;
7488 struct _arm_elf_section_data
*sec_data
;
7489 elf32_stm32l4xx_erratum_list
*newerr
;
7491 hash_table
= elf32_arm_hash_table (link_info
);
7492 BFD_ASSERT (hash_table
!= NULL
);
7493 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
7495 s
= bfd_get_linker_section
7496 (hash_table
->bfd_of_glue_owner
, STM32L4XX_ERRATUM_VENEER_SECTION_NAME
);
7498 BFD_ASSERT (s
!= NULL
);
7500 sec_data
= elf32_arm_section_data (s
);
7502 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
7503 (STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
) + 10);
7505 BFD_ASSERT (tmp_name
);
7507 sprintf (tmp_name
, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
,
7508 hash_table
->num_stm32l4xx_fixes
);
7510 myh
= elf_link_hash_lookup
7511 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
7513 BFD_ASSERT (myh
== NULL
);
7516 val
= hash_table
->stm32l4xx_erratum_glue_size
;
7517 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
7518 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
7519 NULL
, TRUE
, FALSE
, &bh
);
7521 myh
= (struct elf_link_hash_entry
*) bh
;
7522 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7523 myh
->forced_local
= 1;
7525 /* Link veneer back to calling location. */
7526 sec_data
->stm32l4xx_erratumcount
+= 1;
7527 newerr
= (elf32_stm32l4xx_erratum_list
*)
7528 bfd_zmalloc (sizeof (elf32_stm32l4xx_erratum_list
));
7530 newerr
->type
= STM32L4XX_ERRATUM_VENEER
;
7532 newerr
->u
.v
.branch
= branch
;
7533 newerr
->u
.v
.id
= hash_table
->num_stm32l4xx_fixes
;
7534 branch
->u
.b
.veneer
= newerr
;
7536 newerr
->next
= sec_data
->stm32l4xx_erratumlist
;
7537 sec_data
->stm32l4xx_erratumlist
= newerr
;
7539 /* A symbol for the return from the veneer. */
7540 sprintf (tmp_name
, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
"_r",
7541 hash_table
->num_stm32l4xx_fixes
);
7543 myh
= elf_link_hash_lookup
7544 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
7551 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
7552 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
7554 myh
= (struct elf_link_hash_entry
*) bh
;
7555 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
7556 myh
->forced_local
= 1;
7560 /* Generate a mapping symbol for the veneer section, and explicitly add an
7561 entry for that symbol to the code/data map for the section. */
7562 if (hash_table
->stm32l4xx_erratum_glue_size
== 0)
7565 /* Creates a THUMB symbol since there is no other choice. */
7566 _bfd_generic_link_add_one_symbol (link_info
,
7567 hash_table
->bfd_of_glue_owner
, "$t",
7568 BSF_LOCAL
, s
, 0, NULL
,
7571 myh
= (struct elf_link_hash_entry
*) bh
;
7572 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
7573 myh
->forced_local
= 1;
7575 /* The elf32_arm_init_maps function only cares about symbols from input
7576 BFDs. We must make a note of this generated mapping symbol
7577 ourselves so that code byteswapping works properly in
7578 elf32_arm_write_section. */
7579 elf32_arm_section_map_add (s
, 't', 0);
7582 s
->size
+= veneer_size
;
7583 hash_table
->stm32l4xx_erratum_glue_size
+= veneer_size
;
7584 hash_table
->num_stm32l4xx_fixes
++;
7586 /* The offset of the veneer. */
7590 #define ARM_GLUE_SECTION_FLAGS \
7591 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
7592 | SEC_READONLY | SEC_LINKER_CREATED)
7594 /* Create a fake section for use by the ARM backend of the linker. */
7597 arm_make_glue_section (bfd
* abfd
, const char * name
)
7601 sec
= bfd_get_linker_section (abfd
, name
);
7606 sec
= bfd_make_section_anyway_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
7609 || !bfd_set_section_alignment (abfd
, sec
, 2))
7612 /* Set the gc mark to prevent the section from being removed by garbage
7613 collection, despite the fact that no relocs refer to this section. */
7619 /* Set size of .plt entries. This function is called from the
7620 linker scripts in ld/emultempl/{armelf}.em. */
7623 bfd_elf32_arm_use_long_plt (void)
7625 elf32_arm_use_long_plt_entry
= TRUE
;
7628 /* Add the glue sections to ABFD. This function is called from the
7629 linker scripts in ld/emultempl/{armelf}.em. */
7632 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
7633 struct bfd_link_info
*info
)
7635 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
7636 bfd_boolean dostm32l4xx
= globals
7637 && globals
->stm32l4xx_fix
!= BFD_ARM_STM32L4XX_FIX_NONE
;
7638 bfd_boolean addglue
;
7640 /* If we are only performing a partial
7641 link do not bother adding the glue. */
7642 if (bfd_link_relocatable (info
))
7645 addglue
= arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
7646 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
7647 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
7648 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
7654 && arm_make_glue_section (abfd
, STM32L4XX_ERRATUM_VENEER_SECTION_NAME
);
7657 /* Mark output sections of veneers needing a dedicated one with SEC_KEEP. This
7658 ensures they are not marked for deletion by
7659 strip_excluded_output_sections () when veneers are going to be created
7660 later. Not doing so would trigger assert on empty section size in
7661 lang_size_sections_1 (). */
7664 bfd_elf32_arm_keep_private_stub_output_sections (struct bfd_link_info
*info
)
7666 enum elf32_arm_stub_type stub_type
;
7668 /* If we are only performing a partial
7669 link do not bother adding the glue. */
7670 if (bfd_link_relocatable (info
))
7673 for (stub_type
= arm_stub_none
+ 1; stub_type
< max_stub_type
; stub_type
++)
7676 const char *out_sec_name
;
7678 if (!arm_dedicated_stub_output_section_required (stub_type
))
7681 out_sec_name
= arm_dedicated_stub_output_section_name (stub_type
);
7682 out_sec
= bfd_get_section_by_name (info
->output_bfd
, out_sec_name
);
7683 if (out_sec
!= NULL
)
7684 out_sec
->flags
|= SEC_KEEP
;
7688 /* Select a BFD to be used to hold the sections used by the glue code.
7689 This function is called from the linker scripts in ld/emultempl/
7693 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
7695 struct elf32_arm_link_hash_table
*globals
;
7697 /* If we are only performing a partial link
7698 do not bother getting a bfd to hold the glue. */
7699 if (bfd_link_relocatable (info
))
7702 /* Make sure we don't attach the glue sections to a dynamic object. */
7703 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
7705 globals
= elf32_arm_hash_table (info
);
7706 BFD_ASSERT (globals
!= NULL
);
7708 if (globals
->bfd_of_glue_owner
!= NULL
)
7711 /* Save the bfd for later use. */
7712 globals
->bfd_of_glue_owner
= abfd
;
7718 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
7722 cpu_arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
7725 if (globals
->fix_arm1176
)
7727 if (cpu_arch
== TAG_CPU_ARCH_V6T2
|| cpu_arch
> TAG_CPU_ARCH_V6K
)
7728 globals
->use_blx
= 1;
7732 if (cpu_arch
> TAG_CPU_ARCH_V4T
)
7733 globals
->use_blx
= 1;
7738 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
7739 struct bfd_link_info
*link_info
)
7741 Elf_Internal_Shdr
*symtab_hdr
;
7742 Elf_Internal_Rela
*internal_relocs
= NULL
;
7743 Elf_Internal_Rela
*irel
, *irelend
;
7744 bfd_byte
*contents
= NULL
;
7747 struct elf32_arm_link_hash_table
*globals
;
7749 /* If we are only performing a partial link do not bother
7750 to construct any glue. */
7751 if (bfd_link_relocatable (link_info
))
7754 /* Here we have a bfd that is to be included on the link. We have a
7755 hook to do reloc rummaging, before section sizes are nailed down. */
7756 globals
= elf32_arm_hash_table (link_info
);
7757 BFD_ASSERT (globals
!= NULL
);
7759 check_use_blx (globals
);
7761 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
7763 _bfd_error_handler (_("%pB: BE8 images only valid in big-endian mode"),
7768 /* PR 5398: If we have not decided to include any loadable sections in
7769 the output then we will not have a glue owner bfd. This is OK, it
7770 just means that there is nothing else for us to do here. */
7771 if (globals
->bfd_of_glue_owner
== NULL
)
7774 /* Rummage around all the relocs and map the glue vectors. */
7775 sec
= abfd
->sections
;
7780 for (; sec
!= NULL
; sec
= sec
->next
)
7782 if (sec
->reloc_count
== 0)
7785 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
7788 symtab_hdr
= & elf_symtab_hdr (abfd
);
7790 /* Load the relocs. */
7792 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
7794 if (internal_relocs
== NULL
)
7797 irelend
= internal_relocs
+ sec
->reloc_count
;
7798 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7801 unsigned long r_index
;
7803 struct elf_link_hash_entry
*h
;
7805 r_type
= ELF32_R_TYPE (irel
->r_info
);
7806 r_index
= ELF32_R_SYM (irel
->r_info
);
7808 /* These are the only relocation types we care about. */
7809 if ( r_type
!= R_ARM_PC24
7810 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
7813 /* Get the section contents if we haven't done so already. */
7814 if (contents
== NULL
)
7816 /* Get cached copy if it exists. */
7817 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7818 contents
= elf_section_data (sec
)->this_hdr
.contents
;
7821 /* Go get them off disk. */
7822 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
7827 if (r_type
== R_ARM_V4BX
)
7831 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
7832 record_arm_bx_glue (link_info
, reg
);
7836 /* If the relocation is not against a symbol it cannot concern us. */
7839 /* We don't care about local symbols. */
7840 if (r_index
< symtab_hdr
->sh_info
)
7843 /* This is an external symbol. */
7844 r_index
-= symtab_hdr
->sh_info
;
7845 h
= (struct elf_link_hash_entry
*)
7846 elf_sym_hashes (abfd
)[r_index
];
7848 /* If the relocation is against a static symbol it must be within
7849 the current section and so cannot be a cross ARM/Thumb relocation. */
7853 /* If the call will go through a PLT entry then we do not need
7855 if (globals
->root
.splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
7861 /* This one is a call from arm code. We need to look up
7862 the target of the call. If it is a thumb target, we
7864 if (ARM_GET_SYM_BRANCH_TYPE (h
->target_internal
)
7865 == ST_BRANCH_TO_THUMB
)
7866 record_arm_to_thumb_glue (link_info
, h
);
7874 if (contents
!= NULL
7875 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7879 if (internal_relocs
!= NULL
7880 && elf_section_data (sec
)->relocs
!= internal_relocs
)
7881 free (internal_relocs
);
7882 internal_relocs
= NULL
;
7888 if (contents
!= NULL
7889 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7891 if (internal_relocs
!= NULL
7892 && elf_section_data (sec
)->relocs
!= internal_relocs
)
7893 free (internal_relocs
);
7900 /* Initialise maps of ARM/Thumb/data for input BFDs. */
7903 bfd_elf32_arm_init_maps (bfd
*abfd
)
7905 Elf_Internal_Sym
*isymbuf
;
7906 Elf_Internal_Shdr
*hdr
;
7907 unsigned int i
, localsyms
;
7909 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
7910 if (! is_arm_elf (abfd
))
7913 if ((abfd
->flags
& DYNAMIC
) != 0)
7916 hdr
= & elf_symtab_hdr (abfd
);
7917 localsyms
= hdr
->sh_info
;
7919 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
7920 should contain the number of local symbols, which should come before any
7921 global symbols. Mapping symbols are always local. */
7922 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
7925 /* No internal symbols read? Skip this BFD. */
7926 if (isymbuf
== NULL
)
7929 for (i
= 0; i
< localsyms
; i
++)
7931 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
7932 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7936 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
7938 name
= bfd_elf_string_from_elf_section (abfd
,
7939 hdr
->sh_link
, isym
->st_name
);
7941 if (bfd_is_arm_special_symbol_name (name
,
7942 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
7943 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
7949 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
7950 say what they wanted. */
7953 bfd_elf32_arm_set_cortex_a8_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
7955 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
7956 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
7958 if (globals
== NULL
)
7961 if (globals
->fix_cortex_a8
== -1)
7963 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
7964 if (out_attr
[Tag_CPU_arch
].i
== TAG_CPU_ARCH_V7
7965 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
7966 || out_attr
[Tag_CPU_arch_profile
].i
== 0))
7967 globals
->fix_cortex_a8
= 1;
7969 globals
->fix_cortex_a8
= 0;
7975 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
7977 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
7978 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
7980 if (globals
== NULL
)
7982 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
7983 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
7985 switch (globals
->vfp11_fix
)
7987 case BFD_ARM_VFP11_FIX_DEFAULT
:
7988 case BFD_ARM_VFP11_FIX_NONE
:
7989 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
7993 /* Give a warning, but do as the user requests anyway. */
7994 _bfd_error_handler (_("%pB: warning: selected VFP11 erratum "
7995 "workaround is not necessary for target architecture"), obfd
);
7998 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
7999 /* For earlier architectures, we might need the workaround, but do not
8000 enable it by default. If users is running with broken hardware, they
8001 must enable the erratum fix explicitly. */
8002 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
8006 bfd_elf32_arm_set_stm32l4xx_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
8008 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
8009 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
8011 if (globals
== NULL
)
8014 /* We assume only Cortex-M4 may require the fix. */
8015 if (out_attr
[Tag_CPU_arch
].i
!= TAG_CPU_ARCH_V7E_M
8016 || out_attr
[Tag_CPU_arch_profile
].i
!= 'M')
8018 if (globals
->stm32l4xx_fix
!= BFD_ARM_STM32L4XX_FIX_NONE
)
8019 /* Give a warning, but do as the user requests anyway. */
8021 (_("%pB: warning: selected STM32L4XX erratum "
8022 "workaround is not necessary for target architecture"), obfd
);
8026 enum bfd_arm_vfp11_pipe
8034 /* Return a VFP register number. This is encoded as RX:X for single-precision
8035 registers, or X:RX for double-precision registers, where RX is the group of
8036 four bits in the instruction encoding and X is the single extension bit.
8037 RX and X fields are specified using their lowest (starting) bit. The return
8040 0...31: single-precision registers s0...s31
8041 32...63: double-precision registers d0...d31.
8043 Although X should be zero for VFP11 (encoding d0...d15 only), we might
8044 encounter VFP3 instructions, so we allow the full range for DP registers. */
8047 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
8051 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
8053 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
8056 /* Set bits in *WMASK according to a register number REG as encoded by
8057 bfd_arm_vfp11_regno(). Ignore d16-d31. */
8060 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
8065 *wmask
|= 3 << ((reg
- 32) * 2);
8068 /* Return TRUE if WMASK overwrites anything in REGS. */
8071 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
8075 for (i
= 0; i
< numregs
; i
++)
8077 unsigned int reg
= regs
[i
];
8079 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
8087 if ((wmask
& (3 << (reg
* 2))) != 0)
8094 /* In this function, we're interested in two things: finding input registers
8095 for VFP data-processing instructions, and finding the set of registers which
8096 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
8097 hold the written set, so FLDM etc. are easy to deal with (we're only
8098 interested in 32 SP registers or 16 dp registers, due to the VFP version
8099 implemented by the chip in question). DP registers are marked by setting
8100 both SP registers in the write mask). */
8102 static enum bfd_arm_vfp11_pipe
8103 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
8106 enum bfd_arm_vfp11_pipe vpipe
= VFP11_BAD
;
8107 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
8109 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
8112 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
8113 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
8115 pqrs
= ((insn
& 0x00800000) >> 20)
8116 | ((insn
& 0x00300000) >> 19)
8117 | ((insn
& 0x00000040) >> 6);
8121 case 0: /* fmac[sd]. */
8122 case 1: /* fnmac[sd]. */
8123 case 2: /* fmsc[sd]. */
8124 case 3: /* fnmsc[sd]. */
8126 bfd_arm_vfp11_write_mask (destmask
, fd
);
8128 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
8133 case 4: /* fmul[sd]. */
8134 case 5: /* fnmul[sd]. */
8135 case 6: /* fadd[sd]. */
8136 case 7: /* fsub[sd]. */
8140 case 8: /* fdiv[sd]. */
8143 bfd_arm_vfp11_write_mask (destmask
, fd
);
8144 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
8149 case 15: /* extended opcode. */
8151 unsigned int extn
= ((insn
>> 15) & 0x1e)
8152 | ((insn
>> 7) & 1);
8156 case 0: /* fcpy[sd]. */
8157 case 1: /* fabs[sd]. */
8158 case 2: /* fneg[sd]. */
8159 case 8: /* fcmp[sd]. */
8160 case 9: /* fcmpe[sd]. */
8161 case 10: /* fcmpz[sd]. */
8162 case 11: /* fcmpez[sd]. */
8163 case 16: /* fuito[sd]. */
8164 case 17: /* fsito[sd]. */
8165 case 24: /* ftoui[sd]. */
8166 case 25: /* ftouiz[sd]. */
8167 case 26: /* ftosi[sd]. */
8168 case 27: /* ftosiz[sd]. */
8169 /* These instructions will not bounce due to underflow. */
8174 case 3: /* fsqrt[sd]. */
8175 /* fsqrt cannot underflow, but it can (perhaps) overwrite
8176 registers to cause the erratum in previous instructions. */
8177 bfd_arm_vfp11_write_mask (destmask
, fd
);
8181 case 15: /* fcvt{ds,sd}. */
8185 bfd_arm_vfp11_write_mask (destmask
, fd
);
8187 /* Only FCVTSD can underflow. */
8188 if ((insn
& 0x100) != 0)
8207 /* Two-register transfer. */
8208 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
8210 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
8212 if ((insn
& 0x100000) == 0)
8215 bfd_arm_vfp11_write_mask (destmask
, fm
);
8218 bfd_arm_vfp11_write_mask (destmask
, fm
);
8219 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
8225 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
8227 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
8228 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
8232 case 0: /* Two-reg transfer. We should catch these above. */
8235 case 2: /* fldm[sdx]. */
8239 unsigned int i
, offset
= insn
& 0xff;
8244 for (i
= fd
; i
< fd
+ offset
; i
++)
8245 bfd_arm_vfp11_write_mask (destmask
, i
);
8249 case 4: /* fld[sd]. */
8251 bfd_arm_vfp11_write_mask (destmask
, fd
);
8260 /* Single-register transfer. Note L==0. */
8261 else if ((insn
& 0x0f100e10) == 0x0e000a10)
8263 unsigned int opcode
= (insn
>> 21) & 7;
8264 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
8268 case 0: /* fmsr/fmdlr. */
8269 case 1: /* fmdhr. */
8270 /* Mark fmdhr and fmdlr as writing to the whole of the DP
8271 destination register. I don't know if this is exactly right,
8272 but it is the conservative choice. */
8273 bfd_arm_vfp11_write_mask (destmask
, fn
);
8287 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
8290 /* Look for potentially-troublesome code sequences which might trigger the
8291 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
8292 (available from ARM) for details of the erratum. A short version is
8293 described in ld.texinfo. */
8296 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
8299 bfd_byte
*contents
= NULL
;
8301 int regs
[3], numregs
= 0;
8302 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
8303 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
8305 if (globals
== NULL
)
8308 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
8309 The states transition as follows:
8311 0 -> 1 (vector) or 0 -> 2 (scalar)
8312 A VFP FMAC-pipeline instruction has been seen. Fill
8313 regs[0]..regs[numregs-1] with its input operands. Remember this
8314 instruction in 'first_fmac'.
8317 Any instruction, except for a VFP instruction which overwrites
8322 A VFP instruction has been seen which overwrites any of regs[*].
8323 We must make a veneer! Reset state to 0 before examining next
8327 If we fail to match anything in state 2, reset to state 0 and reset
8328 the instruction pointer to the instruction after 'first_fmac'.
8330 If the VFP11 vector mode is in use, there must be at least two unrelated
8331 instructions between anti-dependent VFP11 instructions to properly avoid
8332 triggering the erratum, hence the use of the extra state 1. */
8334 /* If we are only performing a partial link do not bother
8335 to construct any glue. */
8336 if (bfd_link_relocatable (link_info
))
8339 /* Skip if this bfd does not correspond to an ELF image. */
8340 if (! is_arm_elf (abfd
))
8343 /* We should have chosen a fix type by the time we get here. */
8344 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
8346 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
8349 /* Skip this BFD if it corresponds to an executable or dynamic object. */
8350 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
8353 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8355 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
8356 struct _arm_elf_section_data
*sec_data
;
8358 /* If we don't have executable progbits, we're not interested in this
8359 section. Also skip if section is to be excluded. */
8360 if (elf_section_type (sec
) != SHT_PROGBITS
8361 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
8362 || (sec
->flags
& SEC_EXCLUDE
) != 0
8363 || sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8364 || sec
->output_section
== bfd_abs_section_ptr
8365 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
8368 sec_data
= elf32_arm_section_data (sec
);
8370 if (sec_data
->mapcount
== 0)
8373 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8374 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8375 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
8378 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
8379 elf32_arm_compare_mapping
);
8381 for (span
= 0; span
< sec_data
->mapcount
; span
++)
8383 unsigned int span_start
= sec_data
->map
[span
].vma
;
8384 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
8385 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
8386 char span_type
= sec_data
->map
[span
].type
;
8388 /* FIXME: Only ARM mode is supported at present. We may need to
8389 support Thumb-2 mode also at some point. */
8390 if (span_type
!= 'a')
8393 for (i
= span_start
; i
< span_end
;)
8395 unsigned int next_i
= i
+ 4;
8396 unsigned int insn
= bfd_big_endian (abfd
)
8397 ? (contents
[i
] << 24)
8398 | (contents
[i
+ 1] << 16)
8399 | (contents
[i
+ 2] << 8)
8401 : (contents
[i
+ 3] << 24)
8402 | (contents
[i
+ 2] << 16)
8403 | (contents
[i
+ 1] << 8)
8405 unsigned int writemask
= 0;
8406 enum bfd_arm_vfp11_pipe vpipe
;
8411 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
8413 /* I'm assuming the VFP11 erratum can trigger with denorm
8414 operands on either the FMAC or the DS pipeline. This might
8415 lead to slightly overenthusiastic veneer insertion. */
8416 if (vpipe
== VFP11_FMAC
|| vpipe
== VFP11_DS
)
8418 state
= use_vector
? 1 : 2;
8420 veneer_of_insn
= insn
;
8426 int other_regs
[3], other_numregs
;
8427 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
8430 if (vpipe
!= VFP11_BAD
8431 && bfd_arm_vfp11_antidependency (writemask
, regs
,
8441 int other_regs
[3], other_numregs
;
8442 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
8445 if (vpipe
!= VFP11_BAD
8446 && bfd_arm_vfp11_antidependency (writemask
, regs
,
8452 next_i
= first_fmac
+ 4;
8458 abort (); /* Should be unreachable. */
8463 elf32_vfp11_erratum_list
*newerr
=(elf32_vfp11_erratum_list
*)
8464 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
8466 elf32_arm_section_data (sec
)->erratumcount
+= 1;
8468 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
8473 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
8480 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
8485 newerr
->next
= sec_data
->erratumlist
;
8486 sec_data
->erratumlist
= newerr
;
8495 if (contents
!= NULL
8496 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8504 if (contents
!= NULL
8505 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8511 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
8512 after sections have been laid out, using specially-named symbols. */
8515 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
8516 struct bfd_link_info
*link_info
)
8519 struct elf32_arm_link_hash_table
*globals
;
8522 if (bfd_link_relocatable (link_info
))
8525 /* Skip if this bfd does not correspond to an ELF image. */
8526 if (! is_arm_elf (abfd
))
8529 globals
= elf32_arm_hash_table (link_info
);
8530 if (globals
== NULL
)
8533 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
8534 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
8536 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8538 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
8539 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
8541 for (; errnode
!= NULL
; errnode
= errnode
->next
)
8543 struct elf_link_hash_entry
*myh
;
8546 switch (errnode
->type
)
8548 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
8549 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
8550 /* Find veneer symbol. */
8551 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
8552 errnode
->u
.b
.veneer
->u
.v
.id
);
8554 myh
= elf_link_hash_lookup
8555 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
8558 _bfd_error_handler (_("%pB: unable to find %s veneer `%s'"),
8559 abfd
, "VFP11", tmp_name
);
8561 vma
= myh
->root
.u
.def
.section
->output_section
->vma
8562 + myh
->root
.u
.def
.section
->output_offset
8563 + myh
->root
.u
.def
.value
;
8565 errnode
->u
.b
.veneer
->vma
= vma
;
8568 case VFP11_ERRATUM_ARM_VENEER
:
8569 case VFP11_ERRATUM_THUMB_VENEER
:
8570 /* Find return location. */
8571 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
8574 myh
= elf_link_hash_lookup
8575 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
8578 _bfd_error_handler (_("%pB: unable to find %s veneer `%s'"),
8579 abfd
, "VFP11", tmp_name
);
8581 vma
= myh
->root
.u
.def
.section
->output_section
->vma
8582 + myh
->root
.u
.def
.section
->output_offset
8583 + myh
->root
.u
.def
.value
;
8585 errnode
->u
.v
.branch
->vma
= vma
;
8597 /* Find virtual-memory addresses for STM32L4XX erratum veneers and
8598 return locations after sections have been laid out, using
8599 specially-named symbols. */
8602 bfd_elf32_arm_stm32l4xx_fix_veneer_locations (bfd
*abfd
,
8603 struct bfd_link_info
*link_info
)
8606 struct elf32_arm_link_hash_table
*globals
;
8609 if (bfd_link_relocatable (link_info
))
8612 /* Skip if this bfd does not correspond to an ELF image. */
8613 if (! is_arm_elf (abfd
))
8616 globals
= elf32_arm_hash_table (link_info
);
8617 if (globals
== NULL
)
8620 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
8621 (STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
) + 10);
8623 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8625 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
8626 elf32_stm32l4xx_erratum_list
*errnode
= sec_data
->stm32l4xx_erratumlist
;
8628 for (; errnode
!= NULL
; errnode
= errnode
->next
)
8630 struct elf_link_hash_entry
*myh
;
8633 switch (errnode
->type
)
8635 case STM32L4XX_ERRATUM_BRANCH_TO_VENEER
:
8636 /* Find veneer symbol. */
8637 sprintf (tmp_name
, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
,
8638 errnode
->u
.b
.veneer
->u
.v
.id
);
8640 myh
= elf_link_hash_lookup
8641 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
8644 _bfd_error_handler (_("%pB: unable to find %s veneer `%s'"),
8645 abfd
, "STM32L4XX", tmp_name
);
8647 vma
= myh
->root
.u
.def
.section
->output_section
->vma
8648 + myh
->root
.u
.def
.section
->output_offset
8649 + myh
->root
.u
.def
.value
;
8651 errnode
->u
.b
.veneer
->vma
= vma
;
8654 case STM32L4XX_ERRATUM_VENEER
:
8655 /* Find return location. */
8656 sprintf (tmp_name
, STM32L4XX_ERRATUM_VENEER_ENTRY_NAME
"_r",
8659 myh
= elf_link_hash_lookup
8660 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
8663 _bfd_error_handler (_("%pB: unable to find %s veneer `%s'"),
8664 abfd
, "STM32L4XX", tmp_name
);
8666 vma
= myh
->root
.u
.def
.section
->output_section
->vma
8667 + myh
->root
.u
.def
.section
->output_offset
8668 + myh
->root
.u
.def
.value
;
8670 errnode
->u
.v
.branch
->vma
= vma
;
8682 static inline bfd_boolean
8683 is_thumb2_ldmia (const insn32 insn
)
8685 /* Encoding T2: LDM<c>.W <Rn>{!},<registers>
8686 1110 - 1000 - 10W1 - rrrr - PM (0) l - llll - llll - llll. */
8687 return (insn
& 0xffd02000) == 0xe8900000;
8690 static inline bfd_boolean
8691 is_thumb2_ldmdb (const insn32 insn
)
8693 /* Encoding T1: LDMDB<c> <Rn>{!},<registers>
8694 1110 - 1001 - 00W1 - rrrr - PM (0) l - llll - llll - llll. */
8695 return (insn
& 0xffd02000) == 0xe9100000;
8698 static inline bfd_boolean
8699 is_thumb2_vldm (const insn32 insn
)
8701 /* A6.5 Extension register load or store instruction
8703 We look for SP 32-bit and DP 64-bit registers.
8704 Encoding T1 VLDM{mode}<c> <Rn>{!}, <list>
8705 <list> is consecutive 64-bit registers
8706 1110 - 110P - UDW1 - rrrr - vvvv - 1011 - iiii - iiii
8707 Encoding T2 VLDM{mode}<c> <Rn>{!}, <list>
8708 <list> is consecutive 32-bit registers
8709 1110 - 110P - UDW1 - rrrr - vvvv - 1010 - iiii - iiii
8710 if P==0 && U==1 && W==1 && Rn=1101 VPOP
8711 if PUW=010 || PUW=011 || PUW=101 VLDM. */
8713 (((insn
& 0xfe100f00) == 0xec100b00) ||
8714 ((insn
& 0xfe100f00) == 0xec100a00))
8715 && /* (IA without !). */
8716 (((((insn
<< 7) >> 28) & 0xd) == 0x4)
8717 /* (IA with !), includes VPOP (when reg number is SP). */
8718 || ((((insn
<< 7) >> 28) & 0xd) == 0x5)
8720 || ((((insn
<< 7) >> 28) & 0xd) == 0x9));
8723 /* STM STM32L4XX erratum : This function assumes that it receives an LDM or
8725 - computes the number and the mode of memory accesses
8726 - decides if the replacement should be done:
8727 . replaces only if > 8-word accesses
8728 . or (testing purposes only) replaces all accesses. */
8731 stm32l4xx_need_create_replacing_stub (const insn32 insn
,
8732 bfd_arm_stm32l4xx_fix stm32l4xx_fix
)
8736 /* The field encoding the register list is the same for both LDMIA
8737 and LDMDB encodings. */
8738 if (is_thumb2_ldmia (insn
) || is_thumb2_ldmdb (insn
))
8739 nb_words
= elf32_arm_popcount (insn
& 0x0000ffff);
8740 else if (is_thumb2_vldm (insn
))
8741 nb_words
= (insn
& 0xff);
8743 /* DEFAULT mode accounts for the real bug condition situation,
8744 ALL mode inserts stubs for each LDM/VLDM instruction (testing). */
8746 (stm32l4xx_fix
== BFD_ARM_STM32L4XX_FIX_DEFAULT
) ? nb_words
> 8 :
8747 (stm32l4xx_fix
== BFD_ARM_STM32L4XX_FIX_ALL
) ? TRUE
: FALSE
;
8750 /* Look for potentially-troublesome code sequences which might trigger
8751 the STM STM32L4XX erratum. */
8754 bfd_elf32_arm_stm32l4xx_erratum_scan (bfd
*abfd
,
8755 struct bfd_link_info
*link_info
)
8758 bfd_byte
*contents
= NULL
;
8759 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
8761 if (globals
== NULL
)
8764 /* If we are only performing a partial link do not bother
8765 to construct any glue. */
8766 if (bfd_link_relocatable (link_info
))
8769 /* Skip if this bfd does not correspond to an ELF image. */
8770 if (! is_arm_elf (abfd
))
8773 if (globals
->stm32l4xx_fix
== BFD_ARM_STM32L4XX_FIX_NONE
)
8776 /* Skip this BFD if it corresponds to an executable or dynamic object. */
8777 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
8780 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8782 unsigned int i
, span
;
8783 struct _arm_elf_section_data
*sec_data
;
8785 /* If we don't have executable progbits, we're not interested in this
8786 section. Also skip if section is to be excluded. */
8787 if (elf_section_type (sec
) != SHT_PROGBITS
8788 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
8789 || (sec
->flags
& SEC_EXCLUDE
) != 0
8790 || sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8791 || sec
->output_section
== bfd_abs_section_ptr
8792 || strcmp (sec
->name
, STM32L4XX_ERRATUM_VENEER_SECTION_NAME
) == 0)
8795 sec_data
= elf32_arm_section_data (sec
);
8797 if (sec_data
->mapcount
== 0)
8800 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
8801 contents
= elf_section_data (sec
)->this_hdr
.contents
;
8802 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
8805 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
8806 elf32_arm_compare_mapping
);
8808 for (span
= 0; span
< sec_data
->mapcount
; span
++)
8810 unsigned int span_start
= sec_data
->map
[span
].vma
;
8811 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
8812 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
8813 char span_type
= sec_data
->map
[span
].type
;
8814 int itblock_current_pos
= 0;
8816 /* Only Thumb2 mode need be supported with this CM4 specific
8817 code, we should not encounter any arm mode eg span_type
8819 if (span_type
!= 't')
8822 for (i
= span_start
; i
< span_end
;)
8824 unsigned int insn
= bfd_get_16 (abfd
, &contents
[i
]);
8825 bfd_boolean insn_32bit
= FALSE
;
8826 bfd_boolean is_ldm
= FALSE
;
8827 bfd_boolean is_vldm
= FALSE
;
8828 bfd_boolean is_not_last_in_it_block
= FALSE
;
8830 /* The first 16-bits of all 32-bit thumb2 instructions start
8831 with opcode[15..13]=0b111 and the encoded op1 can be anything
8832 except opcode[12..11]!=0b00.
8833 See 32-bit Thumb instruction encoding. */
8834 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
8837 /* Compute the predicate that tells if the instruction
8838 is concerned by the IT block
8839 - Creates an error if there is a ldm that is not
8840 last in the IT block thus cannot be replaced
8841 - Otherwise we can create a branch at the end of the
8842 IT block, it will be controlled naturally by IT
8843 with the proper pseudo-predicate
8844 - So the only interesting predicate is the one that
8845 tells that we are not on the last item of an IT
8847 if (itblock_current_pos
!= 0)
8848 is_not_last_in_it_block
= !!--itblock_current_pos
;
8852 /* Load the rest of the insn (in manual-friendly order). */
8853 insn
= (insn
<< 16) | bfd_get_16 (abfd
, &contents
[i
+ 2]);
8854 is_ldm
= is_thumb2_ldmia (insn
) || is_thumb2_ldmdb (insn
);
8855 is_vldm
= is_thumb2_vldm (insn
);
8857 /* Veneers are created for (v)ldm depending on
8858 option flags and memory accesses conditions; but
8859 if the instruction is not the last instruction of
8860 an IT block, we cannot create a jump there, so we
8862 if ((is_ldm
|| is_vldm
)
8863 && stm32l4xx_need_create_replacing_stub
8864 (insn
, globals
->stm32l4xx_fix
))
8866 if (is_not_last_in_it_block
)
8869 /* xgettext:c-format */
8870 (_("%pB(%pA+%#x): error: multiple load detected"
8871 " in non-last IT block instruction:"
8872 " STM32L4XX veneer cannot be generated; "
8873 "use gcc option -mrestrict-it to generate"
8874 " only one instruction per IT block"),
8879 elf32_stm32l4xx_erratum_list
*newerr
=
8880 (elf32_stm32l4xx_erratum_list
*)
8882 (sizeof (elf32_stm32l4xx_erratum_list
));
8884 elf32_arm_section_data (sec
)
8885 ->stm32l4xx_erratumcount
+= 1;
8886 newerr
->u
.b
.insn
= insn
;
8887 /* We create only thumb branches. */
8889 STM32L4XX_ERRATUM_BRANCH_TO_VENEER
;
8890 record_stm32l4xx_erratum_veneer
8891 (link_info
, newerr
, abfd
, sec
,
8894 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
:
8895 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE
);
8897 newerr
->next
= sec_data
->stm32l4xx_erratumlist
;
8898 sec_data
->stm32l4xx_erratumlist
= newerr
;
8905 IT blocks are only encoded in T1
8906 Encoding T1: IT{x{y{z}}} <firstcond>
8907 1 0 1 1 - 1 1 1 1 - firstcond - mask
8908 if mask = '0000' then see 'related encodings'
8909 We don't deal with UNPREDICTABLE, just ignore these.
8910 There can be no nested IT blocks so an IT block
8911 is naturally a new one for which it is worth
8912 computing its size. */
8913 bfd_boolean is_newitblock
= ((insn
& 0xff00) == 0xbf00)
8914 && ((insn
& 0x000f) != 0x0000);
8915 /* If we have a new IT block we compute its size. */
8918 /* Compute the number of instructions controlled
8919 by the IT block, it will be used to decide
8920 whether we are inside an IT block or not. */
8921 unsigned int mask
= insn
& 0x000f;
8922 itblock_current_pos
= 4 - ctz (mask
);
8926 i
+= insn_32bit
? 4 : 2;
8930 if (contents
!= NULL
8931 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8939 if (contents
!= NULL
8940 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8946 /* Set target relocation values needed during linking. */
8949 bfd_elf32_arm_set_target_params (struct bfd
*output_bfd
,
8950 struct bfd_link_info
*link_info
,
8951 struct elf32_arm_params
*params
)
8953 struct elf32_arm_link_hash_table
*globals
;
8955 globals
= elf32_arm_hash_table (link_info
);
8956 if (globals
== NULL
)
8959 globals
->target1_is_rel
= params
->target1_is_rel
;
8960 if (strcmp (params
->target2_type
, "rel") == 0)
8961 globals
->target2_reloc
= R_ARM_REL32
;
8962 else if (strcmp (params
->target2_type
, "abs") == 0)
8963 globals
->target2_reloc
= R_ARM_ABS32
;
8964 else if (strcmp (params
->target2_type
, "got-rel") == 0)
8965 globals
->target2_reloc
= R_ARM_GOT_PREL
;
8968 _bfd_error_handler (_("invalid TARGET2 relocation type '%s'"),
8969 params
->target2_type
);
8971 globals
->fix_v4bx
= params
->fix_v4bx
;
8972 globals
->use_blx
|= params
->use_blx
;
8973 globals
->vfp11_fix
= params
->vfp11_denorm_fix
;
8974 globals
->stm32l4xx_fix
= params
->stm32l4xx_fix
;
8975 if (globals
->fdpic_p
)
8976 globals
->pic_veneer
= 1;
8978 globals
->pic_veneer
= params
->pic_veneer
;
8979 globals
->fix_cortex_a8
= params
->fix_cortex_a8
;
8980 globals
->fix_arm1176
= params
->fix_arm1176
;
8981 globals
->cmse_implib
= params
->cmse_implib
;
8982 globals
->in_implib_bfd
= params
->in_implib_bfd
;
8984 BFD_ASSERT (is_arm_elf (output_bfd
));
8985 elf_arm_tdata (output_bfd
)->no_enum_size_warning
8986 = params
->no_enum_size_warning
;
8987 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
8988 = params
->no_wchar_size_warning
;
8991 /* Replace the target offset of a Thumb bl or b.w instruction. */
8994 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
9000 BFD_ASSERT ((offset
& 1) == 0);
9002 upper
= bfd_get_16 (abfd
, insn
);
9003 lower
= bfd_get_16 (abfd
, insn
+ 2);
9004 reloc_sign
= (offset
< 0) ? 1 : 0;
9005 upper
= (upper
& ~(bfd_vma
) 0x7ff)
9006 | ((offset
>> 12) & 0x3ff)
9007 | (reloc_sign
<< 10);
9008 lower
= (lower
& ~(bfd_vma
) 0x2fff)
9009 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
9010 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
9011 | ((offset
>> 1) & 0x7ff);
9012 bfd_put_16 (abfd
, upper
, insn
);
9013 bfd_put_16 (abfd
, lower
, insn
+ 2);
9016 /* Thumb code calling an ARM function. */
9019 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
9023 asection
* input_section
,
9024 bfd_byte
* hit_data
,
9027 bfd_signed_vma addend
,
9029 char **error_message
)
9033 long int ret_offset
;
9034 struct elf_link_hash_entry
* myh
;
9035 struct elf32_arm_link_hash_table
* globals
;
9037 myh
= find_thumb_glue (info
, name
, error_message
);
9041 globals
= elf32_arm_hash_table (info
);
9042 BFD_ASSERT (globals
!= NULL
);
9043 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
9045 my_offset
= myh
->root
.u
.def
.value
;
9047 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
9048 THUMB2ARM_GLUE_SECTION_NAME
);
9050 BFD_ASSERT (s
!= NULL
);
9051 BFD_ASSERT (s
->contents
!= NULL
);
9052 BFD_ASSERT (s
->output_section
!= NULL
);
9054 if ((my_offset
& 0x01) == 0x01)
9057 && sym_sec
->owner
!= NULL
9058 && !INTERWORK_FLAG (sym_sec
->owner
))
9061 (_("%pB(%s): warning: interworking not enabled;"
9062 " first occurrence: %pB: %s call to %s"),
9063 sym_sec
->owner
, name
, input_bfd
, "Thumb", "ARM");
9069 myh
->root
.u
.def
.value
= my_offset
;
9071 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
9072 s
->contents
+ my_offset
);
9074 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
9075 s
->contents
+ my_offset
+ 2);
9078 /* Address of destination of the stub. */
9079 ((bfd_signed_vma
) val
)
9081 /* Offset from the start of the current section
9082 to the start of the stubs. */
9084 /* Offset of the start of this stub from the start of the stubs. */
9086 /* Address of the start of the current section. */
9087 + s
->output_section
->vma
)
9088 /* The branch instruction is 4 bytes into the stub. */
9090 /* ARM branches work from the pc of the instruction + 8. */
9093 put_arm_insn (globals
, output_bfd
,
9094 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
9095 s
->contents
+ my_offset
+ 4);
9098 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
9100 /* Now go back and fix up the original BL insn to point to here. */
9102 /* Address of where the stub is located. */
9103 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
9104 /* Address of where the BL is located. */
9105 - (input_section
->output_section
->vma
+ input_section
->output_offset
9107 /* Addend in the relocation. */
9109 /* Biassing for PC-relative addressing. */
9112 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
9117 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
9119 static struct elf_link_hash_entry
*
9120 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
9127 char ** error_message
)
9130 long int ret_offset
;
9131 struct elf_link_hash_entry
* myh
;
9132 struct elf32_arm_link_hash_table
* globals
;
9134 myh
= find_arm_glue (info
, name
, error_message
);
9138 globals
= elf32_arm_hash_table (info
);
9139 BFD_ASSERT (globals
!= NULL
);
9140 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
9142 my_offset
= myh
->root
.u
.def
.value
;
9144 if ((my_offset
& 0x01) == 0x01)
9147 && sym_sec
->owner
!= NULL
9148 && !INTERWORK_FLAG (sym_sec
->owner
))
9151 (_("%pB(%s): warning: interworking not enabled;"
9152 " first occurrence: %pB: %s call to %s"),
9153 sym_sec
->owner
, name
, input_bfd
, "ARM", "Thumb");
9157 myh
->root
.u
.def
.value
= my_offset
;
9159 if (bfd_link_pic (info
)
9160 || globals
->root
.is_relocatable_executable
9161 || globals
->pic_veneer
)
9163 /* For relocatable objects we can't use absolute addresses,
9164 so construct the address from a relative offset. */
9165 /* TODO: If the offset is small it's probably worth
9166 constructing the address with adds. */
9167 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
9168 s
->contents
+ my_offset
);
9169 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
9170 s
->contents
+ my_offset
+ 4);
9171 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
9172 s
->contents
+ my_offset
+ 8);
9173 /* Adjust the offset by 4 for the position of the add,
9174 and 8 for the pipeline offset. */
9175 ret_offset
= (val
- (s
->output_offset
9176 + s
->output_section
->vma
9179 bfd_put_32 (output_bfd
, ret_offset
,
9180 s
->contents
+ my_offset
+ 12);
9182 else if (globals
->use_blx
)
9184 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
9185 s
->contents
+ my_offset
);
9187 /* It's a thumb address. Add the low order bit. */
9188 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
9189 s
->contents
+ my_offset
+ 4);
9193 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
9194 s
->contents
+ my_offset
);
9196 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
9197 s
->contents
+ my_offset
+ 4);
9199 /* It's a thumb address. Add the low order bit. */
9200 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
9201 s
->contents
+ my_offset
+ 8);
9207 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
9212 /* Arm code calling a Thumb function. */
9215 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
9219 asection
* input_section
,
9220 bfd_byte
* hit_data
,
9223 bfd_signed_vma addend
,
9225 char **error_message
)
9227 unsigned long int tmp
;
9230 long int ret_offset
;
9231 struct elf_link_hash_entry
* myh
;
9232 struct elf32_arm_link_hash_table
* globals
;
9234 globals
= elf32_arm_hash_table (info
);
9235 BFD_ASSERT (globals
!= NULL
);
9236 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
9238 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
9239 ARM2THUMB_GLUE_SECTION_NAME
);
9240 BFD_ASSERT (s
!= NULL
);
9241 BFD_ASSERT (s
->contents
!= NULL
);
9242 BFD_ASSERT (s
->output_section
!= NULL
);
9244 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
9245 sym_sec
, val
, s
, error_message
);
9249 my_offset
= myh
->root
.u
.def
.value
;
9250 tmp
= bfd_get_32 (input_bfd
, hit_data
);
9251 tmp
= tmp
& 0xFF000000;
9253 /* Somehow these are both 4 too far, so subtract 8. */
9254 ret_offset
= (s
->output_offset
9256 + s
->output_section
->vma
9257 - (input_section
->output_offset
9258 + input_section
->output_section
->vma
9262 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
9264 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
9269 /* Populate Arm stub for an exported Thumb function. */
9272 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
9274 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
9276 struct elf_link_hash_entry
* myh
;
9277 struct elf32_arm_link_hash_entry
*eh
;
9278 struct elf32_arm_link_hash_table
* globals
;
9281 char *error_message
;
9283 eh
= elf32_arm_hash_entry (h
);
9284 /* Allocate stubs for exported Thumb functions on v4t. */
9285 if (eh
->export_glue
== NULL
)
9288 globals
= elf32_arm_hash_table (info
);
9289 BFD_ASSERT (globals
!= NULL
);
9290 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
9292 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
9293 ARM2THUMB_GLUE_SECTION_NAME
);
9294 BFD_ASSERT (s
!= NULL
);
9295 BFD_ASSERT (s
->contents
!= NULL
);
9296 BFD_ASSERT (s
->output_section
!= NULL
);
9298 sec
= eh
->export_glue
->root
.u
.def
.section
;
9300 BFD_ASSERT (sec
->output_section
!= NULL
);
9302 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
9303 + sec
->output_section
->vma
;
9305 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
9306 h
->root
.u
.def
.section
->owner
,
9307 globals
->obfd
, sec
, val
, s
,
9313 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
9316 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
9321 struct elf32_arm_link_hash_table
*globals
;
9323 globals
= elf32_arm_hash_table (info
);
9324 BFD_ASSERT (globals
!= NULL
);
9325 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
9327 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
9328 ARM_BX_GLUE_SECTION_NAME
);
9329 BFD_ASSERT (s
!= NULL
);
9330 BFD_ASSERT (s
->contents
!= NULL
);
9331 BFD_ASSERT (s
->output_section
!= NULL
);
9333 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
9335 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
9337 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
9339 p
= s
->contents
+ glue_addr
;
9340 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
9341 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
9342 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
9343 globals
->bx_glue_offset
[reg
] |= 1;
9346 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
9349 /* Generate Arm stubs for exported Thumb symbols. */
9351 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
9352 struct bfd_link_info
*link_info
)
9354 struct elf32_arm_link_hash_table
* globals
;
9356 if (link_info
== NULL
)
9357 /* Ignore this if we are not called by the ELF backend linker. */
9360 globals
= elf32_arm_hash_table (link_info
);
9361 if (globals
== NULL
)
9364 /* If blx is available then exported Thumb symbols are OK and there is
9366 if (globals
->use_blx
)
9369 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
9373 /* Reserve space for COUNT dynamic relocations in relocation selection
9377 elf32_arm_allocate_dynrelocs (struct bfd_link_info
*info
, asection
*sreloc
,
9378 bfd_size_type count
)
9380 struct elf32_arm_link_hash_table
*htab
;
9382 htab
= elf32_arm_hash_table (info
);
9383 BFD_ASSERT (htab
->root
.dynamic_sections_created
);
9386 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
9389 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
9390 dynamic, the relocations should go in SRELOC, otherwise they should
9391 go in the special .rel.iplt section. */
9394 elf32_arm_allocate_irelocs (struct bfd_link_info
*info
, asection
*sreloc
,
9395 bfd_size_type count
)
9397 struct elf32_arm_link_hash_table
*htab
;
9399 htab
= elf32_arm_hash_table (info
);
9400 if (!htab
->root
.dynamic_sections_created
)
9401 htab
->root
.irelplt
->size
+= RELOC_SIZE (htab
) * count
;
9404 BFD_ASSERT (sreloc
!= NULL
);
9405 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
9409 /* Add relocation REL to the end of relocation section SRELOC. */
9412 elf32_arm_add_dynreloc (bfd
*output_bfd
, struct bfd_link_info
*info
,
9413 asection
*sreloc
, Elf_Internal_Rela
*rel
)
9416 struct elf32_arm_link_hash_table
*htab
;
9418 htab
= elf32_arm_hash_table (info
);
9419 if (!htab
->root
.dynamic_sections_created
9420 && ELF32_R_TYPE (rel
->r_info
) == R_ARM_IRELATIVE
)
9421 sreloc
= htab
->root
.irelplt
;
9424 loc
= sreloc
->contents
;
9425 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (htab
);
9426 if (sreloc
->reloc_count
* RELOC_SIZE (htab
) > sreloc
->size
)
9428 SWAP_RELOC_OUT (htab
) (output_bfd
, rel
, loc
);
9431 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
9432 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
9436 elf32_arm_allocate_plt_entry (struct bfd_link_info
*info
,
9437 bfd_boolean is_iplt_entry
,
9438 union gotplt_union
*root_plt
,
9439 struct arm_plt_info
*arm_plt
)
9441 struct elf32_arm_link_hash_table
*htab
;
9445 htab
= elf32_arm_hash_table (info
);
9449 splt
= htab
->root
.iplt
;
9450 sgotplt
= htab
->root
.igotplt
;
9452 /* NaCl uses a special first entry in .iplt too. */
9453 if (htab
->nacl_p
&& splt
->size
== 0)
9454 splt
->size
+= htab
->plt_header_size
;
9456 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
9457 elf32_arm_allocate_irelocs (info
, htab
->root
.irelplt
, 1);
9461 splt
= htab
->root
.splt
;
9462 sgotplt
= htab
->root
.sgotplt
;
9466 /* Allocate room for R_ARM_FUNCDESC_VALUE. */
9467 /* For lazy binding, relocations will be put into .rel.plt, in
9468 .rel.got otherwise. */
9469 /* FIXME: today we don't support lazy binding so put it in .rel.got */
9470 if (info
->flags
& DF_BIND_NOW
)
9471 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
9473 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
9477 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
9478 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
9481 /* If this is the first .plt entry, make room for the special
9483 if (splt
->size
== 0)
9484 splt
->size
+= htab
->plt_header_size
;
9486 htab
->next_tls_desc_index
++;
9489 /* Allocate the PLT entry itself, including any leading Thumb stub. */
9490 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
9491 splt
->size
+= PLT_THUMB_STUB_SIZE
;
9492 root_plt
->offset
= splt
->size
;
9493 splt
->size
+= htab
->plt_entry_size
;
9495 if (!htab
->symbian_p
)
9497 /* We also need to make an entry in the .got.plt section, which
9498 will be placed in the .got section by the linker script. */
9500 arm_plt
->got_offset
= sgotplt
->size
;
9502 arm_plt
->got_offset
= sgotplt
->size
- 8 * htab
->num_tls_desc
;
9504 /* Function descriptor takes 64 bits in GOT. */
9512 arm_movw_immediate (bfd_vma value
)
9514 return (value
& 0x00000fff) | ((value
& 0x0000f000) << 4);
9518 arm_movt_immediate (bfd_vma value
)
9520 return ((value
& 0x0fff0000) >> 16) | ((value
& 0xf0000000) >> 12);
9523 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
9524 the entry lives in .iplt and resolves to (*SYM_VALUE)().
9525 Otherwise, DYNINDX is the index of the symbol in the dynamic
9526 symbol table and SYM_VALUE is undefined.
9528 ROOT_PLT points to the offset of the PLT entry from the start of its
9529 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
9530 bookkeeping information.
9532 Returns FALSE if there was a problem. */
9535 elf32_arm_populate_plt_entry (bfd
*output_bfd
, struct bfd_link_info
*info
,
9536 union gotplt_union
*root_plt
,
9537 struct arm_plt_info
*arm_plt
,
9538 int dynindx
, bfd_vma sym_value
)
9540 struct elf32_arm_link_hash_table
*htab
;
9546 Elf_Internal_Rela rel
;
9547 bfd_vma plt_header_size
;
9548 bfd_vma got_header_size
;
9550 htab
= elf32_arm_hash_table (info
);
9552 /* Pick the appropriate sections and sizes. */
9555 splt
= htab
->root
.iplt
;
9556 sgot
= htab
->root
.igotplt
;
9557 srel
= htab
->root
.irelplt
;
9559 /* There are no reserved entries in .igot.plt, and no special
9560 first entry in .iplt. */
9561 got_header_size
= 0;
9562 plt_header_size
= 0;
9566 splt
= htab
->root
.splt
;
9567 sgot
= htab
->root
.sgotplt
;
9568 srel
= htab
->root
.srelplt
;
9570 got_header_size
= get_elf_backend_data (output_bfd
)->got_header_size
;
9571 plt_header_size
= htab
->plt_header_size
;
9573 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
9575 /* Fill in the entry in the procedure linkage table. */
9576 if (htab
->symbian_p
)
9578 BFD_ASSERT (dynindx
>= 0);
9579 put_arm_insn (htab
, output_bfd
,
9580 elf32_arm_symbian_plt_entry
[0],
9581 splt
->contents
+ root_plt
->offset
);
9582 bfd_put_32 (output_bfd
,
9583 elf32_arm_symbian_plt_entry
[1],
9584 splt
->contents
+ root_plt
->offset
+ 4);
9586 /* Fill in the entry in the .rel.plt section. */
9587 rel
.r_offset
= (splt
->output_section
->vma
9588 + splt
->output_offset
9589 + root_plt
->offset
+ 4);
9590 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_GLOB_DAT
);
9592 /* Get the index in the procedure linkage table which
9593 corresponds to this symbol. This is the index of this symbol
9594 in all the symbols for which we are making plt entries. The
9595 first entry in the procedure linkage table is reserved. */
9596 plt_index
= ((root_plt
->offset
- plt_header_size
)
9597 / htab
->plt_entry_size
);
9601 bfd_vma got_offset
, got_address
, plt_address
;
9602 bfd_vma got_displacement
, initial_got_entry
;
9605 BFD_ASSERT (sgot
!= NULL
);
9607 /* Get the offset into the .(i)got.plt table of the entry that
9608 corresponds to this function. */
9609 got_offset
= (arm_plt
->got_offset
& -2);
9611 /* Get the index in the procedure linkage table which
9612 corresponds to this symbol. This is the index of this symbol
9613 in all the symbols for which we are making plt entries.
9614 After the reserved .got.plt entries, all symbols appear in
9615 the same order as in .plt. */
9617 /* Function descriptor takes 8 bytes. */
9618 plt_index
= (got_offset
- got_header_size
) / 8;
9620 plt_index
= (got_offset
- got_header_size
) / 4;
9622 /* Calculate the address of the GOT entry. */
9623 got_address
= (sgot
->output_section
->vma
9624 + sgot
->output_offset
9627 /* ...and the address of the PLT entry. */
9628 plt_address
= (splt
->output_section
->vma
9629 + splt
->output_offset
9630 + root_plt
->offset
);
9632 ptr
= splt
->contents
+ root_plt
->offset
;
9633 if (htab
->vxworks_p
&& bfd_link_pic (info
))
9638 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
9640 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
9642 val
|= got_address
- sgot
->output_section
->vma
;
9644 val
|= plt_index
* RELOC_SIZE (htab
);
9645 if (i
== 2 || i
== 5)
9646 bfd_put_32 (output_bfd
, val
, ptr
);
9648 put_arm_insn (htab
, output_bfd
, val
, ptr
);
9651 else if (htab
->vxworks_p
)
9656 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
9658 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
9662 val
|= 0xffffff & -((root_plt
->offset
+ i
* 4 + 8) >> 2);
9664 val
|= plt_index
* RELOC_SIZE (htab
);
9665 if (i
== 2 || i
== 5)
9666 bfd_put_32 (output_bfd
, val
, ptr
);
9668 put_arm_insn (htab
, output_bfd
, val
, ptr
);
9671 loc
= (htab
->srelplt2
->contents
9672 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
9674 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
9675 referencing the GOT for this PLT entry. */
9676 rel
.r_offset
= plt_address
+ 8;
9677 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
9678 rel
.r_addend
= got_offset
;
9679 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
9680 loc
+= RELOC_SIZE (htab
);
9682 /* Create the R_ARM_ABS32 relocation referencing the
9683 beginning of the PLT for this GOT entry. */
9684 rel
.r_offset
= got_address
;
9685 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
9687 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
9689 else if (htab
->nacl_p
)
9691 /* Calculate the displacement between the PLT slot and the
9692 common tail that's part of the special initial PLT slot. */
9693 int32_t tail_displacement
9694 = ((splt
->output_section
->vma
+ splt
->output_offset
9695 + ARM_NACL_PLT_TAIL_OFFSET
)
9696 - (plt_address
+ htab
->plt_entry_size
+ 4));
9697 BFD_ASSERT ((tail_displacement
& 3) == 0);
9698 tail_displacement
>>= 2;
9700 BFD_ASSERT ((tail_displacement
& 0xff000000) == 0
9701 || (-tail_displacement
& 0xff000000) == 0);
9703 /* Calculate the displacement between the PLT slot and the entry
9704 in the GOT. The offset accounts for the value produced by
9705 adding to pc in the penultimate instruction of the PLT stub. */
9706 got_displacement
= (got_address
9707 - (plt_address
+ htab
->plt_entry_size
));
9709 /* NaCl does not support interworking at all. */
9710 BFD_ASSERT (!elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
));
9712 put_arm_insn (htab
, output_bfd
,
9713 elf32_arm_nacl_plt_entry
[0]
9714 | arm_movw_immediate (got_displacement
),
9716 put_arm_insn (htab
, output_bfd
,
9717 elf32_arm_nacl_plt_entry
[1]
9718 | arm_movt_immediate (got_displacement
),
9720 put_arm_insn (htab
, output_bfd
,
9721 elf32_arm_nacl_plt_entry
[2],
9723 put_arm_insn (htab
, output_bfd
,
9724 elf32_arm_nacl_plt_entry
[3]
9725 | (tail_displacement
& 0x00ffffff),
9728 else if (htab
->fdpic_p
)
9730 /* Fill-up Thumb stub if needed. */
9731 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
9733 put_thumb_insn (htab
, output_bfd
,
9734 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
9735 put_thumb_insn (htab
, output_bfd
,
9736 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
9738 put_arm_insn(htab
, output_bfd
,
9739 elf32_arm_fdpic_plt_entry
[0], ptr
+ 0);
9740 put_arm_insn(htab
, output_bfd
,
9741 elf32_arm_fdpic_plt_entry
[1], ptr
+ 4);
9742 put_arm_insn(htab
, output_bfd
,
9743 elf32_arm_fdpic_plt_entry
[2], ptr
+ 8);
9744 put_arm_insn(htab
, output_bfd
,
9745 elf32_arm_fdpic_plt_entry
[3], ptr
+ 12);
9746 bfd_put_32 (output_bfd
, got_offset
, ptr
+ 16);
9748 if (!(info
->flags
& DF_BIND_NOW
))
9750 /* funcdesc_value_reloc_offset. */
9751 bfd_put_32 (output_bfd
,
9752 htab
->root
.srelplt
->reloc_count
* RELOC_SIZE (htab
),
9754 put_arm_insn(htab
, output_bfd
,
9755 elf32_arm_fdpic_plt_entry
[6], ptr
+ 24);
9756 put_arm_insn(htab
, output_bfd
,
9757 elf32_arm_fdpic_plt_entry
[7], ptr
+ 28);
9758 put_arm_insn(htab
, output_bfd
,
9759 elf32_arm_fdpic_plt_entry
[8], ptr
+ 32);
9760 put_arm_insn(htab
, output_bfd
,
9761 elf32_arm_fdpic_plt_entry
[9], ptr
+ 36);
9764 else if (using_thumb_only (htab
))
9766 /* PR ld/16017: Generate thumb only PLT entries. */
9767 if (!using_thumb2 (htab
))
9769 /* FIXME: We ought to be able to generate thumb-1 PLT
9771 _bfd_error_handler (_("%pB: warning: thumb-1 mode PLT generation not currently supported"),
9776 /* Calculate the displacement between the PLT slot and the entry in
9777 the GOT. The 12-byte offset accounts for the value produced by
9778 adding to pc in the 3rd instruction of the PLT stub. */
9779 got_displacement
= got_address
- (plt_address
+ 12);
9781 /* As we are using 32 bit instructions we have to use 'put_arm_insn'
9782 instead of 'put_thumb_insn'. */
9783 put_arm_insn (htab
, output_bfd
,
9784 elf32_thumb2_plt_entry
[0]
9785 | ((got_displacement
& 0x000000ff) << 16)
9786 | ((got_displacement
& 0x00000700) << 20)
9787 | ((got_displacement
& 0x00000800) >> 1)
9788 | ((got_displacement
& 0x0000f000) >> 12),
9790 put_arm_insn (htab
, output_bfd
,
9791 elf32_thumb2_plt_entry
[1]
9792 | ((got_displacement
& 0x00ff0000) )
9793 | ((got_displacement
& 0x07000000) << 4)
9794 | ((got_displacement
& 0x08000000) >> 17)
9795 | ((got_displacement
& 0xf0000000) >> 28),
9797 put_arm_insn (htab
, output_bfd
,
9798 elf32_thumb2_plt_entry
[2],
9800 put_arm_insn (htab
, output_bfd
,
9801 elf32_thumb2_plt_entry
[3],
9806 /* Calculate the displacement between the PLT slot and the
9807 entry in the GOT. The eight-byte offset accounts for the
9808 value produced by adding to pc in the first instruction
9810 got_displacement
= got_address
- (plt_address
+ 8);
9812 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
9814 put_thumb_insn (htab
, output_bfd
,
9815 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
9816 put_thumb_insn (htab
, output_bfd
,
9817 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
9820 if (!elf32_arm_use_long_plt_entry
)
9822 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
9824 put_arm_insn (htab
, output_bfd
,
9825 elf32_arm_plt_entry_short
[0]
9826 | ((got_displacement
& 0x0ff00000) >> 20),
9828 put_arm_insn (htab
, output_bfd
,
9829 elf32_arm_plt_entry_short
[1]
9830 | ((got_displacement
& 0x000ff000) >> 12),
9832 put_arm_insn (htab
, output_bfd
,
9833 elf32_arm_plt_entry_short
[2]
9834 | (got_displacement
& 0x00000fff),
9836 #ifdef FOUR_WORD_PLT
9837 bfd_put_32 (output_bfd
, elf32_arm_plt_entry_short
[3], ptr
+ 12);
9842 put_arm_insn (htab
, output_bfd
,
9843 elf32_arm_plt_entry_long
[0]
9844 | ((got_displacement
& 0xf0000000) >> 28),
9846 put_arm_insn (htab
, output_bfd
,
9847 elf32_arm_plt_entry_long
[1]
9848 | ((got_displacement
& 0x0ff00000) >> 20),
9850 put_arm_insn (htab
, output_bfd
,
9851 elf32_arm_plt_entry_long
[2]
9852 | ((got_displacement
& 0x000ff000) >> 12),
9854 put_arm_insn (htab
, output_bfd
,
9855 elf32_arm_plt_entry_long
[3]
9856 | (got_displacement
& 0x00000fff),
9861 /* Fill in the entry in the .rel(a).(i)plt section. */
9862 rel
.r_offset
= got_address
;
9866 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
9867 The dynamic linker or static executable then calls SYM_VALUE
9868 to determine the correct run-time value of the .igot.plt entry. */
9869 rel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9870 initial_got_entry
= sym_value
;
9874 /* For FDPIC we will have to resolve a R_ARM_FUNCDESC_VALUE
9875 used by PLT entry. */
9878 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_FUNCDESC_VALUE
);
9879 initial_got_entry
= 0;
9883 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_JUMP_SLOT
);
9884 initial_got_entry
= (splt
->output_section
->vma
9885 + splt
->output_offset
);
9889 /* Fill in the entry in the global offset table. */
9890 bfd_put_32 (output_bfd
, initial_got_entry
,
9891 sgot
->contents
+ got_offset
);
9893 if (htab
->fdpic_p
&& !(info
->flags
& DF_BIND_NOW
))
9895 /* Setup initial funcdesc value. */
9896 /* FIXME: we don't support lazy binding because there is a
9897 race condition between both words getting written and
9898 some other thread attempting to read them. The ARM
9899 architecture does not have an atomic 64 bit load/store
9900 instruction that could be used to prevent it; it is
9901 recommended that threaded FDPIC applications run with the
9902 LD_BIND_NOW environment variable set. */
9903 bfd_put_32(output_bfd
, plt_address
+ 0x18,
9904 sgot
->contents
+ got_offset
);
9905 bfd_put_32(output_bfd
, -1 /*TODO*/,
9906 sgot
->contents
+ got_offset
+ 4);
9911 elf32_arm_add_dynreloc (output_bfd
, info
, srel
, &rel
);
9916 /* For FDPIC we put PLT relocationss into .rel.got when not
9917 lazy binding otherwise we put them in .rel.plt. For now,
9918 we don't support lazy binding so put it in .rel.got. */
9919 if (info
->flags
& DF_BIND_NOW
)
9920 elf32_arm_add_dynreloc(output_bfd
, info
, htab
->root
.srelgot
, &rel
);
9922 elf32_arm_add_dynreloc(output_bfd
, info
, htab
->root
.srelplt
, &rel
);
9926 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
9927 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
9934 /* Some relocations map to different relocations depending on the
9935 target. Return the real relocation. */
9938 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
9944 if (globals
->target1_is_rel
)
9950 return globals
->target2_reloc
;
9957 /* Return the base VMA address which should be subtracted from real addresses
9958 when resolving @dtpoff relocation.
9959 This is PT_TLS segment p_vaddr. */
9962 dtpoff_base (struct bfd_link_info
*info
)
9964 /* If tls_sec is NULL, we should have signalled an error already. */
9965 if (elf_hash_table (info
)->tls_sec
== NULL
)
9967 return elf_hash_table (info
)->tls_sec
->vma
;
9970 /* Return the relocation value for @tpoff relocation
9971 if STT_TLS virtual address is ADDRESS. */
9974 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
9976 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9979 /* If tls_sec is NULL, we should have signalled an error already. */
9980 if (htab
->tls_sec
== NULL
)
9982 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
9983 return address
- htab
->tls_sec
->vma
+ base
;
9986 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
9987 VALUE is the relocation value. */
9989 static bfd_reloc_status_type
9990 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
9993 return bfd_reloc_overflow
;
9995 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
9996 bfd_put_32 (abfd
, value
, data
);
9997 return bfd_reloc_ok
;
10000 /* Handle TLS relaxations. Relaxing is possible for symbols that use
10001 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
10002 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
10004 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
10005 is to then call final_link_relocate. Return other values in the
10008 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
10009 the pre-relaxed code. It would be nice if the relocs were updated
10010 to match the optimization. */
10012 static bfd_reloc_status_type
10013 elf32_arm_tls_relax (struct elf32_arm_link_hash_table
*globals
,
10014 bfd
*input_bfd
, asection
*input_sec
, bfd_byte
*contents
,
10015 Elf_Internal_Rela
*rel
, unsigned long is_local
)
10017 unsigned long insn
;
10019 switch (ELF32_R_TYPE (rel
->r_info
))
10022 return bfd_reloc_notsupported
;
10024 case R_ARM_TLS_GOTDESC
:
10029 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10031 insn
-= 5; /* THUMB */
10033 insn
-= 8; /* ARM */
10035 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
10036 return bfd_reloc_continue
;
10038 case R_ARM_THM_TLS_DESCSEQ
:
10040 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
10041 if ((insn
& 0xff78) == 0x4478) /* add rx, pc */
10045 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
10047 else if ((insn
& 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
10051 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
10054 bfd_put_16 (input_bfd
, insn
& 0xf83f, contents
+ rel
->r_offset
);
10056 else if ((insn
& 0xff87) == 0x4780) /* blx rx */
10060 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
10063 bfd_put_16 (input_bfd
, 0x4600 | (insn
& 0x78),
10064 contents
+ rel
->r_offset
);
10068 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
10069 /* It's a 32 bit instruction, fetch the rest of it for
10070 error generation. */
10071 insn
= (insn
<< 16)
10072 | bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
10074 /* xgettext:c-format */
10075 (_("%pB(%pA+%#" PRIx64
"): "
10076 "unexpected %s instruction '%#lx' in TLS trampoline"),
10077 input_bfd
, input_sec
, (uint64_t) rel
->r_offset
,
10079 return bfd_reloc_notsupported
;
10083 case R_ARM_TLS_DESCSEQ
:
10085 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10086 if ((insn
& 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
10090 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xffff),
10091 contents
+ rel
->r_offset
);
10093 else if ((insn
& 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
10097 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
10100 bfd_put_32 (input_bfd
, insn
& 0xfffff000,
10101 contents
+ rel
->r_offset
);
10103 else if ((insn
& 0xfffffff0) == 0xe12fff30) /* blx rx */
10107 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
10110 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xf),
10111 contents
+ rel
->r_offset
);
10116 /* xgettext:c-format */
10117 (_("%pB(%pA+%#" PRIx64
"): "
10118 "unexpected %s instruction '%#lx' in TLS trampoline"),
10119 input_bfd
, input_sec
, (uint64_t) rel
->r_offset
,
10121 return bfd_reloc_notsupported
;
10125 case R_ARM_TLS_CALL
:
10126 /* GD->IE relaxation, turn the instruction into 'nop' or
10127 'ldr r0, [pc,r0]' */
10128 insn
= is_local
? 0xe1a00000 : 0xe79f0000;
10129 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
10132 case R_ARM_THM_TLS_CALL
:
10133 /* GD->IE relaxation. */
10135 /* add r0,pc; ldr r0, [r0] */
10137 else if (using_thumb2 (globals
))
10144 bfd_put_16 (input_bfd
, insn
>> 16, contents
+ rel
->r_offset
);
10145 bfd_put_16 (input_bfd
, insn
& 0xffff, contents
+ rel
->r_offset
+ 2);
10148 return bfd_reloc_ok
;
10151 /* For a given value of n, calculate the value of G_n as required to
10152 deal with group relocations. We return it in the form of an
10153 encoded constant-and-rotation, together with the final residual. If n is
10154 specified as less than zero, then final_residual is filled with the
10155 input value and no further action is performed. */
10158 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
10162 bfd_vma encoded_g_n
= 0;
10163 bfd_vma residual
= value
; /* Also known as Y_n. */
10165 for (current_n
= 0; current_n
<= n
; current_n
++)
10169 /* Calculate which part of the value to mask. */
10176 /* Determine the most significant bit in the residual and
10177 align the resulting value to a 2-bit boundary. */
10178 for (msb
= 30; msb
>= 0; msb
-= 2)
10179 if (residual
& (3 << msb
))
10182 /* The desired shift is now (msb - 6), or zero, whichever
10189 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
10190 g_n
= residual
& (0xff << shift
);
10191 encoded_g_n
= (g_n
>> shift
)
10192 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
10194 /* Calculate the residual for the next time around. */
10198 *final_residual
= residual
;
10200 return encoded_g_n
;
10203 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
10204 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
10207 identify_add_or_sub (bfd_vma insn
)
10209 int opcode
= insn
& 0x1e00000;
10211 if (opcode
== 1 << 23) /* ADD */
10214 if (opcode
== 1 << 22) /* SUB */
10220 /* Perform a relocation as part of a final link. */
10222 static bfd_reloc_status_type
10223 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
10226 asection
* input_section
,
10227 bfd_byte
* contents
,
10228 Elf_Internal_Rela
* rel
,
10230 struct bfd_link_info
* info
,
10231 asection
* sym_sec
,
10232 const char * sym_name
,
10233 unsigned char st_type
,
10234 enum arm_st_branch_type branch_type
,
10235 struct elf_link_hash_entry
* h
,
10236 bfd_boolean
* unresolved_reloc_p
,
10237 char ** error_message
)
10239 unsigned long r_type
= howto
->type
;
10240 unsigned long r_symndx
;
10241 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
10242 bfd_vma
* local_got_offsets
;
10243 bfd_vma
* local_tlsdesc_gotents
;
10246 asection
* sreloc
= NULL
;
10247 asection
* srelgot
;
10249 bfd_signed_vma signed_addend
;
10250 unsigned char dynreloc_st_type
;
10251 bfd_vma dynreloc_value
;
10252 struct elf32_arm_link_hash_table
* globals
;
10253 struct elf32_arm_link_hash_entry
*eh
;
10254 union gotplt_union
*root_plt
;
10255 struct arm_plt_info
*arm_plt
;
10256 bfd_vma plt_offset
;
10257 bfd_vma gotplt_offset
;
10258 bfd_boolean has_iplt_entry
;
10259 bfd_boolean resolved_to_zero
;
10261 globals
= elf32_arm_hash_table (info
);
10262 if (globals
== NULL
)
10263 return bfd_reloc_notsupported
;
10265 BFD_ASSERT (is_arm_elf (input_bfd
));
10266 BFD_ASSERT (howto
!= NULL
);
10268 /* Some relocation types map to different relocations depending on the
10269 target. We pick the right one here. */
10270 r_type
= arm_real_reloc_type (globals
, r_type
);
10272 /* It is possible to have linker relaxations on some TLS access
10273 models. Update our information here. */
10274 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
10276 if (r_type
!= howto
->type
)
10277 howto
= elf32_arm_howto_from_type (r_type
);
10279 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10280 sgot
= globals
->root
.sgot
;
10281 local_got_offsets
= elf_local_got_offsets (input_bfd
);
10282 local_tlsdesc_gotents
= elf32_arm_local_tlsdesc_gotent (input_bfd
);
10284 if (globals
->root
.dynamic_sections_created
)
10285 srelgot
= globals
->root
.srelgot
;
10289 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10291 if (globals
->use_rel
)
10293 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
10295 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10297 signed_addend
= -1;
10298 signed_addend
&= ~ howto
->src_mask
;
10299 signed_addend
|= addend
;
10302 signed_addend
= addend
;
10305 addend
= signed_addend
= rel
->r_addend
;
10307 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
10308 are resolving a function call relocation. */
10309 if (using_thumb_only (globals
)
10310 && (r_type
== R_ARM_THM_CALL
10311 || r_type
== R_ARM_THM_JUMP24
)
10312 && branch_type
== ST_BRANCH_TO_ARM
)
10313 branch_type
= ST_BRANCH_TO_THUMB
;
10315 /* Record the symbol information that should be used in dynamic
10317 dynreloc_st_type
= st_type
;
10318 dynreloc_value
= value
;
10319 if (branch_type
== ST_BRANCH_TO_THUMB
)
10320 dynreloc_value
|= 1;
10322 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
10323 VALUE appropriately for relocations that we resolve at link time. */
10324 has_iplt_entry
= FALSE
;
10325 if (elf32_arm_get_plt_info (input_bfd
, globals
, eh
, r_symndx
, &root_plt
,
10327 && root_plt
->offset
!= (bfd_vma
) -1)
10329 plt_offset
= root_plt
->offset
;
10330 gotplt_offset
= arm_plt
->got_offset
;
10332 if (h
== NULL
|| eh
->is_iplt
)
10334 has_iplt_entry
= TRUE
;
10335 splt
= globals
->root
.iplt
;
10337 /* Populate .iplt entries here, because not all of them will
10338 be seen by finish_dynamic_symbol. The lower bit is set if
10339 we have already populated the entry. */
10340 if (plt_offset
& 1)
10344 if (elf32_arm_populate_plt_entry (output_bfd
, info
, root_plt
, arm_plt
,
10345 -1, dynreloc_value
))
10346 root_plt
->offset
|= 1;
10348 return bfd_reloc_notsupported
;
10351 /* Static relocations always resolve to the .iplt entry. */
10352 st_type
= STT_FUNC
;
10353 value
= (splt
->output_section
->vma
10354 + splt
->output_offset
10356 branch_type
= ST_BRANCH_TO_ARM
;
10358 /* If there are non-call relocations that resolve to the .iplt
10359 entry, then all dynamic ones must too. */
10360 if (arm_plt
->noncall_refcount
!= 0)
10362 dynreloc_st_type
= st_type
;
10363 dynreloc_value
= value
;
10367 /* We populate the .plt entry in finish_dynamic_symbol. */
10368 splt
= globals
->root
.splt
;
10373 plt_offset
= (bfd_vma
) -1;
10374 gotplt_offset
= (bfd_vma
) -1;
10377 resolved_to_zero
= (h
!= NULL
10378 && UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
10383 /* We don't need to find a value for this symbol. It's just a
10385 *unresolved_reloc_p
= FALSE
;
10386 return bfd_reloc_ok
;
10389 if (!globals
->vxworks_p
)
10390 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
10391 /* Fall through. */
10395 case R_ARM_ABS32_NOI
:
10397 case R_ARM_REL32_NOI
:
10403 /* Handle relocations which should use the PLT entry. ABS32/REL32
10404 will use the symbol's value, which may point to a PLT entry, but we
10405 don't need to handle that here. If we created a PLT entry, all
10406 branches in this object should go to it, except if the PLT is too
10407 far away, in which case a long branch stub should be inserted. */
10408 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
10409 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
10410 && r_type
!= R_ARM_CALL
10411 && r_type
!= R_ARM_JUMP24
10412 && r_type
!= R_ARM_PLT32
)
10413 && plt_offset
!= (bfd_vma
) -1)
10415 /* If we've created a .plt section, and assigned a PLT entry
10416 to this function, it must either be a STT_GNU_IFUNC reference
10417 or not be known to bind locally. In other cases, we should
10418 have cleared the PLT entry by now. */
10419 BFD_ASSERT (has_iplt_entry
|| !SYMBOL_CALLS_LOCAL (info
, h
));
10421 value
= (splt
->output_section
->vma
10422 + splt
->output_offset
10424 *unresolved_reloc_p
= FALSE
;
10425 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
10426 contents
, rel
->r_offset
, value
,
10430 /* When generating a shared object or relocatable executable, these
10431 relocations are copied into the output file to be resolved at
10433 if ((bfd_link_pic (info
)
10434 || globals
->root
.is_relocatable_executable
10435 || globals
->fdpic_p
)
10436 && (input_section
->flags
& SEC_ALLOC
)
10437 && !(globals
->vxworks_p
10438 && strcmp (input_section
->output_section
->name
,
10440 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
10441 || !SYMBOL_CALLS_LOCAL (info
, h
))
10442 && !(input_bfd
== globals
->stub_bfd
10443 && strstr (input_section
->name
, STUB_SUFFIX
))
10445 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
10446 && !resolved_to_zero
)
10447 || h
->root
.type
!= bfd_link_hash_undefweak
)
10448 && r_type
!= R_ARM_PC24
10449 && r_type
!= R_ARM_CALL
10450 && r_type
!= R_ARM_JUMP24
10451 && r_type
!= R_ARM_PREL31
10452 && r_type
!= R_ARM_PLT32
)
10454 Elf_Internal_Rela outrel
;
10455 bfd_boolean skip
, relocate
;
10458 if ((r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
10459 && !h
->def_regular
)
10461 char *v
= _("shared object");
10463 if (bfd_link_executable (info
))
10464 v
= _("PIE executable");
10467 (_("%pB: relocation %s against external or undefined symbol `%s'"
10468 " can not be used when making a %s; recompile with -fPIC"), input_bfd
,
10469 elf32_arm_howto_table_1
[r_type
].name
, h
->root
.root
.string
, v
);
10470 return bfd_reloc_notsupported
;
10473 *unresolved_reloc_p
= FALSE
;
10475 if (sreloc
== NULL
&& globals
->root
.dynamic_sections_created
)
10477 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
10478 ! globals
->use_rel
);
10480 if (sreloc
== NULL
)
10481 return bfd_reloc_notsupported
;
10487 outrel
.r_addend
= addend
;
10489 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
10491 if (outrel
.r_offset
== (bfd_vma
) -1)
10493 else if (outrel
.r_offset
== (bfd_vma
) -2)
10494 skip
= TRUE
, relocate
= TRUE
;
10495 outrel
.r_offset
+= (input_section
->output_section
->vma
10496 + input_section
->output_offset
);
10499 memset (&outrel
, 0, sizeof outrel
);
10501 && h
->dynindx
!= -1
10502 && (!bfd_link_pic (info
)
10503 || !(bfd_link_pie (info
)
10504 || SYMBOLIC_BIND (info
, h
))
10505 || !h
->def_regular
))
10506 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
10511 /* This symbol is local, or marked to become local. */
10512 BFD_ASSERT (r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
10513 || (globals
->fdpic_p
&& !bfd_link_pic(info
)));
10514 if (globals
->symbian_p
)
10518 /* On Symbian OS, the data segment and text segement
10519 can be relocated independently. Therefore, we
10520 must indicate the segment to which this
10521 relocation is relative. The BPABI allows us to
10522 use any symbol in the right segment; we just use
10523 the section symbol as it is convenient. (We
10524 cannot use the symbol given by "h" directly as it
10525 will not appear in the dynamic symbol table.)
10527 Note that the dynamic linker ignores the section
10528 symbol value, so we don't subtract osec->vma
10529 from the emitted reloc addend. */
10531 osec
= sym_sec
->output_section
;
10533 osec
= input_section
->output_section
;
10534 symbol
= elf_section_data (osec
)->dynindx
;
10537 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
10539 if ((osec
->flags
& SEC_READONLY
) == 0
10540 && htab
->data_index_section
!= NULL
)
10541 osec
= htab
->data_index_section
;
10543 osec
= htab
->text_index_section
;
10544 symbol
= elf_section_data (osec
)->dynindx
;
10546 BFD_ASSERT (symbol
!= 0);
10549 /* On SVR4-ish systems, the dynamic loader cannot
10550 relocate the text and data segments independently,
10551 so the symbol does not matter. */
10553 if (dynreloc_st_type
== STT_GNU_IFUNC
)
10554 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
10555 to the .iplt entry. Instead, every non-call reference
10556 must use an R_ARM_IRELATIVE relocation to obtain the
10557 correct run-time address. */
10558 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_IRELATIVE
);
10559 else if (globals
->fdpic_p
&& !bfd_link_pic(info
))
10562 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
10563 if (globals
->use_rel
)
10566 outrel
.r_addend
+= dynreloc_value
;
10570 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
, outrel
.r_offset
);
10572 elf32_arm_add_dynreloc (output_bfd
, info
, sreloc
, &outrel
);
10574 /* If this reloc is against an external symbol, we do not want to
10575 fiddle with the addend. Otherwise, we need to include the symbol
10576 value so that it becomes an addend for the dynamic reloc. */
10578 return bfd_reloc_ok
;
10580 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
10581 contents
, rel
->r_offset
,
10582 dynreloc_value
, (bfd_vma
) 0);
10584 else switch (r_type
)
10587 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
10589 case R_ARM_XPC25
: /* Arm BLX instruction. */
10592 case R_ARM_PC24
: /* Arm B/BL instruction. */
10595 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
10597 if (r_type
== R_ARM_XPC25
)
10599 /* Check for Arm calling Arm function. */
10600 /* FIXME: Should we translate the instruction into a BL
10601 instruction instead ? */
10602 if (branch_type
!= ST_BRANCH_TO_THUMB
)
10604 (_("\%pB: warning: %s BLX instruction targets"
10605 " %s function '%s'"),
10607 "ARM", h
? h
->root
.root
.string
: "(local)");
10609 else if (r_type
== R_ARM_PC24
)
10611 /* Check for Arm calling Thumb function. */
10612 if (branch_type
== ST_BRANCH_TO_THUMB
)
10614 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
10615 output_bfd
, input_section
,
10616 hit_data
, sym_sec
, rel
->r_offset
,
10617 signed_addend
, value
,
10619 return bfd_reloc_ok
;
10621 return bfd_reloc_dangerous
;
10625 /* Check if a stub has to be inserted because the
10626 destination is too far or we are changing mode. */
10627 if ( r_type
== R_ARM_CALL
10628 || r_type
== R_ARM_JUMP24
10629 || r_type
== R_ARM_PLT32
)
10631 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
10632 struct elf32_arm_link_hash_entry
*hash
;
10634 hash
= (struct elf32_arm_link_hash_entry
*) h
;
10635 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
10636 st_type
, &branch_type
,
10637 hash
, value
, sym_sec
,
10638 input_bfd
, sym_name
);
10640 if (stub_type
!= arm_stub_none
)
10642 /* The target is out of reach, so redirect the
10643 branch to the local stub for this function. */
10644 stub_entry
= elf32_arm_get_stub_entry (input_section
,
10649 if (stub_entry
!= NULL
)
10650 value
= (stub_entry
->stub_offset
10651 + stub_entry
->stub_sec
->output_offset
10652 + stub_entry
->stub_sec
->output_section
->vma
);
10654 if (plt_offset
!= (bfd_vma
) -1)
10655 *unresolved_reloc_p
= FALSE
;
10660 /* If the call goes through a PLT entry, make sure to
10661 check distance to the right destination address. */
10662 if (plt_offset
!= (bfd_vma
) -1)
10664 value
= (splt
->output_section
->vma
10665 + splt
->output_offset
10667 *unresolved_reloc_p
= FALSE
;
10668 /* The PLT entry is in ARM mode, regardless of the
10669 target function. */
10670 branch_type
= ST_BRANCH_TO_ARM
;
10675 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
10677 S is the address of the symbol in the relocation.
10678 P is address of the instruction being relocated.
10679 A is the addend (extracted from the instruction) in bytes.
10681 S is held in 'value'.
10682 P is the base address of the section containing the
10683 instruction plus the offset of the reloc into that
10685 (input_section->output_section->vma +
10686 input_section->output_offset +
10688 A is the addend, converted into bytes, ie:
10689 (signed_addend * 4)
10691 Note: None of these operations have knowledge of the pipeline
10692 size of the processor, thus it is up to the assembler to
10693 encode this information into the addend. */
10694 value
-= (input_section
->output_section
->vma
10695 + input_section
->output_offset
);
10696 value
-= rel
->r_offset
;
10697 if (globals
->use_rel
)
10698 value
+= (signed_addend
<< howto
->size
);
10700 /* RELA addends do not have to be adjusted by howto->size. */
10701 value
+= signed_addend
;
10703 signed_addend
= value
;
10704 signed_addend
>>= howto
->rightshift
;
10706 /* A branch to an undefined weak symbol is turned into a jump to
10707 the next instruction unless a PLT entry will be created.
10708 Do the same for local undefined symbols (but not for STN_UNDEF).
10709 The jump to the next instruction is optimized as a NOP depending
10710 on the architecture. */
10711 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
10712 && plt_offset
== (bfd_vma
) -1)
10713 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sym_sec
))
10715 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000);
10717 if (arch_has_arm_nop (globals
))
10718 value
|= 0x0320f000;
10720 value
|= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
10724 /* Perform a signed range check. */
10725 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
10726 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
10727 return bfd_reloc_overflow
;
10729 addend
= (value
& 2);
10731 value
= (signed_addend
& howto
->dst_mask
)
10732 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
10734 if (r_type
== R_ARM_CALL
)
10736 /* Set the H bit in the BLX instruction. */
10737 if (branch_type
== ST_BRANCH_TO_THUMB
)
10740 value
|= (1 << 24);
10742 value
&= ~(bfd_vma
)(1 << 24);
10745 /* Select the correct instruction (BL or BLX). */
10746 /* Only if we are not handling a BL to a stub. In this
10747 case, mode switching is performed by the stub. */
10748 if (branch_type
== ST_BRANCH_TO_THUMB
&& !stub_entry
)
10749 value
|= (1 << 28);
10750 else if (stub_entry
|| branch_type
!= ST_BRANCH_UNKNOWN
)
10752 value
&= ~(bfd_vma
)(1 << 28);
10753 value
|= (1 << 24);
10762 if (branch_type
== ST_BRANCH_TO_THUMB
)
10766 case R_ARM_ABS32_NOI
:
10772 if (branch_type
== ST_BRANCH_TO_THUMB
)
10774 value
-= (input_section
->output_section
->vma
10775 + input_section
->output_offset
+ rel
->r_offset
);
10778 case R_ARM_REL32_NOI
:
10780 value
-= (input_section
->output_section
->vma
10781 + input_section
->output_offset
+ rel
->r_offset
);
10785 value
-= (input_section
->output_section
->vma
10786 + input_section
->output_offset
+ rel
->r_offset
);
10787 value
+= signed_addend
;
10788 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
10790 /* Check for overflow. */
10791 if ((value
^ (value
>> 1)) & (1 << 30))
10792 return bfd_reloc_overflow
;
10794 value
&= 0x7fffffff;
10795 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
10796 if (branch_type
== ST_BRANCH_TO_THUMB
)
10801 bfd_put_32 (input_bfd
, value
, hit_data
);
10802 return bfd_reloc_ok
;
10805 /* PR 16202: Refectch the addend using the correct size. */
10806 if (globals
->use_rel
)
10807 addend
= bfd_get_8 (input_bfd
, hit_data
);
10810 /* There is no way to tell whether the user intended to use a signed or
10811 unsigned addend. When checking for overflow we accept either,
10812 as specified by the AAELF. */
10813 if ((long) value
> 0xff || (long) value
< -0x80)
10814 return bfd_reloc_overflow
;
10816 bfd_put_8 (input_bfd
, value
, hit_data
);
10817 return bfd_reloc_ok
;
10820 /* PR 16202: Refectch the addend using the correct size. */
10821 if (globals
->use_rel
)
10822 addend
= bfd_get_16 (input_bfd
, hit_data
);
10825 /* See comment for R_ARM_ABS8. */
10826 if ((long) value
> 0xffff || (long) value
< -0x8000)
10827 return bfd_reloc_overflow
;
10829 bfd_put_16 (input_bfd
, value
, hit_data
);
10830 return bfd_reloc_ok
;
10832 case R_ARM_THM_ABS5
:
10833 /* Support ldr and str instructions for the thumb. */
10834 if (globals
->use_rel
)
10836 /* Need to refetch addend. */
10837 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
10838 /* ??? Need to determine shift amount from operand size. */
10839 addend
>>= howto
->rightshift
;
10843 /* ??? Isn't value unsigned? */
10844 if ((long) value
> 0x1f || (long) value
< -0x10)
10845 return bfd_reloc_overflow
;
10847 /* ??? Value needs to be properly shifted into place first. */
10848 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
10849 bfd_put_16 (input_bfd
, value
, hit_data
);
10850 return bfd_reloc_ok
;
10852 case R_ARM_THM_ALU_PREL_11_0
:
10853 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
10856 bfd_signed_vma relocation
;
10858 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
10859 | bfd_get_16 (input_bfd
, hit_data
+ 2);
10861 if (globals
->use_rel
)
10863 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
10864 | ((insn
& (1 << 26)) >> 15);
10865 if (insn
& 0xf00000)
10866 signed_addend
= -signed_addend
;
10869 relocation
= value
+ signed_addend
;
10870 relocation
-= Pa (input_section
->output_section
->vma
10871 + input_section
->output_offset
10874 /* PR 21523: Use an absolute value. The user of this reloc will
10875 have already selected an ADD or SUB insn appropriately. */
10876 value
= labs (relocation
);
10878 if (value
>= 0x1000)
10879 return bfd_reloc_overflow
;
10881 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
10882 if (branch_type
== ST_BRANCH_TO_THUMB
)
10885 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
10886 | ((value
& 0x700) << 4)
10887 | ((value
& 0x800) << 15);
10888 if (relocation
< 0)
10891 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
10892 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
10894 return bfd_reloc_ok
;
10897 case R_ARM_THM_PC8
:
10898 /* PR 10073: This reloc is not generated by the GNU toolchain,
10899 but it is supported for compatibility with third party libraries
10900 generated by other compilers, specifically the ARM/IAR. */
10903 bfd_signed_vma relocation
;
10905 insn
= bfd_get_16 (input_bfd
, hit_data
);
10907 if (globals
->use_rel
)
10908 addend
= ((((insn
& 0x00ff) << 2) + 4) & 0x3ff) -4;
10910 relocation
= value
+ addend
;
10911 relocation
-= Pa (input_section
->output_section
->vma
10912 + input_section
->output_offset
10915 value
= relocation
;
10917 /* We do not check for overflow of this reloc. Although strictly
10918 speaking this is incorrect, it appears to be necessary in order
10919 to work with IAR generated relocs. Since GCC and GAS do not
10920 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
10921 a problem for them. */
10924 insn
= (insn
& 0xff00) | (value
>> 2);
10926 bfd_put_16 (input_bfd
, insn
, hit_data
);
10928 return bfd_reloc_ok
;
10931 case R_ARM_THM_PC12
:
10932 /* Corresponds to: ldr.w reg, [pc, #offset]. */
10935 bfd_signed_vma relocation
;
10937 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
10938 | bfd_get_16 (input_bfd
, hit_data
+ 2);
10940 if (globals
->use_rel
)
10942 signed_addend
= insn
& 0xfff;
10943 if (!(insn
& (1 << 23)))
10944 signed_addend
= -signed_addend
;
10947 relocation
= value
+ signed_addend
;
10948 relocation
-= Pa (input_section
->output_section
->vma
10949 + input_section
->output_offset
10952 value
= relocation
;
10954 if (value
>= 0x1000)
10955 return bfd_reloc_overflow
;
10957 insn
= (insn
& 0xff7ff000) | value
;
10958 if (relocation
>= 0)
10961 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
10962 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
10964 return bfd_reloc_ok
;
10967 case R_ARM_THM_XPC22
:
10968 case R_ARM_THM_CALL
:
10969 case R_ARM_THM_JUMP24
:
10970 /* Thumb BL (branch long instruction). */
10972 bfd_vma relocation
;
10973 bfd_vma reloc_sign
;
10974 bfd_boolean overflow
= FALSE
;
10975 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
10976 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
10977 bfd_signed_vma reloc_signed_max
;
10978 bfd_signed_vma reloc_signed_min
;
10980 bfd_signed_vma signed_check
;
10982 const int thumb2
= using_thumb2 (globals
);
10983 const int thumb2_bl
= using_thumb2_bl (globals
);
10985 /* A branch to an undefined weak symbol is turned into a jump to
10986 the next instruction unless a PLT entry will be created.
10987 The jump to the next instruction is optimized as a NOP.W for
10988 Thumb-2 enabled architectures. */
10989 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
10990 && plt_offset
== (bfd_vma
) -1)
10994 bfd_put_16 (input_bfd
, 0xf3af, hit_data
);
10995 bfd_put_16 (input_bfd
, 0x8000, hit_data
+ 2);
10999 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
11000 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
11002 return bfd_reloc_ok
;
11005 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
11006 with Thumb-1) involving the J1 and J2 bits. */
11007 if (globals
->use_rel
)
11009 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
11010 bfd_vma upper
= upper_insn
& 0x3ff;
11011 bfd_vma lower
= lower_insn
& 0x7ff;
11012 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
11013 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
11014 bfd_vma i1
= j1
^ s
? 0 : 1;
11015 bfd_vma i2
= j2
^ s
? 0 : 1;
11017 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
11019 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
11021 signed_addend
= addend
;
11024 if (r_type
== R_ARM_THM_XPC22
)
11026 /* Check for Thumb to Thumb call. */
11027 /* FIXME: Should we translate the instruction into a BL
11028 instruction instead ? */
11029 if (branch_type
== ST_BRANCH_TO_THUMB
)
11031 (_("%pB: warning: %s BLX instruction targets"
11032 " %s function '%s'"),
11033 input_bfd
, "Thumb",
11034 "Thumb", h
? h
->root
.root
.string
: "(local)");
11038 /* If it is not a call to Thumb, assume call to Arm.
11039 If it is a call relative to a section name, then it is not a
11040 function call at all, but rather a long jump. Calls through
11041 the PLT do not require stubs. */
11042 if (branch_type
== ST_BRANCH_TO_ARM
&& plt_offset
== (bfd_vma
) -1)
11044 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
11046 /* Convert BL to BLX. */
11047 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
11049 else if (( r_type
!= R_ARM_THM_CALL
)
11050 && (r_type
!= R_ARM_THM_JUMP24
))
11052 if (elf32_thumb_to_arm_stub
11053 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
11054 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
11056 return bfd_reloc_ok
;
11058 return bfd_reloc_dangerous
;
11061 else if (branch_type
== ST_BRANCH_TO_THUMB
11062 && globals
->use_blx
11063 && r_type
== R_ARM_THM_CALL
)
11065 /* Make sure this is a BL. */
11066 lower_insn
|= 0x1800;
11070 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
11071 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
11073 /* Check if a stub has to be inserted because the destination
11075 struct elf32_arm_stub_hash_entry
*stub_entry
;
11076 struct elf32_arm_link_hash_entry
*hash
;
11078 hash
= (struct elf32_arm_link_hash_entry
*) h
;
11080 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
11081 st_type
, &branch_type
,
11082 hash
, value
, sym_sec
,
11083 input_bfd
, sym_name
);
11085 if (stub_type
!= arm_stub_none
)
11087 /* The target is out of reach or we are changing modes, so
11088 redirect the branch to the local stub for this
11090 stub_entry
= elf32_arm_get_stub_entry (input_section
,
11094 if (stub_entry
!= NULL
)
11096 value
= (stub_entry
->stub_offset
11097 + stub_entry
->stub_sec
->output_offset
11098 + stub_entry
->stub_sec
->output_section
->vma
);
11100 if (plt_offset
!= (bfd_vma
) -1)
11101 *unresolved_reloc_p
= FALSE
;
11104 /* If this call becomes a call to Arm, force BLX. */
11105 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
11108 && !arm_stub_is_thumb (stub_entry
->stub_type
))
11109 || branch_type
!= ST_BRANCH_TO_THUMB
)
11110 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
11115 /* Handle calls via the PLT. */
11116 if (stub_type
== arm_stub_none
&& plt_offset
!= (bfd_vma
) -1)
11118 value
= (splt
->output_section
->vma
11119 + splt
->output_offset
11122 if (globals
->use_blx
11123 && r_type
== R_ARM_THM_CALL
11124 && ! using_thumb_only (globals
))
11126 /* If the Thumb BLX instruction is available, convert
11127 the BL to a BLX instruction to call the ARM-mode
11129 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
11130 branch_type
= ST_BRANCH_TO_ARM
;
11134 if (! using_thumb_only (globals
))
11135 /* Target the Thumb stub before the ARM PLT entry. */
11136 value
-= PLT_THUMB_STUB_SIZE
;
11137 branch_type
= ST_BRANCH_TO_THUMB
;
11139 *unresolved_reloc_p
= FALSE
;
11142 relocation
= value
+ signed_addend
;
11144 relocation
-= (input_section
->output_section
->vma
11145 + input_section
->output_offset
11148 check
= relocation
>> howto
->rightshift
;
11150 /* If this is a signed value, the rightshift just dropped
11151 leading 1 bits (assuming twos complement). */
11152 if ((bfd_signed_vma
) relocation
>= 0)
11153 signed_check
= check
;
11155 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
11157 /* Calculate the permissable maximum and minimum values for
11158 this relocation according to whether we're relocating for
11160 bitsize
= howto
->bitsize
;
11163 reloc_signed_max
= (1 << (bitsize
- 1)) - 1;
11164 reloc_signed_min
= ~reloc_signed_max
;
11166 /* Assumes two's complement. */
11167 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
11170 if ((lower_insn
& 0x5000) == 0x4000)
11171 /* For a BLX instruction, make sure that the relocation is rounded up
11172 to a word boundary. This follows the semantics of the instruction
11173 which specifies that bit 1 of the target address will come from bit
11174 1 of the base address. */
11175 relocation
= (relocation
+ 2) & ~ 3;
11177 /* Put RELOCATION back into the insn. Assumes two's complement.
11178 We use the Thumb-2 encoding, which is safe even if dealing with
11179 a Thumb-1 instruction by virtue of our overflow check above. */
11180 reloc_sign
= (signed_check
< 0) ? 1 : 0;
11181 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
11182 | ((relocation
>> 12) & 0x3ff)
11183 | (reloc_sign
<< 10);
11184 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
11185 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
11186 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
11187 | ((relocation
>> 1) & 0x7ff);
11189 /* Put the relocated value back in the object file: */
11190 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
11191 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
11193 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
11197 case R_ARM_THM_JUMP19
:
11198 /* Thumb32 conditional branch instruction. */
11200 bfd_vma relocation
;
11201 bfd_boolean overflow
= FALSE
;
11202 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
11203 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
11204 bfd_signed_vma reloc_signed_max
= 0xffffe;
11205 bfd_signed_vma reloc_signed_min
= -0x100000;
11206 bfd_signed_vma signed_check
;
11207 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
11208 struct elf32_arm_stub_hash_entry
*stub_entry
;
11209 struct elf32_arm_link_hash_entry
*hash
;
11211 /* Need to refetch the addend, reconstruct the top three bits,
11212 and squish the two 11 bit pieces together. */
11213 if (globals
->use_rel
)
11215 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
11216 bfd_vma upper
= (upper_insn
& 0x003f);
11217 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
11218 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
11219 bfd_vma lower
= (lower_insn
& 0x07ff);
11223 upper
|= (!S
) << 8;
11224 upper
-= 0x0100; /* Sign extend. */
11226 addend
= (upper
<< 12) | (lower
<< 1);
11227 signed_addend
= addend
;
11230 /* Handle calls via the PLT. */
11231 if (plt_offset
!= (bfd_vma
) -1)
11233 value
= (splt
->output_section
->vma
11234 + splt
->output_offset
11236 /* Target the Thumb stub before the ARM PLT entry. */
11237 value
-= PLT_THUMB_STUB_SIZE
;
11238 *unresolved_reloc_p
= FALSE
;
11241 hash
= (struct elf32_arm_link_hash_entry
*)h
;
11243 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
11244 st_type
, &branch_type
,
11245 hash
, value
, sym_sec
,
11246 input_bfd
, sym_name
);
11247 if (stub_type
!= arm_stub_none
)
11249 stub_entry
= elf32_arm_get_stub_entry (input_section
,
11253 if (stub_entry
!= NULL
)
11255 value
= (stub_entry
->stub_offset
11256 + stub_entry
->stub_sec
->output_offset
11257 + stub_entry
->stub_sec
->output_section
->vma
);
11261 relocation
= value
+ signed_addend
;
11262 relocation
-= (input_section
->output_section
->vma
11263 + input_section
->output_offset
11265 signed_check
= (bfd_signed_vma
) relocation
;
11267 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
11270 /* Put RELOCATION back into the insn. */
11272 bfd_vma S
= (relocation
& 0x00100000) >> 20;
11273 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
11274 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
11275 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
11276 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
11278 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
11279 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
11282 /* Put the relocated value back in the object file: */
11283 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
11284 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
11286 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
11289 case R_ARM_THM_JUMP11
:
11290 case R_ARM_THM_JUMP8
:
11291 case R_ARM_THM_JUMP6
:
11292 /* Thumb B (branch) instruction). */
11294 bfd_signed_vma relocation
;
11295 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
11296 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
11297 bfd_signed_vma signed_check
;
11299 /* CZB cannot jump backward. */
11300 if (r_type
== R_ARM_THM_JUMP6
)
11301 reloc_signed_min
= 0;
11303 if (globals
->use_rel
)
11305 /* Need to refetch addend. */
11306 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
11307 if (addend
& ((howto
->src_mask
+ 1) >> 1))
11309 signed_addend
= -1;
11310 signed_addend
&= ~ howto
->src_mask
;
11311 signed_addend
|= addend
;
11314 signed_addend
= addend
;
11315 /* The value in the insn has been right shifted. We need to
11316 undo this, so that we can perform the address calculation
11317 in terms of bytes. */
11318 signed_addend
<<= howto
->rightshift
;
11320 relocation
= value
+ signed_addend
;
11322 relocation
-= (input_section
->output_section
->vma
11323 + input_section
->output_offset
11326 relocation
>>= howto
->rightshift
;
11327 signed_check
= relocation
;
11329 if (r_type
== R_ARM_THM_JUMP6
)
11330 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
11332 relocation
&= howto
->dst_mask
;
11333 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
11335 bfd_put_16 (input_bfd
, relocation
, hit_data
);
11337 /* Assumes two's complement. */
11338 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
11339 return bfd_reloc_overflow
;
11341 return bfd_reloc_ok
;
11344 case R_ARM_ALU_PCREL7_0
:
11345 case R_ARM_ALU_PCREL15_8
:
11346 case R_ARM_ALU_PCREL23_15
:
11349 bfd_vma relocation
;
11351 insn
= bfd_get_32 (input_bfd
, hit_data
);
11352 if (globals
->use_rel
)
11354 /* Extract the addend. */
11355 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
11356 signed_addend
= addend
;
11358 relocation
= value
+ signed_addend
;
11360 relocation
-= (input_section
->output_section
->vma
11361 + input_section
->output_offset
11363 insn
= (insn
& ~0xfff)
11364 | ((howto
->bitpos
<< 7) & 0xf00)
11365 | ((relocation
>> howto
->bitpos
) & 0xff);
11366 bfd_put_32 (input_bfd
, value
, hit_data
);
11368 return bfd_reloc_ok
;
11370 case R_ARM_GNU_VTINHERIT
:
11371 case R_ARM_GNU_VTENTRY
:
11372 return bfd_reloc_ok
;
11374 case R_ARM_GOTOFF32
:
11375 /* Relocation is relative to the start of the
11376 global offset table. */
11378 BFD_ASSERT (sgot
!= NULL
);
11380 return bfd_reloc_notsupported
;
11382 /* If we are addressing a Thumb function, we need to adjust the
11383 address by one, so that attempts to call the function pointer will
11384 correctly interpret it as Thumb code. */
11385 if (branch_type
== ST_BRANCH_TO_THUMB
)
11388 /* Note that sgot->output_offset is not involved in this
11389 calculation. We always want the start of .got. If we
11390 define _GLOBAL_OFFSET_TABLE in a different way, as is
11391 permitted by the ABI, we might have to change this
11393 value
-= sgot
->output_section
->vma
;
11394 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11395 contents
, rel
->r_offset
, value
,
11399 /* Use global offset table as symbol value. */
11400 BFD_ASSERT (sgot
!= NULL
);
11403 return bfd_reloc_notsupported
;
11405 *unresolved_reloc_p
= FALSE
;
11406 value
= sgot
->output_section
->vma
;
11407 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11408 contents
, rel
->r_offset
, value
,
11412 case R_ARM_GOT_PREL
:
11413 /* Relocation is to the entry for this symbol in the
11414 global offset table. */
11416 return bfd_reloc_notsupported
;
11418 if (dynreloc_st_type
== STT_GNU_IFUNC
11419 && plt_offset
!= (bfd_vma
) -1
11420 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
11422 /* We have a relocation against a locally-binding STT_GNU_IFUNC
11423 symbol, and the relocation resolves directly to the runtime
11424 target rather than to the .iplt entry. This means that any
11425 .got entry would be the same value as the .igot.plt entry,
11426 so there's no point creating both. */
11427 sgot
= globals
->root
.igotplt
;
11428 value
= sgot
->output_offset
+ gotplt_offset
;
11430 else if (h
!= NULL
)
11434 off
= h
->got
.offset
;
11435 BFD_ASSERT (off
!= (bfd_vma
) -1);
11436 if ((off
& 1) != 0)
11438 /* We have already processsed one GOT relocation against
11441 if (globals
->root
.dynamic_sections_created
11442 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
11443 *unresolved_reloc_p
= FALSE
;
11447 Elf_Internal_Rela outrel
;
11450 if (((h
->dynindx
!= -1) || globals
->fdpic_p
)
11451 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
11453 /* If the symbol doesn't resolve locally in a static
11454 object, we have an undefined reference. If the
11455 symbol doesn't resolve locally in a dynamic object,
11456 it should be resolved by the dynamic linker. */
11457 if (globals
->root
.dynamic_sections_created
)
11459 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
11460 *unresolved_reloc_p
= FALSE
;
11464 outrel
.r_addend
= 0;
11468 if (dynreloc_st_type
== STT_GNU_IFUNC
)
11469 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
11470 else if (bfd_link_pic (info
)
11471 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
11472 || h
->root
.type
!= bfd_link_hash_undefweak
))
11473 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
11474 else if (globals
->fdpic_p
)
11478 outrel
.r_addend
= dynreloc_value
;
11481 /* The GOT entry is initialized to zero by default.
11482 See if we should install a different value. */
11483 if (outrel
.r_addend
!= 0
11484 && (outrel
.r_info
== 0 || globals
->use_rel
|| isrofixup
))
11486 bfd_put_32 (output_bfd
, outrel
.r_addend
,
11487 sgot
->contents
+ off
);
11488 outrel
.r_addend
= 0;
11491 if (outrel
.r_info
!= 0 && !isrofixup
)
11493 outrel
.r_offset
= (sgot
->output_section
->vma
11494 + sgot
->output_offset
11496 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
11498 else if (isrofixup
)
11500 arm_elf_add_rofixup(output_bfd
,
11501 elf32_arm_hash_table(info
)->srofixup
,
11502 sgot
->output_section
->vma
11503 + sgot
->output_offset
+ off
);
11505 h
->got
.offset
|= 1;
11507 value
= sgot
->output_offset
+ off
;
11513 BFD_ASSERT (local_got_offsets
!= NULL
11514 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
11516 off
= local_got_offsets
[r_symndx
];
11518 /* The offset must always be a multiple of 4. We use the
11519 least significant bit to record whether we have already
11520 generated the necessary reloc. */
11521 if ((off
& 1) != 0)
11525 if (globals
->use_rel
)
11526 bfd_put_32 (output_bfd
, dynreloc_value
, sgot
->contents
+ off
);
11528 if (bfd_link_pic (info
) || dynreloc_st_type
== STT_GNU_IFUNC
)
11530 Elf_Internal_Rela outrel
;
11532 outrel
.r_addend
= addend
+ dynreloc_value
;
11533 outrel
.r_offset
= (sgot
->output_section
->vma
11534 + sgot
->output_offset
11536 if (dynreloc_st_type
== STT_GNU_IFUNC
)
11537 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
11539 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
11540 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
11542 else if (globals
->fdpic_p
)
11544 /* For FDPIC executables, we use rofixup to fix
11545 address at runtime. */
11546 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
,
11547 sgot
->output_section
->vma
+ sgot
->output_offset
11551 local_got_offsets
[r_symndx
] |= 1;
11554 value
= sgot
->output_offset
+ off
;
11556 if (r_type
!= R_ARM_GOT32
)
11557 value
+= sgot
->output_section
->vma
;
11559 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11560 contents
, rel
->r_offset
, value
,
11563 case R_ARM_TLS_LDO32
:
11564 value
= value
- dtpoff_base (info
);
11566 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11567 contents
, rel
->r_offset
, value
,
11570 case R_ARM_TLS_LDM32
:
11571 case R_ARM_TLS_LDM32_FDPIC
:
11578 off
= globals
->tls_ldm_got
.offset
;
11580 if ((off
& 1) != 0)
11584 /* If we don't know the module number, create a relocation
11586 if (bfd_link_pic (info
))
11588 Elf_Internal_Rela outrel
;
11590 if (srelgot
== NULL
)
11593 outrel
.r_addend
= 0;
11594 outrel
.r_offset
= (sgot
->output_section
->vma
11595 + sgot
->output_offset
+ off
);
11596 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
11598 if (globals
->use_rel
)
11599 bfd_put_32 (output_bfd
, outrel
.r_addend
,
11600 sgot
->contents
+ off
);
11602 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
11605 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ off
);
11607 globals
->tls_ldm_got
.offset
|= 1;
11610 if (r_type
== R_ARM_TLS_LDM32_FDPIC
)
11612 bfd_put_32(output_bfd
,
11613 globals
->root
.sgot
->output_offset
+ off
,
11614 contents
+ rel
->r_offset
);
11616 return bfd_reloc_ok
;
11620 value
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
11621 - (input_section
->output_section
->vma
11622 + input_section
->output_offset
+ rel
->r_offset
);
11624 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11625 contents
, rel
->r_offset
, value
,
11630 case R_ARM_TLS_CALL
:
11631 case R_ARM_THM_TLS_CALL
:
11632 case R_ARM_TLS_GD32
:
11633 case R_ARM_TLS_GD32_FDPIC
:
11634 case R_ARM_TLS_IE32
:
11635 case R_ARM_TLS_IE32_FDPIC
:
11636 case R_ARM_TLS_GOTDESC
:
11637 case R_ARM_TLS_DESCSEQ
:
11638 case R_ARM_THM_TLS_DESCSEQ
:
11640 bfd_vma off
, offplt
;
11644 BFD_ASSERT (sgot
!= NULL
);
11649 dyn
= globals
->root
.dynamic_sections_created
;
11650 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
11651 bfd_link_pic (info
),
11653 && (!bfd_link_pic (info
)
11654 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
11656 *unresolved_reloc_p
= FALSE
;
11659 off
= h
->got
.offset
;
11660 offplt
= elf32_arm_hash_entry (h
)->tlsdesc_got
;
11661 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
11665 BFD_ASSERT (local_got_offsets
!= NULL
);
11666 off
= local_got_offsets
[r_symndx
];
11667 offplt
= local_tlsdesc_gotents
[r_symndx
];
11668 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
11671 /* Linker relaxations happens from one of the
11672 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
11673 if (ELF32_R_TYPE(rel
->r_info
) != r_type
)
11674 tls_type
= GOT_TLS_IE
;
11676 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
11678 if ((off
& 1) != 0)
11682 bfd_boolean need_relocs
= FALSE
;
11683 Elf_Internal_Rela outrel
;
11686 /* The GOT entries have not been initialized yet. Do it
11687 now, and emit any relocations. If both an IE GOT and a
11688 GD GOT are necessary, we emit the GD first. */
11690 if ((bfd_link_pic (info
) || indx
!= 0)
11692 || (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
11693 && !resolved_to_zero
)
11694 || h
->root
.type
!= bfd_link_hash_undefweak
))
11696 need_relocs
= TRUE
;
11697 BFD_ASSERT (srelgot
!= NULL
);
11700 if (tls_type
& GOT_TLS_GDESC
)
11704 /* We should have relaxed, unless this is an undefined
11706 BFD_ASSERT ((h
&& (h
->root
.type
== bfd_link_hash_undefweak
))
11707 || bfd_link_pic (info
));
11708 BFD_ASSERT (globals
->sgotplt_jump_table_size
+ offplt
+ 8
11709 <= globals
->root
.sgotplt
->size
);
11711 outrel
.r_addend
= 0;
11712 outrel
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
11713 + globals
->root
.sgotplt
->output_offset
11715 + globals
->sgotplt_jump_table_size
);
11717 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DESC
);
11718 sreloc
= globals
->root
.srelplt
;
11719 loc
= sreloc
->contents
;
11720 loc
+= globals
->next_tls_desc_index
++ * RELOC_SIZE (globals
);
11721 BFD_ASSERT (loc
+ RELOC_SIZE (globals
)
11722 <= sreloc
->contents
+ sreloc
->size
);
11724 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
11726 /* For globals, the first word in the relocation gets
11727 the relocation index and the top bit set, or zero,
11728 if we're binding now. For locals, it gets the
11729 symbol's offset in the tls section. */
11730 bfd_put_32 (output_bfd
,
11731 !h
? value
- elf_hash_table (info
)->tls_sec
->vma
11732 : info
->flags
& DF_BIND_NOW
? 0
11733 : 0x80000000 | ELF32_R_SYM (outrel
.r_info
),
11734 globals
->root
.sgotplt
->contents
+ offplt
11735 + globals
->sgotplt_jump_table_size
);
11737 /* Second word in the relocation is always zero. */
11738 bfd_put_32 (output_bfd
, 0,
11739 globals
->root
.sgotplt
->contents
+ offplt
11740 + globals
->sgotplt_jump_table_size
+ 4);
11742 if (tls_type
& GOT_TLS_GD
)
11746 outrel
.r_addend
= 0;
11747 outrel
.r_offset
= (sgot
->output_section
->vma
11748 + sgot
->output_offset
11750 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
11752 if (globals
->use_rel
)
11753 bfd_put_32 (output_bfd
, outrel
.r_addend
,
11754 sgot
->contents
+ cur_off
);
11756 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
11759 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
11760 sgot
->contents
+ cur_off
+ 4);
11763 outrel
.r_addend
= 0;
11764 outrel
.r_info
= ELF32_R_INFO (indx
,
11765 R_ARM_TLS_DTPOFF32
);
11766 outrel
.r_offset
+= 4;
11768 if (globals
->use_rel
)
11769 bfd_put_32 (output_bfd
, outrel
.r_addend
,
11770 sgot
->contents
+ cur_off
+ 4);
11772 elf32_arm_add_dynreloc (output_bfd
, info
,
11778 /* If we are not emitting relocations for a
11779 general dynamic reference, then we must be in a
11780 static link or an executable link with the
11781 symbol binding locally. Mark it as belonging
11782 to module 1, the executable. */
11783 bfd_put_32 (output_bfd
, 1,
11784 sgot
->contents
+ cur_off
);
11785 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
11786 sgot
->contents
+ cur_off
+ 4);
11792 if (tls_type
& GOT_TLS_IE
)
11797 outrel
.r_addend
= value
- dtpoff_base (info
);
11799 outrel
.r_addend
= 0;
11800 outrel
.r_offset
= (sgot
->output_section
->vma
11801 + sgot
->output_offset
11803 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
11805 if (globals
->use_rel
)
11806 bfd_put_32 (output_bfd
, outrel
.r_addend
,
11807 sgot
->contents
+ cur_off
);
11809 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
11812 bfd_put_32 (output_bfd
, tpoff (info
, value
),
11813 sgot
->contents
+ cur_off
);
11818 h
->got
.offset
|= 1;
11820 local_got_offsets
[r_symndx
] |= 1;
11823 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
&& r_type
!= R_ARM_TLS_GD32_FDPIC
)
11825 else if (tls_type
& GOT_TLS_GDESC
)
11828 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
11829 || ELF32_R_TYPE(rel
->r_info
) == R_ARM_THM_TLS_CALL
)
11831 bfd_signed_vma offset
;
11832 /* TLS stubs are arm mode. The original symbol is a
11833 data object, so branch_type is bogus. */
11834 branch_type
= ST_BRANCH_TO_ARM
;
11835 enum elf32_arm_stub_type stub_type
11836 = arm_type_of_stub (info
, input_section
, rel
,
11837 st_type
, &branch_type
,
11838 (struct elf32_arm_link_hash_entry
*)h
,
11839 globals
->tls_trampoline
, globals
->root
.splt
,
11840 input_bfd
, sym_name
);
11842 if (stub_type
!= arm_stub_none
)
11844 struct elf32_arm_stub_hash_entry
*stub_entry
11845 = elf32_arm_get_stub_entry
11846 (input_section
, globals
->root
.splt
, 0, rel
,
11847 globals
, stub_type
);
11848 offset
= (stub_entry
->stub_offset
11849 + stub_entry
->stub_sec
->output_offset
11850 + stub_entry
->stub_sec
->output_section
->vma
);
11853 offset
= (globals
->root
.splt
->output_section
->vma
11854 + globals
->root
.splt
->output_offset
11855 + globals
->tls_trampoline
);
11857 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
)
11859 unsigned long inst
;
11861 offset
-= (input_section
->output_section
->vma
11862 + input_section
->output_offset
11863 + rel
->r_offset
+ 8);
11865 inst
= offset
>> 2;
11866 inst
&= 0x00ffffff;
11867 value
= inst
| (globals
->use_blx
? 0xfa000000 : 0xeb000000);
11871 /* Thumb blx encodes the offset in a complicated
11873 unsigned upper_insn
, lower_insn
;
11876 offset
-= (input_section
->output_section
->vma
11877 + input_section
->output_offset
11878 + rel
->r_offset
+ 4);
11880 if (stub_type
!= arm_stub_none
11881 && arm_stub_is_thumb (stub_type
))
11883 lower_insn
= 0xd000;
11887 lower_insn
= 0xc000;
11888 /* Round up the offset to a word boundary. */
11889 offset
= (offset
+ 2) & ~2;
11893 upper_insn
= (0xf000
11894 | ((offset
>> 12) & 0x3ff)
11896 lower_insn
|= (((!((offset
>> 23) & 1)) ^ neg
) << 13)
11897 | (((!((offset
>> 22) & 1)) ^ neg
) << 11)
11898 | ((offset
>> 1) & 0x7ff);
11899 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
11900 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
11901 return bfd_reloc_ok
;
11904 /* These relocations needs special care, as besides the fact
11905 they point somewhere in .gotplt, the addend must be
11906 adjusted accordingly depending on the type of instruction
11908 else if ((r_type
== R_ARM_TLS_GOTDESC
) && (tls_type
& GOT_TLS_GDESC
))
11910 unsigned long data
, insn
;
11913 data
= bfd_get_32 (input_bfd
, hit_data
);
11919 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
- data
);
11920 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
11921 insn
= (insn
<< 16)
11922 | bfd_get_16 (input_bfd
,
11923 contents
+ rel
->r_offset
- data
+ 2);
11924 if ((insn
& 0xf800c000) == 0xf000c000)
11927 else if ((insn
& 0xffffff00) == 0x4400)
11933 /* xgettext:c-format */
11934 (_("%pB(%pA+%#" PRIx64
"): "
11935 "unexpected %s instruction '%#lx' "
11936 "referenced by TLS_GOTDESC"),
11937 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
11939 return bfd_reloc_notsupported
;
11944 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- data
);
11946 switch (insn
>> 24)
11948 case 0xeb: /* bl */
11949 case 0xfa: /* blx */
11953 case 0xe0: /* add */
11959 /* xgettext:c-format */
11960 (_("%pB(%pA+%#" PRIx64
"): "
11961 "unexpected %s instruction '%#lx' "
11962 "referenced by TLS_GOTDESC"),
11963 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
11965 return bfd_reloc_notsupported
;
11969 value
+= ((globals
->root
.sgotplt
->output_section
->vma
11970 + globals
->root
.sgotplt
->output_offset
+ off
)
11971 - (input_section
->output_section
->vma
11972 + input_section
->output_offset
11974 + globals
->sgotplt_jump_table_size
);
11977 value
= ((globals
->root
.sgot
->output_section
->vma
11978 + globals
->root
.sgot
->output_offset
+ off
)
11979 - (input_section
->output_section
->vma
11980 + input_section
->output_offset
+ rel
->r_offset
));
11982 if (globals
->fdpic_p
&& (r_type
== R_ARM_TLS_GD32_FDPIC
||
11983 r_type
== R_ARM_TLS_IE32_FDPIC
))
11985 /* For FDPIC relocations, resolve to the offset of the GOT
11986 entry from the start of GOT. */
11987 bfd_put_32(output_bfd
,
11988 globals
->root
.sgot
->output_offset
+ off
,
11989 contents
+ rel
->r_offset
);
11991 return bfd_reloc_ok
;
11995 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
11996 contents
, rel
->r_offset
, value
,
12001 case R_ARM_TLS_LE32
:
12002 if (bfd_link_dll (info
))
12005 /* xgettext:c-format */
12006 (_("%pB(%pA+%#" PRIx64
"): %s relocation not permitted "
12007 "in shared object"),
12008 input_bfd
, input_section
, (uint64_t) rel
->r_offset
, howto
->name
);
12009 return bfd_reloc_notsupported
;
12012 value
= tpoff (info
, value
);
12014 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
12015 contents
, rel
->r_offset
, value
,
12019 if (globals
->fix_v4bx
)
12021 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12023 /* Ensure that we have a BX instruction. */
12024 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
12026 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
12028 /* Branch to veneer. */
12030 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
12031 glue_addr
-= input_section
->output_section
->vma
12032 + input_section
->output_offset
12033 + rel
->r_offset
+ 8;
12034 insn
= (insn
& 0xf0000000) | 0x0a000000
12035 | ((glue_addr
>> 2) & 0x00ffffff);
12039 /* Preserve Rm (lowest four bits) and the condition code
12040 (highest four bits). Other bits encode MOV PC,Rm. */
12041 insn
= (insn
& 0xf000000f) | 0x01a0f000;
12044 bfd_put_32 (input_bfd
, insn
, hit_data
);
12046 return bfd_reloc_ok
;
12048 case R_ARM_MOVW_ABS_NC
:
12049 case R_ARM_MOVT_ABS
:
12050 case R_ARM_MOVW_PREL_NC
:
12051 case R_ARM_MOVT_PREL
:
12052 /* Until we properly support segment-base-relative addressing then
12053 we assume the segment base to be zero, as for the group relocations.
12054 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
12055 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
12056 case R_ARM_MOVW_BREL_NC
:
12057 case R_ARM_MOVW_BREL
:
12058 case R_ARM_MOVT_BREL
:
12060 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12062 if (globals
->use_rel
)
12064 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
12065 signed_addend
= (addend
^ 0x8000) - 0x8000;
12068 value
+= signed_addend
;
12070 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
12071 value
-= (input_section
->output_section
->vma
12072 + input_section
->output_offset
+ rel
->r_offset
);
12074 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
12075 return bfd_reloc_overflow
;
12077 if (branch_type
== ST_BRANCH_TO_THUMB
)
12080 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
12081 || r_type
== R_ARM_MOVT_BREL
)
12084 insn
&= 0xfff0f000;
12085 insn
|= value
& 0xfff;
12086 insn
|= (value
& 0xf000) << 4;
12087 bfd_put_32 (input_bfd
, insn
, hit_data
);
12089 return bfd_reloc_ok
;
12091 case R_ARM_THM_MOVW_ABS_NC
:
12092 case R_ARM_THM_MOVT_ABS
:
12093 case R_ARM_THM_MOVW_PREL_NC
:
12094 case R_ARM_THM_MOVT_PREL
:
12095 /* Until we properly support segment-base-relative addressing then
12096 we assume the segment base to be zero, as for the above relocations.
12097 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
12098 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
12099 as R_ARM_THM_MOVT_ABS. */
12100 case R_ARM_THM_MOVW_BREL_NC
:
12101 case R_ARM_THM_MOVW_BREL
:
12102 case R_ARM_THM_MOVT_BREL
:
12106 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
12107 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
12109 if (globals
->use_rel
)
12111 addend
= ((insn
>> 4) & 0xf000)
12112 | ((insn
>> 15) & 0x0800)
12113 | ((insn
>> 4) & 0x0700)
12115 signed_addend
= (addend
^ 0x8000) - 0x8000;
12118 value
+= signed_addend
;
12120 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
12121 value
-= (input_section
->output_section
->vma
12122 + input_section
->output_offset
+ rel
->r_offset
);
12124 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
12125 return bfd_reloc_overflow
;
12127 if (branch_type
== ST_BRANCH_TO_THUMB
)
12130 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
12131 || r_type
== R_ARM_THM_MOVT_BREL
)
12134 insn
&= 0xfbf08f00;
12135 insn
|= (value
& 0xf000) << 4;
12136 insn
|= (value
& 0x0800) << 15;
12137 insn
|= (value
& 0x0700) << 4;
12138 insn
|= (value
& 0x00ff);
12140 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
12141 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
12143 return bfd_reloc_ok
;
12145 case R_ARM_ALU_PC_G0_NC
:
12146 case R_ARM_ALU_PC_G1_NC
:
12147 case R_ARM_ALU_PC_G0
:
12148 case R_ARM_ALU_PC_G1
:
12149 case R_ARM_ALU_PC_G2
:
12150 case R_ARM_ALU_SB_G0_NC
:
12151 case R_ARM_ALU_SB_G1_NC
:
12152 case R_ARM_ALU_SB_G0
:
12153 case R_ARM_ALU_SB_G1
:
12154 case R_ARM_ALU_SB_G2
:
12156 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12157 bfd_vma pc
= input_section
->output_section
->vma
12158 + input_section
->output_offset
+ rel
->r_offset
;
12159 /* sb is the origin of the *segment* containing the symbol. */
12160 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
12163 bfd_signed_vma signed_value
;
12166 /* Determine which group of bits to select. */
12169 case R_ARM_ALU_PC_G0_NC
:
12170 case R_ARM_ALU_PC_G0
:
12171 case R_ARM_ALU_SB_G0_NC
:
12172 case R_ARM_ALU_SB_G0
:
12176 case R_ARM_ALU_PC_G1_NC
:
12177 case R_ARM_ALU_PC_G1
:
12178 case R_ARM_ALU_SB_G1_NC
:
12179 case R_ARM_ALU_SB_G1
:
12183 case R_ARM_ALU_PC_G2
:
12184 case R_ARM_ALU_SB_G2
:
12192 /* If REL, extract the addend from the insn. If RELA, it will
12193 have already been fetched for us. */
12194 if (globals
->use_rel
)
12197 bfd_vma constant
= insn
& 0xff;
12198 bfd_vma rotation
= (insn
& 0xf00) >> 8;
12201 signed_addend
= constant
;
12204 /* Compensate for the fact that in the instruction, the
12205 rotation is stored in multiples of 2 bits. */
12208 /* Rotate "constant" right by "rotation" bits. */
12209 signed_addend
= (constant
>> rotation
) |
12210 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
12213 /* Determine if the instruction is an ADD or a SUB.
12214 (For REL, this determines the sign of the addend.) */
12215 negative
= identify_add_or_sub (insn
);
12219 /* xgettext:c-format */
12220 (_("%pB(%pA+%#" PRIx64
"): only ADD or SUB instructions "
12221 "are allowed for ALU group relocations"),
12222 input_bfd
, input_section
, (uint64_t) rel
->r_offset
);
12223 return bfd_reloc_overflow
;
12226 signed_addend
*= negative
;
12229 /* Compute the value (X) to go in the place. */
12230 if (r_type
== R_ARM_ALU_PC_G0_NC
12231 || r_type
== R_ARM_ALU_PC_G1_NC
12232 || r_type
== R_ARM_ALU_PC_G0
12233 || r_type
== R_ARM_ALU_PC_G1
12234 || r_type
== R_ARM_ALU_PC_G2
)
12236 signed_value
= value
- pc
+ signed_addend
;
12238 /* Section base relative. */
12239 signed_value
= value
- sb
+ signed_addend
;
12241 /* If the target symbol is a Thumb function, then set the
12242 Thumb bit in the address. */
12243 if (branch_type
== ST_BRANCH_TO_THUMB
)
12246 /* Calculate the value of the relevant G_n, in encoded
12247 constant-with-rotation format. */
12248 g_n
= calculate_group_reloc_mask (signed_value
< 0 ? - signed_value
: signed_value
,
12251 /* Check for overflow if required. */
12252 if ((r_type
== R_ARM_ALU_PC_G0
12253 || r_type
== R_ARM_ALU_PC_G1
12254 || r_type
== R_ARM_ALU_PC_G2
12255 || r_type
== R_ARM_ALU_SB_G0
12256 || r_type
== R_ARM_ALU_SB_G1
12257 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
12260 /* xgettext:c-format */
12261 (_("%pB(%pA+%#" PRIx64
"): overflow whilst "
12262 "splitting %#" PRIx64
" for group relocation %s"),
12263 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
12264 (uint64_t) (signed_value
< 0 ? -signed_value
: signed_value
),
12266 return bfd_reloc_overflow
;
12269 /* Mask out the value and the ADD/SUB part of the opcode; take care
12270 not to destroy the S bit. */
12271 insn
&= 0xff1ff000;
12273 /* Set the opcode according to whether the value to go in the
12274 place is negative. */
12275 if (signed_value
< 0)
12280 /* Encode the offset. */
12283 bfd_put_32 (input_bfd
, insn
, hit_data
);
12285 return bfd_reloc_ok
;
12287 case R_ARM_LDR_PC_G0
:
12288 case R_ARM_LDR_PC_G1
:
12289 case R_ARM_LDR_PC_G2
:
12290 case R_ARM_LDR_SB_G0
:
12291 case R_ARM_LDR_SB_G1
:
12292 case R_ARM_LDR_SB_G2
:
12294 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12295 bfd_vma pc
= input_section
->output_section
->vma
12296 + input_section
->output_offset
+ rel
->r_offset
;
12297 /* sb is the origin of the *segment* containing the symbol. */
12298 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
12300 bfd_signed_vma signed_value
;
12303 /* Determine which groups of bits to calculate. */
12306 case R_ARM_LDR_PC_G0
:
12307 case R_ARM_LDR_SB_G0
:
12311 case R_ARM_LDR_PC_G1
:
12312 case R_ARM_LDR_SB_G1
:
12316 case R_ARM_LDR_PC_G2
:
12317 case R_ARM_LDR_SB_G2
:
12325 /* If REL, extract the addend from the insn. If RELA, it will
12326 have already been fetched for us. */
12327 if (globals
->use_rel
)
12329 int negative
= (insn
& (1 << 23)) ? 1 : -1;
12330 signed_addend
= negative
* (insn
& 0xfff);
12333 /* Compute the value (X) to go in the place. */
12334 if (r_type
== R_ARM_LDR_PC_G0
12335 || r_type
== R_ARM_LDR_PC_G1
12336 || r_type
== R_ARM_LDR_PC_G2
)
12338 signed_value
= value
- pc
+ signed_addend
;
12340 /* Section base relative. */
12341 signed_value
= value
- sb
+ signed_addend
;
12343 /* Calculate the value of the relevant G_{n-1} to obtain
12344 the residual at that stage. */
12345 calculate_group_reloc_mask (signed_value
< 0 ? - signed_value
: signed_value
,
12346 group
- 1, &residual
);
12348 /* Check for overflow. */
12349 if (residual
>= 0x1000)
12352 /* xgettext:c-format */
12353 (_("%pB(%pA+%#" PRIx64
"): overflow whilst "
12354 "splitting %#" PRIx64
" for group relocation %s"),
12355 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
12356 (uint64_t) (signed_value
< 0 ? -signed_value
: signed_value
),
12358 return bfd_reloc_overflow
;
12361 /* Mask out the value and U bit. */
12362 insn
&= 0xff7ff000;
12364 /* Set the U bit if the value to go in the place is non-negative. */
12365 if (signed_value
>= 0)
12368 /* Encode the offset. */
12371 bfd_put_32 (input_bfd
, insn
, hit_data
);
12373 return bfd_reloc_ok
;
12375 case R_ARM_LDRS_PC_G0
:
12376 case R_ARM_LDRS_PC_G1
:
12377 case R_ARM_LDRS_PC_G2
:
12378 case R_ARM_LDRS_SB_G0
:
12379 case R_ARM_LDRS_SB_G1
:
12380 case R_ARM_LDRS_SB_G2
:
12382 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12383 bfd_vma pc
= input_section
->output_section
->vma
12384 + input_section
->output_offset
+ rel
->r_offset
;
12385 /* sb is the origin of the *segment* containing the symbol. */
12386 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
12388 bfd_signed_vma signed_value
;
12391 /* Determine which groups of bits to calculate. */
12394 case R_ARM_LDRS_PC_G0
:
12395 case R_ARM_LDRS_SB_G0
:
12399 case R_ARM_LDRS_PC_G1
:
12400 case R_ARM_LDRS_SB_G1
:
12404 case R_ARM_LDRS_PC_G2
:
12405 case R_ARM_LDRS_SB_G2
:
12413 /* If REL, extract the addend from the insn. If RELA, it will
12414 have already been fetched for us. */
12415 if (globals
->use_rel
)
12417 int negative
= (insn
& (1 << 23)) ? 1 : -1;
12418 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
12421 /* Compute the value (X) to go in the place. */
12422 if (r_type
== R_ARM_LDRS_PC_G0
12423 || r_type
== R_ARM_LDRS_PC_G1
12424 || r_type
== R_ARM_LDRS_PC_G2
)
12426 signed_value
= value
- pc
+ signed_addend
;
12428 /* Section base relative. */
12429 signed_value
= value
- sb
+ signed_addend
;
12431 /* Calculate the value of the relevant G_{n-1} to obtain
12432 the residual at that stage. */
12433 calculate_group_reloc_mask (signed_value
< 0 ? - signed_value
: signed_value
,
12434 group
- 1, &residual
);
12436 /* Check for overflow. */
12437 if (residual
>= 0x100)
12440 /* xgettext:c-format */
12441 (_("%pB(%pA+%#" PRIx64
"): overflow whilst "
12442 "splitting %#" PRIx64
" for group relocation %s"),
12443 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
12444 (uint64_t) (signed_value
< 0 ? -signed_value
: signed_value
),
12446 return bfd_reloc_overflow
;
12449 /* Mask out the value and U bit. */
12450 insn
&= 0xff7ff0f0;
12452 /* Set the U bit if the value to go in the place is non-negative. */
12453 if (signed_value
>= 0)
12456 /* Encode the offset. */
12457 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
12459 bfd_put_32 (input_bfd
, insn
, hit_data
);
12461 return bfd_reloc_ok
;
12463 case R_ARM_LDC_PC_G0
:
12464 case R_ARM_LDC_PC_G1
:
12465 case R_ARM_LDC_PC_G2
:
12466 case R_ARM_LDC_SB_G0
:
12467 case R_ARM_LDC_SB_G1
:
12468 case R_ARM_LDC_SB_G2
:
12470 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
12471 bfd_vma pc
= input_section
->output_section
->vma
12472 + input_section
->output_offset
+ rel
->r_offset
;
12473 /* sb is the origin of the *segment* containing the symbol. */
12474 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
12476 bfd_signed_vma signed_value
;
12479 /* Determine which groups of bits to calculate. */
12482 case R_ARM_LDC_PC_G0
:
12483 case R_ARM_LDC_SB_G0
:
12487 case R_ARM_LDC_PC_G1
:
12488 case R_ARM_LDC_SB_G1
:
12492 case R_ARM_LDC_PC_G2
:
12493 case R_ARM_LDC_SB_G2
:
12501 /* If REL, extract the addend from the insn. If RELA, it will
12502 have already been fetched for us. */
12503 if (globals
->use_rel
)
12505 int negative
= (insn
& (1 << 23)) ? 1 : -1;
12506 signed_addend
= negative
* ((insn
& 0xff) << 2);
12509 /* Compute the value (X) to go in the place. */
12510 if (r_type
== R_ARM_LDC_PC_G0
12511 || r_type
== R_ARM_LDC_PC_G1
12512 || r_type
== R_ARM_LDC_PC_G2
)
12514 signed_value
= value
- pc
+ signed_addend
;
12516 /* Section base relative. */
12517 signed_value
= value
- sb
+ signed_addend
;
12519 /* Calculate the value of the relevant G_{n-1} to obtain
12520 the residual at that stage. */
12521 calculate_group_reloc_mask (signed_value
< 0 ? - signed_value
: signed_value
,
12522 group
- 1, &residual
);
12524 /* Check for overflow. (The absolute value to go in the place must be
12525 divisible by four and, after having been divided by four, must
12526 fit in eight bits.) */
12527 if ((residual
& 0x3) != 0 || residual
>= 0x400)
12530 /* xgettext:c-format */
12531 (_("%pB(%pA+%#" PRIx64
"): overflow whilst "
12532 "splitting %#" PRIx64
" for group relocation %s"),
12533 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
12534 (uint64_t) (signed_value
< 0 ? -signed_value
: signed_value
),
12536 return bfd_reloc_overflow
;
12539 /* Mask out the value and U bit. */
12540 insn
&= 0xff7fff00;
12542 /* Set the U bit if the value to go in the place is non-negative. */
12543 if (signed_value
>= 0)
12546 /* Encode the offset. */
12547 insn
|= residual
>> 2;
12549 bfd_put_32 (input_bfd
, insn
, hit_data
);
12551 return bfd_reloc_ok
;
12553 case R_ARM_THM_ALU_ABS_G0_NC
:
12554 case R_ARM_THM_ALU_ABS_G1_NC
:
12555 case R_ARM_THM_ALU_ABS_G2_NC
:
12556 case R_ARM_THM_ALU_ABS_G3_NC
:
12558 const int shift_array
[4] = {0, 8, 16, 24};
12559 bfd_vma insn
= bfd_get_16 (input_bfd
, hit_data
);
12560 bfd_vma addr
= value
;
12561 int shift
= shift_array
[r_type
- R_ARM_THM_ALU_ABS_G0_NC
];
12563 /* Compute address. */
12564 if (globals
->use_rel
)
12565 signed_addend
= insn
& 0xff;
12566 addr
+= signed_addend
;
12567 if (branch_type
== ST_BRANCH_TO_THUMB
)
12569 /* Clean imm8 insn. */
12571 /* And update with correct part of address. */
12572 insn
|= (addr
>> shift
) & 0xff;
12574 bfd_put_16 (input_bfd
, insn
, hit_data
);
12577 *unresolved_reloc_p
= FALSE
;
12578 return bfd_reloc_ok
;
12580 case R_ARM_GOTOFFFUNCDESC
:
12584 struct fdpic_local
*local_fdpic_cnts
= elf32_arm_local_fdpic_cnts(input_bfd
);
12585 int dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
12586 int offset
= local_fdpic_cnts
[r_symndx
].funcdesc_offset
& ~1;
12587 bfd_vma addr
= dynreloc_value
- sym_sec
->output_section
->vma
;
12590 if (bfd_link_pic(info
) && dynindx
== 0)
12593 /* Resolve relocation. */
12594 bfd_put_32(output_bfd
, (offset
+ sgot
->output_offset
)
12595 , contents
+ rel
->r_offset
);
12596 /* Emit R_ARM_FUNCDESC_VALUE or two fixups on funcdesc if
12598 arm_elf_fill_funcdesc(output_bfd
, info
,
12599 &local_fdpic_cnts
[r_symndx
].funcdesc_offset
,
12600 dynindx
, offset
, addr
, dynreloc_value
, seg
);
12605 int offset
= eh
->fdpic_cnts
.funcdesc_offset
& ~1;
12609 /* For static binaries, sym_sec can be null. */
12612 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
12613 addr
= dynreloc_value
- sym_sec
->output_section
->vma
;
12621 if (bfd_link_pic(info
) && dynindx
== 0)
12624 /* This case cannot occur since funcdesc is allocated by
12625 the dynamic loader so we cannot resolve the relocation. */
12626 if (h
->dynindx
!= -1)
12629 /* Resolve relocation. */
12630 bfd_put_32(output_bfd
, (offset
+ sgot
->output_offset
),
12631 contents
+ rel
->r_offset
);
12632 /* Emit R_ARM_FUNCDESC_VALUE on funcdesc if not done yet. */
12633 arm_elf_fill_funcdesc(output_bfd
, info
,
12634 &eh
->fdpic_cnts
.funcdesc_offset
,
12635 dynindx
, offset
, addr
, dynreloc_value
, seg
);
12638 *unresolved_reloc_p
= FALSE
;
12639 return bfd_reloc_ok
;
12641 case R_ARM_GOTFUNCDESC
:
12645 Elf_Internal_Rela outrel
;
12647 /* Resolve relocation. */
12648 bfd_put_32(output_bfd
, ((eh
->fdpic_cnts
.gotfuncdesc_offset
& ~1)
12649 + sgot
->output_offset
),
12650 contents
+ rel
->r_offset
);
12651 /* Add funcdesc and associated R_ARM_FUNCDESC_VALUE. */
12652 if(h
->dynindx
== -1)
12655 int offset
= eh
->fdpic_cnts
.funcdesc_offset
& ~1;
12659 /* For static binaries sym_sec can be null. */
12662 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
12663 addr
= dynreloc_value
- sym_sec
->output_section
->vma
;
12671 /* Emit R_ARM_FUNCDESC_VALUE on funcdesc if not done yet. */
12672 arm_elf_fill_funcdesc(output_bfd
, info
,
12673 &eh
->fdpic_cnts
.funcdesc_offset
,
12674 dynindx
, offset
, addr
, dynreloc_value
, seg
);
12677 /* Add a dynamic relocation on GOT entry if not already done. */
12678 if ((eh
->fdpic_cnts
.gotfuncdesc_offset
& 1) == 0)
12680 if (h
->dynindx
== -1)
12682 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
12683 if (h
->root
.type
== bfd_link_hash_undefweak
)
12684 bfd_put_32(output_bfd
, 0, sgot
->contents
12685 + (eh
->fdpic_cnts
.gotfuncdesc_offset
& ~1));
12687 bfd_put_32(output_bfd
, sgot
->output_section
->vma
12688 + sgot
->output_offset
12689 + (eh
->fdpic_cnts
.funcdesc_offset
& ~1),
12691 + (eh
->fdpic_cnts
.gotfuncdesc_offset
& ~1));
12695 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_FUNCDESC
);
12697 outrel
.r_offset
= sgot
->output_section
->vma
12698 + sgot
->output_offset
12699 + (eh
->fdpic_cnts
.gotfuncdesc_offset
& ~1);
12700 outrel
.r_addend
= 0;
12701 if (h
->dynindx
== -1 && !bfd_link_pic(info
))
12702 if (h
->root
.type
== bfd_link_hash_undefweak
)
12703 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
, -1);
12705 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
, outrel
.r_offset
);
12707 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
12708 eh
->fdpic_cnts
.gotfuncdesc_offset
|= 1;
12713 /* Such relocation on static function should not have been
12714 emitted by the compiler. */
12718 *unresolved_reloc_p
= FALSE
;
12719 return bfd_reloc_ok
;
12721 case R_ARM_FUNCDESC
:
12725 struct fdpic_local
*local_fdpic_cnts
= elf32_arm_local_fdpic_cnts(input_bfd
);
12726 Elf_Internal_Rela outrel
;
12727 int dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
12728 int offset
= local_fdpic_cnts
[r_symndx
].funcdesc_offset
& ~1;
12729 bfd_vma addr
= dynreloc_value
- sym_sec
->output_section
->vma
;
12732 if (bfd_link_pic(info
) && dynindx
== 0)
12735 /* Replace static FUNCDESC relocation with a
12736 R_ARM_RELATIVE dynamic relocation or with a rofixup for
12738 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
12739 outrel
.r_offset
= input_section
->output_section
->vma
12740 + input_section
->output_offset
+ rel
->r_offset
;
12741 outrel
.r_addend
= 0;
12742 if (bfd_link_pic(info
))
12743 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
12745 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
, outrel
.r_offset
);
12747 bfd_put_32 (input_bfd
, sgot
->output_section
->vma
12748 + sgot
->output_offset
+ offset
, hit_data
);
12750 /* Emit R_ARM_FUNCDESC_VALUE on funcdesc if not done yet. */
12751 arm_elf_fill_funcdesc(output_bfd
, info
,
12752 &local_fdpic_cnts
[r_symndx
].funcdesc_offset
,
12753 dynindx
, offset
, addr
, dynreloc_value
, seg
);
12757 if (h
->dynindx
== -1)
12760 int offset
= eh
->fdpic_cnts
.funcdesc_offset
& ~1;
12763 Elf_Internal_Rela outrel
;
12765 /* For static binaries sym_sec can be null. */
12768 dynindx
= elf_section_data (sym_sec
->output_section
)->dynindx
;
12769 addr
= dynreloc_value
- sym_sec
->output_section
->vma
;
12777 if (bfd_link_pic(info
) && dynindx
== 0)
12780 /* Replace static FUNCDESC relocation with a
12781 R_ARM_RELATIVE dynamic relocation. */
12782 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
12783 outrel
.r_offset
= input_section
->output_section
->vma
12784 + input_section
->output_offset
+ rel
->r_offset
;
12785 outrel
.r_addend
= 0;
12786 if (bfd_link_pic(info
))
12787 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
12789 arm_elf_add_rofixup(output_bfd
, globals
->srofixup
, outrel
.r_offset
);
12791 bfd_put_32 (input_bfd
, sgot
->output_section
->vma
12792 + sgot
->output_offset
+ offset
, hit_data
);
12794 /* Emit R_ARM_FUNCDESC_VALUE on funcdesc if not done yet. */
12795 arm_elf_fill_funcdesc(output_bfd
, info
,
12796 &eh
->fdpic_cnts
.funcdesc_offset
,
12797 dynindx
, offset
, addr
, dynreloc_value
, seg
);
12801 Elf_Internal_Rela outrel
;
12803 /* Add a dynamic relocation. */
12804 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_FUNCDESC
);
12805 outrel
.r_offset
= input_section
->output_section
->vma
12806 + input_section
->output_offset
+ rel
->r_offset
;
12807 outrel
.r_addend
= 0;
12808 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
12812 *unresolved_reloc_p
= FALSE
;
12813 return bfd_reloc_ok
;
12816 return bfd_reloc_notsupported
;
12820 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
12822 arm_add_to_rel (bfd
* abfd
,
12823 bfd_byte
* address
,
12824 reloc_howto_type
* howto
,
12825 bfd_signed_vma increment
)
12827 bfd_signed_vma addend
;
12829 if (howto
->type
== R_ARM_THM_CALL
12830 || howto
->type
== R_ARM_THM_JUMP24
)
12832 int upper_insn
, lower_insn
;
12835 upper_insn
= bfd_get_16 (abfd
, address
);
12836 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
12837 upper
= upper_insn
& 0x7ff;
12838 lower
= lower_insn
& 0x7ff;
12840 addend
= (upper
<< 12) | (lower
<< 1);
12841 addend
+= increment
;
12844 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
12845 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
12847 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
12848 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
12854 contents
= bfd_get_32 (abfd
, address
);
12856 /* Get the (signed) value from the instruction. */
12857 addend
= contents
& howto
->src_mask
;
12858 if (addend
& ((howto
->src_mask
+ 1) >> 1))
12860 bfd_signed_vma mask
;
12863 mask
&= ~ howto
->src_mask
;
12867 /* Add in the increment, (which is a byte value). */
12868 switch (howto
->type
)
12871 addend
+= increment
;
12878 addend
<<= howto
->size
;
12879 addend
+= increment
;
12881 /* Should we check for overflow here ? */
12883 /* Drop any undesired bits. */
12884 addend
>>= howto
->rightshift
;
12888 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
12890 bfd_put_32 (abfd
, contents
, address
);
12894 #define IS_ARM_TLS_RELOC(R_TYPE) \
12895 ((R_TYPE) == R_ARM_TLS_GD32 \
12896 || (R_TYPE) == R_ARM_TLS_GD32_FDPIC \
12897 || (R_TYPE) == R_ARM_TLS_LDO32 \
12898 || (R_TYPE) == R_ARM_TLS_LDM32 \
12899 || (R_TYPE) == R_ARM_TLS_LDM32_FDPIC \
12900 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
12901 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
12902 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
12903 || (R_TYPE) == R_ARM_TLS_LE32 \
12904 || (R_TYPE) == R_ARM_TLS_IE32 \
12905 || (R_TYPE) == R_ARM_TLS_IE32_FDPIC \
12906 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
12908 /* Specific set of relocations for the gnu tls dialect. */
12909 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
12910 ((R_TYPE) == R_ARM_TLS_GOTDESC \
12911 || (R_TYPE) == R_ARM_TLS_CALL \
12912 || (R_TYPE) == R_ARM_THM_TLS_CALL \
12913 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
12914 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
12916 /* Relocate an ARM ELF section. */
12919 elf32_arm_relocate_section (bfd
* output_bfd
,
12920 struct bfd_link_info
* info
,
12922 asection
* input_section
,
12923 bfd_byte
* contents
,
12924 Elf_Internal_Rela
* relocs
,
12925 Elf_Internal_Sym
* local_syms
,
12926 asection
** local_sections
)
12928 Elf_Internal_Shdr
*symtab_hdr
;
12929 struct elf_link_hash_entry
**sym_hashes
;
12930 Elf_Internal_Rela
*rel
;
12931 Elf_Internal_Rela
*relend
;
12933 struct elf32_arm_link_hash_table
* globals
;
12935 globals
= elf32_arm_hash_table (info
);
12936 if (globals
== NULL
)
12939 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
12940 sym_hashes
= elf_sym_hashes (input_bfd
);
12943 relend
= relocs
+ input_section
->reloc_count
;
12944 for (; rel
< relend
; rel
++)
12947 reloc_howto_type
* howto
;
12948 unsigned long r_symndx
;
12949 Elf_Internal_Sym
* sym
;
12951 struct elf_link_hash_entry
* h
;
12952 bfd_vma relocation
;
12953 bfd_reloc_status_type r
;
12956 bfd_boolean unresolved_reloc
= FALSE
;
12957 char *error_message
= NULL
;
12959 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12960 r_type
= ELF32_R_TYPE (rel
->r_info
);
12961 r_type
= arm_real_reloc_type (globals
, r_type
);
12963 if ( r_type
== R_ARM_GNU_VTENTRY
12964 || r_type
== R_ARM_GNU_VTINHERIT
)
12967 howto
= bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
12970 return _bfd_unrecognized_reloc (input_bfd
, input_section
, r_type
);
12976 if (r_symndx
< symtab_hdr
->sh_info
)
12978 sym
= local_syms
+ r_symndx
;
12979 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
12980 sec
= local_sections
[r_symndx
];
12982 /* An object file might have a reference to a local
12983 undefined symbol. This is a daft object file, but we
12984 should at least do something about it. V4BX & NONE
12985 relocations do not use the symbol and are explicitly
12986 allowed to use the undefined symbol, so allow those.
12987 Likewise for relocations against STN_UNDEF. */
12988 if (r_type
!= R_ARM_V4BX
12989 && r_type
!= R_ARM_NONE
12990 && r_symndx
!= STN_UNDEF
12991 && bfd_is_und_section (sec
)
12992 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
12993 (*info
->callbacks
->undefined_symbol
)
12994 (info
, bfd_elf_string_from_elf_section
12995 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
12996 input_bfd
, input_section
,
12997 rel
->r_offset
, TRUE
);
12999 if (globals
->use_rel
)
13001 relocation
= (sec
->output_section
->vma
13002 + sec
->output_offset
13004 if (!bfd_link_relocatable (info
)
13005 && (sec
->flags
& SEC_MERGE
)
13006 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13009 bfd_vma addend
, value
;
13013 case R_ARM_MOVW_ABS_NC
:
13014 case R_ARM_MOVT_ABS
:
13015 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13016 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
13017 addend
= (addend
^ 0x8000) - 0x8000;
13020 case R_ARM_THM_MOVW_ABS_NC
:
13021 case R_ARM_THM_MOVT_ABS
:
13022 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
13024 value
|= bfd_get_16 (input_bfd
,
13025 contents
+ rel
->r_offset
+ 2);
13026 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
13027 | ((value
& 0x04000000) >> 15);
13028 addend
= (addend
^ 0x8000) - 0x8000;
13032 if (howto
->rightshift
13033 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
13036 /* xgettext:c-format */
13037 (_("%pB(%pA+%#" PRIx64
"): "
13038 "%s relocation against SEC_MERGE section"),
13039 input_bfd
, input_section
,
13040 (uint64_t) rel
->r_offset
, howto
->name
);
13044 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13046 /* Get the (signed) value from the instruction. */
13047 addend
= value
& howto
->src_mask
;
13048 if (addend
& ((howto
->src_mask
+ 1) >> 1))
13050 bfd_signed_vma mask
;
13053 mask
&= ~ howto
->src_mask
;
13061 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
13063 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
13065 /* Cases here must match those in the preceding
13066 switch statement. */
13069 case R_ARM_MOVW_ABS_NC
:
13070 case R_ARM_MOVT_ABS
:
13071 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
13072 | (addend
& 0xfff);
13073 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
13076 case R_ARM_THM_MOVW_ABS_NC
:
13077 case R_ARM_THM_MOVT_ABS
:
13078 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
13079 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
13080 bfd_put_16 (input_bfd
, value
>> 16,
13081 contents
+ rel
->r_offset
);
13082 bfd_put_16 (input_bfd
, value
,
13083 contents
+ rel
->r_offset
+ 2);
13087 value
= (value
& ~ howto
->dst_mask
)
13088 | (addend
& howto
->dst_mask
);
13089 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
13095 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13099 bfd_boolean warned
, ignored
;
13101 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13102 r_symndx
, symtab_hdr
, sym_hashes
,
13103 h
, sec
, relocation
,
13104 unresolved_reloc
, warned
, ignored
);
13106 sym_type
= h
->type
;
13109 if (sec
!= NULL
&& discarded_section (sec
))
13110 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
13111 rel
, 1, relend
, howto
, 0, contents
);
13113 if (bfd_link_relocatable (info
))
13115 /* This is a relocatable link. We don't have to change
13116 anything, unless the reloc is against a section symbol,
13117 in which case we have to adjust according to where the
13118 section symbol winds up in the output section. */
13119 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13121 if (globals
->use_rel
)
13122 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
13123 howto
, (bfd_signed_vma
) sec
->output_offset
);
13125 rel
->r_addend
+= sec
->output_offset
;
13131 name
= h
->root
.root
.string
;
13134 name
= (bfd_elf_string_from_elf_section
13135 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
13136 if (name
== NULL
|| *name
== '\0')
13137 name
= bfd_section_name (input_bfd
, sec
);
13140 if (r_symndx
!= STN_UNDEF
13141 && r_type
!= R_ARM_NONE
13143 || h
->root
.type
== bfd_link_hash_defined
13144 || h
->root
.type
== bfd_link_hash_defweak
)
13145 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
13148 ((sym_type
== STT_TLS
13149 /* xgettext:c-format */
13150 ? _("%pB(%pA+%#" PRIx64
"): %s used with TLS symbol %s")
13151 /* xgettext:c-format */
13152 : _("%pB(%pA+%#" PRIx64
"): %s used with non-TLS symbol %s")),
13155 (uint64_t) rel
->r_offset
,
13160 /* We call elf32_arm_final_link_relocate unless we're completely
13161 done, i.e., the relaxation produced the final output we want,
13162 and we won't let anybody mess with it. Also, we have to do
13163 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
13164 both in relaxed and non-relaxed cases. */
13165 if ((elf32_arm_tls_transition (info
, r_type
, h
) != (unsigned)r_type
)
13166 || (IS_ARM_TLS_GNU_RELOC (r_type
)
13167 && !((h
? elf32_arm_hash_entry (h
)->tls_type
:
13168 elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
])
13171 r
= elf32_arm_tls_relax (globals
, input_bfd
, input_section
,
13172 contents
, rel
, h
== NULL
);
13173 /* This may have been marked unresolved because it came from
13174 a shared library. But we've just dealt with that. */
13175 unresolved_reloc
= 0;
13178 r
= bfd_reloc_continue
;
13180 if (r
== bfd_reloc_continue
)
13182 unsigned char branch_type
=
13183 h
? ARM_GET_SYM_BRANCH_TYPE (h
->target_internal
)
13184 : ARM_GET_SYM_BRANCH_TYPE (sym
->st_target_internal
);
13186 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
13187 input_section
, contents
, rel
,
13188 relocation
, info
, sec
, name
,
13189 sym_type
, branch_type
, h
,
13194 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
13195 because such sections are not SEC_ALLOC and thus ld.so will
13196 not process them. */
13197 if (unresolved_reloc
13198 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
13200 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
13201 rel
->r_offset
) != (bfd_vma
) -1)
13204 /* xgettext:c-format */
13205 (_("%pB(%pA+%#" PRIx64
"): "
13206 "unresolvable %s relocation against symbol `%s'"),
13209 (uint64_t) rel
->r_offset
,
13211 h
->root
.root
.string
);
13215 if (r
!= bfd_reloc_ok
)
13219 case bfd_reloc_overflow
:
13220 /* If the overflowing reloc was to an undefined symbol,
13221 we have already printed one error message and there
13222 is no point complaining again. */
13223 if (!h
|| h
->root
.type
!= bfd_link_hash_undefined
)
13224 (*info
->callbacks
->reloc_overflow
)
13225 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
13226 (bfd_vma
) 0, input_bfd
, input_section
, rel
->r_offset
);
13229 case bfd_reloc_undefined
:
13230 (*info
->callbacks
->undefined_symbol
)
13231 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
);
13234 case bfd_reloc_outofrange
:
13235 error_message
= _("out of range");
13238 case bfd_reloc_notsupported
:
13239 error_message
= _("unsupported relocation");
13242 case bfd_reloc_dangerous
:
13243 /* error_message should already be set. */
13247 error_message
= _("unknown error");
13248 /* Fall through. */
13251 BFD_ASSERT (error_message
!= NULL
);
13252 (*info
->callbacks
->reloc_dangerous
)
13253 (info
, error_message
, input_bfd
, input_section
, rel
->r_offset
);
13262 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
13263 adds the edit to the start of the list. (The list must be built in order of
13264 ascending TINDEX: the function's callers are primarily responsible for
13265 maintaining that condition). */
13268 add_unwind_table_edit (arm_unwind_table_edit
**head
,
13269 arm_unwind_table_edit
**tail
,
13270 arm_unwind_edit_type type
,
13271 asection
*linked_section
,
13272 unsigned int tindex
)
13274 arm_unwind_table_edit
*new_edit
= (arm_unwind_table_edit
*)
13275 xmalloc (sizeof (arm_unwind_table_edit
));
13277 new_edit
->type
= type
;
13278 new_edit
->linked_section
= linked_section
;
13279 new_edit
->index
= tindex
;
13283 new_edit
->next
= NULL
;
13286 (*tail
)->next
= new_edit
;
13288 (*tail
) = new_edit
;
13291 (*head
) = new_edit
;
13295 new_edit
->next
= *head
;
13304 static _arm_elf_section_data
*get_arm_elf_section_data (asection
*);
13306 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
13308 adjust_exidx_size(asection
*exidx_sec
, int adjust
)
13312 if (!exidx_sec
->rawsize
)
13313 exidx_sec
->rawsize
= exidx_sec
->size
;
13315 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
13316 out_sec
= exidx_sec
->output_section
;
13317 /* Adjust size of output section. */
13318 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
13321 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
13323 insert_cantunwind_after(asection
*text_sec
, asection
*exidx_sec
)
13325 struct _arm_elf_section_data
*exidx_arm_data
;
13327 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
13328 add_unwind_table_edit (
13329 &exidx_arm_data
->u
.exidx
.unwind_edit_list
,
13330 &exidx_arm_data
->u
.exidx
.unwind_edit_tail
,
13331 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
13333 exidx_arm_data
->additional_reloc_count
++;
13335 adjust_exidx_size(exidx_sec
, 8);
13338 /* Scan .ARM.exidx tables, and create a list describing edits which should be
13339 made to those tables, such that:
13341 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
13342 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
13343 codes which have been inlined into the index).
13345 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
13347 The edits are applied when the tables are written
13348 (in elf32_arm_write_section). */
13351 elf32_arm_fix_exidx_coverage (asection
**text_section_order
,
13352 unsigned int num_text_sections
,
13353 struct bfd_link_info
*info
,
13354 bfd_boolean merge_exidx_entries
)
13357 unsigned int last_second_word
= 0, i
;
13358 asection
*last_exidx_sec
= NULL
;
13359 asection
*last_text_sec
= NULL
;
13360 int last_unwind_type
= -1;
13362 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
13364 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
13368 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
13370 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
13371 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
13373 if (!hdr
|| hdr
->sh_type
!= SHT_ARM_EXIDX
)
13376 if (elf_sec
->linked_to
)
13378 Elf_Internal_Shdr
*linked_hdr
13379 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
13380 struct _arm_elf_section_data
*linked_sec_arm_data
13381 = get_arm_elf_section_data (linked_hdr
->bfd_section
);
13383 if (linked_sec_arm_data
== NULL
)
13386 /* Link this .ARM.exidx section back from the text section it
13388 linked_sec_arm_data
->u
.text
.arm_exidx_sec
= sec
;
13393 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
13394 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
13395 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
13397 for (i
= 0; i
< num_text_sections
; i
++)
13399 asection
*sec
= text_section_order
[i
];
13400 asection
*exidx_sec
;
13401 struct _arm_elf_section_data
*arm_data
= get_arm_elf_section_data (sec
);
13402 struct _arm_elf_section_data
*exidx_arm_data
;
13403 bfd_byte
*contents
= NULL
;
13404 int deleted_exidx_bytes
= 0;
13406 arm_unwind_table_edit
*unwind_edit_head
= NULL
;
13407 arm_unwind_table_edit
*unwind_edit_tail
= NULL
;
13408 Elf_Internal_Shdr
*hdr
;
13411 if (arm_data
== NULL
)
13414 exidx_sec
= arm_data
->u
.text
.arm_exidx_sec
;
13415 if (exidx_sec
== NULL
)
13417 /* Section has no unwind data. */
13418 if (last_unwind_type
== 0 || !last_exidx_sec
)
13421 /* Ignore zero sized sections. */
13422 if (sec
->size
== 0)
13425 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
13426 last_unwind_type
= 0;
13430 /* Skip /DISCARD/ sections. */
13431 if (bfd_is_abs_section (exidx_sec
->output_section
))
13434 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
13435 if (hdr
->sh_type
!= SHT_ARM_EXIDX
)
13438 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
13439 if (exidx_arm_data
== NULL
)
13442 ibfd
= exidx_sec
->owner
;
13444 if (hdr
->contents
!= NULL
)
13445 contents
= hdr
->contents
;
13446 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
13450 if (last_unwind_type
> 0)
13452 unsigned int first_word
= bfd_get_32 (ibfd
, contents
);
13453 /* Add cantunwind if first unwind item does not match section
13455 if (first_word
!= sec
->vma
)
13457 insert_cantunwind_after (last_text_sec
, last_exidx_sec
);
13458 last_unwind_type
= 0;
13462 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
13464 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
13468 /* An EXIDX_CANTUNWIND entry. */
13469 if (second_word
== 1)
13471 if (last_unwind_type
== 0)
13475 /* Inlined unwinding data. Merge if equal to previous. */
13476 else if ((second_word
& 0x80000000) != 0)
13478 if (merge_exidx_entries
13479 && last_second_word
== second_word
&& last_unwind_type
== 1)
13482 last_second_word
= second_word
;
13484 /* Normal table entry. In theory we could merge these too,
13485 but duplicate entries are likely to be much less common. */
13489 if (elide
&& !bfd_link_relocatable (info
))
13491 add_unwind_table_edit (&unwind_edit_head
, &unwind_edit_tail
,
13492 DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
13494 deleted_exidx_bytes
+= 8;
13497 last_unwind_type
= unwind_type
;
13500 /* Free contents if we allocated it ourselves. */
13501 if (contents
!= hdr
->contents
)
13504 /* Record edits to be applied later (in elf32_arm_write_section). */
13505 exidx_arm_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
13506 exidx_arm_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
13508 if (deleted_exidx_bytes
> 0)
13509 adjust_exidx_size(exidx_sec
, -deleted_exidx_bytes
);
13511 last_exidx_sec
= exidx_sec
;
13512 last_text_sec
= sec
;
13515 /* Add terminating CANTUNWIND entry. */
13516 if (!bfd_link_relocatable (info
) && last_exidx_sec
13517 && last_unwind_type
!= 0)
13518 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
13524 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
13525 bfd
*ibfd
, const char *name
)
13527 asection
*sec
, *osec
;
13529 sec
= bfd_get_linker_section (ibfd
, name
);
13530 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
13533 osec
= sec
->output_section
;
13534 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
13537 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
13538 sec
->output_offset
, sec
->size
))
13545 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
13547 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
13548 asection
*sec
, *osec
;
13550 if (globals
== NULL
)
13553 /* Invoke the regular ELF backend linker to do all the work. */
13554 if (!bfd_elf_final_link (abfd
, info
))
13557 /* Process stub sections (eg BE8 encoding, ...). */
13558 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
13560 for (i
=0; i
<htab
->top_id
; i
++)
13562 sec
= htab
->stub_group
[i
].stub_sec
;
13563 /* Only process it once, in its link_sec slot. */
13564 if (sec
&& i
== htab
->stub_group
[i
].link_sec
->id
)
13566 osec
= sec
->output_section
;
13567 elf32_arm_write_section (abfd
, info
, sec
, sec
->contents
);
13568 if (! bfd_set_section_contents (abfd
, osec
, sec
->contents
,
13569 sec
->output_offset
, sec
->size
))
13574 /* Write out any glue sections now that we have created all the
13576 if (globals
->bfd_of_glue_owner
!= NULL
)
13578 if (! elf32_arm_output_glue_section (info
, abfd
,
13579 globals
->bfd_of_glue_owner
,
13580 ARM2THUMB_GLUE_SECTION_NAME
))
13583 if (! elf32_arm_output_glue_section (info
, abfd
,
13584 globals
->bfd_of_glue_owner
,
13585 THUMB2ARM_GLUE_SECTION_NAME
))
13588 if (! elf32_arm_output_glue_section (info
, abfd
,
13589 globals
->bfd_of_glue_owner
,
13590 VFP11_ERRATUM_VENEER_SECTION_NAME
))
13593 if (! elf32_arm_output_glue_section (info
, abfd
,
13594 globals
->bfd_of_glue_owner
,
13595 STM32L4XX_ERRATUM_VENEER_SECTION_NAME
))
13598 if (! elf32_arm_output_glue_section (info
, abfd
,
13599 globals
->bfd_of_glue_owner
,
13600 ARM_BX_GLUE_SECTION_NAME
))
13607 /* Return a best guess for the machine number based on the attributes. */
13609 static unsigned int
13610 bfd_arm_get_mach_from_attributes (bfd
* abfd
)
13612 int arch
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
13616 case TAG_CPU_ARCH_V4
: return bfd_mach_arm_4
;
13617 case TAG_CPU_ARCH_V4T
: return bfd_mach_arm_4T
;
13618 case TAG_CPU_ARCH_V5T
: return bfd_mach_arm_5T
;
13620 case TAG_CPU_ARCH_V5TE
:
13624 BFD_ASSERT (Tag_CPU_name
< NUM_KNOWN_OBJ_ATTRIBUTES
);
13625 name
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_CPU_name
].s
;
13629 if (strcmp (name
, "IWMMXT2") == 0)
13630 return bfd_mach_arm_iWMMXt2
;
13632 if (strcmp (name
, "IWMMXT") == 0)
13633 return bfd_mach_arm_iWMMXt
;
13635 if (strcmp (name
, "XSCALE") == 0)
13639 BFD_ASSERT (Tag_WMMX_arch
< NUM_KNOWN_OBJ_ATTRIBUTES
);
13640 wmmx
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_WMMX_arch
].i
;
13643 case 1: return bfd_mach_arm_iWMMXt
;
13644 case 2: return bfd_mach_arm_iWMMXt2
;
13645 default: return bfd_mach_arm_XScale
;
13650 return bfd_mach_arm_5TE
;
13654 return bfd_mach_arm_unknown
;
13658 /* Set the right machine number. */
13661 elf32_arm_object_p (bfd
*abfd
)
13665 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
13667 if (mach
== bfd_mach_arm_unknown
)
13669 if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
13670 mach
= bfd_mach_arm_ep9312
;
13672 mach
= bfd_arm_get_mach_from_attributes (abfd
);
13675 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
13679 /* Function to keep ARM specific flags in the ELF header. */
13682 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
13684 if (elf_flags_init (abfd
)
13685 && elf_elfheader (abfd
)->e_flags
!= flags
)
13687 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
13689 if (flags
& EF_ARM_INTERWORK
)
13691 (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
13695 (_("warning: clearing the interworking flag of %pB due to outside request"),
13701 elf_elfheader (abfd
)->e_flags
= flags
;
13702 elf_flags_init (abfd
) = TRUE
;
13708 /* Copy backend specific data from one object module to another. */
13711 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
13714 flagword out_flags
;
13716 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
13719 in_flags
= elf_elfheader (ibfd
)->e_flags
;
13720 out_flags
= elf_elfheader (obfd
)->e_flags
;
13722 if (elf_flags_init (obfd
)
13723 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
13724 && in_flags
!= out_flags
)
13726 /* Cannot mix APCS26 and APCS32 code. */
13727 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
13730 /* Cannot mix float APCS and non-float APCS code. */
13731 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
13734 /* If the src and dest have different interworking flags
13735 then turn off the interworking bit. */
13736 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
13738 if (out_flags
& EF_ARM_INTERWORK
)
13740 (_("warning: clearing the interworking flag of %pB because non-interworking code in %pB has been linked with it"),
13743 in_flags
&= ~EF_ARM_INTERWORK
;
13746 /* Likewise for PIC, though don't warn for this case. */
13747 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
13748 in_flags
&= ~EF_ARM_PIC
;
13751 elf_elfheader (obfd
)->e_flags
= in_flags
;
13752 elf_flags_init (obfd
) = TRUE
;
13754 return _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
13757 /* Values for Tag_ABI_PCS_R9_use. */
13766 /* Values for Tag_ABI_PCS_RW_data. */
13769 AEABI_PCS_RW_data_absolute
,
13770 AEABI_PCS_RW_data_PCrel
,
13771 AEABI_PCS_RW_data_SBrel
,
13772 AEABI_PCS_RW_data_unused
13775 /* Values for Tag_ABI_enum_size. */
13781 AEABI_enum_forced_wide
13784 /* Determine whether an object attribute tag takes an integer, a
13788 elf32_arm_obj_attrs_arg_type (int tag
)
13790 if (tag
== Tag_compatibility
)
13791 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
13792 else if (tag
== Tag_nodefaults
)
13793 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
13794 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
13795 return ATTR_TYPE_FLAG_STR_VAL
;
13797 return ATTR_TYPE_FLAG_INT_VAL
;
13799 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
13802 /* The ABI defines that Tag_conformance should be emitted first, and that
13803 Tag_nodefaults should be second (if either is defined). This sets those
13804 two positions, and bumps up the position of all the remaining tags to
13807 elf32_arm_obj_attrs_order (int num
)
13809 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
13810 return Tag_conformance
;
13811 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
+ 1)
13812 return Tag_nodefaults
;
13813 if ((num
- 2) < Tag_nodefaults
)
13815 if ((num
- 1) < Tag_conformance
)
13820 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
13822 elf32_arm_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
13824 if ((tag
& 127) < 64)
13827 (_("%pB: unknown mandatory EABI object attribute %d"),
13829 bfd_set_error (bfd_error_bad_value
);
13835 (_("warning: %pB: unknown EABI object attribute %d"),
13841 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
13842 Returns -1 if no architecture could be read. */
13845 get_secondary_compatible_arch (bfd
*abfd
)
13847 obj_attribute
*attr
=
13848 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
13850 /* Note: the tag and its argument below are uleb128 values, though
13851 currently-defined values fit in one byte for each. */
13853 && attr
->s
[0] == Tag_CPU_arch
13854 && (attr
->s
[1] & 128) != 128
13855 && attr
->s
[2] == 0)
13858 /* This tag is "safely ignorable", so don't complain if it looks funny. */
13862 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
13863 The tag is removed if ARCH is -1. */
13866 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
13868 obj_attribute
*attr
=
13869 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
13877 /* Note: the tag and its argument below are uleb128 values, though
13878 currently-defined values fit in one byte for each. */
13880 attr
->s
= (char *) bfd_alloc (abfd
, 3);
13881 attr
->s
[0] = Tag_CPU_arch
;
13886 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
13890 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
13891 int newtag
, int secondary_compat
)
13893 #define T(X) TAG_CPU_ARCH_##X
13894 int tagl
, tagh
, result
;
13897 T(V6T2
), /* PRE_V4. */
13899 T(V6T2
), /* V4T. */
13900 T(V6T2
), /* V5T. */
13901 T(V6T2
), /* V5TE. */
13902 T(V6T2
), /* V5TEJ. */
13905 T(V6T2
) /* V6T2. */
13909 T(V6K
), /* PRE_V4. */
13913 T(V6K
), /* V5TE. */
13914 T(V6K
), /* V5TEJ. */
13916 T(V6KZ
), /* V6KZ. */
13922 T(V7
), /* PRE_V4. */
13927 T(V7
), /* V5TEJ. */
13940 T(V6K
), /* V5TE. */
13941 T(V6K
), /* V5TEJ. */
13943 T(V6KZ
), /* V6KZ. */
13947 T(V6_M
) /* V6_M. */
13949 const int v6s_m
[] =
13955 T(V6K
), /* V5TE. */
13956 T(V6K
), /* V5TEJ. */
13958 T(V6KZ
), /* V6KZ. */
13962 T(V6S_M
), /* V6_M. */
13963 T(V6S_M
) /* V6S_M. */
13965 const int v7e_m
[] =
13969 T(V7E_M
), /* V4T. */
13970 T(V7E_M
), /* V5T. */
13971 T(V7E_M
), /* V5TE. */
13972 T(V7E_M
), /* V5TEJ. */
13973 T(V7E_M
), /* V6. */
13974 T(V7E_M
), /* V6KZ. */
13975 T(V7E_M
), /* V6T2. */
13976 T(V7E_M
), /* V6K. */
13977 T(V7E_M
), /* V7. */
13978 T(V7E_M
), /* V6_M. */
13979 T(V7E_M
), /* V6S_M. */
13980 T(V7E_M
) /* V7E_M. */
13984 T(V8
), /* PRE_V4. */
13989 T(V8
), /* V5TEJ. */
13996 T(V8
), /* V6S_M. */
13997 T(V8
), /* V7E_M. */
14002 T(V8R
), /* PRE_V4. */
14006 T(V8R
), /* V5TE. */
14007 T(V8R
), /* V5TEJ. */
14009 T(V8R
), /* V6KZ. */
14010 T(V8R
), /* V6T2. */
14013 T(V8R
), /* V6_M. */
14014 T(V8R
), /* V6S_M. */
14015 T(V8R
), /* V7E_M. */
14019 const int v8m_baseline
[] =
14032 T(V8M_BASE
), /* V6_M. */
14033 T(V8M_BASE
), /* V6S_M. */
14037 T(V8M_BASE
) /* V8-M BASELINE. */
14039 const int v8m_mainline
[] =
14051 T(V8M_MAIN
), /* V7. */
14052 T(V8M_MAIN
), /* V6_M. */
14053 T(V8M_MAIN
), /* V6S_M. */
14054 T(V8M_MAIN
), /* V7E_M. */
14057 T(V8M_MAIN
), /* V8-M BASELINE. */
14058 T(V8M_MAIN
) /* V8-M MAINLINE. */
14060 const int v4t_plus_v6_m
[] =
14066 T(V5TE
), /* V5TE. */
14067 T(V5TEJ
), /* V5TEJ. */
14069 T(V6KZ
), /* V6KZ. */
14070 T(V6T2
), /* V6T2. */
14073 T(V6_M
), /* V6_M. */
14074 T(V6S_M
), /* V6S_M. */
14075 T(V7E_M
), /* V7E_M. */
14078 T(V8M_BASE
), /* V8-M BASELINE. */
14079 T(V8M_MAIN
), /* V8-M MAINLINE. */
14080 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
14082 const int *comb
[] =
14094 /* Pseudo-architecture. */
14098 /* Check we've not got a higher architecture than we know about. */
14100 if (oldtag
> MAX_TAG_CPU_ARCH
|| newtag
> MAX_TAG_CPU_ARCH
)
14102 _bfd_error_handler (_("error: %pB: unknown CPU architecture"), ibfd
);
14106 /* Override old tag if we have a Tag_also_compatible_with on the output. */
14108 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
14109 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
14110 oldtag
= T(V4T_PLUS_V6_M
);
14112 /* And override the new tag if we have a Tag_also_compatible_with on the
14115 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
14116 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
14117 newtag
= T(V4T_PLUS_V6_M
);
14119 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
14120 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
14122 /* Architectures before V6KZ add features monotonically. */
14123 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
14126 result
= comb
[tagh
- T(V6T2
)] ? comb
[tagh
- T(V6T2
)][tagl
] : -1;
14128 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
14129 as the canonical version. */
14130 if (result
== T(V4T_PLUS_V6_M
))
14133 *secondary_compat_out
= T(V6_M
);
14136 *secondary_compat_out
= -1;
14140 _bfd_error_handler (_("error: %pB: conflicting CPU architectures %d/%d"),
14141 ibfd
, oldtag
, newtag
);
14149 /* Query attributes object to see if integer divide instructions may be
14150 present in an object. */
14152 elf32_arm_attributes_accept_div (const obj_attribute
*attr
)
14154 int arch
= attr
[Tag_CPU_arch
].i
;
14155 int profile
= attr
[Tag_CPU_arch_profile
].i
;
14157 switch (attr
[Tag_DIV_use
].i
)
14160 /* Integer divide allowed if instruction contained in archetecture. */
14161 if (arch
== TAG_CPU_ARCH_V7
&& (profile
== 'R' || profile
== 'M'))
14163 else if (arch
>= TAG_CPU_ARCH_V7E_M
)
14169 /* Integer divide explicitly prohibited. */
14173 /* Unrecognised case - treat as allowing divide everywhere. */
14175 /* Integer divide allowed in ARM state. */
14180 /* Query attributes object to see if integer divide instructions are
14181 forbidden to be in the object. This is not the inverse of
14182 elf32_arm_attributes_accept_div. */
14184 elf32_arm_attributes_forbid_div (const obj_attribute
*attr
)
14186 return attr
[Tag_DIV_use
].i
== 1;
14189 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
14190 are conflicting attributes. */
14193 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
14195 bfd
*obfd
= info
->output_bfd
;
14196 obj_attribute
*in_attr
;
14197 obj_attribute
*out_attr
;
14198 /* Some tags have 0 = don't care, 1 = strong requirement,
14199 2 = weak requirement. */
14200 static const int order_021
[3] = {0, 2, 1};
14202 bfd_boolean result
= TRUE
;
14203 const char *sec_name
= get_elf_backend_data (ibfd
)->obj_attrs_section
;
14205 /* Skip the linker stubs file. This preserves previous behavior
14206 of accepting unknown attributes in the first input file - but
14208 if (ibfd
->flags
& BFD_LINKER_CREATED
)
14211 /* Skip any input that hasn't attribute section.
14212 This enables to link object files without attribute section with
14214 if (bfd_get_section_by_name (ibfd
, sec_name
) == NULL
)
14217 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
14219 /* This is the first object. Copy the attributes. */
14220 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
14222 out_attr
= elf_known_obj_attributes_proc (obfd
);
14224 /* Use the Tag_null value to indicate the attributes have been
14228 /* We do not output objects with Tag_MPextension_use_legacy - we move
14229 the attribute's value to Tag_MPextension_use. */
14230 if (out_attr
[Tag_MPextension_use_legacy
].i
!= 0)
14232 if (out_attr
[Tag_MPextension_use
].i
!= 0
14233 && out_attr
[Tag_MPextension_use_legacy
].i
14234 != out_attr
[Tag_MPextension_use
].i
)
14237 (_("Error: %pB has both the current and legacy "
14238 "Tag_MPextension_use attributes"), ibfd
);
14242 out_attr
[Tag_MPextension_use
] =
14243 out_attr
[Tag_MPextension_use_legacy
];
14244 out_attr
[Tag_MPextension_use_legacy
].type
= 0;
14245 out_attr
[Tag_MPextension_use_legacy
].i
= 0;
14251 in_attr
= elf_known_obj_attributes_proc (ibfd
);
14252 out_attr
= elf_known_obj_attributes_proc (obfd
);
14253 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
14254 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
14256 /* Ignore mismatches if the object doesn't use floating point or is
14257 floating point ABI independent. */
14258 if (out_attr
[Tag_ABI_FP_number_model
].i
== AEABI_FP_number_model_none
14259 || (in_attr
[Tag_ABI_FP_number_model
].i
!= AEABI_FP_number_model_none
14260 && out_attr
[Tag_ABI_VFP_args
].i
== AEABI_VFP_args_compatible
))
14261 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
14262 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= AEABI_FP_number_model_none
14263 && in_attr
[Tag_ABI_VFP_args
].i
!= AEABI_VFP_args_compatible
)
14266 (_("error: %pB uses VFP register arguments, %pB does not"),
14267 in_attr
[Tag_ABI_VFP_args
].i
? ibfd
: obfd
,
14268 in_attr
[Tag_ABI_VFP_args
].i
? obfd
: ibfd
);
14273 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
14275 /* Merge this attribute with existing attributes. */
14278 case Tag_CPU_raw_name
:
14280 /* These are merged after Tag_CPU_arch. */
14283 case Tag_ABI_optimization_goals
:
14284 case Tag_ABI_FP_optimization_goals
:
14285 /* Use the first value seen. */
14290 int secondary_compat
= -1, secondary_compat_out
= -1;
14291 unsigned int saved_out_attr
= out_attr
[i
].i
;
14293 static const char *name_table
[] =
14295 /* These aren't real CPU names, but we can't guess
14296 that from the architecture version alone. */
14312 "ARM v8-M.baseline",
14313 "ARM v8-M.mainline",
14316 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
14317 secondary_compat
= get_secondary_compatible_arch (ibfd
);
14318 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
14319 arch_attr
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
14320 &secondary_compat_out
,
14324 /* Return with error if failed to merge. */
14325 if (arch_attr
== -1)
14328 out_attr
[i
].i
= arch_attr
;
14330 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
14332 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
14333 if (out_attr
[i
].i
== saved_out_attr
)
14334 ; /* Leave the names alone. */
14335 else if (out_attr
[i
].i
== in_attr
[i
].i
)
14337 /* The output architecture has been changed to match the
14338 input architecture. Use the input names. */
14339 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
14340 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
14342 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
14343 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
14348 out_attr
[Tag_CPU_name
].s
= NULL
;
14349 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
14352 /* If we still don't have a value for Tag_CPU_name,
14353 make one up now. Tag_CPU_raw_name remains blank. */
14354 if (out_attr
[Tag_CPU_name
].s
== NULL
14355 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
14356 out_attr
[Tag_CPU_name
].s
=
14357 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
14361 case Tag_ARM_ISA_use
:
14362 case Tag_THUMB_ISA_use
:
14363 case Tag_WMMX_arch
:
14364 case Tag_Advanced_SIMD_arch
:
14365 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
14366 case Tag_ABI_FP_rounding
:
14367 case Tag_ABI_FP_exceptions
:
14368 case Tag_ABI_FP_user_exceptions
:
14369 case Tag_ABI_FP_number_model
:
14370 case Tag_FP_HP_extension
:
14371 case Tag_CPU_unaligned_access
:
14373 case Tag_MPextension_use
:
14374 /* Use the largest value specified. */
14375 if (in_attr
[i
].i
> out_attr
[i
].i
)
14376 out_attr
[i
].i
= in_attr
[i
].i
;
14379 case Tag_ABI_align_preserved
:
14380 case Tag_ABI_PCS_RO_data
:
14381 /* Use the smallest value specified. */
14382 if (in_attr
[i
].i
< out_attr
[i
].i
)
14383 out_attr
[i
].i
= in_attr
[i
].i
;
14386 case Tag_ABI_align_needed
:
14387 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
14388 && (in_attr
[Tag_ABI_align_preserved
].i
== 0
14389 || out_attr
[Tag_ABI_align_preserved
].i
== 0))
14391 /* This error message should be enabled once all non-conformant
14392 binaries in the toolchain have had the attributes set
14395 (_("error: %pB: 8-byte data alignment conflicts with %pB"),
14399 /* Fall through. */
14400 case Tag_ABI_FP_denormal
:
14401 case Tag_ABI_PCS_GOT_use
:
14402 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
14403 value if greater than 2 (for future-proofing). */
14404 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
14405 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
14406 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
14407 out_attr
[i
].i
= in_attr
[i
].i
;
14410 case Tag_Virtualization_use
:
14411 /* The virtualization tag effectively stores two bits of
14412 information: the intended use of TrustZone (in bit 0), and the
14413 intended use of Virtualization (in bit 1). */
14414 if (out_attr
[i
].i
== 0)
14415 out_attr
[i
].i
= in_attr
[i
].i
;
14416 else if (in_attr
[i
].i
!= 0
14417 && in_attr
[i
].i
!= out_attr
[i
].i
)
14419 if (in_attr
[i
].i
<= 3 && out_attr
[i
].i
<= 3)
14424 (_("error: %pB: unable to merge virtualization attributes "
14432 case Tag_CPU_arch_profile
:
14433 if (out_attr
[i
].i
!= in_attr
[i
].i
)
14435 /* 0 will merge with anything.
14436 'A' and 'S' merge to 'A'.
14437 'R' and 'S' merge to 'R'.
14438 'M' and 'A|R|S' is an error. */
14439 if (out_attr
[i
].i
== 0
14440 || (out_attr
[i
].i
== 'S'
14441 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
14442 out_attr
[i
].i
= in_attr
[i
].i
;
14443 else if (in_attr
[i
].i
== 0
14444 || (in_attr
[i
].i
== 'S'
14445 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
14446 ; /* Do nothing. */
14450 (_("error: %pB: conflicting architecture profiles %c/%c"),
14452 in_attr
[i
].i
? in_attr
[i
].i
: '0',
14453 out_attr
[i
].i
? out_attr
[i
].i
: '0');
14459 case Tag_DSP_extension
:
14460 /* No need to change output value if any of:
14461 - pre (<=) ARMv5T input architecture (do not have DSP)
14462 - M input profile not ARMv7E-M and do not have DSP. */
14463 if (in_attr
[Tag_CPU_arch
].i
<= 3
14464 || (in_attr
[Tag_CPU_arch_profile
].i
== 'M'
14465 && in_attr
[Tag_CPU_arch
].i
!= 13
14466 && in_attr
[i
].i
== 0))
14467 ; /* Do nothing. */
14468 /* Output value should be 0 if DSP part of architecture, ie.
14469 - post (>=) ARMv5te architecture output
14470 - A, R or S profile output or ARMv7E-M output architecture. */
14471 else if (out_attr
[Tag_CPU_arch
].i
>= 4
14472 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
14473 || out_attr
[Tag_CPU_arch_profile
].i
== 'R'
14474 || out_attr
[Tag_CPU_arch_profile
].i
== 'S'
14475 || out_attr
[Tag_CPU_arch
].i
== 13))
14477 /* Otherwise, DSP instructions are added and not part of output
14485 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
14486 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
14487 when it's 0. It might mean absence of FP hardware if
14488 Tag_FP_arch is zero. */
14490 #define VFP_VERSION_COUNT 9
14491 static const struct
14495 } vfp_versions
[VFP_VERSION_COUNT
] =
14511 /* If the output has no requirement about FP hardware,
14512 follow the requirement of the input. */
14513 if (out_attr
[i
].i
== 0)
14515 /* This assert is still reasonable, we shouldn't
14516 produce the suspicious build attribute
14517 combination (See below for in_attr). */
14518 BFD_ASSERT (out_attr
[Tag_ABI_HardFP_use
].i
== 0);
14519 out_attr
[i
].i
= in_attr
[i
].i
;
14520 out_attr
[Tag_ABI_HardFP_use
].i
14521 = in_attr
[Tag_ABI_HardFP_use
].i
;
14524 /* If the input has no requirement about FP hardware, do
14526 else if (in_attr
[i
].i
== 0)
14528 /* We used to assert that Tag_ABI_HardFP_use was
14529 zero here, but we should never assert when
14530 consuming an object file that has suspicious
14531 build attributes. The single precision variant
14532 of 'no FP architecture' is still 'no FP
14533 architecture', so we just ignore the tag in this
14538 /* Both the input and the output have nonzero Tag_FP_arch.
14539 So Tag_ABI_HardFP_use is implied by Tag_FP_arch when it's zero. */
14541 /* If both the input and the output have zero Tag_ABI_HardFP_use,
14543 if (in_attr
[Tag_ABI_HardFP_use
].i
== 0
14544 && out_attr
[Tag_ABI_HardFP_use
].i
== 0)
14546 /* If the input and the output have different Tag_ABI_HardFP_use,
14547 the combination of them is 0 (implied by Tag_FP_arch). */
14548 else if (in_attr
[Tag_ABI_HardFP_use
].i
14549 != out_attr
[Tag_ABI_HardFP_use
].i
)
14550 out_attr
[Tag_ABI_HardFP_use
].i
= 0;
14552 /* Now we can handle Tag_FP_arch. */
14554 /* Values of VFP_VERSION_COUNT or more aren't defined, so just
14555 pick the biggest. */
14556 if (in_attr
[i
].i
>= VFP_VERSION_COUNT
14557 && in_attr
[i
].i
> out_attr
[i
].i
)
14559 out_attr
[i
] = in_attr
[i
];
14562 /* The output uses the superset of input features
14563 (ISA version) and registers. */
14564 ver
= vfp_versions
[in_attr
[i
].i
].ver
;
14565 if (ver
< vfp_versions
[out_attr
[i
].i
].ver
)
14566 ver
= vfp_versions
[out_attr
[i
].i
].ver
;
14567 regs
= vfp_versions
[in_attr
[i
].i
].regs
;
14568 if (regs
< vfp_versions
[out_attr
[i
].i
].regs
)
14569 regs
= vfp_versions
[out_attr
[i
].i
].regs
;
14570 /* This assumes all possible supersets are also a valid
14572 for (newval
= VFP_VERSION_COUNT
- 1; newval
> 0; newval
--)
14574 if (regs
== vfp_versions
[newval
].regs
14575 && ver
== vfp_versions
[newval
].ver
)
14578 out_attr
[i
].i
= newval
;
14581 case Tag_PCS_config
:
14582 if (out_attr
[i
].i
== 0)
14583 out_attr
[i
].i
= in_attr
[i
].i
;
14584 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= in_attr
[i
].i
)
14586 /* It's sometimes ok to mix different configs, so this is only
14589 (_("warning: %pB: conflicting platform configuration"), ibfd
);
14592 case Tag_ABI_PCS_R9_use
:
14593 if (in_attr
[i
].i
!= out_attr
[i
].i
14594 && out_attr
[i
].i
!= AEABI_R9_unused
14595 && in_attr
[i
].i
!= AEABI_R9_unused
)
14598 (_("error: %pB: conflicting use of R9"), ibfd
);
14601 if (out_attr
[i
].i
== AEABI_R9_unused
)
14602 out_attr
[i
].i
= in_attr
[i
].i
;
14604 case Tag_ABI_PCS_RW_data
:
14605 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
14606 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
14607 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
14610 (_("error: %pB: SB relative addressing conflicts with use of R9"),
14614 /* Use the smallest value specified. */
14615 if (in_attr
[i
].i
< out_attr
[i
].i
)
14616 out_attr
[i
].i
= in_attr
[i
].i
;
14618 case Tag_ABI_PCS_wchar_t
:
14619 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
14620 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
14623 (_("warning: %pB uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
14624 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
14626 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
14627 out_attr
[i
].i
= in_attr
[i
].i
;
14629 case Tag_ABI_enum_size
:
14630 if (in_attr
[i
].i
!= AEABI_enum_unused
)
14632 if (out_attr
[i
].i
== AEABI_enum_unused
14633 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
14635 /* The existing object is compatible with anything.
14636 Use whatever requirements the new object has. */
14637 out_attr
[i
].i
= in_attr
[i
].i
;
14639 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
14640 && out_attr
[i
].i
!= in_attr
[i
].i
14641 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
14643 static const char *aeabi_enum_names
[] =
14644 { "", "variable-size", "32-bit", "" };
14645 const char *in_name
=
14646 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
14647 ? aeabi_enum_names
[in_attr
[i
].i
]
14649 const char *out_name
=
14650 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
14651 ? aeabi_enum_names
[out_attr
[i
].i
]
14654 (_("warning: %pB uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
14655 ibfd
, in_name
, out_name
);
14659 case Tag_ABI_VFP_args
:
14662 case Tag_ABI_WMMX_args
:
14663 if (in_attr
[i
].i
!= out_attr
[i
].i
)
14666 (_("error: %pB uses iWMMXt register arguments, %pB does not"),
14671 case Tag_compatibility
:
14672 /* Merged in target-independent code. */
14674 case Tag_ABI_HardFP_use
:
14675 /* This is handled along with Tag_FP_arch. */
14677 case Tag_ABI_FP_16bit_format
:
14678 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
14680 if (in_attr
[i
].i
!= out_attr
[i
].i
)
14683 (_("error: fp16 format mismatch between %pB and %pB"),
14688 if (in_attr
[i
].i
!= 0)
14689 out_attr
[i
].i
= in_attr
[i
].i
;
14693 /* A value of zero on input means that the divide instruction may
14694 be used if available in the base architecture as specified via
14695 Tag_CPU_arch and Tag_CPU_arch_profile. A value of 1 means that
14696 the user did not want divide instructions. A value of 2
14697 explicitly means that divide instructions were allowed in ARM
14698 and Thumb state. */
14699 if (in_attr
[i
].i
== out_attr
[i
].i
)
14700 /* Do nothing. */ ;
14701 else if (elf32_arm_attributes_forbid_div (in_attr
)
14702 && !elf32_arm_attributes_accept_div (out_attr
))
14704 else if (elf32_arm_attributes_forbid_div (out_attr
)
14705 && elf32_arm_attributes_accept_div (in_attr
))
14706 out_attr
[i
].i
= in_attr
[i
].i
;
14707 else if (in_attr
[i
].i
== 2)
14708 out_attr
[i
].i
= in_attr
[i
].i
;
14711 case Tag_MPextension_use_legacy
:
14712 /* We don't output objects with Tag_MPextension_use_legacy - we
14713 move the value to Tag_MPextension_use. */
14714 if (in_attr
[i
].i
!= 0 && in_attr
[Tag_MPextension_use
].i
!= 0)
14716 if (in_attr
[Tag_MPextension_use
].i
!= in_attr
[i
].i
)
14719 (_("%pB has both the current and legacy "
14720 "Tag_MPextension_use attributes"),
14726 if (in_attr
[i
].i
> out_attr
[Tag_MPextension_use
].i
)
14727 out_attr
[Tag_MPextension_use
] = in_attr
[i
];
14731 case Tag_nodefaults
:
14732 /* This tag is set if it exists, but the value is unused (and is
14733 typically zero). We don't actually need to do anything here -
14734 the merge happens automatically when the type flags are merged
14737 case Tag_also_compatible_with
:
14738 /* Already done in Tag_CPU_arch. */
14740 case Tag_conformance
:
14741 /* Keep the attribute if it matches. Throw it away otherwise.
14742 No attribute means no claim to conform. */
14743 if (!in_attr
[i
].s
|| !out_attr
[i
].s
14744 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
14745 out_attr
[i
].s
= NULL
;
14750 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
14753 /* If out_attr was copied from in_attr then it won't have a type yet. */
14754 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
14755 out_attr
[i
].type
= in_attr
[i
].type
;
14758 /* Merge Tag_compatibility attributes and any common GNU ones. */
14759 if (!_bfd_elf_merge_object_attributes (ibfd
, info
))
14762 /* Check for any attributes not known on ARM. */
14763 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
14769 /* Return TRUE if the two EABI versions are incompatible. */
14772 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
14774 /* v4 and v5 are the same spec before and after it was released,
14775 so allow mixing them. */
14776 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
14777 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
14780 return (iver
== over
);
14783 /* Merge backend specific data from an object file to the output
14784 object file when linking. */
14787 elf32_arm_merge_private_bfd_data (bfd
*, struct bfd_link_info
*);
14789 /* Display the flags field. */
14792 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
14794 FILE * file
= (FILE *) ptr
;
14795 unsigned long flags
;
14797 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
14799 /* Print normal ELF private data. */
14800 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
14802 flags
= elf_elfheader (abfd
)->e_flags
;
14803 /* Ignore init flag - it may not be set, despite the flags field
14804 containing valid data. */
14806 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
14808 switch (EF_ARM_EABI_VERSION (flags
))
14810 case EF_ARM_EABI_UNKNOWN
:
14811 /* The following flag bits are GNU extensions and not part of the
14812 official ARM ELF extended ABI. Hence they are only decoded if
14813 the EABI version is not set. */
14814 if (flags
& EF_ARM_INTERWORK
)
14815 fprintf (file
, _(" [interworking enabled]"));
14817 if (flags
& EF_ARM_APCS_26
)
14818 fprintf (file
, " [APCS-26]");
14820 fprintf (file
, " [APCS-32]");
14822 if (flags
& EF_ARM_VFP_FLOAT
)
14823 fprintf (file
, _(" [VFP float format]"));
14824 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
14825 fprintf (file
, _(" [Maverick float format]"));
14827 fprintf (file
, _(" [FPA float format]"));
14829 if (flags
& EF_ARM_APCS_FLOAT
)
14830 fprintf (file
, _(" [floats passed in float registers]"));
14832 if (flags
& EF_ARM_PIC
)
14833 fprintf (file
, _(" [position independent]"));
14835 if (flags
& EF_ARM_NEW_ABI
)
14836 fprintf (file
, _(" [new ABI]"));
14838 if (flags
& EF_ARM_OLD_ABI
)
14839 fprintf (file
, _(" [old ABI]"));
14841 if (flags
& EF_ARM_SOFT_FLOAT
)
14842 fprintf (file
, _(" [software FP]"));
14844 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
14845 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
14846 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
14847 | EF_ARM_MAVERICK_FLOAT
);
14850 case EF_ARM_EABI_VER1
:
14851 fprintf (file
, _(" [Version1 EABI]"));
14853 if (flags
& EF_ARM_SYMSARESORTED
)
14854 fprintf (file
, _(" [sorted symbol table]"));
14856 fprintf (file
, _(" [unsorted symbol table]"));
14858 flags
&= ~ EF_ARM_SYMSARESORTED
;
14861 case EF_ARM_EABI_VER2
:
14862 fprintf (file
, _(" [Version2 EABI]"));
14864 if (flags
& EF_ARM_SYMSARESORTED
)
14865 fprintf (file
, _(" [sorted symbol table]"));
14867 fprintf (file
, _(" [unsorted symbol table]"));
14869 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
14870 fprintf (file
, _(" [dynamic symbols use segment index]"));
14872 if (flags
& EF_ARM_MAPSYMSFIRST
)
14873 fprintf (file
, _(" [mapping symbols precede others]"));
14875 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
14876 | EF_ARM_MAPSYMSFIRST
);
14879 case EF_ARM_EABI_VER3
:
14880 fprintf (file
, _(" [Version3 EABI]"));
14883 case EF_ARM_EABI_VER4
:
14884 fprintf (file
, _(" [Version4 EABI]"));
14887 case EF_ARM_EABI_VER5
:
14888 fprintf (file
, _(" [Version5 EABI]"));
14890 if (flags
& EF_ARM_ABI_FLOAT_SOFT
)
14891 fprintf (file
, _(" [soft-float ABI]"));
14893 if (flags
& EF_ARM_ABI_FLOAT_HARD
)
14894 fprintf (file
, _(" [hard-float ABI]"));
14896 flags
&= ~(EF_ARM_ABI_FLOAT_SOFT
| EF_ARM_ABI_FLOAT_HARD
);
14899 if (flags
& EF_ARM_BE8
)
14900 fprintf (file
, _(" [BE8]"));
14902 if (flags
& EF_ARM_LE8
)
14903 fprintf (file
, _(" [LE8]"));
14905 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
14909 fprintf (file
, _(" <EABI version unrecognised>"));
14913 flags
&= ~ EF_ARM_EABIMASK
;
14915 if (flags
& EF_ARM_RELEXEC
)
14916 fprintf (file
, _(" [relocatable executable]"));
14918 if (flags
& EF_ARM_PIC
)
14919 fprintf (file
, _(" [position independent]"));
14921 if (elf_elfheader (abfd
)->e_ident
[EI_OSABI
] == ELFOSABI_ARM_FDPIC
)
14922 fprintf (file
, _(" [FDPIC ABI supplement]"));
14924 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_PIC
);
14927 fprintf (file
, _("<Unrecognised flag bits set>"));
14929 fputc ('\n', file
);
14935 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
14937 switch (ELF_ST_TYPE (elf_sym
->st_info
))
14939 case STT_ARM_TFUNC
:
14940 return ELF_ST_TYPE (elf_sym
->st_info
);
14942 case STT_ARM_16BIT
:
14943 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
14944 This allows us to distinguish between data used by Thumb instructions
14945 and non-data (which is probably code) inside Thumb regions of an
14947 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
14948 return ELF_ST_TYPE (elf_sym
->st_info
);
14959 elf32_arm_gc_mark_hook (asection
*sec
,
14960 struct bfd_link_info
*info
,
14961 Elf_Internal_Rela
*rel
,
14962 struct elf_link_hash_entry
*h
,
14963 Elf_Internal_Sym
*sym
)
14966 switch (ELF32_R_TYPE (rel
->r_info
))
14968 case R_ARM_GNU_VTINHERIT
:
14969 case R_ARM_GNU_VTENTRY
:
14973 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
14976 /* Look through the relocs for a section during the first phase. */
14979 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
14980 asection
*sec
, const Elf_Internal_Rela
*relocs
)
14982 Elf_Internal_Shdr
*symtab_hdr
;
14983 struct elf_link_hash_entry
**sym_hashes
;
14984 const Elf_Internal_Rela
*rel
;
14985 const Elf_Internal_Rela
*rel_end
;
14988 struct elf32_arm_link_hash_table
*htab
;
14989 bfd_boolean call_reloc_p
;
14990 bfd_boolean may_become_dynamic_p
;
14991 bfd_boolean may_need_local_target_p
;
14992 unsigned long nsyms
;
14994 if (bfd_link_relocatable (info
))
14997 BFD_ASSERT (is_arm_elf (abfd
));
14999 htab
= elf32_arm_hash_table (info
);
15005 /* Create dynamic sections for relocatable executables so that we can
15006 copy relocations. */
15007 if (htab
->root
.is_relocatable_executable
15008 && ! htab
->root
.dynamic_sections_created
)
15010 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
15014 if (htab
->root
.dynobj
== NULL
)
15015 htab
->root
.dynobj
= abfd
;
15016 if (!create_ifunc_sections (info
))
15019 dynobj
= htab
->root
.dynobj
;
15021 symtab_hdr
= & elf_symtab_hdr (abfd
);
15022 sym_hashes
= elf_sym_hashes (abfd
);
15023 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
15025 rel_end
= relocs
+ sec
->reloc_count
;
15026 for (rel
= relocs
; rel
< rel_end
; rel
++)
15028 Elf_Internal_Sym
*isym
;
15029 struct elf_link_hash_entry
*h
;
15030 struct elf32_arm_link_hash_entry
*eh
;
15031 unsigned int r_symndx
;
15034 r_symndx
= ELF32_R_SYM (rel
->r_info
);
15035 r_type
= ELF32_R_TYPE (rel
->r_info
);
15036 r_type
= arm_real_reloc_type (htab
, r_type
);
15038 if (r_symndx
>= nsyms
15039 /* PR 9934: It is possible to have relocations that do not
15040 refer to symbols, thus it is also possible to have an
15041 object file containing relocations but no symbol table. */
15042 && (r_symndx
> STN_UNDEF
|| nsyms
> 0))
15044 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd
,
15053 if (r_symndx
< symtab_hdr
->sh_info
)
15055 /* A local symbol. */
15056 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
15063 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
15064 while (h
->root
.type
== bfd_link_hash_indirect
15065 || h
->root
.type
== bfd_link_hash_warning
)
15066 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
15070 eh
= (struct elf32_arm_link_hash_entry
*) h
;
15072 call_reloc_p
= FALSE
;
15073 may_become_dynamic_p
= FALSE
;
15074 may_need_local_target_p
= FALSE
;
15076 /* Could be done earlier, if h were already available. */
15077 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
15080 case R_ARM_GOTOFFFUNCDESC
:
15084 if (!elf32_arm_allocate_local_sym_info (abfd
))
15086 elf32_arm_local_fdpic_cnts(abfd
)[r_symndx
].gotofffuncdesc_cnt
+= 1;
15087 elf32_arm_local_fdpic_cnts(abfd
)[r_symndx
].funcdesc_offset
= -1;
15091 eh
->fdpic_cnts
.gotofffuncdesc_cnt
++;
15096 case R_ARM_GOTFUNCDESC
:
15100 /* Such a relocation is not supposed to be generated
15101 by gcc on a static function. */
15102 /* Anyway if needed it could be handled. */
15107 eh
->fdpic_cnts
.gotfuncdesc_cnt
++;
15112 case R_ARM_FUNCDESC
:
15116 if (!elf32_arm_allocate_local_sym_info (abfd
))
15118 elf32_arm_local_fdpic_cnts(abfd
)[r_symndx
].funcdesc_cnt
+= 1;
15119 elf32_arm_local_fdpic_cnts(abfd
)[r_symndx
].funcdesc_offset
= -1;
15123 eh
->fdpic_cnts
.funcdesc_cnt
++;
15129 case R_ARM_GOT_PREL
:
15130 case R_ARM_TLS_GD32
:
15131 case R_ARM_TLS_GD32_FDPIC
:
15132 case R_ARM_TLS_IE32
:
15133 case R_ARM_TLS_IE32_FDPIC
:
15134 case R_ARM_TLS_GOTDESC
:
15135 case R_ARM_TLS_DESCSEQ
:
15136 case R_ARM_THM_TLS_DESCSEQ
:
15137 case R_ARM_TLS_CALL
:
15138 case R_ARM_THM_TLS_CALL
:
15139 /* This symbol requires a global offset table entry. */
15141 int tls_type
, old_tls_type
;
15145 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
15146 case R_ARM_TLS_GD32_FDPIC
: tls_type
= GOT_TLS_GD
; break;
15148 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
15149 case R_ARM_TLS_IE32_FDPIC
: tls_type
= GOT_TLS_IE
; break;
15151 case R_ARM_TLS_GOTDESC
:
15152 case R_ARM_TLS_CALL
: case R_ARM_THM_TLS_CALL
:
15153 case R_ARM_TLS_DESCSEQ
: case R_ARM_THM_TLS_DESCSEQ
:
15154 tls_type
= GOT_TLS_GDESC
; break;
15156 default: tls_type
= GOT_NORMAL
; break;
15159 if (!bfd_link_executable (info
) && (tls_type
& GOT_TLS_IE
))
15160 info
->flags
|= DF_STATIC_TLS
;
15165 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
15169 /* This is a global offset table entry for a local symbol. */
15170 if (!elf32_arm_allocate_local_sym_info (abfd
))
15172 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
15173 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
15176 /* If a variable is accessed with both tls methods, two
15177 slots may be created. */
15178 if (GOT_TLS_GD_ANY_P (old_tls_type
)
15179 && GOT_TLS_GD_ANY_P (tls_type
))
15180 tls_type
|= old_tls_type
;
15182 /* We will already have issued an error message if there
15183 is a TLS/non-TLS mismatch, based on the symbol
15184 type. So just combine any TLS types needed. */
15185 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
15186 && tls_type
!= GOT_NORMAL
)
15187 tls_type
|= old_tls_type
;
15189 /* If the symbol is accessed in both IE and GDESC
15190 method, we're able to relax. Turn off the GDESC flag,
15191 without messing up with any other kind of tls types
15192 that may be involved. */
15193 if ((tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_GDESC
))
15194 tls_type
&= ~GOT_TLS_GDESC
;
15196 if (old_tls_type
!= tls_type
)
15199 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
15201 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
15204 /* Fall through. */
15206 case R_ARM_TLS_LDM32
:
15207 case R_ARM_TLS_LDM32_FDPIC
:
15208 if (r_type
== R_ARM_TLS_LDM32
|| r_type
== R_ARM_TLS_LDM32_FDPIC
)
15209 htab
->tls_ldm_got
.refcount
++;
15210 /* Fall through. */
15212 case R_ARM_GOTOFF32
:
15214 if (htab
->root
.sgot
== NULL
15215 && !create_got_section (htab
->root
.dynobj
, info
))
15224 case R_ARM_THM_CALL
:
15225 case R_ARM_THM_JUMP24
:
15226 case R_ARM_THM_JUMP19
:
15227 call_reloc_p
= TRUE
;
15228 may_need_local_target_p
= TRUE
;
15232 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
15233 ldr __GOTT_INDEX__ offsets. */
15234 if (!htab
->vxworks_p
)
15236 may_need_local_target_p
= TRUE
;
15239 else goto jump_over
;
15241 /* Fall through. */
15243 case R_ARM_MOVW_ABS_NC
:
15244 case R_ARM_MOVT_ABS
:
15245 case R_ARM_THM_MOVW_ABS_NC
:
15246 case R_ARM_THM_MOVT_ABS
:
15247 if (bfd_link_pic (info
))
15250 (_("%pB: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
15251 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
15252 (h
) ? h
->root
.root
.string
: "a local symbol");
15253 bfd_set_error (bfd_error_bad_value
);
15257 /* Fall through. */
15259 case R_ARM_ABS32_NOI
:
15261 if (h
!= NULL
&& bfd_link_executable (info
))
15263 h
->pointer_equality_needed
= 1;
15265 /* Fall through. */
15267 case R_ARM_REL32_NOI
:
15268 case R_ARM_MOVW_PREL_NC
:
15269 case R_ARM_MOVT_PREL
:
15270 case R_ARM_THM_MOVW_PREL_NC
:
15271 case R_ARM_THM_MOVT_PREL
:
15273 /* Should the interworking branches be listed here? */
15274 if ((bfd_link_pic (info
) || htab
->root
.is_relocatable_executable
15276 && (sec
->flags
& SEC_ALLOC
) != 0)
15279 && elf32_arm_howto_from_type (r_type
)->pc_relative
)
15281 /* In shared libraries and relocatable executables,
15282 we treat local relative references as calls;
15283 see the related SYMBOL_CALLS_LOCAL code in
15284 allocate_dynrelocs. */
15285 call_reloc_p
= TRUE
;
15286 may_need_local_target_p
= TRUE
;
15289 /* We are creating a shared library or relocatable
15290 executable, and this is a reloc against a global symbol,
15291 or a non-PC-relative reloc against a local symbol.
15292 We may need to copy the reloc into the output. */
15293 may_become_dynamic_p
= TRUE
;
15296 may_need_local_target_p
= TRUE
;
15299 /* This relocation describes the C++ object vtable hierarchy.
15300 Reconstruct it for later use during GC. */
15301 case R_ARM_GNU_VTINHERIT
:
15302 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
15306 /* This relocation describes which C++ vtable entries are actually
15307 used. Record for later use during GC. */
15308 case R_ARM_GNU_VTENTRY
:
15309 BFD_ASSERT (h
!= NULL
);
15311 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
15319 /* We may need a .plt entry if the function this reloc
15320 refers to is in a different object, regardless of the
15321 symbol's type. We can't tell for sure yet, because
15322 something later might force the symbol local. */
15324 else if (may_need_local_target_p
)
15325 /* If this reloc is in a read-only section, we might
15326 need a copy reloc. We can't check reliably at this
15327 stage whether the section is read-only, as input
15328 sections have not yet been mapped to output sections.
15329 Tentatively set the flag for now, and correct in
15330 adjust_dynamic_symbol. */
15331 h
->non_got_ref
= 1;
15334 if (may_need_local_target_p
15335 && (h
!= NULL
|| ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
))
15337 union gotplt_union
*root_plt
;
15338 struct arm_plt_info
*arm_plt
;
15339 struct arm_local_iplt_info
*local_iplt
;
15343 root_plt
= &h
->plt
;
15344 arm_plt
= &eh
->plt
;
15348 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
15349 if (local_iplt
== NULL
)
15351 root_plt
= &local_iplt
->root
;
15352 arm_plt
= &local_iplt
->arm
;
15355 /* If the symbol is a function that doesn't bind locally,
15356 this relocation will need a PLT entry. */
15357 if (root_plt
->refcount
!= -1)
15358 root_plt
->refcount
+= 1;
15361 arm_plt
->noncall_refcount
++;
15363 /* It's too early to use htab->use_blx here, so we have to
15364 record possible blx references separately from
15365 relocs that definitely need a thumb stub. */
15367 if (r_type
== R_ARM_THM_CALL
)
15368 arm_plt
->maybe_thumb_refcount
+= 1;
15370 if (r_type
== R_ARM_THM_JUMP24
15371 || r_type
== R_ARM_THM_JUMP19
)
15372 arm_plt
->thumb_refcount
+= 1;
15375 if (may_become_dynamic_p
)
15377 struct elf_dyn_relocs
*p
, **head
;
15379 /* Create a reloc section in dynobj. */
15380 if (sreloc
== NULL
)
15382 sreloc
= _bfd_elf_make_dynamic_reloc_section
15383 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
15385 if (sreloc
== NULL
)
15388 /* BPABI objects never have dynamic relocations mapped. */
15389 if (htab
->symbian_p
)
15393 flags
= bfd_get_section_flags (dynobj
, sreloc
);
15394 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
15395 bfd_set_section_flags (dynobj
, sreloc
, flags
);
15399 /* If this is a global symbol, count the number of
15400 relocations we need for this symbol. */
15402 head
= &((struct elf32_arm_link_hash_entry
*) h
)->dyn_relocs
;
15405 head
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
15411 if (p
== NULL
|| p
->sec
!= sec
)
15413 bfd_size_type amt
= sizeof *p
;
15415 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->root
.dynobj
, amt
);
15425 if (elf32_arm_howto_from_type (r_type
)->pc_relative
)
15428 if (h
== NULL
&& htab
->fdpic_p
&& !bfd_link_pic(info
)
15429 && r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_ABS32_NOI
) {
15430 /* Here we only support R_ARM_ABS32 and R_ARM_ABS32_NOI
15431 that will become rofixup. */
15432 /* This is due to the fact that we suppose all will become rofixup. */
15433 fprintf(stderr
, "FDPIC does not yet support %d relocation to become dynamic for executable\n", r_type
);
15435 (_("FDPIC does not yet support %s relocation"
15436 " to become dynamic for executable"),
15437 elf32_arm_howto_table_1
[r_type
].name
);
15447 elf32_arm_update_relocs (asection
*o
,
15448 struct bfd_elf_section_reloc_data
*reldata
)
15450 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
15451 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
15452 const struct elf_backend_data
*bed
;
15453 _arm_elf_section_data
*eado
;
15454 struct bfd_link_order
*p
;
15455 bfd_byte
*erela_head
, *erela
;
15456 Elf_Internal_Rela
*irela_head
, *irela
;
15457 Elf_Internal_Shdr
*rel_hdr
;
15459 unsigned int count
;
15461 eado
= get_arm_elf_section_data (o
);
15463 if (!eado
|| eado
->elf
.this_hdr
.sh_type
!= SHT_ARM_EXIDX
)
15467 bed
= get_elf_backend_data (abfd
);
15468 rel_hdr
= reldata
->hdr
;
15470 if (rel_hdr
->sh_entsize
== bed
->s
->sizeof_rel
)
15472 swap_in
= bed
->s
->swap_reloc_in
;
15473 swap_out
= bed
->s
->swap_reloc_out
;
15475 else if (rel_hdr
->sh_entsize
== bed
->s
->sizeof_rela
)
15477 swap_in
= bed
->s
->swap_reloca_in
;
15478 swap_out
= bed
->s
->swap_reloca_out
;
15483 erela_head
= rel_hdr
->contents
;
15484 irela_head
= (Elf_Internal_Rela
*) bfd_zmalloc
15485 ((NUM_SHDR_ENTRIES (rel_hdr
) + 1) * sizeof (*irela_head
));
15487 erela
= erela_head
;
15488 irela
= irela_head
;
15491 for (p
= o
->map_head
.link_order
; p
; p
= p
->next
)
15493 if (p
->type
== bfd_section_reloc_link_order
15494 || p
->type
== bfd_symbol_reloc_link_order
)
15496 (*swap_in
) (abfd
, erela
, irela
);
15497 erela
+= rel_hdr
->sh_entsize
;
15501 else if (p
->type
== bfd_indirect_link_order
)
15503 struct bfd_elf_section_reloc_data
*input_reldata
;
15504 arm_unwind_table_edit
*edit_list
, *edit_tail
;
15505 _arm_elf_section_data
*eadi
;
15510 i
= p
->u
.indirect
.section
;
15512 eadi
= get_arm_elf_section_data (i
);
15513 edit_list
= eadi
->u
.exidx
.unwind_edit_list
;
15514 edit_tail
= eadi
->u
.exidx
.unwind_edit_tail
;
15515 offset
= o
->vma
+ i
->output_offset
;
15517 if (eadi
->elf
.rel
.hdr
&&
15518 eadi
->elf
.rel
.hdr
->sh_entsize
== rel_hdr
->sh_entsize
)
15519 input_reldata
= &eadi
->elf
.rel
;
15520 else if (eadi
->elf
.rela
.hdr
&&
15521 eadi
->elf
.rela
.hdr
->sh_entsize
== rel_hdr
->sh_entsize
)
15522 input_reldata
= &eadi
->elf
.rela
;
15528 for (j
= 0; j
< NUM_SHDR_ENTRIES (input_reldata
->hdr
); j
++)
15530 arm_unwind_table_edit
*edit_node
, *edit_next
;
15532 bfd_vma reloc_index
;
15534 (*swap_in
) (abfd
, erela
, irela
);
15535 reloc_index
= (irela
->r_offset
- offset
) / 8;
15538 edit_node
= edit_list
;
15539 for (edit_next
= edit_list
;
15540 edit_next
&& edit_next
->index
<= reloc_index
;
15541 edit_next
= edit_node
->next
)
15544 edit_node
= edit_next
;
15547 if (edit_node
->type
!= DELETE_EXIDX_ENTRY
15548 || edit_node
->index
!= reloc_index
)
15550 irela
->r_offset
-= bias
* 8;
15555 erela
+= rel_hdr
->sh_entsize
;
15558 if (edit_tail
->type
== INSERT_EXIDX_CANTUNWIND_AT_END
)
15560 /* New relocation entity. */
15561 asection
*text_sec
= edit_tail
->linked_section
;
15562 asection
*text_out
= text_sec
->output_section
;
15563 bfd_vma exidx_offset
= offset
+ i
->size
- 8;
15565 irela
->r_addend
= 0;
15566 irela
->r_offset
= exidx_offset
;
15567 irela
->r_info
= ELF32_R_INFO
15568 (text_out
->target_index
, R_ARM_PREL31
);
15575 for (j
= 0; j
< NUM_SHDR_ENTRIES (input_reldata
->hdr
); j
++)
15577 (*swap_in
) (abfd
, erela
, irela
);
15578 erela
+= rel_hdr
->sh_entsize
;
15582 count
+= NUM_SHDR_ENTRIES (input_reldata
->hdr
);
15587 reldata
->count
= count
;
15588 rel_hdr
->sh_size
= count
* rel_hdr
->sh_entsize
;
15590 erela
= erela_head
;
15591 irela
= irela_head
;
15594 (*swap_out
) (abfd
, irela
, erela
);
15595 erela
+= rel_hdr
->sh_entsize
;
15602 /* Hashes are no longer valid. */
15603 free (reldata
->hashes
);
15604 reldata
->hashes
= NULL
;
15607 /* Unwinding tables are not referenced directly. This pass marks them as
15608 required if the corresponding code section is marked. Similarly, ARMv8-M
15609 secure entry functions can only be referenced by SG veneers which are
15610 created after the GC process. They need to be marked in case they reside in
15611 their own section (as would be the case if code was compiled with
15612 -ffunction-sections). */
15615 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
15616 elf_gc_mark_hook_fn gc_mark_hook
)
15619 Elf_Internal_Shdr
**elf_shdrp
;
15620 asection
*cmse_sec
;
15621 obj_attribute
*out_attr
;
15622 Elf_Internal_Shdr
*symtab_hdr
;
15623 unsigned i
, sym_count
, ext_start
;
15624 const struct elf_backend_data
*bed
;
15625 struct elf_link_hash_entry
**sym_hashes
;
15626 struct elf32_arm_link_hash_entry
*cmse_hash
;
15627 bfd_boolean again
, is_v8m
, first_bfd_browse
= TRUE
;
15629 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
15631 out_attr
= elf_known_obj_attributes_proc (info
->output_bfd
);
15632 is_v8m
= out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V8M_BASE
15633 && out_attr
[Tag_CPU_arch_profile
].i
== 'M';
15635 /* Marking EH data may cause additional code sections to be marked,
15636 requiring multiple passes. */
15641 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
15645 if (! is_arm_elf (sub
))
15648 elf_shdrp
= elf_elfsections (sub
);
15649 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
15651 Elf_Internal_Shdr
*hdr
;
15653 hdr
= &elf_section_data (o
)->this_hdr
;
15654 if (hdr
->sh_type
== SHT_ARM_EXIDX
15656 && hdr
->sh_link
< elf_numsections (sub
)
15658 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
15661 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
15666 /* Mark section holding ARMv8-M secure entry functions. We mark all
15667 of them so no need for a second browsing. */
15668 if (is_v8m
&& first_bfd_browse
)
15670 sym_hashes
= elf_sym_hashes (sub
);
15671 bed
= get_elf_backend_data (sub
);
15672 symtab_hdr
= &elf_tdata (sub
)->symtab_hdr
;
15673 sym_count
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
15674 ext_start
= symtab_hdr
->sh_info
;
15676 /* Scan symbols. */
15677 for (i
= ext_start
; i
< sym_count
; i
++)
15679 cmse_hash
= elf32_arm_hash_entry (sym_hashes
[i
- ext_start
]);
15681 /* Assume it is a special symbol. If not, cmse_scan will
15682 warn about it and user can do something about it. */
15683 if (ARM_GET_SYM_CMSE_SPCL (cmse_hash
->root
.target_internal
))
15685 cmse_sec
= cmse_hash
->root
.root
.u
.def
.section
;
15686 if (!cmse_sec
->gc_mark
15687 && !_bfd_elf_gc_mark (info
, cmse_sec
, gc_mark_hook
))
15693 first_bfd_browse
= FALSE
;
15699 /* Treat mapping symbols as special target symbols. */
15702 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
15704 return bfd_is_arm_special_symbol_name (sym
->name
,
15705 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
15708 /* This is a copy of elf_find_function() from elf.c except that
15709 ARM mapping symbols are ignored when looking for function names
15710 and STT_ARM_TFUNC is considered to a function type. */
15713 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
15714 asymbol
** symbols
,
15715 asection
* section
,
15717 const char ** filename_ptr
,
15718 const char ** functionname_ptr
)
15720 const char * filename
= NULL
;
15721 asymbol
* func
= NULL
;
15722 bfd_vma low_func
= 0;
15725 for (p
= symbols
; *p
!= NULL
; p
++)
15727 elf_symbol_type
*q
;
15729 q
= (elf_symbol_type
*) *p
;
15731 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
15736 filename
= bfd_asymbol_name (&q
->symbol
);
15739 case STT_ARM_TFUNC
:
15741 /* Skip mapping symbols. */
15742 if ((q
->symbol
.flags
& BSF_LOCAL
)
15743 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
15744 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
15746 /* Fall through. */
15747 if (bfd_get_section (&q
->symbol
) == section
15748 && q
->symbol
.value
>= low_func
15749 && q
->symbol
.value
<= offset
)
15751 func
= (asymbol
*) q
;
15752 low_func
= q
->symbol
.value
;
15762 *filename_ptr
= filename
;
15763 if (functionname_ptr
)
15764 *functionname_ptr
= bfd_asymbol_name (func
);
15770 /* Find the nearest line to a particular section and offset, for error
15771 reporting. This code is a duplicate of the code in elf.c, except
15772 that it uses arm_elf_find_function. */
15775 elf32_arm_find_nearest_line (bfd
* abfd
,
15776 asymbol
** symbols
,
15777 asection
* section
,
15779 const char ** filename_ptr
,
15780 const char ** functionname_ptr
,
15781 unsigned int * line_ptr
,
15782 unsigned int * discriminator_ptr
)
15784 bfd_boolean found
= FALSE
;
15786 if (_bfd_dwarf2_find_nearest_line (abfd
, symbols
, NULL
, section
, offset
,
15787 filename_ptr
, functionname_ptr
,
15788 line_ptr
, discriminator_ptr
,
15789 dwarf_debug_sections
, 0,
15790 & elf_tdata (abfd
)->dwarf2_find_line_info
))
15792 if (!*functionname_ptr
)
15793 arm_elf_find_function (abfd
, symbols
, section
, offset
,
15794 *filename_ptr
? NULL
: filename_ptr
,
15800 /* Skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain
15803 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
15804 & found
, filename_ptr
,
15805 functionname_ptr
, line_ptr
,
15806 & elf_tdata (abfd
)->line_info
))
15809 if (found
&& (*functionname_ptr
|| *line_ptr
))
15812 if (symbols
== NULL
)
15815 if (! arm_elf_find_function (abfd
, symbols
, section
, offset
,
15816 filename_ptr
, functionname_ptr
))
15824 elf32_arm_find_inliner_info (bfd
* abfd
,
15825 const char ** filename_ptr
,
15826 const char ** functionname_ptr
,
15827 unsigned int * line_ptr
)
15830 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
15831 functionname_ptr
, line_ptr
,
15832 & elf_tdata (abfd
)->dwarf2_find_line_info
);
15836 /* Find dynamic relocs for H that apply to read-only sections. */
15839 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
15841 struct elf_dyn_relocs
*p
;
15843 for (p
= elf32_arm_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
15845 asection
*s
= p
->sec
->output_section
;
15847 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
15853 /* Adjust a symbol defined by a dynamic object and referenced by a
15854 regular object. The current definition is in some section of the
15855 dynamic object, but we're not including those sections. We have to
15856 change the definition to something the rest of the link can
15860 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
15861 struct elf_link_hash_entry
* h
)
15864 asection
*s
, *srel
;
15865 struct elf32_arm_link_hash_entry
* eh
;
15866 struct elf32_arm_link_hash_table
*globals
;
15868 globals
= elf32_arm_hash_table (info
);
15869 if (globals
== NULL
)
15872 dynobj
= elf_hash_table (info
)->dynobj
;
15874 /* Make sure we know what is going on here. */
15875 BFD_ASSERT (dynobj
!= NULL
15877 || h
->type
== STT_GNU_IFUNC
15881 && !h
->def_regular
)));
15883 eh
= (struct elf32_arm_link_hash_entry
*) h
;
15885 /* If this is a function, put it in the procedure linkage table. We
15886 will fill in the contents of the procedure linkage table later,
15887 when we know the address of the .got section. */
15888 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
15890 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
15891 symbol binds locally. */
15892 if (h
->plt
.refcount
<= 0
15893 || (h
->type
!= STT_GNU_IFUNC
15894 && (SYMBOL_CALLS_LOCAL (info
, h
)
15895 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
15896 && h
->root
.type
== bfd_link_hash_undefweak
))))
15898 /* This case can occur if we saw a PLT32 reloc in an input
15899 file, but the symbol was never referred to by a dynamic
15900 object, or if all references were garbage collected. In
15901 such a case, we don't actually need to build a procedure
15902 linkage table, and we can just do a PC24 reloc instead. */
15903 h
->plt
.offset
= (bfd_vma
) -1;
15904 eh
->plt
.thumb_refcount
= 0;
15905 eh
->plt
.maybe_thumb_refcount
= 0;
15906 eh
->plt
.noncall_refcount
= 0;
15914 /* It's possible that we incorrectly decided a .plt reloc was
15915 needed for an R_ARM_PC24 or similar reloc to a non-function sym
15916 in check_relocs. We can't decide accurately between function
15917 and non-function syms in check-relocs; Objects loaded later in
15918 the link may change h->type. So fix it now. */
15919 h
->plt
.offset
= (bfd_vma
) -1;
15920 eh
->plt
.thumb_refcount
= 0;
15921 eh
->plt
.maybe_thumb_refcount
= 0;
15922 eh
->plt
.noncall_refcount
= 0;
15925 /* If this is a weak symbol, and there is a real definition, the
15926 processor independent code will have arranged for us to see the
15927 real definition first, and we can just use the same value. */
15928 if (h
->is_weakalias
)
15930 struct elf_link_hash_entry
*def
= weakdef (h
);
15931 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
15932 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
15933 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
15937 /* If there are no non-GOT references, we do not need a copy
15939 if (!h
->non_got_ref
)
15942 /* This is a reference to a symbol defined by a dynamic object which
15943 is not a function. */
15945 /* If we are creating a shared library, we must presume that the
15946 only references to the symbol are via the global offset table.
15947 For such cases we need not do anything here; the relocations will
15948 be handled correctly by relocate_section. Relocatable executables
15949 can reference data in shared objects directly, so we don't need to
15950 do anything here. */
15951 if (bfd_link_pic (info
) || globals
->root
.is_relocatable_executable
)
15954 /* We must allocate the symbol in our .dynbss section, which will
15955 become part of the .bss section of the executable. There will be
15956 an entry for this symbol in the .dynsym section. The dynamic
15957 object will contain position independent code, so all references
15958 from the dynamic object to this symbol will go through the global
15959 offset table. The dynamic linker will use the .dynsym entry to
15960 determine the address it must put in the global offset table, so
15961 both the dynamic object and the regular object will refer to the
15962 same memory location for the variable. */
15963 /* If allowed, we must generate a R_ARM_COPY reloc to tell the dynamic
15964 linker to copy the initial value out of the dynamic object and into
15965 the runtime process image. We need to remember the offset into the
15966 .rel(a).bss section we are going to use. */
15967 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
15969 s
= globals
->root
.sdynrelro
;
15970 srel
= globals
->root
.sreldynrelro
;
15974 s
= globals
->root
.sdynbss
;
15975 srel
= globals
->root
.srelbss
;
15977 if (info
->nocopyreloc
== 0
15978 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
15981 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
15985 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
15988 /* Allocate space in .plt, .got and associated reloc sections for
15992 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry
*h
, void * inf
)
15994 struct bfd_link_info
*info
;
15995 struct elf32_arm_link_hash_table
*htab
;
15996 struct elf32_arm_link_hash_entry
*eh
;
15997 struct elf_dyn_relocs
*p
;
15999 if (h
->root
.type
== bfd_link_hash_indirect
)
16002 eh
= (struct elf32_arm_link_hash_entry
*) h
;
16004 info
= (struct bfd_link_info
*) inf
;
16005 htab
= elf32_arm_hash_table (info
);
16009 if ((htab
->root
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
16010 && h
->plt
.refcount
> 0)
16012 /* Make sure this symbol is output as a dynamic symbol.
16013 Undefined weak syms won't yet be marked as dynamic. */
16014 if (h
->dynindx
== -1 && !h
->forced_local
16015 && h
->root
.type
== bfd_link_hash_undefweak
)
16017 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16021 /* If the call in the PLT entry binds locally, the associated
16022 GOT entry should use an R_ARM_IRELATIVE relocation instead of
16023 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
16024 than the .plt section. */
16025 if (h
->type
== STT_GNU_IFUNC
&& SYMBOL_CALLS_LOCAL (info
, h
))
16028 if (eh
->plt
.noncall_refcount
== 0
16029 && SYMBOL_REFERENCES_LOCAL (info
, h
))
16030 /* All non-call references can be resolved directly.
16031 This means that they can (and in some cases, must)
16032 resolve directly to the run-time target, rather than
16033 to the PLT. That in turns means that any .got entry
16034 would be equal to the .igot.plt entry, so there's
16035 no point having both. */
16036 h
->got
.refcount
= 0;
16039 if (bfd_link_pic (info
)
16041 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
16043 elf32_arm_allocate_plt_entry (info
, eh
->is_iplt
, &h
->plt
, &eh
->plt
);
16045 /* If this symbol is not defined in a regular file, and we are
16046 not generating a shared library, then set the symbol to this
16047 location in the .plt. This is required to make function
16048 pointers compare as equal between the normal executable and
16049 the shared library. */
16050 if (! bfd_link_pic (info
)
16051 && !h
->def_regular
)
16053 h
->root
.u
.def
.section
= htab
->root
.splt
;
16054 h
->root
.u
.def
.value
= h
->plt
.offset
;
16056 /* Make sure the function is not marked as Thumb, in case
16057 it is the target of an ABS32 relocation, which will
16058 point to the PLT entry. */
16059 ARM_SET_SYM_BRANCH_TYPE (h
->target_internal
, ST_BRANCH_TO_ARM
);
16062 /* VxWorks executables have a second set of relocations for
16063 each PLT entry. They go in a separate relocation section,
16064 which is processed by the kernel loader. */
16065 if (htab
->vxworks_p
&& !bfd_link_pic (info
))
16067 /* There is a relocation for the initial PLT entry:
16068 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
16069 if (h
->plt
.offset
== htab
->plt_header_size
)
16070 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 1);
16072 /* There are two extra relocations for each subsequent
16073 PLT entry: an R_ARM_32 relocation for the GOT entry,
16074 and an R_ARM_32 relocation for the PLT entry. */
16075 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 2);
16080 h
->plt
.offset
= (bfd_vma
) -1;
16086 h
->plt
.offset
= (bfd_vma
) -1;
16090 eh
= (struct elf32_arm_link_hash_entry
*) h
;
16091 eh
->tlsdesc_got
= (bfd_vma
) -1;
16093 if (h
->got
.refcount
> 0)
16097 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
16100 /* Make sure this symbol is output as a dynamic symbol.
16101 Undefined weak syms won't yet be marked as dynamic. */
16102 if (htab
->root
.dynamic_sections_created
&& h
->dynindx
== -1 && !h
->forced_local
16103 && h
->root
.type
== bfd_link_hash_undefweak
)
16105 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16109 if (!htab
->symbian_p
)
16111 s
= htab
->root
.sgot
;
16112 h
->got
.offset
= s
->size
;
16114 if (tls_type
== GOT_UNKNOWN
)
16117 if (tls_type
== GOT_NORMAL
)
16118 /* Non-TLS symbols need one GOT slot. */
16122 if (tls_type
& GOT_TLS_GDESC
)
16124 /* R_ARM_TLS_DESC needs 2 GOT slots. */
16126 = (htab
->root
.sgotplt
->size
16127 - elf32_arm_compute_jump_table_size (htab
));
16128 htab
->root
.sgotplt
->size
+= 8;
16129 h
->got
.offset
= (bfd_vma
) -2;
16130 /* plt.got_offset needs to know there's a TLS_DESC
16131 reloc in the middle of .got.plt. */
16132 htab
->num_tls_desc
++;
16135 if (tls_type
& GOT_TLS_GD
)
16137 /* R_ARM_TLS_GD32 and R_ARM_TLS_GD32_FDPIC need two
16138 consecutive GOT slots. If the symbol is both GD
16139 and GDESC, got.offset may have been
16141 h
->got
.offset
= s
->size
;
16145 if (tls_type
& GOT_TLS_IE
)
16146 /* R_ARM_TLS_IE32/R_ARM_TLS_IE32_FDPIC need one GOT
16151 dyn
= htab
->root
.dynamic_sections_created
;
16154 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
16155 bfd_link_pic (info
),
16157 && (!bfd_link_pic (info
)
16158 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
16161 if (tls_type
!= GOT_NORMAL
16162 && (bfd_link_pic (info
) || indx
!= 0)
16163 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
16164 || h
->root
.type
!= bfd_link_hash_undefweak
))
16166 if (tls_type
& GOT_TLS_IE
)
16167 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16169 if (tls_type
& GOT_TLS_GD
)
16170 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16172 if (tls_type
& GOT_TLS_GDESC
)
16174 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
16175 /* GDESC needs a trampoline to jump to. */
16176 htab
->tls_trampoline
= -1;
16179 /* Only GD needs it. GDESC just emits one relocation per
16181 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
16182 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16184 else if (((indx
!= -1) || htab
->fdpic_p
)
16185 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
16187 if (htab
->root
.dynamic_sections_created
)
16188 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
16189 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16191 else if (h
->type
== STT_GNU_IFUNC
16192 && eh
->plt
.noncall_refcount
== 0)
16193 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
16194 they all resolve dynamically instead. Reserve room for the
16195 GOT entry's R_ARM_IRELATIVE relocation. */
16196 elf32_arm_allocate_irelocs (info
, htab
->root
.srelgot
, 1);
16197 else if (bfd_link_pic (info
)
16198 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
16199 || h
->root
.type
!= bfd_link_hash_undefweak
))
16200 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
16201 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16202 else if (htab
->fdpic_p
&& tls_type
== GOT_NORMAL
)
16203 /* Reserve room for rofixup for FDPIC executable. */
16204 /* TLS relocs do not need space since they are completely
16206 htab
->srofixup
->size
+= 4;
16210 h
->got
.offset
= (bfd_vma
) -1;
16212 /* FDPIC support. */
16213 if (eh
->fdpic_cnts
.gotofffuncdesc_cnt
> 0)
16215 /* Symbol musn't be exported. */
16216 if (h
->dynindx
!= -1)
16219 /* We only allocate one function descriptor with its associated relocation. */
16220 if (eh
->fdpic_cnts
.funcdesc_offset
== -1)
16222 asection
*s
= htab
->root
.sgot
;
16224 eh
->fdpic_cnts
.funcdesc_offset
= s
->size
;
16226 /* We will add an R_ARM_FUNCDESC_VALUE relocation or two rofixups. */
16227 if (bfd_link_pic(info
))
16228 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16230 htab
->srofixup
->size
+= 8;
16234 if (eh
->fdpic_cnts
.gotfuncdesc_cnt
> 0)
16236 asection
*s
= htab
->root
.sgot
;
16238 if (htab
->root
.dynamic_sections_created
&& h
->dynindx
== -1
16239 && !h
->forced_local
)
16240 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16243 if (h
->dynindx
== -1)
16245 /* We only allocate one function descriptor with its associated relocation. q */
16246 if (eh
->fdpic_cnts
.funcdesc_offset
== -1)
16249 eh
->fdpic_cnts
.funcdesc_offset
= s
->size
;
16251 /* We will add an R_ARM_FUNCDESC_VALUE relocation or two rofixups. */
16252 if (bfd_link_pic(info
))
16253 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16255 htab
->srofixup
->size
+= 8;
16259 /* Add one entry into the GOT and a R_ARM_FUNCDESC or
16260 R_ARM_RELATIVE/rofixup relocation on it. */
16261 eh
->fdpic_cnts
.gotfuncdesc_offset
= s
->size
;
16263 if (h
->dynindx
== -1 && !bfd_link_pic(info
))
16264 htab
->srofixup
->size
+= 4;
16266 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16269 if (eh
->fdpic_cnts
.funcdesc_cnt
> 0)
16271 if (htab
->root
.dynamic_sections_created
&& h
->dynindx
== -1
16272 && !h
->forced_local
)
16273 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16276 if (h
->dynindx
== -1)
16278 /* We only allocate one function descriptor with its associated relocation. */
16279 if (eh
->fdpic_cnts
.funcdesc_offset
== -1)
16281 asection
*s
= htab
->root
.sgot
;
16283 eh
->fdpic_cnts
.funcdesc_offset
= s
->size
;
16285 /* We will add an R_ARM_FUNCDESC_VALUE relocation or two rofixups. */
16286 if (bfd_link_pic(info
))
16287 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16289 htab
->srofixup
->size
+= 8;
16292 if (h
->dynindx
== -1 && !bfd_link_pic(info
))
16294 /* For FDPIC executable we replace R_ARM_RELATIVE with a rofixup. */
16295 htab
->srofixup
->size
+= 4 * eh
->fdpic_cnts
.funcdesc_cnt
;
16299 /* Will need one dynamic reloc per reference. will be either
16300 R_ARM_FUNCDESC or R_ARM_RELATIVE for hidden symbols. */
16301 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
,
16302 eh
->fdpic_cnts
.funcdesc_cnt
);
16306 /* Allocate stubs for exported Thumb functions on v4t. */
16307 if (!htab
->use_blx
&& h
->dynindx
!= -1
16309 && ARM_GET_SYM_BRANCH_TYPE (h
->target_internal
) == ST_BRANCH_TO_THUMB
16310 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
16312 struct elf_link_hash_entry
* th
;
16313 struct bfd_link_hash_entry
* bh
;
16314 struct elf_link_hash_entry
* myh
;
16318 /* Create a new symbol to regist the real location of the function. */
16319 s
= h
->root
.u
.def
.section
;
16320 sprintf (name
, "__real_%s", h
->root
.root
.string
);
16321 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
16322 name
, BSF_GLOBAL
, s
,
16323 h
->root
.u
.def
.value
,
16324 NULL
, TRUE
, FALSE
, &bh
);
16326 myh
= (struct elf_link_hash_entry
*) bh
;
16327 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
16328 myh
->forced_local
= 1;
16329 ARM_SET_SYM_BRANCH_TYPE (myh
->target_internal
, ST_BRANCH_TO_THUMB
);
16330 eh
->export_glue
= myh
;
16331 th
= record_arm_to_thumb_glue (info
, h
);
16332 /* Point the symbol at the stub. */
16333 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
16334 ARM_SET_SYM_BRANCH_TYPE (h
->target_internal
, ST_BRANCH_TO_ARM
);
16335 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
16336 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
16339 if (eh
->dyn_relocs
== NULL
)
16342 /* In the shared -Bsymbolic case, discard space allocated for
16343 dynamic pc-relative relocs against symbols which turn out to be
16344 defined in regular objects. For the normal shared case, discard
16345 space for pc-relative relocs that have become local due to symbol
16346 visibility changes. */
16348 if (bfd_link_pic (info
) || htab
->root
.is_relocatable_executable
|| htab
->fdpic_p
)
16350 /* Relocs that use pc_count are PC-relative forms, which will appear
16351 on something like ".long foo - ." or "movw REG, foo - .". We want
16352 calls to protected symbols to resolve directly to the function
16353 rather than going via the plt. If people want function pointer
16354 comparisons to work as expected then they should avoid writing
16355 assembly like ".long foo - .". */
16356 if (SYMBOL_CALLS_LOCAL (info
, h
))
16358 struct elf_dyn_relocs
**pp
;
16360 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
16362 p
->count
-= p
->pc_count
;
16371 if (htab
->vxworks_p
)
16373 struct elf_dyn_relocs
**pp
;
16375 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
16377 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
16384 /* Also discard relocs on undefined weak syms with non-default
16386 if (eh
->dyn_relocs
!= NULL
16387 && h
->root
.type
== bfd_link_hash_undefweak
)
16389 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
16390 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
16391 eh
->dyn_relocs
= NULL
;
16393 /* Make sure undefined weak symbols are output as a dynamic
16395 else if (htab
->root
.dynamic_sections_created
&& h
->dynindx
== -1
16396 && !h
->forced_local
)
16398 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16403 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
16404 && h
->root
.type
== bfd_link_hash_new
)
16406 /* Output absolute symbols so that we can create relocations
16407 against them. For normal symbols we output a relocation
16408 against the section that contains them. */
16409 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16416 /* For the non-shared case, discard space for relocs against
16417 symbols which turn out to need copy relocs or are not
16420 if (!h
->non_got_ref
16421 && ((h
->def_dynamic
16422 && !h
->def_regular
)
16423 || (htab
->root
.dynamic_sections_created
16424 && (h
->root
.type
== bfd_link_hash_undefweak
16425 || h
->root
.type
== bfd_link_hash_undefined
))))
16427 /* Make sure this symbol is output as a dynamic symbol.
16428 Undefined weak syms won't yet be marked as dynamic. */
16429 if (h
->dynindx
== -1 && !h
->forced_local
16430 && h
->root
.type
== bfd_link_hash_undefweak
)
16432 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
16436 /* If that succeeded, we know we'll be keeping all the
16438 if (h
->dynindx
!= -1)
16442 eh
->dyn_relocs
= NULL
;
16447 /* Finally, allocate space. */
16448 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
16450 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
16452 if (h
->type
== STT_GNU_IFUNC
16453 && eh
->plt
.noncall_refcount
== 0
16454 && SYMBOL_REFERENCES_LOCAL (info
, h
))
16455 elf32_arm_allocate_irelocs (info
, sreloc
, p
->count
);
16456 else if (h
->dynindx
!= -1 && (!bfd_link_pic(info
) || !info
->symbolic
|| !h
->def_regular
))
16457 elf32_arm_allocate_dynrelocs (info
, sreloc
, p
->count
);
16458 else if (htab
->fdpic_p
&& !bfd_link_pic(info
))
16459 htab
->srofixup
->size
+= 4 * p
->count
;
16461 elf32_arm_allocate_dynrelocs (info
, sreloc
, p
->count
);
16467 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
16468 read-only sections. */
16471 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info_p
)
16475 if (h
->root
.type
== bfd_link_hash_indirect
)
16478 sec
= readonly_dynrelocs (h
);
16481 struct bfd_link_info
*info
= (struct bfd_link_info
*) info_p
;
16483 info
->flags
|= DF_TEXTREL
;
16484 info
->callbacks
->minfo
16485 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
16486 sec
->owner
, h
->root
.root
.string
, sec
);
16488 /* Not an error, just cut short the traversal. */
16496 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
16499 struct elf32_arm_link_hash_table
*globals
;
16501 globals
= elf32_arm_hash_table (info
);
16502 if (globals
== NULL
)
16505 globals
->byteswap_code
= byteswap_code
;
16508 /* Set the sizes of the dynamic sections. */
16511 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
16512 struct bfd_link_info
* info
)
16517 bfd_boolean relocs
;
16519 struct elf32_arm_link_hash_table
*htab
;
16521 htab
= elf32_arm_hash_table (info
);
16525 dynobj
= elf_hash_table (info
)->dynobj
;
16526 BFD_ASSERT (dynobj
!= NULL
);
16527 check_use_blx (htab
);
16529 if (elf_hash_table (info
)->dynamic_sections_created
)
16531 /* Set the contents of the .interp section to the interpreter. */
16532 if (bfd_link_executable (info
) && !info
->nointerp
)
16534 s
= bfd_get_linker_section (dynobj
, ".interp");
16535 BFD_ASSERT (s
!= NULL
);
16536 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
16537 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
16541 /* Set up .got offsets for local syms, and space for local dynamic
16543 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
16545 bfd_signed_vma
*local_got
;
16546 bfd_signed_vma
*end_local_got
;
16547 struct arm_local_iplt_info
**local_iplt_ptr
, *local_iplt
;
16548 char *local_tls_type
;
16549 bfd_vma
*local_tlsdesc_gotent
;
16550 bfd_size_type locsymcount
;
16551 Elf_Internal_Shdr
*symtab_hdr
;
16553 bfd_boolean is_vxworks
= htab
->vxworks_p
;
16554 unsigned int symndx
;
16555 struct fdpic_local
*local_fdpic_cnts
;
16557 if (! is_arm_elf (ibfd
))
16560 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
16562 struct elf_dyn_relocs
*p
;
16564 for (p
= (struct elf_dyn_relocs
*)
16565 elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
16567 if (!bfd_is_abs_section (p
->sec
)
16568 && bfd_is_abs_section (p
->sec
->output_section
))
16570 /* Input section has been discarded, either because
16571 it is a copy of a linkonce section or due to
16572 linker script /DISCARD/, so we'll be discarding
16575 else if (is_vxworks
16576 && strcmp (p
->sec
->output_section
->name
,
16579 /* Relocations in vxworks .tls_vars sections are
16580 handled specially by the loader. */
16582 else if (p
->count
!= 0)
16584 srel
= elf_section_data (p
->sec
)->sreloc
;
16585 if (htab
->fdpic_p
&& !bfd_link_pic(info
))
16586 htab
->srofixup
->size
+= 4 * p
->count
;
16588 elf32_arm_allocate_dynrelocs (info
, srel
, p
->count
);
16589 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
16590 info
->flags
|= DF_TEXTREL
;
16595 local_got
= elf_local_got_refcounts (ibfd
);
16599 symtab_hdr
= & elf_symtab_hdr (ibfd
);
16600 locsymcount
= symtab_hdr
->sh_info
;
16601 end_local_got
= local_got
+ locsymcount
;
16602 local_iplt_ptr
= elf32_arm_local_iplt (ibfd
);
16603 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
16604 local_tlsdesc_gotent
= elf32_arm_local_tlsdesc_gotent (ibfd
);
16605 local_fdpic_cnts
= elf32_arm_local_fdpic_cnts (ibfd
);
16607 s
= htab
->root
.sgot
;
16608 srel
= htab
->root
.srelgot
;
16609 for (; local_got
< end_local_got
;
16610 ++local_got
, ++local_iplt_ptr
, ++local_tls_type
,
16611 ++local_tlsdesc_gotent
, ++symndx
, ++local_fdpic_cnts
)
16613 *local_tlsdesc_gotent
= (bfd_vma
) -1;
16614 local_iplt
= *local_iplt_ptr
;
16616 /* FDPIC support. */
16617 if (local_fdpic_cnts
->gotofffuncdesc_cnt
> 0)
16619 if (local_fdpic_cnts
->funcdesc_offset
== -1)
16621 local_fdpic_cnts
->funcdesc_offset
= s
->size
;
16624 /* We will add an R_ARM_FUNCDESC_VALUE relocation or two rofixups. */
16625 if (bfd_link_pic(info
))
16626 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
16628 htab
->srofixup
->size
+= 8;
16632 if (local_fdpic_cnts
->funcdesc_cnt
> 0)
16634 if (local_fdpic_cnts
->funcdesc_offset
== -1)
16636 local_fdpic_cnts
->funcdesc_offset
= s
->size
;
16639 /* We will add an R_ARM_FUNCDESC_VALUE relocation or two rofixups. */
16640 if (bfd_link_pic(info
))
16641 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
16643 htab
->srofixup
->size
+= 8;
16646 /* We will add n R_ARM_RELATIVE relocations or n rofixups. */
16647 if (bfd_link_pic(info
))
16648 elf32_arm_allocate_dynrelocs (info
, srel
, local_fdpic_cnts
->funcdesc_cnt
);
16650 htab
->srofixup
->size
+= 4 * local_fdpic_cnts
->funcdesc_cnt
;
16653 if (local_iplt
!= NULL
)
16655 struct elf_dyn_relocs
*p
;
16657 if (local_iplt
->root
.refcount
> 0)
16659 elf32_arm_allocate_plt_entry (info
, TRUE
,
16662 if (local_iplt
->arm
.noncall_refcount
== 0)
16663 /* All references to the PLT are calls, so all
16664 non-call references can resolve directly to the
16665 run-time target. This means that the .got entry
16666 would be the same as the .igot.plt entry, so there's
16667 no point creating both. */
16672 BFD_ASSERT (local_iplt
->arm
.noncall_refcount
== 0);
16673 local_iplt
->root
.offset
= (bfd_vma
) -1;
16676 for (p
= local_iplt
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
16680 psrel
= elf_section_data (p
->sec
)->sreloc
;
16681 if (local_iplt
->arm
.noncall_refcount
== 0)
16682 elf32_arm_allocate_irelocs (info
, psrel
, p
->count
);
16684 elf32_arm_allocate_dynrelocs (info
, psrel
, p
->count
);
16687 if (*local_got
> 0)
16689 Elf_Internal_Sym
*isym
;
16691 *local_got
= s
->size
;
16692 if (*local_tls_type
& GOT_TLS_GD
)
16693 /* TLS_GD relocs need an 8-byte structure in the GOT. */
16695 if (*local_tls_type
& GOT_TLS_GDESC
)
16697 *local_tlsdesc_gotent
= htab
->root
.sgotplt
->size
16698 - elf32_arm_compute_jump_table_size (htab
);
16699 htab
->root
.sgotplt
->size
+= 8;
16700 *local_got
= (bfd_vma
) -2;
16701 /* plt.got_offset needs to know there's a TLS_DESC
16702 reloc in the middle of .got.plt. */
16703 htab
->num_tls_desc
++;
16705 if (*local_tls_type
& GOT_TLS_IE
)
16708 if (*local_tls_type
& GOT_NORMAL
)
16710 /* If the symbol is both GD and GDESC, *local_got
16711 may have been overwritten. */
16712 *local_got
= s
->size
;
16716 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, symndx
);
16720 /* If all references to an STT_GNU_IFUNC PLT are calls,
16721 then all non-call references, including this GOT entry,
16722 resolve directly to the run-time target. */
16723 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
16724 && (local_iplt
== NULL
16725 || local_iplt
->arm
.noncall_refcount
== 0))
16726 elf32_arm_allocate_irelocs (info
, srel
, 1);
16727 else if (bfd_link_pic (info
) || output_bfd
->flags
& DYNAMIC
|| htab
->fdpic_p
)
16729 if ((bfd_link_pic (info
) && !(*local_tls_type
& GOT_TLS_GDESC
)))
16730 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
16731 else if (htab
->fdpic_p
&& *local_tls_type
& GOT_NORMAL
)
16732 htab
->srofixup
->size
+= 4;
16734 if ((bfd_link_pic (info
) || htab
->fdpic_p
)
16735 && *local_tls_type
& GOT_TLS_GDESC
)
16737 elf32_arm_allocate_dynrelocs (info
,
16738 htab
->root
.srelplt
, 1);
16739 htab
->tls_trampoline
= -1;
16744 *local_got
= (bfd_vma
) -1;
16748 if (htab
->tls_ldm_got
.refcount
> 0)
16750 /* Allocate two GOT entries and one dynamic relocation (if necessary)
16751 for R_ARM_TLS_LDM32/R_ARM_TLS_LDM32_FDPIC relocations. */
16752 htab
->tls_ldm_got
.offset
= htab
->root
.sgot
->size
;
16753 htab
->root
.sgot
->size
+= 8;
16754 if (bfd_link_pic (info
))
16755 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
16758 htab
->tls_ldm_got
.offset
= -1;
16760 /* At the very end of the .rofixup section is a pointer to the GOT,
16761 reserve space for it. */
16762 if (htab
->fdpic_p
&& htab
->srofixup
!= NULL
)
16763 htab
->srofixup
->size
+= 4;
16765 /* Allocate global sym .plt and .got entries, and space for global
16766 sym dynamic relocs. */
16767 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs_for_symbol
, info
);
16769 /* Here we rummage through the found bfds to collect glue information. */
16770 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
16772 if (! is_arm_elf (ibfd
))
16775 /* Initialise mapping tables for code/data. */
16776 bfd_elf32_arm_init_maps (ibfd
);
16778 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
16779 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
)
16780 || !bfd_elf32_arm_stm32l4xx_erratum_scan (ibfd
, info
))
16781 _bfd_error_handler (_("errors encountered processing file %pB"), ibfd
);
16784 /* Allocate space for the glue sections now that we've sized them. */
16785 bfd_elf32_arm_allocate_interworking_sections (info
);
16787 /* For every jump slot reserved in the sgotplt, reloc_count is
16788 incremented. However, when we reserve space for TLS descriptors,
16789 it's not incremented, so in order to compute the space reserved
16790 for them, it suffices to multiply the reloc count by the jump
16792 if (htab
->root
.srelplt
)
16793 htab
->sgotplt_jump_table_size
= elf32_arm_compute_jump_table_size(htab
);
16795 if (htab
->tls_trampoline
)
16797 if (htab
->root
.splt
->size
== 0)
16798 htab
->root
.splt
->size
+= htab
->plt_header_size
;
16800 htab
->tls_trampoline
= htab
->root
.splt
->size
;
16801 htab
->root
.splt
->size
+= htab
->plt_entry_size
;
16803 /* If we're not using lazy TLS relocations, don't generate the
16804 PLT and GOT entries they require. */
16805 if (!(info
->flags
& DF_BIND_NOW
))
16807 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
16808 htab
->root
.sgot
->size
+= 4;
16810 htab
->dt_tlsdesc_plt
= htab
->root
.splt
->size
;
16811 htab
->root
.splt
->size
+= 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
);
16815 /* The check_relocs and adjust_dynamic_symbol entry points have
16816 determined the sizes of the various dynamic sections. Allocate
16817 memory for them. */
16820 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
16824 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
16827 /* It's OK to base decisions on the section name, because none
16828 of the dynobj section names depend upon the input files. */
16829 name
= bfd_get_section_name (dynobj
, s
);
16831 if (s
== htab
->root
.splt
)
16833 /* Remember whether there is a PLT. */
16834 plt
= s
->size
!= 0;
16836 else if (CONST_STRNEQ (name
, ".rel"))
16840 /* Remember whether there are any reloc sections other
16841 than .rel(a).plt and .rela.plt.unloaded. */
16842 if (s
!= htab
->root
.srelplt
&& s
!= htab
->srelplt2
)
16845 /* We use the reloc_count field as a counter if we need
16846 to copy relocs into the output file. */
16847 s
->reloc_count
= 0;
16850 else if (s
!= htab
->root
.sgot
16851 && s
!= htab
->root
.sgotplt
16852 && s
!= htab
->root
.iplt
16853 && s
!= htab
->root
.igotplt
16854 && s
!= htab
->root
.sdynbss
16855 && s
!= htab
->root
.sdynrelro
16856 && s
!= htab
->srofixup
)
16858 /* It's not one of our sections, so don't allocate space. */
16864 /* If we don't need this section, strip it from the
16865 output file. This is mostly to handle .rel(a).bss and
16866 .rel(a).plt. We must create both sections in
16867 create_dynamic_sections, because they must be created
16868 before the linker maps input sections to output
16869 sections. The linker does that before
16870 adjust_dynamic_symbol is called, and it is that
16871 function which decides whether anything needs to go
16872 into these sections. */
16873 s
->flags
|= SEC_EXCLUDE
;
16877 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
16880 /* Allocate memory for the section contents. */
16881 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
16882 if (s
->contents
== NULL
)
16886 if (elf_hash_table (info
)->dynamic_sections_created
)
16888 /* Add some entries to the .dynamic section. We fill in the
16889 values later, in elf32_arm_finish_dynamic_sections, but we
16890 must add the entries now so that we get the correct size for
16891 the .dynamic section. The DT_DEBUG entry is filled in by the
16892 dynamic linker and used by the debugger. */
16893 #define add_dynamic_entry(TAG, VAL) \
16894 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
16896 if (bfd_link_executable (info
))
16898 if (!add_dynamic_entry (DT_DEBUG
, 0))
16904 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
16905 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
16906 || !add_dynamic_entry (DT_PLTREL
,
16907 htab
->use_rel
? DT_REL
: DT_RELA
)
16908 || !add_dynamic_entry (DT_JMPREL
, 0))
16911 if (htab
->dt_tlsdesc_plt
16912 && (!add_dynamic_entry (DT_TLSDESC_PLT
,0)
16913 || !add_dynamic_entry (DT_TLSDESC_GOT
,0)))
16921 if (!add_dynamic_entry (DT_REL
, 0)
16922 || !add_dynamic_entry (DT_RELSZ
, 0)
16923 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
16928 if (!add_dynamic_entry (DT_RELA
, 0)
16929 || !add_dynamic_entry (DT_RELASZ
, 0)
16930 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
16935 /* If any dynamic relocs apply to a read-only section,
16936 then we need a DT_TEXTREL entry. */
16937 if ((info
->flags
& DF_TEXTREL
) == 0)
16938 elf_link_hash_traverse (&htab
->root
, maybe_set_textrel
, info
);
16940 if ((info
->flags
& DF_TEXTREL
) != 0)
16942 if (!add_dynamic_entry (DT_TEXTREL
, 0))
16945 if (htab
->vxworks_p
16946 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
16949 #undef add_dynamic_entry
16954 /* Size sections even though they're not dynamic. We use it to setup
16955 _TLS_MODULE_BASE_, if needed. */
16958 elf32_arm_always_size_sections (bfd
*output_bfd
,
16959 struct bfd_link_info
*info
)
16962 struct elf32_arm_link_hash_table
*htab
;
16964 htab
= elf32_arm_hash_table (info
);
16966 if (bfd_link_relocatable (info
))
16969 tls_sec
= elf_hash_table (info
)->tls_sec
;
16973 struct elf_link_hash_entry
*tlsbase
;
16975 tlsbase
= elf_link_hash_lookup
16976 (elf_hash_table (info
), "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
16980 struct bfd_link_hash_entry
*bh
= NULL
;
16981 const struct elf_backend_data
*bed
16982 = get_elf_backend_data (output_bfd
);
16984 if (!(_bfd_generic_link_add_one_symbol
16985 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
16986 tls_sec
, 0, NULL
, FALSE
,
16987 bed
->collect
, &bh
)))
16990 tlsbase
->type
= STT_TLS
;
16991 tlsbase
= (struct elf_link_hash_entry
*)bh
;
16992 tlsbase
->def_regular
= 1;
16993 tlsbase
->other
= STV_HIDDEN
;
16994 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
16998 if (htab
->fdpic_p
&& !bfd_link_relocatable (info
)
16999 && !bfd_elf_stack_segment_size (output_bfd
, info
,
17000 "__stacksize", DEFAULT_STACK_SIZE
))
17006 /* Finish up dynamic symbol handling. We set the contents of various
17007 dynamic sections here. */
17010 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
17011 struct bfd_link_info
* info
,
17012 struct elf_link_hash_entry
* h
,
17013 Elf_Internal_Sym
* sym
)
17015 struct elf32_arm_link_hash_table
*htab
;
17016 struct elf32_arm_link_hash_entry
*eh
;
17018 htab
= elf32_arm_hash_table (info
);
17022 eh
= (struct elf32_arm_link_hash_entry
*) h
;
17024 if (h
->plt
.offset
!= (bfd_vma
) -1)
17028 BFD_ASSERT (h
->dynindx
!= -1);
17029 if (! elf32_arm_populate_plt_entry (output_bfd
, info
, &h
->plt
, &eh
->plt
,
17034 if (!h
->def_regular
)
17036 /* Mark the symbol as undefined, rather than as defined in
17037 the .plt section. */
17038 sym
->st_shndx
= SHN_UNDEF
;
17039 /* If the symbol is weak we need to clear the value.
17040 Otherwise, the PLT entry would provide a definition for
17041 the symbol even if the symbol wasn't defined anywhere,
17042 and so the symbol would never be NULL. Leave the value if
17043 there were any relocations where pointer equality matters
17044 (this is a clue for the dynamic linker, to make function
17045 pointer comparisons work between an application and shared
17047 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
17050 else if (eh
->is_iplt
&& eh
->plt
.noncall_refcount
!= 0)
17052 /* At least one non-call relocation references this .iplt entry,
17053 so the .iplt entry is the function's canonical address. */
17054 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
17055 ARM_SET_SYM_BRANCH_TYPE (sym
->st_target_internal
, ST_BRANCH_TO_ARM
);
17056 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
17057 (output_bfd
, htab
->root
.iplt
->output_section
));
17058 sym
->st_value
= (h
->plt
.offset
17059 + htab
->root
.iplt
->output_section
->vma
17060 + htab
->root
.iplt
->output_offset
);
17067 Elf_Internal_Rela rel
;
17069 /* This symbol needs a copy reloc. Set it up. */
17070 BFD_ASSERT (h
->dynindx
!= -1
17071 && (h
->root
.type
== bfd_link_hash_defined
17072 || h
->root
.type
== bfd_link_hash_defweak
));
17075 rel
.r_offset
= (h
->root
.u
.def
.value
17076 + h
->root
.u
.def
.section
->output_section
->vma
17077 + h
->root
.u
.def
.section
->output_offset
);
17078 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
17079 if (h
->root
.u
.def
.section
== htab
->root
.sdynrelro
)
17080 s
= htab
->root
.sreldynrelro
;
17082 s
= htab
->root
.srelbss
;
17083 elf32_arm_add_dynreloc (output_bfd
, info
, s
, &rel
);
17086 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
17087 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
17088 to the ".got" section. */
17089 if (h
== htab
->root
.hdynamic
17090 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
17091 sym
->st_shndx
= SHN_ABS
;
17097 arm_put_trampoline (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
17099 const unsigned long *template, unsigned count
)
17103 for (ix
= 0; ix
!= count
; ix
++)
17105 unsigned long insn
= template[ix
];
17107 /* Emit mov pc,rx if bx is not permitted. */
17108 if (htab
->fix_v4bx
== 1 && (insn
& 0x0ffffff0) == 0x012fff10)
17109 insn
= (insn
& 0xf000000f) | 0x01a0f000;
17110 put_arm_insn (htab
, output_bfd
, insn
, (char *)contents
+ ix
*4);
17114 /* Install the special first PLT entry for elf32-arm-nacl. Unlike
17115 other variants, NaCl needs this entry in a static executable's
17116 .iplt too. When we're handling that case, GOT_DISPLACEMENT is
17117 zero. For .iplt really only the last bundle is useful, and .iplt
17118 could have a shorter first entry, with each individual PLT entry's
17119 relative branch calculated differently so it targets the last
17120 bundle instead of the instruction before it (labelled .Lplt_tail
17121 above). But it's simpler to keep the size and layout of PLT0
17122 consistent with the dynamic case, at the cost of some dead code at
17123 the start of .iplt and the one dead store to the stack at the start
17126 arm_nacl_put_plt0 (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
17127 asection
*plt
, bfd_vma got_displacement
)
17131 put_arm_insn (htab
, output_bfd
,
17132 elf32_arm_nacl_plt0_entry
[0]
17133 | arm_movw_immediate (got_displacement
),
17134 plt
->contents
+ 0);
17135 put_arm_insn (htab
, output_bfd
,
17136 elf32_arm_nacl_plt0_entry
[1]
17137 | arm_movt_immediate (got_displacement
),
17138 plt
->contents
+ 4);
17140 for (i
= 2; i
< ARRAY_SIZE (elf32_arm_nacl_plt0_entry
); ++i
)
17141 put_arm_insn (htab
, output_bfd
,
17142 elf32_arm_nacl_plt0_entry
[i
],
17143 plt
->contents
+ (i
* 4));
17146 /* Finish up the dynamic sections. */
17149 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
17154 struct elf32_arm_link_hash_table
*htab
;
17156 htab
= elf32_arm_hash_table (info
);
17160 dynobj
= elf_hash_table (info
)->dynobj
;
17162 sgot
= htab
->root
.sgotplt
;
17163 /* A broken linker script might have discarded the dynamic sections.
17164 Catch this here so that we do not seg-fault later on. */
17165 if (sgot
!= NULL
&& bfd_is_abs_section (sgot
->output_section
))
17167 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
17169 if (elf_hash_table (info
)->dynamic_sections_created
)
17172 Elf32_External_Dyn
*dyncon
, *dynconend
;
17174 splt
= htab
->root
.splt
;
17175 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
17176 BFD_ASSERT (htab
->symbian_p
|| sgot
!= NULL
);
17178 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
17179 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
17181 for (; dyncon
< dynconend
; dyncon
++)
17183 Elf_Internal_Dyn dyn
;
17187 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
17194 if (htab
->vxworks_p
17195 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
17196 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17201 goto get_vma_if_bpabi
;
17204 goto get_vma_if_bpabi
;
17207 goto get_vma_if_bpabi
;
17209 name
= ".gnu.version";
17210 goto get_vma_if_bpabi
;
17212 name
= ".gnu.version_d";
17213 goto get_vma_if_bpabi
;
17215 name
= ".gnu.version_r";
17216 goto get_vma_if_bpabi
;
17219 name
= htab
->symbian_p
? ".got" : ".got.plt";
17222 name
= RELOC_SECTION (htab
, ".plt");
17224 s
= bfd_get_linker_section (dynobj
, name
);
17228 (_("could not find section %s"), name
);
17229 bfd_set_error (bfd_error_invalid_operation
);
17232 if (!htab
->symbian_p
)
17233 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17235 /* In the BPABI, tags in the PT_DYNAMIC section point
17236 at the file offset, not the memory address, for the
17237 convenience of the post linker. */
17238 dyn
.d_un
.d_ptr
= s
->output_section
->filepos
+ s
->output_offset
;
17239 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17243 if (htab
->symbian_p
)
17248 s
= htab
->root
.srelplt
;
17249 BFD_ASSERT (s
!= NULL
);
17250 dyn
.d_un
.d_val
= s
->size
;
17251 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17258 /* In the BPABI, the DT_REL tag must point at the file
17259 offset, not the VMA, of the first relocation
17260 section. So, we use code similar to that in
17261 elflink.c, but do not check for SHF_ALLOC on the
17262 relocation section, since relocation sections are
17263 never allocated under the BPABI. PLT relocs are also
17265 if (htab
->symbian_p
)
17268 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
17269 ? SHT_REL
: SHT_RELA
);
17270 dyn
.d_un
.d_val
= 0;
17271 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
17273 Elf_Internal_Shdr
*hdr
17274 = elf_elfsections (output_bfd
)[i
];
17275 if (hdr
->sh_type
== type
)
17277 if (dyn
.d_tag
== DT_RELSZ
17278 || dyn
.d_tag
== DT_RELASZ
)
17279 dyn
.d_un
.d_val
+= hdr
->sh_size
;
17280 else if ((ufile_ptr
) hdr
->sh_offset
17281 <= dyn
.d_un
.d_val
- 1)
17282 dyn
.d_un
.d_val
= hdr
->sh_offset
;
17285 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17289 case DT_TLSDESC_PLT
:
17290 s
= htab
->root
.splt
;
17291 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
17292 + htab
->dt_tlsdesc_plt
);
17293 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17296 case DT_TLSDESC_GOT
:
17297 s
= htab
->root
.sgot
;
17298 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
17299 + htab
->dt_tlsdesc_got
);
17300 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17303 /* Set the bottom bit of DT_INIT/FINI if the
17304 corresponding function is Thumb. */
17306 name
= info
->init_function
;
17309 name
= info
->fini_function
;
17311 /* If it wasn't set by elf_bfd_final_link
17312 then there is nothing to adjust. */
17313 if (dyn
.d_un
.d_val
!= 0)
17315 struct elf_link_hash_entry
* eh
;
17317 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
17318 FALSE
, FALSE
, TRUE
);
17320 && ARM_GET_SYM_BRANCH_TYPE (eh
->target_internal
)
17321 == ST_BRANCH_TO_THUMB
)
17323 dyn
.d_un
.d_val
|= 1;
17324 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17331 /* Fill in the first entry in the procedure linkage table. */
17332 if (splt
->size
> 0 && htab
->plt_header_size
)
17334 const bfd_vma
*plt0_entry
;
17335 bfd_vma got_address
, plt_address
, got_displacement
;
17337 /* Calculate the addresses of the GOT and PLT. */
17338 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
17339 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
17341 if (htab
->vxworks_p
)
17343 /* The VxWorks GOT is relocated by the dynamic linker.
17344 Therefore, we must emit relocations rather than simply
17345 computing the values now. */
17346 Elf_Internal_Rela rel
;
17348 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
17349 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
17350 splt
->contents
+ 0);
17351 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
17352 splt
->contents
+ 4);
17353 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
17354 splt
->contents
+ 8);
17355 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
17357 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
17358 rel
.r_offset
= plt_address
+ 12;
17359 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
17361 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
17362 htab
->srelplt2
->contents
);
17364 else if (htab
->nacl_p
)
17365 arm_nacl_put_plt0 (htab
, output_bfd
, splt
,
17366 got_address
+ 8 - (plt_address
+ 16));
17367 else if (using_thumb_only (htab
))
17369 got_displacement
= got_address
- (plt_address
+ 12);
17371 plt0_entry
= elf32_thumb2_plt0_entry
;
17372 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
17373 splt
->contents
+ 0);
17374 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
17375 splt
->contents
+ 4);
17376 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
17377 splt
->contents
+ 8);
17379 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 12);
17383 got_displacement
= got_address
- (plt_address
+ 16);
17385 plt0_entry
= elf32_arm_plt0_entry
;
17386 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
17387 splt
->contents
+ 0);
17388 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
17389 splt
->contents
+ 4);
17390 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
17391 splt
->contents
+ 8);
17392 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
17393 splt
->contents
+ 12);
17395 #ifdef FOUR_WORD_PLT
17396 /* The displacement value goes in the otherwise-unused
17397 last word of the second entry. */
17398 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
17400 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
17405 /* UnixWare sets the entsize of .plt to 4, although that doesn't
17406 really seem like the right value. */
17407 if (splt
->output_section
->owner
== output_bfd
)
17408 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
17410 if (htab
->dt_tlsdesc_plt
)
17412 bfd_vma got_address
17413 = sgot
->output_section
->vma
+ sgot
->output_offset
;
17414 bfd_vma gotplt_address
= (htab
->root
.sgot
->output_section
->vma
17415 + htab
->root
.sgot
->output_offset
);
17416 bfd_vma plt_address
17417 = splt
->output_section
->vma
+ splt
->output_offset
;
17419 arm_put_trampoline (htab
, output_bfd
,
17420 splt
->contents
+ htab
->dt_tlsdesc_plt
,
17421 dl_tlsdesc_lazy_trampoline
, 6);
17423 bfd_put_32 (output_bfd
,
17424 gotplt_address
+ htab
->dt_tlsdesc_got
17425 - (plt_address
+ htab
->dt_tlsdesc_plt
)
17426 - dl_tlsdesc_lazy_trampoline
[6],
17427 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24);
17428 bfd_put_32 (output_bfd
,
17429 got_address
- (plt_address
+ htab
->dt_tlsdesc_plt
)
17430 - dl_tlsdesc_lazy_trampoline
[7],
17431 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24 + 4);
17434 if (htab
->tls_trampoline
)
17436 arm_put_trampoline (htab
, output_bfd
,
17437 splt
->contents
+ htab
->tls_trampoline
,
17438 tls_trampoline
, 3);
17439 #ifdef FOUR_WORD_PLT
17440 bfd_put_32 (output_bfd
, 0x00000000,
17441 splt
->contents
+ htab
->tls_trampoline
+ 12);
17445 if (htab
->vxworks_p
17446 && !bfd_link_pic (info
)
17447 && htab
->root
.splt
->size
> 0)
17449 /* Correct the .rel(a).plt.unloaded relocations. They will have
17450 incorrect symbol indexes. */
17454 num_plts
= ((htab
->root
.splt
->size
- htab
->plt_header_size
)
17455 / htab
->plt_entry_size
);
17456 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
17458 for (; num_plts
; num_plts
--)
17460 Elf_Internal_Rela rel
;
17462 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
17463 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
17464 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
17465 p
+= RELOC_SIZE (htab
);
17467 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
17468 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
17469 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
17470 p
+= RELOC_SIZE (htab
);
17475 if (htab
->nacl_p
&& htab
->root
.iplt
!= NULL
&& htab
->root
.iplt
->size
> 0)
17476 /* NaCl uses a special first entry in .iplt too. */
17477 arm_nacl_put_plt0 (htab
, output_bfd
, htab
->root
.iplt
, 0);
17479 /* Fill in the first three entries in the global offset table. */
17482 if (sgot
->size
> 0)
17485 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
17487 bfd_put_32 (output_bfd
,
17488 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
17490 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
17491 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
17494 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
17497 /* At the very end of the .rofixup section is a pointer to the GOT. */
17498 if (htab
->fdpic_p
&& htab
->srofixup
!= NULL
)
17500 struct elf_link_hash_entry
*hgot
= htab
->root
.hgot
;
17502 bfd_vma got_value
= hgot
->root
.u
.def
.value
17503 + hgot
->root
.u
.def
.section
->output_section
->vma
17504 + hgot
->root
.u
.def
.section
->output_offset
;
17506 arm_elf_add_rofixup(output_bfd
, htab
->srofixup
, got_value
);
17508 /* Make sure we allocated and generated the same number of fixups. */
17509 BFD_ASSERT (htab
->srofixup
->reloc_count
* 4 == htab
->srofixup
->size
);
17516 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
17518 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
17519 struct elf32_arm_link_hash_table
*globals
;
17520 struct elf_segment_map
*m
;
17522 i_ehdrp
= elf_elfheader (abfd
);
17524 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
17525 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
17527 _bfd_elf_post_process_headers (abfd
, link_info
);
17528 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
17532 globals
= elf32_arm_hash_table (link_info
);
17533 if (globals
!= NULL
&& globals
->byteswap_code
)
17534 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
17536 if (globals
->fdpic_p
)
17537 i_ehdrp
->e_ident
[EI_OSABI
] |= ELFOSABI_ARM_FDPIC
;
17540 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_VER5
17541 && ((i_ehdrp
->e_type
== ET_DYN
) || (i_ehdrp
->e_type
== ET_EXEC
)))
17543 int abi
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_ABI_VFP_args
);
17544 if (abi
== AEABI_VFP_args_vfp
)
17545 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_HARD
;
17547 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_SOFT
;
17550 /* Scan segment to set p_flags attribute if it contains only sections with
17551 SHF_ARM_PURECODE flag. */
17552 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
17558 for (j
= 0; j
< m
->count
; j
++)
17560 if (!(elf_section_flags (m
->sections
[j
]) & SHF_ARM_PURECODE
))
17566 m
->p_flags_valid
= 1;
17571 static enum elf_reloc_type_class
17572 elf32_arm_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
17573 const asection
*rel_sec ATTRIBUTE_UNUSED
,
17574 const Elf_Internal_Rela
*rela
)
17576 switch ((int) ELF32_R_TYPE (rela
->r_info
))
17578 case R_ARM_RELATIVE
:
17579 return reloc_class_relative
;
17580 case R_ARM_JUMP_SLOT
:
17581 return reloc_class_plt
;
17583 return reloc_class_copy
;
17584 case R_ARM_IRELATIVE
:
17585 return reloc_class_ifunc
;
17587 return reloc_class_normal
;
17592 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
17594 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
17597 /* Return TRUE if this is an unwinding table entry. */
17600 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
17602 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
17603 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
17607 /* Set the type and flags for an ARM section. We do this by
17608 the section name, which is a hack, but ought to work. */
17611 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
17615 name
= bfd_get_section_name (abfd
, sec
);
17617 if (is_arm_elf_unwind_section_name (abfd
, name
))
17619 hdr
->sh_type
= SHT_ARM_EXIDX
;
17620 hdr
->sh_flags
|= SHF_LINK_ORDER
;
17623 if (sec
->flags
& SEC_ELF_PURECODE
)
17624 hdr
->sh_flags
|= SHF_ARM_PURECODE
;
17629 /* Handle an ARM specific section when reading an object file. This is
17630 called when bfd_section_from_shdr finds a section with an unknown
17634 elf32_arm_section_from_shdr (bfd
*abfd
,
17635 Elf_Internal_Shdr
* hdr
,
17639 /* There ought to be a place to keep ELF backend specific flags, but
17640 at the moment there isn't one. We just keep track of the
17641 sections by their name, instead. Fortunately, the ABI gives
17642 names for all the ARM specific sections, so we will probably get
17644 switch (hdr
->sh_type
)
17646 case SHT_ARM_EXIDX
:
17647 case SHT_ARM_PREEMPTMAP
:
17648 case SHT_ARM_ATTRIBUTES
:
17655 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
17661 static _arm_elf_section_data
*
17662 get_arm_elf_section_data (asection
* sec
)
17664 if (sec
&& sec
->owner
&& is_arm_elf (sec
->owner
))
17665 return elf32_arm_section_data (sec
);
17673 struct bfd_link_info
*info
;
17676 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
17677 asection
*, struct elf_link_hash_entry
*);
17678 } output_arch_syminfo
;
17680 enum map_symbol_type
17688 /* Output a single mapping symbol. */
17691 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
17692 enum map_symbol_type type
,
17695 static const char *names
[3] = {"$a", "$t", "$d"};
17696 Elf_Internal_Sym sym
;
17698 sym
.st_value
= osi
->sec
->output_section
->vma
17699 + osi
->sec
->output_offset
17703 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
17704 sym
.st_shndx
= osi
->sec_shndx
;
17705 sym
.st_target_internal
= 0;
17706 elf32_arm_section_map_add (osi
->sec
, names
[type
][1], offset
);
17707 return osi
->func (osi
->flaginfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
17710 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
17711 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
17714 elf32_arm_output_plt_map_1 (output_arch_syminfo
*osi
,
17715 bfd_boolean is_iplt_entry_p
,
17716 union gotplt_union
*root_plt
,
17717 struct arm_plt_info
*arm_plt
)
17719 struct elf32_arm_link_hash_table
*htab
;
17720 bfd_vma addr
, plt_header_size
;
17722 if (root_plt
->offset
== (bfd_vma
) -1)
17725 htab
= elf32_arm_hash_table (osi
->info
);
17729 if (is_iplt_entry_p
)
17731 osi
->sec
= htab
->root
.iplt
;
17732 plt_header_size
= 0;
17736 osi
->sec
= htab
->root
.splt
;
17737 plt_header_size
= htab
->plt_header_size
;
17739 osi
->sec_shndx
= (_bfd_elf_section_from_bfd_section
17740 (osi
->info
->output_bfd
, osi
->sec
->output_section
));
17742 addr
= root_plt
->offset
& -2;
17743 if (htab
->symbian_p
)
17745 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17747 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
17750 else if (htab
->vxworks_p
)
17752 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17754 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
17756 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
17758 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
17761 else if (htab
->nacl_p
)
17763 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17766 else if (htab
->fdpic_p
)
17768 if (elf32_arm_plt_needs_thumb_stub_p (osi
->info
, arm_plt
))
17769 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
17771 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17773 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 16))
17775 if (htab
->plt_entry_size
== 4 * ARRAY_SIZE(elf32_arm_fdpic_plt_entry
))
17776 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 24))
17779 else if (using_thumb_only (htab
))
17781 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
))
17786 bfd_boolean thumb_stub_p
;
17788 thumb_stub_p
= elf32_arm_plt_needs_thumb_stub_p (osi
->info
, arm_plt
);
17791 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
17794 #ifdef FOUR_WORD_PLT
17795 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17797 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
17800 /* A three-word PLT with no Thumb thunk contains only Arm code,
17801 so only need to output a mapping symbol for the first PLT entry and
17802 entries with thumb thunks. */
17803 if (thumb_stub_p
|| addr
== plt_header_size
)
17805 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
17814 /* Output mapping symbols for PLT entries associated with H. */
17817 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
17819 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
17820 struct elf32_arm_link_hash_entry
*eh
;
17822 if (h
->root
.type
== bfd_link_hash_indirect
)
17825 if (h
->root
.type
== bfd_link_hash_warning
)
17826 /* When warning symbols are created, they **replace** the "real"
17827 entry in the hash table, thus we never get to see the real
17828 symbol in a hash traversal. So look at it now. */
17829 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
17831 eh
= (struct elf32_arm_link_hash_entry
*) h
;
17832 return elf32_arm_output_plt_map_1 (osi
, SYMBOL_CALLS_LOCAL (osi
->info
, h
),
17833 &h
->plt
, &eh
->plt
);
17836 /* Bind a veneered symbol to its veneer identified by its hash entry
17837 STUB_ENTRY. The veneered location thus loose its symbol. */
17840 arm_stub_claim_sym (struct elf32_arm_stub_hash_entry
*stub_entry
)
17842 struct elf32_arm_link_hash_entry
*hash
= stub_entry
->h
;
17845 hash
->root
.root
.u
.def
.section
= stub_entry
->stub_sec
;
17846 hash
->root
.root
.u
.def
.value
= stub_entry
->stub_offset
;
17847 hash
->root
.size
= stub_entry
->stub_size
;
17850 /* Output a single local symbol for a generated stub. */
17853 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
17854 bfd_vma offset
, bfd_vma size
)
17856 Elf_Internal_Sym sym
;
17858 sym
.st_value
= osi
->sec
->output_section
->vma
17859 + osi
->sec
->output_offset
17861 sym
.st_size
= size
;
17863 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
17864 sym
.st_shndx
= osi
->sec_shndx
;
17865 sym
.st_target_internal
= 0;
17866 return osi
->func (osi
->flaginfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
17870 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
17873 struct elf32_arm_stub_hash_entry
*stub_entry
;
17874 asection
*stub_sec
;
17877 output_arch_syminfo
*osi
;
17878 const insn_sequence
*template_sequence
;
17879 enum stub_insn_type prev_type
;
17882 enum map_symbol_type sym_type
;
17884 /* Massage our args to the form they really have. */
17885 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
17886 osi
= (output_arch_syminfo
*) in_arg
;
17888 stub_sec
= stub_entry
->stub_sec
;
17890 /* Ensure this stub is attached to the current section being
17892 if (stub_sec
!= osi
->sec
)
17895 addr
= (bfd_vma
) stub_entry
->stub_offset
;
17896 template_sequence
= stub_entry
->stub_template
;
17898 if (arm_stub_sym_claimed (stub_entry
->stub_type
))
17899 arm_stub_claim_sym (stub_entry
);
17902 stub_name
= stub_entry
->output_name
;
17903 switch (template_sequence
[0].type
)
17906 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
,
17907 stub_entry
->stub_size
))
17912 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
17913 stub_entry
->stub_size
))
17922 prev_type
= DATA_TYPE
;
17924 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
17926 switch (template_sequence
[i
].type
)
17929 sym_type
= ARM_MAP_ARM
;
17934 sym_type
= ARM_MAP_THUMB
;
17938 sym_type
= ARM_MAP_DATA
;
17946 if (template_sequence
[i
].type
!= prev_type
)
17948 prev_type
= template_sequence
[i
].type
;
17949 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
17953 switch (template_sequence
[i
].type
)
17977 /* Output mapping symbols for linker generated sections,
17978 and for those data-only sections that do not have a
17982 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
17983 struct bfd_link_info
*info
,
17985 int (*func
) (void *, const char *,
17986 Elf_Internal_Sym
*,
17988 struct elf_link_hash_entry
*))
17990 output_arch_syminfo osi
;
17991 struct elf32_arm_link_hash_table
*htab
;
17993 bfd_size_type size
;
17996 htab
= elf32_arm_hash_table (info
);
18000 check_use_blx (htab
);
18002 osi
.flaginfo
= flaginfo
;
18006 /* Add a $d mapping symbol to data-only sections that
18007 don't have any mapping symbol. This may result in (harmless) redundant
18008 mapping symbols. */
18009 for (input_bfd
= info
->input_bfds
;
18011 input_bfd
= input_bfd
->link
.next
)
18013 if ((input_bfd
->flags
& (BFD_LINKER_CREATED
| HAS_SYMS
)) == HAS_SYMS
)
18014 for (osi
.sec
= input_bfd
->sections
;
18016 osi
.sec
= osi
.sec
->next
)
18018 if (osi
.sec
->output_section
!= NULL
18019 && ((osi
.sec
->output_section
->flags
& (SEC_ALLOC
| SEC_CODE
))
18021 && (osi
.sec
->flags
& (SEC_HAS_CONTENTS
| SEC_LINKER_CREATED
))
18022 == SEC_HAS_CONTENTS
18023 && get_arm_elf_section_data (osi
.sec
) != NULL
18024 && get_arm_elf_section_data (osi
.sec
)->mapcount
== 0
18025 && osi
.sec
->size
> 0
18026 && (osi
.sec
->flags
& SEC_EXCLUDE
) == 0)
18028 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
18029 (output_bfd
, osi
.sec
->output_section
);
18030 if (osi
.sec_shndx
!= (int)SHN_BAD
)
18031 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 0);
18036 /* ARM->Thumb glue. */
18037 if (htab
->arm_glue_size
> 0)
18039 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
18040 ARM2THUMB_GLUE_SECTION_NAME
);
18042 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
18043 (output_bfd
, osi
.sec
->output_section
);
18044 if (bfd_link_pic (info
) || htab
->root
.is_relocatable_executable
18045 || htab
->pic_veneer
)
18046 size
= ARM2THUMB_PIC_GLUE_SIZE
;
18047 else if (htab
->use_blx
)
18048 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
18050 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
18052 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
18054 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
18055 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
18059 /* Thumb->ARM glue. */
18060 if (htab
->thumb_glue_size
> 0)
18062 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
18063 THUMB2ARM_GLUE_SECTION_NAME
);
18065 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
18066 (output_bfd
, osi
.sec
->output_section
);
18067 size
= THUMB2ARM_GLUE_SIZE
;
18069 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
18071 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
18072 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
18076 /* ARMv4 BX veneers. */
18077 if (htab
->bx_glue_size
> 0)
18079 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
18080 ARM_BX_GLUE_SECTION_NAME
);
18082 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
18083 (output_bfd
, osi
.sec
->output_section
);
18085 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
18088 /* Long calls stubs. */
18089 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
18091 asection
* stub_sec
;
18093 for (stub_sec
= htab
->stub_bfd
->sections
;
18095 stub_sec
= stub_sec
->next
)
18097 /* Ignore non-stub sections. */
18098 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
18101 osi
.sec
= stub_sec
;
18103 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
18104 (output_bfd
, osi
.sec
->output_section
);
18106 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
18110 /* Finally, output mapping symbols for the PLT. */
18111 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
18113 osi
.sec
= htab
->root
.splt
;
18114 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
18115 (output_bfd
, osi
.sec
->output_section
));
18117 /* Output mapping symbols for the plt header. SymbianOS does not have a
18119 if (htab
->vxworks_p
)
18121 /* VxWorks shared libraries have no PLT header. */
18122 if (!bfd_link_pic (info
))
18124 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
18126 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
18130 else if (htab
->nacl_p
)
18132 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
18135 else if (using_thumb_only (htab
))
18137 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, 0))
18139 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
18141 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, 16))
18144 else if (!htab
->symbian_p
&& !htab
->fdpic_p
)
18146 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
18148 #ifndef FOUR_WORD_PLT
18149 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
18154 if (htab
->nacl_p
&& htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0)
18156 /* NaCl uses a special first entry in .iplt too. */
18157 osi
.sec
= htab
->root
.iplt
;
18158 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
18159 (output_bfd
, osi
.sec
->output_section
));
18160 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
18163 if ((htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
18164 || (htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0))
18166 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, &osi
);
18167 for (input_bfd
= info
->input_bfds
;
18169 input_bfd
= input_bfd
->link
.next
)
18171 struct arm_local_iplt_info
**local_iplt
;
18172 unsigned int i
, num_syms
;
18174 local_iplt
= elf32_arm_local_iplt (input_bfd
);
18175 if (local_iplt
!= NULL
)
18177 num_syms
= elf_symtab_hdr (input_bfd
).sh_info
;
18178 for (i
= 0; i
< num_syms
; i
++)
18179 if (local_iplt
[i
] != NULL
18180 && !elf32_arm_output_plt_map_1 (&osi
, TRUE
,
18181 &local_iplt
[i
]->root
,
18182 &local_iplt
[i
]->arm
))
18187 if (htab
->dt_tlsdesc_plt
!= 0)
18189 /* Mapping symbols for the lazy tls trampoline. */
18190 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->dt_tlsdesc_plt
))
18193 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
18194 htab
->dt_tlsdesc_plt
+ 24))
18197 if (htab
->tls_trampoline
!= 0)
18199 /* Mapping symbols for the tls trampoline. */
18200 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->tls_trampoline
))
18202 #ifdef FOUR_WORD_PLT
18203 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
18204 htab
->tls_trampoline
+ 12))
18212 /* Filter normal symbols of CMSE entry functions of ABFD to include in
18213 the import library. All SYMCOUNT symbols of ABFD can be examined
18214 from their pointers in SYMS. Pointers of symbols to keep should be
18215 stored continuously at the beginning of that array.
18217 Returns the number of symbols to keep. */
18219 static unsigned int
18220 elf32_arm_filter_cmse_symbols (bfd
*abfd ATTRIBUTE_UNUSED
,
18221 struct bfd_link_info
*info
,
18222 asymbol
**syms
, long symcount
)
18226 long src_count
, dst_count
= 0;
18227 struct elf32_arm_link_hash_table
*htab
;
18229 htab
= elf32_arm_hash_table (info
);
18230 if (!htab
->stub_bfd
|| !htab
->stub_bfd
->sections
)
18234 cmse_name
= (char *) bfd_malloc (maxnamelen
);
18235 for (src_count
= 0; src_count
< symcount
; src_count
++)
18237 struct elf32_arm_link_hash_entry
*cmse_hash
;
18243 sym
= syms
[src_count
];
18244 flags
= sym
->flags
;
18245 name
= (char *) bfd_asymbol_name (sym
);
18247 if ((flags
& BSF_FUNCTION
) != BSF_FUNCTION
)
18249 if (!(flags
& (BSF_GLOBAL
| BSF_WEAK
)))
18252 namelen
= strlen (name
) + sizeof (CMSE_PREFIX
) + 1;
18253 if (namelen
> maxnamelen
)
18255 cmse_name
= (char *)
18256 bfd_realloc (cmse_name
, namelen
);
18257 maxnamelen
= namelen
;
18259 snprintf (cmse_name
, maxnamelen
, "%s%s", CMSE_PREFIX
, name
);
18260 cmse_hash
= (struct elf32_arm_link_hash_entry
*)
18261 elf_link_hash_lookup (&(htab
)->root
, cmse_name
, FALSE
, FALSE
, TRUE
);
18264 || (cmse_hash
->root
.root
.type
!= bfd_link_hash_defined
18265 && cmse_hash
->root
.root
.type
!= bfd_link_hash_defweak
)
18266 || cmse_hash
->root
.type
!= STT_FUNC
)
18269 if (!ARM_GET_SYM_CMSE_SPCL (cmse_hash
->root
.target_internal
))
18272 syms
[dst_count
++] = sym
;
18276 syms
[dst_count
] = NULL
;
18281 /* Filter symbols of ABFD to include in the import library. All
18282 SYMCOUNT symbols of ABFD can be examined from their pointers in
18283 SYMS. Pointers of symbols to keep should be stored continuously at
18284 the beginning of that array.
18286 Returns the number of symbols to keep. */
18288 static unsigned int
18289 elf32_arm_filter_implib_symbols (bfd
*abfd ATTRIBUTE_UNUSED
,
18290 struct bfd_link_info
*info
,
18291 asymbol
**syms
, long symcount
)
18293 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
18295 /* Requirement 8 of "ARM v8-M Security Extensions: Requirements on
18296 Development Tools" (ARM-ECM-0359818) mandates Secure Gateway import
18297 library to be a relocatable object file. */
18298 BFD_ASSERT (!(bfd_get_file_flags (info
->out_implib_bfd
) & EXEC_P
));
18299 if (globals
->cmse_implib
)
18300 return elf32_arm_filter_cmse_symbols (abfd
, info
, syms
, symcount
);
18302 return _bfd_elf_filter_global_symbols (abfd
, info
, syms
, symcount
);
18305 /* Allocate target specific section data. */
18308 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
18310 if (!sec
->used_by_bfd
)
18312 _arm_elf_section_data
*sdata
;
18313 bfd_size_type amt
= sizeof (*sdata
);
18315 sdata
= (_arm_elf_section_data
*) bfd_zalloc (abfd
, amt
);
18318 sec
->used_by_bfd
= sdata
;
18321 return _bfd_elf_new_section_hook (abfd
, sec
);
18325 /* Used to order a list of mapping symbols by address. */
18328 elf32_arm_compare_mapping (const void * a
, const void * b
)
18330 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
18331 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
18333 if (amap
->vma
> bmap
->vma
)
18335 else if (amap
->vma
< bmap
->vma
)
18337 else if (amap
->type
> bmap
->type
)
18338 /* Ensure results do not depend on the host qsort for objects with
18339 multiple mapping symbols at the same address by sorting on type
18342 else if (amap
->type
< bmap
->type
)
18348 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
18350 static unsigned long
18351 offset_prel31 (unsigned long addr
, bfd_vma offset
)
18353 return (addr
& ~0x7ffffffful
) | ((addr
+ offset
) & 0x7ffffffful
);
18356 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
18360 copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
, bfd_vma offset
)
18362 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
18363 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
18365 /* High bit of first word is supposed to be zero. */
18366 if ((first_word
& 0x80000000ul
) == 0)
18367 first_word
= offset_prel31 (first_word
, offset
);
18369 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
18370 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
18371 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
18372 second_word
= offset_prel31 (second_word
, offset
);
18374 bfd_put_32 (output_bfd
, first_word
, to
);
18375 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
18378 /* Data for make_branch_to_a8_stub(). */
18380 struct a8_branch_to_stub_data
18382 asection
*writing_section
;
18383 bfd_byte
*contents
;
18387 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
18388 places for a particular section. */
18391 make_branch_to_a8_stub (struct bfd_hash_entry
*gen_entry
,
18394 struct elf32_arm_stub_hash_entry
*stub_entry
;
18395 struct a8_branch_to_stub_data
*data
;
18396 bfd_byte
*contents
;
18397 unsigned long branch_insn
;
18398 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
18399 bfd_signed_vma branch_offset
;
18403 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
18404 data
= (struct a8_branch_to_stub_data
*) in_arg
;
18406 if (stub_entry
->target_section
!= data
->writing_section
18407 || stub_entry
->stub_type
< arm_stub_a8_veneer_lwm
)
18410 contents
= data
->contents
;
18412 /* We use target_section as Cortex-A8 erratum workaround stubs are only
18413 generated when both source and target are in the same section. */
18414 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
18415 + stub_entry
->target_section
->output_offset
18416 + stub_entry
->source_value
;
18418 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
18419 + stub_entry
->stub_sec
->output_offset
18420 + stub_entry
->stub_offset
;
18422 if (stub_entry
->stub_type
== arm_stub_a8_veneer_blx
)
18423 veneered_insn_loc
&= ~3u;
18425 branch_offset
= veneer_entry_loc
- veneered_insn_loc
- 4;
18427 abfd
= stub_entry
->target_section
->owner
;
18428 loc
= stub_entry
->source_value
;
18430 /* We attempt to avoid this condition by setting stubs_always_after_branch
18431 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
18432 This check is just to be on the safe side... */
18433 if ((veneered_insn_loc
& ~0xfff) == (veneer_entry_loc
& ~0xfff))
18435 _bfd_error_handler (_("%pB: error: Cortex-A8 erratum stub is "
18436 "allocated in unsafe location"), abfd
);
18440 switch (stub_entry
->stub_type
)
18442 case arm_stub_a8_veneer_b
:
18443 case arm_stub_a8_veneer_b_cond
:
18444 branch_insn
= 0xf0009000;
18447 case arm_stub_a8_veneer_blx
:
18448 branch_insn
= 0xf000e800;
18451 case arm_stub_a8_veneer_bl
:
18453 unsigned int i1
, j1
, i2
, j2
, s
;
18455 branch_insn
= 0xf000d000;
18458 if (branch_offset
< -16777216 || branch_offset
> 16777214)
18460 /* There's not much we can do apart from complain if this
18462 _bfd_error_handler (_("%pB: error: Cortex-A8 erratum stub out "
18463 "of range (input file too large)"), abfd
);
18467 /* i1 = not(j1 eor s), so:
18469 j1 = (not i1) eor s. */
18471 branch_insn
|= (branch_offset
>> 1) & 0x7ff;
18472 branch_insn
|= ((branch_offset
>> 12) & 0x3ff) << 16;
18473 i2
= (branch_offset
>> 22) & 1;
18474 i1
= (branch_offset
>> 23) & 1;
18475 s
= (branch_offset
>> 24) & 1;
18478 branch_insn
|= j2
<< 11;
18479 branch_insn
|= j1
<< 13;
18480 branch_insn
|= s
<< 26;
18489 bfd_put_16 (abfd
, (branch_insn
>> 16) & 0xffff, &contents
[loc
]);
18490 bfd_put_16 (abfd
, branch_insn
& 0xffff, &contents
[loc
+ 2]);
18495 /* Beginning of stm32l4xx work-around. */
18497 /* Functions encoding instructions necessary for the emission of the
18498 fix-stm32l4xx-629360.
18499 Encoding is extracted from the
18500 ARM (C) Architecture Reference Manual
18501 ARMv7-A and ARMv7-R edition
18502 ARM DDI 0406C.b (ID072512). */
18504 static inline bfd_vma
18505 create_instruction_branch_absolute (int branch_offset
)
18507 /* A8.8.18 B (A8-334)
18508 B target_address (Encoding T4). */
18509 /* 1111 - 0Sii - iiii - iiii - 10J1 - Jiii - iiii - iiii. */
18510 /* jump offset is: S:I1:I2:imm10:imm11:0. */
18511 /* with : I1 = NOT (J1 EOR S) I2 = NOT (J2 EOR S). */
18513 int s
= ((branch_offset
& 0x1000000) >> 24);
18514 int j1
= s
^ !((branch_offset
& 0x800000) >> 23);
18515 int j2
= s
^ !((branch_offset
& 0x400000) >> 22);
18517 if (branch_offset
< -(1 << 24) || branch_offset
>= (1 << 24))
18518 BFD_ASSERT (0 && "Error: branch out of range. Cannot create branch.");
18520 bfd_vma patched_inst
= 0xf0009000
18522 | (((unsigned long) (branch_offset
) >> 12) & 0x3ff) << 16 /* imm10. */
18523 | j1
<< 13 /* J1. */
18524 | j2
<< 11 /* J2. */
18525 | (((unsigned long) (branch_offset
) >> 1) & 0x7ff); /* imm11. */
18527 return patched_inst
;
18530 static inline bfd_vma
18531 create_instruction_ldmia (int base_reg
, int wback
, int reg_mask
)
18533 /* A8.8.57 LDM/LDMIA/LDMFD (A8-396)
18534 LDMIA Rn!, {Ra, Rb, Rc, ...} (Encoding T2). */
18535 bfd_vma patched_inst
= 0xe8900000
18536 | (/*W=*/wback
<< 21)
18538 | (reg_mask
& 0x0000ffff);
18540 return patched_inst
;
18543 static inline bfd_vma
18544 create_instruction_ldmdb (int base_reg
, int wback
, int reg_mask
)
18546 /* A8.8.60 LDMDB/LDMEA (A8-402)
18547 LDMDB Rn!, {Ra, Rb, Rc, ...} (Encoding T1). */
18548 bfd_vma patched_inst
= 0xe9100000
18549 | (/*W=*/wback
<< 21)
18551 | (reg_mask
& 0x0000ffff);
18553 return patched_inst
;
18556 static inline bfd_vma
18557 create_instruction_mov (int target_reg
, int source_reg
)
18559 /* A8.8.103 MOV (register) (A8-486)
18560 MOV Rd, Rm (Encoding T1). */
18561 bfd_vma patched_inst
= 0x4600
18562 | (target_reg
& 0x7)
18563 | ((target_reg
& 0x8) >> 3) << 7
18564 | (source_reg
<< 3);
18566 return patched_inst
;
18569 static inline bfd_vma
18570 create_instruction_sub (int target_reg
, int source_reg
, int value
)
18572 /* A8.8.221 SUB (immediate) (A8-708)
18573 SUB Rd, Rn, #value (Encoding T3). */
18574 bfd_vma patched_inst
= 0xf1a00000
18575 | (target_reg
<< 8)
18576 | (source_reg
<< 16)
18578 | ((value
& 0x800) >> 11) << 26
18579 | ((value
& 0x700) >> 8) << 12
18582 return patched_inst
;
18585 static inline bfd_vma
18586 create_instruction_vldmia (int base_reg
, int is_dp
, int wback
, int num_words
,
18589 /* A8.8.332 VLDM (A8-922)
18590 VLMD{MODE} Rn{!}, {list} (Encoding T1 or T2). */
18591 bfd_vma patched_inst
= (is_dp
? 0xec900b00 : 0xec900a00)
18592 | (/*W=*/wback
<< 21)
18594 | (num_words
& 0x000000ff)
18595 | (((unsigned)first_reg
>> 1) & 0x0000000f) << 12
18596 | (first_reg
& 0x00000001) << 22;
18598 return patched_inst
;
18601 static inline bfd_vma
18602 create_instruction_vldmdb (int base_reg
, int is_dp
, int num_words
,
18605 /* A8.8.332 VLDM (A8-922)
18606 VLMD{MODE} Rn!, {} (Encoding T1 or T2). */
18607 bfd_vma patched_inst
= (is_dp
? 0xed300b00 : 0xed300a00)
18609 | (num_words
& 0x000000ff)
18610 | (((unsigned)first_reg
>>1 ) & 0x0000000f) << 12
18611 | (first_reg
& 0x00000001) << 22;
18613 return patched_inst
;
18616 static inline bfd_vma
18617 create_instruction_udf_w (int value
)
18619 /* A8.8.247 UDF (A8-758)
18620 Undefined (Encoding T2). */
18621 bfd_vma patched_inst
= 0xf7f0a000
18622 | (value
& 0x00000fff)
18623 | (value
& 0x000f0000) << 16;
18625 return patched_inst
;
18628 static inline bfd_vma
18629 create_instruction_udf (int value
)
18631 /* A8.8.247 UDF (A8-758)
18632 Undefined (Encoding T1). */
18633 bfd_vma patched_inst
= 0xde00
18636 return patched_inst
;
18639 /* Functions writing an instruction in memory, returning the next
18640 memory position to write to. */
18642 static inline bfd_byte
*
18643 push_thumb2_insn32 (struct elf32_arm_link_hash_table
* htab
,
18644 bfd
* output_bfd
, bfd_byte
*pt
, insn32 insn
)
18646 put_thumb2_insn (htab
, output_bfd
, insn
, pt
);
18650 static inline bfd_byte
*
18651 push_thumb2_insn16 (struct elf32_arm_link_hash_table
* htab
,
18652 bfd
* output_bfd
, bfd_byte
*pt
, insn32 insn
)
18654 put_thumb_insn (htab
, output_bfd
, insn
, pt
);
18658 /* Function filling up a region in memory with T1 and T2 UDFs taking
18659 care of alignment. */
18662 stm32l4xx_fill_stub_udf (struct elf32_arm_link_hash_table
* htab
,
18664 const bfd_byte
* const base_stub_contents
,
18665 bfd_byte
* const from_stub_contents
,
18666 const bfd_byte
* const end_stub_contents
)
18668 bfd_byte
*current_stub_contents
= from_stub_contents
;
18670 /* Fill the remaining of the stub with deterministic contents : UDF
18672 Check if realignment is needed on modulo 4 frontier using T1, to
18674 if ((current_stub_contents
< end_stub_contents
)
18675 && !((current_stub_contents
- base_stub_contents
) % 2)
18676 && ((current_stub_contents
- base_stub_contents
) % 4))
18677 current_stub_contents
=
18678 push_thumb2_insn16 (htab
, output_bfd
, current_stub_contents
,
18679 create_instruction_udf (0));
18681 for (; current_stub_contents
< end_stub_contents
;)
18682 current_stub_contents
=
18683 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18684 create_instruction_udf_w (0));
18686 return current_stub_contents
;
18689 /* Functions writing the stream of instructions equivalent to the
18690 derived sequence for ldmia, ldmdb, vldm respectively. */
18693 stm32l4xx_create_replacing_stub_ldmia (struct elf32_arm_link_hash_table
* htab
,
18695 const insn32 initial_insn
,
18696 const bfd_byte
*const initial_insn_addr
,
18697 bfd_byte
*const base_stub_contents
)
18699 int wback
= (initial_insn
& 0x00200000) >> 21;
18700 int ri
, rn
= (initial_insn
& 0x000F0000) >> 16;
18701 int insn_all_registers
= initial_insn
& 0x0000ffff;
18702 int insn_low_registers
, insn_high_registers
;
18703 int usable_register_mask
;
18704 int nb_registers
= elf32_arm_popcount (insn_all_registers
);
18705 int restore_pc
= (insn_all_registers
& (1 << 15)) ? 1 : 0;
18706 int restore_rn
= (insn_all_registers
& (1 << rn
)) ? 1 : 0;
18707 bfd_byte
*current_stub_contents
= base_stub_contents
;
18709 BFD_ASSERT (is_thumb2_ldmia (initial_insn
));
18711 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
18712 smaller than 8 registers load sequences that do not cause the
18714 if (nb_registers
<= 8)
18716 /* UNTOUCHED : LDMIA Rn{!}, {R-all-register-list}. */
18717 current_stub_contents
=
18718 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18721 /* B initial_insn_addr+4. */
18723 current_stub_contents
=
18724 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18725 create_instruction_branch_absolute
18726 (initial_insn_addr
- current_stub_contents
));
18728 /* Fill the remaining of the stub with deterministic contents. */
18729 current_stub_contents
=
18730 stm32l4xx_fill_stub_udf (htab
, output_bfd
,
18731 base_stub_contents
, current_stub_contents
,
18732 base_stub_contents
+
18733 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
);
18738 /* - reg_list[13] == 0. */
18739 BFD_ASSERT ((insn_all_registers
& (1 << 13))==0);
18741 /* - reg_list[14] & reg_list[15] != 1. */
18742 BFD_ASSERT ((insn_all_registers
& 0xC000) != 0xC000);
18744 /* - if (wback==1) reg_list[rn] == 0. */
18745 BFD_ASSERT (!wback
|| !restore_rn
);
18747 /* - nb_registers > 8. */
18748 BFD_ASSERT (elf32_arm_popcount (insn_all_registers
) > 8);
18750 /* At this point, LDMxx initial insn loads between 9 and 14 registers. */
18752 /* In the following algorithm, we split this wide LDM using 2 LDM insns:
18753 - One with the 7 lowest registers (register mask 0x007F)
18754 This LDM will finally contain between 2 and 7 registers
18755 - One with the 7 highest registers (register mask 0xDF80)
18756 This ldm will finally contain between 2 and 7 registers. */
18757 insn_low_registers
= insn_all_registers
& 0x007F;
18758 insn_high_registers
= insn_all_registers
& 0xDF80;
18760 /* A spare register may be needed during this veneer to temporarily
18761 handle the base register. This register will be restored with the
18762 last LDM operation.
18763 The usable register may be any general purpose register (that
18764 excludes PC, SP, LR : register mask is 0x1FFF). */
18765 usable_register_mask
= 0x1FFF;
18767 /* Generate the stub function. */
18770 /* LDMIA Rn!, {R-low-register-list} : (Encoding T2). */
18771 current_stub_contents
=
18772 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18773 create_instruction_ldmia
18774 (rn
, /*wback=*/1, insn_low_registers
));
18776 /* LDMIA Rn!, {R-high-register-list} : (Encoding T2). */
18777 current_stub_contents
=
18778 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18779 create_instruction_ldmia
18780 (rn
, /*wback=*/1, insn_high_registers
));
18783 /* B initial_insn_addr+4. */
18784 current_stub_contents
=
18785 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18786 create_instruction_branch_absolute
18787 (initial_insn_addr
- current_stub_contents
));
18790 else /* if (!wback). */
18794 /* If Rn is not part of the high-register-list, move it there. */
18795 if (!(insn_high_registers
& (1 << rn
)))
18797 /* Choose a Ri in the high-register-list that will be restored. */
18798 ri
= ctz (insn_high_registers
& usable_register_mask
& ~(1 << rn
));
18801 current_stub_contents
=
18802 push_thumb2_insn16 (htab
, output_bfd
, current_stub_contents
,
18803 create_instruction_mov (ri
, rn
));
18806 /* LDMIA Ri!, {R-low-register-list} : (Encoding T2). */
18807 current_stub_contents
=
18808 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18809 create_instruction_ldmia
18810 (ri
, /*wback=*/1, insn_low_registers
));
18812 /* LDMIA Ri, {R-high-register-list} : (Encoding T2). */
18813 current_stub_contents
=
18814 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18815 create_instruction_ldmia
18816 (ri
, /*wback=*/0, insn_high_registers
));
18820 /* B initial_insn_addr+4. */
18821 current_stub_contents
=
18822 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18823 create_instruction_branch_absolute
18824 (initial_insn_addr
- current_stub_contents
));
18828 /* Fill the remaining of the stub with deterministic contents. */
18829 current_stub_contents
=
18830 stm32l4xx_fill_stub_udf (htab
, output_bfd
,
18831 base_stub_contents
, current_stub_contents
,
18832 base_stub_contents
+
18833 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
);
18837 stm32l4xx_create_replacing_stub_ldmdb (struct elf32_arm_link_hash_table
* htab
,
18839 const insn32 initial_insn
,
18840 const bfd_byte
*const initial_insn_addr
,
18841 bfd_byte
*const base_stub_contents
)
18843 int wback
= (initial_insn
& 0x00200000) >> 21;
18844 int ri
, rn
= (initial_insn
& 0x000f0000) >> 16;
18845 int insn_all_registers
= initial_insn
& 0x0000ffff;
18846 int insn_low_registers
, insn_high_registers
;
18847 int usable_register_mask
;
18848 int restore_pc
= (insn_all_registers
& (1 << 15)) ? 1 : 0;
18849 int restore_rn
= (insn_all_registers
& (1 << rn
)) ? 1 : 0;
18850 int nb_registers
= elf32_arm_popcount (insn_all_registers
);
18851 bfd_byte
*current_stub_contents
= base_stub_contents
;
18853 BFD_ASSERT (is_thumb2_ldmdb (initial_insn
));
18855 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
18856 smaller than 8 registers load sequences that do not cause the
18858 if (nb_registers
<= 8)
18860 /* UNTOUCHED : LDMIA Rn{!}, {R-all-register-list}. */
18861 current_stub_contents
=
18862 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18865 /* B initial_insn_addr+4. */
18866 current_stub_contents
=
18867 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18868 create_instruction_branch_absolute
18869 (initial_insn_addr
- current_stub_contents
));
18871 /* Fill the remaining of the stub with deterministic contents. */
18872 current_stub_contents
=
18873 stm32l4xx_fill_stub_udf (htab
, output_bfd
,
18874 base_stub_contents
, current_stub_contents
,
18875 base_stub_contents
+
18876 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
);
18881 /* - reg_list[13] == 0. */
18882 BFD_ASSERT ((insn_all_registers
& (1 << 13)) == 0);
18884 /* - reg_list[14] & reg_list[15] != 1. */
18885 BFD_ASSERT ((insn_all_registers
& 0xC000) != 0xC000);
18887 /* - if (wback==1) reg_list[rn] == 0. */
18888 BFD_ASSERT (!wback
|| !restore_rn
);
18890 /* - nb_registers > 8. */
18891 BFD_ASSERT (elf32_arm_popcount (insn_all_registers
) > 8);
18893 /* At this point, LDMxx initial insn loads between 9 and 14 registers. */
18895 /* In the following algorithm, we split this wide LDM using 2 LDM insn:
18896 - One with the 7 lowest registers (register mask 0x007F)
18897 This LDM will finally contain between 2 and 7 registers
18898 - One with the 7 highest registers (register mask 0xDF80)
18899 This ldm will finally contain between 2 and 7 registers. */
18900 insn_low_registers
= insn_all_registers
& 0x007F;
18901 insn_high_registers
= insn_all_registers
& 0xDF80;
18903 /* A spare register may be needed during this veneer to temporarily
18904 handle the base register. This register will be restored with
18905 the last LDM operation.
18906 The usable register may be any general purpose register (that excludes
18907 PC, SP, LR : register mask is 0x1FFF). */
18908 usable_register_mask
= 0x1FFF;
18910 /* Generate the stub function. */
18911 if (!wback
&& !restore_pc
&& !restore_rn
)
18913 /* Choose a Ri in the low-register-list that will be restored. */
18914 ri
= ctz (insn_low_registers
& usable_register_mask
& ~(1 << rn
));
18917 current_stub_contents
=
18918 push_thumb2_insn16 (htab
, output_bfd
, current_stub_contents
,
18919 create_instruction_mov (ri
, rn
));
18921 /* LDMDB Ri!, {R-high-register-list}. */
18922 current_stub_contents
=
18923 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18924 create_instruction_ldmdb
18925 (ri
, /*wback=*/1, insn_high_registers
));
18927 /* LDMDB Ri, {R-low-register-list}. */
18928 current_stub_contents
=
18929 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18930 create_instruction_ldmdb
18931 (ri
, /*wback=*/0, insn_low_registers
));
18933 /* B initial_insn_addr+4. */
18934 current_stub_contents
=
18935 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18936 create_instruction_branch_absolute
18937 (initial_insn_addr
- current_stub_contents
));
18939 else if (wback
&& !restore_pc
&& !restore_rn
)
18941 /* LDMDB Rn!, {R-high-register-list}. */
18942 current_stub_contents
=
18943 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18944 create_instruction_ldmdb
18945 (rn
, /*wback=*/1, insn_high_registers
));
18947 /* LDMDB Rn!, {R-low-register-list}. */
18948 current_stub_contents
=
18949 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18950 create_instruction_ldmdb
18951 (rn
, /*wback=*/1, insn_low_registers
));
18953 /* B initial_insn_addr+4. */
18954 current_stub_contents
=
18955 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18956 create_instruction_branch_absolute
18957 (initial_insn_addr
- current_stub_contents
));
18959 else if (!wback
&& restore_pc
&& !restore_rn
)
18961 /* Choose a Ri in the high-register-list that will be restored. */
18962 ri
= ctz (insn_high_registers
& usable_register_mask
& ~(1 << rn
));
18964 /* SUB Ri, Rn, #(4*nb_registers). */
18965 current_stub_contents
=
18966 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18967 create_instruction_sub (ri
, rn
, (4 * nb_registers
)));
18969 /* LDMIA Ri!, {R-low-register-list}. */
18970 current_stub_contents
=
18971 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18972 create_instruction_ldmia
18973 (ri
, /*wback=*/1, insn_low_registers
));
18975 /* LDMIA Ri, {R-high-register-list}. */
18976 current_stub_contents
=
18977 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18978 create_instruction_ldmia
18979 (ri
, /*wback=*/0, insn_high_registers
));
18981 else if (wback
&& restore_pc
&& !restore_rn
)
18983 /* Choose a Ri in the high-register-list that will be restored. */
18984 ri
= ctz (insn_high_registers
& usable_register_mask
& ~(1 << rn
));
18986 /* SUB Rn, Rn, #(4*nb_registers) */
18987 current_stub_contents
=
18988 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18989 create_instruction_sub (rn
, rn
, (4 * nb_registers
)));
18992 current_stub_contents
=
18993 push_thumb2_insn16 (htab
, output_bfd
, current_stub_contents
,
18994 create_instruction_mov (ri
, rn
));
18996 /* LDMIA Ri!, {R-low-register-list}. */
18997 current_stub_contents
=
18998 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
18999 create_instruction_ldmia
19000 (ri
, /*wback=*/1, insn_low_registers
));
19002 /* LDMIA Ri, {R-high-register-list}. */
19003 current_stub_contents
=
19004 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19005 create_instruction_ldmia
19006 (ri
, /*wback=*/0, insn_high_registers
));
19008 else if (!wback
&& !restore_pc
&& restore_rn
)
19011 if (!(insn_low_registers
& (1 << rn
)))
19013 /* Choose a Ri in the low-register-list that will be restored. */
19014 ri
= ctz (insn_low_registers
& usable_register_mask
& ~(1 << rn
));
19017 current_stub_contents
=
19018 push_thumb2_insn16 (htab
, output_bfd
, current_stub_contents
,
19019 create_instruction_mov (ri
, rn
));
19022 /* LDMDB Ri!, {R-high-register-list}. */
19023 current_stub_contents
=
19024 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19025 create_instruction_ldmdb
19026 (ri
, /*wback=*/1, insn_high_registers
));
19028 /* LDMDB Ri, {R-low-register-list}. */
19029 current_stub_contents
=
19030 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19031 create_instruction_ldmdb
19032 (ri
, /*wback=*/0, insn_low_registers
));
19034 /* B initial_insn_addr+4. */
19035 current_stub_contents
=
19036 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19037 create_instruction_branch_absolute
19038 (initial_insn_addr
- current_stub_contents
));
19040 else if (!wback
&& restore_pc
&& restore_rn
)
19043 if (!(insn_high_registers
& (1 << rn
)))
19045 /* Choose a Ri in the high-register-list that will be restored. */
19046 ri
= ctz (insn_high_registers
& usable_register_mask
& ~(1 << rn
));
19049 /* SUB Ri, Rn, #(4*nb_registers). */
19050 current_stub_contents
=
19051 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19052 create_instruction_sub (ri
, rn
, (4 * nb_registers
)));
19054 /* LDMIA Ri!, {R-low-register-list}. */
19055 current_stub_contents
=
19056 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19057 create_instruction_ldmia
19058 (ri
, /*wback=*/1, insn_low_registers
));
19060 /* LDMIA Ri, {R-high-register-list}. */
19061 current_stub_contents
=
19062 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19063 create_instruction_ldmia
19064 (ri
, /*wback=*/0, insn_high_registers
));
19066 else if (wback
&& restore_rn
)
19068 /* The assembler should not have accepted to encode this. */
19069 BFD_ASSERT (0 && "Cannot patch an instruction that has an "
19070 "undefined behavior.\n");
19073 /* Fill the remaining of the stub with deterministic contents. */
19074 current_stub_contents
=
19075 stm32l4xx_fill_stub_udf (htab
, output_bfd
,
19076 base_stub_contents
, current_stub_contents
,
19077 base_stub_contents
+
19078 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
);
19083 stm32l4xx_create_replacing_stub_vldm (struct elf32_arm_link_hash_table
* htab
,
19085 const insn32 initial_insn
,
19086 const bfd_byte
*const initial_insn_addr
,
19087 bfd_byte
*const base_stub_contents
)
19089 int num_words
= ((unsigned int) initial_insn
<< 24) >> 24;
19090 bfd_byte
*current_stub_contents
= base_stub_contents
;
19092 BFD_ASSERT (is_thumb2_vldm (initial_insn
));
19094 /* In BFD_ARM_STM32L4XX_FIX_ALL mode we may have to deal with
19095 smaller than 8 words load sequences that do not cause the
19097 if (num_words
<= 8)
19099 /* Untouched instruction. */
19100 current_stub_contents
=
19101 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19104 /* B initial_insn_addr+4. */
19105 current_stub_contents
=
19106 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19107 create_instruction_branch_absolute
19108 (initial_insn_addr
- current_stub_contents
));
19112 bfd_boolean is_dp
= /* DP encoding. */
19113 (initial_insn
& 0xfe100f00) == 0xec100b00;
19114 bfd_boolean is_ia_nobang
= /* (IA without !). */
19115 (((initial_insn
<< 7) >> 28) & 0xd) == 0x4;
19116 bfd_boolean is_ia_bang
= /* (IA with !) - includes VPOP. */
19117 (((initial_insn
<< 7) >> 28) & 0xd) == 0x5;
19118 bfd_boolean is_db_bang
= /* (DB with !). */
19119 (((initial_insn
<< 7) >> 28) & 0xd) == 0x9;
19120 int base_reg
= ((unsigned int) initial_insn
<< 12) >> 28;
19121 /* d = UInt (Vd:D);. */
19122 int first_reg
= ((((unsigned int) initial_insn
<< 16) >> 28) << 1)
19123 | (((unsigned int)initial_insn
<< 9) >> 31);
19125 /* Compute the number of 8-words chunks needed to split. */
19126 int chunks
= (num_words
% 8) ? (num_words
/ 8 + 1) : (num_words
/ 8);
19129 /* The test coverage has been done assuming the following
19130 hypothesis that exactly one of the previous is_ predicates is
19132 BFD_ASSERT ( (is_ia_nobang
^ is_ia_bang
^ is_db_bang
)
19133 && !(is_ia_nobang
& is_ia_bang
& is_db_bang
));
19135 /* We treat the cutting of the words in one pass for all
19136 cases, then we emit the adjustments:
19139 -> vldm rx!, {8_words_or_less} for each needed 8_word
19140 -> sub rx, rx, #size (list)
19143 -> vldm rx!, {8_words_or_less} for each needed 8_word
19144 This also handles vpop instruction (when rx is sp)
19147 -> vldmb rx!, {8_words_or_less} for each needed 8_word. */
19148 for (chunk
= 0; chunk
< chunks
; ++chunk
)
19150 bfd_vma new_insn
= 0;
19152 if (is_ia_nobang
|| is_ia_bang
)
19154 new_insn
= create_instruction_vldmia
19158 chunks
- (chunk
+ 1) ?
19159 8 : num_words
- chunk
* 8,
19160 first_reg
+ chunk
* 8);
19162 else if (is_db_bang
)
19164 new_insn
= create_instruction_vldmdb
19167 chunks
- (chunk
+ 1) ?
19168 8 : num_words
- chunk
* 8,
19169 first_reg
+ chunk
* 8);
19173 current_stub_contents
=
19174 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19178 /* Only this case requires the base register compensation
19182 current_stub_contents
=
19183 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19184 create_instruction_sub
19185 (base_reg
, base_reg
, 4*num_words
));
19188 /* B initial_insn_addr+4. */
19189 current_stub_contents
=
19190 push_thumb2_insn32 (htab
, output_bfd
, current_stub_contents
,
19191 create_instruction_branch_absolute
19192 (initial_insn_addr
- current_stub_contents
));
19195 /* Fill the remaining of the stub with deterministic contents. */
19196 current_stub_contents
=
19197 stm32l4xx_fill_stub_udf (htab
, output_bfd
,
19198 base_stub_contents
, current_stub_contents
,
19199 base_stub_contents
+
19200 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE
);
19204 stm32l4xx_create_replacing_stub (struct elf32_arm_link_hash_table
* htab
,
19206 const insn32 wrong_insn
,
19207 const bfd_byte
*const wrong_insn_addr
,
19208 bfd_byte
*const stub_contents
)
19210 if (is_thumb2_ldmia (wrong_insn
))
19211 stm32l4xx_create_replacing_stub_ldmia (htab
, output_bfd
,
19212 wrong_insn
, wrong_insn_addr
,
19214 else if (is_thumb2_ldmdb (wrong_insn
))
19215 stm32l4xx_create_replacing_stub_ldmdb (htab
, output_bfd
,
19216 wrong_insn
, wrong_insn_addr
,
19218 else if (is_thumb2_vldm (wrong_insn
))
19219 stm32l4xx_create_replacing_stub_vldm (htab
, output_bfd
,
19220 wrong_insn
, wrong_insn_addr
,
19224 /* End of stm32l4xx work-around. */
19227 /* Do code byteswapping. Return FALSE afterwards so that the section is
19228 written out as normal. */
19231 elf32_arm_write_section (bfd
*output_bfd
,
19232 struct bfd_link_info
*link_info
,
19234 bfd_byte
*contents
)
19236 unsigned int mapcount
, errcount
;
19237 _arm_elf_section_data
*arm_data
;
19238 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
19239 elf32_arm_section_map
*map
;
19240 elf32_vfp11_erratum_list
*errnode
;
19241 elf32_stm32l4xx_erratum_list
*stm32l4xx_errnode
;
19244 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
19248 if (globals
== NULL
)
19251 /* If this section has not been allocated an _arm_elf_section_data
19252 structure then we cannot record anything. */
19253 arm_data
= get_arm_elf_section_data (sec
);
19254 if (arm_data
== NULL
)
19257 mapcount
= arm_data
->mapcount
;
19258 map
= arm_data
->map
;
19259 errcount
= arm_data
->erratumcount
;
19263 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
19265 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
19266 errnode
= errnode
->next
)
19268 bfd_vma target
= errnode
->vma
- offset
;
19270 switch (errnode
->type
)
19272 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
19274 bfd_vma branch_to_veneer
;
19275 /* Original condition code of instruction, plus bit mask for
19276 ARM B instruction. */
19277 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
19280 /* The instruction is before the label. */
19283 /* Above offset included in -4 below. */
19284 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
19285 - errnode
->vma
- 4;
19287 if ((signed) branch_to_veneer
< -(1 << 25)
19288 || (signed) branch_to_veneer
>= (1 << 25))
19289 _bfd_error_handler (_("%pB: error: VFP11 veneer out of "
19290 "range"), output_bfd
);
19292 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
19293 contents
[endianflip
^ target
] = insn
& 0xff;
19294 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
19295 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
19296 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
19300 case VFP11_ERRATUM_ARM_VENEER
:
19302 bfd_vma branch_from_veneer
;
19305 /* Take size of veneer into account. */
19306 branch_from_veneer
= errnode
->u
.v
.branch
->vma
19307 - errnode
->vma
- 12;
19309 if ((signed) branch_from_veneer
< -(1 << 25)
19310 || (signed) branch_from_veneer
>= (1 << 25))
19311 _bfd_error_handler (_("%pB: error: VFP11 veneer out of "
19312 "range"), output_bfd
);
19314 /* Original instruction. */
19315 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
19316 contents
[endianflip
^ target
] = insn
& 0xff;
19317 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
19318 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
19319 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
19321 /* Branch back to insn after original insn. */
19322 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
19323 contents
[endianflip
^ (target
+ 4)] = insn
& 0xff;
19324 contents
[endianflip
^ (target
+ 5)] = (insn
>> 8) & 0xff;
19325 contents
[endianflip
^ (target
+ 6)] = (insn
>> 16) & 0xff;
19326 contents
[endianflip
^ (target
+ 7)] = (insn
>> 24) & 0xff;
19336 if (arm_data
->stm32l4xx_erratumcount
!= 0)
19338 for (stm32l4xx_errnode
= arm_data
->stm32l4xx_erratumlist
;
19339 stm32l4xx_errnode
!= 0;
19340 stm32l4xx_errnode
= stm32l4xx_errnode
->next
)
19342 bfd_vma target
= stm32l4xx_errnode
->vma
- offset
;
19344 switch (stm32l4xx_errnode
->type
)
19346 case STM32L4XX_ERRATUM_BRANCH_TO_VENEER
:
19349 bfd_vma branch_to_veneer
=
19350 stm32l4xx_errnode
->u
.b
.veneer
->vma
- stm32l4xx_errnode
->vma
;
19352 if ((signed) branch_to_veneer
< -(1 << 24)
19353 || (signed) branch_to_veneer
>= (1 << 24))
19355 bfd_vma out_of_range
=
19356 ((signed) branch_to_veneer
< -(1 << 24)) ?
19357 - branch_to_veneer
- (1 << 24) :
19358 ((signed) branch_to_veneer
>= (1 << 24)) ?
19359 branch_to_veneer
- (1 << 24) : 0;
19362 (_("%pB(%#" PRIx64
"): error: "
19363 "cannot create STM32L4XX veneer; "
19364 "jump out of range by %" PRId64
" bytes; "
19365 "cannot encode branch instruction"),
19367 (uint64_t) (stm32l4xx_errnode
->vma
- 4),
19368 (int64_t) out_of_range
);
19372 insn
= create_instruction_branch_absolute
19373 (stm32l4xx_errnode
->u
.b
.veneer
->vma
- stm32l4xx_errnode
->vma
);
19375 /* The instruction is before the label. */
19378 put_thumb2_insn (globals
, output_bfd
,
19379 (bfd_vma
) insn
, contents
+ target
);
19383 case STM32L4XX_ERRATUM_VENEER
:
19386 bfd_byte
* veneer_r
;
19389 veneer
= contents
+ target
;
19391 + stm32l4xx_errnode
->u
.b
.veneer
->vma
19392 - stm32l4xx_errnode
->vma
- 4;
19394 if ((signed) (veneer_r
- veneer
-
19395 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE
>
19396 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
?
19397 STM32L4XX_ERRATUM_VLDM_VENEER_SIZE
:
19398 STM32L4XX_ERRATUM_LDM_VENEER_SIZE
) < -(1 << 24)
19399 || (signed) (veneer_r
- veneer
) >= (1 << 24))
19401 _bfd_error_handler (_("%pB: error: cannot create STM32L4XX "
19402 "veneer"), output_bfd
);
19406 /* Original instruction. */
19407 insn
= stm32l4xx_errnode
->u
.v
.branch
->u
.b
.insn
;
19409 stm32l4xx_create_replacing_stub
19410 (globals
, output_bfd
, insn
, (void*)veneer_r
, (void*)veneer
);
19420 if (arm_data
->elf
.this_hdr
.sh_type
== SHT_ARM_EXIDX
)
19422 arm_unwind_table_edit
*edit_node
19423 = arm_data
->u
.exidx
.unwind_edit_list
;
19424 /* Now, sec->size is the size of the section we will write. The original
19425 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
19426 markers) was sec->rawsize. (This isn't the case if we perform no
19427 edits, then rawsize will be zero and we should use size). */
19428 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
19429 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
19430 unsigned int in_index
, out_index
;
19431 bfd_vma add_to_offsets
= 0;
19433 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
19437 unsigned int edit_index
= edit_node
->index
;
19439 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
19441 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
19442 contents
+ in_index
* 8, add_to_offsets
);
19446 else if (in_index
== edit_index
19447 || (in_index
* 8 >= input_size
19448 && edit_index
== UINT_MAX
))
19450 switch (edit_node
->type
)
19452 case DELETE_EXIDX_ENTRY
:
19454 add_to_offsets
+= 8;
19457 case INSERT_EXIDX_CANTUNWIND_AT_END
:
19459 asection
*text_sec
= edit_node
->linked_section
;
19460 bfd_vma text_offset
= text_sec
->output_section
->vma
19461 + text_sec
->output_offset
19463 bfd_vma exidx_offset
= offset
+ out_index
* 8;
19464 unsigned long prel31_offset
;
19466 /* Note: this is meant to be equivalent to an
19467 R_ARM_PREL31 relocation. These synthetic
19468 EXIDX_CANTUNWIND markers are not relocated by the
19469 usual BFD method. */
19470 prel31_offset
= (text_offset
- exidx_offset
)
19472 if (bfd_link_relocatable (link_info
))
19474 /* Here relocation for new EXIDX_CANTUNWIND is
19475 created, so there is no need to
19476 adjust offset by hand. */
19477 prel31_offset
= text_sec
->output_offset
19481 /* First address we can't unwind. */
19482 bfd_put_32 (output_bfd
, prel31_offset
,
19483 &edited_contents
[out_index
* 8]);
19485 /* Code for EXIDX_CANTUNWIND. */
19486 bfd_put_32 (output_bfd
, 0x1,
19487 &edited_contents
[out_index
* 8 + 4]);
19490 add_to_offsets
-= 8;
19495 edit_node
= edit_node
->next
;
19500 /* No more edits, copy remaining entries verbatim. */
19501 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
19502 contents
+ in_index
* 8, add_to_offsets
);
19508 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
19509 bfd_set_section_contents (output_bfd
, sec
->output_section
,
19511 (file_ptr
) sec
->output_offset
, sec
->size
);
19516 /* Fix code to point to Cortex-A8 erratum stubs. */
19517 if (globals
->fix_cortex_a8
)
19519 struct a8_branch_to_stub_data data
;
19521 data
.writing_section
= sec
;
19522 data
.contents
= contents
;
19524 bfd_hash_traverse (& globals
->stub_hash_table
, make_branch_to_a8_stub
,
19531 if (globals
->byteswap_code
)
19533 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
19536 for (i
= 0; i
< mapcount
; i
++)
19538 if (i
== mapcount
- 1)
19541 end
= map
[i
+ 1].vma
;
19543 switch (map
[i
].type
)
19546 /* Byte swap code words. */
19547 while (ptr
+ 3 < end
)
19549 tmp
= contents
[ptr
];
19550 contents
[ptr
] = contents
[ptr
+ 3];
19551 contents
[ptr
+ 3] = tmp
;
19552 tmp
= contents
[ptr
+ 1];
19553 contents
[ptr
+ 1] = contents
[ptr
+ 2];
19554 contents
[ptr
+ 2] = tmp
;
19560 /* Byte swap code halfwords. */
19561 while (ptr
+ 1 < end
)
19563 tmp
= contents
[ptr
];
19564 contents
[ptr
] = contents
[ptr
+ 1];
19565 contents
[ptr
+ 1] = tmp
;
19571 /* Leave data alone. */
19579 arm_data
->mapcount
= -1;
19580 arm_data
->mapsize
= 0;
19581 arm_data
->map
= NULL
;
19586 /* Mangle thumb function symbols as we read them in. */
19589 elf32_arm_swap_symbol_in (bfd
* abfd
,
19592 Elf_Internal_Sym
*dst
)
19594 Elf_Internal_Shdr
*symtab_hdr
;
19595 const char *name
= NULL
;
19597 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
19599 dst
->st_target_internal
= 0;
19601 /* New EABI objects mark thumb function symbols by setting the low bit of
19603 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
19604 || ELF_ST_TYPE (dst
->st_info
) == STT_GNU_IFUNC
)
19606 if (dst
->st_value
& 1)
19608 dst
->st_value
&= ~(bfd_vma
) 1;
19609 ARM_SET_SYM_BRANCH_TYPE (dst
->st_target_internal
,
19610 ST_BRANCH_TO_THUMB
);
19613 ARM_SET_SYM_BRANCH_TYPE (dst
->st_target_internal
, ST_BRANCH_TO_ARM
);
19615 else if (ELF_ST_TYPE (dst
->st_info
) == STT_ARM_TFUNC
)
19617 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_FUNC
);
19618 ARM_SET_SYM_BRANCH_TYPE (dst
->st_target_internal
, ST_BRANCH_TO_THUMB
);
19620 else if (ELF_ST_TYPE (dst
->st_info
) == STT_SECTION
)
19621 ARM_SET_SYM_BRANCH_TYPE (dst
->st_target_internal
, ST_BRANCH_LONG
);
19623 ARM_SET_SYM_BRANCH_TYPE (dst
->st_target_internal
, ST_BRANCH_UNKNOWN
);
19625 /* Mark CMSE special symbols. */
19626 symtab_hdr
= & elf_symtab_hdr (abfd
);
19627 if (symtab_hdr
->sh_size
)
19628 name
= bfd_elf_sym_name (abfd
, symtab_hdr
, dst
, NULL
);
19629 if (name
&& CONST_STRNEQ (name
, CMSE_PREFIX
))
19630 ARM_SET_SYM_CMSE_SPCL (dst
->st_target_internal
);
19636 /* Mangle thumb function symbols as we write them out. */
19639 elf32_arm_swap_symbol_out (bfd
*abfd
,
19640 const Elf_Internal_Sym
*src
,
19644 Elf_Internal_Sym newsym
;
19646 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
19647 of the address set, as per the new EABI. We do this unconditionally
19648 because objcopy does not set the elf header flags until after
19649 it writes out the symbol table. */
19650 if (ARM_GET_SYM_BRANCH_TYPE (src
->st_target_internal
) == ST_BRANCH_TO_THUMB
)
19653 if (ELF_ST_TYPE (src
->st_info
) != STT_GNU_IFUNC
)
19654 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
19655 if (newsym
.st_shndx
!= SHN_UNDEF
)
19657 /* Do this only for defined symbols. At link type, the static
19658 linker will simulate the work of dynamic linker of resolving
19659 symbols and will carry over the thumbness of found symbols to
19660 the output symbol table. It's not clear how it happens, but
19661 the thumbness of undefined symbols can well be different at
19662 runtime, and writing '1' for them will be confusing for users
19663 and possibly for dynamic linker itself.
19665 newsym
.st_value
|= 1;
19670 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
19673 /* Add the PT_ARM_EXIDX program header. */
19676 elf32_arm_modify_segment_map (bfd
*abfd
,
19677 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
19679 struct elf_segment_map
*m
;
19682 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
19683 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
19685 /* If there is already a PT_ARM_EXIDX header, then we do not
19686 want to add another one. This situation arises when running
19687 "strip"; the input binary already has the header. */
19688 m
= elf_seg_map (abfd
);
19689 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
19693 m
= (struct elf_segment_map
*)
19694 bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
19697 m
->p_type
= PT_ARM_EXIDX
;
19699 m
->sections
[0] = sec
;
19701 m
->next
= elf_seg_map (abfd
);
19702 elf_seg_map (abfd
) = m
;
19709 /* We may add a PT_ARM_EXIDX program header. */
19712 elf32_arm_additional_program_headers (bfd
*abfd
,
19713 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
19717 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
19718 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
19724 /* Hook called by the linker routine which adds symbols from an object
19728 elf32_arm_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
19729 Elf_Internal_Sym
*sym
, const char **namep
,
19730 flagword
*flagsp
, asection
**secp
, bfd_vma
*valp
)
19732 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
19733 && (abfd
->flags
& DYNAMIC
) == 0
19734 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
19735 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
19737 if (elf32_arm_hash_table (info
) == NULL
)
19740 if (elf32_arm_hash_table (info
)->vxworks_p
19741 && !elf_vxworks_add_symbol_hook (abfd
, info
, sym
, namep
,
19742 flagsp
, secp
, valp
))
19748 /* We use this to override swap_symbol_in and swap_symbol_out. */
19749 const struct elf_size_info elf32_arm_size_info
=
19751 sizeof (Elf32_External_Ehdr
),
19752 sizeof (Elf32_External_Phdr
),
19753 sizeof (Elf32_External_Shdr
),
19754 sizeof (Elf32_External_Rel
),
19755 sizeof (Elf32_External_Rela
),
19756 sizeof (Elf32_External_Sym
),
19757 sizeof (Elf32_External_Dyn
),
19758 sizeof (Elf_External_Note
),
19762 ELFCLASS32
, EV_CURRENT
,
19763 bfd_elf32_write_out_phdrs
,
19764 bfd_elf32_write_shdrs_and_ehdr
,
19765 bfd_elf32_checksum_contents
,
19766 bfd_elf32_write_relocs
,
19767 elf32_arm_swap_symbol_in
,
19768 elf32_arm_swap_symbol_out
,
19769 bfd_elf32_slurp_reloc_table
,
19770 bfd_elf32_slurp_symbol_table
,
19771 bfd_elf32_swap_dyn_in
,
19772 bfd_elf32_swap_dyn_out
,
19773 bfd_elf32_swap_reloc_in
,
19774 bfd_elf32_swap_reloc_out
,
19775 bfd_elf32_swap_reloca_in
,
19776 bfd_elf32_swap_reloca_out
19780 read_code32 (const bfd
*abfd
, const bfd_byte
*addr
)
19782 /* V7 BE8 code is always little endian. */
19783 if ((elf_elfheader (abfd
)->e_flags
& EF_ARM_BE8
) != 0)
19784 return bfd_getl32 (addr
);
19786 return bfd_get_32 (abfd
, addr
);
19790 read_code16 (const bfd
*abfd
, const bfd_byte
*addr
)
19792 /* V7 BE8 code is always little endian. */
19793 if ((elf_elfheader (abfd
)->e_flags
& EF_ARM_BE8
) != 0)
19794 return bfd_getl16 (addr
);
19796 return bfd_get_16 (abfd
, addr
);
19799 /* Return size of plt0 entry starting at ADDR
19800 or (bfd_vma) -1 if size can not be determined. */
19803 elf32_arm_plt0_size (const bfd
*abfd
, const bfd_byte
*addr
)
19805 bfd_vma first_word
;
19808 first_word
= read_code32 (abfd
, addr
);
19810 if (first_word
== elf32_arm_plt0_entry
[0])
19811 plt0_size
= 4 * ARRAY_SIZE (elf32_arm_plt0_entry
);
19812 else if (first_word
== elf32_thumb2_plt0_entry
[0])
19813 plt0_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry
);
19815 /* We don't yet handle this PLT format. */
19816 return (bfd_vma
) -1;
19821 /* Return size of plt entry starting at offset OFFSET
19822 of plt section located at address START
19823 or (bfd_vma) -1 if size can not be determined. */
19826 elf32_arm_plt_size (const bfd
*abfd
, const bfd_byte
*start
, bfd_vma offset
)
19828 bfd_vma first_insn
;
19829 bfd_vma plt_size
= 0;
19830 const bfd_byte
*addr
= start
+ offset
;
19832 /* PLT entry size if fixed on Thumb-only platforms. */
19833 if (read_code32 (abfd
, start
) == elf32_thumb2_plt0_entry
[0])
19834 return 4 * ARRAY_SIZE (elf32_thumb2_plt_entry
);
19836 /* Respect Thumb stub if necessary. */
19837 if (read_code16 (abfd
, addr
) == elf32_arm_plt_thumb_stub
[0])
19839 plt_size
+= 2 * ARRAY_SIZE(elf32_arm_plt_thumb_stub
);
19842 /* Strip immediate from first add. */
19843 first_insn
= read_code32 (abfd
, addr
+ plt_size
) & 0xffffff00;
19845 #ifdef FOUR_WORD_PLT
19846 if (first_insn
== elf32_arm_plt_entry
[0])
19847 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry
);
19849 if (first_insn
== elf32_arm_plt_entry_long
[0])
19850 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry_long
);
19851 else if (first_insn
== elf32_arm_plt_entry_short
[0])
19852 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry_short
);
19855 /* We don't yet handle this PLT format. */
19856 return (bfd_vma
) -1;
19861 /* Implementation is shamelessly borrowed from _bfd_elf_get_synthetic_symtab. */
19864 elf32_arm_get_synthetic_symtab (bfd
*abfd
,
19865 long symcount ATTRIBUTE_UNUSED
,
19866 asymbol
**syms ATTRIBUTE_UNUSED
,
19876 Elf_Internal_Shdr
*hdr
;
19884 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
19887 if (dynsymcount
<= 0)
19890 relplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
19891 if (relplt
== NULL
)
19894 hdr
= &elf_section_data (relplt
)->this_hdr
;
19895 if (hdr
->sh_link
!= elf_dynsymtab (abfd
)
19896 || (hdr
->sh_type
!= SHT_REL
&& hdr
->sh_type
!= SHT_RELA
))
19899 plt
= bfd_get_section_by_name (abfd
, ".plt");
19903 if (!elf32_arm_size_info
.slurp_reloc_table (abfd
, relplt
, dynsyms
, TRUE
))
19906 data
= plt
->contents
;
19909 if (!bfd_get_full_section_contents(abfd
, (asection
*) plt
, &data
) || data
== NULL
)
19911 bfd_cache_section_contents((asection
*) plt
, data
);
19914 count
= relplt
->size
/ hdr
->sh_entsize
;
19915 size
= count
* sizeof (asymbol
);
19916 p
= relplt
->relocation
;
19917 for (i
= 0; i
< count
; i
++, p
+= elf32_arm_size_info
.int_rels_per_ext_rel
)
19919 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
19920 if (p
->addend
!= 0)
19921 size
+= sizeof ("+0x") - 1 + 8;
19924 s
= *ret
= (asymbol
*) bfd_malloc (size
);
19928 offset
= elf32_arm_plt0_size (abfd
, data
);
19929 if (offset
== (bfd_vma
) -1)
19932 names
= (char *) (s
+ count
);
19933 p
= relplt
->relocation
;
19935 for (i
= 0; i
< count
; i
++, p
+= elf32_arm_size_info
.int_rels_per_ext_rel
)
19939 bfd_vma plt_size
= elf32_arm_plt_size (abfd
, data
, offset
);
19940 if (plt_size
== (bfd_vma
) -1)
19943 *s
= **p
->sym_ptr_ptr
;
19944 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
19945 we are defining a symbol, ensure one of them is set. */
19946 if ((s
->flags
& BSF_LOCAL
) == 0)
19947 s
->flags
|= BSF_GLOBAL
;
19948 s
->flags
|= BSF_SYNTHETIC
;
19953 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
19954 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
19956 if (p
->addend
!= 0)
19960 memcpy (names
, "+0x", sizeof ("+0x") - 1);
19961 names
+= sizeof ("+0x") - 1;
19962 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
19963 for (a
= buf
; *a
== '0'; ++a
)
19966 memcpy (names
, a
, len
);
19969 memcpy (names
, "@plt", sizeof ("@plt"));
19970 names
+= sizeof ("@plt");
19972 offset
+= plt_size
;
19979 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
* hdr
)
19981 if (hdr
->sh_flags
& SHF_ARM_PURECODE
)
19982 *flags
|= SEC_ELF_PURECODE
;
19987 elf32_arm_lookup_section_flags (char *flag_name
)
19989 if (!strcmp (flag_name
, "SHF_ARM_PURECODE"))
19990 return SHF_ARM_PURECODE
;
19992 return SEC_NO_FLAGS
;
19995 static unsigned int
19996 elf32_arm_count_additional_relocs (asection
*sec
)
19998 struct _arm_elf_section_data
*arm_data
;
19999 arm_data
= get_arm_elf_section_data (sec
);
20001 return arm_data
== NULL
? 0 : arm_data
->additional_reloc_count
;
20004 /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which
20005 has a type >= SHT_LOOS. Returns TRUE if these fields were initialised
20006 FALSE otherwise. ISECTION is the best guess matching section from the
20007 input bfd IBFD, but it might be NULL. */
20010 elf32_arm_copy_special_section_fields (const bfd
*ibfd ATTRIBUTE_UNUSED
,
20011 bfd
*obfd ATTRIBUTE_UNUSED
,
20012 const Elf_Internal_Shdr
*isection ATTRIBUTE_UNUSED
,
20013 Elf_Internal_Shdr
*osection
)
20015 switch (osection
->sh_type
)
20017 case SHT_ARM_EXIDX
:
20019 Elf_Internal_Shdr
**oheaders
= elf_elfsections (obfd
);
20020 Elf_Internal_Shdr
**iheaders
= elf_elfsections (ibfd
);
20023 osection
->sh_flags
= SHF_ALLOC
| SHF_LINK_ORDER
;
20024 osection
->sh_info
= 0;
20026 /* The sh_link field must be set to the text section associated with
20027 this index section. Unfortunately the ARM EHABI does not specify
20028 exactly how to determine this association. Our caller does try
20029 to match up OSECTION with its corresponding input section however
20030 so that is a good first guess. */
20031 if (isection
!= NULL
20032 && osection
->bfd_section
!= NULL
20033 && isection
->bfd_section
!= NULL
20034 && isection
->bfd_section
->output_section
!= NULL
20035 && isection
->bfd_section
->output_section
== osection
->bfd_section
20036 && iheaders
!= NULL
20037 && isection
->sh_link
> 0
20038 && isection
->sh_link
< elf_numsections (ibfd
)
20039 && iheaders
[isection
->sh_link
]->bfd_section
!= NULL
20040 && iheaders
[isection
->sh_link
]->bfd_section
->output_section
!= NULL
20043 for (i
= elf_numsections (obfd
); i
-- > 0;)
20044 if (oheaders
[i
]->bfd_section
20045 == iheaders
[isection
->sh_link
]->bfd_section
->output_section
)
20051 /* Failing that we have to find a matching section ourselves. If
20052 we had the output section name available we could compare that
20053 with input section names. Unfortunately we don't. So instead
20054 we use a simple heuristic and look for the nearest executable
20055 section before this one. */
20056 for (i
= elf_numsections (obfd
); i
-- > 0;)
20057 if (oheaders
[i
] == osection
)
20063 if (oheaders
[i
]->sh_type
== SHT_PROGBITS
20064 && (oheaders
[i
]->sh_flags
& (SHF_ALLOC
| SHF_EXECINSTR
))
20065 == (SHF_ALLOC
| SHF_EXECINSTR
))
20071 osection
->sh_link
= i
;
20072 /* If the text section was part of a group
20073 then the index section should be too. */
20074 if (oheaders
[i
]->sh_flags
& SHF_GROUP
)
20075 osection
->sh_flags
|= SHF_GROUP
;
20081 case SHT_ARM_PREEMPTMAP
:
20082 osection
->sh_flags
= SHF_ALLOC
;
20085 case SHT_ARM_ATTRIBUTES
:
20086 case SHT_ARM_DEBUGOVERLAY
:
20087 case SHT_ARM_OVERLAYSECTION
:
20095 /* Returns TRUE if NAME is an ARM mapping symbol.
20096 Traditionally the symbols $a, $d and $t have been used.
20097 The ARM ELF standard also defines $x (for A64 code). It also allows a
20098 period initiated suffix to be added to the symbol: "$[adtx]\.[:sym_char]+".
20099 Other tools might also produce $b (Thumb BL), $f, $p, $m and $v, but we do
20100 not support them here. $t.x indicates the start of ThumbEE instructions. */
20103 is_arm_mapping_symbol (const char * name
)
20105 return name
!= NULL
/* Paranoia. */
20106 && name
[0] == '$' /* Note: if objcopy --prefix-symbols has been used then
20107 the mapping symbols could have acquired a prefix.
20108 We do not support this here, since such symbols no
20109 longer conform to the ARM ELF ABI. */
20110 && (name
[1] == 'a' || name
[1] == 'd' || name
[1] == 't' || name
[1] == 'x')
20111 && (name
[2] == 0 || name
[2] == '.');
20112 /* FIXME: Strictly speaking the symbol is only a valid mapping symbol if
20113 any characters that follow the period are legal characters for the body
20114 of a symbol's name. For now we just assume that this is the case. */
20117 /* Make sure that mapping symbols in object files are not removed via the
20118 "strip --strip-unneeded" tool. These symbols are needed in order to
20119 correctly generate interworking veneers, and for byte swapping code
20120 regions. Once an object file has been linked, it is safe to remove the
20121 symbols as they will no longer be needed. */
20124 elf32_arm_backend_symbol_processing (bfd
*abfd
, asymbol
*sym
)
20126 if (((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
20127 && sym
->section
!= bfd_abs_section_ptr
20128 && is_arm_mapping_symbol (sym
->name
))
20129 sym
->flags
|= BSF_KEEP
;
20132 #undef elf_backend_copy_special_section_fields
20133 #define elf_backend_copy_special_section_fields elf32_arm_copy_special_section_fields
20135 #define ELF_ARCH bfd_arch_arm
20136 #define ELF_TARGET_ID ARM_ELF_DATA
20137 #define ELF_MACHINE_CODE EM_ARM
20138 #ifdef __QNXTARGET__
20139 #define ELF_MAXPAGESIZE 0x1000
20141 #define ELF_MAXPAGESIZE 0x10000
20143 #define ELF_MINPAGESIZE 0x1000
20144 #define ELF_COMMONPAGESIZE 0x1000
20146 #define bfd_elf32_mkobject elf32_arm_mkobject
20148 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
20149 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
20150 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
20151 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
20152 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
20153 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
20154 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
20155 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
20156 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
20157 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
20158 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
20159 #define bfd_elf32_bfd_final_link elf32_arm_final_link
20160 #define bfd_elf32_get_synthetic_symtab elf32_arm_get_synthetic_symtab
20162 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
20163 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
20164 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
20165 #define elf_backend_check_relocs elf32_arm_check_relocs
20166 #define elf_backend_update_relocs elf32_arm_update_relocs
20167 #define elf_backend_relocate_section elf32_arm_relocate_section
20168 #define elf_backend_write_section elf32_arm_write_section
20169 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
20170 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
20171 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
20172 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
20173 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
20174 #define elf_backend_always_size_sections elf32_arm_always_size_sections
20175 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
20176 #define elf_backend_post_process_headers elf32_arm_post_process_headers
20177 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
20178 #define elf_backend_object_p elf32_arm_object_p
20179 #define elf_backend_fake_sections elf32_arm_fake_sections
20180 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
20181 #define elf_backend_final_write_processing elf32_arm_final_write_processing
20182 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
20183 #define elf_backend_size_info elf32_arm_size_info
20184 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
20185 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
20186 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
20187 #define elf_backend_filter_implib_symbols elf32_arm_filter_implib_symbols
20188 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
20189 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
20190 #define elf_backend_count_additional_relocs elf32_arm_count_additional_relocs
20191 #define elf_backend_symbol_processing elf32_arm_backend_symbol_processing
20193 #define elf_backend_can_refcount 1
20194 #define elf_backend_can_gc_sections 1
20195 #define elf_backend_plt_readonly 1
20196 #define elf_backend_want_got_plt 1
20197 #define elf_backend_want_plt_sym 0
20198 #define elf_backend_want_dynrelro 1
20199 #define elf_backend_may_use_rel_p 1
20200 #define elf_backend_may_use_rela_p 0
20201 #define elf_backend_default_use_rela_p 0
20202 #define elf_backend_dtrel_excludes_plt 1
20204 #define elf_backend_got_header_size 12
20205 #define elf_backend_extern_protected_data 1
20207 #undef elf_backend_obj_attrs_vendor
20208 #define elf_backend_obj_attrs_vendor "aeabi"
20209 #undef elf_backend_obj_attrs_section
20210 #define elf_backend_obj_attrs_section ".ARM.attributes"
20211 #undef elf_backend_obj_attrs_arg_type
20212 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
20213 #undef elf_backend_obj_attrs_section_type
20214 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
20215 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
20216 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
20218 #undef elf_backend_section_flags
20219 #define elf_backend_section_flags elf32_arm_section_flags
20220 #undef elf_backend_lookup_section_flags_hook
20221 #define elf_backend_lookup_section_flags_hook elf32_arm_lookup_section_flags
20223 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
20225 #include "elf32-target.h"
20227 /* Native Client targets. */
20229 #undef TARGET_LITTLE_SYM
20230 #define TARGET_LITTLE_SYM arm_elf32_nacl_le_vec
20231 #undef TARGET_LITTLE_NAME
20232 #define TARGET_LITTLE_NAME "elf32-littlearm-nacl"
20233 #undef TARGET_BIG_SYM
20234 #define TARGET_BIG_SYM arm_elf32_nacl_be_vec
20235 #undef TARGET_BIG_NAME
20236 #define TARGET_BIG_NAME "elf32-bigarm-nacl"
20238 /* Like elf32_arm_link_hash_table_create -- but overrides
20239 appropriately for NaCl. */
20241 static struct bfd_link_hash_table
*
20242 elf32_arm_nacl_link_hash_table_create (bfd
*abfd
)
20244 struct bfd_link_hash_table
*ret
;
20246 ret
= elf32_arm_link_hash_table_create (abfd
);
20249 struct elf32_arm_link_hash_table
*htab
20250 = (struct elf32_arm_link_hash_table
*) ret
;
20254 htab
->plt_header_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt0_entry
);
20255 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt_entry
);
20260 /* Since NaCl doesn't use the ARM-specific unwind format, we don't
20261 really need to use elf32_arm_modify_segment_map. But we do it
20262 anyway just to reduce gratuitous differences with the stock ARM backend. */
20265 elf32_arm_nacl_modify_segment_map (bfd
*abfd
, struct bfd_link_info
*info
)
20267 return (elf32_arm_modify_segment_map (abfd
, info
)
20268 && nacl_modify_segment_map (abfd
, info
));
20272 elf32_arm_nacl_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
20274 elf32_arm_final_write_processing (abfd
, linker
);
20275 nacl_final_write_processing (abfd
, linker
);
20279 elf32_arm_nacl_plt_sym_val (bfd_vma i
, const asection
*plt
,
20280 const arelent
*rel ATTRIBUTE_UNUSED
)
20283 + 4 * (ARRAY_SIZE (elf32_arm_nacl_plt0_entry
) +
20284 i
* ARRAY_SIZE (elf32_arm_nacl_plt_entry
));
20288 #define elf32_bed elf32_arm_nacl_bed
20289 #undef bfd_elf32_bfd_link_hash_table_create
20290 #define bfd_elf32_bfd_link_hash_table_create \
20291 elf32_arm_nacl_link_hash_table_create
20292 #undef elf_backend_plt_alignment
20293 #define elf_backend_plt_alignment 4
20294 #undef elf_backend_modify_segment_map
20295 #define elf_backend_modify_segment_map elf32_arm_nacl_modify_segment_map
20296 #undef elf_backend_modify_program_headers
20297 #define elf_backend_modify_program_headers nacl_modify_program_headers
20298 #undef elf_backend_final_write_processing
20299 #define elf_backend_final_write_processing elf32_arm_nacl_final_write_processing
20300 #undef bfd_elf32_get_synthetic_symtab
20301 #undef elf_backend_plt_sym_val
20302 #define elf_backend_plt_sym_val elf32_arm_nacl_plt_sym_val
20303 #undef elf_backend_copy_special_section_fields
20305 #undef ELF_MINPAGESIZE
20306 #undef ELF_COMMONPAGESIZE
20309 #include "elf32-target.h"
20311 /* Reset to defaults. */
20312 #undef elf_backend_plt_alignment
20313 #undef elf_backend_modify_segment_map
20314 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
20315 #undef elf_backend_modify_program_headers
20316 #undef elf_backend_final_write_processing
20317 #define elf_backend_final_write_processing elf32_arm_final_write_processing
20318 #undef ELF_MINPAGESIZE
20319 #define ELF_MINPAGESIZE 0x1000
20320 #undef ELF_COMMONPAGESIZE
20321 #define ELF_COMMONPAGESIZE 0x1000
20324 /* FDPIC Targets. */
20326 #undef TARGET_LITTLE_SYM
20327 #define TARGET_LITTLE_SYM arm_elf32_fdpic_le_vec
20328 #undef TARGET_LITTLE_NAME
20329 #define TARGET_LITTLE_NAME "elf32-littlearm-fdpic"
20330 #undef TARGET_BIG_SYM
20331 #define TARGET_BIG_SYM arm_elf32_fdpic_be_vec
20332 #undef TARGET_BIG_NAME
20333 #define TARGET_BIG_NAME "elf32-bigarm-fdpic"
20334 #undef elf_match_priority
20335 #define elf_match_priority 128
20337 #define ELF_OSABI ELFOSABI_ARM_FDPIC
20339 /* Like elf32_arm_link_hash_table_create -- but overrides
20340 appropriately for FDPIC. */
20342 static struct bfd_link_hash_table
*
20343 elf32_arm_fdpic_link_hash_table_create (bfd
*abfd
)
20345 struct bfd_link_hash_table
*ret
;
20347 ret
= elf32_arm_link_hash_table_create (abfd
);
20350 struct elf32_arm_link_hash_table
*htab
= (struct elf32_arm_link_hash_table
*) ret
;
20357 /* We need dynamic symbols for every section, since segments can
20358 relocate independently. */
20360 elf32_arm_fdpic_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
20361 struct bfd_link_info
*info
20363 asection
*p ATTRIBUTE_UNUSED
)
20365 switch (elf_section_data (p
)->this_hdr
.sh_type
)
20369 /* If sh_type is yet undecided, assume it could be
20370 SHT_PROGBITS/SHT_NOBITS. */
20374 /* There shouldn't be section relative relocations
20375 against any other section. */
20382 #define elf32_bed elf32_arm_fdpic_bed
20384 #undef bfd_elf32_bfd_link_hash_table_create
20385 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_fdpic_link_hash_table_create
20387 #undef elf_backend_omit_section_dynsym
20388 #define elf_backend_omit_section_dynsym elf32_arm_fdpic_omit_section_dynsym
20390 #include "elf32-target.h"
20392 #undef elf_match_priority
20394 #undef elf_backend_omit_section_dynsym
20396 /* VxWorks Targets. */
20398 #undef TARGET_LITTLE_SYM
20399 #define TARGET_LITTLE_SYM arm_elf32_vxworks_le_vec
20400 #undef TARGET_LITTLE_NAME
20401 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
20402 #undef TARGET_BIG_SYM
20403 #define TARGET_BIG_SYM arm_elf32_vxworks_be_vec
20404 #undef TARGET_BIG_NAME
20405 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
20407 /* Like elf32_arm_link_hash_table_create -- but overrides
20408 appropriately for VxWorks. */
20410 static struct bfd_link_hash_table
*
20411 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
20413 struct bfd_link_hash_table
*ret
;
20415 ret
= elf32_arm_link_hash_table_create (abfd
);
20418 struct elf32_arm_link_hash_table
*htab
20419 = (struct elf32_arm_link_hash_table
*) ret
;
20421 htab
->vxworks_p
= 1;
20427 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
20429 elf32_arm_final_write_processing (abfd
, linker
);
20430 elf_vxworks_final_write_processing (abfd
, linker
);
20434 #define elf32_bed elf32_arm_vxworks_bed
20436 #undef bfd_elf32_bfd_link_hash_table_create
20437 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
20438 #undef elf_backend_final_write_processing
20439 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
20440 #undef elf_backend_emit_relocs
20441 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
20443 #undef elf_backend_may_use_rel_p
20444 #define elf_backend_may_use_rel_p 0
20445 #undef elf_backend_may_use_rela_p
20446 #define elf_backend_may_use_rela_p 1
20447 #undef elf_backend_default_use_rela_p
20448 #define elf_backend_default_use_rela_p 1
20449 #undef elf_backend_want_plt_sym
20450 #define elf_backend_want_plt_sym 1
20451 #undef ELF_MAXPAGESIZE
20452 #define ELF_MAXPAGESIZE 0x1000
20454 #include "elf32-target.h"
20457 /* Merge backend specific data from an object file to the output
20458 object file when linking. */
20461 elf32_arm_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
20463 bfd
*obfd
= info
->output_bfd
;
20464 flagword out_flags
;
20466 bfd_boolean flags_compatible
= TRUE
;
20469 /* Check if we have the same endianness. */
20470 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
20473 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
20476 if (!elf32_arm_merge_eabi_attributes (ibfd
, info
))
20479 /* The input BFD must have had its flags initialised. */
20480 /* The following seems bogus to me -- The flags are initialized in
20481 the assembler but I don't think an elf_flags_init field is
20482 written into the object. */
20483 /* BFD_ASSERT (elf_flags_init (ibfd)); */
20485 in_flags
= elf_elfheader (ibfd
)->e_flags
;
20486 out_flags
= elf_elfheader (obfd
)->e_flags
;
20488 /* In theory there is no reason why we couldn't handle this. However
20489 in practice it isn't even close to working and there is no real
20490 reason to want it. */
20491 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
20492 && !(ibfd
->flags
& DYNAMIC
)
20493 && (in_flags
& EF_ARM_BE8
))
20495 _bfd_error_handler (_("error: %pB is already in final BE8 format"),
20500 if (!elf_flags_init (obfd
))
20502 /* If the input is the default architecture and had the default
20503 flags then do not bother setting the flags for the output
20504 architecture, instead allow future merges to do this. If no
20505 future merges ever set these flags then they will retain their
20506 uninitialised values, which surprise surprise, correspond
20507 to the default values. */
20508 if (bfd_get_arch_info (ibfd
)->the_default
20509 && elf_elfheader (ibfd
)->e_flags
== 0)
20512 elf_flags_init (obfd
) = TRUE
;
20513 elf_elfheader (obfd
)->e_flags
= in_flags
;
20515 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
20516 && bfd_get_arch_info (obfd
)->the_default
)
20517 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
20522 /* Determine what should happen if the input ARM architecture
20523 does not match the output ARM architecture. */
20524 if (! bfd_arm_merge_machines (ibfd
, obfd
))
20527 /* Identical flags must be compatible. */
20528 if (in_flags
== out_flags
)
20531 /* Check to see if the input BFD actually contains any sections. If
20532 not, its flags may not have been initialised either, but it
20533 cannot actually cause any incompatiblity. Do not short-circuit
20534 dynamic objects; their section list may be emptied by
20535 elf_link_add_object_symbols.
20537 Also check to see if there are no code sections in the input.
20538 In this case there is no need to check for code specific flags.
20539 XXX - do we need to worry about floating-point format compatability
20540 in data sections ? */
20541 if (!(ibfd
->flags
& DYNAMIC
))
20543 bfd_boolean null_input_bfd
= TRUE
;
20544 bfd_boolean only_data_sections
= TRUE
;
20546 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
20548 /* Ignore synthetic glue sections. */
20549 if (strcmp (sec
->name
, ".glue_7")
20550 && strcmp (sec
->name
, ".glue_7t"))
20552 if ((bfd_get_section_flags (ibfd
, sec
)
20553 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
20554 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
20555 only_data_sections
= FALSE
;
20557 null_input_bfd
= FALSE
;
20562 if (null_input_bfd
|| only_data_sections
)
20566 /* Complain about various flag mismatches. */
20567 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
20568 EF_ARM_EABI_VERSION (out_flags
)))
20571 (_("error: source object %pB has EABI version %d, but target %pB has EABI version %d"),
20572 ibfd
, (in_flags
& EF_ARM_EABIMASK
) >> 24,
20573 obfd
, (out_flags
& EF_ARM_EABIMASK
) >> 24);
20577 /* Not sure what needs to be checked for EABI versions >= 1. */
20578 /* VxWorks libraries do not use these flags. */
20579 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
20580 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
20581 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
20583 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
20586 (_("error: %pB is compiled for APCS-%d, whereas target %pB uses APCS-%d"),
20587 ibfd
, in_flags
& EF_ARM_APCS_26
? 26 : 32,
20588 obfd
, out_flags
& EF_ARM_APCS_26
? 26 : 32);
20589 flags_compatible
= FALSE
;
20592 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
20594 if (in_flags
& EF_ARM_APCS_FLOAT
)
20596 (_("error: %pB passes floats in float registers, whereas %pB passes them in integer registers"),
20600 (_("error: %pB passes floats in integer registers, whereas %pB passes them in float registers"),
20603 flags_compatible
= FALSE
;
20606 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
20608 if (in_flags
& EF_ARM_VFP_FLOAT
)
20610 (_("error: %pB uses %s instructions, whereas %pB does not"),
20611 ibfd
, "VFP", obfd
);
20614 (_("error: %pB uses %s instructions, whereas %pB does not"),
20615 ibfd
, "FPA", obfd
);
20617 flags_compatible
= FALSE
;
20620 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
20622 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
20624 (_("error: %pB uses %s instructions, whereas %pB does not"),
20625 ibfd
, "Maverick", obfd
);
20628 (_("error: %pB does not use %s instructions, whereas %pB does"),
20629 ibfd
, "Maverick", obfd
);
20631 flags_compatible
= FALSE
;
20634 #ifdef EF_ARM_SOFT_FLOAT
20635 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
20637 /* We can allow interworking between code that is VFP format
20638 layout, and uses either soft float or integer regs for
20639 passing floating point arguments and results. We already
20640 know that the APCS_FLOAT flags match; similarly for VFP
20642 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
20643 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
20645 if (in_flags
& EF_ARM_SOFT_FLOAT
)
20647 (_("error: %pB uses software FP, whereas %pB uses hardware FP"),
20651 (_("error: %pB uses hardware FP, whereas %pB uses software FP"),
20654 flags_compatible
= FALSE
;
20659 /* Interworking mismatch is only a warning. */
20660 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
20662 if (in_flags
& EF_ARM_INTERWORK
)
20665 (_("warning: %pB supports interworking, whereas %pB does not"),
20671 (_("warning: %pB does not support interworking, whereas %pB does"),
20677 return flags_compatible
;
20681 /* Symbian OS Targets. */
20683 #undef TARGET_LITTLE_SYM
20684 #define TARGET_LITTLE_SYM arm_elf32_symbian_le_vec
20685 #undef TARGET_LITTLE_NAME
20686 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
20687 #undef TARGET_BIG_SYM
20688 #define TARGET_BIG_SYM arm_elf32_symbian_be_vec
20689 #undef TARGET_BIG_NAME
20690 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
20692 /* Like elf32_arm_link_hash_table_create -- but overrides
20693 appropriately for Symbian OS. */
20695 static struct bfd_link_hash_table
*
20696 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
20698 struct bfd_link_hash_table
*ret
;
20700 ret
= elf32_arm_link_hash_table_create (abfd
);
20703 struct elf32_arm_link_hash_table
*htab
20704 = (struct elf32_arm_link_hash_table
*)ret
;
20705 /* There is no PLT header for Symbian OS. */
20706 htab
->plt_header_size
= 0;
20707 /* The PLT entries are each one instruction and one word. */
20708 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
20709 htab
->symbian_p
= 1;
20710 /* Symbian uses armv5t or above, so use_blx is always true. */
20712 htab
->root
.is_relocatable_executable
= 1;
20717 static const struct bfd_elf_special_section
20718 elf32_arm_symbian_special_sections
[] =
20720 /* In a BPABI executable, the dynamic linking sections do not go in
20721 the loadable read-only segment. The post-linker may wish to
20722 refer to these sections, but they are not part of the final
20724 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
20725 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
20726 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
20727 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
20728 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
20729 /* These sections do not need to be writable as the SymbianOS
20730 postlinker will arrange things so that no dynamic relocation is
20732 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
20733 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
20734 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
20735 { NULL
, 0, 0, 0, 0 }
20739 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
20740 struct bfd_link_info
*link_info
)
20742 /* BPABI objects are never loaded directly by an OS kernel; they are
20743 processed by a postlinker first, into an OS-specific format. If
20744 the D_PAGED bit is set on the file, BFD will align segments on
20745 page boundaries, so that an OS can directly map the file. With
20746 BPABI objects, that just results in wasted space. In addition,
20747 because we clear the D_PAGED bit, map_sections_to_segments will
20748 recognize that the program headers should not be mapped into any
20749 loadable segment. */
20750 abfd
->flags
&= ~D_PAGED
;
20751 elf32_arm_begin_write_processing (abfd
, link_info
);
20755 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
20756 struct bfd_link_info
*info
)
20758 struct elf_segment_map
*m
;
20761 /* BPABI shared libraries and executables should have a PT_DYNAMIC
20762 segment. However, because the .dynamic section is not marked
20763 with SEC_LOAD, the generic ELF code will not create such a
20765 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
20768 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
20769 if (m
->p_type
== PT_DYNAMIC
)
20774 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
20775 m
->next
= elf_seg_map (abfd
);
20776 elf_seg_map (abfd
) = m
;
20780 /* Also call the generic arm routine. */
20781 return elf32_arm_modify_segment_map (abfd
, info
);
20784 /* Return address for Ith PLT stub in section PLT, for relocation REL
20785 or (bfd_vma) -1 if it should not be included. */
20788 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
20789 const arelent
*rel ATTRIBUTE_UNUSED
)
20791 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
20795 #define elf32_bed elf32_arm_symbian_bed
20797 /* The dynamic sections are not allocated on SymbianOS; the postlinker
20798 will process them and then discard them. */
20799 #undef ELF_DYNAMIC_SEC_FLAGS
20800 #define ELF_DYNAMIC_SEC_FLAGS \
20801 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
20803 #undef elf_backend_emit_relocs
20805 #undef bfd_elf32_bfd_link_hash_table_create
20806 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
20807 #undef elf_backend_special_sections
20808 #define elf_backend_special_sections elf32_arm_symbian_special_sections
20809 #undef elf_backend_begin_write_processing
20810 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
20811 #undef elf_backend_final_write_processing
20812 #define elf_backend_final_write_processing elf32_arm_final_write_processing
20814 #undef elf_backend_modify_segment_map
20815 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
20817 /* There is no .got section for BPABI objects, and hence no header. */
20818 #undef elf_backend_got_header_size
20819 #define elf_backend_got_header_size 0
20821 /* Similarly, there is no .got.plt section. */
20822 #undef elf_backend_want_got_plt
20823 #define elf_backend_want_got_plt 0
20825 #undef elf_backend_plt_sym_val
20826 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
20828 #undef elf_backend_may_use_rel_p
20829 #define elf_backend_may_use_rel_p 1
20830 #undef elf_backend_may_use_rela_p
20831 #define elf_backend_may_use_rela_p 0
20832 #undef elf_backend_default_use_rela_p
20833 #define elf_backend_default_use_rela_p 0
20834 #undef elf_backend_want_plt_sym
20835 #define elf_backend_want_plt_sym 0
20836 #undef elf_backend_dtrel_excludes_plt
20837 #define elf_backend_dtrel_excludes_plt 0
20838 #undef ELF_MAXPAGESIZE
20839 #define ELF_MAXPAGESIZE 0x8000
20841 #include "elf32-target.h"