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 static bfd_boolean elf32_arm_set_private_flags
29 PARAMS ((bfd
*, flagword
));
30 static bfd_boolean elf32_arm_copy_private_bfd_data
31 PARAMS ((bfd
*, bfd
*));
32 static bfd_boolean elf32_arm_merge_private_bfd_data
33 PARAMS ((bfd
*, bfd
*));
34 static bfd_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
40 static bfd_reloc_status_type elf32_arm_final_link_relocate
41 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
42 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
43 const char *, int, struct elf_link_hash_entry
*));
44 static insn32 insert_thumb_branch
45 PARAMS ((insn32
, int));
46 static struct elf_link_hash_entry
*find_thumb_glue
47 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
48 static struct elf_link_hash_entry
*find_arm_glue
49 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
50 static void elf32_arm_post_process_headers
51 PARAMS ((bfd
*, struct bfd_link_info
*));
52 static int elf32_arm_to_thumb_stub
53 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
54 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
55 static int elf32_thumb_to_arm_stub
56 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
57 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
58 static bfd_boolean elf32_arm_relocate_section
59 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
60 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
61 static asection
* elf32_arm_gc_mark_hook
62 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
63 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
64 static bfd_boolean elf32_arm_gc_sweep_hook
65 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
66 const Elf_Internal_Rela
*));
67 static bfd_boolean elf32_arm_check_relocs
68 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
69 const Elf_Internal_Rela
*));
70 static bfd_boolean elf32_arm_find_nearest_line
71 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
72 const char **, unsigned int *));
73 static bfd_boolean elf32_arm_adjust_dynamic_symbol
74 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
75 static bfd_boolean elf32_arm_size_dynamic_sections
76 PARAMS ((bfd
*, struct bfd_link_info
*));
77 static bfd_boolean elf32_arm_finish_dynamic_symbol
78 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
80 static bfd_boolean elf32_arm_finish_dynamic_sections
81 PARAMS ((bfd
*, struct bfd_link_info
*));
82 static struct bfd_hash_entry
* elf32_arm_link_hash_newfunc
83 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
85 static void arm_add_to_rel
86 PARAMS ((bfd
*, bfd_byte
*, reloc_howto_type
*, bfd_signed_vma
));
88 static bfd_boolean allocate_dynrelocs
89 PARAMS ((struct elf_link_hash_entry
*h
, PTR inf
));
90 static bfd_boolean create_got_section
91 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
92 static bfd_boolean elf32_arm_create_dynamic_sections
93 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
94 static enum elf_reloc_type_class elf32_arm_reloc_type_class
95 PARAMS ((const Elf_Internal_Rela
*));
96 static bfd_boolean elf32_arm_object_p
99 #ifndef ELFARM_NABI_C_INCLUDED
100 static void record_arm_to_thumb_glue
101 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
102 static void record_thumb_to_arm_glue
103 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
104 bfd_boolean bfd_elf32_arm_allocate_interworking_sections
105 PARAMS ((struct bfd_link_info
*));
106 bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 bfd_boolean bfd_elf32_arm_process_before_allocation
109 PARAMS ((bfd
*, struct bfd_link_info
*, int, int));
113 #define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
115 /* The linker script knows the section names for placement.
116 The entry_names are used to do simple name mangling on the stubs.
117 Given a function name, and its type, the stub can be found. The
118 name can be changed. The only requirement is the %s be present. */
119 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
120 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
122 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
123 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
125 /* The name of the dynamic interpreter. This is put in the .interp
127 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
131 /* The size in bytes of the special first entry in the procedure
133 #define PLT_HEADER_SIZE 16
135 /* The size in bytes of an entry in the procedure linkage table. */
136 #define PLT_ENTRY_SIZE 16
138 /* The first entry in a procedure linkage table looks like
139 this. It is set up so that any shared library function that is
140 called before the relocation has been set up calls the dynamic
142 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
144 0xe52de004, /* str lr, [sp, #-4]! */
145 0xe59fe010, /* ldr lr, [pc, #16] */
146 0xe08fe00e, /* add lr, pc, lr */
147 0xe5bef008, /* ldr pc, [lr, #8]! */
150 /* Subsequent entries in a procedure linkage table look like
152 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
154 0xe28fc600, /* add ip, pc, #NN */
155 0xe28cca00, /* add ip, ip, #NN */
156 0xe5bcf000, /* ldr pc, [ip, #NN]! */
157 0x00000000, /* unused */
162 /* The size in bytes of the special first entry in the procedure
164 #define PLT_HEADER_SIZE 20
166 /* The size in bytes of an entry in the procedure linkage table. */
167 #define PLT_ENTRY_SIZE 12
169 /* The first entry in a procedure linkage table looks like
170 this. It is set up so that any shared library function that is
171 called before the relocation has been set up calls the dynamic
173 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
175 0xe52de004, /* str lr, [sp, #-4]! */
176 0xe59fe004, /* ldr lr, [pc, #4] */
177 0xe08fe00e, /* add lr, pc, lr */
178 0xe5bef008, /* ldr pc, [lr, #8]! */
179 0x00000000, /* &GOT[0] - . */
182 /* Subsequent entries in a procedure linkage table look like
184 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
186 0xe28fc600, /* add ip, pc, #0xNN00000 */
187 0xe28cca00, /* add ip, ip, #0xNN000 */
188 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
193 /* Used to build a map of a section. This is required for mixed-endian
196 typedef struct elf32_elf_section_map
201 elf32_arm_section_map
;
203 struct _arm_elf_section_data
205 struct bfd_elf_section_data elf
;
207 elf32_arm_section_map
*map
;
210 #define elf32_arm_section_data(sec) \
211 ((struct _arm_elf_section_data *) elf_section_data (sec))
213 /* The ARM linker needs to keep track of the number of relocs that it
214 decides to copy in check_relocs for each symbol. This is so that
215 it can discard PC relative relocs if it doesn't need them when
216 linking with -Bsymbolic. We store the information in a field
217 extending the regular ELF linker hash table. */
219 /* This structure keeps track of the number of PC relative relocs we
220 have copied for a given symbol. */
221 struct elf32_arm_relocs_copied
224 struct elf32_arm_relocs_copied
* next
;
225 /* A section in dynobj. */
227 /* Number of relocs copied in this section. */
231 /* Arm ELF linker hash entry. */
232 struct elf32_arm_link_hash_entry
234 struct elf_link_hash_entry root
;
236 /* Number of PC relative relocs copied for this symbol. */
237 struct elf32_arm_relocs_copied
* relocs_copied
;
240 /* Traverse an arm ELF linker hash table. */
241 #define elf32_arm_link_hash_traverse(table, func, info) \
242 (elf_link_hash_traverse \
244 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
247 /* Get the ARM elf linker hash table from a link_info structure. */
248 #define elf32_arm_hash_table(info) \
249 ((struct elf32_arm_link_hash_table *) ((info)->hash))
251 /* ARM ELF linker hash table. */
252 struct elf32_arm_link_hash_table
254 /* The main hash table. */
255 struct elf_link_hash_table root
;
257 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
258 bfd_size_type thumb_glue_size
;
260 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
261 bfd_size_type arm_glue_size
;
263 /* An arbitrary input BFD chosen to hold the glue sections. */
264 bfd
* bfd_of_glue_owner
;
266 /* A boolean indicating whether knowledge of the ARM's pipeline
267 length should be applied by the linker. */
268 int no_pipeline_knowledge
;
270 /* Nonzero to output a BE8 image. */
273 /* Short-cuts to get to dynamic linker sections. */
282 /* Small local sym to section mapping cache. */
283 struct sym_sec_cache sym_sec
;
286 /* Create an entry in an ARM ELF linker hash table. */
288 static struct bfd_hash_entry
*
289 elf32_arm_link_hash_newfunc (entry
, table
, string
)
290 struct bfd_hash_entry
* entry
;
291 struct bfd_hash_table
* table
;
294 struct elf32_arm_link_hash_entry
* ret
=
295 (struct elf32_arm_link_hash_entry
*) entry
;
297 /* Allocate the structure if it has not already been allocated by a
299 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
300 ret
= ((struct elf32_arm_link_hash_entry
*)
301 bfd_hash_allocate (table
,
302 sizeof (struct elf32_arm_link_hash_entry
)));
303 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
304 return (struct bfd_hash_entry
*) ret
;
306 /* Call the allocation method of the superclass. */
307 ret
= ((struct elf32_arm_link_hash_entry
*)
308 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
310 if (ret
!= (struct elf32_arm_link_hash_entry
*) NULL
)
311 ret
->relocs_copied
= NULL
;
313 return (struct bfd_hash_entry
*) ret
;
316 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
317 shortcuts to them in our hash table. */
320 create_got_section (dynobj
, info
)
322 struct bfd_link_info
*info
;
324 struct elf32_arm_link_hash_table
*htab
;
326 if (! _bfd_elf_create_got_section (dynobj
, info
))
329 htab
= elf32_arm_hash_table (info
);
330 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
331 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
332 if (!htab
->sgot
|| !htab
->sgotplt
)
335 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
336 if (htab
->srelgot
== NULL
337 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
338 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
339 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
341 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
346 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
347 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
351 elf32_arm_create_dynamic_sections (dynobj
, info
)
353 struct bfd_link_info
*info
;
355 struct elf32_arm_link_hash_table
*htab
;
357 htab
= elf32_arm_hash_table (info
);
358 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
361 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
364 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
365 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
366 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
368 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
370 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
371 || (!info
->shared
&& !htab
->srelbss
))
377 /* Copy the extra info we tack onto an elf_link_hash_entry. */
380 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
381 struct elf_link_hash_entry
*dir
,
382 struct elf_link_hash_entry
*ind
)
384 struct elf32_arm_link_hash_entry
*edir
, *eind
;
386 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
387 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
389 if (eind
->relocs_copied
!= NULL
)
391 if (edir
->relocs_copied
!= NULL
)
393 struct elf32_arm_relocs_copied
**pp
;
394 struct elf32_arm_relocs_copied
*p
;
396 if (ind
->root
.type
== bfd_link_hash_indirect
)
399 /* Add reloc counts against the weak sym to the strong sym
400 list. Merge any entries against the same section. */
401 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
403 struct elf32_arm_relocs_copied
*q
;
405 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
406 if (q
->section
== p
->section
)
408 q
->count
+= p
->count
;
415 *pp
= edir
->relocs_copied
;
418 edir
->relocs_copied
= eind
->relocs_copied
;
419 eind
->relocs_copied
= NULL
;
422 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
425 /* Create an ARM elf linker hash table. */
427 static struct bfd_link_hash_table
*
428 elf32_arm_link_hash_table_create (abfd
)
431 struct elf32_arm_link_hash_table
*ret
;
432 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
434 ret
= (struct elf32_arm_link_hash_table
*) bfd_malloc (amt
);
435 if (ret
== (struct elf32_arm_link_hash_table
*) NULL
)
438 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
439 elf32_arm_link_hash_newfunc
))
452 ret
->thumb_glue_size
= 0;
453 ret
->arm_glue_size
= 0;
454 ret
->bfd_of_glue_owner
= NULL
;
455 ret
->no_pipeline_knowledge
= 0;
456 ret
->byteswap_code
= 0;
457 ret
->sym_sec
.abfd
= NULL
;
459 return &ret
->root
.root
;
462 /* Locate the Thumb encoded calling stub for NAME. */
464 static struct elf_link_hash_entry
*
465 find_thumb_glue (link_info
, name
, input_bfd
)
466 struct bfd_link_info
*link_info
;
471 struct elf_link_hash_entry
*hash
;
472 struct elf32_arm_link_hash_table
*hash_table
;
474 /* We need a pointer to the armelf specific hash table. */
475 hash_table
= elf32_arm_hash_table (link_info
);
477 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
478 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
480 BFD_ASSERT (tmp_name
);
482 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
484 hash
= elf_link_hash_lookup
485 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
488 /* xgettext:c-format */
489 (*_bfd_error_handler
) (_("%s: unable to find THUMB glue '%s' for `%s'"),
490 bfd_archive_filename (input_bfd
), tmp_name
, name
);
497 /* Locate the ARM encoded calling stub for NAME. */
499 static struct elf_link_hash_entry
*
500 find_arm_glue (link_info
, name
, input_bfd
)
501 struct bfd_link_info
*link_info
;
506 struct elf_link_hash_entry
*myh
;
507 struct elf32_arm_link_hash_table
*hash_table
;
509 /* We need a pointer to the elfarm specific hash table. */
510 hash_table
= elf32_arm_hash_table (link_info
);
512 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
513 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
515 BFD_ASSERT (tmp_name
);
517 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
519 myh
= elf_link_hash_lookup
520 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
523 /* xgettext:c-format */
524 (*_bfd_error_handler
) (_("%s: unable to find ARM glue '%s' for `%s'"),
525 bfd_archive_filename (input_bfd
), tmp_name
, name
);
539 .word func @ behave as if you saw a ARM_32 reloc. */
541 #define ARM2THUMB_GLUE_SIZE 12
542 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
543 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
544 static const insn32 a2t3_func_addr_insn
= 0x00000001;
546 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
550 __func_from_thumb: __func_from_thumb:
552 nop ldr r6, __func_addr
554 __func_change_to_arm: bx r6
556 __func_back_to_thumb:
562 #define THUMB2ARM_GLUE_SIZE 8
563 static const insn16 t2a1_bx_pc_insn
= 0x4778;
564 static const insn16 t2a2_noop_insn
= 0x46c0;
565 static const insn32 t2a3_b_insn
= 0xea000000;
567 #ifndef ELFARM_NABI_C_INCLUDED
569 bfd_elf32_arm_allocate_interworking_sections (info
)
570 struct bfd_link_info
* info
;
574 struct elf32_arm_link_hash_table
* globals
;
576 globals
= elf32_arm_hash_table (info
);
578 BFD_ASSERT (globals
!= NULL
);
580 if (globals
->arm_glue_size
!= 0)
582 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
584 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
585 ARM2THUMB_GLUE_SECTION_NAME
);
587 BFD_ASSERT (s
!= NULL
);
589 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
590 globals
->arm_glue_size
);
592 s
->_raw_size
= s
->_cooked_size
= globals
->arm_glue_size
;
596 if (globals
->thumb_glue_size
!= 0)
598 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
600 s
= bfd_get_section_by_name
601 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
603 BFD_ASSERT (s
!= NULL
);
605 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
606 globals
->thumb_glue_size
);
608 s
->_raw_size
= s
->_cooked_size
= globals
->thumb_glue_size
;
616 record_arm_to_thumb_glue (link_info
, h
)
617 struct bfd_link_info
* link_info
;
618 struct elf_link_hash_entry
* h
;
620 const char * name
= h
->root
.root
.string
;
623 struct elf_link_hash_entry
* myh
;
624 struct bfd_link_hash_entry
* bh
;
625 struct elf32_arm_link_hash_table
* globals
;
628 globals
= elf32_arm_hash_table (link_info
);
630 BFD_ASSERT (globals
!= NULL
);
631 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
633 s
= bfd_get_section_by_name
634 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
636 BFD_ASSERT (s
!= NULL
);
638 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
639 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
641 BFD_ASSERT (tmp_name
);
643 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
645 myh
= elf_link_hash_lookup
646 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
650 /* We've already seen this guy. */
655 /* The only trick here is using hash_table->arm_glue_size as the value. Even
656 though the section isn't allocated yet, this is where we will be putting
659 val
= globals
->arm_glue_size
+ 1;
660 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
661 tmp_name
, BSF_GLOBAL
, s
, val
,
662 NULL
, TRUE
, FALSE
, &bh
);
666 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
672 record_thumb_to_arm_glue (link_info
, h
)
673 struct bfd_link_info
*link_info
;
674 struct elf_link_hash_entry
*h
;
676 const char *name
= h
->root
.root
.string
;
679 struct elf_link_hash_entry
*myh
;
680 struct bfd_link_hash_entry
*bh
;
681 struct elf32_arm_link_hash_table
*hash_table
;
685 hash_table
= elf32_arm_hash_table (link_info
);
687 BFD_ASSERT (hash_table
!= NULL
);
688 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
690 s
= bfd_get_section_by_name
691 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
693 BFD_ASSERT (s
!= NULL
);
695 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
696 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
698 BFD_ASSERT (tmp_name
);
700 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
702 myh
= elf_link_hash_lookup
703 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
707 /* We've already seen this guy. */
713 val
= hash_table
->thumb_glue_size
+ 1;
714 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
715 tmp_name
, BSF_GLOBAL
, s
, val
,
716 NULL
, TRUE
, FALSE
, &bh
);
718 /* If we mark it 'Thumb', the disassembler will do a better job. */
719 myh
= (struct elf_link_hash_entry
*) bh
;
720 bind
= ELF_ST_BIND (myh
->type
);
721 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
725 #define CHANGE_TO_ARM "__%s_change_to_arm"
726 #define BACK_FROM_ARM "__%s_back_from_arm"
728 /* Allocate another symbol to mark where we switch to Arm mode. */
729 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
730 + strlen (CHANGE_TO_ARM
) + 1);
732 BFD_ASSERT (tmp_name
);
734 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
737 val
= hash_table
->thumb_glue_size
+ 4,
738 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
739 tmp_name
, BSF_LOCAL
, s
, val
,
740 NULL
, TRUE
, FALSE
, &bh
);
744 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
749 /* Add the glue sections to ABFD. This function is called from the
750 linker scripts in ld/emultempl/{armelf}.em. */
753 bfd_elf32_arm_add_glue_sections_to_bfd (abfd
, info
)
755 struct bfd_link_info
*info
;
760 /* If we are only performing a partial
761 link do not bother adding the glue. */
762 if (info
->relocatable
)
765 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
769 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
770 will prevent elf_link_input_bfd() from processing the contents
772 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
774 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
777 || !bfd_set_section_flags (abfd
, sec
, flags
)
778 || !bfd_set_section_alignment (abfd
, sec
, 2))
781 /* Set the gc mark to prevent the section from being removed by garbage
782 collection, despite the fact that no relocs refer to this section. */
786 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
790 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
792 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
795 || !bfd_set_section_flags (abfd
, sec
, flags
)
796 || !bfd_set_section_alignment (abfd
, sec
, 2))
805 /* Select a BFD to be used to hold the sections used by the glue code.
806 This function is called from the linker scripts in ld/emultempl/
810 bfd_elf32_arm_get_bfd_for_interworking (abfd
, info
)
812 struct bfd_link_info
*info
;
814 struct elf32_arm_link_hash_table
*globals
;
816 /* If we are only performing a partial link
817 do not bother getting a bfd to hold the glue. */
818 if (info
->relocatable
)
821 globals
= elf32_arm_hash_table (info
);
823 BFD_ASSERT (globals
!= NULL
);
825 if (globals
->bfd_of_glue_owner
!= NULL
)
828 /* Save the bfd for later use. */
829 globals
->bfd_of_glue_owner
= abfd
;
835 bfd_elf32_arm_process_before_allocation (abfd
, link_info
,
836 no_pipeline_knowledge
,
839 struct bfd_link_info
*link_info
;
840 int no_pipeline_knowledge
;
843 Elf_Internal_Shdr
*symtab_hdr
;
844 Elf_Internal_Rela
*internal_relocs
= NULL
;
845 Elf_Internal_Rela
*irel
, *irelend
;
846 bfd_byte
*contents
= NULL
;
849 struct elf32_arm_link_hash_table
*globals
;
851 /* If we are only performing a partial link do not bother
852 to construct any glue. */
853 if (link_info
->relocatable
)
856 /* Here we have a bfd that is to be included on the link. We have a hook
857 to do reloc rummaging, before section sizes are nailed down. */
858 globals
= elf32_arm_hash_table (link_info
);
860 BFD_ASSERT (globals
!= NULL
);
861 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
863 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
864 if (byteswap_code
&& !bfd_big_endian (abfd
))
867 _("%s: BE8 images only valid in big-endian mode."),
868 bfd_archive_filename (abfd
));
871 globals
->byteswap_code
= byteswap_code
;
873 /* Rummage around all the relocs and map the glue vectors. */
874 sec
= abfd
->sections
;
879 for (; sec
!= NULL
; sec
= sec
->next
)
881 if (sec
->reloc_count
== 0)
884 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
886 /* Load the relocs. */
888 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
889 (Elf_Internal_Rela
*) NULL
, FALSE
);
891 if (internal_relocs
== NULL
)
894 irelend
= internal_relocs
+ sec
->reloc_count
;
895 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
898 unsigned long r_index
;
900 struct elf_link_hash_entry
*h
;
902 r_type
= ELF32_R_TYPE (irel
->r_info
);
903 r_index
= ELF32_R_SYM (irel
->r_info
);
905 /* These are the only relocation types we care about. */
906 if ( r_type
!= R_ARM_PC24
907 && r_type
!= R_ARM_THM_PC22
)
910 /* Get the section contents if we haven't done so already. */
911 if (contents
== NULL
)
913 /* Get cached copy if it exists. */
914 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
915 contents
= elf_section_data (sec
)->this_hdr
.contents
;
918 /* Go get them off disk. */
919 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
920 if (contents
== NULL
)
923 if (!bfd_get_section_contents (abfd
, sec
, contents
,
924 (file_ptr
) 0, sec
->_raw_size
))
929 /* If the relocation is not against a symbol it cannot concern us. */
932 /* We don't care about local symbols. */
933 if (r_index
< symtab_hdr
->sh_info
)
936 /* This is an external symbol. */
937 r_index
-= symtab_hdr
->sh_info
;
938 h
= (struct elf_link_hash_entry
*)
939 elf_sym_hashes (abfd
)[r_index
];
941 /* If the relocation is against a static symbol it must be within
942 the current section and so cannot be a cross ARM/Thumb relocation. */
949 /* This one is a call from arm code. We need to look up
950 the target of the call. If it is a thumb target, we
952 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
953 record_arm_to_thumb_glue (link_info
, h
);
957 /* This one is a call from thumb code. We look
958 up the target of the call. If it is not a thumb
959 target, we insert glue. */
960 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
961 record_thumb_to_arm_glue (link_info
, h
);
970 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
974 if (internal_relocs
!= NULL
975 && elf_section_data (sec
)->relocs
!= internal_relocs
)
976 free (internal_relocs
);
977 internal_relocs
= NULL
;
984 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
986 if (internal_relocs
!= NULL
987 && elf_section_data (sec
)->relocs
!= internal_relocs
)
988 free (internal_relocs
);
994 /* The thumb form of a long branch is a bit finicky, because the offset
995 encoding is split over two fields, each in it's own instruction. They
996 can occur in any order. So given a thumb form of long branch, and an
997 offset, insert the offset into the thumb branch and return finished
1000 It takes two thumb instructions to encode the target address. Each has
1001 11 bits to invest. The upper 11 bits are stored in one (identified by
1002 H-0.. see below), the lower 11 bits are stored in the other (identified
1005 Combine together and shifted left by 1 (it's a half word address) and
1009 H-0, upper address-0 = 000
1011 H-1, lower address-0 = 800
1013 They can be ordered either way, but the arm tools I've seen always put
1014 the lower one first. It probably doesn't matter. krk@cygnus.com
1016 XXX: Actually the order does matter. The second instruction (H-1)
1017 moves the computed address into the PC, so it must be the second one
1018 in the sequence. The problem, however is that whilst little endian code
1019 stores the instructions in HI then LOW order, big endian code does the
1020 reverse. nickc@cygnus.com. */
1022 #define LOW_HI_ORDER 0xF800F000
1023 #define HI_LOW_ORDER 0xF000F800
1026 insert_thumb_branch (br_insn
, rel_off
)
1030 unsigned int low_bits
;
1031 unsigned int high_bits
;
1033 BFD_ASSERT ((rel_off
& 1) != 1);
1035 rel_off
>>= 1; /* Half word aligned address. */
1036 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
1037 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
1039 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
1040 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
1041 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
1042 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
1044 /* FIXME: abort is probably not the right call. krk@cygnus.com */
1045 abort (); /* error - not a valid branch instruction form. */
1050 /* Thumb code calling an ARM function. */
1053 elf32_thumb_to_arm_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1054 hit_data
, sym_sec
, offset
, addend
, val
)
1055 struct bfd_link_info
* info
;
1059 asection
* input_section
;
1060 bfd_byte
* hit_data
;
1063 bfd_signed_vma addend
;
1068 unsigned long int tmp
;
1069 long int ret_offset
;
1070 struct elf_link_hash_entry
* myh
;
1071 struct elf32_arm_link_hash_table
* globals
;
1073 myh
= find_thumb_glue (info
, name
, input_bfd
);
1077 globals
= elf32_arm_hash_table (info
);
1079 BFD_ASSERT (globals
!= NULL
);
1080 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1082 my_offset
= myh
->root
.u
.def
.value
;
1084 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1085 THUMB2ARM_GLUE_SECTION_NAME
);
1087 BFD_ASSERT (s
!= NULL
);
1088 BFD_ASSERT (s
->contents
!= NULL
);
1089 BFD_ASSERT (s
->output_section
!= NULL
);
1091 if ((my_offset
& 0x01) == 0x01)
1094 && sym_sec
->owner
!= NULL
1095 && !INTERWORK_FLAG (sym_sec
->owner
))
1097 (*_bfd_error_handler
)
1098 (_("%s(%s): warning: interworking not enabled."),
1099 bfd_archive_filename (sym_sec
->owner
), name
);
1100 (*_bfd_error_handler
)
1101 (_(" first occurrence: %s: thumb call to arm"),
1102 bfd_archive_filename (input_bfd
));
1108 myh
->root
.u
.def
.value
= my_offset
;
1110 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
1111 s
->contents
+ my_offset
);
1113 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
1114 s
->contents
+ my_offset
+ 2);
1117 /* Address of destination of the stub. */
1118 ((bfd_signed_vma
) val
)
1120 /* Offset from the start of the current section to the start of the stubs. */
1122 /* Offset of the start of this stub from the start of the stubs. */
1124 /* Address of the start of the current section. */
1125 + s
->output_section
->vma
)
1126 /* The branch instruction is 4 bytes into the stub. */
1128 /* ARM branches work from the pc of the instruction + 8. */
1131 bfd_put_32 (output_bfd
,
1132 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1133 s
->contents
+ my_offset
+ 4);
1136 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
1138 /* Now go back and fix up the original BL insn to point to here. */
1140 /* Address of where the stub is located. */
1141 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
1142 /* Address of where the BL is located. */
1143 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ offset
)
1144 /* Addend in the relocation. */
1146 /* Biassing for PC-relative addressing. */
1149 tmp
= bfd_get_32 (input_bfd
, hit_data
1150 - input_section
->vma
);
1152 bfd_put_32 (output_bfd
,
1153 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1154 hit_data
- input_section
->vma
);
1159 /* Arm code calling a Thumb function. */
1162 elf32_arm_to_thumb_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1163 hit_data
, sym_sec
, offset
, addend
, val
)
1164 struct bfd_link_info
* info
;
1168 asection
* input_section
;
1169 bfd_byte
* hit_data
;
1172 bfd_signed_vma addend
;
1175 unsigned long int tmp
;
1178 long int ret_offset
;
1179 struct elf_link_hash_entry
* myh
;
1180 struct elf32_arm_link_hash_table
* globals
;
1182 myh
= find_arm_glue (info
, name
, input_bfd
);
1186 globals
= elf32_arm_hash_table (info
);
1188 BFD_ASSERT (globals
!= NULL
);
1189 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1191 my_offset
= myh
->root
.u
.def
.value
;
1192 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1193 ARM2THUMB_GLUE_SECTION_NAME
);
1194 BFD_ASSERT (s
!= NULL
);
1195 BFD_ASSERT (s
->contents
!= NULL
);
1196 BFD_ASSERT (s
->output_section
!= NULL
);
1198 if ((my_offset
& 0x01) == 0x01)
1201 && sym_sec
->owner
!= NULL
1202 && !INTERWORK_FLAG (sym_sec
->owner
))
1204 (*_bfd_error_handler
)
1205 (_("%s(%s): warning: interworking not enabled."),
1206 bfd_archive_filename (sym_sec
->owner
), name
);
1207 (*_bfd_error_handler
)
1208 (_(" first occurrence: %s: arm call to thumb"),
1209 bfd_archive_filename (input_bfd
));
1213 myh
->root
.u
.def
.value
= my_offset
;
1215 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1216 s
->contents
+ my_offset
);
1218 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1219 s
->contents
+ my_offset
+ 4);
1221 /* It's a thumb address. Add the low order bit. */
1222 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1223 s
->contents
+ my_offset
+ 8);
1226 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1228 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1229 tmp
= tmp
& 0xFF000000;
1231 /* Somehow these are both 4 too far, so subtract 8. */
1232 ret_offset
= (s
->output_offset
1234 + s
->output_section
->vma
1235 - (input_section
->output_offset
1236 + input_section
->output_section
->vma
1240 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1242 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1247 /* Perform a relocation as part of a final link. */
1249 static bfd_reloc_status_type
1250 elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
1251 input_section
, contents
, rel
, value
,
1252 info
, sym_sec
, sym_name
, sym_flags
, h
)
1253 reloc_howto_type
* howto
;
1256 asection
* input_section
;
1257 bfd_byte
* contents
;
1258 Elf_Internal_Rela
* rel
;
1260 struct bfd_link_info
* info
;
1262 const char * sym_name
;
1264 struct elf_link_hash_entry
* h
;
1266 unsigned long r_type
= howto
->type
;
1267 unsigned long r_symndx
;
1268 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1269 bfd
* dynobj
= NULL
;
1270 Elf_Internal_Shdr
* symtab_hdr
;
1271 struct elf_link_hash_entry
** sym_hashes
;
1272 bfd_vma
* local_got_offsets
;
1273 asection
* sgot
= NULL
;
1274 asection
* splt
= NULL
;
1275 asection
* sreloc
= NULL
;
1277 bfd_signed_vma signed_addend
;
1278 struct elf32_arm_link_hash_table
* globals
;
1280 /* If the start address has been set, then set the EF_ARM_HASENTRY
1281 flag. Setting this more than once is redundant, but the cost is
1282 not too high, and it keeps the code simple.
1284 The test is done here, rather than somewhere else, because the
1285 start address is only set just before the final link commences.
1287 Note - if the user deliberately sets a start address of 0, the
1288 flag will not be set. */
1289 if (bfd_get_start_address (output_bfd
) != 0)
1290 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1292 globals
= elf32_arm_hash_table (info
);
1294 dynobj
= elf_hash_table (info
)->dynobj
;
1297 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1298 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1300 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1301 sym_hashes
= elf_sym_hashes (input_bfd
);
1302 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1303 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1306 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1308 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1311 signed_addend
&= ~ howto
->src_mask
;
1312 signed_addend
|= addend
;
1315 signed_addend
= addend
;
1317 addend
= signed_addend
= rel
->r_addend
;
1323 return bfd_reloc_ok
;
1332 /* r_symndx will be zero only for relocs against symbols
1333 from removed linkonce sections, or sections discarded by
1336 return bfd_reloc_ok
;
1338 /* Handle relocations which should use the PLT entry. ABS32/REL32
1339 will use the symbol's value, which may point to a PLT entry, but we
1340 don't need to handle that here. If we created a PLT entry, all
1341 branches in this object should go to it. */
1342 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
1345 && h
->plt
.offset
!= (bfd_vma
) -1)
1347 /* If we've created a .plt section, and assigned a PLT entry to
1348 this function, it should not be known to bind locally. If
1349 it were, we would have cleared the PLT entry. */
1350 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
1352 value
= (splt
->output_section
->vma
1353 + splt
->output_offset
1355 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1356 contents
, rel
->r_offset
, value
,
1360 /* When generating a shared object, these relocations are copied
1361 into the output file to be resolved at run time. */
1363 && (input_section
->flags
& SEC_ALLOC
)
1364 && (r_type
!= R_ARM_REL32
1365 || !SYMBOL_CALLS_LOCAL (info
, h
))
1367 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1368 || h
->root
.type
!= bfd_link_hash_undefweak
)
1369 && r_type
!= R_ARM_PC24
1370 && r_type
!= R_ARM_PLT32
)
1372 Elf_Internal_Rela outrel
;
1374 bfd_boolean skip
, relocate
;
1380 name
= (bfd_elf_string_from_elf_section
1382 elf_elfheader (input_bfd
)->e_shstrndx
,
1383 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1385 return bfd_reloc_notsupported
;
1387 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1388 && strcmp (bfd_get_section_name (input_bfd
,
1392 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1393 BFD_ASSERT (sreloc
!= NULL
);
1400 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1402 if (outrel
.r_offset
== (bfd_vma
) -1)
1404 else if (outrel
.r_offset
== (bfd_vma
) -2)
1405 skip
= TRUE
, relocate
= TRUE
;
1406 outrel
.r_offset
+= (input_section
->output_section
->vma
1407 + input_section
->output_offset
);
1410 memset (&outrel
, 0, sizeof outrel
);
1415 || (h
->elf_link_hash_flags
1416 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1417 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1420 /* This symbol is local, or marked to become local. */
1422 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1425 loc
= sreloc
->contents
;
1426 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1427 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1429 /* If this reloc is against an external symbol, we do not want to
1430 fiddle with the addend. Otherwise, we need to include the symbol
1431 value so that it becomes an addend for the dynamic reloc. */
1433 return bfd_reloc_ok
;
1435 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1436 contents
, rel
->r_offset
, value
,
1439 else switch (r_type
)
1442 case R_ARM_XPC25
: /* Arm BLX instruction. */
1444 case R_ARM_PC24
: /* Arm B/BL instruction */
1447 if (r_type
== R_ARM_XPC25
)
1449 /* Check for Arm calling Arm function. */
1450 /* FIXME: Should we translate the instruction into a BL
1451 instruction instead ? */
1452 if (sym_flags
!= STT_ARM_TFUNC
)
1453 (*_bfd_error_handler
) (_("\
1454 %s: Warning: Arm BLX instruction targets Arm function '%s'."),
1455 bfd_archive_filename (input_bfd
),
1456 h
? h
->root
.root
.string
: "(local)");
1461 /* Check for Arm calling Thumb function. */
1462 if (sym_flags
== STT_ARM_TFUNC
)
1464 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
, output_bfd
,
1465 input_section
, hit_data
, sym_sec
, rel
->r_offset
,
1466 signed_addend
, value
);
1467 return bfd_reloc_ok
;
1471 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1472 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1474 /* The old way of doing things. Trearing the addend as a
1475 byte sized field and adding in the pipeline offset. */
1476 value
-= (input_section
->output_section
->vma
1477 + input_section
->output_offset
);
1478 value
-= rel
->r_offset
;
1481 if (! globals
->no_pipeline_knowledge
)
1486 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1488 S is the address of the symbol in the relocation.
1489 P is address of the instruction being relocated.
1490 A is the addend (extracted from the instruction) in bytes.
1492 S is held in 'value'.
1493 P is the base address of the section containing the instruction
1494 plus the offset of the reloc into that section, ie:
1495 (input_section->output_section->vma +
1496 input_section->output_offset +
1498 A is the addend, converted into bytes, ie:
1501 Note: None of these operations have knowledge of the pipeline
1502 size of the processor, thus it is up to the assembler to encode
1503 this information into the addend. */
1504 value
-= (input_section
->output_section
->vma
1505 + input_section
->output_offset
);
1506 value
-= rel
->r_offset
;
1507 value
+= (signed_addend
<< howto
->size
);
1509 /* Previous versions of this code also used to add in the pipeline
1510 offset here. This is wrong because the linker is not supposed
1511 to know about such things, and one day it might change. In order
1512 to support old binaries that need the old behaviour however, so
1513 we attempt to detect which ABI was used to create the reloc. */
1514 if (! globals
->no_pipeline_knowledge
)
1516 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1518 i_ehdrp
= elf_elfheader (input_bfd
);
1520 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1525 signed_addend
= value
;
1526 signed_addend
>>= howto
->rightshift
;
1528 /* It is not an error for an undefined weak reference to be
1529 out of range. Any program that branches to such a symbol
1530 is going to crash anyway, so there is no point worrying
1531 about getting the destination exactly right. */
1532 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1534 /* Perform a signed range check. */
1535 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1536 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1537 return bfd_reloc_overflow
;
1541 /* If necessary set the H bit in the BLX instruction. */
1542 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1543 value
= (signed_addend
& howto
->dst_mask
)
1544 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1548 value
= (signed_addend
& howto
->dst_mask
)
1549 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1554 if (sym_flags
== STT_ARM_TFUNC
)
1559 value
-= (input_section
->output_section
->vma
1560 + input_section
->output_offset
+ rel
->r_offset
);
1565 bfd_put_32 (input_bfd
, value
, hit_data
);
1566 return bfd_reloc_ok
;
1570 if ((long) value
> 0x7f || (long) value
< -0x80)
1571 return bfd_reloc_overflow
;
1573 bfd_put_8 (input_bfd
, value
, hit_data
);
1574 return bfd_reloc_ok
;
1579 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1580 return bfd_reloc_overflow
;
1582 bfd_put_16 (input_bfd
, value
, hit_data
);
1583 return bfd_reloc_ok
;
1586 /* Support ldr and str instruction for the arm */
1587 /* Also thumb b (unconditional branch). ??? Really? */
1590 if ((long) value
> 0x7ff || (long) value
< -0x800)
1591 return bfd_reloc_overflow
;
1593 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1594 bfd_put_32 (input_bfd
, value
, hit_data
);
1595 return bfd_reloc_ok
;
1597 case R_ARM_THM_ABS5
:
1598 /* Support ldr and str instructions for the thumb. */
1600 /* Need to refetch addend. */
1601 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1602 /* ??? Need to determine shift amount from operand size. */
1603 addend
>>= howto
->rightshift
;
1607 /* ??? Isn't value unsigned? */
1608 if ((long) value
> 0x1f || (long) value
< -0x10)
1609 return bfd_reloc_overflow
;
1611 /* ??? Value needs to be properly shifted into place first. */
1612 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1613 bfd_put_16 (input_bfd
, value
, hit_data
);
1614 return bfd_reloc_ok
;
1617 case R_ARM_THM_XPC22
:
1619 case R_ARM_THM_PC22
:
1620 /* Thumb BL (branch long instruction). */
1623 bfd_boolean overflow
= FALSE
;
1624 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1625 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1626 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1627 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1629 bfd_signed_vma signed_check
;
1632 /* Need to refetch the addend and squish the two 11 bit pieces
1635 bfd_vma upper
= upper_insn
& 0x7ff;
1636 bfd_vma lower
= lower_insn
& 0x7ff;
1637 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1638 addend
= (upper
<< 12) | (lower
<< 1);
1639 signed_addend
= addend
;
1643 if (r_type
== R_ARM_THM_XPC22
)
1645 /* Check for Thumb to Thumb call. */
1646 /* FIXME: Should we translate the instruction into a BL
1647 instruction instead ? */
1648 if (sym_flags
== STT_ARM_TFUNC
)
1649 (*_bfd_error_handler
) (_("\
1650 %s: Warning: Thumb BLX instruction targets thumb function '%s'."),
1651 bfd_archive_filename (input_bfd
),
1652 h
? h
->root
.root
.string
: "(local)");
1657 /* If it is not a call to Thumb, assume call to Arm.
1658 If it is a call relative to a section name, then it is not a
1659 function call at all, but rather a long jump. */
1660 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1662 if (elf32_thumb_to_arm_stub
1663 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1664 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1665 return bfd_reloc_ok
;
1667 return bfd_reloc_dangerous
;
1671 relocation
= value
+ signed_addend
;
1673 relocation
-= (input_section
->output_section
->vma
1674 + input_section
->output_offset
1677 if (! globals
->no_pipeline_knowledge
)
1679 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1681 i_ehdrp
= elf_elfheader (input_bfd
);
1683 /* Previous versions of this code also used to add in the pipline
1684 offset here. This is wrong because the linker is not supposed
1685 to know about such things, and one day it might change. In order
1686 to support old binaries that need the old behaviour however, so
1687 we attempt to detect which ABI was used to create the reloc. */
1688 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1689 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1690 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1694 check
= relocation
>> howto
->rightshift
;
1696 /* If this is a signed value, the rightshift just dropped
1697 leading 1 bits (assuming twos complement). */
1698 if ((bfd_signed_vma
) relocation
>= 0)
1699 signed_check
= check
;
1701 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1703 /* Assumes two's complement. */
1704 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1708 if (r_type
== R_ARM_THM_XPC22
1709 && ((lower_insn
& 0x1800) == 0x0800))
1710 /* For a BLX instruction, make sure that the relocation is rounded up
1711 to a word boundary. This follows the semantics of the instruction
1712 which specifies that bit 1 of the target address will come from bit
1713 1 of the base address. */
1714 relocation
= (relocation
+ 2) & ~ 3;
1716 /* Put RELOCATION back into the insn. */
1717 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1718 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1720 /* Put the relocated value back in the object file: */
1721 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1722 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1724 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1728 case R_ARM_THM_PC11
:
1729 /* Thumb B (branch) instruction). */
1731 bfd_signed_vma relocation
;
1732 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1733 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1734 bfd_signed_vma signed_check
;
1737 /* Need to refetch addend. */
1738 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1739 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1742 signed_addend
&= ~ howto
->src_mask
;
1743 signed_addend
|= addend
;
1746 signed_addend
= addend
;
1747 /* The value in the insn has been right shifted. We need to
1748 undo this, so that we can perform the address calculation
1749 in terms of bytes. */
1750 signed_addend
<<= howto
->rightshift
;
1752 relocation
= value
+ signed_addend
;
1754 relocation
-= (input_section
->output_section
->vma
1755 + input_section
->output_offset
1758 relocation
>>= howto
->rightshift
;
1759 signed_check
= relocation
;
1760 relocation
&= howto
->dst_mask
;
1761 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1763 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1765 /* Assumes two's complement. */
1766 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1767 return bfd_reloc_overflow
;
1769 return bfd_reloc_ok
;
1773 case R_ARM_ALU_PCREL7_0
:
1774 case R_ARM_ALU_PCREL15_8
:
1775 case R_ARM_ALU_PCREL23_15
:
1780 insn
= bfd_get_32 (input_bfd
, hit_data
);
1782 /* Extract the addend. */
1783 addend
= (insn
& 0xff) << ((insn
& 0xf00) >> 7);
1784 signed_addend
= addend
;
1786 relocation
= value
+ signed_addend
;
1788 relocation
-= (input_section
->output_section
->vma
1789 + input_section
->output_offset
1791 insn
= (insn
& ~0xfff)
1792 | ((howto
->bitpos
<< 7) & 0xf00)
1793 | ((relocation
>> howto
->bitpos
) & 0xff);
1794 bfd_put_32 (input_bfd
, value
, hit_data
);
1796 return bfd_reloc_ok
;
1799 case R_ARM_GNU_VTINHERIT
:
1800 case R_ARM_GNU_VTENTRY
:
1801 return bfd_reloc_ok
;
1804 return bfd_reloc_notsupported
;
1806 case R_ARM_GLOB_DAT
:
1807 return bfd_reloc_notsupported
;
1809 case R_ARM_JUMP_SLOT
:
1810 return bfd_reloc_notsupported
;
1812 case R_ARM_RELATIVE
:
1813 return bfd_reloc_notsupported
;
1816 /* Relocation is relative to the start of the
1817 global offset table. */
1819 BFD_ASSERT (sgot
!= NULL
);
1821 return bfd_reloc_notsupported
;
1823 /* If we are addressing a Thumb function, we need to adjust the
1824 address by one, so that attempts to call the function pointer will
1825 correctly interpret it as Thumb code. */
1826 if (sym_flags
== STT_ARM_TFUNC
)
1829 /* Note that sgot->output_offset is not involved in this
1830 calculation. We always want the start of .got. If we
1831 define _GLOBAL_OFFSET_TABLE in a different way, as is
1832 permitted by the ABI, we might have to change this
1834 value
-= sgot
->output_section
->vma
;
1835 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1836 contents
, rel
->r_offset
, value
,
1840 /* Use global offset table as symbol value. */
1841 BFD_ASSERT (sgot
!= NULL
);
1844 return bfd_reloc_notsupported
;
1846 value
= sgot
->output_section
->vma
;
1847 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1848 contents
, rel
->r_offset
, value
,
1852 /* Relocation is to the entry for this symbol in the
1853 global offset table. */
1855 return bfd_reloc_notsupported
;
1862 off
= h
->got
.offset
;
1863 BFD_ASSERT (off
!= (bfd_vma
) -1);
1864 dyn
= globals
->root
.dynamic_sections_created
;
1866 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1868 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1869 || (ELF_ST_VISIBILITY (h
->other
)
1870 && h
->root
.type
== bfd_link_hash_undefweak
))
1872 /* This is actually a static link, or it is a -Bsymbolic link
1873 and the symbol is defined locally. We must initialize this
1874 entry in the global offset table. Since the offset must
1875 always be a multiple of 4, we use the least significant bit
1876 to record whether we have initialized it already.
1878 When doing a dynamic link, we create a .rel.got relocation
1879 entry to initialize the value. This is done in the
1880 finish_dynamic_symbol routine. */
1885 /* If we are addressing a Thumb function, we need to
1886 adjust the address by one, so that attempts to
1887 call the function pointer will correctly
1888 interpret it as Thumb code. */
1889 if (sym_flags
== STT_ARM_TFUNC
)
1892 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1897 value
= sgot
->output_offset
+ off
;
1903 BFD_ASSERT (local_got_offsets
!= NULL
&&
1904 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1906 off
= local_got_offsets
[r_symndx
];
1908 /* The offset must always be a multiple of 4. We use the
1909 least significant bit to record whether we have already
1910 generated the necessary reloc. */
1915 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1920 Elf_Internal_Rela outrel
;
1923 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1924 BFD_ASSERT (srelgot
!= NULL
);
1926 outrel
.r_offset
= (sgot
->output_section
->vma
1927 + sgot
->output_offset
1929 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1930 loc
= srelgot
->contents
;
1931 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1932 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1935 local_got_offsets
[r_symndx
] |= 1;
1938 value
= sgot
->output_offset
+ off
;
1941 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1942 contents
, rel
->r_offset
, value
,
1946 return bfd_reloc_notsupported
;
1948 case R_ARM_AMP_VCALL9
:
1949 return bfd_reloc_notsupported
;
1951 case R_ARM_RSBREL32
:
1952 return bfd_reloc_notsupported
;
1954 case R_ARM_THM_RPC22
:
1955 return bfd_reloc_notsupported
;
1958 return bfd_reloc_notsupported
;
1961 return bfd_reloc_notsupported
;
1964 return bfd_reloc_notsupported
;
1967 return bfd_reloc_notsupported
;
1970 return bfd_reloc_notsupported
;
1975 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1977 arm_add_to_rel (abfd
, address
, howto
, increment
)
1980 reloc_howto_type
* howto
;
1981 bfd_signed_vma increment
;
1983 bfd_signed_vma addend
;
1985 if (howto
->type
== R_ARM_THM_PC22
)
1987 int upper_insn
, lower_insn
;
1990 upper_insn
= bfd_get_16 (abfd
, address
);
1991 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1992 upper
= upper_insn
& 0x7ff;
1993 lower
= lower_insn
& 0x7ff;
1995 addend
= (upper
<< 12) | (lower
<< 1);
1996 addend
+= increment
;
1999 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
2000 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
2002 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
2003 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
2009 contents
= bfd_get_32 (abfd
, address
);
2011 /* Get the (signed) value from the instruction. */
2012 addend
= contents
& howto
->src_mask
;
2013 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2015 bfd_signed_vma mask
;
2018 mask
&= ~ howto
->src_mask
;
2022 /* Add in the increment, (which is a byte value). */
2023 switch (howto
->type
)
2026 addend
+= increment
;
2030 addend
<<= howto
->size
;
2031 addend
+= increment
;
2033 /* Should we check for overflow here ? */
2035 /* Drop any undesired bits. */
2036 addend
>>= howto
->rightshift
;
2040 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2042 bfd_put_32 (abfd
, contents
, address
);
2045 #endif /* USE_REL */
2047 /* Relocate an ARM ELF section. */
2049 elf32_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2050 contents
, relocs
, local_syms
, local_sections
)
2052 struct bfd_link_info
*info
;
2054 asection
*input_section
;
2056 Elf_Internal_Rela
*relocs
;
2057 Elf_Internal_Sym
*local_syms
;
2058 asection
**local_sections
;
2060 Elf_Internal_Shdr
*symtab_hdr
;
2061 struct elf_link_hash_entry
**sym_hashes
;
2062 Elf_Internal_Rela
*rel
;
2063 Elf_Internal_Rela
*relend
;
2067 if (info
->relocatable
)
2071 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2072 sym_hashes
= elf_sym_hashes (input_bfd
);
2075 relend
= relocs
+ input_section
->reloc_count
;
2076 for (; rel
< relend
; rel
++)
2079 reloc_howto_type
* howto
;
2080 unsigned long r_symndx
;
2081 Elf_Internal_Sym
* sym
;
2083 struct elf_link_hash_entry
* h
;
2085 bfd_reloc_status_type r
;
2088 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2089 r_type
= ELF32_R_TYPE (rel
->r_info
);
2091 if ( r_type
== R_ARM_GNU_VTENTRY
2092 || r_type
== R_ARM_GNU_VTINHERIT
)
2095 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
2096 howto
= bfd_reloc
.howto
;
2099 if (info
->relocatable
)
2101 /* This is a relocatable link. We don't have to change
2102 anything, unless the reloc is against a section symbol,
2103 in which case we have to adjust according to where the
2104 section symbol winds up in the output section. */
2105 if (r_symndx
< symtab_hdr
->sh_info
)
2107 sym
= local_syms
+ r_symndx
;
2108 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2110 sec
= local_sections
[r_symndx
];
2111 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2113 (bfd_signed_vma
) (sec
->output_offset
2122 /* This is a final link. */
2127 if (r_symndx
< symtab_hdr
->sh_info
)
2129 sym
= local_syms
+ r_symndx
;
2130 sec
= local_sections
[r_symndx
];
2132 relocation
= (sec
->output_section
->vma
2133 + sec
->output_offset
2135 if ((sec
->flags
& SEC_MERGE
)
2136 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2139 bfd_vma addend
, value
;
2141 if (howto
->rightshift
)
2143 (*_bfd_error_handler
)
2144 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
2145 bfd_archive_filename (input_bfd
),
2146 bfd_get_section_name (input_bfd
, input_section
),
2147 (long) rel
->r_offset
, howto
->name
);
2151 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2153 /* Get the (signed) value from the instruction. */
2154 addend
= value
& howto
->src_mask
;
2155 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2157 bfd_signed_vma mask
;
2160 mask
&= ~ howto
->src_mask
;
2165 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2167 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2168 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2169 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2172 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2178 bfd_boolean unresolved_reloc
;
2180 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2181 r_symndx
, symtab_hdr
, sym_hashes
,
2183 unresolved_reloc
, warned
);
2185 if (unresolved_reloc
|| relocation
!= 0)
2187 /* In these cases, we don't need the relocation value.
2188 We check specially because in some obscure cases
2189 sec->output_section will be NULL. */
2194 case R_ARM_THM_PC22
:
2197 (!info
->symbolic
&& h
->dynindx
!= -1)
2198 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2200 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2201 && ((input_section
->flags
& SEC_ALLOC
) != 0
2202 /* DWARF will emit R_ARM_ABS32 relocations in its
2203 sections against symbols defined externally
2204 in shared libraries. We can't do anything
2206 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2207 && (h
->elf_link_hash_flags
2208 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2218 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
2219 (elf_hash_table (info
)->dynamic_sections_created
,
2222 || (!info
->symbolic
&& h
->dynindx
!= -1)
2223 || (h
->elf_link_hash_flags
2224 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2229 if (h
->plt
.offset
!= (bfd_vma
)-1)
2234 if (unresolved_reloc
)
2236 (_("%s: warning: unresolvable relocation %d against symbol `%s' from %s section"),
2237 bfd_archive_filename (input_bfd
),
2239 h
->root
.root
.string
,
2240 bfd_get_section_name (input_bfd
, input_section
));
2247 name
= h
->root
.root
.string
;
2250 name
= (bfd_elf_string_from_elf_section
2251 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2252 if (name
== NULL
|| *name
== '\0')
2253 name
= bfd_section_name (input_bfd
, sec
);
2256 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2257 input_section
, contents
, rel
,
2258 relocation
, info
, sec
, name
,
2259 (h
? ELF_ST_TYPE (h
->type
) :
2260 ELF_ST_TYPE (sym
->st_info
)), h
);
2262 if (r
!= bfd_reloc_ok
)
2264 const char * msg
= (const char *) 0;
2268 case bfd_reloc_overflow
:
2269 /* If the overflowing reloc was to an undefined symbol,
2270 we have already printed one error message and there
2271 is no point complaining again. */
2273 h
->root
.type
!= bfd_link_hash_undefined
)
2274 && (!((*info
->callbacks
->reloc_overflow
)
2275 (info
, name
, howto
->name
, (bfd_vma
) 0,
2276 input_bfd
, input_section
, rel
->r_offset
))))
2280 case bfd_reloc_undefined
:
2281 if (!((*info
->callbacks
->undefined_symbol
)
2282 (info
, name
, input_bfd
, input_section
,
2283 rel
->r_offset
, TRUE
)))
2287 case bfd_reloc_outofrange
:
2288 msg
= _("internal error: out of range error");
2291 case bfd_reloc_notsupported
:
2292 msg
= _("internal error: unsupported relocation error");
2295 case bfd_reloc_dangerous
:
2296 msg
= _("internal error: dangerous error");
2300 msg
= _("internal error: unknown error");
2304 if (!((*info
->callbacks
->warning
)
2305 (info
, msg
, name
, input_bfd
, input_section
,
2316 /* Set the right machine number. */
2319 elf32_arm_object_p (abfd
)
2324 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2326 if (mach
!= bfd_mach_arm_unknown
)
2327 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2329 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
2330 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
2333 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2338 /* Function to keep ARM specific flags in the ELF header. */
2340 elf32_arm_set_private_flags (abfd
, flags
)
2344 if (elf_flags_init (abfd
)
2345 && elf_elfheader (abfd
)->e_flags
!= flags
)
2347 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2349 if (flags
& EF_ARM_INTERWORK
)
2350 (*_bfd_error_handler
) (_("\
2351 Warning: Not setting interworking flag of %s since it has already been specified as non-interworking"),
2352 bfd_archive_filename (abfd
));
2354 _bfd_error_handler (_("\
2355 Warning: Clearing the interworking flag of %s due to outside request"),
2356 bfd_archive_filename (abfd
));
2361 elf_elfheader (abfd
)->e_flags
= flags
;
2362 elf_flags_init (abfd
) = TRUE
;
2368 /* Copy backend specific data from one object module to another. */
2371 elf32_arm_copy_private_bfd_data (ibfd
, obfd
)
2378 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2379 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2382 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2383 out_flags
= elf_elfheader (obfd
)->e_flags
;
2385 if (elf_flags_init (obfd
)
2386 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2387 && in_flags
!= out_flags
)
2389 /* Cannot mix APCS26 and APCS32 code. */
2390 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2393 /* Cannot mix float APCS and non-float APCS code. */
2394 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2397 /* If the src and dest have different interworking flags
2398 then turn off the interworking bit. */
2399 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2401 if (out_flags
& EF_ARM_INTERWORK
)
2402 _bfd_error_handler (_("\
2403 Warning: Clearing the interworking flag of %s because non-interworking code in %s has been linked with it"),
2404 bfd_get_filename (obfd
),
2405 bfd_archive_filename (ibfd
));
2407 in_flags
&= ~EF_ARM_INTERWORK
;
2410 /* Likewise for PIC, though don't warn for this case. */
2411 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2412 in_flags
&= ~EF_ARM_PIC
;
2415 elf_elfheader (obfd
)->e_flags
= in_flags
;
2416 elf_flags_init (obfd
) = TRUE
;
2421 /* Merge backend specific data from an object file to the output
2422 object file when linking. */
2425 elf32_arm_merge_private_bfd_data (ibfd
, obfd
)
2431 bfd_boolean flags_compatible
= TRUE
;
2434 /* Check if we have the same endianess. */
2435 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2438 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2439 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2442 /* The input BFD must have had its flags initialised. */
2443 /* The following seems bogus to me -- The flags are initialized in
2444 the assembler but I don't think an elf_flags_init field is
2445 written into the object. */
2446 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2448 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2449 out_flags
= elf_elfheader (obfd
)->e_flags
;
2451 if (!elf_flags_init (obfd
))
2453 /* If the input is the default architecture and had the default
2454 flags then do not bother setting the flags for the output
2455 architecture, instead allow future merges to do this. If no
2456 future merges ever set these flags then they will retain their
2457 uninitialised values, which surprise surprise, correspond
2458 to the default values. */
2459 if (bfd_get_arch_info (ibfd
)->the_default
2460 && elf_elfheader (ibfd
)->e_flags
== 0)
2463 elf_flags_init (obfd
) = TRUE
;
2464 elf_elfheader (obfd
)->e_flags
= in_flags
;
2466 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2467 && bfd_get_arch_info (obfd
)->the_default
)
2468 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2473 /* Determine what should happen if the input ARM architecture
2474 does not match the output ARM architecture. */
2475 if (! bfd_arm_merge_machines (ibfd
, obfd
))
2478 /* Identical flags must be compatible. */
2479 if (in_flags
== out_flags
)
2482 /* Check to see if the input BFD actually contains any sections. If
2483 not, its flags may not have been initialised either, but it
2484 cannot actually cause any incompatibility. Do not short-circuit
2485 dynamic objects; their section list may be emptied by
2486 elf_link_add_object_symbols.
2488 Also check to see if there are no code sections in the input.
2489 In this case there is no need to check for code specific flags.
2490 XXX - do we need to worry about floating-point format compatability
2491 in data sections ? */
2492 if (!(ibfd
->flags
& DYNAMIC
))
2494 bfd_boolean null_input_bfd
= TRUE
;
2495 bfd_boolean only_data_sections
= TRUE
;
2497 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2499 /* Ignore synthetic glue sections. */
2500 if (strcmp (sec
->name
, ".glue_7")
2501 && strcmp (sec
->name
, ".glue_7t"))
2503 if ((bfd_get_section_flags (ibfd
, sec
)
2504 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2505 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2506 only_data_sections
= FALSE
;
2508 null_input_bfd
= FALSE
;
2513 if (null_input_bfd
|| only_data_sections
)
2517 /* Complain about various flag mismatches. */
2518 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2520 _bfd_error_handler (_("\
2521 ERROR: %s is compiled for EABI version %d, whereas %s is compiled for version %d"),
2522 bfd_archive_filename (ibfd
),
2523 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2524 bfd_get_filename (obfd
),
2525 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2529 /* Not sure what needs to be checked for EABI versions >= 1. */
2530 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2532 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2534 _bfd_error_handler (_("\
2535 ERROR: %s is compiled for APCS-%d, whereas target %s uses APCS-%d"),
2536 bfd_archive_filename (ibfd
),
2537 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2538 bfd_get_filename (obfd
),
2539 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2540 flags_compatible
= FALSE
;
2543 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2545 if (in_flags
& EF_ARM_APCS_FLOAT
)
2546 _bfd_error_handler (_("\
2547 ERROR: %s passes floats in float registers, whereas %s passes them in integer registers"),
2548 bfd_archive_filename (ibfd
),
2549 bfd_get_filename (obfd
));
2551 _bfd_error_handler (_("\
2552 ERROR: %s passes floats in integer registers, whereas %s passes them in float registers"),
2553 bfd_archive_filename (ibfd
),
2554 bfd_get_filename (obfd
));
2556 flags_compatible
= FALSE
;
2559 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2561 if (in_flags
& EF_ARM_VFP_FLOAT
)
2562 _bfd_error_handler (_("\
2563 ERROR: %s uses VFP instructions, whereas %s does not"),
2564 bfd_archive_filename (ibfd
),
2565 bfd_get_filename (obfd
));
2567 _bfd_error_handler (_("\
2568 ERROR: %s uses FPA instructions, whereas %s does not"),
2569 bfd_archive_filename (ibfd
),
2570 bfd_get_filename (obfd
));
2572 flags_compatible
= FALSE
;
2575 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
2577 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
2578 _bfd_error_handler (_("\
2579 ERROR: %s uses Maverick instructions, whereas %s does not"),
2580 bfd_archive_filename (ibfd
),
2581 bfd_get_filename (obfd
));
2583 _bfd_error_handler (_("\
2584 ERROR: %s does not use Maverick instructions, whereas %s does"),
2585 bfd_archive_filename (ibfd
),
2586 bfd_get_filename (obfd
));
2588 flags_compatible
= FALSE
;
2591 #ifdef EF_ARM_SOFT_FLOAT
2592 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2594 /* We can allow interworking between code that is VFP format
2595 layout, and uses either soft float or integer regs for
2596 passing floating point arguments and results. We already
2597 know that the APCS_FLOAT flags match; similarly for VFP
2599 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2600 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2602 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2603 _bfd_error_handler (_("\
2604 ERROR: %s uses software FP, whereas %s uses hardware FP"),
2605 bfd_archive_filename (ibfd
),
2606 bfd_get_filename (obfd
));
2608 _bfd_error_handler (_("\
2609 ERROR: %s uses hardware FP, whereas %s uses software FP"),
2610 bfd_archive_filename (ibfd
),
2611 bfd_get_filename (obfd
));
2613 flags_compatible
= FALSE
;
2618 /* Interworking mismatch is only a warning. */
2619 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2621 if (in_flags
& EF_ARM_INTERWORK
)
2623 _bfd_error_handler (_("\
2624 Warning: %s supports interworking, whereas %s does not"),
2625 bfd_archive_filename (ibfd
),
2626 bfd_get_filename (obfd
));
2630 _bfd_error_handler (_("\
2631 Warning: %s does not support interworking, whereas %s does"),
2632 bfd_archive_filename (ibfd
),
2633 bfd_get_filename (obfd
));
2638 return flags_compatible
;
2641 /* Display the flags field. */
2644 elf32_arm_print_private_bfd_data (abfd
, ptr
)
2648 FILE * file
= (FILE *) ptr
;
2649 unsigned long flags
;
2651 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2653 /* Print normal ELF private data. */
2654 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2656 flags
= elf_elfheader (abfd
)->e_flags
;
2657 /* Ignore init flag - it may not be set, despite the flags field
2658 containing valid data. */
2660 /* xgettext:c-format */
2661 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2663 switch (EF_ARM_EABI_VERSION (flags
))
2665 case EF_ARM_EABI_UNKNOWN
:
2666 /* The following flag bits are GNU extensions and not part of the
2667 official ARM ELF extended ABI. Hence they are only decoded if
2668 the EABI version is not set. */
2669 if (flags
& EF_ARM_INTERWORK
)
2670 fprintf (file
, _(" [interworking enabled]"));
2672 if (flags
& EF_ARM_APCS_26
)
2673 fprintf (file
, " [APCS-26]");
2675 fprintf (file
, " [APCS-32]");
2677 if (flags
& EF_ARM_VFP_FLOAT
)
2678 fprintf (file
, _(" [VFP float format]"));
2679 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
2680 fprintf (file
, _(" [Maverick float format]"));
2682 fprintf (file
, _(" [FPA float format]"));
2684 if (flags
& EF_ARM_APCS_FLOAT
)
2685 fprintf (file
, _(" [floats passed in float registers]"));
2687 if (flags
& EF_ARM_PIC
)
2688 fprintf (file
, _(" [position independent]"));
2690 if (flags
& EF_ARM_NEW_ABI
)
2691 fprintf (file
, _(" [new ABI]"));
2693 if (flags
& EF_ARM_OLD_ABI
)
2694 fprintf (file
, _(" [old ABI]"));
2696 if (flags
& EF_ARM_SOFT_FLOAT
)
2697 fprintf (file
, _(" [software FP]"));
2699 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2700 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2701 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
2702 | EF_ARM_MAVERICK_FLOAT
);
2705 case EF_ARM_EABI_VER1
:
2706 fprintf (file
, _(" [Version1 EABI]"));
2708 if (flags
& EF_ARM_SYMSARESORTED
)
2709 fprintf (file
, _(" [sorted symbol table]"));
2711 fprintf (file
, _(" [unsorted symbol table]"));
2713 flags
&= ~ EF_ARM_SYMSARESORTED
;
2716 case EF_ARM_EABI_VER2
:
2717 fprintf (file
, _(" [Version2 EABI]"));
2719 if (flags
& EF_ARM_SYMSARESORTED
)
2720 fprintf (file
, _(" [sorted symbol table]"));
2722 fprintf (file
, _(" [unsorted symbol table]"));
2724 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2725 fprintf (file
, _(" [dynamic symbols use segment index]"));
2727 if (flags
& EF_ARM_MAPSYMSFIRST
)
2728 fprintf (file
, _(" [mapping symbols precede others]"));
2730 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2731 | EF_ARM_MAPSYMSFIRST
);
2734 case EF_ARM_EABI_VER3
:
2735 fprintf (file
, _(" [Version3 EABI]"));
2737 if (flags
& EF_ARM_BE8
)
2738 fprintf (file
, _(" [BE8]"));
2740 if (flags
& EF_ARM_LE8
)
2741 fprintf (file
, _(" [LE8]"));
2743 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
2747 fprintf (file
, _(" <EABI version unrecognised>"));
2751 flags
&= ~ EF_ARM_EABIMASK
;
2753 if (flags
& EF_ARM_RELEXEC
)
2754 fprintf (file
, _(" [relocatable executable]"));
2756 if (flags
& EF_ARM_HASENTRY
)
2757 fprintf (file
, _(" [has entry point]"));
2759 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2762 fprintf (file
, _("<Unrecognised flag bits set>"));
2770 elf32_arm_get_symbol_type (elf_sym
, type
)
2771 Elf_Internal_Sym
* elf_sym
;
2774 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2777 return ELF_ST_TYPE (elf_sym
->st_info
);
2780 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2781 This allows us to distinguish between data used by Thumb instructions
2782 and non-data (which is probably code) inside Thumb regions of an
2784 if (type
!= STT_OBJECT
)
2785 return ELF_ST_TYPE (elf_sym
->st_info
);
2796 elf32_arm_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2798 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2799 Elf_Internal_Rela
*rel
;
2800 struct elf_link_hash_entry
*h
;
2801 Elf_Internal_Sym
*sym
;
2805 switch (ELF32_R_TYPE (rel
->r_info
))
2807 case R_ARM_GNU_VTINHERIT
:
2808 case R_ARM_GNU_VTENTRY
:
2812 switch (h
->root
.type
)
2814 case bfd_link_hash_defined
:
2815 case bfd_link_hash_defweak
:
2816 return h
->root
.u
.def
.section
;
2818 case bfd_link_hash_common
:
2819 return h
->root
.u
.c
.p
->section
;
2827 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2832 /* Update the got entry reference counts for the section being removed. */
2835 elf32_arm_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2836 bfd
*abfd ATTRIBUTE_UNUSED
;
2837 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2838 asection
*sec ATTRIBUTE_UNUSED
;
2839 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2841 Elf_Internal_Shdr
*symtab_hdr
;
2842 struct elf_link_hash_entry
**sym_hashes
;
2843 bfd_signed_vma
*local_got_refcounts
;
2844 const Elf_Internal_Rela
*rel
, *relend
;
2845 unsigned long r_symndx
;
2846 struct elf_link_hash_entry
*h
;
2848 elf_section_data (sec
)->local_dynrel
= NULL
;
2850 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2851 sym_hashes
= elf_sym_hashes (abfd
);
2852 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2854 relend
= relocs
+ sec
->reloc_count
;
2855 for (rel
= relocs
; rel
< relend
; rel
++)
2856 switch (ELF32_R_TYPE (rel
->r_info
))
2859 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2860 if (r_symndx
>= symtab_hdr
->sh_info
)
2862 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2863 if (h
->got
.refcount
> 0)
2864 h
->got
.refcount
-= 1;
2866 else if (local_got_refcounts
!= NULL
)
2868 if (local_got_refcounts
[r_symndx
] > 0)
2869 local_got_refcounts
[r_symndx
] -= 1;
2877 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2878 if (r_symndx
>= symtab_hdr
->sh_info
)
2880 struct elf32_arm_link_hash_entry
*eh
;
2881 struct elf32_arm_relocs_copied
**pp
;
2882 struct elf32_arm_relocs_copied
*p
;
2884 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2886 if (h
->plt
.refcount
> 0)
2887 h
->plt
.refcount
-= 1;
2889 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
2890 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
2892 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2894 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
2896 if (p
->section
== sec
)
2914 /* Look through the relocs for a section during the first phase. */
2917 elf32_arm_check_relocs (abfd
, info
, sec
, relocs
)
2919 struct bfd_link_info
*info
;
2921 const Elf_Internal_Rela
*relocs
;
2923 Elf_Internal_Shdr
*symtab_hdr
;
2924 struct elf_link_hash_entry
**sym_hashes
;
2925 struct elf_link_hash_entry
**sym_hashes_end
;
2926 const Elf_Internal_Rela
*rel
;
2927 const Elf_Internal_Rela
*rel_end
;
2930 bfd_vma
*local_got_offsets
;
2931 struct elf32_arm_link_hash_table
*htab
;
2933 if (info
->relocatable
)
2936 htab
= elf32_arm_hash_table (info
);
2939 dynobj
= elf_hash_table (info
)->dynobj
;
2940 local_got_offsets
= elf_local_got_offsets (abfd
);
2942 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2943 sym_hashes
= elf_sym_hashes (abfd
);
2944 sym_hashes_end
= sym_hashes
2945 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2947 if (!elf_bad_symtab (abfd
))
2948 sym_hashes_end
-= symtab_hdr
->sh_info
;
2950 rel_end
= relocs
+ sec
->reloc_count
;
2951 for (rel
= relocs
; rel
< rel_end
; rel
++)
2953 struct elf_link_hash_entry
*h
;
2954 unsigned long r_symndx
;
2956 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2957 if (r_symndx
< symtab_hdr
->sh_info
)
2960 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2962 switch (ELF32_R_TYPE (rel
->r_info
))
2965 /* This symbol requires a global offset table entry. */
2972 bfd_signed_vma
*local_got_refcounts
;
2974 /* This is a global offset table entry for a local symbol. */
2975 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2976 if (local_got_refcounts
== NULL
)
2980 size
= symtab_hdr
->sh_info
;
2981 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
2982 local_got_refcounts
= ((bfd_signed_vma
*)
2983 bfd_zalloc (abfd
, size
));
2984 if (local_got_refcounts
== NULL
)
2986 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2988 local_got_refcounts
[r_symndx
] += 1;
2994 if (htab
->sgot
== NULL
)
2996 if (htab
->root
.dynobj
== NULL
)
2997 htab
->root
.dynobj
= abfd
;
2998 if (!create_got_section (htab
->root
.dynobj
, info
))
3009 /* If this reloc is in a read-only section, we might
3010 need a copy reloc. We can't check reliably at this
3011 stage whether the section is read-only, as input
3012 sections have not yet been mapped to output sections.
3013 Tentatively set the flag for now, and correct in
3014 adjust_dynamic_symbol. */
3016 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3018 /* We may need a .plt entry if the function this reloc
3019 refers to is in a different object. We can't tell for
3020 sure yet, because something later might force the
3022 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
3023 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_PLT32
)
3024 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3026 /* If we create a PLT entry, this relocation will reference
3027 it, even if it's an ABS32 relocation. */
3028 h
->plt
.refcount
+= 1;
3031 /* If we are creating a shared library, and this is a reloc
3032 against a global symbol, or a non PC relative reloc
3033 against a local symbol, then we need to copy the reloc
3034 into the shared library. However, if we are linking with
3035 -Bsymbolic, we do not need to copy a reloc against a
3036 global symbol which is defined in an object we are
3037 including in the link (i.e., DEF_REGULAR is set). At
3038 this point we have not seen all the input files, so it is
3039 possible that DEF_REGULAR is not set now but will be set
3040 later (it is never cleared). We account for that
3041 possibility below by storing information in the
3042 relocs_copied field of the hash table entry. */
3044 && (sec
->flags
& SEC_ALLOC
) != 0
3045 && ((ELF32_R_TYPE (rel
->r_info
) != R_ARM_PC24
3046 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_PLT32
3047 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_REL32
)
3049 && (! info
->symbolic
3050 || (h
->elf_link_hash_flags
3051 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3053 struct elf32_arm_relocs_copied
*p
, **head
;
3055 /* When creating a shared object, we must copy these
3056 reloc types into the output file. We create a reloc
3057 section in dynobj and make room for this reloc. */
3062 name
= (bfd_elf_string_from_elf_section
3064 elf_elfheader (abfd
)->e_shstrndx
,
3065 elf_section_data (sec
)->rel_hdr
.sh_name
));
3069 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
3070 && strcmp (bfd_get_section_name (abfd
, sec
),
3073 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3078 sreloc
= bfd_make_section (dynobj
, name
);
3079 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3080 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3081 if ((sec
->flags
& SEC_ALLOC
) != 0)
3082 flags
|= SEC_ALLOC
| SEC_LOAD
;
3084 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
3085 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
3089 elf_section_data (sec
)->sreloc
= sreloc
;
3092 /* If this is a global symbol, we count the number of
3093 relocations we need for this symbol. */
3096 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
3100 /* Track dynamic relocs needed for local syms too.
3101 We really need local syms available to do this
3105 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3110 head
= ((struct elf32_arm_relocs_copied
**)
3111 &elf_section_data (s
)->local_dynrel
);
3115 if (p
== NULL
|| p
->section
!= sec
)
3117 bfd_size_type amt
= sizeof *p
;
3118 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
3127 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
3128 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
3133 /* This relocation describes the C++ object vtable hierarchy.
3134 Reconstruct it for later use during GC. */
3135 case R_ARM_GNU_VTINHERIT
:
3136 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3140 /* This relocation describes which C++ vtable entries are actually
3141 used. Record for later use during GC. */
3142 case R_ARM_GNU_VTENTRY
:
3143 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
3152 /* Find the nearest line to a particular section and offset, for error
3153 reporting. This code is a duplicate of the code in elf.c, except
3154 that it also accepts STT_ARM_TFUNC as a symbol that names a function. */
3157 elf32_arm_find_nearest_line
3158 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
3163 const char **filename_ptr
;
3164 const char **functionname_ptr
;
3165 unsigned int *line_ptr
;
3168 const char *filename
;
3173 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3174 filename_ptr
, functionname_ptr
,
3176 &elf_tdata (abfd
)->dwarf2_find_line_info
))
3179 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
3180 &found
, filename_ptr
,
3181 functionname_ptr
, line_ptr
,
3182 &elf_tdata (abfd
)->line_info
))
3188 if (symbols
== NULL
)
3195 for (p
= symbols
; *p
!= NULL
; p
++)
3199 q
= (elf_symbol_type
*) *p
;
3201 if (bfd_get_section (&q
->symbol
) != section
)
3204 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
3209 filename
= bfd_asymbol_name (&q
->symbol
);
3214 if (q
->symbol
.section
== section
3215 && q
->symbol
.value
>= low_func
3216 && q
->symbol
.value
<= offset
)
3218 func
= (asymbol
*) q
;
3219 low_func
= q
->symbol
.value
;
3228 *filename_ptr
= filename
;
3229 *functionname_ptr
= bfd_asymbol_name (func
);
3235 /* Adjust a symbol defined by a dynamic object and referenced by a
3236 regular object. The current definition is in some section of the
3237 dynamic object, but we're not including those sections. We have to
3238 change the definition to something the rest of the link can
3242 elf32_arm_adjust_dynamic_symbol (info
, h
)
3243 struct bfd_link_info
* info
;
3244 struct elf_link_hash_entry
* h
;
3248 unsigned int power_of_two
;
3250 dynobj
= elf_hash_table (info
)->dynobj
;
3252 /* Make sure we know what is going on here. */
3253 BFD_ASSERT (dynobj
!= NULL
3254 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3255 || h
->weakdef
!= NULL
3256 || ((h
->elf_link_hash_flags
3257 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3258 && (h
->elf_link_hash_flags
3259 & ELF_LINK_HASH_REF_REGULAR
) != 0
3260 && (h
->elf_link_hash_flags
3261 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3263 /* If this is a function, put it in the procedure linkage table. We
3264 will fill in the contents of the procedure linkage table later,
3265 when we know the address of the .got section. */
3266 if (h
->type
== STT_FUNC
3267 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3269 if (h
->plt
.refcount
<= 0
3270 || SYMBOL_CALLS_LOCAL (info
, h
)
3271 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3272 && h
->root
.type
== bfd_link_hash_undefweak
))
3274 /* This case can occur if we saw a PLT32 reloc in an input
3275 file, but the symbol was never referred to by a dynamic
3276 object, or if all references were garbage collected. In
3277 such a case, we don't actually need to build a procedure
3278 linkage table, and we can just do a PC24 reloc instead. */
3279 h
->plt
.offset
= (bfd_vma
) -1;
3280 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3286 /* It's possible that we incorrectly decided a .plt reloc was
3287 needed for an R_ARM_PC24 reloc to a non-function sym in
3288 check_relocs. We can't decide accurately between function and
3289 non-function syms in check-relocs; Objects loaded later in
3290 the link may change h->type. So fix it now. */
3291 h
->plt
.offset
= (bfd_vma
) -1;
3293 /* If this is a weak symbol, and there is a real definition, the
3294 processor independent code will have arranged for us to see the
3295 real definition first, and we can just use the same value. */
3296 if (h
->weakdef
!= NULL
)
3298 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3299 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3300 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3301 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3305 /* This is a reference to a symbol defined by a dynamic object which
3306 is not a function. */
3308 /* If we are creating a shared library, we must presume that the
3309 only references to the symbol are via the global offset table.
3310 For such cases we need not do anything here; the relocations will
3311 be handled correctly by relocate_section. */
3315 /* We must allocate the symbol in our .dynbss section, which will
3316 become part of the .bss section of the executable. There will be
3317 an entry for this symbol in the .dynsym section. The dynamic
3318 object will contain position independent code, so all references
3319 from the dynamic object to this symbol will go through the global
3320 offset table. The dynamic linker will use the .dynsym entry to
3321 determine the address it must put in the global offset table, so
3322 both the dynamic object and the regular object will refer to the
3323 same memory location for the variable. */
3324 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3325 BFD_ASSERT (s
!= NULL
);
3327 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
3328 copy the initial value out of the dynamic object and into the
3329 runtime process image. We need to remember the offset into the
3330 .rel.bss section we are going to use. */
3331 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3335 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
3336 BFD_ASSERT (srel
!= NULL
);
3337 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3338 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3341 /* We need to figure out the alignment required for this symbol. I
3342 have no idea how ELF linkers handle this. */
3343 power_of_two
= bfd_log2 (h
->size
);
3344 if (power_of_two
> 3)
3347 /* Apply the required alignment. */
3348 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3349 (bfd_size_type
) (1 << power_of_two
));
3350 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3352 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3356 /* Define the symbol as being at this point in the section. */
3357 h
->root
.u
.def
.section
= s
;
3358 h
->root
.u
.def
.value
= s
->_raw_size
;
3360 /* Increment the section size to make room for the symbol. */
3361 s
->_raw_size
+= h
->size
;
3366 /* Allocate space in .plt, .got and associated reloc sections for
3370 allocate_dynrelocs (h
, inf
)
3371 struct elf_link_hash_entry
*h
;
3374 struct bfd_link_info
*info
;
3375 struct elf32_arm_link_hash_table
*htab
;
3376 struct elf32_arm_link_hash_entry
*eh
;
3377 struct elf32_arm_relocs_copied
*p
;
3379 if (h
->root
.type
== bfd_link_hash_indirect
)
3382 if (h
->root
.type
== bfd_link_hash_warning
)
3383 /* When warning symbols are created, they **replace** the "real"
3384 entry in the hash table, thus we never get to see the real
3385 symbol in a hash traversal. So look at it now. */
3386 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3388 info
= (struct bfd_link_info
*) inf
;
3389 htab
= elf32_arm_hash_table (info
);
3391 if (htab
->root
.dynamic_sections_created
3392 && h
->plt
.refcount
> 0)
3394 /* Make sure this symbol is output as a dynamic symbol.
3395 Undefined weak syms won't yet be marked as dynamic. */
3396 if (h
->dynindx
== -1
3397 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3399 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3404 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3406 asection
*s
= htab
->splt
;
3408 /* If this is the first .plt entry, make room for the special
3410 if (s
->_raw_size
== 0)
3411 s
->_raw_size
+= PLT_HEADER_SIZE
;
3413 h
->plt
.offset
= s
->_raw_size
;
3415 /* If this symbol is not defined in a regular file, and we are
3416 not generating a shared library, then set the symbol to this
3417 location in the .plt. This is required to make function
3418 pointers compare as equal between the normal executable and
3419 the shared library. */
3421 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3423 h
->root
.u
.def
.section
= s
;
3424 h
->root
.u
.def
.value
= h
->plt
.offset
;
3427 /* Make room for this entry. */
3428 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3430 /* We also need to make an entry in the .got.plt section, which
3431 will be placed in the .got section by the linker script. */
3432 htab
->sgotplt
->_raw_size
+= 4;
3434 /* We also need to make an entry in the .rel.plt section. */
3435 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rel
);
3439 h
->plt
.offset
= (bfd_vma
) -1;
3440 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3445 h
->plt
.offset
= (bfd_vma
) -1;
3446 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3449 if (h
->got
.refcount
> 0)
3454 /* Make sure this symbol is output as a dynamic symbol.
3455 Undefined weak syms won't yet be marked as dynamic. */
3456 if (h
->dynindx
== -1
3457 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3459 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3464 h
->got
.offset
= s
->_raw_size
;
3466 dyn
= htab
->root
.dynamic_sections_created
;
3467 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3468 || h
->root
.type
!= bfd_link_hash_undefweak
)
3470 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3471 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rel
);
3474 h
->got
.offset
= (bfd_vma
) -1;
3476 eh
= (struct elf32_arm_link_hash_entry
*) h
;
3477 if (eh
->relocs_copied
== NULL
)
3480 /* In the shared -Bsymbolic case, discard space allocated for
3481 dynamic pc-relative relocs against symbols which turn out to be
3482 defined in regular objects. For the normal shared case, discard
3483 space for pc-relative relocs that have become local due to symbol
3484 visibility changes. */
3488 /* Discard relocs on undefined weak syms with non-default
3490 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3491 && h
->root
.type
== bfd_link_hash_undefweak
)
3492 eh
->relocs_copied
= NULL
;
3496 /* For the non-shared case, discard space for relocs against
3497 symbols which turn out to need copy relocs or are not
3500 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3501 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3502 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3503 || (htab
->root
.dynamic_sections_created
3504 && (h
->root
.type
== bfd_link_hash_undefweak
3505 || h
->root
.type
== bfd_link_hash_undefined
))))
3507 /* Make sure this symbol is output as a dynamic symbol.
3508 Undefined weak syms won't yet be marked as dynamic. */
3509 if (h
->dynindx
== -1
3510 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3512 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3516 /* If that succeeded, we know we'll be keeping all the
3518 if (h
->dynindx
!= -1)
3522 eh
->relocs_copied
= NULL
;
3527 /* Finally, allocate space. */
3528 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
3530 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
3531 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3537 /* Set the sizes of the dynamic sections. */
3540 elf32_arm_size_dynamic_sections (output_bfd
, info
)
3541 bfd
* output_bfd ATTRIBUTE_UNUSED
;
3542 struct bfd_link_info
* info
;
3549 struct elf32_arm_link_hash_table
*htab
;
3551 htab
= elf32_arm_hash_table (info
);
3552 dynobj
= elf_hash_table (info
)->dynobj
;
3553 BFD_ASSERT (dynobj
!= NULL
);
3555 if (elf_hash_table (info
)->dynamic_sections_created
)
3557 /* Set the contents of the .interp section to the interpreter. */
3558 if (info
->executable
)
3560 s
= bfd_get_section_by_name (dynobj
, ".interp");
3561 BFD_ASSERT (s
!= NULL
);
3562 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3563 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3567 /* Set up .got offsets for local syms, and space for local dynamic
3569 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3571 bfd_signed_vma
*local_got
;
3572 bfd_signed_vma
*end_local_got
;
3573 char *local_tls_type
;
3574 bfd_size_type locsymcount
;
3575 Elf_Internal_Shdr
*symtab_hdr
;
3578 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3581 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3583 struct elf32_arm_relocs_copied
*p
;
3585 for (p
= *((struct elf32_arm_relocs_copied
**)
3586 &elf_section_data (s
)->local_dynrel
);
3590 if (!bfd_is_abs_section (p
->section
)
3591 && bfd_is_abs_section (p
->section
->output_section
))
3593 /* Input section has been discarded, either because
3594 it is a copy of a linkonce section or due to
3595 linker script /DISCARD/, so we'll be discarding
3598 else if (p
->count
!= 0)
3600 srel
= elf_section_data (p
->section
)->sreloc
;
3601 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3602 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
3603 info
->flags
|= DF_TEXTREL
;
3608 local_got
= elf_local_got_refcounts (ibfd
);
3612 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3613 locsymcount
= symtab_hdr
->sh_info
;
3614 end_local_got
= local_got
+ locsymcount
;
3616 srel
= htab
->srelgot
;
3617 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
3621 *local_got
= s
->_raw_size
;
3624 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3627 *local_got
= (bfd_vma
) -1;
3631 /* Allocate global sym .plt and .got entries, and space for global
3632 sym dynamic relocs. */
3633 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
3635 /* The check_relocs and adjust_dynamic_symbol entry points have
3636 determined the sizes of the various dynamic sections. Allocate
3640 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3645 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3648 /* It's OK to base decisions on the section name, because none
3649 of the dynobj section names depend upon the input files. */
3650 name
= bfd_get_section_name (dynobj
, s
);
3654 if (strcmp (name
, ".plt") == 0)
3656 if (s
->_raw_size
== 0)
3658 /* Strip this section if we don't need it; see the
3664 /* Remember whether there is a PLT. */
3668 else if (strncmp (name
, ".rel", 4) == 0)
3670 if (s
->_raw_size
== 0)
3672 /* If we don't need this section, strip it from the
3673 output file. This is mostly to handle .rel.bss and
3674 .rel.plt. We must create both sections in
3675 create_dynamic_sections, because they must be created
3676 before the linker maps input sections to output
3677 sections. The linker does that before
3678 adjust_dynamic_symbol is called, and it is that
3679 function which decides whether anything needs to go
3680 into these sections. */
3685 /* Remember whether there are any reloc sections other
3687 if (strcmp (name
, ".rel.plt") != 0)
3690 /* We use the reloc_count field as a counter if we need
3691 to copy relocs into the output file. */
3695 else if (strncmp (name
, ".got", 4) != 0)
3697 /* It's not one of our sections, so don't allocate space. */
3703 _bfd_strip_section_from_output (info
, s
);
3707 /* Allocate memory for the section contents. */
3708 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3709 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3713 if (elf_hash_table (info
)->dynamic_sections_created
)
3715 /* Add some entries to the .dynamic section. We fill in the
3716 values later, in elf32_arm_finish_dynamic_sections, but we
3717 must add the entries now so that we get the correct size for
3718 the .dynamic section. The DT_DEBUG entry is filled in by the
3719 dynamic linker and used by the debugger. */
3720 #define add_dynamic_entry(TAG, VAL) \
3721 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3725 if (!add_dynamic_entry (DT_DEBUG
, 0))
3731 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3732 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3733 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3734 || !add_dynamic_entry (DT_JMPREL
, 0))
3740 if ( !add_dynamic_entry (DT_REL
, 0)
3741 || !add_dynamic_entry (DT_RELSZ
, 0)
3742 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3746 if ((info
->flags
& DF_TEXTREL
) != 0)
3748 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3750 info
->flags
|= DF_TEXTREL
;
3753 #undef add_synamic_entry
3758 /* Finish up dynamic symbol handling. We set the contents of various
3759 dynamic sections here. */
3762 elf32_arm_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3764 struct bfd_link_info
* info
;
3765 struct elf_link_hash_entry
* h
;
3766 Elf_Internal_Sym
* sym
;
3770 dynobj
= elf_hash_table (info
)->dynobj
;
3772 if (h
->plt
.offset
!= (bfd_vma
) -1)
3779 Elf_Internal_Rela rel
;
3781 bfd_vma got_displacement
;
3783 /* This symbol has an entry in the procedure linkage table. Set
3786 BFD_ASSERT (h
->dynindx
!= -1);
3788 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3789 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3790 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3791 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3793 /* Get the index in the procedure linkage table which
3794 corresponds to this symbol. This is the index of this symbol
3795 in all the symbols for which we are making plt entries. The
3796 first entry in the procedure linkage table is reserved. */
3797 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3799 /* Get the offset into the .got table of the entry that
3800 corresponds to this function. Each .got entry is 4 bytes.
3801 The first three are reserved. */
3802 got_offset
= (plt_index
+ 3) * 4;
3804 /* Calculate the displacement between the PLT slot and the
3805 entry in the GOT. */
3806 got_displacement
= (sgot
->output_section
->vma
3807 + sgot
->output_offset
3809 - splt
->output_section
->vma
3810 - splt
->output_offset
3814 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
3816 /* Fill in the entry in the procedure linkage table. */
3817 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
3818 splt
->contents
+ h
->plt
.offset
+ 0);
3819 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
3820 splt
->contents
+ h
->plt
.offset
+ 4);
3821 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
3822 splt
->contents
+ h
->plt
.offset
+ 8);
3823 #ifdef FOUR_WORD_PLT
3824 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
3825 splt
->contents
+ h
->plt
.offset
+ 12);
3828 /* Fill in the entry in the global offset table. */
3829 bfd_put_32 (output_bfd
,
3830 (splt
->output_section
->vma
3831 + splt
->output_offset
),
3832 sgot
->contents
+ got_offset
);
3834 /* Fill in the entry in the .rel.plt section. */
3835 rel
.r_offset
= (sgot
->output_section
->vma
3836 + sgot
->output_offset
3838 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3839 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3840 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3842 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3844 /* Mark the symbol as undefined, rather than as defined in
3845 the .plt section. Leave the value alone. */
3846 sym
->st_shndx
= SHN_UNDEF
;
3847 /* If the symbol is weak, we do need to clear the value.
3848 Otherwise, the PLT entry would provide a definition for
3849 the symbol even if the symbol wasn't defined anywhere,
3850 and so the symbol would never be NULL. */
3851 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
3857 if (h
->got
.offset
!= (bfd_vma
) -1)
3861 Elf_Internal_Rela rel
;
3864 /* This symbol has an entry in the global offset table. Set it
3866 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3867 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3868 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3870 rel
.r_offset
= (sgot
->output_section
->vma
3871 + sgot
->output_offset
3872 + (h
->got
.offset
&~ (bfd_vma
) 1));
3874 /* If this is a static link, or it is a -Bsymbolic link and the
3875 symbol is defined locally or was forced to be local because
3876 of a version file, we just want to emit a RELATIVE reloc.
3877 The entry in the global offset table will already have been
3878 initialized in the relocate_section function. */
3880 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3882 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3883 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3887 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3888 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3889 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3892 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3893 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3896 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3899 Elf_Internal_Rela rel
;
3902 /* This symbol needs a copy reloc. Set it up. */
3903 BFD_ASSERT (h
->dynindx
!= -1
3904 && (h
->root
.type
== bfd_link_hash_defined
3905 || h
->root
.type
== bfd_link_hash_defweak
));
3907 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3909 BFD_ASSERT (s
!= NULL
);
3911 rel
.r_offset
= (h
->root
.u
.def
.value
3912 + h
->root
.u
.def
.section
->output_section
->vma
3913 + h
->root
.u
.def
.section
->output_offset
);
3914 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3915 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3916 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3919 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3920 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3921 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3922 sym
->st_shndx
= SHN_ABS
;
3927 /* Finish up the dynamic sections. */
3930 elf32_arm_finish_dynamic_sections (output_bfd
, info
)
3932 struct bfd_link_info
* info
;
3938 dynobj
= elf_hash_table (info
)->dynobj
;
3940 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3941 BFD_ASSERT (sgot
!= NULL
);
3942 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3944 if (elf_hash_table (info
)->dynamic_sections_created
)
3947 Elf32_External_Dyn
*dyncon
, *dynconend
;
3949 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3950 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3952 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3953 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3955 for (; dyncon
< dynconend
; dyncon
++)
3957 Elf_Internal_Dyn dyn
;
3961 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3974 s
= bfd_get_section_by_name (output_bfd
, name
);
3975 BFD_ASSERT (s
!= NULL
);
3976 dyn
.d_un
.d_ptr
= s
->vma
;
3977 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3981 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3982 BFD_ASSERT (s
!= NULL
);
3983 if (s
->_cooked_size
!= 0)
3984 dyn
.d_un
.d_val
= s
->_cooked_size
;
3986 dyn
.d_un
.d_val
= s
->_raw_size
;
3987 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3991 /* My reading of the SVR4 ABI indicates that the
3992 procedure linkage table relocs (DT_JMPREL) should be
3993 included in the overall relocs (DT_REL). This is
3994 what Solaris does. However, UnixWare can not handle
3995 that case. Therefore, we override the DT_RELSZ entry
3996 here to make it not include the JMPREL relocs. Since
3997 the linker script arranges for .rel.plt to follow all
3998 other relocation sections, we don't have to worry
3999 about changing the DT_REL entry. */
4000 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
4003 if (s
->_cooked_size
!= 0)
4004 dyn
.d_un
.d_val
-= s
->_cooked_size
;
4006 dyn
.d_un
.d_val
-= s
->_raw_size
;
4008 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4011 /* Set the bottom bit of DT_INIT/FINI if the
4012 corresponding function is Thumb. */
4014 name
= info
->init_function
;
4017 name
= info
->fini_function
;
4019 /* If it wasn't set by elf_bfd_final_link
4020 then there is nothing to adjust. */
4021 if (dyn
.d_un
.d_val
!= 0)
4023 struct elf_link_hash_entry
* eh
;
4025 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
4026 FALSE
, FALSE
, TRUE
);
4027 if (eh
!= (struct elf_link_hash_entry
*) NULL
4028 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
4030 dyn
.d_un
.d_val
|= 1;
4031 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4038 /* Fill in the first entry in the procedure linkage table. */
4039 if (splt
->_raw_size
> 0)
4041 bfd_vma got_displacement
;
4043 /* Calculate the displacement between the PLT slot and &GOT[0]. */
4044 got_displacement
= (sgot
->output_section
->vma
4045 + sgot
->output_offset
4046 - splt
->output_section
->vma
4047 - splt
->output_offset
4050 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
4051 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
4052 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
4053 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
4054 #ifdef FOUR_WORD_PLT
4055 /* The displacement value goes in the otherwise-unused last word of
4056 the second entry. */
4057 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
4059 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
4063 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4064 really seem like the right value. */
4065 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
4068 /* Fill in the first three entries in the global offset table. */
4069 if (sgot
->_raw_size
> 0)
4072 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4074 bfd_put_32 (output_bfd
,
4075 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4077 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4078 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4081 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4087 elf32_arm_post_process_headers (abfd
, link_info
)
4089 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
4091 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
4092 struct elf32_arm_link_hash_table
*globals
;
4094 i_ehdrp
= elf_elfheader (abfd
);
4096 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
4097 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
4101 globals
= elf32_arm_hash_table (link_info
);
4102 if (globals
->byteswap_code
)
4103 i_ehdrp
->e_flags
|= EF_ARM_BE8
;
4107 static enum elf_reloc_type_class
4108 elf32_arm_reloc_type_class (rela
)
4109 const Elf_Internal_Rela
*rela
;
4111 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4113 case R_ARM_RELATIVE
:
4114 return reloc_class_relative
;
4115 case R_ARM_JUMP_SLOT
:
4116 return reloc_class_plt
;
4118 return reloc_class_copy
;
4120 return reloc_class_normal
;
4124 static bfd_boolean elf32_arm_section_flags
PARAMS ((flagword
*, const Elf_Internal_Shdr
*));
4125 static void elf32_arm_final_write_processing
PARAMS ((bfd
*, bfd_boolean
));
4127 /* Set the right machine number for an Arm ELF file. */
4130 elf32_arm_section_flags (flags
, hdr
)
4132 const Elf_Internal_Shdr
*hdr
;
4134 if (hdr
->sh_type
== SHT_NOTE
)
4135 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
4141 elf32_arm_final_write_processing (abfd
, linker
)
4143 bfd_boolean linker ATTRIBUTE_UNUSED
;
4145 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
4149 /* Called for each symbol. Builds a section map based on mapping symbols.
4150 Does not alter any of the symbols. */
4153 elf32_arm_output_symbol_hook (struct bfd_link_info
*info
,
4155 Elf_Internal_Sym
*elfsym
,
4156 asection
*input_sec
,
4157 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
4160 elf32_arm_section_map
*map
;
4161 struct elf32_arm_link_hash_table
*globals
;
4163 /* Only do this on final link. */
4164 if (info
->relocatable
)
4167 /* Only build a map if we need to byteswap code. */
4168 globals
= elf32_arm_hash_table (info
);
4169 if (!globals
->byteswap_code
)
4172 /* We only want mapping symbols. */
4180 mapcount
= ++(elf32_arm_section_data (input_sec
)->mapcount
);
4181 map
= elf32_arm_section_data (input_sec
)->map
;
4182 /* TODO: This may be inefficient, but we probably don't usually have many
4183 mapping symbols per section. */
4184 map
= bfd_realloc (map
, mapcount
* sizeof (elf32_arm_section_map
));
4185 elf32_arm_section_data (input_sec
)->map
= map
;
4187 map
[mapcount
- 1].vma
= elfsym
->st_value
;
4188 map
[mapcount
- 1].type
= name
[1];
4193 /* Allocate target specific section data. */
4196 elf32_arm_new_section_hook (bfd
*abfd
, asection
*sec
)
4198 struct _arm_elf_section_data
*sdata
;
4199 bfd_size_type amt
= sizeof (*sdata
);
4201 sdata
= bfd_zalloc (abfd
, amt
);
4204 sec
->used_by_bfd
= sdata
;
4206 return _bfd_elf_new_section_hook (abfd
, sec
);
4210 /* Used to order a list of mapping symbols by address. */
4213 elf32_arm_compare_mapping (const void * a
, const void * b
)
4215 return ((const elf32_arm_section_map
*) a
)->vma
4216 > ((const elf32_arm_section_map
*) b
)->vma
;
4220 /* Do code byteswapping. Return FALSE afterwards so that the section is
4221 written out as normal. */
4224 elf32_arm_write_section (bfd
*output_bfd ATTRIBUTE_UNUSED
, asection
*sec
,
4228 elf32_arm_section_map
*map
;
4235 mapcount
= elf32_arm_section_data (sec
)->mapcount
;
4236 map
= elf32_arm_section_data (sec
)->map
;
4241 qsort (map
, mapcount
, sizeof (elf32_arm_section_map
),
4242 elf32_arm_compare_mapping
);
4244 offset
= sec
->output_section
->vma
+ sec
->output_offset
;
4245 ptr
= map
[0].vma
- offset
;
4246 for (i
= 0; i
< mapcount
; i
++)
4248 if (i
== mapcount
- 1)
4249 end
= bfd_section_size (output_bfd
, sec
);
4251 end
= map
[i
+ 1].vma
- offset
;
4253 switch (map
[i
].type
)
4256 /* Byte swap code words. */
4257 while (ptr
+ 3 < end
)
4259 tmp
= contents
[ptr
];
4260 contents
[ptr
] = contents
[ptr
+ 3];
4261 contents
[ptr
+ 3] = tmp
;
4262 tmp
= contents
[ptr
+ 1];
4263 contents
[ptr
+ 1] = contents
[ptr
+ 2];
4264 contents
[ptr
+ 2] = tmp
;
4270 /* Byte swap code halfwords. */
4271 while (ptr
+ 1 < end
)
4273 tmp
= contents
[ptr
];
4274 contents
[ptr
] = contents
[ptr
+ 1];
4275 contents
[ptr
+ 1] = tmp
;
4281 /* Leave data alone. */
4290 #define ELF_ARCH bfd_arch_arm
4291 #define ELF_MACHINE_CODE EM_ARM
4292 #ifdef __QNXTARGET__
4293 #define ELF_MAXPAGESIZE 0x1000
4295 #define ELF_MAXPAGESIZE 0x8000
4298 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
4299 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
4300 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
4301 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
4302 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
4303 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
4304 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4305 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
4307 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
4308 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
4309 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
4310 #define elf_backend_check_relocs elf32_arm_check_relocs
4311 #define elf_backend_relocate_section elf32_arm_relocate_section
4312 #define elf_backend_write_section elf32_arm_write_section
4313 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
4314 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
4315 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
4316 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
4317 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
4318 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
4319 #define elf_backend_post_process_headers elf32_arm_post_process_headers
4320 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
4321 #define elf_backend_object_p elf32_arm_object_p
4322 #define elf_backend_section_flags elf32_arm_section_flags
4323 #define elf_backend_final_write_processing elf32_arm_final_write_processing
4324 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
4326 #define elf_backend_can_refcount 1
4327 #define elf_backend_can_gc_sections 1
4328 #define elf_backend_plt_readonly 1
4329 #define elf_backend_want_got_plt 1
4330 #define elf_backend_want_plt_sym 0
4332 #define elf_backend_rela_normal 1
4335 #define elf_backend_got_header_size 12
4337 #include "elf32-target.h"