1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
24 #include "libiberty.h"
27 #include "elf-vxworks.h"
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
62 static struct elf_backend_data elf32_arm_vxworks_bed
;
64 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
68 static reloc_howto_type elf32_arm_howto_table_1
[] =
71 HOWTO (R_ARM_NONE
, /* type */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
75 FALSE
, /* pc_relative */
77 complain_overflow_dont
,/* complain_on_overflow */
78 bfd_elf_generic_reloc
, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE
, /* partial_inplace */
83 FALSE
), /* pcrel_offset */
85 HOWTO (R_ARM_PC24
, /* type */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
89 TRUE
, /* pc_relative */
91 complain_overflow_signed
,/* complain_on_overflow */
92 bfd_elf_generic_reloc
, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE
, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE
), /* pcrel_offset */
100 HOWTO (R_ARM_ABS32
, /* type */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE
, /* pc_relative */
106 complain_overflow_bitfield
,/* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE
, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32
, /* type */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
119 TRUE
, /* pc_relative */
121 complain_overflow_bitfield
,/* complain_on_overflow */
122 bfd_elf_generic_reloc
, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE
, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE
), /* pcrel_offset */
129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
130 HOWTO (R_ARM_LDR_PC_G0
, /* type */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
134 TRUE
, /* pc_relative */
136 complain_overflow_dont
,/* complain_on_overflow */
137 bfd_elf_generic_reloc
, /* special_function */
138 "R_ARM_LDR_PC_G0", /* name */
139 FALSE
, /* partial_inplace */
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE
), /* pcrel_offset */
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16
, /* type */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
149 FALSE
, /* pc_relative */
151 complain_overflow_bitfield
,/* complain_on_overflow */
152 bfd_elf_generic_reloc
, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE
, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE
), /* pcrel_offset */
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12
, /* type */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
164 FALSE
, /* pc_relative */
166 complain_overflow_bitfield
,/* complain_on_overflow */
167 bfd_elf_generic_reloc
, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE
, /* partial_inplace */
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
172 FALSE
), /* pcrel_offset */
174 HOWTO (R_ARM_THM_ABS5
, /* type */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE
, /* pc_relative */
180 complain_overflow_bitfield
,/* complain_on_overflow */
181 bfd_elf_generic_reloc
, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE
, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE
), /* pcrel_offset */
189 HOWTO (R_ARM_ABS8
, /* type */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
193 FALSE
, /* pc_relative */
195 complain_overflow_bitfield
,/* complain_on_overflow */
196 bfd_elf_generic_reloc
, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE
, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE
), /* pcrel_offset */
203 HOWTO (R_ARM_SBREL32
, /* type */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
207 FALSE
, /* pc_relative */
209 complain_overflow_dont
,/* complain_on_overflow */
210 bfd_elf_generic_reloc
, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE
, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE
), /* pcrel_offset */
217 HOWTO (R_ARM_THM_CALL
, /* type */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
221 TRUE
, /* pc_relative */
223 complain_overflow_signed
,/* complain_on_overflow */
224 bfd_elf_generic_reloc
, /* special_function */
225 "R_ARM_THM_CALL", /* name */
226 FALSE
, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE
), /* pcrel_offset */
231 HOWTO (R_ARM_THM_PC8
, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 TRUE
, /* pc_relative */
237 complain_overflow_signed
,/* complain_on_overflow */
238 bfd_elf_generic_reloc
, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE
, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE
), /* pcrel_offset */
245 HOWTO (R_ARM_BREL_ADJ
, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 FALSE
, /* pc_relative */
251 complain_overflow_signed
,/* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_ARM_BREL_ADJ", /* name */
254 FALSE
, /* partial_inplace */
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE
), /* pcrel_offset */
259 HOWTO (R_ARM_SWI24
, /* type */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE
, /* pc_relative */
265 complain_overflow_signed
,/* complain_on_overflow */
266 bfd_elf_generic_reloc
, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE
, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE
), /* pcrel_offset */
273 HOWTO (R_ARM_THM_SWI8
, /* type */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
277 FALSE
, /* pc_relative */
279 complain_overflow_signed
,/* complain_on_overflow */
280 bfd_elf_generic_reloc
, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE
, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE
), /* pcrel_offset */
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25
, /* type */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
292 TRUE
, /* pc_relative */
294 complain_overflow_signed
,/* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE
, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE
), /* pcrel_offset */
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 TRUE
, /* pc_relative */
309 complain_overflow_signed
,/* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE
, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE
), /* pcrel_offset */
317 /* Dynamic TLS relocations. */
319 HOWTO (R_ARM_TLS_DTPMOD32
, /* type */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
323 FALSE
, /* pc_relative */
325 complain_overflow_bitfield
,/* complain_on_overflow */
326 bfd_elf_generic_reloc
, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE
, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE
), /* pcrel_offset */
333 HOWTO (R_ARM_TLS_DTPOFF32
, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 FALSE
, /* pc_relative */
339 complain_overflow_bitfield
,/* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE
, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE
), /* pcrel_offset */
347 HOWTO (R_ARM_TLS_TPOFF32
, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 FALSE
, /* pc_relative */
353 complain_overflow_bitfield
,/* complain_on_overflow */
354 bfd_elf_generic_reloc
, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE
, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE
), /* pcrel_offset */
361 /* Relocs used in ARM Linux */
363 HOWTO (R_ARM_COPY
, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 FALSE
, /* pc_relative */
369 complain_overflow_bitfield
,/* complain_on_overflow */
370 bfd_elf_generic_reloc
, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE
, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE
), /* pcrel_offset */
377 HOWTO (R_ARM_GLOB_DAT
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 FALSE
, /* pc_relative */
383 complain_overflow_bitfield
,/* complain_on_overflow */
384 bfd_elf_generic_reloc
, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE
, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE
), /* pcrel_offset */
391 HOWTO (R_ARM_JUMP_SLOT
, /* type */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
395 FALSE
, /* pc_relative */
397 complain_overflow_bitfield
,/* complain_on_overflow */
398 bfd_elf_generic_reloc
, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE
, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE
), /* pcrel_offset */
405 HOWTO (R_ARM_RELATIVE
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 FALSE
, /* pc_relative */
411 complain_overflow_bitfield
,/* complain_on_overflow */
412 bfd_elf_generic_reloc
, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE
, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE
), /* pcrel_offset */
419 HOWTO (R_ARM_GOTOFF32
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE
, /* pc_relative */
425 complain_overflow_bitfield
,/* complain_on_overflow */
426 bfd_elf_generic_reloc
, /* special_function */
427 "R_ARM_GOTOFF32", /* name */
428 TRUE
, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE
), /* pcrel_offset */
433 HOWTO (R_ARM_GOTPC
, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE
, /* pc_relative */
439 complain_overflow_bitfield
,/* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE
, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE
), /* pcrel_offset */
447 HOWTO (R_ARM_GOT32
, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 FALSE
, /* pc_relative */
453 complain_overflow_bitfield
,/* complain_on_overflow */
454 bfd_elf_generic_reloc
, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE
, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE
), /* pcrel_offset */
461 HOWTO (R_ARM_PLT32
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 TRUE
, /* pc_relative */
467 complain_overflow_bitfield
,/* complain_on_overflow */
468 bfd_elf_generic_reloc
, /* special_function */
469 "R_ARM_PLT32", /* name */
470 FALSE
, /* partial_inplace */
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE
), /* pcrel_offset */
475 HOWTO (R_ARM_CALL
, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 TRUE
, /* pc_relative */
481 complain_overflow_signed
,/* complain_on_overflow */
482 bfd_elf_generic_reloc
, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE
, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE
), /* pcrel_offset */
489 HOWTO (R_ARM_JUMP24
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 TRUE
, /* pc_relative */
495 complain_overflow_signed
,/* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE
, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE
), /* pcrel_offset */
503 HOWTO (R_ARM_THM_JUMP24
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 TRUE
, /* pc_relative */
509 complain_overflow_signed
,/* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_ARM_THM_JUMP24", /* name */
512 FALSE
, /* partial_inplace */
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE
), /* pcrel_offset */
517 HOWTO (R_ARM_BASE_ABS
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 FALSE
, /* pc_relative */
523 complain_overflow_dont
,/* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_ARM_BASE_ABS", /* name */
526 FALSE
, /* partial_inplace */
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
529 FALSE
), /* pcrel_offset */
531 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 TRUE
, /* pc_relative */
537 complain_overflow_dont
,/* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE
, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE
), /* pcrel_offset */
545 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 TRUE
, /* pc_relative */
551 complain_overflow_dont
,/* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE
, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE
), /* pcrel_offset */
559 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 TRUE
, /* pc_relative */
565 complain_overflow_dont
,/* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE
, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE
), /* pcrel_offset */
573 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_dont
,/* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE
, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE
), /* pcrel_offset */
587 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
591 FALSE
, /* pc_relative */
593 complain_overflow_dont
,/* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE
, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE
), /* pcrel_offset */
601 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
605 FALSE
, /* pc_relative */
607 complain_overflow_dont
,/* complain_on_overflow */
608 bfd_elf_generic_reloc
, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE
, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE
), /* pcrel_offset */
615 HOWTO (R_ARM_TARGET1
, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 FALSE
, /* pc_relative */
621 complain_overflow_dont
,/* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE
, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE
), /* pcrel_offset */
629 HOWTO (R_ARM_ROSEGREL32
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 FALSE
, /* pc_relative */
635 complain_overflow_dont
,/* complain_on_overflow */
636 bfd_elf_generic_reloc
, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE
, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE
), /* pcrel_offset */
643 HOWTO (R_ARM_V4BX
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_dont
,/* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE
, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 HOWTO (R_ARM_TARGET2
, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE
, /* pc_relative */
663 complain_overflow_signed
,/* complain_on_overflow */
664 bfd_elf_generic_reloc
, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE
, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE
), /* pcrel_offset */
671 HOWTO (R_ARM_PREL31
, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 TRUE
, /* pc_relative */
677 complain_overflow_signed
,/* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE
, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE
), /* pcrel_offset */
685 HOWTO (R_ARM_MOVW_ABS_NC
, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE
, /* pc_relative */
691 complain_overflow_dont
,/* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE
, /* partial_inplace */
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
697 FALSE
), /* pcrel_offset */
699 HOWTO (R_ARM_MOVT_ABS
, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 FALSE
, /* pc_relative */
705 complain_overflow_bitfield
,/* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE
, /* partial_inplace */
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
711 FALSE
), /* pcrel_offset */
713 HOWTO (R_ARM_MOVW_PREL_NC
, /* type */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
717 TRUE
, /* pc_relative */
719 complain_overflow_dont
,/* complain_on_overflow */
720 bfd_elf_generic_reloc
, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE
, /* partial_inplace */
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
725 TRUE
), /* pcrel_offset */
727 HOWTO (R_ARM_MOVT_PREL
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 TRUE
, /* pc_relative */
733 complain_overflow_bitfield
,/* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE
, /* partial_inplace */
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
739 TRUE
), /* pcrel_offset */
741 HOWTO (R_ARM_THM_MOVW_ABS_NC
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_dont
,/* complain_on_overflow */
748 bfd_elf_generic_reloc
, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE
, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE
), /* pcrel_offset */
755 HOWTO (R_ARM_THM_MOVT_ABS
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_bitfield
,/* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE
, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 HOWTO (R_ARM_THM_MOVW_PREL_NC
,/* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 TRUE
, /* pc_relative */
775 complain_overflow_dont
,/* complain_on_overflow */
776 bfd_elf_generic_reloc
, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE
, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE
), /* pcrel_offset */
783 HOWTO (R_ARM_THM_MOVT_PREL
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 TRUE
, /* pc_relative */
789 complain_overflow_bitfield
,/* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE
, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE
), /* pcrel_offset */
797 HOWTO (R_ARM_THM_JUMP19
, /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 TRUE
, /* pc_relative */
803 complain_overflow_signed
,/* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE
, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE
), /* pcrel_offset */
811 HOWTO (R_ARM_THM_JUMP6
, /* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 TRUE
, /* pc_relative */
817 complain_overflow_unsigned
,/* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE
, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE
), /* pcrel_offset */
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
828 HOWTO (R_ARM_THM_ALU_PREL_11_0
,/* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 TRUE
, /* pc_relative */
834 complain_overflow_dont
,/* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE
, /* partial_inplace */
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
840 TRUE
), /* pcrel_offset */
842 HOWTO (R_ARM_THM_PC12
, /* type */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
846 TRUE
, /* pc_relative */
848 complain_overflow_dont
,/* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE
, /* partial_inplace */
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
854 TRUE
), /* pcrel_offset */
856 HOWTO (R_ARM_ABS32_NOI
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
,/* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE
, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 HOWTO (R_ARM_REL32_NOI
, /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 TRUE
, /* pc_relative */
876 complain_overflow_dont
,/* complain_on_overflow */
877 bfd_elf_generic_reloc
, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE
, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE
), /* pcrel_offset */
884 /* Group relocations. */
886 HOWTO (R_ARM_ALU_PC_G0_NC
, /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 TRUE
, /* pc_relative */
892 complain_overflow_dont
,/* complain_on_overflow */
893 bfd_elf_generic_reloc
, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE
, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE
), /* pcrel_offset */
900 HOWTO (R_ARM_ALU_PC_G0
, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 TRUE
, /* pc_relative */
906 complain_overflow_dont
,/* complain_on_overflow */
907 bfd_elf_generic_reloc
, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE
, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE
), /* pcrel_offset */
914 HOWTO (R_ARM_ALU_PC_G1_NC
, /* type */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
918 TRUE
, /* pc_relative */
920 complain_overflow_dont
,/* complain_on_overflow */
921 bfd_elf_generic_reloc
, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE
, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE
), /* pcrel_offset */
928 HOWTO (R_ARM_ALU_PC_G1
, /* type */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
932 TRUE
, /* pc_relative */
934 complain_overflow_dont
,/* complain_on_overflow */
935 bfd_elf_generic_reloc
, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE
, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE
), /* pcrel_offset */
942 HOWTO (R_ARM_ALU_PC_G2
, /* type */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
946 TRUE
, /* pc_relative */
948 complain_overflow_dont
,/* complain_on_overflow */
949 bfd_elf_generic_reloc
, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE
, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE
), /* pcrel_offset */
956 HOWTO (R_ARM_LDR_PC_G1
, /* type */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
960 TRUE
, /* pc_relative */
962 complain_overflow_dont
,/* complain_on_overflow */
963 bfd_elf_generic_reloc
, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE
, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE
), /* pcrel_offset */
970 HOWTO (R_ARM_LDR_PC_G2
, /* type */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
974 TRUE
, /* pc_relative */
976 complain_overflow_dont
,/* complain_on_overflow */
977 bfd_elf_generic_reloc
, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE
, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE
), /* pcrel_offset */
984 HOWTO (R_ARM_LDRS_PC_G0
, /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 TRUE
, /* pc_relative */
990 complain_overflow_dont
,/* complain_on_overflow */
991 bfd_elf_generic_reloc
, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE
, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE
), /* pcrel_offset */
998 HOWTO (R_ARM_LDRS_PC_G1
, /* type */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1002 TRUE
, /* pc_relative */
1004 complain_overflow_dont
,/* complain_on_overflow */
1005 bfd_elf_generic_reloc
, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE
, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE
), /* pcrel_offset */
1012 HOWTO (R_ARM_LDRS_PC_G2
, /* type */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 TRUE
, /* pc_relative */
1018 complain_overflow_dont
,/* complain_on_overflow */
1019 bfd_elf_generic_reloc
, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE
, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE
), /* pcrel_offset */
1026 HOWTO (R_ARM_LDC_PC_G0
, /* type */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1030 TRUE
, /* pc_relative */
1032 complain_overflow_dont
,/* complain_on_overflow */
1033 bfd_elf_generic_reloc
, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE
, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE
), /* pcrel_offset */
1040 HOWTO (R_ARM_LDC_PC_G1
, /* type */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1044 TRUE
, /* pc_relative */
1046 complain_overflow_dont
,/* complain_on_overflow */
1047 bfd_elf_generic_reloc
, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE
, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE
), /* pcrel_offset */
1054 HOWTO (R_ARM_LDC_PC_G2
, /* type */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1058 TRUE
, /* pc_relative */
1060 complain_overflow_dont
,/* complain_on_overflow */
1061 bfd_elf_generic_reloc
, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE
, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE
), /* pcrel_offset */
1068 HOWTO (R_ARM_ALU_SB_G0_NC
, /* type */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 TRUE
, /* pc_relative */
1074 complain_overflow_dont
,/* complain_on_overflow */
1075 bfd_elf_generic_reloc
, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE
, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE
), /* pcrel_offset */
1082 HOWTO (R_ARM_ALU_SB_G0
, /* type */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1086 TRUE
, /* pc_relative */
1088 complain_overflow_dont
,/* complain_on_overflow */
1089 bfd_elf_generic_reloc
, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE
, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE
), /* pcrel_offset */
1096 HOWTO (R_ARM_ALU_SB_G1_NC
, /* type */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1100 TRUE
, /* pc_relative */
1102 complain_overflow_dont
,/* complain_on_overflow */
1103 bfd_elf_generic_reloc
, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE
, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE
), /* pcrel_offset */
1110 HOWTO (R_ARM_ALU_SB_G1
, /* type */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1114 TRUE
, /* pc_relative */
1116 complain_overflow_dont
,/* complain_on_overflow */
1117 bfd_elf_generic_reloc
, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE
, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE
), /* pcrel_offset */
1124 HOWTO (R_ARM_ALU_SB_G2
, /* type */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1128 TRUE
, /* pc_relative */
1130 complain_overflow_dont
,/* complain_on_overflow */
1131 bfd_elf_generic_reloc
, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE
, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE
), /* pcrel_offset */
1138 HOWTO (R_ARM_LDR_SB_G0
, /* type */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1142 TRUE
, /* pc_relative */
1144 complain_overflow_dont
,/* complain_on_overflow */
1145 bfd_elf_generic_reloc
, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE
, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE
), /* pcrel_offset */
1152 HOWTO (R_ARM_LDR_SB_G1
, /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 TRUE
, /* pc_relative */
1158 complain_overflow_dont
,/* complain_on_overflow */
1159 bfd_elf_generic_reloc
, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE
, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE
), /* pcrel_offset */
1166 HOWTO (R_ARM_LDR_SB_G2
, /* type */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1170 TRUE
, /* pc_relative */
1172 complain_overflow_dont
,/* complain_on_overflow */
1173 bfd_elf_generic_reloc
, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE
, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE
), /* pcrel_offset */
1180 HOWTO (R_ARM_LDRS_SB_G0
, /* type */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 TRUE
, /* pc_relative */
1186 complain_overflow_dont
,/* complain_on_overflow */
1187 bfd_elf_generic_reloc
, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE
, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE
), /* pcrel_offset */
1194 HOWTO (R_ARM_LDRS_SB_G1
, /* type */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1198 TRUE
, /* pc_relative */
1200 complain_overflow_dont
,/* complain_on_overflow */
1201 bfd_elf_generic_reloc
, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE
, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE
), /* pcrel_offset */
1208 HOWTO (R_ARM_LDRS_SB_G2
, /* type */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1212 TRUE
, /* pc_relative */
1214 complain_overflow_dont
,/* complain_on_overflow */
1215 bfd_elf_generic_reloc
, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE
, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE
), /* pcrel_offset */
1222 HOWTO (R_ARM_LDC_SB_G0
, /* type */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1226 TRUE
, /* pc_relative */
1228 complain_overflow_dont
,/* complain_on_overflow */
1229 bfd_elf_generic_reloc
, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE
, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE
), /* pcrel_offset */
1236 HOWTO (R_ARM_LDC_SB_G1
, /* type */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1240 TRUE
, /* pc_relative */
1242 complain_overflow_dont
,/* complain_on_overflow */
1243 bfd_elf_generic_reloc
, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE
, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE
), /* pcrel_offset */
1250 HOWTO (R_ARM_LDC_SB_G2
, /* type */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 TRUE
, /* pc_relative */
1256 complain_overflow_dont
,/* complain_on_overflow */
1257 bfd_elf_generic_reloc
, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE
, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE
), /* pcrel_offset */
1264 /* End of group relocations. */
1266 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE
, /* pc_relative */
1272 complain_overflow_dont
,/* complain_on_overflow */
1273 bfd_elf_generic_reloc
, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE
, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE
), /* pcrel_offset */
1280 HOWTO (R_ARM_MOVT_BREL
, /* type */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1284 FALSE
, /* pc_relative */
1286 complain_overflow_bitfield
,/* complain_on_overflow */
1287 bfd_elf_generic_reloc
, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE
, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE
), /* pcrel_offset */
1294 HOWTO (R_ARM_MOVW_BREL
, /* type */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE
, /* pc_relative */
1300 complain_overflow_dont
,/* complain_on_overflow */
1301 bfd_elf_generic_reloc
, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE
, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE
), /* pcrel_offset */
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1312 FALSE
, /* pc_relative */
1314 complain_overflow_dont
,/* complain_on_overflow */
1315 bfd_elf_generic_reloc
, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE
, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE
), /* pcrel_offset */
1322 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1326 FALSE
, /* pc_relative */
1328 complain_overflow_bitfield
,/* complain_on_overflow */
1329 bfd_elf_generic_reloc
, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE
, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE
), /* pcrel_offset */
1336 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1340 FALSE
, /* pc_relative */
1342 complain_overflow_dont
,/* complain_on_overflow */
1343 bfd_elf_generic_reloc
, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE
, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE
), /* pcrel_offset */
1350 EMPTY_HOWTO (90), /* Unallocated. */
1355 HOWTO (R_ARM_PLT32_ABS
, /* type */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE
, /* pc_relative */
1361 complain_overflow_dont
,/* complain_on_overflow */
1362 bfd_elf_generic_reloc
, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE
, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE
), /* pcrel_offset */
1369 HOWTO (R_ARM_GOT_ABS
, /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE
, /* pc_relative */
1375 complain_overflow_dont
,/* complain_on_overflow */
1376 bfd_elf_generic_reloc
, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE
, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE
), /* pcrel_offset */
1383 HOWTO (R_ARM_GOT_PREL
, /* type */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1387 TRUE
, /* pc_relative */
1389 complain_overflow_dont
, /* complain_on_overflow */
1390 bfd_elf_generic_reloc
, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE
, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE
), /* pcrel_offset */
1397 HOWTO (R_ARM_GOT_BREL12
, /* type */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE
, /* pc_relative */
1403 complain_overflow_bitfield
,/* complain_on_overflow */
1404 bfd_elf_generic_reloc
, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE
, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE
), /* pcrel_offset */
1411 HOWTO (R_ARM_GOTOFF12
, /* type */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1415 FALSE
, /* pc_relative */
1417 complain_overflow_bitfield
,/* complain_on_overflow */
1418 bfd_elf_generic_reloc
, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE
, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE
), /* pcrel_offset */
1425 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
1432 FALSE
, /* pc_relative */
1434 complain_overflow_dont
, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE
, /* partial_inplace */
1440 FALSE
), /* pcrel_offset */
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 FALSE
, /* pc_relative */
1449 complain_overflow_dont
, /* complain_on_overflow */
1450 NULL
, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE
, /* partial_inplace */
1455 FALSE
), /* pcrel_offset */
1457 HOWTO (R_ARM_THM_JUMP11
, /* type */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1461 TRUE
, /* pc_relative */
1463 complain_overflow_signed
, /* complain_on_overflow */
1464 bfd_elf_generic_reloc
, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE
, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE
), /* pcrel_offset */
1471 HOWTO (R_ARM_THM_JUMP8
, /* type */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1475 TRUE
, /* pc_relative */
1477 complain_overflow_signed
, /* complain_on_overflow */
1478 bfd_elf_generic_reloc
, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE
, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE
), /* pcrel_offset */
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32
, /* type */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1490 FALSE
, /* pc_relative */
1492 complain_overflow_bitfield
,/* complain_on_overflow */
1493 NULL
, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
1495 TRUE
, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
1498 FALSE
), /* pcrel_offset */
1500 HOWTO (R_ARM_TLS_LDM32
, /* type */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 FALSE
, /* pc_relative */
1506 complain_overflow_bitfield
,/* complain_on_overflow */
1507 bfd_elf_generic_reloc
, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE
, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
1512 FALSE
), /* pcrel_offset */
1514 HOWTO (R_ARM_TLS_LDO32
, /* type */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1518 FALSE
, /* pc_relative */
1520 complain_overflow_bitfield
,/* complain_on_overflow */
1521 bfd_elf_generic_reloc
, /* special_function */
1522 "R_ARM_TLS_LDO32", /* name */
1523 TRUE
, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
1526 FALSE
), /* pcrel_offset */
1528 HOWTO (R_ARM_TLS_IE32
, /* type */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1532 FALSE
, /* pc_relative */
1534 complain_overflow_bitfield
,/* complain_on_overflow */
1535 NULL
, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE
, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
1540 FALSE
), /* pcrel_offset */
1542 HOWTO (R_ARM_TLS_LE32
, /* type */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE
, /* pc_relative */
1548 complain_overflow_bitfield
,/* complain_on_overflow */
1549 bfd_elf_generic_reloc
, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE
, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE
), /* pcrel_offset */
1556 HOWTO (R_ARM_TLS_LDO12
, /* type */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE
, /* pc_relative */
1562 complain_overflow_bitfield
,/* complain_on_overflow */
1563 bfd_elf_generic_reloc
, /* special_function */
1564 "R_ARM_TLS_LDO12", /* name */
1565 FALSE
, /* partial_inplace */
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE
), /* pcrel_offset */
1570 HOWTO (R_ARM_TLS_LE12
, /* type */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE
, /* pc_relative */
1576 complain_overflow_bitfield
,/* complain_on_overflow */
1577 bfd_elf_generic_reloc
, /* special_function */
1578 "R_ARM_TLS_LE12", /* name */
1579 FALSE
, /* partial_inplace */
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE
), /* pcrel_offset */
1584 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE
, /* pc_relative */
1590 complain_overflow_bitfield
,/* complain_on_overflow */
1591 bfd_elf_generic_reloc
, /* special_function */
1592 "R_ARM_TLS_IE12GP", /* name */
1593 FALSE
, /* partial_inplace */
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE
), /* pcrel_offset */
1599 /* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
1603 249-255 extended, currently unused, relocations: */
1605 static reloc_howto_type elf32_arm_howto_table_2
[4] =
1607 HOWTO (R_ARM_RREL32
, /* type */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1611 FALSE
, /* pc_relative */
1613 complain_overflow_dont
,/* complain_on_overflow */
1614 bfd_elf_generic_reloc
, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE
, /* partial_inplace */
1619 FALSE
), /* pcrel_offset */
1621 HOWTO (R_ARM_RABS32
, /* type */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1625 FALSE
, /* pc_relative */
1627 complain_overflow_dont
,/* complain_on_overflow */
1628 bfd_elf_generic_reloc
, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE
, /* partial_inplace */
1633 FALSE
), /* pcrel_offset */
1635 HOWTO (R_ARM_RPC24
, /* type */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1639 FALSE
, /* pc_relative */
1641 complain_overflow_dont
,/* complain_on_overflow */
1642 bfd_elf_generic_reloc
, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE
, /* partial_inplace */
1647 FALSE
), /* pcrel_offset */
1649 HOWTO (R_ARM_RBASE
, /* type */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1653 FALSE
, /* pc_relative */
1655 complain_overflow_dont
,/* complain_on_overflow */
1656 bfd_elf_generic_reloc
, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE
, /* partial_inplace */
1661 FALSE
) /* pcrel_offset */
1664 static reloc_howto_type
*
1665 elf32_arm_howto_from_type (unsigned int r_type
)
1667 if (r_type
< ARRAY_SIZE (elf32_arm_howto_table_1
))
1668 return &elf32_arm_howto_table_1
[r_type
];
1670 if (r_type
>= R_ARM_RREL32
1671 && r_type
< R_ARM_RREL32
+ ARRAY_SIZE (elf32_arm_howto_table_2
))
1672 return &elf32_arm_howto_table_2
[r_type
- R_ARM_RREL32
];
1678 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1679 Elf_Internal_Rela
* elf_reloc
)
1681 unsigned int r_type
;
1683 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1684 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1687 struct elf32_arm_reloc_map
1689 bfd_reloc_code_real_type bfd_reloc_val
;
1690 unsigned char elf_reloc_val
;
1693 /* All entries in this list must also be present in elf32_arm_howto_table. */
1694 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1696 {BFD_RELOC_NONE
, R_ARM_NONE
},
1697 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1698 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1699 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1700 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1701 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1702 {BFD_RELOC_32
, R_ARM_ABS32
},
1703 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1704 {BFD_RELOC_8
, R_ARM_ABS8
},
1705 {BFD_RELOC_16
, R_ARM_ABS16
},
1706 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1707 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1714 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1715 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1716 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1717 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1718 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1719 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1720 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1721 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1722 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1723 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1724 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1725 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1726 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1727 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1728 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1729 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1732 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1733 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1734 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1735 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1736 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1737 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1738 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1739 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1740 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1741 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1742 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1746 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1748 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1749 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1750 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1751 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1752 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1753 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1754 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1755 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1756 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1757 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1758 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1760 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1762 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1763 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1764 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1765 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1766 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1767 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1768 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1769 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1770 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1771 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1772 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
},
1773 {BFD_RELOC_ARM_V4BX
, R_ARM_V4BX
}
1776 static reloc_howto_type
*
1777 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1778 bfd_reloc_code_real_type code
)
1782 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_reloc_map
); i
++)
1783 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1784 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1789 static reloc_howto_type
*
1790 elf32_arm_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1795 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_1
); i
++)
1796 if (elf32_arm_howto_table_1
[i
].name
!= NULL
1797 && strcasecmp (elf32_arm_howto_table_1
[i
].name
, r_name
) == 0)
1798 return &elf32_arm_howto_table_1
[i
];
1800 for (i
= 0; i
< ARRAY_SIZE (elf32_arm_howto_table_2
); i
++)
1801 if (elf32_arm_howto_table_2
[i
].name
!= NULL
1802 && strcasecmp (elf32_arm_howto_table_2
[i
].name
, r_name
) == 0)
1803 return &elf32_arm_howto_table_2
[i
];
1808 /* Support for core dump NOTE sections. */
1811 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1816 switch (note
->descsz
)
1821 case 148: /* Linux/ARM 32-bit. */
1823 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1826 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1835 /* Make a ".reg/999" section. */
1836 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1837 size
, note
->descpos
+ offset
);
1841 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1843 switch (note
->descsz
)
1848 case 124: /* Linux/ARM elf_prpsinfo. */
1849 elf_tdata (abfd
)->core_program
1850 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1851 elf_tdata (abfd
)->core_command
1852 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1855 /* Note that for some reason, a spurious space is tacked
1856 onto the end of the args in some (at least one anyway)
1857 implementations, so strip it off if it exists. */
1859 char *command
= elf_tdata (abfd
)->core_command
;
1860 int n
= strlen (command
);
1862 if (0 < n
&& command
[n
- 1] == ' ')
1863 command
[n
- 1] = '\0';
1869 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1870 #define TARGET_LITTLE_NAME "elf32-littlearm"
1871 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1872 #define TARGET_BIG_NAME "elf32-bigarm"
1874 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1875 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1877 typedef unsigned long int insn32
;
1878 typedef unsigned short int insn16
;
1880 /* In lieu of proper flags, assume all EABIv4 or later objects are
1882 #define INTERWORK_FLAG(abfd) \
1883 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1884 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1886 /* The linker script knows the section names for placement.
1887 The entry_names are used to do simple name mangling on the stubs.
1888 Given a function name, and its type, the stub can be found. The
1889 name can be changed. The only requirement is the %s be present. */
1890 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1891 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1893 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1894 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1896 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1897 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1899 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1900 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1902 #define STUB_ENTRY_NAME "__%s_veneer"
1904 /* The name of the dynamic interpreter. This is put in the .interp
1906 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1908 #ifdef FOUR_WORD_PLT
1910 /* The first entry in a procedure linkage table looks like
1911 this. It is set up so that any shared library function that is
1912 called before the relocation has been set up calls the dynamic
1914 static const bfd_vma elf32_arm_plt0_entry
[] =
1916 0xe52de004, /* str lr, [sp, #-4]! */
1917 0xe59fe010, /* ldr lr, [pc, #16] */
1918 0xe08fe00e, /* add lr, pc, lr */
1919 0xe5bef008, /* ldr pc, [lr, #8]! */
1922 /* Subsequent entries in a procedure linkage table look like
1924 static const bfd_vma elf32_arm_plt_entry
[] =
1926 0xe28fc600, /* add ip, pc, #NN */
1927 0xe28cca00, /* add ip, ip, #NN */
1928 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1929 0x00000000, /* unused */
1934 /* The first entry in a procedure linkage table looks like
1935 this. It is set up so that any shared library function that is
1936 called before the relocation has been set up calls the dynamic
1938 static const bfd_vma elf32_arm_plt0_entry
[] =
1940 0xe52de004, /* str lr, [sp, #-4]! */
1941 0xe59fe004, /* ldr lr, [pc, #4] */
1942 0xe08fe00e, /* add lr, pc, lr */
1943 0xe5bef008, /* ldr pc, [lr, #8]! */
1944 0x00000000, /* &GOT[0] - . */
1947 /* Subsequent entries in a procedure linkage table look like
1949 static const bfd_vma elf32_arm_plt_entry
[] =
1951 0xe28fc600, /* add ip, pc, #0xNN00000 */
1952 0xe28cca00, /* add ip, ip, #0xNN000 */
1953 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1958 /* The format of the first entry in the procedure linkage table
1959 for a VxWorks executable. */
1960 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
1962 0xe52dc008, /* str ip,[sp,#-8]! */
1963 0xe59fc000, /* ldr ip,[pc] */
1964 0xe59cf008, /* ldr pc,[ip,#8] */
1965 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1968 /* The format of subsequent entries in a VxWorks executable. */
1969 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
1971 0xe59fc000, /* ldr ip,[pc] */
1972 0xe59cf000, /* ldr pc,[ip] */
1973 0x00000000, /* .long @got */
1974 0xe59fc000, /* ldr ip,[pc] */
1975 0xea000000, /* b _PLT */
1976 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1979 /* The format of entries in a VxWorks shared library. */
1980 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xe79cf009, /* ldr pc,[ip,r9] */
1984 0x00000000, /* .long @got */
1985 0xe59fc000, /* ldr ip,[pc] */
1986 0xe599f008, /* ldr pc,[r9,#8] */
1987 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1990 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1991 #define PLT_THUMB_STUB_SIZE 4
1992 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
1998 /* The entries in a PLT when using a DLL-based target with multiple
2000 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
2002 0xe51ff004, /* ldr pc, [pc, #-4] */
2003 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2006 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2007 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2008 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2009 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2010 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2011 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2013 static const bfd_vma arm_long_branch_stub
[] =
2015 0xe51ff004, /* ldr pc, [pc, #-4] */
2016 0x00000000, /* dcd R_ARM_ABS32(X) */
2019 static const bfd_vma arm_thumb_v4t_long_branch_stub
[] =
2021 0xe59fc000, /* ldr ip, [pc, #0] */
2022 0xe12fff1c, /* bx ip */
2023 0x00000000, /* dcd R_ARM_ABS32(X) */
2026 static const bfd_vma arm_thumb_thumb_long_branch_stub
[] =
2028 0x4e02b540, /* push {r6, lr} */
2029 /* ldr r6, [pc, #8] */
2030 0x473046fe, /* mov lr, pc */
2032 0xbf00bd40, /* pop {r6, pc} */
2034 0x00000000, /* dcd R_ARM_ABS32(X) */
2037 static const bfd_vma arm_thumb_arm_v4t_long_branch_stub
[] =
2039 0x4e03b540, /* push {r6, lr} */
2040 /* ldr r6, [pc, #12] */
2041 0x473046fe, /* mov lr, pc */
2043 0xe8bd4040, /* pop {r6, pc} */
2044 0xe12fff1e, /* bx lr */
2045 0x00000000, /* dcd R_ARM_ABS32(X) */
2048 static const bfd_vma arm_pic_long_branch_stub
[] =
2050 0xe59fc000, /* ldr r12, [pc] */
2051 0xe08ff00c, /* add pc, pc, ip */
2052 0x00000000, /* dcd R_ARM_REL32(X) */
2055 /* Section name for stubs is the associated section name plus this
2057 #define STUB_SUFFIX ".stub"
2059 enum elf32_arm_stub_type
2062 arm_stub_long_branch
,
2063 arm_thumb_v4t_stub_long_branch
,
2064 arm_thumb_thumb_stub_long_branch
,
2065 arm_thumb_arm_v4t_stub_long_branch
,
2066 arm_stub_pic_long_branch
,
2069 struct elf32_arm_stub_hash_entry
2071 /* Base hash table entry structure. */
2072 struct bfd_hash_entry root
;
2074 /* The stub section. */
2077 /* Offset within stub_sec of the beginning of this stub. */
2078 bfd_vma stub_offset
;
2080 /* Given the symbol's value and its section we can determine its final
2081 value when building the stubs (so the stub knows where to jump). */
2082 bfd_vma target_value
;
2083 asection
*target_section
;
2085 enum elf32_arm_stub_type stub_type
;
2087 /* The symbol table entry, if any, that this was derived from. */
2088 struct elf32_arm_link_hash_entry
*h
;
2090 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2091 unsigned char st_type
;
2093 /* Where this stub is being called from, or, in the case of combined
2094 stub sections, the first input section in the group. */
2097 /* The name for the local symbol at the start of this stub. The
2098 stub name in the hash table has to be unique; this does not, so
2099 it can be friendlier. */
2103 /* Used to build a map of a section. This is required for mixed-endian
2106 typedef struct elf32_elf_section_map
2111 elf32_arm_section_map
;
2113 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2117 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
,
2118 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
,
2119 VFP11_ERRATUM_ARM_VENEER
,
2120 VFP11_ERRATUM_THUMB_VENEER
2122 elf32_vfp11_erratum_type
;
2124 typedef struct elf32_vfp11_erratum_list
2126 struct elf32_vfp11_erratum_list
*next
;
2132 struct elf32_vfp11_erratum_list
*veneer
;
2133 unsigned int vfp_insn
;
2137 struct elf32_vfp11_erratum_list
*branch
;
2141 elf32_vfp11_erratum_type type
;
2143 elf32_vfp11_erratum_list
;
2145 typedef struct _arm_elf_section_data
2147 struct bfd_elf_section_data elf
;
2148 unsigned int mapcount
;
2149 unsigned int mapsize
;
2150 elf32_arm_section_map
*map
;
2151 unsigned int erratumcount
;
2152 elf32_vfp11_erratum_list
*erratumlist
;
2154 _arm_elf_section_data
;
2156 #define elf32_arm_section_data(sec) \
2157 ((_arm_elf_section_data *) elf_section_data (sec))
2159 /* The size of the thread control block. */
2162 struct elf_arm_obj_tdata
2164 struct elf_obj_tdata root
;
2166 /* tls_type for each local got entry. */
2167 char *local_got_tls_type
;
2169 /* Zero to warn when linking objects with incompatible enum sizes. */
2170 int no_enum_size_warning
;
2172 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2173 int no_wchar_size_warning
;
2176 #define elf_arm_tdata(bfd) \
2177 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2179 #define elf32_arm_local_got_tls_type(bfd) \
2180 (elf_arm_tdata (bfd)->local_got_tls_type)
2182 #define is_arm_elf(bfd) \
2183 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2184 && elf_tdata (bfd) != NULL \
2185 && elf_object_id (bfd) == ARM_ELF_TDATA)
2188 elf32_arm_mkobject (bfd
*abfd
)
2190 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_arm_obj_tdata
),
2194 /* The ARM linker needs to keep track of the number of relocs that it
2195 decides to copy in check_relocs for each symbol. This is so that
2196 it can discard PC relative relocs if it doesn't need them when
2197 linking with -Bsymbolic. We store the information in a field
2198 extending the regular ELF linker hash table. */
2200 /* This structure keeps track of the number of relocs we have copied
2201 for a given symbol. */
2202 struct elf32_arm_relocs_copied
2205 struct elf32_arm_relocs_copied
* next
;
2206 /* A section in dynobj. */
2208 /* Number of relocs copied in this section. */
2209 bfd_size_type count
;
2210 /* Number of PC-relative relocs copied in this section. */
2211 bfd_size_type pc_count
;
2214 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2216 /* Arm ELF linker hash entry. */
2217 struct elf32_arm_link_hash_entry
2219 struct elf_link_hash_entry root
;
2221 /* Number of PC relative relocs copied for this symbol. */
2222 struct elf32_arm_relocs_copied
* relocs_copied
;
2224 /* We reference count Thumb references to a PLT entry separately,
2225 so that we can emit the Thumb trampoline only if needed. */
2226 bfd_signed_vma plt_thumb_refcount
;
2228 /* Some references from Thumb code may be eliminated by BL->BLX
2229 conversion, so record them separately. */
2230 bfd_signed_vma plt_maybe_thumb_refcount
;
2232 /* Since PLT entries have variable size if the Thumb prologue is
2233 used, we need to record the index into .got.plt instead of
2234 recomputing it from the PLT offset. */
2235 bfd_signed_vma plt_got_offset
;
2237 #define GOT_UNKNOWN 0
2238 #define GOT_NORMAL 1
2239 #define GOT_TLS_GD 2
2240 #define GOT_TLS_IE 4
2241 unsigned char tls_type
;
2243 /* The symbol marking the real symbol location for exported thumb
2244 symbols with Arm stubs. */
2245 struct elf_link_hash_entry
*export_glue
;
2247 /* A pointer to the most recently used stub hash entry against this
2249 struct elf32_arm_stub_hash_entry
*stub_cache
;
2252 /* Traverse an arm ELF linker hash table. */
2253 #define elf32_arm_link_hash_traverse(table, func, info) \
2254 (elf_link_hash_traverse \
2256 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2259 /* Get the ARM elf linker hash table from a link_info structure. */
2260 #define elf32_arm_hash_table(info) \
2261 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2263 #define arm_stub_hash_lookup(table, string, create, copy) \
2264 ((struct elf32_arm_stub_hash_entry *) \
2265 bfd_hash_lookup ((table), (string), (create), (copy)))
2267 /* ARM ELF linker hash table. */
2268 struct elf32_arm_link_hash_table
2270 /* The main hash table. */
2271 struct elf_link_hash_table root
;
2273 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2274 bfd_size_type thumb_glue_size
;
2276 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2277 bfd_size_type arm_glue_size
;
2279 /* The size in bytes of section containing the ARMv4 BX veneers. */
2280 bfd_size_type bx_glue_size
;
2282 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2283 veneer has been populated. */
2284 bfd_vma bx_glue_offset
[15];
2286 /* The size in bytes of the section containing glue for VFP11 erratum
2288 bfd_size_type vfp11_erratum_glue_size
;
2290 /* An arbitrary input BFD chosen to hold the glue sections. */
2291 bfd
* bfd_of_glue_owner
;
2293 /* Nonzero to output a BE8 image. */
2296 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2297 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2300 /* The relocation to use for R_ARM_TARGET2 relocations. */
2303 /* 0 = Ignore R_ARM_V4BX.
2304 1 = Convert BX to MOV PC.
2305 2 = Generate v4 interworing stubs. */
2308 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2311 /* What sort of code sequences we should look for which may trigger the
2312 VFP11 denorm erratum. */
2313 bfd_arm_vfp11_fix vfp11_fix
;
2315 /* Global counter for the number of fixes we have emitted. */
2316 int num_vfp11_fixes
;
2318 /* Nonzero to force PIC branch veneers. */
2321 /* The number of bytes in the initial entry in the PLT. */
2322 bfd_size_type plt_header_size
;
2324 /* The number of bytes in the subsequent PLT etries. */
2325 bfd_size_type plt_entry_size
;
2327 /* True if the target system is VxWorks. */
2330 /* True if the target system is Symbian OS. */
2333 /* True if the target uses REL relocations. */
2336 /* Short-cuts to get to dynamic linker sections. */
2345 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2348 /* Data for R_ARM_TLS_LDM32 relocations. */
2351 bfd_signed_vma refcount
;
2355 /* Small local sym to section mapping cache. */
2356 struct sym_sec_cache sym_sec
;
2358 /* For convenience in allocate_dynrelocs. */
2361 /* The stub hash table. */
2362 struct bfd_hash_table stub_hash_table
;
2364 /* Linker stub bfd. */
2367 /* Linker call-backs. */
2368 asection
* (*add_stub_section
) (const char *, asection
*);
2369 void (*layout_sections_again
) (void);
2371 /* Array to keep track of which stub sections have been created, and
2372 information on stub grouping. */
2375 /* This is the section to which stubs in the group will be
2378 /* The stub section. */
2382 /* Assorted information used by elf32_arm_size_stubs. */
2383 unsigned int bfd_count
;
2385 asection
**input_list
;
2388 /* Create an entry in an ARM ELF linker hash table. */
2390 static struct bfd_hash_entry
*
2391 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
2392 struct bfd_hash_table
* table
,
2393 const char * string
)
2395 struct elf32_arm_link_hash_entry
* ret
=
2396 (struct elf32_arm_link_hash_entry
*) entry
;
2398 /* Allocate the structure if it has not already been allocated by a
2401 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
2403 return (struct bfd_hash_entry
*) ret
;
2405 /* Call the allocation method of the superclass. */
2406 ret
= ((struct elf32_arm_link_hash_entry
*)
2407 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2411 ret
->relocs_copied
= NULL
;
2412 ret
->tls_type
= GOT_UNKNOWN
;
2413 ret
->plt_thumb_refcount
= 0;
2414 ret
->plt_maybe_thumb_refcount
= 0;
2415 ret
->plt_got_offset
= -1;
2416 ret
->export_glue
= NULL
;
2418 ret
->stub_cache
= NULL
;
2421 return (struct bfd_hash_entry
*) ret
;
2424 /* Initialize an entry in the stub hash table. */
2426 static struct bfd_hash_entry
*
2427 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2428 struct bfd_hash_table
*table
,
2431 /* Allocate the structure if it has not already been allocated by a
2435 entry
= bfd_hash_allocate (table
,
2436 sizeof (struct elf32_arm_stub_hash_entry
));
2441 /* Call the allocation method of the superclass. */
2442 entry
= bfd_hash_newfunc (entry
, table
, string
);
2445 struct elf32_arm_stub_hash_entry
*eh
;
2447 /* Initialize the local fields. */
2448 eh
= (struct elf32_arm_stub_hash_entry
*) entry
;
2449 eh
->stub_sec
= NULL
;
2450 eh
->stub_offset
= 0;
2451 eh
->target_value
= 0;
2452 eh
->target_section
= NULL
;
2453 eh
->stub_type
= arm_stub_none
;
2461 /* Return true if NAME is the name of the relocation section associated
2465 reloc_section_p (struct elf32_arm_link_hash_table
*htab
,
2466 const char *name
, asection
*s
)
2469 return CONST_STRNEQ (name
, ".rel") && strcmp (s
->name
, name
+ 4) == 0;
2471 return CONST_STRNEQ (name
, ".rela") && strcmp (s
->name
, name
+ 5) == 0;
2474 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2475 shortcuts to them in our hash table. */
2478 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
2480 struct elf32_arm_link_hash_table
*htab
;
2482 htab
= elf32_arm_hash_table (info
);
2483 /* BPABI objects never have a GOT, or associated sections. */
2484 if (htab
->symbian_p
)
2487 if (! _bfd_elf_create_got_section (dynobj
, info
))
2490 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2491 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2492 if (!htab
->sgot
|| !htab
->sgotplt
)
2495 htab
->srelgot
= bfd_make_section_with_flags (dynobj
,
2496 RELOC_SECTION (htab
, ".got"),
2497 (SEC_ALLOC
| SEC_LOAD
2500 | SEC_LINKER_CREATED
2502 if (htab
->srelgot
== NULL
2503 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
2508 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2509 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2513 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
2515 struct elf32_arm_link_hash_table
*htab
;
2517 htab
= elf32_arm_hash_table (info
);
2518 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2521 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2524 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2525 htab
->srelplt
= bfd_get_section_by_name (dynobj
,
2526 RELOC_SECTION (htab
, ".plt"));
2527 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2529 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
2530 RELOC_SECTION (htab
, ".bss"));
2532 if (htab
->vxworks_p
)
2534 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
2539 htab
->plt_header_size
= 0;
2540 htab
->plt_entry_size
2541 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
2545 htab
->plt_header_size
2546 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
2547 htab
->plt_entry_size
2548 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
2555 || (!info
->shared
&& !htab
->srelbss
))
2561 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2564 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
2565 struct elf_link_hash_entry
*dir
,
2566 struct elf_link_hash_entry
*ind
)
2568 struct elf32_arm_link_hash_entry
*edir
, *eind
;
2570 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
2571 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
2573 if (eind
->relocs_copied
!= NULL
)
2575 if (edir
->relocs_copied
!= NULL
)
2577 struct elf32_arm_relocs_copied
**pp
;
2578 struct elf32_arm_relocs_copied
*p
;
2580 /* Add reloc counts against the indirect sym to the direct sym
2581 list. Merge any entries against the same section. */
2582 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
2584 struct elf32_arm_relocs_copied
*q
;
2586 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
2587 if (q
->section
== p
->section
)
2589 q
->pc_count
+= p
->pc_count
;
2590 q
->count
+= p
->count
;
2597 *pp
= edir
->relocs_copied
;
2600 edir
->relocs_copied
= eind
->relocs_copied
;
2601 eind
->relocs_copied
= NULL
;
2604 if (ind
->root
.type
== bfd_link_hash_indirect
)
2606 /* Copy over PLT info. */
2607 edir
->plt_thumb_refcount
+= eind
->plt_thumb_refcount
;
2608 eind
->plt_thumb_refcount
= 0;
2609 edir
->plt_maybe_thumb_refcount
+= eind
->plt_maybe_thumb_refcount
;
2610 eind
->plt_maybe_thumb_refcount
= 0;
2612 if (dir
->got
.refcount
<= 0)
2614 edir
->tls_type
= eind
->tls_type
;
2615 eind
->tls_type
= GOT_UNKNOWN
;
2619 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2622 /* Create an ARM elf linker hash table. */
2624 static struct bfd_link_hash_table
*
2625 elf32_arm_link_hash_table_create (bfd
*abfd
)
2627 struct elf32_arm_link_hash_table
*ret
;
2628 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
2630 ret
= bfd_malloc (amt
);
2634 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
2635 elf32_arm_link_hash_newfunc
,
2636 sizeof (struct elf32_arm_link_hash_entry
)))
2643 ret
->sgotplt
= NULL
;
2644 ret
->srelgot
= NULL
;
2646 ret
->srelplt
= NULL
;
2647 ret
->sdynbss
= NULL
;
2648 ret
->srelbss
= NULL
;
2649 ret
->srelplt2
= NULL
;
2650 ret
->thumb_glue_size
= 0;
2651 ret
->arm_glue_size
= 0;
2652 ret
->bx_glue_size
= 0;
2653 memset (ret
->bx_glue_offset
, 0, sizeof (ret
->bx_glue_offset
));
2654 ret
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
2655 ret
->vfp11_erratum_glue_size
= 0;
2656 ret
->num_vfp11_fixes
= 0;
2657 ret
->bfd_of_glue_owner
= NULL
;
2658 ret
->byteswap_code
= 0;
2659 ret
->target1_is_rel
= 0;
2660 ret
->target2_reloc
= R_ARM_NONE
;
2661 #ifdef FOUR_WORD_PLT
2662 ret
->plt_header_size
= 16;
2663 ret
->plt_entry_size
= 16;
2665 ret
->plt_header_size
= 20;
2666 ret
->plt_entry_size
= 12;
2673 ret
->sym_sec
.abfd
= NULL
;
2675 ret
->tls_ldm_got
.refcount
= 0;
2676 ret
->stub_bfd
= NULL
;
2677 ret
->add_stub_section
= NULL
;
2678 ret
->layout_sections_again
= NULL
;
2679 ret
->stub_group
= NULL
;
2682 ret
->input_list
= NULL
;
2684 if (!bfd_hash_table_init (&ret
->stub_hash_table
, stub_hash_newfunc
,
2685 sizeof (struct elf32_arm_stub_hash_entry
)))
2691 return &ret
->root
.root
;
2694 /* Free the derived linker hash table. */
2697 elf32_arm_hash_table_free (struct bfd_link_hash_table
*hash
)
2699 struct elf32_arm_link_hash_table
*ret
2700 = (struct elf32_arm_link_hash_table
*) hash
;
2702 bfd_hash_table_free (&ret
->stub_hash_table
);
2703 _bfd_generic_link_hash_table_free (hash
);
2706 /* Determine if we're dealing with a Thumb only architecture. */
2709 using_thumb_only (struct elf32_arm_link_hash_table
*globals
)
2711 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2715 if (arch
!= TAG_CPU_ARCH_V7
)
2718 profile
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2719 Tag_CPU_arch_profile
);
2721 return profile
== 'M';
2724 /* Determine if we're dealing with a Thumb-2 object. */
2727 using_thumb2 (struct elf32_arm_link_hash_table
*globals
)
2729 int arch
= bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
2731 return arch
== TAG_CPU_ARCH_V6T2
|| arch
>= TAG_CPU_ARCH_V7
;
2735 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type
)
2739 case arm_thumb_thumb_stub_long_branch
:
2740 case arm_thumb_arm_v4t_stub_long_branch
:
2751 /* Determine the type of stub needed, if any, for a call. */
2753 static enum elf32_arm_stub_type
2754 arm_type_of_stub (struct bfd_link_info
*info
,
2755 asection
*input_sec
,
2756 const Elf_Internal_Rela
*rel
,
2757 unsigned char st_type
,
2758 struct elf32_arm_link_hash_entry
*hash
,
2759 bfd_vma destination
)
2762 bfd_signed_vma branch_offset
;
2763 unsigned int r_type
;
2764 struct elf32_arm_link_hash_table
* globals
;
2767 enum elf32_arm_stub_type stub_type
= arm_stub_none
;
2769 /* We don't know the actual type of destination in case it is of
2770 type STT_SECTION: give up. */
2771 if (st_type
== STT_SECTION
)
2774 globals
= elf32_arm_hash_table (info
);
2776 thumb_only
= using_thumb_only (globals
);
2778 thumb2
= using_thumb2 (globals
);
2780 /* Determine where the call point is. */
2781 location
= (input_sec
->output_offset
2782 + input_sec
->output_section
->vma
2785 branch_offset
= (bfd_signed_vma
)(destination
- location
);
2787 r_type
= ELF32_R_TYPE (rel
->r_info
);
2789 /* If the call will go through a PLT entry then we do not need
2791 if (globals
->splt
!= NULL
&& hash
!= NULL
&& hash
->root
.plt
.offset
!= (bfd_vma
) -1)
2794 if (r_type
== R_ARM_THM_CALL
)
2797 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
2798 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
2800 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
2801 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
2802 || ((st_type
!= STT_ARM_TFUNC
) && !globals
->use_blx
))
2804 if (st_type
== STT_ARM_TFUNC
)
2806 /* Thumb to thumb. */
2809 stub_type
= (info
->shared
| globals
->pic_veneer
)
2810 ? ((globals
->use_blx
)
2811 ? arm_stub_pic_long_branch
2813 : (globals
->use_blx
)
2814 ? arm_stub_long_branch
2819 stub_type
= (info
->shared
| globals
->pic_veneer
)
2821 : (globals
->use_blx
)
2822 ? arm_thumb_thumb_stub_long_branch
2829 stub_type
= (info
->shared
| globals
->pic_veneer
)
2830 ? ((globals
->use_blx
)
2831 ? arm_stub_pic_long_branch
2833 : (globals
->use_blx
)
2834 ? arm_stub_long_branch
2835 : arm_thumb_arm_v4t_stub_long_branch
;
2839 else if (r_type
== R_ARM_CALL
)
2841 if (st_type
== STT_ARM_TFUNC
)
2844 /* We have an extra 2-bytes reach because of the mode change
2845 (bit 24 (H) of BLX encoding). */
2846 if (branch_offset
> (ARM_MAX_FWD_BRANCH_OFFSET
+ 2)
2847 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
)
2848 || !globals
->use_blx
)
2850 stub_type
= (info
->shared
| globals
->pic_veneer
)
2851 ? arm_stub_pic_long_branch
2852 : (globals
->use_blx
)
2853 ? arm_stub_long_branch
2854 : arm_thumb_v4t_stub_long_branch
;
2860 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
2861 || (branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
))
2863 stub_type
= (info
->shared
| globals
->pic_veneer
)
2864 ? arm_stub_pic_long_branch
2865 : arm_stub_long_branch
;
2873 /* Build a name for an entry in the stub hash table. */
2876 elf32_arm_stub_name (const asection
*input_section
,
2877 const asection
*sym_sec
,
2878 const struct elf32_arm_link_hash_entry
*hash
,
2879 const Elf_Internal_Rela
*rel
)
2886 len
= 8 + 1 + strlen (hash
->root
.root
.root
.string
) + 1 + 8 + 1;
2887 stub_name
= bfd_malloc (len
);
2888 if (stub_name
!= NULL
)
2889 sprintf (stub_name
, "%08x_%s+%x",
2890 input_section
->id
& 0xffffffff,
2891 hash
->root
.root
.root
.string
,
2892 (int) rel
->r_addend
& 0xffffffff);
2896 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
2897 stub_name
= bfd_malloc (len
);
2898 if (stub_name
!= NULL
)
2899 sprintf (stub_name
, "%08x_%x:%x+%x",
2900 input_section
->id
& 0xffffffff,
2901 sym_sec
->id
& 0xffffffff,
2902 (int) ELF32_R_SYM (rel
->r_info
) & 0xffffffff,
2903 (int) rel
->r_addend
& 0xffffffff);
2909 /* Look up an entry in the stub hash. Stub entries are cached because
2910 creating the stub name takes a bit of time. */
2912 static struct elf32_arm_stub_hash_entry
*
2913 elf32_arm_get_stub_entry (const asection
*input_section
,
2914 const asection
*sym_sec
,
2915 struct elf_link_hash_entry
*hash
,
2916 const Elf_Internal_Rela
*rel
,
2917 struct elf32_arm_link_hash_table
*htab
)
2919 struct elf32_arm_stub_hash_entry
*stub_entry
;
2920 struct elf32_arm_link_hash_entry
*h
= (struct elf32_arm_link_hash_entry
*) hash
;
2921 const asection
*id_sec
;
2923 if ((input_section
->flags
& SEC_CODE
) == 0)
2926 /* If this input section is part of a group of sections sharing one
2927 stub section, then use the id of the first section in the group.
2928 Stub names need to include a section id, as there may well be
2929 more than one stub used to reach say, printf, and we need to
2930 distinguish between them. */
2931 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2933 if (h
!= NULL
&& h
->stub_cache
!= NULL
2934 && h
->stub_cache
->h
== h
2935 && h
->stub_cache
->id_sec
== id_sec
)
2937 stub_entry
= h
->stub_cache
;
2943 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, h
, rel
);
2944 if (stub_name
== NULL
)
2947 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
2948 stub_name
, FALSE
, FALSE
);
2950 h
->stub_cache
= stub_entry
;
2958 /* Add a new stub entry to the stub hash. Not all fields of the new
2959 stub entry are initialised. */
2961 static struct elf32_arm_stub_hash_entry
*
2962 elf32_arm_add_stub (const char *stub_name
,
2964 struct elf32_arm_link_hash_table
*htab
)
2968 struct elf32_arm_stub_hash_entry
*stub_entry
;
2970 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2971 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2972 if (stub_sec
== NULL
)
2974 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2975 if (stub_sec
== NULL
)
2981 namelen
= strlen (link_sec
->name
);
2982 len
= namelen
+ sizeof (STUB_SUFFIX
);
2983 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2987 memcpy (s_name
, link_sec
->name
, namelen
);
2988 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2989 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2990 if (stub_sec
== NULL
)
2992 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2994 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2997 /* Enter this entry into the linker stub hash table. */
2998 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3000 if (stub_entry
== NULL
)
3002 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3008 stub_entry
->stub_sec
= stub_sec
;
3009 stub_entry
->stub_offset
= 0;
3010 stub_entry
->id_sec
= link_sec
;
3015 /* Store an Arm insn into an output section not processed by
3016 elf32_arm_write_section. */
3019 put_arm_insn (struct elf32_arm_link_hash_table
* htab
,
3020 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3022 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3023 bfd_putl32 (val
, ptr
);
3025 bfd_putb32 (val
, ptr
);
3028 /* Store a 16-bit Thumb insn into an output section not processed by
3029 elf32_arm_write_section. */
3032 put_thumb_insn (struct elf32_arm_link_hash_table
* htab
,
3033 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3035 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3036 bfd_putl16 (val
, ptr
);
3038 bfd_putb16 (val
, ptr
);
3042 arm_build_one_stub (struct bfd_hash_entry
*gen_entry
,
3045 struct elf32_arm_stub_hash_entry
*stub_entry
;
3046 struct bfd_link_info
*info
;
3047 struct elf32_arm_link_hash_table
*htab
;
3055 const bfd_vma
*template;
3057 struct elf32_arm_link_hash_table
* globals
;
3059 /* Massage our args to the form they really have. */
3060 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3061 info
= (struct bfd_link_info
*) in_arg
;
3063 globals
= elf32_arm_hash_table (info
);
3065 htab
= elf32_arm_hash_table (info
);
3066 stub_sec
= stub_entry
->stub_sec
;
3068 /* Make a note of the offset within the stubs for this entry. */
3069 stub_entry
->stub_offset
= stub_sec
->size
;
3070 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3072 stub_bfd
= stub_sec
->owner
;
3074 /* This is the address of the start of the stub. */
3075 stub_addr
= stub_sec
->output_section
->vma
+ stub_sec
->output_offset
3076 + stub_entry
->stub_offset
;
3078 /* This is the address of the stub destination. */
3079 sym_value
= (stub_entry
->target_value
3080 + stub_entry
->target_section
->output_offset
3081 + stub_entry
->target_section
->output_section
->vma
);
3083 switch (stub_entry
->stub_type
)
3085 case arm_stub_long_branch
:
3086 template = arm_long_branch_stub
;
3087 template_size
= (sizeof (arm_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3089 case arm_thumb_v4t_stub_long_branch
:
3090 template = arm_thumb_v4t_long_branch_stub
;
3091 template_size
= (sizeof (arm_thumb_v4t_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3093 case arm_thumb_thumb_stub_long_branch
:
3094 template = arm_thumb_thumb_long_branch_stub
;
3095 template_size
= (sizeof (arm_thumb_thumb_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3097 case arm_thumb_arm_v4t_stub_long_branch
:
3098 template = arm_thumb_arm_v4t_long_branch_stub
;
3099 template_size
= (sizeof (arm_thumb_arm_v4t_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3101 case arm_stub_pic_long_branch
:
3102 template = arm_pic_long_branch_stub
;
3103 template_size
= (sizeof (arm_pic_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3111 for (i
= 0; i
< (template_size
/ 4); i
++)
3113 /* A 0 pattern is a placeholder, every other pattern is an
3115 if (template[i
] != 0)
3116 put_arm_insn (globals
, stub_bfd
, template[i
], loc
+ size
);
3118 bfd_put_32 (stub_bfd
, template[i
], loc
+ size
);
3122 stub_sec
->size
+= size
;
3124 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3125 if (stub_entry
->st_type
== STT_ARM_TFUNC
)
3128 switch (stub_entry
->stub_type
)
3130 case arm_stub_long_branch
:
3131 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32
),
3132 stub_bfd
, stub_sec
, stub_sec
->contents
,
3133 stub_entry
->stub_offset
+ 4, sym_value
, 0);
3135 case arm_thumb_v4t_stub_long_branch
:
3136 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32
),
3137 stub_bfd
, stub_sec
, stub_sec
->contents
,
3138 stub_entry
->stub_offset
+ 8, sym_value
, 0);
3140 case arm_thumb_thumb_stub_long_branch
:
3141 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32
),
3142 stub_bfd
, stub_sec
, stub_sec
->contents
,
3143 stub_entry
->stub_offset
+ 12, sym_value
, 0);
3145 case arm_thumb_arm_v4t_stub_long_branch
:
3146 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32
),
3147 stub_bfd
, stub_sec
, stub_sec
->contents
,
3148 stub_entry
->stub_offset
+ 16, sym_value
, 0);
3150 case arm_stub_pic_long_branch
:
3151 /* We want the value relative to the address 8 bytes from the
3152 start of the stub. */
3153 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_REL32
),
3154 stub_bfd
, stub_sec
, stub_sec
->contents
,
3155 stub_entry
->stub_offset
+ 8, sym_value
, 0);
3164 /* As above, but don't actually build the stub. Just bump offset so
3165 we know stub section sizes. */
3168 arm_size_one_stub (struct bfd_hash_entry
*gen_entry
,
3171 struct elf32_arm_stub_hash_entry
*stub_entry
;
3172 struct elf32_arm_link_hash_table
*htab
;
3173 const bfd_vma
*template;
3178 /* Massage our args to the form they really have. */
3179 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
3180 htab
= (struct elf32_arm_link_hash_table
*) in_arg
;
3182 switch (stub_entry
->stub_type
)
3184 case arm_stub_long_branch
:
3185 template = arm_long_branch_stub
;
3186 template_size
= (sizeof (arm_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3188 case arm_thumb_v4t_stub_long_branch
:
3189 template = arm_thumb_v4t_long_branch_stub
;
3190 template_size
= (sizeof (arm_thumb_v4t_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3192 case arm_thumb_thumb_stub_long_branch
:
3193 template = arm_thumb_thumb_long_branch_stub
;
3194 template_size
= (sizeof (arm_thumb_thumb_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3196 case arm_thumb_arm_v4t_stub_long_branch
:
3197 template = arm_thumb_arm_v4t_long_branch_stub
;
3198 template_size
= (sizeof (arm_thumb_arm_v4t_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3200 case arm_stub_pic_long_branch
:
3201 template = arm_pic_long_branch_stub
;
3202 template_size
= (sizeof (arm_pic_long_branch_stub
) / sizeof (bfd_vma
)) * 4;
3211 for (i
= 0; i
< (template_size
/ 4); i
++)
3213 size
= (size
+ 7) & ~7;
3214 stub_entry
->stub_sec
->size
+= size
;
3218 /* External entry points for sizing and building linker stubs. */
3220 /* Set up various things so that we can make a list of input sections
3221 for each output section included in the link. Returns -1 on error,
3222 0 when no stubs will be needed, and 1 on success. */
3225 elf32_arm_setup_section_lists (bfd
*output_bfd
,
3226 struct bfd_link_info
*info
)
3229 unsigned int bfd_count
;
3230 int top_id
, top_index
;
3232 asection
**input_list
, **list
;
3234 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3236 if (! is_elf_hash_table (htab
))
3239 /* Count the number of input BFDs and find the top input section id. */
3240 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
3242 input_bfd
= input_bfd
->link_next
)
3245 for (section
= input_bfd
->sections
;
3247 section
= section
->next
)
3249 if (top_id
< section
->id
)
3250 top_id
= section
->id
;
3253 htab
->bfd_count
= bfd_count
;
3255 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
3256 htab
->stub_group
= bfd_zmalloc (amt
);
3257 if (htab
->stub_group
== NULL
)
3260 /* We can't use output_bfd->section_count here to find the top output
3261 section index as some sections may have been removed, and
3262 _bfd_strip_section_from_output doesn't renumber the indices. */
3263 for (section
= output_bfd
->sections
, top_index
= 0;
3265 section
= section
->next
)
3267 if (top_index
< section
->index
)
3268 top_index
= section
->index
;
3271 htab
->top_index
= top_index
;
3272 amt
= sizeof (asection
*) * (top_index
+ 1);
3273 input_list
= bfd_malloc (amt
);
3274 htab
->input_list
= input_list
;
3275 if (input_list
== NULL
)
3278 /* For sections we aren't interested in, mark their entries with a
3279 value we can check later. */
3280 list
= input_list
+ top_index
;
3282 *list
= bfd_abs_section_ptr
;
3283 while (list
-- != input_list
);
3285 for (section
= output_bfd
->sections
;
3287 section
= section
->next
)
3289 if ((section
->flags
& SEC_CODE
) != 0)
3290 input_list
[section
->index
] = NULL
;
3296 /* The linker repeatedly calls this function for each input section,
3297 in the order that input sections are linked into output sections.
3298 Build lists of input sections to determine groupings between which
3299 we may insert linker stubs. */
3302 elf32_arm_next_input_section (struct bfd_link_info
*info
,
3305 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3307 if (isec
->output_section
->index
<= htab
->top_index
)
3309 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
3311 if (*list
!= bfd_abs_section_ptr
)
3313 /* Steal the link_sec pointer for our list. */
3314 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3315 /* This happens to make the list in reverse order,
3316 which is what we want. */
3317 PREV_SEC (isec
) = *list
;
3323 /* See whether we can group stub sections together. Grouping stub
3324 sections may result in fewer stubs. More importantly, we need to
3325 put all .init* and .fini* stubs at the beginning of the .init or
3326 .fini output sections respectively, because glibc splits the
3327 _init and _fini functions into multiple parts. Putting a stub in
3328 the middle of a function is not a good idea. */
3331 group_sections (struct elf32_arm_link_hash_table
*htab
,
3332 bfd_size_type stub_group_size
,
3333 bfd_boolean stubs_always_before_branch
)
3335 asection
**list
= htab
->input_list
+ htab
->top_index
;
3339 asection
*tail
= *list
;
3341 if (tail
== bfd_abs_section_ptr
)
3344 while (tail
!= NULL
)
3348 bfd_size_type total
;
3352 while ((prev
= PREV_SEC (curr
)) != NULL
3353 && ((total
+= curr
->output_offset
- prev
->output_offset
)
3357 /* OK, the size from the start of CURR to the end is less
3358 than stub_group_size and thus can be handled by one stub
3359 section. (Or the tail section is itself larger than
3360 stub_group_size, in which case we may be toast.)
3361 We should really be keeping track of the total size of
3362 stubs added here, as stubs contribute to the final output
3366 prev
= PREV_SEC (tail
);
3367 /* Set up this stub group. */
3368 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3370 while (tail
!= curr
&& (tail
= prev
) != NULL
);
3372 /* But wait, there's more! Input sections up to stub_group_size
3373 bytes before the stub section can be handled by it too. */
3374 if (!stubs_always_before_branch
)
3378 && ((total
+= tail
->output_offset
- prev
->output_offset
)
3382 prev
= PREV_SEC (tail
);
3383 htab
->stub_group
[tail
->id
].link_sec
= curr
;
3389 while (list
-- != htab
->input_list
);
3391 free (htab
->input_list
);
3395 /* Determine and set the size of the stub section for a final link.
3397 The basic idea here is to examine all the relocations looking for
3398 PC-relative calls to a target that is unreachable with a "bl"
3402 elf32_arm_size_stubs (bfd
*output_bfd
,
3404 struct bfd_link_info
*info
,
3405 bfd_signed_vma group_size
,
3406 asection
* (*add_stub_section
) (const char *, asection
*),
3407 void (*layout_sections_again
) (void))
3409 bfd_size_type stub_group_size
;
3410 bfd_boolean stubs_always_before_branch
;
3411 bfd_boolean stub_changed
= 0;
3412 struct elf32_arm_link_hash_table
*htab
= elf32_arm_hash_table (info
);
3414 /* Propagate mach to stub bfd, because it may not have been
3415 finalized when we created stub_bfd. */
3416 bfd_set_arch_mach (stub_bfd
, bfd_get_arch (output_bfd
),
3417 bfd_get_mach (output_bfd
));
3419 /* Stash our params away. */
3420 htab
->stub_bfd
= stub_bfd
;
3421 htab
->add_stub_section
= add_stub_section
;
3422 htab
->layout_sections_again
= layout_sections_again
;
3423 stubs_always_before_branch
= group_size
< 0;
3425 stub_group_size
= -group_size
;
3427 stub_group_size
= group_size
;
3429 if (stub_group_size
== 1)
3431 /* Default values. */
3432 /* Thumb branch range is +-4MB has to be used as the default
3433 maximum size (a given section can contain both ARM and Thumb
3434 code, so the worst case has to be taken into account).
3436 This value is 24K less than that, which allows for 2025
3437 12-byte stubs. If we exceed that, then we will fail to link.
3438 The user will have to relink with an explicit group size
3440 stub_group_size
= 4170000;
3443 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
3448 unsigned int bfd_indx
;
3451 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
3453 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
3455 Elf_Internal_Shdr
*symtab_hdr
;
3457 Elf_Internal_Sym
*local_syms
= NULL
;
3459 /* We'll need the symbol table in a second. */
3460 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3461 if (symtab_hdr
->sh_info
== 0)
3464 /* Walk over each section attached to the input bfd. */
3465 for (section
= input_bfd
->sections
;
3467 section
= section
->next
)
3469 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
3471 /* If there aren't any relocs, then there's nothing more
3473 if ((section
->flags
& SEC_RELOC
) == 0
3474 || section
->reloc_count
== 0
3475 || (section
->flags
& SEC_CODE
) == 0)
3478 /* If this section is a link-once section that will be
3479 discarded, then don't create any stubs. */
3480 if (section
->output_section
== NULL
3481 || section
->output_section
->owner
!= output_bfd
)
3484 /* Get the relocs. */
3486 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
3487 NULL
, info
->keep_memory
);
3488 if (internal_relocs
== NULL
)
3489 goto error_ret_free_local
;
3491 /* Now examine each relocation. */
3492 irela
= internal_relocs
;
3493 irelaend
= irela
+ section
->reloc_count
;
3494 for (; irela
< irelaend
; irela
++)
3496 unsigned int r_type
, r_indx
;
3497 enum elf32_arm_stub_type stub_type
;
3498 struct elf32_arm_stub_hash_entry
*stub_entry
;
3501 bfd_vma destination
;
3502 struct elf32_arm_link_hash_entry
*hash
;
3503 const char *sym_name
;
3505 const asection
*id_sec
;
3506 unsigned char st_type
;
3508 r_type
= ELF32_R_TYPE (irela
->r_info
);
3509 r_indx
= ELF32_R_SYM (irela
->r_info
);
3511 if (r_type
>= (unsigned int) R_ARM_max
)
3513 bfd_set_error (bfd_error_bad_value
);
3514 error_ret_free_internal
:
3515 if (elf_section_data (section
)->relocs
== NULL
)
3516 free (internal_relocs
);
3517 goto error_ret_free_local
;
3520 /* Only look for stubs on call instructions. */
3521 if ((r_type
!= (unsigned int) R_ARM_CALL
)
3522 && (r_type
!= (unsigned int) R_ARM_THM_CALL
))
3525 /* Now determine the call target, its name, value,
3532 if (r_indx
< symtab_hdr
->sh_info
)
3534 /* It's a local symbol. */
3535 Elf_Internal_Sym
*sym
;
3536 Elf_Internal_Shdr
*hdr
;
3538 if (local_syms
== NULL
)
3541 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3542 if (local_syms
== NULL
)
3544 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3545 symtab_hdr
->sh_info
, 0,
3547 if (local_syms
== NULL
)
3548 goto error_ret_free_internal
;
3551 sym
= local_syms
+ r_indx
;
3552 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
3553 sym_sec
= hdr
->bfd_section
;
3554 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
3555 sym_value
= sym
->st_value
;
3556 destination
= (sym_value
+ irela
->r_addend
3557 + sym_sec
->output_offset
3558 + sym_sec
->output_section
->vma
);
3559 st_type
= ELF_ST_TYPE (sym
->st_info
);
3561 = bfd_elf_string_from_elf_section (input_bfd
,
3562 symtab_hdr
->sh_link
,
3567 /* It's an external symbol. */
3570 e_indx
= r_indx
- symtab_hdr
->sh_info
;
3571 hash
= ((struct elf32_arm_link_hash_entry
*)
3572 elf_sym_hashes (input_bfd
)[e_indx
]);
3574 while (hash
->root
.root
.type
== bfd_link_hash_indirect
3575 || hash
->root
.root
.type
== bfd_link_hash_warning
)
3576 hash
= ((struct elf32_arm_link_hash_entry
*)
3577 hash
->root
.root
.u
.i
.link
);
3579 if (hash
->root
.root
.type
== bfd_link_hash_defined
3580 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
3582 sym_sec
= hash
->root
.root
.u
.def
.section
;
3583 sym_value
= hash
->root
.root
.u
.def
.value
;
3584 if (sym_sec
->output_section
!= NULL
)
3585 destination
= (sym_value
+ irela
->r_addend
3586 + sym_sec
->output_offset
3587 + sym_sec
->output_section
->vma
);
3589 else if (hash
->root
.root
.type
== bfd_link_hash_undefweak
3590 || hash
->root
.root
.type
== bfd_link_hash_undefined
)
3591 /* For a shared library, these will need a PLT stub,
3592 which is treated separately.
3593 For absolute code, they cannot be handled. */
3597 bfd_set_error (bfd_error_bad_value
);
3598 goto error_ret_free_internal
;
3600 st_type
= ELF_ST_TYPE (hash
->root
.type
);
3601 sym_name
= hash
->root
.root
.root
.string
;
3604 /* Determine what (if any) linker stub is needed. */
3605 stub_type
= arm_type_of_stub (info
, section
, irela
, st_type
,
3607 if (stub_type
== arm_stub_none
)
3610 /* Support for grouping stub sections. */
3611 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
3613 /* Get the name of this stub. */
3614 stub_name
= elf32_arm_stub_name (id_sec
, sym_sec
, hash
, irela
);
3616 goto error_ret_free_internal
;
3618 stub_entry
= arm_stub_hash_lookup (&htab
->stub_hash_table
,
3621 if (stub_entry
!= NULL
)
3623 /* The proper stub has already been created. */
3628 stub_entry
= elf32_arm_add_stub (stub_name
, section
, htab
);
3629 if (stub_entry
== NULL
)
3632 goto error_ret_free_internal
;
3635 stub_entry
->target_value
= sym_value
;
3636 stub_entry
->target_section
= sym_sec
;
3637 stub_entry
->stub_type
= stub_type
;
3638 stub_entry
->h
= hash
;
3639 stub_entry
->st_type
= st_type
;
3641 if (sym_name
== NULL
)
3642 sym_name
= "unnamed";
3643 stub_entry
->output_name
3644 = bfd_alloc (htab
->stub_bfd
,
3645 sizeof (THUMB2ARM_GLUE_ENTRY_NAME
)
3646 + strlen (sym_name
));
3647 if (stub_entry
->output_name
== NULL
)
3650 goto error_ret_free_internal
;
3653 /* For historical reasons, use the existing names for
3654 ARM-to-Thumb and Thumb-to-ARM stubs. */
3655 if (r_type
== (unsigned int) R_ARM_THM_CALL
3656 && st_type
!= STT_ARM_TFUNC
)
3657 sprintf (stub_entry
->output_name
, THUMB2ARM_GLUE_ENTRY_NAME
,
3659 else if (r_type
== (unsigned int) R_ARM_CALL
3660 && st_type
== STT_ARM_TFUNC
)
3661 sprintf (stub_entry
->output_name
, ARM2THUMB_GLUE_ENTRY_NAME
,
3664 sprintf (stub_entry
->output_name
, STUB_ENTRY_NAME
,
3667 stub_changed
= TRUE
;
3670 /* We're done with the internal relocs, free them. */
3671 if (elf_section_data (section
)->relocs
== NULL
)
3672 free (internal_relocs
);
3679 /* OK, we've added some stubs. Find out the new size of the
3681 for (stub_sec
= htab
->stub_bfd
->sections
;
3683 stub_sec
= stub_sec
->next
)
3686 bfd_hash_traverse (&htab
->stub_hash_table
, arm_size_one_stub
, htab
);
3688 /* Ask the linker to do its stuff. */
3689 (*htab
->layout_sections_again
) ();
3690 stub_changed
= FALSE
;
3695 error_ret_free_local
:
3699 /* Build all the stubs associated with the current output file. The
3700 stubs are kept in a hash table attached to the main linker hash
3701 table. We also set up the .plt entries for statically linked PIC
3702 functions here. This function is called via arm_elf_finish in the
3706 elf32_arm_build_stubs (struct bfd_link_info
*info
)
3709 struct bfd_hash_table
*table
;
3710 struct elf32_arm_link_hash_table
*htab
;
3712 htab
= elf32_arm_hash_table (info
);
3714 for (stub_sec
= htab
->stub_bfd
->sections
;
3716 stub_sec
= stub_sec
->next
)
3720 /* Ignore non-stub sections. */
3721 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
3724 /* Allocate memory to hold the linker stubs. */
3725 size
= stub_sec
->size
;
3726 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
3727 if (stub_sec
->contents
== NULL
&& size
!= 0)
3732 /* Build the stubs as directed by the stub hash table. */
3733 table
= &htab
->stub_hash_table
;
3734 bfd_hash_traverse (table
, arm_build_one_stub
, info
);
3739 /* Locate the Thumb encoded calling stub for NAME. */
3741 static struct elf_link_hash_entry
*
3742 find_thumb_glue (struct bfd_link_info
*link_info
,
3744 char **error_message
)
3747 struct elf_link_hash_entry
*hash
;
3748 struct elf32_arm_link_hash_table
*hash_table
;
3750 /* We need a pointer to the armelf specific hash table. */
3751 hash_table
= elf32_arm_hash_table (link_info
);
3753 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
3754 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
3756 BFD_ASSERT (tmp_name
);
3758 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
3760 hash
= elf_link_hash_lookup
3761 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
3764 && asprintf (error_message
, _("unable to find THUMB glue '%s' for '%s'"),
3765 tmp_name
, name
) == -1)
3766 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
3773 /* Locate the ARM encoded calling stub for NAME. */
3775 static struct elf_link_hash_entry
*
3776 find_arm_glue (struct bfd_link_info
*link_info
,
3778 char **error_message
)
3781 struct elf_link_hash_entry
*myh
;
3782 struct elf32_arm_link_hash_table
*hash_table
;
3784 /* We need a pointer to the elfarm specific hash table. */
3785 hash_table
= elf32_arm_hash_table (link_info
);
3787 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
3788 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
3790 BFD_ASSERT (tmp_name
);
3792 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
3794 myh
= elf_link_hash_lookup
3795 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
3798 && asprintf (error_message
, _("unable to find ARM glue '%s' for '%s'"),
3799 tmp_name
, name
) == -1)
3800 *error_message
= (char *) bfd_errmsg (bfd_error_system_call
);
3807 /* ARM->Thumb glue (static images):
3811 ldr r12, __func_addr
3814 .word func @ behave as if you saw a ARM_32 reloc.
3821 .word func @ behave as if you saw a ARM_32 reloc.
3823 (relocatable images)
3826 ldr r12, __func_offset
3832 #define ARM2THUMB_STATIC_GLUE_SIZE 12
3833 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
3834 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
3835 static const insn32 a2t3_func_addr_insn
= 0x00000001;
3837 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
3838 static const insn32 a2t1v5_ldr_insn
= 0xe51ff004;
3839 static const insn32 a2t2v5_func_addr_insn
= 0x00000001;
3841 #define ARM2THUMB_PIC_GLUE_SIZE 16
3842 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
3843 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
3844 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
3846 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
3850 __func_from_thumb: __func_from_thumb:
3852 nop ldr r6, __func_addr
3855 ;; back_to_thumb .arm
3856 ldmia r13! {r6, lr} ldmia r13! {r6, lr}
3861 #define THUMB2ARM_GLUE_SIZE 8
3862 static const insn16 t2a1_bx_pc_insn
= 0x4778;
3863 static const insn16 t2a2_noop_insn
= 0x46c0;
3864 static const insn32 t2a3_b_insn
= 0xea000000;
3866 #define VFP11_ERRATUM_VENEER_SIZE 8
3868 #define ARM_BX_VENEER_SIZE 12
3869 static const insn32 armbx1_tst_insn
= 0xe3100001;
3870 static const insn32 armbx2_moveq_insn
= 0x01a0f000;
3871 static const insn32 armbx3_bx_insn
= 0xe12fff10;
3873 #ifndef ELFARM_NABI_C_INCLUDED
3875 arm_allocate_glue_section_space (bfd
* abfd
, bfd_size_type size
, const char * name
)
3878 bfd_byte
* contents
;
3883 BFD_ASSERT (abfd
!= NULL
);
3885 s
= bfd_get_section_by_name (abfd
, name
);
3886 BFD_ASSERT (s
!= NULL
);
3888 contents
= bfd_alloc (abfd
, size
);
3890 BFD_ASSERT (s
->size
== size
);
3891 s
->contents
= contents
;
3895 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
3897 struct elf32_arm_link_hash_table
* globals
;
3899 globals
= elf32_arm_hash_table (info
);
3900 BFD_ASSERT (globals
!= NULL
);
3902 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
3903 globals
->arm_glue_size
,
3904 ARM2THUMB_GLUE_SECTION_NAME
);
3906 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
3907 globals
->thumb_glue_size
,
3908 THUMB2ARM_GLUE_SECTION_NAME
);
3910 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
3911 globals
->vfp11_erratum_glue_size
,
3912 VFP11_ERRATUM_VENEER_SECTION_NAME
);
3914 arm_allocate_glue_section_space (globals
->bfd_of_glue_owner
,
3915 globals
->bx_glue_size
,
3916 ARM_BX_GLUE_SECTION_NAME
);
3921 /* Allocate space and symbols for calling a Thumb function from Arm mode.
3922 returns the symbol identifying the stub. */
3924 static struct elf_link_hash_entry
*
3925 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
3926 struct elf_link_hash_entry
* h
)
3928 const char * name
= h
->root
.root
.string
;
3931 struct elf_link_hash_entry
* myh
;
3932 struct bfd_link_hash_entry
* bh
;
3933 struct elf32_arm_link_hash_table
* globals
;
3937 globals
= elf32_arm_hash_table (link_info
);
3939 BFD_ASSERT (globals
!= NULL
);
3940 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
3942 s
= bfd_get_section_by_name
3943 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
3945 BFD_ASSERT (s
!= NULL
);
3947 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
3949 BFD_ASSERT (tmp_name
);
3951 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
3953 myh
= elf_link_hash_lookup
3954 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
3958 /* We've already seen this guy. */
3963 /* The only trick here is using hash_table->arm_glue_size as the value.
3964 Even though the section isn't allocated yet, this is where we will be
3965 putting it. The +1 on the value marks that the stub has not been
3966 output yet - not that it is a Thumb function. */
3968 val
= globals
->arm_glue_size
+ 1;
3969 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
3970 tmp_name
, BSF_GLOBAL
, s
, val
,
3971 NULL
, TRUE
, FALSE
, &bh
);
3973 myh
= (struct elf_link_hash_entry
*) bh
;
3974 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
3975 myh
->forced_local
= 1;
3979 if (link_info
->shared
|| globals
->root
.is_relocatable_executable
3980 || globals
->pic_veneer
)
3981 size
= ARM2THUMB_PIC_GLUE_SIZE
;
3982 else if (globals
->use_blx
)
3983 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
3985 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
3988 globals
->arm_glue_size
+= size
;
3994 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
3995 struct elf_link_hash_entry
*h
)
3997 const char *name
= h
->root
.root
.string
;
4000 struct elf_link_hash_entry
*myh
;
4001 struct bfd_link_hash_entry
*bh
;
4002 struct elf32_arm_link_hash_table
*hash_table
;
4005 hash_table
= elf32_arm_hash_table (link_info
);
4007 BFD_ASSERT (hash_table
!= NULL
);
4008 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
4010 s
= bfd_get_section_by_name
4011 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
4013 BFD_ASSERT (s
!= NULL
);
4015 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4016 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
4018 BFD_ASSERT (tmp_name
);
4020 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
4022 myh
= elf_link_hash_lookup
4023 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
4027 /* We've already seen this guy. */
4032 /* The only trick here is using hash_table->thumb_glue_size as the value.
4033 Even though the section isn't allocated yet, this is where we will be
4034 putting it. The +1 on the value marks that the stub has not been
4035 output yet - not that it is a Thumb function. */
4037 val
= hash_table
->thumb_glue_size
+ 1;
4038 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
4039 tmp_name
, BSF_GLOBAL
, s
, val
,
4040 NULL
, TRUE
, FALSE
, &bh
);
4042 /* If we mark it 'Thumb', the disassembler will do a better job. */
4043 myh
= (struct elf_link_hash_entry
*) bh
;
4044 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
4045 myh
->forced_local
= 1;
4049 #define CHANGE_TO_ARM "__%s_change_to_arm"
4050 #define BACK_FROM_ARM "__%s_back_from_arm"
4052 /* Allocate another symbol to mark where we switch to Arm mode. */
4053 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
4054 + strlen (CHANGE_TO_ARM
) + 1);
4056 BFD_ASSERT (tmp_name
);
4058 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
4061 val
= hash_table
->thumb_glue_size
+ 4,
4062 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
4063 tmp_name
, BSF_LOCAL
, s
, val
,
4064 NULL
, TRUE
, FALSE
, &bh
);
4068 s
->size
+= THUMB2ARM_GLUE_SIZE
;
4069 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
4073 /* Allocate space for ARMv4 BX veneers. */
4076 record_arm_bx_glue (struct bfd_link_info
* link_info
, int reg
)
4079 struct elf32_arm_link_hash_table
*globals
;
4081 struct elf_link_hash_entry
*myh
;
4082 struct bfd_link_hash_entry
*bh
;
4085 /* BX PC does not need a veneer. */
4089 globals
= elf32_arm_hash_table (link_info
);
4091 BFD_ASSERT (globals
!= NULL
);
4092 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
4094 /* Check if this veneer has already been allocated. */
4095 if (globals
->bx_glue_offset
[reg
])
4098 s
= bfd_get_section_by_name
4099 (globals
->bfd_of_glue_owner
, ARM_BX_GLUE_SECTION_NAME
);
4101 BFD_ASSERT (s
!= NULL
);
4103 /* Add symbol for veneer. */
4104 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (ARM_BX_GLUE_ENTRY_NAME
) + 1);
4106 BFD_ASSERT (tmp_name
);
4108 sprintf (tmp_name
, ARM_BX_GLUE_ENTRY_NAME
, reg
);
4110 myh
= elf_link_hash_lookup
4111 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4113 BFD_ASSERT (myh
== NULL
);
4116 val
= globals
->bx_glue_size
;
4117 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
4118 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
4119 NULL
, TRUE
, FALSE
, &bh
);
4121 myh
= (struct elf_link_hash_entry
*) bh
;
4122 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4123 myh
->forced_local
= 1;
4125 s
->size
+= ARM_BX_VENEER_SIZE
;
4126 globals
->bx_glue_offset
[reg
] = globals
->bx_glue_size
| 2;
4127 globals
->bx_glue_size
+= ARM_BX_VENEER_SIZE
;
4131 /* Add an entry to the code/data map for section SEC. */
4134 elf32_arm_section_map_add (asection
*sec
, char type
, bfd_vma vma
)
4136 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
4137 unsigned int newidx
;
4139 if (sec_data
->map
== NULL
)
4141 sec_data
->map
= bfd_malloc (sizeof (elf32_arm_section_map
));
4142 sec_data
->mapcount
= 0;
4143 sec_data
->mapsize
= 1;
4146 newidx
= sec_data
->mapcount
++;
4148 if (sec_data
->mapcount
> sec_data
->mapsize
)
4150 sec_data
->mapsize
*= 2;
4151 sec_data
->map
= bfd_realloc_or_free (sec_data
->map
, sec_data
->mapsize
4152 * sizeof (elf32_arm_section_map
));
4157 sec_data
->map
[newidx
].vma
= vma
;
4158 sec_data
->map
[newidx
].type
= type
;
4163 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4164 veneers are handled for now. */
4167 record_vfp11_erratum_veneer (struct bfd_link_info
*link_info
,
4168 elf32_vfp11_erratum_list
*branch
,
4170 asection
*branch_sec
,
4171 unsigned int offset
)
4174 struct elf32_arm_link_hash_table
*hash_table
;
4176 struct elf_link_hash_entry
*myh
;
4177 struct bfd_link_hash_entry
*bh
;
4179 struct _arm_elf_section_data
*sec_data
;
4181 elf32_vfp11_erratum_list
*newerr
;
4183 hash_table
= elf32_arm_hash_table (link_info
);
4185 BFD_ASSERT (hash_table
!= NULL
);
4186 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
4188 s
= bfd_get_section_by_name
4189 (hash_table
->bfd_of_glue_owner
, VFP11_ERRATUM_VENEER_SECTION_NAME
);
4191 sec_data
= elf32_arm_section_data (s
);
4193 BFD_ASSERT (s
!= NULL
);
4195 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
4196 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
4198 BFD_ASSERT (tmp_name
);
4200 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
4201 hash_table
->num_vfp11_fixes
);
4203 myh
= elf_link_hash_lookup
4204 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4206 BFD_ASSERT (myh
== NULL
);
4209 val
= hash_table
->vfp11_erratum_glue_size
;
4210 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
4211 tmp_name
, BSF_FUNCTION
| BSF_LOCAL
, s
, val
,
4212 NULL
, TRUE
, FALSE
, &bh
);
4214 myh
= (struct elf_link_hash_entry
*) bh
;
4215 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4216 myh
->forced_local
= 1;
4218 /* Link veneer back to calling location. */
4219 errcount
= ++(sec_data
->erratumcount
);
4220 newerr
= bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
4222 newerr
->type
= VFP11_ERRATUM_ARM_VENEER
;
4224 newerr
->u
.v
.branch
= branch
;
4225 newerr
->u
.v
.id
= hash_table
->num_vfp11_fixes
;
4226 branch
->u
.b
.veneer
= newerr
;
4228 newerr
->next
= sec_data
->erratumlist
;
4229 sec_data
->erratumlist
= newerr
;
4231 /* A symbol for the return from the veneer. */
4232 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
4233 hash_table
->num_vfp11_fixes
);
4235 myh
= elf_link_hash_lookup
4236 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, FALSE
);
4243 _bfd_generic_link_add_one_symbol (link_info
, branch_bfd
, tmp_name
, BSF_LOCAL
,
4244 branch_sec
, val
, NULL
, TRUE
, FALSE
, &bh
);
4246 myh
= (struct elf_link_hash_entry
*) bh
;
4247 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
4248 myh
->forced_local
= 1;
4252 /* Generate a mapping symbol for the veneer section, and explicitly add an
4253 entry for that symbol to the code/data map for the section. */
4254 if (hash_table
->vfp11_erratum_glue_size
== 0)
4257 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4258 ever requires this erratum fix. */
4259 _bfd_generic_link_add_one_symbol (link_info
,
4260 hash_table
->bfd_of_glue_owner
, "$a",
4261 BSF_LOCAL
, s
, 0, NULL
,
4264 myh
= (struct elf_link_hash_entry
*) bh
;
4265 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
4266 myh
->forced_local
= 1;
4268 /* The elf32_arm_init_maps function only cares about symbols from input
4269 BFDs. We must make a note of this generated mapping symbol
4270 ourselves so that code byteswapping works properly in
4271 elf32_arm_write_section. */
4272 elf32_arm_section_map_add (s
, 'a', 0);
4275 s
->size
+= VFP11_ERRATUM_VENEER_SIZE
;
4276 hash_table
->vfp11_erratum_glue_size
+= VFP11_ERRATUM_VENEER_SIZE
;
4277 hash_table
->num_vfp11_fixes
++;
4279 /* The offset of the veneer. */
4283 /* Note: we do not include the flag SEC_LINKER_CREATED, as that
4284 would prevent elf_link_input_bfd() from processing the contents
4286 #define ARM_GLUE_SECTION_FLAGS \
4287 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY)
4289 /* Create a fake section for use by the ARM backend of the linker. */
4292 arm_make_glue_section (bfd
* abfd
, const char * name
)
4296 sec
= bfd_get_section_by_name (abfd
, name
);
4301 sec
= bfd_make_section_with_flags (abfd
, name
, ARM_GLUE_SECTION_FLAGS
);
4304 || !bfd_set_section_alignment (abfd
, sec
, 2))
4307 /* Set the gc mark to prevent the section from being removed by garbage
4308 collection, despite the fact that no relocs refer to this section. */
4314 /* Add the glue sections to ABFD. This function is called from the
4315 linker scripts in ld/emultempl/{armelf}.em. */
4318 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
4319 struct bfd_link_info
*info
)
4321 /* If we are only performing a partial
4322 link do not bother adding the glue. */
4323 if (info
->relocatable
)
4326 /* Linker stubs don't need glue. */
4327 if (!strcmp (abfd
->filename
, "linker stubs"))
4330 return arm_make_glue_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
)
4331 && arm_make_glue_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
)
4332 && arm_make_glue_section (abfd
, VFP11_ERRATUM_VENEER_SECTION_NAME
)
4333 && arm_make_glue_section (abfd
, ARM_BX_GLUE_SECTION_NAME
);
4336 /* Select a BFD to be used to hold the sections used by the glue code.
4337 This function is called from the linker scripts in ld/emultempl/
4341 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
4343 struct elf32_arm_link_hash_table
*globals
;
4345 /* If we are only performing a partial link
4346 do not bother getting a bfd to hold the glue. */
4347 if (info
->relocatable
)
4350 /* Make sure we don't attach the glue sections to a dynamic object. */
4351 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
4353 globals
= elf32_arm_hash_table (info
);
4355 BFD_ASSERT (globals
!= NULL
);
4357 if (globals
->bfd_of_glue_owner
!= NULL
)
4360 /* Save the bfd for later use. */
4361 globals
->bfd_of_glue_owner
= abfd
;
4367 check_use_blx (struct elf32_arm_link_hash_table
*globals
)
4369 if (bfd_elf_get_obj_attr_int (globals
->obfd
, OBJ_ATTR_PROC
,
4371 globals
->use_blx
= 1;
4375 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
4376 struct bfd_link_info
*link_info
)
4378 Elf_Internal_Shdr
*symtab_hdr
;
4379 Elf_Internal_Rela
*internal_relocs
= NULL
;
4380 Elf_Internal_Rela
*irel
, *irelend
;
4381 bfd_byte
*contents
= NULL
;
4384 struct elf32_arm_link_hash_table
*globals
;
4386 /* If we are only performing a partial link do not bother
4387 to construct any glue. */
4388 if (link_info
->relocatable
)
4391 /* Here we have a bfd that is to be included on the link. We have a
4392 hook to do reloc rummaging, before section sizes are nailed down. */
4393 globals
= elf32_arm_hash_table (link_info
);
4395 BFD_ASSERT (globals
!= NULL
);
4397 check_use_blx (globals
);
4399 if (globals
->byteswap_code
&& !bfd_big_endian (abfd
))
4401 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4406 /* PR 5398: If we have not decided to include any loadable sections in
4407 the output then we will not have a glue owner bfd. This is OK, it
4408 just means that there is nothing else for us to do here. */
4409 if (globals
->bfd_of_glue_owner
== NULL
)
4412 /* Rummage around all the relocs and map the glue vectors. */
4413 sec
= abfd
->sections
;
4418 for (; sec
!= NULL
; sec
= sec
->next
)
4420 if (sec
->reloc_count
== 0)
4423 if ((sec
->flags
& SEC_EXCLUDE
) != 0)
4426 symtab_hdr
= & elf_symtab_hdr (abfd
);
4428 /* Load the relocs. */
4430 = _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
, FALSE
);
4432 if (internal_relocs
== NULL
)
4435 irelend
= internal_relocs
+ sec
->reloc_count
;
4436 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
4439 unsigned long r_index
;
4441 struct elf_link_hash_entry
*h
;
4443 r_type
= ELF32_R_TYPE (irel
->r_info
);
4444 r_index
= ELF32_R_SYM (irel
->r_info
);
4446 /* These are the only relocation types we care about. */
4447 if ( r_type
!= R_ARM_PC24
4448 && r_type
!= R_ARM_PLT32
4449 && r_type
!= R_ARM_JUMP24
4450 && r_type
!= R_ARM_THM_JUMP24
4451 && (r_type
!= R_ARM_V4BX
|| globals
->fix_v4bx
< 2))
4454 /* Get the section contents if we haven't done so already. */
4455 if (contents
== NULL
)
4457 /* Get cached copy if it exists. */
4458 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
4459 contents
= elf_section_data (sec
)->this_hdr
.contents
;
4462 /* Go get them off disk. */
4463 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
4468 if (r_type
== R_ARM_V4BX
)
4472 reg
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
) & 0xf;
4473 record_arm_bx_glue (link_info
, reg
);
4477 /* If the relocation is not against a symbol it cannot concern us. */
4480 /* We don't care about local symbols. */
4481 if (r_index
< symtab_hdr
->sh_info
)
4484 /* This is an external symbol. */
4485 r_index
-= symtab_hdr
->sh_info
;
4486 h
= (struct elf_link_hash_entry
*)
4487 elf_sym_hashes (abfd
)[r_index
];
4489 /* If the relocation is against a static symbol it must be within
4490 the current section and so cannot be a cross ARM/Thumb relocation. */
4494 /* If the call will go through a PLT entry then we do not need
4496 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
4504 /* This one is a call from arm code. We need to look up
4505 the target of the call. If it is a thumb target, we
4507 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
4508 && !(r_type
== R_ARM_CALL
&& globals
->use_blx
))
4509 record_arm_to_thumb_glue (link_info
, h
);
4512 case R_ARM_THM_JUMP24
:
4513 /* This one is a call from thumb code. We look
4514 up the target of the call. If it is not a thumb
4515 target, we insert glue. */
4516 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
4517 && !(globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
4518 && h
->root
.type
!= bfd_link_hash_undefweak
)
4519 record_thumb_to_arm_glue (link_info
, h
);
4527 if (contents
!= NULL
4528 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
4532 if (internal_relocs
!= NULL
4533 && elf_section_data (sec
)->relocs
!= internal_relocs
)
4534 free (internal_relocs
);
4535 internal_relocs
= NULL
;
4541 if (contents
!= NULL
4542 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
4544 if (internal_relocs
!= NULL
4545 && elf_section_data (sec
)->relocs
!= internal_relocs
)
4546 free (internal_relocs
);
4553 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4556 bfd_elf32_arm_init_maps (bfd
*abfd
)
4558 Elf_Internal_Sym
*isymbuf
;
4559 Elf_Internal_Shdr
*hdr
;
4560 unsigned int i
, localsyms
;
4562 if ((abfd
->flags
& DYNAMIC
) != 0)
4565 hdr
= & elf_symtab_hdr (abfd
);
4566 localsyms
= hdr
->sh_info
;
4568 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4569 should contain the number of local symbols, which should come before any
4570 global symbols. Mapping symbols are always local. */
4571 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, localsyms
, 0, NULL
, NULL
,
4574 /* No internal symbols read? Skip this BFD. */
4575 if (isymbuf
== NULL
)
4578 for (i
= 0; i
< localsyms
; i
++)
4580 Elf_Internal_Sym
*isym
= &isymbuf
[i
];
4581 asection
*sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4585 && ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
)
4587 name
= bfd_elf_string_from_elf_section (abfd
,
4588 hdr
->sh_link
, isym
->st_name
);
4590 if (bfd_is_arm_special_symbol_name (name
,
4591 BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
4592 elf32_arm_section_map_add (sec
, name
[1], isym
->st_value
);
4599 bfd_elf32_arm_set_vfp11_fix (bfd
*obfd
, struct bfd_link_info
*link_info
)
4601 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
4602 obj_attribute
*out_attr
= elf_known_obj_attributes_proc (obfd
);
4604 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4605 if (out_attr
[Tag_CPU_arch
].i
>= TAG_CPU_ARCH_V7
)
4607 switch (globals
->vfp11_fix
)
4609 case BFD_ARM_VFP11_FIX_DEFAULT
:
4610 case BFD_ARM_VFP11_FIX_NONE
:
4611 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
4615 /* Give a warning, but do as the user requests anyway. */
4616 (*_bfd_error_handler
) (_("%B: warning: selected VFP11 erratum "
4617 "workaround is not necessary for target architecture"), obfd
);
4620 else if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_DEFAULT
)
4621 /* For earlier architectures, we might need the workaround, but do not
4622 enable it by default. If users is running with broken hardware, they
4623 must enable the erratum fix explicitly. */
4624 globals
->vfp11_fix
= BFD_ARM_VFP11_FIX_NONE
;
4628 enum bfd_arm_vfp11_pipe
4636 /* Return a VFP register number. This is encoded as RX:X for single-precision
4637 registers, or X:RX for double-precision registers, where RX is the group of
4638 four bits in the instruction encoding and X is the single extension bit.
4639 RX and X fields are specified using their lowest (starting) bit. The return
4642 0...31: single-precision registers s0...s31
4643 32...63: double-precision registers d0...d31.
4645 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4646 encounter VFP3 instructions, so we allow the full range for DP registers. */
4649 bfd_arm_vfp11_regno (unsigned int insn
, bfd_boolean is_double
, unsigned int rx
,
4653 return (((insn
>> rx
) & 0xf) | (((insn
>> x
) & 1) << 4)) + 32;
4655 return (((insn
>> rx
) & 0xf) << 1) | ((insn
>> x
) & 1);
4658 /* Set bits in *WMASK according to a register number REG as encoded by
4659 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4662 bfd_arm_vfp11_write_mask (unsigned int *wmask
, unsigned int reg
)
4667 *wmask
|= 3 << ((reg
- 32) * 2);
4670 /* Return TRUE if WMASK overwrites anything in REGS. */
4673 bfd_arm_vfp11_antidependency (unsigned int wmask
, int *regs
, int numregs
)
4677 for (i
= 0; i
< numregs
; i
++)
4679 unsigned int reg
= regs
[i
];
4681 if (reg
< 32 && (wmask
& (1 << reg
)) != 0)
4689 if ((wmask
& (3 << (reg
* 2))) != 0)
4696 /* In this function, we're interested in two things: finding input registers
4697 for VFP data-processing instructions, and finding the set of registers which
4698 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4699 hold the written set, so FLDM etc. are easy to deal with (we're only
4700 interested in 32 SP registers or 16 dp registers, due to the VFP version
4701 implemented by the chip in question). DP registers are marked by setting
4702 both SP registers in the write mask). */
4704 static enum bfd_arm_vfp11_pipe
4705 bfd_arm_vfp11_insn_decode (unsigned int insn
, unsigned int *destmask
, int *regs
,
4708 enum bfd_arm_vfp11_pipe pipe
= VFP11_BAD
;
4709 bfd_boolean is_double
= ((insn
& 0xf00) == 0xb00) ? 1 : 0;
4711 if ((insn
& 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4714 unsigned int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
4715 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
4717 pqrs
= ((insn
& 0x00800000) >> 20)
4718 | ((insn
& 0x00300000) >> 19)
4719 | ((insn
& 0x00000040) >> 6);
4723 case 0: /* fmac[sd]. */
4724 case 1: /* fnmac[sd]. */
4725 case 2: /* fmsc[sd]. */
4726 case 3: /* fnmsc[sd]. */
4728 bfd_arm_vfp11_write_mask (destmask
, fd
);
4730 regs
[1] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
4735 case 4: /* fmul[sd]. */
4736 case 5: /* fnmul[sd]. */
4737 case 6: /* fadd[sd]. */
4738 case 7: /* fsub[sd]. */
4742 case 8: /* fdiv[sd]. */
4745 bfd_arm_vfp11_write_mask (destmask
, fd
);
4746 regs
[0] = bfd_arm_vfp11_regno (insn
, is_double
, 16, 7); /* Fn. */
4751 case 15: /* extended opcode. */
4753 unsigned int extn
= ((insn
>> 15) & 0x1e)
4754 | ((insn
>> 7) & 1);
4758 case 0: /* fcpy[sd]. */
4759 case 1: /* fabs[sd]. */
4760 case 2: /* fneg[sd]. */
4761 case 8: /* fcmp[sd]. */
4762 case 9: /* fcmpe[sd]. */
4763 case 10: /* fcmpz[sd]. */
4764 case 11: /* fcmpez[sd]. */
4765 case 16: /* fuito[sd]. */
4766 case 17: /* fsito[sd]. */
4767 case 24: /* ftoui[sd]. */
4768 case 25: /* ftouiz[sd]. */
4769 case 26: /* ftosi[sd]. */
4770 case 27: /* ftosiz[sd]. */
4771 /* These instructions will not bounce due to underflow. */
4776 case 3: /* fsqrt[sd]. */
4777 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4778 registers to cause the erratum in previous instructions. */
4779 bfd_arm_vfp11_write_mask (destmask
, fd
);
4783 case 15: /* fcvt{ds,sd}. */
4787 bfd_arm_vfp11_write_mask (destmask
, fd
);
4789 /* Only FCVTSD can underflow. */
4790 if ((insn
& 0x100) != 0)
4809 /* Two-register transfer. */
4810 else if ((insn
& 0x0fe00ed0) == 0x0c400a10)
4812 unsigned int fm
= bfd_arm_vfp11_regno (insn
, is_double
, 0, 5);
4814 if ((insn
& 0x100000) == 0)
4817 bfd_arm_vfp11_write_mask (destmask
, fm
);
4820 bfd_arm_vfp11_write_mask (destmask
, fm
);
4821 bfd_arm_vfp11_write_mask (destmask
, fm
+ 1);
4827 else if ((insn
& 0x0e100e00) == 0x0c100a00) /* A load insn. */
4829 int fd
= bfd_arm_vfp11_regno (insn
, is_double
, 12, 22);
4830 unsigned int puw
= ((insn
>> 21) & 0x1) | (((insn
>> 23) & 3) << 1);
4834 case 0: /* Two-reg transfer. We should catch these above. */
4837 case 2: /* fldm[sdx]. */
4841 unsigned int i
, offset
= insn
& 0xff;
4846 for (i
= fd
; i
< fd
+ offset
; i
++)
4847 bfd_arm_vfp11_write_mask (destmask
, i
);
4851 case 4: /* fld[sd]. */
4853 bfd_arm_vfp11_write_mask (destmask
, fd
);
4862 /* Single-register transfer. Note L==0. */
4863 else if ((insn
& 0x0f100e10) == 0x0e000a10)
4865 unsigned int opcode
= (insn
>> 21) & 7;
4866 unsigned int fn
= bfd_arm_vfp11_regno (insn
, is_double
, 16, 7);
4870 case 0: /* fmsr/fmdlr. */
4871 case 1: /* fmdhr. */
4872 /* Mark fmdhr and fmdlr as writing to the whole of the DP
4873 destination register. I don't know if this is exactly right,
4874 but it is the conservative choice. */
4875 bfd_arm_vfp11_write_mask (destmask
, fn
);
4889 static int elf32_arm_compare_mapping (const void * a
, const void * b
);
4892 /* Look for potentially-troublesome code sequences which might trigger the
4893 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
4894 (available from ARM) for details of the erratum. A short version is
4895 described in ld.texinfo. */
4898 bfd_elf32_arm_vfp11_erratum_scan (bfd
*abfd
, struct bfd_link_info
*link_info
)
4901 bfd_byte
*contents
= NULL
;
4903 int regs
[3], numregs
= 0;
4904 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
4905 int use_vector
= (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_VECTOR
);
4907 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
4908 The states transition as follows:
4910 0 -> 1 (vector) or 0 -> 2 (scalar)
4911 A VFP FMAC-pipeline instruction has been seen. Fill
4912 regs[0]..regs[numregs-1] with its input operands. Remember this
4913 instruction in 'first_fmac'.
4916 Any instruction, except for a VFP instruction which overwrites
4921 A VFP instruction has been seen which overwrites any of regs[*].
4922 We must make a veneer! Reset state to 0 before examining next
4926 If we fail to match anything in state 2, reset to state 0 and reset
4927 the instruction pointer to the instruction after 'first_fmac'.
4929 If the VFP11 vector mode is in use, there must be at least two unrelated
4930 instructions between anti-dependent VFP11 instructions to properly avoid
4931 triggering the erratum, hence the use of the extra state 1. */
4933 /* If we are only performing a partial link do not bother
4934 to construct any glue. */
4935 if (link_info
->relocatable
)
4938 /* Skip if this bfd does not correspond to an ELF image. */
4939 if (! is_arm_elf (abfd
))
4942 /* We should have chosen a fix type by the time we get here. */
4943 BFD_ASSERT (globals
->vfp11_fix
!= BFD_ARM_VFP11_FIX_DEFAULT
);
4945 if (globals
->vfp11_fix
== BFD_ARM_VFP11_FIX_NONE
)
4948 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4950 unsigned int i
, span
, first_fmac
= 0, veneer_of_insn
= 0;
4951 struct _arm_elf_section_data
*sec_data
;
4953 /* If we don't have executable progbits, we're not interested in this
4954 section. Also skip if section is to be excluded. */
4955 if (elf_section_type (sec
) != SHT_PROGBITS
4956 || (elf_section_flags (sec
) & SHF_EXECINSTR
) == 0
4957 || (sec
->flags
& SEC_EXCLUDE
) != 0
4958 || strcmp (sec
->name
, VFP11_ERRATUM_VENEER_SECTION_NAME
) == 0)
4961 sec_data
= elf32_arm_section_data (sec
);
4963 if (sec_data
->mapcount
== 0)
4966 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
4967 contents
= elf_section_data (sec
)->this_hdr
.contents
;
4968 else if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
4971 qsort (sec_data
->map
, sec_data
->mapcount
, sizeof (elf32_arm_section_map
),
4972 elf32_arm_compare_mapping
);
4974 for (span
= 0; span
< sec_data
->mapcount
; span
++)
4976 unsigned int span_start
= sec_data
->map
[span
].vma
;
4977 unsigned int span_end
= (span
== sec_data
->mapcount
- 1)
4978 ? sec
->size
: sec_data
->map
[span
+ 1].vma
;
4979 char span_type
= sec_data
->map
[span
].type
;
4981 /* FIXME: Only ARM mode is supported at present. We may need to
4982 support Thumb-2 mode also at some point. */
4983 if (span_type
!= 'a')
4986 for (i
= span_start
; i
< span_end
;)
4988 unsigned int next_i
= i
+ 4;
4989 unsigned int insn
= bfd_big_endian (abfd
)
4990 ? (contents
[i
] << 24)
4991 | (contents
[i
+ 1] << 16)
4992 | (contents
[i
+ 2] << 8)
4994 : (contents
[i
+ 3] << 24)
4995 | (contents
[i
+ 2] << 16)
4996 | (contents
[i
+ 1] << 8)
4998 unsigned int writemask
= 0;
4999 enum bfd_arm_vfp11_pipe pipe
;
5004 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
, regs
,
5006 /* I'm assuming the VFP11 erratum can trigger with denorm
5007 operands on either the FMAC or the DS pipeline. This might
5008 lead to slightly overenthusiastic veneer insertion. */
5009 if (pipe
== VFP11_FMAC
|| pipe
== VFP11_DS
)
5011 state
= use_vector
? 1 : 2;
5013 veneer_of_insn
= insn
;
5019 int other_regs
[3], other_numregs
;
5020 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5023 if (pipe
!= VFP11_BAD
5024 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5034 int other_regs
[3], other_numregs
;
5035 pipe
= bfd_arm_vfp11_insn_decode (insn
, &writemask
,
5038 if (pipe
!= VFP11_BAD
5039 && bfd_arm_vfp11_antidependency (writemask
, regs
,
5045 next_i
= first_fmac
+ 4;
5051 abort (); /* Should be unreachable. */
5056 elf32_vfp11_erratum_list
*newerr
5057 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list
));
5060 errcount
= ++(elf32_arm_section_data (sec
)->erratumcount
);
5062 newerr
->u
.b
.vfp_insn
= veneer_of_insn
;
5067 newerr
->type
= VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
;
5074 record_vfp11_erratum_veneer (link_info
, newerr
, abfd
, sec
,
5079 newerr
->next
= sec_data
->erratumlist
;
5080 sec_data
->erratumlist
= newerr
;
5089 if (contents
!= NULL
5090 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5098 if (contents
!= NULL
5099 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
5105 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5106 after sections have been laid out, using specially-named symbols. */
5109 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd
*abfd
,
5110 struct bfd_link_info
*link_info
)
5113 struct elf32_arm_link_hash_table
*globals
;
5116 if (link_info
->relocatable
)
5119 /* Skip if this bfd does not correspond to an ELF image. */
5120 if (! is_arm_elf (abfd
))
5123 globals
= elf32_arm_hash_table (link_info
);
5125 tmp_name
= bfd_malloc ((bfd_size_type
) strlen
5126 (VFP11_ERRATUM_VENEER_ENTRY_NAME
) + 10);
5128 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5130 struct _arm_elf_section_data
*sec_data
= elf32_arm_section_data (sec
);
5131 elf32_vfp11_erratum_list
*errnode
= sec_data
->erratumlist
;
5133 for (; errnode
!= NULL
; errnode
= errnode
->next
)
5135 struct elf_link_hash_entry
*myh
;
5138 switch (errnode
->type
)
5140 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
5141 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER
:
5142 /* Find veneer symbol. */
5143 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
,
5144 errnode
->u
.b
.veneer
->u
.v
.id
);
5146 myh
= elf_link_hash_lookup
5147 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5150 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
5151 "`%s'"), abfd
, tmp_name
);
5153 vma
= myh
->root
.u
.def
.section
->output_section
->vma
5154 + myh
->root
.u
.def
.section
->output_offset
5155 + myh
->root
.u
.def
.value
;
5157 errnode
->u
.b
.veneer
->vma
= vma
;
5160 case VFP11_ERRATUM_ARM_VENEER
:
5161 case VFP11_ERRATUM_THUMB_VENEER
:
5162 /* Find return location. */
5163 sprintf (tmp_name
, VFP11_ERRATUM_VENEER_ENTRY_NAME
"_r",
5166 myh
= elf_link_hash_lookup
5167 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
5170 (*_bfd_error_handler
) (_("%B: unable to find VFP11 veneer "
5171 "`%s'"), abfd
, tmp_name
);
5173 vma
= myh
->root
.u
.def
.section
->output_section
->vma
5174 + myh
->root
.u
.def
.section
->output_offset
5175 + myh
->root
.u
.def
.value
;
5177 errnode
->u
.v
.branch
->vma
= vma
;
5190 /* Set target relocation values needed during linking. */
5193 bfd_elf32_arm_set_target_relocs (struct bfd
*output_bfd
,
5194 struct bfd_link_info
*link_info
,
5196 char * target2_type
,
5199 bfd_arm_vfp11_fix vfp11_fix
,
5200 int no_enum_warn
, int no_wchar_warn
,
5203 struct elf32_arm_link_hash_table
*globals
;
5205 globals
= elf32_arm_hash_table (link_info
);
5207 globals
->target1_is_rel
= target1_is_rel
;
5208 if (strcmp (target2_type
, "rel") == 0)
5209 globals
->target2_reloc
= R_ARM_REL32
;
5210 else if (strcmp (target2_type
, "abs") == 0)
5211 globals
->target2_reloc
= R_ARM_ABS32
;
5212 else if (strcmp (target2_type
, "got-rel") == 0)
5213 globals
->target2_reloc
= R_ARM_GOT_PREL
;
5216 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5219 globals
->fix_v4bx
= fix_v4bx
;
5220 globals
->use_blx
|= use_blx
;
5221 globals
->vfp11_fix
= vfp11_fix
;
5222 globals
->pic_veneer
= pic_veneer
;
5224 BFD_ASSERT (is_arm_elf (output_bfd
));
5225 elf_arm_tdata (output_bfd
)->no_enum_size_warning
= no_enum_warn
;
5226 elf_arm_tdata (output_bfd
)->no_wchar_size_warning
= no_wchar_warn
;
5229 /* Replace the target offset of a Thumb bl or b.w instruction. */
5232 insert_thumb_branch (bfd
*abfd
, long int offset
, bfd_byte
*insn
)
5238 BFD_ASSERT ((offset
& 1) == 0);
5240 upper
= bfd_get_16 (abfd
, insn
);
5241 lower
= bfd_get_16 (abfd
, insn
+ 2);
5242 reloc_sign
= (offset
< 0) ? 1 : 0;
5243 upper
= (upper
& ~(bfd_vma
) 0x7ff)
5244 | ((offset
>> 12) & 0x3ff)
5245 | (reloc_sign
<< 10);
5246 lower
= (lower
& ~(bfd_vma
) 0x2fff)
5247 | (((!((offset
>> 23) & 1)) ^ reloc_sign
) << 13)
5248 | (((!((offset
>> 22) & 1)) ^ reloc_sign
) << 11)
5249 | ((offset
>> 1) & 0x7ff);
5250 bfd_put_16 (abfd
, upper
, insn
);
5251 bfd_put_16 (abfd
, lower
, insn
+ 2);
5254 /* Thumb code calling an ARM function. */
5257 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
5261 asection
* input_section
,
5262 bfd_byte
* hit_data
,
5265 bfd_signed_vma addend
,
5267 char **error_message
)
5271 long int ret_offset
;
5272 struct elf_link_hash_entry
* myh
;
5273 struct elf32_arm_link_hash_table
* globals
;
5275 myh
= find_thumb_glue (info
, name
, error_message
);
5279 globals
= elf32_arm_hash_table (info
);
5281 BFD_ASSERT (globals
!= NULL
);
5282 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5284 my_offset
= myh
->root
.u
.def
.value
;
5286 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5287 THUMB2ARM_GLUE_SECTION_NAME
);
5289 BFD_ASSERT (s
!= NULL
);
5290 BFD_ASSERT (s
->contents
!= NULL
);
5291 BFD_ASSERT (s
->output_section
!= NULL
);
5293 if ((my_offset
& 0x01) == 0x01)
5296 && sym_sec
->owner
!= NULL
5297 && !INTERWORK_FLAG (sym_sec
->owner
))
5299 (*_bfd_error_handler
)
5300 (_("%B(%s): warning: interworking not enabled.\n"
5301 " first occurrence: %B: thumb call to arm"),
5302 sym_sec
->owner
, input_bfd
, name
);
5308 myh
->root
.u
.def
.value
= my_offset
;
5310 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
5311 s
->contents
+ my_offset
);
5313 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
5314 s
->contents
+ my_offset
+ 2);
5317 /* Address of destination of the stub. */
5318 ((bfd_signed_vma
) val
)
5320 /* Offset from the start of the current section
5321 to the start of the stubs. */
5323 /* Offset of the start of this stub from the start of the stubs. */
5325 /* Address of the start of the current section. */
5326 + s
->output_section
->vma
)
5327 /* The branch instruction is 4 bytes into the stub. */
5329 /* ARM branches work from the pc of the instruction + 8. */
5332 put_arm_insn (globals
, output_bfd
,
5333 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
5334 s
->contents
+ my_offset
+ 4);
5337 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
5339 /* Now go back and fix up the original BL insn to point to here. */
5341 /* Address of where the stub is located. */
5342 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
5343 /* Address of where the BL is located. */
5344 - (input_section
->output_section
->vma
+ input_section
->output_offset
5346 /* Addend in the relocation. */
5348 /* Biassing for PC-relative addressing. */
5351 insert_thumb_branch (input_bfd
, ret_offset
, hit_data
- input_section
->vma
);
5356 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5358 static struct elf_link_hash_entry
*
5359 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
5366 char ** error_message
)
5369 long int ret_offset
;
5370 struct elf_link_hash_entry
* myh
;
5371 struct elf32_arm_link_hash_table
* globals
;
5373 myh
= find_arm_glue (info
, name
, error_message
);
5377 globals
= elf32_arm_hash_table (info
);
5379 BFD_ASSERT (globals
!= NULL
);
5380 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5382 my_offset
= myh
->root
.u
.def
.value
;
5384 if ((my_offset
& 0x01) == 0x01)
5387 && sym_sec
->owner
!= NULL
5388 && !INTERWORK_FLAG (sym_sec
->owner
))
5390 (*_bfd_error_handler
)
5391 (_("%B(%s): warning: interworking not enabled.\n"
5392 " first occurrence: %B: arm call to thumb"),
5393 sym_sec
->owner
, input_bfd
, name
);
5397 myh
->root
.u
.def
.value
= my_offset
;
5399 if (info
->shared
|| globals
->root
.is_relocatable_executable
5400 || globals
->pic_veneer
)
5402 /* For relocatable objects we can't use absolute addresses,
5403 so construct the address from a relative offset. */
5404 /* TODO: If the offset is small it's probably worth
5405 constructing the address with adds. */
5406 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
5407 s
->contents
+ my_offset
);
5408 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
5409 s
->contents
+ my_offset
+ 4);
5410 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
5411 s
->contents
+ my_offset
+ 8);
5412 /* Adjust the offset by 4 for the position of the add,
5413 and 8 for the pipeline offset. */
5414 ret_offset
= (val
- (s
->output_offset
5415 + s
->output_section
->vma
5418 bfd_put_32 (output_bfd
, ret_offset
,
5419 s
->contents
+ my_offset
+ 12);
5421 else if (globals
->use_blx
)
5423 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1v5_ldr_insn
,
5424 s
->contents
+ my_offset
);
5426 /* It's a thumb address. Add the low order bit. */
5427 bfd_put_32 (output_bfd
, val
| a2t2v5_func_addr_insn
,
5428 s
->contents
+ my_offset
+ 4);
5432 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
5433 s
->contents
+ my_offset
);
5435 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
5436 s
->contents
+ my_offset
+ 4);
5438 /* It's a thumb address. Add the low order bit. */
5439 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
5440 s
->contents
+ my_offset
+ 8);
5446 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
5451 /* Arm code calling a Thumb function. */
5454 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
5458 asection
* input_section
,
5459 bfd_byte
* hit_data
,
5462 bfd_signed_vma addend
,
5464 char **error_message
)
5466 unsigned long int tmp
;
5469 long int ret_offset
;
5470 struct elf_link_hash_entry
* myh
;
5471 struct elf32_arm_link_hash_table
* globals
;
5473 globals
= elf32_arm_hash_table (info
);
5475 BFD_ASSERT (globals
!= NULL
);
5476 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5478 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5479 ARM2THUMB_GLUE_SECTION_NAME
);
5480 BFD_ASSERT (s
!= NULL
);
5481 BFD_ASSERT (s
->contents
!= NULL
);
5482 BFD_ASSERT (s
->output_section
!= NULL
);
5484 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
5485 sym_sec
, val
, s
, error_message
);
5489 my_offset
= myh
->root
.u
.def
.value
;
5490 tmp
= bfd_get_32 (input_bfd
, hit_data
);
5491 tmp
= tmp
& 0xFF000000;
5493 /* Somehow these are both 4 too far, so subtract 8. */
5494 ret_offset
= (s
->output_offset
5496 + s
->output_section
->vma
5497 - (input_section
->output_offset
5498 + input_section
->output_section
->vma
5502 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
5504 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
5509 /* Populate Arm stub for an exported Thumb function. */
5512 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
5514 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
5516 struct elf_link_hash_entry
* myh
;
5517 struct elf32_arm_link_hash_entry
*eh
;
5518 struct elf32_arm_link_hash_table
* globals
;
5521 char *error_message
;
5523 eh
= elf32_arm_hash_entry (h
);
5524 /* Allocate stubs for exported Thumb functions on v4t. */
5525 if (eh
->export_glue
== NULL
)
5528 globals
= elf32_arm_hash_table (info
);
5530 BFD_ASSERT (globals
!= NULL
);
5531 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5533 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5534 ARM2THUMB_GLUE_SECTION_NAME
);
5535 BFD_ASSERT (s
!= NULL
);
5536 BFD_ASSERT (s
->contents
!= NULL
);
5537 BFD_ASSERT (s
->output_section
!= NULL
);
5539 sec
= eh
->export_glue
->root
.u
.def
.section
;
5541 BFD_ASSERT (sec
->output_section
!= NULL
);
5543 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
5544 + sec
->output_section
->vma
;
5546 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
5547 h
->root
.u
.def
.section
->owner
,
5548 globals
->obfd
, sec
, val
, s
,
5554 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5557 elf32_arm_bx_glue (struct bfd_link_info
* info
, int reg
)
5562 struct elf32_arm_link_hash_table
*globals
;
5564 globals
= elf32_arm_hash_table (info
);
5566 BFD_ASSERT (globals
!= NULL
);
5567 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
5569 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
5570 ARM_BX_GLUE_SECTION_NAME
);
5571 BFD_ASSERT (s
!= NULL
);
5572 BFD_ASSERT (s
->contents
!= NULL
);
5573 BFD_ASSERT (s
->output_section
!= NULL
);
5575 BFD_ASSERT (globals
->bx_glue_offset
[reg
] & 2);
5577 glue_addr
= globals
->bx_glue_offset
[reg
] & ~(bfd_vma
)3;
5579 if ((globals
->bx_glue_offset
[reg
] & 1) == 0)
5581 p
= s
->contents
+ glue_addr
;
5582 bfd_put_32 (globals
->obfd
, armbx1_tst_insn
+ (reg
<< 16), p
);
5583 bfd_put_32 (globals
->obfd
, armbx2_moveq_insn
+ reg
, p
+ 4);
5584 bfd_put_32 (globals
->obfd
, armbx3_bx_insn
+ reg
, p
+ 8);
5585 globals
->bx_glue_offset
[reg
] |= 1;
5588 return glue_addr
+ s
->output_section
->vma
+ s
->output_offset
;
5591 /* Generate Arm stubs for exported Thumb symbols. */
5593 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5594 struct bfd_link_info
*link_info
)
5596 struct elf32_arm_link_hash_table
* globals
;
5598 if (link_info
== NULL
)
5599 /* Ignore this if we are not called by the ELF backend linker. */
5602 globals
= elf32_arm_hash_table (link_info
);
5603 /* If blx is available then exported Thumb symbols are OK and there is
5605 if (globals
->use_blx
)
5608 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
5612 /* Some relocations map to different relocations depending on the
5613 target. Return the real relocation. */
5616 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
5622 if (globals
->target1_is_rel
)
5628 return globals
->target2_reloc
;
5635 /* Return the base VMA address which should be subtracted from real addresses
5636 when resolving @dtpoff relocation.
5637 This is PT_TLS segment p_vaddr. */
5640 dtpoff_base (struct bfd_link_info
*info
)
5642 /* If tls_sec is NULL, we should have signalled an error already. */
5643 if (elf_hash_table (info
)->tls_sec
== NULL
)
5645 return elf_hash_table (info
)->tls_sec
->vma
;
5648 /* Return the relocation value for @tpoff relocation
5649 if STT_TLS virtual address is ADDRESS. */
5652 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
5654 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5657 /* If tls_sec is NULL, we should have signalled an error already. */
5658 if (htab
->tls_sec
== NULL
)
5660 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
5661 return address
- htab
->tls_sec
->vma
+ base
;
5664 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5665 VALUE is the relocation value. */
5667 static bfd_reloc_status_type
5668 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
5671 return bfd_reloc_overflow
;
5673 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
5674 bfd_put_32 (abfd
, value
, data
);
5675 return bfd_reloc_ok
;
5678 /* For a given value of n, calculate the value of G_n as required to
5679 deal with group relocations. We return it in the form of an
5680 encoded constant-and-rotation, together with the final residual. If n is
5681 specified as less than zero, then final_residual is filled with the
5682 input value and no further action is performed. */
5685 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
5689 bfd_vma encoded_g_n
= 0;
5690 bfd_vma residual
= value
; /* Also known as Y_n. */
5692 for (current_n
= 0; current_n
<= n
; current_n
++)
5696 /* Calculate which part of the value to mask. */
5703 /* Determine the most significant bit in the residual and
5704 align the resulting value to a 2-bit boundary. */
5705 for (msb
= 30; msb
>= 0; msb
-= 2)
5706 if (residual
& (3 << msb
))
5709 /* The desired shift is now (msb - 6), or zero, whichever
5716 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5717 g_n
= residual
& (0xff << shift
);
5718 encoded_g_n
= (g_n
>> shift
)
5719 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
5721 /* Calculate the residual for the next time around. */
5725 *final_residual
= residual
;
5730 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5731 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5734 identify_add_or_sub (bfd_vma insn
)
5736 int opcode
= insn
& 0x1e00000;
5738 if (opcode
== 1 << 23) /* ADD */
5741 if (opcode
== 1 << 22) /* SUB */
5747 /* Perform a relocation as part of a final link. */
5749 static bfd_reloc_status_type
5750 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
5753 asection
* input_section
,
5754 bfd_byte
* contents
,
5755 Elf_Internal_Rela
* rel
,
5757 struct bfd_link_info
* info
,
5759 const char * sym_name
,
5761 struct elf_link_hash_entry
* h
,
5762 bfd_boolean
* unresolved_reloc_p
,
5763 char ** error_message
)
5765 unsigned long r_type
= howto
->type
;
5766 unsigned long r_symndx
;
5767 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
5768 bfd
* dynobj
= NULL
;
5769 Elf_Internal_Shdr
* symtab_hdr
;
5770 struct elf_link_hash_entry
** sym_hashes
;
5771 bfd_vma
* local_got_offsets
;
5772 asection
* sgot
= NULL
;
5773 asection
* splt
= NULL
;
5774 asection
* sreloc
= NULL
;
5776 bfd_signed_vma signed_addend
;
5777 struct elf32_arm_link_hash_table
* globals
;
5779 globals
= elf32_arm_hash_table (info
);
5781 BFD_ASSERT (is_arm_elf (input_bfd
));
5783 /* Some relocation types map to different relocations depending on the
5784 target. We pick the right one here. */
5785 r_type
= arm_real_reloc_type (globals
, r_type
);
5786 if (r_type
!= howto
->type
)
5787 howto
= elf32_arm_howto_from_type (r_type
);
5789 /* If the start address has been set, then set the EF_ARM_HASENTRY
5790 flag. Setting this more than once is redundant, but the cost is
5791 not too high, and it keeps the code simple.
5793 The test is done here, rather than somewhere else, because the
5794 start address is only set just before the final link commences.
5796 Note - if the user deliberately sets a start address of 0, the
5797 flag will not be set. */
5798 if (bfd_get_start_address (output_bfd
) != 0)
5799 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
5801 dynobj
= elf_hash_table (info
)->dynobj
;
5804 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5805 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5807 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
5808 sym_hashes
= elf_sym_hashes (input_bfd
);
5809 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5810 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5812 if (globals
->use_rel
)
5814 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
5816 if (addend
& ((howto
->src_mask
+ 1) >> 1))
5819 signed_addend
&= ~ howto
->src_mask
;
5820 signed_addend
|= addend
;
5823 signed_addend
= addend
;
5826 addend
= signed_addend
= rel
->r_addend
;
5831 /* We don't need to find a value for this symbol. It's just a
5833 *unresolved_reloc_p
= FALSE
;
5834 return bfd_reloc_ok
;
5837 if (!globals
->vxworks_p
)
5838 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
5842 case R_ARM_ABS32_NOI
:
5844 case R_ARM_REL32_NOI
:
5850 /* Handle relocations which should use the PLT entry. ABS32/REL32
5851 will use the symbol's value, which may point to a PLT entry, but we
5852 don't need to handle that here. If we created a PLT entry, all
5853 branches in this object should go to it. */
5854 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
5855 && r_type
!= R_ARM_ABS32_NOI
&& r_type
!= R_ARM_REL32_NOI
)
5858 && h
->plt
.offset
!= (bfd_vma
) -1)
5860 /* If we've created a .plt section, and assigned a PLT entry to
5861 this function, it should not be known to bind locally. If
5862 it were, we would have cleared the PLT entry. */
5863 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
5865 value
= (splt
->output_section
->vma
5866 + splt
->output_offset
5868 *unresolved_reloc_p
= FALSE
;
5869 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
5870 contents
, rel
->r_offset
, value
,
5874 /* When generating a shared object or relocatable executable, these
5875 relocations are copied into the output file to be resolved at
5877 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
5878 && (input_section
->flags
& SEC_ALLOC
)
5879 && !(elf32_arm_hash_table (info
)->vxworks_p
5880 && strcmp (input_section
->output_section
->name
,
5882 && ((r_type
!= R_ARM_REL32
&& r_type
!= R_ARM_REL32_NOI
)
5883 || !SYMBOL_CALLS_LOCAL (info
, h
))
5885 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5886 || h
->root
.type
!= bfd_link_hash_undefweak
)
5887 && r_type
!= R_ARM_PC24
5888 && r_type
!= R_ARM_CALL
5889 && r_type
!= R_ARM_JUMP24
5890 && r_type
!= R_ARM_PREL31
5891 && r_type
!= R_ARM_PLT32
)
5893 Elf_Internal_Rela outrel
;
5895 bfd_boolean skip
, relocate
;
5897 *unresolved_reloc_p
= FALSE
;
5903 name
= (bfd_elf_string_from_elf_section
5905 elf_elfheader (input_bfd
)->e_shstrndx
,
5906 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5908 return bfd_reloc_notsupported
;
5910 BFD_ASSERT (reloc_section_p (globals
, name
, input_section
));
5912 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5913 BFD_ASSERT (sreloc
!= NULL
);
5919 outrel
.r_addend
= addend
;
5921 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5923 if (outrel
.r_offset
== (bfd_vma
) -1)
5925 else if (outrel
.r_offset
== (bfd_vma
) -2)
5926 skip
= TRUE
, relocate
= TRUE
;
5927 outrel
.r_offset
+= (input_section
->output_section
->vma
5928 + input_section
->output_offset
);
5931 memset (&outrel
, 0, sizeof outrel
);
5936 || !h
->def_regular
))
5937 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5942 /* This symbol is local, or marked to become local. */
5943 if (sym_flags
== STT_ARM_TFUNC
)
5945 if (globals
->symbian_p
)
5949 /* On Symbian OS, the data segment and text segement
5950 can be relocated independently. Therefore, we
5951 must indicate the segment to which this
5952 relocation is relative. The BPABI allows us to
5953 use any symbol in the right segment; we just use
5954 the section symbol as it is convenient. (We
5955 cannot use the symbol given by "h" directly as it
5956 will not appear in the dynamic symbol table.)
5958 Note that the dynamic linker ignores the section
5959 symbol value, so we don't subtract osec->vma
5960 from the emitted reloc addend. */
5962 osec
= sym_sec
->output_section
;
5964 osec
= input_section
->output_section
;
5965 symbol
= elf_section_data (osec
)->dynindx
;
5968 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5970 if ((osec
->flags
& SEC_READONLY
) == 0
5971 && htab
->data_index_section
!= NULL
)
5972 osec
= htab
->data_index_section
;
5974 osec
= htab
->text_index_section
;
5975 symbol
= elf_section_data (osec
)->dynindx
;
5977 BFD_ASSERT (symbol
!= 0);
5980 /* On SVR4-ish systems, the dynamic loader cannot
5981 relocate the text and data segments independently,
5982 so the symbol does not matter. */
5984 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
5985 if (globals
->use_rel
)
5988 outrel
.r_addend
+= value
;
5991 loc
= sreloc
->contents
;
5992 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
5993 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
5995 /* If this reloc is against an external symbol, we do not want to
5996 fiddle with the addend. Otherwise, we need to include the symbol
5997 value so that it becomes an addend for the dynamic reloc. */
5999 return bfd_reloc_ok
;
6001 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6002 contents
, rel
->r_offset
, value
,
6005 else switch (r_type
)
6008 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
6010 case R_ARM_XPC25
: /* Arm BLX instruction. */
6013 case R_ARM_PC24
: /* Arm B/BL instruction. */
6017 bfd_signed_vma branch_offset
;
6018 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
6020 from
= (input_section
->output_section
->vma
6021 + input_section
->output_offset
6023 branch_offset
= (bfd_signed_vma
)(value
- from
);
6025 if (r_type
== R_ARM_XPC25
)
6027 /* Check for Arm calling Arm function. */
6028 /* FIXME: Should we translate the instruction into a BL
6029 instruction instead ? */
6030 if (sym_flags
!= STT_ARM_TFUNC
)
6031 (*_bfd_error_handler
)
6032 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6034 h
? h
->root
.root
.string
: "(local)");
6036 else if (r_type
!= R_ARM_CALL
)
6038 /* Check for Arm calling Thumb function. */
6039 if (sym_flags
== STT_ARM_TFUNC
)
6041 if (elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
6042 output_bfd
, input_section
,
6043 hit_data
, sym_sec
, rel
->r_offset
,
6044 signed_addend
, value
,
6046 return bfd_reloc_ok
;
6048 return bfd_reloc_dangerous
;
6052 /* Check if a stub has to be inserted because the
6053 destination is too far or we are changing mode. */
6054 if (r_type
== R_ARM_CALL
)
6056 if (branch_offset
> ARM_MAX_FWD_BRANCH_OFFSET
6057 || branch_offset
< ARM_MAX_BWD_BRANCH_OFFSET
6058 || sym_flags
== STT_ARM_TFUNC
)
6060 /* The target is out of reach, so redirect the
6061 branch to the local stub for this function. */
6063 stub_entry
= elf32_arm_get_stub_entry (input_section
,
6066 if (stub_entry
!= NULL
)
6067 value
= (stub_entry
->stub_offset
6068 + stub_entry
->stub_sec
->output_offset
6069 + stub_entry
->stub_sec
->output_section
->vma
);
6073 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6075 S is the address of the symbol in the relocation.
6076 P is address of the instruction being relocated.
6077 A is the addend (extracted from the instruction) in bytes.
6079 S is held in 'value'.
6080 P is the base address of the section containing the
6081 instruction plus the offset of the reloc into that
6083 (input_section->output_section->vma +
6084 input_section->output_offset +
6086 A is the addend, converted into bytes, ie:
6089 Note: None of these operations have knowledge of the pipeline
6090 size of the processor, thus it is up to the assembler to
6091 encode this information into the addend. */
6092 value
-= (input_section
->output_section
->vma
6093 + input_section
->output_offset
);
6094 value
-= rel
->r_offset
;
6095 if (globals
->use_rel
)
6096 value
+= (signed_addend
<< howto
->size
);
6098 /* RELA addends do not have to be adjusted by howto->size. */
6099 value
+= signed_addend
;
6101 signed_addend
= value
;
6102 signed_addend
>>= howto
->rightshift
;
6104 /* A branch to an undefined weak symbol is turned into a jump to
6105 the next instruction. */
6106 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
6108 value
= (bfd_get_32 (input_bfd
, hit_data
) & 0xf0000000)
6113 /* Perform a signed range check. */
6114 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
6115 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
6116 return bfd_reloc_overflow
;
6118 addend
= (value
& 2);
6120 value
= (signed_addend
& howto
->dst_mask
)
6121 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
6123 /* Set the H bit in the BLX instruction. */
6124 if (sym_flags
== STT_ARM_TFUNC
)
6129 value
&= ~(bfd_vma
)(1 << 24);
6131 if (r_type
== R_ARM_CALL
)
6133 /* Select the correct instruction (BL or BLX). */
6134 /* Only if we are not handling a BL to a stub. In this
6135 case, mode switching is performed by the stub. */
6136 if (sym_flags
== STT_ARM_TFUNC
&& !stub_entry
)
6140 value
&= ~(bfd_vma
)(1 << 28);
6150 if (sym_flags
== STT_ARM_TFUNC
)
6154 case R_ARM_ABS32_NOI
:
6160 if (sym_flags
== STT_ARM_TFUNC
)
6162 value
-= (input_section
->output_section
->vma
6163 + input_section
->output_offset
+ rel
->r_offset
);
6166 case R_ARM_REL32_NOI
:
6168 value
-= (input_section
->output_section
->vma
6169 + input_section
->output_offset
+ rel
->r_offset
);
6173 value
-= (input_section
->output_section
->vma
6174 + input_section
->output_offset
+ rel
->r_offset
);
6175 value
+= signed_addend
;
6176 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
6178 /* Check for overflow. */
6179 if ((value
^ (value
>> 1)) & (1 << 30))
6180 return bfd_reloc_overflow
;
6182 value
&= 0x7fffffff;
6183 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
6184 if (sym_flags
== STT_ARM_TFUNC
)
6189 bfd_put_32 (input_bfd
, value
, hit_data
);
6190 return bfd_reloc_ok
;
6194 if ((long) value
> 0x7f || (long) value
< -0x80)
6195 return bfd_reloc_overflow
;
6197 bfd_put_8 (input_bfd
, value
, hit_data
);
6198 return bfd_reloc_ok
;
6203 if ((long) value
> 0x7fff || (long) value
< -0x8000)
6204 return bfd_reloc_overflow
;
6206 bfd_put_16 (input_bfd
, value
, hit_data
);
6207 return bfd_reloc_ok
;
6209 case R_ARM_THM_ABS5
:
6210 /* Support ldr and str instructions for the thumb. */
6211 if (globals
->use_rel
)
6213 /* Need to refetch addend. */
6214 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
6215 /* ??? Need to determine shift amount from operand size. */
6216 addend
>>= howto
->rightshift
;
6220 /* ??? Isn't value unsigned? */
6221 if ((long) value
> 0x1f || (long) value
< -0x10)
6222 return bfd_reloc_overflow
;
6224 /* ??? Value needs to be properly shifted into place first. */
6225 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
6226 bfd_put_16 (input_bfd
, value
, hit_data
);
6227 return bfd_reloc_ok
;
6229 case R_ARM_THM_ALU_PREL_11_0
:
6230 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6233 bfd_signed_vma relocation
;
6235 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
6236 | bfd_get_16 (input_bfd
, hit_data
+ 2);
6238 if (globals
->use_rel
)
6240 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
6241 | ((insn
& (1 << 26)) >> 15);
6242 if (insn
& 0xf00000)
6243 signed_addend
= -signed_addend
;
6246 relocation
= value
+ signed_addend
;
6247 relocation
-= (input_section
->output_section
->vma
6248 + input_section
->output_offset
6251 value
= abs (relocation
);
6253 if (value
>= 0x1000)
6254 return bfd_reloc_overflow
;
6256 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
6257 | ((value
& 0x700) << 4)
6258 | ((value
& 0x800) << 15);
6262 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
6263 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
6265 return bfd_reloc_ok
;
6268 case R_ARM_THM_PC12
:
6269 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6272 bfd_signed_vma relocation
;
6274 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
6275 | bfd_get_16 (input_bfd
, hit_data
+ 2);
6277 if (globals
->use_rel
)
6279 signed_addend
= insn
& 0xfff;
6280 if (!(insn
& (1 << 23)))
6281 signed_addend
= -signed_addend
;
6284 relocation
= value
+ signed_addend
;
6285 relocation
-= (input_section
->output_section
->vma
6286 + input_section
->output_offset
6289 value
= abs (relocation
);
6291 if (value
>= 0x1000)
6292 return bfd_reloc_overflow
;
6294 insn
= (insn
& 0xff7ff000) | value
;
6295 if (relocation
>= 0)
6298 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
6299 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
6301 return bfd_reloc_ok
;
6304 case R_ARM_THM_XPC22
:
6305 case R_ARM_THM_CALL
:
6306 case R_ARM_THM_JUMP24
:
6307 /* Thumb BL (branch long instruction). */
6311 bfd_boolean overflow
= FALSE
;
6312 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
6313 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
6314 bfd_signed_vma reloc_signed_max
;
6315 bfd_signed_vma reloc_signed_min
;
6317 bfd_signed_vma signed_check
;
6319 int thumb2
= using_thumb2 (globals
);
6321 /* A branch to an undefined weak symbol is turned into a jump to
6322 the next instruction. */
6323 if (h
&& h
->root
.type
== bfd_link_hash_undefweak
)
6325 bfd_put_16 (input_bfd
, 0xe000, hit_data
);
6326 bfd_put_16 (input_bfd
, 0xbf00, hit_data
+ 2);
6327 return bfd_reloc_ok
;
6330 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6331 with Thumb-1) involving the J1 and J2 bits. */
6332 if (globals
->use_rel
)
6334 bfd_vma s
= (upper_insn
& (1 << 10)) >> 10;
6335 bfd_vma upper
= upper_insn
& 0x3ff;
6336 bfd_vma lower
= lower_insn
& 0x7ff;
6337 bfd_vma j1
= (lower_insn
& (1 << 13)) >> 13;
6338 bfd_vma j2
= (lower_insn
& (1 << 11)) >> 11;
6339 bfd_vma i1
= j1
^ s
? 0 : 1;
6340 bfd_vma i2
= j2
^ s
? 0 : 1;
6342 addend
= (i1
<< 23) | (i2
<< 22) | (upper
<< 12) | (lower
<< 1);
6344 addend
= (addend
| ((s
? 0 : 1) << 24)) - (1 << 24);
6346 signed_addend
= addend
;
6349 if (r_type
== R_ARM_THM_XPC22
)
6351 /* Check for Thumb to Thumb call. */
6352 /* FIXME: Should we translate the instruction into a BL
6353 instruction instead ? */
6354 if (sym_flags
== STT_ARM_TFUNC
)
6355 (*_bfd_error_handler
)
6356 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6358 h
? h
->root
.root
.string
: "(local)");
6362 /* If it is not a call to Thumb, assume call to Arm.
6363 If it is a call relative to a section name, then it is not a
6364 function call at all, but rather a long jump. Calls through
6365 the PLT do not require stubs. */
6366 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
6367 && (h
== NULL
|| splt
== NULL
6368 || h
->plt
.offset
== (bfd_vma
) -1))
6370 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
6372 /* Convert BL to BLX. */
6373 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6375 else if (r_type
!= R_ARM_THM_CALL
)
6377 if (elf32_thumb_to_arm_stub
6378 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
6379 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
,
6381 return bfd_reloc_ok
;
6383 return bfd_reloc_dangerous
;
6386 else if (sym_flags
== STT_ARM_TFUNC
&& globals
->use_blx
6387 && r_type
== R_ARM_THM_CALL
)
6389 /* Make sure this is a BL. */
6390 lower_insn
|= 0x1800;
6394 /* Handle calls via the PLT. */
6395 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6397 value
= (splt
->output_section
->vma
6398 + splt
->output_offset
6400 if (globals
->use_blx
&& r_type
== R_ARM_THM_CALL
)
6402 /* If the Thumb BLX instruction is available, convert the
6403 BL to a BLX instruction to call the ARM-mode PLT entry. */
6404 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6407 /* Target the Thumb stub before the ARM PLT entry. */
6408 value
-= PLT_THUMB_STUB_SIZE
;
6409 *unresolved_reloc_p
= FALSE
;
6412 if (r_type
== R_ARM_THM_CALL
)
6414 /* Check if a stub has to be inserted because the destination
6417 bfd_signed_vma branch_offset
;
6418 struct elf32_arm_stub_hash_entry
*stub_entry
= NULL
;
6420 from
= (input_section
->output_section
->vma
6421 + input_section
->output_offset
6423 branch_offset
= (bfd_signed_vma
)(value
- from
);
6426 && (branch_offset
> THM_MAX_FWD_BRANCH_OFFSET
6427 || (branch_offset
< THM_MAX_BWD_BRANCH_OFFSET
)))
6430 && (branch_offset
> THM2_MAX_FWD_BRANCH_OFFSET
6431 || (branch_offset
< THM2_MAX_BWD_BRANCH_OFFSET
)))
6432 || ((sym_flags
!= STT_ARM_TFUNC
) && !globals
->use_blx
))
6434 /* The target is out of reach or we are changing modes, so
6435 redirect the branch to the local stub for this
6437 stub_entry
= elf32_arm_get_stub_entry (input_section
,
6440 if (stub_entry
!= NULL
)
6441 value
= (stub_entry
->stub_offset
6442 + stub_entry
->stub_sec
->output_offset
6443 + stub_entry
->stub_sec
->output_section
->vma
);
6445 /* If this call becomes a call to Arm, force BLX. */
6446 if (globals
->use_blx
)
6449 && !arm_stub_is_thumb (stub_entry
->stub_type
))
6450 || (sym_flags
!= STT_ARM_TFUNC
))
6451 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
6456 relocation
= value
+ signed_addend
;
6458 relocation
-= (input_section
->output_section
->vma
6459 + input_section
->output_offset
6462 check
= relocation
>> howto
->rightshift
;
6464 /* If this is a signed value, the rightshift just dropped
6465 leading 1 bits (assuming twos complement). */
6466 if ((bfd_signed_vma
) relocation
>= 0)
6467 signed_check
= check
;
6469 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
6471 /* Calculate the permissable maximum and minimum values for
6472 this relocation according to whether we're relocating for
6474 bitsize
= howto
->bitsize
;
6477 reloc_signed_max
= ((1 << (bitsize
- 1)) - 1) >> howto
->rightshift
;
6478 reloc_signed_min
= ~reloc_signed_max
;
6480 /* Assumes two's complement. */
6481 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6484 if ((lower_insn
& 0x5000) == 0x4000)
6485 /* For a BLX instruction, make sure that the relocation is rounded up
6486 to a word boundary. This follows the semantics of the instruction
6487 which specifies that bit 1 of the target address will come from bit
6488 1 of the base address. */
6489 relocation
= (relocation
+ 2) & ~ 3;
6491 /* Put RELOCATION back into the insn. Assumes two's complement.
6492 We use the Thumb-2 encoding, which is safe even if dealing with
6493 a Thumb-1 instruction by virtue of our overflow check above. */
6494 reloc_sign
= (signed_check
< 0) ? 1 : 0;
6495 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff)
6496 | ((relocation
>> 12) & 0x3ff)
6497 | (reloc_sign
<< 10);
6498 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x2fff)
6499 | (((!((relocation
>> 23) & 1)) ^ reloc_sign
) << 13)
6500 | (((!((relocation
>> 22) & 1)) ^ reloc_sign
) << 11)
6501 | ((relocation
>> 1) & 0x7ff);
6503 /* Put the relocated value back in the object file: */
6504 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
6505 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
6507 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
6511 case R_ARM_THM_JUMP19
:
6512 /* Thumb32 conditional branch instruction. */
6515 bfd_boolean overflow
= FALSE
;
6516 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
6517 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
6518 bfd_signed_vma reloc_signed_max
= 0xffffe;
6519 bfd_signed_vma reloc_signed_min
= -0x100000;
6520 bfd_signed_vma signed_check
;
6522 /* Need to refetch the addend, reconstruct the top three bits,
6523 and squish the two 11 bit pieces together. */
6524 if (globals
->use_rel
)
6526 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
6527 bfd_vma upper
= (upper_insn
& 0x003f);
6528 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
6529 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
6530 bfd_vma lower
= (lower_insn
& 0x07ff);
6535 upper
-= 0x0100; /* Sign extend. */
6537 addend
= (upper
<< 12) | (lower
<< 1);
6538 signed_addend
= addend
;
6541 /* Handle calls via the PLT. */
6542 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
6544 value
= (splt
->output_section
->vma
6545 + splt
->output_offset
6547 /* Target the Thumb stub before the ARM PLT entry. */
6548 value
-= PLT_THUMB_STUB_SIZE
;
6549 *unresolved_reloc_p
= FALSE
;
6552 /* ??? Should handle interworking? GCC might someday try to
6553 use this for tail calls. */
6555 relocation
= value
+ signed_addend
;
6556 relocation
-= (input_section
->output_section
->vma
6557 + input_section
->output_offset
6559 signed_check
= (bfd_signed_vma
) relocation
;
6561 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6564 /* Put RELOCATION back into the insn. */
6566 bfd_vma S
= (relocation
& 0x00100000) >> 20;
6567 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
6568 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
6569 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
6570 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
6572 upper_insn
= (upper_insn
& 0xfbc0) | (S
<< 10) | hi
;
6573 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
6576 /* Put the relocated value back in the object file: */
6577 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
6578 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
6580 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
6583 case R_ARM_THM_JUMP11
:
6584 case R_ARM_THM_JUMP8
:
6585 case R_ARM_THM_JUMP6
:
6586 /* Thumb B (branch) instruction). */
6588 bfd_signed_vma relocation
;
6589 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
6590 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
6591 bfd_signed_vma signed_check
;
6593 /* CZB cannot jump backward. */
6594 if (r_type
== R_ARM_THM_JUMP6
)
6595 reloc_signed_min
= 0;
6597 if (globals
->use_rel
)
6599 /* Need to refetch addend. */
6600 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
6601 if (addend
& ((howto
->src_mask
+ 1) >> 1))
6604 signed_addend
&= ~ howto
->src_mask
;
6605 signed_addend
|= addend
;
6608 signed_addend
= addend
;
6609 /* The value in the insn has been right shifted. We need to
6610 undo this, so that we can perform the address calculation
6611 in terms of bytes. */
6612 signed_addend
<<= howto
->rightshift
;
6614 relocation
= value
+ signed_addend
;
6616 relocation
-= (input_section
->output_section
->vma
6617 + input_section
->output_offset
6620 relocation
>>= howto
->rightshift
;
6621 signed_check
= relocation
;
6623 if (r_type
== R_ARM_THM_JUMP6
)
6624 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
6626 relocation
&= howto
->dst_mask
;
6627 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
6629 bfd_put_16 (input_bfd
, relocation
, hit_data
);
6631 /* Assumes two's complement. */
6632 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
6633 return bfd_reloc_overflow
;
6635 return bfd_reloc_ok
;
6638 case R_ARM_ALU_PCREL7_0
:
6639 case R_ARM_ALU_PCREL15_8
:
6640 case R_ARM_ALU_PCREL23_15
:
6645 insn
= bfd_get_32 (input_bfd
, hit_data
);
6646 if (globals
->use_rel
)
6648 /* Extract the addend. */
6649 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
6650 signed_addend
= addend
;
6652 relocation
= value
+ signed_addend
;
6654 relocation
-= (input_section
->output_section
->vma
6655 + input_section
->output_offset
6657 insn
= (insn
& ~0xfff)
6658 | ((howto
->bitpos
<< 7) & 0xf00)
6659 | ((relocation
>> howto
->bitpos
) & 0xff);
6660 bfd_put_32 (input_bfd
, value
, hit_data
);
6662 return bfd_reloc_ok
;
6664 case R_ARM_GNU_VTINHERIT
:
6665 case R_ARM_GNU_VTENTRY
:
6666 return bfd_reloc_ok
;
6668 case R_ARM_GOTOFF32
:
6669 /* Relocation is relative to the start of the
6670 global offset table. */
6672 BFD_ASSERT (sgot
!= NULL
);
6674 return bfd_reloc_notsupported
;
6676 /* If we are addressing a Thumb function, we need to adjust the
6677 address by one, so that attempts to call the function pointer will
6678 correctly interpret it as Thumb code. */
6679 if (sym_flags
== STT_ARM_TFUNC
)
6682 /* Note that sgot->output_offset is not involved in this
6683 calculation. We always want the start of .got. If we
6684 define _GLOBAL_OFFSET_TABLE in a different way, as is
6685 permitted by the ABI, we might have to change this
6687 value
-= sgot
->output_section
->vma
;
6688 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6689 contents
, rel
->r_offset
, value
,
6693 /* Use global offset table as symbol value. */
6694 BFD_ASSERT (sgot
!= NULL
);
6697 return bfd_reloc_notsupported
;
6699 *unresolved_reloc_p
= FALSE
;
6700 value
= sgot
->output_section
->vma
;
6701 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6702 contents
, rel
->r_offset
, value
,
6706 case R_ARM_GOT_PREL
:
6707 /* Relocation is to the entry for this symbol in the
6708 global offset table. */
6710 return bfd_reloc_notsupported
;
6717 off
= h
->got
.offset
;
6718 BFD_ASSERT (off
!= (bfd_vma
) -1);
6719 dyn
= globals
->root
.dynamic_sections_created
;
6721 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
6723 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6724 || (ELF_ST_VISIBILITY (h
->other
)
6725 && h
->root
.type
== bfd_link_hash_undefweak
))
6727 /* This is actually a static link, or it is a -Bsymbolic link
6728 and the symbol is defined locally. We must initialize this
6729 entry in the global offset table. Since the offset must
6730 always be a multiple of 4, we use the least significant bit
6731 to record whether we have initialized it already.
6733 When doing a dynamic link, we create a .rel(a).got relocation
6734 entry to initialize the value. This is done in the
6735 finish_dynamic_symbol routine. */
6740 /* If we are addressing a Thumb function, we need to
6741 adjust the address by one, so that attempts to
6742 call the function pointer will correctly
6743 interpret it as Thumb code. */
6744 if (sym_flags
== STT_ARM_TFUNC
)
6747 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
6752 *unresolved_reloc_p
= FALSE
;
6754 value
= sgot
->output_offset
+ off
;
6760 BFD_ASSERT (local_got_offsets
!= NULL
&&
6761 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
6763 off
= local_got_offsets
[r_symndx
];
6765 /* The offset must always be a multiple of 4. We use the
6766 least significant bit to record whether we have already
6767 generated the necessary reloc. */
6772 /* If we are addressing a Thumb function, we need to
6773 adjust the address by one, so that attempts to
6774 call the function pointer will correctly
6775 interpret it as Thumb code. */
6776 if (sym_flags
== STT_ARM_TFUNC
)
6779 if (globals
->use_rel
)
6780 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
6785 Elf_Internal_Rela outrel
;
6788 srelgot
= (bfd_get_section_by_name
6789 (dynobj
, RELOC_SECTION (globals
, ".got")));
6790 BFD_ASSERT (srelgot
!= NULL
);
6792 outrel
.r_addend
= addend
+ value
;
6793 outrel
.r_offset
= (sgot
->output_section
->vma
6794 + sgot
->output_offset
6796 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
6797 loc
= srelgot
->contents
;
6798 loc
+= srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
6799 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6802 local_got_offsets
[r_symndx
] |= 1;
6805 value
= sgot
->output_offset
+ off
;
6807 if (r_type
!= R_ARM_GOT32
)
6808 value
+= sgot
->output_section
->vma
;
6810 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6811 contents
, rel
->r_offset
, value
,
6814 case R_ARM_TLS_LDO32
:
6815 value
= value
- dtpoff_base (info
);
6817 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6818 contents
, rel
->r_offset
, value
,
6821 case R_ARM_TLS_LDM32
:
6825 if (globals
->sgot
== NULL
)
6828 off
= globals
->tls_ldm_got
.offset
;
6834 /* If we don't know the module number, create a relocation
6838 Elf_Internal_Rela outrel
;
6841 if (globals
->srelgot
== NULL
)
6844 outrel
.r_addend
= 0;
6845 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
6846 + globals
->sgot
->output_offset
+ off
);
6847 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
6849 if (globals
->use_rel
)
6850 bfd_put_32 (output_bfd
, outrel
.r_addend
,
6851 globals
->sgot
->contents
+ off
);
6853 loc
= globals
->srelgot
->contents
;
6854 loc
+= globals
->srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
6855 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6858 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
6860 globals
->tls_ldm_got
.offset
|= 1;
6863 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
6864 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
6866 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
6867 contents
, rel
->r_offset
, value
,
6871 case R_ARM_TLS_GD32
:
6872 case R_ARM_TLS_IE32
:
6878 if (globals
->sgot
== NULL
)
6885 dyn
= globals
->root
.dynamic_sections_created
;
6886 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
6888 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
6890 *unresolved_reloc_p
= FALSE
;
6893 off
= h
->got
.offset
;
6894 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
6898 if (local_got_offsets
== NULL
)
6900 off
= local_got_offsets
[r_symndx
];
6901 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
6904 if (tls_type
== GOT_UNKNOWN
)
6911 bfd_boolean need_relocs
= FALSE
;
6912 Elf_Internal_Rela outrel
;
6913 bfd_byte
*loc
= NULL
;
6916 /* The GOT entries have not been initialized yet. Do it
6917 now, and emit any relocations. If both an IE GOT and a
6918 GD GOT are necessary, we emit the GD first. */
6920 if ((info
->shared
|| indx
!= 0)
6922 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6923 || h
->root
.type
!= bfd_link_hash_undefweak
))
6926 if (globals
->srelgot
== NULL
)
6928 loc
= globals
->srelgot
->contents
;
6929 loc
+= globals
->srelgot
->reloc_count
* RELOC_SIZE (globals
);
6932 if (tls_type
& GOT_TLS_GD
)
6936 outrel
.r_addend
= 0;
6937 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
6938 + globals
->sgot
->output_offset
6940 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
6942 if (globals
->use_rel
)
6943 bfd_put_32 (output_bfd
, outrel
.r_addend
,
6944 globals
->sgot
->contents
+ cur_off
);
6946 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6947 globals
->srelgot
->reloc_count
++;
6948 loc
+= RELOC_SIZE (globals
);
6951 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
6952 globals
->sgot
->contents
+ cur_off
+ 4);
6955 outrel
.r_addend
= 0;
6956 outrel
.r_info
= ELF32_R_INFO (indx
,
6957 R_ARM_TLS_DTPOFF32
);
6958 outrel
.r_offset
+= 4;
6960 if (globals
->use_rel
)
6961 bfd_put_32 (output_bfd
, outrel
.r_addend
,
6962 globals
->sgot
->contents
+ cur_off
+ 4);
6965 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
6966 globals
->srelgot
->reloc_count
++;
6967 loc
+= RELOC_SIZE (globals
);
6972 /* If we are not emitting relocations for a
6973 general dynamic reference, then we must be in a
6974 static link or an executable link with the
6975 symbol binding locally. Mark it as belonging
6976 to module 1, the executable. */
6977 bfd_put_32 (output_bfd
, 1,
6978 globals
->sgot
->contents
+ cur_off
);
6979 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
6980 globals
->sgot
->contents
+ cur_off
+ 4);
6986 if (tls_type
& GOT_TLS_IE
)
6991 outrel
.r_addend
= value
- dtpoff_base (info
);
6993 outrel
.r_addend
= 0;
6994 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
6995 + globals
->sgot
->output_offset
6997 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
6999 if (globals
->use_rel
)
7000 bfd_put_32 (output_bfd
, outrel
.r_addend
,
7001 globals
->sgot
->contents
+ cur_off
);
7003 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
7004 globals
->srelgot
->reloc_count
++;
7005 loc
+= RELOC_SIZE (globals
);
7008 bfd_put_32 (output_bfd
, tpoff (info
, value
),
7009 globals
->sgot
->contents
+ cur_off
);
7016 local_got_offsets
[r_symndx
] |= 1;
7019 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
7021 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
7022 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
7024 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7025 contents
, rel
->r_offset
, value
,
7029 case R_ARM_TLS_LE32
:
7032 (*_bfd_error_handler
)
7033 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7034 input_bfd
, input_section
,
7035 (long) rel
->r_offset
, howto
->name
);
7039 value
= tpoff (info
, value
);
7041 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
7042 contents
, rel
->r_offset
, value
,
7046 if (globals
->fix_v4bx
)
7048 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7050 /* Ensure that we have a BX instruction. */
7051 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
7053 if (globals
->fix_v4bx
== 2 && (insn
& 0xf) != 0xf)
7055 /* Branch to veneer. */
7057 glue_addr
= elf32_arm_bx_glue (info
, insn
& 0xf);
7058 glue_addr
-= input_section
->output_section
->vma
7059 + input_section
->output_offset
7060 + rel
->r_offset
+ 8;
7061 insn
= (insn
& 0xf0000000) | 0x0a000000
7062 | ((glue_addr
>> 2) & 0x00ffffff);
7066 /* Preserve Rm (lowest four bits) and the condition code
7067 (highest four bits). Other bits encode MOV PC,Rm. */
7068 insn
= (insn
& 0xf000000f) | 0x01a0f000;
7071 bfd_put_32 (input_bfd
, insn
, hit_data
);
7073 return bfd_reloc_ok
;
7075 case R_ARM_MOVW_ABS_NC
:
7076 case R_ARM_MOVT_ABS
:
7077 case R_ARM_MOVW_PREL_NC
:
7078 case R_ARM_MOVT_PREL
:
7079 /* Until we properly support segment-base-relative addressing then
7080 we assume the segment base to be zero, as for the group relocations.
7081 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7082 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7083 case R_ARM_MOVW_BREL_NC
:
7084 case R_ARM_MOVW_BREL
:
7085 case R_ARM_MOVT_BREL
:
7087 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7089 if (globals
->use_rel
)
7091 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
7092 signed_addend
= (addend
^ 0x8000) - 0x8000;
7095 value
+= signed_addend
;
7097 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
7098 value
-= (input_section
->output_section
->vma
7099 + input_section
->output_offset
+ rel
->r_offset
);
7101 if (r_type
== R_ARM_MOVW_BREL
&& value
>= 0x10000)
7102 return bfd_reloc_overflow
;
7104 if (sym_flags
== STT_ARM_TFUNC
)
7107 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
7108 || r_type
== R_ARM_MOVT_BREL
)
7112 insn
|= value
& 0xfff;
7113 insn
|= (value
& 0xf000) << 4;
7114 bfd_put_32 (input_bfd
, insn
, hit_data
);
7116 return bfd_reloc_ok
;
7118 case R_ARM_THM_MOVW_ABS_NC
:
7119 case R_ARM_THM_MOVT_ABS
:
7120 case R_ARM_THM_MOVW_PREL_NC
:
7121 case R_ARM_THM_MOVT_PREL
:
7122 /* Until we properly support segment-base-relative addressing then
7123 we assume the segment base to be zero, as for the above relocations.
7124 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7125 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7126 as R_ARM_THM_MOVT_ABS. */
7127 case R_ARM_THM_MOVW_BREL_NC
:
7128 case R_ARM_THM_MOVW_BREL
:
7129 case R_ARM_THM_MOVT_BREL
:
7133 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
7134 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
7136 if (globals
->use_rel
)
7138 addend
= ((insn
>> 4) & 0xf000)
7139 | ((insn
>> 15) & 0x0800)
7140 | ((insn
>> 4) & 0x0700)
7142 signed_addend
= (addend
^ 0x8000) - 0x8000;
7145 value
+= signed_addend
;
7147 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
7148 value
-= (input_section
->output_section
->vma
7149 + input_section
->output_offset
+ rel
->r_offset
);
7151 if (r_type
== R_ARM_THM_MOVW_BREL
&& value
>= 0x10000)
7152 return bfd_reloc_overflow
;
7154 if (sym_flags
== STT_ARM_TFUNC
)
7157 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
7158 || r_type
== R_ARM_THM_MOVT_BREL
)
7162 insn
|= (value
& 0xf000) << 4;
7163 insn
|= (value
& 0x0800) << 15;
7164 insn
|= (value
& 0x0700) << 4;
7165 insn
|= (value
& 0x00ff);
7167 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
7168 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
7170 return bfd_reloc_ok
;
7172 case R_ARM_ALU_PC_G0_NC
:
7173 case R_ARM_ALU_PC_G1_NC
:
7174 case R_ARM_ALU_PC_G0
:
7175 case R_ARM_ALU_PC_G1
:
7176 case R_ARM_ALU_PC_G2
:
7177 case R_ARM_ALU_SB_G0_NC
:
7178 case R_ARM_ALU_SB_G1_NC
:
7179 case R_ARM_ALU_SB_G0
:
7180 case R_ARM_ALU_SB_G1
:
7181 case R_ARM_ALU_SB_G2
:
7183 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7184 bfd_vma pc
= input_section
->output_section
->vma
7185 + input_section
->output_offset
+ rel
->r_offset
;
7186 /* sb should be the origin of the *segment* containing the symbol.
7187 It is not clear how to obtain this OS-dependent value, so we
7188 make an arbitrary choice of zero. */
7192 bfd_signed_vma signed_value
;
7195 /* Determine which group of bits to select. */
7198 case R_ARM_ALU_PC_G0_NC
:
7199 case R_ARM_ALU_PC_G0
:
7200 case R_ARM_ALU_SB_G0_NC
:
7201 case R_ARM_ALU_SB_G0
:
7205 case R_ARM_ALU_PC_G1_NC
:
7206 case R_ARM_ALU_PC_G1
:
7207 case R_ARM_ALU_SB_G1_NC
:
7208 case R_ARM_ALU_SB_G1
:
7212 case R_ARM_ALU_PC_G2
:
7213 case R_ARM_ALU_SB_G2
:
7221 /* If REL, extract the addend from the insn. If RELA, it will
7222 have already been fetched for us. */
7223 if (globals
->use_rel
)
7226 bfd_vma constant
= insn
& 0xff;
7227 bfd_vma rotation
= (insn
& 0xf00) >> 8;
7230 signed_addend
= constant
;
7233 /* Compensate for the fact that in the instruction, the
7234 rotation is stored in multiples of 2 bits. */
7237 /* Rotate "constant" right by "rotation" bits. */
7238 signed_addend
= (constant
>> rotation
) |
7239 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
7242 /* Determine if the instruction is an ADD or a SUB.
7243 (For REL, this determines the sign of the addend.) */
7244 negative
= identify_add_or_sub (insn
);
7247 (*_bfd_error_handler
)
7248 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7249 input_bfd
, input_section
,
7250 (long) rel
->r_offset
, howto
->name
);
7251 return bfd_reloc_overflow
;
7254 signed_addend
*= negative
;
7257 /* Compute the value (X) to go in the place. */
7258 if (r_type
== R_ARM_ALU_PC_G0_NC
7259 || r_type
== R_ARM_ALU_PC_G1_NC
7260 || r_type
== R_ARM_ALU_PC_G0
7261 || r_type
== R_ARM_ALU_PC_G1
7262 || r_type
== R_ARM_ALU_PC_G2
)
7264 signed_value
= value
- pc
+ signed_addend
;
7266 /* Section base relative. */
7267 signed_value
= value
- sb
+ signed_addend
;
7269 /* If the target symbol is a Thumb function, then set the
7270 Thumb bit in the address. */
7271 if (sym_flags
== STT_ARM_TFUNC
)
7274 /* Calculate the value of the relevant G_n, in encoded
7275 constant-with-rotation format. */
7276 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
7279 /* Check for overflow if required. */
7280 if ((r_type
== R_ARM_ALU_PC_G0
7281 || r_type
== R_ARM_ALU_PC_G1
7282 || r_type
== R_ARM_ALU_PC_G2
7283 || r_type
== R_ARM_ALU_SB_G0
7284 || r_type
== R_ARM_ALU_SB_G1
7285 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
7287 (*_bfd_error_handler
)
7288 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7289 input_bfd
, input_section
,
7290 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7291 return bfd_reloc_overflow
;
7294 /* Mask out the value and the ADD/SUB part of the opcode; take care
7295 not to destroy the S bit. */
7298 /* Set the opcode according to whether the value to go in the
7299 place is negative. */
7300 if (signed_value
< 0)
7305 /* Encode the offset. */
7308 bfd_put_32 (input_bfd
, insn
, hit_data
);
7310 return bfd_reloc_ok
;
7312 case R_ARM_LDR_PC_G0
:
7313 case R_ARM_LDR_PC_G1
:
7314 case R_ARM_LDR_PC_G2
:
7315 case R_ARM_LDR_SB_G0
:
7316 case R_ARM_LDR_SB_G1
:
7317 case R_ARM_LDR_SB_G2
:
7319 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7320 bfd_vma pc
= input_section
->output_section
->vma
7321 + input_section
->output_offset
+ rel
->r_offset
;
7322 bfd_vma sb
= 0; /* See note above. */
7324 bfd_signed_vma signed_value
;
7327 /* Determine which groups of bits to calculate. */
7330 case R_ARM_LDR_PC_G0
:
7331 case R_ARM_LDR_SB_G0
:
7335 case R_ARM_LDR_PC_G1
:
7336 case R_ARM_LDR_SB_G1
:
7340 case R_ARM_LDR_PC_G2
:
7341 case R_ARM_LDR_SB_G2
:
7349 /* If REL, extract the addend from the insn. If RELA, it will
7350 have already been fetched for us. */
7351 if (globals
->use_rel
)
7353 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7354 signed_addend
= negative
* (insn
& 0xfff);
7357 /* Compute the value (X) to go in the place. */
7358 if (r_type
== R_ARM_LDR_PC_G0
7359 || r_type
== R_ARM_LDR_PC_G1
7360 || r_type
== R_ARM_LDR_PC_G2
)
7362 signed_value
= value
- pc
+ signed_addend
;
7364 /* Section base relative. */
7365 signed_value
= value
- sb
+ signed_addend
;
7367 /* Calculate the value of the relevant G_{n-1} to obtain
7368 the residual at that stage. */
7369 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7371 /* Check for overflow. */
7372 if (residual
>= 0x1000)
7374 (*_bfd_error_handler
)
7375 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7376 input_bfd
, input_section
,
7377 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7378 return bfd_reloc_overflow
;
7381 /* Mask out the value and U bit. */
7384 /* Set the U bit if the value to go in the place is non-negative. */
7385 if (signed_value
>= 0)
7388 /* Encode the offset. */
7391 bfd_put_32 (input_bfd
, insn
, hit_data
);
7393 return bfd_reloc_ok
;
7395 case R_ARM_LDRS_PC_G0
:
7396 case R_ARM_LDRS_PC_G1
:
7397 case R_ARM_LDRS_PC_G2
:
7398 case R_ARM_LDRS_SB_G0
:
7399 case R_ARM_LDRS_SB_G1
:
7400 case R_ARM_LDRS_SB_G2
:
7402 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7403 bfd_vma pc
= input_section
->output_section
->vma
7404 + input_section
->output_offset
+ rel
->r_offset
;
7405 bfd_vma sb
= 0; /* See note above. */
7407 bfd_signed_vma signed_value
;
7410 /* Determine which groups of bits to calculate. */
7413 case R_ARM_LDRS_PC_G0
:
7414 case R_ARM_LDRS_SB_G0
:
7418 case R_ARM_LDRS_PC_G1
:
7419 case R_ARM_LDRS_SB_G1
:
7423 case R_ARM_LDRS_PC_G2
:
7424 case R_ARM_LDRS_SB_G2
:
7432 /* If REL, extract the addend from the insn. If RELA, it will
7433 have already been fetched for us. */
7434 if (globals
->use_rel
)
7436 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7437 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
7440 /* Compute the value (X) to go in the place. */
7441 if (r_type
== R_ARM_LDRS_PC_G0
7442 || r_type
== R_ARM_LDRS_PC_G1
7443 || r_type
== R_ARM_LDRS_PC_G2
)
7445 signed_value
= value
- pc
+ signed_addend
;
7447 /* Section base relative. */
7448 signed_value
= value
- sb
+ signed_addend
;
7450 /* Calculate the value of the relevant G_{n-1} to obtain
7451 the residual at that stage. */
7452 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7454 /* Check for overflow. */
7455 if (residual
>= 0x100)
7457 (*_bfd_error_handler
)
7458 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7459 input_bfd
, input_section
,
7460 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7461 return bfd_reloc_overflow
;
7464 /* Mask out the value and U bit. */
7467 /* Set the U bit if the value to go in the place is non-negative. */
7468 if (signed_value
>= 0)
7471 /* Encode the offset. */
7472 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
7474 bfd_put_32 (input_bfd
, insn
, hit_data
);
7476 return bfd_reloc_ok
;
7478 case R_ARM_LDC_PC_G0
:
7479 case R_ARM_LDC_PC_G1
:
7480 case R_ARM_LDC_PC_G2
:
7481 case R_ARM_LDC_SB_G0
:
7482 case R_ARM_LDC_SB_G1
:
7483 case R_ARM_LDC_SB_G2
:
7485 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
7486 bfd_vma pc
= input_section
->output_section
->vma
7487 + input_section
->output_offset
+ rel
->r_offset
;
7488 bfd_vma sb
= 0; /* See note above. */
7490 bfd_signed_vma signed_value
;
7493 /* Determine which groups of bits to calculate. */
7496 case R_ARM_LDC_PC_G0
:
7497 case R_ARM_LDC_SB_G0
:
7501 case R_ARM_LDC_PC_G1
:
7502 case R_ARM_LDC_SB_G1
:
7506 case R_ARM_LDC_PC_G2
:
7507 case R_ARM_LDC_SB_G2
:
7515 /* If REL, extract the addend from the insn. If RELA, it will
7516 have already been fetched for us. */
7517 if (globals
->use_rel
)
7519 int negative
= (insn
& (1 << 23)) ? 1 : -1;
7520 signed_addend
= negative
* ((insn
& 0xff) << 2);
7523 /* Compute the value (X) to go in the place. */
7524 if (r_type
== R_ARM_LDC_PC_G0
7525 || r_type
== R_ARM_LDC_PC_G1
7526 || r_type
== R_ARM_LDC_PC_G2
)
7528 signed_value
= value
- pc
+ signed_addend
;
7530 /* Section base relative. */
7531 signed_value
= value
- sb
+ signed_addend
;
7533 /* Calculate the value of the relevant G_{n-1} to obtain
7534 the residual at that stage. */
7535 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
7537 /* Check for overflow. (The absolute value to go in the place must be
7538 divisible by four and, after having been divided by four, must
7539 fit in eight bits.) */
7540 if ((residual
& 0x3) != 0 || residual
>= 0x400)
7542 (*_bfd_error_handler
)
7543 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7544 input_bfd
, input_section
,
7545 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
7546 return bfd_reloc_overflow
;
7549 /* Mask out the value and U bit. */
7552 /* Set the U bit if the value to go in the place is non-negative. */
7553 if (signed_value
>= 0)
7556 /* Encode the offset. */
7557 insn
|= residual
>> 2;
7559 bfd_put_32 (input_bfd
, insn
, hit_data
);
7561 return bfd_reloc_ok
;
7564 return bfd_reloc_notsupported
;
7568 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7570 arm_add_to_rel (bfd
* abfd
,
7572 reloc_howto_type
* howto
,
7573 bfd_signed_vma increment
)
7575 bfd_signed_vma addend
;
7577 if (howto
->type
== R_ARM_THM_CALL
7578 || howto
->type
== R_ARM_THM_JUMP24
)
7580 int upper_insn
, lower_insn
;
7583 upper_insn
= bfd_get_16 (abfd
, address
);
7584 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
7585 upper
= upper_insn
& 0x7ff;
7586 lower
= lower_insn
& 0x7ff;
7588 addend
= (upper
<< 12) | (lower
<< 1);
7589 addend
+= increment
;
7592 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
7593 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
7595 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
7596 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
7602 contents
= bfd_get_32 (abfd
, address
);
7604 /* Get the (signed) value from the instruction. */
7605 addend
= contents
& howto
->src_mask
;
7606 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7608 bfd_signed_vma mask
;
7611 mask
&= ~ howto
->src_mask
;
7615 /* Add in the increment, (which is a byte value). */
7616 switch (howto
->type
)
7619 addend
+= increment
;
7626 addend
<<= howto
->size
;
7627 addend
+= increment
;
7629 /* Should we check for overflow here ? */
7631 /* Drop any undesired bits. */
7632 addend
>>= howto
->rightshift
;
7636 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
7638 bfd_put_32 (abfd
, contents
, address
);
7642 #define IS_ARM_TLS_RELOC(R_TYPE) \
7643 ((R_TYPE) == R_ARM_TLS_GD32 \
7644 || (R_TYPE) == R_ARM_TLS_LDO32 \
7645 || (R_TYPE) == R_ARM_TLS_LDM32 \
7646 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7647 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7648 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7649 || (R_TYPE) == R_ARM_TLS_LE32 \
7650 || (R_TYPE) == R_ARM_TLS_IE32)
7652 /* Relocate an ARM ELF section. */
7655 elf32_arm_relocate_section (bfd
* output_bfd
,
7656 struct bfd_link_info
* info
,
7658 asection
* input_section
,
7659 bfd_byte
* contents
,
7660 Elf_Internal_Rela
* relocs
,
7661 Elf_Internal_Sym
* local_syms
,
7662 asection
** local_sections
)
7664 Elf_Internal_Shdr
*symtab_hdr
;
7665 struct elf_link_hash_entry
**sym_hashes
;
7666 Elf_Internal_Rela
*rel
;
7667 Elf_Internal_Rela
*relend
;
7669 struct elf32_arm_link_hash_table
* globals
;
7671 globals
= elf32_arm_hash_table (info
);
7673 symtab_hdr
= & elf_symtab_hdr (input_bfd
);
7674 sym_hashes
= elf_sym_hashes (input_bfd
);
7677 relend
= relocs
+ input_section
->reloc_count
;
7678 for (; rel
< relend
; rel
++)
7681 reloc_howto_type
* howto
;
7682 unsigned long r_symndx
;
7683 Elf_Internal_Sym
* sym
;
7685 struct elf_link_hash_entry
* h
;
7687 bfd_reloc_status_type r
;
7690 bfd_boolean unresolved_reloc
= FALSE
;
7691 char *error_message
= NULL
;
7693 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7694 r_type
= ELF32_R_TYPE (rel
->r_info
);
7695 r_type
= arm_real_reloc_type (globals
, r_type
);
7697 if ( r_type
== R_ARM_GNU_VTENTRY
7698 || r_type
== R_ARM_GNU_VTINHERIT
)
7701 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
7702 howto
= bfd_reloc
.howto
;
7708 if (r_symndx
< symtab_hdr
->sh_info
)
7710 sym
= local_syms
+ r_symndx
;
7711 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
7712 sec
= local_sections
[r_symndx
];
7713 if (globals
->use_rel
)
7715 relocation
= (sec
->output_section
->vma
7716 + sec
->output_offset
7718 if (!info
->relocatable
7719 && (sec
->flags
& SEC_MERGE
)
7720 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7723 bfd_vma addend
, value
;
7727 case R_ARM_MOVW_ABS_NC
:
7728 case R_ARM_MOVT_ABS
:
7729 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7730 addend
= ((value
& 0xf0000) >> 4) | (value
& 0xfff);
7731 addend
= (addend
^ 0x8000) - 0x8000;
7734 case R_ARM_THM_MOVW_ABS_NC
:
7735 case R_ARM_THM_MOVT_ABS
:
7736 value
= bfd_get_16 (input_bfd
, contents
+ rel
->r_offset
)
7738 value
|= bfd_get_16 (input_bfd
,
7739 contents
+ rel
->r_offset
+ 2);
7740 addend
= ((value
& 0xf7000) >> 4) | (value
& 0xff)
7741 | ((value
& 0x04000000) >> 15);
7742 addend
= (addend
^ 0x8000) - 0x8000;
7746 if (howto
->rightshift
7747 || (howto
->src_mask
& (howto
->src_mask
+ 1)))
7749 (*_bfd_error_handler
)
7750 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7751 input_bfd
, input_section
,
7752 (long) rel
->r_offset
, howto
->name
);
7756 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7758 /* Get the (signed) value from the instruction. */
7759 addend
= value
& howto
->src_mask
;
7760 if (addend
& ((howto
->src_mask
+ 1) >> 1))
7762 bfd_signed_vma mask
;
7765 mask
&= ~ howto
->src_mask
;
7773 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
7775 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
7777 /* Cases here must match those in the preceeding
7778 switch statement. */
7781 case R_ARM_MOVW_ABS_NC
:
7782 case R_ARM_MOVT_ABS
:
7783 value
= (value
& 0xfff0f000) | ((addend
& 0xf000) << 4)
7785 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
7788 case R_ARM_THM_MOVW_ABS_NC
:
7789 case R_ARM_THM_MOVT_ABS
:
7790 value
= (value
& 0xfbf08f00) | ((addend
& 0xf700) << 4)
7791 | (addend
& 0xff) | ((addend
& 0x0800) << 15);
7792 bfd_put_16 (input_bfd
, value
>> 16,
7793 contents
+ rel
->r_offset
);
7794 bfd_put_16 (input_bfd
, value
,
7795 contents
+ rel
->r_offset
+ 2);
7799 value
= (value
& ~ howto
->dst_mask
)
7800 | (addend
& howto
->dst_mask
);
7801 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
7807 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
7813 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
7814 r_symndx
, symtab_hdr
, sym_hashes
,
7816 unresolved_reloc
, warned
);
7821 if (sec
!= NULL
&& elf_discarded_section (sec
))
7823 /* For relocs against symbols from removed linkonce sections,
7824 or sections discarded by a linker script, we just want the
7825 section contents zeroed. Avoid any special processing. */
7826 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
7832 if (info
->relocatable
)
7834 /* This is a relocatable link. We don't have to change
7835 anything, unless the reloc is against a section symbol,
7836 in which case we have to adjust according to where the
7837 section symbol winds up in the output section. */
7838 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
7840 if (globals
->use_rel
)
7841 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
7842 howto
, (bfd_signed_vma
) sec
->output_offset
);
7844 rel
->r_addend
+= sec
->output_offset
;
7850 name
= h
->root
.root
.string
;
7853 name
= (bfd_elf_string_from_elf_section
7854 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
7855 if (name
== NULL
|| *name
== '\0')
7856 name
= bfd_section_name (input_bfd
, sec
);
7860 && r_type
!= R_ARM_NONE
7862 || h
->root
.type
== bfd_link_hash_defined
7863 || h
->root
.type
== bfd_link_hash_defweak
)
7864 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
7866 (*_bfd_error_handler
)
7867 ((sym_type
== STT_TLS
7868 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
7869 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
7872 (long) rel
->r_offset
,
7877 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
7878 input_section
, contents
, rel
,
7879 relocation
, info
, sec
, name
,
7880 (h
? ELF_ST_TYPE (h
->type
) :
7881 ELF_ST_TYPE (sym
->st_info
)), h
,
7882 &unresolved_reloc
, &error_message
);
7884 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
7885 because such sections are not SEC_ALLOC and thus ld.so will
7886 not process them. */
7887 if (unresolved_reloc
7888 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
7891 (*_bfd_error_handler
)
7892 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
7895 (long) rel
->r_offset
,
7897 h
->root
.root
.string
);
7901 if (r
!= bfd_reloc_ok
)
7905 case bfd_reloc_overflow
:
7906 /* If the overflowing reloc was to an undefined symbol,
7907 we have already printed one error message and there
7908 is no point complaining again. */
7910 h
->root
.type
!= bfd_link_hash_undefined
)
7911 && (!((*info
->callbacks
->reloc_overflow
)
7912 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
7913 (bfd_vma
) 0, input_bfd
, input_section
,
7918 case bfd_reloc_undefined
:
7919 if (!((*info
->callbacks
->undefined_symbol
)
7920 (info
, name
, input_bfd
, input_section
,
7921 rel
->r_offset
, TRUE
)))
7925 case bfd_reloc_outofrange
:
7926 error_message
= _("out of range");
7929 case bfd_reloc_notsupported
:
7930 error_message
= _("unsupported relocation");
7933 case bfd_reloc_dangerous
:
7934 /* error_message should already be set. */
7938 error_message
= _("unknown error");
7942 BFD_ASSERT (error_message
!= NULL
);
7943 if (!((*info
->callbacks
->reloc_dangerous
)
7944 (info
, error_message
, input_bfd
, input_section
,
7955 /* Set the right machine number. */
7958 elf32_arm_object_p (bfd
*abfd
)
7962 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
7964 if (mach
!= bfd_mach_arm_unknown
)
7965 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
7967 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
7968 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
7971 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
7976 /* Function to keep ARM specific flags in the ELF header. */
7979 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
7981 if (elf_flags_init (abfd
)
7982 && elf_elfheader (abfd
)->e_flags
!= flags
)
7984 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
7986 if (flags
& EF_ARM_INTERWORK
)
7987 (*_bfd_error_handler
)
7988 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
7992 (_("Warning: Clearing the interworking flag of %B due to outside request"),
7998 elf_elfheader (abfd
)->e_flags
= flags
;
7999 elf_flags_init (abfd
) = TRUE
;
8005 /* Copy backend specific data from one object module to another. */
8008 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
8013 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
8016 in_flags
= elf_elfheader (ibfd
)->e_flags
;
8017 out_flags
= elf_elfheader (obfd
)->e_flags
;
8019 if (elf_flags_init (obfd
)
8020 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
8021 && in_flags
!= out_flags
)
8023 /* Cannot mix APCS26 and APCS32 code. */
8024 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
8027 /* Cannot mix float APCS and non-float APCS code. */
8028 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
8031 /* If the src and dest have different interworking flags
8032 then turn off the interworking bit. */
8033 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
8035 if (out_flags
& EF_ARM_INTERWORK
)
8037 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8040 in_flags
&= ~EF_ARM_INTERWORK
;
8043 /* Likewise for PIC, though don't warn for this case. */
8044 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
8045 in_flags
&= ~EF_ARM_PIC
;
8048 elf_elfheader (obfd
)->e_flags
= in_flags
;
8049 elf_flags_init (obfd
) = TRUE
;
8051 /* Also copy the EI_OSABI field. */
8052 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
8053 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
8055 /* Copy object attributes. */
8056 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
8061 /* Values for Tag_ABI_PCS_R9_use. */
8070 /* Values for Tag_ABI_PCS_RW_data. */
8073 AEABI_PCS_RW_data_absolute
,
8074 AEABI_PCS_RW_data_PCrel
,
8075 AEABI_PCS_RW_data_SBrel
,
8076 AEABI_PCS_RW_data_unused
8079 /* Values for Tag_ABI_enum_size. */
8085 AEABI_enum_forced_wide
8088 /* Determine whether an object attribute tag takes an integer, a
8092 elf32_arm_obj_attrs_arg_type (int tag
)
8094 if (tag
== Tag_compatibility
)
8096 else if (tag
== 4 || tag
== 5)
8101 return (tag
& 1) != 0 ? 2 : 1;
8104 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8105 are conflicting attributes. */
8108 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
8110 obj_attribute
*in_attr
;
8111 obj_attribute
*out_attr
;
8112 obj_attribute_list
*in_list
;
8113 /* Some tags have 0 = don't care, 1 = strong requirement,
8114 2 = weak requirement. */
8115 static const int order_312
[3] = {3, 1, 2};
8116 /* For use with Tag_VFP_arch. */
8117 static const int order_01243
[5] = {0, 1, 2, 4, 3};
8120 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
8122 /* This is the first object. Copy the attributes. */
8123 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
8125 /* Use the Tag_null value to indicate the attributes have been
8127 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
8132 in_attr
= elf_known_obj_attributes_proc (ibfd
);
8133 out_attr
= elf_known_obj_attributes_proc (obfd
);
8134 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8135 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
8137 /* Ignore mismatches if teh object doesn't use floating point. */
8138 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
8139 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
8140 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
8143 (_("ERROR: %B uses VFP register arguments, %B does not"),
8149 for (i
= 4; i
< NUM_KNOWN_OBJ_ATTRIBUTES
; i
++)
8151 /* Merge this attribute with existing attributes. */
8154 case Tag_CPU_raw_name
:
8156 /* Use whichever has the greatest architecture requirements. We
8157 won't necessarily have both the above tags, so make sure input
8158 name is non-NULL. */
8159 if (in_attr
[Tag_CPU_arch
].i
> out_attr
[Tag_CPU_arch
].i
8161 out_attr
[i
].s
= _bfd_elf_attr_strdup (obfd
, in_attr
[i
].s
);
8164 case Tag_ABI_optimization_goals
:
8165 case Tag_ABI_FP_optimization_goals
:
8166 /* Use the first value seen. */
8170 case Tag_ARM_ISA_use
:
8171 case Tag_THUMB_ISA_use
:
8174 /* ??? Do NEON and WMMX conflict? */
8175 case Tag_ABI_FP_rounding
:
8176 case Tag_ABI_FP_denormal
:
8177 case Tag_ABI_FP_exceptions
:
8178 case Tag_ABI_FP_user_exceptions
:
8179 case Tag_ABI_FP_number_model
:
8180 case Tag_ABI_align8_preserved
:
8181 case Tag_ABI_HardFP_use
:
8182 /* Use the largest value specified. */
8183 if (in_attr
[i
].i
> out_attr
[i
].i
)
8184 out_attr
[i
].i
= in_attr
[i
].i
;
8187 case Tag_CPU_arch_profile
:
8188 /* Warn if conflicting architecture profiles used. */
8189 if (out_attr
[i
].i
&& in_attr
[i
].i
&& in_attr
[i
].i
!= out_attr
[i
].i
)
8192 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
8193 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
8197 out_attr
[i
].i
= in_attr
[i
].i
;
8200 if (in_attr
[i
].i
> 4 || out_attr
[i
].i
> 4
8201 || order_01243
[in_attr
[i
].i
] > order_01243
[out_attr
[i
].i
])
8202 out_attr
[i
].i
= in_attr
[i
].i
;
8204 case Tag_PCS_config
:
8205 if (out_attr
[i
].i
== 0)
8206 out_attr
[i
].i
= in_attr
[i
].i
;
8207 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
8209 /* It's sometimes ok to mix different configs, so this is only
8212 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
8215 case Tag_ABI_PCS_R9_use
:
8216 if (in_attr
[i
].i
!= out_attr
[i
].i
8217 && out_attr
[i
].i
!= AEABI_R9_unused
8218 && in_attr
[i
].i
!= AEABI_R9_unused
)
8221 (_("ERROR: %B: Conflicting use of R9"), ibfd
);
8224 if (out_attr
[i
].i
== AEABI_R9_unused
)
8225 out_attr
[i
].i
= in_attr
[i
].i
;
8227 case Tag_ABI_PCS_RW_data
:
8228 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
8229 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
8230 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
8233 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
8237 /* Use the smallest value specified. */
8238 if (in_attr
[i
].i
< out_attr
[i
].i
)
8239 out_attr
[i
].i
= in_attr
[i
].i
;
8241 case Tag_ABI_PCS_RO_data
:
8242 /* Use the smallest value specified. */
8243 if (in_attr
[i
].i
< out_attr
[i
].i
)
8244 out_attr
[i
].i
= in_attr
[i
].i
;
8246 case Tag_ABI_PCS_GOT_use
:
8247 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
8248 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
8249 out_attr
[i
].i
= in_attr
[i
].i
;
8251 case Tag_ABI_PCS_wchar_t
:
8252 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
8253 && !elf_arm_tdata (obfd
)->no_wchar_size_warning
)
8256 (_("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"),
8257 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
8259 else if (in_attr
[i
].i
&& !out_attr
[i
].i
)
8260 out_attr
[i
].i
= in_attr
[i
].i
;
8262 case Tag_ABI_align8_needed
:
8263 /* ??? Check against Tag_ABI_align8_preserved. */
8264 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
8265 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
8266 out_attr
[i
].i
= in_attr
[i
].i
;
8268 case Tag_ABI_enum_size
:
8269 if (in_attr
[i
].i
!= AEABI_enum_unused
)
8271 if (out_attr
[i
].i
== AEABI_enum_unused
8272 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
8274 /* The existing object is compatible with anything.
8275 Use whatever requirements the new object has. */
8276 out_attr
[i
].i
= in_attr
[i
].i
;
8278 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
8279 && out_attr
[i
].i
!= in_attr
[i
].i
8280 && !elf_arm_tdata (obfd
)->no_enum_size_warning
)
8282 const char *aeabi_enum_names
[] =
8283 { "", "variable-size", "32-bit", "" };
8285 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8286 ibfd
, aeabi_enum_names
[in_attr
[i
].i
],
8287 aeabi_enum_names
[out_attr
[i
].i
]);
8291 case Tag_ABI_VFP_args
:
8294 case Tag_ABI_WMMX_args
:
8295 if (in_attr
[i
].i
!= out_attr
[i
].i
)
8298 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
8303 default: /* All known attributes should be explicitly covered. */
8307 if (in_attr
[i
].type
&& !out_attr
[i
].type
)
8308 switch (in_attr
[i
].type
)
8312 out_attr
[i
].type
= 1;
8317 out_attr
[i
].type
= 2;
8325 /* Merge Tag_compatibility attributes and any common GNU ones. */
8326 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
8328 /* Check for any attributes not known on ARM. */
8329 in_list
= elf_other_obj_attributes_proc (ibfd
);
8330 while (in_list
&& in_list
->tag
== Tag_compatibility
)
8331 in_list
= in_list
->next
;
8333 for (; in_list
; in_list
= in_list
->next
)
8335 if ((in_list
->tag
& 128) < 64)
8338 (_("Warning: %B: Unknown EABI object attribute %d"),
8339 ibfd
, in_list
->tag
);
8347 /* Return TRUE if the two EABI versions are incompatible. */
8350 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
8352 /* v4 and v5 are the same spec before and after it was released,
8353 so allow mixing them. */
8354 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
8355 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
8358 return (iver
== over
);
8361 /* Merge backend specific data from an object file to the output
8362 object file when linking. */
8365 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
8369 bfd_boolean flags_compatible
= TRUE
;
8372 /* Check if we have the same endianess. */
8373 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
8376 if (! is_arm_elf (ibfd
) || ! is_arm_elf (obfd
))
8379 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
8382 /* The input BFD must have had its flags initialised. */
8383 /* The following seems bogus to me -- The flags are initialized in
8384 the assembler but I don't think an elf_flags_init field is
8385 written into the object. */
8386 /* BFD_ASSERT (elf_flags_init (ibfd)); */
8388 in_flags
= elf_elfheader (ibfd
)->e_flags
;
8389 out_flags
= elf_elfheader (obfd
)->e_flags
;
8391 /* In theory there is no reason why we couldn't handle this. However
8392 in practice it isn't even close to working and there is no real
8393 reason to want it. */
8394 if (EF_ARM_EABI_VERSION (in_flags
) >= EF_ARM_EABI_VER4
8395 && !(ibfd
->flags
& DYNAMIC
)
8396 && (in_flags
& EF_ARM_BE8
))
8398 _bfd_error_handler (_("ERROR: %B is already in final BE8 format"),
8403 if (!elf_flags_init (obfd
))
8405 /* If the input is the default architecture and had the default
8406 flags then do not bother setting the flags for the output
8407 architecture, instead allow future merges to do this. If no
8408 future merges ever set these flags then they will retain their
8409 uninitialised values, which surprise surprise, correspond
8410 to the default values. */
8411 if (bfd_get_arch_info (ibfd
)->the_default
8412 && elf_elfheader (ibfd
)->e_flags
== 0)
8415 elf_flags_init (obfd
) = TRUE
;
8416 elf_elfheader (obfd
)->e_flags
= in_flags
;
8418 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
8419 && bfd_get_arch_info (obfd
)->the_default
)
8420 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
8425 /* Determine what should happen if the input ARM architecture
8426 does not match the output ARM architecture. */
8427 if (! bfd_arm_merge_machines (ibfd
, obfd
))
8430 /* Identical flags must be compatible. */
8431 if (in_flags
== out_flags
)
8434 /* Check to see if the input BFD actually contains any sections. If
8435 not, its flags may not have been initialised either, but it
8436 cannot actually cause any incompatiblity. Do not short-circuit
8437 dynamic objects; their section list may be emptied by
8438 elf_link_add_object_symbols.
8440 Also check to see if there are no code sections in the input.
8441 In this case there is no need to check for code specific flags.
8442 XXX - do we need to worry about floating-point format compatability
8443 in data sections ? */
8444 if (!(ibfd
->flags
& DYNAMIC
))
8446 bfd_boolean null_input_bfd
= TRUE
;
8447 bfd_boolean only_data_sections
= TRUE
;
8449 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8451 /* Ignore synthetic glue sections. */
8452 if (strcmp (sec
->name
, ".glue_7")
8453 && strcmp (sec
->name
, ".glue_7t"))
8455 if ((bfd_get_section_flags (ibfd
, sec
)
8456 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
8457 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
8458 only_data_sections
= FALSE
;
8460 null_input_bfd
= FALSE
;
8465 if (null_input_bfd
|| only_data_sections
)
8469 /* Complain about various flag mismatches. */
8470 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
8471 EF_ARM_EABI_VERSION (out_flags
)))
8474 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
8476 (in_flags
& EF_ARM_EABIMASK
) >> 24,
8477 (out_flags
& EF_ARM_EABIMASK
) >> 24);
8481 /* Not sure what needs to be checked for EABI versions >= 1. */
8482 /* VxWorks libraries do not use these flags. */
8483 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
8484 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
8485 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
8487 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
8490 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
8492 in_flags
& EF_ARM_APCS_26
? 26 : 32,
8493 out_flags
& EF_ARM_APCS_26
? 26 : 32);
8494 flags_compatible
= FALSE
;
8497 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
8499 if (in_flags
& EF_ARM_APCS_FLOAT
)
8501 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
8505 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
8508 flags_compatible
= FALSE
;
8511 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
8513 if (in_flags
& EF_ARM_VFP_FLOAT
)
8515 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
8519 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
8522 flags_compatible
= FALSE
;
8525 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
8527 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
8529 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
8533 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
8536 flags_compatible
= FALSE
;
8539 #ifdef EF_ARM_SOFT_FLOAT
8540 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
8542 /* We can allow interworking between code that is VFP format
8543 layout, and uses either soft float or integer regs for
8544 passing floating point arguments and results. We already
8545 know that the APCS_FLOAT flags match; similarly for VFP
8547 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
8548 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
8550 if (in_flags
& EF_ARM_SOFT_FLOAT
)
8552 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
8556 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
8559 flags_compatible
= FALSE
;
8564 /* Interworking mismatch is only a warning. */
8565 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
8567 if (in_flags
& EF_ARM_INTERWORK
)
8570 (_("Warning: %B supports interworking, whereas %B does not"),
8576 (_("Warning: %B does not support interworking, whereas %B does"),
8582 return flags_compatible
;
8585 /* Display the flags field. */
8588 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
8590 FILE * file
= (FILE *) ptr
;
8591 unsigned long flags
;
8593 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
8595 /* Print normal ELF private data. */
8596 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
8598 flags
= elf_elfheader (abfd
)->e_flags
;
8599 /* Ignore init flag - it may not be set, despite the flags field
8600 containing valid data. */
8602 /* xgettext:c-format */
8603 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
8605 switch (EF_ARM_EABI_VERSION (flags
))
8607 case EF_ARM_EABI_UNKNOWN
:
8608 /* The following flag bits are GNU extensions and not part of the
8609 official ARM ELF extended ABI. Hence they are only decoded if
8610 the EABI version is not set. */
8611 if (flags
& EF_ARM_INTERWORK
)
8612 fprintf (file
, _(" [interworking enabled]"));
8614 if (flags
& EF_ARM_APCS_26
)
8615 fprintf (file
, " [APCS-26]");
8617 fprintf (file
, " [APCS-32]");
8619 if (flags
& EF_ARM_VFP_FLOAT
)
8620 fprintf (file
, _(" [VFP float format]"));
8621 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
8622 fprintf (file
, _(" [Maverick float format]"));
8624 fprintf (file
, _(" [FPA float format]"));
8626 if (flags
& EF_ARM_APCS_FLOAT
)
8627 fprintf (file
, _(" [floats passed in float registers]"));
8629 if (flags
& EF_ARM_PIC
)
8630 fprintf (file
, _(" [position independent]"));
8632 if (flags
& EF_ARM_NEW_ABI
)
8633 fprintf (file
, _(" [new ABI]"));
8635 if (flags
& EF_ARM_OLD_ABI
)
8636 fprintf (file
, _(" [old ABI]"));
8638 if (flags
& EF_ARM_SOFT_FLOAT
)
8639 fprintf (file
, _(" [software FP]"));
8641 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
8642 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
8643 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
8644 | EF_ARM_MAVERICK_FLOAT
);
8647 case EF_ARM_EABI_VER1
:
8648 fprintf (file
, _(" [Version1 EABI]"));
8650 if (flags
& EF_ARM_SYMSARESORTED
)
8651 fprintf (file
, _(" [sorted symbol table]"));
8653 fprintf (file
, _(" [unsorted symbol table]"));
8655 flags
&= ~ EF_ARM_SYMSARESORTED
;
8658 case EF_ARM_EABI_VER2
:
8659 fprintf (file
, _(" [Version2 EABI]"));
8661 if (flags
& EF_ARM_SYMSARESORTED
)
8662 fprintf (file
, _(" [sorted symbol table]"));
8664 fprintf (file
, _(" [unsorted symbol table]"));
8666 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
8667 fprintf (file
, _(" [dynamic symbols use segment index]"));
8669 if (flags
& EF_ARM_MAPSYMSFIRST
)
8670 fprintf (file
, _(" [mapping symbols precede others]"));
8672 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
8673 | EF_ARM_MAPSYMSFIRST
);
8676 case EF_ARM_EABI_VER3
:
8677 fprintf (file
, _(" [Version3 EABI]"));
8680 case EF_ARM_EABI_VER4
:
8681 fprintf (file
, _(" [Version4 EABI]"));
8684 case EF_ARM_EABI_VER5
:
8685 fprintf (file
, _(" [Version5 EABI]"));
8687 if (flags
& EF_ARM_BE8
)
8688 fprintf (file
, _(" [BE8]"));
8690 if (flags
& EF_ARM_LE8
)
8691 fprintf (file
, _(" [LE8]"));
8693 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
8697 fprintf (file
, _(" <EABI version unrecognised>"));
8701 flags
&= ~ EF_ARM_EABIMASK
;
8703 if (flags
& EF_ARM_RELEXEC
)
8704 fprintf (file
, _(" [relocatable executable]"));
8706 if (flags
& EF_ARM_HASENTRY
)
8707 fprintf (file
, _(" [has entry point]"));
8709 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
8712 fprintf (file
, _("<Unrecognised flag bits set>"));
8720 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
8722 switch (ELF_ST_TYPE (elf_sym
->st_info
))
8725 return ELF_ST_TYPE (elf_sym
->st_info
);
8728 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
8729 This allows us to distinguish between data used by Thumb instructions
8730 and non-data (which is probably code) inside Thumb regions of an
8732 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
8733 return ELF_ST_TYPE (elf_sym
->st_info
);
8744 elf32_arm_gc_mark_hook (asection
*sec
,
8745 struct bfd_link_info
*info
,
8746 Elf_Internal_Rela
*rel
,
8747 struct elf_link_hash_entry
*h
,
8748 Elf_Internal_Sym
*sym
)
8751 switch (ELF32_R_TYPE (rel
->r_info
))
8753 case R_ARM_GNU_VTINHERIT
:
8754 case R_ARM_GNU_VTENTRY
:
8758 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
8761 /* Update the got entry reference counts for the section being removed. */
8764 elf32_arm_gc_sweep_hook (bfd
* abfd
,
8765 struct bfd_link_info
* info
,
8767 const Elf_Internal_Rela
* relocs
)
8769 Elf_Internal_Shdr
*symtab_hdr
;
8770 struct elf_link_hash_entry
**sym_hashes
;
8771 bfd_signed_vma
*local_got_refcounts
;
8772 const Elf_Internal_Rela
*rel
, *relend
;
8773 struct elf32_arm_link_hash_table
* globals
;
8775 if (info
->relocatable
)
8778 globals
= elf32_arm_hash_table (info
);
8780 elf_section_data (sec
)->local_dynrel
= NULL
;
8782 symtab_hdr
= & elf_symtab_hdr (abfd
);
8783 sym_hashes
= elf_sym_hashes (abfd
);
8784 local_got_refcounts
= elf_local_got_refcounts (abfd
);
8786 check_use_blx (globals
);
8788 relend
= relocs
+ sec
->reloc_count
;
8789 for (rel
= relocs
; rel
< relend
; rel
++)
8791 unsigned long r_symndx
;
8792 struct elf_link_hash_entry
*h
= NULL
;
8795 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8796 if (r_symndx
>= symtab_hdr
->sh_info
)
8798 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8799 while (h
->root
.type
== bfd_link_hash_indirect
8800 || h
->root
.type
== bfd_link_hash_warning
)
8801 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8804 r_type
= ELF32_R_TYPE (rel
->r_info
);
8805 r_type
= arm_real_reloc_type (globals
, r_type
);
8809 case R_ARM_GOT_PREL
:
8810 case R_ARM_TLS_GD32
:
8811 case R_ARM_TLS_IE32
:
8814 if (h
->got
.refcount
> 0)
8815 h
->got
.refcount
-= 1;
8817 else if (local_got_refcounts
!= NULL
)
8819 if (local_got_refcounts
[r_symndx
] > 0)
8820 local_got_refcounts
[r_symndx
] -= 1;
8824 case R_ARM_TLS_LDM32
:
8825 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
8829 case R_ARM_ABS32_NOI
:
8831 case R_ARM_REL32_NOI
:
8837 case R_ARM_THM_CALL
:
8838 case R_ARM_THM_JUMP24
:
8839 case R_ARM_THM_JUMP19
:
8840 case R_ARM_MOVW_ABS_NC
:
8841 case R_ARM_MOVT_ABS
:
8842 case R_ARM_MOVW_PREL_NC
:
8843 case R_ARM_MOVT_PREL
:
8844 case R_ARM_THM_MOVW_ABS_NC
:
8845 case R_ARM_THM_MOVT_ABS
:
8846 case R_ARM_THM_MOVW_PREL_NC
:
8847 case R_ARM_THM_MOVT_PREL
:
8848 /* Should the interworking branches be here also? */
8852 struct elf32_arm_link_hash_entry
*eh
;
8853 struct elf32_arm_relocs_copied
**pp
;
8854 struct elf32_arm_relocs_copied
*p
;
8856 eh
= (struct elf32_arm_link_hash_entry
*) h
;
8858 if (h
->plt
.refcount
> 0)
8860 h
->plt
.refcount
-= 1;
8861 if (r_type
== R_ARM_THM_CALL
)
8862 eh
->plt_maybe_thumb_refcount
--;
8864 if (r_type
== R_ARM_THM_JUMP24
8865 || r_type
== R_ARM_THM_JUMP19
)
8866 eh
->plt_thumb_refcount
--;
8869 if (r_type
== R_ARM_ABS32
8870 || r_type
== R_ARM_REL32
8871 || r_type
== R_ARM_ABS32_NOI
8872 || r_type
== R_ARM_REL32_NOI
)
8874 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
8876 if (p
->section
== sec
)
8879 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
8880 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32_NOI
)
8898 /* Look through the relocs for a section during the first phase. */
8901 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
8902 asection
*sec
, const Elf_Internal_Rela
*relocs
)
8904 Elf_Internal_Shdr
*symtab_hdr
;
8905 struct elf_link_hash_entry
**sym_hashes
;
8906 const Elf_Internal_Rela
*rel
;
8907 const Elf_Internal_Rela
*rel_end
;
8910 bfd_vma
*local_got_offsets
;
8911 struct elf32_arm_link_hash_table
*htab
;
8912 bfd_boolean needs_plt
;
8914 if (info
->relocatable
)
8917 BFD_ASSERT (is_arm_elf (abfd
));
8919 htab
= elf32_arm_hash_table (info
);
8922 /* Create dynamic sections for relocatable executables so that we can
8923 copy relocations. */
8924 if (htab
->root
.is_relocatable_executable
8925 && ! htab
->root
.dynamic_sections_created
)
8927 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
8931 dynobj
= elf_hash_table (info
)->dynobj
;
8932 local_got_offsets
= elf_local_got_offsets (abfd
);
8934 symtab_hdr
= & elf_symtab_hdr (abfd
);
8935 sym_hashes
= elf_sym_hashes (abfd
);
8937 rel_end
= relocs
+ sec
->reloc_count
;
8938 for (rel
= relocs
; rel
< rel_end
; rel
++)
8940 struct elf_link_hash_entry
*h
;
8941 struct elf32_arm_link_hash_entry
*eh
;
8942 unsigned long r_symndx
;
8945 r_symndx
= ELF32_R_SYM (rel
->r_info
);
8946 r_type
= ELF32_R_TYPE (rel
->r_info
);
8947 r_type
= arm_real_reloc_type (htab
, r_type
);
8949 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
8951 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
8956 if (r_symndx
< symtab_hdr
->sh_info
)
8960 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8961 while (h
->root
.type
== bfd_link_hash_indirect
8962 || h
->root
.type
== bfd_link_hash_warning
)
8963 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8966 eh
= (struct elf32_arm_link_hash_entry
*) h
;
8971 case R_ARM_GOT_PREL
:
8972 case R_ARM_TLS_GD32
:
8973 case R_ARM_TLS_IE32
:
8974 /* This symbol requires a global offset table entry. */
8976 int tls_type
, old_tls_type
;
8980 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
8981 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
8982 default: tls_type
= GOT_NORMAL
; break;
8988 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
8992 bfd_signed_vma
*local_got_refcounts
;
8994 /* This is a global offset table entry for a local symbol. */
8995 local_got_refcounts
= elf_local_got_refcounts (abfd
);
8996 if (local_got_refcounts
== NULL
)
9000 size
= symtab_hdr
->sh_info
;
9001 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
9002 local_got_refcounts
= bfd_zalloc (abfd
, size
);
9003 if (local_got_refcounts
== NULL
)
9005 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
9006 elf32_arm_local_got_tls_type (abfd
)
9007 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
9009 local_got_refcounts
[r_symndx
] += 1;
9010 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
9013 /* We will already have issued an error message if there is a
9014 TLS / non-TLS mismatch, based on the symbol type. We don't
9015 support any linker relaxations. So just combine any TLS
9017 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
9018 && tls_type
!= GOT_NORMAL
)
9019 tls_type
|= old_tls_type
;
9021 if (old_tls_type
!= tls_type
)
9024 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
9026 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
9031 case R_ARM_TLS_LDM32
:
9032 if (r_type
== R_ARM_TLS_LDM32
)
9033 htab
->tls_ldm_got
.refcount
++;
9036 case R_ARM_GOTOFF32
:
9038 if (htab
->sgot
== NULL
)
9040 if (htab
->root
.dynobj
== NULL
)
9041 htab
->root
.dynobj
= abfd
;
9042 if (!create_got_section (htab
->root
.dynobj
, info
))
9048 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9049 ldr __GOTT_INDEX__ offsets. */
9050 if (!htab
->vxworks_p
)
9059 case R_ARM_THM_CALL
:
9060 case R_ARM_THM_JUMP24
:
9061 case R_ARM_THM_JUMP19
:
9066 case R_ARM_ABS32_NOI
:
9068 case R_ARM_REL32_NOI
:
9069 case R_ARM_MOVW_ABS_NC
:
9070 case R_ARM_MOVT_ABS
:
9071 case R_ARM_MOVW_PREL_NC
:
9072 case R_ARM_MOVT_PREL
:
9073 case R_ARM_THM_MOVW_ABS_NC
:
9074 case R_ARM_THM_MOVT_ABS
:
9075 case R_ARM_THM_MOVW_PREL_NC
:
9076 case R_ARM_THM_MOVT_PREL
:
9080 /* Should the interworking branches be listed here? */
9083 /* If this reloc is in a read-only section, we might
9084 need a copy reloc. We can't check reliably at this
9085 stage whether the section is read-only, as input
9086 sections have not yet been mapped to output sections.
9087 Tentatively set the flag for now, and correct in
9088 adjust_dynamic_symbol. */
9092 /* We may need a .plt entry if the function this reloc
9093 refers to is in a different object. We can't tell for
9094 sure yet, because something later might force the
9099 /* If we create a PLT entry, this relocation will reference
9100 it, even if it's an ABS32 relocation. */
9101 h
->plt
.refcount
+= 1;
9103 /* It's too early to use htab->use_blx here, so we have to
9104 record possible blx references separately from
9105 relocs that definitely need a thumb stub. */
9107 if (r_type
== R_ARM_THM_CALL
)
9108 eh
->plt_maybe_thumb_refcount
+= 1;
9110 if (r_type
== R_ARM_THM_JUMP24
9111 || r_type
== R_ARM_THM_JUMP19
)
9112 eh
->plt_thumb_refcount
+= 1;
9115 /* If we are creating a shared library or relocatable executable,
9116 and this is a reloc against a global symbol, or a non PC
9117 relative reloc against a local symbol, then we need to copy
9118 the reloc into the shared library. However, if we are linking
9119 with -Bsymbolic, we do not need to copy a reloc against a
9120 global symbol which is defined in an object we are
9121 including in the link (i.e., DEF_REGULAR is set). At
9122 this point we have not seen all the input files, so it is
9123 possible that DEF_REGULAR is not set now but will be set
9124 later (it is never cleared). We account for that
9125 possibility below by storing information in the
9126 relocs_copied field of the hash table entry. */
9127 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
9128 && (sec
->flags
& SEC_ALLOC
) != 0
9129 && ((r_type
== R_ARM_ABS32
|| r_type
== R_ARM_ABS32_NOI
)
9130 || (h
!= NULL
&& ! h
->needs_plt
9131 && (! info
->symbolic
|| ! h
->def_regular
))))
9133 struct elf32_arm_relocs_copied
*p
, **head
;
9135 /* When creating a shared object, we must copy these
9136 reloc types into the output file. We create a reloc
9137 section in dynobj and make room for this reloc. */
9142 name
= (bfd_elf_string_from_elf_section
9144 elf_elfheader (abfd
)->e_shstrndx
,
9145 elf_section_data (sec
)->rel_hdr
.sh_name
));
9149 BFD_ASSERT (reloc_section_p (htab
, name
, sec
));
9151 sreloc
= bfd_get_section_by_name (dynobj
, name
);
9156 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
9157 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
9158 if ((sec
->flags
& SEC_ALLOC
) != 0
9159 /* BPABI objects never have dynamic
9160 relocations mapped. */
9161 && !htab
->symbian_p
)
9162 flags
|= SEC_ALLOC
| SEC_LOAD
;
9163 sreloc
= bfd_make_section_with_flags (dynobj
,
9167 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
9171 elf_section_data (sec
)->sreloc
= sreloc
;
9174 /* If this is a global symbol, we count the number of
9175 relocations we need for this symbol. */
9178 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
9182 /* Track dynamic relocs needed for local syms too.
9183 We really need local syms available to do this
9189 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
9194 vpp
= &elf_section_data (s
)->local_dynrel
;
9195 head
= (struct elf32_arm_relocs_copied
**) vpp
;
9199 if (p
== NULL
|| p
->section
!= sec
)
9201 bfd_size_type amt
= sizeof *p
;
9203 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
9213 if (r_type
== R_ARM_REL32
|| r_type
== R_ARM_REL32_NOI
)
9219 /* This relocation describes the C++ object vtable hierarchy.
9220 Reconstruct it for later use during GC. */
9221 case R_ARM_GNU_VTINHERIT
:
9222 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
9226 /* This relocation describes which C++ vtable entries are actually
9227 used. Record for later use during GC. */
9228 case R_ARM_GNU_VTENTRY
:
9229 BFD_ASSERT (h
!= NULL
);
9231 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
9240 /* Unwinding tables are not referenced directly. This pass marks them as
9241 required if the corresponding code section is marked. */
9244 elf32_arm_gc_mark_extra_sections (struct bfd_link_info
*info
,
9245 elf_gc_mark_hook_fn gc_mark_hook
)
9248 Elf_Internal_Shdr
**elf_shdrp
;
9251 /* Marking EH data may cause additional code sections to be marked,
9252 requiring multiple passes. */
9257 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
9261 if (! is_arm_elf (sub
))
9264 elf_shdrp
= elf_elfsections (sub
);
9265 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
9267 Elf_Internal_Shdr
*hdr
;
9269 hdr
= &elf_section_data (o
)->this_hdr
;
9270 if (hdr
->sh_type
== SHT_ARM_EXIDX
9272 && hdr
->sh_link
< elf_numsections (sub
)
9274 && elf_shdrp
[hdr
->sh_link
]->bfd_section
->gc_mark
)
9277 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
9287 /* Treat mapping symbols as special target symbols. */
9290 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
9292 return bfd_is_arm_special_symbol_name (sym
->name
,
9293 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
9296 /* This is a copy of elf_find_function() from elf.c except that
9297 ARM mapping symbols are ignored when looking for function names
9298 and STT_ARM_TFUNC is considered to a function type. */
9301 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
9305 const char ** filename_ptr
,
9306 const char ** functionname_ptr
)
9308 const char * filename
= NULL
;
9309 asymbol
* func
= NULL
;
9310 bfd_vma low_func
= 0;
9313 for (p
= symbols
; *p
!= NULL
; p
++)
9317 q
= (elf_symbol_type
*) *p
;
9319 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
9324 filename
= bfd_asymbol_name (&q
->symbol
);
9329 /* Skip mapping symbols. */
9330 if ((q
->symbol
.flags
& BSF_LOCAL
)
9331 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
9332 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
9335 if (bfd_get_section (&q
->symbol
) == section
9336 && q
->symbol
.value
>= low_func
9337 && q
->symbol
.value
<= offset
)
9339 func
= (asymbol
*) q
;
9340 low_func
= q
->symbol
.value
;
9350 *filename_ptr
= filename
;
9351 if (functionname_ptr
)
9352 *functionname_ptr
= bfd_asymbol_name (func
);
9358 /* Find the nearest line to a particular section and offset, for error
9359 reporting. This code is a duplicate of the code in elf.c, except
9360 that it uses arm_elf_find_function. */
9363 elf32_arm_find_nearest_line (bfd
* abfd
,
9367 const char ** filename_ptr
,
9368 const char ** functionname_ptr
,
9369 unsigned int * line_ptr
)
9371 bfd_boolean found
= FALSE
;
9373 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
9375 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
9376 filename_ptr
, functionname_ptr
,
9378 & elf_tdata (abfd
)->dwarf2_find_line_info
))
9380 if (!*functionname_ptr
)
9381 arm_elf_find_function (abfd
, section
, symbols
, offset
,
9382 *filename_ptr
? NULL
: filename_ptr
,
9388 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
9389 & found
, filename_ptr
,
9390 functionname_ptr
, line_ptr
,
9391 & elf_tdata (abfd
)->line_info
))
9394 if (found
&& (*functionname_ptr
|| *line_ptr
))
9397 if (symbols
== NULL
)
9400 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
9401 filename_ptr
, functionname_ptr
))
9409 elf32_arm_find_inliner_info (bfd
* abfd
,
9410 const char ** filename_ptr
,
9411 const char ** functionname_ptr
,
9412 unsigned int * line_ptr
)
9415 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
9416 functionname_ptr
, line_ptr
,
9417 & elf_tdata (abfd
)->dwarf2_find_line_info
);
9421 /* Adjust a symbol defined by a dynamic object and referenced by a
9422 regular object. The current definition is in some section of the
9423 dynamic object, but we're not including those sections. We have to
9424 change the definition to something the rest of the link can
9428 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
9429 struct elf_link_hash_entry
* h
)
9433 struct elf32_arm_link_hash_entry
* eh
;
9434 struct elf32_arm_link_hash_table
*globals
;
9436 globals
= elf32_arm_hash_table (info
);
9437 dynobj
= elf_hash_table (info
)->dynobj
;
9439 /* Make sure we know what is going on here. */
9440 BFD_ASSERT (dynobj
!= NULL
9442 || h
->u
.weakdef
!= NULL
9445 && !h
->def_regular
)));
9447 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9449 /* If this is a function, put it in the procedure linkage table. We
9450 will fill in the contents of the procedure linkage table later,
9451 when we know the address of the .got section. */
9452 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
9455 if (h
->plt
.refcount
<= 0
9456 || SYMBOL_CALLS_LOCAL (info
, h
)
9457 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
9458 && h
->root
.type
== bfd_link_hash_undefweak
))
9460 /* This case can occur if we saw a PLT32 reloc in an input
9461 file, but the symbol was never referred to by a dynamic
9462 object, or if all references were garbage collected. In
9463 such a case, we don't actually need to build a procedure
9464 linkage table, and we can just do a PC24 reloc instead. */
9465 h
->plt
.offset
= (bfd_vma
) -1;
9466 eh
->plt_thumb_refcount
= 0;
9467 eh
->plt_maybe_thumb_refcount
= 0;
9475 /* It's possible that we incorrectly decided a .plt reloc was
9476 needed for an R_ARM_PC24 or similar reloc to a non-function sym
9477 in check_relocs. We can't decide accurately between function
9478 and non-function syms in check-relocs; Objects loaded later in
9479 the link may change h->type. So fix it now. */
9480 h
->plt
.offset
= (bfd_vma
) -1;
9481 eh
->plt_thumb_refcount
= 0;
9482 eh
->plt_maybe_thumb_refcount
= 0;
9485 /* If this is a weak symbol, and there is a real definition, the
9486 processor independent code will have arranged for us to see the
9487 real definition first, and we can just use the same value. */
9488 if (h
->u
.weakdef
!= NULL
)
9490 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
9491 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
9492 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
9493 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
9497 /* If there are no non-GOT references, we do not need a copy
9499 if (!h
->non_got_ref
)
9502 /* This is a reference to a symbol defined by a dynamic object which
9503 is not a function. */
9505 /* If we are creating a shared library, we must presume that the
9506 only references to the symbol are via the global offset table.
9507 For such cases we need not do anything here; the relocations will
9508 be handled correctly by relocate_section. Relocatable executables
9509 can reference data in shared objects directly, so we don't need to
9510 do anything here. */
9511 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
9516 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
9517 h
->root
.root
.string
);
9521 /* We must allocate the symbol in our .dynbss section, which will
9522 become part of the .bss section of the executable. There will be
9523 an entry for this symbol in the .dynsym section. The dynamic
9524 object will contain position independent code, so all references
9525 from the dynamic object to this symbol will go through the global
9526 offset table. The dynamic linker will use the .dynsym entry to
9527 determine the address it must put in the global offset table, so
9528 both the dynamic object and the regular object will refer to the
9529 same memory location for the variable. */
9530 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
9531 BFD_ASSERT (s
!= NULL
);
9533 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
9534 copy the initial value out of the dynamic object and into the
9535 runtime process image. We need to remember the offset into the
9536 .rel(a).bss section we are going to use. */
9537 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
9541 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
9542 BFD_ASSERT (srel
!= NULL
);
9543 srel
->size
+= RELOC_SIZE (globals
);
9547 return _bfd_elf_adjust_dynamic_copy (h
, s
);
9550 /* Allocate space in .plt, .got and associated reloc sections for
9554 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
9556 struct bfd_link_info
*info
;
9557 struct elf32_arm_link_hash_table
*htab
;
9558 struct elf32_arm_link_hash_entry
*eh
;
9559 struct elf32_arm_relocs_copied
*p
;
9560 bfd_signed_vma thumb_refs
;
9562 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9564 if (h
->root
.type
== bfd_link_hash_indirect
)
9567 if (h
->root
.type
== bfd_link_hash_warning
)
9568 /* When warning symbols are created, they **replace** the "real"
9569 entry in the hash table, thus we never get to see the real
9570 symbol in a hash traversal. So look at it now. */
9571 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9573 info
= (struct bfd_link_info
*) inf
;
9574 htab
= elf32_arm_hash_table (info
);
9576 if (htab
->root
.dynamic_sections_created
9577 && h
->plt
.refcount
> 0)
9579 /* Make sure this symbol is output as a dynamic symbol.
9580 Undefined weak syms won't yet be marked as dynamic. */
9581 if (h
->dynindx
== -1
9582 && !h
->forced_local
)
9584 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9589 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
9591 asection
*s
= htab
->splt
;
9593 /* If this is the first .plt entry, make room for the special
9596 s
->size
+= htab
->plt_header_size
;
9598 h
->plt
.offset
= s
->size
;
9600 /* If we will insert a Thumb trampoline before this PLT, leave room
9602 thumb_refs
= eh
->plt_thumb_refcount
;
9604 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
9608 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
9609 s
->size
+= PLT_THUMB_STUB_SIZE
;
9612 /* If this symbol is not defined in a regular file, and we are
9613 not generating a shared library, then set the symbol to this
9614 location in the .plt. This is required to make function
9615 pointers compare as equal between the normal executable and
9616 the shared library. */
9620 h
->root
.u
.def
.section
= s
;
9621 h
->root
.u
.def
.value
= h
->plt
.offset
;
9623 /* Make sure the function is not marked as Thumb, in case
9624 it is the target of an ABS32 relocation, which will
9625 point to the PLT entry. */
9626 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
9627 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
9630 /* Make room for this entry. */
9631 s
->size
+= htab
->plt_entry_size
;
9633 if (!htab
->symbian_p
)
9635 /* We also need to make an entry in the .got.plt section, which
9636 will be placed in the .got section by the linker script. */
9637 eh
->plt_got_offset
= htab
->sgotplt
->size
;
9638 htab
->sgotplt
->size
+= 4;
9641 /* We also need to make an entry in the .rel(a).plt section. */
9642 htab
->srelplt
->size
+= RELOC_SIZE (htab
);
9644 /* VxWorks executables have a second set of relocations for
9645 each PLT entry. They go in a separate relocation section,
9646 which is processed by the kernel loader. */
9647 if (htab
->vxworks_p
&& !info
->shared
)
9649 /* There is a relocation for the initial PLT entry:
9650 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
9651 if (h
->plt
.offset
== htab
->plt_header_size
)
9652 htab
->srelplt2
->size
+= RELOC_SIZE (htab
);
9654 /* There are two extra relocations for each subsequent
9655 PLT entry: an R_ARM_32 relocation for the GOT entry,
9656 and an R_ARM_32 relocation for the PLT entry. */
9657 htab
->srelplt2
->size
+= RELOC_SIZE (htab
) * 2;
9662 h
->plt
.offset
= (bfd_vma
) -1;
9668 h
->plt
.offset
= (bfd_vma
) -1;
9672 if (h
->got
.refcount
> 0)
9676 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
9679 /* Make sure this symbol is output as a dynamic symbol.
9680 Undefined weak syms won't yet be marked as dynamic. */
9681 if (h
->dynindx
== -1
9682 && !h
->forced_local
)
9684 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9688 if (!htab
->symbian_p
)
9691 h
->got
.offset
= s
->size
;
9693 if (tls_type
== GOT_UNKNOWN
)
9696 if (tls_type
== GOT_NORMAL
)
9697 /* Non-TLS symbols need one GOT slot. */
9701 if (tls_type
& GOT_TLS_GD
)
9702 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
9704 if (tls_type
& GOT_TLS_IE
)
9705 /* R_ARM_TLS_IE32 needs one GOT slot. */
9709 dyn
= htab
->root
.dynamic_sections_created
;
9712 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
9714 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9717 if (tls_type
!= GOT_NORMAL
9718 && (info
->shared
|| indx
!= 0)
9719 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9720 || h
->root
.type
!= bfd_link_hash_undefweak
))
9722 if (tls_type
& GOT_TLS_IE
)
9723 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
9725 if (tls_type
& GOT_TLS_GD
)
9726 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
9728 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
9729 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
9731 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9732 || h
->root
.type
!= bfd_link_hash_undefweak
)
9734 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
9735 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
9739 h
->got
.offset
= (bfd_vma
) -1;
9741 /* Allocate stubs for exported Thumb functions on v4t. */
9742 if (!htab
->use_blx
&& h
->dynindx
!= -1
9744 && ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
9745 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9747 struct elf_link_hash_entry
* th
;
9748 struct bfd_link_hash_entry
* bh
;
9749 struct elf_link_hash_entry
* myh
;
9753 /* Create a new symbol to regist the real location of the function. */
9754 s
= h
->root
.u
.def
.section
;
9755 sprintf (name
, "__real_%s", h
->root
.root
.string
);
9756 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
9757 name
, BSF_GLOBAL
, s
,
9758 h
->root
.u
.def
.value
,
9759 NULL
, TRUE
, FALSE
, &bh
);
9761 myh
= (struct elf_link_hash_entry
*) bh
;
9762 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
9763 myh
->forced_local
= 1;
9764 eh
->export_glue
= myh
;
9765 th
= record_arm_to_thumb_glue (info
, h
);
9766 /* Point the symbol at the stub. */
9767 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
9768 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
9769 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
9772 if (eh
->relocs_copied
== NULL
)
9775 /* In the shared -Bsymbolic case, discard space allocated for
9776 dynamic pc-relative relocs against symbols which turn out to be
9777 defined in regular objects. For the normal shared case, discard
9778 space for pc-relative relocs that have become local due to symbol
9779 visibility changes. */
9781 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
9783 /* The only relocs that use pc_count are R_ARM_REL32 and
9784 R_ARM_REL32_NOI, which will appear on something like
9785 ".long foo - .". We want calls to protected symbols to resolve
9786 directly to the function rather than going via the plt. If people
9787 want function pointer comparisons to work as expected then they
9788 should avoid writing assembly like ".long foo - .". */
9789 if (SYMBOL_CALLS_LOCAL (info
, h
))
9791 struct elf32_arm_relocs_copied
**pp
;
9793 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
9795 p
->count
-= p
->pc_count
;
9804 if (elf32_arm_hash_table (info
)->vxworks_p
)
9806 struct elf32_arm_relocs_copied
**pp
;
9808 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
9810 if (strcmp (p
->section
->output_section
->name
, ".tls_vars") == 0)
9817 /* Also discard relocs on undefined weak syms with non-default
9819 if (eh
->relocs_copied
!= NULL
9820 && h
->root
.type
== bfd_link_hash_undefweak
)
9822 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9823 eh
->relocs_copied
= NULL
;
9825 /* Make sure undefined weak symbols are output as a dynamic
9827 else if (h
->dynindx
== -1
9828 && !h
->forced_local
)
9830 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9835 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
9836 && h
->root
.type
== bfd_link_hash_new
)
9838 /* Output absolute symbols so that we can create relocations
9839 against them. For normal symbols we output a relocation
9840 against the section that contains them. */
9841 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9848 /* For the non-shared case, discard space for relocs against
9849 symbols which turn out to need copy relocs or are not
9855 || (htab
->root
.dynamic_sections_created
9856 && (h
->root
.type
== bfd_link_hash_undefweak
9857 || h
->root
.type
== bfd_link_hash_undefined
))))
9859 /* Make sure this symbol is output as a dynamic symbol.
9860 Undefined weak syms won't yet be marked as dynamic. */
9861 if (h
->dynindx
== -1
9862 && !h
->forced_local
)
9864 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9868 /* If that succeeded, we know we'll be keeping all the
9870 if (h
->dynindx
!= -1)
9874 eh
->relocs_copied
= NULL
;
9879 /* Finally, allocate space. */
9880 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
9882 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
9883 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
9889 /* Find any dynamic relocs that apply to read-only sections. */
9892 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
* h
, void * inf
)
9894 struct elf32_arm_link_hash_entry
* eh
;
9895 struct elf32_arm_relocs_copied
* p
;
9897 if (h
->root
.type
== bfd_link_hash_warning
)
9898 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9900 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9901 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
9903 asection
*s
= p
->section
;
9905 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
9907 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9909 info
->flags
|= DF_TEXTREL
;
9911 /* Not an error, just cut short the traversal. */
9919 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info
*info
,
9922 struct elf32_arm_link_hash_table
*globals
;
9924 globals
= elf32_arm_hash_table (info
);
9925 globals
->byteswap_code
= byteswap_code
;
9928 /* Set the sizes of the dynamic sections. */
9931 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
9932 struct bfd_link_info
* info
)
9939 struct elf32_arm_link_hash_table
*htab
;
9941 htab
= elf32_arm_hash_table (info
);
9942 dynobj
= elf_hash_table (info
)->dynobj
;
9943 BFD_ASSERT (dynobj
!= NULL
);
9944 check_use_blx (htab
);
9946 if (elf_hash_table (info
)->dynamic_sections_created
)
9948 /* Set the contents of the .interp section to the interpreter. */
9949 if (info
->executable
)
9951 s
= bfd_get_section_by_name (dynobj
, ".interp");
9952 BFD_ASSERT (s
!= NULL
);
9953 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9954 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9958 /* Set up .got offsets for local syms, and space for local dynamic
9960 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
9962 bfd_signed_vma
*local_got
;
9963 bfd_signed_vma
*end_local_got
;
9964 char *local_tls_type
;
9965 bfd_size_type locsymcount
;
9966 Elf_Internal_Shdr
*symtab_hdr
;
9968 bfd_boolean is_vxworks
= elf32_arm_hash_table (info
)->vxworks_p
;
9970 if (! is_arm_elf (ibfd
))
9973 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9975 struct elf32_arm_relocs_copied
*p
;
9977 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9979 if (!bfd_is_abs_section (p
->section
)
9980 && bfd_is_abs_section (p
->section
->output_section
))
9982 /* Input section has been discarded, either because
9983 it is a copy of a linkonce section or due to
9984 linker script /DISCARD/, so we'll be discarding
9988 && strcmp (p
->section
->output_section
->name
,
9991 /* Relocations in vxworks .tls_vars sections are
9992 handled specially by the loader. */
9994 else if (p
->count
!= 0)
9996 srel
= elf_section_data (p
->section
)->sreloc
;
9997 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
9998 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
9999 info
->flags
|= DF_TEXTREL
;
10004 local_got
= elf_local_got_refcounts (ibfd
);
10008 symtab_hdr
= & elf_symtab_hdr (ibfd
);
10009 locsymcount
= symtab_hdr
->sh_info
;
10010 end_local_got
= local_got
+ locsymcount
;
10011 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
10013 srel
= htab
->srelgot
;
10014 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
10016 if (*local_got
> 0)
10018 *local_got
= s
->size
;
10019 if (*local_tls_type
& GOT_TLS_GD
)
10020 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10022 if (*local_tls_type
& GOT_TLS_IE
)
10024 if (*local_tls_type
== GOT_NORMAL
)
10027 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
10028 srel
->size
+= RELOC_SIZE (htab
);
10031 *local_got
= (bfd_vma
) -1;
10035 if (htab
->tls_ldm_got
.refcount
> 0)
10037 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10038 for R_ARM_TLS_LDM32 relocations. */
10039 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
10040 htab
->sgot
->size
+= 8;
10042 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
10045 htab
->tls_ldm_got
.offset
= -1;
10047 /* Allocate global sym .plt and .got entries, and space for global
10048 sym dynamic relocs. */
10049 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
10051 /* Here we rummage through the found bfds to collect glue information. */
10052 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
10054 if (! is_arm_elf (ibfd
))
10057 /* Initialise mapping tables for code/data. */
10058 bfd_elf32_arm_init_maps (ibfd
);
10060 if (!bfd_elf32_arm_process_before_allocation (ibfd
, info
)
10061 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd
, info
))
10062 /* xgettext:c-format */
10063 _bfd_error_handler (_("Errors encountered processing file %s"),
10067 /* The check_relocs and adjust_dynamic_symbol entry points have
10068 determined the sizes of the various dynamic sections. Allocate
10069 memory for them. */
10072 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10076 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10079 /* It's OK to base decisions on the section name, because none
10080 of the dynobj section names depend upon the input files. */
10081 name
= bfd_get_section_name (dynobj
, s
);
10083 if (strcmp (name
, ".plt") == 0)
10085 /* Remember whether there is a PLT. */
10086 plt
= s
->size
!= 0;
10088 else if (CONST_STRNEQ (name
, ".rel"))
10092 /* Remember whether there are any reloc sections other
10093 than .rel(a).plt and .rela.plt.unloaded. */
10094 if (s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
10097 /* We use the reloc_count field as a counter if we need
10098 to copy relocs into the output file. */
10099 s
->reloc_count
= 0;
10102 else if (! CONST_STRNEQ (name
, ".got")
10103 && strcmp (name
, ".dynbss") != 0)
10105 /* It's not one of our sections, so don't allocate space. */
10111 /* If we don't need this section, strip it from the
10112 output file. This is mostly to handle .rel(a).bss and
10113 .rel(a).plt. We must create both sections in
10114 create_dynamic_sections, because they must be created
10115 before the linker maps input sections to output
10116 sections. The linker does that before
10117 adjust_dynamic_symbol is called, and it is that
10118 function which decides whether anything needs to go
10119 into these sections. */
10120 s
->flags
|= SEC_EXCLUDE
;
10124 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10127 /* Allocate memory for the section contents. */
10128 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10129 if (s
->contents
== NULL
)
10133 if (elf_hash_table (info
)->dynamic_sections_created
)
10135 /* Add some entries to the .dynamic section. We fill in the
10136 values later, in elf32_arm_finish_dynamic_sections, but we
10137 must add the entries now so that we get the correct size for
10138 the .dynamic section. The DT_DEBUG entry is filled in by the
10139 dynamic linker and used by the debugger. */
10140 #define add_dynamic_entry(TAG, VAL) \
10141 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10143 if (info
->executable
)
10145 if (!add_dynamic_entry (DT_DEBUG
, 0))
10151 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
10152 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10153 || !add_dynamic_entry (DT_PLTREL
,
10154 htab
->use_rel
? DT_REL
: DT_RELA
)
10155 || !add_dynamic_entry (DT_JMPREL
, 0))
10163 if (!add_dynamic_entry (DT_REL
, 0)
10164 || !add_dynamic_entry (DT_RELSZ
, 0)
10165 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
10170 if (!add_dynamic_entry (DT_RELA
, 0)
10171 || !add_dynamic_entry (DT_RELASZ
, 0)
10172 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
10177 /* If any dynamic relocs apply to a read-only section,
10178 then we need a DT_TEXTREL entry. */
10179 if ((info
->flags
& DF_TEXTREL
) == 0)
10180 elf_link_hash_traverse (& htab
->root
, elf32_arm_readonly_dynrelocs
,
10183 if ((info
->flags
& DF_TEXTREL
) != 0)
10185 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10188 if (htab
->vxworks_p
10189 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
10192 #undef add_dynamic_entry
10197 /* Finish up dynamic symbol handling. We set the contents of various
10198 dynamic sections here. */
10201 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
,
10202 struct bfd_link_info
* info
,
10203 struct elf_link_hash_entry
* h
,
10204 Elf_Internal_Sym
* sym
)
10207 struct elf32_arm_link_hash_table
*htab
;
10208 struct elf32_arm_link_hash_entry
*eh
;
10210 dynobj
= elf_hash_table (info
)->dynobj
;
10211 htab
= elf32_arm_hash_table (info
);
10212 eh
= (struct elf32_arm_link_hash_entry
*) h
;
10214 if (h
->plt
.offset
!= (bfd_vma
) -1)
10220 Elf_Internal_Rela rel
;
10222 /* This symbol has an entry in the procedure linkage table. Set
10225 BFD_ASSERT (h
->dynindx
!= -1);
10227 splt
= bfd_get_section_by_name (dynobj
, ".plt");
10228 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".plt"));
10229 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
10231 /* Fill in the entry in the procedure linkage table. */
10232 if (htab
->symbian_p
)
10234 put_arm_insn (htab
, output_bfd
,
10235 elf32_arm_symbian_plt_entry
[0],
10236 splt
->contents
+ h
->plt
.offset
);
10237 bfd_put_32 (output_bfd
,
10238 elf32_arm_symbian_plt_entry
[1],
10239 splt
->contents
+ h
->plt
.offset
+ 4);
10241 /* Fill in the entry in the .rel.plt section. */
10242 rel
.r_offset
= (splt
->output_section
->vma
10243 + splt
->output_offset
10244 + h
->plt
.offset
+ 4);
10245 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
10247 /* Get the index in the procedure linkage table which
10248 corresponds to this symbol. This is the index of this symbol
10249 in all the symbols for which we are making plt entries. The
10250 first entry in the procedure linkage table is reserved. */
10251 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
10252 / htab
->plt_entry_size
);
10256 bfd_vma got_offset
, got_address
, plt_address
;
10257 bfd_vma got_displacement
;
10261 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
10262 BFD_ASSERT (sgot
!= NULL
);
10264 /* Get the offset into the .got.plt table of the entry that
10265 corresponds to this function. */
10266 got_offset
= eh
->plt_got_offset
;
10268 /* Get the index in the procedure linkage table which
10269 corresponds to this symbol. This is the index of this symbol
10270 in all the symbols for which we are making plt entries. The
10271 first three entries in .got.plt are reserved; after that
10272 symbols appear in the same order as in .plt. */
10273 plt_index
= (got_offset
- 12) / 4;
10275 /* Calculate the address of the GOT entry. */
10276 got_address
= (sgot
->output_section
->vma
10277 + sgot
->output_offset
10280 /* ...and the address of the PLT entry. */
10281 plt_address
= (splt
->output_section
->vma
10282 + splt
->output_offset
10285 ptr
= htab
->splt
->contents
+ h
->plt
.offset
;
10286 if (htab
->vxworks_p
&& info
->shared
)
10291 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
10293 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
10295 val
|= got_address
- sgot
->output_section
->vma
;
10297 val
|= plt_index
* RELOC_SIZE (htab
);
10298 if (i
== 2 || i
== 5)
10299 bfd_put_32 (output_bfd
, val
, ptr
);
10301 put_arm_insn (htab
, output_bfd
, val
, ptr
);
10304 else if (htab
->vxworks_p
)
10309 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
10311 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
10313 val
|= got_address
;
10315 val
|= 0xffffff & -((h
->plt
.offset
+ i
* 4 + 8) >> 2);
10317 val
|= plt_index
* RELOC_SIZE (htab
);
10318 if (i
== 2 || i
== 5)
10319 bfd_put_32 (output_bfd
, val
, ptr
);
10321 put_arm_insn (htab
, output_bfd
, val
, ptr
);
10324 loc
= (htab
->srelplt2
->contents
10325 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
10327 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
10328 referencing the GOT for this PLT entry. */
10329 rel
.r_offset
= plt_address
+ 8;
10330 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
10331 rel
.r_addend
= got_offset
;
10332 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
10333 loc
+= RELOC_SIZE (htab
);
10335 /* Create the R_ARM_ABS32 relocation referencing the
10336 beginning of the PLT for this GOT entry. */
10337 rel
.r_offset
= got_address
;
10338 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
10340 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
10344 bfd_signed_vma thumb_refs
;
10345 /* Calculate the displacement between the PLT slot and the
10346 entry in the GOT. The eight-byte offset accounts for the
10347 value produced by adding to pc in the first instruction
10348 of the PLT stub. */
10349 got_displacement
= got_address
- (plt_address
+ 8);
10351 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
10353 thumb_refs
= eh
->plt_thumb_refcount
;
10354 if (!htab
->use_blx
)
10355 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
10357 if (thumb_refs
> 0)
10359 put_thumb_insn (htab
, output_bfd
,
10360 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
10361 put_thumb_insn (htab
, output_bfd
,
10362 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
10365 put_arm_insn (htab
, output_bfd
,
10366 elf32_arm_plt_entry
[0]
10367 | ((got_displacement
& 0x0ff00000) >> 20),
10369 put_arm_insn (htab
, output_bfd
,
10370 elf32_arm_plt_entry
[1]
10371 | ((got_displacement
& 0x000ff000) >> 12),
10373 put_arm_insn (htab
, output_bfd
,
10374 elf32_arm_plt_entry
[2]
10375 | (got_displacement
& 0x00000fff),
10377 #ifdef FOUR_WORD_PLT
10378 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
10382 /* Fill in the entry in the global offset table. */
10383 bfd_put_32 (output_bfd
,
10384 (splt
->output_section
->vma
10385 + splt
->output_offset
),
10386 sgot
->contents
+ got_offset
);
10388 /* Fill in the entry in the .rel(a).plt section. */
10390 rel
.r_offset
= got_address
;
10391 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
10394 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
10395 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
10397 if (!h
->def_regular
)
10399 /* Mark the symbol as undefined, rather than as defined in
10400 the .plt section. Leave the value alone. */
10401 sym
->st_shndx
= SHN_UNDEF
;
10402 /* If the symbol is weak, we do need to clear the value.
10403 Otherwise, the PLT entry would provide a definition for
10404 the symbol even if the symbol wasn't defined anywhere,
10405 and so the symbol would never be NULL. */
10406 if (!h
->ref_regular_nonweak
)
10411 if (h
->got
.offset
!= (bfd_vma
) -1
10412 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
10413 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
10417 Elf_Internal_Rela rel
;
10421 /* This symbol has an entry in the global offset table. Set it
10423 sgot
= bfd_get_section_by_name (dynobj
, ".got");
10424 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".got"));
10425 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
10427 offset
= (h
->got
.offset
& ~(bfd_vma
) 1);
10429 rel
.r_offset
= (sgot
->output_section
->vma
10430 + sgot
->output_offset
10433 /* If this is a static link, or it is a -Bsymbolic link and the
10434 symbol is defined locally or was forced to be local because
10435 of a version file, we just want to emit a RELATIVE reloc.
10436 The entry in the global offset table will already have been
10437 initialized in the relocate_section function. */
10439 && SYMBOL_REFERENCES_LOCAL (info
, h
))
10441 BFD_ASSERT ((h
->got
.offset
& 1) != 0);
10442 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
10443 if (!htab
->use_rel
)
10445 rel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
10446 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
10451 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
10452 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
10453 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
10456 loc
= srel
->contents
+ srel
->reloc_count
++ * RELOC_SIZE (htab
);
10457 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
10463 Elf_Internal_Rela rel
;
10466 /* This symbol needs a copy reloc. Set it up. */
10467 BFD_ASSERT (h
->dynindx
!= -1
10468 && (h
->root
.type
== bfd_link_hash_defined
10469 || h
->root
.type
== bfd_link_hash_defweak
));
10471 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
10472 RELOC_SECTION (htab
, ".bss"));
10473 BFD_ASSERT (s
!= NULL
);
10476 rel
.r_offset
= (h
->root
.u
.def
.value
10477 + h
->root
.u
.def
.section
->output_section
->vma
10478 + h
->root
.u
.def
.section
->output_offset
);
10479 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
10480 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
10481 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
10484 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
10485 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
10486 to the ".got" section. */
10487 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
10488 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
10489 sym
->st_shndx
= SHN_ABS
;
10494 /* Finish up the dynamic sections. */
10497 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
10503 dynobj
= elf_hash_table (info
)->dynobj
;
10505 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
10506 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
10507 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
10509 if (elf_hash_table (info
)->dynamic_sections_created
)
10512 Elf32_External_Dyn
*dyncon
, *dynconend
;
10513 struct elf32_arm_link_hash_table
*htab
;
10515 htab
= elf32_arm_hash_table (info
);
10516 splt
= bfd_get_section_by_name (dynobj
, ".plt");
10517 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
10519 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
10520 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
10522 for (; dyncon
< dynconend
; dyncon
++)
10524 Elf_Internal_Dyn dyn
;
10528 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
10535 if (htab
->vxworks_p
10536 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
10537 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10542 goto get_vma_if_bpabi
;
10545 goto get_vma_if_bpabi
;
10548 goto get_vma_if_bpabi
;
10550 name
= ".gnu.version";
10551 goto get_vma_if_bpabi
;
10553 name
= ".gnu.version_d";
10554 goto get_vma_if_bpabi
;
10556 name
= ".gnu.version_r";
10557 goto get_vma_if_bpabi
;
10563 name
= RELOC_SECTION (htab
, ".plt");
10565 s
= bfd_get_section_by_name (output_bfd
, name
);
10566 BFD_ASSERT (s
!= NULL
);
10567 if (!htab
->symbian_p
)
10568 dyn
.d_un
.d_ptr
= s
->vma
;
10570 /* In the BPABI, tags in the PT_DYNAMIC section point
10571 at the file offset, not the memory address, for the
10572 convenience of the post linker. */
10573 dyn
.d_un
.d_ptr
= s
->filepos
;
10574 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10578 if (htab
->symbian_p
)
10583 s
= bfd_get_section_by_name (output_bfd
,
10584 RELOC_SECTION (htab
, ".plt"));
10585 BFD_ASSERT (s
!= NULL
);
10586 dyn
.d_un
.d_val
= s
->size
;
10587 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10592 if (!htab
->symbian_p
)
10594 /* My reading of the SVR4 ABI indicates that the
10595 procedure linkage table relocs (DT_JMPREL) should be
10596 included in the overall relocs (DT_REL). This is
10597 what Solaris does. However, UnixWare can not handle
10598 that case. Therefore, we override the DT_RELSZ entry
10599 here to make it not include the JMPREL relocs. Since
10600 the linker script arranges for .rel(a).plt to follow all
10601 other relocation sections, we don't have to worry
10602 about changing the DT_REL entry. */
10603 s
= bfd_get_section_by_name (output_bfd
,
10604 RELOC_SECTION (htab
, ".plt"));
10606 dyn
.d_un
.d_val
-= s
->size
;
10607 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10610 /* Fall through. */
10614 /* In the BPABI, the DT_REL tag must point at the file
10615 offset, not the VMA, of the first relocation
10616 section. So, we use code similar to that in
10617 elflink.c, but do not check for SHF_ALLOC on the
10618 relcoation section, since relocations sections are
10619 never allocated under the BPABI. The comments above
10620 about Unixware notwithstanding, we include all of the
10621 relocations here. */
10622 if (htab
->symbian_p
)
10625 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
10626 ? SHT_REL
: SHT_RELA
);
10627 dyn
.d_un
.d_val
= 0;
10628 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
10630 Elf_Internal_Shdr
*hdr
10631 = elf_elfsections (output_bfd
)[i
];
10632 if (hdr
->sh_type
== type
)
10634 if (dyn
.d_tag
== DT_RELSZ
10635 || dyn
.d_tag
== DT_RELASZ
)
10636 dyn
.d_un
.d_val
+= hdr
->sh_size
;
10637 else if ((ufile_ptr
) hdr
->sh_offset
10638 <= dyn
.d_un
.d_val
- 1)
10639 dyn
.d_un
.d_val
= hdr
->sh_offset
;
10642 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10646 /* Set the bottom bit of DT_INIT/FINI if the
10647 corresponding function is Thumb. */
10649 name
= info
->init_function
;
10652 name
= info
->fini_function
;
10654 /* If it wasn't set by elf_bfd_final_link
10655 then there is nothing to adjust. */
10656 if (dyn
.d_un
.d_val
!= 0)
10658 struct elf_link_hash_entry
* eh
;
10660 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
10661 FALSE
, FALSE
, TRUE
);
10663 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
10665 dyn
.d_un
.d_val
|= 1;
10666 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
10673 /* Fill in the first entry in the procedure linkage table. */
10674 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
10676 const bfd_vma
*plt0_entry
;
10677 bfd_vma got_address
, plt_address
, got_displacement
;
10679 /* Calculate the addresses of the GOT and PLT. */
10680 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
10681 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
10683 if (htab
->vxworks_p
)
10685 /* The VxWorks GOT is relocated by the dynamic linker.
10686 Therefore, we must emit relocations rather than simply
10687 computing the values now. */
10688 Elf_Internal_Rela rel
;
10690 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
10691 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
10692 splt
->contents
+ 0);
10693 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
10694 splt
->contents
+ 4);
10695 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
10696 splt
->contents
+ 8);
10697 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
10699 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
10700 rel
.r_offset
= plt_address
+ 12;
10701 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
10703 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
10704 htab
->srelplt2
->contents
);
10708 got_displacement
= got_address
- (plt_address
+ 16);
10710 plt0_entry
= elf32_arm_plt0_entry
;
10711 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
10712 splt
->contents
+ 0);
10713 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
10714 splt
->contents
+ 4);
10715 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
10716 splt
->contents
+ 8);
10717 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
10718 splt
->contents
+ 12);
10720 #ifdef FOUR_WORD_PLT
10721 /* The displacement value goes in the otherwise-unused
10722 last word of the second entry. */
10723 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
10725 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
10730 /* UnixWare sets the entsize of .plt to 4, although that doesn't
10731 really seem like the right value. */
10732 if (splt
->output_section
->owner
== output_bfd
)
10733 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
10735 if (htab
->vxworks_p
&& !info
->shared
&& htab
->splt
->size
> 0)
10737 /* Correct the .rel(a).plt.unloaded relocations. They will have
10738 incorrect symbol indexes. */
10742 num_plts
= ((htab
->splt
->size
- htab
->plt_header_size
)
10743 / htab
->plt_entry_size
);
10744 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
10746 for (; num_plts
; num_plts
--)
10748 Elf_Internal_Rela rel
;
10750 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
10751 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
10752 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
10753 p
+= RELOC_SIZE (htab
);
10755 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
10756 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
10757 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
10758 p
+= RELOC_SIZE (htab
);
10763 /* Fill in the first three entries in the global offset table. */
10766 if (sgot
->size
> 0)
10769 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
10771 bfd_put_32 (output_bfd
,
10772 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
10774 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
10775 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
10778 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
10785 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
10787 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
10788 struct elf32_arm_link_hash_table
*globals
;
10790 i_ehdrp
= elf_elfheader (abfd
);
10792 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
10793 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
10795 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
10796 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
10800 globals
= elf32_arm_hash_table (link_info
);
10801 if (globals
->byteswap_code
)
10802 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
10806 static enum elf_reloc_type_class
10807 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
10809 switch ((int) ELF32_R_TYPE (rela
->r_info
))
10811 case R_ARM_RELATIVE
:
10812 return reloc_class_relative
;
10813 case R_ARM_JUMP_SLOT
:
10814 return reloc_class_plt
;
10816 return reloc_class_copy
;
10818 return reloc_class_normal
;
10822 /* Set the right machine number for an Arm ELF file. */
10825 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
10827 if (hdr
->sh_type
== SHT_NOTE
)
10828 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
10834 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
10836 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
10839 /* Return TRUE if this is an unwinding table entry. */
10842 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
10844 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
10845 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
10849 /* Set the type and flags for an ARM section. We do this by
10850 the section name, which is a hack, but ought to work. */
10853 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
10857 name
= bfd_get_section_name (abfd
, sec
);
10859 if (is_arm_elf_unwind_section_name (abfd
, name
))
10861 hdr
->sh_type
= SHT_ARM_EXIDX
;
10862 hdr
->sh_flags
|= SHF_LINK_ORDER
;
10867 /* Handle an ARM specific section when reading an object file. This is
10868 called when bfd_section_from_shdr finds a section with an unknown
10872 elf32_arm_section_from_shdr (bfd
*abfd
,
10873 Elf_Internal_Shdr
* hdr
,
10877 /* There ought to be a place to keep ELF backend specific flags, but
10878 at the moment there isn't one. We just keep track of the
10879 sections by their name, instead. Fortunately, the ABI gives
10880 names for all the ARM specific sections, so we will probably get
10882 switch (hdr
->sh_type
)
10884 case SHT_ARM_EXIDX
:
10885 case SHT_ARM_PREEMPTMAP
:
10886 case SHT_ARM_ATTRIBUTES
:
10893 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
10899 /* A structure used to record a list of sections, independently
10900 of the next and prev fields in the asection structure. */
10901 typedef struct section_list
10904 struct section_list
* next
;
10905 struct section_list
* prev
;
10909 /* Unfortunately we need to keep a list of sections for which
10910 an _arm_elf_section_data structure has been allocated. This
10911 is because it is possible for functions like elf32_arm_write_section
10912 to be called on a section which has had an elf_data_structure
10913 allocated for it (and so the used_by_bfd field is valid) but
10914 for which the ARM extended version of this structure - the
10915 _arm_elf_section_data structure - has not been allocated. */
10916 static section_list
* sections_with_arm_elf_section_data
= NULL
;
10919 record_section_with_arm_elf_section_data (asection
* sec
)
10921 struct section_list
* entry
;
10923 entry
= bfd_malloc (sizeof (* entry
));
10927 entry
->next
= sections_with_arm_elf_section_data
;
10928 entry
->prev
= NULL
;
10929 if (entry
->next
!= NULL
)
10930 entry
->next
->prev
= entry
;
10931 sections_with_arm_elf_section_data
= entry
;
10934 static struct section_list
*
10935 find_arm_elf_section_entry (asection
* sec
)
10937 struct section_list
* entry
;
10938 static struct section_list
* last_entry
= NULL
;
10940 /* This is a short cut for the typical case where the sections are added
10941 to the sections_with_arm_elf_section_data list in forward order and
10942 then looked up here in backwards order. This makes a real difference
10943 to the ld-srec/sec64k.exp linker test. */
10944 entry
= sections_with_arm_elf_section_data
;
10945 if (last_entry
!= NULL
)
10947 if (last_entry
->sec
== sec
)
10948 entry
= last_entry
;
10949 else if (last_entry
->next
!= NULL
10950 && last_entry
->next
->sec
== sec
)
10951 entry
= last_entry
->next
;
10954 for (; entry
; entry
= entry
->next
)
10955 if (entry
->sec
== sec
)
10959 /* Record the entry prior to this one - it is the entry we are most
10960 likely to want to locate next time. Also this way if we have been
10961 called from unrecord_section_with_arm_elf_section_data() we will not
10962 be caching a pointer that is about to be freed. */
10963 last_entry
= entry
->prev
;
10968 static _arm_elf_section_data
*
10969 get_arm_elf_section_data (asection
* sec
)
10971 struct section_list
* entry
;
10973 entry
= find_arm_elf_section_entry (sec
);
10976 return elf32_arm_section_data (entry
->sec
);
10982 unrecord_section_with_arm_elf_section_data (asection
* sec
)
10984 struct section_list
* entry
;
10986 entry
= find_arm_elf_section_entry (sec
);
10990 if (entry
->prev
!= NULL
)
10991 entry
->prev
->next
= entry
->next
;
10992 if (entry
->next
!= NULL
)
10993 entry
->next
->prev
= entry
->prev
;
10994 if (entry
== sections_with_arm_elf_section_data
)
10995 sections_with_arm_elf_section_data
= entry
->next
;
11004 struct bfd_link_info
*info
;
11007 bfd_boolean (*func
) (void *, const char *, Elf_Internal_Sym
*,
11008 asection
*, struct elf_link_hash_entry
*);
11009 } output_arch_syminfo
;
11011 enum map_symbol_type
11019 /* Output a single mapping symbol. */
11022 elf32_arm_output_map_sym (output_arch_syminfo
*osi
,
11023 enum map_symbol_type type
,
11026 static const char *names
[3] = {"$a", "$t", "$d"};
11027 struct elf32_arm_link_hash_table
*htab
;
11028 Elf_Internal_Sym sym
;
11030 htab
= elf32_arm_hash_table (osi
->info
);
11031 sym
.st_value
= osi
->sec
->output_section
->vma
11032 + osi
->sec
->output_offset
11036 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
11037 sym
.st_shndx
= osi
->sec_shndx
;
11038 if (!osi
->func (osi
->finfo
, names
[type
], &sym
, osi
->sec
, NULL
))
11044 /* Output mapping symbols for PLT entries associated with H. */
11047 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
11049 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
11050 struct elf32_arm_link_hash_table
*htab
;
11051 struct elf32_arm_link_hash_entry
*eh
;
11054 htab
= elf32_arm_hash_table (osi
->info
);
11056 if (h
->root
.type
== bfd_link_hash_indirect
)
11059 if (h
->root
.type
== bfd_link_hash_warning
)
11060 /* When warning symbols are created, they **replace** the "real"
11061 entry in the hash table, thus we never get to see the real
11062 symbol in a hash traversal. So look at it now. */
11063 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11065 if (h
->plt
.offset
== (bfd_vma
) -1)
11068 eh
= (struct elf32_arm_link_hash_entry
*) h
;
11069 addr
= h
->plt
.offset
;
11070 if (htab
->symbian_p
)
11072 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11074 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
11077 else if (htab
->vxworks_p
)
11079 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11081 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
11083 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
11085 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
11090 bfd_signed_vma thumb_refs
;
11092 thumb_refs
= eh
->plt_thumb_refcount
;
11093 if (!htab
->use_blx
)
11094 thumb_refs
+= eh
->plt_maybe_thumb_refcount
;
11096 if (thumb_refs
> 0)
11098 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
11101 #ifdef FOUR_WORD_PLT
11102 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11104 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
11107 /* A three-word PLT with no Thumb thunk contains only Arm code,
11108 so only need to output a mapping symbol for the first PLT entry and
11109 entries with thumb thunks. */
11110 if (thumb_refs
> 0 || addr
== 20)
11112 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11121 /* Output a single local symbol for a generated stub. */
11124 elf32_arm_output_stub_sym (output_arch_syminfo
*osi
, const char *name
,
11125 bfd_vma offset
, bfd_vma size
)
11127 struct elf32_arm_link_hash_table
*htab
;
11128 Elf_Internal_Sym sym
;
11130 htab
= elf32_arm_hash_table (osi
->info
);
11131 sym
.st_value
= osi
->sec
->output_section
->vma
11132 + osi
->sec
->output_offset
11134 sym
.st_size
= size
;
11136 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
11137 sym
.st_shndx
= osi
->sec_shndx
;
11138 if (!osi
->func (osi
->finfo
, name
, &sym
, osi
->sec
, NULL
))
11144 arm_map_one_stub (struct bfd_hash_entry
* gen_entry
,
11147 struct elf32_arm_stub_hash_entry
*stub_entry
;
11148 struct bfd_link_info
*info
;
11149 struct elf32_arm_link_hash_table
*htab
;
11150 asection
*stub_sec
;
11153 output_arch_syminfo
*osi
;
11155 /* Massage our args to the form they really have. */
11156 stub_entry
= (struct elf32_arm_stub_hash_entry
*) gen_entry
;
11157 osi
= (output_arch_syminfo
*) in_arg
;
11161 htab
= elf32_arm_hash_table (info
);
11162 stub_sec
= stub_entry
->stub_sec
;
11164 /* Ensure this stub is attached to the current section being
11166 if (stub_sec
!= osi
->sec
)
11169 addr
= (bfd_vma
) stub_entry
->stub_offset
;
11170 stub_name
= stub_entry
->output_name
;
11172 switch (stub_entry
->stub_type
)
11174 case arm_stub_long_branch
:
11175 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, 8))
11177 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11179 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
11182 case arm_thumb_v4t_stub_long_branch
:
11183 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, 12))
11185 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11187 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
11190 case arm_thumb_thumb_stub_long_branch
:
11191 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1, 16))
11193 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
))
11195 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
11198 case arm_thumb_arm_v4t_stub_long_branch
:
11199 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
| 1, 20))
11201 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_THUMB
, addr
))
11203 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
+ 8))
11205 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 16))
11208 case arm_stub_pic_long_branch
:
11209 if (!elf32_arm_output_stub_sym (osi
, stub_name
, addr
, 12))
11211 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_ARM
, addr
))
11213 if (!elf32_arm_output_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
11223 /* Output mapping symbols for linker generated sections. */
11226 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
11227 struct bfd_link_info
*info
,
11229 bfd_boolean (*func
) (void *, const char *,
11230 Elf_Internal_Sym
*,
11232 struct elf_link_hash_entry
*))
11234 output_arch_syminfo osi
;
11235 struct elf32_arm_link_hash_table
*htab
;
11237 bfd_size_type size
;
11239 htab
= elf32_arm_hash_table (info
);
11240 check_use_blx (htab
);
11246 /* ARM->Thumb glue. */
11247 if (htab
->arm_glue_size
> 0)
11249 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
11250 ARM2THUMB_GLUE_SECTION_NAME
);
11252 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
11253 (output_bfd
, osi
.sec
->output_section
);
11254 if (info
->shared
|| htab
->root
.is_relocatable_executable
11255 || htab
->pic_veneer
)
11256 size
= ARM2THUMB_PIC_GLUE_SIZE
;
11257 else if (htab
->use_blx
)
11258 size
= ARM2THUMB_V5_STATIC_GLUE_SIZE
;
11260 size
= ARM2THUMB_STATIC_GLUE_SIZE
;
11262 for (offset
= 0; offset
< htab
->arm_glue_size
; offset
+= size
)
11264 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
);
11265 elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, offset
+ size
- 4);
11269 /* Thumb->ARM glue. */
11270 if (htab
->thumb_glue_size
> 0)
11272 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
11273 THUMB2ARM_GLUE_SECTION_NAME
);
11275 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
11276 (output_bfd
, osi
.sec
->output_section
);
11277 size
= THUMB2ARM_GLUE_SIZE
;
11279 for (offset
= 0; offset
< htab
->thumb_glue_size
; offset
+= size
)
11281 elf32_arm_output_map_sym (&osi
, ARM_MAP_THUMB
, offset
);
11282 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, offset
+ 4);
11286 /* ARMv4 BX veneers. */
11287 if (htab
->bx_glue_size
> 0)
11289 osi
.sec
= bfd_get_section_by_name (htab
->bfd_of_glue_owner
,
11290 ARM_BX_GLUE_SECTION_NAME
);
11292 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
11293 (output_bfd
, osi
.sec
->output_section
);
11295 elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0);
11298 /* Long calls stubs. */
11299 if (htab
->stub_bfd
&& htab
->stub_bfd
->sections
)
11301 asection
* stub_sec
;
11303 for (stub_sec
= htab
->stub_bfd
->sections
;
11305 stub_sec
= stub_sec
->next
)
11307 /* Ignore non-stub sections. */
11308 if (!strstr (stub_sec
->name
, STUB_SUFFIX
))
11311 osi
.sec
= stub_sec
;
11313 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section
11314 (output_bfd
, osi
.sec
->output_section
);
11316 bfd_hash_traverse (&htab
->stub_hash_table
, arm_map_one_stub
, &osi
);
11320 /* Finally, output mapping symbols for the PLT. */
11321 if (!htab
->splt
|| htab
->splt
->size
== 0)
11324 osi
.sec_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
11325 htab
->splt
->output_section
);
11326 osi
.sec
= htab
->splt
;
11327 /* Output mapping symbols for the plt header. SymbianOS does not have a
11329 if (htab
->vxworks_p
)
11331 /* VxWorks shared libraries have no PLT header. */
11334 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
11336 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 12))
11340 else if (!htab
->symbian_p
)
11342 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_ARM
, 0))
11344 #ifndef FOUR_WORD_PLT
11345 if (!elf32_arm_output_map_sym (&osi
, ARM_MAP_DATA
, 16))
11350 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, (void *) &osi
);
11354 /* Allocate target specific section data. */
11357 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
11359 if (!sec
->used_by_bfd
)
11361 _arm_elf_section_data
*sdata
;
11362 bfd_size_type amt
= sizeof (*sdata
);
11364 sdata
= bfd_zalloc (abfd
, amt
);
11367 sec
->used_by_bfd
= sdata
;
11370 record_section_with_arm_elf_section_data (sec
);
11372 return _bfd_elf_new_section_hook (abfd
, sec
);
11376 /* Used to order a list of mapping symbols by address. */
11379 elf32_arm_compare_mapping (const void * a
, const void * b
)
11381 const elf32_arm_section_map
*amap
= (const elf32_arm_section_map
*) a
;
11382 const elf32_arm_section_map
*bmap
= (const elf32_arm_section_map
*) b
;
11384 if (amap
->vma
> bmap
->vma
)
11386 else if (amap
->vma
< bmap
->vma
)
11388 else if (amap
->type
> bmap
->type
)
11389 /* Ensure results do not depend on the host qsort for objects with
11390 multiple mapping symbols at the same address by sorting on type
11393 else if (amap
->type
< bmap
->type
)
11400 /* Do code byteswapping. Return FALSE afterwards so that the section is
11401 written out as normal. */
11404 elf32_arm_write_section (bfd
*output_bfd
,
11405 struct bfd_link_info
*link_info
,
11407 bfd_byte
*contents
)
11409 int mapcount
, errcount
;
11410 _arm_elf_section_data
*arm_data
;
11411 struct elf32_arm_link_hash_table
*globals
= elf32_arm_hash_table (link_info
);
11412 elf32_arm_section_map
*map
;
11413 elf32_vfp11_erratum_list
*errnode
;
11416 bfd_vma offset
= sec
->output_section
->vma
+ sec
->output_offset
;
11420 /* If this section has not been allocated an _arm_elf_section_data
11421 structure then we cannot record anything. */
11422 arm_data
= get_arm_elf_section_data (sec
);
11423 if (arm_data
== NULL
)
11426 mapcount
= arm_data
->mapcount
;
11427 map
= arm_data
->map
;
11428 errcount
= arm_data
->erratumcount
;
11432 unsigned int endianflip
= bfd_big_endian (output_bfd
) ? 3 : 0;
11434 for (errnode
= arm_data
->erratumlist
; errnode
!= 0;
11435 errnode
= errnode
->next
)
11437 bfd_vma index
= errnode
->vma
- offset
;
11439 switch (errnode
->type
)
11441 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER
:
11443 bfd_vma branch_to_veneer
;
11444 /* Original condition code of instruction, plus bit mask for
11445 ARM B instruction. */
11446 unsigned int insn
= (errnode
->u
.b
.vfp_insn
& 0xf0000000)
11449 /* The instruction is before the label. */
11452 /* Above offset included in -4 below. */
11453 branch_to_veneer
= errnode
->u
.b
.veneer
->vma
11454 - errnode
->vma
- 4;
11456 if ((signed) branch_to_veneer
< -(1 << 25)
11457 || (signed) branch_to_veneer
>= (1 << 25))
11458 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
11459 "range"), output_bfd
);
11461 insn
|= (branch_to_veneer
>> 2) & 0xffffff;
11462 contents
[endianflip
^ index
] = insn
& 0xff;
11463 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
11464 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
11465 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
11469 case VFP11_ERRATUM_ARM_VENEER
:
11471 bfd_vma branch_from_veneer
;
11474 /* Take size of veneer into account. */
11475 branch_from_veneer
= errnode
->u
.v
.branch
->vma
11476 - errnode
->vma
- 12;
11478 if ((signed) branch_from_veneer
< -(1 << 25)
11479 || (signed) branch_from_veneer
>= (1 << 25))
11480 (*_bfd_error_handler
) (_("%B: error: VFP11 veneer out of "
11481 "range"), output_bfd
);
11483 /* Original instruction. */
11484 insn
= errnode
->u
.v
.branch
->u
.b
.vfp_insn
;
11485 contents
[endianflip
^ index
] = insn
& 0xff;
11486 contents
[endianflip
^ (index
+ 1)] = (insn
>> 8) & 0xff;
11487 contents
[endianflip
^ (index
+ 2)] = (insn
>> 16) & 0xff;
11488 contents
[endianflip
^ (index
+ 3)] = (insn
>> 24) & 0xff;
11490 /* Branch back to insn after original insn. */
11491 insn
= 0xea000000 | ((branch_from_veneer
>> 2) & 0xffffff);
11492 contents
[endianflip
^ (index
+ 4)] = insn
& 0xff;
11493 contents
[endianflip
^ (index
+ 5)] = (insn
>> 8) & 0xff;
11494 contents
[endianflip
^ (index
+ 6)] = (insn
>> 16) & 0xff;
11495 contents
[endianflip
^ (index
+ 7)] = (insn
>> 24) & 0xff;
11508 if (globals
->byteswap_code
)
11510 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
11513 for (i
= 0; i
< mapcount
; i
++)
11515 if (i
== mapcount
- 1)
11518 end
= map
[i
+ 1].vma
;
11520 switch (map
[i
].type
)
11523 /* Byte swap code words. */
11524 while (ptr
+ 3 < end
)
11526 tmp
= contents
[ptr
];
11527 contents
[ptr
] = contents
[ptr
+ 3];
11528 contents
[ptr
+ 3] = tmp
;
11529 tmp
= contents
[ptr
+ 1];
11530 contents
[ptr
+ 1] = contents
[ptr
+ 2];
11531 contents
[ptr
+ 2] = tmp
;
11537 /* Byte swap code halfwords. */
11538 while (ptr
+ 1 < end
)
11540 tmp
= contents
[ptr
];
11541 contents
[ptr
] = contents
[ptr
+ 1];
11542 contents
[ptr
+ 1] = tmp
;
11548 /* Leave data alone. */
11556 arm_data
->mapcount
= 0;
11557 arm_data
->mapsize
= 0;
11558 arm_data
->map
= NULL
;
11559 unrecord_section_with_arm_elf_section_data (sec
);
11565 unrecord_section_via_map_over_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
11567 void * ignore ATTRIBUTE_UNUSED
)
11569 unrecord_section_with_arm_elf_section_data (sec
);
11573 elf32_arm_close_and_cleanup (bfd
* abfd
)
11575 if (abfd
->sections
)
11576 bfd_map_over_sections (abfd
,
11577 unrecord_section_via_map_over_sections
,
11580 return _bfd_elf_close_and_cleanup (abfd
);
11584 elf32_arm_bfd_free_cached_info (bfd
* abfd
)
11586 if (abfd
->sections
)
11587 bfd_map_over_sections (abfd
,
11588 unrecord_section_via_map_over_sections
,
11591 return _bfd_free_cached_info (abfd
);
11594 /* Display STT_ARM_TFUNC symbols as functions. */
11597 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
11600 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
11602 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
11603 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
11607 /* Mangle thumb function symbols as we read them in. */
11610 elf32_arm_swap_symbol_in (bfd
* abfd
,
11613 Elf_Internal_Sym
*dst
)
11615 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
11618 /* New EABI objects mark thumb function symbols by setting the low bit of
11619 the address. Turn these into STT_ARM_TFUNC. */
11620 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
11621 && (dst
->st_value
& 1))
11623 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
11624 dst
->st_value
&= ~(bfd_vma
) 1;
11630 /* Mangle thumb function symbols as we write them out. */
11633 elf32_arm_swap_symbol_out (bfd
*abfd
,
11634 const Elf_Internal_Sym
*src
,
11638 Elf_Internal_Sym newsym
;
11640 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
11641 of the address set, as per the new EABI. We do this unconditionally
11642 because objcopy does not set the elf header flags until after
11643 it writes out the symbol table. */
11644 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
11647 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
11648 if (newsym
.st_shndx
!= SHN_UNDEF
)
11650 /* Do this only for defined symbols. At link type, the static
11651 linker will simulate the work of dynamic linker of resolving
11652 symbols and will carry over the thumbness of found symbols to
11653 the output symbol table. It's not clear how it happens, but
11654 the thumbness of undefined symbols can well be different at
11655 runtime, and writing '1' for them will be confusing for users
11656 and possibly for dynamic linker itself.
11658 newsym
.st_value
|= 1;
11663 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
11666 /* Add the PT_ARM_EXIDX program header. */
11669 elf32_arm_modify_segment_map (bfd
*abfd
,
11670 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
11672 struct elf_segment_map
*m
;
11675 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
11676 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
11678 /* If there is already a PT_ARM_EXIDX header, then we do not
11679 want to add another one. This situation arises when running
11680 "strip"; the input binary already has the header. */
11681 m
= elf_tdata (abfd
)->segment_map
;
11682 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
11686 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
11689 m
->p_type
= PT_ARM_EXIDX
;
11691 m
->sections
[0] = sec
;
11693 m
->next
= elf_tdata (abfd
)->segment_map
;
11694 elf_tdata (abfd
)->segment_map
= m
;
11701 /* We may add a PT_ARM_EXIDX program header. */
11704 elf32_arm_additional_program_headers (bfd
*abfd
,
11705 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
11709 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
11710 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
11716 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
11719 elf32_arm_is_function_type (unsigned int type
)
11721 return (type
== STT_FUNC
) || (type
== STT_ARM_TFUNC
);
11724 /* We use this to override swap_symbol_in and swap_symbol_out. */
11725 const struct elf_size_info elf32_arm_size_info
=
11727 sizeof (Elf32_External_Ehdr
),
11728 sizeof (Elf32_External_Phdr
),
11729 sizeof (Elf32_External_Shdr
),
11730 sizeof (Elf32_External_Rel
),
11731 sizeof (Elf32_External_Rela
),
11732 sizeof (Elf32_External_Sym
),
11733 sizeof (Elf32_External_Dyn
),
11734 sizeof (Elf_External_Note
),
11738 ELFCLASS32
, EV_CURRENT
,
11739 bfd_elf32_write_out_phdrs
,
11740 bfd_elf32_write_shdrs_and_ehdr
,
11741 bfd_elf32_checksum_contents
,
11742 bfd_elf32_write_relocs
,
11743 elf32_arm_swap_symbol_in
,
11744 elf32_arm_swap_symbol_out
,
11745 bfd_elf32_slurp_reloc_table
,
11746 bfd_elf32_slurp_symbol_table
,
11747 bfd_elf32_swap_dyn_in
,
11748 bfd_elf32_swap_dyn_out
,
11749 bfd_elf32_swap_reloc_in
,
11750 bfd_elf32_swap_reloc_out
,
11751 bfd_elf32_swap_reloca_in
,
11752 bfd_elf32_swap_reloca_out
11755 #define ELF_ARCH bfd_arch_arm
11756 #define ELF_MACHINE_CODE EM_ARM
11757 #ifdef __QNXTARGET__
11758 #define ELF_MAXPAGESIZE 0x1000
11760 #define ELF_MAXPAGESIZE 0x8000
11762 #define ELF_MINPAGESIZE 0x1000
11763 #define ELF_COMMONPAGESIZE 0x1000
11765 #define bfd_elf32_mkobject elf32_arm_mkobject
11767 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
11768 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
11769 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
11770 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
11771 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
11772 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
11773 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
11774 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
11775 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
11776 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
11777 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
11778 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
11779 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
11780 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
11782 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
11783 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
11784 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
11785 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
11786 #define elf_backend_check_relocs elf32_arm_check_relocs
11787 #define elf_backend_relocate_section elf32_arm_relocate_section
11788 #define elf_backend_write_section elf32_arm_write_section
11789 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
11790 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
11791 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
11792 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
11793 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
11794 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
11795 #define elf_backend_post_process_headers elf32_arm_post_process_headers
11796 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
11797 #define elf_backend_object_p elf32_arm_object_p
11798 #define elf_backend_section_flags elf32_arm_section_flags
11799 #define elf_backend_fake_sections elf32_arm_fake_sections
11800 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
11801 #define elf_backend_final_write_processing elf32_arm_final_write_processing
11802 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
11803 #define elf_backend_symbol_processing elf32_arm_symbol_processing
11804 #define elf_backend_size_info elf32_arm_size_info
11805 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
11806 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
11807 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
11808 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
11809 #define elf_backend_is_function_type elf32_arm_is_function_type
11811 #define elf_backend_can_refcount 1
11812 #define elf_backend_can_gc_sections 1
11813 #define elf_backend_plt_readonly 1
11814 #define elf_backend_want_got_plt 1
11815 #define elf_backend_want_plt_sym 0
11816 #define elf_backend_may_use_rel_p 1
11817 #define elf_backend_may_use_rela_p 0
11818 #define elf_backend_default_use_rela_p 0
11820 #define elf_backend_got_header_size 12
11822 #undef elf_backend_obj_attrs_vendor
11823 #define elf_backend_obj_attrs_vendor "aeabi"
11824 #undef elf_backend_obj_attrs_section
11825 #define elf_backend_obj_attrs_section ".ARM.attributes"
11826 #undef elf_backend_obj_attrs_arg_type
11827 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
11828 #undef elf_backend_obj_attrs_section_type
11829 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
11831 #include "elf32-target.h"
11833 /* VxWorks Targets. */
11835 #undef TARGET_LITTLE_SYM
11836 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
11837 #undef TARGET_LITTLE_NAME
11838 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
11839 #undef TARGET_BIG_SYM
11840 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
11841 #undef TARGET_BIG_NAME
11842 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
11844 /* Like elf32_arm_link_hash_table_create -- but overrides
11845 appropriately for VxWorks. */
11847 static struct bfd_link_hash_table
*
11848 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
11850 struct bfd_link_hash_table
*ret
;
11852 ret
= elf32_arm_link_hash_table_create (abfd
);
11855 struct elf32_arm_link_hash_table
*htab
11856 = (struct elf32_arm_link_hash_table
*) ret
;
11858 htab
->vxworks_p
= 1;
11864 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
11866 elf32_arm_final_write_processing (abfd
, linker
);
11867 elf_vxworks_final_write_processing (abfd
, linker
);
11871 #define elf32_bed elf32_arm_vxworks_bed
11873 #undef bfd_elf32_bfd_link_hash_table_create
11874 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
11875 #undef elf_backend_add_symbol_hook
11876 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
11877 #undef elf_backend_final_write_processing
11878 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
11879 #undef elf_backend_emit_relocs
11880 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
11882 #undef elf_backend_may_use_rel_p
11883 #define elf_backend_may_use_rel_p 0
11884 #undef elf_backend_may_use_rela_p
11885 #define elf_backend_may_use_rela_p 1
11886 #undef elf_backend_default_use_rela_p
11887 #define elf_backend_default_use_rela_p 1
11888 #undef elf_backend_want_plt_sym
11889 #define elf_backend_want_plt_sym 1
11890 #undef ELF_MAXPAGESIZE
11891 #define ELF_MAXPAGESIZE 0x1000
11893 #include "elf32-target.h"
11896 /* Symbian OS Targets. */
11898 #undef TARGET_LITTLE_SYM
11899 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
11900 #undef TARGET_LITTLE_NAME
11901 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
11902 #undef TARGET_BIG_SYM
11903 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
11904 #undef TARGET_BIG_NAME
11905 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
11907 /* Like elf32_arm_link_hash_table_create -- but overrides
11908 appropriately for Symbian OS. */
11910 static struct bfd_link_hash_table
*
11911 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
11913 struct bfd_link_hash_table
*ret
;
11915 ret
= elf32_arm_link_hash_table_create (abfd
);
11918 struct elf32_arm_link_hash_table
*htab
11919 = (struct elf32_arm_link_hash_table
*)ret
;
11920 /* There is no PLT header for Symbian OS. */
11921 htab
->plt_header_size
= 0;
11922 /* The PLT entries are each one instruction and one word. */
11923 htab
->plt_entry_size
= 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
);
11924 htab
->symbian_p
= 1;
11925 /* Symbian uses armv5t or above, so use_blx is always true. */
11927 htab
->root
.is_relocatable_executable
= 1;
11932 static const struct bfd_elf_special_section
11933 elf32_arm_symbian_special_sections
[] =
11935 /* In a BPABI executable, the dynamic linking sections do not go in
11936 the loadable read-only segment. The post-linker may wish to
11937 refer to these sections, but they are not part of the final
11939 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
11940 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
11941 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
11942 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
11943 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
11944 /* These sections do not need to be writable as the SymbianOS
11945 postlinker will arrange things so that no dynamic relocation is
11947 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
11948 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
11949 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
11950 { NULL
, 0, 0, 0, 0 }
11954 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
11955 struct bfd_link_info
*link_info
)
11957 /* BPABI objects are never loaded directly by an OS kernel; they are
11958 processed by a postlinker first, into an OS-specific format. If
11959 the D_PAGED bit is set on the file, BFD will align segments on
11960 page boundaries, so that an OS can directly map the file. With
11961 BPABI objects, that just results in wasted space. In addition,
11962 because we clear the D_PAGED bit, map_sections_to_segments will
11963 recognize that the program headers should not be mapped into any
11964 loadable segment. */
11965 abfd
->flags
&= ~D_PAGED
;
11966 elf32_arm_begin_write_processing (abfd
, link_info
);
11970 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
11971 struct bfd_link_info
*info
)
11973 struct elf_segment_map
*m
;
11976 /* BPABI shared libraries and executables should have a PT_DYNAMIC
11977 segment. However, because the .dynamic section is not marked
11978 with SEC_LOAD, the generic ELF code will not create such a
11980 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
11983 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
11984 if (m
->p_type
== PT_DYNAMIC
)
11989 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
11990 m
->next
= elf_tdata (abfd
)->segment_map
;
11991 elf_tdata (abfd
)->segment_map
= m
;
11995 /* Also call the generic arm routine. */
11996 return elf32_arm_modify_segment_map (abfd
, info
);
11999 /* Return address for Ith PLT stub in section PLT, for relocation REL
12000 or (bfd_vma) -1 if it should not be included. */
12003 elf32_arm_symbian_plt_sym_val (bfd_vma i
, const asection
*plt
,
12004 const arelent
*rel ATTRIBUTE_UNUSED
)
12006 return plt
->vma
+ 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry
) * i
;
12011 #define elf32_bed elf32_arm_symbian_bed
12013 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12014 will process them and then discard them. */
12015 #undef ELF_DYNAMIC_SEC_FLAGS
12016 #define ELF_DYNAMIC_SEC_FLAGS \
12017 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12019 #undef elf_backend_add_symbol_hook
12020 #undef elf_backend_emit_relocs
12022 #undef bfd_elf32_bfd_link_hash_table_create
12023 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12024 #undef elf_backend_special_sections
12025 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12026 #undef elf_backend_begin_write_processing
12027 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12028 #undef elf_backend_final_write_processing
12029 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12031 #undef elf_backend_modify_segment_map
12032 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12034 /* There is no .got section for BPABI objects, and hence no header. */
12035 #undef elf_backend_got_header_size
12036 #define elf_backend_got_header_size 0
12038 /* Similarly, there is no .got.plt section. */
12039 #undef elf_backend_want_got_plt
12040 #define elf_backend_want_got_plt 0
12042 #undef elf_backend_plt_sym_val
12043 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12045 #undef elf_backend_may_use_rel_p
12046 #define elf_backend_may_use_rel_p 1
12047 #undef elf_backend_may_use_rela_p
12048 #define elf_backend_may_use_rela_p 0
12049 #undef elf_backend_default_use_rela_p
12050 #define elf_backend_default_use_rela_p 0
12051 #undef elf_backend_want_plt_sym
12052 #define elf_backend_want_plt_sym 0
12053 #undef ELF_MAXPAGESIZE
12054 #define ELF_MAXPAGESIZE 0x8000
12056 #include "elf32-target.h"