1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 typedef unsigned long int insn32
;
25 typedef unsigned short int insn16
;
27 static bfd_boolean elf32_arm_set_private_flags
28 PARAMS ((bfd
*, flagword
));
29 static bfd_boolean elf32_arm_copy_private_bfd_data
30 PARAMS ((bfd
*, bfd
*));
31 static bfd_boolean elf32_arm_merge_private_bfd_data
32 PARAMS ((bfd
*, bfd
*));
33 static bfd_boolean elf32_arm_print_private_bfd_data
34 PARAMS ((bfd
*, PTR
));
35 static int elf32_arm_get_symbol_type
36 PARAMS (( Elf_Internal_Sym
*, int));
37 static struct bfd_link_hash_table
*elf32_arm_link_hash_table_create
39 static bfd_reloc_status_type elf32_arm_final_link_relocate
40 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
41 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
42 const char *, int, struct elf_link_hash_entry
*));
43 static insn32 insert_thumb_branch
44 PARAMS ((insn32
, int));
45 static struct elf_link_hash_entry
*find_thumb_glue
46 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
47 static struct elf_link_hash_entry
*find_arm_glue
48 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
49 static void elf32_arm_post_process_headers
50 PARAMS ((bfd
*, struct bfd_link_info
*));
51 static int elf32_arm_to_thumb_stub
52 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
53 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
54 static int elf32_thumb_to_arm_stub
55 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
56 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
57 static bfd_boolean elf32_arm_relocate_section
58 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
59 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
60 static asection
* elf32_arm_gc_mark_hook
61 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
62 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
63 static bfd_boolean elf32_arm_gc_sweep_hook
64 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
65 const Elf_Internal_Rela
*));
66 static bfd_boolean elf32_arm_check_relocs
67 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
68 const Elf_Internal_Rela
*));
69 static bfd_boolean elf32_arm_find_nearest_line
70 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
71 const char **, unsigned int *));
72 static bfd_boolean elf32_arm_adjust_dynamic_symbol
73 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
74 static bfd_boolean elf32_arm_size_dynamic_sections
75 PARAMS ((bfd
*, struct bfd_link_info
*));
76 static bfd_boolean elf32_arm_finish_dynamic_symbol
77 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
79 static bfd_boolean elf32_arm_finish_dynamic_sections
80 PARAMS ((bfd
*, struct bfd_link_info
*));
81 static struct bfd_hash_entry
* elf32_arm_link_hash_newfunc
82 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
84 static void arm_add_to_rel
85 PARAMS ((bfd
*, bfd_byte
*, reloc_howto_type
*, bfd_signed_vma
));
87 static bfd_boolean allocate_dynrelocs
88 PARAMS ((struct elf_link_hash_entry
*h
, PTR inf
));
89 static bfd_boolean create_got_section
90 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
91 static bfd_boolean elf32_arm_create_dynamic_sections
92 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
93 static enum elf_reloc_type_class elf32_arm_reloc_type_class
94 PARAMS ((const Elf_Internal_Rela
*));
95 static bfd_boolean elf32_arm_object_p
98 #ifndef ELFARM_NABI_C_INCLUDED
99 static void record_arm_to_thumb_glue
100 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
101 static void record_thumb_to_arm_glue
102 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
103 bfd_boolean bfd_elf32_arm_allocate_interworking_sections
104 PARAMS ((struct bfd_link_info
*));
105 bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
106 PARAMS ((bfd
*, struct bfd_link_info
*));
107 bfd_boolean bfd_elf32_arm_process_before_allocation
108 PARAMS ((bfd
*, struct bfd_link_info
*, int));
112 #define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
114 /* The linker script knows the section names for placement.
115 The entry_names are used to do simple name mangling on the stubs.
116 Given a function name, and its type, the stub can be found. The
117 name can be changed. The only requirement is the %s be present. */
118 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
119 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
121 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
122 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
124 /* The name of the dynamic interpreter. This is put in the .interp
126 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
130 /* The size in bytes of the special first entry in the procedure
132 #define PLT_HEADER_SIZE 16
134 /* The size in bytes of an entry in the procedure linkage table. */
135 #define PLT_ENTRY_SIZE 16
137 /* The first entry in a procedure linkage table looks like
138 this. It is set up so that any shared library function that is
139 called before the relocation has been set up calls the dynamic
141 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
143 0xe52de004, /* str lr, [sp, #-4]! */
144 0xe59fe010, /* ldr lr, [pc, #16] */
145 0xe08fe00e, /* add lr, pc, lr */
146 0xe5bef008, /* ldr pc, [lr, #8]! */
149 /* Subsequent entries in a procedure linkage table look like
151 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
153 0xe28fc600, /* add ip, pc, #NN */
154 0xe28cca00, /* add ip, ip, #NN */
155 0xe5bcf000, /* ldr pc, [ip, #NN]! */
156 0x00000000, /* unused */
161 /* The size in bytes of the special first entry in the procedure
163 #define PLT_HEADER_SIZE 20
165 /* The size in bytes of an entry in the procedure linkage table. */
166 #define PLT_ENTRY_SIZE 12
168 /* The first entry in a procedure linkage table looks like
169 this. It is set up so that any shared library function that is
170 called before the relocation has been set up calls the dynamic
172 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
174 0xe52de004, /* str lr, [sp, #-4]! */
175 0xe59fe004, /* ldr lr, [pc, #4] */
176 0xe08fe00e, /* add lr, pc, lr */
177 0xe5bef008, /* ldr pc, [lr, #8]! */
178 0x00000000, /* &GOT[0] - . */
181 /* Subsequent entries in a procedure linkage table look like
183 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
185 0xe28fc600, /* add ip, pc, #0xNN00000 */
186 0xe28cca00, /* add ip, ip, #0xNN000 */
187 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
192 /* The ARM linker needs to keep track of the number of relocs that it
193 decides to copy in check_relocs for each symbol. This is so that
194 it can discard PC relative relocs if it doesn't need them when
195 linking with -Bsymbolic. We store the information in a field
196 extending the regular ELF linker hash table. */
198 /* This structure keeps track of the number of PC relative relocs we
199 have copied for a given symbol. */
200 struct elf32_arm_relocs_copied
203 struct elf32_arm_relocs_copied
* next
;
204 /* A section in dynobj. */
206 /* Number of relocs copied in this section. */
208 /* Number of relocs copied in this section. */
209 bfd_size_type pc_count
;
212 /* Arm ELF linker hash entry. */
213 struct elf32_arm_link_hash_entry
215 struct elf_link_hash_entry root
;
217 /* Number of PC relative relocs copied for this symbol. */
218 struct elf32_arm_relocs_copied
* relocs_copied
;
221 /* Traverse an arm ELF linker hash table. */
222 #define elf32_arm_link_hash_traverse(table, func, info) \
223 (elf_link_hash_traverse \
225 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
228 /* Get the ARM elf linker hash table from a link_info structure. */
229 #define elf32_arm_hash_table(info) \
230 ((struct elf32_arm_link_hash_table *) ((info)->hash))
232 /* ARM ELF linker hash table. */
233 struct elf32_arm_link_hash_table
235 /* The main hash table. */
236 struct elf_link_hash_table root
;
238 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
239 bfd_size_type thumb_glue_size
;
241 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
242 bfd_size_type arm_glue_size
;
244 /* An arbitrary input BFD chosen to hold the glue sections. */
245 bfd
* bfd_of_glue_owner
;
247 /* A boolean indicating whether knowledge of the ARM's pipeline
248 length should be applied by the linker. */
249 int no_pipeline_knowledge
;
251 /* Short-cuts to get to dynamic linker sections. */
260 /* Small local sym to section mapping cache. */
261 struct sym_sec_cache sym_sec
;
264 /* Create an entry in an ARM ELF linker hash table. */
266 static struct bfd_hash_entry
*
267 elf32_arm_link_hash_newfunc (entry
, table
, string
)
268 struct bfd_hash_entry
* entry
;
269 struct bfd_hash_table
* table
;
272 struct elf32_arm_link_hash_entry
* ret
=
273 (struct elf32_arm_link_hash_entry
*) entry
;
275 /* Allocate the structure if it has not already been allocated by a
277 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
278 ret
= ((struct elf32_arm_link_hash_entry
*)
279 bfd_hash_allocate (table
,
280 sizeof (struct elf32_arm_link_hash_entry
)));
281 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
282 return (struct bfd_hash_entry
*) ret
;
284 /* Call the allocation method of the superclass. */
285 ret
= ((struct elf32_arm_link_hash_entry
*)
286 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
288 if (ret
!= (struct elf32_arm_link_hash_entry
*) NULL
)
289 ret
->relocs_copied
= NULL
;
291 return (struct bfd_hash_entry
*) ret
;
294 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
295 shortcuts to them in our hash table. */
298 create_got_section (dynobj
, info
)
300 struct bfd_link_info
*info
;
302 struct elf32_arm_link_hash_table
*htab
;
304 if (! _bfd_elf_create_got_section (dynobj
, info
))
307 htab
= elf32_arm_hash_table (info
);
308 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
309 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
310 if (!htab
->sgot
|| !htab
->sgotplt
)
313 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
314 if (htab
->srelgot
== NULL
315 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
316 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
317 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
319 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
324 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
325 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
329 elf32_arm_create_dynamic_sections (dynobj
, info
)
331 struct bfd_link_info
*info
;
333 struct elf32_arm_link_hash_table
*htab
;
335 htab
= elf32_arm_hash_table (info
);
336 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
339 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
342 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
343 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
344 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
346 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
348 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
349 || (!info
->shared
&& !htab
->srelbss
))
355 /* Copy the extra info we tack onto an elf_link_hash_entry. */
358 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
359 struct elf_link_hash_entry
*dir
,
360 struct elf_link_hash_entry
*ind
)
362 struct elf32_arm_link_hash_entry
*edir
, *eind
;
364 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
365 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
367 if (eind
->relocs_copied
!= NULL
)
369 if (edir
->relocs_copied
!= NULL
)
371 struct elf32_arm_relocs_copied
**pp
;
372 struct elf32_arm_relocs_copied
*p
;
374 if (ind
->root
.type
== bfd_link_hash_indirect
)
377 /* Add reloc counts against the weak sym to the strong sym
378 list. Merge any entries against the same section. */
379 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
381 struct elf32_arm_relocs_copied
*q
;
383 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
384 if (q
->section
== p
->section
)
386 q
->pc_count
+= p
->pc_count
;
387 q
->count
+= p
->count
;
394 *pp
= edir
->relocs_copied
;
397 edir
->relocs_copied
= eind
->relocs_copied
;
398 eind
->relocs_copied
= NULL
;
401 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
404 /* Create an ARM elf linker hash table. */
406 static struct bfd_link_hash_table
*
407 elf32_arm_link_hash_table_create (abfd
)
410 struct elf32_arm_link_hash_table
*ret
;
411 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
413 ret
= (struct elf32_arm_link_hash_table
*) bfd_malloc (amt
);
414 if (ret
== (struct elf32_arm_link_hash_table
*) NULL
)
417 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
418 elf32_arm_link_hash_newfunc
))
431 ret
->thumb_glue_size
= 0;
432 ret
->arm_glue_size
= 0;
433 ret
->bfd_of_glue_owner
= NULL
;
434 ret
->no_pipeline_knowledge
= 0;
435 ret
->sym_sec
.abfd
= NULL
;
437 return &ret
->root
.root
;
440 /* Locate the Thumb encoded calling stub for NAME. */
442 static struct elf_link_hash_entry
*
443 find_thumb_glue (link_info
, name
, input_bfd
)
444 struct bfd_link_info
*link_info
;
449 struct elf_link_hash_entry
*hash
;
450 struct elf32_arm_link_hash_table
*hash_table
;
452 /* We need a pointer to the armelf specific hash table. */
453 hash_table
= elf32_arm_hash_table (link_info
);
455 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
456 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
458 BFD_ASSERT (tmp_name
);
460 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
462 hash
= elf_link_hash_lookup
463 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
466 /* xgettext:c-format */
467 (*_bfd_error_handler
) (_("%s: unable to find THUMB glue '%s' for `%s'"),
468 bfd_archive_filename (input_bfd
), tmp_name
, name
);
475 /* Locate the ARM encoded calling stub for NAME. */
477 static struct elf_link_hash_entry
*
478 find_arm_glue (link_info
, name
, input_bfd
)
479 struct bfd_link_info
*link_info
;
484 struct elf_link_hash_entry
*myh
;
485 struct elf32_arm_link_hash_table
*hash_table
;
487 /* We need a pointer to the elfarm specific hash table. */
488 hash_table
= elf32_arm_hash_table (link_info
);
490 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
491 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
493 BFD_ASSERT (tmp_name
);
495 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
497 myh
= elf_link_hash_lookup
498 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
501 /* xgettext:c-format */
502 (*_bfd_error_handler
) (_("%s: unable to find ARM glue '%s' for `%s'"),
503 bfd_archive_filename (input_bfd
), tmp_name
, name
);
517 .word func @ behave as if you saw a ARM_32 reloc. */
519 #define ARM2THUMB_GLUE_SIZE 12
520 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
521 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
522 static const insn32 a2t3_func_addr_insn
= 0x00000001;
524 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
528 __func_from_thumb: __func_from_thumb:
530 nop ldr r6, __func_addr
532 __func_change_to_arm: bx r6
534 __func_back_to_thumb:
540 #define THUMB2ARM_GLUE_SIZE 8
541 static const insn16 t2a1_bx_pc_insn
= 0x4778;
542 static const insn16 t2a2_noop_insn
= 0x46c0;
543 static const insn32 t2a3_b_insn
= 0xea000000;
545 #ifndef ELFARM_NABI_C_INCLUDED
547 bfd_elf32_arm_allocate_interworking_sections (info
)
548 struct bfd_link_info
* info
;
552 struct elf32_arm_link_hash_table
* globals
;
554 globals
= elf32_arm_hash_table (info
);
556 BFD_ASSERT (globals
!= NULL
);
558 if (globals
->arm_glue_size
!= 0)
560 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
562 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
563 ARM2THUMB_GLUE_SECTION_NAME
);
565 BFD_ASSERT (s
!= NULL
);
567 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
568 globals
->arm_glue_size
);
570 s
->_raw_size
= s
->_cooked_size
= globals
->arm_glue_size
;
574 if (globals
->thumb_glue_size
!= 0)
576 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
578 s
= bfd_get_section_by_name
579 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
581 BFD_ASSERT (s
!= NULL
);
583 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
584 globals
->thumb_glue_size
);
586 s
->_raw_size
= s
->_cooked_size
= globals
->thumb_glue_size
;
594 record_arm_to_thumb_glue (link_info
, h
)
595 struct bfd_link_info
* link_info
;
596 struct elf_link_hash_entry
* h
;
598 const char * name
= h
->root
.root
.string
;
601 struct elf_link_hash_entry
* myh
;
602 struct bfd_link_hash_entry
* bh
;
603 struct elf32_arm_link_hash_table
* globals
;
606 globals
= elf32_arm_hash_table (link_info
);
608 BFD_ASSERT (globals
!= NULL
);
609 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
611 s
= bfd_get_section_by_name
612 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
614 BFD_ASSERT (s
!= NULL
);
616 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
617 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
619 BFD_ASSERT (tmp_name
);
621 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
623 myh
= elf_link_hash_lookup
624 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
628 /* We've already seen this guy. */
633 /* The only trick here is using hash_table->arm_glue_size as the value. Even
634 though the section isn't allocated yet, this is where we will be putting
637 val
= globals
->arm_glue_size
+ 1;
638 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
639 tmp_name
, BSF_GLOBAL
, s
, val
,
640 NULL
, TRUE
, FALSE
, &bh
);
644 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
650 record_thumb_to_arm_glue (link_info
, h
)
651 struct bfd_link_info
*link_info
;
652 struct elf_link_hash_entry
*h
;
654 const char *name
= h
->root
.root
.string
;
657 struct elf_link_hash_entry
*myh
;
658 struct bfd_link_hash_entry
*bh
;
659 struct elf32_arm_link_hash_table
*hash_table
;
663 hash_table
= elf32_arm_hash_table (link_info
);
665 BFD_ASSERT (hash_table
!= NULL
);
666 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
668 s
= bfd_get_section_by_name
669 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
671 BFD_ASSERT (s
!= NULL
);
673 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
674 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
676 BFD_ASSERT (tmp_name
);
678 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
680 myh
= elf_link_hash_lookup
681 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
685 /* We've already seen this guy. */
691 val
= hash_table
->thumb_glue_size
+ 1;
692 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
693 tmp_name
, BSF_GLOBAL
, s
, val
,
694 NULL
, TRUE
, FALSE
, &bh
);
696 /* If we mark it 'Thumb', the disassembler will do a better job. */
697 myh
= (struct elf_link_hash_entry
*) bh
;
698 bind
= ELF_ST_BIND (myh
->type
);
699 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
703 #define CHANGE_TO_ARM "__%s_change_to_arm"
704 #define BACK_FROM_ARM "__%s_back_from_arm"
706 /* Allocate another symbol to mark where we switch to Arm mode. */
707 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
708 + strlen (CHANGE_TO_ARM
) + 1);
710 BFD_ASSERT (tmp_name
);
712 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
715 val
= hash_table
->thumb_glue_size
+ 4,
716 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
717 tmp_name
, BSF_LOCAL
, s
, val
,
718 NULL
, TRUE
, FALSE
, &bh
);
722 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
727 /* Add the glue sections to ABFD. This function is called from the
728 linker scripts in ld/emultempl/{armelf}.em. */
731 bfd_elf32_arm_add_glue_sections_to_bfd (abfd
, info
)
733 struct bfd_link_info
*info
;
738 /* If we are only performing a partial
739 link do not bother adding the glue. */
740 if (info
->relocatable
)
743 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
747 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
748 will prevent elf_link_input_bfd() from processing the contents
750 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
752 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
755 || !bfd_set_section_flags (abfd
, sec
, flags
)
756 || !bfd_set_section_alignment (abfd
, sec
, 2))
759 /* Set the gc mark to prevent the section from being removed by garbage
760 collection, despite the fact that no relocs refer to this section. */
764 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
768 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
770 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
773 || !bfd_set_section_flags (abfd
, sec
, flags
)
774 || !bfd_set_section_alignment (abfd
, sec
, 2))
783 /* Select a BFD to be used to hold the sections used by the glue code.
784 This function is called from the linker scripts in ld/emultempl/
788 bfd_elf32_arm_get_bfd_for_interworking (abfd
, info
)
790 struct bfd_link_info
*info
;
792 struct elf32_arm_link_hash_table
*globals
;
794 /* If we are only performing a partial link
795 do not bother getting a bfd to hold the glue. */
796 if (info
->relocatable
)
799 globals
= elf32_arm_hash_table (info
);
801 BFD_ASSERT (globals
!= NULL
);
803 if (globals
->bfd_of_glue_owner
!= NULL
)
806 /* Save the bfd for later use. */
807 globals
->bfd_of_glue_owner
= abfd
;
813 bfd_elf32_arm_process_before_allocation (abfd
, link_info
, no_pipeline_knowledge
)
815 struct bfd_link_info
*link_info
;
816 int no_pipeline_knowledge
;
818 Elf_Internal_Shdr
*symtab_hdr
;
819 Elf_Internal_Rela
*internal_relocs
= NULL
;
820 Elf_Internal_Rela
*irel
, *irelend
;
821 bfd_byte
*contents
= NULL
;
824 struct elf32_arm_link_hash_table
*globals
;
826 /* If we are only performing a partial link do not bother
827 to construct any glue. */
828 if (link_info
->relocatable
)
831 /* Here we have a bfd that is to be included on the link. We have a hook
832 to do reloc rummaging, before section sizes are nailed down. */
833 globals
= elf32_arm_hash_table (link_info
);
835 BFD_ASSERT (globals
!= NULL
);
836 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
838 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
840 /* Rummage around all the relocs and map the glue vectors. */
841 sec
= abfd
->sections
;
846 for (; sec
!= NULL
; sec
= sec
->next
)
848 if (sec
->reloc_count
== 0)
851 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
853 /* Load the relocs. */
855 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
856 (Elf_Internal_Rela
*) NULL
, FALSE
);
858 if (internal_relocs
== NULL
)
861 irelend
= internal_relocs
+ sec
->reloc_count
;
862 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
865 unsigned long r_index
;
867 struct elf_link_hash_entry
*h
;
869 r_type
= ELF32_R_TYPE (irel
->r_info
);
870 r_index
= ELF32_R_SYM (irel
->r_info
);
872 /* These are the only relocation types we care about. */
873 if ( r_type
!= R_ARM_PC24
874 && r_type
!= R_ARM_THM_PC22
)
877 /* Get the section contents if we haven't done so already. */
878 if (contents
== NULL
)
880 /* Get cached copy if it exists. */
881 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
882 contents
= elf_section_data (sec
)->this_hdr
.contents
;
885 /* Go get them off disk. */
886 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
887 if (contents
== NULL
)
890 if (!bfd_get_section_contents (abfd
, sec
, contents
,
891 (file_ptr
) 0, sec
->_raw_size
))
896 /* If the relocation is not against a symbol it cannot concern us. */
899 /* We don't care about local symbols. */
900 if (r_index
< symtab_hdr
->sh_info
)
903 /* This is an external symbol. */
904 r_index
-= symtab_hdr
->sh_info
;
905 h
= (struct elf_link_hash_entry
*)
906 elf_sym_hashes (abfd
)[r_index
];
908 /* If the relocation is against a static symbol it must be within
909 the current section and so cannot be a cross ARM/Thumb relocation. */
916 /* This one is a call from arm code. We need to look up
917 the target of the call. If it is a thumb target, we
919 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
920 record_arm_to_thumb_glue (link_info
, h
);
924 /* This one is a call from thumb code. We look
925 up the target of the call. If it is not a thumb
926 target, we insert glue. */
927 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
928 record_thumb_to_arm_glue (link_info
, h
);
937 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
941 if (internal_relocs
!= NULL
942 && elf_section_data (sec
)->relocs
!= internal_relocs
)
943 free (internal_relocs
);
944 internal_relocs
= NULL
;
951 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
953 if (internal_relocs
!= NULL
954 && elf_section_data (sec
)->relocs
!= internal_relocs
)
955 free (internal_relocs
);
961 /* The thumb form of a long branch is a bit finicky, because the offset
962 encoding is split over two fields, each in it's own instruction. They
963 can occur in any order. So given a thumb form of long branch, and an
964 offset, insert the offset into the thumb branch and return finished
967 It takes two thumb instructions to encode the target address. Each has
968 11 bits to invest. The upper 11 bits are stored in one (identified by
969 H-0.. see below), the lower 11 bits are stored in the other (identified
972 Combine together and shifted left by 1 (it's a half word address) and
976 H-0, upper address-0 = 000
978 H-1, lower address-0 = 800
980 They can be ordered either way, but the arm tools I've seen always put
981 the lower one first. It probably doesn't matter. krk@cygnus.com
983 XXX: Actually the order does matter. The second instruction (H-1)
984 moves the computed address into the PC, so it must be the second one
985 in the sequence. The problem, however is that whilst little endian code
986 stores the instructions in HI then LOW order, big endian code does the
987 reverse. nickc@cygnus.com. */
989 #define LOW_HI_ORDER 0xF800F000
990 #define HI_LOW_ORDER 0xF000F800
993 insert_thumb_branch (br_insn
, rel_off
)
997 unsigned int low_bits
;
998 unsigned int high_bits
;
1000 BFD_ASSERT ((rel_off
& 1) != 1);
1002 rel_off
>>= 1; /* Half word aligned address. */
1003 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
1004 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
1006 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
1007 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
1008 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
1009 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
1011 /* FIXME: abort is probably not the right call. krk@cygnus.com */
1012 abort (); /* error - not a valid branch instruction form. */
1017 /* Thumb code calling an ARM function. */
1020 elf32_thumb_to_arm_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1021 hit_data
, sym_sec
, offset
, addend
, val
)
1022 struct bfd_link_info
* info
;
1026 asection
* input_section
;
1027 bfd_byte
* hit_data
;
1030 bfd_signed_vma addend
;
1035 unsigned long int tmp
;
1036 long int ret_offset
;
1037 struct elf_link_hash_entry
* myh
;
1038 struct elf32_arm_link_hash_table
* globals
;
1040 myh
= find_thumb_glue (info
, name
, input_bfd
);
1044 globals
= elf32_arm_hash_table (info
);
1046 BFD_ASSERT (globals
!= NULL
);
1047 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1049 my_offset
= myh
->root
.u
.def
.value
;
1051 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1052 THUMB2ARM_GLUE_SECTION_NAME
);
1054 BFD_ASSERT (s
!= NULL
);
1055 BFD_ASSERT (s
->contents
!= NULL
);
1056 BFD_ASSERT (s
->output_section
!= NULL
);
1058 if ((my_offset
& 0x01) == 0x01)
1061 && sym_sec
->owner
!= NULL
1062 && !INTERWORK_FLAG (sym_sec
->owner
))
1064 (*_bfd_error_handler
)
1065 (_("%s(%s): warning: interworking not enabled."),
1066 bfd_archive_filename (sym_sec
->owner
), name
);
1067 (*_bfd_error_handler
)
1068 (_(" first occurrence: %s: thumb call to arm"),
1069 bfd_archive_filename (input_bfd
));
1075 myh
->root
.u
.def
.value
= my_offset
;
1077 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
1078 s
->contents
+ my_offset
);
1080 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
1081 s
->contents
+ my_offset
+ 2);
1084 /* Address of destination of the stub. */
1085 ((bfd_signed_vma
) val
)
1087 /* Offset from the start of the current section to the start of the stubs. */
1089 /* Offset of the start of this stub from the start of the stubs. */
1091 /* Address of the start of the current section. */
1092 + s
->output_section
->vma
)
1093 /* The branch instruction is 4 bytes into the stub. */
1095 /* ARM branches work from the pc of the instruction + 8. */
1098 bfd_put_32 (output_bfd
,
1099 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1100 s
->contents
+ my_offset
+ 4);
1103 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
1105 /* Now go back and fix up the original BL insn to point to here. */
1107 /* Address of where the stub is located. */
1108 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
1109 /* Address of where the BL is located. */
1110 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ offset
)
1111 /* Addend in the relocation. */
1113 /* Biassing for PC-relative addressing. */
1116 tmp
= bfd_get_32 (input_bfd
, hit_data
1117 - input_section
->vma
);
1119 bfd_put_32 (output_bfd
,
1120 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1121 hit_data
- input_section
->vma
);
1126 /* Arm code calling a Thumb function. */
1129 elf32_arm_to_thumb_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1130 hit_data
, sym_sec
, offset
, addend
, val
)
1131 struct bfd_link_info
* info
;
1135 asection
* input_section
;
1136 bfd_byte
* hit_data
;
1139 bfd_signed_vma addend
;
1142 unsigned long int tmp
;
1145 long int ret_offset
;
1146 struct elf_link_hash_entry
* myh
;
1147 struct elf32_arm_link_hash_table
* globals
;
1149 myh
= find_arm_glue (info
, name
, input_bfd
);
1153 globals
= elf32_arm_hash_table (info
);
1155 BFD_ASSERT (globals
!= NULL
);
1156 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1158 my_offset
= myh
->root
.u
.def
.value
;
1159 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1160 ARM2THUMB_GLUE_SECTION_NAME
);
1161 BFD_ASSERT (s
!= NULL
);
1162 BFD_ASSERT (s
->contents
!= NULL
);
1163 BFD_ASSERT (s
->output_section
!= NULL
);
1165 if ((my_offset
& 0x01) == 0x01)
1168 && sym_sec
->owner
!= NULL
1169 && !INTERWORK_FLAG (sym_sec
->owner
))
1171 (*_bfd_error_handler
)
1172 (_("%s(%s): warning: interworking not enabled."),
1173 bfd_archive_filename (sym_sec
->owner
), name
);
1174 (*_bfd_error_handler
)
1175 (_(" first occurrence: %s: arm call to thumb"),
1176 bfd_archive_filename (input_bfd
));
1180 myh
->root
.u
.def
.value
= my_offset
;
1182 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1183 s
->contents
+ my_offset
);
1185 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1186 s
->contents
+ my_offset
+ 4);
1188 /* It's a thumb address. Add the low order bit. */
1189 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1190 s
->contents
+ my_offset
+ 8);
1193 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1195 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1196 tmp
= tmp
& 0xFF000000;
1198 /* Somehow these are both 4 too far, so subtract 8. */
1199 ret_offset
= (s
->output_offset
1201 + s
->output_section
->vma
1202 - (input_section
->output_offset
1203 + input_section
->output_section
->vma
1207 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1209 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1214 /* This is the condition under which elf32_arm_finish_dynamic_symbol
1215 will be called from elflink.h. If elflink.h doesn't call our
1216 finish_dynamic_symbol routine, we'll need to do something about
1217 initializing any .plt and .got entries in elf32_arm_relocate_section
1218 and elf32_arm_final_link_relocate. */
1219 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
1222 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1223 && ((H)->dynindx != -1 \
1224 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1226 /* Perform a relocation as part of a final link. */
1228 static bfd_reloc_status_type
1229 elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
1230 input_section
, contents
, rel
, value
,
1231 info
, sym_sec
, sym_name
, sym_flags
, h
)
1232 reloc_howto_type
* howto
;
1235 asection
* input_section
;
1236 bfd_byte
* contents
;
1237 Elf_Internal_Rela
* rel
;
1239 struct bfd_link_info
* info
;
1241 const char * sym_name
;
1243 struct elf_link_hash_entry
* h
;
1245 unsigned long r_type
= howto
->type
;
1246 unsigned long r_symndx
;
1247 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1248 bfd
* dynobj
= NULL
;
1249 Elf_Internal_Shdr
* symtab_hdr
;
1250 struct elf_link_hash_entry
** sym_hashes
;
1251 bfd_vma
* local_got_offsets
;
1252 asection
* sgot
= NULL
;
1253 asection
* splt
= NULL
;
1254 asection
* sreloc
= NULL
;
1256 bfd_signed_vma signed_addend
;
1257 struct elf32_arm_link_hash_table
* globals
;
1259 /* If the start address has been set, then set the EF_ARM_HASENTRY
1260 flag. Setting this more than once is redundant, but the cost is
1261 not too high, and it keeps the code simple.
1263 The test is done here, rather than somewhere else, because the
1264 start address is only set just before the final link commences.
1266 Note - if the user deliberately sets a start address of 0, the
1267 flag will not be set. */
1268 if (bfd_get_start_address (output_bfd
) != 0)
1269 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1271 globals
= elf32_arm_hash_table (info
);
1273 dynobj
= elf_hash_table (info
)->dynobj
;
1276 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1277 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1279 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1280 sym_hashes
= elf_sym_hashes (input_bfd
);
1281 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1282 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1285 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1287 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1290 signed_addend
&= ~ howto
->src_mask
;
1291 signed_addend
|= addend
;
1294 signed_addend
= addend
;
1296 addend
= signed_addend
= rel
->r_addend
;
1302 return bfd_reloc_ok
;
1310 /* r_symndx will be zero only for relocs against symbols
1311 from removed linkonce sections, or sections discarded by
1314 return bfd_reloc_ok
;
1316 /* When generating a shared object, these relocations are copied
1317 into the output file to be resolved at run time. */
1319 && (input_section
->flags
& SEC_ALLOC
)
1321 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1322 || h
->root
.type
!= bfd_link_hash_undefweak
)
1323 && (r_type
!= R_ARM_PC24
1324 || !SYMBOL_CALLS_LOCAL (info
, h
))))
1326 Elf_Internal_Rela outrel
;
1328 bfd_boolean skip
, relocate
;
1334 name
= (bfd_elf_string_from_elf_section
1336 elf_elfheader (input_bfd
)->e_shstrndx
,
1337 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1339 return bfd_reloc_notsupported
;
1341 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1342 && strcmp (bfd_get_section_name (input_bfd
,
1346 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1347 BFD_ASSERT (sreloc
!= NULL
);
1354 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1356 if (outrel
.r_offset
== (bfd_vma
) -1)
1358 else if (outrel
.r_offset
== (bfd_vma
) -2)
1359 skip
= TRUE
, relocate
= TRUE
;
1360 outrel
.r_offset
+= (input_section
->output_section
->vma
1361 + input_section
->output_offset
);
1364 memset (&outrel
, 0, sizeof outrel
);
1367 && (r_type
== R_ARM_PC24
1370 || (h
->elf_link_hash_flags
1371 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1372 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1375 /* This symbol is local, or marked to become local. */
1377 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1380 loc
= sreloc
->contents
;
1381 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1382 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1384 /* If this reloc is against an external symbol, we do not want to
1385 fiddle with the addend. Otherwise, we need to include the symbol
1386 value so that it becomes an addend for the dynamic reloc. */
1388 return bfd_reloc_ok
;
1390 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1391 contents
, rel
->r_offset
, value
,
1394 else switch (r_type
)
1397 case R_ARM_XPC25
: /* Arm BLX instruction. */
1399 case R_ARM_PC24
: /* Arm B/BL instruction */
1401 if (r_type
== R_ARM_XPC25
)
1403 /* Check for Arm calling Arm function. */
1404 /* FIXME: Should we translate the instruction into a BL
1405 instruction instead ? */
1406 if (sym_flags
!= STT_ARM_TFUNC
)
1407 (*_bfd_error_handler
) (_("\
1408 %s: Warning: Arm BLX instruction targets Arm function '%s'."),
1409 bfd_archive_filename (input_bfd
),
1410 h
? h
->root
.root
.string
: "(local)");
1415 /* Check for Arm calling Thumb function. */
1416 if (sym_flags
== STT_ARM_TFUNC
)
1418 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
, output_bfd
,
1419 input_section
, hit_data
, sym_sec
, rel
->r_offset
,
1420 signed_addend
, value
);
1421 return bfd_reloc_ok
;
1425 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1426 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1428 /* The old way of doing things. Trearing the addend as a
1429 byte sized field and adding in the pipeline offset. */
1430 value
-= (input_section
->output_section
->vma
1431 + input_section
->output_offset
);
1432 value
-= rel
->r_offset
;
1435 if (! globals
->no_pipeline_knowledge
)
1440 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1442 S is the address of the symbol in the relocation.
1443 P is address of the instruction being relocated.
1444 A is the addend (extracted from the instruction) in bytes.
1446 S is held in 'value'.
1447 P is the base address of the section containing the instruction
1448 plus the offset of the reloc into that section, ie:
1449 (input_section->output_section->vma +
1450 input_section->output_offset +
1452 A is the addend, converted into bytes, ie:
1455 Note: None of these operations have knowledge of the pipeline
1456 size of the processor, thus it is up to the assembler to encode
1457 this information into the addend. */
1458 value
-= (input_section
->output_section
->vma
1459 + input_section
->output_offset
);
1460 value
-= rel
->r_offset
;
1461 value
+= (signed_addend
<< howto
->size
);
1463 /* Previous versions of this code also used to add in the pipeline
1464 offset here. This is wrong because the linker is not supposed
1465 to know about such things, and one day it might change. In order
1466 to support old binaries that need the old behaviour however, so
1467 we attempt to detect which ABI was used to create the reloc. */
1468 if (! globals
->no_pipeline_knowledge
)
1470 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1472 i_ehdrp
= elf_elfheader (input_bfd
);
1474 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1479 signed_addend
= value
;
1480 signed_addend
>>= howto
->rightshift
;
1482 /* It is not an error for an undefined weak reference to be
1483 out of range. Any program that branches to such a symbol
1484 is going to crash anyway, so there is no point worrying
1485 about getting the destination exactly right. */
1486 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1488 /* Perform a signed range check. */
1489 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1490 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1491 return bfd_reloc_overflow
;
1495 /* If necessary set the H bit in the BLX instruction. */
1496 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1497 value
= (signed_addend
& howto
->dst_mask
)
1498 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1502 value
= (signed_addend
& howto
->dst_mask
)
1503 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1508 if (sym_flags
== STT_ARM_TFUNC
)
1513 value
-= (input_section
->output_section
->vma
1514 + input_section
->output_offset
+ rel
->r_offset
);
1519 bfd_put_32 (input_bfd
, value
, hit_data
);
1520 return bfd_reloc_ok
;
1524 if ((long) value
> 0x7f || (long) value
< -0x80)
1525 return bfd_reloc_overflow
;
1527 bfd_put_8 (input_bfd
, value
, hit_data
);
1528 return bfd_reloc_ok
;
1533 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1534 return bfd_reloc_overflow
;
1536 bfd_put_16 (input_bfd
, value
, hit_data
);
1537 return bfd_reloc_ok
;
1540 /* Support ldr and str instruction for the arm */
1541 /* Also thumb b (unconditional branch). ??? Really? */
1544 if ((long) value
> 0x7ff || (long) value
< -0x800)
1545 return bfd_reloc_overflow
;
1547 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1548 bfd_put_32 (input_bfd
, value
, hit_data
);
1549 return bfd_reloc_ok
;
1551 case R_ARM_THM_ABS5
:
1552 /* Support ldr and str instructions for the thumb. */
1554 /* Need to refetch addend. */
1555 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1556 /* ??? Need to determine shift amount from operand size. */
1557 addend
>>= howto
->rightshift
;
1561 /* ??? Isn't value unsigned? */
1562 if ((long) value
> 0x1f || (long) value
< -0x10)
1563 return bfd_reloc_overflow
;
1565 /* ??? Value needs to be properly shifted into place first. */
1566 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1567 bfd_put_16 (input_bfd
, value
, hit_data
);
1568 return bfd_reloc_ok
;
1571 case R_ARM_THM_XPC22
:
1573 case R_ARM_THM_PC22
:
1574 /* Thumb BL (branch long instruction). */
1577 bfd_boolean overflow
= FALSE
;
1578 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1579 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1580 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1581 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1583 bfd_signed_vma signed_check
;
1586 /* Need to refetch the addend and squish the two 11 bit pieces
1589 bfd_vma upper
= upper_insn
& 0x7ff;
1590 bfd_vma lower
= lower_insn
& 0x7ff;
1591 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1592 addend
= (upper
<< 12) | (lower
<< 1);
1593 signed_addend
= addend
;
1597 if (r_type
== R_ARM_THM_XPC22
)
1599 /* Check for Thumb to Thumb call. */
1600 /* FIXME: Should we translate the instruction into a BL
1601 instruction instead ? */
1602 if (sym_flags
== STT_ARM_TFUNC
)
1603 (*_bfd_error_handler
) (_("\
1604 %s: Warning: Thumb BLX instruction targets thumb function '%s'."),
1605 bfd_archive_filename (input_bfd
),
1606 h
? h
->root
.root
.string
: "(local)");
1611 /* If it is not a call to Thumb, assume call to Arm.
1612 If it is a call relative to a section name, then it is not a
1613 function call at all, but rather a long jump. */
1614 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1616 if (elf32_thumb_to_arm_stub
1617 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1618 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1619 return bfd_reloc_ok
;
1621 return bfd_reloc_dangerous
;
1625 relocation
= value
+ signed_addend
;
1627 relocation
-= (input_section
->output_section
->vma
1628 + input_section
->output_offset
1631 if (! globals
->no_pipeline_knowledge
)
1633 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1635 i_ehdrp
= elf_elfheader (input_bfd
);
1637 /* Previous versions of this code also used to add in the pipline
1638 offset here. This is wrong because the linker is not supposed
1639 to know about such things, and one day it might change. In order
1640 to support old binaries that need the old behaviour however, so
1641 we attempt to detect which ABI was used to create the reloc. */
1642 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1643 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1644 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1648 check
= relocation
>> howto
->rightshift
;
1650 /* If this is a signed value, the rightshift just dropped
1651 leading 1 bits (assuming twos complement). */
1652 if ((bfd_signed_vma
) relocation
>= 0)
1653 signed_check
= check
;
1655 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1657 /* Assumes two's complement. */
1658 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1662 if (r_type
== R_ARM_THM_XPC22
1663 && ((lower_insn
& 0x1800) == 0x0800))
1664 /* For a BLX instruction, make sure that the relocation is rounded up
1665 to a word boundary. This follows the semantics of the instruction
1666 which specifies that bit 1 of the target address will come from bit
1667 1 of the base address. */
1668 relocation
= (relocation
+ 2) & ~ 3;
1670 /* Put RELOCATION back into the insn. */
1671 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1672 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1674 /* Put the relocated value back in the object file: */
1675 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1676 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1678 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1682 case R_ARM_THM_PC11
:
1683 /* Thumb B (branch) instruction). */
1685 bfd_signed_vma relocation
;
1686 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1687 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1688 bfd_signed_vma signed_check
;
1691 /* Need to refetch addend. */
1692 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1693 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1696 signed_addend
&= ~ howto
->src_mask
;
1697 signed_addend
|= addend
;
1700 signed_addend
= addend
;
1701 /* The value in the insn has been right shifted. We need to
1702 undo this, so that we can perform the address calculation
1703 in terms of bytes. */
1704 signed_addend
<<= howto
->rightshift
;
1706 relocation
= value
+ signed_addend
;
1708 relocation
-= (input_section
->output_section
->vma
1709 + input_section
->output_offset
1712 relocation
>>= howto
->rightshift
;
1713 signed_check
= relocation
;
1714 relocation
&= howto
->dst_mask
;
1715 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1717 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1719 /* Assumes two's complement. */
1720 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1721 return bfd_reloc_overflow
;
1723 return bfd_reloc_ok
;
1726 case R_ARM_GNU_VTINHERIT
:
1727 case R_ARM_GNU_VTENTRY
:
1728 return bfd_reloc_ok
;
1731 return bfd_reloc_notsupported
;
1733 case R_ARM_GLOB_DAT
:
1734 return bfd_reloc_notsupported
;
1736 case R_ARM_JUMP_SLOT
:
1737 return bfd_reloc_notsupported
;
1739 case R_ARM_RELATIVE
:
1740 return bfd_reloc_notsupported
;
1743 /* Relocation is relative to the start of the
1744 global offset table. */
1746 BFD_ASSERT (sgot
!= NULL
);
1748 return bfd_reloc_notsupported
;
1750 /* If we are addressing a Thumb function, we need to adjust the
1751 address by one, so that attempts to call the function pointer will
1752 correctly interpret it as Thumb code. */
1753 if (sym_flags
== STT_ARM_TFUNC
)
1756 /* Note that sgot->output_offset is not involved in this
1757 calculation. We always want the start of .got. If we
1758 define _GLOBAL_OFFSET_TABLE in a different way, as is
1759 permitted by the ABI, we might have to change this
1761 value
-= sgot
->output_section
->vma
;
1762 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1763 contents
, rel
->r_offset
, value
,
1767 /* Use global offset table as symbol value. */
1768 BFD_ASSERT (sgot
!= NULL
);
1771 return bfd_reloc_notsupported
;
1773 value
= sgot
->output_section
->vma
;
1774 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1775 contents
, rel
->r_offset
, value
,
1779 /* Relocation is to the entry for this symbol in the
1780 global offset table. */
1782 return bfd_reloc_notsupported
;
1789 off
= h
->got
.offset
;
1790 BFD_ASSERT (off
!= (bfd_vma
) -1);
1791 dyn
= globals
->root
.dynamic_sections_created
;
1793 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1795 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1796 || (ELF_ST_VISIBILITY (h
->other
)
1797 && h
->root
.type
== bfd_link_hash_undefweak
))
1799 /* This is actually a static link, or it is a -Bsymbolic link
1800 and the symbol is defined locally. We must initialize this
1801 entry in the global offset table. Since the offset must
1802 always be a multiple of 4, we use the least significant bit
1803 to record whether we have initialized it already.
1805 When doing a dynamic link, we create a .rel.got relocation
1806 entry to initialize the value. This is done in the
1807 finish_dynamic_symbol routine. */
1812 /* If we are addressing a Thumb function, we need to
1813 adjust the address by one, so that attempts to
1814 call the function pointer will correctly
1815 interpret it as Thumb code. */
1816 if (sym_flags
== STT_ARM_TFUNC
)
1819 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1824 value
= sgot
->output_offset
+ off
;
1830 BFD_ASSERT (local_got_offsets
!= NULL
&&
1831 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1833 off
= local_got_offsets
[r_symndx
];
1835 /* The offset must always be a multiple of 4. We use the
1836 least significant bit to record whether we have already
1837 generated the necessary reloc. */
1842 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1847 Elf_Internal_Rela outrel
;
1850 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1851 BFD_ASSERT (srelgot
!= NULL
);
1853 outrel
.r_offset
= (sgot
->output_section
->vma
1854 + sgot
->output_offset
1856 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1857 loc
= srelgot
->contents
;
1858 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1859 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1862 local_got_offsets
[r_symndx
] |= 1;
1865 value
= sgot
->output_offset
+ off
;
1868 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1869 contents
, rel
->r_offset
, value
,
1873 /* Relocation is to the entry for this symbol in the
1874 procedure linkage table. */
1876 /* Resolve a PLT32 reloc against a local symbol directly,
1877 without using the procedure linkage table. */
1879 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1880 contents
, rel
->r_offset
, value
,
1883 if (h
->plt
.offset
== (bfd_vma
) -1
1884 || globals
->splt
== NULL
)
1885 /* We didn't make a PLT entry for this symbol. This
1886 happens when statically linking PIC code, or when
1887 using -Bsymbolic. */
1888 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1889 contents
, rel
->r_offset
, value
,
1892 BFD_ASSERT(splt
!= NULL
);
1894 return bfd_reloc_notsupported
;
1896 value
= (splt
->output_section
->vma
1897 + splt
->output_offset
1899 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1900 contents
, rel
->r_offset
, value
,
1904 return bfd_reloc_notsupported
;
1906 case R_ARM_AMP_VCALL9
:
1907 return bfd_reloc_notsupported
;
1909 case R_ARM_RSBREL32
:
1910 return bfd_reloc_notsupported
;
1912 case R_ARM_THM_RPC22
:
1913 return bfd_reloc_notsupported
;
1916 return bfd_reloc_notsupported
;
1919 return bfd_reloc_notsupported
;
1922 return bfd_reloc_notsupported
;
1925 return bfd_reloc_notsupported
;
1928 return bfd_reloc_notsupported
;
1933 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1935 arm_add_to_rel (abfd
, address
, howto
, increment
)
1938 reloc_howto_type
* howto
;
1939 bfd_signed_vma increment
;
1941 bfd_signed_vma addend
;
1943 if (howto
->type
== R_ARM_THM_PC22
)
1945 int upper_insn
, lower_insn
;
1948 upper_insn
= bfd_get_16 (abfd
, address
);
1949 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1950 upper
= upper_insn
& 0x7ff;
1951 lower
= lower_insn
& 0x7ff;
1953 addend
= (upper
<< 12) | (lower
<< 1);
1954 addend
+= increment
;
1957 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
1958 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
1960 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
1961 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
1967 contents
= bfd_get_32 (abfd
, address
);
1969 /* Get the (signed) value from the instruction. */
1970 addend
= contents
& howto
->src_mask
;
1971 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1973 bfd_signed_vma mask
;
1976 mask
&= ~ howto
->src_mask
;
1980 /* Add in the increment, (which is a byte value). */
1981 switch (howto
->type
)
1984 addend
+= increment
;
1988 addend
<<= howto
->size
;
1989 addend
+= increment
;
1991 /* Should we check for overflow here ? */
1993 /* Drop any undesired bits. */
1994 addend
>>= howto
->rightshift
;
1998 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2000 bfd_put_32 (abfd
, contents
, address
);
2003 #endif /* USE_REL */
2005 /* Relocate an ARM ELF section. */
2007 elf32_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2008 contents
, relocs
, local_syms
, local_sections
)
2010 struct bfd_link_info
*info
;
2012 asection
*input_section
;
2014 Elf_Internal_Rela
*relocs
;
2015 Elf_Internal_Sym
*local_syms
;
2016 asection
**local_sections
;
2018 Elf_Internal_Shdr
*symtab_hdr
;
2019 struct elf_link_hash_entry
**sym_hashes
;
2020 Elf_Internal_Rela
*rel
;
2021 Elf_Internal_Rela
*relend
;
2025 if (info
->relocatable
)
2029 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2030 sym_hashes
= elf_sym_hashes (input_bfd
);
2033 relend
= relocs
+ input_section
->reloc_count
;
2034 for (; rel
< relend
; rel
++)
2037 reloc_howto_type
* howto
;
2038 unsigned long r_symndx
;
2039 Elf_Internal_Sym
* sym
;
2041 struct elf_link_hash_entry
* h
;
2043 bfd_reloc_status_type r
;
2046 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2047 r_type
= ELF32_R_TYPE (rel
->r_info
);
2049 if ( r_type
== R_ARM_GNU_VTENTRY
2050 || r_type
== R_ARM_GNU_VTINHERIT
)
2053 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
2054 howto
= bfd_reloc
.howto
;
2057 if (info
->relocatable
)
2059 /* This is a relocatable link. We don't have to change
2060 anything, unless the reloc is against a section symbol,
2061 in which case we have to adjust according to where the
2062 section symbol winds up in the output section. */
2063 if (r_symndx
< symtab_hdr
->sh_info
)
2065 sym
= local_syms
+ r_symndx
;
2066 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2068 sec
= local_sections
[r_symndx
];
2069 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2071 (bfd_signed_vma
) (sec
->output_offset
2080 /* This is a final link. */
2085 if (r_symndx
< symtab_hdr
->sh_info
)
2087 sym
= local_syms
+ r_symndx
;
2088 sec
= local_sections
[r_symndx
];
2090 relocation
= (sec
->output_section
->vma
2091 + sec
->output_offset
2093 if ((sec
->flags
& SEC_MERGE
)
2094 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2097 bfd_vma addend
, value
;
2099 if (howto
->rightshift
)
2101 (*_bfd_error_handler
)
2102 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
2103 bfd_archive_filename (input_bfd
),
2104 bfd_get_section_name (input_bfd
, input_section
),
2105 (long) rel
->r_offset
, howto
->name
);
2109 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2111 /* Get the (signed) value from the instruction. */
2112 addend
= value
& howto
->src_mask
;
2113 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2115 bfd_signed_vma mask
;
2118 mask
&= ~ howto
->src_mask
;
2123 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2125 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2126 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2127 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2130 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2136 bfd_boolean unresolved_reloc
;
2138 RELOC_FOR_GLOBAL_SYMBOL (h
, sym_hashes
, r_symndx
,
2139 symtab_hdr
, relocation
,
2140 sec
, unresolved_reloc
, info
,
2143 if (unresolved_reloc
|| relocation
!= 0)
2145 /* In these cases, we don't need the relocation value.
2146 We check specially because in some obscure cases
2147 sec->output_section will be NULL. */
2152 case R_ARM_THM_PC22
:
2155 (!info
->symbolic
&& h
->dynindx
!= -1)
2156 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2158 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2159 && ((input_section
->flags
& SEC_ALLOC
) != 0
2160 /* DWARF will emit R_ARM_ABS32 relocations in its
2161 sections against symbols defined externally
2162 in shared libraries. We can't do anything
2164 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2165 && (h
->elf_link_hash_flags
2166 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2176 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
2177 (elf_hash_table (info
)->dynamic_sections_created
,
2180 || (!info
->symbolic
&& h
->dynindx
!= -1)
2181 || (h
->elf_link_hash_flags
2182 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2187 if (h
->plt
.offset
!= (bfd_vma
)-1)
2192 if (unresolved_reloc
)
2194 (_("%s: warning: unresolvable relocation %d against symbol `%s' from %s section"),
2195 bfd_archive_filename (input_bfd
),
2197 h
->root
.root
.string
,
2198 bfd_get_section_name (input_bfd
, input_section
));
2205 name
= h
->root
.root
.string
;
2208 name
= (bfd_elf_string_from_elf_section
2209 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2210 if (name
== NULL
|| *name
== '\0')
2211 name
= bfd_section_name (input_bfd
, sec
);
2214 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2215 input_section
, contents
, rel
,
2216 relocation
, info
, sec
, name
,
2217 (h
? ELF_ST_TYPE (h
->type
) :
2218 ELF_ST_TYPE (sym
->st_info
)), h
);
2220 if (r
!= bfd_reloc_ok
)
2222 const char * msg
= (const char *) 0;
2226 case bfd_reloc_overflow
:
2227 /* If the overflowing reloc was to an undefined symbol,
2228 we have already printed one error message and there
2229 is no point complaining again. */
2231 h
->root
.type
!= bfd_link_hash_undefined
)
2232 && (!((*info
->callbacks
->reloc_overflow
)
2233 (info
, name
, howto
->name
, (bfd_vma
) 0,
2234 input_bfd
, input_section
, rel
->r_offset
))))
2238 case bfd_reloc_undefined
:
2239 if (!((*info
->callbacks
->undefined_symbol
)
2240 (info
, name
, input_bfd
, input_section
,
2241 rel
->r_offset
, TRUE
)))
2245 case bfd_reloc_outofrange
:
2246 msg
= _("internal error: out of range error");
2249 case bfd_reloc_notsupported
:
2250 msg
= _("internal error: unsupported relocation error");
2253 case bfd_reloc_dangerous
:
2254 msg
= _("internal error: dangerous error");
2258 msg
= _("internal error: unknown error");
2262 if (!((*info
->callbacks
->warning
)
2263 (info
, msg
, name
, input_bfd
, input_section
,
2274 /* Set the right machine number. */
2277 elf32_arm_object_p (abfd
)
2282 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2284 if (mach
!= bfd_mach_arm_unknown
)
2285 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2287 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
2288 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
2291 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2296 /* Function to keep ARM specific flags in the ELF header. */
2298 elf32_arm_set_private_flags (abfd
, flags
)
2302 if (elf_flags_init (abfd
)
2303 && elf_elfheader (abfd
)->e_flags
!= flags
)
2305 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2307 if (flags
& EF_ARM_INTERWORK
)
2308 (*_bfd_error_handler
) (_("\
2309 Warning: Not setting interworking flag of %s since it has already been specified as non-interworking"),
2310 bfd_archive_filename (abfd
));
2312 _bfd_error_handler (_("\
2313 Warning: Clearing the interworking flag of %s due to outside request"),
2314 bfd_archive_filename (abfd
));
2319 elf_elfheader (abfd
)->e_flags
= flags
;
2320 elf_flags_init (abfd
) = TRUE
;
2326 /* Copy backend specific data from one object module to another. */
2329 elf32_arm_copy_private_bfd_data (ibfd
, obfd
)
2336 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2337 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2340 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2341 out_flags
= elf_elfheader (obfd
)->e_flags
;
2343 if (elf_flags_init (obfd
)
2344 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2345 && in_flags
!= out_flags
)
2347 /* Cannot mix APCS26 and APCS32 code. */
2348 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2351 /* Cannot mix float APCS and non-float APCS code. */
2352 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2355 /* If the src and dest have different interworking flags
2356 then turn off the interworking bit. */
2357 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2359 if (out_flags
& EF_ARM_INTERWORK
)
2360 _bfd_error_handler (_("\
2361 Warning: Clearing the interworking flag of %s because non-interworking code in %s has been linked with it"),
2362 bfd_get_filename (obfd
),
2363 bfd_archive_filename (ibfd
));
2365 in_flags
&= ~EF_ARM_INTERWORK
;
2368 /* Likewise for PIC, though don't warn for this case. */
2369 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2370 in_flags
&= ~EF_ARM_PIC
;
2373 elf_elfheader (obfd
)->e_flags
= in_flags
;
2374 elf_flags_init (obfd
) = TRUE
;
2379 /* Merge backend specific data from an object file to the output
2380 object file when linking. */
2383 elf32_arm_merge_private_bfd_data (ibfd
, obfd
)
2389 bfd_boolean flags_compatible
= TRUE
;
2392 /* Check if we have the same endianess. */
2393 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2396 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2397 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2400 /* The input BFD must have had its flags initialised. */
2401 /* The following seems bogus to me -- The flags are initialized in
2402 the assembler but I don't think an elf_flags_init field is
2403 written into the object. */
2404 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2406 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2407 out_flags
= elf_elfheader (obfd
)->e_flags
;
2409 if (!elf_flags_init (obfd
))
2411 /* If the input is the default architecture and had the default
2412 flags then do not bother setting the flags for the output
2413 architecture, instead allow future merges to do this. If no
2414 future merges ever set these flags then they will retain their
2415 uninitialised values, which surprise surprise, correspond
2416 to the default values. */
2417 if (bfd_get_arch_info (ibfd
)->the_default
2418 && elf_elfheader (ibfd
)->e_flags
== 0)
2421 elf_flags_init (obfd
) = TRUE
;
2422 elf_elfheader (obfd
)->e_flags
= in_flags
;
2424 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2425 && bfd_get_arch_info (obfd
)->the_default
)
2426 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2431 /* Determine what should happen if the input ARM architecture
2432 does not match the output ARM architecture. */
2433 if (! bfd_arm_merge_machines (ibfd
, obfd
))
2436 /* Identical flags must be compatible. */
2437 if (in_flags
== out_flags
)
2440 /* Check to see if the input BFD actually contains any sections. If
2441 not, its flags may not have been initialised either, but it
2442 cannot actually cause any incompatibility. Do not short-circuit
2443 dynamic objects; their section list may be emptied by
2444 elf_link_add_object_symbols. */
2446 if (!(ibfd
->flags
& DYNAMIC
))
2448 bfd_boolean null_input_bfd
= TRUE
;
2450 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2452 /* Ignore synthetic glue sections. */
2453 if (strcmp (sec
->name
, ".glue_7")
2454 && strcmp (sec
->name
, ".glue_7t"))
2456 null_input_bfd
= FALSE
;
2464 /* Complain about various flag mismatches. */
2465 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2467 _bfd_error_handler (_("\
2468 ERROR: %s is compiled for EABI version %d, whereas %s is compiled for version %d"),
2469 bfd_archive_filename (ibfd
),
2470 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2471 bfd_get_filename (obfd
),
2472 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2476 /* Not sure what needs to be checked for EABI versions >= 1. */
2477 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2479 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2481 _bfd_error_handler (_("\
2482 ERROR: %s is compiled for APCS-%d, whereas target %s uses APCS-%d"),
2483 bfd_archive_filename (ibfd
),
2484 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2485 bfd_get_filename (obfd
),
2486 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2487 flags_compatible
= FALSE
;
2490 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2492 if (in_flags
& EF_ARM_APCS_FLOAT
)
2493 _bfd_error_handler (_("\
2494 ERROR: %s passes floats in float registers, whereas %s passes them in integer registers"),
2495 bfd_archive_filename (ibfd
),
2496 bfd_get_filename (obfd
));
2498 _bfd_error_handler (_("\
2499 ERROR: %s passes floats in integer registers, whereas %s passes them in float registers"),
2500 bfd_archive_filename (ibfd
),
2501 bfd_get_filename (obfd
));
2503 flags_compatible
= FALSE
;
2506 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2508 if (in_flags
& EF_ARM_VFP_FLOAT
)
2509 _bfd_error_handler (_("\
2510 ERROR: %s uses VFP instructions, whereas %s does not"),
2511 bfd_archive_filename (ibfd
),
2512 bfd_get_filename (obfd
));
2514 _bfd_error_handler (_("\
2515 ERROR: %s uses FPA instructions, whereas %s does not"),
2516 bfd_archive_filename (ibfd
),
2517 bfd_get_filename (obfd
));
2519 flags_compatible
= FALSE
;
2522 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
2524 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
2525 _bfd_error_handler (_("\
2526 ERROR: %s uses Maverick instructions, whereas %s does not"),
2527 bfd_archive_filename (ibfd
),
2528 bfd_get_filename (obfd
));
2530 _bfd_error_handler (_("\
2531 ERROR: %s does not use Maverick instructions, whereas %s does"),
2532 bfd_archive_filename (ibfd
),
2533 bfd_get_filename (obfd
));
2535 flags_compatible
= FALSE
;
2538 #ifdef EF_ARM_SOFT_FLOAT
2539 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2541 /* We can allow interworking between code that is VFP format
2542 layout, and uses either soft float or integer regs for
2543 passing floating point arguments and results. We already
2544 know that the APCS_FLOAT flags match; similarly for VFP
2546 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2547 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2549 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2550 _bfd_error_handler (_("\
2551 ERROR: %s uses software FP, whereas %s uses hardware FP"),
2552 bfd_archive_filename (ibfd
),
2553 bfd_get_filename (obfd
));
2555 _bfd_error_handler (_("\
2556 ERROR: %s uses hardware FP, whereas %s uses software FP"),
2557 bfd_archive_filename (ibfd
),
2558 bfd_get_filename (obfd
));
2560 flags_compatible
= FALSE
;
2565 /* Interworking mismatch is only a warning. */
2566 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2568 if (in_flags
& EF_ARM_INTERWORK
)
2570 _bfd_error_handler (_("\
2571 Warning: %s supports interworking, whereas %s does not"),
2572 bfd_archive_filename (ibfd
),
2573 bfd_get_filename (obfd
));
2577 _bfd_error_handler (_("\
2578 Warning: %s does not support interworking, whereas %s does"),
2579 bfd_archive_filename (ibfd
),
2580 bfd_get_filename (obfd
));
2585 return flags_compatible
;
2588 /* Display the flags field. */
2591 elf32_arm_print_private_bfd_data (abfd
, ptr
)
2595 FILE * file
= (FILE *) ptr
;
2596 unsigned long flags
;
2598 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2600 /* Print normal ELF private data. */
2601 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2603 flags
= elf_elfheader (abfd
)->e_flags
;
2604 /* Ignore init flag - it may not be set, despite the flags field
2605 containing valid data. */
2607 /* xgettext:c-format */
2608 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2610 switch (EF_ARM_EABI_VERSION (flags
))
2612 case EF_ARM_EABI_UNKNOWN
:
2613 /* The following flag bits are GNU extensions and not part of the
2614 official ARM ELF extended ABI. Hence they are only decoded if
2615 the EABI version is not set. */
2616 if (flags
& EF_ARM_INTERWORK
)
2617 fprintf (file
, _(" [interworking enabled]"));
2619 if (flags
& EF_ARM_APCS_26
)
2620 fprintf (file
, " [APCS-26]");
2622 fprintf (file
, " [APCS-32]");
2624 if (flags
& EF_ARM_VFP_FLOAT
)
2625 fprintf (file
, _(" [VFP float format]"));
2626 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
2627 fprintf (file
, _(" [Maverick float format]"));
2629 fprintf (file
, _(" [FPA float format]"));
2631 if (flags
& EF_ARM_APCS_FLOAT
)
2632 fprintf (file
, _(" [floats passed in float registers]"));
2634 if (flags
& EF_ARM_PIC
)
2635 fprintf (file
, _(" [position independent]"));
2637 if (flags
& EF_ARM_NEW_ABI
)
2638 fprintf (file
, _(" [new ABI]"));
2640 if (flags
& EF_ARM_OLD_ABI
)
2641 fprintf (file
, _(" [old ABI]"));
2643 if (flags
& EF_ARM_SOFT_FLOAT
)
2644 fprintf (file
, _(" [software FP]"));
2646 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2647 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2648 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
2649 | EF_ARM_MAVERICK_FLOAT
);
2652 case EF_ARM_EABI_VER1
:
2653 fprintf (file
, _(" [Version1 EABI]"));
2655 if (flags
& EF_ARM_SYMSARESORTED
)
2656 fprintf (file
, _(" [sorted symbol table]"));
2658 fprintf (file
, _(" [unsorted symbol table]"));
2660 flags
&= ~ EF_ARM_SYMSARESORTED
;
2663 case EF_ARM_EABI_VER2
:
2664 fprintf (file
, _(" [Version2 EABI]"));
2666 if (flags
& EF_ARM_SYMSARESORTED
)
2667 fprintf (file
, _(" [sorted symbol table]"));
2669 fprintf (file
, _(" [unsorted symbol table]"));
2671 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2672 fprintf (file
, _(" [dynamic symbols use segment index]"));
2674 if (flags
& EF_ARM_MAPSYMSFIRST
)
2675 fprintf (file
, _(" [mapping symbols precede others]"));
2677 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2678 | EF_ARM_MAPSYMSFIRST
);
2682 fprintf (file
, _(" <EABI version unrecognised>"));
2686 flags
&= ~ EF_ARM_EABIMASK
;
2688 if (flags
& EF_ARM_RELEXEC
)
2689 fprintf (file
, _(" [relocatable executable]"));
2691 if (flags
& EF_ARM_HASENTRY
)
2692 fprintf (file
, _(" [has entry point]"));
2694 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2697 fprintf (file
, _("<Unrecognised flag bits set>"));
2705 elf32_arm_get_symbol_type (elf_sym
, type
)
2706 Elf_Internal_Sym
* elf_sym
;
2709 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2712 return ELF_ST_TYPE (elf_sym
->st_info
);
2715 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2716 This allows us to distinguish between data used by Thumb instructions
2717 and non-data (which is probably code) inside Thumb regions of an
2719 if (type
!= STT_OBJECT
)
2720 return ELF_ST_TYPE (elf_sym
->st_info
);
2731 elf32_arm_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2733 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2734 Elf_Internal_Rela
*rel
;
2735 struct elf_link_hash_entry
*h
;
2736 Elf_Internal_Sym
*sym
;
2740 switch (ELF32_R_TYPE (rel
->r_info
))
2742 case R_ARM_GNU_VTINHERIT
:
2743 case R_ARM_GNU_VTENTRY
:
2747 switch (h
->root
.type
)
2749 case bfd_link_hash_defined
:
2750 case bfd_link_hash_defweak
:
2751 return h
->root
.u
.def
.section
;
2753 case bfd_link_hash_common
:
2754 return h
->root
.u
.c
.p
->section
;
2762 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2767 /* Update the got entry reference counts for the section being removed. */
2770 elf32_arm_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2771 bfd
*abfd ATTRIBUTE_UNUSED
;
2772 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2773 asection
*sec ATTRIBUTE_UNUSED
;
2774 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2776 Elf_Internal_Shdr
*symtab_hdr
;
2777 struct elf_link_hash_entry
**sym_hashes
;
2778 bfd_signed_vma
*local_got_refcounts
;
2779 const Elf_Internal_Rela
*rel
, *relend
;
2780 unsigned long r_symndx
;
2781 struct elf_link_hash_entry
*h
;
2783 elf_section_data (sec
)->local_dynrel
= NULL
;
2785 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2786 sym_hashes
= elf_sym_hashes (abfd
);
2787 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2789 relend
= relocs
+ sec
->reloc_count
;
2790 for (rel
= relocs
; rel
< relend
; rel
++)
2791 switch (ELF32_R_TYPE (rel
->r_info
))
2794 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2795 if (r_symndx
>= symtab_hdr
->sh_info
)
2797 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2798 if (h
->got
.refcount
> 0)
2799 h
->got
.refcount
-= 1;
2801 else if (local_got_refcounts
!= NULL
)
2803 if (local_got_refcounts
[r_symndx
] > 0)
2804 local_got_refcounts
[r_symndx
] -= 1;
2811 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2812 if (r_symndx
>= symtab_hdr
->sh_info
)
2814 struct elf32_arm_link_hash_entry
*eh
;
2815 struct elf32_arm_relocs_copied
**pp
;
2816 struct elf32_arm_relocs_copied
*p
;
2818 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2820 if (!info
->shared
&& h
->plt
.refcount
> 0)
2821 h
->plt
.refcount
-= 1;
2823 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2825 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2826 if (p
->section
== sec
)
2828 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
)
2839 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2840 if (r_symndx
>= symtab_hdr
->sh_info
)
2842 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2843 if (h
->plt
.refcount
> 0)
2844 h
->plt
.refcount
-= 1;
2855 /* Look through the relocs for a section during the first phase. */
2858 elf32_arm_check_relocs (abfd
, info
, sec
, relocs
)
2860 struct bfd_link_info
*info
;
2862 const Elf_Internal_Rela
*relocs
;
2864 Elf_Internal_Shdr
*symtab_hdr
;
2865 struct elf_link_hash_entry
**sym_hashes
;
2866 struct elf_link_hash_entry
**sym_hashes_end
;
2867 const Elf_Internal_Rela
*rel
;
2868 const Elf_Internal_Rela
*rel_end
;
2871 bfd_vma
*local_got_offsets
;
2872 struct elf32_arm_link_hash_table
*htab
;
2874 if (info
->relocatable
)
2877 htab
= elf32_arm_hash_table (info
);
2880 dynobj
= elf_hash_table (info
)->dynobj
;
2881 local_got_offsets
= elf_local_got_offsets (abfd
);
2883 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2884 sym_hashes
= elf_sym_hashes (abfd
);
2885 sym_hashes_end
= sym_hashes
2886 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2888 if (!elf_bad_symtab (abfd
))
2889 sym_hashes_end
-= symtab_hdr
->sh_info
;
2891 rel_end
= relocs
+ sec
->reloc_count
;
2892 for (rel
= relocs
; rel
< rel_end
; rel
++)
2894 struct elf_link_hash_entry
*h
;
2895 unsigned long r_symndx
;
2897 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2898 if (r_symndx
< symtab_hdr
->sh_info
)
2901 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2903 switch (ELF32_R_TYPE (rel
->r_info
))
2906 /* This symbol requires a procedure linkage table entry. We
2907 actually build the entry in adjust_dynamic_symbol,
2908 because this might be a case of linking PIC code which is
2909 never referenced by a dynamic object, in which case we
2910 don't need to generate a procedure linkage table entry
2913 /* If this is a local symbol, we resolve it directly without
2914 creating a procedure linkage table entry. */
2918 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2923 /* This symbol requires a global offset table entry. */
2930 bfd_signed_vma
*local_got_refcounts
;
2932 /* This is a global offset table entry for a local symbol. */
2933 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2934 if (local_got_refcounts
== NULL
)
2938 size
= symtab_hdr
->sh_info
;
2939 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
2940 local_got_refcounts
= ((bfd_signed_vma
*)
2941 bfd_zalloc (abfd
, size
));
2942 if (local_got_refcounts
== NULL
)
2944 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2946 local_got_refcounts
[r_symndx
] += 1;
2952 if (htab
->sgot
== NULL
)
2954 if (htab
->root
.dynobj
== NULL
)
2955 htab
->root
.dynobj
= abfd
;
2956 if (!create_got_section (htab
->root
.dynobj
, info
))
2964 if (h
!= NULL
&& !info
->shared
)
2966 /* If this reloc is in a read-only section, we might
2967 need a copy reloc. We can't check reliably at this
2968 stage whether the section is read-only, as input
2969 sections have not yet been mapped to output sections.
2970 Tentatively set the flag for now, and correct in
2971 adjust_dynamic_symbol. */
2972 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
2974 /* We may need a .plt entry if the function this reloc
2975 refers to is in a shared lib. */
2976 h
->plt
.refcount
+= 1;
2979 /* If we are creating a shared library, and this is a reloc
2980 against a global symbol, or a non PC relative reloc
2981 against a local symbol, then we need to copy the reloc
2982 into the shared library. However, if we are linking with
2983 -Bsymbolic, we do not need to copy a reloc against a
2984 global symbol which is defined in an object we are
2985 including in the link (i.e., DEF_REGULAR is set). At
2986 this point we have not seen all the input files, so it is
2987 possible that DEF_REGULAR is not set now but will be set
2988 later (it is never cleared). We account for that
2989 possibility below by storing information in the
2990 relocs_copied field of the hash table entry. */
2992 && (sec
->flags
& SEC_ALLOC
) != 0
2993 && (ELF32_R_TYPE (rel
->r_info
) != R_ARM_PC24
2995 && (! info
->symbolic
2996 || (h
->elf_link_hash_flags
2997 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2999 struct elf32_arm_relocs_copied
*p
, **head
;
3001 /* When creating a shared object, we must copy these
3002 reloc types into the output file. We create a reloc
3003 section in dynobj and make room for this reloc. */
3008 name
= (bfd_elf_string_from_elf_section
3010 elf_elfheader (abfd
)->e_shstrndx
,
3011 elf_section_data (sec
)->rel_hdr
.sh_name
));
3015 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
3016 && strcmp (bfd_get_section_name (abfd
, sec
),
3019 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3024 sreloc
= bfd_make_section (dynobj
, name
);
3025 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3026 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3027 if ((sec
->flags
& SEC_ALLOC
) != 0)
3028 flags
|= SEC_ALLOC
| SEC_LOAD
;
3030 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
3031 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
3035 elf_section_data (sec
)->sreloc
= sreloc
;
3038 /* If this is a global symbol, we count the number of
3039 relocations we need for this symbol. */
3042 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
3046 /* Track dynamic relocs needed for local syms too.
3047 We really need local syms available to do this
3051 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3056 head
= ((struct elf32_arm_relocs_copied
**)
3057 &elf_section_data (s
)->local_dynrel
);
3061 if (p
== NULL
|| p
->section
!= sec
)
3063 bfd_size_type amt
= sizeof *p
;
3064 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
3075 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
)
3080 /* This relocation describes the C++ object vtable hierarchy.
3081 Reconstruct it for later use during GC. */
3082 case R_ARM_GNU_VTINHERIT
:
3083 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3087 /* This relocation describes which C++ vtable entries are actually
3088 used. Record for later use during GC. */
3089 case R_ARM_GNU_VTENTRY
:
3090 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
3099 /* Find the nearest line to a particular section and offset, for error
3100 reporting. This code is a duplicate of the code in elf.c, except
3101 that it also accepts STT_ARM_TFUNC as a symbol that names a function. */
3104 elf32_arm_find_nearest_line
3105 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
3110 const char **filename_ptr
;
3111 const char **functionname_ptr
;
3112 unsigned int *line_ptr
;
3115 const char *filename
;
3120 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
3121 filename_ptr
, functionname_ptr
,
3123 &elf_tdata (abfd
)->dwarf2_find_line_info
))
3126 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
3127 &found
, filename_ptr
,
3128 functionname_ptr
, line_ptr
,
3129 &elf_tdata (abfd
)->line_info
))
3135 if (symbols
== NULL
)
3142 for (p
= symbols
; *p
!= NULL
; p
++)
3146 q
= (elf_symbol_type
*) *p
;
3148 if (bfd_get_section (&q
->symbol
) != section
)
3151 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
3156 filename
= bfd_asymbol_name (&q
->symbol
);
3161 if (q
->symbol
.section
== section
3162 && q
->symbol
.value
>= low_func
3163 && q
->symbol
.value
<= offset
)
3165 func
= (asymbol
*) q
;
3166 low_func
= q
->symbol
.value
;
3175 *filename_ptr
= filename
;
3176 *functionname_ptr
= bfd_asymbol_name (func
);
3182 /* Adjust a symbol defined by a dynamic object and referenced by a
3183 regular object. The current definition is in some section of the
3184 dynamic object, but we're not including those sections. We have to
3185 change the definition to something the rest of the link can
3189 elf32_arm_adjust_dynamic_symbol (info
, h
)
3190 struct bfd_link_info
* info
;
3191 struct elf_link_hash_entry
* h
;
3195 unsigned int power_of_two
;
3197 dynobj
= elf_hash_table (info
)->dynobj
;
3199 /* Make sure we know what is going on here. */
3200 BFD_ASSERT (dynobj
!= NULL
3201 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3202 || h
->weakdef
!= NULL
3203 || ((h
->elf_link_hash_flags
3204 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3205 && (h
->elf_link_hash_flags
3206 & ELF_LINK_HASH_REF_REGULAR
) != 0
3207 && (h
->elf_link_hash_flags
3208 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3210 /* If this is a function, put it in the procedure linkage table. We
3211 will fill in the contents of the procedure linkage table later,
3212 when we know the address of the .got section. */
3213 if (h
->type
== STT_FUNC
3214 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3216 if (h
->plt
.refcount
<= 0
3217 || SYMBOL_CALLS_LOCAL (info
, h
)
3218 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3219 && h
->root
.type
== bfd_link_hash_undefweak
))
3221 /* This case can occur if we saw a PLT32 reloc in an input
3222 file, but the symbol was never referred to by a dynamic
3223 object, or if all references were garbage collected. In
3224 such a case, we don't actually need to build a procedure
3225 linkage table, and we can just do a PC24 reloc instead. */
3226 h
->plt
.offset
= (bfd_vma
) -1;
3227 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3233 /* It's possible that we incorrectly decided a .plt reloc was
3234 needed for an R_ARM_PC24 reloc to a non-function sym in
3235 check_relocs. We can't decide accurately between function and
3236 non-function syms in check-relocs; Objects loaded later in
3237 the link may change h->type. So fix it now. */
3238 h
->plt
.offset
= (bfd_vma
) -1;
3240 /* If this is a weak symbol, and there is a real definition, the
3241 processor independent code will have arranged for us to see the
3242 real definition first, and we can just use the same value. */
3243 if (h
->weakdef
!= NULL
)
3245 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3246 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3247 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3248 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3252 /* This is a reference to a symbol defined by a dynamic object which
3253 is not a function. */
3255 /* If we are creating a shared library, we must presume that the
3256 only references to the symbol are via the global offset table.
3257 For such cases we need not do anything here; the relocations will
3258 be handled correctly by relocate_section. */
3262 /* We must allocate the symbol in our .dynbss section, which will
3263 become part of the .bss section of the executable. There will be
3264 an entry for this symbol in the .dynsym section. The dynamic
3265 object will contain position independent code, so all references
3266 from the dynamic object to this symbol will go through the global
3267 offset table. The dynamic linker will use the .dynsym entry to
3268 determine the address it must put in the global offset table, so
3269 both the dynamic object and the regular object will refer to the
3270 same memory location for the variable. */
3271 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3272 BFD_ASSERT (s
!= NULL
);
3274 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
3275 copy the initial value out of the dynamic object and into the
3276 runtime process image. We need to remember the offset into the
3277 .rel.bss section we are going to use. */
3278 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3282 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
3283 BFD_ASSERT (srel
!= NULL
);
3284 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3285 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3288 /* We need to figure out the alignment required for this symbol. I
3289 have no idea how ELF linkers handle this. */
3290 power_of_two
= bfd_log2 (h
->size
);
3291 if (power_of_two
> 3)
3294 /* Apply the required alignment. */
3295 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3296 (bfd_size_type
) (1 << power_of_two
));
3297 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3299 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3303 /* Define the symbol as being at this point in the section. */
3304 h
->root
.u
.def
.section
= s
;
3305 h
->root
.u
.def
.value
= s
->_raw_size
;
3307 /* Increment the section size to make room for the symbol. */
3308 s
->_raw_size
+= h
->size
;
3313 /* Allocate space in .plt, .got and associated reloc sections for
3317 allocate_dynrelocs (h
, inf
)
3318 struct elf_link_hash_entry
*h
;
3321 struct bfd_link_info
*info
;
3322 struct elf32_arm_link_hash_table
*htab
;
3323 struct elf32_arm_link_hash_entry
*eh
;
3324 struct elf32_arm_relocs_copied
*p
;
3326 if (h
->root
.type
== bfd_link_hash_indirect
)
3329 if (h
->root
.type
== bfd_link_hash_warning
)
3330 /* When warning symbols are created, they **replace** the "real"
3331 entry in the hash table, thus we never get to see the real
3332 symbol in a hash traversal. So look at it now. */
3333 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3335 info
= (struct bfd_link_info
*) inf
;
3336 htab
= elf32_arm_hash_table (info
);
3338 if (htab
->root
.dynamic_sections_created
3339 && h
->plt
.refcount
> 0)
3341 /* Make sure this symbol is output as a dynamic symbol.
3342 Undefined weak syms won't yet be marked as dynamic. */
3343 if (h
->dynindx
== -1
3344 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3346 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3351 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3353 asection
*s
= htab
->splt
;
3355 /* If this is the first .plt entry, make room for the special
3357 if (s
->_raw_size
== 0)
3358 s
->_raw_size
+= PLT_HEADER_SIZE
;
3360 h
->plt
.offset
= s
->_raw_size
;
3362 /* If this symbol is not defined in a regular file, and we are
3363 not generating a shared library, then set the symbol to this
3364 location in the .plt. This is required to make function
3365 pointers compare as equal between the normal executable and
3366 the shared library. */
3368 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3370 h
->root
.u
.def
.section
= s
;
3371 h
->root
.u
.def
.value
= h
->plt
.offset
;
3374 /* Make room for this entry. */
3375 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3377 /* We also need to make an entry in the .got.plt section, which
3378 will be placed in the .got section by the linker script. */
3379 htab
->sgotplt
->_raw_size
+= 4;
3381 /* We also need to make an entry in the .rel.plt section. */
3382 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rel
);
3386 h
->plt
.offset
= (bfd_vma
) -1;
3387 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3392 h
->plt
.offset
= (bfd_vma
) -1;
3393 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3396 if (h
->got
.refcount
> 0)
3401 /* Make sure this symbol is output as a dynamic symbol.
3402 Undefined weak syms won't yet be marked as dynamic. */
3403 if (h
->dynindx
== -1
3404 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3406 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3411 h
->got
.offset
= s
->_raw_size
;
3413 dyn
= htab
->root
.dynamic_sections_created
;
3414 if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
3415 || h
->root
.type
!= bfd_link_hash_undefweak
)
3417 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
3418 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rel
);
3421 h
->got
.offset
= (bfd_vma
) -1;
3423 eh
= (struct elf32_arm_link_hash_entry
*) h
;
3424 if (eh
->relocs_copied
== NULL
)
3427 /* In the shared -Bsymbolic case, discard space allocated for
3428 dynamic pc-relative relocs against symbols which turn out to be
3429 defined in regular objects. For the normal shared case, discard
3430 space for pc-relative relocs that have become local due to symbol
3431 visibility changes. */
3435 /* The only reloc that uses pc_count is R_ARM_PC24, which will
3436 appear on a call or on something like ".long foo - .". We
3437 want calls to protected symbols to resolve directly to the
3438 function rather than going via the plt. If people want
3439 function pointer comparisons to work as expected then they
3440 should avoid writing assembly like ".long foo - .". */
3441 if (SYMBOL_CALLS_LOCAL (info
, h
))
3443 struct elf32_arm_relocs_copied
**pp
;
3445 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
; )
3447 p
->count
-= p
->pc_count
;
3456 /* Also discard relocs on undefined weak syms with non-default
3458 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3459 && h
->root
.type
== bfd_link_hash_undefweak
)
3460 eh
->relocs_copied
= NULL
;
3464 /* For the non-shared case, discard space for relocs against
3465 symbols which turn out to need copy relocs or are not
3468 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3469 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3470 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3471 || (htab
->root
.dynamic_sections_created
3472 && (h
->root
.type
== bfd_link_hash_undefweak
3473 || h
->root
.type
== bfd_link_hash_undefined
))))
3475 /* Make sure this symbol is output as a dynamic symbol.
3476 Undefined weak syms won't yet be marked as dynamic. */
3477 if (h
->dynindx
== -1
3478 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3480 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3484 /* If that succeeded, we know we'll be keeping all the
3486 if (h
->dynindx
!= -1)
3490 eh
->relocs_copied
= NULL
;
3495 /* Finally, allocate space. */
3496 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
3498 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
3499 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3505 /* Set the sizes of the dynamic sections. */
3508 elf32_arm_size_dynamic_sections (output_bfd
, info
)
3509 bfd
* output_bfd ATTRIBUTE_UNUSED
;
3510 struct bfd_link_info
* info
;
3517 struct elf32_arm_link_hash_table
*htab
;
3519 htab
= elf32_arm_hash_table (info
);
3520 dynobj
= elf_hash_table (info
)->dynobj
;
3521 BFD_ASSERT (dynobj
!= NULL
);
3523 if (elf_hash_table (info
)->dynamic_sections_created
)
3525 /* Set the contents of the .interp section to the interpreter. */
3526 if (info
->executable
)
3528 s
= bfd_get_section_by_name (dynobj
, ".interp");
3529 BFD_ASSERT (s
!= NULL
);
3530 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3531 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3535 /* Set up .got offsets for local syms, and space for local dynamic
3537 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3539 bfd_signed_vma
*local_got
;
3540 bfd_signed_vma
*end_local_got
;
3541 char *local_tls_type
;
3542 bfd_size_type locsymcount
;
3543 Elf_Internal_Shdr
*symtab_hdr
;
3546 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3549 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3551 struct elf32_arm_relocs_copied
*p
;
3553 for (p
= *((struct elf32_arm_relocs_copied
**)
3554 &elf_section_data (s
)->local_dynrel
);
3558 if (!bfd_is_abs_section (p
->section
)
3559 && bfd_is_abs_section (p
->section
->output_section
))
3561 /* Input section has been discarded, either because
3562 it is a copy of a linkonce section or due to
3563 linker script /DISCARD/, so we'll be discarding
3566 else if (p
->count
!= 0)
3568 srel
= elf_section_data (p
->section
)->sreloc
;
3569 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3570 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
3571 info
->flags
|= DF_TEXTREL
;
3576 local_got
= elf_local_got_refcounts (ibfd
);
3580 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3581 locsymcount
= symtab_hdr
->sh_info
;
3582 end_local_got
= local_got
+ locsymcount
;
3584 srel
= htab
->srelgot
;
3585 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
3589 *local_got
= s
->_raw_size
;
3592 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3595 *local_got
= (bfd_vma
) -1;
3599 /* Allocate global sym .plt and .got entries, and space for global
3600 sym dynamic relocs. */
3601 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
3603 /* The check_relocs and adjust_dynamic_symbol entry points have
3604 determined the sizes of the various dynamic sections. Allocate
3608 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3613 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3616 /* It's OK to base decisions on the section name, because none
3617 of the dynobj section names depend upon the input files. */
3618 name
= bfd_get_section_name (dynobj
, s
);
3622 if (strcmp (name
, ".plt") == 0)
3624 if (s
->_raw_size
== 0)
3626 /* Strip this section if we don't need it; see the
3632 /* Remember whether there is a PLT. */
3636 else if (strncmp (name
, ".rel", 4) == 0)
3638 if (s
->_raw_size
== 0)
3640 /* If we don't need this section, strip it from the
3641 output file. This is mostly to handle .rel.bss and
3642 .rel.plt. We must create both sections in
3643 create_dynamic_sections, because they must be created
3644 before the linker maps input sections to output
3645 sections. The linker does that before
3646 adjust_dynamic_symbol is called, and it is that
3647 function which decides whether anything needs to go
3648 into these sections. */
3653 /* Remember whether there are any reloc sections other
3655 if (strcmp (name
, ".rel.plt") != 0)
3658 /* We use the reloc_count field as a counter if we need
3659 to copy relocs into the output file. */
3663 else if (strncmp (name
, ".got", 4) != 0)
3665 /* It's not one of our sections, so don't allocate space. */
3671 _bfd_strip_section_from_output (info
, s
);
3675 /* Allocate memory for the section contents. */
3676 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3677 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3681 if (elf_hash_table (info
)->dynamic_sections_created
)
3683 /* Add some entries to the .dynamic section. We fill in the
3684 values later, in elf32_arm_finish_dynamic_sections, but we
3685 must add the entries now so that we get the correct size for
3686 the .dynamic section. The DT_DEBUG entry is filled in by the
3687 dynamic linker and used by the debugger. */
3688 #define add_dynamic_entry(TAG, VAL) \
3689 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3693 if (!add_dynamic_entry (DT_DEBUG
, 0))
3699 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3700 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3701 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3702 || !add_dynamic_entry (DT_JMPREL
, 0))
3708 if ( !add_dynamic_entry (DT_REL
, 0)
3709 || !add_dynamic_entry (DT_RELSZ
, 0)
3710 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3714 if ((info
->flags
& DF_TEXTREL
) != 0)
3716 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3718 info
->flags
|= DF_TEXTREL
;
3721 #undef add_synamic_entry
3726 /* Finish up dynamic symbol handling. We set the contents of various
3727 dynamic sections here. */
3730 elf32_arm_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3732 struct bfd_link_info
* info
;
3733 struct elf_link_hash_entry
* h
;
3734 Elf_Internal_Sym
* sym
;
3738 dynobj
= elf_hash_table (info
)->dynobj
;
3740 if (h
->plt
.offset
!= (bfd_vma
) -1)
3747 Elf_Internal_Rela rel
;
3749 bfd_vma got_displacement
;
3751 /* This symbol has an entry in the procedure linkage table. Set
3754 BFD_ASSERT (h
->dynindx
!= -1);
3756 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3757 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3758 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3759 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3761 /* Get the index in the procedure linkage table which
3762 corresponds to this symbol. This is the index of this symbol
3763 in all the symbols for which we are making plt entries. The
3764 first entry in the procedure linkage table is reserved. */
3765 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3767 /* Get the offset into the .got table of the entry that
3768 corresponds to this function. Each .got entry is 4 bytes.
3769 The first three are reserved. */
3770 got_offset
= (plt_index
+ 3) * 4;
3772 /* Calculate the displacement between the PLT slot and the
3773 entry in the GOT. */
3774 got_displacement
= (sgot
->output_section
->vma
3775 + sgot
->output_offset
3777 - splt
->output_section
->vma
3778 - splt
->output_offset
3782 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
3784 /* Fill in the entry in the procedure linkage table. */
3785 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
3786 splt
->contents
+ h
->plt
.offset
+ 0);
3787 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
3788 splt
->contents
+ h
->plt
.offset
+ 4);
3789 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
3790 splt
->contents
+ h
->plt
.offset
+ 8);
3791 #ifdef FOUR_WORD_PLT
3792 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
3793 splt
->contents
+ h
->plt
.offset
+ 12);
3796 /* Fill in the entry in the global offset table. */
3797 bfd_put_32 (output_bfd
,
3798 (splt
->output_section
->vma
3799 + splt
->output_offset
),
3800 sgot
->contents
+ got_offset
);
3802 /* Fill in the entry in the .rel.plt section. */
3803 rel
.r_offset
= (sgot
->output_section
->vma
3804 + sgot
->output_offset
3806 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3807 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3808 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3810 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3812 /* Mark the symbol as undefined, rather than as defined in
3813 the .plt section. Leave the value alone. */
3814 sym
->st_shndx
= SHN_UNDEF
;
3815 /* If the symbol is weak, we do need to clear the value.
3816 Otherwise, the PLT entry would provide a definition for
3817 the symbol even if the symbol wasn't defined anywhere,
3818 and so the symbol would never be NULL. */
3819 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
3825 if (h
->got
.offset
!= (bfd_vma
) -1)
3829 Elf_Internal_Rela rel
;
3832 /* This symbol has an entry in the global offset table. Set it
3834 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3835 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3836 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3838 rel
.r_offset
= (sgot
->output_section
->vma
3839 + sgot
->output_offset
3840 + (h
->got
.offset
&~ (bfd_vma
) 1));
3842 /* If this is a static link, or it is a -Bsymbolic link and the
3843 symbol is defined locally or was forced to be local because
3844 of a version file, we just want to emit a RELATIVE reloc.
3845 The entry in the global offset table will already have been
3846 initialized in the relocate_section function. */
3848 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3850 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3851 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3855 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3856 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3857 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3860 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3861 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3864 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3867 Elf_Internal_Rela rel
;
3870 /* This symbol needs a copy reloc. Set it up. */
3871 BFD_ASSERT (h
->dynindx
!= -1
3872 && (h
->root
.type
== bfd_link_hash_defined
3873 || h
->root
.type
== bfd_link_hash_defweak
));
3875 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3877 BFD_ASSERT (s
!= NULL
);
3879 rel
.r_offset
= (h
->root
.u
.def
.value
3880 + h
->root
.u
.def
.section
->output_section
->vma
3881 + h
->root
.u
.def
.section
->output_offset
);
3882 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3883 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3884 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3887 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3888 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3889 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3890 sym
->st_shndx
= SHN_ABS
;
3895 /* Finish up the dynamic sections. */
3898 elf32_arm_finish_dynamic_sections (output_bfd
, info
)
3900 struct bfd_link_info
* info
;
3906 dynobj
= elf_hash_table (info
)->dynobj
;
3908 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3909 BFD_ASSERT (sgot
!= NULL
);
3910 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3912 if (elf_hash_table (info
)->dynamic_sections_created
)
3915 Elf32_External_Dyn
*dyncon
, *dynconend
;
3917 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3918 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3920 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3921 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3923 for (; dyncon
< dynconend
; dyncon
++)
3925 Elf_Internal_Dyn dyn
;
3929 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3942 s
= bfd_get_section_by_name (output_bfd
, name
);
3943 BFD_ASSERT (s
!= NULL
);
3944 dyn
.d_un
.d_ptr
= s
->vma
;
3945 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3949 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3950 BFD_ASSERT (s
!= NULL
);
3951 if (s
->_cooked_size
!= 0)
3952 dyn
.d_un
.d_val
= s
->_cooked_size
;
3954 dyn
.d_un
.d_val
= s
->_raw_size
;
3955 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3959 /* My reading of the SVR4 ABI indicates that the
3960 procedure linkage table relocs (DT_JMPREL) should be
3961 included in the overall relocs (DT_REL). This is
3962 what Solaris does. However, UnixWare can not handle
3963 that case. Therefore, we override the DT_RELSZ entry
3964 here to make it not include the JMPREL relocs. Since
3965 the linker script arranges for .rel.plt to follow all
3966 other relocation sections, we don't have to worry
3967 about changing the DT_REL entry. */
3968 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3971 if (s
->_cooked_size
!= 0)
3972 dyn
.d_un
.d_val
-= s
->_cooked_size
;
3974 dyn
.d_un
.d_val
-= s
->_raw_size
;
3976 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3979 /* Set the bottom bit of DT_INIT/FINI if the
3980 corresponding function is Thumb. */
3982 name
= info
->init_function
;
3985 name
= info
->fini_function
;
3987 /* If it wasn't set by elf_bfd_final_link
3988 then there is nothing to adjust. */
3989 if (dyn
.d_un
.d_val
!= 0)
3991 struct elf_link_hash_entry
* eh
;
3993 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
3994 FALSE
, FALSE
, TRUE
);
3995 if (eh
!= (struct elf_link_hash_entry
*) NULL
3996 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
3998 dyn
.d_un
.d_val
|= 1;
3999 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4006 /* Fill in the first entry in the procedure linkage table. */
4007 if (splt
->_raw_size
> 0)
4009 bfd_vma got_displacement
;
4011 /* Calculate the displacement between the PLT slot and &GOT[0]. */
4012 got_displacement
= (sgot
->output_section
->vma
4013 + sgot
->output_offset
4014 - splt
->output_section
->vma
4015 - splt
->output_offset
4018 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
4019 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
4020 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
4021 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
4022 #ifdef FOUR_WORD_PLT
4023 /* The displacement value goes in the otherwise-unused last word of
4024 the second entry. */
4025 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
4027 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
4031 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4032 really seem like the right value. */
4033 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
4036 /* Fill in the first three entries in the global offset table. */
4037 if (sgot
->_raw_size
> 0)
4040 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4042 bfd_put_32 (output_bfd
,
4043 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4045 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4046 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4049 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4055 elf32_arm_post_process_headers (abfd
, link_info
)
4057 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
4059 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
4061 i_ehdrp
= elf_elfheader (abfd
);
4063 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
4064 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
4067 static enum elf_reloc_type_class
4068 elf32_arm_reloc_type_class (rela
)
4069 const Elf_Internal_Rela
*rela
;
4071 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4073 case R_ARM_RELATIVE
:
4074 return reloc_class_relative
;
4075 case R_ARM_JUMP_SLOT
:
4076 return reloc_class_plt
;
4078 return reloc_class_copy
;
4080 return reloc_class_normal
;
4084 static bfd_boolean elf32_arm_section_flags
PARAMS ((flagword
*, Elf_Internal_Shdr
*));
4085 static void elf32_arm_final_write_processing
PARAMS ((bfd
*, bfd_boolean
));
4087 /* Set the right machine number for an Arm ELF file. */
4090 elf32_arm_section_flags (flags
, hdr
)
4092 Elf_Internal_Shdr
*hdr
;
4094 if (hdr
->sh_type
== SHT_NOTE
)
4095 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
4101 elf32_arm_final_write_processing (abfd
, linker
)
4103 bfd_boolean linker ATTRIBUTE_UNUSED
;
4105 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
4108 #define ELF_ARCH bfd_arch_arm
4109 #define ELF_MACHINE_CODE EM_ARM
4110 #ifdef __QNXTARGET__
4111 #define ELF_MAXPAGESIZE 0x1000
4113 #define ELF_MAXPAGESIZE 0x8000
4116 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
4117 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
4118 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
4119 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
4120 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
4121 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
4122 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4124 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
4125 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
4126 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
4127 #define elf_backend_check_relocs elf32_arm_check_relocs
4128 #define elf_backend_relocate_section elf32_arm_relocate_section
4129 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
4130 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
4131 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
4132 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
4133 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
4134 #define elf_backend_post_process_headers elf32_arm_post_process_headers
4135 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
4136 #define elf_backend_object_p elf32_arm_object_p
4137 #define elf_backend_section_flags elf32_arm_section_flags
4138 #define elf_backend_final_write_processing elf32_arm_final_write_processing
4139 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
4141 #define elf_backend_can_refcount 1
4142 #define elf_backend_can_gc_sections 1
4143 #define elf_backend_plt_readonly 1
4144 #define elf_backend_want_got_plt 1
4145 #define elf_backend_want_plt_sym 0
4147 #define elf_backend_rela_normal 1
4150 #define elf_backend_got_header_size 12
4152 #include "elf32-target.h"