1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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 #define ARM_ELF_ABI_VERSION 0
63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
65 static struct elf_backend_data elf32_arm_vxworks_bed
;
67 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
68 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
71 static reloc_howto_type elf32_arm_howto_table_1
[] =
74 HOWTO (R_ARM_NONE
, /* type */
76 0, /* size (0 = byte, 1 = short, 2 = long) */
78 FALSE
, /* pc_relative */
80 complain_overflow_dont
,/* complain_on_overflow */
81 bfd_elf_generic_reloc
, /* special_function */
82 "R_ARM_NONE", /* name */
83 FALSE
, /* partial_inplace */
86 FALSE
), /* pcrel_offset */
88 HOWTO (R_ARM_PC24
, /* type */
90 2, /* size (0 = byte, 1 = short, 2 = long) */
92 TRUE
, /* pc_relative */
94 complain_overflow_signed
,/* complain_on_overflow */
95 bfd_elf_generic_reloc
, /* special_function */
96 "R_ARM_PC24", /* name */
97 FALSE
, /* partial_inplace */
98 0x00ffffff, /* src_mask */
99 0x00ffffff, /* dst_mask */
100 TRUE
), /* pcrel_offset */
102 /* 32 bit absolute */
103 HOWTO (R_ARM_ABS32
, /* type */
105 2, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE
, /* pc_relative */
109 complain_overflow_bitfield
,/* complain_on_overflow */
110 bfd_elf_generic_reloc
, /* special_function */
111 "R_ARM_ABS32", /* name */
112 FALSE
, /* partial_inplace */
113 0xffffffff, /* src_mask */
114 0xffffffff, /* dst_mask */
115 FALSE
), /* pcrel_offset */
117 /* standard 32bit pc-relative reloc */
118 HOWTO (R_ARM_REL32
, /* type */
120 2, /* size (0 = byte, 1 = short, 2 = long) */
122 TRUE
, /* pc_relative */
124 complain_overflow_bitfield
,/* complain_on_overflow */
125 bfd_elf_generic_reloc
, /* special_function */
126 "R_ARM_REL32", /* name */
127 FALSE
, /* partial_inplace */
128 0xffffffff, /* src_mask */
129 0xffffffff, /* dst_mask */
130 TRUE
), /* pcrel_offset */
132 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
133 HOWTO (R_ARM_LDR_PC_G0
, /* type */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
137 TRUE
, /* pc_relative */
139 complain_overflow_dont
,/* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_ARM_LDR_PC_G0", /* name */
142 FALSE
, /* partial_inplace */
143 0xffffffff, /* src_mask */
144 0xffffffff, /* dst_mask */
145 TRUE
), /* pcrel_offset */
147 /* 16 bit absolute */
148 HOWTO (R_ARM_ABS16
, /* type */
150 1, /* size (0 = byte, 1 = short, 2 = long) */
152 FALSE
, /* pc_relative */
154 complain_overflow_bitfield
,/* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_ARM_ABS16", /* name */
157 FALSE
, /* partial_inplace */
158 0x0000ffff, /* src_mask */
159 0x0000ffff, /* dst_mask */
160 FALSE
), /* pcrel_offset */
162 /* 12 bit absolute */
163 HOWTO (R_ARM_ABS12
, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 FALSE
, /* pc_relative */
169 complain_overflow_bitfield
,/* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_ARM_ABS12", /* name */
172 FALSE
, /* partial_inplace */
173 0x00000fff, /* src_mask */
174 0x00000fff, /* dst_mask */
175 FALSE
), /* pcrel_offset */
177 HOWTO (R_ARM_THM_ABS5
, /* type */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
181 FALSE
, /* pc_relative */
183 complain_overflow_bitfield
,/* complain_on_overflow */
184 bfd_elf_generic_reloc
, /* special_function */
185 "R_ARM_THM_ABS5", /* name */
186 FALSE
, /* partial_inplace */
187 0x000007e0, /* src_mask */
188 0x000007e0, /* dst_mask */
189 FALSE
), /* pcrel_offset */
192 HOWTO (R_ARM_ABS8
, /* type */
194 0, /* size (0 = byte, 1 = short, 2 = long) */
196 FALSE
, /* pc_relative */
198 complain_overflow_bitfield
,/* complain_on_overflow */
199 bfd_elf_generic_reloc
, /* special_function */
200 "R_ARM_ABS8", /* name */
201 FALSE
, /* partial_inplace */
202 0x000000ff, /* src_mask */
203 0x000000ff, /* dst_mask */
204 FALSE
), /* pcrel_offset */
206 HOWTO (R_ARM_SBREL32
, /* type */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
210 FALSE
, /* pc_relative */
212 complain_overflow_dont
,/* complain_on_overflow */
213 bfd_elf_generic_reloc
, /* special_function */
214 "R_ARM_SBREL32", /* name */
215 FALSE
, /* partial_inplace */
216 0xffffffff, /* src_mask */
217 0xffffffff, /* dst_mask */
218 FALSE
), /* pcrel_offset */
220 /* FIXME: Has two more bits of offset in Thumb32. */
221 HOWTO (R_ARM_THM_CALL
, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 TRUE
, /* pc_relative */
227 complain_overflow_signed
,/* complain_on_overflow */
228 bfd_elf_generic_reloc
, /* special_function */
229 "R_ARM_THM_CALL", /* name */
230 FALSE
, /* partial_inplace */
231 0x07ff07ff, /* src_mask */
232 0x07ff07ff, /* dst_mask */
233 TRUE
), /* pcrel_offset */
235 HOWTO (R_ARM_THM_PC8
, /* type */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
239 TRUE
, /* pc_relative */
241 complain_overflow_signed
,/* complain_on_overflow */
242 bfd_elf_generic_reloc
, /* special_function */
243 "R_ARM_THM_PC8", /* name */
244 FALSE
, /* partial_inplace */
245 0x000000ff, /* src_mask */
246 0x000000ff, /* dst_mask */
247 TRUE
), /* pcrel_offset */
249 HOWTO (R_ARM_BREL_ADJ
, /* type */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
253 FALSE
, /* pc_relative */
255 complain_overflow_signed
,/* complain_on_overflow */
256 bfd_elf_generic_reloc
, /* special_function */
257 "R_ARM_BREL_ADJ", /* name */
258 FALSE
, /* partial_inplace */
259 0xffffffff, /* src_mask */
260 0xffffffff, /* dst_mask */
261 FALSE
), /* pcrel_offset */
263 HOWTO (R_ARM_SWI24
, /* type */
265 0, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_signed
,/* complain_on_overflow */
270 bfd_elf_generic_reloc
, /* special_function */
271 "R_ARM_SWI24", /* name */
272 FALSE
, /* partial_inplace */
273 0x00000000, /* src_mask */
274 0x00000000, /* dst_mask */
275 FALSE
), /* pcrel_offset */
277 HOWTO (R_ARM_THM_SWI8
, /* type */
279 0, /* size (0 = byte, 1 = short, 2 = long) */
281 FALSE
, /* pc_relative */
283 complain_overflow_signed
,/* complain_on_overflow */
284 bfd_elf_generic_reloc
, /* special_function */
285 "R_ARM_SWI8", /* name */
286 FALSE
, /* partial_inplace */
287 0x00000000, /* src_mask */
288 0x00000000, /* dst_mask */
289 FALSE
), /* pcrel_offset */
291 /* BLX instruction for the ARM. */
292 HOWTO (R_ARM_XPC25
, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 TRUE
, /* pc_relative */
298 complain_overflow_signed
,/* complain_on_overflow */
299 bfd_elf_generic_reloc
, /* special_function */
300 "R_ARM_XPC25", /* name */
301 FALSE
, /* partial_inplace */
302 0x00ffffff, /* src_mask */
303 0x00ffffff, /* dst_mask */
304 TRUE
), /* pcrel_offset */
306 /* BLX instruction for the Thumb. */
307 HOWTO (R_ARM_THM_XPC22
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 TRUE
, /* pc_relative */
313 complain_overflow_signed
,/* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_ARM_THM_XPC22", /* name */
316 FALSE
, /* partial_inplace */
317 0x07ff07ff, /* src_mask */
318 0x07ff07ff, /* dst_mask */
319 TRUE
), /* pcrel_offset */
321 /* Dynamic TLS relocations. */
323 HOWTO (R_ARM_TLS_DTPMOD32
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_bitfield
,/* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_ARM_TLS_DTPMOD32", /* name */
332 TRUE
, /* partial_inplace */
333 0xffffffff, /* src_mask */
334 0xffffffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 HOWTO (R_ARM_TLS_DTPOFF32
, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 FALSE
, /* pc_relative */
343 complain_overflow_bitfield
,/* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_ARM_TLS_DTPOFF32", /* name */
346 TRUE
, /* partial_inplace */
347 0xffffffff, /* src_mask */
348 0xffffffff, /* dst_mask */
349 FALSE
), /* pcrel_offset */
351 HOWTO (R_ARM_TLS_TPOFF32
, /* type */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
355 FALSE
, /* pc_relative */
357 complain_overflow_bitfield
,/* complain_on_overflow */
358 bfd_elf_generic_reloc
, /* special_function */
359 "R_ARM_TLS_TPOFF32", /* name */
360 TRUE
, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 FALSE
), /* pcrel_offset */
365 /* Relocs used in ARM Linux */
367 HOWTO (R_ARM_COPY
, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 FALSE
, /* pc_relative */
373 complain_overflow_bitfield
,/* complain_on_overflow */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_ARM_COPY", /* name */
376 TRUE
, /* partial_inplace */
377 0xffffffff, /* src_mask */
378 0xffffffff, /* dst_mask */
379 FALSE
), /* pcrel_offset */
381 HOWTO (R_ARM_GLOB_DAT
, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 FALSE
, /* pc_relative */
387 complain_overflow_bitfield
,/* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 "R_ARM_GLOB_DAT", /* name */
390 TRUE
, /* partial_inplace */
391 0xffffffff, /* src_mask */
392 0xffffffff, /* dst_mask */
393 FALSE
), /* pcrel_offset */
395 HOWTO (R_ARM_JUMP_SLOT
, /* type */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
399 FALSE
, /* pc_relative */
401 complain_overflow_bitfield
,/* complain_on_overflow */
402 bfd_elf_generic_reloc
, /* special_function */
403 "R_ARM_JUMP_SLOT", /* name */
404 TRUE
, /* partial_inplace */
405 0xffffffff, /* src_mask */
406 0xffffffff, /* dst_mask */
407 FALSE
), /* pcrel_offset */
409 HOWTO (R_ARM_RELATIVE
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_bitfield
,/* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_ARM_RELATIVE", /* name */
418 TRUE
, /* partial_inplace */
419 0xffffffff, /* src_mask */
420 0xffffffff, /* dst_mask */
421 FALSE
), /* pcrel_offset */
423 HOWTO (R_ARM_GOTOFF32
, /* type */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
427 FALSE
, /* pc_relative */
429 complain_overflow_bitfield
,/* complain_on_overflow */
430 bfd_elf_generic_reloc
, /* special_function */
431 "R_ARM_GOTOFF32", /* name */
432 TRUE
, /* partial_inplace */
433 0xffffffff, /* src_mask */
434 0xffffffff, /* dst_mask */
435 FALSE
), /* pcrel_offset */
437 HOWTO (R_ARM_GOTPC
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 TRUE
, /* pc_relative */
443 complain_overflow_bitfield
,/* complain_on_overflow */
444 bfd_elf_generic_reloc
, /* special_function */
445 "R_ARM_GOTPC", /* name */
446 TRUE
, /* partial_inplace */
447 0xffffffff, /* src_mask */
448 0xffffffff, /* dst_mask */
449 TRUE
), /* pcrel_offset */
451 HOWTO (R_ARM_GOT32
, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_bitfield
,/* complain_on_overflow */
458 bfd_elf_generic_reloc
, /* special_function */
459 "R_ARM_GOT32", /* name */
460 TRUE
, /* partial_inplace */
461 0xffffffff, /* src_mask */
462 0xffffffff, /* dst_mask */
463 FALSE
), /* pcrel_offset */
465 HOWTO (R_ARM_PLT32
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_bitfield
,/* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_ARM_PLT32", /* name */
474 FALSE
, /* partial_inplace */
475 0x00ffffff, /* src_mask */
476 0x00ffffff, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 HOWTO (R_ARM_CALL
, /* type */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 TRUE
, /* pc_relative */
485 complain_overflow_signed
,/* complain_on_overflow */
486 bfd_elf_generic_reloc
, /* special_function */
487 "R_ARM_CALL", /* name */
488 FALSE
, /* partial_inplace */
489 0x00ffffff, /* src_mask */
490 0x00ffffff, /* dst_mask */
491 TRUE
), /* pcrel_offset */
493 HOWTO (R_ARM_JUMP24
, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 TRUE
, /* pc_relative */
499 complain_overflow_signed
,/* complain_on_overflow */
500 bfd_elf_generic_reloc
, /* special_function */
501 "R_ARM_JUMP24", /* name */
502 FALSE
, /* partial_inplace */
503 0x00ffffff, /* src_mask */
504 0x00ffffff, /* dst_mask */
505 TRUE
), /* pcrel_offset */
507 HOWTO (R_ARM_THM_JUMP24
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 TRUE
, /* pc_relative */
513 complain_overflow_signed
,/* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_ARM_THM_JUMP24", /* name */
516 FALSE
, /* partial_inplace */
517 0x07ff2fff, /* src_mask */
518 0x07ff2fff, /* dst_mask */
519 TRUE
), /* pcrel_offset */
521 HOWTO (R_ARM_BASE_ABS
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 FALSE
, /* pc_relative */
527 complain_overflow_dont
,/* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_ARM_BASE_ABS", /* name */
530 FALSE
, /* partial_inplace */
531 0xffffffff, /* src_mask */
532 0xffffffff, /* dst_mask */
533 FALSE
), /* pcrel_offset */
535 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 TRUE
, /* pc_relative */
541 complain_overflow_dont
,/* complain_on_overflow */
542 bfd_elf_generic_reloc
, /* special_function */
543 "R_ARM_ALU_PCREL_7_0", /* name */
544 FALSE
, /* partial_inplace */
545 0x00000fff, /* src_mask */
546 0x00000fff, /* dst_mask */
547 TRUE
), /* pcrel_offset */
549 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 TRUE
, /* pc_relative */
555 complain_overflow_dont
,/* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 "R_ARM_ALU_PCREL_15_8",/* name */
558 FALSE
, /* partial_inplace */
559 0x00000fff, /* src_mask */
560 0x00000fff, /* dst_mask */
561 TRUE
), /* pcrel_offset */
563 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 TRUE
, /* pc_relative */
569 complain_overflow_dont
,/* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_ARM_ALU_PCREL_23_15",/* name */
572 FALSE
, /* partial_inplace */
573 0x00000fff, /* src_mask */
574 0x00000fff, /* dst_mask */
575 TRUE
), /* pcrel_offset */
577 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 FALSE
, /* pc_relative */
583 complain_overflow_dont
,/* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_ARM_LDR_SBREL_11_0",/* name */
586 FALSE
, /* partial_inplace */
587 0x00000fff, /* src_mask */
588 0x00000fff, /* dst_mask */
589 FALSE
), /* pcrel_offset */
591 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 FALSE
, /* pc_relative */
597 complain_overflow_dont
,/* complain_on_overflow */
598 bfd_elf_generic_reloc
, /* special_function */
599 "R_ARM_ALU_SBREL_19_12",/* name */
600 FALSE
, /* partial_inplace */
601 0x000ff000, /* src_mask */
602 0x000ff000, /* dst_mask */
603 FALSE
), /* pcrel_offset */
605 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE
, /* pc_relative */
611 complain_overflow_dont
,/* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 "R_ARM_ALU_SBREL_27_20",/* name */
614 FALSE
, /* partial_inplace */
615 0x0ff00000, /* src_mask */
616 0x0ff00000, /* dst_mask */
617 FALSE
), /* pcrel_offset */
619 HOWTO (R_ARM_TARGET1
, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 FALSE
, /* pc_relative */
625 complain_overflow_dont
,/* complain_on_overflow */
626 bfd_elf_generic_reloc
, /* special_function */
627 "R_ARM_TARGET1", /* name */
628 FALSE
, /* partial_inplace */
629 0xffffffff, /* src_mask */
630 0xffffffff, /* dst_mask */
631 FALSE
), /* pcrel_offset */
633 HOWTO (R_ARM_ROSEGREL32
, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 FALSE
, /* pc_relative */
639 complain_overflow_dont
,/* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_ARM_ROSEGREL32", /* name */
642 FALSE
, /* partial_inplace */
643 0xffffffff, /* src_mask */
644 0xffffffff, /* dst_mask */
645 FALSE
), /* pcrel_offset */
647 HOWTO (R_ARM_V4BX
, /* type */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 FALSE
, /* pc_relative */
653 complain_overflow_dont
,/* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_ARM_V4BX", /* name */
656 FALSE
, /* partial_inplace */
657 0xffffffff, /* src_mask */
658 0xffffffff, /* dst_mask */
659 FALSE
), /* pcrel_offset */
661 HOWTO (R_ARM_TARGET2
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 FALSE
, /* pc_relative */
667 complain_overflow_signed
,/* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_ARM_TARGET2", /* name */
670 FALSE
, /* partial_inplace */
671 0xffffffff, /* src_mask */
672 0xffffffff, /* dst_mask */
673 TRUE
), /* pcrel_offset */
675 HOWTO (R_ARM_PREL31
, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 TRUE
, /* pc_relative */
681 complain_overflow_signed
,/* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_ARM_PREL31", /* name */
684 FALSE
, /* partial_inplace */
685 0x7fffffff, /* src_mask */
686 0x7fffffff, /* dst_mask */
687 TRUE
), /* pcrel_offset */
689 HOWTO (R_ARM_MOVW_ABS_NC
, /* type */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
693 FALSE
, /* pc_relative */
695 complain_overflow_dont
,/* complain_on_overflow */
696 bfd_elf_generic_reloc
, /* special_function */
697 "R_ARM_MOVW_ABS_NC", /* name */
698 FALSE
, /* partial_inplace */
699 0x0000ffff, /* src_mask */
700 0x0000ffff, /* dst_mask */
701 FALSE
), /* pcrel_offset */
703 HOWTO (R_ARM_MOVT_ABS
, /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE
, /* pc_relative */
709 complain_overflow_bitfield
,/* complain_on_overflow */
710 bfd_elf_generic_reloc
, /* special_function */
711 "R_ARM_MOVT_ABS", /* name */
712 FALSE
, /* partial_inplace */
713 0x0000ffff, /* src_mask */
714 0x0000ffff, /* dst_mask */
715 FALSE
), /* pcrel_offset */
717 HOWTO (R_ARM_MOVW_PREL_NC
, /* type */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
721 TRUE
, /* pc_relative */
723 complain_overflow_dont
,/* complain_on_overflow */
724 bfd_elf_generic_reloc
, /* special_function */
725 "R_ARM_MOVW_PREL_NC", /* name */
726 FALSE
, /* partial_inplace */
727 0x0000ffff, /* src_mask */
728 0x0000ffff, /* dst_mask */
729 TRUE
), /* pcrel_offset */
731 HOWTO (R_ARM_MOVT_PREL
, /* type */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
735 TRUE
, /* pc_relative */
737 complain_overflow_bitfield
,/* complain_on_overflow */
738 bfd_elf_generic_reloc
, /* special_function */
739 "R_ARM_MOVT_PREL", /* name */
740 FALSE
, /* partial_inplace */
741 0x0000ffff, /* src_mask */
742 0x0000ffff, /* dst_mask */
743 TRUE
), /* pcrel_offset */
745 HOWTO (R_ARM_THM_MOVW_ABS_NC
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE
, /* pc_relative */
751 complain_overflow_dont
,/* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* special_function */
753 "R_ARM_THM_MOVW_ABS_NC",/* name */
754 FALSE
, /* partial_inplace */
755 0x040f70ff, /* src_mask */
756 0x040f70ff, /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 HOWTO (R_ARM_THM_MOVT_ABS
, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_bitfield
,/* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_ARM_THM_MOVT_ABS", /* name */
768 FALSE
, /* partial_inplace */
769 0x040f70ff, /* src_mask */
770 0x040f70ff, /* dst_mask */
771 FALSE
), /* pcrel_offset */
773 HOWTO (R_ARM_THM_MOVW_PREL_NC
,/* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 TRUE
, /* pc_relative */
779 complain_overflow_dont
,/* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_ARM_THM_MOVW_PREL_NC",/* name */
782 FALSE
, /* partial_inplace */
783 0x040f70ff, /* src_mask */
784 0x040f70ff, /* dst_mask */
785 TRUE
), /* pcrel_offset */
787 HOWTO (R_ARM_THM_MOVT_PREL
, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 TRUE
, /* pc_relative */
793 complain_overflow_bitfield
,/* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* special_function */
795 "R_ARM_THM_MOVT_PREL", /* name */
796 FALSE
, /* partial_inplace */
797 0x040f70ff, /* src_mask */
798 0x040f70ff, /* dst_mask */
799 TRUE
), /* pcrel_offset */
801 HOWTO (R_ARM_THM_JUMP19
, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 TRUE
, /* pc_relative */
807 complain_overflow_signed
,/* complain_on_overflow */
808 bfd_elf_generic_reloc
, /* special_function */
809 "R_ARM_THM_JUMP19", /* name */
810 FALSE
, /* partial_inplace */
811 0x043f2fff, /* src_mask */
812 0x043f2fff, /* dst_mask */
813 TRUE
), /* pcrel_offset */
815 HOWTO (R_ARM_THM_JUMP6
, /* type */
817 1, /* size (0 = byte, 1 = short, 2 = long) */
819 TRUE
, /* pc_relative */
821 complain_overflow_unsigned
,/* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_ARM_THM_JUMP6", /* name */
824 FALSE
, /* partial_inplace */
825 0x02f8, /* src_mask */
826 0x02f8, /* dst_mask */
827 TRUE
), /* pcrel_offset */
829 /* These are declared as 13-bit signed relocations because we can
830 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
832 HOWTO (R_ARM_THM_ALU_PREL_11_0
,/* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 TRUE
, /* pc_relative */
838 complain_overflow_dont
,/* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_ARM_THM_ALU_PREL_11_0",/* name */
841 FALSE
, /* partial_inplace */
842 0xffffffff, /* src_mask */
843 0xffffffff, /* dst_mask */
844 TRUE
), /* pcrel_offset */
846 HOWTO (R_ARM_THM_PC12
, /* type */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
850 TRUE
, /* pc_relative */
852 complain_overflow_dont
,/* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 "R_ARM_THM_PC12", /* name */
855 FALSE
, /* partial_inplace */
856 0xffffffff, /* src_mask */
857 0xffffffff, /* dst_mask */
858 TRUE
), /* pcrel_offset */
860 HOWTO (R_ARM_ABS32_NOI
, /* type */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_dont
,/* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_ARM_ABS32_NOI", /* name */
869 FALSE
, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 HOWTO (R_ARM_REL32_NOI
, /* type */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
878 TRUE
, /* pc_relative */
880 complain_overflow_dont
,/* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_ARM_REL32_NOI", /* name */
883 FALSE
, /* partial_inplace */
884 0xffffffff, /* src_mask */
885 0xffffffff, /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* Group relocations. */
890 HOWTO (R_ARM_ALU_PC_G0_NC
, /* type */
892 2, /* size (0 = byte, 1 = short, 2 = long) */
894 TRUE
, /* pc_relative */
896 complain_overflow_dont
,/* complain_on_overflow */
897 bfd_elf_generic_reloc
, /* special_function */
898 "R_ARM_ALU_PC_G0_NC", /* name */
899 FALSE
, /* partial_inplace */
900 0xffffffff, /* src_mask */
901 0xffffffff, /* dst_mask */
902 TRUE
), /* pcrel_offset */
904 HOWTO (R_ARM_ALU_PC_G0
, /* type */
906 2, /* size (0 = byte, 1 = short, 2 = long) */
908 TRUE
, /* pc_relative */
910 complain_overflow_dont
,/* complain_on_overflow */
911 bfd_elf_generic_reloc
, /* special_function */
912 "R_ARM_ALU_PC_G0", /* name */
913 FALSE
, /* partial_inplace */
914 0xffffffff, /* src_mask */
915 0xffffffff, /* dst_mask */
916 TRUE
), /* pcrel_offset */
918 HOWTO (R_ARM_ALU_PC_G1_NC
, /* type */
920 2, /* size (0 = byte, 1 = short, 2 = long) */
922 TRUE
, /* pc_relative */
924 complain_overflow_dont
,/* complain_on_overflow */
925 bfd_elf_generic_reloc
, /* special_function */
926 "R_ARM_ALU_PC_G1_NC", /* name */
927 FALSE
, /* partial_inplace */
928 0xffffffff, /* src_mask */
929 0xffffffff, /* dst_mask */
930 TRUE
), /* pcrel_offset */
932 HOWTO (R_ARM_ALU_PC_G1
, /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 TRUE
, /* pc_relative */
938 complain_overflow_dont
,/* complain_on_overflow */
939 bfd_elf_generic_reloc
, /* special_function */
940 "R_ARM_ALU_PC_G1", /* name */
941 FALSE
, /* partial_inplace */
942 0xffffffff, /* src_mask */
943 0xffffffff, /* dst_mask */
944 TRUE
), /* pcrel_offset */
946 HOWTO (R_ARM_ALU_PC_G2
, /* type */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
950 TRUE
, /* pc_relative */
952 complain_overflow_dont
,/* complain_on_overflow */
953 bfd_elf_generic_reloc
, /* special_function */
954 "R_ARM_ALU_PC_G2", /* name */
955 FALSE
, /* partial_inplace */
956 0xffffffff, /* src_mask */
957 0xffffffff, /* dst_mask */
958 TRUE
), /* pcrel_offset */
960 HOWTO (R_ARM_LDR_PC_G1
, /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 TRUE
, /* pc_relative */
966 complain_overflow_dont
,/* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 "R_ARM_LDR_PC_G1", /* name */
969 FALSE
, /* partial_inplace */
970 0xffffffff, /* src_mask */
971 0xffffffff, /* dst_mask */
972 TRUE
), /* pcrel_offset */
974 HOWTO (R_ARM_LDR_PC_G2
, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 TRUE
, /* pc_relative */
980 complain_overflow_dont
,/* complain_on_overflow */
981 bfd_elf_generic_reloc
, /* special_function */
982 "R_ARM_LDR_PC_G2", /* name */
983 FALSE
, /* partial_inplace */
984 0xffffffff, /* src_mask */
985 0xffffffff, /* dst_mask */
986 TRUE
), /* pcrel_offset */
988 HOWTO (R_ARM_LDRS_PC_G0
, /* type */
990 2, /* size (0 = byte, 1 = short, 2 = long) */
992 TRUE
, /* pc_relative */
994 complain_overflow_dont
,/* complain_on_overflow */
995 bfd_elf_generic_reloc
, /* special_function */
996 "R_ARM_LDRS_PC_G0", /* name */
997 FALSE
, /* partial_inplace */
998 0xffffffff, /* src_mask */
999 0xffffffff, /* dst_mask */
1000 TRUE
), /* pcrel_offset */
1002 HOWTO (R_ARM_LDRS_PC_G1
, /* type */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1006 TRUE
, /* pc_relative */
1008 complain_overflow_dont
,/* complain_on_overflow */
1009 bfd_elf_generic_reloc
, /* special_function */
1010 "R_ARM_LDRS_PC_G1", /* name */
1011 FALSE
, /* partial_inplace */
1012 0xffffffff, /* src_mask */
1013 0xffffffff, /* dst_mask */
1014 TRUE
), /* pcrel_offset */
1016 HOWTO (R_ARM_LDRS_PC_G2
, /* type */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1020 TRUE
, /* pc_relative */
1022 complain_overflow_dont
,/* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_ARM_LDRS_PC_G2", /* name */
1025 FALSE
, /* partial_inplace */
1026 0xffffffff, /* src_mask */
1027 0xffffffff, /* dst_mask */
1028 TRUE
), /* pcrel_offset */
1030 HOWTO (R_ARM_LDC_PC_G0
, /* type */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1034 TRUE
, /* pc_relative */
1036 complain_overflow_dont
,/* complain_on_overflow */
1037 bfd_elf_generic_reloc
, /* special_function */
1038 "R_ARM_LDC_PC_G0", /* name */
1039 FALSE
, /* partial_inplace */
1040 0xffffffff, /* src_mask */
1041 0xffffffff, /* dst_mask */
1042 TRUE
), /* pcrel_offset */
1044 HOWTO (R_ARM_LDC_PC_G1
, /* type */
1046 2, /* size (0 = byte, 1 = short, 2 = long) */
1048 TRUE
, /* pc_relative */
1050 complain_overflow_dont
,/* complain_on_overflow */
1051 bfd_elf_generic_reloc
, /* special_function */
1052 "R_ARM_LDC_PC_G1", /* name */
1053 FALSE
, /* partial_inplace */
1054 0xffffffff, /* src_mask */
1055 0xffffffff, /* dst_mask */
1056 TRUE
), /* pcrel_offset */
1058 HOWTO (R_ARM_LDC_PC_G2
, /* type */
1060 2, /* size (0 = byte, 1 = short, 2 = long) */
1062 TRUE
, /* pc_relative */
1064 complain_overflow_dont
,/* complain_on_overflow */
1065 bfd_elf_generic_reloc
, /* special_function */
1066 "R_ARM_LDC_PC_G2", /* name */
1067 FALSE
, /* partial_inplace */
1068 0xffffffff, /* src_mask */
1069 0xffffffff, /* dst_mask */
1070 TRUE
), /* pcrel_offset */
1072 HOWTO (R_ARM_ALU_SB_G0_NC
, /* type */
1074 2, /* size (0 = byte, 1 = short, 2 = long) */
1076 TRUE
, /* pc_relative */
1078 complain_overflow_dont
,/* complain_on_overflow */
1079 bfd_elf_generic_reloc
, /* special_function */
1080 "R_ARM_ALU_SB_G0_NC", /* name */
1081 FALSE
, /* partial_inplace */
1082 0xffffffff, /* src_mask */
1083 0xffffffff, /* dst_mask */
1084 TRUE
), /* pcrel_offset */
1086 HOWTO (R_ARM_ALU_SB_G0
, /* type */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1090 TRUE
, /* pc_relative */
1092 complain_overflow_dont
,/* complain_on_overflow */
1093 bfd_elf_generic_reloc
, /* special_function */
1094 "R_ARM_ALU_SB_G0", /* name */
1095 FALSE
, /* partial_inplace */
1096 0xffffffff, /* src_mask */
1097 0xffffffff, /* dst_mask */
1098 TRUE
), /* pcrel_offset */
1100 HOWTO (R_ARM_ALU_SB_G1_NC
, /* type */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1104 TRUE
, /* pc_relative */
1106 complain_overflow_dont
,/* complain_on_overflow */
1107 bfd_elf_generic_reloc
, /* special_function */
1108 "R_ARM_ALU_SB_G1_NC", /* name */
1109 FALSE
, /* partial_inplace */
1110 0xffffffff, /* src_mask */
1111 0xffffffff, /* dst_mask */
1112 TRUE
), /* pcrel_offset */
1114 HOWTO (R_ARM_ALU_SB_G1
, /* type */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 TRUE
, /* pc_relative */
1120 complain_overflow_dont
,/* complain_on_overflow */
1121 bfd_elf_generic_reloc
, /* special_function */
1122 "R_ARM_ALU_SB_G1", /* name */
1123 FALSE
, /* partial_inplace */
1124 0xffffffff, /* src_mask */
1125 0xffffffff, /* dst_mask */
1126 TRUE
), /* pcrel_offset */
1128 HOWTO (R_ARM_ALU_SB_G2
, /* type */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 TRUE
, /* pc_relative */
1134 complain_overflow_dont
,/* complain_on_overflow */
1135 bfd_elf_generic_reloc
, /* special_function */
1136 "R_ARM_ALU_SB_G2", /* name */
1137 FALSE
, /* partial_inplace */
1138 0xffffffff, /* src_mask */
1139 0xffffffff, /* dst_mask */
1140 TRUE
), /* pcrel_offset */
1142 HOWTO (R_ARM_LDR_SB_G0
, /* type */
1144 2, /* size (0 = byte, 1 = short, 2 = long) */
1146 TRUE
, /* pc_relative */
1148 complain_overflow_dont
,/* complain_on_overflow */
1149 bfd_elf_generic_reloc
, /* special_function */
1150 "R_ARM_LDR_SB_G0", /* name */
1151 FALSE
, /* partial_inplace */
1152 0xffffffff, /* src_mask */
1153 0xffffffff, /* dst_mask */
1154 TRUE
), /* pcrel_offset */
1156 HOWTO (R_ARM_LDR_SB_G1
, /* type */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1160 TRUE
, /* pc_relative */
1162 complain_overflow_dont
,/* complain_on_overflow */
1163 bfd_elf_generic_reloc
, /* special_function */
1164 "R_ARM_LDR_SB_G1", /* name */
1165 FALSE
, /* partial_inplace */
1166 0xffffffff, /* src_mask */
1167 0xffffffff, /* dst_mask */
1168 TRUE
), /* pcrel_offset */
1170 HOWTO (R_ARM_LDR_SB_G2
, /* type */
1172 2, /* size (0 = byte, 1 = short, 2 = long) */
1174 TRUE
, /* pc_relative */
1176 complain_overflow_dont
,/* complain_on_overflow */
1177 bfd_elf_generic_reloc
, /* special_function */
1178 "R_ARM_LDR_SB_G2", /* name */
1179 FALSE
, /* partial_inplace */
1180 0xffffffff, /* src_mask */
1181 0xffffffff, /* dst_mask */
1182 TRUE
), /* pcrel_offset */
1184 HOWTO (R_ARM_LDRS_SB_G0
, /* type */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1188 TRUE
, /* pc_relative */
1190 complain_overflow_dont
,/* complain_on_overflow */
1191 bfd_elf_generic_reloc
, /* special_function */
1192 "R_ARM_LDRS_SB_G0", /* name */
1193 FALSE
, /* partial_inplace */
1194 0xffffffff, /* src_mask */
1195 0xffffffff, /* dst_mask */
1196 TRUE
), /* pcrel_offset */
1198 HOWTO (R_ARM_LDRS_SB_G1
, /* type */
1200 2, /* size (0 = byte, 1 = short, 2 = long) */
1202 TRUE
, /* pc_relative */
1204 complain_overflow_dont
,/* complain_on_overflow */
1205 bfd_elf_generic_reloc
, /* special_function */
1206 "R_ARM_LDRS_SB_G1", /* name */
1207 FALSE
, /* partial_inplace */
1208 0xffffffff, /* src_mask */
1209 0xffffffff, /* dst_mask */
1210 TRUE
), /* pcrel_offset */
1212 HOWTO (R_ARM_LDRS_SB_G2
, /* type */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1216 TRUE
, /* pc_relative */
1218 complain_overflow_dont
,/* complain_on_overflow */
1219 bfd_elf_generic_reloc
, /* special_function */
1220 "R_ARM_LDRS_SB_G2", /* name */
1221 FALSE
, /* partial_inplace */
1222 0xffffffff, /* src_mask */
1223 0xffffffff, /* dst_mask */
1224 TRUE
), /* pcrel_offset */
1226 HOWTO (R_ARM_LDC_SB_G0
, /* type */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1230 TRUE
, /* pc_relative */
1232 complain_overflow_dont
,/* complain_on_overflow */
1233 bfd_elf_generic_reloc
, /* special_function */
1234 "R_ARM_LDC_SB_G0", /* name */
1235 FALSE
, /* partial_inplace */
1236 0xffffffff, /* src_mask */
1237 0xffffffff, /* dst_mask */
1238 TRUE
), /* pcrel_offset */
1240 HOWTO (R_ARM_LDC_SB_G1
, /* type */
1242 2, /* size (0 = byte, 1 = short, 2 = long) */
1244 TRUE
, /* pc_relative */
1246 complain_overflow_dont
,/* complain_on_overflow */
1247 bfd_elf_generic_reloc
, /* special_function */
1248 "R_ARM_LDC_SB_G1", /* name */
1249 FALSE
, /* partial_inplace */
1250 0xffffffff, /* src_mask */
1251 0xffffffff, /* dst_mask */
1252 TRUE
), /* pcrel_offset */
1254 HOWTO (R_ARM_LDC_SB_G2
, /* type */
1256 2, /* size (0 = byte, 1 = short, 2 = long) */
1258 TRUE
, /* pc_relative */
1260 complain_overflow_dont
,/* complain_on_overflow */
1261 bfd_elf_generic_reloc
, /* special_function */
1262 "R_ARM_LDC_SB_G2", /* name */
1263 FALSE
, /* partial_inplace */
1264 0xffffffff, /* src_mask */
1265 0xffffffff, /* dst_mask */
1266 TRUE
), /* pcrel_offset */
1268 /* End of group relocations. */
1270 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1274 FALSE
, /* pc_relative */
1276 complain_overflow_dont
,/* complain_on_overflow */
1277 bfd_elf_generic_reloc
, /* special_function */
1278 "R_ARM_MOVW_BREL_NC", /* name */
1279 FALSE
, /* partial_inplace */
1280 0x0000ffff, /* src_mask */
1281 0x0000ffff, /* dst_mask */
1282 FALSE
), /* pcrel_offset */
1284 HOWTO (R_ARM_MOVT_BREL
, /* type */
1286 2, /* size (0 = byte, 1 = short, 2 = long) */
1288 FALSE
, /* pc_relative */
1290 complain_overflow_bitfield
,/* complain_on_overflow */
1291 bfd_elf_generic_reloc
, /* special_function */
1292 "R_ARM_MOVT_BREL", /* name */
1293 FALSE
, /* partial_inplace */
1294 0x0000ffff, /* src_mask */
1295 0x0000ffff, /* dst_mask */
1296 FALSE
), /* pcrel_offset */
1298 HOWTO (R_ARM_MOVW_BREL
, /* type */
1300 2, /* size (0 = byte, 1 = short, 2 = long) */
1302 FALSE
, /* pc_relative */
1304 complain_overflow_dont
,/* complain_on_overflow */
1305 bfd_elf_generic_reloc
, /* special_function */
1306 "R_ARM_MOVW_BREL", /* name */
1307 FALSE
, /* partial_inplace */
1308 0x0000ffff, /* src_mask */
1309 0x0000ffff, /* dst_mask */
1310 FALSE
), /* pcrel_offset */
1312 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_dont
,/* complain_on_overflow */
1319 bfd_elf_generic_reloc
, /* special_function */
1320 "R_ARM_THM_MOVW_BREL_NC",/* name */
1321 FALSE
, /* partial_inplace */
1322 0x040f70ff, /* src_mask */
1323 0x040f70ff, /* dst_mask */
1324 FALSE
), /* pcrel_offset */
1326 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE
, /* pc_relative */
1332 complain_overflow_bitfield
,/* complain_on_overflow */
1333 bfd_elf_generic_reloc
, /* special_function */
1334 "R_ARM_THM_MOVT_BREL", /* name */
1335 FALSE
, /* partial_inplace */
1336 0x040f70ff, /* src_mask */
1337 0x040f70ff, /* dst_mask */
1338 FALSE
), /* pcrel_offset */
1340 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
1342 2, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE
, /* pc_relative */
1346 complain_overflow_dont
,/* complain_on_overflow */
1347 bfd_elf_generic_reloc
, /* special_function */
1348 "R_ARM_THM_MOVW_BREL", /* name */
1349 FALSE
, /* partial_inplace */
1350 0x040f70ff, /* src_mask */
1351 0x040f70ff, /* dst_mask */
1352 FALSE
), /* pcrel_offset */
1354 EMPTY_HOWTO (90), /* unallocated */
1359 HOWTO (R_ARM_PLT32_ABS
, /* type */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE
, /* pc_relative */
1365 complain_overflow_dont
,/* complain_on_overflow */
1366 bfd_elf_generic_reloc
, /* special_function */
1367 "R_ARM_PLT32_ABS", /* name */
1368 FALSE
, /* partial_inplace */
1369 0xffffffff, /* src_mask */
1370 0xffffffff, /* dst_mask */
1371 FALSE
), /* pcrel_offset */
1373 HOWTO (R_ARM_GOT_ABS
, /* type */
1375 2, /* size (0 = byte, 1 = short, 2 = long) */
1377 FALSE
, /* pc_relative */
1379 complain_overflow_dont
,/* complain_on_overflow */
1380 bfd_elf_generic_reloc
, /* special_function */
1381 "R_ARM_GOT_ABS", /* name */
1382 FALSE
, /* partial_inplace */
1383 0xffffffff, /* src_mask */
1384 0xffffffff, /* dst_mask */
1385 FALSE
), /* pcrel_offset */
1387 HOWTO (R_ARM_GOT_PREL
, /* type */
1389 2, /* size (0 = byte, 1 = short, 2 = long) */
1391 TRUE
, /* pc_relative */
1393 complain_overflow_dont
, /* complain_on_overflow */
1394 bfd_elf_generic_reloc
, /* special_function */
1395 "R_ARM_GOT_PREL", /* name */
1396 FALSE
, /* partial_inplace */
1397 0xffffffff, /* src_mask */
1398 0xffffffff, /* dst_mask */
1399 TRUE
), /* pcrel_offset */
1401 HOWTO (R_ARM_GOT_BREL12
, /* type */
1403 2, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE
, /* pc_relative */
1407 complain_overflow_bitfield
,/* complain_on_overflow */
1408 bfd_elf_generic_reloc
, /* special_function */
1409 "R_ARM_GOT_BREL12", /* name */
1410 FALSE
, /* partial_inplace */
1411 0x00000fff, /* src_mask */
1412 0x00000fff, /* dst_mask */
1413 FALSE
), /* pcrel_offset */
1415 HOWTO (R_ARM_GOTOFF12
, /* type */
1417 2, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE
, /* pc_relative */
1421 complain_overflow_bitfield
,/* complain_on_overflow */
1422 bfd_elf_generic_reloc
, /* special_function */
1423 "R_ARM_GOTOFF12", /* name */
1424 FALSE
, /* partial_inplace */
1425 0x00000fff, /* src_mask */
1426 0x00000fff, /* dst_mask */
1427 FALSE
), /* pcrel_offset */
1429 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1431 /* GNU extension to record C++ vtable member usage */
1432 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE
, /* pc_relative */
1438 complain_overflow_dont
, /* complain_on_overflow */
1439 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1440 "R_ARM_GNU_VTENTRY", /* name */
1441 FALSE
, /* partial_inplace */
1444 FALSE
), /* pcrel_offset */
1446 /* GNU extension to record C++ vtable hierarchy */
1447 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1449 2, /* size (0 = byte, 1 = short, 2 = long) */
1451 FALSE
, /* pc_relative */
1453 complain_overflow_dont
, /* complain_on_overflow */
1454 NULL
, /* special_function */
1455 "R_ARM_GNU_VTINHERIT", /* name */
1456 FALSE
, /* partial_inplace */
1459 FALSE
), /* pcrel_offset */
1461 HOWTO (R_ARM_THM_JUMP11
, /* type */
1463 1, /* size (0 = byte, 1 = short, 2 = long) */
1465 TRUE
, /* pc_relative */
1467 complain_overflow_signed
, /* complain_on_overflow */
1468 bfd_elf_generic_reloc
, /* special_function */
1469 "R_ARM_THM_JUMP11", /* name */
1470 FALSE
, /* partial_inplace */
1471 0x000007ff, /* src_mask */
1472 0x000007ff, /* dst_mask */
1473 TRUE
), /* pcrel_offset */
1475 HOWTO (R_ARM_THM_JUMP8
, /* type */
1477 1, /* size (0 = byte, 1 = short, 2 = long) */
1479 TRUE
, /* pc_relative */
1481 complain_overflow_signed
, /* complain_on_overflow */
1482 bfd_elf_generic_reloc
, /* special_function */
1483 "R_ARM_THM_JUMP8", /* name */
1484 FALSE
, /* partial_inplace */
1485 0x000000ff, /* src_mask */
1486 0x000000ff, /* dst_mask */
1487 TRUE
), /* pcrel_offset */
1489 /* TLS relocations */
1490 HOWTO (R_ARM_TLS_GD32
, /* type */
1492 2, /* size (0 = byte, 1 = short, 2 = long) */
1494 FALSE
, /* pc_relative */
1496 complain_overflow_bitfield
,/* complain_on_overflow */
1497 NULL
, /* special_function */
1498 "R_ARM_TLS_GD32", /* name */
1499 TRUE
, /* partial_inplace */
1500 0xffffffff, /* src_mask */
1501 0xffffffff, /* dst_mask */
1502 FALSE
), /* pcrel_offset */
1504 HOWTO (R_ARM_TLS_LDM32
, /* type */
1506 2, /* size (0 = byte, 1 = short, 2 = long) */
1508 FALSE
, /* pc_relative */
1510 complain_overflow_bitfield
,/* complain_on_overflow */
1511 bfd_elf_generic_reloc
, /* special_function */
1512 "R_ARM_TLS_LDM32", /* name */
1513 TRUE
, /* partial_inplace */
1514 0xffffffff, /* src_mask */
1515 0xffffffff, /* dst_mask */
1516 FALSE
), /* pcrel_offset */
1518 HOWTO (R_ARM_TLS_LDO32
, /* type */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1522 FALSE
, /* pc_relative */
1524 complain_overflow_bitfield
,/* complain_on_overflow */
1525 bfd_elf_generic_reloc
, /* special_function */
1526 "R_ARM_TLS_LDO32", /* name */
1527 TRUE
, /* partial_inplace */
1528 0xffffffff, /* src_mask */
1529 0xffffffff, /* dst_mask */
1530 FALSE
), /* pcrel_offset */
1532 HOWTO (R_ARM_TLS_IE32
, /* type */
1534 2, /* size (0 = byte, 1 = short, 2 = long) */
1536 FALSE
, /* pc_relative */
1538 complain_overflow_bitfield
,/* complain_on_overflow */
1539 NULL
, /* special_function */
1540 "R_ARM_TLS_IE32", /* name */
1541 TRUE
, /* partial_inplace */
1542 0xffffffff, /* src_mask */
1543 0xffffffff, /* dst_mask */
1544 FALSE
), /* pcrel_offset */
1546 HOWTO (R_ARM_TLS_LE32
, /* type */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1550 FALSE
, /* pc_relative */
1552 complain_overflow_bitfield
,/* complain_on_overflow */
1553 bfd_elf_generic_reloc
, /* special_function */
1554 "R_ARM_TLS_LE32", /* name */
1555 TRUE
, /* partial_inplace */
1556 0xffffffff, /* src_mask */
1557 0xffffffff, /* dst_mask */
1558 FALSE
), /* pcrel_offset */
1560 HOWTO (R_ARM_TLS_LDO12
, /* type */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 FALSE
, /* pc_relative */
1566 complain_overflow_bitfield
,/* complain_on_overflow */
1567 bfd_elf_generic_reloc
, /* special_function */
1568 "R_ARM_TLS_LDO12", /* name */
1569 FALSE
, /* partial_inplace */
1570 0x00000fff, /* src_mask */
1571 0x00000fff, /* dst_mask */
1572 FALSE
), /* pcrel_offset */
1574 HOWTO (R_ARM_TLS_LE12
, /* type */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1578 FALSE
, /* pc_relative */
1580 complain_overflow_bitfield
,/* complain_on_overflow */
1581 bfd_elf_generic_reloc
, /* special_function */
1582 "R_ARM_TLS_LE12", /* name */
1583 FALSE
, /* partial_inplace */
1584 0x00000fff, /* src_mask */
1585 0x00000fff, /* dst_mask */
1586 FALSE
), /* pcrel_offset */
1588 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1590 2, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE
, /* pc_relative */
1594 complain_overflow_bitfield
,/* complain_on_overflow */
1595 bfd_elf_generic_reloc
, /* special_function */
1596 "R_ARM_TLS_IE12GP", /* name */
1597 FALSE
, /* partial_inplace */
1598 0x00000fff, /* src_mask */
1599 0x00000fff, /* dst_mask */
1600 FALSE
), /* pcrel_offset */
1603 /* 112-127 private relocations
1604 128 R_ARM_ME_TOO, obsolete
1605 129-255 unallocated in AAELF.
1607 249-255 extended, currently unused, relocations: */
1609 static reloc_howto_type elf32_arm_howto_table_2
[4] =
1611 HOWTO (R_ARM_RREL32
, /* type */
1613 0, /* size (0 = byte, 1 = short, 2 = long) */
1615 FALSE
, /* pc_relative */
1617 complain_overflow_dont
,/* complain_on_overflow */
1618 bfd_elf_generic_reloc
, /* special_function */
1619 "R_ARM_RREL32", /* name */
1620 FALSE
, /* partial_inplace */
1623 FALSE
), /* pcrel_offset */
1625 HOWTO (R_ARM_RABS32
, /* type */
1627 0, /* size (0 = byte, 1 = short, 2 = long) */
1629 FALSE
, /* pc_relative */
1631 complain_overflow_dont
,/* complain_on_overflow */
1632 bfd_elf_generic_reloc
, /* special_function */
1633 "R_ARM_RABS32", /* name */
1634 FALSE
, /* partial_inplace */
1637 FALSE
), /* pcrel_offset */
1639 HOWTO (R_ARM_RPC24
, /* type */
1641 0, /* size (0 = byte, 1 = short, 2 = long) */
1643 FALSE
, /* pc_relative */
1645 complain_overflow_dont
,/* complain_on_overflow */
1646 bfd_elf_generic_reloc
, /* special_function */
1647 "R_ARM_RPC24", /* name */
1648 FALSE
, /* partial_inplace */
1651 FALSE
), /* pcrel_offset */
1653 HOWTO (R_ARM_RBASE
, /* type */
1655 0, /* size (0 = byte, 1 = short, 2 = long) */
1657 FALSE
, /* pc_relative */
1659 complain_overflow_dont
,/* complain_on_overflow */
1660 bfd_elf_generic_reloc
, /* special_function */
1661 "R_ARM_RBASE", /* name */
1662 FALSE
, /* partial_inplace */
1665 FALSE
) /* pcrel_offset */
1668 static reloc_howto_type
*
1669 elf32_arm_howto_from_type (unsigned int r_type
)
1671 if (r_type
< NUM_ELEM (elf32_arm_howto_table_1
))
1672 return &elf32_arm_howto_table_1
[r_type
];
1674 if (r_type
>= R_ARM_RREL32
1675 && r_type
< R_ARM_RREL32
+ NUM_ELEM (elf32_arm_howto_table_2
))
1676 return &elf32_arm_howto_table_2
[r_type
- R_ARM_RREL32
];
1682 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1683 Elf_Internal_Rela
* elf_reloc
)
1685 unsigned int r_type
;
1687 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1688 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1691 struct elf32_arm_reloc_map
1693 bfd_reloc_code_real_type bfd_reloc_val
;
1694 unsigned char elf_reloc_val
;
1697 /* All entries in this list must also be present in elf32_arm_howto_table. */
1698 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1700 {BFD_RELOC_NONE
, R_ARM_NONE
},
1701 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1702 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1703 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1704 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1705 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1706 {BFD_RELOC_32
, R_ARM_ABS32
},
1707 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1708 {BFD_RELOC_8
, R_ARM_ABS8
},
1709 {BFD_RELOC_16
, R_ARM_ABS16
},
1710 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1711 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1718 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1719 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1720 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1721 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1722 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1723 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1724 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1725 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1726 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1727 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1728 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1729 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1730 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1731 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1732 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1733 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1734 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1735 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1736 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1737 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1738 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1739 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1740 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1741 {BFD_RELOC_ARM_MOVW
, R_ARM_MOVW_ABS_NC
},
1742 {BFD_RELOC_ARM_MOVT
, R_ARM_MOVT_ABS
},
1743 {BFD_RELOC_ARM_MOVW_PCREL
, R_ARM_MOVW_PREL_NC
},
1744 {BFD_RELOC_ARM_MOVT_PCREL
, R_ARM_MOVT_PREL
},
1745 {BFD_RELOC_ARM_THUMB_MOVW
, R_ARM_THM_MOVW_ABS_NC
},
1746 {BFD_RELOC_ARM_THUMB_MOVT
, R_ARM_THM_MOVT_ABS
},
1747 {BFD_RELOC_ARM_THUMB_MOVW_PCREL
, R_ARM_THM_MOVW_PREL_NC
},
1748 {BFD_RELOC_ARM_THUMB_MOVT_PCREL
, R_ARM_THM_MOVT_PREL
},
1749 {BFD_RELOC_ARM_ALU_PC_G0_NC
, R_ARM_ALU_PC_G0_NC
},
1750 {BFD_RELOC_ARM_ALU_PC_G0
, R_ARM_ALU_PC_G0
},
1751 {BFD_RELOC_ARM_ALU_PC_G1_NC
, R_ARM_ALU_PC_G1_NC
},
1752 {BFD_RELOC_ARM_ALU_PC_G1
, R_ARM_ALU_PC_G1
},
1753 {BFD_RELOC_ARM_ALU_PC_G2
, R_ARM_ALU_PC_G2
},
1754 {BFD_RELOC_ARM_LDR_PC_G0
, R_ARM_LDR_PC_G0
},
1755 {BFD_RELOC_ARM_LDR_PC_G1
, R_ARM_LDR_PC_G1
},
1756 {BFD_RELOC_ARM_LDR_PC_G2
, R_ARM_LDR_PC_G2
},
1757 {BFD_RELOC_ARM_LDRS_PC_G0
, R_ARM_LDRS_PC_G0
},
1758 {BFD_RELOC_ARM_LDRS_PC_G1
, R_ARM_LDRS_PC_G1
},
1759 {BFD_RELOC_ARM_LDRS_PC_G2
, R_ARM_LDRS_PC_G2
},
1760 {BFD_RELOC_ARM_LDC_PC_G0
, R_ARM_LDC_PC_G0
},
1761 {BFD_RELOC_ARM_LDC_PC_G1
, R_ARM_LDC_PC_G1
},
1762 {BFD_RELOC_ARM_LDC_PC_G2
, R_ARM_LDC_PC_G2
},
1763 {BFD_RELOC_ARM_ALU_SB_G0_NC
, R_ARM_ALU_SB_G0_NC
},
1764 {BFD_RELOC_ARM_ALU_SB_G0
, R_ARM_ALU_SB_G0
},
1765 {BFD_RELOC_ARM_ALU_SB_G1_NC
, R_ARM_ALU_SB_G1_NC
},
1766 {BFD_RELOC_ARM_ALU_SB_G1
, R_ARM_ALU_SB_G1
},
1767 {BFD_RELOC_ARM_ALU_SB_G2
, R_ARM_ALU_SB_G2
},
1768 {BFD_RELOC_ARM_LDR_SB_G0
, R_ARM_LDR_SB_G0
},
1769 {BFD_RELOC_ARM_LDR_SB_G1
, R_ARM_LDR_SB_G1
},
1770 {BFD_RELOC_ARM_LDR_SB_G2
, R_ARM_LDR_SB_G2
},
1771 {BFD_RELOC_ARM_LDRS_SB_G0
, R_ARM_LDRS_SB_G0
},
1772 {BFD_RELOC_ARM_LDRS_SB_G1
, R_ARM_LDRS_SB_G1
},
1773 {BFD_RELOC_ARM_LDRS_SB_G2
, R_ARM_LDRS_SB_G2
},
1774 {BFD_RELOC_ARM_LDC_SB_G0
, R_ARM_LDC_SB_G0
},
1775 {BFD_RELOC_ARM_LDC_SB_G1
, R_ARM_LDC_SB_G1
},
1776 {BFD_RELOC_ARM_LDC_SB_G2
, R_ARM_LDC_SB_G2
}
1779 static reloc_howto_type
*
1780 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1781 bfd_reloc_code_real_type code
)
1784 for (i
= 0; i
< NUM_ELEM (elf32_arm_reloc_map
); i
++)
1785 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1786 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1791 /* Support for core dump NOTE sections */
1793 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1798 switch (note
->descsz
)
1803 case 148: /* Linux/ARM 32-bit*/
1805 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1808 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1817 /* Make a ".reg/999" section. */
1818 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1819 size
, note
->descpos
+ offset
);
1823 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1825 switch (note
->descsz
)
1830 case 124: /* Linux/ARM elf_prpsinfo */
1831 elf_tdata (abfd
)->core_program
1832 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1833 elf_tdata (abfd
)->core_command
1834 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1837 /* Note that for some reason, a spurious space is tacked
1838 onto the end of the args in some (at least one anyway)
1839 implementations, so strip it off if it exists. */
1842 char *command
= elf_tdata (abfd
)->core_command
;
1843 int n
= strlen (command
);
1845 if (0 < n
&& command
[n
- 1] == ' ')
1846 command
[n
- 1] = '\0';
1852 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1853 #define TARGET_LITTLE_NAME "elf32-littlearm"
1854 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1855 #define TARGET_BIG_NAME "elf32-bigarm"
1857 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1858 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1860 typedef unsigned long int insn32
;
1861 typedef unsigned short int insn16
;
1863 /* In lieu of proper flags, assume all EABIv4 or later objects are
1865 #define INTERWORK_FLAG(abfd) \
1866 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1867 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1869 /* The linker script knows the section names for placement.
1870 The entry_names are used to do simple name mangling on the stubs.
1871 Given a function name, and its type, the stub can be found. The
1872 name can be changed. The only requirement is the %s be present. */
1873 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1874 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1876 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1877 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1879 /* The name of the dynamic interpreter. This is put in the .interp
1881 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1883 #ifdef FOUR_WORD_PLT
1885 /* The first entry in a procedure linkage table looks like
1886 this. It is set up so that any shared library function that is
1887 called before the relocation has been set up calls the dynamic
1889 static const bfd_vma elf32_arm_plt0_entry
[] =
1891 0xe52de004, /* str lr, [sp, #-4]! */
1892 0xe59fe010, /* ldr lr, [pc, #16] */
1893 0xe08fe00e, /* add lr, pc, lr */
1894 0xe5bef008, /* ldr pc, [lr, #8]! */
1897 /* Subsequent entries in a procedure linkage table look like
1899 static const bfd_vma elf32_arm_plt_entry
[] =
1901 0xe28fc600, /* add ip, pc, #NN */
1902 0xe28cca00, /* add ip, ip, #NN */
1903 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1904 0x00000000, /* unused */
1909 /* The first entry in a procedure linkage table looks like
1910 this. It is set up so that any shared library function that is
1911 called before the relocation has been set up calls the dynamic
1913 static const bfd_vma elf32_arm_plt0_entry
[] =
1915 0xe52de004, /* str lr, [sp, #-4]! */
1916 0xe59fe004, /* ldr lr, [pc, #4] */
1917 0xe08fe00e, /* add lr, pc, lr */
1918 0xe5bef008, /* ldr pc, [lr, #8]! */
1919 0x00000000, /* &GOT[0] - . */
1922 /* Subsequent entries in a procedure linkage table look like
1924 static const bfd_vma elf32_arm_plt_entry
[] =
1926 0xe28fc600, /* add ip, pc, #0xNN00000 */
1927 0xe28cca00, /* add ip, ip, #0xNN000 */
1928 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1933 /* The format of the first entry in the procedure linkage table
1934 for a VxWorks executable. */
1935 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
1937 0xe52dc008, /* str ip,[sp,#-8]! */
1938 0xe59fc000, /* ldr ip,[pc] */
1939 0xe59cf008, /* ldr pc,[ip,#8] */
1940 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1943 /* The format of subsequent entries in a VxWorks executable. */
1944 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
1946 0xe59fc000, /* ldr ip,[pc] */
1947 0xe59cf000, /* ldr pc,[ip] */
1948 0x00000000, /* .long @got */
1949 0xe59fc000, /* ldr ip,[pc] */
1950 0xea000000, /* b _PLT */
1951 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1954 /* The format of entries in a VxWorks shared library. */
1955 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
1957 0xe59fc000, /* ldr ip,[pc] */
1958 0xe79cf009, /* ldr pc,[ip,r9] */
1959 0x00000000, /* .long @got */
1960 0xe59fc000, /* ldr ip,[pc] */
1961 0xe599f008, /* ldr pc,[r9,#8] */
1962 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1965 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1966 #define PLT_THUMB_STUB_SIZE 4
1967 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
1973 /* The entries in a PLT when using a DLL-based target with multiple
1975 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
1977 0xe51ff004, /* ldr pc, [pc, #-4] */
1978 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1981 /* Used to build a map of a section. This is required for mixed-endian
1984 typedef struct elf32_elf_section_map
1989 elf32_arm_section_map
;
1991 typedef struct _arm_elf_section_data
1993 struct bfd_elf_section_data elf
;
1994 unsigned int mapcount
;
1995 elf32_arm_section_map
*map
;
1997 _arm_elf_section_data
;
1999 #define elf32_arm_section_data(sec) \
2000 ((_arm_elf_section_data *) elf_section_data (sec))
2002 /* The size of the thread control block. */
2005 #define NUM_KNOWN_ATTRIBUTES 32
2007 typedef struct aeabi_attribute
2014 typedef struct aeabi_attribute_list
2016 struct aeabi_attribute_list
*next
;
2018 aeabi_attribute attr
;
2019 } aeabi_attribute_list
;
2021 struct elf32_arm_obj_tdata
2023 struct elf_obj_tdata root
;
2025 /* tls_type for each local got entry. */
2026 char *local_got_tls_type
;
2028 aeabi_attribute known_eabi_attributes
[NUM_KNOWN_ATTRIBUTES
];
2029 aeabi_attribute_list
*other_eabi_attributes
;
2032 #define elf32_arm_tdata(abfd) \
2033 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2035 #define elf32_arm_local_got_tls_type(abfd) \
2036 (elf32_arm_tdata (abfd)->local_got_tls_type)
2039 elf32_arm_mkobject (bfd
*abfd
)
2041 if (abfd
->tdata
.any
== NULL
)
2043 bfd_size_type amt
= sizeof (struct elf32_arm_obj_tdata
);
2044 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2045 if (abfd
->tdata
.any
== NULL
)
2048 return bfd_elf_mkobject (abfd
);
2051 /* The ARM linker needs to keep track of the number of relocs that it
2052 decides to copy in check_relocs for each symbol. This is so that
2053 it can discard PC relative relocs if it doesn't need them when
2054 linking with -Bsymbolic. We store the information in a field
2055 extending the regular ELF linker hash table. */
2057 /* This structure keeps track of the number of relocs we have copied
2058 for a given symbol. */
2059 struct elf32_arm_relocs_copied
2062 struct elf32_arm_relocs_copied
* next
;
2063 /* A section in dynobj. */
2065 /* Number of relocs copied in this section. */
2066 bfd_size_type count
;
2067 /* Number of PC-relative relocs copied in this section. */
2068 bfd_size_type pc_count
;
2071 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2073 /* Arm ELF linker hash entry. */
2074 struct elf32_arm_link_hash_entry
2076 struct elf_link_hash_entry root
;
2078 /* Number of PC relative relocs copied for this symbol. */
2079 struct elf32_arm_relocs_copied
* relocs_copied
;
2081 /* We reference count Thumb references to a PLT entry separately,
2082 so that we can emit the Thumb trampoline only if needed. */
2083 bfd_signed_vma plt_thumb_refcount
;
2085 /* Since PLT entries have variable size if the Thumb prologue is
2086 used, we need to record the index into .got.plt instead of
2087 recomputing it from the PLT offset. */
2088 bfd_signed_vma plt_got_offset
;
2090 #define GOT_UNKNOWN 0
2091 #define GOT_NORMAL 1
2092 #define GOT_TLS_GD 2
2093 #define GOT_TLS_IE 4
2094 unsigned char tls_type
;
2096 /* The symbol marking the real symbol location for exported thumb
2097 symbols with Arm stubs. */
2098 struct elf_link_hash_entry
*export_glue
;
2101 /* Traverse an arm ELF linker hash table. */
2102 #define elf32_arm_link_hash_traverse(table, func, info) \
2103 (elf_link_hash_traverse \
2105 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2108 /* Get the ARM elf linker hash table from a link_info structure. */
2109 #define elf32_arm_hash_table(info) \
2110 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2112 /* ARM ELF linker hash table. */
2113 struct elf32_arm_link_hash_table
2115 /* The main hash table. */
2116 struct elf_link_hash_table root
;
2118 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2119 bfd_size_type thumb_glue_size
;
2121 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2122 bfd_size_type arm_glue_size
;
2124 /* An arbitrary input BFD chosen to hold the glue sections. */
2125 bfd
* bfd_of_glue_owner
;
2127 /* Nonzero to output a BE8 image. */
2130 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2131 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2134 /* The relocation to use for R_ARM_TARGET2 relocations. */
2137 /* Nonzero to fix BX instructions for ARMv4 targets. */
2140 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2143 /* The number of bytes in the initial entry in the PLT. */
2144 bfd_size_type plt_header_size
;
2146 /* The number of bytes in the subsequent PLT etries. */
2147 bfd_size_type plt_entry_size
;
2149 /* True if the target system is VxWorks. */
2152 /* True if the target system is Symbian OS. */
2155 /* True if the target uses REL relocations. */
2158 /* Short-cuts to get to dynamic linker sections. */
2167 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2170 /* Data for R_ARM_TLS_LDM32 relocations. */
2172 bfd_signed_vma refcount
;
2176 /* Small local sym to section mapping cache. */
2177 struct sym_sec_cache sym_sec
;
2179 /* For convenience in allocate_dynrelocs. */
2183 /* Create an entry in an ARM ELF linker hash table. */
2185 static struct bfd_hash_entry
*
2186 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
2187 struct bfd_hash_table
* table
,
2188 const char * string
)
2190 struct elf32_arm_link_hash_entry
* ret
=
2191 (struct elf32_arm_link_hash_entry
*) entry
;
2193 /* Allocate the structure if it has not already been allocated by a
2195 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
2196 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
2198 return (struct bfd_hash_entry
*) ret
;
2200 /* Call the allocation method of the superclass. */
2201 ret
= ((struct elf32_arm_link_hash_entry
*)
2202 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
2206 ret
->relocs_copied
= NULL
;
2207 ret
->tls_type
= GOT_UNKNOWN
;
2208 ret
->plt_thumb_refcount
= 0;
2209 ret
->plt_got_offset
= -1;
2210 ret
->export_glue
= NULL
;
2213 return (struct bfd_hash_entry
*) ret
;
2216 /* Return true if NAME is the name of the relocation section associated
2220 reloc_section_p (struct elf32_arm_link_hash_table
*htab
,
2221 const char *name
, asection
*s
)
2224 return CONST_STRNEQ (name
, ".rel") && strcmp (s
->name
, name
+ 4) == 0;
2226 return CONST_STRNEQ (name
, ".rela") && strcmp (s
->name
, name
+ 5) == 0;
2229 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2230 shortcuts to them in our hash table. */
2233 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
2235 struct elf32_arm_link_hash_table
*htab
;
2237 htab
= elf32_arm_hash_table (info
);
2238 /* BPABI objects never have a GOT, or associated sections. */
2239 if (htab
->symbian_p
)
2242 if (! _bfd_elf_create_got_section (dynobj
, info
))
2245 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2246 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2247 if (!htab
->sgot
|| !htab
->sgotplt
)
2250 htab
->srelgot
= bfd_make_section_with_flags (dynobj
,
2251 RELOC_SECTION (htab
, ".got"),
2252 (SEC_ALLOC
| SEC_LOAD
2255 | SEC_LINKER_CREATED
2257 if (htab
->srelgot
== NULL
2258 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
2263 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2264 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2268 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
2270 struct elf32_arm_link_hash_table
*htab
;
2272 htab
= elf32_arm_hash_table (info
);
2273 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2276 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2279 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2280 htab
->srelplt
= bfd_get_section_by_name (dynobj
,
2281 RELOC_SECTION (htab
, ".plt"));
2282 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2284 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
2285 RELOC_SECTION (htab
, ".bss"));
2287 if (htab
->vxworks_p
)
2289 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
2294 htab
->plt_header_size
= 0;
2295 htab
->plt_entry_size
2296 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
2300 htab
->plt_header_size
2301 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
2302 htab
->plt_entry_size
2303 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
2310 || (!info
->shared
&& !htab
->srelbss
))
2316 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2319 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
2320 struct elf_link_hash_entry
*dir
,
2321 struct elf_link_hash_entry
*ind
)
2323 struct elf32_arm_link_hash_entry
*edir
, *eind
;
2325 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
2326 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
2328 if (eind
->relocs_copied
!= NULL
)
2330 if (edir
->relocs_copied
!= NULL
)
2332 struct elf32_arm_relocs_copied
**pp
;
2333 struct elf32_arm_relocs_copied
*p
;
2335 /* Add reloc counts against the indirect sym to the direct sym
2336 list. Merge any entries against the same section. */
2337 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
2339 struct elf32_arm_relocs_copied
*q
;
2341 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
2342 if (q
->section
== p
->section
)
2344 q
->pc_count
+= p
->pc_count
;
2345 q
->count
+= p
->count
;
2352 *pp
= edir
->relocs_copied
;
2355 edir
->relocs_copied
= eind
->relocs_copied
;
2356 eind
->relocs_copied
= NULL
;
2359 if (ind
->root
.type
== bfd_link_hash_indirect
)
2361 /* Copy over PLT info. */
2362 edir
->plt_thumb_refcount
+= eind
->plt_thumb_refcount
;
2363 eind
->plt_thumb_refcount
= 0;
2365 if (dir
->got
.refcount
<= 0)
2367 edir
->tls_type
= eind
->tls_type
;
2368 eind
->tls_type
= GOT_UNKNOWN
;
2372 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
2375 /* Create an ARM elf linker hash table. */
2377 static struct bfd_link_hash_table
*
2378 elf32_arm_link_hash_table_create (bfd
*abfd
)
2380 struct elf32_arm_link_hash_table
*ret
;
2381 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
2383 ret
= bfd_malloc (amt
);
2387 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
2388 elf32_arm_link_hash_newfunc
,
2389 sizeof (struct elf32_arm_link_hash_entry
)))
2396 ret
->sgotplt
= NULL
;
2397 ret
->srelgot
= NULL
;
2399 ret
->srelplt
= NULL
;
2400 ret
->sdynbss
= NULL
;
2401 ret
->srelbss
= NULL
;
2402 ret
->srelplt2
= NULL
;
2403 ret
->thumb_glue_size
= 0;
2404 ret
->arm_glue_size
= 0;
2405 ret
->bfd_of_glue_owner
= NULL
;
2406 ret
->byteswap_code
= 0;
2407 ret
->target1_is_rel
= 0;
2408 ret
->target2_reloc
= R_ARM_NONE
;
2409 #ifdef FOUR_WORD_PLT
2410 ret
->plt_header_size
= 16;
2411 ret
->plt_entry_size
= 16;
2413 ret
->plt_header_size
= 20;
2414 ret
->plt_entry_size
= 12;
2421 ret
->sym_sec
.abfd
= NULL
;
2423 ret
->tls_ldm_got
.refcount
= 0;
2425 return &ret
->root
.root
;
2428 /* Locate the Thumb encoded calling stub for NAME. */
2430 static struct elf_link_hash_entry
*
2431 find_thumb_glue (struct bfd_link_info
*link_info
,
2436 struct elf_link_hash_entry
*hash
;
2437 struct elf32_arm_link_hash_table
*hash_table
;
2439 /* We need a pointer to the armelf specific hash table. */
2440 hash_table
= elf32_arm_hash_table (link_info
);
2442 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2443 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
2445 BFD_ASSERT (tmp_name
);
2447 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
2449 hash
= elf_link_hash_lookup
2450 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2453 /* xgettext:c-format */
2454 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
2455 input_bfd
, tmp_name
, name
);
2462 /* Locate the ARM encoded calling stub for NAME. */
2464 static struct elf_link_hash_entry
*
2465 find_arm_glue (struct bfd_link_info
*link_info
,
2470 struct elf_link_hash_entry
*myh
;
2471 struct elf32_arm_link_hash_table
*hash_table
;
2473 /* We need a pointer to the elfarm specific hash table. */
2474 hash_table
= elf32_arm_hash_table (link_info
);
2476 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2477 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
2479 BFD_ASSERT (tmp_name
);
2481 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
2483 myh
= elf_link_hash_lookup
2484 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2487 /* xgettext:c-format */
2488 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
2489 input_bfd
, tmp_name
, name
);
2496 /* ARM->Thumb glue (static images):
2500 ldr r12, __func_addr
2503 .word func @ behave as if you saw a ARM_32 reloc.
2505 (relocatable images)
2508 ldr r12, __func_offset
2515 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2516 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
2517 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
2518 static const insn32 a2t3_func_addr_insn
= 0x00000001;
2520 #define ARM2THUMB_PIC_GLUE_SIZE 16
2521 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
2522 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
2523 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
2525 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2529 __func_from_thumb: __func_from_thumb:
2531 nop ldr r6, __func_addr
2533 __func_change_to_arm: bx r6
2535 __func_back_to_thumb:
2541 #define THUMB2ARM_GLUE_SIZE 8
2542 static const insn16 t2a1_bx_pc_insn
= 0x4778;
2543 static const insn16 t2a2_noop_insn
= 0x46c0;
2544 static const insn32 t2a3_b_insn
= 0xea000000;
2546 #ifndef ELFARM_NABI_C_INCLUDED
2548 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
2552 struct elf32_arm_link_hash_table
* globals
;
2554 globals
= elf32_arm_hash_table (info
);
2556 BFD_ASSERT (globals
!= NULL
);
2558 if (globals
->arm_glue_size
!= 0)
2560 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2562 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2563 ARM2THUMB_GLUE_SECTION_NAME
);
2565 BFD_ASSERT (s
!= NULL
);
2567 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
2569 s
->size
= globals
->arm_glue_size
;
2573 if (globals
->thumb_glue_size
!= 0)
2575 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2577 s
= bfd_get_section_by_name
2578 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2580 BFD_ASSERT (s
!= NULL
);
2582 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
2584 s
->size
= globals
->thumb_glue_size
;
2591 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2592 returns the symbol identifying teh stub. */
2593 static struct elf_link_hash_entry
*
2594 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
2595 struct elf_link_hash_entry
* h
)
2597 const char * name
= h
->root
.root
.string
;
2600 struct elf_link_hash_entry
* myh
;
2601 struct bfd_link_hash_entry
* bh
;
2602 struct elf32_arm_link_hash_table
* globals
;
2605 globals
= elf32_arm_hash_table (link_info
);
2607 BFD_ASSERT (globals
!= NULL
);
2608 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2610 s
= bfd_get_section_by_name
2611 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
2613 BFD_ASSERT (s
!= NULL
);
2615 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
2617 BFD_ASSERT (tmp_name
);
2619 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
2621 myh
= elf_link_hash_lookup
2622 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2626 /* We've already seen this guy. */
2631 /* The only trick here is using hash_table->arm_glue_size as the value.
2632 Even though the section isn't allocated yet, this is where we will be
2635 val
= globals
->arm_glue_size
+ 1;
2636 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
2637 tmp_name
, BSF_GLOBAL
, s
, val
,
2638 NULL
, TRUE
, FALSE
, &bh
);
2640 myh
= (struct elf_link_hash_entry
*) bh
;
2641 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
2642 myh
->forced_local
= 1;
2646 if ((link_info
->shared
|| globals
->root
.is_relocatable_executable
))
2647 globals
->arm_glue_size
+= ARM2THUMB_PIC_GLUE_SIZE
;
2649 globals
->arm_glue_size
+= ARM2THUMB_STATIC_GLUE_SIZE
;
2655 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
2656 struct elf_link_hash_entry
*h
)
2658 const char *name
= h
->root
.root
.string
;
2661 struct elf_link_hash_entry
*myh
;
2662 struct bfd_link_hash_entry
*bh
;
2663 struct elf32_arm_link_hash_table
*hash_table
;
2666 hash_table
= elf32_arm_hash_table (link_info
);
2668 BFD_ASSERT (hash_table
!= NULL
);
2669 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
2671 s
= bfd_get_section_by_name
2672 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2674 BFD_ASSERT (s
!= NULL
);
2676 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2677 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
2679 BFD_ASSERT (tmp_name
);
2681 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
2683 myh
= elf_link_hash_lookup
2684 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2688 /* We've already seen this guy. */
2694 val
= hash_table
->thumb_glue_size
+ 1;
2695 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2696 tmp_name
, BSF_GLOBAL
, s
, val
,
2697 NULL
, TRUE
, FALSE
, &bh
);
2699 /* If we mark it 'Thumb', the disassembler will do a better job. */
2700 myh
= (struct elf_link_hash_entry
*) bh
;
2701 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
2702 myh
->forced_local
= 1;
2706 #define CHANGE_TO_ARM "__%s_change_to_arm"
2707 #define BACK_FROM_ARM "__%s_back_from_arm"
2709 /* Allocate another symbol to mark where we switch to Arm mode. */
2710 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2711 + strlen (CHANGE_TO_ARM
) + 1);
2713 BFD_ASSERT (tmp_name
);
2715 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
2718 val
= hash_table
->thumb_glue_size
+ 4,
2719 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2720 tmp_name
, BSF_LOCAL
, s
, val
,
2721 NULL
, TRUE
, FALSE
, &bh
);
2725 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
2730 /* Add the glue sections to ABFD. This function is called from the
2731 linker scripts in ld/emultempl/{armelf}.em. */
2734 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
2735 struct bfd_link_info
*info
)
2740 /* If we are only performing a partial
2741 link do not bother adding the glue. */
2742 if (info
->relocatable
)
2745 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
2749 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2750 will prevent elf_link_input_bfd() from processing the contents
2752 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
2754 sec
= bfd_make_section_with_flags (abfd
,
2755 ARM2THUMB_GLUE_SECTION_NAME
,
2759 || !bfd_set_section_alignment (abfd
, sec
, 2))
2762 /* Set the gc mark to prevent the section from being removed by garbage
2763 collection, despite the fact that no relocs refer to this section. */
2767 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
2771 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2772 | SEC_CODE
| SEC_READONLY
;
2774 sec
= bfd_make_section_with_flags (abfd
,
2775 THUMB2ARM_GLUE_SECTION_NAME
,
2779 || !bfd_set_section_alignment (abfd
, sec
, 2))
2788 /* Select a BFD to be used to hold the sections used by the glue code.
2789 This function is called from the linker scripts in ld/emultempl/
2793 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
2795 struct elf32_arm_link_hash_table
*globals
;
2797 /* If we are only performing a partial link
2798 do not bother getting a bfd to hold the glue. */
2799 if (info
->relocatable
)
2802 /* Make sure we don't attach the glue sections to a dynamic object. */
2803 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
2805 globals
= elf32_arm_hash_table (info
);
2807 BFD_ASSERT (globals
!= NULL
);
2809 if (globals
->bfd_of_glue_owner
!= NULL
)
2812 /* Save the bfd for later use. */
2813 globals
->bfd_of_glue_owner
= abfd
;
2818 static void check_use_blx(struct elf32_arm_link_hash_table
*globals
)
2820 if (elf32_arm_get_eabi_attr_int (globals
->obfd
, Tag_CPU_arch
) > 2)
2821 globals
->use_blx
= 1;
2825 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
2826 struct bfd_link_info
*link_info
,
2829 Elf_Internal_Shdr
*symtab_hdr
;
2830 Elf_Internal_Rela
*internal_relocs
= NULL
;
2831 Elf_Internal_Rela
*irel
, *irelend
;
2832 bfd_byte
*contents
= NULL
;
2835 struct elf32_arm_link_hash_table
*globals
;
2837 /* If we are only performing a partial link do not bother
2838 to construct any glue. */
2839 if (link_info
->relocatable
)
2842 /* Here we have a bfd that is to be included on the link. We have a hook
2843 to do reloc rummaging, before section sizes are nailed down. */
2844 globals
= elf32_arm_hash_table (link_info
);
2845 check_use_blx (globals
);
2847 BFD_ASSERT (globals
!= NULL
);
2848 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2850 if (byteswap_code
&& !bfd_big_endian (abfd
))
2852 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2856 globals
->byteswap_code
= byteswap_code
;
2858 /* Rummage around all the relocs and map the glue vectors. */
2859 sec
= abfd
->sections
;
2864 for (; sec
!= NULL
; sec
= sec
->next
)
2866 if (sec
->reloc_count
== 0)
2869 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2871 /* Load the relocs. */
2873 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
2874 (Elf_Internal_Rela
*) NULL
, FALSE
);
2876 if (internal_relocs
== NULL
)
2879 irelend
= internal_relocs
+ sec
->reloc_count
;
2880 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2883 unsigned long r_index
;
2885 struct elf_link_hash_entry
*h
;
2887 r_type
= ELF32_R_TYPE (irel
->r_info
);
2888 r_index
= ELF32_R_SYM (irel
->r_info
);
2890 /* These are the only relocation types we care about. */
2891 if ( r_type
!= R_ARM_PC24
2892 && r_type
!= R_ARM_PLT32
2893 && r_type
!= R_ARM_CALL
2894 && r_type
!= R_ARM_JUMP24
2895 && r_type
!= R_ARM_THM_CALL
)
2898 /* Get the section contents if we haven't done so already. */
2899 if (contents
== NULL
)
2901 /* Get cached copy if it exists. */
2902 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2903 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2906 /* Go get them off disk. */
2907 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2912 /* If the relocation is not against a symbol it cannot concern us. */
2915 /* We don't care about local symbols. */
2916 if (r_index
< symtab_hdr
->sh_info
)
2919 /* This is an external symbol. */
2920 r_index
-= symtab_hdr
->sh_info
;
2921 h
= (struct elf_link_hash_entry
*)
2922 elf_sym_hashes (abfd
)[r_index
];
2924 /* If the relocation is against a static symbol it must be within
2925 the current section and so cannot be a cross ARM/Thumb relocation. */
2929 /* If the call will go through a PLT entry then we do not need
2931 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2940 /* This one is a call from arm code. We need to look up
2941 the target of the call. If it is a thumb target, we
2943 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
2944 && !(r_type
== R_ARM_CALL
&& globals
->use_blx
))
2945 record_arm_to_thumb_glue (link_info
, h
);
2948 case R_ARM_THM_CALL
:
2949 /* This one is a call from thumb code. We look
2950 up the target of the call. If it is not a thumb
2951 target, we insert glue. */
2952 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
&& !globals
->use_blx
)
2953 record_thumb_to_arm_glue (link_info
, h
);
2961 if (contents
!= NULL
2962 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2966 if (internal_relocs
!= NULL
2967 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2968 free (internal_relocs
);
2969 internal_relocs
= NULL
;
2975 if (contents
!= NULL
2976 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2978 if (internal_relocs
!= NULL
2979 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2980 free (internal_relocs
);
2987 /* Set target relocation values needed during linking. */
2990 bfd_elf32_arm_set_target_relocs (struct bfd_link_info
*link_info
,
2992 char * target2_type
,
2996 struct elf32_arm_link_hash_table
*globals
;
2998 globals
= elf32_arm_hash_table (link_info
);
3000 globals
->target1_is_rel
= target1_is_rel
;
3001 if (strcmp (target2_type
, "rel") == 0)
3002 globals
->target2_reloc
= R_ARM_REL32
;
3003 else if (strcmp (target2_type
, "abs") == 0)
3004 globals
->target2_reloc
= R_ARM_ABS32
;
3005 else if (strcmp (target2_type
, "got-rel") == 0)
3006 globals
->target2_reloc
= R_ARM_GOT_PREL
;
3009 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3012 globals
->fix_v4bx
= fix_v4bx
;
3013 globals
->use_blx
|= use_blx
;
3016 /* The thumb form of a long branch is a bit finicky, because the offset
3017 encoding is split over two fields, each in it's own instruction. They
3018 can occur in any order. So given a thumb form of long branch, and an
3019 offset, insert the offset into the thumb branch and return finished
3022 It takes two thumb instructions to encode the target address. Each has
3023 11 bits to invest. The upper 11 bits are stored in one (identified by
3024 H-0.. see below), the lower 11 bits are stored in the other (identified
3027 Combine together and shifted left by 1 (it's a half word address) and
3031 H-0, upper address-0 = 000
3033 H-1, lower address-0 = 800
3035 They can be ordered either way, but the arm tools I've seen always put
3036 the lower one first. It probably doesn't matter. krk@cygnus.com
3038 XXX: Actually the order does matter. The second instruction (H-1)
3039 moves the computed address into the PC, so it must be the second one
3040 in the sequence. The problem, however is that whilst little endian code
3041 stores the instructions in HI then LOW order, big endian code does the
3042 reverse. nickc@cygnus.com. */
3044 #define LOW_HI_ORDER 0xF800F000
3045 #define HI_LOW_ORDER 0xF000F800
3048 insert_thumb_branch (insn32 br_insn
, int rel_off
)
3050 unsigned int low_bits
;
3051 unsigned int high_bits
;
3053 BFD_ASSERT ((rel_off
& 1) != 1);
3055 rel_off
>>= 1; /* Half word aligned address. */
3056 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
3057 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
3059 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
3060 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
3061 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
3062 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
3064 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3065 abort (); /* Error - not a valid branch instruction form. */
3071 /* Store an Arm insn into an output section not processed by
3072 elf32_arm_write_section. */
3075 put_arm_insn (struct elf32_arm_link_hash_table
*htab
,
3076 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3078 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3079 bfd_putl32 (val
, ptr
);
3081 bfd_putb32 (val
, ptr
);
3085 /* Store a 16-bit Thumb insn into an output section not processed by
3086 elf32_arm_write_section. */
3089 put_thumb_insn (struct elf32_arm_link_hash_table
*htab
,
3090 bfd
* output_bfd
, bfd_vma val
, void * ptr
)
3092 if (htab
->byteswap_code
!= bfd_little_endian (output_bfd
))
3093 bfd_putl16 (val
, ptr
);
3095 bfd_putb16 (val
, ptr
);
3099 /* Thumb code calling an ARM function. */
3102 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
3106 asection
* input_section
,
3107 bfd_byte
* hit_data
,
3110 bfd_signed_vma addend
,
3115 unsigned long int tmp
;
3116 long int ret_offset
;
3117 struct elf_link_hash_entry
* myh
;
3118 struct elf32_arm_link_hash_table
* globals
;
3120 myh
= find_thumb_glue (info
, name
, input_bfd
);
3124 globals
= elf32_arm_hash_table (info
);
3126 BFD_ASSERT (globals
!= NULL
);
3127 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
3129 my_offset
= myh
->root
.u
.def
.value
;
3131 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
3132 THUMB2ARM_GLUE_SECTION_NAME
);
3134 BFD_ASSERT (s
!= NULL
);
3135 BFD_ASSERT (s
->contents
!= NULL
);
3136 BFD_ASSERT (s
->output_section
!= NULL
);
3138 if ((my_offset
& 0x01) == 0x01)
3141 && sym_sec
->owner
!= NULL
3142 && !INTERWORK_FLAG (sym_sec
->owner
))
3144 (*_bfd_error_handler
)
3145 (_("%B(%s): warning: interworking not enabled.\n"
3146 " first occurrence: %B: thumb call to arm"),
3147 sym_sec
->owner
, input_bfd
, name
);
3153 myh
->root
.u
.def
.value
= my_offset
;
3155 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
3156 s
->contents
+ my_offset
);
3158 put_thumb_insn (globals
, output_bfd
, (bfd_vma
) t2a2_noop_insn
,
3159 s
->contents
+ my_offset
+ 2);
3162 /* Address of destination of the stub. */
3163 ((bfd_signed_vma
) val
)
3165 /* Offset from the start of the current section
3166 to the start of the stubs. */
3168 /* Offset of the start of this stub from the start of the stubs. */
3170 /* Address of the start of the current section. */
3171 + s
->output_section
->vma
)
3172 /* The branch instruction is 4 bytes into the stub. */
3174 /* ARM branches work from the pc of the instruction + 8. */
3177 put_arm_insn (globals
, output_bfd
,
3178 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
3179 s
->contents
+ my_offset
+ 4);
3182 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
3184 /* Now go back and fix up the original BL insn to point to here. */
3186 /* Address of where the stub is located. */
3187 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
3188 /* Address of where the BL is located. */
3189 - (input_section
->output_section
->vma
+ input_section
->output_offset
3191 /* Addend in the relocation. */
3193 /* Biassing for PC-relative addressing. */
3196 tmp
= bfd_get_32 (input_bfd
, hit_data
3197 - input_section
->vma
);
3199 bfd_put_32 (output_bfd
,
3200 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
3201 hit_data
- input_section
->vma
);
3206 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
3208 static struct elf_link_hash_entry
*
3209 elf32_arm_create_thumb_stub (struct bfd_link_info
* info
,
3218 long int ret_offset
;
3219 struct elf_link_hash_entry
* myh
;
3220 struct elf32_arm_link_hash_table
* globals
;
3222 myh
= find_arm_glue (info
, name
, input_bfd
);
3226 globals
= elf32_arm_hash_table (info
);
3228 BFD_ASSERT (globals
!= NULL
);
3229 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
3231 my_offset
= myh
->root
.u
.def
.value
;
3233 if ((my_offset
& 0x01) == 0x01)
3236 && sym_sec
->owner
!= NULL
3237 && !INTERWORK_FLAG (sym_sec
->owner
))
3239 (*_bfd_error_handler
)
3240 (_("%B(%s): warning: interworking not enabled.\n"
3241 " first occurrence: %B: arm call to thumb"),
3242 sym_sec
->owner
, input_bfd
, name
);
3246 myh
->root
.u
.def
.value
= my_offset
;
3248 if ((info
->shared
|| globals
->root
.is_relocatable_executable
))
3250 /* For relocatable objects we can't use absolute addresses,
3251 so construct the address from a relative offset. */
3252 /* TODO: If the offset is small it's probably worth
3253 constructing the address with adds. */
3254 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
3255 s
->contents
+ my_offset
);
3256 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
3257 s
->contents
+ my_offset
+ 4);
3258 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
3259 s
->contents
+ my_offset
+ 8);
3260 /* Adjust the offset by 4 for the position of the add,
3261 and 8 for the pipeline offset. */
3262 ret_offset
= (val
- (s
->output_offset
3263 + s
->output_section
->vma
3266 bfd_put_32 (output_bfd
, ret_offset
,
3267 s
->contents
+ my_offset
+ 12);
3271 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
3272 s
->contents
+ my_offset
);
3274 put_arm_insn (globals
, output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
3275 s
->contents
+ my_offset
+ 4);
3277 /* It's a thumb address. Add the low order bit. */
3278 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
3279 s
->contents
+ my_offset
+ 8);
3283 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
3288 /* Arm code calling a Thumb function. */
3291 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
3295 asection
* input_section
,
3296 bfd_byte
* hit_data
,
3299 bfd_signed_vma addend
,
3302 unsigned long int tmp
;
3305 long int ret_offset
;
3306 struct elf_link_hash_entry
* myh
;
3307 struct elf32_arm_link_hash_table
* globals
;
3309 globals
= elf32_arm_hash_table (info
);
3311 BFD_ASSERT (globals
!= NULL
);
3312 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
3314 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
3315 ARM2THUMB_GLUE_SECTION_NAME
);
3316 BFD_ASSERT (s
!= NULL
);
3317 BFD_ASSERT (s
->contents
!= NULL
);
3318 BFD_ASSERT (s
->output_section
!= NULL
);
3320 myh
= elf32_arm_create_thumb_stub (info
, name
, input_bfd
, output_bfd
,
3325 my_offset
= myh
->root
.u
.def
.value
;
3326 tmp
= bfd_get_32 (input_bfd
, hit_data
);
3327 tmp
= tmp
& 0xFF000000;
3329 /* Somehow these are both 4 too far, so subtract 8. */
3330 ret_offset
= (s
->output_offset
3332 + s
->output_section
->vma
3333 - (input_section
->output_offset
3334 + input_section
->output_section
->vma
3338 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
3340 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
3345 /* Populate Arm stub for an exported Thumb function. */
3348 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry
*h
, void * inf
)
3350 struct bfd_link_info
* info
= (struct bfd_link_info
*) inf
;
3352 struct elf_link_hash_entry
* myh
;
3353 struct elf32_arm_link_hash_entry
*eh
;
3354 struct elf32_arm_link_hash_table
* globals
;
3358 eh
= elf32_arm_hash_entry(h
);
3359 /* Allocate stubs for exported Thumb functions on v4t. */
3360 if (eh
->export_glue
== NULL
)
3363 globals
= elf32_arm_hash_table (info
);
3365 BFD_ASSERT (globals
!= NULL
);
3366 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
3368 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
3369 ARM2THUMB_GLUE_SECTION_NAME
);
3370 BFD_ASSERT (s
!= NULL
);
3371 BFD_ASSERT (s
->contents
!= NULL
);
3372 BFD_ASSERT (s
->output_section
!= NULL
);
3374 sec
= eh
->export_glue
->root
.u
.def
.section
;
3375 val
= eh
->export_glue
->root
.u
.def
.value
+ sec
->output_offset
3376 + sec
->output_section
->vma
;
3377 myh
= elf32_arm_create_thumb_stub (info
, h
->root
.root
.string
,
3378 h
->root
.u
.def
.section
->owner
,
3379 globals
->obfd
, sec
, val
, s
);
3384 /* Generate Arm stubs for exported Thumb symbols. */
3386 elf32_arm_begin_write_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
3387 struct bfd_link_info
*link_info
)
3389 struct elf32_arm_link_hash_table
* globals
;
3394 globals
= elf32_arm_hash_table (link_info
);
3395 /* If blx is available then exported Thumb symbols are OK and there is
3397 if (globals
->use_blx
)
3400 elf_link_hash_traverse (&globals
->root
, elf32_arm_to_thumb_export_stub
,
3404 /* Some relocations map to different relocations depending on the
3405 target. Return the real relocation. */
3407 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
3413 if (globals
->target1_is_rel
)
3419 return globals
->target2_reloc
;
3426 /* Return the base VMA address which should be subtracted from real addresses
3427 when resolving @dtpoff relocation.
3428 This is PT_TLS segment p_vaddr. */
3431 dtpoff_base (struct bfd_link_info
*info
)
3433 /* If tls_sec is NULL, we should have signalled an error already. */
3434 if (elf_hash_table (info
)->tls_sec
== NULL
)
3436 return elf_hash_table (info
)->tls_sec
->vma
;
3439 /* Return the relocation value for @tpoff relocation
3440 if STT_TLS virtual address is ADDRESS. */
3443 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
3445 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3448 /* If tls_sec is NULL, we should have signalled an error already. */
3449 if (htab
->tls_sec
== NULL
)
3451 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
3452 return address
- htab
->tls_sec
->vma
+ base
;
3455 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
3456 VALUE is the relocation value. */
3458 static bfd_reloc_status_type
3459 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
3462 return bfd_reloc_overflow
;
3464 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
3465 bfd_put_32 (abfd
, value
, data
);
3466 return bfd_reloc_ok
;
3469 /* For a given value of n, calculate the value of G_n as required to
3470 deal with group relocations. We return it in the form of an
3471 encoded constant-and-rotation, together with the final residual. If n is
3472 specified as less than zero, then final_residual is filled with the
3473 input value and no further action is performed. */
3476 calculate_group_reloc_mask (bfd_vma value
, int n
, bfd_vma
*final_residual
)
3480 bfd_vma encoded_g_n
= 0;
3481 bfd_vma residual
= value
; /* Also known as Y_n. */
3483 for (current_n
= 0; current_n
<= n
; current_n
++)
3487 /* Calculate which part of the value to mask. */
3494 /* Determine the most significant bit in the residual and
3495 align the resulting value to a 2-bit boundary. */
3496 for (msb
= 30; msb
>= 0; msb
-= 2)
3497 if (residual
& (3 << msb
))
3500 /* The desired shift is now (msb - 6), or zero, whichever
3507 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
3508 g_n
= residual
& (0xff << shift
);
3509 encoded_g_n
= (g_n
>> shift
)
3510 | ((g_n
<= 0xff ? 0 : (32 - shift
) / 2) << 8);
3512 /* Calculate the residual for the next time around. */
3516 *final_residual
= residual
;
3521 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
3522 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
3524 identify_add_or_sub(bfd_vma insn
)
3526 int opcode
= insn
& 0x1e00000;
3528 if (opcode
== 1 << 23) /* ADD */
3531 if (opcode
== 1 << 22) /* SUB */
3537 /* Perform a relocation as part of a final link. */
3539 static bfd_reloc_status_type
3540 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
3543 asection
* input_section
,
3544 bfd_byte
* contents
,
3545 Elf_Internal_Rela
* rel
,
3547 struct bfd_link_info
* info
,
3549 const char * sym_name
,
3551 struct elf_link_hash_entry
* h
,
3552 bfd_boolean
* unresolved_reloc_p
)
3554 unsigned long r_type
= howto
->type
;
3555 unsigned long r_symndx
;
3556 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
3557 bfd
* dynobj
= NULL
;
3558 Elf_Internal_Shdr
* symtab_hdr
;
3559 struct elf_link_hash_entry
** sym_hashes
;
3560 bfd_vma
* local_got_offsets
;
3561 asection
* sgot
= NULL
;
3562 asection
* splt
= NULL
;
3563 asection
* sreloc
= NULL
;
3565 bfd_signed_vma signed_addend
;
3566 struct elf32_arm_link_hash_table
* globals
;
3568 globals
= elf32_arm_hash_table (info
);
3570 /* Some relocation type map to different relocations depending on the
3571 target. We pick the right one here. */
3572 r_type
= arm_real_reloc_type (globals
, r_type
);
3573 if (r_type
!= howto
->type
)
3574 howto
= elf32_arm_howto_from_type (r_type
);
3576 /* If the start address has been set, then set the EF_ARM_HASENTRY
3577 flag. Setting this more than once is redundant, but the cost is
3578 not too high, and it keeps the code simple.
3580 The test is done here, rather than somewhere else, because the
3581 start address is only set just before the final link commences.
3583 Note - if the user deliberately sets a start address of 0, the
3584 flag will not be set. */
3585 if (bfd_get_start_address (output_bfd
) != 0)
3586 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
3588 dynobj
= elf_hash_table (info
)->dynobj
;
3591 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3592 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3594 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
3595 sym_hashes
= elf_sym_hashes (input_bfd
);
3596 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3597 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3599 if (globals
->use_rel
)
3601 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
3603 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3606 signed_addend
&= ~ howto
->src_mask
;
3607 signed_addend
|= addend
;
3610 signed_addend
= addend
;
3613 addend
= signed_addend
= rel
->r_addend
;
3618 /* We don't need to find a value for this symbol. It's just a
3620 *unresolved_reloc_p
= FALSE
;
3621 return bfd_reloc_ok
;
3624 if (!globals
->vxworks_p
)
3625 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
3635 /* r_symndx will be zero only for relocs against symbols
3636 from removed linkonce sections, or sections discarded by
3639 return bfd_reloc_ok
;
3641 /* Handle relocations which should use the PLT entry. ABS32/REL32
3642 will use the symbol's value, which may point to a PLT entry, but we
3643 don't need to handle that here. If we created a PLT entry, all
3644 branches in this object should go to it. */
3645 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
3648 && h
->plt
.offset
!= (bfd_vma
) -1)
3650 /* If we've created a .plt section, and assigned a PLT entry to
3651 this function, it should not be known to bind locally. If
3652 it were, we would have cleared the PLT entry. */
3653 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
3655 value
= (splt
->output_section
->vma
3656 + splt
->output_offset
3658 *unresolved_reloc_p
= FALSE
;
3659 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3660 contents
, rel
->r_offset
, value
,
3664 /* When generating a shared object or relocatable executable, these
3665 relocations are copied into the output file to be resolved at
3667 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
3668 && (input_section
->flags
& SEC_ALLOC
)
3669 && (r_type
!= R_ARM_REL32
3670 || !SYMBOL_CALLS_LOCAL (info
, h
))
3672 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3673 || h
->root
.type
!= bfd_link_hash_undefweak
)
3674 && r_type
!= R_ARM_PC24
3675 && r_type
!= R_ARM_CALL
3676 && r_type
!= R_ARM_JUMP24
3677 && r_type
!= R_ARM_PREL31
3678 && r_type
!= R_ARM_PLT32
)
3680 Elf_Internal_Rela outrel
;
3682 bfd_boolean skip
, relocate
;
3684 *unresolved_reloc_p
= FALSE
;
3690 name
= (bfd_elf_string_from_elf_section
3692 elf_elfheader (input_bfd
)->e_shstrndx
,
3693 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3695 return bfd_reloc_notsupported
;
3697 BFD_ASSERT (reloc_section_p (globals
, name
, input_section
));
3699 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3700 BFD_ASSERT (sreloc
!= NULL
);
3706 outrel
.r_addend
= addend
;
3708 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3710 if (outrel
.r_offset
== (bfd_vma
) -1)
3712 else if (outrel
.r_offset
== (bfd_vma
) -2)
3713 skip
= TRUE
, relocate
= TRUE
;
3714 outrel
.r_offset
+= (input_section
->output_section
->vma
3715 + input_section
->output_offset
);
3718 memset (&outrel
, 0, sizeof outrel
);
3723 || !h
->def_regular
))
3724 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3729 /* This symbol is local, or marked to become local. */
3730 if (sym_flags
== STT_ARM_TFUNC
)
3732 if (globals
->symbian_p
)
3736 /* On Symbian OS, the data segment and text segement
3737 can be relocated independently. Therefore, we
3738 must indicate the segment to which this
3739 relocation is relative. The BPABI allows us to
3740 use any symbol in the right segment; we just use
3741 the section symbol as it is convenient. (We
3742 cannot use the symbol given by "h" directly as it
3743 will not appear in the dynamic symbol table.)
3745 Note that the dynamic linker ignores the section
3746 symbol value, so we don't subtract osec->vma
3747 from the emitted reloc addend. */
3749 osec
= sym_sec
->output_section
;
3751 osec
= input_section
->output_section
;
3752 symbol
= elf_section_data (osec
)->dynindx
;
3755 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
3757 if ((osec
->flags
& SEC_READONLY
) == 0
3758 && htab
->data_index_section
!= NULL
)
3759 osec
= htab
->data_index_section
;
3761 osec
= htab
->text_index_section
;
3762 symbol
= elf_section_data (osec
)->dynindx
;
3764 BFD_ASSERT (symbol
!= 0);
3767 /* On SVR4-ish systems, the dynamic loader cannot
3768 relocate the text and data segments independently,
3769 so the symbol does not matter. */
3771 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
3772 if (globals
->use_rel
)
3775 outrel
.r_addend
+= value
;
3778 loc
= sreloc
->contents
;
3779 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
3780 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3782 /* If this reloc is against an external symbol, we do not want to
3783 fiddle with the addend. Otherwise, we need to include the symbol
3784 value so that it becomes an addend for the dynamic reloc. */
3786 return bfd_reloc_ok
;
3788 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3789 contents
, rel
->r_offset
, value
,
3792 else switch (r_type
)
3795 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
3797 case R_ARM_XPC25
: /* Arm BLX instruction. */
3800 case R_ARM_PC24
: /* Arm B/BL instruction */
3802 if (r_type
== R_ARM_XPC25
)
3804 /* Check for Arm calling Arm function. */
3805 /* FIXME: Should we translate the instruction into a BL
3806 instruction instead ? */
3807 if (sym_flags
!= STT_ARM_TFUNC
)
3808 (*_bfd_error_handler
)
3809 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3811 h
? h
->root
.root
.string
: "(local)");
3813 else if (r_type
!= R_ARM_CALL
|| !globals
->use_blx
)
3815 /* Check for Arm calling Thumb function. */
3816 if (sym_flags
== STT_ARM_TFUNC
)
3818 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
3819 output_bfd
, input_section
,
3820 hit_data
, sym_sec
, rel
->r_offset
,
3821 signed_addend
, value
);
3822 return bfd_reloc_ok
;
3826 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3828 S is the address of the symbol in the relocation.
3829 P is address of the instruction being relocated.
3830 A is the addend (extracted from the instruction) in bytes.
3832 S is held in 'value'.
3833 P is the base address of the section containing the
3834 instruction plus the offset of the reloc into that
3836 (input_section->output_section->vma +
3837 input_section->output_offset +
3839 A is the addend, converted into bytes, ie:
3842 Note: None of these operations have knowledge of the pipeline
3843 size of the processor, thus it is up to the assembler to
3844 encode this information into the addend. */
3845 value
-= (input_section
->output_section
->vma
3846 + input_section
->output_offset
);
3847 value
-= rel
->r_offset
;
3848 if (globals
->use_rel
)
3849 value
+= (signed_addend
<< howto
->size
);
3851 /* RELA addends do not have to be adjusted by howto->size. */
3852 value
+= signed_addend
;
3854 signed_addend
= value
;
3855 signed_addend
>>= howto
->rightshift
;
3857 /* It is not an error for an undefined weak reference to be
3858 out of range. Any program that branches to such a symbol
3859 is going to crash anyway, so there is no point worrying
3860 about getting the destination exactly right. */
3861 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3863 /* Perform a signed range check. */
3864 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
3865 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
3866 return bfd_reloc_overflow
;
3869 addend
= (value
& 2);
3871 value
= (signed_addend
& howto
->dst_mask
)
3872 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
3874 /* Set the H bit in the BLX instruction. */
3875 if (sym_flags
== STT_ARM_TFUNC
)
3880 value
&= ~(bfd_vma
)(1 << 24);
3882 if (r_type
== R_ARM_CALL
)
3884 /* Select the correct instruction (BL or BLX). */
3885 if (sym_flags
== STT_ARM_TFUNC
)
3889 value
&= ~(bfd_vma
)(1 << 28);
3897 if (sym_flags
== STT_ARM_TFUNC
)
3903 if (sym_flags
== STT_ARM_TFUNC
)
3905 value
-= (input_section
->output_section
->vma
3906 + input_section
->output_offset
+ rel
->r_offset
);
3910 value
-= (input_section
->output_section
->vma
3911 + input_section
->output_offset
+ rel
->r_offset
);
3912 value
+= signed_addend
;
3913 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3915 /* Check for overflow */
3916 if ((value
^ (value
>> 1)) & (1 << 30))
3917 return bfd_reloc_overflow
;
3919 value
&= 0x7fffffff;
3920 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
3921 if (sym_flags
== STT_ARM_TFUNC
)
3926 bfd_put_32 (input_bfd
, value
, hit_data
);
3927 return bfd_reloc_ok
;
3931 if ((long) value
> 0x7f || (long) value
< -0x80)
3932 return bfd_reloc_overflow
;
3934 bfd_put_8 (input_bfd
, value
, hit_data
);
3935 return bfd_reloc_ok
;
3940 if ((long) value
> 0x7fff || (long) value
< -0x8000)
3941 return bfd_reloc_overflow
;
3943 bfd_put_16 (input_bfd
, value
, hit_data
);
3944 return bfd_reloc_ok
;
3946 case R_ARM_THM_ABS5
:
3947 /* Support ldr and str instructions for the thumb. */
3948 if (globals
->use_rel
)
3950 /* Need to refetch addend. */
3951 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
3952 /* ??? Need to determine shift amount from operand size. */
3953 addend
>>= howto
->rightshift
;
3957 /* ??? Isn't value unsigned? */
3958 if ((long) value
> 0x1f || (long) value
< -0x10)
3959 return bfd_reloc_overflow
;
3961 /* ??? Value needs to be properly shifted into place first. */
3962 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
3963 bfd_put_16 (input_bfd
, value
, hit_data
);
3964 return bfd_reloc_ok
;
3966 case R_ARM_THM_ALU_PREL_11_0
:
3967 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
3970 bfd_signed_vma relocation
;
3972 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
3973 | bfd_get_16 (input_bfd
, hit_data
+ 2);
3975 if (globals
->use_rel
)
3977 signed_addend
= (insn
& 0xff) | ((insn
& 0x7000) >> 4)
3978 | ((insn
& (1 << 26)) >> 15);
3979 if (insn
& 0xf00000)
3980 signed_addend
= -signed_addend
;
3983 relocation
= value
+ signed_addend
;
3984 relocation
-= (input_section
->output_section
->vma
3985 + input_section
->output_offset
3988 value
= abs (relocation
);
3990 if (value
>= 0x1000)
3991 return bfd_reloc_overflow
;
3993 insn
= (insn
& 0xfb0f8f00) | (value
& 0xff)
3994 | ((value
& 0x700) << 4)
3995 | ((value
& 0x800) << 15);
3999 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
4000 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
4002 return bfd_reloc_ok
;
4005 case R_ARM_THM_PC12
:
4006 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4009 bfd_signed_vma relocation
;
4011 insn
= (bfd_get_16 (input_bfd
, hit_data
) << 16)
4012 | bfd_get_16 (input_bfd
, hit_data
+ 2);
4014 if (globals
->use_rel
)
4016 signed_addend
= insn
& 0xfff;
4017 if (!(insn
& (1 << 23)))
4018 signed_addend
= -signed_addend
;
4021 relocation
= value
+ signed_addend
;
4022 relocation
-= (input_section
->output_section
->vma
4023 + input_section
->output_offset
4026 value
= abs (relocation
);
4028 if (value
>= 0x1000)
4029 return bfd_reloc_overflow
;
4031 insn
= (insn
& 0xff7ff000) | value
;
4032 if (relocation
>= 0)
4035 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
4036 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
4038 return bfd_reloc_ok
;
4041 case R_ARM_THM_XPC22
:
4042 case R_ARM_THM_CALL
:
4043 /* Thumb BL (branch long instruction). */
4046 bfd_boolean overflow
= FALSE
;
4047 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
4048 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
4049 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
4050 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
4052 bfd_signed_vma signed_check
;
4054 /* Need to refetch the addend and squish the two 11 bit pieces
4056 if (globals
->use_rel
)
4058 bfd_vma upper
= upper_insn
& 0x7ff;
4059 bfd_vma lower
= lower_insn
& 0x7ff;
4060 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
4061 addend
= (upper
<< 12) | (lower
<< 1);
4062 signed_addend
= addend
;
4065 if (r_type
== R_ARM_THM_XPC22
)
4067 /* Check for Thumb to Thumb call. */
4068 /* FIXME: Should we translate the instruction into a BL
4069 instruction instead ? */
4070 if (sym_flags
== STT_ARM_TFUNC
)
4071 (*_bfd_error_handler
)
4072 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
4074 h
? h
->root
.root
.string
: "(local)");
4078 /* If it is not a call to Thumb, assume call to Arm.
4079 If it is a call relative to a section name, then it is not a
4080 function call at all, but rather a long jump. Calls through
4081 the PLT do not require stubs. */
4082 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
4083 && (h
== NULL
|| splt
== NULL
4084 || h
->plt
.offset
== (bfd_vma
) -1))
4086 if (globals
->use_blx
)
4088 /* Convert BL to BLX. */
4089 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
4091 else if (elf32_thumb_to_arm_stub
4092 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
4093 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
4094 return bfd_reloc_ok
;
4096 return bfd_reloc_dangerous
;
4098 else if (sym_flags
== STT_ARM_TFUNC
&& globals
->use_blx
)
4100 /* Make sure this is a BL. */
4101 lower_insn
|= 0x1800;
4105 /* Handle calls via the PLT. */
4106 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
4108 value
= (splt
->output_section
->vma
4109 + splt
->output_offset
4111 if (globals
->use_blx
)
4113 /* If the Thumb BLX instruction is available, convert the
4114 BL to a BLX instruction to call the ARM-mode PLT entry. */
4115 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
4118 /* Target the Thumb stub before the ARM PLT entry. */
4119 value
-= PLT_THUMB_STUB_SIZE
;
4120 *unresolved_reloc_p
= FALSE
;
4123 relocation
= value
+ signed_addend
;
4125 relocation
-= (input_section
->output_section
->vma
4126 + input_section
->output_offset
4129 check
= relocation
>> howto
->rightshift
;
4131 /* If this is a signed value, the rightshift just dropped
4132 leading 1 bits (assuming twos complement). */
4133 if ((bfd_signed_vma
) relocation
>= 0)
4134 signed_check
= check
;
4136 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
4138 /* Assumes two's complement. */
4139 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
4142 if ((lower_insn
& 0x1800) == 0x0800)
4143 /* For a BLX instruction, make sure that the relocation is rounded up
4144 to a word boundary. This follows the semantics of the instruction
4145 which specifies that bit 1 of the target address will come from bit
4146 1 of the base address. */
4147 relocation
= (relocation
+ 2) & ~ 3;
4149 /* Put RELOCATION back into the insn. */
4150 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
4151 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
4153 /* Put the relocated value back in the object file: */
4154 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
4155 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
4157 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
4161 case R_ARM_THM_JUMP24
:
4162 /* Thumb32 unconditional branch instruction. */
4165 bfd_boolean overflow
= FALSE
;
4166 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
4167 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
4168 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
4169 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
4171 bfd_signed_vma signed_check
;
4173 /* Need to refetch the addend, reconstruct the top three bits, and glue the
4174 two pieces together. */
4175 if (globals
->use_rel
)
4177 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
4178 bfd_vma hi
= (upper_insn
& 0x03ff);
4179 bfd_vma I1
= (lower_insn
& 0x2000) >> 13;
4180 bfd_vma I2
= (lower_insn
& 0x0800) >> 11;
4181 bfd_vma lo
= (lower_insn
& 0x07ff);
4187 signed_addend
= (S
<< 24) | (I1
<< 23) | (I2
<< 22) | (hi
<< 12) | (lo
<< 1);
4188 signed_addend
-= (1 << 24); /* Sign extend. */
4191 /* ??? Should handle interworking? GCC might someday try to
4192 use this for tail calls. */
4194 relocation
= value
+ signed_addend
;
4195 relocation
-= (input_section
->output_section
->vma
4196 + input_section
->output_offset
4199 check
= relocation
>> howto
->rightshift
;
4201 /* If this is a signed value, the rightshift just dropped
4202 leading 1 bits (assuming twos complement). */
4203 if ((bfd_signed_vma
) relocation
>= 0)
4204 signed_check
= check
;
4206 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
4208 /* Assumes two's complement. */
4209 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
4212 /* Put RELOCATION back into the insn. */
4214 bfd_vma S
= (relocation
& 0x01000000) >> 24;
4215 bfd_vma I1
= (relocation
& 0x00800000) >> 23;
4216 bfd_vma I2
= (relocation
& 0x00400000) >> 22;
4217 bfd_vma hi
= (relocation
& 0x003ff000) >> 12;
4218 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
4223 upper_insn
= (upper_insn
& (bfd_vma
) 0xf800) | (S
<< 10) | hi
;
4224 lower_insn
= (lower_insn
& (bfd_vma
) 0xd000) | (I1
<< 13) | (I2
<< 11) | lo
;
4227 /* Put the relocated value back in the object file: */
4228 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
4229 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
4231 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
4234 case R_ARM_THM_JUMP19
:
4235 /* Thumb32 conditional branch instruction. */
4238 bfd_boolean overflow
= FALSE
;
4239 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
4240 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
4241 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
4242 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
4244 bfd_signed_vma signed_check
;
4246 /* Need to refetch the addend, reconstruct the top three bits,
4247 and squish the two 11 bit pieces together. */
4248 if (globals
->use_rel
)
4250 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
4251 bfd_vma upper
= (upper_insn
& 0x001f);
4252 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
4253 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
4254 bfd_vma lower
= (lower_insn
& 0x07ff);
4259 upper
-= 0x0100; /* Sign extend. */
4261 addend
= (upper
<< 12) | (lower
<< 1);
4262 signed_addend
= addend
;
4265 /* ??? Should handle interworking? GCC might someday try to
4266 use this for tail calls. */
4268 relocation
= value
+ signed_addend
;
4269 relocation
-= (input_section
->output_section
->vma
4270 + input_section
->output_offset
4273 check
= relocation
>> howto
->rightshift
;
4275 /* If this is a signed value, the rightshift just dropped
4276 leading 1 bits (assuming twos complement). */
4277 if ((bfd_signed_vma
) relocation
>= 0)
4278 signed_check
= check
;
4280 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
4282 /* Assumes two's complement. */
4283 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
4286 /* Put RELOCATION back into the insn. */
4288 bfd_vma S
= (relocation
& 0x00100000) >> 20;
4289 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
4290 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
4291 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
4292 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
4294 upper_insn
= (upper_insn
& 0xfb30) | (S
<< 10) | hi
;
4295 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
4298 /* Put the relocated value back in the object file: */
4299 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
4300 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
4302 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
4305 case R_ARM_THM_JUMP11
:
4306 case R_ARM_THM_JUMP8
:
4307 case R_ARM_THM_JUMP6
:
4308 /* Thumb B (branch) instruction). */
4310 bfd_signed_vma relocation
;
4311 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
4312 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
4313 bfd_signed_vma signed_check
;
4315 /* CZB cannot jump backward. */
4316 if (r_type
== R_ARM_THM_JUMP6
)
4317 reloc_signed_min
= 0;
4319 if (globals
->use_rel
)
4321 /* Need to refetch addend. */
4322 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
4323 if (addend
& ((howto
->src_mask
+ 1) >> 1))
4326 signed_addend
&= ~ howto
->src_mask
;
4327 signed_addend
|= addend
;
4330 signed_addend
= addend
;
4331 /* The value in the insn has been right shifted. We need to
4332 undo this, so that we can perform the address calculation
4333 in terms of bytes. */
4334 signed_addend
<<= howto
->rightshift
;
4336 relocation
= value
+ signed_addend
;
4338 relocation
-= (input_section
->output_section
->vma
4339 + input_section
->output_offset
4342 relocation
>>= howto
->rightshift
;
4343 signed_check
= relocation
;
4345 if (r_type
== R_ARM_THM_JUMP6
)
4346 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
4348 relocation
&= howto
->dst_mask
;
4349 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
4351 bfd_put_16 (input_bfd
, relocation
, hit_data
);
4353 /* Assumes two's complement. */
4354 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
4355 return bfd_reloc_overflow
;
4357 return bfd_reloc_ok
;
4360 case R_ARM_ALU_PCREL7_0
:
4361 case R_ARM_ALU_PCREL15_8
:
4362 case R_ARM_ALU_PCREL23_15
:
4367 insn
= bfd_get_32 (input_bfd
, hit_data
);
4368 if (globals
->use_rel
)
4370 /* Extract the addend. */
4371 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
4372 signed_addend
= addend
;
4374 relocation
= value
+ signed_addend
;
4376 relocation
-= (input_section
->output_section
->vma
4377 + input_section
->output_offset
4379 insn
= (insn
& ~0xfff)
4380 | ((howto
->bitpos
<< 7) & 0xf00)
4381 | ((relocation
>> howto
->bitpos
) & 0xff);
4382 bfd_put_32 (input_bfd
, value
, hit_data
);
4384 return bfd_reloc_ok
;
4386 case R_ARM_GNU_VTINHERIT
:
4387 case R_ARM_GNU_VTENTRY
:
4388 return bfd_reloc_ok
;
4390 case R_ARM_GOTOFF32
:
4391 /* Relocation is relative to the start of the
4392 global offset table. */
4394 BFD_ASSERT (sgot
!= NULL
);
4396 return bfd_reloc_notsupported
;
4398 /* If we are addressing a Thumb function, we need to adjust the
4399 address by one, so that attempts to call the function pointer will
4400 correctly interpret it as Thumb code. */
4401 if (sym_flags
== STT_ARM_TFUNC
)
4404 /* Note that sgot->output_offset is not involved in this
4405 calculation. We always want the start of .got. If we
4406 define _GLOBAL_OFFSET_TABLE in a different way, as is
4407 permitted by the ABI, we might have to change this
4409 value
-= sgot
->output_section
->vma
;
4410 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4411 contents
, rel
->r_offset
, value
,
4415 /* Use global offset table as symbol value. */
4416 BFD_ASSERT (sgot
!= NULL
);
4419 return bfd_reloc_notsupported
;
4421 *unresolved_reloc_p
= FALSE
;
4422 value
= sgot
->output_section
->vma
;
4423 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4424 contents
, rel
->r_offset
, value
,
4428 case R_ARM_GOT_PREL
:
4429 /* Relocation is to the entry for this symbol in the
4430 global offset table. */
4432 return bfd_reloc_notsupported
;
4439 off
= h
->got
.offset
;
4440 BFD_ASSERT (off
!= (bfd_vma
) -1);
4441 dyn
= globals
->root
.dynamic_sections_created
;
4443 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4445 && SYMBOL_REFERENCES_LOCAL (info
, h
))
4446 || (ELF_ST_VISIBILITY (h
->other
)
4447 && h
->root
.type
== bfd_link_hash_undefweak
))
4449 /* This is actually a static link, or it is a -Bsymbolic link
4450 and the symbol is defined locally. We must initialize this
4451 entry in the global offset table. Since the offset must
4452 always be a multiple of 4, we use the least significant bit
4453 to record whether we have initialized it already.
4455 When doing a dynamic link, we create a .rel(a).got relocation
4456 entry to initialize the value. This is done in the
4457 finish_dynamic_symbol routine. */
4462 /* If we are addressing a Thumb function, we need to
4463 adjust the address by one, so that attempts to
4464 call the function pointer will correctly
4465 interpret it as Thumb code. */
4466 if (sym_flags
== STT_ARM_TFUNC
)
4469 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
4474 *unresolved_reloc_p
= FALSE
;
4476 value
= sgot
->output_offset
+ off
;
4482 BFD_ASSERT (local_got_offsets
!= NULL
&&
4483 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
4485 off
= local_got_offsets
[r_symndx
];
4487 /* The offset must always be a multiple of 4. We use the
4488 least significant bit to record whether we have already
4489 generated the necessary reloc. */
4494 /* If we are addressing a Thumb function, we need to
4495 adjust the address by one, so that attempts to
4496 call the function pointer will correctly
4497 interpret it as Thumb code. */
4498 if (sym_flags
== STT_ARM_TFUNC
)
4501 if (globals
->use_rel
)
4502 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
4507 Elf_Internal_Rela outrel
;
4510 srelgot
= (bfd_get_section_by_name
4511 (dynobj
, RELOC_SECTION (globals
, ".got")));
4512 BFD_ASSERT (srelgot
!= NULL
);
4514 outrel
.r_addend
= addend
+ value
;
4515 outrel
.r_offset
= (sgot
->output_section
->vma
4516 + sgot
->output_offset
4518 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
4519 loc
= srelgot
->contents
;
4520 loc
+= srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
4521 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4524 local_got_offsets
[r_symndx
] |= 1;
4527 value
= sgot
->output_offset
+ off
;
4529 if (r_type
!= R_ARM_GOT32
)
4530 value
+= sgot
->output_section
->vma
;
4532 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4533 contents
, rel
->r_offset
, value
,
4536 case R_ARM_TLS_LDO32
:
4537 value
= value
- dtpoff_base (info
);
4539 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4540 contents
, rel
->r_offset
, value
,
4543 case R_ARM_TLS_LDM32
:
4547 if (globals
->sgot
== NULL
)
4550 off
= globals
->tls_ldm_got
.offset
;
4556 /* If we don't know the module number, create a relocation
4560 Elf_Internal_Rela outrel
;
4563 if (globals
->srelgot
== NULL
)
4566 outrel
.r_addend
= 0;
4567 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
4568 + globals
->sgot
->output_offset
+ off
);
4569 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
4571 if (globals
->use_rel
)
4572 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4573 globals
->sgot
->contents
+ off
);
4575 loc
= globals
->srelgot
->contents
;
4576 loc
+= globals
->srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
4577 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4580 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
4582 globals
->tls_ldm_got
.offset
|= 1;
4585 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
4586 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
4588 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4589 contents
, rel
->r_offset
, value
,
4593 case R_ARM_TLS_GD32
:
4594 case R_ARM_TLS_IE32
:
4600 if (globals
->sgot
== NULL
)
4607 dyn
= globals
->root
.dynamic_sections_created
;
4608 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4610 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
4612 *unresolved_reloc_p
= FALSE
;
4615 off
= h
->got
.offset
;
4616 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
4620 if (local_got_offsets
== NULL
)
4622 off
= local_got_offsets
[r_symndx
];
4623 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
4626 if (tls_type
== GOT_UNKNOWN
)
4633 bfd_boolean need_relocs
= FALSE
;
4634 Elf_Internal_Rela outrel
;
4635 bfd_byte
*loc
= NULL
;
4638 /* The GOT entries have not been initialized yet. Do it
4639 now, and emit any relocations. If both an IE GOT and a
4640 GD GOT are necessary, we emit the GD first. */
4642 if ((info
->shared
|| indx
!= 0)
4644 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4645 || h
->root
.type
!= bfd_link_hash_undefweak
))
4648 if (globals
->srelgot
== NULL
)
4650 loc
= globals
->srelgot
->contents
;
4651 loc
+= globals
->srelgot
->reloc_count
* RELOC_SIZE (globals
);
4654 if (tls_type
& GOT_TLS_GD
)
4658 outrel
.r_addend
= 0;
4659 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
4660 + globals
->sgot
->output_offset
4662 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
4664 if (globals
->use_rel
)
4665 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4666 globals
->sgot
->contents
+ cur_off
);
4668 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4669 globals
->srelgot
->reloc_count
++;
4670 loc
+= RELOC_SIZE (globals
);
4673 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
4674 globals
->sgot
->contents
+ cur_off
+ 4);
4677 outrel
.r_addend
= 0;
4678 outrel
.r_info
= ELF32_R_INFO (indx
,
4679 R_ARM_TLS_DTPOFF32
);
4680 outrel
.r_offset
+= 4;
4682 if (globals
->use_rel
)
4683 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4684 globals
->sgot
->contents
+ cur_off
+ 4);
4687 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4688 globals
->srelgot
->reloc_count
++;
4689 loc
+= RELOC_SIZE (globals
);
4694 /* If we are not emitting relocations for a
4695 general dynamic reference, then we must be in a
4696 static link or an executable link with the
4697 symbol binding locally. Mark it as belonging
4698 to module 1, the executable. */
4699 bfd_put_32 (output_bfd
, 1,
4700 globals
->sgot
->contents
+ cur_off
);
4701 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
4702 globals
->sgot
->contents
+ cur_off
+ 4);
4708 if (tls_type
& GOT_TLS_IE
)
4713 outrel
.r_addend
= value
- dtpoff_base (info
);
4715 outrel
.r_addend
= 0;
4716 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
4717 + globals
->sgot
->output_offset
4719 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
4721 if (globals
->use_rel
)
4722 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4723 globals
->sgot
->contents
+ cur_off
);
4725 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4726 globals
->srelgot
->reloc_count
++;
4727 loc
+= RELOC_SIZE (globals
);
4730 bfd_put_32 (output_bfd
, tpoff (info
, value
),
4731 globals
->sgot
->contents
+ cur_off
);
4738 local_got_offsets
[r_symndx
] |= 1;
4741 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
4743 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
4744 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
4746 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4747 contents
, rel
->r_offset
, value
,
4751 case R_ARM_TLS_LE32
:
4754 (*_bfd_error_handler
)
4755 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
4756 input_bfd
, input_section
,
4757 (long) rel
->r_offset
, howto
->name
);
4761 value
= tpoff (info
, value
);
4763 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4764 contents
, rel
->r_offset
, value
,
4768 if (globals
->fix_v4bx
)
4770 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
4772 /* Ensure that we have a BX instruction. */
4773 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
4775 /* Preserve Rm (lowest four bits) and the condition code
4776 (highest four bits). Other bits encode MOV PC,Rm. */
4777 insn
= (insn
& 0xf000000f) | 0x01a0f000;
4779 bfd_put_32 (input_bfd
, insn
, hit_data
);
4781 return bfd_reloc_ok
;
4783 case R_ARM_MOVW_ABS_NC
:
4784 case R_ARM_MOVT_ABS
:
4785 case R_ARM_MOVW_PREL_NC
:
4786 case R_ARM_MOVT_PREL
:
4788 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
4790 if (globals
->use_rel
)
4792 addend
= ((insn
>> 4) & 0xf000) | (insn
& 0xfff);
4793 signed_addend
= (addend
^ 0x10000) - 0x10000;
4795 value
+= signed_addend
;
4796 if (sym_flags
== STT_ARM_TFUNC
)
4799 if (r_type
== R_ARM_MOVW_PREL_NC
|| r_type
== R_ARM_MOVT_PREL
)
4800 value
-= (input_section
->output_section
->vma
4801 + input_section
->output_offset
+ rel
->r_offset
);
4803 if (r_type
== R_ARM_MOVT_ABS
|| r_type
== R_ARM_MOVT_PREL
)
4807 insn
|= value
& 0xfff;
4808 insn
|= (value
& 0xf000) << 4;
4809 bfd_put_32 (input_bfd
, insn
, hit_data
);
4811 return bfd_reloc_ok
;
4813 case R_ARM_THM_MOVW_ABS_NC
:
4814 case R_ARM_THM_MOVT_ABS
:
4815 case R_ARM_THM_MOVW_PREL_NC
:
4816 case R_ARM_THM_MOVT_PREL
:
4820 insn
= bfd_get_16 (input_bfd
, hit_data
) << 16;
4821 insn
|= bfd_get_16 (input_bfd
, hit_data
+ 2);
4823 if (globals
->use_rel
)
4825 addend
= ((insn
>> 4) & 0xf000)
4826 | ((insn
>> 15) & 0x0800)
4827 | ((insn
>> 4) & 0x0700)
4829 signed_addend
= (addend
^ 0x10000) - 0x10000;
4831 value
+= signed_addend
;
4832 if (sym_flags
== STT_ARM_TFUNC
)
4835 if (r_type
== R_ARM_THM_MOVW_PREL_NC
|| r_type
== R_ARM_THM_MOVT_PREL
)
4836 value
-= (input_section
->output_section
->vma
4837 + input_section
->output_offset
+ rel
->r_offset
);
4839 if (r_type
== R_ARM_THM_MOVT_ABS
|| r_type
== R_ARM_THM_MOVT_PREL
)
4843 insn
|= (value
& 0xf000) << 4;
4844 insn
|= (value
& 0x0800) << 15;
4845 insn
|= (value
& 0x0700) << 4;
4846 insn
|= (value
& 0x00ff);
4848 bfd_put_16 (input_bfd
, insn
>> 16, hit_data
);
4849 bfd_put_16 (input_bfd
, insn
& 0xffff, hit_data
+ 2);
4851 return bfd_reloc_ok
;
4853 case R_ARM_ALU_PC_G0_NC
:
4854 case R_ARM_ALU_PC_G1_NC
:
4855 case R_ARM_ALU_PC_G0
:
4856 case R_ARM_ALU_PC_G1
:
4857 case R_ARM_ALU_PC_G2
:
4858 case R_ARM_ALU_SB_G0_NC
:
4859 case R_ARM_ALU_SB_G1_NC
:
4860 case R_ARM_ALU_SB_G0
:
4861 case R_ARM_ALU_SB_G1
:
4862 case R_ARM_ALU_SB_G2
:
4864 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
4865 bfd_vma pc
= input_section
->output_section
->vma
4866 + input_section
->output_offset
+ rel
->r_offset
;
4867 /* sb should be the origin of the *segment* containing the symbol.
4868 It is not clear how to obtain this OS-dependent value, so we
4869 make an arbitrary choice of zero. */
4873 bfd_signed_vma signed_value
;
4876 /* Determine which group of bits to select. */
4879 case R_ARM_ALU_PC_G0_NC
:
4880 case R_ARM_ALU_PC_G0
:
4881 case R_ARM_ALU_SB_G0_NC
:
4882 case R_ARM_ALU_SB_G0
:
4886 case R_ARM_ALU_PC_G1_NC
:
4887 case R_ARM_ALU_PC_G1
:
4888 case R_ARM_ALU_SB_G1_NC
:
4889 case R_ARM_ALU_SB_G1
:
4893 case R_ARM_ALU_PC_G2
:
4894 case R_ARM_ALU_SB_G2
:
4902 /* If REL, extract the addend from the insn. If RELA, it will
4903 have already been fetched for us. */
4904 if (globals
->use_rel
)
4907 bfd_vma constant
= insn
& 0xff;
4908 bfd_vma rotation
= (insn
& 0xf00) >> 8;
4911 signed_addend
= constant
;
4914 /* Compensate for the fact that in the instruction, the
4915 rotation is stored in multiples of 2 bits. */
4918 /* Rotate "constant" right by "rotation" bits. */
4919 signed_addend
= (constant
>> rotation
) |
4920 (constant
<< (8 * sizeof (bfd_vma
) - rotation
));
4923 /* Determine if the instruction is an ADD or a SUB.
4924 (For REL, this determines the sign of the addend.) */
4925 negative
= identify_add_or_sub (insn
);
4928 (*_bfd_error_handler
)
4929 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
4930 input_bfd
, input_section
,
4931 (long) rel
->r_offset
, howto
->name
);
4932 return bfd_reloc_overflow
;
4935 signed_addend
*= negative
;
4938 /* Compute the value (X) to go in the place. */
4939 if (r_type
== R_ARM_ALU_PC_G0_NC
4940 || r_type
== R_ARM_ALU_PC_G1_NC
4941 || r_type
== R_ARM_ALU_PC_G0
4942 || r_type
== R_ARM_ALU_PC_G1
4943 || r_type
== R_ARM_ALU_PC_G2
)
4945 signed_value
= value
- pc
+ signed_addend
;
4947 /* Section base relative. */
4948 signed_value
= value
- sb
+ signed_addend
;
4950 /* If the target symbol is a Thumb function, then set the
4951 Thumb bit in the address. */
4952 if (sym_flags
== STT_ARM_TFUNC
)
4955 /* Calculate the value of the relevant G_n, in encoded
4956 constant-with-rotation format. */
4957 g_n
= calculate_group_reloc_mask (abs (signed_value
), group
,
4960 /* Check for overflow if required. */
4961 if ((r_type
== R_ARM_ALU_PC_G0
4962 || r_type
== R_ARM_ALU_PC_G1
4963 || r_type
== R_ARM_ALU_PC_G2
4964 || r_type
== R_ARM_ALU_SB_G0
4965 || r_type
== R_ARM_ALU_SB_G1
4966 || r_type
== R_ARM_ALU_SB_G2
) && residual
!= 0)
4968 (*_bfd_error_handler
)
4969 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
4970 input_bfd
, input_section
,
4971 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
4972 return bfd_reloc_overflow
;
4975 /* Mask out the value and the ADD/SUB part of the opcode; take care
4976 not to destroy the S bit. */
4979 /* Set the opcode according to whether the value to go in the
4980 place is negative. */
4981 if (signed_value
< 0)
4986 /* Encode the offset. */
4989 bfd_put_32 (input_bfd
, insn
, hit_data
);
4991 return bfd_reloc_ok
;
4993 case R_ARM_LDR_PC_G0
:
4994 case R_ARM_LDR_PC_G1
:
4995 case R_ARM_LDR_PC_G2
:
4996 case R_ARM_LDR_SB_G0
:
4997 case R_ARM_LDR_SB_G1
:
4998 case R_ARM_LDR_SB_G2
:
5000 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
5001 bfd_vma pc
= input_section
->output_section
->vma
5002 + input_section
->output_offset
+ rel
->r_offset
;
5003 bfd_vma sb
= 0; /* See note above. */
5005 bfd_signed_vma signed_value
;
5008 /* Determine which groups of bits to calculate. */
5011 case R_ARM_LDR_PC_G0
:
5012 case R_ARM_LDR_SB_G0
:
5016 case R_ARM_LDR_PC_G1
:
5017 case R_ARM_LDR_SB_G1
:
5021 case R_ARM_LDR_PC_G2
:
5022 case R_ARM_LDR_SB_G2
:
5030 /* If REL, extract the addend from the insn. If RELA, it will
5031 have already been fetched for us. */
5032 if (globals
->use_rel
)
5034 int negative
= (insn
& (1 << 23)) ? 1 : -1;
5035 signed_addend
= negative
* (insn
& 0xfff);
5038 /* Compute the value (X) to go in the place. */
5039 if (r_type
== R_ARM_LDR_PC_G0
5040 || r_type
== R_ARM_LDR_PC_G1
5041 || r_type
== R_ARM_LDR_PC_G2
)
5043 signed_value
= value
- pc
+ signed_addend
;
5045 /* Section base relative. */
5046 signed_value
= value
- sb
+ signed_addend
;
5048 /* Calculate the value of the relevant G_{n-1} to obtain
5049 the residual at that stage. */
5050 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
5052 /* Check for overflow. */
5053 if (residual
>= 0x1000)
5055 (*_bfd_error_handler
)
5056 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5057 input_bfd
, input_section
,
5058 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
5059 return bfd_reloc_overflow
;
5062 /* Mask out the value and U bit. */
5065 /* Set the U bit if the value to go in the place is non-negative. */
5066 if (signed_value
>= 0)
5069 /* Encode the offset. */
5072 bfd_put_32 (input_bfd
, insn
, hit_data
);
5074 return bfd_reloc_ok
;
5076 case R_ARM_LDRS_PC_G0
:
5077 case R_ARM_LDRS_PC_G1
:
5078 case R_ARM_LDRS_PC_G2
:
5079 case R_ARM_LDRS_SB_G0
:
5080 case R_ARM_LDRS_SB_G1
:
5081 case R_ARM_LDRS_SB_G2
:
5083 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
5084 bfd_vma pc
= input_section
->output_section
->vma
5085 + input_section
->output_offset
+ rel
->r_offset
;
5086 bfd_vma sb
= 0; /* See note above. */
5088 bfd_signed_vma signed_value
;
5091 /* Determine which groups of bits to calculate. */
5094 case R_ARM_LDRS_PC_G0
:
5095 case R_ARM_LDRS_SB_G0
:
5099 case R_ARM_LDRS_PC_G1
:
5100 case R_ARM_LDRS_SB_G1
:
5104 case R_ARM_LDRS_PC_G2
:
5105 case R_ARM_LDRS_SB_G2
:
5113 /* If REL, extract the addend from the insn. If RELA, it will
5114 have already been fetched for us. */
5115 if (globals
->use_rel
)
5117 int negative
= (insn
& (1 << 23)) ? 1 : -1;
5118 signed_addend
= negative
* (((insn
& 0xf00) >> 4) + (insn
& 0xf));
5121 /* Compute the value (X) to go in the place. */
5122 if (r_type
== R_ARM_LDRS_PC_G0
5123 || r_type
== R_ARM_LDRS_PC_G1
5124 || r_type
== R_ARM_LDRS_PC_G2
)
5126 signed_value
= value
- pc
+ signed_addend
;
5128 /* Section base relative. */
5129 signed_value
= value
- sb
+ signed_addend
;
5131 /* Calculate the value of the relevant G_{n-1} to obtain
5132 the residual at that stage. */
5133 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
5135 /* Check for overflow. */
5136 if (residual
>= 0x100)
5138 (*_bfd_error_handler
)
5139 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5140 input_bfd
, input_section
,
5141 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
5142 return bfd_reloc_overflow
;
5145 /* Mask out the value and U bit. */
5148 /* Set the U bit if the value to go in the place is non-negative. */
5149 if (signed_value
>= 0)
5152 /* Encode the offset. */
5153 insn
|= ((residual
& 0xf0) << 4) | (residual
& 0xf);
5155 bfd_put_32 (input_bfd
, insn
, hit_data
);
5157 return bfd_reloc_ok
;
5159 case R_ARM_LDC_PC_G0
:
5160 case R_ARM_LDC_PC_G1
:
5161 case R_ARM_LDC_PC_G2
:
5162 case R_ARM_LDC_SB_G0
:
5163 case R_ARM_LDC_SB_G1
:
5164 case R_ARM_LDC_SB_G2
:
5166 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
5167 bfd_vma pc
= input_section
->output_section
->vma
5168 + input_section
->output_offset
+ rel
->r_offset
;
5169 bfd_vma sb
= 0; /* See note above. */
5171 bfd_signed_vma signed_value
;
5174 /* Determine which groups of bits to calculate. */
5177 case R_ARM_LDC_PC_G0
:
5178 case R_ARM_LDC_SB_G0
:
5182 case R_ARM_LDC_PC_G1
:
5183 case R_ARM_LDC_SB_G1
:
5187 case R_ARM_LDC_PC_G2
:
5188 case R_ARM_LDC_SB_G2
:
5196 /* If REL, extract the addend from the insn. If RELA, it will
5197 have already been fetched for us. */
5198 if (globals
->use_rel
)
5200 int negative
= (insn
& (1 << 23)) ? 1 : -1;
5201 signed_addend
= negative
* ((insn
& 0xff) << 2);
5204 /* Compute the value (X) to go in the place. */
5205 if (r_type
== R_ARM_LDC_PC_G0
5206 || r_type
== R_ARM_LDC_PC_G1
5207 || r_type
== R_ARM_LDC_PC_G2
)
5209 signed_value
= value
- pc
+ signed_addend
;
5211 /* Section base relative. */
5212 signed_value
= value
- sb
+ signed_addend
;
5214 /* Calculate the value of the relevant G_{n-1} to obtain
5215 the residual at that stage. */
5216 calculate_group_reloc_mask (abs (signed_value
), group
- 1, &residual
);
5218 /* Check for overflow. (The absolute value to go in the place must be
5219 divisible by four and, after having been divided by four, must
5220 fit in eight bits.) */
5221 if ((residual
& 0x3) != 0 || residual
>= 0x400)
5223 (*_bfd_error_handler
)
5224 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5225 input_bfd
, input_section
,
5226 (long) rel
->r_offset
, abs (signed_value
), howto
->name
);
5227 return bfd_reloc_overflow
;
5230 /* Mask out the value and U bit. */
5233 /* Set the U bit if the value to go in the place is non-negative. */
5234 if (signed_value
>= 0)
5237 /* Encode the offset. */
5238 insn
|= residual
>> 2;
5240 bfd_put_32 (input_bfd
, insn
, hit_data
);
5242 return bfd_reloc_ok
;
5245 return bfd_reloc_notsupported
;
5251 uleb128_size (unsigned int i
)
5263 /* Return TRUE if the attribute has the default value (0/""). */
5265 is_default_attr (aeabi_attribute
*attr
)
5267 if ((attr
->type
& 1) && attr
->i
!= 0)
5269 if ((attr
->type
& 2) && attr
->s
&& *attr
->s
)
5275 /* Return the size of a single attribute. */
5277 eabi_attr_size(int tag
, aeabi_attribute
*attr
)
5281 if (is_default_attr (attr
))
5284 size
= uleb128_size (tag
);
5286 size
+= uleb128_size (attr
->i
);
5288 size
+= strlen ((char *)attr
->s
) + 1;
5292 /* Returns the size of the eabi object attributess section. */
5294 elf32_arm_eabi_attr_size (bfd
*abfd
)
5297 aeabi_attribute
*attr
;
5298 aeabi_attribute_list
*list
;
5301 attr
= elf32_arm_tdata (abfd
)->known_eabi_attributes
;
5302 size
= 16; /* 'A' <size> "aeabi" 0x1 <size>. */
5303 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
5304 size
+= eabi_attr_size (i
, &attr
[i
]);
5306 for (list
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
5309 size
+= eabi_attr_size (list
->tag
, &list
->attr
);
5315 write_uleb128 (bfd_byte
*p
, unsigned int val
)
5330 /* Write attribute ATTR to butter P, and return a pointer to the following
5333 write_eabi_attribute (bfd_byte
*p
, int tag
, aeabi_attribute
*attr
)
5335 /* Suppress default entries. */
5336 if (is_default_attr(attr
))
5339 p
= write_uleb128 (p
, tag
);
5341 p
= write_uleb128 (p
, attr
->i
);
5346 len
= strlen (attr
->s
) + 1;
5347 memcpy (p
, attr
->s
, len
);
5354 /* Write the contents of the eabi attributes section to p. */
5356 elf32_arm_set_eabi_attr_contents (bfd
*abfd
, bfd_byte
*contents
, bfd_vma size
)
5359 aeabi_attribute
*attr
;
5360 aeabi_attribute_list
*list
;
5365 bfd_put_32 (abfd
, size
- 1, p
);
5367 memcpy (p
, "aeabi", 6);
5370 bfd_put_32 (abfd
, size
- 11, p
);
5373 attr
= elf32_arm_tdata (abfd
)->known_eabi_attributes
;
5374 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
5375 p
= write_eabi_attribute (p
, i
, &attr
[i
]);
5377 for (list
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
5380 p
= write_eabi_attribute (p
, list
->tag
, &list
->attr
);
5383 /* Override final_link to handle EABI object attribute sections. */
5386 elf32_arm_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
5389 struct bfd_link_order
*p
;
5390 asection
*attr_section
= NULL
;
5394 /* elf32_arm_merge_private_bfd_data will already have merged the
5395 object attributes. Remove the input sections from the link, and set
5396 the contents of the output secton. */
5397 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5399 if (strcmp (o
->name
, ".ARM.attributes") == 0)
5401 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
5403 asection
*input_section
;
5405 if (p
->type
!= bfd_indirect_link_order
)
5407 input_section
= p
->u
.indirect
.section
;
5408 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5409 elf_link_input_bfd ignores this section. */
5410 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
5413 size
= elf32_arm_eabi_attr_size (abfd
);
5414 bfd_set_section_size (abfd
, o
, size
);
5416 /* Skip this section later on. */
5417 o
->map_head
.link_order
= NULL
;
5420 /* Invoke the ELF linker to do all the work. */
5421 if (!bfd_elf_final_link (abfd
, info
))
5426 contents
= bfd_malloc(size
);
5427 if (contents
== NULL
)
5429 elf32_arm_set_eabi_attr_contents (abfd
, contents
, size
);
5430 bfd_set_section_contents (abfd
, attr_section
, contents
, 0, size
);
5437 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
5439 arm_add_to_rel (bfd
* abfd
,
5441 reloc_howto_type
* howto
,
5442 bfd_signed_vma increment
)
5444 bfd_signed_vma addend
;
5446 if (howto
->type
== R_ARM_THM_CALL
)
5448 int upper_insn
, lower_insn
;
5451 upper_insn
= bfd_get_16 (abfd
, address
);
5452 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
5453 upper
= upper_insn
& 0x7ff;
5454 lower
= lower_insn
& 0x7ff;
5456 addend
= (upper
<< 12) | (lower
<< 1);
5457 addend
+= increment
;
5460 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
5461 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
5463 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
5464 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
5470 contents
= bfd_get_32 (abfd
, address
);
5472 /* Get the (signed) value from the instruction. */
5473 addend
= contents
& howto
->src_mask
;
5474 if (addend
& ((howto
->src_mask
+ 1) >> 1))
5476 bfd_signed_vma mask
;
5479 mask
&= ~ howto
->src_mask
;
5483 /* Add in the increment, (which is a byte value). */
5484 switch (howto
->type
)
5487 addend
+= increment
;
5494 addend
<<= howto
->size
;
5495 addend
+= increment
;
5497 /* Should we check for overflow here ? */
5499 /* Drop any undesired bits. */
5500 addend
>>= howto
->rightshift
;
5504 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
5506 bfd_put_32 (abfd
, contents
, address
);
5510 #define IS_ARM_TLS_RELOC(R_TYPE) \
5511 ((R_TYPE) == R_ARM_TLS_GD32 \
5512 || (R_TYPE) == R_ARM_TLS_LDO32 \
5513 || (R_TYPE) == R_ARM_TLS_LDM32 \
5514 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
5515 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
5516 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
5517 || (R_TYPE) == R_ARM_TLS_LE32 \
5518 || (R_TYPE) == R_ARM_TLS_IE32)
5520 /* Relocate an ARM ELF section. */
5522 elf32_arm_relocate_section (bfd
* output_bfd
,
5523 struct bfd_link_info
* info
,
5525 asection
* input_section
,
5526 bfd_byte
* contents
,
5527 Elf_Internal_Rela
* relocs
,
5528 Elf_Internal_Sym
* local_syms
,
5529 asection
** local_sections
)
5531 Elf_Internal_Shdr
*symtab_hdr
;
5532 struct elf_link_hash_entry
**sym_hashes
;
5533 Elf_Internal_Rela
*rel
;
5534 Elf_Internal_Rela
*relend
;
5536 struct elf32_arm_link_hash_table
* globals
;
5538 globals
= elf32_arm_hash_table (info
);
5539 if (info
->relocatable
&& !globals
->use_rel
)
5542 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
5543 sym_hashes
= elf_sym_hashes (input_bfd
);
5546 relend
= relocs
+ input_section
->reloc_count
;
5547 for (; rel
< relend
; rel
++)
5550 reloc_howto_type
* howto
;
5551 unsigned long r_symndx
;
5552 Elf_Internal_Sym
* sym
;
5554 struct elf_link_hash_entry
* h
;
5556 bfd_reloc_status_type r
;
5559 bfd_boolean unresolved_reloc
= FALSE
;
5561 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5562 r_type
= ELF32_R_TYPE (rel
->r_info
);
5563 r_type
= arm_real_reloc_type (globals
, r_type
);
5565 if ( r_type
== R_ARM_GNU_VTENTRY
5566 || r_type
== R_ARM_GNU_VTINHERIT
)
5569 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
5570 howto
= bfd_reloc
.howto
;
5572 if (info
->relocatable
&& globals
->use_rel
)
5574 /* This is a relocatable link. We don't have to change
5575 anything, unless the reloc is against a section symbol,
5576 in which case we have to adjust according to where the
5577 section symbol winds up in the output section. */
5578 if (r_symndx
< symtab_hdr
->sh_info
)
5580 sym
= local_syms
+ r_symndx
;
5581 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5583 sec
= local_sections
[r_symndx
];
5584 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
5586 (bfd_signed_vma
) (sec
->output_offset
5594 /* This is a final link. */
5599 if (r_symndx
< symtab_hdr
->sh_info
)
5601 sym
= local_syms
+ r_symndx
;
5602 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
5603 sec
= local_sections
[r_symndx
];
5604 if (globals
->use_rel
)
5606 relocation
= (sec
->output_section
->vma
5607 + sec
->output_offset
5609 if ((sec
->flags
& SEC_MERGE
)
5610 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
5613 bfd_vma addend
, value
;
5615 if (howto
->rightshift
)
5617 (*_bfd_error_handler
)
5618 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
5619 input_bfd
, input_section
,
5620 (long) rel
->r_offset
, howto
->name
);
5624 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5626 /* Get the (signed) value from the instruction. */
5627 addend
= value
& howto
->src_mask
;
5628 if (addend
& ((howto
->src_mask
+ 1) >> 1))
5630 bfd_signed_vma mask
;
5633 mask
&= ~ howto
->src_mask
;
5638 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
5640 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
5641 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
5642 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
5646 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
5652 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
5653 r_symndx
, symtab_hdr
, sym_hashes
,
5655 unresolved_reloc
, warned
);
5661 name
= h
->root
.root
.string
;
5664 name
= (bfd_elf_string_from_elf_section
5665 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5666 if (name
== NULL
|| *name
== '\0')
5667 name
= bfd_section_name (input_bfd
, sec
);
5671 && r_type
!= R_ARM_NONE
5673 || h
->root
.type
== bfd_link_hash_defined
5674 || h
->root
.type
== bfd_link_hash_defweak
)
5675 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
5677 (*_bfd_error_handler
)
5678 ((sym_type
== STT_TLS
5679 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5680 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5683 (long) rel
->r_offset
,
5688 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
5689 input_section
, contents
, rel
,
5690 relocation
, info
, sec
, name
,
5691 (h
? ELF_ST_TYPE (h
->type
) :
5692 ELF_ST_TYPE (sym
->st_info
)), h
,
5695 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5696 because such sections are not SEC_ALLOC and thus ld.so will
5697 not process them. */
5698 if (unresolved_reloc
5699 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5702 (*_bfd_error_handler
)
5703 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5706 (long) rel
->r_offset
,
5708 h
->root
.root
.string
);
5712 if (r
!= bfd_reloc_ok
)
5714 const char * msg
= (const char *) 0;
5718 case bfd_reloc_overflow
:
5719 /* If the overflowing reloc was to an undefined symbol,
5720 we have already printed one error message and there
5721 is no point complaining again. */
5723 h
->root
.type
!= bfd_link_hash_undefined
)
5724 && (!((*info
->callbacks
->reloc_overflow
)
5725 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
5726 (bfd_vma
) 0, input_bfd
, input_section
,
5731 case bfd_reloc_undefined
:
5732 if (!((*info
->callbacks
->undefined_symbol
)
5733 (info
, name
, input_bfd
, input_section
,
5734 rel
->r_offset
, TRUE
)))
5738 case bfd_reloc_outofrange
:
5739 msg
= _("internal error: out of range error");
5742 case bfd_reloc_notsupported
:
5743 msg
= _("internal error: unsupported relocation error");
5746 case bfd_reloc_dangerous
:
5747 msg
= _("internal error: dangerous error");
5751 msg
= _("internal error: unknown error");
5755 if (!((*info
->callbacks
->warning
)
5756 (info
, msg
, name
, input_bfd
, input_section
,
5767 /* Allocate/find an object attribute. */
5768 static aeabi_attribute
*
5769 elf32_arm_new_eabi_attr (bfd
*abfd
, int tag
)
5771 aeabi_attribute
*attr
;
5772 aeabi_attribute_list
*list
;
5773 aeabi_attribute_list
*p
;
5774 aeabi_attribute_list
**lastp
;
5777 if (tag
< NUM_KNOWN_ATTRIBUTES
)
5779 /* Knwon tags are preallocated. */
5780 attr
= &elf32_arm_tdata (abfd
)->known_eabi_attributes
[tag
];
5784 /* Create a new tag. */
5785 list
= (aeabi_attribute_list
*)
5786 bfd_alloc (abfd
, sizeof (aeabi_attribute_list
));
5787 memset (list
, 0, sizeof (aeabi_attribute_list
));
5789 /* Keep the tag list in order. */
5790 lastp
= &elf32_arm_tdata (abfd
)->other_eabi_attributes
;
5791 for (p
= *lastp
; p
; p
= p
->next
)
5797 list
->next
= *lastp
;
5806 elf32_arm_get_eabi_attr_int (bfd
*abfd
, int tag
)
5808 aeabi_attribute_list
*p
;
5810 if (tag
< NUM_KNOWN_ATTRIBUTES
)
5812 /* Knwon tags are preallocated. */
5813 return elf32_arm_tdata (abfd
)->known_eabi_attributes
[tag
].i
;
5817 for (p
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
5831 elf32_arm_add_eabi_attr_int (bfd
*abfd
, int tag
, unsigned int i
)
5833 aeabi_attribute
*attr
;
5835 attr
= elf32_arm_new_eabi_attr (abfd
, tag
);
5841 attr_strdup (bfd
*abfd
, const char * s
)
5846 len
= strlen (s
) + 1;
5847 p
= (char *)bfd_alloc(abfd
, len
);
5848 return memcpy (p
, s
, len
);
5852 elf32_arm_add_eabi_attr_string (bfd
*abfd
, int tag
, const char *s
)
5854 aeabi_attribute
*attr
;
5856 attr
= elf32_arm_new_eabi_attr (abfd
, tag
);
5858 attr
->s
= attr_strdup (abfd
, s
);
5862 elf32_arm_add_eabi_attr_compat (bfd
*abfd
, unsigned int i
, const char *s
)
5864 aeabi_attribute_list
*list
;
5865 aeabi_attribute_list
*p
;
5866 aeabi_attribute_list
**lastp
;
5868 list
= (aeabi_attribute_list
*)
5869 bfd_alloc (abfd
, sizeof (aeabi_attribute_list
));
5870 memset (list
, 0, sizeof (aeabi_attribute_list
));
5871 list
->tag
= Tag_compatibility
;
5872 list
->attr
.type
= 3;
5874 list
->attr
.s
= attr_strdup (abfd
, s
);
5876 lastp
= &elf32_arm_tdata (abfd
)->other_eabi_attributes
;
5877 for (p
= *lastp
; p
; p
= p
->next
)
5880 if (p
->tag
!= Tag_compatibility
)
5882 cmp
= strcmp(s
, p
->attr
.s
);
5883 if (cmp
< 0 || (cmp
== 0 && i
< p
->attr
.i
))
5887 list
->next
= *lastp
;
5891 /* Set the right machine number. */
5894 elf32_arm_object_p (bfd
*abfd
)
5898 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
5900 if (mach
!= bfd_mach_arm_unknown
)
5901 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
5903 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
5904 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
5907 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
5912 /* Function to keep ARM specific flags in the ELF header. */
5915 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
5917 if (elf_flags_init (abfd
)
5918 && elf_elfheader (abfd
)->e_flags
!= flags
)
5920 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
5922 if (flags
& EF_ARM_INTERWORK
)
5923 (*_bfd_error_handler
)
5924 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
5928 (_("Warning: Clearing the interworking flag of %B due to outside request"),
5934 elf_elfheader (abfd
)->e_flags
= flags
;
5935 elf_flags_init (abfd
) = TRUE
;
5941 /* Copy the eabi object attribute from IBFD to OBFD. */
5943 copy_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
5945 aeabi_attribute
*in_attr
;
5946 aeabi_attribute
*out_attr
;
5947 aeabi_attribute_list
*list
;
5950 in_attr
= elf32_arm_tdata (ibfd
)->known_eabi_attributes
;
5951 out_attr
= elf32_arm_tdata (obfd
)->known_eabi_attributes
;
5952 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
5954 out_attr
->i
= in_attr
->i
;
5955 if (in_attr
->s
&& *in_attr
->s
)
5956 out_attr
->s
= attr_strdup (obfd
, in_attr
->s
);
5961 for (list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
5965 in_attr
= &list
->attr
;
5966 switch (in_attr
->type
)
5969 elf32_arm_add_eabi_attr_int (obfd
, list
->tag
, in_attr
->i
);
5972 elf32_arm_add_eabi_attr_string (obfd
, list
->tag
, in_attr
->s
);
5975 elf32_arm_add_eabi_attr_compat (obfd
, in_attr
->i
, in_attr
->s
);
5984 /* Copy backend specific data from one object module to another. */
5987 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
5992 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5993 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5996 in_flags
= elf_elfheader (ibfd
)->e_flags
;
5997 out_flags
= elf_elfheader (obfd
)->e_flags
;
5999 if (elf_flags_init (obfd
)
6000 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
6001 && in_flags
!= out_flags
)
6003 /* Cannot mix APCS26 and APCS32 code. */
6004 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
6007 /* Cannot mix float APCS and non-float APCS code. */
6008 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
6011 /* If the src and dest have different interworking flags
6012 then turn off the interworking bit. */
6013 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
6015 if (out_flags
& EF_ARM_INTERWORK
)
6017 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6020 in_flags
&= ~EF_ARM_INTERWORK
;
6023 /* Likewise for PIC, though don't warn for this case. */
6024 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
6025 in_flags
&= ~EF_ARM_PIC
;
6028 elf_elfheader (obfd
)->e_flags
= in_flags
;
6029 elf_flags_init (obfd
) = TRUE
;
6031 /* Also copy the EI_OSABI field. */
6032 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
6033 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
6035 /* Copy EABI object attributes. */
6036 copy_eabi_attributes (ibfd
, obfd
);
6041 /* Values for Tag_ABI_PCS_R9_use. */
6050 /* Values for Tag_ABI_PCS_RW_data. */
6053 AEABI_PCS_RW_data_absolute
,
6054 AEABI_PCS_RW_data_PCrel
,
6055 AEABI_PCS_RW_data_SBrel
,
6056 AEABI_PCS_RW_data_unused
6059 /* Values for Tag_ABI_enum_size. */
6065 AEABI_enum_forced_wide
6068 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
6069 are conflicting attributes. */
6071 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
6073 aeabi_attribute
*in_attr
;
6074 aeabi_attribute
*out_attr
;
6075 aeabi_attribute_list
*in_list
;
6076 aeabi_attribute_list
*out_list
;
6077 /* Some tags have 0 = don't care, 1 = strong requirement,
6078 2 = weak requirement. */
6079 static const int order_312
[3] = {3, 1, 2};
6082 if (!elf32_arm_tdata (ibfd
)->known_eabi_attributes
[0].i
)
6084 /* This is the first object. Copy the attributes. */
6085 copy_eabi_attributes (ibfd
, obfd
);
6089 /* Use the Tag_null value to indicate the attributes have been
6091 elf32_arm_tdata (ibfd
)->known_eabi_attributes
[0].i
= 1;
6093 in_attr
= elf32_arm_tdata (ibfd
)->known_eabi_attributes
;
6094 out_attr
= elf32_arm_tdata (obfd
)->known_eabi_attributes
;
6095 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6096 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
6098 /* Ignore mismatches if teh object doesn't use floating point. */
6099 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
6100 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
6101 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
6104 (_("ERROR: %B uses VFP register arguments, %B does not"),
6110 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
6112 /* Merge this attribute with existing attributes. */
6115 case Tag_CPU_raw_name
:
6117 /* Use whichever has the greatest architecture requirements. */
6118 if (in_attr
[Tag_CPU_arch
].i
> out_attr
[Tag_CPU_arch
].i
)
6119 out_attr
[i
].s
= attr_strdup(obfd
, in_attr
[i
].s
);
6122 case Tag_ABI_optimization_goals
:
6123 case Tag_ABI_FP_optimization_goals
:
6124 /* Use the first value seen. */
6128 case Tag_ARM_ISA_use
:
6129 case Tag_THUMB_ISA_use
:
6133 /* ??? Do NEON and WMMX conflict? */
6134 case Tag_ABI_FP_rounding
:
6135 case Tag_ABI_FP_denormal
:
6136 case Tag_ABI_FP_exceptions
:
6137 case Tag_ABI_FP_user_exceptions
:
6138 case Tag_ABI_FP_number_model
:
6139 case Tag_ABI_align8_preserved
:
6140 case Tag_ABI_HardFP_use
:
6141 /* Use the largest value specified. */
6142 if (in_attr
[i
].i
> out_attr
[i
].i
)
6143 out_attr
[i
].i
= in_attr
[i
].i
;
6146 case Tag_CPU_arch_profile
:
6147 /* Warn if conflicting architecture profiles used. */
6148 if (out_attr
[i
].i
&& in_attr
[i
].i
&& in_attr
[i
].i
!= out_attr
[i
].i
)
6151 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6152 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
6156 out_attr
[i
].i
= in_attr
[i
].i
;
6158 case Tag_PCS_config
:
6159 if (out_attr
[i
].i
== 0)
6160 out_attr
[i
].i
= in_attr
[i
].i
;
6161 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
6163 /* It's sometimes ok to mix different configs, so this is only
6166 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
6169 case Tag_ABI_PCS_R9_use
:
6170 if (out_attr
[i
].i
!= AEABI_R9_unused
6171 && in_attr
[i
].i
!= AEABI_R9_unused
)
6174 (_("ERROR: %B: Conflicting use of R9"), ibfd
);
6177 if (out_attr
[i
].i
== AEABI_R9_unused
)
6178 out_attr
[i
].i
= in_attr
[i
].i
;
6180 case Tag_ABI_PCS_RW_data
:
6181 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
6182 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
6183 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
6186 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6190 /* Use the smallest value specified. */
6191 if (in_attr
[i
].i
< out_attr
[i
].i
)
6192 out_attr
[i
].i
= in_attr
[i
].i
;
6194 case Tag_ABI_PCS_RO_data
:
6195 /* Use the smallest value specified. */
6196 if (in_attr
[i
].i
< out_attr
[i
].i
)
6197 out_attr
[i
].i
= in_attr
[i
].i
;
6199 case Tag_ABI_PCS_GOT_use
:
6200 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
6201 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
6202 out_attr
[i
].i
= in_attr
[i
].i
;
6204 case Tag_ABI_PCS_wchar_t
:
6205 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
)
6208 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd
);
6212 out_attr
[i
].i
= in_attr
[i
].i
;
6214 case Tag_ABI_align8_needed
:
6215 /* ??? Check against Tag_ABI_align8_preserved. */
6216 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
6217 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
6218 out_attr
[i
].i
= in_attr
[i
].i
;
6220 case Tag_ABI_enum_size
:
6221 if (in_attr
[i
].i
!= AEABI_enum_unused
)
6223 if (out_attr
[i
].i
== AEABI_enum_unused
6224 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
6226 /* The existing object is compatible with anything.
6227 Use whatever requirements the new object has. */
6228 out_attr
[i
].i
= in_attr
[i
].i
;
6230 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
6231 && out_attr
[i
].i
!= in_attr
[i
].i
)
6234 (_("ERROR: %B: Conflicting enum sizes"), ibfd
);
6238 case Tag_ABI_VFP_args
:
6241 case Tag_ABI_WMMX_args
:
6242 if (in_attr
[i
].i
!= out_attr
[i
].i
)
6245 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6250 default: /* All known attributes should be explicitly covered. */
6255 in_list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
6256 out_list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
6257 while (in_list
&& in_list
->tag
== Tag_compatibility
)
6259 in_attr
= &in_list
->attr
;
6260 if (in_attr
->i
== 0)
6262 if (in_attr
->i
== 1)
6265 (_("ERROR: %B: Must be processed by '%s' toolchain"),
6269 if (!out_list
|| out_list
->tag
!= Tag_compatibility
6270 || strcmp (in_attr
->s
, out_list
->attr
.s
) != 0)
6272 /* Add this compatibility tag to the output. */
6273 elf32_arm_add_eabi_attr_compat (obfd
, in_attr
->i
, in_attr
->s
);
6276 out_attr
= &out_list
->attr
;
6277 /* Check all the input tags with the same identifier. */
6280 if (out_list
->tag
!= Tag_compatibility
6281 || in_attr
->i
!= out_attr
->i
6282 || strcmp (in_attr
->s
, out_attr
->s
) != 0)
6285 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6286 ibfd
, in_attr
->s
, in_attr
->i
);
6289 in_list
= in_list
->next
;
6290 if (in_list
->tag
!= Tag_compatibility
6291 || strcmp (in_attr
->s
, in_list
->attr
.s
) != 0)
6293 in_attr
= &in_list
->attr
;
6294 out_list
= out_list
->next
;
6296 out_attr
= &out_list
->attr
;
6299 /* Check the output doesn't have extra tags with this identifier. */
6300 if (out_list
&& out_list
->tag
== Tag_compatibility
6301 && strcmp (in_attr
->s
, out_list
->attr
.s
) == 0)
6304 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6305 ibfd
, in_attr
->s
, out_list
->attr
.i
);
6310 for (; in_list
; in_list
= in_list
->next
)
6312 if ((in_list
->tag
& 128) < 64)
6315 (_("Warning: %B: Unknown EABI object attribute %d"),
6316 ibfd
, in_list
->tag
);
6324 /* Return TRUE if the two EABI versions are incompatible. */
6327 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
6329 /* v4 and v5 are the same spec before and after it was released,
6330 so allow mixing them. */
6331 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
6332 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
6335 return (iver
== over
);
6338 /* Merge backend specific data from an object file to the output
6339 object file when linking. */
6342 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
6346 bfd_boolean flags_compatible
= TRUE
;
6349 /* Check if we have the same endianess. */
6350 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
6353 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6354 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6357 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
6360 /* The input BFD must have had its flags initialised. */
6361 /* The following seems bogus to me -- The flags are initialized in
6362 the assembler but I don't think an elf_flags_init field is
6363 written into the object. */
6364 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6366 in_flags
= elf_elfheader (ibfd
)->e_flags
;
6367 out_flags
= elf_elfheader (obfd
)->e_flags
;
6369 if (!elf_flags_init (obfd
))
6371 /* If the input is the default architecture and had the default
6372 flags then do not bother setting the flags for the output
6373 architecture, instead allow future merges to do this. If no
6374 future merges ever set these flags then they will retain their
6375 uninitialised values, which surprise surprise, correspond
6376 to the default values. */
6377 if (bfd_get_arch_info (ibfd
)->the_default
6378 && elf_elfheader (ibfd
)->e_flags
== 0)
6381 elf_flags_init (obfd
) = TRUE
;
6382 elf_elfheader (obfd
)->e_flags
= in_flags
;
6384 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
6385 && bfd_get_arch_info (obfd
)->the_default
)
6386 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
6391 /* Determine what should happen if the input ARM architecture
6392 does not match the output ARM architecture. */
6393 if (! bfd_arm_merge_machines (ibfd
, obfd
))
6396 /* Identical flags must be compatible. */
6397 if (in_flags
== out_flags
)
6400 /* Check to see if the input BFD actually contains any sections. If
6401 not, its flags may not have been initialised either, but it
6402 cannot actually cause any incompatiblity. Do not short-circuit
6403 dynamic objects; their section list may be emptied by
6404 elf_link_add_object_symbols.
6406 Also check to see if there are no code sections in the input.
6407 In this case there is no need to check for code specific flags.
6408 XXX - do we need to worry about floating-point format compatability
6409 in data sections ? */
6410 if (!(ibfd
->flags
& DYNAMIC
))
6412 bfd_boolean null_input_bfd
= TRUE
;
6413 bfd_boolean only_data_sections
= TRUE
;
6415 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6417 /* Ignore synthetic glue sections. */
6418 if (strcmp (sec
->name
, ".glue_7")
6419 && strcmp (sec
->name
, ".glue_7t"))
6421 if ((bfd_get_section_flags (ibfd
, sec
)
6422 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6423 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
6424 only_data_sections
= FALSE
;
6426 null_input_bfd
= FALSE
;
6431 if (null_input_bfd
|| only_data_sections
)
6435 /* Complain about various flag mismatches. */
6436 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
6437 EF_ARM_EABI_VERSION (out_flags
)))
6440 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
6442 (in_flags
& EF_ARM_EABIMASK
) >> 24,
6443 (out_flags
& EF_ARM_EABIMASK
) >> 24);
6447 /* Not sure what needs to be checked for EABI versions >= 1. */
6448 /* VxWorks libraries do not use these flags. */
6449 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
6450 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
6451 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
6453 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
6456 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
6458 in_flags
& EF_ARM_APCS_26
? 26 : 32,
6459 out_flags
& EF_ARM_APCS_26
? 26 : 32);
6460 flags_compatible
= FALSE
;
6463 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
6465 if (in_flags
& EF_ARM_APCS_FLOAT
)
6467 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
6471 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
6474 flags_compatible
= FALSE
;
6477 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
6479 if (in_flags
& EF_ARM_VFP_FLOAT
)
6481 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
6485 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
6488 flags_compatible
= FALSE
;
6491 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
6493 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
6495 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
6499 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
6502 flags_compatible
= FALSE
;
6505 #ifdef EF_ARM_SOFT_FLOAT
6506 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
6508 /* We can allow interworking between code that is VFP format
6509 layout, and uses either soft float or integer regs for
6510 passing floating point arguments and results. We already
6511 know that the APCS_FLOAT flags match; similarly for VFP
6513 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
6514 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
6516 if (in_flags
& EF_ARM_SOFT_FLOAT
)
6518 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
6522 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
6525 flags_compatible
= FALSE
;
6530 /* Interworking mismatch is only a warning. */
6531 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
6533 if (in_flags
& EF_ARM_INTERWORK
)
6536 (_("Warning: %B supports interworking, whereas %B does not"),
6542 (_("Warning: %B does not support interworking, whereas %B does"),
6548 return flags_compatible
;
6551 /* Display the flags field. */
6554 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
6556 FILE * file
= (FILE *) ptr
;
6557 unsigned long flags
;
6559 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
6561 /* Print normal ELF private data. */
6562 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6564 flags
= elf_elfheader (abfd
)->e_flags
;
6565 /* Ignore init flag - it may not be set, despite the flags field
6566 containing valid data. */
6568 /* xgettext:c-format */
6569 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
6571 switch (EF_ARM_EABI_VERSION (flags
))
6573 case EF_ARM_EABI_UNKNOWN
:
6574 /* The following flag bits are GNU extensions and not part of the
6575 official ARM ELF extended ABI. Hence they are only decoded if
6576 the EABI version is not set. */
6577 if (flags
& EF_ARM_INTERWORK
)
6578 fprintf (file
, _(" [interworking enabled]"));
6580 if (flags
& EF_ARM_APCS_26
)
6581 fprintf (file
, " [APCS-26]");
6583 fprintf (file
, " [APCS-32]");
6585 if (flags
& EF_ARM_VFP_FLOAT
)
6586 fprintf (file
, _(" [VFP float format]"));
6587 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
6588 fprintf (file
, _(" [Maverick float format]"));
6590 fprintf (file
, _(" [FPA float format]"));
6592 if (flags
& EF_ARM_APCS_FLOAT
)
6593 fprintf (file
, _(" [floats passed in float registers]"));
6595 if (flags
& EF_ARM_PIC
)
6596 fprintf (file
, _(" [position independent]"));
6598 if (flags
& EF_ARM_NEW_ABI
)
6599 fprintf (file
, _(" [new ABI]"));
6601 if (flags
& EF_ARM_OLD_ABI
)
6602 fprintf (file
, _(" [old ABI]"));
6604 if (flags
& EF_ARM_SOFT_FLOAT
)
6605 fprintf (file
, _(" [software FP]"));
6607 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
6608 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
6609 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
6610 | EF_ARM_MAVERICK_FLOAT
);
6613 case EF_ARM_EABI_VER1
:
6614 fprintf (file
, _(" [Version1 EABI]"));
6616 if (flags
& EF_ARM_SYMSARESORTED
)
6617 fprintf (file
, _(" [sorted symbol table]"));
6619 fprintf (file
, _(" [unsorted symbol table]"));
6621 flags
&= ~ EF_ARM_SYMSARESORTED
;
6624 case EF_ARM_EABI_VER2
:
6625 fprintf (file
, _(" [Version2 EABI]"));
6627 if (flags
& EF_ARM_SYMSARESORTED
)
6628 fprintf (file
, _(" [sorted symbol table]"));
6630 fprintf (file
, _(" [unsorted symbol table]"));
6632 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
6633 fprintf (file
, _(" [dynamic symbols use segment index]"));
6635 if (flags
& EF_ARM_MAPSYMSFIRST
)
6636 fprintf (file
, _(" [mapping symbols precede others]"));
6638 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
6639 | EF_ARM_MAPSYMSFIRST
);
6642 case EF_ARM_EABI_VER3
:
6643 fprintf (file
, _(" [Version3 EABI]"));
6646 case EF_ARM_EABI_VER4
:
6647 fprintf (file
, _(" [Version4 EABI]"));
6650 case EF_ARM_EABI_VER5
:
6651 fprintf (file
, _(" [Version5 EABI]"));
6653 if (flags
& EF_ARM_BE8
)
6654 fprintf (file
, _(" [BE8]"));
6656 if (flags
& EF_ARM_LE8
)
6657 fprintf (file
, _(" [LE8]"));
6659 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
6663 fprintf (file
, _(" <EABI version unrecognised>"));
6667 flags
&= ~ EF_ARM_EABIMASK
;
6669 if (flags
& EF_ARM_RELEXEC
)
6670 fprintf (file
, _(" [relocatable executable]"));
6672 if (flags
& EF_ARM_HASENTRY
)
6673 fprintf (file
, _(" [has entry point]"));
6675 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
6678 fprintf (file
, _("<Unrecognised flag bits set>"));
6686 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
6688 switch (ELF_ST_TYPE (elf_sym
->st_info
))
6691 return ELF_ST_TYPE (elf_sym
->st_info
);
6694 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
6695 This allows us to distinguish between data used by Thumb instructions
6696 and non-data (which is probably code) inside Thumb regions of an
6698 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
6699 return ELF_ST_TYPE (elf_sym
->st_info
);
6710 elf32_arm_gc_mark_hook (asection
*sec
,
6711 struct bfd_link_info
*info
,
6712 Elf_Internal_Rela
*rel
,
6713 struct elf_link_hash_entry
*h
,
6714 Elf_Internal_Sym
*sym
)
6717 switch (ELF32_R_TYPE (rel
->r_info
))
6719 case R_ARM_GNU_VTINHERIT
:
6720 case R_ARM_GNU_VTENTRY
:
6724 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6727 /* Update the got entry reference counts for the section being removed. */
6730 elf32_arm_gc_sweep_hook (bfd
* abfd
,
6731 struct bfd_link_info
* info
,
6733 const Elf_Internal_Rela
* relocs
)
6735 Elf_Internal_Shdr
*symtab_hdr
;
6736 struct elf_link_hash_entry
**sym_hashes
;
6737 bfd_signed_vma
*local_got_refcounts
;
6738 const Elf_Internal_Rela
*rel
, *relend
;
6739 struct elf32_arm_link_hash_table
* globals
;
6741 globals
= elf32_arm_hash_table (info
);
6743 elf_section_data (sec
)->local_dynrel
= NULL
;
6745 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6746 sym_hashes
= elf_sym_hashes (abfd
);
6747 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6749 relend
= relocs
+ sec
->reloc_count
;
6750 for (rel
= relocs
; rel
< relend
; rel
++)
6752 unsigned long r_symndx
;
6753 struct elf_link_hash_entry
*h
= NULL
;
6756 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6757 if (r_symndx
>= symtab_hdr
->sh_info
)
6759 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6760 while (h
->root
.type
== bfd_link_hash_indirect
6761 || h
->root
.type
== bfd_link_hash_warning
)
6762 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6765 r_type
= ELF32_R_TYPE (rel
->r_info
);
6766 r_type
= arm_real_reloc_type (globals
, r_type
);
6770 case R_ARM_GOT_PREL
:
6771 case R_ARM_TLS_GD32
:
6772 case R_ARM_TLS_IE32
:
6775 if (h
->got
.refcount
> 0)
6776 h
->got
.refcount
-= 1;
6778 else if (local_got_refcounts
!= NULL
)
6780 if (local_got_refcounts
[r_symndx
] > 0)
6781 local_got_refcounts
[r_symndx
] -= 1;
6785 case R_ARM_TLS_LDM32
:
6786 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
6796 case R_ARM_THM_CALL
:
6797 case R_ARM_MOVW_ABS_NC
:
6798 case R_ARM_MOVT_ABS
:
6799 case R_ARM_MOVW_PREL_NC
:
6800 case R_ARM_MOVT_PREL
:
6801 case R_ARM_THM_MOVW_ABS_NC
:
6802 case R_ARM_THM_MOVT_ABS
:
6803 case R_ARM_THM_MOVW_PREL_NC
:
6804 case R_ARM_THM_MOVT_PREL
:
6805 /* Should the interworking branches be here also? */
6809 struct elf32_arm_link_hash_entry
*eh
;
6810 struct elf32_arm_relocs_copied
**pp
;
6811 struct elf32_arm_relocs_copied
*p
;
6813 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6815 if (h
->plt
.refcount
> 0)
6817 h
->plt
.refcount
-= 1;
6818 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_CALL
)
6819 eh
->plt_thumb_refcount
--;
6822 if (r_type
== R_ARM_ABS32
6823 || r_type
== R_ARM_REL32
)
6825 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
6827 if (p
->section
== sec
)
6830 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
6848 /* Look through the relocs for a section during the first phase. */
6851 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
6852 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6854 Elf_Internal_Shdr
*symtab_hdr
;
6855 struct elf_link_hash_entry
**sym_hashes
;
6856 struct elf_link_hash_entry
**sym_hashes_end
;
6857 const Elf_Internal_Rela
*rel
;
6858 const Elf_Internal_Rela
*rel_end
;
6861 bfd_vma
*local_got_offsets
;
6862 struct elf32_arm_link_hash_table
*htab
;
6864 if (info
->relocatable
)
6867 htab
= elf32_arm_hash_table (info
);
6870 /* Create dynamic sections for relocatable executables so that we can
6871 copy relocations. */
6872 if (htab
->root
.is_relocatable_executable
6873 && ! htab
->root
.dynamic_sections_created
)
6875 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
6879 dynobj
= elf_hash_table (info
)->dynobj
;
6880 local_got_offsets
= elf_local_got_offsets (abfd
);
6882 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6883 sym_hashes
= elf_sym_hashes (abfd
);
6884 sym_hashes_end
= sym_hashes
6885 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
6887 if (!elf_bad_symtab (abfd
))
6888 sym_hashes_end
-= symtab_hdr
->sh_info
;
6890 rel_end
= relocs
+ sec
->reloc_count
;
6891 for (rel
= relocs
; rel
< rel_end
; rel
++)
6893 struct elf_link_hash_entry
*h
;
6894 struct elf32_arm_link_hash_entry
*eh
;
6895 unsigned long r_symndx
;
6898 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6899 r_type
= ELF32_R_TYPE (rel
->r_info
);
6900 r_type
= arm_real_reloc_type (htab
, r_type
);
6902 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
6904 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
6909 if (r_symndx
< symtab_hdr
->sh_info
)
6913 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6914 while (h
->root
.type
== bfd_link_hash_indirect
6915 || h
->root
.type
== bfd_link_hash_warning
)
6916 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6919 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6924 case R_ARM_GOT_PREL
:
6925 case R_ARM_TLS_GD32
:
6926 case R_ARM_TLS_IE32
:
6927 /* This symbol requires a global offset table entry. */
6929 int tls_type
, old_tls_type
;
6933 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
6934 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
6935 default: tls_type
= GOT_NORMAL
; break;
6941 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
6945 bfd_signed_vma
*local_got_refcounts
;
6947 /* This is a global offset table entry for a local symbol. */
6948 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6949 if (local_got_refcounts
== NULL
)
6953 size
= symtab_hdr
->sh_info
;
6954 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
6955 local_got_refcounts
= bfd_zalloc (abfd
, size
);
6956 if (local_got_refcounts
== NULL
)
6958 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6959 elf32_arm_local_got_tls_type (abfd
)
6960 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6962 local_got_refcounts
[r_symndx
] += 1;
6963 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
6966 /* We will already have issued an error message if there is a
6967 TLS / non-TLS mismatch, based on the symbol type. We don't
6968 support any linker relaxations. So just combine any TLS
6970 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
6971 && tls_type
!= GOT_NORMAL
)
6972 tls_type
|= old_tls_type
;
6974 if (old_tls_type
!= tls_type
)
6977 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
6979 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6984 case R_ARM_TLS_LDM32
:
6985 if (r_type
== R_ARM_TLS_LDM32
)
6986 htab
->tls_ldm_got
.refcount
++;
6989 case R_ARM_GOTOFF32
:
6991 if (htab
->sgot
== NULL
)
6993 if (htab
->root
.dynobj
== NULL
)
6994 htab
->root
.dynobj
= abfd
;
6995 if (!create_got_section (htab
->root
.dynobj
, info
))
7001 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7002 ldr __GOTT_INDEX__ offsets. */
7003 if (!htab
->vxworks_p
)
7014 case R_ARM_THM_CALL
:
7015 case R_ARM_MOVW_ABS_NC
:
7016 case R_ARM_MOVT_ABS
:
7017 case R_ARM_MOVW_PREL_NC
:
7018 case R_ARM_MOVT_PREL
:
7019 case R_ARM_THM_MOVW_ABS_NC
:
7020 case R_ARM_THM_MOVT_ABS
:
7021 case R_ARM_THM_MOVW_PREL_NC
:
7022 case R_ARM_THM_MOVT_PREL
:
7023 /* Should the interworking branches be listed here? */
7026 /* If this reloc is in a read-only section, we might
7027 need a copy reloc. We can't check reliably at this
7028 stage whether the section is read-only, as input
7029 sections have not yet been mapped to output sections.
7030 Tentatively set the flag for now, and correct in
7031 adjust_dynamic_symbol. */
7035 /* We may need a .plt entry if the function this reloc
7036 refers to is in a different object. We can't tell for
7037 sure yet, because something later might force the
7039 if (r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
7042 /* If we create a PLT entry, this relocation will reference
7043 it, even if it's an ABS32 relocation. */
7044 h
->plt
.refcount
+= 1;
7046 if (r_type
== R_ARM_THM_CALL
)
7047 eh
->plt_thumb_refcount
+= 1;
7050 /* If we are creating a shared library or relocatable executable,
7051 and this is a reloc against a global symbol, or a non PC
7052 relative reloc against a local symbol, then we need to copy
7053 the reloc into the shared library. However, if we are linking
7054 with -Bsymbolic, we do not need to copy a reloc against a
7055 global symbol which is defined in an object we are
7056 including in the link (i.e., DEF_REGULAR is set). At
7057 this point we have not seen all the input files, so it is
7058 possible that DEF_REGULAR is not set now but will be set
7059 later (it is never cleared). We account for that
7060 possibility below by storing information in the
7061 relocs_copied field of the hash table entry. */
7062 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
7063 && (sec
->flags
& SEC_ALLOC
) != 0
7064 && (r_type
== R_ARM_ABS32
7065 || (h
!= NULL
&& ! h
->needs_plt
7066 && (! info
->symbolic
|| ! h
->def_regular
))))
7068 struct elf32_arm_relocs_copied
*p
, **head
;
7070 /* When creating a shared object, we must copy these
7071 reloc types into the output file. We create a reloc
7072 section in dynobj and make room for this reloc. */
7077 name
= (bfd_elf_string_from_elf_section
7079 elf_elfheader (abfd
)->e_shstrndx
,
7080 elf_section_data (sec
)->rel_hdr
.sh_name
));
7084 BFD_ASSERT (reloc_section_p (htab
, name
, sec
));
7086 sreloc
= bfd_get_section_by_name (dynobj
, name
);
7091 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
7092 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
7093 if ((sec
->flags
& SEC_ALLOC
) != 0
7094 /* BPABI objects never have dynamic
7095 relocations mapped. */
7096 && !htab
->symbian_p
)
7097 flags
|= SEC_ALLOC
| SEC_LOAD
;
7098 sreloc
= bfd_make_section_with_flags (dynobj
,
7102 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
7106 elf_section_data (sec
)->sreloc
= sreloc
;
7109 /* If this is a global symbol, we count the number of
7110 relocations we need for this symbol. */
7113 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
7117 /* Track dynamic relocs needed for local syms too.
7118 We really need local syms available to do this
7124 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
7129 vpp
= &elf_section_data (s
)->local_dynrel
;
7130 head
= (struct elf32_arm_relocs_copied
**) vpp
;
7134 if (p
== NULL
|| p
->section
!= sec
)
7136 bfd_size_type amt
= sizeof *p
;
7138 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
7148 if (r_type
== R_ARM_REL32
)
7154 /* This relocation describes the C++ object vtable hierarchy.
7155 Reconstruct it for later use during GC. */
7156 case R_ARM_GNU_VTINHERIT
:
7157 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7161 /* This relocation describes which C++ vtable entries are actually
7162 used. Record for later use during GC. */
7163 case R_ARM_GNU_VTENTRY
:
7164 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7173 /* Treat mapping symbols as special target symbols. */
7176 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
7178 return bfd_is_arm_special_symbol_name (sym
->name
,
7179 BFD_ARM_SPECIAL_SYM_TYPE_ANY
);
7182 /* This is a copy of elf_find_function() from elf.c except that
7183 ARM mapping symbols are ignored when looking for function names
7184 and STT_ARM_TFUNC is considered to a function type. */
7187 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
7191 const char ** filename_ptr
,
7192 const char ** functionname_ptr
)
7194 const char * filename
= NULL
;
7195 asymbol
* func
= NULL
;
7196 bfd_vma low_func
= 0;
7199 for (p
= symbols
; *p
!= NULL
; p
++)
7203 q
= (elf_symbol_type
*) *p
;
7205 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
7210 filename
= bfd_asymbol_name (&q
->symbol
);
7215 /* Skip mapping symbols. */
7216 if ((q
->symbol
.flags
& BSF_LOCAL
)
7217 && bfd_is_arm_special_symbol_name (q
->symbol
.name
,
7218 BFD_ARM_SPECIAL_SYM_TYPE_ANY
))
7221 if (bfd_get_section (&q
->symbol
) == section
7222 && q
->symbol
.value
>= low_func
7223 && q
->symbol
.value
<= offset
)
7225 func
= (asymbol
*) q
;
7226 low_func
= q
->symbol
.value
;
7236 *filename_ptr
= filename
;
7237 if (functionname_ptr
)
7238 *functionname_ptr
= bfd_asymbol_name (func
);
7244 /* Find the nearest line to a particular section and offset, for error
7245 reporting. This code is a duplicate of the code in elf.c, except
7246 that it uses arm_elf_find_function. */
7249 elf32_arm_find_nearest_line (bfd
* abfd
,
7253 const char ** filename_ptr
,
7254 const char ** functionname_ptr
,
7255 unsigned int * line_ptr
)
7257 bfd_boolean found
= FALSE
;
7259 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7261 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
7262 filename_ptr
, functionname_ptr
,
7264 & elf_tdata (abfd
)->dwarf2_find_line_info
))
7266 if (!*functionname_ptr
)
7267 arm_elf_find_function (abfd
, section
, symbols
, offset
,
7268 *filename_ptr
? NULL
: filename_ptr
,
7274 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
7275 & found
, filename_ptr
,
7276 functionname_ptr
, line_ptr
,
7277 & elf_tdata (abfd
)->line_info
))
7280 if (found
&& (*functionname_ptr
|| *line_ptr
))
7283 if (symbols
== NULL
)
7286 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
7287 filename_ptr
, functionname_ptr
))
7295 elf32_arm_find_inliner_info (bfd
* abfd
,
7296 const char ** filename_ptr
,
7297 const char ** functionname_ptr
,
7298 unsigned int * line_ptr
)
7301 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
7302 functionname_ptr
, line_ptr
,
7303 & elf_tdata (abfd
)->dwarf2_find_line_info
);
7307 /* Adjust a symbol defined by a dynamic object and referenced by a
7308 regular object. The current definition is in some section of the
7309 dynamic object, but we're not including those sections. We have to
7310 change the definition to something the rest of the link can
7314 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
7315 struct elf_link_hash_entry
* h
)
7319 unsigned int power_of_two
;
7320 struct elf32_arm_link_hash_entry
* eh
;
7321 struct elf32_arm_link_hash_table
*globals
;
7323 globals
= elf32_arm_hash_table (info
);
7324 dynobj
= elf_hash_table (info
)->dynobj
;
7326 /* Make sure we know what is going on here. */
7327 BFD_ASSERT (dynobj
!= NULL
7329 || h
->u
.weakdef
!= NULL
7332 && !h
->def_regular
)));
7334 eh
= (struct elf32_arm_link_hash_entry
*) h
;
7336 /* If this is a function, put it in the procedure linkage table. We
7337 will fill in the contents of the procedure linkage table later,
7338 when we know the address of the .got section. */
7339 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
7342 if (h
->plt
.refcount
<= 0
7343 || SYMBOL_CALLS_LOCAL (info
, h
)
7344 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7345 && h
->root
.type
== bfd_link_hash_undefweak
))
7347 /* This case can occur if we saw a PLT32 reloc in an input
7348 file, but the symbol was never referred to by a dynamic
7349 object, or if all references were garbage collected. In
7350 such a case, we don't actually need to build a procedure
7351 linkage table, and we can just do a PC24 reloc instead. */
7352 h
->plt
.offset
= (bfd_vma
) -1;
7353 eh
->plt_thumb_refcount
= 0;
7361 /* It's possible that we incorrectly decided a .plt reloc was
7362 needed for an R_ARM_PC24 or similar reloc to a non-function sym
7363 in check_relocs. We can't decide accurately between function
7364 and non-function syms in check-relocs; Objects loaded later in
7365 the link may change h->type. So fix it now. */
7366 h
->plt
.offset
= (bfd_vma
) -1;
7367 eh
->plt_thumb_refcount
= 0;
7370 /* If this is a weak symbol, and there is a real definition, the
7371 processor independent code will have arranged for us to see the
7372 real definition first, and we can just use the same value. */
7373 if (h
->u
.weakdef
!= NULL
)
7375 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7376 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7377 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7378 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7382 /* If there are no non-GOT references, we do not need a copy
7384 if (!h
->non_got_ref
)
7387 /* This is a reference to a symbol defined by a dynamic object which
7388 is not a function. */
7390 /* If we are creating a shared library, we must presume that the
7391 only references to the symbol are via the global offset table.
7392 For such cases we need not do anything here; the relocations will
7393 be handled correctly by relocate_section. Relocatable executables
7394 can reference data in shared objects directly, so we don't need to
7395 do anything here. */
7396 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
7401 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
7402 h
->root
.root
.string
);
7406 /* We must allocate the symbol in our .dynbss section, which will
7407 become part of the .bss section of the executable. There will be
7408 an entry for this symbol in the .dynsym section. The dynamic
7409 object will contain position independent code, so all references
7410 from the dynamic object to this symbol will go through the global
7411 offset table. The dynamic linker will use the .dynsym entry to
7412 determine the address it must put in the global offset table, so
7413 both the dynamic object and the regular object will refer to the
7414 same memory location for the variable. */
7415 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
7416 BFD_ASSERT (s
!= NULL
);
7418 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
7419 copy the initial value out of the dynamic object and into the
7420 runtime process image. We need to remember the offset into the
7421 .rel(a).bss section we are going to use. */
7422 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
7426 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
7427 BFD_ASSERT (srel
!= NULL
);
7428 srel
->size
+= RELOC_SIZE (globals
);
7432 /* We need to figure out the alignment required for this symbol. I
7433 have no idea how ELF linkers handle this. */
7434 power_of_two
= bfd_log2 (h
->size
);
7435 if (power_of_two
> 3)
7438 /* Apply the required alignment. */
7439 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
7440 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
7442 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
7446 /* Define the symbol as being at this point in the section. */
7447 h
->root
.u
.def
.section
= s
;
7448 h
->root
.u
.def
.value
= s
->size
;
7450 /* Increment the section size to make room for the symbol. */
7456 /* Allocate space in .plt, .got and associated reloc sections for
7460 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
7462 struct bfd_link_info
*info
;
7463 struct elf32_arm_link_hash_table
*htab
;
7464 struct elf32_arm_link_hash_entry
*eh
;
7465 struct elf32_arm_relocs_copied
*p
;
7467 eh
= (struct elf32_arm_link_hash_entry
*) h
;
7469 if (h
->root
.type
== bfd_link_hash_indirect
)
7472 if (h
->root
.type
== bfd_link_hash_warning
)
7473 /* When warning symbols are created, they **replace** the "real"
7474 entry in the hash table, thus we never get to see the real
7475 symbol in a hash traversal. So look at it now. */
7476 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7478 info
= (struct bfd_link_info
*) inf
;
7479 htab
= elf32_arm_hash_table (info
);
7481 if (htab
->root
.dynamic_sections_created
7482 && h
->plt
.refcount
> 0)
7484 /* Make sure this symbol is output as a dynamic symbol.
7485 Undefined weak syms won't yet be marked as dynamic. */
7486 if (h
->dynindx
== -1
7487 && !h
->forced_local
)
7489 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7494 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
7496 asection
*s
= htab
->splt
;
7498 /* If this is the first .plt entry, make room for the special
7501 s
->size
+= htab
->plt_header_size
;
7503 h
->plt
.offset
= s
->size
;
7505 /* If we will insert a Thumb trampoline before this PLT, leave room
7507 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
7509 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
7510 s
->size
+= PLT_THUMB_STUB_SIZE
;
7513 /* If this symbol is not defined in a regular file, and we are
7514 not generating a shared library, then set the symbol to this
7515 location in the .plt. This is required to make function
7516 pointers compare as equal between the normal executable and
7517 the shared library. */
7521 h
->root
.u
.def
.section
= s
;
7522 h
->root
.u
.def
.value
= h
->plt
.offset
;
7524 /* Make sure the function is not marked as Thumb, in case
7525 it is the target of an ABS32 relocation, which will
7526 point to the PLT entry. */
7527 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
7528 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
7531 /* Make room for this entry. */
7532 s
->size
+= htab
->plt_entry_size
;
7534 if (!htab
->symbian_p
)
7536 /* We also need to make an entry in the .got.plt section, which
7537 will be placed in the .got section by the linker script. */
7538 eh
->plt_got_offset
= htab
->sgotplt
->size
;
7539 htab
->sgotplt
->size
+= 4;
7542 /* We also need to make an entry in the .rel(a).plt section. */
7543 htab
->srelplt
->size
+= RELOC_SIZE (htab
);
7545 /* VxWorks executables have a second set of relocations for
7546 each PLT entry. They go in a separate relocation section,
7547 which is processed by the kernel loader. */
7548 if (htab
->vxworks_p
&& !info
->shared
)
7550 /* There is a relocation for the initial PLT entry:
7551 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
7552 if (h
->plt
.offset
== htab
->plt_header_size
)
7553 htab
->srelplt2
->size
+= RELOC_SIZE (htab
);
7555 /* There are two extra relocations for each subsequent
7556 PLT entry: an R_ARM_32 relocation for the GOT entry,
7557 and an R_ARM_32 relocation for the PLT entry. */
7558 htab
->srelplt2
->size
+= RELOC_SIZE (htab
) * 2;
7563 h
->plt
.offset
= (bfd_vma
) -1;
7569 h
->plt
.offset
= (bfd_vma
) -1;
7573 if (h
->got
.refcount
> 0)
7577 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
7580 /* Make sure this symbol is output as a dynamic symbol.
7581 Undefined weak syms won't yet be marked as dynamic. */
7582 if (h
->dynindx
== -1
7583 && !h
->forced_local
)
7585 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7589 if (!htab
->symbian_p
)
7592 h
->got
.offset
= s
->size
;
7594 if (tls_type
== GOT_UNKNOWN
)
7597 if (tls_type
== GOT_NORMAL
)
7598 /* Non-TLS symbols need one GOT slot. */
7602 if (tls_type
& GOT_TLS_GD
)
7603 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
7605 if (tls_type
& GOT_TLS_IE
)
7606 /* R_ARM_TLS_IE32 needs one GOT slot. */
7610 dyn
= htab
->root
.dynamic_sections_created
;
7613 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7615 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
7618 if (tls_type
!= GOT_NORMAL
7619 && (info
->shared
|| indx
!= 0)
7620 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7621 || h
->root
.type
!= bfd_link_hash_undefweak
))
7623 if (tls_type
& GOT_TLS_IE
)
7624 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
7626 if (tls_type
& GOT_TLS_GD
)
7627 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
7629 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
7630 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
7632 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7633 || h
->root
.type
!= bfd_link_hash_undefweak
)
7635 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
7636 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
7640 h
->got
.offset
= (bfd_vma
) -1;
7642 /* Allocate stubs for exported Thumb functions on v4t. */
7643 if (!htab
->use_blx
&& h
->dynindx
!= -1
7644 && ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
7645 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
7647 struct elf_link_hash_entry
* th
;
7648 struct bfd_link_hash_entry
* bh
;
7649 struct elf_link_hash_entry
* myh
;
7653 /* Create a new symbol to regist the real location of the function. */
7654 s
= h
->root
.u
.def
.section
;
7655 sprintf(name
, "__real_%s", h
->root
.root
.string
);
7656 _bfd_generic_link_add_one_symbol (info
, s
->owner
,
7657 name
, BSF_GLOBAL
, s
,
7658 h
->root
.u
.def
.value
,
7659 NULL
, TRUE
, FALSE
, &bh
);
7661 myh
= (struct elf_link_hash_entry
*) bh
;
7662 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
7663 myh
->forced_local
= 1;
7664 eh
->export_glue
= myh
;
7665 th
= record_arm_to_thumb_glue (info
, h
);
7666 /* Point the symbol at the stub. */
7667 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
7668 h
->root
.u
.def
.section
= th
->root
.u
.def
.section
;
7669 h
->root
.u
.def
.value
= th
->root
.u
.def
.value
& ~1;
7672 if (eh
->relocs_copied
== NULL
)
7675 /* In the shared -Bsymbolic case, discard space allocated for
7676 dynamic pc-relative relocs against symbols which turn out to be
7677 defined in regular objects. For the normal shared case, discard
7678 space for pc-relative relocs that have become local due to symbol
7679 visibility changes. */
7681 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
7683 /* The only reloc that uses pc_count is R_ARM_REL32, which will
7684 appear on something like ".long foo - .". We want calls to
7685 protected symbols to resolve directly to the function rather
7686 than going via the plt. If people want function pointer
7687 comparisons to work as expected then they should avoid
7688 writing assembly like ".long foo - .". */
7689 if (SYMBOL_CALLS_LOCAL (info
, h
))
7691 struct elf32_arm_relocs_copied
**pp
;
7693 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
7695 p
->count
-= p
->pc_count
;
7704 /* Also discard relocs on undefined weak syms with non-default
7706 if (eh
->relocs_copied
!= NULL
7707 && h
->root
.type
== bfd_link_hash_undefweak
)
7709 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7710 eh
->relocs_copied
= NULL
;
7712 /* Make sure undefined weak symbols are output as a dynamic
7714 else if (h
->dynindx
== -1
7715 && !h
->forced_local
)
7717 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7722 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
7723 && h
->root
.type
== bfd_link_hash_new
)
7725 /* Output absolute symbols so that we can create relocations
7726 against them. For normal symbols we output a relocation
7727 against the section that contains them. */
7728 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7735 /* For the non-shared case, discard space for relocs against
7736 symbols which turn out to need copy relocs or are not
7742 || (htab
->root
.dynamic_sections_created
7743 && (h
->root
.type
== bfd_link_hash_undefweak
7744 || h
->root
.type
== bfd_link_hash_undefined
))))
7746 /* Make sure this symbol is output as a dynamic symbol.
7747 Undefined weak syms won't yet be marked as dynamic. */
7748 if (h
->dynindx
== -1
7749 && !h
->forced_local
)
7751 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7755 /* If that succeeded, we know we'll be keeping all the
7757 if (h
->dynindx
!= -1)
7761 eh
->relocs_copied
= NULL
;
7766 /* Finally, allocate space. */
7767 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
7769 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
7770 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
7776 /* Find any dynamic relocs that apply to read-only sections. */
7779 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
7781 struct elf32_arm_link_hash_entry
*eh
;
7782 struct elf32_arm_relocs_copied
*p
;
7784 if (h
->root
.type
== bfd_link_hash_warning
)
7785 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7787 eh
= (struct elf32_arm_link_hash_entry
*) h
;
7788 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
7790 asection
*s
= p
->section
;
7792 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7794 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
7796 info
->flags
|= DF_TEXTREL
;
7798 /* Not an error, just cut short the traversal. */
7805 /* Set the sizes of the dynamic sections. */
7808 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
7809 struct bfd_link_info
* info
)
7816 struct elf32_arm_link_hash_table
*htab
;
7818 htab
= elf32_arm_hash_table (info
);
7819 dynobj
= elf_hash_table (info
)->dynobj
;
7820 BFD_ASSERT (dynobj
!= NULL
);
7821 check_use_blx (htab
);
7823 if (elf_hash_table (info
)->dynamic_sections_created
)
7825 /* Set the contents of the .interp section to the interpreter. */
7826 if (info
->executable
)
7828 s
= bfd_get_section_by_name (dynobj
, ".interp");
7829 BFD_ASSERT (s
!= NULL
);
7830 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7831 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7835 /* Set up .got offsets for local syms, and space for local dynamic
7837 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7839 bfd_signed_vma
*local_got
;
7840 bfd_signed_vma
*end_local_got
;
7841 char *local_tls_type
;
7842 bfd_size_type locsymcount
;
7843 Elf_Internal_Shdr
*symtab_hdr
;
7846 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
7849 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7851 struct elf32_arm_relocs_copied
*p
;
7853 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
7855 if (!bfd_is_abs_section (p
->section
)
7856 && bfd_is_abs_section (p
->section
->output_section
))
7858 /* Input section has been discarded, either because
7859 it is a copy of a linkonce section or due to
7860 linker script /DISCARD/, so we'll be discarding
7863 else if (p
->count
!= 0)
7865 srel
= elf_section_data (p
->section
)->sreloc
;
7866 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
7867 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
7868 info
->flags
|= DF_TEXTREL
;
7873 local_got
= elf_local_got_refcounts (ibfd
);
7877 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7878 locsymcount
= symtab_hdr
->sh_info
;
7879 end_local_got
= local_got
+ locsymcount
;
7880 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
7882 srel
= htab
->srelgot
;
7883 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
7887 *local_got
= s
->size
;
7888 if (*local_tls_type
& GOT_TLS_GD
)
7889 /* TLS_GD relocs need an 8-byte structure in the GOT. */
7891 if (*local_tls_type
& GOT_TLS_IE
)
7893 if (*local_tls_type
== GOT_NORMAL
)
7896 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
7897 srel
->size
+= RELOC_SIZE (htab
);
7900 *local_got
= (bfd_vma
) -1;
7904 if (htab
->tls_ldm_got
.refcount
> 0)
7906 /* Allocate two GOT entries and one dynamic relocation (if necessary)
7907 for R_ARM_TLS_LDM32 relocations. */
7908 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
7909 htab
->sgot
->size
+= 8;
7911 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
7914 htab
->tls_ldm_got
.offset
= -1;
7916 /* Allocate global sym .plt and .got entries, and space for global
7917 sym dynamic relocs. */
7918 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
7920 /* The check_relocs and adjust_dynamic_symbol entry points have
7921 determined the sizes of the various dynamic sections. Allocate
7925 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7929 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7932 /* It's OK to base decisions on the section name, because none
7933 of the dynobj section names depend upon the input files. */
7934 name
= bfd_get_section_name (dynobj
, s
);
7936 if (strcmp (name
, ".plt") == 0)
7938 /* Remember whether there is a PLT. */
7941 else if (CONST_STRNEQ (name
, ".rel"))
7945 /* Remember whether there are any reloc sections other
7946 than .rel(a).plt and .rela.plt.unloaded. */
7947 if (s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
7950 /* We use the reloc_count field as a counter if we need
7951 to copy relocs into the output file. */
7955 else if (! CONST_STRNEQ (name
, ".got")
7956 && strcmp (name
, ".dynbss") != 0)
7958 /* It's not one of our sections, so don't allocate space. */
7964 /* If we don't need this section, strip it from the
7965 output file. This is mostly to handle .rel(a).bss and
7966 .rel(a).plt. We must create both sections in
7967 create_dynamic_sections, because they must be created
7968 before the linker maps input sections to output
7969 sections. The linker does that before
7970 adjust_dynamic_symbol is called, and it is that
7971 function which decides whether anything needs to go
7972 into these sections. */
7973 s
->flags
|= SEC_EXCLUDE
;
7977 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
7980 /* Allocate memory for the section contents. */
7981 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
7982 if (s
->contents
== NULL
)
7986 if (elf_hash_table (info
)->dynamic_sections_created
)
7988 /* Add some entries to the .dynamic section. We fill in the
7989 values later, in elf32_arm_finish_dynamic_sections, but we
7990 must add the entries now so that we get the correct size for
7991 the .dynamic section. The DT_DEBUG entry is filled in by the
7992 dynamic linker and used by the debugger. */
7993 #define add_dynamic_entry(TAG, VAL) \
7994 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7996 if (info
->executable
)
7998 if (!add_dynamic_entry (DT_DEBUG
, 0))
8004 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
8005 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8006 || !add_dynamic_entry (DT_PLTREL
,
8007 htab
->use_rel
? DT_REL
: DT_RELA
)
8008 || !add_dynamic_entry (DT_JMPREL
, 0))
8016 if (!add_dynamic_entry (DT_REL
, 0)
8017 || !add_dynamic_entry (DT_RELSZ
, 0)
8018 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
8023 if (!add_dynamic_entry (DT_RELA
, 0)
8024 || !add_dynamic_entry (DT_RELASZ
, 0)
8025 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
8030 /* If any dynamic relocs apply to a read-only section,
8031 then we need a DT_TEXTREL entry. */
8032 if ((info
->flags
& DF_TEXTREL
) == 0)
8033 elf_link_hash_traverse (&htab
->root
, elf32_arm_readonly_dynrelocs
,
8036 if ((info
->flags
& DF_TEXTREL
) != 0)
8038 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8042 #undef add_dynamic_entry
8047 /* Finish up dynamic symbol handling. We set the contents of various
8048 dynamic sections here. */
8051 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
8052 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
8055 struct elf32_arm_link_hash_table
*htab
;
8056 struct elf32_arm_link_hash_entry
*eh
;
8058 dynobj
= elf_hash_table (info
)->dynobj
;
8059 htab
= elf32_arm_hash_table (info
);
8060 eh
= (struct elf32_arm_link_hash_entry
*) h
;
8062 if (h
->plt
.offset
!= (bfd_vma
) -1)
8068 Elf_Internal_Rela rel
;
8070 /* This symbol has an entry in the procedure linkage table. Set
8073 BFD_ASSERT (h
->dynindx
!= -1);
8075 splt
= bfd_get_section_by_name (dynobj
, ".plt");
8076 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".plt"));
8077 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
8079 /* Fill in the entry in the procedure linkage table. */
8080 if (htab
->symbian_p
)
8082 put_arm_insn (htab
, output_bfd
,
8083 elf32_arm_symbian_plt_entry
[0],
8084 splt
->contents
+ h
->plt
.offset
);
8085 bfd_put_32 (output_bfd
,
8086 elf32_arm_symbian_plt_entry
[1],
8087 splt
->contents
+ h
->plt
.offset
+ 4);
8089 /* Fill in the entry in the .rel.plt section. */
8090 rel
.r_offset
= (splt
->output_section
->vma
8091 + splt
->output_offset
8092 + h
->plt
.offset
+ 4);
8093 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
8095 /* Get the index in the procedure linkage table which
8096 corresponds to this symbol. This is the index of this symbol
8097 in all the symbols for which we are making plt entries. The
8098 first entry in the procedure linkage table is reserved. */
8099 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
8100 / htab
->plt_entry_size
);
8104 bfd_vma got_offset
, got_address
, plt_address
;
8105 bfd_vma got_displacement
;
8109 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
8110 BFD_ASSERT (sgot
!= NULL
);
8112 /* Get the offset into the .got.plt table of the entry that
8113 corresponds to this function. */
8114 got_offset
= eh
->plt_got_offset
;
8116 /* Get the index in the procedure linkage table which
8117 corresponds to this symbol. This is the index of this symbol
8118 in all the symbols for which we are making plt entries. The
8119 first three entries in .got.plt are reserved; after that
8120 symbols appear in the same order as in .plt. */
8121 plt_index
= (got_offset
- 12) / 4;
8123 /* Calculate the address of the GOT entry. */
8124 got_address
= (sgot
->output_section
->vma
8125 + sgot
->output_offset
8128 /* ...and the address of the PLT entry. */
8129 plt_address
= (splt
->output_section
->vma
8130 + splt
->output_offset
8133 ptr
= htab
->splt
->contents
+ h
->plt
.offset
;
8134 if (htab
->vxworks_p
&& info
->shared
)
8139 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++, ptr
+= 4)
8141 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
8143 val
|= got_address
- sgot
->output_section
->vma
;
8145 val
|= plt_index
* RELOC_SIZE (htab
);
8146 if (i
== 2 || i
== 5)
8147 bfd_put_32 (output_bfd
, val
, ptr
);
8149 put_arm_insn (htab
, output_bfd
, val
, ptr
);
8152 else if (htab
->vxworks_p
)
8157 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++)
8159 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
8163 val
|= 0xffffff & -((h
->plt
.offset
+ i
* 4 + 8) >> 2);
8165 val
|= plt_index
* RELOC_SIZE (htab
);
8166 if (i
== 2 || i
== 5)
8167 bfd_put_32 (output_bfd
, val
, ptr
);
8169 put_arm_insn (htab
, output_bfd
, val
, ptr
);
8172 loc
= (htab
->srelplt2
->contents
8173 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
8175 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8176 referencing the GOT for this PLT entry. */
8177 rel
.r_offset
= plt_address
+ 8;
8178 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
8179 rel
.r_addend
= got_offset
;
8180 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
8181 loc
+= RELOC_SIZE (htab
);
8183 /* Create the R_ARM_ABS32 relocation referencing the
8184 beginning of the PLT for this GOT entry. */
8185 rel
.r_offset
= got_address
;
8186 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
8188 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
8192 /* Calculate the displacement between the PLT slot and the
8193 entry in the GOT. The eight-byte offset accounts for the
8194 value produced by adding to pc in the first instruction
8196 got_displacement
= got_address
- (plt_address
+ 8);
8198 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
8200 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
8202 put_thumb_insn (htab
, output_bfd
,
8203 elf32_arm_plt_thumb_stub
[0], ptr
- 4);
8204 put_thumb_insn (htab
, output_bfd
,
8205 elf32_arm_plt_thumb_stub
[1], ptr
- 2);
8208 put_arm_insn (htab
, output_bfd
,
8209 elf32_arm_plt_entry
[0]
8210 | ((got_displacement
& 0x0ff00000) >> 20),
8212 put_arm_insn (htab
, output_bfd
,
8213 elf32_arm_plt_entry
[1]
8214 | ((got_displacement
& 0x000ff000) >> 12),
8216 put_arm_insn (htab
, output_bfd
,
8217 elf32_arm_plt_entry
[2]
8218 | (got_displacement
& 0x00000fff),
8220 #ifdef FOUR_WORD_PLT
8221 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3], ptr
+ 12);
8225 /* Fill in the entry in the global offset table. */
8226 bfd_put_32 (output_bfd
,
8227 (splt
->output_section
->vma
8228 + splt
->output_offset
),
8229 sgot
->contents
+ got_offset
);
8231 /* Fill in the entry in the .rel(a).plt section. */
8233 rel
.r_offset
= got_address
;
8234 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
8237 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
8238 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
8240 if (!h
->def_regular
)
8242 /* Mark the symbol as undefined, rather than as defined in
8243 the .plt section. Leave the value alone. */
8244 sym
->st_shndx
= SHN_UNDEF
;
8245 /* If the symbol is weak, we do need to clear the value.
8246 Otherwise, the PLT entry would provide a definition for
8247 the symbol even if the symbol wasn't defined anywhere,
8248 and so the symbol would never be NULL. */
8249 if (!h
->ref_regular_nonweak
)
8254 if (h
->got
.offset
!= (bfd_vma
) -1
8255 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
8256 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
8260 Elf_Internal_Rela rel
;
8264 /* This symbol has an entry in the global offset table. Set it
8266 sgot
= bfd_get_section_by_name (dynobj
, ".got");
8267 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".got"));
8268 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
8270 offset
= (h
->got
.offset
& ~(bfd_vma
) 1);
8272 rel
.r_offset
= (sgot
->output_section
->vma
8273 + sgot
->output_offset
8276 /* If this is a static link, or it is a -Bsymbolic link and the
8277 symbol is defined locally or was forced to be local because
8278 of a version file, we just want to emit a RELATIVE reloc.
8279 The entry in the global offset table will already have been
8280 initialized in the relocate_section function. */
8282 && SYMBOL_REFERENCES_LOCAL (info
, h
))
8284 BFD_ASSERT((h
->got
.offset
& 1) != 0);
8285 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
8288 rel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
8289 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
8294 BFD_ASSERT((h
->got
.offset
& 1) == 0);
8295 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
8296 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
8299 loc
= srel
->contents
+ srel
->reloc_count
++ * RELOC_SIZE (htab
);
8300 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
8306 Elf_Internal_Rela rel
;
8309 /* This symbol needs a copy reloc. Set it up. */
8310 BFD_ASSERT (h
->dynindx
!= -1
8311 && (h
->root
.type
== bfd_link_hash_defined
8312 || h
->root
.type
== bfd_link_hash_defweak
));
8314 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
8315 RELOC_SECTION (htab
, ".bss"));
8316 BFD_ASSERT (s
!= NULL
);
8319 rel
.r_offset
= (h
->root
.u
.def
.value
8320 + h
->root
.u
.def
.section
->output_section
->vma
8321 + h
->root
.u
.def
.section
->output_offset
);
8322 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
8323 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
8324 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
8327 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
8328 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
8329 to the ".got" section. */
8330 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
8331 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
8332 sym
->st_shndx
= SHN_ABS
;
8337 /* Finish up the dynamic sections. */
8340 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
8346 dynobj
= elf_hash_table (info
)->dynobj
;
8348 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
8349 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
8350 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8352 if (elf_hash_table (info
)->dynamic_sections_created
)
8355 Elf32_External_Dyn
*dyncon
, *dynconend
;
8356 struct elf32_arm_link_hash_table
*htab
;
8358 htab
= elf32_arm_hash_table (info
);
8359 splt
= bfd_get_section_by_name (dynobj
, ".plt");
8360 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
8362 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
8363 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
8365 for (; dyncon
< dynconend
; dyncon
++)
8367 Elf_Internal_Dyn dyn
;
8371 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8382 goto get_vma_if_bpabi
;
8385 goto get_vma_if_bpabi
;
8388 goto get_vma_if_bpabi
;
8390 name
= ".gnu.version";
8391 goto get_vma_if_bpabi
;
8393 name
= ".gnu.version_d";
8394 goto get_vma_if_bpabi
;
8396 name
= ".gnu.version_r";
8397 goto get_vma_if_bpabi
;
8403 name
= RELOC_SECTION (htab
, ".plt");
8405 s
= bfd_get_section_by_name (output_bfd
, name
);
8406 BFD_ASSERT (s
!= NULL
);
8407 if (!htab
->symbian_p
)
8408 dyn
.d_un
.d_ptr
= s
->vma
;
8410 /* In the BPABI, tags in the PT_DYNAMIC section point
8411 at the file offset, not the memory address, for the
8412 convenience of the post linker. */
8413 dyn
.d_un
.d_ptr
= s
->filepos
;
8414 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8418 if (htab
->symbian_p
)
8423 s
= bfd_get_section_by_name (output_bfd
,
8424 RELOC_SECTION (htab
, ".plt"));
8425 BFD_ASSERT (s
!= NULL
);
8426 dyn
.d_un
.d_val
= s
->size
;
8427 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8432 if (!htab
->symbian_p
)
8434 /* My reading of the SVR4 ABI indicates that the
8435 procedure linkage table relocs (DT_JMPREL) should be
8436 included in the overall relocs (DT_REL). This is
8437 what Solaris does. However, UnixWare can not handle
8438 that case. Therefore, we override the DT_RELSZ entry
8439 here to make it not include the JMPREL relocs. Since
8440 the linker script arranges for .rel(a).plt to follow all
8441 other relocation sections, we don't have to worry
8442 about changing the DT_REL entry. */
8443 s
= bfd_get_section_by_name (output_bfd
,
8444 RELOC_SECTION (htab
, ".plt"));
8446 dyn
.d_un
.d_val
-= s
->size
;
8447 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8454 /* In the BPABI, the DT_REL tag must point at the file
8455 offset, not the VMA, of the first relocation
8456 section. So, we use code similar to that in
8457 elflink.c, but do not check for SHF_ALLOC on the
8458 relcoation section, since relocations sections are
8459 never allocated under the BPABI. The comments above
8460 about Unixware notwithstanding, we include all of the
8461 relocations here. */
8462 if (htab
->symbian_p
)
8465 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
8466 ? SHT_REL
: SHT_RELA
);
8468 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
8470 Elf_Internal_Shdr
*hdr
8471 = elf_elfsections (output_bfd
)[i
];
8472 if (hdr
->sh_type
== type
)
8474 if (dyn
.d_tag
== DT_RELSZ
8475 || dyn
.d_tag
== DT_RELASZ
)
8476 dyn
.d_un
.d_val
+= hdr
->sh_size
;
8477 else if ((ufile_ptr
) hdr
->sh_offset
8478 <= dyn
.d_un
.d_val
- 1)
8479 dyn
.d_un
.d_val
= hdr
->sh_offset
;
8482 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8486 /* Set the bottom bit of DT_INIT/FINI if the
8487 corresponding function is Thumb. */
8489 name
= info
->init_function
;
8492 name
= info
->fini_function
;
8494 /* If it wasn't set by elf_bfd_final_link
8495 then there is nothing to adjust. */
8496 if (dyn
.d_un
.d_val
!= 0)
8498 struct elf_link_hash_entry
* eh
;
8500 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
8501 FALSE
, FALSE
, TRUE
);
8502 if (eh
!= (struct elf_link_hash_entry
*) NULL
8503 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
8505 dyn
.d_un
.d_val
|= 1;
8506 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8513 /* Fill in the first entry in the procedure linkage table. */
8514 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
8516 const bfd_vma
*plt0_entry
;
8517 bfd_vma got_address
, plt_address
, got_displacement
;
8519 /* Calculate the addresses of the GOT and PLT. */
8520 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
8521 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
8523 if (htab
->vxworks_p
)
8525 /* The VxWorks GOT is relocated by the dynamic linker.
8526 Therefore, we must emit relocations rather than simply
8527 computing the values now. */
8528 Elf_Internal_Rela rel
;
8530 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
8531 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
8532 splt
->contents
+ 0);
8533 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
8534 splt
->contents
+ 4);
8535 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
8536 splt
->contents
+ 8);
8537 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
8539 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
8540 rel
.r_offset
= plt_address
+ 12;
8541 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
8543 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
8544 htab
->srelplt2
->contents
);
8548 got_displacement
= got_address
- (plt_address
+ 16);
8550 plt0_entry
= elf32_arm_plt0_entry
;
8551 put_arm_insn (htab
, output_bfd
, plt0_entry
[0],
8552 splt
->contents
+ 0);
8553 put_arm_insn (htab
, output_bfd
, plt0_entry
[1],
8554 splt
->contents
+ 4);
8555 put_arm_insn (htab
, output_bfd
, plt0_entry
[2],
8556 splt
->contents
+ 8);
8557 put_arm_insn (htab
, output_bfd
, plt0_entry
[3],
8558 splt
->contents
+ 12);
8560 #ifdef FOUR_WORD_PLT
8561 /* The displacement value goes in the otherwise-unused
8562 last word of the second entry. */
8563 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
8565 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
8570 /* UnixWare sets the entsize of .plt to 4, although that doesn't
8571 really seem like the right value. */
8572 if (splt
->output_section
->owner
== output_bfd
)
8573 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
8575 if (htab
->vxworks_p
&& !info
->shared
&& htab
->splt
->size
> 0)
8577 /* Correct the .rel(a).plt.unloaded relocations. They will have
8578 incorrect symbol indexes. */
8582 num_plts
= ((htab
->splt
->size
- htab
->plt_header_size
)
8583 / htab
->plt_entry_size
);
8584 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
8586 for (; num_plts
; num_plts
--)
8588 Elf_Internal_Rela rel
;
8590 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
8591 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
8592 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
8593 p
+= RELOC_SIZE (htab
);
8595 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
8596 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
8597 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
8598 p
+= RELOC_SIZE (htab
);
8603 /* Fill in the first three entries in the global offset table. */
8609 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
8611 bfd_put_32 (output_bfd
,
8612 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
8614 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
8615 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
8618 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
8625 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
8627 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
8628 struct elf32_arm_link_hash_table
*globals
;
8630 i_ehdrp
= elf_elfheader (abfd
);
8632 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
8633 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
8635 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
8636 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
8640 globals
= elf32_arm_hash_table (link_info
);
8641 if (globals
->byteswap_code
)
8642 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
8646 static enum elf_reloc_type_class
8647 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
8649 switch ((int) ELF32_R_TYPE (rela
->r_info
))
8651 case R_ARM_RELATIVE
:
8652 return reloc_class_relative
;
8653 case R_ARM_JUMP_SLOT
:
8654 return reloc_class_plt
;
8656 return reloc_class_copy
;
8658 return reloc_class_normal
;
8662 /* Set the right machine number for an Arm ELF file. */
8665 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
8667 if (hdr
->sh_type
== SHT_NOTE
)
8668 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
8674 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
8676 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
8679 /* Return TRUE if this is an unwinding table entry. */
8682 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
8684 return (CONST_STRNEQ (name
, ELF_STRING_ARM_unwind
)
8685 || CONST_STRNEQ (name
, ELF_STRING_ARM_unwind_once
));
8689 /* Set the type and flags for an ARM section. We do this by
8690 the section name, which is a hack, but ought to work. */
8693 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
8697 name
= bfd_get_section_name (abfd
, sec
);
8699 if (is_arm_elf_unwind_section_name (abfd
, name
))
8701 hdr
->sh_type
= SHT_ARM_EXIDX
;
8702 hdr
->sh_flags
|= SHF_LINK_ORDER
;
8704 else if (strcmp(name
, ".ARM.attributes") == 0)
8706 hdr
->sh_type
= SHT_ARM_ATTRIBUTES
;
8711 /* Parse an Arm EABI attributes section. */
8713 elf32_arm_parse_attributes (bfd
*abfd
, Elf_Internal_Shdr
* hdr
)
8719 contents
= bfd_malloc (hdr
->sh_size
);
8722 if (!bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
, 0,
8731 len
= hdr
->sh_size
- 1;
8735 bfd_vma section_len
;
8737 section_len
= bfd_get_32 (abfd
, p
);
8739 if (section_len
> len
)
8742 namelen
= strlen ((char *)p
) + 1;
8743 section_len
-= namelen
+ 4;
8744 if (strcmp((char *)p
, "aeabi") != 0)
8746 /* Vendor section. Ignore it. */
8747 p
+= namelen
+ section_len
;
8752 while (section_len
> 0)
8757 bfd_vma subsection_len
;
8760 tag
= read_unsigned_leb128 (abfd
, p
, &n
);
8762 subsection_len
= bfd_get_32 (abfd
, p
);
8764 if (subsection_len
> section_len
)
8765 subsection_len
= section_len
;
8766 section_len
-= subsection_len
;
8767 subsection_len
-= n
+ 4;
8768 end
= p
+ subsection_len
;
8774 bfd_boolean is_string
;
8776 tag
= read_unsigned_leb128 (abfd
, p
, &n
);
8778 if (tag
== 4 || tag
== 5)
8783 is_string
= (tag
& 1) != 0;
8784 if (tag
== Tag_compatibility
)
8786 val
= read_unsigned_leb128 (abfd
, p
, &n
);
8788 elf32_arm_add_eabi_attr_compat (abfd
, val
,
8790 p
+= strlen ((char *)p
) + 1;
8794 elf32_arm_add_eabi_attr_string (abfd
, tag
,
8796 p
+= strlen ((char *)p
) + 1;
8800 val
= read_unsigned_leb128 (abfd
, p
, &n
);
8802 elf32_arm_add_eabi_attr_int (abfd
, tag
, val
);
8808 /* Don't have anywhere convenient to attach these.
8809 Fall through for now. */
8811 /* Ignore things we don't kow about. */
8812 p
+= subsection_len
;
8823 /* Handle an ARM specific section when reading an object file. This is
8824 called when bfd_section_from_shdr finds a section with an unknown
8828 elf32_arm_section_from_shdr (bfd
*abfd
,
8829 Elf_Internal_Shdr
* hdr
,
8833 /* There ought to be a place to keep ELF backend specific flags, but
8834 at the moment there isn't one. We just keep track of the
8835 sections by their name, instead. Fortunately, the ABI gives
8836 names for all the ARM specific sections, so we will probably get
8838 switch (hdr
->sh_type
)
8841 case SHT_ARM_PREEMPTMAP
:
8842 case SHT_ARM_ATTRIBUTES
:
8849 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
8852 if (hdr
->sh_type
== SHT_ARM_ATTRIBUTES
)
8853 elf32_arm_parse_attributes(abfd
, hdr
);
8857 /* A structure used to record a list of sections, independently
8858 of the next and prev fields in the asection structure. */
8859 typedef struct section_list
8862 struct section_list
* next
;
8863 struct section_list
* prev
;
8867 /* Unfortunately we need to keep a list of sections for which
8868 an _arm_elf_section_data structure has been allocated. This
8869 is because it is possible for functions like elf32_arm_write_section
8870 to be called on a section which has had an elf_data_structure
8871 allocated for it (and so the used_by_bfd field is valid) but
8872 for which the ARM extended version of this structure - the
8873 _arm_elf_section_data structure - has not been allocated. */
8874 static section_list
* sections_with_arm_elf_section_data
= NULL
;
8877 record_section_with_arm_elf_section_data (asection
* sec
)
8879 struct section_list
* entry
;
8881 entry
= bfd_malloc (sizeof (* entry
));
8885 entry
->next
= sections_with_arm_elf_section_data
;
8887 if (entry
->next
!= NULL
)
8888 entry
->next
->prev
= entry
;
8889 sections_with_arm_elf_section_data
= entry
;
8892 static struct section_list
*
8893 find_arm_elf_section_entry (asection
* sec
)
8895 struct section_list
* entry
;
8896 static struct section_list
* last_entry
= NULL
;
8898 /* This is a short cut for the typical case where the sections are added
8899 to the sections_with_arm_elf_section_data list in forward order and
8900 then looked up here in backwards order. This makes a real difference
8901 to the ld-srec/sec64k.exp linker test. */
8902 entry
= sections_with_arm_elf_section_data
;
8903 if (last_entry
!= NULL
)
8905 if (last_entry
->sec
== sec
)
8907 else if (last_entry
->next
!= NULL
8908 && last_entry
->next
->sec
== sec
)
8909 entry
= last_entry
->next
;
8912 for (; entry
; entry
= entry
->next
)
8913 if (entry
->sec
== sec
)
8917 /* Record the entry prior to this one - it is the entry we are most
8918 likely to want to locate next time. Also this way if we have been
8919 called from unrecord_section_with_arm_elf_section_data() we will not
8920 be caching a pointer that is about to be freed. */
8921 last_entry
= entry
->prev
;
8926 static _arm_elf_section_data
*
8927 get_arm_elf_section_data (asection
* sec
)
8929 struct section_list
* entry
;
8931 entry
= find_arm_elf_section_entry (sec
);
8934 return elf32_arm_section_data (entry
->sec
);
8940 unrecord_section_with_arm_elf_section_data (asection
* sec
)
8942 struct section_list
* entry
;
8944 entry
= find_arm_elf_section_entry (sec
);
8948 if (entry
->prev
!= NULL
)
8949 entry
->prev
->next
= entry
->next
;
8950 if (entry
->next
!= NULL
)
8951 entry
->next
->prev
= entry
->prev
;
8952 if (entry
== sections_with_arm_elf_section_data
)
8953 sections_with_arm_elf_section_data
= entry
->next
;
8958 /* Called for each symbol. Builds a section map based on mapping symbols.
8959 Does not alter any of the symbols. */
8962 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
8964 Elf_Internal_Sym
*elfsym
,
8965 asection
*input_sec
,
8966 struct elf_link_hash_entry
*h
)
8969 elf32_arm_section_map
*map
;
8970 elf32_arm_section_map
*newmap
;
8971 _arm_elf_section_data
*arm_data
;
8972 struct elf32_arm_link_hash_table
*globals
;
8974 globals
= elf32_arm_hash_table (info
);
8975 if (globals
->vxworks_p
8976 && !elf_vxworks_link_output_symbol_hook (info
, name
, elfsym
,
8980 /* Only do this on final link. */
8981 if (info
->relocatable
)
8984 /* Only build a map if we need to byteswap code. */
8985 if (!globals
->byteswap_code
)
8988 /* We only want mapping symbols. */
8989 if (!bfd_is_arm_special_symbol_name (name
, BFD_ARM_SPECIAL_SYM_TYPE_MAP
))
8992 /* If this section has not been allocated an _arm_elf_section_data
8993 structure then we cannot record anything. */
8994 arm_data
= get_arm_elf_section_data (input_sec
);
8995 if (arm_data
== NULL
)
8998 mapcount
= arm_data
->mapcount
+ 1;
8999 map
= arm_data
->map
;
9001 /* TODO: This may be inefficient, but we probably don't usually have many
9002 mapping symbols per section. */
9003 newmap
= bfd_realloc (map
, mapcount
* sizeof (* map
));
9006 arm_data
->map
= newmap
;
9007 arm_data
->mapcount
= mapcount
;
9009 newmap
[mapcount
- 1].vma
= elfsym
->st_value
;
9010 newmap
[mapcount
- 1].type
= name
[1];
9019 struct bfd_link_info
*info
;
9022 bfd_boolean (*func
) (void *, const char *, Elf_Internal_Sym
*,
9023 asection
*, struct elf_link_hash_entry
*);
9024 } output_arch_syminfo
;
9026 enum map_symbol_type
9034 /* Output a single PLT mapping symbol. */
9037 elf32_arm_ouput_plt_map_sym (output_arch_syminfo
*osi
,
9038 enum map_symbol_type type
,
9041 static const char *names
[3] = {"$a", "$t", "$d"};
9042 struct elf32_arm_link_hash_table
*htab
;
9043 Elf_Internal_Sym sym
;
9045 htab
= elf32_arm_hash_table (osi
->info
);
9046 sym
.st_value
= osi
->plt_offset
+ offset
;
9049 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_NOTYPE
);
9050 sym
.st_shndx
= osi
->plt_shndx
;
9051 if (!osi
->func (osi
->finfo
, names
[type
], &sym
, htab
->splt
, NULL
))
9057 /* Output mapping symbols for PLT entries associated with H. */
9060 elf32_arm_output_plt_map (struct elf_link_hash_entry
*h
, void *inf
)
9062 output_arch_syminfo
*osi
= (output_arch_syminfo
*) inf
;
9063 struct elf32_arm_link_hash_table
*htab
;
9064 struct elf32_arm_link_hash_entry
*eh
;
9067 htab
= elf32_arm_hash_table (osi
->info
);
9069 if (h
->root
.type
== bfd_link_hash_indirect
)
9072 if (h
->root
.type
== bfd_link_hash_warning
)
9073 /* When warning symbols are created, they **replace** the "real"
9074 entry in the hash table, thus we never get to see the real
9075 symbol in a hash traversal. So look at it now. */
9076 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9078 if (h
->plt
.offset
== (bfd_vma
) -1)
9081 eh
= (struct elf32_arm_link_hash_entry
*) h
;
9082 addr
= h
->plt
.offset
;
9083 if (htab
->symbian_p
)
9085 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_ARM
, addr
))
9087 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_DATA
, addr
+ 4))
9090 else if (htab
->vxworks_p
)
9092 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_ARM
, addr
))
9094 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_DATA
, addr
+ 8))
9096 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_ARM
, addr
+ 12))
9098 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_DATA
, addr
+ 20))
9103 bfd_boolean thumb_stub
;
9105 thumb_stub
= eh
->plt_thumb_refcount
> 0 && !htab
->use_blx
;
9108 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_THUMB
, addr
- 4))
9111 #ifdef FOUR_WORD_PLT
9112 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_ARM
, addr
))
9114 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_DATA
, addr
+ 12))
9117 /* A three-word PLT with no Thumb thunk contains only Arm code,
9118 so only need to output a mapping symbol for the first PLT entry and
9119 entries with thumb thunks. */
9120 if (thumb_stub
|| addr
== 20)
9122 if (!elf32_arm_ouput_plt_map_sym (osi
, ARM_MAP_ARM
, addr
))
9132 /* Output mapping symbols for the PLT. */
9135 elf32_arm_output_arch_local_syms (bfd
*output_bfd
,
9136 struct bfd_link_info
*info
,
9137 void *finfo
, bfd_boolean (*func
) (void *, const char *,
9140 struct elf_link_hash_entry
*))
9142 output_arch_syminfo osi
;
9143 struct elf32_arm_link_hash_table
*htab
;
9145 htab
= elf32_arm_hash_table (info
);
9146 if (!htab
->splt
|| htab
->splt
->size
== 0)
9149 check_use_blx(htab
);
9153 osi
.plt_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
9154 htab
->splt
->output_section
);
9155 osi
.plt_offset
= htab
->splt
->output_section
->vma
;
9157 /* Output mapping symbols for the plt header. SymbianOS does not have a
9159 if (htab
->vxworks_p
)
9161 /* VxWorks shared libraries have no PLT header. */
9164 if (!elf32_arm_ouput_plt_map_sym (&osi
, ARM_MAP_ARM
, 0))
9166 if (!elf32_arm_ouput_plt_map_sym (&osi
, ARM_MAP_DATA
, 12))
9170 else if (!htab
->symbian_p
)
9172 if (!elf32_arm_ouput_plt_map_sym (&osi
, ARM_MAP_ARM
, 0))
9174 #ifndef FOUR_WORD_PLT
9175 if (!elf32_arm_ouput_plt_map_sym (&osi
, ARM_MAP_DATA
, 16))
9180 elf_link_hash_traverse (&htab
->root
, elf32_arm_output_plt_map
, (void *) &osi
);
9184 /* Allocate target specific section data. */
9187 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
9189 if (!sec
->used_by_bfd
)
9191 _arm_elf_section_data
*sdata
;
9192 bfd_size_type amt
= sizeof (*sdata
);
9194 sdata
= bfd_zalloc (abfd
, amt
);
9197 sec
->used_by_bfd
= sdata
;
9200 record_section_with_arm_elf_section_data (sec
);
9202 return _bfd_elf_new_section_hook (abfd
, sec
);
9206 /* Used to order a list of mapping symbols by address. */
9209 elf32_arm_compare_mapping (const void * a
, const void * b
)
9211 return ((const elf32_arm_section_map
*) a
)->vma
9212 > ((const elf32_arm_section_map
*) b
)->vma
;
9216 /* Do code byteswapping. Return FALSE afterwards so that the section is
9217 written out as normal. */
9220 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
9224 _arm_elf_section_data
*arm_data
;
9225 elf32_arm_section_map
*map
;
9232 /* If this section has not been allocated an _arm_elf_section_data
9233 structure then we cannot record anything. */
9234 arm_data
= get_arm_elf_section_data (sec
);
9235 if (arm_data
== NULL
)
9238 mapcount
= arm_data
->mapcount
;
9239 map
= arm_data
->map
;
9244 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
9246 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
9247 ptr
= map
[0].vma
- offset
;
9248 for (i
= 0; i
< mapcount
; i
++)
9250 if (i
== mapcount
- 1)
9253 end
= map
[i
+ 1].vma
- offset
;
9255 switch (map
[i
].type
)
9258 /* Byte swap code words. */
9259 while (ptr
+ 3 < end
)
9261 tmp
= contents
[ptr
];
9262 contents
[ptr
] = contents
[ptr
+ 3];
9263 contents
[ptr
+ 3] = tmp
;
9264 tmp
= contents
[ptr
+ 1];
9265 contents
[ptr
+ 1] = contents
[ptr
+ 2];
9266 contents
[ptr
+ 2] = tmp
;
9272 /* Byte swap code halfwords. */
9273 while (ptr
+ 1 < end
)
9275 tmp
= contents
[ptr
];
9276 contents
[ptr
] = contents
[ptr
+ 1];
9277 contents
[ptr
+ 1] = tmp
;
9283 /* Leave data alone. */
9290 arm_data
->mapcount
= 0;
9291 arm_data
->map
= NULL
;
9292 unrecord_section_with_arm_elf_section_data (sec
);
9298 unrecord_section_via_map_over_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
9300 void * ignore ATTRIBUTE_UNUSED
)
9302 unrecord_section_with_arm_elf_section_data (sec
);
9306 elf32_arm_close_and_cleanup (bfd
* abfd
)
9309 bfd_map_over_sections (abfd
,
9310 unrecord_section_via_map_over_sections
,
9313 return _bfd_elf_close_and_cleanup (abfd
);
9317 elf32_arm_bfd_free_cached_info (bfd
* abfd
)
9320 bfd_map_over_sections (abfd
,
9321 unrecord_section_via_map_over_sections
,
9324 return _bfd_free_cached_info (abfd
);
9327 /* Display STT_ARM_TFUNC symbols as functions. */
9330 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
9333 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
9335 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
9336 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
9340 /* Mangle thumb function symbols as we read them in. */
9343 elf32_arm_swap_symbol_in (bfd
* abfd
,
9346 Elf_Internal_Sym
*dst
)
9348 if (!bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
))
9351 /* New EABI objects mark thumb function symbols by setting the low bit of
9352 the address. Turn these into STT_ARM_TFUNC. */
9353 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
9354 && (dst
->st_value
& 1))
9356 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
9357 dst
->st_value
&= ~(bfd_vma
) 1;
9363 /* Mangle thumb function symbols as we write them out. */
9366 elf32_arm_swap_symbol_out (bfd
*abfd
,
9367 const Elf_Internal_Sym
*src
,
9371 Elf_Internal_Sym newsym
;
9373 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
9374 of the address set, as per the new EABI. We do this unconditionally
9375 because objcopy does not set the elf header flags until after
9376 it writes out the symbol table. */
9377 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
9380 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
9381 if (newsym
.st_shndx
!= SHN_UNDEF
)
9383 /* Do this only for defined symbols. At link type, the static
9384 linker will simulate the work of dynamic linker of resolving
9385 symbols and will carry over the thumbness of found symbols to
9386 the output symbol table. It's not clear how it happens, but
9387 the thumbness of undefined symbols can well be different at
9388 runtime, and writing '1' for them will be confusing for users
9389 and possibly for dynamic linker itself.
9391 newsym
.st_value
|= 1;
9396 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
9399 /* Add the PT_ARM_EXIDX program header. */
9402 elf32_arm_modify_segment_map (bfd
*abfd
,
9403 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9405 struct elf_segment_map
*m
;
9408 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
9409 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
9411 /* If there is already a PT_ARM_EXIDX header, then we do not
9412 want to add another one. This situation arises when running
9413 "strip"; the input binary already has the header. */
9414 m
= elf_tdata (abfd
)->segment_map
;
9415 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
9419 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
9422 m
->p_type
= PT_ARM_EXIDX
;
9424 m
->sections
[0] = sec
;
9426 m
->next
= elf_tdata (abfd
)->segment_map
;
9427 elf_tdata (abfd
)->segment_map
= m
;
9434 /* We may add a PT_ARM_EXIDX program header. */
9437 elf32_arm_additional_program_headers (bfd
*abfd
,
9438 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
9442 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
9443 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
9449 /* We use this to override swap_symbol_in and swap_symbol_out. */
9450 const struct elf_size_info elf32_arm_size_info
= {
9451 sizeof (Elf32_External_Ehdr
),
9452 sizeof (Elf32_External_Phdr
),
9453 sizeof (Elf32_External_Shdr
),
9454 sizeof (Elf32_External_Rel
),
9455 sizeof (Elf32_External_Rela
),
9456 sizeof (Elf32_External_Sym
),
9457 sizeof (Elf32_External_Dyn
),
9458 sizeof (Elf_External_Note
),
9462 ELFCLASS32
, EV_CURRENT
,
9463 bfd_elf32_write_out_phdrs
,
9464 bfd_elf32_write_shdrs_and_ehdr
,
9465 bfd_elf32_write_relocs
,
9466 elf32_arm_swap_symbol_in
,
9467 elf32_arm_swap_symbol_out
,
9468 bfd_elf32_slurp_reloc_table
,
9469 bfd_elf32_slurp_symbol_table
,
9470 bfd_elf32_swap_dyn_in
,
9471 bfd_elf32_swap_dyn_out
,
9472 bfd_elf32_swap_reloc_in
,
9473 bfd_elf32_swap_reloc_out
,
9474 bfd_elf32_swap_reloca_in
,
9475 bfd_elf32_swap_reloca_out
9478 #define ELF_ARCH bfd_arch_arm
9479 #define ELF_MACHINE_CODE EM_ARM
9480 #ifdef __QNXTARGET__
9481 #define ELF_MAXPAGESIZE 0x1000
9483 #define ELF_MAXPAGESIZE 0x8000
9485 #define ELF_MINPAGESIZE 0x1000
9486 #define ELF_COMMONPAGESIZE 0x1000
9488 #define bfd_elf32_mkobject elf32_arm_mkobject
9490 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
9491 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
9492 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
9493 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
9494 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
9495 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
9496 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
9497 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
9498 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
9499 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
9500 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
9501 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
9502 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
9504 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
9505 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
9506 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
9507 #define elf_backend_check_relocs elf32_arm_check_relocs
9508 #define elf_backend_relocate_section elf32_arm_relocate_section
9509 #define elf_backend_write_section elf32_arm_write_section
9510 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
9511 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
9512 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
9513 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
9514 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
9515 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
9516 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
9517 #define elf_backend_post_process_headers elf32_arm_post_process_headers
9518 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
9519 #define elf_backend_object_p elf32_arm_object_p
9520 #define elf_backend_section_flags elf32_arm_section_flags
9521 #define elf_backend_fake_sections elf32_arm_fake_sections
9522 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
9523 #define elf_backend_final_write_processing elf32_arm_final_write_processing
9524 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
9525 #define elf_backend_symbol_processing elf32_arm_symbol_processing
9526 #define elf_backend_size_info elf32_arm_size_info
9527 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
9528 #define elf_backend_additional_program_headers \
9529 elf32_arm_additional_program_headers
9530 #define elf_backend_output_arch_local_syms \
9531 elf32_arm_output_arch_local_syms
9532 #define elf_backend_begin_write_processing \
9533 elf32_arm_begin_write_processing
9535 #define elf_backend_can_refcount 1
9536 #define elf_backend_can_gc_sections 1
9537 #define elf_backend_plt_readonly 1
9538 #define elf_backend_want_got_plt 1
9539 #define elf_backend_want_plt_sym 0
9540 #define elf_backend_may_use_rel_p 1
9541 #define elf_backend_may_use_rela_p 0
9542 #define elf_backend_default_use_rela_p 0
9543 #define elf_backend_rela_normal 0
9545 #define elf_backend_got_header_size 12
9547 #include "elf32-target.h"
9549 /* VxWorks Targets */
9551 #undef TARGET_LITTLE_SYM
9552 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
9553 #undef TARGET_LITTLE_NAME
9554 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
9555 #undef TARGET_BIG_SYM
9556 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
9557 #undef TARGET_BIG_NAME
9558 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
9560 /* Like elf32_arm_link_hash_table_create -- but overrides
9561 appropriately for VxWorks. */
9562 static struct bfd_link_hash_table
*
9563 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
9565 struct bfd_link_hash_table
*ret
;
9567 ret
= elf32_arm_link_hash_table_create (abfd
);
9570 struct elf32_arm_link_hash_table
*htab
9571 = (struct elf32_arm_link_hash_table
*) ret
;
9573 htab
->vxworks_p
= 1;
9579 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
9581 elf32_arm_final_write_processing (abfd
, linker
);
9582 elf_vxworks_final_write_processing (abfd
, linker
);
9586 #define elf32_bed elf32_arm_vxworks_bed
9588 #undef bfd_elf32_bfd_link_hash_table_create
9589 #define bfd_elf32_bfd_link_hash_table_create \
9590 elf32_arm_vxworks_link_hash_table_create
9591 #undef elf_backend_add_symbol_hook
9592 #define elf_backend_add_symbol_hook \
9593 elf_vxworks_add_symbol_hook
9594 #undef elf_backend_final_write_processing
9595 #define elf_backend_final_write_processing \
9596 elf32_arm_vxworks_final_write_processing
9597 #undef elf_backend_emit_relocs
9598 #define elf_backend_emit_relocs \
9599 elf_vxworks_emit_relocs
9601 #undef elf_backend_may_use_rel_p
9602 #define elf_backend_may_use_rel_p 0
9603 #undef elf_backend_may_use_rela_p
9604 #define elf_backend_may_use_rela_p 1
9605 #undef elf_backend_default_use_rela_p
9606 #define elf_backend_default_use_rela_p 1
9607 #undef elf_backend_rela_normal
9608 #define elf_backend_rela_normal 1
9609 #undef elf_backend_want_plt_sym
9610 #define elf_backend_want_plt_sym 1
9611 #undef ELF_MAXPAGESIZE
9612 #define ELF_MAXPAGESIZE 0x1000
9614 #include "elf32-target.h"
9617 /* Symbian OS Targets */
9619 #undef TARGET_LITTLE_SYM
9620 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
9621 #undef TARGET_LITTLE_NAME
9622 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
9623 #undef TARGET_BIG_SYM
9624 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
9625 #undef TARGET_BIG_NAME
9626 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
9628 /* Like elf32_arm_link_hash_table_create -- but overrides
9629 appropriately for Symbian OS. */
9630 static struct bfd_link_hash_table
*
9631 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
9633 struct bfd_link_hash_table
*ret
;
9635 ret
= elf32_arm_link_hash_table_create (abfd
);
9638 struct elf32_arm_link_hash_table
*htab
9639 = (struct elf32_arm_link_hash_table
*)ret
;
9640 /* There is no PLT header for Symbian OS. */
9641 htab
->plt_header_size
= 0;
9642 /* The PLT entries are each three instructions. */
9643 htab
->plt_entry_size
= 4 * NUM_ELEM (elf32_arm_symbian_plt_entry
);
9644 htab
->symbian_p
= 1;
9645 /* Symbian uses armv5t or above, so use_blx is always true. */
9647 htab
->root
.is_relocatable_executable
= 1;
9652 static const struct bfd_elf_special_section
9653 elf32_arm_symbian_special_sections
[] =
9655 /* In a BPABI executable, the dynamic linking sections do not go in
9656 the loadable read-only segment. The post-linker may wish to
9657 refer to these sections, but they are not part of the final
9659 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC
, 0 },
9660 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB
, 0 },
9661 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM
, 0 },
9662 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS
, 0 },
9663 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH
, 0 },
9664 /* These sections do not need to be writable as the SymbianOS
9665 postlinker will arrange things so that no dynamic relocation is
9667 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
9668 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
9669 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
9670 { NULL
, 0, 0, 0, 0 }
9674 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
9675 struct bfd_link_info
*link_info
)
9677 /* BPABI objects are never loaded directly by an OS kernel; they are
9678 processed by a postlinker first, into an OS-specific format. If
9679 the D_PAGED bit is set on the file, BFD will align segments on
9680 page boundaries, so that an OS can directly map the file. With
9681 BPABI objects, that just results in wasted space. In addition,
9682 because we clear the D_PAGED bit, map_sections_to_segments will
9683 recognize that the program headers should not be mapped into any
9684 loadable segment. */
9685 abfd
->flags
&= ~D_PAGED
;
9686 elf32_arm_begin_write_processing(abfd
, link_info
);
9690 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
9691 struct bfd_link_info
*info
)
9693 struct elf_segment_map
*m
;
9696 /* BPABI shared libraries and executables should have a PT_DYNAMIC
9697 segment. However, because the .dynamic section is not marked
9698 with SEC_LOAD, the generic ELF code will not create such a
9700 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
9703 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
9704 if (m
->p_type
== PT_DYNAMIC
)
9709 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
9710 m
->next
= elf_tdata (abfd
)->segment_map
;
9711 elf_tdata (abfd
)->segment_map
= m
;
9715 /* Also call the generic arm routine. */
9716 return elf32_arm_modify_segment_map (abfd
, info
);
9720 #define elf32_bed elf32_arm_symbian_bed
9722 /* The dynamic sections are not allocated on SymbianOS; the postlinker
9723 will process them and then discard them. */
9724 #undef ELF_DYNAMIC_SEC_FLAGS
9725 #define ELF_DYNAMIC_SEC_FLAGS \
9726 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
9728 #undef bfd_elf32_bfd_link_hash_table_create
9729 #define bfd_elf32_bfd_link_hash_table_create \
9730 elf32_arm_symbian_link_hash_table_create
9731 #undef elf_backend_add_symbol_hook
9733 #undef elf_backend_special_sections
9734 #define elf_backend_special_sections elf32_arm_symbian_special_sections
9736 #undef elf_backend_begin_write_processing
9737 #define elf_backend_begin_write_processing \
9738 elf32_arm_symbian_begin_write_processing
9739 #undef elf_backend_final_write_processing
9740 #define elf_backend_final_write_processing \
9741 elf32_arm_final_write_processing
9742 #undef elf_backend_emit_relocs
9744 #undef elf_backend_modify_segment_map
9745 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
9747 /* There is no .got section for BPABI objects, and hence no header. */
9748 #undef elf_backend_got_header_size
9749 #define elf_backend_got_header_size 0
9751 /* Similarly, there is no .got.plt section. */
9752 #undef elf_backend_want_got_plt
9753 #define elf_backend_want_got_plt 0
9755 #undef elf_backend_may_use_rel_p
9756 #define elf_backend_may_use_rel_p 1
9757 #undef elf_backend_may_use_rela_p
9758 #define elf_backend_may_use_rela_p 0
9759 #undef elf_backend_default_use_rela_p
9760 #define elf_backend_default_use_rela_p 0
9761 #undef elf_backend_rela_normal
9762 #define elf_backend_rela_normal 0
9763 #undef elf_backend_want_plt_sym
9764 #define elf_backend_want_plt_sym 0
9765 #undef ELF_MAXPAGESIZE
9766 #define ELF_MAXPAGESIZE 0x8000
9768 #include "elf32-target.h"