1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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. */
28 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
31 #define elf_info_to_howto 0
32 #define elf_info_to_howto_rel elf32_arm_info_to_howto
34 #define ARM_ELF_ABI_VERSION 0
35 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
37 static reloc_howto_type
* elf32_arm_reloc_type_lookup
38 PARAMS ((bfd
* abfd
, bfd_reloc_code_real_type code
));
39 static bfd_boolean elf32_arm_nabi_grok_prstatus
40 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
41 static bfd_boolean elf32_arm_nabi_grok_psinfo
42 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
44 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
45 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
48 static reloc_howto_type elf32_arm_howto_table_1
[] =
51 HOWTO (R_ARM_NONE
, /* type */
53 0, /* size (0 = byte, 1 = short, 2 = long) */
55 FALSE
, /* pc_relative */
57 complain_overflow_dont
,/* complain_on_overflow */
58 bfd_elf_generic_reloc
, /* special_function */
59 "R_ARM_NONE", /* name */
60 FALSE
, /* partial_inplace */
63 FALSE
), /* pcrel_offset */
65 HOWTO (R_ARM_PC24
, /* type */
67 2, /* size (0 = byte, 1 = short, 2 = long) */
69 TRUE
, /* pc_relative */
71 complain_overflow_signed
,/* complain_on_overflow */
72 bfd_elf_generic_reloc
, /* special_function */
73 "R_ARM_PC24", /* name */
74 FALSE
, /* partial_inplace */
75 0x00ffffff, /* src_mask */
76 0x00ffffff, /* dst_mask */
77 TRUE
), /* pcrel_offset */
80 HOWTO (R_ARM_ABS32
, /* type */
82 2, /* size (0 = byte, 1 = short, 2 = long) */
84 FALSE
, /* pc_relative */
86 complain_overflow_bitfield
,/* complain_on_overflow */
87 bfd_elf_generic_reloc
, /* special_function */
88 "R_ARM_ABS32", /* name */
89 FALSE
, /* partial_inplace */
90 0xffffffff, /* src_mask */
91 0xffffffff, /* dst_mask */
92 FALSE
), /* pcrel_offset */
94 /* standard 32bit pc-relative reloc */
95 HOWTO (R_ARM_REL32
, /* type */
97 2, /* size (0 = byte, 1 = short, 2 = long) */
99 TRUE
, /* pc_relative */
101 complain_overflow_bitfield
,/* complain_on_overflow */
102 bfd_elf_generic_reloc
, /* special_function */
103 "R_ARM_REL32", /* name */
104 FALSE
, /* partial_inplace */
105 0xffffffff, /* src_mask */
106 0xffffffff, /* dst_mask */
107 TRUE
), /* pcrel_offset */
109 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
110 HOWTO (R_ARM_PC13
, /* type */
112 0, /* size (0 = byte, 1 = short, 2 = long) */
114 FALSE
, /* pc_relative */
116 complain_overflow_bitfield
,/* complain_on_overflow */
117 bfd_elf_generic_reloc
, /* special_function */
118 "R_ARM_PC13", /* name */
119 FALSE
, /* partial_inplace */
120 0x000000ff, /* src_mask */
121 0x000000ff, /* dst_mask */
122 FALSE
), /* pcrel_offset */
124 /* 16 bit absolute */
125 HOWTO (R_ARM_ABS16
, /* type */
127 1, /* size (0 = byte, 1 = short, 2 = long) */
129 FALSE
, /* pc_relative */
131 complain_overflow_bitfield
,/* complain_on_overflow */
132 bfd_elf_generic_reloc
, /* special_function */
133 "R_ARM_ABS16", /* name */
134 FALSE
, /* partial_inplace */
135 0x0000ffff, /* src_mask */
136 0x0000ffff, /* dst_mask */
137 FALSE
), /* pcrel_offset */
139 /* 12 bit absolute */
140 HOWTO (R_ARM_ABS12
, /* type */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
144 FALSE
, /* pc_relative */
146 complain_overflow_bitfield
,/* complain_on_overflow */
147 bfd_elf_generic_reloc
, /* special_function */
148 "R_ARM_ABS12", /* name */
149 FALSE
, /* partial_inplace */
150 0x000008ff, /* src_mask */
151 0x000008ff, /* dst_mask */
152 FALSE
), /* pcrel_offset */
154 HOWTO (R_ARM_THM_ABS5
, /* type */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE
, /* pc_relative */
160 complain_overflow_bitfield
,/* complain_on_overflow */
161 bfd_elf_generic_reloc
, /* special_function */
162 "R_ARM_THM_ABS5", /* name */
163 FALSE
, /* partial_inplace */
164 0x000007e0, /* src_mask */
165 0x000007e0, /* dst_mask */
166 FALSE
), /* pcrel_offset */
169 HOWTO (R_ARM_ABS8
, /* type */
171 0, /* size (0 = byte, 1 = short, 2 = long) */
173 FALSE
, /* pc_relative */
175 complain_overflow_bitfield
,/* complain_on_overflow */
176 bfd_elf_generic_reloc
, /* special_function */
177 "R_ARM_ABS8", /* name */
178 FALSE
, /* partial_inplace */
179 0x000000ff, /* src_mask */
180 0x000000ff, /* dst_mask */
181 FALSE
), /* pcrel_offset */
183 HOWTO (R_ARM_SBREL32
, /* type */
185 2, /* size (0 = byte, 1 = short, 2 = long) */
187 FALSE
, /* pc_relative */
189 complain_overflow_dont
,/* complain_on_overflow */
190 bfd_elf_generic_reloc
, /* special_function */
191 "R_ARM_SBREL32", /* name */
192 FALSE
, /* partial_inplace */
193 0xffffffff, /* src_mask */
194 0xffffffff, /* dst_mask */
195 FALSE
), /* pcrel_offset */
197 /* FIXME: Has two more bits of offset in Thumb32. */
198 HOWTO (R_ARM_THM_CALL
, /* type */
200 2, /* size (0 = byte, 1 = short, 2 = long) */
202 TRUE
, /* pc_relative */
204 complain_overflow_signed
,/* complain_on_overflow */
205 bfd_elf_generic_reloc
, /* special_function */
206 "R_ARM_THM_CALL", /* name */
207 FALSE
, /* partial_inplace */
208 0x07ff07ff, /* src_mask */
209 0x07ff07ff, /* dst_mask */
210 TRUE
), /* pcrel_offset */
212 HOWTO (R_ARM_THM_PC8
, /* type */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
216 TRUE
, /* pc_relative */
218 complain_overflow_signed
,/* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_ARM_THM_PC8", /* name */
221 FALSE
, /* partial_inplace */
222 0x000000ff, /* src_mask */
223 0x000000ff, /* dst_mask */
224 TRUE
), /* pcrel_offset */
226 HOWTO (R_ARM_BREL_ADJ
, /* type */
228 1, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_signed
,/* complain_on_overflow */
233 bfd_elf_generic_reloc
, /* special_function */
234 "R_ARM_BREL_ADJ", /* name */
235 FALSE
, /* partial_inplace */
236 0xffffffff, /* src_mask */
237 0xffffffff, /* dst_mask */
238 FALSE
), /* pcrel_offset */
240 HOWTO (R_ARM_SWI24
, /* type */
242 0, /* size (0 = byte, 1 = short, 2 = long) */
244 FALSE
, /* pc_relative */
246 complain_overflow_signed
,/* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_ARM_SWI24", /* name */
249 FALSE
, /* partial_inplace */
250 0x00000000, /* src_mask */
251 0x00000000, /* dst_mask */
252 FALSE
), /* pcrel_offset */
254 HOWTO (R_ARM_THM_SWI8
, /* type */
256 0, /* size (0 = byte, 1 = short, 2 = long) */
258 FALSE
, /* pc_relative */
260 complain_overflow_signed
,/* complain_on_overflow */
261 bfd_elf_generic_reloc
, /* special_function */
262 "R_ARM_SWI8", /* name */
263 FALSE
, /* partial_inplace */
264 0x00000000, /* src_mask */
265 0x00000000, /* dst_mask */
266 FALSE
), /* pcrel_offset */
268 /* BLX instruction for the ARM. */
269 HOWTO (R_ARM_XPC25
, /* type */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
273 TRUE
, /* pc_relative */
275 complain_overflow_signed
,/* complain_on_overflow */
276 bfd_elf_generic_reloc
, /* special_function */
277 "R_ARM_XPC25", /* name */
278 FALSE
, /* partial_inplace */
279 0x00ffffff, /* src_mask */
280 0x00ffffff, /* dst_mask */
281 TRUE
), /* pcrel_offset */
283 /* BLX instruction for the Thumb. */
284 HOWTO (R_ARM_THM_XPC22
, /* type */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
288 TRUE
, /* pc_relative */
290 complain_overflow_signed
,/* complain_on_overflow */
291 bfd_elf_generic_reloc
, /* special_function */
292 "R_ARM_THM_XPC22", /* name */
293 FALSE
, /* partial_inplace */
294 0x07ff07ff, /* src_mask */
295 0x07ff07ff, /* dst_mask */
296 TRUE
), /* pcrel_offset */
298 /* Dynamic TLS relocations. */
300 HOWTO (R_ARM_TLS_DTPMOD32
, /* type */
302 2, /* size (0 = byte, 1 = short, 2 = long) */
304 FALSE
, /* pc_relative */
306 complain_overflow_bitfield
,/* complain_on_overflow */
307 bfd_elf_generic_reloc
, /* special_function */
308 "R_ARM_TLS_DTPMOD32", /* name */
309 TRUE
, /* partial_inplace */
310 0xffffffff, /* src_mask */
311 0xffffffff, /* dst_mask */
312 FALSE
), /* pcrel_offset */
314 HOWTO (R_ARM_TLS_DTPOFF32
, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 FALSE
, /* pc_relative */
320 complain_overflow_bitfield
,/* complain_on_overflow */
321 bfd_elf_generic_reloc
, /* special_function */
322 "R_ARM_TLS_DTPOFF32", /* name */
323 TRUE
, /* partial_inplace */
324 0xffffffff, /* src_mask */
325 0xffffffff, /* dst_mask */
326 FALSE
), /* pcrel_offset */
328 HOWTO (R_ARM_TLS_TPOFF32
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 FALSE
, /* pc_relative */
334 complain_overflow_bitfield
,/* complain_on_overflow */
335 bfd_elf_generic_reloc
, /* special_function */
336 "R_ARM_TLS_TPOFF32", /* name */
337 TRUE
, /* partial_inplace */
338 0xffffffff, /* src_mask */
339 0xffffffff, /* dst_mask */
340 FALSE
), /* pcrel_offset */
342 /* Relocs used in ARM Linux */
344 HOWTO (R_ARM_COPY
, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
350 complain_overflow_bitfield
,/* complain_on_overflow */
351 bfd_elf_generic_reloc
, /* special_function */
352 "R_ARM_COPY", /* name */
353 TRUE
, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 FALSE
), /* pcrel_offset */
358 HOWTO (R_ARM_GLOB_DAT
, /* type */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_bitfield
,/* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_ARM_GLOB_DAT", /* name */
367 TRUE
, /* partial_inplace */
368 0xffffffff, /* src_mask */
369 0xffffffff, /* dst_mask */
370 FALSE
), /* pcrel_offset */
372 HOWTO (R_ARM_JUMP_SLOT
, /* type */
374 2, /* size (0 = byte, 1 = short, 2 = long) */
376 FALSE
, /* pc_relative */
378 complain_overflow_bitfield
,/* complain_on_overflow */
379 bfd_elf_generic_reloc
, /* special_function */
380 "R_ARM_JUMP_SLOT", /* name */
381 TRUE
, /* partial_inplace */
382 0xffffffff, /* src_mask */
383 0xffffffff, /* dst_mask */
384 FALSE
), /* pcrel_offset */
386 HOWTO (R_ARM_RELATIVE
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_bitfield
,/* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_ARM_RELATIVE", /* name */
395 TRUE
, /* partial_inplace */
396 0xffffffff, /* src_mask */
397 0xffffffff, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 HOWTO (R_ARM_GOTOFF32
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE
, /* pc_relative */
406 complain_overflow_bitfield
,/* complain_on_overflow */
407 bfd_elf_generic_reloc
, /* special_function */
408 "R_ARM_GOTOFF32", /* name */
409 TRUE
, /* partial_inplace */
410 0xffffffff, /* src_mask */
411 0xffffffff, /* dst_mask */
412 FALSE
), /* pcrel_offset */
414 HOWTO (R_ARM_GOTPC
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 TRUE
, /* pc_relative */
420 complain_overflow_bitfield
,/* complain_on_overflow */
421 bfd_elf_generic_reloc
, /* special_function */
422 "R_ARM_GOTPC", /* name */
423 TRUE
, /* partial_inplace */
424 0xffffffff, /* src_mask */
425 0xffffffff, /* dst_mask */
426 TRUE
), /* pcrel_offset */
428 HOWTO (R_ARM_GOT32
, /* type */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE
, /* pc_relative */
434 complain_overflow_bitfield
,/* complain_on_overflow */
435 bfd_elf_generic_reloc
, /* special_function */
436 "R_ARM_GOT32", /* name */
437 TRUE
, /* partial_inplace */
438 0xffffffff, /* src_mask */
439 0xffffffff, /* dst_mask */
440 FALSE
), /* pcrel_offset */
442 HOWTO (R_ARM_PLT32
, /* type */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
446 TRUE
, /* pc_relative */
448 complain_overflow_bitfield
,/* complain_on_overflow */
449 bfd_elf_generic_reloc
, /* special_function */
450 "R_ARM_PLT32", /* name */
451 TRUE
, /* partial_inplace */
452 0x00ffffff, /* src_mask */
453 0x00ffffff, /* dst_mask */
454 TRUE
), /* pcrel_offset */
456 HOWTO (R_ARM_CALL
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 TRUE
, /* pc_relative */
462 complain_overflow_signed
,/* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_ARM_CALL", /* name */
465 FALSE
, /* partial_inplace */
466 0x00ffffff, /* src_mask */
467 0x00ffffff, /* dst_mask */
468 TRUE
), /* pcrel_offset */
470 HOWTO (R_ARM_JUMP24
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 TRUE
, /* pc_relative */
476 complain_overflow_signed
,/* complain_on_overflow */
477 bfd_elf_generic_reloc
, /* special_function */
478 "R_ARM_JUMP24", /* name */
479 FALSE
, /* partial_inplace */
480 0x00ffffff, /* src_mask */
481 0x00ffffff, /* dst_mask */
482 TRUE
), /* pcrel_offset */
484 HOWTO (R_ARM_THM_JUMP24
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 TRUE
, /* pc_relative */
490 complain_overflow_signed
,/* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_ARM_THM_JUMP24", /* name */
493 FALSE
, /* partial_inplace */
494 0x07ff2fff, /* src_mask */
495 0x07ff2fff, /* dst_mask */
496 TRUE
), /* pcrel_offset */
498 HOWTO (R_ARM_BASE_ABS
, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_dont
,/* complain_on_overflow */
505 bfd_elf_generic_reloc
, /* special_function */
506 "R_ARM_BASE_ABS", /* name */
507 FALSE
, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 FALSE
), /* pcrel_offset */
512 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 TRUE
, /* pc_relative */
518 complain_overflow_dont
,/* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 "R_ARM_ALU_PCREL_7_0", /* name */
521 FALSE
, /* partial_inplace */
522 0x00000fff, /* src_mask */
523 0x00000fff, /* dst_mask */
524 TRUE
), /* pcrel_offset */
526 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 TRUE
, /* pc_relative */
532 complain_overflow_dont
,/* complain_on_overflow */
533 bfd_elf_generic_reloc
, /* special_function */
534 "R_ARM_ALU_PCREL_15_8",/* name */
535 FALSE
, /* partial_inplace */
536 0x00000fff, /* src_mask */
537 0x00000fff, /* dst_mask */
538 TRUE
), /* pcrel_offset */
540 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 TRUE
, /* pc_relative */
546 complain_overflow_dont
,/* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_ARM_ALU_PCREL_23_15",/* name */
549 FALSE
, /* partial_inplace */
550 0x00000fff, /* src_mask */
551 0x00000fff, /* dst_mask */
552 TRUE
), /* pcrel_offset */
554 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE
, /* pc_relative */
560 complain_overflow_dont
,/* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_ARM_LDR_SBREL_11_0",/* name */
563 FALSE
, /* partial_inplace */
564 0x00000fff, /* src_mask */
565 0x00000fff, /* dst_mask */
566 FALSE
), /* pcrel_offset */
568 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 FALSE
, /* pc_relative */
574 complain_overflow_dont
,/* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 "R_ARM_ALU_SBREL_19_12",/* name */
577 FALSE
, /* partial_inplace */
578 0x000ff000, /* src_mask */
579 0x000ff000, /* dst_mask */
580 FALSE
), /* pcrel_offset */
582 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE
, /* pc_relative */
588 complain_overflow_dont
,/* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 "R_ARM_ALU_SBREL_27_20",/* name */
591 FALSE
, /* partial_inplace */
592 0x0ff00000, /* src_mask */
593 0x0ff00000, /* dst_mask */
594 FALSE
), /* pcrel_offset */
596 HOWTO (R_ARM_TARGET1
, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE
, /* pc_relative */
602 complain_overflow_dont
,/* complain_on_overflow */
603 bfd_elf_generic_reloc
, /* special_function */
604 "R_ARM_TARGET1", /* name */
605 FALSE
, /* partial_inplace */
606 0xffffffff, /* src_mask */
607 0xffffffff, /* dst_mask */
608 FALSE
), /* pcrel_offset */
610 HOWTO (R_ARM_ROSEGREL32
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE
, /* pc_relative */
616 complain_overflow_dont
,/* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_ARM_ROSEGREL32", /* name */
619 FALSE
, /* partial_inplace */
620 0xffffffff, /* src_mask */
621 0xffffffff, /* dst_mask */
622 FALSE
), /* pcrel_offset */
624 HOWTO (R_ARM_V4BX
, /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 FALSE
, /* pc_relative */
630 complain_overflow_dont
,/* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_ARM_V4BX", /* name */
633 FALSE
, /* partial_inplace */
634 0xffffffff, /* src_mask */
635 0xffffffff, /* dst_mask */
636 FALSE
), /* pcrel_offset */
638 HOWTO (R_ARM_TARGET2
, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE
, /* pc_relative */
644 complain_overflow_signed
,/* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 "R_ARM_TARGET2", /* name */
647 FALSE
, /* partial_inplace */
648 0xffffffff, /* src_mask */
649 0xffffffff, /* dst_mask */
650 TRUE
), /* pcrel_offset */
652 HOWTO (R_ARM_PREL31
, /* type */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
656 TRUE
, /* pc_relative */
658 complain_overflow_signed
,/* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_ARM_PREL31", /* name */
661 FALSE
, /* partial_inplace */
662 0x7fffffff, /* src_mask */
663 0x7fffffff, /* dst_mask */
664 TRUE
), /* pcrel_offset */
666 HOWTO (R_ARM_MOVW_ABS_NC
, /* type */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
670 FALSE
, /* pc_relative */
672 complain_overflow_dont
,/* complain_on_overflow */
673 bfd_elf_generic_reloc
, /* special_function */
674 "R_ARM_MOVW_ABS_NC", /* name */
675 FALSE
, /* partial_inplace */
676 0x0000ffff, /* src_mask */
677 0x0000ffff, /* dst_mask */
678 FALSE
), /* pcrel_offset */
680 HOWTO (R_ARM_MOVT_ABS
, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 FALSE
, /* pc_relative */
686 complain_overflow_bitfield
,/* complain_on_overflow */
687 bfd_elf_generic_reloc
, /* special_function */
688 "R_ARM_MOVT_ABS", /* name */
689 FALSE
, /* partial_inplace */
690 0x0000ffff, /* src_mask */
691 0x0000ffff, /* dst_mask */
692 FALSE
), /* pcrel_offset */
694 HOWTO (R_ARM_MOVW_PREL_NC
, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 TRUE
, /* pc_relative */
700 complain_overflow_dont
,/* complain_on_overflow */
701 bfd_elf_generic_reloc
, /* special_function */
702 "R_ARM_MOVW_PREL_NC", /* name */
703 FALSE
, /* partial_inplace */
704 0x0000ffff, /* src_mask */
705 0x0000ffff, /* dst_mask */
706 TRUE
), /* pcrel_offset */
708 HOWTO (R_ARM_MOVT_PREL
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 TRUE
, /* pc_relative */
714 complain_overflow_bitfield
,/* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_ARM_MOVT_PREL", /* name */
717 FALSE
, /* partial_inplace */
718 0x0000ffff, /* src_mask */
719 0x0000ffff, /* dst_mask */
720 TRUE
), /* pcrel_offset */
722 HOWTO (R_ARM_THM_MOVW_ABS_NC
, /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE
, /* pc_relative */
728 complain_overflow_dont
,/* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 "R_ARM_THM_MOVW_ABS_NC",/* name */
731 FALSE
, /* partial_inplace */
732 0x040f70ff, /* src_mask */
733 0x040f70ff, /* dst_mask */
734 FALSE
), /* pcrel_offset */
736 HOWTO (R_ARM_THM_MOVT_ABS
, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE
, /* pc_relative */
742 complain_overflow_bitfield
,/* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_ARM_THM_MOVT_ABS", /* name */
745 FALSE
, /* partial_inplace */
746 0x040f70ff, /* src_mask */
747 0x040f70ff, /* dst_mask */
748 FALSE
), /* pcrel_offset */
750 HOWTO (R_ARM_THM_MOVW_PREL_NC
,/* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 TRUE
, /* pc_relative */
756 complain_overflow_dont
,/* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 "R_ARM_THM_MOVW_PREL_NC",/* name */
759 FALSE
, /* partial_inplace */
760 0x040f70ff, /* src_mask */
761 0x040f70ff, /* dst_mask */
762 TRUE
), /* pcrel_offset */
764 HOWTO (R_ARM_THM_MOVT_PREL
, /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 TRUE
, /* pc_relative */
770 complain_overflow_bitfield
,/* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_ARM_THM_MOVT_PREL", /* name */
773 FALSE
, /* partial_inplace */
774 0x040f70ff, /* src_mask */
775 0x040f70ff, /* dst_mask */
776 TRUE
), /* pcrel_offset */
778 HOWTO (R_ARM_THM_JUMP19
, /* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 TRUE
, /* pc_relative */
784 complain_overflow_signed
,/* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_ARM_THM_JUMP19", /* name */
787 FALSE
, /* partial_inplace */
788 0x043f2fff, /* src_mask */
789 0x043f2fff, /* dst_mask */
790 TRUE
), /* pcrel_offset */
792 HOWTO (R_ARM_THM_JUMP6
, /* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 TRUE
, /* pc_relative */
798 complain_overflow_unsigned
,/* complain_on_overflow */
799 bfd_elf_generic_reloc
, /* special_function */
800 "R_ARM_THM_JUMP6", /* name */
801 FALSE
, /* partial_inplace */
802 0x02f8, /* src_mask */
803 0x02f8, /* dst_mask */
804 TRUE
), /* pcrel_offset */
806 /* These are declared as 13-bit signed relocations because we can
807 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
809 HOWTO (R_ARM_THM_ALU_PREL_11_0
,/* type */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 TRUE
, /* pc_relative */
815 complain_overflow_signed
,/* complain_on_overflow */
816 bfd_elf_generic_reloc
, /* special_function */
817 "R_ARM_THM_ALU_PREL_11_0",/* name */
818 FALSE
, /* partial_inplace */
819 0x040070ff, /* src_mask */
820 0x040070ff, /* dst_mask */
821 TRUE
), /* pcrel_offset */
823 HOWTO (R_ARM_THM_PC12
, /* type */
825 2, /* size (0 = byte, 1 = short, 2 = long) */
827 TRUE
, /* pc_relative */
829 complain_overflow_signed
,/* complain_on_overflow */
830 bfd_elf_generic_reloc
, /* special_function */
831 "R_ARM_THM_PC12", /* name */
832 FALSE
, /* partial_inplace */
833 0x040070ff, /* src_mask */
834 0x040070ff, /* dst_mask */
835 TRUE
), /* pcrel_offset */
837 HOWTO (R_ARM_ABS32_NOI
, /* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE
, /* pc_relative */
843 complain_overflow_dont
,/* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 "R_ARM_ABS32_NOI", /* name */
846 FALSE
, /* partial_inplace */
847 0xffffffff, /* src_mask */
848 0xffffffff, /* dst_mask */
849 FALSE
), /* pcrel_offset */
851 HOWTO (R_ARM_REL32_NOI
, /* type */
853 2, /* size (0 = byte, 1 = short, 2 = long) */
855 TRUE
, /* pc_relative */
857 complain_overflow_dont
,/* complain_on_overflow */
858 bfd_elf_generic_reloc
, /* special_function */
859 "R_ARM_REL32_NOI", /* name */
860 FALSE
, /* partial_inplace */
861 0xffffffff, /* src_mask */
862 0xffffffff, /* dst_mask */
863 FALSE
), /* pcrel_offset */
866 /* Relocations 57 .. 83 are the "group relocations" which we do not
869 static reloc_howto_type elf32_arm_howto_table_2
[] =
871 HOWTO (R_ARM_MOVW_BREL_NC
, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE
, /* pc_relative */
877 complain_overflow_dont
,/* complain_on_overflow */
878 bfd_elf_generic_reloc
, /* special_function */
879 "R_ARM_MOVW_BREL_NC", /* name */
880 FALSE
, /* partial_inplace */
881 0x0000ffff, /* src_mask */
882 0x0000ffff, /* dst_mask */
883 FALSE
), /* pcrel_offset */
885 HOWTO (R_ARM_MOVT_BREL
, /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 FALSE
, /* pc_relative */
891 complain_overflow_bitfield
,/* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 "R_ARM_MOVT_BREL", /* name */
894 FALSE
, /* partial_inplace */
895 0x0000ffff, /* src_mask */
896 0x0000ffff, /* dst_mask */
897 FALSE
), /* pcrel_offset */
899 HOWTO (R_ARM_MOVW_BREL
, /* type */
901 2, /* size (0 = byte, 1 = short, 2 = long) */
903 FALSE
, /* pc_relative */
905 complain_overflow_dont
,/* complain_on_overflow */
906 bfd_elf_generic_reloc
, /* special_function */
907 "R_ARM_MOVW_BREL", /* name */
908 FALSE
, /* partial_inplace */
909 0x0000ffff, /* src_mask */
910 0x0000ffff, /* dst_mask */
911 FALSE
), /* pcrel_offset */
913 HOWTO (R_ARM_THM_MOVW_BREL_NC
,/* type */
915 2, /* size (0 = byte, 1 = short, 2 = long) */
917 FALSE
, /* pc_relative */
919 complain_overflow_dont
,/* complain_on_overflow */
920 bfd_elf_generic_reloc
, /* special_function */
921 "R_ARM_THM_MOVW_BREL_NC",/* name */
922 FALSE
, /* partial_inplace */
923 0x040f70ff, /* src_mask */
924 0x040f70ff, /* dst_mask */
925 FALSE
), /* pcrel_offset */
927 HOWTO (R_ARM_THM_MOVT_BREL
, /* type */
929 2, /* size (0 = byte, 1 = short, 2 = long) */
931 FALSE
, /* pc_relative */
933 complain_overflow_bitfield
,/* complain_on_overflow */
934 bfd_elf_generic_reloc
, /* special_function */
935 "R_ARM_THM_MOVT_BREL", /* name */
936 FALSE
, /* partial_inplace */
937 0x040f70ff, /* src_mask */
938 0x040f70ff, /* dst_mask */
939 FALSE
), /* pcrel_offset */
941 HOWTO (R_ARM_THM_MOVW_BREL
, /* type */
943 2, /* size (0 = byte, 1 = short, 2 = long) */
945 FALSE
, /* pc_relative */
947 complain_overflow_dont
,/* complain_on_overflow */
948 bfd_elf_generic_reloc
, /* special_function */
949 "R_ARM_THM_MOVW_BREL", /* name */
950 FALSE
, /* partial_inplace */
951 0x040f70ff, /* src_mask */
952 0x040f70ff, /* dst_mask */
953 FALSE
), /* pcrel_offset */
955 EMPTY_HOWTO (90), /* unallocated */
960 HOWTO (R_ARM_PLT32_ABS
, /* type */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
,/* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 "R_ARM_PLT32_ABS", /* name */
969 FALSE
, /* partial_inplace */
970 0xffffffff, /* src_mask */
971 0xffffffff, /* dst_mask */
972 FALSE
), /* pcrel_offset */
974 HOWTO (R_ARM_GOT_ABS
, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 FALSE
, /* pc_relative */
980 complain_overflow_dont
,/* complain_on_overflow */
981 bfd_elf_generic_reloc
, /* special_function */
982 "R_ARM_GOT_ABS", /* name */
983 FALSE
, /* partial_inplace */
984 0xffffffff, /* src_mask */
985 0xffffffff, /* dst_mask */
986 FALSE
), /* pcrel_offset */
988 HOWTO (R_ARM_GOT_PREL
, /* type */
990 2, /* size (0 = byte, 1 = short, 2 = long) */
992 TRUE
, /* pc_relative */
994 complain_overflow_dont
, /* complain_on_overflow */
995 bfd_elf_generic_reloc
, /* special_function */
996 "R_ARM_GOT_PREL", /* name */
997 FALSE
, /* partial_inplace */
998 0xffffffff, /* src_mask */
999 0xffffffff, /* dst_mask */
1000 TRUE
), /* pcrel_offset */
1002 HOWTO (R_ARM_GOT_BREL12
, /* type */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1006 FALSE
, /* pc_relative */
1008 complain_overflow_bitfield
,/* complain_on_overflow */
1009 bfd_elf_generic_reloc
, /* special_function */
1010 "R_ARM_GOT_BREL12", /* name */
1011 FALSE
, /* partial_inplace */
1012 0x00000fff, /* src_mask */
1013 0x00000fff, /* dst_mask */
1014 FALSE
), /* pcrel_offset */
1016 HOWTO (R_ARM_GOTOFF12
, /* type */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE
, /* pc_relative */
1022 complain_overflow_bitfield
,/* complain_on_overflow */
1023 bfd_elf_generic_reloc
, /* special_function */
1024 "R_ARM_GOTOFF12", /* name */
1025 FALSE
, /* partial_inplace */
1026 0x00000fff, /* src_mask */
1027 0x00000fff, /* dst_mask */
1028 FALSE
), /* pcrel_offset */
1030 EMPTY_HOWTO (R_ARM_GOTRELAX
), /* reserved for future GOT-load optimizations */
1032 /* GNU extension to record C++ vtable member usage */
1033 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
1035 2, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE
, /* pc_relative */
1039 complain_overflow_dont
, /* complain_on_overflow */
1040 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
1041 "R_ARM_GNU_VTENTRY", /* name */
1042 FALSE
, /* partial_inplace */
1045 FALSE
), /* pcrel_offset */
1047 /* GNU extension to record C++ vtable hierarchy */
1048 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1052 FALSE
, /* pc_relative */
1054 complain_overflow_dont
, /* complain_on_overflow */
1055 NULL
, /* special_function */
1056 "R_ARM_GNU_VTINHERIT", /* name */
1057 FALSE
, /* partial_inplace */
1060 FALSE
), /* pcrel_offset */
1062 HOWTO (R_ARM_THM_JUMP11
, /* type */
1064 1, /* size (0 = byte, 1 = short, 2 = long) */
1066 TRUE
, /* pc_relative */
1068 complain_overflow_signed
, /* complain_on_overflow */
1069 bfd_elf_generic_reloc
, /* special_function */
1070 "R_ARM_THM_JUMP11", /* name */
1071 FALSE
, /* partial_inplace */
1072 0x000007ff, /* src_mask */
1073 0x000007ff, /* dst_mask */
1074 TRUE
), /* pcrel_offset */
1076 HOWTO (R_ARM_THM_JUMP8
, /* type */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 TRUE
, /* pc_relative */
1082 complain_overflow_signed
, /* complain_on_overflow */
1083 bfd_elf_generic_reloc
, /* special_function */
1084 "R_ARM_THM_JUMP8", /* name */
1085 FALSE
, /* partial_inplace */
1086 0x000000ff, /* src_mask */
1087 0x000000ff, /* dst_mask */
1088 TRUE
), /* pcrel_offset */
1090 /* TLS relocations */
1091 HOWTO (R_ARM_TLS_GD32
, /* type */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_bitfield
,/* complain_on_overflow */
1098 NULL
, /* special_function */
1099 "R_ARM_TLS_GD32", /* name */
1100 TRUE
, /* partial_inplace */
1101 0xffffffff, /* src_mask */
1102 0xffffffff, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 HOWTO (R_ARM_TLS_LDM32
, /* type */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_bitfield
,/* complain_on_overflow */
1112 bfd_elf_generic_reloc
, /* special_function */
1113 "R_ARM_TLS_LDM32", /* name */
1114 TRUE
, /* partial_inplace */
1115 0xffffffff, /* src_mask */
1116 0xffffffff, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 HOWTO (R_ARM_TLS_LDO32
, /* type */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1123 FALSE
, /* pc_relative */
1125 complain_overflow_bitfield
,/* complain_on_overflow */
1126 bfd_elf_generic_reloc
, /* special_function */
1127 "R_ARM_TLS_LDO32", /* name */
1128 TRUE
, /* partial_inplace */
1129 0xffffffff, /* src_mask */
1130 0xffffffff, /* dst_mask */
1131 FALSE
), /* pcrel_offset */
1133 HOWTO (R_ARM_TLS_IE32
, /* type */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE
, /* pc_relative */
1139 complain_overflow_bitfield
,/* complain_on_overflow */
1140 NULL
, /* special_function */
1141 "R_ARM_TLS_IE32", /* name */
1142 TRUE
, /* partial_inplace */
1143 0xffffffff, /* src_mask */
1144 0xffffffff, /* dst_mask */
1145 FALSE
), /* pcrel_offset */
1147 HOWTO (R_ARM_TLS_LE32
, /* type */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1151 FALSE
, /* pc_relative */
1153 complain_overflow_bitfield
,/* complain_on_overflow */
1154 bfd_elf_generic_reloc
, /* special_function */
1155 "R_ARM_TLS_LE32", /* name */
1156 TRUE
, /* partial_inplace */
1157 0xffffffff, /* src_mask */
1158 0xffffffff, /* dst_mask */
1159 FALSE
), /* pcrel_offset */
1161 HOWTO (R_ARM_TLS_LDO12
, /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE
, /* pc_relative */
1167 complain_overflow_bitfield
,/* complain_on_overflow */
1168 bfd_elf_generic_reloc
, /* special_function */
1169 "R_ARM_TLS_LDO12", /* name */
1170 FALSE
, /* partial_inplace */
1171 0x00000fff, /* src_mask */
1172 0x00000fff, /* dst_mask */
1173 FALSE
), /* pcrel_offset */
1175 HOWTO (R_ARM_TLS_LE12
, /* type */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE
, /* pc_relative */
1181 complain_overflow_bitfield
,/* complain_on_overflow */
1182 bfd_elf_generic_reloc
, /* special_function */
1183 "R_ARM_TLS_LE12", /* name */
1184 FALSE
, /* partial_inplace */
1185 0x00000fff, /* src_mask */
1186 0x00000fff, /* dst_mask */
1187 FALSE
), /* pcrel_offset */
1189 HOWTO (R_ARM_TLS_IE12GP
, /* type */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1193 FALSE
, /* pc_relative */
1195 complain_overflow_bitfield
,/* complain_on_overflow */
1196 bfd_elf_generic_reloc
, /* special_function */
1197 "R_ARM_TLS_IE12GP", /* name */
1198 FALSE
, /* partial_inplace */
1199 0x00000fff, /* src_mask */
1200 0x00000fff, /* dst_mask */
1201 FALSE
), /* pcrel_offset */
1204 /* 112-127 private relocations
1205 128 R_ARM_ME_TOO, obsolete
1206 129-255 unallocated in AAELF.
1208 249-255 extended, currently unused, relocations: */
1210 static reloc_howto_type elf32_arm_howto_table_3
[4] =
1212 HOWTO (R_ARM_RREL32
, /* type */
1214 0, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_dont
,/* complain_on_overflow */
1219 bfd_elf_generic_reloc
, /* special_function */
1220 "R_ARM_RREL32", /* name */
1221 FALSE
, /* partial_inplace */
1224 FALSE
), /* pcrel_offset */
1226 HOWTO (R_ARM_RABS32
, /* type */
1228 0, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE
, /* pc_relative */
1232 complain_overflow_dont
,/* complain_on_overflow */
1233 bfd_elf_generic_reloc
, /* special_function */
1234 "R_ARM_RABS32", /* name */
1235 FALSE
, /* partial_inplace */
1238 FALSE
), /* pcrel_offset */
1240 HOWTO (R_ARM_RPC24
, /* type */
1242 0, /* size (0 = byte, 1 = short, 2 = long) */
1244 FALSE
, /* pc_relative */
1246 complain_overflow_dont
,/* complain_on_overflow */
1247 bfd_elf_generic_reloc
, /* special_function */
1248 "R_ARM_RPC24", /* name */
1249 FALSE
, /* partial_inplace */
1252 FALSE
), /* pcrel_offset */
1254 HOWTO (R_ARM_RBASE
, /* type */
1256 0, /* size (0 = byte, 1 = short, 2 = long) */
1258 FALSE
, /* pc_relative */
1260 complain_overflow_dont
,/* complain_on_overflow */
1261 bfd_elf_generic_reloc
, /* special_function */
1262 "R_ARM_RBASE", /* name */
1263 FALSE
, /* partial_inplace */
1266 FALSE
) /* pcrel_offset */
1269 static reloc_howto_type
*
1270 elf32_arm_howto_from_type (unsigned int r_type
)
1272 if (r_type
< NUM_ELEM (elf32_arm_howto_table_1
))
1273 return &elf32_arm_howto_table_1
[r_type
];
1275 if (r_type
>= R_ARM_MOVW_BREL_NC
1276 && r_type
< R_ARM_MOVW_BREL_NC
+ NUM_ELEM (elf32_arm_howto_table_2
))
1277 return &elf32_arm_howto_table_2
[r_type
- R_ARM_MOVW_BREL_NC
];
1279 if (r_type
>= R_ARM_RREL32
1280 && r_type
< R_ARM_RREL32
+ NUM_ELEM (elf32_arm_howto_table_2
))
1281 return &elf32_arm_howto_table_3
[r_type
- R_ARM_RREL32
];
1287 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
1288 Elf_Internal_Rela
* elf_reloc
)
1290 unsigned int r_type
;
1292 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
1293 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
1296 struct elf32_arm_reloc_map
1298 bfd_reloc_code_real_type bfd_reloc_val
;
1299 unsigned char elf_reloc_val
;
1302 /* All entries in this list must also be present in elf32_arm_howto_table. */
1303 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
1305 {BFD_RELOC_NONE
, R_ARM_NONE
},
1306 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
1307 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
1308 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
1309 {BFD_RELOC_32
, R_ARM_ABS32
},
1310 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
1311 {BFD_RELOC_8
, R_ARM_ABS8
},
1312 {BFD_RELOC_16
, R_ARM_ABS16
},
1313 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
1314 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
1315 {BFD_RELOC_THUMB_PCREL_BRANCH25
, R_ARM_THM_JUMP24
},
1316 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_CALL
},
1317 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_JUMP11
},
1318 {BFD_RELOC_THUMB_PCREL_BRANCH20
, R_ARM_THM_JUMP19
},
1319 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_JUMP8
},
1320 {BFD_RELOC_THUMB_PCREL_BRANCH7
, R_ARM_THM_JUMP6
},
1321 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
1322 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
1323 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
1324 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF32
},
1325 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
1326 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
1327 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1328 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
1329 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
1330 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
1331 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
1332 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
},
1333 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
1334 {BFD_RELOC_ARM_TLS_GD32
, R_ARM_TLS_GD32
},
1335 {BFD_RELOC_ARM_TLS_LDO32
, R_ARM_TLS_LDO32
},
1336 {BFD_RELOC_ARM_TLS_LDM32
, R_ARM_TLS_LDM32
},
1337 {BFD_RELOC_ARM_TLS_DTPMOD32
, R_ARM_TLS_DTPMOD32
},
1338 {BFD_RELOC_ARM_TLS_DTPOFF32
, R_ARM_TLS_DTPOFF32
},
1339 {BFD_RELOC_ARM_TLS_TPOFF32
, R_ARM_TLS_TPOFF32
},
1340 {BFD_RELOC_ARM_TLS_IE32
, R_ARM_TLS_IE32
},
1341 {BFD_RELOC_ARM_TLS_LE32
, R_ARM_TLS_LE32
},
1342 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
1343 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
1346 static reloc_howto_type
*
1347 elf32_arm_reloc_type_lookup (abfd
, code
)
1348 bfd
*abfd ATTRIBUTE_UNUSED
;
1349 bfd_reloc_code_real_type code
;
1352 for (i
= 0; i
< NUM_ELEM (elf32_arm_reloc_map
); i
++)
1353 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
1354 return elf32_arm_howto_from_type (elf32_arm_reloc_map
[i
].elf_reloc_val
);
1359 /* Support for core dump NOTE sections */
1361 elf32_arm_nabi_grok_prstatus (abfd
, note
)
1363 Elf_Internal_Note
*note
;
1368 switch (note
->descsz
)
1373 case 148: /* Linux/ARM 32-bit*/
1375 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1378 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1387 /* Make a ".reg/999" section. */
1388 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1389 size
, note
->descpos
+ offset
);
1393 elf32_arm_nabi_grok_psinfo (abfd
, note
)
1395 Elf_Internal_Note
*note
;
1397 switch (note
->descsz
)
1402 case 124: /* Linux/ARM elf_prpsinfo */
1403 elf_tdata (abfd
)->core_program
1404 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
1405 elf_tdata (abfd
)->core_command
1406 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
1409 /* Note that for some reason, a spurious space is tacked
1410 onto the end of the args in some (at least one anyway)
1411 implementations, so strip it off if it exists. */
1414 char *command
= elf_tdata (abfd
)->core_command
;
1415 int n
= strlen (command
);
1417 if (0 < n
&& command
[n
- 1] == ' ')
1418 command
[n
- 1] = '\0';
1424 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1425 #define TARGET_LITTLE_NAME "elf32-littlearm"
1426 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1427 #define TARGET_BIG_NAME "elf32-bigarm"
1429 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1430 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1432 typedef unsigned long int insn32
;
1433 typedef unsigned short int insn16
;
1435 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
1436 #define INTERWORK_FLAG(abfd) \
1437 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
1438 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1440 /* The linker script knows the section names for placement.
1441 The entry_names are used to do simple name mangling on the stubs.
1442 Given a function name, and its type, the stub can be found. The
1443 name can be changed. The only requirement is the %s be present. */
1444 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1445 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1447 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1448 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1450 /* The name of the dynamic interpreter. This is put in the .interp
1452 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1454 #ifdef FOUR_WORD_PLT
1456 /* The first entry in a procedure linkage table looks like
1457 this. It is set up so that any shared library function that is
1458 called before the relocation has been set up calls the dynamic
1460 static const bfd_vma elf32_arm_plt0_entry
[] =
1462 0xe52de004, /* str lr, [sp, #-4]! */
1463 0xe59fe010, /* ldr lr, [pc, #16] */
1464 0xe08fe00e, /* add lr, pc, lr */
1465 0xe5bef008, /* ldr pc, [lr, #8]! */
1468 /* Subsequent entries in a procedure linkage table look like
1470 static const bfd_vma elf32_arm_plt_entry
[] =
1472 0xe28fc600, /* add ip, pc, #NN */
1473 0xe28cca00, /* add ip, ip, #NN */
1474 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1475 0x00000000, /* unused */
1480 /* The first entry in a procedure linkage table looks like
1481 this. It is set up so that any shared library function that is
1482 called before the relocation has been set up calls the dynamic
1484 static const bfd_vma elf32_arm_plt0_entry
[] =
1486 0xe52de004, /* str lr, [sp, #-4]! */
1487 0xe59fe004, /* ldr lr, [pc, #4] */
1488 0xe08fe00e, /* add lr, pc, lr */
1489 0xe5bef008, /* ldr pc, [lr, #8]! */
1490 0x00000000, /* &GOT[0] - . */
1493 /* Subsequent entries in a procedure linkage table look like
1495 static const bfd_vma elf32_arm_plt_entry
[] =
1497 0xe28fc600, /* add ip, pc, #0xNN00000 */
1498 0xe28cca00, /* add ip, ip, #0xNN000 */
1499 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1504 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1505 #define PLT_THUMB_STUB_SIZE 4
1506 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
1512 /* The entries in a PLT when using a DLL-based target with multiple
1514 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
1516 0xe51ff004, /* ldr pc, [pc, #-4] */
1517 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1520 /* Used to build a map of a section. This is required for mixed-endian
1523 typedef struct elf32_elf_section_map
1528 elf32_arm_section_map
;
1530 struct _arm_elf_section_data
1532 struct bfd_elf_section_data elf
;
1534 elf32_arm_section_map
*map
;
1537 #define elf32_arm_section_data(sec) \
1538 ((struct _arm_elf_section_data *) elf_section_data (sec))
1540 /* The size of the thread control block. */
1543 struct elf32_arm_obj_tdata
1545 struct elf_obj_tdata root
;
1547 /* tls_type for each local got entry. */
1548 char *local_got_tls_type
;
1551 #define elf32_arm_tdata(abfd) \
1552 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1554 #define elf32_arm_local_got_tls_type(abfd) \
1555 (elf32_arm_tdata (abfd)->local_got_tls_type)
1558 elf32_arm_mkobject (bfd
*abfd
)
1560 bfd_size_type amt
= sizeof (struct elf32_arm_obj_tdata
);
1561 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
1562 if (abfd
->tdata
.any
== NULL
)
1567 /* The ARM linker needs to keep track of the number of relocs that it
1568 decides to copy in check_relocs for each symbol. This is so that
1569 it can discard PC relative relocs if it doesn't need them when
1570 linking with -Bsymbolic. We store the information in a field
1571 extending the regular ELF linker hash table. */
1573 /* This structure keeps track of the number of relocs we have copied
1574 for a given symbol. */
1575 struct elf32_arm_relocs_copied
1578 struct elf32_arm_relocs_copied
* next
;
1579 /* A section in dynobj. */
1581 /* Number of relocs copied in this section. */
1582 bfd_size_type count
;
1583 /* Number of PC-relative relocs copied in this section. */
1584 bfd_size_type pc_count
;
1587 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1589 /* Arm ELF linker hash entry. */
1590 struct elf32_arm_link_hash_entry
1592 struct elf_link_hash_entry root
;
1594 /* Number of PC relative relocs copied for this symbol. */
1595 struct elf32_arm_relocs_copied
* relocs_copied
;
1597 /* We reference count Thumb references to a PLT entry separately,
1598 so that we can emit the Thumb trampoline only if needed. */
1599 bfd_signed_vma plt_thumb_refcount
;
1601 /* Since PLT entries have variable size if the Thumb prologue is
1602 used, we need to record the index into .got.plt instead of
1603 recomputing it from the PLT offset. */
1604 bfd_signed_vma plt_got_offset
;
1606 #define GOT_UNKNOWN 0
1607 #define GOT_NORMAL 1
1608 #define GOT_TLS_GD 2
1609 #define GOT_TLS_IE 4
1610 unsigned char tls_type
;
1613 /* Traverse an arm ELF linker hash table. */
1614 #define elf32_arm_link_hash_traverse(table, func, info) \
1615 (elf_link_hash_traverse \
1617 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1620 /* Get the ARM elf linker hash table from a link_info structure. */
1621 #define elf32_arm_hash_table(info) \
1622 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1624 /* ARM ELF linker hash table. */
1625 struct elf32_arm_link_hash_table
1627 /* The main hash table. */
1628 struct elf_link_hash_table root
;
1630 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1631 bfd_size_type thumb_glue_size
;
1633 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1634 bfd_size_type arm_glue_size
;
1636 /* An arbitrary input BFD chosen to hold the glue sections. */
1637 bfd
* bfd_of_glue_owner
;
1639 /* Nonzero to output a BE8 image. */
1642 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1643 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1646 /* The relocation to use for R_ARM_TARGET2 relocations. */
1649 /* Nonzero to fix BX instructions for ARMv4 targets. */
1652 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1655 /* The number of bytes in the initial entry in the PLT. */
1656 bfd_size_type plt_header_size
;
1658 /* The number of bytes in the subsequent PLT etries. */
1659 bfd_size_type plt_entry_size
;
1661 /* True if the target system is Symbian OS. */
1664 /* True if the target uses REL relocations. */
1667 /* Short-cuts to get to dynamic linker sections. */
1676 /* Data for R_ARM_TLS_LDM32 relocations. */
1678 bfd_signed_vma refcount
;
1682 /* Small local sym to section mapping cache. */
1683 struct sym_sec_cache sym_sec
;
1685 /* For convenience in allocate_dynrelocs. */
1689 /* Create an entry in an ARM ELF linker hash table. */
1691 static struct bfd_hash_entry
*
1692 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
1693 struct bfd_hash_table
* table
,
1694 const char * string
)
1696 struct elf32_arm_link_hash_entry
* ret
=
1697 (struct elf32_arm_link_hash_entry
*) entry
;
1699 /* Allocate the structure if it has not already been allocated by a
1701 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
1702 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
1704 return (struct bfd_hash_entry
*) ret
;
1706 /* Call the allocation method of the superclass. */
1707 ret
= ((struct elf32_arm_link_hash_entry
*)
1708 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1712 ret
->relocs_copied
= NULL
;
1713 ret
->tls_type
= GOT_UNKNOWN
;
1714 ret
->plt_thumb_refcount
= 0;
1715 ret
->plt_got_offset
= -1;
1718 return (struct bfd_hash_entry
*) ret
;
1721 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1722 shortcuts to them in our hash table. */
1725 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
1727 struct elf32_arm_link_hash_table
*htab
;
1729 htab
= elf32_arm_hash_table (info
);
1730 /* BPABI objects never have a GOT, or associated sections. */
1731 if (htab
->symbian_p
)
1734 if (! _bfd_elf_create_got_section (dynobj
, info
))
1737 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1738 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1739 if (!htab
->sgot
|| !htab
->sgotplt
)
1742 htab
->srelgot
= bfd_make_section_with_flags (dynobj
, ".rel.got",
1743 (SEC_ALLOC
| SEC_LOAD
1746 | SEC_LINKER_CREATED
1748 if (htab
->srelgot
== NULL
1749 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
1754 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1755 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1759 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1761 struct elf32_arm_link_hash_table
*htab
;
1763 htab
= elf32_arm_hash_table (info
);
1764 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
1767 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1770 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
1771 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
1772 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1774 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
1779 || (!info
->shared
&& !htab
->srelbss
))
1785 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1788 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
1789 struct elf_link_hash_entry
*dir
,
1790 struct elf_link_hash_entry
*ind
)
1792 struct elf32_arm_link_hash_entry
*edir
, *eind
;
1794 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
1795 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
1797 if (eind
->relocs_copied
!= NULL
)
1799 if (edir
->relocs_copied
!= NULL
)
1801 struct elf32_arm_relocs_copied
**pp
;
1802 struct elf32_arm_relocs_copied
*p
;
1804 if (ind
->root
.type
== bfd_link_hash_indirect
)
1807 /* Add reloc counts against the weak sym to the strong sym
1808 list. Merge any entries against the same section. */
1809 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
1811 struct elf32_arm_relocs_copied
*q
;
1813 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
1814 if (q
->section
== p
->section
)
1816 q
->pc_count
+= p
->pc_count
;
1817 q
->count
+= p
->count
;
1824 *pp
= edir
->relocs_copied
;
1827 edir
->relocs_copied
= eind
->relocs_copied
;
1828 eind
->relocs_copied
= NULL
;
1831 /* If the direct symbol already has an associated PLT entry, the
1832 indirect symbol should not. If it doesn't, swap refcount information
1833 from the indirect symbol. */
1834 if (edir
->plt_thumb_refcount
== 0)
1836 edir
->plt_thumb_refcount
= eind
->plt_thumb_refcount
;
1837 eind
->plt_thumb_refcount
= 0;
1840 BFD_ASSERT (eind
->plt_thumb_refcount
== 0);
1842 if (ind
->root
.type
== bfd_link_hash_indirect
1843 && dir
->got
.refcount
<= 0)
1845 edir
->tls_type
= eind
->tls_type
;
1846 eind
->tls_type
= GOT_UNKNOWN
;
1849 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
1852 /* Create an ARM elf linker hash table. */
1854 static struct bfd_link_hash_table
*
1855 elf32_arm_link_hash_table_create (bfd
*abfd
)
1857 struct elf32_arm_link_hash_table
*ret
;
1858 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
1860 ret
= bfd_malloc (amt
);
1864 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
1865 elf32_arm_link_hash_newfunc
))
1872 ret
->sgotplt
= NULL
;
1873 ret
->srelgot
= NULL
;
1875 ret
->srelplt
= NULL
;
1876 ret
->sdynbss
= NULL
;
1877 ret
->srelbss
= NULL
;
1878 ret
->thumb_glue_size
= 0;
1879 ret
->arm_glue_size
= 0;
1880 ret
->bfd_of_glue_owner
= NULL
;
1881 ret
->byteswap_code
= 0;
1882 ret
->target1_is_rel
= 0;
1883 ret
->target2_reloc
= R_ARM_NONE
;
1884 #ifdef FOUR_WORD_PLT
1885 ret
->plt_header_size
= 16;
1886 ret
->plt_entry_size
= 16;
1888 ret
->plt_header_size
= 20;
1889 ret
->plt_entry_size
= 12;
1895 ret
->sym_sec
.abfd
= NULL
;
1897 ret
->tls_ldm_got
.refcount
= 0;
1899 return &ret
->root
.root
;
1902 /* Locate the Thumb encoded calling stub for NAME. */
1904 static struct elf_link_hash_entry
*
1905 find_thumb_glue (struct bfd_link_info
*link_info
,
1910 struct elf_link_hash_entry
*hash
;
1911 struct elf32_arm_link_hash_table
*hash_table
;
1913 /* We need a pointer to the armelf specific hash table. */
1914 hash_table
= elf32_arm_hash_table (link_info
);
1916 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1917 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
1919 BFD_ASSERT (tmp_name
);
1921 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
1923 hash
= elf_link_hash_lookup
1924 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1927 /* xgettext:c-format */
1928 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1929 input_bfd
, tmp_name
, name
);
1936 /* Locate the ARM encoded calling stub for NAME. */
1938 static struct elf_link_hash_entry
*
1939 find_arm_glue (struct bfd_link_info
*link_info
,
1944 struct elf_link_hash_entry
*myh
;
1945 struct elf32_arm_link_hash_table
*hash_table
;
1947 /* We need a pointer to the elfarm specific hash table. */
1948 hash_table
= elf32_arm_hash_table (link_info
);
1950 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1951 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
1953 BFD_ASSERT (tmp_name
);
1955 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
1957 myh
= elf_link_hash_lookup
1958 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1961 /* xgettext:c-format */
1962 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
1963 input_bfd
, tmp_name
, name
);
1970 /* ARM->Thumb glue (static images):
1974 ldr r12, __func_addr
1977 .word func @ behave as if you saw a ARM_32 reloc.
1979 (relocatable images)
1982 ldr r12, __func_offset
1989 #define ARM2THUMB_STATIC_GLUE_SIZE 12
1990 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
1991 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
1992 static const insn32 a2t3_func_addr_insn
= 0x00000001;
1994 #define ARM2THUMB_PIC_GLUE_SIZE 16
1995 static const insn32 a2t1p_ldr_insn
= 0xe59fc004;
1996 static const insn32 a2t2p_add_pc_insn
= 0xe08cc00f;
1997 static const insn32 a2t3p_bx_r12_insn
= 0xe12fff1c;
1999 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2003 __func_from_thumb: __func_from_thumb:
2005 nop ldr r6, __func_addr
2007 __func_change_to_arm: bx r6
2009 __func_back_to_thumb:
2015 #define THUMB2ARM_GLUE_SIZE 8
2016 static const insn16 t2a1_bx_pc_insn
= 0x4778;
2017 static const insn16 t2a2_noop_insn
= 0x46c0;
2018 static const insn32 t2a3_b_insn
= 0xea000000;
2020 #ifndef ELFARM_NABI_C_INCLUDED
2022 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
2026 struct elf32_arm_link_hash_table
* globals
;
2028 globals
= elf32_arm_hash_table (info
);
2030 BFD_ASSERT (globals
!= NULL
);
2032 if (globals
->arm_glue_size
!= 0)
2034 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2036 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2037 ARM2THUMB_GLUE_SECTION_NAME
);
2039 BFD_ASSERT (s
!= NULL
);
2041 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
2043 s
->size
= globals
->arm_glue_size
;
2047 if (globals
->thumb_glue_size
!= 0)
2049 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2051 s
= bfd_get_section_by_name
2052 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2054 BFD_ASSERT (s
!= NULL
);
2056 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
2058 s
->size
= globals
->thumb_glue_size
;
2066 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
2067 struct elf_link_hash_entry
* h
)
2069 const char * name
= h
->root
.root
.string
;
2072 struct elf_link_hash_entry
* myh
;
2073 struct bfd_link_hash_entry
* bh
;
2074 struct elf32_arm_link_hash_table
* globals
;
2077 globals
= elf32_arm_hash_table (link_info
);
2079 BFD_ASSERT (globals
!= NULL
);
2080 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2082 s
= bfd_get_section_by_name
2083 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
2085 BFD_ASSERT (s
!= NULL
);
2087 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
2089 BFD_ASSERT (tmp_name
);
2091 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
2093 myh
= elf_link_hash_lookup
2094 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2098 /* We've already seen this guy. */
2103 /* The only trick here is using hash_table->arm_glue_size as the value.
2104 Even though the section isn't allocated yet, this is where we will be
2107 val
= globals
->arm_glue_size
+ 1;
2108 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
2109 tmp_name
, BSF_GLOBAL
, s
, val
,
2110 NULL
, TRUE
, FALSE
, &bh
);
2112 myh
= (struct elf_link_hash_entry
*) bh
;
2113 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
2114 myh
->forced_local
= 1;
2118 if ((link_info
->shared
|| globals
->root
.is_relocatable_executable
))
2119 globals
->arm_glue_size
+= ARM2THUMB_PIC_GLUE_SIZE
;
2121 globals
->arm_glue_size
+= ARM2THUMB_STATIC_GLUE_SIZE
;
2127 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
2128 struct elf_link_hash_entry
*h
)
2130 const char *name
= h
->root
.root
.string
;
2133 struct elf_link_hash_entry
*myh
;
2134 struct bfd_link_hash_entry
*bh
;
2135 struct elf32_arm_link_hash_table
*hash_table
;
2138 hash_table
= elf32_arm_hash_table (link_info
);
2140 BFD_ASSERT (hash_table
!= NULL
);
2141 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
2143 s
= bfd_get_section_by_name
2144 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2146 BFD_ASSERT (s
!= NULL
);
2148 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2149 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
2151 BFD_ASSERT (tmp_name
);
2153 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
2155 myh
= elf_link_hash_lookup
2156 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
2160 /* We've already seen this guy. */
2166 val
= hash_table
->thumb_glue_size
+ 1;
2167 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2168 tmp_name
, BSF_GLOBAL
, s
, val
,
2169 NULL
, TRUE
, FALSE
, &bh
);
2171 /* If we mark it 'Thumb', the disassembler will do a better job. */
2172 myh
= (struct elf_link_hash_entry
*) bh
;
2173 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
2174 myh
->forced_local
= 1;
2178 #define CHANGE_TO_ARM "__%s_change_to_arm"
2179 #define BACK_FROM_ARM "__%s_back_from_arm"
2181 /* Allocate another symbol to mark where we switch to Arm mode. */
2182 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
2183 + strlen (CHANGE_TO_ARM
) + 1);
2185 BFD_ASSERT (tmp_name
);
2187 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
2190 val
= hash_table
->thumb_glue_size
+ 4,
2191 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
2192 tmp_name
, BSF_LOCAL
, s
, val
,
2193 NULL
, TRUE
, FALSE
, &bh
);
2197 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
2202 /* Add the glue sections to ABFD. This function is called from the
2203 linker scripts in ld/emultempl/{armelf}.em. */
2206 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
2207 struct bfd_link_info
*info
)
2212 /* If we are only performing a partial
2213 link do not bother adding the glue. */
2214 if (info
->relocatable
)
2217 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
2221 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2222 will prevent elf_link_input_bfd() from processing the contents
2224 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
2226 sec
= bfd_make_section_with_flags (abfd
,
2227 ARM2THUMB_GLUE_SECTION_NAME
,
2231 || !bfd_set_section_alignment (abfd
, sec
, 2))
2234 /* Set the gc mark to prevent the section from being removed by garbage
2235 collection, despite the fact that no relocs refer to this section. */
2239 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
2243 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2244 | SEC_CODE
| SEC_READONLY
;
2246 sec
= bfd_make_section_with_flags (abfd
,
2247 THUMB2ARM_GLUE_SECTION_NAME
,
2251 || !bfd_set_section_alignment (abfd
, sec
, 2))
2260 /* Select a BFD to be used to hold the sections used by the glue code.
2261 This function is called from the linker scripts in ld/emultempl/
2265 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
2267 struct elf32_arm_link_hash_table
*globals
;
2269 /* If we are only performing a partial link
2270 do not bother getting a bfd to hold the glue. */
2271 if (info
->relocatable
)
2274 /* Make sure we don't attach the glue sections to a dynamic object. */
2275 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
2277 globals
= elf32_arm_hash_table (info
);
2279 BFD_ASSERT (globals
!= NULL
);
2281 if (globals
->bfd_of_glue_owner
!= NULL
)
2284 /* Save the bfd for later use. */
2285 globals
->bfd_of_glue_owner
= abfd
;
2291 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
2292 struct bfd_link_info
*link_info
,
2295 Elf_Internal_Shdr
*symtab_hdr
;
2296 Elf_Internal_Rela
*internal_relocs
= NULL
;
2297 Elf_Internal_Rela
*irel
, *irelend
;
2298 bfd_byte
*contents
= NULL
;
2301 struct elf32_arm_link_hash_table
*globals
;
2303 /* If we are only performing a partial link do not bother
2304 to construct any glue. */
2305 if (link_info
->relocatable
)
2308 /* Here we have a bfd that is to be included on the link. We have a hook
2309 to do reloc rummaging, before section sizes are nailed down. */
2310 globals
= elf32_arm_hash_table (link_info
);
2312 BFD_ASSERT (globals
!= NULL
);
2313 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2315 if (byteswap_code
&& !bfd_big_endian (abfd
))
2317 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2321 globals
->byteswap_code
= byteswap_code
;
2323 /* Rummage around all the relocs and map the glue vectors. */
2324 sec
= abfd
->sections
;
2329 for (; sec
!= NULL
; sec
= sec
->next
)
2331 if (sec
->reloc_count
== 0)
2334 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2336 /* Load the relocs. */
2338 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
2339 (Elf_Internal_Rela
*) NULL
, FALSE
);
2341 if (internal_relocs
== NULL
)
2344 irelend
= internal_relocs
+ sec
->reloc_count
;
2345 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2348 unsigned long r_index
;
2350 struct elf_link_hash_entry
*h
;
2352 r_type
= ELF32_R_TYPE (irel
->r_info
);
2353 r_index
= ELF32_R_SYM (irel
->r_info
);
2355 /* These are the only relocation types we care about. */
2356 if ( r_type
!= R_ARM_PC24
2357 && r_type
!= R_ARM_PLT32
2358 && r_type
!= R_ARM_CALL
2359 && r_type
!= R_ARM_JUMP24
2360 && r_type
!= R_ARM_THM_CALL
)
2363 /* Get the section contents if we haven't done so already. */
2364 if (contents
== NULL
)
2366 /* Get cached copy if it exists. */
2367 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2368 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2371 /* Go get them off disk. */
2372 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2377 /* If the relocation is not against a symbol it cannot concern us. */
2380 /* We don't care about local symbols. */
2381 if (r_index
< symtab_hdr
->sh_info
)
2384 /* This is an external symbol. */
2385 r_index
-= symtab_hdr
->sh_info
;
2386 h
= (struct elf_link_hash_entry
*)
2387 elf_sym_hashes (abfd
)[r_index
];
2389 /* If the relocation is against a static symbol it must be within
2390 the current section and so cannot be a cross ARM/Thumb relocation. */
2394 /* If the call will go through a PLT entry then we do not need
2396 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2405 /* This one is a call from arm code. We need to look up
2406 the target of the call. If it is a thumb target, we
2408 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
2409 record_arm_to_thumb_glue (link_info
, h
);
2412 case R_ARM_THM_CALL
:
2413 /* This one is a call from thumb code. We look
2414 up the target of the call. If it is not a thumb
2415 target, we insert glue. */
2416 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
2417 record_thumb_to_arm_glue (link_info
, h
);
2425 if (contents
!= NULL
2426 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2430 if (internal_relocs
!= NULL
2431 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2432 free (internal_relocs
);
2433 internal_relocs
= NULL
;
2439 if (contents
!= NULL
2440 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2442 if (internal_relocs
!= NULL
2443 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2444 free (internal_relocs
);
2451 /* Set target relocation values needed during linking. */
2454 bfd_elf32_arm_set_target_relocs (struct bfd_link_info
*link_info
,
2456 char * target2_type
,
2460 struct elf32_arm_link_hash_table
*globals
;
2462 globals
= elf32_arm_hash_table (link_info
);
2464 globals
->target1_is_rel
= target1_is_rel
;
2465 if (strcmp (target2_type
, "rel") == 0)
2466 globals
->target2_reloc
= R_ARM_REL32
;
2467 else if (strcmp (target2_type
, "abs") == 0)
2468 globals
->target2_reloc
= R_ARM_ABS32
;
2469 else if (strcmp (target2_type
, "got-rel") == 0)
2470 globals
->target2_reloc
= R_ARM_GOT_PREL
;
2473 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2476 globals
->fix_v4bx
= fix_v4bx
;
2477 globals
->use_blx
|= use_blx
;
2480 /* The thumb form of a long branch is a bit finicky, because the offset
2481 encoding is split over two fields, each in it's own instruction. They
2482 can occur in any order. So given a thumb form of long branch, and an
2483 offset, insert the offset into the thumb branch and return finished
2486 It takes two thumb instructions to encode the target address. Each has
2487 11 bits to invest. The upper 11 bits are stored in one (identified by
2488 H-0.. see below), the lower 11 bits are stored in the other (identified
2491 Combine together and shifted left by 1 (it's a half word address) and
2495 H-0, upper address-0 = 000
2497 H-1, lower address-0 = 800
2499 They can be ordered either way, but the arm tools I've seen always put
2500 the lower one first. It probably doesn't matter. krk@cygnus.com
2502 XXX: Actually the order does matter. The second instruction (H-1)
2503 moves the computed address into the PC, so it must be the second one
2504 in the sequence. The problem, however is that whilst little endian code
2505 stores the instructions in HI then LOW order, big endian code does the
2506 reverse. nickc@cygnus.com. */
2508 #define LOW_HI_ORDER 0xF800F000
2509 #define HI_LOW_ORDER 0xF000F800
2512 insert_thumb_branch (insn32 br_insn
, int rel_off
)
2514 unsigned int low_bits
;
2515 unsigned int high_bits
;
2517 BFD_ASSERT ((rel_off
& 1) != 1);
2519 rel_off
>>= 1; /* Half word aligned address. */
2520 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
2521 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
2523 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
2524 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
2525 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
2526 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
2528 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2529 abort (); /* Error - not a valid branch instruction form. */
2534 /* Thumb code calling an ARM function. */
2537 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
2541 asection
* input_section
,
2542 bfd_byte
* hit_data
,
2545 bfd_signed_vma addend
,
2550 unsigned long int tmp
;
2551 long int ret_offset
;
2552 struct elf_link_hash_entry
* myh
;
2553 struct elf32_arm_link_hash_table
* globals
;
2555 myh
= find_thumb_glue (info
, name
, input_bfd
);
2559 globals
= elf32_arm_hash_table (info
);
2561 BFD_ASSERT (globals
!= NULL
);
2562 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2564 my_offset
= myh
->root
.u
.def
.value
;
2566 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2567 THUMB2ARM_GLUE_SECTION_NAME
);
2569 BFD_ASSERT (s
!= NULL
);
2570 BFD_ASSERT (s
->contents
!= NULL
);
2571 BFD_ASSERT (s
->output_section
!= NULL
);
2573 if ((my_offset
& 0x01) == 0x01)
2576 && sym_sec
->owner
!= NULL
2577 && !INTERWORK_FLAG (sym_sec
->owner
))
2579 (*_bfd_error_handler
)
2580 (_("%B(%s): warning: interworking not enabled.\n"
2581 " first occurrence: %B: thumb call to arm"),
2582 sym_sec
->owner
, input_bfd
, name
);
2588 myh
->root
.u
.def
.value
= my_offset
;
2590 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
2591 s
->contents
+ my_offset
);
2593 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
2594 s
->contents
+ my_offset
+ 2);
2597 /* Address of destination of the stub. */
2598 ((bfd_signed_vma
) val
)
2600 /* Offset from the start of the current section
2601 to the start of the stubs. */
2603 /* Offset of the start of this stub from the start of the stubs. */
2605 /* Address of the start of the current section. */
2606 + s
->output_section
->vma
)
2607 /* The branch instruction is 4 bytes into the stub. */
2609 /* ARM branches work from the pc of the instruction + 8. */
2612 bfd_put_32 (output_bfd
,
2613 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
2614 s
->contents
+ my_offset
+ 4);
2617 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
2619 /* Now go back and fix up the original BL insn to point to here. */
2621 /* Address of where the stub is located. */
2622 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
2623 /* Address of where the BL is located. */
2624 - (input_section
->output_section
->vma
+ input_section
->output_offset
2626 /* Addend in the relocation. */
2628 /* Biassing for PC-relative addressing. */
2631 tmp
= bfd_get_32 (input_bfd
, hit_data
2632 - input_section
->vma
);
2634 bfd_put_32 (output_bfd
,
2635 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
2636 hit_data
- input_section
->vma
);
2641 /* Arm code calling a Thumb function. */
2644 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
2648 asection
* input_section
,
2649 bfd_byte
* hit_data
,
2652 bfd_signed_vma addend
,
2655 unsigned long int tmp
;
2658 long int ret_offset
;
2659 struct elf_link_hash_entry
* myh
;
2660 struct elf32_arm_link_hash_table
* globals
;
2662 myh
= find_arm_glue (info
, name
, input_bfd
);
2666 globals
= elf32_arm_hash_table (info
);
2668 BFD_ASSERT (globals
!= NULL
);
2669 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2671 my_offset
= myh
->root
.u
.def
.value
;
2672 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2673 ARM2THUMB_GLUE_SECTION_NAME
);
2674 BFD_ASSERT (s
!= NULL
);
2675 BFD_ASSERT (s
->contents
!= NULL
);
2676 BFD_ASSERT (s
->output_section
!= NULL
);
2678 if ((my_offset
& 0x01) == 0x01)
2681 && sym_sec
->owner
!= NULL
2682 && !INTERWORK_FLAG (sym_sec
->owner
))
2684 (*_bfd_error_handler
)
2685 (_("%B(%s): warning: interworking not enabled.\n"
2686 " first occurrence: %B: arm call to thumb"),
2687 sym_sec
->owner
, input_bfd
, name
);
2691 myh
->root
.u
.def
.value
= my_offset
;
2693 if ((info
->shared
|| globals
->root
.is_relocatable_executable
))
2695 /* For relocatable objects we can't use absolute addresses,
2696 so construct the address from a relative offset. */
2697 /* TODO: If the offset is small it's probably worth
2698 constructing the address with adds. */
2699 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1p_ldr_insn
,
2700 s
->contents
+ my_offset
);
2701 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2p_add_pc_insn
,
2702 s
->contents
+ my_offset
+ 4);
2703 bfd_put_32 (output_bfd
, (bfd_vma
) a2t3p_bx_r12_insn
,
2704 s
->contents
+ my_offset
+ 8);
2705 /* Adjust the offset by 4 for the position of the add,
2706 and 8 for the pipeline offset. */
2707 ret_offset
= (val
- (s
->output_offset
2708 + s
->output_section
->vma
2711 bfd_put_32 (output_bfd
, ret_offset
,
2712 s
->contents
+ my_offset
+ 12);
2716 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
2717 s
->contents
+ my_offset
);
2719 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
2720 s
->contents
+ my_offset
+ 4);
2722 /* It's a thumb address. Add the low order bit. */
2723 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
2724 s
->contents
+ my_offset
+ 8);
2728 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
2730 tmp
= bfd_get_32 (input_bfd
, hit_data
);
2731 tmp
= tmp
& 0xFF000000;
2733 /* Somehow these are both 4 too far, so subtract 8. */
2734 ret_offset
= (s
->output_offset
2736 + s
->output_section
->vma
2737 - (input_section
->output_offset
2738 + input_section
->output_section
->vma
2742 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
2744 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
2749 /* Some relocations map to different relocations depending on the
2750 target. Return the real relocation. */
2752 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
2758 if (globals
->target1_is_rel
)
2764 return globals
->target2_reloc
;
2771 /* Return the base VMA address which should be subtracted from real addresses
2772 when resolving @dtpoff relocation.
2773 This is PT_TLS segment p_vaddr. */
2776 dtpoff_base (struct bfd_link_info
*info
)
2778 /* If tls_sec is NULL, we should have signalled an error already. */
2779 if (elf_hash_table (info
)->tls_sec
== NULL
)
2781 return elf_hash_table (info
)->tls_sec
->vma
;
2784 /* Return the relocation value for @tpoff relocation
2785 if STT_TLS virtual address is ADDRESS. */
2788 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
2790 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2793 /* If tls_sec is NULL, we should have signalled an error already. */
2794 if (htab
->tls_sec
== NULL
)
2796 base
= align_power ((bfd_vma
) TCB_SIZE
, htab
->tls_sec
->alignment_power
);
2797 return address
- htab
->tls_sec
->vma
+ base
;
2800 /* Perform a relocation as part of a final link. */
2802 static bfd_reloc_status_type
2803 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
2806 asection
* input_section
,
2807 bfd_byte
* contents
,
2808 Elf_Internal_Rela
* rel
,
2810 struct bfd_link_info
* info
,
2812 const char * sym_name
,
2814 struct elf_link_hash_entry
* h
,
2815 bfd_boolean
* unresolved_reloc_p
)
2817 unsigned long r_type
= howto
->type
;
2818 unsigned long r_symndx
;
2819 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
2820 bfd
* dynobj
= NULL
;
2821 Elf_Internal_Shdr
* symtab_hdr
;
2822 struct elf_link_hash_entry
** sym_hashes
;
2823 bfd_vma
* local_got_offsets
;
2824 asection
* sgot
= NULL
;
2825 asection
* splt
= NULL
;
2826 asection
* sreloc
= NULL
;
2828 bfd_signed_vma signed_addend
;
2829 struct elf32_arm_link_hash_table
* globals
;
2831 globals
= elf32_arm_hash_table (info
);
2833 /* Some relocation type map to different relocations depending on the
2834 target. We pick the right one here. */
2835 r_type
= arm_real_reloc_type (globals
, r_type
);
2836 if (r_type
!= howto
->type
)
2837 howto
= elf32_arm_howto_from_type (r_type
);
2839 /* If the start address has been set, then set the EF_ARM_HASENTRY
2840 flag. Setting this more than once is redundant, but the cost is
2841 not too high, and it keeps the code simple.
2843 The test is done here, rather than somewhere else, because the
2844 start address is only set just before the final link commences.
2846 Note - if the user deliberately sets a start address of 0, the
2847 flag will not be set. */
2848 if (bfd_get_start_address (output_bfd
) != 0)
2849 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
2851 dynobj
= elf_hash_table (info
)->dynobj
;
2854 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2855 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2857 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2858 sym_hashes
= elf_sym_hashes (input_bfd
);
2859 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2860 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2862 if (globals
->use_rel
)
2864 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
2866 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2869 signed_addend
&= ~ howto
->src_mask
;
2870 signed_addend
|= addend
;
2873 signed_addend
= addend
;
2876 addend
= signed_addend
= rel
->r_addend
;
2881 /* We don't need to find a value for this symbol. It's just a
2883 *unresolved_reloc_p
= FALSE
;
2884 return bfd_reloc_ok
;
2894 /* r_symndx will be zero only for relocs against symbols
2895 from removed linkonce sections, or sections discarded by
2898 return bfd_reloc_ok
;
2900 /* Handle relocations which should use the PLT entry. ABS32/REL32
2901 will use the symbol's value, which may point to a PLT entry, but we
2902 don't need to handle that here. If we created a PLT entry, all
2903 branches in this object should go to it. */
2904 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
2907 && h
->plt
.offset
!= (bfd_vma
) -1)
2909 /* If we've created a .plt section, and assigned a PLT entry to
2910 this function, it should not be known to bind locally. If
2911 it were, we would have cleared the PLT entry. */
2912 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
2914 value
= (splt
->output_section
->vma
2915 + splt
->output_offset
2917 *unresolved_reloc_p
= FALSE
;
2918 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2919 contents
, rel
->r_offset
, value
,
2923 /* When generating a shared object or relocatable executable, these
2924 relocations are copied into the output file to be resolved at
2926 if ((info
->shared
|| globals
->root
.is_relocatable_executable
)
2927 && (input_section
->flags
& SEC_ALLOC
)
2928 && (r_type
!= R_ARM_REL32
2929 || !SYMBOL_CALLS_LOCAL (info
, h
))
2931 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2932 || h
->root
.type
!= bfd_link_hash_undefweak
)
2933 && r_type
!= R_ARM_PC24
2934 && r_type
!= R_ARM_CALL
2935 && r_type
!= R_ARM_JUMP24
2936 && r_type
!= R_ARM_PREL31
2937 && r_type
!= R_ARM_PLT32
)
2939 Elf_Internal_Rela outrel
;
2941 bfd_boolean skip
, relocate
;
2943 *unresolved_reloc_p
= FALSE
;
2949 name
= (bfd_elf_string_from_elf_section
2951 elf_elfheader (input_bfd
)->e_shstrndx
,
2952 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2954 return bfd_reloc_notsupported
;
2956 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
2957 && strcmp (bfd_get_section_name (input_bfd
,
2961 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2962 BFD_ASSERT (sreloc
!= NULL
);
2969 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2971 if (outrel
.r_offset
== (bfd_vma
) -1)
2973 else if (outrel
.r_offset
== (bfd_vma
) -2)
2974 skip
= TRUE
, relocate
= TRUE
;
2975 outrel
.r_offset
+= (input_section
->output_section
->vma
2976 + input_section
->output_offset
);
2979 memset (&outrel
, 0, sizeof outrel
);
2984 || !h
->def_regular
))
2985 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2990 /* This symbol is local, or marked to become local. */
2992 if (sym_flags
== STT_ARM_TFUNC
)
2994 if (globals
->symbian_p
)
2996 /* On Symbian OS, the data segment and text segement
2997 can be relocated independently. Therefore, we
2998 must indicate the segment to which this
2999 relocation is relative. The BPABI allows us to
3000 use any symbol in the right segment; we just use
3001 the section symbol as it is convenient. (We
3002 cannot use the symbol given by "h" directly as it
3003 will not appear in the dynamic symbol table.) */
3005 symbol
= elf_section_data (sym_sec
->output_section
)->dynindx
;
3007 symbol
= elf_section_data (input_section
->output_section
)->dynindx
;
3008 BFD_ASSERT (symbol
!= 0);
3011 /* On SVR4-ish systems, the dynamic loader cannot
3012 relocate the text and data segments independently,
3013 so the symbol does not matter. */
3015 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
3018 loc
= sreloc
->contents
;
3019 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3020 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3022 /* If this reloc is against an external symbol, we do not want to
3023 fiddle with the addend. Otherwise, we need to include the symbol
3024 value so that it becomes an addend for the dynamic reloc. */
3026 return bfd_reloc_ok
;
3028 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3029 contents
, rel
->r_offset
, value
,
3032 else switch (r_type
)
3034 case R_ARM_XPC25
: /* Arm BLX instruction. */
3037 case R_ARM_PC24
: /* Arm B/BL instruction */
3039 if (r_type
== R_ARM_XPC25
)
3041 /* Check for Arm calling Arm function. */
3042 /* FIXME: Should we translate the instruction into a BL
3043 instruction instead ? */
3044 if (sym_flags
!= STT_ARM_TFUNC
)
3045 (*_bfd_error_handler
)
3046 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3048 h
? h
->root
.root
.string
: "(local)");
3052 /* Check for Arm calling Thumb function. */
3053 if (sym_flags
== STT_ARM_TFUNC
)
3055 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
3056 output_bfd
, input_section
,
3057 hit_data
, sym_sec
, rel
->r_offset
,
3058 signed_addend
, value
);
3059 return bfd_reloc_ok
;
3063 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3065 S is the address of the symbol in the relocation.
3066 P is address of the instruction being relocated.
3067 A is the addend (extracted from the instruction) in bytes.
3069 S is held in 'value'.
3070 P is the base address of the section containing the
3071 instruction plus the offset of the reloc into that
3073 (input_section->output_section->vma +
3074 input_section->output_offset +
3076 A is the addend, converted into bytes, ie:
3079 Note: None of these operations have knowledge of the pipeline
3080 size of the processor, thus it is up to the assembler to
3081 encode this information into the addend. */
3082 value
-= (input_section
->output_section
->vma
3083 + input_section
->output_offset
);
3084 value
-= rel
->r_offset
;
3085 if (globals
->use_rel
)
3086 value
+= (signed_addend
<< howto
->size
);
3088 /* RELA addends do not have to be adjusted by howto->size. */
3089 value
+= signed_addend
;
3091 signed_addend
= value
;
3092 signed_addend
>>= howto
->rightshift
;
3094 /* It is not an error for an undefined weak reference to be
3095 out of range. Any program that branches to such a symbol
3096 is going to crash anyway, so there is no point worrying
3097 about getting the destination exactly right. */
3098 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3100 /* Perform a signed range check. */
3101 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
3102 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
3103 return bfd_reloc_overflow
;
3106 /* If necessary set the H bit in the BLX instruction. */
3107 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
3108 value
= (signed_addend
& howto
->dst_mask
)
3109 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
3112 value
= (signed_addend
& howto
->dst_mask
)
3113 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
3118 if (sym_flags
== STT_ARM_TFUNC
)
3123 value
-= (input_section
->output_section
->vma
3124 + input_section
->output_offset
+ rel
->r_offset
);
3129 value
-= (input_section
->output_section
->vma
3130 + input_section
->output_offset
+ rel
->r_offset
);
3131 value
+= signed_addend
;
3132 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
3134 /* Check for overflow */
3135 if ((value
^ (value
>> 1)) & (1 << 30))
3136 return bfd_reloc_overflow
;
3138 value
&= 0x7fffffff;
3139 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
3140 if (sym_flags
== STT_ARM_TFUNC
)
3145 bfd_put_32 (input_bfd
, value
, hit_data
);
3146 return bfd_reloc_ok
;
3150 if ((long) value
> 0x7f || (long) value
< -0x80)
3151 return bfd_reloc_overflow
;
3153 bfd_put_8 (input_bfd
, value
, hit_data
);
3154 return bfd_reloc_ok
;
3159 if ((long) value
> 0x7fff || (long) value
< -0x8000)
3160 return bfd_reloc_overflow
;
3162 bfd_put_16 (input_bfd
, value
, hit_data
);
3163 return bfd_reloc_ok
;
3166 /* Support ldr and str instruction for the arm */
3167 /* Also thumb b (unconditional branch). ??? Really? */
3170 if ((long) value
> 0x7ff || (long) value
< -0x800)
3171 return bfd_reloc_overflow
;
3173 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
3174 bfd_put_32 (input_bfd
, value
, hit_data
);
3175 return bfd_reloc_ok
;
3177 case R_ARM_THM_ABS5
:
3178 /* Support ldr and str instructions for the thumb. */
3179 if (globals
->use_rel
)
3181 /* Need to refetch addend. */
3182 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
3183 /* ??? Need to determine shift amount from operand size. */
3184 addend
>>= howto
->rightshift
;
3188 /* ??? Isn't value unsigned? */
3189 if ((long) value
> 0x1f || (long) value
< -0x10)
3190 return bfd_reloc_overflow
;
3192 /* ??? Value needs to be properly shifted into place first. */
3193 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
3194 bfd_put_16 (input_bfd
, value
, hit_data
);
3195 return bfd_reloc_ok
;
3197 case R_ARM_THM_XPC22
:
3198 case R_ARM_THM_CALL
:
3199 /* Thumb BL (branch long instruction). */
3202 bfd_boolean overflow
= FALSE
;
3203 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3204 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3205 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3206 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3208 bfd_signed_vma signed_check
;
3209 bfd_boolean thumb_plt_call
= FALSE
;
3211 /* Need to refetch the addend and squish the two 11 bit pieces
3213 if (globals
->use_rel
)
3215 bfd_vma upper
= upper_insn
& 0x7ff;
3216 bfd_vma lower
= lower_insn
& 0x7ff;
3217 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
3218 addend
= (upper
<< 12) | (lower
<< 1);
3219 signed_addend
= addend
;
3222 if (r_type
== R_ARM_THM_XPC22
)
3224 /* Check for Thumb to Thumb call. */
3225 /* FIXME: Should we translate the instruction into a BL
3226 instruction instead ? */
3227 if (sym_flags
== STT_ARM_TFUNC
)
3228 (*_bfd_error_handler
)
3229 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3231 h
? h
->root
.root
.string
: "(local)");
3235 /* If it is not a call to Thumb, assume call to Arm.
3236 If it is a call relative to a section name, then it is not a
3237 function call at all, but rather a long jump. Calls through
3238 the PLT do not require stubs. */
3239 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
3240 && (h
== NULL
|| splt
== NULL
3241 || h
->plt
.offset
== (bfd_vma
) -1))
3243 if (elf32_thumb_to_arm_stub
3244 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
3245 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
3246 return bfd_reloc_ok
;
3248 return bfd_reloc_dangerous
;
3252 /* Handle calls via the PLT. */
3253 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
3255 value
= (splt
->output_section
->vma
3256 + splt
->output_offset
3258 if (globals
->use_blx
)
3260 /* If the Thumb BLX instruction is available, convert the
3261 BL to a BLX instruction to call the ARM-mode PLT entry. */
3262 if ((lower_insn
& (0x3 << 11)) == 0x3 << 11)
3264 lower_insn
= (lower_insn
& ~(0x3 << 11)) | 0x1 << 11;
3265 thumb_plt_call
= TRUE
;
3269 /* Target the Thumb stub before the ARM PLT entry. */
3270 value
-= PLT_THUMB_STUB_SIZE
;
3271 *unresolved_reloc_p
= FALSE
;
3274 relocation
= value
+ signed_addend
;
3276 relocation
-= (input_section
->output_section
->vma
3277 + input_section
->output_offset
3280 check
= relocation
>> howto
->rightshift
;
3282 /* If this is a signed value, the rightshift just dropped
3283 leading 1 bits (assuming twos complement). */
3284 if ((bfd_signed_vma
) relocation
>= 0)
3285 signed_check
= check
;
3287 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
3289 /* Assumes two's complement. */
3290 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3293 if ((r_type
== R_ARM_THM_XPC22
3294 && ((lower_insn
& 0x1800) == 0x0800))
3296 /* For a BLX instruction, make sure that the relocation is rounded up
3297 to a word boundary. This follows the semantics of the instruction
3298 which specifies that bit 1 of the target address will come from bit
3299 1 of the base address. */
3300 relocation
= (relocation
+ 2) & ~ 3;
3302 /* Put RELOCATION back into the insn. */
3303 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
3304 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
3306 /* Put the relocated value back in the object file: */
3307 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3308 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3310 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3314 case R_ARM_THM_JUMP24
:
3315 /* Thumb32 unconditional branch instruction. */
3318 bfd_boolean overflow
= FALSE
;
3319 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3320 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3321 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3322 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3324 bfd_signed_vma signed_check
;
3326 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3327 two pieces together. */
3328 if (globals
->use_rel
)
3330 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
3331 bfd_vma hi
= (upper_insn
& 0x03ff);
3332 bfd_vma I1
= (lower_insn
& 0x2000) >> 13;
3333 bfd_vma I2
= (lower_insn
& 0x0800) >> 11;
3334 bfd_vma lo
= (lower_insn
& 0x07ff);
3340 signed_addend
= (S
<< 24) | (I1
<< 23) | (I2
<< 22) | (hi
<< 12) | (lo
<< 1);
3341 signed_addend
-= (1 << 24); /* Sign extend. */
3344 /* ??? Should handle interworking? GCC might someday try to
3345 use this for tail calls. */
3347 relocation
= value
+ signed_addend
;
3348 relocation
-= (input_section
->output_section
->vma
3349 + input_section
->output_offset
3352 check
= relocation
>> howto
->rightshift
;
3354 /* If this is a signed value, the rightshift just dropped
3355 leading 1 bits (assuming twos complement). */
3356 if ((bfd_signed_vma
) relocation
>= 0)
3357 signed_check
= check
;
3359 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
3361 /* Assumes two's complement. */
3362 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3365 /* Put RELOCATION back into the insn. */
3367 bfd_vma S
= (relocation
& 0x01000000) >> 24;
3368 bfd_vma I1
= (relocation
& 0x00800000) >> 23;
3369 bfd_vma I2
= (relocation
& 0x00400000) >> 22;
3370 bfd_vma hi
= (relocation
& 0x003ff000) >> 12;
3371 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
3376 upper_insn
= (upper_insn
& (bfd_vma
) 0xf800) | (S
<< 10) | hi
;
3377 lower_insn
= (lower_insn
& (bfd_vma
) 0xd000) | (I1
<< 13) | (I2
<< 11) | lo
;
3380 /* Put the relocated value back in the object file: */
3381 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3382 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3384 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3387 case R_ARM_THM_JUMP19
:
3388 /* Thumb32 conditional branch instruction. */
3391 bfd_boolean overflow
= FALSE
;
3392 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
3393 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
3394 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
3395 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3397 bfd_signed_vma signed_check
;
3399 /* Need to refetch the addend, reconstruct the top three bits,
3400 and squish the two 11 bit pieces together. */
3401 if (globals
->use_rel
)
3403 bfd_vma S
= (upper_insn
& 0x0400) >> 10;
3404 bfd_vma upper
= (upper_insn
& 0x001f);
3405 bfd_vma J1
= (lower_insn
& 0x2000) >> 13;
3406 bfd_vma J2
= (lower_insn
& 0x0800) >> 11;
3407 bfd_vma lower
= (lower_insn
& 0x07ff);
3412 upper
-= 0x0100; /* Sign extend. */
3414 addend
= (upper
<< 12) | (lower
<< 1);
3415 signed_addend
= addend
;
3418 /* ??? Should handle interworking? GCC might someday try to
3419 use this for tail calls. */
3421 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 /* Put RELOCATION back into the insn. */
3441 bfd_vma S
= (relocation
& 0x00100000) >> 20;
3442 bfd_vma J2
= (relocation
& 0x00080000) >> 19;
3443 bfd_vma J1
= (relocation
& 0x00040000) >> 18;
3444 bfd_vma hi
= (relocation
& 0x0003f000) >> 12;
3445 bfd_vma lo
= (relocation
& 0x00000ffe) >> 1;
3447 upper_insn
= (upper_insn
& 0xfb30) | (S
<< 10) | hi
;
3448 lower_insn
= (lower_insn
& 0xd000) | (J1
<< 13) | (J2
<< 11) | lo
;
3451 /* Put the relocated value back in the object file: */
3452 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
3453 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
3455 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
3458 case R_ARM_THM_JUMP11
:
3459 case R_ARM_THM_JUMP8
:
3460 case R_ARM_THM_JUMP6
:
3461 /* Thumb B (branch) instruction). */
3463 bfd_signed_vma relocation
;
3464 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
3465 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
3466 bfd_signed_vma signed_check
;
3468 /* CZB cannot jump backward. */
3469 if (r_type
== R_ARM_THM_JUMP6
)
3470 reloc_signed_min
= 0;
3472 if (globals
->use_rel
)
3474 /* Need to refetch addend. */
3475 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
3476 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3479 signed_addend
&= ~ howto
->src_mask
;
3480 signed_addend
|= addend
;
3483 signed_addend
= addend
;
3484 /* The value in the insn has been right shifted. We need to
3485 undo this, so that we can perform the address calculation
3486 in terms of bytes. */
3487 signed_addend
<<= howto
->rightshift
;
3489 relocation
= value
+ signed_addend
;
3491 relocation
-= (input_section
->output_section
->vma
3492 + input_section
->output_offset
3495 relocation
>>= howto
->rightshift
;
3496 signed_check
= relocation
;
3498 if (r_type
== R_ARM_THM_JUMP6
)
3499 relocation
= ((relocation
& 0x0020) << 4) | ((relocation
& 0x001f) << 3);
3501 relocation
&= howto
->dst_mask
;
3502 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
3504 bfd_put_16 (input_bfd
, relocation
, hit_data
);
3506 /* Assumes two's complement. */
3507 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
3508 return bfd_reloc_overflow
;
3510 return bfd_reloc_ok
;
3513 case R_ARM_ALU_PCREL7_0
:
3514 case R_ARM_ALU_PCREL15_8
:
3515 case R_ARM_ALU_PCREL23_15
:
3520 insn
= bfd_get_32 (input_bfd
, hit_data
);
3521 if (globals
->use_rel
)
3523 /* Extract the addend. */
3524 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
3525 signed_addend
= addend
;
3527 relocation
= value
+ signed_addend
;
3529 relocation
-= (input_section
->output_section
->vma
3530 + input_section
->output_offset
3532 insn
= (insn
& ~0xfff)
3533 | ((howto
->bitpos
<< 7) & 0xf00)
3534 | ((relocation
>> howto
->bitpos
) & 0xff);
3535 bfd_put_32 (input_bfd
, value
, hit_data
);
3537 return bfd_reloc_ok
;
3539 case R_ARM_GNU_VTINHERIT
:
3540 case R_ARM_GNU_VTENTRY
:
3541 return bfd_reloc_ok
;
3543 case R_ARM_GOTOFF32
:
3544 /* Relocation is relative to the start of the
3545 global offset table. */
3547 BFD_ASSERT (sgot
!= NULL
);
3549 return bfd_reloc_notsupported
;
3551 /* If we are addressing a Thumb function, we need to adjust the
3552 address by one, so that attempts to call the function pointer will
3553 correctly interpret it as Thumb code. */
3554 if (sym_flags
== STT_ARM_TFUNC
)
3557 /* Note that sgot->output_offset is not involved in this
3558 calculation. We always want the start of .got. If we
3559 define _GLOBAL_OFFSET_TABLE in a different way, as is
3560 permitted by the ABI, we might have to change this
3562 value
-= sgot
->output_section
->vma
;
3563 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3564 contents
, rel
->r_offset
, value
,
3568 /* Use global offset table as symbol value. */
3569 BFD_ASSERT (sgot
!= NULL
);
3572 return bfd_reloc_notsupported
;
3574 *unresolved_reloc_p
= FALSE
;
3575 value
= sgot
->output_section
->vma
;
3576 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3577 contents
, rel
->r_offset
, value
,
3581 case R_ARM_GOT_PREL
:
3582 /* Relocation is to the entry for this symbol in the
3583 global offset table. */
3585 return bfd_reloc_notsupported
;
3592 off
= h
->got
.offset
;
3593 BFD_ASSERT (off
!= (bfd_vma
) -1);
3594 dyn
= globals
->root
.dynamic_sections_created
;
3596 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3598 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3599 || (ELF_ST_VISIBILITY (h
->other
)
3600 && h
->root
.type
== bfd_link_hash_undefweak
))
3602 /* This is actually a static link, or it is a -Bsymbolic link
3603 and the symbol is defined locally. We must initialize this
3604 entry in the global offset table. Since the offset must
3605 always be a multiple of 4, we use the least significant bit
3606 to record whether we have initialized it already.
3608 When doing a dynamic link, we create a .rel.got relocation
3609 entry to initialize the value. This is done in the
3610 finish_dynamic_symbol routine. */
3615 /* If we are addressing a Thumb function, we need to
3616 adjust the address by one, so that attempts to
3617 call the function pointer will correctly
3618 interpret it as Thumb code. */
3619 if (sym_flags
== STT_ARM_TFUNC
)
3622 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
3627 *unresolved_reloc_p
= FALSE
;
3629 value
= sgot
->output_offset
+ off
;
3635 BFD_ASSERT (local_got_offsets
!= NULL
&&
3636 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3638 off
= local_got_offsets
[r_symndx
];
3640 /* The offset must always be a multiple of 4. We use the
3641 least significant bit to record whether we have already
3642 generated the necessary reloc. */
3647 /* If we are addressing a Thumb function, we need to
3648 adjust the address by one, so that attempts to
3649 call the function pointer will correctly
3650 interpret it as Thumb code. */
3651 if (sym_flags
== STT_ARM_TFUNC
)
3654 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
3659 Elf_Internal_Rela outrel
;
3662 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
3663 BFD_ASSERT (srelgot
!= NULL
);
3665 outrel
.r_offset
= (sgot
->output_section
->vma
3666 + sgot
->output_offset
3668 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3669 loc
= srelgot
->contents
;
3670 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3671 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3674 local_got_offsets
[r_symndx
] |= 1;
3677 value
= sgot
->output_offset
+ off
;
3679 if (r_type
!= R_ARM_GOT32
)
3680 value
+= sgot
->output_section
->vma
;
3682 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3683 contents
, rel
->r_offset
, value
,
3686 case R_ARM_TLS_LDO32
:
3687 value
= value
- dtpoff_base (info
);
3689 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3690 contents
, rel
->r_offset
, value
, (bfd_vma
) 0);
3692 case R_ARM_TLS_LDM32
:
3696 if (globals
->sgot
== NULL
)
3699 off
= globals
->tls_ldm_got
.offset
;
3705 /* If we don't know the module number, create a relocation
3709 Elf_Internal_Rela outrel
;
3712 if (globals
->srelgot
== NULL
)
3715 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
3716 + globals
->sgot
->output_offset
+ off
);
3717 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32
);
3719 bfd_put_32 (output_bfd
, 0, globals
->sgot
->contents
+ off
);
3721 loc
= globals
->srelgot
->contents
;
3722 loc
+= globals
->srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3723 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3726 bfd_put_32 (output_bfd
, 1, globals
->sgot
->contents
+ off
);
3728 globals
->tls_ldm_got
.offset
|= 1;
3731 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
3732 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
3734 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3735 contents
, rel
->r_offset
, value
,
3739 case R_ARM_TLS_GD32
:
3740 case R_ARM_TLS_IE32
:
3746 if (globals
->sgot
== NULL
)
3753 dyn
= globals
->root
.dynamic_sections_created
;
3754 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
3756 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
3758 *unresolved_reloc_p
= FALSE
;
3761 off
= h
->got
.offset
;
3762 tls_type
= ((struct elf32_arm_link_hash_entry
*) h
)->tls_type
;
3766 if (local_got_offsets
== NULL
)
3768 off
= local_got_offsets
[r_symndx
];
3769 tls_type
= elf32_arm_local_got_tls_type (input_bfd
)[r_symndx
];
3772 if (tls_type
== GOT_UNKNOWN
)
3779 bfd_boolean need_relocs
= FALSE
;
3780 Elf_Internal_Rela outrel
;
3781 bfd_byte
*loc
= NULL
;
3784 /* The GOT entries have not been initialized yet. Do it
3785 now, and emit any relocations. If both an IE GOT and a
3786 GD GOT are necessary, we emit the GD first. */
3788 if ((info
->shared
|| indx
!= 0)
3790 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3791 || h
->root
.type
!= bfd_link_hash_undefweak
))
3794 if (globals
->srelgot
== NULL
)
3796 loc
= globals
->srelgot
->contents
;
3797 loc
+= globals
->srelgot
->reloc_count
* sizeof (Elf32_External_Rel
);
3800 if (tls_type
& GOT_TLS_GD
)
3804 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
3805 + globals
->sgot
->output_offset
+ cur_off
);
3806 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_DTPMOD32
);
3807 bfd_put_32 (output_bfd
, 0, globals
->sgot
->contents
+ cur_off
);
3809 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3810 globals
->srelgot
->reloc_count
++;
3811 loc
+= sizeof (Elf32_External_Rel
);
3814 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
3815 globals
->sgot
->contents
+ cur_off
+ 4);
3818 bfd_put_32 (output_bfd
, 0,
3819 globals
->sgot
->contents
+ cur_off
+ 4);
3821 outrel
.r_info
= ELF32_R_INFO (indx
,
3822 R_ARM_TLS_DTPOFF32
);
3823 outrel
.r_offset
+= 4;
3824 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3825 globals
->srelgot
->reloc_count
++;
3826 loc
+= sizeof (Elf32_External_Rel
);
3831 /* If we are not emitting relocations for a
3832 general dynamic reference, then we must be in a
3833 static link or an executable link with the
3834 symbol binding locally. Mark it as belonging
3835 to module 1, the executable. */
3836 bfd_put_32 (output_bfd
, 1,
3837 globals
->sgot
->contents
+ cur_off
);
3838 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
3839 globals
->sgot
->contents
+ cur_off
+ 4);
3845 if (tls_type
& GOT_TLS_IE
)
3849 outrel
.r_offset
= (globals
->sgot
->output_section
->vma
3850 + globals
->sgot
->output_offset
3852 outrel
.r_info
= ELF32_R_INFO (indx
, R_ARM_TLS_TPOFF32
);
3855 bfd_put_32 (output_bfd
, value
- dtpoff_base (info
),
3856 globals
->sgot
->contents
+ cur_off
);
3858 bfd_put_32 (output_bfd
, 0,
3859 globals
->sgot
->contents
+ cur_off
);
3861 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
3862 globals
->srelgot
->reloc_count
++;
3863 loc
+= sizeof (Elf32_External_Rel
);
3866 bfd_put_32 (output_bfd
, tpoff (info
, value
),
3867 globals
->sgot
->contents
+ cur_off
);
3874 local_got_offsets
[r_symndx
] |= 1;
3877 if ((tls_type
& GOT_TLS_GD
) && r_type
!= R_ARM_TLS_GD32
)
3879 value
= globals
->sgot
->output_section
->vma
+ globals
->sgot
->output_offset
+ off
3880 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
3882 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3883 contents
, rel
->r_offset
, value
,
3887 case R_ARM_TLS_LE32
:
3890 (*_bfd_error_handler
)
3891 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
3892 input_bfd
, input_section
,
3893 (long) rel
->r_offset
, howto
->name
);
3897 value
= tpoff (info
, value
);
3899 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3900 contents
, rel
->r_offset
, value
, (bfd_vma
) 0);
3903 if (globals
->fix_v4bx
)
3905 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
3907 /* Ensure that we have a BX instruction. */
3908 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
3910 /* Preserve Rm (lowest four bits) and the condition code
3911 (highest four bits). Other bits encode MOV PC,Rm. */
3912 insn
= (insn
& 0xf000000f) | 0x01a0f000;
3914 bfd_put_32 (input_bfd
, insn
, hit_data
);
3916 return bfd_reloc_ok
;
3919 return bfd_reloc_notsupported
;
3923 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
3925 arm_add_to_rel (bfd
* abfd
,
3927 reloc_howto_type
* howto
,
3928 bfd_signed_vma increment
)
3930 bfd_signed_vma addend
;
3932 if (howto
->type
== R_ARM_THM_CALL
)
3934 int upper_insn
, lower_insn
;
3937 upper_insn
= bfd_get_16 (abfd
, address
);
3938 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
3939 upper
= upper_insn
& 0x7ff;
3940 lower
= lower_insn
& 0x7ff;
3942 addend
= (upper
<< 12) | (lower
<< 1);
3943 addend
+= increment
;
3946 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
3947 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
3949 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
3950 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
3956 contents
= bfd_get_32 (abfd
, address
);
3958 /* Get the (signed) value from the instruction. */
3959 addend
= contents
& howto
->src_mask
;
3960 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3962 bfd_signed_vma mask
;
3965 mask
&= ~ howto
->src_mask
;
3969 /* Add in the increment, (which is a byte value). */
3970 switch (howto
->type
)
3973 addend
+= increment
;
3980 addend
<<= howto
->size
;
3981 addend
+= increment
;
3983 /* Should we check for overflow here ? */
3985 /* Drop any undesired bits. */
3986 addend
>>= howto
->rightshift
;
3990 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
3992 bfd_put_32 (abfd
, contents
, address
);
3996 #define IS_ARM_TLS_RELOC(R_TYPE) \
3997 ((R_TYPE) == R_ARM_TLS_GD32 \
3998 || (R_TYPE) == R_ARM_TLS_LDO32 \
3999 || (R_TYPE) == R_ARM_TLS_LDM32 \
4000 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4001 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4002 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4003 || (R_TYPE) == R_ARM_TLS_LE32 \
4004 || (R_TYPE) == R_ARM_TLS_IE32)
4006 /* Relocate an ARM ELF section. */
4008 elf32_arm_relocate_section (bfd
* output_bfd
,
4009 struct bfd_link_info
* info
,
4011 asection
* input_section
,
4012 bfd_byte
* contents
,
4013 Elf_Internal_Rela
* relocs
,
4014 Elf_Internal_Sym
* local_syms
,
4015 asection
** local_sections
)
4017 Elf_Internal_Shdr
*symtab_hdr
;
4018 struct elf_link_hash_entry
**sym_hashes
;
4019 Elf_Internal_Rela
*rel
;
4020 Elf_Internal_Rela
*relend
;
4022 struct elf32_arm_link_hash_table
* globals
;
4024 globals
= elf32_arm_hash_table (info
);
4025 if (info
->relocatable
&& !globals
->use_rel
)
4028 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
4029 sym_hashes
= elf_sym_hashes (input_bfd
);
4032 relend
= relocs
+ input_section
->reloc_count
;
4033 for (; rel
< relend
; rel
++)
4036 reloc_howto_type
* howto
;
4037 unsigned long r_symndx
;
4038 Elf_Internal_Sym
* sym
;
4040 struct elf_link_hash_entry
* h
;
4042 bfd_reloc_status_type r
;
4045 bfd_boolean unresolved_reloc
= FALSE
;
4047 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4048 r_type
= ELF32_R_TYPE (rel
->r_info
);
4049 r_type
= arm_real_reloc_type (globals
, r_type
);
4051 if ( r_type
== R_ARM_GNU_VTENTRY
4052 || r_type
== R_ARM_GNU_VTINHERIT
)
4055 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
4056 howto
= bfd_reloc
.howto
;
4058 if (info
->relocatable
&& globals
->use_rel
)
4060 /* This is a relocatable link. We don't have to change
4061 anything, unless the reloc is against a section symbol,
4062 in which case we have to adjust according to where the
4063 section symbol winds up in the output section. */
4064 if (r_symndx
< symtab_hdr
->sh_info
)
4066 sym
= local_syms
+ r_symndx
;
4067 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4069 sec
= local_sections
[r_symndx
];
4070 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
4072 (bfd_signed_vma
) (sec
->output_offset
4080 /* This is a final link. */
4085 if (r_symndx
< symtab_hdr
->sh_info
)
4087 sym
= local_syms
+ r_symndx
;
4088 sym_type
= ELF32_ST_TYPE (sym
->st_info
);
4089 sec
= local_sections
[r_symndx
];
4090 if (globals
->use_rel
)
4092 relocation
= (sec
->output_section
->vma
4093 + sec
->output_offset
4095 if ((sec
->flags
& SEC_MERGE
)
4096 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4099 bfd_vma addend
, value
;
4101 if (howto
->rightshift
)
4103 (*_bfd_error_handler
)
4104 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4105 input_bfd
, input_section
,
4106 (long) rel
->r_offset
, howto
->name
);
4110 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4112 /* Get the (signed) value from the instruction. */
4113 addend
= value
& howto
->src_mask
;
4114 if (addend
& ((howto
->src_mask
+ 1) >> 1))
4116 bfd_signed_vma mask
;
4119 mask
&= ~ howto
->src_mask
;
4124 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4126 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4127 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
4128 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
4132 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4138 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4139 r_symndx
, symtab_hdr
, sym_hashes
,
4141 unresolved_reloc
, warned
);
4147 name
= h
->root
.root
.string
;
4150 name
= (bfd_elf_string_from_elf_section
4151 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4152 if (name
== NULL
|| *name
== '\0')
4153 name
= bfd_section_name (input_bfd
, sec
);
4157 && r_type
!= R_ARM_NONE
4159 || h
->root
.type
== bfd_link_hash_defined
4160 || h
->root
.type
== bfd_link_hash_defweak
)
4161 && IS_ARM_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
4163 (*_bfd_error_handler
)
4164 ((sym_type
== STT_TLS
4165 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4166 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4169 (long) rel
->r_offset
,
4174 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
4175 input_section
, contents
, rel
,
4176 relocation
, info
, sec
, name
,
4177 (h
? ELF_ST_TYPE (h
->type
) :
4178 ELF_ST_TYPE (sym
->st_info
)), h
,
4181 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4182 because such sections are not SEC_ALLOC and thus ld.so will
4183 not process them. */
4184 if (unresolved_reloc
4185 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
4188 (*_bfd_error_handler
)
4189 (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"),
4190 input_bfd
, input_section
, (long) rel
->r_offset
,
4191 r_type
, h
->root
.root
.string
);
4195 if (r
!= bfd_reloc_ok
)
4197 const char * msg
= (const char *) 0;
4201 case bfd_reloc_overflow
:
4202 /* If the overflowing reloc was to an undefined symbol,
4203 we have already printed one error message and there
4204 is no point complaining again. */
4206 h
->root
.type
!= bfd_link_hash_undefined
)
4207 && (!((*info
->callbacks
->reloc_overflow
)
4208 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
4209 (bfd_vma
) 0, input_bfd
, input_section
,
4214 case bfd_reloc_undefined
:
4215 if (!((*info
->callbacks
->undefined_symbol
)
4216 (info
, name
, input_bfd
, input_section
,
4217 rel
->r_offset
, TRUE
)))
4221 case bfd_reloc_outofrange
:
4222 msg
= _("internal error: out of range error");
4225 case bfd_reloc_notsupported
:
4226 msg
= _("internal error: unsupported relocation error");
4229 case bfd_reloc_dangerous
:
4230 msg
= _("internal error: dangerous error");
4234 msg
= _("internal error: unknown error");
4238 if (!((*info
->callbacks
->warning
)
4239 (info
, msg
, name
, input_bfd
, input_section
,
4250 /* Set the right machine number. */
4253 elf32_arm_object_p (bfd
*abfd
)
4257 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
4259 if (mach
!= bfd_mach_arm_unknown
)
4260 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
4262 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
4263 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
4266 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
4271 /* Function to keep ARM specific flags in the ELF header. */
4274 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
4276 if (elf_flags_init (abfd
)
4277 && elf_elfheader (abfd
)->e_flags
!= flags
)
4279 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
4281 if (flags
& EF_ARM_INTERWORK
)
4282 (*_bfd_error_handler
)
4283 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4287 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4293 elf_elfheader (abfd
)->e_flags
= flags
;
4294 elf_flags_init (abfd
) = TRUE
;
4300 /* Copy backend specific data from one object module to another. */
4303 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
4308 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4309 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4312 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4313 out_flags
= elf_elfheader (obfd
)->e_flags
;
4315 if (elf_flags_init (obfd
)
4316 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
4317 && in_flags
!= out_flags
)
4319 /* Cannot mix APCS26 and APCS32 code. */
4320 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
4323 /* Cannot mix float APCS and non-float APCS code. */
4324 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
4327 /* If the src and dest have different interworking flags
4328 then turn off the interworking bit. */
4329 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
4331 if (out_flags
& EF_ARM_INTERWORK
)
4333 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4336 in_flags
&= ~EF_ARM_INTERWORK
;
4339 /* Likewise for PIC, though don't warn for this case. */
4340 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
4341 in_flags
&= ~EF_ARM_PIC
;
4344 elf_elfheader (obfd
)->e_flags
= in_flags
;
4345 elf_flags_init (obfd
) = TRUE
;
4347 /* Also copy the EI_OSABI field. */
4348 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
4349 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
4354 /* Merge backend specific data from an object file to the output
4355 object file when linking. */
4358 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
4362 bfd_boolean flags_compatible
= TRUE
;
4365 /* Check if we have the same endianess. */
4366 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
4369 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4370 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4373 /* The input BFD must have had its flags initialised. */
4374 /* The following seems bogus to me -- The flags are initialized in
4375 the assembler but I don't think an elf_flags_init field is
4376 written into the object. */
4377 /* BFD_ASSERT (elf_flags_init (ibfd)); */
4379 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4380 out_flags
= elf_elfheader (obfd
)->e_flags
;
4382 if (!elf_flags_init (obfd
))
4384 /* If the input is the default architecture and had the default
4385 flags then do not bother setting the flags for the output
4386 architecture, instead allow future merges to do this. If no
4387 future merges ever set these flags then they will retain their
4388 uninitialised values, which surprise surprise, correspond
4389 to the default values. */
4390 if (bfd_get_arch_info (ibfd
)->the_default
4391 && elf_elfheader (ibfd
)->e_flags
== 0)
4394 elf_flags_init (obfd
) = TRUE
;
4395 elf_elfheader (obfd
)->e_flags
= in_flags
;
4397 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4398 && bfd_get_arch_info (obfd
)->the_default
)
4399 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
4404 /* Determine what should happen if the input ARM architecture
4405 does not match the output ARM architecture. */
4406 if (! bfd_arm_merge_machines (ibfd
, obfd
))
4409 /* Identical flags must be compatible. */
4410 if (in_flags
== out_flags
)
4413 /* Check to see if the input BFD actually contains any sections. If
4414 not, its flags may not have been initialised either, but it
4415 cannot actually cause any incompatibility. Do not short-circuit
4416 dynamic objects; their section list may be emptied by
4417 elf_link_add_object_symbols.
4419 Also check to see if there are no code sections in the input.
4420 In this case there is no need to check for code specific flags.
4421 XXX - do we need to worry about floating-point format compatability
4422 in data sections ? */
4423 if (!(ibfd
->flags
& DYNAMIC
))
4425 bfd_boolean null_input_bfd
= TRUE
;
4426 bfd_boolean only_data_sections
= TRUE
;
4428 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4430 /* Ignore synthetic glue sections. */
4431 if (strcmp (sec
->name
, ".glue_7")
4432 && strcmp (sec
->name
, ".glue_7t"))
4434 if ((bfd_get_section_flags (ibfd
, sec
)
4435 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
4436 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
4437 only_data_sections
= FALSE
;
4439 null_input_bfd
= FALSE
;
4444 if (null_input_bfd
|| only_data_sections
)
4448 /* Complain about various flag mismatches. */
4449 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
4452 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
4454 (in_flags
& EF_ARM_EABIMASK
) >> 24,
4455 (out_flags
& EF_ARM_EABIMASK
) >> 24);
4459 /* Not sure what needs to be checked for EABI versions >= 1. */
4460 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
4462 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
4465 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
4467 in_flags
& EF_ARM_APCS_26
? 26 : 32,
4468 out_flags
& EF_ARM_APCS_26
? 26 : 32);
4469 flags_compatible
= FALSE
;
4472 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
4474 if (in_flags
& EF_ARM_APCS_FLOAT
)
4476 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
4480 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
4483 flags_compatible
= FALSE
;
4486 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
4488 if (in_flags
& EF_ARM_VFP_FLOAT
)
4490 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
4494 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
4497 flags_compatible
= FALSE
;
4500 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
4502 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
4504 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
4508 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
4511 flags_compatible
= FALSE
;
4514 #ifdef EF_ARM_SOFT_FLOAT
4515 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
4517 /* We can allow interworking between code that is VFP format
4518 layout, and uses either soft float or integer regs for
4519 passing floating point arguments and results. We already
4520 know that the APCS_FLOAT flags match; similarly for VFP
4522 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
4523 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
4525 if (in_flags
& EF_ARM_SOFT_FLOAT
)
4527 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
4531 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
4534 flags_compatible
= FALSE
;
4539 /* Interworking mismatch is only a warning. */
4540 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
4542 if (in_flags
& EF_ARM_INTERWORK
)
4545 (_("Warning: %B supports interworking, whereas %B does not"),
4551 (_("Warning: %B does not support interworking, whereas %B does"),
4557 return flags_compatible
;
4560 /* Display the flags field. */
4563 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
4565 FILE * file
= (FILE *) ptr
;
4566 unsigned long flags
;
4568 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4570 /* Print normal ELF private data. */
4571 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4573 flags
= elf_elfheader (abfd
)->e_flags
;
4574 /* Ignore init flag - it may not be set, despite the flags field
4575 containing valid data. */
4577 /* xgettext:c-format */
4578 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
4580 switch (EF_ARM_EABI_VERSION (flags
))
4582 case EF_ARM_EABI_UNKNOWN
:
4583 /* The following flag bits are GNU extensions and not part of the
4584 official ARM ELF extended ABI. Hence they are only decoded if
4585 the EABI version is not set. */
4586 if (flags
& EF_ARM_INTERWORK
)
4587 fprintf (file
, _(" [interworking enabled]"));
4589 if (flags
& EF_ARM_APCS_26
)
4590 fprintf (file
, " [APCS-26]");
4592 fprintf (file
, " [APCS-32]");
4594 if (flags
& EF_ARM_VFP_FLOAT
)
4595 fprintf (file
, _(" [VFP float format]"));
4596 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
4597 fprintf (file
, _(" [Maverick float format]"));
4599 fprintf (file
, _(" [FPA float format]"));
4601 if (flags
& EF_ARM_APCS_FLOAT
)
4602 fprintf (file
, _(" [floats passed in float registers]"));
4604 if (flags
& EF_ARM_PIC
)
4605 fprintf (file
, _(" [position independent]"));
4607 if (flags
& EF_ARM_NEW_ABI
)
4608 fprintf (file
, _(" [new ABI]"));
4610 if (flags
& EF_ARM_OLD_ABI
)
4611 fprintf (file
, _(" [old ABI]"));
4613 if (flags
& EF_ARM_SOFT_FLOAT
)
4614 fprintf (file
, _(" [software FP]"));
4616 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
4617 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
4618 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
4619 | EF_ARM_MAVERICK_FLOAT
);
4622 case EF_ARM_EABI_VER1
:
4623 fprintf (file
, _(" [Version1 EABI]"));
4625 if (flags
& EF_ARM_SYMSARESORTED
)
4626 fprintf (file
, _(" [sorted symbol table]"));
4628 fprintf (file
, _(" [unsorted symbol table]"));
4630 flags
&= ~ EF_ARM_SYMSARESORTED
;
4633 case EF_ARM_EABI_VER2
:
4634 fprintf (file
, _(" [Version2 EABI]"));
4636 if (flags
& EF_ARM_SYMSARESORTED
)
4637 fprintf (file
, _(" [sorted symbol table]"));
4639 fprintf (file
, _(" [unsorted symbol table]"));
4641 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
4642 fprintf (file
, _(" [dynamic symbols use segment index]"));
4644 if (flags
& EF_ARM_MAPSYMSFIRST
)
4645 fprintf (file
, _(" [mapping symbols precede others]"));
4647 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
4648 | EF_ARM_MAPSYMSFIRST
);
4651 case EF_ARM_EABI_VER3
:
4652 fprintf (file
, _(" [Version3 EABI]"));
4655 case EF_ARM_EABI_VER4
:
4656 fprintf (file
, _(" [Version4 EABI]"));
4658 if (flags
& EF_ARM_BE8
)
4659 fprintf (file
, _(" [BE8]"));
4661 if (flags
& EF_ARM_LE8
)
4662 fprintf (file
, _(" [LE8]"));
4664 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
4668 fprintf (file
, _(" <EABI version unrecognised>"));
4672 flags
&= ~ EF_ARM_EABIMASK
;
4674 if (flags
& EF_ARM_RELEXEC
)
4675 fprintf (file
, _(" [relocatable executable]"));
4677 if (flags
& EF_ARM_HASENTRY
)
4678 fprintf (file
, _(" [has entry point]"));
4680 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
4683 fprintf (file
, _("<Unrecognised flag bits set>"));
4691 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
4693 switch (ELF_ST_TYPE (elf_sym
->st_info
))
4696 return ELF_ST_TYPE (elf_sym
->st_info
);
4699 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
4700 This allows us to distinguish between data used by Thumb instructions
4701 and non-data (which is probably code) inside Thumb regions of an
4703 if (type
!= STT_OBJECT
)
4704 return ELF_ST_TYPE (elf_sym
->st_info
);
4715 elf32_arm_gc_mark_hook (asection
* sec
,
4716 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
4717 Elf_Internal_Rela
* rel
,
4718 struct elf_link_hash_entry
* h
,
4719 Elf_Internal_Sym
* sym
)
4723 switch (ELF32_R_TYPE (rel
->r_info
))
4725 case R_ARM_GNU_VTINHERIT
:
4726 case R_ARM_GNU_VTENTRY
:
4730 switch (h
->root
.type
)
4732 case bfd_link_hash_defined
:
4733 case bfd_link_hash_defweak
:
4734 return h
->root
.u
.def
.section
;
4736 case bfd_link_hash_common
:
4737 return h
->root
.u
.c
.p
->section
;
4745 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4750 /* Update the got entry reference counts for the section being removed. */
4753 elf32_arm_gc_sweep_hook (bfd
* abfd
,
4754 struct bfd_link_info
* info
,
4756 const Elf_Internal_Rela
* relocs
)
4758 Elf_Internal_Shdr
*symtab_hdr
;
4759 struct elf_link_hash_entry
**sym_hashes
;
4760 bfd_signed_vma
*local_got_refcounts
;
4761 const Elf_Internal_Rela
*rel
, *relend
;
4762 struct elf32_arm_link_hash_table
* globals
;
4764 globals
= elf32_arm_hash_table (info
);
4766 elf_section_data (sec
)->local_dynrel
= NULL
;
4768 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4769 sym_hashes
= elf_sym_hashes (abfd
);
4770 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4772 relend
= relocs
+ sec
->reloc_count
;
4773 for (rel
= relocs
; rel
< relend
; rel
++)
4775 unsigned long r_symndx
;
4776 struct elf_link_hash_entry
*h
= NULL
;
4779 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4780 if (r_symndx
>= symtab_hdr
->sh_info
)
4782 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4783 while (h
->root
.type
== bfd_link_hash_indirect
4784 || h
->root
.type
== bfd_link_hash_warning
)
4785 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4788 r_type
= ELF32_R_TYPE (rel
->r_info
);
4789 r_type
= arm_real_reloc_type (globals
, r_type
);
4793 case R_ARM_GOT_PREL
:
4794 case R_ARM_TLS_GD32
:
4795 case R_ARM_TLS_IE32
:
4798 if (h
->got
.refcount
> 0)
4799 h
->got
.refcount
-= 1;
4801 else if (local_got_refcounts
!= NULL
)
4803 if (local_got_refcounts
[r_symndx
] > 0)
4804 local_got_refcounts
[r_symndx
] -= 1;
4808 case R_ARM_TLS_LDM32
:
4809 elf32_arm_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
4819 case R_ARM_THM_CALL
:
4820 /* Should the interworking branches be here also? */
4824 struct elf32_arm_link_hash_entry
*eh
;
4825 struct elf32_arm_relocs_copied
**pp
;
4826 struct elf32_arm_relocs_copied
*p
;
4828 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4830 if (h
->plt
.refcount
> 0)
4832 h
->plt
.refcount
-= 1;
4833 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_CALL
)
4834 eh
->plt_thumb_refcount
--;
4837 if (r_type
== R_ARM_ABS32
4838 || r_type
== R_ARM_REL32
)
4840 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
4842 if (p
->section
== sec
)
4845 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
4863 /* Look through the relocs for a section during the first phase. */
4866 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4867 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4869 Elf_Internal_Shdr
*symtab_hdr
;
4870 struct elf_link_hash_entry
**sym_hashes
;
4871 struct elf_link_hash_entry
**sym_hashes_end
;
4872 const Elf_Internal_Rela
*rel
;
4873 const Elf_Internal_Rela
*rel_end
;
4876 bfd_vma
*local_got_offsets
;
4877 struct elf32_arm_link_hash_table
*htab
;
4879 if (info
->relocatable
)
4882 htab
= elf32_arm_hash_table (info
);
4885 /* Create dynamic sections for relocatable executables so that we can
4886 copy relocations. */
4887 if (htab
->root
.is_relocatable_executable
4888 && ! htab
->root
.dynamic_sections_created
)
4890 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
4894 dynobj
= elf_hash_table (info
)->dynobj
;
4895 local_got_offsets
= elf_local_got_offsets (abfd
);
4897 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4898 sym_hashes
= elf_sym_hashes (abfd
);
4899 sym_hashes_end
= sym_hashes
4900 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
4902 if (!elf_bad_symtab (abfd
))
4903 sym_hashes_end
-= symtab_hdr
->sh_info
;
4905 rel_end
= relocs
+ sec
->reloc_count
;
4906 for (rel
= relocs
; rel
< rel_end
; rel
++)
4908 struct elf_link_hash_entry
*h
;
4909 struct elf32_arm_link_hash_entry
*eh
;
4910 unsigned long r_symndx
;
4913 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4914 r_type
= ELF32_R_TYPE (rel
->r_info
);
4915 r_type
= arm_real_reloc_type (htab
, r_type
);
4917 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
4919 (*_bfd_error_handler
) (_("%B: bad symbol index: %d"), abfd
,
4924 if (r_symndx
< symtab_hdr
->sh_info
)
4927 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4929 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4934 case R_ARM_GOT_PREL
:
4935 case R_ARM_TLS_GD32
:
4936 case R_ARM_TLS_IE32
:
4937 /* This symbol requires a global offset table entry. */
4939 int tls_type
, old_tls_type
;
4943 case R_ARM_TLS_GD32
: tls_type
= GOT_TLS_GD
; break;
4944 case R_ARM_TLS_IE32
: tls_type
= GOT_TLS_IE
; break;
4945 default: tls_type
= GOT_NORMAL
; break;
4951 old_tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
4955 bfd_signed_vma
*local_got_refcounts
;
4957 /* This is a global offset table entry for a local symbol. */
4958 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4959 if (local_got_refcounts
== NULL
)
4963 size
= symtab_hdr
->sh_info
;
4964 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
4965 local_got_refcounts
= bfd_zalloc (abfd
, size
);
4966 if (local_got_refcounts
== NULL
)
4968 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
4969 elf32_arm_local_got_tls_type (abfd
)
4970 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
4972 local_got_refcounts
[r_symndx
] += 1;
4973 old_tls_type
= elf32_arm_local_got_tls_type (abfd
) [r_symndx
];
4976 /* We will already have issued an error message if there is a
4977 TLS / non-TLS mismatch, based on the symbol type. We don't
4978 support any linker relaxations. So just combine any TLS
4980 if (old_tls_type
!= GOT_UNKNOWN
&& old_tls_type
!= GOT_NORMAL
4981 && tls_type
!= GOT_NORMAL
)
4982 tls_type
|= old_tls_type
;
4984 if (old_tls_type
!= tls_type
)
4987 elf32_arm_hash_entry (h
)->tls_type
= tls_type
;
4989 elf32_arm_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
4994 case R_ARM_TLS_LDM32
:
4995 if (r_type
== R_ARM_TLS_LDM32
)
4996 htab
->tls_ldm_got
.refcount
++;
4999 case R_ARM_GOTOFF32
:
5001 if (htab
->sgot
== NULL
)
5003 if (htab
->root
.dynobj
== NULL
)
5004 htab
->root
.dynobj
= abfd
;
5005 if (!create_got_section (htab
->root
.dynobj
, info
))
5017 case R_ARM_THM_CALL
:
5018 /* Should the interworking branches be listed here? */
5021 /* If this reloc is in a read-only section, we might
5022 need a copy reloc. We can't check reliably at this
5023 stage whether the section is read-only, as input
5024 sections have not yet been mapped to output sections.
5025 Tentatively set the flag for now, and correct in
5026 adjust_dynamic_symbol. */
5030 /* We may need a .plt entry if the function this reloc
5031 refers to is in a different object. We can't tell for
5032 sure yet, because something later might force the
5034 if (r_type
== R_ARM_PC24
5035 || r_type
== R_ARM_CALL
5036 || r_type
== R_ARM_JUMP24
5037 || r_type
== R_ARM_PREL31
5038 || r_type
== R_ARM_PLT32
5039 || r_type
== R_ARM_THM_CALL
)
5042 /* If we create a PLT entry, this relocation will reference
5043 it, even if it's an ABS32 relocation. */
5044 h
->plt
.refcount
+= 1;
5046 if (r_type
== R_ARM_THM_CALL
)
5047 eh
->plt_thumb_refcount
+= 1;
5050 /* If we are creating a shared library or relocatable executable,
5051 and this is a reloc against a global symbol, or a non PC
5052 relative reloc against a local symbol, then we need to copy
5053 the reloc into the shared library. However, if we are linking
5054 with -Bsymbolic, we do not need to copy a reloc against a
5055 global symbol which is defined in an object we are
5056 including in the link (i.e., DEF_REGULAR is set). At
5057 this point we have not seen all the input files, so it is
5058 possible that DEF_REGULAR is not set now but will be set
5059 later (it is never cleared). We account for that
5060 possibility below by storing information in the
5061 relocs_copied field of the hash table entry. */
5062 if ((info
->shared
|| htab
->root
.is_relocatable_executable
)
5063 && (sec
->flags
& SEC_ALLOC
) != 0
5064 && (r_type
== R_ARM_ABS32
5065 || (h
!= NULL
&& ! h
->needs_plt
5066 && (! info
->symbolic
|| ! h
->def_regular
))))
5068 struct elf32_arm_relocs_copied
*p
, **head
;
5070 /* When creating a shared object, we must copy these
5071 reloc types into the output file. We create a reloc
5072 section in dynobj and make room for this reloc. */
5077 name
= (bfd_elf_string_from_elf_section
5079 elf_elfheader (abfd
)->e_shstrndx
,
5080 elf_section_data (sec
)->rel_hdr
.sh_name
));
5084 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
5085 && strcmp (bfd_get_section_name (abfd
, sec
),
5088 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5093 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
5094 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
5095 if ((sec
->flags
& SEC_ALLOC
) != 0
5096 /* BPABI objects never have dynamic
5097 relocations mapped. */
5098 && !htab
->symbian_p
)
5099 flags
|= SEC_ALLOC
| SEC_LOAD
;
5100 sreloc
= bfd_make_section_with_flags (dynobj
,
5104 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
5108 elf_section_data (sec
)->sreloc
= sreloc
;
5111 /* If this is a global symbol, we count the number of
5112 relocations we need for this symbol. */
5115 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
5119 /* Track dynamic relocs needed for local syms too.
5120 We really need local syms available to do this
5124 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
5129 head
= ((struct elf32_arm_relocs_copied
**)
5130 &elf_section_data (s
)->local_dynrel
);
5134 if (p
== NULL
|| p
->section
!= sec
)
5136 bfd_size_type amt
= sizeof *p
;
5138 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
5148 if (r_type
== R_ARM_REL32
)
5154 /* This relocation describes the C++ object vtable hierarchy.
5155 Reconstruct it for later use during GC. */
5156 case R_ARM_GNU_VTINHERIT
:
5157 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5161 /* This relocation describes which C++ vtable entries are actually
5162 used. Record for later use during GC. */
5163 case R_ARM_GNU_VTENTRY
:
5164 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
5173 /* Treat mapping symbols as special target symbols. */
5176 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
5178 return bfd_is_arm_mapping_symbol_name (sym
->name
);
5181 /* This is a copy of elf_find_function() from elf.c except that
5182 ARM mapping symbols are ignored when looking for function names
5183 and STT_ARM_TFUNC is considered to a function type. */
5186 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
5190 const char ** filename_ptr
,
5191 const char ** functionname_ptr
)
5193 const char * filename
= NULL
;
5194 asymbol
* func
= NULL
;
5195 bfd_vma low_func
= 0;
5198 for (p
= symbols
; *p
!= NULL
; p
++)
5202 q
= (elf_symbol_type
*) *p
;
5204 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
5209 filename
= bfd_asymbol_name (&q
->symbol
);
5214 /* Skip $a and $t symbols. */
5215 if ((q
->symbol
.flags
& BSF_LOCAL
)
5216 && bfd_is_arm_mapping_symbol_name (q
->symbol
.name
))
5219 if (bfd_get_section (&q
->symbol
) == section
5220 && q
->symbol
.value
>= low_func
5221 && q
->symbol
.value
<= offset
)
5223 func
= (asymbol
*) q
;
5224 low_func
= q
->symbol
.value
;
5234 *filename_ptr
= filename
;
5235 if (functionname_ptr
)
5236 *functionname_ptr
= bfd_asymbol_name (func
);
5242 /* Find the nearest line to a particular section and offset, for error
5243 reporting. This code is a duplicate of the code in elf.c, except
5244 that it uses arm_elf_find_function. */
5247 elf32_arm_find_nearest_line (bfd
* abfd
,
5251 const char ** filename_ptr
,
5252 const char ** functionname_ptr
,
5253 unsigned int * line_ptr
)
5255 bfd_boolean found
= FALSE
;
5257 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
5259 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
5260 filename_ptr
, functionname_ptr
,
5262 & elf_tdata (abfd
)->dwarf2_find_line_info
))
5264 if (!*functionname_ptr
)
5265 arm_elf_find_function (abfd
, section
, symbols
, offset
,
5266 *filename_ptr
? NULL
: filename_ptr
,
5272 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
5273 & found
, filename_ptr
,
5274 functionname_ptr
, line_ptr
,
5275 & elf_tdata (abfd
)->line_info
))
5278 if (found
&& (*functionname_ptr
|| *line_ptr
))
5281 if (symbols
== NULL
)
5284 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
5285 filename_ptr
, functionname_ptr
))
5292 /* Adjust a symbol defined by a dynamic object and referenced by a
5293 regular object. The current definition is in some section of the
5294 dynamic object, but we're not including those sections. We have to
5295 change the definition to something the rest of the link can
5299 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
5300 struct elf_link_hash_entry
* h
)
5304 unsigned int power_of_two
;
5305 struct elf32_arm_link_hash_entry
* eh
;
5306 struct elf32_arm_link_hash_table
*globals
;
5308 globals
= elf32_arm_hash_table (info
);
5309 dynobj
= elf_hash_table (info
)->dynobj
;
5311 /* Make sure we know what is going on here. */
5312 BFD_ASSERT (dynobj
!= NULL
5314 || h
->u
.weakdef
!= NULL
5317 && !h
->def_regular
)));
5319 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5321 /* If this is a function, put it in the procedure linkage table. We
5322 will fill in the contents of the procedure linkage table later,
5323 when we know the address of the .got section. */
5324 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
5327 if (h
->plt
.refcount
<= 0
5328 || SYMBOL_CALLS_LOCAL (info
, h
)
5329 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5330 && h
->root
.type
== bfd_link_hash_undefweak
))
5332 /* This case can occur if we saw a PLT32 reloc in an input
5333 file, but the symbol was never referred to by a dynamic
5334 object, or if all references were garbage collected. In
5335 such a case, we don't actually need to build a procedure
5336 linkage table, and we can just do a PC24 reloc instead. */
5337 h
->plt
.offset
= (bfd_vma
) -1;
5338 eh
->plt_thumb_refcount
= 0;
5346 /* It's possible that we incorrectly decided a .plt reloc was
5347 needed for an R_ARM_PC24 or similar reloc to a non-function sym
5348 in check_relocs. We can't decide accurately between function
5349 and non-function syms in check-relocs; Objects loaded later in
5350 the link may change h->type. So fix it now. */
5351 h
->plt
.offset
= (bfd_vma
) -1;
5352 eh
->plt_thumb_refcount
= 0;
5355 /* If this is a weak symbol, and there is a real definition, the
5356 processor independent code will have arranged for us to see the
5357 real definition first, and we can just use the same value. */
5358 if (h
->u
.weakdef
!= NULL
)
5360 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5361 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5362 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5363 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5367 /* If there are no non-GOT references, we do not need a copy
5369 if (!h
->non_got_ref
)
5372 /* This is a reference to a symbol defined by a dynamic object which
5373 is not a function. */
5375 /* If we are creating a shared library, we must presume that the
5376 only references to the symbol are via the global offset table.
5377 For such cases we need not do anything here; the relocations will
5378 be handled correctly by relocate_section. Relocatable executables
5379 can reference data in shared objects directly, so we don't need to
5380 do anything here. */
5381 if (info
->shared
|| globals
->root
.is_relocatable_executable
)
5384 /* We must allocate the symbol in our .dynbss section, which will
5385 become part of the .bss section of the executable. There will be
5386 an entry for this symbol in the .dynsym section. The dynamic
5387 object will contain position independent code, so all references
5388 from the dynamic object to this symbol will go through the global
5389 offset table. The dynamic linker will use the .dynsym entry to
5390 determine the address it must put in the global offset table, so
5391 both the dynamic object and the regular object will refer to the
5392 same memory location for the variable. */
5393 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
5394 BFD_ASSERT (s
!= NULL
);
5396 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
5397 copy the initial value out of the dynamic object and into the
5398 runtime process image. We need to remember the offset into the
5399 .rel.bss section we are going to use. */
5400 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5404 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
5405 BFD_ASSERT (srel
!= NULL
);
5406 srel
->size
+= sizeof (Elf32_External_Rel
);
5410 /* We need to figure out the alignment required for this symbol. I
5411 have no idea how ELF linkers handle this. */
5412 power_of_two
= bfd_log2 (h
->size
);
5413 if (power_of_two
> 3)
5416 /* Apply the required alignment. */
5417 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
5418 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
5420 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
5424 /* Define the symbol as being at this point in the section. */
5425 h
->root
.u
.def
.section
= s
;
5426 h
->root
.u
.def
.value
= s
->size
;
5428 /* Increment the section size to make room for the symbol. */
5434 /* Allocate space in .plt, .got and associated reloc sections for
5438 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
5440 struct bfd_link_info
*info
;
5441 struct elf32_arm_link_hash_table
*htab
;
5442 struct elf32_arm_link_hash_entry
*eh
;
5443 struct elf32_arm_relocs_copied
*p
;
5445 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5447 if (h
->root
.type
== bfd_link_hash_indirect
)
5450 if (h
->root
.type
== bfd_link_hash_warning
)
5451 /* When warning symbols are created, they **replace** the "real"
5452 entry in the hash table, thus we never get to see the real
5453 symbol in a hash traversal. So look at it now. */
5454 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5456 info
= (struct bfd_link_info
*) inf
;
5457 htab
= elf32_arm_hash_table (info
);
5459 if (htab
->root
.dynamic_sections_created
5460 && h
->plt
.refcount
> 0)
5462 /* Make sure this symbol is output as a dynamic symbol.
5463 Undefined weak syms won't yet be marked as dynamic. */
5464 if (h
->dynindx
== -1
5465 && !h
->forced_local
)
5467 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5472 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
5474 asection
*s
= htab
->splt
;
5476 /* If this is the first .plt entry, make room for the special
5479 s
->size
+= htab
->plt_header_size
;
5481 h
->plt
.offset
= s
->size
;
5483 /* If we will insert a Thumb trampoline before this PLT, leave room
5485 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
5487 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
5488 s
->size
+= PLT_THUMB_STUB_SIZE
;
5491 /* If this symbol is not defined in a regular file, and we are
5492 not generating a shared library, then set the symbol to this
5493 location in the .plt. This is required to make function
5494 pointers compare as equal between the normal executable and
5495 the shared library. */
5499 h
->root
.u
.def
.section
= s
;
5500 h
->root
.u
.def
.value
= h
->plt
.offset
;
5502 /* Make sure the function is not marked as Thumb, in case
5503 it is the target of an ABS32 relocation, which will
5504 point to the PLT entry. */
5505 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
5506 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
5509 /* Make room for this entry. */
5510 s
->size
+= htab
->plt_entry_size
;
5512 if (!htab
->symbian_p
)
5514 /* We also need to make an entry in the .got.plt section, which
5515 will be placed in the .got section by the linker script. */
5516 eh
->plt_got_offset
= htab
->sgotplt
->size
;
5517 htab
->sgotplt
->size
+= 4;
5520 /* We also need to make an entry in the .rel.plt section. */
5521 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
5525 h
->plt
.offset
= (bfd_vma
) -1;
5531 h
->plt
.offset
= (bfd_vma
) -1;
5535 if (h
->got
.refcount
> 0)
5539 int tls_type
= elf32_arm_hash_entry (h
)->tls_type
;
5542 /* Make sure this symbol is output as a dynamic symbol.
5543 Undefined weak syms won't yet be marked as dynamic. */
5544 if (h
->dynindx
== -1
5545 && !h
->forced_local
)
5547 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5551 if (!htab
->symbian_p
)
5554 h
->got
.offset
= s
->size
;
5556 if (tls_type
== GOT_UNKNOWN
)
5559 if (tls_type
== GOT_NORMAL
)
5560 /* Non-TLS symbols need one GOT slot. */
5564 if (tls_type
& GOT_TLS_GD
)
5565 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
5567 if (tls_type
& GOT_TLS_IE
)
5568 /* R_ARM_TLS_IE32 needs one GOT slot. */
5572 dyn
= htab
->root
.dynamic_sections_created
;
5575 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5577 || !SYMBOL_REFERENCES_LOCAL (info
, h
)))
5580 if (tls_type
!= GOT_NORMAL
5581 && (info
->shared
|| indx
!= 0)
5582 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5583 || h
->root
.type
!= bfd_link_hash_undefweak
))
5585 if (tls_type
& GOT_TLS_IE
)
5586 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
5588 if (tls_type
& GOT_TLS_GD
)
5589 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
5591 if ((tls_type
& GOT_TLS_GD
) && indx
!= 0)
5592 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
5594 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5595 || h
->root
.type
!= bfd_link_hash_undefweak
)
5597 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
5598 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
5602 h
->got
.offset
= (bfd_vma
) -1;
5604 if (eh
->relocs_copied
== NULL
)
5607 /* In the shared -Bsymbolic case, discard space allocated for
5608 dynamic pc-relative relocs against symbols which turn out to be
5609 defined in regular objects. For the normal shared case, discard
5610 space for pc-relative relocs that have become local due to symbol
5611 visibility changes. */
5613 if (info
->shared
|| htab
->root
.is_relocatable_executable
)
5615 /* The only reloc that uses pc_count is R_ARM_REL32, which will
5616 appear on something like ".long foo - .". We want calls to
5617 protected symbols to resolve directly to the function rather
5618 than going via the plt. If people want function pointer
5619 comparisons to work as expected then they should avoid
5620 writing assembly like ".long foo - .". */
5621 if (SYMBOL_CALLS_LOCAL (info
, h
))
5623 struct elf32_arm_relocs_copied
**pp
;
5625 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
5627 p
->count
-= p
->pc_count
;
5636 /* Also discard relocs on undefined weak syms with non-default
5638 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5639 && h
->root
.type
== bfd_link_hash_undefweak
)
5640 eh
->relocs_copied
= NULL
;
5641 else if (htab
->root
.is_relocatable_executable
&& h
->dynindx
== -1
5642 && h
->root
.type
== bfd_link_hash_new
)
5644 /* Output absolute symbols so that we can create relocations
5645 against them. For normal symbols we output a relocation
5646 against the section that contains them. */
5647 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5654 /* For the non-shared case, discard space for relocs against
5655 symbols which turn out to need copy relocs or are not
5661 || (htab
->root
.dynamic_sections_created
5662 && (h
->root
.type
== bfd_link_hash_undefweak
5663 || h
->root
.type
== bfd_link_hash_undefined
))))
5665 /* Make sure this symbol is output as a dynamic symbol.
5666 Undefined weak syms won't yet be marked as dynamic. */
5667 if (h
->dynindx
== -1
5668 && !h
->forced_local
)
5670 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5674 /* If that succeeded, we know we'll be keeping all the
5676 if (h
->dynindx
!= -1)
5680 eh
->relocs_copied
= NULL
;
5685 /* Finally, allocate space. */
5686 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
5688 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
5689 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
5695 /* Find any dynamic relocs that apply to read-only sections. */
5698 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
5700 struct elf32_arm_link_hash_entry
*eh
;
5701 struct elf32_arm_relocs_copied
*p
;
5703 if (h
->root
.type
== bfd_link_hash_warning
)
5704 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5706 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5707 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
5709 asection
*s
= p
->section
;
5711 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5713 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5715 info
->flags
|= DF_TEXTREL
;
5717 /* Not an error, just cut short the traversal. */
5724 /* Set the sizes of the dynamic sections. */
5727 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
5728 struct bfd_link_info
* info
)
5735 struct elf32_arm_link_hash_table
*htab
;
5737 htab
= elf32_arm_hash_table (info
);
5738 dynobj
= elf_hash_table (info
)->dynobj
;
5739 BFD_ASSERT (dynobj
!= NULL
);
5741 if (elf_hash_table (info
)->dynamic_sections_created
)
5743 /* Set the contents of the .interp section to the interpreter. */
5744 if (info
->executable
)
5746 s
= bfd_get_section_by_name (dynobj
, ".interp");
5747 BFD_ASSERT (s
!= NULL
);
5748 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5749 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5753 /* Set up .got offsets for local syms, and space for local dynamic
5755 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5757 bfd_signed_vma
*local_got
;
5758 bfd_signed_vma
*end_local_got
;
5759 char *local_tls_type
;
5760 bfd_size_type locsymcount
;
5761 Elf_Internal_Shdr
*symtab_hdr
;
5764 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
5767 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5769 struct elf32_arm_relocs_copied
*p
;
5771 for (p
= *((struct elf32_arm_relocs_copied
**)
5772 &elf_section_data (s
)->local_dynrel
);
5776 if (!bfd_is_abs_section (p
->section
)
5777 && bfd_is_abs_section (p
->section
->output_section
))
5779 /* Input section has been discarded, either because
5780 it is a copy of a linkonce section or due to
5781 linker script /DISCARD/, so we'll be discarding
5784 else if (p
->count
!= 0)
5786 srel
= elf_section_data (p
->section
)->sreloc
;
5787 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
5788 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
5789 info
->flags
|= DF_TEXTREL
;
5794 local_got
= elf_local_got_refcounts (ibfd
);
5798 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
5799 locsymcount
= symtab_hdr
->sh_info
;
5800 end_local_got
= local_got
+ locsymcount
;
5801 local_tls_type
= elf32_arm_local_got_tls_type (ibfd
);
5803 srel
= htab
->srelgot
;
5804 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
5808 *local_got
= s
->size
;
5809 if (*local_tls_type
& GOT_TLS_GD
)
5810 /* TLS_GD relocs need an 8-byte structure in the GOT. */
5812 if (*local_tls_type
& GOT_TLS_IE
)
5814 if (*local_tls_type
== GOT_NORMAL
)
5817 if (info
->shared
|| *local_tls_type
== GOT_TLS_GD
)
5818 srel
->size
+= sizeof (Elf32_External_Rel
);
5821 *local_got
= (bfd_vma
) -1;
5825 if (htab
->tls_ldm_got
.refcount
> 0)
5827 /* Allocate two GOT entries and one dynamic relocation (if necessary)
5828 for R_ARM_TLS_LDM32 relocations. */
5829 htab
->tls_ldm_got
.offset
= htab
->sgot
->size
;
5830 htab
->sgot
->size
+= 8;
5832 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
5835 htab
->tls_ldm_got
.offset
= -1;
5837 /* Allocate global sym .plt and .got entries, and space for global
5838 sym dynamic relocs. */
5839 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
5841 /* The check_relocs and adjust_dynamic_symbol entry points have
5842 determined the sizes of the various dynamic sections. Allocate
5846 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5851 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5854 /* It's OK to base decisions on the section name, because none
5855 of the dynobj section names depend upon the input files. */
5856 name
= bfd_get_section_name (dynobj
, s
);
5860 if (strcmp (name
, ".plt") == 0)
5864 /* Strip this section if we don't need it; see the
5870 /* Remember whether there is a PLT. */
5874 else if (strncmp (name
, ".rel", 4) == 0)
5878 /* If we don't need this section, strip it from the
5879 output file. This is mostly to handle .rel.bss and
5880 .rel.plt. We must create both sections in
5881 create_dynamic_sections, because they must be created
5882 before the linker maps input sections to output
5883 sections. The linker does that before
5884 adjust_dynamic_symbol is called, and it is that
5885 function which decides whether anything needs to go
5886 into these sections. */
5891 /* Remember whether there are any reloc sections other
5893 if (strcmp (name
, ".rel.plt") != 0)
5896 /* We use the reloc_count field as a counter if we need
5897 to copy relocs into the output file. */
5901 else if (strncmp (name
, ".got", 4) != 0)
5903 /* It's not one of our sections, so don't allocate space. */
5909 s
->flags
|= SEC_EXCLUDE
;
5913 /* Allocate memory for the section contents. */
5914 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
5915 if (s
->contents
== NULL
&& s
->size
!= 0)
5919 if (elf_hash_table (info
)->dynamic_sections_created
)
5921 /* Add some entries to the .dynamic section. We fill in the
5922 values later, in elf32_arm_finish_dynamic_sections, but we
5923 must add the entries now so that we get the correct size for
5924 the .dynamic section. The DT_DEBUG entry is filled in by the
5925 dynamic linker and used by the debugger. */
5926 #define add_dynamic_entry(TAG, VAL) \
5927 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5931 if (!add_dynamic_entry (DT_DEBUG
, 0))
5937 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
5938 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
5939 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
5940 || !add_dynamic_entry (DT_JMPREL
, 0))
5946 if ( !add_dynamic_entry (DT_REL
, 0)
5947 || !add_dynamic_entry (DT_RELSZ
, 0)
5948 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
5952 /* If any dynamic relocs apply to a read-only section,
5953 then we need a DT_TEXTREL entry. */
5954 if ((info
->flags
& DF_TEXTREL
) == 0)
5955 elf_link_hash_traverse (&htab
->root
, elf32_arm_readonly_dynrelocs
,
5958 if ((info
->flags
& DF_TEXTREL
) != 0)
5960 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5962 info
->flags
|= DF_TEXTREL
;
5965 #undef add_synamic_entry
5970 /* Finish up dynamic symbol handling. We set the contents of various
5971 dynamic sections here. */
5974 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
5975 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
5978 struct elf32_arm_link_hash_table
*htab
;
5979 struct elf32_arm_link_hash_entry
*eh
;
5981 dynobj
= elf_hash_table (info
)->dynobj
;
5982 htab
= elf32_arm_hash_table (info
);
5983 eh
= (struct elf32_arm_link_hash_entry
*) h
;
5985 if (h
->plt
.offset
!= (bfd_vma
) -1)
5991 Elf_Internal_Rela rel
;
5993 /* This symbol has an entry in the procedure linkage table. Set
5996 BFD_ASSERT (h
->dynindx
!= -1);
5998 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5999 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
6000 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
6002 /* Fill in the entry in the procedure linkage table. */
6003 if (htab
->symbian_p
)
6006 for (i
= 0; i
< htab
->plt_entry_size
/ 4; ++i
)
6007 bfd_put_32 (output_bfd
,
6008 elf32_arm_symbian_plt_entry
[i
],
6009 splt
->contents
+ h
->plt
.offset
+ 4 * i
);
6011 /* Fill in the entry in the .rel.plt section. */
6012 rel
.r_offset
= (splt
->output_section
->vma
6013 + splt
->output_offset
6014 + h
->plt
.offset
+ 4 * (i
- 1));
6015 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
6017 /* Get the index in the procedure linkage table which
6018 corresponds to this symbol. This is the index of this symbol
6019 in all the symbols for which we are making plt entries. The
6020 first entry in the procedure linkage table is reserved. */
6021 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
6022 / htab
->plt_entry_size
);
6027 bfd_vma got_displacement
;
6030 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
6031 BFD_ASSERT (sgot
!= NULL
);
6033 /* Get the offset into the .got.plt table of the entry that
6034 corresponds to this function. */
6035 got_offset
= eh
->plt_got_offset
;
6037 /* Get the index in the procedure linkage table which
6038 corresponds to this symbol. This is the index of this symbol
6039 in all the symbols for which we are making plt entries. The
6040 first three entries in .got.plt are reserved; after that
6041 symbols appear in the same order as in .plt. */
6042 plt_index
= (got_offset
- 12) / 4;
6044 /* Calculate the displacement between the PLT slot and the
6045 entry in the GOT. The eight-byte offset accounts for the
6046 value produced by adding to pc in the first instruction
6048 got_displacement
= (sgot
->output_section
->vma
6049 + sgot
->output_offset
6051 - splt
->output_section
->vma
6052 - splt
->output_offset
6056 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
6058 if (!htab
->use_blx
&& eh
->plt_thumb_refcount
> 0)
6060 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[0],
6061 splt
->contents
+ h
->plt
.offset
- 4);
6062 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[1],
6063 splt
->contents
+ h
->plt
.offset
- 2);
6066 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
6067 splt
->contents
+ h
->plt
.offset
+ 0);
6068 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
6069 splt
->contents
+ h
->plt
.offset
+ 4);
6070 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
6071 splt
->contents
+ h
->plt
.offset
+ 8);
6072 #ifdef FOUR_WORD_PLT
6073 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
6074 splt
->contents
+ h
->plt
.offset
+ 12);
6077 /* Fill in the entry in the global offset table. */
6078 bfd_put_32 (output_bfd
,
6079 (splt
->output_section
->vma
6080 + splt
->output_offset
),
6081 sgot
->contents
+ got_offset
);
6083 /* Fill in the entry in the .rel.plt section. */
6084 rel
.r_offset
= (sgot
->output_section
->vma
6085 + sgot
->output_offset
6087 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
6090 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
6091 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
6093 if (!h
->def_regular
)
6095 /* Mark the symbol as undefined, rather than as defined in
6096 the .plt section. Leave the value alone. */
6097 sym
->st_shndx
= SHN_UNDEF
;
6098 /* If the symbol is weak, we do need to clear the value.
6099 Otherwise, the PLT entry would provide a definition for
6100 the symbol even if the symbol wasn't defined anywhere,
6101 and so the symbol would never be NULL. */
6102 if (!h
->ref_regular_nonweak
)
6107 if (h
->got
.offset
!= (bfd_vma
) -1
6108 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_GD
) == 0
6109 && (elf32_arm_hash_entry (h
)->tls_type
& GOT_TLS_IE
) == 0)
6113 Elf_Internal_Rela rel
;
6116 /* This symbol has an entry in the global offset table. Set it
6118 sgot
= bfd_get_section_by_name (dynobj
, ".got");
6119 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
6120 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
6122 rel
.r_offset
= (sgot
->output_section
->vma
6123 + sgot
->output_offset
6124 + (h
->got
.offset
&~ (bfd_vma
) 1));
6126 /* If this is a static link, or it is a -Bsymbolic link and the
6127 symbol is defined locally or was forced to be local because
6128 of a version file, we just want to emit a RELATIVE reloc.
6129 The entry in the global offset table will already have been
6130 initialized in the relocate_section function. */
6132 && SYMBOL_REFERENCES_LOCAL (info
, h
))
6134 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6135 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
6139 BFD_ASSERT((h
->got
.offset
& 1) == 0);
6140 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
6141 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
6144 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
6145 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
6151 Elf_Internal_Rela rel
;
6154 /* This symbol needs a copy reloc. Set it up. */
6155 BFD_ASSERT (h
->dynindx
!= -1
6156 && (h
->root
.type
== bfd_link_hash_defined
6157 || h
->root
.type
== bfd_link_hash_defweak
));
6159 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
6161 BFD_ASSERT (s
!= NULL
);
6163 rel
.r_offset
= (h
->root
.u
.def
.value
6164 + h
->root
.u
.def
.section
->output_section
->vma
6165 + h
->root
.u
.def
.section
->output_offset
);
6166 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
6167 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
6168 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
6171 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6172 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6173 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
6174 sym
->st_shndx
= SHN_ABS
;
6179 /* Finish up the dynamic sections. */
6182 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
6188 dynobj
= elf_hash_table (info
)->dynobj
;
6190 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
6191 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
6192 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6194 if (elf_hash_table (info
)->dynamic_sections_created
)
6197 Elf32_External_Dyn
*dyncon
, *dynconend
;
6198 struct elf32_arm_link_hash_table
*htab
;
6200 htab
= elf32_arm_hash_table (info
);
6201 splt
= bfd_get_section_by_name (dynobj
, ".plt");
6202 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
6204 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6205 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
6207 for (; dyncon
< dynconend
; dyncon
++)
6209 Elf_Internal_Dyn dyn
;
6213 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6224 goto get_vma_if_bpabi
;
6227 goto get_vma_if_bpabi
;
6230 goto get_vma_if_bpabi
;
6232 name
= ".gnu.version";
6233 goto get_vma_if_bpabi
;
6235 name
= ".gnu.version_d";
6236 goto get_vma_if_bpabi
;
6238 name
= ".gnu.version_r";
6239 goto get_vma_if_bpabi
;
6247 s
= bfd_get_section_by_name (output_bfd
, name
);
6248 BFD_ASSERT (s
!= NULL
);
6249 if (!htab
->symbian_p
)
6250 dyn
.d_un
.d_ptr
= s
->vma
;
6252 /* In the BPABI, tags in the PT_DYNAMIC section point
6253 at the file offset, not the memory address, for the
6254 convenience of the post linker. */
6255 dyn
.d_un
.d_ptr
= s
->filepos
;
6256 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6260 if (htab
->symbian_p
)
6265 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
6266 BFD_ASSERT (s
!= NULL
);
6267 dyn
.d_un
.d_val
= s
->size
;
6268 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6272 if (!htab
->symbian_p
)
6274 /* My reading of the SVR4 ABI indicates that the
6275 procedure linkage table relocs (DT_JMPREL) should be
6276 included in the overall relocs (DT_REL). This is
6277 what Solaris does. However, UnixWare can not handle
6278 that case. Therefore, we override the DT_RELSZ entry
6279 here to make it not include the JMPREL relocs. Since
6280 the linker script arranges for .rel.plt to follow all
6281 other relocation sections, we don't have to worry
6282 about changing the DT_REL entry. */
6283 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
6285 dyn
.d_un
.d_val
-= s
->size
;
6286 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6294 /* In the BPABI, the DT_REL tag must point at the file
6295 offset, not the VMA, of the first relocation
6296 section. So, we use code similar to that in
6297 elflink.c, but do not check for SHF_ALLOC on the
6298 relcoation section, since relocations sections are
6299 never allocated under the BPABI. The comments above
6300 about Unixware notwithstanding, we include all of the
6301 relocations here. */
6302 if (htab
->symbian_p
)
6305 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
6306 ? SHT_REL
: SHT_RELA
);
6308 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
6310 Elf_Internal_Shdr
*hdr
6311 = elf_elfsections (output_bfd
)[i
];
6312 if (hdr
->sh_type
== type
)
6314 if (dyn
.d_tag
== DT_RELSZ
6315 || dyn
.d_tag
== DT_RELASZ
)
6316 dyn
.d_un
.d_val
+= hdr
->sh_size
;
6317 else if ((ufile_ptr
) hdr
->sh_offset
6318 <= dyn
.d_un
.d_val
- 1)
6319 dyn
.d_un
.d_val
= hdr
->sh_offset
;
6322 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6326 /* Set the bottom bit of DT_INIT/FINI if the
6327 corresponding function is Thumb. */
6329 name
= info
->init_function
;
6332 name
= info
->fini_function
;
6334 /* If it wasn't set by elf_bfd_final_link
6335 then there is nothing to adjust. */
6336 if (dyn
.d_un
.d_val
!= 0)
6338 struct elf_link_hash_entry
* eh
;
6340 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
6341 FALSE
, FALSE
, TRUE
);
6342 if (eh
!= (struct elf_link_hash_entry
*) NULL
6343 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
6345 dyn
.d_un
.d_val
|= 1;
6346 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6353 /* Fill in the first entry in the procedure linkage table. */
6354 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
6356 bfd_vma got_displacement
;
6358 /* Calculate the displacement between the PLT slot and &GOT[0]. */
6359 got_displacement
= (sgot
->output_section
->vma
6360 + sgot
->output_offset
6361 - splt
->output_section
->vma
6362 - splt
->output_offset
6365 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
6366 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
6367 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
6368 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
6369 #ifdef FOUR_WORD_PLT
6370 /* The displacement value goes in the otherwise-unused last word of
6371 the second entry. */
6372 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
6374 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
6378 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6379 really seem like the right value. */
6380 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
6383 /* Fill in the first three entries in the global offset table. */
6389 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6391 bfd_put_32 (output_bfd
,
6392 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6394 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
6395 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
6398 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6405 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
6407 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
6408 struct elf32_arm_link_hash_table
*globals
;
6410 i_ehdrp
= elf_elfheader (abfd
);
6412 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
6413 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
6415 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
6416 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
6420 globals
= elf32_arm_hash_table (link_info
);
6421 if (globals
->byteswap_code
)
6422 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
6426 static enum elf_reloc_type_class
6427 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
6429 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6431 case R_ARM_RELATIVE
:
6432 return reloc_class_relative
;
6433 case R_ARM_JUMP_SLOT
:
6434 return reloc_class_plt
;
6436 return reloc_class_copy
;
6438 return reloc_class_normal
;
6442 /* Set the right machine number for an Arm ELF file. */
6445 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
6447 if (hdr
->sh_type
== SHT_NOTE
)
6448 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
6454 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6456 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
6459 /* Return TRUE if this is an unwinding table entry. */
6462 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
6466 len1
= sizeof (ELF_STRING_ARM_unwind
) - 1;
6467 len2
= sizeof (ELF_STRING_ARM_unwind_once
) - 1;
6468 return (strncmp (name
, ELF_STRING_ARM_unwind
, len1
) == 0
6469 || strncmp (name
, ELF_STRING_ARM_unwind_once
, len2
) == 0);
6473 /* Set the type and flags for an ARM section. We do this by
6474 the section name, which is a hack, but ought to work. */
6477 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
6481 name
= bfd_get_section_name (abfd
, sec
);
6483 if (is_arm_elf_unwind_section_name (abfd
, name
))
6485 hdr
->sh_type
= SHT_ARM_EXIDX
;
6486 hdr
->sh_flags
|= SHF_LINK_ORDER
;
6491 /* Handle an ARM specific section when reading an object file. This is
6492 called when bfd_section_from_shdr finds a section with an unknown
6496 elf32_arm_section_from_shdr (bfd
*abfd
,
6497 Elf_Internal_Shdr
* hdr
,
6501 /* There ought to be a place to keep ELF backend specific flags, but
6502 at the moment there isn't one. We just keep track of the
6503 sections by their name, instead. Fortunately, the ABI gives
6504 names for all the ARM specific sections, so we will probably get
6506 switch (hdr
->sh_type
)
6515 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6521 /* Called for each symbol. Builds a section map based on mapping symbols.
6522 Does not alter any of the symbols. */
6525 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
6527 Elf_Internal_Sym
*elfsym
,
6528 asection
*input_sec
,
6529 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6532 elf32_arm_section_map
*map
;
6533 struct elf32_arm_link_hash_table
*globals
;
6535 /* Only do this on final link. */
6536 if (info
->relocatable
)
6539 /* Only build a map if we need to byteswap code. */
6540 globals
= elf32_arm_hash_table (info
);
6541 if (!globals
->byteswap_code
)
6544 /* We only want mapping symbols. */
6545 if (! bfd_is_arm_mapping_symbol_name (name
))
6548 mapcount
= ++(elf32_arm_section_data (input_sec
)->mapcount
);
6549 map
= elf32_arm_section_data (input_sec
)->map
;
6550 /* TODO: This may be inefficient, but we probably don't usually have many
6551 mapping symbols per section. */
6552 map
= bfd_realloc (map
, mapcount
* sizeof (elf32_arm_section_map
));
6553 elf32_arm_section_data (input_sec
)->map
= map
;
6555 map
[mapcount
- 1].vma
= elfsym
->st_value
;
6556 map
[mapcount
- 1].type
= name
[1];
6561 /* Allocate target specific section data. */
6564 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
6566 struct _arm_elf_section_data
*sdata
;
6567 bfd_size_type amt
= sizeof (*sdata
);
6569 sdata
= bfd_zalloc (abfd
, amt
);
6572 sec
->used_by_bfd
= sdata
;
6574 return _bfd_elf_new_section_hook (abfd
, sec
);
6578 /* Used to order a list of mapping symbols by address. */
6581 elf32_arm_compare_mapping (const void * a
, const void * b
)
6583 return ((const elf32_arm_section_map
*) a
)->vma
6584 > ((const elf32_arm_section_map
*) b
)->vma
;
6588 /* Do code byteswapping. Return FALSE afterwards so that the section is
6589 written out as normal. */
6592 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
6596 elf32_arm_section_map
*map
;
6603 mapcount
= elf32_arm_section_data (sec
)->mapcount
;
6604 map
= elf32_arm_section_data (sec
)->map
;
6609 qsort (map
, mapcount
, sizeof (elf32_arm_section_map
),
6610 elf32_arm_compare_mapping
);
6612 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
6613 ptr
= map
[0].vma
- offset
;
6614 for (i
= 0; i
< mapcount
; i
++)
6616 if (i
== mapcount
- 1)
6619 end
= map
[i
+ 1].vma
- offset
;
6621 switch (map
[i
].type
)
6624 /* Byte swap code words. */
6625 while (ptr
+ 3 < end
)
6627 tmp
= contents
[ptr
];
6628 contents
[ptr
] = contents
[ptr
+ 3];
6629 contents
[ptr
+ 3] = tmp
;
6630 tmp
= contents
[ptr
+ 1];
6631 contents
[ptr
+ 1] = contents
[ptr
+ 2];
6632 contents
[ptr
+ 2] = tmp
;
6638 /* Byte swap code halfwords. */
6639 while (ptr
+ 1 < end
)
6641 tmp
= contents
[ptr
];
6642 contents
[ptr
] = contents
[ptr
+ 1];
6643 contents
[ptr
+ 1] = tmp
;
6649 /* Leave data alone. */
6658 /* Display STT_ARM_TFUNC symbols as functions. */
6661 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
6664 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
6666 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
6667 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
6671 /* Mangle thumb function symbols as we read them in. */
6674 elf32_arm_swap_symbol_in (bfd
* abfd
,
6677 Elf_Internal_Sym
*dst
)
6679 bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
);
6681 /* New EABI objects mark thumb function symbols by setting the low bit of
6682 the address. Turn these into STT_ARM_TFUNC. */
6683 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
6684 && (dst
->st_value
& 1))
6686 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
6687 dst
->st_value
&= ~(bfd_vma
) 1;
6692 /* Mangle thumb function symbols as we write them out. */
6695 elf32_arm_swap_symbol_out (bfd
*abfd
,
6696 const Elf_Internal_Sym
*src
,
6700 Elf_Internal_Sym newsym
;
6702 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
6703 of the address set, as per the new EABI. We do this unconditionally
6704 because objcopy does not set the elf header flags until after
6705 it writes out the symbol table. */
6706 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
6709 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
6710 newsym
.st_value
|= 1;
6714 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
6717 /* Add the PT_ARM_EXIDX program header. */
6720 elf32_arm_modify_segment_map (bfd
*abfd
,
6721 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
6723 struct elf_segment_map
*m
;
6726 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
6727 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
6729 /* If there is already a PT_ARM_EXIDX header, then we do not
6730 want to add another one. This situation arises when running
6731 "strip"; the input binary already has the header. */
6732 m
= elf_tdata (abfd
)->segment_map
;
6733 while (m
&& m
->p_type
!= PT_ARM_EXIDX
)
6737 m
= bfd_zalloc (abfd
, sizeof (struct elf_segment_map
));
6740 m
->p_type
= PT_ARM_EXIDX
;
6742 m
->sections
[0] = sec
;
6744 m
->next
= elf_tdata (abfd
)->segment_map
;
6745 elf_tdata (abfd
)->segment_map
= m
;
6752 /* We may add a PT_ARM_EXIDX program header. */
6755 elf32_arm_additional_program_headers (bfd
*abfd
)
6759 sec
= bfd_get_section_by_name (abfd
, ".ARM.exidx");
6760 if (sec
!= NULL
&& (sec
->flags
& SEC_LOAD
) != 0)
6766 /* We use this to override swap_symbol_in and swap_symbol_out. */
6767 const struct elf_size_info elf32_arm_size_info
= {
6768 sizeof (Elf32_External_Ehdr
),
6769 sizeof (Elf32_External_Phdr
),
6770 sizeof (Elf32_External_Shdr
),
6771 sizeof (Elf32_External_Rel
),
6772 sizeof (Elf32_External_Rela
),
6773 sizeof (Elf32_External_Sym
),
6774 sizeof (Elf32_External_Dyn
),
6775 sizeof (Elf_External_Note
),
6779 ELFCLASS32
, EV_CURRENT
,
6780 bfd_elf32_write_out_phdrs
,
6781 bfd_elf32_write_shdrs_and_ehdr
,
6782 bfd_elf32_write_relocs
,
6783 elf32_arm_swap_symbol_in
,
6784 elf32_arm_swap_symbol_out
,
6785 bfd_elf32_slurp_reloc_table
,
6786 bfd_elf32_slurp_symbol_table
,
6787 bfd_elf32_swap_dyn_in
,
6788 bfd_elf32_swap_dyn_out
,
6789 bfd_elf32_swap_reloc_in
,
6790 bfd_elf32_swap_reloc_out
,
6791 bfd_elf32_swap_reloca_in
,
6792 bfd_elf32_swap_reloca_out
6795 #define ELF_ARCH bfd_arch_arm
6796 #define ELF_MACHINE_CODE EM_ARM
6797 #ifdef __QNXTARGET__
6798 #define ELF_MAXPAGESIZE 0x1000
6800 #define ELF_MAXPAGESIZE 0x8000
6802 #define ELF_MINPAGESIZE 0x1000
6804 #define bfd_elf32_mkobject elf32_arm_mkobject
6806 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
6807 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
6808 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
6809 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
6810 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
6811 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
6812 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
6813 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
6814 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
6816 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
6817 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6818 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
6819 #define elf_backend_check_relocs elf32_arm_check_relocs
6820 #define elf_backend_relocate_section elf32_arm_relocate_section
6821 #define elf_backend_write_section elf32_arm_write_section
6822 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
6823 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
6824 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
6825 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
6826 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
6827 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
6828 #define elf_backend_post_process_headers elf32_arm_post_process_headers
6829 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
6830 #define elf_backend_object_p elf32_arm_object_p
6831 #define elf_backend_section_flags elf32_arm_section_flags
6832 #define elf_backend_fake_sections elf32_arm_fake_sections
6833 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
6834 #define elf_backend_final_write_processing elf32_arm_final_write_processing
6835 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
6836 #define elf_backend_symbol_processing elf32_arm_symbol_processing
6837 #define elf_backend_size_info elf32_arm_size_info
6838 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
6839 #define elf_backend_additional_program_headers \
6840 elf32_arm_additional_program_headers
6842 #define elf_backend_can_refcount 1
6843 #define elf_backend_can_gc_sections 1
6844 #define elf_backend_plt_readonly 1
6845 #define elf_backend_want_got_plt 1
6846 #define elf_backend_want_plt_sym 0
6847 #define elf_backend_may_use_rel_p 1
6848 #define elf_backend_may_use_rela_p 0
6849 #define elf_backend_default_use_rela_p 0
6850 #define elf_backend_rela_normal 0
6852 #define elf_backend_got_header_size 12
6854 #include "elf32-target.h"
6856 /* VxWorks Targets */
6858 #undef TARGET_LITTLE_SYM
6859 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
6860 #undef TARGET_LITTLE_NAME
6861 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
6862 #undef TARGET_BIG_SYM
6863 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
6864 #undef TARGET_BIG_NAME
6865 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
6867 /* Like elf32_arm_link_hash_table_create -- but overrides
6868 appropriately for VxWorks. */
6869 static struct bfd_link_hash_table
*
6870 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
6872 struct bfd_link_hash_table
*ret
;
6874 ret
= elf32_arm_link_hash_table_create (abfd
);
6877 struct elf32_arm_link_hash_table
*htab
6878 = (struct elf32_arm_link_hash_table
*)ret
;
6885 #define elf32_bed elf32_arm_vxworks_bed
6887 #undef bfd_elf32_bfd_link_hash_table_create
6888 #define bfd_elf32_bfd_link_hash_table_create \
6889 elf32_arm_vxworks_link_hash_table_create
6891 #undef elf_backend_may_use_rel_p
6892 #define elf_backend_may_use_rel_p 0
6893 #undef elf_backend_may_use_rela_p
6894 #define elf_backend_may_use_rela_p 1
6895 #undef elf_backend_default_use_rela_p
6896 #define elf_backend_default_use_rela_p 1
6897 #undef elf_backend_rela_normal
6898 #define elf_backend_rela_normal 1
6900 #include "elf32-target.h"
6903 /* Symbian OS Targets */
6905 #undef TARGET_LITTLE_SYM
6906 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
6907 #undef TARGET_LITTLE_NAME
6908 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
6909 #undef TARGET_BIG_SYM
6910 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
6911 #undef TARGET_BIG_NAME
6912 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
6914 /* Like elf32_arm_link_hash_table_create -- but overrides
6915 appropriately for Symbian OS. */
6916 static struct bfd_link_hash_table
*
6917 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
6919 struct bfd_link_hash_table
*ret
;
6921 ret
= elf32_arm_link_hash_table_create (abfd
);
6924 struct elf32_arm_link_hash_table
*htab
6925 = (struct elf32_arm_link_hash_table
*)ret
;
6926 /* There is no PLT header for Symbian OS. */
6927 htab
->plt_header_size
= 0;
6928 /* The PLT entries are each three instructions. */
6929 htab
->plt_entry_size
= 4 * NUM_ELEM (elf32_arm_symbian_plt_entry
);
6930 htab
->symbian_p
= 1;
6931 /* Symbian uses armv5t or above, so use_blx is always true. */
6933 htab
->root
.is_relocatable_executable
= 1;
6938 static struct bfd_elf_special_section
const
6939 symbian_special_sections_d
[]=
6941 /* In a BPABI executable, the dynamic linking sections do not go in
6942 the loadable read-only segment. The post-linker may wish to
6943 refer to these sections, but they are not part of the final
6945 { ".dynamic", 8, 0, SHT_DYNAMIC
, 0 },
6946 { ".dynstr", 7, 0, SHT_STRTAB
, 0 },
6947 { ".dynsym", 7, 0, SHT_DYNSYM
, 0 },
6948 { NULL
, 0, 0, 0, 0 }
6951 static struct bfd_elf_special_section
const
6952 symbian_special_sections_g
[]=
6954 /* In a BPABI executable, the dynamic linking sections do not go in
6955 the loadable read-only segment. The post-linker may wish to
6956 refer to these sections, but they are not part of the final
6958 { ".got", 4, 0, SHT_PROGBITS
, 0 },
6959 { NULL
, 0, 0, 0, 0 }
6962 static struct bfd_elf_special_section
const
6963 symbian_special_sections_h
[]=
6965 /* In a BPABI executable, the dynamic linking sections do not go in
6966 the loadable read-only segment. The post-linker may wish to
6967 refer to these sections, but they are not part of the final
6969 { ".hash", 5, 0, SHT_HASH
, 0 },
6970 { NULL
, 0, 0, 0, 0 }
6973 static struct bfd_elf_special_section
const
6974 symbian_special_sections_i
[]=
6976 /* These sections do not need to be writable as the SymbianOS
6977 postlinker will arrange things so that no dynamic relocation is
6979 { ".init_array", 11, 0, SHT_INIT_ARRAY
, SHF_ALLOC
},
6980 { NULL
, 0, 0, 0, 0 }
6983 static struct bfd_elf_special_section
const
6984 symbian_special_sections_f
[]=
6986 /* These sections do not need to be writable as the SymbianOS
6987 postlinker will arrange things so that no dynamic relocation is
6989 { ".fini_array", 11, 0, SHT_FINI_ARRAY
, SHF_ALLOC
},
6990 { NULL
, 0, 0, 0, 0 }
6993 static struct bfd_elf_special_section
const
6994 symbian_special_sections_p
[]=
6996 /* These sections do not need to be writable as the SymbianOS
6997 postlinker will arrange things so that no dynamic relocation is
6999 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY
, SHF_ALLOC
},
7000 { NULL
, 0, 0, 0, 0 }
7003 static struct bfd_elf_special_section
const *
7004 elf32_arm_symbian_special_sections
[27]=
7009 symbian_special_sections_d
, /* 'd' */
7011 symbian_special_sections_f
, /* 'f' */
7012 symbian_special_sections_g
, /* 'g' */
7013 symbian_special_sections_h
, /* 'h' */
7014 symbian_special_sections_i
, /* 'i' */
7021 symbian_special_sections_p
, /* 'p' */
7036 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
7037 struct bfd_link_info
*link_info
7040 /* BPABI objects are never loaded directly by an OS kernel; they are
7041 processed by a postlinker first, into an OS-specific format. If
7042 the D_PAGED bit is set on the file, BFD will align segments on
7043 page boundaries, so that an OS can directly map the file. With
7044 BPABI objects, that just results in wasted space. In addition,
7045 because we clear the D_PAGED bit, map_sections_to_segments will
7046 recognize that the program headers should not be mapped into any
7047 loadable segment. */
7048 abfd
->flags
&= ~D_PAGED
;
7052 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
7053 struct bfd_link_info
*info
)
7055 struct elf_segment_map
*m
;
7058 /* BPABI shared libraries and executables should have a PT_DYNAMIC
7059 segment. However, because the .dynamic section is not marked
7060 with SEC_LOAD, the generic ELF code will not create such a
7062 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
7065 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
7066 m
->next
= elf_tdata (abfd
)->segment_map
;
7067 elf_tdata (abfd
)->segment_map
= m
;
7070 /* Also call the generic arm routine. */
7071 return elf32_arm_modify_segment_map (abfd
, info
);
7075 #define elf32_bed elf32_arm_symbian_bed
7077 /* The dynamic sections are not allocated on SymbianOS; the postlinker
7078 will process them and then discard them. */
7079 #undef ELF_DYNAMIC_SEC_FLAGS
7080 #define ELF_DYNAMIC_SEC_FLAGS \
7081 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
7083 #undef bfd_elf32_bfd_link_hash_table_create
7084 #define bfd_elf32_bfd_link_hash_table_create \
7085 elf32_arm_symbian_link_hash_table_create
7087 #undef elf_backend_special_sections
7088 #define elf_backend_special_sections elf32_arm_symbian_special_sections
7090 #undef elf_backend_begin_write_processing
7091 #define elf_backend_begin_write_processing \
7092 elf32_arm_symbian_begin_write_processing
7094 #undef elf_backend_modify_segment_map
7095 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
7097 /* There is no .got section for BPABI objects, and hence no header. */
7098 #undef elf_backend_got_header_size
7099 #define elf_backend_got_header_size 0
7101 /* Similarly, there is no .got.plt section. */
7102 #undef elf_backend_want_got_plt
7103 #define elf_backend_want_got_plt 0
7105 #undef elf_backend_may_use_rel_p
7106 #define elf_backend_may_use_rel_p 1
7107 #undef elf_backend_may_use_rela_p
7108 #define elf_backend_may_use_rela_p 0
7109 #undef elf_backend_default_use_rela_p
7110 #define elf_backend_default_use_rela_p 0
7111 #undef elf_backend_rela_normal
7112 #define elf_backend_rela_normal 0
7114 #include "elf32-target.h"