1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 typedef unsigned long int insn32
;
21 typedef unsigned short int insn16
;
23 static boolean elf32_arm_set_private_flags
24 PARAMS ((bfd
*, flagword
));
25 static boolean elf32_arm_copy_private_bfd_data
26 PARAMS ((bfd
*, bfd
*));
27 static boolean elf32_arm_merge_private_bfd_data
28 PARAMS ((bfd
*, bfd
*));
29 static boolean elf32_arm_print_private_bfd_data
30 PARAMS ((bfd
*, PTR
));
31 static int elf32_arm_get_symbol_type
32 PARAMS (( Elf_Internal_Sym
*, int));
33 static struct bfd_link_hash_table
*elf32_arm_link_hash_table_create
35 static bfd_reloc_status_type elf32_arm_final_link_relocate
36 PARAMS ((reloc_howto_type
*, bfd
*, bfd
*, asection
*, bfd_byte
*,
37 Elf_Internal_Rela
*, bfd_vma
, struct bfd_link_info
*, asection
*,
38 const char *, int, struct elf_link_hash_entry
*));
39 static insn32 insert_thumb_branch
40 PARAMS ((insn32
, int));
41 static struct elf_link_hash_entry
*find_thumb_glue
42 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
43 static struct elf_link_hash_entry
*find_arm_glue
44 PARAMS ((struct bfd_link_info
*, const char *, bfd
*));
45 static void elf32_arm_post_process_headers
46 PARAMS ((bfd
*, struct bfd_link_info
*));
47 static int elf32_arm_to_thumb_stub
48 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
49 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
50 static int elf32_thumb_to_arm_stub
51 PARAMS ((struct bfd_link_info
*, const char *, bfd
*, bfd
*, asection
*,
52 bfd_byte
*, asection
*, bfd_vma
, bfd_signed_vma
, bfd_vma
));
53 static boolean elf32_arm_relocate_section
54 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
55 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
56 static asection
* elf32_arm_gc_mark_hook
57 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
58 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
59 static boolean elf32_arm_gc_sweep_hook
60 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
61 const Elf_Internal_Rela
*));
62 static boolean elf32_arm_check_relocs
63 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
64 const Elf_Internal_Rela
*));
65 static boolean elf32_arm_find_nearest_line
66 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
67 const char **, unsigned int *));
68 static boolean elf32_arm_adjust_dynamic_symbol
69 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
70 static boolean elf32_arm_size_dynamic_sections
71 PARAMS ((bfd
*, struct bfd_link_info
*));
72 static boolean elf32_arm_finish_dynamic_symbol
73 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
75 static boolean elf32_arm_finish_dynamic_sections
76 PARAMS ((bfd
*, struct bfd_link_info
*));
77 static struct bfd_hash_entry
* elf32_arm_link_hash_newfunc
78 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
80 static void arm_add_to_rel
81 PARAMS ((bfd
*, bfd_byte
*, reloc_howto_type
*, bfd_signed_vma
));
83 static enum elf_reloc_type_class elf32_arm_reloc_type_class
84 PARAMS ((const Elf_Internal_Rela
*));
86 #ifndef ELFARM_NABI_C_INCLUDED
87 static void record_arm_to_thumb_glue
88 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
89 static void record_thumb_to_arm_glue
90 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
91 boolean bfd_elf32_arm_allocate_interworking_sections
92 PARAMS ((struct bfd_link_info
*));
93 boolean bfd_elf32_arm_get_bfd_for_interworking
94 PARAMS ((bfd
*, struct bfd_link_info
*));
95 boolean bfd_elf32_arm_process_before_allocation
96 PARAMS ((bfd
*, struct bfd_link_info
*, int));
98 static boolean elf32_arm_create_dynamic_sections
99 PARAMS ((bfd
*, struct bfd_link_info
*));
102 #define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
104 /* The linker script knows the section names for placement.
105 The entry_names are used to do simple name mangling on the stubs.
106 Given a function name, and its type, the stub can be found. The
107 name can be changed. The only requirement is the %s be present. */
108 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
109 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
111 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
112 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
114 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
118 /* The size in bytes of an entry in the procedure linkage table. */
119 #define ARM_PLT_ENTRY_SIZE 16
120 #define THUMB_PLT_ENTRY_SIZE 20
121 #define PLT_ENTRY_SIZE(ARM) \
122 ((ARM) ? ARM_PLT_ENTRY_SIZE : THUMB_PLT_ENTRY_SIZE)
124 /* The first entry in a procedure linkage table looks like
125 this. It is set up so that any shared library function that is
126 called before the relocation has been set up calls the dynamic
128 static const bfd_vma elf32_arm_plt0_entry
[ARM_PLT_ENTRY_SIZE
/ 4] =
130 0xe52de004, /* str lr, [sp, #-4]! */
131 0xe59fe010, /* ldr lr, [pc, #16] */
132 0xe08fe00e, /* add lr, pc, lr */
133 0xe5bef008 /* ldr pc, [lr, #8]! */
136 static const insn16 elf32_thumb_plt0_entry
[THUMB_PLT_ENTRY_SIZE
/ 2] =
138 0xb500, /* push {lr} */
139 0xb082, /* sub sp, #8 */
140 0x9000, /* str r0, [sp] */
141 0x4807, /* ldr r0, [pc, #28] */
142 0x300c, /* add r0, #12 */
143 0x4478, /* add r0, pc */
144 0x4686, /* mov lr, r0 */
145 0x6800, /* ldr r0, [r0] */
146 0x9001, /* str r0, [sp, #4] */
147 0xbd01 /* pop {r0, pc} */
150 /* Subsequent entries in a procedure linkage table look like
152 static const bfd_vma elf32_arm_plt_entry
[ARM_PLT_ENTRY_SIZE
/ 4] =
154 0xe59fc004, /* ldr ip, [pc, #4] */
155 0xe08fc00c, /* add ip, pc, ip */
156 0xe59cf000, /* ldr pc, [ip] */
157 0x00000000 /* offset to symbol in got */
160 /* Note that on ARMv5 and above unlike the ARM PLT entries, the Thumb
161 entry can switch mode depending on the corresponding address in the
162 GOT. The dynamic linker should set or clear the last bit of the
163 address in the GOT accordingly. */
165 static const insn16 elf32_thumb_plt_entry
[THUMB_PLT_ENTRY_SIZE
/ 2] =
167 0xb082, /* sub sp, #8 */
168 0x9000, /* str r0, [sp] */
169 0x4802, /* ldr r0, [pc, #8] */
170 0x4478, /* add r0, pc */
171 0x4684, /* mov ip, r0 */
172 0x6800, /* ldr r0, [r0] */
173 0x9001, /* str r0, [sp, #4] */
174 0xbd01, /* pop {r0, pc} */
175 0x0000, /* offset to symbol in got */
179 /* The ARM linker needs to keep track of the number of relocs that it
180 decides to copy in check_relocs for each symbol. This is so that
181 it can discard PC relative relocs if it doesn't need them when
182 linking with -Bsymbolic. We store the information in a field
183 extending the regular ELF linker hash table. */
185 /* This structure keeps track of the number of PC relative relocs we
186 have copied for a given symbol. */
187 struct elf32_arm_pcrel_relocs_copied
190 struct elf32_arm_pcrel_relocs_copied
* next
;
191 /* A section in dynobj. */
193 /* Number of relocs copied in this section. */
198 /* We can generate Thumb or ARM PLT entries. This structure holds
199 additional information for symbols that have corresponding PLT
202 struct elf32_arm_plt_entry_info
204 /* The first relocation type referring to this PLT entry. Used to
205 determine the type of the entry if the symbol is undefined. */
208 /* True if we decided to emit the ARM version of the PLT entry for
209 this symbol. Otherwise the entry is Thumb. */
212 /* The offset of the corresponding .got.plt entry. */
213 bfd_vma got_plt_offset
;
216 /* Arm ELF linker hash entry. */
217 struct elf32_arm_link_hash_entry
219 struct elf_link_hash_entry root
;
221 /* Number of PC relative relocs copied for this symbol. */
222 struct elf32_arm_pcrel_relocs_copied
* pcrel_relocs_copied
;
224 struct elf32_arm_plt_entry_info plt_info
;
227 /* Declare this now that the above structures are defined. */
228 static boolean elf32_arm_discard_copies
229 PARAMS ((struct elf32_arm_link_hash_entry
*, PTR
));
231 /* Traverse an arm ELF linker hash table. */
232 #define elf32_arm_link_hash_traverse(table, func, info) \
233 (elf_link_hash_traverse \
235 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
238 /* Get the ARM elf linker hash table from a link_info structure. */
239 #define elf32_arm_hash_table(info) \
240 ((struct elf32_arm_link_hash_table *) ((info)->hash))
242 /* ARM ELF linker hash table. */
243 struct elf32_arm_link_hash_table
245 /* The main hash table. */
246 struct elf_link_hash_table root
;
248 /* The size in bytes of the section containg the Thumb-to-ARM glue. */
249 bfd_size_type thumb_glue_size
;
251 /* The size in bytes of the section containg the ARM-to-Thumb glue. */
252 bfd_size_type arm_glue_size
;
254 /* An arbitary input BFD chosen to hold the glue sections. */
255 bfd
* bfd_of_glue_owner
;
257 /* A boolean indicating whether knowledge of the ARM's pipeline
258 length should be applied by the linker. */
259 int no_pipeline_knowledge
;
262 /* Create an entry in an ARM ELF linker hash table. */
264 static struct bfd_hash_entry
*
265 elf32_arm_link_hash_newfunc (entry
, table
, string
)
266 struct bfd_hash_entry
* entry
;
267 struct bfd_hash_table
* table
;
270 struct elf32_arm_link_hash_entry
* ret
=
271 (struct elf32_arm_link_hash_entry
*) entry
;
273 /* Allocate the structure if it has not already been allocated by a
275 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
276 ret
= ((struct elf32_arm_link_hash_entry
*)
277 bfd_hash_allocate (table
,
278 sizeof (struct elf32_arm_link_hash_entry
)));
279 if (ret
== (struct elf32_arm_link_hash_entry
*) NULL
)
280 return (struct bfd_hash_entry
*) ret
;
282 /* Call the allocation method of the superclass. */
283 ret
= ((struct elf32_arm_link_hash_entry
*)
284 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
286 if (ret
!= (struct elf32_arm_link_hash_entry
*) NULL
)
288 ret
->pcrel_relocs_copied
= NULL
;
289 ret
->plt_info
.first_rel_type
= R_ARM_NONE
;
292 return (struct bfd_hash_entry
*) ret
;
295 /* Create an ARM elf linker hash table. */
297 static struct bfd_link_hash_table
*
298 elf32_arm_link_hash_table_create (abfd
)
301 struct elf32_arm_link_hash_table
*ret
;
302 bfd_size_type amt
= sizeof (struct elf32_arm_link_hash_table
);
304 ret
= (struct elf32_arm_link_hash_table
*) bfd_malloc (amt
);
305 if (ret
== (struct elf32_arm_link_hash_table
*) NULL
)
308 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
309 elf32_arm_link_hash_newfunc
))
315 ret
->thumb_glue_size
= 0;
316 ret
->arm_glue_size
= 0;
317 ret
->bfd_of_glue_owner
= NULL
;
318 ret
->no_pipeline_knowledge
= 0;
320 return &ret
->root
.root
;
323 /* Locate the Thumb encoded calling stub for NAME. */
325 static struct elf_link_hash_entry
*
326 find_thumb_glue (link_info
, name
, input_bfd
)
327 struct bfd_link_info
*link_info
;
332 struct elf_link_hash_entry
*hash
;
333 struct elf32_arm_link_hash_table
*hash_table
;
335 /* We need a pointer to the armelf specific hash table. */
336 hash_table
= elf32_arm_hash_table (link_info
);
338 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
339 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
341 BFD_ASSERT (tmp_name
);
343 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
345 hash
= elf_link_hash_lookup
346 (&(hash_table
)->root
, tmp_name
, false, false, true);
349 /* xgettext:c-format */
350 (*_bfd_error_handler
) (_("%s: unable to find THUMB glue '%s' for `%s'"),
351 bfd_archive_filename (input_bfd
), tmp_name
, name
);
358 /* Locate the ARM encoded calling stub for NAME. */
360 static struct elf_link_hash_entry
*
361 find_arm_glue (link_info
, name
, input_bfd
)
362 struct bfd_link_info
*link_info
;
367 struct elf_link_hash_entry
*myh
;
368 struct elf32_arm_link_hash_table
*hash_table
;
370 /* We need a pointer to the elfarm specific hash table. */
371 hash_table
= elf32_arm_hash_table (link_info
);
373 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
374 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
376 BFD_ASSERT (tmp_name
);
378 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
380 myh
= elf_link_hash_lookup
381 (&(hash_table
)->root
, tmp_name
, false, false, true);
384 /* xgettext:c-format */
385 (*_bfd_error_handler
) (_("%s: unable to find ARM glue '%s' for `%s'"),
386 bfd_archive_filename (input_bfd
), tmp_name
, name
);
400 .word func @ behave as if you saw a ARM_32 reloc. */
402 #define ARM2THUMB_GLUE_SIZE 12
403 static const insn32 a2t1_ldr_insn
= 0xe59fc000;
404 static const insn32 a2t2_bx_r12_insn
= 0xe12fff1c;
405 static const insn32 a2t3_func_addr_insn
= 0x00000001;
407 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
411 __func_from_thumb: __func_from_thumb:
413 nop ldr r6, __func_addr
415 __func_change_to_arm: bx r6
417 __func_back_to_thumb:
423 #define THUMB2ARM_GLUE_SIZE 8
424 static const insn16 t2a1_bx_pc_insn
= 0x4778;
425 static const insn16 t2a2_noop_insn
= 0x46c0;
426 static const insn32 t2a3_b_insn
= 0xea000000;
428 static const insn16 t2a1_push_insn
= 0xb540;
429 static const insn16 t2a2_ldr_insn
= 0x4e03;
430 static const insn16 t2a3_mov_insn
= 0x46fe;
431 static const insn16 t2a4_bx_insn
= 0x4730;
432 static const insn32 t2a5_pop_insn
= 0xe8bd4040;
433 static const insn32 t2a6_bx_insn
= 0xe12fff1e;
435 #ifndef ELFARM_NABI_C_INCLUDED
437 bfd_elf32_arm_allocate_interworking_sections (info
)
438 struct bfd_link_info
* info
;
442 struct elf32_arm_link_hash_table
* globals
;
444 globals
= elf32_arm_hash_table (info
);
446 BFD_ASSERT (globals
!= NULL
);
448 if (globals
->arm_glue_size
!= 0)
450 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
452 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
453 ARM2THUMB_GLUE_SECTION_NAME
);
455 BFD_ASSERT (s
!= NULL
);
457 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
458 globals
->arm_glue_size
);
460 s
->_raw_size
= s
->_cooked_size
= globals
->arm_glue_size
;
464 if (globals
->thumb_glue_size
!= 0)
466 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
468 s
= bfd_get_section_by_name
469 (globals
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
471 BFD_ASSERT (s
!= NULL
);
473 foo
= (bfd_byte
*) bfd_alloc (globals
->bfd_of_glue_owner
,
474 globals
->thumb_glue_size
);
476 s
->_raw_size
= s
->_cooked_size
= globals
->thumb_glue_size
;
484 record_arm_to_thumb_glue (link_info
, h
)
485 struct bfd_link_info
* link_info
;
486 struct elf_link_hash_entry
* h
;
488 const char * name
= h
->root
.root
.string
;
491 struct elf_link_hash_entry
* myh
;
492 struct elf32_arm_link_hash_table
* globals
;
495 globals
= elf32_arm_hash_table (link_info
);
497 BFD_ASSERT (globals
!= NULL
);
498 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
500 s
= bfd_get_section_by_name
501 (globals
->bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
503 BFD_ASSERT (s
!= NULL
);
505 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
506 + strlen (ARM2THUMB_GLUE_ENTRY_NAME
) + 1);
508 BFD_ASSERT (tmp_name
);
510 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
512 myh
= elf_link_hash_lookup
513 (&(globals
)->root
, tmp_name
, false, false, true);
517 /* We've already seen this guy. */
522 /* The only trick here is using hash_table->arm_glue_size as the value. Even
523 though the section isn't allocated yet, this is where we will be putting
525 val
= globals
->arm_glue_size
+ 1;
526 _bfd_generic_link_add_one_symbol (link_info
, globals
->bfd_of_glue_owner
,
527 tmp_name
, BSF_GLOBAL
, s
, val
,
529 (struct bfd_link_hash_entry
**) &myh
);
533 globals
->arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
539 record_thumb_to_arm_glue (link_info
, h
)
540 struct bfd_link_info
*link_info
;
541 struct elf_link_hash_entry
*h
;
543 const char *name
= h
->root
.root
.string
;
546 struct elf_link_hash_entry
*myh
;
547 struct elf32_arm_link_hash_table
*hash_table
;
551 hash_table
= elf32_arm_hash_table (link_info
);
553 BFD_ASSERT (hash_table
!= NULL
);
554 BFD_ASSERT (hash_table
->bfd_of_glue_owner
!= NULL
);
556 s
= bfd_get_section_by_name
557 (hash_table
->bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
559 BFD_ASSERT (s
!= NULL
);
561 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
562 + strlen (THUMB2ARM_GLUE_ENTRY_NAME
) + 1);
564 BFD_ASSERT (tmp_name
);
566 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
568 myh
= elf_link_hash_lookup
569 (&(hash_table
)->root
, tmp_name
, false, false, true);
573 /* We've already seen this guy. */
578 val
= hash_table
->thumb_glue_size
+ 1;
579 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
580 tmp_name
, BSF_GLOBAL
, s
, val
,
582 (struct bfd_link_hash_entry
**) &myh
);
584 /* If we mark it 'Thumb', the disassembler will do a better job. */
585 bind
= ELF_ST_BIND (myh
->type
);
586 myh
->type
= ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
590 #define CHANGE_TO_ARM "__%s_change_to_arm"
591 #define BACK_FROM_ARM "__%s_back_from_arm"
593 /* Allocate another symbol to mark where we switch to Arm mode. */
594 tmp_name
= (char *) bfd_malloc ((bfd_size_type
) strlen (name
)
595 + strlen (CHANGE_TO_ARM
) + 1);
597 BFD_ASSERT (tmp_name
);
599 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
603 val
= hash_table
->thumb_glue_size
+ 4,
604 _bfd_generic_link_add_one_symbol (link_info
, hash_table
->bfd_of_glue_owner
,
605 tmp_name
, BSF_LOCAL
, s
, val
,
607 (struct bfd_link_hash_entry
**) &myh
);
611 hash_table
->thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
616 /* Add the glue sections to ABFD. This function is called from the
617 linker scripts in ld/emultempl/{armelf}.em. */
620 bfd_elf32_arm_add_glue_sections_to_bfd (abfd
, info
)
622 struct bfd_link_info
*info
;
627 /* If we are only performing a partial
628 link do not bother adding the glue. */
629 if (info
->relocateable
)
632 sec
= bfd_get_section_by_name (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
636 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
637 will prevent elf_link_input_bfd() from processing the contents
639 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
641 sec
= bfd_make_section (abfd
, ARM2THUMB_GLUE_SECTION_NAME
);
644 || !bfd_set_section_flags (abfd
, sec
, flags
)
645 || !bfd_set_section_alignment (abfd
, sec
, 2))
648 /* Set the gc mark to prevent the section from being removed by garbage
649 collection, despite the fact that no relocs refer to this section. */
653 sec
= bfd_get_section_by_name (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
657 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_CODE
| SEC_READONLY
;
659 sec
= bfd_make_section (abfd
, THUMB2ARM_GLUE_SECTION_NAME
);
662 || !bfd_set_section_flags (abfd
, sec
, flags
)
663 || !bfd_set_section_alignment (abfd
, sec
, 2))
672 /* Select a BFD to be used to hold the sections used by the glue code.
673 This function is called from the linker scripts in ld/emultempl/
677 bfd_elf32_arm_get_bfd_for_interworking (abfd
, info
)
679 struct bfd_link_info
*info
;
681 struct elf32_arm_link_hash_table
*globals
;
683 /* If we are only performing a partial link
684 do not bother getting a bfd to hold the glue. */
685 if (info
->relocateable
)
688 globals
= elf32_arm_hash_table (info
);
690 BFD_ASSERT (globals
!= NULL
);
692 if (globals
->bfd_of_glue_owner
!= NULL
)
695 /* Save the bfd for later use. */
696 globals
->bfd_of_glue_owner
= abfd
;
702 bfd_elf32_arm_process_before_allocation (abfd
, link_info
, no_pipeline_knowledge
)
704 struct bfd_link_info
*link_info
;
705 int no_pipeline_knowledge
;
707 Elf_Internal_Shdr
*symtab_hdr
;
708 Elf_Internal_Rela
*internal_relocs
= NULL
;
709 Elf_Internal_Rela
*irel
, *irelend
;
710 bfd_byte
*contents
= NULL
;
713 struct elf32_arm_link_hash_table
*globals
;
715 /* If we are only performing a partial link do not bother
716 to construct any glue. */
717 if (link_info
->relocateable
)
720 /* Here we have a bfd that is to be included on the link. We have a hook
721 to do reloc rummaging, before section sizes are nailed down. */
722 globals
= elf32_arm_hash_table (link_info
);
724 BFD_ASSERT (globals
!= NULL
);
725 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
727 globals
->no_pipeline_knowledge
= no_pipeline_knowledge
;
729 /* Rummage around all the relocs and map the glue vectors. */
730 sec
= abfd
->sections
;
735 for (; sec
!= NULL
; sec
= sec
->next
)
737 if (sec
->reloc_count
== 0)
740 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
742 /* Load the relocs. */
744 = _bfd_elf32_link_read_relocs (abfd
, sec
, (PTR
) NULL
,
745 (Elf_Internal_Rela
*) NULL
, false);
747 if (internal_relocs
== NULL
)
750 irelend
= internal_relocs
+ sec
->reloc_count
;
751 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
754 unsigned long r_index
;
756 struct elf_link_hash_entry
*h
;
758 r_type
= ELF32_R_TYPE (irel
->r_info
);
759 r_index
= ELF32_R_SYM (irel
->r_info
);
761 /* These are the only relocation types we care about. */
762 if ( r_type
!= R_ARM_PC24
763 && r_type
!= R_ARM_THM_PC22
)
766 /* Get the section contents if we haven't done so already. */
767 if (contents
== NULL
)
769 /* Get cached copy if it exists. */
770 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
771 contents
= elf_section_data (sec
)->this_hdr
.contents
;
774 /* Go get them off disk. */
775 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
776 if (contents
== NULL
)
779 if (!bfd_get_section_contents (abfd
, sec
, contents
,
780 (file_ptr
) 0, sec
->_raw_size
))
785 /* If the relocation is not against a symbol it cannot concern us. */
788 /* We don't care about local symbols. */
789 if (r_index
< symtab_hdr
->sh_info
)
792 /* This is an external symbol. */
793 r_index
-= symtab_hdr
->sh_info
;
794 h
= (struct elf_link_hash_entry
*)
795 elf_sym_hashes (abfd
)[r_index
];
797 /* If the relocation is against a static symbol it must be within
798 the current section and so cannot be a cross ARM/Thumb relocation. */
805 /* This one is a call from arm code. We need to look up
806 the target of the call. If it is a thumb target, we
808 if (ELF_ST_TYPE(h
->type
) == STT_ARM_TFUNC
)
809 record_arm_to_thumb_glue (link_info
, h
);
813 /* This one is a call from thumb code. We look
814 up the target of the call. If it is not a thumb
815 target, we insert glue. */
816 if (ELF_ST_TYPE (h
->type
) != STT_ARM_TFUNC
)
817 record_thumb_to_arm_glue (link_info
, h
);
826 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
830 if (internal_relocs
!= NULL
831 && elf_section_data (sec
)->relocs
!= internal_relocs
)
832 free (internal_relocs
);
833 internal_relocs
= NULL
;
840 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
842 if (internal_relocs
!= NULL
843 && elf_section_data (sec
)->relocs
!= internal_relocs
)
844 free (internal_relocs
);
850 /* The thumb form of a long branch is a bit finicky, because the offset
851 encoding is split over two fields, each in it's own instruction. They
852 can occur in any order. So given a thumb form of long branch, and an
853 offset, insert the offset into the thumb branch and return finished
856 It takes two thumb instructions to encode the target address. Each has
857 11 bits to invest. The upper 11 bits are stored in one (identifed by
858 H-0.. see below), the lower 11 bits are stored in the other (identified
861 Combine together and shifted left by 1 (it's a half word address) and
865 H-0, upper address-0 = 000
867 H-1, lower address-0 = 800
869 They can be ordered either way, but the arm tools I've seen always put
870 the lower one first. It probably doesn't matter. krk@cygnus.com
872 XXX: Actually the order does matter. The second instruction (H-1)
873 moves the computed address into the PC, so it must be the second one
874 in the sequence. The problem, however is that whilst little endian code
875 stores the instructions in HI then LOW order, big endian code does the
876 reverse. nickc@cygnus.com. */
878 #define LOW_HI_ORDER 0xF800F000
879 #define HI_LOW_ORDER 0xF000F800
882 insert_thumb_branch (br_insn
, rel_off
)
886 unsigned int low_bits
;
887 unsigned int high_bits
;
889 BFD_ASSERT ((rel_off
& 1) != 1);
891 rel_off
>>= 1; /* Half word aligned address. */
892 low_bits
= rel_off
& 0x000007FF; /* The bottom 11 bits. */
893 high_bits
= (rel_off
>> 11) & 0x000007FF; /* The top 11 bits. */
895 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
896 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
897 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
898 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
900 /* FIXME: abort is probably not the right call. krk@cygnus.com */
901 abort (); /* error - not a valid branch instruction form. */
906 /* Thumb code calling an ARM function. */
909 elf32_thumb_to_arm_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
910 hit_data
, sym_sec
, offset
, addend
, val
)
911 struct bfd_link_info
* info
;
915 asection
* input_section
;
919 bfd_signed_vma addend
;
924 unsigned long int tmp
;
926 struct elf_link_hash_entry
* myh
;
927 struct elf32_arm_link_hash_table
* globals
;
929 myh
= find_thumb_glue (info
, name
, input_bfd
);
933 globals
= elf32_arm_hash_table (info
);
935 BFD_ASSERT (globals
!= NULL
);
936 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
938 my_offset
= myh
->root
.u
.def
.value
;
940 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
941 THUMB2ARM_GLUE_SECTION_NAME
);
943 BFD_ASSERT (s
!= NULL
);
944 BFD_ASSERT (s
->contents
!= NULL
);
945 BFD_ASSERT (s
->output_section
!= NULL
);
947 if ((my_offset
& 0x01) == 0x01)
950 && sym_sec
->owner
!= NULL
951 && !INTERWORK_FLAG (sym_sec
->owner
))
953 (*_bfd_error_handler
)
954 (_("%s(%s): warning: interworking not enabled."),
955 bfd_archive_filename (sym_sec
->owner
), name
);
956 (*_bfd_error_handler
)
957 (_(" first occurrence: %s: thumb call to arm"),
958 bfd_archive_filename (input_bfd
));
964 myh
->root
.u
.def
.value
= my_offset
;
966 bfd_put_16 (output_bfd
, (bfd_vma
) t2a1_bx_pc_insn
,
967 s
->contents
+ my_offset
);
969 bfd_put_16 (output_bfd
, (bfd_vma
) t2a2_noop_insn
,
970 s
->contents
+ my_offset
+ 2);
973 /* Address of destination of the stub. */
974 ((bfd_signed_vma
) val
)
976 /* Offset from the start of the current section to the start of the stubs. */
978 /* Offset of the start of this stub from the start of the stubs. */
980 /* Address of the start of the current section. */
981 + s
->output_section
->vma
)
982 /* The branch instruction is 4 bytes into the stub. */
984 /* ARM branches work from the pc of the instruction + 8. */
987 bfd_put_32 (output_bfd
,
988 (bfd_vma
) t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
989 s
->contents
+ my_offset
+ 4);
992 BFD_ASSERT (my_offset
<= globals
->thumb_glue_size
);
994 /* Now go back and fix up the original BL insn to point
996 ret_offset
= (s
->output_offset
998 - (input_section
->output_offset
1002 tmp
= bfd_get_32 (input_bfd
, hit_data
1003 - input_section
->vma
);
1005 bfd_put_32 (output_bfd
,
1006 (bfd_vma
) insert_thumb_branch (tmp
, ret_offset
),
1007 hit_data
- input_section
->vma
);
1012 /* Arm code calling a Thumb function. */
1015 elf32_arm_to_thumb_stub (info
, name
, input_bfd
, output_bfd
, input_section
,
1016 hit_data
, sym_sec
, offset
, addend
, val
)
1017 struct bfd_link_info
* info
;
1021 asection
* input_section
;
1022 bfd_byte
* hit_data
;
1025 bfd_signed_vma addend
;
1028 unsigned long int tmp
;
1031 long int ret_offset
;
1032 struct elf_link_hash_entry
* myh
;
1033 struct elf32_arm_link_hash_table
* globals
;
1035 myh
= find_arm_glue (info
, name
, input_bfd
);
1039 globals
= elf32_arm_hash_table (info
);
1041 BFD_ASSERT (globals
!= NULL
);
1042 BFD_ASSERT (globals
->bfd_of_glue_owner
!= NULL
);
1044 my_offset
= myh
->root
.u
.def
.value
;
1045 s
= bfd_get_section_by_name (globals
->bfd_of_glue_owner
,
1046 ARM2THUMB_GLUE_SECTION_NAME
);
1047 BFD_ASSERT (s
!= NULL
);
1048 BFD_ASSERT (s
->contents
!= NULL
);
1049 BFD_ASSERT (s
->output_section
!= NULL
);
1051 if ((my_offset
& 0x01) == 0x01)
1054 && sym_sec
->owner
!= NULL
1055 && !INTERWORK_FLAG (sym_sec
->owner
))
1057 (*_bfd_error_handler
)
1058 (_("%s(%s): warning: interworking not enabled."),
1059 bfd_archive_filename (sym_sec
->owner
), name
);
1060 (*_bfd_error_handler
)
1061 (_(" first occurrence: %s: arm call to thumb"),
1062 bfd_archive_filename (input_bfd
));
1066 myh
->root
.u
.def
.value
= my_offset
;
1068 bfd_put_32 (output_bfd
, (bfd_vma
) a2t1_ldr_insn
,
1069 s
->contents
+ my_offset
);
1071 bfd_put_32 (output_bfd
, (bfd_vma
) a2t2_bx_r12_insn
,
1072 s
->contents
+ my_offset
+ 4);
1074 /* It's a thumb address. Add the low order bit. */
1075 bfd_put_32 (output_bfd
, val
| a2t3_func_addr_insn
,
1076 s
->contents
+ my_offset
+ 8);
1079 BFD_ASSERT (my_offset
<= globals
->arm_glue_size
);
1081 tmp
= bfd_get_32 (input_bfd
, hit_data
);
1082 tmp
= tmp
& 0xFF000000;
1084 /* Somehow these are both 4 too far, so subtract 8. */
1085 ret_offset
= (s
->output_offset
1087 + s
->output_section
->vma
1088 - (input_section
->output_offset
1089 + input_section
->output_section
->vma
1093 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1095 bfd_put_32 (output_bfd
, (bfd_vma
) tmp
, hit_data
- input_section
->vma
);
1100 /* Perform a relocation as part of a final link. */
1102 static bfd_reloc_status_type
1103 elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
1104 input_section
, contents
, rel
, value
,
1105 info
, sym_sec
, sym_name
, sym_flags
, h
)
1106 reloc_howto_type
* howto
;
1109 asection
* input_section
;
1110 bfd_byte
* contents
;
1111 Elf_Internal_Rela
* rel
;
1113 struct bfd_link_info
* info
;
1115 const char * sym_name
;
1117 struct elf_link_hash_entry
* h
;
1119 unsigned long r_type
= howto
->type
;
1120 unsigned long r_symndx
;
1121 bfd_byte
* hit_data
= contents
+ rel
->r_offset
;
1122 bfd
* dynobj
= NULL
;
1123 Elf_Internal_Shdr
* symtab_hdr
;
1124 struct elf_link_hash_entry
** sym_hashes
;
1125 bfd_vma
* local_got_offsets
;
1126 asection
* sgot
= NULL
;
1127 asection
* splt
= NULL
;
1128 asection
* splt_thumb
= NULL
;
1129 asection
* sreloc
= NULL
;
1131 bfd_signed_vma signed_addend
;
1132 struct elf32_arm_link_hash_table
* globals
;
1134 /* If the start address has been set, then set the EF_ARM_HASENTRY
1135 flag. Setting this more than once is redundant, but the cost is
1136 not too high, and it keeps the code simple.
1138 The test is done here, rather than somewhere else, because the
1139 start address is only set just before the final link commences.
1141 Note - if the user deliberately sets a start address of 0, the
1142 flag will not be set. */
1143 if (bfd_get_start_address (output_bfd
) != 0)
1144 elf_elfheader (output_bfd
)->e_flags
|= EF_ARM_HASENTRY
;
1146 globals
= elf32_arm_hash_table (info
);
1148 dynobj
= elf_hash_table (info
)->dynobj
;
1151 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1152 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1153 splt_thumb
= bfd_get_section_by_name (dynobj
, ".plt.thumb");
1155 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1156 sym_hashes
= elf_sym_hashes (input_bfd
);
1157 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1158 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1161 addend
= bfd_get_32 (input_bfd
, hit_data
) & howto
->src_mask
;
1163 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1166 signed_addend
&= ~ howto
->src_mask
;
1167 signed_addend
|= addend
;
1170 signed_addend
= addend
;
1172 addend
= signed_addend
= rel
->r_addend
;
1178 return bfd_reloc_ok
;
1186 /* When generating a shared object, these relocations are copied
1187 into the output file to be resolved at run time. */
1190 && (r_type
!= R_ARM_PC24
1193 && (! info
->symbolic
1194 || (h
->elf_link_hash_flags
1195 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
1197 Elf_Internal_Rel outrel
;
1198 boolean skip
, relocate
;
1204 name
= (bfd_elf_string_from_elf_section
1206 elf_elfheader (input_bfd
)->e_shstrndx
,
1207 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1209 return bfd_reloc_notsupported
;
1211 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
1212 && strcmp (bfd_get_section_name (input_bfd
,
1216 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1217 BFD_ASSERT (sreloc
!= NULL
);
1224 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1226 if (outrel
.r_offset
== (bfd_vma
) -1)
1228 else if (outrel
.r_offset
== (bfd_vma
) -2)
1229 skip
= true, relocate
= true;
1230 outrel
.r_offset
+= (input_section
->output_section
->vma
1231 + input_section
->output_offset
);
1234 memset (&outrel
, 0, sizeof outrel
);
1235 else if (r_type
== R_ARM_PC24
)
1237 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
1238 if ((input_section
->flags
& SEC_ALLOC
) == 0)
1240 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_PC24
);
1245 || ((info
->symbolic
|| h
->dynindx
== -1)
1246 && (h
->elf_link_hash_flags
1247 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
1250 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1254 BFD_ASSERT (h
->dynindx
!= -1);
1255 if ((input_section
->flags
& SEC_ALLOC
) == 0)
1257 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_ABS32
);
1261 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1262 (((Elf32_External_Rel
*)
1264 + sreloc
->reloc_count
));
1265 ++sreloc
->reloc_count
;
1267 /* If this reloc is against an external symbol, we do not want to
1268 fiddle with the addend. Otherwise, we need to include the symbol
1269 value so that it becomes an addend for the dynamic reloc. */
1271 return bfd_reloc_ok
;
1273 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1274 contents
, rel
->r_offset
, value
,
1277 else switch (r_type
)
1280 case R_ARM_XPC25
: /* Arm BLX instruction. */
1282 case R_ARM_PC24
: /* Arm B/BL instruction */
1284 if (r_type
== R_ARM_XPC25
)
1286 /* Check for Arm calling Arm function. */
1287 /* FIXME: Should we translate the instruction into a BL
1288 instruction instead ? */
1289 if (sym_flags
!= STT_ARM_TFUNC
)
1290 (*_bfd_error_handler
) (_("\
1291 %s: Warning: Arm BLX instruction targets Arm function '%s'."),
1292 bfd_archive_filename (input_bfd
),
1293 h
? h
->root
.root
.string
: "(local)");
1298 /* Check for Arm calling Thumb function. */
1299 if (sym_flags
== STT_ARM_TFUNC
)
1301 elf32_arm_to_thumb_stub (info
, sym_name
, input_bfd
, output_bfd
,
1302 input_section
, hit_data
, sym_sec
, rel
->r_offset
,
1303 signed_addend
, value
);
1304 return bfd_reloc_ok
;
1308 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1309 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0)
1311 /* The old way of doing things. Trearing the addend as a
1312 byte sized field and adding in the pipeline offset. */
1313 value
-= (input_section
->output_section
->vma
1314 + input_section
->output_offset
);
1315 value
-= rel
->r_offset
;
1318 if (! globals
->no_pipeline_knowledge
)
1323 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1325 S is the address of the symbol in the relocation.
1326 P is address of the instruction being relocated.
1327 A is the addend (extracted from the instruction) in bytes.
1329 S is held in 'value'.
1330 P is the base address of the section containing the instruction
1331 plus the offset of the reloc into that section, ie:
1332 (input_section->output_section->vma +
1333 input_section->output_offset +
1335 A is the addend, converted into bytes, ie:
1338 Note: None of these operations have knowledge of the pipeline
1339 size of the processor, thus it is up to the assembler to encode
1340 this information into the addend. */
1341 value
-= (input_section
->output_section
->vma
1342 + input_section
->output_offset
);
1343 value
-= rel
->r_offset
;
1344 value
+= (signed_addend
<< howto
->size
);
1346 /* Previous versions of this code also used to add in the pipeline
1347 offset here. This is wrong because the linker is not supposed
1348 to know about such things, and one day it might change. In order
1349 to support old binaries that need the old behaviour however, so
1350 we attempt to detect which ABI was used to create the reloc. */
1351 if (! globals
->no_pipeline_knowledge
)
1353 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form */
1355 i_ehdrp
= elf_elfheader (input_bfd
);
1357 if (i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1362 signed_addend
= value
;
1363 signed_addend
>>= howto
->rightshift
;
1365 /* It is not an error for an undefined weak reference to be
1366 out of range. Any program that branches to such a symbol
1367 is going to crash anyway, so there is no point worrying
1368 about getting the destination exactly right. */
1369 if (! h
|| h
->root
.type
!= bfd_link_hash_undefweak
)
1371 /* Perform a signed range check. */
1372 if ( signed_addend
> ((bfd_signed_vma
) (howto
->dst_mask
>> 1))
1373 || signed_addend
< - ((bfd_signed_vma
) ((howto
->dst_mask
+ 1) >> 1)))
1374 return bfd_reloc_overflow
;
1378 /* If necessary set the H bit in the BLX instruction. */
1379 if (r_type
== R_ARM_XPC25
&& ((value
& 2) == 2))
1380 value
= (signed_addend
& howto
->dst_mask
)
1381 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
))
1385 value
= (signed_addend
& howto
->dst_mask
)
1386 | (bfd_get_32 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1391 if (sym_flags
== STT_ARM_TFUNC
)
1396 value
-= (input_section
->output_section
->vma
1397 + input_section
->output_offset
+ rel
->r_offset
);
1402 bfd_put_32 (input_bfd
, value
, hit_data
);
1403 return bfd_reloc_ok
;
1407 if ((long) value
> 0x7f || (long) value
< -0x80)
1408 return bfd_reloc_overflow
;
1410 bfd_put_8 (input_bfd
, value
, hit_data
);
1411 return bfd_reloc_ok
;
1416 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1417 return bfd_reloc_overflow
;
1419 bfd_put_16 (input_bfd
, value
, hit_data
);
1420 return bfd_reloc_ok
;
1423 /* Support ldr and str instruction for the arm */
1424 /* Also thumb b (unconditional branch). ??? Really? */
1427 if ((long) value
> 0x7ff || (long) value
< -0x800)
1428 return bfd_reloc_overflow
;
1430 value
|= (bfd_get_32 (input_bfd
, hit_data
) & 0xfffff000);
1431 bfd_put_32 (input_bfd
, value
, hit_data
);
1432 return bfd_reloc_ok
;
1434 case R_ARM_THM_ABS5
:
1435 /* Support ldr and str instructions for the thumb. */
1437 /* Need to refetch addend. */
1438 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1439 /* ??? Need to determine shift amount from operand size. */
1440 addend
>>= howto
->rightshift
;
1444 /* ??? Isn't value unsigned? */
1445 if ((long) value
> 0x1f || (long) value
< -0x10)
1446 return bfd_reloc_overflow
;
1448 /* ??? Value needs to be properly shifted into place first. */
1449 value
|= bfd_get_16 (input_bfd
, hit_data
) & 0xf83f;
1450 bfd_put_16 (input_bfd
, value
, hit_data
);
1451 return bfd_reloc_ok
;
1454 case R_ARM_THM_XPC22
:
1456 case R_ARM_THM_PC22
:
1457 /* Thumb BL (branch long instruction). */
1460 boolean overflow
= false;
1461 bfd_vma upper_insn
= bfd_get_16 (input_bfd
, hit_data
);
1462 bfd_vma lower_insn
= bfd_get_16 (input_bfd
, hit_data
+ 2);
1463 bfd_signed_vma reloc_signed_max
= ((1 << (howto
->bitsize
- 1)) - 1) >> howto
->rightshift
;
1464 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1466 bfd_signed_vma signed_check
;
1469 /* Need to refetch the addend and squish the two 11 bit pieces
1472 bfd_vma upper
= upper_insn
& 0x7ff;
1473 bfd_vma lower
= lower_insn
& 0x7ff;
1474 upper
= (upper
^ 0x400) - 0x400; /* Sign extend. */
1475 addend
= (upper
<< 12) | (lower
<< 1);
1476 signed_addend
= addend
;
1480 /* If value is zero then we are linking a shared object and
1481 this is a reference to an externally visible symbol. */
1482 if (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1 && value
== 0)
1483 value
= (splt_thumb
->output_section
->vma
1484 + splt_thumb
->output_offset
1488 if (r_type
== R_ARM_THM_XPC22
)
1490 /* Check for Thumb to Thumb call. */
1491 /* FIXME: Should we translate the instruction into a BL
1492 instruction instead ? */
1493 if (sym_flags
== STT_ARM_TFUNC
)
1494 (*_bfd_error_handler
) (_("\
1495 %s: Warning: Thumb BLX instruction targets thumb function '%s'."),
1496 bfd_archive_filename (input_bfd
),
1497 h
? h
->root
.root
.string
: "(local)");
1502 /* If it is not a call to Thumb, assume call to Arm.
1503 If it is a call relative to a section name, then it is not a
1504 function call at all, but rather a long jump. */
1505 if (sym_flags
!= STT_ARM_TFUNC
&& sym_flags
!= STT_SECTION
)
1507 if (elf32_thumb_to_arm_stub
1508 (info
, sym_name
, input_bfd
, output_bfd
, input_section
,
1509 hit_data
, sym_sec
, rel
->r_offset
, signed_addend
, value
))
1510 return bfd_reloc_ok
;
1512 return bfd_reloc_dangerous
;
1516 relocation
= value
+ signed_addend
;
1518 relocation
-= (input_section
->output_section
->vma
1519 + input_section
->output_offset
1522 if (! globals
->no_pipeline_knowledge
)
1524 Elf_Internal_Ehdr
* i_ehdrp
; /* Elf file header, internal form. */
1526 i_ehdrp
= elf_elfheader (input_bfd
);
1528 /* Previous versions of this code also used to add in the pipline
1529 offset here. This is wrong because the linker is not supposed
1530 to know about such things, and one day it might change. In order
1531 to support old binaries that need the old behaviour however, so
1532 we attempt to detect which ABI was used to create the reloc. */
1533 if ( strcmp (bfd_get_target (input_bfd
), "elf32-littlearm-oabi") == 0
1534 || strcmp (bfd_get_target (input_bfd
), "elf32-bigarm-oabi") == 0
1535 || i_ehdrp
->e_ident
[EI_OSABI
] == 0)
1539 check
= relocation
>> howto
->rightshift
;
1541 /* If this is a signed value, the rightshift just dropped
1542 leading 1 bits (assuming twos complement). */
1543 if ((bfd_signed_vma
) relocation
>= 0)
1544 signed_check
= check
;
1546 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1548 /* Assumes two's complement. */
1549 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1553 if (r_type
== R_ARM_THM_XPC22
1554 && ((lower_insn
& 0x1800) == 0x0800))
1555 /* For a BLX instruction, make sure that the relocation is rounded up
1556 to a word boundary. This follows the semantics of the instruction
1557 which specifies that bit 1 of the target address will come from bit
1558 1 of the base address. */
1559 relocation
= (relocation
+ 2) & ~ 3;
1561 /* Put RELOCATION back into the insn. */
1562 upper_insn
= (upper_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 12) & 0x7ff);
1563 lower_insn
= (lower_insn
& ~(bfd_vma
) 0x7ff) | ((relocation
>> 1) & 0x7ff);
1565 /* Put the relocated value back in the object file: */
1566 bfd_put_16 (input_bfd
, upper_insn
, hit_data
);
1567 bfd_put_16 (input_bfd
, lower_insn
, hit_data
+ 2);
1569 return (overflow
? bfd_reloc_overflow
: bfd_reloc_ok
);
1573 case R_ARM_THM_PC11
:
1574 /* Thumb B (branch) instruction). */
1577 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1578 bfd_signed_vma reloc_signed_min
= ~ reloc_signed_max
;
1580 bfd_signed_vma signed_check
;
1583 /* Need to refetch addend. */
1584 addend
= bfd_get_16 (input_bfd
, hit_data
) & howto
->src_mask
;
1585 /* ??? Need to determine shift amount from operand size. */
1586 addend
>>= howto
->rightshift
;
1588 relocation
= value
+ addend
;
1590 relocation
-= (input_section
->output_section
->vma
1591 + input_section
->output_offset
1594 check
= relocation
>> howto
->rightshift
;
1596 /* If this is a signed value, the rightshift just
1597 dropped leading 1 bits (assuming twos complement). */
1598 if ((bfd_signed_vma
) relocation
>= 0)
1599 signed_check
= check
;
1601 signed_check
= check
| ~((bfd_vma
) -1 >> howto
->rightshift
);
1603 relocation
|= (bfd_get_16 (input_bfd
, hit_data
) & (~ howto
->dst_mask
));
1605 bfd_put_16 (input_bfd
, relocation
, hit_data
);
1607 /* Assumes two's complement. */
1608 if (signed_check
> reloc_signed_max
|| signed_check
< reloc_signed_min
)
1609 return bfd_reloc_overflow
;
1611 return bfd_reloc_ok
;
1614 case R_ARM_GNU_VTINHERIT
:
1615 case R_ARM_GNU_VTENTRY
:
1616 return bfd_reloc_ok
;
1619 return bfd_reloc_notsupported
;
1621 case R_ARM_GLOB_DAT
:
1622 return bfd_reloc_notsupported
;
1624 case R_ARM_JUMP_SLOT
:
1625 return bfd_reloc_notsupported
;
1627 case R_ARM_RELATIVE
:
1628 return bfd_reloc_notsupported
;
1631 /* Relocation is relative to the start of the
1632 global offset table. */
1634 BFD_ASSERT (sgot
!= NULL
);
1636 return bfd_reloc_notsupported
;
1638 /* If we are addressing a Thumb function, we need to adjust the
1639 address by one, so that attempts to call the function pointer will
1640 correctly interpret it as Thumb code. */
1641 if (sym_flags
== STT_ARM_TFUNC
)
1644 /* Note that sgot->output_offset is not involved in this
1645 calculation. We always want the start of .got. If we
1646 define _GLOBAL_OFFSET_TABLE in a different way, as is
1647 permitted by the ABI, we might have to change this
1649 value
-= sgot
->output_section
->vma
;
1650 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1651 contents
, rel
->r_offset
, value
,
1655 /* Use global offset table as symbol value. */
1656 BFD_ASSERT (sgot
!= NULL
);
1659 return bfd_reloc_notsupported
;
1661 value
= sgot
->output_section
->vma
;
1662 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1663 contents
, rel
->r_offset
, value
,
1667 /* Relocation is to the entry for this symbol in the
1668 global offset table. */
1670 return bfd_reloc_notsupported
;
1676 off
= h
->got
.offset
;
1677 BFD_ASSERT (off
!= (bfd_vma
) -1);
1679 if (!elf_hash_table (info
)->dynamic_sections_created
||
1680 (info
->shared
&& (info
->symbolic
|| h
->dynindx
== -1)
1681 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1683 /* This is actually a static link, or it is a -Bsymbolic link
1684 and the symbol is defined locally. We must initialize this
1685 entry in the global offset table. Since the offset must
1686 always be a multiple of 4, we use the least significant bit
1687 to record whether we have initialized it already.
1689 When doing a dynamic link, we create a .rel.got relocation
1690 entry to initialize the value. This is done in the
1691 finish_dynamic_symbol routine. */
1696 /* If we are addressing a Thumb function, we need to
1697 adjust the address by one, so that attempts to
1698 call the function pointer will correctly
1699 interpret it as Thumb code. */
1700 if (sym_flags
== STT_ARM_TFUNC
)
1703 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1708 value
= sgot
->output_offset
+ off
;
1714 BFD_ASSERT (local_got_offsets
!= NULL
&&
1715 local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1717 off
= local_got_offsets
[r_symndx
];
1719 /* The offset must always be a multiple of 4. We use the
1720 least significant bit to record whether we have already
1721 generated the necessary reloc. */
1726 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1731 Elf_Internal_Rel outrel
;
1733 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
1734 BFD_ASSERT (srelgot
!= NULL
);
1736 outrel
.r_offset
= (sgot
->output_section
->vma
1737 + sgot
->output_offset
1739 outrel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
1740 bfd_elf32_swap_reloc_out (output_bfd
, &outrel
,
1741 (((Elf32_External_Rel
*)
1743 + srelgot
->reloc_count
));
1744 ++srelgot
->reloc_count
;
1747 local_got_offsets
[r_symndx
] |= 1;
1750 value
= sgot
->output_offset
+ off
;
1753 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1754 contents
, rel
->r_offset
, value
,
1758 /* Relocation is to the entry for this symbol in the
1759 procedure linkage table. */
1761 /* Resolve a PLT32 reloc against a local symbol directly,
1762 without using the procedure linkage table. */
1764 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1765 contents
, rel
->r_offset
, value
,
1768 if (h
->plt
.offset
== (bfd_vma
) -1)
1769 /* We didn't make a PLT entry for this symbol. This
1770 happens when statically linking PIC code, or when
1771 using -Bsymbolic. */
1772 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1773 contents
, rel
->r_offset
, value
,
1776 BFD_ASSERT(splt
!= NULL
);
1778 return bfd_reloc_notsupported
;
1780 value
= (splt
->output_section
->vma
1781 + splt
->output_offset
1783 return _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1784 contents
, rel
->r_offset
, value
,
1788 return bfd_reloc_notsupported
;
1790 case R_ARM_AMP_VCALL9
:
1791 return bfd_reloc_notsupported
;
1793 case R_ARM_RSBREL32
:
1794 return bfd_reloc_notsupported
;
1796 case R_ARM_THM_RPC22
:
1797 return bfd_reloc_notsupported
;
1800 return bfd_reloc_notsupported
;
1803 return bfd_reloc_notsupported
;
1806 return bfd_reloc_notsupported
;
1809 return bfd_reloc_notsupported
;
1812 return bfd_reloc_notsupported
;
1817 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1819 arm_add_to_rel (abfd
, address
, howto
, increment
)
1822 reloc_howto_type
* howto
;
1823 bfd_signed_vma increment
;
1825 bfd_signed_vma addend
;
1827 if (howto
->type
== R_ARM_THM_PC22
)
1829 int upper_insn
, lower_insn
;
1832 upper_insn
= bfd_get_16 (abfd
, address
);
1833 lower_insn
= bfd_get_16 (abfd
, address
+ 2);
1834 upper
= upper_insn
& 0x7ff;
1835 lower
= lower_insn
& 0x7ff;
1837 addend
= (upper
<< 12) | (lower
<< 1);
1838 addend
+= increment
;
1841 upper_insn
= (upper_insn
& 0xf800) | ((addend
>> 11) & 0x7ff);
1842 lower_insn
= (lower_insn
& 0xf800) | (addend
& 0x7ff);
1844 bfd_put_16 (abfd
, (bfd_vma
) upper_insn
, address
);
1845 bfd_put_16 (abfd
, (bfd_vma
) lower_insn
, address
+ 2);
1851 contents
= bfd_get_32 (abfd
, address
);
1853 /* Get the (signed) value from the instruction. */
1854 addend
= contents
& howto
->src_mask
;
1855 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1857 bfd_signed_vma mask
;
1860 mask
&= ~ howto
->src_mask
;
1864 /* Add in the increment, (which is a byte value). */
1865 switch (howto
->type
)
1868 addend
+= increment
;
1872 addend
<<= howto
->size
;
1873 addend
+= increment
;
1875 /* Should we check for overflow here ? */
1877 /* Drop any undesired bits. */
1878 addend
>>= howto
->rightshift
;
1882 contents
= (contents
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1884 bfd_put_32 (abfd
, contents
, address
);
1887 #endif /* USE_REL */
1889 /* Relocate an ARM ELF section. */
1891 elf32_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1892 contents
, relocs
, local_syms
, local_sections
)
1894 struct bfd_link_info
* info
;
1896 asection
* input_section
;
1897 bfd_byte
* contents
;
1898 Elf_Internal_Rela
* relocs
;
1899 Elf_Internal_Sym
* local_syms
;
1900 asection
** local_sections
;
1902 Elf_Internal_Shdr
* symtab_hdr
;
1903 struct elf_link_hash_entry
** sym_hashes
;
1904 Elf_Internal_Rela
* rel
;
1905 Elf_Internal_Rela
* relend
;
1909 if (info
->relocateable
)
1913 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
1914 sym_hashes
= elf_sym_hashes (input_bfd
);
1917 relend
= relocs
+ input_section
->reloc_count
;
1918 for (; rel
< relend
; rel
++)
1921 reloc_howto_type
* howto
;
1922 unsigned long r_symndx
;
1923 Elf_Internal_Sym
* sym
;
1925 struct elf_link_hash_entry
* h
;
1927 bfd_reloc_status_type r
;
1930 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1931 r_type
= ELF32_R_TYPE (rel
->r_info
);
1933 if ( r_type
== R_ARM_GNU_VTENTRY
1934 || r_type
== R_ARM_GNU_VTINHERIT
)
1938 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
,
1939 (Elf_Internal_Rel
*) rel
);
1941 elf32_arm_info_to_howto (input_bfd
, & bfd_reloc
, rel
);
1943 howto
= bfd_reloc
.howto
;
1946 if (info
->relocateable
)
1948 /* This is a relocateable link. We don't have to change
1949 anything, unless the reloc is against a section symbol,
1950 in which case we have to adjust according to where the
1951 section symbol winds up in the output section. */
1952 if (r_symndx
< symtab_hdr
->sh_info
)
1954 sym
= local_syms
+ r_symndx
;
1955 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1957 sec
= local_sections
[r_symndx
];
1958 arm_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
1960 (bfd_signed_vma
) (sec
->output_offset
1969 /* This is a final link. */
1974 if (r_symndx
< symtab_hdr
->sh_info
)
1976 sym
= local_syms
+ r_symndx
;
1977 sec
= local_sections
[r_symndx
];
1979 relocation
= (sec
->output_section
->vma
1980 + sec
->output_offset
1982 if ((sec
->flags
& SEC_MERGE
)
1983 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1986 bfd_vma addend
, value
;
1988 if (howto
->rightshift
)
1990 (*_bfd_error_handler
)
1991 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
1992 bfd_archive_filename (input_bfd
),
1993 bfd_get_section_name (input_bfd
, input_section
),
1994 (long) rel
->r_offset
, howto
->name
);
1998 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2000 /* Get the (signed) value from the instruction. */
2001 addend
= value
& howto
->src_mask
;
2002 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2004 bfd_signed_vma mask
;
2007 mask
&= ~ howto
->src_mask
;
2012 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
2014 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2015 value
= (value
& ~ howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2016 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2019 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
2024 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2026 while ( h
->root
.type
== bfd_link_hash_indirect
2027 || h
->root
.type
== bfd_link_hash_warning
)
2028 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2030 if ( h
->root
.type
== bfd_link_hash_defined
2031 || h
->root
.type
== bfd_link_hash_defweak
)
2033 int relocation_needed
= 1;
2035 sec
= h
->root
.u
.def
.section
;
2037 /* In these cases, we don't need the relocation value.
2038 We check specially because in some obscure cases
2039 sec->output_section will be NULL. */
2044 case R_ARM_THM_PC22
:
2047 (!info
->symbolic
&& h
->dynindx
!= -1)
2048 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2050 && ((input_section
->flags
& SEC_ALLOC
) != 0
2051 /* DWARF will emit R_ARM_ABS32 relocations in its
2052 sections against symbols defined externally
2053 in shared libraries. We can't do anything
2055 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2056 && (h
->elf_link_hash_flags
2057 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
2059 relocation_needed
= 0;
2063 relocation_needed
= 0;
2067 if (elf_hash_table(info
)->dynamic_sections_created
2069 || (!info
->symbolic
&& h
->dynindx
!= -1)
2070 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2073 relocation_needed
= 0;
2077 if (h
->plt
.offset
!= (bfd_vma
)-1)
2078 relocation_needed
= 0;
2082 if (sec
->output_section
== NULL
)
2084 (*_bfd_error_handler
)
2085 (_("%s: warning: unresolvable relocation %d against symbol `%s' from %s section"),
2086 bfd_archive_filename (input_bfd
),
2088 h
->root
.root
.string
,
2089 bfd_get_section_name (input_bfd
, input_section
));
2090 relocation_needed
= 0;
2094 if (relocation_needed
)
2095 relocation
= h
->root
.u
.def
.value
2096 + sec
->output_section
->vma
2097 + sec
->output_offset
;
2101 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2103 else if (info
->shared
&& !info
->symbolic
2104 && !info
->no_undefined
2105 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2109 if (!((*info
->callbacks
->undefined_symbol
)
2110 (info
, h
->root
.root
.string
, input_bfd
,
2111 input_section
, rel
->r_offset
,
2112 (!info
->shared
|| info
->no_undefined
2113 || ELF_ST_VISIBILITY (h
->other
)))))
2120 name
= h
->root
.root
.string
;
2123 name
= (bfd_elf_string_from_elf_section
2124 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2125 if (name
== NULL
|| *name
== '\0')
2126 name
= bfd_section_name (input_bfd
, sec
);
2129 r
= elf32_arm_final_link_relocate (howto
, input_bfd
, output_bfd
,
2130 input_section
, contents
, rel
,
2131 relocation
, info
, sec
, name
,
2132 (h
? ELF_ST_TYPE (h
->type
) :
2133 ELF_ST_TYPE (sym
->st_info
)), h
);
2135 if (r
!= bfd_reloc_ok
)
2137 const char * msg
= (const char *) 0;
2141 case bfd_reloc_overflow
:
2142 /* If the overflowing reloc was to an undefined symbol,
2143 we have already printed one error message and there
2144 is no point complaining again. */
2146 h
->root
.type
!= bfd_link_hash_undefined
)
2147 && (!((*info
->callbacks
->reloc_overflow
)
2148 (info
, name
, howto
->name
, (bfd_vma
) 0,
2149 input_bfd
, input_section
, rel
->r_offset
))))
2153 case bfd_reloc_undefined
:
2154 if (!((*info
->callbacks
->undefined_symbol
)
2155 (info
, name
, input_bfd
, input_section
,
2156 rel
->r_offset
, true)))
2160 case bfd_reloc_outofrange
:
2161 msg
= _("internal error: out of range error");
2164 case bfd_reloc_notsupported
:
2165 msg
= _("internal error: unsupported relocation error");
2168 case bfd_reloc_dangerous
:
2169 msg
= _("internal error: dangerous error");
2173 msg
= _("internal error: unknown error");
2177 if (!((*info
->callbacks
->warning
)
2178 (info
, msg
, name
, input_bfd
, input_section
,
2189 /* Function to keep ARM specific flags in the ELF header. */
2191 elf32_arm_set_private_flags (abfd
, flags
)
2195 if (elf_flags_init (abfd
)
2196 && elf_elfheader (abfd
)->e_flags
!= flags
)
2198 if (EF_ARM_EABI_VERSION (flags
) == EF_ARM_EABI_UNKNOWN
)
2200 if (flags
& EF_ARM_INTERWORK
)
2201 (*_bfd_error_handler
) (_("\
2202 Warning: Not setting interworking flag of %s since it has already been specified as non-interworking"),
2203 bfd_archive_filename (abfd
));
2205 _bfd_error_handler (_("\
2206 Warning: Clearing the interworking flag of %s due to outside request"),
2207 bfd_archive_filename (abfd
));
2212 elf_elfheader (abfd
)->e_flags
= flags
;
2213 elf_flags_init (abfd
) = true;
2219 /* Copy backend specific data from one object module to another. */
2222 elf32_arm_copy_private_bfd_data (ibfd
, obfd
)
2229 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2230 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2233 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2234 out_flags
= elf_elfheader (obfd
)->e_flags
;
2236 if (elf_flags_init (obfd
)
2237 && EF_ARM_EABI_VERSION (out_flags
) == EF_ARM_EABI_UNKNOWN
2238 && in_flags
!= out_flags
)
2240 /* Cannot mix APCS26 and APCS32 code. */
2241 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2244 /* Cannot mix float APCS and non-float APCS code. */
2245 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2248 /* If the src and dest have different interworking flags
2249 then turn off the interworking bit. */
2250 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2252 if (out_flags
& EF_ARM_INTERWORK
)
2253 _bfd_error_handler (_("\
2254 Warning: Clearing the interworking flag of %s because non-interworking code in %s has been linked with it"),
2255 bfd_get_filename (obfd
),
2256 bfd_archive_filename (ibfd
));
2258 in_flags
&= ~EF_ARM_INTERWORK
;
2261 /* Likewise for PIC, though don't warn for this case. */
2262 if ((in_flags
& EF_ARM_PIC
) != (out_flags
& EF_ARM_PIC
))
2263 in_flags
&= ~EF_ARM_PIC
;
2266 elf_elfheader (obfd
)->e_flags
= in_flags
;
2267 elf_flags_init (obfd
) = true;
2272 /* Merge backend specific data from an object file to the output
2273 object file when linking. */
2276 elf32_arm_merge_private_bfd_data (ibfd
, obfd
)
2282 boolean flags_compatible
= true;
2283 boolean null_input_bfd
= true;
2286 /* Check if we have the same endianess. */
2287 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2290 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2291 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2294 /* The input BFD must have had its flags initialised. */
2295 /* The following seems bogus to me -- The flags are initialized in
2296 the assembler but I don't think an elf_flags_init field is
2297 written into the object. */
2298 /* BFD_ASSERT (elf_flags_init (ibfd)); */
2300 in_flags
= elf_elfheader (ibfd
)->e_flags
;
2301 out_flags
= elf_elfheader (obfd
)->e_flags
;
2303 if (!elf_flags_init (obfd
))
2305 /* If the input is the default architecture and had the default
2306 flags then do not bother setting the flags for the output
2307 architecture, instead allow future merges to do this. If no
2308 future merges ever set these flags then they will retain their
2309 uninitialised values, which surprise surprise, correspond
2310 to the default values. */
2311 if (bfd_get_arch_info (ibfd
)->the_default
2312 && elf_elfheader (ibfd
)->e_flags
== 0)
2315 elf_flags_init (obfd
) = true;
2316 elf_elfheader (obfd
)->e_flags
= in_flags
;
2318 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
2319 && bfd_get_arch_info (obfd
)->the_default
)
2320 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
2325 /* Identical flags must be compatible. */
2326 if (in_flags
== out_flags
)
2329 /* Check to see if the input BFD actually contains any sections.
2330 If not, its flags may not have been initialised either, but it cannot
2331 actually cause any incompatibility. */
2332 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2334 /* Ignore synthetic glue sections. */
2335 if (strcmp (sec
->name
, ".glue_7")
2336 && strcmp (sec
->name
, ".glue_7t"))
2338 null_input_bfd
= false;
2345 /* Complain about various flag mismatches. */
2346 if (EF_ARM_EABI_VERSION (in_flags
) != EF_ARM_EABI_VERSION (out_flags
))
2348 _bfd_error_handler (_("\
2349 ERROR: %s is compiled for EABI version %d, whereas %s is compiled for version %d"),
2350 bfd_archive_filename (ibfd
),
2351 (in_flags
& EF_ARM_EABIMASK
) >> 24,
2352 bfd_get_filename (obfd
),
2353 (out_flags
& EF_ARM_EABIMASK
) >> 24);
2357 /* Not sure what needs to be checked for EABI versions >= 1. */
2358 if (EF_ARM_EABI_VERSION (in_flags
) == EF_ARM_EABI_UNKNOWN
)
2360 if ((in_flags
& EF_ARM_APCS_26
) != (out_flags
& EF_ARM_APCS_26
))
2362 _bfd_error_handler (_("\
2363 ERROR: %s is compiled for APCS-%d, whereas target %s uses APCS-%d"),
2364 bfd_archive_filename (ibfd
),
2365 in_flags
& EF_ARM_APCS_26
? 26 : 32,
2366 bfd_get_filename (obfd
),
2367 out_flags
& EF_ARM_APCS_26
? 26 : 32);
2368 flags_compatible
= false;
2371 if ((in_flags
& EF_ARM_APCS_FLOAT
) != (out_flags
& EF_ARM_APCS_FLOAT
))
2373 if (in_flags
& EF_ARM_APCS_FLOAT
)
2374 _bfd_error_handler (_("\
2375 ERROR: %s passes floats in float registers, whereas %s passes them in integer registers"),
2376 bfd_archive_filename (ibfd
),
2377 bfd_get_filename (obfd
));
2379 _bfd_error_handler (_("\
2380 ERROR: %s passes floats in integer registers, whereas %s passes them in float registers"),
2381 bfd_archive_filename (ibfd
),
2382 bfd_get_filename (obfd
));
2384 flags_compatible
= false;
2387 if ((in_flags
& EF_ARM_VFP_FLOAT
) != (out_flags
& EF_ARM_VFP_FLOAT
))
2389 if (in_flags
& EF_ARM_VFP_FLOAT
)
2390 _bfd_error_handler (_("\
2391 ERROR: %s uses VFP instructions, whereas %s uses FPA instructions"),
2392 bfd_archive_filename (ibfd
),
2393 bfd_get_filename (obfd
));
2395 _bfd_error_handler (_("\
2396 ERROR: %s uses FPA instructions, whereas %s uses VFP instructions"),
2397 bfd_archive_filename (ibfd
),
2398 bfd_get_filename (obfd
));
2400 flags_compatible
= false;
2403 #ifdef EF_ARM_SOFT_FLOAT
2404 if ((in_flags
& EF_ARM_SOFT_FLOAT
) != (out_flags
& EF_ARM_SOFT_FLOAT
))
2406 /* We can allow interworking between code that is VFP format
2407 layout, and uses either soft float or integer regs for
2408 passing floating point arguments and results. We already
2409 know that the APCS_FLOAT flags match; similarly for VFP
2411 if ((in_flags
& EF_ARM_APCS_FLOAT
) != 0
2412 || (in_flags
& EF_ARM_VFP_FLOAT
) == 0)
2414 if (in_flags
& EF_ARM_SOFT_FLOAT
)
2415 _bfd_error_handler (_("\
2416 ERROR: %s uses software FP, whereas %s uses hardware FP"),
2417 bfd_archive_filename (ibfd
),
2418 bfd_get_filename (obfd
));
2420 _bfd_error_handler (_("\
2421 ERROR: %s uses hardware FP, whereas %s uses software FP"),
2422 bfd_archive_filename (ibfd
),
2423 bfd_get_filename (obfd
));
2425 flags_compatible
= false;
2430 /* Interworking mismatch is only a warning. */
2431 if ((in_flags
& EF_ARM_INTERWORK
) != (out_flags
& EF_ARM_INTERWORK
))
2433 if (in_flags
& EF_ARM_INTERWORK
)
2435 _bfd_error_handler (_("\
2436 Warning: %s supports interworking, whereas %s does not"),
2437 bfd_archive_filename (ibfd
),
2438 bfd_get_filename (obfd
));
2442 _bfd_error_handler (_("\
2443 Warning: %s does not support interworking, whereas %s does"),
2444 bfd_archive_filename (ibfd
),
2445 bfd_get_filename (obfd
));
2450 return flags_compatible
;
2453 /* Display the flags field. */
2456 elf32_arm_print_private_bfd_data (abfd
, ptr
)
2460 FILE * file
= (FILE *) ptr
;
2461 unsigned long flags
;
2463 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
2465 /* Print normal ELF private data. */
2466 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
2468 flags
= elf_elfheader (abfd
)->e_flags
;
2469 /* Ignore init flag - it may not be set, despite the flags field
2470 containing valid data. */
2472 /* xgettext:c-format */
2473 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
2475 switch (EF_ARM_EABI_VERSION (flags
))
2477 case EF_ARM_EABI_UNKNOWN
:
2478 /* The following flag bits are GNU extenstions and not part of the
2479 official ARM ELF extended ABI. Hence they are only decoded if
2480 the EABI version is not set. */
2481 if (flags
& EF_ARM_INTERWORK
)
2482 fprintf (file
, _(" [interworking enabled]"));
2484 if (flags
& EF_ARM_APCS_26
)
2485 fprintf (file
, " [APCS-26]");
2487 fprintf (file
, " [APCS-32]");
2489 if (flags
& EF_ARM_VFP_FLOAT
)
2490 fprintf (file
, _(" [VFP float format]"));
2492 fprintf (file
, _(" [FPA float format]"));
2494 if (flags
& EF_ARM_APCS_FLOAT
)
2495 fprintf (file
, _(" [floats passed in float registers]"));
2497 if (flags
& EF_ARM_PIC
)
2498 fprintf (file
, _(" [position independent]"));
2500 if (flags
& EF_ARM_NEW_ABI
)
2501 fprintf (file
, _(" [new ABI]"));
2503 if (flags
& EF_ARM_OLD_ABI
)
2504 fprintf (file
, _(" [old ABI]"));
2506 if (flags
& EF_ARM_SOFT_FLOAT
)
2507 fprintf (file
, _(" [software FP]"));
2509 flags
&= ~(EF_ARM_INTERWORK
| EF_ARM_APCS_26
| EF_ARM_APCS_FLOAT
2510 | EF_ARM_PIC
| EF_ARM_NEW_ABI
| EF_ARM_OLD_ABI
2511 | EF_ARM_SOFT_FLOAT
| EF_ARM_VFP_FLOAT
);
2514 case EF_ARM_EABI_VER1
:
2515 fprintf (file
, _(" [Version1 EABI]"));
2517 if (flags
& EF_ARM_SYMSARESORTED
)
2518 fprintf (file
, _(" [sorted symbol table]"));
2520 fprintf (file
, _(" [unsorted symbol table]"));
2522 flags
&= ~ EF_ARM_SYMSARESORTED
;
2525 case EF_ARM_EABI_VER2
:
2526 fprintf (file
, _(" [Version2 EABI]"));
2528 if (flags
& EF_ARM_SYMSARESORTED
)
2529 fprintf (file
, _(" [sorted symbol table]"));
2531 fprintf (file
, _(" [unsorted symbol table]"));
2533 if (flags
& EF_ARM_DYNSYMSUSESEGIDX
)
2534 fprintf (file
, _(" [dynamic symbols use segment index]"));
2536 if (flags
& EF_ARM_MAPSYMSFIRST
)
2537 fprintf (file
, _(" [mapping symbols precede others]"));
2539 flags
&= ~(EF_ARM_SYMSARESORTED
| EF_ARM_DYNSYMSUSESEGIDX
2540 | EF_ARM_MAPSYMSFIRST
);
2544 fprintf (file
, _(" <EABI version unrecognised>"));
2548 flags
&= ~ EF_ARM_EABIMASK
;
2550 if (flags
& EF_ARM_RELEXEC
)
2551 fprintf (file
, _(" [relocatable executable]"));
2553 if (flags
& EF_ARM_HASENTRY
)
2554 fprintf (file
, _(" [has entry point]"));
2556 flags
&= ~ (EF_ARM_RELEXEC
| EF_ARM_HASENTRY
);
2559 fprintf (file
, _("<Unrecognised flag bits set>"));
2567 elf32_arm_get_symbol_type (elf_sym
, type
)
2568 Elf_Internal_Sym
* elf_sym
;
2571 switch (ELF_ST_TYPE (elf_sym
->st_info
))
2574 return ELF_ST_TYPE (elf_sym
->st_info
);
2577 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
2578 This allows us to distinguish between data used by Thumb instructions
2579 and non-data (which is probably code) inside Thumb regions of an
2581 if (type
!= STT_OBJECT
)
2582 return ELF_ST_TYPE (elf_sym
->st_info
);
2593 elf32_arm_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2595 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2596 Elf_Internal_Rela
*rel
;
2597 struct elf_link_hash_entry
*h
;
2598 Elf_Internal_Sym
*sym
;
2602 switch (ELF32_R_TYPE (rel
->r_info
))
2604 case R_ARM_GNU_VTINHERIT
:
2605 case R_ARM_GNU_VTENTRY
:
2609 switch (h
->root
.type
)
2611 case bfd_link_hash_defined
:
2612 case bfd_link_hash_defweak
:
2613 return h
->root
.u
.def
.section
;
2615 case bfd_link_hash_common
:
2616 return h
->root
.u
.c
.p
->section
;
2624 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2629 /* Update the got entry reference counts for the section being removed. */
2632 elf32_arm_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2633 bfd
*abfd ATTRIBUTE_UNUSED
;
2634 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2635 asection
*sec ATTRIBUTE_UNUSED
;
2636 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2638 /* We don't support garbage collection of GOT and PLT relocs yet. */
2642 /* Look through the relocs for a section during the first phase. */
2645 elf32_arm_check_relocs (abfd
, info
, sec
, relocs
)
2647 struct bfd_link_info
* info
;
2649 const Elf_Internal_Rela
* relocs
;
2651 Elf_Internal_Shdr
* symtab_hdr
;
2652 struct elf_link_hash_entry
** sym_hashes
;
2653 struct elf_link_hash_entry
** sym_hashes_end
;
2654 const Elf_Internal_Rela
* rel
;
2655 const Elf_Internal_Rela
* rel_end
;
2657 asection
* sgot
, *srelgot
, *sreloc
;
2658 bfd_vma
* local_got_offsets
;
2660 if (info
->relocateable
)
2663 sgot
= srelgot
= sreloc
= NULL
;
2665 dynobj
= elf_hash_table (info
)->dynobj
;
2666 local_got_offsets
= elf_local_got_offsets (abfd
);
2668 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2669 sym_hashes
= elf_sym_hashes (abfd
);
2670 sym_hashes_end
= sym_hashes
2671 + symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
2673 if (!elf_bad_symtab (abfd
))
2674 sym_hashes_end
-= symtab_hdr
->sh_info
;
2676 rel_end
= relocs
+ sec
->reloc_count
;
2677 for (rel
= relocs
; rel
< rel_end
; rel
++)
2679 struct elf_link_hash_entry
*h
;
2680 unsigned long r_symndx
;
2682 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2683 if (r_symndx
< symtab_hdr
->sh_info
)
2686 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2688 /* Some relocs require a global offset table. */
2691 switch (ELF32_R_TYPE (rel
->r_info
))
2696 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2697 if (! _bfd_elf_create_got_section (dynobj
, info
))
2706 switch (ELF32_R_TYPE (rel
->r_info
))
2709 /* This symbol requires a global offset table entry. */
2712 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2713 BFD_ASSERT (sgot
!= NULL
);
2716 /* Get the got relocation section if necessary. */
2718 && (h
!= NULL
|| info
->shared
))
2720 srelgot
= bfd_get_section_by_name (dynobj
, ".rel.got");
2722 /* If no got relocation section, make one and initialize. */
2723 if (srelgot
== NULL
)
2725 srelgot
= bfd_make_section (dynobj
, ".rel.got");
2727 || ! bfd_set_section_flags (dynobj
, srelgot
,
2732 | SEC_LINKER_CREATED
2734 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2741 if (h
->got
.offset
!= (bfd_vma
) -1)
2742 /* We have already allocated space in the .got. */
2745 h
->got
.offset
= sgot
->_raw_size
;
2747 /* Make sure this symbol is output as a dynamic symbol. */
2748 if (h
->dynindx
== -1)
2749 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2752 srelgot
->_raw_size
+= sizeof (Elf32_External_Rel
);
2756 /* This is a global offset table entry for a local
2758 if (local_got_offsets
== NULL
)
2763 size
= symtab_hdr
->sh_info
;
2764 size
*= sizeof (bfd_vma
);
2765 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
2766 if (local_got_offsets
== NULL
)
2768 elf_local_got_offsets (abfd
) = local_got_offsets
;
2769 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
2770 local_got_offsets
[i
] = (bfd_vma
) -1;
2773 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
2774 /* We have already allocated space in the .got. */
2777 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
2780 /* If we are generating a shared object, we need to
2781 output a R_ARM_RELATIVE reloc so that the dynamic
2782 linker can adjust this GOT entry. */
2783 srelgot
->_raw_size
+= sizeof (Elf32_External_Rel
);
2786 sgot
->_raw_size
+= 4;
2790 /* This symbol requires a procedure linkage table entry. We
2791 actually build the entry in adjust_dynamic_symbol,
2792 because this might be a case of linking PIC code which is
2793 never referenced by a dynamic object, in which case we
2794 don't need to generate a procedure linkage table entry
2797 /* If this is a local symbol, we resolve it directly without
2798 creating a procedure linkage table entry. */
2802 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2804 struct elf32_arm_link_hash_entry
*eh
;
2806 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2807 if (eh
->plt_info
.first_rel_type
== R_ARM_NONE
)
2808 eh
->plt_info
.first_rel_type
= R_ARM_PLT32
;
2812 case R_ARM_THM_PC22
:
2813 /* Since there is no PLT32 for Thumb if we are creating a
2814 shared library and this is an externally visible symbol
2815 then add it to the PLT. */
2816 if (info
->shared
&& h
!= NULL
&& h
->dynindx
!= -1
2817 && (! info
->symbolic
2818 || (h
->elf_link_hash_flags
2819 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2821 struct elf32_arm_link_hash_entry
*eh
;
2823 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2824 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2825 if (eh
->plt_info
.first_rel_type
== R_ARM_NONE
)
2826 eh
->plt_info
.first_rel_type
= R_ARM_THM_PC22
;
2833 /* If we are creating a shared library, and this is a reloc
2834 against a global symbol, or a non PC relative reloc
2835 against a local symbol, then we need to copy the reloc
2836 into the shared library. However, if we are linking with
2837 -Bsymbolic, we do not need to copy a reloc against a
2838 global symbol which is defined in an object we are
2839 including in the link (i.e., DEF_REGULAR is set). At
2840 this point we have not seen all the input files, so it is
2841 possible that DEF_REGULAR is not set now but will be set
2842 later (it is never cleared). We account for that
2843 possibility below by storing information in the
2844 pcrel_relocs_copied field of the hash table entry. */
2846 && (ELF32_R_TYPE (rel
->r_info
) != R_ARM_PC24
2848 && (! info
->symbolic
2849 || (h
->elf_link_hash_flags
2850 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2852 /* When creating a shared object, we must copy these
2853 reloc types into the output file. We create a reloc
2854 section in dynobj and make room for this reloc. */
2859 name
= (bfd_elf_string_from_elf_section
2861 elf_elfheader (abfd
)->e_shstrndx
,
2862 elf_section_data (sec
)->rel_hdr
.sh_name
));
2866 BFD_ASSERT (strncmp (name
, ".rel", 4) == 0
2867 && strcmp (bfd_get_section_name (abfd
, sec
),
2870 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2875 sreloc
= bfd_make_section (dynobj
, name
);
2876 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2877 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2878 if ((sec
->flags
& SEC_ALLOC
) != 0)
2879 flags
|= SEC_ALLOC
| SEC_LOAD
;
2881 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2882 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2885 if (sec
->flags
& SEC_READONLY
)
2886 info
->flags
|= DF_TEXTREL
;
2889 sreloc
->_raw_size
+= sizeof (Elf32_External_Rel
);
2890 /* If we are linking with -Bsymbolic, and this is a
2891 global symbol, we count the number of PC relative
2892 relocations we have entered for this symbol, so that
2893 we can discard them again if the symbol is later
2894 defined by a regular object. Note that this function
2895 is only called if we are using an elf_i386 linker
2896 hash table, which means that h is really a pointer to
2897 an elf_i386_link_hash_entry. */
2898 if (h
!= NULL
&& info
->symbolic
2899 && ELF32_R_TYPE (rel
->r_info
) == R_ARM_PC24
)
2901 struct elf32_arm_link_hash_entry
* eh
;
2902 struct elf32_arm_pcrel_relocs_copied
* p
;
2904 eh
= (struct elf32_arm_link_hash_entry
*) h
;
2906 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
2907 if (p
->section
== sreloc
)
2912 p
= ((struct elf32_arm_pcrel_relocs_copied
*)
2913 bfd_alloc (dynobj
, (bfd_size_type
) sizeof * p
));
2916 p
->next
= eh
->pcrel_relocs_copied
;
2917 eh
->pcrel_relocs_copied
= p
;
2918 p
->section
= sreloc
;
2927 /* This relocation describes the C++ object vtable hierarchy.
2928 Reconstruct it for later use during GC. */
2929 case R_ARM_GNU_VTINHERIT
:
2930 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2934 /* This relocation describes which C++ vtable entries are actually
2935 used. Record for later use during GC. */
2936 case R_ARM_GNU_VTENTRY
:
2937 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2946 /* Find the nearest line to a particular section and offset, for error
2947 reporting. This code is a duplicate of the code in elf.c, except
2948 that it also accepts STT_ARM_TFUNC as a symbol that names a function. */
2951 elf32_arm_find_nearest_line
2952 (abfd
, section
, symbols
, offset
, filename_ptr
, functionname_ptr
, line_ptr
)
2957 const char ** filename_ptr
;
2958 const char ** functionname_ptr
;
2959 unsigned int * line_ptr
;
2962 const char * filename
;
2967 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
2968 filename_ptr
, functionname_ptr
,
2970 &elf_tdata (abfd
)->dwarf2_find_line_info
))
2973 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
2974 &found
, filename_ptr
,
2975 functionname_ptr
, line_ptr
,
2976 &elf_tdata (abfd
)->line_info
))
2982 if (symbols
== NULL
)
2989 for (p
= symbols
; *p
!= NULL
; p
++)
2993 q
= (elf_symbol_type
*) *p
;
2995 if (bfd_get_section (&q
->symbol
) != section
)
2998 switch (ELF_ST_TYPE (q
->internal_elf_sym
.st_info
))
3003 filename
= bfd_asymbol_name (&q
->symbol
);
3008 if (q
->symbol
.section
== section
3009 && q
->symbol
.value
>= low_func
3010 && q
->symbol
.value
<= offset
)
3012 func
= (asymbol
*) q
;
3013 low_func
= q
->symbol
.value
;
3022 *filename_ptr
= filename
;
3023 *functionname_ptr
= bfd_asymbol_name (func
);
3029 /* Adjust a symbol defined by a dynamic object and referenced by a
3030 regular object. The current definition is in some section of the
3031 dynamic object, but we're not including those sections. We have to
3032 change the definition to something the rest of the link can
3036 elf32_arm_adjust_dynamic_symbol (info
, h
)
3037 struct bfd_link_info
* info
;
3038 struct elf_link_hash_entry
* h
;
3042 unsigned int power_of_two
;
3044 dynobj
= elf_hash_table (info
)->dynobj
;
3046 /* Make sure we know what is going on here. */
3047 BFD_ASSERT (dynobj
!= NULL
3048 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3049 || h
->weakdef
!= NULL
3050 || ((h
->elf_link_hash_flags
3051 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3052 && (h
->elf_link_hash_flags
3053 & ELF_LINK_HASH_REF_REGULAR
) != 0
3054 && (h
->elf_link_hash_flags
3055 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3057 /* If this is a function, put it in the procedure linkage table. We
3058 will fill in the contents of the procedure linkage table later,
3059 when we know the address of the .got section. */
3060 if (h
->type
== STT_FUNC
|| h
->type
== STT_ARM_TFUNC
3061 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3063 struct elf32_arm_plt_entry_info
*plt_info
;
3065 plt_info
= &((struct elf32_arm_link_hash_entry
*) h
)->plt_info
;
3066 plt_info
->arm_plt
= ! (h
->type
== STT_ARM_TFUNC
||
3067 (h
->type
!= STT_ARM_TFUNC
&& h
->type
!= STT_FUNC
3068 && plt_info
->first_rel_type
== R_ARM_THM_PC22
));
3071 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3072 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
3074 /* This case can occur if we saw a PLT32 reloc in an input
3075 file, but the symbol was never referred to by a dynamic
3076 object. In such a case, we don't actually need to build
3077 a procedure linkage table, and we can just do a PC32
3079 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
3083 /* Make sure this symbol is output as a dynamic symbol. */
3084 if (h
->dynindx
== -1)
3086 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3090 s
= bfd_get_section_by_name (dynobj
,
3091 plt_info
->arm_plt
? ".plt" : ".plt.thumb");
3092 BFD_ASSERT (s
!= NULL
);
3094 /* If this is the first PLT entry, make room for the special
3096 if (s
->_raw_size
== 0)
3097 s
->_raw_size
+= PLT_ENTRY_SIZE (plt_info
->arm_plt
);
3099 /* If this symbol is not defined in a regular file, and we are
3100 not generating a shared library, then set the symbol to this
3101 location in the .plt. This is required to make function
3102 pointers compare as equal between the normal executable and
3103 the shared library. */
3105 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3107 h
->root
.u
.def
.section
= s
;
3108 h
->root
.u
.def
.value
= s
->_raw_size
;
3111 h
->plt
.offset
= s
->_raw_size
;
3113 /* Make room for this entry. */
3114 s
->_raw_size
+= PLT_ENTRY_SIZE (plt_info
->arm_plt
);
3116 /* We also need to make an entry in the .got.plt section, which
3117 will be placed in the .got section by the linker script. */
3118 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3119 BFD_ASSERT (s
!= NULL
);
3120 plt_info
->got_plt_offset
= s
->_raw_size
;
3123 /* We also need to make an entry in the .rel.plt section. */
3125 s
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3126 BFD_ASSERT (s
!= NULL
);
3127 s
->_raw_size
+= sizeof (Elf32_External_Rel
);
3132 /* If this is a weak symbol, and there is a real definition, the
3133 processor independent code will have arranged for us to see the
3134 real definition first, and we can just use the same value. */
3135 if (h
->weakdef
!= NULL
)
3137 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3138 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3139 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3140 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3144 /* This is a reference to a symbol defined by a dynamic object which
3145 is not a function. */
3147 /* If we are creating a shared library, we must presume that the
3148 only references to the symbol are via the global offset table.
3149 For such cases we need not do anything here; the relocations will
3150 be handled correctly by relocate_section. */
3154 /* We must allocate the symbol in our .dynbss section, which will
3155 become part of the .bss section of the executable. There will be
3156 an entry for this symbol in the .dynsym section. The dynamic
3157 object will contain position independent code, so all references
3158 from the dynamic object to this symbol will go through the global
3159 offset table. The dynamic linker will use the .dynsym entry to
3160 determine the address it must put in the global offset table, so
3161 both the dynamic object and the regular object will refer to the
3162 same memory location for the variable. */
3163 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3164 BFD_ASSERT (s
!= NULL
);
3166 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
3167 copy the initial value out of the dynamic object and into the
3168 runtime process image. We need to remember the offset into the
3169 .rel.bss section we are going to use. */
3170 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3174 srel
= bfd_get_section_by_name (dynobj
, ".rel.bss");
3175 BFD_ASSERT (srel
!= NULL
);
3176 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
3177 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3180 /* We need to figure out the alignment required for this symbol. I
3181 have no idea how ELF linkers handle this. */
3182 power_of_two
= bfd_log2 (h
->size
);
3183 if (power_of_two
> 3)
3186 /* Apply the required alignment. */
3187 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3188 (bfd_size_type
) (1 << power_of_two
));
3189 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3191 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3195 /* Define the symbol as being at this point in the section. */
3196 h
->root
.u
.def
.section
= s
;
3197 h
->root
.u
.def
.value
= s
->_raw_size
;
3199 /* Increment the section size to make room for the symbol. */
3200 s
->_raw_size
+= h
->size
;
3205 /* Set the sizes of the dynamic sections. */
3208 elf32_arm_size_dynamic_sections (output_bfd
, info
)
3209 bfd
* output_bfd ATTRIBUTE_UNUSED
;
3210 struct bfd_link_info
* info
;
3217 dynobj
= elf_hash_table (info
)->dynobj
;
3218 BFD_ASSERT (dynobj
!= NULL
);
3220 if (elf_hash_table (info
)->dynamic_sections_created
)
3222 /* Set the contents of the .interp section to the interpreter. */
3225 s
= bfd_get_section_by_name (dynobj
, ".interp");
3226 BFD_ASSERT (s
!= NULL
);
3227 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3228 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3233 /* We may have created entries in the .rel.got section.
3234 However, if we are not creating the dynamic sections, we will
3235 not actually use these entries. Reset the size of .rel.got,
3236 which will cause it to get stripped from the output file
3238 s
= bfd_get_section_by_name (dynobj
, ".rel.got");
3243 /* If this is a -Bsymbolic shared link, then we need to discard all
3244 PC relative relocs against symbols defined in a regular object.
3245 We allocated space for them in the check_relocs routine, but we
3246 will not fill them in in the relocate_section routine. */
3247 if (info
->shared
&& info
->symbolic
)
3248 elf32_arm_link_hash_traverse (elf32_arm_hash_table (info
),
3249 elf32_arm_discard_copies
,
3252 /* The check_relocs and adjust_dynamic_symbol entry points have
3253 determined the sizes of the various dynamic sections. Allocate
3257 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3262 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3265 /* It's OK to base decisions on the section name, because none
3266 of the dynobj section names depend upon the input files. */
3267 name
= bfd_get_section_name (dynobj
, s
);
3271 /* Match .plt.thumb as well. */
3272 if (strncmp (name
, ".plt", 4) == 0)
3274 if (s
->_raw_size
== 0)
3276 /* Strip this section if we don't need it; see the
3282 /* Remember whether there is a PLT. */
3286 else if (strncmp (name
, ".rel", 4) == 0)
3288 if (s
->_raw_size
== 0)
3290 /* If we don't need this section, strip it from the
3291 output file. This is mostly to handle .rel.bss and
3292 .rel.plt. We must create both sections in
3293 create_dynamic_sections, because they must be created
3294 before the linker maps input sections to output
3295 sections. The linker does that before
3296 adjust_dynamic_symbol is called, and it is that
3297 function which decides whether anything needs to go
3298 into these sections. */
3303 /* Remember whether there are any reloc sections other
3305 if (strcmp (name
, ".rel.plt") != 0)
3308 /* We use the reloc_count field as a counter if we need
3309 to copy relocs into the output file. */
3313 else if (strncmp (name
, ".got", 4) != 0)
3315 /* It's not one of our sections, so don't allocate space. */
3323 for (spp
= &s
->output_section
->owner
->sections
;
3325 spp
= &(*spp
)->next
)
3327 if (*spp
== s
->output_section
)
3329 bfd_section_list_remove (s
->output_section
->owner
, spp
);
3330 --s
->output_section
->owner
->section_count
;
3337 /* Allocate memory for the section contents. */
3338 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3339 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3343 if (elf_hash_table (info
)->dynamic_sections_created
)
3345 /* Add some entries to the .dynamic section. We fill in the
3346 values later, in elf32_arm_finish_dynamic_sections, but we
3347 must add the entries now so that we get the correct size for
3348 the .dynamic section. The DT_DEBUG entry is filled in by the
3349 dynamic linker and used by the debugger. */
3350 #define add_dynamic_entry(TAG, VAL) \
3351 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3355 if (!add_dynamic_entry (DT_DEBUG
, 0))
3361 if ( !add_dynamic_entry (DT_PLTGOT
, 0)
3362 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3363 || !add_dynamic_entry (DT_PLTREL
, DT_REL
)
3364 || !add_dynamic_entry (DT_JMPREL
, 0))
3370 if ( !add_dynamic_entry (DT_REL
, 0)
3371 || !add_dynamic_entry (DT_RELSZ
, 0)
3372 || !add_dynamic_entry (DT_RELENT
, sizeof (Elf32_External_Rel
)))
3376 if ((info
->flags
& DF_TEXTREL
) != 0)
3378 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3380 info
->flags
|= DF_TEXTREL
;
3383 #undef add_synamic_entry
3388 /* This function is called via elf32_arm_link_hash_traverse if we are
3389 creating a shared object with -Bsymbolic. It discards the space
3390 allocated to copy PC relative relocs against symbols which are
3391 defined in regular objects. We allocated space for them in the
3392 check_relocs routine, but we won't fill them in in the
3393 relocate_section routine. */
3396 elf32_arm_discard_copies (h
, ignore
)
3397 struct elf32_arm_link_hash_entry
* h
;
3398 PTR ignore ATTRIBUTE_UNUSED
;
3400 struct elf32_arm_pcrel_relocs_copied
* s
;
3402 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3403 h
= (struct elf32_arm_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3405 /* We only discard relocs for symbols defined in a regular object. */
3406 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3409 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
3410 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rel
);
3415 /* Finish up dynamic symbol handling. We set the contents of various
3416 dynamic sections here. */
3419 elf32_arm_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3421 struct bfd_link_info
* info
;
3422 struct elf_link_hash_entry
* h
;
3423 Elf_Internal_Sym
* sym
;
3427 dynobj
= elf_hash_table (info
)->dynobj
;
3429 if (h
->plt
.offset
!= (bfd_vma
) -1)
3432 asection
* splt_thumb
;
3436 Elf_Internal_Rel rel
;
3437 struct elf32_arm_plt_entry_info
*plt_info
;
3439 /* This symbol has an entry in the procedure linkage table. Set
3442 BFD_ASSERT (h
->dynindx
!= -1);
3444 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3445 splt_thumb
= bfd_get_section_by_name (dynobj
, ".plt.thumb");
3446 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3447 srel
= bfd_get_section_by_name (dynobj
, ".rel.plt");
3448 BFD_ASSERT (splt
!= NULL
&& splt_thumb
!= NULL
&& sgot
!= NULL
3451 plt_info
= &((struct elf32_arm_link_hash_entry
*) h
)->plt_info
;
3453 /* Get the index in the relocation table that corresponds to the
3454 entry in the global offset table. */
3455 rel_index
= plt_info
->got_plt_offset
/ 4 - 3;
3457 /* Fill in the entry in the procedure linkage table. */
3459 if (plt_info
->arm_plt
)
3461 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[0],
3462 splt
->contents
+ h
->plt
.offset
+ 0);
3463 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[1],
3464 splt
->contents
+ h
->plt
.offset
+ 4);
3465 bfd_put_32 (output_bfd
, elf32_arm_plt_entry
[2],
3466 splt
->contents
+ h
->plt
.offset
+ 8);
3468 bfd_put_32 (output_bfd
,
3469 (sgot
->output_section
->vma
3470 + sgot
->output_offset
3471 + plt_info
->got_plt_offset
3472 - splt
->output_section
->vma
3473 - splt
->output_offset
3474 - h
->plt
.offset
- 12),
3475 splt
->contents
+ h
->plt
.offset
+ 12);
3477 /* Fill in the entry in the global offset table. */
3478 bfd_put_32 (output_bfd
,
3479 (splt
->output_section
->vma
3480 + splt
->output_offset
),
3481 sgot
->contents
+ plt_info
->got_plt_offset
);
3485 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[0],
3486 splt_thumb
->contents
+ h
->plt
.offset
+ 0);
3487 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[1],
3488 splt_thumb
->contents
+ h
->plt
.offset
+ 2);
3489 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[2],
3490 splt_thumb
->contents
+ h
->plt
.offset
+ 4);
3491 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[3],
3492 splt_thumb
->contents
+ h
->plt
.offset
+ 6);
3493 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[4],
3494 splt_thumb
->contents
+ h
->plt
.offset
+ 8);
3495 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[5],
3496 splt_thumb
->contents
+ h
->plt
.offset
+ 10);
3497 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[6],
3498 splt_thumb
->contents
+ h
->plt
.offset
+ 12);
3499 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt_entry
[7],
3500 splt_thumb
->contents
+ h
->plt
.offset
+ 14);
3502 bfd_put_32 (output_bfd
,
3503 (sgot
->output_section
->vma
3504 + sgot
->output_offset
3505 + plt_info
->got_plt_offset
3506 - splt_thumb
->output_section
->vma
3507 - splt_thumb
->output_offset
3508 - h
->plt
.offset
- 10),
3509 splt_thumb
->contents
+ h
->plt
.offset
+ 16);
3511 /* Fill in the entry in the global offset table and set
3512 bottom bit as plt[0] is a Thumb function. */
3513 bfd_put_32 (output_bfd
,
3514 (splt_thumb
->output_section
->vma
3515 + (splt_thumb
->output_offset
| 1)),
3516 sgot
->contents
+ plt_info
->got_plt_offset
);
3519 /* Fill in the entry in the .rel.plt section. */
3520 rel
.r_offset
= (sgot
->output_section
->vma
3521 + sgot
->output_offset
3522 + plt_info
->got_plt_offset
);
3523 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_JUMP_SLOT
);
3524 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3525 ((Elf32_External_Rel
*) srel
->contents
3528 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3530 /* Mark the symbol as undefined, rather than as defined in
3531 the .plt section. Leave the value alone. */
3532 sym
->st_shndx
= SHN_UNDEF
;
3533 /* If the symbol is weak, we do need to clear the value.
3534 Otherwise, the PLT entry would provide a definition for
3535 the symbol even if the symbol wasn't defined anywhere,
3536 and so the symbol would never be NULL. */
3537 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
3543 if (h
->got
.offset
!= (bfd_vma
) -1)
3547 Elf_Internal_Rel rel
;
3549 /* This symbol has an entry in the global offset table. Set it
3551 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3552 srel
= bfd_get_section_by_name (dynobj
, ".rel.got");
3553 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
3555 rel
.r_offset
= (sgot
->output_section
->vma
3556 + sgot
->output_offset
3557 + (h
->got
.offset
&~ (bfd_vma
) 1));
3559 /* If this is a -Bsymbolic link, and the symbol is defined
3560 locally, we just want to emit a RELATIVE reloc. The entry in
3561 the global offset table will already have been initialized in
3562 the relocate_section function. */
3564 && (info
->symbolic
|| h
->dynindx
== -1)
3565 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3566 rel
.r_info
= ELF32_R_INFO (0, R_ARM_RELATIVE
);
3569 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3570 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_GLOB_DAT
);
3573 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3574 ((Elf32_External_Rel
*) srel
->contents
3575 + srel
->reloc_count
));
3576 ++srel
->reloc_count
;
3579 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3582 Elf_Internal_Rel rel
;
3584 /* This symbol needs a copy reloc. Set it up. */
3585 BFD_ASSERT (h
->dynindx
!= -1
3586 && (h
->root
.type
== bfd_link_hash_defined
3587 || h
->root
.type
== bfd_link_hash_defweak
));
3589 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3591 BFD_ASSERT (s
!= NULL
);
3593 rel
.r_offset
= (h
->root
.u
.def
.value
3594 + h
->root
.u
.def
.section
->output_section
->vma
3595 + h
->root
.u
.def
.section
->output_offset
);
3596 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARM_COPY
);
3597 bfd_elf32_swap_reloc_out (output_bfd
, &rel
,
3598 ((Elf32_External_Rel
*) s
->contents
3603 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3604 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3605 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3606 sym
->st_shndx
= SHN_ABS
;
3611 /* Finish up the dynamic sections. */
3614 elf32_arm_finish_dynamic_sections (output_bfd
, info
)
3616 struct bfd_link_info
* info
;
3622 dynobj
= elf_hash_table (info
)->dynobj
;
3624 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
3625 BFD_ASSERT (sgot
!= NULL
);
3626 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3628 if (elf_hash_table (info
)->dynamic_sections_created
)
3631 asection
*splt_thumb
;
3632 Elf32_External_Dyn
*dyncon
, *dynconend
;
3634 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3635 splt_thumb
= bfd_get_section_by_name (dynobj
, ".plt.thumb");
3636 BFD_ASSERT (splt
!= NULL
&& splt_thumb
!= NULL
&& sdyn
!= NULL
);
3638 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3639 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3641 for (; dyncon
< dynconend
; dyncon
++)
3643 Elf_Internal_Dyn dyn
;
3647 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3660 s
= bfd_get_section_by_name (output_bfd
, name
);
3661 BFD_ASSERT (s
!= NULL
);
3662 dyn
.d_un
.d_ptr
= s
->vma
;
3663 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3667 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3668 BFD_ASSERT (s
!= NULL
);
3669 if (s
->_cooked_size
!= 0)
3670 dyn
.d_un
.d_val
= s
->_cooked_size
;
3672 dyn
.d_un
.d_val
= s
->_raw_size
;
3673 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3677 /* My reading of the SVR4 ABI indicates that the
3678 procedure linkage table relocs (DT_JMPREL) should be
3679 included in the overall relocs (DT_REL). This is
3680 what Solaris does. However, UnixWare can not handle
3681 that case. Therefore, we override the DT_RELSZ entry
3682 here to make it not include the JMPREL relocs. Since
3683 the linker script arranges for .rel.plt to follow all
3684 other relocation sections, we don't have to worry
3685 about changing the DT_REL entry. */
3686 s
= bfd_get_section_by_name (output_bfd
, ".rel.plt");
3689 if (s
->_cooked_size
!= 0)
3690 dyn
.d_un
.d_val
-= s
->_cooked_size
;
3692 dyn
.d_un
.d_val
-= s
->_raw_size
;
3694 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3699 /* Fill in the first entries in the procedure linkage tables. */
3700 if (splt
->_raw_size
> 0)
3702 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[0], splt
->contents
+ 0);
3703 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[1], splt
->contents
+ 4);
3704 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[2], splt
->contents
+ 8);
3705 bfd_put_32 (output_bfd
, elf32_arm_plt0_entry
[3], splt
->contents
+ 12);
3707 if (splt_thumb
->_raw_size
> 0)
3709 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[0],
3710 splt_thumb
->contents
+ 0);
3711 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[1],
3712 splt_thumb
->contents
+ 2);
3713 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[2],
3714 splt_thumb
->contents
+ 4);
3715 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[3],
3716 splt_thumb
->contents
+ 6);
3717 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[4],
3718 splt_thumb
->contents
+ 8);
3719 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[5],
3720 splt_thumb
->contents
+ 10);
3721 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[6],
3722 splt_thumb
->contents
+ 12);
3723 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[7],
3724 splt_thumb
->contents
+ 14);
3725 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[8],
3726 splt_thumb
->contents
+ 16);
3727 bfd_put_16 (output_bfd
, (bfd_vma
) elf32_thumb_plt0_entry
[9],
3728 splt_thumb
->contents
+ 18);
3731 /* UnixWare sets the entsize of .plt to 4, although that doesn't
3732 really seem like the right value. */
3733 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
3736 /* Fill in the first three entries in the global offset table. */
3737 if (sgot
->_raw_size
> 0)
3740 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
3742 bfd_put_32 (output_bfd
,
3743 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3745 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
3746 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
3749 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3755 elf32_arm_post_process_headers (abfd
, link_info
)
3757 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
3759 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
3761 i_ehdrp
= elf_elfheader (abfd
);
3763 i_ehdrp
->e_ident
[EI_OSABI
] = ARM_ELF_OS_ABI_VERSION
;
3764 i_ehdrp
->e_ident
[EI_ABIVERSION
] = ARM_ELF_ABI_VERSION
;
3767 static enum elf_reloc_type_class
3768 elf32_arm_reloc_type_class (rela
)
3769 const Elf_Internal_Rela
*rela
;
3771 switch ((int) ELF32_R_TYPE (rela
->r_info
))
3773 case R_ARM_RELATIVE
:
3774 return reloc_class_relative
;
3775 case R_ARM_JUMP_SLOT
:
3776 return reloc_class_plt
;
3778 return reloc_class_copy
;
3780 return reloc_class_normal
;
3785 elf32_arm_create_dynamic_sections (abfd
, info
)
3787 struct bfd_link_info
*info
;
3791 ret
= _bfd_elf_create_dynamic_sections (abfd
, info
);
3795 asection
*splt_thumb
;
3797 unsigned int alignent_power
;
3799 /* Let's match the attributes of .plt. */
3800 splt
= bfd_get_section_by_name (abfd
, ".plt");
3801 BFD_ASSERT (splt
!= NULL
);
3803 flags
= bfd_get_section_flags (abfd
, splt
);
3804 alignent_power
= bfd_get_section_alignment (abfd
, splt
);
3806 splt_thumb
= bfd_make_section (abfd
, ".plt.thumb");
3807 if (splt_thumb
== NULL
3808 || !bfd_set_section_flags (abfd
, splt_thumb
, flags
)
3809 || !bfd_set_section_alignment (abfd
, splt_thumb
, alignent_power
))
3815 #define ELF_ARCH bfd_arch_arm
3816 #define ELF_MACHINE_CODE EM_ARM
3817 #ifndef ELF_MAXPAGESIZE
3818 #define ELF_MAXPAGESIZE 0x8000
3821 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
3822 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
3823 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
3824 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
3825 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
3826 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
3827 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
3829 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
3830 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
3831 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
3832 #define elf_backend_check_relocs elf32_arm_check_relocs
3833 #define elf_backend_relocate_section elf32_arm_relocate_section
3834 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
3835 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
3836 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
3837 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
3838 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
3839 #define elf_backend_post_process_headers elf32_arm_post_process_headers
3840 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
3842 #define elf_backend_can_gc_sections 1
3843 #define elf_backend_plt_readonly 1
3844 #define elf_backend_want_got_plt 1
3845 #define elf_backend_want_plt_sym 0
3847 #define elf_backend_rela_normal 1
3850 #define elf_backend_got_header_size 12
3851 #define elf_backend_plt_header_size ARM_PLT_ENTRY_SIZE
3853 #include "elf32-target.h"