1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 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 2 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, MA 02110-1301, USA. */
23 #include "libiberty.h"
26 #include "elf-vxworks.h"
30 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
62 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 0x0000ffff, /* src_mask */
696 0x0000ffff, /* 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 0x0000ffff, /* src_mask */
710 0x0000ffff, /* 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 0x0000ffff, /* src_mask */
724 0x0000ffff, /* 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 0x0000ffff, /* src_mask */
738 0x0000ffff, /* 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 < NUM_ELEM (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 + NUM_ELEM (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}
1775 static reloc_howto_type *
1776 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1777 bfd_reloc_code_real_type code)
1780 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1781 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1782 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1787 static reloc_howto_type *
1788 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1794 i < (sizeof (elf32_arm_howto_table_1)
1795 / sizeof (elf32_arm_howto_table_1[0]));
1797 if (elf32_arm_howto_table_1[i].name != NULL
1798 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1799 return &elf32_arm_howto_table_1[i];
1802 i < (sizeof (elf32_arm_howto_table_2)
1803 / sizeof (elf32_arm_howto_table_2[0]));
1805 if (elf32_arm_howto_table_2[i].name != NULL
1806 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1807 return &elf32_arm_howto_table_2[i];
1812 /* Support for core dump NOTE sections */
1814 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1819 switch (note->descsz)
1824 case 148: /* Linux/ARM 32-bit*/
1826 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1829 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1837 case 96: /* FreeBSD/ARM */
1839 if (elf_tdata(abfd)->core_signal == 0)
1840 elf_tdata (abfd)->core_signal = ((int *)(note->descdata))[5];
1843 elf_tdata (abfd)->core_pid = ((int *)(note->descdata))[6];
1851 /* Make a ".reg/999" section. */
1852 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1853 size, note->descpos + offset);
1857 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1859 switch (note->descsz)
1864 case 124: /* Linux/ARM elf_prpsinfo */
1865 elf_tdata (abfd)->core_program
1866 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1867 elf_tdata (abfd)->core_command
1868 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1871 /* Note that for some reason, a spurious space is tacked
1872 onto the end of the args in some (at least one anyway)
1873 implementations, so strip it off if it exists. */
1876 char *command = elf_tdata (abfd)->core_command;
1877 int n = strlen (command);
1879 if (0 < n && command[n - 1] == ' ')
1880 command[n - 1] = '\0';
1886 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1887 #define TARGET_LITTLE_NAME "elf32-littlearm"
1888 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1889 #define TARGET_BIG_NAME "elf32-bigarm"
1891 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1892 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1894 typedef unsigned long int insn32;
1895 typedef unsigned short int insn16;
1897 /* In lieu of proper flags, assume all EABIv4 or later objects are
1899 #define INTERWORK_FLAG(abfd) \
1900 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1901 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1903 /* The linker script knows the section names for placement.
1904 The entry_names are used to do simple name mangling on the stubs.
1905 Given a function name, and its type, the stub can be found. The
1906 name can be changed. The only requirement is the %s be present. */
1907 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1908 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1910 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1911 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1913 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1914 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1916 /* The name of the dynamic interpreter. This is put in the .interp
1918 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1920 #ifdef FOUR_WORD_PLT
1922 /* The first entry in a procedure linkage table looks like
1923 this. It is set up so that any shared library function that is
1924 called before the relocation has been set up calls the dynamic
1926 static const bfd_vma elf32_arm_plt0_entry [] =
1928 0xe52de004, /* str lr, [sp, #-4]! */
1929 0xe59fe010, /* ldr lr, [pc, #16] */
1930 0xe08fe00e, /* add lr, pc, lr */
1931 0xe5bef008, /* ldr pc, [lr, #8]! */
1934 /* Subsequent entries in a procedure linkage table look like
1936 static const bfd_vma elf32_arm_plt_entry [] =
1938 0xe28fc600, /* add ip, pc, #NN */
1939 0xe28cca00, /* add ip, ip, #NN */
1940 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1941 0x00000000, /* unused */
1946 /* The first entry in a procedure linkage table looks like
1947 this. It is set up so that any shared library function that is
1948 called before the relocation has been set up calls the dynamic
1950 static const bfd_vma elf32_arm_plt0_entry [] =
1952 0xe52de004, /* str lr, [sp, #-4]! */
1953 0xe59fe004, /* ldr lr, [pc, #4] */
1954 0xe08fe00e, /* add lr, pc, lr */
1955 0xe5bef008, /* ldr pc, [lr, #8]! */
1956 0x00000000, /* &GOT[0] - . */
1959 /* Subsequent entries in a procedure linkage table look like
1961 static const bfd_vma elf32_arm_plt_entry [] =
1963 0xe28fc600, /* add ip, pc, #0xNN00000 */
1964 0xe28cca00, /* add ip, ip, #0xNN000 */
1965 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1970 /* The format of the first entry in the procedure linkage table
1971 for a VxWorks executable. */
1972 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1974 0xe52dc008, /* str ip,[sp,#-8]! */
1975 0xe59fc000, /* ldr ip,[pc] */
1976 0xe59cf008, /* ldr pc,[ip,#8] */
1977 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1980 /* The format of subsequent entries in a VxWorks executable. */
1981 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1983 0xe59fc000, /* ldr ip,[pc] */
1984 0xe59cf000, /* ldr pc,[ip] */
1985 0x00000000, /* .long @got */
1986 0xe59fc000, /* ldr ip,[pc] */
1987 0xea000000, /* b _PLT */
1988 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1991 /* The format of entries in a VxWorks shared library. */
1992 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1994 0xe59fc000, /* ldr ip,[pc] */
1995 0xe79cf009, /* ldr pc,[ip,r9] */
1996 0x00000000, /* .long @got */
1997 0xe59fc000, /* ldr ip,[pc] */
1998 0xe599f008, /* ldr pc,[r9,#8] */
1999 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
2002 /* An initial stub used if the PLT entry is referenced from Thumb code. */
2003 #define PLT_THUMB_STUB_SIZE 4
2004 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2010 /* The entries in a PLT when using a DLL-based target with multiple
2012 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2014 0xe51ff004, /* ldr pc, [pc, #-4] */
2015 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2018 /* Used to build a map of a section. This is required for mixed-endian
2021 typedef struct elf32_elf_section_map
2026 elf32_arm_section_map;
2028 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2032 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2033 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2034 VFP11_ERRATUM_ARM_VENEER,
2035 VFP11_ERRATUM_THUMB_VENEER
2037 elf32_vfp11_erratum_type;
2039 typedef struct elf32_vfp11_erratum_list
2041 struct elf32_vfp11_erratum_list *next;
2047 struct elf32_vfp11_erratum_list *veneer;
2048 unsigned int vfp_insn;
2052 struct elf32_vfp11_erratum_list *branch;
2056 elf32_vfp11_erratum_type type;
2058 elf32_vfp11_erratum_list;
2060 typedef struct _arm_elf_section_data
2062 struct bfd_elf_section_data elf;
2063 unsigned int mapcount;
2064 unsigned int mapsize;
2065 elf32_arm_section_map *map;
2066 unsigned int erratumcount;
2067 elf32_vfp11_erratum_list *erratumlist;
2069 _arm_elf_section_data;
2071 #define elf32_arm_section_data(sec) \
2072 ((_arm_elf_section_data *) elf_section_data (sec))
2074 /* The size of the thread control block. */
2077 struct elf32_arm_obj_tdata
2079 struct elf_obj_tdata root;
2081 /* tls_type for each local got entry. */
2082 char *local_got_tls_type;
2084 /* Zero to warn when linking objects with incompatible enum sizes. */
2085 int no_enum_size_warning;
2088 #define elf32_arm_tdata(abfd) \
2089 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2091 #define elf32_arm_local_got_tls_type(abfd) \
2092 (elf32_arm_tdata (abfd)->local_got_tls_type)
2095 elf32_arm_mkobject (bfd *abfd)
2097 if (abfd->tdata.any == NULL)
2099 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2100 abfd->tdata.any = bfd_zalloc (abfd, amt);
2101 if (abfd->tdata.any == NULL)
2104 return bfd_elf_mkobject (abfd);
2107 /* The ARM linker needs to keep track of the number of relocs that it
2108 decides to copy in check_relocs for each symbol. This is so that
2109 it can discard PC relative relocs if it doesn't need them when
2110 linking with -Bsymbolic. We store the information in a field
2111 extending the regular ELF linker hash table. */
2113 /* This structure keeps track of the number of relocs we have copied
2114 for a given symbol. */
2115 struct elf32_arm_relocs_copied
2118 struct elf32_arm_relocs_copied * next;
2119 /* A section in dynobj. */
2121 /* Number of relocs copied in this section. */
2122 bfd_size_type count;
2123 /* Number of PC-relative relocs copied in this section. */
2124 bfd_size_type pc_count;
2127 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2129 /* Arm ELF linker hash entry. */
2130 struct elf32_arm_link_hash_entry
2132 struct elf_link_hash_entry root;
2134 /* Number of PC relative relocs copied for this symbol. */
2135 struct elf32_arm_relocs_copied * relocs_copied;
2137 /* We reference count Thumb references to a PLT entry separately,
2138 so that we can emit the Thumb trampoline only if needed. */
2139 bfd_signed_vma plt_thumb_refcount;
2141 /* Since PLT entries have variable size if the Thumb prologue is
2142 used, we need to record the index into .got.plt instead of
2143 recomputing it from the PLT offset. */
2144 bfd_signed_vma plt_got_offset;
2146 #define GOT_UNKNOWN 0
2147 #define GOT_NORMAL 1
2148 #define GOT_TLS_GD 2
2149 #define GOT_TLS_IE 4
2150 unsigned char tls_type;
2152 /* The symbol marking the real symbol location for exported thumb
2153 symbols with Arm stubs. */
2154 struct elf_link_hash_entry *export_glue;
2157 /* Traverse an arm ELF linker hash table. */
2158 #define elf32_arm_link_hash_traverse(table, func, info) \
2159 (elf_link_hash_traverse \
2161 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2164 /* Get the ARM elf linker hash table from a link_info structure. */
2165 #define elf32_arm_hash_table(info) \
2166 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2168 /* ARM ELF linker hash table. */
2169 struct elf32_arm_link_hash_table
2171 /* The main hash table. */
2172 struct elf_link_hash_table root;
2174 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2175 bfd_size_type thumb_glue_size;
2177 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2178 bfd_size_type arm_glue_size;
2180 /* The size in bytes of the section containing glue for VFP11 erratum
2182 bfd_size_type vfp11_erratum_glue_size;
2184 /* An arbitrary input BFD chosen to hold the glue sections. */
2185 bfd * bfd_of_glue_owner;
2187 /* Nonzero to output a BE8 image. */
2190 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2191 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2194 /* The relocation to use for R_ARM_TARGET2 relocations. */
2197 /* Nonzero to fix BX instructions for ARMv4 targets. */
2200 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2203 /* What sort of code sequences we should look for which may trigger the
2204 VFP11 denorm erratum. */
2205 bfd_arm_vfp11_fix vfp11_fix;
2207 /* Global counter for the number of fixes we have emitted. */
2208 int num_vfp11_fixes;
2210 /* Nonzero to force PIC branch veneers. */
2213 /* The number of bytes in the initial entry in the PLT. */
2214 bfd_size_type plt_header_size;
2216 /* The number of bytes in the subsequent PLT etries. */
2217 bfd_size_type plt_entry_size;
2219 /* True if the target system is VxWorks. */
2222 /* True if the target system is Symbian OS. */
2225 /* True if the target uses REL relocations. */
2228 /* Short-cuts to get to dynamic linker sections. */
2237 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2240 /* Data for R_ARM_TLS_LDM32 relocations. */
2242 bfd_signed_vma refcount;
2246 /* Small local sym to section mapping cache. */
2247 struct sym_sec_cache sym_sec;
2249 /* For convenience in allocate_dynrelocs. */
2253 /* Create an entry in an ARM ELF linker hash table. */
2255 static struct bfd_hash_entry *
2256 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2257 struct bfd_hash_table * table,
2258 const char * string)
2260 struct elf32_arm_link_hash_entry * ret =
2261 (struct elf32_arm_link_hash_entry *) entry;
2263 /* Allocate the structure if it has not already been allocated by a
2265 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2266 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2268 return (struct bfd_hash_entry *) ret;
2270 /* Call the allocation method of the superclass. */
2271 ret = ((struct elf32_arm_link_hash_entry *)
2272 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2276 ret->relocs_copied = NULL;
2277 ret->tls_type = GOT_UNKNOWN;
2278 ret->plt_thumb_refcount = 0;
2279 ret->plt_got_offset = -1;
2280 ret->export_glue = NULL;
2283 return (struct bfd_hash_entry *) ret;
2286 /* Return true if NAME is the name of the relocation section associated
2290 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2291 const char *name, asection *s)
2294 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2296 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2299 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2300 shortcuts to them in our hash table. */
2303 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2305 struct elf32_arm_link_hash_table *htab;
2307 htab = elf32_arm_hash_table (info);
2308 /* BPABI objects never have a GOT, or associated sections. */
2309 if (htab->symbian_p)
2312 if (! _bfd_elf_create_got_section (dynobj, info))
2315 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2316 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2317 if (!htab->sgot || !htab->sgotplt)
2320 htab->srelgot = bfd_make_section_with_flags (dynobj,
2321 RELOC_SECTION (htab, ".got"),
2322 (SEC_ALLOC | SEC_LOAD
2325 | SEC_LINKER_CREATED
2327 if (htab->srelgot == NULL
2328 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2333 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2334 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2338 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2340 struct elf32_arm_link_hash_table *htab;
2342 htab = elf32_arm_hash_table (info);
2343 if (!htab->sgot && !create_got_section (dynobj, info))
2346 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2349 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2350 htab->srelplt = bfd_get_section_by_name (dynobj,
2351 RELOC_SECTION (htab, ".plt"));
2352 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2354 htab->srelbss = bfd_get_section_by_name (dynobj,
2355 RELOC_SECTION (htab, ".bss"));
2357 if (htab->vxworks_p)
2359 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2364 htab->plt_header_size = 0;
2365 htab->plt_entry_size
2366 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2370 htab->plt_header_size
2371 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2372 htab->plt_entry_size
2373 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2380 || (!info->shared && !htab->srelbss))
2386 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2389 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2390 struct elf_link_hash_entry *dir,
2391 struct elf_link_hash_entry *ind)
2393 struct elf32_arm_link_hash_entry *edir, *eind;
2395 edir = (struct elf32_arm_link_hash_entry *) dir;
2396 eind = (struct elf32_arm_link_hash_entry *) ind;
2398 if (eind->relocs_copied != NULL)
2400 if (edir->relocs_copied != NULL)
2402 struct elf32_arm_relocs_copied **pp;
2403 struct elf32_arm_relocs_copied *p;
2405 /* Add reloc counts against the indirect sym to the direct sym
2406 list. Merge any entries against the same section. */
2407 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2409 struct elf32_arm_relocs_copied *q;
2411 for (q = edir->relocs_copied; q != NULL; q = q->next)
2412 if (q->section == p->section)
2414 q->pc_count += p->pc_count;
2415 q->count += p->count;
2422 *pp = edir->relocs_copied;
2425 edir->relocs_copied = eind->relocs_copied;
2426 eind->relocs_copied = NULL;
2429 if (ind->root.type == bfd_link_hash_indirect)
2431 /* Copy over PLT info. */
2432 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2433 eind->plt_thumb_refcount = 0;
2435 if (dir->got.refcount <= 0)
2437 edir->tls_type = eind->tls_type;
2438 eind->tls_type = GOT_UNKNOWN;
2442 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2445 /* Create an ARM elf linker hash table. */
2447 static struct bfd_link_hash_table *
2448 elf32_arm_link_hash_table_create (bfd *abfd)
2450 struct elf32_arm_link_hash_table *ret;
2451 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2453 ret = bfd_malloc (amt);
2457 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2458 elf32_arm_link_hash_newfunc,
2459 sizeof (struct elf32_arm_link_hash_entry)))
2466 ret->sgotplt = NULL;
2467 ret->srelgot = NULL;
2469 ret->srelplt = NULL;
2470 ret->sdynbss = NULL;
2471 ret->srelbss = NULL;
2472 ret->srelplt2 = NULL;
2473 ret->thumb_glue_size = 0;
2474 ret->arm_glue_size = 0;
2475 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2476 ret->vfp11_erratum_glue_size = 0;
2477 ret->num_vfp11_fixes = 0;
2478 ret->bfd_of_glue_owner = NULL;
2479 ret->byteswap_code = 0;
2480 ret->target1_is_rel = 0;
2481 ret->target2_reloc = R_ARM_NONE;
2482 #ifdef FOUR_WORD_PLT
2483 ret->plt_header_size = 16;
2484 ret->plt_entry_size = 16;
2486 ret->plt_header_size = 20;
2487 ret->plt_entry_size = 12;
2494 ret->sym_sec.abfd = NULL;
2496 ret->tls_ldm_got.refcount = 0;
2498 return &ret->root.root;
2501 /* Locate the Thumb encoded calling stub for NAME. */
2503 static struct elf_link_hash_entry *
2504 find_thumb_glue (struct bfd_link_info *link_info,
2506 char **error_message)
2509 struct elf_link_hash_entry *hash;
2510 struct elf32_arm_link_hash_table *hash_table;
2512 /* We need a pointer to the armelf specific hash table. */
2513 hash_table = elf32_arm_hash_table (link_info);
2515 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2516 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2518 BFD_ASSERT (tmp_name);
2520 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2522 hash = elf_link_hash_lookup
2523 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2526 asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2534 /* Locate the ARM encoded calling stub for NAME. */
2536 static struct elf_link_hash_entry *
2537 find_arm_glue (struct bfd_link_info *link_info,
2539 char **error_message)
2542 struct elf_link_hash_entry *myh;
2543 struct elf32_arm_link_hash_table *hash_table;
2545 /* We need a pointer to the elfarm specific hash table. */
2546 hash_table = elf32_arm_hash_table (link_info);
2548 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2549 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2551 BFD_ASSERT (tmp_name);
2553 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2555 myh = elf_link_hash_lookup
2556 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2559 asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2567 /* ARM->Thumb glue (static images):
2571 ldr r12, __func_addr
2574 .word func @ behave as if you saw a ARM_32 reloc.
2581 .word func @ behave as if you saw a ARM_32 reloc.
2583 (relocatable images)
2586 ldr r12, __func_offset
2593 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2594 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2595 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2596 static const insn32 a2t3_func_addr_insn = 0x00000001;
2598 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
2599 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
2600 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
2602 #define ARM2THUMB_PIC_GLUE_SIZE 16
2603 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2604 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2605 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2607 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2611 __func_from_thumb: __func_from_thumb:
2613 nop ldr r6, __func_addr
2615 __func_change_to_arm: bx r6
2617 __func_back_to_thumb:
2623 #define THUMB2ARM_GLUE_SIZE 8
2624 static const insn16 t2a1_bx_pc_insn = 0x4778;
2625 static const insn16 t2a2_noop_insn = 0x46c0;
2626 static const insn32 t2a3_b_insn = 0xea000000;
2628 #define VFP11_ERRATUM_VENEER_SIZE 8
2630 #ifndef ELFARM_NABI_C_INCLUDED
2632 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2636 struct elf32_arm_link_hash_table * globals;
2638 globals = elf32_arm_hash_table (info);
2640 BFD_ASSERT (globals != NULL);
2642 if (globals->arm_glue_size != 0)
2644 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2646 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2647 ARM2THUMB_GLUE_SECTION_NAME);
2649 BFD_ASSERT (s != NULL);
2651 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2653 BFD_ASSERT (s->size == globals->arm_glue_size);
2657 if (globals->thumb_glue_size != 0)
2659 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2661 s = bfd_get_section_by_name
2662 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2664 BFD_ASSERT (s != NULL);
2666 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2668 BFD_ASSERT (s->size == globals->thumb_glue_size);
2672 if (globals->vfp11_erratum_glue_size != 0)
2674 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2676 s = bfd_get_section_by_name
2677 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2679 BFD_ASSERT (s != NULL);
2681 foo = bfd_alloc (globals->bfd_of_glue_owner,
2682 globals->vfp11_erratum_glue_size);
2684 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
2691 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2692 returns the symbol identifying teh stub. */
2693 static struct elf_link_hash_entry *
2694 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2695 struct elf_link_hash_entry * h)
2697 const char * name = h->root.root.string;
2700 struct elf_link_hash_entry * myh;
2701 struct bfd_link_hash_entry * bh;
2702 struct elf32_arm_link_hash_table * globals;
2706 globals = elf32_arm_hash_table (link_info);
2708 BFD_ASSERT (globals != NULL);
2709 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2711 s = bfd_get_section_by_name
2712 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2714 BFD_ASSERT (s != NULL);
2716 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2718 BFD_ASSERT (tmp_name);
2720 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2722 myh = elf_link_hash_lookup
2723 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2727 /* We've already seen this guy. */
2732 /* The only trick here is using hash_table->arm_glue_size as the value.
2733 Even though the section isn't allocated yet, this is where we will be
2736 val = globals->arm_glue_size + 1;
2737 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2738 tmp_name, BSF_GLOBAL, s, val,
2739 NULL, TRUE, FALSE, &bh);
2741 myh = (struct elf_link_hash_entry *) bh;
2742 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2743 myh->forced_local = 1;
2747 if (link_info->shared || globals->root.is_relocatable_executable
2748 || globals->pic_veneer)
2749 size = ARM2THUMB_PIC_GLUE_SIZE;
2750 else if (globals->use_blx)
2751 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
2753 size = ARM2THUMB_STATIC_GLUE_SIZE;
2756 globals->arm_glue_size += size;
2762 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2763 struct elf_link_hash_entry *h)
2765 const char *name = h->root.root.string;
2768 struct elf_link_hash_entry *myh;
2769 struct bfd_link_hash_entry *bh;
2770 struct elf32_arm_link_hash_table *hash_table;
2773 hash_table = elf32_arm_hash_table (link_info);
2775 BFD_ASSERT (hash_table != NULL);
2776 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2778 s = bfd_get_section_by_name
2779 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2781 BFD_ASSERT (s != NULL);
2783 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2784 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2786 BFD_ASSERT (tmp_name);
2788 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2790 myh = elf_link_hash_lookup
2791 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2795 /* We've already seen this guy. */
2801 val = hash_table->thumb_glue_size + 1;
2802 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2803 tmp_name, BSF_GLOBAL, s, val,
2804 NULL, TRUE, FALSE, &bh);
2806 /* If we mark it 'Thumb', the disassembler will do a better job. */
2807 myh = (struct elf_link_hash_entry *) bh;
2808 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2809 myh->forced_local = 1;
2813 #define CHANGE_TO_ARM "__%s_change_to_arm"
2814 #define BACK_FROM_ARM "__%s_back_from_arm"
2816 /* Allocate another symbol to mark where we switch to Arm mode. */
2817 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2818 + strlen (CHANGE_TO_ARM) + 1);
2820 BFD_ASSERT (tmp_name);
2822 sprintf (tmp_name, CHANGE_TO_ARM, name);
2825 val = hash_table->thumb_glue_size + 4,
2826 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2827 tmp_name, BSF_LOCAL, s, val,
2828 NULL, TRUE, FALSE, &bh);
2832 s->size += THUMB2ARM_GLUE_SIZE;
2833 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2839 /* Add an entry to the code/data map for section SEC. */
2842 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
2844 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
2845 unsigned int newidx;
2847 if (sec_data->map == NULL)
2849 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
2850 sec_data->mapcount = 0;
2851 sec_data->mapsize = 1;
2854 newidx = sec_data->mapcount++;
2856 if (sec_data->mapcount > sec_data->mapsize)
2858 sec_data->mapsize *= 2;
2859 sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize
2860 * sizeof (elf32_arm_section_map));
2863 sec_data->map[newidx].vma = vma;
2864 sec_data->map[newidx].type = type;
2868 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
2869 veneers are handled for now. */
2872 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
2873 elf32_vfp11_erratum_list *branch,
2875 asection *branch_sec,
2876 unsigned int offset)
2879 struct elf32_arm_link_hash_table *hash_table;
2881 struct elf_link_hash_entry *myh;
2882 struct bfd_link_hash_entry *bh;
2884 struct _arm_elf_section_data *sec_data;
2886 elf32_vfp11_erratum_list *newerr;
2888 hash_table = elf32_arm_hash_table (link_info);
2890 BFD_ASSERT (hash_table != NULL);
2891 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2893 s = bfd_get_section_by_name
2894 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2896 sec_data = elf32_arm_section_data (s);
2898 BFD_ASSERT (s != NULL);
2900 tmp_name = bfd_malloc ((bfd_size_type) strlen
2901 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
2903 BFD_ASSERT (tmp_name);
2905 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
2906 hash_table->num_vfp11_fixes);
2908 myh = elf_link_hash_lookup
2909 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2911 BFD_ASSERT (myh == NULL);
2914 val = hash_table->vfp11_erratum_glue_size;
2915 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2916 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
2917 NULL, TRUE, FALSE, &bh);
2919 myh = (struct elf_link_hash_entry *) bh;
2920 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2921 myh->forced_local = 1;
2923 /* Link veneer back to calling location. */
2924 errcount = ++(sec_data->erratumcount);
2925 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
2927 newerr->type = VFP11_ERRATUM_ARM_VENEER;
2929 newerr->u.v.branch = branch;
2930 newerr->u.v.id = hash_table->num_vfp11_fixes;
2931 branch->u.b.veneer = newerr;
2933 newerr->next = sec_data->erratumlist;
2934 sec_data->erratumlist = newerr;
2936 /* A symbol for the return from the veneer. */
2937 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
2938 hash_table->num_vfp11_fixes);
2940 myh = elf_link_hash_lookup
2941 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2948 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
2949 branch_sec, val, NULL, TRUE, FALSE, &bh);
2951 myh = (struct elf_link_hash_entry *) bh;
2952 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2953 myh->forced_local = 1;
2957 /* Generate a mapping symbol for the veneer section, and explicitly add an
2958 entry for that symbol to the code/data map for the section. */
2959 if (hash_table->vfp11_erratum_glue_size == 0)
2962 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
2963 ever requires this erratum fix. */
2964 _bfd_generic_link_add_one_symbol (link_info,
2965 hash_table->bfd_of_glue_owner, "$a",
2966 BSF_LOCAL, s, 0, NULL,
2969 myh = (struct elf_link_hash_entry *) bh;
2970 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
2971 myh->forced_local = 1;
2973 /* The elf32_arm_init_maps function only cares about symbols from input
2974 BFDs. We must make a note of this generated mapping symbol
2975 ourselves so that code byteswapping works properly in
2976 elf32_arm_write_section. */
2977 elf32_arm_section_map_add (s, 'a', 0);
2980 s->size += VFP11_ERRATUM_VENEER_SIZE;
2981 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
2982 hash_table->num_vfp11_fixes++;
2984 /* The offset of the veneer. */
2988 /* Add the glue sections to ABFD. This function is called from the
2989 linker scripts in ld/emultempl/{armelf}.em. */
2992 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2993 struct bfd_link_info *info)
2998 /* If we are only performing a partial
2999 link do not bother adding the glue. */
3000 if (info->relocatable)
3003 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
3007 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
3008 will prevent elf_link_input_bfd() from processing the contents
3010 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3011 | SEC_CODE | SEC_READONLY);
3013 sec = bfd_make_section_with_flags (abfd,
3014 ARM2THUMB_GLUE_SECTION_NAME,
3018 || !bfd_set_section_alignment (abfd, sec, 2))
3021 /* Set the gc mark to prevent the section from being removed by garbage
3022 collection, despite the fact that no relocs refer to this section. */
3026 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
3030 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3031 | SEC_CODE | SEC_READONLY);
3033 sec = bfd_make_section_with_flags (abfd,
3034 THUMB2ARM_GLUE_SECTION_NAME,
3038 || !bfd_set_section_alignment (abfd, sec, 2))
3044 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
3048 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3049 | SEC_CODE | SEC_READONLY);
3051 sec = bfd_make_section_with_flags (abfd,
3052 VFP11_ERRATUM_VENEER_SECTION_NAME,
3056 || !bfd_set_section_alignment (abfd, sec, 2))
3065 /* Select a BFD to be used to hold the sections used by the glue code.
3066 This function is called from the linker scripts in ld/emultempl/
3070 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
3072 struct elf32_arm_link_hash_table *globals;
3074 /* If we are only performing a partial link
3075 do not bother getting a bfd to hold the glue. */
3076 if (info->relocatable)
3079 /* Make sure we don't attach the glue sections to a dynamic object. */
3080 BFD_ASSERT (!(abfd->flags & DYNAMIC));
3082 globals = elf32_arm_hash_table (info);
3084 BFD_ASSERT (globals != NULL);
3086 if (globals->bfd_of_glue_owner != NULL)
3089 /* Save the bfd for later use. */
3090 globals->bfd_of_glue_owner = abfd;
3095 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
3097 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3099 globals->use_blx = 1;
3103 bfd_elf32_arm_process_before_allocation (bfd *abfd,
3104 struct bfd_link_info *link_info)
3106 Elf_Internal_Shdr *symtab_hdr;
3107 Elf_Internal_Rela *internal_relocs = NULL;
3108 Elf_Internal_Rela *irel, *irelend;
3109 bfd_byte *contents = NULL;
3112 struct elf32_arm_link_hash_table *globals;
3114 /* If we are only performing a partial link do not bother
3115 to construct any glue. */
3116 if (link_info->relocatable)
3119 /* Here we have a bfd that is to be included on the link. We have a hook
3120 to do reloc rummaging, before section sizes are nailed down. */
3121 globals = elf32_arm_hash_table (link_info);
3122 check_use_blx (globals);
3124 BFD_ASSERT (globals != NULL);
3125 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3127 if (globals->byteswap_code && !bfd_big_endian (abfd))
3129 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
3134 /* Rummage around all the relocs and map the glue vectors. */
3135 sec = abfd->sections;
3140 for (; sec != NULL; sec = sec->next)
3142 if (sec->reloc_count == 0)
3145 if ((sec->flags & SEC_EXCLUDE) != 0)
3148 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3150 /* Load the relocs. */
3152 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
3153 (Elf_Internal_Rela *) NULL, FALSE);
3155 if (internal_relocs == NULL)
3158 irelend = internal_relocs + sec->reloc_count;
3159 for (irel = internal_relocs; irel < irelend; irel++)
3162 unsigned long r_index;
3164 struct elf_link_hash_entry *h;
3166 r_type = ELF32_R_TYPE (irel->r_info);
3167 r_index = ELF32_R_SYM (irel->r_info);
3169 /* These are the only relocation types we care about. */
3170 if ( r_type != R_ARM_PC24
3171 && r_type != R_ARM_PLT32
3172 && r_type != R_ARM_CALL
3173 && r_type != R_ARM_JUMP24
3174 && r_type != R_ARM_THM_CALL)
3177 /* Get the section contents if we haven't done so already. */
3178 if (contents == NULL)
3180 /* Get cached copy if it exists. */
3181 if (elf_section_data (sec)->this_hdr.contents != NULL)
3182 contents = elf_section_data (sec)->this_hdr.contents;
3185 /* Go get them off disk. */
3186 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3191 /* If the relocation is not against a symbol it cannot concern us. */
3194 /* We don't care about local symbols. */
3195 if (r_index < symtab_hdr->sh_info)
3198 /* This is an external symbol. */
3199 r_index -= symtab_hdr->sh_info;
3200 h = (struct elf_link_hash_entry *)
3201 elf_sym_hashes (abfd)[r_index];
3203 /* If the relocation is against a static symbol it must be within
3204 the current section and so cannot be a cross ARM/Thumb relocation. */
3208 /* If the call will go through a PLT entry then we do not need
3210 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
3219 /* This one is a call from arm code. We need to look up
3220 the target of the call. If it is a thumb target, we
3222 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
3223 && !(r_type == R_ARM_CALL && globals->use_blx))
3224 record_arm_to_thumb_glue (link_info, h);
3227 case R_ARM_THM_CALL:
3228 /* This one is a call from thumb code. We look
3229 up the target of the call. If it is not a thumb
3230 target, we insert glue. */
3231 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx
3232 && h->root.type != bfd_link_hash_undefweak)
3233 record_thumb_to_arm_glue (link_info, h);
3241 if (contents != NULL
3242 && elf_section_data (sec)->this_hdr.contents != contents)
3246 if (internal_relocs != NULL
3247 && elf_section_data (sec)->relocs != internal_relocs)
3248 free (internal_relocs);
3249 internal_relocs = NULL;
3255 if (contents != NULL
3256 && elf_section_data (sec)->this_hdr.contents != contents)
3258 if (internal_relocs != NULL
3259 && elf_section_data (sec)->relocs != internal_relocs)
3260 free (internal_relocs);
3267 /* Initialise maps of ARM/Thumb/data for input BFDs. */
3270 bfd_elf32_arm_init_maps (bfd *abfd)
3272 Elf_Internal_Sym *isymbuf;
3273 Elf_Internal_Shdr *hdr;
3274 unsigned int i, localsyms;
3276 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour || elf_tdata (abfd) == NULL)
3279 if ((abfd->flags & DYNAMIC) != 0)
3282 hdr = &elf_tdata (abfd)->symtab_hdr;
3283 localsyms = hdr->sh_info;
3285 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3286 should contain the number of local symbols, which should come before any
3287 global symbols. Mapping symbols are always local. */
3288 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
3291 /* No internal symbols read? Skip this BFD. */
3292 if (isymbuf == NULL)
3295 for (i = 0; i < localsyms; i++)
3297 Elf_Internal_Sym *isym = &isymbuf[i];
3298 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3302 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3304 name = bfd_elf_string_from_elf_section (abfd,
3305 hdr->sh_link, isym->st_name);
3307 if (bfd_is_arm_special_symbol_name (name,
3308 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
3309 elf32_arm_section_map_add (sec, name[1], isym->st_value);
3316 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
3318 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3319 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
3321 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
3322 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
3324 switch (globals->vfp11_fix)
3326 case BFD_ARM_VFP11_FIX_DEFAULT:
3327 case BFD_ARM_VFP11_FIX_NONE:
3328 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3332 /* Give a warning, but do as the user requests anyway. */
3333 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
3334 "workaround is not necessary for target architecture"), obfd);
3337 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
3338 /* For earlier architectures, we might need the workaround, but do not
3339 enable it by default. If users is running with broken hardware, they
3340 must enable the erratum fix explicitly. */
3341 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3345 enum bfd_arm_vfp11_pipe {
3352 /* Return a VFP register number. This is encoded as RX:X for single-precision
3353 registers, or X:RX for double-precision registers, where RX is the group of
3354 four bits in the instruction encoding and X is the single extension bit.
3355 RX and X fields are specified using their lowest (starting) bit. The return
3358 0...31: single-precision registers s0...s31
3359 32...63: double-precision registers d0...d31.
3361 Although X should be zero for VFP11 (encoding d0...d15 only), we might
3362 encounter VFP3 instructions, so we allow the full range for DP registers. */
3365 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
3369 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
3371 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
3374 /* Set bits in *WMASK according to a register number REG as encoded by
3375 bfd_arm_vfp11_regno(). Ignore d16-d31. */
3378 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
3383 *wmask |= 3 << ((reg - 32) * 2);
3386 /* Return TRUE if WMASK overwrites anything in REGS. */
3389 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
3393 for (i = 0; i < numregs; i++)
3395 unsigned int reg = regs[i];
3397 if (reg < 32 && (wmask & (1 << reg)) != 0)
3405 if ((wmask & (3 << (reg * 2))) != 0)
3412 /* In this function, we're interested in two things: finding input registers
3413 for VFP data-processing instructions, and finding the set of registers which
3414 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
3415 hold the written set, so FLDM etc. are easy to deal with (we're only
3416 interested in 32 SP registers or 16 dp registers, due to the VFP version
3417 implemented by the chip in question). DP registers are marked by setting
3418 both SP registers in the write mask). */
3420 static enum bfd_arm_vfp11_pipe
3421 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
3424 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
3425 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
3427 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
3430 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3431 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3433 pqrs = ((insn & 0x00800000) >> 20)
3434 | ((insn & 0x00300000) >> 19)
3435 | ((insn & 0x00000040) >> 6);
3439 case 0: /* fmac[sd]. */
3440 case 1: /* fnmac[sd]. */
3441 case 2: /* fmsc[sd]. */
3442 case 3: /* fnmsc[sd]. */
3444 bfd_arm_vfp11_write_mask (destmask, fd);
3446 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3451 case 4: /* fmul[sd]. */
3452 case 5: /* fnmul[sd]. */
3453 case 6: /* fadd[sd]. */
3454 case 7: /* fsub[sd]. */
3458 case 8: /* fdiv[sd]. */
3461 bfd_arm_vfp11_write_mask (destmask, fd);
3462 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3467 case 15: /* extended opcode. */
3469 unsigned int extn = ((insn >> 15) & 0x1e)
3470 | ((insn >> 7) & 1);
3474 case 0: /* fcpy[sd]. */
3475 case 1: /* fabs[sd]. */
3476 case 2: /* fneg[sd]. */
3477 case 8: /* fcmp[sd]. */
3478 case 9: /* fcmpe[sd]. */
3479 case 10: /* fcmpz[sd]. */
3480 case 11: /* fcmpez[sd]. */
3481 case 16: /* fuito[sd]. */
3482 case 17: /* fsito[sd]. */
3483 case 24: /* ftoui[sd]. */
3484 case 25: /* ftouiz[sd]. */
3485 case 26: /* ftosi[sd]. */
3486 case 27: /* ftosiz[sd]. */
3487 /* These instructions will not bounce due to underflow. */
3492 case 3: /* fsqrt[sd]. */
3493 /* fsqrt cannot underflow, but it can (perhaps) overwrite
3494 registers to cause the erratum in previous instructions. */
3495 bfd_arm_vfp11_write_mask (destmask, fd);
3499 case 15: /* fcvt{ds,sd}. */
3503 bfd_arm_vfp11_write_mask (destmask, fd);
3505 /* Only FCVTSD can underflow. */
3506 if ((insn & 0x100) != 0)
3525 /* Two-register transfer. */
3526 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
3528 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3530 if ((insn & 0x100000) == 0)
3533 bfd_arm_vfp11_write_mask (destmask, fm);
3536 bfd_arm_vfp11_write_mask (destmask, fm);
3537 bfd_arm_vfp11_write_mask (destmask, fm + 1);
3543 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
3545 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3546 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
3550 case 0: /* Two-reg transfer. We should catch these above. */
3553 case 2: /* fldm[sdx]. */
3557 unsigned int i, offset = insn & 0xff;
3562 for (i = fd; i < fd + offset; i++)
3563 bfd_arm_vfp11_write_mask (destmask, i);
3567 case 4: /* fld[sd]. */
3569 bfd_arm_vfp11_write_mask (destmask, fd);
3578 /* Single-register transfer. Note L==0. */
3579 else if ((insn & 0x0f100e10) == 0x0e000a10)
3581 unsigned int opcode = (insn >> 21) & 7;
3582 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
3586 case 0: /* fmsr/fmdlr. */
3587 case 1: /* fmdhr. */
3588 /* Mark fmdhr and fmdlr as writing to the whole of the DP
3589 destination register. I don't know if this is exactly right,
3590 but it is the conservative choice. */
3591 bfd_arm_vfp11_write_mask (destmask, fn);
3605 static int elf32_arm_compare_mapping (const void * a, const void * b);
3608 /* Look for potentially-troublesome code sequences which might trigger the
3609 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
3610 (available from ARM) for details of the erratum. A short version is
3611 described in ld.texinfo. */
3614 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
3617 bfd_byte *contents = NULL;
3619 int regs[3], numregs = 0;
3620 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3621 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
3623 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
3624 The states transition as follows:
3626 0 -> 1 (vector) or 0 -> 2 (scalar)
3627 A VFP FMAC-pipeline instruction has been seen. Fill
3628 regs[0]..regs[numregs-1] with its input operands. Remember this
3629 instruction in 'first_fmac'.
3632 Any instruction, except for a VFP instruction which overwrites
3637 A VFP instruction has been seen which overwrites any of regs[*].
3638 We must make a veneer! Reset state to 0 before examining next
3642 If we fail to match anything in state 2, reset to state 0 and reset
3643 the instruction pointer to the instruction after 'first_fmac'.
3645 If the VFP11 vector mode is in use, there must be at least two unrelated
3646 instructions between anti-dependent VFP11 instructions to properly avoid
3647 triggering the erratum, hence the use of the extra state 1.
3650 /* If we are only performing a partial link do not bother
3651 to construct any glue. */
3652 if (link_info->relocatable)
3655 /* We should have chosen a fix type by the time we get here. */
3656 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
3658 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
3661 /* Skip if this bfd does not correspond to an ELF image. */
3662 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3665 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3667 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
3668 struct _arm_elf_section_data *sec_data;
3670 /* If we don't have executable progbits, we're not interested in this
3671 section. Also skip if section is to be excluded. */
3672 if (elf_section_type (sec) != SHT_PROGBITS
3673 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
3674 || (sec->flags & SEC_EXCLUDE) != 0
3675 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
3678 sec_data = elf32_arm_section_data (sec);
3680 if (sec_data->mapcount == 0)
3683 if (elf_section_data (sec)->this_hdr.contents != NULL)
3684 contents = elf_section_data (sec)->this_hdr.contents;
3685 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3688 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
3689 elf32_arm_compare_mapping);
3691 for (span = 0; span < sec_data->mapcount; span++)
3693 unsigned int span_start = sec_data->map[span].vma;
3694 unsigned int span_end = (span == sec_data->mapcount - 1)
3695 ? sec->size : sec_data->map[span + 1].vma;
3696 char span_type = sec_data->map[span].type;
3698 /* FIXME: Only ARM mode is supported at present. We may need to
3699 support Thumb-2 mode also at some point. */
3700 if (span_type != 'a')
3703 for (i = span_start; i < span_end;)
3705 unsigned int next_i = i + 4;
3706 unsigned int insn = bfd_big_endian (abfd)
3707 ? (contents[i] << 24)
3708 | (contents[i + 1] << 16)
3709 | (contents[i + 2] << 8)
3711 : (contents[i + 3] << 24)
3712 | (contents[i + 2] << 16)
3713 | (contents[i + 1] << 8)
3715 unsigned int writemask = 0;
3716 enum bfd_arm_vfp11_pipe pipe;
3721 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
3723 /* I'm assuming the VFP11 erratum can trigger with denorm
3724 operands on either the FMAC or the DS pipeline. This might
3725 lead to slightly overenthusiastic veneer insertion. */
3726 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
3728 state = use_vector ? 1 : 2;
3730 veneer_of_insn = insn;
3736 int other_regs[3], other_numregs;
3737 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3740 if (pipe != VFP11_BAD
3741 && bfd_arm_vfp11_antidependency (writemask, regs,
3751 int other_regs[3], other_numregs;
3752 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3755 if (pipe != VFP11_BAD
3756 && bfd_arm_vfp11_antidependency (writemask, regs,
3762 next_i = first_fmac + 4;
3768 abort (); /* Should be unreachable. */
3773 elf32_vfp11_erratum_list *newerr
3774 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
3777 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
3779 newerr->u.b.vfp_insn = veneer_of_insn;
3784 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
3791 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
3796 newerr->next = sec_data->erratumlist;
3797 sec_data->erratumlist = newerr;
3806 if (contents != NULL
3807 && elf_section_data (sec)->this_hdr.contents != contents)
3815 if (contents != NULL
3816 && elf_section_data (sec)->this_hdr.contents != contents)
3822 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
3823 after sections have been laid out, using specially-named symbols. */
3826 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
3827 struct bfd_link_info *link_info)
3830 struct elf32_arm_link_hash_table *globals;
3833 if (link_info->relocatable)
3836 /* Skip if this bfd does not correspond to an ELF image. */
3837 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3840 globals = elf32_arm_hash_table (link_info);
3842 tmp_name = bfd_malloc ((bfd_size_type) strlen
3843 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
3845 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3847 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
3848 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
3850 for (; errnode != NULL; errnode = errnode->next)
3852 struct elf_link_hash_entry *myh;
3855 switch (errnode->type)
3857 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
3858 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
3859 /* Find veneer symbol. */
3860 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
3861 errnode->u.b.veneer->u.v.id);
3863 myh = elf_link_hash_lookup
3864 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3867 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3868 "`%s'"), abfd, tmp_name);
3870 vma = myh->root.u.def.section->output_section->vma
3871 + myh->root.u.def.section->output_offset
3872 + myh->root.u.def.value;
3874 errnode->u.b.veneer->vma = vma;
3877 case VFP11_ERRATUM_ARM_VENEER:
3878 case VFP11_ERRATUM_THUMB_VENEER:
3879 /* Find return location. */
3880 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
3883 myh = elf_link_hash_lookup
3884 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3887 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3888 "`%s'"), abfd, tmp_name);
3890 vma = myh->root.u.def.section->output_section->vma
3891 + myh->root.u.def.section->output_offset
3892 + myh->root.u.def.value;
3894 errnode->u.v.branch->vma = vma;
3907 /* Set target relocation values needed during linking. */
3910 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
3911 struct bfd_link_info *link_info,
3913 char * target2_type,
3916 bfd_arm_vfp11_fix vfp11_fix,
3917 int no_enum_warn, int pic_veneer)
3919 struct elf32_arm_link_hash_table *globals;
3921 globals = elf32_arm_hash_table (link_info);
3923 globals->target1_is_rel = target1_is_rel;
3924 if (strcmp (target2_type, "rel") == 0)
3925 globals->target2_reloc = R_ARM_REL32;
3926 else if (strcmp (target2_type, "abs") == 0)
3927 globals->target2_reloc = R_ARM_ABS32;
3928 else if (strcmp (target2_type, "got-rel") == 0)
3929 globals->target2_reloc = R_ARM_GOT_PREL;
3932 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3935 globals->fix_v4bx = fix_v4bx;
3936 globals->use_blx |= use_blx;
3937 globals->vfp11_fix = vfp11_fix;
3938 globals->pic_veneer = pic_veneer;
3940 elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
3943 /* The thumb form of a long branch is a bit finicky, because the offset
3944 encoding is split over two fields, each in it's own instruction. They
3945 can occur in any order. So given a thumb form of long branch, and an
3946 offset, insert the offset into the thumb branch and return finished
3949 It takes two thumb instructions to encode the target address. Each has
3950 11 bits to invest. The upper 11 bits are stored in one (identified by
3951 H-0.. see below), the lower 11 bits are stored in the other (identified
3954 Combine together and shifted left by 1 (it's a half word address) and
3958 H-0, upper address-0 = 000
3960 H-1, lower address-0 = 800
3962 They can be ordered either way, but the arm tools I've seen always put
3963 the lower one first. It probably doesn't matter. krk@cygnus.com
3965 XXX: Actually the order does matter. The second instruction (H-1)
3966 moves the computed address into the PC, so it must be the second one
3967 in the sequence. The problem, however is that whilst little endian code
3968 stores the instructions in HI then LOW order, big endian code does the
3969 reverse. nickc@cygnus.com. */
3971 #define LOW_HI_ORDER 0xF800F000
3972 #define HI_LOW_ORDER 0xF000F800
3975 insert_thumb_branch (insn32 br_insn, int rel_off)
3977 unsigned int low_bits;
3978 unsigned int high_bits;
3980 BFD_ASSERT ((rel_off & 1) != 1);
3982 rel_off >>= 1; /* Half word aligned address. */
3983 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
3984 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
3986 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3987 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3988 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3989 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3991 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3992 abort (); /* Error - not a valid branch instruction form. */
3998 /* Store an Arm insn into an output section not processed by
3999 elf32_arm_write_section. */
4002 put_arm_insn (struct elf32_arm_link_hash_table *htab,
4003 bfd * output_bfd, bfd_vma val, void * ptr)
4005 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4006 bfd_putl32 (val, ptr);
4008 bfd_putb32 (val, ptr);
4012 /* Store a 16-bit Thumb insn into an output section not processed by
4013 elf32_arm_write_section. */
4016 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
4017 bfd * output_bfd, bfd_vma val, void * ptr)
4019 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4020 bfd_putl16 (val, ptr);
4022 bfd_putb16 (val, ptr);
4026 /* Thumb code calling an ARM function. */
4029 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
4033 asection * input_section,
4034 bfd_byte * hit_data,
4037 bfd_signed_vma addend,
4039 char **error_message)
4043 unsigned long int tmp;
4044 long int ret_offset;
4045 struct elf_link_hash_entry * myh;
4046 struct elf32_arm_link_hash_table * globals;
4048 myh = find_thumb_glue (info, name, error_message);
4052 globals = elf32_arm_hash_table (info);
4054 BFD_ASSERT (globals != NULL);
4055 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4057 my_offset = myh->root.u.def.value;
4059 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4060 THUMB2ARM_GLUE_SECTION_NAME);
4062 BFD_ASSERT (s != NULL);
4063 BFD_ASSERT (s->contents != NULL);
4064 BFD_ASSERT (s->output_section != NULL);
4066 if ((my_offset & 0x01) == 0x01)
4069 && sym_sec->owner != NULL
4070 && !INTERWORK_FLAG (sym_sec->owner))
4072 (*_bfd_error_handler)
4073 (_("%B(%s): warning: interworking not enabled.\n"
4074 " first occurrence: %B: thumb call to arm"),
4075 sym_sec->owner, input_bfd, name);
4081 myh->root.u.def.value = my_offset;
4083 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
4084 s->contents + my_offset);
4086 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
4087 s->contents + my_offset + 2);
4090 /* Address of destination of the stub. */
4091 ((bfd_signed_vma) val)
4093 /* Offset from the start of the current section
4094 to the start of the stubs. */
4096 /* Offset of the start of this stub from the start of the stubs. */
4098 /* Address of the start of the current section. */
4099 + s->output_section->vma)
4100 /* The branch instruction is 4 bytes into the stub. */
4102 /* ARM branches work from the pc of the instruction + 8. */
4105 put_arm_insn (globals, output_bfd,
4106 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
4107 s->contents + my_offset + 4);
4110 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
4112 /* Now go back and fix up the original BL insn to point to here. */
4114 /* Address of where the stub is located. */
4115 (s->output_section->vma + s->output_offset + my_offset)
4116 /* Address of where the BL is located. */
4117 - (input_section->output_section->vma + input_section->output_offset
4119 /* Addend in the relocation. */
4121 /* Biassing for PC-relative addressing. */
4124 tmp = bfd_get_32 (input_bfd, hit_data
4125 - input_section->vma);
4127 bfd_put_32 (output_bfd,
4128 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
4129 hit_data - input_section->vma);
4134 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
4136 static struct elf_link_hash_entry *
4137 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
4144 char **error_message)
4147 long int ret_offset;
4148 struct elf_link_hash_entry * myh;
4149 struct elf32_arm_link_hash_table * globals;
4151 myh = find_arm_glue (info, name, error_message);
4155 globals = elf32_arm_hash_table (info);
4157 BFD_ASSERT (globals != NULL);
4158 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4160 my_offset = myh->root.u.def.value;
4162 if ((my_offset & 0x01) == 0x01)
4165 && sym_sec->owner != NULL
4166 && !INTERWORK_FLAG (sym_sec->owner))
4168 (*_bfd_error_handler)
4169 (_("%B(%s): warning: interworking not enabled.\n"
4170 " first occurrence: %B: arm call to thumb"),
4171 sym_sec->owner, input_bfd, name);
4175 myh->root.u.def.value = my_offset;
4177 if (info->shared || globals->root.is_relocatable_executable
4178 || globals->pic_veneer)
4180 /* For relocatable objects we can't use absolute addresses,
4181 so construct the address from a relative offset. */
4182 /* TODO: If the offset is small it's probably worth
4183 constructing the address with adds. */
4184 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
4185 s->contents + my_offset);
4186 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
4187 s->contents + my_offset + 4);
4188 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
4189 s->contents + my_offset + 8);
4190 /* Adjust the offset by 4 for the position of the add,
4191 and 8 for the pipeline offset. */
4192 ret_offset = (val - (s->output_offset
4193 + s->output_section->vma
4196 bfd_put_32 (output_bfd, ret_offset,
4197 s->contents + my_offset + 12);
4199 else if (globals->use_blx)
4201 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
4202 s->contents + my_offset);
4204 /* It's a thumb address. Add the low order bit. */
4205 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
4206 s->contents + my_offset + 4);
4210 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
4211 s->contents + my_offset);
4213 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
4214 s->contents + my_offset + 4);
4216 /* It's a thumb address. Add the low order bit. */
4217 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
4218 s->contents + my_offset + 8);
4222 BFD_ASSERT (my_offset <= globals->arm_glue_size);
4227 /* Arm code calling a Thumb function. */
4230 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
4234 asection * input_section,
4235 bfd_byte * hit_data,
4238 bfd_signed_vma addend,
4240 char **error_message)
4242 unsigned long int tmp;
4245 long int ret_offset;
4246 struct elf_link_hash_entry * myh;
4247 struct elf32_arm_link_hash_table * globals;
4249 globals = elf32_arm_hash_table (info);
4251 BFD_ASSERT (globals != NULL);
4252 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4254 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4255 ARM2THUMB_GLUE_SECTION_NAME);
4256 BFD_ASSERT (s != NULL);
4257 BFD_ASSERT (s->contents != NULL);
4258 BFD_ASSERT (s->output_section != NULL);
4260 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
4261 sym_sec, val, s, error_message);
4265 my_offset = myh->root.u.def.value;
4266 tmp = bfd_get_32 (input_bfd, hit_data);
4267 tmp = tmp & 0xFF000000;
4269 /* Somehow these are both 4 too far, so subtract 8. */
4270 ret_offset = (s->output_offset
4272 + s->output_section->vma
4273 - (input_section->output_offset
4274 + input_section->output_section->vma
4278 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
4280 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
4285 /* Populate Arm stub for an exported Thumb function. */
4288 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
4290 struct bfd_link_info * info = (struct bfd_link_info *) inf;
4292 struct elf_link_hash_entry * myh;
4293 struct elf32_arm_link_hash_entry *eh;
4294 struct elf32_arm_link_hash_table * globals;
4297 char *error_message;
4299 eh = elf32_arm_hash_entry(h);
4300 /* Allocate stubs for exported Thumb functions on v4t. */
4301 if (eh->export_glue == NULL)
4304 globals = elf32_arm_hash_table (info);
4306 BFD_ASSERT (globals != NULL);
4307 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4309 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4310 ARM2THUMB_GLUE_SECTION_NAME);
4311 BFD_ASSERT (s != NULL);
4312 BFD_ASSERT (s->contents != NULL);
4313 BFD_ASSERT (s->output_section != NULL);
4315 sec = eh->export_glue->root.u.def.section;
4317 BFD_ASSERT (sec->output_section != NULL);
4319 val = eh->export_glue->root.u.def.value + sec->output_offset
4320 + sec->output_section->vma;
4321 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
4322 h->root.u.def.section->owner,
4323 globals->obfd, sec, val, s,
4329 /* Generate Arm stubs for exported Thumb symbols. */
4331 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
4332 struct bfd_link_info *link_info)
4334 struct elf32_arm_link_hash_table * globals;
4339 globals = elf32_arm_hash_table (link_info);
4340 /* If blx is available then exported Thumb symbols are OK and there is
4342 if (globals->use_blx)
4345 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
4349 /* Some relocations map to different relocations depending on the
4350 target. Return the real relocation. */
4352 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
4358 if (globals->target1_is_rel)
4364 return globals->target2_reloc;
4371 /* Return the base VMA address which should be subtracted from real addresses
4372 when resolving @dtpoff relocation.
4373 This is PT_TLS segment p_vaddr. */
4376 dtpoff_base (struct bfd_link_info *info)
4378 /* If tls_sec is NULL, we should have signalled an error already. */
4379 if (elf_hash_table (info)->tls_sec == NULL)
4381 return elf_hash_table (info)->tls_sec->vma;
4384 /* Return the relocation value for @tpoff relocation
4385 if STT_TLS virtual address is ADDRESS. */
4388 tpoff (struct bfd_link_info *info, bfd_vma address)
4390 struct elf_link_hash_table *htab = elf_hash_table (info);
4393 /* If tls_sec is NULL, we should have signalled an error already. */
4394 if (htab->tls_sec == NULL)
4396 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
4397 return address - htab->tls_sec->vma + base;
4400 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
4401 VALUE is the relocation value. */
4403 static bfd_reloc_status_type
4404 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
4407 return bfd_reloc_overflow;
4409 value |= bfd_get_32 (abfd, data) & 0xfffff000;
4410 bfd_put_32 (abfd, value, data);
4411 return bfd_reloc_ok;
4414 /* For a given value of n, calculate the value of G_n as required to
4415 deal with group relocations. We return it in the form of an
4416 encoded constant-and-rotation, together with the final residual. If n is
4417 specified as less than zero, then final_residual is filled with the
4418 input value and no further action is performed. */
4421 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
4425 bfd_vma encoded_g_n = 0;
4426 bfd_vma residual = value; /* Also known as Y_n. */
4428 for (current_n = 0; current_n <= n; current_n++)
4432 /* Calculate which part of the value to mask. */
4439 /* Determine the most significant bit in the residual and
4440 align the resulting value to a 2-bit boundary. */
4441 for (msb = 30; msb >= 0; msb -= 2)
4442 if (residual & (3 << msb))
4445 /* The desired shift is now (msb - 6), or zero, whichever
4452 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
4453 g_n = residual & (0xff << shift);
4454 encoded_g_n = (g_n >> shift)
4455 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
4457 /* Calculate the residual for the next time around. */
4461 *final_residual = residual;
4466 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
4467 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
4469 identify_add_or_sub(bfd_vma insn)
4471 int opcode = insn & 0x1e00000;
4473 if (opcode == 1 << 23) /* ADD */
4476 if (opcode == 1 << 22) /* SUB */
4482 /* Determine if we're dealing with a Thumb-2 object. */
4484 static int using_thumb2 (struct elf32_arm_link_hash_table *globals)
4486 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4488 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
4491 /* Perform a relocation as part of a final link. */
4493 static bfd_reloc_status_type
4494 elf32_arm_final_link_relocate (reloc_howto_type * howto,
4497 asection * input_section,
4498 bfd_byte * contents,
4499 Elf_Internal_Rela * rel,
4501 struct bfd_link_info * info,
4503 const char * sym_name,
4505 struct elf_link_hash_entry * h,
4506 bfd_boolean * unresolved_reloc_p,
4507 char **error_message)
4509 unsigned long r_type = howto->type;
4510 unsigned long r_symndx;
4511 bfd_byte * hit_data = contents + rel->r_offset;
4512 bfd * dynobj = NULL;
4513 Elf_Internal_Shdr * symtab_hdr;
4514 struct elf_link_hash_entry ** sym_hashes;
4515 bfd_vma * local_got_offsets;
4516 asection * sgot = NULL;
4517 asection * splt = NULL;
4518 asection * sreloc = NULL;
4520 bfd_signed_vma signed_addend;
4521 struct elf32_arm_link_hash_table * globals;
4523 globals = elf32_arm_hash_table (info);
4525 /* Some relocation type map to different relocations depending on the
4526 target. We pick the right one here. */
4527 r_type = arm_real_reloc_type (globals, r_type);
4528 if (r_type != howto->type)
4529 howto = elf32_arm_howto_from_type (r_type);
4531 /* If the start address has been set, then set the EF_ARM_HASENTRY
4532 flag. Setting this more than once is redundant, but the cost is
4533 not too high, and it keeps the code simple.
4535 The test is done here, rather than somewhere else, because the
4536 start address is only set just before the final link commences.
4538 Note - if the user deliberately sets a start address of 0, the
4539 flag will not be set. */
4540 if (bfd_get_start_address (output_bfd) != 0)
4541 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
4543 dynobj = elf_hash_table (info)->dynobj;
4546 sgot = bfd_get_section_by_name (dynobj, ".got");
4547 splt = bfd_get_section_by_name (dynobj, ".plt");
4549 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4550 sym_hashes = elf_sym_hashes (input_bfd);
4551 local_got_offsets = elf_local_got_offsets (input_bfd);
4552 r_symndx = ELF32_R_SYM (rel->r_info);
4554 if (globals->use_rel)
4556 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
4558 if (addend & ((howto->src_mask + 1) >> 1))
4561 signed_addend &= ~ howto->src_mask;
4562 signed_addend |= addend;
4565 signed_addend = addend;
4568 addend = signed_addend = rel->r_addend;
4573 /* We don't need to find a value for this symbol. It's just a
4575 *unresolved_reloc_p = FALSE;
4576 return bfd_reloc_ok;
4579 if (!globals->vxworks_p)
4580 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4584 case R_ARM_ABS32_NOI:
4586 case R_ARM_REL32_NOI:
4592 /* Handle relocations which should use the PLT entry. ABS32/REL32
4593 will use the symbol's value, which may point to a PLT entry, but we
4594 don't need to handle that here. If we created a PLT entry, all
4595 branches in this object should go to it. */
4596 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
4597 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
4600 && h->plt.offset != (bfd_vma) -1)
4602 /* If we've created a .plt section, and assigned a PLT entry to
4603 this function, it should not be known to bind locally. If
4604 it were, we would have cleared the PLT entry. */
4605 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
4607 value = (splt->output_section->vma
4608 + splt->output_offset
4610 *unresolved_reloc_p = FALSE;
4611 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4612 contents, rel->r_offset, value,
4616 /* When generating a shared object or relocatable executable, these
4617 relocations are copied into the output file to be resolved at
4619 if ((info->shared || globals->root.is_relocatable_executable)
4620 && (input_section->flags & SEC_ALLOC)
4621 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
4622 || !SYMBOL_CALLS_LOCAL (info, h))
4624 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4625 || h->root.type != bfd_link_hash_undefweak)
4626 && r_type != R_ARM_PC24
4627 && r_type != R_ARM_CALL
4628 && r_type != R_ARM_JUMP24
4629 && r_type != R_ARM_PREL31
4630 && r_type != R_ARM_PLT32)
4632 Elf_Internal_Rela outrel;
4634 bfd_boolean skip, relocate;
4636 *unresolved_reloc_p = FALSE;
4642 name = (bfd_elf_string_from_elf_section
4644 elf_elfheader (input_bfd)->e_shstrndx,
4645 elf_section_data (input_section)->rel_hdr.sh_name));
4647 return bfd_reloc_notsupported;
4649 BFD_ASSERT (reloc_section_p (globals, name, input_section));
4651 sreloc = bfd_get_section_by_name (dynobj, name);
4652 BFD_ASSERT (sreloc != NULL);
4658 outrel.r_addend = addend;
4660 _bfd_elf_section_offset (output_bfd, info, input_section,
4662 if (outrel.r_offset == (bfd_vma) -1)
4664 else if (outrel.r_offset == (bfd_vma) -2)
4665 skip = TRUE, relocate = TRUE;
4666 outrel.r_offset += (input_section->output_section->vma
4667 + input_section->output_offset);
4670 memset (&outrel, 0, sizeof outrel);
4675 || !h->def_regular))
4676 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4681 /* This symbol is local, or marked to become local. */
4682 if (sym_flags == STT_ARM_TFUNC)
4684 if (globals->symbian_p)
4688 /* On Symbian OS, the data segment and text segement
4689 can be relocated independently. Therefore, we
4690 must indicate the segment to which this
4691 relocation is relative. The BPABI allows us to
4692 use any symbol in the right segment; we just use
4693 the section symbol as it is convenient. (We
4694 cannot use the symbol given by "h" directly as it
4695 will not appear in the dynamic symbol table.)
4697 Note that the dynamic linker ignores the section
4698 symbol value, so we don't subtract osec->vma
4699 from the emitted reloc addend. */
4701 osec = sym_sec->output_section;
4703 osec = input_section->output_section;
4704 symbol = elf_section_data (osec)->dynindx;
4707 struct elf_link_hash_table *htab = elf_hash_table (info);
4709 if ((osec->flags & SEC_READONLY) == 0
4710 && htab->data_index_section != NULL)
4711 osec = htab->data_index_section;
4713 osec = htab->text_index_section;
4714 symbol = elf_section_data (osec)->dynindx;
4716 BFD_ASSERT (symbol != 0);
4719 /* On SVR4-ish systems, the dynamic loader cannot
4720 relocate the text and data segments independently,
4721 so the symbol does not matter. */
4723 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
4724 if (globals->use_rel)
4727 outrel.r_addend += value;
4730 loc = sreloc->contents;
4731 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
4732 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4734 /* If this reloc is against an external symbol, we do not want to
4735 fiddle with the addend. Otherwise, we need to include the symbol
4736 value so that it becomes an addend for the dynamic reloc. */
4738 return bfd_reloc_ok;
4740 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4741 contents, rel->r_offset, value,
4744 else switch (r_type)
4747 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4749 case R_ARM_XPC25: /* Arm BLX instruction. */
4752 case R_ARM_PC24: /* Arm B/BL instruction */
4754 if (r_type == R_ARM_XPC25)
4756 /* Check for Arm calling Arm function. */
4757 /* FIXME: Should we translate the instruction into a BL
4758 instruction instead ? */
4759 if (sym_flags != STT_ARM_TFUNC)
4760 (*_bfd_error_handler)
4761 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
4763 h ? h->root.root.string : "(local)");
4765 else if (r_type != R_ARM_CALL || !globals->use_blx)
4767 /* Check for Arm calling Thumb function. */
4768 if (sym_flags == STT_ARM_TFUNC)
4770 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
4771 output_bfd, input_section,
4772 hit_data, sym_sec, rel->r_offset,
4773 signed_addend, value,
4775 return bfd_reloc_ok;
4777 return bfd_reloc_dangerous;
4781 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
4783 S is the address of the symbol in the relocation.
4784 P is address of the instruction being relocated.
4785 A is the addend (extracted from the instruction) in bytes.
4787 S is held in 'value'.
4788 P is the base address of the section containing the
4789 instruction plus the offset of the reloc into that
4791 (input_section->output_section->vma +
4792 input_section->output_offset +
4794 A is the addend, converted into bytes, ie:
4797 Note: None of these operations have knowledge of the pipeline
4798 size of the processor, thus it is up to the assembler to
4799 encode this information into the addend. */
4800 value -= (input_section->output_section->vma
4801 + input_section->output_offset);
4802 value -= rel->r_offset;
4803 if (globals->use_rel)
4804 value += (signed_addend << howto->size);
4806 /* RELA addends do not have to be adjusted by howto->size. */
4807 value += signed_addend;
4809 signed_addend = value;
4810 signed_addend >>= howto->rightshift;
4812 /* A branch to an undefined weak symbol is turned into a jump to
4813 the next instruction. */
4814 if (h && h->root.type == bfd_link_hash_undefweak)
4816 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
4821 /* Perform a signed range check. */
4822 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
4823 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
4824 return bfd_reloc_overflow;
4826 addend = (value & 2);
4828 value = (signed_addend & howto->dst_mask)
4829 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
4831 /* Set the H bit in the BLX instruction. */
4832 if (sym_flags == STT_ARM_TFUNC)
4837 value &= ~(bfd_vma)(1 << 24);
4839 if (r_type == R_ARM_CALL)
4841 /* Select the correct instruction (BL or BLX). */
4842 if (sym_flags == STT_ARM_TFUNC)
4846 value &= ~(bfd_vma)(1 << 28);
4855 if (sym_flags == STT_ARM_TFUNC)
4859 case R_ARM_ABS32_NOI:
4865 if (sym_flags == STT_ARM_TFUNC)
4867 value -= (input_section->output_section->vma
4868 + input_section->output_offset + rel->r_offset);
4871 case R_ARM_REL32_NOI:
4873 value -= (input_section->output_section->vma
4874 + input_section->output_offset + rel->r_offset);
4878 value -= (input_section->output_section->vma
4879 + input_section->output_offset + rel->r_offset);
4880 value += signed_addend;
4881 if (! h || h->root.type != bfd_link_hash_undefweak)
4883 /* Check for overflow */
4884 if ((value ^ (value >> 1)) & (1 << 30))
4885 return bfd_reloc_overflow;
4887 value &= 0x7fffffff;
4888 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
4889 if (sym_flags == STT_ARM_TFUNC)
4894 bfd_put_32 (input_bfd, value, hit_data);
4895 return bfd_reloc_ok;
4899 if ((long) value > 0x7f || (long) value < -0x80)
4900 return bfd_reloc_overflow;
4902 bfd_put_8 (input_bfd, value, hit_data);
4903 return bfd_reloc_ok;
4908 if ((long) value > 0x7fff || (long) value < -0x8000)
4909 return bfd_reloc_overflow;
4911 bfd_put_16 (input_bfd, value, hit_data);
4912 return bfd_reloc_ok;
4914 case R_ARM_THM_ABS5:
4915 /* Support ldr and str instructions for the thumb. */
4916 if (globals->use_rel)
4918 /* Need to refetch addend. */
4919 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4920 /* ??? Need to determine shift amount from operand size. */
4921 addend >>= howto->rightshift;
4925 /* ??? Isn't value unsigned? */
4926 if ((long) value > 0x1f || (long) value < -0x10)
4927 return bfd_reloc_overflow;
4929 /* ??? Value needs to be properly shifted into place first. */
4930 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4931 bfd_put_16 (input_bfd, value, hit_data);
4932 return bfd_reloc_ok;
4934 case R_ARM_THM_ALU_PREL_11_0:
4935 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
4938 bfd_signed_vma relocation;
4940 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4941 | bfd_get_16 (input_bfd, hit_data + 2);
4943 if (globals->use_rel)
4945 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4946 | ((insn & (1 << 26)) >> 15);
4947 if (insn & 0xf00000)
4948 signed_addend = -signed_addend;
4951 relocation = value + signed_addend;
4952 relocation -= (input_section->output_section->vma
4953 + input_section->output_offset
4956 value = llabs (relocation);
4958 if (value >= 0x1000)
4959 return bfd_reloc_overflow;
4961 insn = (insn & 0xfb0f8f00) | (value & 0xff)
4962 | ((value & 0x700) << 4)
4963 | ((value & 0x800) << 15);
4967 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4968 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4970 return bfd_reloc_ok;
4973 case R_ARM_THM_PC12:
4974 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4977 bfd_signed_vma relocation;
4979 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4980 | bfd_get_16 (input_bfd, hit_data + 2);
4982 if (globals->use_rel)
4984 signed_addend = insn & 0xfff;
4985 if (!(insn & (1 << 23)))
4986 signed_addend = -signed_addend;
4989 relocation = value + signed_addend;
4990 relocation -= (input_section->output_section->vma
4991 + input_section->output_offset
4994 value = llabs (relocation);
4996 if (value >= 0x1000)
4997 return bfd_reloc_overflow;
4999 insn = (insn & 0xff7ff000) | value;
5000 if (relocation >= 0)
5003 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5004 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5006 return bfd_reloc_ok;
5009 case R_ARM_THM_XPC22:
5010 case R_ARM_THM_CALL:
5011 /* Thumb BL (branch long instruction). */
5015 bfd_boolean overflow = FALSE;
5016 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5017 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5018 bfd_signed_vma reloc_signed_max;
5019 bfd_signed_vma reloc_signed_min;
5021 bfd_signed_vma signed_check;
5023 int thumb2 = using_thumb2 (globals);
5025 /* A branch to an undefined weak symbol is turned into a jump to
5026 the next instruction. */
5027 if (h && h->root.type == bfd_link_hash_undefweak)
5029 bfd_put_16 (input_bfd, 0xe000, hit_data);
5030 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
5031 return bfd_reloc_ok;
5034 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
5035 with Thumb-1) involving the J1 and J2 bits. */
5036 if (globals->use_rel)
5038 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
5039 bfd_vma upper = upper_insn & 0x3ff;
5040 bfd_vma lower = lower_insn & 0x7ff;
5041 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
5042 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
5043 bfd_vma i1 = j1 ^ s ? 0 : 1;
5044 bfd_vma i2 = j2 ^ s ? 0 : 1;
5046 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
5048 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
5050 signed_addend = addend;
5053 if (r_type == R_ARM_THM_XPC22)
5055 /* Check for Thumb to Thumb call. */
5056 /* FIXME: Should we translate the instruction into a BL
5057 instruction instead ? */
5058 if (sym_flags == STT_ARM_TFUNC)
5059 (*_bfd_error_handler)
5060 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
5062 h ? h->root.root.string : "(local)");
5066 /* If it is not a call to Thumb, assume call to Arm.
5067 If it is a call relative to a section name, then it is not a
5068 function call at all, but rather a long jump. Calls through
5069 the PLT do not require stubs. */
5070 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
5071 && (h == NULL || splt == NULL
5072 || h->plt.offset == (bfd_vma) -1))
5074 if (globals->use_blx)
5076 /* Convert BL to BLX. */
5077 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5079 else if (elf32_thumb_to_arm_stub
5080 (info, sym_name, input_bfd, output_bfd, input_section,
5081 hit_data, sym_sec, rel->r_offset, signed_addend, value,
5083 return bfd_reloc_ok;
5085 return bfd_reloc_dangerous;
5087 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
5089 /* Make sure this is a BL. */
5090 lower_insn |= 0x1800;
5094 /* Handle calls via the PLT. */
5095 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5097 value = (splt->output_section->vma
5098 + splt->output_offset
5100 if (globals->use_blx)
5102 /* If the Thumb BLX instruction is available, convert the
5103 BL to a BLX instruction to call the ARM-mode PLT entry. */
5104 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5107 /* Target the Thumb stub before the ARM PLT entry. */
5108 value -= PLT_THUMB_STUB_SIZE;
5109 *unresolved_reloc_p = FALSE;
5112 relocation = value + signed_addend;
5114 relocation -= (input_section->output_section->vma
5115 + input_section->output_offset
5118 check = relocation >> howto->rightshift;
5120 /* If this is a signed value, the rightshift just dropped
5121 leading 1 bits (assuming twos complement). */
5122 if ((bfd_signed_vma) relocation >= 0)
5123 signed_check = check;
5125 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5127 /* Calculate the permissable maximum and minimum values for
5128 this relocation according to whether we're relocating for
5130 bitsize = howto->bitsize;
5133 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
5134 reloc_signed_min = ~reloc_signed_max;
5136 /* Assumes two's complement. */
5137 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5140 if ((lower_insn & 0x1800) == 0x0800)
5141 /* For a BLX instruction, make sure that the relocation is rounded up
5142 to a word boundary. This follows the semantics of the instruction
5143 which specifies that bit 1 of the target address will come from bit
5144 1 of the base address. */
5145 relocation = (relocation + 2) & ~ 3;
5147 /* Put RELOCATION back into the insn. Assumes two's complement.
5148 We use the Thumb-2 encoding, which is safe even if dealing with
5149 a Thumb-1 instruction by virtue of our overflow check above. */
5150 reloc_sign = (signed_check < 0) ? 1 : 0;
5151 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
5152 | ((relocation >> 12) & 0x3ff)
5153 | (reloc_sign << 10);
5154 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
5155 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
5156 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
5157 | ((relocation >> 1) & 0x7ff);
5159 /* Put the relocated value back in the object file: */
5160 bfd_put_16 (input_bfd, upper_insn, hit_data);
5161 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5163 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5167 case R_ARM_THM_JUMP24:
5168 /* Thumb32 unconditional branch instruction. */
5171 bfd_boolean overflow = FALSE;
5172 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5173 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5174 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
5175 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5177 bfd_signed_vma signed_check;
5179 /* Need to refetch the addend, reconstruct the top three bits, and glue the
5180 two pieces together. */
5181 if (globals->use_rel)
5183 bfd_vma S = (upper_insn & 0x0400) >> 10;
5184 bfd_vma hi = (upper_insn & 0x03ff);
5185 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
5186 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
5187 bfd_vma lo = (lower_insn & 0x07ff);
5193 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
5194 signed_addend -= (1 << 24); /* Sign extend. */
5197 /* ??? Should handle interworking? GCC might someday try to
5198 use this for tail calls. */
5200 relocation = value + signed_addend;
5201 relocation -= (input_section->output_section->vma
5202 + input_section->output_offset
5205 check = relocation >> howto->rightshift;
5207 /* If this is a signed value, the rightshift just dropped
5208 leading 1 bits (assuming twos complement). */
5209 if ((bfd_signed_vma) relocation >= 0)
5210 signed_check = check;
5212 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5214 /* Assumes two's complement. */
5215 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5218 /* Put RELOCATION back into the insn. */
5220 bfd_vma S = (relocation & 0x01000000) >> 24;
5221 bfd_vma I1 = (relocation & 0x00800000) >> 23;
5222 bfd_vma I2 = (relocation & 0x00400000) >> 22;
5223 bfd_vma hi = (relocation & 0x003ff000) >> 12;
5224 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5229 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
5230 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
5233 /* Put the relocated value back in the object file: */
5234 bfd_put_16 (input_bfd, upper_insn, hit_data);
5235 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5237 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5240 case R_ARM_THM_JUMP19:
5241 /* Thumb32 conditional branch instruction. */
5244 bfd_boolean overflow = FALSE;
5245 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5246 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5247 bfd_signed_vma reloc_signed_max = 0xffffe;
5248 bfd_signed_vma reloc_signed_min = -0x100000;
5249 bfd_signed_vma signed_check;
5251 /* Need to refetch the addend, reconstruct the top three bits,
5252 and squish the two 11 bit pieces together. */
5253 if (globals->use_rel)
5255 bfd_vma S = (upper_insn & 0x0400) >> 10;
5256 bfd_vma upper = (upper_insn & 0x003f);
5257 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
5258 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
5259 bfd_vma lower = (lower_insn & 0x07ff);
5264 upper -= 0x0100; /* Sign extend. */
5266 addend = (upper << 12) | (lower << 1);
5267 signed_addend = addend;
5270 /* ??? Should handle interworking? GCC might someday try to
5271 use this for tail calls. */
5273 relocation = value + signed_addend;
5274 relocation -= (input_section->output_section->vma
5275 + input_section->output_offset
5277 signed_check = (bfd_signed_vma) relocation;
5279 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5282 /* Put RELOCATION back into the insn. */
5284 bfd_vma S = (relocation & 0x00100000) >> 20;
5285 bfd_vma J2 = (relocation & 0x00080000) >> 19;
5286 bfd_vma J1 = (relocation & 0x00040000) >> 18;
5287 bfd_vma hi = (relocation & 0x0003f000) >> 12;
5288 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5290 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
5291 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
5294 /* Put the relocated value back in the object file: */
5295 bfd_put_16 (input_bfd, upper_insn, hit_data);
5296 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5298 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5301 case R_ARM_THM_JUMP11:
5302 case R_ARM_THM_JUMP8:
5303 case R_ARM_THM_JUMP6:
5304 /* Thumb B (branch) instruction). */
5306 bfd_signed_vma relocation;
5307 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
5308 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5309 bfd_signed_vma signed_check;
5311 /* CZB cannot jump backward. */
5312 if (r_type == R_ARM_THM_JUMP6)
5313 reloc_signed_min = 0;
5315 if (globals->use_rel)
5317 /* Need to refetch addend. */
5318 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
5319 if (addend & ((howto->src_mask + 1) >> 1))
5322 signed_addend &= ~ howto->src_mask;
5323 signed_addend |= addend;
5326 signed_addend = addend;
5327 /* The value in the insn has been right shifted. We need to
5328 undo this, so that we can perform the address calculation
5329 in terms of bytes. */
5330 signed_addend <<= howto->rightshift;
5332 relocation = value + signed_addend;
5334 relocation -= (input_section->output_section->vma
5335 + input_section->output_offset
5338 relocation >>= howto->rightshift;
5339 signed_check = relocation;
5341 if (r_type == R_ARM_THM_JUMP6)
5342 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
5344 relocation &= howto->dst_mask;
5345 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
5347 bfd_put_16 (input_bfd, relocation, hit_data);
5349 /* Assumes two's complement. */
5350 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5351 return bfd_reloc_overflow;
5353 return bfd_reloc_ok;
5356 case R_ARM_ALU_PCREL7_0:
5357 case R_ARM_ALU_PCREL15_8:
5358 case R_ARM_ALU_PCREL23_15:
5363 insn = bfd_get_32 (input_bfd, hit_data);
5364 if (globals->use_rel)
5366 /* Extract the addend. */
5367 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
5368 signed_addend = addend;
5370 relocation = value + signed_addend;
5372 relocation -= (input_section->output_section->vma
5373 + input_section->output_offset
5375 insn = (insn & ~0xfff)
5376 | ((howto->bitpos << 7) & 0xf00)
5377 | ((relocation >> howto->bitpos) & 0xff);
5378 bfd_put_32 (input_bfd, value, hit_data);
5380 return bfd_reloc_ok;
5382 case R_ARM_GNU_VTINHERIT:
5383 case R_ARM_GNU_VTENTRY:
5384 return bfd_reloc_ok;
5386 case R_ARM_GOTOFF32:
5387 /* Relocation is relative to the start of the
5388 global offset table. */
5390 BFD_ASSERT (sgot != NULL);
5392 return bfd_reloc_notsupported;
5394 /* If we are addressing a Thumb function, we need to adjust the
5395 address by one, so that attempts to call the function pointer will
5396 correctly interpret it as Thumb code. */
5397 if (sym_flags == STT_ARM_TFUNC)
5400 /* Note that sgot->output_offset is not involved in this
5401 calculation. We always want the start of .got. If we
5402 define _GLOBAL_OFFSET_TABLE in a different way, as is
5403 permitted by the ABI, we might have to change this
5405 value -= sgot->output_section->vma;
5406 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5407 contents, rel->r_offset, value,
5411 /* Use global offset table as symbol value. */
5412 BFD_ASSERT (sgot != NULL);
5415 return bfd_reloc_notsupported;
5417 *unresolved_reloc_p = FALSE;
5418 value = sgot->output_section->vma;
5419 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5420 contents, rel->r_offset, value,
5424 case R_ARM_GOT_PREL:
5425 /* Relocation is to the entry for this symbol in the
5426 global offset table. */
5428 return bfd_reloc_notsupported;
5435 off = h->got.offset;
5436 BFD_ASSERT (off != (bfd_vma) -1);
5437 dyn = globals->root.dynamic_sections_created;
5439 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5441 && SYMBOL_REFERENCES_LOCAL (info, h))
5442 || (ELF_ST_VISIBILITY (h->other)
5443 && h->root.type == bfd_link_hash_undefweak))
5445 /* This is actually a static link, or it is a -Bsymbolic link
5446 and the symbol is defined locally. We must initialize this
5447 entry in the global offset table. Since the offset must
5448 always be a multiple of 4, we use the least significant bit
5449 to record whether we have initialized it already.
5451 When doing a dynamic link, we create a .rel(a).got relocation
5452 entry to initialize the value. This is done in the
5453 finish_dynamic_symbol routine. */
5458 /* If we are addressing a Thumb function, we need to
5459 adjust the address by one, so that attempts to
5460 call the function pointer will correctly
5461 interpret it as Thumb code. */
5462 if (sym_flags == STT_ARM_TFUNC)
5465 bfd_put_32 (output_bfd, value, sgot->contents + off);
5470 *unresolved_reloc_p = FALSE;
5472 value = sgot->output_offset + off;
5478 BFD_ASSERT (local_got_offsets != NULL &&
5479 local_got_offsets[r_symndx] != (bfd_vma) -1);
5481 off = local_got_offsets[r_symndx];
5483 /* The offset must always be a multiple of 4. We use the
5484 least significant bit to record whether we have already
5485 generated the necessary reloc. */
5490 /* If we are addressing a Thumb function, we need to
5491 adjust the address by one, so that attempts to
5492 call the function pointer will correctly
5493 interpret it as Thumb code. */
5494 if (sym_flags == STT_ARM_TFUNC)
5497 if (globals->use_rel)
5498 bfd_put_32 (output_bfd, value, sgot->contents + off);
5503 Elf_Internal_Rela outrel;
5506 srelgot = (bfd_get_section_by_name
5507 (dynobj, RELOC_SECTION (globals, ".got")));
5508 BFD_ASSERT (srelgot != NULL);
5510 outrel.r_addend = addend + value;
5511 outrel.r_offset = (sgot->output_section->vma
5512 + sgot->output_offset
5514 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5515 loc = srelgot->contents;
5516 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
5517 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5520 local_got_offsets[r_symndx] |= 1;
5523 value = sgot->output_offset + off;
5525 if (r_type != R_ARM_GOT32)
5526 value += sgot->output_section->vma;
5528 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5529 contents, rel->r_offset, value,
5532 case R_ARM_TLS_LDO32:
5533 value = value - dtpoff_base (info);
5535 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5536 contents, rel->r_offset, value,
5539 case R_ARM_TLS_LDM32:
5543 if (globals->sgot == NULL)
5546 off = globals->tls_ldm_got.offset;
5552 /* If we don't know the module number, create a relocation
5556 Elf_Internal_Rela outrel;
5559 if (globals->srelgot == NULL)
5562 outrel.r_addend = 0;
5563 outrel.r_offset = (globals->sgot->output_section->vma
5564 + globals->sgot->output_offset + off);
5565 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
5567 if (globals->use_rel)
5568 bfd_put_32 (output_bfd, outrel.r_addend,
5569 globals->sgot->contents + off);
5571 loc = globals->srelgot->contents;
5572 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
5573 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5576 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
5578 globals->tls_ldm_got.offset |= 1;
5581 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5582 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5584 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5585 contents, rel->r_offset, value,
5589 case R_ARM_TLS_GD32:
5590 case R_ARM_TLS_IE32:
5596 if (globals->sgot == NULL)
5603 dyn = globals->root.dynamic_sections_created;
5604 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5606 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5608 *unresolved_reloc_p = FALSE;
5611 off = h->got.offset;
5612 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
5616 if (local_got_offsets == NULL)
5618 off = local_got_offsets[r_symndx];
5619 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
5622 if (tls_type == GOT_UNKNOWN)
5629 bfd_boolean need_relocs = FALSE;
5630 Elf_Internal_Rela outrel;
5631 bfd_byte *loc = NULL;
5634 /* The GOT entries have not been initialized yet. Do it
5635 now, and emit any relocations. If both an IE GOT and a
5636 GD GOT are necessary, we emit the GD first. */
5638 if ((info->shared || indx != 0)
5640 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5641 || h->root.type != bfd_link_hash_undefweak))
5644 if (globals->srelgot == NULL)
5646 loc = globals->srelgot->contents;
5647 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
5650 if (tls_type & GOT_TLS_GD)
5654 outrel.r_addend = 0;
5655 outrel.r_offset = (globals->sgot->output_section->vma
5656 + globals->sgot->output_offset
5658 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
5660 if (globals->use_rel)
5661 bfd_put_32 (output_bfd, outrel.r_addend,
5662 globals->sgot->contents + cur_off);
5664 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5665 globals->srelgot->reloc_count++;
5666 loc += RELOC_SIZE (globals);
5669 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5670 globals->sgot->contents + cur_off + 4);
5673 outrel.r_addend = 0;
5674 outrel.r_info = ELF32_R_INFO (indx,
5675 R_ARM_TLS_DTPOFF32);
5676 outrel.r_offset += 4;
5678 if (globals->use_rel)
5679 bfd_put_32 (output_bfd, outrel.r_addend,
5680 globals->sgot->contents + cur_off + 4);
5683 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5684 globals->srelgot->reloc_count++;
5685 loc += RELOC_SIZE (globals);
5690 /* If we are not emitting relocations for a
5691 general dynamic reference, then we must be in a
5692 static link or an executable link with the
5693 symbol binding locally. Mark it as belonging
5694 to module 1, the executable. */
5695 bfd_put_32 (output_bfd, 1,
5696 globals->sgot->contents + cur_off);
5697 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5698 globals->sgot->contents + cur_off + 4);
5704 if (tls_type & GOT_TLS_IE)
5709 outrel.r_addend = value - dtpoff_base (info);
5711 outrel.r_addend = 0;
5712 outrel.r_offset = (globals->sgot->output_section->vma
5713 + globals->sgot->output_offset
5715 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
5717 if (globals->use_rel)
5718 bfd_put_32 (output_bfd, outrel.r_addend,
5719 globals->sgot->contents + cur_off);
5721 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5722 globals->srelgot->reloc_count++;
5723 loc += RELOC_SIZE (globals);
5726 bfd_put_32 (output_bfd, tpoff (info, value),
5727 globals->sgot->contents + cur_off);
5734 local_got_offsets[r_symndx] |= 1;
5737 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
5739 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5740 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5742 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5743 contents, rel->r_offset, value,
5747 case R_ARM_TLS_LE32:
5750 (*_bfd_error_handler)
5751 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
5752 input_bfd, input_section,
5753 (long) rel->r_offset, howto->name);
5757 value = tpoff (info, value);
5759 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5760 contents, rel->r_offset, value,
5764 if (globals->fix_v4bx)
5766 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5768 /* Ensure that we have a BX instruction. */
5769 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
5771 /* Preserve Rm (lowest four bits) and the condition code
5772 (highest four bits). Other bits encode MOV PC,Rm. */
5773 insn = (insn & 0xf000000f) | 0x01a0f000;
5775 bfd_put_32 (input_bfd, insn, hit_data);
5777 return bfd_reloc_ok;
5779 case R_ARM_MOVW_ABS_NC:
5780 case R_ARM_MOVT_ABS:
5781 case R_ARM_MOVW_PREL_NC:
5782 case R_ARM_MOVT_PREL:
5783 /* Until we properly support segment-base-relative addressing then
5784 we assume the segment base to be zero, as for the group relocations.
5785 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
5786 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
5787 case R_ARM_MOVW_BREL_NC:
5788 case R_ARM_MOVW_BREL:
5789 case R_ARM_MOVT_BREL:
5791 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5793 if (globals->use_rel)
5795 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
5796 signed_addend = (addend ^ 0x8000) - 0x8000;
5799 value += signed_addend;
5801 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
5802 value -= (input_section->output_section->vma
5803 + input_section->output_offset + rel->r_offset);
5805 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
5806 return bfd_reloc_overflow;
5808 if (sym_flags == STT_ARM_TFUNC)
5811 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
5812 || r_type == R_ARM_MOVT_BREL)
5816 insn |= value & 0xfff;
5817 insn |= (value & 0xf000) << 4;
5818 bfd_put_32 (input_bfd, insn, hit_data);
5820 return bfd_reloc_ok;
5822 case R_ARM_THM_MOVW_ABS_NC:
5823 case R_ARM_THM_MOVT_ABS:
5824 case R_ARM_THM_MOVW_PREL_NC:
5825 case R_ARM_THM_MOVT_PREL:
5826 /* Until we properly support segment-base-relative addressing then
5827 we assume the segment base to be zero, as for the above relocations.
5828 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
5829 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
5830 as R_ARM_THM_MOVT_ABS. */
5831 case R_ARM_THM_MOVW_BREL_NC:
5832 case R_ARM_THM_MOVW_BREL:
5833 case R_ARM_THM_MOVT_BREL:
5837 insn = bfd_get_16 (input_bfd, hit_data) << 16;
5838 insn |= bfd_get_16 (input_bfd, hit_data + 2);
5840 if (globals->use_rel)
5842 addend = ((insn >> 4) & 0xf000)
5843 | ((insn >> 15) & 0x0800)
5844 | ((insn >> 4) & 0x0700)
5846 signed_addend = (addend ^ 0x10000) - 0x10000;
5849 value += signed_addend;
5851 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
5852 value -= (input_section->output_section->vma
5853 + input_section->output_offset + rel->r_offset);
5855 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
5856 return bfd_reloc_overflow;
5858 if (sym_flags == STT_ARM_TFUNC)
5861 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
5862 || r_type == R_ARM_THM_MOVT_BREL)
5866 insn |= (value & 0xf000) << 4;
5867 insn |= (value & 0x0800) << 15;
5868 insn |= (value & 0x0700) << 4;
5869 insn |= (value & 0x00ff);
5871 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5872 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5874 return bfd_reloc_ok;
5876 case R_ARM_ALU_PC_G0_NC:
5877 case R_ARM_ALU_PC_G1_NC:
5878 case R_ARM_ALU_PC_G0:
5879 case R_ARM_ALU_PC_G1:
5880 case R_ARM_ALU_PC_G2:
5881 case R_ARM_ALU_SB_G0_NC:
5882 case R_ARM_ALU_SB_G1_NC:
5883 case R_ARM_ALU_SB_G0:
5884 case R_ARM_ALU_SB_G1:
5885 case R_ARM_ALU_SB_G2:
5887 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5888 bfd_vma pc = input_section->output_section->vma
5889 + input_section->output_offset + rel->r_offset;
5890 /* sb should be the origin of the *segment* containing the symbol.
5891 It is not clear how to obtain this OS-dependent value, so we
5892 make an arbitrary choice of zero. */
5896 bfd_signed_vma signed_value;
5899 /* Determine which group of bits to select. */
5902 case R_ARM_ALU_PC_G0_NC:
5903 case R_ARM_ALU_PC_G0:
5904 case R_ARM_ALU_SB_G0_NC:
5905 case R_ARM_ALU_SB_G0:
5909 case R_ARM_ALU_PC_G1_NC:
5910 case R_ARM_ALU_PC_G1:
5911 case R_ARM_ALU_SB_G1_NC:
5912 case R_ARM_ALU_SB_G1:
5916 case R_ARM_ALU_PC_G2:
5917 case R_ARM_ALU_SB_G2:
5925 /* If REL, extract the addend from the insn. If RELA, it will
5926 have already been fetched for us. */
5927 if (globals->use_rel)
5930 bfd_vma constant = insn & 0xff;
5931 bfd_vma rotation = (insn & 0xf00) >> 8;
5934 signed_addend = constant;
5937 /* Compensate for the fact that in the instruction, the
5938 rotation is stored in multiples of 2 bits. */
5941 /* Rotate "constant" right by "rotation" bits. */
5942 signed_addend = (constant >> rotation) |
5943 (constant << (8 * sizeof (bfd_vma) - rotation));
5946 /* Determine if the instruction is an ADD or a SUB.
5947 (For REL, this determines the sign of the addend.) */
5948 negative = identify_add_or_sub (insn);
5951 (*_bfd_error_handler)
5952 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5953 input_bfd, input_section,
5954 (long) rel->r_offset, howto->name);
5955 return bfd_reloc_overflow;
5958 signed_addend *= negative;
5961 /* Compute the value (X) to go in the place. */
5962 if (r_type == R_ARM_ALU_PC_G0_NC
5963 || r_type == R_ARM_ALU_PC_G1_NC
5964 || r_type == R_ARM_ALU_PC_G0
5965 || r_type == R_ARM_ALU_PC_G1
5966 || r_type == R_ARM_ALU_PC_G2)
5968 signed_value = value - pc + signed_addend;
5970 /* Section base relative. */
5971 signed_value = value - sb + signed_addend;
5973 /* If the target symbol is a Thumb function, then set the
5974 Thumb bit in the address. */
5975 if (sym_flags == STT_ARM_TFUNC)
5978 /* Calculate the value of the relevant G_n, in encoded
5979 constant-with-rotation format. */
5980 g_n = calculate_group_reloc_mask (llabs (signed_value), group,
5983 /* Check for overflow if required. */
5984 if ((r_type == R_ARM_ALU_PC_G0
5985 || r_type == R_ARM_ALU_PC_G1
5986 || r_type == R_ARM_ALU_PC_G2
5987 || r_type == R_ARM_ALU_SB_G0
5988 || r_type == R_ARM_ALU_SB_G1
5989 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5991 (*_bfd_error_handler)
5992 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5993 input_bfd, input_section,
5994 (long) rel->r_offset, llabs (signed_value), howto->name);
5995 return bfd_reloc_overflow;
5998 /* Mask out the value and the ADD/SUB part of the opcode; take care
5999 not to destroy the S bit. */
6002 /* Set the opcode according to whether the value to go in the
6003 place is negative. */
6004 if (signed_value < 0)
6009 /* Encode the offset. */
6012 bfd_put_32 (input_bfd, insn, hit_data);
6014 return bfd_reloc_ok;
6016 case R_ARM_LDR_PC_G0:
6017 case R_ARM_LDR_PC_G1:
6018 case R_ARM_LDR_PC_G2:
6019 case R_ARM_LDR_SB_G0:
6020 case R_ARM_LDR_SB_G1:
6021 case R_ARM_LDR_SB_G2:
6023 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6024 bfd_vma pc = input_section->output_section->vma
6025 + input_section->output_offset + rel->r_offset;
6026 bfd_vma sb = 0; /* See note above. */
6028 bfd_signed_vma signed_value;
6031 /* Determine which groups of bits to calculate. */
6034 case R_ARM_LDR_PC_G0:
6035 case R_ARM_LDR_SB_G0:
6039 case R_ARM_LDR_PC_G1:
6040 case R_ARM_LDR_SB_G1:
6044 case R_ARM_LDR_PC_G2:
6045 case R_ARM_LDR_SB_G2:
6053 /* If REL, extract the addend from the insn. If RELA, it will
6054 have already been fetched for us. */
6055 if (globals->use_rel)
6057 int negative = (insn & (1 << 23)) ? 1 : -1;
6058 signed_addend = negative * (insn & 0xfff);
6061 /* Compute the value (X) to go in the place. */
6062 if (r_type == R_ARM_LDR_PC_G0
6063 || r_type == R_ARM_LDR_PC_G1
6064 || r_type == R_ARM_LDR_PC_G2)
6066 signed_value = value - pc + signed_addend;
6068 /* Section base relative. */
6069 signed_value = value - sb + signed_addend;
6071 /* Calculate the value of the relevant G_{n-1} to obtain
6072 the residual at that stage. */
6073 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6075 /* Check for overflow. */
6076 if (residual >= 0x1000)
6078 (*_bfd_error_handler)
6079 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6080 input_bfd, input_section,
6081 (long) rel->r_offset, llabs (signed_value), howto->name);
6082 return bfd_reloc_overflow;
6085 /* Mask out the value and U bit. */
6088 /* Set the U bit if the value to go in the place is non-negative. */
6089 if (signed_value >= 0)
6092 /* Encode the offset. */
6095 bfd_put_32 (input_bfd, insn, hit_data);
6097 return bfd_reloc_ok;
6099 case R_ARM_LDRS_PC_G0:
6100 case R_ARM_LDRS_PC_G1:
6101 case R_ARM_LDRS_PC_G2:
6102 case R_ARM_LDRS_SB_G0:
6103 case R_ARM_LDRS_SB_G1:
6104 case R_ARM_LDRS_SB_G2:
6106 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6107 bfd_vma pc = input_section->output_section->vma
6108 + input_section->output_offset + rel->r_offset;
6109 bfd_vma sb = 0; /* See note above. */
6111 bfd_signed_vma signed_value;
6114 /* Determine which groups of bits to calculate. */
6117 case R_ARM_LDRS_PC_G0:
6118 case R_ARM_LDRS_SB_G0:
6122 case R_ARM_LDRS_PC_G1:
6123 case R_ARM_LDRS_SB_G1:
6127 case R_ARM_LDRS_PC_G2:
6128 case R_ARM_LDRS_SB_G2:
6136 /* If REL, extract the addend from the insn. If RELA, it will
6137 have already been fetched for us. */
6138 if (globals->use_rel)
6140 int negative = (insn & (1 << 23)) ? 1 : -1;
6141 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
6144 /* Compute the value (X) to go in the place. */
6145 if (r_type == R_ARM_LDRS_PC_G0
6146 || r_type == R_ARM_LDRS_PC_G1
6147 || r_type == R_ARM_LDRS_PC_G2)
6149 signed_value = value - pc + signed_addend;
6151 /* Section base relative. */
6152 signed_value = value - sb + signed_addend;
6154 /* Calculate the value of the relevant G_{n-1} to obtain
6155 the residual at that stage. */
6156 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6158 /* Check for overflow. */
6159 if (residual >= 0x100)
6161 (*_bfd_error_handler)
6162 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6163 input_bfd, input_section,
6164 (long) rel->r_offset, llabs (signed_value), howto->name);
6165 return bfd_reloc_overflow;
6168 /* Mask out the value and U bit. */
6171 /* Set the U bit if the value to go in the place is non-negative. */
6172 if (signed_value >= 0)
6175 /* Encode the offset. */
6176 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
6178 bfd_put_32 (input_bfd, insn, hit_data);
6180 return bfd_reloc_ok;
6182 case R_ARM_LDC_PC_G0:
6183 case R_ARM_LDC_PC_G1:
6184 case R_ARM_LDC_PC_G2:
6185 case R_ARM_LDC_SB_G0:
6186 case R_ARM_LDC_SB_G1:
6187 case R_ARM_LDC_SB_G2:
6189 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6190 bfd_vma pc = input_section->output_section->vma
6191 + input_section->output_offset + rel->r_offset;
6192 bfd_vma sb = 0; /* See note above. */
6194 bfd_signed_vma signed_value;
6197 /* Determine which groups of bits to calculate. */
6200 case R_ARM_LDC_PC_G0:
6201 case R_ARM_LDC_SB_G0:
6205 case R_ARM_LDC_PC_G1:
6206 case R_ARM_LDC_SB_G1:
6210 case R_ARM_LDC_PC_G2:
6211 case R_ARM_LDC_SB_G2:
6219 /* If REL, extract the addend from the insn. If RELA, it will
6220 have already been fetched for us. */
6221 if (globals->use_rel)
6223 int negative = (insn & (1 << 23)) ? 1 : -1;
6224 signed_addend = negative * ((insn & 0xff) << 2);
6227 /* Compute the value (X) to go in the place. */
6228 if (r_type == R_ARM_LDC_PC_G0
6229 || r_type == R_ARM_LDC_PC_G1
6230 || r_type == R_ARM_LDC_PC_G2)
6232 signed_value = value - pc + signed_addend;
6234 /* Section base relative. */
6235 signed_value = value - sb + signed_addend;
6237 /* Calculate the value of the relevant G_{n-1} to obtain
6238 the residual at that stage. */
6239 calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6241 /* Check for overflow. (The absolute value to go in the place must be
6242 divisible by four and, after having been divided by four, must
6243 fit in eight bits.) */
6244 if ((residual & 0x3) != 0 || residual >= 0x400)
6246 (*_bfd_error_handler)
6247 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6248 input_bfd, input_section,
6249 (long) rel->r_offset, llabs (signed_value), howto->name);
6250 return bfd_reloc_overflow;
6253 /* Mask out the value and U bit. */
6256 /* Set the U bit if the value to go in the place is non-negative. */
6257 if (signed_value >= 0)
6260 /* Encode the offset. */
6261 insn |= residual >> 2;
6263 bfd_put_32 (input_bfd, insn, hit_data);
6265 return bfd_reloc_ok;
6268 return bfd_reloc_notsupported;
6272 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
6274 arm_add_to_rel (bfd * abfd,
6276 reloc_howto_type * howto,
6277 bfd_signed_vma increment)
6279 bfd_signed_vma addend;
6281 if (howto->type == R_ARM_THM_CALL)
6283 int upper_insn, lower_insn;
6286 upper_insn = bfd_get_16 (abfd, address);
6287 lower_insn = bfd_get_16 (abfd, address + 2);
6288 upper = upper_insn & 0x7ff;
6289 lower = lower_insn & 0x7ff;
6291 addend = (upper << 12) | (lower << 1);
6292 addend += increment;
6295 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
6296 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
6298 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
6299 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
6305 contents = bfd_get_32 (abfd, address);
6307 /* Get the (signed) value from the instruction. */
6308 addend = contents & howto->src_mask;
6309 if (addend & ((howto->src_mask + 1) >> 1))
6311 bfd_signed_vma mask;
6314 mask &= ~ howto->src_mask;
6318 /* Add in the increment, (which is a byte value). */
6319 switch (howto->type)
6322 addend += increment;
6329 addend <<= howto->size;
6330 addend += increment;
6332 /* Should we check for overflow here ? */
6334 /* Drop any undesired bits. */
6335 addend >>= howto->rightshift;
6339 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
6341 bfd_put_32 (abfd, contents, address);
6345 #define IS_ARM_TLS_RELOC(R_TYPE) \
6346 ((R_TYPE) == R_ARM_TLS_GD32 \
6347 || (R_TYPE) == R_ARM_TLS_LDO32 \
6348 || (R_TYPE) == R_ARM_TLS_LDM32 \
6349 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
6350 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
6351 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
6352 || (R_TYPE) == R_ARM_TLS_LE32 \
6353 || (R_TYPE) == R_ARM_TLS_IE32)
6355 /* Relocate an ARM ELF section. */
6357 elf32_arm_relocate_section (bfd * output_bfd,
6358 struct bfd_link_info * info,
6360 asection * input_section,
6361 bfd_byte * contents,
6362 Elf_Internal_Rela * relocs,
6363 Elf_Internal_Sym * local_syms,
6364 asection ** local_sections)
6366 Elf_Internal_Shdr *symtab_hdr;
6367 struct elf_link_hash_entry **sym_hashes;
6368 Elf_Internal_Rela *rel;
6369 Elf_Internal_Rela *relend;
6371 struct elf32_arm_link_hash_table * globals;
6373 globals = elf32_arm_hash_table (info);
6375 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
6376 sym_hashes = elf_sym_hashes (input_bfd);
6379 relend = relocs + input_section->reloc_count;
6380 for (; rel < relend; rel++)
6383 reloc_howto_type * howto;
6384 unsigned long r_symndx;
6385 Elf_Internal_Sym * sym;
6387 struct elf_link_hash_entry * h;
6389 bfd_reloc_status_type r;
6392 bfd_boolean unresolved_reloc = FALSE;
6393 char *error_message = NULL;
6395 r_symndx = ELF32_R_SYM (rel->r_info);
6396 r_type = ELF32_R_TYPE (rel->r_info);
6397 r_type = arm_real_reloc_type (globals, r_type);
6399 if ( r_type == R_ARM_GNU_VTENTRY
6400 || r_type == R_ARM_GNU_VTINHERIT)
6403 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
6404 howto = bfd_reloc.howto;
6410 if (r_symndx < symtab_hdr->sh_info)
6412 sym = local_syms + r_symndx;
6413 sym_type = ELF32_ST_TYPE (sym->st_info);
6414 sec = local_sections[r_symndx];
6415 if (globals->use_rel)
6417 relocation = (sec->output_section->vma
6418 + sec->output_offset
6420 if (!info->relocatable
6421 && (sec->flags & SEC_MERGE)
6422 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6425 bfd_vma addend, value;
6427 if (howto->rightshift)
6429 (*_bfd_error_handler)
6430 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
6431 input_bfd, input_section,
6432 (long) rel->r_offset, howto->name);
6436 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
6438 /* Get the (signed) value from the instruction. */
6439 addend = value & howto->src_mask;
6440 if (addend & ((howto->src_mask + 1) >> 1))
6442 bfd_signed_vma mask;
6445 mask &= ~ howto->src_mask;
6450 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
6452 addend += msec->output_section->vma + msec->output_offset;
6453 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
6454 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
6458 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6464 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6465 r_symndx, symtab_hdr, sym_hashes,
6467 unresolved_reloc, warned);
6472 if (sec != NULL && elf_discarded_section (sec))
6474 /* For relocs against symbols from removed linkonce sections,
6475 or sections discarded by a linker script, we just want the
6476 section contents zeroed. Avoid any special processing. */
6477 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
6483 if (info->relocatable)
6485 /* This is a relocatable link. We don't have to change
6486 anything, unless the reloc is against a section symbol,
6487 in which case we have to adjust according to where the
6488 section symbol winds up in the output section. */
6489 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6491 if (globals->use_rel)
6492 arm_add_to_rel (input_bfd, contents + rel->r_offset,
6493 howto, (bfd_signed_vma) sec->output_offset);
6495 rel->r_addend += sec->output_offset;
6501 name = h->root.root.string;
6504 name = (bfd_elf_string_from_elf_section
6505 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6506 if (name == NULL || *name == '\0')
6507 name = bfd_section_name (input_bfd, sec);
6511 && r_type != R_ARM_NONE
6513 || h->root.type == bfd_link_hash_defined
6514 || h->root.type == bfd_link_hash_defweak)
6515 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
6517 (*_bfd_error_handler)
6518 ((sym_type == STT_TLS
6519 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6520 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6523 (long) rel->r_offset,
6528 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
6529 input_section, contents, rel,
6530 relocation, info, sec, name,
6531 (h ? ELF_ST_TYPE (h->type) :
6532 ELF_ST_TYPE (sym->st_info)), h,
6533 &unresolved_reloc, &error_message);
6535 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6536 because such sections are not SEC_ALLOC and thus ld.so will
6537 not process them. */
6538 if (unresolved_reloc
6539 && !((input_section->flags & SEC_DEBUGGING) != 0
6542 (*_bfd_error_handler)
6543 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6546 (long) rel->r_offset,
6548 h->root.root.string);
6552 if (r != bfd_reloc_ok)
6556 case bfd_reloc_overflow:
6557 /* If the overflowing reloc was to an undefined symbol,
6558 we have already printed one error message and there
6559 is no point complaining again. */
6561 h->root.type != bfd_link_hash_undefined)
6562 && (!((*info->callbacks->reloc_overflow)
6563 (info, (h ? &h->root : NULL), name, howto->name,
6564 (bfd_vma) 0, input_bfd, input_section,
6569 case bfd_reloc_undefined:
6570 if (!((*info->callbacks->undefined_symbol)
6571 (info, name, input_bfd, input_section,
6572 rel->r_offset, TRUE)))
6576 case bfd_reloc_outofrange:
6577 error_message = _("out of range");
6580 case bfd_reloc_notsupported:
6581 error_message = _("unsupported relocation");
6584 case bfd_reloc_dangerous:
6585 /* error_message should already be set. */
6589 error_message = _("unknown error");
6593 BFD_ASSERT (error_message != NULL);
6594 if (!((*info->callbacks->reloc_dangerous)
6595 (info, error_message, input_bfd, input_section,
6606 /* Set the right machine number. */
6609 elf32_arm_object_p (bfd *abfd)
6613 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
6615 if (mach != bfd_mach_arm_unknown)
6616 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6618 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6619 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
6622 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6627 /* Function to keep ARM specific flags in the ELF header. */
6630 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
6632 if (elf_flags_init (abfd)
6633 && elf_elfheader (abfd)->e_flags != flags)
6635 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6637 if (flags & EF_ARM_INTERWORK)
6638 (*_bfd_error_handler)
6639 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6643 (_("Warning: Clearing the interworking flag of %B due to outside request"),
6649 elf_elfheader (abfd)->e_flags = flags;
6650 elf_flags_init (abfd) = TRUE;
6656 /* Copy backend specific data from one object module to another. */
6659 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6664 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6665 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6668 in_flags = elf_elfheader (ibfd)->e_flags;
6669 out_flags = elf_elfheader (obfd)->e_flags;
6671 if (elf_flags_init (obfd)
6672 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
6673 && in_flags != out_flags)
6675 /* Cannot mix APCS26 and APCS32 code. */
6676 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6679 /* Cannot mix float APCS and non-float APCS code. */
6680 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6683 /* If the src and dest have different interworking flags
6684 then turn off the interworking bit. */
6685 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6687 if (out_flags & EF_ARM_INTERWORK)
6689 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6692 in_flags &= ~EF_ARM_INTERWORK;
6695 /* Likewise for PIC, though don't warn for this case. */
6696 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
6697 in_flags &= ~EF_ARM_PIC;
6700 elf_elfheader (obfd)->e_flags = in_flags;
6701 elf_flags_init (obfd) = TRUE;
6703 /* Also copy the EI_OSABI field. */
6704 elf_elfheader (obfd)->e_ident[EI_OSABI] =
6705 elf_elfheader (ibfd)->e_ident[EI_OSABI];
6707 /* Copy object attributes. */
6708 _bfd_elf_copy_obj_attributes (ibfd, obfd);
6713 /* Values for Tag_ABI_PCS_R9_use. */
6722 /* Values for Tag_ABI_PCS_RW_data. */
6725 AEABI_PCS_RW_data_absolute,
6726 AEABI_PCS_RW_data_PCrel,
6727 AEABI_PCS_RW_data_SBrel,
6728 AEABI_PCS_RW_data_unused
6731 /* Values for Tag_ABI_enum_size. */
6737 AEABI_enum_forced_wide
6740 /* Determine whether an object attribute tag takes an integer, a
6743 elf32_arm_obj_attrs_arg_type (int tag)
6745 if (tag == Tag_compatibility)
6747 else if (tag == 4 || tag == 5)
6752 return (tag & 1) != 0 ? 2 : 1;
6755 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
6756 are conflicting attributes. */
6758 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
6760 obj_attribute *in_attr;
6761 obj_attribute *out_attr;
6762 obj_attribute_list *in_list;
6763 /* Some tags have 0 = don't care, 1 = strong requirement,
6764 2 = weak requirement. */
6765 static const int order_312[3] = {3, 1, 2};
6768 if (!elf_known_obj_attributes_proc (obfd)[0].i)
6770 /* This is the first object. Copy the attributes. */
6771 _bfd_elf_copy_obj_attributes (ibfd, obfd);
6773 /* Use the Tag_null value to indicate the attributes have been
6775 elf_known_obj_attributes_proc (obfd)[0].i = 1;
6780 in_attr = elf_known_obj_attributes_proc (ibfd);
6781 out_attr = elf_known_obj_attributes_proc (obfd);
6782 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6783 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6785 /* Ignore mismatches if teh object doesn't use floating point. */
6786 if (out_attr[Tag_ABI_FP_number_model].i == 0)
6787 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6788 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6790 bfd *hasbfd, *hasnotbfd;
6792 if (in_attr[Tag_ABI_VFP_args].i)
6804 (_("ERROR: %B uses VFP register arguments, %B does not"),
6810 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
6812 if (out_attr[i].type == 0)
6813 out_attr[i].type = in_attr[i].type;
6815 /* Merge this attribute with existing attributes. */
6818 case Tag_CPU_raw_name:
6820 /* Use whichever has the greatest architecture requirements. We
6821 won't necessarily have both the above tags, so make sure input
6822 name is non-NULL. */
6823 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6825 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
6828 case Tag_ABI_optimization_goals:
6829 case Tag_ABI_FP_optimization_goals:
6830 /* Use the first value seen. */
6834 case Tag_ARM_ISA_use:
6835 case Tag_THUMB_ISA_use:
6839 /* ??? Do NEON and WMMX conflict? */
6840 case Tag_ABI_FP_rounding:
6841 case Tag_ABI_FP_denormal:
6842 case Tag_ABI_FP_exceptions:
6843 case Tag_ABI_FP_user_exceptions:
6844 case Tag_ABI_FP_number_model:
6845 case Tag_ABI_align8_preserved:
6846 case Tag_ABI_HardFP_use:
6847 case Tag_CPU_unaligned_access:
6848 case Tag_FP_HP_extension:
6849 /* Use the largest value specified. */
6850 if (in_attr[i].i > out_attr[i].i)
6851 out_attr[i].i = in_attr[i].i;
6854 case Tag_CPU_arch_profile:
6855 /* Warn if conflicting architecture profiles used. */
6856 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6859 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6860 ibfd, in_attr[i].i, out_attr[i].i);
6864 out_attr[i].i = in_attr[i].i;
6866 case Tag_PCS_config:
6867 if (out_attr[i].i == 0)
6868 out_attr[i].i = in_attr[i].i;
6869 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6871 /* It's sometimes ok to mix different configs, so this is only
6874 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6877 case Tag_ABI_PCS_R9_use:
6878 if (in_attr[i].i != out_attr[i].i
6879 && out_attr[i].i != AEABI_R9_unused
6880 && in_attr[i].i != AEABI_R9_unused)
6883 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6886 if (out_attr[i].i == AEABI_R9_unused)
6887 out_attr[i].i = in_attr[i].i;
6889 case Tag_ABI_PCS_RW_data:
6890 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6891 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6892 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6895 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6899 /* Use the smallest value specified. */
6900 if (in_attr[i].i < out_attr[i].i)
6901 out_attr[i].i = in_attr[i].i;
6903 case Tag_ABI_PCS_RO_data:
6904 /* Use the smallest value specified. */
6905 if (in_attr[i].i < out_attr[i].i)
6906 out_attr[i].i = in_attr[i].i;
6908 case Tag_ABI_PCS_GOT_use:
6909 if (in_attr[i].i > 2 || out_attr[i].i > 2
6910 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6911 out_attr[i].i = in_attr[i].i;
6913 case Tag_ABI_PCS_wchar_t:
6914 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6917 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6921 out_attr[i].i = in_attr[i].i;
6923 case Tag_ABI_align8_needed:
6924 /* ??? Check against Tag_ABI_align8_preserved. */
6925 if (in_attr[i].i > 2 || out_attr[i].i > 2
6926 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6927 out_attr[i].i = in_attr[i].i;
6929 case Tag_ABI_enum_size:
6930 if (in_attr[i].i != AEABI_enum_unused)
6932 if (out_attr[i].i == AEABI_enum_unused
6933 || out_attr[i].i == AEABI_enum_forced_wide)
6935 /* The existing object is compatible with anything.
6936 Use whatever requirements the new object has. */
6937 out_attr[i].i = in_attr[i].i;
6939 else if (in_attr[i].i != AEABI_enum_forced_wide
6940 && out_attr[i].i != in_attr[i].i
6941 && !elf32_arm_tdata (obfd)->no_enum_size_warning)
6943 const char *aeabi_enum_names[] =
6944 { "", "variable-size", "32-bit", "" };
6946 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
6947 ibfd, aeabi_enum_names[in_attr[i].i],
6948 aeabi_enum_names[out_attr[i].i]);
6952 case Tag_ABI_VFP_args:
6955 case Tag_ABI_WMMX_args:
6956 if (in_attr[i].i != out_attr[i].i)
6959 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6964 default: /* All known attributes should be explicitly covered. */
6971 /* Merge Tag_compatibility attributes and any common GNU ones. */
6972 _bfd_elf_merge_object_attributes (ibfd, obfd);
6974 /* Check for any attributes not known on ARM. */
6975 in_list = elf_other_obj_attributes_proc (ibfd);
6976 while (in_list && in_list->tag == Tag_compatibility)
6977 in_list = in_list->next;
6979 for (; in_list; in_list = in_list->next)
6981 if ((in_list->tag & 128) < 64
6982 && in_list->tag != Tag_Virtualization_use)
6985 (_("Warning: %B: Unknown EABI object attribute %d"),
6986 ibfd, in_list->tag);
6994 /* Return TRUE if the two EABI versions are incompatible. */
6997 elf32_arm_versions_compatible (unsigned iver, unsigned over)
6999 /* v4 and v5 are the same spec before and after it was released,
7000 so allow mixing them. */
7001 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
7002 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
7005 return (iver == over);
7008 /* Merge backend specific data from an object file to the output
7009 object file when linking. */
7012 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
7016 bfd_boolean flags_compatible = TRUE;
7019 /* Check if we have the same endianess. */
7020 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
7023 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7024 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7027 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
7030 /* The input BFD must have had its flags initialised. */
7031 /* The following seems bogus to me -- The flags are initialized in
7032 the assembler but I don't think an elf_flags_init field is
7033 written into the object. */
7034 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7036 in_flags = elf_elfheader (ibfd)->e_flags;
7037 out_flags = elf_elfheader (obfd)->e_flags;
7039 if (!elf_flags_init (obfd))
7041 /* If the input is the default architecture and had the default
7042 flags then do not bother setting the flags for the output
7043 architecture, instead allow future merges to do this. If no
7044 future merges ever set these flags then they will retain their
7045 uninitialised values, which surprise surprise, correspond
7046 to the default values. */
7047 if (bfd_get_arch_info (ibfd)->the_default
7048 && elf_elfheader (ibfd)->e_flags == 0)
7051 elf_flags_init (obfd) = TRUE;
7052 elf_elfheader (obfd)->e_flags = in_flags;
7054 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7055 && bfd_get_arch_info (obfd)->the_default)
7056 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
7061 /* Determine what should happen if the input ARM architecture
7062 does not match the output ARM architecture. */
7063 if (! bfd_arm_merge_machines (ibfd, obfd))
7066 /* Identical flags must be compatible. */
7067 if (in_flags == out_flags)
7070 /* Check to see if the input BFD actually contains any sections. If
7071 not, its flags may not have been initialised either, but it
7072 cannot actually cause any incompatiblity. Do not short-circuit
7073 dynamic objects; their section list may be emptied by
7074 elf_link_add_object_symbols.
7076 Also check to see if there are no code sections in the input.
7077 In this case there is no need to check for code specific flags.
7078 XXX - do we need to worry about floating-point format compatability
7079 in data sections ? */
7080 if (!(ibfd->flags & DYNAMIC))
7082 bfd_boolean null_input_bfd = TRUE;
7083 bfd_boolean only_data_sections = TRUE;
7085 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7087 /* Ignore synthetic glue sections. */
7088 if (strcmp (sec->name, ".glue_7")
7089 && strcmp (sec->name, ".glue_7t"))
7091 if ((bfd_get_section_flags (ibfd, sec)
7092 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7093 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7094 only_data_sections = FALSE;
7096 null_input_bfd = FALSE;
7101 if (null_input_bfd || only_data_sections)
7105 /* Complain about various flag mismatches. */
7106 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
7107 EF_ARM_EABI_VERSION (out_flags)))
7110 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
7112 (in_flags & EF_ARM_EABIMASK) >> 24,
7113 (out_flags & EF_ARM_EABIMASK) >> 24);
7117 /* Not sure what needs to be checked for EABI versions >= 1. */
7118 /* VxWorks libraries do not use these flags. */
7119 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
7120 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
7121 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
7123 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7126 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
7128 in_flags & EF_ARM_APCS_26 ? 26 : 32,
7129 out_flags & EF_ARM_APCS_26 ? 26 : 32);
7130 flags_compatible = FALSE;
7133 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7135 if (in_flags & EF_ARM_APCS_FLOAT)
7137 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
7141 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
7144 flags_compatible = FALSE;
7147 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
7149 if (in_flags & EF_ARM_VFP_FLOAT)
7151 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
7155 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
7158 flags_compatible = FALSE;
7161 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
7163 if (in_flags & EF_ARM_MAVERICK_FLOAT)
7165 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
7169 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
7172 flags_compatible = FALSE;
7175 #ifdef EF_ARM_SOFT_FLOAT
7176 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
7178 /* We can allow interworking between code that is VFP format
7179 layout, and uses either soft float or integer regs for
7180 passing floating point arguments and results. We already
7181 know that the APCS_FLOAT flags match; similarly for VFP
7183 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
7184 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
7186 if (in_flags & EF_ARM_SOFT_FLOAT)
7188 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
7192 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
7195 flags_compatible = FALSE;
7200 /* Interworking mismatch is only a warning. */
7201 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7203 if (in_flags & EF_ARM_INTERWORK)
7206 (_("Warning: %B supports interworking, whereas %B does not"),
7212 (_("Warning: %B does not support interworking, whereas %B does"),
7218 return flags_compatible;
7221 /* Display the flags field. */
7224 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
7226 FILE * file = (FILE *) ptr;
7227 unsigned long flags;
7229 BFD_ASSERT (abfd != NULL && ptr != NULL);
7231 /* Print normal ELF private data. */
7232 _bfd_elf_print_private_bfd_data (abfd, ptr);
7234 flags = elf_elfheader (abfd)->e_flags;
7235 /* Ignore init flag - it may not be set, despite the flags field
7236 containing valid data. */
7238 /* xgettext:c-format */
7239 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7241 switch (EF_ARM_EABI_VERSION (flags))
7243 case EF_ARM_EABI_UNKNOWN:
7244 /* The following flag bits are GNU extensions and not part of the
7245 official ARM ELF extended ABI. Hence they are only decoded if
7246 the EABI version is not set. */
7247 if (flags & EF_ARM_INTERWORK)
7248 fprintf (file, _(" [interworking enabled]"));
7250 if (flags & EF_ARM_APCS_26)
7251 fprintf (file, " [APCS-26]");
7253 fprintf (file, " [APCS-32]");
7255 if (flags & EF_ARM_VFP_FLOAT)
7256 fprintf (file, _(" [VFP float format]"));
7257 else if (flags & EF_ARM_MAVERICK_FLOAT)
7258 fprintf (file, _(" [Maverick float format]"));
7260 fprintf (file, _(" [FPA float format]"));
7262 if (flags & EF_ARM_APCS_FLOAT)
7263 fprintf (file, _(" [floats passed in float registers]"));
7265 if (flags & EF_ARM_PIC)
7266 fprintf (file, _(" [position independent]"));
7268 if (flags & EF_ARM_NEW_ABI)
7269 fprintf (file, _(" [new ABI]"));
7271 if (flags & EF_ARM_OLD_ABI)
7272 fprintf (file, _(" [old ABI]"));
7274 if (flags & EF_ARM_SOFT_FLOAT)
7275 fprintf (file, _(" [software FP]"));
7277 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
7278 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
7279 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
7280 | EF_ARM_MAVERICK_FLOAT);
7283 case EF_ARM_EABI_VER1:
7284 fprintf (file, _(" [Version1 EABI]"));
7286 if (flags & EF_ARM_SYMSARESORTED)
7287 fprintf (file, _(" [sorted symbol table]"));
7289 fprintf (file, _(" [unsorted symbol table]"));
7291 flags &= ~ EF_ARM_SYMSARESORTED;
7294 case EF_ARM_EABI_VER2:
7295 fprintf (file, _(" [Version2 EABI]"));
7297 if (flags & EF_ARM_SYMSARESORTED)
7298 fprintf (file, _(" [sorted symbol table]"));
7300 fprintf (file, _(" [unsorted symbol table]"));
7302 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
7303 fprintf (file, _(" [dynamic symbols use segment index]"));
7305 if (flags & EF_ARM_MAPSYMSFIRST)
7306 fprintf (file, _(" [mapping symbols precede others]"));
7308 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
7309 | EF_ARM_MAPSYMSFIRST);
7312 case EF_ARM_EABI_VER3:
7313 fprintf (file, _(" [Version3 EABI]"));
7316 case EF_ARM_EABI_VER4:
7317 fprintf (file, _(" [Version4 EABI]"));
7320 case EF_ARM_EABI_VER5:
7321 fprintf (file, _(" [Version5 EABI]"));
7323 if (flags & EF_ARM_BE8)
7324 fprintf (file, _(" [BE8]"));
7326 if (flags & EF_ARM_LE8)
7327 fprintf (file, _(" [LE8]"));
7329 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
7333 fprintf (file, _(" <EABI version unrecognised>"));
7337 flags &= ~ EF_ARM_EABIMASK;
7339 if (flags & EF_ARM_RELEXEC)
7340 fprintf (file, _(" [relocatable executable]"));
7342 if (flags & EF_ARM_HASENTRY)
7343 fprintf (file, _(" [has entry point]"));
7345 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
7348 fprintf (file, _("<Unrecognised flag bits set>"));
7356 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
7358 switch (ELF_ST_TYPE (elf_sym->st_info))
7361 return ELF_ST_TYPE (elf_sym->st_info);
7364 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
7365 This allows us to distinguish between data used by Thumb instructions
7366 and non-data (which is probably code) inside Thumb regions of an
7368 if (type != STT_OBJECT && type != STT_TLS)
7369 return ELF_ST_TYPE (elf_sym->st_info);
7380 elf32_arm_gc_mark_hook (asection *sec,
7381 struct bfd_link_info *info,
7382 Elf_Internal_Rela *rel,
7383 struct elf_link_hash_entry *h,
7384 Elf_Internal_Sym *sym)
7387 switch (ELF32_R_TYPE (rel->r_info))
7389 case R_ARM_GNU_VTINHERIT:
7390 case R_ARM_GNU_VTENTRY:
7394 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7397 /* Update the got entry reference counts for the section being removed. */
7400 elf32_arm_gc_sweep_hook (bfd * abfd,
7401 struct bfd_link_info * info,
7403 const Elf_Internal_Rela * relocs)
7405 Elf_Internal_Shdr *symtab_hdr;
7406 struct elf_link_hash_entry **sym_hashes;
7407 bfd_signed_vma *local_got_refcounts;
7408 const Elf_Internal_Rela *rel, *relend;
7409 struct elf32_arm_link_hash_table * globals;
7411 globals = elf32_arm_hash_table (info);
7413 elf_section_data (sec)->local_dynrel = NULL;
7415 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7416 sym_hashes = elf_sym_hashes (abfd);
7417 local_got_refcounts = elf_local_got_refcounts (abfd);
7419 relend = relocs + sec->reloc_count;
7420 for (rel = relocs; rel < relend; rel++)
7422 unsigned long r_symndx;
7423 struct elf_link_hash_entry *h = NULL;
7426 r_symndx = ELF32_R_SYM (rel->r_info);
7427 if (r_symndx >= symtab_hdr->sh_info)
7429 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7430 while (h->root.type == bfd_link_hash_indirect
7431 || h->root.type == bfd_link_hash_warning)
7432 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7435 r_type = ELF32_R_TYPE (rel->r_info);
7436 r_type = arm_real_reloc_type (globals, r_type);
7440 case R_ARM_GOT_PREL:
7441 case R_ARM_TLS_GD32:
7442 case R_ARM_TLS_IE32:
7445 if (h->got.refcount > 0)
7446 h->got.refcount -= 1;
7448 else if (local_got_refcounts != NULL)
7450 if (local_got_refcounts[r_symndx] > 0)
7451 local_got_refcounts[r_symndx] -= 1;
7455 case R_ARM_TLS_LDM32:
7456 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7460 case R_ARM_ABS32_NOI:
7462 case R_ARM_REL32_NOI:
7468 case R_ARM_THM_CALL:
7469 case R_ARM_MOVW_ABS_NC:
7470 case R_ARM_MOVT_ABS:
7471 case R_ARM_MOVW_PREL_NC:
7472 case R_ARM_MOVT_PREL:
7473 case R_ARM_THM_MOVW_ABS_NC:
7474 case R_ARM_THM_MOVT_ABS:
7475 case R_ARM_THM_MOVW_PREL_NC:
7476 case R_ARM_THM_MOVT_PREL:
7477 /* Should the interworking branches be here also? */
7481 struct elf32_arm_link_hash_entry *eh;
7482 struct elf32_arm_relocs_copied **pp;
7483 struct elf32_arm_relocs_copied *p;
7485 eh = (struct elf32_arm_link_hash_entry *) h;
7487 if (h->plt.refcount > 0)
7489 h->plt.refcount -= 1;
7490 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
7491 eh->plt_thumb_refcount--;
7494 if (r_type == R_ARM_ABS32
7495 || r_type == R_ARM_REL32
7496 || r_type == R_ARM_ABS32_NOI
7497 || r_type == R_ARM_REL32_NOI)
7499 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7501 if (p->section == sec)
7504 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7505 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
7523 /* Look through the relocs for a section during the first phase. */
7526 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7527 asection *sec, const Elf_Internal_Rela *relocs)
7529 Elf_Internal_Shdr *symtab_hdr;
7530 struct elf_link_hash_entry **sym_hashes;
7531 struct elf_link_hash_entry **sym_hashes_end;
7532 const Elf_Internal_Rela *rel;
7533 const Elf_Internal_Rela *rel_end;
7536 bfd_vma *local_got_offsets;
7537 struct elf32_arm_link_hash_table *htab;
7539 if (info->relocatable)
7542 htab = elf32_arm_hash_table (info);
7545 /* Create dynamic sections for relocatable executables so that we can
7546 copy relocations. */
7547 if (htab->root.is_relocatable_executable
7548 && ! htab->root.dynamic_sections_created)
7550 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7554 dynobj = elf_hash_table (info)->dynobj;
7555 local_got_offsets = elf_local_got_offsets (abfd);
7557 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7558 sym_hashes = elf_sym_hashes (abfd);
7559 sym_hashes_end = sym_hashes
7560 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7562 if (!elf_bad_symtab (abfd))
7563 sym_hashes_end -= symtab_hdr->sh_info;
7565 rel_end = relocs + sec->reloc_count;
7566 for (rel = relocs; rel < rel_end; rel++)
7568 struct elf_link_hash_entry *h;
7569 struct elf32_arm_link_hash_entry *eh;
7570 unsigned long r_symndx;
7573 r_symndx = ELF32_R_SYM (rel->r_info);
7574 r_type = ELF32_R_TYPE (rel->r_info);
7575 r_type = arm_real_reloc_type (htab, r_type);
7577 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7579 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7584 if (r_symndx < symtab_hdr->sh_info)
7588 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7589 while (h->root.type == bfd_link_hash_indirect
7590 || h->root.type == bfd_link_hash_warning)
7591 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7594 eh = (struct elf32_arm_link_hash_entry *) h;
7599 case R_ARM_GOT_PREL:
7600 case R_ARM_TLS_GD32:
7601 case R_ARM_TLS_IE32:
7602 /* This symbol requires a global offset table entry. */
7604 int tls_type, old_tls_type;
7608 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7609 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7610 default: tls_type = GOT_NORMAL; break;
7616 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7620 bfd_signed_vma *local_got_refcounts;
7622 /* This is a global offset table entry for a local symbol. */
7623 local_got_refcounts = elf_local_got_refcounts (abfd);
7624 if (local_got_refcounts == NULL)
7628 size = symtab_hdr->sh_info;
7629 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7630 local_got_refcounts = bfd_zalloc (abfd, size);
7631 if (local_got_refcounts == NULL)
7633 elf_local_got_refcounts (abfd) = local_got_refcounts;
7634 elf32_arm_local_got_tls_type (abfd)
7635 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7637 local_got_refcounts[r_symndx] += 1;
7638 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7641 /* We will already have issued an error message if there is a
7642 TLS / non-TLS mismatch, based on the symbol type. We don't
7643 support any linker relaxations. So just combine any TLS
7645 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7646 && tls_type != GOT_NORMAL)
7647 tls_type |= old_tls_type;
7649 if (old_tls_type != tls_type)
7652 elf32_arm_hash_entry (h)->tls_type = tls_type;
7654 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7659 case R_ARM_TLS_LDM32:
7660 if (r_type == R_ARM_TLS_LDM32)
7661 htab->tls_ldm_got.refcount++;
7664 case R_ARM_GOTOFF32:
7666 if (htab->sgot == NULL)
7668 if (htab->root.dynobj == NULL)
7669 htab->root.dynobj = abfd;
7670 if (!create_got_section (htab->root.dynobj, info))
7676 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7677 ldr __GOTT_INDEX__ offsets. */
7678 if (!htab->vxworks_p)
7683 case R_ARM_ABS32_NOI:
7685 case R_ARM_REL32_NOI:
7691 case R_ARM_THM_CALL:
7692 case R_ARM_MOVW_ABS_NC:
7693 case R_ARM_MOVT_ABS:
7694 case R_ARM_MOVW_PREL_NC:
7695 case R_ARM_MOVT_PREL:
7696 case R_ARM_THM_MOVW_ABS_NC:
7697 case R_ARM_THM_MOVT_ABS:
7698 case R_ARM_THM_MOVW_PREL_NC:
7699 case R_ARM_THM_MOVT_PREL:
7700 /* Should the interworking branches be listed here? */
7703 /* If this reloc is in a read-only section, we might
7704 need a copy reloc. We can't check reliably at this
7705 stage whether the section is read-only, as input
7706 sections have not yet been mapped to output sections.
7707 Tentatively set the flag for now, and correct in
7708 adjust_dynamic_symbol. */
7712 /* We may need a .plt entry if the function this reloc
7713 refers to is in a different object. We can't tell for
7714 sure yet, because something later might force the
7720 case R_ARM_ABS32_NOI:
7722 case R_ARM_REL32_NOI:
7723 case R_ARM_MOVW_ABS_NC:
7724 case R_ARM_MOVT_ABS:
7725 case R_ARM_MOVW_PREL_NC:
7726 case R_ARM_MOVT_PREL:
7727 case R_ARM_THM_MOVW_ABS_NC:
7728 case R_ARM_THM_MOVT_ABS:
7729 case R_ARM_THM_MOVW_PREL_NC:
7730 case R_ARM_THM_MOVT_PREL:
7737 /* If we create a PLT entry, this relocation will reference
7738 it, even if it's an ABS32 relocation. */
7739 h->plt.refcount += 1;
7741 if (r_type == R_ARM_THM_CALL)
7742 eh->plt_thumb_refcount += 1;
7745 /* If we are creating a shared library or relocatable executable,
7746 and this is a reloc against a global symbol, or a non PC
7747 relative reloc against a local symbol, then we need to copy
7748 the reloc into the shared library. However, if we are linking
7749 with -Bsymbolic, we do not need to copy a reloc against a
7750 global symbol which is defined in an object we are
7751 including in the link (i.e., DEF_REGULAR is set). At
7752 this point we have not seen all the input files, so it is
7753 possible that DEF_REGULAR is not set now but will be set
7754 later (it is never cleared). We account for that
7755 possibility below by storing information in the
7756 relocs_copied field of the hash table entry. */
7757 if ((info->shared || htab->root.is_relocatable_executable)
7758 && (sec->flags & SEC_ALLOC) != 0
7759 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
7760 || (h != NULL && ! h->needs_plt
7761 && (! info->symbolic || ! h->def_regular))))
7763 struct elf32_arm_relocs_copied *p, **head;
7765 /* When creating a shared object, we must copy these
7766 reloc types into the output file. We create a reloc
7767 section in dynobj and make room for this reloc. */
7772 name = (bfd_elf_string_from_elf_section
7774 elf_elfheader (abfd)->e_shstrndx,
7775 elf_section_data (sec)->rel_hdr.sh_name));
7779 BFD_ASSERT (reloc_section_p (htab, name, sec));
7781 sreloc = bfd_get_section_by_name (dynobj, name);
7786 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7787 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7788 if ((sec->flags & SEC_ALLOC) != 0
7789 /* BPABI objects never have dynamic
7790 relocations mapped. */
7791 && !htab->symbian_p)
7792 flags |= SEC_ALLOC | SEC_LOAD;
7793 sreloc = bfd_make_section_with_flags (dynobj,
7797 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7801 elf_section_data (sec)->sreloc = sreloc;
7804 /* If this is a global symbol, we count the number of
7805 relocations we need for this symbol. */
7808 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7812 /* Track dynamic relocs needed for local syms too.
7813 We really need local syms available to do this
7819 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7824 vpp = &elf_section_data (s)->local_dynrel;
7825 head = (struct elf32_arm_relocs_copied **) vpp;
7829 if (p == NULL || p->section != sec)
7831 bfd_size_type amt = sizeof *p;
7833 p = bfd_alloc (htab->root.dynobj, amt);
7843 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
7849 /* This relocation describes the C++ object vtable hierarchy.
7850 Reconstruct it for later use during GC. */
7851 case R_ARM_GNU_VTINHERIT:
7852 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7856 /* This relocation describes which C++ vtable entries are actually
7857 used. Record for later use during GC. */
7858 case R_ARM_GNU_VTENTRY:
7859 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7868 /* Unwinding tables are not referenced directly. This pass marks them as
7869 required if the corresponding code section is marked. */
7872 elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
7873 elf_gc_mark_hook_fn gc_mark_hook)
7876 Elf_Internal_Shdr **elf_shdrp;
7879 /* Marking EH data may cause additional code sections to be marked,
7880 requiring multiple passes. */
7885 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
7889 if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
7892 elf_shdrp = elf_elfsections (sub);
7893 for (o = sub->sections; o != NULL; o = o->next)
7895 Elf_Internal_Shdr *hdr;
7896 hdr = &elf_section_data (o)->this_hdr;
7897 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
7899 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
7902 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
7912 /* Treat mapping symbols as special target symbols. */
7915 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7917 return bfd_is_arm_special_symbol_name (sym->name,
7918 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7921 /* This is a copy of elf_find_function() from elf.c except that
7922 ARM mapping symbols are ignored when looking for function names
7923 and STT_ARM_TFUNC is considered to a function type. */
7926 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7930 const char ** filename_ptr,
7931 const char ** functionname_ptr)
7933 const char * filename = NULL;
7934 asymbol * func = NULL;
7935 bfd_vma low_func = 0;
7938 for (p = symbols; *p != NULL; p++)
7942 q = (elf_symbol_type *) *p;
7944 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7949 filename = bfd_asymbol_name (&q->symbol);
7954 /* Skip mapping symbols. */
7955 if ((q->symbol.flags & BSF_LOCAL)
7956 && bfd_is_arm_special_symbol_name (q->symbol.name,
7957 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7960 if (bfd_get_section (&q->symbol) == section
7961 && q->symbol.value >= low_func
7962 && q->symbol.value <= offset)
7964 func = (asymbol *) q;
7965 low_func = q->symbol.value;
7975 *filename_ptr = filename;
7976 if (functionname_ptr)
7977 *functionname_ptr = bfd_asymbol_name (func);
7983 /* Find the nearest line to a particular section and offset, for error
7984 reporting. This code is a duplicate of the code in elf.c, except
7985 that it uses arm_elf_find_function. */
7988 elf32_arm_find_nearest_line (bfd * abfd,
7992 const char ** filename_ptr,
7993 const char ** functionname_ptr,
7994 unsigned int * line_ptr)
7996 bfd_boolean found = FALSE;
7998 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
8000 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
8001 filename_ptr, functionname_ptr,
8003 & elf_tdata (abfd)->dwarf2_find_line_info))
8005 if (!*functionname_ptr)
8006 arm_elf_find_function (abfd, section, symbols, offset,
8007 *filename_ptr ? NULL : filename_ptr,
8013 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
8014 & found, filename_ptr,
8015 functionname_ptr, line_ptr,
8016 & elf_tdata (abfd)->line_info))
8019 if (found && (*functionname_ptr || *line_ptr))
8022 if (symbols == NULL)
8025 if (! arm_elf_find_function (abfd, section, symbols, offset,
8026 filename_ptr, functionname_ptr))
8034 elf32_arm_find_inliner_info (bfd * abfd,
8035 const char ** filename_ptr,
8036 const char ** functionname_ptr,
8037 unsigned int * line_ptr)
8040 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
8041 functionname_ptr, line_ptr,
8042 & elf_tdata (abfd)->dwarf2_find_line_info);
8046 /* Adjust a symbol defined by a dynamic object and referenced by a
8047 regular object. The current definition is in some section of the
8048 dynamic object, but we're not including those sections. We have to
8049 change the definition to something the rest of the link can
8053 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
8054 struct elf_link_hash_entry * h)
8058 struct elf32_arm_link_hash_entry * eh;
8059 struct elf32_arm_link_hash_table *globals;
8061 globals = elf32_arm_hash_table (info);
8062 dynobj = elf_hash_table (info)->dynobj;
8064 /* Make sure we know what is going on here. */
8065 BFD_ASSERT (dynobj != NULL
8067 || h->u.weakdef != NULL
8070 && !h->def_regular)));
8072 eh = (struct elf32_arm_link_hash_entry *) h;
8074 /* If this is a function, put it in the procedure linkage table. We
8075 will fill in the contents of the procedure linkage table later,
8076 when we know the address of the .got section. */
8077 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
8080 if (h->plt.refcount <= 0
8081 || SYMBOL_CALLS_LOCAL (info, h)
8082 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8083 && h->root.type == bfd_link_hash_undefweak))
8085 /* This case can occur if we saw a PLT32 reloc in an input
8086 file, but the symbol was never referred to by a dynamic
8087 object, or if all references were garbage collected. In
8088 such a case, we don't actually need to build a procedure
8089 linkage table, and we can just do a PC24 reloc instead. */
8090 h->plt.offset = (bfd_vma) -1;
8091 eh->plt_thumb_refcount = 0;
8099 /* It's possible that we incorrectly decided a .plt reloc was
8100 needed for an R_ARM_PC24 or similar reloc to a non-function sym
8101 in check_relocs. We can't decide accurately between function
8102 and non-function syms in check-relocs; Objects loaded later in
8103 the link may change h->type. So fix it now. */
8104 h->plt.offset = (bfd_vma) -1;
8105 eh->plt_thumb_refcount = 0;
8108 /* If this is a weak symbol, and there is a real definition, the
8109 processor independent code will have arranged for us to see the
8110 real definition first, and we can just use the same value. */
8111 if (h->u.weakdef != NULL)
8113 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8114 || h->u.weakdef->root.type == bfd_link_hash_defweak);
8115 h->root.u.def.section = h->u.weakdef->root.u.def.section;
8116 h->root.u.def.value = h->u.weakdef->root.u.def.value;
8120 /* If there are no non-GOT references, we do not need a copy
8122 if (!h->non_got_ref)
8125 /* This is a reference to a symbol defined by a dynamic object which
8126 is not a function. */
8128 /* If we are creating a shared library, we must presume that the
8129 only references to the symbol are via the global offset table.
8130 For such cases we need not do anything here; the relocations will
8131 be handled correctly by relocate_section. Relocatable executables
8132 can reference data in shared objects directly, so we don't need to
8133 do anything here. */
8134 if (info->shared || globals->root.is_relocatable_executable)
8139 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8140 h->root.root.string);
8144 /* We must allocate the symbol in our .dynbss section, which will
8145 become part of the .bss section of the executable. There will be
8146 an entry for this symbol in the .dynsym section. The dynamic
8147 object will contain position independent code, so all references
8148 from the dynamic object to this symbol will go through the global
8149 offset table. The dynamic linker will use the .dynsym entry to
8150 determine the address it must put in the global offset table, so
8151 both the dynamic object and the regular object will refer to the
8152 same memory location for the variable. */
8153 s = bfd_get_section_by_name (dynobj, ".dynbss");
8154 BFD_ASSERT (s != NULL);
8156 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8157 copy the initial value out of the dynamic object and into the
8158 runtime process image. We need to remember the offset into the
8159 .rel(a).bss section we are going to use. */
8160 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8164 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
8165 BFD_ASSERT (srel != NULL);
8166 srel->size += RELOC_SIZE (globals);
8170 return _bfd_elf_adjust_dynamic_copy (h, s);
8173 /* Allocate space in .plt, .got and associated reloc sections for
8177 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
8179 struct bfd_link_info *info;
8180 struct elf32_arm_link_hash_table *htab;
8181 struct elf32_arm_link_hash_entry *eh;
8182 struct elf32_arm_relocs_copied *p;
8184 eh = (struct elf32_arm_link_hash_entry *) h;
8186 if (h->root.type == bfd_link_hash_indirect)
8189 if (h->root.type == bfd_link_hash_warning)
8190 /* When warning symbols are created, they **replace** the "real"
8191 entry in the hash table, thus we never get to see the real
8192 symbol in a hash traversal. So look at it now. */
8193 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8195 info = (struct bfd_link_info *) inf;
8196 htab = elf32_arm_hash_table (info);
8198 if (htab->root.dynamic_sections_created
8199 && h->plt.refcount > 0)
8201 /* Make sure this symbol is output as a dynamic symbol.
8202 Undefined weak syms won't yet be marked as dynamic. */
8203 if (h->dynindx == -1
8204 && !h->forced_local)
8206 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8211 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8213 asection *s = htab->splt;
8215 /* If this is the first .plt entry, make room for the special
8218 s->size += htab->plt_header_size;
8220 h->plt.offset = s->size;
8222 /* If we will insert a Thumb trampoline before this PLT, leave room
8224 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8226 h->plt.offset += PLT_THUMB_STUB_SIZE;
8227 s->size += PLT_THUMB_STUB_SIZE;
8230 /* If this symbol is not defined in a regular file, and we are
8231 not generating a shared library, then set the symbol to this
8232 location in the .plt. This is required to make function
8233 pointers compare as equal between the normal executable and
8234 the shared library. */
8238 h->root.u.def.section = s;
8239 h->root.u.def.value = h->plt.offset;
8241 /* Make sure the function is not marked as Thumb, in case
8242 it is the target of an ABS32 relocation, which will
8243 point to the PLT entry. */
8244 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8245 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8248 /* Make room for this entry. */
8249 s->size += htab->plt_entry_size;
8251 if (!htab->symbian_p)
8253 /* We also need to make an entry in the .got.plt section, which
8254 will be placed in the .got section by the linker script. */
8255 eh->plt_got_offset = htab->sgotplt->size;
8256 htab->sgotplt->size += 4;
8259 /* We also need to make an entry in the .rel(a).plt section. */
8260 htab->srelplt->size += RELOC_SIZE (htab);
8262 /* VxWorks executables have a second set of relocations for
8263 each PLT entry. They go in a separate relocation section,
8264 which is processed by the kernel loader. */
8265 if (htab->vxworks_p && !info->shared)
8267 /* There is a relocation for the initial PLT entry:
8268 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
8269 if (h->plt.offset == htab->plt_header_size)
8270 htab->srelplt2->size += RELOC_SIZE (htab);
8272 /* There are two extra relocations for each subsequent
8273 PLT entry: an R_ARM_32 relocation for the GOT entry,
8274 and an R_ARM_32 relocation for the PLT entry. */
8275 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8280 h->plt.offset = (bfd_vma) -1;
8286 h->plt.offset = (bfd_vma) -1;
8290 if (h->got.refcount > 0)
8294 int tls_type = elf32_arm_hash_entry (h)->tls_type;
8297 /* Make sure this symbol is output as a dynamic symbol.
8298 Undefined weak syms won't yet be marked as dynamic. */
8299 if (h->dynindx == -1
8300 && !h->forced_local)
8302 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8306 if (!htab->symbian_p)
8309 h->got.offset = s->size;
8311 if (tls_type == GOT_UNKNOWN)
8314 if (tls_type == GOT_NORMAL)
8315 /* Non-TLS symbols need one GOT slot. */
8319 if (tls_type & GOT_TLS_GD)
8320 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
8322 if (tls_type & GOT_TLS_IE)
8323 /* R_ARM_TLS_IE32 needs one GOT slot. */
8327 dyn = htab->root.dynamic_sections_created;
8330 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8332 || !SYMBOL_REFERENCES_LOCAL (info, h)))
8335 if (tls_type != GOT_NORMAL
8336 && (info->shared || indx != 0)
8337 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8338 || h->root.type != bfd_link_hash_undefweak))
8340 if (tls_type & GOT_TLS_IE)
8341 htab->srelgot->size += RELOC_SIZE (htab);
8343 if (tls_type & GOT_TLS_GD)
8344 htab->srelgot->size += RELOC_SIZE (htab);
8346 if ((tls_type & GOT_TLS_GD) && indx != 0)
8347 htab->srelgot->size += RELOC_SIZE (htab);
8349 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8350 || h->root.type != bfd_link_hash_undefweak)
8352 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8353 htab->srelgot->size += RELOC_SIZE (htab);
8357 h->got.offset = (bfd_vma) -1;
8359 /* Allocate stubs for exported Thumb functions on v4t. */
8360 if (!htab->use_blx && h->dynindx != -1
8362 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8363 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8365 struct elf_link_hash_entry * th;
8366 struct bfd_link_hash_entry * bh;
8367 struct elf_link_hash_entry * myh;
8371 /* Create a new symbol to regist the real location of the function. */
8372 s = h->root.u.def.section;
8373 sprintf(name, "__real_%s", h->root.root.string);
8374 _bfd_generic_link_add_one_symbol (info, s->owner,
8375 name, BSF_GLOBAL, s,
8376 h->root.u.def.value,
8377 NULL, TRUE, FALSE, &bh);
8379 myh = (struct elf_link_hash_entry *) bh;
8380 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8381 myh->forced_local = 1;
8382 eh->export_glue = myh;
8383 th = record_arm_to_thumb_glue (info, h);
8384 /* Point the symbol at the stub. */
8385 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8386 h->root.u.def.section = th->root.u.def.section;
8387 h->root.u.def.value = th->root.u.def.value & ~1;
8390 if (eh->relocs_copied == NULL)
8393 /* In the shared -Bsymbolic case, discard space allocated for
8394 dynamic pc-relative relocs against symbols which turn out to be
8395 defined in regular objects. For the normal shared case, discard
8396 space for pc-relative relocs that have become local due to symbol
8397 visibility changes. */
8399 if (info->shared || htab->root.is_relocatable_executable)
8401 /* The only relocs that use pc_count are R_ARM_REL32 and
8402 R_ARM_REL32_NOI, which will appear on something like
8403 ".long foo - .". We want calls to protected symbols to resolve
8404 directly to the function rather than going via the plt. If people
8405 want function pointer comparisons to work as expected then they
8406 should avoid writing assembly like ".long foo - .". */
8407 if (SYMBOL_CALLS_LOCAL (info, h))
8409 struct elf32_arm_relocs_copied **pp;
8411 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8413 p->count -= p->pc_count;
8422 /* Also discard relocs on undefined weak syms with non-default
8424 if (eh->relocs_copied != NULL
8425 && h->root.type == bfd_link_hash_undefweak)
8427 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8428 eh->relocs_copied = NULL;
8430 /* Make sure undefined weak symbols are output as a dynamic
8432 else if (h->dynindx == -1
8433 && !h->forced_local)
8435 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8440 else if (htab->root.is_relocatable_executable && h->dynindx == -1
8441 && h->root.type == bfd_link_hash_new)
8443 /* Output absolute symbols so that we can create relocations
8444 against them. For normal symbols we output a relocation
8445 against the section that contains them. */
8446 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8453 /* For the non-shared case, discard space for relocs against
8454 symbols which turn out to need copy relocs or are not
8460 || (htab->root.dynamic_sections_created
8461 && (h->root.type == bfd_link_hash_undefweak
8462 || h->root.type == bfd_link_hash_undefined))))
8464 /* Make sure this symbol is output as a dynamic symbol.
8465 Undefined weak syms won't yet be marked as dynamic. */
8466 if (h->dynindx == -1
8467 && !h->forced_local)
8469 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8473 /* If that succeeded, we know we'll be keeping all the
8475 if (h->dynindx != -1)
8479 eh->relocs_copied = NULL;
8484 /* Finally, allocate space. */
8485 for (p = eh->relocs_copied; p != NULL; p = p->next)
8487 asection *sreloc = elf_section_data (p->section)->sreloc;
8488 sreloc->size += p->count * RELOC_SIZE (htab);
8494 /* Find any dynamic relocs that apply to read-only sections. */
8497 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8499 struct elf32_arm_link_hash_entry *eh;
8500 struct elf32_arm_relocs_copied *p;
8502 if (h->root.type == bfd_link_hash_warning)
8503 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8505 eh = (struct elf32_arm_link_hash_entry *) h;
8506 for (p = eh->relocs_copied; p != NULL; p = p->next)
8508 asection *s = p->section;
8510 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8512 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8514 info->flags |= DF_TEXTREL;
8516 /* Not an error, just cut short the traversal. */
8524 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8527 struct elf32_arm_link_hash_table *globals;
8529 globals = elf32_arm_hash_table (info);
8530 globals->byteswap_code = byteswap_code;
8533 /* Set the sizes of the dynamic sections. */
8536 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8537 struct bfd_link_info * info)
8544 struct elf32_arm_link_hash_table *htab;
8546 htab = elf32_arm_hash_table (info);
8547 dynobj = elf_hash_table (info)->dynobj;
8548 BFD_ASSERT (dynobj != NULL);
8549 check_use_blx (htab);
8551 if (elf_hash_table (info)->dynamic_sections_created)
8553 /* Set the contents of the .interp section to the interpreter. */
8554 if (info->executable)
8556 s = bfd_get_section_by_name (dynobj, ".interp");
8557 BFD_ASSERT (s != NULL);
8558 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8559 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8563 /* Set up .got offsets for local syms, and space for local dynamic
8565 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8567 bfd_signed_vma *local_got;
8568 bfd_signed_vma *end_local_got;
8569 char *local_tls_type;
8570 bfd_size_type locsymcount;
8571 Elf_Internal_Shdr *symtab_hdr;
8574 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8577 for (s = ibfd->sections; s != NULL; s = s->next)
8579 struct elf32_arm_relocs_copied *p;
8581 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
8583 if (!bfd_is_abs_section (p->section)
8584 && bfd_is_abs_section (p->section->output_section))
8586 /* Input section has been discarded, either because
8587 it is a copy of a linkonce section or due to
8588 linker script /DISCARD/, so we'll be discarding
8591 else if (p->count != 0)
8593 srel = elf_section_data (p->section)->sreloc;
8594 srel->size += p->count * RELOC_SIZE (htab);
8595 if ((p->section->output_section->flags & SEC_READONLY) != 0)
8596 info->flags |= DF_TEXTREL;
8601 local_got = elf_local_got_refcounts (ibfd);
8605 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8606 locsymcount = symtab_hdr->sh_info;
8607 end_local_got = local_got + locsymcount;
8608 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8610 srel = htab->srelgot;
8611 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8615 *local_got = s->size;
8616 if (*local_tls_type & GOT_TLS_GD)
8617 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8619 if (*local_tls_type & GOT_TLS_IE)
8621 if (*local_tls_type == GOT_NORMAL)
8624 if (info->shared || *local_tls_type == GOT_TLS_GD)
8625 srel->size += RELOC_SIZE (htab);
8628 *local_got = (bfd_vma) -1;
8632 if (htab->tls_ldm_got.refcount > 0)
8634 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8635 for R_ARM_TLS_LDM32 relocations. */
8636 htab->tls_ldm_got.offset = htab->sgot->size;
8637 htab->sgot->size += 8;
8639 htab->srelgot->size += RELOC_SIZE (htab);
8642 htab->tls_ldm_got.offset = -1;
8644 /* Allocate global sym .plt and .got entries, and space for global
8645 sym dynamic relocs. */
8646 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8648 /* Here we rummage through the found bfds to collect glue information. */
8649 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8651 /* Initialise mapping tables for code/data. */
8652 bfd_elf32_arm_init_maps (ibfd);
8654 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8655 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
8656 /* xgettext:c-format */
8657 _bfd_error_handler (_("Errors encountered processing file %s"),
8661 /* The check_relocs and adjust_dynamic_symbol entry points have
8662 determined the sizes of the various dynamic sections. Allocate
8666 for (s = dynobj->sections; s != NULL; s = s->next)
8670 if ((s->flags & SEC_LINKER_CREATED) == 0)
8673 /* It's OK to base decisions on the section name, because none
8674 of the dynobj section names depend upon the input files. */
8675 name = bfd_get_section_name (dynobj, s);
8677 if (strcmp (name, ".plt") == 0)
8679 /* Remember whether there is a PLT. */
8682 else if (CONST_STRNEQ (name, ".rel"))
8686 /* Remember whether there are any reloc sections other
8687 than .rel(a).plt and .rela.plt.unloaded. */
8688 if (s != htab->srelplt && s != htab->srelplt2)
8691 /* We use the reloc_count field as a counter if we need
8692 to copy relocs into the output file. */
8696 else if (! CONST_STRNEQ (name, ".got")
8697 && strcmp (name, ".dynbss") != 0)
8699 /* It's not one of our sections, so don't allocate space. */
8705 /* If we don't need this section, strip it from the
8706 output file. This is mostly to handle .rel(a).bss and
8707 .rel(a).plt. We must create both sections in
8708 create_dynamic_sections, because they must be created
8709 before the linker maps input sections to output
8710 sections. The linker does that before
8711 adjust_dynamic_symbol is called, and it is that
8712 function which decides whether anything needs to go
8713 into these sections. */
8714 s->flags |= SEC_EXCLUDE;
8718 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8721 /* Allocate memory for the section contents. */
8722 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8723 if (s->contents == NULL)
8727 if (elf_hash_table (info)->dynamic_sections_created)
8729 /* Add some entries to the .dynamic section. We fill in the
8730 values later, in elf32_arm_finish_dynamic_sections, but we
8731 must add the entries now so that we get the correct size for
8732 the .dynamic section. The DT_DEBUG entry is filled in by the
8733 dynamic linker and used by the debugger. */
8734 #define add_dynamic_entry(TAG, VAL) \
8735 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8737 if (info->executable)
8739 if (!add_dynamic_entry (DT_DEBUG, 0))
8745 if ( !add_dynamic_entry (DT_PLTGOT, 0)
8746 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8747 || !add_dynamic_entry (DT_PLTREL,
8748 htab->use_rel ? DT_REL : DT_RELA)
8749 || !add_dynamic_entry (DT_JMPREL, 0))
8757 if (!add_dynamic_entry (DT_REL, 0)
8758 || !add_dynamic_entry (DT_RELSZ, 0)
8759 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8764 if (!add_dynamic_entry (DT_RELA, 0)
8765 || !add_dynamic_entry (DT_RELASZ, 0)
8766 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8771 /* If any dynamic relocs apply to a read-only section,
8772 then we need a DT_TEXTREL entry. */
8773 if ((info->flags & DF_TEXTREL) == 0)
8774 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8777 if ((info->flags & DF_TEXTREL) != 0)
8779 if (!add_dynamic_entry (DT_TEXTREL, 0))
8783 #undef add_dynamic_entry
8788 /* Finish up dynamic symbol handling. We set the contents of various
8789 dynamic sections here. */
8792 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8793 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
8796 struct elf32_arm_link_hash_table *htab;
8797 struct elf32_arm_link_hash_entry *eh;
8799 dynobj = elf_hash_table (info)->dynobj;
8800 htab = elf32_arm_hash_table (info);
8801 eh = (struct elf32_arm_link_hash_entry *) h;
8803 if (h->plt.offset != (bfd_vma) -1)
8809 Elf_Internal_Rela rel;
8811 /* This symbol has an entry in the procedure linkage table. Set
8814 BFD_ASSERT (h->dynindx != -1);
8816 splt = bfd_get_section_by_name (dynobj, ".plt");
8817 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8818 BFD_ASSERT (splt != NULL && srel != NULL);
8820 /* Fill in the entry in the procedure linkage table. */
8821 if (htab->symbian_p)
8823 put_arm_insn (htab, output_bfd,
8824 elf32_arm_symbian_plt_entry[0],
8825 splt->contents + h->plt.offset);
8826 bfd_put_32 (output_bfd,
8827 elf32_arm_symbian_plt_entry[1],
8828 splt->contents + h->plt.offset + 4);
8830 /* Fill in the entry in the .rel.plt section. */
8831 rel.r_offset = (splt->output_section->vma
8832 + splt->output_offset
8833 + h->plt.offset + 4);
8834 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8836 /* Get the index in the procedure linkage table which
8837 corresponds to this symbol. This is the index of this symbol
8838 in all the symbols for which we are making plt entries. The
8839 first entry in the procedure linkage table is reserved. */
8840 plt_index = ((h->plt.offset - htab->plt_header_size)
8841 / htab->plt_entry_size);
8845 bfd_vma got_offset, got_address, plt_address;
8846 bfd_vma got_displacement;
8850 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8851 BFD_ASSERT (sgot != NULL);
8853 /* Get the offset into the .got.plt table of the entry that
8854 corresponds to this function. */
8855 got_offset = eh->plt_got_offset;
8857 /* Get the index in the procedure linkage table which
8858 corresponds to this symbol. This is the index of this symbol
8859 in all the symbols for which we are making plt entries. The
8860 first three entries in .got.plt are reserved; after that
8861 symbols appear in the same order as in .plt. */
8862 plt_index = (got_offset - 12) / 4;
8864 /* Calculate the address of the GOT entry. */
8865 got_address = (sgot->output_section->vma
8866 + sgot->output_offset
8869 /* ...and the address of the PLT entry. */
8870 plt_address = (splt->output_section->vma
8871 + splt->output_offset
8874 ptr = htab->splt->contents + h->plt.offset;
8875 if (htab->vxworks_p && info->shared)
8880 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8882 val = elf32_arm_vxworks_shared_plt_entry[i];
8884 val |= got_address - sgot->output_section->vma;
8886 val |= plt_index * RELOC_SIZE (htab);
8887 if (i == 2 || i == 5)
8888 bfd_put_32 (output_bfd, val, ptr);
8890 put_arm_insn (htab, output_bfd, val, ptr);
8893 else if (htab->vxworks_p)
8898 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8900 val = elf32_arm_vxworks_exec_plt_entry[i];
8904 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8906 val |= plt_index * RELOC_SIZE (htab);
8907 if (i == 2 || i == 5)
8908 bfd_put_32 (output_bfd, val, ptr);
8910 put_arm_insn (htab, output_bfd, val, ptr);
8913 loc = (htab->srelplt2->contents
8914 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8916 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8917 referencing the GOT for this PLT entry. */
8918 rel.r_offset = plt_address + 8;
8919 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8920 rel.r_addend = got_offset;
8921 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8922 loc += RELOC_SIZE (htab);
8924 /* Create the R_ARM_ABS32 relocation referencing the
8925 beginning of the PLT for this GOT entry. */
8926 rel.r_offset = got_address;
8927 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8929 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8933 /* Calculate the displacement between the PLT slot and the
8934 entry in the GOT. The eight-byte offset accounts for the
8935 value produced by adding to pc in the first instruction
8937 got_displacement = got_address - (plt_address + 8);
8939 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8941 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8943 put_thumb_insn (htab, output_bfd,
8944 elf32_arm_plt_thumb_stub[0], ptr - 4);
8945 put_thumb_insn (htab, output_bfd,
8946 elf32_arm_plt_thumb_stub[1], ptr - 2);
8949 put_arm_insn (htab, output_bfd,
8950 elf32_arm_plt_entry[0]
8951 | ((got_displacement & 0x0ff00000) >> 20),
8953 put_arm_insn (htab, output_bfd,
8954 elf32_arm_plt_entry[1]
8955 | ((got_displacement & 0x000ff000) >> 12),
8957 put_arm_insn (htab, output_bfd,
8958 elf32_arm_plt_entry[2]
8959 | (got_displacement & 0x00000fff),
8961 #ifdef FOUR_WORD_PLT
8962 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8966 /* Fill in the entry in the global offset table. */
8967 bfd_put_32 (output_bfd,
8968 (splt->output_section->vma
8969 + splt->output_offset),
8970 sgot->contents + got_offset);
8972 /* Fill in the entry in the .rel(a).plt section. */
8974 rel.r_offset = got_address;
8975 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8978 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8979 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8981 if (!h->def_regular)
8983 /* Mark the symbol as undefined, rather than as defined in
8984 the .plt section. Leave the value alone. */
8985 sym->st_shndx = SHN_UNDEF;
8986 /* If the symbol is weak, we do need to clear the value.
8987 Otherwise, the PLT entry would provide a definition for
8988 the symbol even if the symbol wasn't defined anywhere,
8989 and so the symbol would never be NULL. */
8990 if (!h->ref_regular_nonweak)
8995 if (h->got.offset != (bfd_vma) -1
8996 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8997 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
9001 Elf_Internal_Rela rel;
9005 /* This symbol has an entry in the global offset table. Set it
9007 sgot = bfd_get_section_by_name (dynobj, ".got");
9008 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
9009 BFD_ASSERT (sgot != NULL && srel != NULL);
9011 offset = (h->got.offset & ~(bfd_vma) 1);
9013 rel.r_offset = (sgot->output_section->vma
9014 + sgot->output_offset
9017 /* If this is a static link, or it is a -Bsymbolic link and the
9018 symbol is defined locally or was forced to be local because
9019 of a version file, we just want to emit a RELATIVE reloc.
9020 The entry in the global offset table will already have been
9021 initialized in the relocate_section function. */
9023 && SYMBOL_REFERENCES_LOCAL (info, h))
9025 BFD_ASSERT((h->got.offset & 1) != 0);
9026 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9029 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
9030 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9035 BFD_ASSERT((h->got.offset & 1) == 0);
9036 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9037 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9040 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
9041 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9047 Elf_Internal_Rela rel;
9050 /* This symbol needs a copy reloc. Set it up. */
9051 BFD_ASSERT (h->dynindx != -1
9052 && (h->root.type == bfd_link_hash_defined
9053 || h->root.type == bfd_link_hash_defweak));
9055 s = bfd_get_section_by_name (h->root.u.def.section->owner,
9056 RELOC_SECTION (htab, ".bss"));
9057 BFD_ASSERT (s != NULL);
9060 rel.r_offset = (h->root.u.def.value
9061 + h->root.u.def.section->output_section->vma
9062 + h->root.u.def.section->output_offset);
9063 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
9064 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9065 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9068 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
9069 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9070 to the ".got" section. */
9071 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
9072 || (!htab->vxworks_p && h == htab->root.hgot))
9073 sym->st_shndx = SHN_ABS;
9078 /* Finish up the dynamic sections. */
9081 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
9087 dynobj = elf_hash_table (info)->dynobj;
9089 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9090 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
9091 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9093 if (elf_hash_table (info)->dynamic_sections_created)
9096 Elf32_External_Dyn *dyncon, *dynconend;
9097 struct elf32_arm_link_hash_table *htab;
9099 htab = elf32_arm_hash_table (info);
9100 splt = bfd_get_section_by_name (dynobj, ".plt");
9101 BFD_ASSERT (splt != NULL && sdyn != NULL);
9103 dyncon = (Elf32_External_Dyn *) sdyn->contents;
9104 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9106 for (; dyncon < dynconend; dyncon++)
9108 Elf_Internal_Dyn dyn;
9112 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9123 goto get_vma_if_bpabi;
9126 goto get_vma_if_bpabi;
9129 goto get_vma_if_bpabi;
9131 name = ".gnu.version";
9132 goto get_vma_if_bpabi;
9134 name = ".gnu.version_d";
9135 goto get_vma_if_bpabi;
9137 name = ".gnu.version_r";
9138 goto get_vma_if_bpabi;
9144 name = RELOC_SECTION (htab, ".plt");
9146 s = bfd_get_section_by_name (output_bfd, name);
9147 BFD_ASSERT (s != NULL);
9148 if (!htab->symbian_p)
9149 dyn.d_un.d_ptr = s->vma;
9151 /* In the BPABI, tags in the PT_DYNAMIC section point
9152 at the file offset, not the memory address, for the
9153 convenience of the post linker. */
9154 dyn.d_un.d_ptr = s->filepos;
9155 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9159 if (htab->symbian_p)
9164 s = bfd_get_section_by_name (output_bfd,
9165 RELOC_SECTION (htab, ".plt"));
9166 BFD_ASSERT (s != NULL);
9167 dyn.d_un.d_val = s->size;
9168 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9173 if (!htab->symbian_p)
9175 /* My reading of the SVR4 ABI indicates that the
9176 procedure linkage table relocs (DT_JMPREL) should be
9177 included in the overall relocs (DT_REL). This is
9178 what Solaris does. However, UnixWare can not handle
9179 that case. Therefore, we override the DT_RELSZ entry
9180 here to make it not include the JMPREL relocs. Since
9181 the linker script arranges for .rel(a).plt to follow all
9182 other relocation sections, we don't have to worry
9183 about changing the DT_REL entry. */
9184 s = bfd_get_section_by_name (output_bfd,
9185 RELOC_SECTION (htab, ".plt"));
9187 dyn.d_un.d_val -= s->size;
9188 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9195 /* In the BPABI, the DT_REL tag must point at the file
9196 offset, not the VMA, of the first relocation
9197 section. So, we use code similar to that in
9198 elflink.c, but do not check for SHF_ALLOC on the
9199 relcoation section, since relocations sections are
9200 never allocated under the BPABI. The comments above
9201 about Unixware notwithstanding, we include all of the
9202 relocations here. */
9203 if (htab->symbian_p)
9206 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9207 ? SHT_REL : SHT_RELA);
9209 for (i = 1; i < elf_numsections (output_bfd); i++)
9211 Elf_Internal_Shdr *hdr
9212 = elf_elfsections (output_bfd)[i];
9213 if (hdr->sh_type == type)
9215 if (dyn.d_tag == DT_RELSZ
9216 || dyn.d_tag == DT_RELASZ)
9217 dyn.d_un.d_val += hdr->sh_size;
9218 else if ((ufile_ptr) hdr->sh_offset
9219 <= dyn.d_un.d_val - 1)
9220 dyn.d_un.d_val = hdr->sh_offset;
9223 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9227 /* Set the bottom bit of DT_INIT/FINI if the
9228 corresponding function is Thumb. */
9230 name = info->init_function;
9233 name = info->fini_function;
9235 /* If it wasn't set by elf_bfd_final_link
9236 then there is nothing to adjust. */
9237 if (dyn.d_un.d_val != 0)
9239 struct elf_link_hash_entry * eh;
9241 eh = elf_link_hash_lookup (elf_hash_table (info), name,
9242 FALSE, FALSE, TRUE);
9243 if (eh != (struct elf_link_hash_entry *) NULL
9244 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9246 dyn.d_un.d_val |= 1;
9247 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9254 /* Fill in the first entry in the procedure linkage table. */
9255 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
9257 const bfd_vma *plt0_entry;
9258 bfd_vma got_address, plt_address, got_displacement;
9260 /* Calculate the addresses of the GOT and PLT. */
9261 got_address = sgot->output_section->vma + sgot->output_offset;
9262 plt_address = splt->output_section->vma + splt->output_offset;
9264 if (htab->vxworks_p)
9266 /* The VxWorks GOT is relocated by the dynamic linker.
9267 Therefore, we must emit relocations rather than simply
9268 computing the values now. */
9269 Elf_Internal_Rela rel;
9271 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
9272 put_arm_insn (htab, output_bfd, plt0_entry[0],
9273 splt->contents + 0);
9274 put_arm_insn (htab, output_bfd, plt0_entry[1],
9275 splt->contents + 4);
9276 put_arm_insn (htab, output_bfd, plt0_entry[2],
9277 splt->contents + 8);
9278 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9280 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9281 rel.r_offset = plt_address + 12;
9282 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9284 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9285 htab->srelplt2->contents);
9289 got_displacement = got_address - (plt_address + 16);
9291 plt0_entry = elf32_arm_plt0_entry;
9292 put_arm_insn (htab, output_bfd, plt0_entry[0],
9293 splt->contents + 0);
9294 put_arm_insn (htab, output_bfd, plt0_entry[1],
9295 splt->contents + 4);
9296 put_arm_insn (htab, output_bfd, plt0_entry[2],
9297 splt->contents + 8);
9298 put_arm_insn (htab, output_bfd, plt0_entry[3],
9299 splt->contents + 12);
9301 #ifdef FOUR_WORD_PLT
9302 /* The displacement value goes in the otherwise-unused
9303 last word of the second entry. */
9304 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
9306 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
9311 /* UnixWare sets the entsize of .plt to 4, although that doesn't
9312 really seem like the right value. */
9313 if (splt->output_section->owner == output_bfd)
9314 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
9316 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9318 /* Correct the .rel(a).plt.unloaded relocations. They will have
9319 incorrect symbol indexes. */
9323 num_plts = ((htab->splt->size - htab->plt_header_size)
9324 / htab->plt_entry_size);
9325 p = htab->srelplt2->contents + RELOC_SIZE (htab);
9327 for (; num_plts; num_plts--)
9329 Elf_Internal_Rela rel;
9331 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9332 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9333 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9334 p += RELOC_SIZE (htab);
9336 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9337 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9338 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9339 p += RELOC_SIZE (htab);
9344 /* Fill in the first three entries in the global offset table. */
9350 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9352 bfd_put_32 (output_bfd,
9353 sdyn->output_section->vma + sdyn->output_offset,
9355 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9356 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9359 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9366 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9368 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
9369 struct elf32_arm_link_hash_table *globals;
9371 i_ehdrp = elf_elfheader (abfd);
9373 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
9374 i_ehdrp->e_ident[EI_ABIVERSION] = 0;
9378 globals = elf32_arm_hash_table (link_info);
9379 if (globals->byteswap_code)
9380 i_ehdrp->e_flags |= EF_ARM_BE8;
9384 * For EABI 5, we have to tag dynamic binaries and execs as either
9385 * soft float or hard float.
9387 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_VER5 &&
9388 (i_ehdrp->e_type == ET_DYN || i_ehdrp->e_type == ET_EXEC))
9390 bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ABI_VFP_args) ?
9391 EF_ARM_VFP_FLOAT : EF_ARM_SOFT_FLOAT;
9394 static enum elf_reloc_type_class
9395 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
9397 switch ((int) ELF32_R_TYPE (rela->r_info))
9399 case R_ARM_RELATIVE:
9400 return reloc_class_relative;
9401 case R_ARM_JUMP_SLOT:
9402 return reloc_class_plt;
9404 return reloc_class_copy;
9406 return reloc_class_normal;
9410 /* Set the right machine number for an Arm ELF file. */
9413 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
9415 if (hdr->sh_type == SHT_NOTE)
9416 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9422 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
9424 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
9427 /* Return TRUE if this is an unwinding table entry. */
9430 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9432 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9433 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
9437 /* Set the type and flags for an ARM section. We do this by
9438 the section name, which is a hack, but ought to work. */
9441 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9445 name = bfd_get_section_name (abfd, sec);
9447 if (is_arm_elf_unwind_section_name (abfd, name))
9449 hdr->sh_type = SHT_ARM_EXIDX;
9450 hdr->sh_flags |= SHF_LINK_ORDER;
9455 /* Handle an ARM specific section when reading an object file. This is
9456 called when bfd_section_from_shdr finds a section with an unknown
9460 elf32_arm_section_from_shdr (bfd *abfd,
9461 Elf_Internal_Shdr * hdr,
9465 /* There ought to be a place to keep ELF backend specific flags, but
9466 at the moment there isn't one. We just keep track of the
9467 sections by their name, instead. Fortunately, the ABI gives
9468 names for all the ARM specific sections, so we will probably get
9470 switch (hdr->sh_type)
9473 case SHT_ARM_PREEMPTMAP:
9474 case SHT_ARM_ATTRIBUTES:
9481 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
9487 /* A structure used to record a list of sections, independently
9488 of the next and prev fields in the asection structure. */
9489 typedef struct section_list
9492 struct section_list * next;
9493 struct section_list * prev;
9497 /* Unfortunately we need to keep a list of sections for which
9498 an _arm_elf_section_data structure has been allocated. This
9499 is because it is possible for functions like elf32_arm_write_section
9500 to be called on a section which has had an elf_data_structure
9501 allocated for it (and so the used_by_bfd field is valid) but
9502 for which the ARM extended version of this structure - the
9503 _arm_elf_section_data structure - has not been allocated. */
9504 static section_list * sections_with_arm_elf_section_data = NULL;
9507 record_section_with_arm_elf_section_data (asection * sec)
9509 struct section_list * entry;
9511 entry = bfd_malloc (sizeof (* entry));
9515 entry->next = sections_with_arm_elf_section_data;
9517 if (entry->next != NULL)
9518 entry->next->prev = entry;
9519 sections_with_arm_elf_section_data = entry;
9522 static struct section_list *
9523 find_arm_elf_section_entry (asection * sec)
9525 struct section_list * entry;
9526 static struct section_list * last_entry = NULL;
9528 /* This is a short cut for the typical case where the sections are added
9529 to the sections_with_arm_elf_section_data list in forward order and
9530 then looked up here in backwards order. This makes a real difference
9531 to the ld-srec/sec64k.exp linker test. */
9532 entry = sections_with_arm_elf_section_data;
9533 if (last_entry != NULL)
9535 if (last_entry->sec == sec)
9537 else if (last_entry->next != NULL
9538 && last_entry->next->sec == sec)
9539 entry = last_entry->next;
9542 for (; entry; entry = entry->next)
9543 if (entry->sec == sec)
9547 /* Record the entry prior to this one - it is the entry we are most
9548 likely to want to locate next time. Also this way if we have been
9549 called from unrecord_section_with_arm_elf_section_data() we will not
9550 be caching a pointer that is about to be freed. */
9551 last_entry = entry->prev;
9556 static _arm_elf_section_data *
9557 get_arm_elf_section_data (asection * sec)
9559 struct section_list * entry;
9561 entry = find_arm_elf_section_entry (sec);
9564 return elf32_arm_section_data (entry->sec);
9570 unrecord_section_with_arm_elf_section_data (asection * sec)
9572 struct section_list * entry;
9574 entry = find_arm_elf_section_entry (sec);
9578 if (entry->prev != NULL)
9579 entry->prev->next = entry->next;
9580 if (entry->next != NULL)
9581 entry->next->prev = entry->prev;
9582 if (entry == sections_with_arm_elf_section_data)
9583 sections_with_arm_elf_section_data = entry->next;
9592 struct bfd_link_info *info;
9595 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9596 asection *, struct elf_link_hash_entry *);
9597 } output_arch_syminfo;
9599 enum map_symbol_type
9607 /* Output a single PLT mapping symbol. */
9610 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9611 enum map_symbol_type type,
9614 static const char *names[3] = {"$a", "$t", "$d"};
9615 struct elf32_arm_link_hash_table *htab;
9616 Elf_Internal_Sym sym;
9618 htab = elf32_arm_hash_table (osi->info);
9619 sym.st_value = osi->sec->output_section->vma
9620 + osi->sec->output_offset
9624 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
9625 sym.st_shndx = osi->sec_shndx;
9626 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
9632 /* Output mapping symbols for PLT entries associated with H. */
9635 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9637 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9638 struct elf32_arm_link_hash_table *htab;
9639 struct elf32_arm_link_hash_entry *eh;
9642 htab = elf32_arm_hash_table (osi->info);
9644 if (h->root.type == bfd_link_hash_indirect)
9647 if (h->root.type == bfd_link_hash_warning)
9648 /* When warning symbols are created, they **replace** the "real"
9649 entry in the hash table, thus we never get to see the real
9650 symbol in a hash traversal. So look at it now. */
9651 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9653 if (h->plt.offset == (bfd_vma) -1)
9656 eh = (struct elf32_arm_link_hash_entry *) h;
9657 addr = h->plt.offset;
9658 if (htab->symbian_p)
9660 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9662 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9665 else if (htab->vxworks_p)
9667 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9669 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9671 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9673 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9678 bfd_boolean thumb_stub;
9680 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9683 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9686 #ifdef FOUR_WORD_PLT
9687 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9689 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9692 /* A three-word PLT with no Thumb thunk contains only Arm code,
9693 so only need to output a mapping symbol for the first PLT entry and
9694 entries with thumb thunks. */
9695 if (thumb_stub || addr == 20)
9697 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9707 /* Output mapping symbols for linker generated sections. */
9710 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9711 struct bfd_link_info *info,
9712 void *finfo, bfd_boolean (*func) (void *, const char *,
9715 struct elf_link_hash_entry *))
9717 output_arch_syminfo osi;
9718 struct elf32_arm_link_hash_table *htab;
9722 htab = elf32_arm_hash_table (info);
9723 check_use_blx(htab);
9729 /* ARM->Thumb glue. */
9730 if (htab->arm_glue_size > 0)
9732 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9733 ARM2THUMB_GLUE_SECTION_NAME);
9735 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9736 (output_bfd, osi.sec->output_section);
9737 if (info->shared || htab->root.is_relocatable_executable
9738 || htab->pic_veneer)
9739 size = ARM2THUMB_PIC_GLUE_SIZE;
9740 else if (htab->use_blx)
9741 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
9743 size = ARM2THUMB_STATIC_GLUE_SIZE;
9745 for (offset = 0; offset < htab->arm_glue_size; offset += size)
9747 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset);
9748 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
9752 /* Thumb->ARM glue. */
9753 if (htab->thumb_glue_size > 0)
9755 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9756 THUMB2ARM_GLUE_SECTION_NAME);
9758 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9759 (output_bfd, osi.sec->output_section);
9760 size = THUMB2ARM_GLUE_SIZE;
9762 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
9764 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset);
9765 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4);
9769 /* Finally, output mapping symbols for the PLT. */
9770 if (!htab->splt || htab->splt->size == 0)
9773 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9774 htab->splt->output_section);
9775 osi.sec = htab->splt;
9776 /* Output mapping symbols for the plt header. SymbianOS does not have a
9778 if (htab->vxworks_p)
9780 /* VxWorks shared libraries have no PLT header. */
9783 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9785 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9789 else if (!htab->symbian_p)
9791 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9793 #ifndef FOUR_WORD_PLT
9794 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9799 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9803 /* Allocate target specific section data. */
9806 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9808 if (!sec->used_by_bfd)
9810 _arm_elf_section_data *sdata;
9811 bfd_size_type amt = sizeof (*sdata);
9813 sdata = bfd_zalloc (abfd, amt);
9816 sec->used_by_bfd = sdata;
9819 record_section_with_arm_elf_section_data (sec);
9821 return _bfd_elf_new_section_hook (abfd, sec);
9825 /* Used to order a list of mapping symbols by address. */
9828 elf32_arm_compare_mapping (const void * a, const void * b)
9830 return ((const elf32_arm_section_map *) a)->vma
9831 > ((const elf32_arm_section_map *) b)->vma;
9835 /* Do code byteswapping. Return FALSE afterwards so that the section is
9836 written out as normal. */
9839 elf32_arm_write_section (bfd *output_bfd,
9840 struct bfd_link_info *link_info, asection *sec,
9843 int mapcount, errcount;
9844 _arm_elf_section_data *arm_data;
9845 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
9846 elf32_arm_section_map *map;
9847 elf32_vfp11_erratum_list *errnode;
9850 bfd_vma offset = sec->output_section->vma + sec->output_offset;
9854 /* If this section has not been allocated an _arm_elf_section_data
9855 structure then we cannot record anything. */
9856 arm_data = get_arm_elf_section_data (sec);
9857 if (arm_data == NULL)
9860 mapcount = arm_data->mapcount;
9861 map = arm_data->map;
9862 errcount = arm_data->erratumcount;
9866 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
9868 for (errnode = arm_data->erratumlist; errnode != 0;
9869 errnode = errnode->next)
9871 bfd_vma index = errnode->vma - offset;
9873 switch (errnode->type)
9875 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
9877 bfd_vma branch_to_veneer;
9878 /* Original condition code of instruction, plus bit mask for
9879 ARM B instruction. */
9880 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
9883 /* The instruction is before the label. */
9886 /* Above offset included in -4 below. */
9887 branch_to_veneer = errnode->u.b.veneer->vma
9890 if ((signed) branch_to_veneer < -(1 << 25)
9891 || (signed) branch_to_veneer >= (1 << 25))
9892 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9893 "range"), output_bfd);
9895 insn |= (branch_to_veneer >> 2) & 0xffffff;
9896 contents[endianflip ^ index] = insn & 0xff;
9897 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9898 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9899 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9903 case VFP11_ERRATUM_ARM_VENEER:
9905 bfd_vma branch_from_veneer;
9908 /* Take size of veneer into account. */
9909 branch_from_veneer = errnode->u.v.branch->vma
9910 - errnode->vma - 12;
9912 if ((signed) branch_from_veneer < -(1 << 25)
9913 || (signed) branch_from_veneer >= (1 << 25))
9914 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9915 "range"), output_bfd);
9917 /* Original instruction. */
9918 insn = errnode->u.v.branch->u.b.vfp_insn;
9919 contents[endianflip ^ index] = insn & 0xff;
9920 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9921 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9922 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9924 /* Branch back to insn after original insn. */
9925 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
9926 contents[endianflip ^ (index + 4)] = insn & 0xff;
9927 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
9928 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
9929 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
9942 if (globals->byteswap_code)
9944 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9947 for (i = 0; i < mapcount; i++)
9949 if (i == mapcount - 1)
9952 end = map[i + 1].vma;
9954 switch (map[i].type)
9957 /* Byte swap code words. */
9958 while (ptr + 3 < end)
9960 tmp = contents[ptr];
9961 contents[ptr] = contents[ptr + 3];
9962 contents[ptr + 3] = tmp;
9963 tmp = contents[ptr + 1];
9964 contents[ptr + 1] = contents[ptr + 2];
9965 contents[ptr + 2] = tmp;
9971 /* Byte swap code halfwords. */
9972 while (ptr + 1 < end)
9974 tmp = contents[ptr];
9975 contents[ptr] = contents[ptr + 1];
9976 contents[ptr + 1] = tmp;
9982 /* Leave data alone. */
9990 arm_data->mapcount = 0;
9991 arm_data->mapsize = 0;
9992 arm_data->map = NULL;
9993 unrecord_section_with_arm_elf_section_data (sec);
9999 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
10001 void * ignore ATTRIBUTE_UNUSED)
10003 unrecord_section_with_arm_elf_section_data (sec);
10007 elf32_arm_close_and_cleanup (bfd * abfd)
10009 if (abfd->sections)
10010 bfd_map_over_sections (abfd,
10011 unrecord_section_via_map_over_sections,
10014 return _bfd_elf_close_and_cleanup (abfd);
10018 elf32_arm_bfd_free_cached_info (bfd * abfd)
10020 if (abfd->sections)
10021 bfd_map_over_sections (abfd,
10022 unrecord_section_via_map_over_sections,
10025 return _bfd_free_cached_info (abfd);
10028 /* Display STT_ARM_TFUNC symbols as functions. */
10031 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
10034 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10036 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10037 elfsym->symbol.flags |= BSF_FUNCTION;
10041 /* Mangle thumb function symbols as we read them in. */
10044 elf32_arm_swap_symbol_in (bfd * abfd,
10047 Elf_Internal_Sym *dst)
10049 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10052 /* New EABI objects mark thumb function symbols by setting the low bit of
10053 the address. Turn these into STT_ARM_TFUNC. */
10054 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10055 && (dst->st_value & 1))
10057 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10058 dst->st_value &= ~(bfd_vma) 1;
10064 /* Mangle thumb function symbols as we write them out. */
10067 elf32_arm_swap_symbol_out (bfd *abfd,
10068 const Elf_Internal_Sym *src,
10072 Elf_Internal_Sym newsym;
10074 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10075 of the address set, as per the new EABI. We do this unconditionally
10076 because objcopy does not set the elf header flags until after
10077 it writes out the symbol table. */
10078 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10081 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
10082 if (newsym.st_shndx != SHN_UNDEF)
10084 /* Do this only for defined symbols. At link type, the static
10085 linker will simulate the work of dynamic linker of resolving
10086 symbols and will carry over the thumbness of found symbols to
10087 the output symbol table. It's not clear how it happens, but
10088 the thumbness of undefined symbols can well be different at
10089 runtime, and writing '1' for them will be confusing for users
10090 and possibly for dynamic linker itself.
10092 newsym.st_value |= 1;
10097 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10100 /* Add the PT_ARM_EXIDX program header. */
10103 elf32_arm_modify_segment_map (bfd *abfd,
10104 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10106 struct elf_segment_map *m;
10109 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10110 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10112 /* If there is already a PT_ARM_EXIDX header, then we do not
10113 want to add another one. This situation arises when running
10114 "strip"; the input binary already has the header. */
10115 m = elf_tdata (abfd)->segment_map;
10116 while (m && m->p_type != PT_ARM_EXIDX)
10120 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10123 m->p_type = PT_ARM_EXIDX;
10125 m->sections[0] = sec;
10127 m->next = elf_tdata (abfd)->segment_map;
10128 elf_tdata (abfd)->segment_map = m;
10135 /* We may add a PT_ARM_EXIDX program header. */
10138 elf32_arm_additional_program_headers (bfd *abfd,
10139 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10143 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10144 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10150 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
10152 elf32_arm_is_function_type (unsigned int type)
10154 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10157 /* We use this to override swap_symbol_in and swap_symbol_out. */
10158 const struct elf_size_info elf32_arm_size_info = {
10159 sizeof (Elf32_External_Ehdr),
10160 sizeof (Elf32_External_Phdr),
10161 sizeof (Elf32_External_Shdr),
10162 sizeof (Elf32_External_Rel),
10163 sizeof (Elf32_External_Rela),
10164 sizeof (Elf32_External_Sym),
10165 sizeof (Elf32_External_Dyn),
10166 sizeof (Elf_External_Note),
10170 ELFCLASS32, EV_CURRENT,
10171 bfd_elf32_write_out_phdrs,
10172 bfd_elf32_write_shdrs_and_ehdr,
10173 bfd_elf32_write_relocs,
10174 elf32_arm_swap_symbol_in,
10175 elf32_arm_swap_symbol_out,
10176 bfd_elf32_slurp_reloc_table,
10177 bfd_elf32_slurp_symbol_table,
10178 bfd_elf32_swap_dyn_in,
10179 bfd_elf32_swap_dyn_out,
10180 bfd_elf32_swap_reloc_in,
10181 bfd_elf32_swap_reloc_out,
10182 bfd_elf32_swap_reloca_in,
10183 bfd_elf32_swap_reloca_out
10186 #define ELF_ARCH bfd_arch_arm
10187 #define ELF_MACHINE_CODE EM_ARM
10188 #ifdef __QNXTARGET__
10189 #define ELF_MAXPAGESIZE 0x1000
10191 #define ELF_MAXPAGESIZE 0x8000
10193 #define ELF_MINPAGESIZE 0x1000
10194 #define ELF_COMMONPAGESIZE 0x1000
10196 #define bfd_elf32_mkobject elf32_arm_mkobject
10198 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
10199 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
10200 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
10201 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
10202 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
10203 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
10204 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
10205 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
10206 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
10207 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
10208 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
10209 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
10210 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
10212 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
10213 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
10214 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
10215 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
10216 #define elf_backend_check_relocs elf32_arm_check_relocs
10217 #define elf_backend_relocate_section elf32_arm_relocate_section
10218 #define elf_backend_write_section elf32_arm_write_section
10219 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
10220 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
10221 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
10222 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
10223 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
10224 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
10225 #define elf_backend_post_process_headers elf32_arm_post_process_headers
10226 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
10227 #define elf_backend_object_p elf32_arm_object_p
10228 #define elf_backend_section_flags elf32_arm_section_flags
10229 #define elf_backend_fake_sections elf32_arm_fake_sections
10230 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
10231 #define elf_backend_final_write_processing elf32_arm_final_write_processing
10232 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
10233 #define elf_backend_symbol_processing elf32_arm_symbol_processing
10234 #define elf_backend_size_info elf32_arm_size_info
10235 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
10236 #define elf_backend_additional_program_headers \
10237 elf32_arm_additional_program_headers
10238 #define elf_backend_output_arch_local_syms \
10239 elf32_arm_output_arch_local_syms
10240 #define elf_backend_begin_write_processing \
10241 elf32_arm_begin_write_processing
10242 #define elf_backend_is_function_type elf32_arm_is_function_type
10244 #define elf_backend_can_refcount 1
10245 #define elf_backend_can_gc_sections 1
10246 #define elf_backend_plt_readonly 1
10247 #define elf_backend_want_got_plt 1
10248 #define elf_backend_want_plt_sym 0
10249 #define elf_backend_may_use_rel_p 1
10250 #define elf_backend_may_use_rela_p 0
10251 #define elf_backend_default_use_rela_p 0
10253 #define elf_backend_got_header_size 12
10255 #undef elf_backend_obj_attrs_vendor
10256 #define elf_backend_obj_attrs_vendor "aeabi"
10257 #undef elf_backend_obj_attrs_section
10258 #define elf_backend_obj_attrs_section ".ARM.attributes"
10259 #undef elf_backend_obj_attrs_arg_type
10260 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
10261 #undef elf_backend_obj_attrs_section_type
10262 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
10264 #include "elf32-target.h"
10266 /* VxWorks Targets */
10268 #undef TARGET_LITTLE_SYM
10269 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
10270 #undef TARGET_LITTLE_NAME
10271 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
10272 #undef TARGET_BIG_SYM
10273 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
10274 #undef TARGET_BIG_NAME
10275 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
10277 /* Like elf32_arm_link_hash_table_create -- but overrides
10278 appropriately for VxWorks. */
10279 static struct bfd_link_hash_table *
10280 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10282 struct bfd_link_hash_table *ret;
10284 ret = elf32_arm_link_hash_table_create (abfd);
10287 struct elf32_arm_link_hash_table *htab
10288 = (struct elf32_arm_link_hash_table *) ret;
10290 htab->vxworks_p = 1;
10296 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10298 elf32_arm_final_write_processing (abfd, linker);
10299 elf_vxworks_final_write_processing (abfd, linker);
10303 #define elf32_bed elf32_arm_vxworks_bed
10305 #undef bfd_elf32_bfd_link_hash_table_create
10306 #define bfd_elf32_bfd_link_hash_table_create \
10307 elf32_arm_vxworks_link_hash_table_create
10308 #undef elf_backend_add_symbol_hook
10309 #define elf_backend_add_symbol_hook \
10310 elf_vxworks_add_symbol_hook
10311 #undef elf_backend_final_write_processing
10312 #define elf_backend_final_write_processing \
10313 elf32_arm_vxworks_final_write_processing
10314 #undef elf_backend_emit_relocs
10315 #define elf_backend_emit_relocs \
10316 elf_vxworks_emit_relocs
10318 #undef elf_backend_may_use_rel_p
10319 #define elf_backend_may_use_rel_p 0
10320 #undef elf_backend_may_use_rela_p
10321 #define elf_backend_may_use_rela_p 1
10322 #undef elf_backend_default_use_rela_p
10323 #define elf_backend_default_use_rela_p 1
10324 #undef elf_backend_want_plt_sym
10325 #define elf_backend_want_plt_sym 1
10326 #undef ELF_MAXPAGESIZE
10327 #define ELF_MAXPAGESIZE 0x1000
10329 #include "elf32-target.h"
10332 /* Symbian OS Targets */
10334 #undef TARGET_LITTLE_SYM
10335 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
10336 #undef TARGET_LITTLE_NAME
10337 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
10338 #undef TARGET_BIG_SYM
10339 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
10340 #undef TARGET_BIG_NAME
10341 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
10343 /* Like elf32_arm_link_hash_table_create -- but overrides
10344 appropriately for Symbian OS. */
10345 static struct bfd_link_hash_table *
10346 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10348 struct bfd_link_hash_table *ret;
10350 ret = elf32_arm_link_hash_table_create (abfd);
10353 struct elf32_arm_link_hash_table *htab
10354 = (struct elf32_arm_link_hash_table *)ret;
10355 /* There is no PLT header for Symbian OS. */
10356 htab->plt_header_size = 0;
10357 /* The PLT entries are each three instructions. */
10358 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10359 htab->symbian_p = 1;
10360 /* Symbian uses armv5t or above, so use_blx is always true. */
10362 htab->root.is_relocatable_executable = 1;
10367 static const struct bfd_elf_special_section
10368 elf32_arm_symbian_special_sections[] =
10370 /* In a BPABI executable, the dynamic linking sections do not go in
10371 the loadable read-only segment. The post-linker may wish to
10372 refer to these sections, but they are not part of the final
10374 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
10375 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
10376 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
10377 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
10378 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
10379 /* These sections do not need to be writable as the SymbianOS
10380 postlinker will arrange things so that no dynamic relocation is
10382 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
10383 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
10384 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10385 { NULL, 0, 0, 0, 0 }
10389 elf32_arm_symbian_begin_write_processing (bfd *abfd,
10390 struct bfd_link_info *link_info)
10392 /* BPABI objects are never loaded directly by an OS kernel; they are
10393 processed by a postlinker first, into an OS-specific format. If
10394 the D_PAGED bit is set on the file, BFD will align segments on
10395 page boundaries, so that an OS can directly map the file. With
10396 BPABI objects, that just results in wasted space. In addition,
10397 because we clear the D_PAGED bit, map_sections_to_segments will
10398 recognize that the program headers should not be mapped into any
10399 loadable segment. */
10400 abfd->flags &= ~D_PAGED;
10401 elf32_arm_begin_write_processing(abfd, link_info);
10405 elf32_arm_symbian_modify_segment_map (bfd *abfd,
10406 struct bfd_link_info *info)
10408 struct elf_segment_map *m;
10411 /* BPABI shared libraries and executables should have a PT_DYNAMIC
10412 segment. However, because the .dynamic section is not marked
10413 with SEC_LOAD, the generic ELF code will not create such a
10415 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10418 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10419 if (m->p_type == PT_DYNAMIC)
10424 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10425 m->next = elf_tdata (abfd)->segment_map;
10426 elf_tdata (abfd)->segment_map = m;
10430 /* Also call the generic arm routine. */
10431 return elf32_arm_modify_segment_map (abfd, info);
10435 #define elf32_bed elf32_arm_symbian_bed
10437 /* The dynamic sections are not allocated on SymbianOS; the postlinker
10438 will process them and then discard them. */
10439 #undef ELF_DYNAMIC_SEC_FLAGS
10440 #define ELF_DYNAMIC_SEC_FLAGS \
10441 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10443 #undef bfd_elf32_bfd_link_hash_table_create
10444 #define bfd_elf32_bfd_link_hash_table_create \
10445 elf32_arm_symbian_link_hash_table_create
10446 #undef elf_backend_add_symbol_hook
10448 #undef elf_backend_special_sections
10449 #define elf_backend_special_sections elf32_arm_symbian_special_sections
10451 #undef elf_backend_begin_write_processing
10452 #define elf_backend_begin_write_processing \
10453 elf32_arm_symbian_begin_write_processing
10454 #undef elf_backend_final_write_processing
10455 #define elf_backend_final_write_processing \
10456 elf32_arm_final_write_processing
10457 #undef elf_backend_emit_relocs
10459 #undef elf_backend_modify_segment_map
10460 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10462 /* There is no .got section for BPABI objects, and hence no header. */
10463 #undef elf_backend_got_header_size
10464 #define elf_backend_got_header_size 0
10466 /* Similarly, there is no .got.plt section. */
10467 #undef elf_backend_want_got_plt
10468 #define elf_backend_want_got_plt 0
10470 #undef elf_backend_may_use_rel_p
10471 #define elf_backend_may_use_rel_p 1
10472 #undef elf_backend_may_use_rela_p
10473 #define elf_backend_may_use_rela_p 0
10474 #undef elf_backend_default_use_rela_p
10475 #define elf_backend_default_use_rela_p 0
10476 #undef elf_backend_want_plt_sym
10477 #define elf_backend_want_plt_sym 0
10478 #undef ELF_MAXPAGESIZE
10479 #define ELF_MAXPAGESIZE 0x8000
10481 #include "elf32-target.h"