1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
26 #include "libiberty.h"
29 #include "elf-vxworks.h"
32 /* Return the relocation section associated with NAME. HTAB is the
33 bfd's elf32_arm_link_hash_entry. */
34 #define RELOC_SECTION(HTAB, NAME) \
35 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
37 /* Return size of a relocation entry. HTAB is the bfd's
38 elf32_arm_link_hash_entry. */
39 #define RELOC_SIZE(HTAB) \
41 ? sizeof (Elf32_External_Rel) \
42 : sizeof (Elf32_External_Rela))
44 /* Return function to swap relocations in. HTAB is the bfd's
45 elf32_arm_link_hash_entry. */
46 #define SWAP_RELOC_IN(HTAB) \
48 ? bfd_elf32_swap_reloc_in \
49 : bfd_elf32_swap_reloca_in)
51 /* Return function to swap relocations out. HTAB is the bfd's
52 elf32_arm_link_hash_entry. */
53 #define SWAP_RELOC_OUT(HTAB) \
55 ? bfd_elf32_swap_reloc_out \
56 : bfd_elf32_swap_reloca_out)
58 #define elf_info_to_howto 0
59 #define elf_info_to_howto_rel elf32_arm_info_to_howto
61 #define ARM_ELF_ABI_VERSION 0
62 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
64 static struct elf_backend_data elf32_arm_vxworks_bed
;
66 static bfd_boolean
elf32_arm_write_section (bfd
*output_bfd
,
67 struct bfd_link_info
*link_info
,
71 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
72 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
75 static reloc_howto_type elf32_arm_howto_table_1
[] =
78 HOWTO (R_ARM_NONE
, /* type */
80 0, /* size (0 = byte, 1 = short, 2 = long) */
82 FALSE
, /* pc_relative */
84 complain_overflow_dont
,/* complain_on_overflow */
85 bfd_elf_generic_reloc
, /* special_function */
86 "R_ARM_NONE", /* name */
87 FALSE
, /* partial_inplace */
90 FALSE
), /* pcrel_offset */
92 HOWTO (R_ARM_PC24
, /* type */
94 2, /* size (0 = byte, 1 = short, 2 = long) */
96 TRUE
, /* pc_relative */
98 complain_overflow_signed
,/* complain_on_overflow */
99 bfd_elf_generic_reloc
, /* special_function */
100 "R_ARM_PC24", /* name */
101 FALSE
, /* partial_inplace */
102 0x00ffffff, /* src_mask */
103 0x00ffffff, /* dst_mask */
104 TRUE
), /* pcrel_offset */
106 /* 32 bit absolute */
107 HOWTO (R_ARM_ABS32
, /* type */
109 2, /* size (0 = byte, 1 = short, 2 = long) */
111 FALSE
, /* pc_relative */
113 complain_overflow_bitfield
,/* complain_on_overflow */
114 bfd_elf_generic_reloc
, /* special_function */
115 "R_ARM_ABS32", /* name */
116 FALSE
, /* partial_inplace */
117 0xffffffff, /* src_mask */
118 0xffffffff, /* dst_mask */
119 FALSE
), /* pcrel_offset */
121 /* standard 32bit pc-relative reloc */
122 HOWTO (R_ARM_REL32
, /* type */
124 2, /* size (0 = byte, 1 = short, 2 = long) */
126 TRUE
, /* pc_relative */
128 complain_overflow_bitfield
,/* complain_on_overflow */
129 bfd_elf_generic_reloc
, /* special_function */
130 "R_ARM_REL32", /* name */
131 FALSE
, /* partial_inplace */
132 0xffffffff, /* src_mask */
133 0xffffffff, /* dst_mask */
134 TRUE
), /* pcrel_offset */
136 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
137 HOWTO (R_ARM_LDR_PC_G0
, /* type */
139 0, /* size (0 = byte, 1 = short, 2 = long) */
141 TRUE
, /* pc_relative */
143 complain_overflow_dont
,/* complain_on_overflow */
144 bfd_elf_generic_reloc
, /* special_function */
145 "R_ARM_LDR_PC_G0", /* name */
146 FALSE
, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 TRUE
), /* pcrel_offset */
151 /* 16 bit absolute */
152 HOWTO (R_ARM_ABS16
, /* type */
154 1, /* size (0 = byte, 1 = short, 2 = long) */
156 FALSE
, /* pc_relative */
158 complain_overflow_bitfield
,/* complain_on_overflow */
159 bfd_elf_generic_reloc
, /* special_function */
160 "R_ARM_ABS16", /* name */
161 FALSE
, /* partial_inplace */
162 0x0000ffff, /* src_mask */
163 0x0000ffff, /* dst_mask */
164 FALSE
), /* pcrel_offset */
166 /* 12 bit absolute */
167 HOWTO (R_ARM_ABS12
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 FALSE
, /* pc_relative */
173 complain_overflow_bitfield
,/* complain_on_overflow */
174 bfd_elf_generic_reloc
, /* special_function */
175 "R_ARM_ABS12", /* name */
176 FALSE
, /* partial_inplace */
177 0x00000fff, /* src_mask */
178 0x00000fff, /* dst_mask */
179 FALSE
), /* pcrel_offset */
181 HOWTO (R_ARM_THM_ABS5
, /* type */
183 1, /* size (0 = byte, 1 = short, 2 = long) */
185 FALSE
, /* pc_relative */
187 complain_overflow_bitfield
,/* complain_on_overflow */
188 bfd_elf_generic_reloc
, /* special_function */
189 "R_ARM_THM_ABS5", /* name */
190 FALSE
, /* partial_inplace */
191 0x000007e0, /* src_mask */
192 0x000007e0, /* dst_mask */
193 FALSE
), /* pcrel_offset */
196 HOWTO (R_ARM_ABS8
, /* type */
198 0, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE
, /* pc_relative */
202 complain_overflow_bitfield
,/* complain_on_overflow */
203 bfd_elf_generic_reloc
, /* special_function */
204 "R_ARM_ABS8", /* name */
205 FALSE
, /* partial_inplace */
206 0x000000ff, /* src_mask */
207 0x000000ff, /* dst_mask */
208 FALSE
), /* pcrel_offset */
210 HOWTO (R_ARM_SBREL32
, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE
, /* pc_relative */
216 complain_overflow_dont
,/* complain_on_overflow */
217 bfd_elf_generic_reloc
, /* special_function */
218 "R_ARM_SBREL32", /* name */
219 FALSE
, /* partial_inplace */
220 0xffffffff, /* src_mask */
221 0xffffffff, /* dst_mask */
222 FALSE
), /* pcrel_offset */
224 HOWTO (R_ARM_THM_CALL
, /* type */
226 2, /* size (0 = byte, 1 = short, 2 = long) */
228 TRUE
, /* pc_relative */
230 complain_overflow_signed
,/* complain_on_overflow */
231 bfd_elf_generic_reloc
, /* special_function */
232 "R_ARM_THM_CALL", /* name */
233 FALSE
, /* partial_inplace */
234 0x07ff07ff, /* src_mask */
235 0x07ff07ff, /* dst_mask */
236 TRUE
), /* pcrel_offset */
238 HOWTO (R_ARM_THM_PC8
, /* type */
240 1, /* size (0 = byte, 1 = short, 2 = long) */
242 TRUE
, /* pc_relative */
244 complain_overflow_signed
,/* complain_on_overflow */
245 bfd_elf_generic_reloc
, /* special_function */
246 "R_ARM_THM_PC8", /* name */
247 FALSE
, /* partial_inplace */
248 0x000000ff, /* src_mask */
249 0x000000ff, /* dst_mask */
250 TRUE
), /* pcrel_offset */
252 HOWTO (R_ARM_BREL_ADJ
, /* type */
254 1, /* size (0 = byte, 1 = short, 2 = long) */
256 FALSE
, /* pc_relative */
258 complain_overflow_signed
,/* complain_on_overflow */
259 bfd_elf_generic_reloc
, /* special_function */
260 "R_ARM_BREL_ADJ", /* name */
261 FALSE
, /* partial_inplace */
262 0xffffffff, /* src_mask */
263 0xffffffff, /* dst_mask */
264 FALSE
), /* pcrel_offset */
266 HOWTO (R_ARM_SWI24
, /* type */
268 0, /* size (0 = byte, 1 = short, 2 = long) */
270 FALSE
, /* pc_relative */
272 complain_overflow_signed
,/* complain_on_overflow */
273 bfd_elf_generic_reloc
, /* special_function */
274 "R_ARM_SWI24", /* name */
275 FALSE
, /* partial_inplace */
276 0x00000000, /* src_mask */
277 0x00000000, /* dst_mask */
278 FALSE
), /* pcrel_offset */
280 HOWTO (R_ARM_THM_SWI8
, /* type */
282 0, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE
, /* pc_relative */
286 complain_overflow_signed
,/* complain_on_overflow */
287 bfd_elf_generic_reloc
, /* special_function */
288 "R_ARM_SWI8", /* name */
289 FALSE
, /* partial_inplace */
290 0x00000000, /* src_mask */
291 0x00000000, /* dst_mask */
292 FALSE
), /* pcrel_offset */
294 /* BLX instruction for the ARM. */
295 HOWTO (R_ARM_XPC25
, /* type */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
299 TRUE
, /* pc_relative */
301 complain_overflow_signed
,/* complain_on_overflow */
302 bfd_elf_generic_reloc
, /* special_function */
303 "R_ARM_XPC25", /* name */
304 FALSE
, /* partial_inplace */
305 0x00ffffff, /* src_mask */
306 0x00ffffff, /* dst_mask */
307 TRUE
), /* pcrel_offset */
309 /* BLX instruction for the Thumb. */
310 HOWTO (R_ARM_THM_XPC22
, /* type */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 TRUE
, /* pc_relative */
316 complain_overflow_signed
,/* complain_on_overflow */
317 bfd_elf_generic_reloc
, /* special_function */
318 "R_ARM_THM_XPC22", /* name */
319 FALSE
, /* partial_inplace */
320 0x07ff07ff, /* src_mask */
321 0x07ff07ff, /* dst_mask */
322 TRUE
), /* pcrel_offset */
324 /* Dynamic TLS relocations. */
326 HOWTO (R_ARM_TLS_DTPMOD32
, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE
, /* pc_relative */
332 complain_overflow_bitfield
,/* complain_on_overflow */
333 bfd_elf_generic_reloc
, /* special_function */
334 "R_ARM_TLS_DTPMOD32", /* name */
335 TRUE
, /* partial_inplace */
336 0xffffffff, /* src_mask */
337 0xffffffff, /* dst_mask */
338 FALSE
), /* pcrel_offset */
340 HOWTO (R_ARM_TLS_DTPOFF32
, /* type */
342 2, /* size (0 = byte, 1 = short, 2 = long) */
344 FALSE
, /* pc_relative */
346 complain_overflow_bitfield
,/* complain_on_overflow */
347 bfd_elf_generic_reloc
, /* special_function */
348 "R_ARM_TLS_DTPOFF32", /* name */
349 TRUE
, /* partial_inplace */
350 0xffffffff, /* src_mask */
351 0xffffffff, /* dst_mask */
352 FALSE
), /* pcrel_offset */
354 HOWTO (R_ARM_TLS_TPOFF32
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_bitfield
,/* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_ARM_TLS_TPOFF32", /* name */
363 TRUE
, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* Relocs used in ARM Linux */
370 HOWTO (R_ARM_COPY
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_bitfield
,/* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_ARM_COPY", /* name */
379 TRUE
, /* partial_inplace */
380 0xffffffff, /* src_mask */
381 0xffffffff, /* dst_mask */
382 FALSE
), /* pcrel_offset */
384 HOWTO (R_ARM_GLOB_DAT
, /* type */
386 2, /* size (0 = byte, 1 = short, 2 = long) */
388 FALSE
, /* pc_relative */
390 complain_overflow_bitfield
,/* complain_on_overflow */
391 bfd_elf_generic_reloc
, /* special_function */
392 "R_ARM_GLOB_DAT", /* name */
393 TRUE
, /* partial_inplace */
394 0xffffffff, /* src_mask */
395 0xffffffff, /* dst_mask */
396 FALSE
), /* pcrel_offset */
398 HOWTO (R_ARM_JUMP_SLOT
, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE
, /* pc_relative */
404 complain_overflow_bitfield
,/* complain_on_overflow */
405 bfd_elf_generic_reloc
, /* special_function */
406 "R_ARM_JUMP_SLOT", /* name */
407 TRUE
, /* partial_inplace */
408 0xffffffff, /* src_mask */
409 0xffffffff, /* dst_mask */
410 FALSE
), /* pcrel_offset */
412 HOWTO (R_ARM_RELATIVE
, /* type */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE
, /* pc_relative */
418 complain_overflow_bitfield
,/* complain_on_overflow */
419 bfd_elf_generic_reloc
, /* special_function */
420 "R_ARM_RELATIVE", /* name */
421 TRUE
, /* partial_inplace */
422 0xffffffff, /* src_mask */
423 0xffffffff, /* dst_mask */
424 FALSE
), /* pcrel_offset */
426 HOWTO (R_ARM_GOTOFF32
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 FALSE
, /* pc_relative */
432 complain_overflow_bitfield
,/* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_ARM_GOTOFF32", /* name */
435 TRUE
, /* partial_inplace */
436 0xffffffff, /* src_mask */
437 0xffffffff, /* dst_mask */
438 FALSE
), /* pcrel_offset */
440 HOWTO (R_ARM_GOTPC
, /* type */
442 2, /* size (0 = byte, 1 = short, 2 = long) */
444 TRUE
, /* pc_relative */
446 complain_overflow_bitfield
,/* complain_on_overflow */
447 bfd_elf_generic_reloc
, /* special_function */
448 "R_ARM_GOTPC", /* name */
449 TRUE
, /* partial_inplace */
450 0xffffffff, /* src_mask */
451 0xffffffff, /* dst_mask */
452 TRUE
), /* pcrel_offset */
454 HOWTO (R_ARM_GOT32
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_bitfield
,/* complain_on_overflow */
461 bfd_elf_generic_reloc
, /* special_function */
462 "R_ARM_GOT32", /* name */
463 TRUE
, /* partial_inplace */
464 0xffffffff, /* src_mask */
465 0xffffffff, /* dst_mask */
466 FALSE
), /* pcrel_offset */
468 HOWTO (R_ARM_PLT32
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 TRUE
, /* pc_relative */
474 complain_overflow_bitfield
,/* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_ARM_PLT32", /* name */
477 FALSE
, /* partial_inplace */
478 0x00ffffff, /* src_mask */
479 0x00ffffff, /* dst_mask */
480 TRUE
), /* pcrel_offset */
482 HOWTO (R_ARM_CALL
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 TRUE
, /* pc_relative */
488 complain_overflow_signed
,/* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_ARM_CALL", /* name */
491 FALSE
, /* partial_inplace */
492 0x00ffffff, /* src_mask */
493 0x00ffffff, /* dst_mask */
494 TRUE
), /* pcrel_offset */
496 HOWTO (R_ARM_JUMP24
, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 TRUE
, /* pc_relative */
502 complain_overflow_signed
,/* complain_on_overflow */
503 bfd_elf_generic_reloc
, /* special_function */
504 "R_ARM_JUMP24", /* name */
505 FALSE
, /* partial_inplace */
506 0x00ffffff, /* src_mask */
507 0x00ffffff, /* dst_mask */
508 TRUE
), /* pcrel_offset */
510 HOWTO (R_ARM_THM_JUMP24
, /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 TRUE
, /* pc_relative */
516 complain_overflow_signed
,/* complain_on_overflow */
517 bfd_elf_generic_reloc
, /* special_function */
518 "R_ARM_THM_JUMP24", /* name */
519 FALSE
, /* partial_inplace */
520 0x07ff2fff, /* src_mask */
521 0x07ff2fff, /* dst_mask */
522 TRUE
), /* pcrel_offset */
524 HOWTO (R_ARM_BASE_ABS
, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE
, /* pc_relative */
530 complain_overflow_dont
,/* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_ARM_BASE_ABS", /* name */
533 FALSE
, /* partial_inplace */
534 0xffffffff, /* src_mask */
535 0xffffffff, /* dst_mask */
536 FALSE
), /* pcrel_offset */
538 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 TRUE
, /* pc_relative */
544 complain_overflow_dont
,/* complain_on_overflow */
545 bfd_elf_generic_reloc
, /* special_function */
546 "R_ARM_ALU_PCREL_7_0", /* name */
547 FALSE
, /* partial_inplace */
548 0x00000fff, /* src_mask */
549 0x00000fff, /* dst_mask */
550 TRUE
), /* pcrel_offset */
552 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 TRUE
, /* pc_relative */
558 complain_overflow_dont
,/* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_ARM_ALU_PCREL_15_8",/* name */
561 FALSE
, /* partial_inplace */
562 0x00000fff, /* src_mask */
563 0x00000fff, /* dst_mask */
564 TRUE
), /* pcrel_offset */
566 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
570 TRUE
, /* pc_relative */
572 complain_overflow_dont
,/* complain_on_overflow */
573 bfd_elf_generic_reloc
, /* special_function */
574 "R_ARM_ALU_PCREL_23_15",/* name */
575 FALSE
, /* partial_inplace */
576 0x00000fff, /* src_mask */
577 0x00000fff, /* dst_mask */
578 TRUE
), /* pcrel_offset */
580 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE
, /* pc_relative */
586 complain_overflow_dont
,/* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_ARM_LDR_SBREL_11_0",/* name */
589 FALSE
, /* partial_inplace */
590 0x00000fff, /* src_mask */
591 0x00000fff, /* dst_mask */
592 FALSE
), /* pcrel_offset */
594 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE
, /* pc_relative */
600 complain_overflow_dont
,/* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_ARM_ALU_SBREL_19_12",/* name */
603 FALSE
, /* partial_inplace */
604 0x000ff000, /* src_mask */
605 0x000ff000, /* dst_mask */
606 FALSE
), /* pcrel_offset */
608 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 FALSE
, /* pc_relative */
614 complain_overflow_dont
,/* complain_on_overflow */
615 bfd_elf_generic_reloc
, /* special_function */
616 "R_ARM_ALU_SBREL_27_20",/* name */
617 FALSE
, /* partial_inplace */
618 0x0ff00000, /* src_mask */
619 0x0ff00000, /* dst_mask */
620 FALSE
), /* pcrel_offset */
622 HOWTO (R_ARM_TARGET1
, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE
, /* pc_relative */
628 complain_overflow_dont
,/* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_ARM_TARGET1", /* name */
631 FALSE
, /* partial_inplace */
632 0xffffffff, /* src_mask */
633 0xffffffff, /* dst_mask */
634 FALSE
), /* pcrel_offset */
636 HOWTO (R_ARM_ROSEGREL32
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 FALSE
, /* pc_relative */
642 complain_overflow_dont
,/* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 "R_ARM_ROSEGREL32", /* name */
645 FALSE
, /* partial_inplace */
646 0xffffffff, /* src_mask */
647 0xffffffff, /* dst_mask */
648 FALSE
), /* pcrel_offset */
650 HOWTO (R_ARM_V4BX
, /* type */
652 2, /* size (0 = byte, 1 = short, 2 = long) */
654 FALSE
, /* pc_relative */
656 complain_overflow_dont
,/* complain_on_overflow */
657 bfd_elf_generic_reloc
, /* special_function */
658 "R_ARM_V4BX", /* name */
659 FALSE
, /* partial_inplace */
660 0xffffffff, /* src_mask */
661 0xffffffff, /* dst_mask */
662 FALSE
), /* pcrel_offset */
664 HOWTO (R_ARM_TARGET2
, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 FALSE
, /* pc_relative */
670 complain_overflow_signed
,/* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_ARM_TARGET2", /* name */
673 FALSE
, /* partial_inplace */
674 0xffffffff, /* src_mask */
675 0xffffffff, /* dst_mask */
676 TRUE
), /* pcrel_offset */
678 HOWTO (R_ARM_PREL31
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 TRUE
, /* pc_relative */
684 complain_overflow_signed
,/* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 "R_ARM_PREL31", /* name */
687 FALSE
, /* partial_inplace */
688 0x7fffffff, /* src_mask */
689 0x7fffffff, /* dst_mask */
690 TRUE
), /* pcrel_offset */
692 HOWTO (R_ARM_MOVW_ABS_NC
, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE
, /* pc_relative */
698 complain_overflow_dont
,/* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_ARM_MOVW_ABS_NC", /* name */
701 FALSE
, /* partial_inplace */
702 0x000f0fff, /* src_mask */
703 0x000f0fff, /* dst_mask */
704 FALSE
), /* pcrel_offset */
706 HOWTO (R_ARM_MOVT_ABS
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE
, /* pc_relative */
712 complain_overflow_bitfield
,/* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_ARM_MOVT_ABS", /* name */
715 FALSE
, /* partial_inplace */
716 0x000f0fff, /* src_mask */
717 0x000f0fff, /* dst_mask */
718 FALSE
), /* pcrel_offset */
720 HOWTO (R_ARM_MOVW_PREL_NC
, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 TRUE
, /* pc_relative */
726 complain_overflow_dont
,/* complain_on_overflow */
727 bfd_elf_generic_reloc
, /* special_function */
728 "R_ARM_MOVW_PREL_NC", /* name */
729 FALSE
, /* partial_inplace */
730 0x000f0fff, /* src_mask */
731 0x000f0fff, /* dst_mask */
732 TRUE
), /* pcrel_offset */
734 HOWTO (R_ARM_MOVT_PREL
, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 TRUE
, /* pc_relative */
740 complain_overflow_bitfield
,/* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_ARM_MOVT_PREL", /* name */
743 FALSE
, /* partial_inplace */
744 0x000f0fff, /* src_mask */
745 0x000f0fff, /* dst_mask */
746 TRUE
), /* pcrel_offset */
748 HOWTO (R_ARM_THM_MOVW_ABS_NC
, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE
, /* pc_relative */
754 complain_overflow_dont
,/* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_ARM_THM_MOVW_ABS_NC",/* name */
757 FALSE
, /* partial_inplace */
758 0x040f70ff, /* src_mask */
759 0x040f70ff, /* dst_mask */
760 FALSE
), /* pcrel_offset */
762 HOWTO (R_ARM_THM_MOVT_ABS
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 FALSE
, /* pc_relative */
768 complain_overflow_bitfield
,/* complain_on_overflow */
769 bfd_elf_generic_reloc
, /* special_function */
770 "R_ARM_THM_MOVT_ABS", /* name */
771 FALSE
, /* partial_inplace */
772 0x040f70ff, /* src_mask */
773 0x040f70ff, /* dst_mask */
774 FALSE
), /* pcrel_offset */
776 HOWTO (R_ARM_THM_MOVW_PREL_NC
,/* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 TRUE
, /* pc_relative */
782 complain_overflow_dont
,/* complain_on_overflow */
783 bfd_elf_generic_reloc
, /* special_function */
784 "R_ARM_THM_MOVW_PREL_NC",/* name */
785 FALSE
, /* partial_inplace */
786 0x040f70ff, /* src_mask */
787 0x040f70ff, /* dst_mask */
788 TRUE
), /* pcrel_offset */
790 HOWTO (R_ARM_THM_MOVT_PREL
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 TRUE
, /* pc_relative */
796 complain_overflow_bitfield
,/* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_ARM_THM_MOVT_PREL", /* name */
799 FALSE
, /* partial_inplace */
800 0x040f70ff, /* src_mask */
801 0x040f70ff, /* dst_mask */
802 TRUE
), /* pcrel_offset */
804 HOWTO (R_ARM_THM_JUMP19
, /* type */
806 2, /* size (0 = byte, 1 = short, 2 = long) */
808 TRUE
, /* pc_relative */
810 complain_overflow_signed
,/* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_ARM_THM_JUMP19", /* name */
813 FALSE
, /* partial_inplace */
814 0x043f2fff, /* src_mask */
815 0x043f2fff, /* dst_mask */
816 TRUE
), /* pcrel_offset */
818 HOWTO (R_ARM_THM_JUMP6
, /* type */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 TRUE
, /* pc_relative */
824 complain_overflow_unsigned
,/* complain_on_overflow */
825 bfd_elf_generic_reloc
, /* special_function */
826 "R_ARM_THM_JUMP6", /* name */
827 FALSE
, /* partial_inplace */
828 0x02f8, /* src_mask */
829 0x02f8, /* dst_mask */
830 TRUE
), /* pcrel_offset */
832 /* These are declared as 13-bit signed relocations because we can
833 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
835 HOWTO (R_ARM_THM_ALU_PREL_11_0
,/* type */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
839 TRUE
, /* pc_relative */
841 complain_overflow_dont
,/* complain_on_overflow */
842 bfd_elf_generic_reloc
, /* special_function */
843 "R_ARM_THM_ALU_PREL_11_0",/* name */
844 FALSE
, /* partial_inplace */
845 0xffffffff, /* src_mask */
846 0xffffffff, /* dst_mask */
847 TRUE
), /* pcrel_offset */
849 HOWTO (R_ARM_THM_PC12
, /* type */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
853 TRUE
, /* pc_relative */
855 complain_overflow_dont
,/* complain_on_overflow */
856 bfd_elf_generic_reloc
, /* special_function */
857 "R_ARM_THM_PC12", /* name */
858 FALSE
, /* partial_inplace */
859 0xffffffff, /* src_mask */
860 0xffffffff, /* dst_mask */
861 TRUE
), /* pcrel_offset */
863 HOWTO (R_ARM_ABS32_NOI
, /* type */
865 2, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_dont
,/* complain_on_overflow */
870 bfd_elf_generic_reloc
, /* special_function */
871 "R_ARM_ABS32_NOI", /* name */
872 FALSE
, /* partial_inplace */
873 0xffffffff, /* src_mask */
874 0xffffffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 HOWTO (R_ARM_REL32_NOI
, /* type */
879 2, /* size (0 = byte, 1 = short, 2 = long) */
881 TRUE
, /* pc_relative */
883 complain_overflow_dont
,/* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_ARM_REL32_NOI", /* name */
886 FALSE
, /* partial_inplace */
887 0xffffffff, /* src_mask */
888 0xffffffff, /* dst_mask */
889 FALSE
), /* pcrel_offset */
891 /* Group relocations. */
893 HOWTO (R_ARM_ALU_PC_G0_NC
, /* type */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
897 TRUE
, /* pc_relative */
899 complain_overflow_dont
,/* complain_on_overflow */
900 bfd_elf_generic_reloc
, /* special_function */
901 "R_ARM_ALU_PC_G0_NC", /* name */
902 FALSE
, /* partial_inplace */
903 0xffffffff, /* src_mask */
904 0xffffffff, /* dst_mask */
905 TRUE
), /* pcrel_offset */
907 HOWTO (R_ARM_ALU_PC_G0
, /* type */
909 2, /* size (0 = byte, 1 = short, 2 = long) */
911 TRUE
, /* pc_relative */
913 complain_overflow_dont
,/* complain_on_overflow */
914 bfd_elf_generic_reloc
, /* special_function */
915 "R_ARM_ALU_PC_G0", /* name */
916 FALSE
, /* partial_inplace */
917 0xffffffff, /* src_mask */
918 0xffffffff, /* dst_mask */
919 TRUE
), /* pcrel_offset */
921 HOWTO (R_ARM_ALU_PC_G1_NC
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 TRUE
, /* pc_relative */
927 complain_overflow_dont
,/* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_ARM_ALU_PC_G1_NC", /* name */
930 FALSE
, /* partial_inplace */
931 0xffffffff, /* src_mask */
932 0xffffffff, /* dst_mask */
933 TRUE
), /* pcrel_offset */
935 HOWTO (R_ARM_ALU_PC_G1
, /* type */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 TRUE
, /* pc_relative */
941 complain_overflow_dont
,/* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 "R_ARM_ALU_PC_G1", /* name */
944 FALSE
, /* partial_inplace */
945 0xffffffff, /* src_mask */
946 0xffffffff, /* dst_mask */
947 TRUE
), /* pcrel_offset */
949 HOWTO (R_ARM_ALU_PC_G2
, /* type */
951 2, /* size (0 = byte, 1 = short, 2 = long) */
953 TRUE
, /* pc_relative */
955 complain_overflow_dont
,/* complain_on_overflow */
956 bfd_elf_generic_reloc
, /* special_function */
957 "R_ARM_ALU_PC_G2", /* name */
958 FALSE
, /* partial_inplace */
959 0xffffffff, /* src_mask */
960 0xffffffff, /* dst_mask */
961 TRUE
), /* pcrel_offset */
963 HOWTO (R_ARM_LDR_PC_G1
, /* type */
965 2, /* size (0 = byte, 1 = short, 2 = long) */
967 TRUE
, /* pc_relative */
969 complain_overflow_dont
,/* complain_on_overflow */
970 bfd_elf_generic_reloc
, /* special_function */
971 "R_ARM_LDR_PC_G1", /* name */
972 FALSE
, /* partial_inplace */
973 0xffffffff, /* src_mask */
974 0xffffffff, /* dst_mask */
975 TRUE
), /* pcrel_offset */
977 HOWTO (R_ARM_LDR_PC_G2
, /* type */
979 2, /* size (0 = byte, 1 = short, 2 = long) */
981 TRUE
, /* pc_relative */
983 complain_overflow_dont
,/* complain_on_overflow */
984 bfd_elf_generic_reloc
, /* special_function */
985 "R_ARM_LDR_PC_G2", /* name */
986 FALSE
, /* partial_inplace */
987 0xffffffff, /* src_mask */
988 0xffffffff, /* dst_mask */
989 TRUE
), /* pcrel_offset */
991 HOWTO (R_ARM_LDRS_PC_G0
, /* type */
993 2, /* size (0 = byte, 1 = short, 2 = long) */
995 TRUE
, /* pc_relative */
997 complain_overflow_dont
,/* complain_on_overflow */
998 bfd_elf_generic_reloc
, /* special_function */
999 "R_ARM_LDRS_PC_G0", /* name */
1000 FALSE
, /* partial_inplace */
1001 0xffffffff, /* src_mask */
1002 0xffffffff, /* dst_mask */
1003 TRUE
), /* pcrel_offset */
1005 HOWTO (R_ARM_LDRS_PC_G1
, /* type */
1007 2, /* size (0 = byte, 1 = short, 2 = long) */
1009 TRUE
, /* pc_relative */
1011 complain_overflow_dont
,/* complain_on_overflow */
1012 bfd_elf_generic_reloc
, /* special_function */
1013 "R_ARM_LDRS_PC_G1", /* name */
1014 FALSE
, /* partial_inplace */
1015 0xffffffff, /* src_mask */
1016 0xffffffff, /* dst_mask */
1017 TRUE
), /* pcrel_offset */
1019 HOWTO (R_ARM_LDRS_PC_G2
, /* type */
1021 2, /* size (0 = byte, 1 = short, 2 = long) */
1023 TRUE
, /* pc_relative */
1025 complain_overflow_dont
,/* complain_on_overflow */
1026 bfd_elf_generic_reloc
, /* special_function */
1027 "R_ARM_LDRS_PC_G2", /* name */
1028 FALSE
, /* partial_inplace */
1029 0xffffffff, /* src_mask */
1030 0xffffffff, /* dst_mask */
1031 TRUE
), /* pcrel_offset */
1033 HOWTO (R_ARM_LDC_PC_G0
, /* type */
1035 2, /* size (0 = byte, 1 = short, 2 = long) */
1037 TRUE
, /* pc_relative */
1039 complain_overflow_dont
,/* complain_on_overflow */
1040 bfd_elf_generic_reloc
, /* special_function */
1041 "R_ARM_LDC_PC_G0", /* name */
1042 FALSE
, /* partial_inplace */
1043 0xffffffff, /* src_mask */
1044 0xffffffff, /* dst_mask */
1045 TRUE
), /* pcrel_offset */
1047 HOWTO (R_ARM_LDC_PC_G1
, /* type */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 TRUE
, /* pc_relative */
1053 complain_overflow_dont
,/* complain_on_overflow */
1054 bfd_elf_generic_reloc
, /* special_function */
1055 "R_ARM_LDC_PC_G1", /* name */
1056 FALSE
, /* partial_inplace */
1057 0xffffffff, /* src_mask */
1058 0xffffffff, /* dst_mask */
1059 TRUE
), /* pcrel_offset */
1061 HOWTO (R_ARM_LDC_PC_G2
, /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 TRUE
, /* pc_relative */
1067 complain_overflow_dont
,/* complain_on_overflow */
1068 bfd_elf_generic_reloc
, /* special_function */
1069 "R_ARM_LDC_PC_G2", /* name */
1070 FALSE
, /* partial_inplace */
1071 0xffffffff, /* src_mask */
1072 0xffffffff, /* dst_mask */
1073 TRUE
), /* pcrel_offset */
1075 HOWTO (R_ARM_ALU_SB_G0_NC
, /* type */
1077 2, /* size (0 = byte, 1 = short, 2 = long) */
1079 TRUE
, /* pc_relative */
1081 complain_overflow_dont
,/* complain_on_overflow */
1082 bfd_elf_generic_reloc
, /* special_function */
1083 "R_ARM_ALU_SB_G0_NC", /* name */
1084 FALSE
, /* partial_inplace */
1085 0xffffffff, /* src_mask */
1086 0xffffffff, /* dst_mask */
1087 TRUE
), /* pcrel_offset */
1089 HOWTO (R_ARM_ALU_SB_G0
, /* type */
1091 2, /* size (0 = byte, 1 = short, 2 = long) */
1093 TRUE
, /* pc_relative */
1095 complain_overflow_dont
,/* complain_on_overflow */
1096 bfd_elf_generic_reloc
, /* special_function */
1097 "R_ARM_ALU_SB_G0", /* name */
1098 FALSE
, /* partial_inplace */
1099 0xffffffff, /* src_mask */
1100 0xffffffff, /* dst_mask */
1101 TRUE
), /* pcrel_offset */
1103 HOWTO (R_ARM_ALU_SB_G1_NC
, /* type */
1105 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 TRUE
, /* pc_relative */
1109 complain_overflow_dont
,/* complain_on_overflow */
1110 bfd_elf_generic_reloc
, /* special_function */
1111 "R_ARM_ALU_SB_G1_NC", /* name */
1112 FALSE
, /* partial_inplace */
1113 0xffffffff, /* src_mask */
1114 0xffffffff, /* dst_mask */
1115 TRUE
), /* pcrel_offset */
1117 HOWTO (R_ARM_ALU_SB_G1
, /* type */
1119 2, /* size (0 = byte, 1 = short, 2 = long) */
1121 TRUE
, /* pc_relative */
1123 complain_overflow_dont
,/* complain_on_overflow */
1124 bfd_elf_generic_reloc
, /* special_function */
1125 "R_ARM_ALU_SB_G1", /* name */
1126 FALSE
, /* partial_inplace */
1127 0xffffffff, /* src_mask */
1128 0xffffffff, /* dst_mask */
1129 TRUE
), /* pcrel_offset */
1131 HOWTO (R_ARM_ALU_SB_G2
, /* type */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 TRUE
, /* pc_relative */
1137 complain_overflow_dont
,/* complain_on_overflow */
1138 bfd_elf_generic_reloc
, /* special_function */
1139 "R_ARM_ALU_SB_G2", /* name */
1140 FALSE
, /* partial_inplace */
1141 0xffffffff, /* src_mask */
1142 0xffffffff, /* dst_mask */
1143 TRUE
), /* pcrel_offset */
1145 HOWTO (R_ARM_LDR_SB_G0
, /* type */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1149 TRUE
, /* pc_relative */
1151 complain_overflow_dont
,/* complain_on_overflow */
1152 bfd_elf_generic_reloc
, /* special_function */
1153 "R_ARM_LDR_SB_G0", /* name */
1154 FALSE
, /* partial_inplace */
1155 0xffffffff, /* src_mask */
1156 0xffffffff, /* dst_mask */
1157 TRUE
), /* pcrel_offset */
1159 HOWTO (R_ARM_LDR_SB_G1
, /* type */
1161 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 TRUE
, /* pc_relative */
1165 complain_overflow_dont
,/* complain_on_overflow */
1166 bfd_elf_generic_reloc
, /* special_function */
1167 "R_ARM_LDR_SB_G1", /* name */
1168 FALSE
, /* partial_inplace */
1169 0xffffffff, /* src_mask */
1170 0xffffffff, /* dst_mask */
1171 TRUE
), /* pcrel_offset */
1173 HOWTO (R_ARM_LDR_SB_G2
, /* type */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1177 TRUE
, /* pc_relative */
1179 complain_overflow_dont
,/* complain_on_overflow */
1180 bfd_elf_generic_reloc
, /* special_function */
1181 "R_ARM_LDR_SB_G2", /* name */
1182 FALSE
, /* partial_inplace */
1183 0xffffffff, /* src_mask */
1184 0xffffffff, /* dst_mask */
1185 TRUE
), /* pcrel_offset */
1187 HOWTO (R_ARM_LDRS_SB_G0
, /* type */
1189 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 TRUE
, /* pc_relative */
1193 complain_overflow_dont
,/* complain_on_overflow */
1194 bfd_elf_generic_reloc
, /* special_function */
1195 "R_ARM_LDRS_SB_G0", /* name */
1196 FALSE
, /* partial_inplace */
1197 0xffffffff, /* src_mask */
1198 0xffffffff, /* dst_mask */
1199 TRUE
), /* pcrel_offset */
1201 HOWTO (R_ARM_LDRS_SB_G1
, /* type */
1203 2, /* size (0 = byte, 1 = short, 2 = long) */
1205 TRUE
, /* pc_relative */
1207 complain_overflow_dont
,/* complain_on_overflow */
1208 bfd_elf_generic_reloc
, /* special_function */
1209 "R_ARM_LDRS_SB_G1", /* name */
1210 FALSE
, /* partial_inplace */
1211 0xffffffff, /* src_mask */
1212 0xffffffff, /* dst_mask */
1213 TRUE
), /* pcrel_offset */
1215 HOWTO (R_ARM_LDRS_SB_G2
, /* type */
1217 2, /* size (0 = byte, 1 = short, 2 = long) */
1219 TRUE
, /* pc_relative */
1221 complain_overflow_dont
,/* complain_on_overflow */
1222 bfd_elf_generic_reloc
, /* special_function */
1223 "R_ARM_LDRS_SB_G2", /* name */
1224 FALSE
, /* partial_inplace */
1225 0xffffffff, /* src_mask */
1226 0xffffffff, /* dst_mask */
1227 TRUE
), /* pcrel_offset */
1229 HOWTO (R_ARM_LDC_SB_G0
, /* type */
1231 2, /* size (0 = byte, 1 = short, 2 = long) */
1233 TRUE
, /* pc_relative */
1235 complain_overflow_dont
,/* complain_on_overflow */
1236 bfd_elf_generic_reloc
, /* special_function */
1237 "R_ARM_LDC_SB_G0", /* name */
1238 FALSE
, /* partial_inplace */
1239 0xffffffff, /* src_mask */
1240 0xffffffff, /* dst_mask */
1241 TRUE
), /* pcrel_offset */
1243 HOWTO (R_ARM_LDC_SB_G1
, /* type */
1245 2, /* size (0 = byte, 1 = short, 2 = long) */
1247 TRUE
, /* pc_relative */
1249 complain_overflow_dont
,/* complain_on_overflow */
1250 bfd_elf_generic_reloc
, /* special_function */
1251 "R_ARM_LDC_SB_G1", /* name */
1252 FALSE
, /* partial_inplace */
1253 0xffffffff, /* src_mask */
1254 0xffffffff, /* dst_mask */
1255 TRUE
), /* pcrel_offset */
1257 HOWTO (R_ARM_LDC_SB_G2
, /* type */
1259 2, /* size (0 = byte, 1 = short, 2 = long) */
1261 TRUE
, /* pc_relative */
1263 complain_overflow_dont
,/* complain_on_overflow */
1264 bfd_elf_generic_reloc
, /* special_function */
1265 "R_ARM_LDC_SB_G2", /* name */
1266 FALSE
, /* partial_inplace */
1267 0xffffffff, /* src_mask */
1268 0xffffffff, /* dst_mask */
1269 TRUE
), /* pcrel_offset */
1271 /* End of group relocations. */
1273 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
1275 2, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE
, /* pc_relative */
1279 complain_overflow_dont
,/* complain_on_overflow */
1280 bfd_elf_generic_reloc
, /* special_function */
1281 "R_ARM_MOVW_BREL_NC", /* name */
1282 FALSE
, /* partial_inplace */
1283 0x0000ffff, /* src_mask */
1284 0x0000ffff, /* dst_mask */
1285 FALSE
), /* pcrel_offset */
1287 HOWTO (R_ARM_MOVT_BREL
, /* type */
1289 2, /* size (0 = byte, 1 = short, 2 = long) */
1291 FALSE
, /* pc_relative */
1293 complain_overflow_bitfield
,/* complain_on_overflow */
1294 bfd_elf_generic_reloc
, /* special_function */
1295 "R_ARM_MOVT_BREL", /* name */
1296 FALSE
, /* partial_inplace */
1297 0x0000ffff, /* src_mask */
1298 0x0000ffff, /* dst_mask */
1299 FALSE
), /* pcrel_offset */
1301 HOWTO (R_ARM_MOVW_BREL
, /* type */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1305 FALSE
, /* pc_relative */
1307 complain_overflow_dont
,/* complain_on_overflow */
1308 bfd_elf_generic_reloc
, /* special_function */
1309 "R_ARM_MOVW_BREL", /* name */
1310 FALSE
, /* partial_inplace */
1311 0x0000ffff, /* src_mask */
1312 0x0000ffff, /* dst_mask */
1313 FALSE
), /* pcrel_offset */
1315 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
1317 2, /* size (0 = byte, 1 = short, 2 = long) */
1319 FALSE
, /* pc_relative */
1321 complain_overflow_dont
,/* complain_on_overflow */
1322 bfd_elf_generic_reloc
, /* special_function */
1323 "R_ARM_THM_MOVW_BREL_NC",/* name */
1324 FALSE
, /* partial_inplace */
1325 0x040f70ff, /* src_mask */
1326 0x040f70ff, /* dst_mask */
1327 FALSE
), /* pcrel_offset */
1329 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
1331 2, /* size (0 = byte, 1 = short, 2 = long) */
1333 FALSE
, /* pc_relative */
1335 complain_overflow_bitfield
,/* complain_on_overflow */
1336 bfd_elf_generic_reloc
, /* special_function */
1337 "R_ARM_THM_MOVT_BREL", /* name */
1338 FALSE
, /* partial_inplace */
1339 0x040f70ff, /* src_mask */
1340 0x040f70ff, /* dst_mask */
1341 FALSE
), /* pcrel_offset */
1343 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
1345 2, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE
, /* pc_relative */
1349 complain_overflow_dont
,/* complain_on_overflow */
1350 bfd_elf_generic_reloc
, /* special_function */
1351 "R_ARM_THM_MOVW_BREL", /* name */
1352 FALSE
, /* partial_inplace */
1353 0x040f70ff, /* src_mask */
1354 0x040f70ff, /* dst_mask */
1355 FALSE
), /* pcrel_offset */
1357 EMPTY_HOWTO (90), /* Unallocated. */
1362 HOWTO (R_ARM_PLT32_ABS
, /* type */
1364 2, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE
, /* pc_relative */
1368 complain_overflow_dont
,/* complain_on_overflow */
1369 bfd_elf_generic_reloc
, /* special_function */
1370 "R_ARM_PLT32_ABS", /* name */
1371 FALSE
, /* partial_inplace */
1372 0xffffffff, /* src_mask */
1373 0xffffffff, /* dst_mask */
1374 FALSE
), /* pcrel_offset */
1376 HOWTO (R_ARM_GOT_ABS
, /* type */
1378 2, /* size (0 = byte, 1 = short, 2 = long) */
1380 FALSE
, /* pc_relative */
1382 complain_overflow_dont
,/* complain_on_overflow */
1383 bfd_elf_generic_reloc
, /* special_function */
1384 "R_ARM_GOT_ABS", /* name */
1385 FALSE
, /* partial_inplace */
1386 0xffffffff, /* src_mask */
1387 0xffffffff, /* dst_mask */
1388 FALSE
), /* pcrel_offset */
1390 HOWTO (R_ARM_GOT_PREL
, /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 TRUE
, /* pc_relative */
1396 complain_overflow_dont
, /* complain_on_overflow */
1397 bfd_elf_generic_reloc
, /* special_function */
1398 "R_ARM_GOT_PREL", /* name */
1399 FALSE
, /* partial_inplace */
1400 0xffffffff, /* src_mask */
1401 0xffffffff, /* dst_mask */
1402 TRUE
), /* pcrel_offset */
1404 HOWTO (R_ARM_GOT_BREL12
, /* type */
1406 2, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE
, /* pc_relative */
1410 complain_overflow_bitfield
,/* complain_on_overflow */
1411 bfd_elf_generic_reloc
, /* special_function */
1412 "R_ARM_GOT_BREL12", /* name */
1413 FALSE
, /* partial_inplace */
1414 0x00000fff, /* src_mask */
1415 0x00000fff, /* dst_mask */
1416 FALSE
), /* pcrel_offset */
1418 HOWTO (R_ARM_GOTOFF12
, /* type */
1420 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE
, /* pc_relative */
1424 complain_overflow_bitfield
,/* complain_on_overflow */
1425 bfd_elf_generic_reloc
, /* special_function */
1426 "R_ARM_GOTOFF12", /* name */
1427 FALSE
, /* partial_inplace */
1428 0x00000fff, /* src_mask */
1429 0x00000fff, /* dst_mask */
1430 FALSE
), /* pcrel_offset */
1432 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1434 /* GNU extension to record C++ vtable member usage */
1435 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1437 2, /* size (0 = byte, 1 = short, 2 = long) */
1439 FALSE
, /* pc_relative */
1441 complain_overflow_dont
, /* complain_on_overflow */
1442 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1443 "R_ARM_GNU_VTENTRY", /* name */
1444 FALSE
, /* partial_inplace */
1447 FALSE
), /* pcrel_offset */
1449 /* GNU extension to record C++ vtable hierarchy */
1450 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE
, /* pc_relative */
1456 complain_overflow_dont
, /* complain_on_overflow */
1457 NULL
, /* special_function */
1458 "R_ARM_GNU_VTINHERIT", /* name */
1459 FALSE
, /* partial_inplace */
1462 FALSE
), /* pcrel_offset */
1464 HOWTO (R_ARM_THM_JUMP11
, /* type */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1468 TRUE
, /* pc_relative */
1470 complain_overflow_signed
, /* complain_on_overflow */
1471 bfd_elf_generic_reloc
, /* special_function */
1472 "R_ARM_THM_JUMP11", /* name */
1473 FALSE
, /* partial_inplace */
1474 0x000007ff, /* src_mask */
1475 0x000007ff, /* dst_mask */
1476 TRUE
), /* pcrel_offset */
1478 HOWTO (R_ARM_THM_JUMP8
, /* type */
1480 1, /* size (0 = byte, 1 = short, 2 = long) */
1482 TRUE
, /* pc_relative */
1484 complain_overflow_signed
, /* complain_on_overflow */
1485 bfd_elf_generic_reloc
, /* special_function */
1486 "R_ARM_THM_JUMP8", /* name */
1487 FALSE
, /* partial_inplace */
1488 0x000000ff, /* src_mask */
1489 0x000000ff, /* dst_mask */
1490 TRUE
), /* pcrel_offset */
1492 /* TLS relocations */
1493 HOWTO (R_ARM_TLS_GD32
, /* type */
1495 2, /* size (0 = byte, 1 = short, 2 = long) */
1497 FALSE
, /* pc_relative */
1499 complain_overflow_bitfield
,/* complain_on_overflow */
1500 NULL
, /* special_function */
1501 "R_ARM_TLS_GD32", /* name */
1502 TRUE
, /* partial_inplace */
1503 0xffffffff, /* src_mask */
1504 0xffffffff, /* dst_mask */
1505 FALSE
), /* pcrel_offset */
1507 HOWTO (R_ARM_TLS_LDM32
, /* type */
1509 2, /* size (0 = byte, 1 = short, 2 = long) */
1511 FALSE
, /* pc_relative */
1513 complain_overflow_bitfield
,/* complain_on_overflow */
1514 bfd_elf_generic_reloc
, /* special_function */
1515 "R_ARM_TLS_LDM32", /* name */
1516 TRUE
, /* partial_inplace */
1517 0xffffffff, /* src_mask */
1518 0xffffffff, /* dst_mask */
1519 FALSE
), /* pcrel_offset */
1521 HOWTO (R_ARM_TLS_LDO32
, /* type */
1523 2, /* size (0 = byte, 1 = short, 2 = long) */
1525 FALSE
, /* pc_relative */
1527 complain_overflow_bitfield
,/* complain_on_overflow */
1528 bfd_elf_generic_reloc
, /* special_function */
1529 "R_ARM_TLS_LDO32", /* name */
1530 TRUE
, /* partial_inplace */
1531 0xffffffff, /* src_mask */
1532 0xffffffff, /* dst_mask */
1533 FALSE
), /* pcrel_offset */
1535 HOWTO (R_ARM_TLS_IE32
, /* type */
1537 2, /* size (0 = byte, 1 = short, 2 = long) */
1539 FALSE
, /* pc_relative */
1541 complain_overflow_bitfield
,/* complain_on_overflow */
1542 NULL
, /* special_function */
1543 "R_ARM_TLS_IE32", /* name */
1544 TRUE
, /* partial_inplace */
1545 0xffffffff, /* src_mask */
1546 0xffffffff, /* dst_mask */
1547 FALSE
), /* pcrel_offset */
1549 HOWTO (R_ARM_TLS_LE32
, /* type */
1551 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 FALSE
, /* pc_relative */
1555 complain_overflow_bitfield
,/* complain_on_overflow */
1556 bfd_elf_generic_reloc
, /* special_function */
1557 "R_ARM_TLS_LE32", /* name */
1558 TRUE
, /* partial_inplace */
1559 0xffffffff, /* src_mask */
1560 0xffffffff, /* dst_mask */
1561 FALSE
), /* pcrel_offset */
1563 HOWTO (R_ARM_TLS_LDO12
, /* type */
1565 2, /* size (0 = byte, 1 = short, 2 = long) */
1567 FALSE
, /* pc_relative */
1569 complain_overflow_bitfield
,/* complain_on_overflow */
1570 bfd_elf_generic_reloc
, /* special_function */
1571 "R_ARM_TLS_LDO12", /* name */
1572 FALSE
, /* partial_inplace */
1573 0x00000fff, /* src_mask */
1574 0x00000fff, /* dst_mask */
1575 FALSE
), /* pcrel_offset */
1577 HOWTO (R_ARM_TLS_LE12
, /* type */
1579 2, /* size (0 = byte, 1 = short, 2 = long) */
1581 FALSE
, /* pc_relative */
1583 complain_overflow_bitfield
,/* complain_on_overflow */
1584 bfd_elf_generic_reloc
, /* special_function */
1585 "R_ARM_TLS_LE12", /* name */
1586 FALSE
, /* partial_inplace */
1587 0x00000fff, /* src_mask */
1588 0x00000fff, /* dst_mask */
1589 FALSE
), /* pcrel_offset */
1591 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1593 2, /* size (0 = byte, 1 = short, 2 = long) */
1595 FALSE
, /* pc_relative */
1597 complain_overflow_bitfield
,/* complain_on_overflow */
1598 bfd_elf_generic_reloc
, /* special_function */
1599 "R_ARM_TLS_IE12GP", /* name */
1600 FALSE
, /* partial_inplace */
1601 0x00000fff, /* src_mask */
1602 0x00000fff, /* dst_mask */
1603 FALSE
), /* pcrel_offset */
1606 /* 112-127 private relocations
1607 128 R_ARM_ME_TOO, obsolete
1608 129-255 unallocated in AAELF.
1610 249-255 extended, currently unused, relocations: */
1612 static reloc_howto_type elf32_arm_howto_table_2
[4] =
1614 HOWTO (R_ARM_RREL32
, /* type */
1616 0, /* size (0 = byte, 1 = short, 2 = long) */
1618 FALSE
, /* pc_relative */
1620 complain_overflow_dont
,/* complain_on_overflow */
1621 bfd_elf_generic_reloc
, /* special_function */
1622 "R_ARM_RREL32", /* name */
1623 FALSE
, /* partial_inplace */
1626 FALSE
), /* pcrel_offset */
1628 HOWTO (R_ARM_RABS32
, /* type */
1630 0, /* size (0 = byte, 1 = short, 2 = long) */
1632 FALSE
, /* pc_relative */
1634 complain_overflow_dont
,/* complain_on_overflow */
1635 bfd_elf_generic_reloc
, /* special_function */
1636 "R_ARM_RABS32", /* name */
1637 FALSE
, /* partial_inplace */
1640 FALSE
), /* pcrel_offset */
1642 HOWTO (R_ARM_RPC24
, /* type */
1644 0, /* size (0 = byte, 1 = short, 2 = long) */
1646 FALSE
, /* pc_relative */
1648 complain_overflow_dont
,/* complain_on_overflow */
1649 bfd_elf_generic_reloc
, /* special_function */
1650 "R_ARM_RPC24", /* name */
1651 FALSE
, /* partial_inplace */
1654 FALSE
), /* pcrel_offset */
1656 HOWTO (R_ARM_RBASE
, /* type */
1658 0, /* size (0 = byte, 1 = short, 2 = long) */
1660 FALSE
, /* pc_relative */
1662 complain_overflow_dont
,/* complain_on_overflow */
1663 bfd_elf_generic_reloc
, /* special_function */
1664 "R_ARM_RBASE", /* name */
1665 FALSE
, /* partial_inplace */
1668 FALSE
) /* pcrel_offset */
1671 static reloc_howto_type
*
1672 elf32_arm_howto_from_type (unsigned int r_type
)
1674 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1675 return &elf32_arm_howto_table_1
[r_type
];
1677 if (r_type
>= R_ARM_RREL32
1678 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_2
))
1679 return &elf32_arm_howto_table_2
[r_type
- R_ARM_RREL32
];
1685 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1686 Elf_Internal_Rela
* elf_reloc
)
1688 unsigned int r_type
;
1690 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1691 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1694 struct elf32_arm_reloc_map
1696 bfd_reloc_code_real_type bfd_reloc_val
;
1697 unsigned char elf_reloc_val
;
1700 /* All entries in this list must also be present in elf32_arm_howto_table. */
1701 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1703 {BFD_RELOC_NONE
, R_ARM_NONE
},
1704 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1705 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1706 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1707 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1708 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1709 {BFD_RELOC_32
, R_ARM_ABS32
},
1710 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1711 {BFD_RELOC_8
, R_ARM_ABS8
},
1712 {BFD_RELOC_16
, R_ARM_ABS16
},
1713 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1714 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1718 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1719 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1720 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1721 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1722 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1723 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1724 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1725 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1726 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1727 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1728 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1729 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1730 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1731 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1732 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1733 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1734 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1735 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1736 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1737 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1738 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1739 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1740 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1741 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1742 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1743 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1744 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1745 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1746 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1747 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1748 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1749 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1750 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1751 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1752 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1753 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1754 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1755 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1756 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1757 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1758 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1759 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1760 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1761 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1762 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1763 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1764 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1765 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1766 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1767 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1768 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1769 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1770 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1771 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1772 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1773 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1774 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1775 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1776 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1777 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1778 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1779 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
1780 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
}
1783 static reloc_howto_type
*
1784 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1785 bfd_reloc_code_real_type code
)
1789 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
1790 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1791 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1796 static reloc_howto_type
*
1797 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1802 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
1803 if (elf32_arm_howto_table_1
[i
].name
!= NULL
1804 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
1805 return &elf32_arm_howto_table_1
[i
];
1807 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
1808 if (elf32_arm_howto_table_2
[i
].name
!= NULL
1809 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
1810 return &elf32_arm_howto_table_2
[i
];
1815 /* Support for core dump NOTE sections. */
1818 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1823 switch (note
->descsz
)
1828 case 148: /* Linux/ARM 32-bit. */
1830 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1833 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1842 /* Make a ".reg/999" section. */
1843 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1844 size
, note
->descpos
+ offset
);
1848 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1850 switch (note
->descsz
)
1855 case 124: /* Linux/ARM elf_prpsinfo. */
1856 elf_tdata (abfd
)->core_program
1857 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1858 elf_tdata (abfd
)->core_command
1859 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1862 /* Note that for some reason, a spurious space is tacked
1863 onto the end of the args in some (at least one anyway)
1864 implementations, so strip it off if it exists. */
1866 char *command
= elf_tdata (abfd
)->core_command
;
1867 int n
= strlen (command
);
1869 if (0 < n
&& command
[n
- 1] == ' ')
1870 command
[n
- 1] = '\0';
1876 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1877 #define TARGET_LITTLE_NAME "elf32-littlearm"
1878 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1879 #define TARGET_BIG_NAME "elf32-bigarm"
1881 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1882 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1884 typedef unsigned long int insn32
;
1885 typedef unsigned short int insn16
;
1887 /* In lieu of proper flags, assume all EABIv4 or later objects are
1889 #define INTERWORK_FLAG(abfd) \
1890 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1891 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK) \
1892 || ((abfd)->flags & BFD_LINKER_CREATED))
1894 /* The linker script knows the section names for placement.
1895 The entry_names are used to do simple name mangling on the stubs.
1896 Given a function name, and its type, the stub can be found. The
1897 name can be changed. The only requirement is the %s be present. */
1898 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1899 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1901 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1902 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1904 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1905 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1907 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1908 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1910 #define STUB_ENTRY_NAME "__%s_veneer"
1912 /* The name of the dynamic interpreter. This is put in the .interp
1914 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1916 #ifdef FOUR_WORD_PLT
1918 /* The first entry in a procedure linkage table looks like
1919 this. It is set up so that any shared library function that is
1920 called before the relocation has been set up calls the dynamic
1922 static const bfd_vma elf32_arm_plt0_entry
[] =
1924 0xe52de004, /* str lr, [sp, #-4]! */
1925 0xe59fe010, /* ldr lr, [pc, #16] */
1926 0xe08fe00e, /* add lr, pc, lr */
1927 0xe5bef008, /* ldr pc, [lr, #8]! */
1930 /* Subsequent entries in a procedure linkage table look like
1932 static const bfd_vma elf32_arm_plt_entry
[] =
1934 0xe28fc600, /* add ip, pc, #NN */
1935 0xe28cca00, /* add ip, ip, #NN */
1936 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1937 0x00000000, /* unused */
1942 /* The first entry in a procedure linkage table looks like
1943 this. It is set up so that any shared library function that is
1944 called before the relocation has been set up calls the dynamic
1946 static const bfd_vma elf32_arm_plt0_entry
[] =
1948 0xe52de004, /* str lr, [sp, #-4]! */
1949 0xe59fe004, /* ldr lr, [pc, #4] */
1950 0xe08fe00e, /* add lr, pc, lr */
1951 0xe5bef008, /* ldr pc, [lr, #8]! */
1952 0x00000000, /* &GOT[0] - . */
1955 /* Subsequent entries in a procedure linkage table look like
1957 static const bfd_vma elf32_arm_plt_entry
[] =
1959 0xe28fc600, /* add ip, pc, #0xNN00000 */
1960 0xe28cca00, /* add ip, ip, #0xNN000 */
1961 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1966 /* The format of the first entry in the procedure linkage table
1967 for a VxWorks executable. */
1968 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
1970 0xe52dc008, /* str ip,[sp,#-8]! */
1971 0xe59fc000, /* ldr ip,[pc] */
1972 0xe59cf008, /* ldr pc,[ip,#8] */
1973 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1976 /* The format of subsequent entries in a VxWorks executable. */
1977 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
1979 0xe59fc000, /* ldr ip,[pc] */
1980 0xe59cf000, /* ldr pc,[ip] */
1981 0x00000000, /* .long @got */
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xea000000, /* b _PLT */
1984 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1987 /* The format of entries in a VxWorks shared library. */
1988 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
1990 0xe59fc000, /* ldr ip,[pc] */
1991 0xe79cf009, /* ldr pc,[ip,r9] */
1992 0x00000000, /* .long @got */
1993 0xe59fc000, /* ldr ip,[pc] */
1994 0xe599f008, /* ldr pc,[r9,#8] */
1995 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1998 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1999 #define PLT_THUMB_STUB_SIZE 4
2000 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
2006 /* The entries in a PLT when using a DLL-based target with multiple
2008 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2010 0xe51ff004, /* ldr pc, [pc, #-4] */
2011 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2014 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2015 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2016 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2017 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2018 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2019 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2029 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2030 /* A bit of a hack. A Thumb conditional branch, in which the proper condition
2031 is inserted in arm_build_one_stub(). */
2032 #define THUMB16_BCOND_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 1}
2033 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2034 #define THUMB32_B_INSN(X, Z) {(X), THUMB32_TYPE, R_ARM_THM_JUMP24, (Z)}
2035 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2036 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2037 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2042 enum stub_insn_type type
;
2043 unsigned int r_type
;
2047 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2048 to reach the stub if necessary. */
2049 static const insn_sequence elf32_arm_stub_long_branch_any_any
[] =
2051 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2052 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2055 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2057 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb
[] =
2059 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2060 ARM_INSN(0xe12fff1c), /* bx ip */
2061 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2064 /* Thumb -> Thumb long branch stub. Used on M-profile architectures. */
2065 static const insn_sequence elf32_arm_stub_long_branch_thumb_only
[] =
2067 THUMB16_INSN(0xb401), /* push {r0} */
2068 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2069 THUMB16_INSN(0x4684), /* mov ip, r0 */
2070 THUMB16_INSN(0xbc01), /* pop {r0} */
2071 THUMB16_INSN(0x4760), /* bx ip */
2072 THUMB16_INSN(0xbf00), /* nop */
2073 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2076 /* V4T Thumb -> Thumb long branch stub. Using the stack is not
2078 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb
[] =
2080 THUMB16_INSN(0x4778), /* bx pc */
2081 THUMB16_INSN(0x46c0), /* nop */
2082 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2083 ARM_INSN(0xe12fff1c), /* bx ip */
2084 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2087 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2089 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm
[] =
2091 THUMB16_INSN(0x4778), /* bx pc */
2092 THUMB16_INSN(0x46c0), /* nop */
2093 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2094 DATA_WORD(0, R_ARM_ABS32
, 0), /* dcd R_ARM_ABS32(X) */
2097 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2098 one, when the destination is close enough. */
2099 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm
[] =
2101 THUMB16_INSN(0x4778), /* bx pc */
2102 THUMB16_INSN(0x46c0), /* nop */
2103 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2106 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2107 blx to reach the stub if necessary. */
2108 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic
[] =
2110 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2111 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2112 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X-4) */
2115 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2116 blx to reach the stub if necessary. We can not add into pc;
2117 it is not guaranteed to mode switch (different in ARMv6 and
2119 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic
[] =
2121 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2122 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2123 ARM_INSN(0xe12fff1c), /* bx ip */
2124 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2127 /* V4T ARM -> ARM long branch stub, PIC. */
2128 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic
[] =
2130 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2131 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2132 ARM_INSN(0xe12fff1c), /* bx ip */
2133 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2136 /* V4T Thumb -> ARM long branch stub, PIC. */
2137 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic
[] =
2139 THUMB16_INSN(0x4778), /* bx pc */
2140 THUMB16_INSN(0x46c0), /* nop */
2141 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2142 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2143 DATA_WORD(0, R_ARM_REL32
, -4), /* dcd R_ARM_REL32(X) */
2146 /* Thumb -> Thumb long branch stub, PIC. Used on M-profile
2148 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic
[] =
2150 THUMB16_INSN(0xb401), /* push {r0} */
2151 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2152 THUMB16_INSN(0x46fc), /* mov ip, pc */
2153 THUMB16_INSN(0x4484), /* add ip, r0 */
2154 THUMB16_INSN(0xbc01), /* pop {r0} */
2155 THUMB16_INSN(0x4760), /* bx ip */
2156 DATA_WORD(0, R_ARM_REL32
, 4), /* dcd R_ARM_REL32(X) */
2159 /* V4T Thumb -> Thumb long branch stub, PIC. Using the stack is not
2161 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_thumb_pic
[] =
2163 THUMB16_INSN(0x4778), /* bx pc */
2164 THUMB16_INSN(0x46c0), /* nop */
2165 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2166 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2167 ARM_INSN(0xe12fff1c), /* bx ip */
2168 DATA_WORD(0, R_ARM_REL32
, 0), /* dcd R_ARM_REL32(X) */
2171 /* Cortex-A8 erratum-workaround stubs. */
2173 /* Stub used for conditional branches (which may be beyond +/-1MB away, so we
2174 can't use a conditional branch to reach this stub). */
2176 static const insn_sequence elf32_arm_stub_a8_veneer_b_cond
[] =
2178 THUMB16_BCOND_INSN(0xd001), /* b<cond>.n true. */
2179 THUMB32_B_INSN(0xf000b800, -4), /* b.w insn_after_original_branch. */
2180 THUMB32_B_INSN(0xf000b800, -4) /* true: b.w original_branch_dest. */
2183 /* Stub used for b.w and bl.w instructions. */
2185 static const insn_sequence elf32_arm_stub_a8_veneer_b
[] =
2187 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2190 static const insn_sequence elf32_arm_stub_a8_veneer_bl
[] =
2192 THUMB32_B_INSN(0xf000b800, -4) /* b.w original_branch_dest. */
2195 /* Stub used for Thumb-2 blx.w instructions. We modified the original blx.w
2196 instruction (which switches to ARM mode) to point to this stub. Jump to the
2197 real destination using an ARM-mode branch. */
2199 static const insn_sequence elf32_arm_stub_a8_veneer_blx
[] =
2201 ARM_REL_INSN(0xea000000, -8) /* b original_branch_dest. */
2204 /* Section name for stubs is the associated section name plus this
2206 #define STUB_SUFFIX ".stub"
2208 /* One entry per long/short branch stub defined above. */
2210 DEF_STUB(long_branch_any_any) \
2211 DEF_STUB(long_branch_v4t_arm_thumb) \
2212 DEF_STUB(long_branch_thumb_only) \
2213 DEF_STUB(long_branch_v4t_thumb_thumb) \
2214 DEF_STUB(long_branch_v4t_thumb_arm) \
2215 DEF_STUB(short_branch_v4t_thumb_arm) \
2216 DEF_STUB(long_branch_any_arm_pic) \
2217 DEF_STUB(long_branch_any_thumb_pic) \
2218 DEF_STUB(long_branch_v4t_thumb_thumb_pic) \
2219 DEF_STUB(long_branch_v4t_arm_thumb_pic) \
2220 DEF_STUB(long_branch_v4t_thumb_arm_pic) \
2221 DEF_STUB(long_branch_thumb_only_pic) \
2222 DEF_STUB(a8_veneer_b_cond) \
2223 DEF_STUB(a8_veneer_b) \
2224 DEF_STUB(a8_veneer_bl) \
2225 DEF_STUB(a8_veneer_blx)
2227 #define DEF_STUB(x) arm_stub_##x,
2228 enum elf32_arm_stub_type
{
2236 const insn_sequence
* template;
2240 #define DEF_STUB(x) {elf32_arm_stub_##x, ARRAY_SIZE(elf32_arm_stub_##x)},
2241 static const stub_def stub_definitions
[] = {
2246 struct elf32_arm_stub_hash_entry
2248 /* Base hash table entry structure. */
2249 struct bfd_hash_entry root
;
2251 /* The stub section. */
2254 /* Offset within stub_sec of the beginning of this stub. */
2255 bfd_vma stub_offset
;
2257 /* Given the symbol's value and its section we can determine its final
2258 value when building the stubs (so the stub knows where to jump). */
2259 bfd_vma target_value
;
2260 asection
*target_section
;
2262 /* Offset to apply to relocation referencing target_value. */
2263 bfd_vma target_addend
;
2265 /* The instruction which caused this stub to be generated (only valid for
2266 Cortex-A8 erratum workaround stubs at present). */
2267 unsigned long orig_insn
;
2269 /* The stub type. */
2270 enum elf32_arm_stub_type stub_type
;
2271 /* Its encoding size in bytes. */
2274 const insn_sequence
*stub_template
;
2275 /* The size of the template (number of entries). */
2276 int stub_template_size
;
2278 /* The symbol table entry, if any, that this was derived from. */
2279 struct elf32_arm_link_hash_entry
*h
;
2281 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2282 unsigned char st_type
;
2284 /* Where this stub is being called from, or, in the case of combined
2285 stub sections, the first input section in the group. */
2288 /* The name for the local symbol at the start of this stub. The
2289 stub name in the hash table has to be unique; this does not, so
2290 it can be friendlier. */
2294 /* Used to build a map of a section. This is required for mixed-endian
2297 typedef struct elf32_elf_section_map
2302 elf32_arm_section_map
;
2304 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2308 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2309 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2310 VFP11_ERRATUM_ARM_VENEER
,
2311 VFP11_ERRATUM_THUMB_VENEER
2313 elf32_vfp11_erratum_type
;
2315 typedef struct elf32_vfp11_erratum_list
2317 struct elf32_vfp11_erratum_list
*next
;
2323 struct elf32_vfp11_erratum_list
*veneer
;
2324 unsigned int vfp_insn
;
2328 struct elf32_vfp11_erratum_list
*branch
;
2332 elf32_vfp11_erratum_type type
;
2334 elf32_vfp11_erratum_list
;
2339 INSERT_EXIDX_CANTUNWIND_AT_END
2341 arm_unwind_edit_type
;
2343 /* A (sorted) list of edits to apply to an unwind table. */
2344 typedef struct arm_unwind_table_edit
2346 arm_unwind_edit_type type
;
2347 /* Note: we sometimes want to insert an unwind entry corresponding to a
2348 section different from the one we're currently writing out, so record the
2349 (text) section this edit relates to here. */
2350 asection
*linked_section
;
2352 struct arm_unwind_table_edit
*next
;
2354 arm_unwind_table_edit
;
2356 typedef struct _arm_elf_section_data
2358 /* Information about mapping symbols. */
2359 struct bfd_elf_section_data elf
;
2360 unsigned int mapcount
;
2361 unsigned int mapsize
;
2362 elf32_arm_section_map
*map
;
2363 /* Information about CPU errata. */
2364 unsigned int erratumcount
;
2365 elf32_vfp11_erratum_list
*erratumlist
;
2366 /* Information about unwind tables. */
2369 /* Unwind info attached to a text section. */
2372 asection
*arm_exidx_sec
;
2375 /* Unwind info attached to an .ARM.exidx section. */
2378 arm_unwind_table_edit
*unwind_edit_list
;
2379 arm_unwind_table_edit
*unwind_edit_tail
;
2383 _arm_elf_section_data
;
2385 #define elf32_arm_section_data(sec) \
2386 ((_arm_elf_section_data *) elf_section_data (sec))
2388 /* A fix which might be required for Cortex-A8 Thumb-2 branch/TLB erratum.
2389 These fixes are subject to a relaxation procedure (in elf32_arm_size_stubs),
2390 so may be created multiple times: we use an array of these entries whilst
2391 relaxing which we can refresh easily, then create stubs for each potentially
2392 erratum-triggering instruction once we've settled on a solution. */
2394 struct a8_erratum_fix
{
2399 unsigned long orig_insn
;
2401 enum elf32_arm_stub_type stub_type
;
2404 /* A table of relocs applied to branches which might trigger Cortex-A8
2407 struct a8_erratum_reloc
{
2409 bfd_vma destination
;
2410 unsigned int r_type
;
2411 unsigned char st_type
;
2412 const char *sym_name
;
2413 bfd_boolean non_a8_stub
;
2416 /* The size of the thread control block. */
2419 struct elf_arm_obj_tdata
2421 struct elf_obj_tdata root
;
2423 /* tls_type for each local got entry. */
2424 char *local_got_tls_type
;
2426 /* Zero to warn when linking objects with incompatible enum sizes. */
2427 int no_enum_size_warning
;
2429 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2430 int no_wchar_size_warning
;
2433 #define elf_arm_tdata(bfd) \
2434 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2436 #define elf32_arm_local_got_tls_type(bfd) \
2437 (elf_arm_tdata (bfd)->local_got_tls_type)
2439 #define is_arm_elf(bfd) \
2440 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2441 && elf_tdata (bfd) != NULL \
2442 && elf_object_id (bfd) == ARM_ELF_TDATA)
2445 elf32_arm_mkobject (bfd
*abfd
)
2447 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2451 /* The ARM linker needs to keep track of the number of relocs that it
2452 decides to copy in check_relocs for each symbol. This is so that
2453 it can discard PC relative relocs if it doesn't need them when
2454 linking with -Bsymbolic. We store the information in a field
2455 extending the regular ELF linker hash table. */
2457 /* This structure keeps track of the number of relocs we have copied
2458 for a given symbol. */
2459 struct elf32_arm_relocs_copied
2462 struct elf32_arm_relocs_copied
* next
;
2463 /* A section in dynobj. */
2465 /* Number of relocs copied in this section. */
2466 bfd_size_type count
;
2467 /* Number of PC-relative relocs copied in this section. */
2468 bfd_size_type pc_count
;
2471 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2473 /* Arm ELF linker hash entry. */
2474 struct elf32_arm_link_hash_entry
2476 struct elf_link_hash_entry root
;
2478 /* Number of PC relative relocs copied for this symbol. */
2479 struct elf32_arm_relocs_copied
* relocs_copied
;
2481 /* We reference count Thumb references to a PLT entry separately,
2482 so that we can emit the Thumb trampoline only if needed. */
2483 bfd_signed_vma plt_thumb_refcount
;
2485 /* Some references from Thumb code may be eliminated by BL->BLX
2486 conversion, so record them separately. */
2487 bfd_signed_vma plt_maybe_thumb_refcount
;
2489 /* Since PLT entries have variable size if the Thumb prologue is
2490 used, we need to record the index into .got.plt instead of
2491 recomputing it from the PLT offset. */
2492 bfd_signed_vma plt_got_offset
;
2494 #define GOT_UNKNOWN 0
2495 #define GOT_NORMAL 1
2496 #define GOT_TLS_GD 2
2497 #define GOT_TLS_IE 4
2498 unsigned char tls_type
;
2500 /* The symbol marking the real symbol location for exported thumb
2501 symbols with Arm stubs. */
2502 struct elf_link_hash_entry
*export_glue
;
2504 /* A pointer to the most recently used stub hash entry against this
2506 struct elf32_arm_stub_hash_entry
*stub_cache
;
2509 /* Traverse an arm ELF linker hash table. */
2510 #define elf32_arm_link_hash_traverse(table, func, info) \
2511 (elf_link_hash_traverse \
2513 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2516 /* Get the ARM elf linker hash table from a link_info structure. */
2517 #define elf32_arm_hash_table(info) \
2518 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2520 #define arm_stub_hash_lookup(table, string, create, copy) \
2521 ((struct elf32_arm_stub_hash_entry *) \
2522 bfd_hash_lookup ((table), (string), (create), (copy)))
2524 /* ARM ELF linker hash table. */
2525 struct elf32_arm_link_hash_table
2527 /* The main hash table. */
2528 struct elf_link_hash_table root
;
2530 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2531 bfd_size_type thumb_glue_size
;
2533 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2534 bfd_size_type arm_glue_size
;
2536 /* The size in bytes of section containing the ARMv4 BX veneers. */
2537 bfd_size_type bx_glue_size
;
2539 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2540 veneer has been populated. */
2541 bfd_vma bx_glue_offset
[15];
2543 /* The size in bytes of the section containing glue for VFP11 erratum
2545 bfd_size_type vfp11_erratum_glue_size
;
2547 /* A table of fix locations for Cortex-A8 Thumb-2 branch/TLB erratum. This
2548 holds Cortex-A8 erratum fix locations between elf32_arm_size_stubs() and
2549 elf32_arm_write_section(). */
2550 struct a8_erratum_fix
*a8_erratum_fixes
;
2551 unsigned int num_a8_erratum_fixes
;
2553 /* An arbitrary input BFD chosen to hold the glue sections. */
2554 bfd
* bfd_of_glue_owner
;
2556 /* Nonzero to output a BE8 image. */
2559 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2560 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2563 /* The relocation to use for R_ARM_TARGET2 relocations. */
2566 /* 0 = Ignore R_ARM_V4BX.
2567 1 = Convert BX to MOV PC.
2568 2 = Generate v4 interworing stubs. */
2571 /* Whether we should fix the Cortex-A8 Thumb-2 branch/TLB erratum. */
2574 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2577 /* What sort of code sequences we should look for which may trigger the
2578 VFP11 denorm erratum. */
2579 bfd_arm_vfp11_fix vfp11_fix
;
2581 /* Global counter for the number of fixes we have emitted. */
2582 int num_vfp11_fixes
;
2584 /* Nonzero to force PIC branch veneers. */
2587 /* The number of bytes in the initial entry in the PLT. */
2588 bfd_size_type plt_header_size
;
2590 /* The number of bytes in the subsequent PLT etries. */
2591 bfd_size_type plt_entry_size
;
2593 /* True if the target system is VxWorks. */
2596 /* True if the target system is Symbian OS. */
2599 /* True if the target uses REL relocations. */
2602 /* Short-cuts to get to dynamic linker sections. */
2611 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2614 /* Data for R_ARM_TLS_LDM32 relocations. */
2617 bfd_signed_vma refcount
;
2621 /* Small local sym cache. */
2622 struct sym_cache sym_cache
;
2624 /* For convenience in allocate_dynrelocs. */
2627 /* The stub hash table. */
2628 struct bfd_hash_table stub_hash_table
;
2630 /* Linker stub bfd. */
2633 /* Linker call-backs. */
2634 asection
* (*add_stub_section
) (const char *, asection
*);
2635 void (*layout_sections_again
) (void);
2637 /* Array to keep track of which stub sections have been created, and
2638 information on stub grouping. */
2641 /* This is the section to which stubs in the group will be
2644 /* The stub section. */
2648 /* Assorted information used by elf32_arm_size_stubs. */
2649 unsigned int bfd_count
;
2651 asection
**input_list
;
2654 /* Create an entry in an ARM ELF linker hash table. */
2656 static struct bfd_hash_entry
*
2657 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
2658 struct bfd_hash_table
* table
,
2659 const char * string
)
2661 struct elf32_arm_link_hash_entry
* ret
=
2662 (struct elf32_arm_link_hash_entry
*) entry
;
2664 /* Allocate the structure if it has not already been allocated by a
2667 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
2669 return (struct bfd_hash_entry
*) ret
;
2671 /* Call the allocation method of the superclass. */
2672 ret
= ((struct elf32_arm_link_hash_entry
*)
2673 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2677 ret
->relocs_copied
= NULL
;
2678 ret
->tls_type
= GOT_UNKNOWN
;
2679 ret
->plt_thumb_refcount
= 0;
2680 ret
->plt_maybe_thumb_refcount
= 0;
2681 ret
->plt_got_offset
= -1;
2682 ret
->export_glue
= NULL
;
2684 ret
->stub_cache
= NULL
;
2687 return (struct bfd_hash_entry
*) ret
;
2690 /* Initialize an entry in the stub hash table. */
2692 static struct bfd_hash_entry
*
2693 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2694 struct bfd_hash_table
*table
,
2697 /* Allocate the structure if it has not already been allocated by a
2701 entry
= bfd_hash_allocate (table
,
2702 sizeof (struct elf32_arm_stub_hash_entry
));
2707 /* Call the allocation method of the superclass. */
2708 entry
= bfd_hash_newfunc (entry
, table
, string
);
2711 struct elf32_arm_stub_hash_entry
*eh
;
2713 /* Initialize the local fields. */
2714 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
2715 eh
->stub_sec
= NULL
;
2716 eh
->stub_offset
= 0;
2717 eh
->target_value
= 0;
2718 eh
->target_section
= NULL
;
2719 eh
->stub_type
= arm_stub_none
;
2721 eh
->stub_template
= NULL
;
2722 eh
->stub_template_size
= 0;
2730 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2731 shortcuts to them in our hash table. */
2734 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
2736 struct elf32_arm_link_hash_table
*htab
;
2738 htab
= elf32_arm_hash_table (info
);
2739 /* BPABI objects never have a GOT, or associated sections. */
2740 if (htab
->symbian_p
)
2743 if (! _bfd_elf_create_got_section (dynobj
, info
))
2746 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2747 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2748 if (!htab
->sgot
|| !htab
->sgotplt
)
2751 htab
->srelgot
= bfd_get_section_by_name (dynobj
,
2752 RELOC_SECTION (htab
, ".got"));
2753 if (htab
->srelgot
== NULL
)
2758 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2759 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2763 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
2765 struct elf32_arm_link_hash_table
*htab
;
2767 htab
= elf32_arm_hash_table (info
);
2768 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2771 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2774 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2775 htab
->srelplt
= bfd_get_section_by_name (dynobj
,
2776 RELOC_SECTION (htab
, ".plt"));
2777 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2779 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
2780 RELOC_SECTION (htab
, ".bss"));
2782 if (htab
->vxworks_p
)
2784 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
2789 htab
->plt_header_size
= 0;
2790 htab
->plt_entry_size
2791 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
2795 htab
->plt_header_size
2796 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
2797 htab
->plt_entry_size
2798 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
2805 || (!info
->shared
&& !htab
->srelbss
))
2811 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2814 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
2815 struct elf_link_hash_entry
*dir
,
2816 struct elf_link_hash_entry
*ind
)
2818 struct elf32_arm_link_hash_entry
*edir
, *eind
;
2820 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
2821 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
2823 if (eind
->relocs_copied
!= NULL
)
2825 if (edir
->relocs_copied
!= NULL
)
2827 struct elf32_arm_relocs_copied
**pp
;
2828 struct elf32_arm_relocs_copied
*p
;
2830 /* Add reloc counts against the indirect sym to the direct sym
2831 list. Merge any entries against the same section. */
2832 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
2834 struct elf32_arm_relocs_copied
*q
;
2836 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
2837 if (q
->section
== p
->section
)
2839 q
->pc_count
+= p
->pc_count
;
2840 q
->count
+= p
->count
;
2847 *pp
= edir
->relocs_copied
;
2850 edir
->relocs_copied
= eind
->relocs_copied
;
2851 eind
->relocs_copied
= NULL
;
2854 if (ind
->root
.type
== bfd_link_hash_indirect
)
2856 /* Copy over PLT info. */
2857 edir
->plt_thumb_refcount
+= eind
->plt_thumb_refcount
;
2858 eind
->plt_thumb_refcount
= 0;
2859 edir
->plt_maybe_thumb_refcount
+= eind
->plt_maybe_thumb_refcount
;
2860 eind
->plt_maybe_thumb_refcount
= 0;
2862 if (dir
->got
.refcount
<= 0)
2864 edir
->tls_type
= eind
->tls_type
;
2865 eind
->tls_type
= GOT_UNKNOWN
;
2869 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2872 /* Create an ARM elf linker hash table. */
2874 static struct bfd_link_hash_table
*
2875 elf32_arm_link_hash_table_create (bfd
*abfd
)
2877 struct elf32_arm_link_hash_table
*ret
;
2878 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
2880 ret
= bfd_malloc (amt
);
2884 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
2885 elf32_arm_link_hash_newfunc
,
2886 sizeof (struct elf32_arm_link_hash_entry
)))
2893 ret
->sgotplt
= NULL
;
2894 ret
->srelgot
= NULL
;
2896 ret
->srelplt
= NULL
;
2897 ret
->sdynbss
= NULL
;
2898 ret
->srelbss
= NULL
;
2899 ret
->srelplt2
= NULL
;
2900 ret
->thumb_glue_size
= 0;
2901 ret
->arm_glue_size
= 0;
2902 ret
->bx_glue_size
= 0;
2903 memset (ret
->bx_glue_offset
, 0, sizeof (ret
->bx_glue_offset
));
2904 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
2905 ret
->vfp11_erratum_glue_size
= 0;
2906 ret
->num_vfp11_fixes
= 0;
2907 ret
->fix_cortex_a8
= 0;
2908 ret
->bfd_of_glue_owner
= NULL
;
2909 ret
->byteswap_code
= 0;
2910 ret
->target1_is_rel
= 0;
2911 ret
->target2_reloc
= R_ARM_NONE
;
2912 #ifdef FOUR_WORD_PLT
2913 ret
->plt_header_size
= 16;
2914 ret
->plt_entry_size
= 16;
2916 ret
->plt_header_size
= 20;
2917 ret
->plt_entry_size
= 12;
2924 ret
->sym_cache
.abfd
= NULL
;
2926 ret
->tls_ldm_got
.refcount
= 0;
2927 ret
->stub_bfd
= NULL
;
2928 ret
->add_stub_section
= NULL
;
2929 ret
->layout_sections_again
= NULL
;
2930 ret
->stub_group
= NULL
;
2933 ret
->input_list
= NULL
;
2935 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2936 sizeof (struct elf32_arm_stub_hash_entry
)))
2942 return &ret
->root
.root
;
2945 /* Free the derived linker hash table. */
2948 elf32_arm_hash_table_free (struct bfd_link_hash_table
*hash
)
2950 struct elf32_arm_link_hash_table
*ret
2951 = (struct elf32_arm_link_hash_table
*) hash
;
2953 bfd_hash_table_free (&ret
->stub_hash_table
);
2954 _bfd_generic_link_hash_table_free (hash
);
2957 /* Determine if we're dealing with a Thumb only architecture. */
2960 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
2962 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2966 if (arch
!= TAG_CPU_ARCH_V7
)
2969 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2970 Tag_CPU_arch_profile
);
2972 return profile
== 'M';
2975 /* Determine if we're dealing with a Thumb-2 object. */
2978 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
2980 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2982 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
2986 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
2990 case arm_stub_long_branch_thumb_only
:
2991 case arm_stub_long_branch_v4t_thumb_arm
:
2992 case arm_stub_short_branch_v4t_thumb_arm
:
2993 case arm_stub_long_branch_v4t_thumb_arm_pic
:
2994 case arm_stub_long_branch_thumb_only_pic
:
3005 /* Determine the type of stub needed, if any, for a call. */
3007 static enum elf32_arm_stub_type
3008 arm_type_of_stub (struct bfd_link_info
*info
,
3009 asection
*input_sec
,
3010 const Elf_Internal_Rela
*rel
,
3011 unsigned char st_type
,
3012 struct elf32_arm_link_hash_entry
*hash
,
3013 bfd_vma destination
,
3019 bfd_signed_vma branch_offset
;
3020 unsigned int r_type
;
3021 struct elf32_arm_link_hash_table
* globals
;
3024 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
3027 /* We don't know the actual type of destination in case it is of
3028 type STT_SECTION: give up. */
3029 if (st_type
== STT_SECTION
)
3032 globals
= elf32_arm_hash_table (info
);
3034 thumb_only
= using_thumb_only (globals
);
3036 thumb2
= using_thumb2 (globals
);
3038 /* Determine where the call point is. */
3039 location
= (input_sec
->output_offset
3040 + input_sec
->output_section
->vma
3043 branch_offset
= (bfd_signed_vma
)(destination
- location
);
3045 r_type
= ELF32_R_TYPE (rel
->r_info
);
3047 /* Keep a simpler condition, for the sake of clarity. */
3048 if (globals
->splt
!= NULL
&& hash
!= NULL
&& hash
->root
.plt
.offset
!= (bfd_vma
) -1)
3051 /* Note when dealing with PLT entries: the main PLT stub is in
3052 ARM mode, so if the branch is in Thumb mode, another
3053 Thumb->ARM stub will be inserted later just before the ARM
3054 PLT stub. We don't take this extra distance into account
3055 here, because if a long branch stub is needed, we'll add a
3056 Thumb->Arm one and branch directly to the ARM PLT entry
3057 because it avoids spreading offset corrections in several
3061 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
3063 /* Handle cases where:
3064 - this call goes too far (different Thumb/Thumb2 max
3066 - it's a Thumb->Arm call and blx is not available, or it's a
3067 Thumb->Arm branch (not bl). A stub is needed in this case,
3068 but only if this call is not through a PLT entry. Indeed,
3069 PLT stubs handle mode switching already.
3072 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
3073 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
3075 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
3076 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
3077 || ((st_type
!= STT_ARM_TFUNC
)
3078 && (((r_type
== R_ARM_THM_CALL
) && !globals
->use_blx
)
3079 || (r_type
== R_ARM_THM_JUMP24
))
3082 if (st_type
== STT_ARM_TFUNC
)
3084 /* Thumb to thumb. */
3087 stub_type
= (info
->shared
| globals
->pic_veneer
)
3089 ? ((globals
->use_blx
3090 && (r_type
==R_ARM_THM_CALL
))
3091 /* V5T and above. Stub starts with ARM code, so
3092 we must be able to switch mode before
3093 reaching it, which is only possible for 'bl'
3094 (ie R_ARM_THM_CALL relocation). */
3095 ? arm_stub_long_branch_any_thumb_pic
3096 /* On V4T, use Thumb code only. */
3097 : arm_stub_long_branch_v4t_thumb_thumb_pic
)
3099 /* non-PIC stubs. */
3100 : ((globals
->use_blx
3101 && (r_type
==R_ARM_THM_CALL
))
3102 /* V5T and above. */
3103 ? arm_stub_long_branch_any_any
3105 : arm_stub_long_branch_v4t_thumb_thumb
);
3109 stub_type
= (info
->shared
| globals
->pic_veneer
)
3111 ? arm_stub_long_branch_thumb_only_pic
3113 : arm_stub_long_branch_thumb_only
;
3120 && sym_sec
->owner
!= NULL
3121 && !INTERWORK_FLAG (sym_sec
->owner
))
3123 (*_bfd_error_handler
)
3124 (_("%B(%s): warning: interworking not enabled.\n"
3125 " first occurrence: %B: Thumb call to ARM"),
3126 sym_sec
->owner
, input_bfd
, name
);
3129 stub_type
= (info
->shared
| globals
->pic_veneer
)
3131 ? ((globals
->use_blx
3132 && (r_type
==R_ARM_THM_CALL
))
3133 /* V5T and above. */
3134 ? arm_stub_long_branch_any_arm_pic
3136 : arm_stub_long_branch_v4t_thumb_arm_pic
)
3138 /* non-PIC stubs. */
3139 : ((globals
->use_blx
3140 && (r_type
==R_ARM_THM_CALL
))
3141 /* V5T and above. */
3142 ? arm_stub_long_branch_any_any
3144 : arm_stub_long_branch_v4t_thumb_arm
);
3146 /* Handle v4t short branches. */
3147 if ((stub_type
== arm_stub_long_branch_v4t_thumb_arm
)
3148 && (branch_offset
<= THM_MAX_FWD_BRANCH_OFFSET
)
3149 && (branch_offset
>= THM_MAX_BWD_BRANCH_OFFSET
))
3150 stub_type
= arm_stub_short_branch_v4t_thumb_arm
;
3154 else if (r_type
== R_ARM_CALL
|| r_type
== R_ARM_JUMP24
|| r_type
== R_ARM_PLT32
)
3156 if (st_type
== STT_ARM_TFUNC
)
3161 && sym_sec
->owner
!= NULL
3162 && !INTERWORK_FLAG (sym_sec
->owner
))
3164 (*_bfd_error_handler
)
3165 (_("%B(%s): warning: interworking not enabled.\n"
3166 " first occurrence: %B: ARM call to Thumb"),
3167 sym_sec
->owner
, input_bfd
, name
);
3170 /* We have an extra 2-bytes reach because of
3171 the mode change (bit 24 (H) of BLX encoding). */
3172 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
3173 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
3174 || ((r_type
== R_ARM_CALL
) && !globals
->use_blx
)
3175 || (r_type
== R_ARM_JUMP24
)
3176 || (r_type
== R_ARM_PLT32
))
3178 stub_type
= (info
->shared
| globals
->pic_veneer
)
3180 ? ((globals
->use_blx
)
3181 /* V5T and above. */
3182 ? arm_stub_long_branch_any_thumb_pic
3184 : arm_stub_long_branch_v4t_arm_thumb_pic
)
3186 /* non-PIC stubs. */
3187 : ((globals
->use_blx
)
3188 /* V5T and above. */
3189 ? arm_stub_long_branch_any_any
3191 : arm_stub_long_branch_v4t_arm_thumb
);
3197 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
3198 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
3200 stub_type
= (info
->shared
| globals
->pic_veneer
)
3202 ? arm_stub_long_branch_any_arm_pic
3203 /* non-PIC stubs. */
3204 : arm_stub_long_branch_any_any
;
3212 /* Build a name for an entry in the stub hash table. */
3215 elf32_arm_stub_name (const asection
*input_section
,
3216 const asection
*sym_sec
,
3217 const struct elf32_arm_link_hash_entry
*hash
,
3218 const Elf_Internal_Rela
*rel
)
3225 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1;
3226 stub_name
= bfd_malloc (len
);
3227 if (stub_name
!= NULL
)
3228 sprintf (stub_name
, "%08x_%s+%x",
3229 input_section
->id
& 0xffffffff,
3230 hash
->root
.root
.root
.string
,
3231 (int) rel
->r_addend
& 0xffffffff);
3235 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3236 stub_name
= bfd_malloc (len
);
3237 if (stub_name
!= NULL
)
3238 sprintf (stub_name
, "%08x_%x:%x+%x",
3239 input_section
->id
& 0xffffffff,
3240 sym_sec
->id
& 0xffffffff,
3241 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
3242 (int) rel
->r_addend
& 0xffffffff);
3248 /* Look up an entry in the stub hash. Stub entries are cached because
3249 creating the stub name takes a bit of time. */
3251 static struct elf32_arm_stub_hash_entry
*
3252 elf32_arm_get_stub_entry (const asection
*input_section
,
3253 const asection
*sym_sec
,
3254 struct elf_link_hash_entry
*hash
,
3255 const Elf_Internal_Rela
*rel
,
3256 struct elf32_arm_link_hash_table
*htab
)
3258 struct elf32_arm_stub_hash_entry
*stub_entry
;
3259 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
3260 const asection
*id_sec
;
3262 if ((input_section
->flags
& SEC_CODE
) == 0)
3265 /* If this input section is part of a group of sections sharing one
3266 stub section, then use the id of the first section in the group.
3267 Stub names need to include a section id, as there may well be
3268 more than one stub used to reach say, printf, and we need to
3269 distinguish between them. */
3270 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3272 if (h
!= NULL
&& h
->stub_cache
!= NULL
3273 && h
->stub_cache
->h
== h
3274 && h
->stub_cache
->id_sec
== id_sec
)
3276 stub_entry
= h
->stub_cache
;
3282 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
);
3283 if (stub_name
== NULL
)
3286 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3287 stub_name
, FALSE
, FALSE
);
3289 h
->stub_cache
= stub_entry
;
3297 /* Find or create a stub section. Returns a pointer to the stub section, and
3298 the section to which the stub section will be attached (in *LINK_SEC_P).
3299 LINK_SEC_P may be NULL. */
3302 elf32_arm_create_or_find_stub_sec (asection
**link_sec_p
, asection
*section
,
3303 struct elf32_arm_link_hash_table
*htab
)
3308 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3309 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3310 if (stub_sec
== NULL
)
3312 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3313 if (stub_sec
== NULL
)
3319 namelen
= strlen (link_sec
->name
);
3320 len
= namelen
+ sizeof (STUB_SUFFIX
);
3321 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3325 memcpy (s_name
, link_sec
->name
, namelen
);
3326 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3327 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3328 if (stub_sec
== NULL
)
3330 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3332 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3336 *link_sec_p
= link_sec
;
3341 /* Add a new stub entry to the stub hash. Not all fields of the new
3342 stub entry are initialised. */
3344 static struct elf32_arm_stub_hash_entry
*
3345 elf32_arm_add_stub (const char *stub_name
,
3347 struct elf32_arm_link_hash_table
*htab
)
3351 struct elf32_arm_stub_hash_entry
*stub_entry
;
3353 stub_sec
= elf32_arm_create_or_find_stub_sec (&link_sec
, section
, htab
);
3354 if (stub_sec
== NULL
)
3357 /* Enter this entry into the linker stub hash table. */
3358 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3360 if (stub_entry
== NULL
)
3362 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3368 stub_entry
->stub_sec
= stub_sec
;
3369 stub_entry
->stub_offset
= 0;
3370 stub_entry
->id_sec
= link_sec
;
3375 /* Store an Arm insn into an output section not processed by
3376 elf32_arm_write_section. */
3379 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
3380 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3382 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3383 bfd_putl32 (val
, ptr
);
3385 bfd_putb32 (val
, ptr
);
3388 /* Store a 16-bit Thumb insn into an output section not processed by
3389 elf32_arm_write_section. */
3392 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
3393 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3395 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3396 bfd_putl16 (val
, ptr
);
3398 bfd_putb16 (val
, ptr
);
3401 static bfd_reloc_status_type elf32_arm_final_link_relocate
3402 (reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
3403 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
3404 const char *, int, struct elf_link_hash_entry
*, bfd_boolean
*, char **);
3407 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3411 struct elf32_arm_stub_hash_entry
*stub_entry
;
3412 struct bfd_link_info
*info
;
3413 struct elf32_arm_link_hash_table
*htab
;
3421 const insn_sequence
*template;
3423 struct elf32_arm_link_hash_table
* globals
;
3424 int stub_reloc_idx
[MAXRELOCS
] = {-1, -1};
3425 int stub_reloc_offset
[MAXRELOCS
] = {0, 0};
3428 /* Massage our args to the form they really have. */
3429 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3430 info
= (struct bfd_link_info
*) in_arg
;
3432 globals
= elf32_arm_hash_table (info
);
3434 htab
= elf32_arm_hash_table (info
);
3435 stub_sec
= stub_entry
->stub_sec
;
3437 /* Make a note of the offset within the stubs for this entry. */
3438 stub_entry
->stub_offset
= stub_sec
->size
;
3439 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3441 stub_bfd
= stub_sec
->owner
;
3443 /* This is the address of the start of the stub. */
3444 stub_addr
= stub_sec
->output_section
->vma
+ stub_sec
->output_offset
3445 + stub_entry
->stub_offset
;
3447 /* This is the address of the stub destination. */
3448 sym_value
= (stub_entry
->target_value
3449 + stub_entry
->target_section
->output_offset
3450 + stub_entry
->target_section
->output_section
->vma
);
3452 template = stub_entry
->stub_template
;
3453 template_size
= stub_entry
->stub_template_size
;
3456 for (i
= 0; i
< template_size
; i
++)
3458 switch (template[i
].type
)
3462 bfd_vma data
= template[i
].data
;
3463 if (template[i
].reloc_addend
!= 0)
3465 /* We've borrowed the reloc_addend field to mean we should
3466 insert a condition code into this (Thumb-1 branch)
3467 instruction. See THUMB16_BCOND_INSN. */
3468 BFD_ASSERT ((data
& 0xff00) == 0xd000);
3469 data
|= ((stub_entry
->orig_insn
>> 22) & 0xf) << 8;
3471 put_thumb_insn (globals
, stub_bfd
, data
, loc
+ size
);
3477 put_thumb_insn (globals
, stub_bfd
, (template[i
].data
>> 16) & 0xffff,
3479 put_thumb_insn (globals
, stub_bfd
, template[i
].data
& 0xffff,
3481 if (template[i
].r_type
!= R_ARM_NONE
)
3483 stub_reloc_idx
[nrelocs
] = i
;
3484 stub_reloc_offset
[nrelocs
++] = size
;
3490 put_arm_insn (globals
, stub_bfd
, template[i
].data
, loc
+ size
);
3491 /* Handle cases where the target is encoded within the
3493 if (template[i
].r_type
== R_ARM_JUMP24
)
3495 stub_reloc_idx
[nrelocs
] = i
;
3496 stub_reloc_offset
[nrelocs
++] = size
;
3502 bfd_put_32 (stub_bfd
, template[i
].data
, loc
+ size
);
3503 stub_reloc_idx
[nrelocs
] = i
;
3504 stub_reloc_offset
[nrelocs
++] = size
;
3514 stub_sec
->size
+= size
;
3516 /* Stub size has already been computed in arm_size_one_stub. Check
3518 BFD_ASSERT (size
== stub_entry
->stub_size
);
3520 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3521 if (stub_entry
->st_type
== STT_ARM_TFUNC
)
3524 /* Assume there is at least one and at most MAXRELOCS entries to relocate
3526 BFD_ASSERT (nrelocs
!= 0 && nrelocs
<= MAXRELOCS
);
3528 for (i
= 0; i
< nrelocs
; i
++)
3529 if (template[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP24
3530 || template[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_JUMP19
3531 || template[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_CALL
3532 || template[stub_reloc_idx
[i
]].r_type
== R_ARM_THM_XPC22
)
3534 Elf_Internal_Rela rel
;
3535 bfd_boolean unresolved_reloc
;
3536 char *error_message
;
3538 = (template[stub_reloc_idx
[i
]].r_type
!= R_ARM_THM_XPC22
)
3539 ? STT_ARM_TFUNC
: 0;
3540 bfd_vma points_to
= sym_value
+ stub_entry
->target_addend
;
3542 rel
.r_offset
= stub_entry
->stub_offset
+ stub_reloc_offset
[i
];
3543 rel
.r_info
= ELF32_R_INFO (0, template[stub_reloc_idx
[i
]].r_type
);
3544 rel
.r_addend
= template[stub_reloc_idx
[i
]].reloc_addend
;
3546 if (stub_entry
->stub_type
== arm_stub_a8_veneer_b_cond
&& i
== 0)
3547 /* The first relocation in the elf32_arm_stub_a8_veneer_b_cond[]
3548 template should refer back to the instruction after the original
3550 points_to
= sym_value
;
3552 /* Note: _bfd_final_link_relocate doesn't handle these relocations
3553 properly. We should probably use this function unconditionally,
3554 rather than only for certain relocations listed in the enclosing
3555 conditional, for the sake of consistency. */
3556 elf32_arm_final_link_relocate (elf32_arm_howto_from_type
3557 (template[stub_reloc_idx
[i
]].r_type
),
3558 stub_bfd
, info
->output_bfd
, stub_sec
, stub_sec
->contents
, &rel
,
3559 points_to
, info
, stub_entry
->target_section
, "", sym_flags
,
3560 (struct elf_link_hash_entry
*) stub_entry
, &unresolved_reloc
,
3565 _bfd_final_link_relocate (elf32_arm_howto_from_type
3566 (template[stub_reloc_idx
[i
]].r_type
), stub_bfd
, stub_sec
,
3567 stub_sec
->contents
, stub_entry
->stub_offset
+ stub_reloc_offset
[i
],
3568 sym_value
+ stub_entry
->target_addend
,
3569 template[stub_reloc_idx
[i
]].reloc_addend
);
3576 /* Calculate the template, template size and instruction size for a stub.
3577 Return value is the instruction size. */
3580 find_stub_size_and_template (enum elf32_arm_stub_type stub_type
,
3581 const insn_sequence
**stub_template
,
3582 int *stub_template_size
)
3584 const insn_sequence
*template = NULL
;
3585 int template_size
= 0, i
;
3588 template = stub_definitions
[stub_type
].template;
3589 template_size
= stub_definitions
[stub_type
].template_size
;
3592 for (i
= 0; i
< template_size
; i
++)
3594 switch (template[i
].type
)
3613 *stub_template
= template;
3615 if (stub_template_size
)
3616 *stub_template_size
= template_size
;
3621 /* As above, but don't actually build the stub. Just bump offset so
3622 we know stub section sizes. */
3625 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3628 struct elf32_arm_stub_hash_entry
*stub_entry
;
3629 struct elf32_arm_link_hash_table
*htab
;
3630 const insn_sequence
*template;
3631 int template_size
, size
;
3633 /* Massage our args to the form they really have. */
3634 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3635 htab
= (struct elf32_arm_link_hash_table
*) in_arg
;
3637 BFD_ASSERT((stub_entry
->stub_type
> arm_stub_none
)
3638 && stub_entry
->stub_type
< ARRAY_SIZE(stub_definitions
));
3640 size
= find_stub_size_and_template (stub_entry
->stub_type
, &template,
3643 stub_entry
->stub_size
= size
;
3644 stub_entry
->stub_template
= template;
3645 stub_entry
->stub_template_size
= template_size
;
3647 size
= (size
+ 7) & ~7;
3648 stub_entry
->stub_sec
->size
+= size
;
3653 /* External entry points for sizing and building linker stubs. */
3655 /* Set up various things so that we can make a list of input sections
3656 for each output section included in the link. Returns -1 on error,
3657 0 when no stubs will be needed, and 1 on success. */
3660 elf32_arm_setup_section_lists (bfd
*output_bfd
,
3661 struct bfd_link_info
*info
)
3664 unsigned int bfd_count
;
3665 int top_id
, top_index
;
3667 asection
**input_list
, **list
;
3669 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3671 if (! is_elf_hash_table (htab
))
3674 /* Count the number of input BFDs and find the top input section id. */
3675 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3677 input_bfd
= input_bfd
->link_next
)
3680 for (section
= input_bfd
->sections
;
3682 section
= section
->next
)
3684 if (top_id
< section
->id
)
3685 top_id
= section
->id
;
3688 htab
->bfd_count
= bfd_count
;
3690 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3691 htab
->stub_group
= bfd_zmalloc (amt
);
3692 if (htab
->stub_group
== NULL
)
3695 /* We can't use output_bfd->section_count here to find the top output
3696 section index as some sections may have been removed, and
3697 _bfd_strip_section_from_output doesn't renumber the indices. */
3698 for (section
= output_bfd
->sections
, top_index
= 0;
3700 section
= section
->next
)
3702 if (top_index
< section
->index
)
3703 top_index
= section
->index
;
3706 htab
->top_index
= top_index
;
3707 amt
= sizeof (asection
*) * (top_index
+ 1);
3708 input_list
= bfd_malloc (amt
);
3709 htab
->input_list
= input_list
;
3710 if (input_list
== NULL
)
3713 /* For sections we aren't interested in, mark their entries with a
3714 value we can check later. */
3715 list
= input_list
+ top_index
;
3717 *list
= bfd_abs_section_ptr
;
3718 while (list
-- != input_list
);
3720 for (section
= output_bfd
->sections
;
3722 section
= section
->next
)
3724 if ((section
->flags
& SEC_CODE
) != 0)
3725 input_list
[section
->index
] = NULL
;
3731 /* The linker repeatedly calls this function for each input section,
3732 in the order that input sections are linked into output sections.
3733 Build lists of input sections to determine groupings between which
3734 we may insert linker stubs. */
3737 elf32_arm_next_input_section (struct bfd_link_info
*info
,
3740 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3742 if (isec
->output_section
->index
<= htab
->top_index
)
3744 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3746 if (*list
!= bfd_abs_section_ptr
)
3748 /* Steal the link_sec pointer for our list. */
3749 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3750 /* This happens to make the list in reverse order,
3751 which we reverse later. */
3752 PREV_SEC (isec
) = *list
;
3758 /* See whether we can group stub sections together. Grouping stub
3759 sections may result in fewer stubs. More importantly, we need to
3760 put all .init* and .fini* stubs at the end of the .init or
3761 .fini output sections respectively, because glibc splits the
3762 _init and _fini functions into multiple parts. Putting a stub in
3763 the middle of a function is not a good idea. */
3766 group_sections (struct elf32_arm_link_hash_table
*htab
,
3767 bfd_size_type stub_group_size
,
3768 bfd_boolean stubs_always_after_branch
)
3770 asection
**list
= htab
->input_list
;
3774 asection
*tail
= *list
;
3777 if (tail
== bfd_abs_section_ptr
)
3780 /* Reverse the list: we must avoid placing stubs at the
3781 beginning of the section because the beginning of the text
3782 section may be required for an interrupt vector in bare metal
3784 #define NEXT_SEC PREV_SEC
3786 while (tail
!= NULL
)
3788 /* Pop from tail. */
3789 asection
*item
= tail
;
3790 tail
= PREV_SEC (item
);
3793 NEXT_SEC (item
) = head
;
3797 while (head
!= NULL
)
3801 bfd_vma stub_group_start
= head
->output_offset
;
3802 bfd_vma end_of_next
;
3805 while (NEXT_SEC (curr
) != NULL
)
3807 next
= NEXT_SEC (curr
);
3808 end_of_next
= next
->output_offset
+ next
->size
;
3809 if (end_of_next
- stub_group_start
>= stub_group_size
)
3810 /* End of NEXT is too far from start, so stop. */
3812 /* Add NEXT to the group. */
3816 /* OK, the size from the start to the start of CURR is less
3817 than stub_group_size and thus can be handled by one stub
3818 section. (Or the head section is itself larger than
3819 stub_group_size, in which case we may be toast.)
3820 We should really be keeping track of the total size of
3821 stubs added here, as stubs contribute to the final output
3825 next
= NEXT_SEC (head
);
3826 /* Set up this stub group. */
3827 htab
->stub_group
[head
->id
].link_sec
= curr
;
3829 while (head
!= curr
&& (head
= next
) != NULL
);
3831 /* But wait, there's more! Input sections up to stub_group_size
3832 bytes after the stub section can be handled by it too. */
3833 if (!stubs_always_after_branch
)
3835 stub_group_start
= curr
->output_offset
+ curr
->size
;
3837 while (next
!= NULL
)
3839 end_of_next
= next
->output_offset
+ next
->size
;
3840 if (end_of_next
- stub_group_start
>= stub_group_size
)
3841 /* End of NEXT is too far from stubs, so stop. */
3843 /* Add NEXT to the stub group. */
3845 next
= NEXT_SEC (head
);
3846 htab
->stub_group
[head
->id
].link_sec
= curr
;
3852 while (list
++ != htab
->input_list
+ htab
->top_index
);
3854 free (htab
->input_list
);
3859 /* Comparison function for sorting/searching relocations relating to Cortex-A8
3863 a8_reloc_compare (const void *a
, const void *b
)
3865 const struct a8_erratum_reloc
*ra
= a
, *rb
= b
;
3867 if (ra
->from
< rb
->from
)
3869 else if (ra
->from
> rb
->from
)
3875 static struct elf_link_hash_entry
*find_thumb_glue (struct bfd_link_info
*,
3876 const char *, char **);
3878 /* Helper function to scan code for sequences which might trigger the Cortex-A8
3879 branch/TLB erratum. Fill in the table described by A8_FIXES_P,
3880 NUM_A8_FIXES_P, A8_FIX_TABLE_SIZE_P. Returns true if an error occurs, false
3884 cortex_a8_erratum_scan (bfd
*input_bfd
,
3885 struct bfd_link_info
*info
,
3886 struct a8_erratum_fix
**a8_fixes_p
,
3887 unsigned int *num_a8_fixes_p
,
3888 unsigned int *a8_fix_table_size_p
,
3889 struct a8_erratum_reloc
*a8_relocs
,
3890 unsigned int num_a8_relocs
)
3893 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3894 struct a8_erratum_fix
*a8_fixes
= *a8_fixes_p
;
3895 unsigned int num_a8_fixes
= *num_a8_fixes_p
;
3896 unsigned int a8_fix_table_size
= *a8_fix_table_size_p
;
3898 for (section
= input_bfd
->sections
;
3900 section
= section
->next
)
3902 bfd_byte
*contents
= NULL
;
3903 struct _arm_elf_section_data
*sec_data
;
3907 if (elf_section_type (section
) != SHT_PROGBITS
3908 || (elf_section_flags (section
) & SHF_EXECINSTR
) == 0
3909 || (section
->flags
& SEC_EXCLUDE
) != 0
3910 || (section
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
3911 || (section
->output_section
== bfd_abs_section_ptr
))
3914 base_vma
= section
->output_section
->vma
+ section
->output_offset
;
3916 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
3917 contents
= elf_section_data (section
)->this_hdr
.contents
;
3918 else if (! bfd_malloc_and_get_section (input_bfd
, section
, &contents
))
3921 sec_data
= elf32_arm_section_data (section
);
3923 for (span
= 0; span
< sec_data
->mapcount
; span
++)
3925 unsigned int span_start
= sec_data
->map
[span
].vma
;
3926 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
3927 ? section
->size
: sec_data
->map
[span
+ 1].vma
;
3929 char span_type
= sec_data
->map
[span
].type
;
3930 bfd_boolean last_was_32bit
= FALSE
, last_was_branch
= FALSE
;
3932 if (span_type
!= 't')
3935 /* Span is entirely within a single 4KB region: skip scanning. */
3936 if (((base_vma
+ span_start
) & ~0xfff)
3937 == ((base_vma
+ span_end
) & ~0xfff))
3940 /* Scan for 32-bit Thumb-2 branches which span two 4K regions, where:
3942 * The opcode is BLX.W, BL.W, B.W, Bcc.W
3943 * The branch target is in the same 4KB region as the
3944 first half of the branch.
3945 * The instruction before the branch is a 32-bit
3946 length non-branch instruction. */
3947 for (i
= span_start
; i
< span_end
;)
3949 unsigned int insn
= bfd_getl16 (&contents
[i
]);
3950 bfd_boolean insn_32bit
= FALSE
, is_blx
= FALSE
, is_b
= FALSE
;
3951 bfd_boolean is_bl
= FALSE
, is_bcc
= FALSE
, is_32bit_branch
;
3953 if ((insn
& 0xe000) == 0xe000 && (insn
& 0x1800) != 0x0000)
3958 /* Load the rest of the insn (in manual-friendly order). */
3959 insn
= (insn
<< 16) | bfd_getl16 (&contents
[i
+ 2]);
3961 /* Encoding T4: B<c>.W. */
3962 is_b
= (insn
& 0xf800d000) == 0xf0009000;
3963 /* Encoding T1: BL<c>.W. */
3964 is_bl
= (insn
& 0xf800d000) == 0xf000d000;
3965 /* Encoding T2: BLX<c>.W. */
3966 is_blx
= (insn
& 0xf800d000) == 0xf000c000;
3967 /* Encoding T3: B<c>.W (not permitted in IT block). */
3968 is_bcc
= (insn
& 0xf800d000) == 0xf0008000
3969 && (insn
& 0x07f00000) != 0x03800000;
3972 is_32bit_branch
= is_b
|| is_bl
|| is_blx
|| is_bcc
;
3974 if (((base_vma
+ i
) & 0xfff) == 0xffe
3978 && ! last_was_branch
)
3980 bfd_signed_vma offset
;
3981 bfd_boolean force_target_arm
= FALSE
;
3982 bfd_boolean force_target_thumb
= FALSE
;
3984 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
3985 struct a8_erratum_reloc key
, *found
;
3987 key
.from
= base_vma
+ i
;
3988 found
= bsearch (&key
, a8_relocs
, num_a8_relocs
,
3989 sizeof (struct a8_erratum_reloc
),
3994 char *error_message
= NULL
;
3995 struct elf_link_hash_entry
*entry
;
3997 /* We don't care about the error returned from this
3998 function, only if there is glue or not. */
3999 entry
= find_thumb_glue (info
, found
->sym_name
,
4003 found
->non_a8_stub
= TRUE
;
4005 if (found
->r_type
== R_ARM_THM_CALL
4006 && found
->st_type
!= STT_ARM_TFUNC
)
4007 force_target_arm
= TRUE
;
4008 else if (found
->r_type
== R_ARM_THM_CALL
4009 && found
->st_type
== STT_ARM_TFUNC
)
4010 force_target_thumb
= TRUE
;
4013 /* Check if we have an offending branch instruction. */
4015 if (found
&& found
->non_a8_stub
)
4016 /* We've already made a stub for this instruction, e.g.
4017 it's a long branch or a Thumb->ARM stub. Assume that
4018 stub will suffice to work around the A8 erratum (see
4019 setting of always_after_branch above). */
4023 offset
= (insn
& 0x7ff) << 1;
4024 offset
|= (insn
& 0x3f0000) >> 4;
4025 offset
|= (insn
& 0x2000) ? 0x40000 : 0;
4026 offset
|= (insn
& 0x800) ? 0x80000 : 0;
4027 offset
|= (insn
& 0x4000000) ? 0x100000 : 0;
4028 if (offset
& 0x100000)
4029 offset
|= ~ ((bfd_signed_vma
) 0xfffff);
4030 stub_type
= arm_stub_a8_veneer_b_cond
;
4032 else if (is_b
|| is_bl
|| is_blx
)
4034 int s
= (insn
& 0x4000000) != 0;
4035 int j1
= (insn
& 0x2000) != 0;
4036 int j2
= (insn
& 0x800) != 0;
4040 offset
= (insn
& 0x7ff) << 1;
4041 offset
|= (insn
& 0x3ff0000) >> 4;
4045 if (offset
& 0x1000000)
4046 offset
|= ~ ((bfd_signed_vma
) 0xffffff);
4049 offset
&= ~ ((bfd_signed_vma
) 3);
4051 stub_type
= is_blx
? arm_stub_a8_veneer_blx
:
4052 is_bl
? arm_stub_a8_veneer_bl
: arm_stub_a8_veneer_b
;
4055 if (stub_type
!= arm_stub_none
)
4057 bfd_vma pc_for_insn
= base_vma
+ i
+ 4;
4059 /* The original instruction is a BL, but the target is
4060 an ARM instruction. If we were not making a stub,
4061 the BL would have been converted to a BLX. Use the
4062 BLX stub instead in that case. */
4063 if (htab
->use_blx
&& force_target_arm
4064 && stub_type
== arm_stub_a8_veneer_bl
)
4066 stub_type
= arm_stub_a8_veneer_blx
;
4070 /* Conversely, if the original instruction was
4071 BLX but the target is Thumb mode, use the BL
4073 else if (force_target_thumb
4074 && stub_type
== arm_stub_a8_veneer_blx
)
4076 stub_type
= arm_stub_a8_veneer_bl
;
4082 pc_for_insn
&= ~ ((bfd_vma
) 3);
4084 /* If we found a relocation, use the proper destination,
4085 not the offset in the (unrelocated) instruction.
4086 Note this is always done if we switched the stub type
4090 (bfd_signed_vma
) (found
->destination
- pc_for_insn
);
4092 target
= pc_for_insn
+ offset
;
4094 /* The BLX stub is ARM-mode code. Adjust the offset to
4095 take the different PC value (+8 instead of +4) into
4097 if (stub_type
== arm_stub_a8_veneer_blx
)
4100 if (((base_vma
+ i
) & ~0xfff) == (target
& ~0xfff))
4104 if (num_a8_fixes
== a8_fix_table_size
)
4106 a8_fix_table_size
*= 2;
4107 a8_fixes
= bfd_realloc (a8_fixes
,
4108 sizeof (struct a8_erratum_fix
)
4109 * a8_fix_table_size
);
4112 stub_name
= bfd_malloc (8 + 1 + 8 + 1);
4113 if (stub_name
!= NULL
)
4114 sprintf (stub_name
, "%x:%x", section
->id
, i
);
4116 a8_fixes
[num_a8_fixes
].input_bfd
= input_bfd
;
4117 a8_fixes
[num_a8_fixes
].section
= section
;
4118 a8_fixes
[num_a8_fixes
].offset
= i
;
4119 a8_fixes
[num_a8_fixes
].addend
= offset
;
4120 a8_fixes
[num_a8_fixes
].orig_insn
= insn
;
4121 a8_fixes
[num_a8_fixes
].stub_name
= stub_name
;
4122 a8_fixes
[num_a8_fixes
].stub_type
= stub_type
;
4129 i
+= insn_32bit
? 4 : 2;
4130 last_was_32bit
= insn_32bit
;
4131 last_was_branch
= is_32bit_branch
;
4135 if (elf_section_data (section
)->this_hdr
.contents
== NULL
)
4139 *a8_fixes_p
= a8_fixes
;
4140 *num_a8_fixes_p
= num_a8_fixes
;
4141 *a8_fix_table_size_p
= a8_fix_table_size
;
4146 /* Determine and set the size of the stub section for a final link.
4148 The basic idea here is to examine all the relocations looking for
4149 PC-relative calls to a target that is unreachable with a "bl"
4153 elf32_arm_size_stubs (bfd
*output_bfd
,
4155 struct bfd_link_info
*info
,
4156 bfd_signed_vma group_size
,
4157 asection
* (*add_stub_section
) (const char *, asection
*),
4158 void (*layout_sections_again
) (void))
4160 bfd_size_type stub_group_size
;
4161 bfd_boolean stubs_always_after_branch
;
4162 bfd_boolean stub_changed
= 0;
4163 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
4164 struct a8_erratum_fix
*a8_fixes
= NULL
;
4165 unsigned int num_a8_fixes
= 0, prev_num_a8_fixes
= 0, a8_fix_table_size
= 10;
4166 struct a8_erratum_reloc
*a8_relocs
= NULL
;
4167 unsigned int num_a8_relocs
= 0, a8_reloc_table_size
= 10, i
;
4169 if (htab
->fix_cortex_a8
)
4171 a8_fixes
= bfd_zmalloc (sizeof (struct a8_erratum_fix
)
4172 * a8_fix_table_size
);
4173 a8_relocs
= bfd_zmalloc (sizeof (struct a8_erratum_reloc
)
4174 * a8_reloc_table_size
);
4177 /* Propagate mach to stub bfd, because it may not have been
4178 finalized when we created stub_bfd. */
4179 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
4180 bfd_get_mach (output_bfd
));
4182 /* Stash our params away. */
4183 htab
->stub_bfd
= stub_bfd
;
4184 htab
->add_stub_section
= add_stub_section
;
4185 htab
->layout_sections_again
= layout_sections_again
;
4186 stubs_always_after_branch
= group_size
< 0;
4188 /* The Cortex-A8 erratum fix depends on stubs not being in the same 4K page
4189 as the first half of a 32-bit branch straddling two 4K pages. This is a
4190 crude way of enforcing that. */
4191 if (htab
->fix_cortex_a8
)
4192 stubs_always_after_branch
= 1;
4195 stub_group_size
= -group_size
;
4197 stub_group_size
= group_size
;
4199 if (stub_group_size
== 1)
4201 /* Default values. */
4202 /* Thumb branch range is +-4MB has to be used as the default
4203 maximum size (a given section can contain both ARM and Thumb
4204 code, so the worst case has to be taken into account).
4206 This value is 24K less than that, which allows for 2025
4207 12-byte stubs. If we exceed that, then we will fail to link.
4208 The user will have to relink with an explicit group size
4210 stub_group_size
= 4170000;
4213 group_sections (htab
, stub_group_size
, stubs_always_after_branch
);
4218 unsigned int bfd_indx
;
4223 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4225 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4227 Elf_Internal_Shdr
*symtab_hdr
;
4229 Elf_Internal_Sym
*local_syms
= NULL
;
4233 /* We'll need the symbol table in a second. */
4234 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4235 if (symtab_hdr
->sh_info
== 0)
4238 /* Walk over each section attached to the input bfd. */
4239 for (section
= input_bfd
->sections
;
4241 section
= section
->next
)
4243 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4245 /* If there aren't any relocs, then there's nothing more
4247 if ((section
->flags
& SEC_RELOC
) == 0
4248 || section
->reloc_count
== 0
4249 || (section
->flags
& SEC_CODE
) == 0)
4252 /* If this section is a link-once section that will be
4253 discarded, then don't create any stubs. */
4254 if (section
->output_section
== NULL
4255 || section
->output_section
->owner
!= output_bfd
)
4258 /* Get the relocs. */
4260 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
4261 NULL
, info
->keep_memory
);
4262 if (internal_relocs
== NULL
)
4263 goto error_ret_free_local
;
4265 /* Now examine each relocation. */
4266 irela
= internal_relocs
;
4267 irelaend
= irela
+ section
->reloc_count
;
4268 for (; irela
< irelaend
; irela
++)
4270 unsigned int r_type
, r_indx
;
4271 enum elf32_arm_stub_type stub_type
;
4272 struct elf32_arm_stub_hash_entry
*stub_entry
;
4275 bfd_vma destination
;
4276 struct elf32_arm_link_hash_entry
*hash
;
4277 const char *sym_name
;
4279 const asection
*id_sec
;
4280 unsigned char st_type
;
4281 bfd_boolean created_stub
= FALSE
;
4283 r_type
= ELF32_R_TYPE (irela
->r_info
);
4284 r_indx
= ELF32_R_SYM (irela
->r_info
);
4286 if (r_type
>= (unsigned int) R_ARM_max
)
4288 bfd_set_error (bfd_error_bad_value
);
4289 error_ret_free_internal
:
4290 if (elf_section_data (section
)->relocs
== NULL
)
4291 free (internal_relocs
);
4292 goto error_ret_free_local
;
4295 /* Only look for stubs on branch instructions. */
4296 if ((r_type
!= (unsigned int) R_ARM_CALL
)
4297 && (r_type
!= (unsigned int) R_ARM_THM_CALL
)
4298 && (r_type
!= (unsigned int) R_ARM_JUMP24
)
4299 && (r_type
!= (unsigned int) R_ARM_THM_JUMP19
)
4300 && (r_type
!= (unsigned int) R_ARM_THM_XPC22
)
4301 && (r_type
!= (unsigned int) R_ARM_THM_JUMP24
)
4302 && (r_type
!= (unsigned int) R_ARM_PLT32
))
4305 /* Now determine the call target, its name, value,
4312 if (r_indx
< symtab_hdr
->sh_info
)
4314 /* It's a local symbol. */
4315 Elf_Internal_Sym
*sym
;
4316 Elf_Internal_Shdr
*hdr
;
4318 if (local_syms
== NULL
)
4321 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4322 if (local_syms
== NULL
)
4324 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4325 symtab_hdr
->sh_info
, 0,
4327 if (local_syms
== NULL
)
4328 goto error_ret_free_internal
;
4331 sym
= local_syms
+ r_indx
;
4332 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4333 sym_sec
= hdr
->bfd_section
;
4334 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4335 sym_value
= sym
->st_value
;
4336 destination
= (sym_value
+ irela
->r_addend
4337 + sym_sec
->output_offset
4338 + sym_sec
->output_section
->vma
);
4339 st_type
= ELF_ST_TYPE (sym
->st_info
);
4341 = bfd_elf_string_from_elf_section (input_bfd
,
4342 symtab_hdr
->sh_link
,
4347 /* It's an external symbol. */
4350 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4351 hash
= ((struct elf32_arm_link_hash_entry
*)
4352 elf_sym_hashes (input_bfd
)[e_indx
]);
4354 while (hash
->root
.root
.type
== bfd_link_hash_indirect
4355 || hash
->root
.root
.type
== bfd_link_hash_warning
)
4356 hash
= ((struct elf32_arm_link_hash_entry
*)
4357 hash
->root
.root
.u
.i
.link
);
4359 if (hash
->root
.root
.type
== bfd_link_hash_defined
4360 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
4362 sym_sec
= hash
->root
.root
.u
.def
.section
;
4363 sym_value
= hash
->root
.root
.u
.def
.value
;
4365 struct elf32_arm_link_hash_table
*globals
=
4366 elf32_arm_hash_table (info
);
4368 /* For a destination in a shared library,
4369 use the PLT stub as target address to
4370 decide whether a branch stub is
4372 if (globals
->splt
!= NULL
&& hash
!= NULL
4373 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
4375 sym_sec
= globals
->splt
;
4376 sym_value
= hash
->root
.plt
.offset
;
4377 if (sym_sec
->output_section
!= NULL
)
4378 destination
= (sym_value
4379 + sym_sec
->output_offset
4380 + sym_sec
->output_section
->vma
);
4382 else if (sym_sec
->output_section
!= NULL
)
4383 destination
= (sym_value
+ irela
->r_addend
4384 + sym_sec
->output_offset
4385 + sym_sec
->output_section
->vma
);
4387 else if ((hash
->root
.root
.type
== bfd_link_hash_undefined
)
4388 || (hash
->root
.root
.type
== bfd_link_hash_undefweak
))
4390 /* For a shared library, use the PLT stub as
4391 target address to decide whether a long
4392 branch stub is needed.
4393 For absolute code, they cannot be handled. */
4394 struct elf32_arm_link_hash_table
*globals
=
4395 elf32_arm_hash_table (info
);
4397 if (globals
->splt
!= NULL
&& hash
!= NULL
4398 && hash
->root
.plt
.offset
!= (bfd_vma
) -1)
4400 sym_sec
= globals
->splt
;
4401 sym_value
= hash
->root
.plt
.offset
;
4402 if (sym_sec
->output_section
!= NULL
)
4403 destination
= (sym_value
4404 + sym_sec
->output_offset
4405 + sym_sec
->output_section
->vma
);
4412 bfd_set_error (bfd_error_bad_value
);
4413 goto error_ret_free_internal
;
4415 st_type
= ELF_ST_TYPE (hash
->root
.type
);
4416 sym_name
= hash
->root
.root
.root
.string
;
4421 /* Determine what (if any) linker stub is needed. */
4422 stub_type
= arm_type_of_stub (info
, section
, irela
,
4424 destination
, sym_sec
,
4425 input_bfd
, sym_name
);
4426 if (stub_type
== arm_stub_none
)
4429 /* Support for grouping stub sections. */
4430 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4432 /* Get the name of this stub. */
4433 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
,
4436 goto error_ret_free_internal
;
4438 /* We've either created a stub for this reloc already,
4439 or we are about to. */
4440 created_stub
= TRUE
;
4442 stub_entry
= arm_stub_hash_lookup
4443 (&htab
->stub_hash_table
, stub_name
,
4445 if (stub_entry
!= NULL
)
4447 /* The proper stub has already been created. */
4452 stub_entry
= elf32_arm_add_stub (stub_name
, section
,
4454 if (stub_entry
== NULL
)
4457 goto error_ret_free_internal
;
4460 stub_entry
->target_value
= sym_value
;
4461 stub_entry
->target_section
= sym_sec
;
4462 stub_entry
->stub_type
= stub_type
;
4463 stub_entry
->h
= hash
;
4464 stub_entry
->st_type
= st_type
;
4466 if (sym_name
== NULL
)
4467 sym_name
= "unnamed";
4468 stub_entry
->output_name
4469 = bfd_alloc (htab
->stub_bfd
,
4470 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
4471 + strlen (sym_name
));
4472 if (stub_entry
->output_name
== NULL
)
4475 goto error_ret_free_internal
;
4478 /* For historical reasons, use the existing names for
4479 ARM-to-Thumb and Thumb-to-ARM stubs. */
4480 if ( ((r_type
== (unsigned int) R_ARM_THM_CALL
)
4481 || (r_type
== (unsigned int) R_ARM_THM_JUMP24
))
4482 && st_type
!= STT_ARM_TFUNC
)
4483 sprintf (stub_entry
->output_name
,
4484 THUMB2ARM_GLUE_ENTRY_NAME
, sym_name
);
4485 else if ( ((r_type
== (unsigned int) R_ARM_CALL
)
4486 || (r_type
== (unsigned int) R_ARM_JUMP24
))
4487 && st_type
== STT_ARM_TFUNC
)
4488 sprintf (stub_entry
->output_name
,
4489 ARM2THUMB_GLUE_ENTRY_NAME
, sym_name
);
4491 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
4494 stub_changed
= TRUE
;
4498 /* Look for relocations which might trigger Cortex-A8
4500 if (htab
->fix_cortex_a8
4501 && (r_type
== (unsigned int) R_ARM_THM_JUMP24
4502 || r_type
== (unsigned int) R_ARM_THM_JUMP19
4503 || r_type
== (unsigned int) R_ARM_THM_CALL
4504 || r_type
== (unsigned int) R_ARM_THM_XPC22
))
4506 bfd_vma from
= section
->output_section
->vma
4507 + section
->output_offset
4510 if ((from
& 0xfff) == 0xffe)
4512 /* Found a candidate. Note we haven't checked the
4513 destination is within 4K here: if we do so (and
4514 don't create an entry in a8_relocs) we can't tell
4515 that a branch should have been relocated when
4517 if (num_a8_relocs
== a8_reloc_table_size
)
4519 a8_reloc_table_size
*= 2;
4520 a8_relocs
= bfd_realloc (a8_relocs
,
4521 sizeof (struct a8_erratum_reloc
)
4522 * a8_reloc_table_size
);
4525 a8_relocs
[num_a8_relocs
].from
= from
;
4526 a8_relocs
[num_a8_relocs
].destination
= destination
;
4527 a8_relocs
[num_a8_relocs
].r_type
= r_type
;
4528 a8_relocs
[num_a8_relocs
].st_type
= st_type
;
4529 a8_relocs
[num_a8_relocs
].sym_name
= sym_name
;
4530 a8_relocs
[num_a8_relocs
].non_a8_stub
= created_stub
;
4537 /* We're done with the internal relocs, free them. */
4538 if (elf_section_data (section
)->relocs
== NULL
)
4539 free (internal_relocs
);
4542 if (htab
->fix_cortex_a8
)
4544 /* Sort relocs which might apply to Cortex-A8 erratum. */
4545 qsort (a8_relocs
, num_a8_relocs
, sizeof (struct a8_erratum_reloc
),
4548 /* Scan for branches which might trigger Cortex-A8 erratum. */
4549 if (cortex_a8_erratum_scan (input_bfd
, info
, &a8_fixes
,
4550 &num_a8_fixes
, &a8_fix_table_size
,
4551 a8_relocs
, num_a8_relocs
) != 0)
4552 goto error_ret_free_local
;
4556 if (htab
->fix_cortex_a8
&& num_a8_fixes
!= prev_num_a8_fixes
)
4557 stub_changed
= TRUE
;
4562 /* OK, we've added some stubs. Find out the new size of the
4564 for (stub_sec
= htab
->stub_bfd
->sections
;
4566 stub_sec
= stub_sec
->next
)
4568 /* Ignore non-stub sections. */
4569 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4575 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
4577 /* Add Cortex-A8 erratum veneers to stub section sizes too. */
4578 if (htab
->fix_cortex_a8
)
4579 for (i
= 0; i
< num_a8_fixes
; i
++)
4581 stub_sec
= elf32_arm_create_or_find_stub_sec (NULL
,
4582 a8_fixes
[i
].section
, htab
);
4584 if (stub_sec
== NULL
)
4585 goto error_ret_free_local
;
4588 += find_stub_size_and_template (a8_fixes
[i
].stub_type
, NULL
,
4593 /* Ask the linker to do its stuff. */
4594 (*htab
->layout_sections_again
) ();
4595 stub_changed
= FALSE
;
4596 prev_num_a8_fixes
= num_a8_fixes
;
4599 /* Add stubs for Cortex-A8 erratum fixes now. */
4600 if (htab
->fix_cortex_a8
)
4602 for (i
= 0; i
< num_a8_fixes
; i
++)
4604 struct elf32_arm_stub_hash_entry
*stub_entry
;
4605 char *stub_name
= a8_fixes
[i
].stub_name
;
4606 asection
*section
= a8_fixes
[i
].section
;
4607 unsigned int section_id
= a8_fixes
[i
].section
->id
;
4608 asection
*link_sec
= htab
->stub_group
[section_id
].link_sec
;
4609 asection
*stub_sec
= htab
->stub_group
[section_id
].stub_sec
;
4610 const insn_sequence
*template;
4611 int template_size
, size
= 0;
4613 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4615 if (stub_entry
== NULL
)
4617 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
4623 stub_entry
->stub_sec
= stub_sec
;
4624 stub_entry
->stub_offset
= 0;
4625 stub_entry
->id_sec
= link_sec
;
4626 stub_entry
->stub_type
= a8_fixes
[i
].stub_type
;
4627 stub_entry
->target_section
= a8_fixes
[i
].section
;
4628 stub_entry
->target_value
= a8_fixes
[i
].offset
;
4629 stub_entry
->target_addend
= a8_fixes
[i
].addend
;
4630 stub_entry
->orig_insn
= a8_fixes
[i
].orig_insn
;
4631 stub_entry
->st_type
= STT_ARM_TFUNC
;
4633 size
= find_stub_size_and_template (a8_fixes
[i
].stub_type
, &template,
4636 stub_entry
->stub_size
= size
;
4637 stub_entry
->stub_template
= template;
4638 stub_entry
->stub_template_size
= template_size
;
4641 /* Stash the Cortex-A8 erratum fix array for use later in
4642 elf32_arm_write_section(). */
4643 htab
->a8_erratum_fixes
= a8_fixes
;
4644 htab
->num_a8_erratum_fixes
= num_a8_fixes
;
4648 htab
->a8_erratum_fixes
= NULL
;
4649 htab
->num_a8_erratum_fixes
= 0;
4653 error_ret_free_local
:
4657 /* Build all the stubs associated with the current output file. The
4658 stubs are kept in a hash table attached to the main linker hash
4659 table. We also set up the .plt entries for statically linked PIC
4660 functions here. This function is called via arm_elf_finish in the
4664 elf32_arm_build_stubs (struct bfd_link_info
*info
)
4667 struct bfd_hash_table
*table
;
4668 struct elf32_arm_link_hash_table
*htab
;
4670 htab
= elf32_arm_hash_table (info
);
4672 for (stub_sec
= htab
->stub_bfd
->sections
;
4674 stub_sec
= stub_sec
->next
)
4678 /* Ignore non-stub sections. */
4679 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
4682 /* Allocate memory to hold the linker stubs. */
4683 size
= stub_sec
->size
;
4684 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
4685 if (stub_sec
->contents
== NULL
&& size
!= 0)
4690 /* Build the stubs as directed by the stub hash table. */
4691 table
= &htab
->stub_hash_table
;
4692 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
4697 /* Locate the Thumb encoded calling stub for NAME. */
4699 static struct elf_link_hash_entry
*
4700 find_thumb_glue (struct bfd_link_info
*link_info
,
4702 char **error_message
)
4705 struct elf_link_hash_entry
*hash
;
4706 struct elf32_arm_link_hash_table
*hash_table
;
4708 /* We need a pointer to the armelf specific hash table. */
4709 hash_table
= elf32_arm_hash_table (link_info
);
4711 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4712 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
4714 BFD_ASSERT (tmp_name
);
4716 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
4718 hash
= elf_link_hash_lookup
4719 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4722 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
4723 tmp_name
, name
) == -1)
4724 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
4731 /* Locate the ARM encoded calling stub for NAME. */
4733 static struct elf_link_hash_entry
*
4734 find_arm_glue (struct bfd_link_info
*link_info
,
4736 char **error_message
)
4739 struct elf_link_hash_entry
*myh
;
4740 struct elf32_arm_link_hash_table
*hash_table
;
4742 /* We need a pointer to the elfarm specific hash table. */
4743 hash_table
= elf32_arm_hash_table (link_info
);
4745 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4746 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
4748 BFD_ASSERT (tmp_name
);
4750 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
4752 myh
= elf_link_hash_lookup
4753 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4756 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
4757 tmp_name
, name
) == -1)
4758 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
4765 /* ARM->Thumb glue (static images):
4769 ldr r12, __func_addr
4772 .word func @ behave as if you saw a ARM_32 reloc.
4779 .word func @ behave as if you saw a ARM_32 reloc.
4781 (relocatable images)
4784 ldr r12, __func_offset
4790 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4791 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
4792 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
4793 static const insn32 a2t3_func_addr_insn
= 0x00000001;
4795 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4796 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
4797 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
4799 #define ARM2THUMB_PIC_GLUE_SIZE 16
4800 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
4801 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
4802 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
4804 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4808 __func_from_thumb: __func_from_thumb:
4810 nop ldr r6, __func_addr
4820 #define THUMB2ARM_GLUE_SIZE 8
4821 static const insn16 t2a1_bx_pc_insn
= 0x4778;
4822 static const insn16 t2a2_noop_insn
= 0x46c0;
4823 static const insn32 t2a3_b_insn
= 0xea000000;
4825 #define VFP11_ERRATUM_VENEER_SIZE 8
4827 #define ARM_BX_VENEER_SIZE 12
4828 static const insn32 armbx1_tst_insn
= 0xe3100001;
4829 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
4830 static const insn32 armbx3_bx_insn
= 0xe12fff10;
4832 #ifndef ELFARM_NABI_C_INCLUDED
4834 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
4837 bfd_byte
* contents
;
4841 /* Do not include empty glue sections in the output. */
4844 s
= bfd_get_section_by_name (abfd
, name
);
4846 s
->flags
|= SEC_EXCLUDE
;
4851 BFD_ASSERT (abfd
!= NULL
);
4853 s
= bfd_get_section_by_name (abfd
, name
);
4854 BFD_ASSERT (s
!= NULL
);
4856 contents
= bfd_alloc (abfd
, size
);
4858 BFD_ASSERT (s
->size
== size
);
4859 s
->contents
= contents
;
4863 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
4865 struct elf32_arm_link_hash_table
* globals
;
4867 globals
= elf32_arm_hash_table (info
);
4868 BFD_ASSERT (globals
!= NULL
);
4870 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4871 globals
->arm_glue_size
,
4872 ARM2THUMB_GLUE_SECTION_NAME
);
4874 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4875 globals
->thumb_glue_size
,
4876 THUMB2ARM_GLUE_SECTION_NAME
);
4878 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4879 globals
->vfp11_erratum_glue_size
,
4880 VFP11_ERRATUM_VENEER_SECTION_NAME
);
4882 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
4883 globals
->bx_glue_size
,
4884 ARM_BX_GLUE_SECTION_NAME
);
4889 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4890 returns the symbol identifying the stub. */
4892 static struct elf_link_hash_entry
*
4893 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
4894 struct elf_link_hash_entry
* h
)
4896 const char * name
= h
->root
.root
.string
;
4899 struct elf_link_hash_entry
* myh
;
4900 struct bfd_link_hash_entry
* bh
;
4901 struct elf32_arm_link_hash_table
* globals
;
4905 globals
= elf32_arm_hash_table (link_info
);
4907 BFD_ASSERT (globals
!= NULL
);
4908 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
4910 s
= bfd_get_section_by_name
4911 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
4913 BFD_ASSERT (s
!= NULL
);
4915 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
4917 BFD_ASSERT (tmp_name
);
4919 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
4921 myh
= elf_link_hash_lookup
4922 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4926 /* We've already seen this guy. */
4931 /* The only trick here is using hash_table->arm_glue_size as the value.
4932 Even though the section isn't allocated yet, this is where we will be
4933 putting it. The +1 on the value marks that the stub has not been
4934 output yet - not that it is a Thumb function. */
4936 val
= globals
->arm_glue_size
+ 1;
4937 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
4938 tmp_name
, BSF_GLOBAL
, s
, val
,
4939 NULL
, TRUE
, FALSE
, &bh
);
4941 myh
= (struct elf_link_hash_entry
*) bh
;
4942 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4943 myh
->forced_local
= 1;
4947 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
4948 || globals
->pic_veneer
)
4949 size
= ARM2THUMB_PIC_GLUE_SIZE
;
4950 else if (globals
->use_blx
)
4951 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
4953 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
4956 globals
->arm_glue_size
+= size
;
4961 /* Allocate space for ARMv4 BX veneers. */
4964 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
4967 struct elf32_arm_link_hash_table
*globals
;
4969 struct elf_link_hash_entry
*myh
;
4970 struct bfd_link_hash_entry
*bh
;
4973 /* BX PC does not need a veneer. */
4977 globals
= elf32_arm_hash_table (link_info
);
4979 BFD_ASSERT (globals
!= NULL
);
4980 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
4982 /* Check if this veneer has already been allocated. */
4983 if (globals
->bx_glue_offset
[reg
])
4986 s
= bfd_get_section_by_name
4987 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
4989 BFD_ASSERT (s
!= NULL
);
4991 /* Add symbol for veneer. */
4992 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
4994 BFD_ASSERT (tmp_name
);
4996 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
4998 myh
= elf_link_hash_lookup
4999 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5001 BFD_ASSERT (myh
== NULL
);
5004 val
= globals
->bx_glue_size
;
5005 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
5006 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5007 NULL
, TRUE
, FALSE
, &bh
);
5009 myh
= (struct elf_link_hash_entry
*) bh
;
5010 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5011 myh
->forced_local
= 1;
5013 s
->size
+= ARM_BX_VENEER_SIZE
;
5014 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
5015 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
5019 /* Add an entry to the code/data map for section SEC. */
5022 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
5024 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5025 unsigned int newidx
;
5027 if (sec_data
->map
== NULL
)
5029 sec_data
->map
= bfd_malloc (sizeof (elf32_arm_section_map
));
5030 sec_data
->mapcount
= 0;
5031 sec_data
->mapsize
= 1;
5034 newidx
= sec_data
->mapcount
++;
5036 if (sec_data
->mapcount
> sec_data
->mapsize
)
5038 sec_data
->mapsize
*= 2;
5039 sec_data
->map
= bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
5040 * sizeof (elf32_arm_section_map
));
5045 sec_data
->map
[newidx
].vma
= vma
;
5046 sec_data
->map
[newidx
].type
= type
;
5051 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
5052 veneers are handled for now. */
5055 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
5056 elf32_vfp11_erratum_list
*branch
,
5058 asection
*branch_sec
,
5059 unsigned int offset
)
5062 struct elf32_arm_link_hash_table
*hash_table
;
5064 struct elf_link_hash_entry
*myh
;
5065 struct bfd_link_hash_entry
*bh
;
5067 struct _arm_elf_section_data
*sec_data
;
5069 elf32_vfp11_erratum_list
*newerr
;
5071 hash_table
= elf32_arm_hash_table (link_info
);
5073 BFD_ASSERT (hash_table
!= NULL
);
5074 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
5076 s
= bfd_get_section_by_name
5077 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
5079 sec_data
= elf32_arm_section_data (s
);
5081 BFD_ASSERT (s
!= NULL
);
5083 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
5084 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5086 BFD_ASSERT (tmp_name
);
5088 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5089 hash_table
->num_vfp11_fixes
);
5091 myh
= elf_link_hash_lookup
5092 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5094 BFD_ASSERT (myh
== NULL
);
5097 val
= hash_table
->vfp11_erratum_glue_size
;
5098 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
5099 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
5100 NULL
, TRUE
, FALSE
, &bh
);
5102 myh
= (struct elf_link_hash_entry
*) bh
;
5103 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5104 myh
->forced_local
= 1;
5106 /* Link veneer back to calling location. */
5107 errcount
= ++(sec_data
->erratumcount
);
5108 newerr
= bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5110 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
5112 newerr
->u
.v
.branch
= branch
;
5113 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
5114 branch
->u
.b
.veneer
= newerr
;
5116 newerr
->next
= sec_data
->erratumlist
;
5117 sec_data
->erratumlist
= newerr
;
5119 /* A symbol for the return from the veneer. */
5120 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
5121 hash_table
->num_vfp11_fixes
);
5123 myh
= elf_link_hash_lookup
5124 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
5131 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
5132 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
5134 myh
= (struct elf_link_hash_entry
*) bh
;
5135 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
5136 myh
->forced_local
= 1;
5140 /* Generate a mapping symbol for the veneer section, and explicitly add an
5141 entry for that symbol to the code/data map for the section. */
5142 if (hash_table
->vfp11_erratum_glue_size
== 0)
5145 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
5146 ever requires this erratum fix. */
5147 _bfd_generic_link_add_one_symbol (link_info
,
5148 hash_table
->bfd_of_glue_owner
, "$a",
5149 BSF_LOCAL
, s
, 0, NULL
,
5152 myh
= (struct elf_link_hash_entry
*) bh
;
5153 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
5154 myh
->forced_local
= 1;
5156 /* The elf32_arm_init_maps function only cares about symbols from input
5157 BFDs. We must make a note of this generated mapping symbol
5158 ourselves so that code byteswapping works properly in
5159 elf32_arm_write_section. */
5160 elf32_arm_section_map_add (s
, 'a', 0);
5163 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
5164 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
5165 hash_table
->num_vfp11_fixes
++;
5167 /* The offset of the veneer. */
5171 #define ARM_GLUE_SECTION_FLAGS \
5172 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE \
5173 | SEC_READONLY | SEC_LINKER_CREATED)
5175 /* Create a fake section for use by the ARM backend of the linker. */
5178 arm_make_glue_section (bfd
* abfd
, const char * name
)
5182 sec
= bfd_get_section_by_name (abfd
, name
);
5187 sec
= bfd_make_section_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
5190 || !bfd_set_section_alignment (abfd
, sec
, 2))
5193 /* Set the gc mark to prevent the section from being removed by garbage
5194 collection, despite the fact that no relocs refer to this section. */
5200 /* Add the glue sections to ABFD. This function is called from the
5201 linker scripts in ld/emultempl/{armelf}.em. */
5204 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
5205 struct bfd_link_info
*info
)
5207 /* If we are only performing a partial
5208 link do not bother adding the glue. */
5209 if (info
->relocatable
)
5212 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
5213 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
5214 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
5215 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
5218 /* Select a BFD to be used to hold the sections used by the glue code.
5219 This function is called from the linker scripts in ld/emultempl/
5223 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
5225 struct elf32_arm_link_hash_table
*globals
;
5227 /* If we are only performing a partial link
5228 do not bother getting a bfd to hold the glue. */
5229 if (info
->relocatable
)
5232 /* Make sure we don't attach the glue sections to a dynamic object. */
5233 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
5235 globals
= elf32_arm_hash_table (info
);
5237 BFD_ASSERT (globals
!= NULL
);
5239 if (globals
->bfd_of_glue_owner
!= NULL
)
5242 /* Save the bfd for later use. */
5243 globals
->bfd_of_glue_owner
= abfd
;
5249 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
5251 if (bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
5253 globals
->use_blx
= 1;
5257 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
5258 struct bfd_link_info
*link_info
)
5260 Elf_Internal_Shdr
*symtab_hdr
;
5261 Elf_Internal_Rela
*internal_relocs
= NULL
;
5262 Elf_Internal_Rela
*irel
, *irelend
;
5263 bfd_byte
*contents
= NULL
;
5266 struct elf32_arm_link_hash_table
*globals
;
5268 /* If we are only performing a partial link do not bother
5269 to construct any glue. */
5270 if (link_info
->relocatable
)
5273 /* Here we have a bfd that is to be included on the link. We have a
5274 hook to do reloc rummaging, before section sizes are nailed down. */
5275 globals
= elf32_arm_hash_table (link_info
);
5277 BFD_ASSERT (globals
!= NULL
);
5279 check_use_blx (globals
);
5281 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
5283 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
5288 /* PR 5398: If we have not decided to include any loadable sections in
5289 the output then we will not have a glue owner bfd. This is OK, it
5290 just means that there is nothing else for us to do here. */
5291 if (globals
->bfd_of_glue_owner
== NULL
)
5294 /* Rummage around all the relocs and map the glue vectors. */
5295 sec
= abfd
->sections
;
5300 for (; sec
!= NULL
; sec
= sec
->next
)
5302 if (sec
->reloc_count
== 0)
5305 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
5308 symtab_hdr
= & elf_symtab_hdr (abfd
);
5310 /* Load the relocs. */
5312 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
5314 if (internal_relocs
== NULL
)
5317 irelend
= internal_relocs
+ sec
->reloc_count
;
5318 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
5321 unsigned long r_index
;
5323 struct elf_link_hash_entry
*h
;
5325 r_type
= ELF32_R_TYPE (irel
->r_info
);
5326 r_index
= ELF32_R_SYM (irel
->r_info
);
5328 /* These are the only relocation types we care about. */
5329 if ( r_type
!= R_ARM_PC24
5330 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
5333 /* Get the section contents if we haven't done so already. */
5334 if (contents
== NULL
)
5336 /* Get cached copy if it exists. */
5337 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
5338 contents
= elf_section_data (sec
)->this_hdr
.contents
;
5341 /* Go get them off disk. */
5342 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
5347 if (r_type
== R_ARM_V4BX
)
5351 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
5352 record_arm_bx_glue (link_info
, reg
);
5356 /* If the relocation is not against a symbol it cannot concern us. */
5359 /* We don't care about local symbols. */
5360 if (r_index
< symtab_hdr
->sh_info
)
5363 /* This is an external symbol. */
5364 r_index
-= symtab_hdr
->sh_info
;
5365 h
= (struct elf_link_hash_entry
*)
5366 elf_sym_hashes (abfd
)[r_index
];
5368 /* If the relocation is against a static symbol it must be within
5369 the current section and so cannot be a cross ARM/Thumb relocation. */
5373 /* If the call will go through a PLT entry then we do not need
5375 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
5381 /* This one is a call from arm code. We need to look up
5382 the target of the call. If it is a thumb target, we
5384 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
5385 record_arm_to_thumb_glue (link_info
, h
);
5393 if (contents
!= NULL
5394 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5398 if (internal_relocs
!= NULL
5399 && elf_section_data (sec
)->relocs
!= internal_relocs
)
5400 free (internal_relocs
);
5401 internal_relocs
= NULL
;
5407 if (contents
!= NULL
5408 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5410 if (internal_relocs
!= NULL
5411 && elf_section_data (sec
)->relocs
!= internal_relocs
)
5412 free (internal_relocs
);
5419 /* Initialise maps of ARM/Thumb/data for input BFDs. */
5422 bfd_elf32_arm_init_maps (bfd
*abfd
)
5424 Elf_Internal_Sym
*isymbuf
;
5425 Elf_Internal_Shdr
*hdr
;
5426 unsigned int i
, localsyms
;
5428 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
5429 if (! is_arm_elf (abfd
))
5432 if ((abfd
->flags
& DYNAMIC
) != 0)
5435 hdr
= & elf_symtab_hdr (abfd
);
5436 localsyms
= hdr
->sh_info
;
5438 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
5439 should contain the number of local symbols, which should come before any
5440 global symbols. Mapping symbols are always local. */
5441 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
5444 /* No internal symbols read? Skip this BFD. */
5445 if (isymbuf
== NULL
)
5448 for (i
= 0; i
< localsyms
; i
++)
5450 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
5451 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5455 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
5457 name
= bfd_elf_string_from_elf_section (abfd
,
5458 hdr
->sh_link
, isym
->st_name
);
5460 if (bfd_is_arm_special_symbol_name (name
,
5461 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
5462 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
5468 /* Auto-select enabling of Cortex-A8 erratum fix if the user didn't explicitly
5469 say what they wanted. */
5472 bfd_elf32_arm_set_cortex_a8_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
5474 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
5475 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
5477 if (globals
->fix_cortex_a8
== -1)
5479 /* Turn on Cortex-A8 erratum workaround for ARMv7-A. */
5480 if (out_attr
[Tag_CPU_arch
].i
== TAG_CPU_ARCH_V7
5481 && (out_attr
[Tag_CPU_arch_profile
].i
== 'A'
5482 || out_attr
[Tag_CPU_arch_profile
].i
== 0))
5483 globals
->fix_cortex_a8
= 1;
5485 globals
->fix_cortex_a8
= 0;
5491 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
5493 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
5494 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
5496 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
5497 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
5499 switch (globals
->vfp11_fix
)
5501 case BFD_ARM_VFP11_FIX_DEFAULT
:
5502 case BFD_ARM_VFP11_FIX_NONE
:
5503 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
5507 /* Give a warning, but do as the user requests anyway. */
5508 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
5509 "workaround is not necessary for target architecture"), obfd
);
5512 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
5513 /* For earlier architectures, we might need the workaround, but do not
5514 enable it by default. If users is running with broken hardware, they
5515 must enable the erratum fix explicitly. */
5516 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
5520 enum bfd_arm_vfp11_pipe
5528 /* Return a VFP register number. This is encoded as RX:X for single-precision
5529 registers, or X:RX for double-precision registers, where RX is the group of
5530 four bits in the instruction encoding and X is the single extension bit.
5531 RX and X fields are specified using their lowest (starting) bit. The return
5534 0...31: single-precision registers s0...s31
5535 32...63: double-precision registers d0...d31.
5537 Although X should be zero for VFP11 (encoding d0...d15 only), we might
5538 encounter VFP3 instructions, so we allow the full range for DP registers. */
5541 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
5545 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
5547 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
5550 /* Set bits in *WMASK according to a register number REG as encoded by
5551 bfd_arm_vfp11_regno(). Ignore d16-d31. */
5554 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
5559 *wmask
|= 3 << ((reg
- 32) * 2);
5562 /* Return TRUE if WMASK overwrites anything in REGS. */
5565 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
5569 for (i
= 0; i
< numregs
; i
++)
5571 unsigned int reg
= regs
[i
];
5573 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
5581 if ((wmask
& (3 << (reg
* 2))) != 0)
5588 /* In this function, we're interested in two things: finding input registers
5589 for VFP data-processing instructions, and finding the set of registers which
5590 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
5591 hold the written set, so FLDM etc. are easy to deal with (we're only
5592 interested in 32 SP registers or 16 dp registers, due to the VFP version
5593 implemented by the chip in question). DP registers are marked by setting
5594 both SP registers in the write mask). */
5596 static enum bfd_arm_vfp11_pipe
5597 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
5600 enum bfd_arm_vfp11_pipe pipe
= VFP11_BAD
;
5601 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
5603 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
5606 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
5607 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
5609 pqrs
= ((insn
& 0x00800000) >> 20)
5610 | ((insn
& 0x00300000) >> 19)
5611 | ((insn
& 0x00000040) >> 6);
5615 case 0: /* fmac[sd]. */
5616 case 1: /* fnmac[sd]. */
5617 case 2: /* fmsc[sd]. */
5618 case 3: /* fnmsc[sd]. */
5620 bfd_arm_vfp11_write_mask (destmask
, fd
);
5622 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
5627 case 4: /* fmul[sd]. */
5628 case 5: /* fnmul[sd]. */
5629 case 6: /* fadd[sd]. */
5630 case 7: /* fsub[sd]. */
5634 case 8: /* fdiv[sd]. */
5637 bfd_arm_vfp11_write_mask (destmask
, fd
);
5638 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
5643 case 15: /* extended opcode. */
5645 unsigned int extn
= ((insn
>> 15) & 0x1e)
5646 | ((insn
>> 7) & 1);
5650 case 0: /* fcpy[sd]. */
5651 case 1: /* fabs[sd]. */
5652 case 2: /* fneg[sd]. */
5653 case 8: /* fcmp[sd]. */
5654 case 9: /* fcmpe[sd]. */
5655 case 10: /* fcmpz[sd]. */
5656 case 11: /* fcmpez[sd]. */
5657 case 16: /* fuito[sd]. */
5658 case 17: /* fsito[sd]. */
5659 case 24: /* ftoui[sd]. */
5660 case 25: /* ftouiz[sd]. */
5661 case 26: /* ftosi[sd]. */
5662 case 27: /* ftosiz[sd]. */
5663 /* These instructions will not bounce due to underflow. */
5668 case 3: /* fsqrt[sd]. */
5669 /* fsqrt cannot underflow, but it can (perhaps) overwrite
5670 registers to cause the erratum in previous instructions. */
5671 bfd_arm_vfp11_write_mask (destmask
, fd
);
5675 case 15: /* fcvt{ds,sd}. */
5679 bfd_arm_vfp11_write_mask (destmask
, fd
);
5681 /* Only FCVTSD can underflow. */
5682 if ((insn
& 0x100) != 0)
5701 /* Two-register transfer. */
5702 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
5704 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
5706 if ((insn
& 0x100000) == 0)
5709 bfd_arm_vfp11_write_mask (destmask
, fm
);
5712 bfd_arm_vfp11_write_mask (destmask
, fm
);
5713 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
5719 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
5721 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
5722 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
5726 case 0: /* Two-reg transfer. We should catch these above. */
5729 case 2: /* fldm[sdx]. */
5733 unsigned int i
, offset
= insn
& 0xff;
5738 for (i
= fd
; i
< fd
+ offset
; i
++)
5739 bfd_arm_vfp11_write_mask (destmask
, i
);
5743 case 4: /* fld[sd]. */
5745 bfd_arm_vfp11_write_mask (destmask
, fd
);
5754 /* Single-register transfer. Note L==0. */
5755 else if ((insn
& 0x0f100e10) == 0x0e000a10)
5757 unsigned int opcode
= (insn
>> 21) & 7;
5758 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
5762 case 0: /* fmsr/fmdlr. */
5763 case 1: /* fmdhr. */
5764 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5765 destination register. I don't know if this is exactly right,
5766 but it is the conservative choice. */
5767 bfd_arm_vfp11_write_mask (destmask
, fn
);
5781 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
5784 /* Look for potentially-troublesome code sequences which might trigger the
5785 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5786 (available from ARM) for details of the erratum. A short version is
5787 described in ld.texinfo. */
5790 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
5793 bfd_byte
*contents
= NULL
;
5795 int regs
[3], numregs
= 0;
5796 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
5797 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
5799 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5800 The states transition as follows:
5802 0 -> 1 (vector) or 0 -> 2 (scalar)
5803 A VFP FMAC-pipeline instruction has been seen. Fill
5804 regs[0]..regs[numregs-1] with its input operands. Remember this
5805 instruction in 'first_fmac'.
5808 Any instruction, except for a VFP instruction which overwrites
5813 A VFP instruction has been seen which overwrites any of regs[*].
5814 We must make a veneer! Reset state to 0 before examining next
5818 If we fail to match anything in state 2, reset to state 0 and reset
5819 the instruction pointer to the instruction after 'first_fmac'.
5821 If the VFP11 vector mode is in use, there must be at least two unrelated
5822 instructions between anti-dependent VFP11 instructions to properly avoid
5823 triggering the erratum, hence the use of the extra state 1. */
5825 /* If we are only performing a partial link do not bother
5826 to construct any glue. */
5827 if (link_info
->relocatable
)
5830 /* Skip if this bfd does not correspond to an ELF image. */
5831 if (! is_arm_elf (abfd
))
5834 /* We should have chosen a fix type by the time we get here. */
5835 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
5837 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
5840 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5841 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
5844 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5846 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
5847 struct _arm_elf_section_data
*sec_data
;
5849 /* If we don't have executable progbits, we're not interested in this
5850 section. Also skip if section is to be excluded. */
5851 if (elf_section_type (sec
) != SHT_PROGBITS
5852 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
5853 || (sec
->flags
& SEC_EXCLUDE
) != 0
5854 || sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
5855 || sec
->output_section
== bfd_abs_section_ptr
5856 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
5859 sec_data
= elf32_arm_section_data (sec
);
5861 if (sec_data
->mapcount
== 0)
5864 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
5865 contents
= elf_section_data (sec
)->this_hdr
.contents
;
5866 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
5869 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
5870 elf32_arm_compare_mapping
);
5872 for (span
= 0; span
< sec_data
->mapcount
; span
++)
5874 unsigned int span_start
= sec_data
->map
[span
].vma
;
5875 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
5876 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
5877 char span_type
= sec_data
->map
[span
].type
;
5879 /* FIXME: Only ARM mode is supported at present. We may need to
5880 support Thumb-2 mode also at some point. */
5881 if (span_type
!= 'a')
5884 for (i
= span_start
; i
< span_end
;)
5886 unsigned int next_i
= i
+ 4;
5887 unsigned int insn
= bfd_big_endian (abfd
)
5888 ? (contents
[i
] << 24)
5889 | (contents
[i
+ 1] << 16)
5890 | (contents
[i
+ 2] << 8)
5892 : (contents
[i
+ 3] << 24)
5893 | (contents
[i
+ 2] << 16)
5894 | (contents
[i
+ 1] << 8)
5896 unsigned int writemask
= 0;
5897 enum bfd_arm_vfp11_pipe pipe
;
5902 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
5904 /* I'm assuming the VFP11 erratum can trigger with denorm
5905 operands on either the FMAC or the DS pipeline. This might
5906 lead to slightly overenthusiastic veneer insertion. */
5907 if (pipe
== VFP11_FMAC
|| pipe
== VFP11_DS
)
5909 state
= use_vector
? 1 : 2;
5911 veneer_of_insn
= insn
;
5917 int other_regs
[3], other_numregs
;
5918 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5921 if (pipe
!= VFP11_BAD
5922 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5932 int other_regs
[3], other_numregs
;
5933 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5936 if (pipe
!= VFP11_BAD
5937 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5943 next_i
= first_fmac
+ 4;
5949 abort (); /* Should be unreachable. */
5954 elf32_vfp11_erratum_list
*newerr
5955 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5958 errcount
= ++(elf32_arm_section_data (sec
)->erratumcount
);
5960 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
5965 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
5972 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
5977 newerr
->next
= sec_data
->erratumlist
;
5978 sec_data
->erratumlist
= newerr
;
5987 if (contents
!= NULL
5988 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5996 if (contents
!= NULL
5997 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
6003 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
6004 after sections have been laid out, using specially-named symbols. */
6007 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
6008 struct bfd_link_info
*link_info
)
6011 struct elf32_arm_link_hash_table
*globals
;
6014 if (link_info
->relocatable
)
6017 /* Skip if this bfd does not correspond to an ELF image. */
6018 if (! is_arm_elf (abfd
))
6021 globals
= elf32_arm_hash_table (link_info
);
6023 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
6024 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
6026 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6028 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
6029 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
6031 for (; errnode
!= NULL
; errnode
= errnode
->next
)
6033 struct elf_link_hash_entry
*myh
;
6036 switch (errnode
->type
)
6038 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
6039 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
6040 /* Find veneer symbol. */
6041 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
6042 errnode
->u
.b
.veneer
->u
.v
.id
);
6044 myh
= elf_link_hash_lookup
6045 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6048 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6049 "`%s'"), abfd
, tmp_name
);
6051 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6052 + myh
->root
.u
.def
.section
->output_offset
6053 + myh
->root
.u
.def
.value
;
6055 errnode
->u
.b
.veneer
->vma
= vma
;
6058 case VFP11_ERRATUM_ARM_VENEER
:
6059 case VFP11_ERRATUM_THUMB_VENEER
:
6060 /* Find return location. */
6061 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
6064 myh
= elf_link_hash_lookup
6065 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
6068 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
6069 "`%s'"), abfd
, tmp_name
);
6071 vma
= myh
->root
.u
.def
.section
->output_section
->vma
6072 + myh
->root
.u
.def
.section
->output_offset
6073 + myh
->root
.u
.def
.value
;
6075 errnode
->u
.v
.branch
->vma
= vma
;
6088 /* Set target relocation values needed during linking. */
6091 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
6092 struct bfd_link_info
*link_info
,
6094 char * target2_type
,
6097 bfd_arm_vfp11_fix vfp11_fix
,
6098 int no_enum_warn
, int no_wchar_warn
,
6099 int pic_veneer
, int fix_cortex_a8
)
6101 struct elf32_arm_link_hash_table
*globals
;
6103 globals
= elf32_arm_hash_table (link_info
);
6105 globals
->target1_is_rel
= target1_is_rel
;
6106 if (strcmp (target2_type
, "rel") == 0)
6107 globals
->target2_reloc
= R_ARM_REL32
;
6108 else if (strcmp (target2_type
, "abs") == 0)
6109 globals
->target2_reloc
= R_ARM_ABS32
;
6110 else if (strcmp (target2_type
, "got-rel") == 0)
6111 globals
->target2_reloc
= R_ARM_GOT_PREL
;
6114 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
6117 globals
->fix_v4bx
= fix_v4bx
;
6118 globals
->use_blx
|= use_blx
;
6119 globals
->vfp11_fix
= vfp11_fix
;
6120 globals
->pic_veneer
= pic_veneer
;
6121 globals
->fix_cortex_a8
= fix_cortex_a8
;
6123 BFD_ASSERT (is_arm_elf (output_bfd
));
6124 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
6125 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
6128 /* Replace the target offset of a Thumb bl or b.w instruction. */
6131 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
6137 BFD_ASSERT ((offset
& 1) == 0);
6139 upper
= bfd_get_16 (abfd
, insn
);
6140 lower
= bfd_get_16 (abfd
, insn
+ 2);
6141 reloc_sign
= (offset
< 0) ? 1 : 0;
6142 upper
= (upper
& ~(bfd_vma
) 0x7ff)
6143 | ((offset
>> 12) & 0x3ff)
6144 | (reloc_sign
<< 10);
6145 lower
= (lower
& ~(bfd_vma
) 0x2fff)
6146 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
6147 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
6148 | ((offset
>> 1) & 0x7ff);
6149 bfd_put_16 (abfd
, upper
, insn
);
6150 bfd_put_16 (abfd
, lower
, insn
+ 2);
6153 /* Thumb code calling an ARM function. */
6156 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
6160 asection
* input_section
,
6161 bfd_byte
* hit_data
,
6164 bfd_signed_vma addend
,
6166 char **error_message
)
6170 long int ret_offset
;
6171 struct elf_link_hash_entry
* myh
;
6172 struct elf32_arm_link_hash_table
* globals
;
6174 myh
= find_thumb_glue (info
, name
, error_message
);
6178 globals
= elf32_arm_hash_table (info
);
6180 BFD_ASSERT (globals
!= NULL
);
6181 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6183 my_offset
= myh
->root
.u
.def
.value
;
6185 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
6186 THUMB2ARM_GLUE_SECTION_NAME
);
6188 BFD_ASSERT (s
!= NULL
);
6189 BFD_ASSERT (s
->contents
!= NULL
);
6190 BFD_ASSERT (s
->output_section
!= NULL
);
6192 if ((my_offset
& 0x01) == 0x01)
6195 && sym_sec
->owner
!= NULL
6196 && !INTERWORK_FLAG (sym_sec
->owner
))
6198 (*_bfd_error_handler
)
6199 (_("%B(%s): warning: interworking not enabled.\n"
6200 " first occurrence: %B: thumb call to arm"),
6201 sym_sec
->owner
, input_bfd
, name
);
6207 myh
->root
.u
.def
.value
= my_offset
;
6209 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
6210 s
->contents
+ my_offset
);
6212 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
6213 s
->contents
+ my_offset
+ 2);
6216 /* Address of destination of the stub. */
6217 ((bfd_signed_vma
) val
)
6219 /* Offset from the start of the current section
6220 to the start of the stubs. */
6222 /* Offset of the start of this stub from the start of the stubs. */
6224 /* Address of the start of the current section. */
6225 + s
->output_section
->vma
)
6226 /* The branch instruction is 4 bytes into the stub. */
6228 /* ARM branches work from the pc of the instruction + 8. */
6231 put_arm_insn (globals
, output_bfd
,
6232 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
6233 s
->contents
+ my_offset
+ 4);
6236 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
6238 /* Now go back and fix up the original BL insn to point to here. */
6240 /* Address of where the stub is located. */
6241 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
6242 /* Address of where the BL is located. */
6243 - (input_section
->output_section
->vma
+ input_section
->output_offset
6245 /* Addend in the relocation. */
6247 /* Biassing for PC-relative addressing. */
6250 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
6255 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
6257 static struct elf_link_hash_entry
*
6258 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
6265 char ** error_message
)
6268 long int ret_offset
;
6269 struct elf_link_hash_entry
* myh
;
6270 struct elf32_arm_link_hash_table
* globals
;
6272 myh
= find_arm_glue (info
, name
, error_message
);
6276 globals
= elf32_arm_hash_table (info
);
6278 BFD_ASSERT (globals
!= NULL
);
6279 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6281 my_offset
= myh
->root
.u
.def
.value
;
6283 if ((my_offset
& 0x01) == 0x01)
6286 && sym_sec
->owner
!= NULL
6287 && !INTERWORK_FLAG (sym_sec
->owner
))
6289 (*_bfd_error_handler
)
6290 (_("%B(%s): warning: interworking not enabled.\n"
6291 " first occurrence: %B: arm call to thumb"),
6292 sym_sec
->owner
, input_bfd
, name
);
6296 myh
->root
.u
.def
.value
= my_offset
;
6298 if (info
->shared
|| globals
->root
.is_relocatable_executable
6299 || globals
->pic_veneer
)
6301 /* For relocatable objects we can't use absolute addresses,
6302 so construct the address from a relative offset. */
6303 /* TODO: If the offset is small it's probably worth
6304 constructing the address with adds. */
6305 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
6306 s
->contents
+ my_offset
);
6307 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
6308 s
->contents
+ my_offset
+ 4);
6309 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
6310 s
->contents
+ my_offset
+ 8);
6311 /* Adjust the offset by 4 for the position of the add,
6312 and 8 for the pipeline offset. */
6313 ret_offset
= (val
- (s
->output_offset
6314 + s
->output_section
->vma
6317 bfd_put_32 (output_bfd
, ret_offset
,
6318 s
->contents
+ my_offset
+ 12);
6320 else if (globals
->use_blx
)
6322 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
6323 s
->contents
+ my_offset
);
6325 /* It's a thumb address. Add the low order bit. */
6326 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
6327 s
->contents
+ my_offset
+ 4);
6331 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
6332 s
->contents
+ my_offset
);
6334 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
6335 s
->contents
+ my_offset
+ 4);
6337 /* It's a thumb address. Add the low order bit. */
6338 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
6339 s
->contents
+ my_offset
+ 8);
6345 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
6350 /* Arm code calling a Thumb function. */
6353 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
6357 asection
* input_section
,
6358 bfd_byte
* hit_data
,
6361 bfd_signed_vma addend
,
6363 char **error_message
)
6365 unsigned long int tmp
;
6368 long int ret_offset
;
6369 struct elf_link_hash_entry
* myh
;
6370 struct elf32_arm_link_hash_table
* globals
;
6372 globals
= elf32_arm_hash_table (info
);
6374 BFD_ASSERT (globals
!= NULL
);
6375 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6377 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
6378 ARM2THUMB_GLUE_SECTION_NAME
);
6379 BFD_ASSERT (s
!= NULL
);
6380 BFD_ASSERT (s
->contents
!= NULL
);
6381 BFD_ASSERT (s
->output_section
!= NULL
);
6383 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
6384 sym_sec
, val
, s
, error_message
);
6388 my_offset
= myh
->root
.u
.def
.value
;
6389 tmp
= bfd_get_32 (input_bfd
, hit_data
);
6390 tmp
= tmp
& 0xFF000000;
6392 /* Somehow these are both 4 too far, so subtract 8. */
6393 ret_offset
= (s
->output_offset
6395 + s
->output_section
->vma
6396 - (input_section
->output_offset
6397 + input_section
->output_section
->vma
6401 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
6403 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
6408 /* Populate Arm stub for an exported Thumb function. */
6411 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
6413 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
6415 struct elf_link_hash_entry
* myh
;
6416 struct elf32_arm_link_hash_entry
*eh
;
6417 struct elf32_arm_link_hash_table
* globals
;
6420 char *error_message
;
6422 eh
= elf32_arm_hash_entry (h
);
6423 /* Allocate stubs for exported Thumb functions on v4t. */
6424 if (eh
->export_glue
== NULL
)
6427 globals
= elf32_arm_hash_table (info
);
6429 BFD_ASSERT (globals
!= NULL
);
6430 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6432 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
6433 ARM2THUMB_GLUE_SECTION_NAME
);
6434 BFD_ASSERT (s
!= NULL
);
6435 BFD_ASSERT (s
->contents
!= NULL
);
6436 BFD_ASSERT (s
->output_section
!= NULL
);
6438 sec
= eh
->export_glue
->root
.u
.def
.section
;
6440 BFD_ASSERT (sec
->output_section
!= NULL
);
6442 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
6443 + sec
->output_section
->vma
;
6445 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
6446 h
->root
.u
.def
.section
->owner
,
6447 globals
->obfd
, sec
, val
, s
,
6453 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
6456 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
6461 struct elf32_arm_link_hash_table
*globals
;
6463 globals
= elf32_arm_hash_table (info
);
6465 BFD_ASSERT (globals
!= NULL
);
6466 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
6468 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
6469 ARM_BX_GLUE_SECTION_NAME
);
6470 BFD_ASSERT (s
!= NULL
);
6471 BFD_ASSERT (s
->contents
!= NULL
);
6472 BFD_ASSERT (s
->output_section
!= NULL
);
6474 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
6476 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
6478 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
6480 p
= s
->contents
+ glue_addr
;
6481 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
6482 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
6483 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
6484 globals
->bx_glue_offset
[reg
] |= 1;
6487 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
6490 /* Generate Arm stubs for exported Thumb symbols. */
6492 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6493 struct bfd_link_info
*link_info
)
6495 struct elf32_arm_link_hash_table
* globals
;
6497 if (link_info
== NULL
)
6498 /* Ignore this if we are not called by the ELF backend linker. */
6501 globals
= elf32_arm_hash_table (link_info
);
6502 /* If blx is available then exported Thumb symbols are OK and there is
6504 if (globals
->use_blx
)
6507 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
6511 /* Some relocations map to different relocations depending on the
6512 target. Return the real relocation. */
6515 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
6521 if (globals
->target1_is_rel
)
6527 return globals
->target2_reloc
;
6534 /* Return the base VMA address which should be subtracted from real addresses
6535 when resolving @dtpoff relocation.
6536 This is PT_TLS segment p_vaddr. */
6539 dtpoff_base (struct bfd_link_info
*info
)
6541 /* If tls_sec is NULL, we should have signalled an error already. */
6542 if (elf_hash_table (info
)->tls_sec
== NULL
)
6544 return elf_hash_table (info
)->tls_sec
->vma
;
6547 /* Return the relocation value for @tpoff relocation
6548 if STT_TLS virtual address is ADDRESS. */
6551 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
6553 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6556 /* If tls_sec is NULL, we should have signalled an error already. */
6557 if (htab
->tls_sec
== NULL
)
6559 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
6560 return address
- htab
->tls_sec
->vma
+ base
;
6563 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
6564 VALUE is the relocation value. */
6566 static bfd_reloc_status_type
6567 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
6570 return bfd_reloc_overflow
;
6572 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
6573 bfd_put_32 (abfd
, value
, data
);
6574 return bfd_reloc_ok
;
6577 /* For a given value of n, calculate the value of G_n as required to
6578 deal with group relocations. We return it in the form of an
6579 encoded constant-and-rotation, together with the final residual. If n is
6580 specified as less than zero, then final_residual is filled with the
6581 input value and no further action is performed. */
6584 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
6588 bfd_vma encoded_g_n
= 0;
6589 bfd_vma residual
= value
; /* Also known as Y_n. */
6591 for (current_n
= 0; current_n
<= n
; current_n
++)
6595 /* Calculate which part of the value to mask. */
6602 /* Determine the most significant bit in the residual and
6603 align the resulting value to a 2-bit boundary. */
6604 for (msb
= 30; msb
>= 0; msb
-= 2)
6605 if (residual
& (3 << msb
))
6608 /* The desired shift is now (msb - 6), or zero, whichever
6615 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
6616 g_n
= residual
& (0xff << shift
);
6617 encoded_g_n
= (g_n
>> shift
)
6618 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
6620 /* Calculate the residual for the next time around. */
6624 *final_residual
= residual
;
6629 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
6630 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
6633 identify_add_or_sub (bfd_vma insn
)
6635 int opcode
= insn
& 0x1e00000;
6637 if (opcode
== 1 << 23) /* ADD */
6640 if (opcode
== 1 << 22) /* SUB */
6646 /* Perform a relocation as part of a final link. */
6648 static bfd_reloc_status_type
6649 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
6652 asection
* input_section
,
6653 bfd_byte
* contents
,
6654 Elf_Internal_Rela
* rel
,
6656 struct bfd_link_info
* info
,
6658 const char * sym_name
,
6660 struct elf_link_hash_entry
* h
,
6661 bfd_boolean
* unresolved_reloc_p
,
6662 char ** error_message
)
6664 unsigned long r_type
= howto
->type
;
6665 unsigned long r_symndx
;
6666 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
6667 bfd
* dynobj
= NULL
;
6668 Elf_Internal_Shdr
* symtab_hdr
;
6669 struct elf_link_hash_entry
** sym_hashes
;
6670 bfd_vma
* local_got_offsets
;
6671 asection
* sgot
= NULL
;
6672 asection
* splt
= NULL
;
6673 asection
* sreloc
= NULL
;
6675 bfd_signed_vma signed_addend
;
6676 struct elf32_arm_link_hash_table
* globals
;
6678 globals
= elf32_arm_hash_table (info
);
6680 BFD_ASSERT (is_arm_elf (input_bfd
));
6682 /* Some relocation types map to different relocations depending on the
6683 target. We pick the right one here. */
6684 r_type
= arm_real_reloc_type (globals
, r_type
);
6685 if (r_type
!= howto
->type
)
6686 howto
= elf32_arm_howto_from_type (r_type
);
6688 /* If the start address has been set, then set the EF_ARM_HASENTRY
6689 flag. Setting this more than once is redundant, but the cost is
6690 not too high, and it keeps the code simple.
6692 The test is done here, rather than somewhere else, because the
6693 start address is only set just before the final link commences.
6695 Note - if the user deliberately sets a start address of 0, the
6696 flag will not be set. */
6697 if (bfd_get_start_address (output_bfd
) != 0)
6698 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
6700 dynobj
= elf_hash_table (info
)->dynobj
;
6703 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6704 splt
= bfd_get_section_by_name (dynobj
, ".plt");
6706 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
6707 sym_hashes
= elf_sym_hashes (input_bfd
);
6708 local_got_offsets
= elf_local_got_offsets (input_bfd
);
6709 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6711 if (globals
->use_rel
)
6713 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
6715 if (addend
& ((howto
->src_mask
+ 1) >> 1))
6718 signed_addend
&= ~ howto
->src_mask
;
6719 signed_addend
|= addend
;
6722 signed_addend
= addend
;
6725 addend
= signed_addend
= rel
->r_addend
;
6730 /* We don't need to find a value for this symbol. It's just a
6732 *unresolved_reloc_p
= FALSE
;
6733 return bfd_reloc_ok
;
6736 if (!globals
->vxworks_p
)
6737 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
6741 case R_ARM_ABS32_NOI
:
6743 case R_ARM_REL32_NOI
:
6749 /* Handle relocations which should use the PLT entry. ABS32/REL32
6750 will use the symbol's value, which may point to a PLT entry, but we
6751 don't need to handle that here. If we created a PLT entry, all
6752 branches in this object should go to it, except if the PLT is too
6753 far away, in which case a long branch stub should be inserted. */
6754 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
6755 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
6756 && r_type
!= R_ARM_CALL
6757 && r_type
!= R_ARM_JUMP24
6758 && r_type
!= R_ARM_PLT32
)
6761 && h
->plt
.offset
!= (bfd_vma
) -1)
6763 /* If we've created a .plt section, and assigned a PLT entry to
6764 this function, it should not be known to bind locally. If
6765 it were, we would have cleared the PLT entry. */
6766 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
6768 value
= (splt
->output_section
->vma
6769 + splt
->output_offset
6771 *unresolved_reloc_p
= FALSE
;
6772 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6773 contents
, rel
->r_offset
, value
,
6777 /* When generating a shared object or relocatable executable, these
6778 relocations are copied into the output file to be resolved at
6780 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
6781 && (input_section
->flags
& SEC_ALLOC
)
6782 && !(elf32_arm_hash_table (info
)->vxworks_p
6783 && strcmp (input_section
->output_section
->name
,
6785 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
6786 || !SYMBOL_CALLS_LOCAL (info
, h
))
6788 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6789 || h
->root
.type
!= bfd_link_hash_undefweak
)
6790 && r_type
!= R_ARM_PC24
6791 && r_type
!= R_ARM_CALL
6792 && r_type
!= R_ARM_JUMP24
6793 && r_type
!= R_ARM_PREL31
6794 && r_type
!= R_ARM_PLT32
)
6796 Elf_Internal_Rela outrel
;
6798 bfd_boolean skip
, relocate
;
6800 *unresolved_reloc_p
= FALSE
;
6804 sreloc
= _bfd_elf_get_dynamic_reloc_section (input_bfd
, input_section
,
6805 ! globals
->use_rel
);
6808 return bfd_reloc_notsupported
;
6814 outrel
.r_addend
= addend
;
6816 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
6818 if (outrel
.r_offset
== (bfd_vma
) -1)
6820 else if (outrel
.r_offset
== (bfd_vma
) -2)
6821 skip
= TRUE
, relocate
= TRUE
;
6822 outrel
.r_offset
+= (input_section
->output_section
->vma
6823 + input_section
->output_offset
);
6826 memset (&outrel
, 0, sizeof outrel
);
6831 || !h
->def_regular
))
6832 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
6837 /* This symbol is local, or marked to become local. */
6838 if (sym_flags
== STT_ARM_TFUNC
)
6840 if (globals
->symbian_p
)
6844 /* On Symbian OS, the data segment and text segement
6845 can be relocated independently. Therefore, we
6846 must indicate the segment to which this
6847 relocation is relative. The BPABI allows us to
6848 use any symbol in the right segment; we just use
6849 the section symbol as it is convenient. (We
6850 cannot use the symbol given by "h" directly as it
6851 will not appear in the dynamic symbol table.)
6853 Note that the dynamic linker ignores the section
6854 symbol value, so we don't subtract osec->vma
6855 from the emitted reloc addend. */
6857 osec
= sym_sec
->output_section
;
6859 osec
= input_section
->output_section
;
6860 symbol
= elf_section_data (osec
)->dynindx
;
6863 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6865 if ((osec
->flags
& SEC_READONLY
) == 0
6866 && htab
->data_index_section
!= NULL
)
6867 osec
= htab
->data_index_section
;
6869 osec
= htab
->text_index_section
;
6870 symbol
= elf_section_data (osec
)->dynindx
;
6872 BFD_ASSERT (symbol
!= 0);
6875 /* On SVR4-ish systems, the dynamic loader cannot
6876 relocate the text and data segments independently,
6877 so the symbol does not matter. */
6879 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
6880 if (globals
->use_rel
)
6883 outrel
.r_addend
+= value
;
6886 loc
= sreloc
->contents
;
6887 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
6888 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6890 /* If this reloc is against an external symbol, we do not want to
6891 fiddle with the addend. Otherwise, we need to include the symbol
6892 value so that it becomes an addend for the dynamic reloc. */
6894 return bfd_reloc_ok
;
6896 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6897 contents
, rel
->r_offset
, value
,
6900 else switch (r_type
)
6903 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
6905 case R_ARM_XPC25
: /* Arm BLX instruction. */
6908 case R_ARM_PC24
: /* Arm B/BL instruction. */
6912 bfd_signed_vma branch_offset
;
6913 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
6915 if (r_type
== R_ARM_XPC25
)
6917 /* Check for Arm calling Arm function. */
6918 /* FIXME: Should we translate the instruction into a BL
6919 instruction instead ? */
6920 if (sym_flags
!= STT_ARM_TFUNC
)
6921 (*_bfd_error_handler
)
6922 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6924 h
? h
->root
.root
.string
: "(local)");
6926 else if (r_type
== R_ARM_PC24
)
6928 /* Check for Arm calling Thumb function. */
6929 if (sym_flags
== STT_ARM_TFUNC
)
6931 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
6932 output_bfd
, input_section
,
6933 hit_data
, sym_sec
, rel
->r_offset
,
6934 signed_addend
, value
,
6936 return bfd_reloc_ok
;
6938 return bfd_reloc_dangerous
;
6942 /* Check if a stub has to be inserted because the
6943 destination is too far or we are changing mode. */
6944 if ( r_type
== R_ARM_CALL
6945 || r_type
== R_ARM_JUMP24
6946 || r_type
== R_ARM_PLT32
)
6948 /* If the call goes through a PLT entry, make sure to
6949 check distance to the right destination address. */
6950 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6952 value
= (splt
->output_section
->vma
6953 + splt
->output_offset
6955 *unresolved_reloc_p
= FALSE
;
6958 from
= (input_section
->output_section
->vma
6959 + input_section
->output_offset
6961 branch_offset
= (bfd_signed_vma
)(value
- from
);
6963 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
6964 || branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
6965 || ((sym_flags
== STT_ARM_TFUNC
)
6966 && (((r_type
== R_ARM_CALL
) && !globals
->use_blx
)
6967 || (r_type
== R_ARM_JUMP24
)
6968 || (r_type
== R_ARM_PLT32
) ))
6971 /* The target is out of reach, so redirect the
6972 branch to the local stub for this function. */
6974 stub_entry
= elf32_arm_get_stub_entry (input_section
,
6977 if (stub_entry
!= NULL
)
6978 value
= (stub_entry
->stub_offset
6979 + stub_entry
->stub_sec
->output_offset
6980 + stub_entry
->stub_sec
->output_section
->vma
);
6984 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6986 S is the address of the symbol in the relocation.
6987 P is address of the instruction being relocated.
6988 A is the addend (extracted from the instruction) in bytes.
6990 S is held in 'value'.
6991 P is the base address of the section containing the
6992 instruction plus the offset of the reloc into that
6994 (input_section->output_section->vma +
6995 input_section->output_offset +
6997 A is the addend, converted into bytes, ie:
7000 Note: None of these operations have knowledge of the pipeline
7001 size of the processor, thus it is up to the assembler to
7002 encode this information into the addend. */
7003 value
-= (input_section
->output_section
->vma
7004 + input_section
->output_offset
);
7005 value
-= rel
->r_offset
;
7006 if (globals
->use_rel
)
7007 value
+= (signed_addend
<< howto
->size
);
7009 /* RELA addends do not have to be adjusted by howto->size. */
7010 value
+= signed_addend
;
7012 signed_addend
= value
;
7013 signed_addend
>>= howto
->rightshift
;
7015 /* A branch to an undefined weak symbol is turned into a jump to
7016 the next instruction unless a PLT entry will be created. */
7017 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
7018 && !(splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1))
7020 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000)
7025 /* Perform a signed range check. */
7026 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
7027 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
7028 return bfd_reloc_overflow
;
7030 addend
= (value
& 2);
7032 value
= (signed_addend
& howto
->dst_mask
)
7033 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
7035 if (r_type
== R_ARM_CALL
)
7037 /* Set the H bit in the BLX instruction. */
7038 if (sym_flags
== STT_ARM_TFUNC
)
7043 value
&= ~(bfd_vma
)(1 << 24);
7046 /* Select the correct instruction (BL or BLX). */
7047 /* Only if we are not handling a BL to a stub. In this
7048 case, mode switching is performed by the stub. */
7049 if (sym_flags
== STT_ARM_TFUNC
&& !stub_entry
)
7053 value
&= ~(bfd_vma
)(1 << 28);
7063 if (sym_flags
== STT_ARM_TFUNC
)
7067 case R_ARM_ABS32_NOI
:
7073 if (sym_flags
== STT_ARM_TFUNC
)
7075 value
-= (input_section
->output_section
->vma
7076 + input_section
->output_offset
+ rel
->r_offset
);
7079 case R_ARM_REL32_NOI
:
7081 value
-= (input_section
->output_section
->vma
7082 + input_section
->output_offset
+ rel
->r_offset
);
7086 value
-= (input_section
->output_section
->vma
7087 + input_section
->output_offset
+ rel
->r_offset
);
7088 value
+= signed_addend
;
7089 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
7091 /* Check for overflow. */
7092 if ((value
^ (value
>> 1)) & (1 << 30))
7093 return bfd_reloc_overflow
;
7095 value
&= 0x7fffffff;
7096 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
7097 if (sym_flags
== STT_ARM_TFUNC
)
7102 bfd_put_32 (input_bfd
, value
, hit_data
);
7103 return bfd_reloc_ok
;
7107 if ((long) value
> 0x7f || (long) value
< -0x80)
7108 return bfd_reloc_overflow
;
7110 bfd_put_8 (input_bfd
, value
, hit_data
);
7111 return bfd_reloc_ok
;
7116 if ((long) value
> 0x7fff || (long) value
< -0x8000)
7117 return bfd_reloc_overflow
;
7119 bfd_put_16 (input_bfd
, value
, hit_data
);
7120 return bfd_reloc_ok
;
7122 case R_ARM_THM_ABS5
:
7123 /* Support ldr and str instructions for the thumb. */
7124 if (globals
->use_rel
)
7126 /* Need to refetch addend. */
7127 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
7128 /* ??? Need to determine shift amount from operand size. */
7129 addend
>>= howto
->rightshift
;
7133 /* ??? Isn't value unsigned? */
7134 if ((long) value
> 0x1f || (long) value
< -0x10)
7135 return bfd_reloc_overflow
;
7137 /* ??? Value needs to be properly shifted into place first. */
7138 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
7139 bfd_put_16 (input_bfd
, value
, hit_data
);
7140 return bfd_reloc_ok
;
7142 case R_ARM_THM_ALU_PREL_11_0
:
7143 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
7146 bfd_signed_vma relocation
;
7148 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
7149 | bfd_get_16 (input_bfd
, hit_data
+ 2);
7151 if (globals
->use_rel
)
7153 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
7154 | ((insn
& (1 << 26)) >> 15);
7155 if (insn
& 0xf00000)
7156 signed_addend
= -signed_addend
;
7159 relocation
= value
+ signed_addend
;
7160 relocation
-= (input_section
->output_section
->vma
7161 + input_section
->output_offset
7164 value
= abs (relocation
);
7166 if (value
>= 0x1000)
7167 return bfd_reloc_overflow
;
7169 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
7170 | ((value
& 0x700) << 4)
7171 | ((value
& 0x800) << 15);
7175 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
7176 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
7178 return bfd_reloc_ok
;
7181 case R_ARM_THM_PC12
:
7182 /* Corresponds to: ldr.w reg, [pc, #offset]. */
7185 bfd_signed_vma relocation
;
7187 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
7188 | bfd_get_16 (input_bfd
, hit_data
+ 2);
7190 if (globals
->use_rel
)
7192 signed_addend
= insn
& 0xfff;
7193 if (!(insn
& (1 << 23)))
7194 signed_addend
= -signed_addend
;
7197 relocation
= value
+ signed_addend
;
7198 relocation
-= (input_section
->output_section
->vma
7199 + input_section
->output_offset
7202 value
= abs (relocation
);
7204 if (value
>= 0x1000)
7205 return bfd_reloc_overflow
;
7207 insn
= (insn
& 0xff7ff000) | value
;
7208 if (relocation
>= 0)
7211 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
7212 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
7214 return bfd_reloc_ok
;
7217 case R_ARM_THM_XPC22
:
7218 case R_ARM_THM_CALL
:
7219 case R_ARM_THM_JUMP24
:
7220 /* Thumb BL (branch long instruction). */
7224 bfd_boolean overflow
= FALSE
;
7225 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
7226 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
7227 bfd_signed_vma reloc_signed_max
;
7228 bfd_signed_vma reloc_signed_min
;
7230 bfd_signed_vma signed_check
;
7232 int thumb2
= using_thumb2 (globals
);
7234 /* A branch to an undefined weak symbol is turned into a jump to
7235 the next instruction unless a PLT entry will be created. */
7236 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
7237 && !(splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1))
7239 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
7240 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
7241 return bfd_reloc_ok
;
7244 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
7245 with Thumb-1) involving the J1 and J2 bits. */
7246 if (globals
->use_rel
)
7248 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
7249 bfd_vma upper
= upper_insn
& 0x3ff;
7250 bfd_vma lower
= lower_insn
& 0x7ff;
7251 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
7252 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
7253 bfd_vma i1
= j1
^ s
? 0 : 1;
7254 bfd_vma i2
= j2
^ s
? 0 : 1;
7256 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
7258 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
7260 signed_addend
= addend
;
7263 if (r_type
== R_ARM_THM_XPC22
)
7265 /* Check for Thumb to Thumb call. */
7266 /* FIXME: Should we translate the instruction into a BL
7267 instruction instead ? */
7268 if (sym_flags
== STT_ARM_TFUNC
)
7269 (*_bfd_error_handler
)
7270 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
7272 h
? h
->root
.root
.string
: "(local)");
7276 /* If it is not a call to Thumb, assume call to Arm.
7277 If it is a call relative to a section name, then it is not a
7278 function call at all, but rather a long jump. Calls through
7279 the PLT do not require stubs. */
7280 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
7281 && (h
== NULL
|| splt
== NULL
7282 || h
->plt
.offset
== (bfd_vma
) -1))
7284 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
7286 /* Convert BL to BLX. */
7287 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
7289 else if (( r_type
!= R_ARM_THM_CALL
)
7290 && (r_type
!= R_ARM_THM_JUMP24
))
7292 if (elf32_thumb_to_arm_stub
7293 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
7294 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
7296 return bfd_reloc_ok
;
7298 return bfd_reloc_dangerous
;
7301 else if (sym_flags
== STT_ARM_TFUNC
&& globals
->use_blx
7302 && r_type
== R_ARM_THM_CALL
)
7304 /* Make sure this is a BL. */
7305 lower_insn
|= 0x1800;
7309 /* Handle calls via the PLT. */
7310 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
7312 value
= (splt
->output_section
->vma
7313 + splt
->output_offset
7315 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
7317 /* If the Thumb BLX instruction is available, convert the
7318 BL to a BLX instruction to call the ARM-mode PLT entry. */
7319 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
7322 /* Target the Thumb stub before the ARM PLT entry. */
7323 value
-= PLT_THUMB_STUB_SIZE
;
7324 *unresolved_reloc_p
= FALSE
;
7327 if (r_type
== R_ARM_THM_CALL
|| r_type
== R_ARM_THM_JUMP24
)
7329 /* Check if a stub has to be inserted because the destination
7332 bfd_signed_vma branch_offset
;
7333 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
7335 from
= (input_section
->output_section
->vma
7336 + input_section
->output_offset
7338 branch_offset
= (bfd_signed_vma
)(value
- from
);
7341 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
7342 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
7345 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
7346 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
7347 || ((sym_flags
!= STT_ARM_TFUNC
)
7348 && (((r_type
== R_ARM_THM_CALL
) && !globals
->use_blx
)
7349 || r_type
== R_ARM_THM_JUMP24
)))
7351 /* The target is out of reach or we are changing modes, so
7352 redirect the branch to the local stub for this
7354 stub_entry
= elf32_arm_get_stub_entry (input_section
,
7357 if (stub_entry
!= NULL
)
7358 value
= (stub_entry
->stub_offset
7359 + stub_entry
->stub_sec
->output_offset
7360 + stub_entry
->stub_sec
->output_section
->vma
);
7362 /* If this call becomes a call to Arm, force BLX. */
7363 if (globals
->use_blx
&& (r_type
== R_ARM_THM_CALL
))
7366 && !arm_stub_is_thumb (stub_entry
->stub_type
))
7367 || (sym_flags
!= STT_ARM_TFUNC
))
7368 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
7373 relocation
= value
+ signed_addend
;
7375 relocation
-= (input_section
->output_section
->vma
7376 + input_section
->output_offset
7379 check
= relocation
>> howto
->rightshift
;
7381 /* If this is a signed value, the rightshift just dropped
7382 leading 1 bits (assuming twos complement). */
7383 if ((bfd_signed_vma
) relocation
>= 0)
7384 signed_check
= check
;
7386 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
7388 /* Calculate the permissable maximum and minimum values for
7389 this relocation according to whether we're relocating for
7391 bitsize
= howto
->bitsize
;
7394 reloc_signed_max
= ((1 << (bitsize
- 1)) - 1) >> howto
->rightshift
;
7395 reloc_signed_min
= ~reloc_signed_max
;
7397 /* Assumes two's complement. */
7398 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
7401 if ((lower_insn
& 0x5000) == 0x4000)
7402 /* For a BLX instruction, make sure that the relocation is rounded up
7403 to a word boundary. This follows the semantics of the instruction
7404 which specifies that bit 1 of the target address will come from bit
7405 1 of the base address. */
7406 relocation
= (relocation
+ 2) & ~ 3;
7408 /* Put RELOCATION back into the insn. Assumes two's complement.
7409 We use the Thumb-2 encoding, which is safe even if dealing with
7410 a Thumb-1 instruction by virtue of our overflow check above. */
7411 reloc_sign
= (signed_check
< 0) ? 1 : 0;
7412 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
7413 | ((relocation
>> 12) & 0x3ff)
7414 | (reloc_sign
<< 10);
7415 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
7416 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
7417 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
7418 | ((relocation
>> 1) & 0x7ff);
7420 /* Put the relocated value back in the object file: */
7421 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
7422 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
7424 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
7428 case R_ARM_THM_JUMP19
:
7429 /* Thumb32 conditional branch instruction. */
7432 bfd_boolean overflow
= FALSE
;
7433 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
7434 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
7435 bfd_signed_vma reloc_signed_max
= 0xffffe;
7436 bfd_signed_vma reloc_signed_min
= -0x100000;
7437 bfd_signed_vma signed_check
;
7439 /* Need to refetch the addend, reconstruct the top three bits,
7440 and squish the two 11 bit pieces together. */
7441 if (globals
->use_rel
)
7443 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
7444 bfd_vma upper
= (upper_insn
& 0x003f);
7445 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
7446 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
7447 bfd_vma lower
= (lower_insn
& 0x07ff);
7452 upper
-= 0x0100; /* Sign extend. */
7454 addend
= (upper
<< 12) | (lower
<< 1);
7455 signed_addend
= addend
;
7458 /* Handle calls via the PLT. */
7459 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
7461 value
= (splt
->output_section
->vma
7462 + splt
->output_offset
7464 /* Target the Thumb stub before the ARM PLT entry. */
7465 value
-= PLT_THUMB_STUB_SIZE
;
7466 *unresolved_reloc_p
= FALSE
;
7469 /* ??? Should handle interworking? GCC might someday try to
7470 use this for tail calls. */
7472 relocation
= value
+ signed_addend
;
7473 relocation
-= (input_section
->output_section
->vma
7474 + input_section
->output_offset
7476 signed_check
= (bfd_signed_vma
) relocation
;
7478 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
7481 /* Put RELOCATION back into the insn. */
7483 bfd_vma S
= (relocation
& 0x00100000) >> 20;
7484 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
7485 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
7486 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
7487 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
7489 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
7490 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
7493 /* Put the relocated value back in the object file: */
7494 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
7495 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
7497 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
7500 case R_ARM_THM_JUMP11
:
7501 case R_ARM_THM_JUMP8
:
7502 case R_ARM_THM_JUMP6
:
7503 /* Thumb B (branch) instruction). */
7505 bfd_signed_vma relocation
;
7506 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
7507 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
7508 bfd_signed_vma signed_check
;
7510 /* CZB cannot jump backward. */
7511 if (r_type
== R_ARM_THM_JUMP6
)
7512 reloc_signed_min
= 0;
7514 if (globals
->use_rel
)
7516 /* Need to refetch addend. */
7517 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
7518 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7521 signed_addend
&= ~ howto
->src_mask
;
7522 signed_addend
|= addend
;
7525 signed_addend
= addend
;
7526 /* The value in the insn has been right shifted. We need to
7527 undo this, so that we can perform the address calculation
7528 in terms of bytes. */
7529 signed_addend
<<= howto
->rightshift
;
7531 relocation
= value
+ signed_addend
;
7533 relocation
-= (input_section
->output_section
->vma
7534 + input_section
->output_offset
7537 relocation
>>= howto
->rightshift
;
7538 signed_check
= relocation
;
7540 if (r_type
== R_ARM_THM_JUMP6
)
7541 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
7543 relocation
&= howto
->dst_mask
;
7544 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
7546 bfd_put_16 (input_bfd
, relocation
, hit_data
);
7548 /* Assumes two's complement. */
7549 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
7550 return bfd_reloc_overflow
;
7552 return bfd_reloc_ok
;
7555 case R_ARM_ALU_PCREL7_0
:
7556 case R_ARM_ALU_PCREL15_8
:
7557 case R_ARM_ALU_PCREL23_15
:
7562 insn
= bfd_get_32 (input_bfd
, hit_data
);
7563 if (globals
->use_rel
)
7565 /* Extract the addend. */
7566 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
7567 signed_addend
= addend
;
7569 relocation
= value
+ signed_addend
;
7571 relocation
-= (input_section
->output_section
->vma
7572 + input_section
->output_offset
7574 insn
= (insn
& ~0xfff)
7575 | ((howto
->bitpos
<< 7) & 0xf00)
7576 | ((relocation
>> howto
->bitpos
) & 0xff);
7577 bfd_put_32 (input_bfd
, value
, hit_data
);
7579 return bfd_reloc_ok
;
7581 case R_ARM_GNU_VTINHERIT
:
7582 case R_ARM_GNU_VTENTRY
:
7583 return bfd_reloc_ok
;
7585 case R_ARM_GOTOFF32
:
7586 /* Relocation is relative to the start of the
7587 global offset table. */
7589 BFD_ASSERT (sgot
!= NULL
);
7591 return bfd_reloc_notsupported
;
7593 /* If we are addressing a Thumb function, we need to adjust the
7594 address by one, so that attempts to call the function pointer will
7595 correctly interpret it as Thumb code. */
7596 if (sym_flags
== STT_ARM_TFUNC
)
7599 /* Note that sgot->output_offset is not involved in this
7600 calculation. We always want the start of .got. If we
7601 define _GLOBAL_OFFSET_TABLE in a different way, as is
7602 permitted by the ABI, we might have to change this
7604 value
-= sgot
->output_section
->vma
;
7605 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7606 contents
, rel
->r_offset
, value
,
7610 /* Use global offset table as symbol value. */
7611 BFD_ASSERT (sgot
!= NULL
);
7614 return bfd_reloc_notsupported
;
7616 *unresolved_reloc_p
= FALSE
;
7617 value
= sgot
->output_section
->vma
;
7618 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7619 contents
, rel
->r_offset
, value
,
7623 case R_ARM_GOT_PREL
:
7624 /* Relocation is to the entry for this symbol in the
7625 global offset table. */
7627 return bfd_reloc_notsupported
;
7634 off
= h
->got
.offset
;
7635 BFD_ASSERT (off
!= (bfd_vma
) -1);
7636 dyn
= globals
->root
.dynamic_sections_created
;
7638 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7640 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7641 || (ELF_ST_VISIBILITY (h
->other
)
7642 && h
->root
.type
== bfd_link_hash_undefweak
))
7644 /* This is actually a static link, or it is a -Bsymbolic link
7645 and the symbol is defined locally. We must initialize this
7646 entry in the global offset table. Since the offset must
7647 always be a multiple of 4, we use the least significant bit
7648 to record whether we have initialized it already.
7650 When doing a dynamic link, we create a .rel(a).got relocation
7651 entry to initialize the value. This is done in the
7652 finish_dynamic_symbol routine. */
7657 /* If we are addressing a Thumb function, we need to
7658 adjust the address by one, so that attempts to
7659 call the function pointer will correctly
7660 interpret it as Thumb code. */
7661 if (sym_flags
== STT_ARM_TFUNC
)
7664 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
7669 *unresolved_reloc_p
= FALSE
;
7671 value
= sgot
->output_offset
+ off
;
7677 BFD_ASSERT (local_got_offsets
!= NULL
&&
7678 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
7680 off
= local_got_offsets
[r_symndx
];
7682 /* The offset must always be a multiple of 4. We use the
7683 least significant bit to record whether we have already
7684 generated the necessary reloc. */
7689 /* If we are addressing a Thumb function, we need to
7690 adjust the address by one, so that attempts to
7691 call the function pointer will correctly
7692 interpret it as Thumb code. */
7693 if (sym_flags
== STT_ARM_TFUNC
)
7696 if (globals
->use_rel
)
7697 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
7702 Elf_Internal_Rela outrel
;
7705 srelgot
= (bfd_get_section_by_name
7706 (dynobj
, RELOC_SECTION (globals
, ".got")));
7707 BFD_ASSERT (srelgot
!= NULL
);
7709 outrel
.r_addend
= addend
+ value
;
7710 outrel
.r_offset
= (sgot
->output_section
->vma
7711 + sgot
->output_offset
7713 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
7714 loc
= srelgot
->contents
;
7715 loc
+= srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
7716 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7719 local_got_offsets
[r_symndx
] |= 1;
7722 value
= sgot
->output_offset
+ off
;
7724 if (r_type
!= R_ARM_GOT32
)
7725 value
+= sgot
->output_section
->vma
;
7727 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7728 contents
, rel
->r_offset
, value
,
7731 case R_ARM_TLS_LDO32
:
7732 value
= value
- dtpoff_base (info
);
7734 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7735 contents
, rel
->r_offset
, value
,
7738 case R_ARM_TLS_LDM32
:
7742 if (globals
->sgot
== NULL
)
7745 off
= globals
->tls_ldm_got
.offset
;
7751 /* If we don't know the module number, create a relocation
7755 Elf_Internal_Rela outrel
;
7758 if (globals
->srelgot
== NULL
)
7761 outrel
.r_addend
= 0;
7762 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7763 + globals
->sgot
->output_offset
+ off
);
7764 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
7766 if (globals
->use_rel
)
7767 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7768 globals
->sgot
->contents
+ off
);
7770 loc
= globals
->srelgot
->contents
;
7771 loc
+= globals
->srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
7772 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7775 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
7777 globals
->tls_ldm_got
.offset
|= 1;
7780 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
7781 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
7783 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7784 contents
, rel
->r_offset
, value
,
7788 case R_ARM_TLS_GD32
:
7789 case R_ARM_TLS_IE32
:
7795 if (globals
->sgot
== NULL
)
7802 dyn
= globals
->root
.dynamic_sections_created
;
7803 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7805 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
7807 *unresolved_reloc_p
= FALSE
;
7810 off
= h
->got
.offset
;
7811 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
7815 if (local_got_offsets
== NULL
)
7817 off
= local_got_offsets
[r_symndx
];
7818 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
7821 if (tls_type
== GOT_UNKNOWN
)
7828 bfd_boolean need_relocs
= FALSE
;
7829 Elf_Internal_Rela outrel
;
7830 bfd_byte
*loc
= NULL
;
7833 /* The GOT entries have not been initialized yet. Do it
7834 now, and emit any relocations. If both an IE GOT and a
7835 GD GOT are necessary, we emit the GD first. */
7837 if ((info
->shared
|| indx
!= 0)
7839 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7840 || h
->root
.type
!= bfd_link_hash_undefweak
))
7843 if (globals
->srelgot
== NULL
)
7845 loc
= globals
->srelgot
->contents
;
7846 loc
+= globals
->srelgot
->reloc_count
* RELOC_SIZE (globals
);
7849 if (tls_type
& GOT_TLS_GD
)
7853 outrel
.r_addend
= 0;
7854 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7855 + globals
->sgot
->output_offset
7857 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
7859 if (globals
->use_rel
)
7860 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7861 globals
->sgot
->contents
+ cur_off
);
7863 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7864 globals
->srelgot
->reloc_count
++;
7865 loc
+= RELOC_SIZE (globals
);
7868 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
7869 globals
->sgot
->contents
+ cur_off
+ 4);
7872 outrel
.r_addend
= 0;
7873 outrel
.r_info
= ELF32_R_INFO (indx
,
7874 R_ARM_TLS_DTPOFF32
);
7875 outrel
.r_offset
+= 4;
7877 if (globals
->use_rel
)
7878 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7879 globals
->sgot
->contents
+ cur_off
+ 4);
7882 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7883 globals
->srelgot
->reloc_count
++;
7884 loc
+= RELOC_SIZE (globals
);
7889 /* If we are not emitting relocations for a
7890 general dynamic reference, then we must be in a
7891 static link or an executable link with the
7892 symbol binding locally. Mark it as belonging
7893 to module 1, the executable. */
7894 bfd_put_32 (output_bfd
, 1,
7895 globals
->sgot
->contents
+ cur_off
);
7896 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
7897 globals
->sgot
->contents
+ cur_off
+ 4);
7903 if (tls_type
& GOT_TLS_IE
)
7908 outrel
.r_addend
= value
- dtpoff_base (info
);
7910 outrel
.r_addend
= 0;
7911 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
7912 + globals
->sgot
->output_offset
7914 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
7916 if (globals
->use_rel
)
7917 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7918 globals
->sgot
->contents
+ cur_off
);
7920 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7921 globals
->srelgot
->reloc_count
++;
7922 loc
+= RELOC_SIZE (globals
);
7925 bfd_put_32 (output_bfd
, tpoff (info
, value
),
7926 globals
->sgot
->contents
+ cur_off
);
7933 local_got_offsets
[r_symndx
] |= 1;
7936 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
7938 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
7939 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
7941 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7942 contents
, rel
->r_offset
, value
,
7946 case R_ARM_TLS_LE32
:
7949 (*_bfd_error_handler
)
7950 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7951 input_bfd
, input_section
,
7952 (long) rel
->r_offset
, howto
->name
);
7956 value
= tpoff (info
, value
);
7958 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7959 contents
, rel
->r_offset
, value
,
7963 if (globals
->fix_v4bx
)
7965 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7967 /* Ensure that we have a BX instruction. */
7968 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
7970 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
7972 /* Branch to veneer. */
7974 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
7975 glue_addr
-= input_section
->output_section
->vma
7976 + input_section
->output_offset
7977 + rel
->r_offset
+ 8;
7978 insn
= (insn
& 0xf0000000) | 0x0a000000
7979 | ((glue_addr
>> 2) & 0x00ffffff);
7983 /* Preserve Rm (lowest four bits) and the condition code
7984 (highest four bits). Other bits encode MOV PC,Rm. */
7985 insn
= (insn
& 0xf000000f) | 0x01a0f000;
7988 bfd_put_32 (input_bfd
, insn
, hit_data
);
7990 return bfd_reloc_ok
;
7992 case R_ARM_MOVW_ABS_NC
:
7993 case R_ARM_MOVT_ABS
:
7994 case R_ARM_MOVW_PREL_NC
:
7995 case R_ARM_MOVT_PREL
:
7996 /* Until we properly support segment-base-relative addressing then
7997 we assume the segment base to be zero, as for the group relocations.
7998 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7999 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
8000 case R_ARM_MOVW_BREL_NC
:
8001 case R_ARM_MOVW_BREL
:
8002 case R_ARM_MOVT_BREL
:
8004 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
8006 if (globals
->use_rel
)
8008 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
8009 signed_addend
= (addend
^ 0x8000) - 0x8000;
8012 value
+= signed_addend
;
8014 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
8015 value
-= (input_section
->output_section
->vma
8016 + input_section
->output_offset
+ rel
->r_offset
);
8018 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
8019 return bfd_reloc_overflow
;
8021 if (sym_flags
== STT_ARM_TFUNC
)
8024 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
8025 || r_type
== R_ARM_MOVT_BREL
)
8029 insn
|= value
& 0xfff;
8030 insn
|= (value
& 0xf000) << 4;
8031 bfd_put_32 (input_bfd
, insn
, hit_data
);
8033 return bfd_reloc_ok
;
8035 case R_ARM_THM_MOVW_ABS_NC
:
8036 case R_ARM_THM_MOVT_ABS
:
8037 case R_ARM_THM_MOVW_PREL_NC
:
8038 case R_ARM_THM_MOVT_PREL
:
8039 /* Until we properly support segment-base-relative addressing then
8040 we assume the segment base to be zero, as for the above relocations.
8041 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
8042 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
8043 as R_ARM_THM_MOVT_ABS. */
8044 case R_ARM_THM_MOVW_BREL_NC
:
8045 case R_ARM_THM_MOVW_BREL
:
8046 case R_ARM_THM_MOVT_BREL
:
8050 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
8051 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
8053 if (globals
->use_rel
)
8055 addend
= ((insn
>> 4) & 0xf000)
8056 | ((insn
>> 15) & 0x0800)
8057 | ((insn
>> 4) & 0x0700)
8059 signed_addend
= (addend
^ 0x8000) - 0x8000;
8062 value
+= signed_addend
;
8064 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
8065 value
-= (input_section
->output_section
->vma
8066 + input_section
->output_offset
+ rel
->r_offset
);
8068 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
8069 return bfd_reloc_overflow
;
8071 if (sym_flags
== STT_ARM_TFUNC
)
8074 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
8075 || r_type
== R_ARM_THM_MOVT_BREL
)
8079 insn
|= (value
& 0xf000) << 4;
8080 insn
|= (value
& 0x0800) << 15;
8081 insn
|= (value
& 0x0700) << 4;
8082 insn
|= (value
& 0x00ff);
8084 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
8085 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
8087 return bfd_reloc_ok
;
8089 case R_ARM_ALU_PC_G0_NC
:
8090 case R_ARM_ALU_PC_G1_NC
:
8091 case R_ARM_ALU_PC_G0
:
8092 case R_ARM_ALU_PC_G1
:
8093 case R_ARM_ALU_PC_G2
:
8094 case R_ARM_ALU_SB_G0_NC
:
8095 case R_ARM_ALU_SB_G1_NC
:
8096 case R_ARM_ALU_SB_G0
:
8097 case R_ARM_ALU_SB_G1
:
8098 case R_ARM_ALU_SB_G2
:
8100 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
8101 bfd_vma pc
= input_section
->output_section
->vma
8102 + input_section
->output_offset
+ rel
->r_offset
;
8103 /* sb should be the origin of the *segment* containing the symbol.
8104 It is not clear how to obtain this OS-dependent value, so we
8105 make an arbitrary choice of zero. */
8109 bfd_signed_vma signed_value
;
8112 /* Determine which group of bits to select. */
8115 case R_ARM_ALU_PC_G0_NC
:
8116 case R_ARM_ALU_PC_G0
:
8117 case R_ARM_ALU_SB_G0_NC
:
8118 case R_ARM_ALU_SB_G0
:
8122 case R_ARM_ALU_PC_G1_NC
:
8123 case R_ARM_ALU_PC_G1
:
8124 case R_ARM_ALU_SB_G1_NC
:
8125 case R_ARM_ALU_SB_G1
:
8129 case R_ARM_ALU_PC_G2
:
8130 case R_ARM_ALU_SB_G2
:
8138 /* If REL, extract the addend from the insn. If RELA, it will
8139 have already been fetched for us. */
8140 if (globals
->use_rel
)
8143 bfd_vma constant
= insn
& 0xff;
8144 bfd_vma rotation
= (insn
& 0xf00) >> 8;
8147 signed_addend
= constant
;
8150 /* Compensate for the fact that in the instruction, the
8151 rotation is stored in multiples of 2 bits. */
8154 /* Rotate "constant" right by "rotation" bits. */
8155 signed_addend
= (constant
>> rotation
) |
8156 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
8159 /* Determine if the instruction is an ADD or a SUB.
8160 (For REL, this determines the sign of the addend.) */
8161 negative
= identify_add_or_sub (insn
);
8164 (*_bfd_error_handler
)
8165 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
8166 input_bfd
, input_section
,
8167 (long) rel
->r_offset
, howto
->name
);
8168 return bfd_reloc_overflow
;
8171 signed_addend
*= negative
;
8174 /* Compute the value (X) to go in the place. */
8175 if (r_type
== R_ARM_ALU_PC_G0_NC
8176 || r_type
== R_ARM_ALU_PC_G1_NC
8177 || r_type
== R_ARM_ALU_PC_G0
8178 || r_type
== R_ARM_ALU_PC_G1
8179 || r_type
== R_ARM_ALU_PC_G2
)
8181 signed_value
= value
- pc
+ signed_addend
;
8183 /* Section base relative. */
8184 signed_value
= value
- sb
+ signed_addend
;
8186 /* If the target symbol is a Thumb function, then set the
8187 Thumb bit in the address. */
8188 if (sym_flags
== STT_ARM_TFUNC
)
8191 /* Calculate the value of the relevant G_n, in encoded
8192 constant-with-rotation format. */
8193 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
8196 /* Check for overflow if required. */
8197 if ((r_type
== R_ARM_ALU_PC_G0
8198 || r_type
== R_ARM_ALU_PC_G1
8199 || r_type
== R_ARM_ALU_PC_G2
8200 || r_type
== R_ARM_ALU_SB_G0
8201 || r_type
== R_ARM_ALU_SB_G1
8202 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
8204 (*_bfd_error_handler
)
8205 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
8206 input_bfd
, input_section
,
8207 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
8208 return bfd_reloc_overflow
;
8211 /* Mask out the value and the ADD/SUB part of the opcode; take care
8212 not to destroy the S bit. */
8215 /* Set the opcode according to whether the value to go in the
8216 place is negative. */
8217 if (signed_value
< 0)
8222 /* Encode the offset. */
8225 bfd_put_32 (input_bfd
, insn
, hit_data
);
8227 return bfd_reloc_ok
;
8229 case R_ARM_LDR_PC_G0
:
8230 case R_ARM_LDR_PC_G1
:
8231 case R_ARM_LDR_PC_G2
:
8232 case R_ARM_LDR_SB_G0
:
8233 case R_ARM_LDR_SB_G1
:
8234 case R_ARM_LDR_SB_G2
:
8236 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
8237 bfd_vma pc
= input_section
->output_section
->vma
8238 + input_section
->output_offset
+ rel
->r_offset
;
8239 bfd_vma sb
= 0; /* See note above. */
8241 bfd_signed_vma signed_value
;
8244 /* Determine which groups of bits to calculate. */
8247 case R_ARM_LDR_PC_G0
:
8248 case R_ARM_LDR_SB_G0
:
8252 case R_ARM_LDR_PC_G1
:
8253 case R_ARM_LDR_SB_G1
:
8257 case R_ARM_LDR_PC_G2
:
8258 case R_ARM_LDR_SB_G2
:
8266 /* If REL, extract the addend from the insn. If RELA, it will
8267 have already been fetched for us. */
8268 if (globals
->use_rel
)
8270 int negative
= (insn
& (1 << 23)) ? 1 : -1;
8271 signed_addend
= negative
* (insn
& 0xfff);
8274 /* Compute the value (X) to go in the place. */
8275 if (r_type
== R_ARM_LDR_PC_G0
8276 || r_type
== R_ARM_LDR_PC_G1
8277 || r_type
== R_ARM_LDR_PC_G2
)
8279 signed_value
= value
- pc
+ signed_addend
;
8281 /* Section base relative. */
8282 signed_value
= value
- sb
+ signed_addend
;
8284 /* Calculate the value of the relevant G_{n-1} to obtain
8285 the residual at that stage. */
8286 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
8288 /* Check for overflow. */
8289 if (residual
>= 0x1000)
8291 (*_bfd_error_handler
)
8292 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
8293 input_bfd
, input_section
,
8294 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
8295 return bfd_reloc_overflow
;
8298 /* Mask out the value and U bit. */
8301 /* Set the U bit if the value to go in the place is non-negative. */
8302 if (signed_value
>= 0)
8305 /* Encode the offset. */
8308 bfd_put_32 (input_bfd
, insn
, hit_data
);
8310 return bfd_reloc_ok
;
8312 case R_ARM_LDRS_PC_G0
:
8313 case R_ARM_LDRS_PC_G1
:
8314 case R_ARM_LDRS_PC_G2
:
8315 case R_ARM_LDRS_SB_G0
:
8316 case R_ARM_LDRS_SB_G1
:
8317 case R_ARM_LDRS_SB_G2
:
8319 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
8320 bfd_vma pc
= input_section
->output_section
->vma
8321 + input_section
->output_offset
+ rel
->r_offset
;
8322 bfd_vma sb
= 0; /* See note above. */
8324 bfd_signed_vma signed_value
;
8327 /* Determine which groups of bits to calculate. */
8330 case R_ARM_LDRS_PC_G0
:
8331 case R_ARM_LDRS_SB_G0
:
8335 case R_ARM_LDRS_PC_G1
:
8336 case R_ARM_LDRS_SB_G1
:
8340 case R_ARM_LDRS_PC_G2
:
8341 case R_ARM_LDRS_SB_G2
:
8349 /* If REL, extract the addend from the insn. If RELA, it will
8350 have already been fetched for us. */
8351 if (globals
->use_rel
)
8353 int negative
= (insn
& (1 << 23)) ? 1 : -1;
8354 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
8357 /* Compute the value (X) to go in the place. */
8358 if (r_type
== R_ARM_LDRS_PC_G0
8359 || r_type
== R_ARM_LDRS_PC_G1
8360 || r_type
== R_ARM_LDRS_PC_G2
)
8362 signed_value
= value
- pc
+ signed_addend
;
8364 /* Section base relative. */
8365 signed_value
= value
- sb
+ signed_addend
;
8367 /* Calculate the value of the relevant G_{n-1} to obtain
8368 the residual at that stage. */
8369 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
8371 /* Check for overflow. */
8372 if (residual
>= 0x100)
8374 (*_bfd_error_handler
)
8375 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
8376 input_bfd
, input_section
,
8377 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
8378 return bfd_reloc_overflow
;
8381 /* Mask out the value and U bit. */
8384 /* Set the U bit if the value to go in the place is non-negative. */
8385 if (signed_value
>= 0)
8388 /* Encode the offset. */
8389 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
8391 bfd_put_32 (input_bfd
, insn
, hit_data
);
8393 return bfd_reloc_ok
;
8395 case R_ARM_LDC_PC_G0
:
8396 case R_ARM_LDC_PC_G1
:
8397 case R_ARM_LDC_PC_G2
:
8398 case R_ARM_LDC_SB_G0
:
8399 case R_ARM_LDC_SB_G1
:
8400 case R_ARM_LDC_SB_G2
:
8402 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
8403 bfd_vma pc
= input_section
->output_section
->vma
8404 + input_section
->output_offset
+ rel
->r_offset
;
8405 bfd_vma sb
= 0; /* See note above. */
8407 bfd_signed_vma signed_value
;
8410 /* Determine which groups of bits to calculate. */
8413 case R_ARM_LDC_PC_G0
:
8414 case R_ARM_LDC_SB_G0
:
8418 case R_ARM_LDC_PC_G1
:
8419 case R_ARM_LDC_SB_G1
:
8423 case R_ARM_LDC_PC_G2
:
8424 case R_ARM_LDC_SB_G2
:
8432 /* If REL, extract the addend from the insn. If RELA, it will
8433 have already been fetched for us. */
8434 if (globals
->use_rel
)
8436 int negative
= (insn
& (1 << 23)) ? 1 : -1;
8437 signed_addend
= negative
* ((insn
& 0xff) << 2);
8440 /* Compute the value (X) to go in the place. */
8441 if (r_type
== R_ARM_LDC_PC_G0
8442 || r_type
== R_ARM_LDC_PC_G1
8443 || r_type
== R_ARM_LDC_PC_G2
)
8445 signed_value
= value
- pc
+ signed_addend
;
8447 /* Section base relative. */
8448 signed_value
= value
- sb
+ signed_addend
;
8450 /* Calculate the value of the relevant G_{n-1} to obtain
8451 the residual at that stage. */
8452 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
8454 /* Check for overflow. (The absolute value to go in the place must be
8455 divisible by four and, after having been divided by four, must
8456 fit in eight bits.) */
8457 if ((residual
& 0x3) != 0 || residual
>= 0x400)
8459 (*_bfd_error_handler
)
8460 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
8461 input_bfd
, input_section
,
8462 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
8463 return bfd_reloc_overflow
;
8466 /* Mask out the value and U bit. */
8469 /* Set the U bit if the value to go in the place is non-negative. */
8470 if (signed_value
>= 0)
8473 /* Encode the offset. */
8474 insn
|= residual
>> 2;
8476 bfd_put_32 (input_bfd
, insn
, hit_data
);
8478 return bfd_reloc_ok
;
8481 return bfd_reloc_notsupported
;
8485 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
8487 arm_add_to_rel (bfd
* abfd
,
8489 reloc_howto_type
* howto
,
8490 bfd_signed_vma increment
)
8492 bfd_signed_vma addend
;
8494 if (howto
->type
== R_ARM_THM_CALL
8495 || howto
->type
== R_ARM_THM_JUMP24
)
8497 int upper_insn
, lower_insn
;
8500 upper_insn
= bfd_get_16 (abfd
, address
);
8501 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
8502 upper
= upper_insn
& 0x7ff;
8503 lower
= lower_insn
& 0x7ff;
8505 addend
= (upper
<< 12) | (lower
<< 1);
8506 addend
+= increment
;
8509 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
8510 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
8512 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
8513 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
8519 contents
= bfd_get_32 (abfd
, address
);
8521 /* Get the (signed) value from the instruction. */
8522 addend
= contents
& howto
->src_mask
;
8523 if (addend
& ((howto
->src_mask
+ 1) >> 1))
8525 bfd_signed_vma mask
;
8528 mask
&= ~ howto
->src_mask
;
8532 /* Add in the increment, (which is a byte value). */
8533 switch (howto
->type
)
8536 addend
+= increment
;
8543 addend
<<= howto
->size
;
8544 addend
+= increment
;
8546 /* Should we check for overflow here ? */
8548 /* Drop any undesired bits. */
8549 addend
>>= howto
->rightshift
;
8553 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
8555 bfd_put_32 (abfd
, contents
, address
);
8559 #define IS_ARM_TLS_RELOC(R_TYPE) \
8560 ((R_TYPE) == R_ARM_TLS_GD32 \
8561 || (R_TYPE) == R_ARM_TLS_LDO32 \
8562 || (R_TYPE) == R_ARM_TLS_LDM32 \
8563 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
8564 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
8565 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
8566 || (R_TYPE) == R_ARM_TLS_LE32 \
8567 || (R_TYPE) == R_ARM_TLS_IE32)
8569 /* Relocate an ARM ELF section. */
8572 elf32_arm_relocate_section (bfd
* output_bfd
,
8573 struct bfd_link_info
* info
,
8575 asection
* input_section
,
8576 bfd_byte
* contents
,
8577 Elf_Internal_Rela
* relocs
,
8578 Elf_Internal_Sym
* local_syms
,
8579 asection
** local_sections
)
8581 Elf_Internal_Shdr
*symtab_hdr
;
8582 struct elf_link_hash_entry
**sym_hashes
;
8583 Elf_Internal_Rela
*rel
;
8584 Elf_Internal_Rela
*relend
;
8586 struct elf32_arm_link_hash_table
* globals
;
8588 globals
= elf32_arm_hash_table (info
);
8590 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
8591 sym_hashes
= elf_sym_hashes (input_bfd
);
8594 relend
= relocs
+ input_section
->reloc_count
;
8595 for (; rel
< relend
; rel
++)
8598 reloc_howto_type
* howto
;
8599 unsigned long r_symndx
;
8600 Elf_Internal_Sym
* sym
;
8602 struct elf_link_hash_entry
* h
;
8604 bfd_reloc_status_type r
;
8607 bfd_boolean unresolved_reloc
= FALSE
;
8608 char *error_message
= NULL
;
8610 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8611 r_type
= ELF32_R_TYPE (rel
->r_info
);
8612 r_type
= arm_real_reloc_type (globals
, r_type
);
8614 if ( r_type
== R_ARM_GNU_VTENTRY
8615 || r_type
== R_ARM_GNU_VTINHERIT
)
8618 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
8619 howto
= bfd_reloc
.howto
;
8625 if (r_symndx
< symtab_hdr
->sh_info
)
8627 sym
= local_syms
+ r_symndx
;
8628 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
8629 sec
= local_sections
[r_symndx
];
8630 if (globals
->use_rel
)
8632 relocation
= (sec
->output_section
->vma
8633 + sec
->output_offset
8635 if (!info
->relocatable
8636 && (sec
->flags
& SEC_MERGE
)
8637 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8640 bfd_vma addend
, value
;
8644 case R_ARM_MOVW_ABS_NC
:
8645 case R_ARM_MOVT_ABS
:
8646 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
8647 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
8648 addend
= (addend
^ 0x8000) - 0x8000;
8651 case R_ARM_THM_MOVW_ABS_NC
:
8652 case R_ARM_THM_MOVT_ABS
:
8653 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
8655 value
|= bfd_get_16 (input_bfd
,
8656 contents
+ rel
->r_offset
+ 2);
8657 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
8658 | ((value
& 0x04000000) >> 15);
8659 addend
= (addend
^ 0x8000) - 0x8000;
8663 if (howto
->rightshift
8664 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
8666 (*_bfd_error_handler
)
8667 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
8668 input_bfd
, input_section
,
8669 (long) rel
->r_offset
, howto
->name
);
8673 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
8675 /* Get the (signed) value from the instruction. */
8676 addend
= value
& howto
->src_mask
;
8677 if (addend
& ((howto
->src_mask
+ 1) >> 1))
8679 bfd_signed_vma mask
;
8682 mask
&= ~ howto
->src_mask
;
8690 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
8692 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
8694 /* Cases here must match those in the preceeding
8695 switch statement. */
8698 case R_ARM_MOVW_ABS_NC
:
8699 case R_ARM_MOVT_ABS
:
8700 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
8702 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
8705 case R_ARM_THM_MOVW_ABS_NC
:
8706 case R_ARM_THM_MOVT_ABS
:
8707 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
8708 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
8709 bfd_put_16 (input_bfd
, value
>> 16,
8710 contents
+ rel
->r_offset
);
8711 bfd_put_16 (input_bfd
, value
,
8712 contents
+ rel
->r_offset
+ 2);
8716 value
= (value
& ~ howto
->dst_mask
)
8717 | (addend
& howto
->dst_mask
);
8718 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
8724 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8730 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
8731 r_symndx
, symtab_hdr
, sym_hashes
,
8733 unresolved_reloc
, warned
);
8738 if (sec
!= NULL
&& elf_discarded_section (sec
))
8740 /* For relocs against symbols from removed linkonce sections,
8741 or sections discarded by a linker script, we just want the
8742 section contents zeroed. Avoid any special processing. */
8743 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8749 if (info
->relocatable
)
8751 /* This is a relocatable link. We don't have to change
8752 anything, unless the reloc is against a section symbol,
8753 in which case we have to adjust according to where the
8754 section symbol winds up in the output section. */
8755 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8757 if (globals
->use_rel
)
8758 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
8759 howto
, (bfd_signed_vma
) sec
->output_offset
);
8761 rel
->r_addend
+= sec
->output_offset
;
8767 name
= h
->root
.root
.string
;
8770 name
= (bfd_elf_string_from_elf_section
8771 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
8772 if (name
== NULL
|| *name
== '\0')
8773 name
= bfd_section_name (input_bfd
, sec
);
8777 && r_type
!= R_ARM_NONE
8779 || h
->root
.type
== bfd_link_hash_defined
8780 || h
->root
.type
== bfd_link_hash_defweak
)
8781 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
8783 (*_bfd_error_handler
)
8784 ((sym_type
== STT_TLS
8785 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8786 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8789 (long) rel
->r_offset
,
8794 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
8795 input_section
, contents
, rel
,
8796 relocation
, info
, sec
, name
,
8797 (h
? ELF_ST_TYPE (h
->type
) :
8798 ELF_ST_TYPE (sym
->st_info
)), h
,
8799 &unresolved_reloc
, &error_message
);
8801 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8802 because such sections are not SEC_ALLOC and thus ld.so will
8803 not process them. */
8804 if (unresolved_reloc
8805 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8808 (*_bfd_error_handler
)
8809 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8812 (long) rel
->r_offset
,
8814 h
->root
.root
.string
);
8818 if (r
!= bfd_reloc_ok
)
8822 case bfd_reloc_overflow
:
8823 /* If the overflowing reloc was to an undefined symbol,
8824 we have already printed one error message and there
8825 is no point complaining again. */
8827 h
->root
.type
!= bfd_link_hash_undefined
)
8828 && (!((*info
->callbacks
->reloc_overflow
)
8829 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
8830 (bfd_vma
) 0, input_bfd
, input_section
,
8835 case bfd_reloc_undefined
:
8836 if (!((*info
->callbacks
->undefined_symbol
)
8837 (info
, name
, input_bfd
, input_section
,
8838 rel
->r_offset
, TRUE
)))
8842 case bfd_reloc_outofrange
:
8843 error_message
= _("out of range");
8846 case bfd_reloc_notsupported
:
8847 error_message
= _("unsupported relocation");
8850 case bfd_reloc_dangerous
:
8851 /* error_message should already be set. */
8855 error_message
= _("unknown error");
8859 BFD_ASSERT (error_message
!= NULL
);
8860 if (!((*info
->callbacks
->reloc_dangerous
)
8861 (info
, error_message
, input_bfd
, input_section
,
8872 /* Add a new unwind edit to the list described by HEAD, TAIL. If INDEX is zero,
8873 adds the edit to the start of the list. (The list must be built in order of
8874 ascending INDEX: the function's callers are primarily responsible for
8875 maintaining that condition). */
8878 add_unwind_table_edit (arm_unwind_table_edit
**head
,
8879 arm_unwind_table_edit
**tail
,
8880 arm_unwind_edit_type type
,
8881 asection
*linked_section
,
8884 arm_unwind_table_edit
*new_edit
= xmalloc (sizeof (arm_unwind_table_edit
));
8886 new_edit
->type
= type
;
8887 new_edit
->linked_section
= linked_section
;
8888 new_edit
->index
= index
;
8892 new_edit
->next
= NULL
;
8895 (*tail
)->next
= new_edit
;
8904 new_edit
->next
= *head
;
8913 static _arm_elf_section_data
*get_arm_elf_section_data (asection
*);
8915 /* Increase the size of EXIDX_SEC by ADJUST bytes. ADJUST mau be negative. */
8917 adjust_exidx_size(asection
*exidx_sec
, int adjust
)
8921 if (!exidx_sec
->rawsize
)
8922 exidx_sec
->rawsize
= exidx_sec
->size
;
8924 bfd_set_section_size (exidx_sec
->owner
, exidx_sec
, exidx_sec
->size
+ adjust
);
8925 out_sec
= exidx_sec
->output_section
;
8926 /* Adjust size of output section. */
8927 bfd_set_section_size (out_sec
->owner
, out_sec
, out_sec
->size
+adjust
);
8930 /* Insert an EXIDX_CANTUNWIND marker at the end of a section. */
8932 insert_cantunwind_after(asection
*text_sec
, asection
*exidx_sec
)
8934 struct _arm_elf_section_data
*exidx_arm_data
;
8936 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
8937 add_unwind_table_edit (
8938 &exidx_arm_data
->u
.exidx
.unwind_edit_list
,
8939 &exidx_arm_data
->u
.exidx
.unwind_edit_tail
,
8940 INSERT_EXIDX_CANTUNWIND_AT_END
, text_sec
, UINT_MAX
);
8942 adjust_exidx_size(exidx_sec
, 8);
8945 /* Scan .ARM.exidx tables, and create a list describing edits which should be
8946 made to those tables, such that:
8948 1. Regions without unwind data are marked with EXIDX_CANTUNWIND entries.
8949 2. Duplicate entries are merged together (EXIDX_CANTUNWIND, or unwind
8950 codes which have been inlined into the index).
8952 The edits are applied when the tables are written
8953 (in elf32_arm_write_section).
8957 elf32_arm_fix_exidx_coverage (asection
**text_section_order
,
8958 unsigned int num_text_sections
,
8959 struct bfd_link_info
*info
)
8962 unsigned int last_second_word
= 0, i
;
8963 asection
*last_exidx_sec
= NULL
;
8964 asection
*last_text_sec
= NULL
;
8965 int last_unwind_type
= -1;
8967 /* Walk over all EXIDX sections, and create backlinks from the corrsponding
8969 for (inp
= info
->input_bfds
; inp
!= NULL
; inp
= inp
->link_next
)
8973 for (sec
= inp
->sections
; sec
!= NULL
; sec
= sec
->next
)
8975 struct bfd_elf_section_data
*elf_sec
= elf_section_data (sec
);
8976 Elf_Internal_Shdr
*hdr
= &elf_sec
->this_hdr
;
8978 if (!hdr
|| hdr
->sh_type
!= SHT_ARM_EXIDX
)
8981 if (elf_sec
->linked_to
)
8983 Elf_Internal_Shdr
*linked_hdr
8984 = &elf_section_data (elf_sec
->linked_to
)->this_hdr
;
8985 struct _arm_elf_section_data
*linked_sec_arm_data
8986 = get_arm_elf_section_data (linked_hdr
->bfd_section
);
8988 if (linked_sec_arm_data
== NULL
)
8991 /* Link this .ARM.exidx section back from the text section it
8993 linked_sec_arm_data
->u
.text
.arm_exidx_sec
= sec
;
8998 /* Walk all text sections in order of increasing VMA. Eilminate duplicate
8999 index table entries (EXIDX_CANTUNWIND and inlined unwind opcodes),
9000 and add EXIDX_CANTUNWIND entries for sections with no unwind table data.
9003 for (i
= 0; i
< num_text_sections
; i
++)
9005 asection
*sec
= text_section_order
[i
];
9006 asection
*exidx_sec
;
9007 struct _arm_elf_section_data
*arm_data
= get_arm_elf_section_data (sec
);
9008 struct _arm_elf_section_data
*exidx_arm_data
;
9009 bfd_byte
*contents
= NULL
;
9010 int deleted_exidx_bytes
= 0;
9012 arm_unwind_table_edit
*unwind_edit_head
= NULL
;
9013 arm_unwind_table_edit
*unwind_edit_tail
= NULL
;
9014 Elf_Internal_Shdr
*hdr
;
9017 if (arm_data
== NULL
)
9020 exidx_sec
= arm_data
->u
.text
.arm_exidx_sec
;
9021 if (exidx_sec
== NULL
)
9023 /* Section has no unwind data. */
9024 if (last_unwind_type
== 0 || !last_exidx_sec
)
9027 /* Ignore zero sized sections. */
9031 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
9032 last_unwind_type
= 0;
9036 /* Skip /DISCARD/ sections. */
9037 if (bfd_is_abs_section (exidx_sec
->output_section
))
9040 hdr
= &elf_section_data (exidx_sec
)->this_hdr
;
9041 if (hdr
->sh_type
!= SHT_ARM_EXIDX
)
9044 exidx_arm_data
= get_arm_elf_section_data (exidx_sec
);
9045 if (exidx_arm_data
== NULL
)
9048 ibfd
= exidx_sec
->owner
;
9050 if (hdr
->contents
!= NULL
)
9051 contents
= hdr
->contents
;
9052 else if (! bfd_malloc_and_get_section (ibfd
, exidx_sec
, &contents
))
9056 for (j
= 0; j
< hdr
->sh_size
; j
+= 8)
9058 unsigned int second_word
= bfd_get_32 (ibfd
, contents
+ j
+ 4);
9062 /* An EXIDX_CANTUNWIND entry. */
9063 if (second_word
== 1)
9065 if (last_unwind_type
== 0)
9069 /* Inlined unwinding data. Merge if equal to previous. */
9070 else if ((second_word
& 0x80000000) != 0)
9072 if (last_second_word
== second_word
&& last_unwind_type
== 1)
9075 last_second_word
= second_word
;
9077 /* Normal table entry. In theory we could merge these too,
9078 but duplicate entries are likely to be much less common. */
9084 add_unwind_table_edit (&unwind_edit_head
, &unwind_edit_tail
,
9085 DELETE_EXIDX_ENTRY
, NULL
, j
/ 8);
9087 deleted_exidx_bytes
+= 8;
9090 last_unwind_type
= unwind_type
;
9093 /* Free contents if we allocated it ourselves. */
9094 if (contents
!= hdr
->contents
)
9097 /* Record edits to be applied later (in elf32_arm_write_section). */
9098 exidx_arm_data
->u
.exidx
.unwind_edit_list
= unwind_edit_head
;
9099 exidx_arm_data
->u
.exidx
.unwind_edit_tail
= unwind_edit_tail
;
9101 if (deleted_exidx_bytes
> 0)
9102 adjust_exidx_size(exidx_sec
, -deleted_exidx_bytes
);
9104 last_exidx_sec
= exidx_sec
;
9105 last_text_sec
= sec
;
9108 /* Add terminating CANTUNWIND entry. */
9109 if (last_exidx_sec
&& last_unwind_type
!= 0)
9110 insert_cantunwind_after(last_text_sec
, last_exidx_sec
);
9116 elf32_arm_output_glue_section (struct bfd_link_info
*info
, bfd
*obfd
,
9117 bfd
*ibfd
, const char *name
)
9119 asection
*sec
, *osec
;
9121 sec
= bfd_get_section_by_name (ibfd
, name
);
9122 if (sec
== NULL
|| (sec
->flags
& SEC_EXCLUDE
) != 0)
9125 osec
= sec
->output_section
;
9126 if (elf32_arm_write_section (obfd
, info
, sec
, sec
->contents
))
9129 if (! bfd_set_section_contents (obfd
, osec
, sec
->contents
,
9130 sec
->output_offset
, sec
->size
))
9137 elf32_arm_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
9139 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (info
);
9141 /* Invoke the regular ELF backend linker to do all the work. */
9142 if (!bfd_elf_final_link (abfd
, info
))
9145 /* Write out any glue sections now that we have created all the
9147 if (globals
->bfd_of_glue_owner
!= NULL
)
9149 if (! elf32_arm_output_glue_section (info
, abfd
,
9150 globals
->bfd_of_glue_owner
,
9151 ARM2THUMB_GLUE_SECTION_NAME
))
9154 if (! elf32_arm_output_glue_section (info
, abfd
,
9155 globals
->bfd_of_glue_owner
,
9156 THUMB2ARM_GLUE_SECTION_NAME
))
9159 if (! elf32_arm_output_glue_section (info
, abfd
,
9160 globals
->bfd_of_glue_owner
,
9161 VFP11_ERRATUM_VENEER_SECTION_NAME
))
9164 if (! elf32_arm_output_glue_section (info
, abfd
,
9165 globals
->bfd_of_glue_owner
,
9166 ARM_BX_GLUE_SECTION_NAME
))
9173 /* Set the right machine number. */
9176 elf32_arm_object_p (bfd
*abfd
)
9180 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
9182 if (mach
!= bfd_mach_arm_unknown
)
9183 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
9185 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
9186 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
9189 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
9194 /* Function to keep ARM specific flags in the ELF header. */
9197 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
9199 if (elf_flags_init (abfd
)
9200 && elf_elfheader (abfd
)->e_flags
!= flags
)
9202 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
9204 if (flags
& EF_ARM_INTERWORK
)
9205 (*_bfd_error_handler
)
9206 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
9210 (_("Warning: Clearing the interworking flag of %B due to outside request"),
9216 elf_elfheader (abfd
)->e_flags
= flags
;
9217 elf_flags_init (abfd
) = TRUE
;
9223 /* Copy backend specific data from one object module to another. */
9226 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
9231 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
9234 in_flags
= elf_elfheader (ibfd
)->e_flags
;
9235 out_flags
= elf_elfheader (obfd
)->e_flags
;
9237 if (elf_flags_init (obfd
)
9238 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
9239 && in_flags
!= out_flags
)
9241 /* Cannot mix APCS26 and APCS32 code. */
9242 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
9245 /* Cannot mix float APCS and non-float APCS code. */
9246 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
9249 /* If the src and dest have different interworking flags
9250 then turn off the interworking bit. */
9251 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
9253 if (out_flags
& EF_ARM_INTERWORK
)
9255 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
9258 in_flags
&= ~EF_ARM_INTERWORK
;
9261 /* Likewise for PIC, though don't warn for this case. */
9262 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
9263 in_flags
&= ~EF_ARM_PIC
;
9266 elf_elfheader (obfd
)->e_flags
= in_flags
;
9267 elf_flags_init (obfd
) = TRUE
;
9269 /* Also copy the EI_OSABI field. */
9270 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
9271 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
9273 /* Copy object attributes. */
9274 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
9279 /* Values for Tag_ABI_PCS_R9_use. */
9288 /* Values for Tag_ABI_PCS_RW_data. */
9291 AEABI_PCS_RW_data_absolute
,
9292 AEABI_PCS_RW_data_PCrel
,
9293 AEABI_PCS_RW_data_SBrel
,
9294 AEABI_PCS_RW_data_unused
9297 /* Values for Tag_ABI_enum_size. */
9303 AEABI_enum_forced_wide
9306 /* Determine whether an object attribute tag takes an integer, a
9310 elf32_arm_obj_attrs_arg_type (int tag
)
9312 if (tag
== Tag_compatibility
)
9313 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_STR_VAL
;
9314 else if (tag
== Tag_nodefaults
)
9315 return ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_NO_DEFAULT
;
9316 else if (tag
== Tag_CPU_raw_name
|| tag
== Tag_CPU_name
)
9317 return ATTR_TYPE_FLAG_STR_VAL
;
9319 return ATTR_TYPE_FLAG_INT_VAL
;
9321 return (tag
& 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL
: ATTR_TYPE_FLAG_INT_VAL
;
9324 /* The ABI defines that Tag_conformance should be emitted first, and that
9325 Tag_nodefaults should be second (if either is defined). This sets those
9326 two positions, and bumps up the position of all the remaining tags to
9329 elf32_arm_obj_attrs_order (int num
)
9332 return Tag_conformance
;
9334 return Tag_nodefaults
;
9335 if ((num
- 2) < Tag_nodefaults
)
9337 if ((num
- 1) < Tag_conformance
)
9342 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
9343 Returns -1 if no architecture could be read. */
9346 get_secondary_compatible_arch (bfd
*abfd
)
9348 obj_attribute
*attr
=
9349 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
9351 /* Note: the tag and its argument below are uleb128 values, though
9352 currently-defined values fit in one byte for each. */
9354 && attr
->s
[0] == Tag_CPU_arch
9355 && (attr
->s
[1] & 128) != 128
9359 /* This tag is "safely ignorable", so don't complain if it looks funny. */
9363 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
9364 The tag is removed if ARCH is -1. */
9367 set_secondary_compatible_arch (bfd
*abfd
, int arch
)
9369 obj_attribute
*attr
=
9370 &elf_known_obj_attributes_proc (abfd
)[Tag_also_compatible_with
];
9378 /* Note: the tag and its argument below are uleb128 values, though
9379 currently-defined values fit in one byte for each. */
9381 attr
->s
= bfd_alloc (abfd
, 3);
9382 attr
->s
[0] = Tag_CPU_arch
;
9387 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
9391 tag_cpu_arch_combine (bfd
*ibfd
, int oldtag
, int *secondary_compat_out
,
9392 int newtag
, int secondary_compat
)
9394 #define T(X) TAG_CPU_ARCH_##X
9395 int tagl
, tagh
, result
;
9398 T(V6T2
), /* PRE_V4. */
9402 T(V6T2
), /* V5TE. */
9403 T(V6T2
), /* V5TEJ. */
9410 T(V6K
), /* PRE_V4. */
9415 T(V6K
), /* V5TEJ. */
9417 T(V6KZ
), /* V6KZ. */
9423 T(V7
), /* PRE_V4. */
9442 T(V6K
), /* V5TEJ. */
9444 T(V6KZ
), /* V6KZ. */
9457 T(V6K
), /* V5TEJ. */
9459 T(V6KZ
), /* V6KZ. */
9463 T(V6S_M
), /* V6_M. */
9464 T(V6S_M
) /* V6S_M. */
9466 const int v4t_plus_v6_m
[] =
9472 T(V5TE
), /* V5TE. */
9473 T(V5TEJ
), /* V5TEJ. */
9475 T(V6KZ
), /* V6KZ. */
9476 T(V6T2
), /* V6T2. */
9479 T(V6_M
), /* V6_M. */
9480 T(V6S_M
), /* V6S_M. */
9481 T(V4T_PLUS_V6_M
) /* V4T plus V6_M. */
9490 /* Pseudo-architecture. */
9494 /* Check we've not got a higher architecture than we know about. */
9496 if (oldtag
>= MAX_TAG_CPU_ARCH
|| newtag
>= MAX_TAG_CPU_ARCH
)
9498 _bfd_error_handler (_("error: %B: Unknown CPU architecture"), ibfd
);
9502 /* Override old tag if we have a Tag_also_compatible_with on the output. */
9504 if ((oldtag
== T(V6_M
) && *secondary_compat_out
== T(V4T
))
9505 || (oldtag
== T(V4T
) && *secondary_compat_out
== T(V6_M
)))
9506 oldtag
= T(V4T_PLUS_V6_M
);
9508 /* And override the new tag if we have a Tag_also_compatible_with on the
9511 if ((newtag
== T(V6_M
) && secondary_compat
== T(V4T
))
9512 || (newtag
== T(V4T
) && secondary_compat
== T(V6_M
)))
9513 newtag
= T(V4T_PLUS_V6_M
);
9515 tagl
= (oldtag
< newtag
) ? oldtag
: newtag
;
9516 result
= tagh
= (oldtag
> newtag
) ? oldtag
: newtag
;
9518 /* Architectures before V6KZ add features monotonically. */
9519 if (tagh
<= TAG_CPU_ARCH_V6KZ
)
9522 result
= comb
[tagh
- T(V6T2
)][tagl
];
9524 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
9525 as the canonical version. */
9526 if (result
== T(V4T_PLUS_V6_M
))
9529 *secondary_compat_out
= T(V6_M
);
9532 *secondary_compat_out
= -1;
9536 _bfd_error_handler (_("error: %B: Conflicting CPU architectures %d/%d"),
9537 ibfd
, oldtag
, newtag
);
9545 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
9546 are conflicting attributes. */
9549 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
9551 obj_attribute
*in_attr
;
9552 obj_attribute
*out_attr
;
9553 obj_attribute_list
*in_list
;
9554 obj_attribute_list
*out_list
;
9555 obj_attribute_list
**out_listp
;
9556 /* Some tags have 0 = don't care, 1 = strong requirement,
9557 2 = weak requirement. */
9558 static const int order_021
[3] = {0, 2, 1};
9559 /* For use with Tag_VFP_arch. */
9560 static const int order_01243
[5] = {0, 1, 2, 4, 3};
9562 bfd_boolean result
= TRUE
;
9564 /* Skip the linker stubs file. This preserves previous behavior
9565 of accepting unknown attributes in the first input file - but
9567 if (ibfd
->flags
& BFD_LINKER_CREATED
)
9570 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
9572 /* This is the first object. Copy the attributes. */
9573 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
9575 /* Use the Tag_null value to indicate the attributes have been
9577 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
9582 in_attr
= elf_known_obj_attributes_proc (ibfd
);
9583 out_attr
= elf_known_obj_attributes_proc (obfd
);
9584 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
9585 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
9587 /* Ignore mismatches if the object doesn't use floating point. */
9588 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
9589 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
9590 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
9593 (_("error: %B uses VFP register arguments, %B does not"),
9599 for (i
= 4; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
9601 /* Merge this attribute with existing attributes. */
9604 case Tag_CPU_raw_name
:
9606 /* These are merged after Tag_CPU_arch. */
9609 case Tag_ABI_optimization_goals
:
9610 case Tag_ABI_FP_optimization_goals
:
9611 /* Use the first value seen. */
9616 int secondary_compat
= -1, secondary_compat_out
= -1;
9617 unsigned int saved_out_attr
= out_attr
[i
].i
;
9618 static const char *name_table
[] = {
9619 /* These aren't real CPU names, but we can't guess
9620 that from the architecture version alone. */
9636 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
9637 secondary_compat
= get_secondary_compatible_arch (ibfd
);
9638 secondary_compat_out
= get_secondary_compatible_arch (obfd
);
9639 out_attr
[i
].i
= tag_cpu_arch_combine (ibfd
, out_attr
[i
].i
,
9640 &secondary_compat_out
,
9643 set_secondary_compatible_arch (obfd
, secondary_compat_out
);
9645 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
9646 if (out_attr
[i
].i
== saved_out_attr
)
9647 ; /* Leave the names alone. */
9648 else if (out_attr
[i
].i
== in_attr
[i
].i
)
9650 /* The output architecture has been changed to match the
9651 input architecture. Use the input names. */
9652 out_attr
[Tag_CPU_name
].s
= in_attr
[Tag_CPU_name
].s
9653 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_name
].s
)
9655 out_attr
[Tag_CPU_raw_name
].s
= in_attr
[Tag_CPU_raw_name
].s
9656 ? _bfd_elf_attr_strdup (obfd
, in_attr
[Tag_CPU_raw_name
].s
)
9661 out_attr
[Tag_CPU_name
].s
= NULL
;
9662 out_attr
[Tag_CPU_raw_name
].s
= NULL
;
9665 /* If we still don't have a value for Tag_CPU_name,
9666 make one up now. Tag_CPU_raw_name remains blank. */
9667 if (out_attr
[Tag_CPU_name
].s
== NULL
9668 && out_attr
[i
].i
< ARRAY_SIZE (name_table
))
9669 out_attr
[Tag_CPU_name
].s
=
9670 _bfd_elf_attr_strdup (obfd
, name_table
[out_attr
[i
].i
]);
9674 case Tag_ARM_ISA_use
:
9675 case Tag_THUMB_ISA_use
:
9677 case Tag_Advanced_SIMD_arch
:
9678 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
9679 case Tag_ABI_FP_rounding
:
9680 case Tag_ABI_FP_exceptions
:
9681 case Tag_ABI_FP_user_exceptions
:
9682 case Tag_ABI_FP_number_model
:
9683 case Tag_VFP_HP_extension
:
9684 case Tag_CPU_unaligned_access
:
9686 case Tag_Virtualization_use
:
9687 case Tag_MPextension_use
:
9688 /* Use the largest value specified. */
9689 if (in_attr
[i
].i
> out_attr
[i
].i
)
9690 out_attr
[i
].i
= in_attr
[i
].i
;
9693 case Tag_ABI_align8_preserved
:
9694 case Tag_ABI_PCS_RO_data
:
9695 /* Use the smallest value specified. */
9696 if (in_attr
[i
].i
< out_attr
[i
].i
)
9697 out_attr
[i
].i
= in_attr
[i
].i
;
9700 case Tag_ABI_align8_needed
:
9701 if ((in_attr
[i
].i
> 0 || out_attr
[i
].i
> 0)
9702 && (in_attr
[Tag_ABI_align8_preserved
].i
== 0
9703 || out_attr
[Tag_ABI_align8_preserved
].i
== 0))
9705 /* This error message should be enabled once all non-conformant
9706 binaries in the toolchain have had the attributes set
9709 (_("error: %B: 8-byte data alignment conflicts with %B"),
9714 case Tag_ABI_FP_denormal
:
9715 case Tag_ABI_PCS_GOT_use
:
9716 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
9717 value if greater than 2 (for future-proofing). */
9718 if ((in_attr
[i
].i
> 2 && in_attr
[i
].i
> out_attr
[i
].i
)
9719 || (in_attr
[i
].i
<= 2 && out_attr
[i
].i
<= 2
9720 && order_021
[in_attr
[i
].i
] > order_021
[out_attr
[i
].i
]))
9721 out_attr
[i
].i
= in_attr
[i
].i
;
9725 case Tag_CPU_arch_profile
:
9726 if (out_attr
[i
].i
!= in_attr
[i
].i
)
9728 /* 0 will merge with anything.
9729 'A' and 'S' merge to 'A'.
9730 'R' and 'S' merge to 'R'.
9731 'M' and 'A|R|S' is an error. */
9732 if (out_attr
[i
].i
== 0
9733 || (out_attr
[i
].i
== 'S'
9734 && (in_attr
[i
].i
== 'A' || in_attr
[i
].i
== 'R')))
9735 out_attr
[i
].i
= in_attr
[i
].i
;
9736 else if (in_attr
[i
].i
== 0
9737 || (in_attr
[i
].i
== 'S'
9738 && (out_attr
[i
].i
== 'A' || out_attr
[i
].i
== 'R')))
9743 (_("error: %B: Conflicting architecture profiles %c/%c"),
9745 in_attr
[i
].i
? in_attr
[i
].i
: '0',
9746 out_attr
[i
].i
? out_attr
[i
].i
: '0');
9752 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
9753 largest value if greater than 4 (for future-proofing). */
9754 if ((in_attr
[i
].i
> 4 && in_attr
[i
].i
> out_attr
[i
].i
)
9755 || (in_attr
[i
].i
<= 4 && out_attr
[i
].i
<= 4
9756 && order_01243
[in_attr
[i
].i
] > order_01243
[out_attr
[i
].i
]))
9757 out_attr
[i
].i
= in_attr
[i
].i
;
9759 case Tag_PCS_config
:
9760 if (out_attr
[i
].i
== 0)
9761 out_attr
[i
].i
= in_attr
[i
].i
;
9762 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
9764 /* It's sometimes ok to mix different configs, so this is only
9767 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
9770 case Tag_ABI_PCS_R9_use
:
9771 if (in_attr
[i
].i
!= out_attr
[i
].i
9772 && out_attr
[i
].i
!= AEABI_R9_unused
9773 && in_attr
[i
].i
!= AEABI_R9_unused
)
9776 (_("error: %B: Conflicting use of R9"), ibfd
);
9779 if (out_attr
[i
].i
== AEABI_R9_unused
)
9780 out_attr
[i
].i
= in_attr
[i
].i
;
9782 case Tag_ABI_PCS_RW_data
:
9783 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
9784 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
9785 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
9788 (_("error: %B: SB relative addressing conflicts with use of R9"),
9792 /* Use the smallest value specified. */
9793 if (in_attr
[i
].i
< out_attr
[i
].i
)
9794 out_attr
[i
].i
= in_attr
[i
].i
;
9796 case Tag_ABI_PCS_wchar_t
:
9797 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
9798 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
9801 (_("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"),
9802 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
9804 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
9805 out_attr
[i
].i
= in_attr
[i
].i
;
9807 case Tag_ABI_enum_size
:
9808 if (in_attr
[i
].i
!= AEABI_enum_unused
)
9810 if (out_attr
[i
].i
== AEABI_enum_unused
9811 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
9813 /* The existing object is compatible with anything.
9814 Use whatever requirements the new object has. */
9815 out_attr
[i
].i
= in_attr
[i
].i
;
9817 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
9818 && out_attr
[i
].i
!= in_attr
[i
].i
9819 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
9821 static const char *aeabi_enum_names
[] =
9822 { "", "variable-size", "32-bit", "" };
9823 const char *in_name
=
9824 in_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
9825 ? aeabi_enum_names
[in_attr
[i
].i
]
9827 const char *out_name
=
9828 out_attr
[i
].i
< ARRAY_SIZE(aeabi_enum_names
)
9829 ? aeabi_enum_names
[out_attr
[i
].i
]
9832 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
9833 ibfd
, in_name
, out_name
);
9837 case Tag_ABI_VFP_args
:
9840 case Tag_ABI_WMMX_args
:
9841 if (in_attr
[i
].i
!= out_attr
[i
].i
)
9844 (_("error: %B uses iWMMXt register arguments, %B does not"),
9849 case Tag_compatibility
:
9850 /* Merged in target-independent code. */
9852 case Tag_ABI_HardFP_use
:
9853 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
9854 if ((in_attr
[i
].i
== 1 && out_attr
[i
].i
== 2)
9855 || (in_attr
[i
].i
== 2 && out_attr
[i
].i
== 1))
9857 else if (in_attr
[i
].i
> out_attr
[i
].i
)
9858 out_attr
[i
].i
= in_attr
[i
].i
;
9860 case Tag_ABI_FP_16bit_format
:
9861 if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
9863 if (in_attr
[i
].i
!= out_attr
[i
].i
)
9866 (_("error: fp16 format mismatch between %B and %B"),
9871 if (in_attr
[i
].i
!= 0)
9872 out_attr
[i
].i
= in_attr
[i
].i
;
9875 case Tag_nodefaults
:
9876 /* This tag is set if it exists, but the value is unused (and is
9877 typically zero). We don't actually need to do anything here -
9878 the merge happens automatically when the type flags are merged
9881 case Tag_also_compatible_with
:
9882 /* Already done in Tag_CPU_arch. */
9884 case Tag_conformance
:
9885 /* Keep the attribute if it matches. Throw it away otherwise.
9886 No attribute means no claim to conform. */
9887 if (!in_attr
[i
].s
|| !out_attr
[i
].s
9888 || strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0)
9889 out_attr
[i
].s
= NULL
;
9894 bfd
*err_bfd
= NULL
;
9896 /* The "known_obj_attributes" table does contain some undefined
9897 attributes. Ensure that there are unused. */
9898 if (out_attr
[i
].i
!= 0 || out_attr
[i
].s
!= NULL
)
9900 else if (in_attr
[i
].i
!= 0 || in_attr
[i
].s
!= NULL
)
9903 if (err_bfd
!= NULL
)
9905 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9909 (_("%B: Unknown mandatory EABI object attribute %d"),
9911 bfd_set_error (bfd_error_bad_value
);
9917 (_("Warning: %B: Unknown EABI object attribute %d"),
9922 /* Only pass on attributes that match in both inputs. */
9923 if (in_attr
[i
].i
!= out_attr
[i
].i
9924 || in_attr
[i
].s
!= out_attr
[i
].s
9925 || (in_attr
[i
].s
!= NULL
&& out_attr
[i
].s
!= NULL
9926 && strcmp (in_attr
[i
].s
, out_attr
[i
].s
) != 0))
9929 out_attr
[i
].s
= NULL
;
9934 /* If out_attr was copied from in_attr then it won't have a type yet. */
9935 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
9936 out_attr
[i
].type
= in_attr
[i
].type
;
9939 /* Merge Tag_compatibility attributes and any common GNU ones. */
9940 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
9942 /* Check for any attributes not known on ARM. */
9943 in_list
= elf_other_obj_attributes_proc (ibfd
);
9944 out_listp
= &elf_other_obj_attributes_proc (obfd
);
9945 out_list
= *out_listp
;
9947 for (; in_list
|| out_list
; )
9949 bfd
*err_bfd
= NULL
;
9952 /* The tags for each list are in numerical order. */
9953 /* If the tags are equal, then merge. */
9954 if (out_list
&& (!in_list
|| in_list
->tag
> out_list
->tag
))
9956 /* This attribute only exists in obfd. We can't merge, and we don't
9957 know what the tag means, so delete it. */
9959 err_tag
= out_list
->tag
;
9960 *out_listp
= out_list
->next
;
9961 out_list
= *out_listp
;
9963 else if (in_list
&& (!out_list
|| in_list
->tag
< out_list
->tag
))
9965 /* This attribute only exists in ibfd. We can't merge, and we don't
9966 know what the tag means, so ignore it. */
9968 err_tag
= in_list
->tag
;
9969 in_list
= in_list
->next
;
9971 else /* The tags are equal. */
9973 /* As present, all attributes in the list are unknown, and
9974 therefore can't be merged meaningfully. */
9976 err_tag
= out_list
->tag
;
9978 /* Only pass on attributes that match in both inputs. */
9979 if (in_list
->attr
.i
!= out_list
->attr
.i
9980 || in_list
->attr
.s
!= out_list
->attr
.s
9981 || (in_list
->attr
.s
&& out_list
->attr
.s
9982 && strcmp (in_list
->attr
.s
, out_list
->attr
.s
) != 0))
9984 /* No match. Delete the attribute. */
9985 *out_listp
= out_list
->next
;
9986 out_list
= *out_listp
;
9990 /* Matched. Keep the attribute and move to the next. */
9991 out_list
= out_list
->next
;
9992 in_list
= in_list
->next
;
9998 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
9999 if ((err_tag
& 127) < 64)
10002 (_("%B: Unknown mandatory EABI object attribute %d"),
10004 bfd_set_error (bfd_error_bad_value
);
10010 (_("Warning: %B: Unknown EABI object attribute %d"),
10019 /* Return TRUE if the two EABI versions are incompatible. */
10022 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
10024 /* v4 and v5 are the same spec before and after it was released,
10025 so allow mixing them. */
10026 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
10027 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
10030 return (iver
== over
);
10033 /* Merge backend specific data from an object file to the output
10034 object file when linking. */
10037 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
10039 flagword out_flags
;
10041 bfd_boolean flags_compatible
= TRUE
;
10044 /* Check if we have the same endianess. */
10045 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
10048 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
10051 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
10054 /* The input BFD must have had its flags initialised. */
10055 /* The following seems bogus to me -- The flags are initialized in
10056 the assembler but I don't think an elf_flags_init field is
10057 written into the object. */
10058 /* BFD_ASSERT (elf_flags_init (ibfd)); */
10060 in_flags
= elf_elfheader (ibfd
)->e_flags
;
10061 out_flags
= elf_elfheader (obfd
)->e_flags
;
10063 /* In theory there is no reason why we couldn't handle this. However
10064 in practice it isn't even close to working and there is no real
10065 reason to want it. */
10066 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
10067 && !(ibfd
->flags
& DYNAMIC
)
10068 && (in_flags
& EF_ARM_BE8
))
10070 _bfd_error_handler (_("error: %B is already in final BE8 format"),
10075 if (!elf_flags_init (obfd
))
10077 /* If the input is the default architecture and had the default
10078 flags then do not bother setting the flags for the output
10079 architecture, instead allow future merges to do this. If no
10080 future merges ever set these flags then they will retain their
10081 uninitialised values, which surprise surprise, correspond
10082 to the default values. */
10083 if (bfd_get_arch_info (ibfd
)->the_default
10084 && elf_elfheader (ibfd
)->e_flags
== 0)
10087 elf_flags_init (obfd
) = TRUE
;
10088 elf_elfheader (obfd
)->e_flags
= in_flags
;
10090 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
10091 && bfd_get_arch_info (obfd
)->the_default
)
10092 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
10097 /* Determine what should happen if the input ARM architecture
10098 does not match the output ARM architecture. */
10099 if (! bfd_arm_merge_machines (ibfd
, obfd
))
10102 /* Identical flags must be compatible. */
10103 if (in_flags
== out_flags
)
10106 /* Check to see if the input BFD actually contains any sections. If
10107 not, its flags may not have been initialised either, but it
10108 cannot actually cause any incompatiblity. Do not short-circuit
10109 dynamic objects; their section list may be emptied by
10110 elf_link_add_object_symbols.
10112 Also check to see if there are no code sections in the input.
10113 In this case there is no need to check for code specific flags.
10114 XXX - do we need to worry about floating-point format compatability
10115 in data sections ? */
10116 if (!(ibfd
->flags
& DYNAMIC
))
10118 bfd_boolean null_input_bfd
= TRUE
;
10119 bfd_boolean only_data_sections
= TRUE
;
10121 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
10123 /* Ignore synthetic glue sections. */
10124 if (strcmp (sec
->name
, ".glue_7")
10125 && strcmp (sec
->name
, ".glue_7t"))
10127 if ((bfd_get_section_flags (ibfd
, sec
)
10128 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
10129 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
10130 only_data_sections
= FALSE
;
10132 null_input_bfd
= FALSE
;
10137 if (null_input_bfd
|| only_data_sections
)
10141 /* Complain about various flag mismatches. */
10142 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
10143 EF_ARM_EABI_VERSION (out_flags
)))
10146 (_("error: Source object %B has EABI version %d, but target %B has EABI version %d"),
10148 (in_flags
& EF_ARM_EABIMASK
) >> 24,
10149 (out_flags
& EF_ARM_EABIMASK
) >> 24);
10153 /* Not sure what needs to be checked for EABI versions >= 1. */
10154 /* VxWorks libraries do not use these flags. */
10155 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
10156 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
10157 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
10159 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
10162 (_("error: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
10164 in_flags
& EF_ARM_APCS_26
? 26 : 32,
10165 out_flags
& EF_ARM_APCS_26
? 26 : 32);
10166 flags_compatible
= FALSE
;
10169 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
10171 if (in_flags
& EF_ARM_APCS_FLOAT
)
10173 (_("error: %B passes floats in float registers, whereas %B passes them in integer registers"),
10177 (_("error: %B passes floats in integer registers, whereas %B passes them in float registers"),
10180 flags_compatible
= FALSE
;
10183 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
10185 if (in_flags
& EF_ARM_VFP_FLOAT
)
10187 (_("error: %B uses VFP instructions, whereas %B does not"),
10191 (_("error: %B uses FPA instructions, whereas %B does not"),
10194 flags_compatible
= FALSE
;
10197 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
10199 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
10201 (_("error: %B uses Maverick instructions, whereas %B does not"),
10205 (_("error: %B does not use Maverick instructions, whereas %B does"),
10208 flags_compatible
= FALSE
;
10211 #ifdef EF_ARM_SOFT_FLOAT
10212 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
10214 /* We can allow interworking between code that is VFP format
10215 layout, and uses either soft float or integer regs for
10216 passing floating point arguments and results. We already
10217 know that the APCS_FLOAT flags match; similarly for VFP
10219 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
10220 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
10222 if (in_flags
& EF_ARM_SOFT_FLOAT
)
10224 (_("error: %B uses software FP, whereas %B uses hardware FP"),
10228 (_("error: %B uses hardware FP, whereas %B uses software FP"),
10231 flags_compatible
= FALSE
;
10236 /* Interworking mismatch is only a warning. */
10237 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
10239 if (in_flags
& EF_ARM_INTERWORK
)
10242 (_("Warning: %B supports interworking, whereas %B does not"),
10248 (_("Warning: %B does not support interworking, whereas %B does"),
10254 return flags_compatible
;
10257 /* Display the flags field. */
10260 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
10262 FILE * file
= (FILE *) ptr
;
10263 unsigned long flags
;
10265 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
10267 /* Print normal ELF private data. */
10268 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
10270 flags
= elf_elfheader (abfd
)->e_flags
;
10271 /* Ignore init flag - it may not be set, despite the flags field
10272 containing valid data. */
10274 /* xgettext:c-format */
10275 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
10277 switch (EF_ARM_EABI_VERSION (flags
))
10279 case EF_ARM_EABI_UNKNOWN
:
10280 /* The following flag bits are GNU extensions and not part of the
10281 official ARM ELF extended ABI. Hence they are only decoded if
10282 the EABI version is not set. */
10283 if (flags
& EF_ARM_INTERWORK
)
10284 fprintf (file
, _(" [interworking enabled]"));
10286 if (flags
& EF_ARM_APCS_26
)
10287 fprintf (file
, " [APCS-26]");
10289 fprintf (file
, " [APCS-32]");
10291 if (flags
& EF_ARM_VFP_FLOAT
)
10292 fprintf (file
, _(" [VFP float format]"));
10293 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
10294 fprintf (file
, _(" [Maverick float format]"));
10296 fprintf (file
, _(" [FPA float format]"));
10298 if (flags
& EF_ARM_APCS_FLOAT
)
10299 fprintf (file
, _(" [floats passed in float registers]"));
10301 if (flags
& EF_ARM_PIC
)
10302 fprintf (file
, _(" [position independent]"));
10304 if (flags
& EF_ARM_NEW_ABI
)
10305 fprintf (file
, _(" [new ABI]"));
10307 if (flags
& EF_ARM_OLD_ABI
)
10308 fprintf (file
, _(" [old ABI]"));
10310 if (flags
& EF_ARM_SOFT_FLOAT
)
10311 fprintf (file
, _(" [software FP]"));
10313 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
10314 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
10315 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
10316 | EF_ARM_MAVERICK_FLOAT
);
10319 case EF_ARM_EABI_VER1
:
10320 fprintf (file
, _(" [Version1 EABI]"));
10322 if (flags
& EF_ARM_SYMSARESORTED
)
10323 fprintf (file
, _(" [sorted symbol table]"));
10325 fprintf (file
, _(" [unsorted symbol table]"));
10327 flags
&= ~ EF_ARM_SYMSARESORTED
;
10330 case EF_ARM_EABI_VER2
:
10331 fprintf (file
, _(" [Version2 EABI]"));
10333 if (flags
& EF_ARM_SYMSARESORTED
)
10334 fprintf (file
, _(" [sorted symbol table]"));
10336 fprintf (file
, _(" [unsorted symbol table]"));
10338 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
10339 fprintf (file
, _(" [dynamic symbols use segment index]"));
10341 if (flags
& EF_ARM_MAPSYMSFIRST
)
10342 fprintf (file
, _(" [mapping symbols precede others]"));
10344 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
10345 | EF_ARM_MAPSYMSFIRST
);
10348 case EF_ARM_EABI_VER3
:
10349 fprintf (file
, _(" [Version3 EABI]"));
10352 case EF_ARM_EABI_VER4
:
10353 fprintf (file
, _(" [Version4 EABI]"));
10356 case EF_ARM_EABI_VER5
:
10357 fprintf (file
, _(" [Version5 EABI]"));
10359 if (flags
& EF_ARM_BE8
)
10360 fprintf (file
, _(" [BE8]"));
10362 if (flags
& EF_ARM_LE8
)
10363 fprintf (file
, _(" [LE8]"));
10365 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
10369 fprintf (file
, _(" <EABI version unrecognised>"));
10373 flags
&= ~ EF_ARM_EABIMASK
;
10375 if (flags
& EF_ARM_RELEXEC
)
10376 fprintf (file
, _(" [relocatable executable]"));
10378 if (flags
& EF_ARM_HASENTRY
)
10379 fprintf (file
, _(" [has entry point]"));
10381 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
10384 fprintf (file
, _("<Unrecognised flag bits set>"));
10386 fputc ('\n', file
);
10392 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
10394 switch (ELF_ST_TYPE (elf_sym
->st_info
))
10396 case STT_ARM_TFUNC
:
10397 return ELF_ST_TYPE (elf_sym
->st_info
);
10399 case STT_ARM_16BIT
:
10400 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
10401 This allows us to distinguish between data used by Thumb instructions
10402 and non-data (which is probably code) inside Thumb regions of an
10404 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
10405 return ELF_ST_TYPE (elf_sym
->st_info
);
10416 elf32_arm_gc_mark_hook (asection
*sec
,
10417 struct bfd_link_info
*info
,
10418 Elf_Internal_Rela
*rel
,
10419 struct elf_link_hash_entry
*h
,
10420 Elf_Internal_Sym
*sym
)
10423 switch (ELF32_R_TYPE (rel
->r_info
))
10425 case R_ARM_GNU_VTINHERIT
:
10426 case R_ARM_GNU_VTENTRY
:
10430 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10433 /* Update the got entry reference counts for the section being removed. */
10436 elf32_arm_gc_sweep_hook (bfd
* abfd
,
10437 struct bfd_link_info
* info
,
10439 const Elf_Internal_Rela
* relocs
)
10441 Elf_Internal_Shdr
*symtab_hdr
;
10442 struct elf_link_hash_entry
**sym_hashes
;
10443 bfd_signed_vma
*local_got_refcounts
;
10444 const Elf_Internal_Rela
*rel
, *relend
;
10445 struct elf32_arm_link_hash_table
* globals
;
10447 if (info
->relocatable
)
10450 globals
= elf32_arm_hash_table (info
);
10452 elf_section_data (sec
)->local_dynrel
= NULL
;
10454 symtab_hdr
= & elf_symtab_hdr (abfd
);
10455 sym_hashes
= elf_sym_hashes (abfd
);
10456 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10458 check_use_blx (globals
);
10460 relend
= relocs
+ sec
->reloc_count
;
10461 for (rel
= relocs
; rel
< relend
; rel
++)
10463 unsigned long r_symndx
;
10464 struct elf_link_hash_entry
*h
= NULL
;
10467 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10468 if (r_symndx
>= symtab_hdr
->sh_info
)
10470 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
10471 while (h
->root
.type
== bfd_link_hash_indirect
10472 || h
->root
.type
== bfd_link_hash_warning
)
10473 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10476 r_type
= ELF32_R_TYPE (rel
->r_info
);
10477 r_type
= arm_real_reloc_type (globals
, r_type
);
10481 case R_ARM_GOT_PREL
:
10482 case R_ARM_TLS_GD32
:
10483 case R_ARM_TLS_IE32
:
10486 if (h
->got
.refcount
> 0)
10487 h
->got
.refcount
-= 1;
10489 else if (local_got_refcounts
!= NULL
)
10491 if (local_got_refcounts
[r_symndx
] > 0)
10492 local_got_refcounts
[r_symndx
] -= 1;
10496 case R_ARM_TLS_LDM32
:
10497 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
10501 case R_ARM_ABS32_NOI
:
10503 case R_ARM_REL32_NOI
:
10509 case R_ARM_THM_CALL
:
10510 case R_ARM_THM_JUMP24
:
10511 case R_ARM_THM_JUMP19
:
10512 case R_ARM_MOVW_ABS_NC
:
10513 case R_ARM_MOVT_ABS
:
10514 case R_ARM_MOVW_PREL_NC
:
10515 case R_ARM_MOVT_PREL
:
10516 case R_ARM_THM_MOVW_ABS_NC
:
10517 case R_ARM_THM_MOVT_ABS
:
10518 case R_ARM_THM_MOVW_PREL_NC
:
10519 case R_ARM_THM_MOVT_PREL
:
10520 /* Should the interworking branches be here also? */
10524 struct elf32_arm_link_hash_entry
*eh
;
10525 struct elf32_arm_relocs_copied
**pp
;
10526 struct elf32_arm_relocs_copied
*p
;
10528 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10530 if (h
->plt
.refcount
> 0)
10532 h
->plt
.refcount
-= 1;
10533 if (r_type
== R_ARM_THM_CALL
)
10534 eh
->plt_maybe_thumb_refcount
--;
10536 if (r_type
== R_ARM_THM_JUMP24
10537 || r_type
== R_ARM_THM_JUMP19
)
10538 eh
->plt_thumb_refcount
--;
10541 if (r_type
== R_ARM_ABS32
10542 || r_type
== R_ARM_REL32
10543 || r_type
== R_ARM_ABS32_NOI
10544 || r_type
== R_ARM_REL32_NOI
)
10546 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
10548 if (p
->section
== sec
)
10551 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
10552 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32_NOI
)
10570 /* Look through the relocs for a section during the first phase. */
10573 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
10574 asection
*sec
, const Elf_Internal_Rela
*relocs
)
10576 Elf_Internal_Shdr
*symtab_hdr
;
10577 struct elf_link_hash_entry
**sym_hashes
;
10578 const Elf_Internal_Rela
*rel
;
10579 const Elf_Internal_Rela
*rel_end
;
10582 bfd_vma
*local_got_offsets
;
10583 struct elf32_arm_link_hash_table
*htab
;
10584 bfd_boolean needs_plt
;
10585 unsigned long nsyms
;
10587 if (info
->relocatable
)
10590 BFD_ASSERT (is_arm_elf (abfd
));
10592 htab
= elf32_arm_hash_table (info
);
10595 /* Create dynamic sections for relocatable executables so that we can
10596 copy relocations. */
10597 if (htab
->root
.is_relocatable_executable
10598 && ! htab
->root
.dynamic_sections_created
)
10600 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
10604 dynobj
= elf_hash_table (info
)->dynobj
;
10605 local_got_offsets
= elf_local_got_offsets (abfd
);
10607 symtab_hdr
= & elf_symtab_hdr (abfd
);
10608 sym_hashes
= elf_sym_hashes (abfd
);
10609 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
10611 rel_end
= relocs
+ sec
->reloc_count
;
10612 for (rel
= relocs
; rel
< rel_end
; rel
++)
10614 struct elf_link_hash_entry
*h
;
10615 struct elf32_arm_link_hash_entry
*eh
;
10616 unsigned long r_symndx
;
10619 r_symndx
= ELF32_R_SYM (rel
->r_info
);
10620 r_type
= ELF32_R_TYPE (rel
->r_info
);
10621 r_type
= arm_real_reloc_type (htab
, r_type
);
10623 if (r_symndx
>= nsyms
10624 /* PR 9934: It is possible to have relocations that do not
10625 refer to symbols, thus it is also possible to have an
10626 object file containing relocations but no symbol table. */
10627 && (r_symndx
> 0 || nsyms
> 0))
10629 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
10634 if (nsyms
== 0 || r_symndx
< symtab_hdr
->sh_info
)
10638 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
10639 while (h
->root
.type
== bfd_link_hash_indirect
10640 || h
->root
.type
== bfd_link_hash_warning
)
10641 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10644 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10649 case R_ARM_GOT_PREL
:
10650 case R_ARM_TLS_GD32
:
10651 case R_ARM_TLS_IE32
:
10652 /* This symbol requires a global offset table entry. */
10654 int tls_type
, old_tls_type
;
10658 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
10659 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
10660 default: tls_type
= GOT_NORMAL
; break;
10666 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
10670 bfd_signed_vma
*local_got_refcounts
;
10672 /* This is a global offset table entry for a local symbol. */
10673 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10674 if (local_got_refcounts
== NULL
)
10676 bfd_size_type size
;
10678 size
= symtab_hdr
->sh_info
;
10679 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
10680 local_got_refcounts
= bfd_zalloc (abfd
, size
);
10681 if (local_got_refcounts
== NULL
)
10683 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
10684 elf32_arm_local_got_tls_type (abfd
)
10685 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
10687 local_got_refcounts
[r_symndx
] += 1;
10688 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
10691 /* We will already have issued an error message if there is a
10692 TLS / non-TLS mismatch, based on the symbol type. We don't
10693 support any linker relaxations. So just combine any TLS
10695 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
10696 && tls_type
!= GOT_NORMAL
)
10697 tls_type
|= old_tls_type
;
10699 if (old_tls_type
!= tls_type
)
10702 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
10704 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
10707 /* Fall through. */
10709 case R_ARM_TLS_LDM32
:
10710 if (r_type
== R_ARM_TLS_LDM32
)
10711 htab
->tls_ldm_got
.refcount
++;
10712 /* Fall through. */
10714 case R_ARM_GOTOFF32
:
10716 if (htab
->sgot
== NULL
)
10718 if (htab
->root
.dynobj
== NULL
)
10719 htab
->root
.dynobj
= abfd
;
10720 if (!create_got_section (htab
->root
.dynobj
, info
))
10726 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
10727 ldr __GOTT_INDEX__ offsets. */
10728 if (!htab
->vxworks_p
)
10730 /* Fall through. */
10737 case R_ARM_THM_CALL
:
10738 case R_ARM_THM_JUMP24
:
10739 case R_ARM_THM_JUMP19
:
10743 case R_ARM_MOVW_ABS_NC
:
10744 case R_ARM_MOVT_ABS
:
10745 case R_ARM_THM_MOVW_ABS_NC
:
10746 case R_ARM_THM_MOVT_ABS
:
10749 (*_bfd_error_handler
)
10750 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
10751 abfd
, elf32_arm_howto_table_1
[r_type
].name
,
10752 (h
) ? h
->root
.root
.string
: "a local symbol");
10753 bfd_set_error (bfd_error_bad_value
);
10757 /* Fall through. */
10759 case R_ARM_ABS32_NOI
:
10761 case R_ARM_REL32_NOI
:
10762 case R_ARM_MOVW_PREL_NC
:
10763 case R_ARM_MOVT_PREL
:
10764 case R_ARM_THM_MOVW_PREL_NC
:
10765 case R_ARM_THM_MOVT_PREL
:
10769 /* Should the interworking branches be listed here? */
10772 /* If this reloc is in a read-only section, we might
10773 need a copy reloc. We can't check reliably at this
10774 stage whether the section is read-only, as input
10775 sections have not yet been mapped to output sections.
10776 Tentatively set the flag for now, and correct in
10777 adjust_dynamic_symbol. */
10779 h
->non_got_ref
= 1;
10781 /* We may need a .plt entry if the function this reloc
10782 refers to is in a different object. We can't tell for
10783 sure yet, because something later might force the
10788 /* If we create a PLT entry, this relocation will reference
10789 it, even if it's an ABS32 relocation. */
10790 h
->plt
.refcount
+= 1;
10792 /* It's too early to use htab->use_blx here, so we have to
10793 record possible blx references separately from
10794 relocs that definitely need a thumb stub. */
10796 if (r_type
== R_ARM_THM_CALL
)
10797 eh
->plt_maybe_thumb_refcount
+= 1;
10799 if (r_type
== R_ARM_THM_JUMP24
10800 || r_type
== R_ARM_THM_JUMP19
)
10801 eh
->plt_thumb_refcount
+= 1;
10804 /* If we are creating a shared library or relocatable executable,
10805 and this is a reloc against a global symbol, or a non PC
10806 relative reloc against a local symbol, then we need to copy
10807 the reloc into the shared library. However, if we are linking
10808 with -Bsymbolic, we do not need to copy a reloc against a
10809 global symbol which is defined in an object we are
10810 including in the link (i.e., DEF_REGULAR is set). At
10811 this point we have not seen all the input files, so it is
10812 possible that DEF_REGULAR is not set now but will be set
10813 later (it is never cleared). We account for that
10814 possibility below by storing information in the
10815 relocs_copied field of the hash table entry. */
10816 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
10817 && (sec
->flags
& SEC_ALLOC
) != 0
10818 && ((r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
)
10819 || (h
!= NULL
&& ! h
->needs_plt
10820 && (! info
->symbolic
|| ! h
->def_regular
))))
10822 struct elf32_arm_relocs_copied
*p
, **head
;
10824 /* When creating a shared object, we must copy these
10825 reloc types into the output file. We create a reloc
10826 section in dynobj and make room for this reloc. */
10827 if (sreloc
== NULL
)
10829 sreloc
= _bfd_elf_make_dynamic_reloc_section
10830 (sec
, dynobj
, 2, abfd
, ! htab
->use_rel
);
10832 if (sreloc
== NULL
)
10835 /* BPABI objects never have dynamic relocations mapped. */
10836 if (htab
->symbian_p
)
10840 flags
= bfd_get_section_flags (dynobj
, sreloc
);
10841 flags
&= ~(SEC_LOAD
| SEC_ALLOC
);
10842 bfd_set_section_flags (dynobj
, sreloc
, flags
);
10846 /* If this is a global symbol, we count the number of
10847 relocations we need for this symbol. */
10850 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
10854 /* Track dynamic relocs needed for local syms too.
10855 We really need local syms available to do this
10856 easily. Oh well. */
10859 Elf_Internal_Sym
*isym
;
10861 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
10866 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
10870 vpp
= &elf_section_data (s
)->local_dynrel
;
10871 head
= (struct elf32_arm_relocs_copied
**) vpp
;
10875 if (p
== NULL
|| p
->section
!= sec
)
10877 bfd_size_type amt
= sizeof *p
;
10879 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
10889 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
10895 /* This relocation describes the C++ object vtable hierarchy.
10896 Reconstruct it for later use during GC. */
10897 case R_ARM_GNU_VTINHERIT
:
10898 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
10902 /* This relocation describes which C++ vtable entries are actually
10903 used. Record for later use during GC. */
10904 case R_ARM_GNU_VTENTRY
:
10905 BFD_ASSERT (h
!= NULL
);
10907 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
10916 /* Unwinding tables are not referenced directly. This pass marks them as
10917 required if the corresponding code section is marked. */
10920 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
10921 elf_gc_mark_hook_fn gc_mark_hook
)
10924 Elf_Internal_Shdr
**elf_shdrp
;
10927 /* Marking EH data may cause additional code sections to be marked,
10928 requiring multiple passes. */
10933 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10937 if (! is_arm_elf (sub
))
10940 elf_shdrp
= elf_elfsections (sub
);
10941 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
10943 Elf_Internal_Shdr
*hdr
;
10945 hdr
= &elf_section_data (o
)->this_hdr
;
10946 if (hdr
->sh_type
== SHT_ARM_EXIDX
10948 && hdr
->sh_link
< elf_numsections (sub
)
10950 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
10953 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
10963 /* Treat mapping symbols as special target symbols. */
10966 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
10968 return bfd_is_arm_special_symbol_name (sym
->name
,
10969 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
10972 /* This is a copy of elf_find_function() from elf.c except that
10973 ARM mapping symbols are ignored when looking for function names
10974 and STT_ARM_TFUNC is considered to a function type. */
10977 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
10978 asection
* section
,
10979 asymbol
** symbols
,
10981 const char ** filename_ptr
,
10982 const char ** functionname_ptr
)
10984 const char * filename
= NULL
;
10985 asymbol
* func
= NULL
;
10986 bfd_vma low_func
= 0;
10989 for (p
= symbols
; *p
!= NULL
; p
++)
10991 elf_symbol_type
*q
;
10993 q
= (elf_symbol_type
*) *p
;
10995 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
11000 filename
= bfd_asymbol_name (&q
->symbol
);
11003 case STT_ARM_TFUNC
:
11005 /* Skip mapping symbols. */
11006 if ((q
->symbol
.flags
& BSF_LOCAL
)
11007 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
11008 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
11010 /* Fall through. */
11011 if (bfd_get_section (&q
->symbol
) == section
11012 && q
->symbol
.value
>= low_func
11013 && q
->symbol
.value
<= offset
)
11015 func
= (asymbol
*) q
;
11016 low_func
= q
->symbol
.value
;
11026 *filename_ptr
= filename
;
11027 if (functionname_ptr
)
11028 *functionname_ptr
= bfd_asymbol_name (func
);
11034 /* Find the nearest line to a particular section and offset, for error
11035 reporting. This code is a duplicate of the code in elf.c, except
11036 that it uses arm_elf_find_function. */
11039 elf32_arm_find_nearest_line (bfd
* abfd
,
11040 asection
* section
,
11041 asymbol
** symbols
,
11043 const char ** filename_ptr
,
11044 const char ** functionname_ptr
,
11045 unsigned int * line_ptr
)
11047 bfd_boolean found
= FALSE
;
11049 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
11051 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
11052 filename_ptr
, functionname_ptr
,
11054 & elf_tdata (abfd
)->dwarf2_find_line_info
))
11056 if (!*functionname_ptr
)
11057 arm_elf_find_function (abfd
, section
, symbols
, offset
,
11058 *filename_ptr
? NULL
: filename_ptr
,
11064 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
11065 & found
, filename_ptr
,
11066 functionname_ptr
, line_ptr
,
11067 & elf_tdata (abfd
)->line_info
))
11070 if (found
&& (*functionname_ptr
|| *line_ptr
))
11073 if (symbols
== NULL
)
11076 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
11077 filename_ptr
, functionname_ptr
))
11085 elf32_arm_find_inliner_info (bfd
* abfd
,
11086 const char ** filename_ptr
,
11087 const char ** functionname_ptr
,
11088 unsigned int * line_ptr
)
11091 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
11092 functionname_ptr
, line_ptr
,
11093 & elf_tdata (abfd
)->dwarf2_find_line_info
);
11097 /* Adjust a symbol defined by a dynamic object and referenced by a
11098 regular object. The current definition is in some section of the
11099 dynamic object, but we're not including those sections. We have to
11100 change the definition to something the rest of the link can
11104 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
11105 struct elf_link_hash_entry
* h
)
11109 struct elf32_arm_link_hash_entry
* eh
;
11110 struct elf32_arm_link_hash_table
*globals
;
11112 globals
= elf32_arm_hash_table (info
);
11113 dynobj
= elf_hash_table (info
)->dynobj
;
11115 /* Make sure we know what is going on here. */
11116 BFD_ASSERT (dynobj
!= NULL
11118 || h
->u
.weakdef
!= NULL
11121 && !h
->def_regular
)));
11123 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11125 /* If this is a function, put it in the procedure linkage table. We
11126 will fill in the contents of the procedure linkage table later,
11127 when we know the address of the .got section. */
11128 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
11131 if (h
->plt
.refcount
<= 0
11132 || SYMBOL_CALLS_LOCAL (info
, h
)
11133 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
11134 && h
->root
.type
== bfd_link_hash_undefweak
))
11136 /* This case can occur if we saw a PLT32 reloc in an input
11137 file, but the symbol was never referred to by a dynamic
11138 object, or if all references were garbage collected. In
11139 such a case, we don't actually need to build a procedure
11140 linkage table, and we can just do a PC24 reloc instead. */
11141 h
->plt
.offset
= (bfd_vma
) -1;
11142 eh
->plt_thumb_refcount
= 0;
11143 eh
->plt_maybe_thumb_refcount
= 0;
11151 /* It's possible that we incorrectly decided a .plt reloc was
11152 needed for an R_ARM_PC24 or similar reloc to a non-function sym
11153 in check_relocs. We can't decide accurately between function
11154 and non-function syms in check-relocs; Objects loaded later in
11155 the link may change h->type. So fix it now. */
11156 h
->plt
.offset
= (bfd_vma
) -1;
11157 eh
->plt_thumb_refcount
= 0;
11158 eh
->plt_maybe_thumb_refcount
= 0;
11161 /* If this is a weak symbol, and there is a real definition, the
11162 processor independent code will have arranged for us to see the
11163 real definition first, and we can just use the same value. */
11164 if (h
->u
.weakdef
!= NULL
)
11166 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
11167 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
11168 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
11169 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
11173 /* If there are no non-GOT references, we do not need a copy
11175 if (!h
->non_got_ref
)
11178 /* This is a reference to a symbol defined by a dynamic object which
11179 is not a function. */
11181 /* If we are creating a shared library, we must presume that the
11182 only references to the symbol are via the global offset table.
11183 For such cases we need not do anything here; the relocations will
11184 be handled correctly by relocate_section. Relocatable executables
11185 can reference data in shared objects directly, so we don't need to
11186 do anything here. */
11187 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
11192 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
11193 h
->root
.root
.string
);
11197 /* We must allocate the symbol in our .dynbss section, which will
11198 become part of the .bss section of the executable. There will be
11199 an entry for this symbol in the .dynsym section. The dynamic
11200 object will contain position independent code, so all references
11201 from the dynamic object to this symbol will go through the global
11202 offset table. The dynamic linker will use the .dynsym entry to
11203 determine the address it must put in the global offset table, so
11204 both the dynamic object and the regular object will refer to the
11205 same memory location for the variable. */
11206 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
11207 BFD_ASSERT (s
!= NULL
);
11209 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
11210 copy the initial value out of the dynamic object and into the
11211 runtime process image. We need to remember the offset into the
11212 .rel(a).bss section we are going to use. */
11213 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
11217 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
11218 BFD_ASSERT (srel
!= NULL
);
11219 srel
->size
+= RELOC_SIZE (globals
);
11223 return _bfd_elf_adjust_dynamic_copy (h
, s
);
11226 /* Allocate space in .plt, .got and associated reloc sections for
11230 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
11232 struct bfd_link_info
*info
;
11233 struct elf32_arm_link_hash_table
*htab
;
11234 struct elf32_arm_link_hash_entry
*eh
;
11235 struct elf32_arm_relocs_copied
*p
;
11236 bfd_signed_vma thumb_refs
;
11238 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11240 if (h
->root
.type
== bfd_link_hash_indirect
)
11243 if (h
->root
.type
== bfd_link_hash_warning
)
11244 /* When warning symbols are created, they **replace** the "real"
11245 entry in the hash table, thus we never get to see the real
11246 symbol in a hash traversal. So look at it now. */
11247 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11249 info
= (struct bfd_link_info
*) inf
;
11250 htab
= elf32_arm_hash_table (info
);
11252 if (htab
->root
.dynamic_sections_created
11253 && h
->plt
.refcount
> 0)
11255 /* Make sure this symbol is output as a dynamic symbol.
11256 Undefined weak syms won't yet be marked as dynamic. */
11257 if (h
->dynindx
== -1
11258 && !h
->forced_local
)
11260 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
11265 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
11267 asection
*s
= htab
->splt
;
11269 /* If this is the first .plt entry, make room for the special
11272 s
->size
+= htab
->plt_header_size
;
11274 h
->plt
.offset
= s
->size
;
11276 /* If we will insert a Thumb trampoline before this PLT, leave room
11278 thumb_refs
= eh
->plt_thumb_refcount
;
11279 if (!htab
->use_blx
)
11280 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
11282 if (thumb_refs
> 0)
11284 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
11285 s
->size
+= PLT_THUMB_STUB_SIZE
;
11288 /* If this symbol is not defined in a regular file, and we are
11289 not generating a shared library, then set the symbol to this
11290 location in the .plt. This is required to make function
11291 pointers compare as equal between the normal executable and
11292 the shared library. */
11294 && !h
->def_regular
)
11296 h
->root
.u
.def
.section
= s
;
11297 h
->root
.u
.def
.value
= h
->plt
.offset
;
11300 /* Make sure the function is not marked as Thumb, in case
11301 it is the target of an ABS32 relocation, which will
11302 point to the PLT entry. */
11303 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
11304 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
11306 /* Make room for this entry. */
11307 s
->size
+= htab
->plt_entry_size
;
11309 if (!htab
->symbian_p
)
11311 /* We also need to make an entry in the .got.plt section, which
11312 will be placed in the .got section by the linker script. */
11313 eh
->plt_got_offset
= htab
->sgotplt
->size
;
11314 htab
->sgotplt
->size
+= 4;
11317 /* We also need to make an entry in the .rel(a).plt section. */
11318 htab
->srelplt
->size
+= RELOC_SIZE (htab
);
11320 /* VxWorks executables have a second set of relocations for
11321 each PLT entry. They go in a separate relocation section,
11322 which is processed by the kernel loader. */
11323 if (htab
->vxworks_p
&& !info
->shared
)
11325 /* There is a relocation for the initial PLT entry:
11326 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
11327 if (h
->plt
.offset
== htab
->plt_header_size
)
11328 htab
->srelplt2
->size
+= RELOC_SIZE (htab
);
11330 /* There are two extra relocations for each subsequent
11331 PLT entry: an R_ARM_32 relocation for the GOT entry,
11332 and an R_ARM_32 relocation for the PLT entry. */
11333 htab
->srelplt2
->size
+= RELOC_SIZE (htab
) * 2;
11338 h
->plt
.offset
= (bfd_vma
) -1;
11344 h
->plt
.offset
= (bfd_vma
) -1;
11348 if (h
->got
.refcount
> 0)
11352 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
11355 /* Make sure this symbol is output as a dynamic symbol.
11356 Undefined weak syms won't yet be marked as dynamic. */
11357 if (h
->dynindx
== -1
11358 && !h
->forced_local
)
11360 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
11364 if (!htab
->symbian_p
)
11367 h
->got
.offset
= s
->size
;
11369 if (tls_type
== GOT_UNKNOWN
)
11372 if (tls_type
== GOT_NORMAL
)
11373 /* Non-TLS symbols need one GOT slot. */
11377 if (tls_type
& GOT_TLS_GD
)
11378 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
11380 if (tls_type
& GOT_TLS_IE
)
11381 /* R_ARM_TLS_IE32 needs one GOT slot. */
11385 dyn
= htab
->root
.dynamic_sections_created
;
11388 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
11390 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
11393 if (tls_type
!= GOT_NORMAL
11394 && (info
->shared
|| indx
!= 0)
11395 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
11396 || h
->root
.type
!= bfd_link_hash_undefweak
))
11398 if (tls_type
& GOT_TLS_IE
)
11399 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
11401 if (tls_type
& GOT_TLS_GD
)
11402 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
11404 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
11405 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
11407 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
11408 || h
->root
.type
!= bfd_link_hash_undefweak
)
11410 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
11411 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
11415 h
->got
.offset
= (bfd_vma
) -1;
11417 /* Allocate stubs for exported Thumb functions on v4t. */
11418 if (!htab
->use_blx
&& h
->dynindx
!= -1
11420 && ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
11421 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
11423 struct elf_link_hash_entry
* th
;
11424 struct bfd_link_hash_entry
* bh
;
11425 struct elf_link_hash_entry
* myh
;
11429 /* Create a new symbol to regist the real location of the function. */
11430 s
= h
->root
.u
.def
.section
;
11431 sprintf (name
, "__real_%s", h
->root
.root
.string
);
11432 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
11433 name
, BSF_GLOBAL
, s
,
11434 h
->root
.u
.def
.value
,
11435 NULL
, TRUE
, FALSE
, &bh
);
11437 myh
= (struct elf_link_hash_entry
*) bh
;
11438 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
11439 myh
->forced_local
= 1;
11440 eh
->export_glue
= myh
;
11441 th
= record_arm_to_thumb_glue (info
, h
);
11442 /* Point the symbol at the stub. */
11443 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
11444 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
11445 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
11448 if (eh
->relocs_copied
== NULL
)
11451 /* In the shared -Bsymbolic case, discard space allocated for
11452 dynamic pc-relative relocs against symbols which turn out to be
11453 defined in regular objects. For the normal shared case, discard
11454 space for pc-relative relocs that have become local due to symbol
11455 visibility changes. */
11457 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
11459 /* The only relocs that use pc_count are R_ARM_REL32 and
11460 R_ARM_REL32_NOI, which will appear on something like
11461 ".long foo - .". We want calls to protected symbols to resolve
11462 directly to the function rather than going via the plt. If people
11463 want function pointer comparisons to work as expected then they
11464 should avoid writing assembly like ".long foo - .". */
11465 if (SYMBOL_CALLS_LOCAL (info
, h
))
11467 struct elf32_arm_relocs_copied
**pp
;
11469 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
11471 p
->count
-= p
->pc_count
;
11480 if (elf32_arm_hash_table (info
)->vxworks_p
)
11482 struct elf32_arm_relocs_copied
**pp
;
11484 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
11486 if (strcmp (p
->section
->output_section
->name
, ".tls_vars") == 0)
11493 /* Also discard relocs on undefined weak syms with non-default
11495 if (eh
->relocs_copied
!= NULL
11496 && h
->root
.type
== bfd_link_hash_undefweak
)
11498 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
11499 eh
->relocs_copied
= NULL
;
11501 /* Make sure undefined weak symbols are output as a dynamic
11503 else if (h
->dynindx
== -1
11504 && !h
->forced_local
)
11506 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
11511 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
11512 && h
->root
.type
== bfd_link_hash_new
)
11514 /* Output absolute symbols so that we can create relocations
11515 against them. For normal symbols we output a relocation
11516 against the section that contains them. */
11517 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
11524 /* For the non-shared case, discard space for relocs against
11525 symbols which turn out to need copy relocs or are not
11528 if (!h
->non_got_ref
11529 && ((h
->def_dynamic
11530 && !h
->def_regular
)
11531 || (htab
->root
.dynamic_sections_created
11532 && (h
->root
.type
== bfd_link_hash_undefweak
11533 || h
->root
.type
== bfd_link_hash_undefined
))))
11535 /* Make sure this symbol is output as a dynamic symbol.
11536 Undefined weak syms won't yet be marked as dynamic. */
11537 if (h
->dynindx
== -1
11538 && !h
->forced_local
)
11540 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
11544 /* If that succeeded, we know we'll be keeping all the
11546 if (h
->dynindx
!= -1)
11550 eh
->relocs_copied
= NULL
;
11555 /* Finally, allocate space. */
11556 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
11558 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
11559 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
11565 /* Find any dynamic relocs that apply to read-only sections. */
11568 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
11570 struct elf32_arm_link_hash_entry
* eh
;
11571 struct elf32_arm_relocs_copied
* p
;
11573 if (h
->root
.type
== bfd_link_hash_warning
)
11574 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11576 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11577 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
11579 asection
*s
= p
->section
;
11581 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
11583 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
11585 info
->flags
|= DF_TEXTREL
;
11587 /* Not an error, just cut short the traversal. */
11595 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
11598 struct elf32_arm_link_hash_table
*globals
;
11600 globals
= elf32_arm_hash_table (info
);
11601 globals
->byteswap_code
= byteswap_code
;
11604 /* Set the sizes of the dynamic sections. */
11607 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
11608 struct bfd_link_info
* info
)
11613 bfd_boolean relocs
;
11615 struct elf32_arm_link_hash_table
*htab
;
11617 htab
= elf32_arm_hash_table (info
);
11618 dynobj
= elf_hash_table (info
)->dynobj
;
11619 BFD_ASSERT (dynobj
!= NULL
);
11620 check_use_blx (htab
);
11622 if (elf_hash_table (info
)->dynamic_sections_created
)
11624 /* Set the contents of the .interp section to the interpreter. */
11625 if (info
->executable
)
11627 s
= bfd_get_section_by_name (dynobj
, ".interp");
11628 BFD_ASSERT (s
!= NULL
);
11629 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
11630 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
11634 /* Set up .got offsets for local syms, and space for local dynamic
11636 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
11638 bfd_signed_vma
*local_got
;
11639 bfd_signed_vma
*end_local_got
;
11640 char *local_tls_type
;
11641 bfd_size_type locsymcount
;
11642 Elf_Internal_Shdr
*symtab_hdr
;
11644 bfd_boolean is_vxworks
= elf32_arm_hash_table (info
)->vxworks_p
;
11646 if (! is_arm_elf (ibfd
))
11649 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
11651 struct elf32_arm_relocs_copied
*p
;
11653 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
11655 if (!bfd_is_abs_section (p
->section
)
11656 && bfd_is_abs_section (p
->section
->output_section
))
11658 /* Input section has been discarded, either because
11659 it is a copy of a linkonce section or due to
11660 linker script /DISCARD/, so we'll be discarding
11663 else if (is_vxworks
11664 && strcmp (p
->section
->output_section
->name
,
11667 /* Relocations in vxworks .tls_vars sections are
11668 handled specially by the loader. */
11670 else if (p
->count
!= 0)
11672 srel
= elf_section_data (p
->section
)->sreloc
;
11673 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
11674 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
11675 info
->flags
|= DF_TEXTREL
;
11680 local_got
= elf_local_got_refcounts (ibfd
);
11684 symtab_hdr
= & elf_symtab_hdr (ibfd
);
11685 locsymcount
= symtab_hdr
->sh_info
;
11686 end_local_got
= local_got
+ locsymcount
;
11687 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
11689 srel
= htab
->srelgot
;
11690 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
11692 if (*local_got
> 0)
11694 *local_got
= s
->size
;
11695 if (*local_tls_type
& GOT_TLS_GD
)
11696 /* TLS_GD relocs need an 8-byte structure in the GOT. */
11698 if (*local_tls_type
& GOT_TLS_IE
)
11700 if (*local_tls_type
== GOT_NORMAL
)
11703 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
11704 srel
->size
+= RELOC_SIZE (htab
);
11707 *local_got
= (bfd_vma
) -1;
11711 if (htab
->tls_ldm_got
.refcount
> 0)
11713 /* Allocate two GOT entries and one dynamic relocation (if necessary)
11714 for R_ARM_TLS_LDM32 relocations. */
11715 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
11716 htab
->sgot
->size
+= 8;
11718 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
11721 htab
->tls_ldm_got
.offset
= -1;
11723 /* Allocate global sym .plt and .got entries, and space for global
11724 sym dynamic relocs. */
11725 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
11727 /* Here we rummage through the found bfds to collect glue information. */
11728 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
11730 if (! is_arm_elf (ibfd
))
11733 /* Initialise mapping tables for code/data. */
11734 bfd_elf32_arm_init_maps (ibfd
);
11736 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
11737 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
11738 /* xgettext:c-format */
11739 _bfd_error_handler (_("Errors encountered processing file %s"),
11743 /* Allocate space for the glue sections now that we've sized them. */
11744 bfd_elf32_arm_allocate_interworking_sections (info
);
11746 /* The check_relocs and adjust_dynamic_symbol entry points have
11747 determined the sizes of the various dynamic sections. Allocate
11748 memory for them. */
11751 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
11755 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
11758 /* It's OK to base decisions on the section name, because none
11759 of the dynobj section names depend upon the input files. */
11760 name
= bfd_get_section_name (dynobj
, s
);
11762 if (strcmp (name
, ".plt") == 0)
11764 /* Remember whether there is a PLT. */
11765 plt
= s
->size
!= 0;
11767 else if (CONST_STRNEQ (name
, ".rel"))
11771 /* Remember whether there are any reloc sections other
11772 than .rel(a).plt and .rela.plt.unloaded. */
11773 if (s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
11776 /* We use the reloc_count field as a counter if we need
11777 to copy relocs into the output file. */
11778 s
->reloc_count
= 0;
11781 else if (! CONST_STRNEQ (name
, ".got")
11782 && strcmp (name
, ".dynbss") != 0)
11784 /* It's not one of our sections, so don't allocate space. */
11790 /* If we don't need this section, strip it from the
11791 output file. This is mostly to handle .rel(a).bss and
11792 .rel(a).plt. We must create both sections in
11793 create_dynamic_sections, because they must be created
11794 before the linker maps input sections to output
11795 sections. The linker does that before
11796 adjust_dynamic_symbol is called, and it is that
11797 function which decides whether anything needs to go
11798 into these sections. */
11799 s
->flags
|= SEC_EXCLUDE
;
11803 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
11806 /* Allocate memory for the section contents. */
11807 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
11808 if (s
->contents
== NULL
)
11812 if (elf_hash_table (info
)->dynamic_sections_created
)
11814 /* Add some entries to the .dynamic section. We fill in the
11815 values later, in elf32_arm_finish_dynamic_sections, but we
11816 must add the entries now so that we get the correct size for
11817 the .dynamic section. The DT_DEBUG entry is filled in by the
11818 dynamic linker and used by the debugger. */
11819 #define add_dynamic_entry(TAG, VAL) \
11820 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
11822 if (info
->executable
)
11824 if (!add_dynamic_entry (DT_DEBUG
, 0))
11830 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
11831 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
11832 || !add_dynamic_entry (DT_PLTREL
,
11833 htab
->use_rel
? DT_REL
: DT_RELA
)
11834 || !add_dynamic_entry (DT_JMPREL
, 0))
11842 if (!add_dynamic_entry (DT_REL
, 0)
11843 || !add_dynamic_entry (DT_RELSZ
, 0)
11844 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
11849 if (!add_dynamic_entry (DT_RELA
, 0)
11850 || !add_dynamic_entry (DT_RELASZ
, 0)
11851 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
11856 /* If any dynamic relocs apply to a read-only section,
11857 then we need a DT_TEXTREL entry. */
11858 if ((info
->flags
& DF_TEXTREL
) == 0)
11859 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
11862 if ((info
->flags
& DF_TEXTREL
) != 0)
11864 if (!add_dynamic_entry (DT_TEXTREL
, 0))
11867 if (htab
->vxworks_p
11868 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
11871 #undef add_dynamic_entry
11876 /* Finish up dynamic symbol handling. We set the contents of various
11877 dynamic sections here. */
11880 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
11881 struct bfd_link_info
* info
,
11882 struct elf_link_hash_entry
* h
,
11883 Elf_Internal_Sym
* sym
)
11886 struct elf32_arm_link_hash_table
*htab
;
11887 struct elf32_arm_link_hash_entry
*eh
;
11889 dynobj
= elf_hash_table (info
)->dynobj
;
11890 htab
= elf32_arm_hash_table (info
);
11891 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11893 if (h
->plt
.offset
!= (bfd_vma
) -1)
11899 Elf_Internal_Rela rel
;
11901 /* This symbol has an entry in the procedure linkage table. Set
11904 BFD_ASSERT (h
->dynindx
!= -1);
11906 splt
= bfd_get_section_by_name (dynobj
, ".plt");
11907 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".plt"));
11908 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
11910 /* Fill in the entry in the procedure linkage table. */
11911 if (htab
->symbian_p
)
11913 put_arm_insn (htab
, output_bfd
,
11914 elf32_arm_symbian_plt_entry
[0],
11915 splt
->contents
+ h
->plt
.offset
);
11916 bfd_put_32 (output_bfd
,
11917 elf32_arm_symbian_plt_entry
[1],
11918 splt
->contents
+ h
->plt
.offset
+ 4);
11920 /* Fill in the entry in the .rel.plt section. */
11921 rel
.r_offset
= (splt
->output_section
->vma
11922 + splt
->output_offset
11923 + h
->plt
.offset
+ 4);
11924 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
11926 /* Get the index in the procedure linkage table which
11927 corresponds to this symbol. This is the index of this symbol
11928 in all the symbols for which we are making plt entries. The
11929 first entry in the procedure linkage table is reserved. */
11930 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
11931 / htab
->plt_entry_size
);
11935 bfd_vma got_offset
, got_address
, plt_address
;
11936 bfd_vma got_displacement
;
11940 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
11941 BFD_ASSERT (sgot
!= NULL
);
11943 /* Get the offset into the .got.plt table of the entry that
11944 corresponds to this function. */
11945 got_offset
= eh
->plt_got_offset
;
11947 /* Get the index in the procedure linkage table which
11948 corresponds to this symbol. This is the index of this symbol
11949 in all the symbols for which we are making plt entries. The
11950 first three entries in .got.plt are reserved; after that
11951 symbols appear in the same order as in .plt. */
11952 plt_index
= (got_offset
- 12) / 4;
11954 /* Calculate the address of the GOT entry. */
11955 got_address
= (sgot
->output_section
->vma
11956 + sgot
->output_offset
11959 /* ...and the address of the PLT entry. */
11960 plt_address
= (splt
->output_section
->vma
11961 + splt
->output_offset
11964 ptr
= htab
->splt
->contents
+ h
->plt
.offset
;
11965 if (htab
->vxworks_p
&& info
->shared
)
11970 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
11972 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
11974 val
|= got_address
- sgot
->output_section
->vma
;
11976 val
|= plt_index
* RELOC_SIZE (htab
);
11977 if (i
== 2 || i
== 5)
11978 bfd_put_32 (output_bfd
, val
, ptr
);
11980 put_arm_insn (htab
, output_bfd
, val
, ptr
);
11983 else if (htab
->vxworks_p
)
11988 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
11990 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
11992 val
|= got_address
;
11994 val
|= 0xffffff & -((h
->plt
.offset
+ i
* 4 + 8) >> 2);
11996 val
|= plt_index
* RELOC_SIZE (htab
);
11997 if (i
== 2 || i
== 5)
11998 bfd_put_32 (output_bfd
, val
, ptr
);
12000 put_arm_insn (htab
, output_bfd
, val
, ptr
);
12003 loc
= (htab
->srelplt2
->contents
12004 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
12006 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
12007 referencing the GOT for this PLT entry. */
12008 rel
.r_offset
= plt_address
+ 8;
12009 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
12010 rel
.r_addend
= got_offset
;
12011 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
12012 loc
+= RELOC_SIZE (htab
);
12014 /* Create the R_ARM_ABS32 relocation referencing the
12015 beginning of the PLT for this GOT entry. */
12016 rel
.r_offset
= got_address
;
12017 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
12019 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
12023 bfd_signed_vma thumb_refs
;
12024 /* Calculate the displacement between the PLT slot and the
12025 entry in the GOT. The eight-byte offset accounts for the
12026 value produced by adding to pc in the first instruction
12027 of the PLT stub. */
12028 got_displacement
= got_address
- (plt_address
+ 8);
12030 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
12032 thumb_refs
= eh
->plt_thumb_refcount
;
12033 if (!htab
->use_blx
)
12034 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
12036 if (thumb_refs
> 0)
12038 put_thumb_insn (htab
, output_bfd
,
12039 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
12040 put_thumb_insn (htab
, output_bfd
,
12041 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
12044 put_arm_insn (htab
, output_bfd
,
12045 elf32_arm_plt_entry
[0]
12046 | ((got_displacement
& 0x0ff00000) >> 20),
12048 put_arm_insn (htab
, output_bfd
,
12049 elf32_arm_plt_entry
[1]
12050 | ((got_displacement
& 0x000ff000) >> 12),
12052 put_arm_insn (htab
, output_bfd
,
12053 elf32_arm_plt_entry
[2]
12054 | (got_displacement
& 0x00000fff),
12056 #ifdef FOUR_WORD_PLT
12057 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
12061 /* Fill in the entry in the global offset table. */
12062 bfd_put_32 (output_bfd
,
12063 (splt
->output_section
->vma
12064 + splt
->output_offset
),
12065 sgot
->contents
+ got_offset
);
12067 /* Fill in the entry in the .rel(a).plt section. */
12069 rel
.r_offset
= got_address
;
12070 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
12073 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
12074 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
12076 if (!h
->def_regular
)
12078 /* Mark the symbol as undefined, rather than as defined in
12079 the .plt section. Leave the value alone. */
12080 sym
->st_shndx
= SHN_UNDEF
;
12081 /* If the symbol is weak, we do need to clear the value.
12082 Otherwise, the PLT entry would provide a definition for
12083 the symbol even if the symbol wasn't defined anywhere,
12084 and so the symbol would never be NULL. */
12085 if (!h
->ref_regular_nonweak
)
12090 if (h
->got
.offset
!= (bfd_vma
) -1
12091 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
12092 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
12096 Elf_Internal_Rela rel
;
12100 /* This symbol has an entry in the global offset table. Set it
12102 sgot
= bfd_get_section_by_name (dynobj
, ".got");
12103 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".got"));
12104 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
12106 offset
= (h
->got
.offset
& ~(bfd_vma
) 1);
12108 rel
.r_offset
= (sgot
->output_section
->vma
12109 + sgot
->output_offset
12112 /* If this is a static link, or it is a -Bsymbolic link and the
12113 symbol is defined locally or was forced to be local because
12114 of a version file, we just want to emit a RELATIVE reloc.
12115 The entry in the global offset table will already have been
12116 initialized in the relocate_section function. */
12118 && SYMBOL_REFERENCES_LOCAL (info
, h
))
12120 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
12121 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
12122 if (!htab
->use_rel
)
12124 rel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
12125 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
12130 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
12131 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
12132 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
12135 loc
= srel
->contents
+ srel
->reloc_count
++ * RELOC_SIZE (htab
);
12136 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
12142 Elf_Internal_Rela rel
;
12145 /* This symbol needs a copy reloc. Set it up. */
12146 BFD_ASSERT (h
->dynindx
!= -1
12147 && (h
->root
.type
== bfd_link_hash_defined
12148 || h
->root
.type
== bfd_link_hash_defweak
));
12150 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
12151 RELOC_SECTION (htab
, ".bss"));
12152 BFD_ASSERT (s
!= NULL
);
12155 rel
.r_offset
= (h
->root
.u
.def
.value
12156 + h
->root
.u
.def
.section
->output_section
->vma
12157 + h
->root
.u
.def
.section
->output_offset
);
12158 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
12159 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
12160 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
12163 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
12164 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
12165 to the ".got" section. */
12166 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
12167 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
12168 sym
->st_shndx
= SHN_ABS
;
12173 /* Finish up the dynamic sections. */
12176 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
12182 dynobj
= elf_hash_table (info
)->dynobj
;
12184 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
12185 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
12186 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
12188 if (elf_hash_table (info
)->dynamic_sections_created
)
12191 Elf32_External_Dyn
*dyncon
, *dynconend
;
12192 struct elf32_arm_link_hash_table
*htab
;
12194 htab
= elf32_arm_hash_table (info
);
12195 splt
= bfd_get_section_by_name (dynobj
, ".plt");
12196 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
12198 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
12199 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
12201 for (; dyncon
< dynconend
; dyncon
++)
12203 Elf_Internal_Dyn dyn
;
12207 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
12214 if (htab
->vxworks_p
12215 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
12216 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12221 goto get_vma_if_bpabi
;
12224 goto get_vma_if_bpabi
;
12227 goto get_vma_if_bpabi
;
12229 name
= ".gnu.version";
12230 goto get_vma_if_bpabi
;
12232 name
= ".gnu.version_d";
12233 goto get_vma_if_bpabi
;
12235 name
= ".gnu.version_r";
12236 goto get_vma_if_bpabi
;
12242 name
= RELOC_SECTION (htab
, ".plt");
12244 s
= bfd_get_section_by_name (output_bfd
, name
);
12245 BFD_ASSERT (s
!= NULL
);
12246 if (!htab
->symbian_p
)
12247 dyn
.d_un
.d_ptr
= s
->vma
;
12249 /* In the BPABI, tags in the PT_DYNAMIC section point
12250 at the file offset, not the memory address, for the
12251 convenience of the post linker. */
12252 dyn
.d_un
.d_ptr
= s
->filepos
;
12253 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12257 if (htab
->symbian_p
)
12262 s
= bfd_get_section_by_name (output_bfd
,
12263 RELOC_SECTION (htab
, ".plt"));
12264 BFD_ASSERT (s
!= NULL
);
12265 dyn
.d_un
.d_val
= s
->size
;
12266 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12271 if (!htab
->symbian_p
)
12273 /* My reading of the SVR4 ABI indicates that the
12274 procedure linkage table relocs (DT_JMPREL) should be
12275 included in the overall relocs (DT_REL). This is
12276 what Solaris does. However, UnixWare can not handle
12277 that case. Therefore, we override the DT_RELSZ entry
12278 here to make it not include the JMPREL relocs. Since
12279 the linker script arranges for .rel(a).plt to follow all
12280 other relocation sections, we don't have to worry
12281 about changing the DT_REL entry. */
12282 s
= bfd_get_section_by_name (output_bfd
,
12283 RELOC_SECTION (htab
, ".plt"));
12285 dyn
.d_un
.d_val
-= s
->size
;
12286 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12289 /* Fall through. */
12293 /* In the BPABI, the DT_REL tag must point at the file
12294 offset, not the VMA, of the first relocation
12295 section. So, we use code similar to that in
12296 elflink.c, but do not check for SHF_ALLOC on the
12297 relcoation section, since relocations sections are
12298 never allocated under the BPABI. The comments above
12299 about Unixware notwithstanding, we include all of the
12300 relocations here. */
12301 if (htab
->symbian_p
)
12304 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
12305 ? SHT_REL
: SHT_RELA
);
12306 dyn
.d_un
.d_val
= 0;
12307 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
12309 Elf_Internal_Shdr
*hdr
12310 = elf_elfsections (output_bfd
)[i
];
12311 if (hdr
->sh_type
== type
)
12313 if (dyn
.d_tag
== DT_RELSZ
12314 || dyn
.d_tag
== DT_RELASZ
)
12315 dyn
.d_un
.d_val
+= hdr
->sh_size
;
12316 else if ((ufile_ptr
) hdr
->sh_offset
12317 <= dyn
.d_un
.d_val
- 1)
12318 dyn
.d_un
.d_val
= hdr
->sh_offset
;
12321 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12325 /* Set the bottom bit of DT_INIT/FINI if the
12326 corresponding function is Thumb. */
12328 name
= info
->init_function
;
12331 name
= info
->fini_function
;
12333 /* If it wasn't set by elf_bfd_final_link
12334 then there is nothing to adjust. */
12335 if (dyn
.d_un
.d_val
!= 0)
12337 struct elf_link_hash_entry
* eh
;
12339 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
12340 FALSE
, FALSE
, TRUE
);
12342 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
12344 dyn
.d_un
.d_val
|= 1;
12345 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
12352 /* Fill in the first entry in the procedure linkage table. */
12353 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
12355 const bfd_vma
*plt0_entry
;
12356 bfd_vma got_address
, plt_address
, got_displacement
;
12358 /* Calculate the addresses of the GOT and PLT. */
12359 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
12360 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
12362 if (htab
->vxworks_p
)
12364 /* The VxWorks GOT is relocated by the dynamic linker.
12365 Therefore, we must emit relocations rather than simply
12366 computing the values now. */
12367 Elf_Internal_Rela rel
;
12369 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
12370 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
12371 splt
->contents
+ 0);
12372 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
12373 splt
->contents
+ 4);
12374 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
12375 splt
->contents
+ 8);
12376 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
12378 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
12379 rel
.r_offset
= plt_address
+ 12;
12380 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
12382 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
12383 htab
->srelplt2
->contents
);
12387 got_displacement
= got_address
- (plt_address
+ 16);
12389 plt0_entry
= elf32_arm_plt0_entry
;
12390 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
12391 splt
->contents
+ 0);
12392 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
12393 splt
->contents
+ 4);
12394 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
12395 splt
->contents
+ 8);
12396 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
12397 splt
->contents
+ 12);
12399 #ifdef FOUR_WORD_PLT
12400 /* The displacement value goes in the otherwise-unused
12401 last word of the second entry. */
12402 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
12404 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
12409 /* UnixWare sets the entsize of .plt to 4, although that doesn't
12410 really seem like the right value. */
12411 if (splt
->output_section
->owner
== output_bfd
)
12412 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
12414 if (htab
->vxworks_p
&& !info
->shared
&& htab
->splt
->size
> 0)
12416 /* Correct the .rel(a).plt.unloaded relocations. They will have
12417 incorrect symbol indexes. */
12421 num_plts
= ((htab
->splt
->size
- htab
->plt_header_size
)
12422 / htab
->plt_entry_size
);
12423 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
12425 for (; num_plts
; num_plts
--)
12427 Elf_Internal_Rela rel
;
12429 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
12430 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
12431 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
12432 p
+= RELOC_SIZE (htab
);
12434 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
12435 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
12436 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
12437 p
+= RELOC_SIZE (htab
);
12442 /* Fill in the first three entries in the global offset table. */
12445 if (sgot
->size
> 0)
12448 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
12450 bfd_put_32 (output_bfd
,
12451 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
12453 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
12454 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
12457 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
12464 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
12466 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
12467 struct elf32_arm_link_hash_table
*globals
;
12469 i_ehdrp
= elf_elfheader (abfd
);
12471 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
12472 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
12474 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
12475 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
12479 globals
= elf32_arm_hash_table (link_info
);
12480 if (globals
->byteswap_code
)
12481 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
12485 static enum elf_reloc_type_class
12486 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
12488 switch ((int) ELF32_R_TYPE (rela
->r_info
))
12490 case R_ARM_RELATIVE
:
12491 return reloc_class_relative
;
12492 case R_ARM_JUMP_SLOT
:
12493 return reloc_class_plt
;
12495 return reloc_class_copy
;
12497 return reloc_class_normal
;
12501 /* Set the right machine number for an Arm ELF file. */
12504 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
12506 if (hdr
->sh_type
== SHT_NOTE
)
12507 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
12513 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
12515 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
12518 /* Return TRUE if this is an unwinding table entry. */
12521 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
12523 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
12524 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
12528 /* Set the type and flags for an ARM section. We do this by
12529 the section name, which is a hack, but ought to work. */
12532 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
12536 name
= bfd_get_section_name (abfd
, sec
);
12538 if (is_arm_elf_unwind_section_name (abfd
, name
))
12540 hdr
->sh_type
= SHT_ARM_EXIDX
;
12541 hdr
->sh_flags
|= SHF_LINK_ORDER
;
12546 /* Handle an ARM specific section when reading an object file. This is
12547 called when bfd_section_from_shdr finds a section with an unknown
12551 elf32_arm_section_from_shdr (bfd
*abfd
,
12552 Elf_Internal_Shdr
* hdr
,
12556 /* There ought to be a place to keep ELF backend specific flags, but
12557 at the moment there isn't one. We just keep track of the
12558 sections by their name, instead. Fortunately, the ABI gives
12559 names for all the ARM specific sections, so we will probably get
12561 switch (hdr
->sh_type
)
12563 case SHT_ARM_EXIDX
:
12564 case SHT_ARM_PREEMPTMAP
:
12565 case SHT_ARM_ATTRIBUTES
:
12572 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
12578 /* A structure used to record a list of sections, independently
12579 of the next and prev fields in the asection structure. */
12580 typedef struct section_list
12583 struct section_list
* next
;
12584 struct section_list
* prev
;
12588 /* Unfortunately we need to keep a list of sections for which
12589 an _arm_elf_section_data structure has been allocated. This
12590 is because it is possible for functions like elf32_arm_write_section
12591 to be called on a section which has had an elf_data_structure
12592 allocated for it (and so the used_by_bfd field is valid) but
12593 for which the ARM extended version of this structure - the
12594 _arm_elf_section_data structure - has not been allocated. */
12595 static section_list
* sections_with_arm_elf_section_data
= NULL
;
12598 record_section_with_arm_elf_section_data (asection
* sec
)
12600 struct section_list
* entry
;
12602 entry
= bfd_malloc (sizeof (* entry
));
12606 entry
->next
= sections_with_arm_elf_section_data
;
12607 entry
->prev
= NULL
;
12608 if (entry
->next
!= NULL
)
12609 entry
->next
->prev
= entry
;
12610 sections_with_arm_elf_section_data
= entry
;
12613 static struct section_list
*
12614 find_arm_elf_section_entry (asection
* sec
)
12616 struct section_list
* entry
;
12617 static struct section_list
* last_entry
= NULL
;
12619 /* This is a short cut for the typical case where the sections are added
12620 to the sections_with_arm_elf_section_data list in forward order and
12621 then looked up here in backwards order. This makes a real difference
12622 to the ld-srec/sec64k.exp linker test. */
12623 entry
= sections_with_arm_elf_section_data
;
12624 if (last_entry
!= NULL
)
12626 if (last_entry
->sec
== sec
)
12627 entry
= last_entry
;
12628 else if (last_entry
->next
!= NULL
12629 && last_entry
->next
->sec
== sec
)
12630 entry
= last_entry
->next
;
12633 for (; entry
; entry
= entry
->next
)
12634 if (entry
->sec
== sec
)
12638 /* Record the entry prior to this one - it is the entry we are most
12639 likely to want to locate next time. Also this way if we have been
12640 called from unrecord_section_with_arm_elf_section_data() we will not
12641 be caching a pointer that is about to be freed. */
12642 last_entry
= entry
->prev
;
12647 static _arm_elf_section_data
*
12648 get_arm_elf_section_data (asection
* sec
)
12650 struct section_list
* entry
;
12652 entry
= find_arm_elf_section_entry (sec
);
12655 return elf32_arm_section_data (entry
->sec
);
12661 unrecord_section_with_arm_elf_section_data (asection
* sec
)
12663 struct section_list
* entry
;
12665 entry
= find_arm_elf_section_entry (sec
);
12669 if (entry
->prev
!= NULL
)
12670 entry
->prev
->next
= entry
->next
;
12671 if (entry
->next
!= NULL
)
12672 entry
->next
->prev
= entry
->prev
;
12673 if (entry
== sections_with_arm_elf_section_data
)
12674 sections_with_arm_elf_section_data
= entry
->next
;
12683 struct bfd_link_info
*info
;
12686 int (*func
) (void *, const char *, Elf_Internal_Sym
*,
12687 asection
*, struct elf_link_hash_entry
*);
12688 } output_arch_syminfo
;
12690 enum map_symbol_type
12698 /* Output a single mapping symbol. */
12701 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
12702 enum map_symbol_type type
,
12705 static const char *names
[3] = {"$a", "$t", "$d"};
12706 struct elf32_arm_link_hash_table
*htab
;
12707 Elf_Internal_Sym sym
;
12709 htab
= elf32_arm_hash_table (osi
->info
);
12710 sym
.st_value
= osi
->sec
->output_section
->vma
12711 + osi
->sec
->output_offset
12715 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
12716 sym
.st_shndx
= osi
->sec_shndx
;
12717 return osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
) == 1;
12721 /* Output mapping symbols for PLT entries associated with H. */
12724 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
12726 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
12727 struct elf32_arm_link_hash_table
*htab
;
12728 struct elf32_arm_link_hash_entry
*eh
;
12731 htab
= elf32_arm_hash_table (osi
->info
);
12733 if (h
->root
.type
== bfd_link_hash_indirect
)
12736 if (h
->root
.type
== bfd_link_hash_warning
)
12737 /* When warning symbols are created, they **replace** the "real"
12738 entry in the hash table, thus we never get to see the real
12739 symbol in a hash traversal. So look at it now. */
12740 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12742 if (h
->plt
.offset
== (bfd_vma
) -1)
12745 eh
= (struct elf32_arm_link_hash_entry
*) h
;
12746 addr
= h
->plt
.offset
;
12747 if (htab
->symbian_p
)
12749 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
12751 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
12754 else if (htab
->vxworks_p
)
12756 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
12758 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
12760 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
12762 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
12767 bfd_signed_vma thumb_refs
;
12769 thumb_refs
= eh
->plt_thumb_refcount
;
12770 if (!htab
->use_blx
)
12771 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
12773 if (thumb_refs
> 0)
12775 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
12778 #ifdef FOUR_WORD_PLT
12779 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
12781 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
12784 /* A three-word PLT with no Thumb thunk contains only Arm code,
12785 so only need to output a mapping symbol for the first PLT entry and
12786 entries with thumb thunks. */
12787 if (thumb_refs
> 0 || addr
== 20)
12789 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
12798 /* Output a single local symbol for a generated stub. */
12801 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
12802 bfd_vma offset
, bfd_vma size
)
12804 struct elf32_arm_link_hash_table
*htab
;
12805 Elf_Internal_Sym sym
;
12807 htab
= elf32_arm_hash_table (osi
->info
);
12808 sym
.st_value
= osi
->sec
->output_section
->vma
12809 + osi
->sec
->output_offset
12811 sym
.st_size
= size
;
12813 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
12814 sym
.st_shndx
= osi
->sec_shndx
;
12815 return osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
) == 1;
12819 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
12822 struct elf32_arm_stub_hash_entry
*stub_entry
;
12823 struct bfd_link_info
*info
;
12824 struct elf32_arm_link_hash_table
*htab
;
12825 asection
*stub_sec
;
12828 output_arch_syminfo
*osi
;
12829 const insn_sequence
*template;
12830 enum stub_insn_type prev_type
;
12833 enum map_symbol_type sym_type
;
12835 /* Massage our args to the form they really have. */
12836 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
12837 osi
= (output_arch_syminfo
*) in_arg
;
12841 htab
= elf32_arm_hash_table (info
);
12842 stub_sec
= stub_entry
->stub_sec
;
12844 /* Ensure this stub is attached to the current section being
12846 if (stub_sec
!= osi
->sec
)
12849 addr
= (bfd_vma
) stub_entry
->stub_offset
;
12850 stub_name
= stub_entry
->output_name
;
12852 template = stub_entry
->stub_template
;
12853 switch (template[0].type
)
12856 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, stub_entry
->stub_size
))
12861 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1,
12862 stub_entry
->stub_size
))
12870 prev_type
= DATA_TYPE
;
12872 for (i
= 0; i
< stub_entry
->stub_template_size
; i
++)
12874 switch (template[i
].type
)
12877 sym_type
= ARM_MAP_ARM
;
12882 sym_type
= ARM_MAP_THUMB
;
12886 sym_type
= ARM_MAP_DATA
;
12894 if (template[i
].type
!= prev_type
)
12896 prev_type
= template[i
].type
;
12897 if (!elf32_arm_output_map_sym (osi
, sym_type
, addr
+ size
))
12901 switch (template[i
].type
)
12925 /* Output mapping symbols for linker generated sections. */
12928 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
12929 struct bfd_link_info
*info
,
12931 int (*func
) (void *, const char *,
12932 Elf_Internal_Sym
*,
12934 struct elf_link_hash_entry
*))
12936 output_arch_syminfo osi
;
12937 struct elf32_arm_link_hash_table
*htab
;
12939 bfd_size_type size
;
12941 htab
= elf32_arm_hash_table (info
);
12942 check_use_blx (htab
);
12948 /* ARM->Thumb glue. */
12949 if (htab
->arm_glue_size
> 0)
12951 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
12952 ARM2THUMB_GLUE_SECTION_NAME
);
12954 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12955 (output_bfd
, osi
.sec
->output_section
);
12956 if (info
->shared
|| htab
->root
.is_relocatable_executable
12957 || htab
->pic_veneer
)
12958 size
= ARM2THUMB_PIC_GLUE_SIZE
;
12959 else if (htab
->use_blx
)
12960 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
12962 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
12964 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
12966 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
12967 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
12971 /* Thumb->ARM glue. */
12972 if (htab
->thumb_glue_size
> 0)
12974 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
12975 THUMB2ARM_GLUE_SECTION_NAME
);
12977 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12978 (output_bfd
, osi
.sec
->output_section
);
12979 size
= THUMB2ARM_GLUE_SIZE
;
12981 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
12983 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
12984 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
12988 /* ARMv4 BX veneers. */
12989 if (htab
->bx_glue_size
> 0)
12991 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
12992 ARM_BX_GLUE_SECTION_NAME
);
12994 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
12995 (output_bfd
, osi
.sec
->output_section
);
12997 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
13000 /* Long calls stubs. */
13001 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
13003 asection
* stub_sec
;
13005 for (stub_sec
= htab
->stub_bfd
->sections
;
13007 stub_sec
= stub_sec
->next
)
13009 /* Ignore non-stub sections. */
13010 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
13013 osi
.sec
= stub_sec
;
13015 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
13016 (output_bfd
, osi
.sec
->output_section
);
13018 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
13022 /* Finally, output mapping symbols for the PLT. */
13023 if (!htab
->splt
|| htab
->splt
->size
== 0)
13026 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
13027 htab
->splt
->output_section
);
13028 osi
.sec
= htab
->splt
;
13029 /* Output mapping symbols for the plt header. SymbianOS does not have a
13031 if (htab
->vxworks_p
)
13033 /* VxWorks shared libraries have no PLT header. */
13036 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
13038 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
13042 else if (!htab
->symbian_p
)
13044 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
13046 #ifndef FOUR_WORD_PLT
13047 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
13052 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, (void *) &osi
);
13056 /* Allocate target specific section data. */
13059 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
13061 if (!sec
->used_by_bfd
)
13063 _arm_elf_section_data
*sdata
;
13064 bfd_size_type amt
= sizeof (*sdata
);
13066 sdata
= bfd_zalloc (abfd
, amt
);
13069 sec
->used_by_bfd
= sdata
;
13072 record_section_with_arm_elf_section_data (sec
);
13074 return _bfd_elf_new_section_hook (abfd
, sec
);
13078 /* Used to order a list of mapping symbols by address. */
13081 elf32_arm_compare_mapping (const void * a
, const void * b
)
13083 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
13084 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
13086 if (amap
->vma
> bmap
->vma
)
13088 else if (amap
->vma
< bmap
->vma
)
13090 else if (amap
->type
> bmap
->type
)
13091 /* Ensure results do not depend on the host qsort for objects with
13092 multiple mapping symbols at the same address by sorting on type
13095 else if (amap
->type
< bmap
->type
)
13101 /* Add OFFSET to lower 31 bits of ADDR, leaving other bits unmodified. */
13103 static unsigned long
13104 offset_prel31 (unsigned long addr
, bfd_vma offset
)
13106 return (addr
& ~0x7ffffffful
) | ((addr
+ offset
) & 0x7ffffffful
);
13109 /* Copy an .ARM.exidx table entry, adding OFFSET to (applied) PREL31
13113 copy_exidx_entry (bfd
*output_bfd
, bfd_byte
*to
, bfd_byte
*from
, bfd_vma offset
)
13115 unsigned long first_word
= bfd_get_32 (output_bfd
, from
);
13116 unsigned long second_word
= bfd_get_32 (output_bfd
, from
+ 4);
13118 /* High bit of first word is supposed to be zero. */
13119 if ((first_word
& 0x80000000ul
) == 0)
13120 first_word
= offset_prel31 (first_word
, offset
);
13122 /* If the high bit of the first word is clear, and the bit pattern is not 0x1
13123 (EXIDX_CANTUNWIND), this is an offset to an .ARM.extab entry. */
13124 if ((second_word
!= 0x1) && ((second_word
& 0x80000000ul
) == 0))
13125 second_word
= offset_prel31 (second_word
, offset
);
13127 bfd_put_32 (output_bfd
, first_word
, to
);
13128 bfd_put_32 (output_bfd
, second_word
, to
+ 4);
13131 /* Data for make_branch_to_a8_stub(). */
13133 struct a8_branch_to_stub_data
{
13134 asection
*writing_section
;
13135 bfd_byte
*contents
;
13139 /* Helper to insert branches to Cortex-A8 erratum stubs in the right
13140 places for a particular section. */
13143 make_branch_to_a8_stub (struct bfd_hash_entry
*gen_entry
,
13146 struct elf32_arm_stub_hash_entry
*stub_entry
;
13147 struct a8_branch_to_stub_data
*data
;
13148 bfd_byte
*contents
;
13149 unsigned long branch_insn
;
13150 bfd_vma veneered_insn_loc
, veneer_entry_loc
;
13151 bfd_signed_vma branch_offset
;
13153 unsigned int index
;
13155 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
13156 data
= (struct a8_branch_to_stub_data
*) in_arg
;
13158 if (stub_entry
->target_section
!= data
->writing_section
13159 || stub_entry
->stub_type
< arm_stub_a8_veneer_b_cond
)
13162 contents
= data
->contents
;
13164 veneered_insn_loc
= stub_entry
->target_section
->output_section
->vma
13165 + stub_entry
->target_section
->output_offset
13166 + stub_entry
->target_value
;
13168 veneer_entry_loc
= stub_entry
->stub_sec
->output_section
->vma
13169 + stub_entry
->stub_sec
->output_offset
13170 + stub_entry
->stub_offset
;
13172 if (stub_entry
->stub_type
== arm_stub_a8_veneer_blx
)
13173 veneered_insn_loc
&= ~3u;
13175 branch_offset
= veneer_entry_loc
- veneered_insn_loc
- 4;
13177 abfd
= stub_entry
->target_section
->owner
;
13178 index
= stub_entry
->target_value
;
13180 /* We attempt to avoid this condition by setting stubs_always_after_branch
13181 in elf32_arm_size_stubs if we've enabled the Cortex-A8 erratum workaround.
13182 This check is just to be on the safe side... */
13183 if ((veneered_insn_loc
& ~0xfff) == (veneer_entry_loc
& ~0xfff))
13185 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub is "
13186 "allocated in unsafe location"), abfd
);
13190 switch (stub_entry
->stub_type
)
13192 case arm_stub_a8_veneer_b
:
13193 case arm_stub_a8_veneer_b_cond
:
13194 branch_insn
= 0xf0009000;
13197 case arm_stub_a8_veneer_blx
:
13198 branch_insn
= 0xf000e800;
13201 case arm_stub_a8_veneer_bl
:
13203 unsigned int i1
, j1
, i2
, j2
, s
;
13205 branch_insn
= 0xf000d000;
13208 if (branch_offset
< -16777216 || branch_offset
> 16777214)
13210 /* There's not much we can do apart from complain if this
13212 (*_bfd_error_handler
) (_("%B: error: Cortex-A8 erratum stub out "
13213 "of range (input file too large)"), abfd
);
13217 /* i1 = not(j1 eor s), so:
13219 j1 = (not i1) eor s. */
13221 branch_insn
|= (branch_offset
>> 1) & 0x7ff;
13222 branch_insn
|= ((branch_offset
>> 12) & 0x3ff) << 16;
13223 i2
= (branch_offset
>> 22) & 1;
13224 i1
= (branch_offset
>> 23) & 1;
13225 s
= (branch_offset
>> 24) & 1;
13228 branch_insn
|= j2
<< 11;
13229 branch_insn
|= j1
<< 13;
13230 branch_insn
|= s
<< 26;
13239 bfd_put_16 (abfd
, (branch_insn
>> 16) & 0xffff, &contents
[index
]);
13240 bfd_put_16 (abfd
, branch_insn
& 0xffff, &contents
[index
+ 2]);
13245 /* Do code byteswapping. Return FALSE afterwards so that the section is
13246 written out as normal. */
13249 elf32_arm_write_section (bfd
*output_bfd
,
13250 struct bfd_link_info
*link_info
,
13252 bfd_byte
*contents
)
13254 unsigned int mapcount
, errcount
;
13255 _arm_elf_section_data
*arm_data
;
13256 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
13257 elf32_arm_section_map
*map
;
13258 elf32_vfp11_erratum_list
*errnode
;
13261 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
13265 /* If this section has not been allocated an _arm_elf_section_data
13266 structure then we cannot record anything. */
13267 arm_data
= get_arm_elf_section_data (sec
);
13268 if (arm_data
== NULL
)
13271 mapcount
= arm_data
->mapcount
;
13272 map
= arm_data
->map
;
13273 errcount
= arm_data
->erratumcount
;
13277 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
13279 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
13280 errnode
= errnode
->next
)
13282 bfd_vma index
= errnode
->vma
- offset
;
13284 switch (errnode
->type
)
13286 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
13288 bfd_vma branch_to_veneer
;
13289 /* Original condition code of instruction, plus bit mask for
13290 ARM B instruction. */
13291 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
13294 /* The instruction is before the label. */
13297 /* Above offset included in -4 below. */
13298 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
13299 - errnode
->vma
- 4;
13301 if ((signed) branch_to_veneer
< -(1 << 25)
13302 || (signed) branch_to_veneer
>= (1 << 25))
13303 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
13304 "range"), output_bfd
);
13306 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
13307 contents
[endianflip
^ index
] = insn
& 0xff;
13308 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
13309 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
13310 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
13314 case VFP11_ERRATUM_ARM_VENEER
:
13316 bfd_vma branch_from_veneer
;
13319 /* Take size of veneer into account. */
13320 branch_from_veneer
= errnode
->u
.v
.branch
->vma
13321 - errnode
->vma
- 12;
13323 if ((signed) branch_from_veneer
< -(1 << 25)
13324 || (signed) branch_from_veneer
>= (1 << 25))
13325 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
13326 "range"), output_bfd
);
13328 /* Original instruction. */
13329 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
13330 contents
[endianflip
^ index
] = insn
& 0xff;
13331 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
13332 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
13333 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
13335 /* Branch back to insn after original insn. */
13336 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
13337 contents
[endianflip
^ (index
+ 4)] = insn
& 0xff;
13338 contents
[endianflip
^ (index
+ 5)] = (insn
>> 8) & 0xff;
13339 contents
[endianflip
^ (index
+ 6)] = (insn
>> 16) & 0xff;
13340 contents
[endianflip
^ (index
+ 7)] = (insn
>> 24) & 0xff;
13350 if (arm_data
->elf
.this_hdr
.sh_type
== SHT_ARM_EXIDX
)
13352 arm_unwind_table_edit
*edit_node
13353 = arm_data
->u
.exidx
.unwind_edit_list
;
13354 /* Now, sec->size is the size of the section we will write. The original
13355 size (before we merged duplicate entries and inserted EXIDX_CANTUNWIND
13356 markers) was sec->rawsize. (This isn't the case if we perform no
13357 edits, then rawsize will be zero and we should use size). */
13358 bfd_byte
*edited_contents
= bfd_malloc (sec
->size
);
13359 unsigned int input_size
= sec
->rawsize
? sec
->rawsize
: sec
->size
;
13360 unsigned int in_index
, out_index
;
13361 bfd_vma add_to_offsets
= 0;
13363 for (in_index
= 0, out_index
= 0; in_index
* 8 < input_size
|| edit_node
;)
13367 unsigned int edit_index
= edit_node
->index
;
13369 if (in_index
< edit_index
&& in_index
* 8 < input_size
)
13371 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
13372 contents
+ in_index
* 8, add_to_offsets
);
13376 else if (in_index
== edit_index
13377 || (in_index
* 8 >= input_size
13378 && edit_index
== UINT_MAX
))
13380 switch (edit_node
->type
)
13382 case DELETE_EXIDX_ENTRY
:
13384 add_to_offsets
+= 8;
13387 case INSERT_EXIDX_CANTUNWIND_AT_END
:
13389 asection
*text_sec
= edit_node
->linked_section
;
13390 bfd_vma text_offset
= text_sec
->output_section
->vma
13391 + text_sec
->output_offset
13393 bfd_vma exidx_offset
= offset
+ out_index
* 8;
13394 unsigned long prel31_offset
;
13396 /* Note: this is meant to be equivalent to an
13397 R_ARM_PREL31 relocation. These synthetic
13398 EXIDX_CANTUNWIND markers are not relocated by the
13399 usual BFD method. */
13400 prel31_offset
= (text_offset
- exidx_offset
)
13403 /* First address we can't unwind. */
13404 bfd_put_32 (output_bfd
, prel31_offset
,
13405 &edited_contents
[out_index
* 8]);
13407 /* Code for EXIDX_CANTUNWIND. */
13408 bfd_put_32 (output_bfd
, 0x1,
13409 &edited_contents
[out_index
* 8 + 4]);
13412 add_to_offsets
-= 8;
13417 edit_node
= edit_node
->next
;
13422 /* No more edits, copy remaining entries verbatim. */
13423 copy_exidx_entry (output_bfd
, edited_contents
+ out_index
* 8,
13424 contents
+ in_index
* 8, add_to_offsets
);
13430 if (!(sec
->flags
& SEC_EXCLUDE
) && !(sec
->flags
& SEC_NEVER_LOAD
))
13431 bfd_set_section_contents (output_bfd
, sec
->output_section
,
13433 (file_ptr
) sec
->output_offset
, sec
->size
);
13438 /* Fix code to point to Cortex-A8 erratum stubs. */
13439 if (globals
->fix_cortex_a8
)
13441 struct a8_branch_to_stub_data data
;
13443 data
.writing_section
= sec
;
13444 data
.contents
= contents
;
13446 bfd_hash_traverse (&globals
->stub_hash_table
, make_branch_to_a8_stub
,
13453 if (globals
->byteswap_code
)
13455 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
13458 for (i
= 0; i
< mapcount
; i
++)
13460 if (i
== mapcount
- 1)
13463 end
= map
[i
+ 1].vma
;
13465 switch (map
[i
].type
)
13468 /* Byte swap code words. */
13469 while (ptr
+ 3 < end
)
13471 tmp
= contents
[ptr
];
13472 contents
[ptr
] = contents
[ptr
+ 3];
13473 contents
[ptr
+ 3] = tmp
;
13474 tmp
= contents
[ptr
+ 1];
13475 contents
[ptr
+ 1] = contents
[ptr
+ 2];
13476 contents
[ptr
+ 2] = tmp
;
13482 /* Byte swap code halfwords. */
13483 while (ptr
+ 1 < end
)
13485 tmp
= contents
[ptr
];
13486 contents
[ptr
] = contents
[ptr
+ 1];
13487 contents
[ptr
+ 1] = tmp
;
13493 /* Leave data alone. */
13501 arm_data
->mapcount
= 0;
13502 arm_data
->mapsize
= 0;
13503 arm_data
->map
= NULL
;
13504 unrecord_section_with_arm_elf_section_data (sec
);
13510 unrecord_section_via_map_over_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
13512 void * ignore ATTRIBUTE_UNUSED
)
13514 unrecord_section_with_arm_elf_section_data (sec
);
13518 elf32_arm_close_and_cleanup (bfd
* abfd
)
13520 if (abfd
->sections
)
13521 bfd_map_over_sections (abfd
,
13522 unrecord_section_via_map_over_sections
,
13525 return _bfd_elf_close_and_cleanup (abfd
);
13529 elf32_arm_bfd_free_cached_info (bfd
* abfd
)
13531 if (abfd
->sections
)
13532 bfd_map_over_sections (abfd
,
13533 unrecord_section_via_map_over_sections
,
13536 return _bfd_free_cached_info (abfd
);
13539 /* Display STT_ARM_TFUNC symbols as functions. */
13542 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
13545 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
13547 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
13548 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
13552 /* Mangle thumb function symbols as we read them in. */
13555 elf32_arm_swap_symbol_in (bfd
* abfd
,
13558 Elf_Internal_Sym
*dst
)
13560 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
13563 /* New EABI objects mark thumb function symbols by setting the low bit of
13564 the address. Turn these into STT_ARM_TFUNC. */
13565 if ((ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
)
13566 && (dst
->st_value
& 1))
13568 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
13569 dst
->st_value
&= ~(bfd_vma
) 1;
13575 /* Mangle thumb function symbols as we write them out. */
13578 elf32_arm_swap_symbol_out (bfd
*abfd
,
13579 const Elf_Internal_Sym
*src
,
13583 Elf_Internal_Sym newsym
;
13585 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
13586 of the address set, as per the new EABI. We do this unconditionally
13587 because objcopy does not set the elf header flags until after
13588 it writes out the symbol table. */
13589 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
13592 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
13593 if (newsym
.st_shndx
!= SHN_UNDEF
)
13595 /* Do this only for defined symbols. At link type, the static
13596 linker will simulate the work of dynamic linker of resolving
13597 symbols and will carry over the thumbness of found symbols to
13598 the output symbol table. It's not clear how it happens, but
13599 the thumbness of undefined symbols can well be different at
13600 runtime, and writing '1' for them will be confusing for users
13601 and possibly for dynamic linker itself.
13603 newsym
.st_value
|= 1;
13608 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
13611 /* Add the PT_ARM_EXIDX program header. */
13614 elf32_arm_modify_segment_map (bfd
*abfd
,
13615 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
13617 struct elf_segment_map
*m
;
13620 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
13621 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
13623 /* If there is already a PT_ARM_EXIDX header, then we do not
13624 want to add another one. This situation arises when running
13625 "strip"; the input binary already has the header. */
13626 m
= elf_tdata (abfd
)->segment_map
;
13627 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
13631 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
13634 m
->p_type
= PT_ARM_EXIDX
;
13636 m
->sections
[0] = sec
;
13638 m
->next
= elf_tdata (abfd
)->segment_map
;
13639 elf_tdata (abfd
)->segment_map
= m
;
13646 /* We may add a PT_ARM_EXIDX program header. */
13649 elf32_arm_additional_program_headers (bfd
*abfd
,
13650 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
13654 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
13655 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
13661 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
13664 elf32_arm_is_function_type (unsigned int type
)
13666 return (type
== STT_FUNC
) || (type
== STT_ARM_TFUNC
);
13669 /* We use this to override swap_symbol_in and swap_symbol_out. */
13670 const struct elf_size_info elf32_arm_size_info
=
13672 sizeof (Elf32_External_Ehdr
),
13673 sizeof (Elf32_External_Phdr
),
13674 sizeof (Elf32_External_Shdr
),
13675 sizeof (Elf32_External_Rel
),
13676 sizeof (Elf32_External_Rela
),
13677 sizeof (Elf32_External_Sym
),
13678 sizeof (Elf32_External_Dyn
),
13679 sizeof (Elf_External_Note
),
13683 ELFCLASS32
, EV_CURRENT
,
13684 bfd_elf32_write_out_phdrs
,
13685 bfd_elf32_write_shdrs_and_ehdr
,
13686 bfd_elf32_checksum_contents
,
13687 bfd_elf32_write_relocs
,
13688 elf32_arm_swap_symbol_in
,
13689 elf32_arm_swap_symbol_out
,
13690 bfd_elf32_slurp_reloc_table
,
13691 bfd_elf32_slurp_symbol_table
,
13692 bfd_elf32_swap_dyn_in
,
13693 bfd_elf32_swap_dyn_out
,
13694 bfd_elf32_swap_reloc_in
,
13695 bfd_elf32_swap_reloc_out
,
13696 bfd_elf32_swap_reloca_in
,
13697 bfd_elf32_swap_reloca_out
13700 #define ELF_ARCH bfd_arch_arm
13701 #define ELF_MACHINE_CODE EM_ARM
13702 #ifdef __QNXTARGET__
13703 #define ELF_MAXPAGESIZE 0x1000
13705 #define ELF_MAXPAGESIZE 0x8000
13707 #define ELF_MINPAGESIZE 0x1000
13708 #define ELF_COMMONPAGESIZE 0x1000
13710 #define bfd_elf32_mkobject elf32_arm_mkobject
13712 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
13713 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
13714 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
13715 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
13716 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
13717 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
13718 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
13719 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
13720 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
13721 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
13722 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
13723 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
13724 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
13725 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
13726 #define bfd_elf32_bfd_final_link elf32_arm_final_link
13728 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
13729 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
13730 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
13731 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
13732 #define elf_backend_check_relocs elf32_arm_check_relocs
13733 #define elf_backend_relocate_section elf32_arm_relocate_section
13734 #define elf_backend_write_section elf32_arm_write_section
13735 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
13736 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
13737 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
13738 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
13739 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
13740 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
13741 #define elf_backend_post_process_headers elf32_arm_post_process_headers
13742 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
13743 #define elf_backend_object_p elf32_arm_object_p
13744 #define elf_backend_section_flags elf32_arm_section_flags
13745 #define elf_backend_fake_sections elf32_arm_fake_sections
13746 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
13747 #define elf_backend_final_write_processing elf32_arm_final_write_processing
13748 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
13749 #define elf_backend_symbol_processing elf32_arm_symbol_processing
13750 #define elf_backend_size_info elf32_arm_size_info
13751 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
13752 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
13753 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
13754 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
13755 #define elf_backend_is_function_type elf32_arm_is_function_type
13757 #define elf_backend_can_refcount 1
13758 #define elf_backend_can_gc_sections 1
13759 #define elf_backend_plt_readonly 1
13760 #define elf_backend_want_got_plt 1
13761 #define elf_backend_want_plt_sym 0
13762 #define elf_backend_may_use_rel_p 1
13763 #define elf_backend_may_use_rela_p 0
13764 #define elf_backend_default_use_rela_p 0
13766 #define elf_backend_got_header_size 12
13768 #undef elf_backend_obj_attrs_vendor
13769 #define elf_backend_obj_attrs_vendor "aeabi"
13770 #undef elf_backend_obj_attrs_section
13771 #define elf_backend_obj_attrs_section ".ARM.attributes"
13772 #undef elf_backend_obj_attrs_arg_type
13773 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
13774 #undef elf_backend_obj_attrs_section_type
13775 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
13776 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
13778 #include "elf32-target.h"
13780 /* VxWorks Targets. */
13782 #undef TARGET_LITTLE_SYM
13783 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
13784 #undef TARGET_LITTLE_NAME
13785 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
13786 #undef TARGET_BIG_SYM
13787 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
13788 #undef TARGET_BIG_NAME
13789 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
13791 /* Like elf32_arm_link_hash_table_create -- but overrides
13792 appropriately for VxWorks. */
13794 static struct bfd_link_hash_table
*
13795 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
13797 struct bfd_link_hash_table
*ret
;
13799 ret
= elf32_arm_link_hash_table_create (abfd
);
13802 struct elf32_arm_link_hash_table
*htab
13803 = (struct elf32_arm_link_hash_table
*) ret
;
13805 htab
->vxworks_p
= 1;
13811 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
13813 elf32_arm_final_write_processing (abfd
, linker
);
13814 elf_vxworks_final_write_processing (abfd
, linker
);
13818 #define elf32_bed elf32_arm_vxworks_bed
13820 #undef bfd_elf32_bfd_link_hash_table_create
13821 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
13822 #undef elf_backend_add_symbol_hook
13823 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
13824 #undef elf_backend_final_write_processing
13825 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
13826 #undef elf_backend_emit_relocs
13827 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
13829 #undef elf_backend_may_use_rel_p
13830 #define elf_backend_may_use_rel_p 0
13831 #undef elf_backend_may_use_rela_p
13832 #define elf_backend_may_use_rela_p 1
13833 #undef elf_backend_default_use_rela_p
13834 #define elf_backend_default_use_rela_p 1
13835 #undef elf_backend_want_plt_sym
13836 #define elf_backend_want_plt_sym 1
13837 #undef ELF_MAXPAGESIZE
13838 #define ELF_MAXPAGESIZE 0x1000
13840 #include "elf32-target.h"
13843 /* Symbian OS Targets. */
13845 #undef TARGET_LITTLE_SYM
13846 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
13847 #undef TARGET_LITTLE_NAME
13848 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
13849 #undef TARGET_BIG_SYM
13850 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
13851 #undef TARGET_BIG_NAME
13852 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
13854 /* Like elf32_arm_link_hash_table_create -- but overrides
13855 appropriately for Symbian OS. */
13857 static struct bfd_link_hash_table
*
13858 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
13860 struct bfd_link_hash_table
*ret
;
13862 ret
= elf32_arm_link_hash_table_create (abfd
);
13865 struct elf32_arm_link_hash_table
*htab
13866 = (struct elf32_arm_link_hash_table
*)ret
;
13867 /* There is no PLT header for Symbian OS. */
13868 htab
->plt_header_size
= 0;
13869 /* The PLT entries are each one instruction and one word. */
13870 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
13871 htab
->symbian_p
= 1;
13872 /* Symbian uses armv5t or above, so use_blx is always true. */
13874 htab
->root
.is_relocatable_executable
= 1;
13879 static const struct bfd_elf_special_section
13880 elf32_arm_symbian_special_sections
[] =
13882 /* In a BPABI executable, the dynamic linking sections do not go in
13883 the loadable read-only segment. The post-linker may wish to
13884 refer to these sections, but they are not part of the final
13886 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
13887 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
13888 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
13889 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
13890 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
13891 /* These sections do not need to be writable as the SymbianOS
13892 postlinker will arrange things so that no dynamic relocation is
13894 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
13895 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
13896 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
13897 { NULL
, 0, 0, 0, 0 }
13901 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
13902 struct bfd_link_info
*link_info
)
13904 /* BPABI objects are never loaded directly by an OS kernel; they are
13905 processed by a postlinker first, into an OS-specific format. If
13906 the D_PAGED bit is set on the file, BFD will align segments on
13907 page boundaries, so that an OS can directly map the file. With
13908 BPABI objects, that just results in wasted space. In addition,
13909 because we clear the D_PAGED bit, map_sections_to_segments will
13910 recognize that the program headers should not be mapped into any
13911 loadable segment. */
13912 abfd
->flags
&= ~D_PAGED
;
13913 elf32_arm_begin_write_processing (abfd
, link_info
);
13917 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
13918 struct bfd_link_info
*info
)
13920 struct elf_segment_map
*m
;
13923 /* BPABI shared libraries and executables should have a PT_DYNAMIC
13924 segment. However, because the .dynamic section is not marked
13925 with SEC_LOAD, the generic ELF code will not create such a
13927 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
13930 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
13931 if (m
->p_type
== PT_DYNAMIC
)
13936 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
13937 m
->next
= elf_tdata (abfd
)->segment_map
;
13938 elf_tdata (abfd
)->segment_map
= m
;
13942 /* Also call the generic arm routine. */
13943 return elf32_arm_modify_segment_map (abfd
, info
);
13946 /* Return address for Ith PLT stub in section PLT, for relocation REL
13947 or (bfd_vma) -1 if it should not be included. */
13950 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
13951 const arelent
*rel ATTRIBUTE_UNUSED
)
13953 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
13958 #define elf32_bed elf32_arm_symbian_bed
13960 /* The dynamic sections are not allocated on SymbianOS; the postlinker
13961 will process them and then discard them. */
13962 #undef ELF_DYNAMIC_SEC_FLAGS
13963 #define ELF_DYNAMIC_SEC_FLAGS \
13964 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
13966 #undef elf_backend_add_symbol_hook
13967 #undef elf_backend_emit_relocs
13969 #undef bfd_elf32_bfd_link_hash_table_create
13970 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
13971 #undef elf_backend_special_sections
13972 #define elf_backend_special_sections elf32_arm_symbian_special_sections
13973 #undef elf_backend_begin_write_processing
13974 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
13975 #undef elf_backend_final_write_processing
13976 #define elf_backend_final_write_processing elf32_arm_final_write_processing
13978 #undef elf_backend_modify_segment_map
13979 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
13981 /* There is no .got section for BPABI objects, and hence no header. */
13982 #undef elf_backend_got_header_size
13983 #define elf_backend_got_header_size 0
13985 /* Similarly, there is no .got.plt section. */
13986 #undef elf_backend_want_got_plt
13987 #define elf_backend_want_got_plt 0
13989 #undef elf_backend_plt_sym_val
13990 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
13992 #undef elf_backend_may_use_rel_p
13993 #define elf_backend_may_use_rel_p 1
13994 #undef elf_backend_may_use_rela_p
13995 #define elf_backend_may_use_rela_p 0
13996 #undef elf_backend_default_use_rela_p
13997 #define elf_backend_default_use_rela_p 0
13998 #undef elf_backend_want_plt_sym
13999 #define elf_backend_want_plt_sym 0
14000 #undef ELF_MAXPAGESIZE
14001 #define ELF_MAXPAGESIZE 0x8000
14003 #include "elf32-target.h"