1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 typedef unsigned long int insn32
;
26 typedef unsigned short int insn16
;
28 static bfd_boolean elf32_arm_set_private_flags
29 PARAMS ((bfd
*, flagword
));
30 static bfd_boolean elf32_arm_copy_private_bfd_data
31 PARAMS ((bfd
*, bfd
*));
32 static bfd_boolean elf32_arm_merge_private_bfd_data
33 PARAMS ((bfd
*, bfd
*));
34 static bfd_boolean elf32_arm_print_private_bfd_data
35 PARAMS ((bfd
*, PTR
));
36 static int elf32_arm_get_symbol_type
37 PARAMS (( Elf_Internal_Sym
*, int));
38 static struct bfd_link_hash_table
*elf32_arm_link_hash_table_create
40 static bfd_reloc_status_type elf32_arm_final_link_relocate
41 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
42 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
43 const char *, int, struct elf_link_hash_entry
*));
44 static insn32 insert_thumb_branch
45 PARAMS ((insn32
, int));
46 static struct elf_link_hash_entry
*find_thumb_glue
47 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
48 static struct elf_link_hash_entry
*find_arm_glue
49 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
50 static void elf32_arm_post_process_headers
51 PARAMS ((bfd
*, struct bfd_link_info
*));
52 static int elf32_arm_to_thumb_stub
53 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
54 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
55 static int elf32_thumb_to_arm_stub
56 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
57 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
58 static bfd_boolean elf32_arm_relocate_section
59 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
60 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
61 static asection
* elf32_arm_gc_mark_hook
62 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
63 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
64 static bfd_boolean elf32_arm_gc_sweep_hook
65 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
66 const Elf_Internal_Rela
*));
67 static bfd_boolean elf32_arm_check_relocs
68 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
69 const Elf_Internal_Rela
*));
70 static bfd_boolean elf32_arm_find_nearest_line
71 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
72 const char **, unsigned int *));
73 static bfd_boolean elf32_arm_adjust_dynamic_symbol
74 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
75 static bfd_boolean elf32_arm_size_dynamic_sections
76 PARAMS ((bfd
*, struct bfd_link_info
*));
77 static bfd_boolean elf32_arm_finish_dynamic_symbol
78 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
80 static bfd_boolean elf32_arm_finish_dynamic_sections
81 PARAMS ((bfd
*, struct bfd_link_info
*));
82 static struct bfd_hash_entry
* elf32_arm_link_hash_newfunc
83 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
85 static void arm_add_to_rel
86 PARAMS ((bfd
*, bfd_byte
*, reloc_howto_type
*, bfd_signed_vma
));
88 static bfd_boolean allocate_dynrelocs
89 PARAMS ((struct elf_link_hash_entry
*h
, PTR inf
));
90 static bfd_boolean create_got_section
91 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
92 static bfd_boolean elf32_arm_create_dynamic_sections
93 PARAMS ((bfd
* dynobj
, struct bfd_link_info
* info
));
94 static enum elf_reloc_type_class elf32_arm_reloc_type_class
95 PARAMS ((const Elf_Internal_Rela
*));
96 static bfd_boolean elf32_arm_object_p
99 #ifndef ELFARM_NABI_C_INCLUDED
100 static void record_arm_to_thumb_glue
101 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
102 static void record_thumb_to_arm_glue
103 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
104 bfd_boolean bfd_elf32_arm_allocate_interworking_sections
105 PARAMS ((struct bfd_link_info
*));
106 bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
107 PARAMS ((bfd
*, struct bfd_link_info
*));
108 bfd_boolean bfd_elf32_arm_process_before_allocation
109 PARAMS ((bfd
*, struct bfd_link_info
*, int));
113 #define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
115 /* The linker script knows the section names for placement.
116 The entry_names are used to do simple name mangling on the stubs.
117 Given a function name, and its type, the stub can be found. The
118 name can be changed. The only requirement is the %s be present. */
119 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
120 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
122 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
123 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
125 /* The name of the dynamic interpreter. This is put in the .interp
127 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
131 /* The size in bytes of the special first entry in the procedure
133 #define PLT_HEADER_SIZE 16
135 /* The size in bytes of an entry in the procedure linkage table. */
136 #define PLT_ENTRY_SIZE 16
138 /* The first entry in a procedure linkage table looks like
139 this. It is set up so that any shared library function that is
140 called before the relocation has been set up calls the dynamic
142 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
144 0xe52de004, /* str lr, [sp, #-4]! */
145 0xe59fe010, /* ldr lr, [pc, #16] */
146 0xe08fe00e, /* add lr, pc, lr */
147 0xe5bef008, /* ldr pc, [lr, #8]! */
150 /* Subsequent entries in a procedure linkage table look like
152 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
154 0xe28fc600, /* add ip, pc, #NN */
155 0xe28cca00, /* add ip, ip, #NN */
156 0xe5bcf000, /* ldr pc, [ip, #NN]! */
157 0x00000000, /* unused */
162 /* The size in bytes of the special first entry in the procedure
164 #define PLT_HEADER_SIZE 20
166 /* The size in bytes of an entry in the procedure linkage table. */
167 #define PLT_ENTRY_SIZE 12
169 /* The first entry in a procedure linkage table looks like
170 this. It is set up so that any shared library function that is
171 called before the relocation has been set up calls the dynamic
173 static const bfd_vma elf32_arm_plt0_entry
[PLT_HEADER_SIZE
/ 4] =
175 0xe52de004, /* str lr, [sp, #-4]! */
176 0xe59fe004, /* ldr lr, [pc, #4] */
177 0xe08fe00e, /* add lr, pc, lr */
178 0xe5bef008, /* ldr pc, [lr, #8]! */
179 0x00000000, /* &GOT[0] - . */
182 /* Subsequent entries in a procedure linkage table look like
184 static const bfd_vma elf32_arm_plt_entry
[PLT_ENTRY_SIZE
/ 4] =
186 0xe28fc600, /* add ip, pc, #0xNN00000 */
187 0xe28cca00, /* add ip, ip, #0xNN000 */
188 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
193 /* The ARM linker needs to keep track of the number of relocs that it
194 decides to copy in check_relocs for each symbol. This is so that
195 it can discard PC relative relocs if it doesn't need them when
196 linking with -Bsymbolic. We store the information in a field
197 extending the regular ELF linker hash table. */
199 /* This structure keeps track of the number of PC relative relocs we
200 have copied for a given symbol. */
201 struct elf32_arm_relocs_copied
204 struct elf32_arm_relocs_copied
* next
;
205 /* A section in dynobj. */
207 /* Number of relocs copied in this section. */
211 /* Arm ELF linker hash entry. */
212 struct elf32_arm_link_hash_entry
214 struct elf_link_hash_entry root
;
216 /* Number of PC relative relocs copied for this symbol. */
217 struct elf32_arm_relocs_copied
* relocs_copied
;
220 /* Traverse an arm ELF linker hash table. */
221 #define elf32_arm_link_hash_traverse(table, func, info) \
222 (elf_link_hash_traverse \
224 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
227 /* Get the ARM elf linker hash table from a link_info structure. */
228 #define elf32_arm_hash_table(info) \
229 ((struct elf32_arm_link_hash_table *) ((info)->hash))
231 /* ARM ELF linker hash table. */
232 struct elf32_arm_link_hash_table
234 /* The main hash table. */
235 struct elf_link_hash_table root
;
237 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
238 bfd_size_type thumb_glue_size
;
240 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
241 bfd_size_type arm_glue_size
;
243 /* An arbitrary input BFD chosen to hold the glue sections. */
244 bfd
* bfd_of_glue_owner
;
246 /* A boolean indicating whether knowledge of the ARM's pipeline
247 length should be applied by the linker. */
248 int no_pipeline_knowledge
;
250 /* Short-cuts to get to dynamic linker sections. */
259 /* Small local sym to section mapping cache. */
260 struct sym_sec_cache sym_sec
;
263 /* Create an entry in an ARM ELF linker hash table. */
265 static struct bfd_hash_entry
*
266 elf32_arm_link_hash_newfunc (entry
, table
, string
)
267 struct bfd_hash_entry
* entry
;
268 struct bfd_hash_table
* table
;
271 struct elf32_arm_link_hash_entry
* ret
=
272 (struct elf32_arm_link_hash_entry
*) entry
;
274 /* Allocate the structure if it has not already been allocated by a
276 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
277 ret
= ((struct elf32_arm_link_hash_entry
*)
278 bfd_hash_allocate (table
,
279 sizeof (struct elf32_arm_link_hash_entry
)));
280 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
281 return (struct bfd_hash_entry
*) ret
;
283 /* Call the allocation method of the superclass. */
284 ret
= ((struct elf32_arm_link_hash_entry
*)
285 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
287 if (ret
!= (struct elf32_arm_link_hash_entry
*) NULL
)
288 ret
->relocs_copied
= NULL
;
290 return (struct bfd_hash_entry
*) ret
;
293 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
294 shortcuts to them in our hash table. */
297 create_got_section (dynobj
, info
)
299 struct bfd_link_info
*info
;
301 struct elf32_arm_link_hash_table
*htab
;
303 if (! _bfd_elf_create_got_section (dynobj
, info
))
306 htab
= elf32_arm_hash_table (info
);
307 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
308 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
309 if (!htab
->sgot
|| !htab
->sgotplt
)
312 htab
->srelgot
= bfd_make_section (dynobj
, ".rel.got");
313 if (htab
->srelgot
== NULL
314 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
315 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
316 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
318 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
323 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
324 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
328 elf32_arm_create_dynamic_sections (dynobj
, info
)
330 struct bfd_link_info
*info
;
332 struct elf32_arm_link_hash_table
*htab
;
334 htab
= elf32_arm_hash_table (info
);
335 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
338 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
341 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
342 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rel.plt");
343 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
345 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rel.bss");
347 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
348 || (!info
->shared
&& !htab
->srelbss
))
354 /* Copy the extra info we tack onto an elf_link_hash_entry. */
357 elf32_arm_copy_indirect_symbol (const struct elf_backend_data
*bed
,
358 struct elf_link_hash_entry
*dir
,
359 struct elf_link_hash_entry
*ind
)
361 struct elf32_arm_link_hash_entry
*edir
, *eind
;
363 edir
= (struct elf32_arm_link_hash_entry
*) dir
;
364 eind
= (struct elf32_arm_link_hash_entry
*) ind
;
366 if (eind
->relocs_copied
!= NULL
)
368 if (edir
->relocs_copied
!= NULL
)
370 struct elf32_arm_relocs_copied
**pp
;
371 struct elf32_arm_relocs_copied
*p
;
373 if (ind
->root
.type
== bfd_link_hash_indirect
)
376 /* Add reloc counts against the weak sym to the strong sym
377 list. Merge any entries against the same section. */
378 for (pp
= &eind
->relocs_copied
; (p
= *pp
) != NULL
; )
380 struct elf32_arm_relocs_copied
*q
;
382 for (q
= edir
->relocs_copied
; q
!= NULL
; q
= q
->next
)
383 if (q
->section
== p
->section
)
385 q
->count
+= p
->count
;
392 *pp
= edir
->relocs_copied
;
395 edir
->relocs_copied
= eind
->relocs_copied
;
396 eind
->relocs_copied
= NULL
;
399 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
402 /* Create an ARM elf linker hash table. */
404 static struct bfd_link_hash_table
*
405 elf32_arm_link_hash_table_create (abfd
)
408 struct elf32_arm_link_hash_table
*ret
;
409 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
411 ret
= (struct elf32_arm_link_hash_table
*) bfd_malloc (amt
);
412 if (ret
== (struct elf32_arm_link_hash_table
*) NULL
)
415 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
416 elf32_arm_link_hash_newfunc
))
429 ret
->thumb_glue_size
= 0;
430 ret
->arm_glue_size
= 0;
431 ret
->bfd_of_glue_owner
= NULL
;
432 ret
->no_pipeline_knowledge
= 0;
433 ret
->sym_sec
.abfd
= NULL
;
435 return &ret
->root
.root
;
438 /* Locate the Thumb encoded calling stub for NAME. */
440 static struct elf_link_hash_entry
*
441 find_thumb_glue (link_info
, name
, input_bfd
)
442 struct bfd_link_info
*link_info
;
447 struct elf_link_hash_entry
*hash
;
448 struct elf32_arm_link_hash_table
*hash_table
;
450 /* We need a pointer to the armelf specific hash table. */
451 hash_table
= elf32_arm_hash_table (link_info
);
453 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
454 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
456 BFD_ASSERT (tmp_name
);
458 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
460 hash
= elf_link_hash_lookup
461 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
464 /* xgettext:c-format */
465 (*_bfd_error_handler
) (_("%s: unable to find THUMB glue '%s' for `%s'"),
466 bfd_archive_filename (input_bfd
), tmp_name
, name
);
473 /* Locate the ARM encoded calling stub for NAME. */
475 static struct elf_link_hash_entry
*
476 find_arm_glue (link_info
, name
, input_bfd
)
477 struct bfd_link_info
*link_info
;
482 struct elf_link_hash_entry
*myh
;
483 struct elf32_arm_link_hash_table
*hash_table
;
485 /* We need a pointer to the elfarm specific hash table. */
486 hash_table
= elf32_arm_hash_table (link_info
);
488 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
489 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
491 BFD_ASSERT (tmp_name
);
493 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
495 myh
= elf_link_hash_lookup
496 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
499 /* xgettext:c-format */
500 (*_bfd_error_handler
) (_("%s: unable to find ARM glue '%s' for `%s'"),
501 bfd_archive_filename (input_bfd
), tmp_name
, name
);
515 .word func @ behave as if you saw a ARM_32 reloc. */
517 #define ARM2THUMB_GLUE_SIZE 12
518 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
519 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
520 static const insn32 a2t3_func_addr_insn
= 0x00000001;
522 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
526 __func_from_thumb: __func_from_thumb:
528 nop ldr r6, __func_addr
530 __func_change_to_arm: bx r6
532 __func_back_to_thumb:
538 #define THUMB2ARM_GLUE_SIZE 8
539 static const insn16 t2a1_bx_pc_insn
= 0x4778;
540 static const insn16 t2a2_noop_insn
= 0x46c0;
541 static const insn32 t2a3_b_insn
= 0xea000000;
543 #ifndef ELFARM_NABI_C_INCLUDED
545 bfd_elf32_arm_allocate_interworking_sections (info
)
546 struct bfd_link_info
* info
;
550 struct elf32_arm_link_hash_table
* globals
;
552 globals
= elf32_arm_hash_table (info
);
554 BFD_ASSERT (globals
!= NULL
);
556 if (globals
->arm_glue_size
!= 0)
558 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
560 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
561 ARM2THUMB_GLUE_SECTION_NAME
);
563 BFD_ASSERT (s
!= NULL
);
565 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
566 globals
->arm_glue_size
);
568 s
->_raw_size
= s
->_cooked_size
= globals
->arm_glue_size
;
572 if (globals
->thumb_glue_size
!= 0)
574 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
576 s
= bfd_get_section_by_name
577 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
579 BFD_ASSERT (s
!= NULL
);
581 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
582 globals
->thumb_glue_size
);
584 s
->_raw_size
= s
->_cooked_size
= globals
->thumb_glue_size
;
592 record_arm_to_thumb_glue (link_info
, h
)
593 struct bfd_link_info
* link_info
;
594 struct elf_link_hash_entry
* h
;
596 const char * name
= h
->root
.root
.string
;
599 struct elf_link_hash_entry
* myh
;
600 struct bfd_link_hash_entry
* bh
;
601 struct elf32_arm_link_hash_table
* globals
;
604 globals
= elf32_arm_hash_table (link_info
);
606 BFD_ASSERT (globals
!= NULL
);
607 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
609 s
= bfd_get_section_by_name
610 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
612 BFD_ASSERT (s
!= NULL
);
614 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
615 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
617 BFD_ASSERT (tmp_name
);
619 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
621 myh
= elf_link_hash_lookup
622 (&(globals
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
626 /* We've already seen this guy. */
631 /* The only trick here is using hash_table->arm_glue_size as the value. Even
632 though the section isn't allocated yet, this is where we will be putting
635 val
= globals
->arm_glue_size
+ 1;
636 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
637 tmp_name
, BSF_GLOBAL
, s
, val
,
638 NULL
, TRUE
, FALSE
, &bh
);
642 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
648 record_thumb_to_arm_glue (link_info
, h
)
649 struct bfd_link_info
*link_info
;
650 struct elf_link_hash_entry
*h
;
652 const char *name
= h
->root
.root
.string
;
655 struct elf_link_hash_entry
*myh
;
656 struct bfd_link_hash_entry
*bh
;
657 struct elf32_arm_link_hash_table
*hash_table
;
661 hash_table
= elf32_arm_hash_table (link_info
);
663 BFD_ASSERT (hash_table
!= NULL
);
664 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
666 s
= bfd_get_section_by_name
667 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
669 BFD_ASSERT (s
!= NULL
);
671 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
672 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
674 BFD_ASSERT (tmp_name
);
676 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
678 myh
= elf_link_hash_lookup
679 (&(hash_table
)->root
, tmp_name
, FALSE
, FALSE
, TRUE
);
683 /* We've already seen this guy. */
689 val
= hash_table
->thumb_glue_size
+ 1;
690 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
691 tmp_name
, BSF_GLOBAL
, s
, val
,
692 NULL
, TRUE
, FALSE
, &bh
);
694 /* If we mark it 'Thumb', the disassembler will do a better job. */
695 myh
= (struct elf_link_hash_entry
*) bh
;
696 bind
= ELF_ST_BIND (myh
->type
);
697 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
701 #define CHANGE_TO_ARM "__%s_change_to_arm"
702 #define BACK_FROM_ARM "__%s_back_from_arm"
704 /* Allocate another symbol to mark where we switch to Arm mode. */
705 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
706 + strlen (CHANGE_TO_ARM
) + 1);
708 BFD_ASSERT (tmp_name
);
710 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
713 val
= hash_table
->thumb_glue_size
+ 4,
714 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
715 tmp_name
, BSF_LOCAL
, s
, val
,
716 NULL
, TRUE
, FALSE
, &bh
);
720 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
725 /* Add the glue sections to ABFD. This function is called from the
726 linker scripts in ld/emultempl/{armelf}.em. */
729 bfd_elf32_arm_add_glue_sections_to_bfd (abfd
, info
)
731 struct bfd_link_info
*info
;
736 /* If we are only performing a partial
737 link do not bother adding the glue. */
738 if (info
->relocatable
)
741 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
745 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
746 will prevent elf_link_input_bfd() from processing the contents
748 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
750 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
753 || !bfd_set_section_flags (abfd
, sec
, flags
)
754 || !bfd_set_section_alignment (abfd
, sec
, 2))
757 /* Set the gc mark to prevent the section from being removed by garbage
758 collection, despite the fact that no relocs refer to this section. */
762 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
766 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
768 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
771 || !bfd_set_section_flags (abfd
, sec
, flags
)
772 || !bfd_set_section_alignment (abfd
, sec
, 2))
781 /* Select a BFD to be used to hold the sections used by the glue code.
782 This function is called from the linker scripts in ld/emultempl/
786 bfd_elf32_arm_get_bfd_for_interworking (abfd
, info
)
788 struct bfd_link_info
*info
;
790 struct elf32_arm_link_hash_table
*globals
;
792 /* If we are only performing a partial link
793 do not bother getting a bfd to hold the glue. */
794 if (info
->relocatable
)
797 globals
= elf32_arm_hash_table (info
);
799 BFD_ASSERT (globals
!= NULL
);
801 if (globals
->bfd_of_glue_owner
!= NULL
)
804 /* Save the bfd for later use. */
805 globals
->bfd_of_glue_owner
= abfd
;
811 bfd_elf32_arm_process_before_allocation (abfd
, link_info
, no_pipeline_knowledge
)
813 struct bfd_link_info
*link_info
;
814 int no_pipeline_knowledge
;
816 Elf_Internal_Shdr
*symtab_hdr
;
817 Elf_Internal_Rela
*internal_relocs
= NULL
;
818 Elf_Internal_Rela
*irel
, *irelend
;
819 bfd_byte
*contents
= NULL
;
822 struct elf32_arm_link_hash_table
*globals
;
824 /* If we are only performing a partial link do not bother
825 to construct any glue. */
826 if (link_info
->relocatable
)
829 /* Here we have a bfd that is to be included on the link. We have a hook
830 to do reloc rummaging, before section sizes are nailed down. */
831 globals
= elf32_arm_hash_table (link_info
);
833 BFD_ASSERT (globals
!= NULL
);
834 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
836 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
838 /* Rummage around all the relocs and map the glue vectors. */
839 sec
= abfd
->sections
;
844 for (; sec
!= NULL
; sec
= sec
->next
)
846 if (sec
->reloc_count
== 0)
849 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
851 /* Load the relocs. */
853 = _bfd_elf_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
854 (Elf_Internal_Rela
*) NULL
, FALSE
);
856 if (internal_relocs
== NULL
)
859 irelend
= internal_relocs
+ sec
->reloc_count
;
860 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
863 unsigned long r_index
;
865 struct elf_link_hash_entry
*h
;
867 r_type
= ELF32_R_TYPE (irel
->r_info
);
868 r_index
= ELF32_R_SYM (irel
->r_info
);
870 /* These are the only relocation types we care about. */
871 if ( r_type
!= R_ARM_PC24
872 && r_type
!= R_ARM_THM_PC22
)
875 /* Get the section contents if we haven't done so already. */
876 if (contents
== NULL
)
878 /* Get cached copy if it exists. */
879 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
880 contents
= elf_section_data (sec
)->this_hdr
.contents
;
883 /* Go get them off disk. */
884 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
885 if (contents
== NULL
)
888 if (!bfd_get_section_contents (abfd
, sec
, contents
,
889 (file_ptr
) 0, sec
->_raw_size
))
894 /* If the relocation is not against a symbol it cannot concern us. */
897 /* We don't care about local symbols. */
898 if (r_index
< symtab_hdr
->sh_info
)
901 /* This is an external symbol. */
902 r_index
-= symtab_hdr
->sh_info
;
903 h
= (struct elf_link_hash_entry
*)
904 elf_sym_hashes (abfd
)[r_index
];
906 /* If the relocation is against a static symbol it must be within
907 the current section and so cannot be a cross ARM/Thumb relocation. */
914 /* This one is a call from arm code. We need to look up
915 the target of the call. If it is a thumb target, we
917 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
918 record_arm_to_thumb_glue (link_info
, h
);
922 /* This one is a call from thumb code. We look
923 up the target of the call. If it is not a thumb
924 target, we insert glue. */
925 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
926 record_thumb_to_arm_glue (link_info
, h
);
935 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
939 if (internal_relocs
!= NULL
940 && elf_section_data (sec
)->relocs
!= internal_relocs
)
941 free (internal_relocs
);
942 internal_relocs
= NULL
;
949 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
951 if (internal_relocs
!= NULL
952 && elf_section_data (sec
)->relocs
!= internal_relocs
)
953 free (internal_relocs
);
959 /* The thumb form of a long branch is a bit finicky, because the offset
960 encoding is split over two fields, each in it's own instruction. They
961 can occur in any order. So given a thumb form of long branch, and an
962 offset, insert the offset into the thumb branch and return finished
965 It takes two thumb instructions to encode the target address. Each has
966 11 bits to invest. The upper 11 bits are stored in one (identified by
967 H-0.. see below), the lower 11 bits are stored in the other (identified
970 Combine together and shifted left by 1 (it's a half word address) and
974 H-0, upper address-0 = 000
976 H-1, lower address-0 = 800
978 They can be ordered either way, but the arm tools I've seen always put
979 the lower one first. It probably doesn't matter. krk@cygnus.com
981 XXX: Actually the order does matter. The second instruction (H-1)
982 moves the computed address into the PC, so it must be the second one
983 in the sequence. The problem, however is that whilst little endian code
984 stores the instructions in HI then LOW order, big endian code does the
985 reverse. nickc@cygnus.com. */
987 #define LOW_HI_ORDER 0xF800F000
988 #define HI_LOW_ORDER 0xF000F800
991 insert_thumb_branch (br_insn
, rel_off
)
995 unsigned int low_bits
;
996 unsigned int high_bits
;
998 BFD_ASSERT ((rel_off
& 1) != 1);
1000 rel_off
>>= 1; /* Half word aligned address. */
1001 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
1002 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
1004 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
1005 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
1006 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
1007 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
1009 /* FIXME: abort is probably not the right call. krk@cygnus.com */
1010 abort (); /* error - not a valid branch instruction form. */
1015 /* Thumb code calling an ARM function. */
1018 elf32_thumb_to_arm_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1019 hit_data
, sym_sec
, offset
, addend
, val
)
1020 struct bfd_link_info
* info
;
1024 asection
* input_section
;
1025 bfd_byte
* hit_data
;
1028 bfd_signed_vma addend
;
1033 unsigned long int tmp
;
1034 long int ret_offset
;
1035 struct elf_link_hash_entry
* myh
;
1036 struct elf32_arm_link_hash_table
* globals
;
1038 myh
= find_thumb_glue (info
, name
, input_bfd
);
1042 globals
= elf32_arm_hash_table (info
);
1044 BFD_ASSERT (globals
!= NULL
);
1045 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1047 my_offset
= myh
->root
.u
.def
.value
;
1049 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1050 THUMB2ARM_GLUE_SECTION_NAME
);
1052 BFD_ASSERT (s
!= NULL
);
1053 BFD_ASSERT (s
->contents
!= NULL
);
1054 BFD_ASSERT (s
->output_section
!= NULL
);
1056 if ((my_offset
& 0x01) == 0x01)
1059 && sym_sec
->owner
!= NULL
1060 && !INTERWORK_FLAG (sym_sec
->owner
))
1062 (*_bfd_error_handler
)
1063 (_("%s(%s): warning: interworking not enabled."),
1064 bfd_archive_filename (sym_sec
->owner
), name
);
1065 (*_bfd_error_handler
)
1066 (_(" first occurrence: %s: thumb call to arm"),
1067 bfd_archive_filename (input_bfd
));
1073 myh
->root
.u
.def
.value
= my_offset
;
1075 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
1076 s
->contents
+ my_offset
);
1078 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
1079 s
->contents
+ my_offset
+ 2);
1082 /* Address of destination of the stub. */
1083 ((bfd_signed_vma
) val
)
1085 /* Offset from the start of the current section to the start of the stubs. */
1087 /* Offset of the start of this stub from the start of the stubs. */
1089 /* Address of the start of the current section. */
1090 + s
->output_section
->vma
)
1091 /* The branch instruction is 4 bytes into the stub. */
1093 /* ARM branches work from the pc of the instruction + 8. */
1096 bfd_put_32 (output_bfd
,
1097 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1098 s
->contents
+ my_offset
+ 4);
1101 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
1103 /* Now go back and fix up the original BL insn to point to here. */
1105 /* Address of where the stub is located. */
1106 (s
->output_section
->vma
+ s
->output_offset
+ my_offset
)
1107 /* Address of where the BL is located. */
1108 - (input_section
->output_section
->vma
+ input_section
->output_offset
+ offset
)
1109 /* Addend in the relocation. */
1111 /* Biassing for PC-relative addressing. */
1114 tmp
= bfd_get_32 (input_bfd
, hit_data
1115 - input_section
->vma
);
1117 bfd_put_32 (output_bfd
,
1118 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1119 hit_data
- input_section
->vma
);
1124 /* Arm code calling a Thumb function. */
1127 elf32_arm_to_thumb_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1128 hit_data
, sym_sec
, offset
, addend
, val
)
1129 struct bfd_link_info
* info
;
1133 asection
* input_section
;
1134 bfd_byte
* hit_data
;
1137 bfd_signed_vma addend
;
1140 unsigned long int tmp
;
1143 long int ret_offset
;
1144 struct elf_link_hash_entry
* myh
;
1145 struct elf32_arm_link_hash_table
* globals
;
1147 myh
= find_arm_glue (info
, name
, input_bfd
);
1151 globals
= elf32_arm_hash_table (info
);
1153 BFD_ASSERT (globals
!= NULL
);
1154 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1156 my_offset
= myh
->root
.u
.def
.value
;
1157 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1158 ARM2THUMB_GLUE_SECTION_NAME
);
1159 BFD_ASSERT (s
!= NULL
);
1160 BFD_ASSERT (s
->contents
!= NULL
);
1161 BFD_ASSERT (s
->output_section
!= NULL
);
1163 if ((my_offset
& 0x01) == 0x01)
1166 && sym_sec
->owner
!= NULL
1167 && !INTERWORK_FLAG (sym_sec
->owner
))
1169 (*_bfd_error_handler
)
1170 (_("%s(%s): warning: interworking not enabled."),
1171 bfd_archive_filename (sym_sec
->owner
), name
);
1172 (*_bfd_error_handler
)
1173 (_(" first occurrence: %s: arm call to thumb"),
1174 bfd_archive_filename (input_bfd
));
1178 myh
->root
.u
.def
.value
= my_offset
;
1180 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1181 s
->contents
+ my_offset
);
1183 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1184 s
->contents
+ my_offset
+ 4);
1186 /* It's a thumb address. Add the low order bit. */
1187 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1188 s
->contents
+ my_offset
+ 8);
1191 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1193 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1194 tmp
= tmp
& 0xFF000000;
1196 /* Somehow these are both 4 too far, so subtract 8. */
1197 ret_offset
= (s
->output_offset
1199 + s
->output_section
->vma
1200 - (input_section
->output_offset
1201 + input_section
->output_section
->vma
1205 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1207 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1212 /* This is the condition under which elf32_arm_finish_dynamic_symbol
1213 will be called from elflink.h. If elflink.h doesn't call our
1214 finish_dynamic_symbol routine, we'll need to do something about
1215 initializing any .plt and .got entries in elf32_arm_relocate_section
1216 and elf32_arm_final_link_relocate. */
1217 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
1220 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
1221 && ((H)->dynindx != -1 \
1222 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
1224 /* Perform a relocation as part of a final link. */
1226 static bfd_reloc_status_type
1227 elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
1228 input_section
, contents
, rel
, value
,
1229 info
, sym_sec
, sym_name
, sym_flags
, h
)
1230 reloc_howto_type
* howto
;
1233 asection
* input_section
;
1234 bfd_byte
* contents
;
1235 Elf_Internal_Rela
* rel
;
1237 struct bfd_link_info
* info
;
1239 const char * sym_name
;
1241 struct elf_link_hash_entry
* h
;
1243 unsigned long r_type
= howto
->type
;
1244 unsigned long r_symndx
;
1245 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1246 bfd
* dynobj
= NULL
;
1247 Elf_Internal_Shdr
* symtab_hdr
;
1248 struct elf_link_hash_entry
** sym_hashes
;
1249 bfd_vma
* local_got_offsets
;
1250 asection
* sgot
= NULL
;
1251 asection
* splt
= NULL
;
1252 asection
* sreloc
= NULL
;
1254 bfd_signed_vma signed_addend
;
1255 struct elf32_arm_link_hash_table
* globals
;
1257 /* If the start address has been set, then set the EF_ARM_HASENTRY
1258 flag. Setting this more than once is redundant, but the cost is
1259 not too high, and it keeps the code simple.
1261 The test is done here, rather than somewhere else, because the
1262 start address is only set just before the final link commences.
1264 Note - if the user deliberately sets a start address of 0, the
1265 flag will not be set. */
1266 if (bfd_get_start_address (output_bfd
) != 0)
1267 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1269 globals
= elf32_arm_hash_table (info
);
1271 dynobj
= elf_hash_table (info
)->dynobj
;
1274 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1275 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1277 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1278 sym_hashes
= elf_sym_hashes (input_bfd
);
1279 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1280 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1283 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1285 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1288 signed_addend
&= ~ howto
->src_mask
;
1289 signed_addend
|= addend
;
1292 signed_addend
= addend
;
1294 addend
= signed_addend
= rel
->r_addend
;
1300 return bfd_reloc_ok
;
1309 /* r_symndx will be zero only for relocs against symbols
1310 from removed linkonce sections, or sections discarded by
1313 return bfd_reloc_ok
;
1315 /* Handle relocations which should use the PLT entry. ABS32/REL32
1316 will use the symbol's value, which may point to a PLT entry, but we
1317 don't need to handle that here. If we created a PLT entry, all
1318 branches in this object should go to it. */
1319 if ((r_type
!= R_ARM_ABS32
&& r_type
!= R_ARM_REL32
)
1322 && h
->plt
.offset
!= (bfd_vma
) -1)
1324 /* If we've created a .plt section, and assigned a PLT entry to
1325 this function, it should not be known to bind locally. If
1326 it were, we would have cleared the PLT entry. */
1327 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info
, h
));
1329 value
= (splt
->output_section
->vma
1330 + splt
->output_offset
1332 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1333 contents
, rel
->r_offset
, value
,
1337 /* When generating a shared object, these relocations are copied
1338 into the output file to be resolved at run time. */
1340 && (input_section
->flags
& SEC_ALLOC
)
1342 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1343 || h
->root
.type
!= bfd_link_hash_undefweak
)
1344 && r_type
!= R_ARM_PC24
1345 && r_type
!= R_ARM_PLT32
)
1347 Elf_Internal_Rela outrel
;
1349 bfd_boolean skip
, relocate
;
1355 name
= (bfd_elf_string_from_elf_section
1357 elf_elfheader (input_bfd
)->e_shstrndx
,
1358 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1360 return bfd_reloc_notsupported
;
1362 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1363 && strcmp (bfd_get_section_name (input_bfd
,
1367 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1368 BFD_ASSERT (sreloc
!= NULL
);
1375 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1377 if (outrel
.r_offset
== (bfd_vma
) -1)
1379 else if (outrel
.r_offset
== (bfd_vma
) -2)
1380 skip
= TRUE
, relocate
= TRUE
;
1381 outrel
.r_offset
+= (input_section
->output_section
->vma
1382 + input_section
->output_offset
);
1385 memset (&outrel
, 0, sizeof outrel
);
1390 || (h
->elf_link_hash_flags
1391 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1392 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1395 /* This symbol is local, or marked to become local. */
1397 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1400 loc
= sreloc
->contents
;
1401 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1402 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1404 /* If this reloc is against an external symbol, we do not want to
1405 fiddle with the addend. Otherwise, we need to include the symbol
1406 value so that it becomes an addend for the dynamic reloc. */
1408 return bfd_reloc_ok
;
1410 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1411 contents
, rel
->r_offset
, value
,
1414 else switch (r_type
)
1417 case R_ARM_XPC25
: /* Arm BLX instruction. */
1419 case R_ARM_PC24
: /* Arm B/BL instruction */
1422 if (r_type
== R_ARM_XPC25
)
1424 /* Check for Arm calling Arm function. */
1425 /* FIXME: Should we translate the instruction into a BL
1426 instruction instead ? */
1427 if (sym_flags
!= STT_ARM_TFUNC
)
1428 (*_bfd_error_handler
) (_("\
1429 %s: Warning: Arm BLX instruction targets Arm function '%s'."),
1430 bfd_archive_filename (input_bfd
),
1431 h
? h
->root
.root
.string
: "(local)");
1436 /* Check for Arm calling Thumb function. */
1437 if (sym_flags
== STT_ARM_TFUNC
)
1439 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
, output_bfd
,
1440 input_section
, hit_data
, sym_sec
, rel
->r_offset
,
1441 signed_addend
, value
);
1442 return bfd_reloc_ok
;
1446 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1447 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1449 /* The old way of doing things. Trearing the addend as a
1450 byte sized field and adding in the pipeline offset. */
1451 value
-= (input_section
->output_section
->vma
1452 + input_section
->output_offset
);
1453 value
-= rel
->r_offset
;
1456 if (! globals
->no_pipeline_knowledge
)
1461 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1463 S is the address of the symbol in the relocation.
1464 P is address of the instruction being relocated.
1465 A is the addend (extracted from the instruction) in bytes.
1467 S is held in 'value'.
1468 P is the base address of the section containing the instruction
1469 plus the offset of the reloc into that section, ie:
1470 (input_section->output_section->vma +
1471 input_section->output_offset +
1473 A is the addend, converted into bytes, ie:
1476 Note: None of these operations have knowledge of the pipeline
1477 size of the processor, thus it is up to the assembler to encode
1478 this information into the addend. */
1479 value
-= (input_section
->output_section
->vma
1480 + input_section
->output_offset
);
1481 value
-= rel
->r_offset
;
1482 value
+= (signed_addend
<< howto
->size
);
1484 /* Previous versions of this code also used to add in the pipeline
1485 offset here. This is wrong because the linker is not supposed
1486 to know about such things, and one day it might change. In order
1487 to support old binaries that need the old behaviour however, so
1488 we attempt to detect which ABI was used to create the reloc. */
1489 if (! globals
->no_pipeline_knowledge
)
1491 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1493 i_ehdrp
= elf_elfheader (input_bfd
);
1495 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1500 signed_addend
= value
;
1501 signed_addend
>>= howto
->rightshift
;
1503 /* It is not an error for an undefined weak reference to be
1504 out of range. Any program that branches to such a symbol
1505 is going to crash anyway, so there is no point worrying
1506 about getting the destination exactly right. */
1507 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1509 /* Perform a signed range check. */
1510 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1511 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1512 return bfd_reloc_overflow
;
1516 /* If necessary set the H bit in the BLX instruction. */
1517 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1518 value
= (signed_addend
& howto
->dst_mask
)
1519 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1523 value
= (signed_addend
& howto
->dst_mask
)
1524 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1529 if (sym_flags
== STT_ARM_TFUNC
)
1534 value
-= (input_section
->output_section
->vma
1535 + input_section
->output_offset
+ rel
->r_offset
);
1540 bfd_put_32 (input_bfd
, value
, hit_data
);
1541 return bfd_reloc_ok
;
1545 if ((long) value
> 0x7f || (long) value
< -0x80)
1546 return bfd_reloc_overflow
;
1548 bfd_put_8 (input_bfd
, value
, hit_data
);
1549 return bfd_reloc_ok
;
1554 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1555 return bfd_reloc_overflow
;
1557 bfd_put_16 (input_bfd
, value
, hit_data
);
1558 return bfd_reloc_ok
;
1561 /* Support ldr and str instruction for the arm */
1562 /* Also thumb b (unconditional branch). ??? Really? */
1565 if ((long) value
> 0x7ff || (long) value
< -0x800)
1566 return bfd_reloc_overflow
;
1568 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1569 bfd_put_32 (input_bfd
, value
, hit_data
);
1570 return bfd_reloc_ok
;
1572 case R_ARM_THM_ABS5
:
1573 /* Support ldr and str instructions for the thumb. */
1575 /* Need to refetch addend. */
1576 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1577 /* ??? Need to determine shift amount from operand size. */
1578 addend
>>= howto
->rightshift
;
1582 /* ??? Isn't value unsigned? */
1583 if ((long) value
> 0x1f || (long) value
< -0x10)
1584 return bfd_reloc_overflow
;
1586 /* ??? Value needs to be properly shifted into place first. */
1587 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1588 bfd_put_16 (input_bfd
, value
, hit_data
);
1589 return bfd_reloc_ok
;
1592 case R_ARM_THM_XPC22
:
1594 case R_ARM_THM_PC22
:
1595 /* Thumb BL (branch long instruction). */
1598 bfd_boolean overflow
= FALSE
;
1599 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1600 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1601 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1602 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1604 bfd_signed_vma signed_check
;
1607 /* Need to refetch the addend and squish the two 11 bit pieces
1610 bfd_vma upper
= upper_insn
& 0x7ff;
1611 bfd_vma lower
= lower_insn
& 0x7ff;
1612 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1613 addend
= (upper
<< 12) | (lower
<< 1);
1614 signed_addend
= addend
;
1618 if (r_type
== R_ARM_THM_XPC22
)
1620 /* Check for Thumb to Thumb call. */
1621 /* FIXME: Should we translate the instruction into a BL
1622 instruction instead ? */
1623 if (sym_flags
== STT_ARM_TFUNC
)
1624 (*_bfd_error_handler
) (_("\
1625 %s: Warning: Thumb BLX instruction targets thumb function '%s'."),
1626 bfd_archive_filename (input_bfd
),
1627 h
? h
->root
.root
.string
: "(local)");
1632 /* If it is not a call to Thumb, assume call to Arm.
1633 If it is a call relative to a section name, then it is not a
1634 function call at all, but rather a long jump. */
1635 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1637 if (elf32_thumb_to_arm_stub
1638 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1639 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1640 return bfd_reloc_ok
;
1642 return bfd_reloc_dangerous
;
1646 relocation
= value
+ signed_addend
;
1648 relocation
-= (input_section
->output_section
->vma
1649 + input_section
->output_offset
1652 if (! globals
->no_pipeline_knowledge
)
1654 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1656 i_ehdrp
= elf_elfheader (input_bfd
);
1658 /* Previous versions of this code also used to add in the pipline
1659 offset here. This is wrong because the linker is not supposed
1660 to know about such things, and one day it might change. In order
1661 to support old binaries that need the old behaviour however, so
1662 we attempt to detect which ABI was used to create the reloc. */
1663 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1664 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1665 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1669 check
= relocation
>> howto
->rightshift
;
1671 /* If this is a signed value, the rightshift just dropped
1672 leading 1 bits (assuming twos complement). */
1673 if ((bfd_signed_vma
) relocation
>= 0)
1674 signed_check
= check
;
1676 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1678 /* Assumes two's complement. */
1679 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1683 if (r_type
== R_ARM_THM_XPC22
1684 && ((lower_insn
& 0x1800) == 0x0800))
1685 /* For a BLX instruction, make sure that the relocation is rounded up
1686 to a word boundary. This follows the semantics of the instruction
1687 which specifies that bit 1 of the target address will come from bit
1688 1 of the base address. */
1689 relocation
= (relocation
+ 2) & ~ 3;
1691 /* Put RELOCATION back into the insn. */
1692 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1693 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1695 /* Put the relocated value back in the object file: */
1696 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1697 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1699 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1703 case R_ARM_THM_PC11
:
1704 /* Thumb B (branch) instruction). */
1706 bfd_signed_vma relocation
;
1707 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1708 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1709 bfd_signed_vma signed_check
;
1712 /* Need to refetch addend. */
1713 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1714 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1717 signed_addend
&= ~ howto
->src_mask
;
1718 signed_addend
|= addend
;
1721 signed_addend
= addend
;
1722 /* The value in the insn has been right shifted. We need to
1723 undo this, so that we can perform the address calculation
1724 in terms of bytes. */
1725 signed_addend
<<= howto
->rightshift
;
1727 relocation
= value
+ signed_addend
;
1729 relocation
-= (input_section
->output_section
->vma
1730 + input_section
->output_offset
1733 relocation
>>= howto
->rightshift
;
1734 signed_check
= relocation
;
1735 relocation
&= howto
->dst_mask
;
1736 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1738 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1740 /* Assumes two's complement. */
1741 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1742 return bfd_reloc_overflow
;
1744 return bfd_reloc_ok
;
1747 case R_ARM_GNU_VTINHERIT
:
1748 case R_ARM_GNU_VTENTRY
:
1749 return bfd_reloc_ok
;
1752 return bfd_reloc_notsupported
;
1754 case R_ARM_GLOB_DAT
:
1755 return bfd_reloc_notsupported
;
1757 case R_ARM_JUMP_SLOT
:
1758 return bfd_reloc_notsupported
;
1760 case R_ARM_RELATIVE
:
1761 return bfd_reloc_notsupported
;
1764 /* Relocation is relative to the start of the
1765 global offset table. */
1767 BFD_ASSERT (sgot
!= NULL
);
1769 return bfd_reloc_notsupported
;
1771 /* If we are addressing a Thumb function, we need to adjust the
1772 address by one, so that attempts to call the function pointer will
1773 correctly interpret it as Thumb code. */
1774 if (sym_flags
== STT_ARM_TFUNC
)
1777 /* Note that sgot->output_offset is not involved in this
1778 calculation. We always want the start of .got. If we
1779 define _GLOBAL_OFFSET_TABLE in a different way, as is
1780 permitted by the ABI, we might have to change this
1782 value
-= sgot
->output_section
->vma
;
1783 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1784 contents
, rel
->r_offset
, value
,
1788 /* Use global offset table as symbol value. */
1789 BFD_ASSERT (sgot
!= NULL
);
1792 return bfd_reloc_notsupported
;
1794 value
= sgot
->output_section
->vma
;
1795 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1796 contents
, rel
->r_offset
, value
,
1800 /* Relocation is to the entry for this symbol in the
1801 global offset table. */
1803 return bfd_reloc_notsupported
;
1810 off
= h
->got
.offset
;
1811 BFD_ASSERT (off
!= (bfd_vma
) -1);
1812 dyn
= globals
->root
.dynamic_sections_created
;
1814 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1816 && SYMBOL_REFERENCES_LOCAL (info
, h
))
1817 || (ELF_ST_VISIBILITY (h
->other
)
1818 && h
->root
.type
== bfd_link_hash_undefweak
))
1820 /* This is actually a static link, or it is a -Bsymbolic link
1821 and the symbol is defined locally. We must initialize this
1822 entry in the global offset table. Since the offset must
1823 always be a multiple of 4, we use the least significant bit
1824 to record whether we have initialized it already.
1826 When doing a dynamic link, we create a .rel.got relocation
1827 entry to initialize the value. This is done in the
1828 finish_dynamic_symbol routine. */
1833 /* If we are addressing a Thumb function, we need to
1834 adjust the address by one, so that attempts to
1835 call the function pointer will correctly
1836 interpret it as Thumb code. */
1837 if (sym_flags
== STT_ARM_TFUNC
)
1840 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1845 value
= sgot
->output_offset
+ off
;
1851 BFD_ASSERT (local_got_offsets
!= NULL
&&
1852 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1854 off
= local_got_offsets
[r_symndx
];
1856 /* The offset must always be a multiple of 4. We use the
1857 least significant bit to record whether we have already
1858 generated the necessary reloc. */
1863 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1868 Elf_Internal_Rela outrel
;
1871 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1872 BFD_ASSERT (srelgot
!= NULL
);
1874 outrel
.r_offset
= (sgot
->output_section
->vma
1875 + sgot
->output_offset
1877 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1878 loc
= srelgot
->contents
;
1879 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rel
);
1880 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
, loc
);
1883 local_got_offsets
[r_symndx
] |= 1;
1886 value
= sgot
->output_offset
+ off
;
1889 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1890 contents
, rel
->r_offset
, value
,
1894 return bfd_reloc_notsupported
;
1896 case R_ARM_AMP_VCALL9
:
1897 return bfd_reloc_notsupported
;
1899 case R_ARM_RSBREL32
:
1900 return bfd_reloc_notsupported
;
1902 case R_ARM_THM_RPC22
:
1903 return bfd_reloc_notsupported
;
1906 return bfd_reloc_notsupported
;
1909 return bfd_reloc_notsupported
;
1912 return bfd_reloc_notsupported
;
1915 return bfd_reloc_notsupported
;
1918 return bfd_reloc_notsupported
;
1923 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1925 arm_add_to_rel (abfd
, address
, howto
, increment
)
1928 reloc_howto_type
* howto
;
1929 bfd_signed_vma increment
;
1931 bfd_signed_vma addend
;
1933 if (howto
->type
== R_ARM_THM_PC22
)
1935 int upper_insn
, lower_insn
;
1938 upper_insn
= bfd_get_16 (abfd
, address
);
1939 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1940 upper
= upper_insn
& 0x7ff;
1941 lower
= lower_insn
& 0x7ff;
1943 addend
= (upper
<< 12) | (lower
<< 1);
1944 addend
+= increment
;
1947 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
1948 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
1950 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
1951 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
1957 contents
= bfd_get_32 (abfd
, address
);
1959 /* Get the (signed) value from the instruction. */
1960 addend
= contents
& howto
->src_mask
;
1961 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1963 bfd_signed_vma mask
;
1966 mask
&= ~ howto
->src_mask
;
1970 /* Add in the increment, (which is a byte value). */
1971 switch (howto
->type
)
1974 addend
+= increment
;
1978 addend
<<= howto
->size
;
1979 addend
+= increment
;
1981 /* Should we check for overflow here ? */
1983 /* Drop any undesired bits. */
1984 addend
>>= howto
->rightshift
;
1988 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1990 bfd_put_32 (abfd
, contents
, address
);
1993 #endif /* USE_REL */
1995 /* Relocate an ARM ELF section. */
1997 elf32_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1998 contents
, relocs
, local_syms
, local_sections
)
2000 struct bfd_link_info
*info
;
2002 asection
*input_section
;
2004 Elf_Internal_Rela
*relocs
;
2005 Elf_Internal_Sym
*local_syms
;
2006 asection
**local_sections
;
2008 Elf_Internal_Shdr
*symtab_hdr
;
2009 struct elf_link_hash_entry
**sym_hashes
;
2010 Elf_Internal_Rela
*rel
;
2011 Elf_Internal_Rela
*relend
;
2015 if (info
->relocatable
)
2019 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
2020 sym_hashes
= elf_sym_hashes (input_bfd
);
2023 relend
= relocs
+ input_section
->reloc_count
;
2024 for (; rel
< relend
; rel
++)
2027 reloc_howto_type
* howto
;
2028 unsigned long r_symndx
;
2029 Elf_Internal_Sym
* sym
;
2031 struct elf_link_hash_entry
* h
;
2033 bfd_reloc_status_type r
;
2036 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2037 r_type
= ELF32_R_TYPE (rel
->r_info
);
2039 if ( r_type
== R_ARM_GNU_VTENTRY
2040 || r_type
== R_ARM_GNU_VTINHERIT
)
2043 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
2044 howto
= bfd_reloc
.howto
;
2047 if (info
->relocatable
)
2049 /* This is a relocatable link. We don't have to change
2050 anything, unless the reloc is against a section symbol,
2051 in which case we have to adjust according to where the
2052 section symbol winds up in the output section. */
2053 if (r_symndx
< symtab_hdr
->sh_info
)
2055 sym
= local_syms
+ r_symndx
;
2056 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2058 sec
= local_sections
[r_symndx
];
2059 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2061 (bfd_signed_vma
) (sec
->output_offset
2070 /* This is a final link. */
2075 if (r_symndx
< symtab_hdr
->sh_info
)
2077 sym
= local_syms
+ r_symndx
;
2078 sec
= local_sections
[r_symndx
];
2080 relocation
= (sec
->output_section
->vma
2081 + sec
->output_offset
2083 if ((sec
->flags
& SEC_MERGE
)
2084 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2087 bfd_vma addend
, value
;
2089 if (howto
->rightshift
)
2091 (*_bfd_error_handler
)
2092 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
2093 bfd_archive_filename (input_bfd
),
2094 bfd_get_section_name (input_bfd
, input_section
),
2095 (long) rel
->r_offset
, howto
->name
);
2099 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2101 /* Get the (signed) value from the instruction. */
2102 addend
= value
& howto
->src_mask
;
2103 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2105 bfd_signed_vma mask
;
2108 mask
&= ~ howto
->src_mask
;
2113 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2115 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2116 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2117 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2120 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2126 bfd_boolean unresolved_reloc
;
2128 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
2129 r_symndx
, symtab_hdr
, sym_hashes
,
2131 unresolved_reloc
, warned
);
2133 if (unresolved_reloc
|| relocation
!= 0)
2135 /* In these cases, we don't need the relocation value.
2136 We check specially because in some obscure cases
2137 sec->output_section will be NULL. */
2142 case R_ARM_THM_PC22
:
2145 (!info
->symbolic
&& h
->dynindx
!= -1)
2146 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2148 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2149 && ((input_section
->flags
& SEC_ALLOC
) != 0
2150 /* DWARF will emit R_ARM_ABS32 relocations in its
2151 sections against symbols defined externally
2152 in shared libraries. We can't do anything
2154 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2155 && (h
->elf_link_hash_flags
2156 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2166 if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL
2167 (elf_hash_table (info
)->dynamic_sections_created
,
2170 || (!info
->symbolic
&& h
->dynindx
!= -1)
2171 || (h
->elf_link_hash_flags
2172 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2177 if (h
->plt
.offset
!= (bfd_vma
)-1)
2182 if (unresolved_reloc
)
2184 (_("%s: warning: unresolvable relocation %d against symbol `%s' from %s section"),
2185 bfd_archive_filename (input_bfd
),
2187 h
->root
.root
.string
,
2188 bfd_get_section_name (input_bfd
, input_section
));
2195 name
= h
->root
.root
.string
;
2198 name
= (bfd_elf_string_from_elf_section
2199 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2200 if (name
== NULL
|| *name
== '\0')
2201 name
= bfd_section_name (input_bfd
, sec
);
2204 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2205 input_section
, contents
, rel
,
2206 relocation
, info
, sec
, name
,
2207 (h
? ELF_ST_TYPE (h
->type
) :
2208 ELF_ST_TYPE (sym
->st_info
)), h
);
2210 if (r
!= bfd_reloc_ok
)
2212 const char * msg
= (const char *) 0;
2216 case bfd_reloc_overflow
:
2217 /* If the overflowing reloc was to an undefined symbol,
2218 we have already printed one error message and there
2219 is no point complaining again. */
2221 h
->root
.type
!= bfd_link_hash_undefined
)
2222 && (!((*info
->callbacks
->reloc_overflow
)
2223 (info
, name
, howto
->name
, (bfd_vma
) 0,
2224 input_bfd
, input_section
, rel
->r_offset
))))
2228 case bfd_reloc_undefined
:
2229 if (!((*info
->callbacks
->undefined_symbol
)
2230 (info
, name
, input_bfd
, input_section
,
2231 rel
->r_offset
, TRUE
)))
2235 case bfd_reloc_outofrange
:
2236 msg
= _("internal error: out of range error");
2239 case bfd_reloc_notsupported
:
2240 msg
= _("internal error: unsupported relocation error");
2243 case bfd_reloc_dangerous
:
2244 msg
= _("internal error: dangerous error");
2248 msg
= _("internal error: unknown error");
2252 if (!((*info
->callbacks
->warning
)
2253 (info
, msg
, name
, input_bfd
, input_section
,
2264 /* Set the right machine number. */
2267 elf32_arm_object_p (abfd
)
2272 mach
= bfd_arm_get_mach_from_notes (abfd
, ARM_NOTE_SECTION
);
2274 if (mach
!= bfd_mach_arm_unknown
)
2275 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2277 else if (elf_elfheader (abfd
)->e_flags
& EF_ARM_MAVERICK_FLOAT
)
2278 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, bfd_mach_arm_ep9312
);
2281 bfd_default_set_arch_mach (abfd
, bfd_arch_arm
, mach
);
2286 /* Function to keep ARM specific flags in the ELF header. */
2288 elf32_arm_set_private_flags (abfd
, flags
)
2292 if (elf_flags_init (abfd
)
2293 && elf_elfheader (abfd
)->e_flags
!= flags
)
2295 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2297 if (flags
& EF_ARM_INTERWORK
)
2298 (*_bfd_error_handler
) (_("\
2299 Warning: Not setting interworking flag of %s since it has already been specified as non-interworking"),
2300 bfd_archive_filename (abfd
));
2302 _bfd_error_handler (_("\
2303 Warning: Clearing the interworking flag of %s due to outside request"),
2304 bfd_archive_filename (abfd
));
2309 elf_elfheader (abfd
)->e_flags
= flags
;
2310 elf_flags_init (abfd
) = TRUE
;
2316 /* Copy backend specific data from one object module to another. */
2319 elf32_arm_copy_private_bfd_data (ibfd
, obfd
)
2326 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2327 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2330 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2331 out_flags
= elf_elfheader (obfd
)->e_flags
;
2333 if (elf_flags_init (obfd
)
2334 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2335 && in_flags
!= out_flags
)
2337 /* Cannot mix APCS26 and APCS32 code. */
2338 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2341 /* Cannot mix float APCS and non-float APCS code. */
2342 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2345 /* If the src and dest have different interworking flags
2346 then turn off the interworking bit. */
2347 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2349 if (out_flags
& EF_ARM_INTERWORK
)
2350 _bfd_error_handler (_("\
2351 Warning: Clearing the interworking flag of %s because non-interworking code in %s has been linked with it"),
2352 bfd_get_filename (obfd
),
2353 bfd_archive_filename (ibfd
));
2355 in_flags
&= ~EF_ARM_INTERWORK
;
2358 /* Likewise for PIC, though don't warn for this case. */
2359 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2360 in_flags
&= ~EF_ARM_PIC
;
2363 elf_elfheader (obfd
)->e_flags
= in_flags
;
2364 elf_flags_init (obfd
) = TRUE
;
2369 /* Merge backend specific data from an object file to the output
2370 object file when linking. */
2373 elf32_arm_merge_private_bfd_data (ibfd
, obfd
)
2379 bfd_boolean flags_compatible
= TRUE
;
2382 /* Check if we have the same endianess. */
2383 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2386 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2387 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2390 /* The input BFD must have had its flags initialised. */
2391 /* The following seems bogus to me -- The flags are initialized in
2392 the assembler but I don't think an elf_flags_init field is
2393 written into the object. */
2394 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2396 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2397 out_flags
= elf_elfheader (obfd
)->e_flags
;
2399 if (!elf_flags_init (obfd
))
2401 /* If the input is the default architecture and had the default
2402 flags then do not bother setting the flags for the output
2403 architecture, instead allow future merges to do this. If no
2404 future merges ever set these flags then they will retain their
2405 uninitialised values, which surprise surprise, correspond
2406 to the default values. */
2407 if (bfd_get_arch_info (ibfd
)->the_default
2408 && elf_elfheader (ibfd
)->e_flags
== 0)
2411 elf_flags_init (obfd
) = TRUE
;
2412 elf_elfheader (obfd
)->e_flags
= in_flags
;
2414 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2415 && bfd_get_arch_info (obfd
)->the_default
)
2416 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2421 /* Determine what should happen if the input ARM architecture
2422 does not match the output ARM architecture. */
2423 if (! bfd_arm_merge_machines (ibfd
, obfd
))
2426 /* Identical flags must be compatible. */
2427 if (in_flags
== out_flags
)
2430 /* Check to see if the input BFD actually contains any sections. If
2431 not, its flags may not have been initialised either, but it
2432 cannot actually cause any incompatibility. Do not short-circuit
2433 dynamic objects; their section list may be emptied by
2434 elf_link_add_object_symbols.
2436 Also check to see if there are no code sections in the input.
2437 In this case there is no need to check for code specific flags.
2438 XXX - do we need to worry about floating-point format compatability
2439 in data sections ? */
2440 if (!(ibfd
->flags
& DYNAMIC
))
2442 bfd_boolean null_input_bfd
= TRUE
;
2443 bfd_boolean only_data_sections
= TRUE
;
2445 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2447 /* Ignore synthetic glue sections. */
2448 if (strcmp (sec
->name
, ".glue_7")
2449 && strcmp (sec
->name
, ".glue_7t"))
2451 if ((bfd_get_section_flags (ibfd
, sec
)
2452 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2453 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
2454 only_data_sections
= FALSE
;
2456 null_input_bfd
= FALSE
;
2461 if (null_input_bfd
|| only_data_sections
)
2465 /* Complain about various flag mismatches. */
2466 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2468 _bfd_error_handler (_("\
2469 ERROR: %s is compiled for EABI version %d, whereas %s is compiled for version %d"),
2470 bfd_archive_filename (ibfd
),
2471 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2472 bfd_get_filename (obfd
),
2473 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2477 /* Not sure what needs to be checked for EABI versions >= 1. */
2478 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2480 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2482 _bfd_error_handler (_("\
2483 ERROR: %s is compiled for APCS-%d, whereas target %s uses APCS-%d"),
2484 bfd_archive_filename (ibfd
),
2485 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2486 bfd_get_filename (obfd
),
2487 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2488 flags_compatible
= FALSE
;
2491 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2493 if (in_flags
& EF_ARM_APCS_FLOAT
)
2494 _bfd_error_handler (_("\
2495 ERROR: %s passes floats in float registers, whereas %s passes them in integer registers"),
2496 bfd_archive_filename (ibfd
),
2497 bfd_get_filename (obfd
));
2499 _bfd_error_handler (_("\
2500 ERROR: %s passes floats in integer registers, whereas %s passes them in float registers"),
2501 bfd_archive_filename (ibfd
),
2502 bfd_get_filename (obfd
));
2504 flags_compatible
= FALSE
;
2507 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2509 if (in_flags
& EF_ARM_VFP_FLOAT
)
2510 _bfd_error_handler (_("\
2511 ERROR: %s uses VFP instructions, whereas %s does not"),
2512 bfd_archive_filename (ibfd
),
2513 bfd_get_filename (obfd
));
2515 _bfd_error_handler (_("\
2516 ERROR: %s uses FPA instructions, whereas %s does not"),
2517 bfd_archive_filename (ibfd
),
2518 bfd_get_filename (obfd
));
2520 flags_compatible
= FALSE
;
2523 if ((in_flags
& EF_ARM_MAVERICK_FLOAT
) != (out_flags
& EF_ARM_MAVERICK_FLOAT
))
2525 if (in_flags
& EF_ARM_MAVERICK_FLOAT
)
2526 _bfd_error_handler (_("\
2527 ERROR: %s uses Maverick instructions, whereas %s does not"),
2528 bfd_archive_filename (ibfd
),
2529 bfd_get_filename (obfd
));
2531 _bfd_error_handler (_("\
2532 ERROR: %s does not use Maverick instructions, whereas %s does"),
2533 bfd_archive_filename (ibfd
),
2534 bfd_get_filename (obfd
));
2536 flags_compatible
= FALSE
;
2539 #ifdef EF_ARM_SOFT_FLOAT
2540 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2542 /* We can allow interworking between code that is VFP format
2543 layout, and uses either soft float or integer regs for
2544 passing floating point arguments and results. We already
2545 know that the APCS_FLOAT flags match; similarly for VFP
2547 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2548 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2550 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2551 _bfd_error_handler (_("\
2552 ERROR: %s uses software FP, whereas %s uses hardware FP"),
2553 bfd_archive_filename (ibfd
),
2554 bfd_get_filename (obfd
));
2556 _bfd_error_handler (_("\
2557 ERROR: %s uses hardware FP, whereas %s uses software FP"),
2558 bfd_archive_filename (ibfd
),
2559 bfd_get_filename (obfd
));
2561 flags_compatible
= FALSE
;
2566 /* Interworking mismatch is only a warning. */
2567 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2569 if (in_flags
& EF_ARM_INTERWORK
)
2571 _bfd_error_handler (_("\
2572 Warning: %s supports interworking, whereas %s does not"),
2573 bfd_archive_filename (ibfd
),
2574 bfd_get_filename (obfd
));
2578 _bfd_error_handler (_("\
2579 Warning: %s does not support interworking, whereas %s does"),
2580 bfd_archive_filename (ibfd
),
2581 bfd_get_filename (obfd
));
2586 return flags_compatible
;
2589 /* Display the flags field. */
2592 elf32_arm_print_private_bfd_data (abfd
, ptr
)
2596 FILE * file
= (FILE *) ptr
;
2597 unsigned long flags
;
2599 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2601 /* Print normal ELF private data. */
2602 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2604 flags
= elf_elfheader (abfd
)->e_flags
;
2605 /* Ignore init flag - it may not be set, despite the flags field
2606 containing valid data. */
2608 /* xgettext:c-format */
2609 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2611 switch (EF_ARM_EABI_VERSION (flags
))
2613 case EF_ARM_EABI_UNKNOWN
:
2614 /* The following flag bits are GNU extensions and not part of the
2615 official ARM ELF extended ABI. Hence they are only decoded if
2616 the EABI version is not set. */
2617 if (flags
& EF_ARM_INTERWORK
)
2618 fprintf (file
, _(" [interworking enabled]"));
2620 if (flags
& EF_ARM_APCS_26
)
2621 fprintf (file
, " [APCS-26]");
2623 fprintf (file
, " [APCS-32]");
2625 if (flags
& EF_ARM_VFP_FLOAT
)
2626 fprintf (file
, _(" [VFP float format]"));
2627 else if (flags
& EF_ARM_MAVERICK_FLOAT
)
2628 fprintf (file
, _(" [Maverick float format]"));
2630 fprintf (file
, _(" [FPA float format]"));
2632 if (flags
& EF_ARM_APCS_FLOAT
)
2633 fprintf (file
, _(" [floats passed in float registers]"));
2635 if (flags
& EF_ARM_PIC
)
2636 fprintf (file
, _(" [position independent]"));
2638 if (flags
& EF_ARM_NEW_ABI
)
2639 fprintf (file
, _(" [new ABI]"));
2641 if (flags
& EF_ARM_OLD_ABI
)
2642 fprintf (file
, _(" [old ABI]"));
2644 if (flags
& EF_ARM_SOFT_FLOAT
)
2645 fprintf (file
, _(" [software FP]"));
2647 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2648 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2649 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
2650 | EF_ARM_MAVERICK_FLOAT
);
2653 case EF_ARM_EABI_VER1
:
2654 fprintf (file
, _(" [Version1 EABI]"));
2656 if (flags
& EF_ARM_SYMSARESORTED
)
2657 fprintf (file
, _(" [sorted symbol table]"));
2659 fprintf (file
, _(" [unsorted symbol table]"));
2661 flags
&= ~ EF_ARM_SYMSARESORTED
;
2664 case EF_ARM_EABI_VER2
:
2665 fprintf (file
, _(" [Version2 EABI]"));
2667 if (flags
& EF_ARM_SYMSARESORTED
)
2668 fprintf (file
, _(" [sorted symbol table]"));
2670 fprintf (file
, _(" [unsorted symbol table]"));
2672 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2673 fprintf (file
, _(" [dynamic symbols use segment index]"));
2675 if (flags
& EF_ARM_MAPSYMSFIRST
)
2676 fprintf (file
, _(" [mapping symbols precede others]"));
2678 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2679 | EF_ARM_MAPSYMSFIRST
);
2682 case EF_ARM_EABI_VER3
:
2683 fprintf (file
, _(" [Version3 EABI]"));
2685 if (flags
& EF_ARM_BE8
)
2686 fprintf (file
, _(" [BE8]"));
2688 if (flags
& EF_ARM_LE8
)
2689 fprintf (file
, _(" [LE8]"));
2691 flags
&= ~(EF_ARM_LE8
| EF_ARM_BE8
);
2695 fprintf (file
, _(" <EABI version unrecognised>"));
2699 flags
&= ~ EF_ARM_EABIMASK
;
2701 if (flags
& EF_ARM_RELEXEC
)
2702 fprintf (file
, _(" [relocatable executable]"));
2704 if (flags
& EF_ARM_HASENTRY
)
2705 fprintf (file
, _(" [has entry point]"));
2707 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2710 fprintf (file
, _("<Unrecognised flag bits set>"));
2718 elf32_arm_get_symbol_type (elf_sym
, type
)
2719 Elf_Internal_Sym
* elf_sym
;
2722 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2725 return ELF_ST_TYPE (elf_sym
->st_info
);
2728 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2729 This allows us to distinguish between data used by Thumb instructions
2730 and non-data (which is probably code) inside Thumb regions of an
2732 if (type
!= STT_OBJECT
)
2733 return ELF_ST_TYPE (elf_sym
->st_info
);
2744 elf32_arm_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2746 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2747 Elf_Internal_Rela
*rel
;
2748 struct elf_link_hash_entry
*h
;
2749 Elf_Internal_Sym
*sym
;
2753 switch (ELF32_R_TYPE (rel
->r_info
))
2755 case R_ARM_GNU_VTINHERIT
:
2756 case R_ARM_GNU_VTENTRY
:
2760 switch (h
->root
.type
)
2762 case bfd_link_hash_defined
:
2763 case bfd_link_hash_defweak
:
2764 return h
->root
.u
.def
.section
;
2766 case bfd_link_hash_common
:
2767 return h
->root
.u
.c
.p
->section
;
2775 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2780 /* Update the got entry reference counts for the section being removed. */
2783 elf32_arm_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2784 bfd
*abfd ATTRIBUTE_UNUSED
;
2785 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2786 asection
*sec ATTRIBUTE_UNUSED
;
2787 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2789 Elf_Internal_Shdr
*symtab_hdr
;
2790 struct elf_link_hash_entry
**sym_hashes
;
2791 bfd_signed_vma
*local_got_refcounts
;
2792 const Elf_Internal_Rela
*rel
, *relend
;
2793 unsigned long r_symndx
;
2794 struct elf_link_hash_entry
*h
;
2796 elf_section_data (sec
)->local_dynrel
= NULL
;
2798 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2799 sym_hashes
= elf_sym_hashes (abfd
);
2800 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2802 relend
= relocs
+ sec
->reloc_count
;
2803 for (rel
= relocs
; rel
< relend
; rel
++)
2804 switch (ELF32_R_TYPE (rel
->r_info
))
2807 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2808 if (r_symndx
>= symtab_hdr
->sh_info
)
2810 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2811 if (h
->got
.refcount
> 0)
2812 h
->got
.refcount
-= 1;
2814 else if (local_got_refcounts
!= NULL
)
2816 if (local_got_refcounts
[r_symndx
] > 0)
2817 local_got_refcounts
[r_symndx
] -= 1;
2825 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2826 if (r_symndx
>= symtab_hdr
->sh_info
)
2828 struct elf32_arm_link_hash_entry
*eh
;
2829 struct elf32_arm_relocs_copied
**pp
;
2830 struct elf32_arm_relocs_copied
*p
;
2832 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2834 if (h
->plt
.refcount
> 0)
2835 h
->plt
.refcount
-= 1;
2837 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
2838 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
2840 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2842 for (pp
= &eh
->relocs_copied
; (p
= *pp
) != NULL
;
2844 if (p
->section
== sec
)
2862 /* Look through the relocs for a section during the first phase. */
2865 elf32_arm_check_relocs (abfd
, info
, sec
, relocs
)
2867 struct bfd_link_info
*info
;
2869 const Elf_Internal_Rela
*relocs
;
2871 Elf_Internal_Shdr
*symtab_hdr
;
2872 struct elf_link_hash_entry
**sym_hashes
;
2873 struct elf_link_hash_entry
**sym_hashes_end
;
2874 const Elf_Internal_Rela
*rel
;
2875 const Elf_Internal_Rela
*rel_end
;
2878 bfd_vma
*local_got_offsets
;
2879 struct elf32_arm_link_hash_table
*htab
;
2881 if (info
->relocatable
)
2884 htab
= elf32_arm_hash_table (info
);
2887 dynobj
= elf_hash_table (info
)->dynobj
;
2888 local_got_offsets
= elf_local_got_offsets (abfd
);
2890 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2891 sym_hashes
= elf_sym_hashes (abfd
);
2892 sym_hashes_end
= sym_hashes
2893 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2895 if (!elf_bad_symtab (abfd
))
2896 sym_hashes_end
-= symtab_hdr
->sh_info
;
2898 rel_end
= relocs
+ sec
->reloc_count
;
2899 for (rel
= relocs
; rel
< rel_end
; rel
++)
2901 struct elf_link_hash_entry
*h
;
2902 unsigned long r_symndx
;
2904 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2905 if (r_symndx
< symtab_hdr
->sh_info
)
2908 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2910 switch (ELF32_R_TYPE (rel
->r_info
))
2913 /* This symbol requires a global offset table entry. */
2920 bfd_signed_vma
*local_got_refcounts
;
2922 /* This is a global offset table entry for a local symbol. */
2923 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2924 if (local_got_refcounts
== NULL
)
2928 size
= symtab_hdr
->sh_info
;
2929 size
*= (sizeof (bfd_signed_vma
) + sizeof(char));
2930 local_got_refcounts
= ((bfd_signed_vma
*)
2931 bfd_zalloc (abfd
, size
));
2932 if (local_got_refcounts
== NULL
)
2934 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2936 local_got_refcounts
[r_symndx
] += 1;
2942 if (htab
->sgot
== NULL
)
2944 if (htab
->root
.dynobj
== NULL
)
2945 htab
->root
.dynobj
= abfd
;
2946 if (!create_got_section (htab
->root
.dynobj
, info
))
2957 /* If this reloc is in a read-only section, we might
2958 need a copy reloc. We can't check reliably at this
2959 stage whether the section is read-only, as input
2960 sections have not yet been mapped to output sections.
2961 Tentatively set the flag for now, and correct in
2962 adjust_dynamic_symbol. */
2964 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
2966 /* We may need a .plt entry if the function this reloc
2967 refers to is in a different object. We can't tell for
2968 sure yet, because something later might force the
2970 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
2971 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_PLT32
)
2972 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2974 /* If we create a PLT entry, this relocation will reference
2975 it, even if it's an ABS32 relocation. */
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
2994 && ELF32_R_TYPE (rel
->r_info
) != R_ARM_PLT32
)
2996 && (! info
->symbolic
2997 || (h
->elf_link_hash_flags
2998 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3000 struct elf32_arm_relocs_copied
*p
, **head
;
3002 /* When creating a shared object, we must copy these
3003 reloc types into the output file. We create a reloc
3004 section in dynobj and make room for this reloc. */
3009 name
= (bfd_elf_string_from_elf_section
3011 elf_elfheader (abfd
)->e_shstrndx
,
3012 elf_section_data (sec
)->rel_hdr
.sh_name
));
3016 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
3017 && strcmp (bfd_get_section_name (abfd
, sec
),
3020 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3025 sreloc
= bfd_make_section (dynobj
, name
);
3026 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3027 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3028 if ((sec
->flags
& SEC_ALLOC
) != 0)
3029 flags
|= SEC_ALLOC
| SEC_LOAD
;
3031 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
3032 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
3036 elf_section_data (sec
)->sreloc
= sreloc
;
3039 /* If this is a global symbol, we count the number of
3040 relocations we need for this symbol. */
3043 head
= &((struct elf32_arm_link_hash_entry
*) h
)->relocs_copied
;
3047 /* Track dynamic relocs needed for local syms too.
3048 We really need local syms available to do this
3052 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3057 head
= ((struct elf32_arm_relocs_copied
**)
3058 &elf_section_data (s
)->local_dynrel
);
3062 if (p
== NULL
|| p
->section
!= sec
)
3064 bfd_size_type amt
= sizeof *p
;
3065 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
3074 if (ELF32_R_TYPE (rel
->r_info
) == R_ARM_ABS32
3075 || ELF32_R_TYPE (rel
->r_info
) == R_ARM_REL32
)
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, 0, 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 /* Discard relocs on undefined weak syms with non-default
3437 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3438 && h
->root
.type
== bfd_link_hash_undefweak
)
3439 eh
->relocs_copied
= NULL
;
3443 /* For the non-shared case, discard space for relocs against
3444 symbols which turn out to need copy relocs or are not
3447 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3448 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3449 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3450 || (htab
->root
.dynamic_sections_created
3451 && (h
->root
.type
== bfd_link_hash_undefweak
3452 || h
->root
.type
== bfd_link_hash_undefined
))))
3454 /* Make sure this symbol is output as a dynamic symbol.
3455 Undefined weak syms won't yet be marked as dynamic. */
3456 if (h
->dynindx
== -1
3457 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3459 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3463 /* If that succeeded, we know we'll be keeping all the
3465 if (h
->dynindx
!= -1)
3469 eh
->relocs_copied
= NULL
;
3474 /* Finally, allocate space. */
3475 for (p
= eh
->relocs_copied
; p
!= NULL
; p
= p
->next
)
3477 asection
*sreloc
= elf_section_data (p
->section
)->sreloc
;
3478 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3484 /* Set the sizes of the dynamic sections. */
3487 elf32_arm_size_dynamic_sections (output_bfd
, info
)
3488 bfd
* output_bfd ATTRIBUTE_UNUSED
;
3489 struct bfd_link_info
* info
;
3496 struct elf32_arm_link_hash_table
*htab
;
3498 htab
= elf32_arm_hash_table (info
);
3499 dynobj
= elf_hash_table (info
)->dynobj
;
3500 BFD_ASSERT (dynobj
!= NULL
);
3502 if (elf_hash_table (info
)->dynamic_sections_created
)
3504 /* Set the contents of the .interp section to the interpreter. */
3505 if (info
->executable
)
3507 s
= bfd_get_section_by_name (dynobj
, ".interp");
3508 BFD_ASSERT (s
!= NULL
);
3509 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3510 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3514 /* Set up .got offsets for local syms, and space for local dynamic
3516 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3518 bfd_signed_vma
*local_got
;
3519 bfd_signed_vma
*end_local_got
;
3520 char *local_tls_type
;
3521 bfd_size_type locsymcount
;
3522 Elf_Internal_Shdr
*symtab_hdr
;
3525 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3528 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3530 struct elf32_arm_relocs_copied
*p
;
3532 for (p
= *((struct elf32_arm_relocs_copied
**)
3533 &elf_section_data (s
)->local_dynrel
);
3537 if (!bfd_is_abs_section (p
->section
)
3538 && bfd_is_abs_section (p
->section
->output_section
))
3540 /* Input section has been discarded, either because
3541 it is a copy of a linkonce section or due to
3542 linker script /DISCARD/, so we'll be discarding
3545 else if (p
->count
!= 0)
3547 srel
= elf_section_data (p
->section
)->sreloc
;
3548 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rel
);
3549 if ((p
->section
->output_section
->flags
& SEC_READONLY
) != 0)
3550 info
->flags
|= DF_TEXTREL
;
3555 local_got
= elf_local_got_refcounts (ibfd
);
3559 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3560 locsymcount
= symtab_hdr
->sh_info
;
3561 end_local_got
= local_got
+ locsymcount
;
3563 srel
= htab
->srelgot
;
3564 for (; local_got
< end_local_got
; ++local_got
, ++local_tls_type
)
3568 *local_got
= s
->_raw_size
;
3571 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3574 *local_got
= (bfd_vma
) -1;
3578 /* Allocate global sym .plt and .got entries, and space for global
3579 sym dynamic relocs. */
3580 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
3582 /* The check_relocs and adjust_dynamic_symbol entry points have
3583 determined the sizes of the various dynamic sections. Allocate
3587 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3592 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3595 /* It's OK to base decisions on the section name, because none
3596 of the dynobj section names depend upon the input files. */
3597 name
= bfd_get_section_name (dynobj
, s
);
3601 if (strcmp (name
, ".plt") == 0)
3603 if (s
->_raw_size
== 0)
3605 /* Strip this section if we don't need it; see the
3611 /* Remember whether there is a PLT. */
3615 else if (strncmp (name
, ".rel", 4) == 0)
3617 if (s
->_raw_size
== 0)
3619 /* If we don't need this section, strip it from the
3620 output file. This is mostly to handle .rel.bss and
3621 .rel.plt. We must create both sections in
3622 create_dynamic_sections, because they must be created
3623 before the linker maps input sections to output
3624 sections. The linker does that before
3625 adjust_dynamic_symbol is called, and it is that
3626 function which decides whether anything needs to go
3627 into these sections. */
3632 /* Remember whether there are any reloc sections other
3634 if (strcmp (name
, ".rel.plt") != 0)
3637 /* We use the reloc_count field as a counter if we need
3638 to copy relocs into the output file. */
3642 else if (strncmp (name
, ".got", 4) != 0)
3644 /* It's not one of our sections, so don't allocate space. */
3650 _bfd_strip_section_from_output (info
, s
);
3654 /* Allocate memory for the section contents. */
3655 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3656 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3660 if (elf_hash_table (info
)->dynamic_sections_created
)
3662 /* Add some entries to the .dynamic section. We fill in the
3663 values later, in elf32_arm_finish_dynamic_sections, but we
3664 must add the entries now so that we get the correct size for
3665 the .dynamic section. The DT_DEBUG entry is filled in by the
3666 dynamic linker and used by the debugger. */
3667 #define add_dynamic_entry(TAG, VAL) \
3668 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3672 if (!add_dynamic_entry (DT_DEBUG
, 0))
3678 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3679 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3680 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3681 || !add_dynamic_entry (DT_JMPREL
, 0))
3687 if ( !add_dynamic_entry (DT_REL
, 0)
3688 || !add_dynamic_entry (DT_RELSZ
, 0)
3689 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3693 if ((info
->flags
& DF_TEXTREL
) != 0)
3695 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3697 info
->flags
|= DF_TEXTREL
;
3700 #undef add_synamic_entry
3705 /* Finish up dynamic symbol handling. We set the contents of various
3706 dynamic sections here. */
3709 elf32_arm_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3711 struct bfd_link_info
* info
;
3712 struct elf_link_hash_entry
* h
;
3713 Elf_Internal_Sym
* sym
;
3717 dynobj
= elf_hash_table (info
)->dynobj
;
3719 if (h
->plt
.offset
!= (bfd_vma
) -1)
3726 Elf_Internal_Rela rel
;
3728 bfd_vma got_displacement
;
3730 /* This symbol has an entry in the procedure linkage table. Set
3733 BFD_ASSERT (h
->dynindx
!= -1);
3735 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3736 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3737 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3738 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
3740 /* Get the index in the procedure linkage table which
3741 corresponds to this symbol. This is the index of this symbol
3742 in all the symbols for which we are making plt entries. The
3743 first entry in the procedure linkage table is reserved. */
3744 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3746 /* Get the offset into the .got table of the entry that
3747 corresponds to this function. Each .got entry is 4 bytes.
3748 The first three are reserved. */
3749 got_offset
= (plt_index
+ 3) * 4;
3751 /* Calculate the displacement between the PLT slot and the
3752 entry in the GOT. */
3753 got_displacement
= (sgot
->output_section
->vma
3754 + sgot
->output_offset
3756 - splt
->output_section
->vma
3757 - splt
->output_offset
3761 BFD_ASSERT ((got_displacement
& 0xf0000000) == 0);
3763 /* Fill in the entry in the procedure linkage table. */
3764 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0] | ((got_displacement
& 0x0ff00000) >> 20),
3765 splt
->contents
+ h
->plt
.offset
+ 0);
3766 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1] | ((got_displacement
& 0x000ff000) >> 12),
3767 splt
->contents
+ h
->plt
.offset
+ 4);
3768 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2] | (got_displacement
& 0x00000fff),
3769 splt
->contents
+ h
->plt
.offset
+ 8);
3770 #ifdef FOUR_WORD_PLT
3771 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[3],
3772 splt
->contents
+ h
->plt
.offset
+ 12);
3775 /* Fill in the entry in the global offset table. */
3776 bfd_put_32 (output_bfd
,
3777 (splt
->output_section
->vma
3778 + splt
->output_offset
),
3779 sgot
->contents
+ got_offset
);
3781 /* Fill in the entry in the .rel.plt section. */
3782 rel
.r_offset
= (sgot
->output_section
->vma
3783 + sgot
->output_offset
3785 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3786 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rel
);
3787 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3789 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3791 /* Mark the symbol as undefined, rather than as defined in
3792 the .plt section. Leave the value alone. */
3793 sym
->st_shndx
= SHN_UNDEF
;
3794 /* If the symbol is weak, we do need to clear the value.
3795 Otherwise, the PLT entry would provide a definition for
3796 the symbol even if the symbol wasn't defined anywhere,
3797 and so the symbol would never be NULL. */
3798 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
3804 if (h
->got
.offset
!= (bfd_vma
) -1)
3808 Elf_Internal_Rela rel
;
3811 /* This symbol has an entry in the global offset table. Set it
3813 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3814 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3815 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3817 rel
.r_offset
= (sgot
->output_section
->vma
3818 + sgot
->output_offset
3819 + (h
->got
.offset
&~ (bfd_vma
) 1));
3821 /* If this is a static link, or it is a -Bsymbolic link and the
3822 symbol is defined locally or was forced to be local because
3823 of a version file, we just want to emit a RELATIVE reloc.
3824 The entry in the global offset table will already have been
3825 initialized in the relocate_section function. */
3827 && SYMBOL_REFERENCES_LOCAL (info
, h
))
3829 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3830 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3834 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3835 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3836 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3839 loc
= srel
->contents
+ srel
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3840 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3843 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3846 Elf_Internal_Rela rel
;
3849 /* This symbol needs a copy reloc. Set it up. */
3850 BFD_ASSERT (h
->dynindx
!= -1
3851 && (h
->root
.type
== bfd_link_hash_defined
3852 || h
->root
.type
== bfd_link_hash_defweak
));
3854 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3856 BFD_ASSERT (s
!= NULL
);
3858 rel
.r_offset
= (h
->root
.u
.def
.value
3859 + h
->root
.u
.def
.section
->output_section
->vma
3860 + h
->root
.u
.def
.section
->output_offset
);
3861 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3862 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rel
);
3863 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
3866 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3867 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3868 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3869 sym
->st_shndx
= SHN_ABS
;
3874 /* Finish up the dynamic sections. */
3877 elf32_arm_finish_dynamic_sections (output_bfd
, info
)
3879 struct bfd_link_info
* info
;
3885 dynobj
= elf_hash_table (info
)->dynobj
;
3887 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3888 BFD_ASSERT (sgot
!= NULL
);
3889 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3891 if (elf_hash_table (info
)->dynamic_sections_created
)
3894 Elf32_External_Dyn
*dyncon
, *dynconend
;
3896 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3897 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3899 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3900 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3902 for (; dyncon
< dynconend
; dyncon
++)
3904 Elf_Internal_Dyn dyn
;
3908 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3921 s
= bfd_get_section_by_name (output_bfd
, name
);
3922 BFD_ASSERT (s
!= NULL
);
3923 dyn
.d_un
.d_ptr
= s
->vma
;
3924 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3928 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3929 BFD_ASSERT (s
!= NULL
);
3930 if (s
->_cooked_size
!= 0)
3931 dyn
.d_un
.d_val
= s
->_cooked_size
;
3933 dyn
.d_un
.d_val
= s
->_raw_size
;
3934 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3938 /* My reading of the SVR4 ABI indicates that the
3939 procedure linkage table relocs (DT_JMPREL) should be
3940 included in the overall relocs (DT_REL). This is
3941 what Solaris does. However, UnixWare can not handle
3942 that case. Therefore, we override the DT_RELSZ entry
3943 here to make it not include the JMPREL relocs. Since
3944 the linker script arranges for .rel.plt to follow all
3945 other relocation sections, we don't have to worry
3946 about changing the DT_REL entry. */
3947 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3950 if (s
->_cooked_size
!= 0)
3951 dyn
.d_un
.d_val
-= s
->_cooked_size
;
3953 dyn
.d_un
.d_val
-= s
->_raw_size
;
3955 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3958 /* Set the bottom bit of DT_INIT/FINI if the
3959 corresponding function is Thumb. */
3961 name
= info
->init_function
;
3964 name
= info
->fini_function
;
3966 /* If it wasn't set by elf_bfd_final_link
3967 then there is nothing to adjust. */
3968 if (dyn
.d_un
.d_val
!= 0)
3970 struct elf_link_hash_entry
* eh
;
3972 eh
= elf_link_hash_lookup (elf_hash_table (info
), name
,
3973 FALSE
, FALSE
, TRUE
);
3974 if (eh
!= (struct elf_link_hash_entry
*) NULL
3975 && ELF_ST_TYPE (eh
->type
) == STT_ARM_TFUNC
)
3977 dyn
.d_un
.d_val
|= 1;
3978 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3985 /* Fill in the first entry in the procedure linkage table. */
3986 if (splt
->_raw_size
> 0)
3988 bfd_vma got_displacement
;
3990 /* Calculate the displacement between the PLT slot and &GOT[0]. */
3991 got_displacement
= (sgot
->output_section
->vma
3992 + sgot
->output_offset
3993 - splt
->output_section
->vma
3994 - splt
->output_offset
3997 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
3998 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
3999 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
4000 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
4001 #ifdef FOUR_WORD_PLT
4002 /* The displacement value goes in the otherwise-unused last word of
4003 the second entry. */
4004 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 28);
4006 bfd_put_32 (output_bfd
, got_displacement
, splt
->contents
+ 16);
4010 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4011 really seem like the right value. */
4012 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
4015 /* Fill in the first three entries in the global offset table. */
4016 if (sgot
->_raw_size
> 0)
4019 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4021 bfd_put_32 (output_bfd
,
4022 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4024 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4025 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4028 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4034 elf32_arm_post_process_headers (abfd
, link_info
)
4036 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
4038 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
4040 i_ehdrp
= elf_elfheader (abfd
);
4042 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
4043 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
4046 static enum elf_reloc_type_class
4047 elf32_arm_reloc_type_class (rela
)
4048 const Elf_Internal_Rela
*rela
;
4050 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4052 case R_ARM_RELATIVE
:
4053 return reloc_class_relative
;
4054 case R_ARM_JUMP_SLOT
:
4055 return reloc_class_plt
;
4057 return reloc_class_copy
;
4059 return reloc_class_normal
;
4063 static bfd_boolean elf32_arm_section_flags
PARAMS ((flagword
*, Elf_Internal_Shdr
*));
4064 static void elf32_arm_final_write_processing
PARAMS ((bfd
*, bfd_boolean
));
4066 /* Set the right machine number for an Arm ELF file. */
4069 elf32_arm_section_flags (flags
, hdr
)
4071 Elf_Internal_Shdr
*hdr
;
4073 if (hdr
->sh_type
== SHT_NOTE
)
4074 *flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_CONTENTS
;
4080 elf32_arm_final_write_processing (abfd
, linker
)
4082 bfd_boolean linker ATTRIBUTE_UNUSED
;
4084 bfd_arm_update_notes (abfd
, ARM_NOTE_SECTION
);
4087 #define ELF_ARCH bfd_arch_arm
4088 #define ELF_MACHINE_CODE EM_ARM
4089 #ifdef __QNXTARGET__
4090 #define ELF_MAXPAGESIZE 0x1000
4092 #define ELF_MAXPAGESIZE 0x8000
4095 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
4096 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
4097 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
4098 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
4099 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
4100 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
4101 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4103 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
4104 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
4105 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
4106 #define elf_backend_check_relocs elf32_arm_check_relocs
4107 #define elf_backend_relocate_section elf32_arm_relocate_section
4108 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
4109 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
4110 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
4111 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
4112 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
4113 #define elf_backend_post_process_headers elf32_arm_post_process_headers
4114 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
4115 #define elf_backend_object_p elf32_arm_object_p
4116 #define elf_backend_section_flags elf32_arm_section_flags
4117 #define elf_backend_final_write_processing elf32_arm_final_write_processing
4118 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
4120 #define elf_backend_can_refcount 1
4121 #define elf_backend_can_gc_sections 1
4122 #define elf_backend_plt_readonly 1
4123 #define elf_backend_want_got_plt 1
4124 #define elf_backend_want_plt_sym 0
4126 #define elf_backend_rela_normal 1
4129 #define elf_backend_got_header_size 12
4131 #include "elf32-target.h"