1 /* 32-bit ELF support for ARM
2 Copyright (C) 1998-2014 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 arm_elf32_le_vec
2044 #define TARGET_LITTLE_NAME "elf32-littlearm"
2045 #define TARGET_BIG_SYM arm_elf32_be_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 */
2128 #else /* not FOUR_WORD_PLT */
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 /* By default subsequent entries in a procedure linkage table look like
2144 this. Offsets that don't fit into 28 bits will cause link error. */
2145 static const bfd_vma elf32_arm_plt_entry_short
[] =
2147 0xe28fc600, /* add ip, pc, #0xNN00000 */
2148 0xe28cca00, /* add ip, ip, #0xNN000 */
2149 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2152 /* When explicitly asked, we'll use this "long" entry format
2153 which can cope with arbitrary displacements. */
2154 static const bfd_vma elf32_arm_plt_entry_long
[] =
2156 0xe28fc200, /* add ip, pc, #0xN0000000 */
2157 0xe28cc600, /* add ip, ip, #0xNN00000 */
2158 0xe28cca00, /* add ip, ip, #0xNN000 */
2159 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2162 static bfd_boolean elf32_arm_use_long_plt_entry
= FALSE
;
2164 #endif /* not FOUR_WORD_PLT */
2166 /* The first entry in a procedure linkage table looks like this.
2167 It is set up so that any shared library function that is called before the
2168 relocation has been set up calls the dynamic linker first. */
2169 static const bfd_vma elf32_thumb2_plt0_entry
[] =
2171 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2172 an instruction maybe encoded to one or two array elements. */
2173 0xf8dfb500, /* push {lr} */
2174 0x44fee008, /* ldr.w lr, [pc, #8] */
2176 0xff08f85e, /* ldr.w pc, [lr, #8]! */
2177 0x00000000, /* &GOT[0] - . */
2180 /* Subsequent entries in a procedure linkage table for thumb only target
2182 static const bfd_vma elf32_thumb2_plt_entry
[] =
2184 /* NOTE: As this is a mixture of 16-bit and 32-bit instructions,
2185 an instruction maybe encoded to one or two array elements. */
2186 0x0c00f240, /* movw ip, #0xNNNN */
2187 0x0c00f2c0, /* movt ip, #0xNNNN */
2188 0xf8dc44fc, /* add ip, pc */
2189 0xbf00f000 /* ldr.w pc, [ip] */
2193 /* The format of the first entry in the procedure linkage table
2194 for a VxWorks executable. */
2195 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
2197 0xe52dc008, /* str ip,[sp,#-8]! */
2198 0xe59fc000, /* ldr ip,[pc] */
2199 0xe59cf008, /* ldr pc,[ip,#8] */
2200 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2203 /* The format of subsequent entries in a VxWorks executable. */
2204 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
2206 0xe59fc000, /* ldr ip,[pc] */
2207 0xe59cf000, /* ldr pc,[ip] */
2208 0x00000000, /* .long @got */
2209 0xe59fc000, /* ldr ip,[pc] */
2210 0xea000000, /* b _PLT */
2211 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2214 /* The format of entries in a VxWorks shared library. */
2215 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
2217 0xe59fc000, /* ldr ip,[pc] */
2218 0xe79cf009, /* ldr pc,[ip,r9] */
2219 0x00000000, /* .long @got */
2220 0xe59fc000, /* ldr ip,[pc] */
2221 0xe599f008, /* ldr pc,[r9,#8] */
2222 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2225 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2226 #define PLT_THUMB_STUB_SIZE 4
2227 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2233 /* The entries in a PLT when using a DLL-based target with multiple
2235 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2237 0xe51ff004, /* ldr pc, [pc, #-4] */
2238 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2241 /* The first entry in a procedure linkage table looks like
2242 this. It is set up so that any shared library function that is
2243 called before the relocation has been set up calls the dynamic
2245 static const bfd_vma elf32_arm_nacl_plt0_entry
[] =
2248 0xe300c000, /* movw ip, #:lower16:&GOT[2]-.+8 */
2249 0xe340c000, /* movt ip, #:upper16:&GOT[2]-.+8 */
2250 0xe08cc00f, /* add ip, ip, pc */
2251 0xe52dc008, /* str ip, [sp, #-8]! */
2252 /* Second bundle: */
2253 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2254 0xe59cc000, /* ldr ip, [ip] */
2255 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2256 0xe12fff1c, /* bx ip */
2258 0xe320f000, /* nop */
2259 0xe320f000, /* nop */
2260 0xe320f000, /* nop */
2262 0xe50dc004, /* str ip, [sp, #-4] */
2263 /* Fourth bundle: */
2264 0xe3ccc103, /* bic ip, ip, #0xc0000000 */
2265 0xe59cc000, /* ldr ip, [ip] */
2266 0xe3ccc13f, /* bic ip, ip, #0xc000000f */
2267 0xe12fff1c, /* bx ip */
2269 #define ARM_NACL_PLT_TAIL_OFFSET (11 * 4)
2271 /* Subsequent entries in a procedure linkage table look like this. */
2272 static const bfd_vma elf32_arm_nacl_plt_entry
[] =
2274 0xe300c000, /* movw ip, #:lower16:&GOT[n]-.+8 */
2275 0xe340c000, /* movt ip, #:upper16:&GOT[n]-.+8 */
2276 0xe08cc00f, /* add ip, ip, pc */
2277 0xea000000, /* b .Lplt_tail */
2280 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2281 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2282 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2283 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2284 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2285 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2295 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2296 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2297 is inserted in arm_build_one_stub(). */
2298 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2299 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2300 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2301 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2302 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2303 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2308 enum stub_insn_type type
;
2309 unsigned int r_type
;
2313 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2314 to reach the stub if necessary. */
2315 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2317 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2318 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2321 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2323 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2325 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2326 ARM_INSN (0xe12fff1c), /* bx ip */
2327 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2330 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2331 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2333 THUMB16_INSN (0xb401), /* push {r0} */
2334 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2335 THUMB16_INSN (0x4684), /* mov ip, r0 */
2336 THUMB16_INSN (0xbc01), /* pop {r0} */
2337 THUMB16_INSN (0x4760), /* bx ip */
2338 THUMB16_INSN (0xbf00), /* nop */
2339 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2342 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2344 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2346 THUMB16_INSN (0x4778), /* bx pc */
2347 THUMB16_INSN (0x46c0), /* nop */
2348 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2349 ARM_INSN (0xe12fff1c), /* bx ip */
2350 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2353 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2355 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2357 THUMB16_INSN (0x4778), /* bx pc */
2358 THUMB16_INSN (0x46c0), /* nop */
2359 ARM_INSN (0xe51ff004), /* ldr pc, [pc, #-4] */
2360 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2363 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2364 one, when the destination is close enough. */
2365 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2367 THUMB16_INSN (0x4778), /* bx pc */
2368 THUMB16_INSN (0x46c0), /* nop */
2369 ARM_REL_INSN (0xea000000, -8), /* b (X-8) */
2372 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2373 blx to reach the stub if necessary. */
2374 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2376 ARM_INSN (0xe59fc000), /* ldr ip, [pc] */
2377 ARM_INSN (0xe08ff00c), /* add pc, pc, ip */
2378 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2381 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2382 blx to reach the stub if necessary. We can not add into pc;
2383 it is not guaranteed to mode switch (different in ARMv6 and
2385 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2387 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2388 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2389 ARM_INSN (0xe12fff1c), /* bx ip */
2390 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2393 /* V4T ARM -> ARM long branch stub, PIC. */
2394 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2396 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2397 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2398 ARM_INSN (0xe12fff1c), /* bx ip */
2399 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2402 /* V4T Thumb -> ARM long branch stub, PIC. */
2403 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2405 THUMB16_INSN (0x4778), /* bx pc */
2406 THUMB16_INSN (0x46c0), /* nop */
2407 ARM_INSN (0xe59fc000), /* ldr ip, [pc, #0] */
2408 ARM_INSN (0xe08cf00f), /* add pc, ip, pc */
2409 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2412 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2414 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2416 THUMB16_INSN (0xb401), /* push {r0} */
2417 THUMB16_INSN (0x4802), /* ldr r0, [pc, #8] */
2418 THUMB16_INSN (0x46fc), /* mov ip, pc */
2419 THUMB16_INSN (0x4484), /* add ip, r0 */
2420 THUMB16_INSN (0xbc01), /* pop {r0} */
2421 THUMB16_INSN (0x4760), /* bx ip */
2422 DATA_WORD (0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2425 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2427 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2429 THUMB16_INSN (0x4778), /* bx pc */
2430 THUMB16_INSN (0x46c0), /* nop */
2431 ARM_INSN (0xe59fc004), /* ldr ip, [pc, #4] */
2432 ARM_INSN (0xe08fc00c), /* add ip, pc, ip */
2433 ARM_INSN (0xe12fff1c), /* bx ip */
2434 DATA_WORD (0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2437 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2438 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2439 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic
[] =
2441 ARM_INSN (0xe59f1000), /* ldr r1, [pc] */
2442 ARM_INSN (0xe08ff001), /* add pc, pc, r1 */
2443 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2446 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2447 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2448 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic
[] =
2450 THUMB16_INSN (0x4778), /* bx pc */
2451 THUMB16_INSN (0x46c0), /* nop */
2452 ARM_INSN (0xe59f1000), /* ldr r1, [pc, #0] */
2453 ARM_INSN (0xe081f00f), /* add pc, r1, pc */
2454 DATA_WORD (0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2457 /* NaCl ARM -> ARM long branch stub. */
2458 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl
[] =
2460 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2461 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2462 ARM_INSN (0xe12fff1c), /* bx ip */
2463 ARM_INSN (0xe320f000), /* nop */
2464 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2465 DATA_WORD (0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2466 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2467 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2470 /* NaCl ARM -> ARM long branch stub, PIC. */
2471 static const insn_sequence elf32_arm_stub_long_branch_arm_nacl_pic
[] =
2473 ARM_INSN (0xe59fc00c), /* ldr ip, [pc, #12] */
2474 ARM_INSN (0xe08cc00f), /* add ip, ip, pc */
2475 ARM_INSN (0xe3ccc13f), /* bic ip, ip, #0xc000000f */
2476 ARM_INSN (0xe12fff1c), /* bx ip */
2477 ARM_INSN (0xe125be70), /* bkpt 0x5be0 */
2478 DATA_WORD (0, R_ARM_REL32
, 8), /* dcd R_ARM_REL32(X+8) */
2479 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2480 DATA_WORD (0, R_ARM_NONE
, 0), /* .word 0 */
2484 /* Cortex-A8 erratum-workaround stubs. */
2486 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2487 can't use a conditional branch to reach this stub). */
2489 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond
[] =
2491 THUMB16_BCOND_INSN (0xd001), /* b<cond>.n true. */
2492 THUMB32_B_INSN (0xf000b800, -4), /* b.w insn_after_original_branch. */
2493 THUMB32_B_INSN (0xf000b800, -4) /* true: b.w original_branch_dest. */
2496 /* Stub used for b.w and bl.w instructions. */
2498 static const insn_sequence elf32_arm_stub_a8_veneer_b
[] =
2500 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2503 static const insn_sequence elf32_arm_stub_a8_veneer_bl
[] =
2505 THUMB32_B_INSN (0xf000b800, -4) /* b.w original_branch_dest. */
2508 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2509 instruction (which switches to ARM mode) to point to this stub. Jump to the
2510 real destination using an ARM-mode branch. */
2512 static const insn_sequence elf32_arm_stub_a8_veneer_blx
[] =
2514 ARM_REL_INSN (0xea000000, -8) /* b original_branch_dest. */
2517 /* For each section group there can be a specially created linker section
2518 to hold the stubs for that group. The name of the stub section is based
2519 upon the name of another section within that group with the suffix below
2522 PR 13049: STUB_SUFFIX used to be ".stub", but this allowed the user to
2523 create what appeared to be a linker stub section when it actually
2524 contained user code/data. For example, consider this fragment:
2526 const char * stubborn_problems[] = { "np" };
2528 If this is compiled with "-fPIC -fdata-sections" then gcc produces a
2531 .data.rel.local.stubborn_problems
2533 This then causes problems in arm32_arm_build_stubs() as it triggers:
2535 // Ignore non-stub sections.
2536 if (!strstr (stub_sec->name, STUB_SUFFIX))
2539 And so the section would be ignored instead of being processed. Hence
2540 the change in definition of STUB_SUFFIX to a name that cannot be a valid
2542 #define STUB_SUFFIX ".__stub"
2544 /* One entry per long/short branch stub defined above. */
2546 DEF_STUB(long_branch_any_any) \
2547 DEF_STUB(long_branch_v4t_arm_thumb) \
2548 DEF_STUB(long_branch_thumb_only) \
2549 DEF_STUB(long_branch_v4t_thumb_thumb) \
2550 DEF_STUB(long_branch_v4t_thumb_arm) \
2551 DEF_STUB(short_branch_v4t_thumb_arm) \
2552 DEF_STUB(long_branch_any_arm_pic) \
2553 DEF_STUB(long_branch_any_thumb_pic) \
2554 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2555 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2556 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2557 DEF_STUB(long_branch_thumb_only_pic) \
2558 DEF_STUB(long_branch_any_tls_pic) \
2559 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2560 DEF_STUB(long_branch_arm_nacl) \
2561 DEF_STUB(long_branch_arm_nacl_pic) \
2562 DEF_STUB(a8_veneer_b_cond) \
2563 DEF_STUB(a8_veneer_b) \
2564 DEF_STUB(a8_veneer_bl) \
2565 DEF_STUB(a8_veneer_blx)
2567 #define DEF_STUB(x) arm_stub_##x,
2568 enum elf32_arm_stub_type
2572 /* Note the first a8_veneer type. */
2573 arm_stub_a8_veneer_lwm
= arm_stub_a8_veneer_b_cond
2579 const insn_sequence
* template_sequence
;
2583 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2584 static const stub_def stub_definitions
[] =
2590 struct elf32_arm_stub_hash_entry
2592 /* Base hash table entry structure. */
2593 struct bfd_hash_entry root
;
2595 /* The stub section. */
2598 /* Offset within stub_sec of the beginning of this stub. */
2599 bfd_vma stub_offset
;
2601 /* Given the symbol's value and its section we can determine its final
2602 value when building the stubs (so the stub knows where to jump). */
2603 bfd_vma target_value
;
2604 asection
*target_section
;
2606 /* Offset to apply to relocation referencing target_value. */
2607 bfd_vma target_addend
;
2609 /* The instruction which caused this stub to be generated (only valid for
2610 Cortex-A8 erratum workaround stubs at present). */
2611 unsigned long orig_insn
;
2613 /* The stub type. */
2614 enum elf32_arm_stub_type stub_type
;
2615 /* Its encoding size in bytes. */
2618 const insn_sequence
*stub_template
;
2619 /* The size of the template (number of entries). */
2620 int stub_template_size
;
2622 /* The symbol table entry, if any, that this was derived from. */
2623 struct elf32_arm_link_hash_entry
*h
;
2625 /* Type of branch. */
2626 enum arm_st_branch_type branch_type
;
2628 /* Where this stub is being called from, or, in the case of combined
2629 stub sections, the first input section in the group. */
2632 /* The name for the local symbol at the start of this stub. The
2633 stub name in the hash table has to be unique; this does not, so
2634 it can be friendlier. */
2638 /* Used to build a map of a section. This is required for mixed-endian
2641 typedef struct elf32_elf_section_map
2646 elf32_arm_section_map
;
2648 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2652 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2653 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2654 VFP11_ERRATUM_ARM_VENEER
,
2655 VFP11_ERRATUM_THUMB_VENEER
2657 elf32_vfp11_erratum_type
;
2659 typedef struct elf32_vfp11_erratum_list
2661 struct elf32_vfp11_erratum_list
*next
;
2667 struct elf32_vfp11_erratum_list
*veneer
;
2668 unsigned int vfp_insn
;
2672 struct elf32_vfp11_erratum_list
*branch
;
2676 elf32_vfp11_erratum_type type
;
2678 elf32_vfp11_erratum_list
;
2683 INSERT_EXIDX_CANTUNWIND_AT_END
2685 arm_unwind_edit_type
;
2687 /* A (sorted) list of edits to apply to an unwind table. */
2688 typedef struct arm_unwind_table_edit
2690 arm_unwind_edit_type type
;
2691 /* Note: we sometimes want to insert an unwind entry corresponding to a
2692 section different from the one we're currently writing out, so record the
2693 (text) section this edit relates to here. */
2694 asection
*linked_section
;
2696 struct arm_unwind_table_edit
*next
;
2698 arm_unwind_table_edit
;
2700 typedef struct _arm_elf_section_data
2702 /* Information about mapping symbols. */
2703 struct bfd_elf_section_data elf
;
2704 unsigned int mapcount
;
2705 unsigned int mapsize
;
2706 elf32_arm_section_map
*map
;
2707 /* Information about CPU errata. */
2708 unsigned int erratumcount
;
2709 elf32_vfp11_erratum_list
*erratumlist
;
2710 /* Information about unwind tables. */
2713 /* Unwind info attached to a text section. */
2716 asection
*arm_exidx_sec
;
2719 /* Unwind info attached to an .ARM.exidx section. */
2722 arm_unwind_table_edit
*unwind_edit_list
;
2723 arm_unwind_table_edit
*unwind_edit_tail
;
2727 _arm_elf_section_data
;
2729 #define elf32_arm_section_data(sec) \
2730 ((_arm_elf_section_data *) elf_section_data (sec))
2732 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2733 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2734 so may be created multiple times: we use an array of these entries whilst
2735 relaxing which we can refresh easily, then create stubs for each potentially
2736 erratum-triggering instruction once we've settled on a solution. */
2738 struct a8_erratum_fix
2744 unsigned long orig_insn
;
2746 enum elf32_arm_stub_type stub_type
;
2747 enum arm_st_branch_type branch_type
;
2750 /* A table of relocs applied to branches which might trigger Cortex-A8
2753 struct a8_erratum_reloc
2756 bfd_vma destination
;
2757 struct elf32_arm_link_hash_entry
*hash
;
2758 const char *sym_name
;
2759 unsigned int r_type
;
2760 enum arm_st_branch_type branch_type
;
2761 bfd_boolean non_a8_stub
;
2764 /* The size of the thread control block. */
2767 /* ARM-specific information about a PLT entry, over and above the usual
2771 /* We reference count Thumb references to a PLT entry separately,
2772 so that we can emit the Thumb trampoline only if needed. */
2773 bfd_signed_vma thumb_refcount
;
2775 /* Some references from Thumb code may be eliminated by BL->BLX
2776 conversion, so record them separately. */
2777 bfd_signed_vma maybe_thumb_refcount
;
2779 /* How many of the recorded PLT accesses were from non-call relocations.
2780 This information is useful when deciding whether anything takes the
2781 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
2782 non-call references to the function should resolve directly to the
2783 real runtime target. */
2784 unsigned int noncall_refcount
;
2786 /* Since PLT entries have variable size if the Thumb prologue is
2787 used, we need to record the index into .got.plt instead of
2788 recomputing it from the PLT offset. */
2789 bfd_signed_vma got_offset
;
2792 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
2793 struct arm_local_iplt_info
2795 /* The information that is usually found in the generic ELF part of
2796 the hash table entry. */
2797 union gotplt_union root
;
2799 /* The information that is usually found in the ARM-specific part of
2800 the hash table entry. */
2801 struct arm_plt_info arm
;
2803 /* A list of all potential dynamic relocations against this symbol. */
2804 struct elf_dyn_relocs
*dyn_relocs
;
2807 struct elf_arm_obj_tdata
2809 struct elf_obj_tdata root
;
2811 /* tls_type for each local got entry. */
2812 char *local_got_tls_type
;
2814 /* GOTPLT entries for TLS descriptors. */
2815 bfd_vma
*local_tlsdesc_gotent
;
2817 /* Information for local symbols that need entries in .iplt. */
2818 struct arm_local_iplt_info
**local_iplt
;
2820 /* Zero to warn when linking objects with incompatible enum sizes. */
2821 int no_enum_size_warning
;
2823 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2824 int no_wchar_size_warning
;
2827 #define elf_arm_tdata(bfd) \
2828 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2830 #define elf32_arm_local_got_tls_type(bfd) \
2831 (elf_arm_tdata (bfd)->local_got_tls_type)
2833 #define elf32_arm_local_tlsdesc_gotent(bfd) \
2834 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
2836 #define elf32_arm_local_iplt(bfd) \
2837 (elf_arm_tdata (bfd)->local_iplt)
2839 #define is_arm_elf(bfd) \
2840 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2841 && elf_tdata (bfd) != NULL \
2842 && elf_object_id (bfd) == ARM_ELF_DATA)
2845 elf32_arm_mkobject (bfd
*abfd
)
2847 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2851 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2853 /* Arm ELF linker hash entry. */
2854 struct elf32_arm_link_hash_entry
2856 struct elf_link_hash_entry root
;
2858 /* Track dynamic relocs copied for this symbol. */
2859 struct elf_dyn_relocs
*dyn_relocs
;
2861 /* ARM-specific PLT information. */
2862 struct arm_plt_info plt
;
2864 #define GOT_UNKNOWN 0
2865 #define GOT_NORMAL 1
2866 #define GOT_TLS_GD 2
2867 #define GOT_TLS_IE 4
2868 #define GOT_TLS_GDESC 8
2869 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
2870 unsigned int tls_type
: 8;
2872 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
2873 unsigned int is_iplt
: 1;
2875 unsigned int unused
: 23;
2877 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
2878 starting at the end of the jump table. */
2879 bfd_vma tlsdesc_got
;
2881 /* The symbol marking the real symbol location for exported thumb
2882 symbols with Arm stubs. */
2883 struct elf_link_hash_entry
*export_glue
;
2885 /* A pointer to the most recently used stub hash entry against this
2887 struct elf32_arm_stub_hash_entry
*stub_cache
;
2890 /* Traverse an arm ELF linker hash table. */
2891 #define elf32_arm_link_hash_traverse(table, func, info) \
2892 (elf_link_hash_traverse \
2894 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2897 /* Get the ARM elf linker hash table from a link_info structure. */
2898 #define elf32_arm_hash_table(info) \
2899 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
2900 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
2902 #define arm_stub_hash_lookup(table, string, create, copy) \
2903 ((struct elf32_arm_stub_hash_entry *) \
2904 bfd_hash_lookup ((table), (string), (create), (copy)))
2906 /* Array to keep track of which stub sections have been created, and
2907 information on stub grouping. */
2910 /* This is the section to which stubs in the group will be
2913 /* The stub section. */
2917 #define elf32_arm_compute_jump_table_size(htab) \
2918 ((htab)->next_tls_desc_index * 4)
2920 /* ARM ELF linker hash table. */
2921 struct elf32_arm_link_hash_table
2923 /* The main hash table. */
2924 struct elf_link_hash_table root
;
2926 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2927 bfd_size_type thumb_glue_size
;
2929 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2930 bfd_size_type arm_glue_size
;
2932 /* The size in bytes of section containing the ARMv4 BX veneers. */
2933 bfd_size_type bx_glue_size
;
2935 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2936 veneer has been populated. */
2937 bfd_vma bx_glue_offset
[15];
2939 /* The size in bytes of the section containing glue for VFP11 erratum
2941 bfd_size_type vfp11_erratum_glue_size
;
2943 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
2944 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
2945 elf32_arm_write_section(). */
2946 struct a8_erratum_fix
*a8_erratum_fixes
;
2947 unsigned int num_a8_erratum_fixes
;
2949 /* An arbitrary input BFD chosen to hold the glue sections. */
2950 bfd
* bfd_of_glue_owner
;
2952 /* Nonzero to output a BE8 image. */
2955 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2956 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2959 /* The relocation to use for R_ARM_TARGET2 relocations. */
2962 /* 0 = Ignore R_ARM_V4BX.
2963 1 = Convert BX to MOV PC.
2964 2 = Generate v4 interworing stubs. */
2967 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
2970 /* Whether we should fix the ARM1176 BLX immediate issue. */
2973 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2976 /* What sort of code sequences we should look for which may trigger the
2977 VFP11 denorm erratum. */
2978 bfd_arm_vfp11_fix vfp11_fix
;
2980 /* Global counter for the number of fixes we have emitted. */
2981 int num_vfp11_fixes
;
2983 /* Nonzero to force PIC branch veneers. */
2986 /* The number of bytes in the initial entry in the PLT. */
2987 bfd_size_type plt_header_size
;
2989 /* The number of bytes in the subsequent PLT etries. */
2990 bfd_size_type plt_entry_size
;
2992 /* True if the target system is VxWorks. */
2995 /* True if the target system is Symbian OS. */
2998 /* True if the target system is Native Client. */
3001 /* True if the target uses REL relocations. */
3004 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
3005 bfd_vma next_tls_desc_index
;
3007 /* How many R_ARM_TLS_DESC relocations were generated so far. */
3008 bfd_vma num_tls_desc
;
3010 /* Short-cuts to get to dynamic linker sections. */
3014 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
3017 /* The offset into splt of the PLT entry for the TLS descriptor
3018 resolver. Special values are 0, if not necessary (or not found
3019 to be necessary yet), and -1 if needed but not determined
3021 bfd_vma dt_tlsdesc_plt
;
3023 /* The offset into sgot of the GOT entry used by the PLT entry
3025 bfd_vma dt_tlsdesc_got
;
3027 /* Offset in .plt section of tls_arm_trampoline. */
3028 bfd_vma tls_trampoline
;
3030 /* Data for R_ARM_TLS_LDM32 relocations. */
3033 bfd_signed_vma refcount
;
3037 /* Small local sym cache. */
3038 struct sym_cache sym_cache
;
3040 /* For convenience in allocate_dynrelocs. */
3043 /* The amount of space used by the reserved portion of the sgotplt
3044 section, plus whatever space is used by the jump slots. */
3045 bfd_vma sgotplt_jump_table_size
;
3047 /* The stub hash table. */
3048 struct bfd_hash_table stub_hash_table
;
3050 /* Linker stub bfd. */
3053 /* Linker call-backs. */
3054 asection
* (*add_stub_section
) (const char *, asection
*, unsigned int);
3055 void (*layout_sections_again
) (void);
3057 /* Array to keep track of which stub sections have been created, and
3058 information on stub grouping. */
3059 struct map_stub
*stub_group
;
3061 /* Number of elements in stub_group. */
3064 /* Assorted information used by elf32_arm_size_stubs. */
3065 unsigned int bfd_count
;
3067 asection
**input_list
;
3070 /* Create an entry in an ARM ELF linker hash table. */
3072 static struct bfd_hash_entry
*
3073 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
3074 struct bfd_hash_table
* table
,
3075 const char * string
)
3077 struct elf32_arm_link_hash_entry
* ret
=
3078 (struct elf32_arm_link_hash_entry
*) entry
;
3080 /* Allocate the structure if it has not already been allocated by a
3083 ret
= (struct elf32_arm_link_hash_entry
*)
3084 bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
3086 return (struct bfd_hash_entry
*) ret
;
3088 /* Call the allocation method of the superclass. */
3089 ret
= ((struct elf32_arm_link_hash_entry
*)
3090 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3094 ret
->dyn_relocs
= NULL
;
3095 ret
->tls_type
= GOT_UNKNOWN
;
3096 ret
->tlsdesc_got
= (bfd_vma
) -1;
3097 ret
->plt
.thumb_refcount
= 0;
3098 ret
->plt
.maybe_thumb_refcount
= 0;
3099 ret
->plt
.noncall_refcount
= 0;
3100 ret
->plt
.got_offset
= -1;
3101 ret
->is_iplt
= FALSE
;
3102 ret
->export_glue
= NULL
;
3104 ret
->stub_cache
= NULL
;
3107 return (struct bfd_hash_entry
*) ret
;
3110 /* Ensure that we have allocated bookkeeping structures for ABFD's local
3114 elf32_arm_allocate_local_sym_info (bfd
*abfd
)
3116 if (elf_local_got_refcounts (abfd
) == NULL
)
3118 bfd_size_type num_syms
;
3122 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
3123 size
= num_syms
* (sizeof (bfd_signed_vma
)
3124 + sizeof (struct arm_local_iplt_info
*)
3127 data
= bfd_zalloc (abfd
, size
);
3131 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
3132 data
+= num_syms
* sizeof (bfd_signed_vma
);
3134 elf32_arm_local_iplt (abfd
) = (struct arm_local_iplt_info
**) data
;
3135 data
+= num_syms
* sizeof (struct arm_local_iplt_info
*);
3137 elf32_arm_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
3138 data
+= num_syms
* sizeof (bfd_vma
);
3140 elf32_arm_local_got_tls_type (abfd
) = data
;
3145 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
3146 to input bfd ABFD. Create the information if it doesn't already exist.
3147 Return null if an allocation fails. */
3149 static struct arm_local_iplt_info
*
3150 elf32_arm_create_local_iplt (bfd
*abfd
, unsigned long r_symndx
)
3152 struct arm_local_iplt_info
**ptr
;
3154 if (!elf32_arm_allocate_local_sym_info (abfd
))
3157 BFD_ASSERT (r_symndx
< elf_tdata (abfd
)->symtab_hdr
.sh_info
);
3158 ptr
= &elf32_arm_local_iplt (abfd
)[r_symndx
];
3160 *ptr
= bfd_zalloc (abfd
, sizeof (**ptr
));
3164 /* Try to obtain PLT information for the symbol with index R_SYMNDX
3165 in ABFD's symbol table. If the symbol is global, H points to its
3166 hash table entry, otherwise H is null.
3168 Return true if the symbol does have PLT information. When returning
3169 true, point *ROOT_PLT at the target-independent reference count/offset
3170 union and *ARM_PLT at the ARM-specific information. */
3173 elf32_arm_get_plt_info (bfd
*abfd
, struct elf32_arm_link_hash_entry
*h
,
3174 unsigned long r_symndx
, union gotplt_union
**root_plt
,
3175 struct arm_plt_info
**arm_plt
)
3177 struct arm_local_iplt_info
*local_iplt
;
3181 *root_plt
= &h
->root
.plt
;
3186 if (elf32_arm_local_iplt (abfd
) == NULL
)
3189 local_iplt
= elf32_arm_local_iplt (abfd
)[r_symndx
];
3190 if (local_iplt
== NULL
)
3193 *root_plt
= &local_iplt
->root
;
3194 *arm_plt
= &local_iplt
->arm
;
3198 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3202 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info
*info
,
3203 struct arm_plt_info
*arm_plt
)
3205 struct elf32_arm_link_hash_table
*htab
;
3207 htab
= elf32_arm_hash_table (info
);
3208 return (arm_plt
->thumb_refcount
!= 0
3209 || (!htab
->use_blx
&& arm_plt
->maybe_thumb_refcount
!= 0));
3212 /* Return a pointer to the head of the dynamic reloc list that should
3213 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3214 ABFD's symbol table. Return null if an error occurs. */
3216 static struct elf_dyn_relocs
**
3217 elf32_arm_get_local_dynreloc_list (bfd
*abfd
, unsigned long r_symndx
,
3218 Elf_Internal_Sym
*isym
)
3220 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
3222 struct arm_local_iplt_info
*local_iplt
;
3224 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
3225 if (local_iplt
== NULL
)
3227 return &local_iplt
->dyn_relocs
;
3231 /* Track dynamic relocs needed for local syms too.
3232 We really need local syms available to do this
3237 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3241 vpp
= &elf_section_data (s
)->local_dynrel
;
3242 return (struct elf_dyn_relocs
**) vpp
;
3246 /* Initialize an entry in the stub hash table. */
3248 static struct bfd_hash_entry
*
3249 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3250 struct bfd_hash_table
*table
,
3253 /* Allocate the structure if it has not already been allocated by a
3257 entry
= (struct bfd_hash_entry
*)
3258 bfd_hash_allocate (table
, sizeof (struct elf32_arm_stub_hash_entry
));
3263 /* Call the allocation method of the superclass. */
3264 entry
= bfd_hash_newfunc (entry
, table
, string
);
3267 struct elf32_arm_stub_hash_entry
*eh
;
3269 /* Initialize the local fields. */
3270 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
3271 eh
->stub_sec
= NULL
;
3272 eh
->stub_offset
= 0;
3273 eh
->target_value
= 0;
3274 eh
->target_section
= NULL
;
3275 eh
->target_addend
= 0;
3277 eh
->stub_type
= arm_stub_none
;
3279 eh
->stub_template
= NULL
;
3280 eh
->stub_template_size
= 0;
3283 eh
->output_name
= NULL
;
3289 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3290 shortcuts to them in our hash table. */
3293 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3295 struct elf32_arm_link_hash_table
*htab
;
3297 htab
= elf32_arm_hash_table (info
);
3301 /* BPABI objects never have a GOT, or associated sections. */
3302 if (htab
->symbian_p
)
3305 if (! _bfd_elf_create_got_section (dynobj
, info
))
3311 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3314 create_ifunc_sections (struct bfd_link_info
*info
)
3316 struct elf32_arm_link_hash_table
*htab
;
3317 const struct elf_backend_data
*bed
;
3322 htab
= elf32_arm_hash_table (info
);
3323 dynobj
= htab
->root
.dynobj
;
3324 bed
= get_elf_backend_data (dynobj
);
3325 flags
= bed
->dynamic_sec_flags
;
3327 if (htab
->root
.iplt
== NULL
)
3329 s
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt",
3330 flags
| SEC_READONLY
| SEC_CODE
);
3332 || !bfd_set_section_alignment (dynobj
, s
, bed
->plt_alignment
))
3334 htab
->root
.iplt
= s
;
3337 if (htab
->root
.irelplt
== NULL
)
3339 s
= bfd_make_section_anyway_with_flags (dynobj
,
3340 RELOC_SECTION (htab
, ".iplt"),
3341 flags
| SEC_READONLY
);
3343 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3345 htab
->root
.irelplt
= s
;
3348 if (htab
->root
.igotplt
== NULL
)
3350 s
= bfd_make_section_anyway_with_flags (dynobj
, ".igot.plt", flags
);
3352 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3354 htab
->root
.igotplt
= s
;
3359 /* Determine if we're dealing with a Thumb only architecture. */
3362 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
3364 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3368 if (arch
== TAG_CPU_ARCH_V6_M
|| arch
== TAG_CPU_ARCH_V6S_M
)
3371 if (arch
!= TAG_CPU_ARCH_V7
&& arch
!= TAG_CPU_ARCH_V7E_M
)
3374 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3375 Tag_CPU_arch_profile
);
3377 return profile
== 'M';
3380 /* Determine if we're dealing with a Thumb-2 object. */
3383 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
3385 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3387 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
3390 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3391 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3395 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3397 struct elf32_arm_link_hash_table
*htab
;
3399 htab
= elf32_arm_hash_table (info
);
3403 if (!htab
->root
.sgot
&& !create_got_section (dynobj
, info
))
3406 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3409 htab
->sdynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
3411 htab
->srelbss
= bfd_get_linker_section (dynobj
,
3412 RELOC_SECTION (htab
, ".bss"));
3414 if (htab
->vxworks_p
)
3416 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
3421 htab
->plt_header_size
= 0;
3422 htab
->plt_entry_size
3423 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
3427 htab
->plt_header_size
3428 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
3429 htab
->plt_entry_size
3430 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
3436 Test for thumb only architectures. Note - we cannot just call
3437 using_thumb_only() as the attributes in the output bfd have not been
3438 initialised at this point, so instead we use the input bfd. */
3439 bfd
* saved_obfd
= htab
->obfd
;
3441 htab
->obfd
= dynobj
;
3442 if (using_thumb_only (htab
))
3444 htab
->plt_header_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry
);
3445 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt_entry
);
3447 htab
->obfd
= saved_obfd
;
3450 if (!htab
->root
.splt
3451 || !htab
->root
.srelplt
3453 || (!info
->shared
&& !htab
->srelbss
))
3459 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3462 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
3463 struct elf_link_hash_entry
*dir
,
3464 struct elf_link_hash_entry
*ind
)
3466 struct elf32_arm_link_hash_entry
*edir
, *eind
;
3468 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
3469 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
3471 if (eind
->dyn_relocs
!= NULL
)
3473 if (edir
->dyn_relocs
!= NULL
)
3475 struct elf_dyn_relocs
**pp
;
3476 struct elf_dyn_relocs
*p
;
3478 /* Add reloc counts against the indirect sym to the direct sym
3479 list. Merge any entries against the same section. */
3480 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3482 struct elf_dyn_relocs
*q
;
3484 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3485 if (q
->sec
== p
->sec
)
3487 q
->pc_count
+= p
->pc_count
;
3488 q
->count
+= p
->count
;
3495 *pp
= edir
->dyn_relocs
;
3498 edir
->dyn_relocs
= eind
->dyn_relocs
;
3499 eind
->dyn_relocs
= NULL
;
3502 if (ind
->root
.type
== bfd_link_hash_indirect
)
3504 /* Copy over PLT info. */
3505 edir
->plt
.thumb_refcount
+= eind
->plt
.thumb_refcount
;
3506 eind
->plt
.thumb_refcount
= 0;
3507 edir
->plt
.maybe_thumb_refcount
+= eind
->plt
.maybe_thumb_refcount
;
3508 eind
->plt
.maybe_thumb_refcount
= 0;
3509 edir
->plt
.noncall_refcount
+= eind
->plt
.noncall_refcount
;
3510 eind
->plt
.noncall_refcount
= 0;
3512 /* We should only allocate a function to .iplt once the final
3513 symbol information is known. */
3514 BFD_ASSERT (!eind
->is_iplt
);
3516 if (dir
->got
.refcount
<= 0)
3518 edir
->tls_type
= eind
->tls_type
;
3519 eind
->tls_type
= GOT_UNKNOWN
;
3523 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3526 /* Destroy an ARM elf linker hash table. */
3529 elf32_arm_link_hash_table_free (bfd
*obfd
)
3531 struct elf32_arm_link_hash_table
*ret
3532 = (struct elf32_arm_link_hash_table
*) obfd
->link
.hash
;
3534 bfd_hash_table_free (&ret
->stub_hash_table
);
3535 _bfd_elf_link_hash_table_free (obfd
);
3538 /* Create an ARM elf linker hash table. */
3540 static struct bfd_link_hash_table
*
3541 elf32_arm_link_hash_table_create (bfd
*abfd
)
3543 struct elf32_arm_link_hash_table
*ret
;
3544 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
3546 ret
= (struct elf32_arm_link_hash_table
*) bfd_zmalloc (amt
);
3550 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
3551 elf32_arm_link_hash_newfunc
,
3552 sizeof (struct elf32_arm_link_hash_entry
),
3559 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
3560 #ifdef FOUR_WORD_PLT
3561 ret
->plt_header_size
= 16;
3562 ret
->plt_entry_size
= 16;
3564 ret
->plt_header_size
= 20;
3565 ret
->plt_entry_size
= elf32_arm_use_long_plt_entry
? 16 : 12;
3570 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
3571 sizeof (struct elf32_arm_stub_hash_entry
)))
3573 _bfd_elf_link_hash_table_free (abfd
);
3576 ret
->root
.root
.hash_table_free
= elf32_arm_link_hash_table_free
;
3578 return &ret
->root
.root
;
3581 /* Determine what kind of NOPs are available. */
3584 arch_has_arm_nop (struct elf32_arm_link_hash_table
*globals
)
3586 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3588 return arch
== TAG_CPU_ARCH_V6T2
3589 || arch
== TAG_CPU_ARCH_V6K
3590 || arch
== TAG_CPU_ARCH_V7
3591 || arch
== TAG_CPU_ARCH_V7E_M
;
3595 arch_has_thumb2_nop (struct elf32_arm_link_hash_table
*globals
)
3597 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3599 return (arch
== TAG_CPU_ARCH_V6T2
|| arch
== TAG_CPU_ARCH_V7
3600 || arch
== TAG_CPU_ARCH_V7E_M
);
3604 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
3608 case arm_stub_long_branch_thumb_only
:
3609 case arm_stub_long_branch_v4t_thumb_arm
:
3610 case arm_stub_short_branch_v4t_thumb_arm
:
3611 case arm_stub_long_branch_v4t_thumb_arm_pic
:
3612 case arm_stub_long_branch_v4t_thumb_tls_pic
:
3613 case arm_stub_long_branch_thumb_only_pic
:
3624 /* Determine the type of stub needed, if any, for a call. */
3626 static enum elf32_arm_stub_type
3627 arm_type_of_stub (struct bfd_link_info
*info
,
3628 asection
*input_sec
,
3629 const Elf_Internal_Rela
*rel
,
3630 unsigned char st_type
,
3631 enum arm_st_branch_type
*actual_branch_type
,
3632 struct elf32_arm_link_hash_entry
*hash
,
3633 bfd_vma destination
,
3639 bfd_signed_vma branch_offset
;
3640 unsigned int r_type
;
3641 struct elf32_arm_link_hash_table
* globals
;
3644 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
3646 enum arm_st_branch_type branch_type
= *actual_branch_type
;
3647 union gotplt_union
*root_plt
;
3648 struct arm_plt_info
*arm_plt
;
3650 if (branch_type
== ST_BRANCH_LONG
)
3653 globals
= elf32_arm_hash_table (info
);
3654 if (globals
== NULL
)
3657 thumb_only
= using_thumb_only (globals
);
3659 thumb2
= using_thumb2 (globals
);
3661 /* Determine where the call point is. */
3662 location
= (input_sec
->output_offset
3663 + input_sec
->output_section
->vma
3666 r_type
= ELF32_R_TYPE (rel
->r_info
);
3668 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
3669 are considering a function call relocation. */
3670 if (thumb_only
&& (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
3671 && branch_type
== ST_BRANCH_TO_ARM
)
3672 branch_type
= ST_BRANCH_TO_THUMB
;
3674 /* For TLS call relocs, it is the caller's responsibility to provide
3675 the address of the appropriate trampoline. */
3676 if (r_type
!= R_ARM_TLS_CALL
3677 && r_type
!= R_ARM_THM_TLS_CALL
3678 && elf32_arm_get_plt_info (input_bfd
, hash
, ELF32_R_SYM (rel
->r_info
),
3679 &root_plt
, &arm_plt
)
3680 && root_plt
->offset
!= (bfd_vma
) -1)
3684 if (hash
== NULL
|| hash
->is_iplt
)
3685 splt
= globals
->root
.iplt
;
3687 splt
= globals
->root
.splt
;
3692 /* Note when dealing with PLT entries: the main PLT stub is in
3693 ARM mode, so if the branch is in Thumb mode, another
3694 Thumb->ARM stub will be inserted later just before the ARM
3695 PLT stub. We don't take this extra distance into account
3696 here, because if a long branch stub is needed, we'll add a
3697 Thumb->Arm one and branch directly to the ARM PLT entry
3698 because it avoids spreading offset corrections in several
3701 destination
= (splt
->output_section
->vma
3702 + splt
->output_offset
3703 + root_plt
->offset
);
3705 branch_type
= ST_BRANCH_TO_ARM
;
3708 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
3709 BFD_ASSERT (st_type
!= STT_GNU_IFUNC
);
3711 branch_offset
= (bfd_signed_vma
)(destination
- location
);
3713 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
3714 || r_type
== R_ARM_THM_TLS_CALL
)
3716 /* Handle cases where:
3717 - this call goes too far (different Thumb/Thumb2 max
3719 - it's a Thumb->Arm call and blx is not available, or it's a
3720 Thumb->Arm branch (not bl). A stub is needed in this case,
3721 but only if this call is not through a PLT entry. Indeed,
3722 PLT stubs handle mode switching already.
3725 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
3726 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
3728 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
3729 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
3730 || (branch_type
== ST_BRANCH_TO_ARM
3731 && (((r_type
== R_ARM_THM_CALL
3732 || r_type
== R_ARM_THM_TLS_CALL
) && !globals
->use_blx
)
3733 || (r_type
== R_ARM_THM_JUMP24
))
3736 if (branch_type
== ST_BRANCH_TO_THUMB
)
3738 /* Thumb to thumb. */
3741 stub_type
= (info
->shared
| globals
->pic_veneer
)
3743 ? ((globals
->use_blx
3744 && (r_type
== R_ARM_THM_CALL
))
3745 /* V5T and above. Stub starts with ARM code, so
3746 we must be able to switch mode before
3747 reaching it, which is only possible for 'bl'
3748 (ie R_ARM_THM_CALL relocation). */
3749 ? arm_stub_long_branch_any_thumb_pic
3750 /* On V4T, use Thumb code only. */
3751 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
3753 /* non-PIC stubs. */
3754 : ((globals
->use_blx
3755 && (r_type
== R_ARM_THM_CALL
))
3756 /* V5T and above. */
3757 ? arm_stub_long_branch_any_any
3759 : arm_stub_long_branch_v4t_thumb_thumb
);
3763 stub_type
= (info
->shared
| globals
->pic_veneer
)
3765 ? arm_stub_long_branch_thumb_only_pic
3767 : arm_stub_long_branch_thumb_only
;
3774 && sym_sec
->owner
!= NULL
3775 && !INTERWORK_FLAG (sym_sec
->owner
))
3777 (*_bfd_error_handler
)
3778 (_("%B(%s): warning: interworking not enabled.\n"
3779 " first occurrence: %B: Thumb call to ARM"),
3780 sym_sec
->owner
, input_bfd
, name
);
3784 (info
->shared
| globals
->pic_veneer
)
3786 ? (r_type
== R_ARM_THM_TLS_CALL
3787 /* TLS PIC stubs. */
3788 ? (globals
->use_blx
? arm_stub_long_branch_any_tls_pic
3789 : arm_stub_long_branch_v4t_thumb_tls_pic
)
3790 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3791 /* V5T PIC and above. */
3792 ? arm_stub_long_branch_any_arm_pic
3794 : arm_stub_long_branch_v4t_thumb_arm_pic
))
3796 /* non-PIC stubs. */
3797 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3798 /* V5T and above. */
3799 ? arm_stub_long_branch_any_any
3801 : arm_stub_long_branch_v4t_thumb_arm
);
3803 /* Handle v4t short branches. */
3804 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3805 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3806 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3807 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3811 else if (r_type
== R_ARM_CALL
3812 || r_type
== R_ARM_JUMP24
3813 || r_type
== R_ARM_PLT32
3814 || r_type
== R_ARM_TLS_CALL
)
3816 if (branch_type
== ST_BRANCH_TO_THUMB
)
3821 && sym_sec
->owner
!= NULL
3822 && !INTERWORK_FLAG (sym_sec
->owner
))
3824 (*_bfd_error_handler
)
3825 (_("%B(%s): warning: interworking not enabled.\n"
3826 " first occurrence: %B: ARM call to Thumb"),
3827 sym_sec
->owner
, input_bfd
, name
);
3830 /* We have an extra 2-bytes reach because of
3831 the mode change (bit 24 (H) of BLX encoding). */
3832 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3833 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3834 || (r_type
== R_ARM_CALL
&& !globals
->use_blx
)
3835 || (r_type
== R_ARM_JUMP24
)
3836 || (r_type
== R_ARM_PLT32
))
3838 stub_type
= (info
->shared
| globals
->pic_veneer
)
3840 ? ((globals
->use_blx
)
3841 /* V5T and above. */
3842 ? arm_stub_long_branch_any_thumb_pic
3844 : arm_stub_long_branch_v4t_arm_thumb_pic
)
3846 /* non-PIC stubs. */
3847 : ((globals
->use_blx
)
3848 /* V5T and above. */
3849 ? arm_stub_long_branch_any_any
3851 : arm_stub_long_branch_v4t_arm_thumb
);
3857 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3858 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3861 (info
->shared
| globals
->pic_veneer
)
3863 ? (r_type
== R_ARM_TLS_CALL
3865 ? arm_stub_long_branch_any_tls_pic
3867 ? arm_stub_long_branch_arm_nacl_pic
3868 : arm_stub_long_branch_any_arm_pic
))
3869 /* non-PIC stubs. */
3871 ? arm_stub_long_branch_arm_nacl
3872 : arm_stub_long_branch_any_any
);
3877 /* If a stub is needed, record the actual destination type. */
3878 if (stub_type
!= arm_stub_none
)
3879 *actual_branch_type
= branch_type
;
3884 /* Build a name for an entry in the stub hash table. */
3887 elf32_arm_stub_name (const asection
*input_section
,
3888 const asection
*sym_sec
,
3889 const struct elf32_arm_link_hash_entry
*hash
,
3890 const Elf_Internal_Rela
*rel
,
3891 enum elf32_arm_stub_type stub_type
)
3898 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1 + 2 + 1;
3899 stub_name
= (char *) bfd_malloc (len
);
3900 if (stub_name
!= NULL
)
3901 sprintf (stub_name
, "%08x_%s+%x_%d",
3902 input_section
->id
& 0xffffffff,
3903 hash
->root
.root
.root
.string
,
3904 (int) rel
->r_addend
& 0xffffffff,
3909 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
3910 stub_name
= (char *) bfd_malloc (len
);
3911 if (stub_name
!= NULL
)
3912 sprintf (stub_name
, "%08x_%x:%x+%x_%d",
3913 input_section
->id
& 0xffffffff,
3914 sym_sec
->id
& 0xffffffff,
3915 ELF32_R_TYPE (rel
->r_info
) == R_ARM_TLS_CALL
3916 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_TLS_CALL
3917 ? 0 : (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
3918 (int) rel
->r_addend
& 0xffffffff,
3925 /* Look up an entry in the stub hash. Stub entries are cached because
3926 creating the stub name takes a bit of time. */
3928 static struct elf32_arm_stub_hash_entry
*
3929 elf32_arm_get_stub_entry (const asection
*input_section
,
3930 const asection
*sym_sec
,
3931 struct elf_link_hash_entry
*hash
,
3932 const Elf_Internal_Rela
*rel
,
3933 struct elf32_arm_link_hash_table
*htab
,
3934 enum elf32_arm_stub_type stub_type
)
3936 struct elf32_arm_stub_hash_entry
*stub_entry
;
3937 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
3938 const asection
*id_sec
;
3940 if ((input_section
->flags
& SEC_CODE
) == 0)
3943 /* If this input section is part of a group of sections sharing one
3944 stub section, then use the id of the first section in the group.
3945 Stub names need to include a section id, as there may well be
3946 more than one stub used to reach say, printf, and we need to
3947 distinguish between them. */
3948 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3950 if (h
!= NULL
&& h
->stub_cache
!= NULL
3951 && h
->stub_cache
->h
== h
3952 && h
->stub_cache
->id_sec
== id_sec
3953 && h
->stub_cache
->stub_type
== stub_type
)
3955 stub_entry
= h
->stub_cache
;
3961 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
, stub_type
);
3962 if (stub_name
== NULL
)
3965 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3966 stub_name
, FALSE
, FALSE
);
3968 h
->stub_cache
= stub_entry
;
3976 /* Find or create a stub section. Returns a pointer to the stub section, and
3977 the section to which the stub section will be attached (in *LINK_SEC_P).
3978 LINK_SEC_P may be NULL. */
3981 elf32_arm_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
3982 struct elf32_arm_link_hash_table
*htab
)
3987 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3988 BFD_ASSERT (link_sec
!= NULL
);
3989 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3991 if (stub_sec
== NULL
)
3993 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3994 if (stub_sec
== NULL
)
4000 namelen
= strlen (link_sec
->name
);
4001 len
= namelen
+ sizeof (STUB_SUFFIX
);
4002 s_name
= (char *) bfd_alloc (htab
->stub_bfd
, len
);
4006 memcpy (s_name
, link_sec
->name
, namelen
);
4007 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4008 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
,
4009 htab
->nacl_p
? 4 : 3);
4010 if (stub_sec
== NULL
)
4012 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
4014 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
4018 *link_sec_p
= link_sec
;
4023 /* Add a new stub entry to the stub hash. Not all fields of the new
4024 stub entry are initialised. */
4026 static struct elf32_arm_stub_hash_entry
*
4027 elf32_arm_add_stub (const char *stub_name
,
4029 struct elf32_arm_link_hash_table
*htab
)
4033 struct elf32_arm_stub_hash_entry
*stub_entry
;
4035 stub_sec
= elf32_arm_create_or_find_stub_sec (&link_sec
, section
, htab
);
4036 if (stub_sec
== NULL
)
4039 /* Enter this entry into the linker stub hash table. */
4040 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4042 if (stub_entry
== NULL
)
4044 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
4050 stub_entry
->stub_sec
= stub_sec
;
4051 stub_entry
->stub_offset
= 0;
4052 stub_entry
->id_sec
= link_sec
;
4057 /* Store an Arm insn into an output section not processed by
4058 elf32_arm_write_section. */
4061 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
4062 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4064 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4065 bfd_putl32 (val
, ptr
);
4067 bfd_putb32 (val
, ptr
);
4070 /* Store a 16-bit Thumb insn into an output section not processed by
4071 elf32_arm_write_section. */
4074 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
4075 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
4077 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
4078 bfd_putl16 (val
, ptr
);
4080 bfd_putb16 (val
, ptr
);
4083 /* If it's possible to change R_TYPE to a more efficient access
4084 model, return the new reloc type. */
4087 elf32_arm_tls_transition (struct bfd_link_info
*info
, int r_type
,
4088 struct elf_link_hash_entry
*h
)
4090 int is_local
= (h
== NULL
);
4092 if (info
->shared
|| (h
&& h
->root
.type
== bfd_link_hash_undefweak
))
4095 /* We do not support relaxations for Old TLS models. */
4098 case R_ARM_TLS_GOTDESC
:
4099 case R_ARM_TLS_CALL
:
4100 case R_ARM_THM_TLS_CALL
:
4101 case R_ARM_TLS_DESCSEQ
:
4102 case R_ARM_THM_TLS_DESCSEQ
:
4103 return is_local
? R_ARM_TLS_LE32
: R_ARM_TLS_IE32
;
4109 static bfd_reloc_status_type elf32_arm_final_link_relocate
4110 (reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
4111 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
4112 const char *, unsigned char, enum arm_st_branch_type
,
4113 struct elf_link_hash_entry
*, bfd_boolean
*, char **);
4116 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type
)
4120 case arm_stub_a8_veneer_b_cond
:
4121 case arm_stub_a8_veneer_b
:
4122 case arm_stub_a8_veneer_bl
:
4125 case arm_stub_long_branch_any_any
:
4126 case arm_stub_long_branch_v4t_arm_thumb
:
4127 case arm_stub_long_branch_thumb_only
:
4128 case arm_stub_long_branch_v4t_thumb_thumb
:
4129 case arm_stub_long_branch_v4t_thumb_arm
:
4130 case arm_stub_short_branch_v4t_thumb_arm
:
4131 case arm_stub_long_branch_any_arm_pic
:
4132 case arm_stub_long_branch_any_thumb_pic
:
4133 case arm_stub_long_branch_v4t_thumb_thumb_pic
:
4134 case arm_stub_long_branch_v4t_arm_thumb_pic
:
4135 case arm_stub_long_branch_v4t_thumb_arm_pic
:
4136 case arm_stub_long_branch_thumb_only_pic
:
4137 case arm_stub_long_branch_any_tls_pic
:
4138 case arm_stub_long_branch_v4t_thumb_tls_pic
:
4139 case arm_stub_a8_veneer_blx
:
4142 case arm_stub_long_branch_arm_nacl
:
4143 case arm_stub_long_branch_arm_nacl_pic
:
4147 abort (); /* Should be unreachable. */
4152 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
4156 struct elf32_arm_stub_hash_entry
*stub_entry
;
4157 struct elf32_arm_link_hash_table
*globals
;
4158 struct bfd_link_info
*info
;
4165 const insn_sequence
*template_sequence
;
4167 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
4168 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
4171 /* Massage our args to the form they really have. */
4172 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4173 info
= (struct bfd_link_info
*) in_arg
;
4175 globals
= elf32_arm_hash_table (info
);
4176 if (globals
== NULL
)
4179 stub_sec
= stub_entry
->stub_sec
;
4181 if ((globals
->fix_cortex_a8
< 0)
4182 != (arm_stub_required_alignment (stub_entry
->stub_type
) == 2))
4183 /* We have to do less-strictly-aligned fixes last. */
4186 /* Make a note of the offset within the stubs for this entry. */
4187 stub_entry
->stub_offset
= stub_sec
->size
;
4188 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4190 stub_bfd
= stub_sec
->owner
;
4192 /* This is the address of the stub destination. */
4193 sym_value
= (stub_entry
->target_value
4194 + stub_entry
->target_section
->output_offset
4195 + stub_entry
->target_section
->output_section
->vma
);
4197 template_sequence
= stub_entry
->stub_template
;
4198 template_size
= stub_entry
->stub_template_size
;
4201 for (i
= 0; i
< template_size
; i
++)
4203 switch (template_sequence
[i
].type
)
4207 bfd_vma data
= (bfd_vma
) template_sequence
[i
].data
;
4208 if (template_sequence
[i
].reloc_addend
!= 0)
4210 /* We've borrowed the reloc_addend field to mean we should
4211 insert a condition code into this (Thumb-1 branch)
4212 instruction. See THUMB16_BCOND_INSN. */
4213 BFD_ASSERT ((data
& 0xff00) == 0xd000);
4214 data
|= ((stub_entry
->orig_insn
>> 22) & 0xf) << 8;
4216 bfd_put_16 (stub_bfd
, data
, loc
+ size
);
4222 bfd_put_16 (stub_bfd
,
4223 (template_sequence
[i
].data
>> 16) & 0xffff,
4225 bfd_put_16 (stub_bfd
, template_sequence
[i
].data
& 0xffff,
4227 if (template_sequence
[i
].r_type
!= R_ARM_NONE
)
4229 stub_reloc_idx
[nrelocs
] = i
;
4230 stub_reloc_offset
[nrelocs
++] = size
;
4236 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
,
4238 /* Handle cases where the target is encoded within the
4240 if (template_sequence
[i
].r_type
== R_ARM_JUMP24
)
4242 stub_reloc_idx
[nrelocs
] = i
;
4243 stub_reloc_offset
[nrelocs
++] = size
;
4249 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
, loc
+ size
);
4250 stub_reloc_idx
[nrelocs
] = i
;
4251 stub_reloc_offset
[nrelocs
++] = size
;
4261 stub_sec
->size
+= size
;
4263 /* Stub size has already been computed in arm_size_one_stub. Check
4265 BFD_ASSERT (size
== stub_entry
->stub_size
);
4267 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
4268 if (stub_entry
->branch_type
== ST_BRANCH_TO_THUMB
)
4271 /* Assume there is at least one and at most MAXRELOCS entries to relocate
4273 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
4275 for (i
= 0; i
< nrelocs
; i
++)
4276 if (template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP24
4277 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP19
4278 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_CALL
4279 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_XPC22
)
4281 Elf_Internal_Rela rel
;
4282 bfd_boolean unresolved_reloc
;
4283 char *error_message
;
4284 enum arm_st_branch_type branch_type
4285 = (template_sequence
[stub_reloc_idx
[i
]].r_type
!= R_ARM_THM_XPC22
4286 ? ST_BRANCH_TO_THUMB
: ST_BRANCH_TO_ARM
);
4287 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
;
4289 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4290 rel
.r_info
= ELF32_R_INFO (0,
4291 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4292 rel
.r_addend
= template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4294 if (stub_entry
->stub_type
== arm_stub_a8_veneer_b_cond
&& i
== 0)
4295 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
4296 template should refer back to the instruction after the original
4298 points_to
= sym_value
;
4300 /* There may be unintended consequences if this is not true. */
4301 BFD_ASSERT (stub_entry
->h
== NULL
);
4303 /* Note: _bfd_final_link_relocate doesn't handle these relocations
4304 properly. We should probably use this function unconditionally,
4305 rather than only for certain relocations listed in the enclosing
4306 conditional, for the sake of consistency. */
4307 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4308 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4309 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4310 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4311 branch_type
, (struct elf_link_hash_entry
*) stub_entry
->h
,
4312 &unresolved_reloc
, &error_message
);
4316 Elf_Internal_Rela rel
;
4317 bfd_boolean unresolved_reloc
;
4318 char *error_message
;
4319 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
4320 + template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4322 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4323 rel
.r_info
= ELF32_R_INFO (0,
4324 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4327 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4328 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4329 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4330 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4331 stub_entry
->branch_type
,
4332 (struct elf_link_hash_entry
*) stub_entry
->h
, &unresolved_reloc
,
4340 /* Calculate the template, template size and instruction size for a stub.
4341 Return value is the instruction size. */
4344 find_stub_size_and_template (enum elf32_arm_stub_type stub_type
,
4345 const insn_sequence
**stub_template
,
4346 int *stub_template_size
)
4348 const insn_sequence
*template_sequence
= NULL
;
4349 int template_size
= 0, i
;
4352 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
4354 *stub_template
= template_sequence
;
4356 template_size
= stub_definitions
[stub_type
].template_size
;
4357 if (stub_template_size
)
4358 *stub_template_size
= template_size
;
4361 for (i
= 0; i
< template_size
; i
++)
4363 switch (template_sequence
[i
].type
)
4384 /* As above, but don't actually build the stub. Just bump offset so
4385 we know stub section sizes. */
4388 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
4389 void *in_arg ATTRIBUTE_UNUSED
)
4391 struct elf32_arm_stub_hash_entry
*stub_entry
;
4392 const insn_sequence
*template_sequence
;
4393 int template_size
, size
;
4395 /* Massage our args to the form they really have. */
4396 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4398 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
4399 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
4401 size
= find_stub_size_and_template (stub_entry
->stub_type
, &template_sequence
,
4404 stub_entry
->stub_size
= size
;
4405 stub_entry
->stub_template
= template_sequence
;
4406 stub_entry
->stub_template_size
= template_size
;
4408 size
= (size
+ 7) & ~7;
4409 stub_entry
->stub_sec
->size
+= size
;
4414 /* External entry points for sizing and building linker stubs. */
4416 /* Set up various things so that we can make a list of input sections
4417 for each output section included in the link. Returns -1 on error,
4418 0 when no stubs will be needed, and 1 on success. */
4421 elf32_arm_setup_section_lists (bfd
*output_bfd
,
4422 struct bfd_link_info
*info
)
4425 unsigned int bfd_count
;
4426 int top_id
, top_index
;
4428 asection
**input_list
, **list
;
4430 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4434 if (! is_elf_hash_table (htab
))
4437 /* Count the number of input BFDs and find the top input section id. */
4438 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
4440 input_bfd
= input_bfd
->link
.next
)
4443 for (section
= input_bfd
->sections
;
4445 section
= section
->next
)
4447 if (top_id
< section
->id
)
4448 top_id
= section
->id
;
4451 htab
->bfd_count
= bfd_count
;
4453 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4454 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4455 if (htab
->stub_group
== NULL
)
4457 htab
->top_id
= top_id
;
4459 /* We can't use output_bfd->section_count here to find the top output
4460 section index as some sections may have been removed, and
4461 _bfd_strip_section_from_output doesn't renumber the indices. */
4462 for (section
= output_bfd
->sections
, top_index
= 0;
4464 section
= section
->next
)
4466 if (top_index
< section
->index
)
4467 top_index
= section
->index
;
4470 htab
->top_index
= top_index
;
4471 amt
= sizeof (asection
*) * (top_index
+ 1);
4472 input_list
= (asection
**) bfd_malloc (amt
);
4473 htab
->input_list
= input_list
;
4474 if (input_list
== NULL
)
4477 /* For sections we aren't interested in, mark their entries with a
4478 value we can check later. */
4479 list
= input_list
+ top_index
;
4481 *list
= bfd_abs_section_ptr
;
4482 while (list
-- != input_list
);
4484 for (section
= output_bfd
->sections
;
4486 section
= section
->next
)
4488 if ((section
->flags
& SEC_CODE
) != 0)
4489 input_list
[section
->index
] = NULL
;
4495 /* The linker repeatedly calls this function for each input section,
4496 in the order that input sections are linked into output sections.
4497 Build lists of input sections to determine groupings between which
4498 we may insert linker stubs. */
4501 elf32_arm_next_input_section (struct bfd_link_info
*info
,
4504 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4509 if (isec
->output_section
->index
<= htab
->top_index
)
4511 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4513 if (*list
!= bfd_abs_section_ptr
&& (isec
->flags
& SEC_CODE
) != 0)
4515 /* Steal the link_sec pointer for our list. */
4516 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4517 /* This happens to make the list in reverse order,
4518 which we reverse later. */
4519 PREV_SEC (isec
) = *list
;
4525 /* See whether we can group stub sections together. Grouping stub
4526 sections may result in fewer stubs. More importantly, we need to
4527 put all .init* and .fini* stubs at the end of the .init or
4528 .fini output sections respectively, because glibc splits the
4529 _init and _fini functions into multiple parts. Putting a stub in
4530 the middle of a function is not a good idea. */
4533 group_sections (struct elf32_arm_link_hash_table
*htab
,
4534 bfd_size_type stub_group_size
,
4535 bfd_boolean stubs_always_after_branch
)
4537 asection
**list
= htab
->input_list
;
4541 asection
*tail
= *list
;
4544 if (tail
== bfd_abs_section_ptr
)
4547 /* Reverse the list: we must avoid placing stubs at the
4548 beginning of the section because the beginning of the text
4549 section may be required for an interrupt vector in bare metal
4551 #define NEXT_SEC PREV_SEC
4553 while (tail
!= NULL
)
4555 /* Pop from tail. */
4556 asection
*item
= tail
;
4557 tail
= PREV_SEC (item
);
4560 NEXT_SEC (item
) = head
;
4564 while (head
!= NULL
)
4568 bfd_vma stub_group_start
= head
->output_offset
;
4569 bfd_vma end_of_next
;
4572 while (NEXT_SEC (curr
) != NULL
)
4574 next
= NEXT_SEC (curr
);
4575 end_of_next
= next
->output_offset
+ next
->size
;
4576 if (end_of_next
- stub_group_start
>= stub_group_size
)
4577 /* End of NEXT is too far from start, so stop. */
4579 /* Add NEXT to the group. */
4583 /* OK, the size from the start to the start of CURR is less
4584 than stub_group_size and thus can be handled by one stub
4585 section. (Or the head section is itself larger than
4586 stub_group_size, in which case we may be toast.)
4587 We should really be keeping track of the total size of
4588 stubs added here, as stubs contribute to the final output
4592 next
= NEXT_SEC (head
);
4593 /* Set up this stub group. */
4594 htab
->stub_group
[head
->id
].link_sec
= curr
;
4596 while (head
!= curr
&& (head
= next
) != NULL
);
4598 /* But wait, there's more! Input sections up to stub_group_size
4599 bytes after the stub section can be handled by it too. */
4600 if (!stubs_always_after_branch
)
4602 stub_group_start
= curr
->output_offset
+ curr
->size
;
4604 while (next
!= NULL
)
4606 end_of_next
= next
->output_offset
+ next
->size
;
4607 if (end_of_next
- stub_group_start
>= stub_group_size
)
4608 /* End of NEXT is too far from stubs, so stop. */
4610 /* Add NEXT to the stub group. */
4612 next
= NEXT_SEC (head
);
4613 htab
->stub_group
[head
->id
].link_sec
= curr
;
4619 while (list
++ != htab
->input_list
+ htab
->top_index
);
4621 free (htab
->input_list
);
4626 /* Comparison function for sorting/searching relocations relating to Cortex-A8
4630 a8_reloc_compare (const void *a
, const void *b
)
4632 const struct a8_erratum_reloc
*ra
= (const struct a8_erratum_reloc
*) a
;
4633 const struct a8_erratum_reloc
*rb
= (const struct a8_erratum_reloc
*) b
;
4635 if (ra
->from
< rb
->from
)
4637 else if (ra
->from
> rb
->from
)
4643 static struct elf_link_hash_entry
*find_thumb_glue (struct bfd_link_info
*,
4644 const char *, char **);
4646 /* Helper function to scan code for sequences which might trigger the Cortex-A8
4647 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
4648 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
4652 cortex_a8_erratum_scan (bfd
*input_bfd
,
4653 struct bfd_link_info
*info
,
4654 struct a8_erratum_fix
**a8_fixes_p
,
4655 unsigned int *num_a8_fixes_p
,
4656 unsigned int *a8_fix_table_size_p
,
4657 struct a8_erratum_reloc
*a8_relocs
,
4658 unsigned int num_a8_relocs
,
4659 unsigned prev_num_a8_fixes
,
4660 bfd_boolean
*stub_changed_p
)
4663 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4664 struct a8_erratum_fix
*a8_fixes
= *a8_fixes_p
;
4665 unsigned int num_a8_fixes
= *num_a8_fixes_p
;
4666 unsigned int a8_fix_table_size
= *a8_fix_table_size_p
;
4671 for (section
= input_bfd
->sections
;
4673 section
= section
->next
)
4675 bfd_byte
*contents
= NULL
;
4676 struct _arm_elf_section_data
*sec_data
;
4680 if (elf_section_type (section
) != SHT_PROGBITS
4681 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4682 || (section
->flags
& SEC_EXCLUDE
) != 0
4683 || (section
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4684 || (section
->output_section
== bfd_abs_section_ptr
))
4687 base_vma
= section
->output_section
->vma
+ section
->output_offset
;
4689 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4690 contents
= elf_section_data (section
)->this_hdr
.contents
;
4691 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4694 sec_data
= elf32_arm_section_data (section
);
4696 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4698 unsigned int span_start
= sec_data
->map
[span
].vma
;
4699 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
4700 ? section
->size
: sec_data
->map
[span
+ 1].vma
;
4702 char span_type
= sec_data
->map
[span
].type
;
4703 bfd_boolean last_was_32bit
= FALSE
, last_was_branch
= FALSE
;
4705 if (span_type
!= 't')
4708 /* Span is entirely within a single 4KB region: skip scanning. */
4709 if (((base_vma
+ span_start
) & ~0xfff)
4710 == ((base_vma
+ span_end
) & ~0xfff))
4713 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
4715 * The opcode is BLX.W, BL.W, B.W, Bcc.W
4716 * The branch target is in the same 4KB region as the
4717 first half of the branch.
4718 * The instruction before the branch is a 32-bit
4719 length non-branch instruction. */
4720 for (i
= span_start
; i
< span_end
;)
4722 unsigned int insn
= bfd_getl16 (&contents
[i
]);
4723 bfd_boolean insn_32bit
= FALSE
, is_blx
= FALSE
, is_b
= FALSE
;
4724 bfd_boolean is_bl
= FALSE
, is_bcc
= FALSE
, is_32bit_branch
;
4726 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
4731 /* Load the rest of the insn (in manual-friendly order). */
4732 insn
= (insn
<< 16) | bfd_getl16 (&contents
[i
+ 2]);
4734 /* Encoding T4: B<c>.W. */
4735 is_b
= (insn
& 0xf800d000) == 0xf0009000;
4736 /* Encoding T1: BL<c>.W. */
4737 is_bl
= (insn
& 0xf800d000) == 0xf000d000;
4738 /* Encoding T2: BLX<c>.W. */
4739 is_blx
= (insn
& 0xf800d000) == 0xf000c000;
4740 /* Encoding T3: B<c>.W (not permitted in IT block). */
4741 is_bcc
= (insn
& 0xf800d000) == 0xf0008000
4742 && (insn
& 0x07f00000) != 0x03800000;
4745 is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
4747 if (((base_vma
+ i
) & 0xfff) == 0xffe
4751 && ! last_was_branch
)
4753 bfd_signed_vma offset
= 0;
4754 bfd_boolean force_target_arm
= FALSE
;
4755 bfd_boolean force_target_thumb
= FALSE
;
4757 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
4758 struct a8_erratum_reloc key
, *found
;
4759 bfd_boolean use_plt
= FALSE
;
4761 key
.from
= base_vma
+ i
;
4762 found
= (struct a8_erratum_reloc
*)
4763 bsearch (&key
, a8_relocs
, num_a8_relocs
,
4764 sizeof (struct a8_erratum_reloc
),
4769 char *error_message
= NULL
;
4770 struct elf_link_hash_entry
*entry
;
4772 /* We don't care about the error returned from this
4773 function, only if there is glue or not. */
4774 entry
= find_thumb_glue (info
, found
->sym_name
,
4778 found
->non_a8_stub
= TRUE
;
4780 /* Keep a simpler condition, for the sake of clarity. */
4781 if (htab
->root
.splt
!= NULL
&& found
->hash
!= NULL
4782 && found
->hash
->root
.plt
.offset
!= (bfd_vma
) -1)
4785 if (found
->r_type
== R_ARM_THM_CALL
)
4787 if (found
->branch_type
== ST_BRANCH_TO_ARM
4789 force_target_arm
= TRUE
;
4791 force_target_thumb
= TRUE
;
4795 /* Check if we have an offending branch instruction. */
4797 if (found
&& found
->non_a8_stub
)
4798 /* We've already made a stub for this instruction, e.g.
4799 it's a long branch or a Thumb->ARM stub. Assume that
4800 stub will suffice to work around the A8 erratum (see
4801 setting of always_after_branch above). */
4805 offset
= (insn
& 0x7ff) << 1;
4806 offset
|= (insn
& 0x3f0000) >> 4;
4807 offset
|= (insn
& 0x2000) ? 0x40000 : 0;
4808 offset
|= (insn
& 0x800) ? 0x80000 : 0;
4809 offset
|= (insn
& 0x4000000) ? 0x100000 : 0;
4810 if (offset
& 0x100000)
4811 offset
|= ~ ((bfd_signed_vma
) 0xfffff);
4812 stub_type
= arm_stub_a8_veneer_b_cond
;
4814 else if (is_b
|| is_bl
|| is_blx
)
4816 int s
= (insn
& 0x4000000) != 0;
4817 int j1
= (insn
& 0x2000) != 0;
4818 int j2
= (insn
& 0x800) != 0;
4822 offset
= (insn
& 0x7ff) << 1;
4823 offset
|= (insn
& 0x3ff0000) >> 4;
4827 if (offset
& 0x1000000)
4828 offset
|= ~ ((bfd_signed_vma
) 0xffffff);
4831 offset
&= ~ ((bfd_signed_vma
) 3);
4833 stub_type
= is_blx
? arm_stub_a8_veneer_blx
:
4834 is_bl
? arm_stub_a8_veneer_bl
: arm_stub_a8_veneer_b
;
4837 if (stub_type
!= arm_stub_none
)
4839 bfd_vma pc_for_insn
= base_vma
+ i
+ 4;
4841 /* The original instruction is a BL, but the target is
4842 an ARM instruction. If we were not making a stub,
4843 the BL would have been converted to a BLX. Use the
4844 BLX stub instead in that case. */
4845 if (htab
->use_blx
&& force_target_arm
4846 && stub_type
== arm_stub_a8_veneer_bl
)
4848 stub_type
= arm_stub_a8_veneer_blx
;
4852 /* Conversely, if the original instruction was
4853 BLX but the target is Thumb mode, use the BL
4855 else if (force_target_thumb
4856 && stub_type
== arm_stub_a8_veneer_blx
)
4858 stub_type
= arm_stub_a8_veneer_bl
;
4864 pc_for_insn
&= ~ ((bfd_vma
) 3);
4866 /* If we found a relocation, use the proper destination,
4867 not the offset in the (unrelocated) instruction.
4868 Note this is always done if we switched the stub type
4872 (bfd_signed_vma
) (found
->destination
- pc_for_insn
);
4874 /* If the stub will use a Thumb-mode branch to a
4875 PLT target, redirect it to the preceding Thumb
4877 if (stub_type
!= arm_stub_a8_veneer_blx
&& use_plt
)
4878 offset
-= PLT_THUMB_STUB_SIZE
;
4880 target
= pc_for_insn
+ offset
;
4882 /* The BLX stub is ARM-mode code. Adjust the offset to
4883 take the different PC value (+8 instead of +4) into
4885 if (stub_type
== arm_stub_a8_veneer_blx
)
4888 if (((base_vma
+ i
) & ~0xfff) == (target
& ~0xfff))
4890 char *stub_name
= NULL
;
4892 if (num_a8_fixes
== a8_fix_table_size
)
4894 a8_fix_table_size
*= 2;
4895 a8_fixes
= (struct a8_erratum_fix
*)
4896 bfd_realloc (a8_fixes
,
4897 sizeof (struct a8_erratum_fix
)
4898 * a8_fix_table_size
);
4901 if (num_a8_fixes
< prev_num_a8_fixes
)
4903 /* If we're doing a subsequent scan,
4904 check if we've found the same fix as
4905 before, and try and reuse the stub
4907 stub_name
= a8_fixes
[num_a8_fixes
].stub_name
;
4908 if ((a8_fixes
[num_a8_fixes
].section
!= section
)
4909 || (a8_fixes
[num_a8_fixes
].offset
!= i
))
4913 *stub_changed_p
= TRUE
;
4919 stub_name
= (char *) bfd_malloc (8 + 1 + 8 + 1);
4920 if (stub_name
!= NULL
)
4921 sprintf (stub_name
, "%x:%x", section
->id
, i
);
4924 a8_fixes
[num_a8_fixes
].input_bfd
= input_bfd
;
4925 a8_fixes
[num_a8_fixes
].section
= section
;
4926 a8_fixes
[num_a8_fixes
].offset
= i
;
4927 a8_fixes
[num_a8_fixes
].addend
= offset
;
4928 a8_fixes
[num_a8_fixes
].orig_insn
= insn
;
4929 a8_fixes
[num_a8_fixes
].stub_name
= stub_name
;
4930 a8_fixes
[num_a8_fixes
].stub_type
= stub_type
;
4931 a8_fixes
[num_a8_fixes
].branch_type
=
4932 is_blx
? ST_BRANCH_TO_ARM
: ST_BRANCH_TO_THUMB
;
4939 i
+= insn_32bit
? 4 : 2;
4940 last_was_32bit
= insn_32bit
;
4941 last_was_branch
= is_32bit_branch
;
4945 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4949 *a8_fixes_p
= a8_fixes
;
4950 *num_a8_fixes_p
= num_a8_fixes
;
4951 *a8_fix_table_size_p
= a8_fix_table_size
;
4956 /* Determine and set the size of the stub section for a final link.
4958 The basic idea here is to examine all the relocations looking for
4959 PC-relative calls to a target that is unreachable with a "bl"
4963 elf32_arm_size_stubs (bfd
*output_bfd
,
4965 struct bfd_link_info
*info
,
4966 bfd_signed_vma group_size
,
4967 asection
* (*add_stub_section
) (const char *, asection
*,
4969 void (*layout_sections_again
) (void))
4971 bfd_size_type stub_group_size
;
4972 bfd_boolean stubs_always_after_branch
;
4973 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4974 struct a8_erratum_fix
*a8_fixes
= NULL
;
4975 unsigned int num_a8_fixes
= 0, a8_fix_table_size
= 10;
4976 struct a8_erratum_reloc
*a8_relocs
= NULL
;
4977 unsigned int num_a8_relocs
= 0, a8_reloc_table_size
= 10, i
;
4982 if (htab
->fix_cortex_a8
)
4984 a8_fixes
= (struct a8_erratum_fix
*)
4985 bfd_zmalloc (sizeof (struct a8_erratum_fix
) * a8_fix_table_size
);
4986 a8_relocs
= (struct a8_erratum_reloc
*)
4987 bfd_zmalloc (sizeof (struct a8_erratum_reloc
) * a8_reloc_table_size
);
4990 /* Propagate mach to stub bfd, because it may not have been
4991 finalized when we created stub_bfd. */
4992 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4993 bfd_get_mach (output_bfd
));
4995 /* Stash our params away. */
4996 htab
->stub_bfd
= stub_bfd
;
4997 htab
->add_stub_section
= add_stub_section
;
4998 htab
->layout_sections_again
= layout_sections_again
;
4999 stubs_always_after_branch
= group_size
< 0;
5001 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
5002 as the first half of a 32-bit branch straddling two 4K pages. This is a
5003 crude way of enforcing that. */
5004 if (htab
->fix_cortex_a8
)
5005 stubs_always_after_branch
= 1;
5008 stub_group_size
= -group_size
;
5010 stub_group_size
= group_size
;
5012 if (stub_group_size
== 1)
5014 /* Default values. */
5015 /* Thumb branch range is +-4MB has to be used as the default
5016 maximum size (a given section can contain both ARM and Thumb
5017 code, so the worst case has to be taken into account).
5019 This value is 24K less than that, which allows for 2025
5020 12-byte stubs. If we exceed that, then we will fail to link.
5021 The user will have to relink with an explicit group size
5023 stub_group_size
= 4170000;
5026 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
5028 /* If we're applying the cortex A8 fix, we need to determine the
5029 program header size now, because we cannot change it later --
5030 that could alter section placements. Notice the A8 erratum fix
5031 ends up requiring the section addresses to remain unchanged
5032 modulo the page size. That's something we cannot represent
5033 inside BFD, and we don't want to force the section alignment to
5034 be the page size. */
5035 if (htab
->fix_cortex_a8
)
5036 (*htab
->layout_sections_again
) ();
5041 unsigned int bfd_indx
;
5043 bfd_boolean stub_changed
= FALSE
;
5044 unsigned prev_num_a8_fixes
= num_a8_fixes
;
5047 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
5049 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
5051 Elf_Internal_Shdr
*symtab_hdr
;
5053 Elf_Internal_Sym
*local_syms
= NULL
;
5055 if (!is_arm_elf (input_bfd
))
5060 /* We'll need the symbol table in a second. */
5061 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5062 if (symtab_hdr
->sh_info
== 0)
5065 /* Walk over each section attached to the input bfd. */
5066 for (section
= input_bfd
->sections
;
5068 section
= section
->next
)
5070 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
5072 /* If there aren't any relocs, then there's nothing more
5074 if ((section
->flags
& SEC_RELOC
) == 0
5075 || section
->reloc_count
== 0
5076 || (section
->flags
& SEC_CODE
) == 0)
5079 /* If this section is a link-once section that will be
5080 discarded, then don't create any stubs. */
5081 if (section
->output_section
== NULL
5082 || section
->output_section
->owner
!= output_bfd
)
5085 /* Get the relocs. */
5087 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
5088 NULL
, info
->keep_memory
);
5089 if (internal_relocs
== NULL
)
5090 goto error_ret_free_local
;
5092 /* Now examine each relocation. */
5093 irela
= internal_relocs
;
5094 irelaend
= irela
+ section
->reloc_count
;
5095 for (; irela
< irelaend
; irela
++)
5097 unsigned int r_type
, r_indx
;
5098 enum elf32_arm_stub_type stub_type
;
5099 struct elf32_arm_stub_hash_entry
*stub_entry
;
5102 bfd_vma destination
;
5103 struct elf32_arm_link_hash_entry
*hash
;
5104 const char *sym_name
;
5106 const asection
*id_sec
;
5107 unsigned char st_type
;
5108 enum arm_st_branch_type branch_type
;
5109 bfd_boolean created_stub
= FALSE
;
5111 r_type
= ELF32_R_TYPE (irela
->r_info
);
5112 r_indx
= ELF32_R_SYM (irela
->r_info
);
5114 if (r_type
>= (unsigned int) R_ARM_max
)
5116 bfd_set_error (bfd_error_bad_value
);
5117 error_ret_free_internal
:
5118 if (elf_section_data (section
)->relocs
== NULL
)
5119 free (internal_relocs
);
5120 goto error_ret_free_local
;
5124 if (r_indx
>= symtab_hdr
->sh_info
)
5125 hash
= elf32_arm_hash_entry
5126 (elf_sym_hashes (input_bfd
)
5127 [r_indx
- symtab_hdr
->sh_info
]);
5129 /* Only look for stubs on branch instructions, or
5130 non-relaxed TLSCALL */
5131 if ((r_type
!= (unsigned int) R_ARM_CALL
)
5132 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
5133 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
5134 && (r_type
!= (unsigned int) R_ARM_THM_JUMP19
)
5135 && (r_type
!= (unsigned int) R_ARM_THM_XPC22
)
5136 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
5137 && (r_type
!= (unsigned int) R_ARM_PLT32
)
5138 && !((r_type
== (unsigned int) R_ARM_TLS_CALL
5139 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
5140 && r_type
== elf32_arm_tls_transition
5141 (info
, r_type
, &hash
->root
)
5142 && ((hash
? hash
->tls_type
5143 : (elf32_arm_local_got_tls_type
5144 (input_bfd
)[r_indx
]))
5145 & GOT_TLS_GDESC
) != 0))
5148 /* Now determine the call target, its name, value,
5155 if (r_type
== (unsigned int) R_ARM_TLS_CALL
5156 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
5158 /* A non-relaxed TLS call. The target is the
5159 plt-resident trampoline and nothing to do
5161 BFD_ASSERT (htab
->tls_trampoline
> 0);
5162 sym_sec
= htab
->root
.splt
;
5163 sym_value
= htab
->tls_trampoline
;
5166 branch_type
= ST_BRANCH_TO_ARM
;
5170 /* It's a local symbol. */
5171 Elf_Internal_Sym
*sym
;
5173 if (local_syms
== NULL
)
5176 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5177 if (local_syms
== NULL
)
5179 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5180 symtab_hdr
->sh_info
, 0,
5182 if (local_syms
== NULL
)
5183 goto error_ret_free_internal
;
5186 sym
= local_syms
+ r_indx
;
5187 if (sym
->st_shndx
== SHN_UNDEF
)
5188 sym_sec
= bfd_und_section_ptr
;
5189 else if (sym
->st_shndx
== SHN_ABS
)
5190 sym_sec
= bfd_abs_section_ptr
;
5191 else if (sym
->st_shndx
== SHN_COMMON
)
5192 sym_sec
= bfd_com_section_ptr
;
5195 bfd_section_from_elf_index (input_bfd
, sym
->st_shndx
);
5198 /* This is an undefined symbol. It can never
5202 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5203 sym_value
= sym
->st_value
;
5204 destination
= (sym_value
+ irela
->r_addend
5205 + sym_sec
->output_offset
5206 + sym_sec
->output_section
->vma
);
5207 st_type
= ELF_ST_TYPE (sym
->st_info
);
5208 branch_type
= ARM_SYM_BRANCH_TYPE (sym
);
5210 = bfd_elf_string_from_elf_section (input_bfd
,
5211 symtab_hdr
->sh_link
,
5216 /* It's an external symbol. */
5217 while (hash
->root
.root
.type
== bfd_link_hash_indirect
5218 || hash
->root
.root
.type
== bfd_link_hash_warning
)
5219 hash
= ((struct elf32_arm_link_hash_entry
*)
5220 hash
->root
.root
.u
.i
.link
);
5222 if (hash
->root
.root
.type
== bfd_link_hash_defined
5223 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
5225 sym_sec
= hash
->root
.root
.u
.def
.section
;
5226 sym_value
= hash
->root
.root
.u
.def
.value
;
5228 struct elf32_arm_link_hash_table
*globals
=
5229 elf32_arm_hash_table (info
);
5231 /* For a destination in a shared library,
5232 use the PLT stub as target address to
5233 decide whether a branch stub is
5236 && globals
->root
.splt
!= NULL
5238 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5240 sym_sec
= globals
->root
.splt
;
5241 sym_value
= hash
->root
.plt
.offset
;
5242 if (sym_sec
->output_section
!= NULL
)
5243 destination
= (sym_value
5244 + sym_sec
->output_offset
5245 + sym_sec
->output_section
->vma
);
5247 else if (sym_sec
->output_section
!= NULL
)
5248 destination
= (sym_value
+ irela
->r_addend
5249 + sym_sec
->output_offset
5250 + sym_sec
->output_section
->vma
);
5252 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
5253 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
5255 /* For a shared library, use the PLT stub as
5256 target address to decide whether a long
5257 branch stub is needed.
5258 For absolute code, they cannot be handled. */
5259 struct elf32_arm_link_hash_table
*globals
=
5260 elf32_arm_hash_table (info
);
5263 && globals
->root
.splt
!= NULL
5265 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5267 sym_sec
= globals
->root
.splt
;
5268 sym_value
= hash
->root
.plt
.offset
;
5269 if (sym_sec
->output_section
!= NULL
)
5270 destination
= (sym_value
5271 + sym_sec
->output_offset
5272 + sym_sec
->output_section
->vma
);
5279 bfd_set_error (bfd_error_bad_value
);
5280 goto error_ret_free_internal
;
5282 st_type
= hash
->root
.type
;
5283 branch_type
= hash
->root
.target_internal
;
5284 sym_name
= hash
->root
.root
.root
.string
;
5289 /* Determine what (if any) linker stub is needed. */
5290 stub_type
= arm_type_of_stub (info
, section
, irela
,
5291 st_type
, &branch_type
,
5292 hash
, destination
, sym_sec
,
5293 input_bfd
, sym_name
);
5294 if (stub_type
== arm_stub_none
)
5297 /* Support for grouping stub sections. */
5298 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5300 /* Get the name of this stub. */
5301 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
,
5304 goto error_ret_free_internal
;
5306 /* We've either created a stub for this reloc already,
5307 or we are about to. */
5308 created_stub
= TRUE
;
5310 stub_entry
= arm_stub_hash_lookup
5311 (&htab
->stub_hash_table
, stub_name
,
5313 if (stub_entry
!= NULL
)
5315 /* The proper stub has already been created. */
5317 stub_entry
->target_value
= sym_value
;
5321 stub_entry
= elf32_arm_add_stub (stub_name
, section
,
5323 if (stub_entry
== NULL
)
5326 goto error_ret_free_internal
;
5329 stub_entry
->target_value
= sym_value
;
5330 stub_entry
->target_section
= sym_sec
;
5331 stub_entry
->stub_type
= stub_type
;
5332 stub_entry
->h
= hash
;
5333 stub_entry
->branch_type
= branch_type
;
5335 if (sym_name
== NULL
)
5336 sym_name
= "unnamed";
5337 stub_entry
->output_name
= (char *)
5338 bfd_alloc (htab
->stub_bfd
,
5339 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
5340 + strlen (sym_name
));
5341 if (stub_entry
->output_name
== NULL
)
5344 goto error_ret_free_internal
;
5347 /* For historical reasons, use the existing names for
5348 ARM-to-Thumb and Thumb-to-ARM stubs. */
5349 if ((r_type
== (unsigned int) R_ARM_THM_CALL
5350 || r_type
== (unsigned int) R_ARM_THM_JUMP24
)
5351 && branch_type
== ST_BRANCH_TO_ARM
)
5352 sprintf (stub_entry
->output_name
,
5353 THUMB2ARM_GLUE_ENTRY_NAME
, sym_name
);
5354 else if ((r_type
== (unsigned int) R_ARM_CALL
5355 || r_type
== (unsigned int) R_ARM_JUMP24
)
5356 && branch_type
== ST_BRANCH_TO_THUMB
)
5357 sprintf (stub_entry
->output_name
,
5358 ARM2THUMB_GLUE_ENTRY_NAME
, sym_name
);
5360 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
5363 stub_changed
= TRUE
;
5367 /* Look for relocations which might trigger Cortex-A8
5369 if (htab
->fix_cortex_a8
5370 && (r_type
== (unsigned int) R_ARM_THM_JUMP24
5371 || r_type
== (unsigned int) R_ARM_THM_JUMP19
5372 || r_type
== (unsigned int) R_ARM_THM_CALL
5373 || r_type
== (unsigned int) R_ARM_THM_XPC22
))
5375 bfd_vma from
= section
->output_section
->vma
5376 + section
->output_offset
5379 if ((from
& 0xfff) == 0xffe)
5381 /* Found a candidate. Note we haven't checked the
5382 destination is within 4K here: if we do so (and
5383 don't create an entry in a8_relocs) we can't tell
5384 that a branch should have been relocated when
5386 if (num_a8_relocs
== a8_reloc_table_size
)
5388 a8_reloc_table_size
*= 2;
5389 a8_relocs
= (struct a8_erratum_reloc
*)
5390 bfd_realloc (a8_relocs
,
5391 sizeof (struct a8_erratum_reloc
)
5392 * a8_reloc_table_size
);
5395 a8_relocs
[num_a8_relocs
].from
= from
;
5396 a8_relocs
[num_a8_relocs
].destination
= destination
;
5397 a8_relocs
[num_a8_relocs
].r_type
= r_type
;
5398 a8_relocs
[num_a8_relocs
].branch_type
= branch_type
;
5399 a8_relocs
[num_a8_relocs
].sym_name
= sym_name
;
5400 a8_relocs
[num_a8_relocs
].non_a8_stub
= created_stub
;
5401 a8_relocs
[num_a8_relocs
].hash
= hash
;
5408 /* We're done with the internal relocs, free them. */
5409 if (elf_section_data (section
)->relocs
== NULL
)
5410 free (internal_relocs
);
5413 if (htab
->fix_cortex_a8
)
5415 /* Sort relocs which might apply to Cortex-A8 erratum. */
5416 qsort (a8_relocs
, num_a8_relocs
,
5417 sizeof (struct a8_erratum_reloc
),
5420 /* Scan for branches which might trigger Cortex-A8 erratum. */
5421 if (cortex_a8_erratum_scan (input_bfd
, info
, &a8_fixes
,
5422 &num_a8_fixes
, &a8_fix_table_size
,
5423 a8_relocs
, num_a8_relocs
,
5424 prev_num_a8_fixes
, &stub_changed
)
5426 goto error_ret_free_local
;
5430 if (prev_num_a8_fixes
!= num_a8_fixes
)
5431 stub_changed
= TRUE
;
5436 /* OK, we've added some stubs. Find out the new size of the
5438 for (stub_sec
= htab
->stub_bfd
->sections
;
5440 stub_sec
= stub_sec
->next
)
5442 /* Ignore non-stub sections. */
5443 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5449 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
5451 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
5452 if (htab
->fix_cortex_a8
)
5453 for (i
= 0; i
< num_a8_fixes
; i
++)
5455 stub_sec
= elf32_arm_create_or_find_stub_sec (NULL
,
5456 a8_fixes
[i
].section
, htab
);
5458 if (stub_sec
== NULL
)
5459 goto error_ret_free_local
;
5462 += find_stub_size_and_template (a8_fixes
[i
].stub_type
, NULL
,
5467 /* Ask the linker to do its stuff. */
5468 (*htab
->layout_sections_again
) ();
5471 /* Add stubs for Cortex-A8 erratum fixes now. */
5472 if (htab
->fix_cortex_a8
)
5474 for (i
= 0; i
< num_a8_fixes
; i
++)
5476 struct elf32_arm_stub_hash_entry
*stub_entry
;
5477 char *stub_name
= a8_fixes
[i
].stub_name
;
5478 asection
*section
= a8_fixes
[i
].section
;
5479 unsigned int section_id
= a8_fixes
[i
].section
->id
;
5480 asection
*link_sec
= htab
->stub_group
[section_id
].link_sec
;
5481 asection
*stub_sec
= htab
->stub_group
[section_id
].stub_sec
;
5482 const insn_sequence
*template_sequence
;
5483 int template_size
, size
= 0;
5485 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
5487 if (stub_entry
== NULL
)
5489 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
5495 stub_entry
->stub_sec
= stub_sec
;
5496 stub_entry
->stub_offset
= 0;
5497 stub_entry
->id_sec
= link_sec
;
5498 stub_entry
->stub_type
= a8_fixes
[i
].stub_type
;
5499 stub_entry
->target_section
= a8_fixes
[i
].section
;
5500 stub_entry
->target_value
= a8_fixes
[i
].offset
;
5501 stub_entry
->target_addend
= a8_fixes
[i
].addend
;
5502 stub_entry
->orig_insn
= a8_fixes
[i
].orig_insn
;
5503 stub_entry
->branch_type
= a8_fixes
[i
].branch_type
;
5505 size
= find_stub_size_and_template (a8_fixes
[i
].stub_type
,
5509 stub_entry
->stub_size
= size
;
5510 stub_entry
->stub_template
= template_sequence
;
5511 stub_entry
->stub_template_size
= template_size
;
5514 /* Stash the Cortex-A8 erratum fix array for use later in
5515 elf32_arm_write_section(). */
5516 htab
->a8_erratum_fixes
= a8_fixes
;
5517 htab
->num_a8_erratum_fixes
= num_a8_fixes
;
5521 htab
->a8_erratum_fixes
= NULL
;
5522 htab
->num_a8_erratum_fixes
= 0;
5526 error_ret_free_local
:
5530 /* Build all the stubs associated with the current output file. The
5531 stubs are kept in a hash table attached to the main linker hash
5532 table. We also set up the .plt entries for statically linked PIC
5533 functions here. This function is called via arm_elf_finish in the
5537 elf32_arm_build_stubs (struct bfd_link_info
*info
)
5540 struct bfd_hash_table
*table
;
5541 struct elf32_arm_link_hash_table
*htab
;
5543 htab
= elf32_arm_hash_table (info
);
5547 for (stub_sec
= htab
->stub_bfd
->sections
;
5549 stub_sec
= stub_sec
->next
)
5553 /* Ignore non-stub sections. */
5554 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5557 /* Allocate memory to hold the linker stubs. */
5558 size
= stub_sec
->size
;
5559 stub_sec
->contents
= (unsigned char *) bfd_zalloc (htab
->stub_bfd
, size
);
5560 if (stub_sec
->contents
== NULL
&& size
!= 0)
5565 /* Build the stubs as directed by the stub hash table. */
5566 table
= &htab
->stub_hash_table
;
5567 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5568 if (htab
->fix_cortex_a8
)
5570 /* Place the cortex a8 stubs last. */
5571 htab
->fix_cortex_a8
= -1;
5572 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5578 /* Locate the Thumb encoded calling stub for NAME. */
5580 static struct elf_link_hash_entry
*
5581 find_thumb_glue (struct bfd_link_info
*link_info
,
5583 char **error_message
)
5586 struct elf_link_hash_entry
*hash
;
5587 struct elf32_arm_link_hash_table
*hash_table
;
5589 /* We need a pointer to the armelf specific hash table. */
5590 hash_table
= elf32_arm_hash_table (link_info
);
5591 if (hash_table
== NULL
)
5594 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5595 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
5597 BFD_ASSERT (tmp_name
);
5599 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
5601 hash
= elf_link_hash_lookup
5602 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5605 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
5606 tmp_name
, name
) == -1)
5607 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5614 /* Locate the ARM encoded calling stub for NAME. */
5616 static struct elf_link_hash_entry
*
5617 find_arm_glue (struct bfd_link_info
*link_info
,
5619 char **error_message
)
5622 struct elf_link_hash_entry
*myh
;
5623 struct elf32_arm_link_hash_table
*hash_table
;
5625 /* We need a pointer to the elfarm specific hash table. */
5626 hash_table
= elf32_arm_hash_table (link_info
);
5627 if (hash_table
== NULL
)
5630 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5631 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5633 BFD_ASSERT (tmp_name
);
5635 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5637 myh
= elf_link_hash_lookup
5638 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5641 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
5642 tmp_name
, name
) == -1)
5643 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5650 /* ARM->Thumb glue (static images):
5654 ldr r12, __func_addr
5657 .word func @ behave as if you saw a ARM_32 reloc.
5664 .word func @ behave as if you saw a ARM_32 reloc.
5666 (relocatable images)
5669 ldr r12, __func_offset
5675 #define ARM2THUMB_STATIC_GLUE_SIZE 12
5676 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
5677 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
5678 static const insn32 a2t3_func_addr_insn
= 0x00000001;
5680 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
5681 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
5682 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
5684 #define ARM2THUMB_PIC_GLUE_SIZE 16
5685 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
5686 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
5687 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
5689 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
5693 __func_from_thumb: __func_from_thumb:
5695 nop ldr r6, __func_addr
5705 #define THUMB2ARM_GLUE_SIZE 8
5706 static const insn16 t2a1_bx_pc_insn
= 0x4778;
5707 static const insn16 t2a2_noop_insn
= 0x46c0;
5708 static const insn32 t2a3_b_insn
= 0xea000000;
5710 #define VFP11_ERRATUM_VENEER_SIZE 8
5712 #define ARM_BX_VENEER_SIZE 12
5713 static const insn32 armbx1_tst_insn
= 0xe3100001;
5714 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
5715 static const insn32 armbx3_bx_insn
= 0xe12fff10;
5717 #ifndef ELFARM_NABI_C_INCLUDED
5719 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
5722 bfd_byte
* contents
;
5726 /* Do not include empty glue sections in the output. */
5729 s
= bfd_get_linker_section (abfd
, name
);
5731 s
->flags
|= SEC_EXCLUDE
;
5736 BFD_ASSERT (abfd
!= NULL
);
5738 s
= bfd_get_linker_section (abfd
, name
);
5739 BFD_ASSERT (s
!= NULL
);
5741 contents
= (bfd_byte
*) bfd_alloc (abfd
, size
);
5743 BFD_ASSERT (s
->size
== size
);
5744 s
->contents
= contents
;
5748 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
5750 struct elf32_arm_link_hash_table
* globals
;
5752 globals
= elf32_arm_hash_table (info
);
5753 BFD_ASSERT (globals
!= NULL
);
5755 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5756 globals
->arm_glue_size
,
5757 ARM2THUMB_GLUE_SECTION_NAME
);
5759 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5760 globals
->thumb_glue_size
,
5761 THUMB2ARM_GLUE_SECTION_NAME
);
5763 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5764 globals
->vfp11_erratum_glue_size
,
5765 VFP11_ERRATUM_VENEER_SECTION_NAME
);
5767 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5768 globals
->bx_glue_size
,
5769 ARM_BX_GLUE_SECTION_NAME
);
5774 /* Allocate space and symbols for calling a Thumb function from Arm mode.
5775 returns the symbol identifying the stub. */
5777 static struct elf_link_hash_entry
*
5778 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
5779 struct elf_link_hash_entry
* h
)
5781 const char * name
= h
->root
.root
.string
;
5784 struct elf_link_hash_entry
* myh
;
5785 struct bfd_link_hash_entry
* bh
;
5786 struct elf32_arm_link_hash_table
* globals
;
5790 globals
= elf32_arm_hash_table (link_info
);
5791 BFD_ASSERT (globals
!= NULL
);
5792 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5794 s
= bfd_get_linker_section
5795 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
5797 BFD_ASSERT (s
!= NULL
);
5799 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5800 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5802 BFD_ASSERT (tmp_name
);
5804 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5806 myh
= elf_link_hash_lookup
5807 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5811 /* We've already seen this guy. */
5816 /* The only trick here is using hash_table->arm_glue_size as the value.
5817 Even though the section isn't allocated yet, this is where we will be
5818 putting it. The +1 on the value marks that the stub has not been
5819 output yet - not that it is a Thumb function. */
5821 val
= globals
->arm_glue_size
+ 1;
5822 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5823 tmp_name
, BSF_GLOBAL
, s
, val
,
5824 NULL
, TRUE
, FALSE
, &bh
);
5826 myh
= (struct elf_link_hash_entry
*) bh
;
5827 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5828 myh
->forced_local
= 1;
5832 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
5833 || globals
->pic_veneer
)
5834 size
= ARM2THUMB_PIC_GLUE_SIZE
;
5835 else if (globals
->use_blx
)
5836 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
5838 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
5841 globals
->arm_glue_size
+= size
;
5846 /* Allocate space for ARMv4 BX veneers. */
5849 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
5852 struct elf32_arm_link_hash_table
*globals
;
5854 struct elf_link_hash_entry
*myh
;
5855 struct bfd_link_hash_entry
*bh
;
5858 /* BX PC does not need a veneer. */
5862 globals
= elf32_arm_hash_table (link_info
);
5863 BFD_ASSERT (globals
!= NULL
);
5864 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5866 /* Check if this veneer has already been allocated. */
5867 if (globals
->bx_glue_offset
[reg
])
5870 s
= bfd_get_linker_section
5871 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
5873 BFD_ASSERT (s
!= NULL
);
5875 /* Add symbol for veneer. */
5877 bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
5879 BFD_ASSERT (tmp_name
);
5881 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
5883 myh
= elf_link_hash_lookup
5884 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5886 BFD_ASSERT (myh
== NULL
);
5889 val
= globals
->bx_glue_size
;
5890 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5891 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5892 NULL
, TRUE
, FALSE
, &bh
);
5894 myh
= (struct elf_link_hash_entry
*) bh
;
5895 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5896 myh
->forced_local
= 1;
5898 s
->size
+= ARM_BX_VENEER_SIZE
;
5899 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
5900 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
5904 /* Add an entry to the code/data map for section SEC. */
5907 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
5909 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5910 unsigned int newidx
;
5912 if (sec_data
->map
== NULL
)
5914 sec_data
->map
= (elf32_arm_section_map
*)
5915 bfd_malloc (sizeof (elf32_arm_section_map
));
5916 sec_data
->mapcount
= 0;
5917 sec_data
->mapsize
= 1;
5920 newidx
= sec_data
->mapcount
++;
5922 if (sec_data
->mapcount
> sec_data
->mapsize
)
5924 sec_data
->mapsize
*= 2;
5925 sec_data
->map
= (elf32_arm_section_map
*)
5926 bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
5927 * sizeof (elf32_arm_section_map
));
5932 sec_data
->map
[newidx
].vma
= vma
;
5933 sec_data
->map
[newidx
].type
= type
;
5938 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
5939 veneers are handled for now. */
5942 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
5943 elf32_vfp11_erratum_list
*branch
,
5945 asection
*branch_sec
,
5946 unsigned int offset
)
5949 struct elf32_arm_link_hash_table
*hash_table
;
5951 struct elf_link_hash_entry
*myh
;
5952 struct bfd_link_hash_entry
*bh
;
5954 struct _arm_elf_section_data
*sec_data
;
5955 elf32_vfp11_erratum_list
*newerr
;
5957 hash_table
= elf32_arm_hash_table (link_info
);
5958 BFD_ASSERT (hash_table
!= NULL
);
5959 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
5961 s
= bfd_get_linker_section
5962 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
5964 sec_data
= elf32_arm_section_data (s
);
5966 BFD_ASSERT (s
!= NULL
);
5968 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
5969 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5971 BFD_ASSERT (tmp_name
);
5973 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5974 hash_table
->num_vfp11_fixes
);
5976 myh
= elf_link_hash_lookup
5977 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5979 BFD_ASSERT (myh
== NULL
);
5982 val
= hash_table
->vfp11_erratum_glue_size
;
5983 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
5984 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5985 NULL
, TRUE
, FALSE
, &bh
);
5987 myh
= (struct elf_link_hash_entry
*) bh
;
5988 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5989 myh
->forced_local
= 1;
5991 /* Link veneer back to calling location. */
5992 sec_data
->erratumcount
+= 1;
5993 newerr
= (elf32_vfp11_erratum_list
*)
5994 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5996 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
5998 newerr
->u
.v
.branch
= branch
;
5999 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
6000 branch
->u
.b
.veneer
= newerr
;
6002 newerr
->next
= sec_data
->erratumlist
;
6003 sec_data
->erratumlist
= newerr
;
6005 /* A symbol for the return from the veneer. */
6006 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
6007 hash_table
->num_vfp11_fixes
);
6009 myh
= elf_link_hash_lookup
6010 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
6017 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
6018 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
6020 myh
= (struct elf_link_hash_entry
*) bh
;
6021 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
6022 myh
->forced_local
= 1;
6026 /* Generate a mapping symbol for the veneer section, and explicitly add an
6027 entry for that symbol to the code/data map for the section. */
6028 if (hash_table
->vfp11_erratum_glue_size
== 0)
6031 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
6032 ever requires this erratum fix. */
6033 _bfd_generic_link_add_one_symbol (link_info
,
6034 hash_table
->bfd_of_glue_owner
, "$a",
6035 BSF_LOCAL
, s
, 0, NULL
,
6038 myh
= (struct elf_link_hash_entry
*) bh
;
6039 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
6040 myh
->forced_local
= 1;
6042 /* The elf32_arm_init_maps function only cares about symbols from input
6043 BFDs. We must make a note of this generated mapping symbol
6044 ourselves so that code byteswapping works properly in
6045 elf32_arm_write_section. */
6046 elf32_arm_section_map_add (s
, 'a', 0);
6049 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
6050 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
6051 hash_table
->num_vfp11_fixes
++;
6053 /* The offset of the veneer. */
6057 #define ARM_GLUE_SECTION_FLAGS \
6058 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
6059 | SEC_READONLY | SEC_LINKER_CREATED)
6061 /* Create a fake section for use by the ARM backend of the linker. */
6064 arm_make_glue_section (bfd
* abfd
, const char * name
)
6068 sec
= bfd_get_linker_section (abfd
, name
);
6073 sec
= bfd_make_section_anyway_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
6076 || !bfd_set_section_alignment (abfd
, sec
, 2))
6079 /* Set the gc mark to prevent the section from being removed by garbage
6080 collection, despite the fact that no relocs refer to this section. */
6086 /* Set size of .plt entries. This function is called from the
6087 linker scripts in ld/emultempl/{armelf}.em. */
6090 bfd_elf32_arm_use_long_plt (void)
6092 elf32_arm_use_long_plt_entry
= TRUE
;
6095 /* Add the glue sections to ABFD. This function is called from the
6096 linker scripts in ld/emultempl/{armelf}.em. */
6099 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
6100 struct bfd_link_info
*info
)
6102 /* If we are only performing a partial
6103 link do not bother adding the glue. */
6104 if (info
->relocatable
)
6107 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
6108 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
6109 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
6110 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
6113 /* Select a BFD to be used to hold the sections used by the glue code.
6114 This function is called from the linker scripts in ld/emultempl/
6118 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
6120 struct elf32_arm_link_hash_table
*globals
;
6122 /* If we are only performing a partial link
6123 do not bother getting a bfd to hold the glue. */
6124 if (info
->relocatable
)
6127 /* Make sure we don't attach the glue sections to a dynamic object. */
6128 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
6130 globals
= elf32_arm_hash_table (info
);
6131 BFD_ASSERT (globals
!= NULL
);
6133 if (globals
->bfd_of_glue_owner
!= NULL
)
6136 /* Save the bfd for later use. */
6137 globals
->bfd_of_glue_owner
= abfd
;
6143 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
6147 cpu_arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
6150 if (globals
->fix_arm1176
)
6152 if (cpu_arch
== TAG_CPU_ARCH_V6T2
|| cpu_arch
> TAG_CPU_ARCH_V6K
)
6153 globals
->use_blx
= 1;
6157 if (cpu_arch
> TAG_CPU_ARCH_V4T
)
6158 globals
->use_blx
= 1;
6163 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
6164 struct bfd_link_info
*link_info
)
6166 Elf_Internal_Shdr
*symtab_hdr
;
6167 Elf_Internal_Rela
*internal_relocs
= NULL
;
6168 Elf_Internal_Rela
*irel
, *irelend
;
6169 bfd_byte
*contents
= NULL
;
6172 struct elf32_arm_link_hash_table
*globals
;
6174 /* If we are only performing a partial link do not bother
6175 to construct any glue. */
6176 if (link_info
->relocatable
)
6179 /* Here we have a bfd that is to be included on the link. We have a
6180 hook to do reloc rummaging, before section sizes are nailed down. */
6181 globals
= elf32_arm_hash_table (link_info
);
6182 BFD_ASSERT (globals
!= NULL
);
6184 check_use_blx (globals
);
6186 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
6188 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
6193 /* PR 5398: If we have not decided to include any loadable sections in
6194 the output then we will not have a glue owner bfd. This is OK, it
6195 just means that there is nothing else for us to do here. */
6196 if (globals
->bfd_of_glue_owner
== NULL
)
6199 /* Rummage around all the relocs and map the glue vectors. */
6200 sec
= abfd
->sections
;
6205 for (; sec
!= NULL
; sec
= sec
->next
)
6207 if (sec
->reloc_count
== 0)
6210 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
6213 symtab_hdr
= & elf_symtab_hdr (abfd
);
6215 /* Load the relocs. */
6217 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
6219 if (internal_relocs
== NULL
)
6222 irelend
= internal_relocs
+ sec
->reloc_count
;
6223 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6226 unsigned long r_index
;
6228 struct elf_link_hash_entry
*h
;
6230 r_type
= ELF32_R_TYPE (irel
->r_info
);
6231 r_index
= ELF32_R_SYM (irel
->r_info
);
6233 /* These are the only relocation types we care about. */
6234 if ( r_type
!= R_ARM_PC24
6235 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
6238 /* Get the section contents if we haven't done so already. */
6239 if (contents
== NULL
)
6241 /* Get cached copy if it exists. */
6242 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6243 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6246 /* Go get them off disk. */
6247 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6252 if (r_type
== R_ARM_V4BX
)
6256 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
6257 record_arm_bx_glue (link_info
, reg
);
6261 /* If the relocation is not against a symbol it cannot concern us. */
6264 /* We don't care about local symbols. */
6265 if (r_index
< symtab_hdr
->sh_info
)
6268 /* This is an external symbol. */
6269 r_index
-= symtab_hdr
->sh_info
;
6270 h
= (struct elf_link_hash_entry
*)
6271 elf_sym_hashes (abfd
)[r_index
];
6273 /* If the relocation is against a static symbol it must be within
6274 the current section and so cannot be a cross ARM/Thumb relocation. */
6278 /* If the call will go through a PLT entry then we do not need
6280 if (globals
->root
.splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6286 /* This one is a call from arm code. We need to look up
6287 the target of the call. If it is a thumb target, we
6289 if (h
->target_internal
== ST_BRANCH_TO_THUMB
)
6290 record_arm_to_thumb_glue (link_info
, h
);
6298 if (contents
!= NULL
6299 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6303 if (internal_relocs
!= NULL
6304 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6305 free (internal_relocs
);
6306 internal_relocs
= NULL
;
6312 if (contents
!= NULL
6313 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6315 if (internal_relocs
!= NULL
6316 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6317 free (internal_relocs
);
6324 /* Initialise maps of ARM/Thumb/data for input BFDs. */
6327 bfd_elf32_arm_init_maps (bfd
*abfd
)
6329 Elf_Internal_Sym
*isymbuf
;
6330 Elf_Internal_Shdr
*hdr
;
6331 unsigned int i
, localsyms
;
6333 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
6334 if (! is_arm_elf (abfd
))
6337 if ((abfd
->flags
& DYNAMIC
) != 0)
6340 hdr
= & elf_symtab_hdr (abfd
);
6341 localsyms
= hdr
->sh_info
;
6343 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
6344 should contain the number of local symbols, which should come before any
6345 global symbols. Mapping symbols are always local. */
6346 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
6349 /* No internal symbols read? Skip this BFD. */
6350 if (isymbuf
== NULL
)
6353 for (i
= 0; i
< localsyms
; i
++)
6355 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
6356 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6360 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
6362 name
= bfd_elf_string_from_elf_section (abfd
,
6363 hdr
->sh_link
, isym
->st_name
);
6365 if (bfd_is_arm_special_symbol_name (name
,
6366 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
6367 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
6373 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
6374 say what they wanted. */
6377 bfd_elf32_arm_set_cortex_a8_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6379 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6380 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6382 if (globals
== NULL
)
6385 if (globals
->fix_cortex_a8
== -1)
6387 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
6388 if (out_attr
[Tag_CPU_arch
].i
== TAG_CPU_ARCH_V7
6389 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
6390 || out_attr
[Tag_CPU_arch_profile
].i
== 0))
6391 globals
->fix_cortex_a8
= 1;
6393 globals
->fix_cortex_a8
= 0;
6399 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6401 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6402 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6404 if (globals
== NULL
)
6406 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
6407 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
6409 switch (globals
->vfp11_fix
)
6411 case BFD_ARM_VFP11_FIX_DEFAULT
:
6412 case BFD_ARM_VFP11_FIX_NONE
:
6413 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6417 /* Give a warning, but do as the user requests anyway. */
6418 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
6419 "workaround is not necessary for target architecture"), obfd
);
6422 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
6423 /* For earlier architectures, we might need the workaround, but do not
6424 enable it by default. If users is running with broken hardware, they
6425 must enable the erratum fix explicitly. */
6426 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6430 enum bfd_arm_vfp11_pipe
6438 /* Return a VFP register number. This is encoded as RX:X for single-precision
6439 registers, or X:RX for double-precision registers, where RX is the group of
6440 four bits in the instruction encoding and X is the single extension bit.
6441 RX and X fields are specified using their lowest (starting) bit. The return
6444 0...31: single-precision registers s0...s31
6445 32...63: double-precision registers d0...d31.
6447 Although X should be zero for VFP11 (encoding d0...d15 only), we might
6448 encounter VFP3 instructions, so we allow the full range for DP registers. */
6451 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
6455 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
6457 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
6460 /* Set bits in *WMASK according to a register number REG as encoded by
6461 bfd_arm_vfp11_regno(). Ignore d16-d31. */
6464 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
6469 *wmask
|= 3 << ((reg
- 32) * 2);
6472 /* Return TRUE if WMASK overwrites anything in REGS. */
6475 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
6479 for (i
= 0; i
< numregs
; i
++)
6481 unsigned int reg
= regs
[i
];
6483 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
6491 if ((wmask
& (3 << (reg
* 2))) != 0)
6498 /* In this function, we're interested in two things: finding input registers
6499 for VFP data-processing instructions, and finding the set of registers which
6500 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
6501 hold the written set, so FLDM etc. are easy to deal with (we're only
6502 interested in 32 SP registers or 16 dp registers, due to the VFP version
6503 implemented by the chip in question). DP registers are marked by setting
6504 both SP registers in the write mask). */
6506 static enum bfd_arm_vfp11_pipe
6507 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
6510 enum bfd_arm_vfp11_pipe vpipe
= VFP11_BAD
;
6511 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
6513 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
6516 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6517 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6519 pqrs
= ((insn
& 0x00800000) >> 20)
6520 | ((insn
& 0x00300000) >> 19)
6521 | ((insn
& 0x00000040) >> 6);
6525 case 0: /* fmac[sd]. */
6526 case 1: /* fnmac[sd]. */
6527 case 2: /* fmsc[sd]. */
6528 case 3: /* fnmsc[sd]. */
6530 bfd_arm_vfp11_write_mask (destmask
, fd
);
6532 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6537 case 4: /* fmul[sd]. */
6538 case 5: /* fnmul[sd]. */
6539 case 6: /* fadd[sd]. */
6540 case 7: /* fsub[sd]. */
6544 case 8: /* fdiv[sd]. */
6547 bfd_arm_vfp11_write_mask (destmask
, fd
);
6548 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6553 case 15: /* extended opcode. */
6555 unsigned int extn
= ((insn
>> 15) & 0x1e)
6556 | ((insn
>> 7) & 1);
6560 case 0: /* fcpy[sd]. */
6561 case 1: /* fabs[sd]. */
6562 case 2: /* fneg[sd]. */
6563 case 8: /* fcmp[sd]. */
6564 case 9: /* fcmpe[sd]. */
6565 case 10: /* fcmpz[sd]. */
6566 case 11: /* fcmpez[sd]. */
6567 case 16: /* fuito[sd]. */
6568 case 17: /* fsito[sd]. */
6569 case 24: /* ftoui[sd]. */
6570 case 25: /* ftouiz[sd]. */
6571 case 26: /* ftosi[sd]. */
6572 case 27: /* ftosiz[sd]. */
6573 /* These instructions will not bounce due to underflow. */
6578 case 3: /* fsqrt[sd]. */
6579 /* fsqrt cannot underflow, but it can (perhaps) overwrite
6580 registers to cause the erratum in previous instructions. */
6581 bfd_arm_vfp11_write_mask (destmask
, fd
);
6585 case 15: /* fcvt{ds,sd}. */
6589 bfd_arm_vfp11_write_mask (destmask
, fd
);
6591 /* Only FCVTSD can underflow. */
6592 if ((insn
& 0x100) != 0)
6611 /* Two-register transfer. */
6612 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
6614 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6616 if ((insn
& 0x100000) == 0)
6619 bfd_arm_vfp11_write_mask (destmask
, fm
);
6622 bfd_arm_vfp11_write_mask (destmask
, fm
);
6623 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
6629 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
6631 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6632 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
6636 case 0: /* Two-reg transfer. We should catch these above. */
6639 case 2: /* fldm[sdx]. */
6643 unsigned int i
, offset
= insn
& 0xff;
6648 for (i
= fd
; i
< fd
+ offset
; i
++)
6649 bfd_arm_vfp11_write_mask (destmask
, i
);
6653 case 4: /* fld[sd]. */
6655 bfd_arm_vfp11_write_mask (destmask
, fd
);
6664 /* Single-register transfer. Note L==0. */
6665 else if ((insn
& 0x0f100e10) == 0x0e000a10)
6667 unsigned int opcode
= (insn
>> 21) & 7;
6668 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
6672 case 0: /* fmsr/fmdlr. */
6673 case 1: /* fmdhr. */
6674 /* Mark fmdhr and fmdlr as writing to the whole of the DP
6675 destination register. I don't know if this is exactly right,
6676 but it is the conservative choice. */
6677 bfd_arm_vfp11_write_mask (destmask
, fn
);
6691 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
6694 /* Look for potentially-troublesome code sequences which might trigger the
6695 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
6696 (available from ARM) for details of the erratum. A short version is
6697 described in ld.texinfo. */
6700 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
6703 bfd_byte
*contents
= NULL
;
6705 int regs
[3], numregs
= 0;
6706 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6707 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
6709 if (globals
== NULL
)
6712 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
6713 The states transition as follows:
6715 0 -> 1 (vector) or 0 -> 2 (scalar)
6716 A VFP FMAC-pipeline instruction has been seen. Fill
6717 regs[0]..regs[numregs-1] with its input operands. Remember this
6718 instruction in 'first_fmac'.
6721 Any instruction, except for a VFP instruction which overwrites
6726 A VFP instruction has been seen which overwrites any of regs[*].
6727 We must make a veneer! Reset state to 0 before examining next
6731 If we fail to match anything in state 2, reset to state 0 and reset
6732 the instruction pointer to the instruction after 'first_fmac'.
6734 If the VFP11 vector mode is in use, there must be at least two unrelated
6735 instructions between anti-dependent VFP11 instructions to properly avoid
6736 triggering the erratum, hence the use of the extra state 1. */
6738 /* If we are only performing a partial link do not bother
6739 to construct any glue. */
6740 if (link_info
->relocatable
)
6743 /* Skip if this bfd does not correspond to an ELF image. */
6744 if (! is_arm_elf (abfd
))
6747 /* We should have chosen a fix type by the time we get here. */
6748 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
6750 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
6753 /* Skip this BFD if it corresponds to an executable or dynamic object. */
6754 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
6757 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6759 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
6760 struct _arm_elf_section_data
*sec_data
;
6762 /* If we don't have executable progbits, we're not interested in this
6763 section. Also skip if section is to be excluded. */
6764 if (elf_section_type (sec
) != SHT_PROGBITS
6765 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
6766 || (sec
->flags
& SEC_EXCLUDE
) != 0
6767 || sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
6768 || sec
->output_section
== bfd_abs_section_ptr
6769 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
6772 sec_data
= elf32_arm_section_data (sec
);
6774 if (sec_data
->mapcount
== 0)
6777 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6778 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6779 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6782 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
6783 elf32_arm_compare_mapping
);
6785 for (span
= 0; span
< sec_data
->mapcount
; span
++)
6787 unsigned int span_start
= sec_data
->map
[span
].vma
;
6788 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
6789 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
6790 char span_type
= sec_data
->map
[span
].type
;
6792 /* FIXME: Only ARM mode is supported at present. We may need to
6793 support Thumb-2 mode also at some point. */
6794 if (span_type
!= 'a')
6797 for (i
= span_start
; i
< span_end
;)
6799 unsigned int next_i
= i
+ 4;
6800 unsigned int insn
= bfd_big_endian (abfd
)
6801 ? (contents
[i
] << 24)
6802 | (contents
[i
+ 1] << 16)
6803 | (contents
[i
+ 2] << 8)
6805 : (contents
[i
+ 3] << 24)
6806 | (contents
[i
+ 2] << 16)
6807 | (contents
[i
+ 1] << 8)
6809 unsigned int writemask
= 0;
6810 enum bfd_arm_vfp11_pipe vpipe
;
6815 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
6817 /* I'm assuming the VFP11 erratum can trigger with denorm
6818 operands on either the FMAC or the DS pipeline. This might
6819 lead to slightly overenthusiastic veneer insertion. */
6820 if (vpipe
== VFP11_FMAC
|| vpipe
== VFP11_DS
)
6822 state
= use_vector
? 1 : 2;
6824 veneer_of_insn
= insn
;
6830 int other_regs
[3], other_numregs
;
6831 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6834 if (vpipe
!= VFP11_BAD
6835 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6845 int other_regs
[3], other_numregs
;
6846 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6849 if (vpipe
!= VFP11_BAD
6850 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6856 next_i
= first_fmac
+ 4;
6862 abort (); /* Should be unreachable. */
6867 elf32_vfp11_erratum_list
*newerr
=(elf32_vfp11_erratum_list
*)
6868 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
6870 elf32_arm_section_data (sec
)->erratumcount
+= 1;
6872 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
6877 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
6884 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
6889 newerr
->next
= sec_data
->erratumlist
;
6890 sec_data
->erratumlist
= newerr
;
6899 if (contents
!= NULL
6900 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6908 if (contents
!= NULL
6909 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6915 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
6916 after sections have been laid out, using specially-named symbols. */
6919 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
6920 struct bfd_link_info
*link_info
)
6923 struct elf32_arm_link_hash_table
*globals
;
6926 if (link_info
->relocatable
)
6929 /* Skip if this bfd does not correspond to an ELF image. */
6930 if (! is_arm_elf (abfd
))
6933 globals
= elf32_arm_hash_table (link_info
);
6934 if (globals
== NULL
)
6937 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
6938 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
6940 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6942 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
6943 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
6945 for (; errnode
!= NULL
; errnode
= errnode
->next
)
6947 struct elf_link_hash_entry
*myh
;
6950 switch (errnode
->type
)
6952 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
6953 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
6954 /* Find veneer symbol. */
6955 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
6956 errnode
->u
.b
.veneer
->u
.v
.id
);
6958 myh
= elf_link_hash_lookup
6959 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6962 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6963 "`%s'"), abfd
, tmp_name
);
6965 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6966 + myh
->root
.u
.def
.section
->output_offset
6967 + myh
->root
.u
.def
.value
;
6969 errnode
->u
.b
.veneer
->vma
= vma
;
6972 case VFP11_ERRATUM_ARM_VENEER
:
6973 case VFP11_ERRATUM_THUMB_VENEER
:
6974 /* Find return location. */
6975 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
6978 myh
= elf_link_hash_lookup
6979 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6982 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6983 "`%s'"), abfd
, tmp_name
);
6985 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6986 + myh
->root
.u
.def
.section
->output_offset
6987 + myh
->root
.u
.def
.value
;
6989 errnode
->u
.v
.branch
->vma
= vma
;
7002 /* Set target relocation values needed during linking. */
7005 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
7006 struct bfd_link_info
*link_info
,
7008 char * target2_type
,
7011 bfd_arm_vfp11_fix vfp11_fix
,
7012 int no_enum_warn
, int no_wchar_warn
,
7013 int pic_veneer
, int fix_cortex_a8
,
7016 struct elf32_arm_link_hash_table
*globals
;
7018 globals
= elf32_arm_hash_table (link_info
);
7019 if (globals
== NULL
)
7022 globals
->target1_is_rel
= target1_is_rel
;
7023 if (strcmp (target2_type
, "rel") == 0)
7024 globals
->target2_reloc
= R_ARM_REL32
;
7025 else if (strcmp (target2_type
, "abs") == 0)
7026 globals
->target2_reloc
= R_ARM_ABS32
;
7027 else if (strcmp (target2_type
, "got-rel") == 0)
7028 globals
->target2_reloc
= R_ARM_GOT_PREL
;
7031 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
7034 globals
->fix_v4bx
= fix_v4bx
;
7035 globals
->use_blx
|= use_blx
;
7036 globals
->vfp11_fix
= vfp11_fix
;
7037 globals
->pic_veneer
= pic_veneer
;
7038 globals
->fix_cortex_a8
= fix_cortex_a8
;
7039 globals
->fix_arm1176
= fix_arm1176
;
7041 BFD_ASSERT (is_arm_elf (output_bfd
));
7042 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
7043 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
7046 /* Replace the target offset of a Thumb bl or b.w instruction. */
7049 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
7055 BFD_ASSERT ((offset
& 1) == 0);
7057 upper
= bfd_get_16 (abfd
, insn
);
7058 lower
= bfd_get_16 (abfd
, insn
+ 2);
7059 reloc_sign
= (offset
< 0) ? 1 : 0;
7060 upper
= (upper
& ~(bfd_vma
) 0x7ff)
7061 | ((offset
>> 12) & 0x3ff)
7062 | (reloc_sign
<< 10);
7063 lower
= (lower
& ~(bfd_vma
) 0x2fff)
7064 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
7065 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
7066 | ((offset
>> 1) & 0x7ff);
7067 bfd_put_16 (abfd
, upper
, insn
);
7068 bfd_put_16 (abfd
, lower
, insn
+ 2);
7071 /* Thumb code calling an ARM function. */
7074 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
7078 asection
* input_section
,
7079 bfd_byte
* hit_data
,
7082 bfd_signed_vma addend
,
7084 char **error_message
)
7088 long int ret_offset
;
7089 struct elf_link_hash_entry
* myh
;
7090 struct elf32_arm_link_hash_table
* globals
;
7092 myh
= find_thumb_glue (info
, name
, error_message
);
7096 globals
= elf32_arm_hash_table (info
);
7097 BFD_ASSERT (globals
!= NULL
);
7098 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7100 my_offset
= myh
->root
.u
.def
.value
;
7102 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7103 THUMB2ARM_GLUE_SECTION_NAME
);
7105 BFD_ASSERT (s
!= NULL
);
7106 BFD_ASSERT (s
->contents
!= NULL
);
7107 BFD_ASSERT (s
->output_section
!= NULL
);
7109 if ((my_offset
& 0x01) == 0x01)
7112 && sym_sec
->owner
!= NULL
7113 && !INTERWORK_FLAG (sym_sec
->owner
))
7115 (*_bfd_error_handler
)
7116 (_("%B(%s): warning: interworking not enabled.\n"
7117 " first occurrence: %B: Thumb call to ARM"),
7118 sym_sec
->owner
, input_bfd
, name
);
7124 myh
->root
.u
.def
.value
= my_offset
;
7126 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
7127 s
->contents
+ my_offset
);
7129 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
7130 s
->contents
+ my_offset
+ 2);
7133 /* Address of destination of the stub. */
7134 ((bfd_signed_vma
) val
)
7136 /* Offset from the start of the current section
7137 to the start of the stubs. */
7139 /* Offset of the start of this stub from the start of the stubs. */
7141 /* Address of the start of the current section. */
7142 + s
->output_section
->vma
)
7143 /* The branch instruction is 4 bytes into the stub. */
7145 /* ARM branches work from the pc of the instruction + 8. */
7148 put_arm_insn (globals
, output_bfd
,
7149 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
7150 s
->contents
+ my_offset
+ 4);
7153 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
7155 /* Now go back and fix up the original BL insn to point to here. */
7157 /* Address of where the stub is located. */
7158 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
7159 /* Address of where the BL is located. */
7160 - (input_section
->output_section
->vma
+ input_section
->output_offset
7162 /* Addend in the relocation. */
7164 /* Biassing for PC-relative addressing. */
7167 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
7172 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
7174 static struct elf_link_hash_entry
*
7175 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
7182 char ** error_message
)
7185 long int ret_offset
;
7186 struct elf_link_hash_entry
* myh
;
7187 struct elf32_arm_link_hash_table
* globals
;
7189 myh
= find_arm_glue (info
, name
, error_message
);
7193 globals
= elf32_arm_hash_table (info
);
7194 BFD_ASSERT (globals
!= NULL
);
7195 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7197 my_offset
= myh
->root
.u
.def
.value
;
7199 if ((my_offset
& 0x01) == 0x01)
7202 && sym_sec
->owner
!= NULL
7203 && !INTERWORK_FLAG (sym_sec
->owner
))
7205 (*_bfd_error_handler
)
7206 (_("%B(%s): warning: interworking not enabled.\n"
7207 " first occurrence: %B: arm call to thumb"),
7208 sym_sec
->owner
, input_bfd
, name
);
7212 myh
->root
.u
.def
.value
= my_offset
;
7214 if (info
->shared
|| globals
->root
.is_relocatable_executable
7215 || globals
->pic_veneer
)
7217 /* For relocatable objects we can't use absolute addresses,
7218 so construct the address from a relative offset. */
7219 /* TODO: If the offset is small it's probably worth
7220 constructing the address with adds. */
7221 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
7222 s
->contents
+ my_offset
);
7223 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
7224 s
->contents
+ my_offset
+ 4);
7225 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
7226 s
->contents
+ my_offset
+ 8);
7227 /* Adjust the offset by 4 for the position of the add,
7228 and 8 for the pipeline offset. */
7229 ret_offset
= (val
- (s
->output_offset
7230 + s
->output_section
->vma
7233 bfd_put_32 (output_bfd
, ret_offset
,
7234 s
->contents
+ my_offset
+ 12);
7236 else if (globals
->use_blx
)
7238 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
7239 s
->contents
+ my_offset
);
7241 /* It's a thumb address. Add the low order bit. */
7242 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
7243 s
->contents
+ my_offset
+ 4);
7247 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
7248 s
->contents
+ my_offset
);
7250 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
7251 s
->contents
+ my_offset
+ 4);
7253 /* It's a thumb address. Add the low order bit. */
7254 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
7255 s
->contents
+ my_offset
+ 8);
7261 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
7266 /* Arm code calling a Thumb function. */
7269 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
7273 asection
* input_section
,
7274 bfd_byte
* hit_data
,
7277 bfd_signed_vma addend
,
7279 char **error_message
)
7281 unsigned long int tmp
;
7284 long int ret_offset
;
7285 struct elf_link_hash_entry
* myh
;
7286 struct elf32_arm_link_hash_table
* globals
;
7288 globals
= elf32_arm_hash_table (info
);
7289 BFD_ASSERT (globals
!= NULL
);
7290 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7292 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7293 ARM2THUMB_GLUE_SECTION_NAME
);
7294 BFD_ASSERT (s
!= NULL
);
7295 BFD_ASSERT (s
->contents
!= NULL
);
7296 BFD_ASSERT (s
->output_section
!= NULL
);
7298 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
7299 sym_sec
, val
, s
, error_message
);
7303 my_offset
= myh
->root
.u
.def
.value
;
7304 tmp
= bfd_get_32 (input_bfd
, hit_data
);
7305 tmp
= tmp
& 0xFF000000;
7307 /* Somehow these are both 4 too far, so subtract 8. */
7308 ret_offset
= (s
->output_offset
7310 + s
->output_section
->vma
7311 - (input_section
->output_offset
7312 + input_section
->output_section
->vma
7316 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
7318 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
7323 /* Populate Arm stub for an exported Thumb function. */
7326 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
7328 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
7330 struct elf_link_hash_entry
* myh
;
7331 struct elf32_arm_link_hash_entry
*eh
;
7332 struct elf32_arm_link_hash_table
* globals
;
7335 char *error_message
;
7337 eh
= elf32_arm_hash_entry (h
);
7338 /* Allocate stubs for exported Thumb functions on v4t. */
7339 if (eh
->export_glue
== NULL
)
7342 globals
= elf32_arm_hash_table (info
);
7343 BFD_ASSERT (globals
!= NULL
);
7344 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7346 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7347 ARM2THUMB_GLUE_SECTION_NAME
);
7348 BFD_ASSERT (s
!= NULL
);
7349 BFD_ASSERT (s
->contents
!= NULL
);
7350 BFD_ASSERT (s
->output_section
!= NULL
);
7352 sec
= eh
->export_glue
->root
.u
.def
.section
;
7354 BFD_ASSERT (sec
->output_section
!= NULL
);
7356 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
7357 + sec
->output_section
->vma
;
7359 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
7360 h
->root
.u
.def
.section
->owner
,
7361 globals
->obfd
, sec
, val
, s
,
7367 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
7370 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
7375 struct elf32_arm_link_hash_table
*globals
;
7377 globals
= elf32_arm_hash_table (info
);
7378 BFD_ASSERT (globals
!= NULL
);
7379 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7381 s
= bfd_get_linker_section (globals
->bfd_of_glue_owner
,
7382 ARM_BX_GLUE_SECTION_NAME
);
7383 BFD_ASSERT (s
!= NULL
);
7384 BFD_ASSERT (s
->contents
!= NULL
);
7385 BFD_ASSERT (s
->output_section
!= NULL
);
7387 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
7389 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
7391 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
7393 p
= s
->contents
+ glue_addr
;
7394 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
7395 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
7396 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
7397 globals
->bx_glue_offset
[reg
] |= 1;
7400 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
7403 /* Generate Arm stubs for exported Thumb symbols. */
7405 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
7406 struct bfd_link_info
*link_info
)
7408 struct elf32_arm_link_hash_table
* globals
;
7410 if (link_info
== NULL
)
7411 /* Ignore this if we are not called by the ELF backend linker. */
7414 globals
= elf32_arm_hash_table (link_info
);
7415 if (globals
== NULL
)
7418 /* If blx is available then exported Thumb symbols are OK and there is
7420 if (globals
->use_blx
)
7423 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
7427 /* Reserve space for COUNT dynamic relocations in relocation selection
7431 elf32_arm_allocate_dynrelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7432 bfd_size_type count
)
7434 struct elf32_arm_link_hash_table
*htab
;
7436 htab
= elf32_arm_hash_table (info
);
7437 BFD_ASSERT (htab
->root
.dynamic_sections_created
);
7440 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7443 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
7444 dynamic, the relocations should go in SRELOC, otherwise they should
7445 go in the special .rel.iplt section. */
7448 elf32_arm_allocate_irelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7449 bfd_size_type count
)
7451 struct elf32_arm_link_hash_table
*htab
;
7453 htab
= elf32_arm_hash_table (info
);
7454 if (!htab
->root
.dynamic_sections_created
)
7455 htab
->root
.irelplt
->size
+= RELOC_SIZE (htab
) * count
;
7458 BFD_ASSERT (sreloc
!= NULL
);
7459 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7463 /* Add relocation REL to the end of relocation section SRELOC. */
7466 elf32_arm_add_dynreloc (bfd
*output_bfd
, struct bfd_link_info
*info
,
7467 asection
*sreloc
, Elf_Internal_Rela
*rel
)
7470 struct elf32_arm_link_hash_table
*htab
;
7472 htab
= elf32_arm_hash_table (info
);
7473 if (!htab
->root
.dynamic_sections_created
7474 && ELF32_R_TYPE (rel
->r_info
) == R_ARM_IRELATIVE
)
7475 sreloc
= htab
->root
.irelplt
;
7478 loc
= sreloc
->contents
;
7479 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (htab
);
7480 if (sreloc
->reloc_count
* RELOC_SIZE (htab
) > sreloc
->size
)
7482 SWAP_RELOC_OUT (htab
) (output_bfd
, rel
, loc
);
7485 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
7486 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
7490 elf32_arm_allocate_plt_entry (struct bfd_link_info
*info
,
7491 bfd_boolean is_iplt_entry
,
7492 union gotplt_union
*root_plt
,
7493 struct arm_plt_info
*arm_plt
)
7495 struct elf32_arm_link_hash_table
*htab
;
7499 htab
= elf32_arm_hash_table (info
);
7503 splt
= htab
->root
.iplt
;
7504 sgotplt
= htab
->root
.igotplt
;
7506 /* NaCl uses a special first entry in .iplt too. */
7507 if (htab
->nacl_p
&& splt
->size
== 0)
7508 splt
->size
+= htab
->plt_header_size
;
7510 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
7511 elf32_arm_allocate_irelocs (info
, htab
->root
.irelplt
, 1);
7515 splt
= htab
->root
.splt
;
7516 sgotplt
= htab
->root
.sgotplt
;
7518 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
7519 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
7521 /* If this is the first .plt entry, make room for the special
7523 if (splt
->size
== 0)
7524 splt
->size
+= htab
->plt_header_size
;
7527 /* Allocate the PLT entry itself, including any leading Thumb stub. */
7528 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7529 splt
->size
+= PLT_THUMB_STUB_SIZE
;
7530 root_plt
->offset
= splt
->size
;
7531 splt
->size
+= htab
->plt_entry_size
;
7533 if (!htab
->symbian_p
)
7535 /* We also need to make an entry in the .got.plt section, which
7536 will be placed in the .got section by the linker script. */
7537 arm_plt
->got_offset
= sgotplt
->size
- 8 * htab
->num_tls_desc
;
7543 arm_movw_immediate (bfd_vma value
)
7545 return (value
& 0x00000fff) | ((value
& 0x0000f000) << 4);
7549 arm_movt_immediate (bfd_vma value
)
7551 return ((value
& 0x0fff0000) >> 16) | ((value
& 0xf0000000) >> 12);
7554 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
7555 the entry lives in .iplt and resolves to (*SYM_VALUE)().
7556 Otherwise, DYNINDX is the index of the symbol in the dynamic
7557 symbol table and SYM_VALUE is undefined.
7559 ROOT_PLT points to the offset of the PLT entry from the start of its
7560 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
7561 bookkeeping information.
7563 Returns FALSE if there was a problem. */
7566 elf32_arm_populate_plt_entry (bfd
*output_bfd
, struct bfd_link_info
*info
,
7567 union gotplt_union
*root_plt
,
7568 struct arm_plt_info
*arm_plt
,
7569 int dynindx
, bfd_vma sym_value
)
7571 struct elf32_arm_link_hash_table
*htab
;
7577 Elf_Internal_Rela rel
;
7578 bfd_vma plt_header_size
;
7579 bfd_vma got_header_size
;
7581 htab
= elf32_arm_hash_table (info
);
7583 /* Pick the appropriate sections and sizes. */
7586 splt
= htab
->root
.iplt
;
7587 sgot
= htab
->root
.igotplt
;
7588 srel
= htab
->root
.irelplt
;
7590 /* There are no reserved entries in .igot.plt, and no special
7591 first entry in .iplt. */
7592 got_header_size
= 0;
7593 plt_header_size
= 0;
7597 splt
= htab
->root
.splt
;
7598 sgot
= htab
->root
.sgotplt
;
7599 srel
= htab
->root
.srelplt
;
7601 got_header_size
= get_elf_backend_data (output_bfd
)->got_header_size
;
7602 plt_header_size
= htab
->plt_header_size
;
7604 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
7606 /* Fill in the entry in the procedure linkage table. */
7607 if (htab
->symbian_p
)
7609 BFD_ASSERT (dynindx
>= 0);
7610 put_arm_insn (htab
, output_bfd
,
7611 elf32_arm_symbian_plt_entry
[0],
7612 splt
->contents
+ root_plt
->offset
);
7613 bfd_put_32 (output_bfd
,
7614 elf32_arm_symbian_plt_entry
[1],
7615 splt
->contents
+ root_plt
->offset
+ 4);
7617 /* Fill in the entry in the .rel.plt section. */
7618 rel
.r_offset
= (splt
->output_section
->vma
7619 + splt
->output_offset
7620 + root_plt
->offset
+ 4);
7621 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_GLOB_DAT
);
7623 /* Get the index in the procedure linkage table which
7624 corresponds to this symbol. This is the index of this symbol
7625 in all the symbols for which we are making plt entries. The
7626 first entry in the procedure linkage table is reserved. */
7627 plt_index
= ((root_plt
->offset
- plt_header_size
)
7628 / htab
->plt_entry_size
);
7632 bfd_vma got_offset
, got_address
, plt_address
;
7633 bfd_vma got_displacement
, initial_got_entry
;
7636 BFD_ASSERT (sgot
!= NULL
);
7638 /* Get the offset into the .(i)got.plt table of the entry that
7639 corresponds to this function. */
7640 got_offset
= (arm_plt
->got_offset
& -2);
7642 /* Get the index in the procedure linkage table which
7643 corresponds to this symbol. This is the index of this symbol
7644 in all the symbols for which we are making plt entries.
7645 After the reserved .got.plt entries, all symbols appear in
7646 the same order as in .plt. */
7647 plt_index
= (got_offset
- got_header_size
) / 4;
7649 /* Calculate the address of the GOT entry. */
7650 got_address
= (sgot
->output_section
->vma
7651 + sgot
->output_offset
7654 /* ...and the address of the PLT entry. */
7655 plt_address
= (splt
->output_section
->vma
7656 + splt
->output_offset
7657 + root_plt
->offset
);
7659 ptr
= splt
->contents
+ root_plt
->offset
;
7660 if (htab
->vxworks_p
&& info
->shared
)
7665 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7667 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
7669 val
|= got_address
- sgot
->output_section
->vma
;
7671 val
|= plt_index
* RELOC_SIZE (htab
);
7672 if (i
== 2 || i
== 5)
7673 bfd_put_32 (output_bfd
, val
, ptr
);
7675 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7678 else if (htab
->vxworks_p
)
7683 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7685 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
7689 val
|= 0xffffff & -((root_plt
->offset
+ i
* 4 + 8) >> 2);
7691 val
|= plt_index
* RELOC_SIZE (htab
);
7692 if (i
== 2 || i
== 5)
7693 bfd_put_32 (output_bfd
, val
, ptr
);
7695 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7698 loc
= (htab
->srelplt2
->contents
7699 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
7701 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
7702 referencing the GOT for this PLT entry. */
7703 rel
.r_offset
= plt_address
+ 8;
7704 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
7705 rel
.r_addend
= got_offset
;
7706 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7707 loc
+= RELOC_SIZE (htab
);
7709 /* Create the R_ARM_ABS32 relocation referencing the
7710 beginning of the PLT for this GOT entry. */
7711 rel
.r_offset
= got_address
;
7712 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
7714 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7716 else if (htab
->nacl_p
)
7718 /* Calculate the displacement between the PLT slot and the
7719 common tail that's part of the special initial PLT slot. */
7720 int32_t tail_displacement
7721 = ((splt
->output_section
->vma
+ splt
->output_offset
7722 + ARM_NACL_PLT_TAIL_OFFSET
)
7723 - (plt_address
+ htab
->plt_entry_size
+ 4));
7724 BFD_ASSERT ((tail_displacement
& 3) == 0);
7725 tail_displacement
>>= 2;
7727 BFD_ASSERT ((tail_displacement
& 0xff000000) == 0
7728 || (-tail_displacement
& 0xff000000) == 0);
7730 /* Calculate the displacement between the PLT slot and the entry
7731 in the GOT. The offset accounts for the value produced by
7732 adding to pc in the penultimate instruction of the PLT stub. */
7733 got_displacement
= (got_address
7734 - (plt_address
+ htab
->plt_entry_size
));
7736 /* NaCl does not support interworking at all. */
7737 BFD_ASSERT (!elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
));
7739 put_arm_insn (htab
, output_bfd
,
7740 elf32_arm_nacl_plt_entry
[0]
7741 | arm_movw_immediate (got_displacement
),
7743 put_arm_insn (htab
, output_bfd
,
7744 elf32_arm_nacl_plt_entry
[1]
7745 | arm_movt_immediate (got_displacement
),
7747 put_arm_insn (htab
, output_bfd
,
7748 elf32_arm_nacl_plt_entry
[2],
7750 put_arm_insn (htab
, output_bfd
,
7751 elf32_arm_nacl_plt_entry
[3]
7752 | (tail_displacement
& 0x00ffffff),
7755 else if (using_thumb_only (htab
))
7757 /* PR ld/16017: Generate thumb only PLT entries. */
7758 if (!using_thumb2 (htab
))
7760 /* FIXME: We ought to be able to generate thumb-1 PLT
7762 _bfd_error_handler (_("%B: Warning: thumb-1 mode PLT generation not currently supported"),
7767 /* Calculate the displacement between the PLT slot and the entry in
7768 the GOT. The 12-byte offset accounts for the value produced by
7769 adding to pc in the 3rd instruction of the PLT stub. */
7770 got_displacement
= got_address
- (plt_address
+ 12);
7772 /* As we are using 32 bit instructions we have to use 'put_arm_insn'
7773 instead of 'put_thumb_insn'. */
7774 put_arm_insn (htab
, output_bfd
,
7775 elf32_thumb2_plt_entry
[0]
7776 | ((got_displacement
& 0x000000ff) << 16)
7777 | ((got_displacement
& 0x00000700) << 20)
7778 | ((got_displacement
& 0x00000800) >> 1)
7779 | ((got_displacement
& 0x0000f000) >> 12),
7781 put_arm_insn (htab
, output_bfd
,
7782 elf32_thumb2_plt_entry
[1]
7783 | ((got_displacement
& 0x00ff0000) )
7784 | ((got_displacement
& 0x07000000) << 4)
7785 | ((got_displacement
& 0x08000000) >> 17)
7786 | ((got_displacement
& 0xf0000000) >> 28),
7788 put_arm_insn (htab
, output_bfd
,
7789 elf32_thumb2_plt_entry
[2],
7791 put_arm_insn (htab
, output_bfd
,
7792 elf32_thumb2_plt_entry
[3],
7797 /* Calculate the displacement between the PLT slot and the
7798 entry in the GOT. The eight-byte offset accounts for the
7799 value produced by adding to pc in the first instruction
7801 got_displacement
= got_address
- (plt_address
+ 8);
7803 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7805 put_thumb_insn (htab
, output_bfd
,
7806 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
7807 put_thumb_insn (htab
, output_bfd
,
7808 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
7811 if (!elf32_arm_use_long_plt_entry
)
7813 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
7815 put_arm_insn (htab
, output_bfd
,
7816 elf32_arm_plt_entry_short
[0]
7817 | ((got_displacement
& 0x0ff00000) >> 20),
7819 put_arm_insn (htab
, output_bfd
,
7820 elf32_arm_plt_entry_short
[1]
7821 | ((got_displacement
& 0x000ff000) >> 12),
7823 put_arm_insn (htab
, output_bfd
,
7824 elf32_arm_plt_entry_short
[2]
7825 | (got_displacement
& 0x00000fff),
7827 #ifdef FOUR_WORD_PLT
7828 bfd_put_32 (output_bfd
, elf32_arm_plt_entry_short
[3], ptr
+ 12);
7833 put_arm_insn (htab
, output_bfd
,
7834 elf32_arm_plt_entry_long
[0]
7835 | ((got_displacement
& 0xf0000000) >> 28),
7837 put_arm_insn (htab
, output_bfd
,
7838 elf32_arm_plt_entry_long
[1]
7839 | ((got_displacement
& 0x0ff00000) >> 20),
7841 put_arm_insn (htab
, output_bfd
,
7842 elf32_arm_plt_entry_long
[2]
7843 | ((got_displacement
& 0x000ff000) >> 12),
7845 put_arm_insn (htab
, output_bfd
,
7846 elf32_arm_plt_entry_long
[3]
7847 | (got_displacement
& 0x00000fff),
7852 /* Fill in the entry in the .rel(a).(i)plt section. */
7853 rel
.r_offset
= got_address
;
7857 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
7858 The dynamic linker or static executable then calls SYM_VALUE
7859 to determine the correct run-time value of the .igot.plt entry. */
7860 rel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
7861 initial_got_entry
= sym_value
;
7865 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_JUMP_SLOT
);
7866 initial_got_entry
= (splt
->output_section
->vma
7867 + splt
->output_offset
);
7870 /* Fill in the entry in the global offset table. */
7871 bfd_put_32 (output_bfd
, initial_got_entry
,
7872 sgot
->contents
+ got_offset
);
7876 elf32_arm_add_dynreloc (output_bfd
, info
, srel
, &rel
);
7879 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
7880 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7886 /* Some relocations map to different relocations depending on the
7887 target. Return the real relocation. */
7890 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
7896 if (globals
->target1_is_rel
)
7902 return globals
->target2_reloc
;
7909 /* Return the base VMA address which should be subtracted from real addresses
7910 when resolving @dtpoff relocation.
7911 This is PT_TLS segment p_vaddr. */
7914 dtpoff_base (struct bfd_link_info
*info
)
7916 /* If tls_sec is NULL, we should have signalled an error already. */
7917 if (elf_hash_table (info
)->tls_sec
== NULL
)
7919 return elf_hash_table (info
)->tls_sec
->vma
;
7922 /* Return the relocation value for @tpoff relocation
7923 if STT_TLS virtual address is ADDRESS. */
7926 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
7928 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7931 /* If tls_sec is NULL, we should have signalled an error already. */
7932 if (htab
->tls_sec
== NULL
)
7934 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
7935 return address
- htab
->tls_sec
->vma
+ base
;
7938 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
7939 VALUE is the relocation value. */
7941 static bfd_reloc_status_type
7942 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
7945 return bfd_reloc_overflow
;
7947 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
7948 bfd_put_32 (abfd
, value
, data
);
7949 return bfd_reloc_ok
;
7952 /* Handle TLS relaxations. Relaxing is possible for symbols that use
7953 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
7954 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
7956 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
7957 is to then call final_link_relocate. Return other values in the
7960 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
7961 the pre-relaxed code. It would be nice if the relocs were updated
7962 to match the optimization. */
7964 static bfd_reloc_status_type
7965 elf32_arm_tls_relax (struct elf32_arm_link_hash_table
*globals
,
7966 bfd
*input_bfd
, asection
*input_sec
, bfd_byte
*contents
,
7967 Elf_Internal_Rela
*rel
, unsigned long is_local
)
7971 switch (ELF32_R_TYPE (rel
->r_info
))
7974 return bfd_reloc_notsupported
;
7976 case R_ARM_TLS_GOTDESC
:
7981 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7983 insn
-= 5; /* THUMB */
7985 insn
-= 8; /* ARM */
7987 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7988 return bfd_reloc_continue
;
7990 case R_ARM_THM_TLS_DESCSEQ
:
7992 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
7993 if ((insn
& 0xff78) == 0x4478) /* add rx, pc */
7997 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7999 else if ((insn
& 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
8003 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
8006 bfd_put_16 (input_bfd
, insn
& 0xf83f, contents
+ rel
->r_offset
);
8008 else if ((insn
& 0xff87) == 0x4780) /* blx rx */
8012 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
8015 bfd_put_16 (input_bfd
, 0x4600 | (insn
& 0x78),
8016 contents
+ rel
->r_offset
);
8020 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
8021 /* It's a 32 bit instruction, fetch the rest of it for
8022 error generation. */
8024 | bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
8025 (*_bfd_error_handler
)
8026 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' in TLS trampoline"),
8027 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
8028 return bfd_reloc_notsupported
;
8032 case R_ARM_TLS_DESCSEQ
:
8034 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
8035 if ((insn
& 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
8039 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xffff),
8040 contents
+ rel
->r_offset
);
8042 else if ((insn
& 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
8046 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
8049 bfd_put_32 (input_bfd
, insn
& 0xfffff000,
8050 contents
+ rel
->r_offset
);
8052 else if ((insn
& 0xfffffff0) == 0xe12fff30) /* blx rx */
8056 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
8059 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xf),
8060 contents
+ rel
->r_offset
);
8064 (*_bfd_error_handler
)
8065 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' in TLS trampoline"),
8066 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
8067 return bfd_reloc_notsupported
;
8071 case R_ARM_TLS_CALL
:
8072 /* GD->IE relaxation, turn the instruction into 'nop' or
8073 'ldr r0, [pc,r0]' */
8074 insn
= is_local
? 0xe1a00000 : 0xe79f0000;
8075 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
8078 case R_ARM_THM_TLS_CALL
:
8079 /* GD->IE relaxation. */
8081 /* add r0,pc; ldr r0, [r0] */
8083 else if (arch_has_thumb2_nop (globals
))
8090 bfd_put_16 (input_bfd
, insn
>> 16, contents
+ rel
->r_offset
);
8091 bfd_put_16 (input_bfd
, insn
& 0xffff, contents
+ rel
->r_offset
+ 2);
8094 return bfd_reloc_ok
;
8097 /* For a given value of n, calculate the value of G_n as required to
8098 deal with group relocations. We return it in the form of an
8099 encoded constant-and-rotation, together with the final residual. If n is
8100 specified as less than zero, then final_residual is filled with the
8101 input value and no further action is performed. */
8104 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
8108 bfd_vma encoded_g_n
= 0;
8109 bfd_vma residual
= value
; /* Also known as Y_n. */
8111 for (current_n
= 0; current_n
<= n
; current_n
++)
8115 /* Calculate which part of the value to mask. */
8122 /* Determine the most significant bit in the residual and
8123 align the resulting value to a 2-bit boundary. */
8124 for (msb
= 30; msb
>= 0; msb
-= 2)
8125 if (residual
& (3 << msb
))
8128 /* The desired shift is now (msb - 6), or zero, whichever
8135 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
8136 g_n
= residual
& (0xff << shift
);
8137 encoded_g_n
= (g_n
>> shift
)
8138 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
8140 /* Calculate the residual for the next time around. */
8144 *final_residual
= residual
;
8149 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
8150 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
8153 identify_add_or_sub (bfd_vma insn
)
8155 int opcode
= insn
& 0x1e00000;
8157 if (opcode
== 1 << 23) /* ADD */
8160 if (opcode
== 1 << 22) /* SUB */
8166 /* Perform a relocation as part of a final link. */
8168 static bfd_reloc_status_type
8169 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
8172 asection
* input_section
,
8173 bfd_byte
* contents
,
8174 Elf_Internal_Rela
* rel
,
8176 struct bfd_link_info
* info
,
8178 const char * sym_name
,
8179 unsigned char st_type
,
8180 enum arm_st_branch_type branch_type
,
8181 struct elf_link_hash_entry
* h
,
8182 bfd_boolean
* unresolved_reloc_p
,
8183 char ** error_message
)
8185 unsigned long r_type
= howto
->type
;
8186 unsigned long r_symndx
;
8187 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
8188 bfd_vma
* local_got_offsets
;
8189 bfd_vma
* local_tlsdesc_gotents
;
8192 asection
* sreloc
= NULL
;
8195 bfd_signed_vma signed_addend
;
8196 unsigned char dynreloc_st_type
;
8197 bfd_vma dynreloc_value
;
8198 struct elf32_arm_link_hash_table
* globals
;
8199 struct elf32_arm_link_hash_entry
*eh
;
8200 union gotplt_union
*root_plt
;
8201 struct arm_plt_info
*arm_plt
;
8203 bfd_vma gotplt_offset
;
8204 bfd_boolean has_iplt_entry
;
8206 globals
= elf32_arm_hash_table (info
);
8207 if (globals
== NULL
)
8208 return bfd_reloc_notsupported
;
8210 BFD_ASSERT (is_arm_elf (input_bfd
));
8212 /* Some relocation types map to different relocations depending on the
8213 target. We pick the right one here. */
8214 r_type
= arm_real_reloc_type (globals
, r_type
);
8216 /* It is possible to have linker relaxations on some TLS access
8217 models. Update our information here. */
8218 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
8220 if (r_type
!= howto
->type
)
8221 howto
= elf32_arm_howto_from_type (r_type
);
8223 /* If the start address has been set, then set the EF_ARM_HASENTRY
8224 flag. Setting this more than once is redundant, but the cost is
8225 not too high, and it keeps the code simple.
8227 The test is done here, rather than somewhere else, because the
8228 start address is only set just before the final link commences.
8230 Note - if the user deliberately sets a start address of 0, the
8231 flag will not be set. */
8232 if (bfd_get_start_address (output_bfd
) != 0)
8233 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
8235 eh
= (struct elf32_arm_link_hash_entry
*) h
;
8236 sgot
= globals
->root
.sgot
;
8237 local_got_offsets
= elf_local_got_offsets (input_bfd
);
8238 local_tlsdesc_gotents
= elf32_arm_local_tlsdesc_gotent (input_bfd
);
8240 if (globals
->root
.dynamic_sections_created
)
8241 srelgot
= globals
->root
.srelgot
;
8245 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8247 if (globals
->use_rel
)
8249 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
8251 if (addend
& ((howto
->src_mask
+ 1) >> 1))
8254 signed_addend
&= ~ howto
->src_mask
;
8255 signed_addend
|= addend
;
8258 signed_addend
= addend
;
8261 addend
= signed_addend
= rel
->r_addend
;
8263 /* ST_BRANCH_TO_ARM is nonsense to thumb-only targets when we
8264 are resolving a function call relocation. */
8265 if (using_thumb_only (globals
)
8266 && (r_type
== R_ARM_THM_CALL
8267 || r_type
== R_ARM_THM_JUMP24
)
8268 && branch_type
== ST_BRANCH_TO_ARM
)
8269 branch_type
= ST_BRANCH_TO_THUMB
;
8271 /* Record the symbol information that should be used in dynamic
8273 dynreloc_st_type
= st_type
;
8274 dynreloc_value
= value
;
8275 if (branch_type
== ST_BRANCH_TO_THUMB
)
8276 dynreloc_value
|= 1;
8278 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
8279 VALUE appropriately for relocations that we resolve at link time. */
8280 has_iplt_entry
= FALSE
;
8281 if (elf32_arm_get_plt_info (input_bfd
, eh
, r_symndx
, &root_plt
, &arm_plt
)
8282 && root_plt
->offset
!= (bfd_vma
) -1)
8284 plt_offset
= root_plt
->offset
;
8285 gotplt_offset
= arm_plt
->got_offset
;
8287 if (h
== NULL
|| eh
->is_iplt
)
8289 has_iplt_entry
= TRUE
;
8290 splt
= globals
->root
.iplt
;
8292 /* Populate .iplt entries here, because not all of them will
8293 be seen by finish_dynamic_symbol. The lower bit is set if
8294 we have already populated the entry. */
8299 if (elf32_arm_populate_plt_entry (output_bfd
, info
, root_plt
, arm_plt
,
8300 -1, dynreloc_value
))
8301 root_plt
->offset
|= 1;
8303 return bfd_reloc_notsupported
;
8306 /* Static relocations always resolve to the .iplt entry. */
8308 value
= (splt
->output_section
->vma
8309 + splt
->output_offset
8311 branch_type
= ST_BRANCH_TO_ARM
;
8313 /* If there are non-call relocations that resolve to the .iplt
8314 entry, then all dynamic ones must too. */
8315 if (arm_plt
->noncall_refcount
!= 0)
8317 dynreloc_st_type
= st_type
;
8318 dynreloc_value
= value
;
8322 /* We populate the .plt entry in finish_dynamic_symbol. */
8323 splt
= globals
->root
.splt
;
8328 plt_offset
= (bfd_vma
) -1;
8329 gotplt_offset
= (bfd_vma
) -1;
8335 /* We don't need to find a value for this symbol. It's just a
8337 *unresolved_reloc_p
= FALSE
;
8338 return bfd_reloc_ok
;
8341 if (!globals
->vxworks_p
)
8342 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
8346 case R_ARM_ABS32_NOI
:
8348 case R_ARM_REL32_NOI
:
8354 /* Handle relocations which should use the PLT entry. ABS32/REL32
8355 will use the symbol's value, which may point to a PLT entry, but we
8356 don't need to handle that here. If we created a PLT entry, all
8357 branches in this object should go to it, except if the PLT is too
8358 far away, in which case a long branch stub should be inserted. */
8359 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
8360 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
8361 && r_type
!= R_ARM_CALL
8362 && r_type
!= R_ARM_JUMP24
8363 && r_type
!= R_ARM_PLT32
)
8364 && plt_offset
!= (bfd_vma
) -1)
8366 /* If we've created a .plt section, and assigned a PLT entry
8367 to this function, it must either be a STT_GNU_IFUNC reference
8368 or not be known to bind locally. In other cases, we should
8369 have cleared the PLT entry by now. */
8370 BFD_ASSERT (has_iplt_entry
|| !SYMBOL_CALLS_LOCAL (info
, h
));
8372 value
= (splt
->output_section
->vma
8373 + splt
->output_offset
8375 *unresolved_reloc_p
= FALSE
;
8376 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8377 contents
, rel
->r_offset
, value
,
8381 /* When generating a shared object or relocatable executable, these
8382 relocations are copied into the output file to be resolved at
8384 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
8385 && (input_section
->flags
& SEC_ALLOC
)
8386 && !(globals
->vxworks_p
8387 && strcmp (input_section
->output_section
->name
,
8389 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
8390 || !SYMBOL_CALLS_LOCAL (info
, h
))
8391 && !(input_bfd
== globals
->stub_bfd
8392 && strstr (input_section
->name
, STUB_SUFFIX
))
8394 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8395 || h
->root
.type
!= bfd_link_hash_undefweak
)
8396 && r_type
!= R_ARM_PC24
8397 && r_type
!= R_ARM_CALL
8398 && r_type
!= R_ARM_JUMP24
8399 && r_type
!= R_ARM_PREL31
8400 && r_type
!= R_ARM_PLT32
)
8402 Elf_Internal_Rela outrel
;
8403 bfd_boolean skip
, relocate
;
8405 *unresolved_reloc_p
= FALSE
;
8407 if (sreloc
== NULL
&& globals
->root
.dynamic_sections_created
)
8409 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
8410 ! globals
->use_rel
);
8413 return bfd_reloc_notsupported
;
8419 outrel
.r_addend
= addend
;
8421 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
8423 if (outrel
.r_offset
== (bfd_vma
) -1)
8425 else if (outrel
.r_offset
== (bfd_vma
) -2)
8426 skip
= TRUE
, relocate
= TRUE
;
8427 outrel
.r_offset
+= (input_section
->output_section
->vma
8428 + input_section
->output_offset
);
8431 memset (&outrel
, 0, sizeof outrel
);
8436 || !h
->def_regular
))
8437 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
8442 /* This symbol is local, or marked to become local. */
8443 BFD_ASSERT (r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
);
8444 if (globals
->symbian_p
)
8448 /* On Symbian OS, the data segment and text segement
8449 can be relocated independently. Therefore, we
8450 must indicate the segment to which this
8451 relocation is relative. The BPABI allows us to
8452 use any symbol in the right segment; we just use
8453 the section symbol as it is convenient. (We
8454 cannot use the symbol given by "h" directly as it
8455 will not appear in the dynamic symbol table.)
8457 Note that the dynamic linker ignores the section
8458 symbol value, so we don't subtract osec->vma
8459 from the emitted reloc addend. */
8461 osec
= sym_sec
->output_section
;
8463 osec
= input_section
->output_section
;
8464 symbol
= elf_section_data (osec
)->dynindx
;
8467 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8469 if ((osec
->flags
& SEC_READONLY
) == 0
8470 && htab
->data_index_section
!= NULL
)
8471 osec
= htab
->data_index_section
;
8473 osec
= htab
->text_index_section
;
8474 symbol
= elf_section_data (osec
)->dynindx
;
8476 BFD_ASSERT (symbol
!= 0);
8479 /* On SVR4-ish systems, the dynamic loader cannot
8480 relocate the text and data segments independently,
8481 so the symbol does not matter. */
8483 if (dynreloc_st_type
== STT_GNU_IFUNC
)
8484 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
8485 to the .iplt entry. Instead, every non-call reference
8486 must use an R_ARM_IRELATIVE relocation to obtain the
8487 correct run-time address. */
8488 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_IRELATIVE
);
8490 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
8491 if (globals
->use_rel
)
8494 outrel
.r_addend
+= dynreloc_value
;
8497 elf32_arm_add_dynreloc (output_bfd
, info
, sreloc
, &outrel
);
8499 /* If this reloc is against an external symbol, we do not want to
8500 fiddle with the addend. Otherwise, we need to include the symbol
8501 value so that it becomes an addend for the dynamic reloc. */
8503 return bfd_reloc_ok
;
8505 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8506 contents
, rel
->r_offset
,
8507 dynreloc_value
, (bfd_vma
) 0);
8509 else switch (r_type
)
8512 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
8514 case R_ARM_XPC25
: /* Arm BLX instruction. */
8517 case R_ARM_PC24
: /* Arm B/BL instruction. */
8520 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
8522 if (r_type
== R_ARM_XPC25
)
8524 /* Check for Arm calling Arm function. */
8525 /* FIXME: Should we translate the instruction into a BL
8526 instruction instead ? */
8527 if (branch_type
!= ST_BRANCH_TO_THUMB
)
8528 (*_bfd_error_handler
)
8529 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
8531 h
? h
->root
.root
.string
: "(local)");
8533 else if (r_type
== R_ARM_PC24
)
8535 /* Check for Arm calling Thumb function. */
8536 if (branch_type
== ST_BRANCH_TO_THUMB
)
8538 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
8539 output_bfd
, input_section
,
8540 hit_data
, sym_sec
, rel
->r_offset
,
8541 signed_addend
, value
,
8543 return bfd_reloc_ok
;
8545 return bfd_reloc_dangerous
;
8549 /* Check if a stub has to be inserted because the
8550 destination is too far or we are changing mode. */
8551 if ( r_type
== R_ARM_CALL
8552 || r_type
== R_ARM_JUMP24
8553 || r_type
== R_ARM_PLT32
)
8555 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8556 struct elf32_arm_link_hash_entry
*hash
;
8558 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8559 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8560 st_type
, &branch_type
,
8561 hash
, value
, sym_sec
,
8562 input_bfd
, sym_name
);
8564 if (stub_type
!= arm_stub_none
)
8566 /* The target is out of reach, so redirect the
8567 branch to the local stub for this function. */
8568 stub_entry
= elf32_arm_get_stub_entry (input_section
,
8573 if (stub_entry
!= NULL
)
8574 value
= (stub_entry
->stub_offset
8575 + stub_entry
->stub_sec
->output_offset
8576 + stub_entry
->stub_sec
->output_section
->vma
);
8578 if (plt_offset
!= (bfd_vma
) -1)
8579 *unresolved_reloc_p
= FALSE
;
8584 /* If the call goes through a PLT entry, make sure to
8585 check distance to the right destination address. */
8586 if (plt_offset
!= (bfd_vma
) -1)
8588 value
= (splt
->output_section
->vma
8589 + splt
->output_offset
8591 *unresolved_reloc_p
= FALSE
;
8592 /* The PLT entry is in ARM mode, regardless of the
8594 branch_type
= ST_BRANCH_TO_ARM
;
8599 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
8601 S is the address of the symbol in the relocation.
8602 P is address of the instruction being relocated.
8603 A is the addend (extracted from the instruction) in bytes.
8605 S is held in 'value'.
8606 P is the base address of the section containing the
8607 instruction plus the offset of the reloc into that
8609 (input_section->output_section->vma +
8610 input_section->output_offset +
8612 A is the addend, converted into bytes, ie:
8615 Note: None of these operations have knowledge of the pipeline
8616 size of the processor, thus it is up to the assembler to
8617 encode this information into the addend. */
8618 value
-= (input_section
->output_section
->vma
8619 + input_section
->output_offset
);
8620 value
-= rel
->r_offset
;
8621 if (globals
->use_rel
)
8622 value
+= (signed_addend
<< howto
->size
);
8624 /* RELA addends do not have to be adjusted by howto->size. */
8625 value
+= signed_addend
;
8627 signed_addend
= value
;
8628 signed_addend
>>= howto
->rightshift
;
8630 /* A branch to an undefined weak symbol is turned into a jump to
8631 the next instruction unless a PLT entry will be created.
8632 Do the same for local undefined symbols (but not for STN_UNDEF).
8633 The jump to the next instruction is optimized as a NOP depending
8634 on the architecture. */
8635 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
8636 && plt_offset
== (bfd_vma
) -1)
8637 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sym_sec
))
8639 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000);
8641 if (arch_has_arm_nop (globals
))
8642 value
|= 0x0320f000;
8644 value
|= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
8648 /* Perform a signed range check. */
8649 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
8650 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
8651 return bfd_reloc_overflow
;
8653 addend
= (value
& 2);
8655 value
= (signed_addend
& howto
->dst_mask
)
8656 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
8658 if (r_type
== R_ARM_CALL
)
8660 /* Set the H bit in the BLX instruction. */
8661 if (branch_type
== ST_BRANCH_TO_THUMB
)
8666 value
&= ~(bfd_vma
)(1 << 24);
8669 /* Select the correct instruction (BL or BLX). */
8670 /* Only if we are not handling a BL to a stub. In this
8671 case, mode switching is performed by the stub. */
8672 if (branch_type
== ST_BRANCH_TO_THUMB
&& !stub_entry
)
8674 else if (stub_entry
|| branch_type
!= ST_BRANCH_UNKNOWN
)
8676 value
&= ~(bfd_vma
)(1 << 28);
8686 if (branch_type
== ST_BRANCH_TO_THUMB
)
8690 case R_ARM_ABS32_NOI
:
8696 if (branch_type
== ST_BRANCH_TO_THUMB
)
8698 value
-= (input_section
->output_section
->vma
8699 + input_section
->output_offset
+ rel
->r_offset
);
8702 case R_ARM_REL32_NOI
:
8704 value
-= (input_section
->output_section
->vma
8705 + input_section
->output_offset
+ rel
->r_offset
);
8709 value
-= (input_section
->output_section
->vma
8710 + input_section
->output_offset
+ rel
->r_offset
);
8711 value
+= signed_addend
;
8712 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
8714 /* Check for overflow. */
8715 if ((value
^ (value
>> 1)) & (1 << 30))
8716 return bfd_reloc_overflow
;
8718 value
&= 0x7fffffff;
8719 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
8720 if (branch_type
== ST_BRANCH_TO_THUMB
)
8725 bfd_put_32 (input_bfd
, value
, hit_data
);
8726 return bfd_reloc_ok
;
8729 /* PR 16202: Refectch the addend using the correct size. */
8730 if (globals
->use_rel
)
8731 addend
= bfd_get_8 (input_bfd
, hit_data
);
8734 /* There is no way to tell whether the user intended to use a signed or
8735 unsigned addend. When checking for overflow we accept either,
8736 as specified by the AAELF. */
8737 if ((long) value
> 0xff || (long) value
< -0x80)
8738 return bfd_reloc_overflow
;
8740 bfd_put_8 (input_bfd
, value
, hit_data
);
8741 return bfd_reloc_ok
;
8744 /* PR 16202: Refectch the addend using the correct size. */
8745 if (globals
->use_rel
)
8746 addend
= bfd_get_16 (input_bfd
, hit_data
);
8749 /* See comment for R_ARM_ABS8. */
8750 if ((long) value
> 0xffff || (long) value
< -0x8000)
8751 return bfd_reloc_overflow
;
8753 bfd_put_16 (input_bfd
, value
, hit_data
);
8754 return bfd_reloc_ok
;
8756 case R_ARM_THM_ABS5
:
8757 /* Support ldr and str instructions for the thumb. */
8758 if (globals
->use_rel
)
8760 /* Need to refetch addend. */
8761 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
8762 /* ??? Need to determine shift amount from operand size. */
8763 addend
>>= howto
->rightshift
;
8767 /* ??? Isn't value unsigned? */
8768 if ((long) value
> 0x1f || (long) value
< -0x10)
8769 return bfd_reloc_overflow
;
8771 /* ??? Value needs to be properly shifted into place first. */
8772 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
8773 bfd_put_16 (input_bfd
, value
, hit_data
);
8774 return bfd_reloc_ok
;
8776 case R_ARM_THM_ALU_PREL_11_0
:
8777 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
8780 bfd_signed_vma relocation
;
8782 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8783 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8785 if (globals
->use_rel
)
8787 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
8788 | ((insn
& (1 << 26)) >> 15);
8789 if (insn
& 0xf00000)
8790 signed_addend
= -signed_addend
;
8793 relocation
= value
+ signed_addend
;
8794 relocation
-= Pa (input_section
->output_section
->vma
8795 + input_section
->output_offset
8798 value
= abs (relocation
);
8800 if (value
>= 0x1000)
8801 return bfd_reloc_overflow
;
8803 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
8804 | ((value
& 0x700) << 4)
8805 | ((value
& 0x800) << 15);
8809 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8810 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8812 return bfd_reloc_ok
;
8816 /* PR 10073: This reloc is not generated by the GNU toolchain,
8817 but it is supported for compatibility with third party libraries
8818 generated by other compilers, specifically the ARM/IAR. */
8821 bfd_signed_vma relocation
;
8823 insn
= bfd_get_16 (input_bfd
, hit_data
);
8825 if (globals
->use_rel
)
8826 addend
= ((((insn
& 0x00ff) << 2) + 4) & 0x3ff) -4;
8828 relocation
= value
+ addend
;
8829 relocation
-= Pa (input_section
->output_section
->vma
8830 + input_section
->output_offset
8833 value
= abs (relocation
);
8835 /* We do not check for overflow of this reloc. Although strictly
8836 speaking this is incorrect, it appears to be necessary in order
8837 to work with IAR generated relocs. Since GCC and GAS do not
8838 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
8839 a problem for them. */
8842 insn
= (insn
& 0xff00) | (value
>> 2);
8844 bfd_put_16 (input_bfd
, insn
, hit_data
);
8846 return bfd_reloc_ok
;
8849 case R_ARM_THM_PC12
:
8850 /* Corresponds to: ldr.w reg, [pc, #offset]. */
8853 bfd_signed_vma relocation
;
8855 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8856 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8858 if (globals
->use_rel
)
8860 signed_addend
= insn
& 0xfff;
8861 if (!(insn
& (1 << 23)))
8862 signed_addend
= -signed_addend
;
8865 relocation
= value
+ signed_addend
;
8866 relocation
-= Pa (input_section
->output_section
->vma
8867 + input_section
->output_offset
8870 value
= abs (relocation
);
8872 if (value
>= 0x1000)
8873 return bfd_reloc_overflow
;
8875 insn
= (insn
& 0xff7ff000) | value
;
8876 if (relocation
>= 0)
8879 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8880 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8882 return bfd_reloc_ok
;
8885 case R_ARM_THM_XPC22
:
8886 case R_ARM_THM_CALL
:
8887 case R_ARM_THM_JUMP24
:
8888 /* Thumb BL (branch long instruction). */
8892 bfd_boolean overflow
= FALSE
;
8893 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
8894 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
8895 bfd_signed_vma reloc_signed_max
;
8896 bfd_signed_vma reloc_signed_min
;
8898 bfd_signed_vma signed_check
;
8900 const int thumb2
= using_thumb2 (globals
);
8902 /* A branch to an undefined weak symbol is turned into a jump to
8903 the next instruction unless a PLT entry will be created.
8904 The jump to the next instruction is optimized as a NOP.W for
8905 Thumb-2 enabled architectures. */
8906 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
8907 && plt_offset
== (bfd_vma
) -1)
8909 if (arch_has_thumb2_nop (globals
))
8911 bfd_put_16 (input_bfd
, 0xf3af, hit_data
);
8912 bfd_put_16 (input_bfd
, 0x8000, hit_data
+ 2);
8916 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
8917 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
8919 return bfd_reloc_ok
;
8922 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
8923 with Thumb-1) involving the J1 and J2 bits. */
8924 if (globals
->use_rel
)
8926 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
8927 bfd_vma upper
= upper_insn
& 0x3ff;
8928 bfd_vma lower
= lower_insn
& 0x7ff;
8929 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
8930 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
8931 bfd_vma i1
= j1
^ s
? 0 : 1;
8932 bfd_vma i2
= j2
^ s
? 0 : 1;
8934 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
8936 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
8938 signed_addend
= addend
;
8941 if (r_type
== R_ARM_THM_XPC22
)
8943 /* Check for Thumb to Thumb call. */
8944 /* FIXME: Should we translate the instruction into a BL
8945 instruction instead ? */
8946 if (branch_type
== ST_BRANCH_TO_THUMB
)
8947 (*_bfd_error_handler
)
8948 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
8950 h
? h
->root
.root
.string
: "(local)");
8954 /* If it is not a call to Thumb, assume call to Arm.
8955 If it is a call relative to a section name, then it is not a
8956 function call at all, but rather a long jump. Calls through
8957 the PLT do not require stubs. */
8958 if (branch_type
== ST_BRANCH_TO_ARM
&& plt_offset
== (bfd_vma
) -1)
8960 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
8962 /* Convert BL to BLX. */
8963 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8965 else if (( r_type
!= R_ARM_THM_CALL
)
8966 && (r_type
!= R_ARM_THM_JUMP24
))
8968 if (elf32_thumb_to_arm_stub
8969 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
8970 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
8972 return bfd_reloc_ok
;
8974 return bfd_reloc_dangerous
;
8977 else if (branch_type
== ST_BRANCH_TO_THUMB
8979 && r_type
== R_ARM_THM_CALL
)
8981 /* Make sure this is a BL. */
8982 lower_insn
|= 0x1800;
8986 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8987 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
8989 /* Check if a stub has to be inserted because the destination
8991 struct elf32_arm_stub_hash_entry
*stub_entry
;
8992 struct elf32_arm_link_hash_entry
*hash
;
8994 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8996 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8997 st_type
, &branch_type
,
8998 hash
, value
, sym_sec
,
8999 input_bfd
, sym_name
);
9001 if (stub_type
!= arm_stub_none
)
9003 /* The target is out of reach or we are changing modes, so
9004 redirect the branch to the local stub for this
9006 stub_entry
= elf32_arm_get_stub_entry (input_section
,
9010 if (stub_entry
!= NULL
)
9012 value
= (stub_entry
->stub_offset
9013 + stub_entry
->stub_sec
->output_offset
9014 + stub_entry
->stub_sec
->output_section
->vma
);
9016 if (plt_offset
!= (bfd_vma
) -1)
9017 *unresolved_reloc_p
= FALSE
;
9020 /* If this call becomes a call to Arm, force BLX. */
9021 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
9024 && !arm_stub_is_thumb (stub_entry
->stub_type
))
9025 || branch_type
!= ST_BRANCH_TO_THUMB
)
9026 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
9031 /* Handle calls via the PLT. */
9032 if (stub_type
== arm_stub_none
&& plt_offset
!= (bfd_vma
) -1)
9034 value
= (splt
->output_section
->vma
9035 + splt
->output_offset
9038 if (globals
->use_blx
9039 && r_type
== R_ARM_THM_CALL
9040 && ! using_thumb_only (globals
))
9042 /* If the Thumb BLX instruction is available, convert
9043 the BL to a BLX instruction to call the ARM-mode
9045 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
9046 branch_type
= ST_BRANCH_TO_ARM
;
9050 if (! using_thumb_only (globals
))
9051 /* Target the Thumb stub before the ARM PLT entry. */
9052 value
-= PLT_THUMB_STUB_SIZE
;
9053 branch_type
= ST_BRANCH_TO_THUMB
;
9055 *unresolved_reloc_p
= FALSE
;
9058 relocation
= value
+ signed_addend
;
9060 relocation
-= (input_section
->output_section
->vma
9061 + input_section
->output_offset
9064 check
= relocation
>> howto
->rightshift
;
9066 /* If this is a signed value, the rightshift just dropped
9067 leading 1 bits (assuming twos complement). */
9068 if ((bfd_signed_vma
) relocation
>= 0)
9069 signed_check
= check
;
9071 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
9073 /* Calculate the permissable maximum and minimum values for
9074 this relocation according to whether we're relocating for
9076 bitsize
= howto
->bitsize
;
9079 reloc_signed_max
= (1 << (bitsize
- 1)) - 1;
9080 reloc_signed_min
= ~reloc_signed_max
;
9082 /* Assumes two's complement. */
9083 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
9086 if ((lower_insn
& 0x5000) == 0x4000)
9087 /* For a BLX instruction, make sure that the relocation is rounded up
9088 to a word boundary. This follows the semantics of the instruction
9089 which specifies that bit 1 of the target address will come from bit
9090 1 of the base address. */
9091 relocation
= (relocation
+ 2) & ~ 3;
9093 /* Put RELOCATION back into the insn. Assumes two's complement.
9094 We use the Thumb-2 encoding, which is safe even if dealing with
9095 a Thumb-1 instruction by virtue of our overflow check above. */
9096 reloc_sign
= (signed_check
< 0) ? 1 : 0;
9097 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
9098 | ((relocation
>> 12) & 0x3ff)
9099 | (reloc_sign
<< 10);
9100 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
9101 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
9102 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
9103 | ((relocation
>> 1) & 0x7ff);
9105 /* Put the relocated value back in the object file: */
9106 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9107 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9109 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
9113 case R_ARM_THM_JUMP19
:
9114 /* Thumb32 conditional branch instruction. */
9117 bfd_boolean overflow
= FALSE
;
9118 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
9119 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
9120 bfd_signed_vma reloc_signed_max
= 0xffffe;
9121 bfd_signed_vma reloc_signed_min
= -0x100000;
9122 bfd_signed_vma signed_check
;
9124 /* Need to refetch the addend, reconstruct the top three bits,
9125 and squish the two 11 bit pieces together. */
9126 if (globals
->use_rel
)
9128 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
9129 bfd_vma upper
= (upper_insn
& 0x003f);
9130 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
9131 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
9132 bfd_vma lower
= (lower_insn
& 0x07ff);
9137 upper
-= 0x0100; /* Sign extend. */
9139 addend
= (upper
<< 12) | (lower
<< 1);
9140 signed_addend
= addend
;
9143 /* Handle calls via the PLT. */
9144 if (plt_offset
!= (bfd_vma
) -1)
9146 value
= (splt
->output_section
->vma
9147 + splt
->output_offset
9149 /* Target the Thumb stub before the ARM PLT entry. */
9150 value
-= PLT_THUMB_STUB_SIZE
;
9151 *unresolved_reloc_p
= FALSE
;
9154 /* ??? Should handle interworking? GCC might someday try to
9155 use this for tail calls. */
9157 relocation
= value
+ signed_addend
;
9158 relocation
-= (input_section
->output_section
->vma
9159 + input_section
->output_offset
9161 signed_check
= (bfd_signed_vma
) relocation
;
9163 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
9166 /* Put RELOCATION back into the insn. */
9168 bfd_vma S
= (relocation
& 0x00100000) >> 20;
9169 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
9170 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
9171 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
9172 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
9174 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
9175 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
9178 /* Put the relocated value back in the object file: */
9179 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9180 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9182 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
9185 case R_ARM_THM_JUMP11
:
9186 case R_ARM_THM_JUMP8
:
9187 case R_ARM_THM_JUMP6
:
9188 /* Thumb B (branch) instruction). */
9190 bfd_signed_vma relocation
;
9191 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
9192 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
9193 bfd_signed_vma signed_check
;
9195 /* CZB cannot jump backward. */
9196 if (r_type
== R_ARM_THM_JUMP6
)
9197 reloc_signed_min
= 0;
9199 if (globals
->use_rel
)
9201 /* Need to refetch addend. */
9202 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
9203 if (addend
& ((howto
->src_mask
+ 1) >> 1))
9206 signed_addend
&= ~ howto
->src_mask
;
9207 signed_addend
|= addend
;
9210 signed_addend
= addend
;
9211 /* The value in the insn has been right shifted. We need to
9212 undo this, so that we can perform the address calculation
9213 in terms of bytes. */
9214 signed_addend
<<= howto
->rightshift
;
9216 relocation
= value
+ signed_addend
;
9218 relocation
-= (input_section
->output_section
->vma
9219 + input_section
->output_offset
9222 relocation
>>= howto
->rightshift
;
9223 signed_check
= relocation
;
9225 if (r_type
== R_ARM_THM_JUMP6
)
9226 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
9228 relocation
&= howto
->dst_mask
;
9229 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
9231 bfd_put_16 (input_bfd
, relocation
, hit_data
);
9233 /* Assumes two's complement. */
9234 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
9235 return bfd_reloc_overflow
;
9237 return bfd_reloc_ok
;
9240 case R_ARM_ALU_PCREL7_0
:
9241 case R_ARM_ALU_PCREL15_8
:
9242 case R_ARM_ALU_PCREL23_15
:
9247 insn
= bfd_get_32 (input_bfd
, hit_data
);
9248 if (globals
->use_rel
)
9250 /* Extract the addend. */
9251 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
9252 signed_addend
= addend
;
9254 relocation
= value
+ signed_addend
;
9256 relocation
-= (input_section
->output_section
->vma
9257 + input_section
->output_offset
9259 insn
= (insn
& ~0xfff)
9260 | ((howto
->bitpos
<< 7) & 0xf00)
9261 | ((relocation
>> howto
->bitpos
) & 0xff);
9262 bfd_put_32 (input_bfd
, value
, hit_data
);
9264 return bfd_reloc_ok
;
9266 case R_ARM_GNU_VTINHERIT
:
9267 case R_ARM_GNU_VTENTRY
:
9268 return bfd_reloc_ok
;
9270 case R_ARM_GOTOFF32
:
9271 /* Relocation is relative to the start of the
9272 global offset table. */
9274 BFD_ASSERT (sgot
!= NULL
);
9276 return bfd_reloc_notsupported
;
9278 /* If we are addressing a Thumb function, we need to adjust the
9279 address by one, so that attempts to call the function pointer will
9280 correctly interpret it as Thumb code. */
9281 if (branch_type
== ST_BRANCH_TO_THUMB
)
9284 /* Note that sgot->output_offset is not involved in this
9285 calculation. We always want the start of .got. If we
9286 define _GLOBAL_OFFSET_TABLE in a different way, as is
9287 permitted by the ABI, we might have to change this
9289 value
-= sgot
->output_section
->vma
;
9290 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9291 contents
, rel
->r_offset
, value
,
9295 /* Use global offset table as symbol value. */
9296 BFD_ASSERT (sgot
!= NULL
);
9299 return bfd_reloc_notsupported
;
9301 *unresolved_reloc_p
= FALSE
;
9302 value
= sgot
->output_section
->vma
;
9303 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9304 contents
, rel
->r_offset
, value
,
9308 case R_ARM_GOT_PREL
:
9309 /* Relocation is to the entry for this symbol in the
9310 global offset table. */
9312 return bfd_reloc_notsupported
;
9314 if (dynreloc_st_type
== STT_GNU_IFUNC
9315 && plt_offset
!= (bfd_vma
) -1
9316 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
9318 /* We have a relocation against a locally-binding STT_GNU_IFUNC
9319 symbol, and the relocation resolves directly to the runtime
9320 target rather than to the .iplt entry. This means that any
9321 .got entry would be the same value as the .igot.plt entry,
9322 so there's no point creating both. */
9323 sgot
= globals
->root
.igotplt
;
9324 value
= sgot
->output_offset
+ gotplt_offset
;
9330 off
= h
->got
.offset
;
9331 BFD_ASSERT (off
!= (bfd_vma
) -1);
9334 /* We have already processsed one GOT relocation against
9337 if (globals
->root
.dynamic_sections_created
9338 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
9339 *unresolved_reloc_p
= FALSE
;
9343 Elf_Internal_Rela outrel
;
9345 if (h
->dynindx
!= -1 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
9347 /* If the symbol doesn't resolve locally in a static
9348 object, we have an undefined reference. If the
9349 symbol doesn't resolve locally in a dynamic object,
9350 it should be resolved by the dynamic linker. */
9351 if (globals
->root
.dynamic_sections_created
)
9353 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
9354 *unresolved_reloc_p
= FALSE
;
9358 outrel
.r_addend
= 0;
9362 if (dynreloc_st_type
== STT_GNU_IFUNC
)
9363 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9364 else if (info
->shared
&&
9365 (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9366 || h
->root
.type
!= bfd_link_hash_undefweak
))
9367 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
9370 outrel
.r_addend
= dynreloc_value
;
9373 /* The GOT entry is initialized to zero by default.
9374 See if we should install a different value. */
9375 if (outrel
.r_addend
!= 0
9376 && (outrel
.r_info
== 0 || globals
->use_rel
))
9378 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9379 sgot
->contents
+ off
);
9380 outrel
.r_addend
= 0;
9383 if (outrel
.r_info
!= 0)
9385 outrel
.r_offset
= (sgot
->output_section
->vma
9386 + sgot
->output_offset
9388 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9392 value
= sgot
->output_offset
+ off
;
9398 BFD_ASSERT (local_got_offsets
!= NULL
&&
9399 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
9401 off
= local_got_offsets
[r_symndx
];
9403 /* The offset must always be a multiple of 4. We use the
9404 least significant bit to record whether we have already
9405 generated the necessary reloc. */
9410 if (globals
->use_rel
)
9411 bfd_put_32 (output_bfd
, dynreloc_value
, sgot
->contents
+ off
);
9413 if (info
->shared
|| dynreloc_st_type
== STT_GNU_IFUNC
)
9415 Elf_Internal_Rela outrel
;
9417 outrel
.r_addend
= addend
+ dynreloc_value
;
9418 outrel
.r_offset
= (sgot
->output_section
->vma
9419 + sgot
->output_offset
9421 if (dynreloc_st_type
== STT_GNU_IFUNC
)
9422 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9424 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
9425 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9428 local_got_offsets
[r_symndx
] |= 1;
9431 value
= sgot
->output_offset
+ off
;
9433 if (r_type
!= R_ARM_GOT32
)
9434 value
+= sgot
->output_section
->vma
;
9436 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9437 contents
, rel
->r_offset
, value
,
9440 case R_ARM_TLS_LDO32
:
9441 value
= value
- dtpoff_base (info
);
9443 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9444 contents
, rel
->r_offset
, value
,
9447 case R_ARM_TLS_LDM32
:
9454 off
= globals
->tls_ldm_got
.offset
;
9460 /* If we don't know the module number, create a relocation
9464 Elf_Internal_Rela outrel
;
9466 if (srelgot
== NULL
)
9469 outrel
.r_addend
= 0;
9470 outrel
.r_offset
= (sgot
->output_section
->vma
9471 + sgot
->output_offset
+ off
);
9472 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
9474 if (globals
->use_rel
)
9475 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9476 sgot
->contents
+ off
);
9478 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9481 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ off
);
9483 globals
->tls_ldm_got
.offset
|= 1;
9486 value
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
9487 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
9489 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9490 contents
, rel
->r_offset
, value
,
9494 case R_ARM_TLS_CALL
:
9495 case R_ARM_THM_TLS_CALL
:
9496 case R_ARM_TLS_GD32
:
9497 case R_ARM_TLS_IE32
:
9498 case R_ARM_TLS_GOTDESC
:
9499 case R_ARM_TLS_DESCSEQ
:
9500 case R_ARM_THM_TLS_DESCSEQ
:
9502 bfd_vma off
, offplt
;
9506 BFD_ASSERT (sgot
!= NULL
);
9511 dyn
= globals
->root
.dynamic_sections_created
;
9512 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
9514 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9516 *unresolved_reloc_p
= FALSE
;
9519 off
= h
->got
.offset
;
9520 offplt
= elf32_arm_hash_entry (h
)->tlsdesc_got
;
9521 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
9525 BFD_ASSERT (local_got_offsets
!= NULL
);
9526 off
= local_got_offsets
[r_symndx
];
9527 offplt
= local_tlsdesc_gotents
[r_symndx
];
9528 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
9531 /* Linker relaxations happens from one of the
9532 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
9533 if (ELF32_R_TYPE(rel
->r_info
) != r_type
)
9534 tls_type
= GOT_TLS_IE
;
9536 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
9542 bfd_boolean need_relocs
= FALSE
;
9543 Elf_Internal_Rela outrel
;
9546 /* The GOT entries have not been initialized yet. Do it
9547 now, and emit any relocations. If both an IE GOT and a
9548 GD GOT are necessary, we emit the GD first. */
9550 if ((info
->shared
|| indx
!= 0)
9552 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9553 || h
->root
.type
!= bfd_link_hash_undefweak
))
9556 BFD_ASSERT (srelgot
!= NULL
);
9559 if (tls_type
& GOT_TLS_GDESC
)
9563 /* We should have relaxed, unless this is an undefined
9565 BFD_ASSERT ((h
&& (h
->root
.type
== bfd_link_hash_undefweak
))
9567 BFD_ASSERT (globals
->sgotplt_jump_table_size
+ offplt
+ 8
9568 <= globals
->root
.sgotplt
->size
);
9570 outrel
.r_addend
= 0;
9571 outrel
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
9572 + globals
->root
.sgotplt
->output_offset
9574 + globals
->sgotplt_jump_table_size
);
9576 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DESC
);
9577 sreloc
= globals
->root
.srelplt
;
9578 loc
= sreloc
->contents
;
9579 loc
+= globals
->next_tls_desc_index
++ * RELOC_SIZE (globals
);
9580 BFD_ASSERT (loc
+ RELOC_SIZE (globals
)
9581 <= sreloc
->contents
+ sreloc
->size
);
9583 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
9585 /* For globals, the first word in the relocation gets
9586 the relocation index and the top bit set, or zero,
9587 if we're binding now. For locals, it gets the
9588 symbol's offset in the tls section. */
9589 bfd_put_32 (output_bfd
,
9590 !h
? value
- elf_hash_table (info
)->tls_sec
->vma
9591 : info
->flags
& DF_BIND_NOW
? 0
9592 : 0x80000000 | ELF32_R_SYM (outrel
.r_info
),
9593 globals
->root
.sgotplt
->contents
+ offplt
9594 + globals
->sgotplt_jump_table_size
);
9596 /* Second word in the relocation is always zero. */
9597 bfd_put_32 (output_bfd
, 0,
9598 globals
->root
.sgotplt
->contents
+ offplt
9599 + globals
->sgotplt_jump_table_size
+ 4);
9601 if (tls_type
& GOT_TLS_GD
)
9605 outrel
.r_addend
= 0;
9606 outrel
.r_offset
= (sgot
->output_section
->vma
9607 + sgot
->output_offset
9609 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
9611 if (globals
->use_rel
)
9612 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9613 sgot
->contents
+ cur_off
);
9615 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9618 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9619 sgot
->contents
+ cur_off
+ 4);
9622 outrel
.r_addend
= 0;
9623 outrel
.r_info
= ELF32_R_INFO (indx
,
9624 R_ARM_TLS_DTPOFF32
);
9625 outrel
.r_offset
+= 4;
9627 if (globals
->use_rel
)
9628 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9629 sgot
->contents
+ cur_off
+ 4);
9631 elf32_arm_add_dynreloc (output_bfd
, info
,
9637 /* If we are not emitting relocations for a
9638 general dynamic reference, then we must be in a
9639 static link or an executable link with the
9640 symbol binding locally. Mark it as belonging
9641 to module 1, the executable. */
9642 bfd_put_32 (output_bfd
, 1,
9643 sgot
->contents
+ cur_off
);
9644 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9645 sgot
->contents
+ cur_off
+ 4);
9651 if (tls_type
& GOT_TLS_IE
)
9656 outrel
.r_addend
= value
- dtpoff_base (info
);
9658 outrel
.r_addend
= 0;
9659 outrel
.r_offset
= (sgot
->output_section
->vma
9660 + sgot
->output_offset
9662 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
9664 if (globals
->use_rel
)
9665 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9666 sgot
->contents
+ cur_off
);
9668 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9671 bfd_put_32 (output_bfd
, tpoff (info
, value
),
9672 sgot
->contents
+ cur_off
);
9679 local_got_offsets
[r_symndx
] |= 1;
9682 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
9684 else if (tls_type
& GOT_TLS_GDESC
)
9687 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
9688 || ELF32_R_TYPE(rel
->r_info
) == R_ARM_THM_TLS_CALL
)
9690 bfd_signed_vma offset
;
9691 /* TLS stubs are arm mode. The original symbol is a
9692 data object, so branch_type is bogus. */
9693 branch_type
= ST_BRANCH_TO_ARM
;
9694 enum elf32_arm_stub_type stub_type
9695 = arm_type_of_stub (info
, input_section
, rel
,
9696 st_type
, &branch_type
,
9697 (struct elf32_arm_link_hash_entry
*)h
,
9698 globals
->tls_trampoline
, globals
->root
.splt
,
9699 input_bfd
, sym_name
);
9701 if (stub_type
!= arm_stub_none
)
9703 struct elf32_arm_stub_hash_entry
*stub_entry
9704 = elf32_arm_get_stub_entry
9705 (input_section
, globals
->root
.splt
, 0, rel
,
9706 globals
, stub_type
);
9707 offset
= (stub_entry
->stub_offset
9708 + stub_entry
->stub_sec
->output_offset
9709 + stub_entry
->stub_sec
->output_section
->vma
);
9712 offset
= (globals
->root
.splt
->output_section
->vma
9713 + globals
->root
.splt
->output_offset
9714 + globals
->tls_trampoline
);
9716 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
)
9720 offset
-= (input_section
->output_section
->vma
9721 + input_section
->output_offset
9722 + rel
->r_offset
+ 8);
9726 value
= inst
| (globals
->use_blx
? 0xfa000000 : 0xeb000000);
9730 /* Thumb blx encodes the offset in a complicated
9732 unsigned upper_insn
, lower_insn
;
9735 offset
-= (input_section
->output_section
->vma
9736 + input_section
->output_offset
9737 + rel
->r_offset
+ 4);
9739 if (stub_type
!= arm_stub_none
9740 && arm_stub_is_thumb (stub_type
))
9742 lower_insn
= 0xd000;
9746 lower_insn
= 0xc000;
9747 /* Round up the offset to a word boundary. */
9748 offset
= (offset
+ 2) & ~2;
9752 upper_insn
= (0xf000
9753 | ((offset
>> 12) & 0x3ff)
9755 lower_insn
|= (((!((offset
>> 23) & 1)) ^ neg
) << 13)
9756 | (((!((offset
>> 22) & 1)) ^ neg
) << 11)
9757 | ((offset
>> 1) & 0x7ff);
9758 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9759 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9760 return bfd_reloc_ok
;
9763 /* These relocations needs special care, as besides the fact
9764 they point somewhere in .gotplt, the addend must be
9765 adjusted accordingly depending on the type of instruction
9767 else if ((r_type
== R_ARM_TLS_GOTDESC
) && (tls_type
& GOT_TLS_GDESC
))
9769 unsigned long data
, insn
;
9772 data
= bfd_get_32 (input_bfd
, hit_data
);
9778 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
- data
);
9779 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
9781 | bfd_get_16 (input_bfd
,
9782 contents
+ rel
->r_offset
- data
+ 2);
9783 if ((insn
& 0xf800c000) == 0xf000c000)
9786 else if ((insn
& 0xffffff00) == 0x4400)
9791 (*_bfd_error_handler
)
9792 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' referenced by TLS_GOTDESC"),
9793 input_bfd
, input_section
,
9794 (unsigned long)rel
->r_offset
, insn
);
9795 return bfd_reloc_notsupported
;
9800 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- data
);
9805 case 0xfa: /* blx */
9809 case 0xe0: /* add */
9814 (*_bfd_error_handler
)
9815 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' referenced by TLS_GOTDESC"),
9816 input_bfd
, input_section
,
9817 (unsigned long)rel
->r_offset
, insn
);
9818 return bfd_reloc_notsupported
;
9822 value
+= ((globals
->root
.sgotplt
->output_section
->vma
9823 + globals
->root
.sgotplt
->output_offset
+ off
)
9824 - (input_section
->output_section
->vma
9825 + input_section
->output_offset
9827 + globals
->sgotplt_jump_table_size
);
9830 value
= ((globals
->root
.sgot
->output_section
->vma
9831 + globals
->root
.sgot
->output_offset
+ off
)
9832 - (input_section
->output_section
->vma
9833 + input_section
->output_offset
+ rel
->r_offset
));
9835 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9836 contents
, rel
->r_offset
, value
,
9840 case R_ARM_TLS_LE32
:
9841 if (info
->shared
&& !info
->pie
)
9843 (*_bfd_error_handler
)
9844 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
9845 input_bfd
, input_section
,
9846 (long) rel
->r_offset
, howto
->name
);
9847 return bfd_reloc_notsupported
;
9850 value
= tpoff (info
, value
);
9852 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9853 contents
, rel
->r_offset
, value
,
9857 if (globals
->fix_v4bx
)
9859 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9861 /* Ensure that we have a BX instruction. */
9862 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
9864 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
9866 /* Branch to veneer. */
9868 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
9869 glue_addr
-= input_section
->output_section
->vma
9870 + input_section
->output_offset
9871 + rel
->r_offset
+ 8;
9872 insn
= (insn
& 0xf0000000) | 0x0a000000
9873 | ((glue_addr
>> 2) & 0x00ffffff);
9877 /* Preserve Rm (lowest four bits) and the condition code
9878 (highest four bits). Other bits encode MOV PC,Rm. */
9879 insn
= (insn
& 0xf000000f) | 0x01a0f000;
9882 bfd_put_32 (input_bfd
, insn
, hit_data
);
9884 return bfd_reloc_ok
;
9886 case R_ARM_MOVW_ABS_NC
:
9887 case R_ARM_MOVT_ABS
:
9888 case R_ARM_MOVW_PREL_NC
:
9889 case R_ARM_MOVT_PREL
:
9890 /* Until we properly support segment-base-relative addressing then
9891 we assume the segment base to be zero, as for the group relocations.
9892 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
9893 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
9894 case R_ARM_MOVW_BREL_NC
:
9895 case R_ARM_MOVW_BREL
:
9896 case R_ARM_MOVT_BREL
:
9898 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9900 if (globals
->use_rel
)
9902 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
9903 signed_addend
= (addend
^ 0x8000) - 0x8000;
9906 value
+= signed_addend
;
9908 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
9909 value
-= (input_section
->output_section
->vma
9910 + input_section
->output_offset
+ rel
->r_offset
);
9912 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
9913 return bfd_reloc_overflow
;
9915 if (branch_type
== ST_BRANCH_TO_THUMB
)
9918 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
9919 || r_type
== R_ARM_MOVT_BREL
)
9923 insn
|= value
& 0xfff;
9924 insn
|= (value
& 0xf000) << 4;
9925 bfd_put_32 (input_bfd
, insn
, hit_data
);
9927 return bfd_reloc_ok
;
9929 case R_ARM_THM_MOVW_ABS_NC
:
9930 case R_ARM_THM_MOVT_ABS
:
9931 case R_ARM_THM_MOVW_PREL_NC
:
9932 case R_ARM_THM_MOVT_PREL
:
9933 /* Until we properly support segment-base-relative addressing then
9934 we assume the segment base to be zero, as for the above relocations.
9935 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
9936 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
9937 as R_ARM_THM_MOVT_ABS. */
9938 case R_ARM_THM_MOVW_BREL_NC
:
9939 case R_ARM_THM_MOVW_BREL
:
9940 case R_ARM_THM_MOVT_BREL
:
9944 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
9945 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
9947 if (globals
->use_rel
)
9949 addend
= ((insn
>> 4) & 0xf000)
9950 | ((insn
>> 15) & 0x0800)
9951 | ((insn
>> 4) & 0x0700)
9953 signed_addend
= (addend
^ 0x8000) - 0x8000;
9956 value
+= signed_addend
;
9958 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
9959 value
-= (input_section
->output_section
->vma
9960 + input_section
->output_offset
+ rel
->r_offset
);
9962 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
9963 return bfd_reloc_overflow
;
9965 if (branch_type
== ST_BRANCH_TO_THUMB
)
9968 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
9969 || r_type
== R_ARM_THM_MOVT_BREL
)
9973 insn
|= (value
& 0xf000) << 4;
9974 insn
|= (value
& 0x0800) << 15;
9975 insn
|= (value
& 0x0700) << 4;
9976 insn
|= (value
& 0x00ff);
9978 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
9979 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
9981 return bfd_reloc_ok
;
9983 case R_ARM_ALU_PC_G0_NC
:
9984 case R_ARM_ALU_PC_G1_NC
:
9985 case R_ARM_ALU_PC_G0
:
9986 case R_ARM_ALU_PC_G1
:
9987 case R_ARM_ALU_PC_G2
:
9988 case R_ARM_ALU_SB_G0_NC
:
9989 case R_ARM_ALU_SB_G1_NC
:
9990 case R_ARM_ALU_SB_G0
:
9991 case R_ARM_ALU_SB_G1
:
9992 case R_ARM_ALU_SB_G2
:
9994 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9995 bfd_vma pc
= input_section
->output_section
->vma
9996 + input_section
->output_offset
+ rel
->r_offset
;
9997 /* sb is the origin of the *segment* containing the symbol. */
9998 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10001 bfd_signed_vma signed_value
;
10004 /* Determine which group of bits to select. */
10007 case R_ARM_ALU_PC_G0_NC
:
10008 case R_ARM_ALU_PC_G0
:
10009 case R_ARM_ALU_SB_G0_NC
:
10010 case R_ARM_ALU_SB_G0
:
10014 case R_ARM_ALU_PC_G1_NC
:
10015 case R_ARM_ALU_PC_G1
:
10016 case R_ARM_ALU_SB_G1_NC
:
10017 case R_ARM_ALU_SB_G1
:
10021 case R_ARM_ALU_PC_G2
:
10022 case R_ARM_ALU_SB_G2
:
10030 /* If REL, extract the addend from the insn. If RELA, it will
10031 have already been fetched for us. */
10032 if (globals
->use_rel
)
10035 bfd_vma constant
= insn
& 0xff;
10036 bfd_vma rotation
= (insn
& 0xf00) >> 8;
10039 signed_addend
= constant
;
10042 /* Compensate for the fact that in the instruction, the
10043 rotation is stored in multiples of 2 bits. */
10046 /* Rotate "constant" right by "rotation" bits. */
10047 signed_addend
= (constant
>> rotation
) |
10048 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
10051 /* Determine if the instruction is an ADD or a SUB.
10052 (For REL, this determines the sign of the addend.) */
10053 negative
= identify_add_or_sub (insn
);
10056 (*_bfd_error_handler
)
10057 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
10058 input_bfd
, input_section
,
10059 (long) rel
->r_offset
, howto
->name
);
10060 return bfd_reloc_overflow
;
10063 signed_addend
*= negative
;
10066 /* Compute the value (X) to go in the place. */
10067 if (r_type
== R_ARM_ALU_PC_G0_NC
10068 || r_type
== R_ARM_ALU_PC_G1_NC
10069 || r_type
== R_ARM_ALU_PC_G0
10070 || r_type
== R_ARM_ALU_PC_G1
10071 || r_type
== R_ARM_ALU_PC_G2
)
10073 signed_value
= value
- pc
+ signed_addend
;
10075 /* Section base relative. */
10076 signed_value
= value
- sb
+ signed_addend
;
10078 /* If the target symbol is a Thumb function, then set the
10079 Thumb bit in the address. */
10080 if (branch_type
== ST_BRANCH_TO_THUMB
)
10083 /* Calculate the value of the relevant G_n, in encoded
10084 constant-with-rotation format. */
10085 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
10088 /* Check for overflow if required. */
10089 if ((r_type
== R_ARM_ALU_PC_G0
10090 || r_type
== R_ARM_ALU_PC_G1
10091 || r_type
== R_ARM_ALU_PC_G2
10092 || r_type
== R_ARM_ALU_SB_G0
10093 || r_type
== R_ARM_ALU_SB_G1
10094 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
10096 (*_bfd_error_handler
)
10097 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10098 input_bfd
, input_section
,
10099 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10100 return bfd_reloc_overflow
;
10103 /* Mask out the value and the ADD/SUB part of the opcode; take care
10104 not to destroy the S bit. */
10105 insn
&= 0xff1ff000;
10107 /* Set the opcode according to whether the value to go in the
10108 place is negative. */
10109 if (signed_value
< 0)
10114 /* Encode the offset. */
10117 bfd_put_32 (input_bfd
, insn
, hit_data
);
10119 return bfd_reloc_ok
;
10121 case R_ARM_LDR_PC_G0
:
10122 case R_ARM_LDR_PC_G1
:
10123 case R_ARM_LDR_PC_G2
:
10124 case R_ARM_LDR_SB_G0
:
10125 case R_ARM_LDR_SB_G1
:
10126 case R_ARM_LDR_SB_G2
:
10128 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10129 bfd_vma pc
= input_section
->output_section
->vma
10130 + input_section
->output_offset
+ rel
->r_offset
;
10131 /* sb is the origin of the *segment* containing the symbol. */
10132 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10134 bfd_signed_vma signed_value
;
10137 /* Determine which groups of bits to calculate. */
10140 case R_ARM_LDR_PC_G0
:
10141 case R_ARM_LDR_SB_G0
:
10145 case R_ARM_LDR_PC_G1
:
10146 case R_ARM_LDR_SB_G1
:
10150 case R_ARM_LDR_PC_G2
:
10151 case R_ARM_LDR_SB_G2
:
10159 /* If REL, extract the addend from the insn. If RELA, it will
10160 have already been fetched for us. */
10161 if (globals
->use_rel
)
10163 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10164 signed_addend
= negative
* (insn
& 0xfff);
10167 /* Compute the value (X) to go in the place. */
10168 if (r_type
== R_ARM_LDR_PC_G0
10169 || r_type
== R_ARM_LDR_PC_G1
10170 || r_type
== R_ARM_LDR_PC_G2
)
10172 signed_value
= value
- pc
+ signed_addend
;
10174 /* Section base relative. */
10175 signed_value
= value
- sb
+ signed_addend
;
10177 /* Calculate the value of the relevant G_{n-1} to obtain
10178 the residual at that stage. */
10179 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10181 /* Check for overflow. */
10182 if (residual
>= 0x1000)
10184 (*_bfd_error_handler
)
10185 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10186 input_bfd
, input_section
,
10187 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10188 return bfd_reloc_overflow
;
10191 /* Mask out the value and U bit. */
10192 insn
&= 0xff7ff000;
10194 /* Set the U bit if the value to go in the place is non-negative. */
10195 if (signed_value
>= 0)
10198 /* Encode the offset. */
10201 bfd_put_32 (input_bfd
, insn
, hit_data
);
10203 return bfd_reloc_ok
;
10205 case R_ARM_LDRS_PC_G0
:
10206 case R_ARM_LDRS_PC_G1
:
10207 case R_ARM_LDRS_PC_G2
:
10208 case R_ARM_LDRS_SB_G0
:
10209 case R_ARM_LDRS_SB_G1
:
10210 case R_ARM_LDRS_SB_G2
:
10212 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10213 bfd_vma pc
= input_section
->output_section
->vma
10214 + input_section
->output_offset
+ rel
->r_offset
;
10215 /* sb is the origin of the *segment* containing the symbol. */
10216 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10218 bfd_signed_vma signed_value
;
10221 /* Determine which groups of bits to calculate. */
10224 case R_ARM_LDRS_PC_G0
:
10225 case R_ARM_LDRS_SB_G0
:
10229 case R_ARM_LDRS_PC_G1
:
10230 case R_ARM_LDRS_SB_G1
:
10234 case R_ARM_LDRS_PC_G2
:
10235 case R_ARM_LDRS_SB_G2
:
10243 /* If REL, extract the addend from the insn. If RELA, it will
10244 have already been fetched for us. */
10245 if (globals
->use_rel
)
10247 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10248 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
10251 /* Compute the value (X) to go in the place. */
10252 if (r_type
== R_ARM_LDRS_PC_G0
10253 || r_type
== R_ARM_LDRS_PC_G1
10254 || r_type
== R_ARM_LDRS_PC_G2
)
10256 signed_value
= value
- pc
+ signed_addend
;
10258 /* Section base relative. */
10259 signed_value
= value
- sb
+ signed_addend
;
10261 /* Calculate the value of the relevant G_{n-1} to obtain
10262 the residual at that stage. */
10263 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10265 /* Check for overflow. */
10266 if (residual
>= 0x100)
10268 (*_bfd_error_handler
)
10269 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10270 input_bfd
, input_section
,
10271 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10272 return bfd_reloc_overflow
;
10275 /* Mask out the value and U bit. */
10276 insn
&= 0xff7ff0f0;
10278 /* Set the U bit if the value to go in the place is non-negative. */
10279 if (signed_value
>= 0)
10282 /* Encode the offset. */
10283 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
10285 bfd_put_32 (input_bfd
, insn
, hit_data
);
10287 return bfd_reloc_ok
;
10289 case R_ARM_LDC_PC_G0
:
10290 case R_ARM_LDC_PC_G1
:
10291 case R_ARM_LDC_PC_G2
:
10292 case R_ARM_LDC_SB_G0
:
10293 case R_ARM_LDC_SB_G1
:
10294 case R_ARM_LDC_SB_G2
:
10296 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
10297 bfd_vma pc
= input_section
->output_section
->vma
10298 + input_section
->output_offset
+ rel
->r_offset
;
10299 /* sb is the origin of the *segment* containing the symbol. */
10300 bfd_vma sb
= sym_sec
? sym_sec
->output_section
->vma
: 0;
10302 bfd_signed_vma signed_value
;
10305 /* Determine which groups of bits to calculate. */
10308 case R_ARM_LDC_PC_G0
:
10309 case R_ARM_LDC_SB_G0
:
10313 case R_ARM_LDC_PC_G1
:
10314 case R_ARM_LDC_SB_G1
:
10318 case R_ARM_LDC_PC_G2
:
10319 case R_ARM_LDC_SB_G2
:
10327 /* If REL, extract the addend from the insn. If RELA, it will
10328 have already been fetched for us. */
10329 if (globals
->use_rel
)
10331 int negative
= (insn
& (1 << 23)) ? 1 : -1;
10332 signed_addend
= negative
* ((insn
& 0xff) << 2);
10335 /* Compute the value (X) to go in the place. */
10336 if (r_type
== R_ARM_LDC_PC_G0
10337 || r_type
== R_ARM_LDC_PC_G1
10338 || r_type
== R_ARM_LDC_PC_G2
)
10340 signed_value
= value
- pc
+ signed_addend
;
10342 /* Section base relative. */
10343 signed_value
= value
- sb
+ signed_addend
;
10345 /* Calculate the value of the relevant G_{n-1} to obtain
10346 the residual at that stage. */
10347 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
10349 /* Check for overflow. (The absolute value to go in the place must be
10350 divisible by four and, after having been divided by four, must
10351 fit in eight bits.) */
10352 if ((residual
& 0x3) != 0 || residual
>= 0x400)
10354 (*_bfd_error_handler
)
10355 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
10356 input_bfd
, input_section
,
10357 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
10358 return bfd_reloc_overflow
;
10361 /* Mask out the value and U bit. */
10362 insn
&= 0xff7fff00;
10364 /* Set the U bit if the value to go in the place is non-negative. */
10365 if (signed_value
>= 0)
10368 /* Encode the offset. */
10369 insn
|= residual
>> 2;
10371 bfd_put_32 (input_bfd
, insn
, hit_data
);
10373 return bfd_reloc_ok
;
10376 return bfd_reloc_notsupported
;
10380 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
10382 arm_add_to_rel (bfd
* abfd
,
10383 bfd_byte
* address
,
10384 reloc_howto_type
* howto
,
10385 bfd_signed_vma increment
)
10387 bfd_signed_vma addend
;
10389 if (howto
->type
== R_ARM_THM_CALL
10390 || howto
->type
== R_ARM_THM_JUMP24
)
10392 int upper_insn
, lower_insn
;
10395 upper_insn
= bfd_get_16 (abfd
, address
);
10396 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
10397 upper
= upper_insn
& 0x7ff;
10398 lower
= lower_insn
& 0x7ff;
10400 addend
= (upper
<< 12) | (lower
<< 1);
10401 addend
+= increment
;
10404 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
10405 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
10407 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
10408 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
10414 contents
= bfd_get_32 (abfd
, address
);
10416 /* Get the (signed) value from the instruction. */
10417 addend
= contents
& howto
->src_mask
;
10418 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10420 bfd_signed_vma mask
;
10423 mask
&= ~ howto
->src_mask
;
10427 /* Add in the increment, (which is a byte value). */
10428 switch (howto
->type
)
10431 addend
+= increment
;
10438 addend
<<= howto
->size
;
10439 addend
+= increment
;
10441 /* Should we check for overflow here ? */
10443 /* Drop any undesired bits. */
10444 addend
>>= howto
->rightshift
;
10448 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
10450 bfd_put_32 (abfd
, contents
, address
);
10454 #define IS_ARM_TLS_RELOC(R_TYPE) \
10455 ((R_TYPE) == R_ARM_TLS_GD32 \
10456 || (R_TYPE) == R_ARM_TLS_LDO32 \
10457 || (R_TYPE) == R_ARM_TLS_LDM32 \
10458 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
10459 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
10460 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
10461 || (R_TYPE) == R_ARM_TLS_LE32 \
10462 || (R_TYPE) == R_ARM_TLS_IE32 \
10463 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
10465 /* Specific set of relocations for the gnu tls dialect. */
10466 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
10467 ((R_TYPE) == R_ARM_TLS_GOTDESC \
10468 || (R_TYPE) == R_ARM_TLS_CALL \
10469 || (R_TYPE) == R_ARM_THM_TLS_CALL \
10470 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
10471 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
10473 /* Relocate an ARM ELF section. */
10476 elf32_arm_relocate_section (bfd
* output_bfd
,
10477 struct bfd_link_info
* info
,
10479 asection
* input_section
,
10480 bfd_byte
* contents
,
10481 Elf_Internal_Rela
* relocs
,
10482 Elf_Internal_Sym
* local_syms
,
10483 asection
** local_sections
)
10485 Elf_Internal_Shdr
*symtab_hdr
;
10486 struct elf_link_hash_entry
**sym_hashes
;
10487 Elf_Internal_Rela
*rel
;
10488 Elf_Internal_Rela
*relend
;
10490 struct elf32_arm_link_hash_table
* globals
;
10492 globals
= elf32_arm_hash_table (info
);
10493 if (globals
== NULL
)
10496 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
10497 sym_hashes
= elf_sym_hashes (input_bfd
);
10500 relend
= relocs
+ input_section
->reloc_count
;
10501 for (; rel
< relend
; rel
++)
10504 reloc_howto_type
* howto
;
10505 unsigned long r_symndx
;
10506 Elf_Internal_Sym
* sym
;
10508 struct elf_link_hash_entry
* h
;
10509 bfd_vma relocation
;
10510 bfd_reloc_status_type r
;
10513 bfd_boolean unresolved_reloc
= FALSE
;
10514 char *error_message
= NULL
;
10516 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10517 r_type
= ELF32_R_TYPE (rel
->r_info
);
10518 r_type
= arm_real_reloc_type (globals
, r_type
);
10520 if ( r_type
== R_ARM_GNU_VTENTRY
10521 || r_type
== R_ARM_GNU_VTINHERIT
)
10524 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
10525 howto
= bfd_reloc
.howto
;
10531 if (r_symndx
< symtab_hdr
->sh_info
)
10533 sym
= local_syms
+ r_symndx
;
10534 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
10535 sec
= local_sections
[r_symndx
];
10537 /* An object file might have a reference to a local
10538 undefined symbol. This is a daft object file, but we
10539 should at least do something about it. V4BX & NONE
10540 relocations do not use the symbol and are explicitly
10541 allowed to use the undefined symbol, so allow those.
10542 Likewise for relocations against STN_UNDEF. */
10543 if (r_type
!= R_ARM_V4BX
10544 && r_type
!= R_ARM_NONE
10545 && r_symndx
!= STN_UNDEF
10546 && bfd_is_und_section (sec
)
10547 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
10549 if (!info
->callbacks
->undefined_symbol
10550 (info
, bfd_elf_string_from_elf_section
10551 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
10552 input_bfd
, input_section
,
10553 rel
->r_offset
, TRUE
))
10557 if (globals
->use_rel
)
10559 relocation
= (sec
->output_section
->vma
10560 + sec
->output_offset
10562 if (!info
->relocatable
10563 && (sec
->flags
& SEC_MERGE
)
10564 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10567 bfd_vma addend
, value
;
10571 case R_ARM_MOVW_ABS_NC
:
10572 case R_ARM_MOVT_ABS
:
10573 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10574 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
10575 addend
= (addend
^ 0x8000) - 0x8000;
10578 case R_ARM_THM_MOVW_ABS_NC
:
10579 case R_ARM_THM_MOVT_ABS
:
10580 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
10582 value
|= bfd_get_16 (input_bfd
,
10583 contents
+ rel
->r_offset
+ 2);
10584 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
10585 | ((value
& 0x04000000) >> 15);
10586 addend
= (addend
^ 0x8000) - 0x8000;
10590 if (howto
->rightshift
10591 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
10593 (*_bfd_error_handler
)
10594 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
10595 input_bfd
, input_section
,
10596 (long) rel
->r_offset
, howto
->name
);
10600 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10602 /* Get the (signed) value from the instruction. */
10603 addend
= value
& howto
->src_mask
;
10604 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10606 bfd_signed_vma mask
;
10609 mask
&= ~ howto
->src_mask
;
10617 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
10619 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
10621 /* Cases here must match those in the preceding
10622 switch statement. */
10625 case R_ARM_MOVW_ABS_NC
:
10626 case R_ARM_MOVT_ABS
:
10627 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
10628 | (addend
& 0xfff);
10629 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10632 case R_ARM_THM_MOVW_ABS_NC
:
10633 case R_ARM_THM_MOVT_ABS
:
10634 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
10635 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
10636 bfd_put_16 (input_bfd
, value
>> 16,
10637 contents
+ rel
->r_offset
);
10638 bfd_put_16 (input_bfd
, value
,
10639 contents
+ rel
->r_offset
+ 2);
10643 value
= (value
& ~ howto
->dst_mask
)
10644 | (addend
& howto
->dst_mask
);
10645 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10651 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
10655 bfd_boolean warned
, ignored
;
10657 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
10658 r_symndx
, symtab_hdr
, sym_hashes
,
10659 h
, sec
, relocation
,
10660 unresolved_reloc
, warned
, ignored
);
10662 sym_type
= h
->type
;
10665 if (sec
!= NULL
&& discarded_section (sec
))
10666 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
10667 rel
, 1, relend
, howto
, 0, contents
);
10669 if (info
->relocatable
)
10671 /* This is a relocatable link. We don't have to change
10672 anything, unless the reloc is against a section symbol,
10673 in which case we have to adjust according to where the
10674 section symbol winds up in the output section. */
10675 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10677 if (globals
->use_rel
)
10678 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
10679 howto
, (bfd_signed_vma
) sec
->output_offset
);
10681 rel
->r_addend
+= sec
->output_offset
;
10687 name
= h
->root
.root
.string
;
10690 name
= (bfd_elf_string_from_elf_section
10691 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
10692 if (name
== NULL
|| *name
== '\0')
10693 name
= bfd_section_name (input_bfd
, sec
);
10696 if (r_symndx
!= STN_UNDEF
10697 && r_type
!= R_ARM_NONE
10699 || h
->root
.type
== bfd_link_hash_defined
10700 || h
->root
.type
== bfd_link_hash_defweak
)
10701 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
10703 (*_bfd_error_handler
)
10704 ((sym_type
== STT_TLS
10705 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
10706 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
10709 (long) rel
->r_offset
,
10714 /* We call elf32_arm_final_link_relocate unless we're completely
10715 done, i.e., the relaxation produced the final output we want,
10716 and we won't let anybody mess with it. Also, we have to do
10717 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
10718 both in relaxed and non-relaxed cases. */
10719 if ((elf32_arm_tls_transition (info
, r_type
, h
) != (unsigned)r_type
)
10720 || (IS_ARM_TLS_GNU_RELOC (r_type
)
10721 && !((h
? elf32_arm_hash_entry (h
)->tls_type
:
10722 elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
])
10725 r
= elf32_arm_tls_relax (globals
, input_bfd
, input_section
,
10726 contents
, rel
, h
== NULL
);
10727 /* This may have been marked unresolved because it came from
10728 a shared library. But we've just dealt with that. */
10729 unresolved_reloc
= 0;
10732 r
= bfd_reloc_continue
;
10734 if (r
== bfd_reloc_continue
)
10735 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
10736 input_section
, contents
, rel
,
10737 relocation
, info
, sec
, name
, sym_type
,
10738 (h
? h
->target_internal
10739 : ARM_SYM_BRANCH_TYPE (sym
)), h
,
10740 &unresolved_reloc
, &error_message
);
10742 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
10743 because such sections are not SEC_ALLOC and thus ld.so will
10744 not process them. */
10745 if (unresolved_reloc
10746 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
10748 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
10749 rel
->r_offset
) != (bfd_vma
) -1)
10751 (*_bfd_error_handler
)
10752 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
10755 (long) rel
->r_offset
,
10757 h
->root
.root
.string
);
10761 if (r
!= bfd_reloc_ok
)
10765 case bfd_reloc_overflow
:
10766 /* If the overflowing reloc was to an undefined symbol,
10767 we have already printed one error message and there
10768 is no point complaining again. */
10770 h
->root
.type
!= bfd_link_hash_undefined
)
10771 && (!((*info
->callbacks
->reloc_overflow
)
10772 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
10773 (bfd_vma
) 0, input_bfd
, input_section
,
10778 case bfd_reloc_undefined
:
10779 if (!((*info
->callbacks
->undefined_symbol
)
10780 (info
, name
, input_bfd
, input_section
,
10781 rel
->r_offset
, TRUE
)))
10785 case bfd_reloc_outofrange
:
10786 error_message
= _("out of range");
10789 case bfd_reloc_notsupported
:
10790 error_message
= _("unsupported relocation");
10793 case bfd_reloc_dangerous
:
10794 /* error_message should already be set. */
10798 error_message
= _("unknown error");
10799 /* Fall through. */
10802 BFD_ASSERT (error_message
!= NULL
);
10803 if (!((*info
->callbacks
->reloc_dangerous
)
10804 (info
, error_message
, input_bfd
, input_section
,
10815 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
10816 adds the edit to the start of the list. (The list must be built in order of
10817 ascending TINDEX: the function's callers are primarily responsible for
10818 maintaining that condition). */
10821 add_unwind_table_edit (arm_unwind_table_edit
**head
,
10822 arm_unwind_table_edit
**tail
,
10823 arm_unwind_edit_type type
,
10824 asection
*linked_section
,
10825 unsigned int tindex
)
10827 arm_unwind_table_edit
*new_edit
= (arm_unwind_table_edit
*)
10828 xmalloc (sizeof (arm_unwind_table_edit
));
10830 new_edit
->type
= type
;
10831 new_edit
->linked_section
= linked_section
;
10832 new_edit
->index
= tindex
;
10836 new_edit
->next
= NULL
;
10839 (*tail
)->next
= new_edit
;
10841 (*tail
) = new_edit
;
10844 (*head
) = new_edit
;
10848 new_edit
->next
= *head
;
10857 static _arm_elf_section_data
*get_arm_elf_section_data (asection
*);
10859 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
10861 adjust_exidx_size(asection
*exidx_sec
, int adjust
)
10865 if (!exidx_sec
->rawsize
)
10866 exidx_sec
->rawsize
= exidx_sec
->size
;
10868 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
10869 out_sec
= exidx_sec
->output_section
;
10870 /* Adjust size of output section. */
10871 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
10874 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
10876 insert_cantunwind_after(asection
*text_sec
, asection
*exidx_sec
)
10878 struct _arm_elf_section_data
*exidx_arm_data
;
10880 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10881 add_unwind_table_edit (
10882 &exidx_arm_data
->u
.exidx
.unwind_edit_list
,
10883 &exidx_arm_data
->u
.exidx
.unwind_edit_tail
,
10884 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
10886 adjust_exidx_size(exidx_sec
, 8);
10889 /* Scan .ARM.exidx tables, and create a list describing edits which should be
10890 made to those tables, such that:
10892 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
10893 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
10894 codes which have been inlined into the index).
10896 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
10898 The edits are applied when the tables are written
10899 (in elf32_arm_write_section). */
10902 elf32_arm_fix_exidx_coverage (asection
**text_section_order
,
10903 unsigned int num_text_sections
,
10904 struct bfd_link_info
*info
,
10905 bfd_boolean merge_exidx_entries
)
10908 unsigned int last_second_word
= 0, i
;
10909 asection
*last_exidx_sec
= NULL
;
10910 asection
*last_text_sec
= NULL
;
10911 int last_unwind_type
= -1;
10913 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
10915 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link
.next
)
10919 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
10921 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
10922 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
10924 if (!hdr
|| hdr
->sh_type
!= SHT_ARM_EXIDX
)
10927 if (elf_sec
->linked_to
)
10929 Elf_Internal_Shdr
*linked_hdr
10930 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
10931 struct _arm_elf_section_data
*linked_sec_arm_data
10932 = get_arm_elf_section_data (linked_hdr
->bfd_section
);
10934 if (linked_sec_arm_data
== NULL
)
10937 /* Link this .ARM.exidx section back from the text section it
10939 linked_sec_arm_data
->u
.text
.arm_exidx_sec
= sec
;
10944 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
10945 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
10946 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
10948 for (i
= 0; i
< num_text_sections
; i
++)
10950 asection
*sec
= text_section_order
[i
];
10951 asection
*exidx_sec
;
10952 struct _arm_elf_section_data
*arm_data
= get_arm_elf_section_data (sec
);
10953 struct _arm_elf_section_data
*exidx_arm_data
;
10954 bfd_byte
*contents
= NULL
;
10955 int deleted_exidx_bytes
= 0;
10957 arm_unwind_table_edit
*unwind_edit_head
= NULL
;
10958 arm_unwind_table_edit
*unwind_edit_tail
= NULL
;
10959 Elf_Internal_Shdr
*hdr
;
10962 if (arm_data
== NULL
)
10965 exidx_sec
= arm_data
->u
.text
.arm_exidx_sec
;
10966 if (exidx_sec
== NULL
)
10968 /* Section has no unwind data. */
10969 if (last_unwind_type
== 0 || !last_exidx_sec
)
10972 /* Ignore zero sized sections. */
10973 if (sec
->size
== 0)
10976 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
10977 last_unwind_type
= 0;
10981 /* Skip /DISCARD/ sections. */
10982 if (bfd_is_abs_section (exidx_sec
->output_section
))
10985 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
10986 if (hdr
->sh_type
!= SHT_ARM_EXIDX
)
10989 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10990 if (exidx_arm_data
== NULL
)
10993 ibfd
= exidx_sec
->owner
;
10995 if (hdr
->contents
!= NULL
)
10996 contents
= hdr
->contents
;
10997 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
11001 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
11003 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
11007 /* An EXIDX_CANTUNWIND entry. */
11008 if (second_word
== 1)
11010 if (last_unwind_type
== 0)
11014 /* Inlined unwinding data. Merge if equal to previous. */
11015 else if ((second_word
& 0x80000000) != 0)
11017 if (merge_exidx_entries
11018 && last_second_word
== second_word
&& last_unwind_type
== 1)
11021 last_second_word
= second_word
;
11023 /* Normal table entry. In theory we could merge these too,
11024 but duplicate entries are likely to be much less common. */
11030 add_unwind_table_edit (&unwind_edit_head
, &unwind_edit_tail
,
11031 DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
11033 deleted_exidx_bytes
+= 8;
11036 last_unwind_type
= unwind_type
;
11039 /* Free contents if we allocated it ourselves. */
11040 if (contents
!= hdr
->contents
)
11043 /* Record edits to be applied later (in elf32_arm_write_section). */
11044 exidx_arm_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
11045 exidx_arm_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
11047 if (deleted_exidx_bytes
> 0)
11048 adjust_exidx_size(exidx_sec
, -deleted_exidx_bytes
);
11050 last_exidx_sec
= exidx_sec
;
11051 last_text_sec
= sec
;
11054 /* Add terminating CANTUNWIND entry. */
11055 if (last_exidx_sec
&& last_unwind_type
!= 0)
11056 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
11062 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
11063 bfd
*ibfd
, const char *name
)
11065 asection
*sec
, *osec
;
11067 sec
= bfd_get_linker_section (ibfd
, name
);
11068 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
11071 osec
= sec
->output_section
;
11072 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
11075 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
11076 sec
->output_offset
, sec
->size
))
11083 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11085 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
11086 asection
*sec
, *osec
;
11088 if (globals
== NULL
)
11091 /* Invoke the regular ELF backend linker to do all the work. */
11092 if (!bfd_elf_final_link (abfd
, info
))
11095 /* Process stub sections (eg BE8 encoding, ...). */
11096 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
11098 for (i
=0; i
<htab
->top_id
; i
++)
11100 sec
= htab
->stub_group
[i
].stub_sec
;
11101 /* Only process it once, in its link_sec slot. */
11102 if (sec
&& i
== htab
->stub_group
[i
].link_sec
->id
)
11104 osec
= sec
->output_section
;
11105 elf32_arm_write_section (abfd
, info
, sec
, sec
->contents
);
11106 if (! bfd_set_section_contents (abfd
, osec
, sec
->contents
,
11107 sec
->output_offset
, sec
->size
))
11112 /* Write out any glue sections now that we have created all the
11114 if (globals
->bfd_of_glue_owner
!= NULL
)
11116 if (! elf32_arm_output_glue_section (info
, abfd
,
11117 globals
->bfd_of_glue_owner
,
11118 ARM2THUMB_GLUE_SECTION_NAME
))
11121 if (! elf32_arm_output_glue_section (info
, abfd
,
11122 globals
->bfd_of_glue_owner
,
11123 THUMB2ARM_GLUE_SECTION_NAME
))
11126 if (! elf32_arm_output_glue_section (info
, abfd
,
11127 globals
->bfd_of_glue_owner
,
11128 VFP11_ERRATUM_VENEER_SECTION_NAME
))
11131 if (! elf32_arm_output_glue_section (info
, abfd
,
11132 globals
->bfd_of_glue_owner
,
11133 ARM_BX_GLUE_SECTION_NAME
))
11140 /* Return a best guess for the machine number based on the attributes. */
11142 static unsigned int
11143 bfd_arm_get_mach_from_attributes (bfd
* abfd
)
11145 int arch
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_CPU_arch
);
11149 case TAG_CPU_ARCH_V4
: return bfd_mach_arm_4
;
11150 case TAG_CPU_ARCH_V4T
: return bfd_mach_arm_4T
;
11151 case TAG_CPU_ARCH_V5T
: return bfd_mach_arm_5T
;
11153 case TAG_CPU_ARCH_V5TE
:
11157 BFD_ASSERT (Tag_CPU_name
< NUM_KNOWN_OBJ_ATTRIBUTES
);
11158 name
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_CPU_name
].s
;
11162 if (strcmp (name
, "IWMMXT2") == 0)
11163 return bfd_mach_arm_iWMMXt2
;
11165 if (strcmp (name
, "IWMMXT") == 0)
11166 return bfd_mach_arm_iWMMXt
;
11168 if (strcmp (name
, "XSCALE") == 0)
11172 BFD_ASSERT (Tag_WMMX_arch
< NUM_KNOWN_OBJ_ATTRIBUTES
);
11173 wmmx
= elf_known_obj_attributes (abfd
) [OBJ_ATTR_PROC
][Tag_WMMX_arch
].i
;
11176 case 1: return bfd_mach_arm_iWMMXt
;
11177 case 2: return bfd_mach_arm_iWMMXt2
;
11178 default: return bfd_mach_arm_XScale
;
11183 return bfd_mach_arm_5TE
;
11187 return bfd_mach_arm_unknown
;
11191 /* Set the right machine number. */
11194 elf32_arm_object_p (bfd
*abfd
)
11198 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
11200 if (mach
== bfd_mach_arm_unknown
)
11202 if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
11203 mach
= bfd_mach_arm_ep9312
;
11205 mach
= bfd_arm_get_mach_from_attributes (abfd
);
11208 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
11212 /* Function to keep ARM specific flags in the ELF header. */
11215 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
11217 if (elf_flags_init (abfd
)
11218 && elf_elfheader (abfd
)->e_flags
!= flags
)
11220 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
11222 if (flags
& EF_ARM_INTERWORK
)
11223 (*_bfd_error_handler
)
11224 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
11228 (_("Warning: Clearing the interworking flag of %B due to outside request"),
11234 elf_elfheader (abfd
)->e_flags
= flags
;
11235 elf_flags_init (abfd
) = TRUE
;
11241 /* Copy backend specific data from one object module to another. */
11244 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
11247 flagword out_flags
;
11249 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
11252 in_flags
= elf_elfheader (ibfd
)->e_flags
;
11253 out_flags
= elf_elfheader (obfd
)->e_flags
;
11255 if (elf_flags_init (obfd
)
11256 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
11257 && in_flags
!= out_flags
)
11259 /* Cannot mix APCS26 and APCS32 code. */
11260 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
11263 /* Cannot mix float APCS and non-float APCS code. */
11264 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
11267 /* If the src and dest have different interworking flags
11268 then turn off the interworking bit. */
11269 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
11271 if (out_flags
& EF_ARM_INTERWORK
)
11273 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
11276 in_flags
&= ~EF_ARM_INTERWORK
;
11279 /* Likewise for PIC, though don't warn for this case. */
11280 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
11281 in_flags
&= ~EF_ARM_PIC
;
11284 elf_elfheader (obfd
)->e_flags
= in_flags
;
11285 elf_flags_init (obfd
) = TRUE
;
11287 return _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
11290 /* Values for Tag_ABI_PCS_R9_use. */
11299 /* Values for Tag_ABI_PCS_RW_data. */
11302 AEABI_PCS_RW_data_absolute
,
11303 AEABI_PCS_RW_data_PCrel
,
11304 AEABI_PCS_RW_data_SBrel
,
11305 AEABI_PCS_RW_data_unused
11308 /* Values for Tag_ABI_enum_size. */
11314 AEABI_enum_forced_wide
11317 /* Determine whether an object attribute tag takes an integer, a
11321 elf32_arm_obj_attrs_arg_type (int tag
)
11323 if (tag
== Tag_compatibility
)
11324 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
11325 else if (tag
== Tag_nodefaults
)
11326 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
11327 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
11328 return ATTR_TYPE_FLAG_STR_VAL
;
11330 return ATTR_TYPE_FLAG_INT_VAL
;
11332 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
11335 /* The ABI defines that Tag_conformance should be emitted first, and that
11336 Tag_nodefaults should be second (if either is defined). This sets those
11337 two positions, and bumps up the position of all the remaining tags to
11340 elf32_arm_obj_attrs_order (int num
)
11342 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
11343 return Tag_conformance
;
11344 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
+ 1)
11345 return Tag_nodefaults
;
11346 if ((num
- 2) < Tag_nodefaults
)
11348 if ((num
- 1) < Tag_conformance
)
11353 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
11355 elf32_arm_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
11357 if ((tag
& 127) < 64)
11360 (_("%B: Unknown mandatory EABI object attribute %d"),
11362 bfd_set_error (bfd_error_bad_value
);
11368 (_("Warning: %B: Unknown EABI object attribute %d"),
11374 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
11375 Returns -1 if no architecture could be read. */
11378 get_secondary_compatible_arch (bfd
*abfd
)
11380 obj_attribute
*attr
=
11381 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
11383 /* Note: the tag and its argument below are uleb128 values, though
11384 currently-defined values fit in one byte for each. */
11386 && attr
->s
[0] == Tag_CPU_arch
11387 && (attr
->s
[1] & 128) != 128
11388 && attr
->s
[2] == 0)
11391 /* This tag is "safely ignorable", so don't complain if it looks funny. */
11395 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
11396 The tag is removed if ARCH is -1. */
11399 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
11401 obj_attribute
*attr
=
11402 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
11410 /* Note: the tag and its argument below are uleb128 values, though
11411 currently-defined values fit in one byte for each. */
11413 attr
->s
= (char *) bfd_alloc (abfd
, 3);
11414 attr
->s
[0] = Tag_CPU_arch
;
11419 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
11423 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
11424 int newtag
, int secondary_compat
)
11426 #define T(X) TAG_CPU_ARCH_##X
11427 int tagl
, tagh
, result
;
11430 T(V6T2
), /* PRE_V4. */
11432 T(V6T2
), /* V4T. */
11433 T(V6T2
), /* V5T. */
11434 T(V6T2
), /* V5TE. */
11435 T(V6T2
), /* V5TEJ. */
11438 T(V6T2
) /* V6T2. */
11442 T(V6K
), /* PRE_V4. */
11446 T(V6K
), /* V5TE. */
11447 T(V6K
), /* V5TEJ. */
11449 T(V6KZ
), /* V6KZ. */
11455 T(V7
), /* PRE_V4. */
11460 T(V7
), /* V5TEJ. */
11473 T(V6K
), /* V5TE. */
11474 T(V6K
), /* V5TEJ. */
11476 T(V6KZ
), /* V6KZ. */
11480 T(V6_M
) /* V6_M. */
11482 const int v6s_m
[] =
11488 T(V6K
), /* V5TE. */
11489 T(V6K
), /* V5TEJ. */
11491 T(V6KZ
), /* V6KZ. */
11495 T(V6S_M
), /* V6_M. */
11496 T(V6S_M
) /* V6S_M. */
11498 const int v7e_m
[] =
11502 T(V7E_M
), /* V4T. */
11503 T(V7E_M
), /* V5T. */
11504 T(V7E_M
), /* V5TE. */
11505 T(V7E_M
), /* V5TEJ. */
11506 T(V7E_M
), /* V6. */
11507 T(V7E_M
), /* V6KZ. */
11508 T(V7E_M
), /* V6T2. */
11509 T(V7E_M
), /* V6K. */
11510 T(V7E_M
), /* V7. */
11511 T(V7E_M
), /* V6_M. */
11512 T(V7E_M
), /* V6S_M. */
11513 T(V7E_M
) /* V7E_M. */
11517 T(V8
), /* PRE_V4. */
11522 T(V8
), /* V5TEJ. */
11529 T(V8
), /* V6S_M. */
11530 T(V8
), /* V7E_M. */
11533 const int v4t_plus_v6_m
[] =
11539 T(V5TE
), /* V5TE. */
11540 T(V5TEJ
), /* V5TEJ. */
11542 T(V6KZ
), /* V6KZ. */
11543 T(V6T2
), /* V6T2. */
11546 T(V6_M
), /* V6_M. */
11547 T(V6S_M
), /* V6S_M. */
11548 T(V7E_M
), /* V7E_M. */
11550 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
11552 const int *comb
[] =
11561 /* Pseudo-architecture. */
11565 /* Check we've not got a higher architecture than we know about. */
11567 if (oldtag
> MAX_TAG_CPU_ARCH
|| newtag
> MAX_TAG_CPU_ARCH
)
11569 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd
);
11573 /* Override old tag if we have a Tag_also_compatible_with on the output. */
11575 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
11576 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
11577 oldtag
= T(V4T_PLUS_V6_M
);
11579 /* And override the new tag if we have a Tag_also_compatible_with on the
11582 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
11583 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
11584 newtag
= T(V4T_PLUS_V6_M
);
11586 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
11587 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
11589 /* Architectures before V6KZ add features monotonically. */
11590 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
11593 result
= comb
[tagh
- T(V6T2
)][tagl
];
11595 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
11596 as the canonical version. */
11597 if (result
== T(V4T_PLUS_V6_M
))
11600 *secondary_compat_out
= T(V6_M
);
11603 *secondary_compat_out
= -1;
11607 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
11608 ibfd
, oldtag
, newtag
);
11616 /* Query attributes object to see if integer divide instructions may be
11617 present in an object. */
11619 elf32_arm_attributes_accept_div (const obj_attribute
*attr
)
11621 int arch
= attr
[Tag_CPU_arch
].i
;
11622 int profile
= attr
[Tag_CPU_arch_profile
].i
;
11624 switch (attr
[Tag_DIV_use
].i
)
11627 /* Integer divide allowed if instruction contained in archetecture. */
11628 if (arch
== TAG_CPU_ARCH_V7
&& (profile
== 'R' || profile
== 'M'))
11630 else if (arch
>= TAG_CPU_ARCH_V7E_M
)
11636 /* Integer divide explicitly prohibited. */
11640 /* Unrecognised case - treat as allowing divide everywhere. */
11642 /* Integer divide allowed in ARM state. */
11647 /* Query attributes object to see if integer divide instructions are
11648 forbidden to be in the object. This is not the inverse of
11649 elf32_arm_attributes_accept_div. */
11651 elf32_arm_attributes_forbid_div (const obj_attribute
*attr
)
11653 return attr
[Tag_DIV_use
].i
== 1;
11656 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
11657 are conflicting attributes. */
11660 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
11662 obj_attribute
*in_attr
;
11663 obj_attribute
*out_attr
;
11664 /* Some tags have 0 = don't care, 1 = strong requirement,
11665 2 = weak requirement. */
11666 static const int order_021
[3] = {0, 2, 1};
11668 bfd_boolean result
= TRUE
;
11670 /* Skip the linker stubs file. This preserves previous behavior
11671 of accepting unknown attributes in the first input file - but
11673 if (ibfd
->flags
& BFD_LINKER_CREATED
)
11676 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11678 /* This is the first object. Copy the attributes. */
11679 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11681 out_attr
= elf_known_obj_attributes_proc (obfd
);
11683 /* Use the Tag_null value to indicate the attributes have been
11687 /* We do not output objects with Tag_MPextension_use_legacy - we move
11688 the attribute's value to Tag_MPextension_use. */
11689 if (out_attr
[Tag_MPextension_use_legacy
].i
!= 0)
11691 if (out_attr
[Tag_MPextension_use
].i
!= 0
11692 && out_attr
[Tag_MPextension_use_legacy
].i
11693 != out_attr
[Tag_MPextension_use
].i
)
11696 (_("Error: %B has both the current and legacy "
11697 "Tag_MPextension_use attributes"), ibfd
);
11701 out_attr
[Tag_MPextension_use
] =
11702 out_attr
[Tag_MPextension_use_legacy
];
11703 out_attr
[Tag_MPextension_use_legacy
].type
= 0;
11704 out_attr
[Tag_MPextension_use_legacy
].i
= 0;
11710 in_attr
= elf_known_obj_attributes_proc (ibfd
);
11711 out_attr
= elf_known_obj_attributes_proc (obfd
);
11712 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
11713 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
11715 /* Ignore mismatches if the object doesn't use floating point. */
11716 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
11717 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
11718 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
11721 (_("error: %B uses VFP register arguments, %B does not"),
11722 in_attr
[Tag_ABI_VFP_args
].i
? ibfd
: obfd
,
11723 in_attr
[Tag_ABI_VFP_args
].i
? obfd
: ibfd
);
11728 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
11730 /* Merge this attribute with existing attributes. */
11733 case Tag_CPU_raw_name
:
11735 /* These are merged after Tag_CPU_arch. */
11738 case Tag_ABI_optimization_goals
:
11739 case Tag_ABI_FP_optimization_goals
:
11740 /* Use the first value seen. */
11745 int secondary_compat
= -1, secondary_compat_out
= -1;
11746 unsigned int saved_out_attr
= out_attr
[i
].i
;
11747 static const char *name_table
[] = {
11748 /* These aren't real CPU names, but we can't guess
11749 that from the architecture version alone. */
11766 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
11767 secondary_compat
= get_secondary_compatible_arch (ibfd
);
11768 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
11769 out_attr
[i
].i
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
11770 &secondary_compat_out
,
11773 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
11775 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
11776 if (out_attr
[i
].i
== saved_out_attr
)
11777 ; /* Leave the names alone. */
11778 else if (out_attr
[i
].i
== in_attr
[i
].i
)
11780 /* The output architecture has been changed to match the
11781 input architecture. Use the input names. */
11782 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
11783 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
11785 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
11786 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
11791 out_attr
[Tag_CPU_name
].s
= NULL
;
11792 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
11795 /* If we still don't have a value for Tag_CPU_name,
11796 make one up now. Tag_CPU_raw_name remains blank. */
11797 if (out_attr
[Tag_CPU_name
].s
== NULL
11798 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
11799 out_attr
[Tag_CPU_name
].s
=
11800 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
11804 case Tag_ARM_ISA_use
:
11805 case Tag_THUMB_ISA_use
:
11806 case Tag_WMMX_arch
:
11807 case Tag_Advanced_SIMD_arch
:
11808 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
11809 case Tag_ABI_FP_rounding
:
11810 case Tag_ABI_FP_exceptions
:
11811 case Tag_ABI_FP_user_exceptions
:
11812 case Tag_ABI_FP_number_model
:
11813 case Tag_FP_HP_extension
:
11814 case Tag_CPU_unaligned_access
:
11816 case Tag_MPextension_use
:
11817 /* Use the largest value specified. */
11818 if (in_attr
[i
].i
> out_attr
[i
].i
)
11819 out_attr
[i
].i
= in_attr
[i
].i
;
11822 case Tag_ABI_align_preserved
:
11823 case Tag_ABI_PCS_RO_data
:
11824 /* Use the smallest value specified. */
11825 if (in_attr
[i
].i
< out_attr
[i
].i
)
11826 out_attr
[i
].i
= in_attr
[i
].i
;
11829 case Tag_ABI_align_needed
:
11830 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
11831 && (in_attr
[Tag_ABI_align_preserved
].i
== 0
11832 || out_attr
[Tag_ABI_align_preserved
].i
== 0))
11834 /* This error message should be enabled once all non-conformant
11835 binaries in the toolchain have had the attributes set
11838 (_("error: %B: 8-byte data alignment conflicts with %B"),
11842 /* Fall through. */
11843 case Tag_ABI_FP_denormal
:
11844 case Tag_ABI_PCS_GOT_use
:
11845 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
11846 value if greater than 2 (for future-proofing). */
11847 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
11848 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
11849 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
11850 out_attr
[i
].i
= in_attr
[i
].i
;
11853 case Tag_Virtualization_use
:
11854 /* The virtualization tag effectively stores two bits of
11855 information: the intended use of TrustZone (in bit 0), and the
11856 intended use of Virtualization (in bit 1). */
11857 if (out_attr
[i
].i
== 0)
11858 out_attr
[i
].i
= in_attr
[i
].i
;
11859 else if (in_attr
[i
].i
!= 0
11860 && in_attr
[i
].i
!= out_attr
[i
].i
)
11862 if (in_attr
[i
].i
<= 3 && out_attr
[i
].i
<= 3)
11867 (_("error: %B: unable to merge virtualization attributes "
11875 case Tag_CPU_arch_profile
:
11876 if (out_attr
[i
].i
!= in_attr
[i
].i
)
11878 /* 0 will merge with anything.
11879 'A' and 'S' merge to 'A'.
11880 'R' and 'S' merge to 'R'.
11881 'M' and 'A|R|S' is an error. */
11882 if (out_attr
[i
].i
== 0
11883 || (out_attr
[i
].i
== 'S'
11884 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
11885 out_attr
[i
].i
= in_attr
[i
].i
;
11886 else if (in_attr
[i
].i
== 0
11887 || (in_attr
[i
].i
== 'S'
11888 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
11889 ; /* Do nothing. */
11893 (_("error: %B: Conflicting architecture profiles %c/%c"),
11895 in_attr
[i
].i
? in_attr
[i
].i
: '0',
11896 out_attr
[i
].i
? out_attr
[i
].i
: '0');
11903 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
11904 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
11905 when it's 0. It might mean absence of FP hardware if
11906 Tag_FP_arch is zero, otherwise it is effectively SP + DP. */
11908 #define VFP_VERSION_COUNT 8
11909 static const struct
11913 } vfp_versions
[VFP_VERSION_COUNT
] =
11928 /* If the output has no requirement about FP hardware,
11929 follow the requirement of the input. */
11930 if (out_attr
[i
].i
== 0)
11932 BFD_ASSERT (out_attr
[Tag_ABI_HardFP_use
].i
== 0);
11933 out_attr
[i
].i
= in_attr
[i
].i
;
11934 out_attr
[Tag_ABI_HardFP_use
].i
11935 = in_attr
[Tag_ABI_HardFP_use
].i
;
11938 /* If the input has no requirement about FP hardware, do
11940 else if (in_attr
[i
].i
== 0)
11942 BFD_ASSERT (in_attr
[Tag_ABI_HardFP_use
].i
== 0);
11946 /* Both the input and the output have nonzero Tag_FP_arch.
11947 So Tag_ABI_HardFP_use is (SP & DP) when it's zero. */
11949 /* If both the input and the output have zero Tag_ABI_HardFP_use,
11951 if (in_attr
[Tag_ABI_HardFP_use
].i
== 0
11952 && out_attr
[Tag_ABI_HardFP_use
].i
== 0)
11954 /* If the input and the output have different Tag_ABI_HardFP_use,
11955 the combination of them is 3 (SP & DP). */
11956 else if (in_attr
[Tag_ABI_HardFP_use
].i
11957 != out_attr
[Tag_ABI_HardFP_use
].i
)
11958 out_attr
[Tag_ABI_HardFP_use
].i
= 3;
11960 /* Now we can handle Tag_FP_arch. */
11962 /* Values of VFP_VERSION_COUNT or more aren't defined, so just
11963 pick the biggest. */
11964 if (in_attr
[i
].i
>= VFP_VERSION_COUNT
11965 && in_attr
[i
].i
> out_attr
[i
].i
)
11967 out_attr
[i
] = in_attr
[i
];
11970 /* The output uses the superset of input features
11971 (ISA version) and registers. */
11972 ver
= vfp_versions
[in_attr
[i
].i
].ver
;
11973 if (ver
< vfp_versions
[out_attr
[i
].i
].ver
)
11974 ver
= vfp_versions
[out_attr
[i
].i
].ver
;
11975 regs
= vfp_versions
[in_attr
[i
].i
].regs
;
11976 if (regs
< vfp_versions
[out_attr
[i
].i
].regs
)
11977 regs
= vfp_versions
[out_attr
[i
].i
].regs
;
11978 /* This assumes all possible supersets are also a valid
11980 for (newval
= VFP_VERSION_COUNT
- 1; newval
> 0; newval
--)
11982 if (regs
== vfp_versions
[newval
].regs
11983 && ver
== vfp_versions
[newval
].ver
)
11986 out_attr
[i
].i
= newval
;
11989 case Tag_PCS_config
:
11990 if (out_attr
[i
].i
== 0)
11991 out_attr
[i
].i
= in_attr
[i
].i
;
11992 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= in_attr
[i
].i
)
11994 /* It's sometimes ok to mix different configs, so this is only
11997 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
12000 case Tag_ABI_PCS_R9_use
:
12001 if (in_attr
[i
].i
!= out_attr
[i
].i
12002 && out_attr
[i
].i
!= AEABI_R9_unused
12003 && in_attr
[i
].i
!= AEABI_R9_unused
)
12006 (_("error: %B: Conflicting use of R9"), ibfd
);
12009 if (out_attr
[i
].i
== AEABI_R9_unused
)
12010 out_attr
[i
].i
= in_attr
[i
].i
;
12012 case Tag_ABI_PCS_RW_data
:
12013 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
12014 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
12015 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
12018 (_("error: %B: SB relative addressing conflicts with use of R9"),
12022 /* Use the smallest value specified. */
12023 if (in_attr
[i
].i
< out_attr
[i
].i
)
12024 out_attr
[i
].i
= in_attr
[i
].i
;
12026 case Tag_ABI_PCS_wchar_t
:
12027 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
12028 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
12031 (_("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"),
12032 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
12034 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
12035 out_attr
[i
].i
= in_attr
[i
].i
;
12037 case Tag_ABI_enum_size
:
12038 if (in_attr
[i
].i
!= AEABI_enum_unused
)
12040 if (out_attr
[i
].i
== AEABI_enum_unused
12041 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
12043 /* The existing object is compatible with anything.
12044 Use whatever requirements the new object has. */
12045 out_attr
[i
].i
= in_attr
[i
].i
;
12047 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
12048 && out_attr
[i
].i
!= in_attr
[i
].i
12049 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
12051 static const char *aeabi_enum_names
[] =
12052 { "", "variable-size", "32-bit", "" };
12053 const char *in_name
=
12054 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
12055 ? aeabi_enum_names
[in_attr
[i
].i
]
12057 const char *out_name
=
12058 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
12059 ? aeabi_enum_names
[out_attr
[i
].i
]
12062 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
12063 ibfd
, in_name
, out_name
);
12067 case Tag_ABI_VFP_args
:
12070 case Tag_ABI_WMMX_args
:
12071 if (in_attr
[i
].i
!= out_attr
[i
].i
)
12074 (_("error: %B uses iWMMXt register arguments, %B does not"),
12079 case Tag_compatibility
:
12080 /* Merged in target-independent code. */
12082 case Tag_ABI_HardFP_use
:
12083 /* This is handled along with Tag_FP_arch. */
12085 case Tag_ABI_FP_16bit_format
:
12086 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
12088 if (in_attr
[i
].i
!= out_attr
[i
].i
)
12091 (_("error: fp16 format mismatch between %B and %B"),
12096 if (in_attr
[i
].i
!= 0)
12097 out_attr
[i
].i
= in_attr
[i
].i
;
12101 /* A value of zero on input means that the divide instruction may
12102 be used if available in the base architecture as specified via
12103 Tag_CPU_arch and Tag_CPU_arch_profile. A value of 1 means that
12104 the user did not want divide instructions. A value of 2
12105 explicitly means that divide instructions were allowed in ARM
12106 and Thumb state. */
12107 if (in_attr
[i
].i
== out_attr
[i
].i
)
12108 /* Do nothing. */ ;
12109 else if (elf32_arm_attributes_forbid_div (in_attr
)
12110 && !elf32_arm_attributes_accept_div (out_attr
))
12112 else if (elf32_arm_attributes_forbid_div (out_attr
)
12113 && elf32_arm_attributes_accept_div (in_attr
))
12114 out_attr
[i
].i
= in_attr
[i
].i
;
12115 else if (in_attr
[i
].i
== 2)
12116 out_attr
[i
].i
= in_attr
[i
].i
;
12119 case Tag_MPextension_use_legacy
:
12120 /* We don't output objects with Tag_MPextension_use_legacy - we
12121 move the value to Tag_MPextension_use. */
12122 if (in_attr
[i
].i
!= 0 && in_attr
[Tag_MPextension_use
].i
!= 0)
12124 if (in_attr
[Tag_MPextension_use
].i
!= in_attr
[i
].i
)
12127 (_("%B has has both the current and legacy "
12128 "Tag_MPextension_use attributes"),
12134 if (in_attr
[i
].i
> out_attr
[Tag_MPextension_use
].i
)
12135 out_attr
[Tag_MPextension_use
] = in_attr
[i
];
12139 case Tag_nodefaults
:
12140 /* This tag is set if it exists, but the value is unused (and is
12141 typically zero). We don't actually need to do anything here -
12142 the merge happens automatically when the type flags are merged
12145 case Tag_also_compatible_with
:
12146 /* Already done in Tag_CPU_arch. */
12148 case Tag_conformance
:
12149 /* Keep the attribute if it matches. Throw it away otherwise.
12150 No attribute means no claim to conform. */
12151 if (!in_attr
[i
].s
|| !out_attr
[i
].s
12152 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
12153 out_attr
[i
].s
= NULL
;
12158 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
12161 /* If out_attr was copied from in_attr then it won't have a type yet. */
12162 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
12163 out_attr
[i
].type
= in_attr
[i
].type
;
12166 /* Merge Tag_compatibility attributes and any common GNU ones. */
12167 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
12170 /* Check for any attributes not known on ARM. */
12171 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
12177 /* Return TRUE if the two EABI versions are incompatible. */
12180 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
12182 /* v4 and v5 are the same spec before and after it was released,
12183 so allow mixing them. */
12184 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
12185 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
12188 return (iver
== over
);
12191 /* Merge backend specific data from an object file to the output
12192 object file when linking. */
12195 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
);
12197 /* Display the flags field. */
12200 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
12202 FILE * file
= (FILE *) ptr
;
12203 unsigned long flags
;
12205 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12207 /* Print normal ELF private data. */
12208 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12210 flags
= elf_elfheader (abfd
)->e_flags
;
12211 /* Ignore init flag - it may not be set, despite the flags field
12212 containing valid data. */
12214 /* xgettext:c-format */
12215 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12217 switch (EF_ARM_EABI_VERSION (flags
))
12219 case EF_ARM_EABI_UNKNOWN
:
12220 /* The following flag bits are GNU extensions and not part of the
12221 official ARM ELF extended ABI. Hence they are only decoded if
12222 the EABI version is not set. */
12223 if (flags
& EF_ARM_INTERWORK
)
12224 fprintf (file
, _(" [interworking enabled]"));
12226 if (flags
& EF_ARM_APCS_26
)
12227 fprintf (file
, " [APCS-26]");
12229 fprintf (file
, " [APCS-32]");
12231 if (flags
& EF_ARM_VFP_FLOAT
)
12232 fprintf (file
, _(" [VFP float format]"));
12233 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
12234 fprintf (file
, _(" [Maverick float format]"));
12236 fprintf (file
, _(" [FPA float format]"));
12238 if (flags
& EF_ARM_APCS_FLOAT
)
12239 fprintf (file
, _(" [floats passed in float registers]"));
12241 if (flags
& EF_ARM_PIC
)
12242 fprintf (file
, _(" [position independent]"));
12244 if (flags
& EF_ARM_NEW_ABI
)
12245 fprintf (file
, _(" [new ABI]"));
12247 if (flags
& EF_ARM_OLD_ABI
)
12248 fprintf (file
, _(" [old ABI]"));
12250 if (flags
& EF_ARM_SOFT_FLOAT
)
12251 fprintf (file
, _(" [software FP]"));
12253 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
12254 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
12255 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
12256 | EF_ARM_MAVERICK_FLOAT
);
12259 case EF_ARM_EABI_VER1
:
12260 fprintf (file
, _(" [Version1 EABI]"));
12262 if (flags
& EF_ARM_SYMSARESORTED
)
12263 fprintf (file
, _(" [sorted symbol table]"));
12265 fprintf (file
, _(" [unsorted symbol table]"));
12267 flags
&= ~ EF_ARM_SYMSARESORTED
;
12270 case EF_ARM_EABI_VER2
:
12271 fprintf (file
, _(" [Version2 EABI]"));
12273 if (flags
& EF_ARM_SYMSARESORTED
)
12274 fprintf (file
, _(" [sorted symbol table]"));
12276 fprintf (file
, _(" [unsorted symbol table]"));
12278 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
12279 fprintf (file
, _(" [dynamic symbols use segment index]"));
12281 if (flags
& EF_ARM_MAPSYMSFIRST
)
12282 fprintf (file
, _(" [mapping symbols precede others]"));
12284 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
12285 | EF_ARM_MAPSYMSFIRST
);
12288 case EF_ARM_EABI_VER3
:
12289 fprintf (file
, _(" [Version3 EABI]"));
12292 case EF_ARM_EABI_VER4
:
12293 fprintf (file
, _(" [Version4 EABI]"));
12296 case EF_ARM_EABI_VER5
:
12297 fprintf (file
, _(" [Version5 EABI]"));
12299 if (flags
& EF_ARM_ABI_FLOAT_SOFT
)
12300 fprintf (file
, _(" [soft-float ABI]"));
12302 if (flags
& EF_ARM_ABI_FLOAT_HARD
)
12303 fprintf (file
, _(" [hard-float ABI]"));
12305 flags
&= ~(EF_ARM_ABI_FLOAT_SOFT
| EF_ARM_ABI_FLOAT_HARD
);
12308 if (flags
& EF_ARM_BE8
)
12309 fprintf (file
, _(" [BE8]"));
12311 if (flags
& EF_ARM_LE8
)
12312 fprintf (file
, _(" [LE8]"));
12314 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
12318 fprintf (file
, _(" <EABI version unrecognised>"));
12322 flags
&= ~ EF_ARM_EABIMASK
;
12324 if (flags
& EF_ARM_RELEXEC
)
12325 fprintf (file
, _(" [relocatable executable]"));
12327 if (flags
& EF_ARM_HASENTRY
)
12328 fprintf (file
, _(" [has entry point]"));
12330 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
12333 fprintf (file
, _("<Unrecognised flag bits set>"));
12335 fputc ('\n', file
);
12341 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
12343 switch (ELF_ST_TYPE (elf_sym
->st_info
))
12345 case STT_ARM_TFUNC
:
12346 return ELF_ST_TYPE (elf_sym
->st_info
);
12348 case STT_ARM_16BIT
:
12349 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
12350 This allows us to distinguish between data used by Thumb instructions
12351 and non-data (which is probably code) inside Thumb regions of an
12353 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
12354 return ELF_ST_TYPE (elf_sym
->st_info
);
12365 elf32_arm_gc_mark_hook (asection
*sec
,
12366 struct bfd_link_info
*info
,
12367 Elf_Internal_Rela
*rel
,
12368 struct elf_link_hash_entry
*h
,
12369 Elf_Internal_Sym
*sym
)
12372 switch (ELF32_R_TYPE (rel
->r_info
))
12374 case R_ARM_GNU_VTINHERIT
:
12375 case R_ARM_GNU_VTENTRY
:
12379 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
12382 /* Update the got entry reference counts for the section being removed. */
12385 elf32_arm_gc_sweep_hook (bfd
* abfd
,
12386 struct bfd_link_info
* info
,
12388 const Elf_Internal_Rela
* relocs
)
12390 Elf_Internal_Shdr
*symtab_hdr
;
12391 struct elf_link_hash_entry
**sym_hashes
;
12392 bfd_signed_vma
*local_got_refcounts
;
12393 const Elf_Internal_Rela
*rel
, *relend
;
12394 struct elf32_arm_link_hash_table
* globals
;
12396 if (info
->relocatable
)
12399 globals
= elf32_arm_hash_table (info
);
12400 if (globals
== NULL
)
12403 elf_section_data (sec
)->local_dynrel
= NULL
;
12405 symtab_hdr
= & elf_symtab_hdr (abfd
);
12406 sym_hashes
= elf_sym_hashes (abfd
);
12407 local_got_refcounts
= elf_local_got_refcounts (abfd
);
12409 check_use_blx (globals
);
12411 relend
= relocs
+ sec
->reloc_count
;
12412 for (rel
= relocs
; rel
< relend
; rel
++)
12414 unsigned long r_symndx
;
12415 struct elf_link_hash_entry
*h
= NULL
;
12416 struct elf32_arm_link_hash_entry
*eh
;
12418 bfd_boolean call_reloc_p
;
12419 bfd_boolean may_become_dynamic_p
;
12420 bfd_boolean may_need_local_target_p
;
12421 union gotplt_union
*root_plt
;
12422 struct arm_plt_info
*arm_plt
;
12424 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12425 if (r_symndx
>= symtab_hdr
->sh_info
)
12427 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
12428 while (h
->root
.type
== bfd_link_hash_indirect
12429 || h
->root
.type
== bfd_link_hash_warning
)
12430 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12432 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12434 call_reloc_p
= FALSE
;
12435 may_become_dynamic_p
= FALSE
;
12436 may_need_local_target_p
= FALSE
;
12438 r_type
= ELF32_R_TYPE (rel
->r_info
);
12439 r_type
= arm_real_reloc_type (globals
, r_type
);
12443 case R_ARM_GOT_PREL
:
12444 case R_ARM_TLS_GD32
:
12445 case R_ARM_TLS_IE32
:
12448 if (h
->got
.refcount
> 0)
12449 h
->got
.refcount
-= 1;
12451 else if (local_got_refcounts
!= NULL
)
12453 if (local_got_refcounts
[r_symndx
] > 0)
12454 local_got_refcounts
[r_symndx
] -= 1;
12458 case R_ARM_TLS_LDM32
:
12459 globals
->tls_ldm_got
.refcount
-= 1;
12467 case R_ARM_THM_CALL
:
12468 case R_ARM_THM_JUMP24
:
12469 case R_ARM_THM_JUMP19
:
12470 call_reloc_p
= TRUE
;
12471 may_need_local_target_p
= TRUE
;
12475 if (!globals
->vxworks_p
)
12477 may_need_local_target_p
= TRUE
;
12480 /* Fall through. */
12482 case R_ARM_ABS32_NOI
:
12484 case R_ARM_REL32_NOI
:
12485 case R_ARM_MOVW_ABS_NC
:
12486 case R_ARM_MOVT_ABS
:
12487 case R_ARM_MOVW_PREL_NC
:
12488 case R_ARM_MOVT_PREL
:
12489 case R_ARM_THM_MOVW_ABS_NC
:
12490 case R_ARM_THM_MOVT_ABS
:
12491 case R_ARM_THM_MOVW_PREL_NC
:
12492 case R_ARM_THM_MOVT_PREL
:
12493 /* Should the interworking branches be here also? */
12494 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
12495 && (sec
->flags
& SEC_ALLOC
) != 0)
12498 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
12500 call_reloc_p
= TRUE
;
12501 may_need_local_target_p
= TRUE
;
12504 may_become_dynamic_p
= TRUE
;
12507 may_need_local_target_p
= TRUE
;
12514 if (may_need_local_target_p
12515 && elf32_arm_get_plt_info (abfd
, eh
, r_symndx
, &root_plt
, &arm_plt
))
12517 /* If PLT refcount book-keeping is wrong and too low, we'll
12518 see a zero value (going to -1) for the root PLT reference
12520 if (root_plt
->refcount
>= 0)
12522 BFD_ASSERT (root_plt
->refcount
!= 0);
12523 root_plt
->refcount
-= 1;
12526 /* A value of -1 means the symbol has become local, forced
12527 or seeing a hidden definition. Any other negative value
12529 BFD_ASSERT (root_plt
->refcount
== -1);
12532 arm_plt
->noncall_refcount
--;
12534 if (r_type
== R_ARM_THM_CALL
)
12535 arm_plt
->maybe_thumb_refcount
--;
12537 if (r_type
== R_ARM_THM_JUMP24
12538 || r_type
== R_ARM_THM_JUMP19
)
12539 arm_plt
->thumb_refcount
--;
12542 if (may_become_dynamic_p
)
12544 struct elf_dyn_relocs
**pp
;
12545 struct elf_dyn_relocs
*p
;
12548 pp
= &(eh
->dyn_relocs
);
12551 Elf_Internal_Sym
*isym
;
12553 isym
= bfd_sym_from_r_symndx (&globals
->sym_cache
,
12557 pp
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12561 for (; (p
= *pp
) != NULL
; pp
= &p
->next
)
12564 /* Everything must go for SEC. */
12574 /* Look through the relocs for a section during the first phase. */
12577 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
12578 asection
*sec
, const Elf_Internal_Rela
*relocs
)
12580 Elf_Internal_Shdr
*symtab_hdr
;
12581 struct elf_link_hash_entry
**sym_hashes
;
12582 const Elf_Internal_Rela
*rel
;
12583 const Elf_Internal_Rela
*rel_end
;
12586 struct elf32_arm_link_hash_table
*htab
;
12587 bfd_boolean call_reloc_p
;
12588 bfd_boolean may_become_dynamic_p
;
12589 bfd_boolean may_need_local_target_p
;
12590 unsigned long nsyms
;
12592 if (info
->relocatable
)
12595 BFD_ASSERT (is_arm_elf (abfd
));
12597 htab
= elf32_arm_hash_table (info
);
12603 /* Create dynamic sections for relocatable executables so that we can
12604 copy relocations. */
12605 if (htab
->root
.is_relocatable_executable
12606 && ! htab
->root
.dynamic_sections_created
)
12608 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
12612 if (htab
->root
.dynobj
== NULL
)
12613 htab
->root
.dynobj
= abfd
;
12614 if (!create_ifunc_sections (info
))
12617 dynobj
= htab
->root
.dynobj
;
12619 symtab_hdr
= & elf_symtab_hdr (abfd
);
12620 sym_hashes
= elf_sym_hashes (abfd
);
12621 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
12623 rel_end
= relocs
+ sec
->reloc_count
;
12624 for (rel
= relocs
; rel
< rel_end
; rel
++)
12626 Elf_Internal_Sym
*isym
;
12627 struct elf_link_hash_entry
*h
;
12628 struct elf32_arm_link_hash_entry
*eh
;
12629 unsigned long r_symndx
;
12632 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12633 r_type
= ELF32_R_TYPE (rel
->r_info
);
12634 r_type
= arm_real_reloc_type (htab
, r_type
);
12636 if (r_symndx
>= nsyms
12637 /* PR 9934: It is possible to have relocations that do not
12638 refer to symbols, thus it is also possible to have an
12639 object file containing relocations but no symbol table. */
12640 && (r_symndx
> STN_UNDEF
|| nsyms
> 0))
12642 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
12651 if (r_symndx
< symtab_hdr
->sh_info
)
12653 /* A local symbol. */
12654 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
12661 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
12662 while (h
->root
.type
== bfd_link_hash_indirect
12663 || h
->root
.type
== bfd_link_hash_warning
)
12664 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12666 /* PR15323, ref flags aren't set for references in the
12668 h
->root
.non_ir_ref
= 1;
12672 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12674 call_reloc_p
= FALSE
;
12675 may_become_dynamic_p
= FALSE
;
12676 may_need_local_target_p
= FALSE
;
12678 /* Could be done earlier, if h were already available. */
12679 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
12683 case R_ARM_GOT_PREL
:
12684 case R_ARM_TLS_GD32
:
12685 case R_ARM_TLS_IE32
:
12686 case R_ARM_TLS_GOTDESC
:
12687 case R_ARM_TLS_DESCSEQ
:
12688 case R_ARM_THM_TLS_DESCSEQ
:
12689 case R_ARM_TLS_CALL
:
12690 case R_ARM_THM_TLS_CALL
:
12691 /* This symbol requires a global offset table entry. */
12693 int tls_type
, old_tls_type
;
12697 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
12699 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
12701 case R_ARM_TLS_GOTDESC
:
12702 case R_ARM_TLS_CALL
: case R_ARM_THM_TLS_CALL
:
12703 case R_ARM_TLS_DESCSEQ
: case R_ARM_THM_TLS_DESCSEQ
:
12704 tls_type
= GOT_TLS_GDESC
; break;
12706 default: tls_type
= GOT_NORMAL
; break;
12712 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
12716 /* This is a global offset table entry for a local symbol. */
12717 if (!elf32_arm_allocate_local_sym_info (abfd
))
12719 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
12720 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
12723 /* If a variable is accessed with both tls methods, two
12724 slots may be created. */
12725 if (GOT_TLS_GD_ANY_P (old_tls_type
)
12726 && GOT_TLS_GD_ANY_P (tls_type
))
12727 tls_type
|= old_tls_type
;
12729 /* We will already have issued an error message if there
12730 is a TLS/non-TLS mismatch, based on the symbol
12731 type. So just combine any TLS types needed. */
12732 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
12733 && tls_type
!= GOT_NORMAL
)
12734 tls_type
|= old_tls_type
;
12736 /* If the symbol is accessed in both IE and GDESC
12737 method, we're able to relax. Turn off the GDESC flag,
12738 without messing up with any other kind of tls types
12739 that may be involved. */
12740 if ((tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_GDESC
))
12741 tls_type
&= ~GOT_TLS_GDESC
;
12743 if (old_tls_type
!= tls_type
)
12746 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
12748 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
12751 /* Fall through. */
12753 case R_ARM_TLS_LDM32
:
12754 if (r_type
== R_ARM_TLS_LDM32
)
12755 htab
->tls_ldm_got
.refcount
++;
12756 /* Fall through. */
12758 case R_ARM_GOTOFF32
:
12760 if (htab
->root
.sgot
== NULL
12761 && !create_got_section (htab
->root
.dynobj
, info
))
12770 case R_ARM_THM_CALL
:
12771 case R_ARM_THM_JUMP24
:
12772 case R_ARM_THM_JUMP19
:
12773 call_reloc_p
= TRUE
;
12774 may_need_local_target_p
= TRUE
;
12778 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
12779 ldr __GOTT_INDEX__ offsets. */
12780 if (!htab
->vxworks_p
)
12782 may_need_local_target_p
= TRUE
;
12785 /* Fall through. */
12787 case R_ARM_MOVW_ABS_NC
:
12788 case R_ARM_MOVT_ABS
:
12789 case R_ARM_THM_MOVW_ABS_NC
:
12790 case R_ARM_THM_MOVT_ABS
:
12793 (*_bfd_error_handler
)
12794 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
12795 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
12796 (h
) ? h
->root
.root
.string
: "a local symbol");
12797 bfd_set_error (bfd_error_bad_value
);
12801 /* Fall through. */
12803 case R_ARM_ABS32_NOI
:
12804 if (h
!= NULL
&& info
->executable
)
12806 h
->pointer_equality_needed
= 1;
12808 /* Fall through. */
12810 case R_ARM_REL32_NOI
:
12811 case R_ARM_MOVW_PREL_NC
:
12812 case R_ARM_MOVT_PREL
:
12813 case R_ARM_THM_MOVW_PREL_NC
:
12814 case R_ARM_THM_MOVT_PREL
:
12816 /* Should the interworking branches be listed here? */
12817 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
12818 && (sec
->flags
& SEC_ALLOC
) != 0)
12821 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
12823 /* In shared libraries and relocatable executables,
12824 we treat local relative references as calls;
12825 see the related SYMBOL_CALLS_LOCAL code in
12826 allocate_dynrelocs. */
12827 call_reloc_p
= TRUE
;
12828 may_need_local_target_p
= TRUE
;
12831 /* We are creating a shared library or relocatable
12832 executable, and this is a reloc against a global symbol,
12833 or a non-PC-relative reloc against a local symbol.
12834 We may need to copy the reloc into the output. */
12835 may_become_dynamic_p
= TRUE
;
12838 may_need_local_target_p
= TRUE
;
12841 /* This relocation describes the C++ object vtable hierarchy.
12842 Reconstruct it for later use during GC. */
12843 case R_ARM_GNU_VTINHERIT
:
12844 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
12848 /* This relocation describes which C++ vtable entries are actually
12849 used. Record for later use during GC. */
12850 case R_ARM_GNU_VTENTRY
:
12851 BFD_ASSERT (h
!= NULL
);
12853 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
12861 /* We may need a .plt entry if the function this reloc
12862 refers to is in a different object, regardless of the
12863 symbol's type. We can't tell for sure yet, because
12864 something later might force the symbol local. */
12866 else if (may_need_local_target_p
)
12867 /* If this reloc is in a read-only section, we might
12868 need a copy reloc. We can't check reliably at this
12869 stage whether the section is read-only, as input
12870 sections have not yet been mapped to output sections.
12871 Tentatively set the flag for now, and correct in
12872 adjust_dynamic_symbol. */
12873 h
->non_got_ref
= 1;
12876 if (may_need_local_target_p
12877 && (h
!= NULL
|| ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
))
12879 union gotplt_union
*root_plt
;
12880 struct arm_plt_info
*arm_plt
;
12881 struct arm_local_iplt_info
*local_iplt
;
12885 root_plt
= &h
->plt
;
12886 arm_plt
= &eh
->plt
;
12890 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
12891 if (local_iplt
== NULL
)
12893 root_plt
= &local_iplt
->root
;
12894 arm_plt
= &local_iplt
->arm
;
12897 /* If the symbol is a function that doesn't bind locally,
12898 this relocation will need a PLT entry. */
12899 if (root_plt
->refcount
!= -1)
12900 root_plt
->refcount
+= 1;
12903 arm_plt
->noncall_refcount
++;
12905 /* It's too early to use htab->use_blx here, so we have to
12906 record possible blx references separately from
12907 relocs that definitely need a thumb stub. */
12909 if (r_type
== R_ARM_THM_CALL
)
12910 arm_plt
->maybe_thumb_refcount
+= 1;
12912 if (r_type
== R_ARM_THM_JUMP24
12913 || r_type
== R_ARM_THM_JUMP19
)
12914 arm_plt
->thumb_refcount
+= 1;
12917 if (may_become_dynamic_p
)
12919 struct elf_dyn_relocs
*p
, **head
;
12921 /* Create a reloc section in dynobj. */
12922 if (sreloc
== NULL
)
12924 sreloc
= _bfd_elf_make_dynamic_reloc_section
12925 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
12927 if (sreloc
== NULL
)
12930 /* BPABI objects never have dynamic relocations mapped. */
12931 if (htab
->symbian_p
)
12935 flags
= bfd_get_section_flags (dynobj
, sreloc
);
12936 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
12937 bfd_set_section_flags (dynobj
, sreloc
, flags
);
12941 /* If this is a global symbol, count the number of
12942 relocations we need for this symbol. */
12944 head
= &((struct elf32_arm_link_hash_entry
*) h
)->dyn_relocs
;
12947 head
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12953 if (p
== NULL
|| p
->sec
!= sec
)
12955 bfd_size_type amt
= sizeof *p
;
12957 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->root
.dynobj
, amt
);
12967 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
12976 /* Unwinding tables are not referenced directly. This pass marks them as
12977 required if the corresponding code section is marked. */
12980 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
12981 elf_gc_mark_hook_fn gc_mark_hook
)
12984 Elf_Internal_Shdr
**elf_shdrp
;
12987 _bfd_elf_gc_mark_extra_sections (info
, gc_mark_hook
);
12989 /* Marking EH data may cause additional code sections to be marked,
12990 requiring multiple passes. */
12995 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
12999 if (! is_arm_elf (sub
))
13002 elf_shdrp
= elf_elfsections (sub
);
13003 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
13005 Elf_Internal_Shdr
*hdr
;
13007 hdr
= &elf_section_data (o
)->this_hdr
;
13008 if (hdr
->sh_type
== SHT_ARM_EXIDX
13010 && hdr
->sh_link
< elf_numsections (sub
)
13012 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
13015 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
13025 /* Treat mapping symbols as special target symbols. */
13028 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
13030 return bfd_is_arm_special_symbol_name (sym
->name
,
13031 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
13034 /* This is a copy of elf_find_function() from elf.c except that
13035 ARM mapping symbols are ignored when looking for function names
13036 and STT_ARM_TFUNC is considered to a function type. */
13039 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
13040 asection
* section
,
13041 asymbol
** symbols
,
13043 const char ** filename_ptr
,
13044 const char ** functionname_ptr
)
13046 const char * filename
= NULL
;
13047 asymbol
* func
= NULL
;
13048 bfd_vma low_func
= 0;
13051 for (p
= symbols
; *p
!= NULL
; p
++)
13053 elf_symbol_type
*q
;
13055 q
= (elf_symbol_type
*) *p
;
13057 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
13062 filename
= bfd_asymbol_name (&q
->symbol
);
13065 case STT_ARM_TFUNC
:
13067 /* Skip mapping symbols. */
13068 if ((q
->symbol
.flags
& BSF_LOCAL
)
13069 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
13070 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
13072 /* Fall through. */
13073 if (bfd_get_section (&q
->symbol
) == section
13074 && q
->symbol
.value
>= low_func
13075 && q
->symbol
.value
<= offset
)
13077 func
= (asymbol
*) q
;
13078 low_func
= q
->symbol
.value
;
13088 *filename_ptr
= filename
;
13089 if (functionname_ptr
)
13090 *functionname_ptr
= bfd_asymbol_name (func
);
13096 /* Find the nearest line to a particular section and offset, for error
13097 reporting. This code is a duplicate of the code in elf.c, except
13098 that it uses arm_elf_find_function. */
13101 elf32_arm_find_nearest_line (bfd
* abfd
,
13102 asection
* section
,
13103 asymbol
** symbols
,
13105 const char ** filename_ptr
,
13106 const char ** functionname_ptr
,
13107 unsigned int * line_ptr
)
13109 bfd_boolean found
= FALSE
;
13111 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
13113 if (_bfd_dwarf2_find_nearest_line (abfd
, dwarf_debug_sections
,
13114 section
, symbols
, offset
,
13115 filename_ptr
, functionname_ptr
,
13117 & elf_tdata (abfd
)->dwarf2_find_line_info
))
13119 if (!*functionname_ptr
)
13120 arm_elf_find_function (abfd
, section
, symbols
, offset
,
13121 *filename_ptr
? NULL
: filename_ptr
,
13127 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
13128 & found
, filename_ptr
,
13129 functionname_ptr
, line_ptr
,
13130 & elf_tdata (abfd
)->line_info
))
13133 if (found
&& (*functionname_ptr
|| *line_ptr
))
13136 if (symbols
== NULL
)
13139 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
13140 filename_ptr
, functionname_ptr
))
13148 elf32_arm_find_inliner_info (bfd
* abfd
,
13149 const char ** filename_ptr
,
13150 const char ** functionname_ptr
,
13151 unsigned int * line_ptr
)
13154 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
13155 functionname_ptr
, line_ptr
,
13156 & elf_tdata (abfd
)->dwarf2_find_line_info
);
13160 /* Adjust a symbol defined by a dynamic object and referenced by a
13161 regular object. The current definition is in some section of the
13162 dynamic object, but we're not including those sections. We have to
13163 change the definition to something the rest of the link can
13167 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
13168 struct elf_link_hash_entry
* h
)
13172 struct elf32_arm_link_hash_entry
* eh
;
13173 struct elf32_arm_link_hash_table
*globals
;
13175 globals
= elf32_arm_hash_table (info
);
13176 if (globals
== NULL
)
13179 dynobj
= elf_hash_table (info
)->dynobj
;
13181 /* Make sure we know what is going on here. */
13182 BFD_ASSERT (dynobj
!= NULL
13184 || h
->type
== STT_GNU_IFUNC
13185 || h
->u
.weakdef
!= NULL
13188 && !h
->def_regular
)));
13190 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13192 /* If this is a function, put it in the procedure linkage table. We
13193 will fill in the contents of the procedure linkage table later,
13194 when we know the address of the .got section. */
13195 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
13197 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
13198 symbol binds locally. */
13199 if (h
->plt
.refcount
<= 0
13200 || (h
->type
!= STT_GNU_IFUNC
13201 && (SYMBOL_CALLS_LOCAL (info
, h
)
13202 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
13203 && h
->root
.type
== bfd_link_hash_undefweak
))))
13205 /* This case can occur if we saw a PLT32 reloc in an input
13206 file, but the symbol was never referred to by a dynamic
13207 object, or if all references were garbage collected. In
13208 such a case, we don't actually need to build a procedure
13209 linkage table, and we can just do a PC24 reloc instead. */
13210 h
->plt
.offset
= (bfd_vma
) -1;
13211 eh
->plt
.thumb_refcount
= 0;
13212 eh
->plt
.maybe_thumb_refcount
= 0;
13213 eh
->plt
.noncall_refcount
= 0;
13221 /* It's possible that we incorrectly decided a .plt reloc was
13222 needed for an R_ARM_PC24 or similar reloc to a non-function sym
13223 in check_relocs. We can't decide accurately between function
13224 and non-function syms in check-relocs; Objects loaded later in
13225 the link may change h->type. So fix it now. */
13226 h
->plt
.offset
= (bfd_vma
) -1;
13227 eh
->plt
.thumb_refcount
= 0;
13228 eh
->plt
.maybe_thumb_refcount
= 0;
13229 eh
->plt
.noncall_refcount
= 0;
13232 /* If this is a weak symbol, and there is a real definition, the
13233 processor independent code will have arranged for us to see the
13234 real definition first, and we can just use the same value. */
13235 if (h
->u
.weakdef
!= NULL
)
13237 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
13238 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
13239 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
13240 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
13244 /* If there are no non-GOT references, we do not need a copy
13246 if (!h
->non_got_ref
)
13249 /* This is a reference to a symbol defined by a dynamic object which
13250 is not a function. */
13252 /* If we are creating a shared library, we must presume that the
13253 only references to the symbol are via the global offset table.
13254 For such cases we need not do anything here; the relocations will
13255 be handled correctly by relocate_section. Relocatable executables
13256 can reference data in shared objects directly, so we don't need to
13257 do anything here. */
13258 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
13261 /* We must allocate the symbol in our .dynbss section, which will
13262 become part of the .bss section of the executable. There will be
13263 an entry for this symbol in the .dynsym section. The dynamic
13264 object will contain position independent code, so all references
13265 from the dynamic object to this symbol will go through the global
13266 offset table. The dynamic linker will use the .dynsym entry to
13267 determine the address it must put in the global offset table, so
13268 both the dynamic object and the regular object will refer to the
13269 same memory location for the variable. */
13270 s
= bfd_get_linker_section (dynobj
, ".dynbss");
13271 BFD_ASSERT (s
!= NULL
);
13273 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
13274 copy the initial value out of the dynamic object and into the
13275 runtime process image. We need to remember the offset into the
13276 .rel(a).bss section we are going to use. */
13277 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
13281 srel
= bfd_get_linker_section (dynobj
, RELOC_SECTION (globals
, ".bss"));
13282 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
13286 return _bfd_elf_adjust_dynamic_copy (h
, s
);
13289 /* Allocate space in .plt, .got and associated reloc sections for
13293 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry
*h
, void * inf
)
13295 struct bfd_link_info
*info
;
13296 struct elf32_arm_link_hash_table
*htab
;
13297 struct elf32_arm_link_hash_entry
*eh
;
13298 struct elf_dyn_relocs
*p
;
13300 if (h
->root
.type
== bfd_link_hash_indirect
)
13303 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13305 info
= (struct bfd_link_info
*) inf
;
13306 htab
= elf32_arm_hash_table (info
);
13310 if ((htab
->root
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
13311 && h
->plt
.refcount
> 0)
13313 /* Make sure this symbol is output as a dynamic symbol.
13314 Undefined weak syms won't yet be marked as dynamic. */
13315 if (h
->dynindx
== -1
13316 && !h
->forced_local
)
13318 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13322 /* If the call in the PLT entry binds locally, the associated
13323 GOT entry should use an R_ARM_IRELATIVE relocation instead of
13324 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
13325 than the .plt section. */
13326 if (h
->type
== STT_GNU_IFUNC
&& SYMBOL_CALLS_LOCAL (info
, h
))
13329 if (eh
->plt
.noncall_refcount
== 0
13330 && SYMBOL_REFERENCES_LOCAL (info
, h
))
13331 /* All non-call references can be resolved directly.
13332 This means that they can (and in some cases, must)
13333 resolve directly to the run-time target, rather than
13334 to the PLT. That in turns means that any .got entry
13335 would be equal to the .igot.plt entry, so there's
13336 no point having both. */
13337 h
->got
.refcount
= 0;
13342 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
13344 elf32_arm_allocate_plt_entry (info
, eh
->is_iplt
, &h
->plt
, &eh
->plt
);
13346 /* If this symbol is not defined in a regular file, and we are
13347 not generating a shared library, then set the symbol to this
13348 location in the .plt. This is required to make function
13349 pointers compare as equal between the normal executable and
13350 the shared library. */
13352 && !h
->def_regular
)
13354 h
->root
.u
.def
.section
= htab
->root
.splt
;
13355 h
->root
.u
.def
.value
= h
->plt
.offset
;
13357 /* Make sure the function is not marked as Thumb, in case
13358 it is the target of an ABS32 relocation, which will
13359 point to the PLT entry. */
13360 h
->target_internal
= ST_BRANCH_TO_ARM
;
13363 htab
->next_tls_desc_index
++;
13365 /* VxWorks executables have a second set of relocations for
13366 each PLT entry. They go in a separate relocation section,
13367 which is processed by the kernel loader. */
13368 if (htab
->vxworks_p
&& !info
->shared
)
13370 /* There is a relocation for the initial PLT entry:
13371 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
13372 if (h
->plt
.offset
== htab
->plt_header_size
)
13373 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 1);
13375 /* There are two extra relocations for each subsequent
13376 PLT entry: an R_ARM_32 relocation for the GOT entry,
13377 and an R_ARM_32 relocation for the PLT entry. */
13378 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 2);
13383 h
->plt
.offset
= (bfd_vma
) -1;
13389 h
->plt
.offset
= (bfd_vma
) -1;
13393 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13394 eh
->tlsdesc_got
= (bfd_vma
) -1;
13396 if (h
->got
.refcount
> 0)
13400 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
13403 /* Make sure this symbol is output as a dynamic symbol.
13404 Undefined weak syms won't yet be marked as dynamic. */
13405 if (h
->dynindx
== -1
13406 && !h
->forced_local
)
13408 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13412 if (!htab
->symbian_p
)
13414 s
= htab
->root
.sgot
;
13415 h
->got
.offset
= s
->size
;
13417 if (tls_type
== GOT_UNKNOWN
)
13420 if (tls_type
== GOT_NORMAL
)
13421 /* Non-TLS symbols need one GOT slot. */
13425 if (tls_type
& GOT_TLS_GDESC
)
13427 /* R_ARM_TLS_DESC needs 2 GOT slots. */
13429 = (htab
->root
.sgotplt
->size
13430 - elf32_arm_compute_jump_table_size (htab
));
13431 htab
->root
.sgotplt
->size
+= 8;
13432 h
->got
.offset
= (bfd_vma
) -2;
13433 /* plt.got_offset needs to know there's a TLS_DESC
13434 reloc in the middle of .got.plt. */
13435 htab
->num_tls_desc
++;
13438 if (tls_type
& GOT_TLS_GD
)
13440 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. If
13441 the symbol is both GD and GDESC, got.offset may
13442 have been overwritten. */
13443 h
->got
.offset
= s
->size
;
13447 if (tls_type
& GOT_TLS_IE
)
13448 /* R_ARM_TLS_IE32 needs one GOT slot. */
13452 dyn
= htab
->root
.dynamic_sections_created
;
13455 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
13457 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
13460 if (tls_type
!= GOT_NORMAL
13461 && (info
->shared
|| indx
!= 0)
13462 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
13463 || h
->root
.type
!= bfd_link_hash_undefweak
))
13465 if (tls_type
& GOT_TLS_IE
)
13466 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13468 if (tls_type
& GOT_TLS_GD
)
13469 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13471 if (tls_type
& GOT_TLS_GDESC
)
13473 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
13474 /* GDESC needs a trampoline to jump to. */
13475 htab
->tls_trampoline
= -1;
13478 /* Only GD needs it. GDESC just emits one relocation per
13480 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
13481 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13483 else if (indx
!= -1 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
13485 if (htab
->root
.dynamic_sections_created
)
13486 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
13487 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13489 else if (h
->type
== STT_GNU_IFUNC
13490 && eh
->plt
.noncall_refcount
== 0)
13491 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
13492 they all resolve dynamically instead. Reserve room for the
13493 GOT entry's R_ARM_IRELATIVE relocation. */
13494 elf32_arm_allocate_irelocs (info
, htab
->root
.srelgot
, 1);
13495 else if (info
->shared
&& (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
13496 || h
->root
.type
!= bfd_link_hash_undefweak
))
13497 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
13498 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13502 h
->got
.offset
= (bfd_vma
) -1;
13504 /* Allocate stubs for exported Thumb functions on v4t. */
13505 if (!htab
->use_blx
&& h
->dynindx
!= -1
13507 && h
->target_internal
== ST_BRANCH_TO_THUMB
13508 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
13510 struct elf_link_hash_entry
* th
;
13511 struct bfd_link_hash_entry
* bh
;
13512 struct elf_link_hash_entry
* myh
;
13516 /* Create a new symbol to regist the real location of the function. */
13517 s
= h
->root
.u
.def
.section
;
13518 sprintf (name
, "__real_%s", h
->root
.root
.string
);
13519 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
13520 name
, BSF_GLOBAL
, s
,
13521 h
->root
.u
.def
.value
,
13522 NULL
, TRUE
, FALSE
, &bh
);
13524 myh
= (struct elf_link_hash_entry
*) bh
;
13525 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
13526 myh
->forced_local
= 1;
13527 myh
->target_internal
= ST_BRANCH_TO_THUMB
;
13528 eh
->export_glue
= myh
;
13529 th
= record_arm_to_thumb_glue (info
, h
);
13530 /* Point the symbol at the stub. */
13531 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
13532 h
->target_internal
= ST_BRANCH_TO_ARM
;
13533 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
13534 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
13537 if (eh
->dyn_relocs
== NULL
)
13540 /* In the shared -Bsymbolic case, discard space allocated for
13541 dynamic pc-relative relocs against symbols which turn out to be
13542 defined in regular objects. For the normal shared case, discard
13543 space for pc-relative relocs that have become local due to symbol
13544 visibility changes. */
13546 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
13548 /* The only relocs that use pc_count are R_ARM_REL32 and
13549 R_ARM_REL32_NOI, which will appear on something like
13550 ".long foo - .". We want calls to protected symbols to resolve
13551 directly to the function rather than going via the plt. If people
13552 want function pointer comparisons to work as expected then they
13553 should avoid writing assembly like ".long foo - .". */
13554 if (SYMBOL_CALLS_LOCAL (info
, h
))
13556 struct elf_dyn_relocs
**pp
;
13558 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13560 p
->count
-= p
->pc_count
;
13569 if (htab
->vxworks_p
)
13571 struct elf_dyn_relocs
**pp
;
13573 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13575 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
13582 /* Also discard relocs on undefined weak syms with non-default
13584 if (eh
->dyn_relocs
!= NULL
13585 && h
->root
.type
== bfd_link_hash_undefweak
)
13587 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
13588 eh
->dyn_relocs
= NULL
;
13590 /* Make sure undefined weak symbols are output as a dynamic
13592 else if (h
->dynindx
== -1
13593 && !h
->forced_local
)
13595 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13600 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
13601 && h
->root
.type
== bfd_link_hash_new
)
13603 /* Output absolute symbols so that we can create relocations
13604 against them. For normal symbols we output a relocation
13605 against the section that contains them. */
13606 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13613 /* For the non-shared case, discard space for relocs against
13614 symbols which turn out to need copy relocs or are not
13617 if (!h
->non_got_ref
13618 && ((h
->def_dynamic
13619 && !h
->def_regular
)
13620 || (htab
->root
.dynamic_sections_created
13621 && (h
->root
.type
== bfd_link_hash_undefweak
13622 || h
->root
.type
== bfd_link_hash_undefined
))))
13624 /* Make sure this symbol is output as a dynamic symbol.
13625 Undefined weak syms won't yet be marked as dynamic. */
13626 if (h
->dynindx
== -1
13627 && !h
->forced_local
)
13629 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13633 /* If that succeeded, we know we'll be keeping all the
13635 if (h
->dynindx
!= -1)
13639 eh
->dyn_relocs
= NULL
;
13644 /* Finally, allocate space. */
13645 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13647 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
13648 if (h
->type
== STT_GNU_IFUNC
13649 && eh
->plt
.noncall_refcount
== 0
13650 && SYMBOL_REFERENCES_LOCAL (info
, h
))
13651 elf32_arm_allocate_irelocs (info
, sreloc
, p
->count
);
13653 elf32_arm_allocate_dynrelocs (info
, sreloc
, p
->count
);
13659 /* Find any dynamic relocs that apply to read-only sections. */
13662 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
13664 struct elf32_arm_link_hash_entry
* eh
;
13665 struct elf_dyn_relocs
* p
;
13667 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13668 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13670 asection
*s
= p
->sec
;
13672 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
13674 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
13676 info
->flags
|= DF_TEXTREL
;
13678 /* Not an error, just cut short the traversal. */
13686 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
13689 struct elf32_arm_link_hash_table
*globals
;
13691 globals
= elf32_arm_hash_table (info
);
13692 if (globals
== NULL
)
13695 globals
->byteswap_code
= byteswap_code
;
13698 /* Set the sizes of the dynamic sections. */
13701 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
13702 struct bfd_link_info
* info
)
13707 bfd_boolean relocs
;
13709 struct elf32_arm_link_hash_table
*htab
;
13711 htab
= elf32_arm_hash_table (info
);
13715 dynobj
= elf_hash_table (info
)->dynobj
;
13716 BFD_ASSERT (dynobj
!= NULL
);
13717 check_use_blx (htab
);
13719 if (elf_hash_table (info
)->dynamic_sections_created
)
13721 /* Set the contents of the .interp section to the interpreter. */
13722 if (info
->executable
)
13724 s
= bfd_get_linker_section (dynobj
, ".interp");
13725 BFD_ASSERT (s
!= NULL
);
13726 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
13727 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
13731 /* Set up .got offsets for local syms, and space for local dynamic
13733 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13735 bfd_signed_vma
*local_got
;
13736 bfd_signed_vma
*end_local_got
;
13737 struct arm_local_iplt_info
**local_iplt_ptr
, *local_iplt
;
13738 char *local_tls_type
;
13739 bfd_vma
*local_tlsdesc_gotent
;
13740 bfd_size_type locsymcount
;
13741 Elf_Internal_Shdr
*symtab_hdr
;
13743 bfd_boolean is_vxworks
= htab
->vxworks_p
;
13744 unsigned int symndx
;
13746 if (! is_arm_elf (ibfd
))
13749 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
13751 struct elf_dyn_relocs
*p
;
13753 for (p
= (struct elf_dyn_relocs
*)
13754 elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
13756 if (!bfd_is_abs_section (p
->sec
)
13757 && bfd_is_abs_section (p
->sec
->output_section
))
13759 /* Input section has been discarded, either because
13760 it is a copy of a linkonce section or due to
13761 linker script /DISCARD/, so we'll be discarding
13764 else if (is_vxworks
13765 && strcmp (p
->sec
->output_section
->name
,
13768 /* Relocations in vxworks .tls_vars sections are
13769 handled specially by the loader. */
13771 else if (p
->count
!= 0)
13773 srel
= elf_section_data (p
->sec
)->sreloc
;
13774 elf32_arm_allocate_dynrelocs (info
, srel
, p
->count
);
13775 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
13776 info
->flags
|= DF_TEXTREL
;
13781 local_got
= elf_local_got_refcounts (ibfd
);
13785 symtab_hdr
= & elf_symtab_hdr (ibfd
);
13786 locsymcount
= symtab_hdr
->sh_info
;
13787 end_local_got
= local_got
+ locsymcount
;
13788 local_iplt_ptr
= elf32_arm_local_iplt (ibfd
);
13789 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
13790 local_tlsdesc_gotent
= elf32_arm_local_tlsdesc_gotent (ibfd
);
13792 s
= htab
->root
.sgot
;
13793 srel
= htab
->root
.srelgot
;
13794 for (; local_got
< end_local_got
;
13795 ++local_got
, ++local_iplt_ptr
, ++local_tls_type
,
13796 ++local_tlsdesc_gotent
, ++symndx
)
13798 *local_tlsdesc_gotent
= (bfd_vma
) -1;
13799 local_iplt
= *local_iplt_ptr
;
13800 if (local_iplt
!= NULL
)
13802 struct elf_dyn_relocs
*p
;
13804 if (local_iplt
->root
.refcount
> 0)
13806 elf32_arm_allocate_plt_entry (info
, TRUE
,
13809 if (local_iplt
->arm
.noncall_refcount
== 0)
13810 /* All references to the PLT are calls, so all
13811 non-call references can resolve directly to the
13812 run-time target. This means that the .got entry
13813 would be the same as the .igot.plt entry, so there's
13814 no point creating both. */
13819 BFD_ASSERT (local_iplt
->arm
.noncall_refcount
== 0);
13820 local_iplt
->root
.offset
= (bfd_vma
) -1;
13823 for (p
= local_iplt
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13827 psrel
= elf_section_data (p
->sec
)->sreloc
;
13828 if (local_iplt
->arm
.noncall_refcount
== 0)
13829 elf32_arm_allocate_irelocs (info
, psrel
, p
->count
);
13831 elf32_arm_allocate_dynrelocs (info
, psrel
, p
->count
);
13834 if (*local_got
> 0)
13836 Elf_Internal_Sym
*isym
;
13838 *local_got
= s
->size
;
13839 if (*local_tls_type
& GOT_TLS_GD
)
13840 /* TLS_GD relocs need an 8-byte structure in the GOT. */
13842 if (*local_tls_type
& GOT_TLS_GDESC
)
13844 *local_tlsdesc_gotent
= htab
->root
.sgotplt
->size
13845 - elf32_arm_compute_jump_table_size (htab
);
13846 htab
->root
.sgotplt
->size
+= 8;
13847 *local_got
= (bfd_vma
) -2;
13848 /* plt.got_offset needs to know there's a TLS_DESC
13849 reloc in the middle of .got.plt. */
13850 htab
->num_tls_desc
++;
13852 if (*local_tls_type
& GOT_TLS_IE
)
13855 if (*local_tls_type
& GOT_NORMAL
)
13857 /* If the symbol is both GD and GDESC, *local_got
13858 may have been overwritten. */
13859 *local_got
= s
->size
;
13863 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, symndx
);
13867 /* If all references to an STT_GNU_IFUNC PLT are calls,
13868 then all non-call references, including this GOT entry,
13869 resolve directly to the run-time target. */
13870 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
13871 && (local_iplt
== NULL
13872 || local_iplt
->arm
.noncall_refcount
== 0))
13873 elf32_arm_allocate_irelocs (info
, srel
, 1);
13874 else if (info
->shared
|| output_bfd
->flags
& DYNAMIC
)
13876 if ((info
->shared
&& !(*local_tls_type
& GOT_TLS_GDESC
))
13877 || *local_tls_type
& GOT_TLS_GD
)
13878 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
13880 if (info
->shared
&& *local_tls_type
& GOT_TLS_GDESC
)
13882 elf32_arm_allocate_dynrelocs (info
,
13883 htab
->root
.srelplt
, 1);
13884 htab
->tls_trampoline
= -1;
13889 *local_got
= (bfd_vma
) -1;
13893 if (htab
->tls_ldm_got
.refcount
> 0)
13895 /* Allocate two GOT entries and one dynamic relocation (if necessary)
13896 for R_ARM_TLS_LDM32 relocations. */
13897 htab
->tls_ldm_got
.offset
= htab
->root
.sgot
->size
;
13898 htab
->root
.sgot
->size
+= 8;
13900 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13903 htab
->tls_ldm_got
.offset
= -1;
13905 /* Allocate global sym .plt and .got entries, and space for global
13906 sym dynamic relocs. */
13907 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs_for_symbol
, info
);
13909 /* Here we rummage through the found bfds to collect glue information. */
13910 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13912 if (! is_arm_elf (ibfd
))
13915 /* Initialise mapping tables for code/data. */
13916 bfd_elf32_arm_init_maps (ibfd
);
13918 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
13919 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
13920 /* xgettext:c-format */
13921 _bfd_error_handler (_("Errors encountered processing file %s"),
13925 /* Allocate space for the glue sections now that we've sized them. */
13926 bfd_elf32_arm_allocate_interworking_sections (info
);
13928 /* For every jump slot reserved in the sgotplt, reloc_count is
13929 incremented. However, when we reserve space for TLS descriptors,
13930 it's not incremented, so in order to compute the space reserved
13931 for them, it suffices to multiply the reloc count by the jump
13933 if (htab
->root
.srelplt
)
13934 htab
->sgotplt_jump_table_size
= elf32_arm_compute_jump_table_size(htab
);
13936 if (htab
->tls_trampoline
)
13938 if (htab
->root
.splt
->size
== 0)
13939 htab
->root
.splt
->size
+= htab
->plt_header_size
;
13941 htab
->tls_trampoline
= htab
->root
.splt
->size
;
13942 htab
->root
.splt
->size
+= htab
->plt_entry_size
;
13944 /* If we're not using lazy TLS relocations, don't generate the
13945 PLT and GOT entries they require. */
13946 if (!(info
->flags
& DF_BIND_NOW
))
13948 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
13949 htab
->root
.sgot
->size
+= 4;
13951 htab
->dt_tlsdesc_plt
= htab
->root
.splt
->size
;
13952 htab
->root
.splt
->size
+= 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
);
13956 /* The check_relocs and adjust_dynamic_symbol entry points have
13957 determined the sizes of the various dynamic sections. Allocate
13958 memory for them. */
13961 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
13965 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
13968 /* It's OK to base decisions on the section name, because none
13969 of the dynobj section names depend upon the input files. */
13970 name
= bfd_get_section_name (dynobj
, s
);
13972 if (s
== htab
->root
.splt
)
13974 /* Remember whether there is a PLT. */
13975 plt
= s
->size
!= 0;
13977 else if (CONST_STRNEQ (name
, ".rel"))
13981 /* Remember whether there are any reloc sections other
13982 than .rel(a).plt and .rela.plt.unloaded. */
13983 if (s
!= htab
->root
.srelplt
&& s
!= htab
->srelplt2
)
13986 /* We use the reloc_count field as a counter if we need
13987 to copy relocs into the output file. */
13988 s
->reloc_count
= 0;
13991 else if (s
!= htab
->root
.sgot
13992 && s
!= htab
->root
.sgotplt
13993 && s
!= htab
->root
.iplt
13994 && s
!= htab
->root
.igotplt
13995 && s
!= htab
->sdynbss
)
13997 /* It's not one of our sections, so don't allocate space. */
14003 /* If we don't need this section, strip it from the
14004 output file. This is mostly to handle .rel(a).bss and
14005 .rel(a).plt. We must create both sections in
14006 create_dynamic_sections, because they must be created
14007 before the linker maps input sections to output
14008 sections. The linker does that before
14009 adjust_dynamic_symbol is called, and it is that
14010 function which decides whether anything needs to go
14011 into these sections. */
14012 s
->flags
|= SEC_EXCLUDE
;
14016 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
14019 /* Allocate memory for the section contents. */
14020 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
14021 if (s
->contents
== NULL
)
14025 if (elf_hash_table (info
)->dynamic_sections_created
)
14027 /* Add some entries to the .dynamic section. We fill in the
14028 values later, in elf32_arm_finish_dynamic_sections, but we
14029 must add the entries now so that we get the correct size for
14030 the .dynamic section. The DT_DEBUG entry is filled in by the
14031 dynamic linker and used by the debugger. */
14032 #define add_dynamic_entry(TAG, VAL) \
14033 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
14035 if (info
->executable
)
14037 if (!add_dynamic_entry (DT_DEBUG
, 0))
14043 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
14044 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
14045 || !add_dynamic_entry (DT_PLTREL
,
14046 htab
->use_rel
? DT_REL
: DT_RELA
)
14047 || !add_dynamic_entry (DT_JMPREL
, 0))
14050 if (htab
->dt_tlsdesc_plt
&&
14051 (!add_dynamic_entry (DT_TLSDESC_PLT
,0)
14052 || !add_dynamic_entry (DT_TLSDESC_GOT
,0)))
14060 if (!add_dynamic_entry (DT_REL
, 0)
14061 || !add_dynamic_entry (DT_RELSZ
, 0)
14062 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
14067 if (!add_dynamic_entry (DT_RELA
, 0)
14068 || !add_dynamic_entry (DT_RELASZ
, 0)
14069 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
14074 /* If any dynamic relocs apply to a read-only section,
14075 then we need a DT_TEXTREL entry. */
14076 if ((info
->flags
& DF_TEXTREL
) == 0)
14077 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
14080 if ((info
->flags
& DF_TEXTREL
) != 0)
14082 if (!add_dynamic_entry (DT_TEXTREL
, 0))
14085 if (htab
->vxworks_p
14086 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
14089 #undef add_dynamic_entry
14094 /* Size sections even though they're not dynamic. We use it to setup
14095 _TLS_MODULE_BASE_, if needed. */
14098 elf32_arm_always_size_sections (bfd
*output_bfd
,
14099 struct bfd_link_info
*info
)
14103 if (info
->relocatable
)
14106 tls_sec
= elf_hash_table (info
)->tls_sec
;
14110 struct elf_link_hash_entry
*tlsbase
;
14112 tlsbase
= elf_link_hash_lookup
14113 (elf_hash_table (info
), "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
14117 struct bfd_link_hash_entry
*bh
= NULL
;
14118 const struct elf_backend_data
*bed
14119 = get_elf_backend_data (output_bfd
);
14121 if (!(_bfd_generic_link_add_one_symbol
14122 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
14123 tls_sec
, 0, NULL
, FALSE
,
14124 bed
->collect
, &bh
)))
14127 tlsbase
->type
= STT_TLS
;
14128 tlsbase
= (struct elf_link_hash_entry
*)bh
;
14129 tlsbase
->def_regular
= 1;
14130 tlsbase
->other
= STV_HIDDEN
;
14131 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
14137 /* Finish up dynamic symbol handling. We set the contents of various
14138 dynamic sections here. */
14141 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
14142 struct bfd_link_info
* info
,
14143 struct elf_link_hash_entry
* h
,
14144 Elf_Internal_Sym
* sym
)
14146 struct elf32_arm_link_hash_table
*htab
;
14147 struct elf32_arm_link_hash_entry
*eh
;
14149 htab
= elf32_arm_hash_table (info
);
14153 eh
= (struct elf32_arm_link_hash_entry
*) h
;
14155 if (h
->plt
.offset
!= (bfd_vma
) -1)
14159 BFD_ASSERT (h
->dynindx
!= -1);
14160 if (! elf32_arm_populate_plt_entry (output_bfd
, info
, &h
->plt
, &eh
->plt
,
14165 if (!h
->def_regular
)
14167 /* Mark the symbol as undefined, rather than as defined in
14168 the .plt section. Leave the value alone. */
14169 sym
->st_shndx
= SHN_UNDEF
;
14170 /* If the symbol is weak, we do need to clear the value.
14171 Otherwise, the PLT entry would provide a definition for
14172 the symbol even if the symbol wasn't defined anywhere,
14173 and so the symbol would never be NULL. */
14174 if (!h
->ref_regular_nonweak
|| !h
->pointer_equality_needed
)
14177 else if (eh
->is_iplt
&& eh
->plt
.noncall_refcount
!= 0)
14179 /* At least one non-call relocation references this .iplt entry,
14180 so the .iplt entry is the function's canonical address. */
14181 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
14182 sym
->st_target_internal
= ST_BRANCH_TO_ARM
;
14183 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
14184 (output_bfd
, htab
->root
.iplt
->output_section
));
14185 sym
->st_value
= (h
->plt
.offset
14186 + htab
->root
.iplt
->output_section
->vma
14187 + htab
->root
.iplt
->output_offset
);
14194 Elf_Internal_Rela rel
;
14196 /* This symbol needs a copy reloc. Set it up. */
14197 BFD_ASSERT (h
->dynindx
!= -1
14198 && (h
->root
.type
== bfd_link_hash_defined
14199 || h
->root
.type
== bfd_link_hash_defweak
));
14202 BFD_ASSERT (s
!= NULL
);
14205 rel
.r_offset
= (h
->root
.u
.def
.value
14206 + h
->root
.u
.def
.section
->output_section
->vma
14207 + h
->root
.u
.def
.section
->output_offset
);
14208 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
14209 elf32_arm_add_dynreloc (output_bfd
, info
, s
, &rel
);
14212 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
14213 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
14214 to the ".got" section. */
14215 if (h
== htab
->root
.hdynamic
14216 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
14217 sym
->st_shndx
= SHN_ABS
;
14223 arm_put_trampoline (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
14225 const unsigned long *template, unsigned count
)
14229 for (ix
= 0; ix
!= count
; ix
++)
14231 unsigned long insn
= template[ix
];
14233 /* Emit mov pc,rx if bx is not permitted. */
14234 if (htab
->fix_v4bx
== 1 && (insn
& 0x0ffffff0) == 0x012fff10)
14235 insn
= (insn
& 0xf000000f) | 0x01a0f000;
14236 put_arm_insn (htab
, output_bfd
, insn
, (char *)contents
+ ix
*4);
14240 /* Install the special first PLT entry for elf32-arm-nacl. Unlike
14241 other variants, NaCl needs this entry in a static executable's
14242 .iplt too. When we're handling that case, GOT_DISPLACEMENT is
14243 zero. For .iplt really only the last bundle is useful, and .iplt
14244 could have a shorter first entry, with each individual PLT entry's
14245 relative branch calculated differently so it targets the last
14246 bundle instead of the instruction before it (labelled .Lplt_tail
14247 above). But it's simpler to keep the size and layout of PLT0
14248 consistent with the dynamic case, at the cost of some dead code at
14249 the start of .iplt and the one dead store to the stack at the start
14252 arm_nacl_put_plt0 (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
14253 asection
*plt
, bfd_vma got_displacement
)
14257 put_arm_insn (htab
, output_bfd
,
14258 elf32_arm_nacl_plt0_entry
[0]
14259 | arm_movw_immediate (got_displacement
),
14260 plt
->contents
+ 0);
14261 put_arm_insn (htab
, output_bfd
,
14262 elf32_arm_nacl_plt0_entry
[1]
14263 | arm_movt_immediate (got_displacement
),
14264 plt
->contents
+ 4);
14266 for (i
= 2; i
< ARRAY_SIZE (elf32_arm_nacl_plt0_entry
); ++i
)
14267 put_arm_insn (htab
, output_bfd
,
14268 elf32_arm_nacl_plt0_entry
[i
],
14269 plt
->contents
+ (i
* 4));
14272 /* Finish up the dynamic sections. */
14275 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
14280 struct elf32_arm_link_hash_table
*htab
;
14282 htab
= elf32_arm_hash_table (info
);
14286 dynobj
= elf_hash_table (info
)->dynobj
;
14288 sgot
= htab
->root
.sgotplt
;
14289 /* A broken linker script might have discarded the dynamic sections.
14290 Catch this here so that we do not seg-fault later on. */
14291 if (sgot
!= NULL
&& bfd_is_abs_section (sgot
->output_section
))
14293 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
14295 if (elf_hash_table (info
)->dynamic_sections_created
)
14298 Elf32_External_Dyn
*dyncon
, *dynconend
;
14300 splt
= htab
->root
.splt
;
14301 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
14302 BFD_ASSERT (htab
->symbian_p
|| sgot
!= NULL
);
14304 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
14305 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
14307 for (; dyncon
< dynconend
; dyncon
++)
14309 Elf_Internal_Dyn dyn
;
14313 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
14320 if (htab
->vxworks_p
14321 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
14322 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14327 goto get_vma_if_bpabi
;
14330 goto get_vma_if_bpabi
;
14333 goto get_vma_if_bpabi
;
14335 name
= ".gnu.version";
14336 goto get_vma_if_bpabi
;
14338 name
= ".gnu.version_d";
14339 goto get_vma_if_bpabi
;
14341 name
= ".gnu.version_r";
14342 goto get_vma_if_bpabi
;
14348 name
= RELOC_SECTION (htab
, ".plt");
14350 s
= bfd_get_section_by_name (output_bfd
, name
);
14353 /* PR ld/14397: Issue an error message if a required section is missing. */
14354 (*_bfd_error_handler
)
14355 (_("error: required section '%s' not found in the linker script"), name
);
14356 bfd_set_error (bfd_error_invalid_operation
);
14359 if (!htab
->symbian_p
)
14360 dyn
.d_un
.d_ptr
= s
->vma
;
14362 /* In the BPABI, tags in the PT_DYNAMIC section point
14363 at the file offset, not the memory address, for the
14364 convenience of the post linker. */
14365 dyn
.d_un
.d_ptr
= s
->filepos
;
14366 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14370 if (htab
->symbian_p
)
14375 s
= htab
->root
.srelplt
;
14376 BFD_ASSERT (s
!= NULL
);
14377 dyn
.d_un
.d_val
= s
->size
;
14378 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14383 if (!htab
->symbian_p
)
14385 /* My reading of the SVR4 ABI indicates that the
14386 procedure linkage table relocs (DT_JMPREL) should be
14387 included in the overall relocs (DT_REL). This is
14388 what Solaris does. However, UnixWare can not handle
14389 that case. Therefore, we override the DT_RELSZ entry
14390 here to make it not include the JMPREL relocs. Since
14391 the linker script arranges for .rel(a).plt to follow all
14392 other relocation sections, we don't have to worry
14393 about changing the DT_REL entry. */
14394 s
= htab
->root
.srelplt
;
14396 dyn
.d_un
.d_val
-= s
->size
;
14397 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14400 /* Fall through. */
14404 /* In the BPABI, the DT_REL tag must point at the file
14405 offset, not the VMA, of the first relocation
14406 section. So, we use code similar to that in
14407 elflink.c, but do not check for SHF_ALLOC on the
14408 relcoation section, since relocations sections are
14409 never allocated under the BPABI. The comments above
14410 about Unixware notwithstanding, we include all of the
14411 relocations here. */
14412 if (htab
->symbian_p
)
14415 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
14416 ? SHT_REL
: SHT_RELA
);
14417 dyn
.d_un
.d_val
= 0;
14418 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
14420 Elf_Internal_Shdr
*hdr
14421 = elf_elfsections (output_bfd
)[i
];
14422 if (hdr
->sh_type
== type
)
14424 if (dyn
.d_tag
== DT_RELSZ
14425 || dyn
.d_tag
== DT_RELASZ
)
14426 dyn
.d_un
.d_val
+= hdr
->sh_size
;
14427 else if ((ufile_ptr
) hdr
->sh_offset
14428 <= dyn
.d_un
.d_val
- 1)
14429 dyn
.d_un
.d_val
= hdr
->sh_offset
;
14432 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14436 case DT_TLSDESC_PLT
:
14437 s
= htab
->root
.splt
;
14438 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
14439 + htab
->dt_tlsdesc_plt
);
14440 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14443 case DT_TLSDESC_GOT
:
14444 s
= htab
->root
.sgot
;
14445 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
14446 + htab
->dt_tlsdesc_got
);
14447 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14450 /* Set the bottom bit of DT_INIT/FINI if the
14451 corresponding function is Thumb. */
14453 name
= info
->init_function
;
14456 name
= info
->fini_function
;
14458 /* If it wasn't set by elf_bfd_final_link
14459 then there is nothing to adjust. */
14460 if (dyn
.d_un
.d_val
!= 0)
14462 struct elf_link_hash_entry
* eh
;
14464 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
14465 FALSE
, FALSE
, TRUE
);
14466 if (eh
!= NULL
&& eh
->target_internal
== ST_BRANCH_TO_THUMB
)
14468 dyn
.d_un
.d_val
|= 1;
14469 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
14476 /* Fill in the first entry in the procedure linkage table. */
14477 if (splt
->size
> 0 && htab
->plt_header_size
)
14479 const bfd_vma
*plt0_entry
;
14480 bfd_vma got_address
, plt_address
, got_displacement
;
14482 /* Calculate the addresses of the GOT and PLT. */
14483 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
14484 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
14486 if (htab
->vxworks_p
)
14488 /* The VxWorks GOT is relocated by the dynamic linker.
14489 Therefore, we must emit relocations rather than simply
14490 computing the values now. */
14491 Elf_Internal_Rela rel
;
14493 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
14494 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
14495 splt
->contents
+ 0);
14496 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
14497 splt
->contents
+ 4);
14498 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
14499 splt
->contents
+ 8);
14500 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
14502 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
14503 rel
.r_offset
= plt_address
+ 12;
14504 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
14506 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
14507 htab
->srelplt2
->contents
);
14509 else if (htab
->nacl_p
)
14510 arm_nacl_put_plt0 (htab
, output_bfd
, splt
,
14511 got_address
+ 8 - (plt_address
+ 16));
14512 else if (using_thumb_only (htab
))
14514 got_displacement
= got_address
- (plt_address
+ 12);
14516 plt0_entry
= elf32_thumb2_plt0_entry
;
14517 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
14518 splt
->contents
+ 0);
14519 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
14520 splt
->contents
+ 4);
14521 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
14522 splt
->contents
+ 8);
14524 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 12);
14528 got_displacement
= got_address
- (plt_address
+ 16);
14530 plt0_entry
= elf32_arm_plt0_entry
;
14531 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
14532 splt
->contents
+ 0);
14533 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
14534 splt
->contents
+ 4);
14535 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
14536 splt
->contents
+ 8);
14537 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
14538 splt
->contents
+ 12);
14540 #ifdef FOUR_WORD_PLT
14541 /* The displacement value goes in the otherwise-unused
14542 last word of the second entry. */
14543 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
14545 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
14550 /* UnixWare sets the entsize of .plt to 4, although that doesn't
14551 really seem like the right value. */
14552 if (splt
->output_section
->owner
== output_bfd
)
14553 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
14555 if (htab
->dt_tlsdesc_plt
)
14557 bfd_vma got_address
14558 = sgot
->output_section
->vma
+ sgot
->output_offset
;
14559 bfd_vma gotplt_address
= (htab
->root
.sgot
->output_section
->vma
14560 + htab
->root
.sgot
->output_offset
);
14561 bfd_vma plt_address
14562 = splt
->output_section
->vma
+ splt
->output_offset
;
14564 arm_put_trampoline (htab
, output_bfd
,
14565 splt
->contents
+ htab
->dt_tlsdesc_plt
,
14566 dl_tlsdesc_lazy_trampoline
, 6);
14568 bfd_put_32 (output_bfd
,
14569 gotplt_address
+ htab
->dt_tlsdesc_got
14570 - (plt_address
+ htab
->dt_tlsdesc_plt
)
14571 - dl_tlsdesc_lazy_trampoline
[6],
14572 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24);
14573 bfd_put_32 (output_bfd
,
14574 got_address
- (plt_address
+ htab
->dt_tlsdesc_plt
)
14575 - dl_tlsdesc_lazy_trampoline
[7],
14576 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24 + 4);
14579 if (htab
->tls_trampoline
)
14581 arm_put_trampoline (htab
, output_bfd
,
14582 splt
->contents
+ htab
->tls_trampoline
,
14583 tls_trampoline
, 3);
14584 #ifdef FOUR_WORD_PLT
14585 bfd_put_32 (output_bfd
, 0x00000000,
14586 splt
->contents
+ htab
->tls_trampoline
+ 12);
14590 if (htab
->vxworks_p
&& !info
->shared
&& htab
->root
.splt
->size
> 0)
14592 /* Correct the .rel(a).plt.unloaded relocations. They will have
14593 incorrect symbol indexes. */
14597 num_plts
= ((htab
->root
.splt
->size
- htab
->plt_header_size
)
14598 / htab
->plt_entry_size
);
14599 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
14601 for (; num_plts
; num_plts
--)
14603 Elf_Internal_Rela rel
;
14605 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14606 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
14607 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14608 p
+= RELOC_SIZE (htab
);
14610 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14611 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
14612 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14613 p
+= RELOC_SIZE (htab
);
14618 if (htab
->nacl_p
&& htab
->root
.iplt
!= NULL
&& htab
->root
.iplt
->size
> 0)
14619 /* NaCl uses a special first entry in .iplt too. */
14620 arm_nacl_put_plt0 (htab
, output_bfd
, htab
->root
.iplt
, 0);
14622 /* Fill in the first three entries in the global offset table. */
14625 if (sgot
->size
> 0)
14628 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
14630 bfd_put_32 (output_bfd
,
14631 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
14633 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
14634 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
14637 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
14644 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
14646 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
14647 struct elf32_arm_link_hash_table
*globals
;
14649 i_ehdrp
= elf_elfheader (abfd
);
14651 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
14652 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
14654 _bfd_elf_post_process_headers (abfd
, link_info
);
14655 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
14659 globals
= elf32_arm_hash_table (link_info
);
14660 if (globals
!= NULL
&& globals
->byteswap_code
)
14661 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
14664 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_VER5
14665 && ((i_ehdrp
->e_type
== ET_DYN
) || (i_ehdrp
->e_type
== ET_EXEC
)))
14667 int abi
= bfd_elf_get_obj_attr_int (abfd
, OBJ_ATTR_PROC
, Tag_ABI_VFP_args
);
14669 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_HARD
;
14671 i_ehdrp
->e_flags
|= EF_ARM_ABI_FLOAT_SOFT
;
14675 static enum elf_reloc_type_class
14676 elf32_arm_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
14677 const asection
*rel_sec ATTRIBUTE_UNUSED
,
14678 const Elf_Internal_Rela
*rela
)
14680 switch ((int) ELF32_R_TYPE (rela
->r_info
))
14682 case R_ARM_RELATIVE
:
14683 return reloc_class_relative
;
14684 case R_ARM_JUMP_SLOT
:
14685 return reloc_class_plt
;
14687 return reloc_class_copy
;
14689 return reloc_class_normal
;
14694 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
14696 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
14699 /* Return TRUE if this is an unwinding table entry. */
14702 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
14704 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
14705 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
14709 /* Set the type and flags for an ARM section. We do this by
14710 the section name, which is a hack, but ought to work. */
14713 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
14717 name
= bfd_get_section_name (abfd
, sec
);
14719 if (is_arm_elf_unwind_section_name (abfd
, name
))
14721 hdr
->sh_type
= SHT_ARM_EXIDX
;
14722 hdr
->sh_flags
|= SHF_LINK_ORDER
;
14727 /* Handle an ARM specific section when reading an object file. This is
14728 called when bfd_section_from_shdr finds a section with an unknown
14732 elf32_arm_section_from_shdr (bfd
*abfd
,
14733 Elf_Internal_Shdr
* hdr
,
14737 /* There ought to be a place to keep ELF backend specific flags, but
14738 at the moment there isn't one. We just keep track of the
14739 sections by their name, instead. Fortunately, the ABI gives
14740 names for all the ARM specific sections, so we will probably get
14742 switch (hdr
->sh_type
)
14744 case SHT_ARM_EXIDX
:
14745 case SHT_ARM_PREEMPTMAP
:
14746 case SHT_ARM_ATTRIBUTES
:
14753 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
14759 static _arm_elf_section_data
*
14760 get_arm_elf_section_data (asection
* sec
)
14762 if (sec
&& sec
->owner
&& is_arm_elf (sec
->owner
))
14763 return elf32_arm_section_data (sec
);
14771 struct bfd_link_info
*info
;
14774 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
14775 asection
*, struct elf_link_hash_entry
*);
14776 } output_arch_syminfo
;
14778 enum map_symbol_type
14786 /* Output a single mapping symbol. */
14789 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
14790 enum map_symbol_type type
,
14793 static const char *names
[3] = {"$a", "$t", "$d"};
14794 Elf_Internal_Sym sym
;
14796 sym
.st_value
= osi
->sec
->output_section
->vma
14797 + osi
->sec
->output_offset
14801 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
14802 sym
.st_shndx
= osi
->sec_shndx
;
14803 sym
.st_target_internal
= 0;
14804 elf32_arm_section_map_add (osi
->sec
, names
[type
][1], offset
);
14805 return osi
->func (osi
->flaginfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
14808 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
14809 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
14812 elf32_arm_output_plt_map_1 (output_arch_syminfo
*osi
,
14813 bfd_boolean is_iplt_entry_p
,
14814 union gotplt_union
*root_plt
,
14815 struct arm_plt_info
*arm_plt
)
14817 struct elf32_arm_link_hash_table
*htab
;
14818 bfd_vma addr
, plt_header_size
;
14820 if (root_plt
->offset
== (bfd_vma
) -1)
14823 htab
= elf32_arm_hash_table (osi
->info
);
14827 if (is_iplt_entry_p
)
14829 osi
->sec
= htab
->root
.iplt
;
14830 plt_header_size
= 0;
14834 osi
->sec
= htab
->root
.splt
;
14835 plt_header_size
= htab
->plt_header_size
;
14837 osi
->sec_shndx
= (_bfd_elf_section_from_bfd_section
14838 (osi
->info
->output_bfd
, osi
->sec
->output_section
));
14840 addr
= root_plt
->offset
& -2;
14841 if (htab
->symbian_p
)
14843 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14845 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
14848 else if (htab
->vxworks_p
)
14850 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14852 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
14854 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
14856 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
14859 else if (htab
->nacl_p
)
14861 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14864 else if (using_thumb_only (htab
))
14866 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
))
14871 bfd_boolean thumb_stub_p
;
14873 thumb_stub_p
= elf32_arm_plt_needs_thumb_stub_p (osi
->info
, arm_plt
);
14876 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
14879 #ifdef FOUR_WORD_PLT
14880 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14882 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
14885 /* A three-word PLT with no Thumb thunk contains only Arm code,
14886 so only need to output a mapping symbol for the first PLT entry and
14887 entries with thumb thunks. */
14888 if (thumb_stub_p
|| addr
== plt_header_size
)
14890 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14899 /* Output mapping symbols for PLT entries associated with H. */
14902 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
14904 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
14905 struct elf32_arm_link_hash_entry
*eh
;
14907 if (h
->root
.type
== bfd_link_hash_indirect
)
14910 if (h
->root
.type
== bfd_link_hash_warning
)
14911 /* When warning symbols are created, they **replace** the "real"
14912 entry in the hash table, thus we never get to see the real
14913 symbol in a hash traversal. So look at it now. */
14914 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
14916 eh
= (struct elf32_arm_link_hash_entry
*) h
;
14917 return elf32_arm_output_plt_map_1 (osi
, SYMBOL_CALLS_LOCAL (osi
->info
, h
),
14918 &h
->plt
, &eh
->plt
);
14921 /* Output a single local symbol for a generated stub. */
14924 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
14925 bfd_vma offset
, bfd_vma size
)
14927 Elf_Internal_Sym sym
;
14929 sym
.st_value
= osi
->sec
->output_section
->vma
14930 + osi
->sec
->output_offset
14932 sym
.st_size
= size
;
14934 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
14935 sym
.st_shndx
= osi
->sec_shndx
;
14936 sym
.st_target_internal
= 0;
14937 return osi
->func (osi
->flaginfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
14941 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
14944 struct elf32_arm_stub_hash_entry
*stub_entry
;
14945 asection
*stub_sec
;
14948 output_arch_syminfo
*osi
;
14949 const insn_sequence
*template_sequence
;
14950 enum stub_insn_type prev_type
;
14953 enum map_symbol_type sym_type
;
14955 /* Massage our args to the form they really have. */
14956 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
14957 osi
= (output_arch_syminfo
*) in_arg
;
14959 stub_sec
= stub_entry
->stub_sec
;
14961 /* Ensure this stub is attached to the current section being
14963 if (stub_sec
!= osi
->sec
)
14966 addr
= (bfd_vma
) stub_entry
->stub_offset
;
14967 stub_name
= stub_entry
->output_name
;
14969 template_sequence
= stub_entry
->stub_template
;
14970 switch (template_sequence
[0].type
)
14973 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, stub_entry
->stub_size
))
14978 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
14979 stub_entry
->stub_size
))
14987 prev_type
= DATA_TYPE
;
14989 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
14991 switch (template_sequence
[i
].type
)
14994 sym_type
= ARM_MAP_ARM
;
14999 sym_type
= ARM_MAP_THUMB
;
15003 sym_type
= ARM_MAP_DATA
;
15011 if (template_sequence
[i
].type
!= prev_type
)
15013 prev_type
= template_sequence
[i
].type
;
15014 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
15018 switch (template_sequence
[i
].type
)
15042 /* Output mapping symbols for linker generated sections,
15043 and for those data-only sections that do not have a
15047 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
15048 struct bfd_link_info
*info
,
15050 int (*func
) (void *, const char *,
15051 Elf_Internal_Sym
*,
15053 struct elf_link_hash_entry
*))
15055 output_arch_syminfo osi
;
15056 struct elf32_arm_link_hash_table
*htab
;
15058 bfd_size_type size
;
15061 htab
= elf32_arm_hash_table (info
);
15065 check_use_blx (htab
);
15067 osi
.flaginfo
= flaginfo
;
15071 /* Add a $d mapping symbol to data-only sections that
15072 don't have any mapping symbol. This may result in (harmless) redundant
15073 mapping symbols. */
15074 for (input_bfd
= info
->input_bfds
;
15076 input_bfd
= input_bfd
->link
.next
)
15078 if ((input_bfd
->flags
& (BFD_LINKER_CREATED
| HAS_SYMS
)) == HAS_SYMS
)
15079 for (osi
.sec
= input_bfd
->sections
;
15081 osi
.sec
= osi
.sec
->next
)
15083 if (osi
.sec
->output_section
!= NULL
15084 && ((osi
.sec
->output_section
->flags
& (SEC_ALLOC
| SEC_CODE
))
15086 && (osi
.sec
->flags
& (SEC_HAS_CONTENTS
| SEC_LINKER_CREATED
))
15087 == SEC_HAS_CONTENTS
15088 && get_arm_elf_section_data (osi
.sec
) != NULL
15089 && get_arm_elf_section_data (osi
.sec
)->mapcount
== 0
15090 && osi
.sec
->size
> 0
15091 && (osi
.sec
->flags
& SEC_EXCLUDE
) == 0)
15093 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15094 (output_bfd
, osi
.sec
->output_section
);
15095 if (osi
.sec_shndx
!= (int)SHN_BAD
)
15096 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 0);
15101 /* ARM->Thumb glue. */
15102 if (htab
->arm_glue_size
> 0)
15104 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
15105 ARM2THUMB_GLUE_SECTION_NAME
);
15107 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15108 (output_bfd
, osi
.sec
->output_section
);
15109 if (info
->shared
|| htab
->root
.is_relocatable_executable
15110 || htab
->pic_veneer
)
15111 size
= ARM2THUMB_PIC_GLUE_SIZE
;
15112 else if (htab
->use_blx
)
15113 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
15115 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
15117 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
15119 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
15120 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
15124 /* Thumb->ARM glue. */
15125 if (htab
->thumb_glue_size
> 0)
15127 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
15128 THUMB2ARM_GLUE_SECTION_NAME
);
15130 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15131 (output_bfd
, osi
.sec
->output_section
);
15132 size
= THUMB2ARM_GLUE_SIZE
;
15134 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
15136 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
15137 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
15141 /* ARMv4 BX veneers. */
15142 if (htab
->bx_glue_size
> 0)
15144 osi
.sec
= bfd_get_linker_section (htab
->bfd_of_glue_owner
,
15145 ARM_BX_GLUE_SECTION_NAME
);
15147 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15148 (output_bfd
, osi
.sec
->output_section
);
15150 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
15153 /* Long calls stubs. */
15154 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
15156 asection
* stub_sec
;
15158 for (stub_sec
= htab
->stub_bfd
->sections
;
15160 stub_sec
= stub_sec
->next
)
15162 /* Ignore non-stub sections. */
15163 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
15166 osi
.sec
= stub_sec
;
15168 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
15169 (output_bfd
, osi
.sec
->output_section
);
15171 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
15175 /* Finally, output mapping symbols for the PLT. */
15176 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
15178 osi
.sec
= htab
->root
.splt
;
15179 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
15180 (output_bfd
, osi
.sec
->output_section
));
15182 /* Output mapping symbols for the plt header. SymbianOS does not have a
15184 if (htab
->vxworks_p
)
15186 /* VxWorks shared libraries have no PLT header. */
15189 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15191 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
15195 else if (htab
->nacl_p
)
15197 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15200 else if (using_thumb_only (htab
))
15202 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, 0))
15204 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
15206 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, 16))
15209 else if (!htab
->symbian_p
)
15211 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15213 #ifndef FOUR_WORD_PLT
15214 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
15219 if (htab
->nacl_p
&& htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0)
15221 /* NaCl uses a special first entry in .iplt too. */
15222 osi
.sec
= htab
->root
.iplt
;
15223 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
15224 (output_bfd
, osi
.sec
->output_section
));
15225 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
15228 if ((htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
15229 || (htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0))
15231 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, &osi
);
15232 for (input_bfd
= info
->input_bfds
;
15234 input_bfd
= input_bfd
->link
.next
)
15236 struct arm_local_iplt_info
**local_iplt
;
15237 unsigned int i
, num_syms
;
15239 local_iplt
= elf32_arm_local_iplt (input_bfd
);
15240 if (local_iplt
!= NULL
)
15242 num_syms
= elf_symtab_hdr (input_bfd
).sh_info
;
15243 for (i
= 0; i
< num_syms
; i
++)
15244 if (local_iplt
[i
] != NULL
15245 && !elf32_arm_output_plt_map_1 (&osi
, TRUE
,
15246 &local_iplt
[i
]->root
,
15247 &local_iplt
[i
]->arm
))
15252 if (htab
->dt_tlsdesc_plt
!= 0)
15254 /* Mapping symbols for the lazy tls trampoline. */
15255 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->dt_tlsdesc_plt
))
15258 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
15259 htab
->dt_tlsdesc_plt
+ 24))
15262 if (htab
->tls_trampoline
!= 0)
15264 /* Mapping symbols for the tls trampoline. */
15265 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->tls_trampoline
))
15267 #ifdef FOUR_WORD_PLT
15268 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
15269 htab
->tls_trampoline
+ 12))
15277 /* Allocate target specific section data. */
15280 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
15282 if (!sec
->used_by_bfd
)
15284 _arm_elf_section_data
*sdata
;
15285 bfd_size_type amt
= sizeof (*sdata
);
15287 sdata
= (_arm_elf_section_data
*) bfd_zalloc (abfd
, amt
);
15290 sec
->used_by_bfd
= sdata
;
15293 return _bfd_elf_new_section_hook (abfd
, sec
);
15297 /* Used to order a list of mapping symbols by address. */
15300 elf32_arm_compare_mapping (const void * a
, const void * b
)
15302 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
15303 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
15305 if (amap
->vma
> bmap
->vma
)
15307 else if (amap
->vma
< bmap
->vma
)
15309 else if (amap
->type
> bmap
->type
)
15310 /* Ensure results do not depend on the host qsort for objects with
15311 multiple mapping symbols at the same address by sorting on type
15314 else if (amap
->type
< bmap
->type
)
15320 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
15322 static unsigned long
15323 offset_prel31 (unsigned long addr
, bfd_vma offset
)
15325 return (addr
& ~0x7ffffffful
) | ((addr
+ offset
) & 0x7ffffffful
);
15328 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
15332 copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
, bfd_vma offset
)
15334 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
15335 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
15337 /* High bit of first word is supposed to be zero. */
15338 if ((first_word
& 0x80000000ul
) == 0)
15339 first_word
= offset_prel31 (first_word
, offset
);
15341 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
15342 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
15343 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
15344 second_word
= offset_prel31 (second_word
, offset
);
15346 bfd_put_32 (output_bfd
, first_word
, to
);
15347 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
15350 /* Data for make_branch_to_a8_stub(). */
15352 struct a8_branch_to_stub_data
15354 asection
*writing_section
;
15355 bfd_byte
*contents
;
15359 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
15360 places for a particular section. */
15363 make_branch_to_a8_stub (struct bfd_hash_entry
*gen_entry
,
15366 struct elf32_arm_stub_hash_entry
*stub_entry
;
15367 struct a8_branch_to_stub_data
*data
;
15368 bfd_byte
*contents
;
15369 unsigned long branch_insn
;
15370 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
15371 bfd_signed_vma branch_offset
;
15373 unsigned int target
;
15375 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
15376 data
= (struct a8_branch_to_stub_data
*) in_arg
;
15378 if (stub_entry
->target_section
!= data
->writing_section
15379 || stub_entry
->stub_type
< arm_stub_a8_veneer_lwm
)
15382 contents
= data
->contents
;
15384 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
15385 + stub_entry
->target_section
->output_offset
15386 + stub_entry
->target_value
;
15388 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
15389 + stub_entry
->stub_sec
->output_offset
15390 + stub_entry
->stub_offset
;
15392 if (stub_entry
->stub_type
== arm_stub_a8_veneer_blx
)
15393 veneered_insn_loc
&= ~3u;
15395 branch_offset
= veneer_entry_loc
- veneered_insn_loc
- 4;
15397 abfd
= stub_entry
->target_section
->owner
;
15398 target
= stub_entry
->target_value
;
15400 /* We attempt to avoid this condition by setting stubs_always_after_branch
15401 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
15402 This check is just to be on the safe side... */
15403 if ((veneered_insn_loc
& ~0xfff) == (veneer_entry_loc
& ~0xfff))
15405 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub is "
15406 "allocated in unsafe location"), abfd
);
15410 switch (stub_entry
->stub_type
)
15412 case arm_stub_a8_veneer_b
:
15413 case arm_stub_a8_veneer_b_cond
:
15414 branch_insn
= 0xf0009000;
15417 case arm_stub_a8_veneer_blx
:
15418 branch_insn
= 0xf000e800;
15421 case arm_stub_a8_veneer_bl
:
15423 unsigned int i1
, j1
, i2
, j2
, s
;
15425 branch_insn
= 0xf000d000;
15428 if (branch_offset
< -16777216 || branch_offset
> 16777214)
15430 /* There's not much we can do apart from complain if this
15432 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub out "
15433 "of range (input file too large)"), abfd
);
15437 /* i1 = not(j1 eor s), so:
15439 j1 = (not i1) eor s. */
15441 branch_insn
|= (branch_offset
>> 1) & 0x7ff;
15442 branch_insn
|= ((branch_offset
>> 12) & 0x3ff) << 16;
15443 i2
= (branch_offset
>> 22) & 1;
15444 i1
= (branch_offset
>> 23) & 1;
15445 s
= (branch_offset
>> 24) & 1;
15448 branch_insn
|= j2
<< 11;
15449 branch_insn
|= j1
<< 13;
15450 branch_insn
|= s
<< 26;
15459 bfd_put_16 (abfd
, (branch_insn
>> 16) & 0xffff, &contents
[target
]);
15460 bfd_put_16 (abfd
, branch_insn
& 0xffff, &contents
[target
+ 2]);
15465 /* Do code byteswapping. Return FALSE afterwards so that the section is
15466 written out as normal. */
15469 elf32_arm_write_section (bfd
*output_bfd
,
15470 struct bfd_link_info
*link_info
,
15472 bfd_byte
*contents
)
15474 unsigned int mapcount
, errcount
;
15475 _arm_elf_section_data
*arm_data
;
15476 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
15477 elf32_arm_section_map
*map
;
15478 elf32_vfp11_erratum_list
*errnode
;
15481 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
15485 if (globals
== NULL
)
15488 /* If this section has not been allocated an _arm_elf_section_data
15489 structure then we cannot record anything. */
15490 arm_data
= get_arm_elf_section_data (sec
);
15491 if (arm_data
== NULL
)
15494 mapcount
= arm_data
->mapcount
;
15495 map
= arm_data
->map
;
15496 errcount
= arm_data
->erratumcount
;
15500 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
15502 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
15503 errnode
= errnode
->next
)
15505 bfd_vma target
= errnode
->vma
- offset
;
15507 switch (errnode
->type
)
15509 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
15511 bfd_vma branch_to_veneer
;
15512 /* Original condition code of instruction, plus bit mask for
15513 ARM B instruction. */
15514 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
15517 /* The instruction is before the label. */
15520 /* Above offset included in -4 below. */
15521 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
15522 - errnode
->vma
- 4;
15524 if ((signed) branch_to_veneer
< -(1 << 25)
15525 || (signed) branch_to_veneer
>= (1 << 25))
15526 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
15527 "range"), output_bfd
);
15529 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
15530 contents
[endianflip
^ target
] = insn
& 0xff;
15531 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
15532 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
15533 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
15537 case VFP11_ERRATUM_ARM_VENEER
:
15539 bfd_vma branch_from_veneer
;
15542 /* Take size of veneer into account. */
15543 branch_from_veneer
= errnode
->u
.v
.branch
->vma
15544 - errnode
->vma
- 12;
15546 if ((signed) branch_from_veneer
< -(1 << 25)
15547 || (signed) branch_from_veneer
>= (1 << 25))
15548 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
15549 "range"), output_bfd
);
15551 /* Original instruction. */
15552 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
15553 contents
[endianflip
^ target
] = insn
& 0xff;
15554 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
15555 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
15556 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
15558 /* Branch back to insn after original insn. */
15559 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
15560 contents
[endianflip
^ (target
+ 4)] = insn
& 0xff;
15561 contents
[endianflip
^ (target
+ 5)] = (insn
>> 8) & 0xff;
15562 contents
[endianflip
^ (target
+ 6)] = (insn
>> 16) & 0xff;
15563 contents
[endianflip
^ (target
+ 7)] = (insn
>> 24) & 0xff;
15573 if (arm_data
->elf
.this_hdr
.sh_type
== SHT_ARM_EXIDX
)
15575 arm_unwind_table_edit
*edit_node
15576 = arm_data
->u
.exidx
.unwind_edit_list
;
15577 /* Now, sec->size is the size of the section we will write. The original
15578 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
15579 markers) was sec->rawsize. (This isn't the case if we perform no
15580 edits, then rawsize will be zero and we should use size). */
15581 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
15582 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
15583 unsigned int in_index
, out_index
;
15584 bfd_vma add_to_offsets
= 0;
15586 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
15590 unsigned int edit_index
= edit_node
->index
;
15592 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
15594 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
15595 contents
+ in_index
* 8, add_to_offsets
);
15599 else if (in_index
== edit_index
15600 || (in_index
* 8 >= input_size
15601 && edit_index
== UINT_MAX
))
15603 switch (edit_node
->type
)
15605 case DELETE_EXIDX_ENTRY
:
15607 add_to_offsets
+= 8;
15610 case INSERT_EXIDX_CANTUNWIND_AT_END
:
15612 asection
*text_sec
= edit_node
->linked_section
;
15613 bfd_vma text_offset
= text_sec
->output_section
->vma
15614 + text_sec
->output_offset
15616 bfd_vma exidx_offset
= offset
+ out_index
* 8;
15617 unsigned long prel31_offset
;
15619 /* Note: this is meant to be equivalent to an
15620 R_ARM_PREL31 relocation. These synthetic
15621 EXIDX_CANTUNWIND markers are not relocated by the
15622 usual BFD method. */
15623 prel31_offset
= (text_offset
- exidx_offset
)
15626 /* First address we can't unwind. */
15627 bfd_put_32 (output_bfd
, prel31_offset
,
15628 &edited_contents
[out_index
* 8]);
15630 /* Code for EXIDX_CANTUNWIND. */
15631 bfd_put_32 (output_bfd
, 0x1,
15632 &edited_contents
[out_index
* 8 + 4]);
15635 add_to_offsets
-= 8;
15640 edit_node
= edit_node
->next
;
15645 /* No more edits, copy remaining entries verbatim. */
15646 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
15647 contents
+ in_index
* 8, add_to_offsets
);
15653 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
15654 bfd_set_section_contents (output_bfd
, sec
->output_section
,
15656 (file_ptr
) sec
->output_offset
, sec
->size
);
15661 /* Fix code to point to Cortex-A8 erratum stubs. */
15662 if (globals
->fix_cortex_a8
)
15664 struct a8_branch_to_stub_data data
;
15666 data
.writing_section
= sec
;
15667 data
.contents
= contents
;
15669 bfd_hash_traverse (&globals
->stub_hash_table
, make_branch_to_a8_stub
,
15676 if (globals
->byteswap_code
)
15678 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
15681 for (i
= 0; i
< mapcount
; i
++)
15683 if (i
== mapcount
- 1)
15686 end
= map
[i
+ 1].vma
;
15688 switch (map
[i
].type
)
15691 /* Byte swap code words. */
15692 while (ptr
+ 3 < end
)
15694 tmp
= contents
[ptr
];
15695 contents
[ptr
] = contents
[ptr
+ 3];
15696 contents
[ptr
+ 3] = tmp
;
15697 tmp
= contents
[ptr
+ 1];
15698 contents
[ptr
+ 1] = contents
[ptr
+ 2];
15699 contents
[ptr
+ 2] = tmp
;
15705 /* Byte swap code halfwords. */
15706 while (ptr
+ 1 < end
)
15708 tmp
= contents
[ptr
];
15709 contents
[ptr
] = contents
[ptr
+ 1];
15710 contents
[ptr
+ 1] = tmp
;
15716 /* Leave data alone. */
15724 arm_data
->mapcount
= -1;
15725 arm_data
->mapsize
= 0;
15726 arm_data
->map
= NULL
;
15731 /* Mangle thumb function symbols as we read them in. */
15734 elf32_arm_swap_symbol_in (bfd
* abfd
,
15737 Elf_Internal_Sym
*dst
)
15739 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
15742 /* New EABI objects mark thumb function symbols by setting the low bit of
15744 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
15745 || ELF_ST_TYPE (dst
->st_info
) == STT_GNU_IFUNC
)
15747 if (dst
->st_value
& 1)
15749 dst
->st_value
&= ~(bfd_vma
) 1;
15750 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15753 dst
->st_target_internal
= ST_BRANCH_TO_ARM
;
15755 else if (ELF_ST_TYPE (dst
->st_info
) == STT_ARM_TFUNC
)
15757 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_FUNC
);
15758 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15760 else if (ELF_ST_TYPE (dst
->st_info
) == STT_SECTION
)
15761 dst
->st_target_internal
= ST_BRANCH_LONG
;
15763 dst
->st_target_internal
= ST_BRANCH_UNKNOWN
;
15769 /* Mangle thumb function symbols as we write them out. */
15772 elf32_arm_swap_symbol_out (bfd
*abfd
,
15773 const Elf_Internal_Sym
*src
,
15777 Elf_Internal_Sym newsym
;
15779 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
15780 of the address set, as per the new EABI. We do this unconditionally
15781 because objcopy does not set the elf header flags until after
15782 it writes out the symbol table. */
15783 if (src
->st_target_internal
== ST_BRANCH_TO_THUMB
)
15786 if (ELF_ST_TYPE (src
->st_info
) != STT_GNU_IFUNC
)
15787 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
15788 if (newsym
.st_shndx
!= SHN_UNDEF
)
15790 /* Do this only for defined symbols. At link type, the static
15791 linker will simulate the work of dynamic linker of resolving
15792 symbols and will carry over the thumbness of found symbols to
15793 the output symbol table. It's not clear how it happens, but
15794 the thumbness of undefined symbols can well be different at
15795 runtime, and writing '1' for them will be confusing for users
15796 and possibly for dynamic linker itself.
15798 newsym
.st_value
|= 1;
15803 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
15806 /* Add the PT_ARM_EXIDX program header. */
15809 elf32_arm_modify_segment_map (bfd
*abfd
,
15810 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15812 struct elf_segment_map
*m
;
15815 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15816 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15818 /* If there is already a PT_ARM_EXIDX header, then we do not
15819 want to add another one. This situation arises when running
15820 "strip"; the input binary already has the header. */
15821 m
= elf_seg_map (abfd
);
15822 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
15826 m
= (struct elf_segment_map
*)
15827 bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
15830 m
->p_type
= PT_ARM_EXIDX
;
15832 m
->sections
[0] = sec
;
15834 m
->next
= elf_seg_map (abfd
);
15835 elf_seg_map (abfd
) = m
;
15842 /* We may add a PT_ARM_EXIDX program header. */
15845 elf32_arm_additional_program_headers (bfd
*abfd
,
15846 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15850 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15851 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15857 /* Hook called by the linker routine which adds symbols from an object
15861 elf32_arm_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
15862 Elf_Internal_Sym
*sym
, const char **namep
,
15863 flagword
*flagsp
, asection
**secp
, bfd_vma
*valp
)
15865 if ((abfd
->flags
& DYNAMIC
) == 0
15866 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
15867 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
15868 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
15870 if (elf32_arm_hash_table (info
) == NULL
)
15873 if (elf32_arm_hash_table (info
)->vxworks_p
15874 && !elf_vxworks_add_symbol_hook (abfd
, info
, sym
, namep
,
15875 flagsp
, secp
, valp
))
15881 /* We use this to override swap_symbol_in and swap_symbol_out. */
15882 const struct elf_size_info elf32_arm_size_info
=
15884 sizeof (Elf32_External_Ehdr
),
15885 sizeof (Elf32_External_Phdr
),
15886 sizeof (Elf32_External_Shdr
),
15887 sizeof (Elf32_External_Rel
),
15888 sizeof (Elf32_External_Rela
),
15889 sizeof (Elf32_External_Sym
),
15890 sizeof (Elf32_External_Dyn
),
15891 sizeof (Elf_External_Note
),
15895 ELFCLASS32
, EV_CURRENT
,
15896 bfd_elf32_write_out_phdrs
,
15897 bfd_elf32_write_shdrs_and_ehdr
,
15898 bfd_elf32_checksum_contents
,
15899 bfd_elf32_write_relocs
,
15900 elf32_arm_swap_symbol_in
,
15901 elf32_arm_swap_symbol_out
,
15902 bfd_elf32_slurp_reloc_table
,
15903 bfd_elf32_slurp_symbol_table
,
15904 bfd_elf32_swap_dyn_in
,
15905 bfd_elf32_swap_dyn_out
,
15906 bfd_elf32_swap_reloc_in
,
15907 bfd_elf32_swap_reloc_out
,
15908 bfd_elf32_swap_reloca_in
,
15909 bfd_elf32_swap_reloca_out
15912 /* Return size of plt0 entry starting at ADDR
15913 or (bfd_vma) -1 if size can not be determined. */
15916 elf32_arm_plt0_size (const bfd
*abfd
, const bfd_byte
*addr
)
15918 bfd_vma first_word
;
15921 first_word
= H_GET_32 (abfd
, addr
);
15923 if (first_word
== elf32_arm_plt0_entry
[0])
15924 plt0_size
= 4 * ARRAY_SIZE (elf32_arm_plt0_entry
);
15925 else if (first_word
== elf32_thumb2_plt0_entry
[0])
15926 plt0_size
= 4 * ARRAY_SIZE (elf32_thumb2_plt0_entry
);
15928 /* We don't yet handle this PLT format. */
15929 return (bfd_vma
) -1;
15934 /* Return size of plt entry starting at offset OFFSET
15935 of plt section located at address START
15936 or (bfd_vma) -1 if size can not be determined. */
15939 elf32_arm_plt_size (const bfd
*abfd
, const bfd_byte
*start
, bfd_vma offset
)
15941 bfd_vma first_insn
;
15942 bfd_vma plt_size
= 0;
15943 const bfd_byte
*addr
= start
+ offset
;
15945 /* PLT entry size if fixed on Thumb-only platforms. */
15946 if (H_GET_32(abfd
, start
) == elf32_thumb2_plt0_entry
[0])
15947 return 4 * ARRAY_SIZE (elf32_thumb2_plt_entry
);
15949 /* Respect Thumb stub if necessary. */
15950 if (H_GET_16(abfd
, addr
) == elf32_arm_plt_thumb_stub
[0])
15952 plt_size
+= 2 * ARRAY_SIZE(elf32_arm_plt_thumb_stub
);
15955 /* Strip immediate from first add. */
15956 first_insn
= H_GET_32(abfd
, addr
+ plt_size
) & 0xffffff00;
15958 #ifdef FOUR_WORD_PLT
15959 if (first_insn
== elf32_arm_plt_entry
[0])
15960 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry
);
15962 if (first_insn
== elf32_arm_plt_entry_long
[0])
15963 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry_long
);
15964 else if (first_insn
== elf32_arm_plt_entry_short
[0])
15965 plt_size
+= 4 * ARRAY_SIZE (elf32_arm_plt_entry_short
);
15968 /* We don't yet handle this PLT format. */
15969 return (bfd_vma
) -1;
15974 /* Implementation is shamelessly borrowed from _bfd_elf_get_synthetic_symtab. */
15977 elf32_arm_get_synthetic_symtab (bfd
*abfd
,
15978 long symcount ATTRIBUTE_UNUSED
,
15979 asymbol
**syms ATTRIBUTE_UNUSED
,
15989 Elf_Internal_Shdr
*hdr
;
15997 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
16000 if (dynsymcount
<= 0)
16003 relplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
16004 if (relplt
== NULL
)
16007 hdr
= &elf_section_data (relplt
)->this_hdr
;
16008 if (hdr
->sh_link
!= elf_dynsymtab (abfd
)
16009 || (hdr
->sh_type
!= SHT_REL
&& hdr
->sh_type
!= SHT_RELA
))
16012 plt
= bfd_get_section_by_name (abfd
, ".plt");
16016 if (!elf32_arm_size_info
.slurp_reloc_table (abfd
, relplt
, dynsyms
, TRUE
))
16019 data
= plt
->contents
;
16022 if (!bfd_get_full_section_contents(abfd
, (asection
*) plt
, &data
) || data
== NULL
)
16024 bfd_cache_section_contents((asection
*) plt
, data
);
16027 count
= relplt
->size
/ hdr
->sh_entsize
;
16028 size
= count
* sizeof (asymbol
);
16029 p
= relplt
->relocation
;
16030 for (i
= 0; i
< count
; i
++, p
+= elf32_arm_size_info
.int_rels_per_ext_rel
)
16032 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
16033 if (p
->addend
!= 0)
16034 size
+= sizeof ("+0x") - 1 + 8;
16037 s
= *ret
= (asymbol
*) bfd_malloc (size
);
16041 offset
= elf32_arm_plt0_size (abfd
, data
);
16042 if (offset
== (bfd_vma
) -1)
16045 names
= (char *) (s
+ count
);
16046 p
= relplt
->relocation
;
16048 for (i
= 0; i
< count
; i
++, p
+= elf32_arm_size_info
.int_rels_per_ext_rel
)
16052 bfd_vma plt_size
= elf32_arm_plt_size (abfd
, data
, offset
);
16053 if (plt_size
== (bfd_vma
) -1)
16056 *s
= **p
->sym_ptr_ptr
;
16057 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
16058 we are defining a symbol, ensure one of them is set. */
16059 if ((s
->flags
& BSF_LOCAL
) == 0)
16060 s
->flags
|= BSF_GLOBAL
;
16061 s
->flags
|= BSF_SYNTHETIC
;
16066 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
16067 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
16069 if (p
->addend
!= 0)
16073 memcpy (names
, "+0x", sizeof ("+0x") - 1);
16074 names
+= sizeof ("+0x") - 1;
16075 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
16076 for (a
= buf
; *a
== '0'; ++a
)
16079 memcpy (names
, a
, len
);
16082 memcpy (names
, "@plt", sizeof ("@plt"));
16083 names
+= sizeof ("@plt");
16085 offset
+= plt_size
;
16091 #define ELF_ARCH bfd_arch_arm
16092 #define ELF_TARGET_ID ARM_ELF_DATA
16093 #define ELF_MACHINE_CODE EM_ARM
16094 #ifdef __QNXTARGET__
16095 #define ELF_MAXPAGESIZE 0x1000
16097 #define ELF_MAXPAGESIZE 0x8000
16099 #define ELF_MINPAGESIZE 0x1000
16100 #define ELF_COMMONPAGESIZE 0x1000
16102 #define bfd_elf32_mkobject elf32_arm_mkobject
16104 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
16105 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
16106 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
16107 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
16108 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
16109 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
16110 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
16111 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
16112 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
16113 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
16114 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
16115 #define bfd_elf32_bfd_final_link elf32_arm_final_link
16116 #define bfd_elf32_get_synthetic_symtab elf32_arm_get_synthetic_symtab
16118 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
16119 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
16120 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
16121 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
16122 #define elf_backend_check_relocs elf32_arm_check_relocs
16123 #define elf_backend_relocate_section elf32_arm_relocate_section
16124 #define elf_backend_write_section elf32_arm_write_section
16125 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
16126 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
16127 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
16128 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
16129 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
16130 #define elf_backend_always_size_sections elf32_arm_always_size_sections
16131 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
16132 #define elf_backend_post_process_headers elf32_arm_post_process_headers
16133 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
16134 #define elf_backend_object_p elf32_arm_object_p
16135 #define elf_backend_fake_sections elf32_arm_fake_sections
16136 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
16137 #define elf_backend_final_write_processing elf32_arm_final_write_processing
16138 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
16139 #define elf_backend_size_info elf32_arm_size_info
16140 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
16141 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
16142 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
16143 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
16144 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
16146 #define elf_backend_can_refcount 1
16147 #define elf_backend_can_gc_sections 1
16148 #define elf_backend_plt_readonly 1
16149 #define elf_backend_want_got_plt 1
16150 #define elf_backend_want_plt_sym 0
16151 #define elf_backend_may_use_rel_p 1
16152 #define elf_backend_may_use_rela_p 0
16153 #define elf_backend_default_use_rela_p 0
16155 #define elf_backend_got_header_size 12
16157 #undef elf_backend_obj_attrs_vendor
16158 #define elf_backend_obj_attrs_vendor "aeabi"
16159 #undef elf_backend_obj_attrs_section
16160 #define elf_backend_obj_attrs_section ".ARM.attributes"
16161 #undef elf_backend_obj_attrs_arg_type
16162 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
16163 #undef elf_backend_obj_attrs_section_type
16164 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
16165 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
16166 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
16168 #include "elf32-target.h"
16170 /* Native Client targets. */
16172 #undef TARGET_LITTLE_SYM
16173 #define TARGET_LITTLE_SYM arm_elf32_nacl_le_vec
16174 #undef TARGET_LITTLE_NAME
16175 #define TARGET_LITTLE_NAME "elf32-littlearm-nacl"
16176 #undef TARGET_BIG_SYM
16177 #define TARGET_BIG_SYM arm_elf32_nacl_be_vec
16178 #undef TARGET_BIG_NAME
16179 #define TARGET_BIG_NAME "elf32-bigarm-nacl"
16181 /* Like elf32_arm_link_hash_table_create -- but overrides
16182 appropriately for NaCl. */
16184 static struct bfd_link_hash_table
*
16185 elf32_arm_nacl_link_hash_table_create (bfd
*abfd
)
16187 struct bfd_link_hash_table
*ret
;
16189 ret
= elf32_arm_link_hash_table_create (abfd
);
16192 struct elf32_arm_link_hash_table
*htab
16193 = (struct elf32_arm_link_hash_table
*) ret
;
16197 htab
->plt_header_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt0_entry
);
16198 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_nacl_plt_entry
);
16203 /* Since NaCl doesn't use the ARM-specific unwind format, we don't
16204 really need to use elf32_arm_modify_segment_map. But we do it
16205 anyway just to reduce gratuitous differences with the stock ARM backend. */
16208 elf32_arm_nacl_modify_segment_map (bfd
*abfd
, struct bfd_link_info
*info
)
16210 return (elf32_arm_modify_segment_map (abfd
, info
)
16211 && nacl_modify_segment_map (abfd
, info
));
16215 elf32_arm_nacl_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
16217 elf32_arm_final_write_processing (abfd
, linker
);
16218 nacl_final_write_processing (abfd
, linker
);
16222 elf32_arm_nacl_plt_sym_val (bfd_vma i
, const asection
*plt
,
16223 const arelent
*rel ATTRIBUTE_UNUSED
)
16226 + 4 * (ARRAY_SIZE (elf32_arm_nacl_plt0_entry
) +
16227 i
* ARRAY_SIZE (elf32_arm_nacl_plt_entry
));
16231 #define elf32_bed elf32_arm_nacl_bed
16232 #undef bfd_elf32_bfd_link_hash_table_create
16233 #define bfd_elf32_bfd_link_hash_table_create \
16234 elf32_arm_nacl_link_hash_table_create
16235 #undef elf_backend_plt_alignment
16236 #define elf_backend_plt_alignment 4
16237 #undef elf_backend_modify_segment_map
16238 #define elf_backend_modify_segment_map elf32_arm_nacl_modify_segment_map
16239 #undef elf_backend_modify_program_headers
16240 #define elf_backend_modify_program_headers nacl_modify_program_headers
16241 #undef elf_backend_final_write_processing
16242 #define elf_backend_final_write_processing elf32_arm_nacl_final_write_processing
16243 #undef bfd_elf32_get_synthetic_symtab
16244 #undef elf_backend_plt_sym_val
16245 #define elf_backend_plt_sym_val elf32_arm_nacl_plt_sym_val
16247 #undef ELF_MAXPAGESIZE
16248 #define ELF_MAXPAGESIZE 0x10000
16249 #undef ELF_MINPAGESIZE
16250 #undef ELF_COMMONPAGESIZE
16253 #include "elf32-target.h"
16255 /* Reset to defaults. */
16256 #undef elf_backend_plt_alignment
16257 #undef elf_backend_modify_segment_map
16258 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
16259 #undef elf_backend_modify_program_headers
16260 #undef elf_backend_final_write_processing
16261 #define elf_backend_final_write_processing elf32_arm_final_write_processing
16262 #undef ELF_MINPAGESIZE
16263 #define ELF_MINPAGESIZE 0x1000
16264 #undef ELF_COMMONPAGESIZE
16265 #define ELF_COMMONPAGESIZE 0x1000
16268 /* VxWorks Targets. */
16270 #undef TARGET_LITTLE_SYM
16271 #define TARGET_LITTLE_SYM arm_elf32_vxworks_le_vec
16272 #undef TARGET_LITTLE_NAME
16273 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
16274 #undef TARGET_BIG_SYM
16275 #define TARGET_BIG_SYM arm_elf32_vxworks_be_vec
16276 #undef TARGET_BIG_NAME
16277 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
16279 /* Like elf32_arm_link_hash_table_create -- but overrides
16280 appropriately for VxWorks. */
16282 static struct bfd_link_hash_table
*
16283 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
16285 struct bfd_link_hash_table
*ret
;
16287 ret
= elf32_arm_link_hash_table_create (abfd
);
16290 struct elf32_arm_link_hash_table
*htab
16291 = (struct elf32_arm_link_hash_table
*) ret
;
16293 htab
->vxworks_p
= 1;
16299 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
16301 elf32_arm_final_write_processing (abfd
, linker
);
16302 elf_vxworks_final_write_processing (abfd
, linker
);
16306 #define elf32_bed elf32_arm_vxworks_bed
16308 #undef bfd_elf32_bfd_link_hash_table_create
16309 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
16310 #undef elf_backend_final_write_processing
16311 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
16312 #undef elf_backend_emit_relocs
16313 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
16315 #undef elf_backend_may_use_rel_p
16316 #define elf_backend_may_use_rel_p 0
16317 #undef elf_backend_may_use_rela_p
16318 #define elf_backend_may_use_rela_p 1
16319 #undef elf_backend_default_use_rela_p
16320 #define elf_backend_default_use_rela_p 1
16321 #undef elf_backend_want_plt_sym
16322 #define elf_backend_want_plt_sym 1
16323 #undef ELF_MAXPAGESIZE
16324 #define ELF_MAXPAGESIZE 0x1000
16326 #include "elf32-target.h"
16329 /* Merge backend specific data from an object file to the output
16330 object file when linking. */
16333 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
16335 flagword out_flags
;
16337 bfd_boolean flags_compatible
= TRUE
;
16340 /* Check if we have the same endianness. */
16341 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
16344 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
16347 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
16350 /* The input BFD must have had its flags initialised. */
16351 /* The following seems bogus to me -- The flags are initialized in
16352 the assembler but I don't think an elf_flags_init field is
16353 written into the object. */
16354 /* BFD_ASSERT (elf_flags_init (ibfd)); */
16356 in_flags
= elf_elfheader (ibfd
)->e_flags
;
16357 out_flags
= elf_elfheader (obfd
)->e_flags
;
16359 /* In theory there is no reason why we couldn't handle this. However
16360 in practice it isn't even close to working and there is no real
16361 reason to want it. */
16362 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
16363 && !(ibfd
->flags
& DYNAMIC
)
16364 && (in_flags
& EF_ARM_BE8
))
16366 _bfd_error_handler (_("error: %B is already in final BE8 format"),
16371 if (!elf_flags_init (obfd
))
16373 /* If the input is the default architecture and had the default
16374 flags then do not bother setting the flags for the output
16375 architecture, instead allow future merges to do this. If no
16376 future merges ever set these flags then they will retain their
16377 uninitialised values, which surprise surprise, correspond
16378 to the default values. */
16379 if (bfd_get_arch_info (ibfd
)->the_default
16380 && elf_elfheader (ibfd
)->e_flags
== 0)
16383 elf_flags_init (obfd
) = TRUE
;
16384 elf_elfheader (obfd
)->e_flags
= in_flags
;
16386 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
16387 && bfd_get_arch_info (obfd
)->the_default
)
16388 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
16393 /* Determine what should happen if the input ARM architecture
16394 does not match the output ARM architecture. */
16395 if (! bfd_arm_merge_machines (ibfd
, obfd
))
16398 /* Identical flags must be compatible. */
16399 if (in_flags
== out_flags
)
16402 /* Check to see if the input BFD actually contains any sections. If
16403 not, its flags may not have been initialised either, but it
16404 cannot actually cause any incompatiblity. Do not short-circuit
16405 dynamic objects; their section list may be emptied by
16406 elf_link_add_object_symbols.
16408 Also check to see if there are no code sections in the input.
16409 In this case there is no need to check for code specific flags.
16410 XXX - do we need to worry about floating-point format compatability
16411 in data sections ? */
16412 if (!(ibfd
->flags
& DYNAMIC
))
16414 bfd_boolean null_input_bfd
= TRUE
;
16415 bfd_boolean only_data_sections
= TRUE
;
16417 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
16419 /* Ignore synthetic glue sections. */
16420 if (strcmp (sec
->name
, ".glue_7")
16421 && strcmp (sec
->name
, ".glue_7t"))
16423 if ((bfd_get_section_flags (ibfd
, sec
)
16424 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
16425 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
16426 only_data_sections
= FALSE
;
16428 null_input_bfd
= FALSE
;
16433 if (null_input_bfd
|| only_data_sections
)
16437 /* Complain about various flag mismatches. */
16438 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
16439 EF_ARM_EABI_VERSION (out_flags
)))
16442 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
16444 (in_flags
& EF_ARM_EABIMASK
) >> 24,
16445 (out_flags
& EF_ARM_EABIMASK
) >> 24);
16449 /* Not sure what needs to be checked for EABI versions >= 1. */
16450 /* VxWorks libraries do not use these flags. */
16451 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
16452 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
16453 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
16455 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
16458 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
16460 in_flags
& EF_ARM_APCS_26
? 26 : 32,
16461 out_flags
& EF_ARM_APCS_26
? 26 : 32);
16462 flags_compatible
= FALSE
;
16465 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
16467 if (in_flags
& EF_ARM_APCS_FLOAT
)
16469 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
16473 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
16476 flags_compatible
= FALSE
;
16479 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
16481 if (in_flags
& EF_ARM_VFP_FLOAT
)
16483 (_("error: %B uses VFP instructions, whereas %B does not"),
16487 (_("error: %B uses FPA instructions, whereas %B does not"),
16490 flags_compatible
= FALSE
;
16493 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
16495 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
16497 (_("error: %B uses Maverick instructions, whereas %B does not"),
16501 (_("error: %B does not use Maverick instructions, whereas %B does"),
16504 flags_compatible
= FALSE
;
16507 #ifdef EF_ARM_SOFT_FLOAT
16508 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
16510 /* We can allow interworking between code that is VFP format
16511 layout, and uses either soft float or integer regs for
16512 passing floating point arguments and results. We already
16513 know that the APCS_FLOAT flags match; similarly for VFP
16515 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
16516 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
16518 if (in_flags
& EF_ARM_SOFT_FLOAT
)
16520 (_("error: %B uses software FP, whereas %B uses hardware FP"),
16524 (_("error: %B uses hardware FP, whereas %B uses software FP"),
16527 flags_compatible
= FALSE
;
16532 /* Interworking mismatch is only a warning. */
16533 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
16535 if (in_flags
& EF_ARM_INTERWORK
)
16538 (_("Warning: %B supports interworking, whereas %B does not"),
16544 (_("Warning: %B does not support interworking, whereas %B does"),
16550 return flags_compatible
;
16554 /* Symbian OS Targets. */
16556 #undef TARGET_LITTLE_SYM
16557 #define TARGET_LITTLE_SYM arm_elf32_symbian_le_vec
16558 #undef TARGET_LITTLE_NAME
16559 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
16560 #undef TARGET_BIG_SYM
16561 #define TARGET_BIG_SYM arm_elf32_symbian_be_vec
16562 #undef TARGET_BIG_NAME
16563 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
16565 /* Like elf32_arm_link_hash_table_create -- but overrides
16566 appropriately for Symbian OS. */
16568 static struct bfd_link_hash_table
*
16569 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
16571 struct bfd_link_hash_table
*ret
;
16573 ret
= elf32_arm_link_hash_table_create (abfd
);
16576 struct elf32_arm_link_hash_table
*htab
16577 = (struct elf32_arm_link_hash_table
*)ret
;
16578 /* There is no PLT header for Symbian OS. */
16579 htab
->plt_header_size
= 0;
16580 /* The PLT entries are each one instruction and one word. */
16581 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
16582 htab
->symbian_p
= 1;
16583 /* Symbian uses armv5t or above, so use_blx is always true. */
16585 htab
->root
.is_relocatable_executable
= 1;
16590 static const struct bfd_elf_special_section
16591 elf32_arm_symbian_special_sections
[] =
16593 /* In a BPABI executable, the dynamic linking sections do not go in
16594 the loadable read-only segment. The post-linker may wish to
16595 refer to these sections, but they are not part of the final
16597 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
16598 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
16599 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
16600 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
16601 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
16602 /* These sections do not need to be writable as the SymbianOS
16603 postlinker will arrange things so that no dynamic relocation is
16605 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
16606 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
16607 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
16608 { NULL
, 0, 0, 0, 0 }
16612 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
16613 struct bfd_link_info
*link_info
)
16615 /* BPABI objects are never loaded directly by an OS kernel; they are
16616 processed by a postlinker first, into an OS-specific format. If
16617 the D_PAGED bit is set on the file, BFD will align segments on
16618 page boundaries, so that an OS can directly map the file. With
16619 BPABI objects, that just results in wasted space. In addition,
16620 because we clear the D_PAGED bit, map_sections_to_segments will
16621 recognize that the program headers should not be mapped into any
16622 loadable segment. */
16623 abfd
->flags
&= ~D_PAGED
;
16624 elf32_arm_begin_write_processing (abfd
, link_info
);
16628 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
16629 struct bfd_link_info
*info
)
16631 struct elf_segment_map
*m
;
16634 /* BPABI shared libraries and executables should have a PT_DYNAMIC
16635 segment. However, because the .dynamic section is not marked
16636 with SEC_LOAD, the generic ELF code will not create such a
16638 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
16641 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
16642 if (m
->p_type
== PT_DYNAMIC
)
16647 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
16648 m
->next
= elf_seg_map (abfd
);
16649 elf_seg_map (abfd
) = m
;
16653 /* Also call the generic arm routine. */
16654 return elf32_arm_modify_segment_map (abfd
, info
);
16657 /* Return address for Ith PLT stub in section PLT, for relocation REL
16658 or (bfd_vma) -1 if it should not be included. */
16661 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
16662 const arelent
*rel ATTRIBUTE_UNUSED
)
16664 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
16669 #define elf32_bed elf32_arm_symbian_bed
16671 /* The dynamic sections are not allocated on SymbianOS; the postlinker
16672 will process them and then discard them. */
16673 #undef ELF_DYNAMIC_SEC_FLAGS
16674 #define ELF_DYNAMIC_SEC_FLAGS \
16675 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
16677 #undef elf_backend_emit_relocs
16679 #undef bfd_elf32_bfd_link_hash_table_create
16680 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
16681 #undef elf_backend_special_sections
16682 #define elf_backend_special_sections elf32_arm_symbian_special_sections
16683 #undef elf_backend_begin_write_processing
16684 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
16685 #undef elf_backend_final_write_processing
16686 #define elf_backend_final_write_processing elf32_arm_final_write_processing
16688 #undef elf_backend_modify_segment_map
16689 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
16691 /* There is no .got section for BPABI objects, and hence no header. */
16692 #undef elf_backend_got_header_size
16693 #define elf_backend_got_header_size 0
16695 /* Similarly, there is no .got.plt section. */
16696 #undef elf_backend_want_got_plt
16697 #define elf_backend_want_got_plt 0
16699 #undef elf_backend_plt_sym_val
16700 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
16702 #undef elf_backend_may_use_rel_p
16703 #define elf_backend_may_use_rel_p 1
16704 #undef elf_backend_may_use_rela_p
16705 #define elf_backend_may_use_rela_p 0
16706 #undef elf_backend_default_use_rela_p
16707 #define elf_backend_default_use_rela_p 0
16708 #undef elf_backend_want_plt_sym
16709 #define elf_backend_want_plt_sym 0
16710 #undef ELF_MAXPAGESIZE
16711 #define ELF_MAXPAGESIZE 0x8000
16713 #include "elf32-target.h"