1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
26 #include "libiberty.h"
29 #include "elf-vxworks.h"
32 /* Return the relocation section associated with NAME. HTAB is the
33 bfd's elf32_arm_link_hash_entry. */
34 #define RELOC_SECTION(HTAB, NAME) \
35 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
37 /* Return size of a relocation entry. HTAB is the bfd's
38 elf32_arm_link_hash_entry. */
39 #define RELOC_SIZE(HTAB) \
41 ? sizeof (Elf32_External_Rel) \
42 : sizeof (Elf32_External_Rela))
44 /* Return function to swap relocations in. HTAB is the bfd's
45 elf32_arm_link_hash_entry. */
46 #define SWAP_RELOC_IN(HTAB) \
48 ? bfd_elf32_swap_reloc_in \
49 : bfd_elf32_swap_reloca_in)
51 /* Return function to swap relocations out. HTAB is the bfd's
52 elf32_arm_link_hash_entry. */
53 #define SWAP_RELOC_OUT(HTAB) \
55 ? bfd_elf32_swap_reloc_out \
56 : bfd_elf32_swap_reloca_out)
58 #define elf_info_to_howto 0
59 #define elf_info_to_howto_rel elf32_arm_info_to_howto
61 #define ARM_ELF_ABI_VERSION 0
62 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
64 static bfd_boolean
elf32_arm_write_section (bfd
*output_bfd
,
65 struct bfd_link_info
*link_info
,
69 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
70 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
73 static reloc_howto_type elf32_arm_howto_table_1
[] =
76 HOWTO (R_ARM_NONE
, /* type */
78 0, /* size (0 = byte, 1 = short, 2 = long) */
80 FALSE
, /* pc_relative */
82 complain_overflow_dont
,/* complain_on_overflow */
83 bfd_elf_generic_reloc
, /* special_function */
84 "R_ARM_NONE", /* name */
85 FALSE
, /* partial_inplace */
88 FALSE
), /* pcrel_offset */
90 HOWTO (R_ARM_PC24
, /* type */
92 2, /* size (0 = byte, 1 = short, 2 = long) */
94 TRUE
, /* pc_relative */
96 complain_overflow_signed
,/* complain_on_overflow */
97 bfd_elf_generic_reloc
, /* special_function */
98 "R_ARM_PC24", /* name */
99 FALSE
, /* partial_inplace */
100 0x00ffffff, /* src_mask */
101 0x00ffffff, /* dst_mask */
102 TRUE
), /* pcrel_offset */
104 /* 32 bit absolute */
105 HOWTO (R_ARM_ABS32
, /* type */
107 2, /* size (0 = byte, 1 = short, 2 = long) */
109 FALSE
, /* pc_relative */
111 complain_overflow_bitfield
,/* complain_on_overflow */
112 bfd_elf_generic_reloc
, /* special_function */
113 "R_ARM_ABS32", /* name */
114 FALSE
, /* partial_inplace */
115 0xffffffff, /* src_mask */
116 0xffffffff, /* dst_mask */
117 FALSE
), /* pcrel_offset */
119 /* standard 32bit pc-relative reloc */
120 HOWTO (R_ARM_REL32
, /* type */
122 2, /* size (0 = byte, 1 = short, 2 = long) */
124 TRUE
, /* pc_relative */
126 complain_overflow_bitfield
,/* complain_on_overflow */
127 bfd_elf_generic_reloc
, /* special_function */
128 "R_ARM_REL32", /* name */
129 FALSE
, /* partial_inplace */
130 0xffffffff, /* src_mask */
131 0xffffffff, /* dst_mask */
132 TRUE
), /* pcrel_offset */
134 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
135 HOWTO (R_ARM_LDR_PC_G0
, /* type */
137 0, /* size (0 = byte, 1 = short, 2 = long) */
139 TRUE
, /* pc_relative */
141 complain_overflow_dont
,/* complain_on_overflow */
142 bfd_elf_generic_reloc
, /* special_function */
143 "R_ARM_LDR_PC_G0", /* name */
144 FALSE
, /* partial_inplace */
145 0xffffffff, /* src_mask */
146 0xffffffff, /* dst_mask */
147 TRUE
), /* pcrel_offset */
149 /* 16 bit absolute */
150 HOWTO (R_ARM_ABS16
, /* type */
152 1, /* size (0 = byte, 1 = short, 2 = long) */
154 FALSE
, /* pc_relative */
156 complain_overflow_bitfield
,/* complain_on_overflow */
157 bfd_elf_generic_reloc
, /* special_function */
158 "R_ARM_ABS16", /* name */
159 FALSE
, /* partial_inplace */
160 0x0000ffff, /* src_mask */
161 0x0000ffff, /* dst_mask */
162 FALSE
), /* pcrel_offset */
164 /* 12 bit absolute */
165 HOWTO (R_ARM_ABS12
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 FALSE
, /* pc_relative */
171 complain_overflow_bitfield
,/* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_ARM_ABS12", /* name */
174 FALSE
, /* partial_inplace */
175 0x00000fff, /* src_mask */
176 0x00000fff, /* dst_mask */
177 FALSE
), /* pcrel_offset */
179 HOWTO (R_ARM_THM_ABS5
, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_bitfield
,/* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_ARM_THM_ABS5", /* name */
188 FALSE
, /* partial_inplace */
189 0x000007e0, /* src_mask */
190 0x000007e0, /* dst_mask */
191 FALSE
), /* pcrel_offset */
194 HOWTO (R_ARM_ABS8
, /* type */
196 0, /* size (0 = byte, 1 = short, 2 = long) */
198 FALSE
, /* pc_relative */
200 complain_overflow_bitfield
,/* complain_on_overflow */
201 bfd_elf_generic_reloc
, /* special_function */
202 "R_ARM_ABS8", /* name */
203 FALSE
, /* partial_inplace */
204 0x000000ff, /* src_mask */
205 0x000000ff, /* dst_mask */
206 FALSE
), /* pcrel_offset */
208 HOWTO (R_ARM_SBREL32
, /* type */
210 2, /* size (0 = byte, 1 = short, 2 = long) */
212 FALSE
, /* pc_relative */
214 complain_overflow_dont
,/* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_ARM_SBREL32", /* name */
217 FALSE
, /* partial_inplace */
218 0xffffffff, /* src_mask */
219 0xffffffff, /* dst_mask */
220 FALSE
), /* pcrel_offset */
222 HOWTO (R_ARM_THM_CALL
, /* type */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
226 TRUE
, /* pc_relative */
228 complain_overflow_signed
,/* complain_on_overflow */
229 bfd_elf_generic_reloc
, /* special_function */
230 "R_ARM_THM_CALL", /* name */
231 FALSE
, /* partial_inplace */
232 0x07ff07ff, /* src_mask */
233 0x07ff07ff, /* dst_mask */
234 TRUE
), /* pcrel_offset */
236 HOWTO (R_ARM_THM_PC8
, /* type */
238 1, /* size (0 = byte, 1 = short, 2 = long) */
240 TRUE
, /* pc_relative */
242 complain_overflow_signed
,/* complain_on_overflow */
243 bfd_elf_generic_reloc
, /* special_function */
244 "R_ARM_THM_PC8", /* name */
245 FALSE
, /* partial_inplace */
246 0x000000ff, /* src_mask */
247 0x000000ff, /* dst_mask */
248 TRUE
), /* pcrel_offset */
250 HOWTO (R_ARM_BREL_ADJ
, /* type */
252 1, /* size (0 = byte, 1 = short, 2 = long) */
254 FALSE
, /* pc_relative */
256 complain_overflow_signed
,/* complain_on_overflow */
257 bfd_elf_generic_reloc
, /* special_function */
258 "R_ARM_BREL_ADJ", /* name */
259 FALSE
, /* partial_inplace */
260 0xffffffff, /* src_mask */
261 0xffffffff, /* dst_mask */
262 FALSE
), /* pcrel_offset */
264 HOWTO (R_ARM_TLS_DESC
, /* type */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
268 FALSE
, /* pc_relative */
270 complain_overflow_bitfield
,/* complain_on_overflow */
271 bfd_elf_generic_reloc
, /* special_function */
272 "R_ARM_TLS_DESC", /* name */
273 FALSE
, /* partial_inplace */
274 0xffffffff, /* src_mask */
275 0xffffffff, /* dst_mask */
276 FALSE
), /* pcrel_offset */
278 HOWTO (R_ARM_THM_SWI8
, /* type */
280 0, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE
, /* pc_relative */
284 complain_overflow_signed
,/* complain_on_overflow */
285 bfd_elf_generic_reloc
, /* special_function */
286 "R_ARM_SWI8", /* name */
287 FALSE
, /* partial_inplace */
288 0x00000000, /* src_mask */
289 0x00000000, /* dst_mask */
290 FALSE
), /* pcrel_offset */
292 /* BLX instruction for the ARM. */
293 HOWTO (R_ARM_XPC25
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 TRUE
, /* pc_relative */
299 complain_overflow_signed
,/* complain_on_overflow */
300 bfd_elf_generic_reloc
, /* special_function */
301 "R_ARM_XPC25", /* name */
302 FALSE
, /* partial_inplace */
303 0x00ffffff, /* src_mask */
304 0x00ffffff, /* dst_mask */
305 TRUE
), /* pcrel_offset */
307 /* BLX instruction for the Thumb. */
308 HOWTO (R_ARM_THM_XPC22
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 TRUE
, /* pc_relative */
314 complain_overflow_signed
,/* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_ARM_THM_XPC22", /* name */
317 FALSE
, /* partial_inplace */
318 0x07ff07ff, /* src_mask */
319 0x07ff07ff, /* dst_mask */
320 TRUE
), /* pcrel_offset */
322 /* Dynamic TLS relocations. */
324 HOWTO (R_ARM_TLS_DTPMOD32
, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 FALSE
, /* pc_relative */
330 complain_overflow_bitfield
,/* complain_on_overflow */
331 bfd_elf_generic_reloc
, /* special_function */
332 "R_ARM_TLS_DTPMOD32", /* name */
333 TRUE
, /* partial_inplace */
334 0xffffffff, /* src_mask */
335 0xffffffff, /* dst_mask */
336 FALSE
), /* pcrel_offset */
338 HOWTO (R_ARM_TLS_DTPOFF32
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_bitfield
,/* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_ARM_TLS_DTPOFF32", /* name */
347 TRUE
, /* partial_inplace */
348 0xffffffff, /* src_mask */
349 0xffffffff, /* dst_mask */
350 FALSE
), /* pcrel_offset */
352 HOWTO (R_ARM_TLS_TPOFF32
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE
, /* pc_relative */
358 complain_overflow_bitfield
,/* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_ARM_TLS_TPOFF32", /* name */
361 TRUE
, /* partial_inplace */
362 0xffffffff, /* src_mask */
363 0xffffffff, /* dst_mask */
364 FALSE
), /* pcrel_offset */
366 /* Relocs used in ARM Linux */
368 HOWTO (R_ARM_COPY
, /* type */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
372 FALSE
, /* pc_relative */
374 complain_overflow_bitfield
,/* complain_on_overflow */
375 bfd_elf_generic_reloc
, /* special_function */
376 "R_ARM_COPY", /* name */
377 TRUE
, /* partial_inplace */
378 0xffffffff, /* src_mask */
379 0xffffffff, /* dst_mask */
380 FALSE
), /* pcrel_offset */
382 HOWTO (R_ARM_GLOB_DAT
, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 FALSE
, /* pc_relative */
388 complain_overflow_bitfield
,/* complain_on_overflow */
389 bfd_elf_generic_reloc
, /* special_function */
390 "R_ARM_GLOB_DAT", /* name */
391 TRUE
, /* partial_inplace */
392 0xffffffff, /* src_mask */
393 0xffffffff, /* dst_mask */
394 FALSE
), /* pcrel_offset */
396 HOWTO (R_ARM_JUMP_SLOT
, /* type */
398 2, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE
, /* pc_relative */
402 complain_overflow_bitfield
,/* complain_on_overflow */
403 bfd_elf_generic_reloc
, /* special_function */
404 "R_ARM_JUMP_SLOT", /* name */
405 TRUE
, /* partial_inplace */
406 0xffffffff, /* src_mask */
407 0xffffffff, /* dst_mask */
408 FALSE
), /* pcrel_offset */
410 HOWTO (R_ARM_RELATIVE
, /* type */
412 2, /* size (0 = byte, 1 = short, 2 = long) */
414 FALSE
, /* pc_relative */
416 complain_overflow_bitfield
,/* complain_on_overflow */
417 bfd_elf_generic_reloc
, /* special_function */
418 "R_ARM_RELATIVE", /* name */
419 TRUE
, /* partial_inplace */
420 0xffffffff, /* src_mask */
421 0xffffffff, /* dst_mask */
422 FALSE
), /* pcrel_offset */
424 HOWTO (R_ARM_GOTOFF32
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE
, /* pc_relative */
430 complain_overflow_bitfield
,/* complain_on_overflow */
431 bfd_elf_generic_reloc
, /* special_function */
432 "R_ARM_GOTOFF32", /* name */
433 TRUE
, /* partial_inplace */
434 0xffffffff, /* src_mask */
435 0xffffffff, /* dst_mask */
436 FALSE
), /* pcrel_offset */
438 HOWTO (R_ARM_GOTPC
, /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 TRUE
, /* pc_relative */
444 complain_overflow_bitfield
,/* complain_on_overflow */
445 bfd_elf_generic_reloc
, /* special_function */
446 "R_ARM_GOTPC", /* name */
447 TRUE
, /* partial_inplace */
448 0xffffffff, /* src_mask */
449 0xffffffff, /* dst_mask */
450 TRUE
), /* pcrel_offset */
452 HOWTO (R_ARM_GOT32
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 FALSE
, /* pc_relative */
458 complain_overflow_bitfield
,/* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_ARM_GOT32", /* name */
461 TRUE
, /* partial_inplace */
462 0xffffffff, /* src_mask */
463 0xffffffff, /* dst_mask */
464 FALSE
), /* pcrel_offset */
466 HOWTO (R_ARM_PLT32
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE
, /* pc_relative */
472 complain_overflow_bitfield
,/* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 "R_ARM_PLT32", /* name */
475 FALSE
, /* partial_inplace */
476 0x00ffffff, /* src_mask */
477 0x00ffffff, /* dst_mask */
478 TRUE
), /* pcrel_offset */
480 HOWTO (R_ARM_CALL
, /* type */
482 2, /* size (0 = byte, 1 = short, 2 = long) */
484 TRUE
, /* pc_relative */
486 complain_overflow_signed
,/* complain_on_overflow */
487 bfd_elf_generic_reloc
, /* special_function */
488 "R_ARM_CALL", /* name */
489 FALSE
, /* partial_inplace */
490 0x00ffffff, /* src_mask */
491 0x00ffffff, /* dst_mask */
492 TRUE
), /* pcrel_offset */
494 HOWTO (R_ARM_JUMP24
, /* type */
496 2, /* size (0 = byte, 1 = short, 2 = long) */
498 TRUE
, /* pc_relative */
500 complain_overflow_signed
,/* complain_on_overflow */
501 bfd_elf_generic_reloc
, /* special_function */
502 "R_ARM_JUMP24", /* name */
503 FALSE
, /* partial_inplace */
504 0x00ffffff, /* src_mask */
505 0x00ffffff, /* dst_mask */
506 TRUE
), /* pcrel_offset */
508 HOWTO (R_ARM_THM_JUMP24
, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 TRUE
, /* pc_relative */
514 complain_overflow_signed
,/* complain_on_overflow */
515 bfd_elf_generic_reloc
, /* special_function */
516 "R_ARM_THM_JUMP24", /* name */
517 FALSE
, /* partial_inplace */
518 0x07ff2fff, /* src_mask */
519 0x07ff2fff, /* dst_mask */
520 TRUE
), /* pcrel_offset */
522 HOWTO (R_ARM_BASE_ABS
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 FALSE
, /* pc_relative */
528 complain_overflow_dont
,/* complain_on_overflow */
529 bfd_elf_generic_reloc
, /* special_function */
530 "R_ARM_BASE_ABS", /* name */
531 FALSE
, /* partial_inplace */
532 0xffffffff, /* src_mask */
533 0xffffffff, /* dst_mask */
534 FALSE
), /* pcrel_offset */
536 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 TRUE
, /* pc_relative */
542 complain_overflow_dont
,/* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_ARM_ALU_PCREL_7_0", /* name */
545 FALSE
, /* partial_inplace */
546 0x00000fff, /* src_mask */
547 0x00000fff, /* dst_mask */
548 TRUE
), /* pcrel_offset */
550 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 TRUE
, /* pc_relative */
556 complain_overflow_dont
,/* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_ARM_ALU_PCREL_15_8",/* name */
559 FALSE
, /* partial_inplace */
560 0x00000fff, /* src_mask */
561 0x00000fff, /* dst_mask */
562 TRUE
), /* pcrel_offset */
564 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 TRUE
, /* pc_relative */
570 complain_overflow_dont
,/* complain_on_overflow */
571 bfd_elf_generic_reloc
, /* special_function */
572 "R_ARM_ALU_PCREL_23_15",/* name */
573 FALSE
, /* partial_inplace */
574 0x00000fff, /* src_mask */
575 0x00000fff, /* dst_mask */
576 TRUE
), /* pcrel_offset */
578 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_dont
,/* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_ARM_LDR_SBREL_11_0",/* name */
587 FALSE
, /* partial_inplace */
588 0x00000fff, /* src_mask */
589 0x00000fff, /* dst_mask */
590 FALSE
), /* pcrel_offset */
592 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 FALSE
, /* pc_relative */
598 complain_overflow_dont
,/* complain_on_overflow */
599 bfd_elf_generic_reloc
, /* special_function */
600 "R_ARM_ALU_SBREL_19_12",/* name */
601 FALSE
, /* partial_inplace */
602 0x000ff000, /* src_mask */
603 0x000ff000, /* dst_mask */
604 FALSE
), /* pcrel_offset */
606 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 FALSE
, /* pc_relative */
612 complain_overflow_dont
,/* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 "R_ARM_ALU_SBREL_27_20",/* name */
615 FALSE
, /* partial_inplace */
616 0x0ff00000, /* src_mask */
617 0x0ff00000, /* dst_mask */
618 FALSE
), /* pcrel_offset */
620 HOWTO (R_ARM_TARGET1
, /* type */
622 2, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE
, /* pc_relative */
626 complain_overflow_dont
,/* complain_on_overflow */
627 bfd_elf_generic_reloc
, /* special_function */
628 "R_ARM_TARGET1", /* name */
629 FALSE
, /* partial_inplace */
630 0xffffffff, /* src_mask */
631 0xffffffff, /* dst_mask */
632 FALSE
), /* pcrel_offset */
634 HOWTO (R_ARM_ROSEGREL32
, /* type */
636 2, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE
, /* pc_relative */
640 complain_overflow_dont
,/* complain_on_overflow */
641 bfd_elf_generic_reloc
, /* special_function */
642 "R_ARM_ROSEGREL32", /* name */
643 FALSE
, /* partial_inplace */
644 0xffffffff, /* src_mask */
645 0xffffffff, /* dst_mask */
646 FALSE
), /* pcrel_offset */
648 HOWTO (R_ARM_V4BX
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 FALSE
, /* pc_relative */
654 complain_overflow_dont
,/* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_ARM_V4BX", /* name */
657 FALSE
, /* partial_inplace */
658 0xffffffff, /* src_mask */
659 0xffffffff, /* dst_mask */
660 FALSE
), /* pcrel_offset */
662 HOWTO (R_ARM_TARGET2
, /* type */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 FALSE
, /* pc_relative */
668 complain_overflow_signed
,/* complain_on_overflow */
669 bfd_elf_generic_reloc
, /* special_function */
670 "R_ARM_TARGET2", /* name */
671 FALSE
, /* partial_inplace */
672 0xffffffff, /* src_mask */
673 0xffffffff, /* dst_mask */
674 TRUE
), /* pcrel_offset */
676 HOWTO (R_ARM_PREL31
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 TRUE
, /* pc_relative */
682 complain_overflow_signed
,/* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_ARM_PREL31", /* name */
685 FALSE
, /* partial_inplace */
686 0x7fffffff, /* src_mask */
687 0x7fffffff, /* dst_mask */
688 TRUE
), /* pcrel_offset */
690 HOWTO (R_ARM_MOVW_ABS_NC
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_dont
,/* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_ARM_MOVW_ABS_NC", /* name */
699 FALSE
, /* partial_inplace */
700 0x000f0fff, /* src_mask */
701 0x000f0fff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 HOWTO (R_ARM_MOVT_ABS
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 FALSE
, /* pc_relative */
710 complain_overflow_bitfield
,/* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_ARM_MOVT_ABS", /* name */
713 FALSE
, /* partial_inplace */
714 0x000f0fff, /* src_mask */
715 0x000f0fff, /* dst_mask */
716 FALSE
), /* pcrel_offset */
718 HOWTO (R_ARM_MOVW_PREL_NC
, /* type */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 TRUE
, /* pc_relative */
724 complain_overflow_dont
,/* complain_on_overflow */
725 bfd_elf_generic_reloc
, /* special_function */
726 "R_ARM_MOVW_PREL_NC", /* name */
727 FALSE
, /* partial_inplace */
728 0x000f0fff, /* src_mask */
729 0x000f0fff, /* dst_mask */
730 TRUE
), /* pcrel_offset */
732 HOWTO (R_ARM_MOVT_PREL
, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 TRUE
, /* pc_relative */
738 complain_overflow_bitfield
,/* complain_on_overflow */
739 bfd_elf_generic_reloc
, /* special_function */
740 "R_ARM_MOVT_PREL", /* name */
741 FALSE
, /* partial_inplace */
742 0x000f0fff, /* src_mask */
743 0x000f0fff, /* dst_mask */
744 TRUE
), /* pcrel_offset */
746 HOWTO (R_ARM_THM_MOVW_ABS_NC
, /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 FALSE
, /* pc_relative */
752 complain_overflow_dont
,/* complain_on_overflow */
753 bfd_elf_generic_reloc
, /* special_function */
754 "R_ARM_THM_MOVW_ABS_NC",/* name */
755 FALSE
, /* partial_inplace */
756 0x040f70ff, /* src_mask */
757 0x040f70ff, /* dst_mask */
758 FALSE
), /* pcrel_offset */
760 HOWTO (R_ARM_THM_MOVT_ABS
, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 FALSE
, /* pc_relative */
766 complain_overflow_bitfield
,/* complain_on_overflow */
767 bfd_elf_generic_reloc
, /* special_function */
768 "R_ARM_THM_MOVT_ABS", /* name */
769 FALSE
, /* partial_inplace */
770 0x040f70ff, /* src_mask */
771 0x040f70ff, /* dst_mask */
772 FALSE
), /* pcrel_offset */
774 HOWTO (R_ARM_THM_MOVW_PREL_NC
,/* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 TRUE
, /* pc_relative */
780 complain_overflow_dont
,/* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_ARM_THM_MOVW_PREL_NC",/* name */
783 FALSE
, /* partial_inplace */
784 0x040f70ff, /* src_mask */
785 0x040f70ff, /* dst_mask */
786 TRUE
), /* pcrel_offset */
788 HOWTO (R_ARM_THM_MOVT_PREL
, /* type */
790 2, /* size (0 = byte, 1 = short, 2 = long) */
792 TRUE
, /* pc_relative */
794 complain_overflow_bitfield
,/* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_ARM_THM_MOVT_PREL", /* name */
797 FALSE
, /* partial_inplace */
798 0x040f70ff, /* src_mask */
799 0x040f70ff, /* dst_mask */
800 TRUE
), /* pcrel_offset */
802 HOWTO (R_ARM_THM_JUMP19
, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 TRUE
, /* pc_relative */
808 complain_overflow_signed
,/* complain_on_overflow */
809 bfd_elf_generic_reloc
, /* special_function */
810 "R_ARM_THM_JUMP19", /* name */
811 FALSE
, /* partial_inplace */
812 0x043f2fff, /* src_mask */
813 0x043f2fff, /* dst_mask */
814 TRUE
), /* pcrel_offset */
816 HOWTO (R_ARM_THM_JUMP6
, /* type */
818 1, /* size (0 = byte, 1 = short, 2 = long) */
820 TRUE
, /* pc_relative */
822 complain_overflow_unsigned
,/* complain_on_overflow */
823 bfd_elf_generic_reloc
, /* special_function */
824 "R_ARM_THM_JUMP6", /* name */
825 FALSE
, /* partial_inplace */
826 0x02f8, /* src_mask */
827 0x02f8, /* dst_mask */
828 TRUE
), /* pcrel_offset */
830 /* These are declared as 13-bit signed relocations because we can
831 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
833 HOWTO (R_ARM_THM_ALU_PREL_11_0
,/* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 TRUE
, /* pc_relative */
839 complain_overflow_dont
,/* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_ARM_THM_ALU_PREL_11_0",/* name */
842 FALSE
, /* partial_inplace */
843 0xffffffff, /* src_mask */
844 0xffffffff, /* dst_mask */
845 TRUE
), /* pcrel_offset */
847 HOWTO (R_ARM_THM_PC12
, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 TRUE
, /* pc_relative */
853 complain_overflow_dont
,/* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 "R_ARM_THM_PC12", /* name */
856 FALSE
, /* partial_inplace */
857 0xffffffff, /* src_mask */
858 0xffffffff, /* dst_mask */
859 TRUE
), /* pcrel_offset */
861 HOWTO (R_ARM_ABS32_NOI
, /* type */
863 2, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE
, /* pc_relative */
867 complain_overflow_dont
,/* complain_on_overflow */
868 bfd_elf_generic_reloc
, /* special_function */
869 "R_ARM_ABS32_NOI", /* name */
870 FALSE
, /* partial_inplace */
871 0xffffffff, /* src_mask */
872 0xffffffff, /* dst_mask */
873 FALSE
), /* pcrel_offset */
875 HOWTO (R_ARM_REL32_NOI
, /* type */
877 2, /* size (0 = byte, 1 = short, 2 = long) */
879 TRUE
, /* pc_relative */
881 complain_overflow_dont
,/* complain_on_overflow */
882 bfd_elf_generic_reloc
, /* special_function */
883 "R_ARM_REL32_NOI", /* name */
884 FALSE
, /* partial_inplace */
885 0xffffffff, /* src_mask */
886 0xffffffff, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* Group relocations. */
891 HOWTO (R_ARM_ALU_PC_G0_NC
, /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 TRUE
, /* pc_relative */
897 complain_overflow_dont
,/* complain_on_overflow */
898 bfd_elf_generic_reloc
, /* special_function */
899 "R_ARM_ALU_PC_G0_NC", /* name */
900 FALSE
, /* partial_inplace */
901 0xffffffff, /* src_mask */
902 0xffffffff, /* dst_mask */
903 TRUE
), /* pcrel_offset */
905 HOWTO (R_ARM_ALU_PC_G0
, /* type */
907 2, /* size (0 = byte, 1 = short, 2 = long) */
909 TRUE
, /* pc_relative */
911 complain_overflow_dont
,/* complain_on_overflow */
912 bfd_elf_generic_reloc
, /* special_function */
913 "R_ARM_ALU_PC_G0", /* name */
914 FALSE
, /* partial_inplace */
915 0xffffffff, /* src_mask */
916 0xffffffff, /* dst_mask */
917 TRUE
), /* pcrel_offset */
919 HOWTO (R_ARM_ALU_PC_G1_NC
, /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 TRUE
, /* pc_relative */
925 complain_overflow_dont
,/* complain_on_overflow */
926 bfd_elf_generic_reloc
, /* special_function */
927 "R_ARM_ALU_PC_G1_NC", /* name */
928 FALSE
, /* partial_inplace */
929 0xffffffff, /* src_mask */
930 0xffffffff, /* dst_mask */
931 TRUE
), /* pcrel_offset */
933 HOWTO (R_ARM_ALU_PC_G1
, /* type */
935 2, /* size (0 = byte, 1 = short, 2 = long) */
937 TRUE
, /* pc_relative */
939 complain_overflow_dont
,/* complain_on_overflow */
940 bfd_elf_generic_reloc
, /* special_function */
941 "R_ARM_ALU_PC_G1", /* name */
942 FALSE
, /* partial_inplace */
943 0xffffffff, /* src_mask */
944 0xffffffff, /* dst_mask */
945 TRUE
), /* pcrel_offset */
947 HOWTO (R_ARM_ALU_PC_G2
, /* type */
949 2, /* size (0 = byte, 1 = short, 2 = long) */
951 TRUE
, /* pc_relative */
953 complain_overflow_dont
,/* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_ARM_ALU_PC_G2", /* name */
956 FALSE
, /* partial_inplace */
957 0xffffffff, /* src_mask */
958 0xffffffff, /* dst_mask */
959 TRUE
), /* pcrel_offset */
961 HOWTO (R_ARM_LDR_PC_G1
, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 TRUE
, /* pc_relative */
967 complain_overflow_dont
,/* complain_on_overflow */
968 bfd_elf_generic_reloc
, /* special_function */
969 "R_ARM_LDR_PC_G1", /* name */
970 FALSE
, /* partial_inplace */
971 0xffffffff, /* src_mask */
972 0xffffffff, /* dst_mask */
973 TRUE
), /* pcrel_offset */
975 HOWTO (R_ARM_LDR_PC_G2
, /* type */
977 2, /* size (0 = byte, 1 = short, 2 = long) */
979 TRUE
, /* pc_relative */
981 complain_overflow_dont
,/* complain_on_overflow */
982 bfd_elf_generic_reloc
, /* special_function */
983 "R_ARM_LDR_PC_G2", /* name */
984 FALSE
, /* partial_inplace */
985 0xffffffff, /* src_mask */
986 0xffffffff, /* dst_mask */
987 TRUE
), /* pcrel_offset */
989 HOWTO (R_ARM_LDRS_PC_G0
, /* type */
991 2, /* size (0 = byte, 1 = short, 2 = long) */
993 TRUE
, /* pc_relative */
995 complain_overflow_dont
,/* complain_on_overflow */
996 bfd_elf_generic_reloc
, /* special_function */
997 "R_ARM_LDRS_PC_G0", /* name */
998 FALSE
, /* partial_inplace */
999 0xffffffff, /* src_mask */
1000 0xffffffff, /* dst_mask */
1001 TRUE
), /* pcrel_offset */
1003 HOWTO (R_ARM_LDRS_PC_G1
, /* type */
1005 2, /* size (0 = byte, 1 = short, 2 = long) */
1007 TRUE
, /* pc_relative */
1009 complain_overflow_dont
,/* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_ARM_LDRS_PC_G1", /* name */
1012 FALSE
, /* partial_inplace */
1013 0xffffffff, /* src_mask */
1014 0xffffffff, /* dst_mask */
1015 TRUE
), /* pcrel_offset */
1017 HOWTO (R_ARM_LDRS_PC_G2
, /* type */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 TRUE
, /* pc_relative */
1023 complain_overflow_dont
,/* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_ARM_LDRS_PC_G2", /* name */
1026 FALSE
, /* partial_inplace */
1027 0xffffffff, /* src_mask */
1028 0xffffffff, /* dst_mask */
1029 TRUE
), /* pcrel_offset */
1031 HOWTO (R_ARM_LDC_PC_G0
, /* type */
1033 2, /* size (0 = byte, 1 = short, 2 = long) */
1035 TRUE
, /* pc_relative */
1037 complain_overflow_dont
,/* complain_on_overflow */
1038 bfd_elf_generic_reloc
, /* special_function */
1039 "R_ARM_LDC_PC_G0", /* name */
1040 FALSE
, /* partial_inplace */
1041 0xffffffff, /* src_mask */
1042 0xffffffff, /* dst_mask */
1043 TRUE
), /* pcrel_offset */
1045 HOWTO (R_ARM_LDC_PC_G1
, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 TRUE
, /* pc_relative */
1051 complain_overflow_dont
,/* complain_on_overflow */
1052 bfd_elf_generic_reloc
, /* special_function */
1053 "R_ARM_LDC_PC_G1", /* name */
1054 FALSE
, /* partial_inplace */
1055 0xffffffff, /* src_mask */
1056 0xffffffff, /* dst_mask */
1057 TRUE
), /* pcrel_offset */
1059 HOWTO (R_ARM_LDC_PC_G2
, /* type */
1061 2, /* size (0 = byte, 1 = short, 2 = long) */
1063 TRUE
, /* pc_relative */
1065 complain_overflow_dont
,/* complain_on_overflow */
1066 bfd_elf_generic_reloc
, /* special_function */
1067 "R_ARM_LDC_PC_G2", /* name */
1068 FALSE
, /* partial_inplace */
1069 0xffffffff, /* src_mask */
1070 0xffffffff, /* dst_mask */
1071 TRUE
), /* pcrel_offset */
1073 HOWTO (R_ARM_ALU_SB_G0_NC
, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 TRUE
, /* pc_relative */
1079 complain_overflow_dont
,/* complain_on_overflow */
1080 bfd_elf_generic_reloc
, /* special_function */
1081 "R_ARM_ALU_SB_G0_NC", /* name */
1082 FALSE
, /* partial_inplace */
1083 0xffffffff, /* src_mask */
1084 0xffffffff, /* dst_mask */
1085 TRUE
), /* pcrel_offset */
1087 HOWTO (R_ARM_ALU_SB_G0
, /* type */
1089 2, /* size (0 = byte, 1 = short, 2 = long) */
1091 TRUE
, /* pc_relative */
1093 complain_overflow_dont
,/* complain_on_overflow */
1094 bfd_elf_generic_reloc
, /* special_function */
1095 "R_ARM_ALU_SB_G0", /* name */
1096 FALSE
, /* partial_inplace */
1097 0xffffffff, /* src_mask */
1098 0xffffffff, /* dst_mask */
1099 TRUE
), /* pcrel_offset */
1101 HOWTO (R_ARM_ALU_SB_G1_NC
, /* type */
1103 2, /* size (0 = byte, 1 = short, 2 = long) */
1105 TRUE
, /* pc_relative */
1107 complain_overflow_dont
,/* complain_on_overflow */
1108 bfd_elf_generic_reloc
, /* special_function */
1109 "R_ARM_ALU_SB_G1_NC", /* name */
1110 FALSE
, /* partial_inplace */
1111 0xffffffff, /* src_mask */
1112 0xffffffff, /* dst_mask */
1113 TRUE
), /* pcrel_offset */
1115 HOWTO (R_ARM_ALU_SB_G1
, /* type */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 TRUE
, /* pc_relative */
1121 complain_overflow_dont
,/* complain_on_overflow */
1122 bfd_elf_generic_reloc
, /* special_function */
1123 "R_ARM_ALU_SB_G1", /* name */
1124 FALSE
, /* partial_inplace */
1125 0xffffffff, /* src_mask */
1126 0xffffffff, /* dst_mask */
1127 TRUE
), /* pcrel_offset */
1129 HOWTO (R_ARM_ALU_SB_G2
, /* type */
1131 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 TRUE
, /* pc_relative */
1135 complain_overflow_dont
,/* complain_on_overflow */
1136 bfd_elf_generic_reloc
, /* special_function */
1137 "R_ARM_ALU_SB_G2", /* name */
1138 FALSE
, /* partial_inplace */
1139 0xffffffff, /* src_mask */
1140 0xffffffff, /* dst_mask */
1141 TRUE
), /* pcrel_offset */
1143 HOWTO (R_ARM_LDR_SB_G0
, /* type */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 TRUE
, /* pc_relative */
1149 complain_overflow_dont
,/* complain_on_overflow */
1150 bfd_elf_generic_reloc
, /* special_function */
1151 "R_ARM_LDR_SB_G0", /* name */
1152 FALSE
, /* partial_inplace */
1153 0xffffffff, /* src_mask */
1154 0xffffffff, /* dst_mask */
1155 TRUE
), /* pcrel_offset */
1157 HOWTO (R_ARM_LDR_SB_G1
, /* type */
1159 2, /* size (0 = byte, 1 = short, 2 = long) */
1161 TRUE
, /* pc_relative */
1163 complain_overflow_dont
,/* complain_on_overflow */
1164 bfd_elf_generic_reloc
, /* special_function */
1165 "R_ARM_LDR_SB_G1", /* name */
1166 FALSE
, /* partial_inplace */
1167 0xffffffff, /* src_mask */
1168 0xffffffff, /* dst_mask */
1169 TRUE
), /* pcrel_offset */
1171 HOWTO (R_ARM_LDR_SB_G2
, /* type */
1173 2, /* size (0 = byte, 1 = short, 2 = long) */
1175 TRUE
, /* pc_relative */
1177 complain_overflow_dont
,/* complain_on_overflow */
1178 bfd_elf_generic_reloc
, /* special_function */
1179 "R_ARM_LDR_SB_G2", /* name */
1180 FALSE
, /* partial_inplace */
1181 0xffffffff, /* src_mask */
1182 0xffffffff, /* dst_mask */
1183 TRUE
), /* pcrel_offset */
1185 HOWTO (R_ARM_LDRS_SB_G0
, /* type */
1187 2, /* size (0 = byte, 1 = short, 2 = long) */
1189 TRUE
, /* pc_relative */
1191 complain_overflow_dont
,/* complain_on_overflow */
1192 bfd_elf_generic_reloc
, /* special_function */
1193 "R_ARM_LDRS_SB_G0", /* name */
1194 FALSE
, /* partial_inplace */
1195 0xffffffff, /* src_mask */
1196 0xffffffff, /* dst_mask */
1197 TRUE
), /* pcrel_offset */
1199 HOWTO (R_ARM_LDRS_SB_G1
, /* type */
1201 2, /* size (0 = byte, 1 = short, 2 = long) */
1203 TRUE
, /* pc_relative */
1205 complain_overflow_dont
,/* complain_on_overflow */
1206 bfd_elf_generic_reloc
, /* special_function */
1207 "R_ARM_LDRS_SB_G1", /* name */
1208 FALSE
, /* partial_inplace */
1209 0xffffffff, /* src_mask */
1210 0xffffffff, /* dst_mask */
1211 TRUE
), /* pcrel_offset */
1213 HOWTO (R_ARM_LDRS_SB_G2
, /* type */
1215 2, /* size (0 = byte, 1 = short, 2 = long) */
1217 TRUE
, /* pc_relative */
1219 complain_overflow_dont
,/* complain_on_overflow */
1220 bfd_elf_generic_reloc
, /* special_function */
1221 "R_ARM_LDRS_SB_G2", /* name */
1222 FALSE
, /* partial_inplace */
1223 0xffffffff, /* src_mask */
1224 0xffffffff, /* dst_mask */
1225 TRUE
), /* pcrel_offset */
1227 HOWTO (R_ARM_LDC_SB_G0
, /* type */
1229 2, /* size (0 = byte, 1 = short, 2 = long) */
1231 TRUE
, /* pc_relative */
1233 complain_overflow_dont
,/* complain_on_overflow */
1234 bfd_elf_generic_reloc
, /* special_function */
1235 "R_ARM_LDC_SB_G0", /* name */
1236 FALSE
, /* partial_inplace */
1237 0xffffffff, /* src_mask */
1238 0xffffffff, /* dst_mask */
1239 TRUE
), /* pcrel_offset */
1241 HOWTO (R_ARM_LDC_SB_G1
, /* type */
1243 2, /* size (0 = byte, 1 = short, 2 = long) */
1245 TRUE
, /* pc_relative */
1247 complain_overflow_dont
,/* complain_on_overflow */
1248 bfd_elf_generic_reloc
, /* special_function */
1249 "R_ARM_LDC_SB_G1", /* name */
1250 FALSE
, /* partial_inplace */
1251 0xffffffff, /* src_mask */
1252 0xffffffff, /* dst_mask */
1253 TRUE
), /* pcrel_offset */
1255 HOWTO (R_ARM_LDC_SB_G2
, /* type */
1257 2, /* size (0 = byte, 1 = short, 2 = long) */
1259 TRUE
, /* pc_relative */
1261 complain_overflow_dont
,/* complain_on_overflow */
1262 bfd_elf_generic_reloc
, /* special_function */
1263 "R_ARM_LDC_SB_G2", /* name */
1264 FALSE
, /* partial_inplace */
1265 0xffffffff, /* src_mask */
1266 0xffffffff, /* dst_mask */
1267 TRUE
), /* pcrel_offset */
1269 /* End of group relocations. */
1271 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
1273 2, /* size (0 = byte, 1 = short, 2 = long) */
1275 FALSE
, /* pc_relative */
1277 complain_overflow_dont
,/* complain_on_overflow */
1278 bfd_elf_generic_reloc
, /* special_function */
1279 "R_ARM_MOVW_BREL_NC", /* name */
1280 FALSE
, /* partial_inplace */
1281 0x0000ffff, /* src_mask */
1282 0x0000ffff, /* dst_mask */
1283 FALSE
), /* pcrel_offset */
1285 HOWTO (R_ARM_MOVT_BREL
, /* type */
1287 2, /* size (0 = byte, 1 = short, 2 = long) */
1289 FALSE
, /* pc_relative */
1291 complain_overflow_bitfield
,/* complain_on_overflow */
1292 bfd_elf_generic_reloc
, /* special_function */
1293 "R_ARM_MOVT_BREL", /* name */
1294 FALSE
, /* partial_inplace */
1295 0x0000ffff, /* src_mask */
1296 0x0000ffff, /* dst_mask */
1297 FALSE
), /* pcrel_offset */
1299 HOWTO (R_ARM_MOVW_BREL
, /* type */
1301 2, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE
, /* pc_relative */
1305 complain_overflow_dont
,/* complain_on_overflow */
1306 bfd_elf_generic_reloc
, /* special_function */
1307 "R_ARM_MOVW_BREL", /* name */
1308 FALSE
, /* partial_inplace */
1309 0x0000ffff, /* src_mask */
1310 0x0000ffff, /* dst_mask */
1311 FALSE
), /* pcrel_offset */
1313 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
1315 2, /* size (0 = byte, 1 = short, 2 = long) */
1317 FALSE
, /* pc_relative */
1319 complain_overflow_dont
,/* complain_on_overflow */
1320 bfd_elf_generic_reloc
, /* special_function */
1321 "R_ARM_THM_MOVW_BREL_NC",/* name */
1322 FALSE
, /* partial_inplace */
1323 0x040f70ff, /* src_mask */
1324 0x040f70ff, /* dst_mask */
1325 FALSE
), /* pcrel_offset */
1327 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
1329 2, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE
, /* pc_relative */
1333 complain_overflow_bitfield
,/* complain_on_overflow */
1334 bfd_elf_generic_reloc
, /* special_function */
1335 "R_ARM_THM_MOVT_BREL", /* name */
1336 FALSE
, /* partial_inplace */
1337 0x040f70ff, /* src_mask */
1338 0x040f70ff, /* dst_mask */
1339 FALSE
), /* pcrel_offset */
1341 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE
, /* pc_relative */
1347 complain_overflow_dont
,/* complain_on_overflow */
1348 bfd_elf_generic_reloc
, /* special_function */
1349 "R_ARM_THM_MOVW_BREL", /* name */
1350 FALSE
, /* partial_inplace */
1351 0x040f70ff, /* src_mask */
1352 0x040f70ff, /* dst_mask */
1353 FALSE
), /* pcrel_offset */
1355 HOWTO (R_ARM_TLS_GOTDESC
, /* type */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE
, /* pc_relative */
1361 complain_overflow_bitfield
,/* complain_on_overflow */
1362 NULL
, /* special_function */
1363 "R_ARM_TLS_GOTDESC", /* name */
1364 TRUE
, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE
), /* pcrel_offset */
1369 HOWTO (R_ARM_TLS_CALL
, /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE
, /* pc_relative */
1375 complain_overflow_dont
,/* complain_on_overflow */
1376 bfd_elf_generic_reloc
, /* special_function */
1377 "R_ARM_TLS_CALL", /* name */
1378 FALSE
, /* partial_inplace */
1379 0x00ffffff, /* src_mask */
1380 0x00ffffff, /* dst_mask */
1381 FALSE
), /* pcrel_offset */
1383 HOWTO (R_ARM_TLS_DESCSEQ
, /* type */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE
, /* pc_relative */
1389 complain_overflow_bitfield
,/* complain_on_overflow */
1390 bfd_elf_generic_reloc
, /* special_function */
1391 "R_ARM_TLS_DESCSEQ", /* name */
1392 FALSE
, /* partial_inplace */
1393 0x00000000, /* src_mask */
1394 0x00000000, /* dst_mask */
1395 FALSE
), /* pcrel_offset */
1397 HOWTO (R_ARM_THM_TLS_CALL
, /* type */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE
, /* pc_relative */
1403 complain_overflow_dont
,/* complain_on_overflow */
1404 bfd_elf_generic_reloc
, /* special_function */
1405 "R_ARM_THM_TLS_CALL", /* name */
1406 FALSE
, /* partial_inplace */
1407 0x07ff07ff, /* src_mask */
1408 0x07ff07ff, /* dst_mask */
1409 FALSE
), /* pcrel_offset */
1411 HOWTO (R_ARM_PLT32_ABS
, /* type */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1415 FALSE
, /* pc_relative */
1417 complain_overflow_dont
,/* complain_on_overflow */
1418 bfd_elf_generic_reloc
, /* special_function */
1419 "R_ARM_PLT32_ABS", /* name */
1420 FALSE
, /* partial_inplace */
1421 0xffffffff, /* src_mask */
1422 0xffffffff, /* dst_mask */
1423 FALSE
), /* pcrel_offset */
1425 HOWTO (R_ARM_GOT_ABS
, /* type */
1427 2, /* size (0 = byte, 1 = short, 2 = long) */
1429 FALSE
, /* pc_relative */
1431 complain_overflow_dont
,/* complain_on_overflow */
1432 bfd_elf_generic_reloc
, /* special_function */
1433 "R_ARM_GOT_ABS", /* name */
1434 FALSE
, /* partial_inplace */
1435 0xffffffff, /* src_mask */
1436 0xffffffff, /* dst_mask */
1437 FALSE
), /* pcrel_offset */
1439 HOWTO (R_ARM_GOT_PREL
, /* type */
1441 2, /* size (0 = byte, 1 = short, 2 = long) */
1443 TRUE
, /* pc_relative */
1445 complain_overflow_dont
, /* complain_on_overflow */
1446 bfd_elf_generic_reloc
, /* special_function */
1447 "R_ARM_GOT_PREL", /* name */
1448 FALSE
, /* partial_inplace */
1449 0xffffffff, /* src_mask */
1450 0xffffffff, /* dst_mask */
1451 TRUE
), /* pcrel_offset */
1453 HOWTO (R_ARM_GOT_BREL12
, /* type */
1455 2, /* size (0 = byte, 1 = short, 2 = long) */
1457 FALSE
, /* pc_relative */
1459 complain_overflow_bitfield
,/* complain_on_overflow */
1460 bfd_elf_generic_reloc
, /* special_function */
1461 "R_ARM_GOT_BREL12", /* name */
1462 FALSE
, /* partial_inplace */
1463 0x00000fff, /* src_mask */
1464 0x00000fff, /* dst_mask */
1465 FALSE
), /* pcrel_offset */
1467 HOWTO (R_ARM_GOTOFF12
, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 FALSE
, /* pc_relative */
1473 complain_overflow_bitfield
,/* complain_on_overflow */
1474 bfd_elf_generic_reloc
, /* special_function */
1475 "R_ARM_GOTOFF12", /* name */
1476 FALSE
, /* partial_inplace */
1477 0x00000fff, /* src_mask */
1478 0x00000fff, /* dst_mask */
1479 FALSE
), /* pcrel_offset */
1481 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1483 /* GNU extension to record C++ vtable member usage */
1484 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE
, /* pc_relative */
1490 complain_overflow_dont
, /* complain_on_overflow */
1491 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1492 "R_ARM_GNU_VTENTRY", /* name */
1493 FALSE
, /* partial_inplace */
1496 FALSE
), /* pcrel_offset */
1498 /* GNU extension to record C++ vtable hierarchy */
1499 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1501 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_dont
, /* complain_on_overflow */
1506 NULL
, /* special_function */
1507 "R_ARM_GNU_VTINHERIT", /* name */
1508 FALSE
, /* partial_inplace */
1511 FALSE
), /* pcrel_offset */
1513 HOWTO (R_ARM_THM_JUMP11
, /* type */
1515 1, /* size (0 = byte, 1 = short, 2 = long) */
1517 TRUE
, /* pc_relative */
1519 complain_overflow_signed
, /* complain_on_overflow */
1520 bfd_elf_generic_reloc
, /* special_function */
1521 "R_ARM_THM_JUMP11", /* name */
1522 FALSE
, /* partial_inplace */
1523 0x000007ff, /* src_mask */
1524 0x000007ff, /* dst_mask */
1525 TRUE
), /* pcrel_offset */
1527 HOWTO (R_ARM_THM_JUMP8
, /* type */
1529 1, /* size (0 = byte, 1 = short, 2 = long) */
1531 TRUE
, /* pc_relative */
1533 complain_overflow_signed
, /* complain_on_overflow */
1534 bfd_elf_generic_reloc
, /* special_function */
1535 "R_ARM_THM_JUMP8", /* name */
1536 FALSE
, /* partial_inplace */
1537 0x000000ff, /* src_mask */
1538 0x000000ff, /* dst_mask */
1539 TRUE
), /* pcrel_offset */
1541 /* TLS relocations */
1542 HOWTO (R_ARM_TLS_GD32
, /* type */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE
, /* pc_relative */
1548 complain_overflow_bitfield
,/* complain_on_overflow */
1549 NULL
, /* special_function */
1550 "R_ARM_TLS_GD32", /* name */
1551 TRUE
, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE
), /* pcrel_offset */
1556 HOWTO (R_ARM_TLS_LDM32
, /* type */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE
, /* pc_relative */
1562 complain_overflow_bitfield
,/* complain_on_overflow */
1563 bfd_elf_generic_reloc
, /* special_function */
1564 "R_ARM_TLS_LDM32", /* name */
1565 TRUE
, /* partial_inplace */
1566 0xffffffff, /* src_mask */
1567 0xffffffff, /* dst_mask */
1568 FALSE
), /* pcrel_offset */
1570 HOWTO (R_ARM_TLS_LDO32
, /* type */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE
, /* pc_relative */
1576 complain_overflow_bitfield
,/* complain_on_overflow */
1577 bfd_elf_generic_reloc
, /* special_function */
1578 "R_ARM_TLS_LDO32", /* name */
1579 TRUE
, /* partial_inplace */
1580 0xffffffff, /* src_mask */
1581 0xffffffff, /* dst_mask */
1582 FALSE
), /* pcrel_offset */
1584 HOWTO (R_ARM_TLS_IE32
, /* type */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE
, /* pc_relative */
1590 complain_overflow_bitfield
,/* complain_on_overflow */
1591 NULL
, /* special_function */
1592 "R_ARM_TLS_IE32", /* name */
1593 TRUE
, /* partial_inplace */
1594 0xffffffff, /* src_mask */
1595 0xffffffff, /* dst_mask */
1596 FALSE
), /* pcrel_offset */
1598 HOWTO (R_ARM_TLS_LE32
, /* type */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1602 FALSE
, /* pc_relative */
1604 complain_overflow_bitfield
,/* complain_on_overflow */
1605 bfd_elf_generic_reloc
, /* special_function */
1606 "R_ARM_TLS_LE32", /* name */
1607 TRUE
, /* partial_inplace */
1608 0xffffffff, /* src_mask */
1609 0xffffffff, /* dst_mask */
1610 FALSE
), /* pcrel_offset */
1612 HOWTO (R_ARM_TLS_LDO12
, /* type */
1614 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE
, /* pc_relative */
1618 complain_overflow_bitfield
,/* complain_on_overflow */
1619 bfd_elf_generic_reloc
, /* special_function */
1620 "R_ARM_TLS_LDO12", /* name */
1621 FALSE
, /* partial_inplace */
1622 0x00000fff, /* src_mask */
1623 0x00000fff, /* dst_mask */
1624 FALSE
), /* pcrel_offset */
1626 HOWTO (R_ARM_TLS_LE12
, /* type */
1628 2, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE
, /* pc_relative */
1632 complain_overflow_bitfield
,/* complain_on_overflow */
1633 bfd_elf_generic_reloc
, /* special_function */
1634 "R_ARM_TLS_LE12", /* name */
1635 FALSE
, /* partial_inplace */
1636 0x00000fff, /* src_mask */
1637 0x00000fff, /* dst_mask */
1638 FALSE
), /* pcrel_offset */
1640 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1642 2, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE
, /* pc_relative */
1646 complain_overflow_bitfield
,/* complain_on_overflow */
1647 bfd_elf_generic_reloc
, /* special_function */
1648 "R_ARM_TLS_IE12GP", /* name */
1649 FALSE
, /* partial_inplace */
1650 0x00000fff, /* src_mask */
1651 0x00000fff, /* dst_mask */
1652 FALSE
), /* pcrel_offset */
1654 /* 112-127 private relocations. */
1672 /* R_ARM_ME_TOO, obsolete. */
1675 HOWTO (R_ARM_THM_TLS_DESCSEQ
, /* type */
1677 1, /* size (0 = byte, 1 = short, 2 = long) */
1679 FALSE
, /* pc_relative */
1681 complain_overflow_bitfield
,/* complain_on_overflow */
1682 bfd_elf_generic_reloc
, /* special_function */
1683 "R_ARM_THM_TLS_DESCSEQ",/* name */
1684 FALSE
, /* partial_inplace */
1685 0x00000000, /* src_mask */
1686 0x00000000, /* dst_mask */
1687 FALSE
), /* pcrel_offset */
1691 static reloc_howto_type elf32_arm_howto_table_2
[1] =
1693 HOWTO (R_ARM_IRELATIVE
, /* type */
1695 2, /* size (0 = byte, 1 = short, 2 = long) */
1697 FALSE
, /* pc_relative */
1699 complain_overflow_bitfield
,/* complain_on_overflow */
1700 bfd_elf_generic_reloc
, /* special_function */
1701 "R_ARM_IRELATIVE", /* name */
1702 TRUE
, /* partial_inplace */
1703 0xffffffff, /* src_mask */
1704 0xffffffff, /* dst_mask */
1705 FALSE
) /* pcrel_offset */
1708 /* 249-255 extended, currently unused, relocations: */
1709 static reloc_howto_type elf32_arm_howto_table_3
[4] =
1711 HOWTO (R_ARM_RREL32
, /* type */
1713 0, /* size (0 = byte, 1 = short, 2 = long) */
1715 FALSE
, /* pc_relative */
1717 complain_overflow_dont
,/* complain_on_overflow */
1718 bfd_elf_generic_reloc
, /* special_function */
1719 "R_ARM_RREL32", /* name */
1720 FALSE
, /* partial_inplace */
1723 FALSE
), /* pcrel_offset */
1725 HOWTO (R_ARM_RABS32
, /* type */
1727 0, /* size (0 = byte, 1 = short, 2 = long) */
1729 FALSE
, /* pc_relative */
1731 complain_overflow_dont
,/* complain_on_overflow */
1732 bfd_elf_generic_reloc
, /* special_function */
1733 "R_ARM_RABS32", /* name */
1734 FALSE
, /* partial_inplace */
1737 FALSE
), /* pcrel_offset */
1739 HOWTO (R_ARM_RPC24
, /* type */
1741 0, /* size (0 = byte, 1 = short, 2 = long) */
1743 FALSE
, /* pc_relative */
1745 complain_overflow_dont
,/* complain_on_overflow */
1746 bfd_elf_generic_reloc
, /* special_function */
1747 "R_ARM_RPC24", /* name */
1748 FALSE
, /* partial_inplace */
1751 FALSE
), /* pcrel_offset */
1753 HOWTO (R_ARM_RBASE
, /* type */
1755 0, /* size (0 = byte, 1 = short, 2 = long) */
1757 FALSE
, /* pc_relative */
1759 complain_overflow_dont
,/* complain_on_overflow */
1760 bfd_elf_generic_reloc
, /* special_function */
1761 "R_ARM_RBASE", /* name */
1762 FALSE
, /* partial_inplace */
1765 FALSE
) /* pcrel_offset */
1768 static reloc_howto_type
*
1769 elf32_arm_howto_from_type (unsigned int r_type
)
1771 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1772 return &elf32_arm_howto_table_1
[r_type
];
1774 if (r_type
== R_ARM_IRELATIVE
)
1775 return &elf32_arm_howto_table_2
[r_type
- R_ARM_IRELATIVE
];
1777 if (r_type
>= R_ARM_RREL32
1778 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_3
))
1779 return &elf32_arm_howto_table_3
[r_type
- R_ARM_RREL32
];
1785 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1786 Elf_Internal_Rela
* elf_reloc
)
1788 unsigned int r_type
;
1790 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1791 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1794 struct elf32_arm_reloc_map
1796 bfd_reloc_code_real_type bfd_reloc_val
;
1797 unsigned char elf_reloc_val
;
1800 /* All entries in this list must also be present in elf32_arm_howto_table. */
1801 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1803 {BFD_RELOC_NONE
, R_ARM_NONE
},
1804 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1805 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1806 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1807 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1808 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1809 {BFD_RELOC_32
, R_ARM_ABS32
},
1810 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1811 {BFD_RELOC_8
, R_ARM_ABS8
},
1812 {BFD_RELOC_16
, R_ARM_ABS16
},
1813 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1814 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1815 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1816 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1817 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1818 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1819 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1820 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1821 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1822 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1823 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1824 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1825 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1826 {BFD_RELOC_ARM_GOT_PREL
, R_ARM_GOT_PREL
},
1827 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1828 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1829 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1830 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1831 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1832 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1833 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1834 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1835 {BFD_RELOC_ARM_TLS_GOTDESC
, R_ARM_TLS_GOTDESC
},
1836 {BFD_RELOC_ARM_TLS_CALL
, R_ARM_TLS_CALL
},
1837 {BFD_RELOC_ARM_THM_TLS_CALL
, R_ARM_THM_TLS_CALL
},
1838 {BFD_RELOC_ARM_TLS_DESCSEQ
, R_ARM_TLS_DESCSEQ
},
1839 {BFD_RELOC_ARM_THM_TLS_DESCSEQ
, R_ARM_THM_TLS_DESCSEQ
},
1840 {BFD_RELOC_ARM_TLS_DESC
, R_ARM_TLS_DESC
},
1841 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1842 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1843 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1844 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1845 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1846 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1847 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1848 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1849 {BFD_RELOC_ARM_IRELATIVE
, R_ARM_IRELATIVE
},
1850 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1851 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1852 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1853 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1854 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1855 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1856 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1857 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1858 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1859 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1860 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1861 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1862 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1863 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1864 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1865 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1866 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1867 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1868 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1869 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1870 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1871 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1872 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1873 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1874 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1875 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1876 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1877 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1878 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1879 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1880 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1881 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1882 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1883 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1884 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1885 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1886 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1887 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
1888 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
}
1891 static reloc_howto_type
*
1892 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1893 bfd_reloc_code_real_type code
)
1897 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
1898 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1899 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1904 static reloc_howto_type
*
1905 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1910 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
1911 if (elf32_arm_howto_table_1
[i
].name
!= NULL
1912 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
1913 return &elf32_arm_howto_table_1
[i
];
1915 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
1916 if (elf32_arm_howto_table_2
[i
].name
!= NULL
1917 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
1918 return &elf32_arm_howto_table_2
[i
];
1920 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_3
); i
++)
1921 if (elf32_arm_howto_table_3
[i
].name
!= NULL
1922 && strcasecmp (elf32_arm_howto_table_3
[i
].name
, r_name
) == 0)
1923 return &elf32_arm_howto_table_3
[i
];
1928 /* Support for core dump NOTE sections. */
1931 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1936 switch (note
->descsz
)
1941 case 148: /* Linux/ARM 32-bit. */
1943 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1946 elf_tdata (abfd
)->core_lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1955 /* Make a ".reg/999" section. */
1956 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1957 size
, note
->descpos
+ offset
);
1961 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1963 switch (note
->descsz
)
1968 case 124: /* Linux/ARM elf_prpsinfo. */
1969 elf_tdata (abfd
)->core_program
1970 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1971 elf_tdata (abfd
)->core_command
1972 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1975 /* Note that for some reason, a spurious space is tacked
1976 onto the end of the args in some (at least one anyway)
1977 implementations, so strip it off if it exists. */
1979 char *command
= elf_tdata (abfd
)->core_command
;
1980 int n
= strlen (command
);
1982 if (0 < n
&& command
[n
- 1] == ' ')
1983 command
[n
- 1] = '\0';
1989 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1990 #define TARGET_LITTLE_NAME "elf32-littlearm"
1991 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1992 #define TARGET_BIG_NAME "elf32-bigarm"
1994 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1995 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1997 typedef unsigned long int insn32
;
1998 typedef unsigned short int insn16
;
2000 /* In lieu of proper flags, assume all EABIv4 or later objects are
2002 #define INTERWORK_FLAG(abfd) \
2003 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
2004 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
2005 || ((abfd)->flags & BFD_LINKER_CREATED))
2007 /* The linker script knows the section names for placement.
2008 The entry_names are used to do simple name mangling on the stubs.
2009 Given a function name, and its type, the stub can be found. The
2010 name can be changed. The only requirement is the %s be present. */
2011 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
2012 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
2014 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
2015 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
2017 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
2018 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
2020 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
2021 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
2023 #define STUB_ENTRY_NAME "__%s_veneer"
2025 /* The name of the dynamic interpreter. This is put in the .interp
2027 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
2029 static const unsigned long tls_trampoline
[] =
2031 0xe08e0000, /* add r0, lr, r0 */
2032 0xe5901004, /* ldr r1, [r0,#4] */
2033 0xe12fff11, /* bx r1 */
2036 static const unsigned long dl_tlsdesc_lazy_trampoline
[] =
2038 0xe52d2004, /* push {r2} */
2039 0xe59f200c, /* ldr r2, [pc, #3f - . - 8] */
2040 0xe59f100c, /* ldr r1, [pc, #4f - . - 8] */
2041 0xe79f2002, /* 1: ldr r2, [pc, r2] */
2042 0xe081100f, /* 2: add r1, pc */
2043 0xe12fff12, /* bx r2 */
2044 0x00000014, /* 3: .word _GLOBAL_OFFSET_TABLE_ - 1b - 8
2045 + dl_tlsdesc_lazy_resolver(GOT) */
2046 0x00000018, /* 4: .word _GLOBAL_OFFSET_TABLE_ - 2b - 8 */
2049 #ifdef FOUR_WORD_PLT
2051 /* The first entry in a procedure linkage table looks like
2052 this. It is set up so that any shared library function that is
2053 called before the relocation has been set up calls the dynamic
2055 static const bfd_vma elf32_arm_plt0_entry
[] =
2057 0xe52de004, /* str lr, [sp, #-4]! */
2058 0xe59fe010, /* ldr lr, [pc, #16] */
2059 0xe08fe00e, /* add lr, pc, lr */
2060 0xe5bef008, /* ldr pc, [lr, #8]! */
2063 /* Subsequent entries in a procedure linkage table look like
2065 static const bfd_vma elf32_arm_plt_entry
[] =
2067 0xe28fc600, /* add ip, pc, #NN */
2068 0xe28cca00, /* add ip, ip, #NN */
2069 0xe5bcf000, /* ldr pc, [ip, #NN]! */
2070 0x00000000, /* unused */
2075 /* The first entry in a procedure linkage table looks like
2076 this. It is set up so that any shared library function that is
2077 called before the relocation has been set up calls the dynamic
2079 static const bfd_vma elf32_arm_plt0_entry
[] =
2081 0xe52de004, /* str lr, [sp, #-4]! */
2082 0xe59fe004, /* ldr lr, [pc, #4] */
2083 0xe08fe00e, /* add lr, pc, lr */
2084 0xe5bef008, /* ldr pc, [lr, #8]! */
2085 0x00000000, /* &GOT[0] - . */
2088 /* Subsequent entries in a procedure linkage table look like
2090 static const bfd_vma elf32_arm_plt_entry
[] =
2092 0xe28fc600, /* add ip, pc, #0xNN00000 */
2093 0xe28cca00, /* add ip, ip, #0xNN000 */
2094 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
2099 /* The format of the first entry in the procedure linkage table
2100 for a VxWorks executable. */
2101 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
2103 0xe52dc008, /* str ip,[sp,#-8]! */
2104 0xe59fc000, /* ldr ip,[pc] */
2105 0xe59cf008, /* ldr pc,[ip,#8] */
2106 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
2109 /* The format of subsequent entries in a VxWorks executable. */
2110 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
2112 0xe59fc000, /* ldr ip,[pc] */
2113 0xe59cf000, /* ldr pc,[ip] */
2114 0x00000000, /* .long @got */
2115 0xe59fc000, /* ldr ip,[pc] */
2116 0xea000000, /* b _PLT */
2117 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2120 /* The format of entries in a VxWorks shared library. */
2121 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
2123 0xe59fc000, /* ldr ip,[pc] */
2124 0xe79cf009, /* ldr pc,[ip,r9] */
2125 0x00000000, /* .long @got */
2126 0xe59fc000, /* ldr ip,[pc] */
2127 0xe599f008, /* ldr pc,[r9,#8] */
2128 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2131 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2132 #define PLT_THUMB_STUB_SIZE 4
2133 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2139 /* The entries in a PLT when using a DLL-based target with multiple
2141 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2143 0xe51ff004, /* ldr pc, [pc, #-4] */
2144 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2147 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2148 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2149 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2150 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2151 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2152 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2162 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2163 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2164 is inserted in arm_build_one_stub(). */
2165 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2166 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2167 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2168 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2169 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2170 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2175 enum stub_insn_type type
;
2176 unsigned int r_type
;
2180 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2181 to reach the stub if necessary. */
2182 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2184 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2185 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2188 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2190 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2192 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2193 ARM_INSN(0xe12fff1c), /* bx ip */
2194 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2197 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2198 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2200 THUMB16_INSN(0xb401), /* push {r0} */
2201 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2202 THUMB16_INSN(0x4684), /* mov ip, r0 */
2203 THUMB16_INSN(0xbc01), /* pop {r0} */
2204 THUMB16_INSN(0x4760), /* bx ip */
2205 THUMB16_INSN(0xbf00), /* nop */
2206 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2209 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2211 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2213 THUMB16_INSN(0x4778), /* bx pc */
2214 THUMB16_INSN(0x46c0), /* nop */
2215 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2216 ARM_INSN(0xe12fff1c), /* bx ip */
2217 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2220 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2222 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2224 THUMB16_INSN(0x4778), /* bx pc */
2225 THUMB16_INSN(0x46c0), /* nop */
2226 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2227 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2230 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2231 one, when the destination is close enough. */
2232 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2234 THUMB16_INSN(0x4778), /* bx pc */
2235 THUMB16_INSN(0x46c0), /* nop */
2236 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2239 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2240 blx to reach the stub if necessary. */
2241 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2243 ARM_INSN(0xe59fc000), /* ldr ip, [pc] */
2244 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2245 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2248 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2249 blx to reach the stub if necessary. We can not add into pc;
2250 it is not guaranteed to mode switch (different in ARMv6 and
2252 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2254 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2255 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2256 ARM_INSN(0xe12fff1c), /* bx ip */
2257 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2260 /* V4T ARM -> ARM long branch stub, PIC. */
2261 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2263 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2264 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2265 ARM_INSN(0xe12fff1c), /* bx ip */
2266 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2269 /* V4T Thumb -> ARM long branch stub, PIC. */
2270 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2272 THUMB16_INSN(0x4778), /* bx pc */
2273 THUMB16_INSN(0x46c0), /* nop */
2274 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2275 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2276 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2279 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2281 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2283 THUMB16_INSN(0xb401), /* push {r0} */
2284 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2285 THUMB16_INSN(0x46fc), /* mov ip, pc */
2286 THUMB16_INSN(0x4484), /* add ip, r0 */
2287 THUMB16_INSN(0xbc01), /* pop {r0} */
2288 THUMB16_INSN(0x4760), /* bx ip */
2289 DATA_WORD(0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2292 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2294 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2296 THUMB16_INSN(0x4778), /* bx pc */
2297 THUMB16_INSN(0x46c0), /* nop */
2298 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2299 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2300 ARM_INSN(0xe12fff1c), /* bx ip */
2301 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2304 /* Thumb2/ARM -> TLS trampoline. Lowest common denominator, which is a
2305 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2306 static const insn_sequence elf32_arm_stub_long_branch_any_tls_pic
[] =
2308 ARM_INSN(0xe59f1000), /* ldr r1, [pc] */
2309 ARM_INSN(0xe08ff001), /* add pc, pc, r1 */
2310 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2313 /* V4T Thumb -> TLS trampoline. lowest common denominator, which is a
2314 long PIC stub. We can use r1 as a scratch -- and cannot use ip. */
2315 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_tls_pic
[] =
2317 THUMB16_INSN(0x4778), /* bx pc */
2318 THUMB16_INSN(0x46c0), /* nop */
2319 ARM_INSN(0xe59f1000), /* ldr r1, [pc, #0] */
2320 ARM_INSN(0xe081f00f), /* add pc, r1, pc */
2321 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2324 /* Cortex-A8 erratum-workaround stubs. */
2326 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2327 can't use a conditional branch to reach this stub). */
2329 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond
[] =
2331 THUMB16_BCOND_INSN(0xd001), /* b<cond>.n true. */
2332 THUMB32_B_INSN(0xf000b800, -4), /* b.w insn_after_original_branch. */
2333 THUMB32_B_INSN(0xf000b800, -4) /* true: b.w original_branch_dest. */
2336 /* Stub used for b.w and bl.w instructions. */
2338 static const insn_sequence elf32_arm_stub_a8_veneer_b
[] =
2340 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2343 static const insn_sequence elf32_arm_stub_a8_veneer_bl
[] =
2345 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2348 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2349 instruction (which switches to ARM mode) to point to this stub. Jump to the
2350 real destination using an ARM-mode branch. */
2352 static const insn_sequence elf32_arm_stub_a8_veneer_blx
[] =
2354 ARM_REL_INSN(0xea000000, -8) /* b original_branch_dest. */
2357 /* Section name for stubs is the associated section name plus this
2359 #define STUB_SUFFIX ".stub"
2361 /* One entry per long/short branch stub defined above. */
2363 DEF_STUB(long_branch_any_any) \
2364 DEF_STUB(long_branch_v4t_arm_thumb) \
2365 DEF_STUB(long_branch_thumb_only) \
2366 DEF_STUB(long_branch_v4t_thumb_thumb) \
2367 DEF_STUB(long_branch_v4t_thumb_arm) \
2368 DEF_STUB(short_branch_v4t_thumb_arm) \
2369 DEF_STUB(long_branch_any_arm_pic) \
2370 DEF_STUB(long_branch_any_thumb_pic) \
2371 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2372 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2373 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2374 DEF_STUB(long_branch_thumb_only_pic) \
2375 DEF_STUB(long_branch_any_tls_pic) \
2376 DEF_STUB(long_branch_v4t_thumb_tls_pic) \
2377 DEF_STUB(a8_veneer_b_cond) \
2378 DEF_STUB(a8_veneer_b) \
2379 DEF_STUB(a8_veneer_bl) \
2380 DEF_STUB(a8_veneer_blx)
2382 #define DEF_STUB(x) arm_stub_##x,
2383 enum elf32_arm_stub_type
{
2386 /* Note the first a8_veneer type */
2387 arm_stub_a8_veneer_lwm
= arm_stub_a8_veneer_b_cond
2393 const insn_sequence
* template_sequence
;
2397 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2398 static const stub_def stub_definitions
[] = {
2403 struct elf32_arm_stub_hash_entry
2405 /* Base hash table entry structure. */
2406 struct bfd_hash_entry root
;
2408 /* The stub section. */
2411 /* Offset within stub_sec of the beginning of this stub. */
2412 bfd_vma stub_offset
;
2414 /* Given the symbol's value and its section we can determine its final
2415 value when building the stubs (so the stub knows where to jump). */
2416 bfd_vma target_value
;
2417 asection
*target_section
;
2419 /* Offset to apply to relocation referencing target_value. */
2420 bfd_vma target_addend
;
2422 /* The instruction which caused this stub to be generated (only valid for
2423 Cortex-A8 erratum workaround stubs at present). */
2424 unsigned long orig_insn
;
2426 /* The stub type. */
2427 enum elf32_arm_stub_type stub_type
;
2428 /* Its encoding size in bytes. */
2431 const insn_sequence
*stub_template
;
2432 /* The size of the template (number of entries). */
2433 int stub_template_size
;
2435 /* The symbol table entry, if any, that this was derived from. */
2436 struct elf32_arm_link_hash_entry
*h
;
2438 /* Type of branch. */
2439 enum arm_st_branch_type branch_type
;
2441 /* Where this stub is being called from, or, in the case of combined
2442 stub sections, the first input section in the group. */
2445 /* The name for the local symbol at the start of this stub. The
2446 stub name in the hash table has to be unique; this does not, so
2447 it can be friendlier. */
2451 /* Used to build a map of a section. This is required for mixed-endian
2454 typedef struct elf32_elf_section_map
2459 elf32_arm_section_map
;
2461 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2465 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2466 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2467 VFP11_ERRATUM_ARM_VENEER
,
2468 VFP11_ERRATUM_THUMB_VENEER
2470 elf32_vfp11_erratum_type
;
2472 typedef struct elf32_vfp11_erratum_list
2474 struct elf32_vfp11_erratum_list
*next
;
2480 struct elf32_vfp11_erratum_list
*veneer
;
2481 unsigned int vfp_insn
;
2485 struct elf32_vfp11_erratum_list
*branch
;
2489 elf32_vfp11_erratum_type type
;
2491 elf32_vfp11_erratum_list
;
2496 INSERT_EXIDX_CANTUNWIND_AT_END
2498 arm_unwind_edit_type
;
2500 /* A (sorted) list of edits to apply to an unwind table. */
2501 typedef struct arm_unwind_table_edit
2503 arm_unwind_edit_type type
;
2504 /* Note: we sometimes want to insert an unwind entry corresponding to a
2505 section different from the one we're currently writing out, so record the
2506 (text) section this edit relates to here. */
2507 asection
*linked_section
;
2509 struct arm_unwind_table_edit
*next
;
2511 arm_unwind_table_edit
;
2513 typedef struct _arm_elf_section_data
2515 /* Information about mapping symbols. */
2516 struct bfd_elf_section_data elf
;
2517 unsigned int mapcount
;
2518 unsigned int mapsize
;
2519 elf32_arm_section_map
*map
;
2520 /* Information about CPU errata. */
2521 unsigned int erratumcount
;
2522 elf32_vfp11_erratum_list
*erratumlist
;
2523 /* Information about unwind tables. */
2526 /* Unwind info attached to a text section. */
2529 asection
*arm_exidx_sec
;
2532 /* Unwind info attached to an .ARM.exidx section. */
2535 arm_unwind_table_edit
*unwind_edit_list
;
2536 arm_unwind_table_edit
*unwind_edit_tail
;
2540 _arm_elf_section_data
;
2542 #define elf32_arm_section_data(sec) \
2543 ((_arm_elf_section_data *) elf_section_data (sec))
2545 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2546 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2547 so may be created multiple times: we use an array of these entries whilst
2548 relaxing which we can refresh easily, then create stubs for each potentially
2549 erratum-triggering instruction once we've settled on a solution. */
2551 struct a8_erratum_fix
{
2556 unsigned long orig_insn
;
2558 enum elf32_arm_stub_type stub_type
;
2559 enum arm_st_branch_type branch_type
;
2562 /* A table of relocs applied to branches which might trigger Cortex-A8
2565 struct a8_erratum_reloc
{
2567 bfd_vma destination
;
2568 struct elf32_arm_link_hash_entry
*hash
;
2569 const char *sym_name
;
2570 unsigned int r_type
;
2571 enum arm_st_branch_type branch_type
;
2572 bfd_boolean non_a8_stub
;
2575 /* The size of the thread control block. */
2578 /* ARM-specific information about a PLT entry, over and above the usual
2580 struct arm_plt_info
{
2581 /* We reference count Thumb references to a PLT entry separately,
2582 so that we can emit the Thumb trampoline only if needed. */
2583 bfd_signed_vma thumb_refcount
;
2585 /* Some references from Thumb code may be eliminated by BL->BLX
2586 conversion, so record them separately. */
2587 bfd_signed_vma maybe_thumb_refcount
;
2589 /* How many of the recorded PLT accesses were from non-call relocations.
2590 This information is useful when deciding whether anything takes the
2591 address of an STT_GNU_IFUNC PLT. A value of 0 means that all
2592 non-call references to the function should resolve directly to the
2593 real runtime target. */
2594 unsigned int noncall_refcount
;
2596 /* Since PLT entries have variable size if the Thumb prologue is
2597 used, we need to record the index into .got.plt instead of
2598 recomputing it from the PLT offset. */
2599 bfd_signed_vma got_offset
;
2602 /* Information about an .iplt entry for a local STT_GNU_IFUNC symbol. */
2603 struct arm_local_iplt_info
{
2604 /* The information that is usually found in the generic ELF part of
2605 the hash table entry. */
2606 union gotplt_union root
;
2608 /* The information that is usually found in the ARM-specific part of
2609 the hash table entry. */
2610 struct arm_plt_info arm
;
2612 /* A list of all potential dynamic relocations against this symbol. */
2613 struct elf_dyn_relocs
*dyn_relocs
;
2616 struct elf_arm_obj_tdata
2618 struct elf_obj_tdata root
;
2620 /* tls_type for each local got entry. */
2621 char *local_got_tls_type
;
2623 /* GOTPLT entries for TLS descriptors. */
2624 bfd_vma
*local_tlsdesc_gotent
;
2626 /* Information for local symbols that need entries in .iplt. */
2627 struct arm_local_iplt_info
**local_iplt
;
2629 /* Zero to warn when linking objects with incompatible enum sizes. */
2630 int no_enum_size_warning
;
2632 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2633 int no_wchar_size_warning
;
2636 #define elf_arm_tdata(bfd) \
2637 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2639 #define elf32_arm_local_got_tls_type(bfd) \
2640 (elf_arm_tdata (bfd)->local_got_tls_type)
2642 #define elf32_arm_local_tlsdesc_gotent(bfd) \
2643 (elf_arm_tdata (bfd)->local_tlsdesc_gotent)
2645 #define elf32_arm_local_iplt(bfd) \
2646 (elf_arm_tdata (bfd)->local_iplt)
2648 #define is_arm_elf(bfd) \
2649 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2650 && elf_tdata (bfd) != NULL \
2651 && elf_object_id (bfd) == ARM_ELF_DATA)
2654 elf32_arm_mkobject (bfd
*abfd
)
2656 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2660 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2662 /* Arm ELF linker hash entry. */
2663 struct elf32_arm_link_hash_entry
2665 struct elf_link_hash_entry root
;
2667 /* Track dynamic relocs copied for this symbol. */
2668 struct elf_dyn_relocs
*dyn_relocs
;
2670 /* ARM-specific PLT information. */
2671 struct arm_plt_info plt
;
2673 #define GOT_UNKNOWN 0
2674 #define GOT_NORMAL 1
2675 #define GOT_TLS_GD 2
2676 #define GOT_TLS_IE 4
2677 #define GOT_TLS_GDESC 8
2678 #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLS_GDESC))
2679 unsigned int tls_type
: 8;
2681 /* True if the symbol's PLT entry is in .iplt rather than .plt. */
2682 unsigned int is_iplt
: 1;
2684 unsigned int unused
: 23;
2686 /* Offset of the GOTPLT entry reserved for the TLS descriptor,
2687 starting at the end of the jump table. */
2688 bfd_vma tlsdesc_got
;
2690 /* The symbol marking the real symbol location for exported thumb
2691 symbols with Arm stubs. */
2692 struct elf_link_hash_entry
*export_glue
;
2694 /* A pointer to the most recently used stub hash entry against this
2696 struct elf32_arm_stub_hash_entry
*stub_cache
;
2699 /* Traverse an arm ELF linker hash table. */
2700 #define elf32_arm_link_hash_traverse(table, func, info) \
2701 (elf_link_hash_traverse \
2703 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2706 /* Get the ARM elf linker hash table from a link_info structure. */
2707 #define elf32_arm_hash_table(info) \
2708 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
2709 == ARM_ELF_DATA ? ((struct elf32_arm_link_hash_table *) ((info)->hash)) : NULL)
2711 #define arm_stub_hash_lookup(table, string, create, copy) \
2712 ((struct elf32_arm_stub_hash_entry *) \
2713 bfd_hash_lookup ((table), (string), (create), (copy)))
2715 /* Array to keep track of which stub sections have been created, and
2716 information on stub grouping. */
2719 /* This is the section to which stubs in the group will be
2722 /* The stub section. */
2726 #define elf32_arm_compute_jump_table_size(htab) \
2727 ((htab)->next_tls_desc_index * 4)
2729 /* ARM ELF linker hash table. */
2730 struct elf32_arm_link_hash_table
2732 /* The main hash table. */
2733 struct elf_link_hash_table root
;
2735 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2736 bfd_size_type thumb_glue_size
;
2738 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2739 bfd_size_type arm_glue_size
;
2741 /* The size in bytes of section containing the ARMv4 BX veneers. */
2742 bfd_size_type bx_glue_size
;
2744 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2745 veneer has been populated. */
2746 bfd_vma bx_glue_offset
[15];
2748 /* The size in bytes of the section containing glue for VFP11 erratum
2750 bfd_size_type vfp11_erratum_glue_size
;
2752 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
2753 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
2754 elf32_arm_write_section(). */
2755 struct a8_erratum_fix
*a8_erratum_fixes
;
2756 unsigned int num_a8_erratum_fixes
;
2758 /* An arbitrary input BFD chosen to hold the glue sections. */
2759 bfd
* bfd_of_glue_owner
;
2761 /* Nonzero to output a BE8 image. */
2764 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2765 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2768 /* The relocation to use for R_ARM_TARGET2 relocations. */
2771 /* 0 = Ignore R_ARM_V4BX.
2772 1 = Convert BX to MOV PC.
2773 2 = Generate v4 interworing stubs. */
2776 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
2779 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2782 /* What sort of code sequences we should look for which may trigger the
2783 VFP11 denorm erratum. */
2784 bfd_arm_vfp11_fix vfp11_fix
;
2786 /* Global counter for the number of fixes we have emitted. */
2787 int num_vfp11_fixes
;
2789 /* Nonzero to force PIC branch veneers. */
2792 /* The number of bytes in the initial entry in the PLT. */
2793 bfd_size_type plt_header_size
;
2795 /* The number of bytes in the subsequent PLT etries. */
2796 bfd_size_type plt_entry_size
;
2798 /* True if the target system is VxWorks. */
2801 /* True if the target system is Symbian OS. */
2804 /* True if the target uses REL relocations. */
2807 /* The index of the next unused R_ARM_TLS_DESC slot in .rel.plt. */
2808 bfd_vma next_tls_desc_index
;
2810 /* How many R_ARM_TLS_DESC relocations were generated so far. */
2811 bfd_vma num_tls_desc
;
2813 /* Short-cuts to get to dynamic linker sections. */
2817 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2820 /* The offset into splt of the PLT entry for the TLS descriptor
2821 resolver. Special values are 0, if not necessary (or not found
2822 to be necessary yet), and -1 if needed but not determined
2824 bfd_vma dt_tlsdesc_plt
;
2826 /* The offset into sgot of the GOT entry used by the PLT entry
2828 bfd_vma dt_tlsdesc_got
;
2830 /* Offset in .plt section of tls_arm_trampoline. */
2831 bfd_vma tls_trampoline
;
2833 /* Data for R_ARM_TLS_LDM32 relocations. */
2836 bfd_signed_vma refcount
;
2840 /* Small local sym cache. */
2841 struct sym_cache sym_cache
;
2843 /* For convenience in allocate_dynrelocs. */
2846 /* The amount of space used by the reserved portion of the sgotplt
2847 section, plus whatever space is used by the jump slots. */
2848 bfd_vma sgotplt_jump_table_size
;
2850 /* The stub hash table. */
2851 struct bfd_hash_table stub_hash_table
;
2853 /* Linker stub bfd. */
2856 /* Linker call-backs. */
2857 asection
* (*add_stub_section
) (const char *, asection
*);
2858 void (*layout_sections_again
) (void);
2860 /* Array to keep track of which stub sections have been created, and
2861 information on stub grouping. */
2862 struct map_stub
*stub_group
;
2864 /* Number of elements in stub_group. */
2867 /* Assorted information used by elf32_arm_size_stubs. */
2868 unsigned int bfd_count
;
2870 asection
**input_list
;
2873 /* Create an entry in an ARM ELF linker hash table. */
2875 static struct bfd_hash_entry
*
2876 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
2877 struct bfd_hash_table
* table
,
2878 const char * string
)
2880 struct elf32_arm_link_hash_entry
* ret
=
2881 (struct elf32_arm_link_hash_entry
*) entry
;
2883 /* Allocate the structure if it has not already been allocated by a
2886 ret
= (struct elf32_arm_link_hash_entry
*)
2887 bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
2889 return (struct bfd_hash_entry
*) ret
;
2891 /* Call the allocation method of the superclass. */
2892 ret
= ((struct elf32_arm_link_hash_entry
*)
2893 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2897 ret
->dyn_relocs
= NULL
;
2898 ret
->tls_type
= GOT_UNKNOWN
;
2899 ret
->tlsdesc_got
= (bfd_vma
) -1;
2900 ret
->plt
.thumb_refcount
= 0;
2901 ret
->plt
.maybe_thumb_refcount
= 0;
2902 ret
->plt
.noncall_refcount
= 0;
2903 ret
->plt
.got_offset
= -1;
2904 ret
->is_iplt
= FALSE
;
2905 ret
->export_glue
= NULL
;
2907 ret
->stub_cache
= NULL
;
2910 return (struct bfd_hash_entry
*) ret
;
2913 /* Ensure that we have allocated bookkeeping structures for ABFD's local
2917 elf32_arm_allocate_local_sym_info (bfd
*abfd
)
2919 if (elf_local_got_refcounts (abfd
) == NULL
)
2921 bfd_size_type num_syms
;
2925 num_syms
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2926 size
= num_syms
* (sizeof (bfd_signed_vma
)
2927 + sizeof (struct arm_local_iplt_info
*)
2930 data
= bfd_zalloc (abfd
, size
);
2934 elf_local_got_refcounts (abfd
) = (bfd_signed_vma
*) data
;
2935 data
+= num_syms
* sizeof (bfd_signed_vma
);
2937 elf32_arm_local_iplt (abfd
) = (struct arm_local_iplt_info
**) data
;
2938 data
+= num_syms
* sizeof (struct arm_local_iplt_info
*);
2940 elf32_arm_local_tlsdesc_gotent (abfd
) = (bfd_vma
*) data
;
2941 data
+= num_syms
* sizeof (bfd_vma
);
2943 elf32_arm_local_got_tls_type (abfd
) = data
;
2948 /* Return the .iplt information for local symbol R_SYMNDX, which belongs
2949 to input bfd ABFD. Create the information if it doesn't already exist.
2950 Return null if an allocation fails. */
2952 static struct arm_local_iplt_info
*
2953 elf32_arm_create_local_iplt (bfd
*abfd
, unsigned long r_symndx
)
2955 struct arm_local_iplt_info
**ptr
;
2957 if (!elf32_arm_allocate_local_sym_info (abfd
))
2960 BFD_ASSERT (r_symndx
< elf_tdata (abfd
)->symtab_hdr
.sh_info
);
2961 ptr
= &elf32_arm_local_iplt (abfd
)[r_symndx
];
2963 *ptr
= bfd_zalloc (abfd
, sizeof (**ptr
));
2967 /* Try to obtain PLT information for the symbol with index R_SYMNDX
2968 in ABFD's symbol table. If the symbol is global, H points to its
2969 hash table entry, otherwise H is null.
2971 Return true if the symbol does have PLT information. When returning
2972 true, point *ROOT_PLT at the target-independent reference count/offset
2973 union and *ARM_PLT at the ARM-specific information. */
2976 elf32_arm_get_plt_info (bfd
*abfd
, struct elf32_arm_link_hash_entry
*h
,
2977 unsigned long r_symndx
, union gotplt_union
**root_plt
,
2978 struct arm_plt_info
**arm_plt
)
2980 struct arm_local_iplt_info
*local_iplt
;
2984 *root_plt
= &h
->root
.plt
;
2989 if (elf32_arm_local_iplt (abfd
) == NULL
)
2992 local_iplt
= elf32_arm_local_iplt (abfd
)[r_symndx
];
2993 if (local_iplt
== NULL
)
2996 *root_plt
= &local_iplt
->root
;
2997 *arm_plt
= &local_iplt
->arm
;
3001 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
3005 elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info
*info
,
3006 struct arm_plt_info
*arm_plt
)
3008 struct elf32_arm_link_hash_table
*htab
;
3010 htab
= elf32_arm_hash_table (info
);
3011 return (arm_plt
->thumb_refcount
!= 0
3012 || (!htab
->use_blx
&& arm_plt
->maybe_thumb_refcount
!= 0));
3015 /* Return a pointer to the head of the dynamic reloc list that should
3016 be used for local symbol ISYM, which is symbol number R_SYMNDX in
3017 ABFD's symbol table. Return null if an error occurs. */
3019 static struct elf_dyn_relocs
**
3020 elf32_arm_get_local_dynreloc_list (bfd
*abfd
, unsigned long r_symndx
,
3021 Elf_Internal_Sym
*isym
)
3023 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
3025 struct arm_local_iplt_info
*local_iplt
;
3027 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
3028 if (local_iplt
== NULL
)
3030 return &local_iplt
->dyn_relocs
;
3034 /* Track dynamic relocs needed for local syms too.
3035 We really need local syms available to do this
3040 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3044 vpp
= &elf_section_data (s
)->local_dynrel
;
3045 return (struct elf_dyn_relocs
**) vpp
;
3049 /* Initialize an entry in the stub hash table. */
3051 static struct bfd_hash_entry
*
3052 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3053 struct bfd_hash_table
*table
,
3056 /* Allocate the structure if it has not already been allocated by a
3060 entry
= (struct bfd_hash_entry
*)
3061 bfd_hash_allocate (table
, sizeof (struct elf32_arm_stub_hash_entry
));
3066 /* Call the allocation method of the superclass. */
3067 entry
= bfd_hash_newfunc (entry
, table
, string
);
3070 struct elf32_arm_stub_hash_entry
*eh
;
3072 /* Initialize the local fields. */
3073 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
3074 eh
->stub_sec
= NULL
;
3075 eh
->stub_offset
= 0;
3076 eh
->target_value
= 0;
3077 eh
->target_section
= NULL
;
3078 eh
->target_addend
= 0;
3080 eh
->stub_type
= arm_stub_none
;
3082 eh
->stub_template
= NULL
;
3083 eh
->stub_template_size
= 0;
3086 eh
->output_name
= NULL
;
3092 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
3093 shortcuts to them in our hash table. */
3096 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3098 struct elf32_arm_link_hash_table
*htab
;
3100 htab
= elf32_arm_hash_table (info
);
3104 /* BPABI objects never have a GOT, or associated sections. */
3105 if (htab
->symbian_p
)
3108 if (! _bfd_elf_create_got_section (dynobj
, info
))
3114 /* Create the .iplt, .rel(a).iplt and .igot.plt sections. */
3117 create_ifunc_sections (struct bfd_link_info
*info
)
3119 struct elf32_arm_link_hash_table
*htab
;
3120 const struct elf_backend_data
*bed
;
3125 htab
= elf32_arm_hash_table (info
);
3126 dynobj
= htab
->root
.dynobj
;
3127 bed
= get_elf_backend_data (dynobj
);
3128 flags
= bed
->dynamic_sec_flags
;
3130 if (htab
->root
.iplt
== NULL
)
3132 s
= bfd_make_section_with_flags (dynobj
, ".iplt",
3133 flags
| SEC_READONLY
| SEC_CODE
);
3135 || !bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3137 htab
->root
.iplt
= s
;
3140 if (htab
->root
.irelplt
== NULL
)
3142 s
= bfd_make_section_with_flags (dynobj
, RELOC_SECTION (htab
, ".iplt"),
3143 flags
| SEC_READONLY
);
3145 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
3147 htab
->root
.irelplt
= s
;
3150 if (htab
->root
.igotplt
== NULL
)
3152 s
= bfd_make_section_with_flags (dynobj
, ".igot.plt", flags
);
3154 || !bfd_set_section_alignment (dynobj
, s
, bed
->s
->log_file_align
))
3156 htab
->root
.igotplt
= s
;
3161 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
3162 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
3166 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3168 struct elf32_arm_link_hash_table
*htab
;
3170 htab
= elf32_arm_hash_table (info
);
3174 if (!htab
->root
.sgot
&& !create_got_section (dynobj
, info
))
3177 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3180 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3182 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
3183 RELOC_SECTION (htab
, ".bss"));
3185 if (htab
->vxworks_p
)
3187 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
3192 htab
->plt_header_size
= 0;
3193 htab
->plt_entry_size
3194 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
3198 htab
->plt_header_size
3199 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
3200 htab
->plt_entry_size
3201 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
3205 if (!htab
->root
.splt
3206 || !htab
->root
.srelplt
3208 || (!info
->shared
&& !htab
->srelbss
))
3214 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3217 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
3218 struct elf_link_hash_entry
*dir
,
3219 struct elf_link_hash_entry
*ind
)
3221 struct elf32_arm_link_hash_entry
*edir
, *eind
;
3223 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
3224 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
3226 if (eind
->dyn_relocs
!= NULL
)
3228 if (edir
->dyn_relocs
!= NULL
)
3230 struct elf_dyn_relocs
**pp
;
3231 struct elf_dyn_relocs
*p
;
3233 /* Add reloc counts against the indirect sym to the direct sym
3234 list. Merge any entries against the same section. */
3235 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3237 struct elf_dyn_relocs
*q
;
3239 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3240 if (q
->sec
== p
->sec
)
3242 q
->pc_count
+= p
->pc_count
;
3243 q
->count
+= p
->count
;
3250 *pp
= edir
->dyn_relocs
;
3253 edir
->dyn_relocs
= eind
->dyn_relocs
;
3254 eind
->dyn_relocs
= NULL
;
3257 if (ind
->root
.type
== bfd_link_hash_indirect
)
3259 /* Copy over PLT info. */
3260 edir
->plt
.thumb_refcount
+= eind
->plt
.thumb_refcount
;
3261 eind
->plt
.thumb_refcount
= 0;
3262 edir
->plt
.maybe_thumb_refcount
+= eind
->plt
.maybe_thumb_refcount
;
3263 eind
->plt
.maybe_thumb_refcount
= 0;
3264 edir
->plt
.noncall_refcount
+= eind
->plt
.noncall_refcount
;
3265 eind
->plt
.noncall_refcount
= 0;
3267 /* We should only allocate a function to .iplt once the final
3268 symbol information is known. */
3269 BFD_ASSERT (!eind
->is_iplt
);
3271 if (dir
->got
.refcount
<= 0)
3273 edir
->tls_type
= eind
->tls_type
;
3274 eind
->tls_type
= GOT_UNKNOWN
;
3278 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3281 /* Create an ARM elf linker hash table. */
3283 static struct bfd_link_hash_table
*
3284 elf32_arm_link_hash_table_create (bfd
*abfd
)
3286 struct elf32_arm_link_hash_table
*ret
;
3287 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
3289 ret
= (struct elf32_arm_link_hash_table
*) bfd_malloc (amt
);
3293 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
3294 elf32_arm_link_hash_newfunc
,
3295 sizeof (struct elf32_arm_link_hash_entry
),
3302 ret
->sdynbss
= NULL
;
3303 ret
->srelbss
= NULL
;
3304 ret
->srelplt2
= NULL
;
3305 ret
->dt_tlsdesc_plt
= 0;
3306 ret
->dt_tlsdesc_got
= 0;
3307 ret
->tls_trampoline
= 0;
3308 ret
->next_tls_desc_index
= 0;
3309 ret
->num_tls_desc
= 0;
3310 ret
->thumb_glue_size
= 0;
3311 ret
->arm_glue_size
= 0;
3312 ret
->bx_glue_size
= 0;
3313 memset (ret
->bx_glue_offset
, 0, sizeof (ret
->bx_glue_offset
));
3314 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
3315 ret
->vfp11_erratum_glue_size
= 0;
3316 ret
->num_vfp11_fixes
= 0;
3317 ret
->fix_cortex_a8
= 0;
3318 ret
->bfd_of_glue_owner
= NULL
;
3319 ret
->byteswap_code
= 0;
3320 ret
->target1_is_rel
= 0;
3321 ret
->target2_reloc
= R_ARM_NONE
;
3322 #ifdef FOUR_WORD_PLT
3323 ret
->plt_header_size
= 16;
3324 ret
->plt_entry_size
= 16;
3326 ret
->plt_header_size
= 20;
3327 ret
->plt_entry_size
= 12;
3334 ret
->sym_cache
.abfd
= NULL
;
3336 ret
->tls_ldm_got
.refcount
= 0;
3337 ret
->stub_bfd
= NULL
;
3338 ret
->add_stub_section
= NULL
;
3339 ret
->layout_sections_again
= NULL
;
3340 ret
->stub_group
= NULL
;
3344 ret
->input_list
= NULL
;
3346 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
3347 sizeof (struct elf32_arm_stub_hash_entry
)))
3353 return &ret
->root
.root
;
3356 /* Free the derived linker hash table. */
3359 elf32_arm_hash_table_free (struct bfd_link_hash_table
*hash
)
3361 struct elf32_arm_link_hash_table
*ret
3362 = (struct elf32_arm_link_hash_table
*) hash
;
3364 bfd_hash_table_free (&ret
->stub_hash_table
);
3365 _bfd_generic_link_hash_table_free (hash
);
3368 /* Determine if we're dealing with a Thumb only architecture. */
3371 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
3373 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3377 if (arch
== TAG_CPU_ARCH_V6_M
|| arch
== TAG_CPU_ARCH_V6S_M
)
3380 if (arch
!= TAG_CPU_ARCH_V7
&& arch
!= TAG_CPU_ARCH_V7E_M
)
3383 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3384 Tag_CPU_arch_profile
);
3386 return profile
== 'M';
3389 /* Determine if we're dealing with a Thumb-2 object. */
3392 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
3394 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3396 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
3399 /* Determine what kind of NOPs are available. */
3402 arch_has_arm_nop (struct elf32_arm_link_hash_table
*globals
)
3404 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3406 return arch
== TAG_CPU_ARCH_V6T2
3407 || arch
== TAG_CPU_ARCH_V6K
3408 || arch
== TAG_CPU_ARCH_V7
3409 || arch
== TAG_CPU_ARCH_V7E_M
;
3413 arch_has_thumb2_nop (struct elf32_arm_link_hash_table
*globals
)
3415 const int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
3417 return (arch
== TAG_CPU_ARCH_V6T2
|| arch
== TAG_CPU_ARCH_V7
3418 || arch
== TAG_CPU_ARCH_V7E_M
);
3422 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
3426 case arm_stub_long_branch_thumb_only
:
3427 case arm_stub_long_branch_v4t_thumb_arm
:
3428 case arm_stub_short_branch_v4t_thumb_arm
:
3429 case arm_stub_long_branch_v4t_thumb_arm_pic
:
3430 case arm_stub_long_branch_thumb_only_pic
:
3441 /* Determine the type of stub needed, if any, for a call. */
3443 static enum elf32_arm_stub_type
3444 arm_type_of_stub (struct bfd_link_info
*info
,
3445 asection
*input_sec
,
3446 const Elf_Internal_Rela
*rel
,
3447 unsigned char st_type
,
3448 enum arm_st_branch_type
*actual_branch_type
,
3449 struct elf32_arm_link_hash_entry
*hash
,
3450 bfd_vma destination
,
3456 bfd_signed_vma branch_offset
;
3457 unsigned int r_type
;
3458 struct elf32_arm_link_hash_table
* globals
;
3461 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
3463 enum arm_st_branch_type branch_type
= *actual_branch_type
;
3464 union gotplt_union
*root_plt
;
3465 struct arm_plt_info
*arm_plt
;
3467 if (branch_type
== ST_BRANCH_LONG
)
3470 globals
= elf32_arm_hash_table (info
);
3471 if (globals
== NULL
)
3474 thumb_only
= using_thumb_only (globals
);
3476 thumb2
= using_thumb2 (globals
);
3478 /* Determine where the call point is. */
3479 location
= (input_sec
->output_offset
3480 + input_sec
->output_section
->vma
3483 r_type
= ELF32_R_TYPE (rel
->r_info
);
3485 /* For TLS call relocs, it is the caller's responsibility to provide
3486 the address of the appropriate trampoline. */
3487 if (r_type
!= R_ARM_TLS_CALL
3488 && r_type
!= R_ARM_THM_TLS_CALL
3489 && elf32_arm_get_plt_info (input_bfd
, hash
, ELF32_R_SYM (rel
->r_info
),
3490 &root_plt
, &arm_plt
)
3491 && root_plt
->offset
!= (bfd_vma
) -1)
3495 if (hash
== NULL
|| hash
->is_iplt
)
3496 splt
= globals
->root
.iplt
;
3498 splt
= globals
->root
.splt
;
3503 /* Note when dealing with PLT entries: the main PLT stub is in
3504 ARM mode, so if the branch is in Thumb mode, another
3505 Thumb->ARM stub will be inserted later just before the ARM
3506 PLT stub. We don't take this extra distance into account
3507 here, because if a long branch stub is needed, we'll add a
3508 Thumb->Arm one and branch directly to the ARM PLT entry
3509 because it avoids spreading offset corrections in several
3512 destination
= (splt
->output_section
->vma
3513 + splt
->output_offset
3514 + root_plt
->offset
);
3516 branch_type
= ST_BRANCH_TO_ARM
;
3519 /* Calls to STT_GNU_IFUNC symbols should go through a PLT. */
3520 BFD_ASSERT (st_type
!= STT_GNU_IFUNC
);
3522 branch_offset
= (bfd_signed_vma
)(destination
- location
);
3524 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
3525 || r_type
== R_ARM_THM_TLS_CALL
)
3527 /* Handle cases where:
3528 - this call goes too far (different Thumb/Thumb2 max
3530 - it's a Thumb->Arm call and blx is not available, or it's a
3531 Thumb->Arm branch (not bl). A stub is needed in this case,
3532 but only if this call is not through a PLT entry. Indeed,
3533 PLT stubs handle mode switching already.
3536 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
3537 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
3539 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
3540 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
3541 || (branch_type
== ST_BRANCH_TO_ARM
3542 && (((r_type
== R_ARM_THM_CALL
3543 || r_type
== R_ARM_THM_TLS_CALL
) && !globals
->use_blx
)
3544 || (r_type
== R_ARM_THM_JUMP24
))
3547 if (branch_type
== ST_BRANCH_TO_THUMB
)
3549 /* Thumb to thumb. */
3552 stub_type
= (info
->shared
| globals
->pic_veneer
)
3554 ? ((globals
->use_blx
3555 && (r_type
==R_ARM_THM_CALL
))
3556 /* V5T and above. Stub starts with ARM code, so
3557 we must be able to switch mode before
3558 reaching it, which is only possible for 'bl'
3559 (ie R_ARM_THM_CALL relocation). */
3560 ? arm_stub_long_branch_any_thumb_pic
3561 /* On V4T, use Thumb code only. */
3562 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
3564 /* non-PIC stubs. */
3565 : ((globals
->use_blx
3566 && (r_type
==R_ARM_THM_CALL
))
3567 /* V5T and above. */
3568 ? arm_stub_long_branch_any_any
3570 : arm_stub_long_branch_v4t_thumb_thumb
);
3574 stub_type
= (info
->shared
| globals
->pic_veneer
)
3576 ? arm_stub_long_branch_thumb_only_pic
3578 : arm_stub_long_branch_thumb_only
;
3585 && sym_sec
->owner
!= NULL
3586 && !INTERWORK_FLAG (sym_sec
->owner
))
3588 (*_bfd_error_handler
)
3589 (_("%B(%s): warning: interworking not enabled.\n"
3590 " first occurrence: %B: Thumb call to ARM"),
3591 sym_sec
->owner
, input_bfd
, name
);
3595 (info
->shared
| globals
->pic_veneer
)
3597 ? (r_type
== R_ARM_THM_TLS_CALL
3599 ? (globals
->use_blx
? arm_stub_long_branch_any_tls_pic
3600 : arm_stub_long_branch_v4t_thumb_tls_pic
)
3601 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3602 /* V5T PIC and above. */
3603 ? arm_stub_long_branch_any_arm_pic
3605 : arm_stub_long_branch_v4t_thumb_arm_pic
))
3607 /* non-PIC stubs. */
3608 : ((globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
3609 /* V5T and above. */
3610 ? arm_stub_long_branch_any_any
3612 : arm_stub_long_branch_v4t_thumb_arm
);
3614 /* Handle v4t short branches. */
3615 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3616 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3617 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3618 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3622 else if (r_type
== R_ARM_CALL
3623 || r_type
== R_ARM_JUMP24
3624 || r_type
== R_ARM_PLT32
3625 || r_type
== R_ARM_TLS_CALL
)
3627 if (branch_type
== ST_BRANCH_TO_THUMB
)
3632 && sym_sec
->owner
!= NULL
3633 && !INTERWORK_FLAG (sym_sec
->owner
))
3635 (*_bfd_error_handler
)
3636 (_("%B(%s): warning: interworking not enabled.\n"
3637 " first occurrence: %B: ARM call to Thumb"),
3638 sym_sec
->owner
, input_bfd
, name
);
3641 /* We have an extra 2-bytes reach because of
3642 the mode change (bit 24 (H) of BLX encoding). */
3643 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3644 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3645 || (r_type
== R_ARM_CALL
&& !globals
->use_blx
)
3646 || (r_type
== R_ARM_JUMP24
)
3647 || (r_type
== R_ARM_PLT32
))
3649 stub_type
= (info
->shared
| globals
->pic_veneer
)
3651 ? ((globals
->use_blx
)
3652 /* V5T and above. */
3653 ? arm_stub_long_branch_any_thumb_pic
3655 : arm_stub_long_branch_v4t_arm_thumb_pic
)
3657 /* non-PIC stubs. */
3658 : ((globals
->use_blx
)
3659 /* V5T and above. */
3660 ? arm_stub_long_branch_any_any
3662 : arm_stub_long_branch_v4t_arm_thumb
);
3668 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3669 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3672 (info
->shared
| globals
->pic_veneer
)
3674 ? (r_type
== R_ARM_TLS_CALL
3676 ? arm_stub_long_branch_any_tls_pic
3677 : arm_stub_long_branch_any_arm_pic
)
3678 /* non-PIC stubs. */
3679 : arm_stub_long_branch_any_any
;
3684 /* If a stub is needed, record the actual destination type. */
3685 if (stub_type
!= arm_stub_none
)
3686 *actual_branch_type
= branch_type
;
3691 /* Build a name for an entry in the stub hash table. */
3694 elf32_arm_stub_name (const asection
*input_section
,
3695 const asection
*sym_sec
,
3696 const struct elf32_arm_link_hash_entry
*hash
,
3697 const Elf_Internal_Rela
*rel
,
3698 enum elf32_arm_stub_type stub_type
)
3705 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1 + 2 + 1;
3706 stub_name
= (char *) bfd_malloc (len
);
3707 if (stub_name
!= NULL
)
3708 sprintf (stub_name
, "%08x_%s+%x_%d",
3709 input_section
->id
& 0xffffffff,
3710 hash
->root
.root
.root
.string
,
3711 (int) rel
->r_addend
& 0xffffffff,
3716 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 2 + 1;
3717 stub_name
= (char *) bfd_malloc (len
);
3718 if (stub_name
!= NULL
)
3719 sprintf (stub_name
, "%08x_%x:%x+%x_%d",
3720 input_section
->id
& 0xffffffff,
3721 sym_sec
->id
& 0xffffffff,
3722 ELF32_R_TYPE (rel
->r_info
) == R_ARM_TLS_CALL
3723 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_TLS_CALL
3724 ? 0 : (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
3725 (int) rel
->r_addend
& 0xffffffff,
3732 /* Look up an entry in the stub hash. Stub entries are cached because
3733 creating the stub name takes a bit of time. */
3735 static struct elf32_arm_stub_hash_entry
*
3736 elf32_arm_get_stub_entry (const asection
*input_section
,
3737 const asection
*sym_sec
,
3738 struct elf_link_hash_entry
*hash
,
3739 const Elf_Internal_Rela
*rel
,
3740 struct elf32_arm_link_hash_table
*htab
,
3741 enum elf32_arm_stub_type stub_type
)
3743 struct elf32_arm_stub_hash_entry
*stub_entry
;
3744 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
3745 const asection
*id_sec
;
3747 if ((input_section
->flags
& SEC_CODE
) == 0)
3750 /* If this input section is part of a group of sections sharing one
3751 stub section, then use the id of the first section in the group.
3752 Stub names need to include a section id, as there may well be
3753 more than one stub used to reach say, printf, and we need to
3754 distinguish between them. */
3755 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3757 if (h
!= NULL
&& h
->stub_cache
!= NULL
3758 && h
->stub_cache
->h
== h
3759 && h
->stub_cache
->id_sec
== id_sec
3760 && h
->stub_cache
->stub_type
== stub_type
)
3762 stub_entry
= h
->stub_cache
;
3768 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
, stub_type
);
3769 if (stub_name
== NULL
)
3772 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3773 stub_name
, FALSE
, FALSE
);
3775 h
->stub_cache
= stub_entry
;
3783 /* Find or create a stub section. Returns a pointer to the stub section, and
3784 the section to which the stub section will be attached (in *LINK_SEC_P).
3785 LINK_SEC_P may be NULL. */
3788 elf32_arm_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
3789 struct elf32_arm_link_hash_table
*htab
)
3794 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3795 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3796 if (stub_sec
== NULL
)
3798 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3799 if (stub_sec
== NULL
)
3805 namelen
= strlen (link_sec
->name
);
3806 len
= namelen
+ sizeof (STUB_SUFFIX
);
3807 s_name
= (char *) bfd_alloc (htab
->stub_bfd
, len
);
3811 memcpy (s_name
, link_sec
->name
, namelen
);
3812 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3813 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3814 if (stub_sec
== NULL
)
3816 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3818 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3822 *link_sec_p
= link_sec
;
3827 /* Add a new stub entry to the stub hash. Not all fields of the new
3828 stub entry are initialised. */
3830 static struct elf32_arm_stub_hash_entry
*
3831 elf32_arm_add_stub (const char *stub_name
,
3833 struct elf32_arm_link_hash_table
*htab
)
3837 struct elf32_arm_stub_hash_entry
*stub_entry
;
3839 stub_sec
= elf32_arm_create_or_find_stub_sec (&link_sec
, section
, htab
);
3840 if (stub_sec
== NULL
)
3843 /* Enter this entry into the linker stub hash table. */
3844 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3846 if (stub_entry
== NULL
)
3848 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3854 stub_entry
->stub_sec
= stub_sec
;
3855 stub_entry
->stub_offset
= 0;
3856 stub_entry
->id_sec
= link_sec
;
3861 /* Store an Arm insn into an output section not processed by
3862 elf32_arm_write_section. */
3865 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
3866 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3868 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3869 bfd_putl32 (val
, ptr
);
3871 bfd_putb32 (val
, ptr
);
3874 /* Store a 16-bit Thumb insn into an output section not processed by
3875 elf32_arm_write_section. */
3878 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
3879 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3881 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3882 bfd_putl16 (val
, ptr
);
3884 bfd_putb16 (val
, ptr
);
3887 /* If it's possible to change R_TYPE to a more efficient access
3888 model, return the new reloc type. */
3891 elf32_arm_tls_transition (struct bfd_link_info
*info
, int r_type
,
3892 struct elf_link_hash_entry
*h
)
3894 int is_local
= (h
== NULL
);
3896 if (info
->shared
|| (h
&& h
->root
.type
== bfd_link_hash_undefweak
))
3899 /* We do not support relaxations for Old TLS models. */
3902 case R_ARM_TLS_GOTDESC
:
3903 case R_ARM_TLS_CALL
:
3904 case R_ARM_THM_TLS_CALL
:
3905 case R_ARM_TLS_DESCSEQ
:
3906 case R_ARM_THM_TLS_DESCSEQ
:
3907 return is_local
? R_ARM_TLS_LE32
: R_ARM_TLS_IE32
;
3913 static bfd_reloc_status_type elf32_arm_final_link_relocate
3914 (reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
3915 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
3916 const char *, unsigned char, enum arm_st_branch_type
,
3917 struct elf_link_hash_entry
*, bfd_boolean
*, char **);
3920 arm_stub_required_alignment (enum elf32_arm_stub_type stub_type
)
3924 case arm_stub_a8_veneer_b_cond
:
3925 case arm_stub_a8_veneer_b
:
3926 case arm_stub_a8_veneer_bl
:
3929 case arm_stub_long_branch_any_any
:
3930 case arm_stub_long_branch_v4t_arm_thumb
:
3931 case arm_stub_long_branch_thumb_only
:
3932 case arm_stub_long_branch_v4t_thumb_thumb
:
3933 case arm_stub_long_branch_v4t_thumb_arm
:
3934 case arm_stub_short_branch_v4t_thumb_arm
:
3935 case arm_stub_long_branch_any_arm_pic
:
3936 case arm_stub_long_branch_any_thumb_pic
:
3937 case arm_stub_long_branch_v4t_thumb_thumb_pic
:
3938 case arm_stub_long_branch_v4t_arm_thumb_pic
:
3939 case arm_stub_long_branch_v4t_thumb_arm_pic
:
3940 case arm_stub_long_branch_thumb_only_pic
:
3941 case arm_stub_long_branch_any_tls_pic
:
3942 case arm_stub_long_branch_v4t_thumb_tls_pic
:
3943 case arm_stub_a8_veneer_blx
:
3947 abort (); /* Should be unreachable. */
3952 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3956 struct elf32_arm_stub_hash_entry
*stub_entry
;
3957 struct elf32_arm_link_hash_table
*globals
;
3958 struct bfd_link_info
*info
;
3965 const insn_sequence
*template_sequence
;
3967 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
3968 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
3971 /* Massage our args to the form they really have. */
3972 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3973 info
= (struct bfd_link_info
*) in_arg
;
3975 globals
= elf32_arm_hash_table (info
);
3976 if (globals
== NULL
)
3979 stub_sec
= stub_entry
->stub_sec
;
3981 if ((globals
->fix_cortex_a8
< 0)
3982 != (arm_stub_required_alignment (stub_entry
->stub_type
) == 2))
3983 /* We have to do less-strictly-aligned fixes last. */
3986 /* Make a note of the offset within the stubs for this entry. */
3987 stub_entry
->stub_offset
= stub_sec
->size
;
3988 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3990 stub_bfd
= stub_sec
->owner
;
3992 /* This is the address of the stub destination. */
3993 sym_value
= (stub_entry
->target_value
3994 + stub_entry
->target_section
->output_offset
3995 + stub_entry
->target_section
->output_section
->vma
);
3997 template_sequence
= stub_entry
->stub_template
;
3998 template_size
= stub_entry
->stub_template_size
;
4001 for (i
= 0; i
< template_size
; i
++)
4003 switch (template_sequence
[i
].type
)
4007 bfd_vma data
= (bfd_vma
) template_sequence
[i
].data
;
4008 if (template_sequence
[i
].reloc_addend
!= 0)
4010 /* We've borrowed the reloc_addend field to mean we should
4011 insert a condition code into this (Thumb-1 branch)
4012 instruction. See THUMB16_BCOND_INSN. */
4013 BFD_ASSERT ((data
& 0xff00) == 0xd000);
4014 data
|= ((stub_entry
->orig_insn
>> 22) & 0xf) << 8;
4016 bfd_put_16 (stub_bfd
, data
, loc
+ size
);
4022 bfd_put_16 (stub_bfd
,
4023 (template_sequence
[i
].data
>> 16) & 0xffff,
4025 bfd_put_16 (stub_bfd
, template_sequence
[i
].data
& 0xffff,
4027 if (template_sequence
[i
].r_type
!= R_ARM_NONE
)
4029 stub_reloc_idx
[nrelocs
] = i
;
4030 stub_reloc_offset
[nrelocs
++] = size
;
4036 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
,
4038 /* Handle cases where the target is encoded within the
4040 if (template_sequence
[i
].r_type
== R_ARM_JUMP24
)
4042 stub_reloc_idx
[nrelocs
] = i
;
4043 stub_reloc_offset
[nrelocs
++] = size
;
4049 bfd_put_32 (stub_bfd
, template_sequence
[i
].data
, loc
+ size
);
4050 stub_reloc_idx
[nrelocs
] = i
;
4051 stub_reloc_offset
[nrelocs
++] = size
;
4061 stub_sec
->size
+= size
;
4063 /* Stub size has already been computed in arm_size_one_stub. Check
4065 BFD_ASSERT (size
== stub_entry
->stub_size
);
4067 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
4068 if (stub_entry
->branch_type
== ST_BRANCH_TO_THUMB
)
4071 /* Assume there is at least one and at most MAXRELOCS entries to relocate
4073 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
4075 for (i
= 0; i
< nrelocs
; i
++)
4076 if (template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP24
4077 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP19
4078 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_CALL
4079 || template_sequence
[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_XPC22
)
4081 Elf_Internal_Rela rel
;
4082 bfd_boolean unresolved_reloc
;
4083 char *error_message
;
4084 enum arm_st_branch_type branch_type
4085 = (template_sequence
[stub_reloc_idx
[i
]].r_type
!= R_ARM_THM_XPC22
4086 ? ST_BRANCH_TO_THUMB
: ST_BRANCH_TO_ARM
);
4087 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
;
4089 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4090 rel
.r_info
= ELF32_R_INFO (0,
4091 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4092 rel
.r_addend
= template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4094 if (stub_entry
->stub_type
== arm_stub_a8_veneer_b_cond
&& i
== 0)
4095 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
4096 template should refer back to the instruction after the original
4098 points_to
= sym_value
;
4100 /* There may be unintended consequences if this is not true. */
4101 BFD_ASSERT (stub_entry
->h
== NULL
);
4103 /* Note: _bfd_final_link_relocate doesn't handle these relocations
4104 properly. We should probably use this function unconditionally,
4105 rather than only for certain relocations listed in the enclosing
4106 conditional, for the sake of consistency. */
4107 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4108 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4109 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4110 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4111 branch_type
, (struct elf_link_hash_entry
*) stub_entry
->h
,
4112 &unresolved_reloc
, &error_message
);
4116 Elf_Internal_Rela rel
;
4117 bfd_boolean unresolved_reloc
;
4118 char *error_message
;
4119 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
4120 + template_sequence
[stub_reloc_idx
[i
]].reloc_addend
;
4122 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
4123 rel
.r_info
= ELF32_R_INFO (0,
4124 template_sequence
[stub_reloc_idx
[i
]].r_type
);
4127 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
4128 (template_sequence
[stub_reloc_idx
[i
]].r_type
),
4129 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
4130 points_to
, info
, stub_entry
->target_section
, "", STT_FUNC
,
4131 stub_entry
->branch_type
,
4132 (struct elf_link_hash_entry
*) stub_entry
->h
, &unresolved_reloc
,
4140 /* Calculate the template, template size and instruction size for a stub.
4141 Return value is the instruction size. */
4144 find_stub_size_and_template (enum elf32_arm_stub_type stub_type
,
4145 const insn_sequence
**stub_template
,
4146 int *stub_template_size
)
4148 const insn_sequence
*template_sequence
= NULL
;
4149 int template_size
= 0, i
;
4152 template_sequence
= stub_definitions
[stub_type
].template_sequence
;
4154 *stub_template
= template_sequence
;
4156 template_size
= stub_definitions
[stub_type
].template_size
;
4157 if (stub_template_size
)
4158 *stub_template_size
= template_size
;
4161 for (i
= 0; i
< template_size
; i
++)
4163 switch (template_sequence
[i
].type
)
4184 /* As above, but don't actually build the stub. Just bump offset so
4185 we know stub section sizes. */
4188 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
4189 void *in_arg ATTRIBUTE_UNUSED
)
4191 struct elf32_arm_stub_hash_entry
*stub_entry
;
4192 const insn_sequence
*template_sequence
;
4193 int template_size
, size
;
4195 /* Massage our args to the form they really have. */
4196 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
4198 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
4199 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
4201 size
= find_stub_size_and_template (stub_entry
->stub_type
, &template_sequence
,
4204 stub_entry
->stub_size
= size
;
4205 stub_entry
->stub_template
= template_sequence
;
4206 stub_entry
->stub_template_size
= template_size
;
4208 size
= (size
+ 7) & ~7;
4209 stub_entry
->stub_sec
->size
+= size
;
4214 /* External entry points for sizing and building linker stubs. */
4216 /* Set up various things so that we can make a list of input sections
4217 for each output section included in the link. Returns -1 on error,
4218 0 when no stubs will be needed, and 1 on success. */
4221 elf32_arm_setup_section_lists (bfd
*output_bfd
,
4222 struct bfd_link_info
*info
)
4225 unsigned int bfd_count
;
4226 int top_id
, top_index
;
4228 asection
**input_list
, **list
;
4230 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4234 if (! is_elf_hash_table (htab
))
4237 /* Count the number of input BFDs and find the top input section id. */
4238 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
4240 input_bfd
= input_bfd
->link_next
)
4243 for (section
= input_bfd
->sections
;
4245 section
= section
->next
)
4247 if (top_id
< section
->id
)
4248 top_id
= section
->id
;
4251 htab
->bfd_count
= bfd_count
;
4253 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4254 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4255 if (htab
->stub_group
== NULL
)
4257 htab
->top_id
= top_id
;
4259 /* We can't use output_bfd->section_count here to find the top output
4260 section index as some sections may have been removed, and
4261 _bfd_strip_section_from_output doesn't renumber the indices. */
4262 for (section
= output_bfd
->sections
, top_index
= 0;
4264 section
= section
->next
)
4266 if (top_index
< section
->index
)
4267 top_index
= section
->index
;
4270 htab
->top_index
= top_index
;
4271 amt
= sizeof (asection
*) * (top_index
+ 1);
4272 input_list
= (asection
**) bfd_malloc (amt
);
4273 htab
->input_list
= input_list
;
4274 if (input_list
== NULL
)
4277 /* For sections we aren't interested in, mark their entries with a
4278 value we can check later. */
4279 list
= input_list
+ top_index
;
4281 *list
= bfd_abs_section_ptr
;
4282 while (list
-- != input_list
);
4284 for (section
= output_bfd
->sections
;
4286 section
= section
->next
)
4288 if ((section
->flags
& SEC_CODE
) != 0)
4289 input_list
[section
->index
] = NULL
;
4295 /* The linker repeatedly calls this function for each input section,
4296 in the order that input sections are linked into output sections.
4297 Build lists of input sections to determine groupings between which
4298 we may insert linker stubs. */
4301 elf32_arm_next_input_section (struct bfd_link_info
*info
,
4304 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4309 if (isec
->output_section
->index
<= htab
->top_index
)
4311 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4313 if (*list
!= bfd_abs_section_ptr
&& (isec
->flags
& SEC_CODE
) != 0)
4315 /* Steal the link_sec pointer for our list. */
4316 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4317 /* This happens to make the list in reverse order,
4318 which we reverse later. */
4319 PREV_SEC (isec
) = *list
;
4325 /* See whether we can group stub sections together. Grouping stub
4326 sections may result in fewer stubs. More importantly, we need to
4327 put all .init* and .fini* stubs at the end of the .init or
4328 .fini output sections respectively, because glibc splits the
4329 _init and _fini functions into multiple parts. Putting a stub in
4330 the middle of a function is not a good idea. */
4333 group_sections (struct elf32_arm_link_hash_table
*htab
,
4334 bfd_size_type stub_group_size
,
4335 bfd_boolean stubs_always_after_branch
)
4337 asection
**list
= htab
->input_list
;
4341 asection
*tail
= *list
;
4344 if (tail
== bfd_abs_section_ptr
)
4347 /* Reverse the list: we must avoid placing stubs at the
4348 beginning of the section because the beginning of the text
4349 section may be required for an interrupt vector in bare metal
4351 #define NEXT_SEC PREV_SEC
4353 while (tail
!= NULL
)
4355 /* Pop from tail. */
4356 asection
*item
= tail
;
4357 tail
= PREV_SEC (item
);
4360 NEXT_SEC (item
) = head
;
4364 while (head
!= NULL
)
4368 bfd_vma stub_group_start
= head
->output_offset
;
4369 bfd_vma end_of_next
;
4372 while (NEXT_SEC (curr
) != NULL
)
4374 next
= NEXT_SEC (curr
);
4375 end_of_next
= next
->output_offset
+ next
->size
;
4376 if (end_of_next
- stub_group_start
>= stub_group_size
)
4377 /* End of NEXT is too far from start, so stop. */
4379 /* Add NEXT to the group. */
4383 /* OK, the size from the start to the start of CURR is less
4384 than stub_group_size and thus can be handled by one stub
4385 section. (Or the head section is itself larger than
4386 stub_group_size, in which case we may be toast.)
4387 We should really be keeping track of the total size of
4388 stubs added here, as stubs contribute to the final output
4392 next
= NEXT_SEC (head
);
4393 /* Set up this stub group. */
4394 htab
->stub_group
[head
->id
].link_sec
= curr
;
4396 while (head
!= curr
&& (head
= next
) != NULL
);
4398 /* But wait, there's more! Input sections up to stub_group_size
4399 bytes after the stub section can be handled by it too. */
4400 if (!stubs_always_after_branch
)
4402 stub_group_start
= curr
->output_offset
+ curr
->size
;
4404 while (next
!= NULL
)
4406 end_of_next
= next
->output_offset
+ next
->size
;
4407 if (end_of_next
- stub_group_start
>= stub_group_size
)
4408 /* End of NEXT is too far from stubs, so stop. */
4410 /* Add NEXT to the stub group. */
4412 next
= NEXT_SEC (head
);
4413 htab
->stub_group
[head
->id
].link_sec
= curr
;
4419 while (list
++ != htab
->input_list
+ htab
->top_index
);
4421 free (htab
->input_list
);
4426 /* Comparison function for sorting/searching relocations relating to Cortex-A8
4430 a8_reloc_compare (const void *a
, const void *b
)
4432 const struct a8_erratum_reloc
*ra
= (const struct a8_erratum_reloc
*) a
;
4433 const struct a8_erratum_reloc
*rb
= (const struct a8_erratum_reloc
*) b
;
4435 if (ra
->from
< rb
->from
)
4437 else if (ra
->from
> rb
->from
)
4443 static struct elf_link_hash_entry
*find_thumb_glue (struct bfd_link_info
*,
4444 const char *, char **);
4446 /* Helper function to scan code for sequences which might trigger the Cortex-A8
4447 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
4448 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
4452 cortex_a8_erratum_scan (bfd
*input_bfd
,
4453 struct bfd_link_info
*info
,
4454 struct a8_erratum_fix
**a8_fixes_p
,
4455 unsigned int *num_a8_fixes_p
,
4456 unsigned int *a8_fix_table_size_p
,
4457 struct a8_erratum_reloc
*a8_relocs
,
4458 unsigned int num_a8_relocs
,
4459 unsigned prev_num_a8_fixes
,
4460 bfd_boolean
*stub_changed_p
)
4463 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4464 struct a8_erratum_fix
*a8_fixes
= *a8_fixes_p
;
4465 unsigned int num_a8_fixes
= *num_a8_fixes_p
;
4466 unsigned int a8_fix_table_size
= *a8_fix_table_size_p
;
4471 for (section
= input_bfd
->sections
;
4473 section
= section
->next
)
4475 bfd_byte
*contents
= NULL
;
4476 struct _arm_elf_section_data
*sec_data
;
4480 if (elf_section_type (section
) != SHT_PROGBITS
4481 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
4482 || (section
->flags
& SEC_EXCLUDE
) != 0
4483 || (section
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
4484 || (section
->output_section
== bfd_abs_section_ptr
))
4487 base_vma
= section
->output_section
->vma
+ section
->output_offset
;
4489 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
4490 contents
= elf_section_data (section
)->this_hdr
.contents
;
4491 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
4494 sec_data
= elf32_arm_section_data (section
);
4496 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4498 unsigned int span_start
= sec_data
->map
[span
].vma
;
4499 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
4500 ? section
->size
: sec_data
->map
[span
+ 1].vma
;
4502 char span_type
= sec_data
->map
[span
].type
;
4503 bfd_boolean last_was_32bit
= FALSE
, last_was_branch
= FALSE
;
4505 if (span_type
!= 't')
4508 /* Span is entirely within a single 4KB region: skip scanning. */
4509 if (((base_vma
+ span_start
) & ~0xfff)
4510 == ((base_vma
+ span_end
) & ~0xfff))
4513 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
4515 * The opcode is BLX.W, BL.W, B.W, Bcc.W
4516 * The branch target is in the same 4KB region as the
4517 first half of the branch.
4518 * The instruction before the branch is a 32-bit
4519 length non-branch instruction. */
4520 for (i
= span_start
; i
< span_end
;)
4522 unsigned int insn
= bfd_getl16 (&contents
[i
]);
4523 bfd_boolean insn_32bit
= FALSE
, is_blx
= FALSE
, is_b
= FALSE
;
4524 bfd_boolean is_bl
= FALSE
, is_bcc
= FALSE
, is_32bit_branch
;
4526 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
4531 /* Load the rest of the insn (in manual-friendly order). */
4532 insn
= (insn
<< 16) | bfd_getl16 (&contents
[i
+ 2]);
4534 /* Encoding T4: B<c>.W. */
4535 is_b
= (insn
& 0xf800d000) == 0xf0009000;
4536 /* Encoding T1: BL<c>.W. */
4537 is_bl
= (insn
& 0xf800d000) == 0xf000d000;
4538 /* Encoding T2: BLX<c>.W. */
4539 is_blx
= (insn
& 0xf800d000) == 0xf000c000;
4540 /* Encoding T3: B<c>.W (not permitted in IT block). */
4541 is_bcc
= (insn
& 0xf800d000) == 0xf0008000
4542 && (insn
& 0x07f00000) != 0x03800000;
4545 is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
4547 if (((base_vma
+ i
) & 0xfff) == 0xffe
4551 && ! last_was_branch
)
4553 bfd_signed_vma offset
= 0;
4554 bfd_boolean force_target_arm
= FALSE
;
4555 bfd_boolean force_target_thumb
= FALSE
;
4557 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
4558 struct a8_erratum_reloc key
, *found
;
4559 bfd_boolean use_plt
= FALSE
;
4561 key
.from
= base_vma
+ i
;
4562 found
= (struct a8_erratum_reloc
*)
4563 bsearch (&key
, a8_relocs
, num_a8_relocs
,
4564 sizeof (struct a8_erratum_reloc
),
4569 char *error_message
= NULL
;
4570 struct elf_link_hash_entry
*entry
;
4572 /* We don't care about the error returned from this
4573 function, only if there is glue or not. */
4574 entry
= find_thumb_glue (info
, found
->sym_name
,
4578 found
->non_a8_stub
= TRUE
;
4580 /* Keep a simpler condition, for the sake of clarity. */
4581 if (htab
->root
.splt
!= NULL
&& found
->hash
!= NULL
4582 && found
->hash
->root
.plt
.offset
!= (bfd_vma
) -1)
4585 if (found
->r_type
== R_ARM_THM_CALL
)
4587 if (found
->branch_type
== ST_BRANCH_TO_ARM
4589 force_target_arm
= TRUE
;
4591 force_target_thumb
= TRUE
;
4595 /* Check if we have an offending branch instruction. */
4597 if (found
&& found
->non_a8_stub
)
4598 /* We've already made a stub for this instruction, e.g.
4599 it's a long branch or a Thumb->ARM stub. Assume that
4600 stub will suffice to work around the A8 erratum (see
4601 setting of always_after_branch above). */
4605 offset
= (insn
& 0x7ff) << 1;
4606 offset
|= (insn
& 0x3f0000) >> 4;
4607 offset
|= (insn
& 0x2000) ? 0x40000 : 0;
4608 offset
|= (insn
& 0x800) ? 0x80000 : 0;
4609 offset
|= (insn
& 0x4000000) ? 0x100000 : 0;
4610 if (offset
& 0x100000)
4611 offset
|= ~ ((bfd_signed_vma
) 0xfffff);
4612 stub_type
= arm_stub_a8_veneer_b_cond
;
4614 else if (is_b
|| is_bl
|| is_blx
)
4616 int s
= (insn
& 0x4000000) != 0;
4617 int j1
= (insn
& 0x2000) != 0;
4618 int j2
= (insn
& 0x800) != 0;
4622 offset
= (insn
& 0x7ff) << 1;
4623 offset
|= (insn
& 0x3ff0000) >> 4;
4627 if (offset
& 0x1000000)
4628 offset
|= ~ ((bfd_signed_vma
) 0xffffff);
4631 offset
&= ~ ((bfd_signed_vma
) 3);
4633 stub_type
= is_blx
? arm_stub_a8_veneer_blx
:
4634 is_bl
? arm_stub_a8_veneer_bl
: arm_stub_a8_veneer_b
;
4637 if (stub_type
!= arm_stub_none
)
4639 bfd_vma pc_for_insn
= base_vma
+ i
+ 4;
4641 /* The original instruction is a BL, but the target is
4642 an ARM instruction. If we were not making a stub,
4643 the BL would have been converted to a BLX. Use the
4644 BLX stub instead in that case. */
4645 if (htab
->use_blx
&& force_target_arm
4646 && stub_type
== arm_stub_a8_veneer_bl
)
4648 stub_type
= arm_stub_a8_veneer_blx
;
4652 /* Conversely, if the original instruction was
4653 BLX but the target is Thumb mode, use the BL
4655 else if (force_target_thumb
4656 && stub_type
== arm_stub_a8_veneer_blx
)
4658 stub_type
= arm_stub_a8_veneer_bl
;
4664 pc_for_insn
&= ~ ((bfd_vma
) 3);
4666 /* If we found a relocation, use the proper destination,
4667 not the offset in the (unrelocated) instruction.
4668 Note this is always done if we switched the stub type
4672 (bfd_signed_vma
) (found
->destination
- pc_for_insn
);
4674 /* If the stub will use a Thumb-mode branch to a
4675 PLT target, redirect it to the preceding Thumb
4677 if (stub_type
!= arm_stub_a8_veneer_blx
&& use_plt
)
4678 offset
-= PLT_THUMB_STUB_SIZE
;
4680 target
= pc_for_insn
+ offset
;
4682 /* The BLX stub is ARM-mode code. Adjust the offset to
4683 take the different PC value (+8 instead of +4) into
4685 if (stub_type
== arm_stub_a8_veneer_blx
)
4688 if (((base_vma
+ i
) & ~0xfff) == (target
& ~0xfff))
4690 char *stub_name
= NULL
;
4692 if (num_a8_fixes
== a8_fix_table_size
)
4694 a8_fix_table_size
*= 2;
4695 a8_fixes
= (struct a8_erratum_fix
*)
4696 bfd_realloc (a8_fixes
,
4697 sizeof (struct a8_erratum_fix
)
4698 * a8_fix_table_size
);
4701 if (num_a8_fixes
< prev_num_a8_fixes
)
4703 /* If we're doing a subsequent scan,
4704 check if we've found the same fix as
4705 before, and try and reuse the stub
4707 stub_name
= a8_fixes
[num_a8_fixes
].stub_name
;
4708 if ((a8_fixes
[num_a8_fixes
].section
!= section
)
4709 || (a8_fixes
[num_a8_fixes
].offset
!= i
))
4713 *stub_changed_p
= TRUE
;
4719 stub_name
= (char *) bfd_malloc (8 + 1 + 8 + 1);
4720 if (stub_name
!= NULL
)
4721 sprintf (stub_name
, "%x:%x", section
->id
, i
);
4724 a8_fixes
[num_a8_fixes
].input_bfd
= input_bfd
;
4725 a8_fixes
[num_a8_fixes
].section
= section
;
4726 a8_fixes
[num_a8_fixes
].offset
= i
;
4727 a8_fixes
[num_a8_fixes
].addend
= offset
;
4728 a8_fixes
[num_a8_fixes
].orig_insn
= insn
;
4729 a8_fixes
[num_a8_fixes
].stub_name
= stub_name
;
4730 a8_fixes
[num_a8_fixes
].stub_type
= stub_type
;
4731 a8_fixes
[num_a8_fixes
].branch_type
=
4732 is_blx
? ST_BRANCH_TO_ARM
: ST_BRANCH_TO_THUMB
;
4739 i
+= insn_32bit
? 4 : 2;
4740 last_was_32bit
= insn_32bit
;
4741 last_was_branch
= is_32bit_branch
;
4745 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4749 *a8_fixes_p
= a8_fixes
;
4750 *num_a8_fixes_p
= num_a8_fixes
;
4751 *a8_fix_table_size_p
= a8_fix_table_size
;
4756 /* Determine and set the size of the stub section for a final link.
4758 The basic idea here is to examine all the relocations looking for
4759 PC-relative calls to a target that is unreachable with a "bl"
4763 elf32_arm_size_stubs (bfd
*output_bfd
,
4765 struct bfd_link_info
*info
,
4766 bfd_signed_vma group_size
,
4767 asection
* (*add_stub_section
) (const char *, asection
*),
4768 void (*layout_sections_again
) (void))
4770 bfd_size_type stub_group_size
;
4771 bfd_boolean stubs_always_after_branch
;
4772 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4773 struct a8_erratum_fix
*a8_fixes
= NULL
;
4774 unsigned int num_a8_fixes
= 0, a8_fix_table_size
= 10;
4775 struct a8_erratum_reloc
*a8_relocs
= NULL
;
4776 unsigned int num_a8_relocs
= 0, a8_reloc_table_size
= 10, i
;
4781 if (htab
->fix_cortex_a8
)
4783 a8_fixes
= (struct a8_erratum_fix
*)
4784 bfd_zmalloc (sizeof (struct a8_erratum_fix
) * a8_fix_table_size
);
4785 a8_relocs
= (struct a8_erratum_reloc
*)
4786 bfd_zmalloc (sizeof (struct a8_erratum_reloc
) * a8_reloc_table_size
);
4789 /* Propagate mach to stub bfd, because it may not have been
4790 finalized when we created stub_bfd. */
4791 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4792 bfd_get_mach (output_bfd
));
4794 /* Stash our params away. */
4795 htab
->stub_bfd
= stub_bfd
;
4796 htab
->add_stub_section
= add_stub_section
;
4797 htab
->layout_sections_again
= layout_sections_again
;
4798 stubs_always_after_branch
= group_size
< 0;
4800 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
4801 as the first half of a 32-bit branch straddling two 4K pages. This is a
4802 crude way of enforcing that. */
4803 if (htab
->fix_cortex_a8
)
4804 stubs_always_after_branch
= 1;
4807 stub_group_size
= -group_size
;
4809 stub_group_size
= group_size
;
4811 if (stub_group_size
== 1)
4813 /* Default values. */
4814 /* Thumb branch range is +-4MB has to be used as the default
4815 maximum size (a given section can contain both ARM and Thumb
4816 code, so the worst case has to be taken into account).
4818 This value is 24K less than that, which allows for 2025
4819 12-byte stubs. If we exceed that, then we will fail to link.
4820 The user will have to relink with an explicit group size
4822 stub_group_size
= 4170000;
4825 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
4827 /* If we're applying the cortex A8 fix, we need to determine the
4828 program header size now, because we cannot change it later --
4829 that could alter section placements. Notice the A8 erratum fix
4830 ends up requiring the section addresses to remain unchanged
4831 modulo the page size. That's something we cannot represent
4832 inside BFD, and we don't want to force the section alignment to
4833 be the page size. */
4834 if (htab
->fix_cortex_a8
)
4835 (*htab
->layout_sections_again
) ();
4840 unsigned int bfd_indx
;
4842 bfd_boolean stub_changed
= FALSE
;
4843 unsigned prev_num_a8_fixes
= num_a8_fixes
;
4846 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4848 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4850 Elf_Internal_Shdr
*symtab_hdr
;
4852 Elf_Internal_Sym
*local_syms
= NULL
;
4856 /* We'll need the symbol table in a second. */
4857 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4858 if (symtab_hdr
->sh_info
== 0)
4861 /* Walk over each section attached to the input bfd. */
4862 for (section
= input_bfd
->sections
;
4864 section
= section
->next
)
4866 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4868 /* If there aren't any relocs, then there's nothing more
4870 if ((section
->flags
& SEC_RELOC
) == 0
4871 || section
->reloc_count
== 0
4872 || (section
->flags
& SEC_CODE
) == 0)
4875 /* If this section is a link-once section that will be
4876 discarded, then don't create any stubs. */
4877 if (section
->output_section
== NULL
4878 || section
->output_section
->owner
!= output_bfd
)
4881 /* Get the relocs. */
4883 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
4884 NULL
, info
->keep_memory
);
4885 if (internal_relocs
== NULL
)
4886 goto error_ret_free_local
;
4888 /* Now examine each relocation. */
4889 irela
= internal_relocs
;
4890 irelaend
= irela
+ section
->reloc_count
;
4891 for (; irela
< irelaend
; irela
++)
4893 unsigned int r_type
, r_indx
;
4894 enum elf32_arm_stub_type stub_type
;
4895 struct elf32_arm_stub_hash_entry
*stub_entry
;
4898 bfd_vma destination
;
4899 struct elf32_arm_link_hash_entry
*hash
;
4900 const char *sym_name
;
4902 const asection
*id_sec
;
4903 unsigned char st_type
;
4904 enum arm_st_branch_type branch_type
;
4905 bfd_boolean created_stub
= FALSE
;
4907 r_type
= ELF32_R_TYPE (irela
->r_info
);
4908 r_indx
= ELF32_R_SYM (irela
->r_info
);
4910 if (r_type
>= (unsigned int) R_ARM_max
)
4912 bfd_set_error (bfd_error_bad_value
);
4913 error_ret_free_internal
:
4914 if (elf_section_data (section
)->relocs
== NULL
)
4915 free (internal_relocs
);
4916 goto error_ret_free_local
;
4920 if (r_indx
>= symtab_hdr
->sh_info
)
4921 hash
= elf32_arm_hash_entry
4922 (elf_sym_hashes (input_bfd
)
4923 [r_indx
- symtab_hdr
->sh_info
]);
4925 /* Only look for stubs on branch instructions, or
4926 non-relaxed TLSCALL */
4927 if ((r_type
!= (unsigned int) R_ARM_CALL
)
4928 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
4929 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
4930 && (r_type
!= (unsigned int) R_ARM_THM_JUMP19
)
4931 && (r_type
!= (unsigned int) R_ARM_THM_XPC22
)
4932 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
4933 && (r_type
!= (unsigned int) R_ARM_PLT32
)
4934 && !((r_type
== (unsigned int) R_ARM_TLS_CALL
4935 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
4936 && r_type
== elf32_arm_tls_transition
4937 (info
, r_type
, &hash
->root
)
4938 && ((hash
? hash
->tls_type
4939 : (elf32_arm_local_got_tls_type
4940 (input_bfd
)[r_indx
]))
4941 & GOT_TLS_GDESC
) != 0))
4944 /* Now determine the call target, its name, value,
4951 if (r_type
== (unsigned int) R_ARM_TLS_CALL
4952 || r_type
== (unsigned int) R_ARM_THM_TLS_CALL
)
4954 /* A non-relaxed TLS call. The target is the
4955 plt-resident trampoline and nothing to do
4957 BFD_ASSERT (htab
->tls_trampoline
> 0);
4958 sym_sec
= htab
->root
.splt
;
4959 sym_value
= htab
->tls_trampoline
;
4962 branch_type
= ST_BRANCH_TO_ARM
;
4966 /* It's a local symbol. */
4967 Elf_Internal_Sym
*sym
;
4969 if (local_syms
== NULL
)
4972 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4973 if (local_syms
== NULL
)
4975 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4976 symtab_hdr
->sh_info
, 0,
4978 if (local_syms
== NULL
)
4979 goto error_ret_free_internal
;
4982 sym
= local_syms
+ r_indx
;
4983 if (sym
->st_shndx
== SHN_UNDEF
)
4984 sym_sec
= bfd_und_section_ptr
;
4985 else if (sym
->st_shndx
== SHN_ABS
)
4986 sym_sec
= bfd_abs_section_ptr
;
4987 else if (sym
->st_shndx
== SHN_COMMON
)
4988 sym_sec
= bfd_com_section_ptr
;
4991 bfd_section_from_elf_index (input_bfd
, sym
->st_shndx
);
4994 /* This is an undefined symbol. It can never
4998 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4999 sym_value
= sym
->st_value
;
5000 destination
= (sym_value
+ irela
->r_addend
5001 + sym_sec
->output_offset
5002 + sym_sec
->output_section
->vma
);
5003 st_type
= ELF_ST_TYPE (sym
->st_info
);
5004 branch_type
= ARM_SYM_BRANCH_TYPE (sym
);
5006 = bfd_elf_string_from_elf_section (input_bfd
,
5007 symtab_hdr
->sh_link
,
5012 /* It's an external symbol. */
5013 while (hash
->root
.root
.type
== bfd_link_hash_indirect
5014 || hash
->root
.root
.type
== bfd_link_hash_warning
)
5015 hash
= ((struct elf32_arm_link_hash_entry
*)
5016 hash
->root
.root
.u
.i
.link
);
5018 if (hash
->root
.root
.type
== bfd_link_hash_defined
5019 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
5021 sym_sec
= hash
->root
.root
.u
.def
.section
;
5022 sym_value
= hash
->root
.root
.u
.def
.value
;
5024 struct elf32_arm_link_hash_table
*globals
=
5025 elf32_arm_hash_table (info
);
5027 /* For a destination in a shared library,
5028 use the PLT stub as target address to
5029 decide whether a branch stub is
5032 && globals
->root
.splt
!= NULL
5034 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5036 sym_sec
= globals
->root
.splt
;
5037 sym_value
= hash
->root
.plt
.offset
;
5038 if (sym_sec
->output_section
!= NULL
)
5039 destination
= (sym_value
5040 + sym_sec
->output_offset
5041 + sym_sec
->output_section
->vma
);
5043 else if (sym_sec
->output_section
!= NULL
)
5044 destination
= (sym_value
+ irela
->r_addend
5045 + sym_sec
->output_offset
5046 + sym_sec
->output_section
->vma
);
5048 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
5049 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
5051 /* For a shared library, use the PLT stub as
5052 target address to decide whether a long
5053 branch stub is needed.
5054 For absolute code, they cannot be handled. */
5055 struct elf32_arm_link_hash_table
*globals
=
5056 elf32_arm_hash_table (info
);
5059 && globals
->root
.splt
!= NULL
5061 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
5063 sym_sec
= globals
->root
.splt
;
5064 sym_value
= hash
->root
.plt
.offset
;
5065 if (sym_sec
->output_section
!= NULL
)
5066 destination
= (sym_value
5067 + sym_sec
->output_offset
5068 + sym_sec
->output_section
->vma
);
5075 bfd_set_error (bfd_error_bad_value
);
5076 goto error_ret_free_internal
;
5078 st_type
= hash
->root
.type
;
5079 branch_type
= hash
->root
.target_internal
;
5080 sym_name
= hash
->root
.root
.root
.string
;
5085 /* Determine what (if any) linker stub is needed. */
5086 stub_type
= arm_type_of_stub (info
, section
, irela
,
5087 st_type
, &branch_type
,
5088 hash
, destination
, sym_sec
,
5089 input_bfd
, sym_name
);
5090 if (stub_type
== arm_stub_none
)
5093 /* Support for grouping stub sections. */
5094 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5096 /* Get the name of this stub. */
5097 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
,
5100 goto error_ret_free_internal
;
5102 /* We've either created a stub for this reloc already,
5103 or we are about to. */
5104 created_stub
= TRUE
;
5106 stub_entry
= arm_stub_hash_lookup
5107 (&htab
->stub_hash_table
, stub_name
,
5109 if (stub_entry
!= NULL
)
5111 /* The proper stub has already been created. */
5113 stub_entry
->target_value
= sym_value
;
5117 stub_entry
= elf32_arm_add_stub (stub_name
, section
,
5119 if (stub_entry
== NULL
)
5122 goto error_ret_free_internal
;
5125 stub_entry
->target_value
= sym_value
;
5126 stub_entry
->target_section
= sym_sec
;
5127 stub_entry
->stub_type
= stub_type
;
5128 stub_entry
->h
= hash
;
5129 stub_entry
->branch_type
= branch_type
;
5131 if (sym_name
== NULL
)
5132 sym_name
= "unnamed";
5133 stub_entry
->output_name
= (char *)
5134 bfd_alloc (htab
->stub_bfd
,
5135 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
5136 + strlen (sym_name
));
5137 if (stub_entry
->output_name
== NULL
)
5140 goto error_ret_free_internal
;
5143 /* For historical reasons, use the existing names for
5144 ARM-to-Thumb and Thumb-to-ARM stubs. */
5145 if ((r_type
== (unsigned int) R_ARM_THM_CALL
5146 || r_type
== (unsigned int) R_ARM_THM_JUMP24
)
5147 && branch_type
== ST_BRANCH_TO_ARM
)
5148 sprintf (stub_entry
->output_name
,
5149 THUMB2ARM_GLUE_ENTRY_NAME
, sym_name
);
5150 else if ((r_type
== (unsigned int) R_ARM_CALL
5151 || r_type
== (unsigned int) R_ARM_JUMP24
)
5152 && branch_type
== ST_BRANCH_TO_THUMB
)
5153 sprintf (stub_entry
->output_name
,
5154 ARM2THUMB_GLUE_ENTRY_NAME
, sym_name
);
5156 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
5159 stub_changed
= TRUE
;
5163 /* Look for relocations which might trigger Cortex-A8
5165 if (htab
->fix_cortex_a8
5166 && (r_type
== (unsigned int) R_ARM_THM_JUMP24
5167 || r_type
== (unsigned int) R_ARM_THM_JUMP19
5168 || r_type
== (unsigned int) R_ARM_THM_CALL
5169 || r_type
== (unsigned int) R_ARM_THM_XPC22
))
5171 bfd_vma from
= section
->output_section
->vma
5172 + section
->output_offset
5175 if ((from
& 0xfff) == 0xffe)
5177 /* Found a candidate. Note we haven't checked the
5178 destination is within 4K here: if we do so (and
5179 don't create an entry in a8_relocs) we can't tell
5180 that a branch should have been relocated when
5182 if (num_a8_relocs
== a8_reloc_table_size
)
5184 a8_reloc_table_size
*= 2;
5185 a8_relocs
= (struct a8_erratum_reloc
*)
5186 bfd_realloc (a8_relocs
,
5187 sizeof (struct a8_erratum_reloc
)
5188 * a8_reloc_table_size
);
5191 a8_relocs
[num_a8_relocs
].from
= from
;
5192 a8_relocs
[num_a8_relocs
].destination
= destination
;
5193 a8_relocs
[num_a8_relocs
].r_type
= r_type
;
5194 a8_relocs
[num_a8_relocs
].branch_type
= branch_type
;
5195 a8_relocs
[num_a8_relocs
].sym_name
= sym_name
;
5196 a8_relocs
[num_a8_relocs
].non_a8_stub
= created_stub
;
5197 a8_relocs
[num_a8_relocs
].hash
= hash
;
5204 /* We're done with the internal relocs, free them. */
5205 if (elf_section_data (section
)->relocs
== NULL
)
5206 free (internal_relocs
);
5209 if (htab
->fix_cortex_a8
)
5211 /* Sort relocs which might apply to Cortex-A8 erratum. */
5212 qsort (a8_relocs
, num_a8_relocs
,
5213 sizeof (struct a8_erratum_reloc
),
5216 /* Scan for branches which might trigger Cortex-A8 erratum. */
5217 if (cortex_a8_erratum_scan (input_bfd
, info
, &a8_fixes
,
5218 &num_a8_fixes
, &a8_fix_table_size
,
5219 a8_relocs
, num_a8_relocs
,
5220 prev_num_a8_fixes
, &stub_changed
)
5222 goto error_ret_free_local
;
5226 if (prev_num_a8_fixes
!= num_a8_fixes
)
5227 stub_changed
= TRUE
;
5232 /* OK, we've added some stubs. Find out the new size of the
5234 for (stub_sec
= htab
->stub_bfd
->sections
;
5236 stub_sec
= stub_sec
->next
)
5238 /* Ignore non-stub sections. */
5239 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5245 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
5247 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
5248 if (htab
->fix_cortex_a8
)
5249 for (i
= 0; i
< num_a8_fixes
; i
++)
5251 stub_sec
= elf32_arm_create_or_find_stub_sec (NULL
,
5252 a8_fixes
[i
].section
, htab
);
5254 if (stub_sec
== NULL
)
5255 goto error_ret_free_local
;
5258 += find_stub_size_and_template (a8_fixes
[i
].stub_type
, NULL
,
5263 /* Ask the linker to do its stuff. */
5264 (*htab
->layout_sections_again
) ();
5267 /* Add stubs for Cortex-A8 erratum fixes now. */
5268 if (htab
->fix_cortex_a8
)
5270 for (i
= 0; i
< num_a8_fixes
; i
++)
5272 struct elf32_arm_stub_hash_entry
*stub_entry
;
5273 char *stub_name
= a8_fixes
[i
].stub_name
;
5274 asection
*section
= a8_fixes
[i
].section
;
5275 unsigned int section_id
= a8_fixes
[i
].section
->id
;
5276 asection
*link_sec
= htab
->stub_group
[section_id
].link_sec
;
5277 asection
*stub_sec
= htab
->stub_group
[section_id
].stub_sec
;
5278 const insn_sequence
*template_sequence
;
5279 int template_size
, size
= 0;
5281 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
5283 if (stub_entry
== NULL
)
5285 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
5291 stub_entry
->stub_sec
= stub_sec
;
5292 stub_entry
->stub_offset
= 0;
5293 stub_entry
->id_sec
= link_sec
;
5294 stub_entry
->stub_type
= a8_fixes
[i
].stub_type
;
5295 stub_entry
->target_section
= a8_fixes
[i
].section
;
5296 stub_entry
->target_value
= a8_fixes
[i
].offset
;
5297 stub_entry
->target_addend
= a8_fixes
[i
].addend
;
5298 stub_entry
->orig_insn
= a8_fixes
[i
].orig_insn
;
5299 stub_entry
->branch_type
= a8_fixes
[i
].branch_type
;
5301 size
= find_stub_size_and_template (a8_fixes
[i
].stub_type
,
5305 stub_entry
->stub_size
= size
;
5306 stub_entry
->stub_template
= template_sequence
;
5307 stub_entry
->stub_template_size
= template_size
;
5310 /* Stash the Cortex-A8 erratum fix array for use later in
5311 elf32_arm_write_section(). */
5312 htab
->a8_erratum_fixes
= a8_fixes
;
5313 htab
->num_a8_erratum_fixes
= num_a8_fixes
;
5317 htab
->a8_erratum_fixes
= NULL
;
5318 htab
->num_a8_erratum_fixes
= 0;
5322 error_ret_free_local
:
5326 /* Build all the stubs associated with the current output file. The
5327 stubs are kept in a hash table attached to the main linker hash
5328 table. We also set up the .plt entries for statically linked PIC
5329 functions here. This function is called via arm_elf_finish in the
5333 elf32_arm_build_stubs (struct bfd_link_info
*info
)
5336 struct bfd_hash_table
*table
;
5337 struct elf32_arm_link_hash_table
*htab
;
5339 htab
= elf32_arm_hash_table (info
);
5343 for (stub_sec
= htab
->stub_bfd
->sections
;
5345 stub_sec
= stub_sec
->next
)
5349 /* Ignore non-stub sections. */
5350 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
5353 /* Allocate memory to hold the linker stubs. */
5354 size
= stub_sec
->size
;
5355 stub_sec
->contents
= (unsigned char *) bfd_zalloc (htab
->stub_bfd
, size
);
5356 if (stub_sec
->contents
== NULL
&& size
!= 0)
5361 /* Build the stubs as directed by the stub hash table. */
5362 table
= &htab
->stub_hash_table
;
5363 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5364 if (htab
->fix_cortex_a8
)
5366 /* Place the cortex a8 stubs last. */
5367 htab
->fix_cortex_a8
= -1;
5368 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
5374 /* Locate the Thumb encoded calling stub for NAME. */
5376 static struct elf_link_hash_entry
*
5377 find_thumb_glue (struct bfd_link_info
*link_info
,
5379 char **error_message
)
5382 struct elf_link_hash_entry
*hash
;
5383 struct elf32_arm_link_hash_table
*hash_table
;
5385 /* We need a pointer to the armelf specific hash table. */
5386 hash_table
= elf32_arm_hash_table (link_info
);
5387 if (hash_table
== NULL
)
5390 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5391 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
5393 BFD_ASSERT (tmp_name
);
5395 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
5397 hash
= elf_link_hash_lookup
5398 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5401 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
5402 tmp_name
, name
) == -1)
5403 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5410 /* Locate the ARM encoded calling stub for NAME. */
5412 static struct elf_link_hash_entry
*
5413 find_arm_glue (struct bfd_link_info
*link_info
,
5415 char **error_message
)
5418 struct elf_link_hash_entry
*myh
;
5419 struct elf32_arm_link_hash_table
*hash_table
;
5421 /* We need a pointer to the elfarm specific hash table. */
5422 hash_table
= elf32_arm_hash_table (link_info
);
5423 if (hash_table
== NULL
)
5426 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5427 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5429 BFD_ASSERT (tmp_name
);
5431 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5433 myh
= elf_link_hash_lookup
5434 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5437 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
5438 tmp_name
, name
) == -1)
5439 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
5446 /* ARM->Thumb glue (static images):
5450 ldr r12, __func_addr
5453 .word func @ behave as if you saw a ARM_32 reloc.
5460 .word func @ behave as if you saw a ARM_32 reloc.
5462 (relocatable images)
5465 ldr r12, __func_offset
5471 #define ARM2THUMB_STATIC_GLUE_SIZE 12
5472 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
5473 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
5474 static const insn32 a2t3_func_addr_insn
= 0x00000001;
5476 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
5477 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
5478 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
5480 #define ARM2THUMB_PIC_GLUE_SIZE 16
5481 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
5482 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
5483 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
5485 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
5489 __func_from_thumb: __func_from_thumb:
5491 nop ldr r6, __func_addr
5501 #define THUMB2ARM_GLUE_SIZE 8
5502 static const insn16 t2a1_bx_pc_insn
= 0x4778;
5503 static const insn16 t2a2_noop_insn
= 0x46c0;
5504 static const insn32 t2a3_b_insn
= 0xea000000;
5506 #define VFP11_ERRATUM_VENEER_SIZE 8
5508 #define ARM_BX_VENEER_SIZE 12
5509 static const insn32 armbx1_tst_insn
= 0xe3100001;
5510 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
5511 static const insn32 armbx3_bx_insn
= 0xe12fff10;
5513 #ifndef ELFARM_NABI_C_INCLUDED
5515 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
5518 bfd_byte
* contents
;
5522 /* Do not include empty glue sections in the output. */
5525 s
= bfd_get_section_by_name (abfd
, name
);
5527 s
->flags
|= SEC_EXCLUDE
;
5532 BFD_ASSERT (abfd
!= NULL
);
5534 s
= bfd_get_section_by_name (abfd
, name
);
5535 BFD_ASSERT (s
!= NULL
);
5537 contents
= (bfd_byte
*) bfd_alloc (abfd
, size
);
5539 BFD_ASSERT (s
->size
== size
);
5540 s
->contents
= contents
;
5544 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
5546 struct elf32_arm_link_hash_table
* globals
;
5548 globals
= elf32_arm_hash_table (info
);
5549 BFD_ASSERT (globals
!= NULL
);
5551 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5552 globals
->arm_glue_size
,
5553 ARM2THUMB_GLUE_SECTION_NAME
);
5555 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5556 globals
->thumb_glue_size
,
5557 THUMB2ARM_GLUE_SECTION_NAME
);
5559 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5560 globals
->vfp11_erratum_glue_size
,
5561 VFP11_ERRATUM_VENEER_SECTION_NAME
);
5563 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
5564 globals
->bx_glue_size
,
5565 ARM_BX_GLUE_SECTION_NAME
);
5570 /* Allocate space and symbols for calling a Thumb function from Arm mode.
5571 returns the symbol identifying the stub. */
5573 static struct elf_link_hash_entry
*
5574 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
5575 struct elf_link_hash_entry
* h
)
5577 const char * name
= h
->root
.root
.string
;
5580 struct elf_link_hash_entry
* myh
;
5581 struct bfd_link_hash_entry
* bh
;
5582 struct elf32_arm_link_hash_table
* globals
;
5586 globals
= elf32_arm_hash_table (link_info
);
5587 BFD_ASSERT (globals
!= NULL
);
5588 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5590 s
= bfd_get_section_by_name
5591 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
5593 BFD_ASSERT (s
!= NULL
);
5595 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
5596 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
5598 BFD_ASSERT (tmp_name
);
5600 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
5602 myh
= elf_link_hash_lookup
5603 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5607 /* We've already seen this guy. */
5612 /* The only trick here is using hash_table->arm_glue_size as the value.
5613 Even though the section isn't allocated yet, this is where we will be
5614 putting it. The +1 on the value marks that the stub has not been
5615 output yet - not that it is a Thumb function. */
5617 val
= globals
->arm_glue_size
+ 1;
5618 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5619 tmp_name
, BSF_GLOBAL
, s
, val
,
5620 NULL
, TRUE
, FALSE
, &bh
);
5622 myh
= (struct elf_link_hash_entry
*) bh
;
5623 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5624 myh
->forced_local
= 1;
5628 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
5629 || globals
->pic_veneer
)
5630 size
= ARM2THUMB_PIC_GLUE_SIZE
;
5631 else if (globals
->use_blx
)
5632 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
5634 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
5637 globals
->arm_glue_size
+= size
;
5642 /* Allocate space for ARMv4 BX veneers. */
5645 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
5648 struct elf32_arm_link_hash_table
*globals
;
5650 struct elf_link_hash_entry
*myh
;
5651 struct bfd_link_hash_entry
*bh
;
5654 /* BX PC does not need a veneer. */
5658 globals
= elf32_arm_hash_table (link_info
);
5659 BFD_ASSERT (globals
!= NULL
);
5660 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5662 /* Check if this veneer has already been allocated. */
5663 if (globals
->bx_glue_offset
[reg
])
5666 s
= bfd_get_section_by_name
5667 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
5669 BFD_ASSERT (s
!= NULL
);
5671 /* Add symbol for veneer. */
5673 bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
5675 BFD_ASSERT (tmp_name
);
5677 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
5679 myh
= elf_link_hash_lookup
5680 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5682 BFD_ASSERT (myh
== NULL
);
5685 val
= globals
->bx_glue_size
;
5686 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5687 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5688 NULL
, TRUE
, FALSE
, &bh
);
5690 myh
= (struct elf_link_hash_entry
*) bh
;
5691 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5692 myh
->forced_local
= 1;
5694 s
->size
+= ARM_BX_VENEER_SIZE
;
5695 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
5696 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
5700 /* Add an entry to the code/data map for section SEC. */
5703 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
5705 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5706 unsigned int newidx
;
5708 if (sec_data
->map
== NULL
)
5710 sec_data
->map
= (elf32_arm_section_map
*)
5711 bfd_malloc (sizeof (elf32_arm_section_map
));
5712 sec_data
->mapcount
= 0;
5713 sec_data
->mapsize
= 1;
5716 newidx
= sec_data
->mapcount
++;
5718 if (sec_data
->mapcount
> sec_data
->mapsize
)
5720 sec_data
->mapsize
*= 2;
5721 sec_data
->map
= (elf32_arm_section_map
*)
5722 bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
5723 * sizeof (elf32_arm_section_map
));
5728 sec_data
->map
[newidx
].vma
= vma
;
5729 sec_data
->map
[newidx
].type
= type
;
5734 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
5735 veneers are handled for now. */
5738 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
5739 elf32_vfp11_erratum_list
*branch
,
5741 asection
*branch_sec
,
5742 unsigned int offset
)
5745 struct elf32_arm_link_hash_table
*hash_table
;
5747 struct elf_link_hash_entry
*myh
;
5748 struct bfd_link_hash_entry
*bh
;
5750 struct _arm_elf_section_data
*sec_data
;
5751 elf32_vfp11_erratum_list
*newerr
;
5753 hash_table
= elf32_arm_hash_table (link_info
);
5754 BFD_ASSERT (hash_table
!= NULL
);
5755 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
5757 s
= bfd_get_section_by_name
5758 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
5760 sec_data
= elf32_arm_section_data (s
);
5762 BFD_ASSERT (s
!= NULL
);
5764 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
5765 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5767 BFD_ASSERT (tmp_name
);
5769 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5770 hash_table
->num_vfp11_fixes
);
5772 myh
= elf_link_hash_lookup
5773 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5775 BFD_ASSERT (myh
== NULL
);
5778 val
= hash_table
->vfp11_erratum_glue_size
;
5779 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
5780 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5781 NULL
, TRUE
, FALSE
, &bh
);
5783 myh
= (struct elf_link_hash_entry
*) bh
;
5784 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5785 myh
->forced_local
= 1;
5787 /* Link veneer back to calling location. */
5788 sec_data
->erratumcount
+= 1;
5789 newerr
= (elf32_vfp11_erratum_list
*)
5790 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5792 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
5794 newerr
->u
.v
.branch
= branch
;
5795 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
5796 branch
->u
.b
.veneer
= newerr
;
5798 newerr
->next
= sec_data
->erratumlist
;
5799 sec_data
->erratumlist
= newerr
;
5801 /* A symbol for the return from the veneer. */
5802 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
5803 hash_table
->num_vfp11_fixes
);
5805 myh
= elf_link_hash_lookup
5806 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5813 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
5814 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
5816 myh
= (struct elf_link_hash_entry
*) bh
;
5817 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5818 myh
->forced_local
= 1;
5822 /* Generate a mapping symbol for the veneer section, and explicitly add an
5823 entry for that symbol to the code/data map for the section. */
5824 if (hash_table
->vfp11_erratum_glue_size
== 0)
5827 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
5828 ever requires this erratum fix. */
5829 _bfd_generic_link_add_one_symbol (link_info
,
5830 hash_table
->bfd_of_glue_owner
, "$a",
5831 BSF_LOCAL
, s
, 0, NULL
,
5834 myh
= (struct elf_link_hash_entry
*) bh
;
5835 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5836 myh
->forced_local
= 1;
5838 /* The elf32_arm_init_maps function only cares about symbols from input
5839 BFDs. We must make a note of this generated mapping symbol
5840 ourselves so that code byteswapping works properly in
5841 elf32_arm_write_section. */
5842 elf32_arm_section_map_add (s
, 'a', 0);
5845 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
5846 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
5847 hash_table
->num_vfp11_fixes
++;
5849 /* The offset of the veneer. */
5853 #define ARM_GLUE_SECTION_FLAGS \
5854 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
5855 | SEC_READONLY | SEC_LINKER_CREATED)
5857 /* Create a fake section for use by the ARM backend of the linker. */
5860 arm_make_glue_section (bfd
* abfd
, const char * name
)
5864 sec
= bfd_get_section_by_name (abfd
, name
);
5869 sec
= bfd_make_section_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
5872 || !bfd_set_section_alignment (abfd
, sec
, 2))
5875 /* Set the gc mark to prevent the section from being removed by garbage
5876 collection, despite the fact that no relocs refer to this section. */
5882 /* Add the glue sections to ABFD. This function is called from the
5883 linker scripts in ld/emultempl/{armelf}.em. */
5886 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
5887 struct bfd_link_info
*info
)
5889 /* If we are only performing a partial
5890 link do not bother adding the glue. */
5891 if (info
->relocatable
)
5894 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
5895 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
5896 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
5897 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
5900 /* Select a BFD to be used to hold the sections used by the glue code.
5901 This function is called from the linker scripts in ld/emultempl/
5905 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
5907 struct elf32_arm_link_hash_table
*globals
;
5909 /* If we are only performing a partial link
5910 do not bother getting a bfd to hold the glue. */
5911 if (info
->relocatable
)
5914 /* Make sure we don't attach the glue sections to a dynamic object. */
5915 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
5917 globals
= elf32_arm_hash_table (info
);
5918 BFD_ASSERT (globals
!= NULL
);
5920 if (globals
->bfd_of_glue_owner
!= NULL
)
5923 /* Save the bfd for later use. */
5924 globals
->bfd_of_glue_owner
= abfd
;
5930 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
5932 if (bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
5934 globals
->use_blx
= 1;
5938 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
5939 struct bfd_link_info
*link_info
)
5941 Elf_Internal_Shdr
*symtab_hdr
;
5942 Elf_Internal_Rela
*internal_relocs
= NULL
;
5943 Elf_Internal_Rela
*irel
, *irelend
;
5944 bfd_byte
*contents
= NULL
;
5947 struct elf32_arm_link_hash_table
*globals
;
5949 /* If we are only performing a partial link do not bother
5950 to construct any glue. */
5951 if (link_info
->relocatable
)
5954 /* Here we have a bfd that is to be included on the link. We have a
5955 hook to do reloc rummaging, before section sizes are nailed down. */
5956 globals
= elf32_arm_hash_table (link_info
);
5957 BFD_ASSERT (globals
!= NULL
);
5959 check_use_blx (globals
);
5961 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
5963 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
5968 /* PR 5398: If we have not decided to include any loadable sections in
5969 the output then we will not have a glue owner bfd. This is OK, it
5970 just means that there is nothing else for us to do here. */
5971 if (globals
->bfd_of_glue_owner
== NULL
)
5974 /* Rummage around all the relocs and map the glue vectors. */
5975 sec
= abfd
->sections
;
5980 for (; sec
!= NULL
; sec
= sec
->next
)
5982 if (sec
->reloc_count
== 0)
5985 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
5988 symtab_hdr
= & elf_symtab_hdr (abfd
);
5990 /* Load the relocs. */
5992 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
5994 if (internal_relocs
== NULL
)
5997 irelend
= internal_relocs
+ sec
->reloc_count
;
5998 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6001 unsigned long r_index
;
6003 struct elf_link_hash_entry
*h
;
6005 r_type
= ELF32_R_TYPE (irel
->r_info
);
6006 r_index
= ELF32_R_SYM (irel
->r_info
);
6008 /* These are the only relocation types we care about. */
6009 if ( r_type
!= R_ARM_PC24
6010 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
6013 /* Get the section contents if we haven't done so already. */
6014 if (contents
== NULL
)
6016 /* Get cached copy if it exists. */
6017 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6018 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6021 /* Go get them off disk. */
6022 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6027 if (r_type
== R_ARM_V4BX
)
6031 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
6032 record_arm_bx_glue (link_info
, reg
);
6036 /* If the relocation is not against a symbol it cannot concern us. */
6039 /* We don't care about local symbols. */
6040 if (r_index
< symtab_hdr
->sh_info
)
6043 /* This is an external symbol. */
6044 r_index
-= symtab_hdr
->sh_info
;
6045 h
= (struct elf_link_hash_entry
*)
6046 elf_sym_hashes (abfd
)[r_index
];
6048 /* If the relocation is against a static symbol it must be within
6049 the current section and so cannot be a cross ARM/Thumb relocation. */
6053 /* If the call will go through a PLT entry then we do not need
6055 if (globals
->root
.splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6061 /* This one is a call from arm code. We need to look up
6062 the target of the call. If it is a thumb target, we
6064 if (h
->target_internal
== ST_BRANCH_TO_THUMB
)
6065 record_arm_to_thumb_glue (link_info
, h
);
6073 if (contents
!= NULL
6074 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6078 if (internal_relocs
!= NULL
6079 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6080 free (internal_relocs
);
6081 internal_relocs
= NULL
;
6087 if (contents
!= NULL
6088 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6090 if (internal_relocs
!= NULL
6091 && elf_section_data (sec
)->relocs
!= internal_relocs
)
6092 free (internal_relocs
);
6099 /* Initialise maps of ARM/Thumb/data for input BFDs. */
6102 bfd_elf32_arm_init_maps (bfd
*abfd
)
6104 Elf_Internal_Sym
*isymbuf
;
6105 Elf_Internal_Shdr
*hdr
;
6106 unsigned int i
, localsyms
;
6108 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
6109 if (! is_arm_elf (abfd
))
6112 if ((abfd
->flags
& DYNAMIC
) != 0)
6115 hdr
= & elf_symtab_hdr (abfd
);
6116 localsyms
= hdr
->sh_info
;
6118 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
6119 should contain the number of local symbols, which should come before any
6120 global symbols. Mapping symbols are always local. */
6121 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
6124 /* No internal symbols read? Skip this BFD. */
6125 if (isymbuf
== NULL
)
6128 for (i
= 0; i
< localsyms
; i
++)
6130 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
6131 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6135 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
6137 name
= bfd_elf_string_from_elf_section (abfd
,
6138 hdr
->sh_link
, isym
->st_name
);
6140 if (bfd_is_arm_special_symbol_name (name
,
6141 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
6142 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
6148 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
6149 say what they wanted. */
6152 bfd_elf32_arm_set_cortex_a8_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6154 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6155 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6157 if (globals
== NULL
)
6160 if (globals
->fix_cortex_a8
== -1)
6162 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
6163 if (out_attr
[Tag_CPU_arch
].i
== TAG_CPU_ARCH_V7
6164 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
6165 || out_attr
[Tag_CPU_arch_profile
].i
== 0))
6166 globals
->fix_cortex_a8
= 1;
6168 globals
->fix_cortex_a8
= 0;
6174 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
6176 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6177 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
6179 if (globals
== NULL
)
6181 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
6182 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
6184 switch (globals
->vfp11_fix
)
6186 case BFD_ARM_VFP11_FIX_DEFAULT
:
6187 case BFD_ARM_VFP11_FIX_NONE
:
6188 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6192 /* Give a warning, but do as the user requests anyway. */
6193 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
6194 "workaround is not necessary for target architecture"), obfd
);
6197 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
6198 /* For earlier architectures, we might need the workaround, but do not
6199 enable it by default. If users is running with broken hardware, they
6200 must enable the erratum fix explicitly. */
6201 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
6205 enum bfd_arm_vfp11_pipe
6213 /* Return a VFP register number. This is encoded as RX:X for single-precision
6214 registers, or X:RX for double-precision registers, where RX is the group of
6215 four bits in the instruction encoding and X is the single extension bit.
6216 RX and X fields are specified using their lowest (starting) bit. The return
6219 0...31: single-precision registers s0...s31
6220 32...63: double-precision registers d0...d31.
6222 Although X should be zero for VFP11 (encoding d0...d15 only), we might
6223 encounter VFP3 instructions, so we allow the full range for DP registers. */
6226 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
6230 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
6232 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
6235 /* Set bits in *WMASK according to a register number REG as encoded by
6236 bfd_arm_vfp11_regno(). Ignore d16-d31. */
6239 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
6244 *wmask
|= 3 << ((reg
- 32) * 2);
6247 /* Return TRUE if WMASK overwrites anything in REGS. */
6250 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
6254 for (i
= 0; i
< numregs
; i
++)
6256 unsigned int reg
= regs
[i
];
6258 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
6266 if ((wmask
& (3 << (reg
* 2))) != 0)
6273 /* In this function, we're interested in two things: finding input registers
6274 for VFP data-processing instructions, and finding the set of registers which
6275 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
6276 hold the written set, so FLDM etc. are easy to deal with (we're only
6277 interested in 32 SP registers or 16 dp registers, due to the VFP version
6278 implemented by the chip in question). DP registers are marked by setting
6279 both SP registers in the write mask). */
6281 static enum bfd_arm_vfp11_pipe
6282 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
6285 enum bfd_arm_vfp11_pipe vpipe
= VFP11_BAD
;
6286 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
6288 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
6291 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6292 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6294 pqrs
= ((insn
& 0x00800000) >> 20)
6295 | ((insn
& 0x00300000) >> 19)
6296 | ((insn
& 0x00000040) >> 6);
6300 case 0: /* fmac[sd]. */
6301 case 1: /* fnmac[sd]. */
6302 case 2: /* fmsc[sd]. */
6303 case 3: /* fnmsc[sd]. */
6305 bfd_arm_vfp11_write_mask (destmask
, fd
);
6307 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6312 case 4: /* fmul[sd]. */
6313 case 5: /* fnmul[sd]. */
6314 case 6: /* fadd[sd]. */
6315 case 7: /* fsub[sd]. */
6319 case 8: /* fdiv[sd]. */
6322 bfd_arm_vfp11_write_mask (destmask
, fd
);
6323 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
6328 case 15: /* extended opcode. */
6330 unsigned int extn
= ((insn
>> 15) & 0x1e)
6331 | ((insn
>> 7) & 1);
6335 case 0: /* fcpy[sd]. */
6336 case 1: /* fabs[sd]. */
6337 case 2: /* fneg[sd]. */
6338 case 8: /* fcmp[sd]. */
6339 case 9: /* fcmpe[sd]. */
6340 case 10: /* fcmpz[sd]. */
6341 case 11: /* fcmpez[sd]. */
6342 case 16: /* fuito[sd]. */
6343 case 17: /* fsito[sd]. */
6344 case 24: /* ftoui[sd]. */
6345 case 25: /* ftouiz[sd]. */
6346 case 26: /* ftosi[sd]. */
6347 case 27: /* ftosiz[sd]. */
6348 /* These instructions will not bounce due to underflow. */
6353 case 3: /* fsqrt[sd]. */
6354 /* fsqrt cannot underflow, but it can (perhaps) overwrite
6355 registers to cause the erratum in previous instructions. */
6356 bfd_arm_vfp11_write_mask (destmask
, fd
);
6360 case 15: /* fcvt{ds,sd}. */
6364 bfd_arm_vfp11_write_mask (destmask
, fd
);
6366 /* Only FCVTSD can underflow. */
6367 if ((insn
& 0x100) != 0)
6386 /* Two-register transfer. */
6387 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
6389 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
6391 if ((insn
& 0x100000) == 0)
6394 bfd_arm_vfp11_write_mask (destmask
, fm
);
6397 bfd_arm_vfp11_write_mask (destmask
, fm
);
6398 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
6404 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
6406 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
6407 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
6411 case 0: /* Two-reg transfer. We should catch these above. */
6414 case 2: /* fldm[sdx]. */
6418 unsigned int i
, offset
= insn
& 0xff;
6423 for (i
= fd
; i
< fd
+ offset
; i
++)
6424 bfd_arm_vfp11_write_mask (destmask
, i
);
6428 case 4: /* fld[sd]. */
6430 bfd_arm_vfp11_write_mask (destmask
, fd
);
6439 /* Single-register transfer. Note L==0. */
6440 else if ((insn
& 0x0f100e10) == 0x0e000a10)
6442 unsigned int opcode
= (insn
>> 21) & 7;
6443 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
6447 case 0: /* fmsr/fmdlr. */
6448 case 1: /* fmdhr. */
6449 /* Mark fmdhr and fmdlr as writing to the whole of the DP
6450 destination register. I don't know if this is exactly right,
6451 but it is the conservative choice. */
6452 bfd_arm_vfp11_write_mask (destmask
, fn
);
6466 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
6469 /* Look for potentially-troublesome code sequences which might trigger the
6470 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
6471 (available from ARM) for details of the erratum. A short version is
6472 described in ld.texinfo. */
6475 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
6478 bfd_byte
*contents
= NULL
;
6480 int regs
[3], numregs
= 0;
6481 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
6482 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
6484 if (globals
== NULL
)
6487 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
6488 The states transition as follows:
6490 0 -> 1 (vector) or 0 -> 2 (scalar)
6491 A VFP FMAC-pipeline instruction has been seen. Fill
6492 regs[0]..regs[numregs-1] with its input operands. Remember this
6493 instruction in 'first_fmac'.
6496 Any instruction, except for a VFP instruction which overwrites
6501 A VFP instruction has been seen which overwrites any of regs[*].
6502 We must make a veneer! Reset state to 0 before examining next
6506 If we fail to match anything in state 2, reset to state 0 and reset
6507 the instruction pointer to the instruction after 'first_fmac'.
6509 If the VFP11 vector mode is in use, there must be at least two unrelated
6510 instructions between anti-dependent VFP11 instructions to properly avoid
6511 triggering the erratum, hence the use of the extra state 1. */
6513 /* If we are only performing a partial link do not bother
6514 to construct any glue. */
6515 if (link_info
->relocatable
)
6518 /* Skip if this bfd does not correspond to an ELF image. */
6519 if (! is_arm_elf (abfd
))
6522 /* We should have chosen a fix type by the time we get here. */
6523 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
6525 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
6528 /* Skip this BFD if it corresponds to an executable or dynamic object. */
6529 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
6532 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6534 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
6535 struct _arm_elf_section_data
*sec_data
;
6537 /* If we don't have executable progbits, we're not interested in this
6538 section. Also skip if section is to be excluded. */
6539 if (elf_section_type (sec
) != SHT_PROGBITS
6540 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
6541 || (sec
->flags
& SEC_EXCLUDE
) != 0
6542 || sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
6543 || sec
->output_section
== bfd_abs_section_ptr
6544 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
6547 sec_data
= elf32_arm_section_data (sec
);
6549 if (sec_data
->mapcount
== 0)
6552 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
6553 contents
= elf_section_data (sec
)->this_hdr
.contents
;
6554 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
6557 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
6558 elf32_arm_compare_mapping
);
6560 for (span
= 0; span
< sec_data
->mapcount
; span
++)
6562 unsigned int span_start
= sec_data
->map
[span
].vma
;
6563 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
6564 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
6565 char span_type
= sec_data
->map
[span
].type
;
6567 /* FIXME: Only ARM mode is supported at present. We may need to
6568 support Thumb-2 mode also at some point. */
6569 if (span_type
!= 'a')
6572 for (i
= span_start
; i
< span_end
;)
6574 unsigned int next_i
= i
+ 4;
6575 unsigned int insn
= bfd_big_endian (abfd
)
6576 ? (contents
[i
] << 24)
6577 | (contents
[i
+ 1] << 16)
6578 | (contents
[i
+ 2] << 8)
6580 : (contents
[i
+ 3] << 24)
6581 | (contents
[i
+ 2] << 16)
6582 | (contents
[i
+ 1] << 8)
6584 unsigned int writemask
= 0;
6585 enum bfd_arm_vfp11_pipe vpipe
;
6590 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
6592 /* I'm assuming the VFP11 erratum can trigger with denorm
6593 operands on either the FMAC or the DS pipeline. This might
6594 lead to slightly overenthusiastic veneer insertion. */
6595 if (vpipe
== VFP11_FMAC
|| vpipe
== VFP11_DS
)
6597 state
= use_vector
? 1 : 2;
6599 veneer_of_insn
= insn
;
6605 int other_regs
[3], other_numregs
;
6606 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6609 if (vpipe
!= VFP11_BAD
6610 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6620 int other_regs
[3], other_numregs
;
6621 vpipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
6624 if (vpipe
!= VFP11_BAD
6625 && bfd_arm_vfp11_antidependency (writemask
, regs
,
6631 next_i
= first_fmac
+ 4;
6637 abort (); /* Should be unreachable. */
6642 elf32_vfp11_erratum_list
*newerr
=(elf32_vfp11_erratum_list
*)
6643 bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
6645 elf32_arm_section_data (sec
)->erratumcount
+= 1;
6647 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
6652 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
6659 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
6664 newerr
->next
= sec_data
->erratumlist
;
6665 sec_data
->erratumlist
= newerr
;
6674 if (contents
!= NULL
6675 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6683 if (contents
!= NULL
6684 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6690 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
6691 after sections have been laid out, using specially-named symbols. */
6694 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
6695 struct bfd_link_info
*link_info
)
6698 struct elf32_arm_link_hash_table
*globals
;
6701 if (link_info
->relocatable
)
6704 /* Skip if this bfd does not correspond to an ELF image. */
6705 if (! is_arm_elf (abfd
))
6708 globals
= elf32_arm_hash_table (link_info
);
6709 if (globals
== NULL
)
6712 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen
6713 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
6715 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6717 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
6718 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
6720 for (; errnode
!= NULL
; errnode
= errnode
->next
)
6722 struct elf_link_hash_entry
*myh
;
6725 switch (errnode
->type
)
6727 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
6728 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
6729 /* Find veneer symbol. */
6730 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
6731 errnode
->u
.b
.veneer
->u
.v
.id
);
6733 myh
= elf_link_hash_lookup
6734 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6737 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6738 "`%s'"), abfd
, tmp_name
);
6740 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6741 + myh
->root
.u
.def
.section
->output_offset
6742 + myh
->root
.u
.def
.value
;
6744 errnode
->u
.b
.veneer
->vma
= vma
;
6747 case VFP11_ERRATUM_ARM_VENEER
:
6748 case VFP11_ERRATUM_THUMB_VENEER
:
6749 /* Find return location. */
6750 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
6753 myh
= elf_link_hash_lookup
6754 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6757 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6758 "`%s'"), abfd
, tmp_name
);
6760 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6761 + myh
->root
.u
.def
.section
->output_offset
6762 + myh
->root
.u
.def
.value
;
6764 errnode
->u
.v
.branch
->vma
= vma
;
6777 /* Set target relocation values needed during linking. */
6780 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
6781 struct bfd_link_info
*link_info
,
6783 char * target2_type
,
6786 bfd_arm_vfp11_fix vfp11_fix
,
6787 int no_enum_warn
, int no_wchar_warn
,
6788 int pic_veneer
, int fix_cortex_a8
)
6790 struct elf32_arm_link_hash_table
*globals
;
6792 globals
= elf32_arm_hash_table (link_info
);
6793 if (globals
== NULL
)
6796 globals
->target1_is_rel
= target1_is_rel
;
6797 if (strcmp (target2_type
, "rel") == 0)
6798 globals
->target2_reloc
= R_ARM_REL32
;
6799 else if (strcmp (target2_type
, "abs") == 0)
6800 globals
->target2_reloc
= R_ARM_ABS32
;
6801 else if (strcmp (target2_type
, "got-rel") == 0)
6802 globals
->target2_reloc
= R_ARM_GOT_PREL
;
6805 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
6808 globals
->fix_v4bx
= fix_v4bx
;
6809 globals
->use_blx
|= use_blx
;
6810 globals
->vfp11_fix
= vfp11_fix
;
6811 globals
->pic_veneer
= pic_veneer
;
6812 globals
->fix_cortex_a8
= fix_cortex_a8
;
6814 BFD_ASSERT (is_arm_elf (output_bfd
));
6815 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
6816 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
6819 /* Replace the target offset of a Thumb bl or b.w instruction. */
6822 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
6828 BFD_ASSERT ((offset
& 1) == 0);
6830 upper
= bfd_get_16 (abfd
, insn
);
6831 lower
= bfd_get_16 (abfd
, insn
+ 2);
6832 reloc_sign
= (offset
< 0) ? 1 : 0;
6833 upper
= (upper
& ~(bfd_vma
) 0x7ff)
6834 | ((offset
>> 12) & 0x3ff)
6835 | (reloc_sign
<< 10);
6836 lower
= (lower
& ~(bfd_vma
) 0x2fff)
6837 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
6838 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
6839 | ((offset
>> 1) & 0x7ff);
6840 bfd_put_16 (abfd
, upper
, insn
);
6841 bfd_put_16 (abfd
, lower
, insn
+ 2);
6844 /* Thumb code calling an ARM function. */
6847 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
6851 asection
* input_section
,
6852 bfd_byte
* hit_data
,
6855 bfd_signed_vma addend
,
6857 char **error_message
)
6861 long int ret_offset
;
6862 struct elf_link_hash_entry
* myh
;
6863 struct elf32_arm_link_hash_table
* globals
;
6865 myh
= find_thumb_glue (info
, name
, error_message
);
6869 globals
= elf32_arm_hash_table (info
);
6870 BFD_ASSERT (globals
!= NULL
);
6871 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6873 my_offset
= myh
->root
.u
.def
.value
;
6875 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
6876 THUMB2ARM_GLUE_SECTION_NAME
);
6878 BFD_ASSERT (s
!= NULL
);
6879 BFD_ASSERT (s
->contents
!= NULL
);
6880 BFD_ASSERT (s
->output_section
!= NULL
);
6882 if ((my_offset
& 0x01) == 0x01)
6885 && sym_sec
->owner
!= NULL
6886 && !INTERWORK_FLAG (sym_sec
->owner
))
6888 (*_bfd_error_handler
)
6889 (_("%B(%s): warning: interworking not enabled.\n"
6890 " first occurrence: %B: thumb call to arm"),
6891 sym_sec
->owner
, input_bfd
, name
);
6897 myh
->root
.u
.def
.value
= my_offset
;
6899 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
6900 s
->contents
+ my_offset
);
6902 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
6903 s
->contents
+ my_offset
+ 2);
6906 /* Address of destination of the stub. */
6907 ((bfd_signed_vma
) val
)
6909 /* Offset from the start of the current section
6910 to the start of the stubs. */
6912 /* Offset of the start of this stub from the start of the stubs. */
6914 /* Address of the start of the current section. */
6915 + s
->output_section
->vma
)
6916 /* The branch instruction is 4 bytes into the stub. */
6918 /* ARM branches work from the pc of the instruction + 8. */
6921 put_arm_insn (globals
, output_bfd
,
6922 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
6923 s
->contents
+ my_offset
+ 4);
6926 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
6928 /* Now go back and fix up the original BL insn to point to here. */
6930 /* Address of where the stub is located. */
6931 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
6932 /* Address of where the BL is located. */
6933 - (input_section
->output_section
->vma
+ input_section
->output_offset
6935 /* Addend in the relocation. */
6937 /* Biassing for PC-relative addressing. */
6940 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
6945 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
6947 static struct elf_link_hash_entry
*
6948 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
6955 char ** error_message
)
6958 long int ret_offset
;
6959 struct elf_link_hash_entry
* myh
;
6960 struct elf32_arm_link_hash_table
* globals
;
6962 myh
= find_arm_glue (info
, name
, error_message
);
6966 globals
= elf32_arm_hash_table (info
);
6967 BFD_ASSERT (globals
!= NULL
);
6968 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6970 my_offset
= myh
->root
.u
.def
.value
;
6972 if ((my_offset
& 0x01) == 0x01)
6975 && sym_sec
->owner
!= NULL
6976 && !INTERWORK_FLAG (sym_sec
->owner
))
6978 (*_bfd_error_handler
)
6979 (_("%B(%s): warning: interworking not enabled.\n"
6980 " first occurrence: %B: arm call to thumb"),
6981 sym_sec
->owner
, input_bfd
, name
);
6985 myh
->root
.u
.def
.value
= my_offset
;
6987 if (info
->shared
|| globals
->root
.is_relocatable_executable
6988 || globals
->pic_veneer
)
6990 /* For relocatable objects we can't use absolute addresses,
6991 so construct the address from a relative offset. */
6992 /* TODO: If the offset is small it's probably worth
6993 constructing the address with adds. */
6994 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
6995 s
->contents
+ my_offset
);
6996 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
6997 s
->contents
+ my_offset
+ 4);
6998 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
6999 s
->contents
+ my_offset
+ 8);
7000 /* Adjust the offset by 4 for the position of the add,
7001 and 8 for the pipeline offset. */
7002 ret_offset
= (val
- (s
->output_offset
7003 + s
->output_section
->vma
7006 bfd_put_32 (output_bfd
, ret_offset
,
7007 s
->contents
+ my_offset
+ 12);
7009 else if (globals
->use_blx
)
7011 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
7012 s
->contents
+ my_offset
);
7014 /* It's a thumb address. Add the low order bit. */
7015 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
7016 s
->contents
+ my_offset
+ 4);
7020 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
7021 s
->contents
+ my_offset
);
7023 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
7024 s
->contents
+ my_offset
+ 4);
7026 /* It's a thumb address. Add the low order bit. */
7027 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
7028 s
->contents
+ my_offset
+ 8);
7034 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
7039 /* Arm code calling a Thumb function. */
7042 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
7046 asection
* input_section
,
7047 bfd_byte
* hit_data
,
7050 bfd_signed_vma addend
,
7052 char **error_message
)
7054 unsigned long int tmp
;
7057 long int ret_offset
;
7058 struct elf_link_hash_entry
* myh
;
7059 struct elf32_arm_link_hash_table
* globals
;
7061 globals
= elf32_arm_hash_table (info
);
7062 BFD_ASSERT (globals
!= NULL
);
7063 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7065 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
7066 ARM2THUMB_GLUE_SECTION_NAME
);
7067 BFD_ASSERT (s
!= NULL
);
7068 BFD_ASSERT (s
->contents
!= NULL
);
7069 BFD_ASSERT (s
->output_section
!= NULL
);
7071 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
7072 sym_sec
, val
, s
, error_message
);
7076 my_offset
= myh
->root
.u
.def
.value
;
7077 tmp
= bfd_get_32 (input_bfd
, hit_data
);
7078 tmp
= tmp
& 0xFF000000;
7080 /* Somehow these are both 4 too far, so subtract 8. */
7081 ret_offset
= (s
->output_offset
7083 + s
->output_section
->vma
7084 - (input_section
->output_offset
7085 + input_section
->output_section
->vma
7089 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
7091 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
7096 /* Populate Arm stub for an exported Thumb function. */
7099 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
7101 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
7103 struct elf_link_hash_entry
* myh
;
7104 struct elf32_arm_link_hash_entry
*eh
;
7105 struct elf32_arm_link_hash_table
* globals
;
7108 char *error_message
;
7110 eh
= elf32_arm_hash_entry (h
);
7111 /* Allocate stubs for exported Thumb functions on v4t. */
7112 if (eh
->export_glue
== NULL
)
7115 globals
= elf32_arm_hash_table (info
);
7116 BFD_ASSERT (globals
!= NULL
);
7117 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7119 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
7120 ARM2THUMB_GLUE_SECTION_NAME
);
7121 BFD_ASSERT (s
!= NULL
);
7122 BFD_ASSERT (s
->contents
!= NULL
);
7123 BFD_ASSERT (s
->output_section
!= NULL
);
7125 sec
= eh
->export_glue
->root
.u
.def
.section
;
7127 BFD_ASSERT (sec
->output_section
!= NULL
);
7129 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
7130 + sec
->output_section
->vma
;
7132 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
7133 h
->root
.u
.def
.section
->owner
,
7134 globals
->obfd
, sec
, val
, s
,
7140 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
7143 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
7148 struct elf32_arm_link_hash_table
*globals
;
7150 globals
= elf32_arm_hash_table (info
);
7151 BFD_ASSERT (globals
!= NULL
);
7152 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
7154 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
7155 ARM_BX_GLUE_SECTION_NAME
);
7156 BFD_ASSERT (s
!= NULL
);
7157 BFD_ASSERT (s
->contents
!= NULL
);
7158 BFD_ASSERT (s
->output_section
!= NULL
);
7160 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
7162 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
7164 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
7166 p
= s
->contents
+ glue_addr
;
7167 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
7168 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
7169 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
7170 globals
->bx_glue_offset
[reg
] |= 1;
7173 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
7176 /* Generate Arm stubs for exported Thumb symbols. */
7178 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
7179 struct bfd_link_info
*link_info
)
7181 struct elf32_arm_link_hash_table
* globals
;
7183 if (link_info
== NULL
)
7184 /* Ignore this if we are not called by the ELF backend linker. */
7187 globals
= elf32_arm_hash_table (link_info
);
7188 if (globals
== NULL
)
7191 /* If blx is available then exported Thumb symbols are OK and there is
7193 if (globals
->use_blx
)
7196 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
7200 /* Reserve space for COUNT dynamic relocations in relocation selection
7204 elf32_arm_allocate_dynrelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7205 bfd_size_type count
)
7207 struct elf32_arm_link_hash_table
*htab
;
7209 htab
= elf32_arm_hash_table (info
);
7210 BFD_ASSERT (htab
->root
.dynamic_sections_created
);
7213 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7216 /* Reserve space for COUNT R_ARM_IRELATIVE relocations. If the link is
7217 dynamic, the relocations should go in SRELOC, otherwise they should
7218 go in the special .rel.iplt section. */
7221 elf32_arm_allocate_irelocs (struct bfd_link_info
*info
, asection
*sreloc
,
7222 bfd_size_type count
)
7224 struct elf32_arm_link_hash_table
*htab
;
7226 htab
= elf32_arm_hash_table (info
);
7227 if (!htab
->root
.dynamic_sections_created
)
7228 htab
->root
.irelplt
->size
+= RELOC_SIZE (htab
) * count
;
7231 BFD_ASSERT (sreloc
!= NULL
);
7232 sreloc
->size
+= RELOC_SIZE (htab
) * count
;
7236 /* Add relocation REL to the end of relocation section SRELOC. */
7239 elf32_arm_add_dynreloc (bfd
*output_bfd
, struct bfd_link_info
*info
,
7240 asection
*sreloc
, Elf_Internal_Rela
*rel
)
7243 struct elf32_arm_link_hash_table
*htab
;
7245 htab
= elf32_arm_hash_table (info
);
7246 if (!htab
->root
.dynamic_sections_created
7247 && ELF32_R_TYPE (rel
->r_info
) == R_ARM_IRELATIVE
)
7248 sreloc
= htab
->root
.irelplt
;
7251 loc
= sreloc
->contents
;
7252 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (htab
);
7253 if (sreloc
->reloc_count
* RELOC_SIZE (htab
) > sreloc
->size
)
7255 SWAP_RELOC_OUT (htab
) (output_bfd
, rel
, loc
);
7258 /* Allocate room for a PLT entry described by ROOT_PLT and ARM_PLT.
7259 IS_IPLT_ENTRY says whether the entry belongs to .iplt rather than
7263 elf32_arm_allocate_plt_entry (struct bfd_link_info
*info
,
7264 bfd_boolean is_iplt_entry
,
7265 union gotplt_union
*root_plt
,
7266 struct arm_plt_info
*arm_plt
)
7268 struct elf32_arm_link_hash_table
*htab
;
7272 htab
= elf32_arm_hash_table (info
);
7276 splt
= htab
->root
.iplt
;
7277 sgotplt
= htab
->root
.igotplt
;
7279 /* Allocate room for an R_ARM_IRELATIVE relocation in .rel.iplt. */
7280 elf32_arm_allocate_irelocs (info
, htab
->root
.irelplt
, 1);
7284 splt
= htab
->root
.splt
;
7285 sgotplt
= htab
->root
.sgotplt
;
7287 /* Allocate room for an R_JUMP_SLOT relocation in .rel.plt. */
7288 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
7290 /* If this is the first .plt entry, make room for the special
7292 if (splt
->size
== 0)
7293 splt
->size
+= htab
->plt_header_size
;
7296 /* Allocate the PLT entry itself, including any leading Thumb stub. */
7297 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7298 splt
->size
+= PLT_THUMB_STUB_SIZE
;
7299 root_plt
->offset
= splt
->size
;
7300 splt
->size
+= htab
->plt_entry_size
;
7302 if (!htab
->symbian_p
)
7304 /* We also need to make an entry in the .got.plt section, which
7305 will be placed in the .got section by the linker script. */
7306 arm_plt
->got_offset
= sgotplt
->size
- 8 * htab
->num_tls_desc
;
7311 /* Fill in a PLT entry and its associated GOT slot. If DYNINDX == -1,
7312 the entry lives in .iplt and resolves to (*SYM_VALUE)().
7313 Otherwise, DYNINDX is the index of the symbol in the dynamic
7314 symbol table and SYM_VALUE is undefined.
7316 ROOT_PLT points to the offset of the PLT entry from the start of its
7317 section (.iplt or .plt). ARM_PLT points to the symbol's ARM-specific
7318 bookkeeping information. */
7321 elf32_arm_populate_plt_entry (bfd
*output_bfd
, struct bfd_link_info
*info
,
7322 union gotplt_union
*root_plt
,
7323 struct arm_plt_info
*arm_plt
,
7324 int dynindx
, bfd_vma sym_value
)
7326 struct elf32_arm_link_hash_table
*htab
;
7332 Elf_Internal_Rela rel
;
7333 bfd_vma plt_header_size
;
7334 bfd_vma got_header_size
;
7336 htab
= elf32_arm_hash_table (info
);
7338 /* Pick the appropriate sections and sizes. */
7341 splt
= htab
->root
.iplt
;
7342 sgot
= htab
->root
.igotplt
;
7343 srel
= htab
->root
.irelplt
;
7345 /* There are no reserved entries in .igot.plt, and no special
7346 first entry in .iplt. */
7347 got_header_size
= 0;
7348 plt_header_size
= 0;
7352 splt
= htab
->root
.splt
;
7353 sgot
= htab
->root
.sgotplt
;
7354 srel
= htab
->root
.srelplt
;
7356 got_header_size
= get_elf_backend_data (output_bfd
)->got_header_size
;
7357 plt_header_size
= htab
->plt_header_size
;
7359 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
7361 /* Fill in the entry in the procedure linkage table. */
7362 if (htab
->symbian_p
)
7364 BFD_ASSERT (dynindx
>= 0);
7365 put_arm_insn (htab
, output_bfd
,
7366 elf32_arm_symbian_plt_entry
[0],
7367 splt
->contents
+ root_plt
->offset
);
7368 bfd_put_32 (output_bfd
,
7369 elf32_arm_symbian_plt_entry
[1],
7370 splt
->contents
+ root_plt
->offset
+ 4);
7372 /* Fill in the entry in the .rel.plt section. */
7373 rel
.r_offset
= (splt
->output_section
->vma
7374 + splt
->output_offset
7375 + root_plt
->offset
+ 4);
7376 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_GLOB_DAT
);
7378 /* Get the index in the procedure linkage table which
7379 corresponds to this symbol. This is the index of this symbol
7380 in all the symbols for which we are making plt entries. The
7381 first entry in the procedure linkage table is reserved. */
7382 plt_index
= ((root_plt
->offset
- plt_header_size
)
7383 / htab
->plt_entry_size
);
7387 bfd_vma got_offset
, got_address
, plt_address
;
7388 bfd_vma got_displacement
, initial_got_entry
;
7391 BFD_ASSERT (sgot
!= NULL
);
7393 /* Get the offset into the .(i)got.plt table of the entry that
7394 corresponds to this function. */
7395 got_offset
= (arm_plt
->got_offset
& -2);
7397 /* Get the index in the procedure linkage table which
7398 corresponds to this symbol. This is the index of this symbol
7399 in all the symbols for which we are making plt entries.
7400 After the reserved .got.plt entries, all symbols appear in
7401 the same order as in .plt. */
7402 plt_index
= (got_offset
- got_header_size
) / 4;
7404 /* Calculate the address of the GOT entry. */
7405 got_address
= (sgot
->output_section
->vma
7406 + sgot
->output_offset
7409 /* ...and the address of the PLT entry. */
7410 plt_address
= (splt
->output_section
->vma
7411 + splt
->output_offset
7412 + root_plt
->offset
);
7414 ptr
= splt
->contents
+ root_plt
->offset
;
7415 if (htab
->vxworks_p
&& info
->shared
)
7420 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7422 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
7424 val
|= got_address
- sgot
->output_section
->vma
;
7426 val
|= plt_index
* RELOC_SIZE (htab
);
7427 if (i
== 2 || i
== 5)
7428 bfd_put_32 (output_bfd
, val
, ptr
);
7430 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7433 else if (htab
->vxworks_p
)
7438 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
7440 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
7444 val
|= 0xffffff & -((root_plt
->offset
+ i
* 4 + 8) >> 2);
7446 val
|= plt_index
* RELOC_SIZE (htab
);
7447 if (i
== 2 || i
== 5)
7448 bfd_put_32 (output_bfd
, val
, ptr
);
7450 put_arm_insn (htab
, output_bfd
, val
, ptr
);
7453 loc
= (htab
->srelplt2
->contents
7454 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
7456 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
7457 referencing the GOT for this PLT entry. */
7458 rel
.r_offset
= plt_address
+ 8;
7459 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
7460 rel
.r_addend
= got_offset
;
7461 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7462 loc
+= RELOC_SIZE (htab
);
7464 /* Create the R_ARM_ABS32 relocation referencing the
7465 beginning of the PLT for this GOT entry. */
7466 rel
.r_offset
= got_address
;
7467 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
7469 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7473 /* Calculate the displacement between the PLT slot and the
7474 entry in the GOT. The eight-byte offset accounts for the
7475 value produced by adding to pc in the first instruction
7477 got_displacement
= got_address
- (plt_address
+ 8);
7479 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
7481 if (elf32_arm_plt_needs_thumb_stub_p (info
, arm_plt
))
7483 put_thumb_insn (htab
, output_bfd
,
7484 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
7485 put_thumb_insn (htab
, output_bfd
,
7486 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
7489 put_arm_insn (htab
, output_bfd
,
7490 elf32_arm_plt_entry
[0]
7491 | ((got_displacement
& 0x0ff00000) >> 20),
7493 put_arm_insn (htab
, output_bfd
,
7494 elf32_arm_plt_entry
[1]
7495 | ((got_displacement
& 0x000ff000) >> 12),
7497 put_arm_insn (htab
, output_bfd
,
7498 elf32_arm_plt_entry
[2]
7499 | (got_displacement
& 0x00000fff),
7501 #ifdef FOUR_WORD_PLT
7502 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
7506 /* Fill in the entry in the .rel(a).(i)plt section. */
7507 rel
.r_offset
= got_address
;
7511 /* .igot.plt entries use IRELATIVE relocations against SYM_VALUE.
7512 The dynamic linker or static executable then calls SYM_VALUE
7513 to determine the correct run-time value of the .igot.plt entry. */
7514 rel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
7515 initial_got_entry
= sym_value
;
7519 rel
.r_info
= ELF32_R_INFO (dynindx
, R_ARM_JUMP_SLOT
);
7520 initial_got_entry
= (splt
->output_section
->vma
7521 + splt
->output_offset
);
7524 /* Fill in the entry in the global offset table. */
7525 bfd_put_32 (output_bfd
, initial_got_entry
,
7526 sgot
->contents
+ got_offset
);
7529 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
7530 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7533 /* Some relocations map to different relocations depending on the
7534 target. Return the real relocation. */
7537 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
7543 if (globals
->target1_is_rel
)
7549 return globals
->target2_reloc
;
7556 /* Return the base VMA address which should be subtracted from real addresses
7557 when resolving @dtpoff relocation.
7558 This is PT_TLS segment p_vaddr. */
7561 dtpoff_base (struct bfd_link_info
*info
)
7563 /* If tls_sec is NULL, we should have signalled an error already. */
7564 if (elf_hash_table (info
)->tls_sec
== NULL
)
7566 return elf_hash_table (info
)->tls_sec
->vma
;
7569 /* Return the relocation value for @tpoff relocation
7570 if STT_TLS virtual address is ADDRESS. */
7573 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
7575 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7578 /* If tls_sec is NULL, we should have signalled an error already. */
7579 if (htab
->tls_sec
== NULL
)
7581 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
7582 return address
- htab
->tls_sec
->vma
+ base
;
7585 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
7586 VALUE is the relocation value. */
7588 static bfd_reloc_status_type
7589 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
7592 return bfd_reloc_overflow
;
7594 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
7595 bfd_put_32 (abfd
, value
, data
);
7596 return bfd_reloc_ok
;
7599 /* Handle TLS relaxations. Relaxing is possible for symbols that use
7600 R_ARM_GOTDESC, R_ARM_{,THM_}TLS_CALL or
7601 R_ARM_{,THM_}TLS_DESCSEQ relocations, during a static link.
7603 Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
7604 is to then call final_link_relocate. Return other values in the
7607 FIXME:When --emit-relocs is in effect, we'll emit relocs describing
7608 the pre-relaxed code. It would be nice if the relocs were updated
7609 to match the optimization. */
7611 static bfd_reloc_status_type
7612 elf32_arm_tls_relax (struct elf32_arm_link_hash_table
*globals
,
7613 bfd
*input_bfd
, asection
*input_sec
, bfd_byte
*contents
,
7614 Elf_Internal_Rela
*rel
, unsigned long is_local
)
7618 switch (ELF32_R_TYPE (rel
->r_info
))
7621 return bfd_reloc_notsupported
;
7623 case R_ARM_TLS_GOTDESC
:
7628 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7630 insn
-= 5; /* THUMB */
7632 insn
-= 8; /* ARM */
7634 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7635 return bfd_reloc_continue
;
7637 case R_ARM_THM_TLS_DESCSEQ
:
7639 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
);
7640 if ((insn
& 0xff78) == 0x4478) /* add rx, pc */
7644 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7646 else if ((insn
& 0xffc0) == 0x6840) /* ldr rx,[ry,#4] */
7650 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7653 bfd_put_16 (input_bfd
, insn
& 0xf83f, contents
+ rel
->r_offset
);
7655 else if ((insn
& 0xff87) == 0x4780) /* blx rx */
7659 bfd_put_16 (input_bfd
, 0x46c0, contents
+ rel
->r_offset
);
7662 bfd_put_16 (input_bfd
, 0x4600 | (insn
& 0x78),
7663 contents
+ rel
->r_offset
);
7667 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
7668 /* It's a 32 bit instruction, fetch the rest of it for
7669 error generation. */
7671 | bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
+ 2);
7672 (*_bfd_error_handler
)
7673 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' in TLS trampoline"),
7674 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
7675 return bfd_reloc_notsupported
;
7679 case R_ARM_TLS_DESCSEQ
:
7681 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7682 if ((insn
& 0xffff0ff0) == 0xe08f0000) /* add rx,pc,ry */
7686 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xffff),
7687 contents
+ rel
->r_offset
);
7689 else if ((insn
& 0xfff00fff) == 0xe5900004) /* ldr rx,[ry,#4]*/
7693 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
7696 bfd_put_32 (input_bfd
, insn
& 0xfffff000,
7697 contents
+ rel
->r_offset
);
7699 else if ((insn
& 0xfffffff0) == 0xe12fff30) /* blx rx */
7703 bfd_put_32 (input_bfd
, 0xe1a00000, contents
+ rel
->r_offset
);
7706 bfd_put_32 (input_bfd
, 0xe1a00000 | (insn
& 0xf),
7707 contents
+ rel
->r_offset
);
7711 (*_bfd_error_handler
)
7712 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' in TLS trampoline"),
7713 input_bfd
, input_sec
, (unsigned long)rel
->r_offset
, insn
);
7714 return bfd_reloc_notsupported
;
7718 case R_ARM_TLS_CALL
:
7719 /* GD->IE relaxation, turn the instruction into 'nop' or
7720 'ldr r0, [pc,r0]' */
7721 insn
= is_local
? 0xe1a00000 : 0xe79f0000;
7722 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7725 case R_ARM_THM_TLS_CALL
:
7726 /* GD->IE relaxation */
7728 /* add r0,pc; ldr r0, [r0] */
7730 else if (arch_has_thumb2_nop (globals
))
7737 bfd_put_16 (input_bfd
, insn
>> 16, contents
+ rel
->r_offset
);
7738 bfd_put_16 (input_bfd
, insn
& 0xffff, contents
+ rel
->r_offset
+ 2);
7741 return bfd_reloc_ok
;
7744 /* For a given value of n, calculate the value of G_n as required to
7745 deal with group relocations. We return it in the form of an
7746 encoded constant-and-rotation, together with the final residual. If n is
7747 specified as less than zero, then final_residual is filled with the
7748 input value and no further action is performed. */
7751 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
7755 bfd_vma encoded_g_n
= 0;
7756 bfd_vma residual
= value
; /* Also known as Y_n. */
7758 for (current_n
= 0; current_n
<= n
; current_n
++)
7762 /* Calculate which part of the value to mask. */
7769 /* Determine the most significant bit in the residual and
7770 align the resulting value to a 2-bit boundary. */
7771 for (msb
= 30; msb
>= 0; msb
-= 2)
7772 if (residual
& (3 << msb
))
7775 /* The desired shift is now (msb - 6), or zero, whichever
7782 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
7783 g_n
= residual
& (0xff << shift
);
7784 encoded_g_n
= (g_n
>> shift
)
7785 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
7787 /* Calculate the residual for the next time around. */
7791 *final_residual
= residual
;
7796 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
7797 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
7800 identify_add_or_sub (bfd_vma insn
)
7802 int opcode
= insn
& 0x1e00000;
7804 if (opcode
== 1 << 23) /* ADD */
7807 if (opcode
== 1 << 22) /* SUB */
7813 /* Perform a relocation as part of a final link. */
7815 static bfd_reloc_status_type
7816 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
7819 asection
* input_section
,
7820 bfd_byte
* contents
,
7821 Elf_Internal_Rela
* rel
,
7823 struct bfd_link_info
* info
,
7825 const char * sym_name
,
7826 unsigned char st_type
,
7827 enum arm_st_branch_type branch_type
,
7828 struct elf_link_hash_entry
* h
,
7829 bfd_boolean
* unresolved_reloc_p
,
7830 char ** error_message
)
7832 unsigned long r_type
= howto
->type
;
7833 unsigned long r_symndx
;
7834 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
7835 bfd_vma
* local_got_offsets
;
7836 bfd_vma
* local_tlsdesc_gotents
;
7839 asection
* sreloc
= NULL
;
7842 bfd_signed_vma signed_addend
;
7843 unsigned char dynreloc_st_type
;
7844 bfd_vma dynreloc_value
;
7845 struct elf32_arm_link_hash_table
* globals
;
7846 struct elf32_arm_link_hash_entry
*eh
;
7847 union gotplt_union
*root_plt
;
7848 struct arm_plt_info
*arm_plt
;
7850 bfd_vma gotplt_offset
;
7851 bfd_boolean has_iplt_entry
;
7853 globals
= elf32_arm_hash_table (info
);
7854 if (globals
== NULL
)
7855 return bfd_reloc_notsupported
;
7857 BFD_ASSERT (is_arm_elf (input_bfd
));
7859 /* Some relocation types map to different relocations depending on the
7860 target. We pick the right one here. */
7861 r_type
= arm_real_reloc_type (globals
, r_type
);
7863 /* It is possible to have linker relaxations on some TLS access
7864 models. Update our information here. */
7865 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
7867 if (r_type
!= howto
->type
)
7868 howto
= elf32_arm_howto_from_type (r_type
);
7870 /* If the start address has been set, then set the EF_ARM_HASENTRY
7871 flag. Setting this more than once is redundant, but the cost is
7872 not too high, and it keeps the code simple.
7874 The test is done here, rather than somewhere else, because the
7875 start address is only set just before the final link commences.
7877 Note - if the user deliberately sets a start address of 0, the
7878 flag will not be set. */
7879 if (bfd_get_start_address (output_bfd
) != 0)
7880 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
7882 eh
= (struct elf32_arm_link_hash_entry
*) h
;
7883 sgot
= globals
->root
.sgot
;
7884 local_got_offsets
= elf_local_got_offsets (input_bfd
);
7885 local_tlsdesc_gotents
= elf32_arm_local_tlsdesc_gotent (input_bfd
);
7887 if (globals
->root
.dynamic_sections_created
)
7888 srelgot
= globals
->root
.srelgot
;
7892 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7894 if (globals
->use_rel
)
7896 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
7898 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7901 signed_addend
&= ~ howto
->src_mask
;
7902 signed_addend
|= addend
;
7905 signed_addend
= addend
;
7908 addend
= signed_addend
= rel
->r_addend
;
7910 /* Record the symbol information that should be used in dynamic
7912 dynreloc_st_type
= st_type
;
7913 dynreloc_value
= value
;
7914 if (branch_type
== ST_BRANCH_TO_THUMB
)
7915 dynreloc_value
|= 1;
7917 /* Find out whether the symbol has a PLT. Set ST_VALUE, BRANCH_TYPE and
7918 VALUE appropriately for relocations that we resolve at link time. */
7919 has_iplt_entry
= FALSE
;
7920 if (elf32_arm_get_plt_info (input_bfd
, eh
, r_symndx
, &root_plt
, &arm_plt
)
7921 && root_plt
->offset
!= (bfd_vma
) -1)
7923 plt_offset
= root_plt
->offset
;
7924 gotplt_offset
= arm_plt
->got_offset
;
7926 if (h
== NULL
|| eh
->is_iplt
)
7928 has_iplt_entry
= TRUE
;
7929 splt
= globals
->root
.iplt
;
7931 /* Populate .iplt entries here, because not all of them will
7932 be seen by finish_dynamic_symbol. The lower bit is set if
7933 we have already populated the entry. */
7938 elf32_arm_populate_plt_entry (output_bfd
, info
, root_plt
, arm_plt
,
7939 -1, dynreloc_value
);
7940 root_plt
->offset
|= 1;
7943 /* Static relocations always resolve to the .iplt entry. */
7945 value
= (splt
->output_section
->vma
7946 + splt
->output_offset
7948 branch_type
= ST_BRANCH_TO_ARM
;
7950 /* If there are non-call relocations that resolve to the .iplt
7951 entry, then all dynamic ones must too. */
7952 if (arm_plt
->noncall_refcount
!= 0)
7954 dynreloc_st_type
= st_type
;
7955 dynreloc_value
= value
;
7959 /* We populate the .plt entry in finish_dynamic_symbol. */
7960 splt
= globals
->root
.splt
;
7965 plt_offset
= (bfd_vma
) -1;
7966 gotplt_offset
= (bfd_vma
) -1;
7972 /* We don't need to find a value for this symbol. It's just a
7974 *unresolved_reloc_p
= FALSE
;
7975 return bfd_reloc_ok
;
7978 if (!globals
->vxworks_p
)
7979 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
7983 case R_ARM_ABS32_NOI
:
7985 case R_ARM_REL32_NOI
:
7991 /* Handle relocations which should use the PLT entry. ABS32/REL32
7992 will use the symbol's value, which may point to a PLT entry, but we
7993 don't need to handle that here. If we created a PLT entry, all
7994 branches in this object should go to it, except if the PLT is too
7995 far away, in which case a long branch stub should be inserted. */
7996 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
7997 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
7998 && r_type
!= R_ARM_CALL
7999 && r_type
!= R_ARM_JUMP24
8000 && r_type
!= R_ARM_PLT32
)
8001 && plt_offset
!= (bfd_vma
) -1)
8003 /* If we've created a .plt section, and assigned a PLT entry
8004 to this function, it must either be a STT_GNU_IFUNC reference
8005 or not be known to bind locally. In other cases, we should
8006 have cleared the PLT entry by now. */
8007 BFD_ASSERT (has_iplt_entry
|| !SYMBOL_CALLS_LOCAL (info
, h
));
8009 value
= (splt
->output_section
->vma
8010 + splt
->output_offset
8012 *unresolved_reloc_p
= FALSE
;
8013 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8014 contents
, rel
->r_offset
, value
,
8018 /* When generating a shared object or relocatable executable, these
8019 relocations are copied into the output file to be resolved at
8021 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
8022 && (input_section
->flags
& SEC_ALLOC
)
8023 && !(globals
->vxworks_p
8024 && strcmp (input_section
->output_section
->name
,
8026 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
8027 || !SYMBOL_CALLS_LOCAL (info
, h
))
8028 && (!strstr (input_section
->name
, STUB_SUFFIX
))
8030 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8031 || h
->root
.type
!= bfd_link_hash_undefweak
)
8032 && r_type
!= R_ARM_PC24
8033 && r_type
!= R_ARM_CALL
8034 && r_type
!= R_ARM_JUMP24
8035 && r_type
!= R_ARM_PREL31
8036 && r_type
!= R_ARM_PLT32
)
8038 Elf_Internal_Rela outrel
;
8039 bfd_boolean skip
, relocate
;
8041 *unresolved_reloc_p
= FALSE
;
8043 if (sreloc
== NULL
&& globals
->root
.dynamic_sections_created
)
8045 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
8046 ! globals
->use_rel
);
8049 return bfd_reloc_notsupported
;
8055 outrel
.r_addend
= addend
;
8057 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
8059 if (outrel
.r_offset
== (bfd_vma
) -1)
8061 else if (outrel
.r_offset
== (bfd_vma
) -2)
8062 skip
= TRUE
, relocate
= TRUE
;
8063 outrel
.r_offset
+= (input_section
->output_section
->vma
8064 + input_section
->output_offset
);
8067 memset (&outrel
, 0, sizeof outrel
);
8072 || !h
->def_regular
))
8073 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
8078 /* This symbol is local, or marked to become local. */
8079 BFD_ASSERT (r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
);
8080 if (globals
->symbian_p
)
8084 /* On Symbian OS, the data segment and text segement
8085 can be relocated independently. Therefore, we
8086 must indicate the segment to which this
8087 relocation is relative. The BPABI allows us to
8088 use any symbol in the right segment; we just use
8089 the section symbol as it is convenient. (We
8090 cannot use the symbol given by "h" directly as it
8091 will not appear in the dynamic symbol table.)
8093 Note that the dynamic linker ignores the section
8094 symbol value, so we don't subtract osec->vma
8095 from the emitted reloc addend. */
8097 osec
= sym_sec
->output_section
;
8099 osec
= input_section
->output_section
;
8100 symbol
= elf_section_data (osec
)->dynindx
;
8103 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8105 if ((osec
->flags
& SEC_READONLY
) == 0
8106 && htab
->data_index_section
!= NULL
)
8107 osec
= htab
->data_index_section
;
8109 osec
= htab
->text_index_section
;
8110 symbol
= elf_section_data (osec
)->dynindx
;
8112 BFD_ASSERT (symbol
!= 0);
8115 /* On SVR4-ish systems, the dynamic loader cannot
8116 relocate the text and data segments independently,
8117 so the symbol does not matter. */
8119 if (dynreloc_st_type
== STT_GNU_IFUNC
)
8120 /* We have an STT_GNU_IFUNC symbol that doesn't resolve
8121 to the .iplt entry. Instead, every non-call reference
8122 must use an R_ARM_IRELATIVE relocation to obtain the
8123 correct run-time address. */
8124 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_IRELATIVE
);
8126 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
8127 if (globals
->use_rel
)
8130 outrel
.r_addend
+= dynreloc_value
;
8133 elf32_arm_add_dynreloc (output_bfd
, info
, sreloc
, &outrel
);
8135 /* If this reloc is against an external symbol, we do not want to
8136 fiddle with the addend. Otherwise, we need to include the symbol
8137 value so that it becomes an addend for the dynamic reloc. */
8139 return bfd_reloc_ok
;
8141 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8142 contents
, rel
->r_offset
,
8143 dynreloc_value
, (bfd_vma
) 0);
8145 else switch (r_type
)
8148 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
8150 case R_ARM_XPC25
: /* Arm BLX instruction. */
8153 case R_ARM_PC24
: /* Arm B/BL instruction. */
8156 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
8158 if (r_type
== R_ARM_XPC25
)
8160 /* Check for Arm calling Arm function. */
8161 /* FIXME: Should we translate the instruction into a BL
8162 instruction instead ? */
8163 if (branch_type
!= ST_BRANCH_TO_THUMB
)
8164 (*_bfd_error_handler
)
8165 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
8167 h
? h
->root
.root
.string
: "(local)");
8169 else if (r_type
== R_ARM_PC24
)
8171 /* Check for Arm calling Thumb function. */
8172 if (branch_type
== ST_BRANCH_TO_THUMB
)
8174 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
8175 output_bfd
, input_section
,
8176 hit_data
, sym_sec
, rel
->r_offset
,
8177 signed_addend
, value
,
8179 return bfd_reloc_ok
;
8181 return bfd_reloc_dangerous
;
8185 /* Check if a stub has to be inserted because the
8186 destination is too far or we are changing mode. */
8187 if ( r_type
== R_ARM_CALL
8188 || r_type
== R_ARM_JUMP24
8189 || r_type
== R_ARM_PLT32
)
8191 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8192 struct elf32_arm_link_hash_entry
*hash
;
8194 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8195 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8196 st_type
, &branch_type
,
8197 hash
, value
, sym_sec
,
8198 input_bfd
, sym_name
);
8200 if (stub_type
!= arm_stub_none
)
8202 /* The target is out of reach, so redirect the
8203 branch to the local stub for this function. */
8205 stub_entry
= elf32_arm_get_stub_entry (input_section
,
8209 if (stub_entry
!= NULL
)
8210 value
= (stub_entry
->stub_offset
8211 + stub_entry
->stub_sec
->output_offset
8212 + stub_entry
->stub_sec
->output_section
->vma
);
8216 /* If the call goes through a PLT entry, make sure to
8217 check distance to the right destination address. */
8218 if (plt_offset
!= (bfd_vma
) -1)
8220 value
= (splt
->output_section
->vma
8221 + splt
->output_offset
8223 *unresolved_reloc_p
= FALSE
;
8224 /* The PLT entry is in ARM mode, regardless of the
8226 branch_type
= ST_BRANCH_TO_ARM
;
8231 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
8233 S is the address of the symbol in the relocation.
8234 P is address of the instruction being relocated.
8235 A is the addend (extracted from the instruction) in bytes.
8237 S is held in 'value'.
8238 P is the base address of the section containing the
8239 instruction plus the offset of the reloc into that
8241 (input_section->output_section->vma +
8242 input_section->output_offset +
8244 A is the addend, converted into bytes, ie:
8247 Note: None of these operations have knowledge of the pipeline
8248 size of the processor, thus it is up to the assembler to
8249 encode this information into the addend. */
8250 value
-= (input_section
->output_section
->vma
8251 + input_section
->output_offset
);
8252 value
-= rel
->r_offset
;
8253 if (globals
->use_rel
)
8254 value
+= (signed_addend
<< howto
->size
);
8256 /* RELA addends do not have to be adjusted by howto->size. */
8257 value
+= signed_addend
;
8259 signed_addend
= value
;
8260 signed_addend
>>= howto
->rightshift
;
8262 /* A branch to an undefined weak symbol is turned into a jump to
8263 the next instruction unless a PLT entry will be created.
8264 Do the same for local undefined symbols (but not for STN_UNDEF).
8265 The jump to the next instruction is optimized as a NOP depending
8266 on the architecture. */
8267 if (h
? (h
->root
.type
== bfd_link_hash_undefweak
8268 && plt_offset
== (bfd_vma
) -1)
8269 : r_symndx
!= STN_UNDEF
&& bfd_is_und_section (sym_sec
))
8271 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000);
8273 if (arch_has_arm_nop (globals
))
8274 value
|= 0x0320f000;
8276 value
|= 0x01a00000; /* Using pre-UAL nop: mov r0, r0. */
8280 /* Perform a signed range check. */
8281 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
8282 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
8283 return bfd_reloc_overflow
;
8285 addend
= (value
& 2);
8287 value
= (signed_addend
& howto
->dst_mask
)
8288 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
8290 if (r_type
== R_ARM_CALL
)
8292 /* Set the H bit in the BLX instruction. */
8293 if (branch_type
== ST_BRANCH_TO_THUMB
)
8298 value
&= ~(bfd_vma
)(1 << 24);
8301 /* Select the correct instruction (BL or BLX). */
8302 /* Only if we are not handling a BL to a stub. In this
8303 case, mode switching is performed by the stub. */
8304 if (branch_type
== ST_BRANCH_TO_THUMB
&& !stub_entry
)
8308 value
&= ~(bfd_vma
)(1 << 28);
8318 if (branch_type
== ST_BRANCH_TO_THUMB
)
8322 case R_ARM_ABS32_NOI
:
8328 if (branch_type
== ST_BRANCH_TO_THUMB
)
8330 value
-= (input_section
->output_section
->vma
8331 + input_section
->output_offset
+ rel
->r_offset
);
8334 case R_ARM_REL32_NOI
:
8336 value
-= (input_section
->output_section
->vma
8337 + input_section
->output_offset
+ rel
->r_offset
);
8341 value
-= (input_section
->output_section
->vma
8342 + input_section
->output_offset
+ rel
->r_offset
);
8343 value
+= signed_addend
;
8344 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
8346 /* Check for overflow. */
8347 if ((value
^ (value
>> 1)) & (1 << 30))
8348 return bfd_reloc_overflow
;
8350 value
&= 0x7fffffff;
8351 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
8352 if (branch_type
== ST_BRANCH_TO_THUMB
)
8357 bfd_put_32 (input_bfd
, value
, hit_data
);
8358 return bfd_reloc_ok
;
8363 /* There is no way to tell whether the user intended to use a signed or
8364 unsigned addend. When checking for overflow we accept either,
8365 as specified by the AAELF. */
8366 if ((long) value
> 0xff || (long) value
< -0x80)
8367 return bfd_reloc_overflow
;
8369 bfd_put_8 (input_bfd
, value
, hit_data
);
8370 return bfd_reloc_ok
;
8375 /* See comment for R_ARM_ABS8. */
8376 if ((long) value
> 0xffff || (long) value
< -0x8000)
8377 return bfd_reloc_overflow
;
8379 bfd_put_16 (input_bfd
, value
, hit_data
);
8380 return bfd_reloc_ok
;
8382 case R_ARM_THM_ABS5
:
8383 /* Support ldr and str instructions for the thumb. */
8384 if (globals
->use_rel
)
8386 /* Need to refetch addend. */
8387 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
8388 /* ??? Need to determine shift amount from operand size. */
8389 addend
>>= howto
->rightshift
;
8393 /* ??? Isn't value unsigned? */
8394 if ((long) value
> 0x1f || (long) value
< -0x10)
8395 return bfd_reloc_overflow
;
8397 /* ??? Value needs to be properly shifted into place first. */
8398 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
8399 bfd_put_16 (input_bfd
, value
, hit_data
);
8400 return bfd_reloc_ok
;
8402 case R_ARM_THM_ALU_PREL_11_0
:
8403 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
8406 bfd_signed_vma relocation
;
8408 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8409 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8411 if (globals
->use_rel
)
8413 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
8414 | ((insn
& (1 << 26)) >> 15);
8415 if (insn
& 0xf00000)
8416 signed_addend
= -signed_addend
;
8419 relocation
= value
+ signed_addend
;
8420 relocation
-= (input_section
->output_section
->vma
8421 + input_section
->output_offset
8424 value
= abs (relocation
);
8426 if (value
>= 0x1000)
8427 return bfd_reloc_overflow
;
8429 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
8430 | ((value
& 0x700) << 4)
8431 | ((value
& 0x800) << 15);
8435 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8436 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8438 return bfd_reloc_ok
;
8442 /* PR 10073: This reloc is not generated by the GNU toolchain,
8443 but it is supported for compatibility with third party libraries
8444 generated by other compilers, specifically the ARM/IAR. */
8447 bfd_signed_vma relocation
;
8449 insn
= bfd_get_16 (input_bfd
, hit_data
);
8451 if (globals
->use_rel
)
8452 addend
= (insn
& 0x00ff) << 2;
8454 relocation
= value
+ addend
;
8455 relocation
-= (input_section
->output_section
->vma
8456 + input_section
->output_offset
8459 value
= abs (relocation
);
8461 /* We do not check for overflow of this reloc. Although strictly
8462 speaking this is incorrect, it appears to be necessary in order
8463 to work with IAR generated relocs. Since GCC and GAS do not
8464 generate R_ARM_THM_PC8 relocs, the lack of a check should not be
8465 a problem for them. */
8468 insn
= (insn
& 0xff00) | (value
>> 2);
8470 bfd_put_16 (input_bfd
, insn
, hit_data
);
8472 return bfd_reloc_ok
;
8475 case R_ARM_THM_PC12
:
8476 /* Corresponds to: ldr.w reg, [pc, #offset]. */
8479 bfd_signed_vma relocation
;
8481 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
8482 | bfd_get_16 (input_bfd
, hit_data
+ 2);
8484 if (globals
->use_rel
)
8486 signed_addend
= insn
& 0xfff;
8487 if (!(insn
& (1 << 23)))
8488 signed_addend
= -signed_addend
;
8491 relocation
= value
+ signed_addend
;
8492 relocation
-= (input_section
->output_section
->vma
8493 + input_section
->output_offset
8496 value
= abs (relocation
);
8498 if (value
>= 0x1000)
8499 return bfd_reloc_overflow
;
8501 insn
= (insn
& 0xff7ff000) | value
;
8502 if (relocation
>= 0)
8505 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8506 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8508 return bfd_reloc_ok
;
8511 case R_ARM_THM_XPC22
:
8512 case R_ARM_THM_CALL
:
8513 case R_ARM_THM_JUMP24
:
8514 /* Thumb BL (branch long instruction). */
8518 bfd_boolean overflow
= FALSE
;
8519 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
8520 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
8521 bfd_signed_vma reloc_signed_max
;
8522 bfd_signed_vma reloc_signed_min
;
8524 bfd_signed_vma signed_check
;
8526 const int thumb2
= using_thumb2 (globals
);
8528 /* A branch to an undefined weak symbol is turned into a jump to
8529 the next instruction unless a PLT entry will be created.
8530 The jump to the next instruction is optimized as a NOP.W for
8531 Thumb-2 enabled architectures. */
8532 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
8533 && plt_offset
== (bfd_vma
) -1)
8535 if (arch_has_thumb2_nop (globals
))
8537 bfd_put_16 (input_bfd
, 0xf3af, hit_data
);
8538 bfd_put_16 (input_bfd
, 0x8000, hit_data
+ 2);
8542 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
8543 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
8545 return bfd_reloc_ok
;
8548 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
8549 with Thumb-1) involving the J1 and J2 bits. */
8550 if (globals
->use_rel
)
8552 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
8553 bfd_vma upper
= upper_insn
& 0x3ff;
8554 bfd_vma lower
= lower_insn
& 0x7ff;
8555 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
8556 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
8557 bfd_vma i1
= j1
^ s
? 0 : 1;
8558 bfd_vma i2
= j2
^ s
? 0 : 1;
8560 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
8562 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
8564 signed_addend
= addend
;
8567 if (r_type
== R_ARM_THM_XPC22
)
8569 /* Check for Thumb to Thumb call. */
8570 /* FIXME: Should we translate the instruction into a BL
8571 instruction instead ? */
8572 if (branch_type
== ST_BRANCH_TO_THUMB
)
8573 (*_bfd_error_handler
)
8574 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
8576 h
? h
->root
.root
.string
: "(local)");
8580 /* If it is not a call to Thumb, assume call to Arm.
8581 If it is a call relative to a section name, then it is not a
8582 function call at all, but rather a long jump. Calls through
8583 the PLT do not require stubs. */
8584 if (branch_type
== ST_BRANCH_TO_ARM
&& plt_offset
== (bfd_vma
) -1)
8586 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
8588 /* Convert BL to BLX. */
8589 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8591 else if (( r_type
!= R_ARM_THM_CALL
)
8592 && (r_type
!= R_ARM_THM_JUMP24
))
8594 if (elf32_thumb_to_arm_stub
8595 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
8596 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
8598 return bfd_reloc_ok
;
8600 return bfd_reloc_dangerous
;
8603 else if (branch_type
== ST_BRANCH_TO_THUMB
8605 && r_type
== R_ARM_THM_CALL
)
8607 /* Make sure this is a BL. */
8608 lower_insn
|= 0x1800;
8612 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
8613 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
8615 /* Check if a stub has to be inserted because the destination
8617 struct elf32_arm_stub_hash_entry
*stub_entry
;
8618 struct elf32_arm_link_hash_entry
*hash
;
8620 hash
= (struct elf32_arm_link_hash_entry
*) h
;
8622 stub_type
= arm_type_of_stub (info
, input_section
, rel
,
8623 st_type
, &branch_type
,
8624 hash
, value
, sym_sec
,
8625 input_bfd
, sym_name
);
8627 if (stub_type
!= arm_stub_none
)
8629 /* The target is out of reach or we are changing modes, so
8630 redirect the branch to the local stub for this
8632 stub_entry
= elf32_arm_get_stub_entry (input_section
,
8636 if (stub_entry
!= NULL
)
8637 value
= (stub_entry
->stub_offset
8638 + stub_entry
->stub_sec
->output_offset
8639 + stub_entry
->stub_sec
->output_section
->vma
);
8641 /* If this call becomes a call to Arm, force BLX. */
8642 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
8645 && !arm_stub_is_thumb (stub_entry
->stub_type
))
8646 || branch_type
!= ST_BRANCH_TO_THUMB
)
8647 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8652 /* Handle calls via the PLT. */
8653 if (stub_type
== arm_stub_none
&& plt_offset
!= (bfd_vma
) -1)
8655 value
= (splt
->output_section
->vma
8656 + splt
->output_offset
8659 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
8661 /* If the Thumb BLX instruction is available, convert
8662 the BL to a BLX instruction to call the ARM-mode
8664 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
8665 branch_type
= ST_BRANCH_TO_ARM
;
8669 /* Target the Thumb stub before the ARM PLT entry. */
8670 value
-= PLT_THUMB_STUB_SIZE
;
8671 branch_type
= ST_BRANCH_TO_THUMB
;
8673 *unresolved_reloc_p
= FALSE
;
8676 relocation
= value
+ signed_addend
;
8678 relocation
-= (input_section
->output_section
->vma
8679 + input_section
->output_offset
8682 check
= relocation
>> howto
->rightshift
;
8684 /* If this is a signed value, the rightshift just dropped
8685 leading 1 bits (assuming twos complement). */
8686 if ((bfd_signed_vma
) relocation
>= 0)
8687 signed_check
= check
;
8689 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
8691 /* Calculate the permissable maximum and minimum values for
8692 this relocation according to whether we're relocating for
8694 bitsize
= howto
->bitsize
;
8697 reloc_signed_max
= (1 << (bitsize
- 1)) - 1;
8698 reloc_signed_min
= ~reloc_signed_max
;
8700 /* Assumes two's complement. */
8701 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
8704 if ((lower_insn
& 0x5000) == 0x4000)
8705 /* For a BLX instruction, make sure that the relocation is rounded up
8706 to a word boundary. This follows the semantics of the instruction
8707 which specifies that bit 1 of the target address will come from bit
8708 1 of the base address. */
8709 relocation
= (relocation
+ 2) & ~ 3;
8711 /* Put RELOCATION back into the insn. Assumes two's complement.
8712 We use the Thumb-2 encoding, which is safe even if dealing with
8713 a Thumb-1 instruction by virtue of our overflow check above. */
8714 reloc_sign
= (signed_check
< 0) ? 1 : 0;
8715 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
8716 | ((relocation
>> 12) & 0x3ff)
8717 | (reloc_sign
<< 10);
8718 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
8719 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
8720 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
8721 | ((relocation
>> 1) & 0x7ff);
8723 /* Put the relocated value back in the object file: */
8724 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
8725 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
8727 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
8731 case R_ARM_THM_JUMP19
:
8732 /* Thumb32 conditional branch instruction. */
8735 bfd_boolean overflow
= FALSE
;
8736 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
8737 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
8738 bfd_signed_vma reloc_signed_max
= 0xffffe;
8739 bfd_signed_vma reloc_signed_min
= -0x100000;
8740 bfd_signed_vma signed_check
;
8742 /* Need to refetch the addend, reconstruct the top three bits,
8743 and squish the two 11 bit pieces together. */
8744 if (globals
->use_rel
)
8746 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
8747 bfd_vma upper
= (upper_insn
& 0x003f);
8748 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
8749 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
8750 bfd_vma lower
= (lower_insn
& 0x07ff);
8755 upper
-= 0x0100; /* Sign extend. */
8757 addend
= (upper
<< 12) | (lower
<< 1);
8758 signed_addend
= addend
;
8761 /* Handle calls via the PLT. */
8762 if (plt_offset
!= (bfd_vma
) -1)
8764 value
= (splt
->output_section
->vma
8765 + splt
->output_offset
8767 /* Target the Thumb stub before the ARM PLT entry. */
8768 value
-= PLT_THUMB_STUB_SIZE
;
8769 *unresolved_reloc_p
= FALSE
;
8772 /* ??? Should handle interworking? GCC might someday try to
8773 use this for tail calls. */
8775 relocation
= value
+ signed_addend
;
8776 relocation
-= (input_section
->output_section
->vma
8777 + input_section
->output_offset
8779 signed_check
= (bfd_signed_vma
) relocation
;
8781 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
8784 /* Put RELOCATION back into the insn. */
8786 bfd_vma S
= (relocation
& 0x00100000) >> 20;
8787 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
8788 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
8789 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
8790 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
8792 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
8793 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
8796 /* Put the relocated value back in the object file: */
8797 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
8798 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
8800 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
8803 case R_ARM_THM_JUMP11
:
8804 case R_ARM_THM_JUMP8
:
8805 case R_ARM_THM_JUMP6
:
8806 /* Thumb B (branch) instruction). */
8808 bfd_signed_vma relocation
;
8809 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
8810 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
8811 bfd_signed_vma signed_check
;
8813 /* CZB cannot jump backward. */
8814 if (r_type
== R_ARM_THM_JUMP6
)
8815 reloc_signed_min
= 0;
8817 if (globals
->use_rel
)
8819 /* Need to refetch addend. */
8820 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
8821 if (addend
& ((howto
->src_mask
+ 1) >> 1))
8824 signed_addend
&= ~ howto
->src_mask
;
8825 signed_addend
|= addend
;
8828 signed_addend
= addend
;
8829 /* The value in the insn has been right shifted. We need to
8830 undo this, so that we can perform the address calculation
8831 in terms of bytes. */
8832 signed_addend
<<= howto
->rightshift
;
8834 relocation
= value
+ signed_addend
;
8836 relocation
-= (input_section
->output_section
->vma
8837 + input_section
->output_offset
8840 relocation
>>= howto
->rightshift
;
8841 signed_check
= relocation
;
8843 if (r_type
== R_ARM_THM_JUMP6
)
8844 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
8846 relocation
&= howto
->dst_mask
;
8847 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
8849 bfd_put_16 (input_bfd
, relocation
, hit_data
);
8851 /* Assumes two's complement. */
8852 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
8853 return bfd_reloc_overflow
;
8855 return bfd_reloc_ok
;
8858 case R_ARM_ALU_PCREL7_0
:
8859 case R_ARM_ALU_PCREL15_8
:
8860 case R_ARM_ALU_PCREL23_15
:
8865 insn
= bfd_get_32 (input_bfd
, hit_data
);
8866 if (globals
->use_rel
)
8868 /* Extract the addend. */
8869 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
8870 signed_addend
= addend
;
8872 relocation
= value
+ signed_addend
;
8874 relocation
-= (input_section
->output_section
->vma
8875 + input_section
->output_offset
8877 insn
= (insn
& ~0xfff)
8878 | ((howto
->bitpos
<< 7) & 0xf00)
8879 | ((relocation
>> howto
->bitpos
) & 0xff);
8880 bfd_put_32 (input_bfd
, value
, hit_data
);
8882 return bfd_reloc_ok
;
8884 case R_ARM_GNU_VTINHERIT
:
8885 case R_ARM_GNU_VTENTRY
:
8886 return bfd_reloc_ok
;
8888 case R_ARM_GOTOFF32
:
8889 /* Relocation is relative to the start of the
8890 global offset table. */
8892 BFD_ASSERT (sgot
!= NULL
);
8894 return bfd_reloc_notsupported
;
8896 /* If we are addressing a Thumb function, we need to adjust the
8897 address by one, so that attempts to call the function pointer will
8898 correctly interpret it as Thumb code. */
8899 if (branch_type
== ST_BRANCH_TO_THUMB
)
8902 /* Note that sgot->output_offset is not involved in this
8903 calculation. We always want the start of .got. If we
8904 define _GLOBAL_OFFSET_TABLE in a different way, as is
8905 permitted by the ABI, we might have to change this
8907 value
-= sgot
->output_section
->vma
;
8908 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8909 contents
, rel
->r_offset
, value
,
8913 /* Use global offset table as symbol value. */
8914 BFD_ASSERT (sgot
!= NULL
);
8917 return bfd_reloc_notsupported
;
8919 *unresolved_reloc_p
= FALSE
;
8920 value
= sgot
->output_section
->vma
;
8921 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
8922 contents
, rel
->r_offset
, value
,
8926 case R_ARM_GOT_PREL
:
8927 /* Relocation is to the entry for this symbol in the
8928 global offset table. */
8930 return bfd_reloc_notsupported
;
8932 if (dynreloc_st_type
== STT_GNU_IFUNC
8933 && plt_offset
!= (bfd_vma
) -1
8934 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
8936 /* We have a relocation against a locally-binding STT_GNU_IFUNC
8937 symbol, and the relocation resolves directly to the runtime
8938 target rather than to the .iplt entry. This means that any
8939 .got entry would be the same value as the .igot.plt entry,
8940 so there's no point creating both. */
8941 sgot
= globals
->root
.igotplt
;
8942 value
= sgot
->output_offset
+ gotplt_offset
;
8948 off
= h
->got
.offset
;
8949 BFD_ASSERT (off
!= (bfd_vma
) -1);
8952 /* We have already processsed one GOT relocation against
8955 if (globals
->root
.dynamic_sections_created
8956 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
8957 *unresolved_reloc_p
= FALSE
;
8961 Elf_Internal_Rela outrel
;
8963 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8965 /* If the symbol doesn't resolve locally in a static
8966 object, we have an undefined reference. If the
8967 symbol doesn't resolve locally in a dynamic object,
8968 it should be resolved by the dynamic linker. */
8969 if (globals
->root
.dynamic_sections_created
)
8971 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
8972 *unresolved_reloc_p
= FALSE
;
8976 outrel
.r_addend
= 0;
8980 if (dynreloc_st_type
== STT_GNU_IFUNC
)
8981 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
8982 else if (info
->shared
)
8983 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
8986 outrel
.r_addend
= dynreloc_value
;
8989 /* The GOT entry is initialized to zero by default.
8990 See if we should install a different value. */
8991 if (outrel
.r_addend
!= 0
8992 && (outrel
.r_info
== 0 || globals
->use_rel
))
8994 bfd_put_32 (output_bfd
, outrel
.r_addend
,
8995 sgot
->contents
+ off
);
8996 outrel
.r_addend
= 0;
8999 if (outrel
.r_info
!= 0)
9001 outrel
.r_offset
= (sgot
->output_section
->vma
9002 + sgot
->output_offset
9004 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9008 value
= sgot
->output_offset
+ off
;
9014 BFD_ASSERT (local_got_offsets
!= NULL
&&
9015 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
9017 off
= local_got_offsets
[r_symndx
];
9019 /* The offset must always be a multiple of 4. We use the
9020 least significant bit to record whether we have already
9021 generated the necessary reloc. */
9026 if (globals
->use_rel
)
9027 bfd_put_32 (output_bfd
, dynreloc_value
, sgot
->contents
+ off
);
9029 if (info
->shared
|| dynreloc_st_type
== STT_GNU_IFUNC
)
9031 Elf_Internal_Rela outrel
;
9033 outrel
.r_addend
= addend
+ dynreloc_value
;
9034 outrel
.r_offset
= (sgot
->output_section
->vma
9035 + sgot
->output_offset
9037 if (dynreloc_st_type
== STT_GNU_IFUNC
)
9038 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_IRELATIVE
);
9040 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
9041 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9044 local_got_offsets
[r_symndx
] |= 1;
9047 value
= sgot
->output_offset
+ off
;
9049 if (r_type
!= R_ARM_GOT32
)
9050 value
+= sgot
->output_section
->vma
;
9052 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9053 contents
, rel
->r_offset
, value
,
9056 case R_ARM_TLS_LDO32
:
9057 value
= value
- dtpoff_base (info
);
9059 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9060 contents
, rel
->r_offset
, value
,
9063 case R_ARM_TLS_LDM32
:
9070 off
= globals
->tls_ldm_got
.offset
;
9076 /* If we don't know the module number, create a relocation
9080 Elf_Internal_Rela outrel
;
9082 if (srelgot
== NULL
)
9085 outrel
.r_addend
= 0;
9086 outrel
.r_offset
= (sgot
->output_section
->vma
9087 + sgot
->output_offset
+ off
);
9088 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
9090 if (globals
->use_rel
)
9091 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9092 sgot
->contents
+ off
);
9094 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9097 bfd_put_32 (output_bfd
, 1, sgot
->contents
+ off
);
9099 globals
->tls_ldm_got
.offset
|= 1;
9102 value
= sgot
->output_section
->vma
+ sgot
->output_offset
+ off
9103 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
9105 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9106 contents
, rel
->r_offset
, value
,
9110 case R_ARM_TLS_CALL
:
9111 case R_ARM_THM_TLS_CALL
:
9112 case R_ARM_TLS_GD32
:
9113 case R_ARM_TLS_IE32
:
9114 case R_ARM_TLS_GOTDESC
:
9115 case R_ARM_TLS_DESCSEQ
:
9116 case R_ARM_THM_TLS_DESCSEQ
:
9118 bfd_vma off
, offplt
;
9122 BFD_ASSERT (sgot
!= NULL
);
9127 dyn
= globals
->root
.dynamic_sections_created
;
9128 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
9130 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9132 *unresolved_reloc_p
= FALSE
;
9135 off
= h
->got
.offset
;
9136 offplt
= elf32_arm_hash_entry (h
)->tlsdesc_got
;
9137 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
9141 BFD_ASSERT (local_got_offsets
!= NULL
);
9142 off
= local_got_offsets
[r_symndx
];
9143 offplt
= local_tlsdesc_gotents
[r_symndx
];
9144 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
9147 /* Linker relaxations happens from one of the
9148 R_ARM_{GOTDESC,CALL,DESCSEQ} relocations to IE or LE. */
9149 if (ELF32_R_TYPE(rel
->r_info
) != r_type
)
9150 tls_type
= GOT_TLS_IE
;
9152 BFD_ASSERT (tls_type
!= GOT_UNKNOWN
);
9158 bfd_boolean need_relocs
= FALSE
;
9159 Elf_Internal_Rela outrel
;
9162 /* The GOT entries have not been initialized yet. Do it
9163 now, and emit any relocations. If both an IE GOT and a
9164 GD GOT are necessary, we emit the GD first. */
9166 if ((info
->shared
|| indx
!= 0)
9168 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9169 || h
->root
.type
!= bfd_link_hash_undefweak
))
9172 BFD_ASSERT (srelgot
!= NULL
);
9175 if (tls_type
& GOT_TLS_GDESC
)
9179 /* We should have relaxed, unless this is an undefined
9181 BFD_ASSERT ((h
&& (h
->root
.type
== bfd_link_hash_undefweak
))
9183 BFD_ASSERT (globals
->sgotplt_jump_table_size
+ offplt
+ 8
9184 <= globals
->root
.sgotplt
->size
);
9186 outrel
.r_addend
= 0;
9187 outrel
.r_offset
= (globals
->root
.sgotplt
->output_section
->vma
9188 + globals
->root
.sgotplt
->output_offset
9190 + globals
->sgotplt_jump_table_size
);
9192 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DESC
);
9193 sreloc
= globals
->root
.srelplt
;
9194 loc
= sreloc
->contents
;
9195 loc
+= globals
->next_tls_desc_index
++ * RELOC_SIZE (globals
);
9196 BFD_ASSERT (loc
+ RELOC_SIZE (globals
)
9197 <= sreloc
->contents
+ sreloc
->size
);
9199 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
9201 /* For globals, the first word in the relocation gets
9202 the relocation index and the top bit set, or zero,
9203 if we're binding now. For locals, it gets the
9204 symbol's offset in the tls section. */
9205 bfd_put_32 (output_bfd
,
9206 !h
? value
- elf_hash_table (info
)->tls_sec
->vma
9207 : info
->flags
& DF_BIND_NOW
? 0
9208 : 0x80000000 | ELF32_R_SYM (outrel
.r_info
),
9209 globals
->root
.sgotplt
->contents
+ offplt
+
9210 globals
->sgotplt_jump_table_size
);
9212 /* Second word in the relocation is always zero. */
9213 bfd_put_32 (output_bfd
, 0,
9214 globals
->root
.sgotplt
->contents
+ offplt
+
9215 globals
->sgotplt_jump_table_size
+ 4);
9217 if (tls_type
& GOT_TLS_GD
)
9221 outrel
.r_addend
= 0;
9222 outrel
.r_offset
= (sgot
->output_section
->vma
9223 + sgot
->output_offset
9225 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
9227 if (globals
->use_rel
)
9228 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9229 sgot
->contents
+ cur_off
);
9231 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9234 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9235 sgot
->contents
+ cur_off
+ 4);
9238 outrel
.r_addend
= 0;
9239 outrel
.r_info
= ELF32_R_INFO (indx
,
9240 R_ARM_TLS_DTPOFF32
);
9241 outrel
.r_offset
+= 4;
9243 if (globals
->use_rel
)
9244 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9245 sgot
->contents
+ cur_off
+ 4);
9247 elf32_arm_add_dynreloc (output_bfd
, info
,
9253 /* If we are not emitting relocations for a
9254 general dynamic reference, then we must be in a
9255 static link or an executable link with the
9256 symbol binding locally. Mark it as belonging
9257 to module 1, the executable. */
9258 bfd_put_32 (output_bfd
, 1,
9259 sgot
->contents
+ cur_off
);
9260 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
9261 sgot
->contents
+ cur_off
+ 4);
9267 if (tls_type
& GOT_TLS_IE
)
9272 outrel
.r_addend
= value
- dtpoff_base (info
);
9274 outrel
.r_addend
= 0;
9275 outrel
.r_offset
= (sgot
->output_section
->vma
9276 + sgot
->output_offset
9278 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
9280 if (globals
->use_rel
)
9281 bfd_put_32 (output_bfd
, outrel
.r_addend
,
9282 sgot
->contents
+ cur_off
);
9284 elf32_arm_add_dynreloc (output_bfd
, info
, srelgot
, &outrel
);
9287 bfd_put_32 (output_bfd
, tpoff (info
, value
),
9288 sgot
->contents
+ cur_off
);
9295 local_got_offsets
[r_symndx
] |= 1;
9298 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
9300 else if (tls_type
& GOT_TLS_GDESC
)
9303 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
9304 || ELF32_R_TYPE(rel
->r_info
) == R_ARM_THM_TLS_CALL
)
9306 bfd_signed_vma offset
;
9307 enum elf32_arm_stub_type stub_type
9308 = arm_type_of_stub (info
, input_section
, rel
,
9309 st_type
, &branch_type
,
9310 (struct elf32_arm_link_hash_entry
*)h
,
9311 globals
->tls_trampoline
, globals
->root
.splt
,
9312 input_bfd
, sym_name
);
9314 if (stub_type
!= arm_stub_none
)
9316 struct elf32_arm_stub_hash_entry
*stub_entry
9317 = elf32_arm_get_stub_entry
9318 (input_section
, globals
->root
.splt
, 0, rel
,
9319 globals
, stub_type
);
9320 offset
= (stub_entry
->stub_offset
9321 + stub_entry
->stub_sec
->output_offset
9322 + stub_entry
->stub_sec
->output_section
->vma
);
9325 offset
= (globals
->root
.splt
->output_section
->vma
9326 + globals
->root
.splt
->output_offset
9327 + globals
->tls_trampoline
);
9329 if (ELF32_R_TYPE(rel
->r_info
) == R_ARM_TLS_CALL
)
9333 offset
-= (input_section
->output_section
->vma
+
9334 input_section
->output_offset
+ rel
->r_offset
+ 8);
9338 value
= inst
| (globals
->use_blx
? 0xfa000000 : 0xeb000000);
9342 /* Thumb blx encodes the offset in a complicated
9344 unsigned upper_insn
, lower_insn
;
9347 offset
-= (input_section
->output_section
->vma
+
9348 input_section
->output_offset
9349 + rel
->r_offset
+ 4);
9351 /* Round up the offset to a word boundary */
9352 offset
= (offset
+ 2) & ~2;
9354 upper_insn
= (0xf000
9355 | ((offset
>> 12) & 0x3ff)
9357 lower_insn
= (0xc000
9358 | (((!((offset
>> 23) & 1)) ^ neg
) << 13)
9359 | (((!((offset
>> 22) & 1)) ^ neg
) << 11)
9360 | ((offset
>> 1) & 0x7ff));
9361 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
9362 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
9363 return bfd_reloc_ok
;
9366 /* These relocations needs special care, as besides the fact
9367 they point somewhere in .gotplt, the addend must be
9368 adjusted accordingly depending on the type of instruction
9370 else if ((r_type
== R_ARM_TLS_GOTDESC
) && (tls_type
& GOT_TLS_GDESC
))
9372 unsigned long data
, insn
;
9375 data
= bfd_get_32 (input_bfd
, hit_data
);
9381 insn
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
- data
);
9382 if ((insn
& 0xf000) == 0xf000 || (insn
& 0xf800) == 0xe800)
9384 | bfd_get_16 (input_bfd
,
9385 contents
+ rel
->r_offset
- data
+ 2);
9386 if ((insn
& 0xf800c000) == 0xf000c000)
9389 else if ((insn
& 0xffffff00) == 0x4400)
9394 (*_bfd_error_handler
)
9395 (_("%B(%A+0x%lx):unexpected Thumb instruction '0x%x' referenced by TLS_GOTDESC"),
9396 input_bfd
, input_section
,
9397 (unsigned long)rel
->r_offset
, insn
);
9398 return bfd_reloc_notsupported
;
9403 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- data
);
9408 case 0xfa: /* blx */
9412 case 0xe0: /* add */
9417 (*_bfd_error_handler
)
9418 (_("%B(%A+0x%lx):unexpected ARM instruction '0x%x' referenced by TLS_GOTDESC"),
9419 input_bfd
, input_section
,
9420 (unsigned long)rel
->r_offset
, insn
);
9421 return bfd_reloc_notsupported
;
9425 value
+= ((globals
->root
.sgotplt
->output_section
->vma
9426 + globals
->root
.sgotplt
->output_offset
+ off
)
9427 - (input_section
->output_section
->vma
9428 + input_section
->output_offset
9430 + globals
->sgotplt_jump_table_size
);
9433 value
= ((globals
->root
.sgot
->output_section
->vma
9434 + globals
->root
.sgot
->output_offset
+ off
)
9435 - (input_section
->output_section
->vma
9436 + input_section
->output_offset
+ rel
->r_offset
));
9438 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9439 contents
, rel
->r_offset
, value
,
9443 case R_ARM_TLS_LE32
:
9446 (*_bfd_error_handler
)
9447 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
9448 input_bfd
, input_section
,
9449 (long) rel
->r_offset
, howto
->name
);
9450 return (bfd_reloc_status_type
) FALSE
;
9453 value
= tpoff (info
, value
);
9455 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
9456 contents
, rel
->r_offset
, value
,
9460 if (globals
->fix_v4bx
)
9462 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9464 /* Ensure that we have a BX instruction. */
9465 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
9467 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
9469 /* Branch to veneer. */
9471 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
9472 glue_addr
-= input_section
->output_section
->vma
9473 + input_section
->output_offset
9474 + rel
->r_offset
+ 8;
9475 insn
= (insn
& 0xf0000000) | 0x0a000000
9476 | ((glue_addr
>> 2) & 0x00ffffff);
9480 /* Preserve Rm (lowest four bits) and the condition code
9481 (highest four bits). Other bits encode MOV PC,Rm. */
9482 insn
= (insn
& 0xf000000f) | 0x01a0f000;
9485 bfd_put_32 (input_bfd
, insn
, hit_data
);
9487 return bfd_reloc_ok
;
9489 case R_ARM_MOVW_ABS_NC
:
9490 case R_ARM_MOVT_ABS
:
9491 case R_ARM_MOVW_PREL_NC
:
9492 case R_ARM_MOVT_PREL
:
9493 /* Until we properly support segment-base-relative addressing then
9494 we assume the segment base to be zero, as for the group relocations.
9495 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
9496 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
9497 case R_ARM_MOVW_BREL_NC
:
9498 case R_ARM_MOVW_BREL
:
9499 case R_ARM_MOVT_BREL
:
9501 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9503 if (globals
->use_rel
)
9505 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
9506 signed_addend
= (addend
^ 0x8000) - 0x8000;
9509 value
+= signed_addend
;
9511 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
9512 value
-= (input_section
->output_section
->vma
9513 + input_section
->output_offset
+ rel
->r_offset
);
9515 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
9516 return bfd_reloc_overflow
;
9518 if (branch_type
== ST_BRANCH_TO_THUMB
)
9521 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
9522 || r_type
== R_ARM_MOVT_BREL
)
9526 insn
|= value
& 0xfff;
9527 insn
|= (value
& 0xf000) << 4;
9528 bfd_put_32 (input_bfd
, insn
, hit_data
);
9530 return bfd_reloc_ok
;
9532 case R_ARM_THM_MOVW_ABS_NC
:
9533 case R_ARM_THM_MOVT_ABS
:
9534 case R_ARM_THM_MOVW_PREL_NC
:
9535 case R_ARM_THM_MOVT_PREL
:
9536 /* Until we properly support segment-base-relative addressing then
9537 we assume the segment base to be zero, as for the above relocations.
9538 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
9539 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
9540 as R_ARM_THM_MOVT_ABS. */
9541 case R_ARM_THM_MOVW_BREL_NC
:
9542 case R_ARM_THM_MOVW_BREL
:
9543 case R_ARM_THM_MOVT_BREL
:
9547 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
9548 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
9550 if (globals
->use_rel
)
9552 addend
= ((insn
>> 4) & 0xf000)
9553 | ((insn
>> 15) & 0x0800)
9554 | ((insn
>> 4) & 0x0700)
9556 signed_addend
= (addend
^ 0x8000) - 0x8000;
9559 value
+= signed_addend
;
9561 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
9562 value
-= (input_section
->output_section
->vma
9563 + input_section
->output_offset
+ rel
->r_offset
);
9565 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
9566 return bfd_reloc_overflow
;
9568 if (branch_type
== ST_BRANCH_TO_THUMB
)
9571 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
9572 || r_type
== R_ARM_THM_MOVT_BREL
)
9576 insn
|= (value
& 0xf000) << 4;
9577 insn
|= (value
& 0x0800) << 15;
9578 insn
|= (value
& 0x0700) << 4;
9579 insn
|= (value
& 0x00ff);
9581 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
9582 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
9584 return bfd_reloc_ok
;
9586 case R_ARM_ALU_PC_G0_NC
:
9587 case R_ARM_ALU_PC_G1_NC
:
9588 case R_ARM_ALU_PC_G0
:
9589 case R_ARM_ALU_PC_G1
:
9590 case R_ARM_ALU_PC_G2
:
9591 case R_ARM_ALU_SB_G0_NC
:
9592 case R_ARM_ALU_SB_G1_NC
:
9593 case R_ARM_ALU_SB_G0
:
9594 case R_ARM_ALU_SB_G1
:
9595 case R_ARM_ALU_SB_G2
:
9597 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9598 bfd_vma pc
= input_section
->output_section
->vma
9599 + input_section
->output_offset
+ rel
->r_offset
;
9600 /* sb should be the origin of the *segment* containing the symbol.
9601 It is not clear how to obtain this OS-dependent value, so we
9602 make an arbitrary choice of zero. */
9606 bfd_signed_vma signed_value
;
9609 /* Determine which group of bits to select. */
9612 case R_ARM_ALU_PC_G0_NC
:
9613 case R_ARM_ALU_PC_G0
:
9614 case R_ARM_ALU_SB_G0_NC
:
9615 case R_ARM_ALU_SB_G0
:
9619 case R_ARM_ALU_PC_G1_NC
:
9620 case R_ARM_ALU_PC_G1
:
9621 case R_ARM_ALU_SB_G1_NC
:
9622 case R_ARM_ALU_SB_G1
:
9626 case R_ARM_ALU_PC_G2
:
9627 case R_ARM_ALU_SB_G2
:
9635 /* If REL, extract the addend from the insn. If RELA, it will
9636 have already been fetched for us. */
9637 if (globals
->use_rel
)
9640 bfd_vma constant
= insn
& 0xff;
9641 bfd_vma rotation
= (insn
& 0xf00) >> 8;
9644 signed_addend
= constant
;
9647 /* Compensate for the fact that in the instruction, the
9648 rotation is stored in multiples of 2 bits. */
9651 /* Rotate "constant" right by "rotation" bits. */
9652 signed_addend
= (constant
>> rotation
) |
9653 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
9656 /* Determine if the instruction is an ADD or a SUB.
9657 (For REL, this determines the sign of the addend.) */
9658 negative
= identify_add_or_sub (insn
);
9661 (*_bfd_error_handler
)
9662 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
9663 input_bfd
, input_section
,
9664 (long) rel
->r_offset
, howto
->name
);
9665 return bfd_reloc_overflow
;
9668 signed_addend
*= negative
;
9671 /* Compute the value (X) to go in the place. */
9672 if (r_type
== R_ARM_ALU_PC_G0_NC
9673 || r_type
== R_ARM_ALU_PC_G1_NC
9674 || r_type
== R_ARM_ALU_PC_G0
9675 || r_type
== R_ARM_ALU_PC_G1
9676 || r_type
== R_ARM_ALU_PC_G2
)
9678 signed_value
= value
- pc
+ signed_addend
;
9680 /* Section base relative. */
9681 signed_value
= value
- sb
+ signed_addend
;
9683 /* If the target symbol is a Thumb function, then set the
9684 Thumb bit in the address. */
9685 if (branch_type
== ST_BRANCH_TO_THUMB
)
9688 /* Calculate the value of the relevant G_n, in encoded
9689 constant-with-rotation format. */
9690 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
9693 /* Check for overflow if required. */
9694 if ((r_type
== R_ARM_ALU_PC_G0
9695 || r_type
== R_ARM_ALU_PC_G1
9696 || r_type
== R_ARM_ALU_PC_G2
9697 || r_type
== R_ARM_ALU_SB_G0
9698 || r_type
== R_ARM_ALU_SB_G1
9699 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
9701 (*_bfd_error_handler
)
9702 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9703 input_bfd
, input_section
,
9704 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
9705 return bfd_reloc_overflow
;
9708 /* Mask out the value and the ADD/SUB part of the opcode; take care
9709 not to destroy the S bit. */
9712 /* Set the opcode according to whether the value to go in the
9713 place is negative. */
9714 if (signed_value
< 0)
9719 /* Encode the offset. */
9722 bfd_put_32 (input_bfd
, insn
, hit_data
);
9724 return bfd_reloc_ok
;
9726 case R_ARM_LDR_PC_G0
:
9727 case R_ARM_LDR_PC_G1
:
9728 case R_ARM_LDR_PC_G2
:
9729 case R_ARM_LDR_SB_G0
:
9730 case R_ARM_LDR_SB_G1
:
9731 case R_ARM_LDR_SB_G2
:
9733 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9734 bfd_vma pc
= input_section
->output_section
->vma
9735 + input_section
->output_offset
+ rel
->r_offset
;
9736 bfd_vma sb
= 0; /* See note above. */
9738 bfd_signed_vma signed_value
;
9741 /* Determine which groups of bits to calculate. */
9744 case R_ARM_LDR_PC_G0
:
9745 case R_ARM_LDR_SB_G0
:
9749 case R_ARM_LDR_PC_G1
:
9750 case R_ARM_LDR_SB_G1
:
9754 case R_ARM_LDR_PC_G2
:
9755 case R_ARM_LDR_SB_G2
:
9763 /* If REL, extract the addend from the insn. If RELA, it will
9764 have already been fetched for us. */
9765 if (globals
->use_rel
)
9767 int negative
= (insn
& (1 << 23)) ? 1 : -1;
9768 signed_addend
= negative
* (insn
& 0xfff);
9771 /* Compute the value (X) to go in the place. */
9772 if (r_type
== R_ARM_LDR_PC_G0
9773 || r_type
== R_ARM_LDR_PC_G1
9774 || r_type
== R_ARM_LDR_PC_G2
)
9776 signed_value
= value
- pc
+ signed_addend
;
9778 /* Section base relative. */
9779 signed_value
= value
- sb
+ signed_addend
;
9781 /* Calculate the value of the relevant G_{n-1} to obtain
9782 the residual at that stage. */
9783 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
9785 /* Check for overflow. */
9786 if (residual
>= 0x1000)
9788 (*_bfd_error_handler
)
9789 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9790 input_bfd
, input_section
,
9791 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
9792 return bfd_reloc_overflow
;
9795 /* Mask out the value and U bit. */
9798 /* Set the U bit if the value to go in the place is non-negative. */
9799 if (signed_value
>= 0)
9802 /* Encode the offset. */
9805 bfd_put_32 (input_bfd
, insn
, hit_data
);
9807 return bfd_reloc_ok
;
9809 case R_ARM_LDRS_PC_G0
:
9810 case R_ARM_LDRS_PC_G1
:
9811 case R_ARM_LDRS_PC_G2
:
9812 case R_ARM_LDRS_SB_G0
:
9813 case R_ARM_LDRS_SB_G1
:
9814 case R_ARM_LDRS_SB_G2
:
9816 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9817 bfd_vma pc
= input_section
->output_section
->vma
9818 + input_section
->output_offset
+ rel
->r_offset
;
9819 bfd_vma sb
= 0; /* See note above. */
9821 bfd_signed_vma signed_value
;
9824 /* Determine which groups of bits to calculate. */
9827 case R_ARM_LDRS_PC_G0
:
9828 case R_ARM_LDRS_SB_G0
:
9832 case R_ARM_LDRS_PC_G1
:
9833 case R_ARM_LDRS_SB_G1
:
9837 case R_ARM_LDRS_PC_G2
:
9838 case R_ARM_LDRS_SB_G2
:
9846 /* If REL, extract the addend from the insn. If RELA, it will
9847 have already been fetched for us. */
9848 if (globals
->use_rel
)
9850 int negative
= (insn
& (1 << 23)) ? 1 : -1;
9851 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
9854 /* Compute the value (X) to go in the place. */
9855 if (r_type
== R_ARM_LDRS_PC_G0
9856 || r_type
== R_ARM_LDRS_PC_G1
9857 || r_type
== R_ARM_LDRS_PC_G2
)
9859 signed_value
= value
- pc
+ signed_addend
;
9861 /* Section base relative. */
9862 signed_value
= value
- sb
+ signed_addend
;
9864 /* Calculate the value of the relevant G_{n-1} to obtain
9865 the residual at that stage. */
9866 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
9868 /* Check for overflow. */
9869 if (residual
>= 0x100)
9871 (*_bfd_error_handler
)
9872 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9873 input_bfd
, input_section
,
9874 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
9875 return bfd_reloc_overflow
;
9878 /* Mask out the value and U bit. */
9881 /* Set the U bit if the value to go in the place is non-negative. */
9882 if (signed_value
>= 0)
9885 /* Encode the offset. */
9886 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
9888 bfd_put_32 (input_bfd
, insn
, hit_data
);
9890 return bfd_reloc_ok
;
9892 case R_ARM_LDC_PC_G0
:
9893 case R_ARM_LDC_PC_G1
:
9894 case R_ARM_LDC_PC_G2
:
9895 case R_ARM_LDC_SB_G0
:
9896 case R_ARM_LDC_SB_G1
:
9897 case R_ARM_LDC_SB_G2
:
9899 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
9900 bfd_vma pc
= input_section
->output_section
->vma
9901 + input_section
->output_offset
+ rel
->r_offset
;
9902 bfd_vma sb
= 0; /* See note above. */
9904 bfd_signed_vma signed_value
;
9907 /* Determine which groups of bits to calculate. */
9910 case R_ARM_LDC_PC_G0
:
9911 case R_ARM_LDC_SB_G0
:
9915 case R_ARM_LDC_PC_G1
:
9916 case R_ARM_LDC_SB_G1
:
9920 case R_ARM_LDC_PC_G2
:
9921 case R_ARM_LDC_SB_G2
:
9929 /* If REL, extract the addend from the insn. If RELA, it will
9930 have already been fetched for us. */
9931 if (globals
->use_rel
)
9933 int negative
= (insn
& (1 << 23)) ? 1 : -1;
9934 signed_addend
= negative
* ((insn
& 0xff) << 2);
9937 /* Compute the value (X) to go in the place. */
9938 if (r_type
== R_ARM_LDC_PC_G0
9939 || r_type
== R_ARM_LDC_PC_G1
9940 || r_type
== R_ARM_LDC_PC_G2
)
9942 signed_value
= value
- pc
+ signed_addend
;
9944 /* Section base relative. */
9945 signed_value
= value
- sb
+ signed_addend
;
9947 /* Calculate the value of the relevant G_{n-1} to obtain
9948 the residual at that stage. */
9949 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
9951 /* Check for overflow. (The absolute value to go in the place must be
9952 divisible by four and, after having been divided by four, must
9953 fit in eight bits.) */
9954 if ((residual
& 0x3) != 0 || residual
>= 0x400)
9956 (*_bfd_error_handler
)
9957 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
9958 input_bfd
, input_section
,
9959 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
9960 return bfd_reloc_overflow
;
9963 /* Mask out the value and U bit. */
9966 /* Set the U bit if the value to go in the place is non-negative. */
9967 if (signed_value
>= 0)
9970 /* Encode the offset. */
9971 insn
|= residual
>> 2;
9973 bfd_put_32 (input_bfd
, insn
, hit_data
);
9975 return bfd_reloc_ok
;
9978 return bfd_reloc_notsupported
;
9982 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
9984 arm_add_to_rel (bfd
* abfd
,
9986 reloc_howto_type
* howto
,
9987 bfd_signed_vma increment
)
9989 bfd_signed_vma addend
;
9991 if (howto
->type
== R_ARM_THM_CALL
9992 || howto
->type
== R_ARM_THM_JUMP24
)
9994 int upper_insn
, lower_insn
;
9997 upper_insn
= bfd_get_16 (abfd
, address
);
9998 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
9999 upper
= upper_insn
& 0x7ff;
10000 lower
= lower_insn
& 0x7ff;
10002 addend
= (upper
<< 12) | (lower
<< 1);
10003 addend
+= increment
;
10006 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
10007 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
10009 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
10010 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
10016 contents
= bfd_get_32 (abfd
, address
);
10018 /* Get the (signed) value from the instruction. */
10019 addend
= contents
& howto
->src_mask
;
10020 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10022 bfd_signed_vma mask
;
10025 mask
&= ~ howto
->src_mask
;
10029 /* Add in the increment, (which is a byte value). */
10030 switch (howto
->type
)
10033 addend
+= increment
;
10040 addend
<<= howto
->size
;
10041 addend
+= increment
;
10043 /* Should we check for overflow here ? */
10045 /* Drop any undesired bits. */
10046 addend
>>= howto
->rightshift
;
10050 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
10052 bfd_put_32 (abfd
, contents
, address
);
10056 #define IS_ARM_TLS_RELOC(R_TYPE) \
10057 ((R_TYPE) == R_ARM_TLS_GD32 \
10058 || (R_TYPE) == R_ARM_TLS_LDO32 \
10059 || (R_TYPE) == R_ARM_TLS_LDM32 \
10060 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
10061 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
10062 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
10063 || (R_TYPE) == R_ARM_TLS_LE32 \
10064 || (R_TYPE) == R_ARM_TLS_IE32 \
10065 || IS_ARM_TLS_GNU_RELOC (R_TYPE))
10067 /* Specific set of relocations for the gnu tls dialect. */
10068 #define IS_ARM_TLS_GNU_RELOC(R_TYPE) \
10069 ((R_TYPE) == R_ARM_TLS_GOTDESC \
10070 || (R_TYPE) == R_ARM_TLS_CALL \
10071 || (R_TYPE) == R_ARM_THM_TLS_CALL \
10072 || (R_TYPE) == R_ARM_TLS_DESCSEQ \
10073 || (R_TYPE) == R_ARM_THM_TLS_DESCSEQ)
10075 /* Relocate an ARM ELF section. */
10078 elf32_arm_relocate_section (bfd
* output_bfd
,
10079 struct bfd_link_info
* info
,
10081 asection
* input_section
,
10082 bfd_byte
* contents
,
10083 Elf_Internal_Rela
* relocs
,
10084 Elf_Internal_Sym
* local_syms
,
10085 asection
** local_sections
)
10087 Elf_Internal_Shdr
*symtab_hdr
;
10088 struct elf_link_hash_entry
**sym_hashes
;
10089 Elf_Internal_Rela
*rel
;
10090 Elf_Internal_Rela
*relend
;
10092 struct elf32_arm_link_hash_table
* globals
;
10094 globals
= elf32_arm_hash_table (info
);
10095 if (globals
== NULL
)
10098 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
10099 sym_hashes
= elf_sym_hashes (input_bfd
);
10102 relend
= relocs
+ input_section
->reloc_count
;
10103 for (; rel
< relend
; rel
++)
10106 reloc_howto_type
* howto
;
10107 unsigned long r_symndx
;
10108 Elf_Internal_Sym
* sym
;
10110 struct elf_link_hash_entry
* h
;
10111 bfd_vma relocation
;
10112 bfd_reloc_status_type r
;
10115 bfd_boolean unresolved_reloc
= FALSE
;
10116 char *error_message
= NULL
;
10118 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10119 r_type
= ELF32_R_TYPE (rel
->r_info
);
10120 r_type
= arm_real_reloc_type (globals
, r_type
);
10122 if ( r_type
== R_ARM_GNU_VTENTRY
10123 || r_type
== R_ARM_GNU_VTINHERIT
)
10126 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
10127 howto
= bfd_reloc
.howto
;
10133 if (r_symndx
< symtab_hdr
->sh_info
)
10135 sym
= local_syms
+ r_symndx
;
10136 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
10137 sec
= local_sections
[r_symndx
];
10139 /* An object file might have a reference to a local
10140 undefined symbol. This is a daft object file, but we
10141 should at least do something about it. V4BX & NONE
10142 relocations do not use the symbol and are explicitly
10143 allowed to use the undefined symbol, so allow those.
10144 Likewise for relocations against STN_UNDEF. */
10145 if (r_type
!= R_ARM_V4BX
10146 && r_type
!= R_ARM_NONE
10147 && r_symndx
!= STN_UNDEF
10148 && bfd_is_und_section (sec
)
10149 && ELF_ST_BIND (sym
->st_info
) != STB_WEAK
)
10151 if (!info
->callbacks
->undefined_symbol
10152 (info
, bfd_elf_string_from_elf_section
10153 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
),
10154 input_bfd
, input_section
,
10155 rel
->r_offset
, TRUE
))
10159 if (globals
->use_rel
)
10161 relocation
= (sec
->output_section
->vma
10162 + sec
->output_offset
10164 if (!info
->relocatable
10165 && (sec
->flags
& SEC_MERGE
)
10166 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10169 bfd_vma addend
, value
;
10173 case R_ARM_MOVW_ABS_NC
:
10174 case R_ARM_MOVT_ABS
:
10175 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10176 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
10177 addend
= (addend
^ 0x8000) - 0x8000;
10180 case R_ARM_THM_MOVW_ABS_NC
:
10181 case R_ARM_THM_MOVT_ABS
:
10182 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
10184 value
|= bfd_get_16 (input_bfd
,
10185 contents
+ rel
->r_offset
+ 2);
10186 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
10187 | ((value
& 0x04000000) >> 15);
10188 addend
= (addend
^ 0x8000) - 0x8000;
10192 if (howto
->rightshift
10193 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
10195 (*_bfd_error_handler
)
10196 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
10197 input_bfd
, input_section
,
10198 (long) rel
->r_offset
, howto
->name
);
10202 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10204 /* Get the (signed) value from the instruction. */
10205 addend
= value
& howto
->src_mask
;
10206 if (addend
& ((howto
->src_mask
+ 1) >> 1))
10208 bfd_signed_vma mask
;
10211 mask
&= ~ howto
->src_mask
;
10219 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
10221 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
10223 /* Cases here must match those in the preceeding
10224 switch statement. */
10227 case R_ARM_MOVW_ABS_NC
:
10228 case R_ARM_MOVT_ABS
:
10229 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
10230 | (addend
& 0xfff);
10231 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10234 case R_ARM_THM_MOVW_ABS_NC
:
10235 case R_ARM_THM_MOVT_ABS
:
10236 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
10237 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
10238 bfd_put_16 (input_bfd
, value
>> 16,
10239 contents
+ rel
->r_offset
);
10240 bfd_put_16 (input_bfd
, value
,
10241 contents
+ rel
->r_offset
+ 2);
10245 value
= (value
& ~ howto
->dst_mask
)
10246 | (addend
& howto
->dst_mask
);
10247 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
10253 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
10257 bfd_boolean warned
;
10259 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
10260 r_symndx
, symtab_hdr
, sym_hashes
,
10261 h
, sec
, relocation
,
10262 unresolved_reloc
, warned
);
10264 sym_type
= h
->type
;
10267 if (sec
!= NULL
&& elf_discarded_section (sec
))
10268 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
10269 rel
, relend
, howto
, contents
);
10271 if (info
->relocatable
)
10273 /* This is a relocatable link. We don't have to change
10274 anything, unless the reloc is against a section symbol,
10275 in which case we have to adjust according to where the
10276 section symbol winds up in the output section. */
10277 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
10279 if (globals
->use_rel
)
10280 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
10281 howto
, (bfd_signed_vma
) sec
->output_offset
);
10283 rel
->r_addend
+= sec
->output_offset
;
10289 name
= h
->root
.root
.string
;
10292 name
= (bfd_elf_string_from_elf_section
10293 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
10294 if (name
== NULL
|| *name
== '\0')
10295 name
= bfd_section_name (input_bfd
, sec
);
10298 if (r_symndx
!= STN_UNDEF
10299 && r_type
!= R_ARM_NONE
10301 || h
->root
.type
== bfd_link_hash_defined
10302 || h
->root
.type
== bfd_link_hash_defweak
)
10303 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
10305 (*_bfd_error_handler
)
10306 ((sym_type
== STT_TLS
10307 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
10308 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
10311 (long) rel
->r_offset
,
10316 /* We call elf32_arm_final_link_relocate unless we're completely
10317 done, i.e., the relaxation produced the final output we want,
10318 and we won't let anybody mess with it. Also, we have to do
10319 addend adjustments in case of a R_ARM_TLS_GOTDESC relocation
10320 both in relaxed and non-relaxed cases */
10321 if ((elf32_arm_tls_transition (info
, r_type
, h
) != (unsigned)r_type
)
10322 || (IS_ARM_TLS_GNU_RELOC (r_type
)
10323 && !((h
? elf32_arm_hash_entry (h
)->tls_type
:
10324 elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
])
10327 r
= elf32_arm_tls_relax (globals
, input_bfd
, input_section
,
10328 contents
, rel
, h
== NULL
);
10329 /* This may have been marked unresolved because it came from
10330 a shared library. But we've just dealt with that. */
10331 unresolved_reloc
= 0;
10334 r
= bfd_reloc_continue
;
10336 if (r
== bfd_reloc_continue
)
10337 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
10338 input_section
, contents
, rel
,
10339 relocation
, info
, sec
, name
, sym_type
,
10340 (h
? h
->target_internal
10341 : ARM_SYM_BRANCH_TYPE (sym
)), h
,
10342 &unresolved_reloc
, &error_message
);
10344 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
10345 because such sections are not SEC_ALLOC and thus ld.so will
10346 not process them. */
10347 if (unresolved_reloc
10348 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
10349 && h
->def_dynamic
))
10351 (*_bfd_error_handler
)
10352 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
10355 (long) rel
->r_offset
,
10357 h
->root
.root
.string
);
10361 if (r
!= bfd_reloc_ok
)
10365 case bfd_reloc_overflow
:
10366 /* If the overflowing reloc was to an undefined symbol,
10367 we have already printed one error message and there
10368 is no point complaining again. */
10370 h
->root
.type
!= bfd_link_hash_undefined
)
10371 && (!((*info
->callbacks
->reloc_overflow
)
10372 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
10373 (bfd_vma
) 0, input_bfd
, input_section
,
10378 case bfd_reloc_undefined
:
10379 if (!((*info
->callbacks
->undefined_symbol
)
10380 (info
, name
, input_bfd
, input_section
,
10381 rel
->r_offset
, TRUE
)))
10385 case bfd_reloc_outofrange
:
10386 error_message
= _("out of range");
10389 case bfd_reloc_notsupported
:
10390 error_message
= _("unsupported relocation");
10393 case bfd_reloc_dangerous
:
10394 /* error_message should already be set. */
10398 error_message
= _("unknown error");
10399 /* Fall through. */
10402 BFD_ASSERT (error_message
!= NULL
);
10403 if (!((*info
->callbacks
->reloc_dangerous
)
10404 (info
, error_message
, input_bfd
, input_section
,
10415 /* Add a new unwind edit to the list described by HEAD, TAIL. If TINDEX is zero,
10416 adds the edit to the start of the list. (The list must be built in order of
10417 ascending TINDEX: the function's callers are primarily responsible for
10418 maintaining that condition). */
10421 add_unwind_table_edit (arm_unwind_table_edit
**head
,
10422 arm_unwind_table_edit
**tail
,
10423 arm_unwind_edit_type type
,
10424 asection
*linked_section
,
10425 unsigned int tindex
)
10427 arm_unwind_table_edit
*new_edit
= (arm_unwind_table_edit
*)
10428 xmalloc (sizeof (arm_unwind_table_edit
));
10430 new_edit
->type
= type
;
10431 new_edit
->linked_section
= linked_section
;
10432 new_edit
->index
= tindex
;
10436 new_edit
->next
= NULL
;
10439 (*tail
)->next
= new_edit
;
10441 (*tail
) = new_edit
;
10444 (*head
) = new_edit
;
10448 new_edit
->next
= *head
;
10457 static _arm_elf_section_data
*get_arm_elf_section_data (asection
*);
10459 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
10461 adjust_exidx_size(asection
*exidx_sec
, int adjust
)
10465 if (!exidx_sec
->rawsize
)
10466 exidx_sec
->rawsize
= exidx_sec
->size
;
10468 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
10469 out_sec
= exidx_sec
->output_section
;
10470 /* Adjust size of output section. */
10471 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
10474 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
10476 insert_cantunwind_after(asection
*text_sec
, asection
*exidx_sec
)
10478 struct _arm_elf_section_data
*exidx_arm_data
;
10480 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10481 add_unwind_table_edit (
10482 &exidx_arm_data
->u
.exidx
.unwind_edit_list
,
10483 &exidx_arm_data
->u
.exidx
.unwind_edit_tail
,
10484 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
10486 adjust_exidx_size(exidx_sec
, 8);
10489 /* Scan .ARM.exidx tables, and create a list describing edits which should be
10490 made to those tables, such that:
10492 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
10493 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
10494 codes which have been inlined into the index).
10496 If MERGE_EXIDX_ENTRIES is false, duplicate entries are not merged.
10498 The edits are applied when the tables are written
10499 (in elf32_arm_write_section).
10503 elf32_arm_fix_exidx_coverage (asection
**text_section_order
,
10504 unsigned int num_text_sections
,
10505 struct bfd_link_info
*info
,
10506 bfd_boolean merge_exidx_entries
)
10509 unsigned int last_second_word
= 0, i
;
10510 asection
*last_exidx_sec
= NULL
;
10511 asection
*last_text_sec
= NULL
;
10512 int last_unwind_type
= -1;
10514 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
10516 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link_next
)
10520 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
10522 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
10523 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
10525 if (!hdr
|| hdr
->sh_type
!= SHT_ARM_EXIDX
)
10528 if (elf_sec
->linked_to
)
10530 Elf_Internal_Shdr
*linked_hdr
10531 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
10532 struct _arm_elf_section_data
*linked_sec_arm_data
10533 = get_arm_elf_section_data (linked_hdr
->bfd_section
);
10535 if (linked_sec_arm_data
== NULL
)
10538 /* Link this .ARM.exidx section back from the text section it
10540 linked_sec_arm_data
->u
.text
.arm_exidx_sec
= sec
;
10545 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
10546 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
10547 and add EXIDX_CANTUNWIND entries for sections with no unwind table data. */
10549 for (i
= 0; i
< num_text_sections
; i
++)
10551 asection
*sec
= text_section_order
[i
];
10552 asection
*exidx_sec
;
10553 struct _arm_elf_section_data
*arm_data
= get_arm_elf_section_data (sec
);
10554 struct _arm_elf_section_data
*exidx_arm_data
;
10555 bfd_byte
*contents
= NULL
;
10556 int deleted_exidx_bytes
= 0;
10558 arm_unwind_table_edit
*unwind_edit_head
= NULL
;
10559 arm_unwind_table_edit
*unwind_edit_tail
= NULL
;
10560 Elf_Internal_Shdr
*hdr
;
10563 if (arm_data
== NULL
)
10566 exidx_sec
= arm_data
->u
.text
.arm_exidx_sec
;
10567 if (exidx_sec
== NULL
)
10569 /* Section has no unwind data. */
10570 if (last_unwind_type
== 0 || !last_exidx_sec
)
10573 /* Ignore zero sized sections. */
10574 if (sec
->size
== 0)
10577 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
10578 last_unwind_type
= 0;
10582 /* Skip /DISCARD/ sections. */
10583 if (bfd_is_abs_section (exidx_sec
->output_section
))
10586 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
10587 if (hdr
->sh_type
!= SHT_ARM_EXIDX
)
10590 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
10591 if (exidx_arm_data
== NULL
)
10594 ibfd
= exidx_sec
->owner
;
10596 if (hdr
->contents
!= NULL
)
10597 contents
= hdr
->contents
;
10598 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
10602 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
10604 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
10608 /* An EXIDX_CANTUNWIND entry. */
10609 if (second_word
== 1)
10611 if (last_unwind_type
== 0)
10615 /* Inlined unwinding data. Merge if equal to previous. */
10616 else if ((second_word
& 0x80000000) != 0)
10618 if (merge_exidx_entries
10619 && last_second_word
== second_word
&& last_unwind_type
== 1)
10622 last_second_word
= second_word
;
10624 /* Normal table entry. In theory we could merge these too,
10625 but duplicate entries are likely to be much less common. */
10631 add_unwind_table_edit (&unwind_edit_head
, &unwind_edit_tail
,
10632 DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
10634 deleted_exidx_bytes
+= 8;
10637 last_unwind_type
= unwind_type
;
10640 /* Free contents if we allocated it ourselves. */
10641 if (contents
!= hdr
->contents
)
10644 /* Record edits to be applied later (in elf32_arm_write_section). */
10645 exidx_arm_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
10646 exidx_arm_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
10648 if (deleted_exidx_bytes
> 0)
10649 adjust_exidx_size(exidx_sec
, -deleted_exidx_bytes
);
10651 last_exidx_sec
= exidx_sec
;
10652 last_text_sec
= sec
;
10655 /* Add terminating CANTUNWIND entry. */
10656 if (last_exidx_sec
&& last_unwind_type
!= 0)
10657 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
10663 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
10664 bfd
*ibfd
, const char *name
)
10666 asection
*sec
, *osec
;
10668 sec
= bfd_get_section_by_name (ibfd
, name
);
10669 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
10672 osec
= sec
->output_section
;
10673 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
10676 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
10677 sec
->output_offset
, sec
->size
))
10684 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10686 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
10687 asection
*sec
, *osec
;
10689 if (globals
== NULL
)
10692 /* Invoke the regular ELF backend linker to do all the work. */
10693 if (!bfd_elf_final_link (abfd
, info
))
10696 /* Process stub sections (eg BE8 encoding, ...). */
10697 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
10699 for (i
=0; i
<htab
->top_id
; i
++)
10701 sec
= htab
->stub_group
[i
].stub_sec
;
10702 /* Only process it once, in its link_sec slot. */
10703 if (sec
&& i
== htab
->stub_group
[i
].link_sec
->id
)
10705 osec
= sec
->output_section
;
10706 elf32_arm_write_section (abfd
, info
, sec
, sec
->contents
);
10707 if (! bfd_set_section_contents (abfd
, osec
, sec
->contents
,
10708 sec
->output_offset
, sec
->size
))
10713 /* Write out any glue sections now that we have created all the
10715 if (globals
->bfd_of_glue_owner
!= NULL
)
10717 if (! elf32_arm_output_glue_section (info
, abfd
,
10718 globals
->bfd_of_glue_owner
,
10719 ARM2THUMB_GLUE_SECTION_NAME
))
10722 if (! elf32_arm_output_glue_section (info
, abfd
,
10723 globals
->bfd_of_glue_owner
,
10724 THUMB2ARM_GLUE_SECTION_NAME
))
10727 if (! elf32_arm_output_glue_section (info
, abfd
,
10728 globals
->bfd_of_glue_owner
,
10729 VFP11_ERRATUM_VENEER_SECTION_NAME
))
10732 if (! elf32_arm_output_glue_section (info
, abfd
,
10733 globals
->bfd_of_glue_owner
,
10734 ARM_BX_GLUE_SECTION_NAME
))
10741 /* Set the right machine number. */
10744 elf32_arm_object_p (bfd
*abfd
)
10748 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
10750 if (mach
!= bfd_mach_arm_unknown
)
10751 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
10753 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
10754 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
10757 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
10762 /* Function to keep ARM specific flags in the ELF header. */
10765 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
10767 if (elf_flags_init (abfd
)
10768 && elf_elfheader (abfd
)->e_flags
!= flags
)
10770 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
10772 if (flags
& EF_ARM_INTERWORK
)
10773 (*_bfd_error_handler
)
10774 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
10778 (_("Warning: Clearing the interworking flag of %B due to outside request"),
10784 elf_elfheader (abfd
)->e_flags
= flags
;
10785 elf_flags_init (abfd
) = TRUE
;
10791 /* Copy backend specific data from one object module to another. */
10794 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
10797 flagword out_flags
;
10799 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
10802 in_flags
= elf_elfheader (ibfd
)->e_flags
;
10803 out_flags
= elf_elfheader (obfd
)->e_flags
;
10805 if (elf_flags_init (obfd
)
10806 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
10807 && in_flags
!= out_flags
)
10809 /* Cannot mix APCS26 and APCS32 code. */
10810 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
10813 /* Cannot mix float APCS and non-float APCS code. */
10814 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
10817 /* If the src and dest have different interworking flags
10818 then turn off the interworking bit. */
10819 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
10821 if (out_flags
& EF_ARM_INTERWORK
)
10823 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
10826 in_flags
&= ~EF_ARM_INTERWORK
;
10829 /* Likewise for PIC, though don't warn for this case. */
10830 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
10831 in_flags
&= ~EF_ARM_PIC
;
10834 elf_elfheader (obfd
)->e_flags
= in_flags
;
10835 elf_flags_init (obfd
) = TRUE
;
10837 /* Also copy the EI_OSABI field. */
10838 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
10839 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
10841 /* Copy object attributes. */
10842 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
10847 /* Values for Tag_ABI_PCS_R9_use. */
10856 /* Values for Tag_ABI_PCS_RW_data. */
10859 AEABI_PCS_RW_data_absolute
,
10860 AEABI_PCS_RW_data_PCrel
,
10861 AEABI_PCS_RW_data_SBrel
,
10862 AEABI_PCS_RW_data_unused
10865 /* Values for Tag_ABI_enum_size. */
10871 AEABI_enum_forced_wide
10874 /* Determine whether an object attribute tag takes an integer, a
10878 elf32_arm_obj_attrs_arg_type (int tag
)
10880 if (tag
== Tag_compatibility
)
10881 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
10882 else if (tag
== Tag_nodefaults
)
10883 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
10884 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
10885 return ATTR_TYPE_FLAG_STR_VAL
;
10887 return ATTR_TYPE_FLAG_INT_VAL
;
10889 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
10892 /* The ABI defines that Tag_conformance should be emitted first, and that
10893 Tag_nodefaults should be second (if either is defined). This sets those
10894 two positions, and bumps up the position of all the remaining tags to
10897 elf32_arm_obj_attrs_order (int num
)
10899 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
)
10900 return Tag_conformance
;
10901 if (num
== LEAST_KNOWN_OBJ_ATTRIBUTE
+ 1)
10902 return Tag_nodefaults
;
10903 if ((num
- 2) < Tag_nodefaults
)
10905 if ((num
- 1) < Tag_conformance
)
10910 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
10912 elf32_arm_obj_attrs_handle_unknown (bfd
*abfd
, int tag
)
10914 if ((tag
& 127) < 64)
10917 (_("%B: Unknown mandatory EABI object attribute %d"),
10919 bfd_set_error (bfd_error_bad_value
);
10925 (_("Warning: %B: Unknown EABI object attribute %d"),
10931 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
10932 Returns -1 if no architecture could be read. */
10935 get_secondary_compatible_arch (bfd
*abfd
)
10937 obj_attribute
*attr
=
10938 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
10940 /* Note: the tag and its argument below are uleb128 values, though
10941 currently-defined values fit in one byte for each. */
10943 && attr
->s
[0] == Tag_CPU_arch
10944 && (attr
->s
[1] & 128) != 128
10945 && attr
->s
[2] == 0)
10948 /* This tag is "safely ignorable", so don't complain if it looks funny. */
10952 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
10953 The tag is removed if ARCH is -1. */
10956 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
10958 obj_attribute
*attr
=
10959 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
10967 /* Note: the tag and its argument below are uleb128 values, though
10968 currently-defined values fit in one byte for each. */
10970 attr
->s
= (char *) bfd_alloc (abfd
, 3);
10971 attr
->s
[0] = Tag_CPU_arch
;
10976 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
10980 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
10981 int newtag
, int secondary_compat
)
10983 #define T(X) TAG_CPU_ARCH_##X
10984 int tagl
, tagh
, result
;
10987 T(V6T2
), /* PRE_V4. */
10989 T(V6T2
), /* V4T. */
10990 T(V6T2
), /* V5T. */
10991 T(V6T2
), /* V5TE. */
10992 T(V6T2
), /* V5TEJ. */
10995 T(V6T2
) /* V6T2. */
10999 T(V6K
), /* PRE_V4. */
11003 T(V6K
), /* V5TE. */
11004 T(V6K
), /* V5TEJ. */
11006 T(V6KZ
), /* V6KZ. */
11012 T(V7
), /* PRE_V4. */
11017 T(V7
), /* V5TEJ. */
11030 T(V6K
), /* V5TE. */
11031 T(V6K
), /* V5TEJ. */
11033 T(V6KZ
), /* V6KZ. */
11037 T(V6_M
) /* V6_M. */
11039 const int v6s_m
[] =
11045 T(V6K
), /* V5TE. */
11046 T(V6K
), /* V5TEJ. */
11048 T(V6KZ
), /* V6KZ. */
11052 T(V6S_M
), /* V6_M. */
11053 T(V6S_M
) /* V6S_M. */
11055 const int v7e_m
[] =
11059 T(V7E_M
), /* V4T. */
11060 T(V7E_M
), /* V5T. */
11061 T(V7E_M
), /* V5TE. */
11062 T(V7E_M
), /* V5TEJ. */
11063 T(V7E_M
), /* V6. */
11064 T(V7E_M
), /* V6KZ. */
11065 T(V7E_M
), /* V6T2. */
11066 T(V7E_M
), /* V6K. */
11067 T(V7E_M
), /* V7. */
11068 T(V7E_M
), /* V6_M. */
11069 T(V7E_M
), /* V6S_M. */
11070 T(V7E_M
) /* V7E_M. */
11072 const int v4t_plus_v6_m
[] =
11078 T(V5TE
), /* V5TE. */
11079 T(V5TEJ
), /* V5TEJ. */
11081 T(V6KZ
), /* V6KZ. */
11082 T(V6T2
), /* V6T2. */
11085 T(V6_M
), /* V6_M. */
11086 T(V6S_M
), /* V6S_M. */
11087 T(V7E_M
), /* V7E_M. */
11088 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
11090 const int *comb
[] =
11098 /* Pseudo-architecture. */
11102 /* Check we've not got a higher architecture than we know about. */
11104 if (oldtag
> MAX_TAG_CPU_ARCH
|| newtag
> MAX_TAG_CPU_ARCH
)
11106 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd
);
11110 /* Override old tag if we have a Tag_also_compatible_with on the output. */
11112 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
11113 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
11114 oldtag
= T(V4T_PLUS_V6_M
);
11116 /* And override the new tag if we have a Tag_also_compatible_with on the
11119 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
11120 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
11121 newtag
= T(V4T_PLUS_V6_M
);
11123 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
11124 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
11126 /* Architectures before V6KZ add features monotonically. */
11127 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
11130 result
= comb
[tagh
- T(V6T2
)][tagl
];
11132 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
11133 as the canonical version. */
11134 if (result
== T(V4T_PLUS_V6_M
))
11137 *secondary_compat_out
= T(V6_M
);
11140 *secondary_compat_out
= -1;
11144 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
11145 ibfd
, oldtag
, newtag
);
11153 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
11154 are conflicting attributes. */
11157 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
11159 obj_attribute
*in_attr
;
11160 obj_attribute
*out_attr
;
11161 /* Some tags have 0 = don't care, 1 = strong requirement,
11162 2 = weak requirement. */
11163 static const int order_021
[3] = {0, 2, 1};
11165 bfd_boolean result
= TRUE
;
11167 /* Skip the linker stubs file. This preserves previous behavior
11168 of accepting unknown attributes in the first input file - but
11170 if (ibfd
->flags
& BFD_LINKER_CREATED
)
11173 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
11175 /* This is the first object. Copy the attributes. */
11176 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
11178 out_attr
= elf_known_obj_attributes_proc (obfd
);
11180 /* Use the Tag_null value to indicate the attributes have been
11184 /* We do not output objects with Tag_MPextension_use_legacy - we move
11185 the attribute's value to Tag_MPextension_use. */
11186 if (out_attr
[Tag_MPextension_use_legacy
].i
!= 0)
11188 if (out_attr
[Tag_MPextension_use
].i
!= 0
11189 && out_attr
[Tag_MPextension_use_legacy
].i
11190 != out_attr
[Tag_MPextension_use
].i
)
11193 (_("Error: %B has both the current and legacy "
11194 "Tag_MPextension_use attributes"), ibfd
);
11198 out_attr
[Tag_MPextension_use
] =
11199 out_attr
[Tag_MPextension_use_legacy
];
11200 out_attr
[Tag_MPextension_use_legacy
].type
= 0;
11201 out_attr
[Tag_MPextension_use_legacy
].i
= 0;
11207 in_attr
= elf_known_obj_attributes_proc (ibfd
);
11208 out_attr
= elf_known_obj_attributes_proc (obfd
);
11209 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
11210 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
11212 /* Ignore mismatches if the object doesn't use floating point. */
11213 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
11214 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
11215 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
11218 (_("error: %B uses VFP register arguments, %B does not"),
11219 in_attr
[Tag_ABI_VFP_args
].i
? ibfd
: obfd
,
11220 in_attr
[Tag_ABI_VFP_args
].i
? obfd
: ibfd
);
11225 for (i
= LEAST_KNOWN_OBJ_ATTRIBUTE
; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
11227 /* Merge this attribute with existing attributes. */
11230 case Tag_CPU_raw_name
:
11232 /* These are merged after Tag_CPU_arch. */
11235 case Tag_ABI_optimization_goals
:
11236 case Tag_ABI_FP_optimization_goals
:
11237 /* Use the first value seen. */
11242 int secondary_compat
= -1, secondary_compat_out
= -1;
11243 unsigned int saved_out_attr
= out_attr
[i
].i
;
11244 static const char *name_table
[] = {
11245 /* These aren't real CPU names, but we can't guess
11246 that from the architecture version alone. */
11262 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
11263 secondary_compat
= get_secondary_compatible_arch (ibfd
);
11264 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
11265 out_attr
[i
].i
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
11266 &secondary_compat_out
,
11269 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
11271 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
11272 if (out_attr
[i
].i
== saved_out_attr
)
11273 ; /* Leave the names alone. */
11274 else if (out_attr
[i
].i
== in_attr
[i
].i
)
11276 /* The output architecture has been changed to match the
11277 input architecture. Use the input names. */
11278 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
11279 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
11281 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
11282 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
11287 out_attr
[Tag_CPU_name
].s
= NULL
;
11288 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
11291 /* If we still don't have a value for Tag_CPU_name,
11292 make one up now. Tag_CPU_raw_name remains blank. */
11293 if (out_attr
[Tag_CPU_name
].s
== NULL
11294 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
11295 out_attr
[Tag_CPU_name
].s
=
11296 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
11300 case Tag_ARM_ISA_use
:
11301 case Tag_THUMB_ISA_use
:
11302 case Tag_WMMX_arch
:
11303 case Tag_Advanced_SIMD_arch
:
11304 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
11305 case Tag_ABI_FP_rounding
:
11306 case Tag_ABI_FP_exceptions
:
11307 case Tag_ABI_FP_user_exceptions
:
11308 case Tag_ABI_FP_number_model
:
11309 case Tag_FP_HP_extension
:
11310 case Tag_CPU_unaligned_access
:
11312 case Tag_MPextension_use
:
11313 /* Use the largest value specified. */
11314 if (in_attr
[i
].i
> out_attr
[i
].i
)
11315 out_attr
[i
].i
= in_attr
[i
].i
;
11318 case Tag_ABI_align_preserved
:
11319 case Tag_ABI_PCS_RO_data
:
11320 /* Use the smallest value specified. */
11321 if (in_attr
[i
].i
< out_attr
[i
].i
)
11322 out_attr
[i
].i
= in_attr
[i
].i
;
11325 case Tag_ABI_align_needed
:
11326 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
11327 && (in_attr
[Tag_ABI_align_preserved
].i
== 0
11328 || out_attr
[Tag_ABI_align_preserved
].i
== 0))
11330 /* This error message should be enabled once all non-conformant
11331 binaries in the toolchain have had the attributes set
11334 (_("error: %B: 8-byte data alignment conflicts with %B"),
11338 /* Fall through. */
11339 case Tag_ABI_FP_denormal
:
11340 case Tag_ABI_PCS_GOT_use
:
11341 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
11342 value if greater than 2 (for future-proofing). */
11343 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
11344 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
11345 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
11346 out_attr
[i
].i
= in_attr
[i
].i
;
11349 case Tag_Virtualization_use
:
11350 /* The virtualization tag effectively stores two bits of
11351 information: the intended use of TrustZone (in bit 0), and the
11352 intended use of Virtualization (in bit 1). */
11353 if (out_attr
[i
].i
== 0)
11354 out_attr
[i
].i
= in_attr
[i
].i
;
11355 else if (in_attr
[i
].i
!= 0
11356 && in_attr
[i
].i
!= out_attr
[i
].i
)
11358 if (in_attr
[i
].i
<= 3 && out_attr
[i
].i
<= 3)
11363 (_("error: %B: unable to merge virtualization attributes "
11371 case Tag_CPU_arch_profile
:
11372 if (out_attr
[i
].i
!= in_attr
[i
].i
)
11374 /* 0 will merge with anything.
11375 'A' and 'S' merge to 'A'.
11376 'R' and 'S' merge to 'R'.
11377 'M' and 'A|R|S' is an error. */
11378 if (out_attr
[i
].i
== 0
11379 || (out_attr
[i
].i
== 'S'
11380 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
11381 out_attr
[i
].i
= in_attr
[i
].i
;
11382 else if (in_attr
[i
].i
== 0
11383 || (in_attr
[i
].i
== 'S'
11384 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
11385 ; /* Do nothing. */
11389 (_("error: %B: Conflicting architecture profiles %c/%c"),
11391 in_attr
[i
].i
? in_attr
[i
].i
: '0',
11392 out_attr
[i
].i
? out_attr
[i
].i
: '0');
11399 /* Tag_ABI_HardFP_use is handled along with Tag_FP_arch since
11400 the meaning of Tag_ABI_HardFP_use depends on Tag_FP_arch
11401 when it's 0. It might mean absence of FP hardware if
11402 Tag_FP_arch is zero, otherwise it is effectively SP + DP. */
11404 static const struct
11408 } vfp_versions
[7] =
11422 /* If the output has no requirement about FP hardware,
11423 follow the requirement of the input. */
11424 if (out_attr
[i
].i
== 0)
11426 BFD_ASSERT (out_attr
[Tag_ABI_HardFP_use
].i
== 0);
11427 out_attr
[i
].i
= in_attr
[i
].i
;
11428 out_attr
[Tag_ABI_HardFP_use
].i
11429 = in_attr
[Tag_ABI_HardFP_use
].i
;
11432 /* If the input has no requirement about FP hardware, do
11434 else if (in_attr
[i
].i
== 0)
11436 BFD_ASSERT (in_attr
[Tag_ABI_HardFP_use
].i
== 0);
11440 /* Both the input and the output have nonzero Tag_FP_arch.
11441 So Tag_ABI_HardFP_use is (SP & DP) when it's zero. */
11443 /* If both the input and the output have zero Tag_ABI_HardFP_use,
11445 if (in_attr
[Tag_ABI_HardFP_use
].i
== 0
11446 && out_attr
[Tag_ABI_HardFP_use
].i
== 0)
11448 /* If the input and the output have different Tag_ABI_HardFP_use,
11449 the combination of them is 3 (SP & DP). */
11450 else if (in_attr
[Tag_ABI_HardFP_use
].i
11451 != out_attr
[Tag_ABI_HardFP_use
].i
)
11452 out_attr
[Tag_ABI_HardFP_use
].i
= 3;
11454 /* Now we can handle Tag_FP_arch. */
11456 /* Values greater than 6 aren't defined, so just pick the
11458 if (in_attr
[i
].i
> 6 && in_attr
[i
].i
> out_attr
[i
].i
)
11460 out_attr
[i
] = in_attr
[i
];
11463 /* The output uses the superset of input features
11464 (ISA version) and registers. */
11465 ver
= vfp_versions
[in_attr
[i
].i
].ver
;
11466 if (ver
< vfp_versions
[out_attr
[i
].i
].ver
)
11467 ver
= vfp_versions
[out_attr
[i
].i
].ver
;
11468 regs
= vfp_versions
[in_attr
[i
].i
].regs
;
11469 if (regs
< vfp_versions
[out_attr
[i
].i
].regs
)
11470 regs
= vfp_versions
[out_attr
[i
].i
].regs
;
11471 /* This assumes all possible supersets are also a valid
11473 for (newval
= 6; newval
> 0; newval
--)
11475 if (regs
== vfp_versions
[newval
].regs
11476 && ver
== vfp_versions
[newval
].ver
)
11479 out_attr
[i
].i
= newval
;
11482 case Tag_PCS_config
:
11483 if (out_attr
[i
].i
== 0)
11484 out_attr
[i
].i
= in_attr
[i
].i
;
11485 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
11487 /* It's sometimes ok to mix different configs, so this is only
11490 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
11493 case Tag_ABI_PCS_R9_use
:
11494 if (in_attr
[i
].i
!= out_attr
[i
].i
11495 && out_attr
[i
].i
!= AEABI_R9_unused
11496 && in_attr
[i
].i
!= AEABI_R9_unused
)
11499 (_("error: %B: Conflicting use of R9"), ibfd
);
11502 if (out_attr
[i
].i
== AEABI_R9_unused
)
11503 out_attr
[i
].i
= in_attr
[i
].i
;
11505 case Tag_ABI_PCS_RW_data
:
11506 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
11507 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
11508 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
11511 (_("error: %B: SB relative addressing conflicts with use of R9"),
11515 /* Use the smallest value specified. */
11516 if (in_attr
[i
].i
< out_attr
[i
].i
)
11517 out_attr
[i
].i
= in_attr
[i
].i
;
11519 case Tag_ABI_PCS_wchar_t
:
11520 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
11521 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
11524 (_("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"),
11525 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
11527 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
11528 out_attr
[i
].i
= in_attr
[i
].i
;
11530 case Tag_ABI_enum_size
:
11531 if (in_attr
[i
].i
!= AEABI_enum_unused
)
11533 if (out_attr
[i
].i
== AEABI_enum_unused
11534 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
11536 /* The existing object is compatible with anything.
11537 Use whatever requirements the new object has. */
11538 out_attr
[i
].i
= in_attr
[i
].i
;
11540 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
11541 && out_attr
[i
].i
!= in_attr
[i
].i
11542 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
11544 static const char *aeabi_enum_names
[] =
11545 { "", "variable-size", "32-bit", "" };
11546 const char *in_name
=
11547 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
11548 ? aeabi_enum_names
[in_attr
[i
].i
]
11550 const char *out_name
=
11551 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
11552 ? aeabi_enum_names
[out_attr
[i
].i
]
11555 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
11556 ibfd
, in_name
, out_name
);
11560 case Tag_ABI_VFP_args
:
11563 case Tag_ABI_WMMX_args
:
11564 if (in_attr
[i
].i
!= out_attr
[i
].i
)
11567 (_("error: %B uses iWMMXt register arguments, %B does not"),
11572 case Tag_compatibility
:
11573 /* Merged in target-independent code. */
11575 case Tag_ABI_HardFP_use
:
11576 /* This is handled along with Tag_FP_arch. */
11578 case Tag_ABI_FP_16bit_format
:
11579 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
11581 if (in_attr
[i
].i
!= out_attr
[i
].i
)
11584 (_("error: fp16 format mismatch between %B and %B"),
11589 if (in_attr
[i
].i
!= 0)
11590 out_attr
[i
].i
= in_attr
[i
].i
;
11594 /* This tag is set to zero if we can use UDIV and SDIV in Thumb
11595 mode on a v7-M or v7-R CPU; to one if we can not use UDIV or
11596 SDIV at all; and to two if we can use UDIV or SDIV on a v7-A
11597 CPU. We will merge as follows: If the input attribute's value
11598 is one then the output attribute's value remains unchanged. If
11599 the input attribute's value is zero or two then if the output
11600 attribute's value is one the output value is set to the input
11601 value, otherwise the output value must be the same as the
11603 if (in_attr
[i
].i
!= 1 && out_attr
[i
].i
!= 1)
11605 if (in_attr
[i
].i
!= out_attr
[i
].i
)
11608 (_("DIV usage mismatch between %B and %B"),
11614 if (in_attr
[i
].i
!= 1)
11615 out_attr
[i
].i
= in_attr
[i
].i
;
11619 case Tag_MPextension_use_legacy
:
11620 /* We don't output objects with Tag_MPextension_use_legacy - we
11621 move the value to Tag_MPextension_use. */
11622 if (in_attr
[i
].i
!= 0 && in_attr
[Tag_MPextension_use
].i
!= 0)
11624 if (in_attr
[Tag_MPextension_use
].i
!= in_attr
[i
].i
)
11627 (_("%B has has both the current and legacy "
11628 "Tag_MPextension_use attributes"),
11634 if (in_attr
[i
].i
> out_attr
[Tag_MPextension_use
].i
)
11635 out_attr
[Tag_MPextension_use
] = in_attr
[i
];
11639 case Tag_nodefaults
:
11640 /* This tag is set if it exists, but the value is unused (and is
11641 typically zero). We don't actually need to do anything here -
11642 the merge happens automatically when the type flags are merged
11645 case Tag_also_compatible_with
:
11646 /* Already done in Tag_CPU_arch. */
11648 case Tag_conformance
:
11649 /* Keep the attribute if it matches. Throw it away otherwise.
11650 No attribute means no claim to conform. */
11651 if (!in_attr
[i
].s
|| !out_attr
[i
].s
11652 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
11653 out_attr
[i
].s
= NULL
;
11658 = result
&& _bfd_elf_merge_unknown_attribute_low (ibfd
, obfd
, i
);
11661 /* If out_attr was copied from in_attr then it won't have a type yet. */
11662 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
11663 out_attr
[i
].type
= in_attr
[i
].type
;
11666 /* Merge Tag_compatibility attributes and any common GNU ones. */
11667 if (!_bfd_elf_merge_object_attributes (ibfd
, obfd
))
11670 /* Check for any attributes not known on ARM. */
11671 result
&= _bfd_elf_merge_unknown_attribute_list (ibfd
, obfd
);
11677 /* Return TRUE if the two EABI versions are incompatible. */
11680 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
11682 /* v4 and v5 are the same spec before and after it was released,
11683 so allow mixing them. */
11684 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
11685 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
11688 return (iver
== over
);
11691 /* Merge backend specific data from an object file to the output
11692 object file when linking. */
11695 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
);
11697 /* Display the flags field. */
11700 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
11702 FILE * file
= (FILE *) ptr
;
11703 unsigned long flags
;
11705 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
11707 /* Print normal ELF private data. */
11708 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
11710 flags
= elf_elfheader (abfd
)->e_flags
;
11711 /* Ignore init flag - it may not be set, despite the flags field
11712 containing valid data. */
11714 /* xgettext:c-format */
11715 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
11717 switch (EF_ARM_EABI_VERSION (flags
))
11719 case EF_ARM_EABI_UNKNOWN
:
11720 /* The following flag bits are GNU extensions and not part of the
11721 official ARM ELF extended ABI. Hence they are only decoded if
11722 the EABI version is not set. */
11723 if (flags
& EF_ARM_INTERWORK
)
11724 fprintf (file
, _(" [interworking enabled]"));
11726 if (flags
& EF_ARM_APCS_26
)
11727 fprintf (file
, " [APCS-26]");
11729 fprintf (file
, " [APCS-32]");
11731 if (flags
& EF_ARM_VFP_FLOAT
)
11732 fprintf (file
, _(" [VFP float format]"));
11733 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
11734 fprintf (file
, _(" [Maverick float format]"));
11736 fprintf (file
, _(" [FPA float format]"));
11738 if (flags
& EF_ARM_APCS_FLOAT
)
11739 fprintf (file
, _(" [floats passed in float registers]"));
11741 if (flags
& EF_ARM_PIC
)
11742 fprintf (file
, _(" [position independent]"));
11744 if (flags
& EF_ARM_NEW_ABI
)
11745 fprintf (file
, _(" [new ABI]"));
11747 if (flags
& EF_ARM_OLD_ABI
)
11748 fprintf (file
, _(" [old ABI]"));
11750 if (flags
& EF_ARM_SOFT_FLOAT
)
11751 fprintf (file
, _(" [software FP]"));
11753 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
11754 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
11755 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
11756 | EF_ARM_MAVERICK_FLOAT
);
11759 case EF_ARM_EABI_VER1
:
11760 fprintf (file
, _(" [Version1 EABI]"));
11762 if (flags
& EF_ARM_SYMSARESORTED
)
11763 fprintf (file
, _(" [sorted symbol table]"));
11765 fprintf (file
, _(" [unsorted symbol table]"));
11767 flags
&= ~ EF_ARM_SYMSARESORTED
;
11770 case EF_ARM_EABI_VER2
:
11771 fprintf (file
, _(" [Version2 EABI]"));
11773 if (flags
& EF_ARM_SYMSARESORTED
)
11774 fprintf (file
, _(" [sorted symbol table]"));
11776 fprintf (file
, _(" [unsorted symbol table]"));
11778 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
11779 fprintf (file
, _(" [dynamic symbols use segment index]"));
11781 if (flags
& EF_ARM_MAPSYMSFIRST
)
11782 fprintf (file
, _(" [mapping symbols precede others]"));
11784 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
11785 | EF_ARM_MAPSYMSFIRST
);
11788 case EF_ARM_EABI_VER3
:
11789 fprintf (file
, _(" [Version3 EABI]"));
11792 case EF_ARM_EABI_VER4
:
11793 fprintf (file
, _(" [Version4 EABI]"));
11796 case EF_ARM_EABI_VER5
:
11797 fprintf (file
, _(" [Version5 EABI]"));
11799 if (flags
& EF_ARM_BE8
)
11800 fprintf (file
, _(" [BE8]"));
11802 if (flags
& EF_ARM_LE8
)
11803 fprintf (file
, _(" [LE8]"));
11805 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
11809 fprintf (file
, _(" <EABI version unrecognised>"));
11813 flags
&= ~ EF_ARM_EABIMASK
;
11815 if (flags
& EF_ARM_RELEXEC
)
11816 fprintf (file
, _(" [relocatable executable]"));
11818 if (flags
& EF_ARM_HASENTRY
)
11819 fprintf (file
, _(" [has entry point]"));
11821 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
11824 fprintf (file
, _("<Unrecognised flag bits set>"));
11826 fputc ('\n', file
);
11832 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
11834 switch (ELF_ST_TYPE (elf_sym
->st_info
))
11836 case STT_ARM_TFUNC
:
11837 return ELF_ST_TYPE (elf_sym
->st_info
);
11839 case STT_ARM_16BIT
:
11840 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
11841 This allows us to distinguish between data used by Thumb instructions
11842 and non-data (which is probably code) inside Thumb regions of an
11844 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
11845 return ELF_ST_TYPE (elf_sym
->st_info
);
11856 elf32_arm_gc_mark_hook (asection
*sec
,
11857 struct bfd_link_info
*info
,
11858 Elf_Internal_Rela
*rel
,
11859 struct elf_link_hash_entry
*h
,
11860 Elf_Internal_Sym
*sym
)
11863 switch (ELF32_R_TYPE (rel
->r_info
))
11865 case R_ARM_GNU_VTINHERIT
:
11866 case R_ARM_GNU_VTENTRY
:
11870 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
11873 /* Update the got entry reference counts for the section being removed. */
11876 elf32_arm_gc_sweep_hook (bfd
* abfd
,
11877 struct bfd_link_info
* info
,
11879 const Elf_Internal_Rela
* relocs
)
11881 Elf_Internal_Shdr
*symtab_hdr
;
11882 struct elf_link_hash_entry
**sym_hashes
;
11883 bfd_signed_vma
*local_got_refcounts
;
11884 const Elf_Internal_Rela
*rel
, *relend
;
11885 struct elf32_arm_link_hash_table
* globals
;
11887 if (info
->relocatable
)
11890 globals
= elf32_arm_hash_table (info
);
11891 if (globals
== NULL
)
11894 elf_section_data (sec
)->local_dynrel
= NULL
;
11896 symtab_hdr
= & elf_symtab_hdr (abfd
);
11897 sym_hashes
= elf_sym_hashes (abfd
);
11898 local_got_refcounts
= elf_local_got_refcounts (abfd
);
11900 check_use_blx (globals
);
11902 relend
= relocs
+ sec
->reloc_count
;
11903 for (rel
= relocs
; rel
< relend
; rel
++)
11905 unsigned long r_symndx
;
11906 struct elf_link_hash_entry
*h
= NULL
;
11907 struct elf32_arm_link_hash_entry
*eh
;
11909 bfd_boolean call_reloc_p
;
11910 bfd_boolean may_become_dynamic_p
;
11911 bfd_boolean may_need_local_target_p
;
11912 union gotplt_union
*root_plt
;
11913 struct arm_plt_info
*arm_plt
;
11915 r_symndx
= ELF32_R_SYM (rel
->r_info
);
11916 if (r_symndx
>= symtab_hdr
->sh_info
)
11918 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
11919 while (h
->root
.type
== bfd_link_hash_indirect
11920 || h
->root
.type
== bfd_link_hash_warning
)
11921 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11923 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11925 call_reloc_p
= FALSE
;
11926 may_become_dynamic_p
= FALSE
;
11927 may_need_local_target_p
= FALSE
;
11929 r_type
= ELF32_R_TYPE (rel
->r_info
);
11930 r_type
= arm_real_reloc_type (globals
, r_type
);
11934 case R_ARM_GOT_PREL
:
11935 case R_ARM_TLS_GD32
:
11936 case R_ARM_TLS_IE32
:
11939 if (h
->got
.refcount
> 0)
11940 h
->got
.refcount
-= 1;
11942 else if (local_got_refcounts
!= NULL
)
11944 if (local_got_refcounts
[r_symndx
] > 0)
11945 local_got_refcounts
[r_symndx
] -= 1;
11949 case R_ARM_TLS_LDM32
:
11950 globals
->tls_ldm_got
.refcount
-= 1;
11958 case R_ARM_THM_CALL
:
11959 case R_ARM_THM_JUMP24
:
11960 case R_ARM_THM_JUMP19
:
11961 call_reloc_p
= TRUE
;
11962 may_need_local_target_p
= TRUE
;
11966 if (!globals
->vxworks_p
)
11968 may_need_local_target_p
= TRUE
;
11971 /* Fall through. */
11973 case R_ARM_ABS32_NOI
:
11975 case R_ARM_REL32_NOI
:
11976 case R_ARM_MOVW_ABS_NC
:
11977 case R_ARM_MOVT_ABS
:
11978 case R_ARM_MOVW_PREL_NC
:
11979 case R_ARM_MOVT_PREL
:
11980 case R_ARM_THM_MOVW_ABS_NC
:
11981 case R_ARM_THM_MOVT_ABS
:
11982 case R_ARM_THM_MOVW_PREL_NC
:
11983 case R_ARM_THM_MOVT_PREL
:
11984 /* Should the interworking branches be here also? */
11985 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
11986 && (sec
->flags
& SEC_ALLOC
) != 0)
11989 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
11991 call_reloc_p
= TRUE
;
11992 may_need_local_target_p
= TRUE
;
11995 may_become_dynamic_p
= TRUE
;
11998 may_need_local_target_p
= TRUE
;
12005 if (may_need_local_target_p
12006 && elf32_arm_get_plt_info (abfd
, eh
, r_symndx
, &root_plt
, &arm_plt
))
12008 BFD_ASSERT (root_plt
->refcount
> 0);
12009 root_plt
->refcount
-= 1;
12012 arm_plt
->noncall_refcount
--;
12014 if (r_type
== R_ARM_THM_CALL
)
12015 arm_plt
->maybe_thumb_refcount
--;
12017 if (r_type
== R_ARM_THM_JUMP24
12018 || r_type
== R_ARM_THM_JUMP19
)
12019 arm_plt
->thumb_refcount
--;
12022 if (may_become_dynamic_p
)
12024 struct elf_dyn_relocs
**pp
;
12025 struct elf_dyn_relocs
*p
;
12028 pp
= &(eh
->dyn_relocs
);
12031 Elf_Internal_Sym
*isym
;
12033 isym
= bfd_sym_from_r_symndx (&globals
->sym_cache
,
12037 pp
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12041 for (; (p
= *pp
) != NULL
; pp
= &p
->next
)
12044 /* Everything must go for SEC. */
12054 /* Look through the relocs for a section during the first phase. */
12057 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
12058 asection
*sec
, const Elf_Internal_Rela
*relocs
)
12060 Elf_Internal_Shdr
*symtab_hdr
;
12061 struct elf_link_hash_entry
**sym_hashes
;
12062 const Elf_Internal_Rela
*rel
;
12063 const Elf_Internal_Rela
*rel_end
;
12066 struct elf32_arm_link_hash_table
*htab
;
12067 bfd_boolean call_reloc_p
;
12068 bfd_boolean may_become_dynamic_p
;
12069 bfd_boolean may_need_local_target_p
;
12070 unsigned long nsyms
;
12072 if (info
->relocatable
)
12075 BFD_ASSERT (is_arm_elf (abfd
));
12077 htab
= elf32_arm_hash_table (info
);
12083 /* Create dynamic sections for relocatable executables so that we can
12084 copy relocations. */
12085 if (htab
->root
.is_relocatable_executable
12086 && ! htab
->root
.dynamic_sections_created
)
12088 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
12092 if (htab
->root
.dynobj
== NULL
)
12093 htab
->root
.dynobj
= abfd
;
12094 if (!create_ifunc_sections (info
))
12097 dynobj
= htab
->root
.dynobj
;
12099 symtab_hdr
= & elf_symtab_hdr (abfd
);
12100 sym_hashes
= elf_sym_hashes (abfd
);
12101 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
12103 rel_end
= relocs
+ sec
->reloc_count
;
12104 for (rel
= relocs
; rel
< rel_end
; rel
++)
12106 Elf_Internal_Sym
*isym
;
12107 struct elf_link_hash_entry
*h
;
12108 struct elf32_arm_link_hash_entry
*eh
;
12109 unsigned long r_symndx
;
12112 r_symndx
= ELF32_R_SYM (rel
->r_info
);
12113 r_type
= ELF32_R_TYPE (rel
->r_info
);
12114 r_type
= arm_real_reloc_type (htab
, r_type
);
12116 if (r_symndx
>= nsyms
12117 /* PR 9934: It is possible to have relocations that do not
12118 refer to symbols, thus it is also possible to have an
12119 object file containing relocations but no symbol table. */
12120 && (r_symndx
> STN_UNDEF
|| nsyms
> 0))
12122 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
12131 if (r_symndx
< symtab_hdr
->sh_info
)
12133 /* A local symbol. */
12134 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
12141 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
12142 while (h
->root
.type
== bfd_link_hash_indirect
12143 || h
->root
.type
== bfd_link_hash_warning
)
12144 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12148 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12150 call_reloc_p
= FALSE
;
12151 may_become_dynamic_p
= FALSE
;
12152 may_need_local_target_p
= FALSE
;
12154 /* Could be done earlier, if h were already available. */
12155 r_type
= elf32_arm_tls_transition (info
, r_type
, h
);
12159 case R_ARM_GOT_PREL
:
12160 case R_ARM_TLS_GD32
:
12161 case R_ARM_TLS_IE32
:
12162 case R_ARM_TLS_GOTDESC
:
12163 case R_ARM_TLS_DESCSEQ
:
12164 case R_ARM_THM_TLS_DESCSEQ
:
12165 case R_ARM_TLS_CALL
:
12166 case R_ARM_THM_TLS_CALL
:
12167 /* This symbol requires a global offset table entry. */
12169 int tls_type
, old_tls_type
;
12173 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
12175 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
12177 case R_ARM_TLS_GOTDESC
:
12178 case R_ARM_TLS_CALL
: case R_ARM_THM_TLS_CALL
:
12179 case R_ARM_TLS_DESCSEQ
: case R_ARM_THM_TLS_DESCSEQ
:
12180 tls_type
= GOT_TLS_GDESC
; break;
12182 default: tls_type
= GOT_NORMAL
; break;
12188 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
12192 /* This is a global offset table entry for a local symbol. */
12193 if (!elf32_arm_allocate_local_sym_info (abfd
))
12195 elf_local_got_refcounts (abfd
)[r_symndx
] += 1;
12196 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
12199 /* If a variable is accessed with both tls methods, two
12200 slots may be created. */
12201 if (GOT_TLS_GD_ANY_P (old_tls_type
)
12202 && GOT_TLS_GD_ANY_P (tls_type
))
12203 tls_type
|= old_tls_type
;
12205 /* We will already have issued an error message if there
12206 is a TLS/non-TLS mismatch, based on the symbol
12207 type. So just combine any TLS types needed. */
12208 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
12209 && tls_type
!= GOT_NORMAL
)
12210 tls_type
|= old_tls_type
;
12212 /* If the symbol is accessed in both IE and GDESC
12213 method, we're able to relax. Turn off the GDESC flag,
12214 without messing up with any other kind of tls types
12215 that may be involved */
12216 if ((tls_type
& GOT_TLS_IE
) && (tls_type
& GOT_TLS_GDESC
))
12217 tls_type
&= ~GOT_TLS_GDESC
;
12219 if (old_tls_type
!= tls_type
)
12222 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
12224 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
12227 /* Fall through. */
12229 case R_ARM_TLS_LDM32
:
12230 if (r_type
== R_ARM_TLS_LDM32
)
12231 htab
->tls_ldm_got
.refcount
++;
12232 /* Fall through. */
12234 case R_ARM_GOTOFF32
:
12236 if (htab
->root
.sgot
== NULL
12237 && !create_got_section (htab
->root
.dynobj
, info
))
12246 case R_ARM_THM_CALL
:
12247 case R_ARM_THM_JUMP24
:
12248 case R_ARM_THM_JUMP19
:
12249 call_reloc_p
= TRUE
;
12250 may_need_local_target_p
= TRUE
;
12254 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
12255 ldr __GOTT_INDEX__ offsets. */
12256 if (!htab
->vxworks_p
)
12258 may_need_local_target_p
= TRUE
;
12261 /* Fall through. */
12263 case R_ARM_MOVW_ABS_NC
:
12264 case R_ARM_MOVT_ABS
:
12265 case R_ARM_THM_MOVW_ABS_NC
:
12266 case R_ARM_THM_MOVT_ABS
:
12269 (*_bfd_error_handler
)
12270 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
12271 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
12272 (h
) ? h
->root
.root
.string
: "a local symbol");
12273 bfd_set_error (bfd_error_bad_value
);
12277 /* Fall through. */
12279 case R_ARM_ABS32_NOI
:
12281 case R_ARM_REL32_NOI
:
12282 case R_ARM_MOVW_PREL_NC
:
12283 case R_ARM_MOVT_PREL
:
12284 case R_ARM_THM_MOVW_PREL_NC
:
12285 case R_ARM_THM_MOVT_PREL
:
12287 /* Should the interworking branches be listed here? */
12288 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
12289 && (sec
->flags
& SEC_ALLOC
) != 0)
12292 && (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
))
12294 /* In shared libraries and relocatable executables,
12295 we treat local relative references as calls;
12296 see the related SYMBOL_CALLS_LOCAL code in
12297 allocate_dynrelocs. */
12298 call_reloc_p
= TRUE
;
12299 may_need_local_target_p
= TRUE
;
12302 /* We are creating a shared library or relocatable
12303 executable, and this is a reloc against a global symbol,
12304 or a non-PC-relative reloc against a local symbol.
12305 We may need to copy the reloc into the output. */
12306 may_become_dynamic_p
= TRUE
;
12309 may_need_local_target_p
= TRUE
;
12312 /* This relocation describes the C++ object vtable hierarchy.
12313 Reconstruct it for later use during GC. */
12314 case R_ARM_GNU_VTINHERIT
:
12315 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
12319 /* This relocation describes which C++ vtable entries are actually
12320 used. Record for later use during GC. */
12321 case R_ARM_GNU_VTENTRY
:
12322 BFD_ASSERT (h
!= NULL
);
12324 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
12332 /* We may need a .plt entry if the function this reloc
12333 refers to is in a different object, regardless of the
12334 symbol's type. We can't tell for sure yet, because
12335 something later might force the symbol local. */
12337 else if (may_need_local_target_p
)
12338 /* If this reloc is in a read-only section, we might
12339 need a copy reloc. We can't check reliably at this
12340 stage whether the section is read-only, as input
12341 sections have not yet been mapped to output sections.
12342 Tentatively set the flag for now, and correct in
12343 adjust_dynamic_symbol. */
12344 h
->non_got_ref
= 1;
12347 if (may_need_local_target_p
12348 && (h
!= NULL
|| ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
))
12350 union gotplt_union
*root_plt
;
12351 struct arm_plt_info
*arm_plt
;
12352 struct arm_local_iplt_info
*local_iplt
;
12356 root_plt
= &h
->plt
;
12357 arm_plt
= &eh
->plt
;
12361 local_iplt
= elf32_arm_create_local_iplt (abfd
, r_symndx
);
12362 if (local_iplt
== NULL
)
12364 root_plt
= &local_iplt
->root
;
12365 arm_plt
= &local_iplt
->arm
;
12368 /* If the symbol is a function that doesn't bind locally,
12369 this relocation will need a PLT entry. */
12370 root_plt
->refcount
+= 1;
12373 arm_plt
->noncall_refcount
++;
12375 /* It's too early to use htab->use_blx here, so we have to
12376 record possible blx references separately from
12377 relocs that definitely need a thumb stub. */
12379 if (r_type
== R_ARM_THM_CALL
)
12380 arm_plt
->maybe_thumb_refcount
+= 1;
12382 if (r_type
== R_ARM_THM_JUMP24
12383 || r_type
== R_ARM_THM_JUMP19
)
12384 arm_plt
->thumb_refcount
+= 1;
12387 if (may_become_dynamic_p
)
12389 struct elf_dyn_relocs
*p
, **head
;
12391 /* Create a reloc section in dynobj. */
12392 if (sreloc
== NULL
)
12394 sreloc
= _bfd_elf_make_dynamic_reloc_section
12395 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
12397 if (sreloc
== NULL
)
12400 /* BPABI objects never have dynamic relocations mapped. */
12401 if (htab
->symbian_p
)
12405 flags
= bfd_get_section_flags (dynobj
, sreloc
);
12406 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
12407 bfd_set_section_flags (dynobj
, sreloc
, flags
);
12411 /* If this is a global symbol, count the number of
12412 relocations we need for this symbol. */
12414 head
= &((struct elf32_arm_link_hash_entry
*) h
)->dyn_relocs
;
12417 head
= elf32_arm_get_local_dynreloc_list (abfd
, r_symndx
, isym
);
12423 if (p
== NULL
|| p
->sec
!= sec
)
12425 bfd_size_type amt
= sizeof *p
;
12427 p
= (struct elf_dyn_relocs
*) bfd_alloc (htab
->root
.dynobj
, amt
);
12437 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
12446 /* Unwinding tables are not referenced directly. This pass marks them as
12447 required if the corresponding code section is marked. */
12450 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
12451 elf_gc_mark_hook_fn gc_mark_hook
)
12454 Elf_Internal_Shdr
**elf_shdrp
;
12457 /* Marking EH data may cause additional code sections to be marked,
12458 requiring multiple passes. */
12463 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
12467 if (! is_arm_elf (sub
))
12470 elf_shdrp
= elf_elfsections (sub
);
12471 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
12473 Elf_Internal_Shdr
*hdr
;
12475 hdr
= &elf_section_data (o
)->this_hdr
;
12476 if (hdr
->sh_type
== SHT_ARM_EXIDX
12478 && hdr
->sh_link
< elf_numsections (sub
)
12480 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
12483 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
12493 /* Treat mapping symbols as special target symbols. */
12496 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
12498 return bfd_is_arm_special_symbol_name (sym
->name
,
12499 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
12502 /* This is a copy of elf_find_function() from elf.c except that
12503 ARM mapping symbols are ignored when looking for function names
12504 and STT_ARM_TFUNC is considered to a function type. */
12507 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
12508 asection
* section
,
12509 asymbol
** symbols
,
12511 const char ** filename_ptr
,
12512 const char ** functionname_ptr
)
12514 const char * filename
= NULL
;
12515 asymbol
* func
= NULL
;
12516 bfd_vma low_func
= 0;
12519 for (p
= symbols
; *p
!= NULL
; p
++)
12521 elf_symbol_type
*q
;
12523 q
= (elf_symbol_type
*) *p
;
12525 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
12530 filename
= bfd_asymbol_name (&q
->symbol
);
12533 case STT_ARM_TFUNC
:
12535 /* Skip mapping symbols. */
12536 if ((q
->symbol
.flags
& BSF_LOCAL
)
12537 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
12538 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
12540 /* Fall through. */
12541 if (bfd_get_section (&q
->symbol
) == section
12542 && q
->symbol
.value
>= low_func
12543 && q
->symbol
.value
<= offset
)
12545 func
= (asymbol
*) q
;
12546 low_func
= q
->symbol
.value
;
12556 *filename_ptr
= filename
;
12557 if (functionname_ptr
)
12558 *functionname_ptr
= bfd_asymbol_name (func
);
12564 /* Find the nearest line to a particular section and offset, for error
12565 reporting. This code is a duplicate of the code in elf.c, except
12566 that it uses arm_elf_find_function. */
12569 elf32_arm_find_nearest_line (bfd
* abfd
,
12570 asection
* section
,
12571 asymbol
** symbols
,
12573 const char ** filename_ptr
,
12574 const char ** functionname_ptr
,
12575 unsigned int * line_ptr
)
12577 bfd_boolean found
= FALSE
;
12579 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
12581 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
12582 filename_ptr
, functionname_ptr
,
12584 & elf_tdata (abfd
)->dwarf2_find_line_info
))
12586 if (!*functionname_ptr
)
12587 arm_elf_find_function (abfd
, section
, symbols
, offset
,
12588 *filename_ptr
? NULL
: filename_ptr
,
12594 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
12595 & found
, filename_ptr
,
12596 functionname_ptr
, line_ptr
,
12597 & elf_tdata (abfd
)->line_info
))
12600 if (found
&& (*functionname_ptr
|| *line_ptr
))
12603 if (symbols
== NULL
)
12606 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
12607 filename_ptr
, functionname_ptr
))
12615 elf32_arm_find_inliner_info (bfd
* abfd
,
12616 const char ** filename_ptr
,
12617 const char ** functionname_ptr
,
12618 unsigned int * line_ptr
)
12621 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
12622 functionname_ptr
, line_ptr
,
12623 & elf_tdata (abfd
)->dwarf2_find_line_info
);
12627 /* Adjust a symbol defined by a dynamic object and referenced by a
12628 regular object. The current definition is in some section of the
12629 dynamic object, but we're not including those sections. We have to
12630 change the definition to something the rest of the link can
12634 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
12635 struct elf_link_hash_entry
* h
)
12639 struct elf32_arm_link_hash_entry
* eh
;
12640 struct elf32_arm_link_hash_table
*globals
;
12642 globals
= elf32_arm_hash_table (info
);
12643 if (globals
== NULL
)
12646 dynobj
= elf_hash_table (info
)->dynobj
;
12648 /* Make sure we know what is going on here. */
12649 BFD_ASSERT (dynobj
!= NULL
12651 || h
->type
== STT_GNU_IFUNC
12652 || h
->u
.weakdef
!= NULL
12655 && !h
->def_regular
)));
12657 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12659 /* If this is a function, put it in the procedure linkage table. We
12660 will fill in the contents of the procedure linkage table later,
12661 when we know the address of the .got section. */
12662 if (h
->type
== STT_FUNC
|| h
->type
== STT_GNU_IFUNC
|| h
->needs_plt
)
12664 /* Calls to STT_GNU_IFUNC symbols always use a PLT, even if the
12665 symbol binds locally. */
12666 if (h
->plt
.refcount
<= 0
12667 || (h
->type
!= STT_GNU_IFUNC
12668 && (SYMBOL_CALLS_LOCAL (info
, h
)
12669 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
12670 && h
->root
.type
== bfd_link_hash_undefweak
))))
12672 /* This case can occur if we saw a PLT32 reloc in an input
12673 file, but the symbol was never referred to by a dynamic
12674 object, or if all references were garbage collected. In
12675 such a case, we don't actually need to build a procedure
12676 linkage table, and we can just do a PC24 reloc instead. */
12677 h
->plt
.offset
= (bfd_vma
) -1;
12678 eh
->plt
.thumb_refcount
= 0;
12679 eh
->plt
.maybe_thumb_refcount
= 0;
12680 eh
->plt
.noncall_refcount
= 0;
12688 /* It's possible that we incorrectly decided a .plt reloc was
12689 needed for an R_ARM_PC24 or similar reloc to a non-function sym
12690 in check_relocs. We can't decide accurately between function
12691 and non-function syms in check-relocs; Objects loaded later in
12692 the link may change h->type. So fix it now. */
12693 h
->plt
.offset
= (bfd_vma
) -1;
12694 eh
->plt
.thumb_refcount
= 0;
12695 eh
->plt
.maybe_thumb_refcount
= 0;
12696 eh
->plt
.noncall_refcount
= 0;
12699 /* If this is a weak symbol, and there is a real definition, the
12700 processor independent code will have arranged for us to see the
12701 real definition first, and we can just use the same value. */
12702 if (h
->u
.weakdef
!= NULL
)
12704 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
12705 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
12706 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
12707 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
12711 /* If there are no non-GOT references, we do not need a copy
12713 if (!h
->non_got_ref
)
12716 /* This is a reference to a symbol defined by a dynamic object which
12717 is not a function. */
12719 /* If we are creating a shared library, we must presume that the
12720 only references to the symbol are via the global offset table.
12721 For such cases we need not do anything here; the relocations will
12722 be handled correctly by relocate_section. Relocatable executables
12723 can reference data in shared objects directly, so we don't need to
12724 do anything here. */
12725 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
12730 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
12731 h
->root
.root
.string
);
12735 /* We must allocate the symbol in our .dynbss section, which will
12736 become part of the .bss section of the executable. There will be
12737 an entry for this symbol in the .dynsym section. The dynamic
12738 object will contain position independent code, so all references
12739 from the dynamic object to this symbol will go through the global
12740 offset table. The dynamic linker will use the .dynsym entry to
12741 determine the address it must put in the global offset table, so
12742 both the dynamic object and the regular object will refer to the
12743 same memory location for the variable. */
12744 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
12745 BFD_ASSERT (s
!= NULL
);
12747 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
12748 copy the initial value out of the dynamic object and into the
12749 runtime process image. We need to remember the offset into the
12750 .rel(a).bss section we are going to use. */
12751 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
12755 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
12756 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
12760 return _bfd_elf_adjust_dynamic_copy (h
, s
);
12763 /* Allocate space in .plt, .got and associated reloc sections for
12767 allocate_dynrelocs_for_symbol (struct elf_link_hash_entry
*h
, void * inf
)
12769 struct bfd_link_info
*info
;
12770 struct elf32_arm_link_hash_table
*htab
;
12771 struct elf32_arm_link_hash_entry
*eh
;
12772 struct elf_dyn_relocs
*p
;
12774 if (h
->root
.type
== bfd_link_hash_indirect
)
12777 if (h
->root
.type
== bfd_link_hash_warning
)
12778 /* When warning symbols are created, they **replace** the "real"
12779 entry in the hash table, thus we never get to see the real
12780 symbol in a hash traversal. So look at it now. */
12781 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12783 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12785 info
= (struct bfd_link_info
*) inf
;
12786 htab
= elf32_arm_hash_table (info
);
12790 if ((htab
->root
.dynamic_sections_created
|| h
->type
== STT_GNU_IFUNC
)
12791 && h
->plt
.refcount
> 0)
12793 /* Make sure this symbol is output as a dynamic symbol.
12794 Undefined weak syms won't yet be marked as dynamic. */
12795 if (h
->dynindx
== -1
12796 && !h
->forced_local
)
12798 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
12802 /* If the call in the PLT entry binds locally, the associated
12803 GOT entry should use an R_ARM_IRELATIVE relocation instead of
12804 the usual R_ARM_JUMP_SLOT. Put it in the .iplt section rather
12805 than the .plt section. */
12806 if (h
->type
== STT_GNU_IFUNC
&& SYMBOL_CALLS_LOCAL (info
, h
))
12809 if (eh
->plt
.noncall_refcount
== 0
12810 && SYMBOL_REFERENCES_LOCAL (info
, h
))
12811 /* All non-call references can be resolved directly.
12812 This means that they can (and in some cases, must)
12813 resolve directly to the run-time target, rather than
12814 to the PLT. That in turns means that any .got entry
12815 would be equal to the .igot.plt entry, so there's
12816 no point having both. */
12817 h
->got
.refcount
= 0;
12822 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
12824 elf32_arm_allocate_plt_entry (info
, eh
->is_iplt
, &h
->plt
, &eh
->plt
);
12826 /* If this symbol is not defined in a regular file, and we are
12827 not generating a shared library, then set the symbol to this
12828 location in the .plt. This is required to make function
12829 pointers compare as equal between the normal executable and
12830 the shared library. */
12832 && !h
->def_regular
)
12834 h
->root
.u
.def
.section
= htab
->root
.splt
;
12835 h
->root
.u
.def
.value
= h
->plt
.offset
;
12837 /* Make sure the function is not marked as Thumb, in case
12838 it is the target of an ABS32 relocation, which will
12839 point to the PLT entry. */
12840 h
->target_internal
= ST_BRANCH_TO_ARM
;
12843 htab
->next_tls_desc_index
++;
12845 /* VxWorks executables have a second set of relocations for
12846 each PLT entry. They go in a separate relocation section,
12847 which is processed by the kernel loader. */
12848 if (htab
->vxworks_p
&& !info
->shared
)
12850 /* There is a relocation for the initial PLT entry:
12851 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
12852 if (h
->plt
.offset
== htab
->plt_header_size
)
12853 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 1);
12855 /* There are two extra relocations for each subsequent
12856 PLT entry: an R_ARM_32 relocation for the GOT entry,
12857 and an R_ARM_32 relocation for the PLT entry. */
12858 elf32_arm_allocate_dynrelocs (info
, htab
->srelplt2
, 2);
12863 h
->plt
.offset
= (bfd_vma
) -1;
12869 h
->plt
.offset
= (bfd_vma
) -1;
12873 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12874 eh
->tlsdesc_got
= (bfd_vma
) -1;
12876 if (h
->got
.refcount
> 0)
12880 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
12883 /* Make sure this symbol is output as a dynamic symbol.
12884 Undefined weak syms won't yet be marked as dynamic. */
12885 if (h
->dynindx
== -1
12886 && !h
->forced_local
)
12888 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
12892 if (!htab
->symbian_p
)
12894 s
= htab
->root
.sgot
;
12895 h
->got
.offset
= s
->size
;
12897 if (tls_type
== GOT_UNKNOWN
)
12900 if (tls_type
== GOT_NORMAL
)
12901 /* Non-TLS symbols need one GOT slot. */
12905 if (tls_type
& GOT_TLS_GDESC
)
12907 /* R_ARM_TLS_DESC needs 2 GOT slots. */
12909 = (htab
->root
.sgotplt
->size
12910 - elf32_arm_compute_jump_table_size (htab
));
12911 htab
->root
.sgotplt
->size
+= 8;
12912 h
->got
.offset
= (bfd_vma
) -2;
12913 /* plt.got_offset needs to know there's a TLS_DESC
12914 reloc in the middle of .got.plt. */
12915 htab
->num_tls_desc
++;
12918 if (tls_type
& GOT_TLS_GD
)
12920 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. If
12921 the symbol is both GD and GDESC, got.offset may
12922 have been overwritten. */
12923 h
->got
.offset
= s
->size
;
12927 if (tls_type
& GOT_TLS_IE
)
12928 /* R_ARM_TLS_IE32 needs one GOT slot. */
12932 dyn
= htab
->root
.dynamic_sections_created
;
12935 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
12937 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
12940 if (tls_type
!= GOT_NORMAL
12941 && (info
->shared
|| indx
!= 0)
12942 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
12943 || h
->root
.type
!= bfd_link_hash_undefweak
))
12945 if (tls_type
& GOT_TLS_IE
)
12946 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
12948 if (tls_type
& GOT_TLS_GD
)
12949 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
12951 if (tls_type
& GOT_TLS_GDESC
)
12953 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
12954 /* GDESC needs a trampoline to jump to. */
12955 htab
->tls_trampoline
= -1;
12958 /* Only GD needs it. GDESC just emits one relocation per
12960 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
12961 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
12963 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
12965 if (htab
->root
.dynamic_sections_created
)
12966 /* Reserve room for the GOT entry's R_ARM_GLOB_DAT relocation. */
12967 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
12969 else if (h
->type
== STT_GNU_IFUNC
12970 && eh
->plt
.noncall_refcount
== 0)
12971 /* No non-call references resolve the STT_GNU_IFUNC's PLT entry;
12972 they all resolve dynamically instead. Reserve room for the
12973 GOT entry's R_ARM_IRELATIVE relocation. */
12974 elf32_arm_allocate_irelocs (info
, htab
->root
.srelgot
, 1);
12975 else if (info
->shared
)
12976 /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
12977 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
12981 h
->got
.offset
= (bfd_vma
) -1;
12983 /* Allocate stubs for exported Thumb functions on v4t. */
12984 if (!htab
->use_blx
&& h
->dynindx
!= -1
12986 && h
->target_internal
== ST_BRANCH_TO_THUMB
12987 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
12989 struct elf_link_hash_entry
* th
;
12990 struct bfd_link_hash_entry
* bh
;
12991 struct elf_link_hash_entry
* myh
;
12995 /* Create a new symbol to regist the real location of the function. */
12996 s
= h
->root
.u
.def
.section
;
12997 sprintf (name
, "__real_%s", h
->root
.root
.string
);
12998 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
12999 name
, BSF_GLOBAL
, s
,
13000 h
->root
.u
.def
.value
,
13001 NULL
, TRUE
, FALSE
, &bh
);
13003 myh
= (struct elf_link_hash_entry
*) bh
;
13004 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
13005 myh
->forced_local
= 1;
13006 myh
->target_internal
= ST_BRANCH_TO_THUMB
;
13007 eh
->export_glue
= myh
;
13008 th
= record_arm_to_thumb_glue (info
, h
);
13009 /* Point the symbol at the stub. */
13010 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
13011 h
->target_internal
= ST_BRANCH_TO_ARM
;
13012 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
13013 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
13016 if (eh
->dyn_relocs
== NULL
)
13019 /* In the shared -Bsymbolic case, discard space allocated for
13020 dynamic pc-relative relocs against symbols which turn out to be
13021 defined in regular objects. For the normal shared case, discard
13022 space for pc-relative relocs that have become local due to symbol
13023 visibility changes. */
13025 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
13027 /* The only relocs that use pc_count are R_ARM_REL32 and
13028 R_ARM_REL32_NOI, which will appear on something like
13029 ".long foo - .". We want calls to protected symbols to resolve
13030 directly to the function rather than going via the plt. If people
13031 want function pointer comparisons to work as expected then they
13032 should avoid writing assembly like ".long foo - .". */
13033 if (SYMBOL_CALLS_LOCAL (info
, h
))
13035 struct elf_dyn_relocs
**pp
;
13037 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13039 p
->count
-= p
->pc_count
;
13048 if (htab
->vxworks_p
)
13050 struct elf_dyn_relocs
**pp
;
13052 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
13054 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
13061 /* Also discard relocs on undefined weak syms with non-default
13063 if (eh
->dyn_relocs
!= NULL
13064 && h
->root
.type
== bfd_link_hash_undefweak
)
13066 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
13067 eh
->dyn_relocs
= NULL
;
13069 /* Make sure undefined weak symbols are output as a dynamic
13071 else if (h
->dynindx
== -1
13072 && !h
->forced_local
)
13074 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13079 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
13080 && h
->root
.type
== bfd_link_hash_new
)
13082 /* Output absolute symbols so that we can create relocations
13083 against them. For normal symbols we output a relocation
13084 against the section that contains them. */
13085 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13092 /* For the non-shared case, discard space for relocs against
13093 symbols which turn out to need copy relocs or are not
13096 if (!h
->non_got_ref
13097 && ((h
->def_dynamic
13098 && !h
->def_regular
)
13099 || (htab
->root
.dynamic_sections_created
13100 && (h
->root
.type
== bfd_link_hash_undefweak
13101 || h
->root
.type
== bfd_link_hash_undefined
))))
13103 /* Make sure this symbol is output as a dynamic symbol.
13104 Undefined weak syms won't yet be marked as dynamic. */
13105 if (h
->dynindx
== -1
13106 && !h
->forced_local
)
13108 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
13112 /* If that succeeded, we know we'll be keeping all the
13114 if (h
->dynindx
!= -1)
13118 eh
->dyn_relocs
= NULL
;
13123 /* Finally, allocate space. */
13124 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13126 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
13127 if (h
->type
== STT_GNU_IFUNC
13128 && eh
->plt
.noncall_refcount
== 0
13129 && SYMBOL_REFERENCES_LOCAL (info
, h
))
13130 elf32_arm_allocate_irelocs (info
, sreloc
, p
->count
);
13132 elf32_arm_allocate_dynrelocs (info
, sreloc
, p
->count
);
13138 /* Find any dynamic relocs that apply to read-only sections. */
13141 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
13143 struct elf32_arm_link_hash_entry
* eh
;
13144 struct elf_dyn_relocs
* p
;
13146 if (h
->root
.type
== bfd_link_hash_warning
)
13147 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
13149 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13150 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13152 asection
*s
= p
->sec
;
13154 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
13156 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
13158 info
->flags
|= DF_TEXTREL
;
13160 /* Not an error, just cut short the traversal. */
13168 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
13171 struct elf32_arm_link_hash_table
*globals
;
13173 globals
= elf32_arm_hash_table (info
);
13174 if (globals
== NULL
)
13177 globals
->byteswap_code
= byteswap_code
;
13180 /* Set the sizes of the dynamic sections. */
13183 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
13184 struct bfd_link_info
* info
)
13189 bfd_boolean relocs
;
13191 struct elf32_arm_link_hash_table
*htab
;
13193 htab
= elf32_arm_hash_table (info
);
13197 dynobj
= elf_hash_table (info
)->dynobj
;
13198 BFD_ASSERT (dynobj
!= NULL
);
13199 check_use_blx (htab
);
13201 if (elf_hash_table (info
)->dynamic_sections_created
)
13203 /* Set the contents of the .interp section to the interpreter. */
13204 if (info
->executable
)
13206 s
= bfd_get_section_by_name (dynobj
, ".interp");
13207 BFD_ASSERT (s
!= NULL
);
13208 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
13209 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
13213 /* Set up .got offsets for local syms, and space for local dynamic
13215 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
13217 bfd_signed_vma
*local_got
;
13218 bfd_signed_vma
*end_local_got
;
13219 struct arm_local_iplt_info
**local_iplt_ptr
, *local_iplt
;
13220 char *local_tls_type
;
13221 bfd_vma
*local_tlsdesc_gotent
;
13222 bfd_size_type locsymcount
;
13223 Elf_Internal_Shdr
*symtab_hdr
;
13225 bfd_boolean is_vxworks
= htab
->vxworks_p
;
13226 unsigned int symndx
;
13228 if (! is_arm_elf (ibfd
))
13231 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
13233 struct elf_dyn_relocs
*p
;
13235 for (p
= (struct elf_dyn_relocs
*)
13236 elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
13238 if (!bfd_is_abs_section (p
->sec
)
13239 && bfd_is_abs_section (p
->sec
->output_section
))
13241 /* Input section has been discarded, either because
13242 it is a copy of a linkonce section or due to
13243 linker script /DISCARD/, so we'll be discarding
13246 else if (is_vxworks
13247 && strcmp (p
->sec
->output_section
->name
,
13250 /* Relocations in vxworks .tls_vars sections are
13251 handled specially by the loader. */
13253 else if (p
->count
!= 0)
13255 srel
= elf_section_data (p
->sec
)->sreloc
;
13256 elf32_arm_allocate_dynrelocs (info
, srel
, p
->count
);
13257 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
13258 info
->flags
|= DF_TEXTREL
;
13263 local_got
= elf_local_got_refcounts (ibfd
);
13267 symtab_hdr
= & elf_symtab_hdr (ibfd
);
13268 locsymcount
= symtab_hdr
->sh_info
;
13269 end_local_got
= local_got
+ locsymcount
;
13270 local_iplt_ptr
= elf32_arm_local_iplt (ibfd
);
13271 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
13272 local_tlsdesc_gotent
= elf32_arm_local_tlsdesc_gotent (ibfd
);
13274 s
= htab
->root
.sgot
;
13275 srel
= htab
->root
.srelgot
;
13276 for (; local_got
< end_local_got
;
13277 ++local_got
, ++local_iplt_ptr
, ++local_tls_type
,
13278 ++local_tlsdesc_gotent
, ++symndx
)
13280 *local_tlsdesc_gotent
= (bfd_vma
) -1;
13281 local_iplt
= *local_iplt_ptr
;
13282 if (local_iplt
!= NULL
)
13284 struct elf_dyn_relocs
*p
;
13286 if (local_iplt
->root
.refcount
> 0)
13288 elf32_arm_allocate_plt_entry (info
, TRUE
,
13291 if (local_iplt
->arm
.noncall_refcount
== 0)
13292 /* All references to the PLT are calls, so all
13293 non-call references can resolve directly to the
13294 run-time target. This means that the .got entry
13295 would be the same as the .igot.plt entry, so there's
13296 no point creating both. */
13301 BFD_ASSERT (local_iplt
->arm
.noncall_refcount
== 0);
13302 local_iplt
->root
.offset
= (bfd_vma
) -1;
13305 for (p
= local_iplt
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
13309 psrel
= elf_section_data (p
->sec
)->sreloc
;
13310 if (local_iplt
->arm
.noncall_refcount
== 0)
13311 elf32_arm_allocate_irelocs (info
, psrel
, p
->count
);
13313 elf32_arm_allocate_dynrelocs (info
, psrel
, p
->count
);
13316 if (*local_got
> 0)
13318 Elf_Internal_Sym
*isym
;
13320 *local_got
= s
->size
;
13321 if (*local_tls_type
& GOT_TLS_GD
)
13322 /* TLS_GD relocs need an 8-byte structure in the GOT. */
13324 if (*local_tls_type
& GOT_TLS_GDESC
)
13326 *local_tlsdesc_gotent
= htab
->root
.sgotplt
->size
13327 - elf32_arm_compute_jump_table_size (htab
);
13328 htab
->root
.sgotplt
->size
+= 8;
13329 *local_got
= (bfd_vma
) -2;
13330 /* plt.got_offset needs to know there's a TLS_DESC
13331 reloc in the middle of .got.plt. */
13332 htab
->num_tls_desc
++;
13334 if (*local_tls_type
& GOT_TLS_IE
)
13337 if (*local_tls_type
& GOT_NORMAL
)
13339 /* If the symbol is both GD and GDESC, *local_got
13340 may have been overwritten. */
13341 *local_got
= s
->size
;
13345 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, symndx
);
13349 /* If all references to an STT_GNU_IFUNC PLT are calls,
13350 then all non-call references, including this GOT entry,
13351 resolve directly to the run-time target. */
13352 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
13353 && (local_iplt
== NULL
13354 || local_iplt
->arm
.noncall_refcount
== 0))
13355 elf32_arm_allocate_irelocs (info
, srel
, 1);
13356 else if ((info
->shared
&& !(*local_tls_type
& GOT_TLS_GDESC
))
13357 || *local_tls_type
& GOT_TLS_GD
)
13358 elf32_arm_allocate_dynrelocs (info
, srel
, 1);
13360 if (info
->shared
&& *local_tls_type
& GOT_TLS_GDESC
)
13362 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelplt
, 1);
13363 htab
->tls_trampoline
= -1;
13367 *local_got
= (bfd_vma
) -1;
13371 if (htab
->tls_ldm_got
.refcount
> 0)
13373 /* Allocate two GOT entries and one dynamic relocation (if necessary)
13374 for R_ARM_TLS_LDM32 relocations. */
13375 htab
->tls_ldm_got
.offset
= htab
->root
.sgot
->size
;
13376 htab
->root
.sgot
->size
+= 8;
13378 elf32_arm_allocate_dynrelocs (info
, htab
->root
.srelgot
, 1);
13381 htab
->tls_ldm_got
.offset
= -1;
13383 /* Allocate global sym .plt and .got entries, and space for global
13384 sym dynamic relocs. */
13385 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs_for_symbol
, info
);
13387 /* Here we rummage through the found bfds to collect glue information. */
13388 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
13390 if (! is_arm_elf (ibfd
))
13393 /* Initialise mapping tables for code/data. */
13394 bfd_elf32_arm_init_maps (ibfd
);
13396 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
13397 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
13398 /* xgettext:c-format */
13399 _bfd_error_handler (_("Errors encountered processing file %s"),
13403 /* Allocate space for the glue sections now that we've sized them. */
13404 bfd_elf32_arm_allocate_interworking_sections (info
);
13406 /* For every jump slot reserved in the sgotplt, reloc_count is
13407 incremented. However, when we reserve space for TLS descriptors,
13408 it's not incremented, so in order to compute the space reserved
13409 for them, it suffices to multiply the reloc count by the jump
13411 if (htab
->root
.srelplt
)
13412 htab
->sgotplt_jump_table_size
= elf32_arm_compute_jump_table_size(htab
);
13414 if (htab
->tls_trampoline
)
13416 if (htab
->root
.splt
->size
== 0)
13417 htab
->root
.splt
->size
+= htab
->plt_header_size
;
13419 htab
->tls_trampoline
= htab
->root
.splt
->size
;
13420 htab
->root
.splt
->size
+= htab
->plt_entry_size
;
13422 /* If we're not using lazy TLS relocations, don't generate the
13423 PLT and GOT entries they require. */
13424 if (!(info
->flags
& DF_BIND_NOW
))
13426 htab
->dt_tlsdesc_got
= htab
->root
.sgot
->size
;
13427 htab
->root
.sgot
->size
+= 4;
13429 htab
->dt_tlsdesc_plt
= htab
->root
.splt
->size
;
13430 htab
->root
.splt
->size
+= 4 * ARRAY_SIZE (dl_tlsdesc_lazy_trampoline
);
13434 /* The check_relocs and adjust_dynamic_symbol entry points have
13435 determined the sizes of the various dynamic sections. Allocate
13436 memory for them. */
13439 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
13443 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
13446 /* It's OK to base decisions on the section name, because none
13447 of the dynobj section names depend upon the input files. */
13448 name
= bfd_get_section_name (dynobj
, s
);
13450 if (s
== htab
->root
.splt
)
13452 /* Remember whether there is a PLT. */
13453 plt
= s
->size
!= 0;
13455 else if (CONST_STRNEQ (name
, ".rel"))
13459 /* Remember whether there are any reloc sections other
13460 than .rel(a).plt and .rela.plt.unloaded. */
13461 if (s
!= htab
->root
.srelplt
&& s
!= htab
->srelplt2
)
13464 /* We use the reloc_count field as a counter if we need
13465 to copy relocs into the output file. */
13466 s
->reloc_count
= 0;
13469 else if (s
!= htab
->root
.sgot
13470 && s
!= htab
->root
.sgotplt
13471 && s
!= htab
->root
.iplt
13472 && s
!= htab
->root
.igotplt
13473 && s
!= htab
->sdynbss
)
13475 /* It's not one of our sections, so don't allocate space. */
13481 /* If we don't need this section, strip it from the
13482 output file. This is mostly to handle .rel(a).bss and
13483 .rel(a).plt. We must create both sections in
13484 create_dynamic_sections, because they must be created
13485 before the linker maps input sections to output
13486 sections. The linker does that before
13487 adjust_dynamic_symbol is called, and it is that
13488 function which decides whether anything needs to go
13489 into these sections. */
13490 s
->flags
|= SEC_EXCLUDE
;
13494 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
13497 /* Allocate memory for the section contents. */
13498 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
13499 if (s
->contents
== NULL
)
13503 if (elf_hash_table (info
)->dynamic_sections_created
)
13505 /* Add some entries to the .dynamic section. We fill in the
13506 values later, in elf32_arm_finish_dynamic_sections, but we
13507 must add the entries now so that we get the correct size for
13508 the .dynamic section. The DT_DEBUG entry is filled in by the
13509 dynamic linker and used by the debugger. */
13510 #define add_dynamic_entry(TAG, VAL) \
13511 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
13513 if (info
->executable
)
13515 if (!add_dynamic_entry (DT_DEBUG
, 0))
13521 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
13522 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
13523 || !add_dynamic_entry (DT_PLTREL
,
13524 htab
->use_rel
? DT_REL
: DT_RELA
)
13525 || !add_dynamic_entry (DT_JMPREL
, 0))
13528 if (htab
->dt_tlsdesc_plt
&&
13529 (!add_dynamic_entry (DT_TLSDESC_PLT
,0)
13530 || !add_dynamic_entry (DT_TLSDESC_GOT
,0)))
13538 if (!add_dynamic_entry (DT_REL
, 0)
13539 || !add_dynamic_entry (DT_RELSZ
, 0)
13540 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
13545 if (!add_dynamic_entry (DT_RELA
, 0)
13546 || !add_dynamic_entry (DT_RELASZ
, 0)
13547 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
13552 /* If any dynamic relocs apply to a read-only section,
13553 then we need a DT_TEXTREL entry. */
13554 if ((info
->flags
& DF_TEXTREL
) == 0)
13555 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
13558 if ((info
->flags
& DF_TEXTREL
) != 0)
13560 if (!add_dynamic_entry (DT_TEXTREL
, 0))
13563 if (htab
->vxworks_p
13564 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
13567 #undef add_dynamic_entry
13572 /* Size sections even though they're not dynamic. We use it to setup
13573 _TLS_MODULE_BASE_, if needed. */
13576 elf32_arm_always_size_sections (bfd
*output_bfd
,
13577 struct bfd_link_info
*info
)
13581 if (info
->relocatable
)
13584 tls_sec
= elf_hash_table (info
)->tls_sec
;
13588 struct elf_link_hash_entry
*tlsbase
;
13590 tlsbase
= elf_link_hash_lookup
13591 (elf_hash_table (info
), "_TLS_MODULE_BASE_", TRUE
, TRUE
, FALSE
);
13595 struct bfd_link_hash_entry
*bh
= NULL
;
13596 const struct elf_backend_data
*bed
13597 = get_elf_backend_data (output_bfd
);
13599 if (!(_bfd_generic_link_add_one_symbol
13600 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
13601 tls_sec
, 0, NULL
, FALSE
,
13602 bed
->collect
, &bh
)))
13605 tlsbase
->type
= STT_TLS
;
13606 tlsbase
= (struct elf_link_hash_entry
*)bh
;
13607 tlsbase
->def_regular
= 1;
13608 tlsbase
->other
= STV_HIDDEN
;
13609 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
13615 /* Finish up dynamic symbol handling. We set the contents of various
13616 dynamic sections here. */
13619 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
13620 struct bfd_link_info
* info
,
13621 struct elf_link_hash_entry
* h
,
13622 Elf_Internal_Sym
* sym
)
13624 struct elf32_arm_link_hash_table
*htab
;
13625 struct elf32_arm_link_hash_entry
*eh
;
13627 htab
= elf32_arm_hash_table (info
);
13631 eh
= (struct elf32_arm_link_hash_entry
*) h
;
13633 if (h
->plt
.offset
!= (bfd_vma
) -1)
13637 BFD_ASSERT (h
->dynindx
!= -1);
13638 elf32_arm_populate_plt_entry (output_bfd
, info
, &h
->plt
, &eh
->plt
,
13642 if (!h
->def_regular
)
13644 /* Mark the symbol as undefined, rather than as defined in
13645 the .plt section. Leave the value alone. */
13646 sym
->st_shndx
= SHN_UNDEF
;
13647 /* If the symbol is weak, we do need to clear the value.
13648 Otherwise, the PLT entry would provide a definition for
13649 the symbol even if the symbol wasn't defined anywhere,
13650 and so the symbol would never be NULL. */
13651 if (!h
->ref_regular_nonweak
)
13654 else if (eh
->is_iplt
&& eh
->plt
.noncall_refcount
!= 0)
13656 /* At least one non-call relocation references this .iplt entry,
13657 so the .iplt entry is the function's canonical address. */
13658 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
13659 sym
->st_target_internal
= ST_BRANCH_TO_ARM
;
13660 sym
->st_shndx
= (_bfd_elf_section_from_bfd_section
13661 (output_bfd
, htab
->root
.iplt
->output_section
));
13662 sym
->st_value
= (h
->plt
.offset
13663 + htab
->root
.iplt
->output_section
->vma
13664 + htab
->root
.iplt
->output_offset
);
13671 Elf_Internal_Rela rel
;
13673 /* This symbol needs a copy reloc. Set it up. */
13674 BFD_ASSERT (h
->dynindx
!= -1
13675 && (h
->root
.type
== bfd_link_hash_defined
13676 || h
->root
.type
== bfd_link_hash_defweak
));
13679 BFD_ASSERT (s
!= NULL
);
13682 rel
.r_offset
= (h
->root
.u
.def
.value
13683 + h
->root
.u
.def
.section
->output_section
->vma
13684 + h
->root
.u
.def
.section
->output_offset
);
13685 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
13686 elf32_arm_add_dynreloc (output_bfd
, info
, s
, &rel
);
13689 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
13690 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
13691 to the ".got" section. */
13692 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
13693 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
13694 sym
->st_shndx
= SHN_ABS
;
13700 arm_put_trampoline (struct elf32_arm_link_hash_table
*htab
, bfd
*output_bfd
,
13702 const unsigned long *template, unsigned count
)
13706 for (ix
= 0; ix
!= count
; ix
++)
13708 unsigned long insn
= template[ix
];
13710 /* Emit mov pc,rx if bx is not permitted. */
13711 if (htab
->fix_v4bx
== 1 && (insn
& 0x0ffffff0) == 0x012fff10)
13712 insn
= (insn
& 0xf000000f) | 0x01a0f000;
13713 put_arm_insn (htab
, output_bfd
, insn
, (char *)contents
+ ix
*4);
13717 /* Finish up the dynamic sections. */
13720 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
13725 struct elf32_arm_link_hash_table
*htab
;
13727 htab
= elf32_arm_hash_table (info
);
13731 dynobj
= elf_hash_table (info
)->dynobj
;
13733 sgot
= htab
->root
.sgotplt
;
13734 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
13736 if (elf_hash_table (info
)->dynamic_sections_created
)
13739 Elf32_External_Dyn
*dyncon
, *dynconend
;
13741 splt
= htab
->root
.splt
;
13742 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
13743 BFD_ASSERT (htab
->symbian_p
|| sgot
!= NULL
);
13745 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
13746 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
13748 for (; dyncon
< dynconend
; dyncon
++)
13750 Elf_Internal_Dyn dyn
;
13754 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
13761 if (htab
->vxworks_p
13762 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
13763 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13768 goto get_vma_if_bpabi
;
13771 goto get_vma_if_bpabi
;
13774 goto get_vma_if_bpabi
;
13776 name
= ".gnu.version";
13777 goto get_vma_if_bpabi
;
13779 name
= ".gnu.version_d";
13780 goto get_vma_if_bpabi
;
13782 name
= ".gnu.version_r";
13783 goto get_vma_if_bpabi
;
13789 name
= RELOC_SECTION (htab
, ".plt");
13791 s
= bfd_get_section_by_name (output_bfd
, name
);
13792 BFD_ASSERT (s
!= NULL
);
13793 if (!htab
->symbian_p
)
13794 dyn
.d_un
.d_ptr
= s
->vma
;
13796 /* In the BPABI, tags in the PT_DYNAMIC section point
13797 at the file offset, not the memory address, for the
13798 convenience of the post linker. */
13799 dyn
.d_un
.d_ptr
= s
->filepos
;
13800 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13804 if (htab
->symbian_p
)
13809 s
= htab
->root
.srelplt
;
13810 BFD_ASSERT (s
!= NULL
);
13811 dyn
.d_un
.d_val
= s
->size
;
13812 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13817 if (!htab
->symbian_p
)
13819 /* My reading of the SVR4 ABI indicates that the
13820 procedure linkage table relocs (DT_JMPREL) should be
13821 included in the overall relocs (DT_REL). This is
13822 what Solaris does. However, UnixWare can not handle
13823 that case. Therefore, we override the DT_RELSZ entry
13824 here to make it not include the JMPREL relocs. Since
13825 the linker script arranges for .rel(a).plt to follow all
13826 other relocation sections, we don't have to worry
13827 about changing the DT_REL entry. */
13828 s
= htab
->root
.srelplt
;
13830 dyn
.d_un
.d_val
-= s
->size
;
13831 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13834 /* Fall through. */
13838 /* In the BPABI, the DT_REL tag must point at the file
13839 offset, not the VMA, of the first relocation
13840 section. So, we use code similar to that in
13841 elflink.c, but do not check for SHF_ALLOC on the
13842 relcoation section, since relocations sections are
13843 never allocated under the BPABI. The comments above
13844 about Unixware notwithstanding, we include all of the
13845 relocations here. */
13846 if (htab
->symbian_p
)
13849 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
13850 ? SHT_REL
: SHT_RELA
);
13851 dyn
.d_un
.d_val
= 0;
13852 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
13854 Elf_Internal_Shdr
*hdr
13855 = elf_elfsections (output_bfd
)[i
];
13856 if (hdr
->sh_type
== type
)
13858 if (dyn
.d_tag
== DT_RELSZ
13859 || dyn
.d_tag
== DT_RELASZ
)
13860 dyn
.d_un
.d_val
+= hdr
->sh_size
;
13861 else if ((ufile_ptr
) hdr
->sh_offset
13862 <= dyn
.d_un
.d_val
- 1)
13863 dyn
.d_un
.d_val
= hdr
->sh_offset
;
13866 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13870 case DT_TLSDESC_PLT
:
13871 s
= htab
->root
.splt
;
13872 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
13873 + htab
->dt_tlsdesc_plt
);
13874 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13877 case DT_TLSDESC_GOT
:
13878 s
= htab
->root
.sgot
;
13879 dyn
.d_un
.d_ptr
= (s
->output_section
->vma
+ s
->output_offset
13880 + htab
->dt_tlsdesc_got
);
13881 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13884 /* Set the bottom bit of DT_INIT/FINI if the
13885 corresponding function is Thumb. */
13887 name
= info
->init_function
;
13890 name
= info
->fini_function
;
13892 /* If it wasn't set by elf_bfd_final_link
13893 then there is nothing to adjust. */
13894 if (dyn
.d_un
.d_val
!= 0)
13896 struct elf_link_hash_entry
* eh
;
13898 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
13899 FALSE
, FALSE
, TRUE
);
13900 if (eh
!= NULL
&& eh
->target_internal
== ST_BRANCH_TO_THUMB
)
13902 dyn
.d_un
.d_val
|= 1;
13903 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
13910 /* Fill in the first entry in the procedure linkage table. */
13911 if (splt
->size
> 0 && htab
->plt_header_size
)
13913 const bfd_vma
*plt0_entry
;
13914 bfd_vma got_address
, plt_address
, got_displacement
;
13916 /* Calculate the addresses of the GOT and PLT. */
13917 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
13918 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
13920 if (htab
->vxworks_p
)
13922 /* The VxWorks GOT is relocated by the dynamic linker.
13923 Therefore, we must emit relocations rather than simply
13924 computing the values now. */
13925 Elf_Internal_Rela rel
;
13927 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
13928 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
13929 splt
->contents
+ 0);
13930 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
13931 splt
->contents
+ 4);
13932 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
13933 splt
->contents
+ 8);
13934 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
13936 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
13937 rel
.r_offset
= plt_address
+ 12;
13938 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
13940 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
13941 htab
->srelplt2
->contents
);
13945 got_displacement
= got_address
- (plt_address
+ 16);
13947 plt0_entry
= elf32_arm_plt0_entry
;
13948 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
13949 splt
->contents
+ 0);
13950 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
13951 splt
->contents
+ 4);
13952 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
13953 splt
->contents
+ 8);
13954 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
13955 splt
->contents
+ 12);
13957 #ifdef FOUR_WORD_PLT
13958 /* The displacement value goes in the otherwise-unused
13959 last word of the second entry. */
13960 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
13962 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
13967 /* UnixWare sets the entsize of .plt to 4, although that doesn't
13968 really seem like the right value. */
13969 if (splt
->output_section
->owner
== output_bfd
)
13970 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
13972 if (htab
->dt_tlsdesc_plt
)
13974 bfd_vma got_address
13975 = sgot
->output_section
->vma
+ sgot
->output_offset
;
13976 bfd_vma gotplt_address
= (htab
->root
.sgot
->output_section
->vma
13977 + htab
->root
.sgot
->output_offset
);
13978 bfd_vma plt_address
13979 = splt
->output_section
->vma
+ splt
->output_offset
;
13981 arm_put_trampoline (htab
, output_bfd
,
13982 splt
->contents
+ htab
->dt_tlsdesc_plt
,
13983 dl_tlsdesc_lazy_trampoline
, 6);
13985 bfd_put_32 (output_bfd
,
13986 gotplt_address
+ htab
->dt_tlsdesc_got
13987 - (plt_address
+ htab
->dt_tlsdesc_plt
)
13988 - dl_tlsdesc_lazy_trampoline
[6],
13989 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24);
13990 bfd_put_32 (output_bfd
,
13991 got_address
- (plt_address
+ htab
->dt_tlsdesc_plt
)
13992 - dl_tlsdesc_lazy_trampoline
[7],
13993 splt
->contents
+ htab
->dt_tlsdesc_plt
+ 24 + 4);
13996 if (htab
->tls_trampoline
)
13998 arm_put_trampoline (htab
, output_bfd
,
13999 splt
->contents
+ htab
->tls_trampoline
,
14000 tls_trampoline
, 3);
14001 #ifdef FOUR_WORD_PLT
14002 bfd_put_32 (output_bfd
, 0x00000000,
14003 splt
->contents
+ htab
->tls_trampoline
+ 12);
14007 if (htab
->vxworks_p
&& !info
->shared
&& htab
->root
.splt
->size
> 0)
14009 /* Correct the .rel(a).plt.unloaded relocations. They will have
14010 incorrect symbol indexes. */
14014 num_plts
= ((htab
->root
.splt
->size
- htab
->plt_header_size
)
14015 / htab
->plt_entry_size
);
14016 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
14018 for (; num_plts
; num_plts
--)
14020 Elf_Internal_Rela rel
;
14022 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14023 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
14024 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14025 p
+= RELOC_SIZE (htab
);
14027 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
14028 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
14029 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
14030 p
+= RELOC_SIZE (htab
);
14035 /* Fill in the first three entries in the global offset table. */
14038 if (sgot
->size
> 0)
14041 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
14043 bfd_put_32 (output_bfd
,
14044 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
14046 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
14047 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
14050 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
14057 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
14059 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
14060 struct elf32_arm_link_hash_table
*globals
;
14062 i_ehdrp
= elf_elfheader (abfd
);
14064 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
14065 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
14067 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
14068 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
14072 globals
= elf32_arm_hash_table (link_info
);
14073 if (globals
!= NULL
&& globals
->byteswap_code
)
14074 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
14078 static enum elf_reloc_type_class
14079 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
14081 switch ((int) ELF32_R_TYPE (rela
->r_info
))
14083 case R_ARM_RELATIVE
:
14084 return reloc_class_relative
;
14085 case R_ARM_JUMP_SLOT
:
14086 return reloc_class_plt
;
14088 return reloc_class_copy
;
14090 return reloc_class_normal
;
14094 /* Set the right machine number for an Arm ELF file. */
14097 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
14099 if (hdr
->sh_type
== SHT_NOTE
)
14100 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
14106 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
14108 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
14111 /* Return TRUE if this is an unwinding table entry. */
14114 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
14116 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
14117 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
14121 /* Set the type and flags for an ARM section. We do this by
14122 the section name, which is a hack, but ought to work. */
14125 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
14129 name
= bfd_get_section_name (abfd
, sec
);
14131 if (is_arm_elf_unwind_section_name (abfd
, name
))
14133 hdr
->sh_type
= SHT_ARM_EXIDX
;
14134 hdr
->sh_flags
|= SHF_LINK_ORDER
;
14139 /* Handle an ARM specific section when reading an object file. This is
14140 called when bfd_section_from_shdr finds a section with an unknown
14144 elf32_arm_section_from_shdr (bfd
*abfd
,
14145 Elf_Internal_Shdr
* hdr
,
14149 /* There ought to be a place to keep ELF backend specific flags, but
14150 at the moment there isn't one. We just keep track of the
14151 sections by their name, instead. Fortunately, the ABI gives
14152 names for all the ARM specific sections, so we will probably get
14154 switch (hdr
->sh_type
)
14156 case SHT_ARM_EXIDX
:
14157 case SHT_ARM_PREEMPTMAP
:
14158 case SHT_ARM_ATTRIBUTES
:
14165 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
14171 static _arm_elf_section_data
*
14172 get_arm_elf_section_data (asection
* sec
)
14174 if (sec
&& sec
->owner
&& is_arm_elf (sec
->owner
))
14175 return elf32_arm_section_data (sec
);
14183 struct bfd_link_info
*info
;
14186 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
14187 asection
*, struct elf_link_hash_entry
*);
14188 } output_arch_syminfo
;
14190 enum map_symbol_type
14198 /* Output a single mapping symbol. */
14201 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
14202 enum map_symbol_type type
,
14205 static const char *names
[3] = {"$a", "$t", "$d"};
14206 Elf_Internal_Sym sym
;
14208 sym
.st_value
= osi
->sec
->output_section
->vma
14209 + osi
->sec
->output_offset
14213 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
14214 sym
.st_shndx
= osi
->sec_shndx
;
14215 sym
.st_target_internal
= 0;
14216 elf32_arm_section_map_add (osi
->sec
, names
[type
][1], offset
);
14217 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
14220 /* Output mapping symbols for the PLT entry described by ROOT_PLT and ARM_PLT.
14221 IS_IPLT_ENTRY_P says whether the PLT is in .iplt rather than .plt. */
14224 elf32_arm_output_plt_map_1 (output_arch_syminfo
*osi
,
14225 bfd_boolean is_iplt_entry_p
,
14226 union gotplt_union
*root_plt
,
14227 struct arm_plt_info
*arm_plt
)
14229 struct elf32_arm_link_hash_table
*htab
;
14230 bfd_vma addr
, plt_header_size
;
14232 if (root_plt
->offset
== (bfd_vma
) -1)
14235 htab
= elf32_arm_hash_table (osi
->info
);
14239 if (is_iplt_entry_p
)
14241 osi
->sec
= htab
->root
.iplt
;
14242 plt_header_size
= 0;
14246 osi
->sec
= htab
->root
.splt
;
14247 plt_header_size
= htab
->plt_header_size
;
14249 osi
->sec_shndx
= (_bfd_elf_section_from_bfd_section
14250 (osi
->info
->output_bfd
, osi
->sec
->output_section
));
14252 addr
= root_plt
->offset
& -2;
14253 if (htab
->symbian_p
)
14255 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14257 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
14260 else if (htab
->vxworks_p
)
14262 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14264 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
14266 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
14268 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
14273 bfd_boolean thumb_stub_p
;
14275 thumb_stub_p
= elf32_arm_plt_needs_thumb_stub_p (osi
->info
, arm_plt
);
14278 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
14281 #ifdef FOUR_WORD_PLT
14282 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14284 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
14287 /* A three-word PLT with no Thumb thunk contains only Arm code,
14288 so only need to output a mapping symbol for the first PLT entry and
14289 entries with thumb thunks. */
14290 if (thumb_stub_p
|| addr
== plt_header_size
)
14292 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
14301 /* Output mapping symbols for PLT entries associated with H. */
14304 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
14306 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
14307 struct elf32_arm_link_hash_entry
*eh
;
14309 if (h
->root
.type
== bfd_link_hash_indirect
)
14312 if (h
->root
.type
== bfd_link_hash_warning
)
14313 /* When warning symbols are created, they **replace** the "real"
14314 entry in the hash table, thus we never get to see the real
14315 symbol in a hash traversal. So look at it now. */
14316 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
14318 eh
= (struct elf32_arm_link_hash_entry
*) h
;
14319 return elf32_arm_output_plt_map_1 (osi
, SYMBOL_CALLS_LOCAL (osi
->info
, h
),
14320 &h
->plt
, &eh
->plt
);
14323 /* Output a single local symbol for a generated stub. */
14326 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
14327 bfd_vma offset
, bfd_vma size
)
14329 Elf_Internal_Sym sym
;
14331 sym
.st_value
= osi
->sec
->output_section
->vma
14332 + osi
->sec
->output_offset
14334 sym
.st_size
= size
;
14336 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
14337 sym
.st_shndx
= osi
->sec_shndx
;
14338 sym
.st_target_internal
= 0;
14339 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
14343 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
14346 struct elf32_arm_stub_hash_entry
*stub_entry
;
14347 asection
*stub_sec
;
14350 output_arch_syminfo
*osi
;
14351 const insn_sequence
*template_sequence
;
14352 enum stub_insn_type prev_type
;
14355 enum map_symbol_type sym_type
;
14357 /* Massage our args to the form they really have. */
14358 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
14359 osi
= (output_arch_syminfo
*) in_arg
;
14361 stub_sec
= stub_entry
->stub_sec
;
14363 /* Ensure this stub is attached to the current section being
14365 if (stub_sec
!= osi
->sec
)
14368 addr
= (bfd_vma
) stub_entry
->stub_offset
;
14369 stub_name
= stub_entry
->output_name
;
14371 template_sequence
= stub_entry
->stub_template
;
14372 switch (template_sequence
[0].type
)
14375 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, stub_entry
->stub_size
))
14380 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
14381 stub_entry
->stub_size
))
14389 prev_type
= DATA_TYPE
;
14391 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
14393 switch (template_sequence
[i
].type
)
14396 sym_type
= ARM_MAP_ARM
;
14401 sym_type
= ARM_MAP_THUMB
;
14405 sym_type
= ARM_MAP_DATA
;
14413 if (template_sequence
[i
].type
!= prev_type
)
14415 prev_type
= template_sequence
[i
].type
;
14416 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
14420 switch (template_sequence
[i
].type
)
14444 /* Output mapping symbols for linker generated sections,
14445 and for those data-only sections that do not have a
14449 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
14450 struct bfd_link_info
*info
,
14452 int (*func
) (void *, const char *,
14453 Elf_Internal_Sym
*,
14455 struct elf_link_hash_entry
*))
14457 output_arch_syminfo osi
;
14458 struct elf32_arm_link_hash_table
*htab
;
14460 bfd_size_type size
;
14463 htab
= elf32_arm_hash_table (info
);
14467 check_use_blx (htab
);
14473 /* Add a $d mapping symbol to data-only sections that
14474 don't have any mapping symbol. This may result in (harmless) redundant
14475 mapping symbols. */
14476 for (input_bfd
= info
->input_bfds
;
14478 input_bfd
= input_bfd
->link_next
)
14480 if ((input_bfd
->flags
& (BFD_LINKER_CREATED
| HAS_SYMS
)) == HAS_SYMS
)
14481 for (osi
.sec
= input_bfd
->sections
;
14483 osi
.sec
= osi
.sec
->next
)
14485 if (osi
.sec
->output_section
!= NULL
14486 && ((osi
.sec
->output_section
->flags
& (SEC_ALLOC
| SEC_CODE
))
14488 && (osi
.sec
->flags
& (SEC_HAS_CONTENTS
| SEC_LINKER_CREATED
))
14489 == SEC_HAS_CONTENTS
14490 && get_arm_elf_section_data (osi
.sec
) != NULL
14491 && get_arm_elf_section_data (osi
.sec
)->mapcount
== 0
14492 && osi
.sec
->size
> 0)
14494 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14495 (output_bfd
, osi
.sec
->output_section
);
14496 if (osi
.sec_shndx
!= (int)SHN_BAD
)
14497 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 0);
14502 /* ARM->Thumb glue. */
14503 if (htab
->arm_glue_size
> 0)
14505 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
14506 ARM2THUMB_GLUE_SECTION_NAME
);
14508 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14509 (output_bfd
, osi
.sec
->output_section
);
14510 if (info
->shared
|| htab
->root
.is_relocatable_executable
14511 || htab
->pic_veneer
)
14512 size
= ARM2THUMB_PIC_GLUE_SIZE
;
14513 else if (htab
->use_blx
)
14514 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
14516 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
14518 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
14520 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
14521 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
14525 /* Thumb->ARM glue. */
14526 if (htab
->thumb_glue_size
> 0)
14528 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
14529 THUMB2ARM_GLUE_SECTION_NAME
);
14531 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14532 (output_bfd
, osi
.sec
->output_section
);
14533 size
= THUMB2ARM_GLUE_SIZE
;
14535 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
14537 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
14538 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
14542 /* ARMv4 BX veneers. */
14543 if (htab
->bx_glue_size
> 0)
14545 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
14546 ARM_BX_GLUE_SECTION_NAME
);
14548 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14549 (output_bfd
, osi
.sec
->output_section
);
14551 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
14554 /* Long calls stubs. */
14555 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
14557 asection
* stub_sec
;
14559 for (stub_sec
= htab
->stub_bfd
->sections
;
14561 stub_sec
= stub_sec
->next
)
14563 /* Ignore non-stub sections. */
14564 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
14567 osi
.sec
= stub_sec
;
14569 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
14570 (output_bfd
, osi
.sec
->output_section
);
14572 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
14576 /* Finally, output mapping symbols for the PLT. */
14577 if (htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
14579 osi
.sec
= htab
->root
.splt
;
14580 osi
.sec_shndx
= (_bfd_elf_section_from_bfd_section
14581 (output_bfd
, osi
.sec
->output_section
));
14583 /* Output mapping symbols for the plt header. SymbianOS does not have a
14585 if (htab
->vxworks_p
)
14587 /* VxWorks shared libraries have no PLT header. */
14590 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
14592 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
14596 else if (!htab
->symbian_p
)
14598 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
14600 #ifndef FOUR_WORD_PLT
14601 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
14606 if ((htab
->root
.splt
&& htab
->root
.splt
->size
> 0)
14607 || (htab
->root
.iplt
&& htab
->root
.iplt
->size
> 0))
14609 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, &osi
);
14610 for (input_bfd
= info
->input_bfds
;
14612 input_bfd
= input_bfd
->link_next
)
14614 struct arm_local_iplt_info
**local_iplt
;
14615 unsigned int i
, num_syms
;
14617 local_iplt
= elf32_arm_local_iplt (input_bfd
);
14618 if (local_iplt
!= NULL
)
14620 num_syms
= elf_symtab_hdr (input_bfd
).sh_info
;
14621 for (i
= 0; i
< num_syms
; i
++)
14622 if (local_iplt
[i
] != NULL
14623 && !elf32_arm_output_plt_map_1 (&osi
, TRUE
,
14624 &local_iplt
[i
]->root
,
14625 &local_iplt
[i
]->arm
))
14630 if (htab
->dt_tlsdesc_plt
!= 0)
14632 /* Mapping symbols for the lazy tls trampoline. */
14633 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->dt_tlsdesc_plt
))
14636 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
14637 htab
->dt_tlsdesc_plt
+ 24))
14640 if (htab
->tls_trampoline
!= 0)
14642 /* Mapping symbols for the tls trampoline. */
14643 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, htab
->tls_trampoline
))
14645 #ifdef FOUR_WORD_PLT
14646 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
,
14647 htab
->tls_trampoline
+ 12))
14655 /* Allocate target specific section data. */
14658 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
14660 if (!sec
->used_by_bfd
)
14662 _arm_elf_section_data
*sdata
;
14663 bfd_size_type amt
= sizeof (*sdata
);
14665 sdata
= (_arm_elf_section_data
*) bfd_zalloc (abfd
, amt
);
14668 sec
->used_by_bfd
= sdata
;
14671 return _bfd_elf_new_section_hook (abfd
, sec
);
14675 /* Used to order a list of mapping symbols by address. */
14678 elf32_arm_compare_mapping (const void * a
, const void * b
)
14680 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
14681 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
14683 if (amap
->vma
> bmap
->vma
)
14685 else if (amap
->vma
< bmap
->vma
)
14687 else if (amap
->type
> bmap
->type
)
14688 /* Ensure results do not depend on the host qsort for objects with
14689 multiple mapping symbols at the same address by sorting on type
14692 else if (amap
->type
< bmap
->type
)
14698 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
14700 static unsigned long
14701 offset_prel31 (unsigned long addr
, bfd_vma offset
)
14703 return (addr
& ~0x7ffffffful
) | ((addr
+ offset
) & 0x7ffffffful
);
14706 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
14710 copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
, bfd_vma offset
)
14712 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
14713 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
14715 /* High bit of first word is supposed to be zero. */
14716 if ((first_word
& 0x80000000ul
) == 0)
14717 first_word
= offset_prel31 (first_word
, offset
);
14719 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
14720 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
14721 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
14722 second_word
= offset_prel31 (second_word
, offset
);
14724 bfd_put_32 (output_bfd
, first_word
, to
);
14725 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
14728 /* Data for make_branch_to_a8_stub(). */
14730 struct a8_branch_to_stub_data
{
14731 asection
*writing_section
;
14732 bfd_byte
*contents
;
14736 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
14737 places for a particular section. */
14740 make_branch_to_a8_stub (struct bfd_hash_entry
*gen_entry
,
14743 struct elf32_arm_stub_hash_entry
*stub_entry
;
14744 struct a8_branch_to_stub_data
*data
;
14745 bfd_byte
*contents
;
14746 unsigned long branch_insn
;
14747 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
14748 bfd_signed_vma branch_offset
;
14750 unsigned int target
;
14752 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
14753 data
= (struct a8_branch_to_stub_data
*) in_arg
;
14755 if (stub_entry
->target_section
!= data
->writing_section
14756 || stub_entry
->stub_type
< arm_stub_a8_veneer_lwm
)
14759 contents
= data
->contents
;
14761 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
14762 + stub_entry
->target_section
->output_offset
14763 + stub_entry
->target_value
;
14765 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
14766 + stub_entry
->stub_sec
->output_offset
14767 + stub_entry
->stub_offset
;
14769 if (stub_entry
->stub_type
== arm_stub_a8_veneer_blx
)
14770 veneered_insn_loc
&= ~3u;
14772 branch_offset
= veneer_entry_loc
- veneered_insn_loc
- 4;
14774 abfd
= stub_entry
->target_section
->owner
;
14775 target
= stub_entry
->target_value
;
14777 /* We attempt to avoid this condition by setting stubs_always_after_branch
14778 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
14779 This check is just to be on the safe side... */
14780 if ((veneered_insn_loc
& ~0xfff) == (veneer_entry_loc
& ~0xfff))
14782 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub is "
14783 "allocated in unsafe location"), abfd
);
14787 switch (stub_entry
->stub_type
)
14789 case arm_stub_a8_veneer_b
:
14790 case arm_stub_a8_veneer_b_cond
:
14791 branch_insn
= 0xf0009000;
14794 case arm_stub_a8_veneer_blx
:
14795 branch_insn
= 0xf000e800;
14798 case arm_stub_a8_veneer_bl
:
14800 unsigned int i1
, j1
, i2
, j2
, s
;
14802 branch_insn
= 0xf000d000;
14805 if (branch_offset
< -16777216 || branch_offset
> 16777214)
14807 /* There's not much we can do apart from complain if this
14809 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub out "
14810 "of range (input file too large)"), abfd
);
14814 /* i1 = not(j1 eor s), so:
14816 j1 = (not i1) eor s. */
14818 branch_insn
|= (branch_offset
>> 1) & 0x7ff;
14819 branch_insn
|= ((branch_offset
>> 12) & 0x3ff) << 16;
14820 i2
= (branch_offset
>> 22) & 1;
14821 i1
= (branch_offset
>> 23) & 1;
14822 s
= (branch_offset
>> 24) & 1;
14825 branch_insn
|= j2
<< 11;
14826 branch_insn
|= j1
<< 13;
14827 branch_insn
|= s
<< 26;
14836 bfd_put_16 (abfd
, (branch_insn
>> 16) & 0xffff, &contents
[target
]);
14837 bfd_put_16 (abfd
, branch_insn
& 0xffff, &contents
[target
+ 2]);
14842 /* Do code byteswapping. Return FALSE afterwards so that the section is
14843 written out as normal. */
14846 elf32_arm_write_section (bfd
*output_bfd
,
14847 struct bfd_link_info
*link_info
,
14849 bfd_byte
*contents
)
14851 unsigned int mapcount
, errcount
;
14852 _arm_elf_section_data
*arm_data
;
14853 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
14854 elf32_arm_section_map
*map
;
14855 elf32_vfp11_erratum_list
*errnode
;
14858 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
14862 if (globals
== NULL
)
14865 /* If this section has not been allocated an _arm_elf_section_data
14866 structure then we cannot record anything. */
14867 arm_data
= get_arm_elf_section_data (sec
);
14868 if (arm_data
== NULL
)
14871 mapcount
= arm_data
->mapcount
;
14872 map
= arm_data
->map
;
14873 errcount
= arm_data
->erratumcount
;
14877 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
14879 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
14880 errnode
= errnode
->next
)
14882 bfd_vma target
= errnode
->vma
- offset
;
14884 switch (errnode
->type
)
14886 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
14888 bfd_vma branch_to_veneer
;
14889 /* Original condition code of instruction, plus bit mask for
14890 ARM B instruction. */
14891 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
14894 /* The instruction is before the label. */
14897 /* Above offset included in -4 below. */
14898 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
14899 - errnode
->vma
- 4;
14901 if ((signed) branch_to_veneer
< -(1 << 25)
14902 || (signed) branch_to_veneer
>= (1 << 25))
14903 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
14904 "range"), output_bfd
);
14906 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
14907 contents
[endianflip
^ target
] = insn
& 0xff;
14908 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
14909 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
14910 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
14914 case VFP11_ERRATUM_ARM_VENEER
:
14916 bfd_vma branch_from_veneer
;
14919 /* Take size of veneer into account. */
14920 branch_from_veneer
= errnode
->u
.v
.branch
->vma
14921 - errnode
->vma
- 12;
14923 if ((signed) branch_from_veneer
< -(1 << 25)
14924 || (signed) branch_from_veneer
>= (1 << 25))
14925 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
14926 "range"), output_bfd
);
14928 /* Original instruction. */
14929 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
14930 contents
[endianflip
^ target
] = insn
& 0xff;
14931 contents
[endianflip
^ (target
+ 1)] = (insn
>> 8) & 0xff;
14932 contents
[endianflip
^ (target
+ 2)] = (insn
>> 16) & 0xff;
14933 contents
[endianflip
^ (target
+ 3)] = (insn
>> 24) & 0xff;
14935 /* Branch back to insn after original insn. */
14936 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
14937 contents
[endianflip
^ (target
+ 4)] = insn
& 0xff;
14938 contents
[endianflip
^ (target
+ 5)] = (insn
>> 8) & 0xff;
14939 contents
[endianflip
^ (target
+ 6)] = (insn
>> 16) & 0xff;
14940 contents
[endianflip
^ (target
+ 7)] = (insn
>> 24) & 0xff;
14950 if (arm_data
->elf
.this_hdr
.sh_type
== SHT_ARM_EXIDX
)
14952 arm_unwind_table_edit
*edit_node
14953 = arm_data
->u
.exidx
.unwind_edit_list
;
14954 /* Now, sec->size is the size of the section we will write. The original
14955 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
14956 markers) was sec->rawsize. (This isn't the case if we perform no
14957 edits, then rawsize will be zero and we should use size). */
14958 bfd_byte
*edited_contents
= (bfd_byte
*) bfd_malloc (sec
->size
);
14959 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
14960 unsigned int in_index
, out_index
;
14961 bfd_vma add_to_offsets
= 0;
14963 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
14967 unsigned int edit_index
= edit_node
->index
;
14969 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
14971 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
14972 contents
+ in_index
* 8, add_to_offsets
);
14976 else if (in_index
== edit_index
14977 || (in_index
* 8 >= input_size
14978 && edit_index
== UINT_MAX
))
14980 switch (edit_node
->type
)
14982 case DELETE_EXIDX_ENTRY
:
14984 add_to_offsets
+= 8;
14987 case INSERT_EXIDX_CANTUNWIND_AT_END
:
14989 asection
*text_sec
= edit_node
->linked_section
;
14990 bfd_vma text_offset
= text_sec
->output_section
->vma
14991 + text_sec
->output_offset
14993 bfd_vma exidx_offset
= offset
+ out_index
* 8;
14994 unsigned long prel31_offset
;
14996 /* Note: this is meant to be equivalent to an
14997 R_ARM_PREL31 relocation. These synthetic
14998 EXIDX_CANTUNWIND markers are not relocated by the
14999 usual BFD method. */
15000 prel31_offset
= (text_offset
- exidx_offset
)
15003 /* First address we can't unwind. */
15004 bfd_put_32 (output_bfd
, prel31_offset
,
15005 &edited_contents
[out_index
* 8]);
15007 /* Code for EXIDX_CANTUNWIND. */
15008 bfd_put_32 (output_bfd
, 0x1,
15009 &edited_contents
[out_index
* 8 + 4]);
15012 add_to_offsets
-= 8;
15017 edit_node
= edit_node
->next
;
15022 /* No more edits, copy remaining entries verbatim. */
15023 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
15024 contents
+ in_index
* 8, add_to_offsets
);
15030 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
15031 bfd_set_section_contents (output_bfd
, sec
->output_section
,
15033 (file_ptr
) sec
->output_offset
, sec
->size
);
15038 /* Fix code to point to Cortex-A8 erratum stubs. */
15039 if (globals
->fix_cortex_a8
)
15041 struct a8_branch_to_stub_data data
;
15043 data
.writing_section
= sec
;
15044 data
.contents
= contents
;
15046 bfd_hash_traverse (&globals
->stub_hash_table
, make_branch_to_a8_stub
,
15053 if (globals
->byteswap_code
)
15055 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
15058 for (i
= 0; i
< mapcount
; i
++)
15060 if (i
== mapcount
- 1)
15063 end
= map
[i
+ 1].vma
;
15065 switch (map
[i
].type
)
15068 /* Byte swap code words. */
15069 while (ptr
+ 3 < end
)
15071 tmp
= contents
[ptr
];
15072 contents
[ptr
] = contents
[ptr
+ 3];
15073 contents
[ptr
+ 3] = tmp
;
15074 tmp
= contents
[ptr
+ 1];
15075 contents
[ptr
+ 1] = contents
[ptr
+ 2];
15076 contents
[ptr
+ 2] = tmp
;
15082 /* Byte swap code halfwords. */
15083 while (ptr
+ 1 < end
)
15085 tmp
= contents
[ptr
];
15086 contents
[ptr
] = contents
[ptr
+ 1];
15087 contents
[ptr
+ 1] = tmp
;
15093 /* Leave data alone. */
15101 arm_data
->mapcount
= -1;
15102 arm_data
->mapsize
= 0;
15103 arm_data
->map
= NULL
;
15108 /* Mangle thumb function symbols as we read them in. */
15111 elf32_arm_swap_symbol_in (bfd
* abfd
,
15114 Elf_Internal_Sym
*dst
)
15116 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
15119 /* New EABI objects mark thumb function symbols by setting the low bit of
15121 if ((ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
15122 || ELF_ST_TYPE (dst
->st_info
) == STT_GNU_IFUNC
)
15123 && (dst
->st_value
& 1))
15125 dst
->st_value
&= ~(bfd_vma
) 1;
15126 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15128 else if (ELF_ST_TYPE (dst
->st_info
) == STT_ARM_TFUNC
)
15130 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_FUNC
);
15131 dst
->st_target_internal
= ST_BRANCH_TO_THUMB
;
15133 else if (ELF_ST_TYPE (dst
->st_info
) == STT_SECTION
)
15134 dst
->st_target_internal
= ST_BRANCH_LONG
;
15136 dst
->st_target_internal
= ST_BRANCH_TO_ARM
;
15142 /* Mangle thumb function symbols as we write them out. */
15145 elf32_arm_swap_symbol_out (bfd
*abfd
,
15146 const Elf_Internal_Sym
*src
,
15150 Elf_Internal_Sym newsym
;
15152 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
15153 of the address set, as per the new EABI. We do this unconditionally
15154 because objcopy does not set the elf header flags until after
15155 it writes out the symbol table. */
15156 if (src
->st_target_internal
== ST_BRANCH_TO_THUMB
)
15159 if (ELF_ST_TYPE (src
->st_info
) != STT_GNU_IFUNC
)
15160 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
15161 if (newsym
.st_shndx
!= SHN_UNDEF
)
15163 /* Do this only for defined symbols. At link type, the static
15164 linker will simulate the work of dynamic linker of resolving
15165 symbols and will carry over the thumbness of found symbols to
15166 the output symbol table. It's not clear how it happens, but
15167 the thumbness of undefined symbols can well be different at
15168 runtime, and writing '1' for them will be confusing for users
15169 and possibly for dynamic linker itself.
15171 newsym
.st_value
|= 1;
15176 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
15179 /* Add the PT_ARM_EXIDX program header. */
15182 elf32_arm_modify_segment_map (bfd
*abfd
,
15183 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15185 struct elf_segment_map
*m
;
15188 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15189 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15191 /* If there is already a PT_ARM_EXIDX header, then we do not
15192 want to add another one. This situation arises when running
15193 "strip"; the input binary already has the header. */
15194 m
= elf_tdata (abfd
)->segment_map
;
15195 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
15199 m
= (struct elf_segment_map
*)
15200 bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
15203 m
->p_type
= PT_ARM_EXIDX
;
15205 m
->sections
[0] = sec
;
15207 m
->next
= elf_tdata (abfd
)->segment_map
;
15208 elf_tdata (abfd
)->segment_map
= m
;
15215 /* We may add a PT_ARM_EXIDX program header. */
15218 elf32_arm_additional_program_headers (bfd
*abfd
,
15219 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
15223 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
15224 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
15230 /* Hook called by the linker routine which adds symbols from an object
15234 elf32_arm_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
15235 Elf_Internal_Sym
*sym
, const char **namep
,
15236 flagword
*flagsp
, asection
**secp
, bfd_vma
*valp
)
15238 if ((abfd
->flags
& DYNAMIC
) == 0
15239 && (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
15240 || ELF_ST_BIND (sym
->st_info
) == STB_GNU_UNIQUE
))
15241 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= TRUE
;
15243 if (elf32_arm_hash_table (info
)->vxworks_p
15244 && !elf_vxworks_add_symbol_hook (abfd
, info
, sym
, namep
,
15245 flagsp
, secp
, valp
))
15251 /* We use this to override swap_symbol_in and swap_symbol_out. */
15252 const struct elf_size_info elf32_arm_size_info
=
15254 sizeof (Elf32_External_Ehdr
),
15255 sizeof (Elf32_External_Phdr
),
15256 sizeof (Elf32_External_Shdr
),
15257 sizeof (Elf32_External_Rel
),
15258 sizeof (Elf32_External_Rela
),
15259 sizeof (Elf32_External_Sym
),
15260 sizeof (Elf32_External_Dyn
),
15261 sizeof (Elf_External_Note
),
15265 ELFCLASS32
, EV_CURRENT
,
15266 bfd_elf32_write_out_phdrs
,
15267 bfd_elf32_write_shdrs_and_ehdr
,
15268 bfd_elf32_checksum_contents
,
15269 bfd_elf32_write_relocs
,
15270 elf32_arm_swap_symbol_in
,
15271 elf32_arm_swap_symbol_out
,
15272 bfd_elf32_slurp_reloc_table
,
15273 bfd_elf32_slurp_symbol_table
,
15274 bfd_elf32_swap_dyn_in
,
15275 bfd_elf32_swap_dyn_out
,
15276 bfd_elf32_swap_reloc_in
,
15277 bfd_elf32_swap_reloc_out
,
15278 bfd_elf32_swap_reloca_in
,
15279 bfd_elf32_swap_reloca_out
15282 #define ELF_ARCH bfd_arch_arm
15283 #define ELF_TARGET_ID ARM_ELF_DATA
15284 #define ELF_MACHINE_CODE EM_ARM
15285 #ifdef __QNXTARGET__
15286 #define ELF_MAXPAGESIZE 0x1000
15288 #define ELF_MAXPAGESIZE 0x8000
15290 #define ELF_MINPAGESIZE 0x1000
15291 #define ELF_COMMONPAGESIZE 0x1000
15293 #define bfd_elf32_mkobject elf32_arm_mkobject
15295 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
15296 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
15297 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
15298 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
15299 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
15300 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
15301 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
15302 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
15303 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
15304 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
15305 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
15306 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
15307 #define bfd_elf32_bfd_final_link elf32_arm_final_link
15309 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
15310 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
15311 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
15312 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
15313 #define elf_backend_check_relocs elf32_arm_check_relocs
15314 #define elf_backend_relocate_section elf32_arm_relocate_section
15315 #define elf_backend_write_section elf32_arm_write_section
15316 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
15317 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
15318 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
15319 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
15320 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
15321 #define elf_backend_always_size_sections elf32_arm_always_size_sections
15322 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
15323 #define elf_backend_post_process_headers elf32_arm_post_process_headers
15324 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
15325 #define elf_backend_object_p elf32_arm_object_p
15326 #define elf_backend_section_flags elf32_arm_section_flags
15327 #define elf_backend_fake_sections elf32_arm_fake_sections
15328 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
15329 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15330 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
15331 #define elf_backend_size_info elf32_arm_size_info
15332 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
15333 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
15334 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
15335 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
15336 #define elf_backend_add_symbol_hook elf32_arm_add_symbol_hook
15338 #define elf_backend_can_refcount 1
15339 #define elf_backend_can_gc_sections 1
15340 #define elf_backend_plt_readonly 1
15341 #define elf_backend_want_got_plt 1
15342 #define elf_backend_want_plt_sym 0
15343 #define elf_backend_may_use_rel_p 1
15344 #define elf_backend_may_use_rela_p 0
15345 #define elf_backend_default_use_rela_p 0
15347 #define elf_backend_got_header_size 12
15349 #undef elf_backend_obj_attrs_vendor
15350 #define elf_backend_obj_attrs_vendor "aeabi"
15351 #undef elf_backend_obj_attrs_section
15352 #define elf_backend_obj_attrs_section ".ARM.attributes"
15353 #undef elf_backend_obj_attrs_arg_type
15354 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
15355 #undef elf_backend_obj_attrs_section_type
15356 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
15357 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
15358 #define elf_backend_obj_attrs_handle_unknown elf32_arm_obj_attrs_handle_unknown
15360 #include "elf32-target.h"
15362 /* VxWorks Targets. */
15364 #undef TARGET_LITTLE_SYM
15365 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
15366 #undef TARGET_LITTLE_NAME
15367 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
15368 #undef TARGET_BIG_SYM
15369 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
15370 #undef TARGET_BIG_NAME
15371 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
15373 /* Like elf32_arm_link_hash_table_create -- but overrides
15374 appropriately for VxWorks. */
15376 static struct bfd_link_hash_table
*
15377 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
15379 struct bfd_link_hash_table
*ret
;
15381 ret
= elf32_arm_link_hash_table_create (abfd
);
15384 struct elf32_arm_link_hash_table
*htab
15385 = (struct elf32_arm_link_hash_table
*) ret
;
15387 htab
->vxworks_p
= 1;
15393 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
15395 elf32_arm_final_write_processing (abfd
, linker
);
15396 elf_vxworks_final_write_processing (abfd
, linker
);
15400 #define elf32_bed elf32_arm_vxworks_bed
15402 #undef bfd_elf32_bfd_link_hash_table_create
15403 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
15404 #undef elf_backend_final_write_processing
15405 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
15406 #undef elf_backend_emit_relocs
15407 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
15409 #undef elf_backend_may_use_rel_p
15410 #define elf_backend_may_use_rel_p 0
15411 #undef elf_backend_may_use_rela_p
15412 #define elf_backend_may_use_rela_p 1
15413 #undef elf_backend_default_use_rela_p
15414 #define elf_backend_default_use_rela_p 1
15415 #undef elf_backend_want_plt_sym
15416 #define elf_backend_want_plt_sym 1
15417 #undef ELF_MAXPAGESIZE
15418 #define ELF_MAXPAGESIZE 0x1000
15420 #include "elf32-target.h"
15423 /* Merge backend specific data from an object file to the output
15424 object file when linking. */
15427 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
15429 flagword out_flags
;
15431 bfd_boolean flags_compatible
= TRUE
;
15434 /* Check if we have the same endianess. */
15435 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
15438 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
15441 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
15444 /* The input BFD must have had its flags initialised. */
15445 /* The following seems bogus to me -- The flags are initialized in
15446 the assembler but I don't think an elf_flags_init field is
15447 written into the object. */
15448 /* BFD_ASSERT (elf_flags_init (ibfd)); */
15450 in_flags
= elf_elfheader (ibfd
)->e_flags
;
15451 out_flags
= elf_elfheader (obfd
)->e_flags
;
15453 /* In theory there is no reason why we couldn't handle this. However
15454 in practice it isn't even close to working and there is no real
15455 reason to want it. */
15456 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
15457 && !(ibfd
->flags
& DYNAMIC
)
15458 && (in_flags
& EF_ARM_BE8
))
15460 _bfd_error_handler (_("error: %B is already in final BE8 format"),
15465 if (!elf_flags_init (obfd
))
15467 /* If the input is the default architecture and had the default
15468 flags then do not bother setting the flags for the output
15469 architecture, instead allow future merges to do this. If no
15470 future merges ever set these flags then they will retain their
15471 uninitialised values, which surprise surprise, correspond
15472 to the default values. */
15473 if (bfd_get_arch_info (ibfd
)->the_default
15474 && elf_elfheader (ibfd
)->e_flags
== 0)
15477 elf_flags_init (obfd
) = TRUE
;
15478 elf_elfheader (obfd
)->e_flags
= in_flags
;
15480 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
15481 && bfd_get_arch_info (obfd
)->the_default
)
15482 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
15487 /* Determine what should happen if the input ARM architecture
15488 does not match the output ARM architecture. */
15489 if (! bfd_arm_merge_machines (ibfd
, obfd
))
15492 /* Identical flags must be compatible. */
15493 if (in_flags
== out_flags
)
15496 /* Check to see if the input BFD actually contains any sections. If
15497 not, its flags may not have been initialised either, but it
15498 cannot actually cause any incompatiblity. Do not short-circuit
15499 dynamic objects; their section list may be emptied by
15500 elf_link_add_object_symbols.
15502 Also check to see if there are no code sections in the input.
15503 In this case there is no need to check for code specific flags.
15504 XXX - do we need to worry about floating-point format compatability
15505 in data sections ? */
15506 if (!(ibfd
->flags
& DYNAMIC
))
15508 bfd_boolean null_input_bfd
= TRUE
;
15509 bfd_boolean only_data_sections
= TRUE
;
15511 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
15513 /* Ignore synthetic glue sections. */
15514 if (strcmp (sec
->name
, ".glue_7")
15515 && strcmp (sec
->name
, ".glue_7t"))
15517 if ((bfd_get_section_flags (ibfd
, sec
)
15518 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
15519 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
15520 only_data_sections
= FALSE
;
15522 null_input_bfd
= FALSE
;
15527 if (null_input_bfd
|| only_data_sections
)
15531 /* Complain about various flag mismatches. */
15532 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
15533 EF_ARM_EABI_VERSION (out_flags
)))
15536 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
15538 (in_flags
& EF_ARM_EABIMASK
) >> 24,
15539 (out_flags
& EF_ARM_EABIMASK
) >> 24);
15543 /* Not sure what needs to be checked for EABI versions >= 1. */
15544 /* VxWorks libraries do not use these flags. */
15545 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
15546 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
15547 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
15549 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
15552 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
15554 in_flags
& EF_ARM_APCS_26
? 26 : 32,
15555 out_flags
& EF_ARM_APCS_26
? 26 : 32);
15556 flags_compatible
= FALSE
;
15559 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
15561 if (in_flags
& EF_ARM_APCS_FLOAT
)
15563 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
15567 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
15570 flags_compatible
= FALSE
;
15573 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
15575 if (in_flags
& EF_ARM_VFP_FLOAT
)
15577 (_("error: %B uses VFP instructions, whereas %B does not"),
15581 (_("error: %B uses FPA instructions, whereas %B does not"),
15584 flags_compatible
= FALSE
;
15587 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
15589 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
15591 (_("error: %B uses Maverick instructions, whereas %B does not"),
15595 (_("error: %B does not use Maverick instructions, whereas %B does"),
15598 flags_compatible
= FALSE
;
15601 #ifdef EF_ARM_SOFT_FLOAT
15602 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
15604 /* We can allow interworking between code that is VFP format
15605 layout, and uses either soft float or integer regs for
15606 passing floating point arguments and results. We already
15607 know that the APCS_FLOAT flags match; similarly for VFP
15609 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
15610 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
15612 if (in_flags
& EF_ARM_SOFT_FLOAT
)
15614 (_("error: %B uses software FP, whereas %B uses hardware FP"),
15618 (_("error: %B uses hardware FP, whereas %B uses software FP"),
15621 flags_compatible
= FALSE
;
15626 /* Interworking mismatch is only a warning. */
15627 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
15629 if (in_flags
& EF_ARM_INTERWORK
)
15632 (_("Warning: %B supports interworking, whereas %B does not"),
15638 (_("Warning: %B does not support interworking, whereas %B does"),
15644 return flags_compatible
;
15648 /* Symbian OS Targets. */
15650 #undef TARGET_LITTLE_SYM
15651 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
15652 #undef TARGET_LITTLE_NAME
15653 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
15654 #undef TARGET_BIG_SYM
15655 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
15656 #undef TARGET_BIG_NAME
15657 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
15659 /* Like elf32_arm_link_hash_table_create -- but overrides
15660 appropriately for Symbian OS. */
15662 static struct bfd_link_hash_table
*
15663 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
15665 struct bfd_link_hash_table
*ret
;
15667 ret
= elf32_arm_link_hash_table_create (abfd
);
15670 struct elf32_arm_link_hash_table
*htab
15671 = (struct elf32_arm_link_hash_table
*)ret
;
15672 /* There is no PLT header for Symbian OS. */
15673 htab
->plt_header_size
= 0;
15674 /* The PLT entries are each one instruction and one word. */
15675 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
15676 htab
->symbian_p
= 1;
15677 /* Symbian uses armv5t or above, so use_blx is always true. */
15679 htab
->root
.is_relocatable_executable
= 1;
15684 static const struct bfd_elf_special_section
15685 elf32_arm_symbian_special_sections
[] =
15687 /* In a BPABI executable, the dynamic linking sections do not go in
15688 the loadable read-only segment. The post-linker may wish to
15689 refer to these sections, but they are not part of the final
15691 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
15692 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
15693 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
15694 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
15695 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
15696 /* These sections do not need to be writable as the SymbianOS
15697 postlinker will arrange things so that no dynamic relocation is
15699 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
15700 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
15701 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
15702 { NULL
, 0, 0, 0, 0 }
15706 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
15707 struct bfd_link_info
*link_info
)
15709 /* BPABI objects are never loaded directly by an OS kernel; they are
15710 processed by a postlinker first, into an OS-specific format. If
15711 the D_PAGED bit is set on the file, BFD will align segments on
15712 page boundaries, so that an OS can directly map the file. With
15713 BPABI objects, that just results in wasted space. In addition,
15714 because we clear the D_PAGED bit, map_sections_to_segments will
15715 recognize that the program headers should not be mapped into any
15716 loadable segment. */
15717 abfd
->flags
&= ~D_PAGED
;
15718 elf32_arm_begin_write_processing (abfd
, link_info
);
15722 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
15723 struct bfd_link_info
*info
)
15725 struct elf_segment_map
*m
;
15728 /* BPABI shared libraries and executables should have a PT_DYNAMIC
15729 segment. However, because the .dynamic section is not marked
15730 with SEC_LOAD, the generic ELF code will not create such a
15732 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
15735 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
15736 if (m
->p_type
== PT_DYNAMIC
)
15741 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
15742 m
->next
= elf_tdata (abfd
)->segment_map
;
15743 elf_tdata (abfd
)->segment_map
= m
;
15747 /* Also call the generic arm routine. */
15748 return elf32_arm_modify_segment_map (abfd
, info
);
15751 /* Return address for Ith PLT stub in section PLT, for relocation REL
15752 or (bfd_vma) -1 if it should not be included. */
15755 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
15756 const arelent
*rel ATTRIBUTE_UNUSED
)
15758 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
15763 #define elf32_bed elf32_arm_symbian_bed
15765 /* The dynamic sections are not allocated on SymbianOS; the postlinker
15766 will process them and then discard them. */
15767 #undef ELF_DYNAMIC_SEC_FLAGS
15768 #define ELF_DYNAMIC_SEC_FLAGS \
15769 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
15771 #undef elf_backend_emit_relocs
15773 #undef bfd_elf32_bfd_link_hash_table_create
15774 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
15775 #undef elf_backend_special_sections
15776 #define elf_backend_special_sections elf32_arm_symbian_special_sections
15777 #undef elf_backend_begin_write_processing
15778 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
15779 #undef elf_backend_final_write_processing
15780 #define elf_backend_final_write_processing elf32_arm_final_write_processing
15782 #undef elf_backend_modify_segment_map
15783 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
15785 /* There is no .got section for BPABI objects, and hence no header. */
15786 #undef elf_backend_got_header_size
15787 #define elf_backend_got_header_size 0
15789 /* Similarly, there is no .got.plt section. */
15790 #undef elf_backend_want_got_plt
15791 #define elf_backend_want_got_plt 0
15793 #undef elf_backend_plt_sym_val
15794 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
15796 #undef elf_backend_may_use_rel_p
15797 #define elf_backend_may_use_rel_p 1
15798 #undef elf_backend_may_use_rela_p
15799 #define elf_backend_may_use_rela_p 0
15800 #undef elf_backend_default_use_rela_p
15801 #define elf_backend_default_use_rela_p 0
15802 #undef elf_backend_want_plt_sym
15803 #define elf_backend_want_plt_sym 0
15804 #undef ELF_MAXPAGESIZE
15805 #define ELF_MAXPAGESIZE 0x8000
15807 #include "elf32-target.h"