Add support for Thumb PLT entries with interworking
[deliverable/binutils-gdb.git] / bfd / elf32-arm.h
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
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.
10
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.
15
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. */
19
20 typedef unsigned long int insn32;
21 typedef unsigned short int insn16;
22
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
34 PARAMS ((bfd *));
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 *,
74 Elf_Internal_Sym *));
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 *));
79 #ifdef USE_REL
80 static void arm_add_to_rel
81 PARAMS ((bfd *, bfd_byte *, reloc_howto_type *, bfd_signed_vma));
82 #endif
83 static enum elf_reloc_type_class elf32_arm_reloc_type_class
84 PARAMS ((const Elf_Internal_Rela *));
85
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));
97 #endif
98 static boolean elf32_arm_create_dynamic_sections
99 PARAMS ((bfd *, struct bfd_link_info *));
100
101
102 #define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
103
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"
110
111 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
112 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
113
114 /* The name of the dynamic interpreter. This is put in the .interp
115 section. */
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
117
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)
123
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
127 linker first. */
128 static const bfd_vma elf32_arm_plt0_entry [ARM_PLT_ENTRY_SIZE / 4] =
129 {
130 0xe52de004, /* str lr, [sp, #-4]! */
131 0xe59fe010, /* ldr lr, [pc, #16] */
132 0xe08fe00e, /* add lr, pc, lr */
133 0xe5bef008 /* ldr pc, [lr, #8]! */
134 };
135
136 static const insn16 elf32_thumb_plt0_entry [THUMB_PLT_ENTRY_SIZE / 2] =
137 {
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} */
148 };
149
150 /* Subsequent entries in a procedure linkage table look like
151 this. */
152 static const bfd_vma elf32_arm_plt_entry [ARM_PLT_ENTRY_SIZE / 4] =
153 {
154 0xe59fc004, /* ldr ip, [pc, #4] */
155 0xe08fc00c, /* add ip, pc, ip */
156 0xe59cf000, /* ldr pc, [ip] */
157 0x00000000 /* offset to symbol in got */
158 };
159
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. */
164
165 static const insn16 elf32_thumb_plt_entry [THUMB_PLT_ENTRY_SIZE / 2] =
166 {
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 */
176 0x0000
177 };
178
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. */
184
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
188 {
189 /* Next section. */
190 struct elf32_arm_pcrel_relocs_copied * next;
191 /* A section in dynobj. */
192 asection * section;
193 /* Number of relocs copied in this section. */
194 bfd_size_type count;
195 };
196
197
198 /* We can generate Thumb or ARM PLT entries. This structure holds
199 additional information for symbols that have corresponding PLT
200 entries. */
201
202 struct elf32_arm_plt_entry_info
203 {
204 /* The first relocation type referring to this PLT entry. Used to
205 determine the type of the entry if the symbol is undefined. */
206 long first_rel_type;
207
208 /* True if we decided to emit the ARM version of the PLT entry for
209 this symbol. Otherwise the entry is Thumb. */
210 boolean arm_plt;
211
212 /* The offset of the corresponding .got.plt entry. */
213 bfd_vma got_plt_offset;
214 };
215
216 /* Arm ELF linker hash entry. */
217 struct elf32_arm_link_hash_entry
218 {
219 struct elf_link_hash_entry root;
220
221 /* Number of PC relative relocs copied for this symbol. */
222 struct elf32_arm_pcrel_relocs_copied * pcrel_relocs_copied;
223
224 struct elf32_arm_plt_entry_info plt_info;
225 };
226
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));
230
231 /* Traverse an arm ELF linker hash table. */
232 #define elf32_arm_link_hash_traverse(table, func, info) \
233 (elf_link_hash_traverse \
234 (&(table)->root, \
235 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
236 (info)))
237
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))
241
242 /* ARM ELF linker hash table. */
243 struct elf32_arm_link_hash_table
244 {
245 /* The main hash table. */
246 struct elf_link_hash_table root;
247
248 /* The size in bytes of the section containg the Thumb-to-ARM glue. */
249 bfd_size_type thumb_glue_size;
250
251 /* The size in bytes of the section containg the ARM-to-Thumb glue. */
252 bfd_size_type arm_glue_size;
253
254 /* An arbitary input BFD chosen to hold the glue sections. */
255 bfd * bfd_of_glue_owner;
256
257 /* A boolean indicating whether knowledge of the ARM's pipeline
258 length should be applied by the linker. */
259 int no_pipeline_knowledge;
260 };
261
262 /* Create an entry in an ARM ELF linker hash table. */
263
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;
268 const char * string;
269 {
270 struct elf32_arm_link_hash_entry * ret =
271 (struct elf32_arm_link_hash_entry *) entry;
272
273 /* Allocate the structure if it has not already been allocated by a
274 subclass. */
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;
281
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,
285 table, string));
286 if (ret != (struct elf32_arm_link_hash_entry *) NULL)
287 {
288 ret->pcrel_relocs_copied = NULL;
289 ret->plt_info.first_rel_type = R_ARM_NONE;
290 }
291
292 return (struct bfd_hash_entry *) ret;
293 }
294
295 /* Create an ARM elf linker hash table. */
296
297 static struct bfd_link_hash_table *
298 elf32_arm_link_hash_table_create (abfd)
299 bfd *abfd;
300 {
301 struct elf32_arm_link_hash_table *ret;
302 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
303
304 ret = (struct elf32_arm_link_hash_table *) bfd_malloc (amt);
305 if (ret == (struct elf32_arm_link_hash_table *) NULL)
306 return NULL;
307
308 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
309 elf32_arm_link_hash_newfunc))
310 {
311 free (ret);
312 return NULL;
313 }
314
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;
319
320 return &ret->root.root;
321 }
322
323 /* Locate the Thumb encoded calling stub for NAME. */
324
325 static struct elf_link_hash_entry *
326 find_thumb_glue (link_info, name, input_bfd)
327 struct bfd_link_info *link_info;
328 const char *name;
329 bfd *input_bfd;
330 {
331 char *tmp_name;
332 struct elf_link_hash_entry *hash;
333 struct elf32_arm_link_hash_table *hash_table;
334
335 /* We need a pointer to the armelf specific hash table. */
336 hash_table = elf32_arm_hash_table (link_info);
337
338 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
339 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
340
341 BFD_ASSERT (tmp_name);
342
343 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
344
345 hash = elf_link_hash_lookup
346 (&(hash_table)->root, tmp_name, false, false, true);
347
348 if (hash == NULL)
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);
352
353 free (tmp_name);
354
355 return hash;
356 }
357
358 /* Locate the ARM encoded calling stub for NAME. */
359
360 static struct elf_link_hash_entry *
361 find_arm_glue (link_info, name, input_bfd)
362 struct bfd_link_info *link_info;
363 const char *name;
364 bfd *input_bfd;
365 {
366 char *tmp_name;
367 struct elf_link_hash_entry *myh;
368 struct elf32_arm_link_hash_table *hash_table;
369
370 /* We need a pointer to the elfarm specific hash table. */
371 hash_table = elf32_arm_hash_table (link_info);
372
373 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
374 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
375
376 BFD_ASSERT (tmp_name);
377
378 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
379
380 myh = elf_link_hash_lookup
381 (&(hash_table)->root, tmp_name, false, false, true);
382
383 if (myh == NULL)
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);
387
388 free (tmp_name);
389
390 return myh;
391 }
392
393 /* ARM->Thumb glue:
394
395 .arm
396 __func_from_arm:
397 ldr r12, __func_addr
398 bx r12
399 __func_addr:
400 .word func @ behave as if you saw a ARM_32 reloc. */
401
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;
406
407 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
408
409 .thumb .thumb
410 .align 2 .align 2
411 __func_from_thumb: __func_from_thumb:
412 bx pc push {r6, lr}
413 nop ldr r6, __func_addr
414 .arm mov lr, pc
415 __func_change_to_arm: bx r6
416 b func .arm
417 __func_back_to_thumb:
418 ldmia r13! {r6, lr}
419 bx lr
420 __func_addr:
421 .word func */
422
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;
427
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;
434
435 #ifndef ELFARM_NABI_C_INCLUDED
436 boolean
437 bfd_elf32_arm_allocate_interworking_sections (info)
438 struct bfd_link_info * info;
439 {
440 asection * s;
441 bfd_byte * foo;
442 struct elf32_arm_link_hash_table * globals;
443
444 globals = elf32_arm_hash_table (info);
445
446 BFD_ASSERT (globals != NULL);
447
448 if (globals->arm_glue_size != 0)
449 {
450 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
451
452 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
453 ARM2THUMB_GLUE_SECTION_NAME);
454
455 BFD_ASSERT (s != NULL);
456
457 foo = (bfd_byte *) bfd_alloc (globals->bfd_of_glue_owner,
458 globals->arm_glue_size);
459
460 s->_raw_size = s->_cooked_size = globals->arm_glue_size;
461 s->contents = foo;
462 }
463
464 if (globals->thumb_glue_size != 0)
465 {
466 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
467
468 s = bfd_get_section_by_name
469 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
470
471 BFD_ASSERT (s != NULL);
472
473 foo = (bfd_byte *) bfd_alloc (globals->bfd_of_glue_owner,
474 globals->thumb_glue_size);
475
476 s->_raw_size = s->_cooked_size = globals->thumb_glue_size;
477 s->contents = foo;
478 }
479
480 return true;
481 }
482
483 static void
484 record_arm_to_thumb_glue (link_info, h)
485 struct bfd_link_info * link_info;
486 struct elf_link_hash_entry * h;
487 {
488 const char * name = h->root.root.string;
489 asection * s;
490 char * tmp_name;
491 struct elf_link_hash_entry * myh;
492 struct elf32_arm_link_hash_table * globals;
493 bfd_vma val;
494
495 globals = elf32_arm_hash_table (link_info);
496
497 BFD_ASSERT (globals != NULL);
498 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
499
500 s = bfd_get_section_by_name
501 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
502
503 BFD_ASSERT (s != NULL);
504
505 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
506 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
507
508 BFD_ASSERT (tmp_name);
509
510 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
511
512 myh = elf_link_hash_lookup
513 (&(globals)->root, tmp_name, false, false, true);
514
515 if (myh != NULL)
516 {
517 /* We've already seen this guy. */
518 free (tmp_name);
519 return;
520 }
521
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
524 it. */
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,
528 NULL, true, false,
529 (struct bfd_link_hash_entry **) &myh);
530
531 free (tmp_name);
532
533 globals->arm_glue_size += ARM2THUMB_GLUE_SIZE;
534
535 return;
536 }
537
538 static void
539 record_thumb_to_arm_glue (link_info, h)
540 struct bfd_link_info *link_info;
541 struct elf_link_hash_entry *h;
542 {
543 const char *name = h->root.root.string;
544 asection *s;
545 char *tmp_name;
546 struct elf_link_hash_entry *myh;
547 struct elf32_arm_link_hash_table *hash_table;
548 char bind;
549 bfd_vma val;
550
551 hash_table = elf32_arm_hash_table (link_info);
552
553 BFD_ASSERT (hash_table != NULL);
554 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
555
556 s = bfd_get_section_by_name
557 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
558
559 BFD_ASSERT (s != NULL);
560
561 tmp_name = (char *) bfd_malloc ((bfd_size_type) strlen (name)
562 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
563
564 BFD_ASSERT (tmp_name);
565
566 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
567
568 myh = elf_link_hash_lookup
569 (&(hash_table)->root, tmp_name, false, false, true);
570
571 if (myh != NULL)
572 {
573 /* We've already seen this guy. */
574 free (tmp_name);
575 return;
576 }
577
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,
581 NULL, true, false,
582 (struct bfd_link_hash_entry **) &myh);
583
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);
587
588 free (tmp_name);
589
590 #define CHANGE_TO_ARM "__%s_change_to_arm"
591 #define BACK_FROM_ARM "__%s_back_from_arm"
592
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);
596
597 BFD_ASSERT (tmp_name);
598
599 sprintf (tmp_name, CHANGE_TO_ARM, name);
600
601 myh = NULL;
602
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,
606 NULL, true, false,
607 (struct bfd_link_hash_entry **) &myh);
608
609 free (tmp_name);
610
611 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
612
613 return;
614 }
615
616 /* Add the glue sections to ABFD. This function is called from the
617 linker scripts in ld/emultempl/{armelf}.em. */
618
619 boolean
620 bfd_elf32_arm_add_glue_sections_to_bfd (abfd, info)
621 bfd *abfd;
622 struct bfd_link_info *info;
623 {
624 flagword flags;
625 asection *sec;
626
627 /* If we are only performing a partial
628 link do not bother adding the glue. */
629 if (info->relocateable)
630 return true;
631
632 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
633
634 if (sec == NULL)
635 {
636 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
637 will prevent elf_link_input_bfd() from processing the contents
638 of this section. */
639 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
640
641 sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
642
643 if (sec == NULL
644 || !bfd_set_section_flags (abfd, sec, flags)
645 || !bfd_set_section_alignment (abfd, sec, 2))
646 return false;
647
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. */
650 sec->gc_mark = 1;
651 }
652
653 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
654
655 if (sec == NULL)
656 {
657 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
658
659 sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
660
661 if (sec == NULL
662 || !bfd_set_section_flags (abfd, sec, flags)
663 || !bfd_set_section_alignment (abfd, sec, 2))
664 return false;
665
666 sec->gc_mark = 1;
667 }
668
669 return true;
670 }
671
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/
674 {armelf/pe}.em */
675
676 boolean
677 bfd_elf32_arm_get_bfd_for_interworking (abfd, info)
678 bfd *abfd;
679 struct bfd_link_info *info;
680 {
681 struct elf32_arm_link_hash_table *globals;
682
683 /* If we are only performing a partial link
684 do not bother getting a bfd to hold the glue. */
685 if (info->relocateable)
686 return true;
687
688 globals = elf32_arm_hash_table (info);
689
690 BFD_ASSERT (globals != NULL);
691
692 if (globals->bfd_of_glue_owner != NULL)
693 return true;
694
695 /* Save the bfd for later use. */
696 globals->bfd_of_glue_owner = abfd;
697
698 return true;
699 }
700
701 boolean
702 bfd_elf32_arm_process_before_allocation (abfd, link_info, no_pipeline_knowledge)
703 bfd *abfd;
704 struct bfd_link_info *link_info;
705 int no_pipeline_knowledge;
706 {
707 Elf_Internal_Shdr *symtab_hdr;
708 Elf_Internal_Rela *internal_relocs = NULL;
709 Elf_Internal_Rela *irel, *irelend;
710 bfd_byte *contents = NULL;
711
712 asection *sec;
713 struct elf32_arm_link_hash_table *globals;
714
715 /* If we are only performing a partial link do not bother
716 to construct any glue. */
717 if (link_info->relocateable)
718 return true;
719
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);
723
724 BFD_ASSERT (globals != NULL);
725 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
726
727 globals->no_pipeline_knowledge = no_pipeline_knowledge;
728
729 /* Rummage around all the relocs and map the glue vectors. */
730 sec = abfd->sections;
731
732 if (sec == NULL)
733 return true;
734
735 for (; sec != NULL; sec = sec->next)
736 {
737 if (sec->reloc_count == 0)
738 continue;
739
740 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
741
742 /* Load the relocs. */
743 internal_relocs
744 = _bfd_elf32_link_read_relocs (abfd, sec, (PTR) NULL,
745 (Elf_Internal_Rela *) NULL, false);
746
747 if (internal_relocs == NULL)
748 goto error_return;
749
750 irelend = internal_relocs + sec->reloc_count;
751 for (irel = internal_relocs; irel < irelend; irel++)
752 {
753 long r_type;
754 unsigned long r_index;
755
756 struct elf_link_hash_entry *h;
757
758 r_type = ELF32_R_TYPE (irel->r_info);
759 r_index = ELF32_R_SYM (irel->r_info);
760
761 /* These are the only relocation types we care about. */
762 if ( r_type != R_ARM_PC24
763 && r_type != R_ARM_THM_PC22)
764 continue;
765
766 /* Get the section contents if we haven't done so already. */
767 if (contents == NULL)
768 {
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;
772 else
773 {
774 /* Go get them off disk. */
775 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
776 if (contents == NULL)
777 goto error_return;
778
779 if (!bfd_get_section_contents (abfd, sec, contents,
780 (file_ptr) 0, sec->_raw_size))
781 goto error_return;
782 }
783 }
784
785 /* If the relocation is not against a symbol it cannot concern us. */
786 h = NULL;
787
788 /* We don't care about local symbols. */
789 if (r_index < symtab_hdr->sh_info)
790 continue;
791
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];
796
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. */
799 if (h == NULL)
800 continue;
801
802 switch (r_type)
803 {
804 case R_ARM_PC24:
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
807 insert glue. */
808 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC)
809 record_arm_to_thumb_glue (link_info, h);
810 break;
811
812 case R_ARM_THM_PC22:
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);
818 break;
819
820 default:
821 break;
822 }
823 }
824
825 if (contents != NULL
826 && elf_section_data (sec)->this_hdr.contents != contents)
827 free (contents);
828 contents = NULL;
829
830 if (internal_relocs != NULL
831 && elf_section_data (sec)->relocs != internal_relocs)
832 free (internal_relocs);
833 internal_relocs = NULL;
834 }
835
836 return true;
837
838 error_return:
839 if (contents != NULL
840 && elf_section_data (sec)->this_hdr.contents != contents)
841 free (contents);
842 if (internal_relocs != NULL
843 && elf_section_data (sec)->relocs != internal_relocs)
844 free (internal_relocs);
845
846 return false;
847 }
848 #endif
849
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
854 instruction.
855
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
859 by H-1).
860
861 Combine together and shifted left by 1 (it's a half word address) and
862 there you have it.
863
864 Op: 1111 = F,
865 H-0, upper address-0 = 000
866 Op: 1111 = F,
867 H-1, lower address-0 = 800
868
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
871
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. */
877
878 #define LOW_HI_ORDER 0xF800F000
879 #define HI_LOW_ORDER 0xF000F800
880
881 static insn32
882 insert_thumb_branch (br_insn, rel_off)
883 insn32 br_insn;
884 int rel_off;
885 {
886 unsigned int low_bits;
887 unsigned int high_bits;
888
889 BFD_ASSERT ((rel_off & 1) != 1);
890
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. */
894
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;
899 else
900 /* FIXME: abort is probably not the right call. krk@cygnus.com */
901 abort (); /* error - not a valid branch instruction form. */
902
903 return br_insn;
904 }
905
906 /* Thumb code calling an ARM function. */
907
908 static int
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;
912 const char * name;
913 bfd * input_bfd;
914 bfd * output_bfd;
915 asection * input_section;
916 bfd_byte * hit_data;
917 asection * sym_sec;
918 bfd_vma offset;
919 bfd_signed_vma addend;
920 bfd_vma val;
921 {
922 asection * s = 0;
923 bfd_vma my_offset;
924 unsigned long int tmp;
925 long int ret_offset;
926 struct elf_link_hash_entry * myh;
927 struct elf32_arm_link_hash_table * globals;
928
929 myh = find_thumb_glue (info, name, input_bfd);
930 if (myh == NULL)
931 return false;
932
933 globals = elf32_arm_hash_table (info);
934
935 BFD_ASSERT (globals != NULL);
936 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
937
938 my_offset = myh->root.u.def.value;
939
940 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
941 THUMB2ARM_GLUE_SECTION_NAME);
942
943 BFD_ASSERT (s != NULL);
944 BFD_ASSERT (s->contents != NULL);
945 BFD_ASSERT (s->output_section != NULL);
946
947 if ((my_offset & 0x01) == 0x01)
948 {
949 if (sym_sec != NULL
950 && sym_sec->owner != NULL
951 && !INTERWORK_FLAG (sym_sec->owner))
952 {
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));
959
960 return false;
961 }
962
963 --my_offset;
964 myh->root.u.def.value = my_offset;
965
966 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
967 s->contents + my_offset);
968
969 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
970 s->contents + my_offset + 2);
971
972 ret_offset =
973 /* Address of destination of the stub. */
974 ((bfd_signed_vma) val)
975 - ((bfd_signed_vma)
976 /* Offset from the start of the current section to the start of the stubs. */
977 (s->output_offset
978 /* Offset of the start of this stub from the start of the stubs. */
979 + my_offset
980 /* Address of the start of the current section. */
981 + s->output_section->vma)
982 /* The branch instruction is 4 bytes into the stub. */
983 + 4
984 /* ARM branches work from the pc of the instruction + 8. */
985 + 8);
986
987 bfd_put_32 (output_bfd,
988 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
989 s->contents + my_offset + 4);
990 }
991
992 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
993
994 /* Now go back and fix up the original BL insn to point
995 to here. */
996 ret_offset = (s->output_offset
997 + my_offset
998 - (input_section->output_offset
999 + offset + addend)
1000 - 8);
1001
1002 tmp = bfd_get_32 (input_bfd, hit_data
1003 - input_section->vma);
1004
1005 bfd_put_32 (output_bfd,
1006 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
1007 hit_data - input_section->vma);
1008
1009 return true;
1010 }
1011
1012 /* Arm code calling a Thumb function. */
1013
1014 static int
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;
1018 const char * name;
1019 bfd * input_bfd;
1020 bfd * output_bfd;
1021 asection * input_section;
1022 bfd_byte * hit_data;
1023 asection * sym_sec;
1024 bfd_vma offset;
1025 bfd_signed_vma addend;
1026 bfd_vma val;
1027 {
1028 unsigned long int tmp;
1029 bfd_vma my_offset;
1030 asection * s;
1031 long int ret_offset;
1032 struct elf_link_hash_entry * myh;
1033 struct elf32_arm_link_hash_table * globals;
1034
1035 myh = find_arm_glue (info, name, input_bfd);
1036 if (myh == NULL)
1037 return false;
1038
1039 globals = elf32_arm_hash_table (info);
1040
1041 BFD_ASSERT (globals != NULL);
1042 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1043
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);
1050
1051 if ((my_offset & 0x01) == 0x01)
1052 {
1053 if (sym_sec != NULL
1054 && sym_sec->owner != NULL
1055 && !INTERWORK_FLAG (sym_sec->owner))
1056 {
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));
1063 }
1064
1065 --my_offset;
1066 myh->root.u.def.value = my_offset;
1067
1068 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
1069 s->contents + my_offset);
1070
1071 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
1072 s->contents + my_offset + 4);
1073
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);
1077 }
1078
1079 BFD_ASSERT (my_offset <= globals->arm_glue_size);
1080
1081 tmp = bfd_get_32 (input_bfd, hit_data);
1082 tmp = tmp & 0xFF000000;
1083
1084 /* Somehow these are both 4 too far, so subtract 8. */
1085 ret_offset = (s->output_offset
1086 + my_offset
1087 + s->output_section->vma
1088 - (input_section->output_offset
1089 + input_section->output_section->vma
1090 + offset + addend)
1091 - 8);
1092
1093 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
1094
1095 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
1096
1097 return true;
1098 }
1099
1100 /* Perform a relocation as part of a final link. */
1101
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;
1107 bfd * input_bfd;
1108 bfd * output_bfd;
1109 asection * input_section;
1110 bfd_byte * contents;
1111 Elf_Internal_Rela * rel;
1112 bfd_vma value;
1113 struct bfd_link_info * info;
1114 asection * sym_sec;
1115 const char * sym_name;
1116 int sym_flags;
1117 struct elf_link_hash_entry * h;
1118 {
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;
1130 bfd_vma addend;
1131 bfd_signed_vma signed_addend;
1132 struct elf32_arm_link_hash_table * globals;
1133
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.
1137
1138 The test is done here, rather than somewhere else, because the
1139 start address is only set just before the final link commences.
1140
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;
1145
1146 globals = elf32_arm_hash_table (info);
1147
1148 dynobj = elf_hash_table (info)->dynobj;
1149 if (dynobj)
1150 {
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");
1154 }
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);
1159
1160 #ifdef USE_REL
1161 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
1162
1163 if (addend & ((howto->src_mask + 1) >> 1))
1164 {
1165 signed_addend = -1;
1166 signed_addend &= ~ howto->src_mask;
1167 signed_addend |= addend;
1168 }
1169 else
1170 signed_addend = addend;
1171 #else
1172 addend = signed_addend = rel->r_addend;
1173 #endif
1174
1175 switch (r_type)
1176 {
1177 case R_ARM_NONE:
1178 return bfd_reloc_ok;
1179
1180 case R_ARM_PC24:
1181 case R_ARM_ABS32:
1182 case R_ARM_REL32:
1183 #ifndef OLD_ARM_ABI
1184 case R_ARM_XPC25:
1185 #endif
1186 /* When generating a shared object, these relocations are copied
1187 into the output file to be resolved at run time. */
1188 if (info->shared
1189 && r_symndx != 0
1190 && (r_type != R_ARM_PC24
1191 || (h != NULL
1192 && h->dynindx != -1
1193 && (! info->symbolic
1194 || (h->elf_link_hash_flags
1195 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
1196 {
1197 Elf_Internal_Rel outrel;
1198 boolean skip, relocate;
1199
1200 if (sreloc == NULL)
1201 {
1202 const char * name;
1203
1204 name = (bfd_elf_string_from_elf_section
1205 (input_bfd,
1206 elf_elfheader (input_bfd)->e_shstrndx,
1207 elf_section_data (input_section)->rel_hdr.sh_name));
1208 if (name == NULL)
1209 return bfd_reloc_notsupported;
1210
1211 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
1212 && strcmp (bfd_get_section_name (input_bfd,
1213 input_section),
1214 name + 4) == 0);
1215
1216 sreloc = bfd_get_section_by_name (dynobj, name);
1217 BFD_ASSERT (sreloc != NULL);
1218 }
1219
1220 skip = false;
1221 relocate = false;
1222
1223 outrel.r_offset =
1224 _bfd_elf_section_offset (output_bfd, info, input_section,
1225 rel->r_offset);
1226 if (outrel.r_offset == (bfd_vma) -1)
1227 skip = true;
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);
1232
1233 if (skip)
1234 memset (&outrel, 0, sizeof outrel);
1235 else if (r_type == R_ARM_PC24)
1236 {
1237 BFD_ASSERT (h != NULL && h->dynindx != -1);
1238 if ((input_section->flags & SEC_ALLOC) == 0)
1239 relocate = true;
1240 outrel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_PC24);
1241 }
1242 else
1243 {
1244 if (h == NULL
1245 || ((info->symbolic || h->dynindx == -1)
1246 && (h->elf_link_hash_flags
1247 & ELF_LINK_HASH_DEF_REGULAR) != 0))
1248 {
1249 relocate = true;
1250 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
1251 }
1252 else
1253 {
1254 BFD_ASSERT (h->dynindx != -1);
1255 if ((input_section->flags & SEC_ALLOC) == 0)
1256 relocate = true;
1257 outrel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_ABS32);
1258 }
1259 }
1260
1261 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1262 (((Elf32_External_Rel *)
1263 sreloc->contents)
1264 + sreloc->reloc_count));
1265 ++sreloc->reloc_count;
1266
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. */
1270 if (! relocate)
1271 return bfd_reloc_ok;
1272
1273 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1274 contents, rel->r_offset, value,
1275 (bfd_vma) 0);
1276 }
1277 else switch (r_type)
1278 {
1279 #ifndef OLD_ARM_ABI
1280 case R_ARM_XPC25: /* Arm BLX instruction. */
1281 #endif
1282 case R_ARM_PC24: /* Arm B/BL instruction */
1283 #ifndef OLD_ARM_ABI
1284 if (r_type == R_ARM_XPC25)
1285 {
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)");
1294 }
1295 else
1296 #endif
1297 {
1298 /* Check for Arm calling Thumb function. */
1299 if (sym_flags == STT_ARM_TFUNC)
1300 {
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;
1305 }
1306 }
1307
1308 if ( strcmp (bfd_get_target (input_bfd), "elf32-littlearm-oabi") == 0
1309 || strcmp (bfd_get_target (input_bfd), "elf32-bigarm-oabi") == 0)
1310 {
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;
1316 value += addend;
1317
1318 if (! globals->no_pipeline_knowledge)
1319 value -= 8;
1320 }
1321 else
1322 {
1323 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
1324 where:
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.
1328
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 +
1334 rel->r_offset).
1335 A is the addend, converted into bytes, ie:
1336 (signed_addend * 4)
1337
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);
1345
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)
1352 {
1353 Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form */
1354
1355 i_ehdrp = elf_elfheader (input_bfd);
1356
1357 if (i_ehdrp->e_ident[EI_OSABI] == 0)
1358 value -= 8;
1359 }
1360 }
1361
1362 signed_addend = value;
1363 signed_addend >>= howto->rightshift;
1364
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)
1370 {
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;
1375 }
1376
1377 #ifndef OLD_ARM_ABI
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))
1382 | (1 << 24);
1383 else
1384 #endif
1385 value = (signed_addend & howto->dst_mask)
1386 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
1387 break;
1388
1389 case R_ARM_ABS32:
1390 value += addend;
1391 if (sym_flags == STT_ARM_TFUNC)
1392 value |= 1;
1393 break;
1394
1395 case R_ARM_REL32:
1396 value -= (input_section->output_section->vma
1397 + input_section->output_offset + rel->r_offset);
1398 value += addend;
1399 break;
1400 }
1401
1402 bfd_put_32 (input_bfd, value, hit_data);
1403 return bfd_reloc_ok;
1404
1405 case R_ARM_ABS8:
1406 value += addend;
1407 if ((long) value > 0x7f || (long) value < -0x80)
1408 return bfd_reloc_overflow;
1409
1410 bfd_put_8 (input_bfd, value, hit_data);
1411 return bfd_reloc_ok;
1412
1413 case R_ARM_ABS16:
1414 value += addend;
1415
1416 if ((long) value > 0x7fff || (long) value < -0x8000)
1417 return bfd_reloc_overflow;
1418
1419 bfd_put_16 (input_bfd, value, hit_data);
1420 return bfd_reloc_ok;
1421
1422 case R_ARM_ABS12:
1423 /* Support ldr and str instruction for the arm */
1424 /* Also thumb b (unconditional branch). ??? Really? */
1425 value += addend;
1426
1427 if ((long) value > 0x7ff || (long) value < -0x800)
1428 return bfd_reloc_overflow;
1429
1430 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
1431 bfd_put_32 (input_bfd, value, hit_data);
1432 return bfd_reloc_ok;
1433
1434 case R_ARM_THM_ABS5:
1435 /* Support ldr and str instructions for the thumb. */
1436 #ifdef USE_REL
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;
1441 #endif
1442 value += addend;
1443
1444 /* ??? Isn't value unsigned? */
1445 if ((long) value > 0x1f || (long) value < -0x10)
1446 return bfd_reloc_overflow;
1447
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;
1452
1453 #ifndef OLD_ARM_ABI
1454 case R_ARM_THM_XPC22:
1455 #endif
1456 case R_ARM_THM_PC22:
1457 /* Thumb BL (branch long instruction). */
1458 {
1459 bfd_vma relocation;
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;
1465 bfd_vma check;
1466 bfd_signed_vma signed_check;
1467
1468 #ifdef USE_REL
1469 /* Need to refetch the addend and squish the two 11 bit pieces
1470 together. */
1471 {
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;
1477 }
1478 #endif
1479
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
1485 + h->plt.offset);
1486
1487 #ifndef OLD_ARM_ABI
1488 if (r_type == R_ARM_THM_XPC22)
1489 {
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)");
1498 }
1499 else
1500 #endif
1501 {
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)
1506 {
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;
1511 else
1512 return bfd_reloc_dangerous;
1513 }
1514 }
1515
1516 relocation = value + signed_addend;
1517
1518 relocation -= (input_section->output_section->vma
1519 + input_section->output_offset
1520 + rel->r_offset);
1521
1522 if (! globals->no_pipeline_knowledge)
1523 {
1524 Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form. */
1525
1526 i_ehdrp = elf_elfheader (input_bfd);
1527
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)
1536 relocation += 4;
1537 }
1538
1539 check = relocation >> howto->rightshift;
1540
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;
1545 else
1546 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
1547
1548 /* Assumes two's complement. */
1549 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
1550 overflow = true;
1551
1552 #ifndef OLD_ARM_ABI
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;
1560 #endif
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);
1564
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);
1568
1569 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
1570 }
1571 break;
1572
1573 case R_ARM_THM_PC11:
1574 /* Thumb B (branch) instruction). */
1575 {
1576 bfd_vma relocation;
1577 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
1578 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
1579 bfd_vma check;
1580 bfd_signed_vma signed_check;
1581
1582 #ifdef USE_REL
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;
1587 #endif
1588 relocation = value + addend;
1589
1590 relocation -= (input_section->output_section->vma
1591 + input_section->output_offset
1592 + rel->r_offset);
1593
1594 check = relocation >> howto->rightshift;
1595
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;
1600 else
1601 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
1602
1603 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
1604
1605 bfd_put_16 (input_bfd, relocation, hit_data);
1606
1607 /* Assumes two's complement. */
1608 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
1609 return bfd_reloc_overflow;
1610
1611 return bfd_reloc_ok;
1612 }
1613
1614 case R_ARM_GNU_VTINHERIT:
1615 case R_ARM_GNU_VTENTRY:
1616 return bfd_reloc_ok;
1617
1618 case R_ARM_COPY:
1619 return bfd_reloc_notsupported;
1620
1621 case R_ARM_GLOB_DAT:
1622 return bfd_reloc_notsupported;
1623
1624 case R_ARM_JUMP_SLOT:
1625 return bfd_reloc_notsupported;
1626
1627 case R_ARM_RELATIVE:
1628 return bfd_reloc_notsupported;
1629
1630 case R_ARM_GOTOFF:
1631 /* Relocation is relative to the start of the
1632 global offset table. */
1633
1634 BFD_ASSERT (sgot != NULL);
1635 if (sgot == NULL)
1636 return bfd_reloc_notsupported;
1637
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)
1642 value += 1;
1643
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
1648 calculation. */
1649 value -= sgot->output_section->vma;
1650 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1651 contents, rel->r_offset, value,
1652 (bfd_vma) 0);
1653
1654 case R_ARM_GOTPC:
1655 /* Use global offset table as symbol value. */
1656 BFD_ASSERT (sgot != NULL);
1657
1658 if (sgot == NULL)
1659 return bfd_reloc_notsupported;
1660
1661 value = sgot->output_section->vma;
1662 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1663 contents, rel->r_offset, value,
1664 (bfd_vma) 0);
1665
1666 case R_ARM_GOT32:
1667 /* Relocation is to the entry for this symbol in the
1668 global offset table. */
1669 if (sgot == NULL)
1670 return bfd_reloc_notsupported;
1671
1672 if (h != NULL)
1673 {
1674 bfd_vma off;
1675
1676 off = h->got.offset;
1677 BFD_ASSERT (off != (bfd_vma) -1);
1678
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)))
1682 {
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.
1688
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. */
1692 if ((off & 1) != 0)
1693 off &= ~1;
1694 else
1695 {
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)
1701 value |= 1;
1702
1703 bfd_put_32 (output_bfd, value, sgot->contents + off);
1704 h->got.offset |= 1;
1705 }
1706 }
1707
1708 value = sgot->output_offset + off;
1709 }
1710 else
1711 {
1712 bfd_vma off;
1713
1714 BFD_ASSERT (local_got_offsets != NULL &&
1715 local_got_offsets[r_symndx] != (bfd_vma) -1);
1716
1717 off = local_got_offsets[r_symndx];
1718
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. */
1722 if ((off & 1) != 0)
1723 off &= ~1;
1724 else
1725 {
1726 bfd_put_32 (output_bfd, value, sgot->contents + off);
1727
1728 if (info->shared)
1729 {
1730 asection * srelgot;
1731 Elf_Internal_Rel outrel;
1732
1733 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
1734 BFD_ASSERT (srelgot != NULL);
1735
1736 outrel.r_offset = (sgot->output_section->vma
1737 + sgot->output_offset
1738 + off);
1739 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
1740 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1741 (((Elf32_External_Rel *)
1742 srelgot->contents)
1743 + srelgot->reloc_count));
1744 ++srelgot->reloc_count;
1745 }
1746
1747 local_got_offsets[r_symndx] |= 1;
1748 }
1749
1750 value = sgot->output_offset + off;
1751 }
1752
1753 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1754 contents, rel->r_offset, value,
1755 (bfd_vma) 0);
1756
1757 case R_ARM_PLT32:
1758 /* Relocation is to the entry for this symbol in the
1759 procedure linkage table. */
1760
1761 /* Resolve a PLT32 reloc against a local symbol directly,
1762 without using the procedure linkage table. */
1763 if (h == NULL)
1764 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1765 contents, rel->r_offset, value,
1766 (bfd_vma) 0);
1767
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,
1774 (bfd_vma) 0);
1775
1776 BFD_ASSERT(splt != NULL);
1777 if (splt == NULL)
1778 return bfd_reloc_notsupported;
1779
1780 value = (splt->output_section->vma
1781 + splt->output_offset
1782 + h->plt.offset);
1783 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1784 contents, rel->r_offset, value,
1785 (bfd_vma) 0);
1786
1787 case R_ARM_SBREL32:
1788 return bfd_reloc_notsupported;
1789
1790 case R_ARM_AMP_VCALL9:
1791 return bfd_reloc_notsupported;
1792
1793 case R_ARM_RSBREL32:
1794 return bfd_reloc_notsupported;
1795
1796 case R_ARM_THM_RPC22:
1797 return bfd_reloc_notsupported;
1798
1799 case R_ARM_RREL32:
1800 return bfd_reloc_notsupported;
1801
1802 case R_ARM_RABS32:
1803 return bfd_reloc_notsupported;
1804
1805 case R_ARM_RPC24:
1806 return bfd_reloc_notsupported;
1807
1808 case R_ARM_RBASE:
1809 return bfd_reloc_notsupported;
1810
1811 default:
1812 return bfd_reloc_notsupported;
1813 }
1814 }
1815
1816 #ifdef USE_REL
1817 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
1818 static void
1819 arm_add_to_rel (abfd, address, howto, increment)
1820 bfd * abfd;
1821 bfd_byte * address;
1822 reloc_howto_type * howto;
1823 bfd_signed_vma increment;
1824 {
1825 bfd_signed_vma addend;
1826
1827 if (howto->type == R_ARM_THM_PC22)
1828 {
1829 int upper_insn, lower_insn;
1830 int upper, lower;
1831
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;
1836
1837 addend = (upper << 12) | (lower << 1);
1838 addend += increment;
1839 addend >>= 1;
1840
1841 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
1842 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
1843
1844 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
1845 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
1846 }
1847 else
1848 {
1849 bfd_vma contents;
1850
1851 contents = bfd_get_32 (abfd, address);
1852
1853 /* Get the (signed) value from the instruction. */
1854 addend = contents & howto->src_mask;
1855 if (addend & ((howto->src_mask + 1) >> 1))
1856 {
1857 bfd_signed_vma mask;
1858
1859 mask = -1;
1860 mask &= ~ howto->src_mask;
1861 addend |= mask;
1862 }
1863
1864 /* Add in the increment, (which is a byte value). */
1865 switch (howto->type)
1866 {
1867 default:
1868 addend += increment;
1869 break;
1870
1871 case R_ARM_PC24:
1872 addend <<= howto->size;
1873 addend += increment;
1874
1875 /* Should we check for overflow here ? */
1876
1877 /* Drop any undesired bits. */
1878 addend >>= howto->rightshift;
1879 break;
1880 }
1881
1882 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
1883
1884 bfd_put_32 (abfd, contents, address);
1885 }
1886 }
1887 #endif /* USE_REL */
1888
1889 /* Relocate an ARM ELF section. */
1890 static boolean
1891 elf32_arm_relocate_section (output_bfd, info, input_bfd, input_section,
1892 contents, relocs, local_syms, local_sections)
1893 bfd * output_bfd;
1894 struct bfd_link_info * info;
1895 bfd * input_bfd;
1896 asection * input_section;
1897 bfd_byte * contents;
1898 Elf_Internal_Rela * relocs;
1899 Elf_Internal_Sym * local_syms;
1900 asection ** local_sections;
1901 {
1902 Elf_Internal_Shdr * symtab_hdr;
1903 struct elf_link_hash_entry ** sym_hashes;
1904 Elf_Internal_Rela * rel;
1905 Elf_Internal_Rela * relend;
1906 const char * name;
1907
1908 #ifndef USE_REL
1909 if (info->relocateable)
1910 return true;
1911 #endif
1912
1913 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1914 sym_hashes = elf_sym_hashes (input_bfd);
1915
1916 rel = relocs;
1917 relend = relocs + input_section->reloc_count;
1918 for (; rel < relend; rel++)
1919 {
1920 int r_type;
1921 reloc_howto_type * howto;
1922 unsigned long r_symndx;
1923 Elf_Internal_Sym * sym;
1924 asection * sec;
1925 struct elf_link_hash_entry * h;
1926 bfd_vma relocation;
1927 bfd_reloc_status_type r;
1928 arelent bfd_reloc;
1929
1930 r_symndx = ELF32_R_SYM (rel->r_info);
1931 r_type = ELF32_R_TYPE (rel->r_info);
1932
1933 if ( r_type == R_ARM_GNU_VTENTRY
1934 || r_type == R_ARM_GNU_VTINHERIT)
1935 continue;
1936
1937 #ifdef USE_REL
1938 elf32_arm_info_to_howto (input_bfd, & bfd_reloc,
1939 (Elf_Internal_Rel *) rel);
1940 #else
1941 elf32_arm_info_to_howto (input_bfd, & bfd_reloc, rel);
1942 #endif
1943 howto = bfd_reloc.howto;
1944
1945 #ifdef USE_REL
1946 if (info->relocateable)
1947 {
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)
1953 {
1954 sym = local_syms + r_symndx;
1955 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1956 {
1957 sec = local_sections[r_symndx];
1958 arm_add_to_rel (input_bfd, contents + rel->r_offset,
1959 howto,
1960 (bfd_signed_vma) (sec->output_offset
1961 + sym->st_value));
1962 }
1963 }
1964
1965 continue;
1966 }
1967 #endif
1968
1969 /* This is a final link. */
1970 h = NULL;
1971 sym = NULL;
1972 sec = NULL;
1973
1974 if (r_symndx < symtab_hdr->sh_info)
1975 {
1976 sym = local_syms + r_symndx;
1977 sec = local_sections[r_symndx];
1978 #ifdef USE_REL
1979 relocation = (sec->output_section->vma
1980 + sec->output_offset
1981 + sym->st_value);
1982 if ((sec->flags & SEC_MERGE)
1983 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1984 {
1985 asection *msec;
1986 bfd_vma addend, value;
1987
1988 if (howto->rightshift)
1989 {
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);
1995 return false;
1996 }
1997
1998 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
1999
2000 /* Get the (signed) value from the instruction. */
2001 addend = value & howto->src_mask;
2002 if (addend & ((howto->src_mask + 1) >> 1))
2003 {
2004 bfd_signed_vma mask;
2005
2006 mask = -1;
2007 mask &= ~ howto->src_mask;
2008 addend |= mask;
2009 }
2010 msec = sec;
2011 addend =
2012 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
2013 - relocation;
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);
2017 }
2018 #else
2019 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
2020 #endif
2021 }
2022 else
2023 {
2024 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2025
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;
2029
2030 if ( h->root.type == bfd_link_hash_defined
2031 || h->root.type == bfd_link_hash_defweak)
2032 {
2033 int relocation_needed = 1;
2034
2035 sec = h->root.u.def.section;
2036
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. */
2040 switch (r_type)
2041 {
2042 case R_ARM_PC24:
2043 case R_ARM_ABS32:
2044 case R_ARM_THM_PC22:
2045 if (info->shared
2046 && (
2047 (!info->symbolic && h->dynindx != -1)
2048 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2049 )
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
2054 with them here. */
2055 || ((input_section->flags & SEC_DEBUGGING) != 0
2056 && (h->elf_link_hash_flags
2057 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
2058 )
2059 relocation_needed = 0;
2060 break;
2061
2062 case R_ARM_GOTPC:
2063 relocation_needed = 0;
2064 break;
2065
2066 case R_ARM_GOT32:
2067 if (elf_hash_table(info)->dynamic_sections_created
2068 && (!info->shared
2069 || (!info->symbolic && h->dynindx != -1)
2070 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2071 )
2072 )
2073 relocation_needed = 0;
2074 break;
2075
2076 case R_ARM_PLT32:
2077 if (h->plt.offset != (bfd_vma)-1)
2078 relocation_needed = 0;
2079 break;
2080
2081 default:
2082 if (sec->output_section == NULL)
2083 {
2084 (*_bfd_error_handler)
2085 (_("%s: warning: unresolvable relocation %d against symbol `%s' from %s section"),
2086 bfd_archive_filename (input_bfd),
2087 r_type,
2088 h->root.root.string,
2089 bfd_get_section_name (input_bfd, input_section));
2090 relocation_needed = 0;
2091 }
2092 }
2093
2094 if (relocation_needed)
2095 relocation = h->root.u.def.value
2096 + sec->output_section->vma
2097 + sec->output_offset;
2098 else
2099 relocation = 0;
2100 }
2101 else if (h->root.type == bfd_link_hash_undefweak)
2102 relocation = 0;
2103 else if (info->shared && !info->symbolic
2104 && !info->no_undefined
2105 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2106 relocation = 0;
2107 else
2108 {
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)))))
2114 return false;
2115 relocation = 0;
2116 }
2117 }
2118
2119 if (h != NULL)
2120 name = h->root.root.string;
2121 else
2122 {
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);
2127 }
2128
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);
2134
2135 if (r != bfd_reloc_ok)
2136 {
2137 const char * msg = (const char *) 0;
2138
2139 switch (r)
2140 {
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. */
2145 if ((! h ||
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))))
2150 return false;
2151 break;
2152
2153 case bfd_reloc_undefined:
2154 if (!((*info->callbacks->undefined_symbol)
2155 (info, name, input_bfd, input_section,
2156 rel->r_offset, true)))
2157 return false;
2158 break;
2159
2160 case bfd_reloc_outofrange:
2161 msg = _("internal error: out of range error");
2162 goto common_error;
2163
2164 case bfd_reloc_notsupported:
2165 msg = _("internal error: unsupported relocation error");
2166 goto common_error;
2167
2168 case bfd_reloc_dangerous:
2169 msg = _("internal error: dangerous error");
2170 goto common_error;
2171
2172 default:
2173 msg = _("internal error: unknown error");
2174 /* fall through */
2175
2176 common_error:
2177 if (!((*info->callbacks->warning)
2178 (info, msg, name, input_bfd, input_section,
2179 rel->r_offset)))
2180 return false;
2181 break;
2182 }
2183 }
2184 }
2185
2186 return true;
2187 }
2188
2189 /* Function to keep ARM specific flags in the ELF header. */
2190 static boolean
2191 elf32_arm_set_private_flags (abfd, flags)
2192 bfd *abfd;
2193 flagword flags;
2194 {
2195 if (elf_flags_init (abfd)
2196 && elf_elfheader (abfd)->e_flags != flags)
2197 {
2198 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
2199 {
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));
2204 else
2205 _bfd_error_handler (_("\
2206 Warning: Clearing the interworking flag of %s due to outside request"),
2207 bfd_archive_filename (abfd));
2208 }
2209 }
2210 else
2211 {
2212 elf_elfheader (abfd)->e_flags = flags;
2213 elf_flags_init (abfd) = true;
2214 }
2215
2216 return true;
2217 }
2218
2219 /* Copy backend specific data from one object module to another. */
2220
2221 static boolean
2222 elf32_arm_copy_private_bfd_data (ibfd, obfd)
2223 bfd *ibfd;
2224 bfd *obfd;
2225 {
2226 flagword in_flags;
2227 flagword out_flags;
2228
2229 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2230 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2231 return true;
2232
2233 in_flags = elf_elfheader (ibfd)->e_flags;
2234 out_flags = elf_elfheader (obfd)->e_flags;
2235
2236 if (elf_flags_init (obfd)
2237 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
2238 && in_flags != out_flags)
2239 {
2240 /* Cannot mix APCS26 and APCS32 code. */
2241 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
2242 return false;
2243
2244 /* Cannot mix float APCS and non-float APCS code. */
2245 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
2246 return false;
2247
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))
2251 {
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));
2257
2258 in_flags &= ~EF_ARM_INTERWORK;
2259 }
2260
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;
2264 }
2265
2266 elf_elfheader (obfd)->e_flags = in_flags;
2267 elf_flags_init (obfd) = true;
2268
2269 return true;
2270 }
2271
2272 /* Merge backend specific data from an object file to the output
2273 object file when linking. */
2274
2275 static boolean
2276 elf32_arm_merge_private_bfd_data (ibfd, obfd)
2277 bfd * ibfd;
2278 bfd * obfd;
2279 {
2280 flagword out_flags;
2281 flagword in_flags;
2282 boolean flags_compatible = true;
2283 boolean null_input_bfd = true;
2284 asection *sec;
2285
2286 /* Check if we have the same endianess. */
2287 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2288 return false;
2289
2290 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2291 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2292 return true;
2293
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)); */
2299
2300 in_flags = elf_elfheader (ibfd)->e_flags;
2301 out_flags = elf_elfheader (obfd)->e_flags;
2302
2303 if (!elf_flags_init (obfd))
2304 {
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)
2313 return true;
2314
2315 elf_flags_init (obfd) = true;
2316 elf_elfheader (obfd)->e_flags = in_flags;
2317
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));
2321
2322 return true;
2323 }
2324
2325 /* Identical flags must be compatible. */
2326 if (in_flags == out_flags)
2327 return true;
2328
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)
2333 {
2334 /* Ignore synthetic glue sections. */
2335 if (strcmp (sec->name, ".glue_7")
2336 && strcmp (sec->name, ".glue_7t"))
2337 {
2338 null_input_bfd = false;
2339 break;
2340 }
2341 }
2342 if (null_input_bfd)
2343 return true;
2344
2345 /* Complain about various flag mismatches. */
2346 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
2347 {
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);
2354 return false;
2355 }
2356
2357 /* Not sure what needs to be checked for EABI versions >= 1. */
2358 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
2359 {
2360 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
2361 {
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;
2369 }
2370
2371 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
2372 {
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));
2378 else
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));
2383
2384 flags_compatible = false;
2385 }
2386
2387 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
2388 {
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));
2394 else
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));
2399
2400 flags_compatible = false;
2401 }
2402
2403 #ifdef EF_ARM_SOFT_FLOAT
2404 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
2405 {
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
2410 flags. */
2411 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
2412 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
2413 {
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));
2419 else
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));
2424
2425 flags_compatible = false;
2426 }
2427 }
2428 #endif
2429
2430 /* Interworking mismatch is only a warning. */
2431 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
2432 {
2433 if (in_flags & EF_ARM_INTERWORK)
2434 {
2435 _bfd_error_handler (_("\
2436 Warning: %s supports interworking, whereas %s does not"),
2437 bfd_archive_filename (ibfd),
2438 bfd_get_filename (obfd));
2439 }
2440 else
2441 {
2442 _bfd_error_handler (_("\
2443 Warning: %s does not support interworking, whereas %s does"),
2444 bfd_archive_filename (ibfd),
2445 bfd_get_filename (obfd));
2446 }
2447 }
2448 }
2449
2450 return flags_compatible;
2451 }
2452
2453 /* Display the flags field. */
2454
2455 static boolean
2456 elf32_arm_print_private_bfd_data (abfd, ptr)
2457 bfd *abfd;
2458 PTR ptr;
2459 {
2460 FILE * file = (FILE *) ptr;
2461 unsigned long flags;
2462
2463 BFD_ASSERT (abfd != NULL && ptr != NULL);
2464
2465 /* Print normal ELF private data. */
2466 _bfd_elf_print_private_bfd_data (abfd, ptr);
2467
2468 flags = elf_elfheader (abfd)->e_flags;
2469 /* Ignore init flag - it may not be set, despite the flags field
2470 containing valid data. */
2471
2472 /* xgettext:c-format */
2473 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
2474
2475 switch (EF_ARM_EABI_VERSION (flags))
2476 {
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]"));
2483
2484 if (flags & EF_ARM_APCS_26)
2485 fprintf (file, " [APCS-26]");
2486 else
2487 fprintf (file, " [APCS-32]");
2488
2489 if (flags & EF_ARM_VFP_FLOAT)
2490 fprintf (file, _(" [VFP float format]"));
2491 else
2492 fprintf (file, _(" [FPA float format]"));
2493
2494 if (flags & EF_ARM_APCS_FLOAT)
2495 fprintf (file, _(" [floats passed in float registers]"));
2496
2497 if (flags & EF_ARM_PIC)
2498 fprintf (file, _(" [position independent]"));
2499
2500 if (flags & EF_ARM_NEW_ABI)
2501 fprintf (file, _(" [new ABI]"));
2502
2503 if (flags & EF_ARM_OLD_ABI)
2504 fprintf (file, _(" [old ABI]"));
2505
2506 if (flags & EF_ARM_SOFT_FLOAT)
2507 fprintf (file, _(" [software FP]"));
2508
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);
2512 break;
2513
2514 case EF_ARM_EABI_VER1:
2515 fprintf (file, _(" [Version1 EABI]"));
2516
2517 if (flags & EF_ARM_SYMSARESORTED)
2518 fprintf (file, _(" [sorted symbol table]"));
2519 else
2520 fprintf (file, _(" [unsorted symbol table]"));
2521
2522 flags &= ~ EF_ARM_SYMSARESORTED;
2523 break;
2524
2525 case EF_ARM_EABI_VER2:
2526 fprintf (file, _(" [Version2 EABI]"));
2527
2528 if (flags & EF_ARM_SYMSARESORTED)
2529 fprintf (file, _(" [sorted symbol table]"));
2530 else
2531 fprintf (file, _(" [unsorted symbol table]"));
2532
2533 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
2534 fprintf (file, _(" [dynamic symbols use segment index]"));
2535
2536 if (flags & EF_ARM_MAPSYMSFIRST)
2537 fprintf (file, _(" [mapping symbols precede others]"));
2538
2539 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
2540 | EF_ARM_MAPSYMSFIRST);
2541 break;
2542
2543 default:
2544 fprintf (file, _(" <EABI version unrecognised>"));
2545 break;
2546 }
2547
2548 flags &= ~ EF_ARM_EABIMASK;
2549
2550 if (flags & EF_ARM_RELEXEC)
2551 fprintf (file, _(" [relocatable executable]"));
2552
2553 if (flags & EF_ARM_HASENTRY)
2554 fprintf (file, _(" [has entry point]"));
2555
2556 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
2557
2558 if (flags)
2559 fprintf (file, _("<Unrecognised flag bits set>"));
2560
2561 fputc ('\n', file);
2562
2563 return true;
2564 }
2565
2566 static int
2567 elf32_arm_get_symbol_type (elf_sym, type)
2568 Elf_Internal_Sym * elf_sym;
2569 int type;
2570 {
2571 switch (ELF_ST_TYPE (elf_sym->st_info))
2572 {
2573 case STT_ARM_TFUNC:
2574 return ELF_ST_TYPE (elf_sym->st_info);
2575
2576 case STT_ARM_16BIT:
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
2580 executable. */
2581 if (type != STT_OBJECT)
2582 return ELF_ST_TYPE (elf_sym->st_info);
2583 break;
2584
2585 default:
2586 break;
2587 }
2588
2589 return type;
2590 }
2591
2592 static asection *
2593 elf32_arm_gc_mark_hook (sec, info, rel, h, sym)
2594 asection *sec;
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;
2599 {
2600 if (h != NULL)
2601 {
2602 switch (ELF32_R_TYPE (rel->r_info))
2603 {
2604 case R_ARM_GNU_VTINHERIT:
2605 case R_ARM_GNU_VTENTRY:
2606 break;
2607
2608 default:
2609 switch (h->root.type)
2610 {
2611 case bfd_link_hash_defined:
2612 case bfd_link_hash_defweak:
2613 return h->root.u.def.section;
2614
2615 case bfd_link_hash_common:
2616 return h->root.u.c.p->section;
2617
2618 default:
2619 break;
2620 }
2621 }
2622 }
2623 else
2624 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2625
2626 return NULL;
2627 }
2628
2629 /* Update the got entry reference counts for the section being removed. */
2630
2631 static boolean
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;
2637 {
2638 /* We don't support garbage collection of GOT and PLT relocs yet. */
2639 return true;
2640 }
2641
2642 /* Look through the relocs for a section during the first phase. */
2643
2644 static boolean
2645 elf32_arm_check_relocs (abfd, info, sec, relocs)
2646 bfd * abfd;
2647 struct bfd_link_info * info;
2648 asection * sec;
2649 const Elf_Internal_Rela * relocs;
2650 {
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;
2656 bfd * dynobj;
2657 asection * sgot, *srelgot, *sreloc;
2658 bfd_vma * local_got_offsets;
2659
2660 if (info->relocateable)
2661 return true;
2662
2663 sgot = srelgot = sreloc = NULL;
2664
2665 dynobj = elf_hash_table (info)->dynobj;
2666 local_got_offsets = elf_local_got_offsets (abfd);
2667
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);
2672
2673 if (!elf_bad_symtab (abfd))
2674 sym_hashes_end -= symtab_hdr->sh_info;
2675
2676 rel_end = relocs + sec->reloc_count;
2677 for (rel = relocs; rel < rel_end; rel++)
2678 {
2679 struct elf_link_hash_entry *h;
2680 unsigned long r_symndx;
2681
2682 r_symndx = ELF32_R_SYM (rel->r_info);
2683 if (r_symndx < symtab_hdr->sh_info)
2684 h = NULL;
2685 else
2686 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2687
2688 /* Some relocs require a global offset table. */
2689 if (dynobj == NULL)
2690 {
2691 switch (ELF32_R_TYPE (rel->r_info))
2692 {
2693 case R_ARM_GOT32:
2694 case R_ARM_GOTOFF:
2695 case R_ARM_GOTPC:
2696 elf_hash_table (info)->dynobj = dynobj = abfd;
2697 if (! _bfd_elf_create_got_section (dynobj, info))
2698 return false;
2699 break;
2700
2701 default:
2702 break;
2703 }
2704 }
2705
2706 switch (ELF32_R_TYPE (rel->r_info))
2707 {
2708 case R_ARM_GOT32:
2709 /* This symbol requires a global offset table entry. */
2710 if (sgot == NULL)
2711 {
2712 sgot = bfd_get_section_by_name (dynobj, ".got");
2713 BFD_ASSERT (sgot != NULL);
2714 }
2715
2716 /* Get the got relocation section if necessary. */
2717 if (srelgot == NULL
2718 && (h != NULL || info->shared))
2719 {
2720 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
2721
2722 /* If no got relocation section, make one and initialize. */
2723 if (srelgot == NULL)
2724 {
2725 srelgot = bfd_make_section (dynobj, ".rel.got");
2726 if (srelgot == NULL
2727 || ! bfd_set_section_flags (dynobj, srelgot,
2728 (SEC_ALLOC
2729 | SEC_LOAD
2730 | SEC_HAS_CONTENTS
2731 | SEC_IN_MEMORY
2732 | SEC_LINKER_CREATED
2733 | SEC_READONLY))
2734 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2735 return false;
2736 }
2737 }
2738
2739 if (h != NULL)
2740 {
2741 if (h->got.offset != (bfd_vma) -1)
2742 /* We have already allocated space in the .got. */
2743 break;
2744
2745 h->got.offset = sgot->_raw_size;
2746
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))
2750 return false;
2751
2752 srelgot->_raw_size += sizeof (Elf32_External_Rel);
2753 }
2754 else
2755 {
2756 /* This is a global offset table entry for a local
2757 symbol. */
2758 if (local_got_offsets == NULL)
2759 {
2760 bfd_size_type size;
2761 unsigned int i;
2762
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)
2767 return false;
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;
2771 }
2772
2773 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
2774 /* We have already allocated space in the .got. */
2775 break;
2776
2777 local_got_offsets[r_symndx] = sgot->_raw_size;
2778
2779 if (info->shared)
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);
2784 }
2785
2786 sgot->_raw_size += 4;
2787 break;
2788
2789 case R_ARM_PLT32:
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
2795 after all. */
2796
2797 /* If this is a local symbol, we resolve it directly without
2798 creating a procedure linkage table entry. */
2799 if (h == NULL)
2800 continue;
2801
2802 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2803 {
2804 struct elf32_arm_link_hash_entry *eh;
2805
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;
2809 }
2810 break;
2811
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))
2820 {
2821 struct elf32_arm_link_hash_entry *eh;
2822
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;
2827 }
2828 break;
2829
2830 case R_ARM_ABS32:
2831 case R_ARM_REL32:
2832 case R_ARM_PC24:
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. */
2845 if (info->shared
2846 && (ELF32_R_TYPE (rel->r_info) != R_ARM_PC24
2847 || (h != NULL
2848 && (! info->symbolic
2849 || (h->elf_link_hash_flags
2850 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2851 {
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. */
2855 if (sreloc == NULL)
2856 {
2857 const char * name;
2858
2859 name = (bfd_elf_string_from_elf_section
2860 (abfd,
2861 elf_elfheader (abfd)->e_shstrndx,
2862 elf_section_data (sec)->rel_hdr.sh_name));
2863 if (name == NULL)
2864 return false;
2865
2866 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2867 && strcmp (bfd_get_section_name (abfd, sec),
2868 name + 4) == 0);
2869
2870 sreloc = bfd_get_section_by_name (dynobj, name);
2871 if (sreloc == NULL)
2872 {
2873 flagword flags;
2874
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;
2880 if (sreloc == NULL
2881 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2882 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
2883 return false;
2884 }
2885 if (sec->flags & SEC_READONLY)
2886 info->flags |= DF_TEXTREL;
2887 }
2888
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)
2900 {
2901 struct elf32_arm_link_hash_entry * eh;
2902 struct elf32_arm_pcrel_relocs_copied * p;
2903
2904 eh = (struct elf32_arm_link_hash_entry *) h;
2905
2906 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
2907 if (p->section == sreloc)
2908 break;
2909
2910 if (p == NULL)
2911 {
2912 p = ((struct elf32_arm_pcrel_relocs_copied *)
2913 bfd_alloc (dynobj, (bfd_size_type) sizeof * p));
2914 if (p == NULL)
2915 return false;
2916 p->next = eh->pcrel_relocs_copied;
2917 eh->pcrel_relocs_copied = p;
2918 p->section = sreloc;
2919 p->count = 0;
2920 }
2921
2922 ++p->count;
2923 }
2924 }
2925 break;
2926
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))
2931 return false;
2932 break;
2933
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))
2938 return false;
2939 break;
2940 }
2941 }
2942
2943 return true;
2944 }
2945
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. */
2949
2950 static boolean
2951 elf32_arm_find_nearest_line
2952 (abfd, section, symbols, offset, filename_ptr, functionname_ptr, line_ptr)
2953 bfd * abfd;
2954 asection * section;
2955 asymbol ** symbols;
2956 bfd_vma offset;
2957 const char ** filename_ptr;
2958 const char ** functionname_ptr;
2959 unsigned int * line_ptr;
2960 {
2961 boolean found;
2962 const char * filename;
2963 asymbol * func;
2964 bfd_vma low_func;
2965 asymbol ** p;
2966
2967 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
2968 filename_ptr, functionname_ptr,
2969 line_ptr, 0,
2970 &elf_tdata (abfd)->dwarf2_find_line_info))
2971 return true;
2972
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))
2977 return false;
2978
2979 if (found)
2980 return true;
2981
2982 if (symbols == NULL)
2983 return false;
2984
2985 filename = NULL;
2986 func = NULL;
2987 low_func = 0;
2988
2989 for (p = symbols; *p != NULL; p++)
2990 {
2991 elf_symbol_type *q;
2992
2993 q = (elf_symbol_type *) *p;
2994
2995 if (bfd_get_section (&q->symbol) != section)
2996 continue;
2997
2998 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
2999 {
3000 default:
3001 break;
3002 case STT_FILE:
3003 filename = bfd_asymbol_name (&q->symbol);
3004 break;
3005 case STT_NOTYPE:
3006 case STT_FUNC:
3007 case STT_ARM_TFUNC:
3008 if (q->symbol.section == section
3009 && q->symbol.value >= low_func
3010 && q->symbol.value <= offset)
3011 {
3012 func = (asymbol *) q;
3013 low_func = q->symbol.value;
3014 }
3015 break;
3016 }
3017 }
3018
3019 if (func == NULL)
3020 return false;
3021
3022 *filename_ptr = filename;
3023 *functionname_ptr = bfd_asymbol_name (func);
3024 *line_ptr = 0;
3025
3026 return true;
3027 }
3028
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
3033 understand. */
3034
3035 static boolean
3036 elf32_arm_adjust_dynamic_symbol (info, h)
3037 struct bfd_link_info * info;
3038 struct elf_link_hash_entry * h;
3039 {
3040 bfd * dynobj;
3041 asection * s;
3042 unsigned int power_of_two;
3043
3044 dynobj = elf_hash_table (info)->dynobj;
3045
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)));
3056
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)
3062 {
3063 struct elf32_arm_plt_entry_info *plt_info;
3064
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));
3069
3070 if (! info->shared
3071 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3072 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
3073 {
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
3078 reloc instead. */
3079 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
3080 return true;
3081 }
3082
3083 /* Make sure this symbol is output as a dynamic symbol. */
3084 if (h->dynindx == -1)
3085 {
3086 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
3087 return false;
3088 }
3089
3090 s = bfd_get_section_by_name (dynobj,
3091 plt_info->arm_plt ? ".plt" : ".plt.thumb");
3092 BFD_ASSERT (s != NULL);
3093
3094 /* If this is the first PLT entry, make room for the special
3095 first entry. */
3096 if (s->_raw_size == 0)
3097 s->_raw_size += PLT_ENTRY_SIZE (plt_info->arm_plt);
3098
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. */
3104 if (! info->shared
3105 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3106 {
3107 h->root.u.def.section = s;
3108 h->root.u.def.value = s->_raw_size;
3109 }
3110
3111 h->plt.offset = s->_raw_size;
3112
3113 /* Make room for this entry. */
3114 s->_raw_size += PLT_ENTRY_SIZE (plt_info->arm_plt);
3115
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;
3121 s->_raw_size += 4;
3122
3123 /* We also need to make an entry in the .rel.plt section. */
3124
3125 s = bfd_get_section_by_name (dynobj, ".rel.plt");
3126 BFD_ASSERT (s != NULL);
3127 s->_raw_size += sizeof (Elf32_External_Rel);
3128
3129 return true;
3130 }
3131
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)
3136 {
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;
3141 return true;
3142 }
3143
3144 /* This is a reference to a symbol defined by a dynamic object which
3145 is not a function. */
3146
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. */
3151 if (info->shared)
3152 return true;
3153
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);
3165
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)
3171 {
3172 asection *srel;
3173
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;
3178 }
3179
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)
3184 power_of_two = 3;
3185
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))
3190 {
3191 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
3192 return false;
3193 }
3194
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;
3198
3199 /* Increment the section size to make room for the symbol. */
3200 s->_raw_size += h->size;
3201
3202 return true;
3203 }
3204
3205 /* Set the sizes of the dynamic sections. */
3206
3207 static boolean
3208 elf32_arm_size_dynamic_sections (output_bfd, info)
3209 bfd * output_bfd ATTRIBUTE_UNUSED;
3210 struct bfd_link_info * info;
3211 {
3212 bfd * dynobj;
3213 asection * s;
3214 boolean plt;
3215 boolean relocs;
3216
3217 dynobj = elf_hash_table (info)->dynobj;
3218 BFD_ASSERT (dynobj != NULL);
3219
3220 if (elf_hash_table (info)->dynamic_sections_created)
3221 {
3222 /* Set the contents of the .interp section to the interpreter. */
3223 if (! info->shared)
3224 {
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;
3229 }
3230 }
3231 else
3232 {
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
3237 below. */
3238 s = bfd_get_section_by_name (dynobj, ".rel.got");
3239 if (s != NULL)
3240 s->_raw_size = 0;
3241 }
3242
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,
3250 (PTR) NULL);
3251
3252 /* The check_relocs and adjust_dynamic_symbol entry points have
3253 determined the sizes of the various dynamic sections. Allocate
3254 memory for them. */
3255 plt = false;
3256 relocs = false;
3257 for (s = dynobj->sections; s != NULL; s = s->next)
3258 {
3259 const char * name;
3260 boolean strip;
3261
3262 if ((s->flags & SEC_LINKER_CREATED) == 0)
3263 continue;
3264
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);
3268
3269 strip = false;
3270
3271 /* Match .plt.thumb as well. */
3272 if (strncmp (name, ".plt", 4) == 0)
3273 {
3274 if (s->_raw_size == 0)
3275 {
3276 /* Strip this section if we don't need it; see the
3277 comment below. */
3278 strip = true;
3279 }
3280 else
3281 {
3282 /* Remember whether there is a PLT. */
3283 plt = true;
3284 }
3285 }
3286 else if (strncmp (name, ".rel", 4) == 0)
3287 {
3288 if (s->_raw_size == 0)
3289 {
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. */
3299 strip = true;
3300 }
3301 else
3302 {
3303 /* Remember whether there are any reloc sections other
3304 than .rel.plt. */
3305 if (strcmp (name, ".rel.plt") != 0)
3306 relocs = true;
3307
3308 /* We use the reloc_count field as a counter if we need
3309 to copy relocs into the output file. */
3310 s->reloc_count = 0;
3311 }
3312 }
3313 else if (strncmp (name, ".got", 4) != 0)
3314 {
3315 /* It's not one of our sections, so don't allocate space. */
3316 continue;
3317 }
3318
3319 if (strip)
3320 {
3321 asection ** spp;
3322
3323 for (spp = &s->output_section->owner->sections;
3324 *spp != NULL;
3325 spp = &(*spp)->next)
3326 {
3327 if (*spp == s->output_section)
3328 {
3329 bfd_section_list_remove (s->output_section->owner, spp);
3330 --s->output_section->owner->section_count;
3331 break;
3332 }
3333 }
3334 continue;
3335 }
3336
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)
3340 return false;
3341 }
3342
3343 if (elf_hash_table (info)->dynamic_sections_created)
3344 {
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))
3352
3353 if (!info->shared)
3354 {
3355 if (!add_dynamic_entry (DT_DEBUG, 0))
3356 return false;
3357 }
3358
3359 if (plt)
3360 {
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))
3365 return false;
3366 }
3367
3368 if (relocs)
3369 {
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)))
3373 return false;
3374 }
3375
3376 if ((info->flags & DF_TEXTREL) != 0)
3377 {
3378 if (!add_dynamic_entry (DT_TEXTREL, 0))
3379 return false;
3380 info->flags |= DF_TEXTREL;
3381 }
3382 }
3383 #undef add_synamic_entry
3384
3385 return true;
3386 }
3387
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. */
3394
3395 static boolean
3396 elf32_arm_discard_copies (h, ignore)
3397 struct elf32_arm_link_hash_entry * h;
3398 PTR ignore ATTRIBUTE_UNUSED;
3399 {
3400 struct elf32_arm_pcrel_relocs_copied * s;
3401
3402 if (h->root.root.type == bfd_link_hash_warning)
3403 h = (struct elf32_arm_link_hash_entry *) h->root.root.u.i.link;
3404
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)
3407 return true;
3408
3409 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
3410 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rel);
3411
3412 return true;
3413 }
3414
3415 /* Finish up dynamic symbol handling. We set the contents of various
3416 dynamic sections here. */
3417
3418 static boolean
3419 elf32_arm_finish_dynamic_symbol (output_bfd, info, h, sym)
3420 bfd * output_bfd;
3421 struct bfd_link_info * info;
3422 struct elf_link_hash_entry * h;
3423 Elf_Internal_Sym * sym;
3424 {
3425 bfd * dynobj;
3426
3427 dynobj = elf_hash_table (info)->dynobj;
3428
3429 if (h->plt.offset != (bfd_vma) -1)
3430 {
3431 asection * splt;
3432 asection * splt_thumb;
3433 asection * sgot;
3434 asection * srel;
3435 bfd_vma rel_index;
3436 Elf_Internal_Rel rel;
3437 struct elf32_arm_plt_entry_info *plt_info;
3438
3439 /* This symbol has an entry in the procedure linkage table. Set
3440 it up. */
3441
3442 BFD_ASSERT (h->dynindx != -1);
3443
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
3449 && srel != NULL);
3450
3451 plt_info = &((struct elf32_arm_link_hash_entry *) h)->plt_info;
3452
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;
3456
3457 /* Fill in the entry in the procedure linkage table. */
3458
3459 if (plt_info->arm_plt)
3460 {
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);
3467
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);
3476
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);
3482 }
3483 else
3484 {
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);
3501
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);
3510
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);
3517 }
3518
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
3526 + rel_index));
3527
3528 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3529 {
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)
3538 == 0)
3539 sym->st_value = 0;
3540 }
3541 }
3542
3543 if (h->got.offset != (bfd_vma) -1)
3544 {
3545 asection * sgot;
3546 asection * srel;
3547 Elf_Internal_Rel rel;
3548
3549 /* This symbol has an entry in the global offset table. Set it
3550 up. */
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);
3554
3555 rel.r_offset = (sgot->output_section->vma
3556 + sgot->output_offset
3557 + (h->got.offset &~ (bfd_vma) 1));
3558
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. */
3563 if (info->shared
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);
3567 else
3568 {
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);
3571 }
3572
3573 bfd_elf32_swap_reloc_out (output_bfd, &rel,
3574 ((Elf32_External_Rel *) srel->contents
3575 + srel->reloc_count));
3576 ++srel->reloc_count;
3577 }
3578
3579 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
3580 {
3581 asection * s;
3582 Elf_Internal_Rel rel;
3583
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));
3588
3589 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3590 ".rel.bss");
3591 BFD_ASSERT (s != NULL);
3592
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
3599 + s->reloc_count));
3600 ++s->reloc_count;
3601 }
3602
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;
3607
3608 return true;
3609 }
3610
3611 /* Finish up the dynamic sections. */
3612
3613 static boolean
3614 elf32_arm_finish_dynamic_sections (output_bfd, info)
3615 bfd * output_bfd;
3616 struct bfd_link_info * info;
3617 {
3618 bfd * dynobj;
3619 asection * sgot;
3620 asection * sdyn;
3621
3622 dynobj = elf_hash_table (info)->dynobj;
3623
3624 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3625 BFD_ASSERT (sgot != NULL);
3626 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3627
3628 if (elf_hash_table (info)->dynamic_sections_created)
3629 {
3630 asection *splt;
3631 asection *splt_thumb;
3632 Elf32_External_Dyn *dyncon, *dynconend;
3633
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);
3637
3638 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3639 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3640
3641 for (; dyncon < dynconend; dyncon++)
3642 {
3643 Elf_Internal_Dyn dyn;
3644 const char * name;
3645 asection * s;
3646
3647 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3648
3649 switch (dyn.d_tag)
3650 {
3651 default:
3652 break;
3653
3654 case DT_PLTGOT:
3655 name = ".got";
3656 goto get_vma;
3657 case DT_JMPREL:
3658 name = ".rel.plt";
3659 get_vma:
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);
3664 break;
3665
3666 case DT_PLTRELSZ:
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;
3671 else
3672 dyn.d_un.d_val = s->_raw_size;
3673 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3674 break;
3675
3676 case DT_RELSZ:
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");
3687 if (s != NULL)
3688 {
3689 if (s->_cooked_size != 0)
3690 dyn.d_un.d_val -= s->_cooked_size;
3691 else
3692 dyn.d_un.d_val -= s->_raw_size;
3693 }
3694 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3695 break;
3696 }
3697 }
3698
3699 /* Fill in the first entries in the procedure linkage tables. */
3700 if (splt->_raw_size > 0)
3701 {
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);
3706 }
3707 if (splt_thumb->_raw_size > 0)
3708 {
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);
3729 }
3730
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;
3734 }
3735
3736 /* Fill in the first three entries in the global offset table. */
3737 if (sgot->_raw_size > 0)
3738 {
3739 if (sdyn == NULL)
3740 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3741 else
3742 bfd_put_32 (output_bfd,
3743 sdyn->output_section->vma + sdyn->output_offset,
3744 sgot->contents);
3745 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
3746 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3747 }
3748
3749 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3750
3751 return true;
3752 }
3753
3754 static void
3755 elf32_arm_post_process_headers (abfd, link_info)
3756 bfd * abfd;
3757 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
3758 {
3759 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
3760
3761 i_ehdrp = elf_elfheader (abfd);
3762
3763 i_ehdrp->e_ident[EI_OSABI] = ARM_ELF_OS_ABI_VERSION;
3764 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
3765 }
3766
3767 static enum elf_reloc_type_class
3768 elf32_arm_reloc_type_class (rela)
3769 const Elf_Internal_Rela *rela;
3770 {
3771 switch ((int) ELF32_R_TYPE (rela->r_info))
3772 {
3773 case R_ARM_RELATIVE:
3774 return reloc_class_relative;
3775 case R_ARM_JUMP_SLOT:
3776 return reloc_class_plt;
3777 case R_ARM_COPY:
3778 return reloc_class_copy;
3779 default:
3780 return reloc_class_normal;
3781 }
3782 }
3783
3784 boolean
3785 elf32_arm_create_dynamic_sections (abfd, info)
3786 bfd *abfd;
3787 struct bfd_link_info *info;
3788 {
3789 boolean ret;
3790
3791 ret = _bfd_elf_create_dynamic_sections (abfd, info);
3792 if (ret)
3793 {
3794 asection *splt;
3795 asection *splt_thumb;
3796 flagword flags;
3797 unsigned int alignent_power;
3798
3799 /* Let's match the attributes of .plt. */
3800 splt = bfd_get_section_by_name (abfd, ".plt");
3801 BFD_ASSERT (splt != NULL);
3802
3803 flags = bfd_get_section_flags (abfd, splt);
3804 alignent_power = bfd_get_section_alignment (abfd, splt);
3805
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))
3810 return false;
3811 }
3812 return ret;
3813 }
3814
3815 #define ELF_ARCH bfd_arch_arm
3816 #define ELF_MACHINE_CODE EM_ARM
3817 #ifndef ELF_MAXPAGESIZE
3818 #define ELF_MAXPAGESIZE 0x8000
3819 #endif
3820
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
3828
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
3841
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
3846 #ifndef USE_REL
3847 #define elf_backend_rela_normal 1
3848 #endif
3849
3850 #define elf_backend_got_header_size 12
3851 #define elf_backend_plt_header_size ARM_PLT_ENTRY_SIZE
3852
3853 #include "elf32-target.h"
3854
This page took 0.156931 seconds and 5 git commands to generate.