* elf-bfd.h (struct elf_size_info): Add swap_symbol_in field.
[deliverable/binutils-gdb.git] / bfd / coff-arm.c
index 8dcb3bbf9162ad495767b6741ed9f0df429bc8c8..5e7f907a9594af9f16291157b597f48449a7c25f 100644 (file)
@@ -1,6 +1,6 @@
 /* BFD back-end for ARM COFF files.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001
+   2000, 2001, 2002
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -87,12 +87,16 @@ static bfd_reloc_status_type aoutarm_fix_pcrel_26_done
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
 static bfd_reloc_status_type aoutarm_fix_pcrel_26
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+#ifndef ARM_WINCE
 static bfd_reloc_status_type coff_thumb_pcrel_23
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
-static bfd_reloc_status_type coff_thumb_pcrel_12
-  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
 static bfd_reloc_status_type coff_thumb_pcrel_9
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+static insn32 insert_thumb_branch
+  PARAMS ((insn32, int));
+#endif
+static bfd_reloc_status_type coff_thumb_pcrel_12
+  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
 static bfd_reloc_status_type coff_arm_reloc
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
 static boolean coff_arm_adjust_symndx
@@ -109,8 +113,6 @@ static const struct reloc_howto_struct * coff_arm_reloc_type_lookup
   PARAMS ((bfd *, bfd_reloc_code_real_type));
 static struct bfd_link_hash_table * coff_arm_link_hash_table_create
   PARAMS ((bfd *));
-static insn32 insert_thumb_branch
-  PARAMS ((insn32, int));
 static struct coff_link_hash_entry * find_thumb_glue
   PARAMS ((struct bfd_link_info *, const char *, bfd *));
 static struct coff_link_hash_entry * find_arm_glue
@@ -118,9 +120,11 @@ static struct coff_link_hash_entry * find_arm_glue
 #ifndef COFF_IMAGE_WITH_PE
 static void record_arm_to_thumb_glue
   PARAMS ((struct bfd_link_info *, struct coff_link_hash_entry *));
+#ifndef ARM_WINCE
 static void record_thumb_to_arm_glue
   PARAMS ((struct bfd_link_info *, struct coff_link_hash_entry *));
 #endif
+#endif
 static boolean coff_arm_merge_private_bfd_data
   PARAMS ((bfd *, bfd *));
 static boolean coff_arm_print_private_bfd_data
@@ -801,6 +805,7 @@ coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, input_section,
   return flag;
 }
 
+#ifndef ARM_WINCE
 static bfd_reloc_status_type
 coff_thumb_pcrel_23 (abfd, reloc_entry, symbol, data, input_section,
                     output_bfd, error_message)
@@ -818,7 +823,7 @@ coff_thumb_pcrel_23 (abfd, reloc_entry, symbol, data, input_section,
 }
 
 static bfd_reloc_status_type
-coff_thumb_pcrel_12 (abfd, reloc_entry, symbol, data, input_section,
+coff_thumb_pcrel_9 (abfd, reloc_entry, symbol, data, input_section,
                     output_bfd, error_message)
      bfd *abfd;
      arelent *reloc_entry;
@@ -830,11 +835,12 @@ coff_thumb_pcrel_12 (abfd, reloc_entry, symbol, data, input_section,
 {
   return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
                                   input_section, output_bfd, error_message,
-                                 b12);
+                                 b9);
 }
+#endif /* not ARM_WINCE */
 
 static bfd_reloc_status_type
-coff_thumb_pcrel_9 (abfd, reloc_entry, symbol, data, input_section,
+coff_thumb_pcrel_12 (abfd, reloc_entry, symbol, data, input_section,
                     output_bfd, error_message)
      bfd *abfd;
      arelent *reloc_entry;
@@ -846,7 +852,7 @@ coff_thumb_pcrel_9 (abfd, reloc_entry, symbol, data, input_section,
 {
   return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
                                   input_section, output_bfd, error_message,
-                                 b9);
+                                 b12);
 }
 
 static const struct reloc_howto_struct *
@@ -900,6 +906,13 @@ coff_arm_reloc_type_lookup (abfd, code)
 #define BADMAG(x) ARMBADMAG(x)
 #define ARM 1                  /* Customize coffcode.h */
 
+#ifndef ARM_WINCE
+/* Make sure that the 'r_offset' field is copied properly
+   so that identical binaries will compare the same.  */
+#define SWAP_IN_RELOC_OFFSET   H_GET_32
+#define SWAP_OUT_RELOC_OFFSET  H_PUT_32
+#endif
+
 /* Extend the coff_link_hash_table structure with a few ARM specific fields.
    This allows us to store global data here without actually creating any
    global variables, which is a no-no in the BFD world.  */
@@ -934,14 +947,14 @@ coff_arm_link_hash_table_create (abfd)
   struct coff_arm_link_hash_table * ret;
   bfd_size_type amt = sizeof (struct coff_arm_link_hash_table);
 
-  ret = (struct coff_arm_link_hash_table *) bfd_alloc (abfd, amt);
+  ret = (struct coff_arm_link_hash_table *) bfd_malloc (amt);
   if (ret == (struct coff_arm_link_hash_table *) NULL)
     return NULL;
 
   if (! _bfd_coff_link_hash_table_init
       (& ret->root, abfd, _bfd_coff_link_hash_newfunc))
     {
-      bfd_release (abfd, ret);
+      free (ret);
       return (struct bfd_link_hash_table *) NULL;
     }
 
@@ -970,6 +983,7 @@ arm_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
 
 }
 \f
+#ifndef ARM_WINCE
 /* The thumb form of a long branch is a bit finicky, because the offset
    encoding is split over two fields, each in it's own instruction. They
    can occur in any order. So given a thumb form of long branch, and an
@@ -1026,6 +1040,7 @@ insert_thumb_branch (br_insn, rel_off)
 
   return br_insn;
 }
+
 \f
 static struct coff_link_hash_entry *
 find_thumb_glue (info, name, input_bfd)
@@ -1049,12 +1064,13 @@ find_thumb_glue (info, name, input_bfd)
   if (myh == NULL)
     /* xgettext:c-format */
     _bfd_error_handler (_("%s: unable to find THUMB glue '%s' for `%s'"),
-                       bfd_get_filename (input_bfd), tmp_name, name);
+                       bfd_archive_filename (input_bfd), tmp_name, name);
 
   free (tmp_name);
 
   return myh;
 }
+#endif /* not ARM_WINCE */
 
 static struct coff_link_hash_entry *
 find_arm_glue (info, name, input_bfd)
@@ -1078,7 +1094,7 @@ find_arm_glue (info, name, input_bfd)
   if (myh == NULL)
     /* xgettext:c-format */
     _bfd_error_handler (_("%s: unable to find ARM glue '%s' for `%s'"),
-                       bfd_get_filename (input_bfd), tmp_name, name);
+                       bfd_archive_filename (input_bfd), tmp_name, name);
 
   free (tmp_name);
 
@@ -1373,11 +1389,11 @@ coff_arm_relocate_section (output_bfd, info, input_bfd, input_section,
                              _bfd_error_handler
                                /* xgettext:c-format */
                                (_("%s(%s): warning: interworking not enabled."),
-                                bfd_get_filename (h_sec->owner), name);
+                                bfd_archive_filename (h_sec->owner), name);
                              _bfd_error_handler
                                /* xgettext:c-format */
                                (_("  first occurrence: %s: arm call to thumb"),
-                                bfd_get_filename (input_bfd));
+                                bfd_archive_filename (input_bfd));
                            }
 
                          --my_offset;
@@ -1468,11 +1484,11 @@ coff_arm_relocate_section (output_bfd, info, input_bfd, input_section,
                              _bfd_error_handler
                                /* xgettext:c-format */
                                (_("%s(%s): warning: interworking not enabled."),
-                                bfd_get_filename (h_sec->owner), name);
+                                bfd_archive_filename (h_sec->owner), name);
                              _bfd_error_handler
                                /* xgettext:c-format */
                                (_("  first occurrence: %s: thumb call to arm"),
-                                bfd_get_filename (input_bfd));
+                                bfd_archive_filename (input_bfd));
                              _bfd_error_handler
                                (_("  consider relinking with --support-old-code enabled"));
                            }
@@ -1685,21 +1701,23 @@ coff_arm_relocate_section (output_bfd, info, input_bfd, input_section,
                  || signed_check < reloc_signed_min)
                overflow = true;
 
-             /* For the BLX(1) instruction remove bit 0 of the adjusted offset.
-                Bit 0 can only be set if the upper insn is at a half-word boundary,
-                since the destination address, an ARM instruction, must always be
-                on a word boundary.  The semantics of the BLX (1) instruction,
-                however, are that bit 0 in the offset must always be 0, and the
-                corresponding bit 1 in the target address will be set from bit
-                1 of the source address.  */
-             if ((x & 0x18000000) == 0x08000000)
-               relocation &= ~0x2;
-
-             /* Put the relocation into the correct bits.  */
+             /* Put the relocation into the correct bits.
+                For a BLX instruction, make sure that the relocation is rounded up
+                to a word boundary.  This follows the semantics of the instruction
+                which specifies that bit 1 of the target address will come from bit
+                1 of the base address.  */
              if (bfd_big_endian (input_bfd))
-               relocation = (((relocation & 0xffe) >> 1)  | ((relocation << 4) & 0x07ff0000));
+               {
+                 if ((x & 0x1800) == 0x0800 && (relocation & 0x02))
+                   relocation += 2;
+                 relocation = (((relocation & 0xffe) >> 1)  | ((relocation << 4) & 0x07ff0000));
+               }
              else
-               relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff));
+               {
+                 if ((x & 0x18000000) == 0x08000000 && (relocation & 0x02))
+                   relocation += 2;
+                 relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff));
+               }
 
              /* Add the relocation to the correct bits of X.  */
              x = ((x & ~howto->dst_mask) | relocation);
@@ -1765,7 +1783,7 @@ coff_arm_relocate_section (output_bfd, info, input_bfd, input_section,
        case bfd_reloc_outofrange:
          (*_bfd_error_handler)
            (_("%s: bad reloc address 0x%lx in section `%s'"),
-            bfd_get_filename (input_bfd),
+            bfd_archive_filename (input_bfd),
             (unsigned long) rel->r_vaddr,
             bfd_get_section_name (input_bfd, input_section));
          return false;
@@ -1909,6 +1927,7 @@ record_arm_to_thumb_glue (info, h)
   return;
 }
 
+#ifndef ARM_WINCE
 static void
 record_thumb_to_arm_glue (info, h)
      struct bfd_link_info *        info;
@@ -1982,6 +2001,7 @@ record_thumb_to_arm_glue (info, h)
 
   return;
 }
+#endif /* not ARM_WINCE */
 
 /* Select a BFD to be used to hold the sections used by the glue code.
    This function is called from the linker scripts in ld/emultempl/
@@ -2105,7 +2125,7 @@ bfd_arm_process_before_allocation (abfd, info, support_old_code)
          if (symndx >= obj_conv_table_size (abfd))
            {
              _bfd_error_handler (_("%s: illegal symbol index in reloc: %d"),
-                                 bfd_get_filename (abfd), symndx);
+                                 bfd_archive_filename (abfd), symndx);
              continue;
            }
 
@@ -2232,8 +2252,8 @@ coff_arm_merge_private_bfd_data (ibfd, obfd)
            {
              _bfd_error_handler
                /* xgettext: c-format */
-               (_("%s: ERROR: compiled for APCS-%d whereas target %s uses APCS-%d"),
-                bfd_get_filename (ibfd), APCS_26_FLAG (ibfd) ? 26 : 32,
+               (_("ERROR: %s is compiled for APCS-%d, whereas %s is compiled for APCS-%d"),
+                bfd_archive_filename (ibfd), APCS_26_FLAG (ibfd) ? 26 : 32,
                 bfd_get_filename (obfd), APCS_26_FLAG (obfd) ? 26 : 32
                 );
 
@@ -2247,12 +2267,12 @@ coff_arm_merge_private_bfd_data (ibfd, obfd)
 
              if (APCS_FLOAT_FLAG (ibfd))
                /* xgettext: c-format */
-               msg = _("%s: ERROR: passes floats in float registers whereas target %s uses integer registers");
+               msg = _("ERROR: %s passes floats in float registers, whereas %s passes them in integer registers");
              else
                /* xgettext: c-format */
-               msg = _("%s: ERROR: passes floats in integer registers whereas target %s uses float registers");
+               msg = _("ERROR: %s passes floats in integer registers, whereas %s passes them in float registers");
 
-             _bfd_error_handler (msg, bfd_get_filename (ibfd),
+             _bfd_error_handler (msg, bfd_archive_filename (ibfd),
                                  bfd_get_filename (obfd));
 
              bfd_set_error (bfd_error_wrong_format);
@@ -2265,11 +2285,11 @@ coff_arm_merge_private_bfd_data (ibfd, obfd)
 
              if (PIC_FLAG (ibfd))
                /* xgettext: c-format */
-               msg = _("%s: ERROR: compiled as position independent code, whereas target %s is absolute position");
+               msg = _("ERROR: %s is compiled as position independent code, whereas target %s is absolute position");
              else
                /* xgettext: c-format */
-               msg = _("%s: ERROR: compiled as absolute position code, whereas target %s is position independent");
-             _bfd_error_handler (msg, bfd_get_filename (ibfd),
+               msg = _("ERROR: %s is compiled as absolute position code, whereas target %s is position independent");
+             _bfd_error_handler (msg, bfd_archive_filename (ibfd),
                                  bfd_get_filename (obfd));
 
              bfd_set_error (bfd_error_wrong_format);
@@ -2297,12 +2317,12 @@ coff_arm_merge_private_bfd_data (ibfd, obfd)
 
              if (INTERWORK_FLAG (ibfd))
                /* xgettext: c-format */
-               msg = _("Warning: input file %s supports interworking, whereas %s does not.");
+               msg = _("Warning: %s supports interworking, whereas %s does not");
              else
                /* xgettext: c-format */
-               msg = _("Warning: input file %s does not support interworking, whereas %s does.");
+               msg = _("Warning: %s does not support interworking, whereas %s does");
 
-             _bfd_error_handler (msg, bfd_get_filename (ibfd),
+             _bfd_error_handler (msg, bfd_archive_filename (ibfd),
                                  bfd_get_filename (obfd));
            }
        }
@@ -2398,12 +2418,12 @@ _bfd_coff_arm_set_private_flags (abfd, flags)
     {
       if (flag)
        /* xgettext: c-format */
-       _bfd_error_handler (_("Warning: Not setting interworking flag of %s, since it has already been specified as non-interworking"),
-                           bfd_get_filename (abfd));
+       _bfd_error_handler (_("Warning: Not setting interworking flag of %s since it has already been specified as non-interworking"),
+                           bfd_archive_filename (abfd));
       else
        /* xgettext: c-format */
        _bfd_error_handler (_("Warning: Clearing the interworking flag of %s due to outside request"),
-                           bfd_get_filename (abfd));
+                           bfd_archive_filename (abfd));
       flag = 0;
     }
 
@@ -2461,9 +2481,10 @@ coff_arm_copy_private_bfd_data (src, dest)
              if (INTERWORK_FLAG (dest))
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (("Warning: Clearing the interworking bit of %s, because the non-interworking code in %s has been copied into it"),
+                 _bfd_error_handler (("\
+Warning: Clearing the interworking flag of %s because non-interworking code in %s has been linked with it"),
                                      bfd_get_filename (dest),
-                                     bfd_get_filename (src));
+                                     bfd_archive_filename (src));
                }
 
              SET_INTERWORK_FLAG (dest, 0);
This page took 0.029696 seconds and 4 git commands to generate.