Add interworking support (untested) to pe backends.
[binutils-gdb.git] / bfd / coff-arm.c
1 /* BFD back-end for ARM COFF files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24
25 #include "coff/arm.h"
26
27 #include "coff/internal.h"
28
29 #ifdef COFF_WITH_PE
30 #include "coff/pe.h"
31 #endif
32
33 #include "libcoff.h"
34
35 #define APCS_26_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_26)
36 #define APCS_FLOAT_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_FLOAT)
37 #define PIC_FLAG( abfd ) (coff_data (abfd)->flags & F_PIC)
38 #define APCS_SET( abfd ) (coff_data (abfd)->flags & F_APCS_SET)
39 #define SET_APCS_FLAGS( abfd, flgs) (coff_data (abfd)->flags = \
40 (coff_data (abfd)->flags & ~ (F_APCS_26 | F_APCS_FLOAT | F_PIC)) \
41 | (flgs | F_APCS_SET))
42 #define INTERWORK_FLAG( abfd ) (coff_data (abfd)->flags & F_INTERWORK)
43 #define INTERWORK_SET( abfd ) (coff_data (abfd)->flags & F_INTERWORK_SET)
44 #define SET_INTERWORK_FLAG( abfd, flg ) (coff_data (abfd)->flags = \
45 (coff_data (abfd)->flags & ~ F_INTERWORK) \
46 | (flg | F_INTERWORK_SET))
47
48
49 static boolean coff_arm_relocate_section
50 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
51 struct internal_reloc *, struct internal_syment *, asection **));
52
53 static bfd_reloc_status_type
54 aoutarm_fix_pcrel_26_done PARAMS ((bfd *, arelent *, asymbol *, PTR,
55 asection *, bfd *, char **));
56
57 static bfd_reloc_status_type
58 aoutarm_fix_pcrel_26 PARAMS ((bfd *, arelent *, asymbol *, PTR,
59 asection *, bfd *, char **));
60
61 static bfd_reloc_status_type
62 coff_thumb_pcrel_23 PARAMS ((bfd *, arelent *, asymbol *, PTR,
63 asection *, bfd *, char **));
64
65 static bfd_reloc_status_type
66 coff_thumb_pcrel_12 PARAMS ((bfd *, arelent *, asymbol *, PTR,
67 asection *, bfd *, char **));
68
69 static bfd_reloc_status_type
70 coff_thumb_pcrel_9 PARAMS ((bfd *, arelent *, asymbol *, PTR,
71 asection *, bfd *, char **));
72
73 static bfd_reloc_status_type
74 coff_arm_reloc PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *,
75 char **));
76
77 static boolean
78 coff_arm_adjust_symndx PARAMS ((bfd *, struct bfd_link_info *, bfd *,
79 asection *, struct internal_reloc *,
80 boolean *));
81
82 /* The linker script knows the section names for placement.
83 The entry_names are used to do simple name mangling on the stubs.
84 Given a function name, and its type, the stub can be found. The
85 name can be changed. The only requirement is the %s be present.
86 */
87
88 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
89 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
90
91 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
92 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
93
94 /* Used by the assembler. */
95 static bfd_reloc_status_type
96 coff_arm_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
97 error_message)
98 bfd *abfd;
99 arelent *reloc_entry;
100 asymbol *symbol;
101 PTR data;
102 asection *input_section;
103 bfd *output_bfd;
104 char **error_message;
105 {
106 symvalue diff;
107 if (output_bfd == (bfd *) NULL)
108 return bfd_reloc_continue;
109
110 diff = reloc_entry->addend;
111
112 #define DOIT(x) \
113 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
114
115 if (diff != 0)
116 {
117 reloc_howto_type *howto = reloc_entry->howto;
118 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
119
120 switch (howto->size)
121 {
122 case 0:
123 {
124 char x = bfd_get_8 (abfd, addr);
125 DOIT (x);
126 bfd_put_8 (abfd, x, addr);
127 }
128 break;
129
130 case 1:
131 {
132 short x = bfd_get_16 (abfd, addr);
133 DOIT (x);
134 bfd_put_16 (abfd, x, addr);
135 }
136 break;
137
138 case 2:
139 {
140 long x = bfd_get_32 (abfd, addr);
141 DOIT (x);
142 bfd_put_32 (abfd, x, addr);
143 }
144 break;
145
146 default:
147 abort ();
148 }
149 }
150
151 /* Now let bfd_perform_relocation finish everything up. */
152 return bfd_reloc_continue;
153 }
154
155 #define TARGET_UNDERSCORE '_'
156
157 #ifndef PCRELOFFSET
158 #define PCRELOFFSET true
159 #endif
160
161 /* These most certainly belong somewhere else. Just had to get rid of
162 the manifest constants in the code. */
163
164 #define ARM_8 0
165 #define ARM_16 1
166 #define ARM_32 2
167 #define ARM_26 3
168 #define ARM_DISP8 4
169 #define ARM_DISP16 5
170 #define ARM_DISP32 6
171 #define ARM_26D 7
172 /* 8 is unused */
173 #define ARM_NEG16 9
174 #define ARM_NEG32 10
175 #define ARM_RVA32 11
176 #define ARM_THUMB9 12
177 #define ARM_THUMB12 13
178 #define ARM_THUMB23 14
179
180 static reloc_howto_type aoutarm_std_reloc_howto[] =
181 {
182 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
183 HOWTO(ARM_8, /* type */
184 0, /* rightshift */
185 0, /* size */
186 8, /* bitsize */
187 false, /* pc_relative */
188 0, /* bitpos */
189 complain_overflow_bitfield, /* complain_on_overflow */
190 coff_arm_reloc, /* special_function */
191 "ARM_8", /* name */
192 true, /* partial_inplace */
193 0x000000ff, /* src_mask */
194 0x000000ff, /* dst_mask */
195 PCRELOFFSET /* pcrel_offset */),
196 HOWTO(ARM_16,
197 0,
198 1,
199 16,
200 false,
201 0,
202 complain_overflow_bitfield,
203 coff_arm_reloc,
204 "ARM_16",
205 true,
206 0x0000ffff,
207 0x0000ffff,
208 PCRELOFFSET),
209 HOWTO(ARM_32,
210 0,
211 2,
212 32,
213 false,
214 0,
215 complain_overflow_bitfield,
216 coff_arm_reloc,
217 "ARM_32",
218 true,
219 0xffffffff,
220 0xffffffff,
221 PCRELOFFSET),
222 HOWTO(ARM_26,
223 2,
224 2,
225 24,
226 true,
227 0,
228 complain_overflow_signed,
229 aoutarm_fix_pcrel_26 ,
230 "ARM_26",
231 false,
232 0x00ffffff,
233 0x00ffffff,
234 PCRELOFFSET),
235 HOWTO(ARM_DISP8,
236 0,
237 0,
238 8,
239 true,
240 0,
241 complain_overflow_signed,
242 coff_arm_reloc,
243 "ARM_DISP8",
244 true,
245 0x000000ff,
246 0x000000ff,
247 true),
248 HOWTO( ARM_DISP16,
249 0,
250 1,
251 16,
252 true,
253 0,
254 complain_overflow_signed,
255 coff_arm_reloc,
256 "ARM_DISP16",
257 true,
258 0x0000ffff,
259 0x0000ffff,
260 true),
261 HOWTO( ARM_DISP32,
262 0,
263 2,
264 32,
265 true,
266 0,
267 complain_overflow_signed,
268 coff_arm_reloc,
269 "ARM_DISP32",
270 true,
271 0xffffffff,
272 0xffffffff,
273 true),
274 HOWTO( ARM_26D,
275 2,
276 2,
277 24,
278 false,
279 0,
280 complain_overflow_signed,
281 aoutarm_fix_pcrel_26_done,
282 "ARM_26D",
283 true,
284 0x00ffffff,
285 0x0,
286 false),
287 /* 8 is unused */
288 {-1},
289 HOWTO( ARM_NEG16,
290 0,
291 -1,
292 16,
293 false,
294 0,
295 complain_overflow_bitfield,
296 coff_arm_reloc,
297 "ARM_NEG16",
298 true,
299 0x0000ffff,
300 0x0000ffff,
301 false),
302 HOWTO( ARM_NEG32,
303 0,
304 -2,
305 32,
306 false,
307 0,
308 complain_overflow_bitfield,
309 coff_arm_reloc,
310 "ARM_NEG32",
311 true,
312 0xffffffff,
313 0xffffffff,
314 false),
315 HOWTO( ARM_RVA32,
316 0,
317 2,
318 32,
319 false,
320 0,
321 complain_overflow_bitfield,
322 coff_arm_reloc,
323 "ARM_RVA32",
324 true,
325 0xffffffff,
326 0xffffffff,
327 PCRELOFFSET),
328 HOWTO( ARM_THUMB9,
329 1,
330 1,
331 8,
332 true,
333 0,
334 complain_overflow_signed,
335 coff_thumb_pcrel_9 ,
336 "ARM_THUMB9",
337 false,
338 0x000000ff,
339 0x000000ff,
340 PCRELOFFSET),
341 HOWTO( ARM_THUMB12,
342 1,
343 1,
344 11,
345 true,
346 0,
347 complain_overflow_signed,
348 coff_thumb_pcrel_12 ,
349 "ARM_THUMB12",
350 false,
351 0x000007ff,
352 0x000007ff,
353 PCRELOFFSET),
354 HOWTO( ARM_THUMB23,
355 1,
356 2,
357 22,
358 true,
359 0,
360 complain_overflow_signed,
361 coff_thumb_pcrel_23 ,
362 "ARM_THUMB23",
363 false,
364 0x07ff07ff,
365 0x07ff07ff,
366 PCRELOFFSET),
367 };
368 #ifdef COFF_WITH_PE
369 /* Return true if this relocation should
370 appear in the output .reloc section. */
371
372 static boolean in_reloc_p (abfd, howto)
373 bfd * abfd;
374 reloc_howto_type *howto;
375 {
376 return !howto->pc_relative && howto->type != 11;
377 }
378 #endif
379
380
381 #define RTYPE2HOWTO(cache_ptr, dst) \
382 (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
383
384 #define coff_rtype_to_howto coff_arm_rtype_to_howto
385
386 static reloc_howto_type *
387 coff_arm_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
388 bfd *abfd;
389 asection *sec;
390 struct internal_reloc *rel;
391 struct coff_link_hash_entry *h;
392 struct internal_syment *sym;
393 bfd_vma *addendp;
394 {
395 reloc_howto_type *howto;
396
397 howto = aoutarm_std_reloc_howto + rel->r_type;
398
399 if (rel->r_type == ARM_RVA32)
400 {
401 *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
402 }
403
404 /* The relocation_section function will skip pcrel_offset relocs
405 when doing a relocateable link. However, we want to convert
406 ARM26 to ARM26D relocs if possible. We return a fake howto in
407 this case without pcrel_offset set, and adjust the addend to
408 compensate. */
409 if (rel->r_type == ARM_26
410 && h != NULL
411 && (h->root.type == bfd_link_hash_defined
412 || h->root.type == bfd_link_hash_defweak)
413 && h->root.u.def.section->output_section == sec->output_section)
414 {
415 static reloc_howto_type fake_arm26_reloc =
416 HOWTO (ARM_26,
417 2,
418 2,
419 24,
420 true,
421 0,
422 complain_overflow_signed,
423 aoutarm_fix_pcrel_26 ,
424 "ARM_26",
425 false,
426 0x00ffffff,
427 0x00ffffff,
428 false);
429
430 *addendp -= rel->r_vaddr - sec->vma;
431 return & fake_arm26_reloc;
432 }
433
434 return howto;
435
436 }
437 /* Used by the assembler. */
438
439 static bfd_reloc_status_type
440 aoutarm_fix_pcrel_26_done (abfd, reloc_entry, symbol, data, input_section,
441 output_bfd, error_message)
442 bfd *abfd;
443 arelent *reloc_entry;
444 asymbol *symbol;
445 PTR data;
446 asection *input_section;
447 bfd *output_bfd;
448 char **error_message;
449 {
450 /* This is dead simple at present. */
451 return bfd_reloc_ok;
452 }
453
454 /* Used by the assembler. */
455
456 static bfd_reloc_status_type
457 aoutarm_fix_pcrel_26 (abfd, reloc_entry, symbol, data, input_section,
458 output_bfd, error_message)
459 bfd *abfd;
460 arelent *reloc_entry;
461 asymbol *symbol;
462 PTR data;
463 asection *input_section;
464 bfd *output_bfd;
465 char **error_message;
466 {
467 bfd_vma relocation;
468 bfd_size_type addr = reloc_entry->address;
469 long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
470 bfd_reloc_status_type flag = bfd_reloc_ok;
471
472 /* If this is an undefined symbol, return error */
473 if (symbol->section == &bfd_und_section
474 && (symbol->flags & BSF_WEAK) == 0)
475 return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
476
477 /* If the sections are different, and we are doing a partial relocation,
478 just ignore it for now. */
479 if (symbol->section->name != input_section->name
480 && output_bfd != (bfd *)NULL)
481 return bfd_reloc_continue;
482
483 relocation = (target & 0x00ffffff) << 2;
484 relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend */
485 relocation += symbol->value;
486 relocation += symbol->section->output_section->vma;
487 relocation += symbol->section->output_offset;
488 relocation += reloc_entry->addend;
489 relocation -= input_section->output_section->vma;
490 relocation -= input_section->output_offset;
491 relocation -= addr;
492
493 if (relocation & 3)
494 return bfd_reloc_overflow;
495
496 /* Check for overflow */
497 if (relocation & 0x02000000)
498 {
499 if ((relocation & ~0x03ffffff) != ~0x03ffffff)
500 flag = bfd_reloc_overflow;
501 }
502 else if (relocation & ~0x03ffffff)
503 flag = bfd_reloc_overflow;
504
505 target &= ~0x00ffffff;
506 target |= (relocation >> 2) & 0x00ffffff;
507 bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
508
509 /* Now the ARM magic... Change the reloc type so that it is marked as done.
510 Strictly this is only necessary if we are doing a partial relocation. */
511 reloc_entry->howto = &aoutarm_std_reloc_howto[ARM_26D];
512
513 return flag;
514 }
515
516 typedef enum {bunknown, b9, b12, b23} thumb_pcrel_branchtype;
517
518 static bfd_reloc_status_type
519 coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, input_section,
520 output_bfd, error_message, btype)
521 bfd *abfd;
522 arelent *reloc_entry;
523 asymbol *symbol;
524 PTR data;
525 asection *input_section;
526 bfd *output_bfd;
527 char **error_message;
528 thumb_pcrel_branchtype btype;
529 {
530 bfd_vma relocation;
531 bfd_size_type addr = reloc_entry->address;
532 long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
533 bfd_reloc_status_type flag = bfd_reloc_ok;
534 bfd_vma dstmsk;
535 bfd_vma offmsk;
536 bfd_vma signbit;
537
538 /* NOTE: This routine is currently used by GAS, but not by the link
539 phase. */
540
541 switch (btype)
542 {
543 case b9:
544 dstmsk = 0x000000ff;
545 offmsk = 0x000001fe;
546 signbit = 0x00000100;
547 break;
548
549 case b12:
550 dstmsk = 0x000007ff;
551 offmsk = 0x00000ffe;
552 signbit = 0x00000800;
553 break;
554
555 case b23:
556 dstmsk = 0x07ff07ff;
557 offmsk = 0x007fffff;
558 signbit = 0x00400000;
559 break;
560
561 default:
562 abort ();
563 }
564
565 /* If this is an undefined symbol, return error */
566 if (symbol->section == &bfd_und_section
567 && (symbol->flags & BSF_WEAK) == 0)
568 return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
569
570 /* If the sections are different, and we are doing a partial relocation,
571 just ignore it for now. */
572 if (symbol->section->name != input_section->name
573 && output_bfd != (bfd *)NULL)
574 return bfd_reloc_continue;
575
576 switch (btype)
577 {
578 case b9:
579 case b12:
580 relocation = ((target & dstmsk) << 1);
581 break;
582
583 case b23:
584 if (bfd_big_endian (abfd))
585 relocation = ((target & 0x7ff) << 1) | ((target & 0x07ff0000) >> 4);
586 else
587 relocation = ((target & 0x7ff) << 12) | ((target & 0x07ff0000) >> 15);
588 break;
589 }
590
591 relocation = (relocation ^ signbit) - signbit; /* Sign extend */
592 relocation += symbol->value;
593 relocation += symbol->section->output_section->vma;
594 relocation += symbol->section->output_offset;
595 relocation += reloc_entry->addend;
596 relocation -= input_section->output_section->vma;
597 relocation -= input_section->output_offset;
598 relocation -= addr;
599
600 if (relocation & 1)
601 return bfd_reloc_overflow;
602
603 /* Check for overflow */
604 if (relocation & signbit)
605 {
606 if ((relocation & ~offmsk) != ~offmsk)
607 flag = bfd_reloc_overflow;
608 }
609 else if (relocation & ~offmsk)
610 flag = bfd_reloc_overflow;
611
612 target &= ~dstmsk;
613 switch (btype)
614 {
615 case b9:
616 case b12:
617 target |= (relocation >> 1);
618 break;
619
620 case b23:
621 if (bfd_big_endian (abfd))
622 target |= ((relocation & 0xfff) >> 1) | ((relocation << 4) & 0x07ff0000);
623 else
624 target |= ((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff);
625 break;
626 }
627
628 bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
629
630 /* Now the ARM magic... Change the reloc type so that it is marked as done.
631 Strictly this is only necessary if we are doing a partial relocation. */
632 reloc_entry->howto = & aoutarm_std_reloc_howto [ARM_26D];
633
634 /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations */
635 return flag;
636 }
637
638 static bfd_reloc_status_type
639 coff_thumb_pcrel_23 (abfd, reloc_entry, symbol, data, input_section,
640 output_bfd, error_message)
641 bfd *abfd;
642 arelent *reloc_entry;
643 asymbol *symbol;
644 PTR data;
645 asection *input_section;
646 bfd *output_bfd;
647 char **error_message;
648 {
649 return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
650 input_section, output_bfd, error_message, b23);
651 }
652
653 static bfd_reloc_status_type
654 coff_thumb_pcrel_12 (abfd, reloc_entry, symbol, data, input_section,
655 output_bfd, error_message)
656 bfd *abfd;
657 arelent *reloc_entry;
658 asymbol *symbol;
659 PTR data;
660 asection *input_section;
661 bfd *output_bfd;
662 char **error_message;
663 {
664 return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
665 input_section, output_bfd, error_message, b12);
666 }
667
668 static bfd_reloc_status_type
669 coff_thumb_pcrel_9 (abfd, reloc_entry, symbol, data, input_section,
670 output_bfd, error_message)
671 bfd *abfd;
672 arelent *reloc_entry;
673 asymbol *symbol;
674 PTR data;
675 asection *input_section;
676 bfd *output_bfd;
677 char **error_message;
678 {
679 return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
680 input_section, output_bfd, error_message, b9);
681 }
682
683
684 static CONST struct reloc_howto_struct *
685 arm_reloc_type_lookup(abfd,code)
686 bfd *abfd;
687 bfd_reloc_code_real_type code;
688 {
689 #define ASTD(i,j) case i: return &aoutarm_std_reloc_howto[j]
690 if (code == BFD_RELOC_CTOR)
691 switch (bfd_get_arch_info (abfd)->bits_per_address)
692 {
693 case 32:
694 code = BFD_RELOC_32;
695 break;
696 default: return (CONST struct reloc_howto_struct *) 0;
697 }
698
699 switch (code)
700 {
701 ASTD (BFD_RELOC_8, ARM_8);
702 ASTD (BFD_RELOC_16, ARM_16);
703 ASTD (BFD_RELOC_32, ARM_32);
704 ASTD (BFD_RELOC_ARM_PCREL_BRANCH, ARM_26);
705 ASTD (BFD_RELOC_8_PCREL, ARM_DISP8);
706 ASTD (BFD_RELOC_16_PCREL, ARM_DISP16);
707 ASTD (BFD_RELOC_32_PCREL, ARM_DISP32);
708 ASTD (BFD_RELOC_RVA, ARM_RVA32);
709 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9, ARM_THUMB9);
710 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
711 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23);
712 default: return (CONST struct reloc_howto_struct *) 0;
713 }
714 }
715
716
717 #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup
718
719 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
720 #define COFF_PAGE_SIZE 0x1000
721 /* Turn a howto into a reloc nunmber */
722
723 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
724 #define BADMAG(x) ARMBADMAG(x)
725 #define ARM 1 /* Customize coffcode.h */
726
727 /* The set of global variables that mark the total size of each kind
728 of glue required. */
729 static long int global_thumb_glue_size = 0;
730 static long int global_arm_glue_size = 0;
731
732 static bfd * bfd_of_glue_owner = NULL;
733
734 /* some typedefs for holding instructions */
735 typedef unsigned long int insn32;
736 typedef unsigned short int insn16;
737
738 \f
739 /* The thumb form of a long branch is a bit finicky, because the offset
740 encoding is split over two fields, each in it's own instruction. They
741 can occur in any order. So given a thumb form of long branch, and an
742 offset, insert the offset into the thumb branch and return finished
743 instruction.
744
745 It takes two thumb instructions to encode the target address. Each has
746 11 bits to invest. The upper 11 bits are stored in one (identifed by
747 H-0.. see below), the lower 11 bits are stored in the other (identified
748 by H-1).
749
750 Combine together and shifted left by 1 (it's a half word address) and
751 there you have it.
752
753 Op: 1111 = F,
754 H-0, upper address-0 = 000
755 Op: 1111 = F,
756 H-1, lower address-0 = 800
757
758 They can be ordered either way, but the arm tools I've seen always put
759 the lower one first. It probably doesn't matter. krk@cygnus.com
760
761 XXX: Actually the order does matter. The second instruction (H-1)
762 moves the computed address into the PC, so it must be the second one
763 in the sequence. The problem, however is that whilst little endian code
764 stores the instructions in HI then LOW order, big endian code does the
765 reverse. nickc@cygnus.com */
766
767 #define LOW_HI_ORDER 0xF800F000
768 #define HI_LOW_ORDER 0xF000F800
769
770 static insn32
771 insert_thumb_branch (br_insn, rel_off)
772 insn32 br_insn;
773 int rel_off;
774 {
775 unsigned int low_bits;
776 unsigned int high_bits;
777
778
779 BFD_ASSERT((rel_off & 1) != 1);
780
781 rel_off >>= 1; /* half word aligned address */
782 low_bits = rel_off & 0x000007FF; /* the bottom 11 bits */
783 high_bits = ( rel_off >> 11 ) & 0x000007FF; /* the top 11 bits */
784
785 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
786 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
787 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
788 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
789 else
790 abort(); /* error - not a valid branch instruction form */
791
792 /* FIXME: abort is probably not the right call. krk@cygnus.com */
793
794 return br_insn;
795 }
796
797 \f
798 static struct coff_link_hash_entry *
799 find_thumb_glue (info, name, input_bfd)
800 struct bfd_link_info * info;
801 char * name;
802 bfd * input_bfd;
803 {
804 char * tmp_name = 0;
805 struct coff_link_hash_entry * myh = 0;
806
807 tmp_name = ((char *)
808 bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME)));
809
810 BFD_ASSERT (tmp_name);
811
812 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
813
814 myh = coff_link_hash_lookup (coff_hash_table (info),
815 tmp_name,
816 false, false, true);
817 if (myh == NULL)
818 {
819 _bfd_error_handler ("%s: unable to find THUMB glue '%s' for `%s'",
820 bfd_get_filename (input_bfd), tmp_name, name);
821 }
822
823 free (tmp_name);
824
825 return myh;
826 }
827
828 static struct coff_link_hash_entry *
829 find_arm_glue (info, name, input_bfd)
830 struct bfd_link_info * info;
831 char * name;
832 bfd * input_bfd;
833 {
834 char *tmp_name = 0;
835 struct coff_link_hash_entry *myh = 0;
836
837 tmp_name = ((char *)
838 bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME)));
839
840 BFD_ASSERT (tmp_name);
841
842 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
843
844 myh = coff_link_hash_lookup (coff_hash_table (info),
845 tmp_name,
846 false, false, true);
847
848 if (myh == NULL)
849 {
850 _bfd_error_handler ("%s: unable to find ARM glue '%s' for `%s'",
851 bfd_get_filename (input_bfd), tmp_name, name);
852 }
853
854 free (tmp_name);
855
856 return myh;
857 }
858
859 /*
860 ARM->Thumb glue:
861
862 .arm
863 __func_from_arm:
864 ldr r12, __func_addr
865 bx r12
866 __func_addr:
867 .word func @ behave as if you saw a ARM_32 reloc
868
869 ldr ip,8 <__func_addr> e59fc000
870 bx ip e12fff1c
871 .word func 00000001
872
873 */
874
875 #define ARM2THUMB_GLUE_SIZE 12
876 static const insn32
877 a2t1_ldr_insn = 0xe59fc000,
878 a2t2_bx_r12_insn = 0xe12fff1c,
879 a2t3_func_addr_insn = 0x00000001;
880
881 /*
882 Thumb->ARM:
883
884 .thumb
885 .align 2
886 __func_from_thumb:
887 bx pc
888 nop
889 .arm
890 __func_change_to_arm:
891 b func
892
893
894 bx pc 4778
895 nop 0000
896 b func eafffffe
897
898 */
899
900 #define THUMB2ARM_GLUE_SIZE 8
901 static const insn16
902 t2a1_bx_pc_insn = 0x4778,
903 t2a2_noop_insn = 0x46c0;
904 static const insn32
905 t2a3_b_insn = 0xea000000;
906
907 /* TODO:
908 We should really create new local (static) symbols in destination
909 object for each stub we create. We should also create local
910 (static) symbols within the stubs when switching between ARM and
911 Thumb code. This will ensure that the debugger and disassembler
912 can present a better view of stubs.
913
914 We can treat stubs like literal sections, and for the THUMB9 ones
915 (short addressing range) we should be able to insert the stubs
916 between sections. i.e. the simplest approach (since relocations
917 are done on a section basis) is to dump the stubs at the end of
918 processing a section. That way we can always try and minimise the
919 offset to and from a stub. However, this does not map well onto
920 the way that the linker/BFD does its work: mapping all input
921 sections to output sections via the linker script before doing
922 all the processing.
923
924 Unfortunately it may be easier to just to disallow short range
925 Thumb->ARM stubs (i.e. no conditional inter-working branches,
926 only branch-and-link (BL) calls. This will simplify the processing
927 since we can then put all of the stubs into their own section.
928
929 TODO:
930 On a different subject, rather than complaining when a
931 branch cannot fit in the number of bits available for the
932 instruction we should generate a trampoline stub (needed to
933 address the complete 32bit address space). */
934
935 /* The standard COFF backend linker does not cope with the special
936 Thumb BRANCH23 relocation. The alternative would be to split the
937 BRANCH23 into seperate HI23 and LO23 relocations. However, it is a
938 bit simpler simply providing our own relocation driver. */
939
940 /* The reloc processing routine for the ARM/Thumb COFF linker. NOTE:
941 This code is a very slightly modified copy of
942 _bfd_coff_generic_relocate_section. It would be a much more
943 maintainable solution to have a MACRO that could be expanded within
944 _bfd_coff_generic_relocate_section that would only be provided for
945 ARM/Thumb builds. It is only the code marked THUMBEXTENSION that
946 is different from the original. */
947
948 static boolean
949 coff_arm_relocate_section (output_bfd, info, input_bfd, input_section,
950 contents, relocs, syms, sections)
951 bfd *output_bfd;
952 struct bfd_link_info *info;
953 bfd *input_bfd;
954 asection *input_section;
955 bfd_byte *contents;
956 struct internal_reloc *relocs;
957 struct internal_syment *syms;
958 asection **sections;
959 {
960 struct internal_reloc * rel;
961 struct internal_reloc * relend;
962
963 rel = relocs;
964 relend = rel + input_section->reloc_count;
965
966 for (; rel < relend; rel++)
967 {
968 int done = 0;
969 long symndx;
970 struct coff_link_hash_entry *h;
971 struct internal_syment *sym;
972 bfd_vma addend;
973 bfd_vma val;
974 reloc_howto_type *howto;
975 bfd_reloc_status_type rstat;
976 bfd_vma h_val;
977
978 symndx = rel->r_symndx;
979
980 if (symndx == -1)
981 {
982 h = NULL;
983 sym = NULL;
984 }
985 else
986 {
987 h = obj_coff_sym_hashes (input_bfd)[symndx];
988 sym = syms + symndx;
989 }
990
991 /* COFF treats common symbols in one of two ways. Either the
992 size of the symbol is included in the section contents, or it
993 is not. We assume that the size is not included, and force
994 the rtype_to_howto function to adjust the addend as needed. */
995
996 if (sym != NULL && sym->n_scnum != 0)
997 addend = - sym->n_value;
998 else
999 addend = 0;
1000
1001
1002 howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
1003 sym, &addend);
1004 if (howto == NULL)
1005 return false;
1006
1007 /* If we are doing a relocateable link, then we can just ignore
1008 a PC relative reloc that is pcrel_offset. It will already
1009 have the correct value. If this is not a relocateable link,
1010 then we should ignore the symbol value. */
1011 if (howto->pc_relative && howto->pcrel_offset)
1012 {
1013 if (info->relocateable)
1014 continue;
1015 if (sym != NULL && sym->n_scnum != 0)
1016 addend += sym->n_value;
1017 }
1018
1019 /* If we are doing a relocateable link, then we can just ignore
1020 a PC relative reloc that is pcrel_offset. It will already
1021 have the correct value. */
1022 if (info->relocateable
1023 && howto->pc_relative
1024 && howto->pcrel_offset)
1025 continue;
1026
1027 val = 0;
1028
1029 if (h == NULL)
1030 {
1031 asection *sec;
1032
1033 if (symndx == -1)
1034 {
1035 sec = bfd_abs_section_ptr;
1036 val = 0;
1037 }
1038 else
1039 {
1040 sec = sections[symndx];
1041 val = (sec->output_section->vma
1042 + sec->output_offset
1043 + sym->n_value
1044 - sec->vma);
1045 }
1046 }
1047 else
1048 {
1049 #if 1 /* THUMBEXTENSION */
1050 /* We don't output the stubs if we are generating a
1051 relocatable output file, since we may as well leave the
1052 stub generation to the final linker pass. If we fail to
1053 verify that the name is defined, we'll try to build stubs
1054 for an undefined name... */
1055 if (! info->relocateable
1056 && ( h->root.type == bfd_link_hash_defined
1057 || h->root.type == bfd_link_hash_defweak))
1058 {
1059 asection * sec;
1060 asection * h_sec = h->root.u.def.section;
1061 const char * name = h->root.root.string;
1062
1063 /* h locates the symbol referenced in the reloc. */
1064 h_val = (h->root.u.def.value
1065 + h_sec->output_section->vma
1066 + h_sec->output_offset);
1067
1068 if (howto->type == ARM_26)
1069 {
1070 if ( h->class == C_THUMBSTATFUNC
1071 || h->class == C_THUMBEXTFUNC)
1072 {
1073 /* Arm code calling a Thumb function */
1074 signed long int final_disp;
1075 unsigned long int tmp;
1076 long int my_offset;
1077 long int offset;
1078 asection * s = 0;
1079 unsigned long int return_address;
1080 long int ret_offset;
1081 long int disp;
1082 struct coff_link_hash_entry * myh;
1083
1084 myh = find_arm_glue (info, name, input_bfd);
1085 if (myh == NULL)
1086 return false;
1087
1088 my_offset = myh->root.u.def.value;
1089
1090 s = bfd_get_section_by_name (bfd_of_glue_owner,
1091 ARM2THUMB_GLUE_SECTION_NAME);
1092 BFD_ASSERT (s != NULL);
1093 BFD_ASSERT (s->contents != NULL);
1094
1095 if ((my_offset & 0x01) == 0x01)
1096 {
1097 if (h_sec->owner != NULL
1098 && INTERWORK_SET (h_sec->owner)
1099 && ! INTERWORK_FLAG (h_sec->owner))
1100 {
1101 _bfd_error_handler
1102 ("%s(%s): warning: interworking not enabled.",
1103 bfd_get_filename (h_sec->owner), name);
1104 _bfd_error_handler
1105 (" first occurrence: %s: arm call to thumb",
1106 bfd_get_filename (input_bfd));
1107 }
1108
1109 --my_offset;
1110 myh->root.u.def.value = my_offset;
1111
1112 bfd_put_32 (output_bfd, a2t1_ldr_insn, s->contents + my_offset);
1113
1114 bfd_put_32 (output_bfd, a2t2_bx_r12_insn, s->contents + my_offset + 4);
1115
1116 /* It's a thumb address. Add the low order bit. */
1117 bfd_put_32 (output_bfd, h_val | a2t3_func_addr_insn, s->contents + my_offset + 8);
1118 }
1119
1120 BFD_ASSERT (my_offset <= global_arm_glue_size);
1121
1122 tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr - input_section->vma);
1123
1124 tmp = tmp & 0xFF000000;
1125
1126 /* Somehow these are both 4 too far, so subtract 8. */
1127 ret_offset =
1128 s->output_offset
1129 + my_offset
1130 + s->output_section->vma
1131 - (input_section->output_offset
1132 + input_section->output_section->vma
1133 + rel->r_vaddr)
1134 - 8;
1135
1136 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
1137
1138 bfd_put_32 (output_bfd, tmp, contents + rel->r_vaddr - input_section->vma);
1139
1140 done = 1;
1141 }
1142 }
1143
1144 /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12 */
1145 else if (howto->type == ARM_THUMB23)
1146 {
1147 if ( h->class == C_EXT
1148 || h->class == C_STAT
1149 || h->class == C_LABEL)
1150 {
1151 /* Thumb code calling an ARM function */
1152 unsigned long int return_address;
1153 signed long int final_disp;
1154 asection * s = 0;
1155 long int my_offset;
1156 unsigned long int tmp;
1157 long int ret_offset;
1158 struct coff_link_hash_entry * myh;
1159
1160 myh = find_thumb_glue (info, name, input_bfd);
1161 if (myh == NULL)
1162 return false;
1163
1164 my_offset = myh->root.u.def.value;
1165
1166 s = bfd_get_section_by_name (bfd_of_glue_owner,
1167 THUMB2ARM_GLUE_SECTION_NAME);
1168
1169 BFD_ASSERT (s != NULL);
1170 BFD_ASSERT (s->contents != NULL);
1171
1172 if ((my_offset & 0x01) == 0x01)
1173 {
1174 if (h_sec->owner != NULL
1175 && INTERWORK_SET (h_sec->owner)
1176 && ! INTERWORK_FLAG (h_sec->owner))
1177 {
1178 _bfd_error_handler
1179 ("%s(%s): warning: interworking not enabled.",
1180 bfd_get_filename (h_sec->owner), name);
1181 _bfd_error_handler
1182 (" first occurrence: %s: thumb call to arm",
1183 bfd_get_filename (input_bfd));
1184 }
1185 -- my_offset;
1186 myh->root.u.def.value = my_offset;
1187
1188 bfd_put_16 (output_bfd, t2a1_bx_pc_insn,
1189 s->contents + my_offset);
1190
1191 bfd_put_16 (output_bfd, t2a2_noop_insn,
1192 s->contents + my_offset + 2);
1193
1194 ret_offset =
1195 ((signed)h_val) - /* Address of destination of the stub */
1196 ((signed)(s->output_offset /* Offset from the start of the current section to the start of the stubs. */
1197 + my_offset /* Offset of the start of this stub from the start of the stubs. */
1198 + s->output_section->vma) /* Address of the start of the current section. */
1199 + 4 /* The branch instruction is 4 bytes into the stub. */
1200 + 8); /* ARM branches work from the pc of the instruction + 8. */
1201
1202 bfd_put_32 (output_bfd,
1203 t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
1204 s->contents + my_offset + 4);
1205 }
1206
1207 BFD_ASSERT (my_offset <= global_thumb_glue_size);
1208
1209 /* Now go back and fix up the original bl insn to point here. */
1210 ret_offset =
1211 s->output_offset
1212 + my_offset
1213 - (input_section->output_offset
1214 + rel->r_vaddr)
1215 -4;
1216
1217 tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr - input_section->vma);
1218
1219 bfd_put_32 (output_bfd,
1220 insert_thumb_branch (tmp, ret_offset),
1221 contents + rel->r_vaddr - input_section->vma);
1222
1223 done = 1;
1224 }
1225 }
1226 }
1227
1228 /* If the relocation type and destination symbol does not
1229 fall into one of the above categories, then we can just
1230 perform a direct link. */
1231
1232 if (done)
1233 rstat = bfd_reloc_ok;
1234 else
1235 #endif /* THUMBEXTENSION */
1236 if ( h->root.type == bfd_link_hash_defined
1237 || h->root.type == bfd_link_hash_defweak)
1238 {
1239 asection *sec;
1240
1241 sec = h->root.u.def.section;
1242 val = (h->root.u.def.value
1243 + sec->output_section->vma
1244 + sec->output_offset);
1245 }
1246
1247 else if (! info->relocateable)
1248 {
1249 if (! ((*info->callbacks->undefined_symbol)
1250 (info, h->root.root.string, input_bfd, input_section,
1251 rel->r_vaddr - input_section->vma)))
1252 return false;
1253 }
1254 }
1255
1256 if (info->base_file)
1257 {
1258 /* Emit a reloc if the backend thinks it needs it. */
1259 if (sym && pe_data(output_bfd)->in_reloc_p(output_bfd, howto))
1260 {
1261 /* relocation to a symbol in a section which
1262 isn't absolute - we output the address here
1263 to a file */
1264 bfd_vma addr = rel->r_vaddr
1265 - input_section->vma
1266 + input_section->output_offset
1267 + input_section->output_section->vma;
1268 if (coff_data(output_bfd)->pe)
1269 addr -= pe_data(output_bfd)->pe_opthdr.ImageBase;
1270 /* FIXME: Shouldn't 4 be sizeof (addr)? */
1271 fwrite (&addr, 1,4, (FILE *) info->base_file);
1272 }
1273 }
1274
1275 #if 1 /* THUMBEXTENSION */
1276 if (done)
1277 ;
1278 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1279 else if (! info->relocateable
1280 && howto->type == ARM_THUMB23)
1281 {
1282 /* This is pretty much a copy of what the default
1283 _bfd_final_link_relocate and _bfd_relocate_contents
1284 routines do to perform a relocation, with special
1285 processing for the split addressing of the Thumb BL
1286 instruction. Again, it would probably be simpler adding a
1287 ThumbBRANCH23 specific macro expansion into the default
1288 code. */
1289
1290 bfd_vma address = rel->r_vaddr - input_section->vma;
1291
1292 if (address > input_section->_raw_size)
1293 rstat = bfd_reloc_outofrange;
1294 else
1295 {
1296 bfd_vma relocation = val + addend;
1297 int size = bfd_get_reloc_size (howto);
1298 boolean overflow = false;
1299 bfd_byte * location = contents + address;
1300 bfd_vma x = bfd_get_32 (input_bfd, location);
1301 bfd_vma src_mask = 0x007FFFFE;
1302 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
1303 bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
1304 bfd_vma check;
1305 bfd_signed_vma signed_check;
1306 bfd_vma add;
1307 bfd_signed_vma signed_add;
1308
1309 BFD_ASSERT (size == 4);
1310
1311 /* howto->pc_relative should be TRUE for type 14 BRANCH23 */
1312 relocation -= (input_section->output_section->vma
1313 + input_section->output_offset);
1314
1315 /* howto->pcrel_offset should be TRUE for type 14 BRANCH23 */
1316 relocation -= address;
1317
1318 /* No need to negate the relocation with BRANCH23. */
1319 /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23. */
1320 /* howto->rightshift == 1 */
1321 /* Drop unwanted bits from the value we are relocating to. */
1322
1323 check = relocation >> howto->rightshift;
1324
1325 /* If this is a signed value, the rightshift just dropped
1326 leading 1 bits (assuming twos complement). */
1327 if ((bfd_signed_vma) relocation >= 0)
1328 signed_check = check;
1329 else
1330 signed_check = (check
1331 | ((bfd_vma) - 1
1332 & ~((bfd_vma) - 1 >> howto->rightshift)));
1333
1334 /* Get the value from the object file. */
1335 if (bfd_big_endian (input_bfd))
1336 {
1337 add = (((x) & 0x07ff0000) >> 4) | (((x) & 0x7ff) << 1);
1338 }
1339 else
1340 {
1341 add = ((((x) & 0x7ff) << 12) | (((x) & 0x07ff0000) >> 15));
1342 }
1343
1344 /* Get the value from the object file with an appropriate sign.
1345 The expression involving howto->src_mask isolates the upper
1346 bit of src_mask. If that bit is set in the value we are
1347 adding, it is negative, and we subtract out that number times
1348 two. If src_mask includes the highest possible bit, then we
1349 can not get the upper bit, but that does not matter since
1350 signed_add needs no adjustment to become negative in that
1351 case. */
1352
1353 signed_add = add;
1354
1355 if ((add & (((~ src_mask) >> 1) & src_mask)) != 0)
1356 signed_add -= (((~ src_mask) >> 1) & src_mask) << 1;
1357
1358 /* Add the value from the object file, shifted so that it is a
1359 straight number. */
1360 /* howto->bitpos == 0 */
1361
1362 signed_check += signed_add;
1363 relocation += signed_add;
1364
1365 BFD_ASSERT (howto->complain_on_overflow == complain_overflow_signed);
1366
1367 /* Assumes two's complement. */
1368 if ( signed_check > reloc_signed_max
1369 || signed_check < reloc_signed_min)
1370 overflow = true;
1371
1372 /* Put RELOCATION into the correct bits: */
1373
1374 if (bfd_big_endian (input_bfd))
1375 {
1376 relocation = (((relocation & 0xffe) >> 1) | ((relocation << 4) & 0x07ff0000));
1377 }
1378 else
1379 {
1380 relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff));
1381 }
1382
1383 /* Add RELOCATION to the correct bits of X: */
1384 x = ((x & ~howto->dst_mask) | relocation);
1385
1386 /* Put the relocated value back in the object file: */
1387 bfd_put_32 (input_bfd, x, location);
1388
1389 rstat = overflow ? bfd_reloc_overflow : bfd_reloc_ok;
1390 }
1391 }
1392 else
1393 #endif /* THUMBEXTENSION */
1394 rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
1395 contents,
1396 rel->r_vaddr - input_section->vma,
1397 val, addend);
1398 #if 1 /* THUMBEXTENSION */
1399 /* FIXME:
1400 Is this the best way to fix up thumb addresses? krk@cygnus.com
1401 Probably not, but it works, and if it works it don't need fixing! nickc@cygnus.com */
1402 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1403 if (! info->relocateable
1404 && rel->r_type == ARM_32)
1405 {
1406 /* Determine if we need to set the bottom bit of a relocated address
1407 because the address is the address of a Thumb code symbol. */
1408
1409 int patchit = false;
1410
1411 if (h != NULL
1412 && ( h->class == C_THUMBSTATFUNC
1413 || h->class == C_THUMBEXTFUNC))
1414 {
1415 patchit = true;
1416 }
1417 else if (sym != NULL
1418 && sym->n_scnum > N_UNDEF)
1419 {
1420 /* No hash entry - use the symbol instead. */
1421
1422 if ( sym->n_sclass == C_THUMBSTATFUNC
1423 || sym->n_sclass == C_THUMBEXTFUNC)
1424 patchit = true;
1425 }
1426
1427 if (patchit)
1428 {
1429 bfd_byte * location = contents + rel->r_vaddr - input_section->vma;
1430 bfd_vma x = bfd_get_32 (input_bfd, location);
1431
1432 bfd_put_32 (input_bfd, x | 1, location);
1433 }
1434 }
1435 #endif /* THUMBEXTENSION */
1436
1437 switch (rstat)
1438 {
1439 default:
1440 abort ();
1441 case bfd_reloc_ok:
1442 break;
1443 case bfd_reloc_outofrange:
1444 (*_bfd_error_handler)
1445 ("%s: bad reloc address 0x%lx in section `%s'",
1446 bfd_get_filename (input_bfd),
1447 (unsigned long) rel->r_vaddr,
1448 bfd_get_section_name (input_bfd, input_section));
1449 return false;
1450 case bfd_reloc_overflow:
1451 {
1452 const char *name;
1453 char buf[SYMNMLEN + 1];
1454
1455 if (symndx == -1)
1456 name = "*ABS*";
1457 else if (h != NULL)
1458 name = h->root.root.string;
1459 else
1460 {
1461 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1462 if (name == NULL)
1463 return false;
1464 }
1465
1466 if (! ((*info->callbacks->reloc_overflow)
1467 (info, name, howto->name, (bfd_vma) 0, input_bfd,
1468 input_section, rel->r_vaddr - input_section->vma)))
1469 return false;
1470 }
1471 }
1472 }
1473
1474 return true;
1475 }
1476
1477 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
1478 boolean
1479 arm_allocate_interworking_sections (info)
1480 struct bfd_link_info *info;
1481 {
1482 asection * s;
1483 bfd_byte * foo;
1484 #if 0
1485 static char test_char = '1';
1486 #endif
1487
1488 if (global_arm_glue_size != 0)
1489 {
1490 BFD_ASSERT (bfd_of_glue_owner != NULL);
1491
1492 s = bfd_get_section_by_name (bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
1493
1494 BFD_ASSERT (s != NULL);
1495
1496 foo = (bfd_byte *) bfd_alloc (bfd_of_glue_owner, global_arm_glue_size);
1497 #if 0
1498 memset (foo, test_char, global_arm_glue_size);
1499 #endif
1500
1501 s->_raw_size = s->_cooked_size = global_arm_glue_size;
1502 s->contents = foo;
1503 }
1504
1505 if (global_thumb_glue_size != 0)
1506 {
1507 BFD_ASSERT (bfd_of_glue_owner != NULL);
1508
1509 s = bfd_get_section_by_name (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1510
1511 BFD_ASSERT (s != NULL);
1512
1513 foo = (bfd_byte *) bfd_alloc (bfd_of_glue_owner, global_thumb_glue_size);
1514 #if 0
1515 memset (foo, test_char, global_thumb_glue_size);
1516 #endif
1517
1518 s->_raw_size = s->_cooked_size = global_thumb_glue_size;
1519 s->contents = foo;
1520 }
1521
1522 return true;
1523 }
1524
1525 static void
1526 record_arm_to_thumb_glue (info, h)
1527 struct bfd_link_info * info;
1528 struct coff_link_hash_entry * h;
1529 {
1530 const char * name = h->root.root.string;
1531 register asection * s;
1532 char * tmp_name;
1533 struct coff_link_hash_entry * myh;
1534
1535
1536 BFD_ASSERT (bfd_of_glue_owner != NULL);
1537
1538 s = bfd_get_section_by_name (bfd_of_glue_owner,
1539 ARM2THUMB_GLUE_SECTION_NAME);
1540
1541 BFD_ASSERT (s != NULL);
1542
1543 tmp_name = ((char *)
1544 bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME)));
1545
1546 BFD_ASSERT (tmp_name);
1547
1548 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1549
1550 myh = coff_link_hash_lookup (coff_hash_table (info),
1551 tmp_name,
1552 false, false, true);
1553
1554 if (myh != NULL)
1555 {
1556 free (tmp_name);
1557 return; /* we've already seen this guy */
1558 }
1559
1560
1561 /* The only trick here is using global_arm_glue_size as the value. Even
1562 though the section isn't allocated yet, this is where we will be putting
1563 it. */
1564
1565 bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name,
1566 BSF_EXPORT | BSF_GLOBAL,
1567 s, global_arm_glue_size + 1,
1568 NULL, true, false,
1569 (struct bfd_link_hash_entry **) & myh);
1570
1571 global_arm_glue_size += ARM2THUMB_GLUE_SIZE;
1572
1573 free (tmp_name);
1574
1575 return;
1576 }
1577
1578 static void
1579 record_thumb_to_arm_glue (info, h)
1580 struct bfd_link_info * info;
1581 struct coff_link_hash_entry * h;
1582 {
1583 const char * name = h->root.root.string;
1584 register asection * s;
1585 char * tmp_name;
1586 struct coff_link_hash_entry * myh;
1587
1588 BFD_ASSERT (bfd_of_glue_owner != NULL);
1589
1590 s = bfd_get_section_by_name (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1591
1592 BFD_ASSERT (s != NULL);
1593
1594 tmp_name = (char *) bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME));
1595
1596 BFD_ASSERT (tmp_name);
1597
1598 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1599
1600 myh = coff_link_hash_lookup (coff_hash_table (info),
1601 tmp_name,
1602 false, false, true);
1603
1604 if (myh != NULL)
1605 {
1606 free (tmp_name);
1607 return; /* we've already seen this guy */
1608 }
1609
1610 bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name,
1611 BSF_LOCAL, s, global_thumb_glue_size + 1,
1612 NULL, true, false,
1613 (struct bfd_link_hash_entry **) & myh);
1614
1615 /* If we mark it 'thumb', the disassembler will do a better job. */
1616 myh->class = C_THUMBEXTFUNC;
1617
1618 free (tmp_name);
1619
1620 #define CHANGE_TO_ARM "__%s_change_to_arm"
1621
1622 tmp_name = ((char *)
1623 bfd_malloc (strlen (name) + strlen (CHANGE_TO_ARM)));
1624
1625 BFD_ASSERT (tmp_name);
1626
1627 sprintf (tmp_name, CHANGE_TO_ARM, name);
1628
1629 myh = NULL;
1630
1631 /* Now allocate another symbol to switch back to arm mode. */
1632 bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name,
1633 BSF_LOCAL, s, global_thumb_glue_size + 4,
1634 NULL, true, false,
1635 (struct bfd_link_hash_entry **) & myh);
1636
1637 free (tmp_name);
1638
1639 global_thumb_glue_size += THUMB2ARM_GLUE_SIZE;
1640
1641 return;
1642 }
1643
1644 boolean
1645 arm_process_before_allocation (abfd, info)
1646 bfd * abfd;
1647 struct bfd_link_info * info;
1648 {
1649 asection * sec;
1650
1651 /* If we are only performing a partial link do not bother
1652 to construct any glue. */
1653 if (info->relocateable)
1654 return true;
1655
1656 /* Here we have a bfd that is to be included on the link. We have a hook
1657 to do reloc rummaging, before section sizes are nailed down. */
1658
1659 _bfd_coff_get_external_symbols (abfd);
1660
1661 /* Rummage around all the relocs and map the glue vectors. */
1662 sec = abfd->sections;
1663
1664 if (sec == NULL)
1665 return true;
1666
1667 for (; sec != NULL; sec = sec->next)
1668 {
1669 struct internal_reloc * i;
1670 struct internal_reloc * rel;
1671
1672 if (sec->reloc_count == 0)
1673 continue;
1674
1675 /* Load the relocs. */
1676 /* FIXME: there may be a storage leak here. */
1677
1678 i = _bfd_coff_read_internal_relocs (abfd, sec, 1, 0, 0, 0);
1679
1680 BFD_ASSERT (i != 0);
1681
1682 for (rel = i; rel < i + sec->reloc_count; ++rel)
1683 {
1684 unsigned short r_type = rel->r_type;
1685 long symndx;
1686 struct coff_link_hash_entry * h;
1687
1688 symndx = rel->r_symndx;
1689
1690 /* If the relocation is not against a symbol it cannot concern us. */
1691 if (symndx == -1)
1692 continue;
1693
1694 h = obj_coff_sym_hashes (abfd)[symndx];
1695
1696 /* If the relocation is against a static symbol it must be within
1697 the current section and so cannot be a cross ARM/Thumb relocation. */
1698 if (h == NULL)
1699 continue;
1700
1701 switch (r_type)
1702 {
1703 case ARM_26:
1704 /* This one is a call from arm code. We need to look up
1705 the target of the call. If it is a thumb target, we
1706 insert glue. */
1707
1708 if (h->class == C_THUMBEXTFUNC)
1709 record_arm_to_thumb_glue (info, h);
1710 break;
1711
1712 case ARM_THUMB23:
1713 /* This one is a call from thumb code. We used to look
1714 for ARM_THUMB9 and ARM_THUMB12 as well. We need to look
1715 up the target of the call. If it is an arm target, we
1716 insert glue. If the symbol does not exist it will be
1717 given a class of C_EXT and so we will generate a stub
1718 for it. This is not really a problem, since the link
1719 is doomed anyway. */
1720
1721 switch (h->class)
1722 {
1723 case C_EXT:
1724 case C_STAT:
1725 case C_LABEL:
1726 record_thumb_to_arm_glue (info, h);
1727 break;
1728 default:
1729 ;
1730 }
1731 break;
1732
1733 default:
1734 break;
1735 }
1736 }
1737 }
1738
1739 return true;
1740 }
1741 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
1742
1743 #define coff_relocate_section coff_arm_relocate_section
1744
1745 /* When doing a relocateable link, we want to convert ARM26 relocs
1746 into ARM26D relocs. */
1747
1748 static boolean
1749 coff_arm_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp)
1750 bfd *obfd;
1751 struct bfd_link_info *info;
1752 bfd *ibfd;
1753 asection *sec;
1754 struct internal_reloc *irel;
1755 boolean *adjustedp;
1756 {
1757 if (irel->r_type == 3)
1758 {
1759 struct coff_link_hash_entry *h;
1760
1761 h = obj_coff_sym_hashes (ibfd)[irel->r_symndx];
1762 if (h != NULL
1763 && (h->root.type == bfd_link_hash_defined
1764 || h->root.type == bfd_link_hash_defweak)
1765 && h->root.u.def.section->output_section == sec->output_section)
1766 irel->r_type = 7;
1767 }
1768 *adjustedp = false;
1769 return true;
1770 }
1771
1772 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
1773 /* Called when merging the private data areas of two BFDs.
1774 This is important as it allows us to detect if we are
1775 attempting to merge binaries compiled for different ARM
1776 targets, eg different CPUs or differents APCS's. */
1777
1778 boolean
1779 coff_arm_bfd_merge_private_bfd_data (ibfd, obfd)
1780 bfd * ibfd;
1781 bfd * obfd;
1782 {
1783 BFD_ASSERT (ibfd != NULL && obfd != NULL);
1784
1785 if (ibfd == obfd)
1786 return true;
1787
1788 /* If the two formats are different we cannot merge anything.
1789 This is not an error, since it is permissable to change the
1790 input and output formats. */
1791 if (ibfd->xvec != obfd->xvec)
1792 return true;
1793
1794 /* Verify that the APCS is the same for the two BFDs */
1795 if (APCS_SET (ibfd))
1796 {
1797 if (APCS_SET (obfd))
1798 {
1799 /* If the src and dest have different APCS flag bits set, fail. */
1800 if (APCS_26_FLAG (obfd) != APCS_26_FLAG (ibfd))
1801 {
1802 _bfd_error_handler
1803 ("%s: ERROR: compiled for APCS-%d whereas target %s uses APCS-%d",
1804 bfd_get_filename (ibfd), APCS_26_FLAG (ibfd) ? 26 : 32,
1805 bfd_get_filename (obfd), APCS_26_FLAG (obfd) ? 26 : 32
1806 );
1807
1808 bfd_set_error (bfd_error_wrong_format);
1809 return false;
1810 }
1811
1812 if (APCS_FLOAT_FLAG (obfd) != APCS_FLOAT_FLAG (ibfd))
1813 {
1814 _bfd_error_handler
1815 ("%s: ERROR: passes floats in %s registers whereas target %s uses %s registers",
1816 bfd_get_filename (ibfd), APCS_FLOAT_FLAG (ibfd) ? "float" : "integer",
1817 bfd_get_filename (obfd), APCS_FLOAT_FLAG (obfd) ? "float" : "integer"
1818 );
1819
1820 bfd_set_error (bfd_error_wrong_format);
1821 return false;
1822 }
1823
1824 if (PIC_FLAG (obfd) != PIC_FLAG (ibfd))
1825 {
1826 _bfd_error_handler
1827 ("%s: ERROR: compiled as %s code, whereas target %s is %s",
1828 bfd_get_filename (ibfd), PIC_FLAG (ibfd) ? "position independent" : "absoluste position",
1829 bfd_get_filename (obfd), PIC_FLAG (obfd) ? "position independent" : "absoluste position"
1830 );
1831
1832 bfd_set_error (bfd_error_wrong_format);
1833 return false;
1834 }
1835 }
1836 else
1837 {
1838 SET_APCS_FLAGS (obfd, APCS_26_FLAG (ibfd) | APCS_FLOAT_FLAG (ibfd) | PIC_FLAG (ibfd));
1839
1840 /* Set up the arch and fields as well as these are probably wrong. */
1841 bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
1842 }
1843 }
1844
1845 /* Check the interworking support. */
1846 if (INTERWORK_SET (ibfd))
1847 {
1848 if (INTERWORK_SET (obfd))
1849 {
1850 /* If the src and dest differ in their interworking issue a warning. */
1851 if (INTERWORK_FLAG (obfd) != INTERWORK_FLAG (ibfd))
1852 {
1853 _bfd_error_handler
1854 ("Warning: input file %s %s interworking, whereas %s does%s",
1855 bfd_get_filename (ibfd),
1856 INTERWORK_FLAG (ibfd) ? "supports" : "does not support",
1857 bfd_get_filename (obfd),
1858 INTERWORK_FLAG (obfd) ? "." : " not."
1859 );
1860 }
1861 }
1862 else
1863 {
1864 SET_INTERWORK_FLAG (obfd, INTERWORK_FLAG (ibfd));
1865 }
1866 }
1867
1868 return true;
1869 }
1870
1871
1872 /* Display the flags field. */
1873
1874 static boolean
1875 coff_arm_bfd_print_private_bfd_data (abfd, ptr)
1876 bfd * abfd;
1877 PTR ptr;
1878 {
1879 FILE * file = (FILE *) ptr;
1880
1881 BFD_ASSERT (abfd != NULL && ptr != NULL)
1882
1883 fprintf (file, "private flags = %x", coff_data (abfd)->flags);
1884
1885 if (APCS_SET (abfd))
1886 fprintf (file, ": [APCS-%d] [floats passed in %s registers] [%s]",
1887 APCS_26_FLAG (abfd) ? 26 : 32,
1888 APCS_FLOAT_FLAG (abfd) ? "float" : "integer",
1889 PIC_FLAG (abfd) ? "position independent" : "absolute position"
1890 );
1891
1892 if (INTERWORK_SET (abfd))
1893 fprintf (file, ": [interworking %ssupported]",
1894 INTERWORK_FLAG (abfd) ? "" : "not " );
1895
1896 fputc ('\n', file);
1897
1898 return true;
1899 }
1900
1901
1902 /* Copies the given flags into the coff_tdata.flags field.
1903 Typically these flags come from the f_flags[] field of
1904 the COFF filehdr structure, which contains important,
1905 target specific information. */
1906
1907 boolean
1908 coff_arm_bfd_set_private_flags (abfd, flags)
1909 bfd * abfd;
1910 flagword flags;
1911 {
1912 int flag;
1913
1914 BFD_ASSERT (abfd != NULL);
1915
1916 flag = (flags & F_APCS26) ? F_APCS_26 : 0;
1917
1918 /* Make sure that the APCS field has not been initialised to the opposite value. */
1919 if (APCS_SET (abfd)
1920 && ( (APCS_26_FLAG (abfd) != flag)
1921 || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
1922 || (PIC_FLAG (abfd) != (flags & F_PIC))
1923 ))
1924 return false;
1925
1926 flag |= (flags & (F_APCS_FLOAT | F_PIC));
1927
1928 SET_APCS_FLAGS (abfd, flag);
1929
1930 flag = (flags & F_INTERWORK);
1931
1932 /* If either the flags or the BFD do support interworking then do not set the interworking flag. */
1933 if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
1934 flag = 0;
1935
1936 SET_INTERWORK_FLAG (abfd, flag);
1937
1938 return true;
1939 }
1940
1941
1942 /* Copy the important parts of the target specific data
1943 from one instance of a BFD to another. */
1944
1945 static boolean
1946 coff_arm_bfd_copy_private_bfd_data (src, dest)
1947 bfd * src;
1948 bfd * dest;
1949 {
1950 BFD_ASSERT (src != NULL && dest != NULL);
1951
1952 if (src == dest)
1953 return true;
1954
1955 /* If the destination is not in the same format as the source, do not do the copy. */
1956 if (src->xvec != dest->xvec)
1957 return true;
1958
1959 /* copy the flags field */
1960 if (APCS_SET (src))
1961 {
1962 if (APCS_SET (dest))
1963 {
1964 /* If the src and dest have different APCS flag bits set, fail. */
1965 if (APCS_26_FLAG (dest) != APCS_26_FLAG (src))
1966 return false;
1967
1968 if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src))
1969 return false;
1970
1971 if (PIC_FLAG (dest) != PIC_FLAG (src))
1972 return false;
1973 }
1974 else
1975 SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src) | PIC_FLAG (src));
1976 }
1977
1978 if (INTERWORK_SET (src))
1979 {
1980 if (INTERWORK_SET (dest))
1981 {
1982 /* If the src and dest have different interworking flags then turn off the interworking bit. */
1983 if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src))
1984 SET_INTERWORK_FLAG (dest, 0);
1985 }
1986 else
1987 {
1988 SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src));
1989 }
1990 }
1991
1992 return true;
1993 }
1994 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
1995
1996 /* Note: the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX
1997 *must* match the definitions on gcc/config/arm/semi.h. */
1998 #define LOCAL_LABEL_PREFIX "."
1999 #define USER_LABEL_PREFIX "_"
2000
2001 static boolean
2002 coff_arm_is_local_label_name (abfd, name)
2003 bfd * abfd;
2004 const char * name;
2005 {
2006 #ifdef LOCAL_LABEL_PREFIX
2007 /* If there is a prefix for local labels then look for this.
2008 If the prefix exists, but it is empty, then ignore the test. */
2009
2010 if (LOCAL_LABEL_PREFIX[0] != 0)
2011 {
2012 if (strncmp (name, LOCAL_LABEL_PREFIX, strlen (LOCAL_LABEL_PREFIX)) == 0)
2013 return true;
2014 }
2015 #endif
2016 #ifdef USER_LABEL_PREFIX
2017 if (USER_LABEL_PREFIX[0] != 0)
2018 {
2019 if (strncmp (name, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)) == 0)
2020 return false;
2021 }
2022 #endif
2023
2024 /* devo/gcc/config/dbxcoff.h defines ASM_OUTPUT_SOURCE_LINE to generate local line numbers as .LM<number>, so treat these as local. */
2025
2026 switch (name[0])
2027 {
2028 case 'L': return true;
2029 case '.': return (name[1] == 'L' && name[2] == 'M') ? true : false;
2030 default: return false; /* Cannot make our minds up - default to false so that it will not be stripped by accident. */
2031 }
2032 }
2033
2034 #define coff_bfd_is_local_label_name coff_arm_is_local_label_name
2035 #define coff_adjust_symndx coff_arm_adjust_symndx
2036
2037 #define coff_link_output_has_begun coff_arm_link_output_has_begun
2038 #define coff_final_link_postscript coff_arm_final_link_postscript
2039 #define coff_bfd_merge_private_bfd_data coff_arm_bfd_merge_private_bfd_data
2040 #define coff_bfd_print_private_bfd_data coff_arm_bfd_print_private_bfd_data
2041 #define coff_bfd_set_private_flags coff_arm_bfd_set_private_flags
2042 #define coff_bfd_copy_private_bfd_data coff_arm_bfd_copy_private_bfd_data
2043
2044 extern boolean coff_arm_final_link_postscript ();
2045 extern boolean coff_arm_bfd_set_private_flags ();
2046 extern boolean coff_arm_bfd_merge_private_bfd_data ();
2047 extern boolean coff_arm_link_output_has_begun ();
2048
2049 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
2050 /* This piece of machinery exists only to guarantee that the bfd that holds
2051 the glue section is written last.
2052
2053 This does depend on bfd_make_section attaching a new section to the
2054 end of the section list for the bfd.
2055
2056 krk@cygnus.com */
2057
2058 boolean
2059 coff_arm_link_output_has_begun (sub)
2060 bfd * sub;
2061 {
2062 return (sub->output_has_begun || sub == bfd_of_glue_owner);
2063 }
2064
2065 boolean
2066 coff_arm_final_link_postscript (abfd, pfinfo)
2067 bfd * abfd;
2068 struct coff_final_link_info * pfinfo;
2069 {
2070 if (bfd_of_glue_owner != NULL)
2071 {
2072 if (! _bfd_coff_link_input_bfd (pfinfo, bfd_of_glue_owner))
2073 return false;
2074 bfd_of_glue_owner->output_has_begun = true;
2075 }
2076 return true;
2077 }
2078 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
2079
2080 #define coff_SWAP_sym_in arm_bfd_coff_swap_sym_in
2081
2082 static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
2083
2084 /* Sepcial version of symbol swapper, used to grab a bfd
2085 onto which the glue sections can be attached. */
2086 static void
2087 arm_bfd_coff_swap_sym_in (abfd, ext1, in1)
2088 bfd * abfd;
2089 PTR ext1;
2090 PTR in1;
2091 {
2092 flagword flags;
2093 register asection * s;
2094
2095 /* Do the normal swap in. */
2096 coff_swap_sym_in (abfd, ext1, in1);
2097
2098 if (bfd_of_glue_owner != NULL) /* we already have a toc, so go home */
2099 return;
2100
2101 /* Save the bfd for later allocation. */
2102 bfd_of_glue_owner = abfd;
2103
2104 s = bfd_get_section_by_name (bfd_of_glue_owner ,
2105 ARM2THUMB_GLUE_SECTION_NAME);
2106
2107 if (s == NULL)
2108 {
2109 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ;
2110
2111 s = bfd_make_section (bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2112
2113 if (s == NULL
2114 || !bfd_set_section_flags (bfd_of_glue_owner, s, flags)
2115 || !bfd_set_section_alignment (bfd_of_glue_owner, s, 2))
2116 {
2117 /* FIXME: set appropriate bfd error */
2118 abort();
2119 }
2120 }
2121
2122 s = bfd_get_section_by_name (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2123
2124 if (s == NULL)
2125 {
2126 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ;
2127
2128 s = bfd_make_section (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2129
2130 if (s == NULL
2131 || !bfd_set_section_flags (bfd_of_glue_owner, s, flags)
2132 || !bfd_set_section_alignment (bfd_of_glue_owner, s, 2))
2133 {
2134 /* FIXME: set appropriate bfd error krk@cygnus.com */
2135 abort();
2136 }
2137 }
2138
2139 return;
2140 }
2141
2142 #include "coffcode.h"
2143
2144 const bfd_target
2145 #ifdef TARGET_LITTLE_SYM
2146 TARGET_LITTLE_SYM =
2147 #else
2148 armcoff_little_vec =
2149 #endif
2150 {
2151 #ifdef TARGET_LITTLE_NAME
2152 TARGET_LITTLE_NAME,
2153 #else
2154 "coff-arm-little",
2155 #endif
2156 bfd_target_coff_flavour,
2157 BFD_ENDIAN_LITTLE, /* data byte order is little */
2158 BFD_ENDIAN_LITTLE, /* header byte order is little */
2159
2160 (HAS_RELOC | EXEC_P | /* object flags */
2161 HAS_LINENO | HAS_DEBUG |
2162 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2163
2164 #ifndef COFF_WITH_PE
2165 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2166 #else
2167 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
2168 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
2169 #endif
2170
2171 #ifdef TARGET_UNDERSCORE
2172 TARGET_UNDERSCORE, /* leading underscore */
2173 #else
2174 0, /* leading underscore */
2175 #endif
2176 '/', /* ar_pad_char */
2177 15, /* ar_max_namelen */
2178
2179 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2180 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2181 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
2182 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2183 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2184 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
2185
2186 /* Note that we allow an object file to be treated as a core file as well. */
2187 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2188 bfd_generic_archive_p, coff_object_p},
2189 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
2190 bfd_false},
2191 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
2192 _bfd_write_archive_contents, bfd_false},
2193
2194 BFD_JUMP_TABLE_GENERIC (coff),
2195 BFD_JUMP_TABLE_COPY (coff),
2196 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2197 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
2198 BFD_JUMP_TABLE_SYMBOLS (coff),
2199 BFD_JUMP_TABLE_RELOCS (coff),
2200 BFD_JUMP_TABLE_WRITE (coff),
2201 BFD_JUMP_TABLE_LINK (coff),
2202 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2203
2204 (PTR) & bfd_coff_std_swap_table,
2205 };
2206
2207 const bfd_target
2208 #ifdef TARGET_BIG_SYM
2209 TARGET_BIG_SYM =
2210 #else
2211 armcoff_big_vec =
2212 #endif
2213 {
2214 #ifdef TARGET_BIG_NAME
2215 TARGET_BIG_NAME,
2216 #else
2217 "coff-arm-big",
2218 #endif
2219 bfd_target_coff_flavour,
2220 BFD_ENDIAN_BIG, /* data byte order is big */
2221 BFD_ENDIAN_BIG, /* header byte order is big */
2222
2223 (HAS_RELOC | EXEC_P | /* object flags */
2224 HAS_LINENO | HAS_DEBUG |
2225 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2226
2227 #ifndef COFF_WITH_PE
2228 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2229 #else
2230 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
2231 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
2232 #endif
2233
2234 #ifdef TARGET_UNDERSCORE
2235 TARGET_UNDERSCORE, /* leading underscore */
2236 #else
2237 0, /* leading underscore */
2238 #endif
2239 '/', /* ar_pad_char */
2240 15, /* ar_max_namelen */
2241
2242 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2243 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2244 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
2245 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2246 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2247 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
2248
2249 /* Note that we allow an object file to be treated as a core file as well. */
2250 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2251 bfd_generic_archive_p, coff_object_p},
2252 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
2253 bfd_false},
2254 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
2255 _bfd_write_archive_contents, bfd_false},
2256
2257 BFD_JUMP_TABLE_GENERIC (coff),
2258 BFD_JUMP_TABLE_COPY (coff),
2259 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2260 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
2261 BFD_JUMP_TABLE_SYMBOLS (coff),
2262 BFD_JUMP_TABLE_RELOCS (coff),
2263 BFD_JUMP_TABLE_WRITE (coff),
2264 BFD_JUMP_TABLE_LINK (coff),
2265 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2266
2267 (PTR) & bfd_coff_std_swap_table,
2268 };