1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 typedef unsigned long int insn32
;
26 typedef unsigned short int insn16
;
28 /* In leiu of proper flags, assume all EABIv3 objects are interworkable. */
29 #define INTERWORK_FLAG(abfd) \
30 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER3 \
31 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
33 /* The linker script knows the section names for placement.
34 The entry_names are used to do simple name mangling on the stubs.
35 Given a function name, and its type, the stub can be found. The
36 name can be changed. The only requirement is the %s be present. */
37 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
38 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
40 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
41 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
43 /* The name of the dynamic interpreter. This is put in the .interp
45 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
49 /* The first entry in a procedure linkage table looks like
50 this. It is set up so that any shared library function that is
51 called before the relocation has been set up calls the dynamic
53 static const bfd_vma elf32_arm_plt0_entry
[] =
55 0xe52de004, /* str lr, [sp, #-4]! */
56 0xe59fe010, /* ldr lr, [pc, #16] */
57 0xe08fe00e, /* add lr, pc, lr */
58 0xe5bef008, /* ldr pc, [lr, #8]! */
61 /* Subsequent entries in a procedure linkage table look like
63 static const bfd_vma elf32_arm_plt_entry
[] =
65 0xe28fc600, /* add ip, pc, #NN */
66 0xe28cca00, /* add ip, ip, #NN */
67 0xe5bcf000, /* ldr pc, [ip, #NN]! */
68 0x00000000, /* unused */
73 /* The first entry in a procedure linkage table looks like
74 this. It is set up so that any shared library function that is
75 called before the relocation has been set up calls the dynamic
77 static const bfd_vma elf32_arm_plt0_entry
[] =
79 0xe52de004, /* str lr, [sp, #-4]! */
80 0xe59fe004, /* ldr lr, [pc, #4] */
81 0xe08fe00e, /* add lr, pc, lr */
82 0xe5bef008, /* ldr pc, [lr, #8]! */
83 0x00000000, /* &GOT[0] - . */
86 /* Subsequent entries in a procedure linkage table look like
88 static const bfd_vma elf32_arm_plt_entry
[] =
90 0xe28fc600, /* add ip, pc, #0xNN00000 */
91 0xe28cca00, /* add ip, ip, #0xNN000 */
92 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
97 /* The entries in a PLT when using a DLL-based target with multiple
99 static const bfd_vma elf32_arm_symbian_plt_entry
[] =
101 0xe51ff004, /* ldr pr, [pc, #-4] */
102 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
105 /* Used to build a map of a section. This is required for mixed-endian
108 typedef struct elf32_elf_section_map
113 elf32_arm_section_map
;
115 struct _arm_elf_section_data
117 struct bfd_elf_section_data elf
;
119 elf32_arm_section_map
*map
;
122 #define elf32_arm_section_data(sec) \
123 ((struct _arm_elf_section_data *) elf_section_data (sec))
125 /* The ARM linker needs to keep track of the number of relocs that it
126 decides to copy in check_relocs for each symbol. This is so that
127 it can discard PC relative relocs if it doesn't need them when
128 linking with -Bsymbolic. We store the information in a field
129 extending the regular ELF linker hash table. */
131 /* This structure keeps track of the number of PC relative relocs we
132 have copied for a given symbol. */
133 struct elf32_arm_relocs_copied
136 struct elf32_arm_relocs_copied
* next
;
137 /* A section in dynobj. */
139 /* Number of relocs copied in this section. */
143 /* Arm ELF linker hash entry. */
144 struct elf32_arm_link_hash_entry
146 struct elf_link_hash_entry root
;
148 /* Number of PC relative relocs copied for this symbol. */
149 struct elf32_arm_relocs_copied
* relocs_copied
;
152 /* Traverse an arm ELF linker hash table. */
153 #define elf32_arm_link_hash_traverse(table, func, info) \
154 (elf_link_hash_traverse \
156 (bfd_boolean (*) (struct elf_link_hash_entry *, void *))) (func), \
159 /* Get the ARM elf linker hash table from a link_info structure. */
160 #define elf32_arm_hash_table(info) \
161 ((struct elf32_arm_link_hash_table *) ((info)->hash))
163 /* ARM ELF linker hash table. */
164 struct elf32_arm_link_hash_table
166 /* The main hash table. */
167 struct elf_link_hash_table root
;
169 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
170 bfd_size_type thumb_glue_size
;
172 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
173 bfd_size_type arm_glue_size
;
175 /* An arbitrary input BFD chosen to hold the glue sections. */
176 bfd
* bfd_of_glue_owner
;
178 /* A boolean indicating whether knowledge of the ARM's pipeline
179 length should be applied by the linker. */
180 int no_pipeline_knowledge
;
182 /* Nonzero to output a BE8 image. */
185 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
186 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
189 /* The number of bytes in the initial entry in the PLT. */
190 bfd_size_type plt_header_size
;
192 /* The number of bytes in the subsequent PLT etries. */
193 bfd_size_type plt_entry_size
;
195 /* True if the target system is Symbian OS. */
198 /* Short-cuts to get to dynamic linker sections. */
207 /* Small local sym to section mapping cache. */
208 struct sym_sec_cache sym_sec
;
211 /* Create an entry in an ARM ELF linker hash table. */
213 static struct bfd_hash_entry
*
214 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
215 struct bfd_hash_table
* table
,
218 struct elf32_arm_link_hash_entry
* ret
=
219 (struct elf32_arm_link_hash_entry
*) entry
;
221 /* Allocate the structure if it has not already been allocated by a
223 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
224 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
226 return (struct bfd_hash_entry
*) ret
;
228 /* Call the allocation method of the superclass. */
229 ret
= ((struct elf32_arm_link_hash_entry
*)
230 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
233 ret
->relocs_copied
= NULL
;
235 return (struct bfd_hash_entry
*) ret
;
238 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
239 shortcuts to them in our hash table. */
242 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
244 struct elf32_arm_link_hash_table
*htab
;
246 htab
= elf32_arm_hash_table (info
);
247 /* BPABI objects never have a GOT, or associated sections. */
251 if (! _bfd_elf_create_got_section (dynobj
, info
))
254 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
255 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
256 if (!htab
->sgot
|| !htab
->sgotplt
)
259 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
260 if (htab
->srelgot
== NULL
261 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
262 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
263 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
265 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
270 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
271 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
275 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
277 struct elf32_arm_link_hash_table
*htab
;
279 htab
= elf32_arm_hash_table (info
);
280 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
283 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
286 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
287 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
288 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
290 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
295 || (!info
->shared
&& !htab
->srelbss
))
301 /* Copy the extra info we tack onto an elf_link_hash_entry. */
304 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
305 struct elf_link_hash_entry
*dir
,
306 struct elf_link_hash_entry
*ind
)
308 struct elf32_arm_link_hash_entry
*edir
, *eind
;
310 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
311 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
313 if (eind
->relocs_copied
!= NULL
)
315 if (edir
->relocs_copied
!= NULL
)
317 struct elf32_arm_relocs_copied
**pp
;
318 struct elf32_arm_relocs_copied
*p
;
320 if (ind
->root
.type
== bfd_link_hash_indirect
)
323 /* Add reloc counts against the weak sym to the strong sym
324 list. Merge any entries against the same section. */
325 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
327 struct elf32_arm_relocs_copied
*q
;
329 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
330 if (q
->section
== p
->section
)
332 q
->count
+= p
->count
;
339 *pp
= edir
->relocs_copied
;
342 edir
->relocs_copied
= eind
->relocs_copied
;
343 eind
->relocs_copied
= NULL
;
346 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
349 /* Create an ARM elf linker hash table. */
351 static struct bfd_link_hash_table
*
352 elf32_arm_link_hash_table_create (bfd
*abfd
)
354 struct elf32_arm_link_hash_table
*ret
;
355 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
357 ret
= bfd_malloc (amt
);
361 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
362 elf32_arm_link_hash_newfunc
))
375 ret
->thumb_glue_size
= 0;
376 ret
->arm_glue_size
= 0;
377 ret
->bfd_of_glue_owner
= NULL
;
378 ret
->no_pipeline_knowledge
= 0;
379 ret
->byteswap_code
= 0;
380 ret
->target1_is_rel
= 0;
382 ret
->plt_header_size
= 16;
383 ret
->plt_entry_size
= 16;
385 ret
->plt_header_size
= 20;
386 ret
->plt_entry_size
= 12;
389 ret
->sym_sec
.abfd
= NULL
;
391 return &ret
->root
.root
;
394 /* Locate the Thumb encoded calling stub for NAME. */
396 static struct elf_link_hash_entry
*
397 find_thumb_glue (struct bfd_link_info
*link_info
,
402 struct elf_link_hash_entry
*hash
;
403 struct elf32_arm_link_hash_table
*hash_table
;
405 /* We need a pointer to the armelf specific hash table. */
406 hash_table
= elf32_arm_hash_table (link_info
);
408 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
409 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
411 BFD_ASSERT (tmp_name
);
413 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
415 hash
= elf_link_hash_lookup
416 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
419 /* xgettext:c-format */
420 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
421 input_bfd
, tmp_name
, name
);
428 /* Locate the ARM encoded calling stub for NAME. */
430 static struct elf_link_hash_entry
*
431 find_arm_glue (struct bfd_link_info
*link_info
,
436 struct elf_link_hash_entry
*myh
;
437 struct elf32_arm_link_hash_table
*hash_table
;
439 /* We need a pointer to the elfarm specific hash table. */
440 hash_table
= elf32_arm_hash_table (link_info
);
442 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
443 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
445 BFD_ASSERT (tmp_name
);
447 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
449 myh
= elf_link_hash_lookup
450 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
453 /* xgettext:c-format */
454 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
455 input_bfd
, tmp_name
, name
);
469 .word func @ behave as if you saw a ARM_32 reloc. */
471 #define ARM2THUMB_GLUE_SIZE 12
472 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
473 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
474 static const insn32 a2t3_func_addr_insn
= 0x00000001;
476 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
480 __func_from_thumb: __func_from_thumb:
482 nop ldr r6, __func_addr
484 __func_change_to_arm: bx r6
486 __func_back_to_thumb:
492 #define THUMB2ARM_GLUE_SIZE 8
493 static const insn16 t2a1_bx_pc_insn
= 0x4778;
494 static const insn16 t2a2_noop_insn
= 0x46c0;
495 static const insn32 t2a3_b_insn
= 0xea000000;
497 #ifndef ELFARM_NABI_C_INCLUDED
499 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
503 struct elf32_arm_link_hash_table
* globals
;
505 globals
= elf32_arm_hash_table (info
);
507 BFD_ASSERT (globals
!= NULL
);
509 if (globals
->arm_glue_size
!= 0)
511 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
513 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
514 ARM2THUMB_GLUE_SECTION_NAME
);
516 BFD_ASSERT (s
!= NULL
);
518 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
520 s
->size
= globals
->arm_glue_size
;
524 if (globals
->thumb_glue_size
!= 0)
526 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
528 s
= bfd_get_section_by_name
529 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
531 BFD_ASSERT (s
!= NULL
);
533 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
535 s
->size
= globals
->thumb_glue_size
;
543 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
544 struct elf_link_hash_entry
* h
)
546 const char * name
= h
->root
.root
.string
;
549 struct elf_link_hash_entry
* myh
;
550 struct bfd_link_hash_entry
* bh
;
551 struct elf32_arm_link_hash_table
* globals
;
554 globals
= elf32_arm_hash_table (link_info
);
556 BFD_ASSERT (globals
!= NULL
);
557 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
559 s
= bfd_get_section_by_name
560 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
562 BFD_ASSERT (s
!= NULL
);
564 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
566 BFD_ASSERT (tmp_name
);
568 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
570 myh
= elf_link_hash_lookup
571 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
575 /* We've already seen this guy. */
580 /* The only trick here is using hash_table->arm_glue_size as the value.
581 Even though the section isn't allocated yet, this is where we will be
584 val
= globals
->arm_glue_size
+ 1;
585 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
586 tmp_name
, BSF_GLOBAL
, s
, val
,
587 NULL
, TRUE
, FALSE
, &bh
);
591 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
597 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
598 struct elf_link_hash_entry
*h
)
600 const char *name
= h
->root
.root
.string
;
603 struct elf_link_hash_entry
*myh
;
604 struct bfd_link_hash_entry
*bh
;
605 struct elf32_arm_link_hash_table
*hash_table
;
609 hash_table
= elf32_arm_hash_table (link_info
);
611 BFD_ASSERT (hash_table
!= NULL
);
612 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
614 s
= bfd_get_section_by_name
615 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
617 BFD_ASSERT (s
!= NULL
);
619 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
620 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
622 BFD_ASSERT (tmp_name
);
624 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
626 myh
= elf_link_hash_lookup
627 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
631 /* We've already seen this guy. */
637 val
= hash_table
->thumb_glue_size
+ 1;
638 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
639 tmp_name
, BSF_GLOBAL
, s
, val
,
640 NULL
, TRUE
, FALSE
, &bh
);
642 /* If we mark it 'Thumb', the disassembler will do a better job. */
643 myh
= (struct elf_link_hash_entry
*) bh
;
644 bind
= ELF_ST_BIND (myh
->type
);
645 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
649 #define CHANGE_TO_ARM "__%s_change_to_arm"
650 #define BACK_FROM_ARM "__%s_back_from_arm"
652 /* Allocate another symbol to mark where we switch to Arm mode. */
653 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
654 + strlen (CHANGE_TO_ARM
) + 1);
656 BFD_ASSERT (tmp_name
);
658 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
661 val
= hash_table
->thumb_glue_size
+ 4,
662 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
663 tmp_name
, BSF_LOCAL
, s
, val
,
664 NULL
, TRUE
, FALSE
, &bh
);
668 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
673 /* Add the glue sections to ABFD. This function is called from the
674 linker scripts in ld/emultempl/{armelf}.em. */
677 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
678 struct bfd_link_info
*info
)
683 /* If we are only performing a partial
684 link do not bother adding the glue. */
685 if (info
->relocatable
)
688 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
692 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
693 will prevent elf_link_input_bfd() from processing the contents
695 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
697 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
700 || !bfd_set_section_flags (abfd
, sec
, flags
)
701 || !bfd_set_section_alignment (abfd
, sec
, 2))
704 /* Set the gc mark to prevent the section from being removed by garbage
705 collection, despite the fact that no relocs refer to this section. */
709 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
713 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
714 | SEC_CODE
| SEC_READONLY
;
716 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
719 || !bfd_set_section_flags (abfd
, sec
, flags
)
720 || !bfd_set_section_alignment (abfd
, sec
, 2))
729 /* Select a BFD to be used to hold the sections used by the glue code.
730 This function is called from the linker scripts in ld/emultempl/
734 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
736 struct elf32_arm_link_hash_table
*globals
;
738 /* If we are only performing a partial link
739 do not bother getting a bfd to hold the glue. */
740 if (info
->relocatable
)
743 globals
= elf32_arm_hash_table (info
);
745 BFD_ASSERT (globals
!= NULL
);
747 if (globals
->bfd_of_glue_owner
!= NULL
)
750 /* Save the bfd for later use. */
751 globals
->bfd_of_glue_owner
= abfd
;
757 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
758 struct bfd_link_info
*link_info
,
759 int no_pipeline_knowledge
,
763 Elf_Internal_Shdr
*symtab_hdr
;
764 Elf_Internal_Rela
*internal_relocs
= NULL
;
765 Elf_Internal_Rela
*irel
, *irelend
;
766 bfd_byte
*contents
= NULL
;
769 struct elf32_arm_link_hash_table
*globals
;
771 /* If we are only performing a partial link do not bother
772 to construct any glue. */
773 if (link_info
->relocatable
)
776 /* Here we have a bfd that is to be included on the link. We have a hook
777 to do reloc rummaging, before section sizes are nailed down. */
778 globals
= elf32_arm_hash_table (link_info
);
780 BFD_ASSERT (globals
!= NULL
);
781 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
783 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
784 globals
->target1_is_rel
= target1_is_rel
;
785 if (byteswap_code
&& !bfd_big_endian (abfd
))
787 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
791 globals
->byteswap_code
= byteswap_code
;
793 /* Rummage around all the relocs and map the glue vectors. */
794 sec
= abfd
->sections
;
799 for (; sec
!= NULL
; sec
= sec
->next
)
801 if (sec
->reloc_count
== 0)
804 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
806 /* Load the relocs. */
808 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
809 (Elf_Internal_Rela
*) NULL
, FALSE
);
811 if (internal_relocs
== NULL
)
814 irelend
= internal_relocs
+ sec
->reloc_count
;
815 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
818 unsigned long r_index
;
820 struct elf_link_hash_entry
*h
;
822 r_type
= ELF32_R_TYPE (irel
->r_info
);
823 r_index
= ELF32_R_SYM (irel
->r_info
);
825 /* These are the only relocation types we care about. */
826 if ( r_type
!= R_ARM_PC24
827 && r_type
!= R_ARM_THM_PC22
)
830 /* Get the section contents if we haven't done so already. */
831 if (contents
== NULL
)
833 /* Get cached copy if it exists. */
834 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
835 contents
= elf_section_data (sec
)->this_hdr
.contents
;
838 /* Go get them off disk. */
839 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
844 /* If the relocation is not against a symbol it cannot concern us. */
847 /* We don't care about local symbols. */
848 if (r_index
< symtab_hdr
->sh_info
)
851 /* This is an external symbol. */
852 r_index
-= symtab_hdr
->sh_info
;
853 h
= (struct elf_link_hash_entry
*)
854 elf_sym_hashes (abfd
)[r_index
];
856 /* If the relocation is against a static symbol it must be within
857 the current section and so cannot be a cross ARM/Thumb relocation. */
864 /* This one is a call from arm code. We need to look up
865 the target of the call. If it is a thumb target, we
867 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
868 record_arm_to_thumb_glue (link_info
, h
);
872 /* This one is a call from thumb code. We look
873 up the target of the call. If it is not a thumb
874 target, we insert glue. */
875 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
876 record_thumb_to_arm_glue (link_info
, h
);
885 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
889 if (internal_relocs
!= NULL
890 && elf_section_data (sec
)->relocs
!= internal_relocs
)
891 free (internal_relocs
);
892 internal_relocs
= NULL
;
899 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
901 if (internal_relocs
!= NULL
902 && elf_section_data (sec
)->relocs
!= internal_relocs
)
903 free (internal_relocs
);
909 /* The thumb form of a long branch is a bit finicky, because the offset
910 encoding is split over two fields, each in it's own instruction. They
911 can occur in any order. So given a thumb form of long branch, and an
912 offset, insert the offset into the thumb branch and return finished
915 It takes two thumb instructions to encode the target address. Each has
916 11 bits to invest. The upper 11 bits are stored in one (identified by
917 H-0.. see below), the lower 11 bits are stored in the other (identified
920 Combine together and shifted left by 1 (it's a half word address) and
924 H-0, upper address-0 = 000
926 H-1, lower address-0 = 800
928 They can be ordered either way, but the arm tools I've seen always put
929 the lower one first. It probably doesn't matter. krk@cygnus.com
931 XXX: Actually the order does matter. The second instruction (H-1)
932 moves the computed address into the PC, so it must be the second one
933 in the sequence. The problem, however is that whilst little endian code
934 stores the instructions in HI then LOW order, big endian code does the
935 reverse. nickc@cygnus.com. */
937 #define LOW_HI_ORDER 0xF800F000
938 #define HI_LOW_ORDER 0xF000F800
941 insert_thumb_branch (insn32 br_insn
, int rel_off
)
943 unsigned int low_bits
;
944 unsigned int high_bits
;
946 BFD_ASSERT ((rel_off
& 1) != 1);
948 rel_off
>>= 1; /* Half word aligned address. */
949 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
950 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
952 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
953 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
954 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
955 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
957 /* FIXME: abort is probably not the right call. krk@cygnus.com */
958 abort (); /* Error - not a valid branch instruction form. */
963 /* Thumb code calling an ARM function. */
966 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
970 asection
* input_section
,
974 bfd_signed_vma addend
,
979 unsigned long int tmp
;
981 struct elf_link_hash_entry
* myh
;
982 struct elf32_arm_link_hash_table
* globals
;
984 myh
= find_thumb_glue (info
, name
, input_bfd
);
988 globals
= elf32_arm_hash_table (info
);
990 BFD_ASSERT (globals
!= NULL
);
991 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
993 my_offset
= myh
->root
.u
.def
.value
;
995 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
996 THUMB2ARM_GLUE_SECTION_NAME
);
998 BFD_ASSERT (s
!= NULL
);
999 BFD_ASSERT (s
->contents
!= NULL
);
1000 BFD_ASSERT (s
->output_section
!= NULL
);
1002 if ((my_offset
& 0x01) == 0x01)
1005 && sym_sec
->owner
!= NULL
1006 && !INTERWORK_FLAG (sym_sec
->owner
))
1008 (*_bfd_error_handler
)
1009 (_("%B(%s): warning: interworking not enabled.\n"
1010 " first occurrence: %B: thumb call to arm"),
1011 sym_sec
->owner
, input_bfd
, name
);
1017 myh
->root
.u
.def
.value
= my_offset
;
1019 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
1020 s
->contents
+ my_offset
);
1022 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
1023 s
->contents
+ my_offset
+ 2);
1026 /* Address of destination of the stub. */
1027 ((bfd_signed_vma
) val
)
1029 /* Offset from the start of the current section
1030 to the start of the stubs. */
1032 /* Offset of the start of this stub from the start of the stubs. */
1034 /* Address of the start of the current section. */
1035 + s
->output_section
->vma
)
1036 /* The branch instruction is 4 bytes into the stub. */
1038 /* ARM branches work from the pc of the instruction + 8. */
1041 bfd_put_32 (output_bfd
,
1042 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1043 s
->contents
+ my_offset
+ 4);
1046 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
1048 /* Now go back and fix up the original BL insn to point to here. */
1050 /* Address of where the stub is located. */
1051 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
1052 /* Address of where the BL is located. */
1053 - (input_section
->output_section
->vma
+ input_section
->output_offset
1055 /* Addend in the relocation. */
1057 /* Biassing for PC-relative addressing. */
1060 tmp
= bfd_get_32 (input_bfd
, hit_data
1061 - input_section
->vma
);
1063 bfd_put_32 (output_bfd
,
1064 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1065 hit_data
- input_section
->vma
);
1070 /* Arm code calling a Thumb function. */
1073 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
1077 asection
* input_section
,
1078 bfd_byte
* hit_data
,
1081 bfd_signed_vma addend
,
1084 unsigned long int tmp
;
1087 long int ret_offset
;
1088 struct elf_link_hash_entry
* myh
;
1089 struct elf32_arm_link_hash_table
* globals
;
1091 myh
= find_arm_glue (info
, name
, input_bfd
);
1095 globals
= elf32_arm_hash_table (info
);
1097 BFD_ASSERT (globals
!= NULL
);
1098 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1100 my_offset
= myh
->root
.u
.def
.value
;
1101 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1102 ARM2THUMB_GLUE_SECTION_NAME
);
1103 BFD_ASSERT (s
!= NULL
);
1104 BFD_ASSERT (s
->contents
!= NULL
);
1105 BFD_ASSERT (s
->output_section
!= NULL
);
1107 if ((my_offset
& 0x01) == 0x01)
1110 && sym_sec
->owner
!= NULL
1111 && !INTERWORK_FLAG (sym_sec
->owner
))
1113 (*_bfd_error_handler
)
1114 (_("%B(%s): warning: interworking not enabled.\n"
1115 " first occurrence: %B: arm call to thumb"),
1116 sym_sec
->owner
, input_bfd
, name
);
1120 myh
->root
.u
.def
.value
= my_offset
;
1122 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1123 s
->contents
+ my_offset
);
1125 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1126 s
->contents
+ my_offset
+ 4);
1128 /* It's a thumb address. Add the low order bit. */
1129 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1130 s
->contents
+ my_offset
+ 8);
1133 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1135 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1136 tmp
= tmp
& 0xFF000000;
1138 /* Somehow these are both 4 too far, so subtract 8. */
1139 ret_offset
= (s
->output_offset
1141 + s
->output_section
->vma
1142 - (input_section
->output_offset
1143 + input_section
->output_section
->vma
1147 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1149 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1154 /* Perform a relocation as part of a final link. */
1156 static bfd_reloc_status_type
1157 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
1160 asection
* input_section
,
1161 bfd_byte
* contents
,
1162 Elf_Internal_Rela
* rel
,
1164 struct bfd_link_info
* info
,
1166 const char * sym_name
,
1168 struct elf_link_hash_entry
* h
)
1170 unsigned long r_type
= howto
->type
;
1171 unsigned long r_symndx
;
1172 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1173 bfd
* dynobj
= NULL
;
1174 Elf_Internal_Shdr
* symtab_hdr
;
1175 struct elf_link_hash_entry
** sym_hashes
;
1176 bfd_vma
* local_got_offsets
;
1177 asection
* sgot
= NULL
;
1178 asection
* splt
= NULL
;
1179 asection
* sreloc
= NULL
;
1181 bfd_signed_vma signed_addend
;
1182 struct elf32_arm_link_hash_table
* globals
;
1184 globals
= elf32_arm_hash_table (info
);
1187 /* Some relocation type map to different relocations depending on the
1188 target. We pick the right one here. */
1189 if (r_type
== R_ARM_TARGET1
)
1191 if (globals
->target1_is_rel
)
1192 r_type
= R_ARM_REL32
;
1194 r_type
= R_ARM_ABS32
;
1196 howto
= &elf32_arm_howto_table
[r_type
];
1198 #endif /* OLD_ARM_ABI */
1200 /* If the start address has been set, then set the EF_ARM_HASENTRY
1201 flag. Setting this more than once is redundant, but the cost is
1202 not too high, and it keeps the code simple.
1204 The test is done here, rather than somewhere else, because the
1205 start address is only set just before the final link commences.
1207 Note - if the user deliberately sets a start address of 0, the
1208 flag will not be set. */
1209 if (bfd_get_start_address (output_bfd
) != 0)
1210 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1212 dynobj
= elf_hash_table (info
)->dynobj
;
1215 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1216 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1218 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1219 sym_hashes
= elf_sym_hashes (input_bfd
);
1220 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1221 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1224 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1226 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1229 signed_addend
&= ~ howto
->src_mask
;
1230 signed_addend
|= addend
;
1233 signed_addend
= addend
;
1235 addend
= signed_addend
= rel
->r_addend
;
1241 return bfd_reloc_ok
;
1250 /* r_symndx will be zero only for relocs against symbols
1251 from removed linkonce sections, or sections discarded by
1254 return bfd_reloc_ok
;
1256 /* Handle relocations which should use the PLT entry. ABS32/REL32
1257 will use the symbol's value, which may point to a PLT entry, but we
1258 don't need to handle that here. If we created a PLT entry, all
1259 branches in this object should go to it. */
1260 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
1263 && h
->plt
.offset
!= (bfd_vma
) -1)
1265 /* If we've created a .plt section, and assigned a PLT entry to
1266 this function, it should not be known to bind locally. If
1267 it were, we would have cleared the PLT entry. */
1268 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
1270 value
= (splt
->output_section
->vma
1271 + splt
->output_offset
1273 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1274 contents
, rel
->r_offset
, value
,
1278 /* When generating a shared object, these relocations are copied
1279 into the output file to be resolved at run time. */
1281 && (input_section
->flags
& SEC_ALLOC
)
1282 && (r_type
!= R_ARM_REL32
1283 || !SYMBOL_CALLS_LOCAL (info
, h
))
1285 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1286 || h
->root
.type
!= bfd_link_hash_undefweak
)
1287 && r_type
!= R_ARM_PC24
1288 && r_type
!= R_ARM_PLT32
)
1290 Elf_Internal_Rela outrel
;
1292 bfd_boolean skip
, relocate
;
1298 name
= (bfd_elf_string_from_elf_section
1300 elf_elfheader (input_bfd
)->e_shstrndx
,
1301 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1303 return bfd_reloc_notsupported
;
1305 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1306 && strcmp (bfd_get_section_name (input_bfd
,
1310 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1311 BFD_ASSERT (sreloc
!= NULL
);
1318 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1320 if (outrel
.r_offset
== (bfd_vma
) -1)
1322 else if (outrel
.r_offset
== (bfd_vma
) -2)
1323 skip
= TRUE
, relocate
= TRUE
;
1324 outrel
.r_offset
+= (input_section
->output_section
->vma
1325 + input_section
->output_offset
);
1328 memset (&outrel
, 0, sizeof outrel
);
1333 || !h
->def_regular
))
1334 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1337 /* This symbol is local, or marked to become local. */
1339 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1342 loc
= sreloc
->contents
;
1343 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1344 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1346 /* If this reloc is against an external symbol, we do not want to
1347 fiddle with the addend. Otherwise, we need to include the symbol
1348 value so that it becomes an addend for the dynamic reloc. */
1350 return bfd_reloc_ok
;
1352 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1353 contents
, rel
->r_offset
, value
,
1356 else switch (r_type
)
1359 case R_ARM_XPC25
: /* Arm BLX instruction. */
1361 case R_ARM_PC24
: /* Arm B/BL instruction */
1364 if (r_type
== R_ARM_XPC25
)
1366 /* Check for Arm calling Arm function. */
1367 /* FIXME: Should we translate the instruction into a BL
1368 instruction instead ? */
1369 if (sym_flags
!= STT_ARM_TFUNC
)
1370 (*_bfd_error_handler
)
1371 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
1373 h
? h
->root
.root
.string
: "(local)");
1378 /* Check for Arm calling Thumb function. */
1379 if (sym_flags
== STT_ARM_TFUNC
)
1381 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
1382 output_bfd
, input_section
,
1383 hit_data
, sym_sec
, rel
->r_offset
,
1384 signed_addend
, value
);
1385 return bfd_reloc_ok
;
1389 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1390 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1392 /* The old way of doing things. Trearing the addend as a
1393 byte sized field and adding in the pipeline offset. */
1394 value
-= (input_section
->output_section
->vma
1395 + input_section
->output_offset
);
1396 value
-= rel
->r_offset
;
1399 if (! globals
->no_pipeline_knowledge
)
1404 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1406 S is the address of the symbol in the relocation.
1407 P is address of the instruction being relocated.
1408 A is the addend (extracted from the instruction) in bytes.
1410 S is held in 'value'.
1411 P is the base address of the section containing the
1412 instruction plus the offset of the reloc into that
1414 (input_section->output_section->vma +
1415 input_section->output_offset +
1417 A is the addend, converted into bytes, ie:
1420 Note: None of these operations have knowledge of the pipeline
1421 size of the processor, thus it is up to the assembler to
1422 encode this information into the addend. */
1423 value
-= (input_section
->output_section
->vma
1424 + input_section
->output_offset
);
1425 value
-= rel
->r_offset
;
1426 value
+= (signed_addend
<< howto
->size
);
1428 /* Previous versions of this code also used to add in the
1429 pipeline offset here. This is wrong because the linker is
1430 not supposed to know about such things, and one day it might
1431 change. In order to support old binaries that need the old
1432 behaviour however, so we attempt to detect which ABI was
1433 used to create the reloc. */
1434 if (! globals
->no_pipeline_knowledge
)
1436 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1438 i_ehdrp
= elf_elfheader (input_bfd
);
1440 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1445 signed_addend
= value
;
1446 signed_addend
>>= howto
->rightshift
;
1448 /* It is not an error for an undefined weak reference to be
1449 out of range. Any program that branches to such a symbol
1450 is going to crash anyway, so there is no point worrying
1451 about getting the destination exactly right. */
1452 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1454 /* Perform a signed range check. */
1455 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1456 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1457 return bfd_reloc_overflow
;
1461 /* If necessary set the H bit in the BLX instruction. */
1462 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1463 value
= (signed_addend
& howto
->dst_mask
)
1464 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1468 value
= (signed_addend
& howto
->dst_mask
)
1469 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1474 if (sym_flags
== STT_ARM_TFUNC
)
1479 value
-= (input_section
->output_section
->vma
1480 + input_section
->output_offset
+ rel
->r_offset
);
1485 bfd_put_32 (input_bfd
, value
, hit_data
);
1486 return bfd_reloc_ok
;
1490 if ((long) value
> 0x7f || (long) value
< -0x80)
1491 return bfd_reloc_overflow
;
1493 bfd_put_8 (input_bfd
, value
, hit_data
);
1494 return bfd_reloc_ok
;
1499 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1500 return bfd_reloc_overflow
;
1502 bfd_put_16 (input_bfd
, value
, hit_data
);
1503 return bfd_reloc_ok
;
1506 /* Support ldr and str instruction for the arm */
1507 /* Also thumb b (unconditional branch). ??? Really? */
1510 if ((long) value
> 0x7ff || (long) value
< -0x800)
1511 return bfd_reloc_overflow
;
1513 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1514 bfd_put_32 (input_bfd
, value
, hit_data
);
1515 return bfd_reloc_ok
;
1517 case R_ARM_THM_ABS5
:
1518 /* Support ldr and str instructions for the thumb. */
1520 /* Need to refetch addend. */
1521 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1522 /* ??? Need to determine shift amount from operand size. */
1523 addend
>>= howto
->rightshift
;
1527 /* ??? Isn't value unsigned? */
1528 if ((long) value
> 0x1f || (long) value
< -0x10)
1529 return bfd_reloc_overflow
;
1531 /* ??? Value needs to be properly shifted into place first. */
1532 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1533 bfd_put_16 (input_bfd
, value
, hit_data
);
1534 return bfd_reloc_ok
;
1537 case R_ARM_THM_XPC22
:
1539 case R_ARM_THM_PC22
:
1540 /* Thumb BL (branch long instruction). */
1543 bfd_boolean overflow
= FALSE
;
1544 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1545 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1546 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1547 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1549 bfd_signed_vma signed_check
;
1552 /* Need to refetch the addend and squish the two 11 bit pieces
1555 bfd_vma upper
= upper_insn
& 0x7ff;
1556 bfd_vma lower
= lower_insn
& 0x7ff;
1557 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1558 addend
= (upper
<< 12) | (lower
<< 1);
1559 signed_addend
= addend
;
1563 if (r_type
== R_ARM_THM_XPC22
)
1565 /* Check for Thumb to Thumb call. */
1566 /* FIXME: Should we translate the instruction into a BL
1567 instruction instead ? */
1568 if (sym_flags
== STT_ARM_TFUNC
)
1569 (*_bfd_error_handler
)
1570 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
1572 h
? h
->root
.root
.string
: "(local)");
1577 /* If it is not a call to Thumb, assume call to Arm.
1578 If it is a call relative to a section name, then it is not a
1579 function call at all, but rather a long jump. */
1580 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1582 if (elf32_thumb_to_arm_stub
1583 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1584 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1585 return bfd_reloc_ok
;
1587 return bfd_reloc_dangerous
;
1591 relocation
= value
+ signed_addend
;
1593 relocation
-= (input_section
->output_section
->vma
1594 + input_section
->output_offset
1597 if (! globals
->no_pipeline_knowledge
)
1599 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1601 i_ehdrp
= elf_elfheader (input_bfd
);
1603 /* Previous versions of this code also used to add in the pipline
1604 offset here. This is wrong because the linker is not supposed
1605 to know about such things, and one day it might change. In order
1606 to support old binaries that need the old behaviour however, so
1607 we attempt to detect which ABI was used to create the reloc. */
1608 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1609 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1610 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1614 check
= relocation
>> howto
->rightshift
;
1616 /* If this is a signed value, the rightshift just dropped
1617 leading 1 bits (assuming twos complement). */
1618 if ((bfd_signed_vma
) relocation
>= 0)
1619 signed_check
= check
;
1621 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1623 /* Assumes two's complement. */
1624 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1628 if (r_type
== R_ARM_THM_XPC22
1629 && ((lower_insn
& 0x1800) == 0x0800))
1630 /* For a BLX instruction, make sure that the relocation is rounded up
1631 to a word boundary. This follows the semantics of the instruction
1632 which specifies that bit 1 of the target address will come from bit
1633 1 of the base address. */
1634 relocation
= (relocation
+ 2) & ~ 3;
1636 /* Put RELOCATION back into the insn. */
1637 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1638 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1640 /* Put the relocated value back in the object file: */
1641 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1642 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1644 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1648 case R_ARM_THM_PC11
:
1649 /* Thumb B (branch) instruction). */
1651 bfd_signed_vma relocation
;
1652 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1653 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1654 bfd_signed_vma signed_check
;
1657 /* Need to refetch addend. */
1658 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1659 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1662 signed_addend
&= ~ howto
->src_mask
;
1663 signed_addend
|= addend
;
1666 signed_addend
= addend
;
1667 /* The value in the insn has been right shifted. We need to
1668 undo this, so that we can perform the address calculation
1669 in terms of bytes. */
1670 signed_addend
<<= howto
->rightshift
;
1672 relocation
= value
+ signed_addend
;
1674 relocation
-= (input_section
->output_section
->vma
1675 + input_section
->output_offset
1678 relocation
>>= howto
->rightshift
;
1679 signed_check
= relocation
;
1680 relocation
&= howto
->dst_mask
;
1681 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1683 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1685 /* Assumes two's complement. */
1686 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1687 return bfd_reloc_overflow
;
1689 return bfd_reloc_ok
;
1693 case R_ARM_ALU_PCREL7_0
:
1694 case R_ARM_ALU_PCREL15_8
:
1695 case R_ARM_ALU_PCREL23_15
:
1700 insn
= bfd_get_32 (input_bfd
, hit_data
);
1702 /* Extract the addend. */
1703 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
1704 signed_addend
= addend
;
1706 relocation
= value
+ signed_addend
;
1708 relocation
-= (input_section
->output_section
->vma
1709 + input_section
->output_offset
1711 insn
= (insn
& ~0xfff)
1712 | ((howto
->bitpos
<< 7) & 0xf00)
1713 | ((relocation
>> howto
->bitpos
) & 0xff);
1714 bfd_put_32 (input_bfd
, value
, hit_data
);
1716 return bfd_reloc_ok
;
1719 case R_ARM_GNU_VTINHERIT
:
1720 case R_ARM_GNU_VTENTRY
:
1721 return bfd_reloc_ok
;
1724 return bfd_reloc_notsupported
;
1726 case R_ARM_GLOB_DAT
:
1727 return bfd_reloc_notsupported
;
1729 case R_ARM_JUMP_SLOT
:
1730 return bfd_reloc_notsupported
;
1732 case R_ARM_RELATIVE
:
1733 return bfd_reloc_notsupported
;
1736 /* Relocation is relative to the start of the
1737 global offset table. */
1739 BFD_ASSERT (sgot
!= NULL
);
1741 return bfd_reloc_notsupported
;
1743 /* If we are addressing a Thumb function, we need to adjust the
1744 address by one, so that attempts to call the function pointer will
1745 correctly interpret it as Thumb code. */
1746 if (sym_flags
== STT_ARM_TFUNC
)
1749 /* Note that sgot->output_offset is not involved in this
1750 calculation. We always want the start of .got. If we
1751 define _GLOBAL_OFFSET_TABLE in a different way, as is
1752 permitted by the ABI, we might have to change this
1754 value
-= sgot
->output_section
->vma
;
1755 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1756 contents
, rel
->r_offset
, value
,
1760 /* Use global offset table as symbol value. */
1761 BFD_ASSERT (sgot
!= NULL
);
1764 return bfd_reloc_notsupported
;
1766 value
= sgot
->output_section
->vma
;
1767 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1768 contents
, rel
->r_offset
, value
,
1772 /* Relocation is to the entry for this symbol in the
1773 global offset table. */
1775 return bfd_reloc_notsupported
;
1782 off
= h
->got
.offset
;
1783 BFD_ASSERT (off
!= (bfd_vma
) -1);
1784 dyn
= globals
->root
.dynamic_sections_created
;
1786 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1788 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1789 || (ELF_ST_VISIBILITY (h
->other
)
1790 && h
->root
.type
== bfd_link_hash_undefweak
))
1792 /* This is actually a static link, or it is a -Bsymbolic link
1793 and the symbol is defined locally. We must initialize this
1794 entry in the global offset table. Since the offset must
1795 always be a multiple of 4, we use the least significant bit
1796 to record whether we have initialized it already.
1798 When doing a dynamic link, we create a .rel.got relocation
1799 entry to initialize the value. This is done in the
1800 finish_dynamic_symbol routine. */
1805 /* If we are addressing a Thumb function, we need to
1806 adjust the address by one, so that attempts to
1807 call the function pointer will correctly
1808 interpret it as Thumb code. */
1809 if (sym_flags
== STT_ARM_TFUNC
)
1812 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1817 value
= sgot
->output_offset
+ off
;
1823 BFD_ASSERT (local_got_offsets
!= NULL
&&
1824 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1826 off
= local_got_offsets
[r_symndx
];
1828 /* The offset must always be a multiple of 4. We use the
1829 least significant bit to record whether we have already
1830 generated the necessary reloc. */
1835 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1840 Elf_Internal_Rela outrel
;
1843 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1844 BFD_ASSERT (srelgot
!= NULL
);
1846 outrel
.r_offset
= (sgot
->output_section
->vma
1847 + sgot
->output_offset
1849 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1850 loc
= srelgot
->contents
;
1851 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1852 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1855 local_got_offsets
[r_symndx
] |= 1;
1858 value
= sgot
->output_offset
+ off
;
1861 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1862 contents
, rel
->r_offset
, value
,
1866 return bfd_reloc_notsupported
;
1868 case R_ARM_AMP_VCALL9
:
1869 return bfd_reloc_notsupported
;
1871 case R_ARM_RSBREL32
:
1872 return bfd_reloc_notsupported
;
1874 case R_ARM_THM_RPC22
:
1875 return bfd_reloc_notsupported
;
1878 return bfd_reloc_notsupported
;
1881 return bfd_reloc_notsupported
;
1884 return bfd_reloc_notsupported
;
1887 return bfd_reloc_notsupported
;
1890 return bfd_reloc_notsupported
;
1895 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1897 arm_add_to_rel (bfd
* abfd
,
1899 reloc_howto_type
* howto
,
1900 bfd_signed_vma increment
)
1902 bfd_signed_vma addend
;
1904 if (howto
->type
== R_ARM_THM_PC22
)
1906 int upper_insn
, lower_insn
;
1909 upper_insn
= bfd_get_16 (abfd
, address
);
1910 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1911 upper
= upper_insn
& 0x7ff;
1912 lower
= lower_insn
& 0x7ff;
1914 addend
= (upper
<< 12) | (lower
<< 1);
1915 addend
+= increment
;
1918 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
1919 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
1921 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
1922 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
1928 contents
= bfd_get_32 (abfd
, address
);
1930 /* Get the (signed) value from the instruction. */
1931 addend
= contents
& howto
->src_mask
;
1932 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1934 bfd_signed_vma mask
;
1937 mask
&= ~ howto
->src_mask
;
1941 /* Add in the increment, (which is a byte value). */
1942 switch (howto
->type
)
1945 addend
+= increment
;
1949 addend
<<= howto
->size
;
1950 addend
+= increment
;
1952 /* Should we check for overflow here ? */
1954 /* Drop any undesired bits. */
1955 addend
>>= howto
->rightshift
;
1959 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1961 bfd_put_32 (abfd
, contents
, address
);
1964 #endif /* USE_REL */
1966 /* Relocate an ARM ELF section. */
1968 elf32_arm_relocate_section (bfd
* output_bfd
,
1969 struct bfd_link_info
* info
,
1971 asection
* input_section
,
1972 bfd_byte
* contents
,
1973 Elf_Internal_Rela
* relocs
,
1974 Elf_Internal_Sym
* local_syms
,
1975 asection
** local_sections
)
1977 Elf_Internal_Shdr
*symtab_hdr
;
1978 struct elf_link_hash_entry
**sym_hashes
;
1979 Elf_Internal_Rela
*rel
;
1980 Elf_Internal_Rela
*relend
;
1984 if (info
->relocatable
)
1988 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1989 sym_hashes
= elf_sym_hashes (input_bfd
);
1992 relend
= relocs
+ input_section
->reloc_count
;
1993 for (; rel
< relend
; rel
++)
1996 reloc_howto_type
* howto
;
1997 unsigned long r_symndx
;
1998 Elf_Internal_Sym
* sym
;
2000 struct elf_link_hash_entry
* h
;
2002 bfd_reloc_status_type r
;
2005 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2006 r_type
= ELF32_R_TYPE (rel
->r_info
);
2008 if ( r_type
== R_ARM_GNU_VTENTRY
2009 || r_type
== R_ARM_GNU_VTINHERIT
)
2012 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
2013 howto
= bfd_reloc
.howto
;
2016 if (info
->relocatable
)
2018 /* This is a relocatable link. We don't have to change
2019 anything, unless the reloc is against a section symbol,
2020 in which case we have to adjust according to where the
2021 section symbol winds up in the output section. */
2022 if (r_symndx
< symtab_hdr
->sh_info
)
2024 sym
= local_syms
+ r_symndx
;
2025 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2027 sec
= local_sections
[r_symndx
];
2028 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2030 (bfd_signed_vma
) (sec
->output_offset
2039 /* This is a final link. */
2044 if (r_symndx
< symtab_hdr
->sh_info
)
2046 sym
= local_syms
+ r_symndx
;
2047 sec
= local_sections
[r_symndx
];
2049 relocation
= (sec
->output_section
->vma
2050 + sec
->output_offset
2052 if ((sec
->flags
& SEC_MERGE
)
2053 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2056 bfd_vma addend
, value
;
2058 if (howto
->rightshift
)
2060 (*_bfd_error_handler
)
2061 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
2062 input_bfd
, input_section
,
2063 (long) rel
->r_offset
, howto
->name
);
2067 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2069 /* Get the (signed) value from the instruction. */
2070 addend
= value
& howto
->src_mask
;
2071 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2073 bfd_signed_vma mask
;
2076 mask
&= ~ howto
->src_mask
;
2081 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2083 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2084 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2085 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2088 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2094 bfd_boolean unresolved_reloc
;
2096 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2097 r_symndx
, symtab_hdr
, sym_hashes
,
2099 unresolved_reloc
, warned
);
2101 if (unresolved_reloc
|| relocation
!= 0)
2103 /* In these cases, we don't need the relocation value.
2104 We check specially because in some obscure cases
2105 sec->output_section will be NULL. */
2110 case R_ARM_THM_PC22
:
2114 && ((!info
->symbolic
&& h
->dynindx
!= -1)
2116 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2117 && ((input_section
->flags
& SEC_ALLOC
) != 0
2118 /* DWARF will emit R_ARM_ABS32 relocations in its
2119 sections against symbols defined externally
2120 in shared libraries. We can't do anything
2122 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2133 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
2134 (elf_hash_table (info
)->dynamic_sections_created
,
2137 || (!info
->symbolic
&& h
->dynindx
!= -1)
2138 || !h
->def_regular
))
2143 if (unresolved_reloc
)
2145 (_("%B(%A): warning: unresolvable relocation %d against symbol `%s'"),
2146 input_bfd
, input_section
,
2148 h
->root
.root
.string
);
2155 name
= h
->root
.root
.string
;
2158 name
= (bfd_elf_string_from_elf_section
2159 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2160 if (name
== NULL
|| *name
== '\0')
2161 name
= bfd_section_name (input_bfd
, sec
);
2164 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2165 input_section
, contents
, rel
,
2166 relocation
, info
, sec
, name
,
2167 (h
? ELF_ST_TYPE (h
->type
) :
2168 ELF_ST_TYPE (sym
->st_info
)), h
);
2170 if (r
!= bfd_reloc_ok
)
2172 const char * msg
= (const char *) 0;
2176 case bfd_reloc_overflow
:
2177 /* If the overflowing reloc was to an undefined symbol,
2178 we have already printed one error message and there
2179 is no point complaining again. */
2181 h
->root
.type
!= bfd_link_hash_undefined
)
2182 && (!((*info
->callbacks
->reloc_overflow
)
2183 (info
, name
, howto
->name
, (bfd_vma
) 0,
2184 input_bfd
, input_section
, rel
->r_offset
))))
2188 case bfd_reloc_undefined
:
2189 if (!((*info
->callbacks
->undefined_symbol
)
2190 (info
, name
, input_bfd
, input_section
,
2191 rel
->r_offset
, TRUE
)))
2195 case bfd_reloc_outofrange
:
2196 msg
= _("internal error: out of range error");
2199 case bfd_reloc_notsupported
:
2200 msg
= _("internal error: unsupported relocation error");
2203 case bfd_reloc_dangerous
:
2204 msg
= _("internal error: dangerous error");
2208 msg
= _("internal error: unknown error");
2212 if (!((*info
->callbacks
->warning
)
2213 (info
, msg
, name
, input_bfd
, input_section
,
2224 /* Set the right machine number. */
2227 elf32_arm_object_p (bfd
*abfd
)
2231 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2233 if (mach
!= bfd_mach_arm_unknown
)
2234 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2236 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
2237 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
2240 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2245 /* Function to keep ARM specific flags in the ELF header. */
2247 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
2249 if (elf_flags_init (abfd
)
2250 && elf_elfheader (abfd
)->e_flags
!= flags
)
2252 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2254 if (flags
& EF_ARM_INTERWORK
)
2255 (*_bfd_error_handler
)
2256 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
2260 (_("Warning: Clearing the interworking flag of %B due to outside request"),
2266 elf_elfheader (abfd
)->e_flags
= flags
;
2267 elf_flags_init (abfd
) = TRUE
;
2273 /* Copy backend specific data from one object module to another. */
2276 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2281 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2282 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2285 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2286 out_flags
= elf_elfheader (obfd
)->e_flags
;
2288 if (elf_flags_init (obfd
)
2289 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2290 && in_flags
!= out_flags
)
2292 /* Cannot mix APCS26 and APCS32 code. */
2293 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2296 /* Cannot mix float APCS and non-float APCS code. */
2297 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2300 /* If the src and dest have different interworking flags
2301 then turn off the interworking bit. */
2302 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2304 if (out_flags
& EF_ARM_INTERWORK
)
2306 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
2309 in_flags
&= ~EF_ARM_INTERWORK
;
2312 /* Likewise for PIC, though don't warn for this case. */
2313 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2314 in_flags
&= ~EF_ARM_PIC
;
2317 elf_elfheader (obfd
)->e_flags
= in_flags
;
2318 elf_flags_init (obfd
) = TRUE
;
2323 /* Merge backend specific data from an object file to the output
2324 object file when linking. */
2327 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
2331 bfd_boolean flags_compatible
= TRUE
;
2334 /* Check if we have the same endianess. */
2335 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2338 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2339 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2342 /* The input BFD must have had its flags initialised. */
2343 /* The following seems bogus to me -- The flags are initialized in
2344 the assembler but I don't think an elf_flags_init field is
2345 written into the object. */
2346 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2348 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2349 out_flags
= elf_elfheader (obfd
)->e_flags
;
2351 if (!elf_flags_init (obfd
))
2353 /* If the input is the default architecture and had the default
2354 flags then do not bother setting the flags for the output
2355 architecture, instead allow future merges to do this. If no
2356 future merges ever set these flags then they will retain their
2357 uninitialised values, which surprise surprise, correspond
2358 to the default values. */
2359 if (bfd_get_arch_info (ibfd
)->the_default
2360 && elf_elfheader (ibfd
)->e_flags
== 0)
2363 elf_flags_init (obfd
) = TRUE
;
2364 elf_elfheader (obfd
)->e_flags
= in_flags
;
2366 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2367 && bfd_get_arch_info (obfd
)->the_default
)
2368 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2373 /* Determine what should happen if the input ARM architecture
2374 does not match the output ARM architecture. */
2375 if (! bfd_arm_merge_machines (ibfd
, obfd
))
2378 /* Identical flags must be compatible. */
2379 if (in_flags
== out_flags
)
2382 /* Check to see if the input BFD actually contains any sections. If
2383 not, its flags may not have been initialised either, but it
2384 cannot actually cause any incompatibility. Do not short-circuit
2385 dynamic objects; their section list may be emptied by
2386 elf_link_add_object_symbols.
2388 Also check to see if there are no code sections in the input.
2389 In this case there is no need to check for code specific flags.
2390 XXX - do we need to worry about floating-point format compatability
2391 in data sections ? */
2392 if (!(ibfd
->flags
& DYNAMIC
))
2394 bfd_boolean null_input_bfd
= TRUE
;
2395 bfd_boolean only_data_sections
= TRUE
;
2397 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2399 /* Ignore synthetic glue sections. */
2400 if (strcmp (sec
->name
, ".glue_7")
2401 && strcmp (sec
->name
, ".glue_7t"))
2403 if ((bfd_get_section_flags (ibfd
, sec
)
2404 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2405 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2406 only_data_sections
= FALSE
;
2408 null_input_bfd
= FALSE
;
2413 if (null_input_bfd
|| only_data_sections
)
2417 /* Complain about various flag mismatches. */
2418 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2421 (_("ERROR: %B is compiled for EABI version %d, whereas %B is compiled for version %d"),
2423 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2424 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2428 /* Not sure what needs to be checked for EABI versions >= 1. */
2429 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2431 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2434 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
2436 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2437 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2438 flags_compatible
= FALSE
;
2441 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2443 if (in_flags
& EF_ARM_APCS_FLOAT
)
2445 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
2449 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
2452 flags_compatible
= FALSE
;
2455 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2457 if (in_flags
& EF_ARM_VFP_FLOAT
)
2459 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
2463 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
2466 flags_compatible
= FALSE
;
2469 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
2471 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
2473 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
2477 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
2480 flags_compatible
= FALSE
;
2483 #ifdef EF_ARM_SOFT_FLOAT
2484 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2486 /* We can allow interworking between code that is VFP format
2487 layout, and uses either soft float or integer regs for
2488 passing floating point arguments and results. We already
2489 know that the APCS_FLOAT flags match; similarly for VFP
2491 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2492 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2494 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2496 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
2500 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
2503 flags_compatible
= FALSE
;
2508 /* Interworking mismatch is only a warning. */
2509 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2511 if (in_flags
& EF_ARM_INTERWORK
)
2514 (_("Warning: %B supports interworking, whereas %B does not"),
2520 (_("Warning: %B does not support interworking, whereas %B does"),
2526 return flags_compatible
;
2529 /* Display the flags field. */
2532 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
2534 FILE * file
= (FILE *) ptr
;
2535 unsigned long flags
;
2537 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2539 /* Print normal ELF private data. */
2540 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2542 flags
= elf_elfheader (abfd
)->e_flags
;
2543 /* Ignore init flag - it may not be set, despite the flags field
2544 containing valid data. */
2546 /* xgettext:c-format */
2547 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2549 switch (EF_ARM_EABI_VERSION (flags
))
2551 case EF_ARM_EABI_UNKNOWN
:
2552 /* The following flag bits are GNU extensions and not part of the
2553 official ARM ELF extended ABI. Hence they are only decoded if
2554 the EABI version is not set. */
2555 if (flags
& EF_ARM_INTERWORK
)
2556 fprintf (file
, _(" [interworking enabled]"));
2558 if (flags
& EF_ARM_APCS_26
)
2559 fprintf (file
, " [APCS-26]");
2561 fprintf (file
, " [APCS-32]");
2563 if (flags
& EF_ARM_VFP_FLOAT
)
2564 fprintf (file
, _(" [VFP float format]"));
2565 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
2566 fprintf (file
, _(" [Maverick float format]"));
2568 fprintf (file
, _(" [FPA float format]"));
2570 if (flags
& EF_ARM_APCS_FLOAT
)
2571 fprintf (file
, _(" [floats passed in float registers]"));
2573 if (flags
& EF_ARM_PIC
)
2574 fprintf (file
, _(" [position independent]"));
2576 if (flags
& EF_ARM_NEW_ABI
)
2577 fprintf (file
, _(" [new ABI]"));
2579 if (flags
& EF_ARM_OLD_ABI
)
2580 fprintf (file
, _(" [old ABI]"));
2582 if (flags
& EF_ARM_SOFT_FLOAT
)
2583 fprintf (file
, _(" [software FP]"));
2585 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2586 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2587 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
2588 | EF_ARM_MAVERICK_FLOAT
);
2591 case EF_ARM_EABI_VER1
:
2592 fprintf (file
, _(" [Version1 EABI]"));
2594 if (flags
& EF_ARM_SYMSARESORTED
)
2595 fprintf (file
, _(" [sorted symbol table]"));
2597 fprintf (file
, _(" [unsorted symbol table]"));
2599 flags
&= ~ EF_ARM_SYMSARESORTED
;
2602 case EF_ARM_EABI_VER2
:
2603 fprintf (file
, _(" [Version2 EABI]"));
2605 if (flags
& EF_ARM_SYMSARESORTED
)
2606 fprintf (file
, _(" [sorted symbol table]"));
2608 fprintf (file
, _(" [unsorted symbol table]"));
2610 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2611 fprintf (file
, _(" [dynamic symbols use segment index]"));
2613 if (flags
& EF_ARM_MAPSYMSFIRST
)
2614 fprintf (file
, _(" [mapping symbols precede others]"));
2616 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2617 | EF_ARM_MAPSYMSFIRST
);
2620 case EF_ARM_EABI_VER3
:
2621 fprintf (file
, _(" [Version3 EABI]"));
2623 if (flags
& EF_ARM_BE8
)
2624 fprintf (file
, _(" [BE8]"));
2626 if (flags
& EF_ARM_LE8
)
2627 fprintf (file
, _(" [LE8]"));
2629 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
2633 fprintf (file
, _(" <EABI version unrecognised>"));
2637 flags
&= ~ EF_ARM_EABIMASK
;
2639 if (flags
& EF_ARM_RELEXEC
)
2640 fprintf (file
, _(" [relocatable executable]"));
2642 if (flags
& EF_ARM_HASENTRY
)
2643 fprintf (file
, _(" [has entry point]"));
2645 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2648 fprintf (file
, _("<Unrecognised flag bits set>"));
2656 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
2658 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2661 return ELF_ST_TYPE (elf_sym
->st_info
);
2664 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2665 This allows us to distinguish between data used by Thumb instructions
2666 and non-data (which is probably code) inside Thumb regions of an
2668 if (type
!= STT_OBJECT
)
2669 return ELF_ST_TYPE (elf_sym
->st_info
);
2680 elf32_arm_gc_mark_hook (asection
* sec
,
2681 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
2682 Elf_Internal_Rela
* rel
,
2683 struct elf_link_hash_entry
* h
,
2684 Elf_Internal_Sym
* sym
)
2688 switch (ELF32_R_TYPE (rel
->r_info
))
2690 case R_ARM_GNU_VTINHERIT
:
2691 case R_ARM_GNU_VTENTRY
:
2695 switch (h
->root
.type
)
2697 case bfd_link_hash_defined
:
2698 case bfd_link_hash_defweak
:
2699 return h
->root
.u
.def
.section
;
2701 case bfd_link_hash_common
:
2702 return h
->root
.u
.c
.p
->section
;
2710 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2715 /* Update the got entry reference counts for the section being removed. */
2718 elf32_arm_gc_sweep_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
2719 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
2720 asection
* sec ATTRIBUTE_UNUSED
,
2721 const Elf_Internal_Rela
* relocs ATTRIBUTE_UNUSED
)
2723 Elf_Internal_Shdr
*symtab_hdr
;
2724 struct elf_link_hash_entry
**sym_hashes
;
2725 bfd_signed_vma
*local_got_refcounts
;
2726 const Elf_Internal_Rela
*rel
, *relend
;
2727 unsigned long r_symndx
;
2728 struct elf_link_hash_entry
*h
;
2730 elf_section_data (sec
)->local_dynrel
= NULL
;
2732 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2733 sym_hashes
= elf_sym_hashes (abfd
);
2734 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2736 relend
= relocs
+ sec
->reloc_count
;
2737 for (rel
= relocs
; rel
< relend
; rel
++)
2738 switch (ELF32_R_TYPE (rel
->r_info
))
2741 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2742 if (r_symndx
>= symtab_hdr
->sh_info
)
2744 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2745 if (h
->got
.refcount
> 0)
2746 h
->got
.refcount
-= 1;
2748 else if (local_got_refcounts
!= NULL
)
2750 if (local_got_refcounts
[r_symndx
] > 0)
2751 local_got_refcounts
[r_symndx
] -= 1;
2762 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2763 if (r_symndx
>= symtab_hdr
->sh_info
)
2765 struct elf32_arm_link_hash_entry
*eh
;
2766 struct elf32_arm_relocs_copied
**pp
;
2767 struct elf32_arm_relocs_copied
*p
;
2769 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2771 if (h
->plt
.refcount
> 0)
2772 h
->plt
.refcount
-= 1;
2774 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
2776 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_TARGET1
2778 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
2780 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2782 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
2784 if (p
->section
== sec
)
2802 /* Look through the relocs for a section during the first phase. */
2805 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2806 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2808 Elf_Internal_Shdr
*symtab_hdr
;
2809 struct elf_link_hash_entry
**sym_hashes
;
2810 struct elf_link_hash_entry
**sym_hashes_end
;
2811 const Elf_Internal_Rela
*rel
;
2812 const Elf_Internal_Rela
*rel_end
;
2815 bfd_vma
*local_got_offsets
;
2816 struct elf32_arm_link_hash_table
*htab
;
2818 if (info
->relocatable
)
2821 htab
= elf32_arm_hash_table (info
);
2824 dynobj
= elf_hash_table (info
)->dynobj
;
2825 local_got_offsets
= elf_local_got_offsets (abfd
);
2827 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2828 sym_hashes
= elf_sym_hashes (abfd
);
2829 sym_hashes_end
= sym_hashes
2830 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2832 if (!elf_bad_symtab (abfd
))
2833 sym_hashes_end
-= symtab_hdr
->sh_info
;
2835 rel_end
= relocs
+ sec
->reloc_count
;
2836 for (rel
= relocs
; rel
< rel_end
; rel
++)
2838 struct elf_link_hash_entry
*h
;
2839 unsigned long r_symndx
;
2841 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2842 if (r_symndx
< symtab_hdr
->sh_info
)
2845 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2847 switch (ELF32_R_TYPE (rel
->r_info
))
2850 /* This symbol requires a global offset table entry. */
2857 bfd_signed_vma
*local_got_refcounts
;
2859 /* This is a global offset table entry for a local symbol. */
2860 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2861 if (local_got_refcounts
== NULL
)
2865 size
= symtab_hdr
->sh_info
;
2866 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
2867 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2868 if (local_got_refcounts
== NULL
)
2870 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2872 local_got_refcounts
[r_symndx
] += 1;
2878 if (htab
->sgot
== NULL
)
2880 if (htab
->root
.dynobj
== NULL
)
2881 htab
->root
.dynobj
= abfd
;
2882 if (!create_got_section (htab
->root
.dynobj
, info
))
2896 /* If this reloc is in a read-only section, we might
2897 need a copy reloc. We can't check reliably at this
2898 stage whether the section is read-only, as input
2899 sections have not yet been mapped to output sections.
2900 Tentatively set the flag for now, and correct in
2901 adjust_dynamic_symbol. */
2905 /* We may need a .plt entry if the function this reloc
2906 refers to is in a different object. We can't tell for
2907 sure yet, because something later might force the
2909 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
2910 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_PLT32
)
2913 /* If we create a PLT entry, this relocation will reference
2914 it, even if it's an ABS32 relocation. */
2915 h
->plt
.refcount
+= 1;
2918 /* If we are creating a shared library, and this is a reloc
2919 against a global symbol, or a non PC relative reloc
2920 against a local symbol, then we need to copy the reloc
2921 into the shared library. However, if we are linking with
2922 -Bsymbolic, we do not need to copy a reloc against a
2923 global symbol which is defined in an object we are
2924 including in the link (i.e., DEF_REGULAR is set). At
2925 this point we have not seen all the input files, so it is
2926 possible that DEF_REGULAR is not set now but will be set
2927 later (it is never cleared). We account for that
2928 possibility below by storing information in the
2929 relocs_copied field of the hash table entry. */
2931 && (sec
->flags
& SEC_ALLOC
) != 0
2932 && ((ELF32_R_TYPE (rel
->r_info
) != R_ARM_PC24
2933 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_PLT32
2935 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_TARGET1
2937 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_REL32
)
2939 && (! info
->symbolic
2940 || !h
->def_regular
))))
2942 struct elf32_arm_relocs_copied
*p
, **head
;
2944 /* When creating a shared object, we must copy these
2945 reloc types into the output file. We create a reloc
2946 section in dynobj and make room for this reloc. */
2951 name
= (bfd_elf_string_from_elf_section
2953 elf_elfheader (abfd
)->e_shstrndx
,
2954 elf_section_data (sec
)->rel_hdr
.sh_name
));
2958 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
2959 && strcmp (bfd_get_section_name (abfd
, sec
),
2962 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2967 sreloc
= bfd_make_section (dynobj
, name
);
2968 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2969 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2970 if ((sec
->flags
& SEC_ALLOC
) != 0
2971 /* BPABI objects never have dynamic
2972 relocations mapped. */
2973 && !htab
->symbian_p
)
2974 flags
|= SEC_ALLOC
| SEC_LOAD
;
2976 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2977 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2981 elf_section_data (sec
)->sreloc
= sreloc
;
2984 /* If this is a global symbol, we count the number of
2985 relocations we need for this symbol. */
2988 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
2992 /* Track dynamic relocs needed for local syms too.
2993 We really need local syms available to do this
2997 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3002 head
= ((struct elf32_arm_relocs_copied
**)
3003 &elf_section_data (s
)->local_dynrel
);
3007 if (p
== NULL
|| p
->section
!= sec
)
3009 bfd_size_type amt
= sizeof *p
;
3011 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
3020 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
3022 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_TARGET1
3024 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
3029 /* This relocation describes the C++ object vtable hierarchy.
3030 Reconstruct it for later use during GC. */
3031 case R_ARM_GNU_VTINHERIT
:
3032 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3036 /* This relocation describes which C++ vtable entries are actually
3037 used. Record for later use during GC. */
3038 case R_ARM_GNU_VTENTRY
:
3039 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
3049 is_arm_mapping_symbol_name (const char * name
)
3051 return (name
!= NULL
)
3053 && ((name
[1] == 'a') || (name
[1] == 't') || (name
[1] == 'd'))
3057 /* This is a copy of elf_find_function() from elf.c except that
3058 ARM mapping symbols are ignored when looking for function names
3059 and STT_ARM_TFUNC is considered to a function type. */
3062 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
3066 const char ** filename_ptr
,
3067 const char ** functionname_ptr
)
3069 const char * filename
= NULL
;
3070 asymbol
* func
= NULL
;
3071 bfd_vma low_func
= 0;
3074 for (p
= symbols
; *p
!= NULL
; p
++)
3078 q
= (elf_symbol_type
*) *p
;
3080 if (bfd_get_section (&q
->symbol
) != section
)
3083 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
3088 filename
= bfd_asymbol_name (&q
->symbol
);
3092 /* Skip $a and $t symbols. */
3093 if ((q
->symbol
.flags
& BSF_LOCAL
)
3094 && is_arm_mapping_symbol_name (q
->symbol
.name
))
3098 if (q
->symbol
.section
== section
3099 && q
->symbol
.value
>= low_func
3100 && q
->symbol
.value
<= offset
)
3102 func
= (asymbol
*) q
;
3103 low_func
= q
->symbol
.value
;
3113 *filename_ptr
= filename
;
3114 if (functionname_ptr
)
3115 *functionname_ptr
= bfd_asymbol_name (func
);
3121 /* Find the nearest line to a particular section and offset, for error
3122 reporting. This code is a duplicate of the code in elf.c, except
3123 that it uses arm_elf_find_function. */
3126 elf32_arm_find_nearest_line (bfd
* abfd
,
3130 const char ** filename_ptr
,
3131 const char ** functionname_ptr
,
3132 unsigned int * line_ptr
)
3134 bfd_boolean found
= FALSE
;
3136 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
3138 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3139 filename_ptr
, functionname_ptr
,
3141 & elf_tdata (abfd
)->dwarf2_find_line_info
))
3143 if (!*functionname_ptr
)
3144 arm_elf_find_function (abfd
, section
, symbols
, offset
,
3145 *filename_ptr
? NULL
: filename_ptr
,
3151 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
3152 & found
, filename_ptr
,
3153 functionname_ptr
, line_ptr
,
3154 & elf_tdata (abfd
)->line_info
))
3157 if (found
&& (*functionname_ptr
|| *line_ptr
))
3160 if (symbols
== NULL
)
3163 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
3164 filename_ptr
, functionname_ptr
))
3171 /* Adjust a symbol defined by a dynamic object and referenced by a
3172 regular object. The current definition is in some section of the
3173 dynamic object, but we're not including those sections. We have to
3174 change the definition to something the rest of the link can
3178 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
3179 struct elf_link_hash_entry
* h
)
3183 unsigned int power_of_two
;
3185 dynobj
= elf_hash_table (info
)->dynobj
;
3187 /* Make sure we know what is going on here. */
3188 BFD_ASSERT (dynobj
!= NULL
3190 || h
->weakdef
!= NULL
3193 && !h
->def_regular
)));
3195 /* If this is a function, put it in the procedure linkage table. We
3196 will fill in the contents of the procedure linkage table later,
3197 when we know the address of the .got section. */
3198 if (h
->type
== STT_FUNC
3201 if (h
->plt
.refcount
<= 0
3202 || SYMBOL_CALLS_LOCAL (info
, h
)
3203 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3204 && h
->root
.type
== bfd_link_hash_undefweak
))
3206 /* This case can occur if we saw a PLT32 reloc in an input
3207 file, but the symbol was never referred to by a dynamic
3208 object, or if all references were garbage collected. In
3209 such a case, we don't actually need to build a procedure
3210 linkage table, and we can just do a PC24 reloc instead. */
3211 h
->plt
.offset
= (bfd_vma
) -1;
3218 /* It's possible that we incorrectly decided a .plt reloc was
3219 needed for an R_ARM_PC24 reloc to a non-function sym in
3220 check_relocs. We can't decide accurately between function and
3221 non-function syms in check-relocs; Objects loaded later in
3222 the link may change h->type. So fix it now. */
3223 h
->plt
.offset
= (bfd_vma
) -1;
3225 /* If this is a weak symbol, and there is a real definition, the
3226 processor independent code will have arranged for us to see the
3227 real definition first, and we can just use the same value. */
3228 if (h
->weakdef
!= NULL
)
3230 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3231 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3232 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3233 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3237 /* This is a reference to a symbol defined by a dynamic object which
3238 is not a function. */
3240 /* If we are creating a shared library, we must presume that the
3241 only references to the symbol are via the global offset table.
3242 For such cases we need not do anything here; the relocations will
3243 be handled correctly by relocate_section. */
3247 /* We must allocate the symbol in our .dynbss section, which will
3248 become part of the .bss section of the executable. There will be
3249 an entry for this symbol in the .dynsym section. The dynamic
3250 object will contain position independent code, so all references
3251 from the dynamic object to this symbol will go through the global
3252 offset table. The dynamic linker will use the .dynsym entry to
3253 determine the address it must put in the global offset table, so
3254 both the dynamic object and the regular object will refer to the
3255 same memory location for the variable. */
3256 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3257 BFD_ASSERT (s
!= NULL
);
3259 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
3260 copy the initial value out of the dynamic object and into the
3261 runtime process image. We need to remember the offset into the
3262 .rel.bss section we are going to use. */
3263 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3267 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
3268 BFD_ASSERT (srel
!= NULL
);
3269 srel
->size
+= sizeof (Elf32_External_Rel
);
3273 /* We need to figure out the alignment required for this symbol. I
3274 have no idea how ELF linkers handle this. */
3275 power_of_two
= bfd_log2 (h
->size
);
3276 if (power_of_two
> 3)
3279 /* Apply the required alignment. */
3280 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3281 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3283 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3287 /* Define the symbol as being at this point in the section. */
3288 h
->root
.u
.def
.section
= s
;
3289 h
->root
.u
.def
.value
= s
->size
;
3291 /* Increment the section size to make room for the symbol. */
3297 /* Allocate space in .plt, .got and associated reloc sections for
3301 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3303 struct bfd_link_info
*info
;
3304 struct elf32_arm_link_hash_table
*htab
;
3305 struct elf32_arm_link_hash_entry
*eh
;
3306 struct elf32_arm_relocs_copied
*p
;
3308 if (h
->root
.type
== bfd_link_hash_indirect
)
3311 if (h
->root
.type
== bfd_link_hash_warning
)
3312 /* When warning symbols are created, they **replace** the "real"
3313 entry in the hash table, thus we never get to see the real
3314 symbol in a hash traversal. So look at it now. */
3315 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3317 info
= (struct bfd_link_info
*) inf
;
3318 htab
= elf32_arm_hash_table (info
);
3320 if (htab
->root
.dynamic_sections_created
3321 && h
->plt
.refcount
> 0)
3323 /* Make sure this symbol is output as a dynamic symbol.
3324 Undefined weak syms won't yet be marked as dynamic. */
3325 if (h
->dynindx
== -1
3326 && !h
->forced_local
)
3328 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3333 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3335 asection
*s
= htab
->splt
;
3337 /* If this is the first .plt entry, make room for the special
3340 s
->size
+= htab
->plt_header_size
;
3342 h
->plt
.offset
= s
->size
;
3344 /* If this symbol is not defined in a regular file, and we are
3345 not generating a shared library, then set the symbol to this
3346 location in the .plt. This is required to make function
3347 pointers compare as equal between the normal executable and
3348 the shared library. */
3352 h
->root
.u
.def
.section
= s
;
3353 h
->root
.u
.def
.value
= h
->plt
.offset
;
3356 /* Make room for this entry. */
3357 s
->size
+= htab
->plt_entry_size
;
3359 if (!htab
->symbian_p
)
3360 /* We also need to make an entry in the .got.plt section, which
3361 will be placed in the .got section by the linker script. */
3362 htab
->sgotplt
->size
+= 4;
3364 /* We also need to make an entry in the .rel.plt section. */
3365 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
3369 h
->plt
.offset
= (bfd_vma
) -1;
3375 h
->plt
.offset
= (bfd_vma
) -1;
3379 if (h
->got
.refcount
> 0)
3384 /* Make sure this symbol is output as a dynamic symbol.
3385 Undefined weak syms won't yet be marked as dynamic. */
3386 if (h
->dynindx
== -1
3387 && !h
->forced_local
)
3389 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3393 if (!htab
->symbian_p
)
3396 h
->got
.offset
= s
->size
;
3398 dyn
= htab
->root
.dynamic_sections_created
;
3399 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3400 || h
->root
.type
!= bfd_link_hash_undefweak
)
3402 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3403 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
3407 h
->got
.offset
= (bfd_vma
) -1;
3409 eh
= (struct elf32_arm_link_hash_entry
*) h
;
3410 if (eh
->relocs_copied
== NULL
)
3413 /* In the shared -Bsymbolic case, discard space allocated for
3414 dynamic pc-relative relocs against symbols which turn out to be
3415 defined in regular objects. For the normal shared case, discard
3416 space for pc-relative relocs that have become local due to symbol
3417 visibility changes. */
3421 /* Discard relocs on undefined weak syms with non-default
3423 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3424 && h
->root
.type
== bfd_link_hash_undefweak
)
3425 eh
->relocs_copied
= NULL
;
3429 /* For the non-shared case, discard space for relocs against
3430 symbols which turn out to need copy relocs or are not
3436 || (htab
->root
.dynamic_sections_created
3437 && (h
->root
.type
== bfd_link_hash_undefweak
3438 || h
->root
.type
== bfd_link_hash_undefined
))))
3440 /* Make sure this symbol is output as a dynamic symbol.
3441 Undefined weak syms won't yet be marked as dynamic. */
3442 if (h
->dynindx
== -1
3443 && !h
->forced_local
)
3445 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3449 /* If that succeeded, we know we'll be keeping all the
3451 if (h
->dynindx
!= -1)
3455 eh
->relocs_copied
= NULL
;
3460 /* Finally, allocate space. */
3461 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
3463 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
3464 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3470 /* Set the sizes of the dynamic sections. */
3473 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
3474 struct bfd_link_info
* info
)
3481 struct elf32_arm_link_hash_table
*htab
;
3483 htab
= elf32_arm_hash_table (info
);
3484 dynobj
= elf_hash_table (info
)->dynobj
;
3485 BFD_ASSERT (dynobj
!= NULL
);
3487 if (elf_hash_table (info
)->dynamic_sections_created
)
3489 /* Set the contents of the .interp section to the interpreter. */
3490 if (info
->executable
)
3492 s
= bfd_get_section_by_name (dynobj
, ".interp");
3493 BFD_ASSERT (s
!= NULL
);
3494 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3495 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3499 /* Set up .got offsets for local syms, and space for local dynamic
3501 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3503 bfd_signed_vma
*local_got
;
3504 bfd_signed_vma
*end_local_got
;
3505 char *local_tls_type
;
3506 bfd_size_type locsymcount
;
3507 Elf_Internal_Shdr
*symtab_hdr
;
3510 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3513 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3515 struct elf32_arm_relocs_copied
*p
;
3517 for (p
= *((struct elf32_arm_relocs_copied
**)
3518 &elf_section_data (s
)->local_dynrel
);
3522 if (!bfd_is_abs_section (p
->section
)
3523 && bfd_is_abs_section (p
->section
->output_section
))
3525 /* Input section has been discarded, either because
3526 it is a copy of a linkonce section or due to
3527 linker script /DISCARD/, so we'll be discarding
3530 else if (p
->count
!= 0)
3532 srel
= elf_section_data (p
->section
)->sreloc
;
3533 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3534 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
3535 info
->flags
|= DF_TEXTREL
;
3540 local_got
= elf_local_got_refcounts (ibfd
);
3544 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3545 locsymcount
= symtab_hdr
->sh_info
;
3546 end_local_got
= local_got
+ locsymcount
;
3548 srel
= htab
->srelgot
;
3549 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
3553 *local_got
= s
->size
;
3556 srel
->size
+= sizeof (Elf32_External_Rel
);
3559 *local_got
= (bfd_vma
) -1;
3563 /* Allocate global sym .plt and .got entries, and space for global
3564 sym dynamic relocs. */
3565 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
3567 /* The check_relocs and adjust_dynamic_symbol entry points have
3568 determined the sizes of the various dynamic sections. Allocate
3572 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3577 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3580 /* It's OK to base decisions on the section name, because none
3581 of the dynobj section names depend upon the input files. */
3582 name
= bfd_get_section_name (dynobj
, s
);
3586 if (strcmp (name
, ".plt") == 0)
3590 /* Strip this section if we don't need it; see the
3596 /* Remember whether there is a PLT. */
3600 else if (strncmp (name
, ".rel", 4) == 0)
3604 /* If we don't need this section, strip it from the
3605 output file. This is mostly to handle .rel.bss and
3606 .rel.plt. We must create both sections in
3607 create_dynamic_sections, because they must be created
3608 before the linker maps input sections to output
3609 sections. The linker does that before
3610 adjust_dynamic_symbol is called, and it is that
3611 function which decides whether anything needs to go
3612 into these sections. */
3617 /* Remember whether there are any reloc sections other
3619 if (strcmp (name
, ".rel.plt") != 0)
3622 /* We use the reloc_count field as a counter if we need
3623 to copy relocs into the output file. */
3627 else if (strncmp (name
, ".got", 4) != 0)
3629 /* It's not one of our sections, so don't allocate space. */
3635 _bfd_strip_section_from_output (info
, s
);
3639 /* Allocate memory for the section contents. */
3640 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3641 if (s
->contents
== NULL
&& s
->size
!= 0)
3645 if (elf_hash_table (info
)->dynamic_sections_created
)
3647 /* Add some entries to the .dynamic section. We fill in the
3648 values later, in elf32_arm_finish_dynamic_sections, but we
3649 must add the entries now so that we get the correct size for
3650 the .dynamic section. The DT_DEBUG entry is filled in by the
3651 dynamic linker and used by the debugger. */
3652 #define add_dynamic_entry(TAG, VAL) \
3653 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3657 if (!add_dynamic_entry (DT_DEBUG
, 0))
3663 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3664 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3665 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3666 || !add_dynamic_entry (DT_JMPREL
, 0))
3672 if ( !add_dynamic_entry (DT_REL
, 0)
3673 || !add_dynamic_entry (DT_RELSZ
, 0)
3674 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3678 if ((info
->flags
& DF_TEXTREL
) != 0)
3680 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3682 info
->flags
|= DF_TEXTREL
;
3685 #undef add_synamic_entry
3690 /* Finish up dynamic symbol handling. We set the contents of various
3691 dynamic sections here. */
3694 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
3695 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
3698 struct elf32_arm_link_hash_table
*htab
;
3700 dynobj
= elf_hash_table (info
)->dynobj
;
3701 htab
= elf32_arm_hash_table (info
);
3703 if (h
->plt
.offset
!= (bfd_vma
) -1)
3709 Elf_Internal_Rela rel
;
3711 /* This symbol has an entry in the procedure linkage table. Set
3714 BFD_ASSERT (h
->dynindx
!= -1);
3716 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3717 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3718 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
3720 /* Get the index in the procedure linkage table which
3721 corresponds to this symbol. This is the index of this symbol
3722 in all the symbols for which we are making plt entries. The
3723 first entry in the procedure linkage table is reserved. */
3724 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
3725 / htab
->plt_entry_size
);
3727 /* Fill in the entry in the procedure linkage table. */
3728 if (htab
->symbian_p
)
3731 for (i
= 0; i
< htab
->plt_entry_size
/ 4; ++i
)
3732 bfd_put_32 (output_bfd
,
3733 elf32_arm_symbian_plt_entry
[i
],
3734 splt
->contents
+ h
->plt
.offset
+ 4 * i
);
3736 /* Fill in the entry in the .rel.plt section. */
3737 rel
.r_offset
= (splt
->output_offset
3738 + h
->plt
.offset
+ 4 * (i
- 1));
3739 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3744 bfd_vma got_displacement
;
3747 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3748 BFD_ASSERT (sgot
!= NULL
);
3750 /* Get the offset into the .got table of the entry that
3751 corresponds to this function. Each .got entry is 4 bytes.
3752 The first three are reserved. */
3753 got_offset
= (plt_index
+ 3) * 4;
3755 /* Calculate the displacement between the PLT slot and the
3756 entry in the GOT. */
3757 got_displacement
= (sgot
->output_section
->vma
3758 + sgot
->output_offset
3760 - splt
->output_section
->vma
3761 - splt
->output_offset
3765 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
3767 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
3768 splt
->contents
+ h
->plt
.offset
+ 0);
3769 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
3770 splt
->contents
+ h
->plt
.offset
+ 4);
3771 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
3772 splt
->contents
+ h
->plt
.offset
+ 8);
3773 #ifdef FOUR_WORD_PLT
3774 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
3775 splt
->contents
+ h
->plt
.offset
+ 12);
3778 /* Fill in the entry in the global offset table. */
3779 bfd_put_32 (output_bfd
,
3780 (splt
->output_section
->vma
3781 + splt
->output_offset
),
3782 sgot
->contents
+ got_offset
);
3784 /* Fill in the entry in the .rel.plt section. */
3785 rel
.r_offset
= (sgot
->output_section
->vma
3786 + sgot
->output_offset
3788 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3791 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3792 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3794 if (!h
->def_regular
)
3796 /* Mark the symbol as undefined, rather than as defined in
3797 the .plt section. Leave the value alone. */
3798 sym
->st_shndx
= SHN_UNDEF
;
3799 /* If the symbol is weak, we do need to clear the value.
3800 Otherwise, the PLT entry would provide a definition for
3801 the symbol even if the symbol wasn't defined anywhere,
3802 and so the symbol would never be NULL. */
3803 if (!h
->ref_regular_nonweak
)
3808 if (h
->got
.offset
!= (bfd_vma
) -1)
3812 Elf_Internal_Rela rel
;
3815 /* This symbol has an entry in the global offset table. Set it
3817 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3818 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3819 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3821 rel
.r_offset
= (sgot
->output_section
->vma
3822 + sgot
->output_offset
3823 + (h
->got
.offset
&~ (bfd_vma
) 1));
3825 /* If this is a static link, or it is a -Bsymbolic link and the
3826 symbol is defined locally or was forced to be local because
3827 of a version file, we just want to emit a RELATIVE reloc.
3828 The entry in the global offset table will already have been
3829 initialized in the relocate_section function. */
3831 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3833 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3834 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3838 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3839 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3840 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3843 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3844 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3850 Elf_Internal_Rela rel
;
3853 /* This symbol needs a copy reloc. Set it up. */
3854 BFD_ASSERT (h
->dynindx
!= -1
3855 && (h
->root
.type
== bfd_link_hash_defined
3856 || h
->root
.type
== bfd_link_hash_defweak
));
3858 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3860 BFD_ASSERT (s
!= NULL
);
3862 rel
.r_offset
= (h
->root
.u
.def
.value
3863 + h
->root
.u
.def
.section
->output_section
->vma
3864 + h
->root
.u
.def
.section
->output_offset
);
3865 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3866 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3867 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3870 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3871 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3872 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3873 sym
->st_shndx
= SHN_ABS
;
3878 /* Finish up the dynamic sections. */
3881 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
3887 dynobj
= elf_hash_table (info
)->dynobj
;
3889 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3890 BFD_ASSERT (elf32_arm_hash_table (info
)->symbian_p
|| sgot
!= NULL
);
3891 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3893 if (elf_hash_table (info
)->dynamic_sections_created
)
3896 Elf32_External_Dyn
*dyncon
, *dynconend
;
3897 struct elf32_arm_link_hash_table
*htab
;
3899 htab
= elf32_arm_hash_table (info
);
3900 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3901 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3903 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3904 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3906 for (; dyncon
< dynconend
; dyncon
++)
3908 Elf_Internal_Dyn dyn
;
3912 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3923 goto get_vma_if_bpabi
;
3926 goto get_vma_if_bpabi
;
3929 goto get_vma_if_bpabi
;
3937 s
= bfd_get_section_by_name (output_bfd
, name
);
3938 BFD_ASSERT (s
!= NULL
);
3939 if (!htab
->symbian_p
)
3940 dyn
.d_un
.d_ptr
= s
->vma
;
3942 /* In the BPABI, tags in the PT_DYNAMIC section point
3943 at the file offset, not the memory address, for the
3944 convenience of the post linker. */
3945 dyn
.d_un
.d_ptr
= s
->filepos
;
3946 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3950 if (htab
->symbian_p
)
3955 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3956 BFD_ASSERT (s
!= NULL
);
3957 dyn
.d_un
.d_val
= s
->size
;
3958 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3962 if (!htab
->symbian_p
)
3964 /* My reading of the SVR4 ABI indicates that the
3965 procedure linkage table relocs (DT_JMPREL) should be
3966 included in the overall relocs (DT_REL). This is
3967 what Solaris does. However, UnixWare can not handle
3968 that case. Therefore, we override the DT_RELSZ entry
3969 here to make it not include the JMPREL relocs. Since
3970 the linker script arranges for .rel.plt to follow all
3971 other relocation sections, we don't have to worry
3972 about changing the DT_REL entry. */
3973 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3975 dyn
.d_un
.d_val
-= s
->size
;
3976 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3984 /* In the BPABI, the DT_REL tag must point at the file
3985 offset, not the VMA, of the first relocation
3986 section. So, we use code similar to that in
3987 elflink.c, but do not check for SHF_ALLOC on the
3988 relcoation section, since relocations sections are
3989 never allocated under the BPABI. The comments above
3990 about Unixware notwithstanding, we include all of the
3991 relocations here. */
3992 if (htab
->symbian_p
)
3995 type
= ((dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
3996 ? SHT_REL
: SHT_RELA
);
3998 for (i
= 1; i
< elf_numsections (output_bfd
); i
++)
4000 Elf_Internal_Shdr
*hdr
4001 = elf_elfsections (output_bfd
)[i
];
4002 if (hdr
->sh_type
== type
)
4004 if (dyn
.d_tag
== DT_RELSZ
4005 || dyn
.d_tag
== DT_RELASZ
)
4006 dyn
.d_un
.d_val
+= hdr
->sh_size
;
4007 else if (dyn
.d_un
.d_val
== 0
4008 || hdr
->sh_offset
< dyn
.d_un
.d_val
)
4009 dyn
.d_un
.d_val
= hdr
->sh_offset
;
4012 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4016 /* Set the bottom bit of DT_INIT/FINI if the
4017 corresponding function is Thumb. */
4019 name
= info
->init_function
;
4022 name
= info
->fini_function
;
4024 /* If it wasn't set by elf_bfd_final_link
4025 then there is nothing to adjust. */
4026 if (dyn
.d_un
.d_val
!= 0)
4028 struct elf_link_hash_entry
* eh
;
4030 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
4031 FALSE
, FALSE
, TRUE
);
4032 if (eh
!= (struct elf_link_hash_entry
*) NULL
4033 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
4035 dyn
.d_un
.d_val
|= 1;
4036 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4043 /* Fill in the first entry in the procedure linkage table. */
4044 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
4046 bfd_vma got_displacement
;
4048 /* Calculate the displacement between the PLT slot and &GOT[0]. */
4049 got_displacement
= (sgot
->output_section
->vma
4050 + sgot
->output_offset
4051 - splt
->output_section
->vma
4052 - splt
->output_offset
4055 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
4056 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
4057 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
4058 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
4059 #ifdef FOUR_WORD_PLT
4060 /* The displacement value goes in the otherwise-unused last word of
4061 the second entry. */
4062 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
4064 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
4068 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4069 really seem like the right value. */
4070 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
4073 /* Fill in the first three entries in the global offset table. */
4079 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4081 bfd_put_32 (output_bfd
,
4082 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4084 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4085 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4088 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4095 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
4097 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
4098 struct elf32_arm_link_hash_table
*globals
;
4100 i_ehdrp
= elf_elfheader (abfd
);
4102 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
4103 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
4107 globals
= elf32_arm_hash_table (link_info
);
4108 if (globals
->byteswap_code
)
4109 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
4113 static enum elf_reloc_type_class
4114 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
4116 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4118 case R_ARM_RELATIVE
:
4119 return reloc_class_relative
;
4120 case R_ARM_JUMP_SLOT
:
4121 return reloc_class_plt
;
4123 return reloc_class_copy
;
4125 return reloc_class_normal
;
4129 static bfd_boolean
elf32_arm_section_flags (flagword
*, const Elf_Internal_Shdr
*);
4130 static void elf32_arm_final_write_processing (bfd
*, bfd_boolean
);
4132 /* Set the right machine number for an Arm ELF file. */
4135 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
4137 if (hdr
->sh_type
== SHT_NOTE
)
4138 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
4144 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
4146 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
4150 /* Called for each symbol. Builds a section map based on mapping symbols.
4151 Does not alter any of the symbols. */
4154 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
4156 Elf_Internal_Sym
*elfsym
,
4157 asection
*input_sec
,
4158 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4161 elf32_arm_section_map
*map
;
4162 struct elf32_arm_link_hash_table
*globals
;
4164 /* Only do this on final link. */
4165 if (info
->relocatable
)
4168 /* Only build a map if we need to byteswap code. */
4169 globals
= elf32_arm_hash_table (info
);
4170 if (!globals
->byteswap_code
)
4173 /* We only want mapping symbols. */
4174 if (! is_arm_mapping_symbol_name (name
))
4177 mapcount
= ++(elf32_arm_section_data (input_sec
)->mapcount
);
4178 map
= elf32_arm_section_data (input_sec
)->map
;
4179 /* TODO: This may be inefficient, but we probably don't usually have many
4180 mapping symbols per section. */
4181 map
= bfd_realloc (map
, mapcount
* sizeof (elf32_arm_section_map
));
4182 elf32_arm_section_data (input_sec
)->map
= map
;
4184 map
[mapcount
- 1].vma
= elfsym
->st_value
;
4185 map
[mapcount
- 1].type
= name
[1];
4190 /* Allocate target specific section data. */
4193 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
4195 struct _arm_elf_section_data
*sdata
;
4196 bfd_size_type amt
= sizeof (*sdata
);
4198 sdata
= bfd_zalloc (abfd
, amt
);
4201 sec
->used_by_bfd
= sdata
;
4203 return _bfd_elf_new_section_hook (abfd
, sec
);
4207 /* Used to order a list of mapping symbols by address. */
4210 elf32_arm_compare_mapping (const void * a
, const void * b
)
4212 return ((const elf32_arm_section_map
*) a
)->vma
4213 > ((const elf32_arm_section_map
*) b
)->vma
;
4217 /* Do code byteswapping. Return FALSE afterwards so that the section is
4218 written out as normal. */
4221 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
4225 elf32_arm_section_map
*map
;
4232 mapcount
= elf32_arm_section_data (sec
)->mapcount
;
4233 map
= elf32_arm_section_data (sec
)->map
;
4238 qsort (map
, mapcount
, sizeof (elf32_arm_section_map
),
4239 elf32_arm_compare_mapping
);
4241 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4242 ptr
= map
[0].vma
- offset
;
4243 for (i
= 0; i
< mapcount
; i
++)
4245 if (i
== mapcount
- 1)
4248 end
= map
[i
+ 1].vma
- offset
;
4250 switch (map
[i
].type
)
4253 /* Byte swap code words. */
4254 while (ptr
+ 3 < end
)
4256 tmp
= contents
[ptr
];
4257 contents
[ptr
] = contents
[ptr
+ 3];
4258 contents
[ptr
+ 3] = tmp
;
4259 tmp
= contents
[ptr
+ 1];
4260 contents
[ptr
+ 1] = contents
[ptr
+ 2];
4261 contents
[ptr
+ 2] = tmp
;
4267 /* Byte swap code halfwords. */
4268 while (ptr
+ 1 < end
)
4270 tmp
= contents
[ptr
];
4271 contents
[ptr
] = contents
[ptr
+ 1];
4272 contents
[ptr
+ 1] = tmp
;
4278 /* Leave data alone. */
4287 #define ELF_ARCH bfd_arch_arm
4288 #define ELF_MACHINE_CODE EM_ARM
4289 #ifdef __QNXTARGET__
4290 #define ELF_MAXPAGESIZE 0x1000
4292 #define ELF_MAXPAGESIZE 0x8000
4295 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
4296 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
4297 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
4298 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
4299 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
4300 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
4301 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4302 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
4304 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
4305 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
4306 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
4307 #define elf_backend_check_relocs elf32_arm_check_relocs
4308 #define elf_backend_relocate_section elf32_arm_relocate_section
4309 #define elf_backend_write_section elf32_arm_write_section
4310 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
4311 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
4312 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
4313 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
4314 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
4315 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
4316 #define elf_backend_post_process_headers elf32_arm_post_process_headers
4317 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
4318 #define elf_backend_object_p elf32_arm_object_p
4319 #define elf_backend_section_flags elf32_arm_section_flags
4320 #define elf_backend_final_write_processing elf32_arm_final_write_processing
4321 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
4323 #define elf_backend_can_refcount 1
4324 #define elf_backend_can_gc_sections 1
4325 #define elf_backend_plt_readonly 1
4326 #define elf_backend_want_got_plt 1
4327 #define elf_backend_want_plt_sym 0
4329 #define elf_backend_rela_normal 1
4332 #define elf_backend_got_header_size 12
4334 #include "elf32-target.h"