1 /* 32-bit ELF support for ARM
2 Copyright 1998-2013 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "bfd_stdint.h"
26 #include "libiberty.h"
30 #include "elf-vxworks.h"
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
62 #define ARM_ELF_ABI_VERSION 0
63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
65 /* The Adjusted Place, as defined by AAELF. */
66 #define Pa(X) ((X) & 0xfffffffc)
68 static bfd_boolean
elf32_arm_write_section (bfd
*output_bfd
,
69 struct bfd_link_info
*link_info
,
73 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
74 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
77 static reloc_howto_type elf32_arm_howto_table_1
[] =
80 HOWTO (R_ARM_NONE
, /* type */
82 0, /* 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 bfd_elf_generic_reloc
, /* 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 */
1695 static reloc_howto_type elf32_arm_howto_table_2
[1] =
1697 HOWTO (R_ARM_IRELATIVE
, /* type */
1699 2, /* size (0 = byte, 1 = short, 2 = long) */
1701 FALSE
, /* pc_relative */
1703 complain_overflow_bitfield
,/* complain_on_overflow */
1704 bfd_elf_generic_reloc
, /* special_function */
1705 "R_ARM_IRELATIVE", /* name */
1706 TRUE
, /* partial_inplace */
1707 0xffffffff, /* src_mask */
1708 0xffffffff, /* dst_mask */
1709 FALSE
) /* pcrel_offset */
1712 /* 249-255 extended, currently unused, relocations: */
1713 static reloc_howto_type elf32_arm_howto_table_3
[4] =
1715 HOWTO (R_ARM_RREL32
, /* type */
1717 0, /* size (0 = byte, 1 = short, 2 = long) */
1719 FALSE
, /* pc_relative */
1721 complain_overflow_dont
,/* complain_on_overflow */
1722 bfd_elf_generic_reloc
, /* special_function */
1723 "R_ARM_RREL32", /* name */
1724 FALSE
, /* partial_inplace */
1727 FALSE
), /* pcrel_offset */
1729 HOWTO (R_ARM_RABS32
, /* type */
1731 0, /* size (0 = byte, 1 = short, 2 = long) */
1733 FALSE
, /* pc_relative */
1735 complain_overflow_dont
,/* complain_on_overflow */
1736 bfd_elf_generic_reloc
, /* special_function */
1737 "R_ARM_RABS32", /* name */
1738 FALSE
, /* partial_inplace */
1741 FALSE
), /* pcrel_offset */
1743 HOWTO (R_ARM_RPC24
, /* type */
1745 0, /* size (0 = byte, 1 = short, 2 = long) */
1747 FALSE
, /* pc_relative */
1749 complain_overflow_dont
,/* complain_on_overflow */
1750 bfd_elf_generic_reloc
, /* special_function */
1751 "R_ARM_RPC24", /* name */
1752 FALSE
, /* partial_inplace */
1755 FALSE
), /* pcrel_offset */
1757 HOWTO (R_ARM_RBASE
, /* type */
1759 0, /* size (0 = byte, 1 = short, 2 = long) */
1761 FALSE
, /* pc_relative */
1763 complain_overflow_dont
,/* complain_on_overflow */
1764 bfd_elf_generic_reloc
, /* special_function */
1765 "R_ARM_RBASE", /* name */
1766 FALSE
, /* partial_inplace */
1769 FALSE
) /* pcrel_offset */
1772 static reloc_howto_type
*
1773 elf32_arm_howto_from_type (unsigned int r_type
)
1775 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1776 return &elf32_arm_howto_table_1
[r_type
];
1778 if (r_type
== R_ARM_IRELATIVE
)
1779 return &elf32_arm_howto_table_2
[r_type
- R_ARM_IRELATIVE
];
1781 if (r_type
>= R_ARM_RREL32
1782 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_3
))
1783 return &elf32_arm_howto_table_3
[r_type
- R_ARM_RREL32
];
1789 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1790 Elf_Internal_Rela
* elf_reloc
)
1792 unsigned int r_type
;
1794 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1795 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1798 struct elf32_arm_reloc_map
1800 bfd_reloc_code_real_type bfd_reloc_val
;
1801 unsigned char elf_reloc_val
;
1804 /* All entries in this list must also be present in elf32_arm_howto_table. */
1805 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1807 {BFD_RELOC_NONE
, R_ARM_NONE
},
1808 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1809 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1810 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1811 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1812 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1813 {BFD_RELOC_32
, R_ARM_ABS32
},
1814 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1815 {BFD_RELOC_8
, R_ARM_ABS8
},
1816 {BFD_RELOC_16
, R_ARM_ABS16
},
1817 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1818 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1819 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1820 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1821 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1822 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1823 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1824 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1825 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1826 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1827 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1828 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1829 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1830 {BFD_RELOC_ARM_GOT_PREL
, R_ARM_GOT_PREL
},
1831 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1832 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1833 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1834 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1835 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1836 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1837 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1838 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1839 {BFD_RELOC_ARM_TLS_GOTDESC
, R_ARM_TLS_GOTDESC
},
1840 {BFD_RELOC_ARM_TLS_CALL
, R_ARM_TLS_CALL
},
1841 {BFD_RELOC_ARM_THM_TLS_CALL
, R_ARM_THM_TLS_CALL
},
1842 {BFD_RELOC_ARM_TLS_DESCSEQ
, R_ARM_TLS_DESCSEQ
},
1843 {BFD_RELOC_ARM_THM_TLS_DESCSEQ
, R_ARM_THM_TLS_DESCSEQ
},
1844 {BFD_RELOC_ARM_TLS_DESC
, R_ARM_TLS_DESC
},
1845 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1846 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1847 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1848 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1849 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1850 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1851 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1852 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1853 {BFD_RELOC_ARM_IRELATIVE
, R_ARM_IRELATIVE
},
1854 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1855 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1856 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1857 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1858 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1859 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1860 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1861 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1862 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1863 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1864 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1865 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1866 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1867 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1868 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1869 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1870 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1871 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1872 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1873 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1874 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1875 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1876 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1877 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1878 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1879 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1880 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1881 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1882 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1883 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1884 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1885 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1886 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1887 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1888 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1889 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1890 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1891 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
1892 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
}
1895 static reloc_howto_type
*
1896 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1897 bfd_reloc_code_real_type code
)
1901 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
1902 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1903 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1908 static reloc_howto_type
*
1909 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1914 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
1915 if (elf32_arm_howto_table_1
[i
].name
!= NULL
1916 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
1917 return &elf32_arm_howto_table_1
[i
];
1919 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
1920 if (elf32_arm_howto_table_2
[i
].name
!= NULL
1921 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
1922 return &elf32_arm_howto_table_2
[i
];
1924 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_3
); i
++)
1925 if (elf32_arm_howto_table_3
[i
].name
!= NULL
1926 && strcasecmp (elf32_arm_howto_table_3
[i
].name
, r_name
) == 0)
1927 return &elf32_arm_howto_table_3
[i
];
1932 /* Support for core dump NOTE sections. */
1935 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1940 switch (note
->descsz
)
1945 case 148: /* Linux/ARM 32-bit. */
1947 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1950 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1959 /* Make a ".reg/999" section. */
1960 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1961 size
, note
->descpos
+ offset
);
1965 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1967 switch (note
->descsz
)
1972 case 124: /* Linux/ARM elf_prpsinfo. */
1973 elf_tdata (abfd
)->core
->pid
1974 = bfd_get_32 (abfd
, note
->descdata
+ 12);
1975 elf_tdata (abfd
)->core
->program
1976 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1977 elf_tdata (abfd
)->core
->command
1978 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1981 /* Note that for some reason, a spurious space is tacked
1982 onto the end of the args in some (at least one anyway)
1983 implementations, so strip it off if it exists. */
1985 char *command
= elf_tdata (abfd
)->core
->command
;
1986 int n
= strlen (command
);
1988 if (0 < n
&& command
[n
- 1] == ' ')
1989 command
[n
- 1] = '\0';
1996 elf32_arm_nabi_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
,
2009 va_start (ap
, note_type
);
2010 memset (data
, 0, sizeof (data
));
2011 strncpy (data
+ 28, va_arg (ap
, const char *), 16);
2012 strncpy (data
+ 44, va_arg (ap
, const char *), 80);
2015 return elfcore_write_note (abfd
, buf
, bufsiz
,
2016 "CORE", note_type
, data
, sizeof (data
));
2027 va_start (ap
, note_type
);
2028 memset (data
, 0, sizeof (data
));
2029 pid
= va_arg (ap
, long);
2030 bfd_put_32 (abfd
, pid
, data
+ 24);
2031 cursig
= va_arg (ap
, int);
2032 bfd_put_16 (abfd
, cursig
, data
+ 12);
2033 greg
= va_arg (ap
, const void *);
2034 memcpy (data
+ 72, greg
, 72);
2037 return elfcore_write_note (abfd
, buf
, bufsiz
,
2038 "CORE", note_type
, data
, sizeof (data
));
2043 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
2044 #define TARGET_LITTLE_NAME "elf32-littlearm"
2045 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
2046 #define TARGET_BIG_NAME "elf32-bigarm"
2048 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
2049 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
2050 #define elf_backend_write_core_note elf32_arm_nabi_write_core_note
2052 typedef unsigned long int insn32
;
2053 typedef unsigned short int insn16
;
2055 /* In lieu of proper flags, assume all EABIv4 or later objects are
2057 #define INTERWORK_FLAG(abfd) \
2058 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
2059 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
2060 || ((abfd)->flags & BFD_LINKER_CREATED))
2062 /* The linker script knows the section names for placement.
2063 The entry_names are used to do simple name mangling on the stubs.
2064 Given a function name, and its type, the stub can be found. The
2065 name can be changed. The only requirement is the %s be present. */
2066 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
2067 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
2069 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
2070 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
2072 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
2073 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
2075 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
2076 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
2078 #define STUB_ENTRY_NAME "__%s_veneer"
2080 /* The name of the dynamic interpreter. This is put in the .interp
2082 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
2084 static const unsigned long tls_trampoline
[] =
2086 0xe08e0000, /* add r0, lr, r0 */
2087 0xe5901004, /* ldr r1, [r0,#4] */
2088 0xe12fff11, /* bx r1 */
2091 static const unsigned long dl_tlsdesc_lazy_trampoline
[] =
2093 0xe52d2004, /* push {r2} */
2094 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */
2095 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */
2096 0xe79f2002, /* 1: ldr r2, [pc, r2] */
2097 0xe081100f, /* 2: add r1, pc */
2098 0xe12fff12, /* bx r2 */
2099 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8
2100 + dl_tlsdesc_lazy_resolver(GOT) */
2101 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */
2104 #ifdef FOUR_WORD_PLT
2106 /* The first entry in a procedure linkage table looks like
2107 this. It is set up so that any shared library function that is
2108 called before the relocation has been set up calls the dynamic
2110 static const bfd_vma elf32_arm_plt0_entry
[] =
2112 0xe52de004, /* str lr, [sp, #-4]! */
2113 0xe59fe010, /* ldr lr, [pc, #16] */
2114 0xe08fe00e, /* add lr, pc, lr */
2115 0xe5bef008, /* ldr pc, [lr, #8]! */
2118 /* Subsequent entries in a procedure linkage table look like
2120 static const bfd_vma elf32_arm_plt_entry
[] =
2122 0xe28fc600, /* add ip, pc, #NN */
2123 0xe28cca00, /* add ip, ip, #NN */
2124 0xe5bcf000, /* ldr pc, [ip, #NN]! */
2125 0x00000000, /* unused */
2130 /* The first entry in a procedure linkage table looks like
2131 this. It is set up so that any shared library function that is
2132 called before the relocation has been set up calls the dynamic
2134 static const bfd_vma elf32_arm_plt0_entry
[] =
2136 0xe52de004, /* str lr, [sp, #-4]! */
2137 0xe59fe004, /* ldr lr, [pc, #4] */
2138 0xe08fe00e, /* add lr, pc, lr */
2139 0xe5bef008, /* ldr pc, [lr, #8]! */
2140 0x00000000, /* &GOT[0] - . */
2143 /* Subsequent entries in a procedure linkage table look like
2145 static const bfd_vma elf32_arm_plt_entry
[] =
2147 0xe28fc600, /* add ip, pc, #0xNN00000 */
2148 0xe28cca00, /* add ip, ip, #0xNN000 */
2149 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2154 /* The format of the first entry in the procedure linkage table
2155 for a VxWorks executable. */
2156 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
2158 0xe52dc008, /* str ip,[sp,#-8]! */
2159 0xe59fc000, /* ldr ip,[pc] */
2160 0xe59cf008, /* ldr pc,[ip,#8] */
2161 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2164 /* The format of subsequent entries in a VxWorks executable. */
2165 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
2167 0xe59fc000, /* ldr ip,[pc] */
2168 0xe59cf000, /* ldr pc,[ip] */
2169 0x00000000, /* .long @got */
2170 0xe59fc000, /* ldr ip,[pc] */
2171 0xea000000, /* b _PLT */
2172 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2175 /* The format of entries in a VxWorks shared library. */
2176 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
2178 0xe59fc000, /* ldr ip,[pc] */
2179 0xe79cf009, /* ldr pc,[ip,r9] */
2180 0x00000000, /* .long @got */
2181 0xe59fc000, /* ldr ip,[pc] */
2182 0xe599f008, /* ldr pc,[r9,#8] */
2183 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2186 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2187 #define PLT_THUMB_STUB_SIZE 4
2188 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2194 /* The entries in a PLT when using a DLL-based target with multiple
2196 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2198 0xe51ff004, /* ldr pc, [pc, #-4] */
2199 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2202 /* The first entry in a procedure linkage table looks like
2203 this. It is set up so that any shared library function that is
2204 called before the relocation has been set up calls the dynamic
2206 static const bfd_vma elf32_arm_nacl_plt0_entry
[] =
2209 0xe300c000, /* movw ip, #:lower16:&GOT[2]-.+8 */
2210 0xe340c000, /* movt ip, #:upper16:&GOT[2]-.+8 */
2211 0xe08cc00f, /* add ip, ip, pc */
2212 0xe52dc008, /* str ip, [sp, #-8]! */
2213 /* Second bundle: */
2214 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2215 0xe59cc000, /* ldr ip, [ip] */
2216 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2217 0xe12fff1c, /* bx ip */
2219 0xe320f000, /* nop */
2220 0xe320f000, /* nop */
2221 0xe320f000, /* nop */
2223 0xe50dc004, /* str ip, [sp, #-4] */
2224 /* Fourth bundle: */
2225 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2226 0xe59cc000, /* ldr ip, [ip] */
2227 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2228 0xe12fff1c, /* bx ip */
2230 #define ARM_NACL_PLT_TAIL_OFFSET (11 * 4)
2232 /* Subsequent entries in a procedure linkage table look like this. */
2233 static const bfd_vma elf32_arm_nacl_plt_entry
[] =
2235 0xe300c000, /* movw ip, #:lower16:&GOT[n]-.+8 */
2236 0xe340c000, /* movt ip, #:upper16:&GOT[n]-.+8 */
2237 0xe08cc00f, /* add ip, ip, pc */
2238 0xea000000, /* b .Lplt_tail */
2241 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2242 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2243 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2244 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2245 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2246 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2256 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2257 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2258 is inserted in arm_build_one_stub(). */
2259 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2260 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2261 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2262 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2263 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2264 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2269 enum stub_insn_type type
;
2270 unsigned int r_type
;
2274 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2275 to reach the stub if necessary. */
2276 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2278 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2279 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2282 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2284 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2286 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2287 ARM_INSN (0xe12fff1c), /* bx ip */
2288 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2291 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2292 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2294 THUMB16_INSN (0xb401), /* push {r0} */
2295 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2296 THUMB16_INSN (0x4684), /* mov ip, r0 */
2297 THUMB16_INSN (0xbc01), /* pop {r0} */
2298 THUMB16_INSN (0x4760), /* bx ip */
2299 THUMB16_INSN (0xbf00), /* nop */
2300 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2303 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2305 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2307 THUMB16_INSN (0x4778), /* bx pc */
2308 THUMB16_INSN (0x46c0), /* nop */
2309 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2310 ARM_INSN (0xe12fff1c), /* bx ip */
2311 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2314 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2316 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2318 THUMB16_INSN (0x4778), /* bx pc */
2319 THUMB16_INSN (0x46c0), /* nop */
2320 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2321 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2324 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2325 one, when the destination is close enough. */
2326 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2328 THUMB16_INSN (0x4778), /* bx pc */
2329 THUMB16_INSN (0x46c0), /* nop */
2330 ARM_REL_INSN (0xea000000, -8), /* b (X-8) */
2333 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2334 blx to reach the stub if necessary. */
2335 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2337 ARM_INSN (0xe59fc000), /* ldr ip, [pc] */
2338 ARM_INSN (0xe08ff00c), /* add pc, pc, ip */
2339 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2342 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2343 blx to reach the stub if necessary. We can not add into pc;
2344 it is not guaranteed to mode switch (different in ARMv6 and
2346 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2348 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2349 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2350 ARM_INSN (0xe12fff1c), /* bx ip */
2351 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2354 /* V4T ARM -> ARM long branch stub, PIC. */
2355 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2357 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2358 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2359 ARM_INSN (0xe12fff1c), /* bx ip */
2360 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2363 /* V4T Thumb -> ARM long branch stub, PIC. */
2364 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2366 THUMB16_INSN (0x4778), /* bx pc */
2367 THUMB16_INSN (0x46c0), /* nop */
2368 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2369 ARM_INSN (0xe08cf00f), /* add pc, ip, pc */
2370 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2373 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2375 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2377 THUMB16_INSN (0xb401), /* push {r0} */
2378 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2379 THUMB16_INSN (0x46fc), /* mov ip, pc */
2380 THUMB16_INSN (0x4484), /* add ip, r0 */
2381 THUMB16_INSN (0xbc01), /* pop {r0} */
2382 THUMB16_INSN (0x4760), /* bx ip */
2383 DATA_WORD (0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2386 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2388 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2390 THUMB16_INSN (0x4778), /* bx pc */
2391 THUMB16_INSN (0x46c0), /* nop */
2392 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2393 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2394 ARM_INSN (0xe12fff1c), /* bx ip */
2395 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2398 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2399 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2400 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic
[] =
2402 ARM_INSN (0xe59f1000), /* ldr r1, [pc] */
2403 ARM_INSN (0xe08ff001), /* add pc, pc, r1 */
2404 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2407 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2408 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2409 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic
[] =
2411 THUMB16_INSN (0x4778), /* bx pc */
2412 THUMB16_INSN (0x46c0), /* nop */
2413 ARM_INSN (0xe59f1000), /* ldr r1, [pc, #0] */
2414 ARM_INSN (0xe081f00f), /* add pc, r1, pc */
2415 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2418 /* NaCl ARM -> ARM long branch stub. */
2419 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl
[] =
2421 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2422 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2423 ARM_INSN (0xe12fff1c), /* bx ip */
2424 ARM_INSN (0xe320f000), /* nop */
2425 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2426 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2427 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2428 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2431 /* NaCl ARM -> ARM long branch stub, PIC. */
2432 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl_pic
[] =
2434 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2435 ARM_INSN (0xe08cc00f), /* add ip, ip, pc */
2436 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2437 ARM_INSN (0xe12fff1c), /* bx ip */
2438 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2439 DATA_WORD (0, R_ARM_REL32
, 8), /* dcd R_ARM_REL32(X+8) */
2440 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2441 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2445 /* Cortex-A8 erratum-workaround stubs. */
2447 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2448 can't use a conditional branch to reach this stub). */
2450 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond
[] =
2452 THUMB16_BCOND_INSN (0xd001), /* b<cond>.n true. */
2453 THUMB32_B_INSN (0xf000b800, -4), /* b.w insn_after_original_branch. */
2454 THUMB32_B_INSN (0xf000b800, -4) /* true: b.w original_branch_dest. */
2457 /* Stub used for b.w and bl.w instructions. */
2459 static const insn_sequence elf32_arm_stub_a8_veneer_b
[] =
2461 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2464 static const insn_sequence elf32_arm_stub_a8_veneer_bl
[] =
2466 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2469 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2470 instruction (which switches to ARM mode) to point to this stub. Jump to the
2471 real destination using an ARM-mode branch. */
2473 static const insn_sequence elf32_arm_stub_a8_veneer_blx
[] =
2475 ARM_REL_INSN (0xea000000, -8) /* b original_branch_dest. */
2478 /* For each section group there can be a specially created linker section
2479 to hold the stubs for that group. The name of the stub section is based
2480 upon the name of another section within that group with the suffix below
2483 PR 13049: STUB_SUFFIX used to be ".stub", but this allowed the user to
2484 create what appeared to be a linker stub section when it actually
2485 contained user code/data. For example, consider this fragment:
2487 const char * stubborn_problems[] = { "np" };
2489 If this is compiled with "-fPIC -fdata-sections" then gcc produces a
2492 .data.rel.local.stubborn_problems
2494 This then causes problems in arm32_arm_build_stubs() as it triggers:
2496 // Ignore non-stub sections.
2497 if (!strstr (stub_sec->name, STUB_SUFFIX))
2500 And so the section would be ignored instead of being processed. Hence
2501 the change in definition of STUB_SUFFIX to a name that cannot be a valid
2503 #define STUB_SUFFIX ".__stub"
2505 /* One entry per long/short branch stub defined above. */
2507 DEF_STUB(long_branch_any_any) \
2508 DEF_STUB(long_branch_v4t_arm_thumb) \
2509 DEF_STUB(long_branch_thumb_only) \
2510 DEF_STUB(long_branch_v4t_thumb_thumb) \
2511 DEF_STUB(long_branch_v4t_thumb_arm) \
2512 DEF_STUB(short_branch_v4t_thumb_arm) \
2513 DEF_STUB(long_branch_any_arm_pic) \
2514 DEF_STUB(long_branch_any_thumb_pic) \
2515 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2516 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2517 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2518 DEF_STUB(long_branch_thumb_only_pic) \
2519 DEF_STUB(long_branch_any_tls_pic) \
2520 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2521 DEF_STUB(long_branch_arm_nacl) \
2522 DEF_STUB(long_branch_arm_nacl_pic) \
2523 DEF_STUB(a8_veneer_b_cond) \
2524 DEF_STUB(a8_veneer_b) \
2525 DEF_STUB(a8_veneer_bl) \
2526 DEF_STUB(a8_veneer_blx)
2528 #define DEF_STUB(x) arm_stub_##x,
2529 enum elf32_arm_stub_type
2533 /* Note the first a8_veneer type */
2534 arm_stub_a8_veneer_lwm
= arm_stub_a8_veneer_b_cond
2540 const insn_sequence
* template_sequence
;
2544 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2545 static const stub_def stub_definitions
[] =
2551 struct elf32_arm_stub_hash_entry
2553 /* Base hash table entry structure. */
2554 struct bfd_hash_entry root
;
2556 /* The stub section. */
2559 /* Offset within stub_sec of the beginning of this stub. */
2560 bfd_vma stub_offset
;
2562 /* Given the symbol's value and its section we can determine its final
2563 value when building the stubs (so the stub knows where to jump). */
2564 bfd_vma target_value
;
2565 asection
*target_section
;
2567 /* Offset to apply to relocation referencing target_value. */
2568 bfd_vma target_addend
;
2570 /* The instruction which caused this stub to be generated (only valid for
2571 Cortex-A8 erratum workaround stubs at present). */
2572 unsigned long orig_insn
;
2574 /* The stub type. */
2575 enum elf32_arm_stub_type stub_type
;
2576 /* Its encoding size in bytes. */
2579 const insn_sequence
*stub_template
;
2580 /* The size of the template (number of entries). */
2581 int stub_template_size
;
2583 /* The symbol table entry, if any, that this was derived from. */
2584 struct elf32_arm_link_hash_entry
*h
;
2586 /* Type of branch. */
2587 enum arm_st_branch_type branch_type
;
2589 /* Where this stub is being called from, or, in the case of combined
2590 stub sections, the first input section in the group. */
2593 /* The name for the local symbol at the start of this stub. The
2594 stub name in the hash table has to be unique; this does not, so
2595 it can be friendlier. */
2599 /* Used to build a map of a section. This is required for mixed-endian
2602 typedef struct elf32_elf_section_map
2607 elf32_arm_section_map
;
2609 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2613 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2614 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2615 VFP11_ERRATUM_ARM_VENEER
,
2616 VFP11_ERRATUM_THUMB_VENEER
2618 elf32_vfp11_erratum_type
;
2620 typedef struct elf32_vfp11_erratum_list
2622 struct elf32_vfp11_erratum_list
*next
;
2628 struct elf32_vfp11_erratum_list
*veneer
;
2629 unsigned int vfp_insn
;
2633 struct elf32_vfp11_erratum_list
*branch
;
2637 elf32_vfp11_erratum_type type
;
2639 elf32_vfp11_erratum_list
;
2644 INSERT_EXIDX_CANTUNWIND_AT_END
2646 arm_unwind_edit_type
;
2648 /* A (sorted) list of edits to apply to an unwind table. */
2649 typedef struct arm_unwind_table_edit
2651 arm_unwind_edit_type type
;
2652 /* Note: we sometimes want to insert an unwind entry corresponding to a
2653 section different from the one we're currently writing out, so record the
2654 (text) section this edit relates to here. */
2655 asection
*linked_section
;
2657 struct arm_unwind_table_edit
*next
;
2659 arm_unwind_table_edit
;
2661 typedef struct _arm_elf_section_data
2663 /* Information about mapping symbols. */
2664 struct bfd_elf_section_data elf
;
2665 unsigned int mapcount
;
2666 unsigned int mapsize
;
2667 elf32_arm_section_map
*map
;
2668 /* Information about CPU errata. */
2669 unsigned int erratumcount
;
2670 elf32_vfp11_erratum_list
*erratumlist
;
2671 /* Information about unwind tables. */
2674 /* Unwind info attached to a text section. */
2677 asection
*arm_exidx_sec
;
2680 /* Unwind info attached to an .ARM.exidx section. */
2683 arm_unwind_table_edit
*unwind_edit_list
;
2684 arm_unwind_table_edit
*unwind_edit_tail
;
2688 _arm_elf_section_data
;
2690 #define elf32_arm_section_data(sec) \
2691 ((_arm_elf_section_data *) elf_section_data (sec))
2693 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2694 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2695 so may be created multiple times: we use an array of these entries whilst
2696 relaxing which we can refresh easily, then create stubs for each potentially
2697 erratum-triggering instruction once we've settled on a solution. */
2699 struct a8_erratum_fix
2705 unsigned long orig_insn
;
2707 enum elf32_arm_stub_type stub_type
;
2708 enum arm_st_branch_type branch_type
;
2711 /* A table of relocs applied to branches which might trigger Cortex-A8
2714 struct a8_erratum_reloc
2717 bfd_vma destination
;
2718 struct elf32_arm_link_hash_entry
*hash
;
2719 const char *sym_name
;
2720 unsigned int r_type
;
2721 enum arm_st_branch_type branch_type
;
2722 bfd_boolean non_a8_stub
;
2725 /* The size of the thread control block. */
2728 /* ARM-specific information about a PLT entry, over and above the usual
2732 /* We reference count Thumb references to a PLT entry separately,
2733 so that we can emit the Thumb trampoline only if needed. */
2734 bfd_signed_vma thumb_refcount
;
2736 /* Some references from Thumb code may be eliminated by BL->BLX
2737 conversion, so record them separately. */
2738 bfd_signed_vma maybe_thumb_refcount
;
2740 /* How many of the recorded PLT accesses were from non-call relocations.
2741 This information is useful when deciding whether anything takes the
2742 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
2743 non-call references to the function should resolve directly to the
2744 real runtime target. */
2745 unsigned int noncall_refcount
;
2747 /* Since PLT entries have variable size if the Thumb prologue is
2748 used, we need to record the index into .got.plt instead of
2749 recomputing it from the PLT offset. */
2750 bfd_signed_vma got_offset
;
2753 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
2754 struct arm_local_iplt_info
2756 /* The information that is usually found in the generic ELF part of
2757 the hash table entry. */
2758 union gotplt_union root
;
2760 /* The information that is usually found in the ARM-specific part of
2761 the hash table entry. */
2762 struct arm_plt_info arm
;
2764 /* A list of all potential dynamic relocations against this symbol. */
2765 struct elf_dyn_relocs
*dyn_relocs
;
2768 struct elf_arm_obj_tdata
2770 struct elf_obj_tdata root
;
2772 /* tls_type for each local got entry. */
2773 char *local_got_tls_type
;
2775 /* GOTPLT entries for TLS descriptors. */
2776 bfd_vma
*local_tlsdesc_gotent
;
2778 /* Information for local symbols that need entries in .iplt. */
2779 struct arm_local_iplt_info
**local_iplt
;
2781 /* Zero to warn when linking objects with incompatible enum sizes. */
2782 int no_enum_size_warning
;
2784 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2785 int no_wchar_size_warning
;
2788 #define elf_arm_tdata(bfd) \
2789 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2791 #define elf32_arm_local_got_tls_type(bfd) \
2792 (elf_arm_tdata (bfd)->local_got_tls_type)
2794 #define elf32_arm_local_tlsdesc_gotent(bfd) \
2795 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
2797 #define elf32_arm_local_iplt(bfd) \
2798 (elf_arm_tdata (bfd)->local_iplt)
2800 #define is_arm_elf(bfd) \
2801 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2802 && elf_tdata (bfd) != NULL \
2803 && elf_object_id (bfd) == ARM_ELF_DATA)
2806 elf32_arm_mkobject (bfd
*abfd
)
2808 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2812 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2814 /* Arm ELF linker hash entry. */
2815 struct elf32_arm_link_hash_entry
2817 struct elf_link_hash_entry root
;
2819 /* Track dynamic relocs copied for this symbol. */
2820 struct elf_dyn_relocs
*dyn_relocs
;
2822 /* ARM-specific PLT information. */
2823 struct arm_plt_info plt
;
2825 #define GOT_UNKNOWN 0
2826 #define GOT_NORMAL 1
2827 #define GOT_TLS_GD 2
2828 #define GOT_TLS_IE 4
2829 #define GOT_TLS_GDESC 8
2830 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
2831 unsigned int tls_type
: 8;
2833 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
2834 unsigned int is_iplt
: 1;
2836 unsigned int unused
: 23;
2838 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
2839 starting at the end of the jump table. */
2840 bfd_vma tlsdesc_got
;
2842 /* The symbol marking the real symbol location for exported thumb
2843 symbols with Arm stubs. */
2844 struct elf_link_hash_entry
*export_glue
;
2846 /* A pointer to the most recently used stub hash entry against this
2848 struct elf32_arm_stub_hash_entry
*stub_cache
;
2851 /* Traverse an arm ELF linker hash table. */
2852 #define elf32_arm_link_hash_traverse(table, func, info) \
2853 (elf_link_hash_traverse \
2855 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2858 /* Get the ARM elf linker hash table from a link_info structure. */
2859 #define elf32_arm_hash_table(info) \
2860 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
2861 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
2863 #define arm_stub_hash_lookup(table, string, create, copy) \
2864 ((struct elf32_arm_stub_hash_entry *) \
2865 bfd_hash_lookup ((table), (string), (create), (copy)))
2867 /* Array to keep track of which stub sections have been created, and
2868 information on stub grouping. */
2871 /* This is the section to which stubs in the group will be
2874 /* The stub section. */
2878 #define elf32_arm_compute_jump_table_size(htab) \
2879 ((htab)->next_tls_desc_index * 4)
2881 /* ARM ELF linker hash table. */
2882 struct elf32_arm_link_hash_table
2884 /* The main hash table. */
2885 struct elf_link_hash_table root
;
2887 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2888 bfd_size_type thumb_glue_size
;
2890 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2891 bfd_size_type arm_glue_size
;
2893 /* The size in bytes of section containing the ARMv4 BX veneers. */
2894 bfd_size_type bx_glue_size
;
2896 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2897 veneer has been populated. */
2898 bfd_vma bx_glue_offset
[15];
2900 /* The size in bytes of the section containing glue for VFP11 erratum
2902 bfd_size_type vfp11_erratum_glue_size
;
2904 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
2905 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
2906 elf32_arm_write_section(). */
2907 struct a8_erratum_fix
*a8_erratum_fixes
;
2908 unsigned int num_a8_erratum_fixes
;
2910 /* An arbitrary input BFD chosen to hold the glue sections. */
2911 bfd
* bfd_of_glue_owner
;
2913 /* Nonzero to output a BE8 image. */
2916 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2917 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2920 /* The relocation to use for R_ARM_TARGET2 relocations. */
2923 /* 0 = Ignore R_ARM_V4BX.
2924 1 = Convert BX to MOV PC.
2925 2 = Generate v4 interworing stubs. */
2928 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
2931 /* Whether we should fix the ARM1176 BLX immediate issue. */
2934 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2937 /* What sort of code sequences we should look for which may trigger the
2938 VFP11 denorm erratum. */
2939 bfd_arm_vfp11_fix vfp11_fix
;
2941 /* Global counter for the number of fixes we have emitted. */
2942 int num_vfp11_fixes
;
2944 /* Nonzero to force PIC branch veneers. */
2947 /* The number of bytes in the initial entry in the PLT. */
2948 bfd_size_type plt_header_size
;
2950 /* The number of bytes in the subsequent PLT etries. */
2951 bfd_size_type plt_entry_size
;
2953 /* True if the target system is VxWorks. */
2956 /* True if the target system is Symbian OS. */
2959 /* True if the target system is Native Client. */
2962 /* True if the target uses REL relocations. */
2965 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
2966 bfd_vma next_tls_desc_index
;
2968 /* How many R_ARM_TLS_DESC relocations were generated so far. */
2969 bfd_vma num_tls_desc
;
2971 /* Short-cuts to get to dynamic linker sections. */
2975 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2978 /* The offset into splt of the PLT entry for the TLS descriptor
2979 resolver. Special values are 0, if not necessary (or not found
2980 to be necessary yet), and -1 if needed but not determined
2982 bfd_vma dt_tlsdesc_plt
;
2984 /* The offset into sgot of the GOT entry used by the PLT entry
2986 bfd_vma dt_tlsdesc_got
;
2988 /* Offset in .plt section of tls_arm_trampoline. */
2989 bfd_vma tls_trampoline
;
2991 /* Data for R_ARM_TLS_LDM32 relocations. */
2994 bfd_signed_vma refcount
;
2998 /* Small local sym cache. */
2999 struct sym_cache sym_cache
;
3001 /* For convenience in allocate_dynrelocs. */
3004 /* The amount of space used by the reserved portion of the sgotplt
3005 section, plus whatever space is used by the jump slots. */
3006 bfd_vma sgotplt_jump_table_size
;
3008 /* The stub hash table. */
3009 struct bfd_hash_table stub_hash_table
;
3011 /* Linker stub bfd. */
3014 /* Linker call-backs. */
3015 asection
* (*add_stub_section
) (const char *, asection
*, unsigned int);
3016 void (*layout_sections_again
) (void);
3018 /* Array to keep track of which stub sections have been created, and
3019 information on stub grouping. */
3020 struct map_stub
*stub_group
;
3022 /* Number of elements in stub_group. */
3025 /* Assorted information used by elf32_arm_size_stubs. */
3026 unsigned int bfd_count
;
3028 asection
**input_list
;
3031 /* Create an entry in an ARM ELF linker hash table. */
3033 static struct bfd_hash_entry
*
3034 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
3035 struct bfd_hash_table
* table
,
3036 const char * string
)
3038 struct elf32_arm_link_hash_entry
* ret
=
3039 (struct elf32_arm_link_hash_entry
*) entry
;
3041 /* Allocate the structure if it has not already been allocated by a
3044 ret
= (struct elf32_arm_link_hash_entry
*)
3045 bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
3047 return (struct bfd_hash_entry
*) ret
;
3049 /* Call the allocation method of the superclass. */
3050 ret
= ((struct elf32_arm_link_hash_entry
*)
3051 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3055 ret
->dyn_relocs
= NULL
;
3056 ret
->tls_type
= GOT_UNKNOWN
;
3057 ret
->tlsdesc_got
= (bfd_vma
) -1;
3058 ret
->plt
.thumb_refcount
= 0;
3059 ret
->plt
.maybe_thumb_refcount
= 0;
3060 ret
->plt
.noncall_refcount
= 0;
3061 ret
->plt
.got_offset
= -1;
3062 ret
->is_iplt
= FALSE
;
3063 ret
->export_glue
= NULL
;
3065 ret
->stub_cache
= NULL
;
3068 return (struct bfd_hash_entry
*) ret
;
3071 /* Ensure that we have allocated bookkeeping structures for ABFD's local
3075 elf32_arm_allocate_local_sym_info (bfd
*abfd
)
3077 if (elf_local_got_refcounts (abfd
) == NULL
)
3079 bfd_size_type num_syms
;
3083 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
3084 size
= num_syms
* (sizeof (bfd_signed_vma
)
3085 + sizeof (struct arm_local_iplt_info
*)
3088 data
= bfd_zalloc (abfd
, size
);
3092 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
3093 data
+= num_syms
* sizeof (bfd_signed_vma
);
3095 elf32_arm_local_iplt (abfd
) = (struct arm_local_iplt_info
**) data
;
3096 data
+= num_syms
* sizeof (struct arm_local_iplt_info
*);
3098 elf32_arm_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
3099 data
+= num_syms
* sizeof (bfd_vma
);
3101 elf32_arm_local_got_tls_type (abfd
) = data
;
3106 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
3107 to input bfd ABFD. Create the information if it doesn't already exist.
3108 Return null if an allocation fails. */
3110 static struct arm_local_iplt_info
*
3111 elf32_arm_create_local_iplt (bfd
*abfd
, unsigned long r_symndx
)
3113 struct arm_local_iplt_info
**ptr
;
3115 if (!elf32_arm_allocate_local_sym_info (abfd
))
3118 BFD_ASSERT (r_symndx
< elf_tdata (abfd
)->symtab_hdr
.sh_info
);
3119 ptr
= &elf32_arm_local_iplt (abfd
)[r_symndx
];
3121 *ptr
= bfd_zalloc (abfd
, sizeof (**ptr
));
3125 /* Try to obtain PLT information for the symbol with index R_SYMNDX
3126 in ABFD's symbol table. If the symbol is global, H points to its
3127 hash table entry, otherwise H is null.
3129 Return true if the symbol does have PLT information. When returning
3130 true, point *ROOT_PLT at the target-independent reference count/offset
3131 union and *ARM_PLT at the ARM-specific information. */
3134 elf32_arm_get_plt_info (bfd
*abfd
, struct elf32_arm_link_hash_entry
*h
,
3135 unsigned long r_symndx
, union gotplt_union
**root_plt
,
3136 struct arm_plt_info
**arm_plt
)
3138 struct arm_local_iplt_info
*local_iplt
;
3142 *root_plt
= &h
->root
.plt
;
3147 if (elf32_arm_local_iplt (abfd
) == NULL
)
3150 local_iplt
= elf32_arm_local_iplt (abfd
)[r_symndx
];
3151 if (local_iplt
== NULL
)
3154 *root_plt
= &local_iplt
->root
;
3155 *arm_plt
= &local_iplt
->arm
;
3159 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3163 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info
*info
,
3164 struct arm_plt_info
*arm_plt
)
3166 struct elf32_arm_link_hash_table
*htab
;
3168 htab
= elf32_arm_hash_table (info
);
3169 return (arm_plt
->thumb_refcount
!= 0
3170 || (!htab
->use_blx
&& arm_plt
->maybe_thumb_refcount
!= 0));
3173 /* Return a pointer to the head of the dynamic reloc list that should
3174 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3175 ABFD's symbol table. Return null if an error occurs. */
3177 static struct elf_dyn_relocs
**
3178 elf32_arm_get_local_dynreloc_list (bfd
*abfd
, unsigned long r_symndx
,
3179 Elf_Internal_Sym
*isym
)
3181 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
3183 struct arm_local_iplt_info
*local_iplt
;
3185 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
3186 if (local_iplt
== NULL
)
3188 return &local_iplt
->dyn_relocs
;
3192 /* Track dynamic relocs needed for local syms too.
3193 We really need local syms available to do this
3198 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3202 vpp
= &elf_section_data (s
)->local_dynrel
;
3203 return (struct elf_dyn_relocs
**) vpp
;
3207 /* Initialize an entry in the stub hash table. */
3209 static struct bfd_hash_entry
*
3210 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3211 struct bfd_hash_table
*table
,
3214 /* Allocate the structure if it has not already been allocated by a
3218 entry
= (struct bfd_hash_entry
*)
3219 bfd_hash_allocate (table
, sizeof (struct elf32_arm_stub_hash_entry
));
3224 /* Call the allocation method of the superclass. */
3225 entry
= bfd_hash_newfunc (entry
, table
, string
);
3228 struct elf32_arm_stub_hash_entry
*eh
;
3230 /* Initialize the local fields. */
3231 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
3232 eh
->stub_sec
= NULL
;
3233 eh
->stub_offset
= 0;
3234 eh
->target_value
= 0;
3235 eh
->target_section
= NULL
;
3236 eh
->target_addend
= 0;
3238 eh
->stub_type
= arm_stub_none
;
3240 eh
->stub_template
= NULL
;
3241 eh
->stub_template_size
= 0;
3244 eh
->output_name
= NULL
;
3250 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3251 shortcuts to them in our hash table. */
3254 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3256 struct elf32_arm_link_hash_table
*htab
;
3258 htab
= elf32_arm_hash_table (info
);
3262 /* BPABI objects never have a GOT, or associated sections. */
3263 if (htab
->symbian_p
)
3266 if (! _bfd_elf_create_got_section (dynobj
, info
))
3272 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3275 create_ifunc_sections (struct bfd_link_info
*info
)
3277 struct elf32_arm_link_hash_table
*htab
;
3278 const struct elf_backend_data
*bed
;
3283 htab
= elf32_arm_hash_table (info
);
3284 dynobj
= htab
->root
.dynobj
;
3285 bed
= get_elf_backend_data (dynobj
);
3286 flags
= bed
->dynamic_sec_flags
;
3288 if (htab
->root
.iplt
== NULL
)
3290 s
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt",
3291 flags
| SEC_READONLY
| SEC_CODE
);
3293 || !bfd_set_section_alignment (dynobj
, s
, bed
->plt_alignment
))
3295 htab
->root
.iplt
= s
;
3298 if (htab
->root
.irelplt
== NULL
)
3300 s
= bfd_make_section_anyway_with_flags (dynobj
,
3301 RELOC_SECTION (htab
, ".iplt"),
3302 flags
| SEC_READONLY
);
3304 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3306 htab
->root
.irelplt
= s
;
3309 if (htab
->root
.igotplt
== NULL
)
3311 s
= bfd_make_section_anyway_with_flags (dynobj
, ".igot.plt", flags
);
3313 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3315 htab
->root
.igotplt
= s
;
3320 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3321 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3325 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3327 struct elf32_arm_link_hash_table
*htab
;
3329 htab
= elf32_arm_hash_table (info
);
3333 if (!htab
->root
.sgot
&& !create_got_section (dynobj
, info
))
3336 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3339 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
3341 htab
->srelbss
= bfd_get_linker_section (dynobj
,
3342 RELOC_SECTION (htab
, ".bss"));
3344 if (htab
->vxworks_p
)
3346 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
3351 htab
->plt_header_size
= 0;
3352 htab
->plt_entry_size
3353 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
3357 htab
->plt_header_size
3358 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
3359 htab
->plt_entry_size
3360 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
3364 if (!htab
->root
.splt
3365 || !htab
->root
.srelplt
3367 || (!info
->shared
&& !htab
->srelbss
))
3373 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3376 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
3377 struct elf_link_hash_entry
*dir
,
3378 struct elf_link_hash_entry
*ind
)
3380 struct elf32_arm_link_hash_entry
*edir
, *eind
;
3382 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
3383 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
3385 if (eind
->dyn_relocs
!= NULL
)
3387 if (edir
->dyn_relocs
!= NULL
)
3389 struct elf_dyn_relocs
**pp
;
3390 struct elf_dyn_relocs
*p
;
3392 /* Add reloc counts against the indirect sym to the direct sym
3393 list. Merge any entries against the same section. */
3394 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3396 struct elf_dyn_relocs
*q
;
3398 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3399 if (q
->sec
== p
->sec
)
3401 q
->pc_count
+= p
->pc_count
;
3402 q
->count
+= p
->count
;
3409 *pp
= edir
->dyn_relocs
;
3412 edir
->dyn_relocs
= eind
->dyn_relocs
;
3413 eind
->dyn_relocs
= NULL
;
3416 if (ind
->root
.type
== bfd_link_hash_indirect
)
3418 /* Copy over PLT info. */
3419 edir
->plt
.thumb_refcount
+= eind
->plt
.thumb_refcount
;
3420 eind
->plt
.thumb_refcount
= 0;
3421 edir
->plt
.maybe_thumb_refcount
+= eind
->plt
.maybe_thumb_refcount
;
3422 eind
->plt
.maybe_thumb_refcount
= 0;
3423 edir
->plt
.noncall_refcount
+= eind
->plt
.noncall_refcount
;
3424 eind
->plt
.noncall_refcount
= 0;
3426 /* We should only allocate a function to .iplt once the final
3427 symbol information is known. */
3428 BFD_ASSERT (!eind
->is_iplt
);
3430 if (dir
->got
.refcount
<= 0)
3432 edir
->tls_type
= eind
->tls_type
;
3433 eind
->tls_type
= GOT_UNKNOWN
;
3437 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3440 /* Create an ARM elf linker hash table. */
3442 static struct bfd_link_hash_table
*
3443 elf32_arm_link_hash_table_create (bfd
*abfd
)
3445 struct elf32_arm_link_hash_table
*ret
;
3446 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
3448 ret
= (struct elf32_arm_link_hash_table
*) bfd_zmalloc (amt
);
3452 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
3453 elf32_arm_link_hash_newfunc
,
3454 sizeof (struct elf32_arm_link_hash_entry
),
3461 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
3462 #ifdef FOUR_WORD_PLT
3463 ret
->plt_header_size
= 16;
3464 ret
->plt_entry_size
= 16;
3466 ret
->plt_header_size
= 20;
3467 ret
->plt_entry_size
= 12;
3472 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
3473 sizeof (struct elf32_arm_stub_hash_entry
)))
3479 return &ret
->root
.root
;
3482 /* Free the derived linker hash table. */
3485 elf32_arm_hash_table_free (struct bfd_link_hash_table
*hash
)
3487 struct elf32_arm_link_hash_table
*ret
3488 = (struct elf32_arm_link_hash_table
*) hash
;
3490 bfd_hash_table_free (&ret
->stub_hash_table
);
3491 _bfd_elf_link_hash_table_free (hash
);
3494 /* Determine if we're dealing with a Thumb only architecture. */
3497 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
3499 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3503 if (arch
== TAG_CPU_ARCH_V6_M
|| arch
== TAG_CPU_ARCH_V6S_M
)
3506 if (arch
!= TAG_CPU_ARCH_V7
&& arch
!= TAG_CPU_ARCH_V7E_M
)
3509 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3510 Tag_CPU_arch_profile
);
3512 return profile
== 'M';
3515 /* Determine if we're dealing with a Thumb-2 object. */
3518 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
3520 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3522 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
3525 /* Determine what kind of NOPs are available. */
3528 arch_has_arm_nop (struct elf32_arm_link_hash_table
*globals
)
3530 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3532 return arch
== TAG_CPU_ARCH_V6T2
3533 || arch
== TAG_CPU_ARCH_V6K
3534 || arch
== TAG_CPU_ARCH_V7
3535 || arch
== TAG_CPU_ARCH_V7E_M
;
3539 arch_has_thumb2_nop (struct elf32_arm_link_hash_table
*globals
)
3541 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3543 return (arch
== TAG_CPU_ARCH_V6T2
|| arch
== TAG_CPU_ARCH_V7
3544 || arch
== TAG_CPU_ARCH_V7E_M
);
3548 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
3552 case arm_stub_long_branch_thumb_only
:
3553 case arm_stub_long_branch_v4t_thumb_arm
:
3554 case arm_stub_short_branch_v4t_thumb_arm
:
3555 case arm_stub_long_branch_v4t_thumb_arm_pic
:
3556 case arm_stub_long_branch_v4t_thumb_tls_pic
:
3557 case arm_stub_long_branch_thumb_only_pic
:
3568 /* Determine the type of stub needed, if any, for a call. */
3570 static enum elf32_arm_stub_type
3571 arm_type_of_stub (struct bfd_link_info
*info
,
3572 asection
*input_sec
,
3573 const Elf_Internal_Rela
*rel
,
3574 unsigned char st_type
,
3575 enum arm_st_branch_type
*actual_branch_type
,
3576 struct elf32_arm_link_hash_entry
*hash
,
3577 bfd_vma destination
,
3583 bfd_signed_vma branch_offset
;
3584 unsigned int r_type
;
3585 struct elf32_arm_link_hash_table
* globals
;
3588 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
3590 enum arm_st_branch_type branch_type
= *actual_branch_type
;
3591 union gotplt_union
*root_plt
;
3592 struct arm_plt_info
*arm_plt
;
3594 if (branch_type
== ST_BRANCH_LONG
)
3597 globals
= elf32_arm_hash_table (info
);
3598 if (globals
== NULL
)
3601 thumb_only
= using_thumb_only (globals
);
3603 thumb2
= using_thumb2 (globals
);
3605 /* Determine where the call point is. */
3606 location
= (input_sec
->output_offset
3607 + input_sec
->output_section
->vma
3610 r_type
= ELF32_R_TYPE (rel
->r_info
);
3612 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
3613 are considering a function call relocation. */
3614 if (thumb_only
&& (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
3615 && branch_type
== ST_BRANCH_TO_ARM
)
3616 branch_type
= ST_BRANCH_TO_THUMB
;
3618 /* For TLS call relocs, it is the caller's responsibility to provide
3619 the address of the appropriate trampoline. */
3620 if (r_type
!= R_ARM_TLS_CALL
3621 && r_type
!= R_ARM_THM_TLS_CALL
3622 && elf32_arm_get_plt_info (input_bfd
, hash
, ELF32_R_SYM (rel
->r_info
),
3623 &root_plt
, &arm_plt
)
3624 && root_plt
->offset
!= (bfd_vma
) -1)
3628 if (hash
== NULL
|| hash
->is_iplt
)
3629 splt
= globals
->root
.iplt
;
3631 splt
= globals
->root
.splt
;
3636 /* Note when dealing with PLT entries: the main PLT stub is in
3637 ARM mode, so if the branch is in Thumb mode, another
3638 Thumb->ARM stub will be inserted later just before the ARM
3639 PLT stub. We don't take this extra distance into account
3640 here, because if a long branch stub is needed, we'll add a
3641 Thumb->Arm one and branch directly to the ARM PLT entry
3642 because it avoids spreading offset corrections in several
3645 destination
= (splt
->output_section
->vma
3646 + splt
->output_offset
3647 + root_plt
->offset
);
3649 branch_type
= ST_BRANCH_TO_ARM
;
3652 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
3653 BFD_ASSERT (st_type
!= STT_GNU_IFUNC
);
3655 branch_offset
= (bfd_signed_vma
)(destination
- location
);
3657 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
3658 || r_type
== R_ARM_THM_TLS_CALL
)
3660 /* Handle cases where:
3661 - this call goes too far (different Thumb/Thumb2 max
3663 - it's a Thumb->Arm call and blx is not available, or it's a
3664 Thumb->Arm branch (not bl). A stub is needed in this case,
3665 but only if this call is not through a PLT entry. Indeed,
3666 PLT stubs handle mode switching already.
3669 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
3670 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
3672 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
3673 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
3674 || (branch_type
== ST_BRANCH_TO_ARM
3675 && (((r_type
== R_ARM_THM_CALL
3676 || r_type
== R_ARM_THM_TLS_CALL
) && !globals
->use_blx
)
3677 || (r_type
== R_ARM_THM_JUMP24
))
3680 if (branch_type
== ST_BRANCH_TO_THUMB
)
3682 /* Thumb to thumb. */
3685 stub_type
= (info
->shared
| globals
->pic_veneer
)
3687 ? ((globals
->use_blx
3688 && (r_type
== R_ARM_THM_CALL
))
3689 /* V5T and above. Stub starts with ARM code, so
3690 we must be able to switch mode before
3691 reaching it, which is only possible for 'bl'
3692 (ie R_ARM_THM_CALL relocation). */
3693 ? arm_stub_long_branch_any_thumb_pic
3694 /* On V4T, use Thumb code only. */
3695 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
3697 /* non-PIC stubs. */
3698 : ((globals
->use_blx
3699 && (r_type
== R_ARM_THM_CALL
))
3700 /* V5T and above. */
3701 ? arm_stub_long_branch_any_any
3703 : arm_stub_long_branch_v4t_thumb_thumb
);
3707 stub_type
= (info
->shared
| globals
->pic_veneer
)
3709 ? arm_stub_long_branch_thumb_only_pic
3711 : arm_stub_long_branch_thumb_only
;
3718 && sym_sec
->owner
!= NULL
3719 && !INTERWORK_FLAG (sym_sec
->owner
))
3721 (*_bfd_error_handler
)
3722 (_("%B(%s): warning: interworking not enabled.\n"
3723 " first occurrence: %B: Thumb call to ARM"),
3724 sym_sec
->owner
, input_bfd
, name
);
3728 (info
->shared
| globals
->pic_veneer
)
3730 ? (r_type
== R_ARM_THM_TLS_CALL
3732 ? (globals
->use_blx
? arm_stub_long_branch_any_tls_pic
3733 : arm_stub_long_branch_v4t_thumb_tls_pic
)
3734 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3735 /* V5T PIC and above. */
3736 ? arm_stub_long_branch_any_arm_pic
3738 : arm_stub_long_branch_v4t_thumb_arm_pic
))
3740 /* non-PIC stubs. */
3741 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3742 /* V5T and above. */
3743 ? arm_stub_long_branch_any_any
3745 : arm_stub_long_branch_v4t_thumb_arm
);
3747 /* Handle v4t short branches. */
3748 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3749 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3750 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3751 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3755 else if (r_type
== R_ARM_CALL
3756 || r_type
== R_ARM_JUMP24
3757 || r_type
== R_ARM_PLT32
3758 || r_type
== R_ARM_TLS_CALL
)
3760 if (branch_type
== ST_BRANCH_TO_THUMB
)
3765 && sym_sec
->owner
!= NULL
3766 && !INTERWORK_FLAG (sym_sec
->owner
))
3768 (*_bfd_error_handler
)
3769 (_("%B(%s): warning: interworking not enabled.\n"
3770 " first occurrence: %B: ARM call to Thumb"),
3771 sym_sec
->owner
, input_bfd
, name
);
3774 /* We have an extra 2-bytes reach because of
3775 the mode change (bit 24 (H) of BLX encoding). */
3776 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3777 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3778 || (r_type
== R_ARM_CALL
&& !globals
->use_blx
)
3779 || (r_type
== R_ARM_JUMP24
)
3780 || (r_type
== R_ARM_PLT32
))
3782 stub_type
= (info
->shared
| globals
->pic_veneer
)
3784 ? ((globals
->use_blx
)
3785 /* V5T and above. */
3786 ? arm_stub_long_branch_any_thumb_pic
3788 : arm_stub_long_branch_v4t_arm_thumb_pic
)
3790 /* non-PIC stubs. */
3791 : ((globals
->use_blx
)
3792 /* V5T and above. */
3793 ? arm_stub_long_branch_any_any
3795 : arm_stub_long_branch_v4t_arm_thumb
);
3801 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3802 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3805 (info
->shared
| globals
->pic_veneer
)
3807 ? (r_type
== R_ARM_TLS_CALL
3809 ? arm_stub_long_branch_any_tls_pic
3811 ? arm_stub_long_branch_arm_nacl_pic
3812 : arm_stub_long_branch_any_arm_pic
))
3813 /* non-PIC stubs. */
3815 ? arm_stub_long_branch_arm_nacl
3816 : arm_stub_long_branch_any_any
);
3821 /* If a stub is needed, record the actual destination type. */
3822 if (stub_type
!= arm_stub_none
)
3823 *actual_branch_type
= branch_type
;
3828 /* Build a name for an entry in the stub hash table. */
3831 elf32_arm_stub_name (const asection
*input_section
,
3832 const asection
*sym_sec
,
3833 const struct elf32_arm_link_hash_entry
*hash
,
3834 const Elf_Internal_Rela
*rel
,
3835 enum elf32_arm_stub_type stub_type
)
3842 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1 + 2 + 1;
3843 stub_name
= (char *) bfd_malloc (len
);
3844 if (stub_name
!= NULL
)
3845 sprintf (stub_name
, "%08x_%s+%x_%d",
3846 input_section
->id
& 0xffffffff,
3847 hash
->root
.root
.root
.string
,
3848 (int) rel
->r_addend
& 0xffffffff,
3853 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
3854 stub_name
= (char *) bfd_malloc (len
);
3855 if (stub_name
!= NULL
)
3856 sprintf (stub_name
, "%08x_%x:%x+%x_%d",
3857 input_section
->id
& 0xffffffff,
3858 sym_sec
->id
& 0xffffffff,
3859 ELF32_R_TYPE (rel
->r_info
) == R_ARM_TLS_CALL
3860 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_TLS_CALL
3861 ? 0 : (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
3862 (int) rel
->r_addend
& 0xffffffff,
3869 /* Look up an entry in the stub hash. Stub entries are cached because
3870 creating the stub name takes a bit of time. */
3872 static struct elf32_arm_stub_hash_entry
*
3873 elf32_arm_get_stub_entry (const asection
*input_section
,
3874 const asection
*sym_sec
,
3875 struct elf_link_hash_entry
*hash
,
3876 const Elf_Internal_Rela
*rel
,
3877 struct elf32_arm_link_hash_table
*htab
,
3878 enum elf32_arm_stub_type stub_type
)
3880 struct elf32_arm_stub_hash_entry
*stub_entry
;
3881 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
3882 const asection
*id_sec
;
3884 if ((input_section
->flags
& SEC_CODE
) == 0)
3887 /* If this input section is part of a group of sections sharing one
3888 stub section, then use the id of the first section in the group.
3889 Stub names need to include a section id, as there may well be
3890 more than one stub used to reach say, printf, and we need to
3891 distinguish between them. */
3892 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3894 if (h
!= NULL
&& h
->stub_cache
!= NULL
3895 && h
->stub_cache
->h
== h
3896 && h
->stub_cache
->id_sec
== id_sec
3897 && h
->stub_cache
->stub_type
== stub_type
)
3899 stub_entry
= h
->stub_cache
;
3905 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
, stub_type
);
3906 if (stub_name
== NULL
)
3909 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3910 stub_name
, FALSE
, FALSE
);
3912 h
->stub_cache
= stub_entry
;
3920 /* Find or create a stub section. Returns a pointer to the stub section, and
3921 the section to which the stub section will be attached (in *LINK_SEC_P).
3922 LINK_SEC_P may be NULL. */
3925 elf32_arm_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
3926 struct elf32_arm_link_hash_table
*htab
)
3931 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3932 BFD_ASSERT (link_sec
!= NULL
);
3933 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3935 if (stub_sec
== NULL
)
3937 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3938 if (stub_sec
== NULL
)
3944 namelen
= strlen (link_sec
->name
);
3945 len
= namelen
+ sizeof (STUB_SUFFIX
);
3946 s_name
= (char *) bfd_alloc (htab
->stub_bfd
, len
);
3950 memcpy (s_name
, link_sec
->name
, namelen
);
3951 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3952 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
,
3953 htab
->nacl_p
? 4 : 3);
3954 if (stub_sec
== NULL
)
3956 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3958 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3962 *link_sec_p
= link_sec
;
3967 /* Add a new stub entry to the stub hash. Not all fields of the new
3968 stub entry are initialised. */
3970 static struct elf32_arm_stub_hash_entry
*
3971 elf32_arm_add_stub (const char *stub_name
,
3973 struct elf32_arm_link_hash_table
*htab
)
3977 struct elf32_arm_stub_hash_entry
*stub_entry
;
3979 stub_sec
= elf32_arm_create_or_find_stub_sec (&link_sec
, section
, htab
);
3980 if (stub_sec
== NULL
)
3983 /* Enter this entry into the linker stub hash table. */
3984 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3986 if (stub_entry
== NULL
)
3988 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3994 stub_entry
->stub_sec
= stub_sec
;
3995 stub_entry
->stub_offset
= 0;
3996 stub_entry
->id_sec
= link_sec
;
4001 /* Store an Arm insn into an output section not processed by
4002 elf32_arm_write_section. */
4005 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
4006 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4008 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4009 bfd_putl32 (val
, ptr
);
4011 bfd_putb32 (val
, ptr
);
4014 /* Store a 16-bit Thumb insn into an output section not processed by
4015 elf32_arm_write_section. */
4018 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
4019 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4021 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4022 bfd_putl16 (val
, ptr
);
4024 bfd_putb16 (val
, ptr
);
4027 /* If it's possible to change R_TYPE to a more efficient access
4028 model, return the new reloc type. */
4031 elf32_arm_tls_transition (struct bfd_link_info
*info
, int r_type
,
4032 struct elf_link_hash_entry
*h
)
4034 int is_local
= (h
== NULL
);
4036 if (info
->shared
|| (h
&& h
->root
.type
== bfd_link_hash_undefweak
))
4039 /* We do not support relaxations for Old TLS models. */
4042 case R_ARM_TLS_GOTDESC
:
4043 case R_ARM_TLS_CALL
:
4044 case R_ARM_THM_TLS_CALL
:
4045 case R_ARM_TLS_DESCSEQ
:
4046 case R_ARM_THM_TLS_DESCSEQ
:
4047 return is_local
? R_ARM_TLS_LE32
: R_ARM_TLS_IE32
;
4053 static bfd_reloc_status_type elf32_arm_final_link_relocate
4054 (reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
4055 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
4056 const char *, unsigned char, enum arm_st_branch_type
,
4057 struct elf_link_hash_entry
*, bfd_boolean
*, char **);
4060 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type
)
4064 case arm_stub_a8_veneer_b_cond
:
4065 case arm_stub_a8_veneer_b
:
4066 case arm_stub_a8_veneer_bl
:
4069 case arm_stub_long_branch_any_any
:
4070 case arm_stub_long_branch_v4t_arm_thumb
:
4071 case arm_stub_long_branch_thumb_only
:
4072 case arm_stub_long_branch_v4t_thumb_thumb
:
4073 case arm_stub_long_branch_v4t_thumb_arm
:
4074 case arm_stub_short_branch_v4t_thumb_arm
:
4075 case arm_stub_long_branch_any_arm_pic
:
4076 case arm_stub_long_branch_any_thumb_pic
:
4077 case arm_stub_long_branch_v4t_thumb_thumb_pic
:
4078 case arm_stub_long_branch_v4t_arm_thumb_pic
:
4079 case arm_stub_long_branch_v4t_thumb_arm_pic
:
4080 case arm_stub_long_branch_thumb_only_pic
:
4081 case arm_stub_long_branch_any_tls_pic
:
4082 case arm_stub_long_branch_v4t_thumb_tls_pic
:
4083 case arm_stub_a8_veneer_blx
:
4086 case arm_stub_long_branch_arm_nacl
:
4087 case arm_stub_long_branch_arm_nacl_pic
:
4091 abort (); /* Should be unreachable. */
4096 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
4100 struct elf32_arm_stub_hash_entry
*stub_entry
;
4101 struct elf32_arm_link_hash_table
*globals
;
4102 struct bfd_link_info
*info
;
4109 const insn_sequence
*template_sequence
;
4111 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
4112 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
4115 /* Massage our args to the form they really have. */
4116 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4117 info
= (struct bfd_link_info
*) in_arg
;
4119 globals
= elf32_arm_hash_table (info
);
4120 if (globals
== NULL
)
4123 stub_sec
= stub_entry
->stub_sec
;
4125 if ((globals
->fix_cortex_a8
< 0)
4126 != (arm_stub_required_alignment (stub_entry
->stub_type
) == 2))
4127 /* We have to do less-strictly-aligned fixes last. */
4130 /* Make a note of the offset within the stubs for this entry. */
4131 stub_entry
->stub_offset
= stub_sec
->size
;
4132 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4134 stub_bfd
= stub_sec
->owner
;
4136 /* This is the address of the stub destination. */
4137 sym_value
= (stub_entry
->target_value
4138 + stub_entry
->target_section
->output_offset
4139 + stub_entry
->target_section
->output_section
->vma
);
4141 template_sequence
= stub_entry
->stub_template
;
4142 template_size
= stub_entry
->stub_template_size
;
4145 for (i
= 0; i
< template_size
; i
++)
4147 switch (template_sequence
[i
].type
)
4151 bfd_vma data
= (bfd_vma
) template_sequence
[i
].data
;
4152 if (template_sequence
[i
].reloc_addend
!= 0)
4154 /* We've borrowed the reloc_addend field to mean we should
4155 insert a condition code into this (Thumb-1 branch)
4156 instruction. See THUMB16_BCOND_INSN. */
4157 BFD_ASSERT ((data
& 0xff00) == 0xd000);
4158 data
|= ((stub_entry
->orig_insn
>> 22) & 0xf) << 8;
4160 bfd_put_16 (stub_bfd
, data
, loc
+ size
);
4166 bfd_put_16 (stub_bfd
,
4167 (template_sequence
[i
].data
>> 16) & 0xffff,
4169 bfd_put_16 (stub_bfd
, template_sequence
[i
].data
& 0xffff,
4171 if (template_sequence
[i
].r_type
!= R_ARM_NONE
)
4173 stub_reloc_idx
[nrelocs
] = i
;
4174 stub_reloc_offset
[nrelocs
++] = size
;
4180 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
,
4182 /* Handle cases where the target is encoded within the
4184 if (template_sequence
[i
].r_type
== R_ARM_JUMP24
)
4186 stub_reloc_idx
[nrelocs
] = i
;
4187 stub_reloc_offset
[nrelocs
++] = size
;
4193 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
, loc
+ size
);
4194 stub_reloc_idx
[nrelocs
] = i
;
4195 stub_reloc_offset
[nrelocs
++] = size
;
4205 stub_sec
->size
+= size
;
4207 /* Stub size has already been computed in arm_size_one_stub. Check
4209 BFD_ASSERT (size
== stub_entry
->stub_size
);
4211 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
4212 if (stub_entry
->branch_type
== ST_BRANCH_TO_THUMB
)
4215 /* Assume there is at least one and at most MAXRELOCS entries to relocate
4217 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
4219 for (i
= 0; i
< nrelocs
; i
++)
4220 if (template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP24
4221 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP19
4222 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_CALL
4223 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_XPC22
)
4225 Elf_Internal_Rela rel
;
4226 bfd_boolean unresolved_reloc
;
4227 char *error_message
;
4228 enum arm_st_branch_type branch_type
4229 = (template_sequence
[stub_reloc_idx
[i
]].r_type
!= R_ARM_THM_XPC22
4230 ? ST_BRANCH_TO_THUMB
: ST_BRANCH_TO_ARM
);
4231 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
;
4233 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4234 rel
.r_info
= ELF32_R_INFO (0,
4235 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4236 rel
.r_addend
= template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4238 if (stub_entry
->stub_type
== arm_stub_a8_veneer_b_cond
&& i
== 0)
4239 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
4240 template should refer back to the instruction after the original
4242 points_to
= sym_value
;
4244 /* There may be unintended consequences if this is not true. */
4245 BFD_ASSERT (stub_entry
->h
== NULL
);
4247 /* Note: _bfd_final_link_relocate doesn't handle these relocations
4248 properly. We should probably use this function unconditionally,
4249 rather than only for certain relocations listed in the enclosing
4250 conditional, for the sake of consistency. */
4251 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4252 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4253 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4254 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4255 branch_type
, (struct elf_link_hash_entry
*) stub_entry
->h
,
4256 &unresolved_reloc
, &error_message
);
4260 Elf_Internal_Rela rel
;
4261 bfd_boolean unresolved_reloc
;
4262 char *error_message
;
4263 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
4264 + template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4266 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4267 rel
.r_info
= ELF32_R_INFO (0,
4268 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4271 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4272 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4273 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4274 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4275 stub_entry
->branch_type
,
4276 (struct elf_link_hash_entry
*) stub_entry
->h
, &unresolved_reloc
,
4284 /* Calculate the template, template size and instruction size for a stub.
4285 Return value is the instruction size. */
4288 find_stub_size_and_template (enum elf32_arm_stub_type stub_type
,
4289 const insn_sequence
**stub_template
,
4290 int *stub_template_size
)
4292 const insn_sequence
*template_sequence
= NULL
;
4293 int template_size
= 0, i
;
4296 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
4298 *stub_template
= template_sequence
;
4300 template_size
= stub_definitions
[stub_type
].template_size
;
4301 if (stub_template_size
)
4302 *stub_template_size
= template_size
;
4305 for (i
= 0; i
< template_size
; i
++)
4307 switch (template_sequence
[i
].type
)
4328 /* As above, but don't actually build the stub. Just bump offset so
4329 we know stub section sizes. */
4332 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
4333 void *in_arg ATTRIBUTE_UNUSED
)
4335 struct elf32_arm_stub_hash_entry
*stub_entry
;
4336 const insn_sequence
*template_sequence
;
4337 int template_size
, size
;
4339 /* Massage our args to the form they really have. */
4340 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4342 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
4343 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
4345 size
= find_stub_size_and_template (stub_entry
->stub_type
, &template_sequence
,
4348 stub_entry
->stub_size
= size
;
4349 stub_entry
->stub_template
= template_sequence
;
4350 stub_entry
->stub_template_size
= template_size
;
4352 size
= (size
+ 7) & ~7;
4353 stub_entry
->stub_sec
->size
+= size
;
4358 /* External entry points for sizing and building linker stubs. */
4360 /* Set up various things so that we can make a list of input sections
4361 for each output section included in the link. Returns -1 on error,
4362 0 when no stubs will be needed, and 1 on success. */
4365 elf32_arm_setup_section_lists (bfd
*output_bfd
,
4366 struct bfd_link_info
*info
)
4369 unsigned int bfd_count
;
4370 int top_id
, top_index
;
4372 asection
**input_list
, **list
;
4374 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4378 if (! is_elf_hash_table (htab
))
4381 /* Count the number of input BFDs and find the top input section id. */
4382 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
4384 input_bfd
= input_bfd
->link_next
)
4387 for (section
= input_bfd
->sections
;
4389 section
= section
->next
)
4391 if (top_id
< section
->id
)
4392 top_id
= section
->id
;
4395 htab
->bfd_count
= bfd_count
;
4397 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4398 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4399 if (htab
->stub_group
== NULL
)
4401 htab
->top_id
= top_id
;
4403 /* We can't use output_bfd->section_count here to find the top output
4404 section index as some sections may have been removed, and
4405 _bfd_strip_section_from_output doesn't renumber the indices. */
4406 for (section
= output_bfd
->sections
, top_index
= 0;
4408 section
= section
->next
)
4410 if (top_index
< section
->index
)
4411 top_index
= section
->index
;
4414 htab
->top_index
= top_index
;
4415 amt
= sizeof (asection
*) * (top_index
+ 1);
4416 input_list
= (asection
**) bfd_malloc (amt
);
4417 htab
->input_list
= input_list
;
4418 if (input_list
== NULL
)
4421 /* For sections we aren't interested in, mark their entries with a
4422 value we can check later. */
4423 list
= input_list
+ top_index
;
4425 *list
= bfd_abs_section_ptr
;
4426 while (list
-- != input_list
);
4428 for (section
= output_bfd
->sections
;
4430 section
= section
->next
)
4432 if ((section
->flags
& SEC_CODE
) != 0)
4433 input_list
[section
->index
] = NULL
;
4439 /* The linker repeatedly calls this function for each input section,
4440 in the order that input sections are linked into output sections.
4441 Build lists of input sections to determine groupings between which
4442 we may insert linker stubs. */
4445 elf32_arm_next_input_section (struct bfd_link_info
*info
,
4448 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4453 if (isec
->output_section
->index
<= htab
->top_index
)
4455 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4457 if (*list
!= bfd_abs_section_ptr
&& (isec
->flags
& SEC_CODE
) != 0)
4459 /* Steal the link_sec pointer for our list. */
4460 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4461 /* This happens to make the list in reverse order,
4462 which we reverse later. */
4463 PREV_SEC (isec
) = *list
;
4469 /* See whether we can group stub sections together. Grouping stub
4470 sections may result in fewer stubs. More importantly, we need to
4471 put all .init* and .fini* stubs at the end of the .init or
4472 .fini output sections respectively, because glibc splits the
4473 _init and _fini functions into multiple parts. Putting a stub in
4474 the middle of a function is not a good idea. */
4477 group_sections (struct elf32_arm_link_hash_table
*htab
,
4478 bfd_size_type stub_group_size
,
4479 bfd_boolean stubs_always_after_branch
)
4481 asection
**list
= htab
->input_list
;
4485 asection
*tail
= *list
;
4488 if (tail
== bfd_abs_section_ptr
)
4491 /* Reverse the list: we must avoid placing stubs at the
4492 beginning of the section because the beginning of the text
4493 section may be required for an interrupt vector in bare metal
4495 #define NEXT_SEC PREV_SEC
4497 while (tail
!= NULL
)
4499 /* Pop from tail. */
4500 asection
*item
= tail
;
4501 tail
= PREV_SEC (item
);
4504 NEXT_SEC (item
) = head
;
4508 while (head
!= NULL
)
4512 bfd_vma stub_group_start
= head
->output_offset
;
4513 bfd_vma end_of_next
;
4516 while (NEXT_SEC (curr
) != NULL
)
4518 next
= NEXT_SEC (curr
);
4519 end_of_next
= next
->output_offset
+ next
->size
;
4520 if (end_of_next
- stub_group_start
>= stub_group_size
)
4521 /* End of NEXT is too far from start, so stop. */
4523 /* Add NEXT to the group. */
4527 /* OK, the size from the start to the start of CURR is less
4528 than stub_group_size and thus can be handled by one stub
4529 section. (Or the head section is itself larger than
4530 stub_group_size, in which case we may be toast.)
4531 We should really be keeping track of the total size of
4532 stubs added here, as stubs contribute to the final output
4536 next
= NEXT_SEC (head
);
4537 /* Set up this stub group. */
4538 htab
->stub_group
[head
->id
].link_sec
= curr
;
4540 while (head
!= curr
&& (head
= next
) != NULL
);
4542 /* But wait, there's more! Input sections up to stub_group_size
4543 bytes after the stub section can be handled by it too. */
4544 if (!stubs_always_after_branch
)
4546 stub_group_start
= curr
->output_offset
+ curr
->size
;
4548 while (next
!= NULL
)
4550 end_of_next
= next
->output_offset
+ next
->size
;
4551 if (end_of_next
- stub_group_start
>= stub_group_size
)
4552 /* End of NEXT is too far from stubs, so stop. */
4554 /* Add NEXT to the stub group. */
4556 next
= NEXT_SEC (head
);
4557 htab
->stub_group
[head
->id
].link_sec
= curr
;
4563 while (list
++ != htab
->input_list
+ htab
->top_index
);
4565 free (htab
->input_list
);
4570 /* Comparison function for sorting/searching relocations relating to Cortex-A8
4574 a8_reloc_compare (const void *a
, const void *b
)
4576 const struct a8_erratum_reloc
*ra
= (const struct a8_erratum_reloc
*) a
;
4577 const struct a8_erratum_reloc
*rb
= (const struct a8_erratum_reloc
*) b
;
4579 if (ra
->from
< rb
->from
)
4581 else if (ra
->from
> rb
->from
)
4587 static struct elf_link_hash_entry
*find_thumb_glue (struct bfd_link_info
*,
4588 const char *, char **);
4590 /* Helper function to scan code for sequences which might trigger the Cortex-A8
4591 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
4592 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
4596 cortex_a8_erratum_scan (bfd
*input_bfd
,
4597 struct bfd_link_info
*info
,
4598 struct a8_erratum_fix
**a8_fixes_p
,
4599 unsigned int *num_a8_fixes_p
,
4600 unsigned int *a8_fix_table_size_p
,
4601 struct a8_erratum_reloc
*a8_relocs
,
4602 unsigned int num_a8_relocs
,
4603 unsigned prev_num_a8_fixes
,
4604 bfd_boolean
*stub_changed_p
)
4607 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4608 struct a8_erratum_fix
*a8_fixes
= *a8_fixes_p
;
4609 unsigned int num_a8_fixes
= *num_a8_fixes_p
;
4610 unsigned int a8_fix_table_size
= *a8_fix_table_size_p
;
4615 for (section
= input_bfd
->sections
;
4617 section
= section
->next
)
4619 bfd_byte
*contents
= NULL
;
4620 struct _arm_elf_section_data
*sec_data
;
4624 if (elf_section_type (section
) != SHT_PROGBITS
4625 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4626 || (section
->flags
& SEC_EXCLUDE
) != 0
4627 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4628 || (section
->output_section
== bfd_abs_section_ptr
))
4631 base_vma
= section
->output_section
->vma
+ section
->output_offset
;
4633 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4634 contents
= elf_section_data (section
)->this_hdr
.contents
;
4635 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4638 sec_data
= elf32_arm_section_data (section
);
4640 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4642 unsigned int span_start
= sec_data
->map
[span
].vma
;
4643 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
4644 ? section
->size
: sec_data
->map
[span
+ 1].vma
;
4646 char span_type
= sec_data
->map
[span
].type
;
4647 bfd_boolean last_was_32bit
= FALSE
, last_was_branch
= FALSE
;
4649 if (span_type
!= 't')
4652 /* Span is entirely within a single 4KB region: skip scanning. */
4653 if (((base_vma
+ span_start
) & ~0xfff)
4654 == ((base_vma
+ span_end
) & ~0xfff))
4657 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
4659 * The opcode is BLX.W, BL.W, B.W, Bcc.W
4660 * The branch target is in the same 4KB region as the
4661 first half of the branch.
4662 * The instruction before the branch is a 32-bit
4663 length non-branch instruction. */
4664 for (i
= span_start
; i
< span_end
;)
4666 unsigned int insn
= bfd_getl16 (&contents
[i
]);
4667 bfd_boolean insn_32bit
= FALSE
, is_blx
= FALSE
, is_b
= FALSE
;
4668 bfd_boolean is_bl
= FALSE
, is_bcc
= FALSE
, is_32bit_branch
;
4670 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
4675 /* Load the rest of the insn (in manual-friendly order). */
4676 insn
= (insn
<< 16) | bfd_getl16 (&contents
[i
+ 2]);
4678 /* Encoding T4: B<c>.W. */
4679 is_b
= (insn
& 0xf800d000) == 0xf0009000;
4680 /* Encoding T1: BL<c>.W. */
4681 is_bl
= (insn
& 0xf800d000) == 0xf000d000;
4682 /* Encoding T2: BLX<c>.W. */
4683 is_blx
= (insn
& 0xf800d000) == 0xf000c000;
4684 /* Encoding T3: B<c>.W (not permitted in IT block). */
4685 is_bcc
= (insn
& 0xf800d000) == 0xf0008000
4686 && (insn
& 0x07f00000) != 0x03800000;
4689 is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
4691 if (((base_vma
+ i
) & 0xfff) == 0xffe
4695 && ! last_was_branch
)
4697 bfd_signed_vma offset
= 0;
4698 bfd_boolean force_target_arm
= FALSE
;
4699 bfd_boolean force_target_thumb
= FALSE
;
4701 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
4702 struct a8_erratum_reloc key
, *found
;
4703 bfd_boolean use_plt
= FALSE
;
4705 key
.from
= base_vma
+ i
;
4706 found
= (struct a8_erratum_reloc
*)
4707 bsearch (&key
, a8_relocs
, num_a8_relocs
,
4708 sizeof (struct a8_erratum_reloc
),
4713 char *error_message
= NULL
;
4714 struct elf_link_hash_entry
*entry
;
4716 /* We don't care about the error returned from this
4717 function, only if there is glue or not. */
4718 entry
= find_thumb_glue (info
, found
->sym_name
,
4722 found
->non_a8_stub
= TRUE
;
4724 /* Keep a simpler condition, for the sake of clarity. */
4725 if (htab
->root
.splt
!= NULL
&& found
->hash
!= NULL
4726 && found
->hash
->root
.plt
.offset
!= (bfd_vma
) -1)
4729 if (found
->r_type
== R_ARM_THM_CALL
)
4731 if (found
->branch_type
== ST_BRANCH_TO_ARM
4733 force_target_arm
= TRUE
;
4735 force_target_thumb
= TRUE
;
4739 /* Check if we have an offending branch instruction. */
4741 if (found
&& found
->non_a8_stub
)
4742 /* We've already made a stub for this instruction, e.g.
4743 it's a long branch or a Thumb->ARM stub. Assume that
4744 stub will suffice to work around the A8 erratum (see
4745 setting of always_after_branch above). */
4749 offset
= (insn
& 0x7ff) << 1;
4750 offset
|= (insn
& 0x3f0000) >> 4;
4751 offset
|= (insn
& 0x2000) ? 0x40000 : 0;
4752 offset
|= (insn
& 0x800) ? 0x80000 : 0;
4753 offset
|= (insn
& 0x4000000) ? 0x100000 : 0;
4754 if (offset
& 0x100000)
4755 offset
|= ~ ((bfd_signed_vma
) 0xfffff);
4756 stub_type
= arm_stub_a8_veneer_b_cond
;
4758 else if (is_b
|| is_bl
|| is_blx
)
4760 int s
= (insn
& 0x4000000) != 0;
4761 int j1
= (insn
& 0x2000) != 0;
4762 int j2
= (insn
& 0x800) != 0;
4766 offset
= (insn
& 0x7ff) << 1;
4767 offset
|= (insn
& 0x3ff0000) >> 4;
4771 if (offset
& 0x1000000)
4772 offset
|= ~ ((bfd_signed_vma
) 0xffffff);
4775 offset
&= ~ ((bfd_signed_vma
) 3);
4777 stub_type
= is_blx
? arm_stub_a8_veneer_blx
:
4778 is_bl
? arm_stub_a8_veneer_bl
: arm_stub_a8_veneer_b
;
4781 if (stub_type
!= arm_stub_none
)
4783 bfd_vma pc_for_insn
= base_vma
+ i
+ 4;
4785 /* The original instruction is a BL, but the target is
4786 an ARM instruction. If we were not making a stub,
4787 the BL would have been converted to a BLX. Use the
4788 BLX stub instead in that case. */
4789 if (htab
->use_blx
&& force_target_arm
4790 && stub_type
== arm_stub_a8_veneer_bl
)
4792 stub_type
= arm_stub_a8_veneer_blx
;
4796 /* Conversely, if the original instruction was
4797 BLX but the target is Thumb mode, use the BL
4799 else if (force_target_thumb
4800 && stub_type
== arm_stub_a8_veneer_blx
)
4802 stub_type
= arm_stub_a8_veneer_bl
;
4808 pc_for_insn
&= ~ ((bfd_vma
) 3);
4810 /* If we found a relocation, use the proper destination,
4811 not the offset in the (unrelocated) instruction.
4812 Note this is always done if we switched the stub type
4816 (bfd_signed_vma
) (found
->destination
- pc_for_insn
);
4818 /* If the stub will use a Thumb-mode branch to a
4819 PLT target, redirect it to the preceding Thumb
4821 if (stub_type
!= arm_stub_a8_veneer_blx
&& use_plt
)
4822 offset
-= PLT_THUMB_STUB_SIZE
;
4824 target
= pc_for_insn
+ offset
;
4826 /* The BLX stub is ARM-mode code. Adjust the offset to
4827 take the different PC value (+8 instead of +4) into
4829 if (stub_type
== arm_stub_a8_veneer_blx
)
4832 if (((base_vma
+ i
) & ~0xfff) == (target
& ~0xfff))
4834 char *stub_name
= NULL
;
4836 if (num_a8_fixes
== a8_fix_table_size
)
4838 a8_fix_table_size
*= 2;
4839 a8_fixes
= (struct a8_erratum_fix
*)
4840 bfd_realloc (a8_fixes
,
4841 sizeof (struct a8_erratum_fix
)
4842 * a8_fix_table_size
);
4845 if (num_a8_fixes
< prev_num_a8_fixes
)
4847 /* If we're doing a subsequent scan,
4848 check if we've found the same fix as
4849 before, and try and reuse the stub
4851 stub_name
= a8_fixes
[num_a8_fixes
].stub_name
;
4852 if ((a8_fixes
[num_a8_fixes
].section
!= section
)
4853 || (a8_fixes
[num_a8_fixes
].offset
!= i
))
4857 *stub_changed_p
= TRUE
;
4863 stub_name
= (char *) bfd_malloc (8 + 1 + 8 + 1);
4864 if (stub_name
!= NULL
)
4865 sprintf (stub_name
, "%x:%x", section
->id
, i
);
4868 a8_fixes
[num_a8_fixes
].input_bfd
= input_bfd
;
4869 a8_fixes
[num_a8_fixes
].section
= section
;
4870 a8_fixes
[num_a8_fixes
].offset
= i
;
4871 a8_fixes
[num_a8_fixes
].addend
= offset
;
4872 a8_fixes
[num_a8_fixes
].orig_insn
= insn
;
4873 a8_fixes
[num_a8_fixes
].stub_name
= stub_name
;
4874 a8_fixes
[num_a8_fixes
].stub_type
= stub_type
;
4875 a8_fixes
[num_a8_fixes
].branch_type
=
4876 is_blx
? ST_BRANCH_TO_ARM
: ST_BRANCH_TO_THUMB
;
4883 i
+= insn_32bit
? 4 : 2;
4884 last_was_32bit
= insn_32bit
;
4885 last_was_branch
= is_32bit_branch
;
4889 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4893 *a8_fixes_p
= a8_fixes
;
4894 *num_a8_fixes_p
= num_a8_fixes
;
4895 *a8_fix_table_size_p
= a8_fix_table_size
;
4900 /* Determine and set the size of the stub section for a final link.
4902 The basic idea here is to examine all the relocations looking for
4903 PC-relative calls to a target that is unreachable with a "bl"
4907 elf32_arm_size_stubs (bfd
*output_bfd
,
4909 struct bfd_link_info
*info
,
4910 bfd_signed_vma group_size
,
4911 asection
* (*add_stub_section
) (const char *, asection
*,
4913 void (*layout_sections_again
) (void))
4915 bfd_size_type stub_group_size
;
4916 bfd_boolean stubs_always_after_branch
;
4917 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4918 struct a8_erratum_fix
*a8_fixes
= NULL
;
4919 unsigned int num_a8_fixes
= 0, a8_fix_table_size
= 10;
4920 struct a8_erratum_reloc
*a8_relocs
= NULL
;
4921 unsigned int num_a8_relocs
= 0, a8_reloc_table_size
= 10, i
;
4926 if (htab
->fix_cortex_a8
)
4928 a8_fixes
= (struct a8_erratum_fix
*)
4929 bfd_zmalloc (sizeof (struct a8_erratum_fix
) * a8_fix_table_size
);
4930 a8_relocs
= (struct a8_erratum_reloc
*)
4931 bfd_zmalloc (sizeof (struct a8_erratum_reloc
) * a8_reloc_table_size
);
4934 /* Propagate mach to stub bfd, because it may not have been
4935 finalized when we created stub_bfd. */
4936 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4937 bfd_get_mach (output_bfd
));
4939 /* Stash our params away. */
4940 htab
->stub_bfd
= stub_bfd
;
4941 htab
->add_stub_section
= add_stub_section
;
4942 htab
->layout_sections_again
= layout_sections_again
;
4943 stubs_always_after_branch
= group_size
< 0;
4945 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
4946 as the first half of a 32-bit branch straddling two 4K pages. This is a
4947 crude way of enforcing that. */
4948 if (htab
->fix_cortex_a8
)
4949 stubs_always_after_branch
= 1;
4952 stub_group_size
= -group_size
;
4954 stub_group_size
= group_size
;
4956 if (stub_group_size
== 1)
4958 /* Default values. */
4959 /* Thumb branch range is +-4MB has to be used as the default
4960 maximum size (a given section can contain both ARM and Thumb
4961 code, so the worst case has to be taken into account).
4963 This value is 24K less than that, which allows for 2025
4964 12-byte stubs. If we exceed that, then we will fail to link.
4965 The user will have to relink with an explicit group size
4967 stub_group_size
= 4170000;
4970 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
4972 /* If we're applying the cortex A8 fix, we need to determine the
4973 program header size now, because we cannot change it later --
4974 that could alter section placements. Notice the A8 erratum fix
4975 ends up requiring the section addresses to remain unchanged
4976 modulo the page size. That's something we cannot represent
4977 inside BFD, and we don't want to force the section alignment to
4978 be the page size. */
4979 if (htab
->fix_cortex_a8
)
4980 (*htab
->layout_sections_again
) ();
4985 unsigned int bfd_indx
;
4987 bfd_boolean stub_changed
= FALSE
;
4988 unsigned prev_num_a8_fixes
= num_a8_fixes
;
4991 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4993 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4995 Elf_Internal_Shdr
*symtab_hdr
;
4997 Elf_Internal_Sym
*local_syms
= NULL
;
4999 if (!is_arm_elf (input_bfd
))
5004 /* We'll need the symbol table in a second. */
5005 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5006 if (symtab_hdr
->sh_info
== 0)
5009 /* Walk over each section attached to the input bfd. */
5010 for (section
= input_bfd
->sections
;
5012 section
= section
->next
)
5014 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
5016 /* If there aren't any relocs, then there's nothing more
5018 if ((section
->flags
& SEC_RELOC
) == 0
5019 || section
->reloc_count
== 0
5020 || (section
->flags
& SEC_CODE
) == 0)
5023 /* If this section is a link-once section that will be
5024 discarded, then don't create any stubs. */
5025 if (section
->output_section
== NULL
5026 || section
->output_section
->owner
!= output_bfd
)
5029 /* Get the relocs. */
5031 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
5032 NULL
, info
->keep_memory
);
5033 if (internal_relocs
== NULL
)
5034 goto error_ret_free_local
;
5036 /* Now examine each relocation. */
5037 irela
= internal_relocs
;
5038 irelaend
= irela
+ section
->reloc_count
;
5039 for (; irela
< irelaend
; irela
++)
5041 unsigned int r_type
, r_indx
;
5042 enum elf32_arm_stub_type stub_type
;
5043 struct elf32_arm_stub_hash_entry
*stub_entry
;
5046 bfd_vma destination
;
5047 struct elf32_arm_link_hash_entry
*hash
;
5048 const char *sym_name
;
5050 const asection
*id_sec
;
5051 unsigned char st_type
;
5052 enum arm_st_branch_type branch_type
;
5053 bfd_boolean created_stub
= FALSE
;
5055 r_type
= ELF32_R_TYPE (irela
->r_info
);
5056 r_indx
= ELF32_R_SYM (irela
->r_info
);
5058 if (r_type
>= (unsigned int) R_ARM_max
)
5060 bfd_set_error (bfd_error_bad_value
);
5061 error_ret_free_internal
:
5062 if (elf_section_data (section
)->relocs
== NULL
)
5063 free (internal_relocs
);
5064 goto error_ret_free_local
;
5068 if (r_indx
>= symtab_hdr
->sh_info
)
5069 hash
= elf32_arm_hash_entry
5070 (elf_sym_hashes (input_bfd
)
5071 [r_indx
- symtab_hdr
->sh_info
]);
5073 /* Only look for stubs on branch instructions, or
5074 non-relaxed TLSCALL */
5075 if ((r_type
!= (unsigned int) R_ARM_CALL
)
5076 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
5077 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
5078 && (r_type
!= (unsigned int) R_ARM_THM_JUMP19
)
5079 && (r_type
!= (unsigned int) R_ARM_THM_XPC22
)
5080 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
5081 && (r_type
!= (unsigned int) R_ARM_PLT32
)
5082 && !((r_type
== (unsigned int) R_ARM_TLS_CALL
5083 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
5084 && r_type
== elf32_arm_tls_transition
5085 (info
, r_type
, &hash
->root
)
5086 && ((hash
? hash
->tls_type
5087 : (elf32_arm_local_got_tls_type
5088 (input_bfd
)[r_indx
]))
5089 & GOT_TLS_GDESC
) != 0))
5092 /* Now determine the call target, its name, value,
5099 if (r_type
== (unsigned int) R_ARM_TLS_CALL
5100 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
5102 /* A non-relaxed TLS call. The target is the
5103 plt-resident trampoline and nothing to do
5105 BFD_ASSERT (htab
->tls_trampoline
> 0);
5106 sym_sec
= htab
->root
.splt
;
5107 sym_value
= htab
->tls_trampoline
;
5110 branch_type
= ST_BRANCH_TO_ARM
;
5114 /* It's a local symbol. */
5115 Elf_Internal_Sym
*sym
;
5117 if (local_syms
== NULL
)
5120 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5121 if (local_syms
== NULL
)
5123 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5124 symtab_hdr
->sh_info
, 0,
5126 if (local_syms
== NULL
)
5127 goto error_ret_free_internal
;
5130 sym
= local_syms
+ r_indx
;
5131 if (sym
->st_shndx
== SHN_UNDEF
)
5132 sym_sec
= bfd_und_section_ptr
;
5133 else if (sym
->st_shndx
== SHN_ABS
)
5134 sym_sec
= bfd_abs_section_ptr
;
5135 else if (sym
->st_shndx
== SHN_COMMON
)
5136 sym_sec
= bfd_com_section_ptr
;
5139 bfd_section_from_elf_index (input_bfd
, sym
->st_shndx
);
5142 /* This is an undefined symbol. It can never
5146 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5147 sym_value
= sym
->st_value
;
5148 destination
= (sym_value
+ irela
->r_addend
5149 + sym_sec
->output_offset
5150 + sym_sec
->output_section
->vma
);
5151 st_type
= ELF_ST_TYPE (sym
->st_info
);
5152 branch_type
= ARM_SYM_BRANCH_TYPE (sym
);
5154 = bfd_elf_string_from_elf_section (input_bfd
,
5155 symtab_hdr
->sh_link
,
5160 /* It's an external symbol. */
5161 while (hash
->root
.root
.type
== bfd_link_hash_indirect
5162 || hash
->root
.root
.type
== bfd_link_hash_warning
)
5163 hash
= ((struct elf32_arm_link_hash_entry
*)
5164 hash
->root
.root
.u
.i
.link
);
5166 if (hash
->root
.root
.type
== bfd_link_hash_defined
5167 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
5169 sym_sec
= hash
->root
.root
.u
.def
.section
;
5170 sym_value
= hash
->root
.root
.u
.def
.value
;
5172 struct elf32_arm_link_hash_table
*globals
=
5173 elf32_arm_hash_table (info
);
5175 /* For a destination in a shared library,
5176 use the PLT stub as target address to
5177 decide whether a branch stub is
5180 && globals
->root
.splt
!= NULL
5182 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5184 sym_sec
= globals
->root
.splt
;
5185 sym_value
= hash
->root
.plt
.offset
;
5186 if (sym_sec
->output_section
!= NULL
)
5187 destination
= (sym_value
5188 + sym_sec
->output_offset
5189 + sym_sec
->output_section
->vma
);
5191 else if (sym_sec
->output_section
!= NULL
)
5192 destination
= (sym_value
+ irela
->r_addend
5193 + sym_sec
->output_offset
5194 + sym_sec
->output_section
->vma
);
5196 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
5197 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
5199 /* For a shared library, use the PLT stub as
5200 target address to decide whether a long
5201 branch stub is needed.
5202 For absolute code, they cannot be handled. */
5203 struct elf32_arm_link_hash_table
*globals
=
5204 elf32_arm_hash_table (info
);
5207 && globals
->root
.splt
!= NULL
5209 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5211 sym_sec
= globals
->root
.splt
;
5212 sym_value
= hash
->root
.plt
.offset
;
5213 if (sym_sec
->output_section
!= NULL
)
5214 destination
= (sym_value
5215 + sym_sec
->output_offset
5216 + sym_sec
->output_section
->vma
);
5223 bfd_set_error (bfd_error_bad_value
);
5224 goto error_ret_free_internal
;
5226 st_type
= hash
->root
.type
;
5227 branch_type
= hash
->root
.target_internal
;
5228 sym_name
= hash
->root
.root
.root
.string
;
5233 /* Determine what (if any) linker stub is needed. */
5234 stub_type
= arm_type_of_stub (info
, section
, irela
,
5235 st_type
, &branch_type
,
5236 hash
, destination
, sym_sec
,
5237 input_bfd
, sym_name
);
5238 if (stub_type
== arm_stub_none
)
5241 /* Support for grouping stub sections. */
5242 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5244 /* Get the name of this stub. */
5245 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
,
5248 goto error_ret_free_internal
;
5250 /* We've either created a stub for this reloc already,
5251 or we are about to. */
5252 created_stub
= TRUE
;
5254 stub_entry
= arm_stub_hash_lookup
5255 (&htab
->stub_hash_table
, stub_name
,
5257 if (stub_entry
!= NULL
)
5259 /* The proper stub has already been created. */
5261 stub_entry
->target_value
= sym_value
;
5265 stub_entry
= elf32_arm_add_stub (stub_name
, section
,
5267 if (stub_entry
== NULL
)
5270 goto error_ret_free_internal
;
5273 stub_entry
->target_value
= sym_value
;
5274 stub_entry
->target_section
= sym_sec
;
5275 stub_entry
->stub_type
= stub_type
;
5276 stub_entry
->h
= hash
;
5277 stub_entry
->branch_type
= branch_type
;
5279 if (sym_name
== NULL
)
5280 sym_name
= "unnamed";
5281 stub_entry
->output_name
= (char *)
5282 bfd_alloc (htab
->stub_bfd
,
5283 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
5284 + strlen (sym_name
));
5285 if (stub_entry
->output_name
== NULL
)
5288 goto error_ret_free_internal
;
5291 /* For historical reasons, use the existing names for
5292 ARM-to-Thumb and Thumb-to-ARM stubs. */
5293 if ((r_type
== (unsigned int) R_ARM_THM_CALL
5294 || r_type
== (unsigned int) R_ARM_THM_JUMP24
)
5295 && branch_type
== ST_BRANCH_TO_ARM
)
5296 sprintf (stub_entry
->output_name
,
5297 THUMB2ARM_GLUE_ENTRY_NAME
, sym_name
);
5298 else if ((r_type
== (unsigned int) R_ARM_CALL
5299 || r_type
== (unsigned int) R_ARM_JUMP24
)
5300 && branch_type
== ST_BRANCH_TO_THUMB
)
5301 sprintf (stub_entry
->output_name
,
5302 ARM2THUMB_GLUE_ENTRY_NAME
, sym_name
);
5304 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
5307 stub_changed
= TRUE
;
5311 /* Look for relocations which might trigger Cortex-A8
5313 if (htab
->fix_cortex_a8
5314 && (r_type
== (unsigned int) R_ARM_THM_JUMP24
5315 || r_type
== (unsigned int) R_ARM_THM_JUMP19
5316 || r_type
== (unsigned int) R_ARM_THM_CALL
5317 || r_type
== (unsigned int) R_ARM_THM_XPC22
))
5319 bfd_vma from
= section
->output_section
->vma
5320 + section
->output_offset
5323 if ((from
& 0xfff) == 0xffe)
5325 /* Found a candidate. Note we haven't checked the
5326 destination is within 4K here: if we do so (and
5327 don't create an entry in a8_relocs) we can't tell
5328 that a branch should have been relocated when
5330 if (num_a8_relocs
== a8_reloc_table_size
)
5332 a8_reloc_table_size
*= 2;
5333 a8_relocs
= (struct a8_erratum_reloc
*)
5334 bfd_realloc (a8_relocs
,
5335 sizeof (struct a8_erratum_reloc
)
5336 * a8_reloc_table_size
);
5339 a8_relocs
[num_a8_relocs
].from
= from
;
5340 a8_relocs
[num_a8_relocs
].destination
= destination
;
5341 a8_relocs
[num_a8_relocs
].r_type
= r_type
;
5342 a8_relocs
[num_a8_relocs
].branch_type
= branch_type
;
5343 a8_relocs
[num_a8_relocs
].sym_name
= sym_name
;
5344 a8_relocs
[num_a8_relocs
].non_a8_stub
= created_stub
;
5345 a8_relocs
[num_a8_relocs
].hash
= hash
;
5352 /* We're done with the internal relocs, free them. */
5353 if (elf_section_data (section
)->relocs
== NULL
)
5354 free (internal_relocs
);
5357 if (htab
->fix_cortex_a8
)
5359 /* Sort relocs which might apply to Cortex-A8 erratum. */
5360 qsort (a8_relocs
, num_a8_relocs
,
5361 sizeof (struct a8_erratum_reloc
),
5364 /* Scan for branches which might trigger Cortex-A8 erratum. */
5365 if (cortex_a8_erratum_scan (input_bfd
, info
, &a8_fixes
,
5366 &num_a8_fixes
, &a8_fix_table_size
,
5367 a8_relocs
, num_a8_relocs
,
5368 prev_num_a8_fixes
, &stub_changed
)
5370 goto error_ret_free_local
;
5374 if (prev_num_a8_fixes
!= num_a8_fixes
)
5375 stub_changed
= TRUE
;
5380 /* OK, we've added some stubs. Find out the new size of the
5382 for (stub_sec
= htab
->stub_bfd
->sections
;
5384 stub_sec
= stub_sec
->next
)
5386 /* Ignore non-stub sections. */
5387 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5393 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
5395 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
5396 if (htab
->fix_cortex_a8
)
5397 for (i
= 0; i
< num_a8_fixes
; i
++)
5399 stub_sec
= elf32_arm_create_or_find_stub_sec (NULL
,
5400 a8_fixes
[i
].section
, htab
);
5402 if (stub_sec
== NULL
)
5403 goto error_ret_free_local
;
5406 += find_stub_size_and_template (a8_fixes
[i
].stub_type
, NULL
,
5411 /* Ask the linker to do its stuff. */
5412 (*htab
->layout_sections_again
) ();
5415 /* Add stubs for Cortex-A8 erratum fixes now. */
5416 if (htab
->fix_cortex_a8
)
5418 for (i
= 0; i
< num_a8_fixes
; i
++)
5420 struct elf32_arm_stub_hash_entry
*stub_entry
;
5421 char *stub_name
= a8_fixes
[i
].stub_name
;
5422 asection
*section
= a8_fixes
[i
].section
;
5423 unsigned int section_id
= a8_fixes
[i
].section
->id
;
5424 asection
*link_sec
= htab
->stub_group
[section_id
].link_sec
;
5425 asection
*stub_sec
= htab
->stub_group
[section_id
].stub_sec
;
5426 const insn_sequence
*template_sequence
;
5427 int template_size
, size
= 0;
5429 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
5431 if (stub_entry
== NULL
)
5433 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
5439 stub_entry
->stub_sec
= stub_sec
;
5440 stub_entry
->stub_offset
= 0;
5441 stub_entry
->id_sec
= link_sec
;
5442 stub_entry
->stub_type
= a8_fixes
[i
].stub_type
;
5443 stub_entry
->target_section
= a8_fixes
[i
].section
;
5444 stub_entry
->target_value
= a8_fixes
[i
].offset
;
5445 stub_entry
->target_addend
= a8_fixes
[i
].addend
;
5446 stub_entry
->orig_insn
= a8_fixes
[i
].orig_insn
;
5447 stub_entry
->branch_type
= a8_fixes
[i
].branch_type
;
5449 size
= find_stub_size_and_template (a8_fixes
[i
].stub_type
,
5453 stub_entry
->stub_size
= size
;
5454 stub_entry
->stub_template
= template_sequence
;
5455 stub_entry
->stub_template_size
= template_size
;
5458 /* Stash the Cortex-A8 erratum fix array for use later in
5459 elf32_arm_write_section(). */
5460 htab
->a8_erratum_fixes
= a8_fixes
;
5461 htab
->num_a8_erratum_fixes
= num_a8_fixes
;
5465 htab
->a8_erratum_fixes
= NULL
;
5466 htab
->num_a8_erratum_fixes
= 0;
5470 error_ret_free_local
:
5474 /* Build all the stubs associated with the current output file. The
5475 stubs are kept in a hash table attached to the main linker hash
5476 table. We also set up the .plt entries for statically linked PIC
5477 functions here. This function is called via arm_elf_finish in the
5481 elf32_arm_build_stubs (struct bfd_link_info
*info
)
5484 struct bfd_hash_table
*table
;
5485 struct elf32_arm_link_hash_table
*htab
;
5487 htab
= elf32_arm_hash_table (info
);
5491 for (stub_sec
= htab
->stub_bfd
->sections
;
5493 stub_sec
= stub_sec
->next
)
5497 /* Ignore non-stub sections. */
5498 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5501 /* Allocate memory to hold the linker stubs. */
5502 size
= stub_sec
->size
;
5503 stub_sec
->contents
= (unsigned char *) bfd_zalloc (htab
->stub_bfd
, size
);
5504 if (stub_sec
->contents
== NULL
&& size
!= 0)
5509 /* Build the stubs as directed by the stub hash table. */
5510 table
= &htab
->stub_hash_table
;
5511 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5512 if (htab
->fix_cortex_a8
)
5514 /* Place the cortex a8 stubs last. */
5515 htab
->fix_cortex_a8
= -1;
5516 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5522 /* Locate the Thumb encoded calling stub for NAME. */
5524 static struct elf_link_hash_entry
*
5525 find_thumb_glue (struct bfd_link_info
*link_info
,
5527 char **error_message
)
5530 struct elf_link_hash_entry
*hash
;
5531 struct elf32_arm_link_hash_table
*hash_table
;
5533 /* We need a pointer to the armelf specific hash table. */
5534 hash_table
= elf32_arm_hash_table (link_info
);
5535 if (hash_table
== NULL
)
5538 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5539 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
5541 BFD_ASSERT (tmp_name
);
5543 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
5545 hash
= elf_link_hash_lookup
5546 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5549 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
5550 tmp_name
, name
) == -1)
5551 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5558 /* Locate the ARM encoded calling stub for NAME. */
5560 static struct elf_link_hash_entry
*
5561 find_arm_glue (struct bfd_link_info
*link_info
,
5563 char **error_message
)
5566 struct elf_link_hash_entry
*myh
;
5567 struct elf32_arm_link_hash_table
*hash_table
;
5569 /* We need a pointer to the elfarm specific hash table. */
5570 hash_table
= elf32_arm_hash_table (link_info
);
5571 if (hash_table
== NULL
)
5574 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5575 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5577 BFD_ASSERT (tmp_name
);
5579 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5581 myh
= elf_link_hash_lookup
5582 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5585 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
5586 tmp_name
, name
) == -1)
5587 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5594 /* ARM->Thumb glue (static images):
5598 ldr r12, __func_addr
5601 .word func @ behave as if you saw a ARM_32 reloc.
5608 .word func @ behave as if you saw a ARM_32 reloc.
5610 (relocatable images)
5613 ldr r12, __func_offset
5619 #define ARM2THUMB_STATIC_GLUE_SIZE 12
5620 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
5621 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
5622 static const insn32 a2t3_func_addr_insn
= 0x00000001;
5624 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
5625 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
5626 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
5628 #define ARM2THUMB_PIC_GLUE_SIZE 16
5629 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
5630 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
5631 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
5633 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
5637 __func_from_thumb: __func_from_thumb:
5639 nop ldr r6, __func_addr
5649 #define THUMB2ARM_GLUE_SIZE 8
5650 static const insn16 t2a1_bx_pc_insn
= 0x4778;
5651 static const insn16 t2a2_noop_insn
= 0x46c0;
5652 static const insn32 t2a3_b_insn
= 0xea000000;
5654 #define VFP11_ERRATUM_VENEER_SIZE 8
5656 #define ARM_BX_VENEER_SIZE 12
5657 static const insn32 armbx1_tst_insn
= 0xe3100001;
5658 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
5659 static const insn32 armbx3_bx_insn
= 0xe12fff10;
5661 #ifndef ELFARM_NABI_C_INCLUDED
5663 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
5666 bfd_byte
* contents
;
5670 /* Do not include empty glue sections in the output. */
5673 s
= bfd_get_linker_section (abfd
, name
);
5675 s
->flags
|= SEC_EXCLUDE
;
5680 BFD_ASSERT (abfd
!= NULL
);
5682 s
= bfd_get_linker_section (abfd
, name
);
5683 BFD_ASSERT (s
!= NULL
);
5685 contents
= (bfd_byte
*) bfd_alloc (abfd
, size
);
5687 BFD_ASSERT (s
->size
== size
);
5688 s
->contents
= contents
;
5692 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
5694 struct elf32_arm_link_hash_table
* globals
;
5696 globals
= elf32_arm_hash_table (info
);
5697 BFD_ASSERT (globals
!= NULL
);
5699 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5700 globals
->arm_glue_size
,
5701 ARM2THUMB_GLUE_SECTION_NAME
);
5703 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5704 globals
->thumb_glue_size
,
5705 THUMB2ARM_GLUE_SECTION_NAME
);
5707 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5708 globals
->vfp11_erratum_glue_size
,
5709 VFP11_ERRATUM_VENEER_SECTION_NAME
);
5711 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5712 globals
->bx_glue_size
,
5713 ARM_BX_GLUE_SECTION_NAME
);
5718 /* Allocate space and symbols for calling a Thumb function from Arm mode.
5719 returns the symbol identifying the stub. */
5721 static struct elf_link_hash_entry
*
5722 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
5723 struct elf_link_hash_entry
* h
)
5725 const char * name
= h
->root
.root
.string
;
5728 struct elf_link_hash_entry
* myh
;
5729 struct bfd_link_hash_entry
* bh
;
5730 struct elf32_arm_link_hash_table
* globals
;
5734 globals
= elf32_arm_hash_table (link_info
);
5735 BFD_ASSERT (globals
!= NULL
);
5736 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5738 s
= bfd_get_linker_section
5739 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
5741 BFD_ASSERT (s
!= NULL
);
5743 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5744 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5746 BFD_ASSERT (tmp_name
);
5748 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5750 myh
= elf_link_hash_lookup
5751 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5755 /* We've already seen this guy. */
5760 /* The only trick here is using hash_table->arm_glue_size as the value.
5761 Even though the section isn't allocated yet, this is where we will be
5762 putting it. The +1 on the value marks that the stub has not been
5763 output yet - not that it is a Thumb function. */
5765 val
= globals
->arm_glue_size
+ 1;
5766 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5767 tmp_name
, BSF_GLOBAL
, s
, val
,
5768 NULL
, TRUE
, FALSE
, &bh
);
5770 myh
= (struct elf_link_hash_entry
*) bh
;
5771 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5772 myh
->forced_local
= 1;
5776 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
5777 || globals
->pic_veneer
)
5778 size
= ARM2THUMB_PIC_GLUE_SIZE
;
5779 else if (globals
->use_blx
)
5780 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
5782 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
5785 globals
->arm_glue_size
+= size
;
5790 /* Allocate space for ARMv4 BX veneers. */
5793 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
5796 struct elf32_arm_link_hash_table
*globals
;
5798 struct elf_link_hash_entry
*myh
;
5799 struct bfd_link_hash_entry
*bh
;
5802 /* BX PC does not need a veneer. */
5806 globals
= elf32_arm_hash_table (link_info
);
5807 BFD_ASSERT (globals
!= NULL
);
5808 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5810 /* Check if this veneer has already been allocated. */
5811 if (globals
->bx_glue_offset
[reg
])
5814 s
= bfd_get_linker_section
5815 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
5817 BFD_ASSERT (s
!= NULL
);
5819 /* Add symbol for veneer. */
5821 bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
5823 BFD_ASSERT (tmp_name
);
5825 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
5827 myh
= elf_link_hash_lookup
5828 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5830 BFD_ASSERT (myh
== NULL
);
5833 val
= globals
->bx_glue_size
;
5834 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5835 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5836 NULL
, TRUE
, FALSE
, &bh
);
5838 myh
= (struct elf_link_hash_entry
*) bh
;
5839 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5840 myh
->forced_local
= 1;
5842 s
->size
+= ARM_BX_VENEER_SIZE
;
5843 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
5844 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
5848 /* Add an entry to the code/data map for section SEC. */
5851 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
5853 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5854 unsigned int newidx
;
5856 if (sec_data
->map
== NULL
)
5858 sec_data
->map
= (elf32_arm_section_map
*)
5859 bfd_malloc (sizeof (elf32_arm_section_map
));
5860 sec_data
->mapcount
= 0;
5861 sec_data
->mapsize
= 1;
5864 newidx
= sec_data
->mapcount
++;
5866 if (sec_data
->mapcount
> sec_data
->mapsize
)
5868 sec_data
->mapsize
*= 2;
5869 sec_data
->map
= (elf32_arm_section_map
*)
5870 bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
5871 * sizeof (elf32_arm_section_map
));
5876 sec_data
->map
[newidx
].vma
= vma
;
5877 sec_data
->map
[newidx
].type
= type
;
5882 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
5883 veneers are handled for now. */
5886 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
5887 elf32_vfp11_erratum_list
*branch
,
5889 asection
*branch_sec
,
5890 unsigned int offset
)
5893 struct elf32_arm_link_hash_table
*hash_table
;
5895 struct elf_link_hash_entry
*myh
;
5896 struct bfd_link_hash_entry
*bh
;
5898 struct _arm_elf_section_data
*sec_data
;
5899 elf32_vfp11_erratum_list
*newerr
;
5901 hash_table
= elf32_arm_hash_table (link_info
);
5902 BFD_ASSERT (hash_table
!= NULL
);
5903 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
5905 s
= bfd_get_linker_section
5906 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
5908 sec_data
= elf32_arm_section_data (s
);
5910 BFD_ASSERT (s
!= NULL
);
5912 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
5913 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5915 BFD_ASSERT (tmp_name
);
5917 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5918 hash_table
->num_vfp11_fixes
);
5920 myh
= elf_link_hash_lookup
5921 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5923 BFD_ASSERT (myh
== NULL
);
5926 val
= hash_table
->vfp11_erratum_glue_size
;
5927 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
5928 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5929 NULL
, TRUE
, FALSE
, &bh
);
5931 myh
= (struct elf_link_hash_entry
*) bh
;
5932 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5933 myh
->forced_local
= 1;
5935 /* Link veneer back to calling location. */
5936 sec_data
->erratumcount
+= 1;
5937 newerr
= (elf32_vfp11_erratum_list
*)
5938 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5940 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
5942 newerr
->u
.v
.branch
= branch
;
5943 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
5944 branch
->u
.b
.veneer
= newerr
;
5946 newerr
->next
= sec_data
->erratumlist
;
5947 sec_data
->erratumlist
= newerr
;
5949 /* A symbol for the return from the veneer. */
5950 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
5951 hash_table
->num_vfp11_fixes
);
5953 myh
= elf_link_hash_lookup
5954 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5961 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
5962 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
5964 myh
= (struct elf_link_hash_entry
*) bh
;
5965 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5966 myh
->forced_local
= 1;
5970 /* Generate a mapping symbol for the veneer section, and explicitly add an
5971 entry for that symbol to the code/data map for the section. */
5972 if (hash_table
->vfp11_erratum_glue_size
== 0)
5975 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
5976 ever requires this erratum fix. */
5977 _bfd_generic_link_add_one_symbol (link_info
,
5978 hash_table
->bfd_of_glue_owner
, "$a",
5979 BSF_LOCAL
, s
, 0, NULL
,
5982 myh
= (struct elf_link_hash_entry
*) bh
;
5983 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5984 myh
->forced_local
= 1;
5986 /* The elf32_arm_init_maps function only cares about symbols from input
5987 BFDs. We must make a note of this generated mapping symbol
5988 ourselves so that code byteswapping works properly in
5989 elf32_arm_write_section. */
5990 elf32_arm_section_map_add (s
, 'a', 0);
5993 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
5994 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
5995 hash_table
->num_vfp11_fixes
++;
5997 /* The offset of the veneer. */
6001 #define ARM_GLUE_SECTION_FLAGS \
6002 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
6003 | SEC_READONLY | SEC_LINKER_CREATED)
6005 /* Create a fake section for use by the ARM backend of the linker. */
6008 arm_make_glue_section (bfd
* abfd
, const char * name
)
6012 sec
= bfd_get_linker_section (abfd
, name
);
6017 sec
= bfd_make_section_anyway_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
6020 || !bfd_set_section_alignment (abfd
, sec
, 2))
6023 /* Set the gc mark to prevent the section from being removed by garbage
6024 collection, despite the fact that no relocs refer to this section. */
6030 /* Add the glue sections to ABFD. This function is called from the
6031 linker scripts in ld/emultempl/{armelf}.em. */
6034 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
6035 struct bfd_link_info
*info
)
6037 /* If we are only performing a partial
6038 link do not bother adding the glue. */
6039 if (info
->relocatable
)
6042 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
6043 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
6044 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
6045 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
6048 /* Select a BFD to be used to hold the sections used by the glue code.
6049 This function is called from the linker scripts in ld/emultempl/
6053 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
6055 struct elf32_arm_link_hash_table
*globals
;
6057 /* If we are only performing a partial link
6058 do not bother getting a bfd to hold the glue. */
6059 if (info
->relocatable
)
6062 /* Make sure we don't attach the glue sections to a dynamic object. */
6063 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
6065 globals
= elf32_arm_hash_table (info
);
6066 BFD_ASSERT (globals
!= NULL
);
6068 if (globals
->bfd_of_glue_owner
!= NULL
)
6071 /* Save the bfd for later use. */
6072 globals
->bfd_of_glue_owner
= abfd
;
6078 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
6082 cpu_arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
6085 if (globals
->fix_arm1176
)
6087 if (cpu_arch
== TAG_CPU_ARCH_V6T2
|| cpu_arch
> TAG_CPU_ARCH_V6K
)
6088 globals
->use_blx
= 1;
6092 if (cpu_arch
> TAG_CPU_ARCH_V4T
)
6093 globals
->use_blx
= 1;
6098 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
6099 struct bfd_link_info
*link_info
)
6101 Elf_Internal_Shdr
*symtab_hdr
;
6102 Elf_Internal_Rela
*internal_relocs
= NULL
;
6103 Elf_Internal_Rela
*irel
, *irelend
;
6104 bfd_byte
*contents
= NULL
;
6107 struct elf32_arm_link_hash_table
*globals
;
6109 /* If we are only performing a partial link do not bother
6110 to construct any glue. */
6111 if (link_info
->relocatable
)
6114 /* Here we have a bfd that is to be included on the link. We have a
6115 hook to do reloc rummaging, before section sizes are nailed down. */
6116 globals
= elf32_arm_hash_table (link_info
);
6117 BFD_ASSERT (globals
!= NULL
);
6119 check_use_blx (globals
);
6121 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
6123 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
6128 /* PR 5398: If we have not decided to include any loadable sections in
6129 the output then we will not have a glue owner bfd. This is OK, it
6130 just means that there is nothing else for us to do here. */
6131 if (globals
->bfd_of_glue_owner
== NULL
)
6134 /* Rummage around all the relocs and map the glue vectors. */
6135 sec
= abfd
->sections
;
6140 for (; sec
!= NULL
; sec
= sec
->next
)
6142 if (sec
->reloc_count
== 0)
6145 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
6148 symtab_hdr
= & elf_symtab_hdr (abfd
);
6150 /* Load the relocs. */
6152 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
6154 if (internal_relocs
== NULL
)
6157 irelend
= internal_relocs
+ sec
->reloc_count
;
6158 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6161 unsigned long r_index
;
6163 struct elf_link_hash_entry
*h
;
6165 r_type
= ELF32_R_TYPE (irel
->r_info
);
6166 r_index
= ELF32_R_SYM (irel
->r_info
);
6168 /* These are the only relocation types we care about. */
6169 if ( r_type
!= R_ARM_PC24
6170 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
6173 /* Get the section contents if we haven't done so already. */
6174 if (contents
== NULL
)
6176 /* Get cached copy if it exists. */
6177 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6178 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6181 /* Go get them off disk. */
6182 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6187 if (r_type
== R_ARM_V4BX
)
6191 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
6192 record_arm_bx_glue (link_info
, reg
);
6196 /* If the relocation is not against a symbol it cannot concern us. */
6199 /* We don't care about local symbols. */
6200 if (r_index
< symtab_hdr
->sh_info
)
6203 /* This is an external symbol. */
6204 r_index
-= symtab_hdr
->sh_info
;
6205 h
= (struct elf_link_hash_entry
*)
6206 elf_sym_hashes (abfd
)[r_index
];
6208 /* If the relocation is against a static symbol it must be within
6209 the current section and so cannot be a cross ARM/Thumb relocation. */
6213 /* If the call will go through a PLT entry then we do not need
6215 if (globals
->root
.splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6221 /* This one is a call from arm code. We need to look up
6222 the target of the call. If it is a thumb target, we
6224 if (h
->target_internal
== ST_BRANCH_TO_THUMB
)
6225 record_arm_to_thumb_glue (link_info
, h
);
6233 if (contents
!= NULL
6234 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6238 if (internal_relocs
!= NULL
6239 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6240 free (internal_relocs
);
6241 internal_relocs
= NULL
;
6247 if (contents
!= NULL
6248 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6250 if (internal_relocs
!= NULL
6251 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6252 free (internal_relocs
);
6259 /* Initialise maps of ARM/Thumb/data for input BFDs. */
6262 bfd_elf32_arm_init_maps (bfd
*abfd
)
6264 Elf_Internal_Sym
*isymbuf
;
6265 Elf_Internal_Shdr
*hdr
;
6266 unsigned int i
, localsyms
;
6268 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
6269 if (! is_arm_elf (abfd
))
6272 if ((abfd
->flags
& DYNAMIC
) != 0)
6275 hdr
= & elf_symtab_hdr (abfd
);
6276 localsyms
= hdr
->sh_info
;
6278 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
6279 should contain the number of local symbols, which should come before any
6280 global symbols. Mapping symbols are always local. */
6281 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
6284 /* No internal symbols read? Skip this BFD. */
6285 if (isymbuf
== NULL
)
6288 for (i
= 0; i
< localsyms
; i
++)
6290 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
6291 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6295 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
6297 name
= bfd_elf_string_from_elf_section (abfd
,
6298 hdr
->sh_link
, isym
->st_name
);
6300 if (bfd_is_arm_special_symbol_name (name
,
6301 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
6302 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
6308 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
6309 say what they wanted. */
6312 bfd_elf32_arm_set_cortex_a8_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6314 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6315 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6317 if (globals
== NULL
)
6320 if (globals
->fix_cortex_a8
== -1)
6322 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
6323 if (out_attr
[Tag_CPU_arch
].i
== TAG_CPU_ARCH_V7
6324 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
6325 || out_attr
[Tag_CPU_arch_profile
].i
== 0))
6326 globals
->fix_cortex_a8
= 1;
6328 globals
->fix_cortex_a8
= 0;
6334 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6336 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6337 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6339 if (globals
== NULL
)
6341 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
6342 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
6344 switch (globals
->vfp11_fix
)
6346 case BFD_ARM_VFP11_FIX_DEFAULT
:
6347 case BFD_ARM_VFP11_FIX_NONE
:
6348 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6352 /* Give a warning, but do as the user requests anyway. */
6353 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
6354 "workaround is not necessary for target architecture"), obfd
);
6357 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
6358 /* For earlier architectures, we might need the workaround, but do not
6359 enable it by default. If users is running with broken hardware, they
6360 must enable the erratum fix explicitly. */
6361 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6365 enum bfd_arm_vfp11_pipe
6373 /* Return a VFP register number. This is encoded as RX:X for single-precision
6374 registers, or X:RX for double-precision registers, where RX is the group of
6375 four bits in the instruction encoding and X is the single extension bit.
6376 RX and X fields are specified using their lowest (starting) bit. The return
6379 0...31: single-precision registers s0...s31
6380 32...63: double-precision registers d0...d31.
6382 Although X should be zero for VFP11 (encoding d0...d15 only), we might
6383 encounter VFP3 instructions, so we allow the full range for DP registers. */
6386 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
6390 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
6392 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
6395 /* Set bits in *WMASK according to a register number REG as encoded by
6396 bfd_arm_vfp11_regno(). Ignore d16-d31. */
6399 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
6404 *wmask
|= 3 << ((reg
- 32) * 2);
6407 /* Return TRUE if WMASK overwrites anything in REGS. */
6410 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
6414 for (i
= 0; i
< numregs
; i
++)
6416 unsigned int reg
= regs
[i
];
6418 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
6426 if ((wmask
& (3 << (reg
* 2))) != 0)
6433 /* In this function, we're interested in two things: finding input registers
6434 for VFP data-processing instructions, and finding the set of registers which
6435 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
6436 hold the written set, so FLDM etc. are easy to deal with (we're only
6437 interested in 32 SP registers or 16 dp registers, due to the VFP version
6438 implemented by the chip in question). DP registers are marked by setting
6439 both SP registers in the write mask). */
6441 static enum bfd_arm_vfp11_pipe
6442 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
6445 enum bfd_arm_vfp11_pipe vpipe
= VFP11_BAD
;
6446 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
6448 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
6451 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6452 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6454 pqrs
= ((insn
& 0x00800000) >> 20)
6455 | ((insn
& 0x00300000) >> 19)
6456 | ((insn
& 0x00000040) >> 6);
6460 case 0: /* fmac[sd]. */
6461 case 1: /* fnmac[sd]. */
6462 case 2: /* fmsc[sd]. */
6463 case 3: /* fnmsc[sd]. */
6465 bfd_arm_vfp11_write_mask (destmask
, fd
);
6467 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6472 case 4: /* fmul[sd]. */
6473 case 5: /* fnmul[sd]. */
6474 case 6: /* fadd[sd]. */
6475 case 7: /* fsub[sd]. */
6479 case 8: /* fdiv[sd]. */
6482 bfd_arm_vfp11_write_mask (destmask
, fd
);
6483 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6488 case 15: /* extended opcode. */
6490 unsigned int extn
= ((insn
>> 15) & 0x1e)
6491 | ((insn
>> 7) & 1);
6495 case 0: /* fcpy[sd]. */
6496 case 1: /* fabs[sd]. */
6497 case 2: /* fneg[sd]. */
6498 case 8: /* fcmp[sd]. */
6499 case 9: /* fcmpe[sd]. */
6500 case 10: /* fcmpz[sd]. */
6501 case 11: /* fcmpez[sd]. */
6502 case 16: /* fuito[sd]. */
6503 case 17: /* fsito[sd]. */
6504 case 24: /* ftoui[sd]. */
6505 case 25: /* ftouiz[sd]. */
6506 case 26: /* ftosi[sd]. */
6507 case 27: /* ftosiz[sd]. */
6508 /* These instructions will not bounce due to underflow. */
6513 case 3: /* fsqrt[sd]. */
6514 /* fsqrt cannot underflow, but it can (perhaps) overwrite
6515 registers to cause the erratum in previous instructions. */
6516 bfd_arm_vfp11_write_mask (destmask
, fd
);
6520 case 15: /* fcvt{ds,sd}. */
6524 bfd_arm_vfp11_write_mask (destmask
, fd
);
6526 /* Only FCVTSD can underflow. */
6527 if ((insn
& 0x100) != 0)
6546 /* Two-register transfer. */
6547 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
6549 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6551 if ((insn
& 0x100000) == 0)
6554 bfd_arm_vfp11_write_mask (destmask
, fm
);
6557 bfd_arm_vfp11_write_mask (destmask
, fm
);
6558 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
6564 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
6566 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6567 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
6571 case 0: /* Two-reg transfer. We should catch these above. */
6574 case 2: /* fldm[sdx]. */
6578 unsigned int i
, offset
= insn
& 0xff;
6583 for (i
= fd
; i
< fd
+ offset
; i
++)
6584 bfd_arm_vfp11_write_mask (destmask
, i
);
6588 case 4: /* fld[sd]. */
6590 bfd_arm_vfp11_write_mask (destmask
, fd
);
6599 /* Single-register transfer. Note L==0. */
6600 else if ((insn
& 0x0f100e10) == 0x0e000a10)
6602 unsigned int opcode
= (insn
>> 21) & 7;
6603 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
6607 case 0: /* fmsr/fmdlr. */
6608 case 1: /* fmdhr. */
6609 /* Mark fmdhr and fmdlr as writing to the whole of the DP
6610 destination register. I don't know if this is exactly right,
6611 but it is the conservative choice. */
6612 bfd_arm_vfp11_write_mask (destmask
, fn
);
6626 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
6629 /* Look for potentially-troublesome code sequences which might trigger the
6630 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
6631 (available from ARM) for details of the erratum. A short version is
6632 described in ld.texinfo. */
6635 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
6638 bfd_byte
*contents
= NULL
;
6640 int regs
[3], numregs
= 0;
6641 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6642 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
6644 if (globals
== NULL
)
6647 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
6648 The states transition as follows:
6650 0 -> 1 (vector) or 0 -> 2 (scalar)
6651 A VFP FMAC-pipeline instruction has been seen. Fill
6652 regs[0]..regs[numregs-1] with its input operands. Remember this
6653 instruction in 'first_fmac'.
6656 Any instruction, except for a VFP instruction which overwrites
6661 A VFP instruction has been seen which overwrites any of regs[*].
6662 We must make a veneer! Reset state to 0 before examining next
6666 If we fail to match anything in state 2, reset to state 0 and reset
6667 the instruction pointer to the instruction after 'first_fmac'.
6669 If the VFP11 vector mode is in use, there must be at least two unrelated
6670 instructions between anti-dependent VFP11 instructions to properly avoid
6671 triggering the erratum, hence the use of the extra state 1. */
6673 /* If we are only performing a partial link do not bother
6674 to construct any glue. */
6675 if (link_info
->relocatable
)
6678 /* Skip if this bfd does not correspond to an ELF image. */
6679 if (! is_arm_elf (abfd
))
6682 /* We should have chosen a fix type by the time we get here. */
6683 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
6685 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
6688 /* Skip this BFD if it corresponds to an executable or dynamic object. */
6689 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
6692 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6694 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
6695 struct _arm_elf_section_data
*sec_data
;
6697 /* If we don't have executable progbits, we're not interested in this
6698 section. Also skip if section is to be excluded. */
6699 if (elf_section_type (sec
) != SHT_PROGBITS
6700 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
6701 || (sec
->flags
& SEC_EXCLUDE
) != 0
6702 || sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
6703 || sec
->output_section
== bfd_abs_section_ptr
6704 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
6707 sec_data
= elf32_arm_section_data (sec
);
6709 if (sec_data
->mapcount
== 0)
6712 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6713 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6714 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6717 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
6718 elf32_arm_compare_mapping
);
6720 for (span
= 0; span
< sec_data
->mapcount
; span
++)
6722 unsigned int span_start
= sec_data
->map
[span
].vma
;
6723 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
6724 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
6725 char span_type
= sec_data
->map
[span
].type
;
6727 /* FIXME: Only ARM mode is supported at present. We may need to
6728 support Thumb-2 mode also at some point. */
6729 if (span_type
!= 'a')
6732 for (i
= span_start
; i
< span_end
;)
6734 unsigned int next_i
= i
+ 4;
6735 unsigned int insn
= bfd_big_endian (abfd
)
6736 ? (contents
[i
] << 24)
6737 | (contents
[i
+ 1] << 16)
6738 | (contents
[i
+ 2] << 8)
6740 : (contents
[i
+ 3] << 24)
6741 | (contents
[i
+ 2] << 16)
6742 | (contents
[i
+ 1] << 8)
6744 unsigned int writemask
= 0;
6745 enum bfd_arm_vfp11_pipe vpipe
;
6750 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
6752 /* I'm assuming the VFP11 erratum can trigger with denorm
6753 operands on either the FMAC or the DS pipeline. This might
6754 lead to slightly overenthusiastic veneer insertion. */
6755 if (vpipe
== VFP11_FMAC
|| vpipe
== VFP11_DS
)
6757 state
= use_vector
? 1 : 2;
6759 veneer_of_insn
= insn
;
6765 int other_regs
[3], other_numregs
;
6766 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6769 if (vpipe
!= VFP11_BAD
6770 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6780 int other_regs
[3], other_numregs
;
6781 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6784 if (vpipe
!= VFP11_BAD
6785 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6791 next_i
= first_fmac
+ 4;
6797 abort (); /* Should be unreachable. */
6802 elf32_vfp11_erratum_list
*newerr
=(elf32_vfp11_erratum_list
*)
6803 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
6805 elf32_arm_section_data (sec
)->erratumcount
+= 1;
6807 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
6812 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
6819 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
6824 newerr
->next
= sec_data
->erratumlist
;
6825 sec_data
->erratumlist
= newerr
;
6834 if (contents
!= NULL
6835 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6843 if (contents
!= NULL
6844 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6850 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
6851 after sections have been laid out, using specially-named symbols. */
6854 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
6855 struct bfd_link_info
*link_info
)
6858 struct elf32_arm_link_hash_table
*globals
;
6861 if (link_info
->relocatable
)
6864 /* Skip if this bfd does not correspond to an ELF image. */
6865 if (! is_arm_elf (abfd
))
6868 globals
= elf32_arm_hash_table (link_info
);
6869 if (globals
== NULL
)
6872 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
6873 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
6875 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6877 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
6878 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
6880 for (; errnode
!= NULL
; errnode
= errnode
->next
)
6882 struct elf_link_hash_entry
*myh
;
6885 switch (errnode
->type
)
6887 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
6888 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
6889 /* Find veneer symbol. */
6890 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
6891 errnode
->u
.b
.veneer
->u
.v
.id
);
6893 myh
= elf_link_hash_lookup
6894 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6897 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6898 "`%s'"), abfd
, tmp_name
);
6900 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6901 + myh
->root
.u
.def
.section
->output_offset
6902 + myh
->root
.u
.def
.value
;
6904 errnode
->u
.b
.veneer
->vma
= vma
;
6907 case VFP11_ERRATUM_ARM_VENEER
:
6908 case VFP11_ERRATUM_THUMB_VENEER
:
6909 /* Find return location. */
6910 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
6913 myh
= elf_link_hash_lookup
6914 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6917 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6918 "`%s'"), abfd
, tmp_name
);
6920 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6921 + myh
->root
.u
.def
.section
->output_offset
6922 + myh
->root
.u
.def
.value
;
6924 errnode
->u
.v
.branch
->vma
= vma
;
6937 /* Set target relocation values needed during linking. */
6940 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
6941 struct bfd_link_info
*link_info
,
6943 char * target2_type
,
6946 bfd_arm_vfp11_fix vfp11_fix
,
6947 int no_enum_warn
, int no_wchar_warn
,
6948 int pic_veneer
, int fix_cortex_a8
,
6951 struct elf32_arm_link_hash_table
*globals
;
6953 globals
= elf32_arm_hash_table (link_info
);
6954 if (globals
== NULL
)
6957 globals
->target1_is_rel
= target1_is_rel
;
6958 if (strcmp (target2_type
, "rel") == 0)
6959 globals
->target2_reloc
= R_ARM_REL32
;
6960 else if (strcmp (target2_type
, "abs") == 0)
6961 globals
->target2_reloc
= R_ARM_ABS32
;
6962 else if (strcmp (target2_type
, "got-rel") == 0)
6963 globals
->target2_reloc
= R_ARM_GOT_PREL
;
6966 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
6969 globals
->fix_v4bx
= fix_v4bx
;
6970 globals
->use_blx
|= use_blx
;
6971 globals
->vfp11_fix
= vfp11_fix
;
6972 globals
->pic_veneer
= pic_veneer
;
6973 globals
->fix_cortex_a8
= fix_cortex_a8
;
6974 globals
->fix_arm1176
= fix_arm1176
;
6976 BFD_ASSERT (is_arm_elf (output_bfd
));
6977 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
6978 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
6981 /* Replace the target offset of a Thumb bl or b.w instruction. */
6984 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
6990 BFD_ASSERT ((offset
& 1) == 0);
6992 upper
= bfd_get_16 (abfd
, insn
);
6993 lower
= bfd_get_16 (abfd
, insn
+ 2);
6994 reloc_sign
= (offset
< 0) ? 1 : 0;
6995 upper
= (upper
& ~(bfd_vma
) 0x7ff)
6996 | ((offset
>> 12) & 0x3ff)
6997 | (reloc_sign
<< 10);
6998 lower
= (lower
& ~(bfd_vma
) 0x2fff)
6999 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
7000 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
7001 | ((offset
>> 1) & 0x7ff);
7002 bfd_put_16 (abfd
, upper
, insn
);
7003 bfd_put_16 (abfd
, lower
, insn
+ 2);
7006 /* Thumb code calling an ARM function. */
7009 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
7013 asection
* input_section
,
7014 bfd_byte
* hit_data
,
7017 bfd_signed_vma addend
,
7019 char **error_message
)
7023 long int ret_offset
;
7024 struct elf_link_hash_entry
* myh
;
7025 struct elf32_arm_link_hash_table
* globals
;
7027 myh
= find_thumb_glue (info
, name
, error_message
);
7031 globals
= elf32_arm_hash_table (info
);
7032 BFD_ASSERT (globals
!= NULL
);
7033 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7035 my_offset
= myh
->root
.u
.def
.value
;
7037 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7038 THUMB2ARM_GLUE_SECTION_NAME
);
7040 BFD_ASSERT (s
!= NULL
);
7041 BFD_ASSERT (s
->contents
!= NULL
);
7042 BFD_ASSERT (s
->output_section
!= NULL
);
7044 if ((my_offset
& 0x01) == 0x01)
7047 && sym_sec
->owner
!= NULL
7048 && !INTERWORK_FLAG (sym_sec
->owner
))
7050 (*_bfd_error_handler
)
7051 (_("%B(%s): warning: interworking not enabled.\n"
7052 " first occurrence: %B: Thumb call to ARM"),
7053 sym_sec
->owner
, input_bfd
, name
);
7059 myh
->root
.u
.def
.value
= my_offset
;
7061 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
7062 s
->contents
+ my_offset
);
7064 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
7065 s
->contents
+ my_offset
+ 2);
7068 /* Address of destination of the stub. */
7069 ((bfd_signed_vma
) val
)
7071 /* Offset from the start of the current section
7072 to the start of the stubs. */
7074 /* Offset of the start of this stub from the start of the stubs. */
7076 /* Address of the start of the current section. */
7077 + s
->output_section
->vma
)
7078 /* The branch instruction is 4 bytes into the stub. */
7080 /* ARM branches work from the pc of the instruction + 8. */
7083 put_arm_insn (globals
, output_bfd
,
7084 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
7085 s
->contents
+ my_offset
+ 4);
7088 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
7090 /* Now go back and fix up the original BL insn to point to here. */
7092 /* Address of where the stub is located. */
7093 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
7094 /* Address of where the BL is located. */
7095 - (input_section
->output_section
->vma
+ input_section
->output_offset
7097 /* Addend in the relocation. */
7099 /* Biassing for PC-relative addressing. */
7102 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
7107 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
7109 static struct elf_link_hash_entry
*
7110 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
7117 char ** error_message
)
7120 long int ret_offset
;
7121 struct elf_link_hash_entry
* myh
;
7122 struct elf32_arm_link_hash_table
* globals
;
7124 myh
= find_arm_glue (info
, name
, error_message
);
7128 globals
= elf32_arm_hash_table (info
);
7129 BFD_ASSERT (globals
!= NULL
);
7130 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7132 my_offset
= myh
->root
.u
.def
.value
;
7134 if ((my_offset
& 0x01) == 0x01)
7137 && sym_sec
->owner
!= NULL
7138 && !INTERWORK_FLAG (sym_sec
->owner
))
7140 (*_bfd_error_handler
)
7141 (_("%B(%s): warning: interworking not enabled.\n"
7142 " first occurrence: %B: arm call to thumb"),
7143 sym_sec
->owner
, input_bfd
, name
);
7147 myh
->root
.u
.def
.value
= my_offset
;
7149 if (info
->shared
|| globals
->root
.is_relocatable_executable
7150 || globals
->pic_veneer
)
7152 /* For relocatable objects we can't use absolute addresses,
7153 so construct the address from a relative offset. */
7154 /* TODO: If the offset is small it's probably worth
7155 constructing the address with adds. */
7156 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
7157 s
->contents
+ my_offset
);
7158 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
7159 s
->contents
+ my_offset
+ 4);
7160 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
7161 s
->contents
+ my_offset
+ 8);
7162 /* Adjust the offset by 4 for the position of the add,
7163 and 8 for the pipeline offset. */
7164 ret_offset
= (val
- (s
->output_offset
7165 + s
->output_section
->vma
7168 bfd_put_32 (output_bfd
, ret_offset
,
7169 s
->contents
+ my_offset
+ 12);
7171 else if (globals
->use_blx
)
7173 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
7174 s
->contents
+ my_offset
);
7176 /* It's a thumb address. Add the low order bit. */
7177 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
7178 s
->contents
+ my_offset
+ 4);
7182 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
7183 s
->contents
+ my_offset
);
7185 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
7186 s
->contents
+ my_offset
+ 4);
7188 /* It's a thumb address. Add the low order bit. */
7189 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
7190 s
->contents
+ my_offset
+ 8);
7196 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
7201 /* Arm code calling a Thumb function. */
7204 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
7208 asection
* input_section
,
7209 bfd_byte
* hit_data
,
7212 bfd_signed_vma addend
,
7214 char **error_message
)
7216 unsigned long int tmp
;
7219 long int ret_offset
;
7220 struct elf_link_hash_entry
* myh
;
7221 struct elf32_arm_link_hash_table
* globals
;
7223 globals
= elf32_arm_hash_table (info
);
7224 BFD_ASSERT (globals
!= NULL
);
7225 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7227 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7228 ARM2THUMB_GLUE_SECTION_NAME
);
7229 BFD_ASSERT (s
!= NULL
);
7230 BFD_ASSERT (s
->contents
!= NULL
);
7231 BFD_ASSERT (s
->output_section
!= NULL
);
7233 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
7234 sym_sec
, val
, s
, error_message
);
7238 my_offset
= myh
->root
.u
.def
.value
;
7239 tmp
= bfd_get_32 (input_bfd
, hit_data
);
7240 tmp
= tmp
& 0xFF000000;
7242 /* Somehow these are both 4 too far, so subtract 8. */
7243 ret_offset
= (s
->output_offset
7245 + s
->output_section
->vma
7246 - (input_section
->output_offset
7247 + input_section
->output_section
->vma
7251 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
7253 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
7258 /* Populate Arm stub for an exported Thumb function. */
7261 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
7263 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
7265 struct elf_link_hash_entry
* myh
;
7266 struct elf32_arm_link_hash_entry
*eh
;
7267 struct elf32_arm_link_hash_table
* globals
;
7270 char *error_message
;
7272 eh
= elf32_arm_hash_entry (h
);
7273 /* Allocate stubs for exported Thumb functions on v4t. */
7274 if (eh
->export_glue
== NULL
)
7277 globals
= elf32_arm_hash_table (info
);
7278 BFD_ASSERT (globals
!= NULL
);
7279 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7281 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7282 ARM2THUMB_GLUE_SECTION_NAME
);
7283 BFD_ASSERT (s
!= NULL
);
7284 BFD_ASSERT (s
->contents
!= NULL
);
7285 BFD_ASSERT (s
->output_section
!= NULL
);
7287 sec
= eh
->export_glue
->root
.u
.def
.section
;
7289 BFD_ASSERT (sec
->output_section
!= NULL
);
7291 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
7292 + sec
->output_section
->vma
;
7294 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
7295 h
->root
.u
.def
.section
->owner
,
7296 globals
->obfd
, sec
, val
, s
,
7302 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
7305 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
7310 struct elf32_arm_link_hash_table
*globals
;
7312 globals
= elf32_arm_hash_table (info
);
7313 BFD_ASSERT (globals
!= NULL
);
7314 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7316 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7317 ARM_BX_GLUE_SECTION_NAME
);
7318 BFD_ASSERT (s
!= NULL
);
7319 BFD_ASSERT (s
->contents
!= NULL
);
7320 BFD_ASSERT (s
->output_section
!= NULL
);
7322 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
7324 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
7326 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
7328 p
= s
->contents
+ glue_addr
;
7329 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
7330 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
7331 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
7332 globals
->bx_glue_offset
[reg
] |= 1;
7335 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
7338 /* Generate Arm stubs for exported Thumb symbols. */
7340 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
7341 struct bfd_link_info
*link_info
)
7343 struct elf32_arm_link_hash_table
* globals
;
7345 if (link_info
== NULL
)
7346 /* Ignore this if we are not called by the ELF backend linker. */
7349 globals
= elf32_arm_hash_table (link_info
);
7350 if (globals
== NULL
)
7353 /* If blx is available then exported Thumb symbols are OK and there is
7355 if (globals
->use_blx
)
7358 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
7362 /* Reserve space for COUNT dynamic relocations in relocation selection
7366 elf32_arm_allocate_dynrelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7367 bfd_size_type count
)
7369 struct elf32_arm_link_hash_table
*htab
;
7371 htab
= elf32_arm_hash_table (info
);
7372 BFD_ASSERT (htab
->root
.dynamic_sections_created
);
7375 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7378 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
7379 dynamic, the relocations should go in SRELOC, otherwise they should
7380 go in the special .rel.iplt section. */
7383 elf32_arm_allocate_irelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7384 bfd_size_type count
)
7386 struct elf32_arm_link_hash_table
*htab
;
7388 htab
= elf32_arm_hash_table (info
);
7389 if (!htab
->root
.dynamic_sections_created
)
7390 htab
->root
.irelplt
->size
+= RELOC_SIZE (htab
) * count
;
7393 BFD_ASSERT (sreloc
!= NULL
);
7394 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7398 /* Add relocation REL to the end of relocation section SRELOC. */
7401 elf32_arm_add_dynreloc (bfd
*output_bfd
, struct bfd_link_info
*info
,
7402 asection
*sreloc
, Elf_Internal_Rela
*rel
)
7405 struct elf32_arm_link_hash_table
*htab
;
7407 htab
= elf32_arm_hash_table (info
);
7408 if (!htab
->root
.dynamic_sections_created
7409 && ELF32_R_TYPE (rel
->r_info
) == R_ARM_IRELATIVE
)
7410 sreloc
= htab
->root
.irelplt
;
7413 loc
= sreloc
->contents
;
7414 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (htab
);
7415 if (sreloc
->reloc_count
* RELOC_SIZE (htab
) > sreloc
->size
)
7417 SWAP_RELOC_OUT (htab
) (output_bfd
, rel
, loc
);
7420 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
7421 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
7425 elf32_arm_allocate_plt_entry (struct bfd_link_info
*info
,
7426 bfd_boolean is_iplt_entry
,
7427 union gotplt_union
*root_plt
,
7428 struct arm_plt_info
*arm_plt
)
7430 struct elf32_arm_link_hash_table
*htab
;
7434 htab
= elf32_arm_hash_table (info
);
7438 splt
= htab
->root
.iplt
;
7439 sgotplt
= htab
->root
.igotplt
;
7441 /* NaCl uses a special first entry in .iplt too. */
7442 if (htab
->nacl_p
&& splt
->size
== 0)
7443 splt
->size
+= htab
->plt_header_size
;
7445 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
7446 elf32_arm_allocate_irelocs (info
, htab
->root
.irelplt
, 1);
7450 splt
= htab
->root
.splt
;
7451 sgotplt
= htab
->root
.sgotplt
;
7453 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
7454 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
7456 /* If this is the first .plt entry, make room for the special
7458 if (splt
->size
== 0)
7459 splt
->size
+= htab
->plt_header_size
;
7462 /* Allocate the PLT entry itself, including any leading Thumb stub. */
7463 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7464 splt
->size
+= PLT_THUMB_STUB_SIZE
;
7465 root_plt
->offset
= splt
->size
;
7466 splt
->size
+= htab
->plt_entry_size
;
7468 if (!htab
->symbian_p
)
7470 /* We also need to make an entry in the .got.plt section, which
7471 will be placed in the .got section by the linker script. */
7472 arm_plt
->got_offset
= sgotplt
->size
- 8 * htab
->num_tls_desc
;
7478 arm_movw_immediate (bfd_vma value
)
7480 return (value
& 0x00000fff) | ((value
& 0x0000f000) << 4);
7484 arm_movt_immediate (bfd_vma value
)
7486 return ((value
& 0x0fff0000) >> 16) | ((value
& 0xf0000000) >> 12);
7489 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
7490 the entry lives in .iplt and resolves to (*SYM_VALUE)().
7491 Otherwise, DYNINDX is the index of the symbol in the dynamic
7492 symbol table and SYM_VALUE is undefined.
7494 ROOT_PLT points to the offset of the PLT entry from the start of its
7495 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
7496 bookkeeping information.
7498 Returns FALSE if there was a problem. */
7501 elf32_arm_populate_plt_entry (bfd
*output_bfd
, struct bfd_link_info
*info
,
7502 union gotplt_union
*root_plt
,
7503 struct arm_plt_info
*arm_plt
,
7504 int dynindx
, bfd_vma sym_value
)
7506 struct elf32_arm_link_hash_table
*htab
;
7512 Elf_Internal_Rela rel
;
7513 bfd_vma plt_header_size
;
7514 bfd_vma got_header_size
;
7516 htab
= elf32_arm_hash_table (info
);
7518 /* Pick the appropriate sections and sizes. */
7521 splt
= htab
->root
.iplt
;
7522 sgot
= htab
->root
.igotplt
;
7523 srel
= htab
->root
.irelplt
;
7525 /* There are no reserved entries in .igot.plt, and no special
7526 first entry in .iplt. */
7527 got_header_size
= 0;
7528 plt_header_size
= 0;
7532 splt
= htab
->root
.splt
;
7533 sgot
= htab
->root
.sgotplt
;
7534 srel
= htab
->root
.srelplt
;
7536 got_header_size
= get_elf_backend_data (output_bfd
)->got_header_size
;
7537 plt_header_size
= htab
->plt_header_size
;
7539 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
7541 /* Fill in the entry in the procedure linkage table. */
7542 if (htab
->symbian_p
)
7544 BFD_ASSERT (dynindx
>= 0);
7545 put_arm_insn (htab
, output_bfd
,
7546 elf32_arm_symbian_plt_entry
[0],
7547 splt
->contents
+ root_plt
->offset
);
7548 bfd_put_32 (output_bfd
,
7549 elf32_arm_symbian_plt_entry
[1],
7550 splt
->contents
+ root_plt
->offset
+ 4);
7552 /* Fill in the entry in the .rel.plt section. */
7553 rel
.r_offset
= (splt
->output_section
->vma
7554 + splt
->output_offset
7555 + root_plt
->offset
+ 4);
7556 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_GLOB_DAT
);
7558 /* Get the index in the procedure linkage table which
7559 corresponds to this symbol. This is the index of this symbol
7560 in all the symbols for which we are making plt entries. The
7561 first entry in the procedure linkage table is reserved. */
7562 plt_index
= ((root_plt
->offset
- plt_header_size
)
7563 / htab
->plt_entry_size
);
7567 bfd_vma got_offset
, got_address
, plt_address
;
7568 bfd_vma got_displacement
, initial_got_entry
;
7571 BFD_ASSERT (sgot
!= NULL
);
7573 /* Get the offset into the .(i)got.plt table of the entry that
7574 corresponds to this function. */
7575 got_offset
= (arm_plt
->got_offset
& -2);
7577 /* Get the index in the procedure linkage table which
7578 corresponds to this symbol. This is the index of this symbol
7579 in all the symbols for which we are making plt entries.
7580 After the reserved .got.plt entries, all symbols appear in
7581 the same order as in .plt. */
7582 plt_index
= (got_offset
- got_header_size
) / 4;
7584 /* Calculate the address of the GOT entry. */
7585 got_address
= (sgot
->output_section
->vma
7586 + sgot
->output_offset
7589 /* ...and the address of the PLT entry. */
7590 plt_address
= (splt
->output_section
->vma
7591 + splt
->output_offset
7592 + root_plt
->offset
);
7594 ptr
= splt
->contents
+ root_plt
->offset
;
7595 if (htab
->vxworks_p
&& info
->shared
)
7600 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7602 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
7604 val
|= got_address
- sgot
->output_section
->vma
;
7606 val
|= plt_index
* RELOC_SIZE (htab
);
7607 if (i
== 2 || i
== 5)
7608 bfd_put_32 (output_bfd
, val
, ptr
);
7610 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7613 else if (htab
->vxworks_p
)
7618 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7620 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
7624 val
|= 0xffffff & -((root_plt
->offset
+ i
* 4 + 8) >> 2);
7626 val
|= plt_index
* RELOC_SIZE (htab
);
7627 if (i
== 2 || i
== 5)
7628 bfd_put_32 (output_bfd
, val
, ptr
);
7630 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7633 loc
= (htab
->srelplt2
->contents
7634 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
7636 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
7637 referencing the GOT for this PLT entry. */
7638 rel
.r_offset
= plt_address
+ 8;
7639 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
7640 rel
.r_addend
= got_offset
;
7641 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7642 loc
+= RELOC_SIZE (htab
);
7644 /* Create the R_ARM_ABS32 relocation referencing the
7645 beginning of the PLT for this GOT entry. */
7646 rel
.r_offset
= got_address
;
7647 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
7649 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7651 else if (htab
->nacl_p
)
7653 /* Calculate the displacement between the PLT slot and the
7654 common tail that's part of the special initial PLT slot. */
7655 int32_t tail_displacement
7656 = ((splt
->output_section
->vma
+ splt
->output_offset
7657 + ARM_NACL_PLT_TAIL_OFFSET
)
7658 - (plt_address
+ htab
->plt_entry_size
+ 4));
7659 BFD_ASSERT ((tail_displacement
& 3) == 0);
7660 tail_displacement
>>= 2;
7662 BFD_ASSERT ((tail_displacement
& 0xff000000) == 0
7663 || (-tail_displacement
& 0xff000000) == 0);
7665 /* Calculate the displacement between the PLT slot and the entry
7666 in the GOT. The offset accounts for the value produced by
7667 adding to pc in the penultimate instruction of the PLT stub. */
7668 got_displacement
= (got_address
7669 - (plt_address
+ htab
->plt_entry_size
));
7671 /* NaCl does not support interworking at all. */
7672 BFD_ASSERT (!elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
));
7674 put_arm_insn (htab
, output_bfd
,
7675 elf32_arm_nacl_plt_entry
[0]
7676 | arm_movw_immediate (got_displacement
),
7678 put_arm_insn (htab
, output_bfd
,
7679 elf32_arm_nacl_plt_entry
[1]
7680 | arm_movt_immediate (got_displacement
),
7682 put_arm_insn (htab
, output_bfd
,
7683 elf32_arm_nacl_plt_entry
[2],
7685 put_arm_insn (htab
, output_bfd
,
7686 elf32_arm_nacl_plt_entry
[3]
7687 | (tail_displacement
& 0x00ffffff),
7690 else if (using_thumb_only (htab
))
7692 /* PR ld/16017: Do not generate ARM instructions for
7693 the PLT if compiling for a thumb-only target.
7695 FIXME: We ought to be able to generate thumb PLT instructions... */
7696 _bfd_error_handler (_("%B: Warning: thumb mode PLT generation not currently supported"),
7702 /* Calculate the displacement between the PLT slot and the
7703 entry in the GOT. The eight-byte offset accounts for the
7704 value produced by adding to pc in the first instruction
7706 got_displacement
= got_address
- (plt_address
+ 8);
7708 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
7710 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7712 put_thumb_insn (htab
, output_bfd
,
7713 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
7714 put_thumb_insn (htab
, output_bfd
,
7715 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
7718 put_arm_insn (htab
, output_bfd
,
7719 elf32_arm_plt_entry
[0]
7720 | ((got_displacement
& 0x0ff00000) >> 20),
7722 put_arm_insn (htab
, output_bfd
,
7723 elf32_arm_plt_entry
[1]
7724 | ((got_displacement
& 0x000ff000) >> 12),
7726 put_arm_insn (htab
, output_bfd
,
7727 elf32_arm_plt_entry
[2]
7728 | (got_displacement
& 0x00000fff),
7730 #ifdef FOUR_WORD_PLT
7731 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
7735 /* Fill in the entry in the .rel(a).(i)plt section. */
7736 rel
.r_offset
= got_address
;
7740 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
7741 The dynamic linker or static executable then calls SYM_VALUE
7742 to determine the correct run-time value of the .igot.plt entry. */
7743 rel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
7744 initial_got_entry
= sym_value
;
7748 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_JUMP_SLOT
);
7749 initial_got_entry
= (splt
->output_section
->vma
7750 + splt
->output_offset
);
7753 /* Fill in the entry in the global offset table. */
7754 bfd_put_32 (output_bfd
, initial_got_entry
,
7755 sgot
->contents
+ got_offset
);
7759 elf32_arm_add_dynreloc (output_bfd
, info
, srel
, &rel
);
7762 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
7763 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7769 /* Some relocations map to different relocations depending on the
7770 target. Return the real relocation. */
7773 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
7779 if (globals
->target1_is_rel
)
7785 return globals
->target2_reloc
;
7792 /* Return the base VMA address which should be subtracted from real addresses
7793 when resolving @dtpoff relocation.
7794 This is PT_TLS segment p_vaddr. */
7797 dtpoff_base (struct bfd_link_info
*info
)
7799 /* If tls_sec is NULL, we should have signalled an error already. */
7800 if (elf_hash_table (info
)->tls_sec
== NULL
)
7802 return elf_hash_table (info
)->tls_sec
->vma
;
7805 /* Return the relocation value for @tpoff relocation
7806 if STT_TLS virtual address is ADDRESS. */
7809 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
7811 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7814 /* If tls_sec is NULL, we should have signalled an error already. */
7815 if (htab
->tls_sec
== NULL
)
7817 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
7818 return address
- htab
->tls_sec
->vma
+ base
;
7821 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
7822 VALUE is the relocation value. */
7824 static bfd_reloc_status_type
7825 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
7828 return bfd_reloc_overflow
;
7830 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
7831 bfd_put_32 (abfd
, value
, data
);
7832 return bfd_reloc_ok
;
7835 /* Handle TLS relaxations. Relaxing is possible for symbols that use
7836 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
7837 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
7839 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
7840 is to then call final_link_relocate. Return other values in the
7843 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
7844 the pre-relaxed code. It would be nice if the relocs were updated
7845 to match the optimization. */
7847 static bfd_reloc_status_type
7848 elf32_arm_tls_relax (struct elf32_arm_link_hash_table
*globals
,
7849 bfd
*input_bfd
, asection
*input_sec
, bfd_byte
*contents
,
7850 Elf_Internal_Rela
*rel
, unsigned long is_local
)
7854 switch (ELF32_R_TYPE (rel
->r_info
))
7857 return bfd_reloc_notsupported
;
7859 case R_ARM_TLS_GOTDESC
:
7864 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7866 insn
-= 5; /* THUMB */
7868 insn
-= 8; /* ARM */
7870 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7871 return bfd_reloc_continue
;
7873 case R_ARM_THM_TLS_DESCSEQ
:
7875 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
7876 if ((insn
& 0xff78) == 0x4478) /* add rx, pc */
7880 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7882 else if ((insn
& 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
7886 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7889 bfd_put_16 (input_bfd
, insn
& 0xf83f, contents
+ rel
->r_offset
);
7891 else if ((insn
& 0xff87) == 0x4780) /* blx rx */
7895 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7898 bfd_put_16 (input_bfd
, 0x4600 | (insn
& 0x78),
7899 contents
+ rel
->r_offset
);
7903 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
7904 /* It's a 32 bit instruction, fetch the rest of it for
7905 error generation. */
7907 | bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
7908 (*_bfd_error_handler
)
7909 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' in TLS trampoline"),
7910 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
7911 return bfd_reloc_notsupported
;
7915 case R_ARM_TLS_DESCSEQ
:
7917 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7918 if ((insn
& 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
7922 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xffff),
7923 contents
+ rel
->r_offset
);
7925 else if ((insn
& 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
7929 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
7932 bfd_put_32 (input_bfd
, insn
& 0xfffff000,
7933 contents
+ rel
->r_offset
);
7935 else if ((insn
& 0xfffffff0) == 0xe12fff30) /* blx rx */
7939 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
7942 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xf),
7943 contents
+ rel
->r_offset
);
7947 (*_bfd_error_handler
)
7948 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' in TLS trampoline"),
7949 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
7950 return bfd_reloc_notsupported
;
7954 case R_ARM_TLS_CALL
:
7955 /* GD->IE relaxation, turn the instruction into 'nop' or
7956 'ldr r0, [pc,r0]' */
7957 insn
= is_local
? 0xe1a00000 : 0xe79f0000;
7958 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7961 case R_ARM_THM_TLS_CALL
:
7962 /* GD->IE relaxation */
7964 /* add r0,pc; ldr r0, [r0] */
7966 else if (arch_has_thumb2_nop (globals
))
7973 bfd_put_16 (input_bfd
, insn
>> 16, contents
+ rel
->r_offset
);
7974 bfd_put_16 (input_bfd
, insn
& 0xffff, contents
+ rel
->r_offset
+ 2);
7977 return bfd_reloc_ok
;
7980 /* For a given value of n, calculate the value of G_n as required to
7981 deal with group relocations. We return it in the form of an
7982 encoded constant-and-rotation, together with the final residual. If n is
7983 specified as less than zero, then final_residual is filled with the
7984 input value and no further action is performed. */
7987 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
7991 bfd_vma encoded_g_n
= 0;
7992 bfd_vma residual
= value
; /* Also known as Y_n. */
7994 for (current_n
= 0; current_n
<= n
; current_n
++)
7998 /* Calculate which part of the value to mask. */
8005 /* Determine the most significant bit in the residual and
8006 align the resulting value to a 2-bit boundary. */
8007 for (msb
= 30; msb
>= 0; msb
-= 2)
8008 if (residual
& (3 << msb
))
8011 /* The desired shift is now (msb - 6), or zero, whichever
8018 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
8019 g_n
= residual
& (0xff << shift
);
8020 encoded_g_n
= (g_n
>> shift
)
8021 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
8023 /* Calculate the residual for the next time around. */
8027 *final_residual
= residual
;
8032 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
8033 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
8036 identify_add_or_sub (bfd_vma insn
)
8038 int opcode
= insn
& 0x1e00000;
8040 if (opcode
== 1 << 23) /* ADD */
8043 if (opcode
== 1 << 22) /* SUB */
8049 /* Perform a relocation as part of a final link. */
8051 static bfd_reloc_status_type
8052 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
8055 asection
* input_section
,
8056 bfd_byte
* contents
,
8057 Elf_Internal_Rela
* rel
,
8059 struct bfd_link_info
* info
,
8061 const char * sym_name
,
8062 unsigned char st_type
,
8063 enum arm_st_branch_type branch_type
,
8064 struct elf_link_hash_entry
* h
,
8065 bfd_boolean
* unresolved_reloc_p
,
8066 char ** error_message
)
8068 unsigned long r_type
= howto
->type
;
8069 unsigned long r_symndx
;
8070 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
8071 bfd_vma
* local_got_offsets
;
8072 bfd_vma
* local_tlsdesc_gotents
;
8075 asection
* sreloc
= NULL
;
8078 bfd_signed_vma signed_addend
;
8079 unsigned char dynreloc_st_type
;
8080 bfd_vma dynreloc_value
;
8081 struct elf32_arm_link_hash_table
* globals
;
8082 struct elf32_arm_link_hash_entry
*eh
;
8083 union gotplt_union
*root_plt
;
8084 struct arm_plt_info
*arm_plt
;
8086 bfd_vma gotplt_offset
;
8087 bfd_boolean has_iplt_entry
;
8089 globals
= elf32_arm_hash_table (info
);
8090 if (globals
== NULL
)
8091 return bfd_reloc_notsupported
;
8093 BFD_ASSERT (is_arm_elf (input_bfd
));
8095 /* Some relocation types map to different relocations depending on the
8096 target. We pick the right one here. */
8097 r_type
= arm_real_reloc_type (globals
, r_type
);
8099 /* It is possible to have linker relaxations on some TLS access
8100 models. Update our information here. */
8101 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
8103 if (r_type
!= howto
->type
)
8104 howto
= elf32_arm_howto_from_type (r_type
);
8106 /* If the start address has been set, then set the EF_ARM_HASENTRY
8107 flag. Setting this more than once is redundant, but the cost is
8108 not too high, and it keeps the code simple.
8110 The test is done here, rather than somewhere else, because the
8111 start address is only set just before the final link commences.
8113 Note - if the user deliberately sets a start address of 0, the
8114 flag will not be set. */
8115 if (bfd_get_start_address (output_bfd
) != 0)
8116 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
8118 eh
= (struct elf32_arm_link_hash_entry
*) h
;
8119 sgot
= globals
->root
.sgot
;
8120 local_got_offsets
= elf_local_got_offsets (input_bfd
);
8121 local_tlsdesc_gotents
= elf32_arm_local_tlsdesc_gotent (input_bfd
);
8123 if (globals
->root
.dynamic_sections_created
)
8124 srelgot
= globals
->root
.srelgot
;
8128 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8130 if (globals
->use_rel
)
8132 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
8134 if (addend
& ((howto
->src_mask
+ 1) >> 1))
8137 signed_addend
&= ~ howto
->src_mask
;
8138 signed_addend
|= addend
;
8141 signed_addend
= addend
;
8144 addend
= signed_addend
= rel
->r_addend
;
8146 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
8147 are resolving a function call relocation. */
8148 if (using_thumb_only (globals
)
8149 && (r_type
== R_ARM_THM_CALL
8150 || r_type
== R_ARM_THM_JUMP24
)
8151 && branch_type
== ST_BRANCH_TO_ARM
)
8152 branch_type
= ST_BRANCH_TO_THUMB
;
8154 /* Record the symbol information that should be used in dynamic
8156 dynreloc_st_type
= st_type
;
8157 dynreloc_value
= value
;
8158 if (branch_type
== ST_BRANCH_TO_THUMB
)
8159 dynreloc_value
|= 1;
8161 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
8162 VALUE appropriately for relocations that we resolve at link time. */
8163 has_iplt_entry
= FALSE
;
8164 if (elf32_arm_get_plt_info (input_bfd
, eh
, r_symndx
, &root_plt
, &arm_plt
)
8165 && root_plt
->offset
!= (bfd_vma
) -1)
8167 plt_offset
= root_plt
->offset
;
8168 gotplt_offset
= arm_plt
->got_offset
;
8170 if (h
== NULL
|| eh
->is_iplt
)
8172 has_iplt_entry
= TRUE
;
8173 splt
= globals
->root
.iplt
;
8175 /* Populate .iplt entries here, because not all of them will
8176 be seen by finish_dynamic_symbol. The lower bit is set if
8177 we have already populated the entry. */
8182 if (elf32_arm_populate_plt_entry (output_bfd
, info
, root_plt
, arm_plt
,
8183 -1, dynreloc_value
))
8184 root_plt
->offset
|= 1;
8186 return bfd_reloc_notsupported
;
8189 /* Static relocations always resolve to the .iplt entry. */
8191 value
= (splt
->output_section
->vma
8192 + splt
->output_offset
8194 branch_type
= ST_BRANCH_TO_ARM
;
8196 /* If there are non-call relocations that resolve to the .iplt
8197 entry, then all dynamic ones must too. */
8198 if (arm_plt
->noncall_refcount
!= 0)
8200 dynreloc_st_type
= st_type
;
8201 dynreloc_value
= value
;
8205 /* We populate the .plt entry in finish_dynamic_symbol. */
8206 splt
= globals
->root
.splt
;
8211 plt_offset
= (bfd_vma
) -1;
8212 gotplt_offset
= (bfd_vma
) -1;
8218 /* We don't need to find a value for this symbol. It's just a
8220 *unresolved_reloc_p
= FALSE
;
8221 return bfd_reloc_ok
;
8224 if (!globals
->vxworks_p
)
8225 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
8229 case R_ARM_ABS32_NOI
:
8231 case R_ARM_REL32_NOI
:
8237 /* Handle relocations which should use the PLT entry. ABS32/REL32
8238 will use the symbol's value, which may point to a PLT entry, but we
8239 don't need to handle that here. If we created a PLT entry, all
8240 branches in this object should go to it, except if the PLT is too
8241 far away, in which case a long branch stub should be inserted. */
8242 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
8243 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
8244 && r_type
!= R_ARM_CALL
8245 && r_type
!= R_ARM_JUMP24
8246 && r_type
!= R_ARM_PLT32
)
8247 && plt_offset
!= (bfd_vma
) -1)
8249 /* If we've created a .plt section, and assigned a PLT entry
8250 to this function, it must either be a STT_GNU_IFUNC reference
8251 or not be known to bind locally. In other cases, we should
8252 have cleared the PLT entry by now. */
8253 BFD_ASSERT (has_iplt_entry
|| !SYMBOL_CALLS_LOCAL (info
, h
));
8255 value
= (splt
->output_section
->vma
8256 + splt
->output_offset
8258 *unresolved_reloc_p
= FALSE
;
8259 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8260 contents
, rel
->r_offset
, value
,
8264 /* When generating a shared object or relocatable executable, these
8265 relocations are copied into the output file to be resolved at
8267 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
8268 && (input_section
->flags
& SEC_ALLOC
)
8269 && !(globals
->vxworks_p
8270 && strcmp (input_section
->output_section
->name
,
8272 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
8273 || !SYMBOL_CALLS_LOCAL (info
, h
))
8274 && !(input_bfd
== globals
->stub_bfd
8275 && strstr (input_section
->name
, STUB_SUFFIX
))
8277 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8278 || h
->root
.type
!= bfd_link_hash_undefweak
)
8279 && r_type
!= R_ARM_PC24
8280 && r_type
!= R_ARM_CALL
8281 && r_type
!= R_ARM_JUMP24
8282 && r_type
!= R_ARM_PREL31
8283 && r_type
!= R_ARM_PLT32
)
8285 Elf_Internal_Rela outrel
;
8286 bfd_boolean skip
, relocate
;
8288 *unresolved_reloc_p
= FALSE
;
8290 if (sreloc
== NULL
&& globals
->root
.dynamic_sections_created
)
8292 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
8293 ! globals
->use_rel
);
8296 return bfd_reloc_notsupported
;
8302 outrel
.r_addend
= addend
;
8304 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
8306 if (outrel
.r_offset
== (bfd_vma
) -1)
8308 else if (outrel
.r_offset
== (bfd_vma
) -2)
8309 skip
= TRUE
, relocate
= TRUE
;
8310 outrel
.r_offset
+= (input_section
->output_section
->vma
8311 + input_section
->output_offset
);
8314 memset (&outrel
, 0, sizeof outrel
);
8319 || !h
->def_regular
))
8320 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
8325 /* This symbol is local, or marked to become local. */
8326 BFD_ASSERT (r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
);
8327 if (globals
->symbian_p
)
8331 /* On Symbian OS, the data segment and text segement
8332 can be relocated independently. Therefore, we
8333 must indicate the segment to which this
8334 relocation is relative. The BPABI allows us to
8335 use any symbol in the right segment; we just use
8336 the section symbol as it is convenient. (We
8337 cannot use the symbol given by "h" directly as it
8338 will not appear in the dynamic symbol table.)
8340 Note that the dynamic linker ignores the section
8341 symbol value, so we don't subtract osec->vma
8342 from the emitted reloc addend. */
8344 osec
= sym_sec
->output_section
;
8346 osec
= input_section
->output_section
;
8347 symbol
= elf_section_data (osec
)->dynindx
;
8350 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8352 if ((osec
->flags
& SEC_READONLY
) == 0
8353 && htab
->data_index_section
!= NULL
)
8354 osec
= htab
->data_index_section
;
8356 osec
= htab
->text_index_section
;
8357 symbol
= elf_section_data (osec
)->dynindx
;
8359 BFD_ASSERT (symbol
!= 0);
8362 /* On SVR4-ish systems, the dynamic loader cannot
8363 relocate the text and data segments independently,
8364 so the symbol does not matter. */
8366 if (dynreloc_st_type
== STT_GNU_IFUNC
)
8367 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
8368 to the .iplt entry. Instead, every non-call reference
8369 must use an R_ARM_IRELATIVE relocation to obtain the
8370 correct run-time address. */
8371 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_IRELATIVE
);
8373 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
8374 if (globals
->use_rel
)
8377 outrel
.r_addend
+= dynreloc_value
;
8380 elf32_arm_add_dynreloc (output_bfd
, info
, sreloc
, &outrel
);
8382 /* If this reloc is against an external symbol, we do not want to
8383 fiddle with the addend. Otherwise, we need to include the symbol
8384 value so that it becomes an addend for the dynamic reloc. */
8386 return bfd_reloc_ok
;
8388 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8389 contents
, rel
->r_offset
,
8390 dynreloc_value
, (bfd_vma
) 0);
8392 else switch (r_type
)
8395 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
8397 case R_ARM_XPC25
: /* Arm BLX instruction. */
8400 case R_ARM_PC24
: /* Arm B/BL instruction. */
8403 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
8405 if (r_type
== R_ARM_XPC25
)
8407 /* Check for Arm calling Arm function. */
8408 /* FIXME: Should we translate the instruction into a BL
8409 instruction instead ? */
8410 if (branch_type
!= ST_BRANCH_TO_THUMB
)
8411 (*_bfd_error_handler
)
8412 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
8414 h
? h
->root
.root
.string
: "(local)");
8416 else if (r_type
== R_ARM_PC24
)
8418 /* Check for Arm calling Thumb function. */
8419 if (branch_type
== ST_BRANCH_TO_THUMB
)
8421 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
8422 output_bfd
, input_section
,
8423 hit_data
, sym_sec
, rel
->r_offset
,
8424 signed_addend
, value
,
8426 return bfd_reloc_ok
;
8428 return bfd_reloc_dangerous
;
8432 /* Check if a stub has to be inserted because the
8433 destination is too far or we are changing mode. */
8434 if ( r_type
== R_ARM_CALL
8435 || r_type
== R_ARM_JUMP24
8436 || r_type
== R_ARM_PLT32
)
8438 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8439 struct elf32_arm_link_hash_entry
*hash
;
8441 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8442 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8443 st_type
, &branch_type
,
8444 hash
, value
, sym_sec
,
8445 input_bfd
, sym_name
);
8447 if (stub_type
!= arm_stub_none
)
8449 /* The target is out of reach, so redirect the
8450 branch to the local stub for this function. */
8451 stub_entry
= elf32_arm_get_stub_entry (input_section
,
8456 if (stub_entry
!= NULL
)
8457 value
= (stub_entry
->stub_offset
8458 + stub_entry
->stub_sec
->output_offset
8459 + stub_entry
->stub_sec
->output_section
->vma
);
8461 if (plt_offset
!= (bfd_vma
) -1)
8462 *unresolved_reloc_p
= FALSE
;
8467 /* If the call goes through a PLT entry, make sure to
8468 check distance to the right destination address. */
8469 if (plt_offset
!= (bfd_vma
) -1)
8471 value
= (splt
->output_section
->vma
8472 + splt
->output_offset
8474 *unresolved_reloc_p
= FALSE
;
8475 /* The PLT entry is in ARM mode, regardless of the
8477 branch_type
= ST_BRANCH_TO_ARM
;
8482 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
8484 S is the address of the symbol in the relocation.
8485 P is address of the instruction being relocated.
8486 A is the addend (extracted from the instruction) in bytes.
8488 S is held in 'value'.
8489 P is the base address of the section containing the
8490 instruction plus the offset of the reloc into that
8492 (input_section->output_section->vma +
8493 input_section->output_offset +
8495 A is the addend, converted into bytes, ie:
8498 Note: None of these operations have knowledge of the pipeline
8499 size of the processor, thus it is up to the assembler to
8500 encode this information into the addend. */
8501 value
-= (input_section
->output_section
->vma
8502 + input_section
->output_offset
);
8503 value
-= rel
->r_offset
;
8504 if (globals
->use_rel
)
8505 value
+= (signed_addend
<< howto
->size
);
8507 /* RELA addends do not have to be adjusted by howto->size. */
8508 value
+= signed_addend
;
8510 signed_addend
= value
;
8511 signed_addend
>>= howto
->rightshift
;
8513 /* A branch to an undefined weak symbol is turned into a jump to
8514 the next instruction unless a PLT entry will be created.
8515 Do the same for local undefined symbols (but not for STN_UNDEF).
8516 The jump to the next instruction is optimized as a NOP depending
8517 on the architecture. */
8518 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
8519 && plt_offset
== (bfd_vma
) -1)
8520 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sym_sec
))
8522 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000);
8524 if (arch_has_arm_nop (globals
))
8525 value
|= 0x0320f000;
8527 value
|= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
8531 /* Perform a signed range check. */
8532 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
8533 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
8534 return bfd_reloc_overflow
;
8536 addend
= (value
& 2);
8538 value
= (signed_addend
& howto
->dst_mask
)
8539 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
8541 if (r_type
== R_ARM_CALL
)
8543 /* Set the H bit in the BLX instruction. */
8544 if (branch_type
== ST_BRANCH_TO_THUMB
)
8549 value
&= ~(bfd_vma
)(1 << 24);
8552 /* Select the correct instruction (BL or BLX). */
8553 /* Only if we are not handling a BL to a stub. In this
8554 case, mode switching is performed by the stub. */
8555 if (branch_type
== ST_BRANCH_TO_THUMB
&& !stub_entry
)
8557 else if (stub_entry
|| branch_type
!= ST_BRANCH_UNKNOWN
)
8559 value
&= ~(bfd_vma
)(1 << 28);
8569 if (branch_type
== ST_BRANCH_TO_THUMB
)
8573 case R_ARM_ABS32_NOI
:
8579 if (branch_type
== ST_BRANCH_TO_THUMB
)
8581 value
-= (input_section
->output_section
->vma
8582 + input_section
->output_offset
+ rel
->r_offset
);
8585 case R_ARM_REL32_NOI
:
8587 value
-= (input_section
->output_section
->vma
8588 + input_section
->output_offset
+ rel
->r_offset
);
8592 value
-= (input_section
->output_section
->vma
8593 + input_section
->output_offset
+ rel
->r_offset
);
8594 value
+= signed_addend
;
8595 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
8597 /* Check for overflow. */
8598 if ((value
^ (value
>> 1)) & (1 << 30))
8599 return bfd_reloc_overflow
;
8601 value
&= 0x7fffffff;
8602 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
8603 if (branch_type
== ST_BRANCH_TO_THUMB
)
8608 bfd_put_32 (input_bfd
, value
, hit_data
);
8609 return bfd_reloc_ok
;
8614 /* There is no way to tell whether the user intended to use a signed or
8615 unsigned addend. When checking for overflow we accept either,
8616 as specified by the AAELF. */
8617 if ((long) value
> 0xff || (long) value
< -0x80)
8618 return bfd_reloc_overflow
;
8620 bfd_put_8 (input_bfd
, value
, hit_data
);
8621 return bfd_reloc_ok
;
8626 /* See comment for R_ARM_ABS8. */
8627 if ((long) value
> 0xffff || (long) value
< -0x8000)
8628 return bfd_reloc_overflow
;
8630 bfd_put_16 (input_bfd
, value
, hit_data
);
8631 return bfd_reloc_ok
;
8633 case R_ARM_THM_ABS5
:
8634 /* Support ldr and str instructions for the thumb. */
8635 if (globals
->use_rel
)
8637 /* Need to refetch addend. */
8638 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
8639 /* ??? Need to determine shift amount from operand size. */
8640 addend
>>= howto
->rightshift
;
8644 /* ??? Isn't value unsigned? */
8645 if ((long) value
> 0x1f || (long) value
< -0x10)
8646 return bfd_reloc_overflow
;
8648 /* ??? Value needs to be properly shifted into place first. */
8649 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
8650 bfd_put_16 (input_bfd
, value
, hit_data
);
8651 return bfd_reloc_ok
;
8653 case R_ARM_THM_ALU_PREL_11_0
:
8654 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
8657 bfd_signed_vma relocation
;
8659 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8660 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8662 if (globals
->use_rel
)
8664 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
8665 | ((insn
& (1 << 26)) >> 15);
8666 if (insn
& 0xf00000)
8667 signed_addend
= -signed_addend
;
8670 relocation
= value
+ signed_addend
;
8671 relocation
-= Pa (input_section
->output_section
->vma
8672 + input_section
->output_offset
8675 value
= abs (relocation
);
8677 if (value
>= 0x1000)
8678 return bfd_reloc_overflow
;
8680 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
8681 | ((value
& 0x700) << 4)
8682 | ((value
& 0x800) << 15);
8686 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8687 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8689 return bfd_reloc_ok
;
8693 /* PR 10073: This reloc is not generated by the GNU toolchain,
8694 but it is supported for compatibility with third party libraries
8695 generated by other compilers, specifically the ARM/IAR. */
8698 bfd_signed_vma relocation
;
8700 insn
= bfd_get_16 (input_bfd
, hit_data
);
8702 if (globals
->use_rel
)
8703 addend
= ((((insn
& 0x00ff) << 2) + 4) & 0x3ff) -4;
8705 relocation
= value
+ addend
;
8706 relocation
-= Pa (input_section
->output_section
->vma
8707 + input_section
->output_offset
8710 value
= abs (relocation
);
8712 /* We do not check for overflow of this reloc. Although strictly
8713 speaking this is incorrect, it appears to be necessary in order
8714 to work with IAR generated relocs. Since GCC and GAS do not
8715 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
8716 a problem for them. */
8719 insn
= (insn
& 0xff00) | (value
>> 2);
8721 bfd_put_16 (input_bfd
, insn
, hit_data
);
8723 return bfd_reloc_ok
;
8726 case R_ARM_THM_PC12
:
8727 /* Corresponds to: ldr.w reg, [pc, #offset]. */
8730 bfd_signed_vma relocation
;
8732 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8733 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8735 if (globals
->use_rel
)
8737 signed_addend
= insn
& 0xfff;
8738 if (!(insn
& (1 << 23)))
8739 signed_addend
= -signed_addend
;
8742 relocation
= value
+ signed_addend
;
8743 relocation
-= Pa (input_section
->output_section
->vma
8744 + input_section
->output_offset
8747 value
= abs (relocation
);
8749 if (value
>= 0x1000)
8750 return bfd_reloc_overflow
;
8752 insn
= (insn
& 0xff7ff000) | value
;
8753 if (relocation
>= 0)
8756 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8757 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8759 return bfd_reloc_ok
;
8762 case R_ARM_THM_XPC22
:
8763 case R_ARM_THM_CALL
:
8764 case R_ARM_THM_JUMP24
:
8765 /* Thumb BL (branch long instruction). */
8769 bfd_boolean overflow
= FALSE
;
8770 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
8771 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
8772 bfd_signed_vma reloc_signed_max
;
8773 bfd_signed_vma reloc_signed_min
;
8775 bfd_signed_vma signed_check
;
8777 const int thumb2
= using_thumb2 (globals
);
8779 /* A branch to an undefined weak symbol is turned into a jump to
8780 the next instruction unless a PLT entry will be created.
8781 The jump to the next instruction is optimized as a NOP.W for
8782 Thumb-2 enabled architectures. */
8783 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
8784 && plt_offset
== (bfd_vma
) -1)
8786 if (arch_has_thumb2_nop (globals
))
8788 bfd_put_16 (input_bfd
, 0xf3af, hit_data
);
8789 bfd_put_16 (input_bfd
, 0x8000, hit_data
+ 2);
8793 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
8794 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
8796 return bfd_reloc_ok
;
8799 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
8800 with Thumb-1) involving the J1 and J2 bits. */
8801 if (globals
->use_rel
)
8803 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
8804 bfd_vma upper
= upper_insn
& 0x3ff;
8805 bfd_vma lower
= lower_insn
& 0x7ff;
8806 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
8807 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
8808 bfd_vma i1
= j1
^ s
? 0 : 1;
8809 bfd_vma i2
= j2
^ s
? 0 : 1;
8811 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
8813 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
8815 signed_addend
= addend
;
8818 if (r_type
== R_ARM_THM_XPC22
)
8820 /* Check for Thumb to Thumb call. */
8821 /* FIXME: Should we translate the instruction into a BL
8822 instruction instead ? */
8823 if (branch_type
== ST_BRANCH_TO_THUMB
)
8824 (*_bfd_error_handler
)
8825 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
8827 h
? h
->root
.root
.string
: "(local)");
8831 /* If it is not a call to Thumb, assume call to Arm.
8832 If it is a call relative to a section name, then it is not a
8833 function call at all, but rather a long jump. Calls through
8834 the PLT do not require stubs. */
8835 if (branch_type
== ST_BRANCH_TO_ARM
&& plt_offset
== (bfd_vma
) -1)
8837 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
8839 /* Convert BL to BLX. */
8840 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8842 else if (( r_type
!= R_ARM_THM_CALL
)
8843 && (r_type
!= R_ARM_THM_JUMP24
))
8845 if (elf32_thumb_to_arm_stub
8846 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
8847 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
8849 return bfd_reloc_ok
;
8851 return bfd_reloc_dangerous
;
8854 else if (branch_type
== ST_BRANCH_TO_THUMB
8856 && r_type
== R_ARM_THM_CALL
)
8858 /* Make sure this is a BL. */
8859 lower_insn
|= 0x1800;
8863 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8864 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
8866 /* Check if a stub has to be inserted because the destination
8868 struct elf32_arm_stub_hash_entry
*stub_entry
;
8869 struct elf32_arm_link_hash_entry
*hash
;
8871 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8873 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8874 st_type
, &branch_type
,
8875 hash
, value
, sym_sec
,
8876 input_bfd
, sym_name
);
8878 if (stub_type
!= arm_stub_none
)
8880 /* The target is out of reach or we are changing modes, so
8881 redirect the branch to the local stub for this
8883 stub_entry
= elf32_arm_get_stub_entry (input_section
,
8887 if (stub_entry
!= NULL
)
8889 value
= (stub_entry
->stub_offset
8890 + stub_entry
->stub_sec
->output_offset
8891 + stub_entry
->stub_sec
->output_section
->vma
);
8893 if (plt_offset
!= (bfd_vma
) -1)
8894 *unresolved_reloc_p
= FALSE
;
8897 /* If this call becomes a call to Arm, force BLX. */
8898 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
8901 && !arm_stub_is_thumb (stub_entry
->stub_type
))
8902 || branch_type
!= ST_BRANCH_TO_THUMB
)
8903 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8908 /* Handle calls via the PLT. */
8909 if (stub_type
== arm_stub_none
&& plt_offset
!= (bfd_vma
) -1)
8911 value
= (splt
->output_section
->vma
8912 + splt
->output_offset
8915 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
8917 /* If the Thumb BLX instruction is available, convert
8918 the BL to a BLX instruction to call the ARM-mode
8920 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8921 branch_type
= ST_BRANCH_TO_ARM
;
8925 /* Target the Thumb stub before the ARM PLT entry. */
8926 value
-= PLT_THUMB_STUB_SIZE
;
8927 branch_type
= ST_BRANCH_TO_THUMB
;
8929 *unresolved_reloc_p
= FALSE
;
8932 relocation
= value
+ signed_addend
;
8934 relocation
-= (input_section
->output_section
->vma
8935 + input_section
->output_offset
8938 check
= relocation
>> howto
->rightshift
;
8940 /* If this is a signed value, the rightshift just dropped
8941 leading 1 bits (assuming twos complement). */
8942 if ((bfd_signed_vma
) relocation
>= 0)
8943 signed_check
= check
;
8945 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
8947 /* Calculate the permissable maximum and minimum values for
8948 this relocation according to whether we're relocating for
8950 bitsize
= howto
->bitsize
;
8953 reloc_signed_max
= (1 << (bitsize
- 1)) - 1;
8954 reloc_signed_min
= ~reloc_signed_max
;
8956 /* Assumes two's complement. */
8957 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
8960 if ((lower_insn
& 0x5000) == 0x4000)
8961 /* For a BLX instruction, make sure that the relocation is rounded up
8962 to a word boundary. This follows the semantics of the instruction
8963 which specifies that bit 1 of the target address will come from bit
8964 1 of the base address. */
8965 relocation
= (relocation
+ 2) & ~ 3;
8967 /* Put RELOCATION back into the insn. Assumes two's complement.
8968 We use the Thumb-2 encoding, which is safe even if dealing with
8969 a Thumb-1 instruction by virtue of our overflow check above. */
8970 reloc_sign
= (signed_check
< 0) ? 1 : 0;
8971 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
8972 | ((relocation
>> 12) & 0x3ff)
8973 | (reloc_sign
<< 10);
8974 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
8975 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
8976 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
8977 | ((relocation
>> 1) & 0x7ff);
8979 /* Put the relocated value back in the object file: */
8980 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
8981 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
8983 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
8987 case R_ARM_THM_JUMP19
:
8988 /* Thumb32 conditional branch instruction. */
8991 bfd_boolean overflow
= FALSE
;
8992 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
8993 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
8994 bfd_signed_vma reloc_signed_max
= 0xffffe;
8995 bfd_signed_vma reloc_signed_min
= -0x100000;
8996 bfd_signed_vma signed_check
;
8998 /* Need to refetch the addend, reconstruct the top three bits,
8999 and squish the two 11 bit pieces together. */
9000 if (globals
->use_rel
)
9002 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
9003 bfd_vma upper
= (upper_insn
& 0x003f);
9004 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
9005 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
9006 bfd_vma lower
= (lower_insn
& 0x07ff);
9011 upper
-= 0x0100; /* Sign extend. */
9013 addend
= (upper
<< 12) | (lower
<< 1);
9014 signed_addend
= addend
;
9017 /* Handle calls via the PLT. */
9018 if (plt_offset
!= (bfd_vma
) -1)
9020 value
= (splt
->output_section
->vma
9021 + splt
->output_offset
9023 /* Target the Thumb stub before the ARM PLT entry. */
9024 value
-= PLT_THUMB_STUB_SIZE
;
9025 *unresolved_reloc_p
= FALSE
;
9028 /* ??? Should handle interworking? GCC might someday try to
9029 use this for tail calls. */
9031 relocation
= value
+ signed_addend
;
9032 relocation
-= (input_section
->output_section
->vma
9033 + input_section
->output_offset
9035 signed_check
= (bfd_signed_vma
) relocation
;
9037 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
9040 /* Put RELOCATION back into the insn. */
9042 bfd_vma S
= (relocation
& 0x00100000) >> 20;
9043 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
9044 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
9045 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
9046 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
9048 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
9049 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
9052 /* Put the relocated value back in the object file: */
9053 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9054 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9056 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
9059 case R_ARM_THM_JUMP11
:
9060 case R_ARM_THM_JUMP8
:
9061 case R_ARM_THM_JUMP6
:
9062 /* Thumb B (branch) instruction). */
9064 bfd_signed_vma relocation
;
9065 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
9066 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
9067 bfd_signed_vma signed_check
;
9069 /* CZB cannot jump backward. */
9070 if (r_type
== R_ARM_THM_JUMP6
)
9071 reloc_signed_min
= 0;
9073 if (globals
->use_rel
)
9075 /* Need to refetch addend. */
9076 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
9077 if (addend
& ((howto
->src_mask
+ 1) >> 1))
9080 signed_addend
&= ~ howto
->src_mask
;
9081 signed_addend
|= addend
;
9084 signed_addend
= addend
;
9085 /* The value in the insn has been right shifted. We need to
9086 undo this, so that we can perform the address calculation
9087 in terms of bytes. */
9088 signed_addend
<<= howto
->rightshift
;
9090 relocation
= value
+ signed_addend
;
9092 relocation
-= (input_section
->output_section
->vma
9093 + input_section
->output_offset
9096 relocation
>>= howto
->rightshift
;
9097 signed_check
= relocation
;
9099 if (r_type
== R_ARM_THM_JUMP6
)
9100 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
9102 relocation
&= howto
->dst_mask
;
9103 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
9105 bfd_put_16 (input_bfd
, relocation
, hit_data
);
9107 /* Assumes two's complement. */
9108 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
9109 return bfd_reloc_overflow
;
9111 return bfd_reloc_ok
;
9114 case R_ARM_ALU_PCREL7_0
:
9115 case R_ARM_ALU_PCREL15_8
:
9116 case R_ARM_ALU_PCREL23_15
:
9121 insn
= bfd_get_32 (input_bfd
, hit_data
);
9122 if (globals
->use_rel
)
9124 /* Extract the addend. */
9125 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
9126 signed_addend
= addend
;
9128 relocation
= value
+ signed_addend
;
9130 relocation
-= (input_section
->output_section
->vma
9131 + input_section
->output_offset
9133 insn
= (insn
& ~0xfff)
9134 | ((howto
->bitpos
<< 7) & 0xf00)
9135 | ((relocation
>> howto
->bitpos
) & 0xff);
9136 bfd_put_32 (input_bfd
, value
, hit_data
);
9138 return bfd_reloc_ok
;
9140 case R_ARM_GNU_VTINHERIT
:
9141 case R_ARM_GNU_VTENTRY
:
9142 return bfd_reloc_ok
;
9144 case R_ARM_GOTOFF32
:
9145 /* Relocation is relative to the start of the
9146 global offset table. */
9148 BFD_ASSERT (sgot
!= NULL
);
9150 return bfd_reloc_notsupported
;
9152 /* If we are addressing a Thumb function, we need to adjust the
9153 address by one, so that attempts to call the function pointer will
9154 correctly interpret it as Thumb code. */
9155 if (branch_type
== ST_BRANCH_TO_THUMB
)
9158 /* Note that sgot->output_offset is not involved in this
9159 calculation. We always want the start of .got. If we
9160 define _GLOBAL_OFFSET_TABLE in a different way, as is
9161 permitted by the ABI, we might have to change this
9163 value
-= sgot
->output_section
->vma
;
9164 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9165 contents
, rel
->r_offset
, value
,
9169 /* Use global offset table as symbol value. */
9170 BFD_ASSERT (sgot
!= NULL
);
9173 return bfd_reloc_notsupported
;
9175 *unresolved_reloc_p
= FALSE
;
9176 value
= sgot
->output_section
->vma
;
9177 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9178 contents
, rel
->r_offset
, value
,
9182 case R_ARM_GOT_PREL
:
9183 /* Relocation is to the entry for this symbol in the
9184 global offset table. */
9186 return bfd_reloc_notsupported
;
9188 if (dynreloc_st_type
== STT_GNU_IFUNC
9189 && plt_offset
!= (bfd_vma
) -1
9190 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
9192 /* We have a relocation against a locally-binding STT_GNU_IFUNC
9193 symbol, and the relocation resolves directly to the runtime
9194 target rather than to the .iplt entry. This means that any
9195 .got entry would be the same value as the .igot.plt entry,
9196 so there's no point creating both. */
9197 sgot
= globals
->root
.igotplt
;
9198 value
= sgot
->output_offset
+ gotplt_offset
;
9204 off
= h
->got
.offset
;
9205 BFD_ASSERT (off
!= (bfd_vma
) -1);
9208 /* We have already processsed one GOT relocation against
9211 if (globals
->root
.dynamic_sections_created
9212 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
9213 *unresolved_reloc_p
= FALSE
;
9217 Elf_Internal_Rela outrel
;
9219 if (h
->dynindx
!= -1 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
9221 /* If the symbol doesn't resolve locally in a static
9222 object, we have an undefined reference. If the
9223 symbol doesn't resolve locally in a dynamic object,
9224 it should be resolved by the dynamic linker. */
9225 if (globals
->root
.dynamic_sections_created
)
9227 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
9228 *unresolved_reloc_p
= FALSE
;
9232 outrel
.r_addend
= 0;
9236 if (dynreloc_st_type
== STT_GNU_IFUNC
)
9237 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9238 else if (info
->shared
&&
9239 (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9240 || h
->root
.type
!= bfd_link_hash_undefweak
))
9241 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
9244 outrel
.r_addend
= dynreloc_value
;
9247 /* The GOT entry is initialized to zero by default.
9248 See if we should install a different value. */
9249 if (outrel
.r_addend
!= 0
9250 && (outrel
.r_info
== 0 || globals
->use_rel
))
9252 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9253 sgot
->contents
+ off
);
9254 outrel
.r_addend
= 0;
9257 if (outrel
.r_info
!= 0)
9259 outrel
.r_offset
= (sgot
->output_section
->vma
9260 + sgot
->output_offset
9262 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9266 value
= sgot
->output_offset
+ off
;
9272 BFD_ASSERT (local_got_offsets
!= NULL
&&
9273 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
9275 off
= local_got_offsets
[r_symndx
];
9277 /* The offset must always be a multiple of 4. We use the
9278 least significant bit to record whether we have already
9279 generated the necessary reloc. */
9284 if (globals
->use_rel
)
9285 bfd_put_32 (output_bfd
, dynreloc_value
, sgot
->contents
+ off
);
9287 if (info
->shared
|| dynreloc_st_type
== STT_GNU_IFUNC
)
9289 Elf_Internal_Rela outrel
;
9291 outrel
.r_addend
= addend
+ dynreloc_value
;
9292 outrel
.r_offset
= (sgot
->output_section
->vma
9293 + sgot
->output_offset
9295 if (dynreloc_st_type
== STT_GNU_IFUNC
)
9296 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9298 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
9299 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9302 local_got_offsets
[r_symndx
] |= 1;
9305 value
= sgot
->output_offset
+ off
;
9307 if (r_type
!= R_ARM_GOT32
)
9308 value
+= sgot
->output_section
->vma
;
9310 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9311 contents
, rel
->r_offset
, value
,
9314 case R_ARM_TLS_LDO32
:
9315 value
= value
- dtpoff_base (info
);
9317 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9318 contents
, rel
->r_offset
, value
,
9321 case R_ARM_TLS_LDM32
:
9328 off
= globals
->tls_ldm_got
.offset
;
9334 /* If we don't know the module number, create a relocation
9338 Elf_Internal_Rela outrel
;
9340 if (srelgot
== NULL
)
9343 outrel
.r_addend
= 0;
9344 outrel
.r_offset
= (sgot
->output_section
->vma
9345 + sgot
->output_offset
+ off
);
9346 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
9348 if (globals
->use_rel
)
9349 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9350 sgot
->contents
+ off
);
9352 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9355 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ off
);
9357 globals
->tls_ldm_got
.offset
|= 1;
9360 value
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
9361 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
9363 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9364 contents
, rel
->r_offset
, value
,
9368 case R_ARM_TLS_CALL
:
9369 case R_ARM_THM_TLS_CALL
:
9370 case R_ARM_TLS_GD32
:
9371 case R_ARM_TLS_IE32
:
9372 case R_ARM_TLS_GOTDESC
:
9373 case R_ARM_TLS_DESCSEQ
:
9374 case R_ARM_THM_TLS_DESCSEQ
:
9376 bfd_vma off
, offplt
;
9380 BFD_ASSERT (sgot
!= NULL
);
9385 dyn
= globals
->root
.dynamic_sections_created
;
9386 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
9388 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9390 *unresolved_reloc_p
= FALSE
;
9393 off
= h
->got
.offset
;
9394 offplt
= elf32_arm_hash_entry (h
)->tlsdesc_got
;
9395 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
9399 BFD_ASSERT (local_got_offsets
!= NULL
);
9400 off
= local_got_offsets
[r_symndx
];
9401 offplt
= local_tlsdesc_gotents
[r_symndx
];
9402 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
9405 /* Linker relaxations happens from one of the
9406 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
9407 if (ELF32_R_TYPE(rel
->r_info
) != r_type
)
9408 tls_type
= GOT_TLS_IE
;
9410 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
9416 bfd_boolean need_relocs
= FALSE
;
9417 Elf_Internal_Rela outrel
;
9420 /* The GOT entries have not been initialized yet. Do it
9421 now, and emit any relocations. If both an IE GOT and a
9422 GD GOT are necessary, we emit the GD first. */
9424 if ((info
->shared
|| indx
!= 0)
9426 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9427 || h
->root
.type
!= bfd_link_hash_undefweak
))
9430 BFD_ASSERT (srelgot
!= NULL
);
9433 if (tls_type
& GOT_TLS_GDESC
)
9437 /* We should have relaxed, unless this is an undefined
9439 BFD_ASSERT ((h
&& (h
->root
.type
== bfd_link_hash_undefweak
))
9441 BFD_ASSERT (globals
->sgotplt_jump_table_size
+ offplt
+ 8
9442 <= globals
->root
.sgotplt
->size
);
9444 outrel
.r_addend
= 0;
9445 outrel
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
9446 + globals
->root
.sgotplt
->output_offset
9448 + globals
->sgotplt_jump_table_size
);
9450 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DESC
);
9451 sreloc
= globals
->root
.srelplt
;
9452 loc
= sreloc
->contents
;
9453 loc
+= globals
->next_tls_desc_index
++ * RELOC_SIZE (globals
);
9454 BFD_ASSERT (loc
+ RELOC_SIZE (globals
)
9455 <= sreloc
->contents
+ sreloc
->size
);
9457 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
9459 /* For globals, the first word in the relocation gets
9460 the relocation index and the top bit set, or zero,
9461 if we're binding now. For locals, it gets the
9462 symbol's offset in the tls section. */
9463 bfd_put_32 (output_bfd
,
9464 !h
? value
- elf_hash_table (info
)->tls_sec
->vma
9465 : info
->flags
& DF_BIND_NOW
? 0
9466 : 0x80000000 | ELF32_R_SYM (outrel
.r_info
),
9467 globals
->root
.sgotplt
->contents
+ offplt
9468 + globals
->sgotplt_jump_table_size
);
9470 /* Second word in the relocation is always zero. */
9471 bfd_put_32 (output_bfd
, 0,
9472 globals
->root
.sgotplt
->contents
+ offplt
9473 + globals
->sgotplt_jump_table_size
+ 4);
9475 if (tls_type
& GOT_TLS_GD
)
9479 outrel
.r_addend
= 0;
9480 outrel
.r_offset
= (sgot
->output_section
->vma
9481 + sgot
->output_offset
9483 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
9485 if (globals
->use_rel
)
9486 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9487 sgot
->contents
+ cur_off
);
9489 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9492 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9493 sgot
->contents
+ cur_off
+ 4);
9496 outrel
.r_addend
= 0;
9497 outrel
.r_info
= ELF32_R_INFO (indx
,
9498 R_ARM_TLS_DTPOFF32
);
9499 outrel
.r_offset
+= 4;
9501 if (globals
->use_rel
)
9502 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9503 sgot
->contents
+ cur_off
+ 4);
9505 elf32_arm_add_dynreloc (output_bfd
, info
,
9511 /* If we are not emitting relocations for a
9512 general dynamic reference, then we must be in a
9513 static link or an executable link with the
9514 symbol binding locally. Mark it as belonging
9515 to module 1, the executable. */
9516 bfd_put_32 (output_bfd
, 1,
9517 sgot
->contents
+ cur_off
);
9518 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9519 sgot
->contents
+ cur_off
+ 4);
9525 if (tls_type
& GOT_TLS_IE
)
9530 outrel
.r_addend
= value
- dtpoff_base (info
);
9532 outrel
.r_addend
= 0;
9533 outrel
.r_offset
= (sgot
->output_section
->vma
9534 + sgot
->output_offset
9536 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
9538 if (globals
->use_rel
)
9539 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9540 sgot
->contents
+ cur_off
);
9542 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9545 bfd_put_32 (output_bfd
, tpoff (info
, value
),
9546 sgot
->contents
+ cur_off
);
9553 local_got_offsets
[r_symndx
] |= 1;
9556 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
9558 else if (tls_type
& GOT_TLS_GDESC
)
9561 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
9562 || ELF32_R_TYPE(rel
->r_info
) == R_ARM_THM_TLS_CALL
)
9564 bfd_signed_vma offset
;
9565 /* TLS stubs are arm mode. The original symbol is a
9566 data object, so branch_type is bogus. */
9567 branch_type
= ST_BRANCH_TO_ARM
;
9568 enum elf32_arm_stub_type stub_type
9569 = arm_type_of_stub (info
, input_section
, rel
,
9570 st_type
, &branch_type
,
9571 (struct elf32_arm_link_hash_entry
*)h
,
9572 globals
->tls_trampoline
, globals
->root
.splt
,
9573 input_bfd
, sym_name
);
9575 if (stub_type
!= arm_stub_none
)
9577 struct elf32_arm_stub_hash_entry
*stub_entry
9578 = elf32_arm_get_stub_entry
9579 (input_section
, globals
->root
.splt
, 0, rel
,
9580 globals
, stub_type
);
9581 offset
= (stub_entry
->stub_offset
9582 + stub_entry
->stub_sec
->output_offset
9583 + stub_entry
->stub_sec
->output_section
->vma
);
9586 offset
= (globals
->root
.splt
->output_section
->vma
9587 + globals
->root
.splt
->output_offset
9588 + globals
->tls_trampoline
);
9590 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
)
9594 offset
-= (input_section
->output_section
->vma
9595 + input_section
->output_offset
9596 + rel
->r_offset
+ 8);
9600 value
= inst
| (globals
->use_blx
? 0xfa000000 : 0xeb000000);
9604 /* Thumb blx encodes the offset in a complicated
9606 unsigned upper_insn
, lower_insn
;
9609 offset
-= (input_section
->output_section
->vma
9610 + input_section
->output_offset
9611 + rel
->r_offset
+ 4);
9613 if (stub_type
!= arm_stub_none
9614 && arm_stub_is_thumb (stub_type
))
9616 lower_insn
= 0xd000;
9620 lower_insn
= 0xc000;
9621 /* Round up the offset to a word boundary */
9622 offset
= (offset
+ 2) & ~2;
9626 upper_insn
= (0xf000
9627 | ((offset
>> 12) & 0x3ff)
9629 lower_insn
|= (((!((offset
>> 23) & 1)) ^ neg
) << 13)
9630 | (((!((offset
>> 22) & 1)) ^ neg
) << 11)
9631 | ((offset
>> 1) & 0x7ff);
9632 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9633 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9634 return bfd_reloc_ok
;
9637 /* These relocations needs special care, as besides the fact
9638 they point somewhere in .gotplt, the addend must be
9639 adjusted accordingly depending on the type of instruction
9641 else if ((r_type
== R_ARM_TLS_GOTDESC
) && (tls_type
& GOT_TLS_GDESC
))
9643 unsigned long data
, insn
;
9646 data
= bfd_get_32 (input_bfd
, hit_data
);
9652 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
- data
);
9653 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
9655 | bfd_get_16 (input_bfd
,
9656 contents
+ rel
->r_offset
- data
+ 2);
9657 if ((insn
& 0xf800c000) == 0xf000c000)
9660 else if ((insn
& 0xffffff00) == 0x4400)
9665 (*_bfd_error_handler
)
9666 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' referenced by TLS_GOTDESC"),
9667 input_bfd
, input_section
,
9668 (unsigned long)rel
->r_offset
, insn
);
9669 return bfd_reloc_notsupported
;
9674 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- data
);
9679 case 0xfa: /* blx */
9683 case 0xe0: /* add */
9688 (*_bfd_error_handler
)
9689 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' referenced by TLS_GOTDESC"),
9690 input_bfd
, input_section
,
9691 (unsigned long)rel
->r_offset
, insn
);
9692 return bfd_reloc_notsupported
;
9696 value
+= ((globals
->root
.sgotplt
->output_section
->vma
9697 + globals
->root
.sgotplt
->output_offset
+ off
)
9698 - (input_section
->output_section
->vma
9699 + input_section
->output_offset
9701 + globals
->sgotplt_jump_table_size
);
9704 value
= ((globals
->root
.sgot
->output_section
->vma
9705 + globals
->root
.sgot
->output_offset
+ off
)
9706 - (input_section
->output_section
->vma
9707 + input_section
->output_offset
+ rel
->r_offset
));
9709 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9710 contents
, rel
->r_offset
, value
,
9714 case R_ARM_TLS_LE32
:
9715 if (info
->shared
&& !info
->pie
)
9717 (*_bfd_error_handler
)
9718 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
9719 input_bfd
, input_section
,
9720 (long) rel
->r_offset
, howto
->name
);
9721 return bfd_reloc_notsupported
;
9724 value
= tpoff (info
, value
);
9726 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9727 contents
, rel
->r_offset
, value
,
9731 if (globals
->fix_v4bx
)
9733 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9735 /* Ensure that we have a BX instruction. */
9736 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
9738 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
9740 /* Branch to veneer. */
9742 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
9743 glue_addr
-= input_section
->output_section
->vma
9744 + input_section
->output_offset
9745 + rel
->r_offset
+ 8;
9746 insn
= (insn
& 0xf0000000) | 0x0a000000
9747 | ((glue_addr
>> 2) & 0x00ffffff);
9751 /* Preserve Rm (lowest four bits) and the condition code
9752 (highest four bits). Other bits encode MOV PC,Rm. */
9753 insn
= (insn
& 0xf000000f) | 0x01a0f000;
9756 bfd_put_32 (input_bfd
, insn
, hit_data
);
9758 return bfd_reloc_ok
;
9760 case R_ARM_MOVW_ABS_NC
:
9761 case R_ARM_MOVT_ABS
:
9762 case R_ARM_MOVW_PREL_NC
:
9763 case R_ARM_MOVT_PREL
:
9764 /* Until we properly support segment-base-relative addressing then
9765 we assume the segment base to be zero, as for the group relocations.
9766 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
9767 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
9768 case R_ARM_MOVW_BREL_NC
:
9769 case R_ARM_MOVW_BREL
:
9770 case R_ARM_MOVT_BREL
:
9772 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9774 if (globals
->use_rel
)
9776 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
9777 signed_addend
= (addend
^ 0x8000) - 0x8000;
9780 value
+= signed_addend
;
9782 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
9783 value
-= (input_section
->output_section
->vma
9784 + input_section
->output_offset
+ rel
->r_offset
);
9786 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
9787 return bfd_reloc_overflow
;
9789 if (branch_type
== ST_BRANCH_TO_THUMB
)
9792 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
9793 || r_type
== R_ARM_MOVT_BREL
)
9797 insn
|= value
& 0xfff;
9798 insn
|= (value
& 0xf000) << 4;
9799 bfd_put_32 (input_bfd
, insn
, hit_data
);
9801 return bfd_reloc_ok
;
9803 case R_ARM_THM_MOVW_ABS_NC
:
9804 case R_ARM_THM_MOVT_ABS
:
9805 case R_ARM_THM_MOVW_PREL_NC
:
9806 case R_ARM_THM_MOVT_PREL
:
9807 /* Until we properly support segment-base-relative addressing then
9808 we assume the segment base to be zero, as for the above relocations.
9809 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
9810 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
9811 as R_ARM_THM_MOVT_ABS. */
9812 case R_ARM_THM_MOVW_BREL_NC
:
9813 case R_ARM_THM_MOVW_BREL
:
9814 case R_ARM_THM_MOVT_BREL
:
9818 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
9819 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
9821 if (globals
->use_rel
)
9823 addend
= ((insn
>> 4) & 0xf000)
9824 | ((insn
>> 15) & 0x0800)
9825 | ((insn
>> 4) & 0x0700)
9827 signed_addend
= (addend
^ 0x8000) - 0x8000;
9830 value
+= signed_addend
;
9832 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
9833 value
-= (input_section
->output_section
->vma
9834 + input_section
->output_offset
+ rel
->r_offset
);
9836 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
9837 return bfd_reloc_overflow
;
9839 if (branch_type
== ST_BRANCH_TO_THUMB
)
9842 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
9843 || r_type
== R_ARM_THM_MOVT_BREL
)
9847 insn
|= (value
& 0xf000) << 4;
9848 insn
|= (value
& 0x0800) << 15;
9849 insn
|= (value
& 0x0700) << 4;
9850 insn
|= (value
& 0x00ff);
9852 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
9853 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
9855 return bfd_reloc_ok
;
9857 case R_ARM_ALU_PC_G0_NC
:
9858 case R_ARM_ALU_PC_G1_NC
:
9859 case R_ARM_ALU_PC_G0
:
9860 case R_ARM_ALU_PC_G1
:
9861 case R_ARM_ALU_PC_G2
:
9862 case R_ARM_ALU_SB_G0_NC
:
9863 case R_ARM_ALU_SB_G1_NC
:
9864 case R_ARM_ALU_SB_G0
:
9865 case R_ARM_ALU_SB_G1
:
9866 case R_ARM_ALU_SB_G2
:
9868 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9869 bfd_vma pc
= input_section
->output_section
->vma
9870 + input_section
->output_offset
+ rel
->r_offset
;
9871 /* sb is the origin of the *segment* containing the symbol. */
9872 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
9875 bfd_signed_vma signed_value
;
9878 /* Determine which group of bits to select. */
9881 case R_ARM_ALU_PC_G0_NC
:
9882 case R_ARM_ALU_PC_G0
:
9883 case R_ARM_ALU_SB_G0_NC
:
9884 case R_ARM_ALU_SB_G0
:
9888 case R_ARM_ALU_PC_G1_NC
:
9889 case R_ARM_ALU_PC_G1
:
9890 case R_ARM_ALU_SB_G1_NC
:
9891 case R_ARM_ALU_SB_G1
:
9895 case R_ARM_ALU_PC_G2
:
9896 case R_ARM_ALU_SB_G2
:
9904 /* If REL, extract the addend from the insn. If RELA, it will
9905 have already been fetched for us. */
9906 if (globals
->use_rel
)
9909 bfd_vma constant
= insn
& 0xff;
9910 bfd_vma rotation
= (insn
& 0xf00) >> 8;
9913 signed_addend
= constant
;
9916 /* Compensate for the fact that in the instruction, the
9917 rotation is stored in multiples of 2 bits. */
9920 /* Rotate "constant" right by "rotation" bits. */
9921 signed_addend
= (constant
>> rotation
) |
9922 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
9925 /* Determine if the instruction is an ADD or a SUB.
9926 (For REL, this determines the sign of the addend.) */
9927 negative
= identify_add_or_sub (insn
);
9930 (*_bfd_error_handler
)
9931 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
9932 input_bfd
, input_section
,
9933 (long) rel
->r_offset
, howto
->name
);
9934 return bfd_reloc_overflow
;
9937 signed_addend
*= negative
;
9940 /* Compute the value (X) to go in the place. */
9941 if (r_type
== R_ARM_ALU_PC_G0_NC
9942 || r_type
== R_ARM_ALU_PC_G1_NC
9943 || r_type
== R_ARM_ALU_PC_G0
9944 || r_type
== R_ARM_ALU_PC_G1
9945 || r_type
== R_ARM_ALU_PC_G2
)
9947 signed_value
= value
- pc
+ signed_addend
;
9949 /* Section base relative. */
9950 signed_value
= value
- sb
+ signed_addend
;
9952 /* If the target symbol is a Thumb function, then set the
9953 Thumb bit in the address. */
9954 if (branch_type
== ST_BRANCH_TO_THUMB
)
9957 /* Calculate the value of the relevant G_n, in encoded
9958 constant-with-rotation format. */
9959 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
9962 /* Check for overflow if required. */
9963 if ((r_type
== R_ARM_ALU_PC_G0
9964 || r_type
== R_ARM_ALU_PC_G1
9965 || r_type
== R_ARM_ALU_PC_G2
9966 || r_type
== R_ARM_ALU_SB_G0
9967 || r_type
== R_ARM_ALU_SB_G1
9968 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
9970 (*_bfd_error_handler
)
9971 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9972 input_bfd
, input_section
,
9973 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
9974 return bfd_reloc_overflow
;
9977 /* Mask out the value and the ADD/SUB part of the opcode; take care
9978 not to destroy the S bit. */
9981 /* Set the opcode according to whether the value to go in the
9982 place is negative. */
9983 if (signed_value
< 0)
9988 /* Encode the offset. */
9991 bfd_put_32 (input_bfd
, insn
, hit_data
);
9993 return bfd_reloc_ok
;
9995 case R_ARM_LDR_PC_G0
:
9996 case R_ARM_LDR_PC_G1
:
9997 case R_ARM_LDR_PC_G2
:
9998 case R_ARM_LDR_SB_G0
:
9999 case R_ARM_LDR_SB_G1
:
10000 case R_ARM_LDR_SB_G2
:
10002 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10003 bfd_vma pc
= input_section
->output_section
->vma
10004 + input_section
->output_offset
+ rel
->r_offset
;
10005 /* sb is the origin of the *segment* containing the symbol. */
10006 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10008 bfd_signed_vma signed_value
;
10011 /* Determine which groups of bits to calculate. */
10014 case R_ARM_LDR_PC_G0
:
10015 case R_ARM_LDR_SB_G0
:
10019 case R_ARM_LDR_PC_G1
:
10020 case R_ARM_LDR_SB_G1
:
10024 case R_ARM_LDR_PC_G2
:
10025 case R_ARM_LDR_SB_G2
:
10033 /* If REL, extract the addend from the insn. If RELA, it will
10034 have already been fetched for us. */
10035 if (globals
->use_rel
)
10037 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10038 signed_addend
= negative
* (insn
& 0xfff);
10041 /* Compute the value (X) to go in the place. */
10042 if (r_type
== R_ARM_LDR_PC_G0
10043 || r_type
== R_ARM_LDR_PC_G1
10044 || r_type
== R_ARM_LDR_PC_G2
)
10046 signed_value
= value
- pc
+ signed_addend
;
10048 /* Section base relative. */
10049 signed_value
= value
- sb
+ signed_addend
;
10051 /* Calculate the value of the relevant G_{n-1} to obtain
10052 the residual at that stage. */
10053 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10055 /* Check for overflow. */
10056 if (residual
>= 0x1000)
10058 (*_bfd_error_handler
)
10059 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10060 input_bfd
, input_section
,
10061 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10062 return bfd_reloc_overflow
;
10065 /* Mask out the value and U bit. */
10066 insn
&= 0xff7ff000;
10068 /* Set the U bit if the value to go in the place is non-negative. */
10069 if (signed_value
>= 0)
10072 /* Encode the offset. */
10075 bfd_put_32 (input_bfd
, insn
, hit_data
);
10077 return bfd_reloc_ok
;
10079 case R_ARM_LDRS_PC_G0
:
10080 case R_ARM_LDRS_PC_G1
:
10081 case R_ARM_LDRS_PC_G2
:
10082 case R_ARM_LDRS_SB_G0
:
10083 case R_ARM_LDRS_SB_G1
:
10084 case R_ARM_LDRS_SB_G2
:
10086 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10087 bfd_vma pc
= input_section
->output_section
->vma
10088 + input_section
->output_offset
+ rel
->r_offset
;
10089 /* sb is the origin of the *segment* containing the symbol. */
10090 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10092 bfd_signed_vma signed_value
;
10095 /* Determine which groups of bits to calculate. */
10098 case R_ARM_LDRS_PC_G0
:
10099 case R_ARM_LDRS_SB_G0
:
10103 case R_ARM_LDRS_PC_G1
:
10104 case R_ARM_LDRS_SB_G1
:
10108 case R_ARM_LDRS_PC_G2
:
10109 case R_ARM_LDRS_SB_G2
:
10117 /* If REL, extract the addend from the insn. If RELA, it will
10118 have already been fetched for us. */
10119 if (globals
->use_rel
)
10121 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10122 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
10125 /* Compute the value (X) to go in the place. */
10126 if (r_type
== R_ARM_LDRS_PC_G0
10127 || r_type
== R_ARM_LDRS_PC_G1
10128 || r_type
== R_ARM_LDRS_PC_G2
)
10130 signed_value
= value
- pc
+ signed_addend
;
10132 /* Section base relative. */
10133 signed_value
= value
- sb
+ signed_addend
;
10135 /* Calculate the value of the relevant G_{n-1} to obtain
10136 the residual at that stage. */
10137 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10139 /* Check for overflow. */
10140 if (residual
>= 0x100)
10142 (*_bfd_error_handler
)
10143 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10144 input_bfd
, input_section
,
10145 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10146 return bfd_reloc_overflow
;
10149 /* Mask out the value and U bit. */
10150 insn
&= 0xff7ff0f0;
10152 /* Set the U bit if the value to go in the place is non-negative. */
10153 if (signed_value
>= 0)
10156 /* Encode the offset. */
10157 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
10159 bfd_put_32 (input_bfd
, insn
, hit_data
);
10161 return bfd_reloc_ok
;
10163 case R_ARM_LDC_PC_G0
:
10164 case R_ARM_LDC_PC_G1
:
10165 case R_ARM_LDC_PC_G2
:
10166 case R_ARM_LDC_SB_G0
:
10167 case R_ARM_LDC_SB_G1
:
10168 case R_ARM_LDC_SB_G2
:
10170 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10171 bfd_vma pc
= input_section
->output_section
->vma
10172 + input_section
->output_offset
+ rel
->r_offset
;
10173 /* sb is the origin of the *segment* containing the symbol. */
10174 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10176 bfd_signed_vma signed_value
;
10179 /* Determine which groups of bits to calculate. */
10182 case R_ARM_LDC_PC_G0
:
10183 case R_ARM_LDC_SB_G0
:
10187 case R_ARM_LDC_PC_G1
:
10188 case R_ARM_LDC_SB_G1
:
10192 case R_ARM_LDC_PC_G2
:
10193 case R_ARM_LDC_SB_G2
:
10201 /* If REL, extract the addend from the insn. If RELA, it will
10202 have already been fetched for us. */
10203 if (globals
->use_rel
)
10205 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10206 signed_addend
= negative
* ((insn
& 0xff) << 2);
10209 /* Compute the value (X) to go in the place. */
10210 if (r_type
== R_ARM_LDC_PC_G0
10211 || r_type
== R_ARM_LDC_PC_G1
10212 || r_type
== R_ARM_LDC_PC_G2
)
10214 signed_value
= value
- pc
+ signed_addend
;
10216 /* Section base relative. */
10217 signed_value
= value
- sb
+ signed_addend
;
10219 /* Calculate the value of the relevant G_{n-1} to obtain
10220 the residual at that stage. */
10221 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10223 /* Check for overflow. (The absolute value to go in the place must be
10224 divisible by four and, after having been divided by four, must
10225 fit in eight bits.) */
10226 if ((residual
& 0x3) != 0 || residual
>= 0x400)
10228 (*_bfd_error_handler
)
10229 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10230 input_bfd
, input_section
,
10231 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10232 return bfd_reloc_overflow
;
10235 /* Mask out the value and U bit. */
10236 insn
&= 0xff7fff00;
10238 /* Set the U bit if the value to go in the place is non-negative. */
10239 if (signed_value
>= 0)
10242 /* Encode the offset. */
10243 insn
|= residual
>> 2;
10245 bfd_put_32 (input_bfd
, insn
, hit_data
);
10247 return bfd_reloc_ok
;
10250 return bfd_reloc_notsupported
;
10254 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
10256 arm_add_to_rel (bfd
* abfd
,
10257 bfd_byte
* address
,
10258 reloc_howto_type
* howto
,
10259 bfd_signed_vma increment
)
10261 bfd_signed_vma addend
;
10263 if (howto
->type
== R_ARM_THM_CALL
10264 || howto
->type
== R_ARM_THM_JUMP24
)
10266 int upper_insn
, lower_insn
;
10269 upper_insn
= bfd_get_16 (abfd
, address
);
10270 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
10271 upper
= upper_insn
& 0x7ff;
10272 lower
= lower_insn
& 0x7ff;
10274 addend
= (upper
<< 12) | (lower
<< 1);
10275 addend
+= increment
;
10278 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
10279 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
10281 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
10282 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
10288 contents
= bfd_get_32 (abfd
, address
);
10290 /* Get the (signed) value from the instruction. */
10291 addend
= contents
& howto
->src_mask
;
10292 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10294 bfd_signed_vma mask
;
10297 mask
&= ~ howto
->src_mask
;
10301 /* Add in the increment, (which is a byte value). */
10302 switch (howto
->type
)
10305 addend
+= increment
;
10312 addend
<<= howto
->size
;
10313 addend
+= increment
;
10315 /* Should we check for overflow here ? */
10317 /* Drop any undesired bits. */
10318 addend
>>= howto
->rightshift
;
10322 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
10324 bfd_put_32 (abfd
, contents
, address
);
10328 #define IS_ARM_TLS_RELOC(R_TYPE) \
10329 ((R_TYPE) == R_ARM_TLS_GD32 \
10330 || (R_TYPE) == R_ARM_TLS_LDO32 \
10331 || (R_TYPE) == R_ARM_TLS_LDM32 \
10332 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
10333 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
10334 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
10335 || (R_TYPE) == R_ARM_TLS_LE32 \
10336 || (R_TYPE) == R_ARM_TLS_IE32 \
10337 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
10339 /* Specific set of relocations for the gnu tls dialect. */
10340 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
10341 ((R_TYPE) == R_ARM_TLS_GOTDESC \
10342 || (R_TYPE) == R_ARM_TLS_CALL \
10343 || (R_TYPE) == R_ARM_THM_TLS_CALL \
10344 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
10345 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
10347 /* Relocate an ARM ELF section. */
10350 elf32_arm_relocate_section (bfd
* output_bfd
,
10351 struct bfd_link_info
* info
,
10353 asection
* input_section
,
10354 bfd_byte
* contents
,
10355 Elf_Internal_Rela
* relocs
,
10356 Elf_Internal_Sym
* local_syms
,
10357 asection
** local_sections
)
10359 Elf_Internal_Shdr
*symtab_hdr
;
10360 struct elf_link_hash_entry
**sym_hashes
;
10361 Elf_Internal_Rela
*rel
;
10362 Elf_Internal_Rela
*relend
;
10364 struct elf32_arm_link_hash_table
* globals
;
10366 globals
= elf32_arm_hash_table (info
);
10367 if (globals
== NULL
)
10370 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
10371 sym_hashes
= elf_sym_hashes (input_bfd
);
10374 relend
= relocs
+ input_section
->reloc_count
;
10375 for (; rel
< relend
; rel
++)
10378 reloc_howto_type
* howto
;
10379 unsigned long r_symndx
;
10380 Elf_Internal_Sym
* sym
;
10382 struct elf_link_hash_entry
* h
;
10383 bfd_vma relocation
;
10384 bfd_reloc_status_type r
;
10387 bfd_boolean unresolved_reloc
= FALSE
;
10388 char *error_message
= NULL
;
10390 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10391 r_type
= ELF32_R_TYPE (rel
->r_info
);
10392 r_type
= arm_real_reloc_type (globals
, r_type
);
10394 if ( r_type
== R_ARM_GNU_VTENTRY
10395 || r_type
== R_ARM_GNU_VTINHERIT
)
10398 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
10399 howto
= bfd_reloc
.howto
;
10405 if (r_symndx
< symtab_hdr
->sh_info
)
10407 sym
= local_syms
+ r_symndx
;
10408 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
10409 sec
= local_sections
[r_symndx
];
10411 /* An object file might have a reference to a local
10412 undefined symbol. This is a daft object file, but we
10413 should at least do something about it. V4BX & NONE
10414 relocations do not use the symbol and are explicitly
10415 allowed to use the undefined symbol, so allow those.
10416 Likewise for relocations against STN_UNDEF. */
10417 if (r_type
!= R_ARM_V4BX
10418 && r_type
!= R_ARM_NONE
10419 && r_symndx
!= STN_UNDEF
10420 && bfd_is_und_section (sec
)
10421 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
10423 if (!info
->callbacks
->undefined_symbol
10424 (info
, bfd_elf_string_from_elf_section
10425 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
10426 input_bfd
, input_section
,
10427 rel
->r_offset
, TRUE
))
10431 if (globals
->use_rel
)
10433 relocation
= (sec
->output_section
->vma
10434 + sec
->output_offset
10436 if (!info
->relocatable
10437 && (sec
->flags
& SEC_MERGE
)
10438 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10441 bfd_vma addend
, value
;
10445 case R_ARM_MOVW_ABS_NC
:
10446 case R_ARM_MOVT_ABS
:
10447 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10448 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
10449 addend
= (addend
^ 0x8000) - 0x8000;
10452 case R_ARM_THM_MOVW_ABS_NC
:
10453 case R_ARM_THM_MOVT_ABS
:
10454 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
10456 value
|= bfd_get_16 (input_bfd
,
10457 contents
+ rel
->r_offset
+ 2);
10458 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
10459 | ((value
& 0x04000000) >> 15);
10460 addend
= (addend
^ 0x8000) - 0x8000;
10464 if (howto
->rightshift
10465 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
10467 (*_bfd_error_handler
)
10468 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
10469 input_bfd
, input_section
,
10470 (long) rel
->r_offset
, howto
->name
);
10474 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10476 /* Get the (signed) value from the instruction. */
10477 addend
= value
& howto
->src_mask
;
10478 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10480 bfd_signed_vma mask
;
10483 mask
&= ~ howto
->src_mask
;
10491 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
10493 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
10495 /* Cases here must match those in the preceding
10496 switch statement. */
10499 case R_ARM_MOVW_ABS_NC
:
10500 case R_ARM_MOVT_ABS
:
10501 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
10502 | (addend
& 0xfff);
10503 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10506 case R_ARM_THM_MOVW_ABS_NC
:
10507 case R_ARM_THM_MOVT_ABS
:
10508 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
10509 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
10510 bfd_put_16 (input_bfd
, value
>> 16,
10511 contents
+ rel
->r_offset
);
10512 bfd_put_16 (input_bfd
, value
,
10513 contents
+ rel
->r_offset
+ 2);
10517 value
= (value
& ~ howto
->dst_mask
)
10518 | (addend
& howto
->dst_mask
);
10519 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10525 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
10529 bfd_boolean warned
, ignored
;
10531 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
10532 r_symndx
, symtab_hdr
, sym_hashes
,
10533 h
, sec
, relocation
,
10534 unresolved_reloc
, warned
, ignored
);
10536 sym_type
= h
->type
;
10539 if (sec
!= NULL
&& discarded_section (sec
))
10540 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
10541 rel
, 1, relend
, howto
, 0, contents
);
10543 if (info
->relocatable
)
10545 /* This is a relocatable link. We don't have to change
10546 anything, unless the reloc is against a section symbol,
10547 in which case we have to adjust according to where the
10548 section symbol winds up in the output section. */
10549 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10551 if (globals
->use_rel
)
10552 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
10553 howto
, (bfd_signed_vma
) sec
->output_offset
);
10555 rel
->r_addend
+= sec
->output_offset
;
10561 name
= h
->root
.root
.string
;
10564 name
= (bfd_elf_string_from_elf_section
10565 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
10566 if (name
== NULL
|| *name
== '\0')
10567 name
= bfd_section_name (input_bfd
, sec
);
10570 if (r_symndx
!= STN_UNDEF
10571 && r_type
!= R_ARM_NONE
10573 || h
->root
.type
== bfd_link_hash_defined
10574 || h
->root
.type
== bfd_link_hash_defweak
)
10575 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
10577 (*_bfd_error_handler
)
10578 ((sym_type
== STT_TLS
10579 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
10580 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
10583 (long) rel
->r_offset
,
10588 /* We call elf32_arm_final_link_relocate unless we're completely
10589 done, i.e., the relaxation produced the final output we want,
10590 and we won't let anybody mess with it. Also, we have to do
10591 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
10592 both in relaxed and non-relaxed cases */
10593 if ((elf32_arm_tls_transition (info
, r_type
, h
) != (unsigned)r_type
)
10594 || (IS_ARM_TLS_GNU_RELOC (r_type
)
10595 && !((h
? elf32_arm_hash_entry (h
)->tls_type
:
10596 elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
])
10599 r
= elf32_arm_tls_relax (globals
, input_bfd
, input_section
,
10600 contents
, rel
, h
== NULL
);
10601 /* This may have been marked unresolved because it came from
10602 a shared library. But we've just dealt with that. */
10603 unresolved_reloc
= 0;
10606 r
= bfd_reloc_continue
;
10608 if (r
== bfd_reloc_continue
)
10609 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
10610 input_section
, contents
, rel
,
10611 relocation
, info
, sec
, name
, sym_type
,
10612 (h
? h
->target_internal
10613 : ARM_SYM_BRANCH_TYPE (sym
)), h
,
10614 &unresolved_reloc
, &error_message
);
10616 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
10617 because such sections are not SEC_ALLOC and thus ld.so will
10618 not process them. */
10619 if (unresolved_reloc
10620 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
10622 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
10623 rel
->r_offset
) != (bfd_vma
) -1)
10625 (*_bfd_error_handler
)
10626 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
10629 (long) rel
->r_offset
,
10631 h
->root
.root
.string
);
10635 if (r
!= bfd_reloc_ok
)
10639 case bfd_reloc_overflow
:
10640 /* If the overflowing reloc was to an undefined symbol,
10641 we have already printed one error message and there
10642 is no point complaining again. */
10644 h
->root
.type
!= bfd_link_hash_undefined
)
10645 && (!((*info
->callbacks
->reloc_overflow
)
10646 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
10647 (bfd_vma
) 0, input_bfd
, input_section
,
10652 case bfd_reloc_undefined
:
10653 if (!((*info
->callbacks
->undefined_symbol
)
10654 (info
, name
, input_bfd
, input_section
,
10655 rel
->r_offset
, TRUE
)))
10659 case bfd_reloc_outofrange
:
10660 error_message
= _("out of range");
10663 case bfd_reloc_notsupported
:
10664 error_message
= _("unsupported relocation");
10667 case bfd_reloc_dangerous
:
10668 /* error_message should already be set. */
10672 error_message
= _("unknown error");
10673 /* Fall through. */
10676 BFD_ASSERT (error_message
!= NULL
);
10677 if (!((*info
->callbacks
->reloc_dangerous
)
10678 (info
, error_message
, input_bfd
, input_section
,
10689 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
10690 adds the edit to the start of the list. (The list must be built in order of
10691 ascending TINDEX: the function's callers are primarily responsible for
10692 maintaining that condition). */
10695 add_unwind_table_edit (arm_unwind_table_edit
**head
,
10696 arm_unwind_table_edit
**tail
,
10697 arm_unwind_edit_type type
,
10698 asection
*linked_section
,
10699 unsigned int tindex
)
10701 arm_unwind_table_edit
*new_edit
= (arm_unwind_table_edit
*)
10702 xmalloc (sizeof (arm_unwind_table_edit
));
10704 new_edit
->type
= type
;
10705 new_edit
->linked_section
= linked_section
;
10706 new_edit
->index
= tindex
;
10710 new_edit
->next
= NULL
;
10713 (*tail
)->next
= new_edit
;
10715 (*tail
) = new_edit
;
10718 (*head
) = new_edit
;
10722 new_edit
->next
= *head
;
10731 static _arm_elf_section_data
*get_arm_elf_section_data (asection
*);
10733 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
10735 adjust_exidx_size(asection
*exidx_sec
, int adjust
)
10739 if (!exidx_sec
->rawsize
)
10740 exidx_sec
->rawsize
= exidx_sec
->size
;
10742 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
10743 out_sec
= exidx_sec
->output_section
;
10744 /* Adjust size of output section. */
10745 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
10748 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
10750 insert_cantunwind_after(asection
*text_sec
, asection
*exidx_sec
)
10752 struct _arm_elf_section_data
*exidx_arm_data
;
10754 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10755 add_unwind_table_edit (
10756 &exidx_arm_data
->u
.exidx
.unwind_edit_list
,
10757 &exidx_arm_data
->u
.exidx
.unwind_edit_tail
,
10758 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
10760 adjust_exidx_size(exidx_sec
, 8);
10763 /* Scan .ARM.exidx tables, and create a list describing edits which should be
10764 made to those tables, such that:
10766 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
10767 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
10768 codes which have been inlined into the index).
10770 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
10772 The edits are applied when the tables are written
10773 (in elf32_arm_write_section). */
10776 elf32_arm_fix_exidx_coverage (asection
**text_section_order
,
10777 unsigned int num_text_sections
,
10778 struct bfd_link_info
*info
,
10779 bfd_boolean merge_exidx_entries
)
10782 unsigned int last_second_word
= 0, i
;
10783 asection
*last_exidx_sec
= NULL
;
10784 asection
*last_text_sec
= NULL
;
10785 int last_unwind_type
= -1;
10787 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
10789 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link_next
)
10793 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
10795 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
10796 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
10798 if (!hdr
|| hdr
->sh_type
!= SHT_ARM_EXIDX
)
10801 if (elf_sec
->linked_to
)
10803 Elf_Internal_Shdr
*linked_hdr
10804 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
10805 struct _arm_elf_section_data
*linked_sec_arm_data
10806 = get_arm_elf_section_data (linked_hdr
->bfd_section
);
10808 if (linked_sec_arm_data
== NULL
)
10811 /* Link this .ARM.exidx section back from the text section it
10813 linked_sec_arm_data
->u
.text
.arm_exidx_sec
= sec
;
10818 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
10819 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
10820 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
10822 for (i
= 0; i
< num_text_sections
; i
++)
10824 asection
*sec
= text_section_order
[i
];
10825 asection
*exidx_sec
;
10826 struct _arm_elf_section_data
*arm_data
= get_arm_elf_section_data (sec
);
10827 struct _arm_elf_section_data
*exidx_arm_data
;
10828 bfd_byte
*contents
= NULL
;
10829 int deleted_exidx_bytes
= 0;
10831 arm_unwind_table_edit
*unwind_edit_head
= NULL
;
10832 arm_unwind_table_edit
*unwind_edit_tail
= NULL
;
10833 Elf_Internal_Shdr
*hdr
;
10836 if (arm_data
== NULL
)
10839 exidx_sec
= arm_data
->u
.text
.arm_exidx_sec
;
10840 if (exidx_sec
== NULL
)
10842 /* Section has no unwind data. */
10843 if (last_unwind_type
== 0 || !last_exidx_sec
)
10846 /* Ignore zero sized sections. */
10847 if (sec
->size
== 0)
10850 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
10851 last_unwind_type
= 0;
10855 /* Skip /DISCARD/ sections. */
10856 if (bfd_is_abs_section (exidx_sec
->output_section
))
10859 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
10860 if (hdr
->sh_type
!= SHT_ARM_EXIDX
)
10863 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10864 if (exidx_arm_data
== NULL
)
10867 ibfd
= exidx_sec
->owner
;
10869 if (hdr
->contents
!= NULL
)
10870 contents
= hdr
->contents
;
10871 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
10875 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
10877 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
10881 /* An EXIDX_CANTUNWIND entry. */
10882 if (second_word
== 1)
10884 if (last_unwind_type
== 0)
10888 /* Inlined unwinding data. Merge if equal to previous. */
10889 else if ((second_word
& 0x80000000) != 0)
10891 if (merge_exidx_entries
10892 && last_second_word
== second_word
&& last_unwind_type
== 1)
10895 last_second_word
= second_word
;
10897 /* Normal table entry. In theory we could merge these too,
10898 but duplicate entries are likely to be much less common. */
10904 add_unwind_table_edit (&unwind_edit_head
, &unwind_edit_tail
,
10905 DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
10907 deleted_exidx_bytes
+= 8;
10910 last_unwind_type
= unwind_type
;
10913 /* Free contents if we allocated it ourselves. */
10914 if (contents
!= hdr
->contents
)
10917 /* Record edits to be applied later (in elf32_arm_write_section). */
10918 exidx_arm_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
10919 exidx_arm_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
10921 if (deleted_exidx_bytes
> 0)
10922 adjust_exidx_size(exidx_sec
, -deleted_exidx_bytes
);
10924 last_exidx_sec
= exidx_sec
;
10925 last_text_sec
= sec
;
10928 /* Add terminating CANTUNWIND entry. */
10929 if (last_exidx_sec
&& last_unwind_type
!= 0)
10930 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
10936 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
10937 bfd
*ibfd
, const char *name
)
10939 asection
*sec
, *osec
;
10941 sec
= bfd_get_linker_section (ibfd
, name
);
10942 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
10945 osec
= sec
->output_section
;
10946 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
10949 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
10950 sec
->output_offset
, sec
->size
))
10957 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10959 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
10960 asection
*sec
, *osec
;
10962 if (globals
== NULL
)
10965 /* Invoke the regular ELF backend linker to do all the work. */
10966 if (!bfd_elf_final_link (abfd
, info
))
10969 /* Process stub sections (eg BE8 encoding, ...). */
10970 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
10972 for (i
=0; i
<htab
->top_id
; i
++)
10974 sec
= htab
->stub_group
[i
].stub_sec
;
10975 /* Only process it once, in its link_sec slot. */
10976 if (sec
&& i
== htab
->stub_group
[i
].link_sec
->id
)
10978 osec
= sec
->output_section
;
10979 elf32_arm_write_section (abfd
, info
, sec
, sec
->contents
);
10980 if (! bfd_set_section_contents (abfd
, osec
, sec
->contents
,
10981 sec
->output_offset
, sec
->size
))
10986 /* Write out any glue sections now that we have created all the
10988 if (globals
->bfd_of_glue_owner
!= NULL
)
10990 if (! elf32_arm_output_glue_section (info
, abfd
,
10991 globals
->bfd_of_glue_owner
,
10992 ARM2THUMB_GLUE_SECTION_NAME
))
10995 if (! elf32_arm_output_glue_section (info
, abfd
,
10996 globals
->bfd_of_glue_owner
,
10997 THUMB2ARM_GLUE_SECTION_NAME
))
11000 if (! elf32_arm_output_glue_section (info
, abfd
,
11001 globals
->bfd_of_glue_owner
,
11002 VFP11_ERRATUM_VENEER_SECTION_NAME
))
11005 if (! elf32_arm_output_glue_section (info
, abfd
,
11006 globals
->bfd_of_glue_owner
,
11007 ARM_BX_GLUE_SECTION_NAME
))
11014 /* Return a best guess for the machine number based on the attributes. */
11016 static unsigned int
11017 bfd_arm_get_mach_from_attributes (bfd
* abfd
)
11019 int arch
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
11023 case TAG_CPU_ARCH_V4
: return bfd_mach_arm_4
;
11024 case TAG_CPU_ARCH_V4T
: return bfd_mach_arm_4T
;
11025 case TAG_CPU_ARCH_V5T
: return bfd_mach_arm_5T
;
11027 case TAG_CPU_ARCH_V5TE
:
11031 BFD_ASSERT (Tag_CPU_name
< NUM_KNOWN_OBJ_ATTRIBUTES
);
11032 name
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_CPU_name
].s
;
11036 if (strcmp (name
, "IWMMXT2") == 0)
11037 return bfd_mach_arm_iWMMXt2
;
11039 if (strcmp (name
, "IWMMXT") == 0)
11040 return bfd_mach_arm_iWMMXt
;
11042 if (strcmp (name
, "XSCALE") == 0)
11046 BFD_ASSERT (Tag_WMMX_arch
< NUM_KNOWN_OBJ_ATTRIBUTES
);
11047 wmmx
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_WMMX_arch
].i
;
11050 case 1: return bfd_mach_arm_iWMMXt
;
11051 case 2: return bfd_mach_arm_iWMMXt2
;
11052 default: return bfd_mach_arm_XScale
;
11057 return bfd_mach_arm_5TE
;
11061 return bfd_mach_arm_unknown
;
11065 /* Set the right machine number. */
11068 elf32_arm_object_p (bfd
*abfd
)
11072 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
11074 if (mach
== bfd_mach_arm_unknown
)
11076 if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
11077 mach
= bfd_mach_arm_ep9312
;
11079 mach
= bfd_arm_get_mach_from_attributes (abfd
);
11082 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
11086 /* Function to keep ARM specific flags in the ELF header. */
11089 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
11091 if (elf_flags_init (abfd
)
11092 && elf_elfheader (abfd
)->e_flags
!= flags
)
11094 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
11096 if (flags
& EF_ARM_INTERWORK
)
11097 (*_bfd_error_handler
)
11098 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
11102 (_("Warning: Clearing the interworking flag of %B due to outside request"),
11108 elf_elfheader (abfd
)->e_flags
= flags
;
11109 elf_flags_init (abfd
) = TRUE
;
11115 /* Copy backend specific data from one object module to another. */
11118 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11121 flagword out_flags
;
11123 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
11126 in_flags
= elf_elfheader (ibfd
)->e_flags
;
11127 out_flags
= elf_elfheader (obfd
)->e_flags
;
11129 if (elf_flags_init (obfd
)
11130 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
11131 && in_flags
!= out_flags
)
11133 /* Cannot mix APCS26 and APCS32 code. */
11134 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
11137 /* Cannot mix float APCS and non-float APCS code. */
11138 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
11141 /* If the src and dest have different interworking flags
11142 then turn off the interworking bit. */
11143 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
11145 if (out_flags
& EF_ARM_INTERWORK
)
11147 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
11150 in_flags
&= ~EF_ARM_INTERWORK
;
11153 /* Likewise for PIC, though don't warn for this case. */
11154 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
11155 in_flags
&= ~EF_ARM_PIC
;
11158 elf_elfheader (obfd
)->e_flags
= in_flags
;
11159 elf_flags_init (obfd
) = TRUE
;
11161 /* Also copy the EI_OSABI field. */
11162 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
11163 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
11165 /* Copy object attributes. */
11166 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11171 /* Values for Tag_ABI_PCS_R9_use. */
11180 /* Values for Tag_ABI_PCS_RW_data. */
11183 AEABI_PCS_RW_data_absolute
,
11184 AEABI_PCS_RW_data_PCrel
,
11185 AEABI_PCS_RW_data_SBrel
,
11186 AEABI_PCS_RW_data_unused
11189 /* Values for Tag_ABI_enum_size. */
11195 AEABI_enum_forced_wide
11198 /* Determine whether an object attribute tag takes an integer, a
11202 elf32_arm_obj_attrs_arg_type (int tag
)
11204 if (tag
== Tag_compatibility
)
11205 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
11206 else if (tag
== Tag_nodefaults
)
11207 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
11208 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
11209 return ATTR_TYPE_FLAG_STR_VAL
;
11211 return ATTR_TYPE_FLAG_INT_VAL
;
11213 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
11216 /* The ABI defines that Tag_conformance should be emitted first, and that
11217 Tag_nodefaults should be second (if either is defined). This sets those
11218 two positions, and bumps up the position of all the remaining tags to
11221 elf32_arm_obj_attrs_order (int num
)
11223 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
11224 return Tag_conformance
;
11225 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
+ 1)
11226 return Tag_nodefaults
;
11227 if ((num
- 2) < Tag_nodefaults
)
11229 if ((num
- 1) < Tag_conformance
)
11234 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
11236 elf32_arm_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
11238 if ((tag
& 127) < 64)
11241 (_("%B: Unknown mandatory EABI object attribute %d"),
11243 bfd_set_error (bfd_error_bad_value
);
11249 (_("Warning: %B: Unknown EABI object attribute %d"),
11255 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
11256 Returns -1 if no architecture could be read. */
11259 get_secondary_compatible_arch (bfd
*abfd
)
11261 obj_attribute
*attr
=
11262 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
11264 /* Note: the tag and its argument below are uleb128 values, though
11265 currently-defined values fit in one byte for each. */
11267 && attr
->s
[0] == Tag_CPU_arch
11268 && (attr
->s
[1] & 128) != 128
11269 && attr
->s
[2] == 0)
11272 /* This tag is "safely ignorable", so don't complain if it looks funny. */
11276 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
11277 The tag is removed if ARCH is -1. */
11280 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
11282 obj_attribute
*attr
=
11283 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
11291 /* Note: the tag and its argument below are uleb128 values, though
11292 currently-defined values fit in one byte for each. */
11294 attr
->s
= (char *) bfd_alloc (abfd
, 3);
11295 attr
->s
[0] = Tag_CPU_arch
;
11300 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
11304 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
11305 int newtag
, int secondary_compat
)
11307 #define T(X) TAG_CPU_ARCH_##X
11308 int tagl
, tagh
, result
;
11311 T(V6T2
), /* PRE_V4. */
11313 T(V6T2
), /* V4T. */
11314 T(V6T2
), /* V5T. */
11315 T(V6T2
), /* V5TE. */
11316 T(V6T2
), /* V5TEJ. */
11319 T(V6T2
) /* V6T2. */
11323 T(V6K
), /* PRE_V4. */
11327 T(V6K
), /* V5TE. */
11328 T(V6K
), /* V5TEJ. */
11330 T(V6KZ
), /* V6KZ. */
11336 T(V7
), /* PRE_V4. */
11341 T(V7
), /* V5TEJ. */
11354 T(V6K
), /* V5TE. */
11355 T(V6K
), /* V5TEJ. */
11357 T(V6KZ
), /* V6KZ. */
11361 T(V6_M
) /* V6_M. */
11363 const int v6s_m
[] =
11369 T(V6K
), /* V5TE. */
11370 T(V6K
), /* V5TEJ. */
11372 T(V6KZ
), /* V6KZ. */
11376 T(V6S_M
), /* V6_M. */
11377 T(V6S_M
) /* V6S_M. */
11379 const int v7e_m
[] =
11383 T(V7E_M
), /* V4T. */
11384 T(V7E_M
), /* V5T. */
11385 T(V7E_M
), /* V5TE. */
11386 T(V7E_M
), /* V5TEJ. */
11387 T(V7E_M
), /* V6. */
11388 T(V7E_M
), /* V6KZ. */
11389 T(V7E_M
), /* V6T2. */
11390 T(V7E_M
), /* V6K. */
11391 T(V7E_M
), /* V7. */
11392 T(V7E_M
), /* V6_M. */
11393 T(V7E_M
), /* V6S_M. */
11394 T(V7E_M
) /* V7E_M. */
11398 T(V8
), /* PRE_V4. */
11403 T(V8
), /* V5TEJ. */
11410 T(V8
), /* V6S_M. */
11411 T(V8
), /* V7E_M. */
11414 const int v4t_plus_v6_m
[] =
11420 T(V5TE
), /* V5TE. */
11421 T(V5TEJ
), /* V5TEJ. */
11423 T(V6KZ
), /* V6KZ. */
11424 T(V6T2
), /* V6T2. */
11427 T(V6_M
), /* V6_M. */
11428 T(V6S_M
), /* V6S_M. */
11429 T(V7E_M
), /* V7E_M. */
11431 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
11433 const int *comb
[] =
11442 /* Pseudo-architecture. */
11446 /* Check we've not got a higher architecture than we know about. */
11448 if (oldtag
> MAX_TAG_CPU_ARCH
|| newtag
> MAX_TAG_CPU_ARCH
)
11450 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd
);
11454 /* Override old tag if we have a Tag_also_compatible_with on the output. */
11456 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
11457 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
11458 oldtag
= T(V4T_PLUS_V6_M
);
11460 /* And override the new tag if we have a Tag_also_compatible_with on the
11463 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
11464 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
11465 newtag
= T(V4T_PLUS_V6_M
);
11467 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
11468 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
11470 /* Architectures before V6KZ add features monotonically. */
11471 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
11474 result
= comb
[tagh
- T(V6T2
)][tagl
];
11476 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
11477 as the canonical version. */
11478 if (result
== T(V4T_PLUS_V6_M
))
11481 *secondary_compat_out
= T(V6_M
);
11484 *secondary_compat_out
= -1;
11488 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
11489 ibfd
, oldtag
, newtag
);
11497 /* Query attributes object to see if integer divide instructions may be
11498 present in an object. */
11500 elf32_arm_attributes_accept_div (const obj_attribute
*attr
)
11502 int arch
= attr
[Tag_CPU_arch
].i
;
11503 int profile
= attr
[Tag_CPU_arch_profile
].i
;
11505 switch (attr
[Tag_DIV_use
].i
)
11508 /* Integer divide allowed if instruction contained in archetecture. */
11509 if (arch
== TAG_CPU_ARCH_V7
&& (profile
== 'R' || profile
== 'M'))
11511 else if (arch
>= TAG_CPU_ARCH_V7E_M
)
11517 /* Integer divide explicitly prohibited. */
11521 /* Unrecognised case - treat as allowing divide everywhere. */
11523 /* Integer divide allowed in ARM state. */
11528 /* Query attributes object to see if integer divide instructions are
11529 forbidden to be in the object. This is not the inverse of
11530 elf32_arm_attributes_accept_div. */
11532 elf32_arm_attributes_forbid_div (const obj_attribute
*attr
)
11534 return attr
[Tag_DIV_use
].i
== 1;
11537 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
11538 are conflicting attributes. */
11541 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
11543 obj_attribute
*in_attr
;
11544 obj_attribute
*out_attr
;
11545 /* Some tags have 0 = don't care, 1 = strong requirement,
11546 2 = weak requirement. */
11547 static const int order_021
[3] = {0, 2, 1};
11549 bfd_boolean result
= TRUE
;
11551 /* Skip the linker stubs file. This preserves previous behavior
11552 of accepting unknown attributes in the first input file - but
11554 if (ibfd
->flags
& BFD_LINKER_CREATED
)
11557 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11559 /* This is the first object. Copy the attributes. */
11560 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11562 out_attr
= elf_known_obj_attributes_proc (obfd
);
11564 /* Use the Tag_null value to indicate the attributes have been
11568 /* We do not output objects with Tag_MPextension_use_legacy - we move
11569 the attribute's value to Tag_MPextension_use. */
11570 if (out_attr
[Tag_MPextension_use_legacy
].i
!= 0)
11572 if (out_attr
[Tag_MPextension_use
].i
!= 0
11573 && out_attr
[Tag_MPextension_use_legacy
].i
11574 != out_attr
[Tag_MPextension_use
].i
)
11577 (_("Error: %B has both the current and legacy "
11578 "Tag_MPextension_use attributes"), ibfd
);
11582 out_attr
[Tag_MPextension_use
] =
11583 out_attr
[Tag_MPextension_use_legacy
];
11584 out_attr
[Tag_MPextension_use_legacy
].type
= 0;
11585 out_attr
[Tag_MPextension_use_legacy
].i
= 0;
11591 in_attr
= elf_known_obj_attributes_proc (ibfd
);
11592 out_attr
= elf_known_obj_attributes_proc (obfd
);
11593 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
11594 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
11596 /* Ignore mismatches if the object doesn't use floating point. */
11597 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
11598 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
11599 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
11602 (_("error: %B uses VFP register arguments, %B does not"),
11603 in_attr
[Tag_ABI_VFP_args
].i
? ibfd
: obfd
,
11604 in_attr
[Tag_ABI_VFP_args
].i
? obfd
: ibfd
);
11609 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
11611 /* Merge this attribute with existing attributes. */
11614 case Tag_CPU_raw_name
:
11616 /* These are merged after Tag_CPU_arch. */
11619 case Tag_ABI_optimization_goals
:
11620 case Tag_ABI_FP_optimization_goals
:
11621 /* Use the first value seen. */
11626 int secondary_compat
= -1, secondary_compat_out
= -1;
11627 unsigned int saved_out_attr
= out_attr
[i
].i
;
11628 static const char *name_table
[] = {
11629 /* These aren't real CPU names, but we can't guess
11630 that from the architecture version alone. */
11647 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
11648 secondary_compat
= get_secondary_compatible_arch (ibfd
);
11649 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
11650 out_attr
[i
].i
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
11651 &secondary_compat_out
,
11654 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
11656 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
11657 if (out_attr
[i
].i
== saved_out_attr
)
11658 ; /* Leave the names alone. */
11659 else if (out_attr
[i
].i
== in_attr
[i
].i
)
11661 /* The output architecture has been changed to match the
11662 input architecture. Use the input names. */
11663 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
11664 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
11666 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
11667 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
11672 out_attr
[Tag_CPU_name
].s
= NULL
;
11673 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
11676 /* If we still don't have a value for Tag_CPU_name,
11677 make one up now. Tag_CPU_raw_name remains blank. */
11678 if (out_attr
[Tag_CPU_name
].s
== NULL
11679 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
11680 out_attr
[Tag_CPU_name
].s
=
11681 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
11685 case Tag_ARM_ISA_use
:
11686 case Tag_THUMB_ISA_use
:
11687 case Tag_WMMX_arch
:
11688 case Tag_Advanced_SIMD_arch
:
11689 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
11690 case Tag_ABI_FP_rounding
:
11691 case Tag_ABI_FP_exceptions
:
11692 case Tag_ABI_FP_user_exceptions
:
11693 case Tag_ABI_FP_number_model
:
11694 case Tag_FP_HP_extension
:
11695 case Tag_CPU_unaligned_access
:
11697 case Tag_MPextension_use
:
11698 /* Use the largest value specified. */
11699 if (in_attr
[i
].i
> out_attr
[i
].i
)
11700 out_attr
[i
].i
= in_attr
[i
].i
;
11703 case Tag_ABI_align_preserved
:
11704 case Tag_ABI_PCS_RO_data
:
11705 /* Use the smallest value specified. */
11706 if (in_attr
[i
].i
< out_attr
[i
].i
)
11707 out_attr
[i
].i
= in_attr
[i
].i
;
11710 case Tag_ABI_align_needed
:
11711 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
11712 && (in_attr
[Tag_ABI_align_preserved
].i
== 0
11713 || out_attr
[Tag_ABI_align_preserved
].i
== 0))
11715 /* This error message should be enabled once all non-conformant
11716 binaries in the toolchain have had the attributes set
11719 (_("error: %B: 8-byte data alignment conflicts with %B"),
11723 /* Fall through. */
11724 case Tag_ABI_FP_denormal
:
11725 case Tag_ABI_PCS_GOT_use
:
11726 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
11727 value if greater than 2 (for future-proofing). */
11728 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
11729 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
11730 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
11731 out_attr
[i
].i
= in_attr
[i
].i
;
11734 case Tag_Virtualization_use
:
11735 /* The virtualization tag effectively stores two bits of
11736 information: the intended use of TrustZone (in bit 0), and the
11737 intended use of Virtualization (in bit 1). */
11738 if (out_attr
[i
].i
== 0)
11739 out_attr
[i
].i
= in_attr
[i
].i
;
11740 else if (in_attr
[i
].i
!= 0
11741 && in_attr
[i
].i
!= out_attr
[i
].i
)
11743 if (in_attr
[i
].i
<= 3 && out_attr
[i
].i
<= 3)
11748 (_("error: %B: unable to merge virtualization attributes "
11756 case Tag_CPU_arch_profile
:
11757 if (out_attr
[i
].i
!= in_attr
[i
].i
)
11759 /* 0 will merge with anything.
11760 'A' and 'S' merge to 'A'.
11761 'R' and 'S' merge to 'R'.
11762 'M' and 'A|R|S' is an error. */
11763 if (out_attr
[i
].i
== 0
11764 || (out_attr
[i
].i
== 'S'
11765 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
11766 out_attr
[i
].i
= in_attr
[i
].i
;
11767 else if (in_attr
[i
].i
== 0
11768 || (in_attr
[i
].i
== 'S'
11769 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
11770 ; /* Do nothing. */
11774 (_("error: %B: Conflicting architecture profiles %c/%c"),
11776 in_attr
[i
].i
? in_attr
[i
].i
: '0',
11777 out_attr
[i
].i
? out_attr
[i
].i
: '0');
11784 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
11785 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
11786 when it's 0. It might mean absence of FP hardware if
11787 Tag_FP_arch is zero, otherwise it is effectively SP + DP. */
11789 #define VFP_VERSION_COUNT 8
11790 static const struct
11794 } vfp_versions
[VFP_VERSION_COUNT
] =
11809 /* If the output has no requirement about FP hardware,
11810 follow the requirement of the input. */
11811 if (out_attr
[i
].i
== 0)
11813 BFD_ASSERT (out_attr
[Tag_ABI_HardFP_use
].i
== 0);
11814 out_attr
[i
].i
= in_attr
[i
].i
;
11815 out_attr
[Tag_ABI_HardFP_use
].i
11816 = in_attr
[Tag_ABI_HardFP_use
].i
;
11819 /* If the input has no requirement about FP hardware, do
11821 else if (in_attr
[i
].i
== 0)
11823 BFD_ASSERT (in_attr
[Tag_ABI_HardFP_use
].i
== 0);
11827 /* Both the input and the output have nonzero Tag_FP_arch.
11828 So Tag_ABI_HardFP_use is (SP & DP) when it's zero. */
11830 /* If both the input and the output have zero Tag_ABI_HardFP_use,
11832 if (in_attr
[Tag_ABI_HardFP_use
].i
== 0
11833 && out_attr
[Tag_ABI_HardFP_use
].i
== 0)
11835 /* If the input and the output have different Tag_ABI_HardFP_use,
11836 the combination of them is 3 (SP & DP). */
11837 else if (in_attr
[Tag_ABI_HardFP_use
].i
11838 != out_attr
[Tag_ABI_HardFP_use
].i
)
11839 out_attr
[Tag_ABI_HardFP_use
].i
= 3;
11841 /* Now we can handle Tag_FP_arch. */
11843 /* Values of VFP_VERSION_COUNT or more aren't defined, so just
11844 pick the biggest. */
11845 if (in_attr
[i
].i
>= VFP_VERSION_COUNT
11846 && in_attr
[i
].i
> out_attr
[i
].i
)
11848 out_attr
[i
] = in_attr
[i
];
11851 /* The output uses the superset of input features
11852 (ISA version) and registers. */
11853 ver
= vfp_versions
[in_attr
[i
].i
].ver
;
11854 if (ver
< vfp_versions
[out_attr
[i
].i
].ver
)
11855 ver
= vfp_versions
[out_attr
[i
].i
].ver
;
11856 regs
= vfp_versions
[in_attr
[i
].i
].regs
;
11857 if (regs
< vfp_versions
[out_attr
[i
].i
].regs
)
11858 regs
= vfp_versions
[out_attr
[i
].i
].regs
;
11859 /* This assumes all possible supersets are also a valid
11861 for (newval
= VFP_VERSION_COUNT
- 1; newval
> 0; newval
--)
11863 if (regs
== vfp_versions
[newval
].regs
11864 && ver
== vfp_versions
[newval
].ver
)
11867 out_attr
[i
].i
= newval
;
11870 case Tag_PCS_config
:
11871 if (out_attr
[i
].i
== 0)
11872 out_attr
[i
].i
= in_attr
[i
].i
;
11873 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= in_attr
[i
].i
)
11875 /* It's sometimes ok to mix different configs, so this is only
11878 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
11881 case Tag_ABI_PCS_R9_use
:
11882 if (in_attr
[i
].i
!= out_attr
[i
].i
11883 && out_attr
[i
].i
!= AEABI_R9_unused
11884 && in_attr
[i
].i
!= AEABI_R9_unused
)
11887 (_("error: %B: Conflicting use of R9"), ibfd
);
11890 if (out_attr
[i
].i
== AEABI_R9_unused
)
11891 out_attr
[i
].i
= in_attr
[i
].i
;
11893 case Tag_ABI_PCS_RW_data
:
11894 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
11895 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
11896 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
11899 (_("error: %B: SB relative addressing conflicts with use of R9"),
11903 /* Use the smallest value specified. */
11904 if (in_attr
[i
].i
< out_attr
[i
].i
)
11905 out_attr
[i
].i
= in_attr
[i
].i
;
11907 case Tag_ABI_PCS_wchar_t
:
11908 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
11909 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
11912 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
11913 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
11915 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
11916 out_attr
[i
].i
= in_attr
[i
].i
;
11918 case Tag_ABI_enum_size
:
11919 if (in_attr
[i
].i
!= AEABI_enum_unused
)
11921 if (out_attr
[i
].i
== AEABI_enum_unused
11922 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
11924 /* The existing object is compatible with anything.
11925 Use whatever requirements the new object has. */
11926 out_attr
[i
].i
= in_attr
[i
].i
;
11928 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
11929 && out_attr
[i
].i
!= in_attr
[i
].i
11930 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
11932 static const char *aeabi_enum_names
[] =
11933 { "", "variable-size", "32-bit", "" };
11934 const char *in_name
=
11935 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
11936 ? aeabi_enum_names
[in_attr
[i
].i
]
11938 const char *out_name
=
11939 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
11940 ? aeabi_enum_names
[out_attr
[i
].i
]
11943 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
11944 ibfd
, in_name
, out_name
);
11948 case Tag_ABI_VFP_args
:
11951 case Tag_ABI_WMMX_args
:
11952 if (in_attr
[i
].i
!= out_attr
[i
].i
)
11955 (_("error: %B uses iWMMXt register arguments, %B does not"),
11960 case Tag_compatibility
:
11961 /* Merged in target-independent code. */
11963 case Tag_ABI_HardFP_use
:
11964 /* This is handled along with Tag_FP_arch. */
11966 case Tag_ABI_FP_16bit_format
:
11967 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
11969 if (in_attr
[i
].i
!= out_attr
[i
].i
)
11972 (_("error: fp16 format mismatch between %B and %B"),
11977 if (in_attr
[i
].i
!= 0)
11978 out_attr
[i
].i
= in_attr
[i
].i
;
11982 /* A value of zero on input means that the divide instruction may
11983 be used if available in the base architecture as specified via
11984 Tag_CPU_arch and Tag_CPU_arch_profile. A value of 1 means that
11985 the user did not want divide instructions. A value of 2
11986 explicitly means that divide instructions were allowed in ARM
11987 and Thumb state. */
11988 if (in_attr
[i
].i
== out_attr
[i
].i
)
11989 /* Do nothing. */ ;
11990 else if (elf32_arm_attributes_forbid_div (in_attr
)
11991 && !elf32_arm_attributes_accept_div (out_attr
))
11993 else if (elf32_arm_attributes_forbid_div (out_attr
)
11994 && elf32_arm_attributes_accept_div (in_attr
))
11995 out_attr
[i
].i
= in_attr
[i
].i
;
11996 else if (in_attr
[i
].i
== 2)
11997 out_attr
[i
].i
= in_attr
[i
].i
;
12000 case Tag_MPextension_use_legacy
:
12001 /* We don't output objects with Tag_MPextension_use_legacy - we
12002 move the value to Tag_MPextension_use. */
12003 if (in_attr
[i
].i
!= 0 && in_attr
[Tag_MPextension_use
].i
!= 0)
12005 if (in_attr
[Tag_MPextension_use
].i
!= in_attr
[i
].i
)
12008 (_("%B has has both the current and legacy "
12009 "Tag_MPextension_use attributes"),
12015 if (in_attr
[i
].i
> out_attr
[Tag_MPextension_use
].i
)
12016 out_attr
[Tag_MPextension_use
] = in_attr
[i
];
12020 case Tag_nodefaults
:
12021 /* This tag is set if it exists, but the value is unused (and is
12022 typically zero). We don't actually need to do anything here -
12023 the merge happens automatically when the type flags are merged
12026 case Tag_also_compatible_with
:
12027 /* Already done in Tag_CPU_arch. */
12029 case Tag_conformance
:
12030 /* Keep the attribute if it matches. Throw it away otherwise.
12031 No attribute means no claim to conform. */
12032 if (!in_attr
[i
].s
|| !out_attr
[i
].s
12033 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
12034 out_attr
[i
].s
= NULL
;
12039 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
12042 /* If out_attr was copied from in_attr then it won't have a type yet. */
12043 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
12044 out_attr
[i
].type
= in_attr
[i
].type
;
12047 /* Merge Tag_compatibility attributes and any common GNU ones. */
12048 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
12051 /* Check for any attributes not known on ARM. */
12052 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
12058 /* Return TRUE if the two EABI versions are incompatible. */
12061 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
12063 /* v4 and v5 are the same spec before and after it was released,
12064 so allow mixing them. */
12065 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
12066 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
12069 return (iver
== over
);
12072 /* Merge backend specific data from an object file to the output
12073 object file when linking. */
12076 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
);
12078 /* Display the flags field. */
12081 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
12083 FILE * file
= (FILE *) ptr
;
12084 unsigned long flags
;
12086 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12088 /* Print normal ELF private data. */
12089 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12091 flags
= elf_elfheader (abfd
)->e_flags
;
12092 /* Ignore init flag - it may not be set, despite the flags field
12093 containing valid data. */
12095 /* xgettext:c-format */
12096 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12098 switch (EF_ARM_EABI_VERSION (flags
))
12100 case EF_ARM_EABI_UNKNOWN
:
12101 /* The following flag bits are GNU extensions and not part of the
12102 official ARM ELF extended ABI. Hence they are only decoded if
12103 the EABI version is not set. */
12104 if (flags
& EF_ARM_INTERWORK
)
12105 fprintf (file
, _(" [interworking enabled]"));
12107 if (flags
& EF_ARM_APCS_26
)
12108 fprintf (file
, " [APCS-26]");
12110 fprintf (file
, " [APCS-32]");
12112 if (flags
& EF_ARM_VFP_FLOAT
)
12113 fprintf (file
, _(" [VFP float format]"));
12114 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
12115 fprintf (file
, _(" [Maverick float format]"));
12117 fprintf (file
, _(" [FPA float format]"));
12119 if (flags
& EF_ARM_APCS_FLOAT
)
12120 fprintf (file
, _(" [floats passed in float registers]"));
12122 if (flags
& EF_ARM_PIC
)
12123 fprintf (file
, _(" [position independent]"));
12125 if (flags
& EF_ARM_NEW_ABI
)
12126 fprintf (file
, _(" [new ABI]"));
12128 if (flags
& EF_ARM_OLD_ABI
)
12129 fprintf (file
, _(" [old ABI]"));
12131 if (flags
& EF_ARM_SOFT_FLOAT
)
12132 fprintf (file
, _(" [software FP]"));
12134 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
12135 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
12136 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
12137 | EF_ARM_MAVERICK_FLOAT
);
12140 case EF_ARM_EABI_VER1
:
12141 fprintf (file
, _(" [Version1 EABI]"));
12143 if (flags
& EF_ARM_SYMSARESORTED
)
12144 fprintf (file
, _(" [sorted symbol table]"));
12146 fprintf (file
, _(" [unsorted symbol table]"));
12148 flags
&= ~ EF_ARM_SYMSARESORTED
;
12151 case EF_ARM_EABI_VER2
:
12152 fprintf (file
, _(" [Version2 EABI]"));
12154 if (flags
& EF_ARM_SYMSARESORTED
)
12155 fprintf (file
, _(" [sorted symbol table]"));
12157 fprintf (file
, _(" [unsorted symbol table]"));
12159 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
12160 fprintf (file
, _(" [dynamic symbols use segment index]"));
12162 if (flags
& EF_ARM_MAPSYMSFIRST
)
12163 fprintf (file
, _(" [mapping symbols precede others]"));
12165 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
12166 | EF_ARM_MAPSYMSFIRST
);
12169 case EF_ARM_EABI_VER3
:
12170 fprintf (file
, _(" [Version3 EABI]"));
12173 case EF_ARM_EABI_VER4
:
12174 fprintf (file
, _(" [Version4 EABI]"));
12177 case EF_ARM_EABI_VER5
:
12178 fprintf (file
, _(" [Version5 EABI]"));
12180 if (flags
& EF_ARM_ABI_FLOAT_SOFT
)
12181 fprintf (file
, _(" [soft-float ABI]"));
12183 if (flags
& EF_ARM_ABI_FLOAT_HARD
)
12184 fprintf (file
, _(" [hard-float ABI]"));
12186 flags
&= ~(EF_ARM_ABI_FLOAT_SOFT
| EF_ARM_ABI_FLOAT_HARD
);
12189 if (flags
& EF_ARM_BE8
)
12190 fprintf (file
, _(" [BE8]"));
12192 if (flags
& EF_ARM_LE8
)
12193 fprintf (file
, _(" [LE8]"));
12195 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
12199 fprintf (file
, _(" <EABI version unrecognised>"));
12203 flags
&= ~ EF_ARM_EABIMASK
;
12205 if (flags
& EF_ARM_RELEXEC
)
12206 fprintf (file
, _(" [relocatable executable]"));
12208 if (flags
& EF_ARM_HASENTRY
)
12209 fprintf (file
, _(" [has entry point]"));
12211 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
12214 fprintf (file
, _("<Unrecognised flag bits set>"));
12216 fputc ('\n', file
);
12222 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
12224 switch (ELF_ST_TYPE (elf_sym
->st_info
))
12226 case STT_ARM_TFUNC
:
12227 return ELF_ST_TYPE (elf_sym
->st_info
);
12229 case STT_ARM_16BIT
:
12230 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
12231 This allows us to distinguish between data used by Thumb instructions
12232 and non-data (which is probably code) inside Thumb regions of an
12234 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
12235 return ELF_ST_TYPE (elf_sym
->st_info
);
12246 elf32_arm_gc_mark_hook (asection
*sec
,
12247 struct bfd_link_info
*info
,
12248 Elf_Internal_Rela
*rel
,
12249 struct elf_link_hash_entry
*h
,
12250 Elf_Internal_Sym
*sym
)
12253 switch (ELF32_R_TYPE (rel
->r_info
))
12255 case R_ARM_GNU_VTINHERIT
:
12256 case R_ARM_GNU_VTENTRY
:
12260 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
12263 /* Update the got entry reference counts for the section being removed. */
12266 elf32_arm_gc_sweep_hook (bfd
* abfd
,
12267 struct bfd_link_info
* info
,
12269 const Elf_Internal_Rela
* relocs
)
12271 Elf_Internal_Shdr
*symtab_hdr
;
12272 struct elf_link_hash_entry
**sym_hashes
;
12273 bfd_signed_vma
*local_got_refcounts
;
12274 const Elf_Internal_Rela
*rel
, *relend
;
12275 struct elf32_arm_link_hash_table
* globals
;
12277 if (info
->relocatable
)
12280 globals
= elf32_arm_hash_table (info
);
12281 if (globals
== NULL
)
12284 elf_section_data (sec
)->local_dynrel
= NULL
;
12286 symtab_hdr
= & elf_symtab_hdr (abfd
);
12287 sym_hashes
= elf_sym_hashes (abfd
);
12288 local_got_refcounts
= elf_local_got_refcounts (abfd
);
12290 check_use_blx (globals
);
12292 relend
= relocs
+ sec
->reloc_count
;
12293 for (rel
= relocs
; rel
< relend
; rel
++)
12295 unsigned long r_symndx
;
12296 struct elf_link_hash_entry
*h
= NULL
;
12297 struct elf32_arm_link_hash_entry
*eh
;
12299 bfd_boolean call_reloc_p
;
12300 bfd_boolean may_become_dynamic_p
;
12301 bfd_boolean may_need_local_target_p
;
12302 union gotplt_union
*root_plt
;
12303 struct arm_plt_info
*arm_plt
;
12305 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12306 if (r_symndx
>= symtab_hdr
->sh_info
)
12308 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
12309 while (h
->root
.type
== bfd_link_hash_indirect
12310 || h
->root
.type
== bfd_link_hash_warning
)
12311 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12313 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12315 call_reloc_p
= FALSE
;
12316 may_become_dynamic_p
= FALSE
;
12317 may_need_local_target_p
= FALSE
;
12319 r_type
= ELF32_R_TYPE (rel
->r_info
);
12320 r_type
= arm_real_reloc_type (globals
, r_type
);
12324 case R_ARM_GOT_PREL
:
12325 case R_ARM_TLS_GD32
:
12326 case R_ARM_TLS_IE32
:
12329 if (h
->got
.refcount
> 0)
12330 h
->got
.refcount
-= 1;
12332 else if (local_got_refcounts
!= NULL
)
12334 if (local_got_refcounts
[r_symndx
] > 0)
12335 local_got_refcounts
[r_symndx
] -= 1;
12339 case R_ARM_TLS_LDM32
:
12340 globals
->tls_ldm_got
.refcount
-= 1;
12348 case R_ARM_THM_CALL
:
12349 case R_ARM_THM_JUMP24
:
12350 case R_ARM_THM_JUMP19
:
12351 call_reloc_p
= TRUE
;
12352 may_need_local_target_p
= TRUE
;
12356 if (!globals
->vxworks_p
)
12358 may_need_local_target_p
= TRUE
;
12361 /* Fall through. */
12363 case R_ARM_ABS32_NOI
:
12365 case R_ARM_REL32_NOI
:
12366 case R_ARM_MOVW_ABS_NC
:
12367 case R_ARM_MOVT_ABS
:
12368 case R_ARM_MOVW_PREL_NC
:
12369 case R_ARM_MOVT_PREL
:
12370 case R_ARM_THM_MOVW_ABS_NC
:
12371 case R_ARM_THM_MOVT_ABS
:
12372 case R_ARM_THM_MOVW_PREL_NC
:
12373 case R_ARM_THM_MOVT_PREL
:
12374 /* Should the interworking branches be here also? */
12375 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
12376 && (sec
->flags
& SEC_ALLOC
) != 0)
12379 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
12381 call_reloc_p
= TRUE
;
12382 may_need_local_target_p
= TRUE
;
12385 may_become_dynamic_p
= TRUE
;
12388 may_need_local_target_p
= TRUE
;
12395 if (may_need_local_target_p
12396 && elf32_arm_get_plt_info (abfd
, eh
, r_symndx
, &root_plt
, &arm_plt
))
12398 /* If PLT refcount book-keeping is wrong and too low, we'll
12399 see a zero value (going to -1) for the root PLT reference
12401 if (root_plt
->refcount
>= 0)
12403 BFD_ASSERT (root_plt
->refcount
!= 0);
12404 root_plt
->refcount
-= 1;
12407 /* A value of -1 means the symbol has become local, forced
12408 or seeing a hidden definition. Any other negative value
12410 BFD_ASSERT (root_plt
->refcount
== -1);
12413 arm_plt
->noncall_refcount
--;
12415 if (r_type
== R_ARM_THM_CALL
)
12416 arm_plt
->maybe_thumb_refcount
--;
12418 if (r_type
== R_ARM_THM_JUMP24
12419 || r_type
== R_ARM_THM_JUMP19
)
12420 arm_plt
->thumb_refcount
--;
12423 if (may_become_dynamic_p
)
12425 struct elf_dyn_relocs
**pp
;
12426 struct elf_dyn_relocs
*p
;
12429 pp
= &(eh
->dyn_relocs
);
12432 Elf_Internal_Sym
*isym
;
12434 isym
= bfd_sym_from_r_symndx (&globals
->sym_cache
,
12438 pp
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12442 for (; (p
= *pp
) != NULL
; pp
= &p
->next
)
12445 /* Everything must go for SEC. */
12455 /* Look through the relocs for a section during the first phase. */
12458 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
12459 asection
*sec
, const Elf_Internal_Rela
*relocs
)
12461 Elf_Internal_Shdr
*symtab_hdr
;
12462 struct elf_link_hash_entry
**sym_hashes
;
12463 const Elf_Internal_Rela
*rel
;
12464 const Elf_Internal_Rela
*rel_end
;
12467 struct elf32_arm_link_hash_table
*htab
;
12468 bfd_boolean call_reloc_p
;
12469 bfd_boolean may_become_dynamic_p
;
12470 bfd_boolean may_need_local_target_p
;
12471 unsigned long nsyms
;
12473 if (info
->relocatable
)
12476 BFD_ASSERT (is_arm_elf (abfd
));
12478 htab
= elf32_arm_hash_table (info
);
12484 /* Create dynamic sections for relocatable executables so that we can
12485 copy relocations. */
12486 if (htab
->root
.is_relocatable_executable
12487 && ! htab
->root
.dynamic_sections_created
)
12489 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
12493 if (htab
->root
.dynobj
== NULL
)
12494 htab
->root
.dynobj
= abfd
;
12495 if (!create_ifunc_sections (info
))
12498 dynobj
= htab
->root
.dynobj
;
12500 symtab_hdr
= & elf_symtab_hdr (abfd
);
12501 sym_hashes
= elf_sym_hashes (abfd
);
12502 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
12504 rel_end
= relocs
+ sec
->reloc_count
;
12505 for (rel
= relocs
; rel
< rel_end
; rel
++)
12507 Elf_Internal_Sym
*isym
;
12508 struct elf_link_hash_entry
*h
;
12509 struct elf32_arm_link_hash_entry
*eh
;
12510 unsigned long r_symndx
;
12513 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12514 r_type
= ELF32_R_TYPE (rel
->r_info
);
12515 r_type
= arm_real_reloc_type (htab
, r_type
);
12517 if (r_symndx
>= nsyms
12518 /* PR 9934: It is possible to have relocations that do not
12519 refer to symbols, thus it is also possible to have an
12520 object file containing relocations but no symbol table. */
12521 && (r_symndx
> STN_UNDEF
|| nsyms
> 0))
12523 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
12532 if (r_symndx
< symtab_hdr
->sh_info
)
12534 /* A local symbol. */
12535 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
12542 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
12543 while (h
->root
.type
== bfd_link_hash_indirect
12544 || h
->root
.type
== bfd_link_hash_warning
)
12545 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12547 /* PR15323, ref flags aren't set for references in the
12549 h
->root
.non_ir_ref
= 1;
12553 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12555 call_reloc_p
= FALSE
;
12556 may_become_dynamic_p
= FALSE
;
12557 may_need_local_target_p
= FALSE
;
12559 /* Could be done earlier, if h were already available. */
12560 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
12564 case R_ARM_GOT_PREL
:
12565 case R_ARM_TLS_GD32
:
12566 case R_ARM_TLS_IE32
:
12567 case R_ARM_TLS_GOTDESC
:
12568 case R_ARM_TLS_DESCSEQ
:
12569 case R_ARM_THM_TLS_DESCSEQ
:
12570 case R_ARM_TLS_CALL
:
12571 case R_ARM_THM_TLS_CALL
:
12572 /* This symbol requires a global offset table entry. */
12574 int tls_type
, old_tls_type
;
12578 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
12580 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
12582 case R_ARM_TLS_GOTDESC
:
12583 case R_ARM_TLS_CALL
: case R_ARM_THM_TLS_CALL
:
12584 case R_ARM_TLS_DESCSEQ
: case R_ARM_THM_TLS_DESCSEQ
:
12585 tls_type
= GOT_TLS_GDESC
; break;
12587 default: tls_type
= GOT_NORMAL
; break;
12593 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
12597 /* This is a global offset table entry for a local symbol. */
12598 if (!elf32_arm_allocate_local_sym_info (abfd
))
12600 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
12601 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
12604 /* If a variable is accessed with both tls methods, two
12605 slots may be created. */
12606 if (GOT_TLS_GD_ANY_P (old_tls_type
)
12607 && GOT_TLS_GD_ANY_P (tls_type
))
12608 tls_type
|= old_tls_type
;
12610 /* We will already have issued an error message if there
12611 is a TLS/non-TLS mismatch, based on the symbol
12612 type. So just combine any TLS types needed. */
12613 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
12614 && tls_type
!= GOT_NORMAL
)
12615 tls_type
|= old_tls_type
;
12617 /* If the symbol is accessed in both IE and GDESC
12618 method, we're able to relax. Turn off the GDESC flag,
12619 without messing up with any other kind of tls types
12620 that may be involved */
12621 if ((tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_GDESC
))
12622 tls_type
&= ~GOT_TLS_GDESC
;
12624 if (old_tls_type
!= tls_type
)
12627 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
12629 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
12632 /* Fall through. */
12634 case R_ARM_TLS_LDM32
:
12635 if (r_type
== R_ARM_TLS_LDM32
)
12636 htab
->tls_ldm_got
.refcount
++;
12637 /* Fall through. */
12639 case R_ARM_GOTOFF32
:
12641 if (htab
->root
.sgot
== NULL
12642 && !create_got_section (htab
->root
.dynobj
, info
))
12651 case R_ARM_THM_CALL
:
12652 case R_ARM_THM_JUMP24
:
12653 case R_ARM_THM_JUMP19
:
12654 call_reloc_p
= TRUE
;
12655 may_need_local_target_p
= TRUE
;
12659 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
12660 ldr __GOTT_INDEX__ offsets. */
12661 if (!htab
->vxworks_p
)
12663 may_need_local_target_p
= TRUE
;
12666 /* Fall through. */
12668 case R_ARM_MOVW_ABS_NC
:
12669 case R_ARM_MOVT_ABS
:
12670 case R_ARM_THM_MOVW_ABS_NC
:
12671 case R_ARM_THM_MOVT_ABS
:
12674 (*_bfd_error_handler
)
12675 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
12676 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
12677 (h
) ? h
->root
.root
.string
: "a local symbol");
12678 bfd_set_error (bfd_error_bad_value
);
12682 /* Fall through. */
12684 case R_ARM_ABS32_NOI
:
12686 case R_ARM_REL32_NOI
:
12687 case R_ARM_MOVW_PREL_NC
:
12688 case R_ARM_MOVT_PREL
:
12689 case R_ARM_THM_MOVW_PREL_NC
:
12690 case R_ARM_THM_MOVT_PREL
:
12692 /* Should the interworking branches be listed here? */
12693 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
12694 && (sec
->flags
& SEC_ALLOC
) != 0)
12697 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
12699 /* In shared libraries and relocatable executables,
12700 we treat local relative references as calls;
12701 see the related SYMBOL_CALLS_LOCAL code in
12702 allocate_dynrelocs. */
12703 call_reloc_p
= TRUE
;
12704 may_need_local_target_p
= TRUE
;
12707 /* We are creating a shared library or relocatable
12708 executable, and this is a reloc against a global symbol,
12709 or a non-PC-relative reloc against a local symbol.
12710 We may need to copy the reloc into the output. */
12711 may_become_dynamic_p
= TRUE
;
12714 may_need_local_target_p
= TRUE
;
12717 /* This relocation describes the C++ object vtable hierarchy.
12718 Reconstruct it for later use during GC. */
12719 case R_ARM_GNU_VTINHERIT
:
12720 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
12724 /* This relocation describes which C++ vtable entries are actually
12725 used. Record for later use during GC. */
12726 case R_ARM_GNU_VTENTRY
:
12727 BFD_ASSERT (h
!= NULL
);
12729 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
12737 /* We may need a .plt entry if the function this reloc
12738 refers to is in a different object, regardless of the
12739 symbol's type. We can't tell for sure yet, because
12740 something later might force the symbol local. */
12742 else if (may_need_local_target_p
)
12743 /* If this reloc is in a read-only section, we might
12744 need a copy reloc. We can't check reliably at this
12745 stage whether the section is read-only, as input
12746 sections have not yet been mapped to output sections.
12747 Tentatively set the flag for now, and correct in
12748 adjust_dynamic_symbol. */
12749 h
->non_got_ref
= 1;
12752 if (may_need_local_target_p
12753 && (h
!= NULL
|| ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
))
12755 union gotplt_union
*root_plt
;
12756 struct arm_plt_info
*arm_plt
;
12757 struct arm_local_iplt_info
*local_iplt
;
12761 root_plt
= &h
->plt
;
12762 arm_plt
= &eh
->plt
;
12766 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
12767 if (local_iplt
== NULL
)
12769 root_plt
= &local_iplt
->root
;
12770 arm_plt
= &local_iplt
->arm
;
12773 /* If the symbol is a function that doesn't bind locally,
12774 this relocation will need a PLT entry. */
12775 if (root_plt
->refcount
!= -1)
12776 root_plt
->refcount
+= 1;
12779 arm_plt
->noncall_refcount
++;
12781 /* It's too early to use htab->use_blx here, so we have to
12782 record possible blx references separately from
12783 relocs that definitely need a thumb stub. */
12785 if (r_type
== R_ARM_THM_CALL
)
12786 arm_plt
->maybe_thumb_refcount
+= 1;
12788 if (r_type
== R_ARM_THM_JUMP24
12789 || r_type
== R_ARM_THM_JUMP19
)
12790 arm_plt
->thumb_refcount
+= 1;
12793 if (may_become_dynamic_p
)
12795 struct elf_dyn_relocs
*p
, **head
;
12797 /* Create a reloc section in dynobj. */
12798 if (sreloc
== NULL
)
12800 sreloc
= _bfd_elf_make_dynamic_reloc_section
12801 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
12803 if (sreloc
== NULL
)
12806 /* BPABI objects never have dynamic relocations mapped. */
12807 if (htab
->symbian_p
)
12811 flags
= bfd_get_section_flags (dynobj
, sreloc
);
12812 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
12813 bfd_set_section_flags (dynobj
, sreloc
, flags
);
12817 /* If this is a global symbol, count the number of
12818 relocations we need for this symbol. */
12820 head
= &((struct elf32_arm_link_hash_entry
*) h
)->dyn_relocs
;
12823 head
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12829 if (p
== NULL
|| p
->sec
!= sec
)
12831 bfd_size_type amt
= sizeof *p
;
12833 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->root
.dynobj
, amt
);
12843 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
12852 /* Unwinding tables are not referenced directly. This pass marks them as
12853 required if the corresponding code section is marked. */
12856 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
12857 elf_gc_mark_hook_fn gc_mark_hook
)
12860 Elf_Internal_Shdr
**elf_shdrp
;
12863 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
12865 /* Marking EH data may cause additional code sections to be marked,
12866 requiring multiple passes. */
12871 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
12875 if (! is_arm_elf (sub
))
12878 elf_shdrp
= elf_elfsections (sub
);
12879 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
12881 Elf_Internal_Shdr
*hdr
;
12883 hdr
= &elf_section_data (o
)->this_hdr
;
12884 if (hdr
->sh_type
== SHT_ARM_EXIDX
12886 && hdr
->sh_link
< elf_numsections (sub
)
12888 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
12891 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
12901 /* Treat mapping symbols as special target symbols. */
12904 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
12906 return bfd_is_arm_special_symbol_name (sym
->name
,
12907 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
12910 /* This is a copy of elf_find_function() from elf.c except that
12911 ARM mapping symbols are ignored when looking for function names
12912 and STT_ARM_TFUNC is considered to a function type. */
12915 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
12916 asection
* section
,
12917 asymbol
** symbols
,
12919 const char ** filename_ptr
,
12920 const char ** functionname_ptr
)
12922 const char * filename
= NULL
;
12923 asymbol
* func
= NULL
;
12924 bfd_vma low_func
= 0;
12927 for (p
= symbols
; *p
!= NULL
; p
++)
12929 elf_symbol_type
*q
;
12931 q
= (elf_symbol_type
*) *p
;
12933 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
12938 filename
= bfd_asymbol_name (&q
->symbol
);
12941 case STT_ARM_TFUNC
:
12943 /* Skip mapping symbols. */
12944 if ((q
->symbol
.flags
& BSF_LOCAL
)
12945 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
12946 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
12948 /* Fall through. */
12949 if (bfd_get_section (&q
->symbol
) == section
12950 && q
->symbol
.value
>= low_func
12951 && q
->symbol
.value
<= offset
)
12953 func
= (asymbol
*) q
;
12954 low_func
= q
->symbol
.value
;
12964 *filename_ptr
= filename
;
12965 if (functionname_ptr
)
12966 *functionname_ptr
= bfd_asymbol_name (func
);
12972 /* Find the nearest line to a particular section and offset, for error
12973 reporting. This code is a duplicate of the code in elf.c, except
12974 that it uses arm_elf_find_function. */
12977 elf32_arm_find_nearest_line (bfd
* abfd
,
12978 asection
* section
,
12979 asymbol
** symbols
,
12981 const char ** filename_ptr
,
12982 const char ** functionname_ptr
,
12983 unsigned int * line_ptr
)
12985 bfd_boolean found
= FALSE
;
12987 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
12989 if (_bfd_dwarf2_find_nearest_line (abfd
, dwarf_debug_sections
,
12990 section
, symbols
, offset
,
12991 filename_ptr
, functionname_ptr
,
12993 & elf_tdata (abfd
)->dwarf2_find_line_info
))
12995 if (!*functionname_ptr
)
12996 arm_elf_find_function (abfd
, section
, symbols
, offset
,
12997 *filename_ptr
? NULL
: filename_ptr
,
13003 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
13004 & found
, filename_ptr
,
13005 functionname_ptr
, line_ptr
,
13006 & elf_tdata (abfd
)->line_info
))
13009 if (found
&& (*functionname_ptr
|| *line_ptr
))
13012 if (symbols
== NULL
)
13015 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
13016 filename_ptr
, functionname_ptr
))
13024 elf32_arm_find_inliner_info (bfd
* abfd
,
13025 const char ** filename_ptr
,
13026 const char ** functionname_ptr
,
13027 unsigned int * line_ptr
)
13030 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
13031 functionname_ptr
, line_ptr
,
13032 & elf_tdata (abfd
)->dwarf2_find_line_info
);
13036 /* Adjust a symbol defined by a dynamic object and referenced by a
13037 regular object. The current definition is in some section of the
13038 dynamic object, but we're not including those sections. We have to
13039 change the definition to something the rest of the link can
13043 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
13044 struct elf_link_hash_entry
* h
)
13048 struct elf32_arm_link_hash_entry
* eh
;
13049 struct elf32_arm_link_hash_table
*globals
;
13051 globals
= elf32_arm_hash_table (info
);
13052 if (globals
== NULL
)
13055 dynobj
= elf_hash_table (info
)->dynobj
;
13057 /* Make sure we know what is going on here. */
13058 BFD_ASSERT (dynobj
!= NULL
13060 || h
->type
== STT_GNU_IFUNC
13061 || h
->u
.weakdef
!= NULL
13064 && !h
->def_regular
)));
13066 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13068 /* If this is a function, put it in the procedure linkage table. We
13069 will fill in the contents of the procedure linkage table later,
13070 when we know the address of the .got section. */
13071 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
13073 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
13074 symbol binds locally. */
13075 if (h
->plt
.refcount
<= 0
13076 || (h
->type
!= STT_GNU_IFUNC
13077 && (SYMBOL_CALLS_LOCAL (info
, h
)
13078 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
13079 && h
->root
.type
== bfd_link_hash_undefweak
))))
13081 /* This case can occur if we saw a PLT32 reloc in an input
13082 file, but the symbol was never referred to by a dynamic
13083 object, or if all references were garbage collected. In
13084 such a case, we don't actually need to build a procedure
13085 linkage table, and we can just do a PC24 reloc instead. */
13086 h
->plt
.offset
= (bfd_vma
) -1;
13087 eh
->plt
.thumb_refcount
= 0;
13088 eh
->plt
.maybe_thumb_refcount
= 0;
13089 eh
->plt
.noncall_refcount
= 0;
13097 /* It's possible that we incorrectly decided a .plt reloc was
13098 needed for an R_ARM_PC24 or similar reloc to a non-function sym
13099 in check_relocs. We can't decide accurately between function
13100 and non-function syms in check-relocs; Objects loaded later in
13101 the link may change h->type. So fix it now. */
13102 h
->plt
.offset
= (bfd_vma
) -1;
13103 eh
->plt
.thumb_refcount
= 0;
13104 eh
->plt
.maybe_thumb_refcount
= 0;
13105 eh
->plt
.noncall_refcount
= 0;
13108 /* If this is a weak symbol, and there is a real definition, the
13109 processor independent code will have arranged for us to see the
13110 real definition first, and we can just use the same value. */
13111 if (h
->u
.weakdef
!= NULL
)
13113 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
13114 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
13115 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
13116 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
13120 /* If there are no non-GOT references, we do not need a copy
13122 if (!h
->non_got_ref
)
13125 /* This is a reference to a symbol defined by a dynamic object which
13126 is not a function. */
13128 /* If we are creating a shared library, we must presume that the
13129 only references to the symbol are via the global offset table.
13130 For such cases we need not do anything here; the relocations will
13131 be handled correctly by relocate_section. Relocatable executables
13132 can reference data in shared objects directly, so we don't need to
13133 do anything here. */
13134 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
13137 /* We must allocate the symbol in our .dynbss section, which will
13138 become part of the .bss section of the executable. There will be
13139 an entry for this symbol in the .dynsym section. The dynamic
13140 object will contain position independent code, so all references
13141 from the dynamic object to this symbol will go through the global
13142 offset table. The dynamic linker will use the .dynsym entry to
13143 determine the address it must put in the global offset table, so
13144 both the dynamic object and the regular object will refer to the
13145 same memory location for the variable. */
13146 s
= bfd_get_linker_section (dynobj
, ".dynbss");
13147 BFD_ASSERT (s
!= NULL
);
13149 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
13150 copy the initial value out of the dynamic object and into the
13151 runtime process image. We need to remember the offset into the
13152 .rel(a).bss section we are going to use. */
13153 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
13157 srel
= bfd_get_linker_section (dynobj
, RELOC_SECTION (globals
, ".bss"));
13158 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
13162 return _bfd_elf_adjust_dynamic_copy (h
, s
);
13165 /* Allocate space in .plt, .got and associated reloc sections for
13169 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry
*h
, void * inf
)
13171 struct bfd_link_info
*info
;
13172 struct elf32_arm_link_hash_table
*htab
;
13173 struct elf32_arm_link_hash_entry
*eh
;
13174 struct elf_dyn_relocs
*p
;
13176 if (h
->root
.type
== bfd_link_hash_indirect
)
13179 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13181 info
= (struct bfd_link_info
*) inf
;
13182 htab
= elf32_arm_hash_table (info
);
13186 if ((htab
->root
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
13187 && h
->plt
.refcount
> 0)
13189 /* Make sure this symbol is output as a dynamic symbol.
13190 Undefined weak syms won't yet be marked as dynamic. */
13191 if (h
->dynindx
== -1
13192 && !h
->forced_local
)
13194 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13198 /* If the call in the PLT entry binds locally, the associated
13199 GOT entry should use an R_ARM_IRELATIVE relocation instead of
13200 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
13201 than the .plt section. */
13202 if (h
->type
== STT_GNU_IFUNC
&& SYMBOL_CALLS_LOCAL (info
, h
))
13205 if (eh
->plt
.noncall_refcount
== 0
13206 && SYMBOL_REFERENCES_LOCAL (info
, h
))
13207 /* All non-call references can be resolved directly.
13208 This means that they can (and in some cases, must)
13209 resolve directly to the run-time target, rather than
13210 to the PLT. That in turns means that any .got entry
13211 would be equal to the .igot.plt entry, so there's
13212 no point having both. */
13213 h
->got
.refcount
= 0;
13218 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
13220 elf32_arm_allocate_plt_entry (info
, eh
->is_iplt
, &h
->plt
, &eh
->plt
);
13222 /* If this symbol is not defined in a regular file, and we are
13223 not generating a shared library, then set the symbol to this
13224 location in the .plt. This is required to make function
13225 pointers compare as equal between the normal executable and
13226 the shared library. */
13228 && !h
->def_regular
)
13230 h
->root
.u
.def
.section
= htab
->root
.splt
;
13231 h
->root
.u
.def
.value
= h
->plt
.offset
;
13233 /* Make sure the function is not marked as Thumb, in case
13234 it is the target of an ABS32 relocation, which will
13235 point to the PLT entry. */
13236 h
->target_internal
= ST_BRANCH_TO_ARM
;
13239 htab
->next_tls_desc_index
++;
13241 /* VxWorks executables have a second set of relocations for
13242 each PLT entry. They go in a separate relocation section,
13243 which is processed by the kernel loader. */
13244 if (htab
->vxworks_p
&& !info
->shared
)
13246 /* There is a relocation for the initial PLT entry:
13247 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
13248 if (h
->plt
.offset
== htab
->plt_header_size
)
13249 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 1);
13251 /* There are two extra relocations for each subsequent
13252 PLT entry: an R_ARM_32 relocation for the GOT entry,
13253 and an R_ARM_32 relocation for the PLT entry. */
13254 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 2);
13259 h
->plt
.offset
= (bfd_vma
) -1;
13265 h
->plt
.offset
= (bfd_vma
) -1;
13269 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13270 eh
->tlsdesc_got
= (bfd_vma
) -1;
13272 if (h
->got
.refcount
> 0)
13276 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
13279 /* Make sure this symbol is output as a dynamic symbol.
13280 Undefined weak syms won't yet be marked as dynamic. */
13281 if (h
->dynindx
== -1
13282 && !h
->forced_local
)
13284 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13288 if (!htab
->symbian_p
)
13290 s
= htab
->root
.sgot
;
13291 h
->got
.offset
= s
->size
;
13293 if (tls_type
== GOT_UNKNOWN
)
13296 if (tls_type
== GOT_NORMAL
)
13297 /* Non-TLS symbols need one GOT slot. */
13301 if (tls_type
& GOT_TLS_GDESC
)
13303 /* R_ARM_TLS_DESC needs 2 GOT slots. */
13305 = (htab
->root
.sgotplt
->size
13306 - elf32_arm_compute_jump_table_size (htab
));
13307 htab
->root
.sgotplt
->size
+= 8;
13308 h
->got
.offset
= (bfd_vma
) -2;
13309 /* plt.got_offset needs to know there's a TLS_DESC
13310 reloc in the middle of .got.plt. */
13311 htab
->num_tls_desc
++;
13314 if (tls_type
& GOT_TLS_GD
)
13316 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. If
13317 the symbol is both GD and GDESC, got.offset may
13318 have been overwritten. */
13319 h
->got
.offset
= s
->size
;
13323 if (tls_type
& GOT_TLS_IE
)
13324 /* R_ARM_TLS_IE32 needs one GOT slot. */
13328 dyn
= htab
->root
.dynamic_sections_created
;
13331 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
13333 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
13336 if (tls_type
!= GOT_NORMAL
13337 && (info
->shared
|| indx
!= 0)
13338 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
13339 || h
->root
.type
!= bfd_link_hash_undefweak
))
13341 if (tls_type
& GOT_TLS_IE
)
13342 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13344 if (tls_type
& GOT_TLS_GD
)
13345 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13347 if (tls_type
& GOT_TLS_GDESC
)
13349 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
13350 /* GDESC needs a trampoline to jump to. */
13351 htab
->tls_trampoline
= -1;
13354 /* Only GD needs it. GDESC just emits one relocation per
13356 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
13357 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13359 else if (indx
!= -1 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
13361 if (htab
->root
.dynamic_sections_created
)
13362 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
13363 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13365 else if (h
->type
== STT_GNU_IFUNC
13366 && eh
->plt
.noncall_refcount
== 0)
13367 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
13368 they all resolve dynamically instead. Reserve room for the
13369 GOT entry's R_ARM_IRELATIVE relocation. */
13370 elf32_arm_allocate_irelocs (info
, htab
->root
.srelgot
, 1);
13371 else if (info
->shared
&& (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
13372 || h
->root
.type
!= bfd_link_hash_undefweak
))
13373 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
13374 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13378 h
->got
.offset
= (bfd_vma
) -1;
13380 /* Allocate stubs for exported Thumb functions on v4t. */
13381 if (!htab
->use_blx
&& h
->dynindx
!= -1
13383 && h
->target_internal
== ST_BRANCH_TO_THUMB
13384 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
13386 struct elf_link_hash_entry
* th
;
13387 struct bfd_link_hash_entry
* bh
;
13388 struct elf_link_hash_entry
* myh
;
13392 /* Create a new symbol to regist the real location of the function. */
13393 s
= h
->root
.u
.def
.section
;
13394 sprintf (name
, "__real_%s", h
->root
.root
.string
);
13395 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
13396 name
, BSF_GLOBAL
, s
,
13397 h
->root
.u
.def
.value
,
13398 NULL
, TRUE
, FALSE
, &bh
);
13400 myh
= (struct elf_link_hash_entry
*) bh
;
13401 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
13402 myh
->forced_local
= 1;
13403 myh
->target_internal
= ST_BRANCH_TO_THUMB
;
13404 eh
->export_glue
= myh
;
13405 th
= record_arm_to_thumb_glue (info
, h
);
13406 /* Point the symbol at the stub. */
13407 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
13408 h
->target_internal
= ST_BRANCH_TO_ARM
;
13409 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
13410 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
13413 if (eh
->dyn_relocs
== NULL
)
13416 /* In the shared -Bsymbolic case, discard space allocated for
13417 dynamic pc-relative relocs against symbols which turn out to be
13418 defined in regular objects. For the normal shared case, discard
13419 space for pc-relative relocs that have become local due to symbol
13420 visibility changes. */
13422 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
13424 /* The only relocs that use pc_count are R_ARM_REL32 and
13425 R_ARM_REL32_NOI, which will appear on something like
13426 ".long foo - .". We want calls to protected symbols to resolve
13427 directly to the function rather than going via the plt. If people
13428 want function pointer comparisons to work as expected then they
13429 should avoid writing assembly like ".long foo - .". */
13430 if (SYMBOL_CALLS_LOCAL (info
, h
))
13432 struct elf_dyn_relocs
**pp
;
13434 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13436 p
->count
-= p
->pc_count
;
13445 if (htab
->vxworks_p
)
13447 struct elf_dyn_relocs
**pp
;
13449 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13451 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
13458 /* Also discard relocs on undefined weak syms with non-default
13460 if (eh
->dyn_relocs
!= NULL
13461 && h
->root
.type
== bfd_link_hash_undefweak
)
13463 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
13464 eh
->dyn_relocs
= NULL
;
13466 /* Make sure undefined weak symbols are output as a dynamic
13468 else if (h
->dynindx
== -1
13469 && !h
->forced_local
)
13471 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13476 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
13477 && h
->root
.type
== bfd_link_hash_new
)
13479 /* Output absolute symbols so that we can create relocations
13480 against them. For normal symbols we output a relocation
13481 against the section that contains them. */
13482 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13489 /* For the non-shared case, discard space for relocs against
13490 symbols which turn out to need copy relocs or are not
13493 if (!h
->non_got_ref
13494 && ((h
->def_dynamic
13495 && !h
->def_regular
)
13496 || (htab
->root
.dynamic_sections_created
13497 && (h
->root
.type
== bfd_link_hash_undefweak
13498 || h
->root
.type
== bfd_link_hash_undefined
))))
13500 /* Make sure this symbol is output as a dynamic symbol.
13501 Undefined weak syms won't yet be marked as dynamic. */
13502 if (h
->dynindx
== -1
13503 && !h
->forced_local
)
13505 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13509 /* If that succeeded, we know we'll be keeping all the
13511 if (h
->dynindx
!= -1)
13515 eh
->dyn_relocs
= NULL
;
13520 /* Finally, allocate space. */
13521 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13523 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
13524 if (h
->type
== STT_GNU_IFUNC
13525 && eh
->plt
.noncall_refcount
== 0
13526 && SYMBOL_REFERENCES_LOCAL (info
, h
))
13527 elf32_arm_allocate_irelocs (info
, sreloc
, p
->count
);
13529 elf32_arm_allocate_dynrelocs (info
, sreloc
, p
->count
);
13535 /* Find any dynamic relocs that apply to read-only sections. */
13538 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
13540 struct elf32_arm_link_hash_entry
* eh
;
13541 struct elf_dyn_relocs
* p
;
13543 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13544 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13546 asection
*s
= p
->sec
;
13548 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
13550 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
13552 info
->flags
|= DF_TEXTREL
;
13554 /* Not an error, just cut short the traversal. */
13562 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
13565 struct elf32_arm_link_hash_table
*globals
;
13567 globals
= elf32_arm_hash_table (info
);
13568 if (globals
== NULL
)
13571 globals
->byteswap_code
= byteswap_code
;
13574 /* Set the sizes of the dynamic sections. */
13577 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
13578 struct bfd_link_info
* info
)
13583 bfd_boolean relocs
;
13585 struct elf32_arm_link_hash_table
*htab
;
13587 htab
= elf32_arm_hash_table (info
);
13591 dynobj
= elf_hash_table (info
)->dynobj
;
13592 BFD_ASSERT (dynobj
!= NULL
);
13593 check_use_blx (htab
);
13595 if (elf_hash_table (info
)->dynamic_sections_created
)
13597 /* Set the contents of the .interp section to the interpreter. */
13598 if (info
->executable
)
13600 s
= bfd_get_linker_section (dynobj
, ".interp");
13601 BFD_ASSERT (s
!= NULL
);
13602 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
13603 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
13607 /* Set up .got offsets for local syms, and space for local dynamic
13609 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
13611 bfd_signed_vma
*local_got
;
13612 bfd_signed_vma
*end_local_got
;
13613 struct arm_local_iplt_info
**local_iplt_ptr
, *local_iplt
;
13614 char *local_tls_type
;
13615 bfd_vma
*local_tlsdesc_gotent
;
13616 bfd_size_type locsymcount
;
13617 Elf_Internal_Shdr
*symtab_hdr
;
13619 bfd_boolean is_vxworks
= htab
->vxworks_p
;
13620 unsigned int symndx
;
13622 if (! is_arm_elf (ibfd
))
13625 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
13627 struct elf_dyn_relocs
*p
;
13629 for (p
= (struct elf_dyn_relocs
*)
13630 elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
13632 if (!bfd_is_abs_section (p
->sec
)
13633 && bfd_is_abs_section (p
->sec
->output_section
))
13635 /* Input section has been discarded, either because
13636 it is a copy of a linkonce section or due to
13637 linker script /DISCARD/, so we'll be discarding
13640 else if (is_vxworks
13641 && strcmp (p
->sec
->output_section
->name
,
13644 /* Relocations in vxworks .tls_vars sections are
13645 handled specially by the loader. */
13647 else if (p
->count
!= 0)
13649 srel
= elf_section_data (p
->sec
)->sreloc
;
13650 elf32_arm_allocate_dynrelocs (info
, srel
, p
->count
);
13651 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
13652 info
->flags
|= DF_TEXTREL
;
13657 local_got
= elf_local_got_refcounts (ibfd
);
13661 symtab_hdr
= & elf_symtab_hdr (ibfd
);
13662 locsymcount
= symtab_hdr
->sh_info
;
13663 end_local_got
= local_got
+ locsymcount
;
13664 local_iplt_ptr
= elf32_arm_local_iplt (ibfd
);
13665 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
13666 local_tlsdesc_gotent
= elf32_arm_local_tlsdesc_gotent (ibfd
);
13668 s
= htab
->root
.sgot
;
13669 srel
= htab
->root
.srelgot
;
13670 for (; local_got
< end_local_got
;
13671 ++local_got
, ++local_iplt_ptr
, ++local_tls_type
,
13672 ++local_tlsdesc_gotent
, ++symndx
)
13674 *local_tlsdesc_gotent
= (bfd_vma
) -1;
13675 local_iplt
= *local_iplt_ptr
;
13676 if (local_iplt
!= NULL
)
13678 struct elf_dyn_relocs
*p
;
13680 if (local_iplt
->root
.refcount
> 0)
13682 elf32_arm_allocate_plt_entry (info
, TRUE
,
13685 if (local_iplt
->arm
.noncall_refcount
== 0)
13686 /* All references to the PLT are calls, so all
13687 non-call references can resolve directly to the
13688 run-time target. This means that the .got entry
13689 would be the same as the .igot.plt entry, so there's
13690 no point creating both. */
13695 BFD_ASSERT (local_iplt
->arm
.noncall_refcount
== 0);
13696 local_iplt
->root
.offset
= (bfd_vma
) -1;
13699 for (p
= local_iplt
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13703 psrel
= elf_section_data (p
->sec
)->sreloc
;
13704 if (local_iplt
->arm
.noncall_refcount
== 0)
13705 elf32_arm_allocate_irelocs (info
, psrel
, p
->count
);
13707 elf32_arm_allocate_dynrelocs (info
, psrel
, p
->count
);
13710 if (*local_got
> 0)
13712 Elf_Internal_Sym
*isym
;
13714 *local_got
= s
->size
;
13715 if (*local_tls_type
& GOT_TLS_GD
)
13716 /* TLS_GD relocs need an 8-byte structure in the GOT. */
13718 if (*local_tls_type
& GOT_TLS_GDESC
)
13720 *local_tlsdesc_gotent
= htab
->root
.sgotplt
->size
13721 - elf32_arm_compute_jump_table_size (htab
);
13722 htab
->root
.sgotplt
->size
+= 8;
13723 *local_got
= (bfd_vma
) -2;
13724 /* plt.got_offset needs to know there's a TLS_DESC
13725 reloc in the middle of .got.plt. */
13726 htab
->num_tls_desc
++;
13728 if (*local_tls_type
& GOT_TLS_IE
)
13731 if (*local_tls_type
& GOT_NORMAL
)
13733 /* If the symbol is both GD and GDESC, *local_got
13734 may have been overwritten. */
13735 *local_got
= s
->size
;
13739 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, symndx
);
13743 /* If all references to an STT_GNU_IFUNC PLT are calls,
13744 then all non-call references, including this GOT entry,
13745 resolve directly to the run-time target. */
13746 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
13747 && (local_iplt
== NULL
13748 || local_iplt
->arm
.noncall_refcount
== 0))
13749 elf32_arm_allocate_irelocs (info
, srel
, 1);
13750 else if (info
->shared
|| output_bfd
->flags
& DYNAMIC
)
13752 if ((info
->shared
&& !(*local_tls_type
& GOT_TLS_GDESC
))
13753 || *local_tls_type
& GOT_TLS_GD
)
13754 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
13756 if (info
->shared
&& *local_tls_type
& GOT_TLS_GDESC
)
13758 elf32_arm_allocate_dynrelocs (info
,
13759 htab
->root
.srelplt
, 1);
13760 htab
->tls_trampoline
= -1;
13765 *local_got
= (bfd_vma
) -1;
13769 if (htab
->tls_ldm_got
.refcount
> 0)
13771 /* Allocate two GOT entries and one dynamic relocation (if necessary)
13772 for R_ARM_TLS_LDM32 relocations. */
13773 htab
->tls_ldm_got
.offset
= htab
->root
.sgot
->size
;
13774 htab
->root
.sgot
->size
+= 8;
13776 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13779 htab
->tls_ldm_got
.offset
= -1;
13781 /* Allocate global sym .plt and .got entries, and space for global
13782 sym dynamic relocs. */
13783 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs_for_symbol
, info
);
13785 /* Here we rummage through the found bfds to collect glue information. */
13786 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
13788 if (! is_arm_elf (ibfd
))
13791 /* Initialise mapping tables for code/data. */
13792 bfd_elf32_arm_init_maps (ibfd
);
13794 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
13795 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
13796 /* xgettext:c-format */
13797 _bfd_error_handler (_("Errors encountered processing file %s"),
13801 /* Allocate space for the glue sections now that we've sized them. */
13802 bfd_elf32_arm_allocate_interworking_sections (info
);
13804 /* For every jump slot reserved in the sgotplt, reloc_count is
13805 incremented. However, when we reserve space for TLS descriptors,
13806 it's not incremented, so in order to compute the space reserved
13807 for them, it suffices to multiply the reloc count by the jump
13809 if (htab
->root
.srelplt
)
13810 htab
->sgotplt_jump_table_size
= elf32_arm_compute_jump_table_size(htab
);
13812 if (htab
->tls_trampoline
)
13814 if (htab
->root
.splt
->size
== 0)
13815 htab
->root
.splt
->size
+= htab
->plt_header_size
;
13817 htab
->tls_trampoline
= htab
->root
.splt
->size
;
13818 htab
->root
.splt
->size
+= htab
->plt_entry_size
;
13820 /* If we're not using lazy TLS relocations, don't generate the
13821 PLT and GOT entries they require. */
13822 if (!(info
->flags
& DF_BIND_NOW
))
13824 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
13825 htab
->root
.sgot
->size
+= 4;
13827 htab
->dt_tlsdesc_plt
= htab
->root
.splt
->size
;
13828 htab
->root
.splt
->size
+= 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
);
13832 /* The check_relocs and adjust_dynamic_symbol entry points have
13833 determined the sizes of the various dynamic sections. Allocate
13834 memory for them. */
13837 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
13841 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
13844 /* It's OK to base decisions on the section name, because none
13845 of the dynobj section names depend upon the input files. */
13846 name
= bfd_get_section_name (dynobj
, s
);
13848 if (s
== htab
->root
.splt
)
13850 /* Remember whether there is a PLT. */
13851 plt
= s
->size
!= 0;
13853 else if (CONST_STRNEQ (name
, ".rel"))
13857 /* Remember whether there are any reloc sections other
13858 than .rel(a).plt and .rela.plt.unloaded. */
13859 if (s
!= htab
->root
.srelplt
&& s
!= htab
->srelplt2
)
13862 /* We use the reloc_count field as a counter if we need
13863 to copy relocs into the output file. */
13864 s
->reloc_count
= 0;
13867 else if (s
!= htab
->root
.sgot
13868 && s
!= htab
->root
.sgotplt
13869 && s
!= htab
->root
.iplt
13870 && s
!= htab
->root
.igotplt
13871 && s
!= htab
->sdynbss
)
13873 /* It's not one of our sections, so don't allocate space. */
13879 /* If we don't need this section, strip it from the
13880 output file. This is mostly to handle .rel(a).bss and
13881 .rel(a).plt. We must create both sections in
13882 create_dynamic_sections, because they must be created
13883 before the linker maps input sections to output
13884 sections. The linker does that before
13885 adjust_dynamic_symbol is called, and it is that
13886 function which decides whether anything needs to go
13887 into these sections. */
13888 s
->flags
|= SEC_EXCLUDE
;
13892 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
13895 /* Allocate memory for the section contents. */
13896 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
13897 if (s
->contents
== NULL
)
13901 if (elf_hash_table (info
)->dynamic_sections_created
)
13903 /* Add some entries to the .dynamic section. We fill in the
13904 values later, in elf32_arm_finish_dynamic_sections, but we
13905 must add the entries now so that we get the correct size for
13906 the .dynamic section. The DT_DEBUG entry is filled in by the
13907 dynamic linker and used by the debugger. */
13908 #define add_dynamic_entry(TAG, VAL) \
13909 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
13911 if (info
->executable
)
13913 if (!add_dynamic_entry (DT_DEBUG
, 0))
13919 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
13920 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
13921 || !add_dynamic_entry (DT_PLTREL
,
13922 htab
->use_rel
? DT_REL
: DT_RELA
)
13923 || !add_dynamic_entry (DT_JMPREL
, 0))
13926 if (htab
->dt_tlsdesc_plt
&&
13927 (!add_dynamic_entry (DT_TLSDESC_PLT
,0)
13928 || !add_dynamic_entry (DT_TLSDESC_GOT
,0)))
13936 if (!add_dynamic_entry (DT_REL
, 0)
13937 || !add_dynamic_entry (DT_RELSZ
, 0)
13938 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
13943 if (!add_dynamic_entry (DT_RELA
, 0)
13944 || !add_dynamic_entry (DT_RELASZ
, 0)
13945 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
13950 /* If any dynamic relocs apply to a read-only section,
13951 then we need a DT_TEXTREL entry. */
13952 if ((info
->flags
& DF_TEXTREL
) == 0)
13953 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
13956 if ((info
->flags
& DF_TEXTREL
) != 0)
13958 if (!add_dynamic_entry (DT_TEXTREL
, 0))
13961 if (htab
->vxworks_p
13962 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
13965 #undef add_dynamic_entry
13970 /* Size sections even though they're not dynamic. We use it to setup
13971 _TLS_MODULE_BASE_, if needed. */
13974 elf32_arm_always_size_sections (bfd
*output_bfd
,
13975 struct bfd_link_info
*info
)
13979 if (info
->relocatable
)
13982 tls_sec
= elf_hash_table (info
)->tls_sec
;
13986 struct elf_link_hash_entry
*tlsbase
;
13988 tlsbase
= elf_link_hash_lookup
13989 (elf_hash_table (info
), "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
13993 struct bfd_link_hash_entry
*bh
= NULL
;
13994 const struct elf_backend_data
*bed
13995 = get_elf_backend_data (output_bfd
);
13997 if (!(_bfd_generic_link_add_one_symbol
13998 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
13999 tls_sec
, 0, NULL
, FALSE
,
14000 bed
->collect
, &bh
)))
14003 tlsbase
->type
= STT_TLS
;
14004 tlsbase
= (struct elf_link_hash_entry
*)bh
;
14005 tlsbase
->def_regular
= 1;
14006 tlsbase
->other
= STV_HIDDEN
;
14007 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
14013 /* Finish up dynamic symbol handling. We set the contents of various
14014 dynamic sections here. */
14017 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
14018 struct bfd_link_info
* info
,
14019 struct elf_link_hash_entry
* h
,
14020 Elf_Internal_Sym
* sym
)
14022 struct elf32_arm_link_hash_table
*htab
;
14023 struct elf32_arm_link_hash_entry
*eh
;
14025 htab
= elf32_arm_hash_table (info
);
14029 eh
= (struct elf32_arm_link_hash_entry
*) h
;
14031 if (h
->plt
.offset
!= (bfd_vma
) -1)
14035 BFD_ASSERT (h
->dynindx
!= -1);
14036 if (! elf32_arm_populate_plt_entry (output_bfd
, info
, &h
->plt
, &eh
->plt
,
14041 if (!h
->def_regular
)
14043 /* Mark the symbol as undefined, rather than as defined in
14044 the .plt section. Leave the value alone. */
14045 sym
->st_shndx
= SHN_UNDEF
;
14046 /* If the symbol is weak, we do need to clear the value.
14047 Otherwise, the PLT entry would provide a definition for
14048 the symbol even if the symbol wasn't defined anywhere,
14049 and so the symbol would never be NULL. */
14050 if (!h
->ref_regular_nonweak
)
14053 else if (eh
->is_iplt
&& eh
->plt
.noncall_refcount
!= 0)
14055 /* At least one non-call relocation references this .iplt entry,
14056 so the .iplt entry is the function's canonical address. */
14057 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
14058 sym
->st_target_internal
= ST_BRANCH_TO_ARM
;
14059 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
14060 (output_bfd
, htab
->root
.iplt
->output_section
));
14061 sym
->st_value
= (h
->plt
.offset
14062 + htab
->root
.iplt
->output_section
->vma
14063 + htab
->root
.iplt
->output_offset
);
14070 Elf_Internal_Rela rel
;
14072 /* This symbol needs a copy reloc. Set it up. */
14073 BFD_ASSERT (h
->dynindx
!= -1
14074 && (h
->root
.type
== bfd_link_hash_defined
14075 || h
->root
.type
== bfd_link_hash_defweak
));
14078 BFD_ASSERT (s
!= NULL
);
14081 rel
.r_offset
= (h
->root
.u
.def
.value
14082 + h
->root
.u
.def
.section
->output_section
->vma
14083 + h
->root
.u
.def
.section
->output_offset
);
14084 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
14085 elf32_arm_add_dynreloc (output_bfd
, info
, s
, &rel
);
14088 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
14089 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
14090 to the ".got" section. */
14091 if (h
== htab
->root
.hdynamic
14092 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
14093 sym
->st_shndx
= SHN_ABS
;
14099 arm_put_trampoline (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
14101 const unsigned long *template, unsigned count
)
14105 for (ix
= 0; ix
!= count
; ix
++)
14107 unsigned long insn
= template[ix
];
14109 /* Emit mov pc,rx if bx is not permitted. */
14110 if (htab
->fix_v4bx
== 1 && (insn
& 0x0ffffff0) == 0x012fff10)
14111 insn
= (insn
& 0xf000000f) | 0x01a0f000;
14112 put_arm_insn (htab
, output_bfd
, insn
, (char *)contents
+ ix
*4);
14116 /* Install the special first PLT entry for elf32-arm-nacl. Unlike
14117 other variants, NaCl needs this entry in a static executable's
14118 .iplt too. When we're handling that case, GOT_DISPLACEMENT is
14119 zero. For .iplt really only the last bundle is useful, and .iplt
14120 could have a shorter first entry, with each individual PLT entry's
14121 relative branch calculated differently so it targets the last
14122 bundle instead of the instruction before it (labelled .Lplt_tail
14123 above). But it's simpler to keep the size and layout of PLT0
14124 consistent with the dynamic case, at the cost of some dead code at
14125 the start of .iplt and the one dead store to the stack at the start
14128 arm_nacl_put_plt0 (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
14129 asection
*plt
, bfd_vma got_displacement
)
14133 put_arm_insn (htab
, output_bfd
,
14134 elf32_arm_nacl_plt0_entry
[0]
14135 | arm_movw_immediate (got_displacement
),
14136 plt
->contents
+ 0);
14137 put_arm_insn (htab
, output_bfd
,
14138 elf32_arm_nacl_plt0_entry
[1]
14139 | arm_movt_immediate (got_displacement
),
14140 plt
->contents
+ 4);
14142 for (i
= 2; i
< ARRAY_SIZE (elf32_arm_nacl_plt0_entry
); ++i
)
14143 put_arm_insn (htab
, output_bfd
,
14144 elf32_arm_nacl_plt0_entry
[i
],
14145 plt
->contents
+ (i
* 4));
14148 /* Finish up the dynamic sections. */
14151 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
14156 struct elf32_arm_link_hash_table
*htab
;
14158 htab
= elf32_arm_hash_table (info
);
14162 dynobj
= elf_hash_table (info
)->dynobj
;
14164 sgot
= htab
->root
.sgotplt
;
14165 /* A broken linker script might have discarded the dynamic sections.
14166 Catch this here so that we do not seg-fault later on. */
14167 if (sgot
!= NULL
&& bfd_is_abs_section (sgot
->output_section
))
14169 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
14171 if (elf_hash_table (info
)->dynamic_sections_created
)
14174 Elf32_External_Dyn
*dyncon
, *dynconend
;
14176 splt
= htab
->root
.splt
;
14177 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
14178 BFD_ASSERT (htab
->symbian_p
|| sgot
!= NULL
);
14180 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
14181 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
14183 for (; dyncon
< dynconend
; dyncon
++)
14185 Elf_Internal_Dyn dyn
;
14189 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
14196 if (htab
->vxworks_p
14197 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
14198 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14203 goto get_vma_if_bpabi
;
14206 goto get_vma_if_bpabi
;
14209 goto get_vma_if_bpabi
;
14211 name
= ".gnu.version";
14212 goto get_vma_if_bpabi
;
14214 name
= ".gnu.version_d";
14215 goto get_vma_if_bpabi
;
14217 name
= ".gnu.version_r";
14218 goto get_vma_if_bpabi
;
14224 name
= RELOC_SECTION (htab
, ".plt");
14226 s
= bfd_get_section_by_name (output_bfd
, name
);
14229 /* PR ld/14397: Issue an error message if a required section is missing. */
14230 (*_bfd_error_handler
)
14231 (_("error: required section '%s' not found in the linker script"), name
);
14232 bfd_set_error (bfd_error_invalid_operation
);
14235 if (!htab
->symbian_p
)
14236 dyn
.d_un
.d_ptr
= s
->vma
;
14238 /* In the BPABI, tags in the PT_DYNAMIC section point
14239 at the file offset, not the memory address, for the
14240 convenience of the post linker. */
14241 dyn
.d_un
.d_ptr
= s
->filepos
;
14242 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14246 if (htab
->symbian_p
)
14251 s
= htab
->root
.srelplt
;
14252 BFD_ASSERT (s
!= NULL
);
14253 dyn
.d_un
.d_val
= s
->size
;
14254 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14259 if (!htab
->symbian_p
)
14261 /* My reading of the SVR4 ABI indicates that the
14262 procedure linkage table relocs (DT_JMPREL) should be
14263 included in the overall relocs (DT_REL). This is
14264 what Solaris does. However, UnixWare can not handle
14265 that case. Therefore, we override the DT_RELSZ entry
14266 here to make it not include the JMPREL relocs. Since
14267 the linker script arranges for .rel(a).plt to follow all
14268 other relocation sections, we don't have to worry
14269 about changing the DT_REL entry. */
14270 s
= htab
->root
.srelplt
;
14272 dyn
.d_un
.d_val
-= s
->size
;
14273 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14276 /* Fall through. */
14280 /* In the BPABI, the DT_REL tag must point at the file
14281 offset, not the VMA, of the first relocation
14282 section. So, we use code similar to that in
14283 elflink.c, but do not check for SHF_ALLOC on the
14284 relcoation section, since relocations sections are
14285 never allocated under the BPABI. The comments above
14286 about Unixware notwithstanding, we include all of the
14287 relocations here. */
14288 if (htab
->symbian_p
)
14291 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
14292 ? SHT_REL
: SHT_RELA
);
14293 dyn
.d_un
.d_val
= 0;
14294 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
14296 Elf_Internal_Shdr
*hdr
14297 = elf_elfsections (output_bfd
)[i
];
14298 if (hdr
->sh_type
== type
)
14300 if (dyn
.d_tag
== DT_RELSZ
14301 || dyn
.d_tag
== DT_RELASZ
)
14302 dyn
.d_un
.d_val
+= hdr
->sh_size
;
14303 else if ((ufile_ptr
) hdr
->sh_offset
14304 <= dyn
.d_un
.d_val
- 1)
14305 dyn
.d_un
.d_val
= hdr
->sh_offset
;
14308 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14312 case DT_TLSDESC_PLT
:
14313 s
= htab
->root
.splt
;
14314 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
14315 + htab
->dt_tlsdesc_plt
);
14316 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14319 case DT_TLSDESC_GOT
:
14320 s
= htab
->root
.sgot
;
14321 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
14322 + htab
->dt_tlsdesc_got
);
14323 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14326 /* Set the bottom bit of DT_INIT/FINI if the
14327 corresponding function is Thumb. */
14329 name
= info
->init_function
;
14332 name
= info
->fini_function
;
14334 /* If it wasn't set by elf_bfd_final_link
14335 then there is nothing to adjust. */
14336 if (dyn
.d_un
.d_val
!= 0)
14338 struct elf_link_hash_entry
* eh
;
14340 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
14341 FALSE
, FALSE
, TRUE
);
14342 if (eh
!= NULL
&& eh
->target_internal
== ST_BRANCH_TO_THUMB
)
14344 dyn
.d_un
.d_val
|= 1;
14345 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14352 /* Fill in the first entry in the procedure linkage table. */
14353 if (splt
->size
> 0 && htab
->plt_header_size
)
14355 const bfd_vma
*plt0_entry
;
14356 bfd_vma got_address
, plt_address
, got_displacement
;
14358 /* Calculate the addresses of the GOT and PLT. */
14359 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
14360 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
14362 if (htab
->vxworks_p
)
14364 /* The VxWorks GOT is relocated by the dynamic linker.
14365 Therefore, we must emit relocations rather than simply
14366 computing the values now. */
14367 Elf_Internal_Rela rel
;
14369 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
14370 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
14371 splt
->contents
+ 0);
14372 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
14373 splt
->contents
+ 4);
14374 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
14375 splt
->contents
+ 8);
14376 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
14378 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
14379 rel
.r_offset
= plt_address
+ 12;
14380 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
14382 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
14383 htab
->srelplt2
->contents
);
14385 else if (htab
->nacl_p
)
14386 arm_nacl_put_plt0 (htab
, output_bfd
, splt
,
14387 got_address
+ 8 - (plt_address
+ 16));
14390 got_displacement
= got_address
- (plt_address
+ 16);
14392 plt0_entry
= elf32_arm_plt0_entry
;
14393 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
14394 splt
->contents
+ 0);
14395 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
14396 splt
->contents
+ 4);
14397 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
14398 splt
->contents
+ 8);
14399 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
14400 splt
->contents
+ 12);
14402 #ifdef FOUR_WORD_PLT
14403 /* The displacement value goes in the otherwise-unused
14404 last word of the second entry. */
14405 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
14407 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
14412 /* UnixWare sets the entsize of .plt to 4, although that doesn't
14413 really seem like the right value. */
14414 if (splt
->output_section
->owner
== output_bfd
)
14415 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
14417 if (htab
->dt_tlsdesc_plt
)
14419 bfd_vma got_address
14420 = sgot
->output_section
->vma
+ sgot
->output_offset
;
14421 bfd_vma gotplt_address
= (htab
->root
.sgot
->output_section
->vma
14422 + htab
->root
.sgot
->output_offset
);
14423 bfd_vma plt_address
14424 = splt
->output_section
->vma
+ splt
->output_offset
;
14426 arm_put_trampoline (htab
, output_bfd
,
14427 splt
->contents
+ htab
->dt_tlsdesc_plt
,
14428 dl_tlsdesc_lazy_trampoline
, 6);
14430 bfd_put_32 (output_bfd
,
14431 gotplt_address
+ htab
->dt_tlsdesc_got
14432 - (plt_address
+ htab
->dt_tlsdesc_plt
)
14433 - dl_tlsdesc_lazy_trampoline
[6],
14434 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24);
14435 bfd_put_32 (output_bfd
,
14436 got_address
- (plt_address
+ htab
->dt_tlsdesc_plt
)
14437 - dl_tlsdesc_lazy_trampoline
[7],
14438 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24 + 4);
14441 if (htab
->tls_trampoline
)
14443 arm_put_trampoline (htab
, output_bfd
,
14444 splt
->contents
+ htab
->tls_trampoline
,
14445 tls_trampoline
, 3);
14446 #ifdef FOUR_WORD_PLT
14447 bfd_put_32 (output_bfd
, 0x00000000,
14448 splt
->contents
+ htab
->tls_trampoline
+ 12);
14452 if (htab
->vxworks_p
&& !info
->shared
&& htab
->root
.splt
->size
> 0)
14454 /* Correct the .rel(a).plt.unloaded relocations. They will have
14455 incorrect symbol indexes. */
14459 num_plts
= ((htab
->root
.splt
->size
- htab
->plt_header_size
)
14460 / htab
->plt_entry_size
);
14461 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
14463 for (; num_plts
; num_plts
--)
14465 Elf_Internal_Rela rel
;
14467 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14468 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
14469 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14470 p
+= RELOC_SIZE (htab
);
14472 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14473 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
14474 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14475 p
+= RELOC_SIZE (htab
);
14480 if (htab
->nacl_p
&& htab
->root
.iplt
!= NULL
&& htab
->root
.iplt
->size
> 0)
14481 /* NaCl uses a special first entry in .iplt too. */
14482 arm_nacl_put_plt0 (htab
, output_bfd
, htab
->root
.iplt
, 0);
14484 /* Fill in the first three entries in the global offset table. */
14487 if (sgot
->size
> 0)
14490 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
14492 bfd_put_32 (output_bfd
,
14493 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
14495 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
14496 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
14499 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
14506 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
14508 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
14509 struct elf32_arm_link_hash_table
*globals
;
14511 i_ehdrp
= elf_elfheader (abfd
);
14513 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
14514 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
14516 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
14517 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
14521 globals
= elf32_arm_hash_table (link_info
);
14522 if (globals
!= NULL
&& globals
->byteswap_code
)
14523 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
14526 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_VER5
14527 && ((i_ehdrp
->e_type
== ET_DYN
) || (i_ehdrp
->e_type
== ET_EXEC
)))
14529 int abi
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_ABI_VFP_args
);
14531 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_HARD
;
14533 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_SOFT
;
14537 static enum elf_reloc_type_class
14538 elf32_arm_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
14539 const asection
*rel_sec ATTRIBUTE_UNUSED
,
14540 const Elf_Internal_Rela
*rela
)
14542 switch ((int) ELF32_R_TYPE (rela
->r_info
))
14544 case R_ARM_RELATIVE
:
14545 return reloc_class_relative
;
14546 case R_ARM_JUMP_SLOT
:
14547 return reloc_class_plt
;
14549 return reloc_class_copy
;
14551 return reloc_class_normal
;
14556 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
14558 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
14561 /* Return TRUE if this is an unwinding table entry. */
14564 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
14566 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
14567 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
14571 /* Set the type and flags for an ARM section. We do this by
14572 the section name, which is a hack, but ought to work. */
14575 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
14579 name
= bfd_get_section_name (abfd
, sec
);
14581 if (is_arm_elf_unwind_section_name (abfd
, name
))
14583 hdr
->sh_type
= SHT_ARM_EXIDX
;
14584 hdr
->sh_flags
|= SHF_LINK_ORDER
;
14589 /* Handle an ARM specific section when reading an object file. This is
14590 called when bfd_section_from_shdr finds a section with an unknown
14594 elf32_arm_section_from_shdr (bfd
*abfd
,
14595 Elf_Internal_Shdr
* hdr
,
14599 /* There ought to be a place to keep ELF backend specific flags, but
14600 at the moment there isn't one. We just keep track of the
14601 sections by their name, instead. Fortunately, the ABI gives
14602 names for all the ARM specific sections, so we will probably get
14604 switch (hdr
->sh_type
)
14606 case SHT_ARM_EXIDX
:
14607 case SHT_ARM_PREEMPTMAP
:
14608 case SHT_ARM_ATTRIBUTES
:
14615 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
14621 static _arm_elf_section_data
*
14622 get_arm_elf_section_data (asection
* sec
)
14624 if (sec
&& sec
->owner
&& is_arm_elf (sec
->owner
))
14625 return elf32_arm_section_data (sec
);
14633 struct bfd_link_info
*info
;
14636 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
14637 asection
*, struct elf_link_hash_entry
*);
14638 } output_arch_syminfo
;
14640 enum map_symbol_type
14648 /* Output a single mapping symbol. */
14651 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
14652 enum map_symbol_type type
,
14655 static const char *names
[3] = {"$a", "$t", "$d"};
14656 Elf_Internal_Sym sym
;
14658 sym
.st_value
= osi
->sec
->output_section
->vma
14659 + osi
->sec
->output_offset
14663 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
14664 sym
.st_shndx
= osi
->sec_shndx
;
14665 sym
.st_target_internal
= 0;
14666 elf32_arm_section_map_add (osi
->sec
, names
[type
][1], offset
);
14667 return osi
->func (osi
->flaginfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
14670 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
14671 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
14674 elf32_arm_output_plt_map_1 (output_arch_syminfo
*osi
,
14675 bfd_boolean is_iplt_entry_p
,
14676 union gotplt_union
*root_plt
,
14677 struct arm_plt_info
*arm_plt
)
14679 struct elf32_arm_link_hash_table
*htab
;
14680 bfd_vma addr
, plt_header_size
;
14682 if (root_plt
->offset
== (bfd_vma
) -1)
14685 htab
= elf32_arm_hash_table (osi
->info
);
14689 if (is_iplt_entry_p
)
14691 osi
->sec
= htab
->root
.iplt
;
14692 plt_header_size
= 0;
14696 osi
->sec
= htab
->root
.splt
;
14697 plt_header_size
= htab
->plt_header_size
;
14699 osi
->sec_shndx
= (_bfd_elf_section_from_bfd_section
14700 (osi
->info
->output_bfd
, osi
->sec
->output_section
));
14702 addr
= root_plt
->offset
& -2;
14703 if (htab
->symbian_p
)
14705 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14707 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
14710 else if (htab
->vxworks_p
)
14712 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14714 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
14716 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
14718 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
14721 else if (htab
->nacl_p
)
14723 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14728 bfd_boolean thumb_stub_p
;
14730 thumb_stub_p
= elf32_arm_plt_needs_thumb_stub_p (osi
->info
, arm_plt
);
14733 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
14736 #ifdef FOUR_WORD_PLT
14737 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14739 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
14742 /* A three-word PLT with no Thumb thunk contains only Arm code,
14743 so only need to output a mapping symbol for the first PLT entry and
14744 entries with thumb thunks. */
14745 if (thumb_stub_p
|| addr
== plt_header_size
)
14747 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14756 /* Output mapping symbols for PLT entries associated with H. */
14759 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
14761 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
14762 struct elf32_arm_link_hash_entry
*eh
;
14764 if (h
->root
.type
== bfd_link_hash_indirect
)
14767 if (h
->root
.type
== bfd_link_hash_warning
)
14768 /* When warning symbols are created, they **replace** the "real"
14769 entry in the hash table, thus we never get to see the real
14770 symbol in a hash traversal. So look at it now. */
14771 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
14773 eh
= (struct elf32_arm_link_hash_entry
*) h
;
14774 return elf32_arm_output_plt_map_1 (osi
, SYMBOL_CALLS_LOCAL (osi
->info
, h
),
14775 &h
->plt
, &eh
->plt
);
14778 /* Output a single local symbol for a generated stub. */
14781 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
14782 bfd_vma offset
, bfd_vma size
)
14784 Elf_Internal_Sym sym
;
14786 sym
.st_value
= osi
->sec
->output_section
->vma
14787 + osi
->sec
->output_offset
14789 sym
.st_size
= size
;
14791 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
14792 sym
.st_shndx
= osi
->sec_shndx
;
14793 sym
.st_target_internal
= 0;
14794 return osi
->func (osi
->flaginfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
14798 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
14801 struct elf32_arm_stub_hash_entry
*stub_entry
;
14802 asection
*stub_sec
;
14805 output_arch_syminfo
*osi
;
14806 const insn_sequence
*template_sequence
;
14807 enum stub_insn_type prev_type
;
14810 enum map_symbol_type sym_type
;
14812 /* Massage our args to the form they really have. */
14813 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
14814 osi
= (output_arch_syminfo
*) in_arg
;
14816 stub_sec
= stub_entry
->stub_sec
;
14818 /* Ensure this stub is attached to the current section being
14820 if (stub_sec
!= osi
->sec
)
14823 addr
= (bfd_vma
) stub_entry
->stub_offset
;
14824 stub_name
= stub_entry
->output_name
;
14826 template_sequence
= stub_entry
->stub_template
;
14827 switch (template_sequence
[0].type
)
14830 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, stub_entry
->stub_size
))
14835 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
14836 stub_entry
->stub_size
))
14844 prev_type
= DATA_TYPE
;
14846 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
14848 switch (template_sequence
[i
].type
)
14851 sym_type
= ARM_MAP_ARM
;
14856 sym_type
= ARM_MAP_THUMB
;
14860 sym_type
= ARM_MAP_DATA
;
14868 if (template_sequence
[i
].type
!= prev_type
)
14870 prev_type
= template_sequence
[i
].type
;
14871 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
14875 switch (template_sequence
[i
].type
)
14899 /* Output mapping symbols for linker generated sections,
14900 and for those data-only sections that do not have a
14904 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
14905 struct bfd_link_info
*info
,
14907 int (*func
) (void *, const char *,
14908 Elf_Internal_Sym
*,
14910 struct elf_link_hash_entry
*))
14912 output_arch_syminfo osi
;
14913 struct elf32_arm_link_hash_table
*htab
;
14915 bfd_size_type size
;
14918 htab
= elf32_arm_hash_table (info
);
14922 check_use_blx (htab
);
14924 osi
.flaginfo
= flaginfo
;
14928 /* Add a $d mapping symbol to data-only sections that
14929 don't have any mapping symbol. This may result in (harmless) redundant
14930 mapping symbols. */
14931 for (input_bfd
= info
->input_bfds
;
14933 input_bfd
= input_bfd
->link_next
)
14935 if ((input_bfd
->flags
& (BFD_LINKER_CREATED
| HAS_SYMS
)) == HAS_SYMS
)
14936 for (osi
.sec
= input_bfd
->sections
;
14938 osi
.sec
= osi
.sec
->next
)
14940 if (osi
.sec
->output_section
!= NULL
14941 && ((osi
.sec
->output_section
->flags
& (SEC_ALLOC
| SEC_CODE
))
14943 && (osi
.sec
->flags
& (SEC_HAS_CONTENTS
| SEC_LINKER_CREATED
))
14944 == SEC_HAS_CONTENTS
14945 && get_arm_elf_section_data (osi
.sec
) != NULL
14946 && get_arm_elf_section_data (osi
.sec
)->mapcount
== 0
14947 && osi
.sec
->size
> 0
14948 && (osi
.sec
->flags
& SEC_EXCLUDE
) == 0)
14950 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14951 (output_bfd
, osi
.sec
->output_section
);
14952 if (osi
.sec_shndx
!= (int)SHN_BAD
)
14953 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 0);
14958 /* ARM->Thumb glue. */
14959 if (htab
->arm_glue_size
> 0)
14961 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
14962 ARM2THUMB_GLUE_SECTION_NAME
);
14964 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14965 (output_bfd
, osi
.sec
->output_section
);
14966 if (info
->shared
|| htab
->root
.is_relocatable_executable
14967 || htab
->pic_veneer
)
14968 size
= ARM2THUMB_PIC_GLUE_SIZE
;
14969 else if (htab
->use_blx
)
14970 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
14972 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
14974 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
14976 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
14977 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
14981 /* Thumb->ARM glue. */
14982 if (htab
->thumb_glue_size
> 0)
14984 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
14985 THUMB2ARM_GLUE_SECTION_NAME
);
14987 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14988 (output_bfd
, osi
.sec
->output_section
);
14989 size
= THUMB2ARM_GLUE_SIZE
;
14991 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
14993 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
14994 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
14998 /* ARMv4 BX veneers. */
14999 if (htab
->bx_glue_size
> 0)
15001 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
15002 ARM_BX_GLUE_SECTION_NAME
);
15004 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15005 (output_bfd
, osi
.sec
->output_section
);
15007 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
15010 /* Long calls stubs. */
15011 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
15013 asection
* stub_sec
;
15015 for (stub_sec
= htab
->stub_bfd
->sections
;
15017 stub_sec
= stub_sec
->next
)
15019 /* Ignore non-stub sections. */
15020 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
15023 osi
.sec
= stub_sec
;
15025 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15026 (output_bfd
, osi
.sec
->output_section
);
15028 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
15032 /* Finally, output mapping symbols for the PLT. */
15033 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
15035 osi
.sec
= htab
->root
.splt
;
15036 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
15037 (output_bfd
, osi
.sec
->output_section
));
15039 /* Output mapping symbols for the plt header. SymbianOS does not have a
15041 if (htab
->vxworks_p
)
15043 /* VxWorks shared libraries have no PLT header. */
15046 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15048 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
15052 else if (htab
->nacl_p
)
15054 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15057 else if (!htab
->symbian_p
)
15059 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15061 #ifndef FOUR_WORD_PLT
15062 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
15067 if (htab
->nacl_p
&& htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0)
15069 /* NaCl uses a special first entry in .iplt too. */
15070 osi
.sec
= htab
->root
.iplt
;
15071 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
15072 (output_bfd
, osi
.sec
->output_section
));
15073 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15076 if ((htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
15077 || (htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0))
15079 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, &osi
);
15080 for (input_bfd
= info
->input_bfds
;
15082 input_bfd
= input_bfd
->link_next
)
15084 struct arm_local_iplt_info
**local_iplt
;
15085 unsigned int i
, num_syms
;
15087 local_iplt
= elf32_arm_local_iplt (input_bfd
);
15088 if (local_iplt
!= NULL
)
15090 num_syms
= elf_symtab_hdr (input_bfd
).sh_info
;
15091 for (i
= 0; i
< num_syms
; i
++)
15092 if (local_iplt
[i
] != NULL
15093 && !elf32_arm_output_plt_map_1 (&osi
, TRUE
,
15094 &local_iplt
[i
]->root
,
15095 &local_iplt
[i
]->arm
))
15100 if (htab
->dt_tlsdesc_plt
!= 0)
15102 /* Mapping symbols for the lazy tls trampoline. */
15103 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->dt_tlsdesc_plt
))
15106 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
15107 htab
->dt_tlsdesc_plt
+ 24))
15110 if (htab
->tls_trampoline
!= 0)
15112 /* Mapping symbols for the tls trampoline. */
15113 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->tls_trampoline
))
15115 #ifdef FOUR_WORD_PLT
15116 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
15117 htab
->tls_trampoline
+ 12))
15125 /* Allocate target specific section data. */
15128 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
15130 if (!sec
->used_by_bfd
)
15132 _arm_elf_section_data
*sdata
;
15133 bfd_size_type amt
= sizeof (*sdata
);
15135 sdata
= (_arm_elf_section_data
*) bfd_zalloc (abfd
, amt
);
15138 sec
->used_by_bfd
= sdata
;
15141 return _bfd_elf_new_section_hook (abfd
, sec
);
15145 /* Used to order a list of mapping symbols by address. */
15148 elf32_arm_compare_mapping (const void * a
, const void * b
)
15150 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
15151 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
15153 if (amap
->vma
> bmap
->vma
)
15155 else if (amap
->vma
< bmap
->vma
)
15157 else if (amap
->type
> bmap
->type
)
15158 /* Ensure results do not depend on the host qsort for objects with
15159 multiple mapping symbols at the same address by sorting on type
15162 else if (amap
->type
< bmap
->type
)
15168 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
15170 static unsigned long
15171 offset_prel31 (unsigned long addr
, bfd_vma offset
)
15173 return (addr
& ~0x7ffffffful
) | ((addr
+ offset
) & 0x7ffffffful
);
15176 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
15180 copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
, bfd_vma offset
)
15182 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
15183 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
15185 /* High bit of first word is supposed to be zero. */
15186 if ((first_word
& 0x80000000ul
) == 0)
15187 first_word
= offset_prel31 (first_word
, offset
);
15189 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
15190 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
15191 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
15192 second_word
= offset_prel31 (second_word
, offset
);
15194 bfd_put_32 (output_bfd
, first_word
, to
);
15195 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
15198 /* Data for make_branch_to_a8_stub(). */
15200 struct a8_branch_to_stub_data
15202 asection
*writing_section
;
15203 bfd_byte
*contents
;
15207 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
15208 places for a particular section. */
15211 make_branch_to_a8_stub (struct bfd_hash_entry
*gen_entry
,
15214 struct elf32_arm_stub_hash_entry
*stub_entry
;
15215 struct a8_branch_to_stub_data
*data
;
15216 bfd_byte
*contents
;
15217 unsigned long branch_insn
;
15218 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
15219 bfd_signed_vma branch_offset
;
15221 unsigned int target
;
15223 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
15224 data
= (struct a8_branch_to_stub_data
*) in_arg
;
15226 if (stub_entry
->target_section
!= data
->writing_section
15227 || stub_entry
->stub_type
< arm_stub_a8_veneer_lwm
)
15230 contents
= data
->contents
;
15232 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
15233 + stub_entry
->target_section
->output_offset
15234 + stub_entry
->target_value
;
15236 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
15237 + stub_entry
->stub_sec
->output_offset
15238 + stub_entry
->stub_offset
;
15240 if (stub_entry
->stub_type
== arm_stub_a8_veneer_blx
)
15241 veneered_insn_loc
&= ~3u;
15243 branch_offset
= veneer_entry_loc
- veneered_insn_loc
- 4;
15245 abfd
= stub_entry
->target_section
->owner
;
15246 target
= stub_entry
->target_value
;
15248 /* We attempt to avoid this condition by setting stubs_always_after_branch
15249 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
15250 This check is just to be on the safe side... */
15251 if ((veneered_insn_loc
& ~0xfff) == (veneer_entry_loc
& ~0xfff))
15253 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub is "
15254 "allocated in unsafe location"), abfd
);
15258 switch (stub_entry
->stub_type
)
15260 case arm_stub_a8_veneer_b
:
15261 case arm_stub_a8_veneer_b_cond
:
15262 branch_insn
= 0xf0009000;
15265 case arm_stub_a8_veneer_blx
:
15266 branch_insn
= 0xf000e800;
15269 case arm_stub_a8_veneer_bl
:
15271 unsigned int i1
, j1
, i2
, j2
, s
;
15273 branch_insn
= 0xf000d000;
15276 if (branch_offset
< -16777216 || branch_offset
> 16777214)
15278 /* There's not much we can do apart from complain if this
15280 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub out "
15281 "of range (input file too large)"), abfd
);
15285 /* i1 = not(j1 eor s), so:
15287 j1 = (not i1) eor s. */
15289 branch_insn
|= (branch_offset
>> 1) & 0x7ff;
15290 branch_insn
|= ((branch_offset
>> 12) & 0x3ff) << 16;
15291 i2
= (branch_offset
>> 22) & 1;
15292 i1
= (branch_offset
>> 23) & 1;
15293 s
= (branch_offset
>> 24) & 1;
15296 branch_insn
|= j2
<< 11;
15297 branch_insn
|= j1
<< 13;
15298 branch_insn
|= s
<< 26;
15307 bfd_put_16 (abfd
, (branch_insn
>> 16) & 0xffff, &contents
[target
]);
15308 bfd_put_16 (abfd
, branch_insn
& 0xffff, &contents
[target
+ 2]);
15313 /* Do code byteswapping. Return FALSE afterwards so that the section is
15314 written out as normal. */
15317 elf32_arm_write_section (bfd
*output_bfd
,
15318 struct bfd_link_info
*link_info
,
15320 bfd_byte
*contents
)
15322 unsigned int mapcount
, errcount
;
15323 _arm_elf_section_data
*arm_data
;
15324 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
15325 elf32_arm_section_map
*map
;
15326 elf32_vfp11_erratum_list
*errnode
;
15329 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
15333 if (globals
== NULL
)
15336 /* If this section has not been allocated an _arm_elf_section_data
15337 structure then we cannot record anything. */
15338 arm_data
= get_arm_elf_section_data (sec
);
15339 if (arm_data
== NULL
)
15342 mapcount
= arm_data
->mapcount
;
15343 map
= arm_data
->map
;
15344 errcount
= arm_data
->erratumcount
;
15348 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
15350 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
15351 errnode
= errnode
->next
)
15353 bfd_vma target
= errnode
->vma
- offset
;
15355 switch (errnode
->type
)
15357 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
15359 bfd_vma branch_to_veneer
;
15360 /* Original condition code of instruction, plus bit mask for
15361 ARM B instruction. */
15362 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
15365 /* The instruction is before the label. */
15368 /* Above offset included in -4 below. */
15369 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
15370 - errnode
->vma
- 4;
15372 if ((signed) branch_to_veneer
< -(1 << 25)
15373 || (signed) branch_to_veneer
>= (1 << 25))
15374 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
15375 "range"), output_bfd
);
15377 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
15378 contents
[endianflip
^ target
] = insn
& 0xff;
15379 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
15380 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
15381 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
15385 case VFP11_ERRATUM_ARM_VENEER
:
15387 bfd_vma branch_from_veneer
;
15390 /* Take size of veneer into account. */
15391 branch_from_veneer
= errnode
->u
.v
.branch
->vma
15392 - errnode
->vma
- 12;
15394 if ((signed) branch_from_veneer
< -(1 << 25)
15395 || (signed) branch_from_veneer
>= (1 << 25))
15396 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
15397 "range"), output_bfd
);
15399 /* Original instruction. */
15400 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
15401 contents
[endianflip
^ target
] = insn
& 0xff;
15402 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
15403 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
15404 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
15406 /* Branch back to insn after original insn. */
15407 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
15408 contents
[endianflip
^ (target
+ 4)] = insn
& 0xff;
15409 contents
[endianflip
^ (target
+ 5)] = (insn
>> 8) & 0xff;
15410 contents
[endianflip
^ (target
+ 6)] = (insn
>> 16) & 0xff;
15411 contents
[endianflip
^ (target
+ 7)] = (insn
>> 24) & 0xff;
15421 if (arm_data
->elf
.this_hdr
.sh_type
== SHT_ARM_EXIDX
)
15423 arm_unwind_table_edit
*edit_node
15424 = arm_data
->u
.exidx
.unwind_edit_list
;
15425 /* Now, sec->size is the size of the section we will write. The original
15426 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
15427 markers) was sec->rawsize. (This isn't the case if we perform no
15428 edits, then rawsize will be zero and we should use size). */
15429 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
15430 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
15431 unsigned int in_index
, out_index
;
15432 bfd_vma add_to_offsets
= 0;
15434 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
15438 unsigned int edit_index
= edit_node
->index
;
15440 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
15442 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
15443 contents
+ in_index
* 8, add_to_offsets
);
15447 else if (in_index
== edit_index
15448 || (in_index
* 8 >= input_size
15449 && edit_index
== UINT_MAX
))
15451 switch (edit_node
->type
)
15453 case DELETE_EXIDX_ENTRY
:
15455 add_to_offsets
+= 8;
15458 case INSERT_EXIDX_CANTUNWIND_AT_END
:
15460 asection
*text_sec
= edit_node
->linked_section
;
15461 bfd_vma text_offset
= text_sec
->output_section
->vma
15462 + text_sec
->output_offset
15464 bfd_vma exidx_offset
= offset
+ out_index
* 8;
15465 unsigned long prel31_offset
;
15467 /* Note: this is meant to be equivalent to an
15468 R_ARM_PREL31 relocation. These synthetic
15469 EXIDX_CANTUNWIND markers are not relocated by the
15470 usual BFD method. */
15471 prel31_offset
= (text_offset
- exidx_offset
)
15474 /* First address we can't unwind. */
15475 bfd_put_32 (output_bfd
, prel31_offset
,
15476 &edited_contents
[out_index
* 8]);
15478 /* Code for EXIDX_CANTUNWIND. */
15479 bfd_put_32 (output_bfd
, 0x1,
15480 &edited_contents
[out_index
* 8 + 4]);
15483 add_to_offsets
-= 8;
15488 edit_node
= edit_node
->next
;
15493 /* No more edits, copy remaining entries verbatim. */
15494 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
15495 contents
+ in_index
* 8, add_to_offsets
);
15501 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
15502 bfd_set_section_contents (output_bfd
, sec
->output_section
,
15504 (file_ptr
) sec
->output_offset
, sec
->size
);
15509 /* Fix code to point to Cortex-A8 erratum stubs. */
15510 if (globals
->fix_cortex_a8
)
15512 struct a8_branch_to_stub_data data
;
15514 data
.writing_section
= sec
;
15515 data
.contents
= contents
;
15517 bfd_hash_traverse (&globals
->stub_hash_table
, make_branch_to_a8_stub
,
15524 if (globals
->byteswap_code
)
15526 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
15529 for (i
= 0; i
< mapcount
; i
++)
15531 if (i
== mapcount
- 1)
15534 end
= map
[i
+ 1].vma
;
15536 switch (map
[i
].type
)
15539 /* Byte swap code words. */
15540 while (ptr
+ 3 < end
)
15542 tmp
= contents
[ptr
];
15543 contents
[ptr
] = contents
[ptr
+ 3];
15544 contents
[ptr
+ 3] = tmp
;
15545 tmp
= contents
[ptr
+ 1];
15546 contents
[ptr
+ 1] = contents
[ptr
+ 2];
15547 contents
[ptr
+ 2] = tmp
;
15553 /* Byte swap code halfwords. */
15554 while (ptr
+ 1 < end
)
15556 tmp
= contents
[ptr
];
15557 contents
[ptr
] = contents
[ptr
+ 1];
15558 contents
[ptr
+ 1] = tmp
;
15564 /* Leave data alone. */
15572 arm_data
->mapcount
= -1;
15573 arm_data
->mapsize
= 0;
15574 arm_data
->map
= NULL
;
15579 /* Mangle thumb function symbols as we read them in. */
15582 elf32_arm_swap_symbol_in (bfd
* abfd
,
15585 Elf_Internal_Sym
*dst
)
15587 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
15590 /* New EABI objects mark thumb function symbols by setting the low bit of
15592 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
15593 || ELF_ST_TYPE (dst
->st_info
) == STT_GNU_IFUNC
)
15595 if (dst
->st_value
& 1)
15597 dst
->st_value
&= ~(bfd_vma
) 1;
15598 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15601 dst
->st_target_internal
= ST_BRANCH_TO_ARM
;
15603 else if (ELF_ST_TYPE (dst
->st_info
) == STT_ARM_TFUNC
)
15605 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_FUNC
);
15606 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15608 else if (ELF_ST_TYPE (dst
->st_info
) == STT_SECTION
)
15609 dst
->st_target_internal
= ST_BRANCH_LONG
;
15611 dst
->st_target_internal
= ST_BRANCH_UNKNOWN
;
15617 /* Mangle thumb function symbols as we write them out. */
15620 elf32_arm_swap_symbol_out (bfd
*abfd
,
15621 const Elf_Internal_Sym
*src
,
15625 Elf_Internal_Sym newsym
;
15627 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
15628 of the address set, as per the new EABI. We do this unconditionally
15629 because objcopy does not set the elf header flags until after
15630 it writes out the symbol table. */
15631 if (src
->st_target_internal
== ST_BRANCH_TO_THUMB
)
15634 if (ELF_ST_TYPE (src
->st_info
) != STT_GNU_IFUNC
)
15635 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
15636 if (newsym
.st_shndx
!= SHN_UNDEF
)
15638 /* Do this only for defined symbols. At link type, the static
15639 linker will simulate the work of dynamic linker of resolving
15640 symbols and will carry over the thumbness of found symbols to
15641 the output symbol table. It's not clear how it happens, but
15642 the thumbness of undefined symbols can well be different at
15643 runtime, and writing '1' for them will be confusing for users
15644 and possibly for dynamic linker itself.
15646 newsym
.st_value
|= 1;
15651 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
15654 /* Add the PT_ARM_EXIDX program header. */
15657 elf32_arm_modify_segment_map (bfd
*abfd
,
15658 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15660 struct elf_segment_map
*m
;
15663 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15664 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15666 /* If there is already a PT_ARM_EXIDX header, then we do not
15667 want to add another one. This situation arises when running
15668 "strip"; the input binary already has the header. */
15669 m
= elf_seg_map (abfd
);
15670 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
15674 m
= (struct elf_segment_map
*)
15675 bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
15678 m
->p_type
= PT_ARM_EXIDX
;
15680 m
->sections
[0] = sec
;
15682 m
->next
= elf_seg_map (abfd
);
15683 elf_seg_map (abfd
) = m
;
15690 /* We may add a PT_ARM_EXIDX program header. */
15693 elf32_arm_additional_program_headers (bfd
*abfd
,
15694 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15698 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15699 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15705 /* Hook called by the linker routine which adds symbols from an object
15709 elf32_arm_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
15710 Elf_Internal_Sym
*sym
, const char **namep
,
15711 flagword
*flagsp
, asection
**secp
, bfd_vma
*valp
)
15713 if ((abfd
->flags
& DYNAMIC
) == 0
15714 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
15715 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
15716 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
15718 if (elf32_arm_hash_table (info
)->vxworks_p
15719 && !elf_vxworks_add_symbol_hook (abfd
, info
, sym
, namep
,
15720 flagsp
, secp
, valp
))
15726 /* We use this to override swap_symbol_in and swap_symbol_out. */
15727 const struct elf_size_info elf32_arm_size_info
=
15729 sizeof (Elf32_External_Ehdr
),
15730 sizeof (Elf32_External_Phdr
),
15731 sizeof (Elf32_External_Shdr
),
15732 sizeof (Elf32_External_Rel
),
15733 sizeof (Elf32_External_Rela
),
15734 sizeof (Elf32_External_Sym
),
15735 sizeof (Elf32_External_Dyn
),
15736 sizeof (Elf_External_Note
),
15740 ELFCLASS32
, EV_CURRENT
,
15741 bfd_elf32_write_out_phdrs
,
15742 bfd_elf32_write_shdrs_and_ehdr
,
15743 bfd_elf32_checksum_contents
,
15744 bfd_elf32_write_relocs
,
15745 elf32_arm_swap_symbol_in
,
15746 elf32_arm_swap_symbol_out
,
15747 bfd_elf32_slurp_reloc_table
,
15748 bfd_elf32_slurp_symbol_table
,
15749 bfd_elf32_swap_dyn_in
,
15750 bfd_elf32_swap_dyn_out
,
15751 bfd_elf32_swap_reloc_in
,
15752 bfd_elf32_swap_reloc_out
,
15753 bfd_elf32_swap_reloca_in
,
15754 bfd_elf32_swap_reloca_out
15757 #define ELF_ARCH bfd_arch_arm
15758 #define ELF_TARGET_ID ARM_ELF_DATA
15759 #define ELF_MACHINE_CODE EM_ARM
15760 #ifdef __QNXTARGET__
15761 #define ELF_MAXPAGESIZE 0x1000
15763 #define ELF_MAXPAGESIZE 0x8000
15765 #define ELF_MINPAGESIZE 0x1000
15766 #define ELF_COMMONPAGESIZE 0x1000
15768 #define bfd_elf32_mkobject elf32_arm_mkobject
15770 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
15771 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
15772 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
15773 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
15774 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
15775 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
15776 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
15777 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
15778 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
15779 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
15780 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
15781 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
15782 #define bfd_elf32_bfd_final_link elf32_arm_final_link
15784 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
15785 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
15786 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
15787 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
15788 #define elf_backend_check_relocs elf32_arm_check_relocs
15789 #define elf_backend_relocate_section elf32_arm_relocate_section
15790 #define elf_backend_write_section elf32_arm_write_section
15791 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
15792 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
15793 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
15794 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
15795 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
15796 #define elf_backend_always_size_sections elf32_arm_always_size_sections
15797 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
15798 #define elf_backend_post_process_headers elf32_arm_post_process_headers
15799 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
15800 #define elf_backend_object_p elf32_arm_object_p
15801 #define elf_backend_fake_sections elf32_arm_fake_sections
15802 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
15803 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15804 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
15805 #define elf_backend_size_info elf32_arm_size_info
15806 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
15807 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
15808 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
15809 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
15810 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
15812 #define elf_backend_can_refcount 1
15813 #define elf_backend_can_gc_sections 1
15814 #define elf_backend_plt_readonly 1
15815 #define elf_backend_want_got_plt 1
15816 #define elf_backend_want_plt_sym 0
15817 #define elf_backend_may_use_rel_p 1
15818 #define elf_backend_may_use_rela_p 0
15819 #define elf_backend_default_use_rela_p 0
15821 #define elf_backend_got_header_size 12
15823 #undef elf_backend_obj_attrs_vendor
15824 #define elf_backend_obj_attrs_vendor "aeabi"
15825 #undef elf_backend_obj_attrs_section
15826 #define elf_backend_obj_attrs_section ".ARM.attributes"
15827 #undef elf_backend_obj_attrs_arg_type
15828 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
15829 #undef elf_backend_obj_attrs_section_type
15830 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
15831 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
15832 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
15834 #include "elf32-target.h"
15836 /* Native Client targets. */
15838 #undef TARGET_LITTLE_SYM
15839 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_nacl_vec
15840 #undef TARGET_LITTLE_NAME
15841 #define TARGET_LITTLE_NAME "elf32-littlearm-nacl"
15842 #undef TARGET_BIG_SYM
15843 #define TARGET_BIG_SYM bfd_elf32_bigarm_nacl_vec
15844 #undef TARGET_BIG_NAME
15845 #define TARGET_BIG_NAME "elf32-bigarm-nacl"
15847 /* Like elf32_arm_link_hash_table_create -- but overrides
15848 appropriately for NaCl. */
15850 static struct bfd_link_hash_table
*
15851 elf32_arm_nacl_link_hash_table_create (bfd
*abfd
)
15853 struct bfd_link_hash_table
*ret
;
15855 ret
= elf32_arm_link_hash_table_create (abfd
);
15858 struct elf32_arm_link_hash_table
*htab
15859 = (struct elf32_arm_link_hash_table
*) ret
;
15863 htab
->plt_header_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt0_entry
);
15864 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt_entry
);
15869 /* Since NaCl doesn't use the ARM-specific unwind format, we don't
15870 really need to use elf32_arm_modify_segment_map. But we do it
15871 anyway just to reduce gratuitous differences with the stock ARM backend. */
15874 elf32_arm_nacl_modify_segment_map (bfd
*abfd
, struct bfd_link_info
*info
)
15876 return (elf32_arm_modify_segment_map (abfd
, info
)
15877 && nacl_modify_segment_map (abfd
, info
));
15881 elf32_arm_nacl_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
15883 elf32_arm_final_write_processing (abfd
, linker
);
15884 nacl_final_write_processing (abfd
, linker
);
15889 #define elf32_bed elf32_arm_nacl_bed
15890 #undef bfd_elf32_bfd_link_hash_table_create
15891 #define bfd_elf32_bfd_link_hash_table_create \
15892 elf32_arm_nacl_link_hash_table_create
15893 #undef elf_backend_plt_alignment
15894 #define elf_backend_plt_alignment 4
15895 #undef elf_backend_modify_segment_map
15896 #define elf_backend_modify_segment_map elf32_arm_nacl_modify_segment_map
15897 #undef elf_backend_modify_program_headers
15898 #define elf_backend_modify_program_headers nacl_modify_program_headers
15899 #undef elf_backend_final_write_processing
15900 #define elf_backend_final_write_processing elf32_arm_nacl_final_write_processing
15902 #undef ELF_MAXPAGESIZE
15903 #define ELF_MAXPAGESIZE 0x10000
15904 #undef ELF_MINPAGESIZE
15905 #undef ELF_COMMONPAGESIZE
15908 #include "elf32-target.h"
15910 /* Reset to defaults. */
15911 #undef elf_backend_plt_alignment
15912 #undef elf_backend_modify_segment_map
15913 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
15914 #undef elf_backend_modify_program_headers
15915 #undef elf_backend_final_write_processing
15916 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15917 #undef ELF_MINPAGESIZE
15918 #define ELF_MINPAGESIZE 0x1000
15919 #undef ELF_COMMONPAGESIZE
15920 #define ELF_COMMONPAGESIZE 0x1000
15923 /* VxWorks Targets. */
15925 #undef TARGET_LITTLE_SYM
15926 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
15927 #undef TARGET_LITTLE_NAME
15928 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
15929 #undef TARGET_BIG_SYM
15930 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
15931 #undef TARGET_BIG_NAME
15932 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
15934 /* Like elf32_arm_link_hash_table_create -- but overrides
15935 appropriately for VxWorks. */
15937 static struct bfd_link_hash_table
*
15938 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
15940 struct bfd_link_hash_table
*ret
;
15942 ret
= elf32_arm_link_hash_table_create (abfd
);
15945 struct elf32_arm_link_hash_table
*htab
15946 = (struct elf32_arm_link_hash_table
*) ret
;
15948 htab
->vxworks_p
= 1;
15954 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
15956 elf32_arm_final_write_processing (abfd
, linker
);
15957 elf_vxworks_final_write_processing (abfd
, linker
);
15961 #define elf32_bed elf32_arm_vxworks_bed
15963 #undef bfd_elf32_bfd_link_hash_table_create
15964 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
15965 #undef elf_backend_final_write_processing
15966 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
15967 #undef elf_backend_emit_relocs
15968 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
15970 #undef elf_backend_may_use_rel_p
15971 #define elf_backend_may_use_rel_p 0
15972 #undef elf_backend_may_use_rela_p
15973 #define elf_backend_may_use_rela_p 1
15974 #undef elf_backend_default_use_rela_p
15975 #define elf_backend_default_use_rela_p 1
15976 #undef elf_backend_want_plt_sym
15977 #define elf_backend_want_plt_sym 1
15978 #undef ELF_MAXPAGESIZE
15979 #define ELF_MAXPAGESIZE 0x1000
15981 #include "elf32-target.h"
15984 /* Merge backend specific data from an object file to the output
15985 object file when linking. */
15988 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
15990 flagword out_flags
;
15992 bfd_boolean flags_compatible
= TRUE
;
15995 /* Check if we have the same endianness. */
15996 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
15999 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
16002 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
16005 /* The input BFD must have had its flags initialised. */
16006 /* The following seems bogus to me -- The flags are initialized in
16007 the assembler but I don't think an elf_flags_init field is
16008 written into the object. */
16009 /* BFD_ASSERT (elf_flags_init (ibfd)); */
16011 in_flags
= elf_elfheader (ibfd
)->e_flags
;
16012 out_flags
= elf_elfheader (obfd
)->e_flags
;
16014 /* In theory there is no reason why we couldn't handle this. However
16015 in practice it isn't even close to working and there is no real
16016 reason to want it. */
16017 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
16018 && !(ibfd
->flags
& DYNAMIC
)
16019 && (in_flags
& EF_ARM_BE8
))
16021 _bfd_error_handler (_("error: %B is already in final BE8 format"),
16026 if (!elf_flags_init (obfd
))
16028 /* If the input is the default architecture and had the default
16029 flags then do not bother setting the flags for the output
16030 architecture, instead allow future merges to do this. If no
16031 future merges ever set these flags then they will retain their
16032 uninitialised values, which surprise surprise, correspond
16033 to the default values. */
16034 if (bfd_get_arch_info (ibfd
)->the_default
16035 && elf_elfheader (ibfd
)->e_flags
== 0)
16038 elf_flags_init (obfd
) = TRUE
;
16039 elf_elfheader (obfd
)->e_flags
= in_flags
;
16041 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
16042 && bfd_get_arch_info (obfd
)->the_default
)
16043 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
16048 /* Determine what should happen if the input ARM architecture
16049 does not match the output ARM architecture. */
16050 if (! bfd_arm_merge_machines (ibfd
, obfd
))
16053 /* Identical flags must be compatible. */
16054 if (in_flags
== out_flags
)
16057 /* Check to see if the input BFD actually contains any sections. If
16058 not, its flags may not have been initialised either, but it
16059 cannot actually cause any incompatiblity. Do not short-circuit
16060 dynamic objects; their section list may be emptied by
16061 elf_link_add_object_symbols.
16063 Also check to see if there are no code sections in the input.
16064 In this case there is no need to check for code specific flags.
16065 XXX - do we need to worry about floating-point format compatability
16066 in data sections ? */
16067 if (!(ibfd
->flags
& DYNAMIC
))
16069 bfd_boolean null_input_bfd
= TRUE
;
16070 bfd_boolean only_data_sections
= TRUE
;
16072 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
16074 /* Ignore synthetic glue sections. */
16075 if (strcmp (sec
->name
, ".glue_7")
16076 && strcmp (sec
->name
, ".glue_7t"))
16078 if ((bfd_get_section_flags (ibfd
, sec
)
16079 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
16080 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
16081 only_data_sections
= FALSE
;
16083 null_input_bfd
= FALSE
;
16088 if (null_input_bfd
|| only_data_sections
)
16092 /* Complain about various flag mismatches. */
16093 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
16094 EF_ARM_EABI_VERSION (out_flags
)))
16097 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
16099 (in_flags
& EF_ARM_EABIMASK
) >> 24,
16100 (out_flags
& EF_ARM_EABIMASK
) >> 24);
16104 /* Not sure what needs to be checked for EABI versions >= 1. */
16105 /* VxWorks libraries do not use these flags. */
16106 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
16107 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
16108 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
16110 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
16113 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
16115 in_flags
& EF_ARM_APCS_26
? 26 : 32,
16116 out_flags
& EF_ARM_APCS_26
? 26 : 32);
16117 flags_compatible
= FALSE
;
16120 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
16122 if (in_flags
& EF_ARM_APCS_FLOAT
)
16124 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
16128 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
16131 flags_compatible
= FALSE
;
16134 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
16136 if (in_flags
& EF_ARM_VFP_FLOAT
)
16138 (_("error: %B uses VFP instructions, whereas %B does not"),
16142 (_("error: %B uses FPA instructions, whereas %B does not"),
16145 flags_compatible
= FALSE
;
16148 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
16150 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
16152 (_("error: %B uses Maverick instructions, whereas %B does not"),
16156 (_("error: %B does not use Maverick instructions, whereas %B does"),
16159 flags_compatible
= FALSE
;
16162 #ifdef EF_ARM_SOFT_FLOAT
16163 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
16165 /* We can allow interworking between code that is VFP format
16166 layout, and uses either soft float or integer regs for
16167 passing floating point arguments and results. We already
16168 know that the APCS_FLOAT flags match; similarly for VFP
16170 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
16171 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
16173 if (in_flags
& EF_ARM_SOFT_FLOAT
)
16175 (_("error: %B uses software FP, whereas %B uses hardware FP"),
16179 (_("error: %B uses hardware FP, whereas %B uses software FP"),
16182 flags_compatible
= FALSE
;
16187 /* Interworking mismatch is only a warning. */
16188 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
16190 if (in_flags
& EF_ARM_INTERWORK
)
16193 (_("Warning: %B supports interworking, whereas %B does not"),
16199 (_("Warning: %B does not support interworking, whereas %B does"),
16205 return flags_compatible
;
16209 /* Symbian OS Targets. */
16211 #undef TARGET_LITTLE_SYM
16212 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
16213 #undef TARGET_LITTLE_NAME
16214 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
16215 #undef TARGET_BIG_SYM
16216 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
16217 #undef TARGET_BIG_NAME
16218 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
16220 /* Like elf32_arm_link_hash_table_create -- but overrides
16221 appropriately for Symbian OS. */
16223 static struct bfd_link_hash_table
*
16224 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
16226 struct bfd_link_hash_table
*ret
;
16228 ret
= elf32_arm_link_hash_table_create (abfd
);
16231 struct elf32_arm_link_hash_table
*htab
16232 = (struct elf32_arm_link_hash_table
*)ret
;
16233 /* There is no PLT header for Symbian OS. */
16234 htab
->plt_header_size
= 0;
16235 /* The PLT entries are each one instruction and one word. */
16236 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
16237 htab
->symbian_p
= 1;
16238 /* Symbian uses armv5t or above, so use_blx is always true. */
16240 htab
->root
.is_relocatable_executable
= 1;
16245 static const struct bfd_elf_special_section
16246 elf32_arm_symbian_special_sections
[] =
16248 /* In a BPABI executable, the dynamic linking sections do not go in
16249 the loadable read-only segment. The post-linker may wish to
16250 refer to these sections, but they are not part of the final
16252 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
16253 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
16254 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
16255 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
16256 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
16257 /* These sections do not need to be writable as the SymbianOS
16258 postlinker will arrange things so that no dynamic relocation is
16260 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
16261 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
16262 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
16263 { NULL
, 0, 0, 0, 0 }
16267 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
16268 struct bfd_link_info
*link_info
)
16270 /* BPABI objects are never loaded directly by an OS kernel; they are
16271 processed by a postlinker first, into an OS-specific format. If
16272 the D_PAGED bit is set on the file, BFD will align segments on
16273 page boundaries, so that an OS can directly map the file. With
16274 BPABI objects, that just results in wasted space. In addition,
16275 because we clear the D_PAGED bit, map_sections_to_segments will
16276 recognize that the program headers should not be mapped into any
16277 loadable segment. */
16278 abfd
->flags
&= ~D_PAGED
;
16279 elf32_arm_begin_write_processing (abfd
, link_info
);
16283 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
16284 struct bfd_link_info
*info
)
16286 struct elf_segment_map
*m
;
16289 /* BPABI shared libraries and executables should have a PT_DYNAMIC
16290 segment. However, because the .dynamic section is not marked
16291 with SEC_LOAD, the generic ELF code will not create such a
16293 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
16296 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
16297 if (m
->p_type
== PT_DYNAMIC
)
16302 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
16303 m
->next
= elf_seg_map (abfd
);
16304 elf_seg_map (abfd
) = m
;
16308 /* Also call the generic arm routine. */
16309 return elf32_arm_modify_segment_map (abfd
, info
);
16312 /* Return address for Ith PLT stub in section PLT, for relocation REL
16313 or (bfd_vma) -1 if it should not be included. */
16316 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
16317 const arelent
*rel ATTRIBUTE_UNUSED
)
16319 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
16324 #define elf32_bed elf32_arm_symbian_bed
16326 /* The dynamic sections are not allocated on SymbianOS; the postlinker
16327 will process them and then discard them. */
16328 #undef ELF_DYNAMIC_SEC_FLAGS
16329 #define ELF_DYNAMIC_SEC_FLAGS \
16330 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
16332 #undef elf_backend_emit_relocs
16334 #undef bfd_elf32_bfd_link_hash_table_create
16335 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
16336 #undef elf_backend_special_sections
16337 #define elf_backend_special_sections elf32_arm_symbian_special_sections
16338 #undef elf_backend_begin_write_processing
16339 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
16340 #undef elf_backend_final_write_processing
16341 #define elf_backend_final_write_processing elf32_arm_final_write_processing
16343 #undef elf_backend_modify_segment_map
16344 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
16346 /* There is no .got section for BPABI objects, and hence no header. */
16347 #undef elf_backend_got_header_size
16348 #define elf_backend_got_header_size 0
16350 /* Similarly, there is no .got.plt section. */
16351 #undef elf_backend_want_got_plt
16352 #define elf_backend_want_got_plt 0
16354 #undef elf_backend_plt_sym_val
16355 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
16357 #undef elf_backend_may_use_rel_p
16358 #define elf_backend_may_use_rel_p 1
16359 #undef elf_backend_may_use_rela_p
16360 #define elf_backend_may_use_rela_p 0
16361 #undef elf_backend_default_use_rela_p
16362 #define elf_backend_default_use_rela_p 0
16363 #undef elf_backend_want_plt_sym
16364 #define elf_backend_want_plt_sym 0
16365 #undef ELF_MAXPAGESIZE
16366 #define ELF_MAXPAGESIZE 0x8000
16368 #include "elf32-target.h"