1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 typedef unsigned long int insn32
;
22 typedef unsigned short int insn16
;
24 static reloc_howto_type
*elf32_arm_reloc_type_lookup
25 PARAMS ((bfd
* abfd
, bfd_reloc_code_real_type code
));
26 static void elf32_arm_info_to_howto
27 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
28 static boolean elf32_arm_set_private_flags
29 PARAMS ((bfd
*, flagword
));
30 static boolean elf32_arm_copy_private_bfd_data
31 PARAMS ((bfd
*, bfd
*));
32 static boolean elf32_arm_merge_private_bfd_data
33 PARAMS ((bfd
*, bfd
*));
34 static boolean elf32_arm_print_private_bfd_data
35 PARAMS ((bfd
*, PTR
));
36 static int elf32_arm_get_symbol_type
37 PARAMS (( Elf_Internal_Sym
*, int));
38 static struct bfd_link_hash_table
*elf32_arm_link_hash_table_create
42 static insn32 insert_thumb_branch
43 PARAMS ((insn32
, int));
44 static struct elf_link_hash_entry
*find_thumb_glue
45 PARAMS ((struct bfd_link_info
*, CONST
char *, bfd
*));
46 static struct elf_link_hash_entry
*find_arm_glue
47 PARAMS ((struct bfd_link_info
*, CONST
char *, bfd
*));
48 static void record_arm_to_thumb_glue
49 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
50 static void record_thumb_to_arm_glue
51 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
53 /* The linker script knows the section names for placement.
54 The entry_names are used to do simple name mangling on the stubs.
55 Given a function name, and its type, the stub can be found. The
56 name can be changed. The only requirement is the %s be present.
59 #define INTERWORK_FLAG( abfd ) (elf_elfheader (abfd)->e_flags & EF_INTERWORK)
61 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
62 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
64 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
65 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
67 /* Get the ARM elf linker hash table from a link_info structure. */
68 #define elf32_arm_hash_table(info) \
69 ((struct elf32_arm_link_hash_table *) ((info)->hash))
71 /* ARM ELF linker hash table */
72 struct elf32_arm_link_hash_table
74 /* The main hash table. */
75 struct elf_link_hash_table root
;
77 /* The size in bytes of the section containg the Thumb-to-ARM glue. */
78 long int thumb_glue_size
;
80 /* The size in bytes of the section containg the ARM-to-Thumb glue. */
81 long int arm_glue_size
;
83 /* An arbitary input BFD chosen to hold the glue sections. */
84 bfd
*bfd_of_glue_owner
;
90 /* Create an ARM elf linker hash table */
92 static struct bfd_link_hash_table
*
93 elf32_arm_link_hash_table_create (abfd
)
96 struct elf32_arm_link_hash_table
*ret
;
98 ret
= ((struct elf32_arm_link_hash_table
*)
99 bfd_alloc (abfd
, sizeof (struct elf32_arm_link_hash_table
)));
100 if (ret
== (struct elf32_arm_link_hash_table
*) NULL
)
103 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
104 _bfd_elf_link_hash_newfunc
))
106 bfd_release (abfd
, ret
);
110 ret
->thumb_glue_size
= 0;
111 ret
->arm_glue_size
= 0;
112 ret
->bfd_of_glue_owner
= NULL
;
114 return &ret
->root
.root
;
117 static struct elf_link_hash_entry
*
118 find_thumb_glue (link_info
, name
, input_bfd
)
119 struct bfd_link_info
*link_info
;
124 struct elf_link_hash_entry
*hash
;
125 struct elf32_arm_link_hash_table
*hash_table
;
127 /* We need a pointer to the armelf specific hash table. */
128 hash_table
= elf32_arm_hash_table (link_info
);
132 bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1));
134 BFD_ASSERT (tmp_name
);
136 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
138 hash
= elf_link_hash_lookup
139 (&(hash_table
)->root
, tmp_name
, false, false, true);
142 /* xgettext:c-format */
143 _bfd_error_handler (_ ("%s: unable to find THUMB glue '%s' for `%s'"),
144 bfd_get_filename (input_bfd
), tmp_name
, name
);
151 static struct elf_link_hash_entry
*
152 find_arm_glue (link_info
, name
, input_bfd
)
153 struct bfd_link_info
*link_info
;
158 struct elf_link_hash_entry
*myh
;
159 struct elf32_arm_link_hash_table
*hash_table
;
161 /* We need a pointer to the elfarm specific hash table. */
162 hash_table
= elf32_arm_hash_table (link_info
);
165 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1));
167 BFD_ASSERT (tmp_name
);
169 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
171 myh
= elf_link_hash_lookup
172 (&(hash_table
)->root
, tmp_name
, false, false, true);
175 /* xgettext:c-format */
176 _bfd_error_handler (_ ("%s: unable to find ARM glue '%s' for `%s'"),
177 bfd_get_filename (input_bfd
), tmp_name
, name
);
192 .word func @ behave as if you saw a ARM_32 reloc
195 #define ARM2THUMB_GLUE_SIZE 12
196 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
197 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
198 static const insn32 a2t3_func_addr_insn
= 0x00000001;
201 Thumb->ARM: Thumb->(non-interworking aware) ARM
205 __func_from_thumb: __func_from_thumb:
207 nop ldr r6, __func_addr
209 __func_change_to_arm: bx r6
211 __func_back_to_thumb:
218 #define THUMB2ARM_GLUE_SIZE 8
219 static const insn16 t2a1_bx_pc_insn
= 0x4778;
220 static const insn16 t2a2_noop_insn
= 0x46c0;
221 static const insn32 t2a3_b_insn
= 0xea000000;
223 static const insn16 t2a1_push_insn
= 0xb540;
224 static const insn16 t2a2_ldr_insn
= 0x4e03;
225 static const insn16 t2a3_mov_insn
= 0x46fe;
226 static const insn16 t2a4_bx_insn
= 0x4730;
227 static const insn32 t2a5_pop_insn
= 0xe8bd4040;
228 static const insn32 t2a6_bx_insn
= 0xe12fff1e;
231 bfd_elf32_arm_allocate_interworking_sections (info
)
232 struct bfd_link_info
*info
;
236 struct elf32_arm_link_hash_table
*globals
;
238 globals
= elf32_arm_hash_table (info
);
240 BFD_ASSERT (globals
!= NULL
);
242 if (globals
->arm_glue_size
!= 0)
244 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
246 s
= bfd_get_section_by_name
247 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
249 BFD_ASSERT (s
!= NULL
);
251 foo
= (bfd_byte
*) bfd_alloc
252 (globals
->bfd_of_glue_owner
, globals
->arm_glue_size
);
254 s
->_raw_size
= s
->_cooked_size
= globals
->arm_glue_size
;
258 if (globals
->thumb_glue_size
!= 0)
260 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
262 s
= bfd_get_section_by_name
263 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
265 BFD_ASSERT (s
!= NULL
);
267 foo
= (bfd_byte
*) bfd_alloc
268 (globals
->bfd_of_glue_owner
, globals
->thumb_glue_size
);
270 s
->_raw_size
= s
->_cooked_size
= globals
->thumb_glue_size
;
278 record_arm_to_thumb_glue (link_info
, h
)
279 struct bfd_link_info
*link_info
;
280 struct elf_link_hash_entry
*h
;
282 const char *name
= h
->root
.root
.string
;
283 register asection
*s
;
285 struct elf_link_hash_entry
*myh
;
286 struct elf32_arm_link_hash_table
*globals
;
288 globals
= elf32_arm_hash_table (link_info
);
290 BFD_ASSERT (globals
!= NULL
);
291 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
293 s
= bfd_get_section_by_name
294 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
297 BFD_ASSERT (s
!= NULL
);
300 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1));
302 BFD_ASSERT (tmp_name
);
304 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
306 myh
= elf_link_hash_lookup
307 (&(globals
)->root
, tmp_name
, false, false, true);
312 return; /* we've already seen this guy */
315 /* The only trick here is using hash_table->arm_glue_size as the value. Even
316 though the section isn't allocated yet, this is where we will be putting
319 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
, tmp_name
,
321 s
, globals
->arm_glue_size
+ 1,
323 (struct bfd_link_hash_entry
**) &myh
);
327 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
333 record_thumb_to_arm_glue (link_info
, h
)
334 struct bfd_link_info
*link_info
;
335 struct elf_link_hash_entry
*h
;
337 const char *name
= h
->root
.root
.string
;
338 register asection
*s
;
340 struct elf_link_hash_entry
*myh
;
341 struct elf32_arm_link_hash_table
*hash_table
;
344 hash_table
= elf32_arm_hash_table (link_info
);
346 BFD_ASSERT (hash_table
!= NULL
);
347 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
349 s
= bfd_get_section_by_name
350 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
352 BFD_ASSERT (s
!= NULL
);
354 tmp_name
= (char *) bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
356 BFD_ASSERT (tmp_name
);
358 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
360 myh
= elf_link_hash_lookup
361 (&(hash_table
)->root
, tmp_name
, false, false, true);
366 return; /* we've already seen this guy */
369 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
, tmp_name
,
370 BSF_GLOBAL
, s
, hash_table
->thumb_glue_size
+ 1,
372 (struct bfd_link_hash_entry
**) &myh
);
374 /* If we mark it 'thumb', the disassembler will do a better job. */
375 bind
= ELF_ST_BIND (myh
->type
);
376 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
380 /* Allocate another symbol to mark where we switch to arm mode. */
382 #define CHANGE_TO_ARM "__%s_change_to_arm"
383 #define BACK_FROM_ARM "__%s_back_from_arm"
385 tmp_name
= (char *) bfd_malloc (strlen (name
) + strlen (CHANGE_TO_ARM
) + 1);
387 BFD_ASSERT (tmp_name
);
389 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
393 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
, tmp_name
,
394 BSF_LOCAL
, s
, hash_table
->thumb_glue_size
+ 4,
396 (struct bfd_link_hash_entry
**) &myh
);
400 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
405 /* Select a BFD to be used to hold the sections used by the glue code.
406 This function is called from the linker scripts in ld/emultempl/
409 bfd_elf32_arm_get_bfd_for_interworking (abfd
, info
)
411 struct bfd_link_info
*info
;
413 struct elf32_arm_link_hash_table
*globals
;
417 /* If we are only performing a partial link do not bother
418 getting a bfd to hold the glue. */
419 if (info
->relocateable
)
422 globals
= elf32_arm_hash_table (info
);
424 BFD_ASSERT (globals
!= NULL
);
426 if (globals
->bfd_of_glue_owner
!= NULL
)
429 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
433 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
435 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
438 || !bfd_set_section_flags (abfd
, sec
, flags
)
439 || !bfd_set_section_alignment (abfd
, sec
, 2))
443 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
447 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
449 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
452 || !bfd_set_section_flags (abfd
, sec
, flags
)
453 || !bfd_set_section_alignment (abfd
, sec
, 2))
457 /* Save the bfd for later use. */
458 globals
->bfd_of_glue_owner
= abfd
;
464 bfd_elf32_arm_process_before_allocation (abfd
, link_info
)
466 struct bfd_link_info
*link_info
;
468 Elf_Internal_Shdr
*symtab_hdr
;
469 Elf_Internal_Rela
*free_relocs
= NULL
;
470 Elf_Internal_Rela
*irel
, *irelend
;
471 bfd_byte
*contents
= NULL
;
472 bfd_byte
*free_contents
= NULL
;
473 Elf32_External_Sym
*extsyms
= NULL
;
474 Elf32_External_Sym
*free_extsyms
= NULL
;
477 struct elf32_arm_link_hash_table
*globals
;
479 /* If we are only performing a partial link do not bother
480 to construct any glue. */
481 if (link_info
->relocateable
)
484 /* Here we have a bfd that is to be included on the link. We have a hook
485 to do reloc rummaging, before section sizes are nailed down. */
487 globals
= elf32_arm_hash_table (link_info
);
489 BFD_ASSERT (globals
!= NULL
);
490 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
492 /* Rummage around all the relocs and map the glue vectors. */
493 sec
= abfd
->sections
;
498 for (; sec
!= NULL
; sec
= sec
->next
)
500 if (sec
->reloc_count
== 0)
503 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
504 /* Load the relocs. */
506 irel
= (_bfd_elf32_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
507 (Elf_Internal_Rela
*) NULL
, false));
509 BFD_ASSERT (irel
!= 0);
511 irelend
= irel
+ sec
->reloc_count
;
512 for (; irel
< irelend
; irel
++)
515 unsigned long r_index
;
518 struct elf_link_hash_entry
*h
;
520 r_type
= ELF32_R_TYPE (irel
->r_info
);
521 r_index
= ELF32_R_SYM (irel
->r_info
);
523 /* These are the only relocation types we care about */
524 if (r_type
!= R_ARM_PC24
525 && r_type
!= R_ARM_THM_PC22
)
528 /* Get the section contents if we haven't done so already. */
529 if (contents
== NULL
)
531 /* Get cached copy if it exists. */
532 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
533 contents
= elf_section_data (sec
)->this_hdr
.contents
;
536 /* Go get them off disk. */
537 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
538 if (contents
== NULL
)
540 free_contents
= contents
;
542 if (!bfd_get_section_contents (abfd
, sec
, contents
,
543 (file_ptr
) 0, sec
->_raw_size
))
548 /* Read this BFD's symbols if we haven't done so already. */
551 /* Get cached copy if it exists. */
552 if (symtab_hdr
->contents
!= NULL
)
553 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
556 /* Go get them off disk. */
557 extsyms
= ((Elf32_External_Sym
*)
558 bfd_malloc (symtab_hdr
->sh_size
));
561 free_extsyms
= extsyms
;
562 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
563 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
564 != symtab_hdr
->sh_size
))
569 /* If the relocation is not against a symbol it cannot concern us. */
573 /* We don't care about local symbols */
574 if (r_index
< symtab_hdr
->sh_info
)
577 /* This is an external symbol */
578 r_index
-= symtab_hdr
->sh_info
;
579 h
= (struct elf_link_hash_entry
*)
580 elf_sym_hashes (abfd
)[r_index
];
582 /* If the relocation is against a static symbol it must be within
583 the current section and so cannot be a cross ARM/Thumb relocation. */
590 /* This one is a call from arm code. We need to look up
591 the target of the call. If it is a thumb target, we
594 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
595 record_arm_to_thumb_glue (link_info
, h
);
599 /* This one is a call from thumb code. We look
600 up the target of the call. If it is not a thumb
601 target, we insert glue. */
603 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
604 record_thumb_to_arm_glue (link_info
, h
);
615 if (free_relocs
!= NULL
)
617 if (free_contents
!= NULL
)
618 free (free_contents
);
619 if (free_extsyms
!= NULL
)
625 struct elf32_arm_reloc_map
627 unsigned char bfd_reloc_val
;
628 unsigned char elf_reloc_val
;
631 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
633 {BFD_RELOC_NONE
, R_ARM_NONE
,},
634 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
,},
635 {BFD_RELOC_32
, R_ARM_ABS32
,},
636 {BFD_RELOC_32_PCREL
, R_ARM_REL32
,},
637 {BFD_RELOC_8
, R_ARM_ABS8
,},
638 {BFD_RELOC_16
, R_ARM_ABS16
,},
639 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
,},
640 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
,},
641 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_PC22
,},
642 {BFD_RELOC_VTABLE_INHERIT
, R_ARM_GNU_VTINHERIT
},
643 {BFD_RELOC_VTABLE_ENTRY
, R_ARM_GNU_VTENTRY
},
644 {BFD_RELOC_NONE
, R_ARM_SBREL32
,},
645 {BFD_RELOC_NONE
, R_ARM_AMP_VCALL9
,},
646 {BFD_RELOC_THUMB_PCREL_BRANCH12
, R_ARM_THM_PC11
,},
647 {BFD_RELOC_THUMB_PCREL_BRANCH9
, R_ARM_THM_PC9
,}
650 static reloc_howto_type
*
651 elf32_arm_reloc_type_lookup (abfd
, code
)
653 bfd_reloc_code_real_type code
;
658 i
< sizeof (elf32_arm_reloc_map
) / sizeof (struct elf32_arm_reloc_map
);
661 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
662 return &elf32_arm_howto_table
[elf32_arm_reloc_map
[i
].elf_reloc_val
];
668 /* The thumb form of a long branch is a bit finicky, because the offset
669 encoding is split over two fields, each in it's own instruction. They
670 can occur in any order. So given a thumb form of long branch, and an
671 offset, insert the offset into the thumb branch and return finished
674 It takes two thumb instructions to encode the target address. Each has
675 11 bits to invest. The upper 11 bits are stored in one (identifed by
676 H-0.. see below), the lower 11 bits are stored in the other (identified
679 Combine together and shifted left by 1 (it's a half word address) and
683 H-0, upper address-0 = 000
685 H-1, lower address-0 = 800
687 They can be ordered either way, but the arm tools I've seen always put
688 the lower one first. It probably doesn't matter. krk@cygnus.com
690 XXX: Actually the order does matter. The second instruction (H-1)
691 moves the computed address into the PC, so it must be the second one
692 in the sequence. The problem, however is that whilst little endian code
693 stores the instructions in HI then LOW order, big endian code does the
694 reverse. nickc@cygnus.com */
696 #define LOW_HI_ORDER 0xF800F000
697 #define HI_LOW_ORDER 0xF000F800
700 insert_thumb_branch (br_insn
, rel_off
)
704 unsigned int low_bits
;
705 unsigned int high_bits
;
708 BFD_ASSERT ((rel_off
& 1) != 1);
710 rel_off
>>= 1; /* half word aligned address */
711 low_bits
= rel_off
& 0x000007FF; /* the bottom 11 bits */
712 high_bits
= (rel_off
>> 11) & 0x000007FF; /* the top 11 bits */
714 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
715 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
716 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
717 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
719 abort (); /* error - not a valid branch instruction form */
721 /* FIXME: abort is probably not the right call. krk@cygnus.com */
726 /* Thumb code calling an ARM function */
728 elf32_thumb_to_arm_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
729 hit_data
, sym_sec
, offset
, addend
, val
)
730 struct bfd_link_info
*info
;
734 asection
*input_section
;
743 unsigned long int tmp
;
745 struct elf_link_hash_entry
*myh
;
746 struct elf32_arm_link_hash_table
*globals
;
748 myh
= find_thumb_glue (info
, name
, input_bfd
);
752 globals
= elf32_arm_hash_table (info
);
754 BFD_ASSERT (globals
!= NULL
);
755 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
757 my_offset
= myh
->root
.u
.def
.value
;
759 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
760 THUMB2ARM_GLUE_SECTION_NAME
);
762 BFD_ASSERT (s
!= NULL
);
763 BFD_ASSERT (s
->contents
!= NULL
);
764 BFD_ASSERT (s
->output_section
!= NULL
);
766 if ((my_offset
& 0x01) == 0x01)
769 && sym_sec
->owner
!= NULL
770 && !INTERWORK_FLAG (sym_sec
->owner
))
773 (_ ("%s(%s): warning: interworking not enabled."),
774 bfd_get_filename (sym_sec
->owner
), name
);
776 (_ (" first occurrence: %s: thumb call to arm"),
777 bfd_get_filename (input_bfd
));
783 myh
->root
.u
.def
.value
= my_offset
;
785 bfd_put_16 (output_bfd
, t2a1_bx_pc_insn
,
786 s
->contents
+ my_offset
);
788 bfd_put_16 (output_bfd
, t2a2_noop_insn
,
789 s
->contents
+ my_offset
+ 2);
792 ((bfd_signed_vma
) val
) /* Address of destination of the stub */
794 (s
->output_offset
/* Offset from the start of the current section to the start of the stubs. */
795 + my_offset
/* Offset of the start of this stub from the start of the stubs. */
796 + s
->output_section
->vma
) /* Address of the start of the current section. */
797 + 4 /* The branch instruction is 4 bytes into the stub. */
798 + 8); /* ARM branches work from the pc of the instruction + 8. */
800 bfd_put_32 (output_bfd
,
801 t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
802 s
->contents
+ my_offset
+ 4);
805 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
807 /* Now go back and fix up the original BL insn to point
812 - (input_section
->output_offset
816 tmp
= bfd_get_32 (input_bfd
, hit_data
817 - input_section
->vma
);
819 bfd_put_32 (output_bfd
,
820 insert_thumb_branch (tmp
, ret_offset
),
821 hit_data
- input_section
->vma
);
826 /* Arm code calling a Thumb function */
828 elf32_arm_to_thumb_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
829 hit_data
, sym_sec
, offset
, addend
, val
)
831 struct bfd_link_info
*info
;
835 asection
*input_section
;
842 unsigned long int tmp
;
846 struct elf_link_hash_entry
*myh
;
847 struct elf32_arm_link_hash_table
*globals
;
849 myh
= find_arm_glue (info
, name
, input_bfd
);
853 globals
= elf32_arm_hash_table (info
);
855 BFD_ASSERT (globals
!= NULL
);
856 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
858 my_offset
= myh
->root
.u
.def
.value
;
859 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
860 ARM2THUMB_GLUE_SECTION_NAME
);
861 BFD_ASSERT (s
!= NULL
);
862 BFD_ASSERT (s
->contents
!= NULL
);
863 BFD_ASSERT (s
->output_section
!= NULL
);
865 if ((my_offset
& 0x01) == 0x01)
868 && sym_sec
->owner
!= NULL
869 && !INTERWORK_FLAG (sym_sec
->owner
))
872 (_ ("%s(%s): warning: interworking not enabled."),
873 bfd_get_filename (sym_sec
->owner
), name
);
875 (_ (" first occurrence: %s: arm call to thumb"),
876 bfd_get_filename (input_bfd
));
879 myh
->root
.u
.def
.value
= my_offset
;
881 bfd_put_32 (output_bfd
, a2t1_ldr_insn
,
882 s
->contents
+ my_offset
);
884 bfd_put_32 (output_bfd
, a2t2_bx_r12_insn
,
885 s
->contents
+ my_offset
+ 4);
887 /* It's a thumb address. Add the low order bit. */
888 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
889 s
->contents
+ my_offset
+ 8);
892 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
894 tmp
= bfd_get_32 (input_bfd
, hit_data
);
895 tmp
= tmp
& 0xFF000000;
897 /* Somehow these are both 4 too far, so subtract 8. */
898 ret_offset
= s
->output_offset
900 + s
->output_section
->vma
901 - (input_section
->output_offset
902 + input_section
->output_section
->vma
906 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
908 bfd_put_32 (output_bfd
, tmp
, hit_data
909 - input_section
->vma
);
915 /* Perform a relocation as part of a final link. */
916 static bfd_reloc_status_type
917 elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
918 input_section
, contents
, offset
, value
,
919 addend
, info
, sym_sec
, sym_name
, sym_flags
)
920 reloc_howto_type
*howto
;
923 asection
*input_section
;
928 struct bfd_link_info
*info
;
930 const char *sym_name
;
931 unsigned char sym_flags
;
933 unsigned long r_type
= howto
->type
;
934 bfd_byte
*hit_data
= contents
+ offset
;
943 /* Arm B/BL instruction */
946 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
948 /* check for arm calling thumb function */
949 if (sym_flags
== STT_ARM_TFUNC
)
951 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
, output_bfd
,
952 input_section
, hit_data
, sym_sec
, offset
, addend
, value
);
956 value
= value
+ addend
;
957 value
-= (input_section
->output_section
->vma
958 + input_section
->output_offset
+ 8);
960 value
= value
>> howto
->rightshift
;
963 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xff000000);
964 bfd_put_32 (input_bfd
, value
, hit_data
);
969 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
972 if (sym_flags
== STT_ARM_TFUNC
)
974 bfd_put_32 (input_bfd
, value
, hit_data
);
979 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
981 value
-= (input_section
->output_section
->vma
982 + input_section
->output_offset
);
985 bfd_put_32 (input_bfd
, value
, hit_data
);
990 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
993 if ((long) value
> 0x7f || (long) value
< -0x80)
994 return bfd_reloc_overflow
;
996 bfd_put_8 (input_bfd
, value
, hit_data
);
1001 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
1005 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1006 return bfd_reloc_overflow
;
1008 bfd_put_16 (input_bfd
, value
, hit_data
);
1009 return bfd_reloc_ok
;
1012 /* Support ldr and str instruction for the arm */
1013 /* Also thumb b (unconditional branch) */
1015 addend
= (bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
);
1019 if ((long) value
> 0x7ff || (long) value
< -0x800)
1020 return bfd_reloc_overflow
;
1022 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1023 bfd_put_32 (input_bfd
, value
, hit_data
);
1024 return bfd_reloc_ok
;
1026 case R_ARM_THM_ABS5
:
1027 /* Support ldr and str instructions for the thumb. */
1030 if ((long) value
> 0x1f || (long) value
< -0x10)
1031 return bfd_reloc_overflow
;
1033 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf82f;
1034 bfd_put_16 (input_bfd
, value
, hit_data
);
1035 return bfd_reloc_ok
;
1038 case R_ARM_THM_PC22
:
1039 /* thumb BL (branch long instruction). */
1042 boolean overflow
= false;
1043 bfd_vma insn
= bfd_get_32 (input_bfd
, hit_data
);
1044 bfd_vma src_mask
= 0x007FFFFE;
1045 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1046 bfd_signed_vma reloc_signed_min
= ~reloc_signed_max
;
1048 bfd_signed_vma signed_check
;
1050 bfd_signed_vma signed_add
;
1052 /* If it's not a call to thumb, assume call to arm */
1053 if (sym_flags
!= STT_ARM_TFUNC
)
1055 if (elf32_thumb_to_arm_stub
1056 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1057 hit_data
, sym_sec
, offset
, addend
, value
))
1058 return bfd_reloc_ok
;
1060 return bfd_reloc_dangerous
;
1063 relocation
= value
+ addend
;
1064 relocation
-= (input_section
->output_section
->vma
+ input_section
->output_offset
);
1065 relocation
-= offset
;
1067 check
= relocation
>> howto
->rightshift
;
1069 /* If this is a signed value, the rightshift just dropped
1070 leading 1 bits (assuming twos complement). */
1071 if ((bfd_signed_vma
) relocation
>= 0)
1072 signed_check
= check
;
1074 signed_check
= (check
| ((bfd_vma
) - 1 & ~((bfd_vma
) - 1 >> howto
->rightshift
)));
1076 /* Get the value from the object file. */
1077 if (bfd_big_endian (input_bfd
))
1078 add
= (((insn
) & 0x07ff0000) >> 4) | (((insn
) & 0x7ff) << 1);
1080 add
= ((((insn
) & 0x7ff) << 12) | (((insn
) & 0x07ff0000) >> 15));
1082 /* Get the value from the object file with an appropriate sign.
1083 The expression involving howto->src_mask isolates the upper
1084 bit of src_mask. If that bit is set in the value we are
1085 adding, it is negative, and we subtract out that number times
1086 two. If src_mask includes the highest possible bit, then we
1087 can not get the upper bit, but that does not matter since
1088 signed_add needs no adjustment to become negative in that case. */
1092 if ((add
& (((~src_mask
) >> 1) & src_mask
)) != 0)
1093 signed_add
-= (((~src_mask
) >> 1) & src_mask
) << 1;
1095 /* Add the value from the object file, shifted so that it is a
1097 /* howto->bitpos == 0 */
1099 signed_check
+= signed_add
;
1100 relocation
+= signed_add
;
1102 /* Assumes two's complement. */
1103 if (signed_check
> reloc_signed_max
1104 || signed_check
< reloc_signed_min
)
1107 /* Put RELOCATION into the correct bits: */
1109 if (bfd_big_endian (input_bfd
))
1110 relocation
= (((relocation
& 0xffe) >> 1) | ((relocation
<< 4) & 0x07ff0000));
1112 relocation
= (((relocation
& 0xffe) << 15) | ((relocation
>> 12) & 0x7ff));
1114 /* Add RELOCATION to the correct bits of X: */
1115 insn
= ((insn
& ~howto
->dst_mask
) | relocation
);
1117 /* Put the relocated value back in the object file: */
1118 bfd_put_32 (input_bfd
, insn
, hit_data
);
1120 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1124 case R_ARM_GNU_VTINHERIT
:
1125 case R_ARM_GNU_VTENTRY
:
1126 return bfd_reloc_ok
;
1129 return bfd_reloc_notsupported
;
1131 case R_ARM_AMP_VCALL9
:
1132 return bfd_reloc_notsupported
;
1134 case R_ARM_RSBREL32
:
1135 return bfd_reloc_notsupported
;
1137 case R_ARM_THM_RPC22
:
1138 return bfd_reloc_notsupported
;
1141 return bfd_reloc_notsupported
;
1144 return bfd_reloc_notsupported
;
1147 return bfd_reloc_notsupported
;
1150 return bfd_reloc_notsupported
;
1153 return bfd_reloc_notsupported
;
1158 /* Relocate an ARM ELF section. */
1160 elf32_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1161 contents
, relocs
, local_syms
, local_sections
)
1163 struct bfd_link_info
*info
;
1165 asection
*input_section
;
1167 Elf_Internal_Rela
*relocs
;
1168 Elf_Internal_Sym
*local_syms
;
1169 asection
**local_sections
;
1171 Elf_Internal_Shdr
*symtab_hdr
;
1172 struct elf_link_hash_entry
**sym_hashes
;
1173 Elf_Internal_Rela
*rel
, *relend
;
1176 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1177 sym_hashes
= elf_sym_hashes (input_bfd
);
1180 relend
= relocs
+ input_section
->reloc_count
;
1181 for (; rel
< relend
; rel
++)
1184 reloc_howto_type
*howto
;
1185 unsigned long r_symndx
;
1186 Elf_Internal_Sym
*sym
;
1188 struct elf_link_hash_entry
*h
;
1190 bfd_reloc_status_type r
;
1192 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1193 r_type
= ELF32_R_TYPE (rel
->r_info
);
1195 if (r_type
== R_ARM_GNU_VTENTRY
1196 || r_type
== R_ARM_GNU_VTINHERIT
)
1199 howto
= elf32_arm_howto_table
+ r_type
;
1201 if (info
->relocateable
)
1203 /* This is a relocateable link. We don't have to change
1204 anything, unless the reloc is against a section symbol,
1205 in which case we have to adjust according to where the
1206 section symbol winds up in the output section. */
1207 if (r_symndx
< symtab_hdr
->sh_info
)
1209 sym
= local_syms
+ r_symndx
;
1210 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1212 sec
= local_sections
[r_symndx
];
1213 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1220 /* This is a final link. */
1224 if (r_symndx
< symtab_hdr
->sh_info
)
1226 sym
= local_syms
+ r_symndx
;
1227 sec
= local_sections
[r_symndx
];
1228 relocation
= (sec
->output_section
->vma
1229 + sec
->output_offset
1234 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1235 while (h
->root
.type
== bfd_link_hash_indirect
1236 || h
->root
.type
== bfd_link_hash_warning
)
1237 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1238 if (h
->root
.type
== bfd_link_hash_defined
1239 || h
->root
.type
== bfd_link_hash_defweak
)
1241 sec
= h
->root
.u
.def
.section
;
1242 relocation
= (h
->root
.u
.def
.value
1243 + sec
->output_section
->vma
1244 + sec
->output_offset
);
1246 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1250 if (!((*info
->callbacks
->undefined_symbol
)
1251 (info
, h
->root
.root
.string
, input_bfd
,
1252 input_section
, rel
->r_offset
)))
1259 name
= h
->root
.root
.string
;
1262 name
= (bfd_elf_string_from_elf_section
1263 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1264 if (name
== NULL
|| *name
== '\0')
1265 name
= bfd_section_name (input_bfd
, sec
);
1268 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
1270 contents
, rel
->r_offset
,
1271 relocation
, rel
->r_addend
,
1273 (h
? ELF_ST_TYPE (h
->type
) :
1274 ELF_ST_TYPE (sym
->st_info
)));
1276 if (r
!= bfd_reloc_ok
)
1278 const char * msg
= (const char *) 0;
1282 case bfd_reloc_overflow
:
1283 if (!((*info
->callbacks
->reloc_overflow
)
1284 (info
, name
, howto
->name
, (bfd_vma
) 0,
1285 input_bfd
, input_section
, rel
->r_offset
)))
1289 case bfd_reloc_undefined
:
1290 if (!((*info
->callbacks
->undefined_symbol
)
1291 (info
, name
, input_bfd
, input_section
,
1296 case bfd_reloc_outofrange
:
1297 msg
= _ ("internal error: out of range error");
1300 case bfd_reloc_notsupported
:
1301 msg
= _ ("internal error: unsupported relocation error");
1304 case bfd_reloc_dangerous
:
1305 msg
= _ ("internal error: dangerous error");
1309 msg
= _ ("internal error: unknown error");
1313 if (!((*info
->callbacks
->warning
)
1314 (info
, msg
, name
, input_bfd
, input_section
,
1325 /* Function to keep ARM specific flags in the ELF header. */
1327 elf32_arm_set_private_flags (abfd
, flags
)
1331 if (elf_flags_init (abfd
)
1332 && elf_elfheader (abfd
)->e_flags
!= flags
)
1334 if (flags
& EF_INTERWORK
)
1335 _bfd_error_handler (_ ("\
1336 Warning: Not setting interwork flag of %s since it has already been specified as non-interworking"),
1337 bfd_get_filename (abfd
));
1339 _bfd_error_handler (_ ("\
1340 Warning: Clearing the interwork flag of %s due to outside request"),
1341 bfd_get_filename (abfd
));
1345 elf_elfheader (abfd
)->e_flags
= flags
;
1346 elf_flags_init (abfd
) = true;
1352 /* Copy backend specific data from one object module to another */
1354 elf32_arm_copy_private_bfd_data (ibfd
, obfd
)
1361 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1362 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1365 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1366 out_flags
= elf_elfheader (obfd
)->e_flags
;
1368 if (elf_flags_init (obfd
) && in_flags
!= out_flags
)
1370 /* Cannot mix PIC and non-PIC code. */
1371 if ((in_flags
& EF_PIC
) != (out_flags
& EF_PIC
))
1374 /* Cannot mix APCS26 and APCS32 code. */
1375 if ((in_flags
& EF_APCS_26
) != (out_flags
& EF_APCS_26
))
1378 /* Cannot mix float APCS and non-float APCS code. */
1379 if ((in_flags
& EF_APCS_FLOAT
) != (out_flags
& EF_APCS_FLOAT
))
1382 /* If the src and dest have different interworking flags
1383 then turn off the interworking bit. */
1384 if ((in_flags
& EF_INTERWORK
) != (out_flags
& EF_INTERWORK
))
1386 if (out_flags
& EF_INTERWORK
)
1387 _bfd_error_handler (_ ("\
1388 Warning: Clearing the interwork flag in %s because non-interworking code in %s has been linked with it"),
1389 bfd_get_filename (obfd
), bfd_get_filename (ibfd
));
1391 in_flags
&= ~EF_INTERWORK
;
1395 elf_elfheader (obfd
)->e_flags
= in_flags
;
1396 elf_flags_init (obfd
) = true;
1401 /* Merge backend specific data from an object file to the output
1402 object file when linking. */
1404 elf32_arm_merge_private_bfd_data (ibfd
, obfd
)
1411 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1412 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1415 /* The input BFD must have had its flags initialised. */
1416 /* The following seems bogus to me -- The flags are initialized in
1417 the assembler but I don't think an elf_flags_init field is
1418 written into the object */
1419 /* BFD_ASSERT (elf_flags_init (ibfd)); */
1421 in_flags
= elf_elfheader (ibfd
)->e_flags
;
1422 out_flags
= elf_elfheader (obfd
)->e_flags
;
1424 if (!elf_flags_init (obfd
))
1426 /* If the input is the default architecture then do not
1427 bother setting the flags for the output architecture,
1428 instead allow future merges to do this. If no future
1429 merges ever set these flags then they will retain their
1430 unitialised values, which surprise surprise, correspond
1431 to the default values. */
1432 if (bfd_get_arch_info (ibfd
)->the_default
)
1435 elf_flags_init (obfd
) = true;
1436 elf_elfheader (obfd
)->e_flags
= in_flags
;
1438 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1439 && bfd_get_arch_info (obfd
)->the_default
)
1440 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
1445 /* Check flag compatibility. */
1446 if (in_flags
== out_flags
)
1449 /* Complain about various flag mismatches. */
1451 if ((in_flags
& EF_APCS_26
) != (out_flags
& EF_APCS_26
))
1452 _bfd_error_handler (_ ("\
1453 Error: %s compiled for APCS-%d, whereas %s is compiled for APCS-%d"),
1454 bfd_get_filename (ibfd
),
1455 in_flags
& EF_APCS_26
? 26 : 32,
1456 bfd_get_filename (obfd
),
1457 out_flags
& EF_APCS_26
? 26 : 32);
1459 if ((in_flags
& EF_APCS_FLOAT
) != (out_flags
& EF_APCS_FLOAT
))
1460 _bfd_error_handler (_ ("\
1461 Error: %s passes floats in %s registers, whereas %s passes them in %s registers"),
1462 bfd_get_filename (ibfd
),
1463 in_flags
& EF_APCS_FLOAT
? _ ("float") : _ ("integer"),
1464 bfd_get_filename (obfd
),
1465 out_flags
& EF_APCS_26
? _ ("float") : _ ("integer"));
1467 if ((in_flags
& EF_PIC
) != (out_flags
& EF_PIC
))
1468 _bfd_error_handler (_ ("\
1469 Error: %s is compiled as position %s code, whereas %s is not"),
1470 bfd_get_filename (ibfd
),
1471 in_flags
& EF_PIC
? _ ("independent") : _ ("dependent"),
1472 bfd_get_filename (obfd
));
1474 /* Interworking mismatch is only a warning. */
1475 if ((in_flags
& EF_INTERWORK
) != (out_flags
& EF_INTERWORK
))
1477 _bfd_error_handler (_ ("\
1478 Warning: %s %s interworking, whereas %s %s"),
1479 bfd_get_filename (ibfd
),
1480 in_flags
& EF_INTERWORK
? _ ("supports") : _ ("does not support"),
1481 bfd_get_filename (obfd
),
1482 out_flags
& EF_INTERWORK
? _ ("does not") : _ ("does"));
1489 /* Display the flags field */
1491 elf32_arm_print_private_bfd_data (abfd
, ptr
)
1495 FILE *file
= (FILE *) ptr
;
1497 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1499 /* Print normal ELF private data. */
1500 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1502 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1504 /* xgettext:c-format */
1505 fprintf (file
, _ ("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1507 if (elf_elfheader (abfd
)->e_flags
& EF_INTERWORK
)
1508 fprintf (file
, _ (" [interworking enabled]"));
1510 fprintf (file
, _ (" [interworking not enabled]"));
1512 if (elf_elfheader (abfd
)->e_flags
& EF_APCS_26
)
1513 fprintf (file
, _ (" [APCS-26]"));
1515 fprintf (file
, _ (" [APCS-32]"));
1517 if (elf_elfheader (abfd
)->e_flags
& EF_APCS_FLOAT
)
1518 fprintf (file
, _ (" [floats passed in float registers]"));
1520 fprintf (file
, _ (" [floats passed in integer registers]"));
1522 if (elf_elfheader (abfd
)->e_flags
& EF_PIC
)
1523 fprintf (file
, _ (" [position independent]"));
1525 fprintf (file
, _ (" [absolute position]"));
1533 elf32_arm_get_symbol_type (elf_sym
, type
)
1534 Elf_Internal_Sym
* elf_sym
;
1537 if (ELF_ST_TYPE (elf_sym
->st_info
) == STT_ARM_TFUNC
)
1538 return ELF_ST_TYPE (elf_sym
->st_info
);
1544 elf32_arm_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1546 struct bfd_link_info
*info
;
1547 Elf_Internal_Rela
*rel
;
1548 struct elf_link_hash_entry
*h
;
1549 Elf_Internal_Sym
*sym
;
1553 switch (ELF32_R_TYPE (rel
->r_info
))
1555 case R_ARM_GNU_VTINHERIT
:
1556 case R_ARM_GNU_VTENTRY
:
1560 switch (h
->root
.type
)
1562 case bfd_link_hash_defined
:
1563 case bfd_link_hash_defweak
:
1564 return h
->root
.u
.def
.section
;
1566 case bfd_link_hash_common
:
1567 return h
->root
.u
.c
.p
->section
;
1573 if (!(elf_bad_symtab (abfd
)
1574 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1575 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1576 && sym
->st_shndx
!= SHN_COMMON
))
1578 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1585 elf32_arm_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1587 struct bfd_link_info
*info
;
1589 const Elf_Internal_Rela
*relocs
;
1591 /* we don't use got and plt entries for armelf */
1595 /* Look through the relocs for a section during the first phase.
1596 Since we don't do .gots or .plts, we just need to consider the
1597 virtual table relocs for gc. */
1600 elf32_arm_check_relocs (abfd
, info
, sec
, relocs
)
1602 struct bfd_link_info
*info
;
1604 const Elf_Internal_Rela
*relocs
;
1606 Elf_Internal_Shdr
*symtab_hdr
;
1607 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1608 const Elf_Internal_Rela
*rel
;
1609 const Elf_Internal_Rela
*rel_end
;
1611 if (info
->relocateable
)
1614 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1615 sym_hashes
= elf_sym_hashes (abfd
);
1616 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
1617 if (!elf_bad_symtab (abfd
))
1618 sym_hashes_end
-= symtab_hdr
->sh_info
;
1620 rel_end
= relocs
+ sec
->reloc_count
;
1621 for (rel
= relocs
; rel
< rel_end
; rel
++)
1623 struct elf_link_hash_entry
*h
;
1624 unsigned long r_symndx
;
1626 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1627 if (r_symndx
< symtab_hdr
->sh_info
)
1630 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1632 switch (ELF32_R_TYPE (rel
->r_info
))
1634 /* This relocation describes the C++ object vtable hierarchy.
1635 Reconstruct it for later use during GC. */
1636 case R_ARM_GNU_VTINHERIT
:
1637 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1641 /* This relocation describes which C++ vtable entries are actually
1642 used. Record for later use during GC. */
1643 case R_ARM_GNU_VTENTRY
:
1644 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1654 /* Find the nearest line to a particular section and offset, for error
1655 reporting. This code is a duplicate of the code in elf.c, except
1656 that it also accepts STT_ARM_TFUNC as a symbol that names a function. */
1659 elf32_arm_find_nearest_line
1660 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
1665 CONST
char ** filename_ptr
;
1666 CONST
char ** functionname_ptr
;
1667 unsigned int * line_ptr
;
1670 const char * filename
;
1675 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
1676 filename_ptr
, functionname_ptr
,
1680 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
1681 &found
, filename_ptr
,
1682 functionname_ptr
, line_ptr
,
1683 &elf_tdata (abfd
)->line_info
))
1689 if (symbols
== NULL
)
1696 for (p
= symbols
; *p
!= NULL
; p
++)
1700 q
= (elf_symbol_type
*) *p
;
1702 if (bfd_get_section (&q
->symbol
) != section
)
1705 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
1710 filename
= bfd_asymbol_name (&q
->symbol
);
1715 if (q
->symbol
.section
== section
1716 && q
->symbol
.value
>= low_func
1717 && q
->symbol
.value
<= offset
)
1719 func
= (asymbol
*) q
;
1720 low_func
= q
->symbol
.value
;
1729 *filename_ptr
= filename
;
1730 *functionname_ptr
= bfd_asymbol_name (func
);
1736 #define ELF_ARCH bfd_arch_arm
1737 #define ELF_MACHINE_CODE EM_ARM
1739 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
1740 #define elf_backend_relocate_section elf32_arm_relocate_section
1741 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
1742 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
1743 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
1744 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
1745 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
1746 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
1747 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
1748 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
1749 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
1750 #define elf_backend_check_relocs elf32_arm_check_relocs
1752 #define elf_backend_can_gc_sections 1
1754 #include "elf32-target.h"