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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
[] =
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 */
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 HOWTO (R_ARM_THM_PC22
, /* type */
199 2, /* size (0 = byte, 1 = short, 2 = long) */
201 TRUE
, /* pc_relative */
203 complain_overflow_signed
,/* complain_on_overflow */
204 bfd_elf_generic_reloc
, /* special_function */
205 "R_ARM_THM_PC22", /* name */
206 FALSE
, /* partial_inplace */
207 0x07ff07ff, /* src_mask */
208 0x07ff07ff, /* dst_mask */
209 TRUE
), /* pcrel_offset */
211 HOWTO (R_ARM_THM_PC8
, /* type */
213 1, /* size (0 = byte, 1 = short, 2 = long) */
215 TRUE
, /* pc_relative */
217 complain_overflow_signed
,/* complain_on_overflow */
218 bfd_elf_generic_reloc
, /* special_function */
219 "R_ARM_THM_PC8", /* name */
220 FALSE
, /* partial_inplace */
221 0x000000ff, /* src_mask */
222 0x000000ff, /* dst_mask */
223 TRUE
), /* pcrel_offset */
225 HOWTO (R_ARM_AMP_VCALL9
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 TRUE
, /* pc_relative */
231 complain_overflow_signed
,/* complain_on_overflow */
232 bfd_elf_generic_reloc
, /* special_function */
233 "R_ARM_AMP_VCALL9", /* name */
234 FALSE
, /* partial_inplace */
235 0x000000ff, /* src_mask */
236 0x000000ff, /* dst_mask */
237 TRUE
), /* pcrel_offset */
239 HOWTO (R_ARM_SWI24
, /* type */
241 0, /* size (0 = byte, 1 = short, 2 = long) */
243 FALSE
, /* pc_relative */
245 complain_overflow_signed
,/* complain_on_overflow */
246 bfd_elf_generic_reloc
, /* special_function */
247 "R_ARM_SWI24", /* name */
248 FALSE
, /* partial_inplace */
249 0x00000000, /* src_mask */
250 0x00000000, /* dst_mask */
251 FALSE
), /* pcrel_offset */
253 HOWTO (R_ARM_THM_SWI8
, /* type */
255 0, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_signed
,/* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_ARM_SWI8", /* name */
262 FALSE
, /* partial_inplace */
263 0x00000000, /* src_mask */
264 0x00000000, /* dst_mask */
265 FALSE
), /* pcrel_offset */
267 /* BLX instruction for the ARM. */
268 HOWTO (R_ARM_XPC25
, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
272 TRUE
, /* pc_relative */
274 complain_overflow_signed
,/* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* special_function */
276 "R_ARM_XPC25", /* name */
277 FALSE
, /* partial_inplace */
278 0x00ffffff, /* src_mask */
279 0x00ffffff, /* dst_mask */
280 TRUE
), /* pcrel_offset */
282 /* BLX instruction for the Thumb. */
283 HOWTO (R_ARM_THM_XPC22
, /* type */
285 2, /* size (0 = byte, 1 = short, 2 = long) */
287 TRUE
, /* pc_relative */
289 complain_overflow_signed
,/* complain_on_overflow */
290 bfd_elf_generic_reloc
, /* special_function */
291 "R_ARM_THM_XPC22", /* name */
292 FALSE
, /* partial_inplace */
293 0x07ff07ff, /* src_mask */
294 0x07ff07ff, /* dst_mask */
295 TRUE
), /* pcrel_offset */
297 /* These next three relocs are not defined, but we need to fill the space. */
299 HOWTO (R_ARM_NONE
, /* type */
301 0, /* size (0 = byte, 1 = short, 2 = long) */
303 FALSE
, /* pc_relative */
305 complain_overflow_dont
,/* complain_on_overflow */
306 bfd_elf_generic_reloc
, /* special_function */
307 "R_ARM_unknown_17", /* name */
308 FALSE
, /* partial_inplace */
311 FALSE
), /* pcrel_offset */
313 HOWTO (R_ARM_NONE
, /* type */
315 0, /* size (0 = byte, 1 = short, 2 = long) */
317 FALSE
, /* pc_relative */
319 complain_overflow_dont
,/* complain_on_overflow */
320 bfd_elf_generic_reloc
, /* special_function */
321 "R_ARM_unknown_18", /* name */
322 FALSE
, /* partial_inplace */
325 FALSE
), /* pcrel_offset */
327 HOWTO (R_ARM_NONE
, /* type */
329 0, /* size (0 = byte, 1 = short, 2 = long) */
331 FALSE
, /* pc_relative */
333 complain_overflow_dont
,/* complain_on_overflow */
334 bfd_elf_generic_reloc
, /* special_function */
335 "R_ARM_unknown_19", /* name */
336 FALSE
, /* partial_inplace */
339 FALSE
), /* pcrel_offset */
341 /* Relocs used in ARM Linux */
343 HOWTO (R_ARM_COPY
, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 FALSE
, /* pc_relative */
349 complain_overflow_bitfield
,/* complain_on_overflow */
350 bfd_elf_generic_reloc
, /* special_function */
351 "R_ARM_COPY", /* name */
352 TRUE
, /* partial_inplace */
353 0xffffffff, /* src_mask */
354 0xffffffff, /* dst_mask */
355 FALSE
), /* pcrel_offset */
357 HOWTO (R_ARM_GLOB_DAT
, /* type */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE
, /* pc_relative */
363 complain_overflow_bitfield
,/* complain_on_overflow */
364 bfd_elf_generic_reloc
, /* special_function */
365 "R_ARM_GLOB_DAT", /* name */
366 TRUE
, /* partial_inplace */
367 0xffffffff, /* src_mask */
368 0xffffffff, /* dst_mask */
369 FALSE
), /* pcrel_offset */
371 HOWTO (R_ARM_JUMP_SLOT
, /* type */
373 2, /* size (0 = byte, 1 = short, 2 = long) */
375 FALSE
, /* pc_relative */
377 complain_overflow_bitfield
,/* complain_on_overflow */
378 bfd_elf_generic_reloc
, /* special_function */
379 "R_ARM_JUMP_SLOT", /* name */
380 TRUE
, /* partial_inplace */
381 0xffffffff, /* src_mask */
382 0xffffffff, /* dst_mask */
383 FALSE
), /* pcrel_offset */
385 HOWTO (R_ARM_RELATIVE
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_bitfield
,/* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_ARM_RELATIVE", /* name */
394 TRUE
, /* partial_inplace */
395 0xffffffff, /* src_mask */
396 0xffffffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 HOWTO (R_ARM_GOTOFF
, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 FALSE
, /* pc_relative */
405 complain_overflow_bitfield
,/* complain_on_overflow */
406 bfd_elf_generic_reloc
, /* special_function */
407 "R_ARM_GOTOFF", /* name */
408 TRUE
, /* partial_inplace */
409 0xffffffff, /* src_mask */
410 0xffffffff, /* dst_mask */
411 FALSE
), /* pcrel_offset */
413 HOWTO (R_ARM_GOTPC
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 TRUE
, /* pc_relative */
419 complain_overflow_bitfield
,/* complain_on_overflow */
420 bfd_elf_generic_reloc
, /* special_function */
421 "R_ARM_GOTPC", /* name */
422 TRUE
, /* partial_inplace */
423 0xffffffff, /* src_mask */
424 0xffffffff, /* dst_mask */
425 TRUE
), /* pcrel_offset */
427 HOWTO (R_ARM_GOT32
, /* type */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 FALSE
, /* pc_relative */
433 complain_overflow_bitfield
,/* complain_on_overflow */
434 bfd_elf_generic_reloc
, /* special_function */
435 "R_ARM_GOT32", /* name */
436 TRUE
, /* partial_inplace */
437 0xffffffff, /* src_mask */
438 0xffffffff, /* dst_mask */
439 FALSE
), /* pcrel_offset */
441 HOWTO (R_ARM_PLT32
, /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 TRUE
, /* pc_relative */
447 complain_overflow_bitfield
,/* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_ARM_PLT32", /* name */
450 TRUE
, /* partial_inplace */
451 0x00ffffff, /* src_mask */
452 0x00ffffff, /* dst_mask */
453 TRUE
), /* pcrel_offset */
455 HOWTO (R_ARM_CALL
, /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 TRUE
, /* pc_relative */
461 complain_overflow_signed
,/* complain_on_overflow */
462 bfd_elf_generic_reloc
, /* special_function */
463 "R_ARM_CALL", /* name */
464 FALSE
, /* partial_inplace */
465 0x00ffffff, /* src_mask */
466 0x00ffffff, /* dst_mask */
467 TRUE
), /* pcrel_offset */
469 HOWTO (R_ARM_JUMP24
, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 TRUE
, /* pc_relative */
475 complain_overflow_signed
,/* complain_on_overflow */
476 bfd_elf_generic_reloc
, /* special_function */
477 "R_ARM_JUMP24", /* name */
478 FALSE
, /* partial_inplace */
479 0x00ffffff, /* src_mask */
480 0x00ffffff, /* dst_mask */
481 TRUE
), /* pcrel_offset */
483 HOWTO (R_ARM_NONE
, /* type */
485 0, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_dont
,/* complain_on_overflow */
490 bfd_elf_generic_reloc
, /* special_function */
491 "R_ARM_unknown_30", /* name */
492 FALSE
, /* partial_inplace */
495 FALSE
), /* pcrel_offset */
497 HOWTO (R_ARM_NONE
, /* type */
499 0, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_dont
,/* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_ARM_unknown_31", /* name */
506 FALSE
, /* partial_inplace */
509 FALSE
), /* pcrel_offset */
511 HOWTO (R_ARM_ALU_PCREL7_0
, /* type */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
515 TRUE
, /* pc_relative */
517 complain_overflow_dont
,/* complain_on_overflow */
518 bfd_elf_generic_reloc
, /* special_function */
519 "R_ARM_ALU_PCREL_7_0", /* name */
520 FALSE
, /* partial_inplace */
521 0x00000fff, /* src_mask */
522 0x00000fff, /* dst_mask */
523 TRUE
), /* pcrel_offset */
525 HOWTO (R_ARM_ALU_PCREL15_8
, /* type */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
529 TRUE
, /* pc_relative */
531 complain_overflow_dont
,/* complain_on_overflow */
532 bfd_elf_generic_reloc
, /* special_function */
533 "R_ARM_ALU_PCREL_15_8",/* name */
534 FALSE
, /* partial_inplace */
535 0x00000fff, /* src_mask */
536 0x00000fff, /* dst_mask */
537 TRUE
), /* pcrel_offset */
539 HOWTO (R_ARM_ALU_PCREL23_15
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 TRUE
, /* pc_relative */
545 complain_overflow_dont
,/* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_ARM_ALU_PCREL_23_15",/* name */
548 FALSE
, /* partial_inplace */
549 0x00000fff, /* src_mask */
550 0x00000fff, /* dst_mask */
551 TRUE
), /* pcrel_offset */
553 HOWTO (R_ARM_LDR_SBREL_11_0
, /* type */
555 2, /* size (0 = byte, 1 = short, 2 = long) */
557 FALSE
, /* pc_relative */
559 complain_overflow_dont
,/* complain_on_overflow */
560 bfd_elf_generic_reloc
, /* special_function */
561 "R_ARM_LDR_SBREL_11_0",/* name */
562 FALSE
, /* partial_inplace */
563 0x00000fff, /* src_mask */
564 0x00000fff, /* dst_mask */
565 FALSE
), /* pcrel_offset */
567 HOWTO (R_ARM_ALU_SBREL_19_12
, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 FALSE
, /* pc_relative */
573 complain_overflow_dont
,/* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_ARM_ALU_SBREL_19_12",/* name */
576 FALSE
, /* partial_inplace */
577 0x000ff000, /* src_mask */
578 0x000ff000, /* dst_mask */
579 FALSE
), /* pcrel_offset */
581 HOWTO (R_ARM_ALU_SBREL_27_20
, /* type */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
585 FALSE
, /* pc_relative */
587 complain_overflow_dont
,/* complain_on_overflow */
588 bfd_elf_generic_reloc
, /* special_function */
589 "R_ARM_ALU_SBREL_27_20",/* name */
590 FALSE
, /* partial_inplace */
591 0x0ff00000, /* src_mask */
592 0x0ff00000, /* dst_mask */
593 FALSE
), /* pcrel_offset */
595 HOWTO (R_ARM_TARGET1
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 FALSE
, /* pc_relative */
601 complain_overflow_dont
,/* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_ARM_TARGET1", /* name */
604 FALSE
, /* partial_inplace */
605 0xffffffff, /* src_mask */
606 0xffffffff, /* dst_mask */
607 FALSE
), /* pcrel_offset */
609 HOWTO (R_ARM_ROSEGREL32
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE
, /* pc_relative */
615 complain_overflow_dont
,/* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_ARM_ROSEGREL32", /* name */
618 FALSE
, /* partial_inplace */
619 0xffffffff, /* src_mask */
620 0xffffffff, /* dst_mask */
621 FALSE
), /* pcrel_offset */
623 HOWTO (R_ARM_V4BX
, /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 FALSE
, /* pc_relative */
629 complain_overflow_dont
,/* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_ARM_V4BX", /* name */
632 FALSE
, /* partial_inplace */
633 0xffffffff, /* src_mask */
634 0xffffffff, /* dst_mask */
635 FALSE
), /* pcrel_offset */
637 HOWTO (R_ARM_TARGET2
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE
, /* pc_relative */
643 complain_overflow_signed
,/* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_ARM_TARGET2", /* name */
646 FALSE
, /* partial_inplace */
647 0xffffffff, /* src_mask */
648 0xffffffff, /* dst_mask */
649 TRUE
), /* pcrel_offset */
651 HOWTO (R_ARM_PREL31
, /* type */
653 2, /* size (0 = byte, 1 = short, 2 = long) */
655 TRUE
, /* pc_relative */
657 complain_overflow_signed
,/* complain_on_overflow */
658 bfd_elf_generic_reloc
, /* special_function */
659 "R_ARM_PREL31", /* name */
660 FALSE
, /* partial_inplace */
661 0x7fffffff, /* src_mask */
662 0x7fffffff, /* dst_mask */
663 TRUE
), /* pcrel_offset */
666 /* GNU extension to record C++ vtable hierarchy */
667 static reloc_howto_type elf32_arm_vtinherit_howto
=
668 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_dont
, /* complain_on_overflow */
675 NULL
, /* special_function */
676 "R_ARM_GNU_VTINHERIT", /* name */
677 FALSE
, /* partial_inplace */
680 FALSE
); /* pcrel_offset */
682 /* GNU extension to record C++ vtable member usage */
683 static reloc_howto_type elf32_arm_vtentry_howto
=
684 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE
, /* pc_relative */
690 complain_overflow_dont
, /* complain_on_overflow */
691 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
692 "R_ARM_GNU_VTENTRY", /* name */
693 FALSE
, /* partial_inplace */
696 FALSE
); /* pcrel_offset */
698 /* 12 bit pc relative */
699 static reloc_howto_type elf32_arm_thm_pc11_howto
=
700 HOWTO (R_ARM_THM_PC11
, /* type */
702 1, /* size (0 = byte, 1 = short, 2 = long) */
704 TRUE
, /* pc_relative */
706 complain_overflow_signed
, /* complain_on_overflow */
707 bfd_elf_generic_reloc
, /* special_function */
708 "R_ARM_THM_PC11", /* name */
709 FALSE
, /* partial_inplace */
710 0x000007ff, /* src_mask */
711 0x000007ff, /* dst_mask */
712 TRUE
); /* pcrel_offset */
714 /* 12 bit pc relative */
715 static reloc_howto_type elf32_arm_thm_pc9_howto
=
716 HOWTO (R_ARM_THM_PC9
, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 TRUE
, /* pc_relative */
722 complain_overflow_signed
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 "R_ARM_THM_PC9", /* name */
725 FALSE
, /* partial_inplace */
726 0x000000ff, /* src_mask */
727 0x000000ff, /* dst_mask */
728 TRUE
); /* pcrel_offset */
730 /* Place relative GOT-indirect. */
731 static reloc_howto_type elf32_arm_got_prel
=
732 HOWTO (R_ARM_GOT_PREL
, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 TRUE
, /* pc_relative */
738 complain_overflow_dont
, /* complain_on_overflow */
739 bfd_elf_generic_reloc
, /* special_function */
740 "R_ARM_GOT_PREL", /* name */
741 FALSE
, /* partial_inplace */
742 0xffffffff, /* src_mask */
743 0xffffffff, /* dst_mask */
744 TRUE
); /* pcrel_offset */
746 /* Currently unused relocations. */
747 static reloc_howto_type elf32_arm_r_howto
[4] =
749 HOWTO (R_ARM_RREL32
, /* type */
751 0, /* size (0 = byte, 1 = short, 2 = long) */
753 FALSE
, /* pc_relative */
755 complain_overflow_dont
,/* complain_on_overflow */
756 bfd_elf_generic_reloc
, /* special_function */
757 "R_ARM_RREL32", /* name */
758 FALSE
, /* partial_inplace */
761 FALSE
), /* pcrel_offset */
763 HOWTO (R_ARM_RABS32
, /* type */
765 0, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE
, /* pc_relative */
769 complain_overflow_dont
,/* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_ARM_RABS32", /* name */
772 FALSE
, /* partial_inplace */
775 FALSE
), /* pcrel_offset */
777 HOWTO (R_ARM_RPC24
, /* type */
779 0, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE
, /* pc_relative */
783 complain_overflow_dont
,/* complain_on_overflow */
784 bfd_elf_generic_reloc
, /* special_function */
785 "R_ARM_RPC24", /* name */
786 FALSE
, /* partial_inplace */
789 FALSE
), /* pcrel_offset */
791 HOWTO (R_ARM_RBASE
, /* type */
793 0, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_dont
,/* complain_on_overflow */
798 bfd_elf_generic_reloc
, /* special_function */
799 "R_ARM_RBASE", /* name */
800 FALSE
, /* partial_inplace */
803 FALSE
) /* pcrel_offset */
806 static reloc_howto_type
*
807 elf32_arm_howto_from_type (unsigned int r_type
)
809 if (r_type
< NUM_ELEM (elf32_arm_howto_table
))
810 return &elf32_arm_howto_table
[r_type
];
815 return &elf32_arm_got_prel
;
817 case R_ARM_GNU_VTINHERIT
:
818 return &elf32_arm_vtinherit_howto
;
820 case R_ARM_GNU_VTENTRY
:
821 return &elf32_arm_vtentry_howto
;
824 return &elf32_arm_thm_pc11_howto
;
827 return &elf32_arm_thm_pc9_howto
;
833 return &elf32_arm_r_howto
[r_type
- R_ARM_RREL32
];
841 elf32_arm_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
, arelent
* bfd_reloc
,
842 Elf_Internal_Rela
* elf_reloc
)
846 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
847 bfd_reloc
->howto
= elf32_arm_howto_from_type (r_type
);
850 struct elf32_arm_reloc_map
852 bfd_reloc_code_real_type bfd_reloc_val
;
853 unsigned char elf_reloc_val
;
856 /* All entries in this list must also be present in elf32_arm_howto_table. */
857 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
859 {BFD_RELOC_NONE
, R_ARM_NONE
},
860 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
861 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
862 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
863 {BFD_RELOC_32
, R_ARM_ABS32
},
864 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
865 {BFD_RELOC_8
, R_ARM_ABS8
},
866 {BFD_RELOC_16
, R_ARM_ABS16
},
867 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
868 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
869 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_PC22
},
870 {BFD_RELOC_ARM_COPY
, R_ARM_COPY
},
871 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
872 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
873 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
874 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF
},
875 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
876 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
877 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
},
878 {BFD_RELOC_ARM_TARGET1
, R_ARM_TARGET1
},
879 {BFD_RELOC_ARM_ROSEGREL32
, R_ARM_ROSEGREL32
},
880 {BFD_RELOC_ARM_SBREL32
, R_ARM_SBREL32
},
881 {BFD_RELOC_ARM_PREL31
, R_ARM_PREL31
},
882 {BFD_RELOC_ARM_TARGET2
, R_ARM_TARGET2
}
885 static reloc_howto_type
*
886 elf32_arm_reloc_type_lookup (abfd
, code
)
887 bfd
*abfd ATTRIBUTE_UNUSED
;
888 bfd_reloc_code_real_type code
;
894 case BFD_RELOC_VTABLE_INHERIT
:
895 return & elf32_arm_vtinherit_howto
;
897 case BFD_RELOC_VTABLE_ENTRY
:
898 return & elf32_arm_vtentry_howto
;
900 case BFD_RELOC_THUMB_PCREL_BRANCH12
:
901 return & elf32_arm_thm_pc11_howto
;
903 case BFD_RELOC_THUMB_PCREL_BRANCH9
:
904 return & elf32_arm_thm_pc9_howto
;
907 for (i
= 0; i
< NUM_ELEM (elf32_arm_reloc_map
); i
++)
908 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
909 return & elf32_arm_howto_table
[elf32_arm_reloc_map
[i
].elf_reloc_val
];
915 /* Support for core dump NOTE sections */
917 elf32_arm_nabi_grok_prstatus (abfd
, note
)
919 Elf_Internal_Note
*note
;
924 switch (note
->descsz
)
929 case 148: /* Linux/ARM 32-bit*/
931 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
934 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
943 /* Make a ".reg/999" section. */
944 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
945 size
, note
->descpos
+ offset
);
949 elf32_arm_nabi_grok_psinfo (abfd
, note
)
951 Elf_Internal_Note
*note
;
953 switch (note
->descsz
)
958 case 124: /* Linux/ARM elf_prpsinfo */
959 elf_tdata (abfd
)->core_program
960 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
961 elf_tdata (abfd
)->core_command
962 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
965 /* Note that for some reason, a spurious space is tacked
966 onto the end of the args in some (at least one anyway)
967 implementations, so strip it off if it exists. */
970 char *command
= elf_tdata (abfd
)->core_command
;
971 int n
= strlen (command
);
973 if (0 < n
&& command
[n
- 1] == ' ')
974 command
[n
- 1] = '\0';
980 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
981 #define TARGET_LITTLE_NAME "elf32-littlearm"
982 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
983 #define TARGET_BIG_NAME "elf32-bigarm"
985 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
986 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
988 typedef unsigned long int insn32
;
989 typedef unsigned short int insn16
;
991 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
992 #define INTERWORK_FLAG(abfd) \
993 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
994 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
996 /* The linker script knows the section names for placement.
997 The entry_names are used to do simple name mangling on the stubs.
998 Given a function name, and its type, the stub can be found. The
999 name can be changed. The only requirement is the %s be present. */
1000 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1001 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1003 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1004 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1006 /* The name of the dynamic interpreter. This is put in the .interp
1008 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1010 #ifdef FOUR_WORD_PLT
1012 /* The first entry in a procedure linkage table looks like
1013 this. It is set up so that any shared library function that is
1014 called before the relocation has been set up calls the dynamic
1016 static const bfd_vma elf32_arm_plt0_entry
[] =
1018 0xe52de004, /* str lr, [sp, #-4]! */
1019 0xe59fe010, /* ldr lr, [pc, #16] */
1020 0xe08fe00e, /* add lr, pc, lr */
1021 0xe5bef008, /* ldr pc, [lr, #8]! */
1024 /* Subsequent entries in a procedure linkage table look like
1026 static const bfd_vma elf32_arm_plt_entry
[] =
1028 0xe28fc600, /* add ip, pc, #NN */
1029 0xe28cca00, /* add ip, ip, #NN */
1030 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1031 0x00000000, /* unused */
1036 /* The first entry in a procedure linkage table looks like
1037 this. It is set up so that any shared library function that is
1038 called before the relocation has been set up calls the dynamic
1040 static const bfd_vma elf32_arm_plt0_entry
[] =
1042 0xe52de004, /* str lr, [sp, #-4]! */
1043 0xe59fe004, /* ldr lr, [pc, #4] */
1044 0xe08fe00e, /* add lr, pc, lr */
1045 0xe5bef008, /* ldr pc, [lr, #8]! */
1046 0x00000000, /* &GOT[0] - . */
1049 /* Subsequent entries in a procedure linkage table look like
1051 static const bfd_vma elf32_arm_plt_entry
[] =
1053 0xe28fc600, /* add ip, pc, #0xNN00000 */
1054 0xe28cca00, /* add ip, ip, #0xNN000 */
1055 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1060 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1061 #define PLT_THUMB_STUB_SIZE 4
1062 static const bfd_vma elf32_arm_plt_thumb_stub
[] =
1068 /* The entries in a PLT when using a DLL-based target with multiple
1070 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
1072 0xe51ff004, /* ldr pc, [pc, #-4] */
1073 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1076 /* Used to build a map of a section. This is required for mixed-endian
1079 typedef struct elf32_elf_section_map
1084 elf32_arm_section_map
;
1086 struct _arm_elf_section_data
1088 struct bfd_elf_section_data elf
;
1090 elf32_arm_section_map
*map
;
1093 #define elf32_arm_section_data(sec) \
1094 ((struct _arm_elf_section_data *) elf_section_data (sec))
1096 /* The ARM linker needs to keep track of the number of relocs that it
1097 decides to copy in check_relocs for each symbol. This is so that
1098 it can discard PC relative relocs if it doesn't need them when
1099 linking with -Bsymbolic. We store the information in a field
1100 extending the regular ELF linker hash table. */
1102 /* This structure keeps track of the number of PC relative relocs we
1103 have copied for a given symbol. */
1104 struct elf32_arm_relocs_copied
1107 struct elf32_arm_relocs_copied
* next
;
1108 /* A section in dynobj. */
1110 /* Number of relocs copied in this section. */
1111 bfd_size_type count
;
1114 /* Arm ELF linker hash entry. */
1115 struct elf32_arm_link_hash_entry
1117 struct elf_link_hash_entry root
;
1119 /* Number of PC relative relocs copied for this symbol. */
1120 struct elf32_arm_relocs_copied
* relocs_copied
;
1122 /* We reference count Thumb references to a PLT entry separately,
1123 so that we can emit the Thumb trampoline only if needed. */
1124 bfd_signed_vma plt_thumb_refcount
;
1126 /* Since PLT entries have variable size if the Thumb prologue is
1127 used, we need to record the index into .got.plt instead of
1128 recomputing it from the PLT offset. */
1129 bfd_signed_vma plt_got_offset
;
1132 /* Traverse an arm ELF linker hash table. */
1133 #define elf32_arm_link_hash_traverse(table, func, info) \
1134 (elf_link_hash_traverse \
1136 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1139 /* Get the ARM elf linker hash table from a link_info structure. */
1140 #define elf32_arm_hash_table(info) \
1141 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1143 /* ARM ELF linker hash table. */
1144 struct elf32_arm_link_hash_table
1146 /* The main hash table. */
1147 struct elf_link_hash_table root
;
1149 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1150 bfd_size_type thumb_glue_size
;
1152 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1153 bfd_size_type arm_glue_size
;
1155 /* An arbitrary input BFD chosen to hold the glue sections. */
1156 bfd
* bfd_of_glue_owner
;
1158 /* Nonzero to output a BE8 image. */
1161 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1162 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1165 /* The relocation to use for R_ARM_TARGET2 relocations. */
1168 /* Nonzero to fix BX instructions for ARMv4 targets. */
1171 /* The number of bytes in the initial entry in the PLT. */
1172 bfd_size_type plt_header_size
;
1174 /* The number of bytes in the subsequent PLT etries. */
1175 bfd_size_type plt_entry_size
;
1177 /* True if the target system is Symbian OS. */
1180 /* True if the target uses REL relocations. */
1183 /* Short-cuts to get to dynamic linker sections. */
1192 /* Small local sym to section mapping cache. */
1193 struct sym_sec_cache sym_sec
;
1195 /* For convenience in allocate_dynrelocs. */
1199 /* Create an entry in an ARM ELF linker hash table. */
1201 static struct bfd_hash_entry
*
1202 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
1203 struct bfd_hash_table
* table
,
1204 const char * string
)
1206 struct elf32_arm_link_hash_entry
* ret
=
1207 (struct elf32_arm_link_hash_entry
*) entry
;
1209 /* Allocate the structure if it has not already been allocated by a
1211 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
1212 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
1214 return (struct bfd_hash_entry
*) ret
;
1216 /* Call the allocation method of the superclass. */
1217 ret
= ((struct elf32_arm_link_hash_entry
*)
1218 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1222 ret
->relocs_copied
= NULL
;
1223 ret
->plt_thumb_refcount
= 0;
1224 ret
->plt_got_offset
= -1;
1227 return (struct bfd_hash_entry
*) ret
;
1230 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1231 shortcuts to them in our hash table. */
1234 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
1236 struct elf32_arm_link_hash_table
*htab
;
1238 htab
= elf32_arm_hash_table (info
);
1239 /* BPABI objects never have a GOT, or associated sections. */
1240 if (htab
->symbian_p
)
1243 if (! _bfd_elf_create_got_section (dynobj
, info
))
1246 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1247 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1248 if (!htab
->sgot
|| !htab
->sgotplt
)
1251 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
1252 if (htab
->srelgot
== NULL
1253 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
1254 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1255 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
1257 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
1262 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1263 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1267 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
1269 struct elf32_arm_link_hash_table
*htab
;
1271 htab
= elf32_arm_hash_table (info
);
1272 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
1275 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1278 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
1279 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
1280 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1282 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
1287 || (!info
->shared
&& !htab
->srelbss
))
1293 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1296 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
1297 struct elf_link_hash_entry
*dir
,
1298 struct elf_link_hash_entry
*ind
)
1300 struct elf32_arm_link_hash_entry
*edir
, *eind
;
1302 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
1303 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
1305 if (eind
->relocs_copied
!= NULL
)
1307 if (edir
->relocs_copied
!= NULL
)
1309 struct elf32_arm_relocs_copied
**pp
;
1310 struct elf32_arm_relocs_copied
*p
;
1312 if (ind
->root
.type
== bfd_link_hash_indirect
)
1315 /* Add reloc counts against the weak sym to the strong sym
1316 list. Merge any entries against the same section. */
1317 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
1319 struct elf32_arm_relocs_copied
*q
;
1321 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
1322 if (q
->section
== p
->section
)
1324 q
->count
+= p
->count
;
1331 *pp
= edir
->relocs_copied
;
1334 edir
->relocs_copied
= eind
->relocs_copied
;
1335 eind
->relocs_copied
= NULL
;
1338 /* If the direct symbol already has an associated PLT entry, the
1339 indirect symbol should not. If it doesn't, swap refcount information
1340 from the indirect symbol. */
1341 if (edir
->plt_thumb_refcount
== 0)
1343 edir
->plt_thumb_refcount
= eind
->plt_thumb_refcount
;
1344 eind
->plt_thumb_refcount
= 0;
1347 BFD_ASSERT (eind
->plt_thumb_refcount
== 0);
1349 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
1352 /* Create an ARM elf linker hash table. */
1354 static struct bfd_link_hash_table
*
1355 elf32_arm_link_hash_table_create (bfd
*abfd
)
1357 struct elf32_arm_link_hash_table
*ret
;
1358 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
1360 ret
= bfd_malloc (amt
);
1364 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
1365 elf32_arm_link_hash_newfunc
))
1372 ret
->sgotplt
= NULL
;
1373 ret
->srelgot
= NULL
;
1375 ret
->srelplt
= NULL
;
1376 ret
->sdynbss
= NULL
;
1377 ret
->srelbss
= NULL
;
1378 ret
->thumb_glue_size
= 0;
1379 ret
->arm_glue_size
= 0;
1380 ret
->bfd_of_glue_owner
= NULL
;
1381 ret
->byteswap_code
= 0;
1382 ret
->target1_is_rel
= 0;
1383 ret
->target2_reloc
= R_ARM_NONE
;
1384 #ifdef FOUR_WORD_PLT
1385 ret
->plt_header_size
= 16;
1386 ret
->plt_entry_size
= 16;
1388 ret
->plt_header_size
= 20;
1389 ret
->plt_entry_size
= 12;
1393 ret
->sym_sec
.abfd
= NULL
;
1396 return &ret
->root
.root
;
1399 /* Locate the Thumb encoded calling stub for NAME. */
1401 static struct elf_link_hash_entry
*
1402 find_thumb_glue (struct bfd_link_info
*link_info
,
1407 struct elf_link_hash_entry
*hash
;
1408 struct elf32_arm_link_hash_table
*hash_table
;
1410 /* We need a pointer to the armelf specific hash table. */
1411 hash_table
= elf32_arm_hash_table (link_info
);
1413 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1414 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
1416 BFD_ASSERT (tmp_name
);
1418 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
1420 hash
= elf_link_hash_lookup
1421 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1424 /* xgettext:c-format */
1425 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1426 input_bfd
, tmp_name
, name
);
1433 /* Locate the ARM encoded calling stub for NAME. */
1435 static struct elf_link_hash_entry
*
1436 find_arm_glue (struct bfd_link_info
*link_info
,
1441 struct elf_link_hash_entry
*myh
;
1442 struct elf32_arm_link_hash_table
*hash_table
;
1444 /* We need a pointer to the elfarm specific hash table. */
1445 hash_table
= elf32_arm_hash_table (link_info
);
1447 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1448 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
1450 BFD_ASSERT (tmp_name
);
1452 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
1454 myh
= elf_link_hash_lookup
1455 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1458 /* xgettext:c-format */
1459 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
1460 input_bfd
, tmp_name
, name
);
1471 ldr r12, __func_addr
1474 .word func @ behave as if you saw a ARM_32 reloc. */
1476 #define ARM2THUMB_GLUE_SIZE 12
1477 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
1478 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
1479 static const insn32 a2t3_func_addr_insn
= 0x00000001;
1481 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
1485 __func_from_thumb: __func_from_thumb:
1487 nop ldr r6, __func_addr
1489 __func_change_to_arm: bx r6
1491 __func_back_to_thumb:
1497 #define THUMB2ARM_GLUE_SIZE 8
1498 static const insn16 t2a1_bx_pc_insn
= 0x4778;
1499 static const insn16 t2a2_noop_insn
= 0x46c0;
1500 static const insn32 t2a3_b_insn
= 0xea000000;
1502 #ifndef ELFARM_NABI_C_INCLUDED
1504 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
1508 struct elf32_arm_link_hash_table
* globals
;
1510 globals
= elf32_arm_hash_table (info
);
1512 BFD_ASSERT (globals
!= NULL
);
1514 if (globals
->arm_glue_size
!= 0)
1516 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1518 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1519 ARM2THUMB_GLUE_SECTION_NAME
);
1521 BFD_ASSERT (s
!= NULL
);
1523 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
1525 s
->size
= globals
->arm_glue_size
;
1529 if (globals
->thumb_glue_size
!= 0)
1531 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1533 s
= bfd_get_section_by_name
1534 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1536 BFD_ASSERT (s
!= NULL
);
1538 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
1540 s
->size
= globals
->thumb_glue_size
;
1548 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
1549 struct elf_link_hash_entry
* h
)
1551 const char * name
= h
->root
.root
.string
;
1554 struct elf_link_hash_entry
* myh
;
1555 struct bfd_link_hash_entry
* bh
;
1556 struct elf32_arm_link_hash_table
* globals
;
1559 globals
= elf32_arm_hash_table (link_info
);
1561 BFD_ASSERT (globals
!= NULL
);
1562 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1564 s
= bfd_get_section_by_name
1565 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
1567 BFD_ASSERT (s
!= NULL
);
1569 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
1571 BFD_ASSERT (tmp_name
);
1573 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
1575 myh
= elf_link_hash_lookup
1576 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1580 /* We've already seen this guy. */
1585 /* The only trick here is using hash_table->arm_glue_size as the value.
1586 Even though the section isn't allocated yet, this is where we will be
1589 val
= globals
->arm_glue_size
+ 1;
1590 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
1591 tmp_name
, BSF_GLOBAL
, s
, val
,
1592 NULL
, TRUE
, FALSE
, &bh
);
1594 myh
= (struct elf_link_hash_entry
*) bh
;
1595 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1596 myh
->forced_local
= 1;
1600 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
1606 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
1607 struct elf_link_hash_entry
*h
)
1609 const char *name
= h
->root
.root
.string
;
1612 struct elf_link_hash_entry
*myh
;
1613 struct bfd_link_hash_entry
*bh
;
1614 struct elf32_arm_link_hash_table
*hash_table
;
1617 hash_table
= elf32_arm_hash_table (link_info
);
1619 BFD_ASSERT (hash_table
!= NULL
);
1620 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
1622 s
= bfd_get_section_by_name
1623 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1625 BFD_ASSERT (s
!= NULL
);
1627 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1628 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
1630 BFD_ASSERT (tmp_name
);
1632 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
1634 myh
= elf_link_hash_lookup
1635 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
1639 /* We've already seen this guy. */
1645 val
= hash_table
->thumb_glue_size
+ 1;
1646 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
1647 tmp_name
, BSF_GLOBAL
, s
, val
,
1648 NULL
, TRUE
, FALSE
, &bh
);
1650 /* If we mark it 'Thumb', the disassembler will do a better job. */
1651 myh
= (struct elf_link_hash_entry
*) bh
;
1652 myh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_ARM_TFUNC
);
1653 myh
->forced_local
= 1;
1657 #define CHANGE_TO_ARM "__%s_change_to_arm"
1658 #define BACK_FROM_ARM "__%s_back_from_arm"
1660 /* Allocate another symbol to mark where we switch to Arm mode. */
1661 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
1662 + strlen (CHANGE_TO_ARM
) + 1);
1664 BFD_ASSERT (tmp_name
);
1666 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
1669 val
= hash_table
->thumb_glue_size
+ 4,
1670 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
1671 tmp_name
, BSF_LOCAL
, s
, val
,
1672 NULL
, TRUE
, FALSE
, &bh
);
1676 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
1681 /* Add the glue sections to ABFD. This function is called from the
1682 linker scripts in ld/emultempl/{armelf}.em. */
1685 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
1686 struct bfd_link_info
*info
)
1691 /* If we are only performing a partial
1692 link do not bother adding the glue. */
1693 if (info
->relocatable
)
1696 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
1700 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
1701 will prevent elf_link_input_bfd() from processing the contents
1703 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
1705 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
1708 || !bfd_set_section_flags (abfd
, sec
, flags
)
1709 || !bfd_set_section_alignment (abfd
, sec
, 2))
1712 /* Set the gc mark to prevent the section from being removed by garbage
1713 collection, despite the fact that no relocs refer to this section. */
1717 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
1721 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1722 | SEC_CODE
| SEC_READONLY
;
1724 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
1727 || !bfd_set_section_flags (abfd
, sec
, flags
)
1728 || !bfd_set_section_alignment (abfd
, sec
, 2))
1737 /* Select a BFD to be used to hold the sections used by the glue code.
1738 This function is called from the linker scripts in ld/emultempl/
1742 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
1744 struct elf32_arm_link_hash_table
*globals
;
1746 /* If we are only performing a partial link
1747 do not bother getting a bfd to hold the glue. */
1748 if (info
->relocatable
)
1751 /* Make sure we don't attach the glue sections to a dynamic object. */
1752 BFD_ASSERT (!(abfd
->flags
& DYNAMIC
));
1754 globals
= elf32_arm_hash_table (info
);
1756 BFD_ASSERT (globals
!= NULL
);
1758 if (globals
->bfd_of_glue_owner
!= NULL
)
1761 /* Save the bfd for later use. */
1762 globals
->bfd_of_glue_owner
= abfd
;
1768 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
1769 struct bfd_link_info
*link_info
,
1772 Elf_Internal_Shdr
*symtab_hdr
;
1773 Elf_Internal_Rela
*internal_relocs
= NULL
;
1774 Elf_Internal_Rela
*irel
, *irelend
;
1775 bfd_byte
*contents
= NULL
;
1778 struct elf32_arm_link_hash_table
*globals
;
1780 /* If we are only performing a partial link do not bother
1781 to construct any glue. */
1782 if (link_info
->relocatable
)
1785 /* Here we have a bfd that is to be included on the link. We have a hook
1786 to do reloc rummaging, before section sizes are nailed down. */
1787 globals
= elf32_arm_hash_table (link_info
);
1789 BFD_ASSERT (globals
!= NULL
);
1790 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1792 if (byteswap_code
&& !bfd_big_endian (abfd
))
1794 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
1798 globals
->byteswap_code
= byteswap_code
;
1800 /* Rummage around all the relocs and map the glue vectors. */
1801 sec
= abfd
->sections
;
1806 for (; sec
!= NULL
; sec
= sec
->next
)
1808 if (sec
->reloc_count
== 0)
1811 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1813 /* Load the relocs. */
1815 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
1816 (Elf_Internal_Rela
*) NULL
, FALSE
);
1818 if (internal_relocs
== NULL
)
1821 irelend
= internal_relocs
+ sec
->reloc_count
;
1822 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1825 unsigned long r_index
;
1827 struct elf_link_hash_entry
*h
;
1829 r_type
= ELF32_R_TYPE (irel
->r_info
);
1830 r_index
= ELF32_R_SYM (irel
->r_info
);
1832 /* These are the only relocation types we care about. */
1833 if ( r_type
!= R_ARM_PC24
1834 && r_type
!= R_ARM_PLT32
1836 && r_type
!= R_ARM_CALL
1837 && r_type
!= R_ARM_JUMP24
1839 && r_type
!= R_ARM_THM_PC22
)
1842 /* Get the section contents if we haven't done so already. */
1843 if (contents
== NULL
)
1845 /* Get cached copy if it exists. */
1846 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1847 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1850 /* Go get them off disk. */
1851 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1856 /* If the relocation is not against a symbol it cannot concern us. */
1859 /* We don't care about local symbols. */
1860 if (r_index
< symtab_hdr
->sh_info
)
1863 /* This is an external symbol. */
1864 r_index
-= symtab_hdr
->sh_info
;
1865 h
= (struct elf_link_hash_entry
*)
1866 elf_sym_hashes (abfd
)[r_index
];
1868 /* If the relocation is against a static symbol it must be within
1869 the current section and so cannot be a cross ARM/Thumb relocation. */
1873 /* If the call will go through a PLT entry then we do not need
1875 if (globals
->splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
1885 /* This one is a call from arm code. We need to look up
1886 the target of the call. If it is a thumb target, we
1888 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
1889 record_arm_to_thumb_glue (link_info
, h
);
1892 case R_ARM_THM_PC22
:
1893 /* This one is a call from thumb code. We look
1894 up the target of the call. If it is not a thumb
1895 target, we insert glue. */
1896 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
1897 record_thumb_to_arm_glue (link_info
, h
);
1905 if (contents
!= NULL
1906 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1910 if (internal_relocs
!= NULL
1911 && elf_section_data (sec
)->relocs
!= internal_relocs
)
1912 free (internal_relocs
);
1913 internal_relocs
= NULL
;
1919 if (contents
!= NULL
1920 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
1922 if (internal_relocs
!= NULL
1923 && elf_section_data (sec
)->relocs
!= internal_relocs
)
1924 free (internal_relocs
);
1932 /* Set target relocation values needed during linking. */
1935 bfd_elf32_arm_set_target_relocs (struct bfd_link_info
*link_info
,
1937 char * target2_type
,
1940 struct elf32_arm_link_hash_table
*globals
;
1942 globals
= elf32_arm_hash_table (link_info
);
1944 globals
->target1_is_rel
= target1_is_rel
;
1945 if (strcmp (target2_type
, "rel") == 0)
1946 globals
->target2_reloc
= R_ARM_REL32
;
1947 else if (strcmp (target2_type
, "abs") == 0)
1948 globals
->target2_reloc
= R_ARM_ABS32
;
1949 else if (strcmp (target2_type
, "got-rel") == 0)
1950 globals
->target2_reloc
= R_ARM_GOT_PREL
;
1953 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
1956 globals
->fix_v4bx
= fix_v4bx
;
1960 /* The thumb form of a long branch is a bit finicky, because the offset
1961 encoding is split over two fields, each in it's own instruction. They
1962 can occur in any order. So given a thumb form of long branch, and an
1963 offset, insert the offset into the thumb branch and return finished
1966 It takes two thumb instructions to encode the target address. Each has
1967 11 bits to invest. The upper 11 bits are stored in one (identified by
1968 H-0.. see below), the lower 11 bits are stored in the other (identified
1971 Combine together and shifted left by 1 (it's a half word address) and
1975 H-0, upper address-0 = 000
1977 H-1, lower address-0 = 800
1979 They can be ordered either way, but the arm tools I've seen always put
1980 the lower one first. It probably doesn't matter. krk@cygnus.com
1982 XXX: Actually the order does matter. The second instruction (H-1)
1983 moves the computed address into the PC, so it must be the second one
1984 in the sequence. The problem, however is that whilst little endian code
1985 stores the instructions in HI then LOW order, big endian code does the
1986 reverse. nickc@cygnus.com. */
1988 #define LOW_HI_ORDER 0xF800F000
1989 #define HI_LOW_ORDER 0xF000F800
1992 insert_thumb_branch (insn32 br_insn
, int rel_off
)
1994 unsigned int low_bits
;
1995 unsigned int high_bits
;
1997 BFD_ASSERT ((rel_off
& 1) != 1);
1999 rel_off
>>= 1; /* Half word aligned address. */
2000 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
2001 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
2003 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
2004 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
2005 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
2006 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
2008 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2009 abort (); /* Error - not a valid branch instruction form. */
2014 /* Thumb code calling an ARM function. */
2017 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
2021 asection
* input_section
,
2022 bfd_byte
* hit_data
,
2025 bfd_signed_vma addend
,
2030 unsigned long int tmp
;
2031 long int ret_offset
;
2032 struct elf_link_hash_entry
* myh
;
2033 struct elf32_arm_link_hash_table
* globals
;
2035 myh
= find_thumb_glue (info
, name
, input_bfd
);
2039 globals
= elf32_arm_hash_table (info
);
2041 BFD_ASSERT (globals
!= NULL
);
2042 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2044 my_offset
= myh
->root
.u
.def
.value
;
2046 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2047 THUMB2ARM_GLUE_SECTION_NAME
);
2049 BFD_ASSERT (s
!= NULL
);
2050 BFD_ASSERT (s
->contents
!= NULL
);
2051 BFD_ASSERT (s
->output_section
!= NULL
);
2053 if ((my_offset
& 0x01) == 0x01)
2056 && sym_sec
->owner
!= NULL
2057 && !INTERWORK_FLAG (sym_sec
->owner
))
2059 (*_bfd_error_handler
)
2060 (_("%B(%s): warning: interworking not enabled.\n"
2061 " first occurrence: %B: thumb call to arm"),
2062 sym_sec
->owner
, input_bfd
, name
);
2068 myh
->root
.u
.def
.value
= my_offset
;
2070 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
2071 s
->contents
+ my_offset
);
2073 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
2074 s
->contents
+ my_offset
+ 2);
2077 /* Address of destination of the stub. */
2078 ((bfd_signed_vma
) val
)
2080 /* Offset from the start of the current section
2081 to the start of the stubs. */
2083 /* Offset of the start of this stub from the start of the stubs. */
2085 /* Address of the start of the current section. */
2086 + s
->output_section
->vma
)
2087 /* The branch instruction is 4 bytes into the stub. */
2089 /* ARM branches work from the pc of the instruction + 8. */
2092 bfd_put_32 (output_bfd
,
2093 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
2094 s
->contents
+ my_offset
+ 4);
2097 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
2099 /* Now go back and fix up the original BL insn to point to here. */
2101 /* Address of where the stub is located. */
2102 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
2103 /* Address of where the BL is located. */
2104 - (input_section
->output_section
->vma
+ input_section
->output_offset
2106 /* Addend in the relocation. */
2108 /* Biassing for PC-relative addressing. */
2111 tmp
= bfd_get_32 (input_bfd
, hit_data
2112 - input_section
->vma
);
2114 bfd_put_32 (output_bfd
,
2115 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
2116 hit_data
- input_section
->vma
);
2121 /* Arm code calling a Thumb function. */
2124 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
2128 asection
* input_section
,
2129 bfd_byte
* hit_data
,
2132 bfd_signed_vma addend
,
2135 unsigned long int tmp
;
2138 long int ret_offset
;
2139 struct elf_link_hash_entry
* myh
;
2140 struct elf32_arm_link_hash_table
* globals
;
2142 myh
= find_arm_glue (info
, name
, input_bfd
);
2146 globals
= elf32_arm_hash_table (info
);
2148 BFD_ASSERT (globals
!= NULL
);
2149 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
2151 my_offset
= myh
->root
.u
.def
.value
;
2152 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
2153 ARM2THUMB_GLUE_SECTION_NAME
);
2154 BFD_ASSERT (s
!= NULL
);
2155 BFD_ASSERT (s
->contents
!= NULL
);
2156 BFD_ASSERT (s
->output_section
!= NULL
);
2158 if ((my_offset
& 0x01) == 0x01)
2161 && sym_sec
->owner
!= NULL
2162 && !INTERWORK_FLAG (sym_sec
->owner
))
2164 (*_bfd_error_handler
)
2165 (_("%B(%s): warning: interworking not enabled.\n"
2166 " first occurrence: %B: arm call to thumb"),
2167 sym_sec
->owner
, input_bfd
, name
);
2171 myh
->root
.u
.def
.value
= my_offset
;
2173 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
2174 s
->contents
+ my_offset
);
2176 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
2177 s
->contents
+ my_offset
+ 4);
2179 /* It's a thumb address. Add the low order bit. */
2180 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
2181 s
->contents
+ my_offset
+ 8);
2184 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
2186 tmp
= bfd_get_32 (input_bfd
, hit_data
);
2187 tmp
= tmp
& 0xFF000000;
2189 /* Somehow these are both 4 too far, so subtract 8. */
2190 ret_offset
= (s
->output_offset
2192 + s
->output_section
->vma
2193 - (input_section
->output_offset
2194 + input_section
->output_section
->vma
2198 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
2200 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
2207 /* Some relocations map to different relocations depending on the
2208 target. Return the real relocation. */
2210 arm_real_reloc_type (struct elf32_arm_link_hash_table
* globals
,
2216 if (globals
->target1_is_rel
)
2222 return globals
->target2_reloc
;
2228 #endif /* OLD_ARM_ABI */
2231 /* Perform a relocation as part of a final link. */
2233 static bfd_reloc_status_type
2234 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
2237 asection
* input_section
,
2238 bfd_byte
* contents
,
2239 Elf_Internal_Rela
* rel
,
2241 struct bfd_link_info
* info
,
2243 const char * sym_name
,
2245 struct elf_link_hash_entry
* h
)
2247 unsigned long r_type
= howto
->type
;
2248 unsigned long r_symndx
;
2249 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
2250 bfd
* dynobj
= NULL
;
2251 Elf_Internal_Shdr
* symtab_hdr
;
2252 struct elf_link_hash_entry
** sym_hashes
;
2253 bfd_vma
* local_got_offsets
;
2254 asection
* sgot
= NULL
;
2255 asection
* splt
= NULL
;
2256 asection
* sreloc
= NULL
;
2258 bfd_signed_vma signed_addend
;
2259 struct elf32_arm_link_hash_table
* globals
;
2261 globals
= elf32_arm_hash_table (info
);
2264 /* Some relocation type map to different relocations depending on the
2265 target. We pick the right one here. */
2266 r_type
= arm_real_reloc_type (globals
, r_type
);
2267 if (r_type
!= howto
->type
)
2268 howto
= elf32_arm_howto_from_type (r_type
);
2269 #endif /* OLD_ARM_ABI */
2271 /* If the start address has been set, then set the EF_ARM_HASENTRY
2272 flag. Setting this more than once is redundant, but the cost is
2273 not too high, and it keeps the code simple.
2275 The test is done here, rather than somewhere else, because the
2276 start address is only set just before the final link commences.
2278 Note - if the user deliberately sets a start address of 0, the
2279 flag will not be set. */
2280 if (bfd_get_start_address (output_bfd
) != 0)
2281 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
2283 dynobj
= elf_hash_table (info
)->dynobj
;
2286 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2287 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2289 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2290 sym_hashes
= elf_sym_hashes (input_bfd
);
2291 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2292 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2294 if (globals
->use_rel
)
2296 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
2298 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2301 signed_addend
&= ~ howto
->src_mask
;
2302 signed_addend
|= addend
;
2305 signed_addend
= addend
;
2308 addend
= signed_addend
= rel
->r_addend
;
2313 return bfd_reloc_ok
;
2325 /* r_symndx will be zero only for relocs against symbols
2326 from removed linkonce sections, or sections discarded by
2329 return bfd_reloc_ok
;
2331 /* Handle relocations which should use the PLT entry. ABS32/REL32
2332 will use the symbol's value, which may point to a PLT entry, but we
2333 don't need to handle that here. If we created a PLT entry, all
2334 branches in this object should go to it. */
2335 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
2338 && h
->plt
.offset
!= (bfd_vma
) -1)
2340 /* If we've created a .plt section, and assigned a PLT entry to
2341 this function, it should not be known to bind locally. If
2342 it were, we would have cleared the PLT entry. */
2343 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
2345 value
= (splt
->output_section
->vma
2346 + splt
->output_offset
2348 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2349 contents
, rel
->r_offset
, value
,
2353 /* When generating a shared object, these relocations are copied
2354 into the output file to be resolved at run time. */
2356 && (input_section
->flags
& SEC_ALLOC
)
2357 && (r_type
!= R_ARM_REL32
2358 || !SYMBOL_CALLS_LOCAL (info
, h
))
2360 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2361 || h
->root
.type
!= bfd_link_hash_undefweak
)
2362 && r_type
!= R_ARM_PC24
2364 && r_type
!= R_ARM_CALL
2365 && r_type
!= R_ARM_JUMP24
2366 && r_type
!= R_ARM_PREL31
2368 && r_type
!= R_ARM_PLT32
)
2370 Elf_Internal_Rela outrel
;
2372 bfd_boolean skip
, relocate
;
2378 name
= (bfd_elf_string_from_elf_section
2380 elf_elfheader (input_bfd
)->e_shstrndx
,
2381 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2383 return bfd_reloc_notsupported
;
2385 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
2386 && strcmp (bfd_get_section_name (input_bfd
,
2390 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2391 BFD_ASSERT (sreloc
!= NULL
);
2398 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
2400 if (outrel
.r_offset
== (bfd_vma
) -1)
2402 else if (outrel
.r_offset
== (bfd_vma
) -2)
2403 skip
= TRUE
, relocate
= TRUE
;
2404 outrel
.r_offset
+= (input_section
->output_section
->vma
2405 + input_section
->output_offset
);
2408 memset (&outrel
, 0, sizeof outrel
);
2413 || !h
->def_regular
))
2414 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2419 /* This symbol is local, or marked to become local. */
2421 if (sym_flags
== STT_ARM_TFUNC
)
2423 if (globals
->symbian_p
)
2425 /* On Symbian OS, the data segment and text segement
2426 can be relocated independently. Therefore, we
2427 must indicate the segment to which this
2428 relocation is relative. The BPABI allows us to
2429 use any symbol in the right segment; we just use
2430 the section symbol as it is convenient. (We
2431 cannot use the symbol given by "h" directly as it
2432 will not appear in the dynamic symbol table.) */
2433 symbol
= elf_section_data (sym_sec
->output_section
)->dynindx
;
2434 BFD_ASSERT (symbol
!= 0);
2437 /* On SVR4-ish systems, the dynamic loader cannot
2438 relocate the text and data segments independently,
2439 so the symbol does not matter. */
2441 outrel
.r_info
= ELF32_R_INFO (symbol
, R_ARM_RELATIVE
);
2444 loc
= sreloc
->contents
;
2445 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2446 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2448 /* If this reloc is against an external symbol, we do not want to
2449 fiddle with the addend. Otherwise, we need to include the symbol
2450 value so that it becomes an addend for the dynamic reloc. */
2452 return bfd_reloc_ok
;
2454 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2455 contents
, rel
->r_offset
, value
,
2458 else switch (r_type
)
2461 case R_ARM_XPC25
: /* Arm BLX instruction. */
2465 case R_ARM_PC24
: /* Arm B/BL instruction */
2468 if (r_type
== R_ARM_XPC25
)
2470 /* Check for Arm calling Arm function. */
2471 /* FIXME: Should we translate the instruction into a BL
2472 instruction instead ? */
2473 if (sym_flags
!= STT_ARM_TFUNC
)
2474 (*_bfd_error_handler
)
2475 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
2477 h
? h
->root
.root
.string
: "(local)");
2482 /* Check for Arm calling Thumb function. */
2483 if (sym_flags
== STT_ARM_TFUNC
)
2485 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
2486 output_bfd
, input_section
,
2487 hit_data
, sym_sec
, rel
->r_offset
,
2488 signed_addend
, value
);
2489 return bfd_reloc_ok
;
2493 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
2495 S is the address of the symbol in the relocation.
2496 P is address of the instruction being relocated.
2497 A is the addend (extracted from the instruction) in bytes.
2499 S is held in 'value'.
2500 P is the base address of the section containing the
2501 instruction plus the offset of the reloc into that
2503 (input_section->output_section->vma +
2504 input_section->output_offset +
2506 A is the addend, converted into bytes, ie:
2509 Note: None of these operations have knowledge of the pipeline
2510 size of the processor, thus it is up to the assembler to
2511 encode this information into the addend. */
2512 value
-= (input_section
->output_section
->vma
2513 + input_section
->output_offset
);
2514 value
-= rel
->r_offset
;
2515 if (globals
->use_rel
)
2516 value
+= (signed_addend
<< howto
->size
);
2518 /* RELA addends do not have to be adjusted by howto->size. */
2519 value
+= signed_addend
;
2521 signed_addend
= value
;
2522 signed_addend
>>= howto
->rightshift
;
2524 /* It is not an error for an undefined weak reference to be
2525 out of range. Any program that branches to such a symbol
2526 is going to crash anyway, so there is no point worrying
2527 about getting the destination exactly right. */
2528 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
2530 /* Perform a signed range check. */
2531 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
2532 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
2533 return bfd_reloc_overflow
;
2537 /* If necessary set the H bit in the BLX instruction. */
2538 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
2539 value
= (signed_addend
& howto
->dst_mask
)
2540 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
2544 value
= (signed_addend
& howto
->dst_mask
)
2545 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
2550 if (sym_flags
== STT_ARM_TFUNC
)
2555 value
-= (input_section
->output_section
->vma
2556 + input_section
->output_offset
+ rel
->r_offset
);
2562 value
-= (input_section
->output_section
->vma
2563 + input_section
->output_offset
+ rel
->r_offset
);
2564 value
+= signed_addend
;
2565 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
2567 /* Check for overflow */
2568 if ((value
^ (value
>> 1)) & (1 << 30))
2569 return bfd_reloc_overflow
;
2571 value
&= 0x7fffffff;
2572 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0x80000000);
2573 if (sym_flags
== STT_ARM_TFUNC
)
2579 bfd_put_32 (input_bfd
, value
, hit_data
);
2580 return bfd_reloc_ok
;
2584 if ((long) value
> 0x7f || (long) value
< -0x80)
2585 return bfd_reloc_overflow
;
2587 bfd_put_8 (input_bfd
, value
, hit_data
);
2588 return bfd_reloc_ok
;
2593 if ((long) value
> 0x7fff || (long) value
< -0x8000)
2594 return bfd_reloc_overflow
;
2596 bfd_put_16 (input_bfd
, value
, hit_data
);
2597 return bfd_reloc_ok
;
2600 /* Support ldr and str instruction for the arm */
2601 /* Also thumb b (unconditional branch). ??? Really? */
2604 if ((long) value
> 0x7ff || (long) value
< -0x800)
2605 return bfd_reloc_overflow
;
2607 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
2608 bfd_put_32 (input_bfd
, value
, hit_data
);
2609 return bfd_reloc_ok
;
2611 case R_ARM_THM_ABS5
:
2612 /* Support ldr and str instructions for the thumb. */
2613 if (globals
->use_rel
)
2615 /* Need to refetch addend. */
2616 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
2617 /* ??? Need to determine shift amount from operand size. */
2618 addend
>>= howto
->rightshift
;
2622 /* ??? Isn't value unsigned? */
2623 if ((long) value
> 0x1f || (long) value
< -0x10)
2624 return bfd_reloc_overflow
;
2626 /* ??? Value needs to be properly shifted into place first. */
2627 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
2628 bfd_put_16 (input_bfd
, value
, hit_data
);
2629 return bfd_reloc_ok
;
2632 case R_ARM_THM_XPC22
:
2634 case R_ARM_THM_PC22
:
2635 /* Thumb BL (branch long instruction). */
2638 bfd_boolean overflow
= FALSE
;
2639 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
2640 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
2641 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
2642 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
2644 bfd_signed_vma signed_check
;
2646 /* Need to refetch the addend and squish the two 11 bit pieces
2648 if (globals
->use_rel
)
2650 bfd_vma upper
= upper_insn
& 0x7ff;
2651 bfd_vma lower
= lower_insn
& 0x7ff;
2652 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
2653 addend
= (upper
<< 12) | (lower
<< 1);
2654 signed_addend
= addend
;
2657 if (r_type
== R_ARM_THM_XPC22
)
2659 /* Check for Thumb to Thumb call. */
2660 /* FIXME: Should we translate the instruction into a BL
2661 instruction instead ? */
2662 if (sym_flags
== STT_ARM_TFUNC
)
2663 (*_bfd_error_handler
)
2664 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
2666 h
? h
->root
.root
.string
: "(local)");
2671 /* If it is not a call to Thumb, assume call to Arm.
2672 If it is a call relative to a section name, then it is not a
2673 function call at all, but rather a long jump. Calls through
2674 the PLT do not require stubs. */
2675 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
2676 && (h
== NULL
|| splt
== NULL
2677 || h
->plt
.offset
== (bfd_vma
) -1))
2679 if (elf32_thumb_to_arm_stub
2680 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
2681 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
2682 return bfd_reloc_ok
;
2684 return bfd_reloc_dangerous
;
2688 /* Handle calls via the PLT. */
2689 if (h
!= NULL
&& splt
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1)
2691 value
= (splt
->output_section
->vma
2692 + splt
->output_offset
2694 /* Target the Thumb stub before the ARM PLT entry. */
2698 relocation
= value
+ signed_addend
;
2700 relocation
-= (input_section
->output_section
->vma
2701 + input_section
->output_offset
2704 check
= relocation
>> howto
->rightshift
;
2706 /* If this is a signed value, the rightshift just dropped
2707 leading 1 bits (assuming twos complement). */
2708 if ((bfd_signed_vma
) relocation
>= 0)
2709 signed_check
= check
;
2711 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
2713 /* Assumes two's complement. */
2714 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
2718 if (r_type
== R_ARM_THM_XPC22
2719 && ((lower_insn
& 0x1800) == 0x0800))
2720 /* For a BLX instruction, make sure that the relocation is rounded up
2721 to a word boundary. This follows the semantics of the instruction
2722 which specifies that bit 1 of the target address will come from bit
2723 1 of the base address. */
2724 relocation
= (relocation
+ 2) & ~ 3;
2726 /* Put RELOCATION back into the insn. */
2727 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
2728 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
2730 /* Put the relocated value back in the object file: */
2731 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
2732 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
2734 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
2738 case R_ARM_THM_PC11
:
2739 /* Thumb B (branch) instruction). */
2741 bfd_signed_vma relocation
;
2742 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
2743 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
2744 bfd_signed_vma signed_check
;
2746 if (globals
->use_rel
)
2748 /* Need to refetch addend. */
2749 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
2750 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2753 signed_addend
&= ~ howto
->src_mask
;
2754 signed_addend
|= addend
;
2757 signed_addend
= addend
;
2758 /* The value in the insn has been right shifted. We need to
2759 undo this, so that we can perform the address calculation
2760 in terms of bytes. */
2761 signed_addend
<<= howto
->rightshift
;
2763 relocation
= value
+ signed_addend
;
2765 relocation
-= (input_section
->output_section
->vma
2766 + input_section
->output_offset
2769 relocation
>>= howto
->rightshift
;
2770 signed_check
= relocation
;
2771 relocation
&= howto
->dst_mask
;
2772 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
2774 bfd_put_16 (input_bfd
, relocation
, hit_data
);
2776 /* Assumes two's complement. */
2777 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
2778 return bfd_reloc_overflow
;
2780 return bfd_reloc_ok
;
2784 case R_ARM_ALU_PCREL7_0
:
2785 case R_ARM_ALU_PCREL15_8
:
2786 case R_ARM_ALU_PCREL23_15
:
2791 insn
= bfd_get_32 (input_bfd
, hit_data
);
2792 if (globals
->use_rel
)
2794 /* Extract the addend. */
2795 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
2796 signed_addend
= addend
;
2798 relocation
= value
+ signed_addend
;
2800 relocation
-= (input_section
->output_section
->vma
2801 + input_section
->output_offset
2803 insn
= (insn
& ~0xfff)
2804 | ((howto
->bitpos
<< 7) & 0xf00)
2805 | ((relocation
>> howto
->bitpos
) & 0xff);
2806 bfd_put_32 (input_bfd
, value
, hit_data
);
2808 return bfd_reloc_ok
;
2811 case R_ARM_GNU_VTINHERIT
:
2812 case R_ARM_GNU_VTENTRY
:
2813 return bfd_reloc_ok
;
2816 return bfd_reloc_notsupported
;
2818 case R_ARM_GLOB_DAT
:
2819 return bfd_reloc_notsupported
;
2821 case R_ARM_JUMP_SLOT
:
2822 return bfd_reloc_notsupported
;
2824 case R_ARM_RELATIVE
:
2825 return bfd_reloc_notsupported
;
2828 /* Relocation is relative to the start of the
2829 global offset table. */
2831 BFD_ASSERT (sgot
!= NULL
);
2833 return bfd_reloc_notsupported
;
2835 /* If we are addressing a Thumb function, we need to adjust the
2836 address by one, so that attempts to call the function pointer will
2837 correctly interpret it as Thumb code. */
2838 if (sym_flags
== STT_ARM_TFUNC
)
2841 /* Note that sgot->output_offset is not involved in this
2842 calculation. We always want the start of .got. If we
2843 define _GLOBAL_OFFSET_TABLE in a different way, as is
2844 permitted by the ABI, we might have to change this
2846 value
-= sgot
->output_section
->vma
;
2847 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2848 contents
, rel
->r_offset
, value
,
2852 /* Use global offset table as symbol value. */
2853 BFD_ASSERT (sgot
!= NULL
);
2856 return bfd_reloc_notsupported
;
2858 value
= sgot
->output_section
->vma
;
2859 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2860 contents
, rel
->r_offset
, value
,
2865 case R_ARM_GOT_PREL
:
2867 /* Relocation is to the entry for this symbol in the
2868 global offset table. */
2870 return bfd_reloc_notsupported
;
2877 off
= h
->got
.offset
;
2878 BFD_ASSERT (off
!= (bfd_vma
) -1);
2879 dyn
= globals
->root
.dynamic_sections_created
;
2881 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2883 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2884 || (ELF_ST_VISIBILITY (h
->other
)
2885 && h
->root
.type
== bfd_link_hash_undefweak
))
2887 /* This is actually a static link, or it is a -Bsymbolic link
2888 and the symbol is defined locally. We must initialize this
2889 entry in the global offset table. Since the offset must
2890 always be a multiple of 4, we use the least significant bit
2891 to record whether we have initialized it already.
2893 When doing a dynamic link, we create a .rel.got relocation
2894 entry to initialize the value. This is done in the
2895 finish_dynamic_symbol routine. */
2900 /* If we are addressing a Thumb function, we need to
2901 adjust the address by one, so that attempts to
2902 call the function pointer will correctly
2903 interpret it as Thumb code. */
2904 if (sym_flags
== STT_ARM_TFUNC
)
2907 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
2912 value
= sgot
->output_offset
+ off
;
2918 BFD_ASSERT (local_got_offsets
!= NULL
&&
2919 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
2921 off
= local_got_offsets
[r_symndx
];
2923 /* The offset must always be a multiple of 4. We use the
2924 least significant bit to record whether we have already
2925 generated the necessary reloc. */
2930 /* If we are addressing a Thumb function, we need to
2931 adjust the address by one, so that attempts to
2932 call the function pointer will correctly
2933 interpret it as Thumb code. */
2934 if (sym_flags
== STT_ARM_TFUNC
)
2937 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
2942 Elf_Internal_Rela outrel
;
2945 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
2946 BFD_ASSERT (srelgot
!= NULL
);
2948 outrel
.r_offset
= (sgot
->output_section
->vma
2949 + sgot
->output_offset
2951 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
2952 loc
= srelgot
->contents
;
2953 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
2954 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
2957 local_got_offsets
[r_symndx
] |= 1;
2960 value
= sgot
->output_offset
+ off
;
2962 if (r_type
!= R_ARM_GOT32
)
2963 value
+= sgot
->output_section
->vma
;
2965 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2966 contents
, rel
->r_offset
, value
,
2970 return bfd_reloc_notsupported
;
2972 case R_ARM_AMP_VCALL9
:
2973 return bfd_reloc_notsupported
;
2975 case R_ARM_RSBREL32
:
2976 return bfd_reloc_notsupported
;
2978 case R_ARM_THM_RPC22
:
2979 return bfd_reloc_notsupported
;
2982 return bfd_reloc_notsupported
;
2985 return bfd_reloc_notsupported
;
2988 return bfd_reloc_notsupported
;
2991 return bfd_reloc_notsupported
;
2994 if (globals
->fix_v4bx
)
2996 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
2998 /* Ensure that we have a BX instruction. */
2999 BFD_ASSERT ((insn
& 0x0ffffff0) == 0x012fff10);
3001 /* Preserve Rm (lowest four bits) and the condition code
3002 (highest four bits). Other bits encode MOV PC,Rm. */
3003 insn
= (insn
& 0xf000000f) | 0x01a0f000;
3005 bfd_put_32 (input_bfd
, insn
, hit_data
);
3007 return bfd_reloc_ok
;
3010 return bfd_reloc_notsupported
;
3014 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
3016 arm_add_to_rel (bfd
* abfd
,
3018 reloc_howto_type
* howto
,
3019 bfd_signed_vma increment
)
3021 bfd_signed_vma addend
;
3023 if (howto
->type
== R_ARM_THM_PC22
)
3025 int upper_insn
, lower_insn
;
3028 upper_insn
= bfd_get_16 (abfd
, address
);
3029 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
3030 upper
= upper_insn
& 0x7ff;
3031 lower
= lower_insn
& 0x7ff;
3033 addend
= (upper
<< 12) | (lower
<< 1);
3034 addend
+= increment
;
3037 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
3038 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
3040 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
3041 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
3047 contents
= bfd_get_32 (abfd
, address
);
3049 /* Get the (signed) value from the instruction. */
3050 addend
= contents
& howto
->src_mask
;
3051 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3053 bfd_signed_vma mask
;
3056 mask
&= ~ howto
->src_mask
;
3060 /* Add in the increment, (which is a byte value). */
3061 switch (howto
->type
)
3064 addend
+= increment
;
3072 addend
<<= howto
->size
;
3073 addend
+= increment
;
3075 /* Should we check for overflow here ? */
3077 /* Drop any undesired bits. */
3078 addend
>>= howto
->rightshift
;
3082 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
3084 bfd_put_32 (abfd
, contents
, address
);
3088 /* Relocate an ARM ELF section. */
3090 elf32_arm_relocate_section (bfd
* output_bfd
,
3091 struct bfd_link_info
* info
,
3093 asection
* input_section
,
3094 bfd_byte
* contents
,
3095 Elf_Internal_Rela
* relocs
,
3096 Elf_Internal_Sym
* local_syms
,
3097 asection
** local_sections
)
3099 Elf_Internal_Shdr
*symtab_hdr
;
3100 struct elf_link_hash_entry
**sym_hashes
;
3101 Elf_Internal_Rela
*rel
;
3102 Elf_Internal_Rela
*relend
;
3104 struct elf32_arm_link_hash_table
* globals
;
3106 globals
= elf32_arm_hash_table (info
);
3107 if (info
->relocatable
&& !globals
->use_rel
)
3110 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
3111 sym_hashes
= elf_sym_hashes (input_bfd
);
3114 relend
= relocs
+ input_section
->reloc_count
;
3115 for (; rel
< relend
; rel
++)
3118 reloc_howto_type
* howto
;
3119 unsigned long r_symndx
;
3120 Elf_Internal_Sym
* sym
;
3122 struct elf_link_hash_entry
* h
;
3124 bfd_reloc_status_type r
;
3127 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3128 r_type
= ELF32_R_TYPE (rel
->r_info
);
3129 r_type
= arm_real_reloc_type (globals
, r_type
);
3131 if ( r_type
== R_ARM_GNU_VTENTRY
3132 || r_type
== R_ARM_GNU_VTINHERIT
)
3135 bfd_reloc
.howto
= elf32_arm_howto_from_type (r_type
);
3136 howto
= bfd_reloc
.howto
;
3138 if (info
->relocatable
&& globals
->use_rel
)
3140 /* This is a relocatable link. We don't have to change
3141 anything, unless the reloc is against a section symbol,
3142 in which case we have to adjust according to where the
3143 section symbol winds up in the output section. */
3144 if (r_symndx
< symtab_hdr
->sh_info
)
3146 sym
= local_syms
+ r_symndx
;
3147 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3149 sec
= local_sections
[r_symndx
];
3150 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
3152 (bfd_signed_vma
) (sec
->output_offset
3160 /* This is a final link. */
3165 if (r_symndx
< symtab_hdr
->sh_info
)
3167 sym
= local_syms
+ r_symndx
;
3168 sec
= local_sections
[r_symndx
];
3169 if (globals
->use_rel
)
3171 relocation
= (sec
->output_section
->vma
3172 + sec
->output_offset
3174 if ((sec
->flags
& SEC_MERGE
)
3175 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3178 bfd_vma addend
, value
;
3180 if (howto
->rightshift
)
3182 (*_bfd_error_handler
)
3183 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
3184 input_bfd
, input_section
,
3185 (long) rel
->r_offset
, howto
->name
);
3189 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
3191 /* Get the (signed) value from the instruction. */
3192 addend
= value
& howto
->src_mask
;
3193 if (addend
& ((howto
->src_mask
+ 1) >> 1))
3195 bfd_signed_vma mask
;
3198 mask
&= ~ howto
->src_mask
;
3203 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
3205 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
3206 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
3207 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
3211 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
3216 bfd_boolean unresolved_reloc
;
3218 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3219 r_symndx
, symtab_hdr
, sym_hashes
,
3221 unresolved_reloc
, warned
);
3223 if (unresolved_reloc
|| relocation
!= 0)
3225 /* In these cases, we don't need the relocation value.
3226 We check specially because in some obscure cases
3227 sec->output_section will be NULL. */
3237 case R_ARM_THM_PC22
:
3241 && ((!info
->symbolic
&& h
->dynindx
!= -1)
3243 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3244 && ((input_section
->flags
& SEC_ALLOC
) != 0
3245 /* DWARF will emit R_ARM_ABS32 relocations in its
3246 sections against symbols defined externally
3247 in shared libraries. We can't do anything
3249 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
3261 case R_ARM_GOT_PREL
:
3263 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
3264 (elf_hash_table (info
)->dynamic_sections_created
,
3267 || (!info
->symbolic
&& h
->dynindx
!= -1)
3268 || !h
->def_regular
))
3273 if (unresolved_reloc
)
3275 (_("%B(%A): warning: unresolvable relocation %d against symbol `%s'"),
3276 input_bfd
, input_section
,
3278 h
->root
.root
.string
);
3285 name
= h
->root
.root
.string
;
3288 name
= (bfd_elf_string_from_elf_section
3289 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
3290 if (name
== NULL
|| *name
== '\0')
3291 name
= bfd_section_name (input_bfd
, sec
);
3294 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
3295 input_section
, contents
, rel
,
3296 relocation
, info
, sec
, name
,
3297 (h
? ELF_ST_TYPE (h
->type
) :
3298 ELF_ST_TYPE (sym
->st_info
)), h
);
3300 if (r
!= bfd_reloc_ok
)
3302 const char * msg
= (const char *) 0;
3306 case bfd_reloc_overflow
:
3307 /* If the overflowing reloc was to an undefined symbol,
3308 we have already printed one error message and there
3309 is no point complaining again. */
3311 h
->root
.type
!= bfd_link_hash_undefined
)
3312 && (!((*info
->callbacks
->reloc_overflow
)
3313 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3314 (bfd_vma
) 0, input_bfd
, input_section
,
3319 case bfd_reloc_undefined
:
3320 if (!((*info
->callbacks
->undefined_symbol
)
3321 (info
, name
, input_bfd
, input_section
,
3322 rel
->r_offset
, TRUE
)))
3326 case bfd_reloc_outofrange
:
3327 msg
= _("internal error: out of range error");
3330 case bfd_reloc_notsupported
:
3331 msg
= _("internal error: unsupported relocation error");
3334 case bfd_reloc_dangerous
:
3335 msg
= _("internal error: dangerous error");
3339 msg
= _("internal error: unknown error");
3343 if (!((*info
->callbacks
->warning
)
3344 (info
, msg
, name
, input_bfd
, input_section
,
3355 /* Set the right machine number. */
3358 elf32_arm_object_p (bfd
*abfd
)
3362 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
3364 if (mach
!= bfd_mach_arm_unknown
)
3365 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
3367 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
3368 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
3371 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
3376 /* Function to keep ARM specific flags in the ELF header. */
3379 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
3381 if (elf_flags_init (abfd
)
3382 && elf_elfheader (abfd
)->e_flags
!= flags
)
3384 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
3386 if (flags
& EF_ARM_INTERWORK
)
3387 (*_bfd_error_handler
)
3388 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
3392 (_("Warning: Clearing the interworking flag of %B due to outside request"),
3398 elf_elfheader (abfd
)->e_flags
= flags
;
3399 elf_flags_init (abfd
) = TRUE
;
3405 /* Copy backend specific data from one object module to another. */
3408 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3413 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3414 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3417 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3418 out_flags
= elf_elfheader (obfd
)->e_flags
;
3420 if (elf_flags_init (obfd
)
3421 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
3422 && in_flags
!= out_flags
)
3424 /* Cannot mix APCS26 and APCS32 code. */
3425 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
3428 /* Cannot mix float APCS and non-float APCS code. */
3429 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
3432 /* If the src and dest have different interworking flags
3433 then turn off the interworking bit. */
3434 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
3436 if (out_flags
& EF_ARM_INTERWORK
)
3438 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
3441 in_flags
&= ~EF_ARM_INTERWORK
;
3444 /* Likewise for PIC, though don't warn for this case. */
3445 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
3446 in_flags
&= ~EF_ARM_PIC
;
3449 elf_elfheader (obfd
)->e_flags
= in_flags
;
3450 elf_flags_init (obfd
) = TRUE
;
3452 /* Also copy the EI_OSABI field. */
3453 elf_elfheader (obfd
)->e_ident
[EI_OSABI
] =
3454 elf_elfheader (ibfd
)->e_ident
[EI_OSABI
];
3459 /* Merge backend specific data from an object file to the output
3460 object file when linking. */
3463 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
3467 bfd_boolean flags_compatible
= TRUE
;
3470 /* Check if we have the same endianess. */
3471 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
3474 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3475 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3478 /* The input BFD must have had its flags initialised. */
3479 /* The following seems bogus to me -- The flags are initialized in
3480 the assembler but I don't think an elf_flags_init field is
3481 written into the object. */
3482 /* BFD_ASSERT (elf_flags_init (ibfd)); */
3484 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3485 out_flags
= elf_elfheader (obfd
)->e_flags
;
3487 if (!elf_flags_init (obfd
))
3489 /* If the input is the default architecture and had the default
3490 flags then do not bother setting the flags for the output
3491 architecture, instead allow future merges to do this. If no
3492 future merges ever set these flags then they will retain their
3493 uninitialised values, which surprise surprise, correspond
3494 to the default values. */
3495 if (bfd_get_arch_info (ibfd
)->the_default
3496 && elf_elfheader (ibfd
)->e_flags
== 0)
3499 elf_flags_init (obfd
) = TRUE
;
3500 elf_elfheader (obfd
)->e_flags
= in_flags
;
3502 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3503 && bfd_get_arch_info (obfd
)->the_default
)
3504 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
3509 /* Determine what should happen if the input ARM architecture
3510 does not match the output ARM architecture. */
3511 if (! bfd_arm_merge_machines (ibfd
, obfd
))
3514 /* Identical flags must be compatible. */
3515 if (in_flags
== out_flags
)
3518 /* Check to see if the input BFD actually contains any sections. If
3519 not, its flags may not have been initialised either, but it
3520 cannot actually cause any incompatibility. Do not short-circuit
3521 dynamic objects; their section list may be emptied by
3522 elf_link_add_object_symbols.
3524 Also check to see if there are no code sections in the input.
3525 In this case there is no need to check for code specific flags.
3526 XXX - do we need to worry about floating-point format compatability
3527 in data sections ? */
3528 if (!(ibfd
->flags
& DYNAMIC
))
3530 bfd_boolean null_input_bfd
= TRUE
;
3531 bfd_boolean only_data_sections
= TRUE
;
3533 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3535 /* Ignore synthetic glue sections. */
3536 if (strcmp (sec
->name
, ".glue_7")
3537 && strcmp (sec
->name
, ".glue_7t"))
3539 if ((bfd_get_section_flags (ibfd
, sec
)
3540 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
3541 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
3542 only_data_sections
= FALSE
;
3544 null_input_bfd
= FALSE
;
3549 if (null_input_bfd
|| only_data_sections
)
3553 /* Complain about various flag mismatches. */
3554 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
3557 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
3559 (in_flags
& EF_ARM_EABIMASK
) >> 24,
3560 (out_flags
& EF_ARM_EABIMASK
) >> 24);
3564 /* Not sure what needs to be checked for EABI versions >= 1. */
3565 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
3567 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
3570 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
3572 in_flags
& EF_ARM_APCS_26
? 26 : 32,
3573 out_flags
& EF_ARM_APCS_26
? 26 : 32);
3574 flags_compatible
= FALSE
;
3577 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
3579 if (in_flags
& EF_ARM_APCS_FLOAT
)
3581 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
3585 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
3588 flags_compatible
= FALSE
;
3591 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
3593 if (in_flags
& EF_ARM_VFP_FLOAT
)
3595 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
3599 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
3602 flags_compatible
= FALSE
;
3605 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
3607 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
3609 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
3613 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
3616 flags_compatible
= FALSE
;
3619 #ifdef EF_ARM_SOFT_FLOAT
3620 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
3622 /* We can allow interworking between code that is VFP format
3623 layout, and uses either soft float or integer regs for
3624 passing floating point arguments and results. We already
3625 know that the APCS_FLOAT flags match; similarly for VFP
3627 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
3628 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
3630 if (in_flags
& EF_ARM_SOFT_FLOAT
)
3632 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
3636 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
3639 flags_compatible
= FALSE
;
3644 /* Interworking mismatch is only a warning. */
3645 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
3647 if (in_flags
& EF_ARM_INTERWORK
)
3650 (_("Warning: %B supports interworking, whereas %B does not"),
3656 (_("Warning: %B does not support interworking, whereas %B does"),
3662 return flags_compatible
;
3665 /* Display the flags field. */
3668 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
3670 FILE * file
= (FILE *) ptr
;
3671 unsigned long flags
;
3673 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3675 /* Print normal ELF private data. */
3676 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3678 flags
= elf_elfheader (abfd
)->e_flags
;
3679 /* Ignore init flag - it may not be set, despite the flags field
3680 containing valid data. */
3682 /* xgettext:c-format */
3683 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
3685 switch (EF_ARM_EABI_VERSION (flags
))
3687 case EF_ARM_EABI_UNKNOWN
:
3688 /* The following flag bits are GNU extensions and not part of the
3689 official ARM ELF extended ABI. Hence they are only decoded if
3690 the EABI version is not set. */
3691 if (flags
& EF_ARM_INTERWORK
)
3692 fprintf (file
, _(" [interworking enabled]"));
3694 if (flags
& EF_ARM_APCS_26
)
3695 fprintf (file
, " [APCS-26]");
3697 fprintf (file
, " [APCS-32]");
3699 if (flags
& EF_ARM_VFP_FLOAT
)
3700 fprintf (file
, _(" [VFP float format]"));
3701 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
3702 fprintf (file
, _(" [Maverick float format]"));
3704 fprintf (file
, _(" [FPA float format]"));
3706 if (flags
& EF_ARM_APCS_FLOAT
)
3707 fprintf (file
, _(" [floats passed in float registers]"));
3709 if (flags
& EF_ARM_PIC
)
3710 fprintf (file
, _(" [position independent]"));
3712 if (flags
& EF_ARM_NEW_ABI
)
3713 fprintf (file
, _(" [new ABI]"));
3715 if (flags
& EF_ARM_OLD_ABI
)
3716 fprintf (file
, _(" [old ABI]"));
3718 if (flags
& EF_ARM_SOFT_FLOAT
)
3719 fprintf (file
, _(" [software FP]"));
3721 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
3722 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
3723 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
3724 | EF_ARM_MAVERICK_FLOAT
);
3727 case EF_ARM_EABI_VER1
:
3728 fprintf (file
, _(" [Version1 EABI]"));
3730 if (flags
& EF_ARM_SYMSARESORTED
)
3731 fprintf (file
, _(" [sorted symbol table]"));
3733 fprintf (file
, _(" [unsorted symbol table]"));
3735 flags
&= ~ EF_ARM_SYMSARESORTED
;
3738 case EF_ARM_EABI_VER2
:
3739 fprintf (file
, _(" [Version2 EABI]"));
3741 if (flags
& EF_ARM_SYMSARESORTED
)
3742 fprintf (file
, _(" [sorted symbol table]"));
3744 fprintf (file
, _(" [unsorted symbol table]"));
3746 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
3747 fprintf (file
, _(" [dynamic symbols use segment index]"));
3749 if (flags
& EF_ARM_MAPSYMSFIRST
)
3750 fprintf (file
, _(" [mapping symbols precede others]"));
3752 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
3753 | EF_ARM_MAPSYMSFIRST
);
3756 case EF_ARM_EABI_VER3
:
3757 fprintf (file
, _(" [Version3 EABI]"));
3760 case EF_ARM_EABI_VER4
:
3761 fprintf (file
, _(" [Version4 EABI]"));
3763 if (flags
& EF_ARM_BE8
)
3764 fprintf (file
, _(" [BE8]"));
3766 if (flags
& EF_ARM_LE8
)
3767 fprintf (file
, _(" [LE8]"));
3769 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
3773 fprintf (file
, _(" <EABI version unrecognised>"));
3777 flags
&= ~ EF_ARM_EABIMASK
;
3779 if (flags
& EF_ARM_RELEXEC
)
3780 fprintf (file
, _(" [relocatable executable]"));
3782 if (flags
& EF_ARM_HASENTRY
)
3783 fprintf (file
, _(" [has entry point]"));
3785 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
3788 fprintf (file
, _("<Unrecognised flag bits set>"));
3796 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
3798 switch (ELF_ST_TYPE (elf_sym
->st_info
))
3801 return ELF_ST_TYPE (elf_sym
->st_info
);
3804 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
3805 This allows us to distinguish between data used by Thumb instructions
3806 and non-data (which is probably code) inside Thumb regions of an
3808 if (type
!= STT_OBJECT
)
3809 return ELF_ST_TYPE (elf_sym
->st_info
);
3820 elf32_arm_gc_mark_hook (asection
* sec
,
3821 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
3822 Elf_Internal_Rela
* rel
,
3823 struct elf_link_hash_entry
* h
,
3824 Elf_Internal_Sym
* sym
)
3828 switch (ELF32_R_TYPE (rel
->r_info
))
3830 case R_ARM_GNU_VTINHERIT
:
3831 case R_ARM_GNU_VTENTRY
:
3835 switch (h
->root
.type
)
3837 case bfd_link_hash_defined
:
3838 case bfd_link_hash_defweak
:
3839 return h
->root
.u
.def
.section
;
3841 case bfd_link_hash_common
:
3842 return h
->root
.u
.c
.p
->section
;
3850 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3855 /* Update the got entry reference counts for the section being removed. */
3858 elf32_arm_gc_sweep_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
3859 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
3860 asection
* sec ATTRIBUTE_UNUSED
,
3861 const Elf_Internal_Rela
* relocs ATTRIBUTE_UNUSED
)
3863 Elf_Internal_Shdr
*symtab_hdr
;
3864 struct elf_link_hash_entry
**sym_hashes
;
3865 bfd_signed_vma
*local_got_refcounts
;
3866 const Elf_Internal_Rela
*rel
, *relend
;
3867 struct elf32_arm_link_hash_table
* globals
;
3869 globals
= elf32_arm_hash_table (info
);
3871 elf_section_data (sec
)->local_dynrel
= NULL
;
3873 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3874 sym_hashes
= elf_sym_hashes (abfd
);
3875 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3877 relend
= relocs
+ sec
->reloc_count
;
3878 for (rel
= relocs
; rel
< relend
; rel
++)
3880 unsigned long r_symndx
;
3881 struct elf_link_hash_entry
*h
= NULL
;
3884 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3885 if (r_symndx
>= symtab_hdr
->sh_info
)
3887 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3888 while (h
->root
.type
== bfd_link_hash_indirect
3889 || h
->root
.type
== bfd_link_hash_warning
)
3890 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3893 r_type
= ELF32_R_TYPE (rel
->r_info
);
3895 r_type
= arm_real_reloc_type (globals
, r_type
);
3901 case R_ARM_GOT_PREL
:
3905 if (h
->got
.refcount
> 0)
3906 h
->got
.refcount
-= 1;
3908 else if (local_got_refcounts
!= NULL
)
3910 if (local_got_refcounts
[r_symndx
] > 0)
3911 local_got_refcounts
[r_symndx
] -= 1;
3924 case R_ARM_THM_PC22
:
3925 /* Should the interworking branches be here also? */
3929 struct elf32_arm_link_hash_entry
*eh
;
3930 struct elf32_arm_relocs_copied
**pp
;
3931 struct elf32_arm_relocs_copied
*p
;
3933 eh
= (struct elf32_arm_link_hash_entry
*) h
;
3935 if (h
->plt
.refcount
> 0)
3937 h
->plt
.refcount
-= 1;
3938 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_THM_PC22
)
3939 eh
->plt_thumb_refcount
--;
3942 if (r_type
== R_ARM_ABS32
3943 || r_type
== R_ARM_REL32
)
3945 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
3947 if (p
->section
== sec
)
3966 /* Look through the relocs for a section during the first phase. */
3969 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
3970 asection
*sec
, const Elf_Internal_Rela
*relocs
)
3972 Elf_Internal_Shdr
*symtab_hdr
;
3973 struct elf_link_hash_entry
**sym_hashes
;
3974 struct elf_link_hash_entry
**sym_hashes_end
;
3975 const Elf_Internal_Rela
*rel
;
3976 const Elf_Internal_Rela
*rel_end
;
3979 bfd_vma
*local_got_offsets
;
3980 struct elf32_arm_link_hash_table
*htab
;
3982 if (info
->relocatable
)
3985 htab
= elf32_arm_hash_table (info
);
3988 dynobj
= elf_hash_table (info
)->dynobj
;
3989 local_got_offsets
= elf_local_got_offsets (abfd
);
3991 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3992 sym_hashes
= elf_sym_hashes (abfd
);
3993 sym_hashes_end
= sym_hashes
3994 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
3996 if (!elf_bad_symtab (abfd
))
3997 sym_hashes_end
-= symtab_hdr
->sh_info
;
3999 rel_end
= relocs
+ sec
->reloc_count
;
4000 for (rel
= relocs
; rel
< rel_end
; rel
++)
4002 struct elf_link_hash_entry
*h
;
4003 struct elf32_arm_link_hash_entry
*eh
;
4004 unsigned long r_symndx
;
4007 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4008 r_type
= ELF32_R_TYPE (rel
->r_info
);
4010 r_type
= arm_real_reloc_type (htab
, r_type
);
4012 if (r_symndx
< symtab_hdr
->sh_info
)
4015 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4017 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4023 case R_ARM_GOT_PREL
:
4025 /* This symbol requires a global offset table entry. */
4032 bfd_signed_vma
*local_got_refcounts
;
4034 /* This is a global offset table entry for a local symbol. */
4035 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4036 if (local_got_refcounts
== NULL
)
4040 size
= symtab_hdr
->sh_info
;
4041 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
4042 local_got_refcounts
= bfd_zalloc (abfd
, size
);
4043 if (local_got_refcounts
== NULL
)
4045 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
4047 local_got_refcounts
[r_symndx
] += 1;
4049 if (r_type
== R_ARM_GOT32
)
4055 if (htab
->sgot
== NULL
)
4057 if (htab
->root
.dynobj
== NULL
)
4058 htab
->root
.dynobj
= abfd
;
4059 if (!create_got_section (htab
->root
.dynobj
, info
))
4073 case R_ARM_THM_PC22
:
4074 /* Should the interworking branches be listed here? */
4077 /* If this reloc is in a read-only section, we might
4078 need a copy reloc. We can't check reliably at this
4079 stage whether the section is read-only, as input
4080 sections have not yet been mapped to output sections.
4081 Tentatively set the flag for now, and correct in
4082 adjust_dynamic_symbol. */
4086 /* We may need a .plt entry if the function this reloc
4087 refers to is in a different object. We can't tell for
4088 sure yet, because something later might force the
4090 if (r_type
== R_ARM_PC24
4092 || r_type
== R_ARM_CALL
4093 || r_type
== R_ARM_JUMP24
4094 || r_type
== R_ARM_PREL31
4096 || r_type
== R_ARM_PLT32
4097 || r_type
== R_ARM_THM_PC22
)
4100 /* If we create a PLT entry, this relocation will reference
4101 it, even if it's an ABS32 relocation. */
4102 h
->plt
.refcount
+= 1;
4104 if (r_type
== R_ARM_THM_PC22
)
4105 eh
->plt_thumb_refcount
+= 1;
4108 /* If we are creating a shared library, and this is a reloc
4109 against a global symbol, or a non PC relative reloc
4110 against a local symbol, then we need to copy the reloc
4111 into the shared library. However, if we are linking with
4112 -Bsymbolic, we do not need to copy a reloc against a
4113 global symbol which is defined in an object we are
4114 including in the link (i.e., DEF_REGULAR is set). At
4115 this point we have not seen all the input files, so it is
4116 possible that DEF_REGULAR is not set now but will be set
4117 later (it is never cleared). We account for that
4118 possibility below by storing information in the
4119 relocs_copied field of the hash table entry. */
4121 && (sec
->flags
& SEC_ALLOC
) != 0
4122 && ((r_type
!= R_ARM_PC24
4123 && r_type
!= R_ARM_PLT32
4125 && r_type
!= R_ARM_CALL
4126 && r_type
!= R_ARM_JUMP24
4127 && r_type
!= R_ARM_PREL31
4129 && r_type
!= R_ARM_REL32
4130 && r_type
!= R_ARM_THM_PC22
)
4132 && (! info
->symbolic
4133 || !h
->def_regular
))))
4135 struct elf32_arm_relocs_copied
*p
, **head
;
4137 /* When creating a shared object, we must copy these
4138 reloc types into the output file. We create a reloc
4139 section in dynobj and make room for this reloc. */
4144 name
= (bfd_elf_string_from_elf_section
4146 elf_elfheader (abfd
)->e_shstrndx
,
4147 elf_section_data (sec
)->rel_hdr
.sh_name
));
4151 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
4152 && strcmp (bfd_get_section_name (abfd
, sec
),
4155 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4160 sreloc
= bfd_make_section (dynobj
, name
);
4161 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4162 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4163 if ((sec
->flags
& SEC_ALLOC
) != 0
4164 /* BPABI objects never have dynamic
4165 relocations mapped. */
4166 && !htab
->symbian_p
)
4167 flags
|= SEC_ALLOC
| SEC_LOAD
;
4169 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
4170 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
4174 elf_section_data (sec
)->sreloc
= sreloc
;
4177 /* If this is a global symbol, we count the number of
4178 relocations we need for this symbol. */
4181 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
4185 /* Track dynamic relocs needed for local syms too.
4186 We really need local syms available to do this
4190 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4195 head
= ((struct elf32_arm_relocs_copied
**)
4196 &elf_section_data (s
)->local_dynrel
);
4200 if (p
== NULL
|| p
->section
!= sec
)
4202 bfd_size_type amt
= sizeof *p
;
4204 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
4213 if (r_type
== R_ARM_ABS32
4214 || r_type
== R_ARM_REL32
)
4219 /* This relocation describes the C++ object vtable hierarchy.
4220 Reconstruct it for later use during GC. */
4221 case R_ARM_GNU_VTINHERIT
:
4222 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4226 /* This relocation describes which C++ vtable entries are actually
4227 used. Record for later use during GC. */
4228 case R_ARM_GNU_VTENTRY
:
4229 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4239 is_arm_mapping_symbol_name (const char * name
)
4241 return (name
!= NULL
)
4243 && ((name
[1] == 'a') || (name
[1] == 't') || (name
[1] == 'd'))
4247 /* Treat mapping symbols as special target symbols. */
4250 elf32_arm_is_target_special_symbol (bfd
* abfd ATTRIBUTE_UNUSED
, asymbol
* sym
)
4252 return is_arm_mapping_symbol_name (sym
->name
);
4255 /* This is a copy of elf_find_function() from elf.c except that
4256 ARM mapping symbols are ignored when looking for function names
4257 and STT_ARM_TFUNC is considered to a function type. */
4260 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
4264 const char ** filename_ptr
,
4265 const char ** functionname_ptr
)
4267 const char * filename
= NULL
;
4268 asymbol
* func
= NULL
;
4269 bfd_vma low_func
= 0;
4272 for (p
= symbols
; *p
!= NULL
; p
++)
4276 q
= (elf_symbol_type
*) *p
;
4278 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
4283 filename
= bfd_asymbol_name (&q
->symbol
);
4287 /* Skip $a and $t symbols. */
4288 if ((q
->symbol
.flags
& BSF_LOCAL
)
4289 && is_arm_mapping_symbol_name (q
->symbol
.name
))
4293 if (bfd_get_section (&q
->symbol
) == section
4294 && q
->symbol
.value
>= low_func
4295 && q
->symbol
.value
<= offset
)
4297 func
= (asymbol
*) q
;
4298 low_func
= q
->symbol
.value
;
4308 *filename_ptr
= filename
;
4309 if (functionname_ptr
)
4310 *functionname_ptr
= bfd_asymbol_name (func
);
4316 /* Find the nearest line to a particular section and offset, for error
4317 reporting. This code is a duplicate of the code in elf.c, except
4318 that it uses arm_elf_find_function. */
4321 elf32_arm_find_nearest_line (bfd
* abfd
,
4325 const char ** filename_ptr
,
4326 const char ** functionname_ptr
,
4327 unsigned int * line_ptr
)
4329 bfd_boolean found
= FALSE
;
4331 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
4333 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
4334 filename_ptr
, functionname_ptr
,
4336 & elf_tdata (abfd
)->dwarf2_find_line_info
))
4338 if (!*functionname_ptr
)
4339 arm_elf_find_function (abfd
, section
, symbols
, offset
,
4340 *filename_ptr
? NULL
: filename_ptr
,
4346 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
4347 & found
, filename_ptr
,
4348 functionname_ptr
, line_ptr
,
4349 & elf_tdata (abfd
)->line_info
))
4352 if (found
&& (*functionname_ptr
|| *line_ptr
))
4355 if (symbols
== NULL
)
4358 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
4359 filename_ptr
, functionname_ptr
))
4366 /* Adjust a symbol defined by a dynamic object and referenced by a
4367 regular object. The current definition is in some section of the
4368 dynamic object, but we're not including those sections. We have to
4369 change the definition to something the rest of the link can
4373 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
4374 struct elf_link_hash_entry
* h
)
4378 unsigned int power_of_two
;
4379 struct elf32_arm_link_hash_entry
* eh
;
4381 dynobj
= elf_hash_table (info
)->dynobj
;
4383 /* Make sure we know what is going on here. */
4384 BFD_ASSERT (dynobj
!= NULL
4386 || h
->u
.weakdef
!= NULL
4389 && !h
->def_regular
)));
4391 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4393 /* If this is a function, put it in the procedure linkage table. We
4394 will fill in the contents of the procedure linkage table later,
4395 when we know the address of the .got section. */
4396 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
4399 if (h
->plt
.refcount
<= 0
4400 || SYMBOL_CALLS_LOCAL (info
, h
)
4401 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4402 && h
->root
.type
== bfd_link_hash_undefweak
))
4404 /* This case can occur if we saw a PLT32 reloc in an input
4405 file, but the symbol was never referred to by a dynamic
4406 object, or if all references were garbage collected. In
4407 such a case, we don't actually need to build a procedure
4408 linkage table, and we can just do a PC24 reloc instead. */
4409 h
->plt
.offset
= (bfd_vma
) -1;
4410 eh
->plt_thumb_refcount
= 0;
4418 /* It's possible that we incorrectly decided a .plt reloc was
4419 needed for an R_ARM_PC24 or similar reloc to a non-function sym
4420 in check_relocs. We can't decide accurately between function
4421 and non-function syms in check-relocs; Objects loaded later in
4422 the link may change h->type. So fix it now. */
4423 h
->plt
.offset
= (bfd_vma
) -1;
4424 eh
->plt_thumb_refcount
= 0;
4427 /* If this is a weak symbol, and there is a real definition, the
4428 processor independent code will have arranged for us to see the
4429 real definition first, and we can just use the same value. */
4430 if (h
->u
.weakdef
!= NULL
)
4432 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
4433 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
4434 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
4435 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
4439 /* This is a reference to a symbol defined by a dynamic object which
4440 is not a function. */
4442 /* If we are creating a shared library, we must presume that the
4443 only references to the symbol are via the global offset table.
4444 For such cases we need not do anything here; the relocations will
4445 be handled correctly by relocate_section. */
4449 /* We must allocate the symbol in our .dynbss section, which will
4450 become part of the .bss section of the executable. There will be
4451 an entry for this symbol in the .dynsym section. The dynamic
4452 object will contain position independent code, so all references
4453 from the dynamic object to this symbol will go through the global
4454 offset table. The dynamic linker will use the .dynsym entry to
4455 determine the address it must put in the global offset table, so
4456 both the dynamic object and the regular object will refer to the
4457 same memory location for the variable. */
4458 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
4459 BFD_ASSERT (s
!= NULL
);
4461 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
4462 copy the initial value out of the dynamic object and into the
4463 runtime process image. We need to remember the offset into the
4464 .rel.bss section we are going to use. */
4465 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4469 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
4470 BFD_ASSERT (srel
!= NULL
);
4471 srel
->size
+= sizeof (Elf32_External_Rel
);
4475 /* We need to figure out the alignment required for this symbol. I
4476 have no idea how ELF linkers handle this. */
4477 power_of_two
= bfd_log2 (h
->size
);
4478 if (power_of_two
> 3)
4481 /* Apply the required alignment. */
4482 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
4483 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
4485 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
4489 /* Define the symbol as being at this point in the section. */
4490 h
->root
.u
.def
.section
= s
;
4491 h
->root
.u
.def
.value
= s
->size
;
4493 /* Increment the section size to make room for the symbol. */
4499 /* Allocate space in .plt, .got and associated reloc sections for
4503 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
4505 struct bfd_link_info
*info
;
4506 struct elf32_arm_link_hash_table
*htab
;
4507 struct elf32_arm_link_hash_entry
*eh
;
4508 struct elf32_arm_relocs_copied
*p
;
4510 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4512 if (h
->root
.type
== bfd_link_hash_indirect
)
4515 if (h
->root
.type
== bfd_link_hash_warning
)
4516 /* When warning symbols are created, they **replace** the "real"
4517 entry in the hash table, thus we never get to see the real
4518 symbol in a hash traversal. So look at it now. */
4519 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4521 info
= (struct bfd_link_info
*) inf
;
4522 htab
= elf32_arm_hash_table (info
);
4524 if (htab
->root
.dynamic_sections_created
4525 && h
->plt
.refcount
> 0)
4527 /* Make sure this symbol is output as a dynamic symbol.
4528 Undefined weak syms won't yet be marked as dynamic. */
4529 if (h
->dynindx
== -1
4530 && !h
->forced_local
)
4532 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4537 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
4539 asection
*s
= htab
->splt
;
4541 /* If this is the first .plt entry, make room for the special
4544 s
->size
+= htab
->plt_header_size
;
4546 h
->plt
.offset
= s
->size
;
4548 /* If we will insert a Thumb trampoline before this PLT, leave room
4550 if (!htab
->symbian_p
&& eh
->plt_thumb_refcount
> 0)
4552 h
->plt
.offset
+= PLT_THUMB_STUB_SIZE
;
4553 s
->size
+= PLT_THUMB_STUB_SIZE
;
4556 /* If this symbol is not defined in a regular file, and we are
4557 not generating a shared library, then set the symbol to this
4558 location in the .plt. This is required to make function
4559 pointers compare as equal between the normal executable and
4560 the shared library. */
4564 h
->root
.u
.def
.section
= s
;
4565 h
->root
.u
.def
.value
= h
->plt
.offset
;
4567 /* Make sure the function is not marked as Thumb, in case
4568 it is the target of an ABS32 relocation, which will
4569 point to the PLT entry. */
4570 if (ELF_ST_TYPE (h
->type
) == STT_ARM_TFUNC
)
4571 h
->type
= ELF_ST_INFO (ELF_ST_BIND (h
->type
), STT_FUNC
);
4574 /* Make room for this entry. */
4575 s
->size
+= htab
->plt_entry_size
;
4577 if (!htab
->symbian_p
)
4579 /* We also need to make an entry in the .got.plt section, which
4580 will be placed in the .got section by the linker script. */
4581 eh
->plt_got_offset
= htab
->sgotplt
->size
;
4582 htab
->sgotplt
->size
+= 4;
4585 /* We also need to make an entry in the .rel.plt section. */
4586 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
4590 h
->plt
.offset
= (bfd_vma
) -1;
4596 h
->plt
.offset
= (bfd_vma
) -1;
4600 if (h
->got
.refcount
> 0)
4605 /* Make sure this symbol is output as a dynamic symbol.
4606 Undefined weak syms won't yet be marked as dynamic. */
4607 if (h
->dynindx
== -1
4608 && !h
->forced_local
)
4610 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4614 if (!htab
->symbian_p
)
4617 h
->got
.offset
= s
->size
;
4619 dyn
= htab
->root
.dynamic_sections_created
;
4620 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4621 || h
->root
.type
!= bfd_link_hash_undefweak
)
4623 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
4624 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
4628 h
->got
.offset
= (bfd_vma
) -1;
4630 if (eh
->relocs_copied
== NULL
)
4633 /* In the shared -Bsymbolic case, discard space allocated for
4634 dynamic pc-relative relocs against symbols which turn out to be
4635 defined in regular objects. For the normal shared case, discard
4636 space for pc-relative relocs that have become local due to symbol
4637 visibility changes. */
4641 /* Discard relocs on undefined weak syms with non-default
4643 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4644 && h
->root
.type
== bfd_link_hash_undefweak
)
4645 eh
->relocs_copied
= NULL
;
4649 /* For the non-shared case, discard space for relocs against
4650 symbols which turn out to need copy relocs or are not
4656 || (htab
->root
.dynamic_sections_created
4657 && (h
->root
.type
== bfd_link_hash_undefweak
4658 || h
->root
.type
== bfd_link_hash_undefined
))))
4660 /* Make sure this symbol is output as a dynamic symbol.
4661 Undefined weak syms won't yet be marked as dynamic. */
4662 if (h
->dynindx
== -1
4663 && !h
->forced_local
)
4665 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4669 /* If that succeeded, we know we'll be keeping all the
4671 if (h
->dynindx
!= -1)
4675 eh
->relocs_copied
= NULL
;
4680 /* Finally, allocate space. */
4681 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
4683 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
4684 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
4690 /* Find any dynamic relocs that apply to read-only sections. */
4693 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry
*h
, PTR inf
)
4695 struct elf32_arm_link_hash_entry
*eh
;
4696 struct elf32_arm_relocs_copied
*p
;
4698 if (h
->root
.type
== bfd_link_hash_warning
)
4699 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4701 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4702 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
4704 asection
*s
= p
->section
;
4706 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4708 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4710 info
->flags
|= DF_TEXTREL
;
4712 /* Not an error, just cut short the traversal. */
4719 /* Set the sizes of the dynamic sections. */
4722 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
4723 struct bfd_link_info
* info
)
4730 struct elf32_arm_link_hash_table
*htab
;
4732 htab
= elf32_arm_hash_table (info
);
4733 dynobj
= elf_hash_table (info
)->dynobj
;
4734 BFD_ASSERT (dynobj
!= NULL
);
4736 if (elf_hash_table (info
)->dynamic_sections_created
)
4738 /* Set the contents of the .interp section to the interpreter. */
4739 if (info
->executable
)
4741 s
= bfd_get_section_by_name (dynobj
, ".interp");
4742 BFD_ASSERT (s
!= NULL
);
4743 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4744 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4748 /* Set up .got offsets for local syms, and space for local dynamic
4750 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4752 bfd_signed_vma
*local_got
;
4753 bfd_signed_vma
*end_local_got
;
4754 char *local_tls_type
;
4755 bfd_size_type locsymcount
;
4756 Elf_Internal_Shdr
*symtab_hdr
;
4759 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4762 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4764 struct elf32_arm_relocs_copied
*p
;
4766 for (p
= *((struct elf32_arm_relocs_copied
**)
4767 &elf_section_data (s
)->local_dynrel
);
4771 if (!bfd_is_abs_section (p
->section
)
4772 && bfd_is_abs_section (p
->section
->output_section
))
4774 /* Input section has been discarded, either because
4775 it is a copy of a linkonce section or due to
4776 linker script /DISCARD/, so we'll be discarding
4779 else if (p
->count
!= 0)
4781 srel
= elf_section_data (p
->section
)->sreloc
;
4782 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
4783 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
4784 info
->flags
|= DF_TEXTREL
;
4789 local_got
= elf_local_got_refcounts (ibfd
);
4793 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4794 locsymcount
= symtab_hdr
->sh_info
;
4795 end_local_got
= local_got
+ locsymcount
;
4797 srel
= htab
->srelgot
;
4798 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
4802 *local_got
= s
->size
;
4805 srel
->size
+= sizeof (Elf32_External_Rel
);
4808 *local_got
= (bfd_vma
) -1;
4812 /* Allocate global sym .plt and .got entries, and space for global
4813 sym dynamic relocs. */
4814 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
4816 /* The check_relocs and adjust_dynamic_symbol entry points have
4817 determined the sizes of the various dynamic sections. Allocate
4821 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4826 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4829 /* It's OK to base decisions on the section name, because none
4830 of the dynobj section names depend upon the input files. */
4831 name
= bfd_get_section_name (dynobj
, s
);
4835 if (strcmp (name
, ".plt") == 0)
4839 /* Strip this section if we don't need it; see the
4845 /* Remember whether there is a PLT. */
4849 else if (strncmp (name
, ".rel", 4) == 0)
4853 /* If we don't need this section, strip it from the
4854 output file. This is mostly to handle .rel.bss and
4855 .rel.plt. We must create both sections in
4856 create_dynamic_sections, because they must be created
4857 before the linker maps input sections to output
4858 sections. The linker does that before
4859 adjust_dynamic_symbol is called, and it is that
4860 function which decides whether anything needs to go
4861 into these sections. */
4866 /* Remember whether there are any reloc sections other
4868 if (strcmp (name
, ".rel.plt") != 0)
4871 /* We use the reloc_count field as a counter if we need
4872 to copy relocs into the output file. */
4876 else if (strncmp (name
, ".got", 4) != 0)
4878 /* It's not one of our sections, so don't allocate space. */
4884 _bfd_strip_section_from_output (info
, s
);
4888 /* Allocate memory for the section contents. */
4889 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4890 if (s
->contents
== NULL
&& s
->size
!= 0)
4894 if (elf_hash_table (info
)->dynamic_sections_created
)
4896 /* Add some entries to the .dynamic section. We fill in the
4897 values later, in elf32_arm_finish_dynamic_sections, but we
4898 must add the entries now so that we get the correct size for
4899 the .dynamic section. The DT_DEBUG entry is filled in by the
4900 dynamic linker and used by the debugger. */
4901 #define add_dynamic_entry(TAG, VAL) \
4902 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4906 if (!add_dynamic_entry (DT_DEBUG
, 0))
4912 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
4913 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4914 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
4915 || !add_dynamic_entry (DT_JMPREL
, 0))
4921 if ( !add_dynamic_entry (DT_REL
, 0)
4922 || !add_dynamic_entry (DT_RELSZ
, 0)
4923 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
4927 /* If any dynamic relocs apply to a read-only section,
4928 then we need a DT_TEXTREL entry. */
4929 if ((info
->flags
& DF_TEXTREL
) == 0)
4930 elf_link_hash_traverse (&htab
->root
, elf32_arm_readonly_dynrelocs
,
4933 if ((info
->flags
& DF_TEXTREL
) != 0)
4935 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4937 info
->flags
|= DF_TEXTREL
;
4940 #undef add_synamic_entry
4945 /* Finish up dynamic symbol handling. We set the contents of various
4946 dynamic sections here. */
4949 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
4950 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
4953 struct elf32_arm_link_hash_table
*htab
;
4954 struct elf32_arm_link_hash_entry
*eh
;
4956 dynobj
= elf_hash_table (info
)->dynobj
;
4957 htab
= elf32_arm_hash_table (info
);
4958 eh
= (struct elf32_arm_link_hash_entry
*) h
;
4960 if (h
->plt
.offset
!= (bfd_vma
) -1)
4966 Elf_Internal_Rela rel
;
4968 /* This symbol has an entry in the procedure linkage table. Set
4971 BFD_ASSERT (h
->dynindx
!= -1);
4973 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4974 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
4975 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
4977 /* Fill in the entry in the procedure linkage table. */
4978 if (htab
->symbian_p
)
4981 for (i
= 0; i
< htab
->plt_entry_size
/ 4; ++i
)
4982 bfd_put_32 (output_bfd
,
4983 elf32_arm_symbian_plt_entry
[i
],
4984 splt
->contents
+ h
->plt
.offset
+ 4 * i
);
4986 /* Fill in the entry in the .rel.plt section. */
4987 rel
.r_offset
= (splt
->output_section
->vma
4988 + splt
->output_offset
4989 + h
->plt
.offset
+ 4 * (i
- 1));
4990 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
4992 /* Get the index in the procedure linkage table which
4993 corresponds to this symbol. This is the index of this symbol
4994 in all the symbols for which we are making plt entries. The
4995 first entry in the procedure linkage table is reserved. */
4996 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
4997 / htab
->plt_entry_size
);
5002 bfd_vma got_displacement
;
5005 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
5006 BFD_ASSERT (sgot
!= NULL
);
5008 /* Get the offset into the .got.plt table of the entry that
5009 corresponds to this function. */
5010 got_offset
= eh
->plt_got_offset
;
5012 /* Get the index in the procedure linkage table which
5013 corresponds to this symbol. This is the index of this symbol
5014 in all the symbols for which we are making plt entries. The
5015 first three entries in .got.plt are reserved; after that
5016 symbols appear in the same order as in .plt. */
5017 plt_index
= (got_offset
- 12) / 4;
5019 /* Calculate the displacement between the PLT slot and the
5020 entry in the GOT. The eight-byte offset accounts for the
5021 value produced by adding to pc in the first instruction
5023 got_displacement
= (sgot
->output_section
->vma
5024 + sgot
->output_offset
5026 - splt
->output_section
->vma
5027 - splt
->output_offset
5031 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
5033 if (eh
->plt_thumb_refcount
> 0)
5035 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[0],
5036 splt
->contents
+ h
->plt
.offset
- 4);
5037 bfd_put_16 (output_bfd
, elf32_arm_plt_thumb_stub
[1],
5038 splt
->contents
+ h
->plt
.offset
- 2);
5041 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
5042 splt
->contents
+ h
->plt
.offset
+ 0);
5043 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
5044 splt
->contents
+ h
->plt
.offset
+ 4);
5045 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
5046 splt
->contents
+ h
->plt
.offset
+ 8);
5047 #ifdef FOUR_WORD_PLT
5048 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
5049 splt
->contents
+ h
->plt
.offset
+ 12);
5052 /* Fill in the entry in the global offset table. */
5053 bfd_put_32 (output_bfd
,
5054 (splt
->output_section
->vma
5055 + splt
->output_offset
),
5056 sgot
->contents
+ got_offset
);
5058 /* Fill in the entry in the .rel.plt section. */
5059 rel
.r_offset
= (sgot
->output_section
->vma
5060 + sgot
->output_offset
5062 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
5065 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
5066 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5068 if (!h
->def_regular
)
5070 /* Mark the symbol as undefined, rather than as defined in
5071 the .plt section. Leave the value alone. */
5072 sym
->st_shndx
= SHN_UNDEF
;
5073 /* If the symbol is weak, we do need to clear the value.
5074 Otherwise, the PLT entry would provide a definition for
5075 the symbol even if the symbol wasn't defined anywhere,
5076 and so the symbol would never be NULL. */
5077 if (!h
->ref_regular_nonweak
)
5082 if (h
->got
.offset
!= (bfd_vma
) -1)
5086 Elf_Internal_Rela rel
;
5089 /* This symbol has an entry in the global offset table. Set it
5091 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5092 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
5093 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
5095 rel
.r_offset
= (sgot
->output_section
->vma
5096 + sgot
->output_offset
5097 + (h
->got
.offset
&~ (bfd_vma
) 1));
5099 /* If this is a static link, or it is a -Bsymbolic link and the
5100 symbol is defined locally or was forced to be local because
5101 of a version file, we just want to emit a RELATIVE reloc.
5102 The entry in the global offset table will already have been
5103 initialized in the relocate_section function. */
5105 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5107 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5108 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
5112 BFD_ASSERT((h
->got
.offset
& 1) == 0);
5113 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
5114 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
5117 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
5118 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5124 Elf_Internal_Rela rel
;
5127 /* This symbol needs a copy reloc. Set it up. */
5128 BFD_ASSERT (h
->dynindx
!= -1
5129 && (h
->root
.type
== bfd_link_hash_defined
5130 || h
->root
.type
== bfd_link_hash_defweak
));
5132 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
5134 BFD_ASSERT (s
!= NULL
);
5136 rel
.r_offset
= (h
->root
.u
.def
.value
5137 + h
->root
.u
.def
.section
->output_section
->vma
5138 + h
->root
.u
.def
.section
->output_offset
);
5139 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
5140 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
5141 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
5144 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5145 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5146 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5147 sym
->st_shndx
= SHN_ABS
;
5152 /* Finish up the dynamic sections. */
5155 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
5161 dynobj
= elf_hash_table (info
)->dynobj
;
5163 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
5164 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
5165 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5167 if (elf_hash_table (info
)->dynamic_sections_created
)
5170 Elf32_External_Dyn
*dyncon
, *dynconend
;
5171 struct elf32_arm_link_hash_table
*htab
;
5173 htab
= elf32_arm_hash_table (info
);
5174 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5175 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
5177 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5178 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5180 for (; dyncon
< dynconend
; dyncon
++)
5182 Elf_Internal_Dyn dyn
;
5186 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5197 goto get_vma_if_bpabi
;
5200 goto get_vma_if_bpabi
;
5203 goto get_vma_if_bpabi
;
5205 name
= ".gnu.version";
5206 goto get_vma_if_bpabi
;
5208 name
= ".gnu.version_d";
5209 goto get_vma_if_bpabi
;
5211 name
= ".gnu.version_r";
5212 goto get_vma_if_bpabi
;
5220 s
= bfd_get_section_by_name (output_bfd
, name
);
5221 BFD_ASSERT (s
!= NULL
);
5222 if (!htab
->symbian_p
)
5223 dyn
.d_un
.d_ptr
= s
->vma
;
5225 /* In the BPABI, tags in the PT_DYNAMIC section point
5226 at the file offset, not the memory address, for the
5227 convenience of the post linker. */
5228 dyn
.d_un
.d_ptr
= s
->filepos
;
5229 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5233 if (htab
->symbian_p
)
5238 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
5239 BFD_ASSERT (s
!= NULL
);
5240 dyn
.d_un
.d_val
= s
->size
;
5241 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5245 if (!htab
->symbian_p
)
5247 /* My reading of the SVR4 ABI indicates that the
5248 procedure linkage table relocs (DT_JMPREL) should be
5249 included in the overall relocs (DT_REL). This is
5250 what Solaris does. However, UnixWare can not handle
5251 that case. Therefore, we override the DT_RELSZ entry
5252 here to make it not include the JMPREL relocs. Since
5253 the linker script arranges for .rel.plt to follow all
5254 other relocation sections, we don't have to worry
5255 about changing the DT_REL entry. */
5256 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
5258 dyn
.d_un
.d_val
-= s
->size
;
5259 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5267 /* In the BPABI, the DT_REL tag must point at the file
5268 offset, not the VMA, of the first relocation
5269 section. So, we use code similar to that in
5270 elflink.c, but do not check for SHF_ALLOC on the
5271 relcoation section, since relocations sections are
5272 never allocated under the BPABI. The comments above
5273 about Unixware notwithstanding, we include all of the
5274 relocations here. */
5275 if (htab
->symbian_p
)
5278 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
5279 ? SHT_REL
: SHT_RELA
);
5281 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
5283 Elf_Internal_Shdr
*hdr
5284 = elf_elfsections (output_bfd
)[i
];
5285 if (hdr
->sh_type
== type
)
5287 if (dyn
.d_tag
== DT_RELSZ
5288 || dyn
.d_tag
== DT_RELASZ
)
5289 dyn
.d_un
.d_val
+= hdr
->sh_size
;
5290 else if ((ufile_ptr
) hdr
->sh_offset
5291 <= dyn
.d_un
.d_val
- 1)
5292 dyn
.d_un
.d_val
= hdr
->sh_offset
;
5295 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5299 /* Set the bottom bit of DT_INIT/FINI if the
5300 corresponding function is Thumb. */
5302 name
= info
->init_function
;
5305 name
= info
->fini_function
;
5307 /* If it wasn't set by elf_bfd_final_link
5308 then there is nothing to adjust. */
5309 if (dyn
.d_un
.d_val
!= 0)
5311 struct elf_link_hash_entry
* eh
;
5313 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
5314 FALSE
, FALSE
, TRUE
);
5315 if (eh
!= (struct elf_link_hash_entry
*) NULL
5316 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
5318 dyn
.d_un
.d_val
|= 1;
5319 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5326 /* Fill in the first entry in the procedure linkage table. */
5327 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
5329 bfd_vma got_displacement
;
5331 /* Calculate the displacement between the PLT slot and &GOT[0]. */
5332 got_displacement
= (sgot
->output_section
->vma
5333 + sgot
->output_offset
5334 - splt
->output_section
->vma
5335 - splt
->output_offset
5338 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
5339 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
5340 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
5341 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
5342 #ifdef FOUR_WORD_PLT
5343 /* The displacement value goes in the otherwise-unused last word of
5344 the second entry. */
5345 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
5347 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
5351 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5352 really seem like the right value. */
5353 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
5356 /* Fill in the first three entries in the global offset table. */
5362 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5364 bfd_put_32 (output_bfd
,
5365 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5367 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
5368 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
5371 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5378 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
5380 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5381 struct elf32_arm_link_hash_table
*globals
;
5383 i_ehdrp
= elf_elfheader (abfd
);
5385 if (EF_ARM_EABI_VERSION (i_ehdrp
->e_flags
) == EF_ARM_EABI_UNKNOWN
)
5386 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_ARM
;
5388 i_ehdrp
->e_ident
[EI_OSABI
] = 0;
5389 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
5393 globals
= elf32_arm_hash_table (link_info
);
5394 if (globals
->byteswap_code
)
5395 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
5399 static enum elf_reloc_type_class
5400 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
5402 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5404 case R_ARM_RELATIVE
:
5405 return reloc_class_relative
;
5406 case R_ARM_JUMP_SLOT
:
5407 return reloc_class_plt
;
5409 return reloc_class_copy
;
5411 return reloc_class_normal
;
5415 /* Set the right machine number for an Arm ELF file. */
5418 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
5420 if (hdr
->sh_type
== SHT_NOTE
)
5421 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
5427 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
5429 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
5432 /* Return TRUE if this is an unwinding table entry. */
5435 is_arm_elf_unwind_section_name (bfd
* abfd ATTRIBUTE_UNUSED
, const char * name
)
5439 len1
= sizeof (ELF_STRING_ARM_unwind
) - 1;
5440 len2
= sizeof (ELF_STRING_ARM_unwind_once
) - 1;
5441 return (strncmp (name
, ELF_STRING_ARM_unwind
, len1
) == 0
5442 || strncmp (name
, ELF_STRING_ARM_unwind_once
, len2
) == 0);
5446 /* Set the type and flags for an ARM section. We do this by
5447 the section name, which is a hack, but ought to work. */
5450 elf32_arm_fake_sections (bfd
* abfd
, Elf_Internal_Shdr
* hdr
, asection
* sec
)
5454 name
= bfd_get_section_name (abfd
, sec
);
5456 if (is_arm_elf_unwind_section_name (abfd
, name
))
5458 hdr
->sh_type
= SHT_ARM_EXIDX
;
5459 hdr
->sh_flags
|= SHF_LINK_ORDER
;
5464 /* Handle an ARM specific section when reading an object file.
5465 This is called when elf.c finds a section with an unknown type. */
5468 elf32_arm_section_from_shdr (bfd
*abfd
,
5469 Elf_Internal_Shdr
* hdr
,
5472 /* There ought to be a place to keep ELF backend specific flags, but
5473 at the moment there isn't one. We just keep track of the
5474 sections by their name, instead. Fortunately, the ABI gives
5475 names for all the ARM specific sections, so we will probably get
5477 switch (hdr
->sh_type
)
5486 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
5492 /* Called for each symbol. Builds a section map based on mapping symbols.
5493 Does not alter any of the symbols. */
5496 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
5498 Elf_Internal_Sym
*elfsym
,
5499 asection
*input_sec
,
5500 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
5503 elf32_arm_section_map
*map
;
5504 struct elf32_arm_link_hash_table
*globals
;
5506 /* Only do this on final link. */
5507 if (info
->relocatable
)
5510 /* Only build a map if we need to byteswap code. */
5511 globals
= elf32_arm_hash_table (info
);
5512 if (!globals
->byteswap_code
)
5515 /* We only want mapping symbols. */
5516 if (! is_arm_mapping_symbol_name (name
))
5519 mapcount
= ++(elf32_arm_section_data (input_sec
)->mapcount
);
5520 map
= elf32_arm_section_data (input_sec
)->map
;
5521 /* TODO: This may be inefficient, but we probably don't usually have many
5522 mapping symbols per section. */
5523 map
= bfd_realloc (map
, mapcount
* sizeof (elf32_arm_section_map
));
5524 elf32_arm_section_data (input_sec
)->map
= map
;
5526 map
[mapcount
- 1].vma
= elfsym
->st_value
;
5527 map
[mapcount
- 1].type
= name
[1];
5532 /* Allocate target specific section data. */
5535 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
5537 struct _arm_elf_section_data
*sdata
;
5538 bfd_size_type amt
= sizeof (*sdata
);
5540 sdata
= bfd_zalloc (abfd
, amt
);
5543 sec
->used_by_bfd
= sdata
;
5545 return _bfd_elf_new_section_hook (abfd
, sec
);
5549 /* Used to order a list of mapping symbols by address. */
5552 elf32_arm_compare_mapping (const void * a
, const void * b
)
5554 return ((const elf32_arm_section_map
*) a
)->vma
5555 > ((const elf32_arm_section_map
*) b
)->vma
;
5559 /* Do code byteswapping. Return FALSE afterwards so that the section is
5560 written out as normal. */
5563 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
5567 elf32_arm_section_map
*map
;
5574 mapcount
= elf32_arm_section_data (sec
)->mapcount
;
5575 map
= elf32_arm_section_data (sec
)->map
;
5580 qsort (map
, mapcount
, sizeof (elf32_arm_section_map
),
5581 elf32_arm_compare_mapping
);
5583 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
5584 ptr
= map
[0].vma
- offset
;
5585 for (i
= 0; i
< mapcount
; i
++)
5587 if (i
== mapcount
- 1)
5590 end
= map
[i
+ 1].vma
- offset
;
5592 switch (map
[i
].type
)
5595 /* Byte swap code words. */
5596 while (ptr
+ 3 < end
)
5598 tmp
= contents
[ptr
];
5599 contents
[ptr
] = contents
[ptr
+ 3];
5600 contents
[ptr
+ 3] = tmp
;
5601 tmp
= contents
[ptr
+ 1];
5602 contents
[ptr
+ 1] = contents
[ptr
+ 2];
5603 contents
[ptr
+ 2] = tmp
;
5609 /* Byte swap code halfwords. */
5610 while (ptr
+ 1 < end
)
5612 tmp
= contents
[ptr
];
5613 contents
[ptr
] = contents
[ptr
+ 1];
5614 contents
[ptr
+ 1] = tmp
;
5620 /* Leave data alone. */
5629 /* Display STT_ARM_TFUNC symbols as functions. */
5632 elf32_arm_symbol_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
5635 elf_symbol_type
*elfsym
= (elf_symbol_type
*) asym
;
5637 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_ARM_TFUNC
)
5638 elfsym
->symbol
.flags
|= BSF_FUNCTION
;
5642 /* Mangle thumb function symbols as we read them in. */
5645 elf32_arm_swap_symbol_in (bfd
* abfd
,
5648 Elf_Internal_Sym
*dst
)
5650 bfd_elf32_swap_symbol_in (abfd
, psrc
, pshn
, dst
);
5652 /* New EABI objects mark thumb function symbols by setting the low bit of
5653 the address. Turn these into STT_ARM_TFUNC. */
5654 if (ELF_ST_TYPE (dst
->st_info
) == STT_FUNC
5655 && (dst
->st_value
& 1))
5657 dst
->st_info
= ELF_ST_INFO (ELF_ST_BIND (dst
->st_info
), STT_ARM_TFUNC
);
5658 dst
->st_value
&= ~(bfd_vma
) 1;
5663 /* Mangle thumb function symbols as we write them out. */
5666 elf32_arm_swap_symbol_out (bfd
*abfd
,
5667 const Elf_Internal_Sym
*src
,
5671 Elf_Internal_Sym newsym
;
5673 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
5674 of the address set, as per the new EABI. We do this unconditionally
5675 because objcopy does not set the elf header flags until after
5676 it writes out the symbol table. */
5677 if (ELF_ST_TYPE (src
->st_info
) == STT_ARM_TFUNC
)
5680 newsym
.st_info
= ELF_ST_INFO (ELF_ST_BIND (src
->st_info
), STT_FUNC
);
5681 newsym
.st_value
|= 1;
5685 bfd_elf32_swap_symbol_out (abfd
, src
, cdst
, shndx
);
5688 /* We use this to override swap_symbol_in and swap_symbol_out. */
5689 const struct elf_size_info elf32_arm_size_info
= {
5690 sizeof (Elf32_External_Ehdr
),
5691 sizeof (Elf32_External_Phdr
),
5692 sizeof (Elf32_External_Shdr
),
5693 sizeof (Elf32_External_Rel
),
5694 sizeof (Elf32_External_Rela
),
5695 sizeof (Elf32_External_Sym
),
5696 sizeof (Elf32_External_Dyn
),
5697 sizeof (Elf_External_Note
),
5701 ELFCLASS32
, EV_CURRENT
,
5702 bfd_elf32_write_out_phdrs
,
5703 bfd_elf32_write_shdrs_and_ehdr
,
5704 bfd_elf32_write_relocs
,
5705 elf32_arm_swap_symbol_in
,
5706 elf32_arm_swap_symbol_out
,
5707 bfd_elf32_slurp_reloc_table
,
5708 bfd_elf32_slurp_symbol_table
,
5709 bfd_elf32_swap_dyn_in
,
5710 bfd_elf32_swap_dyn_out
,
5711 bfd_elf32_swap_reloc_in
,
5712 bfd_elf32_swap_reloc_out
,
5713 bfd_elf32_swap_reloca_in
,
5714 bfd_elf32_swap_reloca_out
5717 #define ELF_ARCH bfd_arch_arm
5718 #define ELF_MACHINE_CODE EM_ARM
5719 #ifdef __QNXTARGET__
5720 #define ELF_MAXPAGESIZE 0x1000
5722 #define ELF_MAXPAGESIZE 0x8000
5724 #define ELF_MINPAGESIZE 0x1000
5726 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
5727 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
5728 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
5729 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
5730 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
5731 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
5732 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
5733 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
5734 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
5736 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
5737 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
5738 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
5739 #define elf_backend_check_relocs elf32_arm_check_relocs
5740 #define elf_backend_relocate_section elf32_arm_relocate_section
5741 #define elf_backend_write_section elf32_arm_write_section
5742 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
5743 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
5744 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
5745 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
5746 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
5747 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
5748 #define elf_backend_post_process_headers elf32_arm_post_process_headers
5749 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
5750 #define elf_backend_object_p elf32_arm_object_p
5751 #define elf_backend_section_flags elf32_arm_section_flags
5752 #define elf_backend_fake_sections elf32_arm_fake_sections
5753 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
5754 #define elf_backend_final_write_processing elf32_arm_final_write_processing
5755 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
5756 #define elf_backend_symbol_processing elf32_arm_symbol_processing
5757 #define elf_backend_size_info elf32_arm_size_info
5759 #define elf_backend_can_refcount 1
5760 #define elf_backend_can_gc_sections 1
5761 #define elf_backend_plt_readonly 1
5762 #define elf_backend_want_got_plt 1
5763 #define elf_backend_want_plt_sym 0
5764 #define elf_backend_may_use_rel_p 1
5765 #define elf_backend_may_use_rela_p 0
5766 #define elf_backend_default_use_rela_p 0
5767 #define elf_backend_rela_normal 0
5769 #define elf_backend_got_header_size 12
5771 #include "elf32-target.h"
5773 /* VxWorks Targets */
5775 #undef TARGET_LITTLE_SYM
5776 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
5777 #undef TARGET_LITTLE_NAME
5778 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
5779 #undef TARGET_BIG_SYM
5780 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
5781 #undef TARGET_BIG_NAME
5782 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
5784 /* Like elf32_arm_link_hash_table_create -- but overrides
5785 appropriately for VxWorks. */
5786 static struct bfd_link_hash_table
*
5787 elf32_arm_vxworks_link_hash_table_create (bfd
*abfd
)
5789 struct bfd_link_hash_table
*ret
;
5791 ret
= elf32_arm_link_hash_table_create (abfd
);
5794 struct elf32_arm_link_hash_table
*htab
5795 = (struct elf32_arm_link_hash_table
*)ret
;
5802 #define elf32_bed elf32_arm_vxworks_bed
5804 #undef bfd_elf32_bfd_link_hash_table_create
5805 #define bfd_elf32_bfd_link_hash_table_create \
5806 elf32_arm_vxworks_link_hash_table_create
5808 #undef elf_backend_may_use_rel_p
5809 #define elf_backend_may_use_rel_p 0
5810 #undef elf_backend_may_use_rela_p
5811 #define elf_backend_may_use_rela_p 1
5812 #undef elf_backend_default_use_rela_p
5813 #define elf_backend_default_use_rela_p 1
5814 #undef elf_backend_rela_normal
5815 #define elf_backend_rela_normal 1
5817 #include "elf32-target.h"
5820 /* Symbian OS Targets */
5822 #undef TARGET_LITTLE_SYM
5823 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
5824 #undef TARGET_LITTLE_NAME
5825 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
5826 #undef TARGET_BIG_SYM
5827 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
5828 #undef TARGET_BIG_NAME
5829 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
5831 /* Like elf32_arm_link_hash_table_create -- but overrides
5832 appropriately for Symbian OS. */
5833 static struct bfd_link_hash_table
*
5834 elf32_arm_symbian_link_hash_table_create (bfd
*abfd
)
5836 struct bfd_link_hash_table
*ret
;
5838 ret
= elf32_arm_link_hash_table_create (abfd
);
5841 struct elf32_arm_link_hash_table
*htab
5842 = (struct elf32_arm_link_hash_table
*)ret
;
5843 /* There is no PLT header for Symbian OS. */
5844 htab
->plt_header_size
= 0;
5845 /* The PLT entries are each three instructions. */
5846 htab
->plt_entry_size
= 4 * NUM_ELEM (elf32_arm_symbian_plt_entry
);
5847 htab
->symbian_p
= 1;
5852 /* In a BPABI executable, the dynamic linking sections do not go in
5853 the loadable read-only segment. The post-linker may wish to refer
5854 to these sections, but they are not part of the final program
5856 static struct bfd_elf_special_section
const
5857 elf32_arm_symbian_special_sections
[]=
5859 { ".dynamic", 8, 0, SHT_DYNAMIC
, 0 },
5860 { ".dynstr", 7, 0, SHT_STRTAB
, 0 },
5861 { ".dynsym", 7, 0, SHT_DYNSYM
, 0 },
5862 { ".got", 4, 0, SHT_PROGBITS
, 0 },
5863 { ".hash", 5, 0, SHT_HASH
, 0 },
5864 { NULL
, 0, 0, 0, 0 }
5868 elf32_arm_symbian_begin_write_processing (bfd
*abfd
,
5869 struct bfd_link_info
*link_info
5872 /* BPABI objects are never loaded directly by an OS kernel; they are
5873 processed by a postlinker first, into an OS-specific format. If
5874 the D_PAGED bit is set on the file, BFD will align segments on
5875 page boundaries, so that an OS can directly map the file. With
5876 BPABI objects, that just results in wasted space. In addition,
5877 because we clear the D_PAGED bit, map_sections_to_segments will
5878 recognize that the program headers should not be mapped into any
5879 loadable segment. */
5880 abfd
->flags
&= ~D_PAGED
;
5884 elf32_arm_symbian_modify_segment_map (bfd
*abfd
,
5885 struct bfd_link_info
*info
5888 struct elf_segment_map
*m
;
5891 /* BPABI shared libraries and executables should have a PT_DYNAMIC
5892 segment. However, because the .dynamic section is not marked
5893 with SEC_LOAD, the generic ELF code will not create such a
5895 dynsec
= bfd_get_section_by_name (abfd
, ".dynamic");
5898 m
= _bfd_elf_make_dynamic_segment (abfd
, dynsec
);
5899 m
->next
= elf_tdata (abfd
)->segment_map
;
5900 elf_tdata (abfd
)->segment_map
= m
;
5907 #define elf32_bed elf32_arm_symbian_bed
5909 /* The dynamic sections are not allocated on SymbianOS; the postlinker
5910 will process them and then discard them. */
5911 #undef ELF_DYNAMIC_SEC_FLAGS
5912 #define ELF_DYNAMIC_SEC_FLAGS \
5913 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
5915 #undef bfd_elf32_bfd_link_hash_table_create
5916 #define bfd_elf32_bfd_link_hash_table_create \
5917 elf32_arm_symbian_link_hash_table_create
5919 #undef elf_backend_special_sections
5920 #define elf_backend_special_sections elf32_arm_symbian_special_sections
5922 #undef elf_backend_begin_write_processing
5923 #define elf_backend_begin_write_processing \
5924 elf32_arm_symbian_begin_write_processing
5926 #undef elf_backend_modify_segment_map
5927 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
5929 /* There is no .got section for BPABI objects, and hence no header. */
5930 #undef elf_backend_got_header_size
5931 #define elf_backend_got_header_size 0
5933 /* Similarly, there is no .got.plt section. */
5934 #undef elf_backend_want_got_plt
5935 #define elf_backend_want_got_plt 0
5937 #undef elf_backend_may_use_rel_p
5938 #define elf_backend_may_use_rel_p 1
5939 #undef elf_backend_may_use_rela_p
5940 #define elf_backend_may_use_rela_p 0
5941 #undef elf_backend_default_use_rela_p
5942 #define elf_backend_default_use_rela_p 0
5943 #undef elf_backend_rela_normal
5944 #define elf_backend_rela_normal 0
5946 #include "elf32-target.h"