1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
28 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
31 #define elf_info_to_howto 0
32 #define elf_info_to_howto_rel elf32_arm_info_to_howto
34 #define ARM_ELF_ABI_VERSION 0
35 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
37 static reloc_howto_type * elf32_arm_reloc_type_lookup
38 PARAMS ((bfd * abfd, bfd_reloc_code_real_type code));
39 static bfd_boolean elf32_arm_nabi_grok_prstatus
40 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
41 static bfd_boolean elf32_arm_nabi_grok_psinfo
42 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
44 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
45 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
48 static reloc_howto_type elf32_arm_howto_table[] =
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 /* Dynamic TLS relocations. */
299 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 FALSE, /* pc_relative */
305 complain_overflow_bitfield,/* complain_on_overflow */
306 bfd_elf_generic_reloc, /* special_function */
307 "R_ARM_TLS_DTPMOD32", /* name */
308 TRUE, /* partial_inplace */
309 0xffffffff, /* src_mask */
310 0xffffffff, /* dst_mask */
311 FALSE), /* pcrel_offset */
313 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 FALSE, /* pc_relative */
319 complain_overflow_bitfield,/* complain_on_overflow */
320 bfd_elf_generic_reloc, /* special_function */
321 "R_ARM_TLS_DTPOFF32", /* name */
322 TRUE, /* partial_inplace */
323 0xffffffff, /* src_mask */
324 0xffffffff, /* dst_mask */
325 FALSE), /* pcrel_offset */
327 HOWTO (R_ARM_TLS_TPOFF32, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 FALSE, /* pc_relative */
333 complain_overflow_bitfield,/* complain_on_overflow */
334 bfd_elf_generic_reloc, /* special_function */
335 "R_ARM_TLS_TPOFF32", /* name */
336 TRUE, /* partial_inplace */
337 0xffffffff, /* src_mask */
338 0xffffffff, /* dst_mask */
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 static reloc_howto_type elf32_arm_tls_gd32_howto =
667 HOWTO (R_ARM_TLS_GD32, /* type */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
671 FALSE, /* pc_relative */
673 complain_overflow_bitfield,/* complain_on_overflow */
674 NULL, /* special_function */
675 "R_ARM_TLS_GD32", /* name */
676 TRUE, /* partial_inplace */
677 0xffffffff, /* src_mask */
678 0xffffffff, /* dst_mask */
679 FALSE); /* pcrel_offset */
681 static reloc_howto_type elf32_arm_tls_ldo32_howto =
682 HOWTO (R_ARM_TLS_LDO32, /* type */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE, /* pc_relative */
688 complain_overflow_bitfield,/* complain_on_overflow */
689 bfd_elf_generic_reloc, /* special_function */
690 "R_ARM_TLS_LDO32", /* name */
691 TRUE, /* partial_inplace */
692 0xffffffff, /* src_mask */
693 0xffffffff, /* dst_mask */
694 FALSE); /* pcrel_offset */
696 static reloc_howto_type elf32_arm_tls_ldm32_howto =
697 HOWTO (R_ARM_TLS_LDM32, /* type */
699 2, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE, /* pc_relative */
703 complain_overflow_bitfield,/* complain_on_overflow */
704 bfd_elf_generic_reloc, /* special_function */
705 "R_ARM_TLS_LDM32", /* name */
706 TRUE, /* partial_inplace */
707 0xffffffff, /* src_mask */
708 0xffffffff, /* dst_mask */
709 FALSE); /* pcrel_offset */
711 static reloc_howto_type elf32_arm_tls_le32_howto =
712 HOWTO (R_ARM_TLS_LE32, /* type */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE, /* pc_relative */
718 complain_overflow_bitfield,/* complain_on_overflow */
719 bfd_elf_generic_reloc, /* special_function */
720 "R_ARM_TLS_LE32", /* name */
721 TRUE, /* partial_inplace */
722 0xffffffff, /* src_mask */
723 0xffffffff, /* dst_mask */
724 FALSE); /* pcrel_offset */
726 static reloc_howto_type elf32_arm_tls_ie32_howto =
727 HOWTO (R_ARM_TLS_IE32, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE, /* pc_relative */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 NULL, /* special_function */
735 "R_ARM_TLS_IE32", /* name */
736 TRUE, /* partial_inplace */
737 0xffffffff, /* src_mask */
738 0xffffffff, /* dst_mask */
739 FALSE); /* pcrel_offset */
741 /* GNU extension to record C++ vtable hierarchy */
742 static reloc_howto_type elf32_arm_vtinherit_howto =
743 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE, /* pc_relative */
749 complain_overflow_dont, /* complain_on_overflow */
750 NULL, /* special_function */
751 "R_ARM_GNU_VTINHERIT", /* name */
752 FALSE, /* partial_inplace */
755 FALSE); /* pcrel_offset */
757 /* GNU extension to record C++ vtable member usage */
758 static reloc_howto_type elf32_arm_vtentry_howto =
759 HOWTO (R_ARM_GNU_VTENTRY, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE, /* pc_relative */
765 complain_overflow_dont, /* complain_on_overflow */
766 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
767 "R_ARM_GNU_VTENTRY", /* name */
768 FALSE, /* partial_inplace */
771 FALSE); /* pcrel_offset */
773 /* 12 bit pc relative */
774 static reloc_howto_type elf32_arm_thm_pc11_howto =
775 HOWTO (R_ARM_THM_PC11, /* type */
777 1, /* size (0 = byte, 1 = short, 2 = long) */
779 TRUE, /* pc_relative */
781 complain_overflow_signed, /* complain_on_overflow */
782 bfd_elf_generic_reloc, /* special_function */
783 "R_ARM_THM_PC11", /* name */
784 FALSE, /* partial_inplace */
785 0x000007ff, /* src_mask */
786 0x000007ff, /* dst_mask */
787 TRUE); /* pcrel_offset */
789 /* 12 bit pc relative */
790 static reloc_howto_type elf32_arm_thm_pc9_howto =
791 HOWTO (R_ARM_THM_PC9, /* type */
793 1, /* size (0 = byte, 1 = short, 2 = long) */
795 TRUE, /* pc_relative */
797 complain_overflow_signed, /* complain_on_overflow */
798 bfd_elf_generic_reloc, /* special_function */
799 "R_ARM_THM_PC9", /* name */
800 FALSE, /* partial_inplace */
801 0x000000ff, /* src_mask */
802 0x000000ff, /* dst_mask */
803 TRUE); /* pcrel_offset */
805 /* Place relative GOT-indirect. */
806 static reloc_howto_type elf32_arm_got_prel =
807 HOWTO (R_ARM_GOT_PREL, /* type */
809 2, /* size (0 = byte, 1 = short, 2 = long) */
811 TRUE, /* pc_relative */
813 complain_overflow_dont, /* complain_on_overflow */
814 bfd_elf_generic_reloc, /* special_function */
815 "R_ARM_GOT_PREL", /* name */
816 FALSE, /* partial_inplace */
817 0xffffffff, /* src_mask */
818 0xffffffff, /* dst_mask */
819 TRUE); /* pcrel_offset */
821 /* Currently unused relocations. */
822 static reloc_howto_type elf32_arm_r_howto[4] =
824 HOWTO (R_ARM_RREL32, /* type */
826 0, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE, /* pc_relative */
830 complain_overflow_dont,/* complain_on_overflow */
831 bfd_elf_generic_reloc, /* special_function */
832 "R_ARM_RREL32", /* name */
833 FALSE, /* partial_inplace */
836 FALSE), /* pcrel_offset */
838 HOWTO (R_ARM_RABS32, /* type */
840 0, /* size (0 = byte, 1 = short, 2 = long) */
842 FALSE, /* pc_relative */
844 complain_overflow_dont,/* complain_on_overflow */
845 bfd_elf_generic_reloc, /* special_function */
846 "R_ARM_RABS32", /* name */
847 FALSE, /* partial_inplace */
850 FALSE), /* pcrel_offset */
852 HOWTO (R_ARM_RPC24, /* type */
854 0, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE, /* pc_relative */
858 complain_overflow_dont,/* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 "R_ARM_RPC24", /* name */
861 FALSE, /* partial_inplace */
864 FALSE), /* pcrel_offset */
866 HOWTO (R_ARM_RBASE, /* type */
868 0, /* size (0 = byte, 1 = short, 2 = long) */
870 FALSE, /* pc_relative */
872 complain_overflow_dont,/* complain_on_overflow */
873 bfd_elf_generic_reloc, /* special_function */
874 "R_ARM_RBASE", /* name */
875 FALSE, /* partial_inplace */
878 FALSE) /* pcrel_offset */
881 static reloc_howto_type *
882 elf32_arm_howto_from_type (unsigned int r_type)
884 if (r_type < NUM_ELEM (elf32_arm_howto_table))
885 return &elf32_arm_howto_table[r_type];
890 return &elf32_arm_got_prel;
892 case R_ARM_GNU_VTINHERIT:
893 return &elf32_arm_vtinherit_howto;
895 case R_ARM_GNU_VTENTRY:
896 return &elf32_arm_vtentry_howto;
899 return &elf32_arm_thm_pc11_howto;
902 return &elf32_arm_thm_pc9_howto;
905 return &elf32_arm_tls_gd32_howto;
908 case R_ARM_TLS_LDO32:
909 return &elf32_arm_tls_ldo32_howto;
912 case R_ARM_TLS_LDM32:
913 return &elf32_arm_tls_ldm32_howto;
917 return &elf32_arm_tls_ie32_howto;
921 return &elf32_arm_tls_le32_howto;
928 return &elf32_arm_r_howto[r_type - R_ARM_RREL32];
936 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
937 Elf_Internal_Rela * elf_reloc)
941 r_type = ELF32_R_TYPE (elf_reloc->r_info);
942 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
945 struct elf32_arm_reloc_map
947 bfd_reloc_code_real_type bfd_reloc_val;
948 unsigned char elf_reloc_val;
951 /* All entries in this list must also be present in elf32_arm_howto_table. */
952 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
954 {BFD_RELOC_NONE, R_ARM_NONE},
955 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
956 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
957 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
958 {BFD_RELOC_32, R_ARM_ABS32},
959 {BFD_RELOC_32_PCREL, R_ARM_REL32},
960 {BFD_RELOC_8, R_ARM_ABS8},
961 {BFD_RELOC_16, R_ARM_ABS16},
962 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
963 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
964 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_PC22},
965 {BFD_RELOC_ARM_COPY, R_ARM_COPY},
966 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
967 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
968 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
969 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF},
970 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
971 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
972 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
973 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
974 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
975 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
976 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
977 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
978 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
979 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
980 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
981 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
982 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
983 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
984 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
985 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
986 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
989 static reloc_howto_type *
990 elf32_arm_reloc_type_lookup (abfd, code)
991 bfd *abfd ATTRIBUTE_UNUSED;
992 bfd_reloc_code_real_type code;
998 case BFD_RELOC_VTABLE_INHERIT:
999 return & elf32_arm_vtinherit_howto;
1001 case BFD_RELOC_VTABLE_ENTRY:
1002 return & elf32_arm_vtentry_howto;
1004 case BFD_RELOC_THUMB_PCREL_BRANCH12:
1005 return & elf32_arm_thm_pc11_howto;
1007 case BFD_RELOC_THUMB_PCREL_BRANCH9:
1008 return & elf32_arm_thm_pc9_howto;
1010 case BFD_RELOC_ARM_TLS_GD32:
1011 return & elf32_arm_tls_gd32_howto;
1013 case BFD_RELOC_ARM_TLS_LDO32:
1014 return & elf32_arm_tls_ldo32_howto;
1016 case BFD_RELOC_ARM_TLS_LDM32:
1017 return & elf32_arm_tls_ldm32_howto;
1019 case BFD_RELOC_ARM_TLS_IE32:
1020 return & elf32_arm_tls_ie32_howto;
1022 case BFD_RELOC_ARM_TLS_LE32:
1023 return & elf32_arm_tls_le32_howto;
1026 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1027 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1028 return & elf32_arm_howto_table[elf32_arm_reloc_map[i].elf_reloc_val];
1034 /* Support for core dump NOTE sections */
1036 elf32_arm_nabi_grok_prstatus (abfd, note)
1038 Elf_Internal_Note *note;
1043 switch (note->descsz)
1048 case 148: /* Linux/ARM 32-bit*/
1050 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1053 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1062 /* Make a ".reg/999" section. */
1063 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1064 size, note->descpos + offset);
1068 elf32_arm_nabi_grok_psinfo (abfd, note)
1070 Elf_Internal_Note *note;
1072 switch (note->descsz)
1077 case 124: /* Linux/ARM elf_prpsinfo */
1078 elf_tdata (abfd)->core_program
1079 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1080 elf_tdata (abfd)->core_command
1081 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1084 /* Note that for some reason, a spurious space is tacked
1085 onto the end of the args in some (at least one anyway)
1086 implementations, so strip it off if it exists. */
1089 char *command = elf_tdata (abfd)->core_command;
1090 int n = strlen (command);
1092 if (0 < n && command[n - 1] == ' ')
1093 command[n - 1] = '\0';
1099 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1100 #define TARGET_LITTLE_NAME "elf32-littlearm"
1101 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1102 #define TARGET_BIG_NAME "elf32-bigarm"
1104 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1105 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1107 typedef unsigned long int insn32;
1108 typedef unsigned short int insn16;
1110 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
1111 #define INTERWORK_FLAG(abfd) \
1112 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
1113 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1115 /* The linker script knows the section names for placement.
1116 The entry_names are used to do simple name mangling on the stubs.
1117 Given a function name, and its type, the stub can be found. The
1118 name can be changed. The only requirement is the %s be present. */
1119 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1120 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1122 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1123 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1125 /* The name of the dynamic interpreter. This is put in the .interp
1127 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1129 #ifdef FOUR_WORD_PLT
1131 /* The first entry in a procedure linkage table looks like
1132 this. It is set up so that any shared library function that is
1133 called before the relocation has been set up calls the dynamic
1135 static const bfd_vma elf32_arm_plt0_entry [] =
1137 0xe52de004, /* str lr, [sp, #-4]! */
1138 0xe59fe010, /* ldr lr, [pc, #16] */
1139 0xe08fe00e, /* add lr, pc, lr */
1140 0xe5bef008, /* ldr pc, [lr, #8]! */
1143 /* Subsequent entries in a procedure linkage table look like
1145 static const bfd_vma elf32_arm_plt_entry [] =
1147 0xe28fc600, /* add ip, pc, #NN */
1148 0xe28cca00, /* add ip, ip, #NN */
1149 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1150 0x00000000, /* unused */
1155 /* The first entry in a procedure linkage table looks like
1156 this. It is set up so that any shared library function that is
1157 called before the relocation has been set up calls the dynamic
1159 static const bfd_vma elf32_arm_plt0_entry [] =
1161 0xe52de004, /* str lr, [sp, #-4]! */
1162 0xe59fe004, /* ldr lr, [pc, #4] */
1163 0xe08fe00e, /* add lr, pc, lr */
1164 0xe5bef008, /* ldr pc, [lr, #8]! */
1165 0x00000000, /* &GOT[0] - . */
1168 /* Subsequent entries in a procedure linkage table look like
1170 static const bfd_vma elf32_arm_plt_entry [] =
1172 0xe28fc600, /* add ip, pc, #0xNN00000 */
1173 0xe28cca00, /* add ip, ip, #0xNN000 */
1174 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1179 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1180 #define PLT_THUMB_STUB_SIZE 4
1181 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1187 /* The entries in a PLT when using a DLL-based target with multiple
1189 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1191 0xe51ff004, /* ldr pc, [pc, #-4] */
1192 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1195 /* Used to build a map of a section. This is required for mixed-endian
1198 typedef struct elf32_elf_section_map
1203 elf32_arm_section_map;
1205 struct _arm_elf_section_data
1207 struct bfd_elf_section_data elf;
1209 elf32_arm_section_map *map;
1212 #define elf32_arm_section_data(sec) \
1213 ((struct _arm_elf_section_data *) elf_section_data (sec))
1215 /* The size of the thread control block. */
1218 struct elf32_arm_obj_tdata
1220 struct elf_obj_tdata root;
1222 /* tls_type for each local got entry. */
1223 char *local_got_tls_type;
1226 #define elf32_arm_tdata(abfd) \
1227 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1229 #define elf32_arm_local_got_tls_type(abfd) \
1230 (elf32_arm_tdata (abfd)->local_got_tls_type)
1233 elf32_arm_mkobject (bfd *abfd)
1235 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
1236 abfd->tdata.any = bfd_zalloc (abfd, amt);
1237 if (abfd->tdata.any == NULL)
1242 /* The ARM linker needs to keep track of the number of relocs that it
1243 decides to copy in check_relocs for each symbol. This is so that
1244 it can discard PC relative relocs if it doesn't need them when
1245 linking with -Bsymbolic. We store the information in a field
1246 extending the regular ELF linker hash table. */
1248 /* This structure keeps track of the number of relocs we have copied
1249 for a given symbol. */
1250 struct elf32_arm_relocs_copied
1253 struct elf32_arm_relocs_copied * next;
1254 /* A section in dynobj. */
1256 /* Number of relocs copied in this section. */
1257 bfd_size_type count;
1258 /* Number of PC-relative relocs copied in this section. */
1259 bfd_size_type pc_count;
1262 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1264 /* Arm ELF linker hash entry. */
1265 struct elf32_arm_link_hash_entry
1267 struct elf_link_hash_entry root;
1269 /* Number of PC relative relocs copied for this symbol. */
1270 struct elf32_arm_relocs_copied * relocs_copied;
1272 /* We reference count Thumb references to a PLT entry separately,
1273 so that we can emit the Thumb trampoline only if needed. */
1274 bfd_signed_vma plt_thumb_refcount;
1276 /* Since PLT entries have variable size if the Thumb prologue is
1277 used, we need to record the index into .got.plt instead of
1278 recomputing it from the PLT offset. */
1279 bfd_signed_vma plt_got_offset;
1281 #define GOT_UNKNOWN 0
1282 #define GOT_NORMAL 1
1283 #define GOT_TLS_GD 2
1284 #define GOT_TLS_IE 4
1285 unsigned char tls_type;
1288 /* Traverse an arm ELF linker hash table. */
1289 #define elf32_arm_link_hash_traverse(table, func, info) \
1290 (elf_link_hash_traverse \
1292 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1295 /* Get the ARM elf linker hash table from a link_info structure. */
1296 #define elf32_arm_hash_table(info) \
1297 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1299 /* ARM ELF linker hash table. */
1300 struct elf32_arm_link_hash_table
1302 /* The main hash table. */
1303 struct elf_link_hash_table root;
1305 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1306 bfd_size_type thumb_glue_size;
1308 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1309 bfd_size_type arm_glue_size;
1311 /* An arbitrary input BFD chosen to hold the glue sections. */
1312 bfd * bfd_of_glue_owner;
1314 /* Nonzero to output a BE8 image. */
1317 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1318 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1321 /* The relocation to use for R_ARM_TARGET2 relocations. */
1324 /* Nonzero to fix BX instructions for ARMv4 targets. */
1327 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1330 /* The number of bytes in the initial entry in the PLT. */
1331 bfd_size_type plt_header_size;
1333 /* The number of bytes in the subsequent PLT etries. */
1334 bfd_size_type plt_entry_size;
1336 /* True if the target system is Symbian OS. */
1339 /* True if the target uses REL relocations. */
1342 /* Short-cuts to get to dynamic linker sections. */
1351 /* Data for R_ARM_TLS_LDM32 relocations. */
1353 bfd_signed_vma refcount;
1357 /* Small local sym to section mapping cache. */
1358 struct sym_sec_cache sym_sec;
1360 /* For convenience in allocate_dynrelocs. */
1364 /* Create an entry in an ARM ELF linker hash table. */
1366 static struct bfd_hash_entry *
1367 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1368 struct bfd_hash_table * table,
1369 const char * string)
1371 struct elf32_arm_link_hash_entry * ret =
1372 (struct elf32_arm_link_hash_entry *) entry;
1374 /* Allocate the structure if it has not already been allocated by a
1376 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1377 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1379 return (struct bfd_hash_entry *) ret;
1381 /* Call the allocation method of the superclass. */
1382 ret = ((struct elf32_arm_link_hash_entry *)
1383 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1387 ret->relocs_copied = NULL;
1388 ret->tls_type = GOT_UNKNOWN;
1389 ret->plt_thumb_refcount = 0;
1390 ret->plt_got_offset = -1;
1393 return (struct bfd_hash_entry *) ret;
1396 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1397 shortcuts to them in our hash table. */
1400 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1402 struct elf32_arm_link_hash_table *htab;
1404 htab = elf32_arm_hash_table (info);
1405 /* BPABI objects never have a GOT, or associated sections. */
1406 if (htab->symbian_p)
1409 if (! _bfd_elf_create_got_section (dynobj, info))
1412 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1413 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1414 if (!htab->sgot || !htab->sgotplt)
1417 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got",
1418 (SEC_ALLOC | SEC_LOAD
1421 | SEC_LINKER_CREATED
1423 if (htab->srelgot == NULL
1424 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1429 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1430 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1434 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1436 struct elf32_arm_link_hash_table *htab;
1438 htab = elf32_arm_hash_table (info);
1439 if (!htab->sgot && !create_got_section (dynobj, info))
1442 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1445 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1446 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
1447 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1449 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1454 || (!info->shared && !htab->srelbss))
1460 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1463 elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed,
1464 struct elf_link_hash_entry *dir,
1465 struct elf_link_hash_entry *ind)
1467 struct elf32_arm_link_hash_entry *edir, *eind;
1469 edir = (struct elf32_arm_link_hash_entry *) dir;
1470 eind = (struct elf32_arm_link_hash_entry *) ind;
1472 if (eind->relocs_copied != NULL)
1474 if (edir->relocs_copied != NULL)
1476 struct elf32_arm_relocs_copied **pp;
1477 struct elf32_arm_relocs_copied *p;
1479 if (ind->root.type == bfd_link_hash_indirect)
1482 /* Add reloc counts against the weak sym to the strong sym
1483 list. Merge any entries against the same section. */
1484 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1486 struct elf32_arm_relocs_copied *q;
1488 for (q = edir->relocs_copied; q != NULL; q = q->next)
1489 if (q->section == p->section)
1491 q->pc_count += p->pc_count;
1492 q->count += p->count;
1499 *pp = edir->relocs_copied;
1502 edir->relocs_copied = eind->relocs_copied;
1503 eind->relocs_copied = NULL;
1506 /* If the direct symbol already has an associated PLT entry, the
1507 indirect symbol should not. If it doesn't, swap refcount information
1508 from the indirect symbol. */
1509 if (edir->plt_thumb_refcount == 0)
1511 edir->plt_thumb_refcount = eind->plt_thumb_refcount;
1512 eind->plt_thumb_refcount = 0;
1515 BFD_ASSERT (eind->plt_thumb_refcount == 0);
1517 if (ind->root.type == bfd_link_hash_indirect
1518 && dir->got.refcount <= 0)
1520 edir->tls_type = eind->tls_type;
1521 eind->tls_type = GOT_UNKNOWN;
1524 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
1527 /* Create an ARM elf linker hash table. */
1529 static struct bfd_link_hash_table *
1530 elf32_arm_link_hash_table_create (bfd *abfd)
1532 struct elf32_arm_link_hash_table *ret;
1533 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
1535 ret = bfd_malloc (amt);
1539 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
1540 elf32_arm_link_hash_newfunc))
1547 ret->sgotplt = NULL;
1548 ret->srelgot = NULL;
1550 ret->srelplt = NULL;
1551 ret->sdynbss = NULL;
1552 ret->srelbss = NULL;
1553 ret->thumb_glue_size = 0;
1554 ret->arm_glue_size = 0;
1555 ret->bfd_of_glue_owner = NULL;
1556 ret->byteswap_code = 0;
1557 ret->target1_is_rel = 0;
1558 ret->target2_reloc = R_ARM_NONE;
1559 #ifdef FOUR_WORD_PLT
1560 ret->plt_header_size = 16;
1561 ret->plt_entry_size = 16;
1563 ret->plt_header_size = 20;
1564 ret->plt_entry_size = 12;
1570 ret->sym_sec.abfd = NULL;
1572 ret->tls_ldm_got.refcount = 0;
1574 return &ret->root.root;
1577 /* Locate the Thumb encoded calling stub for NAME. */
1579 static struct elf_link_hash_entry *
1580 find_thumb_glue (struct bfd_link_info *link_info,
1585 struct elf_link_hash_entry *hash;
1586 struct elf32_arm_link_hash_table *hash_table;
1588 /* We need a pointer to the armelf specific hash table. */
1589 hash_table = elf32_arm_hash_table (link_info);
1591 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1592 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1594 BFD_ASSERT (tmp_name);
1596 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1598 hash = elf_link_hash_lookup
1599 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1602 /* xgettext:c-format */
1603 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1604 input_bfd, tmp_name, name);
1611 /* Locate the ARM encoded calling stub for NAME. */
1613 static struct elf_link_hash_entry *
1614 find_arm_glue (struct bfd_link_info *link_info,
1619 struct elf_link_hash_entry *myh;
1620 struct elf32_arm_link_hash_table *hash_table;
1622 /* We need a pointer to the elfarm specific hash table. */
1623 hash_table = elf32_arm_hash_table (link_info);
1625 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1626 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1628 BFD_ASSERT (tmp_name);
1630 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1632 myh = elf_link_hash_lookup
1633 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1636 /* xgettext:c-format */
1637 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
1638 input_bfd, tmp_name, name);
1645 /* ARM->Thumb glue (static images):
1649 ldr r12, __func_addr
1652 .word func @ behave as if you saw a ARM_32 reloc.
1654 (relocatable images)
1657 ldr r12, __func_offset
1664 #define ARM2THUMB_STATIC_GLUE_SIZE 12
1665 static const insn32 a2t1_ldr_insn = 0xe59fc000;
1666 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
1667 static const insn32 a2t3_func_addr_insn = 0x00000001;
1669 #define ARM2THUMB_PIC_GLUE_SIZE 16
1670 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
1671 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
1672 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
1674 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
1678 __func_from_thumb: __func_from_thumb:
1680 nop ldr r6, __func_addr
1682 __func_change_to_arm: bx r6
1684 __func_back_to_thumb:
1690 #define THUMB2ARM_GLUE_SIZE 8
1691 static const insn16 t2a1_bx_pc_insn = 0x4778;
1692 static const insn16 t2a2_noop_insn = 0x46c0;
1693 static const insn32 t2a3_b_insn = 0xea000000;
1695 #ifndef ELFARM_NABI_C_INCLUDED
1697 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
1701 struct elf32_arm_link_hash_table * globals;
1703 globals = elf32_arm_hash_table (info);
1705 BFD_ASSERT (globals != NULL);
1707 if (globals->arm_glue_size != 0)
1709 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1711 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
1712 ARM2THUMB_GLUE_SECTION_NAME);
1714 BFD_ASSERT (s != NULL);
1716 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
1718 s->size = globals->arm_glue_size;
1722 if (globals->thumb_glue_size != 0)
1724 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1726 s = bfd_get_section_by_name
1727 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1729 BFD_ASSERT (s != NULL);
1731 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
1733 s->size = globals->thumb_glue_size;
1741 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
1742 struct elf_link_hash_entry * h)
1744 const char * name = h->root.root.string;
1747 struct elf_link_hash_entry * myh;
1748 struct bfd_link_hash_entry * bh;
1749 struct elf32_arm_link_hash_table * globals;
1752 globals = elf32_arm_hash_table (link_info);
1754 BFD_ASSERT (globals != NULL);
1755 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1757 s = bfd_get_section_by_name
1758 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
1760 BFD_ASSERT (s != NULL);
1762 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1764 BFD_ASSERT (tmp_name);
1766 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1768 myh = elf_link_hash_lookup
1769 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
1773 /* We've already seen this guy. */
1778 /* The only trick here is using hash_table->arm_glue_size as the value.
1779 Even though the section isn't allocated yet, this is where we will be
1782 val = globals->arm_glue_size + 1;
1783 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
1784 tmp_name, BSF_GLOBAL, s, val,
1785 NULL, TRUE, FALSE, &bh);
1787 myh = (struct elf_link_hash_entry *) bh;
1788 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
1789 myh->forced_local = 1;
1793 if ((link_info->shared || globals->root.is_relocatable_executable))
1794 globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
1796 globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
1802 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
1803 struct elf_link_hash_entry *h)
1805 const char *name = h->root.root.string;
1808 struct elf_link_hash_entry *myh;
1809 struct bfd_link_hash_entry *bh;
1810 struct elf32_arm_link_hash_table *hash_table;
1813 hash_table = elf32_arm_hash_table (link_info);
1815 BFD_ASSERT (hash_table != NULL);
1816 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
1818 s = bfd_get_section_by_name
1819 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1821 BFD_ASSERT (s != NULL);
1823 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1824 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1826 BFD_ASSERT (tmp_name);
1828 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1830 myh = elf_link_hash_lookup
1831 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1835 /* We've already seen this guy. */
1841 val = hash_table->thumb_glue_size + 1;
1842 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
1843 tmp_name, BSF_GLOBAL, s, val,
1844 NULL, TRUE, FALSE, &bh);
1846 /* If we mark it 'Thumb', the disassembler will do a better job. */
1847 myh = (struct elf_link_hash_entry *) bh;
1848 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
1849 myh->forced_local = 1;
1853 #define CHANGE_TO_ARM "__%s_change_to_arm"
1854 #define BACK_FROM_ARM "__%s_back_from_arm"
1856 /* Allocate another symbol to mark where we switch to Arm mode. */
1857 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1858 + strlen (CHANGE_TO_ARM) + 1);
1860 BFD_ASSERT (tmp_name);
1862 sprintf (tmp_name, CHANGE_TO_ARM, name);
1865 val = hash_table->thumb_glue_size + 4,
1866 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
1867 tmp_name, BSF_LOCAL, s, val,
1868 NULL, TRUE, FALSE, &bh);
1872 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
1877 /* Add the glue sections to ABFD. This function is called from the
1878 linker scripts in ld/emultempl/{armelf}.em. */
1881 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
1882 struct bfd_link_info *info)
1887 /* If we are only performing a partial
1888 link do not bother adding the glue. */
1889 if (info->relocatable)
1892 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
1896 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
1897 will prevent elf_link_input_bfd() from processing the contents
1899 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
1901 sec = bfd_make_section_with_flags (abfd,
1902 ARM2THUMB_GLUE_SECTION_NAME,
1906 || !bfd_set_section_alignment (abfd, sec, 2))
1909 /* Set the gc mark to prevent the section from being removed by garbage
1910 collection, despite the fact that no relocs refer to this section. */
1914 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
1918 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1919 | SEC_CODE | SEC_READONLY;
1921 sec = bfd_make_section_with_flags (abfd,
1922 THUMB2ARM_GLUE_SECTION_NAME,
1926 || !bfd_set_section_alignment (abfd, sec, 2))
1935 /* Select a BFD to be used to hold the sections used by the glue code.
1936 This function is called from the linker scripts in ld/emultempl/
1940 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
1942 struct elf32_arm_link_hash_table *globals;
1944 /* If we are only performing a partial link
1945 do not bother getting a bfd to hold the glue. */
1946 if (info->relocatable)
1949 /* Make sure we don't attach the glue sections to a dynamic object. */
1950 BFD_ASSERT (!(abfd->flags & DYNAMIC));
1952 globals = elf32_arm_hash_table (info);
1954 BFD_ASSERT (globals != NULL);
1956 if (globals->bfd_of_glue_owner != NULL)
1959 /* Save the bfd for later use. */
1960 globals->bfd_of_glue_owner = abfd;
1966 bfd_elf32_arm_process_before_allocation (bfd *abfd,
1967 struct bfd_link_info *link_info,
1970 Elf_Internal_Shdr *symtab_hdr;
1971 Elf_Internal_Rela *internal_relocs = NULL;
1972 Elf_Internal_Rela *irel, *irelend;
1973 bfd_byte *contents = NULL;
1976 struct elf32_arm_link_hash_table *globals;
1978 /* If we are only performing a partial link do not bother
1979 to construct any glue. */
1980 if (link_info->relocatable)
1983 /* Here we have a bfd that is to be included on the link. We have a hook
1984 to do reloc rummaging, before section sizes are nailed down. */
1985 globals = elf32_arm_hash_table (link_info);
1987 BFD_ASSERT (globals != NULL);
1988 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1990 if (byteswap_code && !bfd_big_endian (abfd))
1992 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
1996 globals->byteswap_code = byteswap_code;
1998 /* Rummage around all the relocs and map the glue vectors. */
1999 sec = abfd->sections;
2004 for (; sec != NULL; sec = sec->next)
2006 if (sec->reloc_count == 0)
2009 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2011 /* Load the relocs. */
2013 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2014 (Elf_Internal_Rela *) NULL, FALSE);
2016 if (internal_relocs == NULL)
2019 irelend = internal_relocs + sec->reloc_count;
2020 for (irel = internal_relocs; irel < irelend; irel++)
2023 unsigned long r_index;
2025 struct elf_link_hash_entry *h;
2027 r_type = ELF32_R_TYPE (irel->r_info);
2028 r_index = ELF32_R_SYM (irel->r_info);
2030 /* These are the only relocation types we care about. */
2031 if ( r_type != R_ARM_PC24
2032 && r_type != R_ARM_PLT32
2034 && r_type != R_ARM_CALL
2035 && r_type != R_ARM_JUMP24
2037 && r_type != R_ARM_THM_PC22)
2040 /* Get the section contents if we haven't done so already. */
2041 if (contents == NULL)
2043 /* Get cached copy if it exists. */
2044 if (elf_section_data (sec)->this_hdr.contents != NULL)
2045 contents = elf_section_data (sec)->this_hdr.contents;
2048 /* Go get them off disk. */
2049 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2054 /* If the relocation is not against a symbol it cannot concern us. */
2057 /* We don't care about local symbols. */
2058 if (r_index < symtab_hdr->sh_info)
2061 /* This is an external symbol. */
2062 r_index -= symtab_hdr->sh_info;
2063 h = (struct elf_link_hash_entry *)
2064 elf_sym_hashes (abfd)[r_index];
2066 /* If the relocation is against a static symbol it must be within
2067 the current section and so cannot be a cross ARM/Thumb relocation. */
2071 /* If the call will go through a PLT entry then we do not need
2073 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2084 /* This one is a call from arm code. We need to look up
2085 the target of the call. If it is a thumb target, we
2087 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC)
2088 record_arm_to_thumb_glue (link_info, h);
2091 case R_ARM_THM_PC22:
2092 /* This one is a call from thumb code. We look
2093 up the target of the call. If it is not a thumb
2094 target, we insert glue. */
2095 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC)
2096 record_thumb_to_arm_glue (link_info, h);
2104 if (contents != NULL
2105 && elf_section_data (sec)->this_hdr.contents != contents)
2109 if (internal_relocs != NULL
2110 && elf_section_data (sec)->relocs != internal_relocs)
2111 free (internal_relocs);
2112 internal_relocs = NULL;
2118 if (contents != NULL
2119 && elf_section_data (sec)->this_hdr.contents != contents)
2121 if (internal_relocs != NULL
2122 && elf_section_data (sec)->relocs != internal_relocs)
2123 free (internal_relocs);
2131 /* Set target relocation values needed during linking. */
2134 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2136 char * target2_type,
2140 struct elf32_arm_link_hash_table *globals;
2142 globals = elf32_arm_hash_table (link_info);
2144 globals->target1_is_rel = target1_is_rel;
2145 if (strcmp (target2_type, "rel") == 0)
2146 globals->target2_reloc = R_ARM_REL32;
2147 else if (strcmp (target2_type, "abs") == 0)
2148 globals->target2_reloc = R_ARM_ABS32;
2149 else if (strcmp (target2_type, "got-rel") == 0)
2150 globals->target2_reloc = R_ARM_GOT_PREL;
2153 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2156 globals->fix_v4bx = fix_v4bx;
2157 globals->use_blx |= use_blx;
2161 /* The thumb form of a long branch is a bit finicky, because the offset
2162 encoding is split over two fields, each in it's own instruction. They
2163 can occur in any order. So given a thumb form of long branch, and an
2164 offset, insert the offset into the thumb branch and return finished
2167 It takes two thumb instructions to encode the target address. Each has
2168 11 bits to invest. The upper 11 bits are stored in one (identified by
2169 H-0.. see below), the lower 11 bits are stored in the other (identified
2172 Combine together and shifted left by 1 (it's a half word address) and
2176 H-0, upper address-0 = 000
2178 H-1, lower address-0 = 800
2180 They can be ordered either way, but the arm tools I've seen always put
2183 XXX: Actually the order does matter. The second instruction (H-1)
2184 moves the computed address into the PC, so it must be the second one
2185 in the sequence. The problem, however is that whilst little endian code
2186 stores the instructions in HI then LOW order, big endian code does the
2189 #define LOW_HI_ORDER 0xF800F000
2190 #define HI_LOW_ORDER 0xF000F800
2193 insert_thumb_branch (insn32 br_insn, int rel_off)
2195 unsigned int low_bits;
2196 unsigned int high_bits;
2198 BFD_ASSERT ((rel_off & 1) != 1);
2200 rel_off >>= 1; /* Half word aligned address. */
2201 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2202 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2204 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2205 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2206 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2207 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2210 abort (); /* Error - not a valid branch instruction form. */
2215 /* Thumb code calling an ARM function. */
2218 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2222 asection * input_section,
2223 bfd_byte * hit_data,
2226 bfd_signed_vma addend,
2231 unsigned long int tmp;
2232 long int ret_offset;
2233 struct elf_link_hash_entry * myh;
2234 struct elf32_arm_link_hash_table * globals;
2236 myh = find_thumb_glue (info, name, input_bfd);
2240 globals = elf32_arm_hash_table (info);
2242 BFD_ASSERT (globals != NULL);
2243 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2245 my_offset = myh->root.u.def.value;
2247 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2248 THUMB2ARM_GLUE_SECTION_NAME);
2250 BFD_ASSERT (s != NULL);
2251 BFD_ASSERT (s->contents != NULL);
2252 BFD_ASSERT (s->output_section != NULL);
2254 if ((my_offset & 0x01) == 0x01)
2257 && sym_sec->owner != NULL
2258 && !INTERWORK_FLAG (sym_sec->owner))
2260 (*_bfd_error_handler)
2261 (_("%B(%s): warning: interworking not enabled.\n"
2262 " first occurrence: %B: thumb call to arm"),
2263 sym_sec->owner, input_bfd, name);
2269 myh->root.u.def.value = my_offset;
2271 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2272 s->contents + my_offset);
2274 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2275 s->contents + my_offset + 2);
2278 /* Address of destination of the stub. */
2279 ((bfd_signed_vma) val)
2281 /* Offset from the start of the current section
2282 to the start of the stubs. */
2284 /* Offset of the start of this stub from the start of the stubs. */
2286 /* Address of the start of the current section. */
2287 + s->output_section->vma)
2288 /* The branch instruction is 4 bytes into the stub. */
2290 /* ARM branches work from the pc of the instruction + 8. */
2293 bfd_put_32 (output_bfd,
2294 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2295 s->contents + my_offset + 4);
2298 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2300 /* Now go back and fix up the original BL insn to point to here. */
2302 /* Address of where the stub is located. */
2303 (s->output_section->vma + s->output_offset + my_offset)
2304 /* Address of where the BL is located. */
2305 - (input_section->output_section->vma + input_section->output_offset
2307 /* Addend in the relocation. */
2309 /* Biassing for PC-relative addressing. */
2312 tmp = bfd_get_32 (input_bfd, hit_data
2313 - input_section->vma);
2315 bfd_put_32 (output_bfd,
2316 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2317 hit_data - input_section->vma);
2322 /* Arm code calling a Thumb function. */
2325 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2329 asection * input_section,
2330 bfd_byte * hit_data,
2333 bfd_signed_vma addend,
2336 unsigned long int tmp;
2339 long int ret_offset;
2340 struct elf_link_hash_entry * myh;
2341 struct elf32_arm_link_hash_table * globals;
2343 myh = find_arm_glue (info, name, input_bfd);
2347 globals = elf32_arm_hash_table (info);
2349 BFD_ASSERT (globals != NULL);
2350 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2352 my_offset = myh->root.u.def.value;
2353 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2354 ARM2THUMB_GLUE_SECTION_NAME);
2355 BFD_ASSERT (s != NULL);
2356 BFD_ASSERT (s->contents != NULL);
2357 BFD_ASSERT (s->output_section != NULL);
2359 if ((my_offset & 0x01) == 0x01)
2362 && sym_sec->owner != NULL
2363 && !INTERWORK_FLAG (sym_sec->owner))
2365 (*_bfd_error_handler)
2366 (_("%B(%s): warning: interworking not enabled.\n"
2367 " first occurrence: %B: arm call to thumb"),
2368 sym_sec->owner, input_bfd, name);
2372 myh->root.u.def.value = my_offset;
2374 if ((info->shared || globals->root.is_relocatable_executable))
2376 /* For relocatable objects we can't use absolute addresses,
2377 so construct the address from a relative offset. */
2378 /* TODO: If the offset is small it's probably worth
2379 constructing the address with adds. */
2380 bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn,
2381 s->contents + my_offset);
2382 bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn,
2383 s->contents + my_offset + 4);
2384 bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
2385 s->contents + my_offset + 8);
2386 /* Adjust the offset by 4 for the position of the add,
2387 and 8 for the pipeline offset. */
2388 ret_offset = (val - (s->output_offset
2389 + s->output_section->vma
2392 bfd_put_32 (output_bfd, ret_offset,
2393 s->contents + my_offset + 12);
2397 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2398 s->contents + my_offset);
2400 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2401 s->contents + my_offset + 4);
2403 /* It's a thumb address. Add the low order bit. */
2404 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2405 s->contents + my_offset + 8);
2409 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2411 tmp = bfd_get_32 (input_bfd, hit_data);
2412 tmp = tmp & 0xFF000000;
2414 /* Somehow these are both 4 too far, so subtract 8. */
2415 ret_offset = (s->output_offset
2417 + s->output_section->vma
2418 - (input_section->output_offset
2419 + input_section->output_section->vma
2423 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2425 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2432 /* Some relocations map to different relocations depending on the
2433 target. Return the real relocation. */
2435 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2441 if (globals->target1_is_rel)
2447 return globals->target2_reloc;
2453 #endif /* OLD_ARM_ABI */
2456 /* Return the base VMA address which should be subtracted from real addresses
2457 when resolving @dtpoff relocation.
2458 This is PT_TLS segment p_vaddr. */
2461 dtpoff_base (struct bfd_link_info *info)
2463 /* If tls_sec is NULL, we should have signalled an error already. */
2464 if (elf_hash_table (info)->tls_sec == NULL)
2466 return elf_hash_table (info)->tls_sec->vma;
2469 /* Return the relocation value for @tpoff relocation
2470 if STT_TLS virtual address is ADDRESS. */
2473 tpoff (struct bfd_link_info *info, bfd_vma address)
2475 struct elf_link_hash_table *htab = elf_hash_table (info);
2478 /* If tls_sec is NULL, we should have signalled an error already. */
2479 if (htab->tls_sec == NULL)
2481 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
2482 return address - htab->tls_sec->vma + base;
2485 /* Perform a relocation as part of a final link. */
2487 static bfd_reloc_status_type
2488 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2491 asection * input_section,
2492 bfd_byte * contents,
2493 Elf_Internal_Rela * rel,
2495 struct bfd_link_info * info,
2497 const char * sym_name,
2499 struct elf_link_hash_entry * h,
2500 bfd_boolean * unresolved_reloc_p)
2502 unsigned long r_type = howto->type;
2503 unsigned long r_symndx;
2504 bfd_byte * hit_data = contents + rel->r_offset;
2505 bfd * dynobj = NULL;
2506 Elf_Internal_Shdr * symtab_hdr;
2507 struct elf_link_hash_entry ** sym_hashes;
2508 bfd_vma * local_got_offsets;
2509 asection * sgot = NULL;
2510 asection * splt = NULL;
2511 asection * sreloc = NULL;
2513 bfd_signed_vma signed_addend;
2514 struct elf32_arm_link_hash_table * globals;
2516 globals = elf32_arm_hash_table (info);
2519 /* Some relocation type map to different relocations depending on the
2520 target. We pick the right one here. */
2521 r_type = arm_real_reloc_type (globals, r_type);
2522 if (r_type != howto->type)
2523 howto = elf32_arm_howto_from_type (r_type);
2524 #endif /* OLD_ARM_ABI */
2526 /* If the start address has been set, then set the EF_ARM_HASENTRY
2527 flag. Setting this more than once is redundant, but the cost is
2528 not too high, and it keeps the code simple.
2530 The test is done here, rather than somewhere else, because the
2531 start address is only set just before the final link commences.
2533 Note - if the user deliberately sets a start address of 0, the
2534 flag will not be set. */
2535 if (bfd_get_start_address (output_bfd) != 0)
2536 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2538 dynobj = elf_hash_table (info)->dynobj;
2541 sgot = bfd_get_section_by_name (dynobj, ".got");
2542 splt = bfd_get_section_by_name (dynobj, ".plt");
2544 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2545 sym_hashes = elf_sym_hashes (input_bfd);
2546 local_got_offsets = elf_local_got_offsets (input_bfd);
2547 r_symndx = ELF32_R_SYM (rel->r_info);
2549 if (globals->use_rel)
2551 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
2553 if (addend & ((howto->src_mask + 1) >> 1))
2556 signed_addend &= ~ howto->src_mask;
2557 signed_addend |= addend;
2560 signed_addend = addend;
2563 addend = signed_addend = rel->r_addend;
2568 /* We don't need to find a value for this symbol. It's just a
2570 *unresolved_reloc_p = FALSE;
2571 return bfd_reloc_ok;
2583 /* r_symndx will be zero only for relocs against symbols
2584 from removed linkonce sections, or sections discarded by
2587 return bfd_reloc_ok;
2589 /* Handle relocations which should use the PLT entry. ABS32/REL32
2590 will use the symbol's value, which may point to a PLT entry, but we
2591 don't need to handle that here. If we created a PLT entry, all
2592 branches in this object should go to it. */
2593 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
2596 && h->plt.offset != (bfd_vma) -1)
2598 /* If we've created a .plt section, and assigned a PLT entry to
2599 this function, it should not be known to bind locally. If
2600 it were, we would have cleared the PLT entry. */
2601 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
2603 value = (splt->output_section->vma
2604 + splt->output_offset
2606 *unresolved_reloc_p = FALSE;
2607 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2608 contents, rel->r_offset, value,
2612 /* When generating a shared object or relocatable executable, these
2613 relocations are copied into the output file to be resolved at
2615 if ((info->shared || globals->root.is_relocatable_executable)
2616 && (input_section->flags & SEC_ALLOC)
2617 && (r_type != R_ARM_REL32
2618 || !SYMBOL_CALLS_LOCAL (info, h))
2620 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2621 || h->root.type != bfd_link_hash_undefweak)
2622 && r_type != R_ARM_PC24
2624 && r_type != R_ARM_CALL
2625 && r_type != R_ARM_JUMP24
2626 && r_type != R_ARM_PREL31
2628 && r_type != R_ARM_PLT32)
2630 Elf_Internal_Rela outrel;
2632 bfd_boolean skip, relocate;
2634 *unresolved_reloc_p = FALSE;
2640 name = (bfd_elf_string_from_elf_section
2642 elf_elfheader (input_bfd)->e_shstrndx,
2643 elf_section_data (input_section)->rel_hdr.sh_name));
2645 return bfd_reloc_notsupported;
2647 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2648 && strcmp (bfd_get_section_name (input_bfd,
2652 sreloc = bfd_get_section_by_name (dynobj, name);
2653 BFD_ASSERT (sreloc != NULL);
2660 _bfd_elf_section_offset (output_bfd, info, input_section,
2662 if (outrel.r_offset == (bfd_vma) -1)
2664 else if (outrel.r_offset == (bfd_vma) -2)
2665 skip = TRUE, relocate = TRUE;
2666 outrel.r_offset += (input_section->output_section->vma
2667 + input_section->output_offset);
2670 memset (&outrel, 0, sizeof outrel);
2675 || !h->def_regular))
2676 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2681 /* This symbol is local, or marked to become local. */
2683 if (sym_flags == STT_ARM_TFUNC)
2685 if (globals->symbian_p)
2687 /* On Symbian OS, the data segment and text segement
2688 can be relocated independently. Therefore, we
2689 must indicate the segment to which this
2690 relocation is relative. The BPABI allows us to
2691 use any symbol in the right segment; we just use
2692 the section symbol as it is convenient. (We
2693 cannot use the symbol given by "h" directly as it
2694 will not appear in the dynamic symbol table.) */
2696 symbol = elf_section_data (sym_sec->output_section)->dynindx;
2698 symbol = elf_section_data (input_section->output_section)->dynindx;
2699 BFD_ASSERT (symbol != 0);
2702 /* On SVR4-ish systems, the dynamic loader cannot
2703 relocate the text and data segments independently,
2704 so the symbol does not matter. */
2706 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
2709 loc = sreloc->contents;
2710 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
2711 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2713 /* If this reloc is against an external symbol, we do not want to
2714 fiddle with the addend. Otherwise, we need to include the symbol
2715 value so that it becomes an addend for the dynamic reloc. */
2717 return bfd_reloc_ok;
2719 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2720 contents, rel->r_offset, value,
2723 else switch (r_type)
2726 case R_ARM_XPC25: /* Arm BLX instruction. */
2730 case R_ARM_PC24: /* Arm B/BL instruction */
2733 if (r_type == R_ARM_XPC25)
2735 /* Check for Arm calling Arm function. */
2736 /* FIXME: Should we translate the instruction into a BL
2737 instruction instead ? */
2738 if (sym_flags != STT_ARM_TFUNC)
2739 (*_bfd_error_handler)
2740 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
2742 h ? h->root.root.string : "(local)");
2747 /* Check for Arm calling Thumb function. */
2748 if (sym_flags == STT_ARM_TFUNC)
2750 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
2751 output_bfd, input_section,
2752 hit_data, sym_sec, rel->r_offset,
2753 signed_addend, value);
2754 return bfd_reloc_ok;
2758 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
2760 S is the address of the symbol in the relocation.
2761 P is address of the instruction being relocated.
2762 A is the addend (extracted from the instruction) in bytes.
2764 S is held in 'value'.
2765 P is the base address of the section containing the
2766 instruction plus the offset of the reloc into that
2768 (input_section->output_section->vma +
2769 input_section->output_offset +
2771 A is the addend, converted into bytes, ie:
2774 Note: None of these operations have knowledge of the pipeline
2775 size of the processor, thus it is up to the assembler to
2776 encode this information into the addend. */
2777 value -= (input_section->output_section->vma
2778 + input_section->output_offset);
2779 value -= rel->r_offset;
2780 if (globals->use_rel)
2781 value += (signed_addend << howto->size);
2783 /* RELA addends do not have to be adjusted by howto->size. */
2784 value += signed_addend;
2786 signed_addend = value;
2787 signed_addend >>= howto->rightshift;
2789 /* It is not an error for an undefined weak reference to be
2790 out of range. Any program that branches to such a symbol
2791 is going to crash anyway, so there is no point worrying
2792 about getting the destination exactly right. */
2793 if (! h || h->root.type != bfd_link_hash_undefweak)
2795 /* Perform a signed range check. */
2796 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
2797 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
2798 return bfd_reloc_overflow;
2802 /* If necessary set the H bit in the BLX instruction. */
2803 if (r_type == R_ARM_XPC25 && ((value & 2) == 2))
2804 value = (signed_addend & howto->dst_mask)
2805 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask))
2809 value = (signed_addend & howto->dst_mask)
2810 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
2815 if (sym_flags == STT_ARM_TFUNC)
2820 value -= (input_section->output_section->vma
2821 + input_section->output_offset + rel->r_offset);
2827 value -= (input_section->output_section->vma
2828 + input_section->output_offset + rel->r_offset);
2829 value += signed_addend;
2830 if (! h || h->root.type != bfd_link_hash_undefweak)
2832 /* Check for overflow */
2833 if ((value ^ (value >> 1)) & (1 << 30))
2834 return bfd_reloc_overflow;
2836 value &= 0x7fffffff;
2837 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
2838 if (sym_flags == STT_ARM_TFUNC)
2844 bfd_put_32 (input_bfd, value, hit_data);
2845 return bfd_reloc_ok;
2849 if ((long) value > 0x7f || (long) value < -0x80)
2850 return bfd_reloc_overflow;
2852 bfd_put_8 (input_bfd, value, hit_data);
2853 return bfd_reloc_ok;
2858 if ((long) value > 0x7fff || (long) value < -0x8000)
2859 return bfd_reloc_overflow;
2861 bfd_put_16 (input_bfd, value, hit_data);
2862 return bfd_reloc_ok;
2865 /* Support ldr and str instruction for the arm */
2866 /* Also thumb b (unconditional branch). ??? Really? */
2869 if ((long) value > 0x7ff || (long) value < -0x800)
2870 return bfd_reloc_overflow;
2872 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
2873 bfd_put_32 (input_bfd, value, hit_data);
2874 return bfd_reloc_ok;
2876 case R_ARM_THM_ABS5:
2877 /* Support ldr and str instructions for the thumb. */
2878 if (globals->use_rel)
2880 /* Need to refetch addend. */
2881 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
2882 /* ??? Need to determine shift amount from operand size. */
2883 addend >>= howto->rightshift;
2887 /* ??? Isn't value unsigned? */
2888 if ((long) value > 0x1f || (long) value < -0x10)
2889 return bfd_reloc_overflow;
2891 /* ??? Value needs to be properly shifted into place first. */
2892 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
2893 bfd_put_16 (input_bfd, value, hit_data);
2894 return bfd_reloc_ok;
2897 case R_ARM_THM_XPC22:
2899 case R_ARM_THM_PC22:
2900 /* Thumb BL (branch long instruction). */
2903 bfd_boolean overflow = FALSE;
2904 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
2905 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
2906 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
2907 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
2909 bfd_signed_vma signed_check;
2910 bfd_boolean thumb_plt_call = FALSE;
2912 /* Need to refetch the addend and squish the two 11 bit pieces
2914 if (globals->use_rel)
2916 bfd_vma upper = upper_insn & 0x7ff;
2917 bfd_vma lower = lower_insn & 0x7ff;
2918 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
2919 addend = (upper << 12) | (lower << 1);
2920 signed_addend = addend;
2923 if (r_type == R_ARM_THM_XPC22)
2925 /* Check for Thumb to Thumb call. */
2926 /* FIXME: Should we translate the instruction into a BL
2927 instruction instead ? */
2928 if (sym_flags == STT_ARM_TFUNC)
2929 (*_bfd_error_handler)
2930 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
2932 h ? h->root.root.string : "(local)");
2937 /* If it is not a call to Thumb, assume call to Arm.
2938 If it is a call relative to a section name, then it is not a
2939 function call at all, but rather a long jump. Calls through
2940 the PLT do not require stubs. */
2941 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
2942 && (h == NULL || splt == NULL
2943 || h->plt.offset == (bfd_vma) -1))
2945 if (elf32_thumb_to_arm_stub
2946 (info, sym_name, input_bfd, output_bfd, input_section,
2947 hit_data, sym_sec, rel->r_offset, signed_addend, value))
2948 return bfd_reloc_ok;
2950 return bfd_reloc_dangerous;
2954 /* Handle calls via the PLT. */
2955 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
2957 value = (splt->output_section->vma
2958 + splt->output_offset
2960 if (globals->use_blx)
2962 /* If the Thumb BLX instruction is available, convert the
2963 BL to a BLX instruction to call the ARM-mode PLT entry. */
2964 if ((lower_insn & (0x3 << 11)) == 0x3 << 11)
2966 lower_insn = (lower_insn & ~(0x3 << 11)) | 0x1 << 11;
2967 thumb_plt_call = TRUE;
2971 /* Target the Thumb stub before the ARM PLT entry. */
2972 value -= PLT_THUMB_STUB_SIZE;
2973 *unresolved_reloc_p = FALSE;
2976 relocation = value + signed_addend;
2978 relocation -= (input_section->output_section->vma
2979 + input_section->output_offset
2982 check = relocation >> howto->rightshift;
2984 /* If this is a signed value, the rightshift just dropped
2985 leading 1 bits (assuming twos complement). */
2986 if ((bfd_signed_vma) relocation >= 0)
2987 signed_check = check;
2989 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
2991 /* Assumes two's complement. */
2992 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
2996 if ((r_type == R_ARM_THM_XPC22
2997 && ((lower_insn & 0x1800) == 0x0800))
2999 /* For a BLX instruction, make sure that the relocation is rounded up
3000 to a word boundary. This follows the semantics of the instruction
3001 which specifies that bit 1 of the target address will come from bit
3002 1 of the base address. */
3003 relocation = (relocation + 2) & ~ 3;
3005 /* Put RELOCATION back into the insn. */
3006 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
3007 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
3009 /* Put the relocated value back in the object file: */
3010 bfd_put_16 (input_bfd, upper_insn, hit_data);
3011 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3013 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3017 case R_ARM_THM_PC11:
3019 /* Thumb B (branch) instruction). */
3021 bfd_signed_vma relocation;
3022 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
3023 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3024 bfd_signed_vma signed_check;
3026 if (globals->use_rel)
3028 /* Need to refetch addend. */
3029 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3030 if (addend & ((howto->src_mask + 1) >> 1))
3033 signed_addend &= ~ howto->src_mask;
3034 signed_addend |= addend;
3037 signed_addend = addend;
3038 /* The value in the insn has been right shifted. We need to
3039 undo this, so that we can perform the address calculation
3040 in terms of bytes. */
3041 signed_addend <<= howto->rightshift;
3043 relocation = value + signed_addend;
3045 relocation -= (input_section->output_section->vma
3046 + input_section->output_offset
3049 relocation >>= howto->rightshift;
3050 signed_check = relocation;
3051 relocation &= howto->dst_mask;
3052 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
3054 bfd_put_16 (input_bfd, relocation, hit_data);
3056 /* Assumes two's complement. */
3057 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3058 return bfd_reloc_overflow;
3060 return bfd_reloc_ok;
3064 case R_ARM_ALU_PCREL7_0:
3065 case R_ARM_ALU_PCREL15_8:
3066 case R_ARM_ALU_PCREL23_15:
3071 insn = bfd_get_32 (input_bfd, hit_data);
3072 if (globals->use_rel)
3074 /* Extract the addend. */
3075 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
3076 signed_addend = addend;
3078 relocation = value + signed_addend;
3080 relocation -= (input_section->output_section->vma
3081 + input_section->output_offset
3083 insn = (insn & ~0xfff)
3084 | ((howto->bitpos << 7) & 0xf00)
3085 | ((relocation >> howto->bitpos) & 0xff);
3086 bfd_put_32 (input_bfd, value, hit_data);
3088 return bfd_reloc_ok;
3091 case R_ARM_GNU_VTINHERIT:
3092 case R_ARM_GNU_VTENTRY:
3093 return bfd_reloc_ok;
3096 return bfd_reloc_notsupported;
3098 case R_ARM_GLOB_DAT:
3099 return bfd_reloc_notsupported;
3101 case R_ARM_JUMP_SLOT:
3102 return bfd_reloc_notsupported;
3104 case R_ARM_RELATIVE:
3105 return bfd_reloc_notsupported;
3108 /* Relocation is relative to the start of the
3109 global offset table. */
3111 BFD_ASSERT (sgot != NULL);
3113 return bfd_reloc_notsupported;
3115 /* If we are addressing a Thumb function, we need to adjust the
3116 address by one, so that attempts to call the function pointer will
3117 correctly interpret it as Thumb code. */
3118 if (sym_flags == STT_ARM_TFUNC)
3121 /* Note that sgot->output_offset is not involved in this
3122 calculation. We always want the start of .got. If we
3123 define _GLOBAL_OFFSET_TABLE in a different way, as is
3124 permitted by the ABI, we might have to change this
3126 value -= sgot->output_section->vma;
3127 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3128 contents, rel->r_offset, value,
3132 /* Use global offset table as symbol value. */
3133 BFD_ASSERT (sgot != NULL);
3136 return bfd_reloc_notsupported;
3138 *unresolved_reloc_p = FALSE;
3139 value = sgot->output_section->vma;
3140 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3141 contents, rel->r_offset, value,
3146 case R_ARM_GOT_PREL:
3148 /* Relocation is to the entry for this symbol in the
3149 global offset table. */
3151 return bfd_reloc_notsupported;
3158 off = h->got.offset;
3159 BFD_ASSERT (off != (bfd_vma) -1);
3160 dyn = globals->root.dynamic_sections_created;
3162 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3164 && SYMBOL_REFERENCES_LOCAL (info, h))
3165 || (ELF_ST_VISIBILITY (h->other)
3166 && h->root.type == bfd_link_hash_undefweak))
3168 /* This is actually a static link, or it is a -Bsymbolic link
3169 and the symbol is defined locally. We must initialize this
3170 entry in the global offset table. Since the offset must
3171 always be a multiple of 4, we use the least significant bit
3172 to record whether we have initialized it already.
3174 When doing a dynamic link, we create a .rel.got relocation
3175 entry to initialize the value. This is done in the
3176 finish_dynamic_symbol routine. */
3181 /* If we are addressing a Thumb function, we need to
3182 adjust the address by one, so that attempts to
3183 call the function pointer will correctly
3184 interpret it as Thumb code. */
3185 if (sym_flags == STT_ARM_TFUNC)
3188 bfd_put_32 (output_bfd, value, sgot->contents + off);
3193 *unresolved_reloc_p = FALSE;
3195 value = sgot->output_offset + off;
3201 BFD_ASSERT (local_got_offsets != NULL &&
3202 local_got_offsets[r_symndx] != (bfd_vma) -1);
3204 off = local_got_offsets[r_symndx];
3206 /* The offset must always be a multiple of 4. We use the
3207 least significant bit to record whether we have already
3208 generated the necessary reloc. */
3213 /* If we are addressing a Thumb function, we need to
3214 adjust the address by one, so that attempts to
3215 call the function pointer will correctly
3216 interpret it as Thumb code. */
3217 if (sym_flags == STT_ARM_TFUNC)
3220 bfd_put_32 (output_bfd, value, sgot->contents + off);
3225 Elf_Internal_Rela outrel;
3228 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
3229 BFD_ASSERT (srelgot != NULL);
3231 outrel.r_offset = (sgot->output_section->vma
3232 + sgot->output_offset
3234 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
3235 loc = srelgot->contents;
3236 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3237 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3240 local_got_offsets[r_symndx] |= 1;
3243 value = sgot->output_offset + off;
3245 if (r_type != R_ARM_GOT32)
3246 value += sgot->output_section->vma;
3248 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3249 contents, rel->r_offset, value,
3252 case R_ARM_TLS_LDO32:
3253 value = value - dtpoff_base (info);
3255 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3256 contents, rel->r_offset, value, (bfd_vma) 0);
3258 case R_ARM_TLS_LDM32:
3262 if (globals->sgot == NULL)
3265 off = globals->tls_ldm_got.offset;
3271 /* If we don't know the module number, create a relocation
3275 Elf_Internal_Rela outrel;
3278 if (globals->srelgot == NULL)
3281 outrel.r_offset = (globals->sgot->output_section->vma
3282 + globals->sgot->output_offset + off);
3283 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
3285 bfd_put_32 (output_bfd, 0, globals->sgot->contents + off);
3287 loc = globals->srelgot->contents;
3288 loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3289 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3292 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
3294 globals->tls_ldm_got.offset |= 1;
3297 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3298 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3300 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3301 contents, rel->r_offset, value,
3305 case R_ARM_TLS_GD32:
3306 case R_ARM_TLS_IE32:
3312 if (globals->sgot == NULL)
3319 dyn = globals->root.dynamic_sections_created;
3320 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3322 || !SYMBOL_REFERENCES_LOCAL (info, h)))
3324 *unresolved_reloc_p = FALSE;
3327 off = h->got.offset;
3328 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
3332 if (local_got_offsets == NULL)
3334 off = local_got_offsets[r_symndx];
3335 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
3338 if (tls_type == GOT_UNKNOWN)
3345 bfd_boolean need_relocs = FALSE;
3346 Elf_Internal_Rela outrel;
3347 bfd_byte *loc = NULL;
3350 /* The GOT entries have not been initialized yet. Do it
3351 now, and emit any relocations. If both an IE GOT and a
3352 GD GOT are necessary, we emit the GD first. */
3354 if ((info->shared || indx != 0)
3356 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3357 || h->root.type != bfd_link_hash_undefweak))
3360 if (globals->srelgot == NULL)
3362 loc = globals->srelgot->contents;
3363 loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel);
3366 if (tls_type & GOT_TLS_GD)
3370 outrel.r_offset = (globals->sgot->output_section->vma
3371 + globals->sgot->output_offset + cur_off);
3372 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
3373 bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off);
3375 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3376 globals->srelgot->reloc_count++;
3377 loc += sizeof (Elf32_External_Rel);
3380 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3381 globals->sgot->contents + cur_off + 4);
3384 bfd_put_32 (output_bfd, 0,
3385 globals->sgot->contents + cur_off + 4);
3387 outrel.r_info = ELF32_R_INFO (indx,
3388 R_ARM_TLS_DTPOFF32);
3389 outrel.r_offset += 4;
3390 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3391 globals->srelgot->reloc_count++;
3392 loc += sizeof (Elf32_External_Rel);
3397 /* If we are not emitting relocations for a
3398 general dynamic reference, then we must be in a
3399 static link or an executable link with the
3400 symbol binding locally. Mark it as belonging
3401 to module 1, the executable. */
3402 bfd_put_32 (output_bfd, 1,
3403 globals->sgot->contents + cur_off);
3404 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3405 globals->sgot->contents + cur_off + 4);
3411 if (tls_type & GOT_TLS_IE)
3415 outrel.r_offset = (globals->sgot->output_section->vma
3416 + globals->sgot->output_offset
3418 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
3421 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3422 globals->sgot->contents + cur_off);
3424 bfd_put_32 (output_bfd, 0,
3425 globals->sgot->contents + cur_off);
3427 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3428 globals->srelgot->reloc_count++;
3429 loc += sizeof (Elf32_External_Rel);
3432 bfd_put_32 (output_bfd, tpoff (info, value),
3433 globals->sgot->contents + cur_off);
3440 local_got_offsets[r_symndx] |= 1;
3443 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
3445 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3446 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3448 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3449 contents, rel->r_offset, value,
3453 case R_ARM_TLS_LE32:
3456 (*_bfd_error_handler)
3457 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
3458 input_bfd, input_section,
3459 (long) rel->r_offset, howto->name);
3463 value = tpoff (info, value);
3465 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3466 contents, rel->r_offset, value, (bfd_vma) 0);
3469 return bfd_reloc_notsupported;
3471 case R_ARM_AMP_VCALL9:
3472 return bfd_reloc_notsupported;
3474 case R_ARM_RSBREL32:
3475 return bfd_reloc_notsupported;
3477 case R_ARM_THM_RPC22:
3478 return bfd_reloc_notsupported;
3481 return bfd_reloc_notsupported;
3484 return bfd_reloc_notsupported;
3487 return bfd_reloc_notsupported;
3490 return bfd_reloc_notsupported;
3493 if (globals->fix_v4bx)
3495 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
3497 /* Ensure that we have a BX instruction. */
3498 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
3500 /* Preserve Rm (lowest four bits) and the condition code
3501 (highest four bits). Other bits encode MOV PC,Rm. */
3502 insn = (insn & 0xf000000f) | 0x01a0f000;
3504 bfd_put_32 (input_bfd, insn, hit_data);
3506 return bfd_reloc_ok;
3509 return bfd_reloc_notsupported;
3513 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
3515 arm_add_to_rel (bfd * abfd,
3517 reloc_howto_type * howto,
3518 bfd_signed_vma increment)
3520 bfd_signed_vma addend;
3522 if (howto->type == R_ARM_THM_PC22)
3524 int upper_insn, lower_insn;
3527 upper_insn = bfd_get_16 (abfd, address);
3528 lower_insn = bfd_get_16 (abfd, address + 2);
3529 upper = upper_insn & 0x7ff;
3530 lower = lower_insn & 0x7ff;
3532 addend = (upper << 12) | (lower << 1);
3533 addend += increment;
3536 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
3537 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
3539 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
3540 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
3546 contents = bfd_get_32 (abfd, address);
3548 /* Get the (signed) value from the instruction. */
3549 addend = contents & howto->src_mask;
3550 if (addend & ((howto->src_mask + 1) >> 1))
3552 bfd_signed_vma mask;
3555 mask &= ~ howto->src_mask;
3559 /* Add in the increment, (which is a byte value). */
3560 switch (howto->type)
3563 addend += increment;
3572 addend <<= howto->size;
3573 addend += increment;
3575 /* Should we check for overflow here ? */
3577 /* Drop any undesired bits. */
3578 addend >>= howto->rightshift;
3582 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
3584 bfd_put_32 (abfd, contents, address);
3588 #define IS_ARM_TLS_RELOC(R_TYPE) \
3589 ((R_TYPE) == R_ARM_TLS_GD32 \
3590 || (R_TYPE) == R_ARM_TLS_LDO32 \
3591 || (R_TYPE) == R_ARM_TLS_LDM32 \
3592 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
3593 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
3594 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
3595 || (R_TYPE) == R_ARM_TLS_LE32 \
3596 || (R_TYPE) == R_ARM_TLS_IE32)
3598 /* Relocate an ARM ELF section. */
3600 elf32_arm_relocate_section (bfd * output_bfd,
3601 struct bfd_link_info * info,
3603 asection * input_section,
3604 bfd_byte * contents,
3605 Elf_Internal_Rela * relocs,
3606 Elf_Internal_Sym * local_syms,
3607 asection ** local_sections)
3609 Elf_Internal_Shdr *symtab_hdr;
3610 struct elf_link_hash_entry **sym_hashes;
3611 Elf_Internal_Rela *rel;
3612 Elf_Internal_Rela *relend;
3614 struct elf32_arm_link_hash_table * globals;
3616 globals = elf32_arm_hash_table (info);
3617 if (info->relocatable && !globals->use_rel)
3620 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
3621 sym_hashes = elf_sym_hashes (input_bfd);
3624 relend = relocs + input_section->reloc_count;
3625 for (; rel < relend; rel++)
3628 reloc_howto_type * howto;
3629 unsigned long r_symndx;
3630 Elf_Internal_Sym * sym;
3632 struct elf_link_hash_entry * h;
3634 bfd_reloc_status_type r;
3637 bfd_boolean unresolved_reloc = FALSE;
3639 r_symndx = ELF32_R_SYM (rel->r_info);
3640 r_type = ELF32_R_TYPE (rel->r_info);
3641 r_type = arm_real_reloc_type (globals, r_type);
3643 if ( r_type == R_ARM_GNU_VTENTRY
3644 || r_type == R_ARM_GNU_VTINHERIT)
3647 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
3648 howto = bfd_reloc.howto;
3650 if (info->relocatable && globals->use_rel)
3652 /* This is a relocatable link. We don't have to change
3653 anything, unless the reloc is against a section symbol,
3654 in which case we have to adjust according to where the
3655 section symbol winds up in the output section. */
3656 if (r_symndx < symtab_hdr->sh_info)
3658 sym = local_syms + r_symndx;
3659 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3661 sec = local_sections[r_symndx];
3662 arm_add_to_rel (input_bfd, contents + rel->r_offset,
3664 (bfd_signed_vma) (sec->output_offset
3672 /* This is a final link. */
3677 if (r_symndx < symtab_hdr->sh_info)
3679 sym = local_syms + r_symndx;
3680 sym_type = ELF32_ST_TYPE (sym->st_info);
3681 sec = local_sections[r_symndx];
3682 if (globals->use_rel)
3684 relocation = (sec->output_section->vma
3685 + sec->output_offset
3687 if ((sec->flags & SEC_MERGE)
3688 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3691 bfd_vma addend, value;
3693 if (howto->rightshift)
3695 (*_bfd_error_handler)
3696 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
3697 input_bfd, input_section,
3698 (long) rel->r_offset, howto->name);
3702 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
3704 /* Get the (signed) value from the instruction. */
3705 addend = value & howto->src_mask;
3706 if (addend & ((howto->src_mask + 1) >> 1))
3708 bfd_signed_vma mask;
3711 mask &= ~ howto->src_mask;
3716 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
3718 addend += msec->output_section->vma + msec->output_offset;
3719 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
3720 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
3724 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3730 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3731 r_symndx, symtab_hdr, sym_hashes,
3733 unresolved_reloc, warned);
3739 name = h->root.root.string;
3742 name = (bfd_elf_string_from_elf_section
3743 (input_bfd, symtab_hdr->sh_link, sym->st_name));
3744 if (name == NULL || *name == '\0')
3745 name = bfd_section_name (input_bfd, sec);
3749 && r_type != R_ARM_NONE
3751 || h->root.type == bfd_link_hash_defined
3752 || h->root.type == bfd_link_hash_defweak)
3753 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
3755 (*_bfd_error_handler)
3756 ((sym_type == STT_TLS
3757 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
3758 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
3761 (long) rel->r_offset,
3766 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
3767 input_section, contents, rel,
3768 relocation, info, sec, name,
3769 (h ? ELF_ST_TYPE (h->type) :
3770 ELF_ST_TYPE (sym->st_info)), h,
3773 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3774 because such sections are not SEC_ALLOC and thus ld.so will
3775 not process them. */
3776 if (unresolved_reloc
3777 && !((input_section->flags & SEC_DEBUGGING) != 0
3780 (*_bfd_error_handler)
3781 (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"),
3782 input_bfd, input_section, (long) rel->r_offset,
3783 r_type, h->root.root.string);
3787 if (r != bfd_reloc_ok)
3789 const char * msg = (const char *) 0;
3793 case bfd_reloc_overflow:
3794 /* If the overflowing reloc was to an undefined symbol,
3795 we have already printed one error message and there
3796 is no point complaining again. */
3798 h->root.type != bfd_link_hash_undefined)
3799 && (!((*info->callbacks->reloc_overflow)
3800 (info, (h ? &h->root : NULL), name, howto->name,
3801 (bfd_vma) 0, input_bfd, input_section,
3806 case bfd_reloc_undefined:
3807 if (!((*info->callbacks->undefined_symbol)
3808 (info, name, input_bfd, input_section,
3809 rel->r_offset, TRUE)))
3813 case bfd_reloc_outofrange:
3814 msg = _("internal error: out of range error");
3817 case bfd_reloc_notsupported:
3818 msg = _("internal error: unsupported relocation error");
3821 case bfd_reloc_dangerous:
3822 msg = _("internal error: dangerous error");
3826 msg = _("internal error: unknown error");
3830 if (!((*info->callbacks->warning)
3831 (info, msg, name, input_bfd, input_section,
3842 /* Set the right machine number. */
3845 elf32_arm_object_p (bfd *abfd)
3849 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
3851 if (mach != bfd_mach_arm_unknown)
3852 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
3854 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
3855 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
3858 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
3863 /* Function to keep ARM specific flags in the ELF header. */
3866 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
3868 if (elf_flags_init (abfd)
3869 && elf_elfheader (abfd)->e_flags != flags)
3871 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
3873 if (flags & EF_ARM_INTERWORK)
3874 (*_bfd_error_handler)
3875 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
3879 (_("Warning: Clearing the interworking flag of %B due to outside request"),
3885 elf_elfheader (abfd)->e_flags = flags;
3886 elf_flags_init (abfd) = TRUE;
3892 /* Copy backend specific data from one object module to another. */
3895 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
3900 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3901 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3904 in_flags = elf_elfheader (ibfd)->e_flags;
3905 out_flags = elf_elfheader (obfd)->e_flags;
3907 if (elf_flags_init (obfd)
3908 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
3909 && in_flags != out_flags)
3911 /* Cannot mix APCS26 and APCS32 code. */
3912 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
3915 /* Cannot mix float APCS and non-float APCS code. */
3916 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
3919 /* If the src and dest have different interworking flags
3920 then turn off the interworking bit. */
3921 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
3923 if (out_flags & EF_ARM_INTERWORK)
3925 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
3928 in_flags &= ~EF_ARM_INTERWORK;
3931 /* Likewise for PIC, though don't warn for this case. */
3932 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
3933 in_flags &= ~EF_ARM_PIC;
3936 elf_elfheader (obfd)->e_flags = in_flags;
3937 elf_flags_init (obfd) = TRUE;
3939 /* Also copy the EI_OSABI field. */
3940 elf_elfheader (obfd)->e_ident[EI_OSABI] =
3941 elf_elfheader (ibfd)->e_ident[EI_OSABI];
3946 /* Merge backend specific data from an object file to the output
3947 object file when linking. */
3950 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
3954 bfd_boolean flags_compatible = TRUE;
3957 /* Check if we have the same endianess. */
3958 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
3961 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3962 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3965 /* The input BFD must have had its flags initialised. */
3966 /* The following seems bogus to me -- The flags are initialized in
3967 the assembler but I don't think an elf_flags_init field is
3968 written into the object. */
3969 /* BFD_ASSERT (elf_flags_init (ibfd)); */
3971 in_flags = elf_elfheader (ibfd)->e_flags;
3972 out_flags = elf_elfheader (obfd)->e_flags;
3974 if (!elf_flags_init (obfd))
3976 /* If the input is the default architecture and had the default
3977 flags then do not bother setting the flags for the output
3978 architecture, instead allow future merges to do this. If no
3979 future merges ever set these flags then they will retain their
3980 uninitialised values, which surprise surprise, correspond
3981 to the default values. */
3982 if (bfd_get_arch_info (ibfd)->the_default
3983 && elf_elfheader (ibfd)->e_flags == 0)
3986 elf_flags_init (obfd) = TRUE;
3987 elf_elfheader (obfd)->e_flags = in_flags;
3989 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3990 && bfd_get_arch_info (obfd)->the_default)
3991 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
3996 /* Determine what should happen if the input ARM architecture
3997 does not match the output ARM architecture. */
3998 if (! bfd_arm_merge_machines (ibfd, obfd))
4001 /* Identical flags must be compatible. */
4002 if (in_flags == out_flags)
4005 /* Check to see if the input BFD actually contains any sections. If
4006 not, its flags may not have been initialised either, but it
4007 cannot actually cause any incompatibility. Do not short-circuit
4008 dynamic objects; their section list may be emptied by
4009 elf_link_add_object_symbols.
4011 Also check to see if there are no code sections in the input.
4012 In this case there is no need to check for code specific flags.
4013 XXX - do we need to worry about floating-point format compatability
4014 in data sections ? */
4015 if (!(ibfd->flags & DYNAMIC))
4017 bfd_boolean null_input_bfd = TRUE;
4018 bfd_boolean only_data_sections = TRUE;
4020 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4022 /* Ignore synthetic glue sections. */
4023 if (strcmp (sec->name, ".glue_7")
4024 && strcmp (sec->name, ".glue_7t"))
4026 if ((bfd_get_section_flags (ibfd, sec)
4027 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
4028 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
4029 only_data_sections = FALSE;
4031 null_input_bfd = FALSE;
4036 if (null_input_bfd || only_data_sections)
4040 /* Complain about various flag mismatches. */
4041 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
4044 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
4046 (in_flags & EF_ARM_EABIMASK) >> 24,
4047 (out_flags & EF_ARM_EABIMASK) >> 24);
4051 /* Not sure what needs to be checked for EABI versions >= 1. */
4052 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
4054 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4057 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
4059 in_flags & EF_ARM_APCS_26 ? 26 : 32,
4060 out_flags & EF_ARM_APCS_26 ? 26 : 32);
4061 flags_compatible = FALSE;
4064 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4066 if (in_flags & EF_ARM_APCS_FLOAT)
4068 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
4072 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
4075 flags_compatible = FALSE;
4078 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
4080 if (in_flags & EF_ARM_VFP_FLOAT)
4082 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
4086 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
4089 flags_compatible = FALSE;
4092 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
4094 if (in_flags & EF_ARM_MAVERICK_FLOAT)
4096 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
4100 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
4103 flags_compatible = FALSE;
4106 #ifdef EF_ARM_SOFT_FLOAT
4107 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
4109 /* We can allow interworking between code that is VFP format
4110 layout, and uses either soft float or integer regs for
4111 passing floating point arguments and results. We already
4112 know that the APCS_FLOAT flags match; similarly for VFP
4114 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
4115 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
4117 if (in_flags & EF_ARM_SOFT_FLOAT)
4119 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
4123 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
4126 flags_compatible = FALSE;
4131 /* Interworking mismatch is only a warning. */
4132 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4134 if (in_flags & EF_ARM_INTERWORK)
4137 (_("Warning: %B supports interworking, whereas %B does not"),
4143 (_("Warning: %B does not support interworking, whereas %B does"),
4149 return flags_compatible;
4152 /* Display the flags field. */
4155 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
4157 FILE * file = (FILE *) ptr;
4158 unsigned long flags;
4160 BFD_ASSERT (abfd != NULL && ptr != NULL);
4162 /* Print normal ELF private data. */
4163 _bfd_elf_print_private_bfd_data (abfd, ptr);
4165 flags = elf_elfheader (abfd)->e_flags;
4166 /* Ignore init flag - it may not be set, despite the flags field
4167 containing valid data. */
4169 /* xgettext:c-format */
4170 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4172 switch (EF_ARM_EABI_VERSION (flags))
4174 case EF_ARM_EABI_UNKNOWN:
4175 /* The following flag bits are GNU extensions and not part of the
4176 official ARM ELF extended ABI. Hence they are only decoded if
4177 the EABI version is not set. */
4178 if (flags & EF_ARM_INTERWORK)
4179 fprintf (file, _(" [interworking enabled]"));
4181 if (flags & EF_ARM_APCS_26)
4182 fprintf (file, " [APCS-26]");
4184 fprintf (file, " [APCS-32]");
4186 if (flags & EF_ARM_VFP_FLOAT)
4187 fprintf (file, _(" [VFP float format]"));
4188 else if (flags & EF_ARM_MAVERICK_FLOAT)
4189 fprintf (file, _(" [Maverick float format]"));
4191 fprintf (file, _(" [FPA float format]"));
4193 if (flags & EF_ARM_APCS_FLOAT)
4194 fprintf (file, _(" [floats passed in float registers]"));
4196 if (flags & EF_ARM_PIC)
4197 fprintf (file, _(" [position independent]"));
4199 if (flags & EF_ARM_NEW_ABI)
4200 fprintf (file, _(" [new ABI]"));
4202 if (flags & EF_ARM_OLD_ABI)
4203 fprintf (file, _(" [old ABI]"));
4205 if (flags & EF_ARM_SOFT_FLOAT)
4206 fprintf (file, _(" [software FP]"));
4208 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
4209 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
4210 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
4211 | EF_ARM_MAVERICK_FLOAT);
4214 case EF_ARM_EABI_VER1:
4215 fprintf (file, _(" [Version1 EABI]"));
4217 if (flags & EF_ARM_SYMSARESORTED)
4218 fprintf (file, _(" [sorted symbol table]"));
4220 fprintf (file, _(" [unsorted symbol table]"));
4222 flags &= ~ EF_ARM_SYMSARESORTED;
4225 case EF_ARM_EABI_VER2:
4226 fprintf (file, _(" [Version2 EABI]"));
4228 if (flags & EF_ARM_SYMSARESORTED)
4229 fprintf (file, _(" [sorted symbol table]"));
4231 fprintf (file, _(" [unsorted symbol table]"));
4233 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
4234 fprintf (file, _(" [dynamic symbols use segment index]"));
4236 if (flags & EF_ARM_MAPSYMSFIRST)
4237 fprintf (file, _(" [mapping symbols precede others]"));
4239 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
4240 | EF_ARM_MAPSYMSFIRST);
4243 case EF_ARM_EABI_VER3:
4244 fprintf (file, _(" [Version3 EABI]"));
4247 case EF_ARM_EABI_VER4:
4248 fprintf (file, _(" [Version4 EABI]"));
4250 if (flags & EF_ARM_BE8)
4251 fprintf (file, _(" [BE8]"));
4253 if (flags & EF_ARM_LE8)
4254 fprintf (file, _(" [LE8]"));
4256 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
4260 fprintf (file, _(" <EABI version unrecognised>"));
4264 flags &= ~ EF_ARM_EABIMASK;
4266 if (flags & EF_ARM_RELEXEC)
4267 fprintf (file, _(" [relocatable executable]"));
4269 if (flags & EF_ARM_HASENTRY)
4270 fprintf (file, _(" [has entry point]"));
4272 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
4275 fprintf (file, _("<Unrecognised flag bits set>"));
4283 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
4285 switch (ELF_ST_TYPE (elf_sym->st_info))
4288 return ELF_ST_TYPE (elf_sym->st_info);
4291 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
4292 This allows us to distinguish between data used by Thumb instructions
4293 and non-data (which is probably code) inside Thumb regions of an
4295 if (type != STT_OBJECT)
4296 return ELF_ST_TYPE (elf_sym->st_info);
4307 elf32_arm_gc_mark_hook (asection * sec,
4308 struct bfd_link_info * info ATTRIBUTE_UNUSED,
4309 Elf_Internal_Rela * rel,
4310 struct elf_link_hash_entry * h,
4311 Elf_Internal_Sym * sym)
4315 switch (ELF32_R_TYPE (rel->r_info))
4317 case R_ARM_GNU_VTINHERIT:
4318 case R_ARM_GNU_VTENTRY:
4322 switch (h->root.type)
4324 case bfd_link_hash_defined:
4325 case bfd_link_hash_defweak:
4326 return h->root.u.def.section;
4328 case bfd_link_hash_common:
4329 return h->root.u.c.p->section;
4337 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4342 /* Update the got entry reference counts for the section being removed. */
4345 elf32_arm_gc_sweep_hook (bfd * abfd,
4346 struct bfd_link_info * info,
4348 const Elf_Internal_Rela * relocs)
4350 Elf_Internal_Shdr *symtab_hdr;
4351 struct elf_link_hash_entry **sym_hashes;
4352 bfd_signed_vma *local_got_refcounts;
4353 const Elf_Internal_Rela *rel, *relend;
4354 struct elf32_arm_link_hash_table * globals;
4356 globals = elf32_arm_hash_table (info);
4358 elf_section_data (sec)->local_dynrel = NULL;
4360 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4361 sym_hashes = elf_sym_hashes (abfd);
4362 local_got_refcounts = elf_local_got_refcounts (abfd);
4364 relend = relocs + sec->reloc_count;
4365 for (rel = relocs; rel < relend; rel++)
4367 unsigned long r_symndx;
4368 struct elf_link_hash_entry *h = NULL;
4371 r_symndx = ELF32_R_SYM (rel->r_info);
4372 if (r_symndx >= symtab_hdr->sh_info)
4374 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4375 while (h->root.type == bfd_link_hash_indirect
4376 || h->root.type == bfd_link_hash_warning)
4377 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4380 r_type = ELF32_R_TYPE (rel->r_info);
4382 r_type = arm_real_reloc_type (globals, r_type);
4388 case R_ARM_GOT_PREL:
4390 case R_ARM_TLS_GD32:
4391 case R_ARM_TLS_IE32:
4394 if (h->got.refcount > 0)
4395 h->got.refcount -= 1;
4397 else if (local_got_refcounts != NULL)
4399 if (local_got_refcounts[r_symndx] > 0)
4400 local_got_refcounts[r_symndx] -= 1;
4404 case R_ARM_TLS_LDM32:
4405 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
4417 case R_ARM_THM_PC22:
4418 /* Should the interworking branches be here also? */
4422 struct elf32_arm_link_hash_entry *eh;
4423 struct elf32_arm_relocs_copied **pp;
4424 struct elf32_arm_relocs_copied *p;
4426 eh = (struct elf32_arm_link_hash_entry *) h;
4428 if (h->plt.refcount > 0)
4430 h->plt.refcount -= 1;
4431 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_PC22)
4432 eh->plt_thumb_refcount--;
4435 if (r_type == R_ARM_ABS32
4436 || r_type == R_ARM_REL32)
4438 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
4440 if (p->section == sec)
4443 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
4461 /* Look through the relocs for a section during the first phase. */
4464 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
4465 asection *sec, const Elf_Internal_Rela *relocs)
4467 Elf_Internal_Shdr *symtab_hdr;
4468 struct elf_link_hash_entry **sym_hashes;
4469 struct elf_link_hash_entry **sym_hashes_end;
4470 const Elf_Internal_Rela *rel;
4471 const Elf_Internal_Rela *rel_end;
4474 bfd_vma *local_got_offsets;
4475 struct elf32_arm_link_hash_table *htab;
4477 if (info->relocatable)
4480 htab = elf32_arm_hash_table (info);
4483 /* Create dynamic sections for relocatable executables so that we can
4484 copy relocations. */
4485 if (htab->root.is_relocatable_executable
4486 && ! htab->root.dynamic_sections_created)
4488 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
4492 dynobj = elf_hash_table (info)->dynobj;
4493 local_got_offsets = elf_local_got_offsets (abfd);
4495 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4496 sym_hashes = elf_sym_hashes (abfd);
4497 sym_hashes_end = sym_hashes
4498 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
4500 if (!elf_bad_symtab (abfd))
4501 sym_hashes_end -= symtab_hdr->sh_info;
4503 rel_end = relocs + sec->reloc_count;
4504 for (rel = relocs; rel < rel_end; rel++)
4506 struct elf_link_hash_entry *h;
4507 struct elf32_arm_link_hash_entry *eh;
4508 unsigned long r_symndx;
4511 r_symndx = ELF32_R_SYM (rel->r_info);
4512 r_type = ELF32_R_TYPE (rel->r_info);
4514 r_type = arm_real_reloc_type (htab, r_type);
4517 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
4519 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
4524 if (r_symndx < symtab_hdr->sh_info)
4527 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4529 eh = (struct elf32_arm_link_hash_entry *) h;
4535 case R_ARM_GOT_PREL:
4537 case R_ARM_TLS_GD32:
4538 case R_ARM_TLS_IE32:
4539 /* This symbol requires a global offset table entry. */
4541 int tls_type, old_tls_type;
4545 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
4546 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
4547 default: tls_type = GOT_NORMAL; break;
4553 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
4557 bfd_signed_vma *local_got_refcounts;
4559 /* This is a global offset table entry for a local symbol. */
4560 local_got_refcounts = elf_local_got_refcounts (abfd);
4561 if (local_got_refcounts == NULL)
4565 size = symtab_hdr->sh_info;
4566 size *= (sizeof (bfd_signed_vma) + sizeof(char));
4567 local_got_refcounts = bfd_zalloc (abfd, size);
4568 if (local_got_refcounts == NULL)
4570 elf_local_got_refcounts (abfd) = local_got_refcounts;
4571 elf32_arm_local_got_tls_type (abfd)
4572 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
4574 local_got_refcounts[r_symndx] += 1;
4575 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
4578 /* We will already have issued an error message if there is a
4579 TLS / non-TLS mismatch, based on the symbol type. We don't
4580 support any linker relaxations. So just combine any TLS
4582 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
4583 && tls_type != GOT_NORMAL)
4584 tls_type |= old_tls_type;
4586 if (old_tls_type != tls_type)
4589 elf32_arm_hash_entry (h)->tls_type = tls_type;
4591 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
4596 case R_ARM_TLS_LDM32:
4597 if (r_type == R_ARM_TLS_LDM32)
4598 htab->tls_ldm_got.refcount++;
4603 if (htab->sgot == NULL)
4605 if (htab->root.dynobj == NULL)
4606 htab->root.dynobj = abfd;
4607 if (!create_got_section (htab->root.dynobj, info))
4621 case R_ARM_THM_PC22:
4622 /* Should the interworking branches be listed here? */
4625 /* If this reloc is in a read-only section, we might
4626 need a copy reloc. We can't check reliably at this
4627 stage whether the section is read-only, as input
4628 sections have not yet been mapped to output sections.
4629 Tentatively set the flag for now, and correct in
4630 adjust_dynamic_symbol. */
4634 /* We may need a .plt entry if the function this reloc
4635 refers to is in a different object. We can't tell for
4636 sure yet, because something later might force the
4638 if (r_type == R_ARM_PC24
4640 || r_type == R_ARM_CALL
4641 || r_type == R_ARM_JUMP24
4642 || r_type == R_ARM_PREL31
4644 || r_type == R_ARM_PLT32
4645 || r_type == R_ARM_THM_PC22)
4648 /* If we create a PLT entry, this relocation will reference
4649 it, even if it's an ABS32 relocation. */
4650 h->plt.refcount += 1;
4652 if (r_type == R_ARM_THM_PC22)
4653 eh->plt_thumb_refcount += 1;
4656 /* If we are creating a shared library or relocatable executable,
4657 and this is a reloc against a global symbol, or a non PC
4658 relative reloc against a local symbol, then we need to copy
4659 the reloc into the shared library. However, if we are linking
4660 with -Bsymbolic, we do not need to copy a reloc against a
4661 global symbol which is defined in an object we are
4662 including in the link (i.e., DEF_REGULAR is set). At
4663 this point we have not seen all the input files, so it is
4664 possible that DEF_REGULAR is not set now but will be set
4665 later (it is never cleared). We account for that
4666 possibility below by storing information in the
4667 relocs_copied field of the hash table entry. */
4668 if ((info->shared || htab->root.is_relocatable_executable)
4669 && (sec->flags & SEC_ALLOC) != 0
4670 && (r_type == R_ARM_ABS32
4671 || (h != NULL && ! h->needs_plt
4672 && (! info->symbolic || ! h->def_regular))))
4674 struct elf32_arm_relocs_copied *p, **head;
4676 /* When creating a shared object, we must copy these
4677 reloc types into the output file. We create a reloc
4678 section in dynobj and make room for this reloc. */
4683 name = (bfd_elf_string_from_elf_section
4685 elf_elfheader (abfd)->e_shstrndx,
4686 elf_section_data (sec)->rel_hdr.sh_name));
4690 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
4691 && strcmp (bfd_get_section_name (abfd, sec),
4694 sreloc = bfd_get_section_by_name (dynobj, name);
4699 flags = (SEC_HAS_CONTENTS | SEC_READONLY
4700 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4701 if ((sec->flags & SEC_ALLOC) != 0
4702 /* BPABI objects never have dynamic
4703 relocations mapped. */
4704 && !htab->symbian_p)
4705 flags |= SEC_ALLOC | SEC_LOAD;
4706 sreloc = bfd_make_section_with_flags (dynobj,
4710 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
4714 elf_section_data (sec)->sreloc = sreloc;
4717 /* If this is a global symbol, we count the number of
4718 relocations we need for this symbol. */
4721 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
4725 /* Track dynamic relocs needed for local syms too.
4726 We really need local syms available to do this
4730 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4735 head = ((struct elf32_arm_relocs_copied **)
4736 &elf_section_data (s)->local_dynrel);
4740 if (p == NULL || p->section != sec)
4742 bfd_size_type amt = sizeof *p;
4744 p = bfd_alloc (htab->root.dynobj, amt);
4754 if (r_type == R_ARM_REL32)
4760 /* This relocation describes the C++ object vtable hierarchy.
4761 Reconstruct it for later use during GC. */
4762 case R_ARM_GNU_VTINHERIT:
4763 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4767 /* This relocation describes which C++ vtable entries are actually
4768 used. Record for later use during GC. */
4769 case R_ARM_GNU_VTENTRY:
4770 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
4779 /* Treat mapping symbols as special target symbols. */
4782 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
4784 return bfd_is_arm_mapping_symbol_name (sym->name);
4787 /* This is a copy of elf_find_function() from elf.c except that
4788 ARM mapping symbols are ignored when looking for function names
4789 and STT_ARM_TFUNC is considered to a function type. */
4792 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
4796 const char ** filename_ptr,
4797 const char ** functionname_ptr)
4799 const char * filename = NULL;
4800 asymbol * func = NULL;
4801 bfd_vma low_func = 0;
4804 for (p = symbols; *p != NULL; p++)
4808 q = (elf_symbol_type *) *p;
4810 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
4815 filename = bfd_asymbol_name (&q->symbol);
4820 /* Skip $a and $t symbols. */
4821 if ((q->symbol.flags & BSF_LOCAL)
4822 && bfd_is_arm_mapping_symbol_name (q->symbol.name))
4825 if (bfd_get_section (&q->symbol) == section
4826 && q->symbol.value >= low_func
4827 && q->symbol.value <= offset)
4829 func = (asymbol *) q;
4830 low_func = q->symbol.value;
4840 *filename_ptr = filename;
4841 if (functionname_ptr)
4842 *functionname_ptr = bfd_asymbol_name (func);
4848 /* Find the nearest line to a particular section and offset, for error
4849 reporting. This code is a duplicate of the code in elf.c, except
4850 that it uses arm_elf_find_function. */
4853 elf32_arm_find_nearest_line (bfd * abfd,
4857 const char ** filename_ptr,
4858 const char ** functionname_ptr,
4859 unsigned int * line_ptr)
4861 bfd_boolean found = FALSE;
4863 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
4865 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
4866 filename_ptr, functionname_ptr,
4868 & elf_tdata (abfd)->dwarf2_find_line_info))
4870 if (!*functionname_ptr)
4871 arm_elf_find_function (abfd, section, symbols, offset,
4872 *filename_ptr ? NULL : filename_ptr,
4878 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
4879 & found, filename_ptr,
4880 functionname_ptr, line_ptr,
4881 & elf_tdata (abfd)->line_info))
4884 if (found && (*functionname_ptr || *line_ptr))
4887 if (symbols == NULL)
4890 if (! arm_elf_find_function (abfd, section, symbols, offset,
4891 filename_ptr, functionname_ptr))
4898 /* Adjust a symbol defined by a dynamic object and referenced by a
4899 regular object. The current definition is in some section of the
4900 dynamic object, but we're not including those sections. We have to
4901 change the definition to something the rest of the link can
4905 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
4906 struct elf_link_hash_entry * h)
4910 unsigned int power_of_two;
4911 struct elf32_arm_link_hash_entry * eh;
4912 struct elf32_arm_link_hash_table *globals;
4914 globals = elf32_arm_hash_table (info);
4915 dynobj = elf_hash_table (info)->dynobj;
4917 /* Make sure we know what is going on here. */
4918 BFD_ASSERT (dynobj != NULL
4920 || h->u.weakdef != NULL
4923 && !h->def_regular)));
4925 eh = (struct elf32_arm_link_hash_entry *) h;
4927 /* If this is a function, put it in the procedure linkage table. We
4928 will fill in the contents of the procedure linkage table later,
4929 when we know the address of the .got section. */
4930 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
4933 if (h->plt.refcount <= 0
4934 || SYMBOL_CALLS_LOCAL (info, h)
4935 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4936 && h->root.type == bfd_link_hash_undefweak))
4938 /* This case can occur if we saw a PLT32 reloc in an input
4939 file, but the symbol was never referred to by a dynamic
4940 object, or if all references were garbage collected. In
4941 such a case, we don't actually need to build a procedure
4942 linkage table, and we can just do a PC24 reloc instead. */
4943 h->plt.offset = (bfd_vma) -1;
4944 eh->plt_thumb_refcount = 0;
4952 /* It's possible that we incorrectly decided a .plt reloc was
4953 needed for an R_ARM_PC24 or similar reloc to a non-function sym
4954 in check_relocs. We can't decide accurately between function
4955 and non-function syms in check-relocs; Objects loaded later in
4956 the link may change h->type. So fix it now. */
4957 h->plt.offset = (bfd_vma) -1;
4958 eh->plt_thumb_refcount = 0;
4961 /* If this is a weak symbol, and there is a real definition, the
4962 processor independent code will have arranged for us to see the
4963 real definition first, and we can just use the same value. */
4964 if (h->u.weakdef != NULL)
4966 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4967 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4968 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4969 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4973 /* If there are no non-GOT references, we do not need a copy
4975 if (!h->non_got_ref)
4978 /* This is a reference to a symbol defined by a dynamic object which
4979 is not a function. */
4981 /* If we are creating a shared library, we must presume that the
4982 only references to the symbol are via the global offset table.
4983 For such cases we need not do anything here; the relocations will
4984 be handled correctly by relocate_section. Relocatable executables
4985 can reference data in shared objects directly, so we don't need to
4986 do anything here. */
4987 if (info->shared || globals->root.is_relocatable_executable)
4990 /* We must allocate the symbol in our .dynbss section, which will
4991 become part of the .bss section of the executable. There will be
4992 an entry for this symbol in the .dynsym section. The dynamic
4993 object will contain position independent code, so all references
4994 from the dynamic object to this symbol will go through the global
4995 offset table. The dynamic linker will use the .dynsym entry to
4996 determine the address it must put in the global offset table, so
4997 both the dynamic object and the regular object will refer to the
4998 same memory location for the variable. */
4999 s = bfd_get_section_by_name (dynobj, ".dynbss");
5000 BFD_ASSERT (s != NULL);
5002 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
5003 copy the initial value out of the dynamic object and into the
5004 runtime process image. We need to remember the offset into the
5005 .rel.bss section we are going to use. */
5006 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5010 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
5011 BFD_ASSERT (srel != NULL);
5012 srel->size += sizeof (Elf32_External_Rel);
5016 /* We need to figure out the alignment required for this symbol. I
5017 have no idea how ELF linkers handle this. */
5018 power_of_two = bfd_log2 (h->size);
5019 if (power_of_two > 3)
5022 /* Apply the required alignment. */
5023 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
5024 if (power_of_two > bfd_get_section_alignment (dynobj, s))
5026 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
5030 /* Define the symbol as being at this point in the section. */
5031 h->root.u.def.section = s;
5032 h->root.u.def.value = s->size;
5034 /* Increment the section size to make room for the symbol. */
5040 /* Allocate space in .plt, .got and associated reloc sections for
5044 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
5046 struct bfd_link_info *info;
5047 struct elf32_arm_link_hash_table *htab;
5048 struct elf32_arm_link_hash_entry *eh;
5049 struct elf32_arm_relocs_copied *p;
5051 eh = (struct elf32_arm_link_hash_entry *) h;
5053 if (h->root.type == bfd_link_hash_indirect)
5056 if (h->root.type == bfd_link_hash_warning)
5057 /* When warning symbols are created, they **replace** the "real"
5058 entry in the hash table, thus we never get to see the real
5059 symbol in a hash traversal. So look at it now. */
5060 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5062 info = (struct bfd_link_info *) inf;
5063 htab = elf32_arm_hash_table (info);
5065 if (htab->root.dynamic_sections_created
5066 && h->plt.refcount > 0)
5068 /* Make sure this symbol is output as a dynamic symbol.
5069 Undefined weak syms won't yet be marked as dynamic. */
5070 if (h->dynindx == -1
5071 && !h->forced_local)
5073 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5078 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
5080 asection *s = htab->splt;
5082 /* If this is the first .plt entry, make room for the special
5085 s->size += htab->plt_header_size;
5087 h->plt.offset = s->size;
5089 /* If we will insert a Thumb trampoline before this PLT, leave room
5091 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
5093 h->plt.offset += PLT_THUMB_STUB_SIZE;
5094 s->size += PLT_THUMB_STUB_SIZE;
5097 /* If this symbol is not defined in a regular file, and we are
5098 not generating a shared library, then set the symbol to this
5099 location in the .plt. This is required to make function
5100 pointers compare as equal between the normal executable and
5101 the shared library. */
5105 h->root.u.def.section = s;
5106 h->root.u.def.value = h->plt.offset;
5108 /* Make sure the function is not marked as Thumb, in case
5109 it is the target of an ABS32 relocation, which will
5110 point to the PLT entry. */
5111 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
5112 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
5115 /* Make room for this entry. */
5116 s->size += htab->plt_entry_size;
5118 if (!htab->symbian_p)
5120 /* We also need to make an entry in the .got.plt section, which
5121 will be placed in the .got section by the linker script. */
5122 eh->plt_got_offset = htab->sgotplt->size;
5123 htab->sgotplt->size += 4;
5126 /* We also need to make an entry in the .rel.plt section. */
5127 htab->srelplt->size += sizeof (Elf32_External_Rel);
5131 h->plt.offset = (bfd_vma) -1;
5137 h->plt.offset = (bfd_vma) -1;
5141 if (h->got.refcount > 0)
5145 int tls_type = elf32_arm_hash_entry (h)->tls_type;
5148 /* Make sure this symbol is output as a dynamic symbol.
5149 Undefined weak syms won't yet be marked as dynamic. */
5150 if (h->dynindx == -1
5151 && !h->forced_local)
5153 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5157 if (!htab->symbian_p)
5160 h->got.offset = s->size;
5162 if (tls_type == GOT_UNKNOWN)
5165 if (tls_type == GOT_NORMAL)
5166 /* Non-TLS symbols need one GOT slot. */
5170 if (tls_type & GOT_TLS_GD)
5171 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
5173 if (tls_type & GOT_TLS_IE)
5174 /* R_ARM_TLS_IE32 needs one GOT slot. */
5178 dyn = htab->root.dynamic_sections_created;
5181 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5183 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5186 if (tls_type != GOT_NORMAL
5187 && (info->shared || indx != 0)
5188 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5189 || h->root.type != bfd_link_hash_undefweak))
5191 if (tls_type & GOT_TLS_IE)
5192 htab->srelgot->size += sizeof (Elf32_External_Rel);
5194 if (tls_type & GOT_TLS_GD)
5195 htab->srelgot->size += sizeof (Elf32_External_Rel);
5197 if ((tls_type & GOT_TLS_GD) && indx != 0)
5198 htab->srelgot->size += sizeof (Elf32_External_Rel);
5200 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5201 || h->root.type != bfd_link_hash_undefweak)
5203 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
5204 htab->srelgot->size += sizeof (Elf32_External_Rel);
5208 h->got.offset = (bfd_vma) -1;
5210 if (eh->relocs_copied == NULL)
5213 /* In the shared -Bsymbolic case, discard space allocated for
5214 dynamic pc-relative relocs against symbols which turn out to be
5215 defined in regular objects. For the normal shared case, discard
5216 space for pc-relative relocs that have become local due to symbol
5217 visibility changes. */
5219 if (info->shared || htab->root.is_relocatable_executable)
5221 /* The only reloc that uses pc_count is R_ARM_REL32, which will
5222 appear on something like ".long foo - .". We want calls to
5223 protected symbols to resolve directly to the function rather
5224 than going via the plt. If people want function pointer
5225 comparisons to work as expected then they should avoid
5226 writing assembly like ".long foo - .". */
5227 if (SYMBOL_CALLS_LOCAL (info, h))
5229 struct elf32_arm_relocs_copied **pp;
5231 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
5233 p->count -= p->pc_count;
5242 /* Also discard relocs on undefined weak syms with non-default
5244 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5245 && h->root.type == bfd_link_hash_undefweak)
5246 eh->relocs_copied = NULL;
5247 else if (htab->root.is_relocatable_executable && h->dynindx == -1
5248 && h->root.type == bfd_link_hash_new)
5250 /* Output absolute symbols so that we can create relocations
5251 against them. For normal symbols we output a relocation
5252 against the section that contains them. */
5253 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5260 /* For the non-shared case, discard space for relocs against
5261 symbols which turn out to need copy relocs or are not
5267 || (htab->root.dynamic_sections_created
5268 && (h->root.type == bfd_link_hash_undefweak
5269 || h->root.type == bfd_link_hash_undefined))))
5271 /* Make sure this symbol is output as a dynamic symbol.
5272 Undefined weak syms won't yet be marked as dynamic. */
5273 if (h->dynindx == -1
5274 && !h->forced_local)
5276 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5280 /* If that succeeded, we know we'll be keeping all the
5282 if (h->dynindx != -1)
5286 eh->relocs_copied = NULL;
5291 /* Finally, allocate space. */
5292 for (p = eh->relocs_copied; p != NULL; p = p->next)
5294 asection *sreloc = elf_section_data (p->section)->sreloc;
5295 sreloc->size += p->count * sizeof (Elf32_External_Rel);
5301 /* Find any dynamic relocs that apply to read-only sections. */
5304 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
5306 struct elf32_arm_link_hash_entry *eh;
5307 struct elf32_arm_relocs_copied *p;
5309 if (h->root.type == bfd_link_hash_warning)
5310 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5312 eh = (struct elf32_arm_link_hash_entry *) h;
5313 for (p = eh->relocs_copied; p != NULL; p = p->next)
5315 asection *s = p->section;
5317 if (s != NULL && (s->flags & SEC_READONLY) != 0)
5319 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5321 info->flags |= DF_TEXTREL;
5323 /* Not an error, just cut short the traversal. */
5330 /* Set the sizes of the dynamic sections. */
5333 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
5334 struct bfd_link_info * info)
5341 struct elf32_arm_link_hash_table *htab;
5343 htab = elf32_arm_hash_table (info);
5344 dynobj = elf_hash_table (info)->dynobj;
5345 BFD_ASSERT (dynobj != NULL);
5347 if (elf_hash_table (info)->dynamic_sections_created)
5349 /* Set the contents of the .interp section to the interpreter. */
5350 if (info->executable)
5352 s = bfd_get_section_by_name (dynobj, ".interp");
5353 BFD_ASSERT (s != NULL);
5354 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5355 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5359 /* Set up .got offsets for local syms, and space for local dynamic
5361 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5363 bfd_signed_vma *local_got;
5364 bfd_signed_vma *end_local_got;
5365 char *local_tls_type;
5366 bfd_size_type locsymcount;
5367 Elf_Internal_Shdr *symtab_hdr;
5370 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
5373 for (s = ibfd->sections; s != NULL; s = s->next)
5375 struct elf32_arm_relocs_copied *p;
5377 for (p = *((struct elf32_arm_relocs_copied **)
5378 &elf_section_data (s)->local_dynrel);
5382 if (!bfd_is_abs_section (p->section)
5383 && bfd_is_abs_section (p->section->output_section))
5385 /* Input section has been discarded, either because
5386 it is a copy of a linkonce section or due to
5387 linker script /DISCARD/, so we'll be discarding
5390 else if (p->count != 0)
5392 srel = elf_section_data (p->section)->sreloc;
5393 srel->size += p->count * sizeof (Elf32_External_Rel);
5394 if ((p->section->output_section->flags & SEC_READONLY) != 0)
5395 info->flags |= DF_TEXTREL;
5400 local_got = elf_local_got_refcounts (ibfd);
5404 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5405 locsymcount = symtab_hdr->sh_info;
5406 end_local_got = local_got + locsymcount;
5407 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
5409 srel = htab->srelgot;
5410 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
5414 *local_got = s->size;
5415 if (*local_tls_type & GOT_TLS_GD)
5416 /* TLS_GD relocs need an 8-byte structure in the GOT. */
5418 if (*local_tls_type & GOT_TLS_IE)
5420 if (*local_tls_type == GOT_NORMAL)
5423 if (info->shared || *local_tls_type == GOT_TLS_GD)
5424 srel->size += sizeof (Elf32_External_Rel);
5427 *local_got = (bfd_vma) -1;
5431 if (htab->tls_ldm_got.refcount > 0)
5433 /* Allocate two GOT entries and one dynamic relocation (if necessary)
5434 for R_ARM_TLS_LDM32 relocations. */
5435 htab->tls_ldm_got.offset = htab->sgot->size;
5436 htab->sgot->size += 8;
5438 htab->srelgot->size += sizeof (Elf32_External_Rel);
5441 htab->tls_ldm_got.offset = -1;
5443 /* Allocate global sym .plt and .got entries, and space for global
5444 sym dynamic relocs. */
5445 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
5447 /* The check_relocs and adjust_dynamic_symbol entry points have
5448 determined the sizes of the various dynamic sections. Allocate
5452 for (s = dynobj->sections; s != NULL; s = s->next)
5457 if ((s->flags & SEC_LINKER_CREATED) == 0)
5460 /* It's OK to base decisions on the section name, because none
5461 of the dynobj section names depend upon the input files. */
5462 name = bfd_get_section_name (dynobj, s);
5466 if (strcmp (name, ".plt") == 0)
5470 /* Strip this section if we don't need it; see the
5476 /* Remember whether there is a PLT. */
5480 else if (strncmp (name, ".rel", 4) == 0)
5484 /* If we don't need this section, strip it from the
5485 output file. This is mostly to handle .rel.bss and
5486 .rel.plt. We must create both sections in
5487 create_dynamic_sections, because they must be created
5488 before the linker maps input sections to output
5489 sections. The linker does that before
5490 adjust_dynamic_symbol is called, and it is that
5491 function which decides whether anything needs to go
5492 into these sections. */
5497 /* Remember whether there are any reloc sections other
5499 if (strcmp (name, ".rel.plt") != 0)
5502 /* We use the reloc_count field as a counter if we need
5503 to copy relocs into the output file. */
5507 else if (strncmp (name, ".got", 4) != 0)
5509 /* It's not one of our sections, so don't allocate space. */
5515 s->flags |= SEC_EXCLUDE;
5519 /* Allocate memory for the section contents. */
5520 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
5521 if (s->contents == NULL && s->size != 0)
5525 if (elf_hash_table (info)->dynamic_sections_created)
5527 /* Add some entries to the .dynamic section. We fill in the
5528 values later, in elf32_arm_finish_dynamic_sections, but we
5529 must add the entries now so that we get the correct size for
5530 the .dynamic section. The DT_DEBUG entry is filled in by the
5531 dynamic linker and used by the debugger. */
5532 #define add_dynamic_entry(TAG, VAL) \
5533 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5537 if (!add_dynamic_entry (DT_DEBUG, 0))
5543 if ( !add_dynamic_entry (DT_PLTGOT, 0)
5544 || !add_dynamic_entry (DT_PLTRELSZ, 0)
5545 || !add_dynamic_entry (DT_PLTREL, DT_REL)
5546 || !add_dynamic_entry (DT_JMPREL, 0))
5552 if ( !add_dynamic_entry (DT_REL, 0)
5553 || !add_dynamic_entry (DT_RELSZ, 0)
5554 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
5558 /* If any dynamic relocs apply to a read-only section,
5559 then we need a DT_TEXTREL entry. */
5560 if ((info->flags & DF_TEXTREL) == 0)
5561 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
5564 if ((info->flags & DF_TEXTREL) != 0)
5566 if (!add_dynamic_entry (DT_TEXTREL, 0))
5568 info->flags |= DF_TEXTREL;
5571 #undef add_synamic_entry
5576 /* Finish up dynamic symbol handling. We set the contents of various
5577 dynamic sections here. */
5580 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
5581 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
5584 struct elf32_arm_link_hash_table *htab;
5585 struct elf32_arm_link_hash_entry *eh;
5587 dynobj = elf_hash_table (info)->dynobj;
5588 htab = elf32_arm_hash_table (info);
5589 eh = (struct elf32_arm_link_hash_entry *) h;
5591 if (h->plt.offset != (bfd_vma) -1)
5597 Elf_Internal_Rela rel;
5599 /* This symbol has an entry in the procedure linkage table. Set
5602 BFD_ASSERT (h->dynindx != -1);
5604 splt = bfd_get_section_by_name (dynobj, ".plt");
5605 srel = bfd_get_section_by_name (dynobj, ".rel.plt");
5606 BFD_ASSERT (splt != NULL && srel != NULL);
5608 /* Fill in the entry in the procedure linkage table. */
5609 if (htab->symbian_p)
5612 for (i = 0; i < htab->plt_entry_size / 4; ++i)
5613 bfd_put_32 (output_bfd,
5614 elf32_arm_symbian_plt_entry[i],
5615 splt->contents + h->plt.offset + 4 * i);
5617 /* Fill in the entry in the .rel.plt section. */
5618 rel.r_offset = (splt->output_section->vma
5619 + splt->output_offset
5620 + h->plt.offset + 4 * (i - 1));
5621 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
5623 /* Get the index in the procedure linkage table which
5624 corresponds to this symbol. This is the index of this symbol
5625 in all the symbols for which we are making plt entries. The
5626 first entry in the procedure linkage table is reserved. */
5627 plt_index = ((h->plt.offset - htab->plt_header_size)
5628 / htab->plt_entry_size);
5633 bfd_vma got_displacement;
5636 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
5637 BFD_ASSERT (sgot != NULL);
5639 /* Get the offset into the .got.plt table of the entry that
5640 corresponds to this function. */
5641 got_offset = eh->plt_got_offset;
5643 /* Get the index in the procedure linkage table which
5644 corresponds to this symbol. This is the index of this symbol
5645 in all the symbols for which we are making plt entries. The
5646 first three entries in .got.plt are reserved; after that
5647 symbols appear in the same order as in .plt. */
5648 plt_index = (got_offset - 12) / 4;
5650 /* Calculate the displacement between the PLT slot and the
5651 entry in the GOT. The eight-byte offset accounts for the
5652 value produced by adding to pc in the first instruction
5654 got_displacement = (sgot->output_section->vma
5655 + sgot->output_offset
5657 - splt->output_section->vma
5658 - splt->output_offset
5662 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
5664 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
5666 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
5667 splt->contents + h->plt.offset - 4);
5668 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
5669 splt->contents + h->plt.offset - 2);
5672 bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20),
5673 splt->contents + h->plt.offset + 0);
5674 bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12),
5675 splt->contents + h->plt.offset + 4);
5676 bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff),
5677 splt->contents + h->plt.offset + 8);
5678 #ifdef FOUR_WORD_PLT
5679 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
5680 splt->contents + h->plt.offset + 12);
5683 /* Fill in the entry in the global offset table. */
5684 bfd_put_32 (output_bfd,
5685 (splt->output_section->vma
5686 + splt->output_offset),
5687 sgot->contents + got_offset);
5689 /* Fill in the entry in the .rel.plt section. */
5690 rel.r_offset = (sgot->output_section->vma
5691 + sgot->output_offset
5693 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
5696 loc = srel->contents + plt_index * sizeof (Elf32_External_Rel);
5697 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5699 if (!h->def_regular)
5701 /* Mark the symbol as undefined, rather than as defined in
5702 the .plt section. Leave the value alone. */
5703 sym->st_shndx = SHN_UNDEF;
5704 /* If the symbol is weak, we do need to clear the value.
5705 Otherwise, the PLT entry would provide a definition for
5706 the symbol even if the symbol wasn't defined anywhere,
5707 and so the symbol would never be NULL. */
5708 if (!h->ref_regular_nonweak)
5713 if (h->got.offset != (bfd_vma) -1
5714 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
5715 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
5719 Elf_Internal_Rela rel;
5722 /* This symbol has an entry in the global offset table. Set it
5724 sgot = bfd_get_section_by_name (dynobj, ".got");
5725 srel = bfd_get_section_by_name (dynobj, ".rel.got");
5726 BFD_ASSERT (sgot != NULL && srel != NULL);
5728 rel.r_offset = (sgot->output_section->vma
5729 + sgot->output_offset
5730 + (h->got.offset &~ (bfd_vma) 1));
5732 /* If this is a static link, or it is a -Bsymbolic link and the
5733 symbol is defined locally or was forced to be local because
5734 of a version file, we just want to emit a RELATIVE reloc.
5735 The entry in the global offset table will already have been
5736 initialized in the relocate_section function. */
5738 && SYMBOL_REFERENCES_LOCAL (info, h))
5740 BFD_ASSERT((h->got.offset & 1) != 0);
5741 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5745 BFD_ASSERT((h->got.offset & 1) == 0);
5746 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
5747 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
5750 loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel);
5751 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5757 Elf_Internal_Rela rel;
5760 /* This symbol needs a copy reloc. Set it up. */
5761 BFD_ASSERT (h->dynindx != -1
5762 && (h->root.type == bfd_link_hash_defined
5763 || h->root.type == bfd_link_hash_defweak));
5765 s = bfd_get_section_by_name (h->root.u.def.section->owner,
5767 BFD_ASSERT (s != NULL);
5769 rel.r_offset = (h->root.u.def.value
5770 + h->root.u.def.section->output_section->vma
5771 + h->root.u.def.section->output_offset);
5772 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
5773 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel);
5774 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5777 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5778 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5779 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
5780 sym->st_shndx = SHN_ABS;
5785 /* Finish up the dynamic sections. */
5788 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
5794 dynobj = elf_hash_table (info)->dynobj;
5796 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
5797 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
5798 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5800 if (elf_hash_table (info)->dynamic_sections_created)
5803 Elf32_External_Dyn *dyncon, *dynconend;
5804 struct elf32_arm_link_hash_table *htab;
5806 htab = elf32_arm_hash_table (info);
5807 splt = bfd_get_section_by_name (dynobj, ".plt");
5808 BFD_ASSERT (splt != NULL && sdyn != NULL);
5810 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5811 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5813 for (; dyncon < dynconend; dyncon++)
5815 Elf_Internal_Dyn dyn;
5819 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5830 goto get_vma_if_bpabi;
5833 goto get_vma_if_bpabi;
5836 goto get_vma_if_bpabi;
5838 name = ".gnu.version";
5839 goto get_vma_if_bpabi;
5841 name = ".gnu.version_d";
5842 goto get_vma_if_bpabi;
5844 name = ".gnu.version_r";
5845 goto get_vma_if_bpabi;
5853 s = bfd_get_section_by_name (output_bfd, name);
5854 BFD_ASSERT (s != NULL);
5855 if (!htab->symbian_p)
5856 dyn.d_un.d_ptr = s->vma;
5858 /* In the BPABI, tags in the PT_DYNAMIC section point
5859 at the file offset, not the memory address, for the
5860 convenience of the post linker. */
5861 dyn.d_un.d_ptr = s->filepos;
5862 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5866 if (htab->symbian_p)
5871 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
5872 BFD_ASSERT (s != NULL);
5873 dyn.d_un.d_val = s->size;
5874 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5878 if (!htab->symbian_p)
5880 /* My reading of the SVR4 ABI indicates that the
5881 procedure linkage table relocs (DT_JMPREL) should be
5882 included in the overall relocs (DT_REL). This is
5883 what Solaris does. However, UnixWare can not handle
5884 that case. Therefore, we override the DT_RELSZ entry
5885 here to make it not include the JMPREL relocs. Since
5886 the linker script arranges for .rel.plt to follow all
5887 other relocation sections, we don't have to worry
5888 about changing the DT_REL entry. */
5889 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
5891 dyn.d_un.d_val -= s->size;
5892 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5900 /* In the BPABI, the DT_REL tag must point at the file
5901 offset, not the VMA, of the first relocation
5902 section. So, we use code similar to that in
5903 elflink.c, but do not check for SHF_ALLOC on the
5904 relcoation section, since relocations sections are
5905 never allocated under the BPABI. The comments above
5906 about Unixware notwithstanding, we include all of the
5907 relocations here. */
5908 if (htab->symbian_p)
5911 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
5912 ? SHT_REL : SHT_RELA);
5914 for (i = 1; i < elf_numsections (output_bfd); i++)
5916 Elf_Internal_Shdr *hdr
5917 = elf_elfsections (output_bfd)[i];
5918 if (hdr->sh_type == type)
5920 if (dyn.d_tag == DT_RELSZ
5921 || dyn.d_tag == DT_RELASZ)
5922 dyn.d_un.d_val += hdr->sh_size;
5923 else if ((ufile_ptr) hdr->sh_offset
5924 <= dyn.d_un.d_val - 1)
5925 dyn.d_un.d_val = hdr->sh_offset;
5928 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5932 /* Set the bottom bit of DT_INIT/FINI if the
5933 corresponding function is Thumb. */
5935 name = info->init_function;
5938 name = info->fini_function;
5940 /* If it wasn't set by elf_bfd_final_link
5941 then there is nothing to adjust. */
5942 if (dyn.d_un.d_val != 0)
5944 struct elf_link_hash_entry * eh;
5946 eh = elf_link_hash_lookup (elf_hash_table (info), name,
5947 FALSE, FALSE, TRUE);
5948 if (eh != (struct elf_link_hash_entry *) NULL
5949 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
5951 dyn.d_un.d_val |= 1;
5952 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5959 /* Fill in the first entry in the procedure linkage table. */
5960 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
5962 bfd_vma got_displacement;
5964 /* Calculate the displacement between the PLT slot and &GOT[0]. */
5965 got_displacement = (sgot->output_section->vma
5966 + sgot->output_offset
5967 - splt->output_section->vma
5968 - splt->output_offset
5971 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
5972 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
5973 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
5974 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
5975 #ifdef FOUR_WORD_PLT
5976 /* The displacement value goes in the otherwise-unused last word of
5977 the second entry. */
5978 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
5980 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
5984 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5985 really seem like the right value. */
5986 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
5989 /* Fill in the first three entries in the global offset table. */
5995 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5997 bfd_put_32 (output_bfd,
5998 sdyn->output_section->vma + sdyn->output_offset,
6000 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
6001 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
6004 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
6011 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
6013 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
6014 struct elf32_arm_link_hash_table *globals;
6016 i_ehdrp = elf_elfheader (abfd);
6018 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
6019 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
6021 i_ehdrp->e_ident[EI_OSABI] = 0;
6022 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
6026 globals = elf32_arm_hash_table (link_info);
6027 if (globals->byteswap_code)
6028 i_ehdrp->e_flags |= EF_ARM_BE8;
6032 static enum elf_reloc_type_class
6033 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
6035 switch ((int) ELF32_R_TYPE (rela->r_info))
6037 case R_ARM_RELATIVE:
6038 return reloc_class_relative;
6039 case R_ARM_JUMP_SLOT:
6040 return reloc_class_plt;
6042 return reloc_class_copy;
6044 return reloc_class_normal;
6048 /* Set the right machine number for an Arm ELF file. */
6051 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
6053 if (hdr->sh_type == SHT_NOTE)
6054 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
6060 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
6062 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
6065 /* Return TRUE if this is an unwinding table entry. */
6068 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
6072 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
6073 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
6074 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
6075 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
6079 /* Set the type and flags for an ARM section. We do this by
6080 the section name, which is a hack, but ought to work. */
6083 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
6087 name = bfd_get_section_name (abfd, sec);
6089 if (is_arm_elf_unwind_section_name (abfd, name))
6091 hdr->sh_type = SHT_ARM_EXIDX;
6092 hdr->sh_flags |= SHF_LINK_ORDER;
6097 /* Handle an ARM specific section when reading an object file. This is
6098 called when bfd_section_from_shdr finds a section with an unknown
6102 elf32_arm_section_from_shdr (bfd *abfd,
6103 Elf_Internal_Shdr * hdr,
6107 /* There ought to be a place to keep ELF backend specific flags, but
6108 at the moment there isn't one. We just keep track of the
6109 sections by their name, instead. Fortunately, the ABI gives
6110 names for all the ARM specific sections, so we will probably get
6112 switch (hdr->sh_type)
6121 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6127 /* Called for each symbol. Builds a section map based on mapping symbols.
6128 Does not alter any of the symbols. */
6131 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
6133 Elf_Internal_Sym *elfsym,
6134 asection *input_sec,
6135 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
6138 elf32_arm_section_map *map;
6139 struct elf32_arm_link_hash_table *globals;
6141 /* Only do this on final link. */
6142 if (info->relocatable)
6145 /* Only build a map if we need to byteswap code. */
6146 globals = elf32_arm_hash_table (info);
6147 if (!globals->byteswap_code)
6150 /* We only want mapping symbols. */
6151 if (! bfd_is_arm_mapping_symbol_name (name))
6154 mapcount = ++(elf32_arm_section_data (input_sec)->mapcount);
6155 map = elf32_arm_section_data (input_sec)->map;
6156 /* TODO: This may be inefficient, but we probably don't usually have many
6157 mapping symbols per section. */
6158 map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map));
6159 elf32_arm_section_data (input_sec)->map = map;
6161 map[mapcount - 1].vma = elfsym->st_value;
6162 map[mapcount - 1].type = name[1];
6167 /* Allocate target specific section data. */
6170 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
6172 struct _arm_elf_section_data *sdata;
6173 bfd_size_type amt = sizeof (*sdata);
6175 sdata = bfd_zalloc (abfd, amt);
6178 sec->used_by_bfd = sdata;
6180 return _bfd_elf_new_section_hook (abfd, sec);
6184 /* Used to order a list of mapping symbols by address. */
6187 elf32_arm_compare_mapping (const void * a, const void * b)
6189 return ((const elf32_arm_section_map *) a)->vma
6190 > ((const elf32_arm_section_map *) b)->vma;
6194 /* Do code byteswapping. Return FALSE afterwards so that the section is
6195 written out as normal. */
6198 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
6202 elf32_arm_section_map *map;
6209 mapcount = elf32_arm_section_data (sec)->mapcount;
6210 map = elf32_arm_section_data (sec)->map;
6215 qsort (map, mapcount, sizeof (elf32_arm_section_map),
6216 elf32_arm_compare_mapping);
6218 offset = sec->output_section->vma + sec->output_offset;
6219 ptr = map[0].vma - offset;
6220 for (i = 0; i < mapcount; i++)
6222 if (i == mapcount - 1)
6225 end = map[i + 1].vma - offset;
6227 switch (map[i].type)
6230 /* Byte swap code words. */
6231 while (ptr + 3 < end)
6233 tmp = contents[ptr];
6234 contents[ptr] = contents[ptr + 3];
6235 contents[ptr + 3] = tmp;
6236 tmp = contents[ptr + 1];
6237 contents[ptr + 1] = contents[ptr + 2];
6238 contents[ptr + 2] = tmp;
6244 /* Byte swap code halfwords. */
6245 while (ptr + 1 < end)
6247 tmp = contents[ptr];
6248 contents[ptr] = contents[ptr + 1];
6249 contents[ptr + 1] = tmp;
6255 /* Leave data alone. */
6264 /* Display STT_ARM_TFUNC symbols as functions. */
6267 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
6270 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
6272 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
6273 elfsym->symbol.flags |= BSF_FUNCTION;
6277 /* Mangle thumb function symbols as we read them in. */
6280 elf32_arm_swap_symbol_in (bfd * abfd,
6283 Elf_Internal_Sym *dst)
6285 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
6287 /* New EABI objects mark thumb function symbols by setting the low bit of
6288 the address. Turn these into STT_ARM_TFUNC. */
6289 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
6290 && (dst->st_value & 1))
6292 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
6293 dst->st_value &= ~(bfd_vma) 1;
6298 /* Mangle thumb function symbols as we write them out. */
6301 elf32_arm_swap_symbol_out (bfd *abfd,
6302 const Elf_Internal_Sym *src,
6306 Elf_Internal_Sym newsym;
6308 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
6309 of the address set, as per the new EABI. We do this unconditionally
6310 because objcopy does not set the elf header flags until after
6311 it writes out the symbol table. */
6312 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
6315 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
6316 newsym.st_value |= 1;
6320 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
6323 /* Add the PT_ARM_EXIDX program header. */
6326 elf32_arm_modify_segment_map (bfd *abfd,
6327 struct bfd_link_info *info ATTRIBUTE_UNUSED)
6329 struct elf_segment_map *m;
6332 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
6333 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
6335 /* If there is already a PT_ARM_EXIDX header, then we do not
6336 want to add another one. This situation arises when running
6337 "strip"; the input binary already has the header. */
6338 m = elf_tdata (abfd)->segment_map;
6339 while (m && m->p_type != PT_ARM_EXIDX)
6343 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
6346 m->p_type = PT_ARM_EXIDX;
6348 m->sections[0] = sec;
6350 m->next = elf_tdata (abfd)->segment_map;
6351 elf_tdata (abfd)->segment_map = m;
6358 /* We may add a PT_ARM_EXIDX program header. */
6361 elf32_arm_additional_program_headers (bfd *abfd)
6365 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
6366 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
6372 /* We use this to override swap_symbol_in and swap_symbol_out. */
6373 const struct elf_size_info elf32_arm_size_info = {
6374 sizeof (Elf32_External_Ehdr),
6375 sizeof (Elf32_External_Phdr),
6376 sizeof (Elf32_External_Shdr),
6377 sizeof (Elf32_External_Rel),
6378 sizeof (Elf32_External_Rela),
6379 sizeof (Elf32_External_Sym),
6380 sizeof (Elf32_External_Dyn),
6381 sizeof (Elf_External_Note),
6385 ELFCLASS32, EV_CURRENT,
6386 bfd_elf32_write_out_phdrs,
6387 bfd_elf32_write_shdrs_and_ehdr,
6388 bfd_elf32_write_relocs,
6389 elf32_arm_swap_symbol_in,
6390 elf32_arm_swap_symbol_out,
6391 bfd_elf32_slurp_reloc_table,
6392 bfd_elf32_slurp_symbol_table,
6393 bfd_elf32_swap_dyn_in,
6394 bfd_elf32_swap_dyn_out,
6395 bfd_elf32_swap_reloc_in,
6396 bfd_elf32_swap_reloc_out,
6397 bfd_elf32_swap_reloca_in,
6398 bfd_elf32_swap_reloca_out
6401 #define ELF_ARCH bfd_arch_arm
6402 #define ELF_MACHINE_CODE EM_ARM
6403 #ifdef __QNXTARGET__
6404 #define ELF_MAXPAGESIZE 0x1000
6406 #define ELF_MAXPAGESIZE 0x8000
6408 #define ELF_MINPAGESIZE 0x1000
6410 #define bfd_elf32_mkobject elf32_arm_mkobject
6412 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
6413 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
6414 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
6415 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
6416 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
6417 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
6418 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
6419 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
6420 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
6422 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
6423 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6424 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
6425 #define elf_backend_check_relocs elf32_arm_check_relocs
6426 #define elf_backend_relocate_section elf32_arm_relocate_section
6427 #define elf_backend_write_section elf32_arm_write_section
6428 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
6429 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
6430 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
6431 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
6432 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
6433 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
6434 #define elf_backend_post_process_headers elf32_arm_post_process_headers
6435 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
6436 #define elf_backend_object_p elf32_arm_object_p
6437 #define elf_backend_section_flags elf32_arm_section_flags
6438 #define elf_backend_fake_sections elf32_arm_fake_sections
6439 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
6440 #define elf_backend_final_write_processing elf32_arm_final_write_processing
6441 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
6442 #define elf_backend_symbol_processing elf32_arm_symbol_processing
6443 #define elf_backend_size_info elf32_arm_size_info
6444 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
6445 #define elf_backend_additional_program_headers \
6446 elf32_arm_additional_program_headers
6448 #define elf_backend_can_refcount 1
6449 #define elf_backend_can_gc_sections 1
6450 #define elf_backend_plt_readonly 1
6451 #define elf_backend_want_got_plt 1
6452 #define elf_backend_want_plt_sym 0
6453 #define elf_backend_may_use_rel_p 1
6454 #define elf_backend_may_use_rela_p 0
6455 #define elf_backend_default_use_rela_p 0
6456 #define elf_backend_rela_normal 0
6458 #define elf_backend_got_header_size 12
6460 #include "elf32-target.h"
6462 /* VxWorks Targets */
6464 #undef TARGET_LITTLE_SYM
6465 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
6466 #undef TARGET_LITTLE_NAME
6467 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
6468 #undef TARGET_BIG_SYM
6469 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
6470 #undef TARGET_BIG_NAME
6471 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
6473 /* Like elf32_arm_link_hash_table_create -- but overrides
6474 appropriately for VxWorks. */
6475 static struct bfd_link_hash_table *
6476 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
6478 struct bfd_link_hash_table *ret;
6480 ret = elf32_arm_link_hash_table_create (abfd);
6483 struct elf32_arm_link_hash_table *htab
6484 = (struct elf32_arm_link_hash_table *)ret;
6491 #define elf32_bed elf32_arm_vxworks_bed
6493 #undef bfd_elf32_bfd_link_hash_table_create
6494 #define bfd_elf32_bfd_link_hash_table_create \
6495 elf32_arm_vxworks_link_hash_table_create
6497 #undef elf_backend_may_use_rel_p
6498 #define elf_backend_may_use_rel_p 0
6499 #undef elf_backend_may_use_rela_p
6500 #define elf_backend_may_use_rela_p 1
6501 #undef elf_backend_default_use_rela_p
6502 #define elf_backend_default_use_rela_p 1
6503 #undef elf_backend_rela_normal
6504 #define elf_backend_rela_normal 1
6506 #include "elf32-target.h"
6509 /* Symbian OS Targets */
6511 #undef TARGET_LITTLE_SYM
6512 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
6513 #undef TARGET_LITTLE_NAME
6514 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
6515 #undef TARGET_BIG_SYM
6516 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
6517 #undef TARGET_BIG_NAME
6518 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
6520 /* Like elf32_arm_link_hash_table_create -- but overrides
6521 appropriately for Symbian OS. */
6522 static struct bfd_link_hash_table *
6523 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
6525 struct bfd_link_hash_table *ret;
6527 ret = elf32_arm_link_hash_table_create (abfd);
6530 struct elf32_arm_link_hash_table *htab
6531 = (struct elf32_arm_link_hash_table *)ret;
6532 /* There is no PLT header for Symbian OS. */
6533 htab->plt_header_size = 0;
6534 /* The PLT entries are each three instructions. */
6535 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
6536 htab->symbian_p = 1;
6537 /* Symbian uses armv5t or above, so use_blx is always true. */
6539 htab->root.is_relocatable_executable = 1;
6544 static struct bfd_elf_special_section const
6545 symbian_special_sections_d[]=
6547 /* In a BPABI executable, the dynamic linking sections do not go in
6548 the loadable read-only segment. The post-linker may wish to
6549 refer to these sections, but they are not part of the final
6551 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
6552 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
6553 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
6554 { NULL, 0, 0, 0, 0 }
6557 static struct bfd_elf_special_section const
6558 symbian_special_sections_g[]=
6560 /* In a BPABI executable, the dynamic linking sections do not go in
6561 the loadable read-only segment. The post-linker may wish to
6562 refer to these sections, but they are not part of the final
6564 { ".got", 4, 0, SHT_PROGBITS, 0 },
6565 { NULL, 0, 0, 0, 0 }
6568 static struct bfd_elf_special_section const
6569 symbian_special_sections_h[]=
6571 /* In a BPABI executable, the dynamic linking sections do not go in
6572 the loadable read-only segment. The post-linker may wish to
6573 refer to these sections, but they are not part of the final
6575 { ".hash", 5, 0, SHT_HASH, 0 },
6576 { NULL, 0, 0, 0, 0 }
6579 static struct bfd_elf_special_section const
6580 symbian_special_sections_i[]=
6582 /* These sections do not need to be writable as the SymbianOS
6583 postlinker will arrange things so that no dynamic relocation is
6585 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
6586 { NULL, 0, 0, 0, 0 }
6589 static struct bfd_elf_special_section const
6590 symbian_special_sections_f[]=
6592 /* These sections do not need to be writable as the SymbianOS
6593 postlinker will arrange things so that no dynamic relocation is
6595 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
6596 { NULL, 0, 0, 0, 0 }
6599 static struct bfd_elf_special_section const
6600 symbian_special_sections_p[]=
6602 /* These sections do not need to be writable as the SymbianOS
6603 postlinker will arrange things so that no dynamic relocation is
6605 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
6606 { NULL, 0, 0, 0, 0 }
6609 static struct bfd_elf_special_section const *
6610 elf32_arm_symbian_special_sections[27]=
6615 symbian_special_sections_d, /* 'd' */
6617 symbian_special_sections_f, /* 'f' */
6618 symbian_special_sections_g, /* 'g' */
6619 symbian_special_sections_h, /* 'h' */
6620 symbian_special_sections_i, /* 'i' */
6627 symbian_special_sections_p, /* 'p' */
6642 elf32_arm_symbian_begin_write_processing (bfd *abfd,
6643 struct bfd_link_info *link_info
6646 /* BPABI objects are never loaded directly by an OS kernel; they are
6647 processed by a postlinker first, into an OS-specific format. If
6648 the D_PAGED bit is set on the file, BFD will align segments on
6649 page boundaries, so that an OS can directly map the file. With
6650 BPABI objects, that just results in wasted space. In addition,
6651 because we clear the D_PAGED bit, map_sections_to_segments will
6652 recognize that the program headers should not be mapped into any
6653 loadable segment. */
6654 abfd->flags &= ~D_PAGED;
6658 elf32_arm_symbian_modify_segment_map (bfd *abfd,
6659 struct bfd_link_info *info)
6661 struct elf_segment_map *m;
6664 /* BPABI shared libraries and executables should have a PT_DYNAMIC
6665 segment. However, because the .dynamic section is not marked
6666 with SEC_LOAD, the generic ELF code will not create such a
6668 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
6671 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
6672 m->next = elf_tdata (abfd)->segment_map;
6673 elf_tdata (abfd)->segment_map = m;
6676 /* Also call the generic arm routine. */
6677 return elf32_arm_modify_segment_map (abfd, info);
6681 #define elf32_bed elf32_arm_symbian_bed
6683 /* The dynamic sections are not allocated on SymbianOS; the postlinker
6684 will process them and then discard them. */
6685 #undef ELF_DYNAMIC_SEC_FLAGS
6686 #define ELF_DYNAMIC_SEC_FLAGS \
6687 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
6689 #undef bfd_elf32_bfd_link_hash_table_create
6690 #define bfd_elf32_bfd_link_hash_table_create \
6691 elf32_arm_symbian_link_hash_table_create
6693 #undef elf_backend_special_sections
6694 #define elf_backend_special_sections elf32_arm_symbian_special_sections
6696 #undef elf_backend_begin_write_processing
6697 #define elf_backend_begin_write_processing \
6698 elf32_arm_symbian_begin_write_processing
6700 #undef elf_backend_modify_segment_map
6701 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
6703 /* There is no .got section for BPABI objects, and hence no header. */
6704 #undef elf_backend_got_header_size
6705 #define elf_backend_got_header_size 0
6707 /* Similarly, there is no .got.plt section. */
6708 #undef elf_backend_want_got_plt
6709 #define elf_backend_want_got_plt 0
6711 #undef elf_backend_may_use_rel_p
6712 #define elf_backend_may_use_rel_p 1
6713 #undef elf_backend_may_use_rela_p
6714 #define elf_backend_may_use_rela_p 0
6715 #undef elf_backend_default_use_rela_p
6716 #define elf_backend_default_use_rela_p 0
6717 #undef elf_backend_rela_normal
6718 #define elf_backend_rela_normal 0
6720 #include "elf32-target.h"