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 const 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_PC13
, /* type */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
137 FALSE
, /* pc_relative */
139 complain_overflow_bitfield
,/* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_ARM_PC13", /* name */
142 FALSE
, /* partial_inplace */
143 0x000000ff, /* src_mask */
144 0x000000ff, /* dst_mask */
145 FALSE
), /* 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_signed
,/* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_ARM_THM_ALU_PREL_11_0",/* name */
841 FALSE
, /* partial_inplace */
842 0x040070ff, /* src_mask */
843 0x040070ff, /* 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_signed
,/* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 "R_ARM_THM_PC12", /* name */
855 FALSE
, /* partial_inplace */
856 0x040070ff, /* src_mask */
857 0x040070ff, /* 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 */
889 /* Relocations 57 .. 83 are the "group relocations" which we do not
892 static reloc_howto_type elf32_arm_howto_table_2
[] =
894 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_dont
,/* complain_on_overflow */
901 bfd_elf_generic_reloc
, /* special_function */
902 "R_ARM_MOVW_BREL_NC", /* name */
903 FALSE
, /* partial_inplace */
904 0x0000ffff, /* src_mask */
905 0x0000ffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 HOWTO (R_ARM_MOVT_BREL
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_bitfield
,/* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_ARM_MOVT_BREL", /* name */
917 FALSE
, /* partial_inplace */
918 0x0000ffff, /* src_mask */
919 0x0000ffff, /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 HOWTO (R_ARM_MOVW_BREL
, /* type */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_dont
,/* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* special_function */
930 "R_ARM_MOVW_BREL", /* name */
931 FALSE
, /* partial_inplace */
932 0x0000ffff, /* src_mask */
933 0x0000ffff, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_dont
,/* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 "R_ARM_THM_MOVW_BREL_NC",/* name */
945 FALSE
, /* partial_inplace */
946 0x040f70ff, /* src_mask */
947 0x040f70ff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 FALSE
, /* pc_relative */
956 complain_overflow_bitfield
,/* complain_on_overflow */
957 bfd_elf_generic_reloc
, /* special_function */
958 "R_ARM_THM_MOVT_BREL", /* name */
959 FALSE
, /* partial_inplace */
960 0x040f70ff, /* src_mask */
961 0x040f70ff, /* dst_mask */
962 FALSE
), /* pcrel_offset */
964 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_dont
,/* complain_on_overflow */
971 bfd_elf_generic_reloc
, /* special_function */
972 "R_ARM_THM_MOVW_BREL", /* name */
973 FALSE
, /* partial_inplace */
974 0x040f70ff, /* src_mask */
975 0x040f70ff, /* dst_mask */
976 FALSE
), /* pcrel_offset */
978 EMPTY_HOWTO (90), /* unallocated */
983 HOWTO (R_ARM_PLT32_ABS
, /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_dont
,/* complain_on_overflow */
990 bfd_elf_generic_reloc
, /* special_function */
991 "R_ARM_PLT32_ABS", /* name */
992 FALSE
, /* partial_inplace */
993 0xffffffff, /* src_mask */
994 0xffffffff, /* dst_mask */
995 FALSE
), /* pcrel_offset */
997 HOWTO (R_ARM_GOT_ABS
, /* type */
999 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 FALSE
, /* pc_relative */
1003 complain_overflow_dont
,/* complain_on_overflow */
1004 bfd_elf_generic_reloc
, /* special_function */
1005 "R_ARM_GOT_ABS", /* name */
1006 FALSE
, /* partial_inplace */
1007 0xffffffff, /* src_mask */
1008 0xffffffff, /* dst_mask */
1009 FALSE
), /* pcrel_offset */
1011 HOWTO (R_ARM_GOT_PREL
, /* type */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 TRUE
, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 bfd_elf_generic_reloc
, /* special_function */
1019 "R_ARM_GOT_PREL", /* name */
1020 FALSE
, /* partial_inplace */
1021 0xffffffff, /* src_mask */
1022 0xffffffff, /* dst_mask */
1023 TRUE
), /* pcrel_offset */
1025 HOWTO (R_ARM_GOT_BREL12
, /* type */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_bitfield
,/* complain_on_overflow */
1032 bfd_elf_generic_reloc
, /* special_function */
1033 "R_ARM_GOT_BREL12", /* name */
1034 FALSE
, /* partial_inplace */
1035 0x00000fff, /* src_mask */
1036 0x00000fff, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 HOWTO (R_ARM_GOTOFF12
, /* type */
1041 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE
, /* pc_relative */
1045 complain_overflow_bitfield
,/* complain_on_overflow */
1046 bfd_elf_generic_reloc
, /* special_function */
1047 "R_ARM_GOTOFF12", /* name */
1048 FALSE
, /* partial_inplace */
1049 0x00000fff, /* src_mask */
1050 0x00000fff, /* dst_mask */
1051 FALSE
), /* pcrel_offset */
1053 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1055 /* GNU extension to record C++ vtable member usage */
1056 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE
, /* pc_relative */
1062 complain_overflow_dont
, /* complain_on_overflow */
1063 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1064 "R_ARM_GNU_VTENTRY", /* name */
1065 FALSE
, /* partial_inplace */
1068 FALSE
), /* pcrel_offset */
1070 /* GNU extension to record C++ vtable hierarchy */
1071 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE
, /* pc_relative */
1077 complain_overflow_dont
, /* complain_on_overflow */
1078 NULL
, /* special_function */
1079 "R_ARM_GNU_VTINHERIT", /* name */
1080 FALSE
, /* partial_inplace */
1083 FALSE
), /* pcrel_offset */
1085 HOWTO (R_ARM_THM_JUMP11
, /* type */
1087 1, /* size (0 = byte, 1 = short, 2 = long) */
1089 TRUE
, /* pc_relative */
1091 complain_overflow_signed
, /* complain_on_overflow */
1092 bfd_elf_generic_reloc
, /* special_function */
1093 "R_ARM_THM_JUMP11", /* name */
1094 FALSE
, /* partial_inplace */
1095 0x000007ff, /* src_mask */
1096 0x000007ff, /* dst_mask */
1097 TRUE
), /* pcrel_offset */
1099 HOWTO (R_ARM_THM_JUMP8
, /* type */
1101 1, /* size (0 = byte, 1 = short, 2 = long) */
1103 TRUE
, /* pc_relative */
1105 complain_overflow_signed
, /* complain_on_overflow */
1106 bfd_elf_generic_reloc
, /* special_function */
1107 "R_ARM_THM_JUMP8", /* name */
1108 FALSE
, /* partial_inplace */
1109 0x000000ff, /* src_mask */
1110 0x000000ff, /* dst_mask */
1111 TRUE
), /* pcrel_offset */
1113 /* TLS relocations */
1114 HOWTO (R_ARM_TLS_GD32
, /* type */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 FALSE
, /* pc_relative */
1120 complain_overflow_bitfield
,/* complain_on_overflow */
1121 NULL
, /* special_function */
1122 "R_ARM_TLS_GD32", /* name */
1123 TRUE
, /* partial_inplace */
1124 0xffffffff, /* src_mask */
1125 0xffffffff, /* dst_mask */
1126 FALSE
), /* pcrel_offset */
1128 HOWTO (R_ARM_TLS_LDM32
, /* type */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 FALSE
, /* pc_relative */
1134 complain_overflow_bitfield
,/* complain_on_overflow */
1135 bfd_elf_generic_reloc
, /* special_function */
1136 "R_ARM_TLS_LDM32", /* name */
1137 TRUE
, /* partial_inplace */
1138 0xffffffff, /* src_mask */
1139 0xffffffff, /* dst_mask */
1140 FALSE
), /* pcrel_offset */
1142 HOWTO (R_ARM_TLS_LDO32
, /* type */
1144 2, /* size (0 = byte, 1 = short, 2 = long) */
1146 FALSE
, /* pc_relative */
1148 complain_overflow_bitfield
,/* complain_on_overflow */
1149 bfd_elf_generic_reloc
, /* special_function */
1150 "R_ARM_TLS_LDO32", /* name */
1151 TRUE
, /* partial_inplace */
1152 0xffffffff, /* src_mask */
1153 0xffffffff, /* dst_mask */
1154 FALSE
), /* pcrel_offset */
1156 HOWTO (R_ARM_TLS_IE32
, /* type */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1160 FALSE
, /* pc_relative */
1162 complain_overflow_bitfield
,/* complain_on_overflow */
1163 NULL
, /* special_function */
1164 "R_ARM_TLS_IE32", /* name */
1165 TRUE
, /* partial_inplace */
1166 0xffffffff, /* src_mask */
1167 0xffffffff, /* dst_mask */
1168 FALSE
), /* pcrel_offset */
1170 HOWTO (R_ARM_TLS_LE32
, /* type */
1172 2, /* size (0 = byte, 1 = short, 2 = long) */
1174 FALSE
, /* pc_relative */
1176 complain_overflow_bitfield
,/* complain_on_overflow */
1177 bfd_elf_generic_reloc
, /* special_function */
1178 "R_ARM_TLS_LE32", /* name */
1179 TRUE
, /* partial_inplace */
1180 0xffffffff, /* src_mask */
1181 0xffffffff, /* dst_mask */
1182 FALSE
), /* pcrel_offset */
1184 HOWTO (R_ARM_TLS_LDO12
, /* type */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1188 FALSE
, /* pc_relative */
1190 complain_overflow_bitfield
,/* complain_on_overflow */
1191 bfd_elf_generic_reloc
, /* special_function */
1192 "R_ARM_TLS_LDO12", /* name */
1193 FALSE
, /* partial_inplace */
1194 0x00000fff, /* src_mask */
1195 0x00000fff, /* dst_mask */
1196 FALSE
), /* pcrel_offset */
1198 HOWTO (R_ARM_TLS_LE12
, /* type */
1200 2, /* size (0 = byte, 1 = short, 2 = long) */
1202 FALSE
, /* pc_relative */
1204 complain_overflow_bitfield
,/* complain_on_overflow */
1205 bfd_elf_generic_reloc
, /* special_function */
1206 "R_ARM_TLS_LE12", /* name */
1207 FALSE
, /* partial_inplace */
1208 0x00000fff, /* src_mask */
1209 0x00000fff, /* dst_mask */
1210 FALSE
), /* pcrel_offset */
1212 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_bitfield
,/* complain_on_overflow */
1219 bfd_elf_generic_reloc
, /* special_function */
1220 "R_ARM_TLS_IE12GP", /* name */
1221 FALSE
, /* partial_inplace */
1222 0x00000fff, /* src_mask */
1223 0x00000fff, /* dst_mask */
1224 FALSE
), /* pcrel_offset */
1227 /* 112-127 private relocations
1228 128 R_ARM_ME_TOO, obsolete
1229 129-255 unallocated in AAELF.
1231 249-255 extended, currently unused, relocations: */
1233 static reloc_howto_type elf32_arm_howto_table_3
[4] =
1235 HOWTO (R_ARM_RREL32
, /* type */
1237 0, /* size (0 = byte, 1 = short, 2 = long) */
1239 FALSE
, /* pc_relative */
1241 complain_overflow_dont
,/* complain_on_overflow */
1242 bfd_elf_generic_reloc
, /* special_function */
1243 "R_ARM_RREL32", /* name */
1244 FALSE
, /* partial_inplace */
1247 FALSE
), /* pcrel_offset */
1249 HOWTO (R_ARM_RABS32
, /* type */
1251 0, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_dont
,/* complain_on_overflow */
1256 bfd_elf_generic_reloc
, /* special_function */
1257 "R_ARM_RABS32", /* name */
1258 FALSE
, /* partial_inplace */
1261 FALSE
), /* pcrel_offset */
1263 HOWTO (R_ARM_RPC24
, /* type */
1265 0, /* size (0 = byte, 1 = short, 2 = long) */
1267 FALSE
, /* pc_relative */
1269 complain_overflow_dont
,/* complain_on_overflow */
1270 bfd_elf_generic_reloc
, /* special_function */
1271 "R_ARM_RPC24", /* name */
1272 FALSE
, /* partial_inplace */
1275 FALSE
), /* pcrel_offset */
1277 HOWTO (R_ARM_RBASE
, /* type */
1279 0, /* size (0 = byte, 1 = short, 2 = long) */
1281 FALSE
, /* pc_relative */
1283 complain_overflow_dont
,/* complain_on_overflow */
1284 bfd_elf_generic_reloc
, /* special_function */
1285 "R_ARM_RBASE", /* name */
1286 FALSE
, /* partial_inplace */
1289 FALSE
) /* pcrel_offset */
1292 static reloc_howto_type
*
1293 elf32_arm_howto_from_type (unsigned int r_type
)
1295 if (r_type
< NUM_ELEM (elf32_arm_howto_table_1
))
1296 return &elf32_arm_howto_table_1
[r_type
];
1298 if (r_type
>= R_ARM_MOVW_BREL_NC
1299 && r_type
< R_ARM_MOVW_BREL_NC
+ NUM_ELEM (elf32_arm_howto_table_2
))
1300 return &elf32_arm_howto_table_2
[r_type
- R_ARM_MOVW_BREL_NC
];
1302 if (r_type
>= R_ARM_RREL32
1303 && r_type
< R_ARM_RREL32
+ NUM_ELEM (elf32_arm_howto_table_2
))
1304 return &elf32_arm_howto_table_3
[r_type
- R_ARM_RREL32
];
1310 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1311 Elf_Internal_Rela
* elf_reloc
)
1313 unsigned int r_type
;
1315 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1316 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1319 struct elf32_arm_reloc_map
1321 bfd_reloc_code_real_type bfd_reloc_val
;
1322 unsigned char elf_reloc_val
;
1325 /* All entries in this list must also be present in elf32_arm_howto_table. */
1326 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1328 {BFD_RELOC_NONE
, R_ARM_NONE
},
1329 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1330 {BFD_RELOC_ARM_PCREL_CALL
, R_ARM_CALL
},
1331 {BFD_RELOC_ARM_PCREL_JUMP
, R_ARM_JUMP24
},
1332 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1333 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1334 {BFD_RELOC_32
, R_ARM_ABS32
},
1335 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1336 {BFD_RELOC_8
, R_ARM_ABS8
},
1337 {BFD_RELOC_16
, R_ARM_ABS16
},
1338 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1339 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1340 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1341 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1342 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1343 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1344 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1345 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1346 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1347 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1348 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1349 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1350 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1351 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1352 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1353 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1354 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1355 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1356 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1357 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1358 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1359 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1360 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1361 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1362 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1363 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1364 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1365 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1366 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1367 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1368 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1371 static reloc_howto_type
*
1372 elf32_arm_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1373 bfd_reloc_code_real_type code
)
1376 for (i
= 0; i
< NUM_ELEM (elf32_arm_reloc_map
); i
++)
1377 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1378 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1383 /* Support for core dump NOTE sections */
1385 elf32_arm_nabi_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1390 switch (note
->descsz
)
1395 case 148: /* Linux/ARM 32-bit*/
1397 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1400 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1409 /* Make a ".reg/999" section. */
1410 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1411 size
, note
->descpos
+ offset
);
1415 elf32_arm_nabi_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1417 switch (note
->descsz
)
1422 case 124: /* Linux/ARM elf_prpsinfo */
1423 elf_tdata (abfd
)->core_program
1424 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1425 elf_tdata (abfd
)->core_command
1426 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1429 /* Note that for some reason, a spurious space is tacked
1430 onto the end of the args in some (at least one anyway)
1431 implementations, so strip it off if it exists. */
1434 char *command
= elf_tdata (abfd
)->core_command
;
1435 int n
= strlen (command
);
1437 if (0 < n
&& command
[n
- 1] == ' ')
1438 command
[n
- 1] = '\0';
1444 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1445 #define TARGET_LITTLE_NAME "elf32-littlearm"
1446 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1447 #define TARGET_BIG_NAME "elf32-bigarm"
1449 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1450 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1452 typedef unsigned long int insn32
;
1453 typedef unsigned short int insn16
;
1455 /* In lieu of proper flags, assume all EABIv4 or later objects are
1457 #define INTERWORK_FLAG(abfd) \
1458 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1459 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1461 /* The linker script knows the section names for placement.
1462 The entry_names are used to do simple name mangling on the stubs.
1463 Given a function name, and its type, the stub can be found. The
1464 name can be changed. The only requirement is the %s be present. */
1465 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1466 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1468 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1469 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1471 /* The name of the dynamic interpreter. This is put in the .interp
1473 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1475 #ifdef FOUR_WORD_PLT
1477 /* The first entry in a procedure linkage table looks like
1478 this. It is set up so that any shared library function that is
1479 called before the relocation has been set up calls the dynamic
1481 static const bfd_vma elf32_arm_plt0_entry
[] =
1483 0xe52de004, /* str lr, [sp, #-4]! */
1484 0xe59fe010, /* ldr lr, [pc, #16] */
1485 0xe08fe00e, /* add lr, pc, lr */
1486 0xe5bef008, /* ldr pc, [lr, #8]! */
1489 /* Subsequent entries in a procedure linkage table look like
1491 static const bfd_vma elf32_arm_plt_entry
[] =
1493 0xe28fc600, /* add ip, pc, #NN */
1494 0xe28cca00, /* add ip, ip, #NN */
1495 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1496 0x00000000, /* unused */
1501 /* The first entry in a procedure linkage table looks like
1502 this. It is set up so that any shared library function that is
1503 called before the relocation has been set up calls the dynamic
1505 static const bfd_vma elf32_arm_plt0_entry
[] =
1507 0xe52de004, /* str lr, [sp, #-4]! */
1508 0xe59fe004, /* ldr lr, [pc, #4] */
1509 0xe08fe00e, /* add lr, pc, lr */
1510 0xe5bef008, /* ldr pc, [lr, #8]! */
1511 0x00000000, /* &GOT[0] - . */
1514 /* Subsequent entries in a procedure linkage table look like
1516 static const bfd_vma elf32_arm_plt_entry
[] =
1518 0xe28fc600, /* add ip, pc, #0xNN00000 */
1519 0xe28cca00, /* add ip, ip, #0xNN000 */
1520 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1525 /* The format of the first entry in the procedure linkage table
1526 for a VxWorks executable. */
1527 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry
[] =
1529 0xe52dc008, /* str ip,[sp,#-8]! */
1530 0xe59fc000, /* ldr ip,[pc] */
1531 0xe59cf008, /* ldr pc,[ip,#8] */
1532 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1535 /* The format of subsequent entries in a VxWorks executable. */
1536 static const bfd_vma elf32_arm_vxworks_exec_plt_entry
[] =
1538 0xe59fc000, /* ldr ip,[pc] */
1539 0xe59cf000, /* ldr pc,[ip] */
1540 0x00000000, /* .long @got */
1541 0xe59fc000, /* ldr ip,[pc] */
1542 0xea000000, /* b _PLT */
1543 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1546 /* The format of entries in a VxWorks shared library. */
1547 static const bfd_vma elf32_arm_vxworks_shared_plt_entry
[] =
1549 0xe59fc000, /* ldr ip,[pc] */
1550 0xe79cf009, /* ldr pc,[ip,r9] */
1551 0x00000000, /* .long @got */
1552 0xe59fc000, /* ldr ip,[pc] */
1553 0xe599f008, /* ldr pc,[r9,#8] */
1554 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1557 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1558 #define PLT_THUMB_STUB_SIZE 4
1559 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
1565 /* The entries in a PLT when using a DLL-based target with multiple
1567 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
1569 0xe51ff004, /* ldr pc, [pc, #-4] */
1570 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1573 /* Used to build a map of a section. This is required for mixed-endian
1576 typedef struct elf32_elf_section_map
1581 elf32_arm_section_map
;
1583 typedef struct _arm_elf_section_data
1585 struct bfd_elf_section_data elf
;
1586 unsigned int mapcount
;
1587 elf32_arm_section_map
*map
;
1589 _arm_elf_section_data
;
1591 #define elf32_arm_section_data(sec) \
1592 ((_arm_elf_section_data *) elf_section_data (sec))
1594 /* The size of the thread control block. */
1597 #define NUM_KNOWN_ATTRIBUTES 32
1599 typedef struct aeabi_attribute
1606 typedef struct aeabi_attribute_list
1608 struct aeabi_attribute_list
*next
;
1610 aeabi_attribute attr
;
1611 } aeabi_attribute_list
;
1613 struct elf32_arm_obj_tdata
1615 struct elf_obj_tdata root
;
1617 /* tls_type for each local got entry. */
1618 char *local_got_tls_type
;
1620 aeabi_attribute known_eabi_attributes
[NUM_KNOWN_ATTRIBUTES
];
1621 aeabi_attribute_list
*other_eabi_attributes
;
1624 #define elf32_arm_tdata(abfd) \
1625 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1627 #define elf32_arm_local_got_tls_type(abfd) \
1628 (elf32_arm_tdata (abfd)->local_got_tls_type)
1631 elf32_arm_mkobject (bfd
*abfd
)
1633 bfd_size_type amt
= sizeof (struct elf32_arm_obj_tdata
);
1634 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
1635 if (abfd
->tdata
.any
== NULL
)
1640 /* The ARM linker needs to keep track of the number of relocs that it
1641 decides to copy in check_relocs for each symbol. This is so that
1642 it can discard PC relative relocs if it doesn't need them when
1643 linking with -Bsymbolic. We store the information in a field
1644 extending the regular ELF linker hash table. */
1646 /* This structure keeps track of the number of relocs we have copied
1647 for a given symbol. */
1648 struct elf32_arm_relocs_copied
1651 struct elf32_arm_relocs_copied
* next
;
1652 /* A section in dynobj. */
1654 /* Number of relocs copied in this section. */
1655 bfd_size_type count
;
1656 /* Number of PC-relative relocs copied in this section. */
1657 bfd_size_type pc_count
;
1660 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1662 /* Arm ELF linker hash entry. */
1663 struct elf32_arm_link_hash_entry
1665 struct elf_link_hash_entry root
;
1667 /* Number of PC relative relocs copied for this symbol. */
1668 struct elf32_arm_relocs_copied
* relocs_copied
;
1670 /* We reference count Thumb references to a PLT entry separately,
1671 so that we can emit the Thumb trampoline only if needed. */
1672 bfd_signed_vma plt_thumb_refcount
;
1674 /* Since PLT entries have variable size if the Thumb prologue is
1675 used, we need to record the index into .got.plt instead of
1676 recomputing it from the PLT offset. */
1677 bfd_signed_vma plt_got_offset
;
1679 #define GOT_UNKNOWN 0
1680 #define GOT_NORMAL 1
1681 #define GOT_TLS_GD 2
1682 #define GOT_TLS_IE 4
1683 unsigned char tls_type
;
1686 /* Traverse an arm ELF linker hash table. */
1687 #define elf32_arm_link_hash_traverse(table, func, info) \
1688 (elf_link_hash_traverse \
1690 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1693 /* Get the ARM elf linker hash table from a link_info structure. */
1694 #define elf32_arm_hash_table(info) \
1695 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1697 /* ARM ELF linker hash table. */
1698 struct elf32_arm_link_hash_table
1700 /* The main hash table. */
1701 struct elf_link_hash_table root
;
1703 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1704 bfd_size_type thumb_glue_size
;
1706 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1707 bfd_size_type arm_glue_size
;
1709 /* An arbitrary input BFD chosen to hold the glue sections. */
1710 bfd
* bfd_of_glue_owner
;
1712 /* Nonzero to output a BE8 image. */
1715 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1716 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1719 /* The relocation to use for R_ARM_TARGET2 relocations. */
1722 /* Nonzero to fix BX instructions for ARMv4 targets. */
1725 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1728 /* The number of bytes in the initial entry in the PLT. */
1729 bfd_size_type plt_header_size
;
1731 /* The number of bytes in the subsequent PLT etries. */
1732 bfd_size_type plt_entry_size
;
1734 /* True if the target system is VxWorks. */
1737 /* True if the target system is Symbian OS. */
1740 /* True if the target uses REL relocations. */
1743 /* Short-cuts to get to dynamic linker sections. */
1752 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
1755 /* Data for R_ARM_TLS_LDM32 relocations. */
1757 bfd_signed_vma refcount
;
1761 /* Small local sym to section mapping cache. */
1762 struct sym_sec_cache sym_sec
;
1764 /* For convenience in allocate_dynrelocs. */
1768 /* Create an entry in an ARM ELF linker hash table. */
1770 static struct bfd_hash_entry
*
1771 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
1772 struct bfd_hash_table
* table
,
1773 const char * string
)
1775 struct elf32_arm_link_hash_entry
* ret
=
1776 (struct elf32_arm_link_hash_entry
*) entry
;
1778 /* Allocate the structure if it has not already been allocated by a
1780 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
1781 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
1783 return (struct bfd_hash_entry
*) ret
;
1785 /* Call the allocation method of the superclass. */
1786 ret
= ((struct elf32_arm_link_hash_entry
*)
1787 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1791 ret
->relocs_copied
= NULL
;
1792 ret
->tls_type
= GOT_UNKNOWN
;
1793 ret
->plt_thumb_refcount
= 0;
1794 ret
->plt_got_offset
= -1;
1797 return (struct bfd_hash_entry
*) ret
;
1800 /* Return true if NAME is the name of the relocation section associated
1804 reloc_section_p (struct elf32_arm_link_hash_table
*htab
,
1805 const char *name
, asection
*s
)
1808 return strncmp (name
, ".rel", 4) == 0 && strcmp (s
->name
, name
+ 4) == 0;
1810 return strncmp (name
, ".rela", 5) == 0 && strcmp (s
->name
, name
+ 5) == 0;
1813 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
1814 shortcuts to them in our hash table. */
1817 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
1819 struct elf32_arm_link_hash_table
*htab
;
1821 htab
= elf32_arm_hash_table (info
);
1822 /* BPABI objects never have a GOT, or associated sections. */
1823 if (htab
->symbian_p
)
1826 if (! _bfd_elf_create_got_section (dynobj
, info
))
1829 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1830 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1831 if (!htab
->sgot
|| !htab
->sgotplt
)
1834 htab
->srelgot
= bfd_make_section_with_flags (dynobj
,
1835 RELOC_SECTION (htab
, ".got"),
1836 (SEC_ALLOC
| SEC_LOAD
1839 | SEC_LINKER_CREATED
1841 if (htab
->srelgot
== NULL
1842 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
1847 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
1848 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
1852 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1854 struct elf32_arm_link_hash_table
*htab
;
1856 htab
= elf32_arm_hash_table (info
);
1857 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
1860 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1863 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
1864 htab
->srelplt
= bfd_get_section_by_name (dynobj
,
1865 RELOC_SECTION (htab
, ".plt"));
1866 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1868 htab
->srelbss
= bfd_get_section_by_name (dynobj
,
1869 RELOC_SECTION (htab
, ".bss"));
1871 if (htab
->vxworks_p
)
1873 if (!elf_vxworks_create_dynamic_sections (dynobj
, info
, &htab
->srelplt2
))
1878 htab
->plt_header_size
= 0;
1879 htab
->plt_entry_size
1880 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry
);
1884 htab
->plt_header_size
1885 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry
);
1886 htab
->plt_entry_size
1887 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry
);
1894 || (!info
->shared
&& !htab
->srelbss
))
1900 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1903 elf32_arm_copy_indirect_symbol (struct bfd_link_info
*info
,
1904 struct elf_link_hash_entry
*dir
,
1905 struct elf_link_hash_entry
*ind
)
1907 struct elf32_arm_link_hash_entry
*edir
, *eind
;
1909 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
1910 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
1912 if (eind
->relocs_copied
!= NULL
)
1914 if (edir
->relocs_copied
!= NULL
)
1916 struct elf32_arm_relocs_copied
**pp
;
1917 struct elf32_arm_relocs_copied
*p
;
1919 /* Add reloc counts against the indirect sym to the direct sym
1920 list. Merge any entries against the same section. */
1921 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
1923 struct elf32_arm_relocs_copied
*q
;
1925 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
1926 if (q
->section
== p
->section
)
1928 q
->pc_count
+= p
->pc_count
;
1929 q
->count
+= p
->count
;
1936 *pp
= edir
->relocs_copied
;
1939 edir
->relocs_copied
= eind
->relocs_copied
;
1940 eind
->relocs_copied
= NULL
;
1943 /* Copy over PLT info. */
1944 edir
->plt_thumb_refcount
+= eind
->plt_thumb_refcount
;
1945 eind
->plt_thumb_refcount
= 0;
1947 if (ind
->root
.type
== bfd_link_hash_indirect
1948 && dir
->got
.refcount
<= 0)
1950 edir
->tls_type
= eind
->tls_type
;
1951 eind
->tls_type
= GOT_UNKNOWN
;
1954 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1957 /* Create an ARM elf linker hash table. */
1959 static struct bfd_link_hash_table
*
1960 elf32_arm_link_hash_table_create (bfd
*abfd
)
1962 struct elf32_arm_link_hash_table
*ret
;
1963 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
1965 ret
= bfd_malloc (amt
);
1969 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
1970 elf32_arm_link_hash_newfunc
))
1977 ret
->sgotplt
= NULL
;
1978 ret
->srelgot
= NULL
;
1980 ret
->srelplt
= NULL
;
1981 ret
->sdynbss
= NULL
;
1982 ret
->srelbss
= NULL
;
1983 ret
->srelplt2
= NULL
;
1984 ret
->thumb_glue_size
= 0;
1985 ret
->arm_glue_size
= 0;
1986 ret
->bfd_of_glue_owner
= NULL
;
1987 ret
->byteswap_code
= 0;
1988 ret
->target1_is_rel
= 0;
1989 ret
->target2_reloc
= R_ARM_NONE
;
1990 #ifdef FOUR_WORD_PLT
1991 ret
->plt_header_size
= 16;
1992 ret
->plt_entry_size
= 16;
1994 ret
->plt_header_size
= 20;
1995 ret
->plt_entry_size
= 12;
2002 ret
->sym_sec
.abfd
= NULL
;
2004 ret
->tls_ldm_got
.refcount
= 0;
2006 return &ret
->root
.root
;
2009 /* Locate the Thumb encoded calling stub for NAME. */
2011 static struct elf_link_hash_entry
*
2012 find_thumb_glue (struct bfd_link_info
*link_info
,
2017 struct elf_link_hash_entry
*hash
;
2018 struct elf32_arm_link_hash_table
*hash_table
;
2020 /* We need a pointer to the armelf specific hash table. */
2021 hash_table
= elf32_arm_hash_table (link_info
);
2023 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2024 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
2026 BFD_ASSERT (tmp_name
);
2028 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
2030 hash
= elf_link_hash_lookup
2031 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2034 /* xgettext:c-format */
2035 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
2036 input_bfd
, tmp_name
, name
);
2043 /* Locate the ARM encoded calling stub for NAME. */
2045 static struct elf_link_hash_entry
*
2046 find_arm_glue (struct bfd_link_info
*link_info
,
2051 struct elf_link_hash_entry
*myh
;
2052 struct elf32_arm_link_hash_table
*hash_table
;
2054 /* We need a pointer to the elfarm specific hash table. */
2055 hash_table
= elf32_arm_hash_table (link_info
);
2057 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2058 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
2060 BFD_ASSERT (tmp_name
);
2062 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
2064 myh
= elf_link_hash_lookup
2065 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2068 /* xgettext:c-format */
2069 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
2070 input_bfd
, tmp_name
, name
);
2077 /* ARM->Thumb glue (static images):
2081 ldr r12, __func_addr
2084 .word func @ behave as if you saw a ARM_32 reloc.
2086 (relocatable images)
2089 ldr r12, __func_offset
2096 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2097 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
2098 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
2099 static const insn32 a2t3_func_addr_insn
= 0x00000001;
2101 #define ARM2THUMB_PIC_GLUE_SIZE 16
2102 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
2103 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
2104 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
2106 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2110 __func_from_thumb: __func_from_thumb:
2112 nop ldr r6, __func_addr
2114 __func_change_to_arm: bx r6
2116 __func_back_to_thumb:
2122 #define THUMB2ARM_GLUE_SIZE 8
2123 static const insn16 t2a1_bx_pc_insn
= 0x4778;
2124 static const insn16 t2a2_noop_insn
= 0x46c0;
2125 static const insn32 t2a3_b_insn
= 0xea000000;
2127 #ifndef ELFARM_NABI_C_INCLUDED
2129 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
2133 struct elf32_arm_link_hash_table
* globals
;
2135 globals
= elf32_arm_hash_table (info
);
2137 BFD_ASSERT (globals
!= NULL
);
2139 if (globals
->arm_glue_size
!= 0)
2141 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2143 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2144 ARM2THUMB_GLUE_SECTION_NAME
);
2146 BFD_ASSERT (s
!= NULL
);
2148 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
2150 s
->size
= globals
->arm_glue_size
;
2154 if (globals
->thumb_glue_size
!= 0)
2156 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2158 s
= bfd_get_section_by_name
2159 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2161 BFD_ASSERT (s
!= NULL
);
2163 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
2165 s
->size
= globals
->thumb_glue_size
;
2173 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
2174 struct elf_link_hash_entry
* h
)
2176 const char * name
= h
->root
.root
.string
;
2179 struct elf_link_hash_entry
* myh
;
2180 struct bfd_link_hash_entry
* bh
;
2181 struct elf32_arm_link_hash_table
* globals
;
2184 globals
= elf32_arm_hash_table (link_info
);
2186 BFD_ASSERT (globals
!= NULL
);
2187 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2189 s
= bfd_get_section_by_name
2190 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
2192 BFD_ASSERT (s
!= NULL
);
2194 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
2196 BFD_ASSERT (tmp_name
);
2198 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
2200 myh
= elf_link_hash_lookup
2201 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2205 /* We've already seen this guy. */
2210 /* The only trick here is using hash_table->arm_glue_size as the value.
2211 Even though the section isn't allocated yet, this is where we will be
2214 val
= globals
->arm_glue_size
+ 1;
2215 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
2216 tmp_name
, BSF_GLOBAL
, s
, val
,
2217 NULL
, TRUE
, FALSE
, &bh
);
2219 myh
= (struct elf_link_hash_entry
*) bh
;
2220 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
2221 myh
->forced_local
= 1;
2225 if ((link_info
->shared
|| globals
->root
.is_relocatable_executable
))
2226 globals
->arm_glue_size
+= ARM2THUMB_PIC_GLUE_SIZE
;
2228 globals
->arm_glue_size
+= ARM2THUMB_STATIC_GLUE_SIZE
;
2234 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
2235 struct elf_link_hash_entry
*h
)
2237 const char *name
= h
->root
.root
.string
;
2240 struct elf_link_hash_entry
*myh
;
2241 struct bfd_link_hash_entry
*bh
;
2242 struct elf32_arm_link_hash_table
*hash_table
;
2245 hash_table
= elf32_arm_hash_table (link_info
);
2247 BFD_ASSERT (hash_table
!= NULL
);
2248 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
2250 s
= bfd_get_section_by_name
2251 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2253 BFD_ASSERT (s
!= NULL
);
2255 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2256 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
2258 BFD_ASSERT (tmp_name
);
2260 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
2262 myh
= elf_link_hash_lookup
2263 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2267 /* We've already seen this guy. */
2273 val
= hash_table
->thumb_glue_size
+ 1;
2274 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2275 tmp_name
, BSF_GLOBAL
, s
, val
,
2276 NULL
, TRUE
, FALSE
, &bh
);
2278 /* If we mark it 'Thumb', the disassembler will do a better job. */
2279 myh
= (struct elf_link_hash_entry
*) bh
;
2280 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
2281 myh
->forced_local
= 1;
2285 #define CHANGE_TO_ARM "__%s_change_to_arm"
2286 #define BACK_FROM_ARM "__%s_back_from_arm"
2288 /* Allocate another symbol to mark where we switch to Arm mode. */
2289 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2290 + strlen (CHANGE_TO_ARM
) + 1);
2292 BFD_ASSERT (tmp_name
);
2294 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
2297 val
= hash_table
->thumb_glue_size
+ 4,
2298 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2299 tmp_name
, BSF_LOCAL
, s
, val
,
2300 NULL
, TRUE
, FALSE
, &bh
);
2304 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
2309 /* Add the glue sections to ABFD. This function is called from the
2310 linker scripts in ld/emultempl/{armelf}.em. */
2313 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
2314 struct bfd_link_info
*info
)
2319 /* If we are only performing a partial
2320 link do not bother adding the glue. */
2321 if (info
->relocatable
)
2324 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
2328 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2329 will prevent elf_link_input_bfd() from processing the contents
2331 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
2333 sec
= bfd_make_section_with_flags (abfd
,
2334 ARM2THUMB_GLUE_SECTION_NAME
,
2338 || !bfd_set_section_alignment (abfd
, sec
, 2))
2341 /* Set the gc mark to prevent the section from being removed by garbage
2342 collection, despite the fact that no relocs refer to this section. */
2346 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
2350 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2351 | SEC_CODE
| SEC_READONLY
;
2353 sec
= bfd_make_section_with_flags (abfd
,
2354 THUMB2ARM_GLUE_SECTION_NAME
,
2358 || !bfd_set_section_alignment (abfd
, sec
, 2))
2367 /* Select a BFD to be used to hold the sections used by the glue code.
2368 This function is called from the linker scripts in ld/emultempl/
2372 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
2374 struct elf32_arm_link_hash_table
*globals
;
2376 /* If we are only performing a partial link
2377 do not bother getting a bfd to hold the glue. */
2378 if (info
->relocatable
)
2381 /* Make sure we don't attach the glue sections to a dynamic object. */
2382 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
2384 globals
= elf32_arm_hash_table (info
);
2386 BFD_ASSERT (globals
!= NULL
);
2388 if (globals
->bfd_of_glue_owner
!= NULL
)
2391 /* Save the bfd for later use. */
2392 globals
->bfd_of_glue_owner
= abfd
;
2397 static void check_use_blx(struct elf32_arm_link_hash_table
*globals
)
2399 if (elf32_arm_get_eabi_attr_int (globals
->obfd
, Tag_CPU_arch
) > 2)
2400 globals
->use_blx
= 1;
2404 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
2405 struct bfd_link_info
*link_info
,
2408 Elf_Internal_Shdr
*symtab_hdr
;
2409 Elf_Internal_Rela
*internal_relocs
= NULL
;
2410 Elf_Internal_Rela
*irel
, *irelend
;
2411 bfd_byte
*contents
= NULL
;
2414 struct elf32_arm_link_hash_table
*globals
;
2416 /* If we are only performing a partial link do not bother
2417 to construct any glue. */
2418 if (link_info
->relocatable
)
2421 /* Here we have a bfd that is to be included on the link. We have a hook
2422 to do reloc rummaging, before section sizes are nailed down. */
2423 globals
= elf32_arm_hash_table (link_info
);
2424 check_use_blx (globals
);
2426 BFD_ASSERT (globals
!= NULL
);
2427 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2429 if (byteswap_code
&& !bfd_big_endian (abfd
))
2431 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2435 globals
->byteswap_code
= byteswap_code
;
2437 /* Rummage around all the relocs and map the glue vectors. */
2438 sec
= abfd
->sections
;
2443 for (; sec
!= NULL
; sec
= sec
->next
)
2445 if (sec
->reloc_count
== 0)
2448 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2450 /* Load the relocs. */
2452 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
2453 (Elf_Internal_Rela
*) NULL
, FALSE
);
2455 if (internal_relocs
== NULL
)
2458 irelend
= internal_relocs
+ sec
->reloc_count
;
2459 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2462 unsigned long r_index
;
2464 struct elf_link_hash_entry
*h
;
2466 r_type
= ELF32_R_TYPE (irel
->r_info
);
2467 r_index
= ELF32_R_SYM (irel
->r_info
);
2469 /* These are the only relocation types we care about. */
2470 if ( r_type
!= R_ARM_PC24
2471 && r_type
!= R_ARM_PLT32
2472 && r_type
!= R_ARM_CALL
2473 && r_type
!= R_ARM_JUMP24
2474 && r_type
!= R_ARM_THM_CALL
)
2477 /* Get the section contents if we haven't done so already. */
2478 if (contents
== NULL
)
2480 /* Get cached copy if it exists. */
2481 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2482 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2485 /* Go get them off disk. */
2486 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2491 /* If the relocation is not against a symbol it cannot concern us. */
2494 /* We don't care about local symbols. */
2495 if (r_index
< symtab_hdr
->sh_info
)
2498 /* This is an external symbol. */
2499 r_index
-= symtab_hdr
->sh_info
;
2500 h
= (struct elf_link_hash_entry
*)
2501 elf_sym_hashes (abfd
)[r_index
];
2503 /* If the relocation is against a static symbol it must be within
2504 the current section and so cannot be a cross ARM/Thumb relocation. */
2508 /* If the call will go through a PLT entry then we do not need
2510 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2519 /* This one is a call from arm code. We need to look up
2520 the target of the call. If it is a thumb target, we
2522 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
2523 && !(r_type
== R_ARM_CALL
&& globals
->use_blx
))
2524 record_arm_to_thumb_glue (link_info
, h
);
2527 case R_ARM_THM_CALL
:
2528 /* This one is a call from thumb code. We look
2529 up the target of the call. If it is not a thumb
2530 target, we insert glue. */
2531 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
&& !globals
->use_blx
)
2532 record_thumb_to_arm_glue (link_info
, h
);
2540 if (contents
!= NULL
2541 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2545 if (internal_relocs
!= NULL
2546 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2547 free (internal_relocs
);
2548 internal_relocs
= NULL
;
2554 if (contents
!= NULL
2555 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2557 if (internal_relocs
!= NULL
2558 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2559 free (internal_relocs
);
2566 /* Set target relocation values needed during linking. */
2569 bfd_elf32_arm_set_target_relocs (struct bfd_link_info
*link_info
,
2571 char * target2_type
,
2575 struct elf32_arm_link_hash_table
*globals
;
2577 globals
= elf32_arm_hash_table (link_info
);
2579 globals
->target1_is_rel
= target1_is_rel
;
2580 if (strcmp (target2_type
, "rel") == 0)
2581 globals
->target2_reloc
= R_ARM_REL32
;
2582 else if (strcmp (target2_type
, "abs") == 0)
2583 globals
->target2_reloc
= R_ARM_ABS32
;
2584 else if (strcmp (target2_type
, "got-rel") == 0)
2585 globals
->target2_reloc
= R_ARM_GOT_PREL
;
2588 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2591 globals
->fix_v4bx
= fix_v4bx
;
2592 globals
->use_blx
|= use_blx
;
2595 /* The thumb form of a long branch is a bit finicky, because the offset
2596 encoding is split over two fields, each in it's own instruction. They
2597 can occur in any order. So given a thumb form of long branch, and an
2598 offset, insert the offset into the thumb branch and return finished
2601 It takes two thumb instructions to encode the target address. Each has
2602 11 bits to invest. The upper 11 bits are stored in one (identified by
2603 H-0.. see below), the lower 11 bits are stored in the other (identified
2606 Combine together and shifted left by 1 (it's a half word address) and
2610 H-0, upper address-0 = 000
2612 H-1, lower address-0 = 800
2614 They can be ordered either way, but the arm tools I've seen always put
2615 the lower one first. It probably doesn't matter. krk@cygnus.com
2617 XXX: Actually the order does matter. The second instruction (H-1)
2618 moves the computed address into the PC, so it must be the second one
2619 in the sequence. The problem, however is that whilst little endian code
2620 stores the instructions in HI then LOW order, big endian code does the
2621 reverse. nickc@cygnus.com. */
2623 #define LOW_HI_ORDER 0xF800F000
2624 #define HI_LOW_ORDER 0xF000F800
2627 insert_thumb_branch (insn32 br_insn
, int rel_off
)
2629 unsigned int low_bits
;
2630 unsigned int high_bits
;
2632 BFD_ASSERT ((rel_off
& 1) != 1);
2634 rel_off
>>= 1; /* Half word aligned address. */
2635 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
2636 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
2638 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
2639 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
2640 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
2641 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
2643 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2644 abort (); /* Error - not a valid branch instruction form. */
2649 /* Thumb code calling an ARM function. */
2652 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
2656 asection
* input_section
,
2657 bfd_byte
* hit_data
,
2660 bfd_signed_vma addend
,
2665 unsigned long int tmp
;
2666 long int ret_offset
;
2667 struct elf_link_hash_entry
* myh
;
2668 struct elf32_arm_link_hash_table
* globals
;
2670 myh
= find_thumb_glue (info
, name
, input_bfd
);
2674 globals
= elf32_arm_hash_table (info
);
2676 BFD_ASSERT (globals
!= NULL
);
2677 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2679 my_offset
= myh
->root
.u
.def
.value
;
2681 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2682 THUMB2ARM_GLUE_SECTION_NAME
);
2684 BFD_ASSERT (s
!= NULL
);
2685 BFD_ASSERT (s
->contents
!= NULL
);
2686 BFD_ASSERT (s
->output_section
!= NULL
);
2688 if ((my_offset
& 0x01) == 0x01)
2691 && sym_sec
->owner
!= NULL
2692 && !INTERWORK_FLAG (sym_sec
->owner
))
2694 (*_bfd_error_handler
)
2695 (_("%B(%s): warning: interworking not enabled.\n"
2696 " first occurrence: %B: thumb call to arm"),
2697 sym_sec
->owner
, input_bfd
, name
);
2703 myh
->root
.u
.def
.value
= my_offset
;
2705 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
2706 s
->contents
+ my_offset
);
2708 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
2709 s
->contents
+ my_offset
+ 2);
2712 /* Address of destination of the stub. */
2713 ((bfd_signed_vma
) val
)
2715 /* Offset from the start of the current section
2716 to the start of the stubs. */
2718 /* Offset of the start of this stub from the start of the stubs. */
2720 /* Address of the start of the current section. */
2721 + s
->output_section
->vma
)
2722 /* The branch instruction is 4 bytes into the stub. */
2724 /* ARM branches work from the pc of the instruction + 8. */
2727 bfd_put_32 (output_bfd
,
2728 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
2729 s
->contents
+ my_offset
+ 4);
2732 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
2734 /* Now go back and fix up the original BL insn to point to here. */
2736 /* Address of where the stub is located. */
2737 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
2738 /* Address of where the BL is located. */
2739 - (input_section
->output_section
->vma
+ input_section
->output_offset
2741 /* Addend in the relocation. */
2743 /* Biassing for PC-relative addressing. */
2746 tmp
= bfd_get_32 (input_bfd
, hit_data
2747 - input_section
->vma
);
2749 bfd_put_32 (output_bfd
,
2750 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
2751 hit_data
- input_section
->vma
);
2756 /* Arm code calling a Thumb function. */
2759 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
2763 asection
* input_section
,
2764 bfd_byte
* hit_data
,
2767 bfd_signed_vma addend
,
2770 unsigned long int tmp
;
2773 long int ret_offset
;
2774 struct elf_link_hash_entry
* myh
;
2775 struct elf32_arm_link_hash_table
* globals
;
2777 myh
= find_arm_glue (info
, name
, input_bfd
);
2781 globals
= elf32_arm_hash_table (info
);
2783 BFD_ASSERT (globals
!= NULL
);
2784 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2786 my_offset
= myh
->root
.u
.def
.value
;
2787 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2788 ARM2THUMB_GLUE_SECTION_NAME
);
2789 BFD_ASSERT (s
!= NULL
);
2790 BFD_ASSERT (s
->contents
!= NULL
);
2791 BFD_ASSERT (s
->output_section
!= NULL
);
2793 if ((my_offset
& 0x01) == 0x01)
2796 && sym_sec
->owner
!= NULL
2797 && !INTERWORK_FLAG (sym_sec
->owner
))
2799 (*_bfd_error_handler
)
2800 (_("%B(%s): warning: interworking not enabled.\n"
2801 " first occurrence: %B: arm call to thumb"),
2802 sym_sec
->owner
, input_bfd
, name
);
2806 myh
->root
.u
.def
.value
= my_offset
;
2808 if ((info
->shared
|| globals
->root
.is_relocatable_executable
))
2810 /* For relocatable objects we can't use absolute addresses,
2811 so construct the address from a relative offset. */
2812 /* TODO: If the offset is small it's probably worth
2813 constructing the address with adds. */
2814 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
2815 s
->contents
+ my_offset
);
2816 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
2817 s
->contents
+ my_offset
+ 4);
2818 bfd_put_32 (output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
2819 s
->contents
+ my_offset
+ 8);
2820 /* Adjust the offset by 4 for the position of the add,
2821 and 8 for the pipeline offset. */
2822 ret_offset
= (val
- (s
->output_offset
2823 + s
->output_section
->vma
2826 bfd_put_32 (output_bfd
, ret_offset
,
2827 s
->contents
+ my_offset
+ 12);
2831 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
2832 s
->contents
+ my_offset
);
2834 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
2835 s
->contents
+ my_offset
+ 4);
2837 /* It's a thumb address. Add the low order bit. */
2838 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
2839 s
->contents
+ my_offset
+ 8);
2843 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
2845 tmp
= bfd_get_32 (input_bfd
, hit_data
);
2846 tmp
= tmp
& 0xFF000000;
2848 /* Somehow these are both 4 too far, so subtract 8. */
2849 ret_offset
= (s
->output_offset
2851 + s
->output_section
->vma
2852 - (input_section
->output_offset
2853 + input_section
->output_section
->vma
2857 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
2859 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
2864 /* Some relocations map to different relocations depending on the
2865 target. Return the real relocation. */
2867 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
2873 if (globals
->target1_is_rel
)
2879 return globals
->target2_reloc
;
2886 /* Return the base VMA address which should be subtracted from real addresses
2887 when resolving @dtpoff relocation.
2888 This is PT_TLS segment p_vaddr. */
2891 dtpoff_base (struct bfd_link_info
*info
)
2893 /* If tls_sec is NULL, we should have signalled an error already. */
2894 if (elf_hash_table (info
)->tls_sec
== NULL
)
2896 return elf_hash_table (info
)->tls_sec
->vma
;
2899 /* Return the relocation value for @tpoff relocation
2900 if STT_TLS virtual address is ADDRESS. */
2903 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2905 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2908 /* If tls_sec is NULL, we should have signalled an error already. */
2909 if (htab
->tls_sec
== NULL
)
2911 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
2912 return address
- htab
->tls_sec
->vma
+ base
;
2915 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
2916 VALUE is the relocation value. */
2918 static bfd_reloc_status_type
2919 elf32_arm_abs12_reloc (bfd
*abfd
, void *data
, bfd_vma value
)
2922 return bfd_reloc_overflow
;
2924 value
|= bfd_get_32 (abfd
, data
) & 0xfffff000;
2925 bfd_put_32 (abfd
, value
, data
);
2926 return bfd_reloc_ok
;
2929 /* Perform a relocation as part of a final link. */
2931 static bfd_reloc_status_type
2932 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
2935 asection
* input_section
,
2936 bfd_byte
* contents
,
2937 Elf_Internal_Rela
* rel
,
2939 struct bfd_link_info
* info
,
2941 const char * sym_name
,
2943 struct elf_link_hash_entry
* h
,
2944 bfd_boolean
* unresolved_reloc_p
)
2946 unsigned long r_type
= howto
->type
;
2947 unsigned long r_symndx
;
2948 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
2949 bfd
* dynobj
= NULL
;
2950 Elf_Internal_Shdr
* symtab_hdr
;
2951 struct elf_link_hash_entry
** sym_hashes
;
2952 bfd_vma
* local_got_offsets
;
2953 asection
* sgot
= NULL
;
2954 asection
* splt
= NULL
;
2955 asection
* sreloc
= NULL
;
2957 bfd_signed_vma signed_addend
;
2958 struct elf32_arm_link_hash_table
* globals
;
2960 globals
= elf32_arm_hash_table (info
);
2962 /* Some relocation type map to different relocations depending on the
2963 target. We pick the right one here. */
2964 r_type
= arm_real_reloc_type (globals
, r_type
);
2965 if (r_type
!= howto
->type
)
2966 howto
= elf32_arm_howto_from_type (r_type
);
2968 /* If the start address has been set, then set the EF_ARM_HASENTRY
2969 flag. Setting this more than once is redundant, but the cost is
2970 not too high, and it keeps the code simple.
2972 The test is done here, rather than somewhere else, because the
2973 start address is only set just before the final link commences.
2975 Note - if the user deliberately sets a start address of 0, the
2976 flag will not be set. */
2977 if (bfd_get_start_address (output_bfd
) != 0)
2978 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
2980 dynobj
= elf_hash_table (info
)->dynobj
;
2983 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2984 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2986 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2987 sym_hashes
= elf_sym_hashes (input_bfd
);
2988 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2989 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2991 if (globals
->use_rel
)
2993 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
2995 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2998 signed_addend
&= ~ howto
->src_mask
;
2999 signed_addend
|= addend
;
3002 signed_addend
= addend
;
3005 addend
= signed_addend
= rel
->r_addend
;
3010 /* We don't need to find a value for this symbol. It's just a
3012 *unresolved_reloc_p
= FALSE
;
3013 return bfd_reloc_ok
;
3016 if (!globals
->vxworks_p
)
3017 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
3027 /* r_symndx will be zero only for relocs against symbols
3028 from removed linkonce sections, or sections discarded by
3031 return bfd_reloc_ok
;
3033 /* Handle relocations which should use the PLT entry. ABS32/REL32
3034 will use the symbol's value, which may point to a PLT entry, but we
3035 don't need to handle that here. If we created a PLT entry, all
3036 branches in this object should go to it. */
3037 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
3040 && h
->plt
.offset
!= (bfd_vma
) -1)
3042 /* If we've created a .plt section, and assigned a PLT entry to
3043 this function, it should not be known to bind locally. If
3044 it were, we would have cleared the PLT entry. */
3045 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
3047 value
= (splt
->output_section
->vma
3048 + splt
->output_offset
3050 *unresolved_reloc_p
= FALSE
;
3051 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3052 contents
, rel
->r_offset
, value
,
3056 /* When generating a shared object or relocatable executable, these
3057 relocations are copied into the output file to be resolved at
3059 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
3060 && (input_section
->flags
& SEC_ALLOC
)
3061 && (r_type
!= R_ARM_REL32
3062 || !SYMBOL_CALLS_LOCAL (info
, h
))
3064 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3065 || h
->root
.type
!= bfd_link_hash_undefweak
)
3066 && r_type
!= R_ARM_PC24
3067 && r_type
!= R_ARM_CALL
3068 && r_type
!= R_ARM_JUMP24
3069 && r_type
!= R_ARM_PREL31
3070 && r_type
!= R_ARM_PLT32
)
3072 Elf_Internal_Rela outrel
;
3074 bfd_boolean skip
, relocate
;
3076 *unresolved_reloc_p
= FALSE
;
3082 name
= (bfd_elf_string_from_elf_section
3084 elf_elfheader (input_bfd
)->e_shstrndx
,
3085 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3087 return bfd_reloc_notsupported
;
3089 BFD_ASSERT (reloc_section_p (globals
, name
, input_section
));
3091 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3092 BFD_ASSERT (sreloc
!= NULL
);
3098 outrel
.r_addend
= addend
;
3100 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3102 if (outrel
.r_offset
== (bfd_vma
) -1)
3104 else if (outrel
.r_offset
== (bfd_vma
) -2)
3105 skip
= TRUE
, relocate
= TRUE
;
3106 outrel
.r_offset
+= (input_section
->output_section
->vma
3107 + input_section
->output_offset
);
3110 memset (&outrel
, 0, sizeof outrel
);
3115 || !h
->def_regular
))
3116 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3121 /* This symbol is local, or marked to become local. */
3122 if (sym_flags
== STT_ARM_TFUNC
)
3124 if (globals
->symbian_p
)
3126 /* On Symbian OS, the data segment and text segement
3127 can be relocated independently. Therefore, we
3128 must indicate the segment to which this
3129 relocation is relative. The BPABI allows us to
3130 use any symbol in the right segment; we just use
3131 the section symbol as it is convenient. (We
3132 cannot use the symbol given by "h" directly as it
3133 will not appear in the dynamic symbol table.) */
3135 symbol
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3137 symbol
= elf_section_data (input_section
->output_section
)->dynindx
;
3138 BFD_ASSERT (symbol
!= 0);
3141 /* On SVR4-ish systems, the dynamic loader cannot
3142 relocate the text and data segments independently,
3143 so the symbol does not matter. */
3145 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
3146 if (globals
->use_rel
)
3149 outrel
.r_addend
+= value
;
3152 loc
= sreloc
->contents
;
3153 loc
+= sreloc
->reloc_count
++ * RELOC_SIZE (globals
);
3154 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3156 /* If this reloc is against an external symbol, we do not want to
3157 fiddle with the addend. Otherwise, we need to include the symbol
3158 value so that it becomes an addend for the dynamic reloc. */
3160 return bfd_reloc_ok
;
3162 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3163 contents
, rel
->r_offset
, value
,
3166 else switch (r_type
)
3169 return elf32_arm_abs12_reloc (input_bfd
, hit_data
, value
+ addend
);
3171 case R_ARM_XPC25
: /* Arm BLX instruction. */
3174 case R_ARM_PC24
: /* Arm B/BL instruction */
3176 if (r_type
== R_ARM_XPC25
)
3178 /* Check for Arm calling Arm function. */
3179 /* FIXME: Should we translate the instruction into a BL
3180 instruction instead ? */
3181 if (sym_flags
!= STT_ARM_TFUNC
)
3182 (*_bfd_error_handler
)
3183 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3185 h
? h
->root
.root
.string
: "(local)");
3187 else if (r_type
!= R_ARM_CALL
|| !globals
->use_blx
)
3189 /* Check for Arm calling Thumb function. */
3190 if (sym_flags
== STT_ARM_TFUNC
)
3192 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
3193 output_bfd
, input_section
,
3194 hit_data
, sym_sec
, rel
->r_offset
,
3195 signed_addend
, value
);
3196 return bfd_reloc_ok
;
3200 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3202 S is the address of the symbol in the relocation.
3203 P is address of the instruction being relocated.
3204 A is the addend (extracted from the instruction) in bytes.
3206 S is held in 'value'.
3207 P is the base address of the section containing the
3208 instruction plus the offset of the reloc into that
3210 (input_section->output_section->vma +
3211 input_section->output_offset +
3213 A is the addend, converted into bytes, ie:
3216 Note: None of these operations have knowledge of the pipeline
3217 size of the processor, thus it is up to the assembler to
3218 encode this information into the addend. */
3219 value
-= (input_section
->output_section
->vma
3220 + input_section
->output_offset
);
3221 value
-= rel
->r_offset
;
3222 if (globals
->use_rel
)
3223 value
+= (signed_addend
<< howto
->size
);
3225 /* RELA addends do not have to be adjusted by howto->size. */
3226 value
+= signed_addend
;
3228 signed_addend
= value
;
3229 signed_addend
>>= howto
->rightshift
;
3231 /* It is not an error for an undefined weak reference to be
3232 out of range. Any program that branches to such a symbol
3233 is going to crash anyway, so there is no point worrying
3234 about getting the destination exactly right. */
3235 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3237 /* Perform a signed range check. */
3238 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
3239 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
3240 return bfd_reloc_overflow
;
3243 addend
= (value
& 2);
3245 value
= (signed_addend
& howto
->dst_mask
)
3246 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
3248 /* Set the H bit in the BLX instruction. */
3249 if (sym_flags
== STT_ARM_TFUNC
)
3254 value
&= ~(bfd_vma
)(1 << 24);
3256 if (r_type
== R_ARM_CALL
)
3258 /* Select the correct instruction (BL or BLX). */
3259 if (sym_flags
== STT_ARM_TFUNC
)
3263 value
&= ~(bfd_vma
)(1 << 28);
3271 if (sym_flags
== STT_ARM_TFUNC
)
3276 value
-= (input_section
->output_section
->vma
3277 + input_section
->output_offset
+ rel
->r_offset
);
3282 value
-= (input_section
->output_section
->vma
3283 + input_section
->output_offset
+ rel
->r_offset
);
3284 value
+= signed_addend
;
3285 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3287 /* Check for overflow */
3288 if ((value
^ (value
>> 1)) & (1 << 30))
3289 return bfd_reloc_overflow
;
3291 value
&= 0x7fffffff;
3292 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
3293 if (sym_flags
== STT_ARM_TFUNC
)
3298 bfd_put_32 (input_bfd
, value
, hit_data
);
3299 return bfd_reloc_ok
;
3303 if ((long) value
> 0x7f || (long) value
< -0x80)
3304 return bfd_reloc_overflow
;
3306 bfd_put_8 (input_bfd
, value
, hit_data
);
3307 return bfd_reloc_ok
;
3312 if ((long) value
> 0x7fff || (long) value
< -0x8000)
3313 return bfd_reloc_overflow
;
3315 bfd_put_16 (input_bfd
, value
, hit_data
);
3316 return bfd_reloc_ok
;
3318 case R_ARM_THM_ABS5
:
3319 /* Support ldr and str instructions for the thumb. */
3320 if (globals
->use_rel
)
3322 /* Need to refetch addend. */
3323 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
3324 /* ??? Need to determine shift amount from operand size. */
3325 addend
>>= howto
->rightshift
;
3329 /* ??? Isn't value unsigned? */
3330 if ((long) value
> 0x1f || (long) value
< -0x10)
3331 return bfd_reloc_overflow
;
3333 /* ??? Value needs to be properly shifted into place first. */
3334 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
3335 bfd_put_16 (input_bfd
, value
, hit_data
);
3336 return bfd_reloc_ok
;
3338 case R_ARM_THM_XPC22
:
3339 case R_ARM_THM_CALL
:
3340 /* Thumb BL (branch long instruction). */
3343 bfd_boolean overflow
= FALSE
;
3344 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3345 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3346 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3347 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3349 bfd_signed_vma signed_check
;
3351 /* Need to refetch the addend and squish the two 11 bit pieces
3353 if (globals
->use_rel
)
3355 bfd_vma upper
= upper_insn
& 0x7ff;
3356 bfd_vma lower
= lower_insn
& 0x7ff;
3357 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
3358 addend
= (upper
<< 12) | (lower
<< 1);
3359 signed_addend
= addend
;
3362 if (r_type
== R_ARM_THM_XPC22
)
3364 /* Check for Thumb to Thumb call. */
3365 /* FIXME: Should we translate the instruction into a BL
3366 instruction instead ? */
3367 if (sym_flags
== STT_ARM_TFUNC
)
3368 (*_bfd_error_handler
)
3369 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3371 h
? h
->root
.root
.string
: "(local)");
3375 /* If it is not a call to Thumb, assume call to Arm.
3376 If it is a call relative to a section name, then it is not a
3377 function call at all, but rather a long jump. Calls through
3378 the PLT do not require stubs. */
3379 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
3380 && (h
== NULL
|| splt
== NULL
3381 || h
->plt
.offset
== (bfd_vma
) -1))
3383 if (globals
->use_blx
)
3385 /* Convert BL to BLX. */
3386 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
3388 else if (elf32_thumb_to_arm_stub
3389 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
3390 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
3391 return bfd_reloc_ok
;
3393 return bfd_reloc_dangerous
;
3395 else if (sym_flags
== STT_ARM_TFUNC
&& globals
->use_blx
)
3397 /* Make sure this is a BL. */
3398 lower_insn
|= 0x1800;
3402 /* Handle calls via the PLT. */
3403 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
3405 value
= (splt
->output_section
->vma
3406 + splt
->output_offset
3408 if (globals
->use_blx
)
3410 /* If the Thumb BLX instruction is available, convert the
3411 BL to a BLX instruction to call the ARM-mode PLT entry. */
3412 lower_insn
= (lower_insn
& ~0x1000) | 0x0800;
3415 /* Target the Thumb stub before the ARM PLT entry. */
3416 value
-= PLT_THUMB_STUB_SIZE
;
3417 *unresolved_reloc_p
= FALSE
;
3420 relocation
= value
+ signed_addend
;
3422 relocation
-= (input_section
->output_section
->vma
3423 + input_section
->output_offset
3426 check
= relocation
>> howto
->rightshift
;
3428 /* If this is a signed value, the rightshift just dropped
3429 leading 1 bits (assuming twos complement). */
3430 if ((bfd_signed_vma
) relocation
>= 0)
3431 signed_check
= check
;
3433 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
3435 /* Assumes two's complement. */
3436 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3439 if ((lower_insn
& 0x1800) == 0x0800)
3440 /* For a BLX instruction, make sure that the relocation is rounded up
3441 to a word boundary. This follows the semantics of the instruction
3442 which specifies that bit 1 of the target address will come from bit
3443 1 of the base address. */
3444 relocation
= (relocation
+ 2) & ~ 3;
3446 /* Put RELOCATION back into the insn. */
3447 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
3448 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
3450 /* Put the relocated value back in the object file: */
3451 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3452 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3454 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3458 case R_ARM_THM_JUMP24
:
3459 /* Thumb32 unconditional branch instruction. */
3462 bfd_boolean overflow
= FALSE
;
3463 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3464 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3465 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3466 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3468 bfd_signed_vma signed_check
;
3470 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3471 two pieces together. */
3472 if (globals
->use_rel
)
3474 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
3475 bfd_vma hi
= (upper_insn
& 0x03ff);
3476 bfd_vma I1
= (lower_insn
& 0x2000) >> 13;
3477 bfd_vma I2
= (lower_insn
& 0x0800) >> 11;
3478 bfd_vma lo
= (lower_insn
& 0x07ff);
3484 signed_addend
= (S
<< 24) | (I1
<< 23) | (I2
<< 22) | (hi
<< 12) | (lo
<< 1);
3485 signed_addend
-= (1 << 24); /* Sign extend. */
3488 /* ??? Should handle interworking? GCC might someday try to
3489 use this for tail calls. */
3491 relocation
= value
+ signed_addend
;
3492 relocation
-= (input_section
->output_section
->vma
3493 + input_section
->output_offset
3496 check
= relocation
>> howto
->rightshift
;
3498 /* If this is a signed value, the rightshift just dropped
3499 leading 1 bits (assuming twos complement). */
3500 if ((bfd_signed_vma
) relocation
>= 0)
3501 signed_check
= check
;
3503 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
3505 /* Assumes two's complement. */
3506 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3509 /* Put RELOCATION back into the insn. */
3511 bfd_vma S
= (relocation
& 0x01000000) >> 24;
3512 bfd_vma I1
= (relocation
& 0x00800000) >> 23;
3513 bfd_vma I2
= (relocation
& 0x00400000) >> 22;
3514 bfd_vma hi
= (relocation
& 0x003ff000) >> 12;
3515 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
3520 upper_insn
= (upper_insn
& (bfd_vma
) 0xf800) | (S
<< 10) | hi
;
3521 lower_insn
= (lower_insn
& (bfd_vma
) 0xd000) | (I1
<< 13) | (I2
<< 11) | lo
;
3524 /* Put the relocated value back in the object file: */
3525 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3526 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3528 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3531 case R_ARM_THM_JUMP19
:
3532 /* Thumb32 conditional branch instruction. */
3535 bfd_boolean overflow
= FALSE
;
3536 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3537 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3538 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3539 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3541 bfd_signed_vma signed_check
;
3543 /* Need to refetch the addend, reconstruct the top three bits,
3544 and squish the two 11 bit pieces together. */
3545 if (globals
->use_rel
)
3547 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
3548 bfd_vma upper
= (upper_insn
& 0x001f);
3549 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
3550 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
3551 bfd_vma lower
= (lower_insn
& 0x07ff);
3556 upper
-= 0x0100; /* Sign extend. */
3558 addend
= (upper
<< 12) | (lower
<< 1);
3559 signed_addend
= addend
;
3562 /* ??? Should handle interworking? GCC might someday try to
3563 use this for tail calls. */
3565 relocation
= value
+ signed_addend
;
3566 relocation
-= (input_section
->output_section
->vma
3567 + input_section
->output_offset
3570 check
= relocation
>> howto
->rightshift
;
3572 /* If this is a signed value, the rightshift just dropped
3573 leading 1 bits (assuming twos complement). */
3574 if ((bfd_signed_vma
) relocation
>= 0)
3575 signed_check
= check
;
3577 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
3579 /* Assumes two's complement. */
3580 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3583 /* Put RELOCATION back into the insn. */
3585 bfd_vma S
= (relocation
& 0x00100000) >> 20;
3586 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
3587 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
3588 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
3589 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
3591 upper_insn
= (upper_insn
& 0xfb30) | (S
<< 10) | hi
;
3592 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
3595 /* Put the relocated value back in the object file: */
3596 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3597 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3599 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3602 case R_ARM_THM_JUMP11
:
3603 case R_ARM_THM_JUMP8
:
3604 case R_ARM_THM_JUMP6
:
3605 /* Thumb B (branch) instruction). */
3607 bfd_signed_vma relocation
;
3608 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
3609 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3610 bfd_signed_vma signed_check
;
3612 /* CZB cannot jump backward. */
3613 if (r_type
== R_ARM_THM_JUMP6
)
3614 reloc_signed_min
= 0;
3616 if (globals
->use_rel
)
3618 /* Need to refetch addend. */
3619 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
3620 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3623 signed_addend
&= ~ howto
->src_mask
;
3624 signed_addend
|= addend
;
3627 signed_addend
= addend
;
3628 /* The value in the insn has been right shifted. We need to
3629 undo this, so that we can perform the address calculation
3630 in terms of bytes. */
3631 signed_addend
<<= howto
->rightshift
;
3633 relocation
= value
+ signed_addend
;
3635 relocation
-= (input_section
->output_section
->vma
3636 + input_section
->output_offset
3639 relocation
>>= howto
->rightshift
;
3640 signed_check
= relocation
;
3642 if (r_type
== R_ARM_THM_JUMP6
)
3643 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
3645 relocation
&= howto
->dst_mask
;
3646 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
3648 bfd_put_16 (input_bfd
, relocation
, hit_data
);
3650 /* Assumes two's complement. */
3651 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3652 return bfd_reloc_overflow
;
3654 return bfd_reloc_ok
;
3657 case R_ARM_ALU_PCREL7_0
:
3658 case R_ARM_ALU_PCREL15_8
:
3659 case R_ARM_ALU_PCREL23_15
:
3664 insn
= bfd_get_32 (input_bfd
, hit_data
);
3665 if (globals
->use_rel
)
3667 /* Extract the addend. */
3668 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
3669 signed_addend
= addend
;
3671 relocation
= value
+ signed_addend
;
3673 relocation
-= (input_section
->output_section
->vma
3674 + input_section
->output_offset
3676 insn
= (insn
& ~0xfff)
3677 | ((howto
->bitpos
<< 7) & 0xf00)
3678 | ((relocation
>> howto
->bitpos
) & 0xff);
3679 bfd_put_32 (input_bfd
, value
, hit_data
);
3681 return bfd_reloc_ok
;
3683 case R_ARM_GNU_VTINHERIT
:
3684 case R_ARM_GNU_VTENTRY
:
3685 return bfd_reloc_ok
;
3687 case R_ARM_GOTOFF32
:
3688 /* Relocation is relative to the start of the
3689 global offset table. */
3691 BFD_ASSERT (sgot
!= NULL
);
3693 return bfd_reloc_notsupported
;
3695 /* If we are addressing a Thumb function, we need to adjust the
3696 address by one, so that attempts to call the function pointer will
3697 correctly interpret it as Thumb code. */
3698 if (sym_flags
== STT_ARM_TFUNC
)
3701 /* Note that sgot->output_offset is not involved in this
3702 calculation. We always want the start of .got. If we
3703 define _GLOBAL_OFFSET_TABLE in a different way, as is
3704 permitted by the ABI, we might have to change this
3706 value
-= sgot
->output_section
->vma
;
3707 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3708 contents
, rel
->r_offset
, value
,
3712 /* Use global offset table as symbol value. */
3713 BFD_ASSERT (sgot
!= NULL
);
3716 return bfd_reloc_notsupported
;
3718 *unresolved_reloc_p
= FALSE
;
3719 value
= sgot
->output_section
->vma
;
3720 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3721 contents
, rel
->r_offset
, value
,
3725 case R_ARM_GOT_PREL
:
3726 /* Relocation is to the entry for this symbol in the
3727 global offset table. */
3729 return bfd_reloc_notsupported
;
3736 off
= h
->got
.offset
;
3737 BFD_ASSERT (off
!= (bfd_vma
) -1);
3738 dyn
= globals
->root
.dynamic_sections_created
;
3740 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3742 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3743 || (ELF_ST_VISIBILITY (h
->other
)
3744 && h
->root
.type
== bfd_link_hash_undefweak
))
3746 /* This is actually a static link, or it is a -Bsymbolic link
3747 and the symbol is defined locally. We must initialize this
3748 entry in the global offset table. Since the offset must
3749 always be a multiple of 4, we use the least significant bit
3750 to record whether we have initialized it already.
3752 When doing a dynamic link, we create a .rel(a).got relocation
3753 entry to initialize the value. This is done in the
3754 finish_dynamic_symbol routine. */
3759 /* If we are addressing a Thumb function, we need to
3760 adjust the address by one, so that attempts to
3761 call the function pointer will correctly
3762 interpret it as Thumb code. */
3763 if (sym_flags
== STT_ARM_TFUNC
)
3766 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
3771 *unresolved_reloc_p
= FALSE
;
3773 value
= sgot
->output_offset
+ off
;
3779 BFD_ASSERT (local_got_offsets
!= NULL
&&
3780 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3782 off
= local_got_offsets
[r_symndx
];
3784 /* The offset must always be a multiple of 4. We use the
3785 least significant bit to record whether we have already
3786 generated the necessary reloc. */
3791 /* If we are addressing a Thumb function, we need to
3792 adjust the address by one, so that attempts to
3793 call the function pointer will correctly
3794 interpret it as Thumb code. */
3795 if (sym_flags
== STT_ARM_TFUNC
)
3798 if (globals
->use_rel
)
3799 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
3804 Elf_Internal_Rela outrel
;
3807 srelgot
= (bfd_get_section_by_name
3808 (dynobj
, RELOC_SECTION (globals
, ".got")));
3809 BFD_ASSERT (srelgot
!= NULL
);
3811 outrel
.r_addend
= addend
+ value
;
3812 outrel
.r_offset
= (sgot
->output_section
->vma
3813 + sgot
->output_offset
3815 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3816 loc
= srelgot
->contents
;
3817 loc
+= srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
3818 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3821 local_got_offsets
[r_symndx
] |= 1;
3824 value
= sgot
->output_offset
+ off
;
3826 if (r_type
!= R_ARM_GOT32
)
3827 value
+= sgot
->output_section
->vma
;
3829 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3830 contents
, rel
->r_offset
, value
,
3833 case R_ARM_TLS_LDO32
:
3834 value
= value
- dtpoff_base (info
);
3836 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3837 contents
, rel
->r_offset
, value
,
3840 case R_ARM_TLS_LDM32
:
3844 if (globals
->sgot
== NULL
)
3847 off
= globals
->tls_ldm_got
.offset
;
3853 /* If we don't know the module number, create a relocation
3857 Elf_Internal_Rela outrel
;
3860 if (globals
->srelgot
== NULL
)
3863 outrel
.r_addend
= 0;
3864 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
3865 + globals
->sgot
->output_offset
+ off
);
3866 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
3868 if (globals
->use_rel
)
3869 bfd_put_32 (output_bfd
, outrel
.r_addend
,
3870 globals
->sgot
->contents
+ off
);
3872 loc
= globals
->srelgot
->contents
;
3873 loc
+= globals
->srelgot
->reloc_count
++ * RELOC_SIZE (globals
);
3874 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3877 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
3879 globals
->tls_ldm_got
.offset
|= 1;
3882 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
3883 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
3885 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3886 contents
, rel
->r_offset
, value
,
3890 case R_ARM_TLS_GD32
:
3891 case R_ARM_TLS_IE32
:
3897 if (globals
->sgot
== NULL
)
3904 dyn
= globals
->root
.dynamic_sections_created
;
3905 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3907 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3909 *unresolved_reloc_p
= FALSE
;
3912 off
= h
->got
.offset
;
3913 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
3917 if (local_got_offsets
== NULL
)
3919 off
= local_got_offsets
[r_symndx
];
3920 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
3923 if (tls_type
== GOT_UNKNOWN
)
3930 bfd_boolean need_relocs
= FALSE
;
3931 Elf_Internal_Rela outrel
;
3932 bfd_byte
*loc
= NULL
;
3935 /* The GOT entries have not been initialized yet. Do it
3936 now, and emit any relocations. If both an IE GOT and a
3937 GD GOT are necessary, we emit the GD first. */
3939 if ((info
->shared
|| indx
!= 0)
3941 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3942 || h
->root
.type
!= bfd_link_hash_undefweak
))
3945 if (globals
->srelgot
== NULL
)
3947 loc
= globals
->srelgot
->contents
;
3948 loc
+= globals
->srelgot
->reloc_count
* RELOC_SIZE (globals
);
3951 if (tls_type
& GOT_TLS_GD
)
3955 outrel
.r_addend
= 0;
3956 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
3957 + globals
->sgot
->output_offset
3959 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
3961 if (globals
->use_rel
)
3962 bfd_put_32 (output_bfd
, outrel
.r_addend
,
3963 globals
->sgot
->contents
+ cur_off
);
3965 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3966 globals
->srelgot
->reloc_count
++;
3967 loc
+= RELOC_SIZE (globals
);
3970 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
3971 globals
->sgot
->contents
+ cur_off
+ 4);
3974 outrel
.r_addend
= 0;
3975 outrel
.r_info
= ELF32_R_INFO (indx
,
3976 R_ARM_TLS_DTPOFF32
);
3977 outrel
.r_offset
+= 4;
3979 if (globals
->use_rel
)
3980 bfd_put_32 (output_bfd
, outrel
.r_addend
,
3981 globals
->sgot
->contents
+ cur_off
+ 4);
3984 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
3985 globals
->srelgot
->reloc_count
++;
3986 loc
+= RELOC_SIZE (globals
);
3991 /* If we are not emitting relocations for a
3992 general dynamic reference, then we must be in a
3993 static link or an executable link with the
3994 symbol binding locally. Mark it as belonging
3995 to module 1, the executable. */
3996 bfd_put_32 (output_bfd
, 1,
3997 globals
->sgot
->contents
+ cur_off
);
3998 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
3999 globals
->sgot
->contents
+ cur_off
+ 4);
4005 if (tls_type
& GOT_TLS_IE
)
4010 outrel
.r_addend
= value
- dtpoff_base (info
);
4012 outrel
.r_addend
= 0;
4013 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
4014 + globals
->sgot
->output_offset
4016 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
4018 if (globals
->use_rel
)
4019 bfd_put_32 (output_bfd
, outrel
.r_addend
,
4020 globals
->sgot
->contents
+ cur_off
);
4022 SWAP_RELOC_OUT (globals
) (output_bfd
, &outrel
, loc
);
4023 globals
->srelgot
->reloc_count
++;
4024 loc
+= RELOC_SIZE (globals
);
4027 bfd_put_32 (output_bfd
, tpoff (info
, value
),
4028 globals
->sgot
->contents
+ cur_off
);
4035 local_got_offsets
[r_symndx
] |= 1;
4038 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
4040 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
4041 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
4043 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4044 contents
, rel
->r_offset
, value
,
4048 case R_ARM_TLS_LE32
:
4051 (*_bfd_error_handler
)
4052 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
4053 input_bfd
, input_section
,
4054 (long) rel
->r_offset
, howto
->name
);
4058 value
= tpoff (info
, value
);
4060 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4061 contents
, rel
->r_offset
, value
,
4065 if (globals
->fix_v4bx
)
4067 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
4069 /* Ensure that we have a BX instruction. */
4070 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
4072 /* Preserve Rm (lowest four bits) and the condition code
4073 (highest four bits). Other bits encode MOV PC,Rm. */
4074 insn
= (insn
& 0xf000000f) | 0x01a0f000;
4076 bfd_put_32 (input_bfd
, insn
, hit_data
);
4078 return bfd_reloc_ok
;
4081 return bfd_reloc_notsupported
;
4087 uleb128_size (unsigned int i
)
4099 /* Return TRUE if the attribute has the default value (0/""). */
4101 is_default_attr (aeabi_attribute
*attr
)
4103 if ((attr
->type
& 1) && attr
->i
!= 0)
4105 if ((attr
->type
& 2) && attr
->s
&& *attr
->s
)
4111 /* Return the size of a single attribute. */
4113 eabi_attr_size(int tag
, aeabi_attribute
*attr
)
4117 if (is_default_attr (attr
))
4120 size
= uleb128_size (tag
);
4122 size
+= uleb128_size (attr
->i
);
4124 size
+= strlen ((char *)attr
->s
) + 1;
4128 /* Returns the size of the eabi object attributess section. */
4130 elf32_arm_eabi_attr_size (bfd
*abfd
)
4133 aeabi_attribute
*attr
;
4134 aeabi_attribute_list
*list
;
4137 attr
= elf32_arm_tdata (abfd
)->known_eabi_attributes
;
4138 size
= 16; /* 'A' <size> "aeabi" 0x1 <size>. */
4139 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
4140 size
+= eabi_attr_size (i
, &attr
[i
]);
4142 for (list
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
4145 size
+= eabi_attr_size (list
->tag
, &list
->attr
);
4151 write_uleb128 (bfd_byte
*p
, unsigned int val
)
4166 /* Write attribute ATTR to butter P, and return a pointer to the following
4169 write_eabi_attribute (bfd_byte
*p
, int tag
, aeabi_attribute
*attr
)
4171 /* Suppress default entries. */
4172 if (is_default_attr(attr
))
4175 p
= write_uleb128 (p
, tag
);
4177 p
= write_uleb128 (p
, attr
->i
);
4182 len
= strlen (attr
->s
) + 1;
4183 memcpy (p
, attr
->s
, len
);
4190 /* Write the contents of the eabi attributes section to p. */
4192 elf32_arm_set_eabi_attr_contents (bfd
*abfd
, bfd_byte
*contents
, bfd_vma size
)
4195 aeabi_attribute
*attr
;
4196 aeabi_attribute_list
*list
;
4201 bfd_put_32 (abfd
, size
- 1, p
);
4203 memcpy (p
, "aeabi", 6);
4206 bfd_put_32 (abfd
, size
- 11, p
);
4209 attr
= elf32_arm_tdata (abfd
)->known_eabi_attributes
;
4210 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
4211 p
= write_eabi_attribute (p
, i
, &attr
[i
]);
4213 for (list
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
4216 p
= write_eabi_attribute (p
, list
->tag
, &list
->attr
);
4219 /* Override final_link to handle EABI object attribute sections. */
4222 elf32_arm_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4225 struct bfd_link_order
*p
;
4226 asection
*attr_section
= NULL
;
4230 /* elf32_arm_merge_private_bfd_data will already have merged the
4231 object attributes. Remove the input sections from the link, and set
4232 the contents of the output secton. */
4233 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4235 if (strcmp (o
->name
, ".ARM.attributes") == 0)
4237 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
4239 asection
*input_section
;
4241 if (p
->type
!= bfd_indirect_link_order
)
4243 input_section
= p
->u
.indirect
.section
;
4244 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4245 elf_link_input_bfd ignores this section. */
4246 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
4249 size
= elf32_arm_eabi_attr_size (abfd
);
4250 bfd_set_section_size (abfd
, o
, size
);
4252 /* Skip this section later on. */
4253 o
->map_head
.link_order
= NULL
;
4256 /* Invoke the ELF linker to do all the work. */
4257 if (!bfd_elf_final_link (abfd
, info
))
4262 contents
= bfd_malloc(size
);
4263 if (contents
== NULL
)
4265 elf32_arm_set_eabi_attr_contents (abfd
, contents
, size
);
4266 bfd_set_section_contents (abfd
, attr_section
, contents
, 0, size
);
4273 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
4275 arm_add_to_rel (bfd
* abfd
,
4277 reloc_howto_type
* howto
,
4278 bfd_signed_vma increment
)
4280 bfd_signed_vma addend
;
4282 if (howto
->type
== R_ARM_THM_CALL
)
4284 int upper_insn
, lower_insn
;
4287 upper_insn
= bfd_get_16 (abfd
, address
);
4288 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
4289 upper
= upper_insn
& 0x7ff;
4290 lower
= lower_insn
& 0x7ff;
4292 addend
= (upper
<< 12) | (lower
<< 1);
4293 addend
+= increment
;
4296 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
4297 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
4299 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
4300 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
4306 contents
= bfd_get_32 (abfd
, address
);
4308 /* Get the (signed) value from the instruction. */
4309 addend
= contents
& howto
->src_mask
;
4310 if (addend
& ((howto
->src_mask
+ 1) >> 1))
4312 bfd_signed_vma mask
;
4315 mask
&= ~ howto
->src_mask
;
4319 /* Add in the increment, (which is a byte value). */
4320 switch (howto
->type
)
4323 addend
+= increment
;
4330 addend
<<= howto
->size
;
4331 addend
+= increment
;
4333 /* Should we check for overflow here ? */
4335 /* Drop any undesired bits. */
4336 addend
>>= howto
->rightshift
;
4340 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
4342 bfd_put_32 (abfd
, contents
, address
);
4346 #define IS_ARM_TLS_RELOC(R_TYPE) \
4347 ((R_TYPE) == R_ARM_TLS_GD32 \
4348 || (R_TYPE) == R_ARM_TLS_LDO32 \
4349 || (R_TYPE) == R_ARM_TLS_LDM32 \
4350 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4351 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4352 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4353 || (R_TYPE) == R_ARM_TLS_LE32 \
4354 || (R_TYPE) == R_ARM_TLS_IE32)
4356 /* Relocate an ARM ELF section. */
4358 elf32_arm_relocate_section (bfd
* output_bfd
,
4359 struct bfd_link_info
* info
,
4361 asection
* input_section
,
4362 bfd_byte
* contents
,
4363 Elf_Internal_Rela
* relocs
,
4364 Elf_Internal_Sym
* local_syms
,
4365 asection
** local_sections
)
4367 Elf_Internal_Shdr
*symtab_hdr
;
4368 struct elf_link_hash_entry
**sym_hashes
;
4369 Elf_Internal_Rela
*rel
;
4370 Elf_Internal_Rela
*relend
;
4372 struct elf32_arm_link_hash_table
* globals
;
4374 globals
= elf32_arm_hash_table (info
);
4375 if (info
->relocatable
&& !globals
->use_rel
)
4378 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
4379 sym_hashes
= elf_sym_hashes (input_bfd
);
4382 relend
= relocs
+ input_section
->reloc_count
;
4383 for (; rel
< relend
; rel
++)
4386 reloc_howto_type
* howto
;
4387 unsigned long r_symndx
;
4388 Elf_Internal_Sym
* sym
;
4390 struct elf_link_hash_entry
* h
;
4392 bfd_reloc_status_type r
;
4395 bfd_boolean unresolved_reloc
= FALSE
;
4397 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4398 r_type
= ELF32_R_TYPE (rel
->r_info
);
4399 r_type
= arm_real_reloc_type (globals
, r_type
);
4401 if ( r_type
== R_ARM_GNU_VTENTRY
4402 || r_type
== R_ARM_GNU_VTINHERIT
)
4405 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
4406 howto
= bfd_reloc
.howto
;
4408 if (info
->relocatable
&& globals
->use_rel
)
4410 /* This is a relocatable link. We don't have to change
4411 anything, unless the reloc is against a section symbol,
4412 in which case we have to adjust according to where the
4413 section symbol winds up in the output section. */
4414 if (r_symndx
< symtab_hdr
->sh_info
)
4416 sym
= local_syms
+ r_symndx
;
4417 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4419 sec
= local_sections
[r_symndx
];
4420 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
4422 (bfd_signed_vma
) (sec
->output_offset
4430 /* This is a final link. */
4435 if (r_symndx
< symtab_hdr
->sh_info
)
4437 sym
= local_syms
+ r_symndx
;
4438 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
4439 sec
= local_sections
[r_symndx
];
4440 if (globals
->use_rel
)
4442 relocation
= (sec
->output_section
->vma
4443 + sec
->output_offset
4445 if ((sec
->flags
& SEC_MERGE
)
4446 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4449 bfd_vma addend
, value
;
4451 if (howto
->rightshift
)
4453 (*_bfd_error_handler
)
4454 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4455 input_bfd
, input_section
,
4456 (long) rel
->r_offset
, howto
->name
);
4460 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4462 /* Get the (signed) value from the instruction. */
4463 addend
= value
& howto
->src_mask
;
4464 if (addend
& ((howto
->src_mask
+ 1) >> 1))
4466 bfd_signed_vma mask
;
4469 mask
&= ~ howto
->src_mask
;
4474 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4476 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4477 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
4478 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
4482 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4488 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4489 r_symndx
, symtab_hdr
, sym_hashes
,
4491 unresolved_reloc
, warned
);
4497 name
= h
->root
.root
.string
;
4500 name
= (bfd_elf_string_from_elf_section
4501 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4502 if (name
== NULL
|| *name
== '\0')
4503 name
= bfd_section_name (input_bfd
, sec
);
4507 && r_type
!= R_ARM_NONE
4509 || h
->root
.type
== bfd_link_hash_defined
4510 || h
->root
.type
== bfd_link_hash_defweak
)
4511 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
4513 (*_bfd_error_handler
)
4514 ((sym_type
== STT_TLS
4515 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4516 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4519 (long) rel
->r_offset
,
4524 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
4525 input_section
, contents
, rel
,
4526 relocation
, info
, sec
, name
,
4527 (h
? ELF_ST_TYPE (h
->type
) :
4528 ELF_ST_TYPE (sym
->st_info
)), h
,
4531 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4532 because such sections are not SEC_ALLOC and thus ld.so will
4533 not process them. */
4534 if (unresolved_reloc
4535 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4538 (*_bfd_error_handler
)
4539 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4542 (long) rel
->r_offset
,
4544 h
->root
.root
.string
);
4548 if (r
!= bfd_reloc_ok
)
4550 const char * msg
= (const char *) 0;
4554 case bfd_reloc_overflow
:
4555 /* If the overflowing reloc was to an undefined symbol,
4556 we have already printed one error message and there
4557 is no point complaining again. */
4559 h
->root
.type
!= bfd_link_hash_undefined
)
4560 && (!((*info
->callbacks
->reloc_overflow
)
4561 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4562 (bfd_vma
) 0, input_bfd
, input_section
,
4567 case bfd_reloc_undefined
:
4568 if (!((*info
->callbacks
->undefined_symbol
)
4569 (info
, name
, input_bfd
, input_section
,
4570 rel
->r_offset
, TRUE
)))
4574 case bfd_reloc_outofrange
:
4575 msg
= _("internal error: out of range error");
4578 case bfd_reloc_notsupported
:
4579 msg
= _("internal error: unsupported relocation error");
4582 case bfd_reloc_dangerous
:
4583 msg
= _("internal error: dangerous error");
4587 msg
= _("internal error: unknown error");
4591 if (!((*info
->callbacks
->warning
)
4592 (info
, msg
, name
, input_bfd
, input_section
,
4603 /* Allocate/find an object attribute. */
4604 static aeabi_attribute
*
4605 elf32_arm_new_eabi_attr (bfd
*abfd
, int tag
)
4607 aeabi_attribute
*attr
;
4608 aeabi_attribute_list
*list
;
4609 aeabi_attribute_list
*p
;
4610 aeabi_attribute_list
**lastp
;
4613 if (tag
< NUM_KNOWN_ATTRIBUTES
)
4615 /* Knwon tags are preallocated. */
4616 attr
= &elf32_arm_tdata (abfd
)->known_eabi_attributes
[tag
];
4620 /* Create a new tag. */
4621 list
= (aeabi_attribute_list
*)
4622 bfd_alloc (abfd
, sizeof (aeabi_attribute_list
));
4623 memset (list
, 0, sizeof (aeabi_attribute_list
));
4625 /* Keep the tag list in order. */
4626 lastp
= &elf32_arm_tdata (abfd
)->other_eabi_attributes
;
4627 for (p
= *lastp
; p
; p
= p
->next
)
4633 list
->next
= *lastp
;
4642 elf32_arm_get_eabi_attr_int (bfd
*abfd
, int tag
)
4644 aeabi_attribute_list
*p
;
4646 if (tag
< NUM_KNOWN_ATTRIBUTES
)
4648 /* Knwon tags are preallocated. */
4649 return elf32_arm_tdata (abfd
)->known_eabi_attributes
[tag
].i
;
4653 for (p
= elf32_arm_tdata (abfd
)->other_eabi_attributes
;
4667 elf32_arm_add_eabi_attr_int (bfd
*abfd
, int tag
, unsigned int i
)
4669 aeabi_attribute
*attr
;
4671 attr
= elf32_arm_new_eabi_attr (abfd
, tag
);
4677 attr_strdup (bfd
*abfd
, const char * s
)
4682 len
= strlen (s
) + 1;
4683 p
= (char *)bfd_alloc(abfd
, len
);
4684 return memcpy (p
, s
, len
);
4688 elf32_arm_add_eabi_attr_string (bfd
*abfd
, int tag
, const char *s
)
4690 aeabi_attribute
*attr
;
4692 attr
= elf32_arm_new_eabi_attr (abfd
, tag
);
4694 attr
->s
= attr_strdup (abfd
, s
);
4698 elf32_arm_add_eabi_attr_compat (bfd
*abfd
, unsigned int i
, const char *s
)
4700 aeabi_attribute_list
*list
;
4701 aeabi_attribute_list
*p
;
4702 aeabi_attribute_list
**lastp
;
4704 list
= (aeabi_attribute_list
*)
4705 bfd_alloc (abfd
, sizeof (aeabi_attribute_list
));
4706 memset (list
, 0, sizeof (aeabi_attribute_list
));
4707 list
->tag
= Tag_compatibility
;
4708 list
->attr
.type
= 3;
4710 list
->attr
.s
= attr_strdup (abfd
, s
);
4712 lastp
= &elf32_arm_tdata (abfd
)->other_eabi_attributes
;
4713 for (p
= *lastp
; p
; p
= p
->next
)
4716 if (p
->tag
!= Tag_compatibility
)
4718 cmp
= strcmp(s
, p
->attr
.s
);
4719 if (cmp
< 0 || (cmp
== 0 && i
< p
->attr
.i
))
4723 list
->next
= *lastp
;
4727 /* Set the right machine number. */
4730 elf32_arm_object_p (bfd
*abfd
)
4734 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
4736 if (mach
!= bfd_mach_arm_unknown
)
4737 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
4739 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
4740 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
4743 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
4748 /* Function to keep ARM specific flags in the ELF header. */
4751 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
4753 if (elf_flags_init (abfd
)
4754 && elf_elfheader (abfd
)->e_flags
!= flags
)
4756 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
4758 if (flags
& EF_ARM_INTERWORK
)
4759 (*_bfd_error_handler
)
4760 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4764 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4770 elf_elfheader (abfd
)->e_flags
= flags
;
4771 elf_flags_init (abfd
) = TRUE
;
4777 /* Copy the eabi object attribute from IBFD to OBFD. */
4779 copy_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
4781 aeabi_attribute
*in_attr
;
4782 aeabi_attribute
*out_attr
;
4783 aeabi_attribute_list
*list
;
4786 in_attr
= elf32_arm_tdata (ibfd
)->known_eabi_attributes
;
4787 out_attr
= elf32_arm_tdata (obfd
)->known_eabi_attributes
;
4788 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
4790 out_attr
->i
= in_attr
->i
;
4791 if (in_attr
->s
&& *in_attr
->s
)
4792 out_attr
->s
= attr_strdup (obfd
, in_attr
->s
);
4797 for (list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
4801 in_attr
= &list
->attr
;
4802 switch (in_attr
->type
)
4805 elf32_arm_add_eabi_attr_int (obfd
, list
->tag
, in_attr
->i
);
4808 elf32_arm_add_eabi_attr_string (obfd
, list
->tag
, in_attr
->s
);
4811 elf32_arm_add_eabi_attr_compat (obfd
, in_attr
->i
, in_attr
->s
);
4820 /* Copy backend specific data from one object module to another. */
4823 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4828 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4829 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4832 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4833 out_flags
= elf_elfheader (obfd
)->e_flags
;
4835 if (elf_flags_init (obfd
)
4836 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
4837 && in_flags
!= out_flags
)
4839 /* Cannot mix APCS26 and APCS32 code. */
4840 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
4843 /* Cannot mix float APCS and non-float APCS code. */
4844 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
4847 /* If the src and dest have different interworking flags
4848 then turn off the interworking bit. */
4849 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
4851 if (out_flags
& EF_ARM_INTERWORK
)
4853 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4856 in_flags
&= ~EF_ARM_INTERWORK
;
4859 /* Likewise for PIC, though don't warn for this case. */
4860 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
4861 in_flags
&= ~EF_ARM_PIC
;
4864 elf_elfheader (obfd
)->e_flags
= in_flags
;
4865 elf_flags_init (obfd
) = TRUE
;
4867 /* Also copy the EI_OSABI field. */
4868 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
4869 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
4871 /* Copy EABI object attributes. */
4872 copy_eabi_attributes (ibfd
, obfd
);
4877 /* Values for Tag_ABI_PCS_R9_use. */
4886 /* Values for Tag_ABI_PCS_RW_data. */
4889 AEABI_PCS_RW_data_absolute
,
4890 AEABI_PCS_RW_data_PCrel
,
4891 AEABI_PCS_RW_data_SBrel
,
4892 AEABI_PCS_RW_data_unused
4895 /* Values for Tag_ABI_enum_size. */
4901 AEABI_enum_forced_wide
4904 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
4905 are conflicting attributes. */
4907 elf32_arm_merge_eabi_attributes (bfd
*ibfd
, bfd
*obfd
)
4909 aeabi_attribute
*in_attr
;
4910 aeabi_attribute
*out_attr
;
4911 aeabi_attribute_list
*in_list
;
4912 aeabi_attribute_list
*out_list
;
4913 /* Some tags have 0 = don't care, 1 = strong requirement,
4914 2 = weak requirement. */
4915 static const int order_312
[3] = {3, 1, 2};
4918 if (!elf32_arm_tdata (ibfd
)->known_eabi_attributes
[0].i
)
4920 /* This is the first object. Copy the attributes. */
4921 copy_eabi_attributes (ibfd
, obfd
);
4925 /* Use the Tag_null value to indicate the attributes have been
4927 elf32_arm_tdata (ibfd
)->known_eabi_attributes
[0].i
= 1;
4929 in_attr
= elf32_arm_tdata (ibfd
)->known_eabi_attributes
;
4930 out_attr
= elf32_arm_tdata (obfd
)->known_eabi_attributes
;
4931 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
4932 if (in_attr
[Tag_ABI_VFP_args
].i
!= out_attr
[Tag_ABI_VFP_args
].i
)
4934 /* Ignore mismatches if teh object doesn't use floating point. */
4935 if (out_attr
[Tag_ABI_FP_number_model
].i
== 0)
4936 out_attr
[Tag_ABI_VFP_args
].i
= in_attr
[Tag_ABI_VFP_args
].i
;
4937 else if (in_attr
[Tag_ABI_FP_number_model
].i
!= 0)
4940 (_("ERROR: %B uses VFP register arguments, %B does not"),
4946 for (i
= 4; i
< NUM_KNOWN_ATTRIBUTES
; i
++)
4948 /* Merge this attribute with existing attributes. */
4951 case Tag_CPU_raw_name
:
4953 /* Use whichever has the greatest architecture requirements. */
4954 if (in_attr
[Tag_CPU_arch
].i
> out_attr
[Tag_CPU_arch
].i
)
4955 out_attr
[i
].s
= attr_strdup(obfd
, in_attr
[i
].s
);
4958 case Tag_ABI_optimization_goals
:
4959 case Tag_ABI_FP_optimization_goals
:
4960 /* Use the first value seen. */
4964 case Tag_ARM_ISA_use
:
4965 case Tag_THUMB_ISA_use
:
4969 /* ??? Do NEON and WMMX conflict? */
4970 case Tag_ABI_FP_rounding
:
4971 case Tag_ABI_FP_denormal
:
4972 case Tag_ABI_FP_exceptions
:
4973 case Tag_ABI_FP_user_exceptions
:
4974 case Tag_ABI_FP_number_model
:
4975 case Tag_ABI_align8_preserved
:
4976 case Tag_ABI_HardFP_use
:
4977 /* Use the largest value specified. */
4978 if (in_attr
[i
].i
> out_attr
[i
].i
)
4979 out_attr
[i
].i
= in_attr
[i
].i
;
4982 case Tag_CPU_arch_profile
:
4983 /* Warn if conflicting architecture profiles used. */
4984 if (out_attr
[i
].i
&& in_attr
[i
].i
&& in_attr
[i
].i
!= out_attr
[i
].i
)
4987 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
4988 ibfd
, in_attr
[i
].i
, out_attr
[i
].i
);
4992 out_attr
[i
].i
= in_attr
[i
].i
;
4994 case Tag_PCS_config
:
4995 if (out_attr
[i
].i
== 0)
4996 out_attr
[i
].i
= in_attr
[i
].i
;
4997 else if (in_attr
[i
].i
!= 0 && out_attr
[i
].i
!= 0)
4999 /* It's sometimes ok to mix different configs, so this is only
5002 (_("Warning: %B: Conflicting platform configuration"), ibfd
);
5005 case Tag_ABI_PCS_R9_use
:
5006 if (out_attr
[i
].i
!= AEABI_R9_unused
5007 && in_attr
[i
].i
!= AEABI_R9_unused
)
5010 (_("ERROR: %B: Conflicting use of R9"), ibfd
);
5013 if (out_attr
[i
].i
== AEABI_R9_unused
)
5014 out_attr
[i
].i
= in_attr
[i
].i
;
5016 case Tag_ABI_PCS_RW_data
:
5017 if (in_attr
[i
].i
== AEABI_PCS_RW_data_SBrel
5018 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_SB
5019 && out_attr
[Tag_ABI_PCS_R9_use
].i
!= AEABI_R9_unused
)
5022 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
5026 /* Use the smallest value specified. */
5027 if (in_attr
[i
].i
< out_attr
[i
].i
)
5028 out_attr
[i
].i
= in_attr
[i
].i
;
5030 case Tag_ABI_PCS_RO_data
:
5031 /* Use the smallest value specified. */
5032 if (in_attr
[i
].i
< out_attr
[i
].i
)
5033 out_attr
[i
].i
= in_attr
[i
].i
;
5035 case Tag_ABI_PCS_GOT_use
:
5036 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
5037 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
5038 out_attr
[i
].i
= in_attr
[i
].i
;
5040 case Tag_ABI_PCS_wchar_t
:
5041 if (out_attr
[i
].i
&& in_attr
[i
].i
&& out_attr
[i
].i
!= in_attr
[i
].i
)
5044 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd
);
5048 out_attr
[i
].i
= in_attr
[i
].i
;
5050 case Tag_ABI_align8_needed
:
5051 /* ??? Check against Tag_ABI_align8_preserved. */
5052 if (in_attr
[i
].i
> 2 || out_attr
[i
].i
> 2
5053 || order_312
[in_attr
[i
].i
] < order_312
[out_attr
[i
].i
])
5054 out_attr
[i
].i
= in_attr
[i
].i
;
5056 case Tag_ABI_enum_size
:
5057 if (in_attr
[i
].i
!= AEABI_enum_unused
)
5059 if (out_attr
[i
].i
== AEABI_enum_unused
5060 || out_attr
[i
].i
== AEABI_enum_forced_wide
)
5062 /* The existing object is compatible with anything.
5063 Use whatever requirements the new object has. */
5064 out_attr
[i
].i
= in_attr
[i
].i
;
5066 else if (in_attr
[i
].i
!= AEABI_enum_forced_wide
5067 && out_attr
[i
].i
!= in_attr
[i
].i
)
5070 (_("ERROR: %B: Conflicting enum sizes"), ibfd
);
5074 case Tag_ABI_VFP_args
:
5077 case Tag_ABI_WMMX_args
:
5078 if (in_attr
[i
].i
!= out_attr
[i
].i
)
5081 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
5086 default: /* All known attributes should be explicitly covered. */
5091 in_list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
5092 out_list
= elf32_arm_tdata (ibfd
)->other_eabi_attributes
;
5093 while (in_list
&& in_list
->tag
== Tag_compatibility
)
5095 in_attr
= &in_list
->attr
;
5096 if (in_attr
->i
== 0)
5098 if (in_attr
->i
== 1)
5101 (_("ERROR: %B: Must be processed by '%s' toolchain"),
5105 if (!out_list
|| out_list
->tag
!= Tag_compatibility
5106 || strcmp (in_attr
->s
, out_list
->attr
.s
) != 0)
5108 /* Add this compatibility tag to the output. */
5109 elf32_arm_add_eabi_attr_compat (obfd
, in_attr
->i
, in_attr
->s
);
5112 out_attr
= &out_list
->attr
;
5113 /* Check all the input tags with the same identifier. */
5116 if (out_list
->tag
!= Tag_compatibility
5117 || in_attr
->i
!= out_attr
->i
5118 || strcmp (in_attr
->s
, out_attr
->s
) != 0)
5121 (_("ERROR: %B: Incompatible object tag '%s':%d"),
5122 ibfd
, in_attr
->s
, in_attr
->i
);
5125 in_list
= in_list
->next
;
5126 if (in_list
->tag
!= Tag_compatibility
5127 || strcmp (in_attr
->s
, in_list
->attr
.s
) != 0)
5129 in_attr
= &in_list
->attr
;
5130 out_list
= out_list
->next
;
5132 out_attr
= &out_list
->attr
;
5135 /* Check the output doesn't have extra tags with this identifier. */
5136 if (out_list
&& out_list
->tag
== Tag_compatibility
5137 && strcmp (in_attr
->s
, out_list
->attr
.s
) == 0)
5140 (_("ERROR: %B: Incompatible object tag '%s':%d"),
5141 ibfd
, in_attr
->s
, out_list
->attr
.i
);
5146 for (; in_list
; in_list
= in_list
->next
)
5148 if ((in_list
->tag
& 128) < 64)
5151 (_("Warning: %B: Unknown EABI object attribute %d"),
5152 ibfd
, in_list
->tag
);
5160 /* Return TRUE if the two EABI versions are incompatible. */
5163 elf32_arm_versions_compatible (unsigned iver
, unsigned over
)
5165 /* v4 and v5 are the same spec before and after it was released,
5166 so allow mixing them. */
5167 if ((iver
== EF_ARM_EABI_VER4
&& over
== EF_ARM_EABI_VER5
)
5168 || (iver
== EF_ARM_EABI_VER5
&& over
== EF_ARM_EABI_VER4
))
5171 return (iver
== over
);
5174 /* Merge backend specific data from an object file to the output
5175 object file when linking. */
5178 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
5182 bfd_boolean flags_compatible
= TRUE
;
5185 /* Check if we have the same endianess. */
5186 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
5189 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5190 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5193 if (!elf32_arm_merge_eabi_attributes (ibfd
, obfd
))
5196 /* The input BFD must have had its flags initialised. */
5197 /* The following seems bogus to me -- The flags are initialized in
5198 the assembler but I don't think an elf_flags_init field is
5199 written into the object. */
5200 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5202 in_flags
= elf_elfheader (ibfd
)->e_flags
;
5203 out_flags
= elf_elfheader (obfd
)->e_flags
;
5205 if (!elf_flags_init (obfd
))
5207 /* If the input is the default architecture and had the default
5208 flags then do not bother setting the flags for the output
5209 architecture, instead allow future merges to do this. If no
5210 future merges ever set these flags then they will retain their
5211 uninitialised values, which surprise surprise, correspond
5212 to the default values. */
5213 if (bfd_get_arch_info (ibfd
)->the_default
5214 && elf_elfheader (ibfd
)->e_flags
== 0)
5217 elf_flags_init (obfd
) = TRUE
;
5218 elf_elfheader (obfd
)->e_flags
= in_flags
;
5220 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
5221 && bfd_get_arch_info (obfd
)->the_default
)
5222 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
5227 /* Determine what should happen if the input ARM architecture
5228 does not match the output ARM architecture. */
5229 if (! bfd_arm_merge_machines (ibfd
, obfd
))
5232 /* Identical flags must be compatible. */
5233 if (in_flags
== out_flags
)
5236 /* Check to see if the input BFD actually contains any sections. If
5237 not, its flags may not have been initialised either, but it
5238 cannot actually cause any incompatiblity. Do not short-circuit
5239 dynamic objects; their section list may be emptied by
5240 elf_link_add_object_symbols.
5242 Also check to see if there are no code sections in the input.
5243 In this case there is no need to check for code specific flags.
5244 XXX - do we need to worry about floating-point format compatability
5245 in data sections ? */
5246 if (!(ibfd
->flags
& DYNAMIC
))
5248 bfd_boolean null_input_bfd
= TRUE
;
5249 bfd_boolean only_data_sections
= TRUE
;
5251 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5253 /* Ignore synthetic glue sections. */
5254 if (strcmp (sec
->name
, ".glue_7")
5255 && strcmp (sec
->name
, ".glue_7t"))
5257 if ((bfd_get_section_flags (ibfd
, sec
)
5258 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5259 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
5260 only_data_sections
= FALSE
;
5262 null_input_bfd
= FALSE
;
5267 if (null_input_bfd
|| only_data_sections
)
5271 /* Complain about various flag mismatches. */
5272 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags
),
5273 EF_ARM_EABI_VERSION (out_flags
)))
5276 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
5278 (in_flags
& EF_ARM_EABIMASK
) >> 24,
5279 (out_flags
& EF_ARM_EABIMASK
) >> 24);
5283 /* Not sure what needs to be checked for EABI versions >= 1. */
5284 /* VxWorks libraries do not use these flags. */
5285 if (get_elf_backend_data (obfd
) != &elf32_arm_vxworks_bed
5286 && get_elf_backend_data (ibfd
) != &elf32_arm_vxworks_bed
5287 && EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
5289 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
5292 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
5294 in_flags
& EF_ARM_APCS_26
? 26 : 32,
5295 out_flags
& EF_ARM_APCS_26
? 26 : 32);
5296 flags_compatible
= FALSE
;
5299 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
5301 if (in_flags
& EF_ARM_APCS_FLOAT
)
5303 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
5307 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
5310 flags_compatible
= FALSE
;
5313 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
5315 if (in_flags
& EF_ARM_VFP_FLOAT
)
5317 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
5321 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
5324 flags_compatible
= FALSE
;
5327 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
5329 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
5331 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
5335 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
5338 flags_compatible
= FALSE
;
5341 #ifdef EF_ARM_SOFT_FLOAT
5342 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
5344 /* We can allow interworking between code that is VFP format
5345 layout, and uses either soft float or integer regs for
5346 passing floating point arguments and results. We already
5347 know that the APCS_FLOAT flags match; similarly for VFP
5349 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
5350 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
5352 if (in_flags
& EF_ARM_SOFT_FLOAT
)
5354 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
5358 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
5361 flags_compatible
= FALSE
;
5366 /* Interworking mismatch is only a warning. */
5367 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
5369 if (in_flags
& EF_ARM_INTERWORK
)
5372 (_("Warning: %B supports interworking, whereas %B does not"),
5378 (_("Warning: %B does not support interworking, whereas %B does"),
5384 return flags_compatible
;
5387 /* Display the flags field. */
5390 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
5392 FILE * file
= (FILE *) ptr
;
5393 unsigned long flags
;
5395 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
5397 /* Print normal ELF private data. */
5398 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5400 flags
= elf_elfheader (abfd
)->e_flags
;
5401 /* Ignore init flag - it may not be set, despite the flags field
5402 containing valid data. */
5404 /* xgettext:c-format */
5405 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
5407 switch (EF_ARM_EABI_VERSION (flags
))
5409 case EF_ARM_EABI_UNKNOWN
:
5410 /* The following flag bits are GNU extensions and not part of the
5411 official ARM ELF extended ABI. Hence they are only decoded if
5412 the EABI version is not set. */
5413 if (flags
& EF_ARM_INTERWORK
)
5414 fprintf (file
, _(" [interworking enabled]"));
5416 if (flags
& EF_ARM_APCS_26
)
5417 fprintf (file
, " [APCS-26]");
5419 fprintf (file
, " [APCS-32]");
5421 if (flags
& EF_ARM_VFP_FLOAT
)
5422 fprintf (file
, _(" [VFP float format]"));
5423 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
5424 fprintf (file
, _(" [Maverick float format]"));
5426 fprintf (file
, _(" [FPA float format]"));
5428 if (flags
& EF_ARM_APCS_FLOAT
)
5429 fprintf (file
, _(" [floats passed in float registers]"));
5431 if (flags
& EF_ARM_PIC
)
5432 fprintf (file
, _(" [position independent]"));
5434 if (flags
& EF_ARM_NEW_ABI
)
5435 fprintf (file
, _(" [new ABI]"));
5437 if (flags
& EF_ARM_OLD_ABI
)
5438 fprintf (file
, _(" [old ABI]"));
5440 if (flags
& EF_ARM_SOFT_FLOAT
)
5441 fprintf (file
, _(" [software FP]"));
5443 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
5444 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
5445 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
5446 | EF_ARM_MAVERICK_FLOAT
);
5449 case EF_ARM_EABI_VER1
:
5450 fprintf (file
, _(" [Version1 EABI]"));
5452 if (flags
& EF_ARM_SYMSARESORTED
)
5453 fprintf (file
, _(" [sorted symbol table]"));
5455 fprintf (file
, _(" [unsorted symbol table]"));
5457 flags
&= ~ EF_ARM_SYMSARESORTED
;
5460 case EF_ARM_EABI_VER2
:
5461 fprintf (file
, _(" [Version2 EABI]"));
5463 if (flags
& EF_ARM_SYMSARESORTED
)
5464 fprintf (file
, _(" [sorted symbol table]"));
5466 fprintf (file
, _(" [unsorted symbol table]"));
5468 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
5469 fprintf (file
, _(" [dynamic symbols use segment index]"));
5471 if (flags
& EF_ARM_MAPSYMSFIRST
)
5472 fprintf (file
, _(" [mapping symbols precede others]"));
5474 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
5475 | EF_ARM_MAPSYMSFIRST
);
5478 case EF_ARM_EABI_VER3
:
5479 fprintf (file
, _(" [Version3 EABI]"));
5482 case EF_ARM_EABI_VER4
:
5483 fprintf (file
, _(" [Version4 EABI]"));
5486 case EF_ARM_EABI_VER5
:
5487 fprintf (file
, _(" [Version5 EABI]"));
5489 if (flags
& EF_ARM_BE8
)
5490 fprintf (file
, _(" [BE8]"));
5492 if (flags
& EF_ARM_LE8
)
5493 fprintf (file
, _(" [LE8]"));
5495 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
5499 fprintf (file
, _(" <EABI version unrecognised>"));
5503 flags
&= ~ EF_ARM_EABIMASK
;
5505 if (flags
& EF_ARM_RELEXEC
)
5506 fprintf (file
, _(" [relocatable executable]"));
5508 if (flags
& EF_ARM_HASENTRY
)
5509 fprintf (file
, _(" [has entry point]"));
5511 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
5514 fprintf (file
, _("<Unrecognised flag bits set>"));
5522 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
5524 switch (ELF_ST_TYPE (elf_sym
->st_info
))
5527 return ELF_ST_TYPE (elf_sym
->st_info
);
5530 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
5531 This allows us to distinguish between data used by Thumb instructions
5532 and non-data (which is probably code) inside Thumb regions of an
5534 if (type
!= STT_OBJECT
&& type
!= STT_TLS
)
5535 return ELF_ST_TYPE (elf_sym
->st_info
);
5546 elf32_arm_gc_mark_hook (asection
* sec
,
5547 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
5548 Elf_Internal_Rela
* rel
,
5549 struct elf_link_hash_entry
* h
,
5550 Elf_Internal_Sym
* sym
)
5554 switch (ELF32_R_TYPE (rel
->r_info
))
5556 case R_ARM_GNU_VTINHERIT
:
5557 case R_ARM_GNU_VTENTRY
:
5561 switch (h
->root
.type
)
5563 case bfd_link_hash_defined
:
5564 case bfd_link_hash_defweak
:
5565 return h
->root
.u
.def
.section
;
5567 case bfd_link_hash_common
:
5568 return h
->root
.u
.c
.p
->section
;
5576 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5581 /* Update the got entry reference counts for the section being removed. */
5584 elf32_arm_gc_sweep_hook (bfd
* abfd
,
5585 struct bfd_link_info
* info
,
5587 const Elf_Internal_Rela
* relocs
)
5589 Elf_Internal_Shdr
*symtab_hdr
;
5590 struct elf_link_hash_entry
**sym_hashes
;
5591 bfd_signed_vma
*local_got_refcounts
;
5592 const Elf_Internal_Rela
*rel
, *relend
;
5593 struct elf32_arm_link_hash_table
* globals
;
5595 globals
= elf32_arm_hash_table (info
);
5597 elf_section_data (sec
)->local_dynrel
= NULL
;
5599 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5600 sym_hashes
= elf_sym_hashes (abfd
);
5601 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5603 relend
= relocs
+ sec
->reloc_count
;
5604 for (rel
= relocs
; rel
< relend
; rel
++)
5606 unsigned long r_symndx
;
5607 struct elf_link_hash_entry
*h
= NULL
;
5610 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5611 if (r_symndx
>= symtab_hdr
->sh_info
)
5613 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5614 while (h
->root
.type
== bfd_link_hash_indirect
5615 || h
->root
.type
== bfd_link_hash_warning
)
5616 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5619 r_type
= ELF32_R_TYPE (rel
->r_info
);
5620 r_type
= arm_real_reloc_type (globals
, r_type
);
5624 case R_ARM_GOT_PREL
:
5625 case R_ARM_TLS_GD32
:
5626 case R_ARM_TLS_IE32
:
5629 if (h
->got
.refcount
> 0)
5630 h
->got
.refcount
-= 1;
5632 else if (local_got_refcounts
!= NULL
)
5634 if (local_got_refcounts
[r_symndx
] > 0)
5635 local_got_refcounts
[r_symndx
] -= 1;
5639 case R_ARM_TLS_LDM32
:
5640 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
5650 case R_ARM_THM_CALL
:
5651 /* Should the interworking branches be here also? */
5655 struct elf32_arm_link_hash_entry
*eh
;
5656 struct elf32_arm_relocs_copied
**pp
;
5657 struct elf32_arm_relocs_copied
*p
;
5659 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5661 if (h
->plt
.refcount
> 0)
5663 h
->plt
.refcount
-= 1;
5664 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_CALL
)
5665 eh
->plt_thumb_refcount
--;
5668 if (r_type
== R_ARM_ABS32
5669 || r_type
== R_ARM_REL32
)
5671 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
5673 if (p
->section
== sec
)
5676 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
5694 /* Look through the relocs for a section during the first phase. */
5697 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5698 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5700 Elf_Internal_Shdr
*symtab_hdr
;
5701 struct elf_link_hash_entry
**sym_hashes
;
5702 struct elf_link_hash_entry
**sym_hashes_end
;
5703 const Elf_Internal_Rela
*rel
;
5704 const Elf_Internal_Rela
*rel_end
;
5707 bfd_vma
*local_got_offsets
;
5708 struct elf32_arm_link_hash_table
*htab
;
5710 if (info
->relocatable
)
5713 htab
= elf32_arm_hash_table (info
);
5716 /* Create dynamic sections for relocatable executables so that we can
5717 copy relocations. */
5718 if (htab
->root
.is_relocatable_executable
5719 && ! htab
->root
.dynamic_sections_created
)
5721 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
5725 dynobj
= elf_hash_table (info
)->dynobj
;
5726 local_got_offsets
= elf_local_got_offsets (abfd
);
5728 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5729 sym_hashes
= elf_sym_hashes (abfd
);
5730 sym_hashes_end
= sym_hashes
5731 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
5733 if (!elf_bad_symtab (abfd
))
5734 sym_hashes_end
-= symtab_hdr
->sh_info
;
5736 rel_end
= relocs
+ sec
->reloc_count
;
5737 for (rel
= relocs
; rel
< rel_end
; rel
++)
5739 struct elf_link_hash_entry
*h
;
5740 struct elf32_arm_link_hash_entry
*eh
;
5741 unsigned long r_symndx
;
5744 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5745 r_type
= ELF32_R_TYPE (rel
->r_info
);
5746 r_type
= arm_real_reloc_type (htab
, r_type
);
5748 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
5750 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
5755 if (r_symndx
< symtab_hdr
->sh_info
)
5759 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5760 while (h
->root
.type
== bfd_link_hash_indirect
5761 || h
->root
.type
== bfd_link_hash_warning
)
5762 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5765 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5770 case R_ARM_GOT_PREL
:
5771 case R_ARM_TLS_GD32
:
5772 case R_ARM_TLS_IE32
:
5773 /* This symbol requires a global offset table entry. */
5775 int tls_type
, old_tls_type
;
5779 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
5780 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
5781 default: tls_type
= GOT_NORMAL
; break;
5787 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
5791 bfd_signed_vma
*local_got_refcounts
;
5793 /* This is a global offset table entry for a local symbol. */
5794 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5795 if (local_got_refcounts
== NULL
)
5799 size
= symtab_hdr
->sh_info
;
5800 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
5801 local_got_refcounts
= bfd_zalloc (abfd
, size
);
5802 if (local_got_refcounts
== NULL
)
5804 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
5805 elf32_arm_local_got_tls_type (abfd
)
5806 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
5808 local_got_refcounts
[r_symndx
] += 1;
5809 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
5812 /* We will already have issued an error message if there is a
5813 TLS / non-TLS mismatch, based on the symbol type. We don't
5814 support any linker relaxations. So just combine any TLS
5816 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
5817 && tls_type
!= GOT_NORMAL
)
5818 tls_type
|= old_tls_type
;
5820 if (old_tls_type
!= tls_type
)
5823 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
5825 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
5830 case R_ARM_TLS_LDM32
:
5831 if (r_type
== R_ARM_TLS_LDM32
)
5832 htab
->tls_ldm_got
.refcount
++;
5835 case R_ARM_GOTOFF32
:
5837 if (htab
->sgot
== NULL
)
5839 if (htab
->root
.dynobj
== NULL
)
5840 htab
->root
.dynobj
= abfd
;
5841 if (!create_got_section (htab
->root
.dynobj
, info
))
5847 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
5848 ldr __GOTT_INDEX__ offsets. */
5849 if (!htab
->vxworks_p
)
5860 case R_ARM_THM_CALL
:
5861 /* Should the interworking branches be listed here? */
5864 /* If this reloc is in a read-only section, we might
5865 need a copy reloc. We can't check reliably at this
5866 stage whether the section is read-only, as input
5867 sections have not yet been mapped to output sections.
5868 Tentatively set the flag for now, and correct in
5869 adjust_dynamic_symbol. */
5873 /* We may need a .plt entry if the function this reloc
5874 refers to is in a different object. We can't tell for
5875 sure yet, because something later might force the
5877 if (r_type
== R_ARM_PC24
5878 || r_type
== R_ARM_CALL
5879 || r_type
== R_ARM_JUMP24
5880 || r_type
== R_ARM_PREL31
5881 || r_type
== R_ARM_PLT32
5882 || r_type
== R_ARM_THM_CALL
)
5885 /* If we create a PLT entry, this relocation will reference
5886 it, even if it's an ABS32 relocation. */
5887 h
->plt
.refcount
+= 1;
5889 if (r_type
== R_ARM_THM_CALL
)
5890 eh
->plt_thumb_refcount
+= 1;
5893 /* If we are creating a shared library or relocatable executable,
5894 and this is a reloc against a global symbol, or a non PC
5895 relative reloc against a local symbol, then we need to copy
5896 the reloc into the shared library. However, if we are linking
5897 with -Bsymbolic, we do not need to copy a reloc against a
5898 global symbol which is defined in an object we are
5899 including in the link (i.e., DEF_REGULAR is set). At
5900 this point we have not seen all the input files, so it is
5901 possible that DEF_REGULAR is not set now but will be set
5902 later (it is never cleared). We account for that
5903 possibility below by storing information in the
5904 relocs_copied field of the hash table entry. */
5905 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
5906 && (sec
->flags
& SEC_ALLOC
) != 0
5907 && (r_type
== R_ARM_ABS32
5908 || (h
!= NULL
&& ! h
->needs_plt
5909 && (! info
->symbolic
|| ! h
->def_regular
))))
5911 struct elf32_arm_relocs_copied
*p
, **head
;
5913 /* When creating a shared object, we must copy these
5914 reloc types into the output file. We create a reloc
5915 section in dynobj and make room for this reloc. */
5920 name
= (bfd_elf_string_from_elf_section
5922 elf_elfheader (abfd
)->e_shstrndx
,
5923 elf_section_data (sec
)->rel_hdr
.sh_name
));
5927 BFD_ASSERT (reloc_section_p (htab
, name
, sec
));
5929 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5934 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
5935 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
5936 if ((sec
->flags
& SEC_ALLOC
) != 0
5937 /* BPABI objects never have dynamic
5938 relocations mapped. */
5939 && !htab
->symbian_p
)
5940 flags
|= SEC_ALLOC
| SEC_LOAD
;
5941 sreloc
= bfd_make_section_with_flags (dynobj
,
5945 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
5949 elf_section_data (sec
)->sreloc
= sreloc
;
5952 /* If this is a global symbol, we count the number of
5953 relocations we need for this symbol. */
5956 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
5960 /* Track dynamic relocs needed for local syms too.
5961 We really need local syms available to do this
5967 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
5972 vpp
= &elf_section_data (s
)->local_dynrel
;
5973 head
= (struct elf32_arm_relocs_copied
**) vpp
;
5977 if (p
== NULL
|| p
->section
!= sec
)
5979 bfd_size_type amt
= sizeof *p
;
5981 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
5991 if (r_type
== R_ARM_REL32
)
5997 /* This relocation describes the C++ object vtable hierarchy.
5998 Reconstruct it for later use during GC. */
5999 case R_ARM_GNU_VTINHERIT
:
6000 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6004 /* This relocation describes which C++ vtable entries are actually
6005 used. Record for later use during GC. */
6006 case R_ARM_GNU_VTENTRY
:
6007 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
6016 /* Treat mapping symbols as special target symbols. */
6019 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
6021 return bfd_is_arm_mapping_symbol_name (sym
->name
);
6024 /* This is a copy of elf_find_function() from elf.c except that
6025 ARM mapping symbols are ignored when looking for function names
6026 and STT_ARM_TFUNC is considered to a function type. */
6029 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
6033 const char ** filename_ptr
,
6034 const char ** functionname_ptr
)
6036 const char * filename
= NULL
;
6037 asymbol
* func
= NULL
;
6038 bfd_vma low_func
= 0;
6041 for (p
= symbols
; *p
!= NULL
; p
++)
6045 q
= (elf_symbol_type
*) *p
;
6047 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
6052 filename
= bfd_asymbol_name (&q
->symbol
);
6057 /* Skip $a and $t symbols. */
6058 if ((q
->symbol
.flags
& BSF_LOCAL
)
6059 && bfd_is_arm_mapping_symbol_name (q
->symbol
.name
))
6062 if (bfd_get_section (&q
->symbol
) == section
6063 && q
->symbol
.value
>= low_func
6064 && q
->symbol
.value
<= offset
)
6066 func
= (asymbol
*) q
;
6067 low_func
= q
->symbol
.value
;
6077 *filename_ptr
= filename
;
6078 if (functionname_ptr
)
6079 *functionname_ptr
= bfd_asymbol_name (func
);
6085 /* Find the nearest line to a particular section and offset, for error
6086 reporting. This code is a duplicate of the code in elf.c, except
6087 that it uses arm_elf_find_function. */
6090 elf32_arm_find_nearest_line (bfd
* abfd
,
6094 const char ** filename_ptr
,
6095 const char ** functionname_ptr
,
6096 unsigned int * line_ptr
)
6098 bfd_boolean found
= FALSE
;
6100 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
6102 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
6103 filename_ptr
, functionname_ptr
,
6105 & elf_tdata (abfd
)->dwarf2_find_line_info
))
6107 if (!*functionname_ptr
)
6108 arm_elf_find_function (abfd
, section
, symbols
, offset
,
6109 *filename_ptr
? NULL
: filename_ptr
,
6115 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
6116 & found
, filename_ptr
,
6117 functionname_ptr
, line_ptr
,
6118 & elf_tdata (abfd
)->line_info
))
6121 if (found
&& (*functionname_ptr
|| *line_ptr
))
6124 if (symbols
== NULL
)
6127 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
6128 filename_ptr
, functionname_ptr
))
6136 elf32_arm_find_inliner_info (bfd
* abfd
,
6137 const char ** filename_ptr
,
6138 const char ** functionname_ptr
,
6139 unsigned int * line_ptr
)
6142 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
6143 functionname_ptr
, line_ptr
,
6144 & elf_tdata (abfd
)->dwarf2_find_line_info
);
6148 /* Adjust a symbol defined by a dynamic object and referenced by a
6149 regular object. The current definition is in some section of the
6150 dynamic object, but we're not including those sections. We have to
6151 change the definition to something the rest of the link can
6155 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
6156 struct elf_link_hash_entry
* h
)
6160 unsigned int power_of_two
;
6161 struct elf32_arm_link_hash_entry
* eh
;
6162 struct elf32_arm_link_hash_table
*globals
;
6164 globals
= elf32_arm_hash_table (info
);
6165 dynobj
= elf_hash_table (info
)->dynobj
;
6167 /* Make sure we know what is going on here. */
6168 BFD_ASSERT (dynobj
!= NULL
6170 || h
->u
.weakdef
!= NULL
6173 && !h
->def_regular
)));
6175 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6177 /* If this is a function, put it in the procedure linkage table. We
6178 will fill in the contents of the procedure linkage table later,
6179 when we know the address of the .got section. */
6180 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
6183 if (h
->plt
.refcount
<= 0
6184 || SYMBOL_CALLS_LOCAL (info
, h
)
6185 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
6186 && h
->root
.type
== bfd_link_hash_undefweak
))
6188 /* This case can occur if we saw a PLT32 reloc in an input
6189 file, but the symbol was never referred to by a dynamic
6190 object, or if all references were garbage collected. In
6191 such a case, we don't actually need to build a procedure
6192 linkage table, and we can just do a PC24 reloc instead. */
6193 h
->plt
.offset
= (bfd_vma
) -1;
6194 eh
->plt_thumb_refcount
= 0;
6202 /* It's possible that we incorrectly decided a .plt reloc was
6203 needed for an R_ARM_PC24 or similar reloc to a non-function sym
6204 in check_relocs. We can't decide accurately between function
6205 and non-function syms in check-relocs; Objects loaded later in
6206 the link may change h->type. So fix it now. */
6207 h
->plt
.offset
= (bfd_vma
) -1;
6208 eh
->plt_thumb_refcount
= 0;
6211 /* If this is a weak symbol, and there is a real definition, the
6212 processor independent code will have arranged for us to see the
6213 real definition first, and we can just use the same value. */
6214 if (h
->u
.weakdef
!= NULL
)
6216 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
6217 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
6218 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
6219 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
6223 /* If there are no non-GOT references, we do not need a copy
6225 if (!h
->non_got_ref
)
6228 /* This is a reference to a symbol defined by a dynamic object which
6229 is not a function. */
6231 /* If we are creating a shared library, we must presume that the
6232 only references to the symbol are via the global offset table.
6233 For such cases we need not do anything here; the relocations will
6234 be handled correctly by relocate_section. Relocatable executables
6235 can reference data in shared objects directly, so we don't need to
6236 do anything here. */
6237 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
6242 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
6243 h
->root
.root
.string
);
6247 /* We must allocate the symbol in our .dynbss section, which will
6248 become part of the .bss section of the executable. There will be
6249 an entry for this symbol in the .dynsym section. The dynamic
6250 object will contain position independent code, so all references
6251 from the dynamic object to this symbol will go through the global
6252 offset table. The dynamic linker will use the .dynsym entry to
6253 determine the address it must put in the global offset table, so
6254 both the dynamic object and the regular object will refer to the
6255 same memory location for the variable. */
6256 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
6257 BFD_ASSERT (s
!= NULL
);
6259 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
6260 copy the initial value out of the dynamic object and into the
6261 runtime process image. We need to remember the offset into the
6262 .rel(a).bss section we are going to use. */
6263 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
6267 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (globals
, ".bss"));
6268 BFD_ASSERT (srel
!= NULL
);
6269 srel
->size
+= RELOC_SIZE (globals
);
6273 /* We need to figure out the alignment required for this symbol. I
6274 have no idea how ELF linkers handle this. */
6275 power_of_two
= bfd_log2 (h
->size
);
6276 if (power_of_two
> 3)
6279 /* Apply the required alignment. */
6280 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
6281 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
6283 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
6287 /* Define the symbol as being at this point in the section. */
6288 h
->root
.u
.def
.section
= s
;
6289 h
->root
.u
.def
.value
= s
->size
;
6291 /* Increment the section size to make room for the symbol. */
6297 /* Allocate space in .plt, .got and associated reloc sections for
6301 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
6303 struct bfd_link_info
*info
;
6304 struct elf32_arm_link_hash_table
*htab
;
6305 struct elf32_arm_link_hash_entry
*eh
;
6306 struct elf32_arm_relocs_copied
*p
;
6308 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6310 if (h
->root
.type
== bfd_link_hash_indirect
)
6313 if (h
->root
.type
== bfd_link_hash_warning
)
6314 /* When warning symbols are created, they **replace** the "real"
6315 entry in the hash table, thus we never get to see the real
6316 symbol in a hash traversal. So look at it now. */
6317 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6319 info
= (struct bfd_link_info
*) inf
;
6320 htab
= elf32_arm_hash_table (info
);
6322 if (htab
->root
.dynamic_sections_created
6323 && h
->plt
.refcount
> 0)
6325 /* Make sure this symbol is output as a dynamic symbol.
6326 Undefined weak syms won't yet be marked as dynamic. */
6327 if (h
->dynindx
== -1
6328 && !h
->forced_local
)
6330 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6335 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
6337 asection
*s
= htab
->splt
;
6339 /* If this is the first .plt entry, make room for the special
6342 s
->size
+= htab
->plt_header_size
;
6344 h
->plt
.offset
= s
->size
;
6346 /* If we will insert a Thumb trampoline before this PLT, leave room
6348 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
6350 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
6351 s
->size
+= PLT_THUMB_STUB_SIZE
;
6354 /* If this symbol is not defined in a regular file, and we are
6355 not generating a shared library, then set the symbol to this
6356 location in the .plt. This is required to make function
6357 pointers compare as equal between the normal executable and
6358 the shared library. */
6362 h
->root
.u
.def
.section
= s
;
6363 h
->root
.u
.def
.value
= h
->plt
.offset
;
6365 /* Make sure the function is not marked as Thumb, in case
6366 it is the target of an ABS32 relocation, which will
6367 point to the PLT entry. */
6368 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
6369 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
6372 /* Make room for this entry. */
6373 s
->size
+= htab
->plt_entry_size
;
6375 if (!htab
->symbian_p
)
6377 /* We also need to make an entry in the .got.plt section, which
6378 will be placed in the .got section by the linker script. */
6379 eh
->plt_got_offset
= htab
->sgotplt
->size
;
6380 htab
->sgotplt
->size
+= 4;
6383 /* We also need to make an entry in the .rel(a).plt section. */
6384 htab
->srelplt
->size
+= RELOC_SIZE (htab
);
6386 /* VxWorks executables have a second set of relocations for
6387 each PLT entry. They go in a separate relocation section,
6388 which is processed by the kernel loader. */
6389 if (htab
->vxworks_p
&& !info
->shared
)
6391 /* There is a relocation for the initial PLT entry:
6392 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
6393 if (h
->plt
.offset
== htab
->plt_header_size
)
6394 htab
->srelplt2
->size
+= RELOC_SIZE (htab
);
6396 /* There are two extra relocations for each subsequent
6397 PLT entry: an R_ARM_32 relocation for the GOT entry,
6398 and an R_ARM_32 relocation for the PLT entry. */
6399 htab
->srelplt2
->size
+= RELOC_SIZE (htab
) * 2;
6404 h
->plt
.offset
= (bfd_vma
) -1;
6410 h
->plt
.offset
= (bfd_vma
) -1;
6414 if (h
->got
.refcount
> 0)
6418 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
6421 /* Make sure this symbol is output as a dynamic symbol.
6422 Undefined weak syms won't yet be marked as dynamic. */
6423 if (h
->dynindx
== -1
6424 && !h
->forced_local
)
6426 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6430 if (!htab
->symbian_p
)
6433 h
->got
.offset
= s
->size
;
6435 if (tls_type
== GOT_UNKNOWN
)
6438 if (tls_type
== GOT_NORMAL
)
6439 /* Non-TLS symbols need one GOT slot. */
6443 if (tls_type
& GOT_TLS_GD
)
6444 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
6446 if (tls_type
& GOT_TLS_IE
)
6447 /* R_ARM_TLS_IE32 needs one GOT slot. */
6451 dyn
= htab
->root
.dynamic_sections_created
;
6454 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
6456 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
6459 if (tls_type
!= GOT_NORMAL
6460 && (info
->shared
|| indx
!= 0)
6461 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6462 || h
->root
.type
!= bfd_link_hash_undefweak
))
6464 if (tls_type
& GOT_TLS_IE
)
6465 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
6467 if (tls_type
& GOT_TLS_GD
)
6468 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
6470 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
6471 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
6473 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
6474 || h
->root
.type
!= bfd_link_hash_undefweak
)
6476 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
6477 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
6481 h
->got
.offset
= (bfd_vma
) -1;
6483 if (eh
->relocs_copied
== NULL
)
6486 /* In the shared -Bsymbolic case, discard space allocated for
6487 dynamic pc-relative relocs against symbols which turn out to be
6488 defined in regular objects. For the normal shared case, discard
6489 space for pc-relative relocs that have become local due to symbol
6490 visibility changes. */
6492 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
6494 /* The only reloc that uses pc_count is R_ARM_REL32, which will
6495 appear on something like ".long foo - .". We want calls to
6496 protected symbols to resolve directly to the function rather
6497 than going via the plt. If people want function pointer
6498 comparisons to work as expected then they should avoid
6499 writing assembly like ".long foo - .". */
6500 if (SYMBOL_CALLS_LOCAL (info
, h
))
6502 struct elf32_arm_relocs_copied
**pp
;
6504 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
6506 p
->count
-= p
->pc_count
;
6515 /* Also discard relocs on undefined weak syms with non-default
6517 if (eh
->relocs_copied
!= NULL
6518 && h
->root
.type
== bfd_link_hash_undefweak
)
6520 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
6521 eh
->relocs_copied
= NULL
;
6523 /* Make sure undefined weak symbols are output as a dynamic
6525 else if (h
->dynindx
== -1
6526 && !h
->forced_local
)
6528 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6533 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
6534 && h
->root
.type
== bfd_link_hash_new
)
6536 /* Output absolute symbols so that we can create relocations
6537 against them. For normal symbols we output a relocation
6538 against the section that contains them. */
6539 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6546 /* For the non-shared case, discard space for relocs against
6547 symbols which turn out to need copy relocs or are not
6553 || (htab
->root
.dynamic_sections_created
6554 && (h
->root
.type
== bfd_link_hash_undefweak
6555 || h
->root
.type
== bfd_link_hash_undefined
))))
6557 /* Make sure this symbol is output as a dynamic symbol.
6558 Undefined weak syms won't yet be marked as dynamic. */
6559 if (h
->dynindx
== -1
6560 && !h
->forced_local
)
6562 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6566 /* If that succeeded, we know we'll be keeping all the
6568 if (h
->dynindx
!= -1)
6572 eh
->relocs_copied
= NULL
;
6577 /* Finally, allocate space. */
6578 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
6580 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
6581 sreloc
->size
+= p
->count
* RELOC_SIZE (htab
);
6587 /* Find any dynamic relocs that apply to read-only sections. */
6590 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
6592 struct elf32_arm_link_hash_entry
*eh
;
6593 struct elf32_arm_relocs_copied
*p
;
6595 if (h
->root
.type
== bfd_link_hash_warning
)
6596 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6598 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6599 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
6601 asection
*s
= p
->section
;
6603 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6605 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6607 info
->flags
|= DF_TEXTREL
;
6609 /* Not an error, just cut short the traversal. */
6616 /* Set the sizes of the dynamic sections. */
6619 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
6620 struct bfd_link_info
* info
)
6627 struct elf32_arm_link_hash_table
*htab
;
6629 htab
= elf32_arm_hash_table (info
);
6630 dynobj
= elf_hash_table (info
)->dynobj
;
6631 BFD_ASSERT (dynobj
!= NULL
);
6632 check_use_blx (htab
);
6634 if (elf_hash_table (info
)->dynamic_sections_created
)
6636 /* Set the contents of the .interp section to the interpreter. */
6637 if (info
->executable
)
6639 s
= bfd_get_section_by_name (dynobj
, ".interp");
6640 BFD_ASSERT (s
!= NULL
);
6641 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
6642 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
6646 /* Set up .got offsets for local syms, and space for local dynamic
6648 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6650 bfd_signed_vma
*local_got
;
6651 bfd_signed_vma
*end_local_got
;
6652 char *local_tls_type
;
6653 bfd_size_type locsymcount
;
6654 Elf_Internal_Shdr
*symtab_hdr
;
6657 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
6660 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
6662 struct elf32_arm_relocs_copied
*p
;
6664 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
6666 if (!bfd_is_abs_section (p
->section
)
6667 && bfd_is_abs_section (p
->section
->output_section
))
6669 /* Input section has been discarded, either because
6670 it is a copy of a linkonce section or due to
6671 linker script /DISCARD/, so we'll be discarding
6674 else if (p
->count
!= 0)
6676 srel
= elf_section_data (p
->section
)->sreloc
;
6677 srel
->size
+= p
->count
* RELOC_SIZE (htab
);
6678 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
6679 info
->flags
|= DF_TEXTREL
;
6684 local_got
= elf_local_got_refcounts (ibfd
);
6688 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6689 locsymcount
= symtab_hdr
->sh_info
;
6690 end_local_got
= local_got
+ locsymcount
;
6691 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
6693 srel
= htab
->srelgot
;
6694 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
6698 *local_got
= s
->size
;
6699 if (*local_tls_type
& GOT_TLS_GD
)
6700 /* TLS_GD relocs need an 8-byte structure in the GOT. */
6702 if (*local_tls_type
& GOT_TLS_IE
)
6704 if (*local_tls_type
== GOT_NORMAL
)
6707 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
6708 srel
->size
+= RELOC_SIZE (htab
);
6711 *local_got
= (bfd_vma
) -1;
6715 if (htab
->tls_ldm_got
.refcount
> 0)
6717 /* Allocate two GOT entries and one dynamic relocation (if necessary)
6718 for R_ARM_TLS_LDM32 relocations. */
6719 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
6720 htab
->sgot
->size
+= 8;
6722 htab
->srelgot
->size
+= RELOC_SIZE (htab
);
6725 htab
->tls_ldm_got
.offset
= -1;
6727 /* Allocate global sym .plt and .got entries, and space for global
6728 sym dynamic relocs. */
6729 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
6731 /* The check_relocs and adjust_dynamic_symbol entry points have
6732 determined the sizes of the various dynamic sections. Allocate
6736 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
6740 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
6743 /* It's OK to base decisions on the section name, because none
6744 of the dynobj section names depend upon the input files. */
6745 name
= bfd_get_section_name (dynobj
, s
);
6747 if (strcmp (name
, ".plt") == 0)
6749 /* Remember whether there is a PLT. */
6752 else if (strncmp (name
, ".rel", 4) == 0)
6756 /* Remember whether there are any reloc sections other
6757 than .rel(a).plt and .rela.plt.unloaded. */
6758 if (s
!= htab
->srelplt
&& s
!= htab
->srelplt2
)
6761 /* We use the reloc_count field as a counter if we need
6762 to copy relocs into the output file. */
6766 else if (strncmp (name
, ".got", 4) != 0
6767 && strcmp (name
, ".dynbss") != 0)
6769 /* It's not one of our sections, so don't allocate space. */
6775 /* If we don't need this section, strip it from the
6776 output file. This is mostly to handle .rel(a).bss and
6777 .rel(a).plt. We must create both sections in
6778 create_dynamic_sections, because they must be created
6779 before the linker maps input sections to output
6780 sections. The linker does that before
6781 adjust_dynamic_symbol is called, and it is that
6782 function which decides whether anything needs to go
6783 into these sections. */
6784 s
->flags
|= SEC_EXCLUDE
;
6788 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
6791 /* Allocate memory for the section contents. */
6792 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
6793 if (s
->contents
== NULL
)
6797 if (elf_hash_table (info
)->dynamic_sections_created
)
6799 /* Add some entries to the .dynamic section. We fill in the
6800 values later, in elf32_arm_finish_dynamic_sections, but we
6801 must add the entries now so that we get the correct size for
6802 the .dynamic section. The DT_DEBUG entry is filled in by the
6803 dynamic linker and used by the debugger. */
6804 #define add_dynamic_entry(TAG, VAL) \
6805 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6807 if (info
->executable
)
6809 if (!add_dynamic_entry (DT_DEBUG
, 0))
6815 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
6816 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
6817 || !add_dynamic_entry (DT_PLTREL
,
6818 htab
->use_rel
? DT_REL
: DT_RELA
)
6819 || !add_dynamic_entry (DT_JMPREL
, 0))
6827 if (!add_dynamic_entry (DT_REL
, 0)
6828 || !add_dynamic_entry (DT_RELSZ
, 0)
6829 || !add_dynamic_entry (DT_RELENT
, RELOC_SIZE (htab
)))
6834 if (!add_dynamic_entry (DT_RELA
, 0)
6835 || !add_dynamic_entry (DT_RELASZ
, 0)
6836 || !add_dynamic_entry (DT_RELAENT
, RELOC_SIZE (htab
)))
6841 /* If any dynamic relocs apply to a read-only section,
6842 then we need a DT_TEXTREL entry. */
6843 if ((info
->flags
& DF_TEXTREL
) == 0)
6844 elf_link_hash_traverse (&htab
->root
, elf32_arm_readonly_dynrelocs
,
6847 if ((info
->flags
& DF_TEXTREL
) != 0)
6849 if (!add_dynamic_entry (DT_TEXTREL
, 0))
6853 #undef add_dynamic_entry
6858 /* Finish up dynamic symbol handling. We set the contents of various
6859 dynamic sections here. */
6862 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
6863 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
6866 struct elf32_arm_link_hash_table
*htab
;
6867 struct elf32_arm_link_hash_entry
*eh
;
6869 dynobj
= elf_hash_table (info
)->dynobj
;
6870 htab
= elf32_arm_hash_table (info
);
6871 eh
= (struct elf32_arm_link_hash_entry
*) h
;
6873 if (h
->plt
.offset
!= (bfd_vma
) -1)
6879 Elf_Internal_Rela rel
;
6881 /* This symbol has an entry in the procedure linkage table. Set
6884 BFD_ASSERT (h
->dynindx
!= -1);
6886 splt
= bfd_get_section_by_name (dynobj
, ".plt");
6887 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".plt"));
6888 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
6890 /* Fill in the entry in the procedure linkage table. */
6891 if (htab
->symbian_p
)
6894 for (i
= 0; i
< htab
->plt_entry_size
/ 4; ++i
)
6895 bfd_put_32 (output_bfd
,
6896 elf32_arm_symbian_plt_entry
[i
],
6897 splt
->contents
+ h
->plt
.offset
+ 4 * i
);
6899 /* Fill in the entry in the .rel.plt section. */
6900 rel
.r_offset
= (splt
->output_section
->vma
6901 + splt
->output_offset
6902 + h
->plt
.offset
+ 4 * (i
- 1));
6903 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
6905 /* Get the index in the procedure linkage table which
6906 corresponds to this symbol. This is the index of this symbol
6907 in all the symbols for which we are making plt entries. The
6908 first entry in the procedure linkage table is reserved. */
6909 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
6910 / htab
->plt_entry_size
);
6914 bfd_vma got_offset
, got_address
, plt_address
;
6915 bfd_vma got_displacement
;
6918 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
6919 BFD_ASSERT (sgot
!= NULL
);
6921 /* Get the offset into the .got.plt table of the entry that
6922 corresponds to this function. */
6923 got_offset
= eh
->plt_got_offset
;
6925 /* Get the index in the procedure linkage table which
6926 corresponds to this symbol. This is the index of this symbol
6927 in all the symbols for which we are making plt entries. The
6928 first three entries in .got.plt are reserved; after that
6929 symbols appear in the same order as in .plt. */
6930 plt_index
= (got_offset
- 12) / 4;
6932 /* Calculate the address of the GOT entry. */
6933 got_address
= (sgot
->output_section
->vma
6934 + sgot
->output_offset
6937 /* ...and the address of the PLT entry. */
6938 plt_address
= (splt
->output_section
->vma
6939 + splt
->output_offset
6942 if (htab
->vxworks_p
&& info
->shared
)
6947 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++)
6949 val
= elf32_arm_vxworks_shared_plt_entry
[i
];
6951 val
|= got_address
- sgot
->output_section
->vma
;
6953 val
|= plt_index
* RELOC_SIZE (htab
);
6954 bfd_put_32 (output_bfd
, val
,
6955 htab
->splt
->contents
+ h
->plt
.offset
+ i
* 4);
6958 else if (htab
->vxworks_p
)
6963 for (i
= 0; i
!= htab
->plt_entry_size
/ 4; i
++)
6965 val
= elf32_arm_vxworks_exec_plt_entry
[i
];
6969 val
|= 0xffffff & -((h
->plt
.offset
+ i
* 4 + 8) >> 2);
6971 val
|= plt_index
* RELOC_SIZE (htab
);
6972 bfd_put_32 (output_bfd
, val
,
6973 htab
->splt
->contents
+ h
->plt
.offset
+ i
* 4);
6976 loc
= (htab
->srelplt2
->contents
6977 + (plt_index
* 2 + 1) * RELOC_SIZE (htab
));
6979 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
6980 referencing the GOT for this PLT entry. */
6981 rel
.r_offset
= plt_address
+ 8;
6982 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
6983 rel
.r_addend
= got_offset
;
6984 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
6985 loc
+= RELOC_SIZE (htab
);
6987 /* Create the R_ARM_ABS32 relocation referencing the
6988 beginning of the PLT for this GOT entry. */
6989 rel
.r_offset
= got_address
;
6990 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
6992 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
6996 /* Calculate the displacement between the PLT slot and the
6997 entry in the GOT. The eight-byte offset accounts for the
6998 value produced by adding to pc in the first instruction
7000 got_displacement
= got_address
- (plt_address
+ 8);
7002 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
7004 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
7006 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[0],
7007 splt
->contents
+ h
->plt
.offset
- 4);
7008 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[1],
7009 splt
->contents
+ h
->plt
.offset
- 2);
7012 bfd_put_32 (output_bfd
,
7013 elf32_arm_plt_entry
[0]
7014 | ((got_displacement
& 0x0ff00000) >> 20),
7015 splt
->contents
+ h
->plt
.offset
+ 0);
7016 bfd_put_32 (output_bfd
,
7017 elf32_arm_plt_entry
[1]
7018 | ((got_displacement
& 0x000ff000) >> 12),
7019 splt
->contents
+ h
->plt
.offset
+ 4);
7020 bfd_put_32 (output_bfd
,
7021 elf32_arm_plt_entry
[2]
7022 | (got_displacement
& 0x00000fff),
7023 splt
->contents
+ h
->plt
.offset
+ 8);
7024 #ifdef FOUR_WORD_PLT
7025 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
7026 splt
->contents
+ h
->plt
.offset
+ 12);
7030 /* Fill in the entry in the global offset table. */
7031 bfd_put_32 (output_bfd
,
7032 (splt
->output_section
->vma
7033 + splt
->output_offset
),
7034 sgot
->contents
+ got_offset
);
7036 /* Fill in the entry in the .rel(a).plt section. */
7038 rel
.r_offset
= got_address
;
7039 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
7042 loc
= srel
->contents
+ plt_index
* RELOC_SIZE (htab
);
7043 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7045 if (!h
->def_regular
)
7047 /* Mark the symbol as undefined, rather than as defined in
7048 the .plt section. Leave the value alone. */
7049 sym
->st_shndx
= SHN_UNDEF
;
7050 /* If the symbol is weak, we do need to clear the value.
7051 Otherwise, the PLT entry would provide a definition for
7052 the symbol even if the symbol wasn't defined anywhere,
7053 and so the symbol would never be NULL. */
7054 if (!h
->ref_regular_nonweak
)
7059 if (h
->got
.offset
!= (bfd_vma
) -1
7060 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
7061 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
7065 Elf_Internal_Rela rel
;
7069 /* This symbol has an entry in the global offset table. Set it
7071 sgot
= bfd_get_section_by_name (dynobj
, ".got");
7072 srel
= bfd_get_section_by_name (dynobj
, RELOC_SECTION (htab
, ".got"));
7073 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7075 offset
= (h
->got
.offset
& ~(bfd_vma
) 1);
7077 rel
.r_offset
= (sgot
->output_section
->vma
7078 + sgot
->output_offset
7081 /* If this is a static link, or it is a -Bsymbolic link and the
7082 symbol is defined locally or was forced to be local because
7083 of a version file, we just want to emit a RELATIVE reloc.
7084 The entry in the global offset table will already have been
7085 initialized in the relocate_section function. */
7087 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7089 BFD_ASSERT((h
->got
.offset
& 1) != 0);
7090 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
7093 rel
.r_addend
= bfd_get_32 (output_bfd
, sgot
->contents
+ offset
);
7094 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
7099 BFD_ASSERT((h
->got
.offset
& 1) == 0);
7100 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ offset
);
7101 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
7104 loc
= srel
->contents
+ srel
->reloc_count
++ * RELOC_SIZE (htab
);
7105 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7111 Elf_Internal_Rela rel
;
7114 /* This symbol needs a copy reloc. Set it up. */
7115 BFD_ASSERT (h
->dynindx
!= -1
7116 && (h
->root
.type
== bfd_link_hash_defined
7117 || h
->root
.type
== bfd_link_hash_defweak
));
7119 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7120 RELOC_SECTION (htab
, ".bss"));
7121 BFD_ASSERT (s
!= NULL
);
7124 rel
.r_offset
= (h
->root
.u
.def
.value
7125 + h
->root
.u
.def
.section
->output_section
->vma
7126 + h
->root
.u
.def
.section
->output_offset
);
7127 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
7128 loc
= s
->contents
+ s
->reloc_count
++ * RELOC_SIZE (htab
);
7129 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, loc
);
7132 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
7133 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
7134 to the ".got" section. */
7135 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7136 || (!htab
->vxworks_p
&& h
== htab
->root
.hgot
))
7137 sym
->st_shndx
= SHN_ABS
;
7142 /* Finish up the dynamic sections. */
7145 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
7151 dynobj
= elf_hash_table (info
)->dynobj
;
7153 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
7154 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
7155 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7157 if (elf_hash_table (info
)->dynamic_sections_created
)
7160 Elf32_External_Dyn
*dyncon
, *dynconend
;
7161 struct elf32_arm_link_hash_table
*htab
;
7163 htab
= elf32_arm_hash_table (info
);
7164 splt
= bfd_get_section_by_name (dynobj
, ".plt");
7165 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
7167 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7168 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
7170 for (; dyncon
< dynconend
; dyncon
++)
7172 Elf_Internal_Dyn dyn
;
7176 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7187 goto get_vma_if_bpabi
;
7190 goto get_vma_if_bpabi
;
7193 goto get_vma_if_bpabi
;
7195 name
= ".gnu.version";
7196 goto get_vma_if_bpabi
;
7198 name
= ".gnu.version_d";
7199 goto get_vma_if_bpabi
;
7201 name
= ".gnu.version_r";
7202 goto get_vma_if_bpabi
;
7208 name
= RELOC_SECTION (htab
, ".plt");
7210 s
= bfd_get_section_by_name (output_bfd
, name
);
7211 BFD_ASSERT (s
!= NULL
);
7212 if (!htab
->symbian_p
)
7213 dyn
.d_un
.d_ptr
= s
->vma
;
7215 /* In the BPABI, tags in the PT_DYNAMIC section point
7216 at the file offset, not the memory address, for the
7217 convenience of the post linker. */
7218 dyn
.d_un
.d_ptr
= s
->filepos
;
7219 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7223 if (htab
->symbian_p
)
7228 s
= bfd_get_section_by_name (output_bfd
,
7229 RELOC_SECTION (htab
, ".plt"));
7230 BFD_ASSERT (s
!= NULL
);
7231 dyn
.d_un
.d_val
= s
->size
;
7232 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7237 if (!htab
->symbian_p
)
7239 /* My reading of the SVR4 ABI indicates that the
7240 procedure linkage table relocs (DT_JMPREL) should be
7241 included in the overall relocs (DT_REL). This is
7242 what Solaris does. However, UnixWare can not handle
7243 that case. Therefore, we override the DT_RELSZ entry
7244 here to make it not include the JMPREL relocs. Since
7245 the linker script arranges for .rel(a).plt to follow all
7246 other relocation sections, we don't have to worry
7247 about changing the DT_REL entry. */
7248 s
= bfd_get_section_by_name (output_bfd
,
7249 RELOC_SECTION (htab
, ".plt"));
7251 dyn
.d_un
.d_val
-= s
->size
;
7252 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7259 /* In the BPABI, the DT_REL tag must point at the file
7260 offset, not the VMA, of the first relocation
7261 section. So, we use code similar to that in
7262 elflink.c, but do not check for SHF_ALLOC on the
7263 relcoation section, since relocations sections are
7264 never allocated under the BPABI. The comments above
7265 about Unixware notwithstanding, we include all of the
7266 relocations here. */
7267 if (htab
->symbian_p
)
7270 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
7271 ? SHT_REL
: SHT_RELA
);
7273 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
7275 Elf_Internal_Shdr
*hdr
7276 = elf_elfsections (output_bfd
)[i
];
7277 if (hdr
->sh_type
== type
)
7279 if (dyn
.d_tag
== DT_RELSZ
7280 || dyn
.d_tag
== DT_RELASZ
)
7281 dyn
.d_un
.d_val
+= hdr
->sh_size
;
7282 else if ((ufile_ptr
) hdr
->sh_offset
7283 <= dyn
.d_un
.d_val
- 1)
7284 dyn
.d_un
.d_val
= hdr
->sh_offset
;
7287 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7291 /* Set the bottom bit of DT_INIT/FINI if the
7292 corresponding function is Thumb. */
7294 name
= info
->init_function
;
7297 name
= info
->fini_function
;
7299 /* If it wasn't set by elf_bfd_final_link
7300 then there is nothing to adjust. */
7301 if (dyn
.d_un
.d_val
!= 0)
7303 struct elf_link_hash_entry
* eh
;
7305 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
7306 FALSE
, FALSE
, TRUE
);
7307 if (eh
!= (struct elf_link_hash_entry
*) NULL
7308 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
7310 dyn
.d_un
.d_val
|= 1;
7311 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7318 /* Fill in the first entry in the procedure linkage table. */
7319 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
7321 const bfd_vma
*plt0_entry
;
7322 bfd_vma got_address
, plt_address
, got_displacement
;
7324 /* Calculate the addresses of the GOT and PLT. */
7325 got_address
= sgot
->output_section
->vma
+ sgot
->output_offset
;
7326 plt_address
= splt
->output_section
->vma
+ splt
->output_offset
;
7328 if (htab
->vxworks_p
)
7330 /* The VxWorks GOT is relocated by the dynamic linker.
7331 Therefore, we must emit relocations rather than simply
7332 computing the values now. */
7333 Elf_Internal_Rela rel
;
7335 plt0_entry
= elf32_arm_vxworks_exec_plt0_entry
;
7336 bfd_put_32 (output_bfd
, plt0_entry
[0], splt
->contents
+ 0);
7337 bfd_put_32 (output_bfd
, plt0_entry
[1], splt
->contents
+ 4);
7338 bfd_put_32 (output_bfd
, plt0_entry
[2], splt
->contents
+ 8);
7339 bfd_put_32 (output_bfd
, got_address
, splt
->contents
+ 12);
7341 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
7342 rel
.r_offset
= plt_address
+ 12;
7343 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
7345 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
,
7346 htab
->srelplt2
->contents
);
7350 got_displacement
= got_address
- (plt_address
+ 16);
7352 plt0_entry
= elf32_arm_plt0_entry
;
7353 bfd_put_32 (output_bfd
, plt0_entry
[0], splt
->contents
+ 0);
7354 bfd_put_32 (output_bfd
, plt0_entry
[1], splt
->contents
+ 4);
7355 bfd_put_32 (output_bfd
, plt0_entry
[2], splt
->contents
+ 8);
7356 bfd_put_32 (output_bfd
, plt0_entry
[3], splt
->contents
+ 12);
7358 #ifdef FOUR_WORD_PLT
7359 /* The displacement value goes in the otherwise-unused
7360 last word of the second entry. */
7361 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
7363 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
7368 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7369 really seem like the right value. */
7370 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7372 if (htab
->vxworks_p
&& !info
->shared
&& htab
->splt
->size
> 0)
7374 /* Correct the .rel(a).plt.unloaded relocations. They will have
7375 incorrect symbol indexes. */
7379 num_plts
= ((htab
->splt
->size
- htab
->plt_header_size
)
7380 / htab
->plt_entry_size
);
7381 p
= htab
->srelplt2
->contents
+ RELOC_SIZE (htab
);
7383 for (; num_plts
; num_plts
--)
7385 Elf_Internal_Rela rel
;
7387 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
7388 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_ARM_ABS32
);
7389 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
7390 p
+= RELOC_SIZE (htab
);
7392 SWAP_RELOC_IN (htab
) (output_bfd
, p
, &rel
);
7393 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_ARM_ABS32
);
7394 SWAP_RELOC_OUT (htab
) (output_bfd
, &rel
, p
);
7395 p
+= RELOC_SIZE (htab
);
7400 /* Fill in the first three entries in the global offset table. */
7406 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7408 bfd_put_32 (output_bfd
,
7409 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7411 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7412 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7415 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7422 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
7424 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
7425 struct elf32_arm_link_hash_table
*globals
;
7427 i_ehdrp
= elf_elfheader (abfd
);
7429 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
7430 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
7432 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
7433 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
7437 globals
= elf32_arm_hash_table (link_info
);
7438 if (globals
->byteswap_code
)
7439 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
7443 static enum elf_reloc_type_class
7444 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
7446 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7448 case R_ARM_RELATIVE
:
7449 return reloc_class_relative
;
7450 case R_ARM_JUMP_SLOT
:
7451 return reloc_class_plt
;
7453 return reloc_class_copy
;
7455 return reloc_class_normal
;
7459 /* Set the right machine number for an Arm ELF file. */
7462 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
7464 if (hdr
->sh_type
== SHT_NOTE
)
7465 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
7471 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
7473 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
7476 /* Return TRUE if this is an unwinding table entry. */
7479 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
7483 len1
= sizeof (ELF_STRING_ARM_unwind
) - 1;
7484 len2
= sizeof (ELF_STRING_ARM_unwind_once
) - 1;
7485 return (strncmp (name
, ELF_STRING_ARM_unwind
, len1
) == 0
7486 || strncmp (name
, ELF_STRING_ARM_unwind_once
, len2
) == 0);
7490 /* Set the type and flags for an ARM section. We do this by
7491 the section name, which is a hack, but ought to work. */
7494 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
7498 name
= bfd_get_section_name (abfd
, sec
);
7500 if (is_arm_elf_unwind_section_name (abfd
, name
))
7502 hdr
->sh_type
= SHT_ARM_EXIDX
;
7503 hdr
->sh_flags
|= SHF_LINK_ORDER
;
7505 else if (strcmp(name
, ".ARM.attributes") == 0)
7507 hdr
->sh_type
= SHT_ARM_ATTRIBUTES
;
7512 /* Parse an Arm EABI attributes section. */
7514 elf32_arm_parse_attributes (bfd
*abfd
, Elf_Internal_Shdr
* hdr
)
7520 contents
= bfd_malloc (hdr
->sh_size
);
7523 if (!bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
, 0,
7532 len
= hdr
->sh_size
- 1;
7536 bfd_vma section_len
;
7538 section_len
= bfd_get_32 (abfd
, p
);
7540 if (section_len
> len
)
7543 namelen
= strlen ((char *)p
) + 1;
7544 section_len
-= namelen
+ 4;
7545 if (strcmp((char *)p
, "aeabi") != 0)
7547 /* Vendor section. Ignore it. */
7548 p
+= namelen
+ section_len
;
7553 while (section_len
> 0)
7558 bfd_vma subsection_len
;
7561 tag
= read_unsigned_leb128 (abfd
, p
, &n
);
7563 subsection_len
= bfd_get_32 (abfd
, p
);
7565 if (subsection_len
> section_len
)
7566 subsection_len
= section_len
;
7567 section_len
-= subsection_len
;
7568 subsection_len
-= n
+ 4;
7569 end
= p
+ subsection_len
;
7575 bfd_boolean is_string
;
7577 tag
= read_unsigned_leb128 (abfd
, p
, &n
);
7579 if (tag
== 4 || tag
== 5)
7584 is_string
= (tag
& 1) != 0;
7585 if (tag
== Tag_compatibility
)
7587 val
= read_unsigned_leb128 (abfd
, p
, &n
);
7589 elf32_arm_add_eabi_attr_compat (abfd
, val
,
7591 p
+= strlen ((char *)p
) + 1;
7595 elf32_arm_add_eabi_attr_string (abfd
, tag
,
7597 p
+= strlen ((char *)p
) + 1;
7601 val
= read_unsigned_leb128 (abfd
, p
, &n
);
7603 elf32_arm_add_eabi_attr_int (abfd
, tag
, val
);
7609 /* Don't have anywhere convenient to attach these.
7610 Fall through for now. */
7612 /* Ignore things we don't kow about. */
7613 p
+= subsection_len
;
7624 /* Handle an ARM specific section when reading an object file. This is
7625 called when bfd_section_from_shdr finds a section with an unknown
7629 elf32_arm_section_from_shdr (bfd
*abfd
,
7630 Elf_Internal_Shdr
* hdr
,
7634 /* There ought to be a place to keep ELF backend specific flags, but
7635 at the moment there isn't one. We just keep track of the
7636 sections by their name, instead. Fortunately, the ABI gives
7637 names for all the ARM specific sections, so we will probably get
7639 switch (hdr
->sh_type
)
7642 case SHT_ARM_PREEMPTMAP
:
7643 case SHT_ARM_ATTRIBUTES
:
7650 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
7653 if (hdr
->sh_type
== SHT_ARM_ATTRIBUTES
)
7654 elf32_arm_parse_attributes(abfd
, hdr
);
7658 /* A structure used to record a list of sections, independently
7659 of the next and prev fields in the asection structure. */
7660 typedef struct section_list
7663 struct section_list
* next
;
7664 struct section_list
* prev
;
7668 /* Unfortunately we need to keep a list of sections for which
7669 an _arm_elf_section_data structure has been allocated. This
7670 is because it is possible for functions like elf32_arm_write_section
7671 to be called on a section which has had an elf_data_structure
7672 allocated for it (and so the used_by_bfd field is valid) but
7673 for which the ARM extended version of this structure - the
7674 _arm_elf_section_data structure - has not been allocated. */
7675 static section_list
* sections_with_arm_elf_section_data
= NULL
;
7678 record_section_with_arm_elf_section_data (asection
* sec
)
7680 struct section_list
* entry
;
7682 entry
= bfd_malloc (sizeof (* entry
));
7686 entry
->next
= sections_with_arm_elf_section_data
;
7688 if (entry
->next
!= NULL
)
7689 entry
->next
->prev
= entry
;
7690 sections_with_arm_elf_section_data
= entry
;
7693 static struct section_list
*
7694 find_arm_elf_section_entry (asection
* sec
)
7696 struct section_list
* entry
;
7697 static struct section_list
* last_entry
= NULL
;
7699 /* This is a short cut for the typical case where the sections are added
7700 to the sections_with_arm_elf_section_data list in forward order and
7701 then looked up here in backwards order. This makes a real difference
7702 to the ld-srec/sec64k.exp linker test. */
7703 entry
= sections_with_arm_elf_section_data
;
7704 if (last_entry
!= NULL
)
7706 if (last_entry
->sec
== sec
)
7708 else if (last_entry
->next
!= NULL
7709 && last_entry
->next
->sec
== sec
)
7710 entry
= last_entry
->next
;
7713 for (; entry
; entry
= entry
->next
)
7714 if (entry
->sec
== sec
)
7718 /* Record the entry prior to this one - it is the entry we are most
7719 likely to want to locate next time. Also this way if we have been
7720 called from unrecord_section_with_arm_elf_section_data() we will not
7721 be caching a pointer that is about to be freed. */
7722 last_entry
= entry
->prev
;
7727 static _arm_elf_section_data
*
7728 get_arm_elf_section_data (asection
* sec
)
7730 struct section_list
* entry
;
7732 entry
= find_arm_elf_section_entry (sec
);
7735 return elf32_arm_section_data (entry
->sec
);
7741 unrecord_section_with_arm_elf_section_data (asection
* sec
)
7743 struct section_list
* entry
;
7745 entry
= find_arm_elf_section_entry (sec
);
7749 if (entry
->prev
!= NULL
)
7750 entry
->prev
->next
= entry
->next
;
7751 if (entry
->next
!= NULL
)
7752 entry
->next
->prev
= entry
->prev
;
7753 if (entry
== sections_with_arm_elf_section_data
)
7754 sections_with_arm_elf_section_data
= entry
->next
;
7759 /* Called for each symbol. Builds a section map based on mapping symbols.
7760 Does not alter any of the symbols. */
7763 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
7765 Elf_Internal_Sym
*elfsym
,
7766 asection
*input_sec
,
7767 struct elf_link_hash_entry
*h
)
7770 elf32_arm_section_map
*map
;
7771 elf32_arm_section_map
*newmap
;
7772 _arm_elf_section_data
*arm_data
;
7773 struct elf32_arm_link_hash_table
*globals
;
7775 globals
= elf32_arm_hash_table (info
);
7776 if (globals
->vxworks_p
7777 && !elf_vxworks_link_output_symbol_hook (info
, name
, elfsym
,
7781 /* Only do this on final link. */
7782 if (info
->relocatable
)
7785 /* Only build a map if we need to byteswap code. */
7786 if (!globals
->byteswap_code
)
7789 /* We only want mapping symbols. */
7790 if (! bfd_is_arm_mapping_symbol_name (name
))
7793 /* If this section has not been allocated an _arm_elf_section_data
7794 structure then we cannot record anything. */
7795 arm_data
= get_arm_elf_section_data (input_sec
);
7796 if (arm_data
== NULL
)
7799 mapcount
= arm_data
->mapcount
+ 1;
7800 map
= arm_data
->map
;
7802 /* TODO: This may be inefficient, but we probably don't usually have many
7803 mapping symbols per section. */
7804 newmap
= bfd_realloc (map
, mapcount
* sizeof (* map
));
7807 arm_data
->map
= newmap
;
7808 arm_data
->mapcount
= mapcount
;
7810 newmap
[mapcount
- 1].vma
= elfsym
->st_value
;
7811 newmap
[mapcount
- 1].type
= name
[1];
7817 /* Allocate target specific section data. */
7820 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
7822 _arm_elf_section_data
*sdata
;
7823 bfd_size_type amt
= sizeof (*sdata
);
7825 sdata
= bfd_zalloc (abfd
, amt
);
7828 sec
->used_by_bfd
= sdata
;
7830 record_section_with_arm_elf_section_data (sec
);
7832 return _bfd_elf_new_section_hook (abfd
, sec
);
7836 /* Used to order a list of mapping symbols by address. */
7839 elf32_arm_compare_mapping (const void * a
, const void * b
)
7841 return ((const elf32_arm_section_map
*) a
)->vma
7842 > ((const elf32_arm_section_map
*) b
)->vma
;
7846 /* Do code byteswapping. Return FALSE afterwards so that the section is
7847 written out as normal. */
7850 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
7854 _arm_elf_section_data
*arm_data
;
7855 elf32_arm_section_map
*map
;
7862 /* If this section has not been allocated an _arm_elf_section_data
7863 structure then we cannot record anything. */
7864 arm_data
= get_arm_elf_section_data (sec
);
7865 if (arm_data
== NULL
)
7868 mapcount
= arm_data
->mapcount
;
7869 map
= arm_data
->map
;
7874 qsort (map
, mapcount
, sizeof (* map
), elf32_arm_compare_mapping
);
7876 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
7877 ptr
= map
[0].vma
- offset
;
7878 for (i
= 0; i
< mapcount
; i
++)
7880 if (i
== mapcount
- 1)
7883 end
= map
[i
+ 1].vma
- offset
;
7885 switch (map
[i
].type
)
7888 /* Byte swap code words. */
7889 while (ptr
+ 3 < end
)
7891 tmp
= contents
[ptr
];
7892 contents
[ptr
] = contents
[ptr
+ 3];
7893 contents
[ptr
+ 3] = tmp
;
7894 tmp
= contents
[ptr
+ 1];
7895 contents
[ptr
+ 1] = contents
[ptr
+ 2];
7896 contents
[ptr
+ 2] = tmp
;
7902 /* Byte swap code halfwords. */
7903 while (ptr
+ 1 < end
)
7905 tmp
= contents
[ptr
];
7906 contents
[ptr
] = contents
[ptr
+ 1];
7907 contents
[ptr
+ 1] = tmp
;
7913 /* Leave data alone. */
7920 arm_data
->mapcount
= 0;
7921 arm_data
->map
= NULL
;
7922 unrecord_section_with_arm_elf_section_data (sec
);
7928 unrecord_section_via_map_over_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
7930 void * ignore ATTRIBUTE_UNUSED
)
7932 unrecord_section_with_arm_elf_section_data (sec
);
7936 elf32_arm_close_and_cleanup (bfd
* abfd
)
7938 bfd_map_over_sections (abfd
, unrecord_section_via_map_over_sections
, NULL
);
7940 return _bfd_elf_close_and_cleanup (abfd
);
7943 /* Display STT_ARM_TFUNC symbols as functions. */
7946 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
7949 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
7951 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
7952 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
7956 /* Mangle thumb function symbols as we read them in. */
7959 elf32_arm_swap_symbol_in (bfd
* abfd
,
7962 Elf_Internal_Sym
*dst
)
7964 bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
);
7966 /* New EABI objects mark thumb function symbols by setting the low bit of
7967 the address. Turn these into STT_ARM_TFUNC. */
7968 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
7969 && (dst
->st_value
& 1))
7971 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
7972 dst
->st_value
&= ~(bfd_vma
) 1;
7977 /* Mangle thumb function symbols as we write them out. */
7980 elf32_arm_swap_symbol_out (bfd
*abfd
,
7981 const Elf_Internal_Sym
*src
,
7985 Elf_Internal_Sym newsym
;
7987 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
7988 of the address set, as per the new EABI. We do this unconditionally
7989 because objcopy does not set the elf header flags until after
7990 it writes out the symbol table. */
7991 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
7994 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
7995 newsym
.st_value
|= 1;
7999 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
8002 /* Add the PT_ARM_EXIDX program header. */
8005 elf32_arm_modify_segment_map (bfd
*abfd
,
8006 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
8008 struct elf_segment_map
*m
;
8011 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
8012 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
8014 /* If there is already a PT_ARM_EXIDX header, then we do not
8015 want to add another one. This situation arises when running
8016 "strip"; the input binary already has the header. */
8017 m
= elf_tdata (abfd
)->segment_map
;
8018 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
8022 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
8025 m
->p_type
= PT_ARM_EXIDX
;
8027 m
->sections
[0] = sec
;
8029 m
->next
= elf_tdata (abfd
)->segment_map
;
8030 elf_tdata (abfd
)->segment_map
= m
;
8037 /* We may add a PT_ARM_EXIDX program header. */
8040 elf32_arm_additional_program_headers (bfd
*abfd
)
8044 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
8045 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
8051 /* We use this to override swap_symbol_in and swap_symbol_out. */
8052 const struct elf_size_info elf32_arm_size_info
= {
8053 sizeof (Elf32_External_Ehdr
),
8054 sizeof (Elf32_External_Phdr
),
8055 sizeof (Elf32_External_Shdr
),
8056 sizeof (Elf32_External_Rel
),
8057 sizeof (Elf32_External_Rela
),
8058 sizeof (Elf32_External_Sym
),
8059 sizeof (Elf32_External_Dyn
),
8060 sizeof (Elf_External_Note
),
8064 ELFCLASS32
, EV_CURRENT
,
8065 bfd_elf32_write_out_phdrs
,
8066 bfd_elf32_write_shdrs_and_ehdr
,
8067 bfd_elf32_write_relocs
,
8068 elf32_arm_swap_symbol_in
,
8069 elf32_arm_swap_symbol_out
,
8070 bfd_elf32_slurp_reloc_table
,
8071 bfd_elf32_slurp_symbol_table
,
8072 bfd_elf32_swap_dyn_in
,
8073 bfd_elf32_swap_dyn_out
,
8074 bfd_elf32_swap_reloc_in
,
8075 bfd_elf32_swap_reloc_out
,
8076 bfd_elf32_swap_reloca_in
,
8077 bfd_elf32_swap_reloca_out
8080 #define ELF_ARCH bfd_arch_arm
8081 #define ELF_MACHINE_CODE EM_ARM
8082 #ifdef __QNXTARGET__
8083 #define ELF_MAXPAGESIZE 0x1000
8085 #define ELF_MAXPAGESIZE 0x8000
8087 #define ELF_MINPAGESIZE 0x1000
8089 #define bfd_elf32_mkobject elf32_arm_mkobject
8091 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
8092 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
8093 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
8094 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
8095 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
8096 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
8097 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
8098 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
8099 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
8100 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
8101 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
8102 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
8104 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
8105 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
8106 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
8107 #define elf_backend_check_relocs elf32_arm_check_relocs
8108 #define elf_backend_relocate_section elf32_arm_relocate_section
8109 #define elf_backend_write_section elf32_arm_write_section
8110 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
8111 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
8112 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
8113 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
8114 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
8115 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
8116 #define elf_backend_post_process_headers elf32_arm_post_process_headers
8117 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
8118 #define elf_backend_object_p elf32_arm_object_p
8119 #define elf_backend_section_flags elf32_arm_section_flags
8120 #define elf_backend_fake_sections elf32_arm_fake_sections
8121 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
8122 #define elf_backend_final_write_processing elf32_arm_final_write_processing
8123 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
8124 #define elf_backend_symbol_processing elf32_arm_symbol_processing
8125 #define elf_backend_size_info elf32_arm_size_info
8126 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
8127 #define elf_backend_additional_program_headers \
8128 elf32_arm_additional_program_headers
8130 #define elf_backend_can_refcount 1
8131 #define elf_backend_can_gc_sections 1
8132 #define elf_backend_plt_readonly 1
8133 #define elf_backend_want_got_plt 1
8134 #define elf_backend_want_plt_sym 0
8135 #define elf_backend_may_use_rel_p 1
8136 #define elf_backend_may_use_rela_p 0
8137 #define elf_backend_default_use_rela_p 0
8138 #define elf_backend_rela_normal 0
8140 #define elf_backend_got_header_size 12
8142 #include "elf32-target.h"
8144 /* VxWorks Targets */
8146 #undef TARGET_LITTLE_SYM
8147 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
8148 #undef TARGET_LITTLE_NAME
8149 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
8150 #undef TARGET_BIG_SYM
8151 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
8152 #undef TARGET_BIG_NAME
8153 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
8155 /* Like elf32_arm_link_hash_table_create -- but overrides
8156 appropriately for VxWorks. */
8157 static struct bfd_link_hash_table
*
8158 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
8160 struct bfd_link_hash_table
*ret
;
8162 ret
= elf32_arm_link_hash_table_create (abfd
);
8165 struct elf32_arm_link_hash_table
*htab
8166 = (struct elf32_arm_link_hash_table
*) ret
;
8168 htab
->vxworks_p
= 1;
8174 elf32_arm_vxworks_final_write_processing (bfd
*abfd
, bfd_boolean linker
)
8176 elf32_arm_final_write_processing (abfd
, linker
);
8177 elf_vxworks_final_write_processing (abfd
, linker
);
8181 #define elf32_bed elf32_arm_vxworks_bed
8183 #undef bfd_elf32_bfd_link_hash_table_create
8184 #define bfd_elf32_bfd_link_hash_table_create \
8185 elf32_arm_vxworks_link_hash_table_create
8186 #undef elf_backend_add_symbol_hook
8187 #define elf_backend_add_symbol_hook \
8188 elf_vxworks_add_symbol_hook
8189 #undef elf_backend_final_write_processing
8190 #define elf_backend_final_write_processing \
8191 elf32_arm_vxworks_final_write_processing
8192 #undef elf_backend_emit_relocs
8193 #define elf_backend_emit_relocs \
8194 elf_vxworks_emit_relocs
8196 #undef elf_backend_may_use_rel_p
8197 #define elf_backend_may_use_rel_p 0
8198 #undef elf_backend_may_use_rela_p
8199 #define elf_backend_may_use_rela_p 1
8200 #undef elf_backend_default_use_rela_p
8201 #define elf_backend_default_use_rela_p 1
8202 #undef elf_backend_rela_normal
8203 #define elf_backend_rela_normal 1
8204 #undef elf_backend_want_plt_sym
8205 #define elf_backend_want_plt_sym 1
8206 #undef ELF_MAXPAGESIZE
8207 #define ELF_MAXPAGESIZE 0x1000
8209 #include "elf32-target.h"
8212 /* Symbian OS Targets */
8214 #undef TARGET_LITTLE_SYM
8215 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
8216 #undef TARGET_LITTLE_NAME
8217 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
8218 #undef TARGET_BIG_SYM
8219 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
8220 #undef TARGET_BIG_NAME
8221 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
8223 /* Like elf32_arm_link_hash_table_create -- but overrides
8224 appropriately for Symbian OS. */
8225 static struct bfd_link_hash_table
*
8226 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
8228 struct bfd_link_hash_table
*ret
;
8230 ret
= elf32_arm_link_hash_table_create (abfd
);
8233 struct elf32_arm_link_hash_table
*htab
8234 = (struct elf32_arm_link_hash_table
*)ret
;
8235 /* There is no PLT header for Symbian OS. */
8236 htab
->plt_header_size
= 0;
8237 /* The PLT entries are each three instructions. */
8238 htab
->plt_entry_size
= 4 * NUM_ELEM (elf32_arm_symbian_plt_entry
);
8239 htab
->symbian_p
= 1;
8240 /* Symbian uses armv5t or above, so use_blx is always true. */
8242 htab
->root
.is_relocatable_executable
= 1;
8247 static const struct bfd_elf_special_section
8248 elf32_arm_symbian_special_sections
[] =
8250 /* In a BPABI executable, the dynamic linking sections do not go in
8251 the loadable read-only segment. The post-linker may wish to
8252 refer to these sections, but they are not part of the final
8254 { ".dynamic", 8, 0, SHT_DYNAMIC
, 0 },
8255 { ".dynstr", 7, 0, SHT_STRTAB
, 0 },
8256 { ".dynsym", 7, 0, SHT_DYNSYM
, 0 },
8257 { ".got", 4, 0, SHT_PROGBITS
, 0 },
8258 { ".hash", 5, 0, SHT_HASH
, 0 },
8259 /* These sections do not need to be writable as the SymbianOS
8260 postlinker will arrange things so that no dynamic relocation is
8262 { ".init_array", 11, 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
8263 { ".fini_array", 11, 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
8264 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
8265 { NULL
, 0, 0, 0, 0 }
8269 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
8270 struct bfd_link_info
*link_info
8273 /* BPABI objects are never loaded directly by an OS kernel; they are
8274 processed by a postlinker first, into an OS-specific format. If
8275 the D_PAGED bit is set on the file, BFD will align segments on
8276 page boundaries, so that an OS can directly map the file. With
8277 BPABI objects, that just results in wasted space. In addition,
8278 because we clear the D_PAGED bit, map_sections_to_segments will
8279 recognize that the program headers should not be mapped into any
8280 loadable segment. */
8281 abfd
->flags
&= ~D_PAGED
;
8285 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
8286 struct bfd_link_info
*info
)
8288 struct elf_segment_map
*m
;
8291 /* BPABI shared libraries and executables should have a PT_DYNAMIC
8292 segment. However, because the .dynamic section is not marked
8293 with SEC_LOAD, the generic ELF code will not create such a
8295 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
8298 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
8299 m
->next
= elf_tdata (abfd
)->segment_map
;
8300 elf_tdata (abfd
)->segment_map
= m
;
8303 /* Also call the generic arm routine. */
8304 return elf32_arm_modify_segment_map (abfd
, info
);
8308 #define elf32_bed elf32_arm_symbian_bed
8310 /* The dynamic sections are not allocated on SymbianOS; the postlinker
8311 will process them and then discard them. */
8312 #undef ELF_DYNAMIC_SEC_FLAGS
8313 #define ELF_DYNAMIC_SEC_FLAGS \
8314 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
8316 #undef bfd_elf32_bfd_link_hash_table_create
8317 #define bfd_elf32_bfd_link_hash_table_create \
8318 elf32_arm_symbian_link_hash_table_create
8319 #undef elf_backend_add_symbol_hook
8321 #undef elf_backend_special_sections
8322 #define elf_backend_special_sections elf32_arm_symbian_special_sections
8324 #undef elf_backend_begin_write_processing
8325 #define elf_backend_begin_write_processing \
8326 elf32_arm_symbian_begin_write_processing
8327 #undef elf_backend_final_write_processing
8328 #define elf_backend_final_write_processing \
8329 elf32_arm_final_write_processing
8330 #undef elf_backend_emit_relocs
8332 #undef elf_backend_modify_segment_map
8333 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
8335 /* There is no .got section for BPABI objects, and hence no header. */
8336 #undef elf_backend_got_header_size
8337 #define elf_backend_got_header_size 0
8339 /* Similarly, there is no .got.plt section. */
8340 #undef elf_backend_want_got_plt
8341 #define elf_backend_want_got_plt 0
8343 #undef elf_backend_may_use_rel_p
8344 #define elf_backend_may_use_rel_p 1
8345 #undef elf_backend_may_use_rela_p
8346 #define elf_backend_may_use_rela_p 0
8347 #undef elf_backend_default_use_rela_p
8348 #define elf_backend_default_use_rela_p 0
8349 #undef elf_backend_rela_normal
8350 #define elf_backend_rela_normal 0
8351 #undef elf_backend_want_plt_sym
8352 #define elf_backend_want_plt_sym 0
8353 #undef ELF_MAXPAGESIZE
8354 #define ELF_MAXPAGESIZE 0x8000
8356 #include "elf32-target.h"