1 /* BFD back-end for ARM COFF files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/internal.h"
36 #define APCS_26_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_26)
37 #define APCS_FLOAT_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_FLOAT)
38 #define PIC_FLAG( abfd ) (coff_data (abfd)->flags & F_PIC)
39 #define APCS_SET( abfd ) (coff_data (abfd)->flags & F_APCS_SET)
40 #define SET_APCS_FLAGS( abfd, flgs) (coff_data (abfd)->flags = \
41 (coff_data (abfd)->flags & ~ (F_APCS_26 | F_APCS_FLOAT | F_PIC)) \
42 | (flgs | F_APCS_SET))
43 #define INTERWORK_FLAG( abfd ) (coff_data (abfd)->flags & F_INTERWORK)
44 #define INTERWORK_SET( abfd ) (coff_data (abfd)->flags & F_INTERWORK_SET)
45 #define SET_INTERWORK_FLAG( abfd, flg ) (coff_data (abfd)->flags = \
46 (coff_data (abfd)->flags & ~ F_INTERWORK) \
47 | (flg | F_INTERWORK_SET))
50 static boolean coff_arm_relocate_section
51 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
52 struct internal_reloc
*, struct internal_syment
*, asection
**));
54 static bfd_reloc_status_type
55 aoutarm_fix_pcrel_26_done
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
56 asection
*, bfd
*, char **));
58 static bfd_reloc_status_type
59 aoutarm_fix_pcrel_26
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
60 asection
*, bfd
*, char **));
62 static bfd_reloc_status_type
63 coff_thumb_pcrel_23
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
64 asection
*, bfd
*, char **));
66 static bfd_reloc_status_type
67 coff_thumb_pcrel_12
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
68 asection
*, bfd
*, char **));
70 static bfd_reloc_status_type
71 coff_thumb_pcrel_9
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
72 asection
*, bfd
*, char **));
74 static bfd_reloc_status_type
75 coff_arm_reloc
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*,
79 coff_arm_adjust_symndx
PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*,
80 asection
*, struct internal_reloc
*,
83 /* The linker script knows the section names for placement.
84 The entry_names are used to do simple name mangling on the stubs.
85 Given a function name, and its type, the stub can be found. The
86 name can be changed. The only requirement is the %s be present.
89 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
90 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
92 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
93 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
95 /* Used by the assembler. */
96 static bfd_reloc_status_type
97 coff_arm_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
, output_bfd
,
100 arelent
*reloc_entry
;
103 asection
*input_section
;
105 char **error_message
;
108 if (output_bfd
== (bfd
*) NULL
)
109 return bfd_reloc_continue
;
111 diff
= reloc_entry
->addend
;
114 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
118 reloc_howto_type
*howto
= reloc_entry
->howto
;
119 unsigned char *addr
= (unsigned char *) data
+ reloc_entry
->address
;
125 char x
= bfd_get_8 (abfd
, addr
);
127 bfd_put_8 (abfd
, x
, addr
);
133 short x
= bfd_get_16 (abfd
, addr
);
135 bfd_put_16 (abfd
, x
, addr
);
141 long x
= bfd_get_32 (abfd
, addr
);
143 bfd_put_32 (abfd
, x
, addr
);
152 /* Now let bfd_perform_relocation finish everything up. */
153 return bfd_reloc_continue
;
156 #define TARGET_UNDERSCORE '_'
159 #define PCRELOFFSET true
162 /* These most certainly belong somewhere else. Just had to get rid of
163 the manifest constants in the code. */
177 #define ARM_THUMB9 12
178 #define ARM_THUMB12 13
179 #define ARM_THUMB23 14
181 static reloc_howto_type aoutarm_std_reloc_howto
[] =
183 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
184 HOWTO(ARM_8
, /* type */
188 false, /* pc_relative */
190 complain_overflow_bitfield
, /* complain_on_overflow */
191 coff_arm_reloc
, /* special_function */
193 true, /* partial_inplace */
194 0x000000ff, /* src_mask */
195 0x000000ff, /* dst_mask */
196 PCRELOFFSET
/* pcrel_offset */),
203 complain_overflow_bitfield
,
216 complain_overflow_bitfield
,
229 complain_overflow_signed
,
230 aoutarm_fix_pcrel_26
,
242 complain_overflow_signed
,
255 complain_overflow_signed
,
268 complain_overflow_signed
,
281 complain_overflow_signed
,
282 aoutarm_fix_pcrel_26_done
,
296 complain_overflow_bitfield
,
309 complain_overflow_bitfield
,
322 complain_overflow_bitfield
,
335 complain_overflow_signed
,
348 complain_overflow_signed
,
349 coff_thumb_pcrel_12
,
361 complain_overflow_signed
,
362 coff_thumb_pcrel_23
,
370 /* Return true if this relocation should
371 appear in the output .reloc section. */
373 static boolean
in_reloc_p (abfd
, howto
)
375 reloc_howto_type
*howto
;
377 return !howto
->pc_relative
&& howto
->type
!= 11;
382 #define RTYPE2HOWTO(cache_ptr, dst) \
383 (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
385 #define coff_rtype_to_howto coff_arm_rtype_to_howto
387 static reloc_howto_type
*
388 coff_arm_rtype_to_howto (abfd
, sec
, rel
, h
, sym
, addendp
)
391 struct internal_reloc
*rel
;
392 struct coff_link_hash_entry
*h
;
393 struct internal_syment
*sym
;
396 reloc_howto_type
*howto
;
398 howto
= aoutarm_std_reloc_howto
+ rel
->r_type
;
400 if (rel
->r_type
== ARM_RVA32
)
402 *addendp
-= pe_data(sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
405 /* The relocation_section function will skip pcrel_offset relocs
406 when doing a relocateable link. However, we want to convert
407 ARM26 to ARM26D relocs if possible. We return a fake howto in
408 this case without pcrel_offset set, and adjust the addend to
410 if (rel
->r_type
== ARM_26
412 && (h
->root
.type
== bfd_link_hash_defined
413 || h
->root
.type
== bfd_link_hash_defweak
)
414 && h
->root
.u
.def
.section
->output_section
== sec
->output_section
)
416 static reloc_howto_type fake_arm26_reloc
=
423 complain_overflow_signed
,
424 aoutarm_fix_pcrel_26
,
431 *addendp
-= rel
->r_vaddr
- sec
->vma
;
432 return & fake_arm26_reloc
;
438 /* Used by the assembler. */
440 static bfd_reloc_status_type
441 aoutarm_fix_pcrel_26_done (abfd
, reloc_entry
, symbol
, data
, input_section
,
442 output_bfd
, error_message
)
444 arelent
*reloc_entry
;
447 asection
*input_section
;
449 char **error_message
;
451 /* This is dead simple at present. */
455 /* Used by the assembler. */
457 static bfd_reloc_status_type
458 aoutarm_fix_pcrel_26 (abfd
, reloc_entry
, symbol
, data
, input_section
,
459 output_bfd
, error_message
)
461 arelent
*reloc_entry
;
464 asection
*input_section
;
466 char **error_message
;
469 bfd_size_type addr
= reloc_entry
->address
;
470 long target
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ addr
);
471 bfd_reloc_status_type flag
= bfd_reloc_ok
;
473 /* If this is an undefined symbol, return error */
474 if (symbol
->section
== &bfd_und_section
475 && (symbol
->flags
& BSF_WEAK
) == 0)
476 return output_bfd
? bfd_reloc_continue
: bfd_reloc_undefined
;
478 /* If the sections are different, and we are doing a partial relocation,
479 just ignore it for now. */
480 if (symbol
->section
->name
!= input_section
->name
481 && output_bfd
!= (bfd
*)NULL
)
482 return bfd_reloc_continue
;
484 relocation
= (target
& 0x00ffffff) << 2;
485 relocation
= (relocation
^ 0x02000000) - 0x02000000; /* Sign extend */
486 relocation
+= symbol
->value
;
487 relocation
+= symbol
->section
->output_section
->vma
;
488 relocation
+= symbol
->section
->output_offset
;
489 relocation
+= reloc_entry
->addend
;
490 relocation
-= input_section
->output_section
->vma
;
491 relocation
-= input_section
->output_offset
;
495 return bfd_reloc_overflow
;
497 /* Check for overflow */
498 if (relocation
& 0x02000000)
500 if ((relocation
& ~ (bfd_vma
) 0x03ffffff) != ~ (bfd_vma
) 0x03ffffff)
501 flag
= bfd_reloc_overflow
;
503 else if (relocation
& ~0x03ffffff)
504 flag
= bfd_reloc_overflow
;
506 target
&= ~0x00ffffff;
507 target
|= (relocation
>> 2) & 0x00ffffff;
508 bfd_put_32 (abfd
, target
, (bfd_byte
*) data
+ addr
);
510 /* Now the ARM magic... Change the reloc type so that it is marked as done.
511 Strictly this is only necessary if we are doing a partial relocation. */
512 reloc_entry
->howto
= &aoutarm_std_reloc_howto
[ARM_26D
];
517 typedef enum {bunknown
, b9
, b12
, b23
} thumb_pcrel_branchtype
;
519 static bfd_reloc_status_type
520 coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
, input_section
,
521 output_bfd
, error_message
, btype
)
523 arelent
*reloc_entry
;
526 asection
*input_section
;
528 char **error_message
;
529 thumb_pcrel_branchtype btype
;
531 bfd_vma relocation
= 0;
532 bfd_size_type addr
= reloc_entry
->address
;
533 long target
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ addr
);
534 bfd_reloc_status_type flag
= bfd_reloc_ok
;
539 /* NOTE: This routine is currently used by GAS, but not by the link
547 signbit
= 0x00000100;
553 signbit
= 0x00000800;
559 signbit
= 0x00400000;
566 /* If this is an undefined symbol, return error */
567 if (symbol
->section
== &bfd_und_section
568 && (symbol
->flags
& BSF_WEAK
) == 0)
569 return output_bfd
? bfd_reloc_continue
: bfd_reloc_undefined
;
571 /* If the sections are different, and we are doing a partial relocation,
572 just ignore it for now. */
573 if (symbol
->section
->name
!= input_section
->name
574 && output_bfd
!= (bfd
*)NULL
)
575 return bfd_reloc_continue
;
581 relocation
= ((target
& dstmsk
) << 1);
585 if (bfd_big_endian (abfd
))
586 relocation
= ((target
& 0x7ff) << 1) | ((target
& 0x07ff0000) >> 4);
588 relocation
= ((target
& 0x7ff) << 12) | ((target
& 0x07ff0000) >> 15);
595 relocation
= (relocation
^ signbit
) - signbit
; /* Sign extend */
596 relocation
+= symbol
->value
;
597 relocation
+= symbol
->section
->output_section
->vma
;
598 relocation
+= symbol
->section
->output_offset
;
599 relocation
+= reloc_entry
->addend
;
600 relocation
-= input_section
->output_section
->vma
;
601 relocation
-= input_section
->output_offset
;
605 return bfd_reloc_overflow
;
607 /* Check for overflow */
608 if (relocation
& signbit
)
610 if ((relocation
& ~offmsk
) != ~offmsk
)
611 flag
= bfd_reloc_overflow
;
613 else if (relocation
& ~offmsk
)
614 flag
= bfd_reloc_overflow
;
621 target
|= (relocation
>> 1);
625 if (bfd_big_endian (abfd
))
626 target
|= ((relocation
& 0xfff) >> 1) | ((relocation
<< 4) & 0x07ff0000);
628 target
|= ((relocation
& 0xffe) << 15) | ((relocation
>> 12) & 0x7ff);
635 bfd_put_32 (abfd
, target
, (bfd_byte
*) data
+ addr
);
637 /* Now the ARM magic... Change the reloc type so that it is marked as done.
638 Strictly this is only necessary if we are doing a partial relocation. */
639 reloc_entry
->howto
= & aoutarm_std_reloc_howto
[ARM_26D
];
641 /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations */
645 static bfd_reloc_status_type
646 coff_thumb_pcrel_23 (abfd
, reloc_entry
, symbol
, data
, input_section
,
647 output_bfd
, error_message
)
649 arelent
*reloc_entry
;
652 asection
*input_section
;
654 char **error_message
;
656 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
657 input_section
, output_bfd
, error_message
, b23
);
660 static bfd_reloc_status_type
661 coff_thumb_pcrel_12 (abfd
, reloc_entry
, symbol
, data
, input_section
,
662 output_bfd
, error_message
)
664 arelent
*reloc_entry
;
667 asection
*input_section
;
669 char **error_message
;
671 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
672 input_section
, output_bfd
, error_message
, b12
);
675 static bfd_reloc_status_type
676 coff_thumb_pcrel_9 (abfd
, reloc_entry
, symbol
, data
, input_section
,
677 output_bfd
, error_message
)
679 arelent
*reloc_entry
;
682 asection
*input_section
;
684 char **error_message
;
686 return coff_thumb_pcrel_common (abfd
, reloc_entry
, symbol
, data
,
687 input_section
, output_bfd
, error_message
, b9
);
691 static CONST
struct reloc_howto_struct
*
692 arm_reloc_type_lookup(abfd
,code
)
694 bfd_reloc_code_real_type code
;
696 #define ASTD(i,j) case i: return &aoutarm_std_reloc_howto[j]
697 if (code
== BFD_RELOC_CTOR
)
698 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
703 default: return (CONST
struct reloc_howto_struct
*) 0;
708 ASTD (BFD_RELOC_8
, ARM_8
);
709 ASTD (BFD_RELOC_16
, ARM_16
);
710 ASTD (BFD_RELOC_32
, ARM_32
);
711 ASTD (BFD_RELOC_ARM_PCREL_BRANCH
, ARM_26
);
712 ASTD (BFD_RELOC_8_PCREL
, ARM_DISP8
);
713 ASTD (BFD_RELOC_16_PCREL
, ARM_DISP16
);
714 ASTD (BFD_RELOC_32_PCREL
, ARM_DISP32
);
715 ASTD (BFD_RELOC_RVA
, ARM_RVA32
);
716 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9
, ARM_THUMB9
);
717 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12
, ARM_THUMB12
);
718 ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23
, ARM_THUMB23
);
719 default: return (CONST
struct reloc_howto_struct
*) 0;
724 #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup
726 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
727 #define COFF_PAGE_SIZE 0x1000
728 /* Turn a howto into a reloc nunmber */
730 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
731 #define BADMAG(x) ARMBADMAG(x)
732 #define ARM 1 /* Customize coffcode.h */
734 /* The set of global variables that mark the total size of each kind
735 of glue required, plus a BFD to hang the glue sections onto.
736 Note: These variable should not be made static, since in a *-pe
737 build there are two versions of this file compiled, one for pe
738 objects and one for pei objects, and they want to share these
740 #if defined COFF_IMAGE_WITH_PE
741 extern long int global_thumb_glue_size
;
743 long int global_thumb_glue_size
= 0;
746 #if defined COFF_IMAGE_WITH_PE
747 extern long int global_arm_glue_size
;
749 long int global_arm_glue_size
= 0;
752 #if defined COFF_IMAGE_WITH_PE
753 extern bfd
* bfd_of_glue_owner
;
755 bfd
* bfd_of_glue_owner
= NULL
;
758 /* some typedefs for holding instructions */
759 typedef unsigned long int insn32
;
760 typedef unsigned short int insn16
;
763 /* The thumb form of a long branch is a bit finicky, because the offset
764 encoding is split over two fields, each in it's own instruction. They
765 can occur in any order. So given a thumb form of long branch, and an
766 offset, insert the offset into the thumb branch and return finished
769 It takes two thumb instructions to encode the target address. Each has
770 11 bits to invest. The upper 11 bits are stored in one (identifed by
771 H-0.. see below), the lower 11 bits are stored in the other (identified
774 Combine together and shifted left by 1 (it's a half word address) and
778 H-0, upper address-0 = 000
780 H-1, lower address-0 = 800
782 They can be ordered either way, but the arm tools I've seen always put
783 the lower one first. It probably doesn't matter. krk@cygnus.com
785 XXX: Actually the order does matter. The second instruction (H-1)
786 moves the computed address into the PC, so it must be the second one
787 in the sequence. The problem, however is that whilst little endian code
788 stores the instructions in HI then LOW order, big endian code does the
789 reverse. nickc@cygnus.com */
791 #define LOW_HI_ORDER 0xF800F000
792 #define HI_LOW_ORDER 0xF000F800
795 insert_thumb_branch (br_insn
, rel_off
)
799 unsigned int low_bits
;
800 unsigned int high_bits
;
803 BFD_ASSERT((rel_off
& 1) != 1);
805 rel_off
>>= 1; /* half word aligned address */
806 low_bits
= rel_off
& 0x000007FF; /* the bottom 11 bits */
807 high_bits
= ( rel_off
>> 11 ) & 0x000007FF; /* the top 11 bits */
809 if ((br_insn
& LOW_HI_ORDER
) == LOW_HI_ORDER
)
810 br_insn
= LOW_HI_ORDER
| (low_bits
<< 16) | high_bits
;
811 else if ((br_insn
& HI_LOW_ORDER
) == HI_LOW_ORDER
)
812 br_insn
= HI_LOW_ORDER
| (high_bits
<< 16) | low_bits
;
814 abort(); /* error - not a valid branch instruction form */
816 /* FIXME: abort is probably not the right call. krk@cygnus.com */
822 static struct coff_link_hash_entry
*
823 find_thumb_glue (info
, name
, input_bfd
)
824 struct bfd_link_info
* info
;
829 struct coff_link_hash_entry
* myh
= 0;
832 bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
)));
834 BFD_ASSERT (tmp_name
);
836 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
838 myh
= coff_link_hash_lookup (coff_hash_table (info
),
843 _bfd_error_handler ("%s: unable to find THUMB glue '%s' for `%s'",
844 bfd_get_filename (input_bfd
), tmp_name
, name
);
852 static struct coff_link_hash_entry
*
853 find_arm_glue (info
, name
, input_bfd
)
854 struct bfd_link_info
* info
;
859 struct coff_link_hash_entry
*myh
= 0;
862 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
)));
864 BFD_ASSERT (tmp_name
);
866 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
868 myh
= coff_link_hash_lookup (coff_hash_table (info
),
874 _bfd_error_handler ("%s: unable to find ARM glue '%s' for `%s'",
875 bfd_get_filename (input_bfd
), tmp_name
, name
);
891 .word func @ behave as if you saw a ARM_32 reloc
893 ldr ip,8 <__func_addr> e59fc000
899 #define ARM2THUMB_GLUE_SIZE 12
901 a2t1_ldr_insn
= 0xe59fc000,
902 a2t2_bx_r12_insn
= 0xe12fff1c,
903 a2t3_func_addr_insn
= 0x00000001;
914 __func_change_to_arm:
924 #define THUMB2ARM_GLUE_SIZE 8
926 t2a1_bx_pc_insn
= 0x4778,
927 t2a2_noop_insn
= 0x46c0;
929 t2a3_b_insn
= 0xea000000;
932 We should really create new local (static) symbols in destination
933 object for each stub we create. We should also create local
934 (static) symbols within the stubs when switching between ARM and
935 Thumb code. This will ensure that the debugger and disassembler
936 can present a better view of stubs.
938 We can treat stubs like literal sections, and for the THUMB9 ones
939 (short addressing range) we should be able to insert the stubs
940 between sections. i.e. the simplest approach (since relocations
941 are done on a section basis) is to dump the stubs at the end of
942 processing a section. That way we can always try and minimise the
943 offset to and from a stub. However, this does not map well onto
944 the way that the linker/BFD does its work: mapping all input
945 sections to output sections via the linker script before doing
948 Unfortunately it may be easier to just to disallow short range
949 Thumb->ARM stubs (i.e. no conditional inter-working branches,
950 only branch-and-link (BL) calls. This will simplify the processing
951 since we can then put all of the stubs into their own section.
954 On a different subject, rather than complaining when a
955 branch cannot fit in the number of bits available for the
956 instruction we should generate a trampoline stub (needed to
957 address the complete 32bit address space). */
959 /* The standard COFF backend linker does not cope with the special
960 Thumb BRANCH23 relocation. The alternative would be to split the
961 BRANCH23 into seperate HI23 and LO23 relocations. However, it is a
962 bit simpler simply providing our own relocation driver. */
964 /* The reloc processing routine for the ARM/Thumb COFF linker. NOTE:
965 This code is a very slightly modified copy of
966 _bfd_coff_generic_relocate_section. It would be a much more
967 maintainable solution to have a MACRO that could be expanded within
968 _bfd_coff_generic_relocate_section that would only be provided for
969 ARM/Thumb builds. It is only the code marked THUMBEXTENSION that
970 is different from the original. */
973 coff_arm_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
974 contents
, relocs
, syms
, sections
)
976 struct bfd_link_info
*info
;
978 asection
*input_section
;
980 struct internal_reloc
*relocs
;
981 struct internal_syment
*syms
;
984 struct internal_reloc
* rel
;
985 struct internal_reloc
* relend
;
988 relend
= rel
+ input_section
->reloc_count
;
990 for (; rel
< relend
; rel
++)
994 struct coff_link_hash_entry
*h
;
995 struct internal_syment
*sym
;
998 reloc_howto_type
*howto
;
999 bfd_reloc_status_type rstat
;
1002 symndx
= rel
->r_symndx
;
1011 h
= obj_coff_sym_hashes (input_bfd
)[symndx
];
1012 sym
= syms
+ symndx
;
1015 /* COFF treats common symbols in one of two ways. Either the
1016 size of the symbol is included in the section contents, or it
1017 is not. We assume that the size is not included, and force
1018 the rtype_to_howto function to adjust the addend as needed. */
1020 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
1021 addend
= - sym
->n_value
;
1026 howto
= bfd_coff_rtype_to_howto (input_bfd
, input_section
, rel
, h
,
1031 /* If we are doing a relocateable link, then we can just ignore
1032 a PC relative reloc that is pcrel_offset. It will already
1033 have the correct value. If this is not a relocateable link,
1034 then we should ignore the symbol value. */
1035 if (howto
->pc_relative
&& howto
->pcrel_offset
)
1037 if (info
->relocateable
)
1039 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
1040 addend
+= sym
->n_value
;
1043 /* If we are doing a relocateable link, then we can just ignore
1044 a PC relative reloc that is pcrel_offset. It will already
1045 have the correct value. */
1046 if (info
->relocateable
1047 && howto
->pc_relative
1048 && howto
->pcrel_offset
)
1059 sec
= bfd_abs_section_ptr
;
1064 sec
= sections
[symndx
];
1065 val
= (sec
->output_section
->vma
1066 + sec
->output_offset
1073 #if 1 /* THUMBEXTENSION */
1074 /* We don't output the stubs if we are generating a
1075 relocatable output file, since we may as well leave the
1076 stub generation to the final linker pass. If we fail to
1077 verify that the name is defined, we'll try to build stubs
1078 for an undefined name... */
1079 if (! info
->relocateable
1080 && ( h
->root
.type
== bfd_link_hash_defined
1081 || h
->root
.type
== bfd_link_hash_defweak
))
1083 asection
* h_sec
= h
->root
.u
.def
.section
;
1084 const char * name
= h
->root
.root
.string
;
1086 /* h locates the symbol referenced in the reloc. */
1087 h_val
= (h
->root
.u
.def
.value
1088 + h_sec
->output_section
->vma
1089 + h_sec
->output_offset
);
1091 if (howto
->type
== ARM_26
)
1093 if ( h
->class == C_THUMBSTATFUNC
1094 || h
->class == C_THUMBEXTFUNC
)
1096 /* Arm code calling a Thumb function */
1097 unsigned long int tmp
;
1100 long int ret_offset
;
1101 struct coff_link_hash_entry
* myh
;
1103 myh
= find_arm_glue (info
, name
, input_bfd
);
1107 my_offset
= myh
->root
.u
.def
.value
;
1109 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
1110 ARM2THUMB_GLUE_SECTION_NAME
);
1111 BFD_ASSERT (s
!= NULL
);
1112 BFD_ASSERT (s
->contents
!= NULL
);
1114 if ((my_offset
& 0x01) == 0x01)
1116 if (h_sec
->owner
!= NULL
1117 && INTERWORK_SET (h_sec
->owner
)
1118 && ! INTERWORK_FLAG (h_sec
->owner
))
1121 ("%s(%s): warning: interworking not enabled.",
1122 bfd_get_filename (h_sec
->owner
), name
);
1124 (" first occurrence: %s: arm call to thumb",
1125 bfd_get_filename (input_bfd
));
1129 myh
->root
.u
.def
.value
= my_offset
;
1131 bfd_put_32 (output_bfd
, a2t1_ldr_insn
, s
->contents
+ my_offset
);
1133 bfd_put_32 (output_bfd
, a2t2_bx_r12_insn
, s
->contents
+ my_offset
+ 4);
1135 /* It's a thumb address. Add the low order bit. */
1136 bfd_put_32 (output_bfd
, h_val
| a2t3_func_addr_insn
, s
->contents
+ my_offset
+ 8);
1139 BFD_ASSERT (my_offset
<= global_arm_glue_size
);
1141 tmp
= bfd_get_32 (input_bfd
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1143 tmp
= tmp
& 0xFF000000;
1145 /* Somehow these are both 4 too far, so subtract 8. */
1149 + s
->output_section
->vma
1150 - (input_section
->output_offset
1151 + input_section
->output_section
->vma
1155 tmp
= tmp
| ((ret_offset
>> 2) & 0x00FFFFFF);
1157 bfd_put_32 (output_bfd
, tmp
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1163 /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12 */
1164 else if (howto
->type
== ARM_THUMB23
)
1166 if ( h
->class == C_EXT
1167 || h
->class == C_STAT
1168 || h
->class == C_LABEL
)
1170 /* Thumb code calling an ARM function */
1173 unsigned long int tmp
;
1174 long int ret_offset
;
1175 struct coff_link_hash_entry
* myh
;
1177 myh
= find_thumb_glue (info
, name
, input_bfd
);
1181 my_offset
= myh
->root
.u
.def
.value
;
1183 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
1184 THUMB2ARM_GLUE_SECTION_NAME
);
1186 BFD_ASSERT (s
!= NULL
);
1187 BFD_ASSERT (s
->contents
!= NULL
);
1189 if ((my_offset
& 0x01) == 0x01)
1191 if (h_sec
->owner
!= NULL
1192 && INTERWORK_SET (h_sec
->owner
)
1193 && ! INTERWORK_FLAG (h_sec
->owner
))
1196 ("%s(%s): warning: interworking not enabled.",
1197 bfd_get_filename (h_sec
->owner
), name
);
1199 (" first occurrence: %s: thumb call to arm",
1200 bfd_get_filename (input_bfd
));
1204 myh
->root
.u
.def
.value
= my_offset
;
1206 bfd_put_16 (output_bfd
, t2a1_bx_pc_insn
,
1207 s
->contents
+ my_offset
);
1209 bfd_put_16 (output_bfd
, t2a2_noop_insn
,
1210 s
->contents
+ my_offset
+ 2);
1213 ((signed)h_val
) - /* Address of destination of the stub */
1214 ((signed)(s
->output_offset
/* Offset from the start of the current section to the start of the stubs. */
1215 + my_offset
/* Offset of the start of this stub from the start of the stubs. */
1216 + s
->output_section
->vma
) /* Address of the start of the current section. */
1217 + 4 /* The branch instruction is 4 bytes into the stub. */
1218 + 8); /* ARM branches work from the pc of the instruction + 8. */
1220 bfd_put_32 (output_bfd
,
1221 t2a3_b_insn
| ((ret_offset
>> 2) & 0x00FFFFFF),
1222 s
->contents
+ my_offset
+ 4);
1225 BFD_ASSERT (my_offset
<= global_thumb_glue_size
);
1227 /* Now go back and fix up the original bl insn to point here. */
1231 - (input_section
->output_offset
1235 tmp
= bfd_get_32 (input_bfd
, contents
+ rel
->r_vaddr
- input_section
->vma
);
1237 bfd_put_32 (output_bfd
,
1238 insert_thumb_branch (tmp
, ret_offset
),
1239 contents
+ rel
->r_vaddr
- input_section
->vma
);
1246 /* If the relocation type and destination symbol does not
1247 fall into one of the above categories, then we can just
1248 perform a direct link. */
1251 rstat
= bfd_reloc_ok
;
1253 #endif /* THUMBEXTENSION */
1254 if ( h
->root
.type
== bfd_link_hash_defined
1255 || h
->root
.type
== bfd_link_hash_defweak
)
1259 sec
= h
->root
.u
.def
.section
;
1260 val
= (h
->root
.u
.def
.value
1261 + sec
->output_section
->vma
1262 + sec
->output_offset
);
1265 else if (! info
->relocateable
)
1267 if (! ((*info
->callbacks
->undefined_symbol
)
1268 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
1269 rel
->r_vaddr
- input_section
->vma
)))
1274 if (info
->base_file
)
1276 /* Emit a reloc if the backend thinks it needs it. */
1277 if (sym
&& pe_data(output_bfd
)->in_reloc_p(output_bfd
, howto
))
1279 /* relocation to a symbol in a section which
1280 isn't absolute - we output the address here
1282 bfd_vma addr
= rel
->r_vaddr
1283 - input_section
->vma
1284 + input_section
->output_offset
1285 + input_section
->output_section
->vma
;
1286 if (coff_data(output_bfd
)->pe
)
1287 addr
-= pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
1288 /* FIXME: Shouldn't 4 be sizeof (addr)? */
1289 fwrite (&addr
, 1,4, (FILE *) info
->base_file
);
1293 #if 1 /* THUMBEXTENSION */
1295 rstat
= bfd_reloc_ok
;
1296 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1297 else if (! info
->relocateable
1298 && howto
->type
== ARM_THUMB23
)
1300 /* This is pretty much a copy of what the default
1301 _bfd_final_link_relocate and _bfd_relocate_contents
1302 routines do to perform a relocation, with special
1303 processing for the split addressing of the Thumb BL
1304 instruction. Again, it would probably be simpler adding a
1305 ThumbBRANCH23 specific macro expansion into the default
1308 bfd_vma address
= rel
->r_vaddr
- input_section
->vma
;
1310 if (address
> input_section
->_raw_size
)
1311 rstat
= bfd_reloc_outofrange
;
1314 bfd_vma relocation
= val
+ addend
;
1315 int size
= bfd_get_reloc_size (howto
);
1316 boolean overflow
= false;
1317 bfd_byte
* location
= contents
+ address
;
1318 bfd_vma x
= bfd_get_32 (input_bfd
, location
);
1319 bfd_vma src_mask
= 0x007FFFFE;
1320 bfd_signed_vma reloc_signed_max
= (1 << (howto
->bitsize
- 1)) - 1;
1321 bfd_signed_vma reloc_signed_min
= ~reloc_signed_max
;
1323 bfd_signed_vma signed_check
;
1325 bfd_signed_vma signed_add
;
1327 BFD_ASSERT (size
== 4);
1329 /* howto->pc_relative should be TRUE for type 14 BRANCH23 */
1330 relocation
-= (input_section
->output_section
->vma
1331 + input_section
->output_offset
);
1333 /* howto->pcrel_offset should be TRUE for type 14 BRANCH23 */
1334 relocation
-= address
;
1336 /* No need to negate the relocation with BRANCH23. */
1337 /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23. */
1338 /* howto->rightshift == 1 */
1339 /* Drop unwanted bits from the value we are relocating to. */
1341 check
= relocation
>> howto
->rightshift
;
1343 /* If this is a signed value, the rightshift just dropped
1344 leading 1 bits (assuming twos complement). */
1345 if ((bfd_signed_vma
) relocation
>= 0)
1346 signed_check
= check
;
1348 signed_check
= (check
1350 & ~((bfd_vma
) - 1 >> howto
->rightshift
)));
1352 /* Get the value from the object file. */
1353 if (bfd_big_endian (input_bfd
))
1355 add
= (((x
) & 0x07ff0000) >> 4) | (((x
) & 0x7ff) << 1);
1359 add
= ((((x
) & 0x7ff) << 12) | (((x
) & 0x07ff0000) >> 15));
1362 /* Get the value from the object file with an appropriate sign.
1363 The expression involving howto->src_mask isolates the upper
1364 bit of src_mask. If that bit is set in the value we are
1365 adding, it is negative, and we subtract out that number times
1366 two. If src_mask includes the highest possible bit, then we
1367 can not get the upper bit, but that does not matter since
1368 signed_add needs no adjustment to become negative in that
1373 if ((add
& (((~ src_mask
) >> 1) & src_mask
)) != 0)
1374 signed_add
-= (((~ src_mask
) >> 1) & src_mask
) << 1;
1376 /* Add the value from the object file, shifted so that it is a
1378 /* howto->bitpos == 0 */
1380 signed_check
+= signed_add
;
1381 relocation
+= signed_add
;
1383 BFD_ASSERT (howto
->complain_on_overflow
== complain_overflow_signed
);
1385 /* Assumes two's complement. */
1386 if ( signed_check
> reloc_signed_max
1387 || signed_check
< reloc_signed_min
)
1390 /* Put RELOCATION into the correct bits: */
1392 if (bfd_big_endian (input_bfd
))
1394 relocation
= (((relocation
& 0xffe) >> 1) | ((relocation
<< 4) & 0x07ff0000));
1398 relocation
= (((relocation
& 0xffe) << 15) | ((relocation
>> 12) & 0x7ff));
1401 /* Add RELOCATION to the correct bits of X: */
1402 x
= ((x
& ~howto
->dst_mask
) | relocation
);
1404 /* Put the relocated value back in the object file: */
1405 bfd_put_32 (input_bfd
, x
, location
);
1407 rstat
= overflow
? bfd_reloc_overflow
: bfd_reloc_ok
;
1411 #endif /* THUMBEXTENSION */
1412 rstat
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1414 rel
->r_vaddr
- input_section
->vma
,
1416 #if 1 /* THUMBEXTENSION */
1418 Is this the best way to fix up thumb addresses? krk@cygnus.com
1419 Probably not, but it works, and if it works it don't need fixing! nickc@cygnus.com */
1420 /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */
1421 if (! info
->relocateable
1422 && rel
->r_type
== ARM_32
)
1424 /* Determine if we need to set the bottom bit of a relocated address
1425 because the address is the address of a Thumb code symbol. */
1427 int patchit
= false;
1430 && ( h
->class == C_THUMBSTATFUNC
1431 || h
->class == C_THUMBEXTFUNC
))
1435 else if (sym
!= NULL
1436 && sym
->n_scnum
> N_UNDEF
)
1438 /* No hash entry - use the symbol instead. */
1440 if ( sym
->n_sclass
== C_THUMBSTATFUNC
1441 || sym
->n_sclass
== C_THUMBEXTFUNC
)
1447 bfd_byte
* location
= contents
+ rel
->r_vaddr
- input_section
->vma
;
1448 bfd_vma x
= bfd_get_32 (input_bfd
, location
);
1450 bfd_put_32 (input_bfd
, x
| 1, location
);
1453 #endif /* THUMBEXTENSION */
1461 case bfd_reloc_outofrange
:
1462 (*_bfd_error_handler
)
1463 ("%s: bad reloc address 0x%lx in section `%s'",
1464 bfd_get_filename (input_bfd
),
1465 (unsigned long) rel
->r_vaddr
,
1466 bfd_get_section_name (input_bfd
, input_section
));
1468 case bfd_reloc_overflow
:
1471 char buf
[SYMNMLEN
+ 1];
1476 name
= h
->root
.root
.string
;
1479 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
1484 if (! ((*info
->callbacks
->reloc_overflow
)
1485 (info
, name
, howto
->name
, (bfd_vma
) 0, input_bfd
,
1486 input_section
, rel
->r_vaddr
- input_section
->vma
)))
1495 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
1497 arm_allocate_interworking_sections (info
)
1498 struct bfd_link_info
*info
;
1503 static char test_char
= '1';
1506 if (global_arm_glue_size
!= 0)
1508 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1510 s
= bfd_get_section_by_name (bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
1512 BFD_ASSERT (s
!= NULL
);
1514 foo
= (bfd_byte
*) bfd_alloc (bfd_of_glue_owner
, global_arm_glue_size
);
1516 memset (foo
, test_char
, global_arm_glue_size
);
1519 s
->_raw_size
= s
->_cooked_size
= global_arm_glue_size
;
1523 if (global_thumb_glue_size
!= 0)
1525 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1527 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1529 BFD_ASSERT (s
!= NULL
);
1531 foo
= (bfd_byte
*) bfd_alloc (bfd_of_glue_owner
, global_thumb_glue_size
);
1533 memset (foo
, test_char
, global_thumb_glue_size
);
1536 s
->_raw_size
= s
->_cooked_size
= global_thumb_glue_size
;
1544 record_arm_to_thumb_glue (info
, h
)
1545 struct bfd_link_info
* info
;
1546 struct coff_link_hash_entry
* h
;
1548 const char * name
= h
->root
.root
.string
;
1549 register asection
* s
;
1551 struct coff_link_hash_entry
* myh
;
1554 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1556 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
1557 ARM2THUMB_GLUE_SECTION_NAME
);
1559 BFD_ASSERT (s
!= NULL
);
1561 tmp_name
= ((char *)
1562 bfd_malloc (strlen (name
) + strlen (ARM2THUMB_GLUE_ENTRY_NAME
)));
1564 BFD_ASSERT (tmp_name
);
1566 sprintf (tmp_name
, ARM2THUMB_GLUE_ENTRY_NAME
, name
);
1568 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1570 false, false, true);
1575 return; /* we've already seen this guy */
1579 /* The only trick here is using global_arm_glue_size as the value. Even
1580 though the section isn't allocated yet, this is where we will be putting
1583 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1584 BSF_EXPORT
| BSF_GLOBAL
,
1585 s
, global_arm_glue_size
+ 1,
1587 (struct bfd_link_hash_entry
**) & myh
);
1589 global_arm_glue_size
+= ARM2THUMB_GLUE_SIZE
;
1597 record_thumb_to_arm_glue (info
, h
)
1598 struct bfd_link_info
* info
;
1599 struct coff_link_hash_entry
* h
;
1601 const char * name
= h
->root
.root
.string
;
1602 register asection
* s
;
1604 struct coff_link_hash_entry
* myh
;
1606 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1608 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
1610 BFD_ASSERT (s
!= NULL
);
1612 tmp_name
= (char *) bfd_malloc (strlen (name
) + strlen (THUMB2ARM_GLUE_ENTRY_NAME
));
1614 BFD_ASSERT (tmp_name
);
1616 sprintf (tmp_name
, THUMB2ARM_GLUE_ENTRY_NAME
, name
);
1618 myh
= coff_link_hash_lookup (coff_hash_table (info
),
1620 false, false, true);
1625 return; /* we've already seen this guy */
1628 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1629 BSF_LOCAL
, s
, global_thumb_glue_size
+ 1,
1631 (struct bfd_link_hash_entry
**) & myh
);
1633 /* If we mark it 'thumb', the disassembler will do a better job. */
1634 myh
->class = C_THUMBEXTFUNC
;
1638 #define CHANGE_TO_ARM "__%s_change_to_arm"
1640 tmp_name
= ((char *)
1641 bfd_malloc (strlen (name
) + strlen (CHANGE_TO_ARM
)));
1643 BFD_ASSERT (tmp_name
);
1645 sprintf (tmp_name
, CHANGE_TO_ARM
, name
);
1649 /* Now allocate another symbol to switch back to arm mode. */
1650 bfd_coff_link_add_one_symbol (info
, bfd_of_glue_owner
, tmp_name
,
1651 BSF_LOCAL
, s
, global_thumb_glue_size
+ 4,
1653 (struct bfd_link_hash_entry
**) & myh
);
1657 global_thumb_glue_size
+= THUMB2ARM_GLUE_SIZE
;
1663 arm_process_before_allocation (abfd
, info
)
1665 struct bfd_link_info
* info
;
1669 /* If we are only performing a partial link do not bother
1670 to construct any glue. */
1671 if (info
->relocateable
)
1674 /* Here we have a bfd that is to be included on the link. We have a hook
1675 to do reloc rummaging, before section sizes are nailed down. */
1677 _bfd_coff_get_external_symbols (abfd
);
1679 BFD_ASSERT (bfd_of_glue_owner
!= NULL
);
1681 /* Rummage around all the relocs and map the glue vectors. */
1682 sec
= abfd
->sections
;
1687 for (; sec
!= NULL
; sec
= sec
->next
)
1689 struct internal_reloc
* i
;
1690 struct internal_reloc
* rel
;
1692 if (sec
->reloc_count
== 0)
1695 /* Load the relocs. */
1696 /* FIXME: there may be a storage leak here. */
1698 i
= _bfd_coff_read_internal_relocs (abfd
, sec
, 1, 0, 0, 0);
1700 BFD_ASSERT (i
!= 0);
1702 for (rel
= i
; rel
< i
+ sec
->reloc_count
; ++rel
)
1704 unsigned short r_type
= rel
->r_type
;
1706 struct coff_link_hash_entry
* h
;
1708 symndx
= rel
->r_symndx
;
1710 /* If the relocation is not against a symbol it cannot concern us. */
1714 h
= obj_coff_sym_hashes (abfd
)[symndx
];
1716 /* If the relocation is against a static symbol it must be within
1717 the current section and so cannot be a cross ARM/Thumb relocation. */
1724 /* This one is a call from arm code. We need to look up
1725 the target of the call. If it is a thumb target, we
1728 if (h
->class == C_THUMBEXTFUNC
)
1729 record_arm_to_thumb_glue (info
, h
);
1733 /* This one is a call from thumb code. We used to look
1734 for ARM_THUMB9 and ARM_THUMB12 as well. We need to look
1735 up the target of the call. If it is an arm target, we
1736 insert glue. If the symbol does not exist it will be
1737 given a class of C_EXT and so we will generate a stub
1738 for it. This is not really a problem, since the link
1739 is doomed anyway. */
1746 record_thumb_to_arm_glue (info
, h
);
1761 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
1763 #define coff_relocate_section coff_arm_relocate_section
1765 /* When doing a relocateable link, we want to convert ARM26 relocs
1766 into ARM26D relocs. */
1769 coff_arm_adjust_symndx (obfd
, info
, ibfd
, sec
, irel
, adjustedp
)
1771 struct bfd_link_info
*info
;
1774 struct internal_reloc
*irel
;
1777 if (irel
->r_type
== 3)
1779 struct coff_link_hash_entry
*h
;
1781 h
= obj_coff_sym_hashes (ibfd
)[irel
->r_symndx
];
1783 && (h
->root
.type
== bfd_link_hash_defined
1784 || h
->root
.type
== bfd_link_hash_defweak
)
1785 && h
->root
.u
.def
.section
->output_section
== sec
->output_section
)
1792 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
1793 /* Called when merging the private data areas of two BFDs.
1794 This is important as it allows us to detect if we are
1795 attempting to merge binaries compiled for different ARM
1796 targets, eg different CPUs or differents APCS's. */
1799 coff_arm_bfd_merge_private_bfd_data (ibfd
, obfd
)
1803 BFD_ASSERT (ibfd
!= NULL
&& obfd
!= NULL
);
1808 /* If the two formats are different we cannot merge anything.
1809 This is not an error, since it is permissable to change the
1810 input and output formats. */
1811 if ( ibfd
->xvec
->flavour
!= bfd_target_coff_flavour
1812 || obfd
->xvec
->flavour
!= bfd_target_coff_flavour
)
1815 /* Verify that the APCS is the same for the two BFDs */
1816 if (APCS_SET (ibfd
))
1818 if (APCS_SET (obfd
))
1820 /* If the src and dest have different APCS flag bits set, fail. */
1821 if (APCS_26_FLAG (obfd
) != APCS_26_FLAG (ibfd
))
1824 ("%s: ERROR: compiled for APCS-%d whereas target %s uses APCS-%d",
1825 bfd_get_filename (ibfd
), APCS_26_FLAG (ibfd
) ? 26 : 32,
1826 bfd_get_filename (obfd
), APCS_26_FLAG (obfd
) ? 26 : 32
1829 bfd_set_error (bfd_error_wrong_format
);
1833 if (APCS_FLOAT_FLAG (obfd
) != APCS_FLOAT_FLAG (ibfd
))
1836 ("%s: ERROR: passes floats in %s registers whereas target %s uses %s registers",
1837 bfd_get_filename (ibfd
), APCS_FLOAT_FLAG (ibfd
) ? "float" : "integer",
1838 bfd_get_filename (obfd
), APCS_FLOAT_FLAG (obfd
) ? "float" : "integer"
1841 bfd_set_error (bfd_error_wrong_format
);
1845 if (PIC_FLAG (obfd
) != PIC_FLAG (ibfd
))
1848 ("%s: ERROR: compiled as %s code, whereas target %s is %s",
1849 bfd_get_filename (ibfd
), PIC_FLAG (ibfd
) ? "position independent" : "absoluste position",
1850 bfd_get_filename (obfd
), PIC_FLAG (obfd
) ? "position independent" : "absoluste position"
1853 bfd_set_error (bfd_error_wrong_format
);
1859 SET_APCS_FLAGS (obfd
, APCS_26_FLAG (ibfd
) | APCS_FLOAT_FLAG (ibfd
) | PIC_FLAG (ibfd
));
1861 /* Set up the arch and fields as well as these are probably wrong. */
1862 bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
1866 /* Check the interworking support. */
1867 if (INTERWORK_SET (ibfd
))
1869 if (INTERWORK_SET (obfd
))
1871 /* If the src and dest differ in their interworking issue a warning. */
1872 if (INTERWORK_FLAG (obfd
) != INTERWORK_FLAG (ibfd
))
1875 ("Warning: input file %s %s interworking, whereas %s does%s",
1876 bfd_get_filename (ibfd
),
1877 INTERWORK_FLAG (ibfd
) ? "supports" : "does not support",
1878 bfd_get_filename (obfd
),
1879 INTERWORK_FLAG (obfd
) ? "." : " not."
1885 SET_INTERWORK_FLAG (obfd
, INTERWORK_FLAG (ibfd
));
1893 /* Display the flags field. */
1896 coff_arm_bfd_print_private_bfd_data (abfd
, ptr
)
1900 FILE * file
= (FILE *) ptr
;
1902 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
)
1904 fprintf (file
, "private flags = %x", coff_data (abfd
)->flags
);
1906 if (APCS_SET (abfd
))
1907 fprintf (file
, ": [APCS-%d] [floats passed in %s registers] [%s]",
1908 APCS_26_FLAG (abfd
) ? 26 : 32,
1909 APCS_FLOAT_FLAG (abfd
) ? "float" : "integer",
1910 PIC_FLAG (abfd
) ? "position independent" : "absolute position"
1913 if (INTERWORK_SET (abfd
))
1914 fprintf (file
, " [interworking %ssupported]",
1915 INTERWORK_FLAG (abfd
) ? "" : "not " );
1917 fprintf (file
, " [interworking flag not initialised]");
1925 /* Copies the given flags into the coff_tdata.flags field.
1926 Typically these flags come from the f_flags[] field of
1927 the COFF filehdr structure, which contains important,
1928 target specific information. */
1931 coff_arm_bfd_set_private_flags (abfd
, flags
)
1937 BFD_ASSERT (abfd
!= NULL
);
1939 flag
= (flags
& F_APCS26
) ? F_APCS_26
: 0;
1941 /* Make sure that the APCS field has not been initialised to the opposite value. */
1943 && ( (APCS_26_FLAG (abfd
) != flag
)
1944 || (APCS_FLOAT_FLAG (abfd
) != (flags
& F_APCS_FLOAT
))
1945 || (PIC_FLAG (abfd
) != (flags
& F_PIC
))
1949 flag
|= (flags
& (F_APCS_FLOAT
| F_PIC
));
1951 SET_APCS_FLAGS (abfd
, flag
);
1953 flag
= (flags
& F_INTERWORK
);
1955 /* If either the flags or the BFD do support interworking then do not set the interworking flag. */
1956 if (INTERWORK_SET (abfd
) && (INTERWORK_FLAG (abfd
) != flag
))
1959 SET_INTERWORK_FLAG (abfd
, flag
);
1965 /* Copy the important parts of the target specific data
1966 from one instance of a BFD to another. */
1969 coff_arm_bfd_copy_private_bfd_data (src
, dest
)
1973 BFD_ASSERT (src
!= NULL
&& dest
!= NULL
);
1978 /* If the destination is not in the same format as the source, do not do the copy. */
1979 if (src
->xvec
!= dest
->xvec
)
1982 /* copy the flags field */
1985 if (APCS_SET (dest
))
1987 /* If the src and dest have different APCS flag bits set, fail. */
1988 if (APCS_26_FLAG (dest
) != APCS_26_FLAG (src
))
1991 if (APCS_FLOAT_FLAG (dest
) != APCS_FLOAT_FLAG (src
))
1994 if (PIC_FLAG (dest
) != PIC_FLAG (src
))
1998 SET_APCS_FLAGS (dest
, APCS_26_FLAG (src
) | APCS_FLOAT_FLAG (src
) | PIC_FLAG (src
));
2001 if (INTERWORK_SET (src
))
2003 if (INTERWORK_SET (dest
))
2005 /* If the src and dest have different interworking flags then turn off the interworking bit. */
2006 if (INTERWORK_FLAG (dest
) != INTERWORK_FLAG (src
))
2007 SET_INTERWORK_FLAG (dest
, 0);
2011 SET_INTERWORK_FLAG (dest
, INTERWORK_FLAG (src
));
2018 /* Note: the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX
2019 *must* match the definitions on gcc/config/arm/semi.h. */
2020 #define LOCAL_LABEL_PREFIX "."
2021 #define USER_LABEL_PREFIX "_"
2024 coff_arm_is_local_label_name (abfd
, name
)
2028 #ifdef LOCAL_LABEL_PREFIX
2029 /* If there is a prefix for local labels then look for this.
2030 If the prefix exists, but it is empty, then ignore the test. */
2032 if (LOCAL_LABEL_PREFIX
[0] != 0)
2034 if (strncmp (name
, LOCAL_LABEL_PREFIX
, strlen (LOCAL_LABEL_PREFIX
)) == 0)
2038 #ifdef USER_LABEL_PREFIX
2039 if (USER_LABEL_PREFIX
[0] != 0)
2041 if (strncmp (name
, USER_LABEL_PREFIX
, strlen (USER_LABEL_PREFIX
)) == 0)
2046 /* devo/gcc/config/dbxcoff.h defines ASM_OUTPUT_SOURCE_LINE to generate local line numbers as .LM<number>, so treat these as local. */
2050 case 'L': return true;
2051 case '.': return (name
[1] == 'L' && name
[2] == 'M') ? true : false;
2052 default: return false; /* Cannot make our minds up - default to false so that it will not be stripped by accident. */
2055 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
2057 #define coff_bfd_is_local_label_name coff_arm_is_local_label_name
2058 #define coff_adjust_symndx coff_arm_adjust_symndx
2060 #define coff_link_output_has_begun coff_arm_link_output_has_begun
2061 #define coff_final_link_postscript coff_arm_final_link_postscript
2062 #define coff_bfd_merge_private_bfd_data coff_arm_bfd_merge_private_bfd_data
2063 #define coff_bfd_print_private_bfd_data coff_arm_bfd_print_private_bfd_data
2064 #define coff_bfd_set_private_flags coff_arm_bfd_set_private_flags
2065 #define coff_bfd_copy_private_bfd_data coff_arm_bfd_copy_private_bfd_data
2067 extern boolean
coff_arm_bfd_set_private_flags ();
2068 extern boolean
coff_arm_bfd_merge_private_bfd_data ();
2069 extern boolean
coff_arm_bfd_copy_private_bfd_data ();
2070 extern boolean
coff_arm_bfd_print_private_bfd_data ();
2071 extern boolean
coff_arm_final_link_postscript ();
2072 extern boolean
coff_arm_link_output_has_begun ();
2073 extern boolean
coff_arm_is_local_label_name ();
2075 #if defined COFF_IMAGE_WITH_PE || ! defined COFF_WITH_PE
2076 /* This piece of machinery exists only to guarantee that the bfd that holds
2077 the glue section is written last.
2079 This does depend on bfd_make_section attaching a new section to the
2080 end of the section list for the bfd.
2085 coff_arm_link_output_has_begun (sub
)
2088 return (sub
->output_has_begun
|| sub
== bfd_of_glue_owner
);
2092 coff_arm_final_link_postscript (abfd
, pfinfo
)
2094 struct coff_final_link_info
* pfinfo
;
2096 if (bfd_of_glue_owner
!= NULL
)
2098 if (! _bfd_coff_link_input_bfd (pfinfo
, bfd_of_glue_owner
))
2100 bfd_of_glue_owner
->output_has_begun
= true;
2104 #endif /* COFF_IMAGE_WITH_PE or not COFF_WITH_PE */
2106 #define coff_SWAP_sym_in arm_bfd_coff_swap_sym_in
2108 static void coff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
2110 /* Sepcial version of symbol swapper, used to grab a bfd
2111 onto which the glue sections can be attached. */
2113 arm_bfd_coff_swap_sym_in (abfd
, ext1
, in1
)
2119 register asection
* s
;
2121 /* Do the normal swap in. */
2122 coff_swap_sym_in (abfd
, ext1
, in1
);
2124 if (bfd_of_glue_owner
!= NULL
) /* we already have a toc, so go home */
2127 /* Save the bfd for later allocation. */
2128 bfd_of_glue_owner
= abfd
;
2130 s
= bfd_get_section_by_name (bfd_of_glue_owner
,
2131 ARM2THUMB_GLUE_SECTION_NAME
);
2135 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2137 s
= bfd_make_section (bfd_of_glue_owner
, ARM2THUMB_GLUE_SECTION_NAME
);
2140 || !bfd_set_section_flags (bfd_of_glue_owner
, s
, flags
)
2141 || !bfd_set_section_alignment (bfd_of_glue_owner
, s
, 2))
2143 /* FIXME: set appropriate bfd error */
2148 s
= bfd_get_section_by_name (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2152 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2154 s
= bfd_make_section (bfd_of_glue_owner
, THUMB2ARM_GLUE_SECTION_NAME
);
2157 || !bfd_set_section_flags (bfd_of_glue_owner
, s
, flags
)
2158 || !bfd_set_section_alignment (bfd_of_glue_owner
, s
, 2))
2160 /* FIXME: set appropriate bfd error krk@cygnus.com */
2168 #include "coffcode.h"
2171 #ifdef TARGET_LITTLE_SYM
2174 armcoff_little_vec
=
2177 #ifdef TARGET_LITTLE_NAME
2182 bfd_target_coff_flavour
,
2183 BFD_ENDIAN_LITTLE
, /* data byte order is little */
2184 BFD_ENDIAN_LITTLE
, /* header byte order is little */
2186 (HAS_RELOC
| EXEC_P
| /* object flags */
2187 HAS_LINENO
| HAS_DEBUG
|
2188 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2190 #ifndef COFF_WITH_PE
2191 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2193 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2194 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2197 #ifdef TARGET_UNDERSCORE
2198 TARGET_UNDERSCORE
, /* leading underscore */
2200 0, /* leading underscore */
2202 '/', /* ar_pad_char */
2203 15, /* ar_max_namelen */
2205 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2206 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2207 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2208 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2209 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2210 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2212 /* Note that we allow an object file to be treated as a core file as well. */
2213 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2214 bfd_generic_archive_p
, coff_object_p
},
2215 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2217 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2218 _bfd_write_archive_contents
, bfd_false
},
2220 BFD_JUMP_TABLE_GENERIC (coff
),
2221 BFD_JUMP_TABLE_COPY (coff
),
2222 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2223 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2224 BFD_JUMP_TABLE_SYMBOLS (coff
),
2225 BFD_JUMP_TABLE_RELOCS (coff
),
2226 BFD_JUMP_TABLE_WRITE (coff
),
2227 BFD_JUMP_TABLE_LINK (coff
),
2228 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2230 (PTR
) & bfd_coff_std_swap_table
,
2234 #ifdef TARGET_BIG_SYM
2240 #ifdef TARGET_BIG_NAME
2245 bfd_target_coff_flavour
,
2246 BFD_ENDIAN_BIG
, /* data byte order is big */
2247 BFD_ENDIAN_BIG
, /* header byte order is big */
2249 (HAS_RELOC
| EXEC_P
| /* object flags */
2250 HAS_LINENO
| HAS_DEBUG
|
2251 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2253 #ifndef COFF_WITH_PE
2254 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
2256 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* section flags */
2257 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
),
2260 #ifdef TARGET_UNDERSCORE
2261 TARGET_UNDERSCORE
, /* leading underscore */
2263 0, /* leading underscore */
2265 '/', /* ar_pad_char */
2266 15, /* ar_max_namelen */
2268 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2269 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2270 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
2271 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2272 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2273 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
2275 /* Note that we allow an object file to be treated as a core file as well. */
2276 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2277 bfd_generic_archive_p
, coff_object_p
},
2278 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2280 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2281 _bfd_write_archive_contents
, bfd_false
},
2283 BFD_JUMP_TABLE_GENERIC (coff
),
2284 BFD_JUMP_TABLE_COPY (coff
),
2285 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2286 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2287 BFD_JUMP_TABLE_SYMBOLS (coff
),
2288 BFD_JUMP_TABLE_RELOCS (coff
),
2289 BFD_JUMP_TABLE_WRITE (coff
),
2290 BFD_JUMP_TABLE_LINK (coff
),
2291 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2293 (PTR
) & bfd_coff_std_swap_table
,