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 /* The number of bytes in the initial entry in the PLT. */
186 bfd_size_type plt_header_size
;
188 /* The number of bytes in the subsequent PLT etries. */
189 bfd_size_type plt_entry_size
;
191 /* True if the target system is Symbian OS. */
194 /* Short-cuts to get to dynamic linker sections. */
203 /* Small local sym to section mapping cache. */
204 struct sym_sec_cache sym_sec
;
207 /* Create an entry in an ARM ELF linker hash table. */
209 static struct bfd_hash_entry
*
210 elf32_arm_link_hash_newfunc (struct bfd_hash_entry
* entry
,
211 struct bfd_hash_table
* table
,
214 struct elf32_arm_link_hash_entry
* ret
=
215 (struct elf32_arm_link_hash_entry
*) entry
;
217 /* Allocate the structure if it has not already been allocated by a
219 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
220 ret
= bfd_hash_allocate (table
, sizeof (struct elf32_arm_link_hash_entry
));
222 return (struct bfd_hash_entry
*) ret
;
224 /* Call the allocation method of the superclass. */
225 ret
= ((struct elf32_arm_link_hash_entry
*)
226 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
229 ret
->relocs_copied
= NULL
;
231 return (struct bfd_hash_entry
*) ret
;
234 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
235 shortcuts to them in our hash table. */
238 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
240 struct elf32_arm_link_hash_table
*htab
;
242 htab
= elf32_arm_hash_table (info
);
243 /* BPABI objects never have a GOT, or associated sections. */
247 if (! _bfd_elf_create_got_section (dynobj
, info
))
250 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
251 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
252 if (!htab
->sgot
|| !htab
->sgotplt
)
255 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
256 if (htab
->srelgot
== NULL
257 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
258 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
259 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
261 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
266 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
267 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
271 elf32_arm_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
273 struct elf32_arm_link_hash_table
*htab
;
275 htab
= elf32_arm_hash_table (info
);
276 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
279 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
282 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
283 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
284 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
286 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
291 || (!info
->shared
&& !htab
->srelbss
))
297 /* Copy the extra info we tack onto an elf_link_hash_entry. */
300 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
301 struct elf_link_hash_entry
*dir
,
302 struct elf_link_hash_entry
*ind
)
304 struct elf32_arm_link_hash_entry
*edir
, *eind
;
306 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
307 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
309 if (eind
->relocs_copied
!= NULL
)
311 if (edir
->relocs_copied
!= NULL
)
313 struct elf32_arm_relocs_copied
**pp
;
314 struct elf32_arm_relocs_copied
*p
;
316 if (ind
->root
.type
== bfd_link_hash_indirect
)
319 /* Add reloc counts against the weak sym to the strong sym
320 list. Merge any entries against the same section. */
321 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
323 struct elf32_arm_relocs_copied
*q
;
325 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
326 if (q
->section
== p
->section
)
328 q
->count
+= p
->count
;
335 *pp
= edir
->relocs_copied
;
338 edir
->relocs_copied
= eind
->relocs_copied
;
339 eind
->relocs_copied
= NULL
;
342 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
345 /* Create an ARM elf linker hash table. */
347 static struct bfd_link_hash_table
*
348 elf32_arm_link_hash_table_create (bfd
*abfd
)
350 struct elf32_arm_link_hash_table
*ret
;
351 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
353 ret
= bfd_malloc (amt
);
357 if (!_bfd_elf_link_hash_table_init (& ret
->root
, abfd
,
358 elf32_arm_link_hash_newfunc
))
371 ret
->thumb_glue_size
= 0;
372 ret
->arm_glue_size
= 0;
373 ret
->bfd_of_glue_owner
= NULL
;
374 ret
->no_pipeline_knowledge
= 0;
375 ret
->byteswap_code
= 0;
377 ret
->plt_header_size
= 16;
378 ret
->plt_entry_size
= 16;
380 ret
->plt_header_size
= 20;
381 ret
->plt_entry_size
= 12;
384 ret
->sym_sec
.abfd
= NULL
;
386 return &ret
->root
.root
;
389 /* Locate the Thumb encoded calling stub for NAME. */
391 static struct elf_link_hash_entry
*
392 find_thumb_glue (struct bfd_link_info
*link_info
,
397 struct elf_link_hash_entry
*hash
;
398 struct elf32_arm_link_hash_table
*hash_table
;
400 /* We need a pointer to the armelf specific hash table. */
401 hash_table
= elf32_arm_hash_table (link_info
);
403 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
404 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
406 BFD_ASSERT (tmp_name
);
408 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
410 hash
= elf_link_hash_lookup
411 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
414 /* xgettext:c-format */
415 (*_bfd_error_handler
) (_("%B: unable to find THUMB glue '%s' for `%s'"),
416 input_bfd
, tmp_name
, name
);
423 /* Locate the ARM encoded calling stub for NAME. */
425 static struct elf_link_hash_entry
*
426 find_arm_glue (struct bfd_link_info
*link_info
,
431 struct elf_link_hash_entry
*myh
;
432 struct elf32_arm_link_hash_table
*hash_table
;
434 /* We need a pointer to the elfarm specific hash table. */
435 hash_table
= elf32_arm_hash_table (link_info
);
437 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
438 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
440 BFD_ASSERT (tmp_name
);
442 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
444 myh
= elf_link_hash_lookup
445 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
448 /* xgettext:c-format */
449 (*_bfd_error_handler
) (_("%B: unable to find ARM glue '%s' for `%s'"),
450 input_bfd
, tmp_name
, name
);
464 .word func @ behave as if you saw a ARM_32 reloc. */
466 #define ARM2THUMB_GLUE_SIZE 12
467 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
468 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
469 static const insn32 a2t3_func_addr_insn
= 0x00000001;
471 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
475 __func_from_thumb: __func_from_thumb:
477 nop ldr r6, __func_addr
479 __func_change_to_arm: bx r6
481 __func_back_to_thumb:
487 #define THUMB2ARM_GLUE_SIZE 8
488 static const insn16 t2a1_bx_pc_insn
= 0x4778;
489 static const insn16 t2a2_noop_insn
= 0x46c0;
490 static const insn32 t2a3_b_insn
= 0xea000000;
492 #ifndef ELFARM_NABI_C_INCLUDED
494 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info
* info
)
498 struct elf32_arm_link_hash_table
* globals
;
500 globals
= elf32_arm_hash_table (info
);
502 BFD_ASSERT (globals
!= NULL
);
504 if (globals
->arm_glue_size
!= 0)
506 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
508 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
509 ARM2THUMB_GLUE_SECTION_NAME
);
511 BFD_ASSERT (s
!= NULL
);
513 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
515 s
->size
= globals
->arm_glue_size
;
519 if (globals
->thumb_glue_size
!= 0)
521 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
523 s
= bfd_get_section_by_name
524 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
526 BFD_ASSERT (s
!= NULL
);
528 foo
= bfd_alloc (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
530 s
->size
= globals
->thumb_glue_size
;
538 record_arm_to_thumb_glue (struct bfd_link_info
* link_info
,
539 struct elf_link_hash_entry
* h
)
541 const char * name
= h
->root
.root
.string
;
544 struct elf_link_hash_entry
* myh
;
545 struct bfd_link_hash_entry
* bh
;
546 struct elf32_arm_link_hash_table
* globals
;
549 globals
= elf32_arm_hash_table (link_info
);
551 BFD_ASSERT (globals
!= NULL
);
552 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
554 s
= bfd_get_section_by_name
555 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
557 BFD_ASSERT (s
!= NULL
);
559 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
561 BFD_ASSERT (tmp_name
);
563 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
565 myh
= elf_link_hash_lookup
566 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
570 /* We've already seen this guy. */
575 /* The only trick here is using hash_table->arm_glue_size as the value.
576 Even though the section isn't allocated yet, this is where we will be
579 val
= globals
->arm_glue_size
+ 1;
580 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
581 tmp_name
, BSF_GLOBAL
, s
, val
,
582 NULL
, TRUE
, FALSE
, &bh
);
586 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
592 record_thumb_to_arm_glue (struct bfd_link_info
*link_info
,
593 struct elf_link_hash_entry
*h
)
595 const char *name
= h
->root
.root
.string
;
598 struct elf_link_hash_entry
*myh
;
599 struct bfd_link_hash_entry
*bh
;
600 struct elf32_arm_link_hash_table
*hash_table
;
604 hash_table
= elf32_arm_hash_table (link_info
);
606 BFD_ASSERT (hash_table
!= NULL
);
607 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
609 s
= bfd_get_section_by_name
610 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
612 BFD_ASSERT (s
!= NULL
);
614 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
615 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
617 BFD_ASSERT (tmp_name
);
619 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
621 myh
= elf_link_hash_lookup
622 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
626 /* We've already seen this guy. */
632 val
= hash_table
->thumb_glue_size
+ 1;
633 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
634 tmp_name
, BSF_GLOBAL
, s
, val
,
635 NULL
, TRUE
, FALSE
, &bh
);
637 /* If we mark it 'Thumb', the disassembler will do a better job. */
638 myh
= (struct elf_link_hash_entry
*) bh
;
639 bind
= ELF_ST_BIND (myh
->type
);
640 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
644 #define CHANGE_TO_ARM "__%s_change_to_arm"
645 #define BACK_FROM_ARM "__%s_back_from_arm"
647 /* Allocate another symbol to mark where we switch to Arm mode. */
648 tmp_name
= bfd_malloc ((bfd_size_type
) strlen (name
)
649 + strlen (CHANGE_TO_ARM
) + 1);
651 BFD_ASSERT (tmp_name
);
653 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
656 val
= hash_table
->thumb_glue_size
+ 4,
657 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
658 tmp_name
, BSF_LOCAL
, s
, val
,
659 NULL
, TRUE
, FALSE
, &bh
);
663 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
668 /* Add the glue sections to ABFD. This function is called from the
669 linker scripts in ld/emultempl/{armelf}.em. */
672 bfd_elf32_arm_add_glue_sections_to_bfd (bfd
*abfd
,
673 struct bfd_link_info
*info
)
678 /* If we are only performing a partial
679 link do not bother adding the glue. */
680 if (info
->relocatable
)
683 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
687 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
688 will prevent elf_link_input_bfd() from processing the contents
690 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
692 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
695 || !bfd_set_section_flags (abfd
, sec
, flags
)
696 || !bfd_set_section_alignment (abfd
, sec
, 2))
699 /* Set the gc mark to prevent the section from being removed by garbage
700 collection, despite the fact that no relocs refer to this section. */
704 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
708 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
709 | SEC_CODE
| SEC_READONLY
;
711 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
714 || !bfd_set_section_flags (abfd
, sec
, flags
)
715 || !bfd_set_section_alignment (abfd
, sec
, 2))
724 /* Select a BFD to be used to hold the sections used by the glue code.
725 This function is called from the linker scripts in ld/emultempl/
729 bfd_elf32_arm_get_bfd_for_interworking (bfd
*abfd
, struct bfd_link_info
*info
)
731 struct elf32_arm_link_hash_table
*globals
;
733 /* If we are only performing a partial link
734 do not bother getting a bfd to hold the glue. */
735 if (info
->relocatable
)
738 globals
= elf32_arm_hash_table (info
);
740 BFD_ASSERT (globals
!= NULL
);
742 if (globals
->bfd_of_glue_owner
!= NULL
)
745 /* Save the bfd for later use. */
746 globals
->bfd_of_glue_owner
= abfd
;
752 bfd_elf32_arm_process_before_allocation (bfd
*abfd
,
753 struct bfd_link_info
*link_info
,
754 int no_pipeline_knowledge
,
757 Elf_Internal_Shdr
*symtab_hdr
;
758 Elf_Internal_Rela
*internal_relocs
= NULL
;
759 Elf_Internal_Rela
*irel
, *irelend
;
760 bfd_byte
*contents
= NULL
;
763 struct elf32_arm_link_hash_table
*globals
;
765 /* If we are only performing a partial link do not bother
766 to construct any glue. */
767 if (link_info
->relocatable
)
770 /* Here we have a bfd that is to be included on the link. We have a hook
771 to do reloc rummaging, before section sizes are nailed down. */
772 globals
= elf32_arm_hash_table (link_info
);
774 BFD_ASSERT (globals
!= NULL
);
775 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
777 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
778 if (byteswap_code
&& !bfd_big_endian (abfd
))
780 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
784 globals
->byteswap_code
= byteswap_code
;
786 /* Rummage around all the relocs and map the glue vectors. */
787 sec
= abfd
->sections
;
792 for (; sec
!= NULL
; sec
= sec
->next
)
794 if (sec
->reloc_count
== 0)
797 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
799 /* Load the relocs. */
801 = _bfd_elf_link_read_relocs (abfd
, sec
, (void *) NULL
,
802 (Elf_Internal_Rela
*) NULL
, FALSE
);
804 if (internal_relocs
== NULL
)
807 irelend
= internal_relocs
+ sec
->reloc_count
;
808 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
811 unsigned long r_index
;
813 struct elf_link_hash_entry
*h
;
815 r_type
= ELF32_R_TYPE (irel
->r_info
);
816 r_index
= ELF32_R_SYM (irel
->r_info
);
818 /* These are the only relocation types we care about. */
819 if ( r_type
!= R_ARM_PC24
820 && r_type
!= R_ARM_THM_PC22
)
823 /* Get the section contents if we haven't done so already. */
824 if (contents
== NULL
)
826 /* Get cached copy if it exists. */
827 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
828 contents
= elf_section_data (sec
)->this_hdr
.contents
;
831 /* Go get them off disk. */
832 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
837 /* If the relocation is not against a symbol it cannot concern us. */
840 /* We don't care about local symbols. */
841 if (r_index
< symtab_hdr
->sh_info
)
844 /* This is an external symbol. */
845 r_index
-= symtab_hdr
->sh_info
;
846 h
= (struct elf_link_hash_entry
*)
847 elf_sym_hashes (abfd
)[r_index
];
849 /* If the relocation is against a static symbol it must be within
850 the current section and so cannot be a cross ARM/Thumb relocation. */
857 /* This one is a call from arm code. We need to look up
858 the target of the call. If it is a thumb target, we
860 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
861 record_arm_to_thumb_glue (link_info
, h
);
865 /* This one is a call from thumb code. We look
866 up the target of the call. If it is not a thumb
867 target, we insert glue. */
868 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
869 record_thumb_to_arm_glue (link_info
, h
);
878 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
882 if (internal_relocs
!= NULL
883 && elf_section_data (sec
)->relocs
!= internal_relocs
)
884 free (internal_relocs
);
885 internal_relocs
= NULL
;
892 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
894 if (internal_relocs
!= NULL
895 && elf_section_data (sec
)->relocs
!= internal_relocs
)
896 free (internal_relocs
);
902 /* The thumb form of a long branch is a bit finicky, because the offset
903 encoding is split over two fields, each in it's own instruction. They
904 can occur in any order. So given a thumb form of long branch, and an
905 offset, insert the offset into the thumb branch and return finished
908 It takes two thumb instructions to encode the target address. Each has
909 11 bits to invest. The upper 11 bits are stored in one (identified by
910 H-0.. see below), the lower 11 bits are stored in the other (identified
913 Combine together and shifted left by 1 (it's a half word address) and
917 H-0, upper address-0 = 000
919 H-1, lower address-0 = 800
921 They can be ordered either way, but the arm tools I've seen always put
922 the lower one first. It probably doesn't matter. krk@cygnus.com
924 XXX: Actually the order does matter. The second instruction (H-1)
925 moves the computed address into the PC, so it must be the second one
926 in the sequence. The problem, however is that whilst little endian code
927 stores the instructions in HI then LOW order, big endian code does the
928 reverse. nickc@cygnus.com. */
930 #define LOW_HI_ORDER 0xF800F000
931 #define HI_LOW_ORDER 0xF000F800
934 insert_thumb_branch (insn32 br_insn
, int rel_off
)
936 unsigned int low_bits
;
937 unsigned int high_bits
;
939 BFD_ASSERT ((rel_off
& 1) != 1);
941 rel_off
>>= 1; /* Half word aligned address. */
942 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
943 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
945 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
946 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
947 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
948 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
950 /* FIXME: abort is probably not the right call. krk@cygnus.com */
951 abort (); /* Error - not a valid branch instruction form. */
956 /* Thumb code calling an ARM function. */
959 elf32_thumb_to_arm_stub (struct bfd_link_info
* info
,
963 asection
* input_section
,
967 bfd_signed_vma addend
,
972 unsigned long int tmp
;
974 struct elf_link_hash_entry
* myh
;
975 struct elf32_arm_link_hash_table
* globals
;
977 myh
= find_thumb_glue (info
, name
, input_bfd
);
981 globals
= elf32_arm_hash_table (info
);
983 BFD_ASSERT (globals
!= NULL
);
984 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
986 my_offset
= myh
->root
.u
.def
.value
;
988 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
989 THUMB2ARM_GLUE_SECTION_NAME
);
991 BFD_ASSERT (s
!= NULL
);
992 BFD_ASSERT (s
->contents
!= NULL
);
993 BFD_ASSERT (s
->output_section
!= NULL
);
995 if ((my_offset
& 0x01) == 0x01)
998 && sym_sec
->owner
!= NULL
999 && !INTERWORK_FLAG (sym_sec
->owner
))
1001 (*_bfd_error_handler
)
1002 (_("%B(%s): warning: interworking not enabled.\n"
1003 " first occurrence: %B: thumb call to arm"),
1004 sym_sec
->owner
, input_bfd
, name
);
1010 myh
->root
.u
.def
.value
= my_offset
;
1012 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
1013 s
->contents
+ my_offset
);
1015 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
1016 s
->contents
+ my_offset
+ 2);
1019 /* Address of destination of the stub. */
1020 ((bfd_signed_vma
) val
)
1022 /* Offset from the start of the current section
1023 to the start of the stubs. */
1025 /* Offset of the start of this stub from the start of the stubs. */
1027 /* Address of the start of the current section. */
1028 + s
->output_section
->vma
)
1029 /* The branch instruction is 4 bytes into the stub. */
1031 /* ARM branches work from the pc of the instruction + 8. */
1034 bfd_put_32 (output_bfd
,
1035 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1036 s
->contents
+ my_offset
+ 4);
1039 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
1041 /* Now go back and fix up the original BL insn to point to here. */
1043 /* Address of where the stub is located. */
1044 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
1045 /* Address of where the BL is located. */
1046 - (input_section
->output_section
->vma
+ input_section
->output_offset
1048 /* Addend in the relocation. */
1050 /* Biassing for PC-relative addressing. */
1053 tmp
= bfd_get_32 (input_bfd
, hit_data
1054 - input_section
->vma
);
1056 bfd_put_32 (output_bfd
,
1057 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1058 hit_data
- input_section
->vma
);
1063 /* Arm code calling a Thumb function. */
1066 elf32_arm_to_thumb_stub (struct bfd_link_info
* info
,
1070 asection
* input_section
,
1071 bfd_byte
* hit_data
,
1074 bfd_signed_vma addend
,
1077 unsigned long int tmp
;
1080 long int ret_offset
;
1081 struct elf_link_hash_entry
* myh
;
1082 struct elf32_arm_link_hash_table
* globals
;
1084 myh
= find_arm_glue (info
, name
, input_bfd
);
1088 globals
= elf32_arm_hash_table (info
);
1090 BFD_ASSERT (globals
!= NULL
);
1091 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1093 my_offset
= myh
->root
.u
.def
.value
;
1094 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1095 ARM2THUMB_GLUE_SECTION_NAME
);
1096 BFD_ASSERT (s
!= NULL
);
1097 BFD_ASSERT (s
->contents
!= NULL
);
1098 BFD_ASSERT (s
->output_section
!= NULL
);
1100 if ((my_offset
& 0x01) == 0x01)
1103 && sym_sec
->owner
!= NULL
1104 && !INTERWORK_FLAG (sym_sec
->owner
))
1106 (*_bfd_error_handler
)
1107 (_("%B(%s): warning: interworking not enabled.\n"
1108 " first occurrence: %B: arm call to thumb"),
1109 sym_sec
->owner
, input_bfd
, name
);
1113 myh
->root
.u
.def
.value
= my_offset
;
1115 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1116 s
->contents
+ my_offset
);
1118 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1119 s
->contents
+ my_offset
+ 4);
1121 /* It's a thumb address. Add the low order bit. */
1122 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1123 s
->contents
+ my_offset
+ 8);
1126 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1128 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1129 tmp
= tmp
& 0xFF000000;
1131 /* Somehow these are both 4 too far, so subtract 8. */
1132 ret_offset
= (s
->output_offset
1134 + s
->output_section
->vma
1135 - (input_section
->output_offset
1136 + input_section
->output_section
->vma
1140 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1142 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1147 /* Perform a relocation as part of a final link. */
1149 static bfd_reloc_status_type
1150 elf32_arm_final_link_relocate (reloc_howto_type
* howto
,
1153 asection
* input_section
,
1154 bfd_byte
* contents
,
1155 Elf_Internal_Rela
* rel
,
1157 struct bfd_link_info
* info
,
1159 const char * sym_name
,
1161 struct elf_link_hash_entry
* h
)
1163 unsigned long r_type
= howto
->type
;
1164 unsigned long r_symndx
;
1165 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1166 bfd
* dynobj
= NULL
;
1167 Elf_Internal_Shdr
* symtab_hdr
;
1168 struct elf_link_hash_entry
** sym_hashes
;
1169 bfd_vma
* local_got_offsets
;
1170 asection
* sgot
= NULL
;
1171 asection
* splt
= NULL
;
1172 asection
* sreloc
= NULL
;
1174 bfd_signed_vma signed_addend
;
1175 struct elf32_arm_link_hash_table
* globals
;
1177 /* If the start address has been set, then set the EF_ARM_HASENTRY
1178 flag. Setting this more than once is redundant, but the cost is
1179 not too high, and it keeps the code simple.
1181 The test is done here, rather than somewhere else, because the
1182 start address is only set just before the final link commences.
1184 Note - if the user deliberately sets a start address of 0, the
1185 flag will not be set. */
1186 if (bfd_get_start_address (output_bfd
) != 0)
1187 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1189 globals
= elf32_arm_hash_table (info
);
1191 dynobj
= elf_hash_table (info
)->dynobj
;
1194 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1195 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1197 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1198 sym_hashes
= elf_sym_hashes (input_bfd
);
1199 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1200 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1203 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1205 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1208 signed_addend
&= ~ howto
->src_mask
;
1209 signed_addend
|= addend
;
1212 signed_addend
= addend
;
1214 addend
= signed_addend
= rel
->r_addend
;
1220 return bfd_reloc_ok
;
1229 /* r_symndx will be zero only for relocs against symbols
1230 from removed linkonce sections, or sections discarded by
1233 return bfd_reloc_ok
;
1235 /* Handle relocations which should use the PLT entry. ABS32/REL32
1236 will use the symbol's value, which may point to a PLT entry, but we
1237 don't need to handle that here. If we created a PLT entry, all
1238 branches in this object should go to it. */
1239 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
1242 && h
->plt
.offset
!= (bfd_vma
) -1)
1244 /* If we've created a .plt section, and assigned a PLT entry to
1245 this function, it should not be known to bind locally. If
1246 it were, we would have cleared the PLT entry. */
1247 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
1249 value
= (splt
->output_section
->vma
1250 + splt
->output_offset
1252 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1253 contents
, rel
->r_offset
, value
,
1257 /* When generating a shared object, these relocations are copied
1258 into the output file to be resolved at run time. */
1260 && (input_section
->flags
& SEC_ALLOC
)
1261 && (r_type
!= R_ARM_REL32
1262 || !SYMBOL_CALLS_LOCAL (info
, h
))
1264 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1265 || h
->root
.type
!= bfd_link_hash_undefweak
)
1266 && r_type
!= R_ARM_PC24
1267 && r_type
!= R_ARM_PLT32
)
1269 Elf_Internal_Rela outrel
;
1271 bfd_boolean skip
, relocate
;
1277 name
= (bfd_elf_string_from_elf_section
1279 elf_elfheader (input_bfd
)->e_shstrndx
,
1280 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1282 return bfd_reloc_notsupported
;
1284 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1285 && strcmp (bfd_get_section_name (input_bfd
,
1289 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1290 BFD_ASSERT (sreloc
!= NULL
);
1297 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1299 if (outrel
.r_offset
== (bfd_vma
) -1)
1301 else if (outrel
.r_offset
== (bfd_vma
) -2)
1302 skip
= TRUE
, relocate
= TRUE
;
1303 outrel
.r_offset
+= (input_section
->output_section
->vma
1304 + input_section
->output_offset
);
1307 memset (&outrel
, 0, sizeof outrel
);
1312 || (h
->elf_link_hash_flags
1313 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1314 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1317 /* This symbol is local, or marked to become local. */
1319 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1322 loc
= sreloc
->contents
;
1323 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1324 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1326 /* If this reloc is against an external symbol, we do not want to
1327 fiddle with the addend. Otherwise, we need to include the symbol
1328 value so that it becomes an addend for the dynamic reloc. */
1330 return bfd_reloc_ok
;
1332 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1333 contents
, rel
->r_offset
, value
,
1336 else switch (r_type
)
1339 case R_ARM_XPC25
: /* Arm BLX instruction. */
1341 case R_ARM_PC24
: /* Arm B/BL instruction */
1344 if (r_type
== R_ARM_XPC25
)
1346 /* Check for Arm calling Arm function. */
1347 /* FIXME: Should we translate the instruction into a BL
1348 instruction instead ? */
1349 if (sym_flags
!= STT_ARM_TFUNC
)
1350 (*_bfd_error_handler
)
1351 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
1353 h
? h
->root
.root
.string
: "(local)");
1358 /* Check for Arm calling Thumb function. */
1359 if (sym_flags
== STT_ARM_TFUNC
)
1361 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
,
1362 output_bfd
, input_section
,
1363 hit_data
, sym_sec
, rel
->r_offset
,
1364 signed_addend
, value
);
1365 return bfd_reloc_ok
;
1369 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1370 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1372 /* The old way of doing things. Trearing the addend as a
1373 byte sized field and adding in the pipeline offset. */
1374 value
-= (input_section
->output_section
->vma
1375 + input_section
->output_offset
);
1376 value
-= rel
->r_offset
;
1379 if (! globals
->no_pipeline_knowledge
)
1384 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1386 S is the address of the symbol in the relocation.
1387 P is address of the instruction being relocated.
1388 A is the addend (extracted from the instruction) in bytes.
1390 S is held in 'value'.
1391 P is the base address of the section containing the
1392 instruction plus the offset of the reloc into that
1394 (input_section->output_section->vma +
1395 input_section->output_offset +
1397 A is the addend, converted into bytes, ie:
1400 Note: None of these operations have knowledge of the pipeline
1401 size of the processor, thus it is up to the assembler to
1402 encode this information into the addend. */
1403 value
-= (input_section
->output_section
->vma
1404 + input_section
->output_offset
);
1405 value
-= rel
->r_offset
;
1406 value
+= (signed_addend
<< howto
->size
);
1408 /* Previous versions of this code also used to add in the
1409 pipeline offset here. This is wrong because the linker is
1410 not supposed to know about such things, and one day it might
1411 change. In order to support old binaries that need the old
1412 behaviour however, so we attempt to detect which ABI was
1413 used to create the reloc. */
1414 if (! globals
->no_pipeline_knowledge
)
1416 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1418 i_ehdrp
= elf_elfheader (input_bfd
);
1420 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1425 signed_addend
= value
;
1426 signed_addend
>>= howto
->rightshift
;
1428 /* It is not an error for an undefined weak reference to be
1429 out of range. Any program that branches to such a symbol
1430 is going to crash anyway, so there is no point worrying
1431 about getting the destination exactly right. */
1432 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1434 /* Perform a signed range check. */
1435 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1436 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1437 return bfd_reloc_overflow
;
1441 /* If necessary set the H bit in the BLX instruction. */
1442 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1443 value
= (signed_addend
& howto
->dst_mask
)
1444 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1448 value
= (signed_addend
& howto
->dst_mask
)
1449 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1454 if (sym_flags
== STT_ARM_TFUNC
)
1459 value
-= (input_section
->output_section
->vma
1460 + input_section
->output_offset
+ rel
->r_offset
);
1465 bfd_put_32 (input_bfd
, value
, hit_data
);
1466 return bfd_reloc_ok
;
1470 if ((long) value
> 0x7f || (long) value
< -0x80)
1471 return bfd_reloc_overflow
;
1473 bfd_put_8 (input_bfd
, value
, hit_data
);
1474 return bfd_reloc_ok
;
1479 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1480 return bfd_reloc_overflow
;
1482 bfd_put_16 (input_bfd
, value
, hit_data
);
1483 return bfd_reloc_ok
;
1486 /* Support ldr and str instruction for the arm */
1487 /* Also thumb b (unconditional branch). ??? Really? */
1490 if ((long) value
> 0x7ff || (long) value
< -0x800)
1491 return bfd_reloc_overflow
;
1493 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1494 bfd_put_32 (input_bfd
, value
, hit_data
);
1495 return bfd_reloc_ok
;
1497 case R_ARM_THM_ABS5
:
1498 /* Support ldr and str instructions for the thumb. */
1500 /* Need to refetch addend. */
1501 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1502 /* ??? Need to determine shift amount from operand size. */
1503 addend
>>= howto
->rightshift
;
1507 /* ??? Isn't value unsigned? */
1508 if ((long) value
> 0x1f || (long) value
< -0x10)
1509 return bfd_reloc_overflow
;
1511 /* ??? Value needs to be properly shifted into place first. */
1512 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1513 bfd_put_16 (input_bfd
, value
, hit_data
);
1514 return bfd_reloc_ok
;
1517 case R_ARM_THM_XPC22
:
1519 case R_ARM_THM_PC22
:
1520 /* Thumb BL (branch long instruction). */
1523 bfd_boolean overflow
= FALSE
;
1524 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1525 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1526 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1527 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1529 bfd_signed_vma signed_check
;
1532 /* Need to refetch the addend and squish the two 11 bit pieces
1535 bfd_vma upper
= upper_insn
& 0x7ff;
1536 bfd_vma lower
= lower_insn
& 0x7ff;
1537 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1538 addend
= (upper
<< 12) | (lower
<< 1);
1539 signed_addend
= addend
;
1543 if (r_type
== R_ARM_THM_XPC22
)
1545 /* Check for Thumb to Thumb call. */
1546 /* FIXME: Should we translate the instruction into a BL
1547 instruction instead ? */
1548 if (sym_flags
== STT_ARM_TFUNC
)
1549 (*_bfd_error_handler
)
1550 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
1552 h
? h
->root
.root
.string
: "(local)");
1557 /* If it is not a call to Thumb, assume call to Arm.
1558 If it is a call relative to a section name, then it is not a
1559 function call at all, but rather a long jump. */
1560 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1562 if (elf32_thumb_to_arm_stub
1563 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1564 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1565 return bfd_reloc_ok
;
1567 return bfd_reloc_dangerous
;
1571 relocation
= value
+ signed_addend
;
1573 relocation
-= (input_section
->output_section
->vma
1574 + input_section
->output_offset
1577 if (! globals
->no_pipeline_knowledge
)
1579 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1581 i_ehdrp
= elf_elfheader (input_bfd
);
1583 /* Previous versions of this code also used to add in the pipline
1584 offset here. This is wrong because the linker is not supposed
1585 to know about such things, and one day it might change. In order
1586 to support old binaries that need the old behaviour however, so
1587 we attempt to detect which ABI was used to create the reloc. */
1588 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1589 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1590 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1594 check
= relocation
>> howto
->rightshift
;
1596 /* If this is a signed value, the rightshift just dropped
1597 leading 1 bits (assuming twos complement). */
1598 if ((bfd_signed_vma
) relocation
>= 0)
1599 signed_check
= check
;
1601 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1603 /* Assumes two's complement. */
1604 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1608 if (r_type
== R_ARM_THM_XPC22
1609 && ((lower_insn
& 0x1800) == 0x0800))
1610 /* For a BLX instruction, make sure that the relocation is rounded up
1611 to a word boundary. This follows the semantics of the instruction
1612 which specifies that bit 1 of the target address will come from bit
1613 1 of the base address. */
1614 relocation
= (relocation
+ 2) & ~ 3;
1616 /* Put RELOCATION back into the insn. */
1617 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1618 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1620 /* Put the relocated value back in the object file: */
1621 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1622 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1624 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1628 case R_ARM_THM_PC11
:
1629 /* Thumb B (branch) instruction). */
1631 bfd_signed_vma relocation
;
1632 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1633 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1634 bfd_signed_vma signed_check
;
1637 /* Need to refetch addend. */
1638 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1639 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1642 signed_addend
&= ~ howto
->src_mask
;
1643 signed_addend
|= addend
;
1646 signed_addend
= addend
;
1647 /* The value in the insn has been right shifted. We need to
1648 undo this, so that we can perform the address calculation
1649 in terms of bytes. */
1650 signed_addend
<<= howto
->rightshift
;
1652 relocation
= value
+ signed_addend
;
1654 relocation
-= (input_section
->output_section
->vma
1655 + input_section
->output_offset
1658 relocation
>>= howto
->rightshift
;
1659 signed_check
= relocation
;
1660 relocation
&= howto
->dst_mask
;
1661 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1663 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1665 /* Assumes two's complement. */
1666 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1667 return bfd_reloc_overflow
;
1669 return bfd_reloc_ok
;
1673 case R_ARM_ALU_PCREL7_0
:
1674 case R_ARM_ALU_PCREL15_8
:
1675 case R_ARM_ALU_PCREL23_15
:
1680 insn
= bfd_get_32 (input_bfd
, hit_data
);
1682 /* Extract the addend. */
1683 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
1684 signed_addend
= addend
;
1686 relocation
= value
+ signed_addend
;
1688 relocation
-= (input_section
->output_section
->vma
1689 + input_section
->output_offset
1691 insn
= (insn
& ~0xfff)
1692 | ((howto
->bitpos
<< 7) & 0xf00)
1693 | ((relocation
>> howto
->bitpos
) & 0xff);
1694 bfd_put_32 (input_bfd
, value
, hit_data
);
1696 return bfd_reloc_ok
;
1699 case R_ARM_GNU_VTINHERIT
:
1700 case R_ARM_GNU_VTENTRY
:
1701 return bfd_reloc_ok
;
1704 return bfd_reloc_notsupported
;
1706 case R_ARM_GLOB_DAT
:
1707 return bfd_reloc_notsupported
;
1709 case R_ARM_JUMP_SLOT
:
1710 return bfd_reloc_notsupported
;
1712 case R_ARM_RELATIVE
:
1713 return bfd_reloc_notsupported
;
1716 /* Relocation is relative to the start of the
1717 global offset table. */
1719 BFD_ASSERT (sgot
!= NULL
);
1721 return bfd_reloc_notsupported
;
1723 /* If we are addressing a Thumb function, we need to adjust the
1724 address by one, so that attempts to call the function pointer will
1725 correctly interpret it as Thumb code. */
1726 if (sym_flags
== STT_ARM_TFUNC
)
1729 /* Note that sgot->output_offset is not involved in this
1730 calculation. We always want the start of .got. If we
1731 define _GLOBAL_OFFSET_TABLE in a different way, as is
1732 permitted by the ABI, we might have to change this
1734 value
-= sgot
->output_section
->vma
;
1735 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1736 contents
, rel
->r_offset
, value
,
1740 /* Use global offset table as symbol value. */
1741 BFD_ASSERT (sgot
!= NULL
);
1744 return bfd_reloc_notsupported
;
1746 value
= sgot
->output_section
->vma
;
1747 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1748 contents
, rel
->r_offset
, value
,
1752 /* Relocation is to the entry for this symbol in the
1753 global offset table. */
1755 return bfd_reloc_notsupported
;
1762 off
= h
->got
.offset
;
1763 BFD_ASSERT (off
!= (bfd_vma
) -1);
1764 dyn
= globals
->root
.dynamic_sections_created
;
1766 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1768 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1769 || (ELF_ST_VISIBILITY (h
->other
)
1770 && h
->root
.type
== bfd_link_hash_undefweak
))
1772 /* This is actually a static link, or it is a -Bsymbolic link
1773 and the symbol is defined locally. We must initialize this
1774 entry in the global offset table. Since the offset must
1775 always be a multiple of 4, we use the least significant bit
1776 to record whether we have initialized it already.
1778 When doing a dynamic link, we create a .rel.got relocation
1779 entry to initialize the value. This is done in the
1780 finish_dynamic_symbol routine. */
1785 /* If we are addressing a Thumb function, we need to
1786 adjust the address by one, so that attempts to
1787 call the function pointer will correctly
1788 interpret it as Thumb code. */
1789 if (sym_flags
== STT_ARM_TFUNC
)
1792 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1797 value
= sgot
->output_offset
+ off
;
1803 BFD_ASSERT (local_got_offsets
!= NULL
&&
1804 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1806 off
= local_got_offsets
[r_symndx
];
1808 /* The offset must always be a multiple of 4. We use the
1809 least significant bit to record whether we have already
1810 generated the necessary reloc. */
1815 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1820 Elf_Internal_Rela outrel
;
1823 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1824 BFD_ASSERT (srelgot
!= NULL
);
1826 outrel
.r_offset
= (sgot
->output_section
->vma
1827 + sgot
->output_offset
1829 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1830 loc
= srelgot
->contents
;
1831 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1832 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1835 local_got_offsets
[r_symndx
] |= 1;
1838 value
= sgot
->output_offset
+ off
;
1841 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1842 contents
, rel
->r_offset
, value
,
1846 return bfd_reloc_notsupported
;
1848 case R_ARM_AMP_VCALL9
:
1849 return bfd_reloc_notsupported
;
1851 case R_ARM_RSBREL32
:
1852 return bfd_reloc_notsupported
;
1854 case R_ARM_THM_RPC22
:
1855 return bfd_reloc_notsupported
;
1858 return bfd_reloc_notsupported
;
1861 return bfd_reloc_notsupported
;
1864 return bfd_reloc_notsupported
;
1867 return bfd_reloc_notsupported
;
1870 return bfd_reloc_notsupported
;
1875 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1877 arm_add_to_rel (bfd
* abfd
,
1879 reloc_howto_type
* howto
,
1880 bfd_signed_vma increment
)
1882 bfd_signed_vma addend
;
1884 if (howto
->type
== R_ARM_THM_PC22
)
1886 int upper_insn
, lower_insn
;
1889 upper_insn
= bfd_get_16 (abfd
, address
);
1890 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1891 upper
= upper_insn
& 0x7ff;
1892 lower
= lower_insn
& 0x7ff;
1894 addend
= (upper
<< 12) | (lower
<< 1);
1895 addend
+= increment
;
1898 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
1899 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
1901 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
1902 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
1908 contents
= bfd_get_32 (abfd
, address
);
1910 /* Get the (signed) value from the instruction. */
1911 addend
= contents
& howto
->src_mask
;
1912 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1914 bfd_signed_vma mask
;
1917 mask
&= ~ howto
->src_mask
;
1921 /* Add in the increment, (which is a byte value). */
1922 switch (howto
->type
)
1925 addend
+= increment
;
1929 addend
<<= howto
->size
;
1930 addend
+= increment
;
1932 /* Should we check for overflow here ? */
1934 /* Drop any undesired bits. */
1935 addend
>>= howto
->rightshift
;
1939 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1941 bfd_put_32 (abfd
, contents
, address
);
1944 #endif /* USE_REL */
1946 /* Relocate an ARM ELF section. */
1948 elf32_arm_relocate_section (bfd
* output_bfd
,
1949 struct bfd_link_info
* info
,
1951 asection
* input_section
,
1952 bfd_byte
* contents
,
1953 Elf_Internal_Rela
* relocs
,
1954 Elf_Internal_Sym
* local_syms
,
1955 asection
** local_sections
)
1957 Elf_Internal_Shdr
*symtab_hdr
;
1958 struct elf_link_hash_entry
**sym_hashes
;
1959 Elf_Internal_Rela
*rel
;
1960 Elf_Internal_Rela
*relend
;
1964 if (info
->relocatable
)
1968 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1969 sym_hashes
= elf_sym_hashes (input_bfd
);
1972 relend
= relocs
+ input_section
->reloc_count
;
1973 for (; rel
< relend
; rel
++)
1976 reloc_howto_type
* howto
;
1977 unsigned long r_symndx
;
1978 Elf_Internal_Sym
* sym
;
1980 struct elf_link_hash_entry
* h
;
1982 bfd_reloc_status_type r
;
1985 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1986 r_type
= ELF32_R_TYPE (rel
->r_info
);
1988 if ( r_type
== R_ARM_GNU_VTENTRY
1989 || r_type
== R_ARM_GNU_VTINHERIT
)
1992 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
1993 howto
= bfd_reloc
.howto
;
1996 if (info
->relocatable
)
1998 /* This is a relocatable link. We don't have to change
1999 anything, unless the reloc is against a section symbol,
2000 in which case we have to adjust according to where the
2001 section symbol winds up in the output section. */
2002 if (r_symndx
< symtab_hdr
->sh_info
)
2004 sym
= local_syms
+ r_symndx
;
2005 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2007 sec
= local_sections
[r_symndx
];
2008 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2010 (bfd_signed_vma
) (sec
->output_offset
2019 /* This is a final link. */
2024 if (r_symndx
< symtab_hdr
->sh_info
)
2026 sym
= local_syms
+ r_symndx
;
2027 sec
= local_sections
[r_symndx
];
2029 relocation
= (sec
->output_section
->vma
2030 + sec
->output_offset
2032 if ((sec
->flags
& SEC_MERGE
)
2033 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2036 bfd_vma addend
, value
;
2038 if (howto
->rightshift
)
2040 (*_bfd_error_handler
)
2041 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
2042 input_bfd
, input_section
,
2043 (long) rel
->r_offset
, howto
->name
);
2047 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2049 /* Get the (signed) value from the instruction. */
2050 addend
= value
& howto
->src_mask
;
2051 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2053 bfd_signed_vma mask
;
2056 mask
&= ~ howto
->src_mask
;
2061 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2063 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2064 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2065 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2068 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2074 bfd_boolean unresolved_reloc
;
2076 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2077 r_symndx
, symtab_hdr
, sym_hashes
,
2079 unresolved_reloc
, warned
);
2081 if (unresolved_reloc
|| relocation
!= 0)
2083 /* In these cases, we don't need the relocation value.
2084 We check specially because in some obscure cases
2085 sec->output_section will be NULL. */
2090 case R_ARM_THM_PC22
:
2095 (!info
->symbolic
&& h
->dynindx
!= -1)
2096 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2098 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2099 && ((input_section
->flags
& SEC_ALLOC
) != 0
2100 /* DWARF will emit R_ARM_ABS32 relocations in its
2101 sections against symbols defined externally
2102 in shared libraries. We can't do anything
2104 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2105 && (h
->elf_link_hash_flags
2106 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2116 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
2117 (elf_hash_table (info
)->dynamic_sections_created
,
2120 || (!info
->symbolic
&& h
->dynindx
!= -1)
2121 || (h
->elf_link_hash_flags
2122 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2127 if (unresolved_reloc
)
2129 (_("%B(%A): warning: unresolvable relocation %d against symbol `%s'"),
2130 input_bfd
, input_section
,
2132 h
->root
.root
.string
);
2139 name
= h
->root
.root
.string
;
2142 name
= (bfd_elf_string_from_elf_section
2143 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2144 if (name
== NULL
|| *name
== '\0')
2145 name
= bfd_section_name (input_bfd
, sec
);
2148 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2149 input_section
, contents
, rel
,
2150 relocation
, info
, sec
, name
,
2151 (h
? ELF_ST_TYPE (h
->type
) :
2152 ELF_ST_TYPE (sym
->st_info
)), h
);
2154 if (r
!= bfd_reloc_ok
)
2156 const char * msg
= (const char *) 0;
2160 case bfd_reloc_overflow
:
2161 /* If the overflowing reloc was to an undefined symbol,
2162 we have already printed one error message and there
2163 is no point complaining again. */
2165 h
->root
.type
!= bfd_link_hash_undefined
)
2166 && (!((*info
->callbacks
->reloc_overflow
)
2167 (info
, name
, howto
->name
, (bfd_vma
) 0,
2168 input_bfd
, input_section
, rel
->r_offset
))))
2172 case bfd_reloc_undefined
:
2173 if (!((*info
->callbacks
->undefined_symbol
)
2174 (info
, name
, input_bfd
, input_section
,
2175 rel
->r_offset
, TRUE
)))
2179 case bfd_reloc_outofrange
:
2180 msg
= _("internal error: out of range error");
2183 case bfd_reloc_notsupported
:
2184 msg
= _("internal error: unsupported relocation error");
2187 case bfd_reloc_dangerous
:
2188 msg
= _("internal error: dangerous error");
2192 msg
= _("internal error: unknown error");
2196 if (!((*info
->callbacks
->warning
)
2197 (info
, msg
, name
, input_bfd
, input_section
,
2208 /* Set the right machine number. */
2211 elf32_arm_object_p (bfd
*abfd
)
2215 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2217 if (mach
!= bfd_mach_arm_unknown
)
2218 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2220 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
2221 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
2224 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2229 /* Function to keep ARM specific flags in the ELF header. */
2231 elf32_arm_set_private_flags (bfd
*abfd
, flagword flags
)
2233 if (elf_flags_init (abfd
)
2234 && elf_elfheader (abfd
)->e_flags
!= flags
)
2236 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2238 if (flags
& EF_ARM_INTERWORK
)
2239 (*_bfd_error_handler
)
2240 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
2244 (_("Warning: Clearing the interworking flag of %B due to outside request"),
2250 elf_elfheader (abfd
)->e_flags
= flags
;
2251 elf_flags_init (abfd
) = TRUE
;
2257 /* Copy backend specific data from one object module to another. */
2260 elf32_arm_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2265 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2266 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2269 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2270 out_flags
= elf_elfheader (obfd
)->e_flags
;
2272 if (elf_flags_init (obfd
)
2273 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2274 && in_flags
!= out_flags
)
2276 /* Cannot mix APCS26 and APCS32 code. */
2277 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2280 /* Cannot mix float APCS and non-float APCS code. */
2281 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2284 /* If the src and dest have different interworking flags
2285 then turn off the interworking bit. */
2286 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2288 if (out_flags
& EF_ARM_INTERWORK
)
2290 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
2293 in_flags
&= ~EF_ARM_INTERWORK
;
2296 /* Likewise for PIC, though don't warn for this case. */
2297 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2298 in_flags
&= ~EF_ARM_PIC
;
2301 elf_elfheader (obfd
)->e_flags
= in_flags
;
2302 elf_flags_init (obfd
) = TRUE
;
2307 /* Merge backend specific data from an object file to the output
2308 object file when linking. */
2311 elf32_arm_merge_private_bfd_data (bfd
* ibfd
, bfd
* obfd
)
2315 bfd_boolean flags_compatible
= TRUE
;
2318 /* Check if we have the same endianess. */
2319 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2322 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2323 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2326 /* The input BFD must have had its flags initialised. */
2327 /* The following seems bogus to me -- The flags are initialized in
2328 the assembler but I don't think an elf_flags_init field is
2329 written into the object. */
2330 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2332 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2333 out_flags
= elf_elfheader (obfd
)->e_flags
;
2335 if (!elf_flags_init (obfd
))
2337 /* If the input is the default architecture and had the default
2338 flags then do not bother setting the flags for the output
2339 architecture, instead allow future merges to do this. If no
2340 future merges ever set these flags then they will retain their
2341 uninitialised values, which surprise surprise, correspond
2342 to the default values. */
2343 if (bfd_get_arch_info (ibfd
)->the_default
2344 && elf_elfheader (ibfd
)->e_flags
== 0)
2347 elf_flags_init (obfd
) = TRUE
;
2348 elf_elfheader (obfd
)->e_flags
= in_flags
;
2350 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2351 && bfd_get_arch_info (obfd
)->the_default
)
2352 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2357 /* Determine what should happen if the input ARM architecture
2358 does not match the output ARM architecture. */
2359 if (! bfd_arm_merge_machines (ibfd
, obfd
))
2362 /* Identical flags must be compatible. */
2363 if (in_flags
== out_flags
)
2366 /* Check to see if the input BFD actually contains any sections. If
2367 not, its flags may not have been initialised either, but it
2368 cannot actually cause any incompatibility. Do not short-circuit
2369 dynamic objects; their section list may be emptied by
2370 elf_link_add_object_symbols.
2372 Also check to see if there are no code sections in the input.
2373 In this case there is no need to check for code specific flags.
2374 XXX - do we need to worry about floating-point format compatability
2375 in data sections ? */
2376 if (!(ibfd
->flags
& DYNAMIC
))
2378 bfd_boolean null_input_bfd
= TRUE
;
2379 bfd_boolean only_data_sections
= TRUE
;
2381 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2383 /* Ignore synthetic glue sections. */
2384 if (strcmp (sec
->name
, ".glue_7")
2385 && strcmp (sec
->name
, ".glue_7t"))
2387 if ((bfd_get_section_flags (ibfd
, sec
)
2388 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2389 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2390 only_data_sections
= FALSE
;
2392 null_input_bfd
= FALSE
;
2397 if (null_input_bfd
|| only_data_sections
)
2401 /* Complain about various flag mismatches. */
2402 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2405 (_("ERROR: %B is compiled for EABI version %d, whereas %B is compiled for version %d"),
2407 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2408 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2412 /* Not sure what needs to be checked for EABI versions >= 1. */
2413 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2415 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2418 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
2420 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2421 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2422 flags_compatible
= FALSE
;
2425 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2427 if (in_flags
& EF_ARM_APCS_FLOAT
)
2429 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
2433 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
2436 flags_compatible
= FALSE
;
2439 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2441 if (in_flags
& EF_ARM_VFP_FLOAT
)
2443 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
2447 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
2450 flags_compatible
= FALSE
;
2453 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
2455 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
2457 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
2461 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
2464 flags_compatible
= FALSE
;
2467 #ifdef EF_ARM_SOFT_FLOAT
2468 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2470 /* We can allow interworking between code that is VFP format
2471 layout, and uses either soft float or integer regs for
2472 passing floating point arguments and results. We already
2473 know that the APCS_FLOAT flags match; similarly for VFP
2475 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2476 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2478 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2480 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
2484 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
2487 flags_compatible
= FALSE
;
2492 /* Interworking mismatch is only a warning. */
2493 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2495 if (in_flags
& EF_ARM_INTERWORK
)
2498 (_("Warning: %B supports interworking, whereas %B does not"),
2504 (_("Warning: %B does not support interworking, whereas %B does"),
2510 return flags_compatible
;
2513 /* Display the flags field. */
2516 elf32_arm_print_private_bfd_data (bfd
*abfd
, void * ptr
)
2518 FILE * file
= (FILE *) ptr
;
2519 unsigned long flags
;
2521 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2523 /* Print normal ELF private data. */
2524 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2526 flags
= elf_elfheader (abfd
)->e_flags
;
2527 /* Ignore init flag - it may not be set, despite the flags field
2528 containing valid data. */
2530 /* xgettext:c-format */
2531 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2533 switch (EF_ARM_EABI_VERSION (flags
))
2535 case EF_ARM_EABI_UNKNOWN
:
2536 /* The following flag bits are GNU extensions and not part of the
2537 official ARM ELF extended ABI. Hence they are only decoded if
2538 the EABI version is not set. */
2539 if (flags
& EF_ARM_INTERWORK
)
2540 fprintf (file
, _(" [interworking enabled]"));
2542 if (flags
& EF_ARM_APCS_26
)
2543 fprintf (file
, " [APCS-26]");
2545 fprintf (file
, " [APCS-32]");
2547 if (flags
& EF_ARM_VFP_FLOAT
)
2548 fprintf (file
, _(" [VFP float format]"));
2549 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
2550 fprintf (file
, _(" [Maverick float format]"));
2552 fprintf (file
, _(" [FPA float format]"));
2554 if (flags
& EF_ARM_APCS_FLOAT
)
2555 fprintf (file
, _(" [floats passed in float registers]"));
2557 if (flags
& EF_ARM_PIC
)
2558 fprintf (file
, _(" [position independent]"));
2560 if (flags
& EF_ARM_NEW_ABI
)
2561 fprintf (file
, _(" [new ABI]"));
2563 if (flags
& EF_ARM_OLD_ABI
)
2564 fprintf (file
, _(" [old ABI]"));
2566 if (flags
& EF_ARM_SOFT_FLOAT
)
2567 fprintf (file
, _(" [software FP]"));
2569 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2570 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2571 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
2572 | EF_ARM_MAVERICK_FLOAT
);
2575 case EF_ARM_EABI_VER1
:
2576 fprintf (file
, _(" [Version1 EABI]"));
2578 if (flags
& EF_ARM_SYMSARESORTED
)
2579 fprintf (file
, _(" [sorted symbol table]"));
2581 fprintf (file
, _(" [unsorted symbol table]"));
2583 flags
&= ~ EF_ARM_SYMSARESORTED
;
2586 case EF_ARM_EABI_VER2
:
2587 fprintf (file
, _(" [Version2 EABI]"));
2589 if (flags
& EF_ARM_SYMSARESORTED
)
2590 fprintf (file
, _(" [sorted symbol table]"));
2592 fprintf (file
, _(" [unsorted symbol table]"));
2594 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2595 fprintf (file
, _(" [dynamic symbols use segment index]"));
2597 if (flags
& EF_ARM_MAPSYMSFIRST
)
2598 fprintf (file
, _(" [mapping symbols precede others]"));
2600 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2601 | EF_ARM_MAPSYMSFIRST
);
2604 case EF_ARM_EABI_VER3
:
2605 fprintf (file
, _(" [Version3 EABI]"));
2607 if (flags
& EF_ARM_BE8
)
2608 fprintf (file
, _(" [BE8]"));
2610 if (flags
& EF_ARM_LE8
)
2611 fprintf (file
, _(" [LE8]"));
2613 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
2617 fprintf (file
, _(" <EABI version unrecognised>"));
2621 flags
&= ~ EF_ARM_EABIMASK
;
2623 if (flags
& EF_ARM_RELEXEC
)
2624 fprintf (file
, _(" [relocatable executable]"));
2626 if (flags
& EF_ARM_HASENTRY
)
2627 fprintf (file
, _(" [has entry point]"));
2629 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2632 fprintf (file
, _("<Unrecognised flag bits set>"));
2640 elf32_arm_get_symbol_type (Elf_Internal_Sym
* elf_sym
, int type
)
2642 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2645 return ELF_ST_TYPE (elf_sym
->st_info
);
2648 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2649 This allows us to distinguish between data used by Thumb instructions
2650 and non-data (which is probably code) inside Thumb regions of an
2652 if (type
!= STT_OBJECT
)
2653 return ELF_ST_TYPE (elf_sym
->st_info
);
2664 elf32_arm_gc_mark_hook (asection
* sec
,
2665 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
2666 Elf_Internal_Rela
* rel
,
2667 struct elf_link_hash_entry
* h
,
2668 Elf_Internal_Sym
* sym
)
2672 switch (ELF32_R_TYPE (rel
->r_info
))
2674 case R_ARM_GNU_VTINHERIT
:
2675 case R_ARM_GNU_VTENTRY
:
2679 switch (h
->root
.type
)
2681 case bfd_link_hash_defined
:
2682 case bfd_link_hash_defweak
:
2683 return h
->root
.u
.def
.section
;
2685 case bfd_link_hash_common
:
2686 return h
->root
.u
.c
.p
->section
;
2694 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2699 /* Update the got entry reference counts for the section being removed. */
2702 elf32_arm_gc_sweep_hook (bfd
* abfd ATTRIBUTE_UNUSED
,
2703 struct bfd_link_info
* info ATTRIBUTE_UNUSED
,
2704 asection
* sec ATTRIBUTE_UNUSED
,
2705 const Elf_Internal_Rela
* relocs ATTRIBUTE_UNUSED
)
2707 Elf_Internal_Shdr
*symtab_hdr
;
2708 struct elf_link_hash_entry
**sym_hashes
;
2709 bfd_signed_vma
*local_got_refcounts
;
2710 const Elf_Internal_Rela
*rel
, *relend
;
2711 unsigned long r_symndx
;
2712 struct elf_link_hash_entry
*h
;
2714 elf_section_data (sec
)->local_dynrel
= NULL
;
2716 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2717 sym_hashes
= elf_sym_hashes (abfd
);
2718 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2720 relend
= relocs
+ sec
->reloc_count
;
2721 for (rel
= relocs
; rel
< relend
; rel
++)
2722 switch (ELF32_R_TYPE (rel
->r_info
))
2725 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2726 if (r_symndx
>= symtab_hdr
->sh_info
)
2728 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2729 if (h
->got
.refcount
> 0)
2730 h
->got
.refcount
-= 1;
2732 else if (local_got_refcounts
!= NULL
)
2734 if (local_got_refcounts
[r_symndx
] > 0)
2735 local_got_refcounts
[r_symndx
] -= 1;
2743 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2744 if (r_symndx
>= symtab_hdr
->sh_info
)
2746 struct elf32_arm_link_hash_entry
*eh
;
2747 struct elf32_arm_relocs_copied
**pp
;
2748 struct elf32_arm_relocs_copied
*p
;
2750 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2752 if (h
->plt
.refcount
> 0)
2753 h
->plt
.refcount
-= 1;
2755 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
2756 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
2758 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2760 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
2762 if (p
->section
== sec
)
2780 /* Look through the relocs for a section during the first phase. */
2783 elf32_arm_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
2784 asection
*sec
, const Elf_Internal_Rela
*relocs
)
2786 Elf_Internal_Shdr
*symtab_hdr
;
2787 struct elf_link_hash_entry
**sym_hashes
;
2788 struct elf_link_hash_entry
**sym_hashes_end
;
2789 const Elf_Internal_Rela
*rel
;
2790 const Elf_Internal_Rela
*rel_end
;
2793 bfd_vma
*local_got_offsets
;
2794 struct elf32_arm_link_hash_table
*htab
;
2796 if (info
->relocatable
)
2799 htab
= elf32_arm_hash_table (info
);
2802 dynobj
= elf_hash_table (info
)->dynobj
;
2803 local_got_offsets
= elf_local_got_offsets (abfd
);
2805 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2806 sym_hashes
= elf_sym_hashes (abfd
);
2807 sym_hashes_end
= sym_hashes
2808 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2810 if (!elf_bad_symtab (abfd
))
2811 sym_hashes_end
-= symtab_hdr
->sh_info
;
2813 rel_end
= relocs
+ sec
->reloc_count
;
2814 for (rel
= relocs
; rel
< rel_end
; rel
++)
2816 struct elf_link_hash_entry
*h
;
2817 unsigned long r_symndx
;
2819 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2820 if (r_symndx
< symtab_hdr
->sh_info
)
2823 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2825 switch (ELF32_R_TYPE (rel
->r_info
))
2828 /* This symbol requires a global offset table entry. */
2835 bfd_signed_vma
*local_got_refcounts
;
2837 /* This is a global offset table entry for a local symbol. */
2838 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2839 if (local_got_refcounts
== NULL
)
2843 size
= symtab_hdr
->sh_info
;
2844 size
*= (sizeof (bfd_signed_vma
) + sizeof (char));
2845 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2846 if (local_got_refcounts
== NULL
)
2848 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2850 local_got_refcounts
[r_symndx
] += 1;
2856 if (htab
->sgot
== NULL
)
2858 if (htab
->root
.dynobj
== NULL
)
2859 htab
->root
.dynobj
= abfd
;
2860 if (!create_got_section (htab
->root
.dynobj
, info
))
2871 /* If this reloc is in a read-only section, we might
2872 need a copy reloc. We can't check reliably at this
2873 stage whether the section is read-only, as input
2874 sections have not yet been mapped to output sections.
2875 Tentatively set the flag for now, and correct in
2876 adjust_dynamic_symbol. */
2878 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
2880 /* We may need a .plt entry if the function this reloc
2881 refers to is in a different object. We can't tell for
2882 sure yet, because something later might force the
2884 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
2885 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_PLT32
)
2886 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2888 /* If we create a PLT entry, this relocation will reference
2889 it, even if it's an ABS32 relocation. */
2890 h
->plt
.refcount
+= 1;
2893 /* If we are creating a shared library, and this is a reloc
2894 against a global symbol, or a non PC relative reloc
2895 against a local symbol, then we need to copy the reloc
2896 into the shared library. However, if we are linking with
2897 -Bsymbolic, we do not need to copy a reloc against a
2898 global symbol which is defined in an object we are
2899 including in the link (i.e., DEF_REGULAR is set). At
2900 this point we have not seen all the input files, so it is
2901 possible that DEF_REGULAR is not set now but will be set
2902 later (it is never cleared). We account for that
2903 possibility below by storing information in the
2904 relocs_copied field of the hash table entry. */
2906 && (sec
->flags
& SEC_ALLOC
) != 0
2907 && ((ELF32_R_TYPE (rel
->r_info
) != R_ARM_PC24
2908 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_PLT32
2909 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_REL32
)
2911 && (! info
->symbolic
2912 || (h
->elf_link_hash_flags
2913 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2915 struct elf32_arm_relocs_copied
*p
, **head
;
2917 /* When creating a shared object, we must copy these
2918 reloc types into the output file. We create a reloc
2919 section in dynobj and make room for this reloc. */
2924 name
= (bfd_elf_string_from_elf_section
2926 elf_elfheader (abfd
)->e_shstrndx
,
2927 elf_section_data (sec
)->rel_hdr
.sh_name
));
2931 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
2932 && strcmp (bfd_get_section_name (abfd
, sec
),
2935 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2940 sreloc
= bfd_make_section (dynobj
, name
);
2941 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2942 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2943 if ((sec
->flags
& SEC_ALLOC
) != 0
2944 /* BPABI objects never have dynamic
2945 relocations mapped. */
2946 && !htab
->symbian_p
)
2947 flags
|= SEC_ALLOC
| SEC_LOAD
;
2949 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2950 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2954 elf_section_data (sec
)->sreloc
= sreloc
;
2957 /* If this is a global symbol, we count the number of
2958 relocations we need for this symbol. */
2961 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
2965 /* Track dynamic relocs needed for local syms too.
2966 We really need local syms available to do this
2970 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2975 head
= ((struct elf32_arm_relocs_copied
**)
2976 &elf_section_data (s
)->local_dynrel
);
2980 if (p
== NULL
|| p
->section
!= sec
)
2982 bfd_size_type amt
= sizeof *p
;
2984 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
2993 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
2994 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
2999 /* This relocation describes the C++ object vtable hierarchy.
3000 Reconstruct it for later use during GC. */
3001 case R_ARM_GNU_VTINHERIT
:
3002 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3006 /* This relocation describes which C++ vtable entries are actually
3007 used. Record for later use during GC. */
3008 case R_ARM_GNU_VTENTRY
:
3009 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
3019 is_arm_mapping_symbol_name (const char * name
)
3021 return (name
!= NULL
)
3023 && ((name
[1] == 'a') || (name
[1] == 't') || (name
[1] == 'd'))
3027 /* This is a copy of elf_find_function() from elf.c except that
3028 ARM mapping symbols are ignored when looking for function names
3029 and STT_ARM_TFUNC is considered to a function type. */
3032 arm_elf_find_function (bfd
* abfd ATTRIBUTE_UNUSED
,
3036 const char ** filename_ptr
,
3037 const char ** functionname_ptr
)
3039 const char * filename
= NULL
;
3040 asymbol
* func
= NULL
;
3041 bfd_vma low_func
= 0;
3044 for (p
= symbols
; *p
!= NULL
; p
++)
3048 q
= (elf_symbol_type
*) *p
;
3050 if (bfd_get_section (&q
->symbol
) != section
)
3053 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
3058 filename
= bfd_asymbol_name (&q
->symbol
);
3062 /* Skip $a and $t symbols. */
3063 if ((q
->symbol
.flags
& BSF_LOCAL
)
3064 && is_arm_mapping_symbol_name (q
->symbol
.name
))
3068 if (q
->symbol
.section
== section
3069 && q
->symbol
.value
>= low_func
3070 && q
->symbol
.value
<= offset
)
3072 func
= (asymbol
*) q
;
3073 low_func
= q
->symbol
.value
;
3083 *filename_ptr
= filename
;
3084 if (functionname_ptr
)
3085 *functionname_ptr
= bfd_asymbol_name (func
);
3091 /* Find the nearest line to a particular section and offset, for error
3092 reporting. This code is a duplicate of the code in elf.c, except
3093 that it uses arm_elf_find_function. */
3096 elf32_arm_find_nearest_line (bfd
* abfd
,
3100 const char ** filename_ptr
,
3101 const char ** functionname_ptr
,
3102 unsigned int * line_ptr
)
3104 bfd_boolean found
= FALSE
;
3106 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
3108 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3109 filename_ptr
, functionname_ptr
,
3111 & elf_tdata (abfd
)->dwarf2_find_line_info
))
3113 if (!*functionname_ptr
)
3114 arm_elf_find_function (abfd
, section
, symbols
, offset
,
3115 *filename_ptr
? NULL
: filename_ptr
,
3121 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
3122 & found
, filename_ptr
,
3123 functionname_ptr
, line_ptr
,
3124 & elf_tdata (abfd
)->line_info
))
3127 if (found
&& (*functionname_ptr
|| *line_ptr
))
3130 if (symbols
== NULL
)
3133 if (! arm_elf_find_function (abfd
, section
, symbols
, offset
,
3134 filename_ptr
, functionname_ptr
))
3141 /* Adjust a symbol defined by a dynamic object and referenced by a
3142 regular object. The current definition is in some section of the
3143 dynamic object, but we're not including those sections. We have to
3144 change the definition to something the rest of the link can
3148 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info
* info
,
3149 struct elf_link_hash_entry
* h
)
3153 unsigned int power_of_two
;
3155 dynobj
= elf_hash_table (info
)->dynobj
;
3157 /* Make sure we know what is going on here. */
3158 BFD_ASSERT (dynobj
!= NULL
3159 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3160 || h
->weakdef
!= NULL
3161 || ((h
->elf_link_hash_flags
3162 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3163 && (h
->elf_link_hash_flags
3164 & ELF_LINK_HASH_REF_REGULAR
) != 0
3165 && (h
->elf_link_hash_flags
3166 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3168 /* If this is a function, put it in the procedure linkage table. We
3169 will fill in the contents of the procedure linkage table later,
3170 when we know the address of the .got section. */
3171 if (h
->type
== STT_FUNC
3172 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3174 if (h
->plt
.refcount
<= 0
3175 || SYMBOL_CALLS_LOCAL (info
, h
)
3176 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3177 && h
->root
.type
== bfd_link_hash_undefweak
))
3179 /* This case can occur if we saw a PLT32 reloc in an input
3180 file, but the symbol was never referred to by a dynamic
3181 object, or if all references were garbage collected. In
3182 such a case, we don't actually need to build a procedure
3183 linkage table, and we can just do a PC24 reloc instead. */
3184 h
->plt
.offset
= (bfd_vma
) -1;
3185 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3191 /* It's possible that we incorrectly decided a .plt reloc was
3192 needed for an R_ARM_PC24 reloc to a non-function sym in
3193 check_relocs. We can't decide accurately between function and
3194 non-function syms in check-relocs; Objects loaded later in
3195 the link may change h->type. So fix it now. */
3196 h
->plt
.offset
= (bfd_vma
) -1;
3198 /* If this is a weak symbol, and there is a real definition, the
3199 processor independent code will have arranged for us to see the
3200 real definition first, and we can just use the same value. */
3201 if (h
->weakdef
!= NULL
)
3203 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3204 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3205 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3206 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3210 /* This is a reference to a symbol defined by a dynamic object which
3211 is not a function. */
3213 /* If we are creating a shared library, we must presume that the
3214 only references to the symbol are via the global offset table.
3215 For such cases we need not do anything here; the relocations will
3216 be handled correctly by relocate_section. */
3220 /* We must allocate the symbol in our .dynbss section, which will
3221 become part of the .bss section of the executable. There will be
3222 an entry for this symbol in the .dynsym section. The dynamic
3223 object will contain position independent code, so all references
3224 from the dynamic object to this symbol will go through the global
3225 offset table. The dynamic linker will use the .dynsym entry to
3226 determine the address it must put in the global offset table, so
3227 both the dynamic object and the regular object will refer to the
3228 same memory location for the variable. */
3229 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3230 BFD_ASSERT (s
!= NULL
);
3232 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
3233 copy the initial value out of the dynamic object and into the
3234 runtime process image. We need to remember the offset into the
3235 .rel.bss section we are going to use. */
3236 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3240 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
3241 BFD_ASSERT (srel
!= NULL
);
3242 srel
->size
+= sizeof (Elf32_External_Rel
);
3243 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3246 /* We need to figure out the alignment required for this symbol. I
3247 have no idea how ELF linkers handle this. */
3248 power_of_two
= bfd_log2 (h
->size
);
3249 if (power_of_two
> 3)
3252 /* Apply the required alignment. */
3253 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
3254 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3256 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3260 /* Define the symbol as being at this point in the section. */
3261 h
->root
.u
.def
.section
= s
;
3262 h
->root
.u
.def
.value
= s
->size
;
3264 /* Increment the section size to make room for the symbol. */
3270 /* Allocate space in .plt, .got and associated reloc sections for
3274 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void * inf
)
3276 struct bfd_link_info
*info
;
3277 struct elf32_arm_link_hash_table
*htab
;
3278 struct elf32_arm_link_hash_entry
*eh
;
3279 struct elf32_arm_relocs_copied
*p
;
3281 if (h
->root
.type
== bfd_link_hash_indirect
)
3284 if (h
->root
.type
== bfd_link_hash_warning
)
3285 /* When warning symbols are created, they **replace** the "real"
3286 entry in the hash table, thus we never get to see the real
3287 symbol in a hash traversal. So look at it now. */
3288 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3290 info
= (struct bfd_link_info
*) inf
;
3291 htab
= elf32_arm_hash_table (info
);
3293 if (htab
->root
.dynamic_sections_created
3294 && h
->plt
.refcount
> 0)
3296 /* Make sure this symbol is output as a dynamic symbol.
3297 Undefined weak syms won't yet be marked as dynamic. */
3298 if (h
->dynindx
== -1
3299 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3301 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3306 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3308 asection
*s
= htab
->splt
;
3310 /* If this is the first .plt entry, make room for the special
3313 s
->size
+= htab
->plt_header_size
;
3315 h
->plt
.offset
= s
->size
;
3317 /* If this symbol is not defined in a regular file, and we are
3318 not generating a shared library, then set the symbol to this
3319 location in the .plt. This is required to make function
3320 pointers compare as equal between the normal executable and
3321 the shared library. */
3323 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3325 h
->root
.u
.def
.section
= s
;
3326 h
->root
.u
.def
.value
= h
->plt
.offset
;
3329 /* Make room for this entry. */
3330 s
->size
+= htab
->plt_entry_size
;
3332 if (!htab
->symbian_p
)
3333 /* We also need to make an entry in the .got.plt section, which
3334 will be placed in the .got section by the linker script. */
3335 htab
->sgotplt
->size
+= 4;
3337 /* We also need to make an entry in the .rel.plt section. */
3338 htab
->srelplt
->size
+= sizeof (Elf32_External_Rel
);
3342 h
->plt
.offset
= (bfd_vma
) -1;
3343 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3348 h
->plt
.offset
= (bfd_vma
) -1;
3349 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3352 if (h
->got
.refcount
> 0)
3357 /* Make sure this symbol is output as a dynamic symbol.
3358 Undefined weak syms won't yet be marked as dynamic. */
3359 if (h
->dynindx
== -1
3360 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3362 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3366 if (!htab
->symbian_p
)
3369 h
->got
.offset
= s
->size
;
3371 dyn
= htab
->root
.dynamic_sections_created
;
3372 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3373 || h
->root
.type
!= bfd_link_hash_undefweak
)
3375 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3376 htab
->srelgot
->size
+= sizeof (Elf32_External_Rel
);
3380 h
->got
.offset
= (bfd_vma
) -1;
3382 eh
= (struct elf32_arm_link_hash_entry
*) h
;
3383 if (eh
->relocs_copied
== NULL
)
3386 /* In the shared -Bsymbolic case, discard space allocated for
3387 dynamic pc-relative relocs against symbols which turn out to be
3388 defined in regular objects. For the normal shared case, discard
3389 space for pc-relative relocs that have become local due to symbol
3390 visibility changes. */
3394 /* Discard relocs on undefined weak syms with non-default
3396 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3397 && h
->root
.type
== bfd_link_hash_undefweak
)
3398 eh
->relocs_copied
= NULL
;
3402 /* For the non-shared case, discard space for relocs against
3403 symbols which turn out to need copy relocs or are not
3406 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3407 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3408 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3409 || (htab
->root
.dynamic_sections_created
3410 && (h
->root
.type
== bfd_link_hash_undefweak
3411 || h
->root
.type
== bfd_link_hash_undefined
))))
3413 /* Make sure this symbol is output as a dynamic symbol.
3414 Undefined weak syms won't yet be marked as dynamic. */
3415 if (h
->dynindx
== -1
3416 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3418 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3422 /* If that succeeded, we know we'll be keeping all the
3424 if (h
->dynindx
!= -1)
3428 eh
->relocs_copied
= NULL
;
3433 /* Finally, allocate space. */
3434 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
3436 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
3437 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3443 /* Set the sizes of the dynamic sections. */
3446 elf32_arm_size_dynamic_sections (bfd
* output_bfd ATTRIBUTE_UNUSED
,
3447 struct bfd_link_info
* info
)
3454 struct elf32_arm_link_hash_table
*htab
;
3456 htab
= elf32_arm_hash_table (info
);
3457 dynobj
= elf_hash_table (info
)->dynobj
;
3458 BFD_ASSERT (dynobj
!= NULL
);
3460 if (elf_hash_table (info
)->dynamic_sections_created
)
3462 /* Set the contents of the .interp section to the interpreter. */
3463 if (info
->executable
)
3465 s
= bfd_get_section_by_name (dynobj
, ".interp");
3466 BFD_ASSERT (s
!= NULL
);
3467 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3468 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3472 /* Set up .got offsets for local syms, and space for local dynamic
3474 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3476 bfd_signed_vma
*local_got
;
3477 bfd_signed_vma
*end_local_got
;
3478 char *local_tls_type
;
3479 bfd_size_type locsymcount
;
3480 Elf_Internal_Shdr
*symtab_hdr
;
3483 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3486 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3488 struct elf32_arm_relocs_copied
*p
;
3490 for (p
= *((struct elf32_arm_relocs_copied
**)
3491 &elf_section_data (s
)->local_dynrel
);
3495 if (!bfd_is_abs_section (p
->section
)
3496 && bfd_is_abs_section (p
->section
->output_section
))
3498 /* Input section has been discarded, either because
3499 it is a copy of a linkonce section or due to
3500 linker script /DISCARD/, so we'll be discarding
3503 else if (p
->count
!= 0)
3505 srel
= elf_section_data (p
->section
)->sreloc
;
3506 srel
->size
+= p
->count
* sizeof (Elf32_External_Rel
);
3507 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
3508 info
->flags
|= DF_TEXTREL
;
3513 local_got
= elf_local_got_refcounts (ibfd
);
3517 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3518 locsymcount
= symtab_hdr
->sh_info
;
3519 end_local_got
= local_got
+ locsymcount
;
3521 srel
= htab
->srelgot
;
3522 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
3526 *local_got
= s
->size
;
3529 srel
->size
+= sizeof (Elf32_External_Rel
);
3532 *local_got
= (bfd_vma
) -1;
3536 /* Allocate global sym .plt and .got entries, and space for global
3537 sym dynamic relocs. */
3538 elf_link_hash_traverse (& htab
->root
, allocate_dynrelocs
, info
);
3540 /* The check_relocs and adjust_dynamic_symbol entry points have
3541 determined the sizes of the various dynamic sections. Allocate
3545 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3550 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3553 /* It's OK to base decisions on the section name, because none
3554 of the dynobj section names depend upon the input files. */
3555 name
= bfd_get_section_name (dynobj
, s
);
3559 if (strcmp (name
, ".plt") == 0)
3563 /* Strip this section if we don't need it; see the
3569 /* Remember whether there is a PLT. */
3573 else if (strncmp (name
, ".rel", 4) == 0)
3577 /* If we don't need this section, strip it from the
3578 output file. This is mostly to handle .rel.bss and
3579 .rel.plt. We must create both sections in
3580 create_dynamic_sections, because they must be created
3581 before the linker maps input sections to output
3582 sections. The linker does that before
3583 adjust_dynamic_symbol is called, and it is that
3584 function which decides whether anything needs to go
3585 into these sections. */
3590 /* Remember whether there are any reloc sections other
3592 if (strcmp (name
, ".rel.plt") != 0)
3595 /* We use the reloc_count field as a counter if we need
3596 to copy relocs into the output file. */
3600 else if (strncmp (name
, ".got", 4) != 0)
3602 /* It's not one of our sections, so don't allocate space. */
3608 _bfd_strip_section_from_output (info
, s
);
3612 /* Allocate memory for the section contents. */
3613 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
3614 if (s
->contents
== NULL
&& s
->size
!= 0)
3618 if (elf_hash_table (info
)->dynamic_sections_created
)
3620 /* Add some entries to the .dynamic section. We fill in the
3621 values later, in elf32_arm_finish_dynamic_sections, but we
3622 must add the entries now so that we get the correct size for
3623 the .dynamic section. The DT_DEBUG entry is filled in by the
3624 dynamic linker and used by the debugger. */
3625 #define add_dynamic_entry(TAG, VAL) \
3626 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3630 if (!add_dynamic_entry (DT_DEBUG
, 0))
3636 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3637 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3638 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3639 || !add_dynamic_entry (DT_JMPREL
, 0))
3645 if ( !add_dynamic_entry (DT_REL
, 0)
3646 || !add_dynamic_entry (DT_RELSZ
, 0)
3647 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3651 if ((info
->flags
& DF_TEXTREL
) != 0)
3653 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3655 info
->flags
|= DF_TEXTREL
;
3658 #undef add_synamic_entry
3663 /* Finish up dynamic symbol handling. We set the contents of various
3664 dynamic sections here. */
3667 elf32_arm_finish_dynamic_symbol (bfd
* output_bfd
, struct bfd_link_info
* info
,
3668 struct elf_link_hash_entry
* h
, Elf_Internal_Sym
* sym
)
3671 struct elf32_arm_link_hash_table
*htab
;
3673 dynobj
= elf_hash_table (info
)->dynobj
;
3674 htab
= elf32_arm_hash_table (info
);
3676 if (h
->plt
.offset
!= (bfd_vma
) -1)
3682 Elf_Internal_Rela rel
;
3684 /* This symbol has an entry in the procedure linkage table. Set
3687 BFD_ASSERT (h
->dynindx
!= -1);
3689 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3690 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3691 BFD_ASSERT (splt
!= NULL
&& srel
!= NULL
);
3693 /* Get the index in the procedure linkage table which
3694 corresponds to this symbol. This is the index of this symbol
3695 in all the symbols for which we are making plt entries. The
3696 first entry in the procedure linkage table is reserved. */
3697 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
3698 / htab
->plt_entry_size
);
3700 /* Fill in the entry in the procedure linkage table. */
3701 if (htab
->symbian_p
)
3704 for (i
= 0; i
< htab
->plt_entry_size
/ 4; ++i
)
3705 bfd_put_32 (output_bfd
,
3706 elf32_arm_symbian_plt_entry
[i
],
3707 splt
->contents
+ h
->plt
.offset
+ 4 * i
);
3709 /* Fill in the entry in the .rel.plt section. */
3710 rel
.r_offset
= (splt
->output_offset
3711 + h
->plt
.offset
+ 4 * (i
- 1));
3712 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3717 bfd_vma got_displacement
;
3720 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3721 BFD_ASSERT (sgot
!= NULL
);
3723 /* Get the offset into the .got table of the entry that
3724 corresponds to this function. Each .got entry is 4 bytes.
3725 The first three are reserved. */
3726 got_offset
= (plt_index
+ 3) * 4;
3728 /* Calculate the displacement between the PLT slot and the
3729 entry in the GOT. */
3730 got_displacement
= (sgot
->output_section
->vma
3731 + sgot
->output_offset
3733 - splt
->output_section
->vma
3734 - splt
->output_offset
3738 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
3740 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
3741 splt
->contents
+ h
->plt
.offset
+ 0);
3742 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
3743 splt
->contents
+ h
->plt
.offset
+ 4);
3744 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
3745 splt
->contents
+ h
->plt
.offset
+ 8);
3746 #ifdef FOUR_WORD_PLT
3747 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
3748 splt
->contents
+ h
->plt
.offset
+ 12);
3751 /* Fill in the entry in the global offset table. */
3752 bfd_put_32 (output_bfd
,
3753 (splt
->output_section
->vma
3754 + splt
->output_offset
),
3755 sgot
->contents
+ got_offset
);
3757 /* Fill in the entry in the .rel.plt section. */
3758 rel
.r_offset
= (sgot
->output_section
->vma
3759 + sgot
->output_offset
3761 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3764 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3765 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3767 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3769 /* Mark the symbol as undefined, rather than as defined in
3770 the .plt section. Leave the value alone. */
3771 sym
->st_shndx
= SHN_UNDEF
;
3772 /* If the symbol is weak, we do need to clear the value.
3773 Otherwise, the PLT entry would provide a definition for
3774 the symbol even if the symbol wasn't defined anywhere,
3775 and so the symbol would never be NULL. */
3776 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
3782 if (h
->got
.offset
!= (bfd_vma
) -1)
3786 Elf_Internal_Rela rel
;
3789 /* This symbol has an entry in the global offset table. Set it
3791 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3792 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3793 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3795 rel
.r_offset
= (sgot
->output_section
->vma
3796 + sgot
->output_offset
3797 + (h
->got
.offset
&~ (bfd_vma
) 1));
3799 /* If this is a static link, or it is a -Bsymbolic link and the
3800 symbol is defined locally or was forced to be local because
3801 of a version file, we just want to emit a RELATIVE reloc.
3802 The entry in the global offset table will already have been
3803 initialized in the relocate_section function. */
3805 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3807 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3808 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3812 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3813 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3814 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3817 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3818 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3821 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3824 Elf_Internal_Rela rel
;
3827 /* This symbol needs a copy reloc. Set it up. */
3828 BFD_ASSERT (h
->dynindx
!= -1
3829 && (h
->root
.type
== bfd_link_hash_defined
3830 || h
->root
.type
== bfd_link_hash_defweak
));
3832 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3834 BFD_ASSERT (s
!= NULL
);
3836 rel
.r_offset
= (h
->root
.u
.def
.value
3837 + h
->root
.u
.def
.section
->output_section
->vma
3838 + h
->root
.u
.def
.section
->output_offset
);
3839 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3840 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3841 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3844 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3845 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3846 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3847 sym
->st_shndx
= SHN_ABS
;
3852 /* Finish up the dynamic sections. */
3855 elf32_arm_finish_dynamic_sections (bfd
* output_bfd
, struct bfd_link_info
* info
)
3861 dynobj
= elf_hash_table (info
)->dynobj
;
3863 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3864 BFD_ASSERT (sgot
!= NULL
);
3865 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3867 if (elf_hash_table (info
)->dynamic_sections_created
)
3870 Elf32_External_Dyn
*dyncon
, *dynconend
;
3872 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3873 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3875 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3876 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3878 for (; dyncon
< dynconend
; dyncon
++)
3880 Elf_Internal_Dyn dyn
;
3884 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3897 s
= bfd_get_section_by_name (output_bfd
, name
);
3898 BFD_ASSERT (s
!= NULL
);
3899 dyn
.d_un
.d_ptr
= s
->vma
;
3900 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3904 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3905 BFD_ASSERT (s
!= NULL
);
3906 dyn
.d_un
.d_val
= s
->size
;
3907 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3911 /* My reading of the SVR4 ABI indicates that the
3912 procedure linkage table relocs (DT_JMPREL) should be
3913 included in the overall relocs (DT_REL). This is
3914 what Solaris does. However, UnixWare can not handle
3915 that case. Therefore, we override the DT_RELSZ entry
3916 here to make it not include the JMPREL relocs. Since
3917 the linker script arranges for .rel.plt to follow all
3918 other relocation sections, we don't have to worry
3919 about changing the DT_REL entry. */
3920 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3922 dyn
.d_un
.d_val
-= s
->size
;
3923 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3926 /* Set the bottom bit of DT_INIT/FINI if the
3927 corresponding function is Thumb. */
3929 name
= info
->init_function
;
3932 name
= info
->fini_function
;
3934 /* If it wasn't set by elf_bfd_final_link
3935 then there is nothing to adjust. */
3936 if (dyn
.d_un
.d_val
!= 0)
3938 struct elf_link_hash_entry
* eh
;
3940 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
3941 FALSE
, FALSE
, TRUE
);
3942 if (eh
!= (struct elf_link_hash_entry
*) NULL
3943 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
3945 dyn
.d_un
.d_val
|= 1;
3946 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3953 /* Fill in the first entry in the procedure linkage table. */
3954 if (splt
->size
> 0 && elf32_arm_hash_table (info
)->plt_header_size
)
3956 bfd_vma got_displacement
;
3958 /* Calculate the displacement between the PLT slot and &GOT[0]. */
3959 got_displacement
= (sgot
->output_section
->vma
3960 + sgot
->output_offset
3961 - splt
->output_section
->vma
3962 - splt
->output_offset
3965 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
3966 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
3967 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
3968 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
3969 #ifdef FOUR_WORD_PLT
3970 /* The displacement value goes in the otherwise-unused last word of
3971 the second entry. */
3972 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
3974 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
3978 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3979 really seem like the right value. */
3980 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
3983 /* Fill in the first three entries in the global offset table. */
3987 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
3989 bfd_put_32 (output_bfd
,
3990 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3992 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
3993 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
3996 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4002 elf32_arm_post_process_headers (bfd
* abfd
, struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
4004 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
4005 struct elf32_arm_link_hash_table
*globals
;
4007 i_ehdrp
= elf_elfheader (abfd
);
4009 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
4010 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
4014 globals
= elf32_arm_hash_table (link_info
);
4015 if (globals
->byteswap_code
)
4016 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
4020 static enum elf_reloc_type_class
4021 elf32_arm_reloc_type_class (const Elf_Internal_Rela
*rela
)
4023 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4025 case R_ARM_RELATIVE
:
4026 return reloc_class_relative
;
4027 case R_ARM_JUMP_SLOT
:
4028 return reloc_class_plt
;
4030 return reloc_class_copy
;
4032 return reloc_class_normal
;
4036 static bfd_boolean
elf32_arm_section_flags (flagword
*, const Elf_Internal_Shdr
*);
4037 static void elf32_arm_final_write_processing (bfd
*, bfd_boolean
);
4039 /* Set the right machine number for an Arm ELF file. */
4042 elf32_arm_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
4044 if (hdr
->sh_type
== SHT_NOTE
)
4045 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
4051 elf32_arm_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
4053 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
4057 /* Called for each symbol. Builds a section map based on mapping symbols.
4058 Does not alter any of the symbols. */
4061 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
4063 Elf_Internal_Sym
*elfsym
,
4064 asection
*input_sec
,
4065 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4068 elf32_arm_section_map
*map
;
4069 struct elf32_arm_link_hash_table
*globals
;
4071 /* Only do this on final link. */
4072 if (info
->relocatable
)
4075 /* Only build a map if we need to byteswap code. */
4076 globals
= elf32_arm_hash_table (info
);
4077 if (!globals
->byteswap_code
)
4080 /* We only want mapping symbols. */
4081 if (! is_arm_mapping_symbol_name (name
))
4084 mapcount
= ++(elf32_arm_section_data (input_sec
)->mapcount
);
4085 map
= elf32_arm_section_data (input_sec
)->map
;
4086 /* TODO: This may be inefficient, but we probably don't usually have many
4087 mapping symbols per section. */
4088 map
= bfd_realloc (map
, mapcount
* sizeof (elf32_arm_section_map
));
4089 elf32_arm_section_data (input_sec
)->map
= map
;
4091 map
[mapcount
- 1].vma
= elfsym
->st_value
;
4092 map
[mapcount
- 1].type
= name
[1];
4097 /* Allocate target specific section data. */
4100 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
4102 struct _arm_elf_section_data
*sdata
;
4103 bfd_size_type amt
= sizeof (*sdata
);
4105 sdata
= bfd_zalloc (abfd
, amt
);
4108 sec
->used_by_bfd
= sdata
;
4110 return _bfd_elf_new_section_hook (abfd
, sec
);
4114 /* Used to order a list of mapping symbols by address. */
4117 elf32_arm_compare_mapping (const void * a
, const void * b
)
4119 return ((const elf32_arm_section_map
*) a
)->vma
4120 > ((const elf32_arm_section_map
*) b
)->vma
;
4124 /* Do code byteswapping. Return FALSE afterwards so that the section is
4125 written out as normal. */
4128 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
4132 elf32_arm_section_map
*map
;
4139 mapcount
= elf32_arm_section_data (sec
)->mapcount
;
4140 map
= elf32_arm_section_data (sec
)->map
;
4145 qsort (map
, mapcount
, sizeof (elf32_arm_section_map
),
4146 elf32_arm_compare_mapping
);
4148 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4149 ptr
= map
[0].vma
- offset
;
4150 for (i
= 0; i
< mapcount
; i
++)
4152 if (i
== mapcount
- 1)
4155 end
= map
[i
+ 1].vma
- offset
;
4157 switch (map
[i
].type
)
4160 /* Byte swap code words. */
4161 while (ptr
+ 3 < end
)
4163 tmp
= contents
[ptr
];
4164 contents
[ptr
] = contents
[ptr
+ 3];
4165 contents
[ptr
+ 3] = tmp
;
4166 tmp
= contents
[ptr
+ 1];
4167 contents
[ptr
+ 1] = contents
[ptr
+ 2];
4168 contents
[ptr
+ 2] = tmp
;
4174 /* Byte swap code halfwords. */
4175 while (ptr
+ 1 < end
)
4177 tmp
= contents
[ptr
];
4178 contents
[ptr
] = contents
[ptr
+ 1];
4179 contents
[ptr
+ 1] = tmp
;
4185 /* Leave data alone. */
4194 #define ELF_ARCH bfd_arch_arm
4195 #define ELF_MACHINE_CODE EM_ARM
4196 #ifdef __QNXTARGET__
4197 #define ELF_MAXPAGESIZE 0x1000
4199 #define ELF_MAXPAGESIZE 0x8000
4202 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
4203 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
4204 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
4205 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
4206 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
4207 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
4208 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4209 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
4211 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
4212 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
4213 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
4214 #define elf_backend_check_relocs elf32_arm_check_relocs
4215 #define elf_backend_relocate_section elf32_arm_relocate_section
4216 #define elf_backend_write_section elf32_arm_write_section
4217 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
4218 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
4219 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
4220 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
4221 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
4222 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
4223 #define elf_backend_post_process_headers elf32_arm_post_process_headers
4224 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
4225 #define elf_backend_object_p elf32_arm_object_p
4226 #define elf_backend_section_flags elf32_arm_section_flags
4227 #define elf_backend_final_write_processing elf32_arm_final_write_processing
4228 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
4230 #define elf_backend_can_refcount 1
4231 #define elf_backend_can_gc_sections 1
4232 #define elf_backend_plt_readonly 1
4233 #define elf_backend_want_got_plt 1
4234 #define elf_backend_want_plt_sym 0
4236 #define elf_backend_rela_normal 1
4239 #define elf_backend_got_header_size 12
4241 #include "elf32-target.h"