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.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "coff/internal.h"
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))
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
**));
53 static bfd_reloc_status_type
54 aoutarm_fix_pcrel_26_done
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
55 asection
*, bfd
*, char **));
57 static bfd_reloc_status_type
58 aoutarm_fix_pcrel_26
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
59 asection
*, bfd
*, char **));
61 static bfd_reloc_status_type
62 coff_thumb_pcrel_23
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
63 asection
*, bfd
*, char **));
65 static bfd_reloc_status_type
66 coff_thumb_pcrel_12
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
67 asection
*, bfd
*, char **));
69 static bfd_reloc_status_type
70 coff_thumb_pcrel_9
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
71 asection
*, bfd
*, char **));
73 static bfd_reloc_status_type
74 coff_arm_reloc
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*,
78 coff_arm_adjust_symndx
PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*,
79 asection
*, struct internal_reloc
*,
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.
88 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
89 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
91 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
92 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
94 /* Used by the assembler. */
95 static bfd_reloc_status_type
96 coff_arm_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
, output_bfd
,
102 asection
*input_section
;
104 char **error_message
;
107 if (output_bfd
== (bfd
*) NULL
)
108 return bfd_reloc_continue
;
110 diff
= reloc_entry
->addend
;
113 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
117 reloc_howto_type
*howto
= reloc_entry
->howto
;
118 unsigned char *addr
= (unsigned char *) data
+ reloc_entry
->address
;
124 char x
= bfd_get_8 (abfd
, addr
);
126 bfd_put_8 (abfd
, x
, addr
);
132 short x
= bfd_get_16 (abfd
, addr
);
134 bfd_put_16 (abfd
, x
, addr
);
140 long x
= bfd_get_32 (abfd
, addr
);
142 bfd_put_32 (abfd
, x
, addr
);
151 /* Now let bfd_perform_relocation finish everything up. */
152 return bfd_reloc_continue
;
155 #define TARGET_UNDERSCORE '_'
158 #define PCRELOFFSET true
161 /* These most certainly belong somewhere else. Just had to get rid of
162 the manifest constants in the code. */
176 #define ARM_THUMB9 12
177 #define ARM_THUMB12 13
178 #define ARM_THUMB23 14
180 static reloc_howto_type aoutarm_std_reloc_howto
[] =
182 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
183 HOWTO(ARM_8
, /* type */
187 false, /* pc_relative */
189 complain_overflow_bitfield
, /* complain_on_overflow */
190 coff_arm_reloc
, /* special_function */
192 true, /* partial_inplace */
193 0x000000ff, /* src_mask */
194 0x000000ff, /* dst_mask */
195 PCRELOFFSET
/* pcrel_offset */),
202 complain_overflow_bitfield
,
215 complain_overflow_bitfield
,
228 complain_overflow_signed
,
229 aoutarm_fix_pcrel_26
,
241 complain_overflow_signed
,
254 complain_overflow_signed
,
267 complain_overflow_signed
,
280 complain_overflow_signed
,
281 aoutarm_fix_pcrel_26_done
,
295 complain_overflow_bitfield
,
308 complain_overflow_bitfield
,
321 complain_overflow_bitfield
,
334 complain_overflow_signed
,
347 complain_overflow_signed
,
348 coff_thumb_pcrel_12
,
360 complain_overflow_signed
,
361 coff_thumb_pcrel_23
,
369 /* Return true if this relocation should
370 appear in the output .reloc section. */
372 static boolean
in_reloc_p (abfd
, howto
)
374 reloc_howto_type
*howto
;
376 return !howto
->pc_relative
&& howto
->type
!= 11;
381 #define RTYPE2HOWTO(cache_ptr, dst) \
382 (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
384 #define coff_rtype_to_howto coff_arm_rtype_to_howto
386 static reloc_howto_type
*
387 coff_arm_rtype_to_howto (abfd
, sec
, rel
, h
, sym
, addendp
)
390 struct internal_reloc
*rel
;
391 struct coff_link_hash_entry
*h
;
392 struct internal_syment
*sym
;
395 reloc_howto_type
*howto
;
397 howto
= aoutarm_std_reloc_howto
+ rel
->r_type
;
399 if (rel
->r_type
== ARM_RVA32
)
401 *addendp
-= pe_data(sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
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
409 if (rel
->r_type
== ARM_26
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
)
415 static reloc_howto_type fake_arm26_reloc
=
422 complain_overflow_signed
,
423 aoutarm_fix_pcrel_26
,
430 *addendp
-= rel
->r_vaddr
- sec
->vma
;
431 return & fake_arm26_reloc
;
437 /* Used by the assembler. */
439 static bfd_reloc_status_type
440 aoutarm_fix_pcrel_26_done (abfd
, reloc_entry
, symbol
, data
, input_section
,
441 output_bfd
, error_message
)
443 arelent
*reloc_entry
;
446 asection
*input_section
;
448 char **error_message
;
450 /* This is dead simple at present. */
454 /* Used by the assembler. */
456 static bfd_reloc_status_type
457 aoutarm_fix_pcrel_26 (abfd
, reloc_entry
, symbol
, data
, input_section
,
458 output_bfd
, error_message
)
460 arelent
*reloc_entry
;
463 asection
*input_section
;
465 char **error_message
;
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
;
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
;
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
;
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
;
494 return bfd_reloc_overflow
;
496 /* Check for overflow */
497 if (relocation
& 0x02000000)
499 if ((relocation
& ~0x03ffffff) != ~0x03ffffff)
500 flag
= bfd_reloc_overflow
;
502 else if (relocation
& ~0x03ffffff)
503 flag
= bfd_reloc_overflow
;
505 target
&= ~0x00ffffff;
506 target
|= (relocation
>> 2) & 0x00ffffff;
507 bfd_put_32 (abfd
, target
, (bfd_byte
*) data
+ addr
);
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
];
516 typedef enum {bunknown
, b9
, b12
, b23
} thumb_pcrel_branchtype
;
518 static bfd_reloc_status_type
519 coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
, input_section
,
520 output_bfd
, error_message
, btype
)
522 arelent
*reloc_entry
;
525 asection
*input_section
;
527 char **error_message
;
528 thumb_pcrel_branchtype btype
;
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
;
538 /* NOTE: This routine is currently used by GAS, but not by the link
546 signbit
= 0x00000100;
552 signbit
= 0x00000800;
558 signbit
= 0x00400000;
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
;
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
;
580 relocation
= ((target
& dstmsk
) << 1);
584 if (bfd_big_endian (abfd
))
585 relocation
= ((target
& 0x7ff) << 1) | ((target
& 0x07ff0000) >> 4);
587 relocation
= ((target
& 0x7ff) << 12) | ((target
& 0x07ff0000) >> 15);
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
;
601 return bfd_reloc_overflow
;
603 /* Check for overflow */
604 if (relocation
& signbit
)
606 if ((relocation
& ~offmsk
) != ~offmsk
)
607 flag
= bfd_reloc_overflow
;
609 else if (relocation
& ~offmsk
)
610 flag
= bfd_reloc_overflow
;
617 target
|= (relocation
>> 1);
621 if (bfd_big_endian (abfd
))
622 target
|= ((relocation
& 0xfff) >> 1) | ((relocation
<< 4) & 0x07ff0000);
624 target
|= ((relocation
& 0xffe) << 15) | ((relocation
>> 12) & 0x7ff);
628 bfd_put_32 (abfd
, target
, (bfd_byte
*) data
+ addr
);
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
];
634 /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations */
638 static bfd_reloc_status_type
639 coff_thumb_pcrel_23 (abfd
, reloc_entry
, symbol
, data
, input_section
,
640 output_bfd
, error_message
)
642 arelent
*reloc_entry
;
645 asection
*input_section
;
647 char **error_message
;
649 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
650 input_section
, output_bfd
, error_message
, b23
);
653 static bfd_reloc_status_type
654 coff_thumb_pcrel_12 (abfd
, reloc_entry
, symbol
, data
, input_section
,
655 output_bfd
, error_message
)
657 arelent
*reloc_entry
;
660 asection
*input_section
;
662 char **error_message
;
664 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
665 input_section
, output_bfd
, error_message
, b12
);
668 static bfd_reloc_status_type
669 coff_thumb_pcrel_9 (abfd
, reloc_entry
, symbol
, data
, input_section
,
670 output_bfd
, error_message
)
672 arelent
*reloc_entry
;
675 asection
*input_section
;
677 char **error_message
;
679 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
680 input_section
, output_bfd
, error_message
, b9
);
684 static CONST
struct reloc_howto_struct
*
685 arm_reloc_type_lookup(abfd
,code
)
687 bfd_reloc_code_real_type code
;
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
)
696 default: return (CONST
struct reloc_howto_struct
*) 0;
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;
717 #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup
719 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
720 #define COFF_PAGE_SIZE 0x1000
721 /* Turn a howto into a reloc nunmber */
723 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
724 #define BADMAG(x) ARMBADMAG(x)
725 #define ARM 1 /* Customize coffcode.h */
727 /* The set of global variables that mark the total size of each kind
729 static long int global_thumb_glue_size
= 0;
730 static long int global_arm_glue_size
= 0;
732 static bfd
* bfd_of_glue_owner
= NULL
;
734 /* some typedefs for holding instructions */
735 typedef unsigned long int insn32
;
736 typedef unsigned short int insn16
;
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
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
750 Combine together and shifted left by 1 (it's a half word address) and
754 H-0, upper address-0 = 000
756 H-1, lower address-0 = 800
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
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 */
767 #define LOW_HI_ORDER 0xF800F000
768 #define HI_LOW_ORDER 0xF000F800
771 insert_thumb_branch (br_insn
, rel_off
)
775 unsigned int low_bits
;
776 unsigned int high_bits
;
779 BFD_ASSERT((rel_off
& 1) != 1);
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 */
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
;
790 abort(); /* error - not a valid branch instruction form */
792 /* FIXME: abort is probably not the right call. krk@cygnus.com */
798 static struct coff_link_hash_entry
*
799 find_thumb_glue (info
, name
, input_bfd
)
800 struct bfd_link_info
* info
;
805 struct coff_link_hash_entry
* myh
= 0;
808 bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
)));
810 BFD_ASSERT (tmp_name
);
812 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
814 myh
= coff_link_hash_lookup (coff_hash_table (info
),
819 _bfd_error_handler ("%s: unable to find THUMB glue '%s' for `%s'",
820 bfd_get_filename (input_bfd
), tmp_name
, name
);
828 static struct coff_link_hash_entry
*
829 find_arm_glue (info
, name
, input_bfd
)
830 struct bfd_link_info
* info
;
835 struct coff_link_hash_entry
*myh
= 0;
838 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
)));
840 BFD_ASSERT (tmp_name
);
842 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
844 myh
= coff_link_hash_lookup (coff_hash_table (info
),
850 _bfd_error_handler ("%s: unable to find ARM glue '%s' for `%s'",
851 bfd_get_filename (input_bfd
), tmp_name
, name
);
867 .word func @ behave as if you saw a ARM_32 reloc
869 ldr ip,8 <__func_addr> e59fc000
875 #define ARM2THUMB_GLUE_SIZE 12
877 a2t1_ldr_insn
= 0xe59fc000,
878 a2t2_bx_r12_insn
= 0xe12fff1c,
879 a2t3_func_addr_insn
= 0x00000001;
890 __func_change_to_arm:
900 #define THUMB2ARM_GLUE_SIZE 8
902 t2a1_bx_pc_insn
= 0x4778,
903 t2a2_noop_insn
= 0x46c0;
905 t2a3_b_insn
= 0xea000000;
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.
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
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.
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). */
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. */
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. */
949 coff_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
950 contents
, relocs
, syms
, sections
)
952 struct bfd_link_info
*info
;
954 asection
*input_section
;
956 struct internal_reloc
*relocs
;
957 struct internal_syment
*syms
;
960 struct internal_reloc
* rel
;
961 struct internal_reloc
* relend
;
964 relend
= rel
+ input_section
->reloc_count
;
966 for (; rel
< relend
; rel
++)
970 struct coff_link_hash_entry
*h
;
971 struct internal_syment
*sym
;
974 reloc_howto_type
*howto
;
975 bfd_reloc_status_type rstat
;
978 symndx
= rel
->r_symndx
;
987 h
= obj_coff_sym_hashes (input_bfd
)[symndx
];
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. */
996 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
997 addend
= - sym
->n_value
;
1002 howto
= bfd_coff_rtype_to_howto (input_bfd
, input_section
, rel
, h
,
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
)
1013 if (info
->relocateable
)
1015 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
1016 addend
+= sym
->n_value
;
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
)
1035 sec
= bfd_abs_section_ptr
;
1040 sec
= sections
[symndx
];
1041 val
= (sec
->output_section
->vma
1042 + sec
->output_offset
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
))
1060 asection
* h_sec
= h
->root
.u
.def
.section
;
1061 const char * name
= h
->root
.root
.string
;
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
);
1068 if (howto
->type
== ARM_26
)
1070 if ( h
->class == C_THUMBSTATFUNC
1071 || h
->class == C_THUMBEXTFUNC
)
1073 /* Arm code calling a Thumb function */
1074 signed long int final_disp
;
1075 unsigned long int tmp
;
1079 unsigned long int return_address
;
1080 long int ret_offset
;
1082 struct coff_link_hash_entry
* myh
;
1084 myh
= find_arm_glue (info
, name
, input_bfd
);
1088 my_offset
= myh
->root
.u
.def
.value
;
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
);
1095 if ((my_offset
& 0x01) == 0x01)
1097 if (h_sec
->owner
!= NULL
1098 && INTERWORK_SET (h_sec
->owner
)
1099 && ! INTERWORK_FLAG (h_sec
->owner
))
1100 _bfd_error_handler ("%s: warning: interworking not enabled.",
1101 bfd_get_filename (h_sec
->owner
));
1104 myh
->root
.u
.def
.value
= my_offset
;
1106 bfd_put_32 (output_bfd
, a2t1_ldr_insn
, s
->contents
+ my_offset
);
1108 bfd_put_32 (output_bfd
, a2t2_bx_r12_insn
, s
->contents
+ my_offset
+ 4);
1110 /* It's a thumb address. Add the low order bit. */
1111 bfd_put_32 (output_bfd
, h_val
| a2t3_func_addr_insn
, s
->contents
+ my_offset
+ 8);
1114 BFD_ASSERT (my_offset
<= global_arm_glue_size
);
1116 tmp
= bfd_get_32 (input_bfd
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1118 tmp
= tmp
& 0xFF000000;
1120 /* Somehow these are both 4 too far, so subtract 8. */
1124 + s
->output_section
->vma
1125 - (input_section
->output_offset
1126 + input_section
->output_section
->vma
1130 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1132 bfd_put_32 (output_bfd
, tmp
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1138 /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12 */
1139 else if (howto
->type
== ARM_THUMB23
)
1141 if ( h
->class == C_EXT
1142 || h
->class == C_STAT
1143 || h
->class == C_LABEL
)
1145 /* Thumb code calling an ARM function */
1146 unsigned long int return_address
;
1147 signed long int final_disp
;
1150 unsigned long int tmp
;
1151 long int ret_offset
;
1152 struct coff_link_hash_entry
* myh
;
1154 myh
= find_thumb_glue (info
, name
, input_bfd
);
1158 my_offset
= myh
->root
.u
.def
.value
;
1160 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
1161 THUMB2ARM_GLUE_SECTION_NAME
);
1163 BFD_ASSERT (s
!= NULL
);
1164 BFD_ASSERT (s
->contents
!= NULL
);
1166 if ((my_offset
& 0x01) == 0x01)
1168 if (h_sec
->owner
!= NULL
1169 && INTERWORK_SET (h_sec
->owner
)
1170 && ! INTERWORK_FLAG (h_sec
->owner
))
1171 _bfd_error_handler ("%s: warning: interworking not enabled.",
1172 bfd_get_filename (h_sec
->owner
));
1175 myh
->root
.u
.def
.value
= my_offset
;
1177 bfd_put_16 (output_bfd
, t2a1_bx_pc_insn
,
1178 s
->contents
+ my_offset
);
1180 bfd_put_16 (output_bfd
, t2a2_noop_insn
,
1181 s
->contents
+ my_offset
+ 2);
1185 ((signed)(s
->output_offset
1187 + s
->output_section
->vma
))
1190 t2a3_b_insn
|= ((ret_offset
>> 2) & 0x00FFFFFF);
1192 bfd_put_32 (output_bfd
, t2a3_b_insn
, s
->contents
+ my_offset
+ 4);
1195 BFD_ASSERT (my_offset
<= global_thumb_glue_size
);
1197 /* Now go back and fix up the original bl insn to point here. */
1201 - (input_section
->output_offset
1205 tmp
= bfd_get_32 (input_bfd
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1207 bfd_put_32 (output_bfd
,
1208 insert_thumb_branch (tmp
, ret_offset
),
1209 contents
+ rel
->r_vaddr
- input_section
->vma
);
1216 /* If the relocation type and destination symbol does not
1217 fall into one of the above categories, then we can just
1218 perform a direct link. */
1221 rstat
= bfd_reloc_ok
;
1223 #endif /* THUMBEXTENSION */
1224 if ( h
->root
.type
== bfd_link_hash_defined
1225 || h
->root
.type
== bfd_link_hash_defweak
)
1229 sec
= h
->root
.u
.def
.section
;
1230 val
= (h
->root
.u
.def
.value
1231 + sec
->output_section
->vma
1232 + sec
->output_offset
);
1235 else if (! info
->relocateable
)
1237 if (! ((*info
->callbacks
->undefined_symbol
)
1238 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
1239 rel
->r_vaddr
- input_section
->vma
)))
1244 if (info
->base_file
)
1246 /* Emit a reloc if the backend thinks it needs it. */
1247 if (sym
&& pe_data(output_bfd
)->in_reloc_p(output_bfd
, howto
))
1249 /* relocation to a symbol in a section which
1250 isn't absolute - we output the address here
1252 bfd_vma addr
= rel
->r_vaddr
1253 - input_section
->vma
1254 + input_section
->output_offset
1255 + input_section
->output_section
->vma
;
1256 if (coff_data(output_bfd
)->pe
)
1257 addr
-= pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1258 /* FIXME: Shouldn't 4 be sizeof (addr)? */
1259 fwrite (&addr
, 1,4, (FILE *) info
->base_file
);
1263 #if 1 /* THUMBEXTENSION */
1266 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1267 else if (! info
->relocateable
1268 && howto
->type
== ARM_THUMB23
)
1270 /* This is pretty much a copy of what the default
1271 _bfd_final_link_relocate and _bfd_relocate_contents
1272 routines do to perform a relocation, with special
1273 processing for the split addressing of the Thumb BL
1274 instruction. Again, it would probably be simpler adding a
1275 ThumbBRANCH23 specific macro expansion into the default
1278 bfd_vma address
= rel
->r_vaddr
- input_section
->vma
;
1280 if (address
> input_section
->_raw_size
)
1281 rstat
= bfd_reloc_outofrange
;
1284 bfd_vma relocation
= val
+ addend
;
1285 int size
= bfd_get_reloc_size (howto
);
1286 boolean overflow
= false;
1287 bfd_byte
* location
= contents
+ address
;
1288 bfd_vma x
= bfd_get_32 (input_bfd
, location
);
1289 bfd_vma src_mask
= 0x007FFFFE;
1290 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1291 bfd_signed_vma reloc_signed_min
= ~reloc_signed_max
;
1293 bfd_signed_vma signed_check
;
1295 bfd_signed_vma signed_add
;
1297 BFD_ASSERT (size
== 4);
1299 /* howto->pc_relative should be TRUE for type 14 BRANCH23 */
1300 relocation
-= (input_section
->output_section
->vma
1301 + input_section
->output_offset
);
1303 /* howto->pcrel_offset should be TRUE for type 14 BRANCH23 */
1304 relocation
-= address
;
1306 /* No need to negate the relocation with BRANCH23. */
1307 /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23. */
1308 /* howto->rightshift == 1 */
1309 /* Drop unwanted bits from the value we are relocating to. */
1311 check
= relocation
>> howto
->rightshift
;
1313 /* If this is a signed value, the rightshift just dropped
1314 leading 1 bits (assuming twos complement). */
1315 if ((bfd_signed_vma
) relocation
>= 0)
1316 signed_check
= check
;
1318 signed_check
= (check
1320 & ~((bfd_vma
) - 1 >> howto
->rightshift
)));
1322 /* Get the value from the object file. */
1323 if (bfd_big_endian (input_bfd
))
1325 add
= (((x
) & 0x07ff0000) >> 4) | (((x
) & 0x7ff) << 1);
1329 add
= ((((x
) & 0x7ff) << 12) | (((x
) & 0x07ff0000) >> 15));
1332 /* Get the value from the object file with an appropriate sign.
1333 The expression involving howto->src_mask isolates the upper
1334 bit of src_mask. If that bit is set in the value we are
1335 adding, it is negative, and we subtract out that number times
1336 two. If src_mask includes the highest possible bit, then we
1337 can not get the upper bit, but that does not matter since
1338 signed_add needs no adjustment to become negative in that
1343 if ((add
& (((~ src_mask
) >> 1) & src_mask
)) != 0)
1344 signed_add
-= (((~ src_mask
) >> 1) & src_mask
) << 1;
1346 /* Add the value from the object file, shifted so that it is a
1348 /* howto->bitpos == 0 */
1350 signed_check
+= signed_add
;
1351 relocation
+= signed_add
;
1353 BFD_ASSERT (howto
->complain_on_overflow
== complain_overflow_signed
);
1355 /* Assumes two's complement. */
1356 if ( signed_check
> reloc_signed_max
1357 || signed_check
< reloc_signed_min
)
1360 /* Put RELOCATION into the correct bits: */
1362 if (bfd_big_endian (input_bfd
))
1364 relocation
= (((relocation
& 0xffe) >> 1) | ((relocation
<< 4) & 0x07ff0000));
1368 relocation
= (((relocation
& 0xffe) << 15) | ((relocation
>> 12) & 0x7ff));
1371 /* Add RELOCATION to the correct bits of X: */
1372 x
= ((x
& ~howto
->dst_mask
) | relocation
);
1374 /* Put the relocated value back in the object file: */
1375 bfd_put_32 (input_bfd
, x
, location
);
1377 rstat
= overflow
? bfd_reloc_overflow
: bfd_reloc_ok
;
1381 #endif /* THUMBEXTENSION */
1382 rstat
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1384 rel
->r_vaddr
- input_section
->vma
,
1386 #if 1 /* THUMBEXTENSION */
1388 Is this the best way to fix up thumb addresses? krk@cygnus.com
1389 Probably not, but it works, and if it works it don't need fixing! nickc@cygnus.com */
1390 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1391 if (! info
->relocateable
1392 && rel
->r_type
== ARM_32
)
1394 /* Determine if we need to set the bottom bit of a relocated address
1395 because the address is the address of a Thumb code symbol. */
1397 int patchit
= false;
1400 && ( h
->class == C_THUMBSTATFUNC
1401 || h
->class == C_THUMBEXTFUNC
))
1405 else if (sym
!= NULL
1406 && sym
->n_scnum
> N_UNDEF
)
1408 /* No hash entry - use the symbol instead. */
1410 if ( sym
->n_sclass
== C_THUMBSTATFUNC
1411 || sym
->n_sclass
== C_THUMBEXTFUNC
)
1417 bfd_byte
* location
= contents
+ rel
->r_vaddr
- input_section
->vma
;
1418 bfd_vma x
= bfd_get_32 (input_bfd
, location
);
1420 bfd_put_32 (input_bfd
, x
| 1, location
);
1423 #endif /* THUMBEXTENSION */
1431 case bfd_reloc_outofrange
:
1432 (*_bfd_error_handler
)
1433 ("%s: bad reloc address 0x%lx in section `%s'",
1434 bfd_get_filename (input_bfd
),
1435 (unsigned long) rel
->r_vaddr
,
1436 bfd_get_section_name (input_bfd
, input_section
));
1438 case bfd_reloc_overflow
:
1441 char buf
[SYMNMLEN
+ 1];
1446 name
= h
->root
.root
.string
;
1449 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
1454 if (! ((*info
->callbacks
->reloc_overflow
)
1455 (info
, name
, howto
->name
, (bfd_vma
) 0, input_bfd
,
1456 input_section
, rel
->r_vaddr
- input_section
->vma
)))
1465 #ifndef COFF_WITH_PE
1467 arm_allocate_interworking_sections (info
)
1468 struct bfd_link_info
*info
;
1473 static char test_char
= '1';
1476 if (global_arm_glue_size
!= 0)
1478 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1480 s
= bfd_get_section_by_name (bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
1482 BFD_ASSERT (s
!= NULL
);
1484 foo
= (bfd_byte
*) bfd_alloc (bfd_of_glue_owner
, global_arm_glue_size
);
1486 memset (foo
, test_char
, global_arm_glue_size
);
1489 s
->_raw_size
= s
->_cooked_size
= global_arm_glue_size
;
1493 if (global_thumb_glue_size
!= 0)
1495 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1497 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1499 BFD_ASSERT (s
!= NULL
);
1501 foo
= (bfd_byte
*) bfd_alloc (bfd_of_glue_owner
, global_thumb_glue_size
);
1503 memset (foo
, test_char
, global_thumb_glue_size
);
1506 s
->_raw_size
= s
->_cooked_size
= global_thumb_glue_size
;
1514 record_arm_to_thumb_glue (info
, h
)
1515 struct bfd_link_info
* info
;
1516 struct coff_link_hash_entry
* h
;
1518 const char * name
= h
->root
.root
.string
;
1519 register asection
* s
;
1521 struct coff_link_hash_entry
* myh
;
1524 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1526 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
1527 ARM2THUMB_GLUE_SECTION_NAME
);
1529 BFD_ASSERT (s
!= NULL
);
1531 tmp_name
= ((char *)
1532 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
)));
1534 BFD_ASSERT (tmp_name
);
1536 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
1538 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1540 false, false, true);
1545 return; /* we've already seen this guy */
1549 /* The only trick here is using global_arm_glue_size as the value. Even
1550 though the section isn't allocated yet, this is where we will be putting
1553 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1554 BSF_EXPORT
| BSF_GLOBAL
,
1555 s
, global_arm_glue_size
+ 1,
1557 (struct bfd_link_hash_entry
**) & myh
);
1559 global_arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
1567 record_thumb_to_arm_glue (info
, h
)
1568 struct bfd_link_info
* info
;
1569 struct coff_link_hash_entry
* h
;
1571 const char * name
= h
->root
.root
.string
;
1572 register asection
* s
;
1574 struct coff_link_hash_entry
* myh
;
1576 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1578 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1580 BFD_ASSERT (s
!= NULL
);
1582 tmp_name
= (char *) bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
));
1584 BFD_ASSERT (tmp_name
);
1586 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
1588 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1590 false, false, true);
1595 return; /* we've already seen this guy */
1598 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1599 BSF_LOCAL
, s
, global_thumb_glue_size
+ 1,
1601 (struct bfd_link_hash_entry
**) & myh
);
1603 /* if we mark it 'thumb', the disassembler will do a better job */
1604 myh
->class = C_THUMBEXTFUNC
;
1608 #define CHANGE_TO_ARM "__%s_change_to_arm"
1610 tmp_name
= ((char *)
1611 bfd_malloc (strlen (name
) + strlen (CHANGE_TO_ARM
)));
1613 BFD_ASSERT (tmp_name
);
1615 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
1619 /* now allocate another symbol to switch back to arm mode */
1620 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1621 BSF_LOCAL
, s
, global_thumb_glue_size
+ 4,
1623 (struct bfd_link_hash_entry
**) & myh
);
1627 global_thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
1633 arm_process_before_allocation (abfd
, info
)
1635 struct bfd_link_info
* info
;
1639 /* If we are only performing a partial link do not bother
1640 to construct any glue. */
1641 if (info
->relocateable
)
1644 /* Here we have a bfd that is to be included on the link. We have a hook
1645 to do reloc rummaging, before section sizes are nailed down. */
1647 _bfd_coff_get_external_symbols (abfd
);
1649 /* Rummage around all the relocs and map the glue vectors. */
1650 sec
= abfd
->sections
;
1655 for (; sec
!= NULL
; sec
= sec
->next
)
1657 struct internal_reloc
* i
;
1658 struct internal_reloc
* rel
;
1660 if (sec
->reloc_count
== 0)
1663 /* Load the relocs. */
1664 /* FIXME: there may be a storage leak here. */
1666 i
= _bfd_coff_read_internal_relocs (abfd
, sec
, 1, 0, 0, 0);
1668 BFD_ASSERT (i
!= 0);
1670 for (rel
= i
; rel
< i
+ sec
->reloc_count
; ++rel
)
1672 unsigned short r_type
= rel
->r_type
;
1674 struct coff_link_hash_entry
* h
;
1676 symndx
= rel
->r_symndx
;
1678 /* If the relocation is not against a symbol it cannot concern us. */
1682 h
= obj_coff_sym_hashes (abfd
)[symndx
];
1684 /* If the relocation is against a static symbol it must be within
1685 the current section and so canot be a cross ARM/Thumb relocation. */
1692 /* This one is a call from arm code. We need to look up
1693 the target of the call. If it is a thumb target, we
1696 if (h
->class == C_THUMBEXTFUNC
)
1698 record_arm_to_thumb_glue (info
, h
);
1703 /* This one is a call from thumb code. We used to look
1704 for ARM_THUMB9 and ARM_THUMB12 as well. We need to look
1705 up the target of the call. If it is an arm target, we
1713 record_thumb_to_arm_glue (info
, h
);
1728 #endif /* not COFF_WITH_PE */
1730 #define coff_relocate_section coff_arm_relocate_section
1732 /* When doing a relocateable link, we want to convert ARM26 relocs
1733 into ARM26D relocs. */
1736 coff_arm_adjust_symndx (obfd
, info
, ibfd
, sec
, irel
, adjustedp
)
1738 struct bfd_link_info
*info
;
1741 struct internal_reloc
*irel
;
1744 if (irel
->r_type
== 3)
1746 struct coff_link_hash_entry
*h
;
1748 h
= obj_coff_sym_hashes (ibfd
)[irel
->r_symndx
];
1750 && (h
->root
.type
== bfd_link_hash_defined
1751 || h
->root
.type
== bfd_link_hash_defweak
)
1752 && h
->root
.u
.def
.section
->output_section
== sec
->output_section
)
1759 #ifndef COFF_WITH_PE
1761 /* Called when merging the private data areas of two BFDs.
1762 This is important as it allows us to detect if we are
1763 attempting to merge binaries compiled for different ARM
1764 targets, eg different CPUs or differents APCS's. */
1767 coff_arm_bfd_merge_private_bfd_data (ibfd
, obfd
)
1771 BFD_ASSERT (ibfd
!= NULL
&& obfd
!= NULL
);
1776 /* If the two formats are different we cannot merge anything.
1777 This is not an error, since it is permissable to change the
1778 input and output formats. */
1779 if (ibfd
->xvec
!= obfd
->xvec
)
1782 /* Verify that the APCS is the same for the two BFDs */
1783 if (APCS_SET (ibfd
))
1785 if (APCS_SET (obfd
))
1787 /* If the src and dest have different APCS flag bits set, fail. */
1788 if (APCS_26_FLAG (obfd
) != APCS_26_FLAG (ibfd
))
1791 ("%s: ERROR: compiled for APCS-%d whereas target %s uses APCS-%d",
1792 bfd_get_filename (ibfd
), APCS_26_FLAG (ibfd
) ? 26 : 32,
1793 bfd_get_filename (obfd
), APCS_26_FLAG (obfd
) ? 26 : 32
1796 bfd_set_error (bfd_error_wrong_format
);
1800 if (APCS_FLOAT_FLAG (obfd
) != APCS_FLOAT_FLAG (ibfd
))
1803 ("%s: ERROR: passes floats in %s registers whereas target %s uses %s registers",
1804 bfd_get_filename (ibfd
), APCS_FLOAT_FLAG (ibfd
) ? "float" : "integer",
1805 bfd_get_filename (obfd
), APCS_FLOAT_FLAG (obfd
) ? "float" : "integer"
1808 bfd_set_error (bfd_error_wrong_format
);
1812 if (PIC_FLAG (obfd
) != PIC_FLAG (ibfd
))
1815 ("%s: ERROR: compiled as %s code, whereas target %s is %s",
1816 bfd_get_filename (ibfd
), PIC_FLAG (ibfd
) ? "position independent" : "absoluste position",
1817 bfd_get_filename (obfd
), PIC_FLAG (obfd
) ? "position independent" : "absoluste position"
1820 bfd_set_error (bfd_error_wrong_format
);
1826 SET_APCS_FLAGS (obfd
, APCS_26_FLAG (ibfd
) | APCS_FLOAT_FLAG (ibfd
) | PIC_FLAG (ibfd
));
1828 /* Set up the arch and fields as well as these are probably wrong. */
1829 bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
1833 /* Check the interworking support. */
1834 if (INTERWORK_SET (ibfd
))
1836 if (INTERWORK_SET (obfd
))
1838 /* If the src and dest differ in their interworking issue a warning. */
1839 if (INTERWORK_FLAG (obfd
) != INTERWORK_FLAG (ibfd
))
1842 ("Warning: input file %s %s interworking, whereas %s does%s",
1843 bfd_get_filename (ibfd
),
1844 INTERWORK_FLAG (ibfd
) ? "supports" : "does not support",
1845 bfd_get_filename (obfd
),
1846 INTERWORK_FLAG (obfd
) ? "." : " not."
1852 SET_INTERWORK_FLAG (obfd
, INTERWORK_FLAG (ibfd
));
1860 /* Display the flags field. */
1863 coff_arm_bfd_print_private_bfd_data (abfd
, ptr
)
1867 FILE * file
= (FILE *) ptr
;
1869 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
)
1871 fprintf (file
, "private flags = %x", coff_data (abfd
)->flags
);
1873 if (APCS_SET (abfd
))
1874 fprintf (file
, ": [APCS-%d] [floats passed in %s registers] [%s]",
1875 APCS_26_FLAG (abfd
) ? 26 : 32,
1876 APCS_FLOAT_FLAG (abfd
) ? "float" : "integer",
1877 PIC_FLAG (abfd
) ? "position independent" : "absolute position"
1880 if (INTERWORK_SET (abfd
))
1881 fprintf (file
, ": [interworking %ssupported]",
1882 INTERWORK_FLAG (abfd
) ? "" : "not " );
1890 /* Copies the given flags into the coff_tdata.flags field.
1891 Typically these flags come from the f_flags[] field of
1892 the COFF filehdr structure, which contains important,
1893 target specific information. */
1896 coff_arm_bfd_set_private_flags (abfd
, flags
)
1902 BFD_ASSERT (abfd
!= NULL
);
1904 flag
= (flags
& F_APCS26
) ? F_APCS_26
: 0;
1906 /* Make sure that the APCS field has not been initialised to the opposite value. */
1908 && ( (APCS_26_FLAG (abfd
) != flag
)
1909 || (APCS_FLOAT_FLAG (abfd
) != (flags
& F_APCS_FLOAT
))
1910 || (PIC_FLAG (abfd
) != (flags
& F_PIC
))
1914 flag
|= (flags
& (F_APCS_FLOAT
| F_PIC
));
1916 SET_APCS_FLAGS (abfd
, flag
);
1918 flag
= (flags
& F_INTERWORK
);
1920 /* If either the flags or the BFD do support interworking then do not set the interworking flag. */
1921 if (INTERWORK_SET (abfd
) && (INTERWORK_FLAG (abfd
) != flag
))
1924 SET_INTERWORK_FLAG (abfd
, flag
);
1930 /* Copy the important parts of the target specific data
1931 from one instance of a BFD to another. */
1934 coff_arm_bfd_copy_private_bfd_data (src
, dest
)
1938 BFD_ASSERT (src
!= NULL
&& dest
!= NULL
);
1943 /* If the destination is not in the same format as the source, do not do the copy. */
1944 if (src
->xvec
!= dest
->xvec
)
1947 /* copy the flags field */
1950 if (APCS_SET (dest
))
1952 /* If the src and dest have different APCS flag bits set, fail. */
1953 if (APCS_26_FLAG (dest
) != APCS_26_FLAG (src
))
1956 if (APCS_FLOAT_FLAG (dest
) != APCS_FLOAT_FLAG (src
))
1959 if (PIC_FLAG (dest
) != PIC_FLAG (src
))
1963 SET_APCS_FLAGS (dest
, APCS_26_FLAG (src
) | APCS_FLOAT_FLAG (src
) | PIC_FLAG (src
));
1966 if (INTERWORK_SET (src
))
1968 if (INTERWORK_SET (dest
))
1970 /* If the src and dest have different interworking flags then turn off the interworking bit. */
1971 if (INTERWORK_FLAG (dest
) != INTERWORK_FLAG (src
))
1972 SET_INTERWORK_FLAG (dest
, 0);
1976 SET_INTERWORK_FLAG (dest
, INTERWORK_FLAG (src
));
1982 #endif /* not COFF_WITH_PE */
1984 /* Note: the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX
1985 *must* match the definitions on gcc/config/arm/semi.h. */
1986 #define LOCAL_LABEL_PREFIX "."
1987 #define USER_LABEL_PREFIX "_"
1990 coff_arm_is_local_label_name (abfd
, name
)
1994 #ifdef LOCAL_LABEL_PREFIX
1995 /* If there is a prefix for local labels then look for this.
1996 If the prefix exists, but it is empty, then ignore the test. */
1998 if (LOCAL_LABEL_PREFIX
[0] != 0)
2000 if (strncmp (name
, LOCAL_LABEL_PREFIX
, strlen (LOCAL_LABEL_PREFIX
)) == 0)
2004 #ifdef USER_LABEL_PREFIX
2005 if (USER_LABEL_PREFIX
[0] != 0)
2007 if (strncmp (name
, USER_LABEL_PREFIX
, strlen (USER_LABEL_PREFIX
)) == 0)
2012 /* devo/gcc/config/dbxcoff.h defines ASM_OUTPUT_SOURCE_LINE to generate local line numbers as .LM<number>, so treat these as local. */
2016 case 'L': return true;
2017 case '.': return (name
[1] == 'L' && name
[2] == 'M') ? true : false;
2018 default: return false; /* Cannot make our minds up - default to false so that it will not be stripped by accident. */
2022 #define coff_bfd_is_local_label_name coff_arm_is_local_label_name
2023 #define coff_adjust_symndx coff_arm_adjust_symndx
2025 #ifndef COFF_WITH_PE
2026 #define coff_bfd_merge_private_bfd_data coff_arm_bfd_merge_private_bfd_data
2027 #define coff_bfd_print_private_bfd_data coff_arm_bfd_print_private_bfd_data
2028 #define coff_bfd_set_private_flags coff_arm_bfd_set_private_flags
2029 #define coff_bfd_copy_private_bfd_data coff_arm_bfd_copy_private_bfd_data
2031 /* This piece of machinery exists only to guarantee that the bfd that holds
2032 the glue section is written last.
2034 This does depend on bfd_make_section attaching a new section to the
2035 end of the section list for the bfd.
2040 coff_arm_link_output_has_begun (sub
)
2043 return (sub
->output_has_begun
|| sub
== bfd_of_glue_owner
);
2047 coff_arm_final_link_postscript (abfd
, pfinfo
)
2049 struct coff_final_link_info
* pfinfo
;
2051 if (bfd_of_glue_owner
!= NULL
)
2053 if (! _bfd_coff_link_input_bfd (pfinfo
, bfd_of_glue_owner
))
2055 bfd_of_glue_owner
->output_has_begun
= true;
2059 #define coff_link_output_has_begun coff_arm_link_output_has_begun
2060 #define coff_final_link_postscript coff_arm_final_link_postscript
2063 #define coff_SWAP_sym_in arm_bfd_coff_swap_sym_in
2065 static void coff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
2067 /* Sepcial version of symbol swapper, used to grab a bfd
2068 onto which the glue sections can be attached. */
2070 arm_bfd_coff_swap_sym_in (abfd
, ext1
, in1
)
2076 register asection
* s
;
2078 /* Do the normal swap in. */
2079 coff_swap_sym_in (abfd
, ext1
, in1
);
2081 if (bfd_of_glue_owner
!= NULL
) /* we already have a toc, so go home */
2084 /* Save the bfd for later allocation. */
2085 bfd_of_glue_owner
= abfd
;
2087 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
2088 ARM2THUMB_GLUE_SECTION_NAME
);
2092 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2094 s
= bfd_make_section (bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
2097 || !bfd_set_section_flags (bfd_of_glue_owner
, s
, flags
)
2098 || !bfd_set_section_alignment (bfd_of_glue_owner
, s
, 2))
2100 /* FIXME: set appropriate bfd error */
2105 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2109 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2111 s
= bfd_make_section (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2114 || !bfd_set_section_flags (bfd_of_glue_owner
, s
, flags
)
2115 || !bfd_set_section_alignment (bfd_of_glue_owner
, s
, 2))
2117 /* FIXME: set appropriate bfd error krk@cygnus.com */
2125 #include "coffcode.h"
2128 #ifdef TARGET_LITTLE_SYM
2131 armcoff_little_vec
=
2134 #ifdef TARGET_LITTLE_NAME
2139 bfd_target_coff_flavour
,
2140 BFD_ENDIAN_LITTLE
, /* data byte order is little */
2141 BFD_ENDIAN_LITTLE
, /* header byte order is little */
2143 (HAS_RELOC
| EXEC_P
| /* object flags */
2144 HAS_LINENO
| HAS_DEBUG
|
2145 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2147 #ifndef COFF_WITH_PE
2148 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2150 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2151 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2154 #ifdef TARGET_UNDERSCORE
2155 TARGET_UNDERSCORE
, /* leading underscore */
2157 0, /* leading underscore */
2159 '/', /* ar_pad_char */
2160 15, /* ar_max_namelen */
2162 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2163 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2164 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2165 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2166 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2167 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2169 /* Note that we allow an object file to be treated as a core file as well. */
2170 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2171 bfd_generic_archive_p
, coff_object_p
},
2172 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2174 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2175 _bfd_write_archive_contents
, bfd_false
},
2177 BFD_JUMP_TABLE_GENERIC (coff
),
2178 BFD_JUMP_TABLE_COPY (coff
),
2179 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2180 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2181 BFD_JUMP_TABLE_SYMBOLS (coff
),
2182 BFD_JUMP_TABLE_RELOCS (coff
),
2183 BFD_JUMP_TABLE_WRITE (coff
),
2184 BFD_JUMP_TABLE_LINK (coff
),
2185 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2187 (PTR
) & bfd_coff_std_swap_table
,
2191 #ifdef TARGET_BIG_SYM
2197 #ifdef TARGET_BIG_NAME
2202 bfd_target_coff_flavour
,
2203 BFD_ENDIAN_BIG
, /* data byte order is big */
2204 BFD_ENDIAN_BIG
, /* header byte order is big */
2206 (HAS_RELOC
| EXEC_P
| /* object flags */
2207 HAS_LINENO
| HAS_DEBUG
|
2208 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2210 #ifndef COFF_WITH_PE
2211 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2213 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2214 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2217 #ifdef TARGET_UNDERSCORE
2218 TARGET_UNDERSCORE
, /* leading underscore */
2220 0, /* leading underscore */
2222 '/', /* ar_pad_char */
2223 15, /* ar_max_namelen */
2225 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2226 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2227 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
2228 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2229 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2230 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
2232 /* Note that we allow an object file to be treated as a core file as well. */
2233 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2234 bfd_generic_archive_p
, coff_object_p
},
2235 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2237 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2238 _bfd_write_archive_contents
, bfd_false
},
2240 BFD_JUMP_TABLE_GENERIC (coff
),
2241 BFD_JUMP_TABLE_COPY (coff
),
2242 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2243 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2244 BFD_JUMP_TABLE_SYMBOLS (coff
),
2245 BFD_JUMP_TABLE_RELOCS (coff
),
2246 BFD_JUMP_TABLE_WRITE (coff
),
2247 BFD_JUMP_TABLE_LINK (coff
),
2248 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2250 (PTR
) & bfd_coff_std_swap_table
,