1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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. */
24 #include "libiberty.h"
27 #include "elf-vxworks.h"
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
62 static struct elf_backend_data elf32_arm_vxworks_bed
;
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_SWI24
, /* type */
266 0, /* size (0 = byte, 1 = short, 2 = long) */
268 FALSE
, /* pc_relative */
270 complain_overflow_signed
,/* complain_on_overflow */
271 bfd_elf_generic_reloc
, /* special_function */
272 "R_ARM_SWI24", /* name */
273 FALSE
, /* partial_inplace */
274 0x00000000, /* src_mask */
275 0x00000000, /* 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 EMPTY_HOWTO (90), /* Unallocated. */
1360 HOWTO (R_ARM_PLT32_ABS
, /* type */
1362 2, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE
, /* pc_relative */
1366 complain_overflow_dont
,/* complain_on_overflow */
1367 bfd_elf_generic_reloc
, /* special_function */
1368 "R_ARM_PLT32_ABS", /* name */
1369 FALSE
, /* partial_inplace */
1370 0xffffffff, /* src_mask */
1371 0xffffffff, /* dst_mask */
1372 FALSE
), /* pcrel_offset */
1374 HOWTO (R_ARM_GOT_ABS
, /* type */
1376 2, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE
, /* pc_relative */
1380 complain_overflow_dont
,/* complain_on_overflow */
1381 bfd_elf_generic_reloc
, /* special_function */
1382 "R_ARM_GOT_ABS", /* name */
1383 FALSE
, /* partial_inplace */
1384 0xffffffff, /* src_mask */
1385 0xffffffff, /* dst_mask */
1386 FALSE
), /* pcrel_offset */
1388 HOWTO (R_ARM_GOT_PREL
, /* type */
1390 2, /* size (0 = byte, 1 = short, 2 = long) */
1392 TRUE
, /* pc_relative */
1394 complain_overflow_dont
, /* complain_on_overflow */
1395 bfd_elf_generic_reloc
, /* special_function */
1396 "R_ARM_GOT_PREL", /* name */
1397 FALSE
, /* partial_inplace */
1398 0xffffffff, /* src_mask */
1399 0xffffffff, /* dst_mask */
1400 TRUE
), /* pcrel_offset */
1402 HOWTO (R_ARM_GOT_BREL12
, /* type */
1404 2, /* size (0 = byte, 1 = short, 2 = long) */
1406 FALSE
, /* pc_relative */
1408 complain_overflow_bitfield
,/* complain_on_overflow */
1409 bfd_elf_generic_reloc
, /* special_function */
1410 "R_ARM_GOT_BREL12", /* name */
1411 FALSE
, /* partial_inplace */
1412 0x00000fff, /* src_mask */
1413 0x00000fff, /* dst_mask */
1414 FALSE
), /* pcrel_offset */
1416 HOWTO (R_ARM_GOTOFF12
, /* type */
1418 2, /* size (0 = byte, 1 = short, 2 = long) */
1420 FALSE
, /* pc_relative */
1422 complain_overflow_bitfield
,/* complain_on_overflow */
1423 bfd_elf_generic_reloc
, /* special_function */
1424 "R_ARM_GOTOFF12", /* name */
1425 FALSE
, /* partial_inplace */
1426 0x00000fff, /* src_mask */
1427 0x00000fff, /* dst_mask */
1428 FALSE
), /* pcrel_offset */
1430 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1432 /* GNU extension to record C++ vtable member usage */
1433 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1435 2, /* size (0 = byte, 1 = short, 2 = long) */
1437 FALSE
, /* pc_relative */
1439 complain_overflow_dont
, /* complain_on_overflow */
1440 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1441 "R_ARM_GNU_VTENTRY", /* name */
1442 FALSE
, /* partial_inplace */
1445 FALSE
), /* pcrel_offset */
1447 /* GNU extension to record C++ vtable hierarchy */
1448 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1450 2, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE
, /* pc_relative */
1454 complain_overflow_dont
, /* complain_on_overflow */
1455 NULL
, /* special_function */
1456 "R_ARM_GNU_VTINHERIT", /* name */
1457 FALSE
, /* partial_inplace */
1460 FALSE
), /* pcrel_offset */
1462 HOWTO (R_ARM_THM_JUMP11
, /* type */
1464 1, /* size (0 = byte, 1 = short, 2 = long) */
1466 TRUE
, /* pc_relative */
1468 complain_overflow_signed
, /* complain_on_overflow */
1469 bfd_elf_generic_reloc
, /* special_function */
1470 "R_ARM_THM_JUMP11", /* name */
1471 FALSE
, /* partial_inplace */
1472 0x000007ff, /* src_mask */
1473 0x000007ff, /* dst_mask */
1474 TRUE
), /* pcrel_offset */
1476 HOWTO (R_ARM_THM_JUMP8
, /* type */
1478 1, /* size (0 = byte, 1 = short, 2 = long) */
1480 TRUE
, /* pc_relative */
1482 complain_overflow_signed
, /* complain_on_overflow */
1483 bfd_elf_generic_reloc
, /* special_function */
1484 "R_ARM_THM_JUMP8", /* name */
1485 FALSE
, /* partial_inplace */
1486 0x000000ff, /* src_mask */
1487 0x000000ff, /* dst_mask */
1488 TRUE
), /* pcrel_offset */
1490 /* TLS relocations */
1491 HOWTO (R_ARM_TLS_GD32
, /* type */
1493 2, /* size (0 = byte, 1 = short, 2 = long) */
1495 FALSE
, /* pc_relative */
1497 complain_overflow_bitfield
,/* complain_on_overflow */
1498 NULL
, /* special_function */
1499 "R_ARM_TLS_GD32", /* name */
1500 TRUE
, /* partial_inplace */
1501 0xffffffff, /* src_mask */
1502 0xffffffff, /* dst_mask */
1503 FALSE
), /* pcrel_offset */
1505 HOWTO (R_ARM_TLS_LDM32
, /* type */
1507 2, /* size (0 = byte, 1 = short, 2 = long) */
1509 FALSE
, /* pc_relative */
1511 complain_overflow_bitfield
,/* complain_on_overflow */
1512 bfd_elf_generic_reloc
, /* special_function */
1513 "R_ARM_TLS_LDM32", /* name */
1514 TRUE
, /* partial_inplace */
1515 0xffffffff, /* src_mask */
1516 0xffffffff, /* dst_mask */
1517 FALSE
), /* pcrel_offset */
1519 HOWTO (R_ARM_TLS_LDO32
, /* type */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 FALSE
, /* pc_relative */
1525 complain_overflow_bitfield
,/* complain_on_overflow */
1526 bfd_elf_generic_reloc
, /* special_function */
1527 "R_ARM_TLS_LDO32", /* name */
1528 TRUE
, /* partial_inplace */
1529 0xffffffff, /* src_mask */
1530 0xffffffff, /* dst_mask */
1531 FALSE
), /* pcrel_offset */
1533 HOWTO (R_ARM_TLS_IE32
, /* type */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE
, /* pc_relative */
1539 complain_overflow_bitfield
,/* complain_on_overflow */
1540 NULL
, /* special_function */
1541 "R_ARM_TLS_IE32", /* name */
1542 TRUE
, /* partial_inplace */
1543 0xffffffff, /* src_mask */
1544 0xffffffff, /* dst_mask */
1545 FALSE
), /* pcrel_offset */
1547 HOWTO (R_ARM_TLS_LE32
, /* type */
1549 2, /* size (0 = byte, 1 = short, 2 = long) */
1551 FALSE
, /* pc_relative */
1553 complain_overflow_bitfield
,/* complain_on_overflow */
1554 bfd_elf_generic_reloc
, /* special_function */
1555 "R_ARM_TLS_LE32", /* name */
1556 TRUE
, /* partial_inplace */
1557 0xffffffff, /* src_mask */
1558 0xffffffff, /* dst_mask */
1559 FALSE
), /* pcrel_offset */
1561 HOWTO (R_ARM_TLS_LDO12
, /* type */
1563 2, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE
, /* pc_relative */
1567 complain_overflow_bitfield
,/* complain_on_overflow */
1568 bfd_elf_generic_reloc
, /* special_function */
1569 "R_ARM_TLS_LDO12", /* name */
1570 FALSE
, /* partial_inplace */
1571 0x00000fff, /* src_mask */
1572 0x00000fff, /* dst_mask */
1573 FALSE
), /* pcrel_offset */
1575 HOWTO (R_ARM_TLS_LE12
, /* type */
1577 2, /* size (0 = byte, 1 = short, 2 = long) */
1579 FALSE
, /* pc_relative */
1581 complain_overflow_bitfield
,/* complain_on_overflow */
1582 bfd_elf_generic_reloc
, /* special_function */
1583 "R_ARM_TLS_LE12", /* name */
1584 FALSE
, /* partial_inplace */
1585 0x00000fff, /* src_mask */
1586 0x00000fff, /* dst_mask */
1587 FALSE
), /* pcrel_offset */
1589 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1591 2, /* size (0 = byte, 1 = short, 2 = long) */
1593 FALSE
, /* pc_relative */
1595 complain_overflow_bitfield
,/* complain_on_overflow */
1596 bfd_elf_generic_reloc
, /* special_function */
1597 "R_ARM_TLS_IE12GP", /* name */
1598 FALSE
, /* partial_inplace */
1599 0x00000fff, /* src_mask */
1600 0x00000fff, /* dst_mask */
1601 FALSE
), /* pcrel_offset */
1604 /* 112-127 private relocations
1605 128 R_ARM_ME_TOO, obsolete
1606 129-255 unallocated in AAELF.
1608 249-255 extended, currently unused, relocations: */
1610 static reloc_howto_type elf32_arm_howto_table_2
[4] =
1612 HOWTO (R_ARM_RREL32
, /* type */
1614 0, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE
, /* pc_relative */
1618 complain_overflow_dont
,/* complain_on_overflow */
1619 bfd_elf_generic_reloc
, /* special_function */
1620 "R_ARM_RREL32", /* name */
1621 FALSE
, /* partial_inplace */
1624 FALSE
), /* pcrel_offset */
1626 HOWTO (R_ARM_RABS32
, /* type */
1628 0, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE
, /* pc_relative */
1632 complain_overflow_dont
,/* complain_on_overflow */
1633 bfd_elf_generic_reloc
, /* special_function */
1634 "R_ARM_RABS32", /* name */
1635 FALSE
, /* partial_inplace */
1638 FALSE
), /* pcrel_offset */
1640 HOWTO (R_ARM_RPC24
, /* type */
1642 0, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE
, /* pc_relative */
1646 complain_overflow_dont
,/* complain_on_overflow */
1647 bfd_elf_generic_reloc
, /* special_function */
1648 "R_ARM_RPC24", /* name */
1649 FALSE
, /* partial_inplace */
1652 FALSE
), /* pcrel_offset */
1654 HOWTO (R_ARM_RBASE
, /* type */
1656 0, /* size (0 = byte, 1 = short, 2 = long) */
1658 FALSE
, /* pc_relative */
1660 complain_overflow_dont
,/* complain_on_overflow */
1661 bfd_elf_generic_reloc
, /* special_function */
1662 "R_ARM_RBASE", /* name */
1663 FALSE
, /* partial_inplace */
1666 FALSE
) /* pcrel_offset */
1669 static reloc_howto_type
*
1670 elf32_arm_howto_from_type (unsigned int r_type
)
1672 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1673 return &elf32_arm_howto_table_1
[r_type
];
1675 if (r_type
>= R_ARM_RREL32
1676 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_2
))
1677 return &elf32_arm_howto_table_2
[r_type
- R_ARM_RREL32
];
1683 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1684 Elf_Internal_Rela
* elf_reloc
)
1686 unsigned int r_type
;
1688 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1689 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1692 struct elf32_arm_reloc_map
1694 bfd_reloc_code_real_type bfd_reloc_val
;
1695 unsigned char elf_reloc_val
;
1698 /* All entries in this list must also be present in elf32_arm_howto_table. */
1699 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1701 {BFD_RELOC_NONE
, R_ARM_NONE
},
1702 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1703 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1704 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1705 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1706 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1707 {BFD_RELOC_32
, R_ARM_ABS32
},
1708 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1709 {BFD_RELOC_8
, R_ARM_ABS8
},
1710 {BFD_RELOC_16
, R_ARM_ABS16
},
1711 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1712 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1718 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1719 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1720 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1721 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1722 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1723 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1724 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1725 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1726 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1727 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1728 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1729 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1730 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1731 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1732 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1733 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1734 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1735 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1736 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1737 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1738 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1739 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1740 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1741 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1742 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1743 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1744 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1745 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1746 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1747 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1748 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1749 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1750 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1751 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1752 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1753 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1754 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1755 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1756 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1757 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1758 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1759 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1760 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1761 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1762 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1763 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1764 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1765 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1766 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1767 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1768 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1769 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1770 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1771 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1772 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1773 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1774 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1775 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1776 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1777 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
1778 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
}
1781 static reloc_howto_type
*
1782 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1783 bfd_reloc_code_real_type code
)
1787 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
1788 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1789 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1794 static reloc_howto_type
*
1795 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1800 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
1801 if (elf32_arm_howto_table_1
[i
].name
!= NULL
1802 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
1803 return &elf32_arm_howto_table_1
[i
];
1805 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
1806 if (elf32_arm_howto_table_2
[i
].name
!= NULL
1807 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
1808 return &elf32_arm_howto_table_2
[i
];
1813 /* Support for core dump NOTE sections. */
1816 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1821 switch (note
->descsz
)
1826 case 148: /* Linux/ARM 32-bit. */
1828 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1831 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1840 /* Make a ".reg/999" section. */
1841 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1842 size
, note
->descpos
+ offset
);
1846 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1848 switch (note
->descsz
)
1853 case 124: /* Linux/ARM elf_prpsinfo. */
1854 elf_tdata (abfd
)->core_program
1855 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1856 elf_tdata (abfd
)->core_command
1857 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1860 /* Note that for some reason, a spurious space is tacked
1861 onto the end of the args in some (at least one anyway)
1862 implementations, so strip it off if it exists. */
1864 char *command
= elf_tdata (abfd
)->core_command
;
1865 int n
= strlen (command
);
1867 if (0 < n
&& command
[n
- 1] == ' ')
1868 command
[n
- 1] = '\0';
1874 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1875 #define TARGET_LITTLE_NAME "elf32-littlearm"
1876 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1877 #define TARGET_BIG_NAME "elf32-bigarm"
1879 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1880 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1882 typedef unsigned long int insn32
;
1883 typedef unsigned short int insn16
;
1885 /* In lieu of proper flags, assume all EABIv4 or later objects are
1887 #define INTERWORK_FLAG(abfd) \
1888 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1889 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
1890 || ((abfd)->flags & BFD_LINKER_CREATED))
1892 /* The linker script knows the section names for placement.
1893 The entry_names are used to do simple name mangling on the stubs.
1894 Given a function name, and its type, the stub can be found. The
1895 name can be changed. The only requirement is the %s be present. */
1896 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1897 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1899 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1900 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1902 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1903 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1905 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1906 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1908 #define STUB_ENTRY_NAME "__%s_veneer"
1910 /* The name of the dynamic interpreter. This is put in the .interp
1912 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1914 #ifdef FOUR_WORD_PLT
1916 /* The first entry in a procedure linkage table looks like
1917 this. It is set up so that any shared library function that is
1918 called before the relocation has been set up calls the dynamic
1920 static const bfd_vma elf32_arm_plt0_entry
[] =
1922 0xe52de004, /* str lr, [sp, #-4]! */
1923 0xe59fe010, /* ldr lr, [pc, #16] */
1924 0xe08fe00e, /* add lr, pc, lr */
1925 0xe5bef008, /* ldr pc, [lr, #8]! */
1928 /* Subsequent entries in a procedure linkage table look like
1930 static const bfd_vma elf32_arm_plt_entry
[] =
1932 0xe28fc600, /* add ip, pc, #NN */
1933 0xe28cca00, /* add ip, ip, #NN */
1934 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1935 0x00000000, /* unused */
1940 /* The first entry in a procedure linkage table looks like
1941 this. It is set up so that any shared library function that is
1942 called before the relocation has been set up calls the dynamic
1944 static const bfd_vma elf32_arm_plt0_entry
[] =
1946 0xe52de004, /* str lr, [sp, #-4]! */
1947 0xe59fe004, /* ldr lr, [pc, #4] */
1948 0xe08fe00e, /* add lr, pc, lr */
1949 0xe5bef008, /* ldr pc, [lr, #8]! */
1950 0x00000000, /* &GOT[0] - . */
1953 /* Subsequent entries in a procedure linkage table look like
1955 static const bfd_vma elf32_arm_plt_entry
[] =
1957 0xe28fc600, /* add ip, pc, #0xNN00000 */
1958 0xe28cca00, /* add ip, ip, #0xNN000 */
1959 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1964 /* The format of the first entry in the procedure linkage table
1965 for a VxWorks executable. */
1966 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
1968 0xe52dc008, /* str ip,[sp,#-8]! */
1969 0xe59fc000, /* ldr ip,[pc] */
1970 0xe59cf008, /* ldr pc,[ip,#8] */
1971 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1974 /* The format of subsequent entries in a VxWorks executable. */
1975 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
1977 0xe59fc000, /* ldr ip,[pc] */
1978 0xe59cf000, /* ldr pc,[ip] */
1979 0x00000000, /* .long @got */
1980 0xe59fc000, /* ldr ip,[pc] */
1981 0xea000000, /* b _PLT */
1982 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1985 /* The format of entries in a VxWorks shared library. */
1986 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
1988 0xe59fc000, /* ldr ip,[pc] */
1989 0xe79cf009, /* ldr pc,[ip,r9] */
1990 0x00000000, /* .long @got */
1991 0xe59fc000, /* ldr ip,[pc] */
1992 0xe599f008, /* ldr pc,[r9,#8] */
1993 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1996 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1997 #define PLT_THUMB_STUB_SIZE 4
1998 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2004 /* The entries in a PLT when using a DLL-based target with multiple
2006 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2008 0xe51ff004, /* ldr pc, [pc, #-4] */
2009 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2012 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2013 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2014 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2015 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2016 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2017 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2027 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2028 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2029 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2030 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2031 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2036 enum stub_insn_type type
;
2037 unsigned int r_type
;
2041 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2042 to reach the stub if necessary. */
2043 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2045 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2046 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2049 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2051 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2053 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2054 ARM_INSN(0xe12fff1c), /* bx ip */
2055 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2058 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2059 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2061 THUMB16_INSN(0xb401), /* push {r0} */
2062 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2063 THUMB16_INSN(0x4684), /* mov ip, r0 */
2064 THUMB16_INSN(0xbc01), /* pop {r0} */
2065 THUMB16_INSN(0x4760), /* bx ip */
2066 THUMB16_INSN(0xbf00), /* nop */
2067 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2070 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2072 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2074 THUMB16_INSN(0x4778), /* bx pc */
2075 THUMB16_INSN(0x46c0), /* nop */
2076 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2077 ARM_INSN(0xe12fff1c), /* bx ip */
2078 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2081 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2083 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2085 THUMB16_INSN(0x4778), /* bx pc */
2086 THUMB16_INSN(0x46c0), /* nop */
2087 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2088 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2091 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2092 one, when the destination is close enough. */
2093 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2095 THUMB16_INSN(0x4778), /* bx pc */
2096 THUMB16_INSN(0x46c0), /* nop */
2097 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2100 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2101 blx to reach the stub if necessary. */
2102 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2104 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2105 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2106 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2109 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2110 blx to reach the stub if necessary. We can not add into pc;
2111 it is not guaranteed to mode switch (different in ARMv6 and
2113 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2115 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2116 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2117 ARM_INSN(0xe12fff1c), /* bx ip */
2118 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2121 /* V4T ARM -> ARM long branch stub, PIC. */
2122 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2124 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2125 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2126 ARM_INSN(0xe12fff1c), /* bx ip */
2127 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2130 /* V4T Thumb -> ARM long branch stub, PIC. */
2131 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2133 THUMB16_INSN(0x4778), /* bx pc */
2134 THUMB16_INSN(0x46c0), /* nop */
2135 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2136 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2137 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2140 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2142 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2144 THUMB16_INSN(0xb401), /* push {r0} */
2145 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2146 THUMB16_INSN(0x46fc), /* mov ip, pc */
2147 THUMB16_INSN(0x4484), /* add ip, r0 */
2148 THUMB16_INSN(0xbc01), /* pop {r0} */
2149 THUMB16_INSN(0x4760), /* bx ip */
2150 DATA_WORD(0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2153 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2155 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2157 THUMB16_INSN(0x4778), /* bx pc */
2158 THUMB16_INSN(0x46c0), /* nop */
2159 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2160 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2161 ARM_INSN(0xe12fff1c), /* bx ip */
2162 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2165 /* Section name for stubs is the associated section name plus this
2167 #define STUB_SUFFIX ".stub"
2169 /* One entry per long/short branch stub defined above. */
2171 DEF_STUB(long_branch_any_any) \
2172 DEF_STUB(long_branch_v4t_arm_thumb) \
2173 DEF_STUB(long_branch_thumb_only) \
2174 DEF_STUB(long_branch_v4t_thumb_thumb) \
2175 DEF_STUB(long_branch_v4t_thumb_arm) \
2176 DEF_STUB(short_branch_v4t_thumb_arm) \
2177 DEF_STUB(long_branch_any_arm_pic) \
2178 DEF_STUB(long_branch_any_thumb_pic) \
2179 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2180 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2181 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2182 DEF_STUB(long_branch_thumb_only_pic)
2184 #define DEF_STUB(x) arm_stub_##x,
2185 enum elf32_arm_stub_type
{
2193 const insn_sequence
* template;
2197 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2198 static const stub_def stub_definitions
[] = {
2203 struct elf32_arm_stub_hash_entry
2205 /* Base hash table entry structure. */
2206 struct bfd_hash_entry root
;
2208 /* The stub section. */
2211 /* Offset within stub_sec of the beginning of this stub. */
2212 bfd_vma stub_offset
;
2214 /* Given the symbol's value and its section we can determine its final
2215 value when building the stubs (so the stub knows where to jump). */
2216 bfd_vma target_value
;
2217 asection
*target_section
;
2219 /* The stub type. */
2220 enum elf32_arm_stub_type stub_type
;
2221 /* Its encoding size in bytes. */
2224 const insn_sequence
*stub_template
;
2225 /* The size of the template (number of entries). */
2226 int stub_template_size
;
2228 /* The symbol table entry, if any, that this was derived from. */
2229 struct elf32_arm_link_hash_entry
*h
;
2231 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2232 unsigned char st_type
;
2234 /* Where this stub is being called from, or, in the case of combined
2235 stub sections, the first input section in the group. */
2238 /* The name for the local symbol at the start of this stub. The
2239 stub name in the hash table has to be unique; this does not, so
2240 it can be friendlier. */
2244 /* Used to build a map of a section. This is required for mixed-endian
2247 typedef struct elf32_elf_section_map
2252 elf32_arm_section_map
;
2254 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2258 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2259 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2260 VFP11_ERRATUM_ARM_VENEER
,
2261 VFP11_ERRATUM_THUMB_VENEER
2263 elf32_vfp11_erratum_type
;
2265 typedef struct elf32_vfp11_erratum_list
2267 struct elf32_vfp11_erratum_list
*next
;
2273 struct elf32_vfp11_erratum_list
*veneer
;
2274 unsigned int vfp_insn
;
2278 struct elf32_vfp11_erratum_list
*branch
;
2282 elf32_vfp11_erratum_type type
;
2284 elf32_vfp11_erratum_list
;
2286 typedef struct _arm_elf_section_data
2288 struct bfd_elf_section_data elf
;
2289 unsigned int mapcount
;
2290 unsigned int mapsize
;
2291 elf32_arm_section_map
*map
;
2292 unsigned int erratumcount
;
2293 elf32_vfp11_erratum_list
*erratumlist
;
2295 _arm_elf_section_data
;
2297 #define elf32_arm_section_data(sec) \
2298 ((_arm_elf_section_data *) elf_section_data (sec))
2300 /* The size of the thread control block. */
2303 struct elf_arm_obj_tdata
2305 struct elf_obj_tdata root
;
2307 /* tls_type for each local got entry. */
2308 char *local_got_tls_type
;
2310 /* Zero to warn when linking objects with incompatible enum sizes. */
2311 int no_enum_size_warning
;
2313 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2314 int no_wchar_size_warning
;
2317 #define elf_arm_tdata(bfd) \
2318 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2320 #define elf32_arm_local_got_tls_type(bfd) \
2321 (elf_arm_tdata (bfd)->local_got_tls_type)
2323 #define is_arm_elf(bfd) \
2324 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2325 && elf_tdata (bfd) != NULL \
2326 && elf_object_id (bfd) == ARM_ELF_TDATA)
2329 elf32_arm_mkobject (bfd
*abfd
)
2331 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2335 /* The ARM linker needs to keep track of the number of relocs that it
2336 decides to copy in check_relocs for each symbol. This is so that
2337 it can discard PC relative relocs if it doesn't need them when
2338 linking with -Bsymbolic. We store the information in a field
2339 extending the regular ELF linker hash table. */
2341 /* This structure keeps track of the number of relocs we have copied
2342 for a given symbol. */
2343 struct elf32_arm_relocs_copied
2346 struct elf32_arm_relocs_copied
* next
;
2347 /* A section in dynobj. */
2349 /* Number of relocs copied in this section. */
2350 bfd_size_type count
;
2351 /* Number of PC-relative relocs copied in this section. */
2352 bfd_size_type pc_count
;
2355 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2357 /* Arm ELF linker hash entry. */
2358 struct elf32_arm_link_hash_entry
2360 struct elf_link_hash_entry root
;
2362 /* Number of PC relative relocs copied for this symbol. */
2363 struct elf32_arm_relocs_copied
* relocs_copied
;
2365 /* We reference count Thumb references to a PLT entry separately,
2366 so that we can emit the Thumb trampoline only if needed. */
2367 bfd_signed_vma plt_thumb_refcount
;
2369 /* Some references from Thumb code may be eliminated by BL->BLX
2370 conversion, so record them separately. */
2371 bfd_signed_vma plt_maybe_thumb_refcount
;
2373 /* Since PLT entries have variable size if the Thumb prologue is
2374 used, we need to record the index into .got.plt instead of
2375 recomputing it from the PLT offset. */
2376 bfd_signed_vma plt_got_offset
;
2378 #define GOT_UNKNOWN 0
2379 #define GOT_NORMAL 1
2380 #define GOT_TLS_GD 2
2381 #define GOT_TLS_IE 4
2382 unsigned char tls_type
;
2384 /* The symbol marking the real symbol location for exported thumb
2385 symbols with Arm stubs. */
2386 struct elf_link_hash_entry
*export_glue
;
2388 /* A pointer to the most recently used stub hash entry against this
2390 struct elf32_arm_stub_hash_entry
*stub_cache
;
2393 /* Traverse an arm ELF linker hash table. */
2394 #define elf32_arm_link_hash_traverse(table, func, info) \
2395 (elf_link_hash_traverse \
2397 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2400 /* Get the ARM elf linker hash table from a link_info structure. */
2401 #define elf32_arm_hash_table(info) \
2402 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2404 #define arm_stub_hash_lookup(table, string, create, copy) \
2405 ((struct elf32_arm_stub_hash_entry *) \
2406 bfd_hash_lookup ((table), (string), (create), (copy)))
2408 /* ARM ELF linker hash table. */
2409 struct elf32_arm_link_hash_table
2411 /* The main hash table. */
2412 struct elf_link_hash_table root
;
2414 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2415 bfd_size_type thumb_glue_size
;
2417 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2418 bfd_size_type arm_glue_size
;
2420 /* The size in bytes of section containing the ARMv4 BX veneers. */
2421 bfd_size_type bx_glue_size
;
2423 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2424 veneer has been populated. */
2425 bfd_vma bx_glue_offset
[15];
2427 /* The size in bytes of the section containing glue for VFP11 erratum
2429 bfd_size_type vfp11_erratum_glue_size
;
2431 /* An arbitrary input BFD chosen to hold the glue sections. */
2432 bfd
* bfd_of_glue_owner
;
2434 /* Nonzero to output a BE8 image. */
2437 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2438 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2441 /* The relocation to use for R_ARM_TARGET2 relocations. */
2444 /* 0 = Ignore R_ARM_V4BX.
2445 1 = Convert BX to MOV PC.
2446 2 = Generate v4 interworing stubs. */
2449 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2452 /* What sort of code sequences we should look for which may trigger the
2453 VFP11 denorm erratum. */
2454 bfd_arm_vfp11_fix vfp11_fix
;
2456 /* Global counter for the number of fixes we have emitted. */
2457 int num_vfp11_fixes
;
2459 /* Nonzero to force PIC branch veneers. */
2462 /* The number of bytes in the initial entry in the PLT. */
2463 bfd_size_type plt_header_size
;
2465 /* The number of bytes in the subsequent PLT etries. */
2466 bfd_size_type plt_entry_size
;
2468 /* True if the target system is VxWorks. */
2471 /* True if the target system is Symbian OS. */
2474 /* True if the target uses REL relocations. */
2477 /* Short-cuts to get to dynamic linker sections. */
2486 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2489 /* Data for R_ARM_TLS_LDM32 relocations. */
2492 bfd_signed_vma refcount
;
2496 /* Small local sym to section mapping cache. */
2497 struct sym_sec_cache sym_sec
;
2499 /* For convenience in allocate_dynrelocs. */
2502 /* The stub hash table. */
2503 struct bfd_hash_table stub_hash_table
;
2505 /* Linker stub bfd. */
2508 /* Linker call-backs. */
2509 asection
* (*add_stub_section
) (const char *, asection
*);
2510 void (*layout_sections_again
) (void);
2512 /* Array to keep track of which stub sections have been created, and
2513 information on stub grouping. */
2516 /* This is the section to which stubs in the group will be
2519 /* The stub section. */
2523 /* Assorted information used by elf32_arm_size_stubs. */
2524 unsigned int bfd_count
;
2526 asection
**input_list
;
2529 /* Create an entry in an ARM ELF linker hash table. */
2531 static struct bfd_hash_entry
*
2532 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
2533 struct bfd_hash_table
* table
,
2534 const char * string
)
2536 struct elf32_arm_link_hash_entry
* ret
=
2537 (struct elf32_arm_link_hash_entry
*) entry
;
2539 /* Allocate the structure if it has not already been allocated by a
2542 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
2544 return (struct bfd_hash_entry
*) ret
;
2546 /* Call the allocation method of the superclass. */
2547 ret
= ((struct elf32_arm_link_hash_entry
*)
2548 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2552 ret
->relocs_copied
= NULL
;
2553 ret
->tls_type
= GOT_UNKNOWN
;
2554 ret
->plt_thumb_refcount
= 0;
2555 ret
->plt_maybe_thumb_refcount
= 0;
2556 ret
->plt_got_offset
= -1;
2557 ret
->export_glue
= NULL
;
2559 ret
->stub_cache
= NULL
;
2562 return (struct bfd_hash_entry
*) ret
;
2565 /* Initialize an entry in the stub hash table. */
2567 static struct bfd_hash_entry
*
2568 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2569 struct bfd_hash_table
*table
,
2572 /* Allocate the structure if it has not already been allocated by a
2576 entry
= bfd_hash_allocate (table
,
2577 sizeof (struct elf32_arm_stub_hash_entry
));
2582 /* Call the allocation method of the superclass. */
2583 entry
= bfd_hash_newfunc (entry
, table
, string
);
2586 struct elf32_arm_stub_hash_entry
*eh
;
2588 /* Initialize the local fields. */
2589 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
2590 eh
->stub_sec
= NULL
;
2591 eh
->stub_offset
= 0;
2592 eh
->target_value
= 0;
2593 eh
->target_section
= NULL
;
2594 eh
->stub_type
= arm_stub_none
;
2596 eh
->stub_template
= NULL
;
2597 eh
->stub_template_size
= 0;
2605 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2606 shortcuts to them in our hash table. */
2609 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
2611 struct elf32_arm_link_hash_table
*htab
;
2613 htab
= elf32_arm_hash_table (info
);
2614 /* BPABI objects never have a GOT, or associated sections. */
2615 if (htab
->symbian_p
)
2618 if (! _bfd_elf_create_got_section (dynobj
, info
))
2621 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2622 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2623 if (!htab
->sgot
|| !htab
->sgotplt
)
2626 htab
->srelgot
= bfd_make_section_with_flags (dynobj
,
2627 RELOC_SECTION (htab
, ".got"),
2628 (SEC_ALLOC
| SEC_LOAD
2631 | SEC_LINKER_CREATED
2633 if (htab
->srelgot
== NULL
2634 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
2639 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2640 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2644 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
2646 struct elf32_arm_link_hash_table
*htab
;
2648 htab
= elf32_arm_hash_table (info
);
2649 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2652 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2655 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2656 htab
->srelplt
= bfd_get_section_by_name (dynobj
,
2657 RELOC_SECTION (htab
, ".plt"));
2658 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2660 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
2661 RELOC_SECTION (htab
, ".bss"));
2663 if (htab
->vxworks_p
)
2665 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
2670 htab
->plt_header_size
= 0;
2671 htab
->plt_entry_size
2672 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
2676 htab
->plt_header_size
2677 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
2678 htab
->plt_entry_size
2679 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
2686 || (!info
->shared
&& !htab
->srelbss
))
2692 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2695 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
2696 struct elf_link_hash_entry
*dir
,
2697 struct elf_link_hash_entry
*ind
)
2699 struct elf32_arm_link_hash_entry
*edir
, *eind
;
2701 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
2702 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
2704 if (eind
->relocs_copied
!= NULL
)
2706 if (edir
->relocs_copied
!= NULL
)
2708 struct elf32_arm_relocs_copied
**pp
;
2709 struct elf32_arm_relocs_copied
*p
;
2711 /* Add reloc counts against the indirect sym to the direct sym
2712 list. Merge any entries against the same section. */
2713 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
2715 struct elf32_arm_relocs_copied
*q
;
2717 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
2718 if (q
->section
== p
->section
)
2720 q
->pc_count
+= p
->pc_count
;
2721 q
->count
+= p
->count
;
2728 *pp
= edir
->relocs_copied
;
2731 edir
->relocs_copied
= eind
->relocs_copied
;
2732 eind
->relocs_copied
= NULL
;
2735 if (ind
->root
.type
== bfd_link_hash_indirect
)
2737 /* Copy over PLT info. */
2738 edir
->plt_thumb_refcount
+= eind
->plt_thumb_refcount
;
2739 eind
->plt_thumb_refcount
= 0;
2740 edir
->plt_maybe_thumb_refcount
+= eind
->plt_maybe_thumb_refcount
;
2741 eind
->plt_maybe_thumb_refcount
= 0;
2743 if (dir
->got
.refcount
<= 0)
2745 edir
->tls_type
= eind
->tls_type
;
2746 eind
->tls_type
= GOT_UNKNOWN
;
2750 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2753 /* Create an ARM elf linker hash table. */
2755 static struct bfd_link_hash_table
*
2756 elf32_arm_link_hash_table_create (bfd
*abfd
)
2758 struct elf32_arm_link_hash_table
*ret
;
2759 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
2761 ret
= bfd_malloc (amt
);
2765 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
2766 elf32_arm_link_hash_newfunc
,
2767 sizeof (struct elf32_arm_link_hash_entry
)))
2774 ret
->sgotplt
= NULL
;
2775 ret
->srelgot
= NULL
;
2777 ret
->srelplt
= NULL
;
2778 ret
->sdynbss
= NULL
;
2779 ret
->srelbss
= NULL
;
2780 ret
->srelplt2
= NULL
;
2781 ret
->thumb_glue_size
= 0;
2782 ret
->arm_glue_size
= 0;
2783 ret
->bx_glue_size
= 0;
2784 memset (ret
->bx_glue_offset
, 0, sizeof (ret
->bx_glue_offset
));
2785 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
2786 ret
->vfp11_erratum_glue_size
= 0;
2787 ret
->num_vfp11_fixes
= 0;
2788 ret
->bfd_of_glue_owner
= NULL
;
2789 ret
->byteswap_code
= 0;
2790 ret
->target1_is_rel
= 0;
2791 ret
->target2_reloc
= R_ARM_NONE
;
2792 #ifdef FOUR_WORD_PLT
2793 ret
->plt_header_size
= 16;
2794 ret
->plt_entry_size
= 16;
2796 ret
->plt_header_size
= 20;
2797 ret
->plt_entry_size
= 12;
2804 ret
->sym_sec
.abfd
= NULL
;
2806 ret
->tls_ldm_got
.refcount
= 0;
2807 ret
->stub_bfd
= NULL
;
2808 ret
->add_stub_section
= NULL
;
2809 ret
->layout_sections_again
= NULL
;
2810 ret
->stub_group
= NULL
;
2813 ret
->input_list
= NULL
;
2815 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2816 sizeof (struct elf32_arm_stub_hash_entry
)))
2822 return &ret
->root
.root
;
2825 /* Free the derived linker hash table. */
2828 elf32_arm_hash_table_free (struct bfd_link_hash_table
*hash
)
2830 struct elf32_arm_link_hash_table
*ret
2831 = (struct elf32_arm_link_hash_table
*) hash
;
2833 bfd_hash_table_free (&ret
->stub_hash_table
);
2834 _bfd_generic_link_hash_table_free (hash
);
2837 /* Determine if we're dealing with a Thumb only architecture. */
2840 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
2842 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2846 if (arch
!= TAG_CPU_ARCH_V7
)
2849 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2850 Tag_CPU_arch_profile
);
2852 return profile
== 'M';
2855 /* Determine if we're dealing with a Thumb-2 object. */
2858 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
2860 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2862 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
2866 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
2870 case arm_stub_long_branch_thumb_only
:
2871 case arm_stub_long_branch_v4t_thumb_arm
:
2872 case arm_stub_short_branch_v4t_thumb_arm
:
2873 case arm_stub_long_branch_v4t_thumb_arm_pic
:
2874 case arm_stub_long_branch_thumb_only_pic
:
2885 /* Determine the type of stub needed, if any, for a call. */
2887 static enum elf32_arm_stub_type
2888 arm_type_of_stub (struct bfd_link_info
*info
,
2889 asection
*input_sec
,
2890 const Elf_Internal_Rela
*rel
,
2891 unsigned char st_type
,
2892 struct elf32_arm_link_hash_entry
*hash
,
2893 bfd_vma destination
,
2899 bfd_signed_vma branch_offset
;
2900 unsigned int r_type
;
2901 struct elf32_arm_link_hash_table
* globals
;
2904 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
2907 /* We don't know the actual type of destination in case it is of
2908 type STT_SECTION: give up. */
2909 if (st_type
== STT_SECTION
)
2912 globals
= elf32_arm_hash_table (info
);
2914 thumb_only
= using_thumb_only (globals
);
2916 thumb2
= using_thumb2 (globals
);
2918 /* Determine where the call point is. */
2919 location
= (input_sec
->output_offset
2920 + input_sec
->output_section
->vma
2923 branch_offset
= (bfd_signed_vma
)(destination
- location
);
2925 r_type
= ELF32_R_TYPE (rel
->r_info
);
2927 /* Keep a simpler condition, for the sake of clarity. */
2928 if (globals
->splt
!= NULL
&& hash
!= NULL
&& hash
->root
.plt
.offset
!= (bfd_vma
) -1)
2931 /* Note when dealing with PLT entries: the main PLT stub is in
2932 ARM mode, so if the branch is in Thumb mode, another
2933 Thumb->ARM stub will be inserted later just before the ARM
2934 PLT stub. We don't take this extra distance into account
2935 here, because if a long branch stub is needed, we'll add a
2936 Thumb->Arm one and branch directly to the ARM PLT entry
2937 because it avoids spreading offset corrections in several
2941 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
2943 /* Handle cases where:
2944 - this call goes too far (different Thumb/Thumb2 max
2946 - it's a Thumb->Arm call and blx is not available, or it's a
2947 Thumb->Arm branch (not bl). A stub is needed in this case,
2948 but only if this call is not through a PLT entry. Indeed,
2949 PLT stubs handle mode switching already.
2952 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
2953 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
2955 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
2956 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
2957 || ((st_type
!= STT_ARM_TFUNC
)
2958 && (((r_type
== R_ARM_THM_CALL
) && !globals
->use_blx
)
2959 || (r_type
== R_ARM_THM_JUMP24
))
2962 if (st_type
== STT_ARM_TFUNC
)
2964 /* Thumb to thumb. */
2967 stub_type
= (info
->shared
| globals
->pic_veneer
)
2969 ? ((globals
->use_blx
2970 && (r_type
==R_ARM_THM_CALL
))
2971 /* V5T and above. Stub starts with ARM code, so
2972 we must be able to switch mode before
2973 reaching it, which is only possible for 'bl'
2974 (ie R_ARM_THM_CALL relocation). */
2975 ? arm_stub_long_branch_any_thumb_pic
2976 /* On V4T, use Thumb code only. */
2977 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
2979 /* non-PIC stubs. */
2980 : ((globals
->use_blx
2981 && (r_type
==R_ARM_THM_CALL
))
2982 /* V5T and above. */
2983 ? arm_stub_long_branch_any_any
2985 : arm_stub_long_branch_v4t_thumb_thumb
);
2989 stub_type
= (info
->shared
| globals
->pic_veneer
)
2991 ? arm_stub_long_branch_thumb_only_pic
2993 : arm_stub_long_branch_thumb_only
;
3000 && sym_sec
->owner
!= NULL
3001 && !INTERWORK_FLAG (sym_sec
->owner
))
3003 (*_bfd_error_handler
)
3004 (_("%B(%s): warning: interworking not enabled.\n"
3005 " first occurrence: %B: Thumb call to ARM"),
3006 sym_sec
->owner
, input_bfd
, name
);
3009 stub_type
= (info
->shared
| globals
->pic_veneer
)
3011 ? ((globals
->use_blx
3012 && (r_type
==R_ARM_THM_CALL
))
3013 /* V5T and above. */
3014 ? arm_stub_long_branch_any_arm_pic
3016 : arm_stub_long_branch_v4t_thumb_arm_pic
)
3018 /* non-PIC stubs. */
3019 : ((globals
->use_blx
3020 && (r_type
==R_ARM_THM_CALL
))
3021 /* V5T and above. */
3022 ? arm_stub_long_branch_any_any
3024 : arm_stub_long_branch_v4t_thumb_arm
);
3026 /* Handle v4t short branches. */
3027 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3028 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3029 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3030 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3034 else if (r_type
== R_ARM_CALL
|| r_type
== R_ARM_JUMP24
|| r_type
== R_ARM_PLT32
)
3036 if (st_type
== STT_ARM_TFUNC
)
3041 && sym_sec
->owner
!= NULL
3042 && !INTERWORK_FLAG (sym_sec
->owner
))
3044 (*_bfd_error_handler
)
3045 (_("%B(%s): warning: interworking not enabled.\n"
3046 " first occurrence: %B: ARM call to Thumb"),
3047 sym_sec
->owner
, input_bfd
, name
);
3050 /* We have an extra 2-bytes reach because of
3051 the mode change (bit 24 (H) of BLX encoding). */
3052 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3053 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3054 || ((r_type
== R_ARM_CALL
) && !globals
->use_blx
)
3055 || (r_type
== R_ARM_JUMP24
)
3056 || (r_type
== R_ARM_PLT32
))
3058 stub_type
= (info
->shared
| globals
->pic_veneer
)
3060 ? ((globals
->use_blx
)
3061 /* V5T and above. */
3062 ? arm_stub_long_branch_any_thumb_pic
3064 : arm_stub_long_branch_v4t_arm_thumb_pic
)
3066 /* non-PIC stubs. */
3067 : ((globals
->use_blx
)
3068 /* V5T and above. */
3069 ? arm_stub_long_branch_any_any
3071 : arm_stub_long_branch_v4t_arm_thumb
);
3077 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3078 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3080 stub_type
= (info
->shared
| globals
->pic_veneer
)
3082 ? arm_stub_long_branch_any_arm_pic
3083 /* non-PIC stubs. */
3084 : arm_stub_long_branch_any_any
;
3092 /* Build a name for an entry in the stub hash table. */
3095 elf32_arm_stub_name (const asection
*input_section
,
3096 const asection
*sym_sec
,
3097 const struct elf32_arm_link_hash_entry
*hash
,
3098 const Elf_Internal_Rela
*rel
)
3105 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1;
3106 stub_name
= bfd_malloc (len
);
3107 if (stub_name
!= NULL
)
3108 sprintf (stub_name
, "%08x_%s+%x",
3109 input_section
->id
& 0xffffffff,
3110 hash
->root
.root
.root
.string
,
3111 (int) rel
->r_addend
& 0xffffffff);
3115 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3116 stub_name
= bfd_malloc (len
);
3117 if (stub_name
!= NULL
)
3118 sprintf (stub_name
, "%08x_%x:%x+%x",
3119 input_section
->id
& 0xffffffff,
3120 sym_sec
->id
& 0xffffffff,
3121 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
3122 (int) rel
->r_addend
& 0xffffffff);
3128 /* Look up an entry in the stub hash. Stub entries are cached because
3129 creating the stub name takes a bit of time. */
3131 static struct elf32_arm_stub_hash_entry
*
3132 elf32_arm_get_stub_entry (const asection
*input_section
,
3133 const asection
*sym_sec
,
3134 struct elf_link_hash_entry
*hash
,
3135 const Elf_Internal_Rela
*rel
,
3136 struct elf32_arm_link_hash_table
*htab
)
3138 struct elf32_arm_stub_hash_entry
*stub_entry
;
3139 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
3140 const asection
*id_sec
;
3142 if ((input_section
->flags
& SEC_CODE
) == 0)
3145 /* If this input section is part of a group of sections sharing one
3146 stub section, then use the id of the first section in the group.
3147 Stub names need to include a section id, as there may well be
3148 more than one stub used to reach say, printf, and we need to
3149 distinguish between them. */
3150 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3152 if (h
!= NULL
&& h
->stub_cache
!= NULL
3153 && h
->stub_cache
->h
== h
3154 && h
->stub_cache
->id_sec
== id_sec
)
3156 stub_entry
= h
->stub_cache
;
3162 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
);
3163 if (stub_name
== NULL
)
3166 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3167 stub_name
, FALSE
, FALSE
);
3169 h
->stub_cache
= stub_entry
;
3177 /* Add a new stub entry to the stub hash. Not all fields of the new
3178 stub entry are initialised. */
3180 static struct elf32_arm_stub_hash_entry
*
3181 elf32_arm_add_stub (const char *stub_name
,
3183 struct elf32_arm_link_hash_table
*htab
)
3187 struct elf32_arm_stub_hash_entry
*stub_entry
;
3189 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3190 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3191 if (stub_sec
== NULL
)
3193 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3194 if (stub_sec
== NULL
)
3200 namelen
= strlen (link_sec
->name
);
3201 len
= namelen
+ sizeof (STUB_SUFFIX
);
3202 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3206 memcpy (s_name
, link_sec
->name
, namelen
);
3207 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3208 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3209 if (stub_sec
== NULL
)
3211 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3213 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3216 /* Enter this entry into the linker stub hash table. */
3217 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3219 if (stub_entry
== NULL
)
3221 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3227 stub_entry
->stub_sec
= stub_sec
;
3228 stub_entry
->stub_offset
= 0;
3229 stub_entry
->id_sec
= link_sec
;
3234 /* Store an Arm insn into an output section not processed by
3235 elf32_arm_write_section. */
3238 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
3239 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3241 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3242 bfd_putl32 (val
, ptr
);
3244 bfd_putb32 (val
, ptr
);
3247 /* Store a 16-bit Thumb insn into an output section not processed by
3248 elf32_arm_write_section. */
3251 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
3252 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3254 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3255 bfd_putl16 (val
, ptr
);
3257 bfd_putb16 (val
, ptr
);
3261 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3264 struct elf32_arm_stub_hash_entry
*stub_entry
;
3265 struct bfd_link_info
*info
;
3266 struct elf32_arm_link_hash_table
*htab
;
3274 const insn_sequence
*template;
3276 struct elf32_arm_link_hash_table
* globals
;
3277 int stub_reloc_idx
= -1;
3278 int stub_reloc_offset
= 0;
3280 /* Massage our args to the form they really have. */
3281 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3282 info
= (struct bfd_link_info
*) in_arg
;
3284 globals
= elf32_arm_hash_table (info
);
3286 htab
= elf32_arm_hash_table (info
);
3287 stub_sec
= stub_entry
->stub_sec
;
3289 /* Make a note of the offset within the stubs for this entry. */
3290 stub_entry
->stub_offset
= stub_sec
->size
;
3291 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3293 stub_bfd
= stub_sec
->owner
;
3295 /* This is the address of the start of the stub. */
3296 stub_addr
= stub_sec
->output_section
->vma
+ stub_sec
->output_offset
3297 + stub_entry
->stub_offset
;
3299 /* This is the address of the stub destination. */
3300 sym_value
= (stub_entry
->target_value
3301 + stub_entry
->target_section
->output_offset
3302 + stub_entry
->target_section
->output_section
->vma
);
3304 template = stub_entry
->stub_template
;
3305 template_size
= stub_entry
->stub_template_size
;
3308 for (i
= 0; i
< template_size
; i
++)
3310 switch (template[i
].type
)
3313 put_thumb_insn (globals
, stub_bfd
, template[i
].data
, loc
+ size
);
3318 put_arm_insn (globals
, stub_bfd
, template[i
].data
, loc
+ size
);
3319 /* Handle cases where the target is encoded within the
3321 if (template[i
].r_type
== R_ARM_JUMP24
)
3324 stub_reloc_offset
= size
;
3330 bfd_put_32 (stub_bfd
, template[i
].data
, loc
+ size
);
3332 stub_reloc_offset
= size
;
3342 stub_sec
->size
+= size
;
3344 /* Stub size has already been computed in arm_size_one_stub. Check
3346 BFD_ASSERT (size
== stub_entry
->stub_size
);
3348 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3349 if (stub_entry
->st_type
== STT_ARM_TFUNC
)
3352 /* Assume there is one and only one entry to relocate in each stub. */
3353 BFD_ASSERT (stub_reloc_idx
!= -1);
3355 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx
].r_type
),
3356 stub_bfd
, stub_sec
, stub_sec
->contents
,
3357 stub_entry
->stub_offset
+ stub_reloc_offset
,
3358 sym_value
, template[stub_reloc_idx
].reloc_addend
);
3363 /* As above, but don't actually build the stub. Just bump offset so
3364 we know stub section sizes. */
3367 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3370 struct elf32_arm_stub_hash_entry
*stub_entry
;
3371 struct elf32_arm_link_hash_table
*htab
;
3372 const insn_sequence
*template;
3377 /* Massage our args to the form they really have. */
3378 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3379 htab
= (struct elf32_arm_link_hash_table
*) in_arg
;
3381 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
3382 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
3384 template = stub_definitions
[stub_entry
->stub_type
].template;
3385 template_size
= stub_definitions
[stub_entry
->stub_type
].template_size
;
3388 for (i
= 0; i
< template_size
; i
++)
3390 switch (template[i
].type
)
3410 stub_entry
->stub_size
= size
;
3411 stub_entry
->stub_template
= template;
3412 stub_entry
->stub_template_size
= template_size
;
3414 size
= (size
+ 7) & ~7;
3415 stub_entry
->stub_sec
->size
+= size
;
3420 /* External entry points for sizing and building linker stubs. */
3422 /* Set up various things so that we can make a list of input sections
3423 for each output section included in the link. Returns -1 on error,
3424 0 when no stubs will be needed, and 1 on success. */
3427 elf32_arm_setup_section_lists (bfd
*output_bfd
,
3428 struct bfd_link_info
*info
)
3431 unsigned int bfd_count
;
3432 int top_id
, top_index
;
3434 asection
**input_list
, **list
;
3436 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3438 if (! is_elf_hash_table (htab
))
3441 /* Count the number of input BFDs and find the top input section id. */
3442 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3444 input_bfd
= input_bfd
->link_next
)
3447 for (section
= input_bfd
->sections
;
3449 section
= section
->next
)
3451 if (top_id
< section
->id
)
3452 top_id
= section
->id
;
3455 htab
->bfd_count
= bfd_count
;
3457 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3458 htab
->stub_group
= bfd_zmalloc (amt
);
3459 if (htab
->stub_group
== NULL
)
3462 /* We can't use output_bfd->section_count here to find the top output
3463 section index as some sections may have been removed, and
3464 _bfd_strip_section_from_output doesn't renumber the indices. */
3465 for (section
= output_bfd
->sections
, top_index
= 0;
3467 section
= section
->next
)
3469 if (top_index
< section
->index
)
3470 top_index
= section
->index
;
3473 htab
->top_index
= top_index
;
3474 amt
= sizeof (asection
*) * (top_index
+ 1);
3475 input_list
= bfd_malloc (amt
);
3476 htab
->input_list
= input_list
;
3477 if (input_list
== NULL
)
3480 /* For sections we aren't interested in, mark their entries with a
3481 value we can check later. */
3482 list
= input_list
+ top_index
;
3484 *list
= bfd_abs_section_ptr
;
3485 while (list
-- != input_list
);
3487 for (section
= output_bfd
->sections
;
3489 section
= section
->next
)
3491 if ((section
->flags
& SEC_CODE
) != 0)
3492 input_list
[section
->index
] = NULL
;
3498 /* The linker repeatedly calls this function for each input section,
3499 in the order that input sections are linked into output sections.
3500 Build lists of input sections to determine groupings between which
3501 we may insert linker stubs. */
3504 elf32_arm_next_input_section (struct bfd_link_info
*info
,
3507 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3509 if (isec
->output_section
->index
<= htab
->top_index
)
3511 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3513 if (*list
!= bfd_abs_section_ptr
)
3515 /* Steal the link_sec pointer for our list. */
3516 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3517 /* This happens to make the list in reverse order,
3518 which we reverse later. */
3519 PREV_SEC (isec
) = *list
;
3525 /* See whether we can group stub sections together. Grouping stub
3526 sections may result in fewer stubs. More importantly, we need to
3527 put all .init* and .fini* stubs at the end of the .init or
3528 .fini output sections respectively, because glibc splits the
3529 _init and _fini functions into multiple parts. Putting a stub in
3530 the middle of a function is not a good idea. */
3533 group_sections (struct elf32_arm_link_hash_table
*htab
,
3534 bfd_size_type stub_group_size
,
3535 bfd_boolean stubs_always_after_branch
)
3537 asection
**list
= htab
->input_list
;
3541 asection
*tail
= *list
;
3544 if (tail
== bfd_abs_section_ptr
)
3547 /* Reverse the list: we must avoid placing stubs at the
3548 beginning of the section because the beginning of the text
3549 section may be required for an interrupt vector in bare metal
3551 #define NEXT_SEC PREV_SEC
3553 while (tail
!= NULL
)
3555 /* Pop from tail. */
3556 asection
*item
= tail
;
3557 tail
= PREV_SEC (item
);
3560 NEXT_SEC (item
) = head
;
3564 while (head
!= NULL
)
3568 bfd_vma stub_group_start
= head
->output_offset
;
3569 bfd_vma end_of_next
;
3572 while (NEXT_SEC (curr
) != NULL
)
3574 next
= NEXT_SEC (curr
);
3575 end_of_next
= next
->output_offset
+ next
->size
;
3576 if (end_of_next
- stub_group_start
>= stub_group_size
)
3577 /* End of NEXT is too far from start, so stop. */
3579 /* Add NEXT to the group. */
3583 /* OK, the size from the start to the start of CURR is less
3584 than stub_group_size and thus can be handled by one stub
3585 section. (Or the head section is itself larger than
3586 stub_group_size, in which case we may be toast.)
3587 We should really be keeping track of the total size of
3588 stubs added here, as stubs contribute to the final output
3592 next
= NEXT_SEC (head
);
3593 /* Set up this stub group. */
3594 htab
->stub_group
[head
->id
].link_sec
= curr
;
3596 while (head
!= curr
&& (head
= next
) != NULL
);
3598 /* But wait, there's more! Input sections up to stub_group_size
3599 bytes after the stub section can be handled by it too. */
3600 if (!stubs_always_after_branch
)
3602 stub_group_start
= curr
->output_offset
+ curr
->size
;
3604 while (next
!= NULL
)
3606 end_of_next
= next
->output_offset
+ next
->size
;
3607 if (end_of_next
- stub_group_start
>= stub_group_size
)
3608 /* End of NEXT is too far from stubs, so stop. */
3610 /* Add NEXT to the stub group. */
3612 next
= NEXT_SEC (head
);
3613 htab
->stub_group
[head
->id
].link_sec
= curr
;
3619 while (list
++ != htab
->input_list
+ htab
->top_index
);
3621 free (htab
->input_list
);
3626 /* Determine and set the size of the stub section for a final link.
3628 The basic idea here is to examine all the relocations looking for
3629 PC-relative calls to a target that is unreachable with a "bl"
3633 elf32_arm_size_stubs (bfd
*output_bfd
,
3635 struct bfd_link_info
*info
,
3636 bfd_signed_vma group_size
,
3637 asection
* (*add_stub_section
) (const char *, asection
*),
3638 void (*layout_sections_again
) (void))
3640 bfd_size_type stub_group_size
;
3641 bfd_boolean stubs_always_after_branch
;
3642 bfd_boolean stub_changed
= 0;
3643 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3645 /* Propagate mach to stub bfd, because it may not have been
3646 finalized when we created stub_bfd. */
3647 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3648 bfd_get_mach (output_bfd
));
3650 /* Stash our params away. */
3651 htab
->stub_bfd
= stub_bfd
;
3652 htab
->add_stub_section
= add_stub_section
;
3653 htab
->layout_sections_again
= layout_sections_again
;
3654 stubs_always_after_branch
= group_size
< 0;
3656 stub_group_size
= -group_size
;
3658 stub_group_size
= group_size
;
3660 if (stub_group_size
== 1)
3662 /* Default values. */
3663 /* Thumb branch range is +-4MB has to be used as the default
3664 maximum size (a given section can contain both ARM and Thumb
3665 code, so the worst case has to be taken into account).
3667 This value is 24K less than that, which allows for 2025
3668 12-byte stubs. If we exceed that, then we will fail to link.
3669 The user will have to relink with an explicit group size
3671 stub_group_size
= 4170000;
3674 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
3679 unsigned int bfd_indx
;
3682 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
3684 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
3686 Elf_Internal_Shdr
*symtab_hdr
;
3688 Elf_Internal_Sym
*local_syms
= NULL
;
3690 /* We'll need the symbol table in a second. */
3691 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3692 if (symtab_hdr
->sh_info
== 0)
3695 /* Walk over each section attached to the input bfd. */
3696 for (section
= input_bfd
->sections
;
3698 section
= section
->next
)
3700 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3702 /* If there aren't any relocs, then there's nothing more
3704 if ((section
->flags
& SEC_RELOC
) == 0
3705 || section
->reloc_count
== 0
3706 || (section
->flags
& SEC_CODE
) == 0)
3709 /* If this section is a link-once section that will be
3710 discarded, then don't create any stubs. */
3711 if (section
->output_section
== NULL
3712 || section
->output_section
->owner
!= output_bfd
)
3715 /* Get the relocs. */
3717 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3718 NULL
, info
->keep_memory
);
3719 if (internal_relocs
== NULL
)
3720 goto error_ret_free_local
;
3722 /* Now examine each relocation. */
3723 irela
= internal_relocs
;
3724 irelaend
= irela
+ section
->reloc_count
;
3725 for (; irela
< irelaend
; irela
++)
3727 unsigned int r_type
, r_indx
;
3728 enum elf32_arm_stub_type stub_type
;
3729 struct elf32_arm_stub_hash_entry
*stub_entry
;
3732 bfd_vma destination
;
3733 struct elf32_arm_link_hash_entry
*hash
;
3734 const char *sym_name
;
3736 const asection
*id_sec
;
3737 unsigned char st_type
;
3739 r_type
= ELF32_R_TYPE (irela
->r_info
);
3740 r_indx
= ELF32_R_SYM (irela
->r_info
);
3742 if (r_type
>= (unsigned int) R_ARM_max
)
3744 bfd_set_error (bfd_error_bad_value
);
3745 error_ret_free_internal
:
3746 if (elf_section_data (section
)->relocs
== NULL
)
3747 free (internal_relocs
);
3748 goto error_ret_free_local
;
3751 /* Only look for stubs on branch instructions. */
3752 if ((r_type
!= (unsigned int) R_ARM_CALL
)
3753 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
3754 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
3755 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
3756 && (r_type
!= (unsigned int) R_ARM_PLT32
))
3759 /* Now determine the call target, its name, value,
3766 if (r_indx
< symtab_hdr
->sh_info
)
3768 /* It's a local symbol. */
3769 Elf_Internal_Sym
*sym
;
3770 Elf_Internal_Shdr
*hdr
;
3772 if (local_syms
== NULL
)
3775 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3776 if (local_syms
== NULL
)
3778 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3779 symtab_hdr
->sh_info
, 0,
3781 if (local_syms
== NULL
)
3782 goto error_ret_free_internal
;
3785 sym
= local_syms
+ r_indx
;
3786 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3787 sym_sec
= hdr
->bfd_section
;
3788 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3789 sym_value
= sym
->st_value
;
3790 destination
= (sym_value
+ irela
->r_addend
3791 + sym_sec
->output_offset
3792 + sym_sec
->output_section
->vma
);
3793 st_type
= ELF_ST_TYPE (sym
->st_info
);
3795 = bfd_elf_string_from_elf_section (input_bfd
,
3796 symtab_hdr
->sh_link
,
3801 /* It's an external symbol. */
3804 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3805 hash
= ((struct elf32_arm_link_hash_entry
*)
3806 elf_sym_hashes (input_bfd
)[e_indx
]);
3808 while (hash
->root
.root
.type
== bfd_link_hash_indirect
3809 || hash
->root
.root
.type
== bfd_link_hash_warning
)
3810 hash
= ((struct elf32_arm_link_hash_entry
*)
3811 hash
->root
.root
.u
.i
.link
);
3813 if (hash
->root
.root
.type
== bfd_link_hash_defined
3814 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
3816 sym_sec
= hash
->root
.root
.u
.def
.section
;
3817 sym_value
= hash
->root
.root
.u
.def
.value
;
3818 if (sym_sec
->output_section
!= NULL
)
3819 destination
= (sym_value
+ irela
->r_addend
3820 + sym_sec
->output_offset
3821 + sym_sec
->output_section
->vma
);
3823 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
3824 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
3826 /* For a shared library, use the PLT stub as
3827 target address to decide whether a long
3828 branch stub is needed.
3829 For absolute code, they cannot be handled. */
3830 struct elf32_arm_link_hash_table
*globals
=
3831 elf32_arm_hash_table (info
);
3833 if (globals
->splt
!= NULL
&& hash
!= NULL
3834 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
3836 sym_sec
= globals
->splt
;
3837 sym_value
= hash
->root
.plt
.offset
;
3838 if (sym_sec
->output_section
!= NULL
)
3839 destination
= (sym_value
3840 + sym_sec
->output_offset
3841 + sym_sec
->output_section
->vma
);
3848 bfd_set_error (bfd_error_bad_value
);
3849 goto error_ret_free_internal
;
3851 st_type
= ELF_ST_TYPE (hash
->root
.type
);
3852 sym_name
= hash
->root
.root
.root
.string
;
3855 /* Determine what (if any) linker stub is needed. */
3856 stub_type
= arm_type_of_stub (info
, section
, irela
, st_type
,
3857 hash
, destination
, sym_sec
,
3858 input_bfd
, sym_name
);
3859 if (stub_type
== arm_stub_none
)
3862 /* Support for grouping stub sections. */
3863 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3865 /* Get the name of this stub. */
3866 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
, irela
);
3868 goto error_ret_free_internal
;
3870 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3873 if (stub_entry
!= NULL
)
3875 /* The proper stub has already been created. */
3880 stub_entry
= elf32_arm_add_stub (stub_name
, section
, htab
);
3881 if (stub_entry
== NULL
)
3884 goto error_ret_free_internal
;
3887 stub_entry
->target_value
= sym_value
;
3888 stub_entry
->target_section
= sym_sec
;
3889 stub_entry
->stub_type
= stub_type
;
3890 stub_entry
->h
= hash
;
3891 stub_entry
->st_type
= st_type
;
3893 if (sym_name
== NULL
)
3894 sym_name
= "unnamed";
3895 stub_entry
->output_name
3896 = bfd_alloc (htab
->stub_bfd
,
3897 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
3898 + strlen (sym_name
));
3899 if (stub_entry
->output_name
== NULL
)
3902 goto error_ret_free_internal
;
3905 /* For historical reasons, use the existing names for
3906 ARM-to-Thumb and Thumb-to-ARM stubs. */
3907 if ( ((r_type
== (unsigned int) R_ARM_THM_CALL
)
3908 || (r_type
== (unsigned int) R_ARM_THM_JUMP24
))
3909 && st_type
!= STT_ARM_TFUNC
)
3910 sprintf (stub_entry
->output_name
, THUMB2ARM_GLUE_ENTRY_NAME
,
3912 else if ( ((r_type
== (unsigned int) R_ARM_CALL
)
3913 || (r_type
== (unsigned int) R_ARM_JUMP24
))
3914 && st_type
== STT_ARM_TFUNC
)
3915 sprintf (stub_entry
->output_name
, ARM2THUMB_GLUE_ENTRY_NAME
,
3918 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
3921 stub_changed
= TRUE
;
3924 /* We're done with the internal relocs, free them. */
3925 if (elf_section_data (section
)->relocs
== NULL
)
3926 free (internal_relocs
);
3933 /* OK, we've added some stubs. Find out the new size of the
3935 for (stub_sec
= htab
->stub_bfd
->sections
;
3937 stub_sec
= stub_sec
->next
)
3939 /* Ignore non-stub sections. */
3940 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3946 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
3948 /* Ask the linker to do its stuff. */
3949 (*htab
->layout_sections_again
) ();
3950 stub_changed
= FALSE
;
3955 error_ret_free_local
:
3959 /* Build all the stubs associated with the current output file. The
3960 stubs are kept in a hash table attached to the main linker hash
3961 table. We also set up the .plt entries for statically linked PIC
3962 functions here. This function is called via arm_elf_finish in the
3966 elf32_arm_build_stubs (struct bfd_link_info
*info
)
3969 struct bfd_hash_table
*table
;
3970 struct elf32_arm_link_hash_table
*htab
;
3972 htab
= elf32_arm_hash_table (info
);
3974 for (stub_sec
= htab
->stub_bfd
->sections
;
3976 stub_sec
= stub_sec
->next
)
3980 /* Ignore non-stub sections. */
3981 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3984 /* Allocate memory to hold the linker stubs. */
3985 size
= stub_sec
->size
;
3986 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3987 if (stub_sec
->contents
== NULL
&& size
!= 0)
3992 /* Build the stubs as directed by the stub hash table. */
3993 table
= &htab
->stub_hash_table
;
3994 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
3999 /* Locate the Thumb encoded calling stub for NAME. */
4001 static struct elf_link_hash_entry
*
4002 find_thumb_glue (struct bfd_link_info
*link_info
,
4004 char **error_message
)
4007 struct elf_link_hash_entry
*hash
;
4008 struct elf32_arm_link_hash_table
*hash_table
;
4010 /* We need a pointer to the armelf specific hash table. */
4011 hash_table
= elf32_arm_hash_table (link_info
);
4013 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4014 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
4016 BFD_ASSERT (tmp_name
);
4018 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
4020 hash
= elf_link_hash_lookup
4021 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4024 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
4025 tmp_name
, name
) == -1)
4026 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
4033 /* Locate the ARM encoded calling stub for NAME. */
4035 static struct elf_link_hash_entry
*
4036 find_arm_glue (struct bfd_link_info
*link_info
,
4038 char **error_message
)
4041 struct elf_link_hash_entry
*myh
;
4042 struct elf32_arm_link_hash_table
*hash_table
;
4044 /* We need a pointer to the elfarm specific hash table. */
4045 hash_table
= elf32_arm_hash_table (link_info
);
4047 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4048 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
4050 BFD_ASSERT (tmp_name
);
4052 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
4054 myh
= elf_link_hash_lookup
4055 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4058 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
4059 tmp_name
, name
) == -1)
4060 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
4067 /* ARM->Thumb glue (static images):
4071 ldr r12, __func_addr
4074 .word func @ behave as if you saw a ARM_32 reloc.
4081 .word func @ behave as if you saw a ARM_32 reloc.
4083 (relocatable images)
4086 ldr r12, __func_offset
4092 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4093 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
4094 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
4095 static const insn32 a2t3_func_addr_insn
= 0x00000001;
4097 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4098 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
4099 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
4101 #define ARM2THUMB_PIC_GLUE_SIZE 16
4102 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
4103 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
4104 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
4106 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4110 __func_from_thumb: __func_from_thumb:
4112 nop ldr r6, __func_addr
4122 #define THUMB2ARM_GLUE_SIZE 8
4123 static const insn16 t2a1_bx_pc_insn
= 0x4778;
4124 static const insn16 t2a2_noop_insn
= 0x46c0;
4125 static const insn32 t2a3_b_insn
= 0xea000000;
4127 #define VFP11_ERRATUM_VENEER_SIZE 8
4129 #define ARM_BX_VENEER_SIZE 12
4130 static const insn32 armbx1_tst_insn
= 0xe3100001;
4131 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
4132 static const insn32 armbx3_bx_insn
= 0xe12fff10;
4134 #ifndef ELFARM_NABI_C_INCLUDED
4136 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
4139 bfd_byte
* contents
;
4143 /* Do not include empty glue sections in the output. */
4146 s
= bfd_get_section_by_name (abfd
, name
);
4148 s
->flags
|= SEC_EXCLUDE
;
4153 BFD_ASSERT (abfd
!= NULL
);
4155 s
= bfd_get_section_by_name (abfd
, name
);
4156 BFD_ASSERT (s
!= NULL
);
4158 contents
= bfd_alloc (abfd
, size
);
4160 BFD_ASSERT (s
->size
== size
);
4161 s
->contents
= contents
;
4165 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
4167 struct elf32_arm_link_hash_table
* globals
;
4169 globals
= elf32_arm_hash_table (info
);
4170 BFD_ASSERT (globals
!= NULL
);
4172 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4173 globals
->arm_glue_size
,
4174 ARM2THUMB_GLUE_SECTION_NAME
);
4176 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4177 globals
->thumb_glue_size
,
4178 THUMB2ARM_GLUE_SECTION_NAME
);
4180 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4181 globals
->vfp11_erratum_glue_size
,
4182 VFP11_ERRATUM_VENEER_SECTION_NAME
);
4184 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4185 globals
->bx_glue_size
,
4186 ARM_BX_GLUE_SECTION_NAME
);
4191 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4192 returns the symbol identifying the stub. */
4194 static struct elf_link_hash_entry
*
4195 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
4196 struct elf_link_hash_entry
* h
)
4198 const char * name
= h
->root
.root
.string
;
4201 struct elf_link_hash_entry
* myh
;
4202 struct bfd_link_hash_entry
* bh
;
4203 struct elf32_arm_link_hash_table
* globals
;
4207 globals
= elf32_arm_hash_table (link_info
);
4209 BFD_ASSERT (globals
!= NULL
);
4210 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
4212 s
= bfd_get_section_by_name
4213 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
4215 BFD_ASSERT (s
!= NULL
);
4217 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
4219 BFD_ASSERT (tmp_name
);
4221 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
4223 myh
= elf_link_hash_lookup
4224 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4228 /* We've already seen this guy. */
4233 /* The only trick here is using hash_table->arm_glue_size as the value.
4234 Even though the section isn't allocated yet, this is where we will be
4235 putting it. The +1 on the value marks that the stub has not been
4236 output yet - not that it is a Thumb function. */
4238 val
= globals
->arm_glue_size
+ 1;
4239 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
4240 tmp_name
, BSF_GLOBAL
, s
, val
,
4241 NULL
, TRUE
, FALSE
, &bh
);
4243 myh
= (struct elf_link_hash_entry
*) bh
;
4244 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4245 myh
->forced_local
= 1;
4249 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
4250 || globals
->pic_veneer
)
4251 size
= ARM2THUMB_PIC_GLUE_SIZE
;
4252 else if (globals
->use_blx
)
4253 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
4255 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
4258 globals
->arm_glue_size
+= size
;
4263 /* Allocate space for ARMv4 BX veneers. */
4266 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
4269 struct elf32_arm_link_hash_table
*globals
;
4271 struct elf_link_hash_entry
*myh
;
4272 struct bfd_link_hash_entry
*bh
;
4275 /* BX PC does not need a veneer. */
4279 globals
= elf32_arm_hash_table (link_info
);
4281 BFD_ASSERT (globals
!= NULL
);
4282 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
4284 /* Check if this veneer has already been allocated. */
4285 if (globals
->bx_glue_offset
[reg
])
4288 s
= bfd_get_section_by_name
4289 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
4291 BFD_ASSERT (s
!= NULL
);
4293 /* Add symbol for veneer. */
4294 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
4296 BFD_ASSERT (tmp_name
);
4298 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
4300 myh
= elf_link_hash_lookup
4301 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4303 BFD_ASSERT (myh
== NULL
);
4306 val
= globals
->bx_glue_size
;
4307 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
4308 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
4309 NULL
, TRUE
, FALSE
, &bh
);
4311 myh
= (struct elf_link_hash_entry
*) bh
;
4312 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4313 myh
->forced_local
= 1;
4315 s
->size
+= ARM_BX_VENEER_SIZE
;
4316 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
4317 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
4321 /* Add an entry to the code/data map for section SEC. */
4324 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4326 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
4327 unsigned int newidx
;
4329 if (sec_data
->map
== NULL
)
4331 sec_data
->map
= bfd_malloc (sizeof (elf32_arm_section_map
));
4332 sec_data
->mapcount
= 0;
4333 sec_data
->mapsize
= 1;
4336 newidx
= sec_data
->mapcount
++;
4338 if (sec_data
->mapcount
> sec_data
->mapsize
)
4340 sec_data
->mapsize
*= 2;
4341 sec_data
->map
= bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
4342 * sizeof (elf32_arm_section_map
));
4347 sec_data
->map
[newidx
].vma
= vma
;
4348 sec_data
->map
[newidx
].type
= type
;
4353 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4354 veneers are handled for now. */
4357 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
4358 elf32_vfp11_erratum_list
*branch
,
4360 asection
*branch_sec
,
4361 unsigned int offset
)
4364 struct elf32_arm_link_hash_table
*hash_table
;
4366 struct elf_link_hash_entry
*myh
;
4367 struct bfd_link_hash_entry
*bh
;
4369 struct _arm_elf_section_data
*sec_data
;
4371 elf32_vfp11_erratum_list
*newerr
;
4373 hash_table
= elf32_arm_hash_table (link_info
);
4375 BFD_ASSERT (hash_table
!= NULL
);
4376 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
4378 s
= bfd_get_section_by_name
4379 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
4381 sec_data
= elf32_arm_section_data (s
);
4383 BFD_ASSERT (s
!= NULL
);
4385 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
4386 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
4388 BFD_ASSERT (tmp_name
);
4390 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
4391 hash_table
->num_vfp11_fixes
);
4393 myh
= elf_link_hash_lookup
4394 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4396 BFD_ASSERT (myh
== NULL
);
4399 val
= hash_table
->vfp11_erratum_glue_size
;
4400 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
4401 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
4402 NULL
, TRUE
, FALSE
, &bh
);
4404 myh
= (struct elf_link_hash_entry
*) bh
;
4405 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4406 myh
->forced_local
= 1;
4408 /* Link veneer back to calling location. */
4409 errcount
= ++(sec_data
->erratumcount
);
4410 newerr
= bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
4412 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
4414 newerr
->u
.v
.branch
= branch
;
4415 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
4416 branch
->u
.b
.veneer
= newerr
;
4418 newerr
->next
= sec_data
->erratumlist
;
4419 sec_data
->erratumlist
= newerr
;
4421 /* A symbol for the return from the veneer. */
4422 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
4423 hash_table
->num_vfp11_fixes
);
4425 myh
= elf_link_hash_lookup
4426 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4433 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
4434 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
4436 myh
= (struct elf_link_hash_entry
*) bh
;
4437 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4438 myh
->forced_local
= 1;
4442 /* Generate a mapping symbol for the veneer section, and explicitly add an
4443 entry for that symbol to the code/data map for the section. */
4444 if (hash_table
->vfp11_erratum_glue_size
== 0)
4447 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4448 ever requires this erratum fix. */
4449 _bfd_generic_link_add_one_symbol (link_info
,
4450 hash_table
->bfd_of_glue_owner
, "$a",
4451 BSF_LOCAL
, s
, 0, NULL
,
4454 myh
= (struct elf_link_hash_entry
*) bh
;
4455 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
4456 myh
->forced_local
= 1;
4458 /* The elf32_arm_init_maps function only cares about symbols from input
4459 BFDs. We must make a note of this generated mapping symbol
4460 ourselves so that code byteswapping works properly in
4461 elf32_arm_write_section. */
4462 elf32_arm_section_map_add (s
, 'a', 0);
4465 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
4466 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
4467 hash_table
->num_vfp11_fixes
++;
4469 /* The offset of the veneer. */
4473 #define ARM_GLUE_SECTION_FLAGS \
4474 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
4475 | SEC_READONLY | SEC_LINKER_CREATED)
4477 /* Create a fake section for use by the ARM backend of the linker. */
4480 arm_make_glue_section (bfd
* abfd
, const char * name
)
4484 sec
= bfd_get_section_by_name (abfd
, name
);
4489 sec
= bfd_make_section_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
4492 || !bfd_set_section_alignment (abfd
, sec
, 2))
4495 /* Set the gc mark to prevent the section from being removed by garbage
4496 collection, despite the fact that no relocs refer to this section. */
4502 /* Add the glue sections to ABFD. This function is called from the
4503 linker scripts in ld/emultempl/{armelf}.em. */
4506 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
4507 struct bfd_link_info
*info
)
4509 /* If we are only performing a partial
4510 link do not bother adding the glue. */
4511 if (info
->relocatable
)
4514 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
4515 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
4516 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
4517 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
4520 /* Select a BFD to be used to hold the sections used by the glue code.
4521 This function is called from the linker scripts in ld/emultempl/
4525 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
4527 struct elf32_arm_link_hash_table
*globals
;
4529 /* If we are only performing a partial link
4530 do not bother getting a bfd to hold the glue. */
4531 if (info
->relocatable
)
4534 /* Make sure we don't attach the glue sections to a dynamic object. */
4535 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
4537 globals
= elf32_arm_hash_table (info
);
4539 BFD_ASSERT (globals
!= NULL
);
4541 if (globals
->bfd_of_glue_owner
!= NULL
)
4544 /* Save the bfd for later use. */
4545 globals
->bfd_of_glue_owner
= abfd
;
4551 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
4553 if (bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
4555 globals
->use_blx
= 1;
4559 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
4560 struct bfd_link_info
*link_info
)
4562 Elf_Internal_Shdr
*symtab_hdr
;
4563 Elf_Internal_Rela
*internal_relocs
= NULL
;
4564 Elf_Internal_Rela
*irel
, *irelend
;
4565 bfd_byte
*contents
= NULL
;
4568 struct elf32_arm_link_hash_table
*globals
;
4570 /* If we are only performing a partial link do not bother
4571 to construct any glue. */
4572 if (link_info
->relocatable
)
4575 /* Here we have a bfd that is to be included on the link. We have a
4576 hook to do reloc rummaging, before section sizes are nailed down. */
4577 globals
= elf32_arm_hash_table (link_info
);
4579 BFD_ASSERT (globals
!= NULL
);
4581 check_use_blx (globals
);
4583 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
4585 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4590 /* PR 5398: If we have not decided to include any loadable sections in
4591 the output then we will not have a glue owner bfd. This is OK, it
4592 just means that there is nothing else for us to do here. */
4593 if (globals
->bfd_of_glue_owner
== NULL
)
4596 /* Rummage around all the relocs and map the glue vectors. */
4597 sec
= abfd
->sections
;
4602 for (; sec
!= NULL
; sec
= sec
->next
)
4604 if (sec
->reloc_count
== 0)
4607 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
4610 symtab_hdr
= & elf_symtab_hdr (abfd
);
4612 /* Load the relocs. */
4614 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
4616 if (internal_relocs
== NULL
)
4619 irelend
= internal_relocs
+ sec
->reloc_count
;
4620 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
4623 unsigned long r_index
;
4625 struct elf_link_hash_entry
*h
;
4627 r_type
= ELF32_R_TYPE (irel
->r_info
);
4628 r_index
= ELF32_R_SYM (irel
->r_info
);
4630 /* These are the only relocation types we care about. */
4631 if ( r_type
!= R_ARM_PC24
4632 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
4635 /* Get the section contents if we haven't done so already. */
4636 if (contents
== NULL
)
4638 /* Get cached copy if it exists. */
4639 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
4640 contents
= elf_section_data (sec
)->this_hdr
.contents
;
4643 /* Go get them off disk. */
4644 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
4649 if (r_type
== R_ARM_V4BX
)
4653 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
4654 record_arm_bx_glue (link_info
, reg
);
4658 /* If the relocation is not against a symbol it cannot concern us. */
4661 /* We don't care about local symbols. */
4662 if (r_index
< symtab_hdr
->sh_info
)
4665 /* This is an external symbol. */
4666 r_index
-= symtab_hdr
->sh_info
;
4667 h
= (struct elf_link_hash_entry
*)
4668 elf_sym_hashes (abfd
)[r_index
];
4670 /* If the relocation is against a static symbol it must be within
4671 the current section and so cannot be a cross ARM/Thumb relocation. */
4675 /* If the call will go through a PLT entry then we do not need
4677 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
4683 /* This one is a call from arm code. We need to look up
4684 the target of the call. If it is a thumb target, we
4686 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
4687 record_arm_to_thumb_glue (link_info
, h
);
4695 if (contents
!= NULL
4696 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
4700 if (internal_relocs
!= NULL
4701 && elf_section_data (sec
)->relocs
!= internal_relocs
)
4702 free (internal_relocs
);
4703 internal_relocs
= NULL
;
4709 if (contents
!= NULL
4710 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
4712 if (internal_relocs
!= NULL
4713 && elf_section_data (sec
)->relocs
!= internal_relocs
)
4714 free (internal_relocs
);
4721 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4724 bfd_elf32_arm_init_maps (bfd
*abfd
)
4726 Elf_Internal_Sym
*isymbuf
;
4727 Elf_Internal_Shdr
*hdr
;
4728 unsigned int i
, localsyms
;
4730 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4731 if (! is_arm_elf (abfd
))
4734 if ((abfd
->flags
& DYNAMIC
) != 0)
4737 hdr
= & elf_symtab_hdr (abfd
);
4738 localsyms
= hdr
->sh_info
;
4740 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4741 should contain the number of local symbols, which should come before any
4742 global symbols. Mapping symbols are always local. */
4743 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
4746 /* No internal symbols read? Skip this BFD. */
4747 if (isymbuf
== NULL
)
4750 for (i
= 0; i
< localsyms
; i
++)
4752 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4753 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4757 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4759 name
= bfd_elf_string_from_elf_section (abfd
,
4760 hdr
->sh_link
, isym
->st_name
);
4762 if (bfd_is_arm_special_symbol_name (name
,
4763 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
4764 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
4771 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
4773 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
4774 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
4776 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4777 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
4779 switch (globals
->vfp11_fix
)
4781 case BFD_ARM_VFP11_FIX_DEFAULT
:
4782 case BFD_ARM_VFP11_FIX_NONE
:
4783 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
4787 /* Give a warning, but do as the user requests anyway. */
4788 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
4789 "workaround is not necessary for target architecture"), obfd
);
4792 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
4793 /* For earlier architectures, we might need the workaround, but do not
4794 enable it by default. If users is running with broken hardware, they
4795 must enable the erratum fix explicitly. */
4796 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
4800 enum bfd_arm_vfp11_pipe
4808 /* Return a VFP register number. This is encoded as RX:X for single-precision
4809 registers, or X:RX for double-precision registers, where RX is the group of
4810 four bits in the instruction encoding and X is the single extension bit.
4811 RX and X fields are specified using their lowest (starting) bit. The return
4814 0...31: single-precision registers s0...s31
4815 32...63: double-precision registers d0...d31.
4817 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4818 encounter VFP3 instructions, so we allow the full range for DP registers. */
4821 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
4825 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
4827 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
4830 /* Set bits in *WMASK according to a register number REG as encoded by
4831 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4834 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
4839 *wmask
|= 3 << ((reg
- 32) * 2);
4842 /* Return TRUE if WMASK overwrites anything in REGS. */
4845 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
4849 for (i
= 0; i
< numregs
; i
++)
4851 unsigned int reg
= regs
[i
];
4853 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
4861 if ((wmask
& (3 << (reg
* 2))) != 0)
4868 /* In this function, we're interested in two things: finding input registers
4869 for VFP data-processing instructions, and finding the set of registers which
4870 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4871 hold the written set, so FLDM etc. are easy to deal with (we're only
4872 interested in 32 SP registers or 16 dp registers, due to the VFP version
4873 implemented by the chip in question). DP registers are marked by setting
4874 both SP registers in the write mask). */
4876 static enum bfd_arm_vfp11_pipe
4877 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
4880 enum bfd_arm_vfp11_pipe pipe
= VFP11_BAD
;
4881 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
4883 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4886 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
4887 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
4889 pqrs
= ((insn
& 0x00800000) >> 20)
4890 | ((insn
& 0x00300000) >> 19)
4891 | ((insn
& 0x00000040) >> 6);
4895 case 0: /* fmac[sd]. */
4896 case 1: /* fnmac[sd]. */
4897 case 2: /* fmsc[sd]. */
4898 case 3: /* fnmsc[sd]. */
4900 bfd_arm_vfp11_write_mask (destmask
, fd
);
4902 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
4907 case 4: /* fmul[sd]. */
4908 case 5: /* fnmul[sd]. */
4909 case 6: /* fadd[sd]. */
4910 case 7: /* fsub[sd]. */
4914 case 8: /* fdiv[sd]. */
4917 bfd_arm_vfp11_write_mask (destmask
, fd
);
4918 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
4923 case 15: /* extended opcode. */
4925 unsigned int extn
= ((insn
>> 15) & 0x1e)
4926 | ((insn
>> 7) & 1);
4930 case 0: /* fcpy[sd]. */
4931 case 1: /* fabs[sd]. */
4932 case 2: /* fneg[sd]. */
4933 case 8: /* fcmp[sd]. */
4934 case 9: /* fcmpe[sd]. */
4935 case 10: /* fcmpz[sd]. */
4936 case 11: /* fcmpez[sd]. */
4937 case 16: /* fuito[sd]. */
4938 case 17: /* fsito[sd]. */
4939 case 24: /* ftoui[sd]. */
4940 case 25: /* ftouiz[sd]. */
4941 case 26: /* ftosi[sd]. */
4942 case 27: /* ftosiz[sd]. */
4943 /* These instructions will not bounce due to underflow. */
4948 case 3: /* fsqrt[sd]. */
4949 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4950 registers to cause the erratum in previous instructions. */
4951 bfd_arm_vfp11_write_mask (destmask
, fd
);
4955 case 15: /* fcvt{ds,sd}. */
4959 bfd_arm_vfp11_write_mask (destmask
, fd
);
4961 /* Only FCVTSD can underflow. */
4962 if ((insn
& 0x100) != 0)
4981 /* Two-register transfer. */
4982 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
4984 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
4986 if ((insn
& 0x100000) == 0)
4989 bfd_arm_vfp11_write_mask (destmask
, fm
);
4992 bfd_arm_vfp11_write_mask (destmask
, fm
);
4993 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
4999 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
5001 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
5002 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
5006 case 0: /* Two-reg transfer. We should catch these above. */
5009 case 2: /* fldm[sdx]. */
5013 unsigned int i
, offset
= insn
& 0xff;
5018 for (i
= fd
; i
< fd
+ offset
; i
++)
5019 bfd_arm_vfp11_write_mask (destmask
, i
);
5023 case 4: /* fld[sd]. */
5025 bfd_arm_vfp11_write_mask (destmask
, fd
);
5034 /* Single-register transfer. Note L==0. */
5035 else if ((insn
& 0x0f100e10) == 0x0e000a10)
5037 unsigned int opcode
= (insn
>> 21) & 7;
5038 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
5042 case 0: /* fmsr/fmdlr. */
5043 case 1: /* fmdhr. */
5044 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5045 destination register. I don't know if this is exactly right,
5046 but it is the conservative choice. */
5047 bfd_arm_vfp11_write_mask (destmask
, fn
);
5061 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
5064 /* Look for potentially-troublesome code sequences which might trigger the
5065 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5066 (available from ARM) for details of the erratum. A short version is
5067 described in ld.texinfo. */
5070 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
5073 bfd_byte
*contents
= NULL
;
5075 int regs
[3], numregs
= 0;
5076 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
5077 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
5079 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5080 The states transition as follows:
5082 0 -> 1 (vector) or 0 -> 2 (scalar)
5083 A VFP FMAC-pipeline instruction has been seen. Fill
5084 regs[0]..regs[numregs-1] with its input operands. Remember this
5085 instruction in 'first_fmac'.
5088 Any instruction, except for a VFP instruction which overwrites
5093 A VFP instruction has been seen which overwrites any of regs[*].
5094 We must make a veneer! Reset state to 0 before examining next
5098 If we fail to match anything in state 2, reset to state 0 and reset
5099 the instruction pointer to the instruction after 'first_fmac'.
5101 If the VFP11 vector mode is in use, there must be at least two unrelated
5102 instructions between anti-dependent VFP11 instructions to properly avoid
5103 triggering the erratum, hence the use of the extra state 1. */
5105 /* If we are only performing a partial link do not bother
5106 to construct any glue. */
5107 if (link_info
->relocatable
)
5110 /* Skip if this bfd does not correspond to an ELF image. */
5111 if (! is_arm_elf (abfd
))
5114 /* We should have chosen a fix type by the time we get here. */
5115 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
5117 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
5120 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5121 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
5124 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5126 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
5127 struct _arm_elf_section_data
*sec_data
;
5129 /* If we don't have executable progbits, we're not interested in this
5130 section. Also skip if section is to be excluded. */
5131 if (elf_section_type (sec
) != SHT_PROGBITS
5132 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
5133 || (sec
->flags
& SEC_EXCLUDE
) != 0
5134 || sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
5135 || sec
->output_section
== bfd_abs_section_ptr
5136 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
5139 sec_data
= elf32_arm_section_data (sec
);
5141 if (sec_data
->mapcount
== 0)
5144 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
5145 contents
= elf_section_data (sec
)->this_hdr
.contents
;
5146 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
5149 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
5150 elf32_arm_compare_mapping
);
5152 for (span
= 0; span
< sec_data
->mapcount
; span
++)
5154 unsigned int span_start
= sec_data
->map
[span
].vma
;
5155 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
5156 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
5157 char span_type
= sec_data
->map
[span
].type
;
5159 /* FIXME: Only ARM mode is supported at present. We may need to
5160 support Thumb-2 mode also at some point. */
5161 if (span_type
!= 'a')
5164 for (i
= span_start
; i
< span_end
;)
5166 unsigned int next_i
= i
+ 4;
5167 unsigned int insn
= bfd_big_endian (abfd
)
5168 ? (contents
[i
] << 24)
5169 | (contents
[i
+ 1] << 16)
5170 | (contents
[i
+ 2] << 8)
5172 : (contents
[i
+ 3] << 24)
5173 | (contents
[i
+ 2] << 16)
5174 | (contents
[i
+ 1] << 8)
5176 unsigned int writemask
= 0;
5177 enum bfd_arm_vfp11_pipe pipe
;
5182 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
5184 /* I'm assuming the VFP11 erratum can trigger with denorm
5185 operands on either the FMAC or the DS pipeline. This might
5186 lead to slightly overenthusiastic veneer insertion. */
5187 if (pipe
== VFP11_FMAC
|| pipe
== VFP11_DS
)
5189 state
= use_vector
? 1 : 2;
5191 veneer_of_insn
= insn
;
5197 int other_regs
[3], other_numregs
;
5198 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5201 if (pipe
!= VFP11_BAD
5202 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5212 int other_regs
[3], other_numregs
;
5213 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5216 if (pipe
!= VFP11_BAD
5217 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5223 next_i
= first_fmac
+ 4;
5229 abort (); /* Should be unreachable. */
5234 elf32_vfp11_erratum_list
*newerr
5235 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5238 errcount
= ++(elf32_arm_section_data (sec
)->erratumcount
);
5240 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
5245 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
5252 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
5257 newerr
->next
= sec_data
->erratumlist
;
5258 sec_data
->erratumlist
= newerr
;
5267 if (contents
!= NULL
5268 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5276 if (contents
!= NULL
5277 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5283 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5284 after sections have been laid out, using specially-named symbols. */
5287 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
5288 struct bfd_link_info
*link_info
)
5291 struct elf32_arm_link_hash_table
*globals
;
5294 if (link_info
->relocatable
)
5297 /* Skip if this bfd does not correspond to an ELF image. */
5298 if (! is_arm_elf (abfd
))
5301 globals
= elf32_arm_hash_table (link_info
);
5303 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
5304 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5306 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5308 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5309 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
5311 for (; errnode
!= NULL
; errnode
= errnode
->next
)
5313 struct elf_link_hash_entry
*myh
;
5316 switch (errnode
->type
)
5318 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
5319 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
5320 /* Find veneer symbol. */
5321 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5322 errnode
->u
.b
.veneer
->u
.v
.id
);
5324 myh
= elf_link_hash_lookup
5325 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5328 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
5329 "`%s'"), abfd
, tmp_name
);
5331 vma
= myh
->root
.u
.def
.section
->output_section
->vma
5332 + myh
->root
.u
.def
.section
->output_offset
5333 + myh
->root
.u
.def
.value
;
5335 errnode
->u
.b
.veneer
->vma
= vma
;
5338 case VFP11_ERRATUM_ARM_VENEER
:
5339 case VFP11_ERRATUM_THUMB_VENEER
:
5340 /* Find return location. */
5341 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
5344 myh
= elf_link_hash_lookup
5345 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5348 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
5349 "`%s'"), abfd
, tmp_name
);
5351 vma
= myh
->root
.u
.def
.section
->output_section
->vma
5352 + myh
->root
.u
.def
.section
->output_offset
5353 + myh
->root
.u
.def
.value
;
5355 errnode
->u
.v
.branch
->vma
= vma
;
5368 /* Set target relocation values needed during linking. */
5371 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
5372 struct bfd_link_info
*link_info
,
5374 char * target2_type
,
5377 bfd_arm_vfp11_fix vfp11_fix
,
5378 int no_enum_warn
, int no_wchar_warn
,
5381 struct elf32_arm_link_hash_table
*globals
;
5383 globals
= elf32_arm_hash_table (link_info
);
5385 globals
->target1_is_rel
= target1_is_rel
;
5386 if (strcmp (target2_type
, "rel") == 0)
5387 globals
->target2_reloc
= R_ARM_REL32
;
5388 else if (strcmp (target2_type
, "abs") == 0)
5389 globals
->target2_reloc
= R_ARM_ABS32
;
5390 else if (strcmp (target2_type
, "got-rel") == 0)
5391 globals
->target2_reloc
= R_ARM_GOT_PREL
;
5394 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5397 globals
->fix_v4bx
= fix_v4bx
;
5398 globals
->use_blx
|= use_blx
;
5399 globals
->vfp11_fix
= vfp11_fix
;
5400 globals
->pic_veneer
= pic_veneer
;
5402 BFD_ASSERT (is_arm_elf (output_bfd
));
5403 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
5404 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
5407 /* Replace the target offset of a Thumb bl or b.w instruction. */
5410 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
5416 BFD_ASSERT ((offset
& 1) == 0);
5418 upper
= bfd_get_16 (abfd
, insn
);
5419 lower
= bfd_get_16 (abfd
, insn
+ 2);
5420 reloc_sign
= (offset
< 0) ? 1 : 0;
5421 upper
= (upper
& ~(bfd_vma
) 0x7ff)
5422 | ((offset
>> 12) & 0x3ff)
5423 | (reloc_sign
<< 10);
5424 lower
= (lower
& ~(bfd_vma
) 0x2fff)
5425 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
5426 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
5427 | ((offset
>> 1) & 0x7ff);
5428 bfd_put_16 (abfd
, upper
, insn
);
5429 bfd_put_16 (abfd
, lower
, insn
+ 2);
5432 /* Thumb code calling an ARM function. */
5435 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
5439 asection
* input_section
,
5440 bfd_byte
* hit_data
,
5443 bfd_signed_vma addend
,
5445 char **error_message
)
5449 long int ret_offset
;
5450 struct elf_link_hash_entry
* myh
;
5451 struct elf32_arm_link_hash_table
* globals
;
5453 myh
= find_thumb_glue (info
, name
, error_message
);
5457 globals
= elf32_arm_hash_table (info
);
5459 BFD_ASSERT (globals
!= NULL
);
5460 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5462 my_offset
= myh
->root
.u
.def
.value
;
5464 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5465 THUMB2ARM_GLUE_SECTION_NAME
);
5467 BFD_ASSERT (s
!= NULL
);
5468 BFD_ASSERT (s
->contents
!= NULL
);
5469 BFD_ASSERT (s
->output_section
!= NULL
);
5471 if ((my_offset
& 0x01) == 0x01)
5474 && sym_sec
->owner
!= NULL
5475 && !INTERWORK_FLAG (sym_sec
->owner
))
5477 (*_bfd_error_handler
)
5478 (_("%B(%s): warning: interworking not enabled.\n"
5479 " first occurrence: %B: thumb call to arm"),
5480 sym_sec
->owner
, input_bfd
, name
);
5486 myh
->root
.u
.def
.value
= my_offset
;
5488 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
5489 s
->contents
+ my_offset
);
5491 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
5492 s
->contents
+ my_offset
+ 2);
5495 /* Address of destination of the stub. */
5496 ((bfd_signed_vma
) val
)
5498 /* Offset from the start of the current section
5499 to the start of the stubs. */
5501 /* Offset of the start of this stub from the start of the stubs. */
5503 /* Address of the start of the current section. */
5504 + s
->output_section
->vma
)
5505 /* The branch instruction is 4 bytes into the stub. */
5507 /* ARM branches work from the pc of the instruction + 8. */
5510 put_arm_insn (globals
, output_bfd
,
5511 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
5512 s
->contents
+ my_offset
+ 4);
5515 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
5517 /* Now go back and fix up the original BL insn to point to here. */
5519 /* Address of where the stub is located. */
5520 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
5521 /* Address of where the BL is located. */
5522 - (input_section
->output_section
->vma
+ input_section
->output_offset
5524 /* Addend in the relocation. */
5526 /* Biassing for PC-relative addressing. */
5529 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
5534 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5536 static struct elf_link_hash_entry
*
5537 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
5544 char ** error_message
)
5547 long int ret_offset
;
5548 struct elf_link_hash_entry
* myh
;
5549 struct elf32_arm_link_hash_table
* globals
;
5551 myh
= find_arm_glue (info
, name
, error_message
);
5555 globals
= elf32_arm_hash_table (info
);
5557 BFD_ASSERT (globals
!= NULL
);
5558 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5560 my_offset
= myh
->root
.u
.def
.value
;
5562 if ((my_offset
& 0x01) == 0x01)
5565 && sym_sec
->owner
!= NULL
5566 && !INTERWORK_FLAG (sym_sec
->owner
))
5568 (*_bfd_error_handler
)
5569 (_("%B(%s): warning: interworking not enabled.\n"
5570 " first occurrence: %B: arm call to thumb"),
5571 sym_sec
->owner
, input_bfd
, name
);
5575 myh
->root
.u
.def
.value
= my_offset
;
5577 if (info
->shared
|| globals
->root
.is_relocatable_executable
5578 || globals
->pic_veneer
)
5580 /* For relocatable objects we can't use absolute addresses,
5581 so construct the address from a relative offset. */
5582 /* TODO: If the offset is small it's probably worth
5583 constructing the address with adds. */
5584 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
5585 s
->contents
+ my_offset
);
5586 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
5587 s
->contents
+ my_offset
+ 4);
5588 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
5589 s
->contents
+ my_offset
+ 8);
5590 /* Adjust the offset by 4 for the position of the add,
5591 and 8 for the pipeline offset. */
5592 ret_offset
= (val
- (s
->output_offset
5593 + s
->output_section
->vma
5596 bfd_put_32 (output_bfd
, ret_offset
,
5597 s
->contents
+ my_offset
+ 12);
5599 else if (globals
->use_blx
)
5601 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
5602 s
->contents
+ my_offset
);
5604 /* It's a thumb address. Add the low order bit. */
5605 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
5606 s
->contents
+ my_offset
+ 4);
5610 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
5611 s
->contents
+ my_offset
);
5613 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
5614 s
->contents
+ my_offset
+ 4);
5616 /* It's a thumb address. Add the low order bit. */
5617 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
5618 s
->contents
+ my_offset
+ 8);
5624 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
5629 /* Arm code calling a Thumb function. */
5632 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
5636 asection
* input_section
,
5637 bfd_byte
* hit_data
,
5640 bfd_signed_vma addend
,
5642 char **error_message
)
5644 unsigned long int tmp
;
5647 long int ret_offset
;
5648 struct elf_link_hash_entry
* myh
;
5649 struct elf32_arm_link_hash_table
* globals
;
5651 globals
= elf32_arm_hash_table (info
);
5653 BFD_ASSERT (globals
!= NULL
);
5654 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5656 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5657 ARM2THUMB_GLUE_SECTION_NAME
);
5658 BFD_ASSERT (s
!= NULL
);
5659 BFD_ASSERT (s
->contents
!= NULL
);
5660 BFD_ASSERT (s
->output_section
!= NULL
);
5662 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
5663 sym_sec
, val
, s
, error_message
);
5667 my_offset
= myh
->root
.u
.def
.value
;
5668 tmp
= bfd_get_32 (input_bfd
, hit_data
);
5669 tmp
= tmp
& 0xFF000000;
5671 /* Somehow these are both 4 too far, so subtract 8. */
5672 ret_offset
= (s
->output_offset
5674 + s
->output_section
->vma
5675 - (input_section
->output_offset
5676 + input_section
->output_section
->vma
5680 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
5682 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
5687 /* Populate Arm stub for an exported Thumb function. */
5690 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
5692 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
5694 struct elf_link_hash_entry
* myh
;
5695 struct elf32_arm_link_hash_entry
*eh
;
5696 struct elf32_arm_link_hash_table
* globals
;
5699 char *error_message
;
5701 eh
= elf32_arm_hash_entry (h
);
5702 /* Allocate stubs for exported Thumb functions on v4t. */
5703 if (eh
->export_glue
== NULL
)
5706 globals
= elf32_arm_hash_table (info
);
5708 BFD_ASSERT (globals
!= NULL
);
5709 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5711 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5712 ARM2THUMB_GLUE_SECTION_NAME
);
5713 BFD_ASSERT (s
!= NULL
);
5714 BFD_ASSERT (s
->contents
!= NULL
);
5715 BFD_ASSERT (s
->output_section
!= NULL
);
5717 sec
= eh
->export_glue
->root
.u
.def
.section
;
5719 BFD_ASSERT (sec
->output_section
!= NULL
);
5721 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
5722 + sec
->output_section
->vma
;
5724 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
5725 h
->root
.u
.def
.section
->owner
,
5726 globals
->obfd
, sec
, val
, s
,
5732 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5735 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
5740 struct elf32_arm_link_hash_table
*globals
;
5742 globals
= elf32_arm_hash_table (info
);
5744 BFD_ASSERT (globals
!= NULL
);
5745 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5747 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5748 ARM_BX_GLUE_SECTION_NAME
);
5749 BFD_ASSERT (s
!= NULL
);
5750 BFD_ASSERT (s
->contents
!= NULL
);
5751 BFD_ASSERT (s
->output_section
!= NULL
);
5753 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
5755 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
5757 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
5759 p
= s
->contents
+ glue_addr
;
5760 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
5761 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
5762 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
5763 globals
->bx_glue_offset
[reg
] |= 1;
5766 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
5769 /* Generate Arm stubs for exported Thumb symbols. */
5771 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5772 struct bfd_link_info
*link_info
)
5774 struct elf32_arm_link_hash_table
* globals
;
5776 if (link_info
== NULL
)
5777 /* Ignore this if we are not called by the ELF backend linker. */
5780 globals
= elf32_arm_hash_table (link_info
);
5781 /* If blx is available then exported Thumb symbols are OK and there is
5783 if (globals
->use_blx
)
5786 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
5790 /* Some relocations map to different relocations depending on the
5791 target. Return the real relocation. */
5794 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
5800 if (globals
->target1_is_rel
)
5806 return globals
->target2_reloc
;
5813 /* Return the base VMA address which should be subtracted from real addresses
5814 when resolving @dtpoff relocation.
5815 This is PT_TLS segment p_vaddr. */
5818 dtpoff_base (struct bfd_link_info
*info
)
5820 /* If tls_sec is NULL, we should have signalled an error already. */
5821 if (elf_hash_table (info
)->tls_sec
== NULL
)
5823 return elf_hash_table (info
)->tls_sec
->vma
;
5826 /* Return the relocation value for @tpoff relocation
5827 if STT_TLS virtual address is ADDRESS. */
5830 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
5832 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5835 /* If tls_sec is NULL, we should have signalled an error already. */
5836 if (htab
->tls_sec
== NULL
)
5838 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
5839 return address
- htab
->tls_sec
->vma
+ base
;
5842 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5843 VALUE is the relocation value. */
5845 static bfd_reloc_status_type
5846 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
5849 return bfd_reloc_overflow
;
5851 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
5852 bfd_put_32 (abfd
, value
, data
);
5853 return bfd_reloc_ok
;
5856 /* For a given value of n, calculate the value of G_n as required to
5857 deal with group relocations. We return it in the form of an
5858 encoded constant-and-rotation, together with the final residual. If n is
5859 specified as less than zero, then final_residual is filled with the
5860 input value and no further action is performed. */
5863 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
5867 bfd_vma encoded_g_n
= 0;
5868 bfd_vma residual
= value
; /* Also known as Y_n. */
5870 for (current_n
= 0; current_n
<= n
; current_n
++)
5874 /* Calculate which part of the value to mask. */
5881 /* Determine the most significant bit in the residual and
5882 align the resulting value to a 2-bit boundary. */
5883 for (msb
= 30; msb
>= 0; msb
-= 2)
5884 if (residual
& (3 << msb
))
5887 /* The desired shift is now (msb - 6), or zero, whichever
5894 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5895 g_n
= residual
& (0xff << shift
);
5896 encoded_g_n
= (g_n
>> shift
)
5897 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
5899 /* Calculate the residual for the next time around. */
5903 *final_residual
= residual
;
5908 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5909 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5912 identify_add_or_sub (bfd_vma insn
)
5914 int opcode
= insn
& 0x1e00000;
5916 if (opcode
== 1 << 23) /* ADD */
5919 if (opcode
== 1 << 22) /* SUB */
5925 /* Perform a relocation as part of a final link. */
5927 static bfd_reloc_status_type
5928 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
5931 asection
* input_section
,
5932 bfd_byte
* contents
,
5933 Elf_Internal_Rela
* rel
,
5935 struct bfd_link_info
* info
,
5937 const char * sym_name
,
5939 struct elf_link_hash_entry
* h
,
5940 bfd_boolean
* unresolved_reloc_p
,
5941 char ** error_message
)
5943 unsigned long r_type
= howto
->type
;
5944 unsigned long r_symndx
;
5945 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
5946 bfd
* dynobj
= NULL
;
5947 Elf_Internal_Shdr
* symtab_hdr
;
5948 struct elf_link_hash_entry
** sym_hashes
;
5949 bfd_vma
* local_got_offsets
;
5950 asection
* sgot
= NULL
;
5951 asection
* splt
= NULL
;
5952 asection
* sreloc
= NULL
;
5954 bfd_signed_vma signed_addend
;
5955 struct elf32_arm_link_hash_table
* globals
;
5957 globals
= elf32_arm_hash_table (info
);
5959 BFD_ASSERT (is_arm_elf (input_bfd
));
5961 /* Some relocation types map to different relocations depending on the
5962 target. We pick the right one here. */
5963 r_type
= arm_real_reloc_type (globals
, r_type
);
5964 if (r_type
!= howto
->type
)
5965 howto
= elf32_arm_howto_from_type (r_type
);
5967 /* If the start address has been set, then set the EF_ARM_HASENTRY
5968 flag. Setting this more than once is redundant, but the cost is
5969 not too high, and it keeps the code simple.
5971 The test is done here, rather than somewhere else, because the
5972 start address is only set just before the final link commences.
5974 Note - if the user deliberately sets a start address of 0, the
5975 flag will not be set. */
5976 if (bfd_get_start_address (output_bfd
) != 0)
5977 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
5979 dynobj
= elf_hash_table (info
)->dynobj
;
5982 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5983 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5985 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
5986 sym_hashes
= elf_sym_hashes (input_bfd
);
5987 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5988 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5990 if (globals
->use_rel
)
5992 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
5994 if (addend
& ((howto
->src_mask
+ 1) >> 1))
5997 signed_addend
&= ~ howto
->src_mask
;
5998 signed_addend
|= addend
;
6001 signed_addend
= addend
;
6004 addend
= signed_addend
= rel
->r_addend
;
6009 /* We don't need to find a value for this symbol. It's just a
6011 *unresolved_reloc_p
= FALSE
;
6012 return bfd_reloc_ok
;
6015 if (!globals
->vxworks_p
)
6016 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
6020 case R_ARM_ABS32_NOI
:
6022 case R_ARM_REL32_NOI
:
6028 /* Handle relocations which should use the PLT entry. ABS32/REL32
6029 will use the symbol's value, which may point to a PLT entry, but we
6030 don't need to handle that here. If we created a PLT entry, all
6031 branches in this object should go to it, except if the PLT is too
6032 far away, in which case a long branch stub should be inserted. */
6033 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
6034 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
6035 && r_type
!= R_ARM_CALL
6036 && r_type
!= R_ARM_JUMP24
6037 && r_type
!= R_ARM_PLT32
)
6040 && h
->plt
.offset
!= (bfd_vma
) -1)
6042 /* If we've created a .plt section, and assigned a PLT entry to
6043 this function, it should not be known to bind locally. If
6044 it were, we would have cleared the PLT entry. */
6045 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
6047 value
= (splt
->output_section
->vma
6048 + splt
->output_offset
6050 *unresolved_reloc_p
= FALSE
;
6051 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6052 contents
, rel
->r_offset
, value
,
6056 /* When generating a shared object or relocatable executable, these
6057 relocations are copied into the output file to be resolved at
6059 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
6060 && (input_section
->flags
& SEC_ALLOC
)
6061 && !(elf32_arm_hash_table (info
)->vxworks_p
6062 && strcmp (input_section
->output_section
->name
,
6064 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
6065 || !SYMBOL_CALLS_LOCAL (info
, h
))
6067 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6068 || h
->root
.type
!= bfd_link_hash_undefweak
)
6069 && r_type
!= R_ARM_PC24
6070 && r_type
!= R_ARM_CALL
6071 && r_type
!= R_ARM_JUMP24
6072 && r_type
!= R_ARM_PREL31
6073 && r_type
!= R_ARM_PLT32
)
6075 Elf_Internal_Rela outrel
;
6077 bfd_boolean skip
, relocate
;
6079 *unresolved_reloc_p
= FALSE
;
6083 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
6084 ! globals
->use_rel
);
6087 return bfd_reloc_notsupported
;
6093 outrel
.r_addend
= addend
;
6095 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6097 if (outrel
.r_offset
== (bfd_vma
) -1)
6099 else if (outrel
.r_offset
== (bfd_vma
) -2)
6100 skip
= TRUE
, relocate
= TRUE
;
6101 outrel
.r_offset
+= (input_section
->output_section
->vma
6102 + input_section
->output_offset
);
6105 memset (&outrel
, 0, sizeof outrel
);
6110 || !h
->def_regular
))
6111 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
6116 /* This symbol is local, or marked to become local. */
6117 if (sym_flags
== STT_ARM_TFUNC
)
6119 if (globals
->symbian_p
)
6123 /* On Symbian OS, the data segment and text segement
6124 can be relocated independently. Therefore, we
6125 must indicate the segment to which this
6126 relocation is relative. The BPABI allows us to
6127 use any symbol in the right segment; we just use
6128 the section symbol as it is convenient. (We
6129 cannot use the symbol given by "h" directly as it
6130 will not appear in the dynamic symbol table.)
6132 Note that the dynamic linker ignores the section
6133 symbol value, so we don't subtract osec->vma
6134 from the emitted reloc addend. */
6136 osec
= sym_sec
->output_section
;
6138 osec
= input_section
->output_section
;
6139 symbol
= elf_section_data (osec
)->dynindx
;
6142 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6144 if ((osec
->flags
& SEC_READONLY
) == 0
6145 && htab
->data_index_section
!= NULL
)
6146 osec
= htab
->data_index_section
;
6148 osec
= htab
->text_index_section
;
6149 symbol
= elf_section_data (osec
)->dynindx
;
6151 BFD_ASSERT (symbol
!= 0);
6154 /* On SVR4-ish systems, the dynamic loader cannot
6155 relocate the text and data segments independently,
6156 so the symbol does not matter. */
6158 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
6159 if (globals
->use_rel
)
6162 outrel
.r_addend
+= value
;
6165 loc
= sreloc
->contents
;
6166 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
6167 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6169 /* If this reloc is against an external symbol, we do not want to
6170 fiddle with the addend. Otherwise, we need to include the symbol
6171 value so that it becomes an addend for the dynamic reloc. */
6173 return bfd_reloc_ok
;
6175 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6176 contents
, rel
->r_offset
, value
,
6179 else switch (r_type
)
6182 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
6184 case R_ARM_XPC25
: /* Arm BLX instruction. */
6187 case R_ARM_PC24
: /* Arm B/BL instruction. */
6191 bfd_signed_vma branch_offset
;
6192 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
6194 if (r_type
== R_ARM_XPC25
)
6196 /* Check for Arm calling Arm function. */
6197 /* FIXME: Should we translate the instruction into a BL
6198 instruction instead ? */
6199 if (sym_flags
!= STT_ARM_TFUNC
)
6200 (*_bfd_error_handler
)
6201 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6203 h
? h
->root
.root
.string
: "(local)");
6205 else if (r_type
== R_ARM_PC24
)
6207 /* Check for Arm calling Thumb function. */
6208 if (sym_flags
== STT_ARM_TFUNC
)
6210 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
6211 output_bfd
, input_section
,
6212 hit_data
, sym_sec
, rel
->r_offset
,
6213 signed_addend
, value
,
6215 return bfd_reloc_ok
;
6217 return bfd_reloc_dangerous
;
6221 /* Check if a stub has to be inserted because the
6222 destination is too far or we are changing mode. */
6223 if ( r_type
== R_ARM_CALL
6224 || r_type
== R_ARM_JUMP24
6225 || r_type
== R_ARM_PLT32
)
6227 /* If the call goes through a PLT entry, make sure to
6228 check distance to the right destination address. */
6229 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6231 value
= (splt
->output_section
->vma
6232 + splt
->output_offset
6234 *unresolved_reloc_p
= FALSE
;
6237 from
= (input_section
->output_section
->vma
6238 + input_section
->output_offset
6240 branch_offset
= (bfd_signed_vma
)(value
- from
);
6242 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
6243 || branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
6244 || ((sym_flags
== STT_ARM_TFUNC
)
6245 && (((r_type
== R_ARM_CALL
) && !globals
->use_blx
)
6246 || (r_type
== R_ARM_JUMP24
)
6247 || (r_type
== R_ARM_PLT32
) ))
6250 /* The target is out of reach, so redirect the
6251 branch to the local stub for this function. */
6253 stub_entry
= elf32_arm_get_stub_entry (input_section
,
6256 if (stub_entry
!= NULL
)
6257 value
= (stub_entry
->stub_offset
6258 + stub_entry
->stub_sec
->output_offset
6259 + stub_entry
->stub_sec
->output_section
->vma
);
6263 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6265 S is the address of the symbol in the relocation.
6266 P is address of the instruction being relocated.
6267 A is the addend (extracted from the instruction) in bytes.
6269 S is held in 'value'.
6270 P is the base address of the section containing the
6271 instruction plus the offset of the reloc into that
6273 (input_section->output_section->vma +
6274 input_section->output_offset +
6276 A is the addend, converted into bytes, ie:
6279 Note: None of these operations have knowledge of the pipeline
6280 size of the processor, thus it is up to the assembler to
6281 encode this information into the addend. */
6282 value
-= (input_section
->output_section
->vma
6283 + input_section
->output_offset
);
6284 value
-= rel
->r_offset
;
6285 if (globals
->use_rel
)
6286 value
+= (signed_addend
<< howto
->size
);
6288 /* RELA addends do not have to be adjusted by howto->size. */
6289 value
+= signed_addend
;
6291 signed_addend
= value
;
6292 signed_addend
>>= howto
->rightshift
;
6294 /* A branch to an undefined weak symbol is turned into a jump to
6295 the next instruction unless a PLT entry will be created. */
6296 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
6297 && !(splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1))
6299 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000)
6304 /* Perform a signed range check. */
6305 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
6306 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
6307 return bfd_reloc_overflow
;
6309 addend
= (value
& 2);
6311 value
= (signed_addend
& howto
->dst_mask
)
6312 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
6314 if (r_type
== R_ARM_CALL
)
6316 /* Set the H bit in the BLX instruction. */
6317 if (sym_flags
== STT_ARM_TFUNC
)
6322 value
&= ~(bfd_vma
)(1 << 24);
6325 /* Select the correct instruction (BL or BLX). */
6326 /* Only if we are not handling a BL to a stub. In this
6327 case, mode switching is performed by the stub. */
6328 if (sym_flags
== STT_ARM_TFUNC
&& !stub_entry
)
6332 value
&= ~(bfd_vma
)(1 << 28);
6342 if (sym_flags
== STT_ARM_TFUNC
)
6346 case R_ARM_ABS32_NOI
:
6352 if (sym_flags
== STT_ARM_TFUNC
)
6354 value
-= (input_section
->output_section
->vma
6355 + input_section
->output_offset
+ rel
->r_offset
);
6358 case R_ARM_REL32_NOI
:
6360 value
-= (input_section
->output_section
->vma
6361 + input_section
->output_offset
+ rel
->r_offset
);
6365 value
-= (input_section
->output_section
->vma
6366 + input_section
->output_offset
+ rel
->r_offset
);
6367 value
+= signed_addend
;
6368 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
6370 /* Check for overflow. */
6371 if ((value
^ (value
>> 1)) & (1 << 30))
6372 return bfd_reloc_overflow
;
6374 value
&= 0x7fffffff;
6375 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
6376 if (sym_flags
== STT_ARM_TFUNC
)
6381 bfd_put_32 (input_bfd
, value
, hit_data
);
6382 return bfd_reloc_ok
;
6386 if ((long) value
> 0x7f || (long) value
< -0x80)
6387 return bfd_reloc_overflow
;
6389 bfd_put_8 (input_bfd
, value
, hit_data
);
6390 return bfd_reloc_ok
;
6395 if ((long) value
> 0x7fff || (long) value
< -0x8000)
6396 return bfd_reloc_overflow
;
6398 bfd_put_16 (input_bfd
, value
, hit_data
);
6399 return bfd_reloc_ok
;
6401 case R_ARM_THM_ABS5
:
6402 /* Support ldr and str instructions for the thumb. */
6403 if (globals
->use_rel
)
6405 /* Need to refetch addend. */
6406 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
6407 /* ??? Need to determine shift amount from operand size. */
6408 addend
>>= howto
->rightshift
;
6412 /* ??? Isn't value unsigned? */
6413 if ((long) value
> 0x1f || (long) value
< -0x10)
6414 return bfd_reloc_overflow
;
6416 /* ??? Value needs to be properly shifted into place first. */
6417 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
6418 bfd_put_16 (input_bfd
, value
, hit_data
);
6419 return bfd_reloc_ok
;
6421 case R_ARM_THM_ALU_PREL_11_0
:
6422 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6425 bfd_signed_vma relocation
;
6427 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
6428 | bfd_get_16 (input_bfd
, hit_data
+ 2);
6430 if (globals
->use_rel
)
6432 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
6433 | ((insn
& (1 << 26)) >> 15);
6434 if (insn
& 0xf00000)
6435 signed_addend
= -signed_addend
;
6438 relocation
= value
+ signed_addend
;
6439 relocation
-= (input_section
->output_section
->vma
6440 + input_section
->output_offset
6443 value
= abs (relocation
);
6445 if (value
>= 0x1000)
6446 return bfd_reloc_overflow
;
6448 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
6449 | ((value
& 0x700) << 4)
6450 | ((value
& 0x800) << 15);
6454 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
6455 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
6457 return bfd_reloc_ok
;
6460 case R_ARM_THM_PC12
:
6461 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6464 bfd_signed_vma relocation
;
6466 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
6467 | bfd_get_16 (input_bfd
, hit_data
+ 2);
6469 if (globals
->use_rel
)
6471 signed_addend
= insn
& 0xfff;
6472 if (!(insn
& (1 << 23)))
6473 signed_addend
= -signed_addend
;
6476 relocation
= value
+ signed_addend
;
6477 relocation
-= (input_section
->output_section
->vma
6478 + input_section
->output_offset
6481 value
= abs (relocation
);
6483 if (value
>= 0x1000)
6484 return bfd_reloc_overflow
;
6486 insn
= (insn
& 0xff7ff000) | value
;
6487 if (relocation
>= 0)
6490 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
6491 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
6493 return bfd_reloc_ok
;
6496 case R_ARM_THM_XPC22
:
6497 case R_ARM_THM_CALL
:
6498 case R_ARM_THM_JUMP24
:
6499 /* Thumb BL (branch long instruction). */
6503 bfd_boolean overflow
= FALSE
;
6504 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
6505 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
6506 bfd_signed_vma reloc_signed_max
;
6507 bfd_signed_vma reloc_signed_min
;
6509 bfd_signed_vma signed_check
;
6511 int thumb2
= using_thumb2 (globals
);
6513 /* A branch to an undefined weak symbol is turned into a jump to
6514 the next instruction unless a PLT entry will be created. */
6515 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
6516 && !(splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1))
6518 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
6519 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
6520 return bfd_reloc_ok
;
6523 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6524 with Thumb-1) involving the J1 and J2 bits. */
6525 if (globals
->use_rel
)
6527 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
6528 bfd_vma upper
= upper_insn
& 0x3ff;
6529 bfd_vma lower
= lower_insn
& 0x7ff;
6530 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
6531 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
6532 bfd_vma i1
= j1
^ s
? 0 : 1;
6533 bfd_vma i2
= j2
^ s
? 0 : 1;
6535 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
6537 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
6539 signed_addend
= addend
;
6542 if (r_type
== R_ARM_THM_XPC22
)
6544 /* Check for Thumb to Thumb call. */
6545 /* FIXME: Should we translate the instruction into a BL
6546 instruction instead ? */
6547 if (sym_flags
== STT_ARM_TFUNC
)
6548 (*_bfd_error_handler
)
6549 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6551 h
? h
->root
.root
.string
: "(local)");
6555 /* If it is not a call to Thumb, assume call to Arm.
6556 If it is a call relative to a section name, then it is not a
6557 function call at all, but rather a long jump. Calls through
6558 the PLT do not require stubs. */
6559 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
6560 && (h
== NULL
|| splt
== NULL
6561 || h
->plt
.offset
== (bfd_vma
) -1))
6563 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
6565 /* Convert BL to BLX. */
6566 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6568 else if (( r_type
!= R_ARM_THM_CALL
)
6569 && (r_type
!= R_ARM_THM_JUMP24
))
6571 if (elf32_thumb_to_arm_stub
6572 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
6573 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
6575 return bfd_reloc_ok
;
6577 return bfd_reloc_dangerous
;
6580 else if (sym_flags
== STT_ARM_TFUNC
&& globals
->use_blx
6581 && r_type
== R_ARM_THM_CALL
)
6583 /* Make sure this is a BL. */
6584 lower_insn
|= 0x1800;
6588 /* Handle calls via the PLT. */
6589 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6591 value
= (splt
->output_section
->vma
6592 + splt
->output_offset
6594 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
6596 /* If the Thumb BLX instruction is available, convert the
6597 BL to a BLX instruction to call the ARM-mode PLT entry. */
6598 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6601 /* Target the Thumb stub before the ARM PLT entry. */
6602 value
-= PLT_THUMB_STUB_SIZE
;
6603 *unresolved_reloc_p
= FALSE
;
6606 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
6608 /* Check if a stub has to be inserted because the destination
6611 bfd_signed_vma branch_offset
;
6612 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
6614 from
= (input_section
->output_section
->vma
6615 + input_section
->output_offset
6617 branch_offset
= (bfd_signed_vma
)(value
- from
);
6620 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
6621 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
6624 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
6625 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
6626 || ((sym_flags
!= STT_ARM_TFUNC
)
6627 && (((r_type
== R_ARM_THM_CALL
) && !globals
->use_blx
)
6628 || r_type
== R_ARM_THM_JUMP24
)))
6630 /* The target is out of reach or we are changing modes, so
6631 redirect the branch to the local stub for this
6633 stub_entry
= elf32_arm_get_stub_entry (input_section
,
6636 if (stub_entry
!= NULL
)
6637 value
= (stub_entry
->stub_offset
6638 + stub_entry
->stub_sec
->output_offset
6639 + stub_entry
->stub_sec
->output_section
->vma
);
6641 /* If this call becomes a call to Arm, force BLX. */
6642 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
6645 && !arm_stub_is_thumb (stub_entry
->stub_type
))
6646 || (sym_flags
!= STT_ARM_TFUNC
))
6647 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6652 relocation
= value
+ signed_addend
;
6654 relocation
-= (input_section
->output_section
->vma
6655 + input_section
->output_offset
6658 check
= relocation
>> howto
->rightshift
;
6660 /* If this is a signed value, the rightshift just dropped
6661 leading 1 bits (assuming twos complement). */
6662 if ((bfd_signed_vma
) relocation
>= 0)
6663 signed_check
= check
;
6665 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
6667 /* Calculate the permissable maximum and minimum values for
6668 this relocation according to whether we're relocating for
6670 bitsize
= howto
->bitsize
;
6673 reloc_signed_max
= ((1 << (bitsize
- 1)) - 1) >> howto
->rightshift
;
6674 reloc_signed_min
= ~reloc_signed_max
;
6676 /* Assumes two's complement. */
6677 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6680 if ((lower_insn
& 0x5000) == 0x4000)
6681 /* For a BLX instruction, make sure that the relocation is rounded up
6682 to a word boundary. This follows the semantics of the instruction
6683 which specifies that bit 1 of the target address will come from bit
6684 1 of the base address. */
6685 relocation
= (relocation
+ 2) & ~ 3;
6687 /* Put RELOCATION back into the insn. Assumes two's complement.
6688 We use the Thumb-2 encoding, which is safe even if dealing with
6689 a Thumb-1 instruction by virtue of our overflow check above. */
6690 reloc_sign
= (signed_check
< 0) ? 1 : 0;
6691 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
6692 | ((relocation
>> 12) & 0x3ff)
6693 | (reloc_sign
<< 10);
6694 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
6695 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
6696 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
6697 | ((relocation
>> 1) & 0x7ff);
6699 /* Put the relocated value back in the object file: */
6700 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
6701 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
6703 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
6707 case R_ARM_THM_JUMP19
:
6708 /* Thumb32 conditional branch instruction. */
6711 bfd_boolean overflow
= FALSE
;
6712 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
6713 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
6714 bfd_signed_vma reloc_signed_max
= 0xffffe;
6715 bfd_signed_vma reloc_signed_min
= -0x100000;
6716 bfd_signed_vma signed_check
;
6718 /* Need to refetch the addend, reconstruct the top three bits,
6719 and squish the two 11 bit pieces together. */
6720 if (globals
->use_rel
)
6722 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
6723 bfd_vma upper
= (upper_insn
& 0x003f);
6724 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
6725 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
6726 bfd_vma lower
= (lower_insn
& 0x07ff);
6731 upper
-= 0x0100; /* Sign extend. */
6733 addend
= (upper
<< 12) | (lower
<< 1);
6734 signed_addend
= addend
;
6737 /* Handle calls via the PLT. */
6738 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6740 value
= (splt
->output_section
->vma
6741 + splt
->output_offset
6743 /* Target the Thumb stub before the ARM PLT entry. */
6744 value
-= PLT_THUMB_STUB_SIZE
;
6745 *unresolved_reloc_p
= FALSE
;
6748 /* ??? Should handle interworking? GCC might someday try to
6749 use this for tail calls. */
6751 relocation
= value
+ signed_addend
;
6752 relocation
-= (input_section
->output_section
->vma
6753 + input_section
->output_offset
6755 signed_check
= (bfd_signed_vma
) relocation
;
6757 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6760 /* Put RELOCATION back into the insn. */
6762 bfd_vma S
= (relocation
& 0x00100000) >> 20;
6763 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
6764 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
6765 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
6766 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
6768 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
6769 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
6772 /* Put the relocated value back in the object file: */
6773 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
6774 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
6776 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
6779 case R_ARM_THM_JUMP11
:
6780 case R_ARM_THM_JUMP8
:
6781 case R_ARM_THM_JUMP6
:
6782 /* Thumb B (branch) instruction). */
6784 bfd_signed_vma relocation
;
6785 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
6786 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
6787 bfd_signed_vma signed_check
;
6789 /* CZB cannot jump backward. */
6790 if (r_type
== R_ARM_THM_JUMP6
)
6791 reloc_signed_min
= 0;
6793 if (globals
->use_rel
)
6795 /* Need to refetch addend. */
6796 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
6797 if (addend
& ((howto
->src_mask
+ 1) >> 1))
6800 signed_addend
&= ~ howto
->src_mask
;
6801 signed_addend
|= addend
;
6804 signed_addend
= addend
;
6805 /* The value in the insn has been right shifted. We need to
6806 undo this, so that we can perform the address calculation
6807 in terms of bytes. */
6808 signed_addend
<<= howto
->rightshift
;
6810 relocation
= value
+ signed_addend
;
6812 relocation
-= (input_section
->output_section
->vma
6813 + input_section
->output_offset
6816 relocation
>>= howto
->rightshift
;
6817 signed_check
= relocation
;
6819 if (r_type
== R_ARM_THM_JUMP6
)
6820 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
6822 relocation
&= howto
->dst_mask
;
6823 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
6825 bfd_put_16 (input_bfd
, relocation
, hit_data
);
6827 /* Assumes two's complement. */
6828 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6829 return bfd_reloc_overflow
;
6831 return bfd_reloc_ok
;
6834 case R_ARM_ALU_PCREL7_0
:
6835 case R_ARM_ALU_PCREL15_8
:
6836 case R_ARM_ALU_PCREL23_15
:
6841 insn
= bfd_get_32 (input_bfd
, hit_data
);
6842 if (globals
->use_rel
)
6844 /* Extract the addend. */
6845 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
6846 signed_addend
= addend
;
6848 relocation
= value
+ signed_addend
;
6850 relocation
-= (input_section
->output_section
->vma
6851 + input_section
->output_offset
6853 insn
= (insn
& ~0xfff)
6854 | ((howto
->bitpos
<< 7) & 0xf00)
6855 | ((relocation
>> howto
->bitpos
) & 0xff);
6856 bfd_put_32 (input_bfd
, value
, hit_data
);
6858 return bfd_reloc_ok
;
6860 case R_ARM_GNU_VTINHERIT
:
6861 case R_ARM_GNU_VTENTRY
:
6862 return bfd_reloc_ok
;
6864 case R_ARM_GOTOFF32
:
6865 /* Relocation is relative to the start of the
6866 global offset table. */
6868 BFD_ASSERT (sgot
!= NULL
);
6870 return bfd_reloc_notsupported
;
6872 /* If we are addressing a Thumb function, we need to adjust the
6873 address by one, so that attempts to call the function pointer will
6874 correctly interpret it as Thumb code. */
6875 if (sym_flags
== STT_ARM_TFUNC
)
6878 /* Note that sgot->output_offset is not involved in this
6879 calculation. We always want the start of .got. If we
6880 define _GLOBAL_OFFSET_TABLE in a different way, as is
6881 permitted by the ABI, we might have to change this
6883 value
-= sgot
->output_section
->vma
;
6884 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6885 contents
, rel
->r_offset
, value
,
6889 /* Use global offset table as symbol value. */
6890 BFD_ASSERT (sgot
!= NULL
);
6893 return bfd_reloc_notsupported
;
6895 *unresolved_reloc_p
= FALSE
;
6896 value
= sgot
->output_section
->vma
;
6897 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6898 contents
, rel
->r_offset
, value
,
6902 case R_ARM_GOT_PREL
:
6903 /* Relocation is to the entry for this symbol in the
6904 global offset table. */
6906 return bfd_reloc_notsupported
;
6913 off
= h
->got
.offset
;
6914 BFD_ASSERT (off
!= (bfd_vma
) -1);
6915 dyn
= globals
->root
.dynamic_sections_created
;
6917 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
6919 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6920 || (ELF_ST_VISIBILITY (h
->other
)
6921 && h
->root
.type
== bfd_link_hash_undefweak
))
6923 /* This is actually a static link, or it is a -Bsymbolic link
6924 and the symbol is defined locally. We must initialize this
6925 entry in the global offset table. Since the offset must
6926 always be a multiple of 4, we use the least significant bit
6927 to record whether we have initialized it already.
6929 When doing a dynamic link, we create a .rel(a).got relocation
6930 entry to initialize the value. This is done in the
6931 finish_dynamic_symbol routine. */
6936 /* If we are addressing a Thumb function, we need to
6937 adjust the address by one, so that attempts to
6938 call the function pointer will correctly
6939 interpret it as Thumb code. */
6940 if (sym_flags
== STT_ARM_TFUNC
)
6943 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
6948 *unresolved_reloc_p
= FALSE
;
6950 value
= sgot
->output_offset
+ off
;
6956 BFD_ASSERT (local_got_offsets
!= NULL
&&
6957 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
6959 off
= local_got_offsets
[r_symndx
];
6961 /* The offset must always be a multiple of 4. We use the
6962 least significant bit to record whether we have already
6963 generated the necessary reloc. */
6968 /* If we are addressing a Thumb function, we need to
6969 adjust the address by one, so that attempts to
6970 call the function pointer will correctly
6971 interpret it as Thumb code. */
6972 if (sym_flags
== STT_ARM_TFUNC
)
6975 if (globals
->use_rel
)
6976 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
6981 Elf_Internal_Rela outrel
;
6984 srelgot
= (bfd_get_section_by_name
6985 (dynobj
, RELOC_SECTION (globals
, ".got")));
6986 BFD_ASSERT (srelgot
!= NULL
);
6988 outrel
.r_addend
= addend
+ value
;
6989 outrel
.r_offset
= (sgot
->output_section
->vma
6990 + sgot
->output_offset
6992 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
6993 loc
= srelgot
->contents
;
6994 loc
+= srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
6995 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6998 local_got_offsets
[r_symndx
] |= 1;
7001 value
= sgot
->output_offset
+ off
;
7003 if (r_type
!= R_ARM_GOT32
)
7004 value
+= sgot
->output_section
->vma
;
7006 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7007 contents
, rel
->r_offset
, value
,
7010 case R_ARM_TLS_LDO32
:
7011 value
= value
- dtpoff_base (info
);
7013 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7014 contents
, rel
->r_offset
, value
,
7017 case R_ARM_TLS_LDM32
:
7021 if (globals
->sgot
== NULL
)
7024 off
= globals
->tls_ldm_got
.offset
;
7030 /* If we don't know the module number, create a relocation
7034 Elf_Internal_Rela outrel
;
7037 if (globals
->srelgot
== NULL
)
7040 outrel
.r_addend
= 0;
7041 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7042 + globals
->sgot
->output_offset
+ off
);
7043 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
7045 if (globals
->use_rel
)
7046 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7047 globals
->sgot
->contents
+ off
);
7049 loc
= globals
->srelgot
->contents
;
7050 loc
+= globals
->srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
7051 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7054 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
7056 globals
->tls_ldm_got
.offset
|= 1;
7059 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
7060 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
7062 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7063 contents
, rel
->r_offset
, value
,
7067 case R_ARM_TLS_GD32
:
7068 case R_ARM_TLS_IE32
:
7074 if (globals
->sgot
== NULL
)
7081 dyn
= globals
->root
.dynamic_sections_created
;
7082 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7084 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
7086 *unresolved_reloc_p
= FALSE
;
7089 off
= h
->got
.offset
;
7090 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
7094 if (local_got_offsets
== NULL
)
7096 off
= local_got_offsets
[r_symndx
];
7097 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
7100 if (tls_type
== GOT_UNKNOWN
)
7107 bfd_boolean need_relocs
= FALSE
;
7108 Elf_Internal_Rela outrel
;
7109 bfd_byte
*loc
= NULL
;
7112 /* The GOT entries have not been initialized yet. Do it
7113 now, and emit any relocations. If both an IE GOT and a
7114 GD GOT are necessary, we emit the GD first. */
7116 if ((info
->shared
|| indx
!= 0)
7118 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7119 || h
->root
.type
!= bfd_link_hash_undefweak
))
7122 if (globals
->srelgot
== NULL
)
7124 loc
= globals
->srelgot
->contents
;
7125 loc
+= globals
->srelgot
->reloc_count
* RELOC_SIZE (globals
);
7128 if (tls_type
& GOT_TLS_GD
)
7132 outrel
.r_addend
= 0;
7133 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7134 + globals
->sgot
->output_offset
7136 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
7138 if (globals
->use_rel
)
7139 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7140 globals
->sgot
->contents
+ cur_off
);
7142 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7143 globals
->srelgot
->reloc_count
++;
7144 loc
+= RELOC_SIZE (globals
);
7147 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
7148 globals
->sgot
->contents
+ cur_off
+ 4);
7151 outrel
.r_addend
= 0;
7152 outrel
.r_info
= ELF32_R_INFO (indx
,
7153 R_ARM_TLS_DTPOFF32
);
7154 outrel
.r_offset
+= 4;
7156 if (globals
->use_rel
)
7157 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7158 globals
->sgot
->contents
+ cur_off
+ 4);
7161 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7162 globals
->srelgot
->reloc_count
++;
7163 loc
+= RELOC_SIZE (globals
);
7168 /* If we are not emitting relocations for a
7169 general dynamic reference, then we must be in a
7170 static link or an executable link with the
7171 symbol binding locally. Mark it as belonging
7172 to module 1, the executable. */
7173 bfd_put_32 (output_bfd
, 1,
7174 globals
->sgot
->contents
+ cur_off
);
7175 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
7176 globals
->sgot
->contents
+ cur_off
+ 4);
7182 if (tls_type
& GOT_TLS_IE
)
7187 outrel
.r_addend
= value
- dtpoff_base (info
);
7189 outrel
.r_addend
= 0;
7190 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7191 + globals
->sgot
->output_offset
7193 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
7195 if (globals
->use_rel
)
7196 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7197 globals
->sgot
->contents
+ cur_off
);
7199 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7200 globals
->srelgot
->reloc_count
++;
7201 loc
+= RELOC_SIZE (globals
);
7204 bfd_put_32 (output_bfd
, tpoff (info
, value
),
7205 globals
->sgot
->contents
+ cur_off
);
7212 local_got_offsets
[r_symndx
] |= 1;
7215 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
7217 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
7218 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
7220 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7221 contents
, rel
->r_offset
, value
,
7225 case R_ARM_TLS_LE32
:
7228 (*_bfd_error_handler
)
7229 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7230 input_bfd
, input_section
,
7231 (long) rel
->r_offset
, howto
->name
);
7235 value
= tpoff (info
, value
);
7237 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7238 contents
, rel
->r_offset
, value
,
7242 if (globals
->fix_v4bx
)
7244 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7246 /* Ensure that we have a BX instruction. */
7247 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
7249 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
7251 /* Branch to veneer. */
7253 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
7254 glue_addr
-= input_section
->output_section
->vma
7255 + input_section
->output_offset
7256 + rel
->r_offset
+ 8;
7257 insn
= (insn
& 0xf0000000) | 0x0a000000
7258 | ((glue_addr
>> 2) & 0x00ffffff);
7262 /* Preserve Rm (lowest four bits) and the condition code
7263 (highest four bits). Other bits encode MOV PC,Rm. */
7264 insn
= (insn
& 0xf000000f) | 0x01a0f000;
7267 bfd_put_32 (input_bfd
, insn
, hit_data
);
7269 return bfd_reloc_ok
;
7271 case R_ARM_MOVW_ABS_NC
:
7272 case R_ARM_MOVT_ABS
:
7273 case R_ARM_MOVW_PREL_NC
:
7274 case R_ARM_MOVT_PREL
:
7275 /* Until we properly support segment-base-relative addressing then
7276 we assume the segment base to be zero, as for the group relocations.
7277 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7278 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7279 case R_ARM_MOVW_BREL_NC
:
7280 case R_ARM_MOVW_BREL
:
7281 case R_ARM_MOVT_BREL
:
7283 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7285 if (globals
->use_rel
)
7287 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
7288 signed_addend
= (addend
^ 0x8000) - 0x8000;
7291 value
+= signed_addend
;
7293 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
7294 value
-= (input_section
->output_section
->vma
7295 + input_section
->output_offset
+ rel
->r_offset
);
7297 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
7298 return bfd_reloc_overflow
;
7300 if (sym_flags
== STT_ARM_TFUNC
)
7303 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
7304 || r_type
== R_ARM_MOVT_BREL
)
7308 insn
|= value
& 0xfff;
7309 insn
|= (value
& 0xf000) << 4;
7310 bfd_put_32 (input_bfd
, insn
, hit_data
);
7312 return bfd_reloc_ok
;
7314 case R_ARM_THM_MOVW_ABS_NC
:
7315 case R_ARM_THM_MOVT_ABS
:
7316 case R_ARM_THM_MOVW_PREL_NC
:
7317 case R_ARM_THM_MOVT_PREL
:
7318 /* Until we properly support segment-base-relative addressing then
7319 we assume the segment base to be zero, as for the above relocations.
7320 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7321 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7322 as R_ARM_THM_MOVT_ABS. */
7323 case R_ARM_THM_MOVW_BREL_NC
:
7324 case R_ARM_THM_MOVW_BREL
:
7325 case R_ARM_THM_MOVT_BREL
:
7329 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
7330 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
7332 if (globals
->use_rel
)
7334 addend
= ((insn
>> 4) & 0xf000)
7335 | ((insn
>> 15) & 0x0800)
7336 | ((insn
>> 4) & 0x0700)
7338 signed_addend
= (addend
^ 0x8000) - 0x8000;
7341 value
+= signed_addend
;
7343 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
7344 value
-= (input_section
->output_section
->vma
7345 + input_section
->output_offset
+ rel
->r_offset
);
7347 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
7348 return bfd_reloc_overflow
;
7350 if (sym_flags
== STT_ARM_TFUNC
)
7353 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
7354 || r_type
== R_ARM_THM_MOVT_BREL
)
7358 insn
|= (value
& 0xf000) << 4;
7359 insn
|= (value
& 0x0800) << 15;
7360 insn
|= (value
& 0x0700) << 4;
7361 insn
|= (value
& 0x00ff);
7363 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
7364 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
7366 return bfd_reloc_ok
;
7368 case R_ARM_ALU_PC_G0_NC
:
7369 case R_ARM_ALU_PC_G1_NC
:
7370 case R_ARM_ALU_PC_G0
:
7371 case R_ARM_ALU_PC_G1
:
7372 case R_ARM_ALU_PC_G2
:
7373 case R_ARM_ALU_SB_G0_NC
:
7374 case R_ARM_ALU_SB_G1_NC
:
7375 case R_ARM_ALU_SB_G0
:
7376 case R_ARM_ALU_SB_G1
:
7377 case R_ARM_ALU_SB_G2
:
7379 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7380 bfd_vma pc
= input_section
->output_section
->vma
7381 + input_section
->output_offset
+ rel
->r_offset
;
7382 /* sb should be the origin of the *segment* containing the symbol.
7383 It is not clear how to obtain this OS-dependent value, so we
7384 make an arbitrary choice of zero. */
7388 bfd_signed_vma signed_value
;
7391 /* Determine which group of bits to select. */
7394 case R_ARM_ALU_PC_G0_NC
:
7395 case R_ARM_ALU_PC_G0
:
7396 case R_ARM_ALU_SB_G0_NC
:
7397 case R_ARM_ALU_SB_G0
:
7401 case R_ARM_ALU_PC_G1_NC
:
7402 case R_ARM_ALU_PC_G1
:
7403 case R_ARM_ALU_SB_G1_NC
:
7404 case R_ARM_ALU_SB_G1
:
7408 case R_ARM_ALU_PC_G2
:
7409 case R_ARM_ALU_SB_G2
:
7417 /* If REL, extract the addend from the insn. If RELA, it will
7418 have already been fetched for us. */
7419 if (globals
->use_rel
)
7422 bfd_vma constant
= insn
& 0xff;
7423 bfd_vma rotation
= (insn
& 0xf00) >> 8;
7426 signed_addend
= constant
;
7429 /* Compensate for the fact that in the instruction, the
7430 rotation is stored in multiples of 2 bits. */
7433 /* Rotate "constant" right by "rotation" bits. */
7434 signed_addend
= (constant
>> rotation
) |
7435 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
7438 /* Determine if the instruction is an ADD or a SUB.
7439 (For REL, this determines the sign of the addend.) */
7440 negative
= identify_add_or_sub (insn
);
7443 (*_bfd_error_handler
)
7444 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7445 input_bfd
, input_section
,
7446 (long) rel
->r_offset
, howto
->name
);
7447 return bfd_reloc_overflow
;
7450 signed_addend
*= negative
;
7453 /* Compute the value (X) to go in the place. */
7454 if (r_type
== R_ARM_ALU_PC_G0_NC
7455 || r_type
== R_ARM_ALU_PC_G1_NC
7456 || r_type
== R_ARM_ALU_PC_G0
7457 || r_type
== R_ARM_ALU_PC_G1
7458 || r_type
== R_ARM_ALU_PC_G2
)
7460 signed_value
= value
- pc
+ signed_addend
;
7462 /* Section base relative. */
7463 signed_value
= value
- sb
+ signed_addend
;
7465 /* If the target symbol is a Thumb function, then set the
7466 Thumb bit in the address. */
7467 if (sym_flags
== STT_ARM_TFUNC
)
7470 /* Calculate the value of the relevant G_n, in encoded
7471 constant-with-rotation format. */
7472 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
7475 /* Check for overflow if required. */
7476 if ((r_type
== R_ARM_ALU_PC_G0
7477 || r_type
== R_ARM_ALU_PC_G1
7478 || r_type
== R_ARM_ALU_PC_G2
7479 || r_type
== R_ARM_ALU_SB_G0
7480 || r_type
== R_ARM_ALU_SB_G1
7481 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
7483 (*_bfd_error_handler
)
7484 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7485 input_bfd
, input_section
,
7486 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7487 return bfd_reloc_overflow
;
7490 /* Mask out the value and the ADD/SUB part of the opcode; take care
7491 not to destroy the S bit. */
7494 /* Set the opcode according to whether the value to go in the
7495 place is negative. */
7496 if (signed_value
< 0)
7501 /* Encode the offset. */
7504 bfd_put_32 (input_bfd
, insn
, hit_data
);
7506 return bfd_reloc_ok
;
7508 case R_ARM_LDR_PC_G0
:
7509 case R_ARM_LDR_PC_G1
:
7510 case R_ARM_LDR_PC_G2
:
7511 case R_ARM_LDR_SB_G0
:
7512 case R_ARM_LDR_SB_G1
:
7513 case R_ARM_LDR_SB_G2
:
7515 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7516 bfd_vma pc
= input_section
->output_section
->vma
7517 + input_section
->output_offset
+ rel
->r_offset
;
7518 bfd_vma sb
= 0; /* See note above. */
7520 bfd_signed_vma signed_value
;
7523 /* Determine which groups of bits to calculate. */
7526 case R_ARM_LDR_PC_G0
:
7527 case R_ARM_LDR_SB_G0
:
7531 case R_ARM_LDR_PC_G1
:
7532 case R_ARM_LDR_SB_G1
:
7536 case R_ARM_LDR_PC_G2
:
7537 case R_ARM_LDR_SB_G2
:
7545 /* If REL, extract the addend from the insn. If RELA, it will
7546 have already been fetched for us. */
7547 if (globals
->use_rel
)
7549 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7550 signed_addend
= negative
* (insn
& 0xfff);
7553 /* Compute the value (X) to go in the place. */
7554 if (r_type
== R_ARM_LDR_PC_G0
7555 || r_type
== R_ARM_LDR_PC_G1
7556 || r_type
== R_ARM_LDR_PC_G2
)
7558 signed_value
= value
- pc
+ signed_addend
;
7560 /* Section base relative. */
7561 signed_value
= value
- sb
+ signed_addend
;
7563 /* Calculate the value of the relevant G_{n-1} to obtain
7564 the residual at that stage. */
7565 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7567 /* Check for overflow. */
7568 if (residual
>= 0x1000)
7570 (*_bfd_error_handler
)
7571 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7572 input_bfd
, input_section
,
7573 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7574 return bfd_reloc_overflow
;
7577 /* Mask out the value and U bit. */
7580 /* Set the U bit if the value to go in the place is non-negative. */
7581 if (signed_value
>= 0)
7584 /* Encode the offset. */
7587 bfd_put_32 (input_bfd
, insn
, hit_data
);
7589 return bfd_reloc_ok
;
7591 case R_ARM_LDRS_PC_G0
:
7592 case R_ARM_LDRS_PC_G1
:
7593 case R_ARM_LDRS_PC_G2
:
7594 case R_ARM_LDRS_SB_G0
:
7595 case R_ARM_LDRS_SB_G1
:
7596 case R_ARM_LDRS_SB_G2
:
7598 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7599 bfd_vma pc
= input_section
->output_section
->vma
7600 + input_section
->output_offset
+ rel
->r_offset
;
7601 bfd_vma sb
= 0; /* See note above. */
7603 bfd_signed_vma signed_value
;
7606 /* Determine which groups of bits to calculate. */
7609 case R_ARM_LDRS_PC_G0
:
7610 case R_ARM_LDRS_SB_G0
:
7614 case R_ARM_LDRS_PC_G1
:
7615 case R_ARM_LDRS_SB_G1
:
7619 case R_ARM_LDRS_PC_G2
:
7620 case R_ARM_LDRS_SB_G2
:
7628 /* If REL, extract the addend from the insn. If RELA, it will
7629 have already been fetched for us. */
7630 if (globals
->use_rel
)
7632 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7633 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
7636 /* Compute the value (X) to go in the place. */
7637 if (r_type
== R_ARM_LDRS_PC_G0
7638 || r_type
== R_ARM_LDRS_PC_G1
7639 || r_type
== R_ARM_LDRS_PC_G2
)
7641 signed_value
= value
- pc
+ signed_addend
;
7643 /* Section base relative. */
7644 signed_value
= value
- sb
+ signed_addend
;
7646 /* Calculate the value of the relevant G_{n-1} to obtain
7647 the residual at that stage. */
7648 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7650 /* Check for overflow. */
7651 if (residual
>= 0x100)
7653 (*_bfd_error_handler
)
7654 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7655 input_bfd
, input_section
,
7656 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7657 return bfd_reloc_overflow
;
7660 /* Mask out the value and U bit. */
7663 /* Set the U bit if the value to go in the place is non-negative. */
7664 if (signed_value
>= 0)
7667 /* Encode the offset. */
7668 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
7670 bfd_put_32 (input_bfd
, insn
, hit_data
);
7672 return bfd_reloc_ok
;
7674 case R_ARM_LDC_PC_G0
:
7675 case R_ARM_LDC_PC_G1
:
7676 case R_ARM_LDC_PC_G2
:
7677 case R_ARM_LDC_SB_G0
:
7678 case R_ARM_LDC_SB_G1
:
7679 case R_ARM_LDC_SB_G2
:
7681 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7682 bfd_vma pc
= input_section
->output_section
->vma
7683 + input_section
->output_offset
+ rel
->r_offset
;
7684 bfd_vma sb
= 0; /* See note above. */
7686 bfd_signed_vma signed_value
;
7689 /* Determine which groups of bits to calculate. */
7692 case R_ARM_LDC_PC_G0
:
7693 case R_ARM_LDC_SB_G0
:
7697 case R_ARM_LDC_PC_G1
:
7698 case R_ARM_LDC_SB_G1
:
7702 case R_ARM_LDC_PC_G2
:
7703 case R_ARM_LDC_SB_G2
:
7711 /* If REL, extract the addend from the insn. If RELA, it will
7712 have already been fetched for us. */
7713 if (globals
->use_rel
)
7715 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7716 signed_addend
= negative
* ((insn
& 0xff) << 2);
7719 /* Compute the value (X) to go in the place. */
7720 if (r_type
== R_ARM_LDC_PC_G0
7721 || r_type
== R_ARM_LDC_PC_G1
7722 || r_type
== R_ARM_LDC_PC_G2
)
7724 signed_value
= value
- pc
+ signed_addend
;
7726 /* Section base relative. */
7727 signed_value
= value
- sb
+ signed_addend
;
7729 /* Calculate the value of the relevant G_{n-1} to obtain
7730 the residual at that stage. */
7731 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7733 /* Check for overflow. (The absolute value to go in the place must be
7734 divisible by four and, after having been divided by four, must
7735 fit in eight bits.) */
7736 if ((residual
& 0x3) != 0 || residual
>= 0x400)
7738 (*_bfd_error_handler
)
7739 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7740 input_bfd
, input_section
,
7741 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7742 return bfd_reloc_overflow
;
7745 /* Mask out the value and U bit. */
7748 /* Set the U bit if the value to go in the place is non-negative. */
7749 if (signed_value
>= 0)
7752 /* Encode the offset. */
7753 insn
|= residual
>> 2;
7755 bfd_put_32 (input_bfd
, insn
, hit_data
);
7757 return bfd_reloc_ok
;
7760 return bfd_reloc_notsupported
;
7764 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7766 arm_add_to_rel (bfd
* abfd
,
7768 reloc_howto_type
* howto
,
7769 bfd_signed_vma increment
)
7771 bfd_signed_vma addend
;
7773 if (howto
->type
== R_ARM_THM_CALL
7774 || howto
->type
== R_ARM_THM_JUMP24
)
7776 int upper_insn
, lower_insn
;
7779 upper_insn
= bfd_get_16 (abfd
, address
);
7780 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
7781 upper
= upper_insn
& 0x7ff;
7782 lower
= lower_insn
& 0x7ff;
7784 addend
= (upper
<< 12) | (lower
<< 1);
7785 addend
+= increment
;
7788 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
7789 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
7791 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
7792 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
7798 contents
= bfd_get_32 (abfd
, address
);
7800 /* Get the (signed) value from the instruction. */
7801 addend
= contents
& howto
->src_mask
;
7802 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7804 bfd_signed_vma mask
;
7807 mask
&= ~ howto
->src_mask
;
7811 /* Add in the increment, (which is a byte value). */
7812 switch (howto
->type
)
7815 addend
+= increment
;
7822 addend
<<= howto
->size
;
7823 addend
+= increment
;
7825 /* Should we check for overflow here ? */
7827 /* Drop any undesired bits. */
7828 addend
>>= howto
->rightshift
;
7832 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
7834 bfd_put_32 (abfd
, contents
, address
);
7838 #define IS_ARM_TLS_RELOC(R_TYPE) \
7839 ((R_TYPE) == R_ARM_TLS_GD32 \
7840 || (R_TYPE) == R_ARM_TLS_LDO32 \
7841 || (R_TYPE) == R_ARM_TLS_LDM32 \
7842 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7843 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7844 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7845 || (R_TYPE) == R_ARM_TLS_LE32 \
7846 || (R_TYPE) == R_ARM_TLS_IE32)
7848 /* Relocate an ARM ELF section. */
7851 elf32_arm_relocate_section (bfd
* output_bfd
,
7852 struct bfd_link_info
* info
,
7854 asection
* input_section
,
7855 bfd_byte
* contents
,
7856 Elf_Internal_Rela
* relocs
,
7857 Elf_Internal_Sym
* local_syms
,
7858 asection
** local_sections
)
7860 Elf_Internal_Shdr
*symtab_hdr
;
7861 struct elf_link_hash_entry
**sym_hashes
;
7862 Elf_Internal_Rela
*rel
;
7863 Elf_Internal_Rela
*relend
;
7865 struct elf32_arm_link_hash_table
* globals
;
7867 globals
= elf32_arm_hash_table (info
);
7869 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
7870 sym_hashes
= elf_sym_hashes (input_bfd
);
7873 relend
= relocs
+ input_section
->reloc_count
;
7874 for (; rel
< relend
; rel
++)
7877 reloc_howto_type
* howto
;
7878 unsigned long r_symndx
;
7879 Elf_Internal_Sym
* sym
;
7881 struct elf_link_hash_entry
* h
;
7883 bfd_reloc_status_type r
;
7886 bfd_boolean unresolved_reloc
= FALSE
;
7887 char *error_message
= NULL
;
7889 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7890 r_type
= ELF32_R_TYPE (rel
->r_info
);
7891 r_type
= arm_real_reloc_type (globals
, r_type
);
7893 if ( r_type
== R_ARM_GNU_VTENTRY
7894 || r_type
== R_ARM_GNU_VTINHERIT
)
7897 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
7898 howto
= bfd_reloc
.howto
;
7904 if (r_symndx
< symtab_hdr
->sh_info
)
7906 sym
= local_syms
+ r_symndx
;
7907 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
7908 sec
= local_sections
[r_symndx
];
7909 if (globals
->use_rel
)
7911 relocation
= (sec
->output_section
->vma
7912 + sec
->output_offset
7914 if (!info
->relocatable
7915 && (sec
->flags
& SEC_MERGE
)
7916 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7919 bfd_vma addend
, value
;
7923 case R_ARM_MOVW_ABS_NC
:
7924 case R_ARM_MOVT_ABS
:
7925 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7926 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
7927 addend
= (addend
^ 0x8000) - 0x8000;
7930 case R_ARM_THM_MOVW_ABS_NC
:
7931 case R_ARM_THM_MOVT_ABS
:
7932 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
7934 value
|= bfd_get_16 (input_bfd
,
7935 contents
+ rel
->r_offset
+ 2);
7936 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
7937 | ((value
& 0x04000000) >> 15);
7938 addend
= (addend
^ 0x8000) - 0x8000;
7942 if (howto
->rightshift
7943 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
7945 (*_bfd_error_handler
)
7946 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7947 input_bfd
, input_section
,
7948 (long) rel
->r_offset
, howto
->name
);
7952 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7954 /* Get the (signed) value from the instruction. */
7955 addend
= value
& howto
->src_mask
;
7956 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7958 bfd_signed_vma mask
;
7961 mask
&= ~ howto
->src_mask
;
7969 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
7971 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
7973 /* Cases here must match those in the preceeding
7974 switch statement. */
7977 case R_ARM_MOVW_ABS_NC
:
7978 case R_ARM_MOVT_ABS
:
7979 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
7981 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
7984 case R_ARM_THM_MOVW_ABS_NC
:
7985 case R_ARM_THM_MOVT_ABS
:
7986 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
7987 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
7988 bfd_put_16 (input_bfd
, value
>> 16,
7989 contents
+ rel
->r_offset
);
7990 bfd_put_16 (input_bfd
, value
,
7991 contents
+ rel
->r_offset
+ 2);
7995 value
= (value
& ~ howto
->dst_mask
)
7996 | (addend
& howto
->dst_mask
);
7997 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
8003 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8009 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
8010 r_symndx
, symtab_hdr
, sym_hashes
,
8012 unresolved_reloc
, warned
);
8017 if (sec
!= NULL
&& elf_discarded_section (sec
))
8019 /* For relocs against symbols from removed linkonce sections,
8020 or sections discarded by a linker script, we just want the
8021 section contents zeroed. Avoid any special processing. */
8022 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8028 if (info
->relocatable
)
8030 /* This is a relocatable link. We don't have to change
8031 anything, unless the reloc is against a section symbol,
8032 in which case we have to adjust according to where the
8033 section symbol winds up in the output section. */
8034 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8036 if (globals
->use_rel
)
8037 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
8038 howto
, (bfd_signed_vma
) sec
->output_offset
);
8040 rel
->r_addend
+= sec
->output_offset
;
8046 name
= h
->root
.root
.string
;
8049 name
= (bfd_elf_string_from_elf_section
8050 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
8051 if (name
== NULL
|| *name
== '\0')
8052 name
= bfd_section_name (input_bfd
, sec
);
8056 && r_type
!= R_ARM_NONE
8058 || h
->root
.type
== bfd_link_hash_defined
8059 || h
->root
.type
== bfd_link_hash_defweak
)
8060 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
8062 (*_bfd_error_handler
)
8063 ((sym_type
== STT_TLS
8064 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8065 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8068 (long) rel
->r_offset
,
8073 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
8074 input_section
, contents
, rel
,
8075 relocation
, info
, sec
, name
,
8076 (h
? ELF_ST_TYPE (h
->type
) :
8077 ELF_ST_TYPE (sym
->st_info
)), h
,
8078 &unresolved_reloc
, &error_message
);
8080 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8081 because such sections are not SEC_ALLOC and thus ld.so will
8082 not process them. */
8083 if (unresolved_reloc
8084 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8087 (*_bfd_error_handler
)
8088 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8091 (long) rel
->r_offset
,
8093 h
->root
.root
.string
);
8097 if (r
!= bfd_reloc_ok
)
8101 case bfd_reloc_overflow
:
8102 /* If the overflowing reloc was to an undefined symbol,
8103 we have already printed one error message and there
8104 is no point complaining again. */
8106 h
->root
.type
!= bfd_link_hash_undefined
)
8107 && (!((*info
->callbacks
->reloc_overflow
)
8108 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
8109 (bfd_vma
) 0, input_bfd
, input_section
,
8114 case bfd_reloc_undefined
:
8115 if (!((*info
->callbacks
->undefined_symbol
)
8116 (info
, name
, input_bfd
, input_section
,
8117 rel
->r_offset
, TRUE
)))
8121 case bfd_reloc_outofrange
:
8122 error_message
= _("out of range");
8125 case bfd_reloc_notsupported
:
8126 error_message
= _("unsupported relocation");
8129 case bfd_reloc_dangerous
:
8130 /* error_message should already be set. */
8134 error_message
= _("unknown error");
8138 BFD_ASSERT (error_message
!= NULL
);
8139 if (!((*info
->callbacks
->reloc_dangerous
)
8140 (info
, error_message
, input_bfd
, input_section
,
8152 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
8153 bfd
*ibfd
, const char *name
)
8155 asection
*sec
, *osec
;
8157 sec
= bfd_get_section_by_name (ibfd
, name
);
8158 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
8161 osec
= sec
->output_section
;
8162 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
8165 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
8166 sec
->output_offset
, sec
->size
))
8173 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
8175 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
8177 /* Invoke the regular ELF backend linker to do all the work. */
8178 if (!bfd_elf_final_link (abfd
, info
))
8181 /* Write out any glue sections now that we have created all the
8183 if (globals
->bfd_of_glue_owner
!= NULL
)
8185 if (! elf32_arm_output_glue_section (info
, abfd
,
8186 globals
->bfd_of_glue_owner
,
8187 ARM2THUMB_GLUE_SECTION_NAME
))
8190 if (! elf32_arm_output_glue_section (info
, abfd
,
8191 globals
->bfd_of_glue_owner
,
8192 THUMB2ARM_GLUE_SECTION_NAME
))
8195 if (! elf32_arm_output_glue_section (info
, abfd
,
8196 globals
->bfd_of_glue_owner
,
8197 VFP11_ERRATUM_VENEER_SECTION_NAME
))
8200 if (! elf32_arm_output_glue_section (info
, abfd
,
8201 globals
->bfd_of_glue_owner
,
8202 ARM_BX_GLUE_SECTION_NAME
))
8209 /* Set the right machine number. */
8212 elf32_arm_object_p (bfd
*abfd
)
8216 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
8218 if (mach
!= bfd_mach_arm_unknown
)
8219 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
8221 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
8222 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
8225 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
8230 /* Function to keep ARM specific flags in the ELF header. */
8233 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
8235 if (elf_flags_init (abfd
)
8236 && elf_elfheader (abfd
)->e_flags
!= flags
)
8238 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
8240 if (flags
& EF_ARM_INTERWORK
)
8241 (*_bfd_error_handler
)
8242 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8246 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8252 elf_elfheader (abfd
)->e_flags
= flags
;
8253 elf_flags_init (abfd
) = TRUE
;
8259 /* Copy backend specific data from one object module to another. */
8262 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
8267 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
8270 in_flags
= elf_elfheader (ibfd
)->e_flags
;
8271 out_flags
= elf_elfheader (obfd
)->e_flags
;
8273 if (elf_flags_init (obfd
)
8274 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
8275 && in_flags
!= out_flags
)
8277 /* Cannot mix APCS26 and APCS32 code. */
8278 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
8281 /* Cannot mix float APCS and non-float APCS code. */
8282 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
8285 /* If the src and dest have different interworking flags
8286 then turn off the interworking bit. */
8287 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
8289 if (out_flags
& EF_ARM_INTERWORK
)
8291 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8294 in_flags
&= ~EF_ARM_INTERWORK
;
8297 /* Likewise for PIC, though don't warn for this case. */
8298 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
8299 in_flags
&= ~EF_ARM_PIC
;
8302 elf_elfheader (obfd
)->e_flags
= in_flags
;
8303 elf_flags_init (obfd
) = TRUE
;
8305 /* Also copy the EI_OSABI field. */
8306 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
8307 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
8309 /* Copy object attributes. */
8310 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
8315 /* Values for Tag_ABI_PCS_R9_use. */
8324 /* Values for Tag_ABI_PCS_RW_data. */
8327 AEABI_PCS_RW_data_absolute
,
8328 AEABI_PCS_RW_data_PCrel
,
8329 AEABI_PCS_RW_data_SBrel
,
8330 AEABI_PCS_RW_data_unused
8333 /* Values for Tag_ABI_enum_size. */
8339 AEABI_enum_forced_wide
8342 /* Determine whether an object attribute tag takes an integer, a
8346 elf32_arm_obj_attrs_arg_type (int tag
)
8348 if (tag
== Tag_compatibility
)
8349 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
8350 else if (tag
== Tag_nodefaults
)
8351 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
8352 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
8353 return ATTR_TYPE_FLAG_STR_VAL
;
8355 return ATTR_TYPE_FLAG_INT_VAL
;
8357 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
8360 /* The ABI defines that Tag_conformance should be emitted first, and that
8361 Tag_nodefaults should be second (if either is defined). This sets those
8362 two positions, and bumps up the position of all the remaining tags to
8365 elf32_arm_obj_attrs_order (int num
)
8368 return Tag_conformance
;
8370 return Tag_nodefaults
;
8371 if ((num
- 2) < Tag_nodefaults
)
8373 if ((num
- 1) < Tag_conformance
)
8378 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
8379 Returns -1 if no architecture could be read. */
8382 get_secondary_compatible_arch (bfd
*abfd
)
8384 obj_attribute
*attr
=
8385 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
8387 /* Note: the tag and its argument below are uleb128 values, though
8388 currently-defined values fit in one byte for each. */
8390 && attr
->s
[0] == Tag_CPU_arch
8391 && (attr
->s
[1] & 128) != 128
8395 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8399 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8400 The tag is removed if ARCH is -1. */
8403 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
8405 obj_attribute
*attr
=
8406 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
8414 /* Note: the tag and its argument below are uleb128 values, though
8415 currently-defined values fit in one byte for each. */
8417 attr
->s
= bfd_alloc (abfd
, 3);
8418 attr
->s
[0] = Tag_CPU_arch
;
8423 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8427 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
8428 int newtag
, int secondary_compat
)
8430 #define T(X) TAG_CPU_ARCH_##X
8431 int tagl
, tagh
, result
;
8434 T(V6T2
), /* PRE_V4. */
8438 T(V6T2
), /* V5TE. */
8439 T(V6T2
), /* V5TEJ. */
8446 T(V6K
), /* PRE_V4. */
8451 T(V6K
), /* V5TEJ. */
8453 T(V6KZ
), /* V6KZ. */
8459 T(V7
), /* PRE_V4. */
8478 T(V6K
), /* V5TEJ. */
8480 T(V6KZ
), /* V6KZ. */
8493 T(V6K
), /* V5TEJ. */
8495 T(V6KZ
), /* V6KZ. */
8499 T(V6S_M
), /* V6_M. */
8500 T(V6S_M
) /* V6S_M. */
8502 const int v4t_plus_v6_m
[] =
8508 T(V5TE
), /* V5TE. */
8509 T(V5TEJ
), /* V5TEJ. */
8511 T(V6KZ
), /* V6KZ. */
8512 T(V6T2
), /* V6T2. */
8515 T(V6_M
), /* V6_M. */
8516 T(V6S_M
), /* V6S_M. */
8517 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
8526 /* Pseudo-architecture. */
8530 /* Check we've not got a higher architecture than we know about. */
8532 if (oldtag
>= MAX_TAG_CPU_ARCH
|| newtag
>= MAX_TAG_CPU_ARCH
)
8534 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd
);
8538 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8540 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
8541 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
8542 oldtag
= T(V4T_PLUS_V6_M
);
8544 /* And override the new tag if we have a Tag_also_compatible_with on the
8547 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
8548 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
8549 newtag
= T(V4T_PLUS_V6_M
);
8551 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
8552 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
8554 /* Architectures before V6KZ add features monotonically. */
8555 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
8558 result
= comb
[tagh
- T(V6T2
)][tagl
];
8560 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8561 as the canonical version. */
8562 if (result
== T(V4T_PLUS_V6_M
))
8565 *secondary_compat_out
= T(V6_M
);
8568 *secondary_compat_out
= -1;
8572 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
8573 ibfd
, oldtag
, newtag
);
8581 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8582 are conflicting attributes. */
8585 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
8587 obj_attribute
*in_attr
;
8588 obj_attribute
*out_attr
;
8589 obj_attribute_list
*in_list
;
8590 obj_attribute_list
*out_list
;
8591 obj_attribute_list
**out_listp
;
8592 /* Some tags have 0 = don't care, 1 = strong requirement,
8593 2 = weak requirement. */
8594 static const int order_021
[3] = {0, 2, 1};
8595 /* For use with Tag_VFP_arch. */
8596 static const int order_01243
[5] = {0, 1, 2, 4, 3};
8598 bfd_boolean result
= TRUE
;
8600 /* Skip the linker stubs file. This preserves previous behavior
8601 of accepting unknown attributes in the first input file - but
8603 if (ibfd
->flags
& BFD_LINKER_CREATED
)
8606 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
8608 /* This is the first object. Copy the attributes. */
8609 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
8611 /* Use the Tag_null value to indicate the attributes have been
8613 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
8618 in_attr
= elf_known_obj_attributes_proc (ibfd
);
8619 out_attr
= elf_known_obj_attributes_proc (obfd
);
8620 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8621 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
8623 /* Ignore mismatches if the object doesn't use floating point. */
8624 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
8625 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
8626 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
8629 (_("error: %B uses VFP register arguments, %B does not"),
8635 for (i
= 4; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
8637 /* Merge this attribute with existing attributes. */
8640 case Tag_CPU_raw_name
:
8642 /* These are merged after Tag_CPU_arch. */
8645 case Tag_ABI_optimization_goals
:
8646 case Tag_ABI_FP_optimization_goals
:
8647 /* Use the first value seen. */
8652 int secondary_compat
= -1, secondary_compat_out
= -1;
8653 unsigned int saved_out_attr
= out_attr
[i
].i
;
8654 static const char *name_table
[] = {
8655 /* These aren't real CPU names, but we can't guess
8656 that from the architecture version alone. */
8672 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8673 secondary_compat
= get_secondary_compatible_arch (ibfd
);
8674 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
8675 out_attr
[i
].i
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
8676 &secondary_compat_out
,
8679 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
8681 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8682 if (out_attr
[i
].i
== saved_out_attr
)
8683 ; /* Leave the names alone. */
8684 else if (out_attr
[i
].i
== in_attr
[i
].i
)
8686 /* The output architecture has been changed to match the
8687 input architecture. Use the input names. */
8688 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
8689 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
8691 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
8692 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
8697 out_attr
[Tag_CPU_name
].s
= NULL
;
8698 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
8701 /* If we still don't have a value for Tag_CPU_name,
8702 make one up now. Tag_CPU_raw_name remains blank. */
8703 if (out_attr
[Tag_CPU_name
].s
== NULL
8704 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
8705 out_attr
[Tag_CPU_name
].s
=
8706 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
8710 case Tag_ARM_ISA_use
:
8711 case Tag_THUMB_ISA_use
:
8713 case Tag_Advanced_SIMD_arch
:
8714 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
8715 case Tag_ABI_FP_rounding
:
8716 case Tag_ABI_FP_exceptions
:
8717 case Tag_ABI_FP_user_exceptions
:
8718 case Tag_ABI_FP_number_model
:
8719 case Tag_VFP_HP_extension
:
8720 case Tag_CPU_unaligned_access
:
8722 case Tag_Virtualization_use
:
8723 case Tag_MPextension_use
:
8724 /* Use the largest value specified. */
8725 if (in_attr
[i
].i
> out_attr
[i
].i
)
8726 out_attr
[i
].i
= in_attr
[i
].i
;
8729 case Tag_ABI_align8_preserved
:
8730 case Tag_ABI_PCS_RO_data
:
8731 /* Use the smallest value specified. */
8732 if (in_attr
[i
].i
< out_attr
[i
].i
)
8733 out_attr
[i
].i
= in_attr
[i
].i
;
8736 case Tag_ABI_align8_needed
:
8737 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
8738 && (in_attr
[Tag_ABI_align8_preserved
].i
== 0
8739 || out_attr
[Tag_ABI_align8_preserved
].i
== 0))
8741 /* This error message should be enabled once all non-conformant
8742 binaries in the toolchain have had the attributes set
8745 (_("error: %B: 8-byte data alignment conflicts with %B"),
8750 case Tag_ABI_FP_denormal
:
8751 case Tag_ABI_PCS_GOT_use
:
8752 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8753 value if greater than 2 (for future-proofing). */
8754 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
8755 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
8756 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
8757 out_attr
[i
].i
= in_attr
[i
].i
;
8761 case Tag_CPU_arch_profile
:
8762 if (out_attr
[i
].i
!= in_attr
[i
].i
)
8764 /* 0 will merge with anything.
8765 'A' and 'S' merge to 'A'.
8766 'R' and 'S' merge to 'R'.
8767 'M' and 'A|R|S' is an error. */
8768 if (out_attr
[i
].i
== 0
8769 || (out_attr
[i
].i
== 'S'
8770 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
8771 out_attr
[i
].i
= in_attr
[i
].i
;
8772 else if (in_attr
[i
].i
== 0
8773 || (in_attr
[i
].i
== 'S'
8774 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
8779 (_("error: %B: Conflicting architecture profiles %c/%c"),
8781 in_attr
[i
].i
? in_attr
[i
].i
: '0',
8782 out_attr
[i
].i
? out_attr
[i
].i
: '0');
8788 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8789 largest value if greater than 4 (for future-proofing). */
8790 if ((in_attr
[i
].i
> 4 && in_attr
[i
].i
> out_attr
[i
].i
)
8791 || (in_attr
[i
].i
<= 4 && out_attr
[i
].i
<= 4
8792 && order_01243
[in_attr
[i
].i
] > order_01243
[out_attr
[i
].i
]))
8793 out_attr
[i
].i
= in_attr
[i
].i
;
8795 case Tag_PCS_config
:
8796 if (out_attr
[i
].i
== 0)
8797 out_attr
[i
].i
= in_attr
[i
].i
;
8798 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
8800 /* It's sometimes ok to mix different configs, so this is only
8803 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
8806 case Tag_ABI_PCS_R9_use
:
8807 if (in_attr
[i
].i
!= out_attr
[i
].i
8808 && out_attr
[i
].i
!= AEABI_R9_unused
8809 && in_attr
[i
].i
!= AEABI_R9_unused
)
8812 (_("error: %B: Conflicting use of R9"), ibfd
);
8815 if (out_attr
[i
].i
== AEABI_R9_unused
)
8816 out_attr
[i
].i
= in_attr
[i
].i
;
8818 case Tag_ABI_PCS_RW_data
:
8819 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
8820 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
8821 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
8824 (_("error: %B: SB relative addressing conflicts with use of R9"),
8828 /* Use the smallest value specified. */
8829 if (in_attr
[i
].i
< out_attr
[i
].i
)
8830 out_attr
[i
].i
= in_attr
[i
].i
;
8832 case Tag_ABI_PCS_wchar_t
:
8833 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
8834 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
8837 (_("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"),
8838 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
8840 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
8841 out_attr
[i
].i
= in_attr
[i
].i
;
8843 case Tag_ABI_enum_size
:
8844 if (in_attr
[i
].i
!= AEABI_enum_unused
)
8846 if (out_attr
[i
].i
== AEABI_enum_unused
8847 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
8849 /* The existing object is compatible with anything.
8850 Use whatever requirements the new object has. */
8851 out_attr
[i
].i
= in_attr
[i
].i
;
8853 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
8854 && out_attr
[i
].i
!= in_attr
[i
].i
8855 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
8857 static const char *aeabi_enum_names
[] =
8858 { "", "variable-size", "32-bit", "" };
8859 const char *in_name
=
8860 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
8861 ? aeabi_enum_names
[in_attr
[i
].i
]
8863 const char *out_name
=
8864 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
8865 ? aeabi_enum_names
[out_attr
[i
].i
]
8868 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8869 ibfd
, in_name
, out_name
);
8873 case Tag_ABI_VFP_args
:
8876 case Tag_ABI_WMMX_args
:
8877 if (in_attr
[i
].i
!= out_attr
[i
].i
)
8880 (_("error: %B uses iWMMXt register arguments, %B does not"),
8885 case Tag_compatibility
:
8886 /* Merged in target-independent code. */
8888 case Tag_ABI_HardFP_use
:
8889 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8890 if ((in_attr
[i
].i
== 1 && out_attr
[i
].i
== 2)
8891 || (in_attr
[i
].i
== 2 && out_attr
[i
].i
== 1))
8893 else if (in_attr
[i
].i
> out_attr
[i
].i
)
8894 out_attr
[i
].i
= in_attr
[i
].i
;
8896 case Tag_ABI_FP_16bit_format
:
8897 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
8899 if (in_attr
[i
].i
!= out_attr
[i
].i
)
8902 (_("error: fp16 format mismatch between %B and %B"),
8907 if (in_attr
[i
].i
!= 0)
8908 out_attr
[i
].i
= in_attr
[i
].i
;
8911 case Tag_nodefaults
:
8912 /* This tag is set if it exists, but the value is unused (and is
8913 typically zero). We don't actually need to do anything here -
8914 the merge happens automatically when the type flags are merged
8917 case Tag_also_compatible_with
:
8918 /* Already done in Tag_CPU_arch. */
8920 case Tag_conformance
:
8921 /* Keep the attribute if it matches. Throw it away otherwise.
8922 No attribute means no claim to conform. */
8923 if (!in_attr
[i
].s
|| !out_attr
[i
].s
8924 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
8925 out_attr
[i
].s
= NULL
;
8930 bfd
*err_bfd
= NULL
;
8932 /* The "known_obj_attributes" table does contain some undefined
8933 attributes. Ensure that there are unused. */
8934 if (out_attr
[i
].i
!= 0 || out_attr
[i
].s
!= NULL
)
8936 else if (in_attr
[i
].i
!= 0 || in_attr
[i
].s
!= NULL
)
8939 if (err_bfd
!= NULL
)
8941 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8945 (_("%B: Unknown mandatory EABI object attribute %d"),
8947 bfd_set_error (bfd_error_bad_value
);
8953 (_("Warning: %B: Unknown EABI object attribute %d"),
8958 /* Only pass on attributes that match in both inputs. */
8959 if (in_attr
[i
].i
!= out_attr
[i
].i
8960 || in_attr
[i
].s
!= out_attr
[i
].s
8961 || (in_attr
[i
].s
!= NULL
&& out_attr
[i
].s
!= NULL
8962 && strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0))
8965 out_attr
[i
].s
= NULL
;
8970 /* If out_attr was copied from in_attr then it won't have a type yet. */
8971 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
8972 out_attr
[i
].type
= in_attr
[i
].type
;
8975 /* Merge Tag_compatibility attributes and any common GNU ones. */
8976 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
8978 /* Check for any attributes not known on ARM. */
8979 in_list
= elf_other_obj_attributes_proc (ibfd
);
8980 out_listp
= &elf_other_obj_attributes_proc (obfd
);
8981 out_list
= *out_listp
;
8983 for (; in_list
|| out_list
; )
8985 bfd
*err_bfd
= NULL
;
8988 /* The tags for each list are in numerical order. */
8989 /* If the tags are equal, then merge. */
8990 if (out_list
&& (!in_list
|| in_list
->tag
> out_list
->tag
))
8992 /* This attribute only exists in obfd. We can't merge, and we don't
8993 know what the tag means, so delete it. */
8995 err_tag
= out_list
->tag
;
8996 *out_listp
= out_list
->next
;
8997 out_list
= *out_listp
;
8999 else if (in_list
&& (!out_list
|| in_list
->tag
< out_list
->tag
))
9001 /* This attribute only exists in ibfd. We can't merge, and we don't
9002 know what the tag means, so ignore it. */
9004 err_tag
= in_list
->tag
;
9005 in_list
= in_list
->next
;
9007 else /* The tags are equal. */
9009 /* As present, all attributes in the list are unknown, and
9010 therefore can't be merged meaningfully. */
9012 err_tag
= out_list
->tag
;
9014 /* Only pass on attributes that match in both inputs. */
9015 if (in_list
->attr
.i
!= out_list
->attr
.i
9016 || in_list
->attr
.s
!= out_list
->attr
.s
9017 || (in_list
->attr
.s
&& out_list
->attr
.s
9018 && strcmp (in_list
->attr
.s
, out_list
->attr
.s
) != 0))
9020 /* No match. Delete the attribute. */
9021 *out_listp
= out_list
->next
;
9022 out_list
= *out_listp
;
9026 /* Matched. Keep the attribute and move to the next. */
9027 out_list
= out_list
->next
;
9028 in_list
= in_list
->next
;
9034 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9035 if ((err_tag
& 127) < 64)
9038 (_("%B: Unknown mandatory EABI object attribute %d"),
9040 bfd_set_error (bfd_error_bad_value
);
9046 (_("Warning: %B: Unknown EABI object attribute %d"),
9055 /* Return TRUE if the two EABI versions are incompatible. */
9058 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
9060 /* v4 and v5 are the same spec before and after it was released,
9061 so allow mixing them. */
9062 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
9063 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
9066 return (iver
== over
);
9069 /* Merge backend specific data from an object file to the output
9070 object file when linking. */
9073 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
9077 bfd_boolean flags_compatible
= TRUE
;
9080 /* Check if we have the same endianess. */
9081 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
9084 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
9087 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
9090 /* The input BFD must have had its flags initialised. */
9091 /* The following seems bogus to me -- The flags are initialized in
9092 the assembler but I don't think an elf_flags_init field is
9093 written into the object. */
9094 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9096 in_flags
= elf_elfheader (ibfd
)->e_flags
;
9097 out_flags
= elf_elfheader (obfd
)->e_flags
;
9099 /* In theory there is no reason why we couldn't handle this. However
9100 in practice it isn't even close to working and there is no real
9101 reason to want it. */
9102 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
9103 && !(ibfd
->flags
& DYNAMIC
)
9104 && (in_flags
& EF_ARM_BE8
))
9106 _bfd_error_handler (_("error: %B is already in final BE8 format"),
9111 if (!elf_flags_init (obfd
))
9113 /* If the input is the default architecture and had the default
9114 flags then do not bother setting the flags for the output
9115 architecture, instead allow future merges to do this. If no
9116 future merges ever set these flags then they will retain their
9117 uninitialised values, which surprise surprise, correspond
9118 to the default values. */
9119 if (bfd_get_arch_info (ibfd
)->the_default
9120 && elf_elfheader (ibfd
)->e_flags
== 0)
9123 elf_flags_init (obfd
) = TRUE
;
9124 elf_elfheader (obfd
)->e_flags
= in_flags
;
9126 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
9127 && bfd_get_arch_info (obfd
)->the_default
)
9128 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
9133 /* Determine what should happen if the input ARM architecture
9134 does not match the output ARM architecture. */
9135 if (! bfd_arm_merge_machines (ibfd
, obfd
))
9138 /* Identical flags must be compatible. */
9139 if (in_flags
== out_flags
)
9142 /* Check to see if the input BFD actually contains any sections. If
9143 not, its flags may not have been initialised either, but it
9144 cannot actually cause any incompatiblity. Do not short-circuit
9145 dynamic objects; their section list may be emptied by
9146 elf_link_add_object_symbols.
9148 Also check to see if there are no code sections in the input.
9149 In this case there is no need to check for code specific flags.
9150 XXX - do we need to worry about floating-point format compatability
9151 in data sections ? */
9152 if (!(ibfd
->flags
& DYNAMIC
))
9154 bfd_boolean null_input_bfd
= TRUE
;
9155 bfd_boolean only_data_sections
= TRUE
;
9157 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9159 /* Ignore synthetic glue sections. */
9160 if (strcmp (sec
->name
, ".glue_7")
9161 && strcmp (sec
->name
, ".glue_7t"))
9163 if ((bfd_get_section_flags (ibfd
, sec
)
9164 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
9165 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
9166 only_data_sections
= FALSE
;
9168 null_input_bfd
= FALSE
;
9173 if (null_input_bfd
|| only_data_sections
)
9177 /* Complain about various flag mismatches. */
9178 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
9179 EF_ARM_EABI_VERSION (out_flags
)))
9182 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
9184 (in_flags
& EF_ARM_EABIMASK
) >> 24,
9185 (out_flags
& EF_ARM_EABIMASK
) >> 24);
9189 /* Not sure what needs to be checked for EABI versions >= 1. */
9190 /* VxWorks libraries do not use these flags. */
9191 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
9192 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
9193 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
9195 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
9198 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9200 in_flags
& EF_ARM_APCS_26
? 26 : 32,
9201 out_flags
& EF_ARM_APCS_26
? 26 : 32);
9202 flags_compatible
= FALSE
;
9205 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
9207 if (in_flags
& EF_ARM_APCS_FLOAT
)
9209 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
9213 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
9216 flags_compatible
= FALSE
;
9219 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
9221 if (in_flags
& EF_ARM_VFP_FLOAT
)
9223 (_("error: %B uses VFP instructions, whereas %B does not"),
9227 (_("error: %B uses FPA instructions, whereas %B does not"),
9230 flags_compatible
= FALSE
;
9233 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
9235 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
9237 (_("error: %B uses Maverick instructions, whereas %B does not"),
9241 (_("error: %B does not use Maverick instructions, whereas %B does"),
9244 flags_compatible
= FALSE
;
9247 #ifdef EF_ARM_SOFT_FLOAT
9248 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
9250 /* We can allow interworking between code that is VFP format
9251 layout, and uses either soft float or integer regs for
9252 passing floating point arguments and results. We already
9253 know that the APCS_FLOAT flags match; similarly for VFP
9255 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
9256 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
9258 if (in_flags
& EF_ARM_SOFT_FLOAT
)
9260 (_("error: %B uses software FP, whereas %B uses hardware FP"),
9264 (_("error: %B uses hardware FP, whereas %B uses software FP"),
9267 flags_compatible
= FALSE
;
9272 /* Interworking mismatch is only a warning. */
9273 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
9275 if (in_flags
& EF_ARM_INTERWORK
)
9278 (_("Warning: %B supports interworking, whereas %B does not"),
9284 (_("Warning: %B does not support interworking, whereas %B does"),
9290 return flags_compatible
;
9293 /* Display the flags field. */
9296 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
9298 FILE * file
= (FILE *) ptr
;
9299 unsigned long flags
;
9301 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
9303 /* Print normal ELF private data. */
9304 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
9306 flags
= elf_elfheader (abfd
)->e_flags
;
9307 /* Ignore init flag - it may not be set, despite the flags field
9308 containing valid data. */
9310 /* xgettext:c-format */
9311 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
9313 switch (EF_ARM_EABI_VERSION (flags
))
9315 case EF_ARM_EABI_UNKNOWN
:
9316 /* The following flag bits are GNU extensions and not part of the
9317 official ARM ELF extended ABI. Hence they are only decoded if
9318 the EABI version is not set. */
9319 if (flags
& EF_ARM_INTERWORK
)
9320 fprintf (file
, _(" [interworking enabled]"));
9322 if (flags
& EF_ARM_APCS_26
)
9323 fprintf (file
, " [APCS-26]");
9325 fprintf (file
, " [APCS-32]");
9327 if (flags
& EF_ARM_VFP_FLOAT
)
9328 fprintf (file
, _(" [VFP float format]"));
9329 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
9330 fprintf (file
, _(" [Maverick float format]"));
9332 fprintf (file
, _(" [FPA float format]"));
9334 if (flags
& EF_ARM_APCS_FLOAT
)
9335 fprintf (file
, _(" [floats passed in float registers]"));
9337 if (flags
& EF_ARM_PIC
)
9338 fprintf (file
, _(" [position independent]"));
9340 if (flags
& EF_ARM_NEW_ABI
)
9341 fprintf (file
, _(" [new ABI]"));
9343 if (flags
& EF_ARM_OLD_ABI
)
9344 fprintf (file
, _(" [old ABI]"));
9346 if (flags
& EF_ARM_SOFT_FLOAT
)
9347 fprintf (file
, _(" [software FP]"));
9349 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
9350 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
9351 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
9352 | EF_ARM_MAVERICK_FLOAT
);
9355 case EF_ARM_EABI_VER1
:
9356 fprintf (file
, _(" [Version1 EABI]"));
9358 if (flags
& EF_ARM_SYMSARESORTED
)
9359 fprintf (file
, _(" [sorted symbol table]"));
9361 fprintf (file
, _(" [unsorted symbol table]"));
9363 flags
&= ~ EF_ARM_SYMSARESORTED
;
9366 case EF_ARM_EABI_VER2
:
9367 fprintf (file
, _(" [Version2 EABI]"));
9369 if (flags
& EF_ARM_SYMSARESORTED
)
9370 fprintf (file
, _(" [sorted symbol table]"));
9372 fprintf (file
, _(" [unsorted symbol table]"));
9374 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
9375 fprintf (file
, _(" [dynamic symbols use segment index]"));
9377 if (flags
& EF_ARM_MAPSYMSFIRST
)
9378 fprintf (file
, _(" [mapping symbols precede others]"));
9380 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
9381 | EF_ARM_MAPSYMSFIRST
);
9384 case EF_ARM_EABI_VER3
:
9385 fprintf (file
, _(" [Version3 EABI]"));
9388 case EF_ARM_EABI_VER4
:
9389 fprintf (file
, _(" [Version4 EABI]"));
9392 case EF_ARM_EABI_VER5
:
9393 fprintf (file
, _(" [Version5 EABI]"));
9395 if (flags
& EF_ARM_BE8
)
9396 fprintf (file
, _(" [BE8]"));
9398 if (flags
& EF_ARM_LE8
)
9399 fprintf (file
, _(" [LE8]"));
9401 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
9405 fprintf (file
, _(" <EABI version unrecognised>"));
9409 flags
&= ~ EF_ARM_EABIMASK
;
9411 if (flags
& EF_ARM_RELEXEC
)
9412 fprintf (file
, _(" [relocatable executable]"));
9414 if (flags
& EF_ARM_HASENTRY
)
9415 fprintf (file
, _(" [has entry point]"));
9417 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
9420 fprintf (file
, _("<Unrecognised flag bits set>"));
9428 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
9430 switch (ELF_ST_TYPE (elf_sym
->st_info
))
9433 return ELF_ST_TYPE (elf_sym
->st_info
);
9436 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9437 This allows us to distinguish between data used by Thumb instructions
9438 and non-data (which is probably code) inside Thumb regions of an
9440 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
9441 return ELF_ST_TYPE (elf_sym
->st_info
);
9452 elf32_arm_gc_mark_hook (asection
*sec
,
9453 struct bfd_link_info
*info
,
9454 Elf_Internal_Rela
*rel
,
9455 struct elf_link_hash_entry
*h
,
9456 Elf_Internal_Sym
*sym
)
9459 switch (ELF32_R_TYPE (rel
->r_info
))
9461 case R_ARM_GNU_VTINHERIT
:
9462 case R_ARM_GNU_VTENTRY
:
9466 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
9469 /* Update the got entry reference counts for the section being removed. */
9472 elf32_arm_gc_sweep_hook (bfd
* abfd
,
9473 struct bfd_link_info
* info
,
9475 const Elf_Internal_Rela
* relocs
)
9477 Elf_Internal_Shdr
*symtab_hdr
;
9478 struct elf_link_hash_entry
**sym_hashes
;
9479 bfd_signed_vma
*local_got_refcounts
;
9480 const Elf_Internal_Rela
*rel
, *relend
;
9481 struct elf32_arm_link_hash_table
* globals
;
9483 if (info
->relocatable
)
9486 globals
= elf32_arm_hash_table (info
);
9488 elf_section_data (sec
)->local_dynrel
= NULL
;
9490 symtab_hdr
= & elf_symtab_hdr (abfd
);
9491 sym_hashes
= elf_sym_hashes (abfd
);
9492 local_got_refcounts
= elf_local_got_refcounts (abfd
);
9494 check_use_blx (globals
);
9496 relend
= relocs
+ sec
->reloc_count
;
9497 for (rel
= relocs
; rel
< relend
; rel
++)
9499 unsigned long r_symndx
;
9500 struct elf_link_hash_entry
*h
= NULL
;
9503 r_symndx
= ELF32_R_SYM (rel
->r_info
);
9504 if (r_symndx
>= symtab_hdr
->sh_info
)
9506 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
9507 while (h
->root
.type
== bfd_link_hash_indirect
9508 || h
->root
.type
== bfd_link_hash_warning
)
9509 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9512 r_type
= ELF32_R_TYPE (rel
->r_info
);
9513 r_type
= arm_real_reloc_type (globals
, r_type
);
9517 case R_ARM_GOT_PREL
:
9518 case R_ARM_TLS_GD32
:
9519 case R_ARM_TLS_IE32
:
9522 if (h
->got
.refcount
> 0)
9523 h
->got
.refcount
-= 1;
9525 else if (local_got_refcounts
!= NULL
)
9527 if (local_got_refcounts
[r_symndx
] > 0)
9528 local_got_refcounts
[r_symndx
] -= 1;
9532 case R_ARM_TLS_LDM32
:
9533 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
9537 case R_ARM_ABS32_NOI
:
9539 case R_ARM_REL32_NOI
:
9545 case R_ARM_THM_CALL
:
9546 case R_ARM_THM_JUMP24
:
9547 case R_ARM_THM_JUMP19
:
9548 case R_ARM_MOVW_ABS_NC
:
9549 case R_ARM_MOVT_ABS
:
9550 case R_ARM_MOVW_PREL_NC
:
9551 case R_ARM_MOVT_PREL
:
9552 case R_ARM_THM_MOVW_ABS_NC
:
9553 case R_ARM_THM_MOVT_ABS
:
9554 case R_ARM_THM_MOVW_PREL_NC
:
9555 case R_ARM_THM_MOVT_PREL
:
9556 /* Should the interworking branches be here also? */
9560 struct elf32_arm_link_hash_entry
*eh
;
9561 struct elf32_arm_relocs_copied
**pp
;
9562 struct elf32_arm_relocs_copied
*p
;
9564 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9566 if (h
->plt
.refcount
> 0)
9568 h
->plt
.refcount
-= 1;
9569 if (r_type
== R_ARM_THM_CALL
)
9570 eh
->plt_maybe_thumb_refcount
--;
9572 if (r_type
== R_ARM_THM_JUMP24
9573 || r_type
== R_ARM_THM_JUMP19
)
9574 eh
->plt_thumb_refcount
--;
9577 if (r_type
== R_ARM_ABS32
9578 || r_type
== R_ARM_REL32
9579 || r_type
== R_ARM_ABS32_NOI
9580 || r_type
== R_ARM_REL32_NOI
)
9582 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
9584 if (p
->section
== sec
)
9587 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
9588 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32_NOI
)
9606 /* Look through the relocs for a section during the first phase. */
9609 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
9610 asection
*sec
, const Elf_Internal_Rela
*relocs
)
9612 Elf_Internal_Shdr
*symtab_hdr
;
9613 struct elf_link_hash_entry
**sym_hashes
;
9614 const Elf_Internal_Rela
*rel
;
9615 const Elf_Internal_Rela
*rel_end
;
9618 bfd_vma
*local_got_offsets
;
9619 struct elf32_arm_link_hash_table
*htab
;
9620 bfd_boolean needs_plt
;
9621 unsigned long nsyms
;
9623 if (info
->relocatable
)
9626 BFD_ASSERT (is_arm_elf (abfd
));
9628 htab
= elf32_arm_hash_table (info
);
9631 /* Create dynamic sections for relocatable executables so that we can
9632 copy relocations. */
9633 if (htab
->root
.is_relocatable_executable
9634 && ! htab
->root
.dynamic_sections_created
)
9636 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
9640 dynobj
= elf_hash_table (info
)->dynobj
;
9641 local_got_offsets
= elf_local_got_offsets (abfd
);
9643 symtab_hdr
= & elf_symtab_hdr (abfd
);
9644 sym_hashes
= elf_sym_hashes (abfd
);
9645 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
9647 rel_end
= relocs
+ sec
->reloc_count
;
9648 for (rel
= relocs
; rel
< rel_end
; rel
++)
9650 struct elf_link_hash_entry
*h
;
9651 struct elf32_arm_link_hash_entry
*eh
;
9652 unsigned long r_symndx
;
9655 r_symndx
= ELF32_R_SYM (rel
->r_info
);
9656 r_type
= ELF32_R_TYPE (rel
->r_info
);
9657 r_type
= arm_real_reloc_type (htab
, r_type
);
9659 if (r_symndx
>= nsyms
9660 /* PR 9934: It is possible to have relocations that do not
9661 refer to symbols, thus it is also possible to have an
9662 object file containing relocations but no symbol table. */
9663 && (r_symndx
> 0 || nsyms
> 0))
9665 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
9670 if (nsyms
== 0 || r_symndx
< symtab_hdr
->sh_info
)
9674 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
9675 while (h
->root
.type
== bfd_link_hash_indirect
9676 || h
->root
.type
== bfd_link_hash_warning
)
9677 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9680 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9685 case R_ARM_GOT_PREL
:
9686 case R_ARM_TLS_GD32
:
9687 case R_ARM_TLS_IE32
:
9688 /* This symbol requires a global offset table entry. */
9690 int tls_type
, old_tls_type
;
9694 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
9695 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
9696 default: tls_type
= GOT_NORMAL
; break;
9702 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
9706 bfd_signed_vma
*local_got_refcounts
;
9708 /* This is a global offset table entry for a local symbol. */
9709 local_got_refcounts
= elf_local_got_refcounts (abfd
);
9710 if (local_got_refcounts
== NULL
)
9714 size
= symtab_hdr
->sh_info
;
9715 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
9716 local_got_refcounts
= bfd_zalloc (abfd
, size
);
9717 if (local_got_refcounts
== NULL
)
9719 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
9720 elf32_arm_local_got_tls_type (abfd
)
9721 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
9723 local_got_refcounts
[r_symndx
] += 1;
9724 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
9727 /* We will already have issued an error message if there is a
9728 TLS / non-TLS mismatch, based on the symbol type. We don't
9729 support any linker relaxations. So just combine any TLS
9731 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
9732 && tls_type
!= GOT_NORMAL
)
9733 tls_type
|= old_tls_type
;
9735 if (old_tls_type
!= tls_type
)
9738 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
9740 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
9745 case R_ARM_TLS_LDM32
:
9746 if (r_type
== R_ARM_TLS_LDM32
)
9747 htab
->tls_ldm_got
.refcount
++;
9750 case R_ARM_GOTOFF32
:
9752 if (htab
->sgot
== NULL
)
9754 if (htab
->root
.dynobj
== NULL
)
9755 htab
->root
.dynobj
= abfd
;
9756 if (!create_got_section (htab
->root
.dynobj
, info
))
9762 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9763 ldr __GOTT_INDEX__ offsets. */
9764 if (!htab
->vxworks_p
)
9773 case R_ARM_THM_CALL
:
9774 case R_ARM_THM_JUMP24
:
9775 case R_ARM_THM_JUMP19
:
9779 case R_ARM_MOVW_ABS_NC
:
9780 case R_ARM_MOVT_ABS
:
9781 case R_ARM_THM_MOVW_ABS_NC
:
9782 case R_ARM_THM_MOVT_ABS
:
9785 (*_bfd_error_handler
)
9786 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
9787 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
9788 (h
) ? h
->root
.root
.string
: "a local symbol");
9789 bfd_set_error (bfd_error_bad_value
);
9795 case R_ARM_ABS32_NOI
:
9797 case R_ARM_REL32_NOI
:
9798 case R_ARM_MOVW_PREL_NC
:
9799 case R_ARM_MOVT_PREL
:
9800 case R_ARM_THM_MOVW_PREL_NC
:
9801 case R_ARM_THM_MOVT_PREL
:
9805 /* Should the interworking branches be listed here? */
9808 /* If this reloc is in a read-only section, we might
9809 need a copy reloc. We can't check reliably at this
9810 stage whether the section is read-only, as input
9811 sections have not yet been mapped to output sections.
9812 Tentatively set the flag for now, and correct in
9813 adjust_dynamic_symbol. */
9817 /* We may need a .plt entry if the function this reloc
9818 refers to is in a different object. We can't tell for
9819 sure yet, because something later might force the
9824 /* If we create a PLT entry, this relocation will reference
9825 it, even if it's an ABS32 relocation. */
9826 h
->plt
.refcount
+= 1;
9828 /* It's too early to use htab->use_blx here, so we have to
9829 record possible blx references separately from
9830 relocs that definitely need a thumb stub. */
9832 if (r_type
== R_ARM_THM_CALL
)
9833 eh
->plt_maybe_thumb_refcount
+= 1;
9835 if (r_type
== R_ARM_THM_JUMP24
9836 || r_type
== R_ARM_THM_JUMP19
)
9837 eh
->plt_thumb_refcount
+= 1;
9840 /* If we are creating a shared library or relocatable executable,
9841 and this is a reloc against a global symbol, or a non PC
9842 relative reloc against a local symbol, then we need to copy
9843 the reloc into the shared library. However, if we are linking
9844 with -Bsymbolic, we do not need to copy a reloc against a
9845 global symbol which is defined in an object we are
9846 including in the link (i.e., DEF_REGULAR is set). At
9847 this point we have not seen all the input files, so it is
9848 possible that DEF_REGULAR is not set now but will be set
9849 later (it is never cleared). We account for that
9850 possibility below by storing information in the
9851 relocs_copied field of the hash table entry. */
9852 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
9853 && (sec
->flags
& SEC_ALLOC
) != 0
9854 && ((r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
)
9855 || (h
!= NULL
&& ! h
->needs_plt
9856 && (! info
->symbolic
|| ! h
->def_regular
))))
9858 struct elf32_arm_relocs_copied
*p
, **head
;
9860 /* When creating a shared object, we must copy these
9861 reloc types into the output file. We create a reloc
9862 section in dynobj and make room for this reloc. */
9865 sreloc
= _bfd_elf_make_dynamic_reloc_section
9866 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
9871 /* BPABI objects never have dynamic relocations mapped. */
9872 if (htab
->symbian_p
)
9876 flags
= bfd_get_section_flags (dynobj
, sreloc
);
9877 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
9878 bfd_set_section_flags (dynobj
, sreloc
, flags
);
9882 /* If this is a global symbol, we count the number of
9883 relocations we need for this symbol. */
9886 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
9890 /* Track dynamic relocs needed for local syms too.
9891 We really need local syms available to do this
9897 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
9902 vpp
= &elf_section_data (s
)->local_dynrel
;
9903 head
= (struct elf32_arm_relocs_copied
**) vpp
;
9907 if (p
== NULL
|| p
->section
!= sec
)
9909 bfd_size_type amt
= sizeof *p
;
9911 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
9921 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
9927 /* This relocation describes the C++ object vtable hierarchy.
9928 Reconstruct it for later use during GC. */
9929 case R_ARM_GNU_VTINHERIT
:
9930 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
9934 /* This relocation describes which C++ vtable entries are actually
9935 used. Record for later use during GC. */
9936 case R_ARM_GNU_VTENTRY
:
9937 BFD_ASSERT (h
!= NULL
);
9939 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
9948 /* Unwinding tables are not referenced directly. This pass marks them as
9949 required if the corresponding code section is marked. */
9952 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
9953 elf_gc_mark_hook_fn gc_mark_hook
)
9956 Elf_Internal_Shdr
**elf_shdrp
;
9959 /* Marking EH data may cause additional code sections to be marked,
9960 requiring multiple passes. */
9965 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
9969 if (! is_arm_elf (sub
))
9972 elf_shdrp
= elf_elfsections (sub
);
9973 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
9975 Elf_Internal_Shdr
*hdr
;
9977 hdr
= &elf_section_data (o
)->this_hdr
;
9978 if (hdr
->sh_type
== SHT_ARM_EXIDX
9980 && hdr
->sh_link
< elf_numsections (sub
)
9982 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
9985 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
9995 /* Treat mapping symbols as special target symbols. */
9998 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
10000 return bfd_is_arm_special_symbol_name (sym
->name
,
10001 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
10004 /* This is a copy of elf_find_function() from elf.c except that
10005 ARM mapping symbols are ignored when looking for function names
10006 and STT_ARM_TFUNC is considered to a function type. */
10009 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
10010 asection
* section
,
10011 asymbol
** symbols
,
10013 const char ** filename_ptr
,
10014 const char ** functionname_ptr
)
10016 const char * filename
= NULL
;
10017 asymbol
* func
= NULL
;
10018 bfd_vma low_func
= 0;
10021 for (p
= symbols
; *p
!= NULL
; p
++)
10023 elf_symbol_type
*q
;
10025 q
= (elf_symbol_type
*) *p
;
10027 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
10032 filename
= bfd_asymbol_name (&q
->symbol
);
10035 case STT_ARM_TFUNC
:
10037 /* Skip mapping symbols. */
10038 if ((q
->symbol
.flags
& BSF_LOCAL
)
10039 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
10040 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
10042 /* Fall through. */
10043 if (bfd_get_section (&q
->symbol
) == section
10044 && q
->symbol
.value
>= low_func
10045 && q
->symbol
.value
<= offset
)
10047 func
= (asymbol
*) q
;
10048 low_func
= q
->symbol
.value
;
10058 *filename_ptr
= filename
;
10059 if (functionname_ptr
)
10060 *functionname_ptr
= bfd_asymbol_name (func
);
10066 /* Find the nearest line to a particular section and offset, for error
10067 reporting. This code is a duplicate of the code in elf.c, except
10068 that it uses arm_elf_find_function. */
10071 elf32_arm_find_nearest_line (bfd
* abfd
,
10072 asection
* section
,
10073 asymbol
** symbols
,
10075 const char ** filename_ptr
,
10076 const char ** functionname_ptr
,
10077 unsigned int * line_ptr
)
10079 bfd_boolean found
= FALSE
;
10081 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
10083 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
10084 filename_ptr
, functionname_ptr
,
10086 & elf_tdata (abfd
)->dwarf2_find_line_info
))
10088 if (!*functionname_ptr
)
10089 arm_elf_find_function (abfd
, section
, symbols
, offset
,
10090 *filename_ptr
? NULL
: filename_ptr
,
10096 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
10097 & found
, filename_ptr
,
10098 functionname_ptr
, line_ptr
,
10099 & elf_tdata (abfd
)->line_info
))
10102 if (found
&& (*functionname_ptr
|| *line_ptr
))
10105 if (symbols
== NULL
)
10108 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
10109 filename_ptr
, functionname_ptr
))
10117 elf32_arm_find_inliner_info (bfd
* abfd
,
10118 const char ** filename_ptr
,
10119 const char ** functionname_ptr
,
10120 unsigned int * line_ptr
)
10123 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
10124 functionname_ptr
, line_ptr
,
10125 & elf_tdata (abfd
)->dwarf2_find_line_info
);
10129 /* Adjust a symbol defined by a dynamic object and referenced by a
10130 regular object. The current definition is in some section of the
10131 dynamic object, but we're not including those sections. We have to
10132 change the definition to something the rest of the link can
10136 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
10137 struct elf_link_hash_entry
* h
)
10141 struct elf32_arm_link_hash_entry
* eh
;
10142 struct elf32_arm_link_hash_table
*globals
;
10144 globals
= elf32_arm_hash_table (info
);
10145 dynobj
= elf_hash_table (info
)->dynobj
;
10147 /* Make sure we know what is going on here. */
10148 BFD_ASSERT (dynobj
!= NULL
10150 || h
->u
.weakdef
!= NULL
10153 && !h
->def_regular
)));
10155 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10157 /* If this is a function, put it in the procedure linkage table. We
10158 will fill in the contents of the procedure linkage table later,
10159 when we know the address of the .got section. */
10160 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
10163 if (h
->plt
.refcount
<= 0
10164 || SYMBOL_CALLS_LOCAL (info
, h
)
10165 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
10166 && h
->root
.type
== bfd_link_hash_undefweak
))
10168 /* This case can occur if we saw a PLT32 reloc in an input
10169 file, but the symbol was never referred to by a dynamic
10170 object, or if all references were garbage collected. In
10171 such a case, we don't actually need to build a procedure
10172 linkage table, and we can just do a PC24 reloc instead. */
10173 h
->plt
.offset
= (bfd_vma
) -1;
10174 eh
->plt_thumb_refcount
= 0;
10175 eh
->plt_maybe_thumb_refcount
= 0;
10183 /* It's possible that we incorrectly decided a .plt reloc was
10184 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10185 in check_relocs. We can't decide accurately between function
10186 and non-function syms in check-relocs; Objects loaded later in
10187 the link may change h->type. So fix it now. */
10188 h
->plt
.offset
= (bfd_vma
) -1;
10189 eh
->plt_thumb_refcount
= 0;
10190 eh
->plt_maybe_thumb_refcount
= 0;
10193 /* If this is a weak symbol, and there is a real definition, the
10194 processor independent code will have arranged for us to see the
10195 real definition first, and we can just use the same value. */
10196 if (h
->u
.weakdef
!= NULL
)
10198 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
10199 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
10200 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
10201 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
10205 /* If there are no non-GOT references, we do not need a copy
10207 if (!h
->non_got_ref
)
10210 /* This is a reference to a symbol defined by a dynamic object which
10211 is not a function. */
10213 /* If we are creating a shared library, we must presume that the
10214 only references to the symbol are via the global offset table.
10215 For such cases we need not do anything here; the relocations will
10216 be handled correctly by relocate_section. Relocatable executables
10217 can reference data in shared objects directly, so we don't need to
10218 do anything here. */
10219 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
10224 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
10225 h
->root
.root
.string
);
10229 /* We must allocate the symbol in our .dynbss section, which will
10230 become part of the .bss section of the executable. There will be
10231 an entry for this symbol in the .dynsym section. The dynamic
10232 object will contain position independent code, so all references
10233 from the dynamic object to this symbol will go through the global
10234 offset table. The dynamic linker will use the .dynsym entry to
10235 determine the address it must put in the global offset table, so
10236 both the dynamic object and the regular object will refer to the
10237 same memory location for the variable. */
10238 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
10239 BFD_ASSERT (s
!= NULL
);
10241 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10242 copy the initial value out of the dynamic object and into the
10243 runtime process image. We need to remember the offset into the
10244 .rel(a).bss section we are going to use. */
10245 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
10249 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
10250 BFD_ASSERT (srel
!= NULL
);
10251 srel
->size
+= RELOC_SIZE (globals
);
10255 return _bfd_elf_adjust_dynamic_copy (h
, s
);
10258 /* Allocate space in .plt, .got and associated reloc sections for
10262 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
10264 struct bfd_link_info
*info
;
10265 struct elf32_arm_link_hash_table
*htab
;
10266 struct elf32_arm_link_hash_entry
*eh
;
10267 struct elf32_arm_relocs_copied
*p
;
10268 bfd_signed_vma thumb_refs
;
10270 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10272 if (h
->root
.type
== bfd_link_hash_indirect
)
10275 if (h
->root
.type
== bfd_link_hash_warning
)
10276 /* When warning symbols are created, they **replace** the "real"
10277 entry in the hash table, thus we never get to see the real
10278 symbol in a hash traversal. So look at it now. */
10279 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10281 info
= (struct bfd_link_info
*) inf
;
10282 htab
= elf32_arm_hash_table (info
);
10284 if (htab
->root
.dynamic_sections_created
10285 && h
->plt
.refcount
> 0)
10287 /* Make sure this symbol is output as a dynamic symbol.
10288 Undefined weak syms won't yet be marked as dynamic. */
10289 if (h
->dynindx
== -1
10290 && !h
->forced_local
)
10292 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
10297 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
10299 asection
*s
= htab
->splt
;
10301 /* If this is the first .plt entry, make room for the special
10304 s
->size
+= htab
->plt_header_size
;
10306 h
->plt
.offset
= s
->size
;
10308 /* If we will insert a Thumb trampoline before this PLT, leave room
10310 thumb_refs
= eh
->plt_thumb_refcount
;
10311 if (!htab
->use_blx
)
10312 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
10314 if (thumb_refs
> 0)
10316 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
10317 s
->size
+= PLT_THUMB_STUB_SIZE
;
10320 /* If this symbol is not defined in a regular file, and we are
10321 not generating a shared library, then set the symbol to this
10322 location in the .plt. This is required to make function
10323 pointers compare as equal between the normal executable and
10324 the shared library. */
10326 && !h
->def_regular
)
10328 h
->root
.u
.def
.section
= s
;
10329 h
->root
.u
.def
.value
= h
->plt
.offset
;
10331 /* Make sure the function is not marked as Thumb, in case
10332 it is the target of an ABS32 relocation, which will
10333 point to the PLT entry. */
10334 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
10335 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
10338 /* Make room for this entry. */
10339 s
->size
+= htab
->plt_entry_size
;
10341 if (!htab
->symbian_p
)
10343 /* We also need to make an entry in the .got.plt section, which
10344 will be placed in the .got section by the linker script. */
10345 eh
->plt_got_offset
= htab
->sgotplt
->size
;
10346 htab
->sgotplt
->size
+= 4;
10349 /* We also need to make an entry in the .rel(a).plt section. */
10350 htab
->srelplt
->size
+= RELOC_SIZE (htab
);
10352 /* VxWorks executables have a second set of relocations for
10353 each PLT entry. They go in a separate relocation section,
10354 which is processed by the kernel loader. */
10355 if (htab
->vxworks_p
&& !info
->shared
)
10357 /* There is a relocation for the initial PLT entry:
10358 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10359 if (h
->plt
.offset
== htab
->plt_header_size
)
10360 htab
->srelplt2
->size
+= RELOC_SIZE (htab
);
10362 /* There are two extra relocations for each subsequent
10363 PLT entry: an R_ARM_32 relocation for the GOT entry,
10364 and an R_ARM_32 relocation for the PLT entry. */
10365 htab
->srelplt2
->size
+= RELOC_SIZE (htab
) * 2;
10370 h
->plt
.offset
= (bfd_vma
) -1;
10376 h
->plt
.offset
= (bfd_vma
) -1;
10380 if (h
->got
.refcount
> 0)
10384 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
10387 /* Make sure this symbol is output as a dynamic symbol.
10388 Undefined weak syms won't yet be marked as dynamic. */
10389 if (h
->dynindx
== -1
10390 && !h
->forced_local
)
10392 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
10396 if (!htab
->symbian_p
)
10399 h
->got
.offset
= s
->size
;
10401 if (tls_type
== GOT_UNKNOWN
)
10404 if (tls_type
== GOT_NORMAL
)
10405 /* Non-TLS symbols need one GOT slot. */
10409 if (tls_type
& GOT_TLS_GD
)
10410 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10412 if (tls_type
& GOT_TLS_IE
)
10413 /* R_ARM_TLS_IE32 needs one GOT slot. */
10417 dyn
= htab
->root
.dynamic_sections_created
;
10420 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
10422 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
10425 if (tls_type
!= GOT_NORMAL
10426 && (info
->shared
|| indx
!= 0)
10427 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
10428 || h
->root
.type
!= bfd_link_hash_undefweak
))
10430 if (tls_type
& GOT_TLS_IE
)
10431 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10433 if (tls_type
& GOT_TLS_GD
)
10434 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10436 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
10437 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10439 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
10440 || h
->root
.type
!= bfd_link_hash_undefweak
)
10442 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
10443 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10447 h
->got
.offset
= (bfd_vma
) -1;
10449 /* Allocate stubs for exported Thumb functions on v4t. */
10450 if (!htab
->use_blx
&& h
->dynindx
!= -1
10452 && ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
10453 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
10455 struct elf_link_hash_entry
* th
;
10456 struct bfd_link_hash_entry
* bh
;
10457 struct elf_link_hash_entry
* myh
;
10461 /* Create a new symbol to regist the real location of the function. */
10462 s
= h
->root
.u
.def
.section
;
10463 sprintf (name
, "__real_%s", h
->root
.root
.string
);
10464 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
10465 name
, BSF_GLOBAL
, s
,
10466 h
->root
.u
.def
.value
,
10467 NULL
, TRUE
, FALSE
, &bh
);
10469 myh
= (struct elf_link_hash_entry
*) bh
;
10470 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
10471 myh
->forced_local
= 1;
10472 eh
->export_glue
= myh
;
10473 th
= record_arm_to_thumb_glue (info
, h
);
10474 /* Point the symbol at the stub. */
10475 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
10476 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
10477 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
10480 if (eh
->relocs_copied
== NULL
)
10483 /* In the shared -Bsymbolic case, discard space allocated for
10484 dynamic pc-relative relocs against symbols which turn out to be
10485 defined in regular objects. For the normal shared case, discard
10486 space for pc-relative relocs that have become local due to symbol
10487 visibility changes. */
10489 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
10491 /* The only relocs that use pc_count are R_ARM_REL32 and
10492 R_ARM_REL32_NOI, which will appear on something like
10493 ".long foo - .". We want calls to protected symbols to resolve
10494 directly to the function rather than going via the plt. If people
10495 want function pointer comparisons to work as expected then they
10496 should avoid writing assembly like ".long foo - .". */
10497 if (SYMBOL_CALLS_LOCAL (info
, h
))
10499 struct elf32_arm_relocs_copied
**pp
;
10501 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
10503 p
->count
-= p
->pc_count
;
10512 if (elf32_arm_hash_table (info
)->vxworks_p
)
10514 struct elf32_arm_relocs_copied
**pp
;
10516 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
10518 if (strcmp (p
->section
->output_section
->name
, ".tls_vars") == 0)
10525 /* Also discard relocs on undefined weak syms with non-default
10527 if (eh
->relocs_copied
!= NULL
10528 && h
->root
.type
== bfd_link_hash_undefweak
)
10530 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
10531 eh
->relocs_copied
= NULL
;
10533 /* Make sure undefined weak symbols are output as a dynamic
10535 else if (h
->dynindx
== -1
10536 && !h
->forced_local
)
10538 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
10543 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
10544 && h
->root
.type
== bfd_link_hash_new
)
10546 /* Output absolute symbols so that we can create relocations
10547 against them. For normal symbols we output a relocation
10548 against the section that contains them. */
10549 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
10556 /* For the non-shared case, discard space for relocs against
10557 symbols which turn out to need copy relocs or are not
10560 if (!h
->non_got_ref
10561 && ((h
->def_dynamic
10562 && !h
->def_regular
)
10563 || (htab
->root
.dynamic_sections_created
10564 && (h
->root
.type
== bfd_link_hash_undefweak
10565 || h
->root
.type
== bfd_link_hash_undefined
))))
10567 /* Make sure this symbol is output as a dynamic symbol.
10568 Undefined weak syms won't yet be marked as dynamic. */
10569 if (h
->dynindx
== -1
10570 && !h
->forced_local
)
10572 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
10576 /* If that succeeded, we know we'll be keeping all the
10578 if (h
->dynindx
!= -1)
10582 eh
->relocs_copied
= NULL
;
10587 /* Finally, allocate space. */
10588 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
10590 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
10591 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
10597 /* Find any dynamic relocs that apply to read-only sections. */
10600 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
10602 struct elf32_arm_link_hash_entry
* eh
;
10603 struct elf32_arm_relocs_copied
* p
;
10605 if (h
->root
.type
== bfd_link_hash_warning
)
10606 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10608 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10609 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
10611 asection
*s
= p
->section
;
10613 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
10615 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
10617 info
->flags
|= DF_TEXTREL
;
10619 /* Not an error, just cut short the traversal. */
10627 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
10630 struct elf32_arm_link_hash_table
*globals
;
10632 globals
= elf32_arm_hash_table (info
);
10633 globals
->byteswap_code
= byteswap_code
;
10636 /* Set the sizes of the dynamic sections. */
10639 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
10640 struct bfd_link_info
* info
)
10645 bfd_boolean relocs
;
10647 struct elf32_arm_link_hash_table
*htab
;
10649 htab
= elf32_arm_hash_table (info
);
10650 dynobj
= elf_hash_table (info
)->dynobj
;
10651 BFD_ASSERT (dynobj
!= NULL
);
10652 check_use_blx (htab
);
10654 if (elf_hash_table (info
)->dynamic_sections_created
)
10656 /* Set the contents of the .interp section to the interpreter. */
10657 if (info
->executable
)
10659 s
= bfd_get_section_by_name (dynobj
, ".interp");
10660 BFD_ASSERT (s
!= NULL
);
10661 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10662 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10666 /* Set up .got offsets for local syms, and space for local dynamic
10668 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10670 bfd_signed_vma
*local_got
;
10671 bfd_signed_vma
*end_local_got
;
10672 char *local_tls_type
;
10673 bfd_size_type locsymcount
;
10674 Elf_Internal_Shdr
*symtab_hdr
;
10676 bfd_boolean is_vxworks
= elf32_arm_hash_table (info
)->vxworks_p
;
10678 if (! is_arm_elf (ibfd
))
10681 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10683 struct elf32_arm_relocs_copied
*p
;
10685 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10687 if (!bfd_is_abs_section (p
->section
)
10688 && bfd_is_abs_section (p
->section
->output_section
))
10690 /* Input section has been discarded, either because
10691 it is a copy of a linkonce section or due to
10692 linker script /DISCARD/, so we'll be discarding
10695 else if (is_vxworks
10696 && strcmp (p
->section
->output_section
->name
,
10699 /* Relocations in vxworks .tls_vars sections are
10700 handled specially by the loader. */
10702 else if (p
->count
!= 0)
10704 srel
= elf_section_data (p
->section
)->sreloc
;
10705 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
10706 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
10707 info
->flags
|= DF_TEXTREL
;
10712 local_got
= elf_local_got_refcounts (ibfd
);
10716 symtab_hdr
= & elf_symtab_hdr (ibfd
);
10717 locsymcount
= symtab_hdr
->sh_info
;
10718 end_local_got
= local_got
+ locsymcount
;
10719 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
10721 srel
= htab
->srelgot
;
10722 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
10724 if (*local_got
> 0)
10726 *local_got
= s
->size
;
10727 if (*local_tls_type
& GOT_TLS_GD
)
10728 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10730 if (*local_tls_type
& GOT_TLS_IE
)
10732 if (*local_tls_type
== GOT_NORMAL
)
10735 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
10736 srel
->size
+= RELOC_SIZE (htab
);
10739 *local_got
= (bfd_vma
) -1;
10743 if (htab
->tls_ldm_got
.refcount
> 0)
10745 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10746 for R_ARM_TLS_LDM32 relocations. */
10747 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
10748 htab
->sgot
->size
+= 8;
10750 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10753 htab
->tls_ldm_got
.offset
= -1;
10755 /* Allocate global sym .plt and .got entries, and space for global
10756 sym dynamic relocs. */
10757 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
10759 /* Here we rummage through the found bfds to collect glue information. */
10760 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10762 if (! is_arm_elf (ibfd
))
10765 /* Initialise mapping tables for code/data. */
10766 bfd_elf32_arm_init_maps (ibfd
);
10768 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
10769 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
10770 /* xgettext:c-format */
10771 _bfd_error_handler (_("Errors encountered processing file %s"),
10775 /* Allocate space for the glue sections now that we've sized them. */
10776 bfd_elf32_arm_allocate_interworking_sections (info
);
10778 /* The check_relocs and adjust_dynamic_symbol entry points have
10779 determined the sizes of the various dynamic sections. Allocate
10780 memory for them. */
10783 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10787 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10790 /* It's OK to base decisions on the section name, because none
10791 of the dynobj section names depend upon the input files. */
10792 name
= bfd_get_section_name (dynobj
, s
);
10794 if (strcmp (name
, ".plt") == 0)
10796 /* Remember whether there is a PLT. */
10797 plt
= s
->size
!= 0;
10799 else if (CONST_STRNEQ (name
, ".rel"))
10803 /* Remember whether there are any reloc sections other
10804 than .rel(a).plt and .rela.plt.unloaded. */
10805 if (s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
10808 /* We use the reloc_count field as a counter if we need
10809 to copy relocs into the output file. */
10810 s
->reloc_count
= 0;
10813 else if (! CONST_STRNEQ (name
, ".got")
10814 && strcmp (name
, ".dynbss") != 0)
10816 /* It's not one of our sections, so don't allocate space. */
10822 /* If we don't need this section, strip it from the
10823 output file. This is mostly to handle .rel(a).bss and
10824 .rel(a).plt. We must create both sections in
10825 create_dynamic_sections, because they must be created
10826 before the linker maps input sections to output
10827 sections. The linker does that before
10828 adjust_dynamic_symbol is called, and it is that
10829 function which decides whether anything needs to go
10830 into these sections. */
10831 s
->flags
|= SEC_EXCLUDE
;
10835 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10838 /* Allocate memory for the section contents. */
10839 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10840 if (s
->contents
== NULL
)
10844 if (elf_hash_table (info
)->dynamic_sections_created
)
10846 /* Add some entries to the .dynamic section. We fill in the
10847 values later, in elf32_arm_finish_dynamic_sections, but we
10848 must add the entries now so that we get the correct size for
10849 the .dynamic section. The DT_DEBUG entry is filled in by the
10850 dynamic linker and used by the debugger. */
10851 #define add_dynamic_entry(TAG, VAL) \
10852 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10854 if (info
->executable
)
10856 if (!add_dynamic_entry (DT_DEBUG
, 0))
10862 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
10863 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10864 || !add_dynamic_entry (DT_PLTREL
,
10865 htab
->use_rel
? DT_REL
: DT_RELA
)
10866 || !add_dynamic_entry (DT_JMPREL
, 0))
10874 if (!add_dynamic_entry (DT_REL
, 0)
10875 || !add_dynamic_entry (DT_RELSZ
, 0)
10876 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
10881 if (!add_dynamic_entry (DT_RELA
, 0)
10882 || !add_dynamic_entry (DT_RELASZ
, 0)
10883 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
10888 /* If any dynamic relocs apply to a read-only section,
10889 then we need a DT_TEXTREL entry. */
10890 if ((info
->flags
& DF_TEXTREL
) == 0)
10891 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
10894 if ((info
->flags
& DF_TEXTREL
) != 0)
10896 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10899 if (htab
->vxworks_p
10900 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
10903 #undef add_dynamic_entry
10908 /* Finish up dynamic symbol handling. We set the contents of various
10909 dynamic sections here. */
10912 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
10913 struct bfd_link_info
* info
,
10914 struct elf_link_hash_entry
* h
,
10915 Elf_Internal_Sym
* sym
)
10918 struct elf32_arm_link_hash_table
*htab
;
10919 struct elf32_arm_link_hash_entry
*eh
;
10921 dynobj
= elf_hash_table (info
)->dynobj
;
10922 htab
= elf32_arm_hash_table (info
);
10923 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10925 if (h
->plt
.offset
!= (bfd_vma
) -1)
10931 Elf_Internal_Rela rel
;
10933 /* This symbol has an entry in the procedure linkage table. Set
10936 BFD_ASSERT (h
->dynindx
!= -1);
10938 splt
= bfd_get_section_by_name (dynobj
, ".plt");
10939 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".plt"));
10940 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
10942 /* Fill in the entry in the procedure linkage table. */
10943 if (htab
->symbian_p
)
10945 put_arm_insn (htab
, output_bfd
,
10946 elf32_arm_symbian_plt_entry
[0],
10947 splt
->contents
+ h
->plt
.offset
);
10948 bfd_put_32 (output_bfd
,
10949 elf32_arm_symbian_plt_entry
[1],
10950 splt
->contents
+ h
->plt
.offset
+ 4);
10952 /* Fill in the entry in the .rel.plt section. */
10953 rel
.r_offset
= (splt
->output_section
->vma
10954 + splt
->output_offset
10955 + h
->plt
.offset
+ 4);
10956 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
10958 /* Get the index in the procedure linkage table which
10959 corresponds to this symbol. This is the index of this symbol
10960 in all the symbols for which we are making plt entries. The
10961 first entry in the procedure linkage table is reserved. */
10962 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
10963 / htab
->plt_entry_size
);
10967 bfd_vma got_offset
, got_address
, plt_address
;
10968 bfd_vma got_displacement
;
10972 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
10973 BFD_ASSERT (sgot
!= NULL
);
10975 /* Get the offset into the .got.plt table of the entry that
10976 corresponds to this function. */
10977 got_offset
= eh
->plt_got_offset
;
10979 /* Get the index in the procedure linkage table which
10980 corresponds to this symbol. This is the index of this symbol
10981 in all the symbols for which we are making plt entries. The
10982 first three entries in .got.plt are reserved; after that
10983 symbols appear in the same order as in .plt. */
10984 plt_index
= (got_offset
- 12) / 4;
10986 /* Calculate the address of the GOT entry. */
10987 got_address
= (sgot
->output_section
->vma
10988 + sgot
->output_offset
10991 /* ...and the address of the PLT entry. */
10992 plt_address
= (splt
->output_section
->vma
10993 + splt
->output_offset
10996 ptr
= htab
->splt
->contents
+ h
->plt
.offset
;
10997 if (htab
->vxworks_p
&& info
->shared
)
11002 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
11004 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
11006 val
|= got_address
- sgot
->output_section
->vma
;
11008 val
|= plt_index
* RELOC_SIZE (htab
);
11009 if (i
== 2 || i
== 5)
11010 bfd_put_32 (output_bfd
, val
, ptr
);
11012 put_arm_insn (htab
, output_bfd
, val
, ptr
);
11015 else if (htab
->vxworks_p
)
11020 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
11022 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
11024 val
|= got_address
;
11026 val
|= 0xffffff & -((h
->plt
.offset
+ i
* 4 + 8) >> 2);
11028 val
|= plt_index
* RELOC_SIZE (htab
);
11029 if (i
== 2 || i
== 5)
11030 bfd_put_32 (output_bfd
, val
, ptr
);
11032 put_arm_insn (htab
, output_bfd
, val
, ptr
);
11035 loc
= (htab
->srelplt2
->contents
11036 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
11038 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
11039 referencing the GOT for this PLT entry. */
11040 rel
.r_offset
= plt_address
+ 8;
11041 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
11042 rel
.r_addend
= got_offset
;
11043 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
11044 loc
+= RELOC_SIZE (htab
);
11046 /* Create the R_ARM_ABS32 relocation referencing the
11047 beginning of the PLT for this GOT entry. */
11048 rel
.r_offset
= got_address
;
11049 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
11051 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
11055 bfd_signed_vma thumb_refs
;
11056 /* Calculate the displacement between the PLT slot and the
11057 entry in the GOT. The eight-byte offset accounts for the
11058 value produced by adding to pc in the first instruction
11059 of the PLT stub. */
11060 got_displacement
= got_address
- (plt_address
+ 8);
11062 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
11064 thumb_refs
= eh
->plt_thumb_refcount
;
11065 if (!htab
->use_blx
)
11066 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
11068 if (thumb_refs
> 0)
11070 put_thumb_insn (htab
, output_bfd
,
11071 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
11072 put_thumb_insn (htab
, output_bfd
,
11073 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
11076 put_arm_insn (htab
, output_bfd
,
11077 elf32_arm_plt_entry
[0]
11078 | ((got_displacement
& 0x0ff00000) >> 20),
11080 put_arm_insn (htab
, output_bfd
,
11081 elf32_arm_plt_entry
[1]
11082 | ((got_displacement
& 0x000ff000) >> 12),
11084 put_arm_insn (htab
, output_bfd
,
11085 elf32_arm_plt_entry
[2]
11086 | (got_displacement
& 0x00000fff),
11088 #ifdef FOUR_WORD_PLT
11089 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
11093 /* Fill in the entry in the global offset table. */
11094 bfd_put_32 (output_bfd
,
11095 (splt
->output_section
->vma
11096 + splt
->output_offset
),
11097 sgot
->contents
+ got_offset
);
11099 /* Fill in the entry in the .rel(a).plt section. */
11101 rel
.r_offset
= got_address
;
11102 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
11105 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
11106 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
11108 if (!h
->def_regular
)
11110 /* Mark the symbol as undefined, rather than as defined in
11111 the .plt section. Leave the value alone. */
11112 sym
->st_shndx
= SHN_UNDEF
;
11113 /* If the symbol is weak, we do need to clear the value.
11114 Otherwise, the PLT entry would provide a definition for
11115 the symbol even if the symbol wasn't defined anywhere,
11116 and so the symbol would never be NULL. */
11117 if (!h
->ref_regular_nonweak
)
11122 if (h
->got
.offset
!= (bfd_vma
) -1
11123 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
11124 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
11128 Elf_Internal_Rela rel
;
11132 /* This symbol has an entry in the global offset table. Set it
11134 sgot
= bfd_get_section_by_name (dynobj
, ".got");
11135 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".got"));
11136 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
11138 offset
= (h
->got
.offset
& ~(bfd_vma
) 1);
11140 rel
.r_offset
= (sgot
->output_section
->vma
11141 + sgot
->output_offset
11144 /* If this is a static link, or it is a -Bsymbolic link and the
11145 symbol is defined locally or was forced to be local because
11146 of a version file, we just want to emit a RELATIVE reloc.
11147 The entry in the global offset table will already have been
11148 initialized in the relocate_section function. */
11150 && SYMBOL_REFERENCES_LOCAL (info
, h
))
11152 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
11153 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
11154 if (!htab
->use_rel
)
11156 rel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
11157 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
11162 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
11163 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
11164 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
11167 loc
= srel
->contents
+ srel
->reloc_count
++ * RELOC_SIZE (htab
);
11168 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
11174 Elf_Internal_Rela rel
;
11177 /* This symbol needs a copy reloc. Set it up. */
11178 BFD_ASSERT (h
->dynindx
!= -1
11179 && (h
->root
.type
== bfd_link_hash_defined
11180 || h
->root
.type
== bfd_link_hash_defweak
));
11182 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
11183 RELOC_SECTION (htab
, ".bss"));
11184 BFD_ASSERT (s
!= NULL
);
11187 rel
.r_offset
= (h
->root
.u
.def
.value
11188 + h
->root
.u
.def
.section
->output_section
->vma
11189 + h
->root
.u
.def
.section
->output_offset
);
11190 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
11191 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
11192 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
11195 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11196 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11197 to the ".got" section. */
11198 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
11199 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
11200 sym
->st_shndx
= SHN_ABS
;
11205 /* Finish up the dynamic sections. */
11208 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
11214 dynobj
= elf_hash_table (info
)->dynobj
;
11216 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
11217 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
11218 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
11220 if (elf_hash_table (info
)->dynamic_sections_created
)
11223 Elf32_External_Dyn
*dyncon
, *dynconend
;
11224 struct elf32_arm_link_hash_table
*htab
;
11226 htab
= elf32_arm_hash_table (info
);
11227 splt
= bfd_get_section_by_name (dynobj
, ".plt");
11228 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
11230 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
11231 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
11233 for (; dyncon
< dynconend
; dyncon
++)
11235 Elf_Internal_Dyn dyn
;
11239 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
11246 if (htab
->vxworks_p
11247 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
11248 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11253 goto get_vma_if_bpabi
;
11256 goto get_vma_if_bpabi
;
11259 goto get_vma_if_bpabi
;
11261 name
= ".gnu.version";
11262 goto get_vma_if_bpabi
;
11264 name
= ".gnu.version_d";
11265 goto get_vma_if_bpabi
;
11267 name
= ".gnu.version_r";
11268 goto get_vma_if_bpabi
;
11274 name
= RELOC_SECTION (htab
, ".plt");
11276 s
= bfd_get_section_by_name (output_bfd
, name
);
11277 BFD_ASSERT (s
!= NULL
);
11278 if (!htab
->symbian_p
)
11279 dyn
.d_un
.d_ptr
= s
->vma
;
11281 /* In the BPABI, tags in the PT_DYNAMIC section point
11282 at the file offset, not the memory address, for the
11283 convenience of the post linker. */
11284 dyn
.d_un
.d_ptr
= s
->filepos
;
11285 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11289 if (htab
->symbian_p
)
11294 s
= bfd_get_section_by_name (output_bfd
,
11295 RELOC_SECTION (htab
, ".plt"));
11296 BFD_ASSERT (s
!= NULL
);
11297 dyn
.d_un
.d_val
= s
->size
;
11298 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11303 if (!htab
->symbian_p
)
11305 /* My reading of the SVR4 ABI indicates that the
11306 procedure linkage table relocs (DT_JMPREL) should be
11307 included in the overall relocs (DT_REL). This is
11308 what Solaris does. However, UnixWare can not handle
11309 that case. Therefore, we override the DT_RELSZ entry
11310 here to make it not include the JMPREL relocs. Since
11311 the linker script arranges for .rel(a).plt to follow all
11312 other relocation sections, we don't have to worry
11313 about changing the DT_REL entry. */
11314 s
= bfd_get_section_by_name (output_bfd
,
11315 RELOC_SECTION (htab
, ".plt"));
11317 dyn
.d_un
.d_val
-= s
->size
;
11318 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11321 /* Fall through. */
11325 /* In the BPABI, the DT_REL tag must point at the file
11326 offset, not the VMA, of the first relocation
11327 section. So, we use code similar to that in
11328 elflink.c, but do not check for SHF_ALLOC on the
11329 relcoation section, since relocations sections are
11330 never allocated under the BPABI. The comments above
11331 about Unixware notwithstanding, we include all of the
11332 relocations here. */
11333 if (htab
->symbian_p
)
11336 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
11337 ? SHT_REL
: SHT_RELA
);
11338 dyn
.d_un
.d_val
= 0;
11339 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
11341 Elf_Internal_Shdr
*hdr
11342 = elf_elfsections (output_bfd
)[i
];
11343 if (hdr
->sh_type
== type
)
11345 if (dyn
.d_tag
== DT_RELSZ
11346 || dyn
.d_tag
== DT_RELASZ
)
11347 dyn
.d_un
.d_val
+= hdr
->sh_size
;
11348 else if ((ufile_ptr
) hdr
->sh_offset
11349 <= dyn
.d_un
.d_val
- 1)
11350 dyn
.d_un
.d_val
= hdr
->sh_offset
;
11353 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11357 /* Set the bottom bit of DT_INIT/FINI if the
11358 corresponding function is Thumb. */
11360 name
= info
->init_function
;
11363 name
= info
->fini_function
;
11365 /* If it wasn't set by elf_bfd_final_link
11366 then there is nothing to adjust. */
11367 if (dyn
.d_un
.d_val
!= 0)
11369 struct elf_link_hash_entry
* eh
;
11371 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
11372 FALSE
, FALSE
, TRUE
);
11374 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
11376 dyn
.d_un
.d_val
|= 1;
11377 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11384 /* Fill in the first entry in the procedure linkage table. */
11385 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
11387 const bfd_vma
*plt0_entry
;
11388 bfd_vma got_address
, plt_address
, got_displacement
;
11390 /* Calculate the addresses of the GOT and PLT. */
11391 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
11392 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
11394 if (htab
->vxworks_p
)
11396 /* The VxWorks GOT is relocated by the dynamic linker.
11397 Therefore, we must emit relocations rather than simply
11398 computing the values now. */
11399 Elf_Internal_Rela rel
;
11401 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
11402 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
11403 splt
->contents
+ 0);
11404 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
11405 splt
->contents
+ 4);
11406 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
11407 splt
->contents
+ 8);
11408 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
11410 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
11411 rel
.r_offset
= plt_address
+ 12;
11412 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
11414 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
11415 htab
->srelplt2
->contents
);
11419 got_displacement
= got_address
- (plt_address
+ 16);
11421 plt0_entry
= elf32_arm_plt0_entry
;
11422 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
11423 splt
->contents
+ 0);
11424 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
11425 splt
->contents
+ 4);
11426 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
11427 splt
->contents
+ 8);
11428 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
11429 splt
->contents
+ 12);
11431 #ifdef FOUR_WORD_PLT
11432 /* The displacement value goes in the otherwise-unused
11433 last word of the second entry. */
11434 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
11436 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
11441 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11442 really seem like the right value. */
11443 if (splt
->output_section
->owner
== output_bfd
)
11444 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
11446 if (htab
->vxworks_p
&& !info
->shared
&& htab
->splt
->size
> 0)
11448 /* Correct the .rel(a).plt.unloaded relocations. They will have
11449 incorrect symbol indexes. */
11453 num_plts
= ((htab
->splt
->size
- htab
->plt_header_size
)
11454 / htab
->plt_entry_size
);
11455 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
11457 for (; num_plts
; num_plts
--)
11459 Elf_Internal_Rela rel
;
11461 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
11462 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
11463 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
11464 p
+= RELOC_SIZE (htab
);
11466 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
11467 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
11468 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
11469 p
+= RELOC_SIZE (htab
);
11474 /* Fill in the first three entries in the global offset table. */
11477 if (sgot
->size
> 0)
11480 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
11482 bfd_put_32 (output_bfd
,
11483 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
11485 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
11486 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
11489 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
11496 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
11498 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
11499 struct elf32_arm_link_hash_table
*globals
;
11501 i_ehdrp
= elf_elfheader (abfd
);
11503 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
11504 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
11506 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
11507 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
11511 globals
= elf32_arm_hash_table (link_info
);
11512 if (globals
->byteswap_code
)
11513 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
11517 static enum elf_reloc_type_class
11518 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
11520 switch ((int) ELF32_R_TYPE (rela
->r_info
))
11522 case R_ARM_RELATIVE
:
11523 return reloc_class_relative
;
11524 case R_ARM_JUMP_SLOT
:
11525 return reloc_class_plt
;
11527 return reloc_class_copy
;
11529 return reloc_class_normal
;
11533 /* Set the right machine number for an Arm ELF file. */
11536 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
11538 if (hdr
->sh_type
== SHT_NOTE
)
11539 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
11545 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
11547 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
11550 /* Return TRUE if this is an unwinding table entry. */
11553 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
11555 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
11556 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
11560 /* Set the type and flags for an ARM section. We do this by
11561 the section name, which is a hack, but ought to work. */
11564 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
11568 name
= bfd_get_section_name (abfd
, sec
);
11570 if (is_arm_elf_unwind_section_name (abfd
, name
))
11572 hdr
->sh_type
= SHT_ARM_EXIDX
;
11573 hdr
->sh_flags
|= SHF_LINK_ORDER
;
11578 /* Handle an ARM specific section when reading an object file. This is
11579 called when bfd_section_from_shdr finds a section with an unknown
11583 elf32_arm_section_from_shdr (bfd
*abfd
,
11584 Elf_Internal_Shdr
* hdr
,
11588 /* There ought to be a place to keep ELF backend specific flags, but
11589 at the moment there isn't one. We just keep track of the
11590 sections by their name, instead. Fortunately, the ABI gives
11591 names for all the ARM specific sections, so we will probably get
11593 switch (hdr
->sh_type
)
11595 case SHT_ARM_EXIDX
:
11596 case SHT_ARM_PREEMPTMAP
:
11597 case SHT_ARM_ATTRIBUTES
:
11604 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
11610 /* A structure used to record a list of sections, independently
11611 of the next and prev fields in the asection structure. */
11612 typedef struct section_list
11615 struct section_list
* next
;
11616 struct section_list
* prev
;
11620 /* Unfortunately we need to keep a list of sections for which
11621 an _arm_elf_section_data structure has been allocated. This
11622 is because it is possible for functions like elf32_arm_write_section
11623 to be called on a section which has had an elf_data_structure
11624 allocated for it (and so the used_by_bfd field is valid) but
11625 for which the ARM extended version of this structure - the
11626 _arm_elf_section_data structure - has not been allocated. */
11627 static section_list
* sections_with_arm_elf_section_data
= NULL
;
11630 record_section_with_arm_elf_section_data (asection
* sec
)
11632 struct section_list
* entry
;
11634 entry
= bfd_malloc (sizeof (* entry
));
11638 entry
->next
= sections_with_arm_elf_section_data
;
11639 entry
->prev
= NULL
;
11640 if (entry
->next
!= NULL
)
11641 entry
->next
->prev
= entry
;
11642 sections_with_arm_elf_section_data
= entry
;
11645 static struct section_list
*
11646 find_arm_elf_section_entry (asection
* sec
)
11648 struct section_list
* entry
;
11649 static struct section_list
* last_entry
= NULL
;
11651 /* This is a short cut for the typical case where the sections are added
11652 to the sections_with_arm_elf_section_data list in forward order and
11653 then looked up here in backwards order. This makes a real difference
11654 to the ld-srec/sec64k.exp linker test. */
11655 entry
= sections_with_arm_elf_section_data
;
11656 if (last_entry
!= NULL
)
11658 if (last_entry
->sec
== sec
)
11659 entry
= last_entry
;
11660 else if (last_entry
->next
!= NULL
11661 && last_entry
->next
->sec
== sec
)
11662 entry
= last_entry
->next
;
11665 for (; entry
; entry
= entry
->next
)
11666 if (entry
->sec
== sec
)
11670 /* Record the entry prior to this one - it is the entry we are most
11671 likely to want to locate next time. Also this way if we have been
11672 called from unrecord_section_with_arm_elf_section_data() we will not
11673 be caching a pointer that is about to be freed. */
11674 last_entry
= entry
->prev
;
11679 static _arm_elf_section_data
*
11680 get_arm_elf_section_data (asection
* sec
)
11682 struct section_list
* entry
;
11684 entry
= find_arm_elf_section_entry (sec
);
11687 return elf32_arm_section_data (entry
->sec
);
11693 unrecord_section_with_arm_elf_section_data (asection
* sec
)
11695 struct section_list
* entry
;
11697 entry
= find_arm_elf_section_entry (sec
);
11701 if (entry
->prev
!= NULL
)
11702 entry
->prev
->next
= entry
->next
;
11703 if (entry
->next
!= NULL
)
11704 entry
->next
->prev
= entry
->prev
;
11705 if (entry
== sections_with_arm_elf_section_data
)
11706 sections_with_arm_elf_section_data
= entry
->next
;
11715 struct bfd_link_info
*info
;
11718 bfd_boolean (*func
) (void *, const char *, Elf_Internal_Sym
*,
11719 asection
*, struct elf_link_hash_entry
*);
11720 } output_arch_syminfo
;
11722 enum map_symbol_type
11730 /* Output a single mapping symbol. */
11733 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
11734 enum map_symbol_type type
,
11737 static const char *names
[3] = {"$a", "$t", "$d"};
11738 struct elf32_arm_link_hash_table
*htab
;
11739 Elf_Internal_Sym sym
;
11741 htab
= elf32_arm_hash_table (osi
->info
);
11742 sym
.st_value
= osi
->sec
->output_section
->vma
11743 + osi
->sec
->output_offset
11747 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
11748 sym
.st_shndx
= osi
->sec_shndx
;
11749 if (!osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
))
11755 /* Output mapping symbols for PLT entries associated with H. */
11758 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
11760 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
11761 struct elf32_arm_link_hash_table
*htab
;
11762 struct elf32_arm_link_hash_entry
*eh
;
11765 htab
= elf32_arm_hash_table (osi
->info
);
11767 if (h
->root
.type
== bfd_link_hash_indirect
)
11770 if (h
->root
.type
== bfd_link_hash_warning
)
11771 /* When warning symbols are created, they **replace** the "real"
11772 entry in the hash table, thus we never get to see the real
11773 symbol in a hash traversal. So look at it now. */
11774 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11776 if (h
->plt
.offset
== (bfd_vma
) -1)
11779 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11780 addr
= h
->plt
.offset
;
11781 if (htab
->symbian_p
)
11783 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11785 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
11788 else if (htab
->vxworks_p
)
11790 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11792 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
11794 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
11796 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
11801 bfd_signed_vma thumb_refs
;
11803 thumb_refs
= eh
->plt_thumb_refcount
;
11804 if (!htab
->use_blx
)
11805 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
11807 if (thumb_refs
> 0)
11809 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
11812 #ifdef FOUR_WORD_PLT
11813 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11815 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
11818 /* A three-word PLT with no Thumb thunk contains only Arm code,
11819 so only need to output a mapping symbol for the first PLT entry and
11820 entries with thumb thunks. */
11821 if (thumb_refs
> 0 || addr
== 20)
11823 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11832 /* Output a single local symbol for a generated stub. */
11835 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
11836 bfd_vma offset
, bfd_vma size
)
11838 struct elf32_arm_link_hash_table
*htab
;
11839 Elf_Internal_Sym sym
;
11841 htab
= elf32_arm_hash_table (osi
->info
);
11842 sym
.st_value
= osi
->sec
->output_section
->vma
11843 + osi
->sec
->output_offset
11845 sym
.st_size
= size
;
11847 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
11848 sym
.st_shndx
= osi
->sec_shndx
;
11849 if (!osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
))
11855 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
11858 struct elf32_arm_stub_hash_entry
*stub_entry
;
11859 struct bfd_link_info
*info
;
11860 struct elf32_arm_link_hash_table
*htab
;
11861 asection
*stub_sec
;
11864 output_arch_syminfo
*osi
;
11865 const insn_sequence
*template;
11866 enum stub_insn_type prev_type
;
11869 enum map_symbol_type sym_type
;
11871 /* Massage our args to the form they really have. */
11872 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
11873 osi
= (output_arch_syminfo
*) in_arg
;
11877 htab
= elf32_arm_hash_table (info
);
11878 stub_sec
= stub_entry
->stub_sec
;
11880 /* Ensure this stub is attached to the current section being
11882 if (stub_sec
!= osi
->sec
)
11885 addr
= (bfd_vma
) stub_entry
->stub_offset
;
11886 stub_name
= stub_entry
->output_name
;
11888 template = stub_entry
->stub_template
;
11889 switch (template[0].type
)
11892 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, stub_entry
->stub_size
))
11896 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
11897 stub_entry
->stub_size
))
11905 prev_type
= DATA_TYPE
;
11907 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
11909 switch (template[i
].type
)
11912 sym_type
= ARM_MAP_ARM
;
11916 sym_type
= ARM_MAP_THUMB
;
11920 sym_type
= ARM_MAP_DATA
;
11928 if (template[i
].type
!= prev_type
)
11930 prev_type
= template[i
].type
;
11931 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
11935 switch (template[i
].type
)
11958 /* Output mapping symbols for linker generated sections. */
11961 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
11962 struct bfd_link_info
*info
,
11964 bfd_boolean (*func
) (void *, const char *,
11965 Elf_Internal_Sym
*,
11967 struct elf_link_hash_entry
*))
11969 output_arch_syminfo osi
;
11970 struct elf32_arm_link_hash_table
*htab
;
11972 bfd_size_type size
;
11974 htab
= elf32_arm_hash_table (info
);
11975 check_use_blx (htab
);
11981 /* ARM->Thumb glue. */
11982 if (htab
->arm_glue_size
> 0)
11984 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
11985 ARM2THUMB_GLUE_SECTION_NAME
);
11987 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
11988 (output_bfd
, osi
.sec
->output_section
);
11989 if (info
->shared
|| htab
->root
.is_relocatable_executable
11990 || htab
->pic_veneer
)
11991 size
= ARM2THUMB_PIC_GLUE_SIZE
;
11992 else if (htab
->use_blx
)
11993 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
11995 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
11997 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
11999 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
12000 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
12004 /* Thumb->ARM glue. */
12005 if (htab
->thumb_glue_size
> 0)
12007 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
12008 THUMB2ARM_GLUE_SECTION_NAME
);
12010 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12011 (output_bfd
, osi
.sec
->output_section
);
12012 size
= THUMB2ARM_GLUE_SIZE
;
12014 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
12016 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
12017 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
12021 /* ARMv4 BX veneers. */
12022 if (htab
->bx_glue_size
> 0)
12024 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
12025 ARM_BX_GLUE_SECTION_NAME
);
12027 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12028 (output_bfd
, osi
.sec
->output_section
);
12030 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
12033 /* Long calls stubs. */
12034 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
12036 asection
* stub_sec
;
12038 for (stub_sec
= htab
->stub_bfd
->sections
;
12040 stub_sec
= stub_sec
->next
)
12042 /* Ignore non-stub sections. */
12043 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
12046 osi
.sec
= stub_sec
;
12048 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12049 (output_bfd
, osi
.sec
->output_section
);
12051 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
12055 /* Finally, output mapping symbols for the PLT. */
12056 if (!htab
->splt
|| htab
->splt
->size
== 0)
12059 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
12060 htab
->splt
->output_section
);
12061 osi
.sec
= htab
->splt
;
12062 /* Output mapping symbols for the plt header. SymbianOS does not have a
12064 if (htab
->vxworks_p
)
12066 /* VxWorks shared libraries have no PLT header. */
12069 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
12071 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
12075 else if (!htab
->symbian_p
)
12077 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
12079 #ifndef FOUR_WORD_PLT
12080 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
12085 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, (void *) &osi
);
12089 /* Allocate target specific section data. */
12092 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
12094 if (!sec
->used_by_bfd
)
12096 _arm_elf_section_data
*sdata
;
12097 bfd_size_type amt
= sizeof (*sdata
);
12099 sdata
= bfd_zalloc (abfd
, amt
);
12102 sec
->used_by_bfd
= sdata
;
12105 record_section_with_arm_elf_section_data (sec
);
12107 return _bfd_elf_new_section_hook (abfd
, sec
);
12111 /* Used to order a list of mapping symbols by address. */
12114 elf32_arm_compare_mapping (const void * a
, const void * b
)
12116 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
12117 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
12119 if (amap
->vma
> bmap
->vma
)
12121 else if (amap
->vma
< bmap
->vma
)
12123 else if (amap
->type
> bmap
->type
)
12124 /* Ensure results do not depend on the host qsort for objects with
12125 multiple mapping symbols at the same address by sorting on type
12128 else if (amap
->type
< bmap
->type
)
12135 /* Do code byteswapping. Return FALSE afterwards so that the section is
12136 written out as normal. */
12139 elf32_arm_write_section (bfd
*output_bfd
,
12140 struct bfd_link_info
*link_info
,
12142 bfd_byte
*contents
)
12144 int mapcount
, errcount
;
12145 _arm_elf_section_data
*arm_data
;
12146 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
12147 elf32_arm_section_map
*map
;
12148 elf32_vfp11_erratum_list
*errnode
;
12151 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
12155 /* If this section has not been allocated an _arm_elf_section_data
12156 structure then we cannot record anything. */
12157 arm_data
= get_arm_elf_section_data (sec
);
12158 if (arm_data
== NULL
)
12161 mapcount
= arm_data
->mapcount
;
12162 map
= arm_data
->map
;
12163 errcount
= arm_data
->erratumcount
;
12167 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
12169 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
12170 errnode
= errnode
->next
)
12172 bfd_vma index
= errnode
->vma
- offset
;
12174 switch (errnode
->type
)
12176 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
12178 bfd_vma branch_to_veneer
;
12179 /* Original condition code of instruction, plus bit mask for
12180 ARM B instruction. */
12181 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
12184 /* The instruction is before the label. */
12187 /* Above offset included in -4 below. */
12188 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
12189 - errnode
->vma
- 4;
12191 if ((signed) branch_to_veneer
< -(1 << 25)
12192 || (signed) branch_to_veneer
>= (1 << 25))
12193 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
12194 "range"), output_bfd
);
12196 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
12197 contents
[endianflip
^ index
] = insn
& 0xff;
12198 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
12199 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
12200 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
12204 case VFP11_ERRATUM_ARM_VENEER
:
12206 bfd_vma branch_from_veneer
;
12209 /* Take size of veneer into account. */
12210 branch_from_veneer
= errnode
->u
.v
.branch
->vma
12211 - errnode
->vma
- 12;
12213 if ((signed) branch_from_veneer
< -(1 << 25)
12214 || (signed) branch_from_veneer
>= (1 << 25))
12215 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
12216 "range"), output_bfd
);
12218 /* Original instruction. */
12219 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
12220 contents
[endianflip
^ index
] = insn
& 0xff;
12221 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
12222 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
12223 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
12225 /* Branch back to insn after original insn. */
12226 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
12227 contents
[endianflip
^ (index
+ 4)] = insn
& 0xff;
12228 contents
[endianflip
^ (index
+ 5)] = (insn
>> 8) & 0xff;
12229 contents
[endianflip
^ (index
+ 6)] = (insn
>> 16) & 0xff;
12230 contents
[endianflip
^ (index
+ 7)] = (insn
>> 24) & 0xff;
12243 if (globals
->byteswap_code
)
12245 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
12248 for (i
= 0; i
< mapcount
; i
++)
12250 if (i
== mapcount
- 1)
12253 end
= map
[i
+ 1].vma
;
12255 switch (map
[i
].type
)
12258 /* Byte swap code words. */
12259 while (ptr
+ 3 < end
)
12261 tmp
= contents
[ptr
];
12262 contents
[ptr
] = contents
[ptr
+ 3];
12263 contents
[ptr
+ 3] = tmp
;
12264 tmp
= contents
[ptr
+ 1];
12265 contents
[ptr
+ 1] = contents
[ptr
+ 2];
12266 contents
[ptr
+ 2] = tmp
;
12272 /* Byte swap code halfwords. */
12273 while (ptr
+ 1 < end
)
12275 tmp
= contents
[ptr
];
12276 contents
[ptr
] = contents
[ptr
+ 1];
12277 contents
[ptr
+ 1] = tmp
;
12283 /* Leave data alone. */
12291 arm_data
->mapcount
= 0;
12292 arm_data
->mapsize
= 0;
12293 arm_data
->map
= NULL
;
12294 unrecord_section_with_arm_elf_section_data (sec
);
12300 unrecord_section_via_map_over_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
12302 void * ignore ATTRIBUTE_UNUSED
)
12304 unrecord_section_with_arm_elf_section_data (sec
);
12308 elf32_arm_close_and_cleanup (bfd
* abfd
)
12310 if (abfd
->sections
)
12311 bfd_map_over_sections (abfd
,
12312 unrecord_section_via_map_over_sections
,
12315 return _bfd_elf_close_and_cleanup (abfd
);
12319 elf32_arm_bfd_free_cached_info (bfd
* abfd
)
12321 if (abfd
->sections
)
12322 bfd_map_over_sections (abfd
,
12323 unrecord_section_via_map_over_sections
,
12326 return _bfd_free_cached_info (abfd
);
12329 /* Display STT_ARM_TFUNC symbols as functions. */
12332 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
12335 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
12337 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
12338 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
12342 /* Mangle thumb function symbols as we read them in. */
12345 elf32_arm_swap_symbol_in (bfd
* abfd
,
12348 Elf_Internal_Sym
*dst
)
12350 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
12353 /* New EABI objects mark thumb function symbols by setting the low bit of
12354 the address. Turn these into STT_ARM_TFUNC. */
12355 if ((ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
)
12356 && (dst
->st_value
& 1))
12358 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
12359 dst
->st_value
&= ~(bfd_vma
) 1;
12365 /* Mangle thumb function symbols as we write them out. */
12368 elf32_arm_swap_symbol_out (bfd
*abfd
,
12369 const Elf_Internal_Sym
*src
,
12373 Elf_Internal_Sym newsym
;
12375 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12376 of the address set, as per the new EABI. We do this unconditionally
12377 because objcopy does not set the elf header flags until after
12378 it writes out the symbol table. */
12379 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
12382 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
12383 if (newsym
.st_shndx
!= SHN_UNDEF
)
12385 /* Do this only for defined symbols. At link type, the static
12386 linker will simulate the work of dynamic linker of resolving
12387 symbols and will carry over the thumbness of found symbols to
12388 the output symbol table. It's not clear how it happens, but
12389 the thumbness of undefined symbols can well be different at
12390 runtime, and writing '1' for them will be confusing for users
12391 and possibly for dynamic linker itself.
12393 newsym
.st_value
|= 1;
12398 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
12401 /* Add the PT_ARM_EXIDX program header. */
12404 elf32_arm_modify_segment_map (bfd
*abfd
,
12405 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
12407 struct elf_segment_map
*m
;
12410 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
12411 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
12413 /* If there is already a PT_ARM_EXIDX header, then we do not
12414 want to add another one. This situation arises when running
12415 "strip"; the input binary already has the header. */
12416 m
= elf_tdata (abfd
)->segment_map
;
12417 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
12421 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
12424 m
->p_type
= PT_ARM_EXIDX
;
12426 m
->sections
[0] = sec
;
12428 m
->next
= elf_tdata (abfd
)->segment_map
;
12429 elf_tdata (abfd
)->segment_map
= m
;
12436 /* We may add a PT_ARM_EXIDX program header. */
12439 elf32_arm_additional_program_headers (bfd
*abfd
,
12440 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
12444 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
12445 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
12451 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
12454 elf32_arm_is_function_type (unsigned int type
)
12456 return (type
== STT_FUNC
) || (type
== STT_ARM_TFUNC
);
12459 /* We use this to override swap_symbol_in and swap_symbol_out. */
12460 const struct elf_size_info elf32_arm_size_info
=
12462 sizeof (Elf32_External_Ehdr
),
12463 sizeof (Elf32_External_Phdr
),
12464 sizeof (Elf32_External_Shdr
),
12465 sizeof (Elf32_External_Rel
),
12466 sizeof (Elf32_External_Rela
),
12467 sizeof (Elf32_External_Sym
),
12468 sizeof (Elf32_External_Dyn
),
12469 sizeof (Elf_External_Note
),
12473 ELFCLASS32
, EV_CURRENT
,
12474 bfd_elf32_write_out_phdrs
,
12475 bfd_elf32_write_shdrs_and_ehdr
,
12476 bfd_elf32_checksum_contents
,
12477 bfd_elf32_write_relocs
,
12478 elf32_arm_swap_symbol_in
,
12479 elf32_arm_swap_symbol_out
,
12480 bfd_elf32_slurp_reloc_table
,
12481 bfd_elf32_slurp_symbol_table
,
12482 bfd_elf32_swap_dyn_in
,
12483 bfd_elf32_swap_dyn_out
,
12484 bfd_elf32_swap_reloc_in
,
12485 bfd_elf32_swap_reloc_out
,
12486 bfd_elf32_swap_reloca_in
,
12487 bfd_elf32_swap_reloca_out
12490 #define ELF_ARCH bfd_arch_arm
12491 #define ELF_MACHINE_CODE EM_ARM
12492 #ifdef __QNXTARGET__
12493 #define ELF_MAXPAGESIZE 0x1000
12495 #define ELF_MAXPAGESIZE 0x8000
12497 #define ELF_MINPAGESIZE 0x1000
12498 #define ELF_COMMONPAGESIZE 0x1000
12500 #define bfd_elf32_mkobject elf32_arm_mkobject
12502 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12503 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
12504 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12505 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12506 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
12507 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
12508 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
12509 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
12510 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
12511 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
12512 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
12513 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
12514 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
12515 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
12516 #define bfd_elf32_bfd_final_link elf32_arm_final_link
12518 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12519 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
12520 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
12521 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12522 #define elf_backend_check_relocs elf32_arm_check_relocs
12523 #define elf_backend_relocate_section elf32_arm_relocate_section
12524 #define elf_backend_write_section elf32_arm_write_section
12525 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
12526 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
12527 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12528 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12529 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
12530 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
12531 #define elf_backend_post_process_headers elf32_arm_post_process_headers
12532 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
12533 #define elf_backend_object_p elf32_arm_object_p
12534 #define elf_backend_section_flags elf32_arm_section_flags
12535 #define elf_backend_fake_sections elf32_arm_fake_sections
12536 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
12537 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12538 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
12539 #define elf_backend_symbol_processing elf32_arm_symbol_processing
12540 #define elf_backend_size_info elf32_arm_size_info
12541 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
12542 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12543 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12544 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12545 #define elf_backend_is_function_type elf32_arm_is_function_type
12547 #define elf_backend_can_refcount 1
12548 #define elf_backend_can_gc_sections 1
12549 #define elf_backend_plt_readonly 1
12550 #define elf_backend_want_got_plt 1
12551 #define elf_backend_want_plt_sym 0
12552 #define elf_backend_may_use_rel_p 1
12553 #define elf_backend_may_use_rela_p 0
12554 #define elf_backend_default_use_rela_p 0
12556 #define elf_backend_got_header_size 12
12558 #undef elf_backend_obj_attrs_vendor
12559 #define elf_backend_obj_attrs_vendor "aeabi"
12560 #undef elf_backend_obj_attrs_section
12561 #define elf_backend_obj_attrs_section ".ARM.attributes"
12562 #undef elf_backend_obj_attrs_arg_type
12563 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12564 #undef elf_backend_obj_attrs_section_type
12565 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
12566 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
12568 #include "elf32-target.h"
12570 /* VxWorks Targets. */
12572 #undef TARGET_LITTLE_SYM
12573 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
12574 #undef TARGET_LITTLE_NAME
12575 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
12576 #undef TARGET_BIG_SYM
12577 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
12578 #undef TARGET_BIG_NAME
12579 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12581 /* Like elf32_arm_link_hash_table_create -- but overrides
12582 appropriately for VxWorks. */
12584 static struct bfd_link_hash_table
*
12585 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
12587 struct bfd_link_hash_table
*ret
;
12589 ret
= elf32_arm_link_hash_table_create (abfd
);
12592 struct elf32_arm_link_hash_table
*htab
12593 = (struct elf32_arm_link_hash_table
*) ret
;
12595 htab
->vxworks_p
= 1;
12601 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
12603 elf32_arm_final_write_processing (abfd
, linker
);
12604 elf_vxworks_final_write_processing (abfd
, linker
);
12608 #define elf32_bed elf32_arm_vxworks_bed
12610 #undef bfd_elf32_bfd_link_hash_table_create
12611 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12612 #undef elf_backend_add_symbol_hook
12613 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12614 #undef elf_backend_final_write_processing
12615 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12616 #undef elf_backend_emit_relocs
12617 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
12619 #undef elf_backend_may_use_rel_p
12620 #define elf_backend_may_use_rel_p 0
12621 #undef elf_backend_may_use_rela_p
12622 #define elf_backend_may_use_rela_p 1
12623 #undef elf_backend_default_use_rela_p
12624 #define elf_backend_default_use_rela_p 1
12625 #undef elf_backend_want_plt_sym
12626 #define elf_backend_want_plt_sym 1
12627 #undef ELF_MAXPAGESIZE
12628 #define ELF_MAXPAGESIZE 0x1000
12630 #include "elf32-target.h"
12633 /* Symbian OS Targets. */
12635 #undef TARGET_LITTLE_SYM
12636 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
12637 #undef TARGET_LITTLE_NAME
12638 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
12639 #undef TARGET_BIG_SYM
12640 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
12641 #undef TARGET_BIG_NAME
12642 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
12644 /* Like elf32_arm_link_hash_table_create -- but overrides
12645 appropriately for Symbian OS. */
12647 static struct bfd_link_hash_table
*
12648 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
12650 struct bfd_link_hash_table
*ret
;
12652 ret
= elf32_arm_link_hash_table_create (abfd
);
12655 struct elf32_arm_link_hash_table
*htab
12656 = (struct elf32_arm_link_hash_table
*)ret
;
12657 /* There is no PLT header for Symbian OS. */
12658 htab
->plt_header_size
= 0;
12659 /* The PLT entries are each one instruction and one word. */
12660 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
12661 htab
->symbian_p
= 1;
12662 /* Symbian uses armv5t or above, so use_blx is always true. */
12664 htab
->root
.is_relocatable_executable
= 1;
12669 static const struct bfd_elf_special_section
12670 elf32_arm_symbian_special_sections
[] =
12672 /* In a BPABI executable, the dynamic linking sections do not go in
12673 the loadable read-only segment. The post-linker may wish to
12674 refer to these sections, but they are not part of the final
12676 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
12677 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
12678 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
12679 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
12680 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
12681 /* These sections do not need to be writable as the SymbianOS
12682 postlinker will arrange things so that no dynamic relocation is
12684 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
12685 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
12686 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
12687 { NULL
, 0, 0, 0, 0 }
12691 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
12692 struct bfd_link_info
*link_info
)
12694 /* BPABI objects are never loaded directly by an OS kernel; they are
12695 processed by a postlinker first, into an OS-specific format. If
12696 the D_PAGED bit is set on the file, BFD will align segments on
12697 page boundaries, so that an OS can directly map the file. With
12698 BPABI objects, that just results in wasted space. In addition,
12699 because we clear the D_PAGED bit, map_sections_to_segments will
12700 recognize that the program headers should not be mapped into any
12701 loadable segment. */
12702 abfd
->flags
&= ~D_PAGED
;
12703 elf32_arm_begin_write_processing (abfd
, link_info
);
12707 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
12708 struct bfd_link_info
*info
)
12710 struct elf_segment_map
*m
;
12713 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12714 segment. However, because the .dynamic section is not marked
12715 with SEC_LOAD, the generic ELF code will not create such a
12717 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
12720 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
12721 if (m
->p_type
== PT_DYNAMIC
)
12726 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
12727 m
->next
= elf_tdata (abfd
)->segment_map
;
12728 elf_tdata (abfd
)->segment_map
= m
;
12732 /* Also call the generic arm routine. */
12733 return elf32_arm_modify_segment_map (abfd
, info
);
12736 /* Return address for Ith PLT stub in section PLT, for relocation REL
12737 or (bfd_vma) -1 if it should not be included. */
12740 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
12741 const arelent
*rel ATTRIBUTE_UNUSED
)
12743 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
12748 #define elf32_bed elf32_arm_symbian_bed
12750 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12751 will process them and then discard them. */
12752 #undef ELF_DYNAMIC_SEC_FLAGS
12753 #define ELF_DYNAMIC_SEC_FLAGS \
12754 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12756 #undef elf_backend_add_symbol_hook
12757 #undef elf_backend_emit_relocs
12759 #undef bfd_elf32_bfd_link_hash_table_create
12760 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12761 #undef elf_backend_special_sections
12762 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12763 #undef elf_backend_begin_write_processing
12764 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12765 #undef elf_backend_final_write_processing
12766 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12768 #undef elf_backend_modify_segment_map
12769 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12771 /* There is no .got section for BPABI objects, and hence no header. */
12772 #undef elf_backend_got_header_size
12773 #define elf_backend_got_header_size 0
12775 /* Similarly, there is no .got.plt section. */
12776 #undef elf_backend_want_got_plt
12777 #define elf_backend_want_got_plt 0
12779 #undef elf_backend_plt_sym_val
12780 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12782 #undef elf_backend_may_use_rel_p
12783 #define elf_backend_may_use_rel_p 1
12784 #undef elf_backend_may_use_rela_p
12785 #define elf_backend_may_use_rela_p 0
12786 #undef elf_backend_default_use_rela_p
12787 #define elf_backend_default_use_rela_p 0
12788 #undef elf_backend_want_plt_sym
12789 #define elf_backend_want_plt_sym 0
12790 #undef ELF_MAXPAGESIZE
12791 #define ELF_MAXPAGESIZE 0x8000
12793 #include "elf32-target.h"