Fix potential segfault
[deliverable/binutils-gdb.git] / bfd / coff-arm.c
index 79d4d9cefa04d9b1f0faa7d44f65ddc2e0dc7b28..53e4d3c8ffa45e9bca6a35a20fa0206d053a40f0 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for ARM COFF files.
-   Copyright (C) 1990-2017 Free Software Foundation, Inc.
+   Copyright (C) 1990-2020 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -24,6 +24,8 @@
 #include "libbfd.h"
 #include "coff/arm.h"
 #include "coff/internal.h"
+#include "cpu-arm.h"
+#include "coff-arm.h"
 
 #ifdef COFF_WITH_PE
 #include "coff/pe.h"
@@ -31,6 +33,9 @@
 
 #include "libcoff.h"
 
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
+
 /* Macros for manipulation the bits in the flags field of the coff data
    structure.  */
 #define APCS_26_FLAG(abfd) \
@@ -94,7 +99,7 @@ coff_arm_reloc (bfd *abfd,
                arelent *reloc_entry,
                asymbol *symbol ATTRIBUTE_UNUSED,
                void * data,
-               asection *input_section ATTRIBUTE_UNUSED,
+               asection *input_section,
                bfd *output_bfd,
                char **error_message ATTRIBUTE_UNUSED)
 {
@@ -112,11 +117,11 @@ coff_arm_reloc (bfd *abfd,
   if (diff != 0)
     {
       reloc_howto_type *howto = reloc_entry->howto;
-      unsigned char *addr = (unsigned char *) data + reloc_entry->address;
+      bfd_size_type octets = (reloc_entry->address
+                             * OCTETS_PER_BYTE (abfd, input_section));
+      unsigned char *addr = (unsigned char *) data + octets;
 
-      if (! bfd_reloc_offset_in_range (howto, abfd, input_section,
-                                      reloc_entry->address
-                                      * bfd_octets_per_byte (abfd)))
+      if (!bfd_reloc_offset_in_range (howto, abfd, input_section, octets))
        return bfd_reloc_outofrange;
 
       switch (howto->size)
@@ -814,7 +819,7 @@ coff_thumb_pcrel_12 (bfd *abfd,
                                  b12);
 }
 
-static const struct reloc_howto_struct *
+static reloc_howto_type *
 coff_arm_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code)
 {
 #define ASTD(i,j)       case i: return aoutarm_std_reloc_howto + j
@@ -919,7 +924,7 @@ static struct bfd_link_hash_table *
 coff_arm_link_hash_table_create (bfd * abfd)
 {
   struct coff_arm_link_hash_table * ret;
-  bfd_size_type amt = sizeof (struct coff_arm_link_hash_table);
+  size_t amt = sizeof (struct coff_arm_link_hash_table);
 
   ret = bfd_zmalloc (amt);
   if (ret == NULL)
@@ -1021,7 +1026,7 @@ find_thumb_glue (struct bfd_link_info *info,
 {
   char *tmp_name;
   struct coff_link_hash_entry *myh;
-  bfd_size_type amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
+  size_t amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
 
   tmp_name = bfd_malloc (amt);
 
@@ -1034,7 +1039,7 @@ find_thumb_glue (struct bfd_link_info *info,
 
   if (myh == NULL)
     /* xgettext:c-format */
-    _bfd_error_handler (_("%B: unable to find THUMB glue '%s' for `%s'"),
+    _bfd_error_handler (_("%pB: unable to find THUMB glue '%s' for `%s'"),
                        input_bfd, tmp_name, name);
 
   free (tmp_name);
@@ -1050,7 +1055,7 @@ find_arm_glue (struct bfd_link_info *info,
 {
   char *tmp_name;
   struct coff_link_hash_entry * myh;
-  bfd_size_type amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
+  size_t amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
 
   tmp_name = bfd_malloc (amt);
 
@@ -1063,7 +1068,7 @@ find_arm_glue (struct bfd_link_info *info,
 
   if (myh == NULL)
     /* xgettext:c-format */
-    _bfd_error_handler (_("%B: unable to find ARM glue '%s' for `%s'"),
+    _bfd_error_handler (_("%pB: unable to find ARM glue '%s' for `%s'"),
                        input_bfd, tmp_name, name);
 
   free (tmp_name);
@@ -1149,7 +1154,7 @@ static const insn32 t2a6_bx_insn    = 0xe12fff1e;
 
 /* The standard COFF backend linker does not cope with the special
    Thumb BRANCH23 relocation.  The alternative would be to split the
-   BRANCH23 into seperate HI23 and LO23 relocations. However, it is a
+   BRANCH23 into separate HI23 and LO23 relocations. However, it is a
    bit simpler simply providing our own relocation driver.  */
 
 /* The reloc processing routine for the ARM/Thumb COFF linker.  NOTE:
@@ -1274,9 +1279,8 @@ coff_arm_relocate_section (bfd *output_bfd,
            continue;
          /* FIXME - it is not clear which targets need this next test
             and which do not.  It is known that it is needed for the
-            VxWorks and EPOC-PE targets, but it is also known that it
-            was suppressed for other ARM targets.  This ought to be
-            sorted out one day.  */
+            VxWorks targets but it is also known that it was suppressed
+            for other ARM targets.  This ought to be sorted out one day.  */
 #ifdef ARM_COFF_BUGFIX
          /* We must not ignore the symbol value.  If the symbol is
             within the same section, the relocation should have already
@@ -1365,8 +1369,8 @@ coff_arm_relocate_section (bfd *output_bfd,
                              && ! INTERWORK_FLAG (h_sec->owner))
                            _bfd_error_handler
                              /* xgettext:c-format */
-                             (_("%B(%s): warning: interworking not enabled.\n"
-                                "  first occurrence: %B: arm call to thumb"),
+                             (_("%pB(%s): warning: interworking not enabled; "
+                                "first occurrence: %pB: arm call to thumb"),
                               h_sec->owner, name, input_bfd);
 
                          --my_offset;
@@ -1455,9 +1459,10 @@ coff_arm_relocate_section (bfd *output_bfd,
                              && ! globals->support_old_code)
                            _bfd_error_handler
                              /* xgettext:c-format */
-                             (_("%B(%s): warning: interworking not enabled.\n"
-                                "  first occurrence: %B: thumb call to arm\n"
-                                "  consider relinking with --support-old-code enabled"),
+                             (_("%pB(%s): warning: interworking not enabled; "
+                                "first occurrence: %pB: thumb call to arm; "
+                                "consider relinking with --support-old-code "
+                                "enabled"),
                               h_sec->owner, name, input_bfd);
 
                          -- my_offset;
@@ -1748,8 +1753,8 @@ coff_arm_relocate_section (bfd *output_bfd,
        case bfd_reloc_outofrange:
          _bfd_error_handler
            /* xgettext:c-format */
-           (_("%B: bad reloc address %#Lx in section `%A'"),
-            input_bfd, rel->r_vaddr, input_section);
+           (_("%pB: bad reloc address %#" PRIx64 " in section `%pA'"),
+            input_bfd, (uint64_t) rel->r_vaddr, input_section);
          return FALSE;
        case bfd_reloc_overflow:
          {
@@ -1835,7 +1840,7 @@ record_arm_to_thumb_glue (struct bfd_link_info *  info,
   struct bfd_link_hash_entry *     bh;
   struct coff_arm_link_hash_table * globals;
   bfd_vma val;
-  bfd_size_type amt;
+  size_t amt;
 
   globals = coff_arm_hash_table (info);
 
@@ -1891,7 +1896,7 @@ record_thumb_to_arm_glue (struct bfd_link_info *  info,
   struct bfd_link_hash_entry *      bh;
   struct coff_arm_link_hash_table *  globals;
   bfd_vma val;
-  bfd_size_type amt;
+  size_t amt;
 
   globals = coff_arm_hash_table (info);
 
@@ -1989,7 +1994,7 @@ bfd_arm_get_bfd_for_interworking (bfd *                    abfd,
       sec = bfd_make_section_with_flags (abfd, ARM2THUMB_GLUE_SECTION_NAME,
                                         flags);
       if (sec == NULL
-         || ! bfd_set_section_alignment (abfd, sec, 2))
+         || !bfd_set_section_alignment (sec, 2))
        return FALSE;
     }
 
@@ -2003,7 +2008,7 @@ bfd_arm_get_bfd_for_interworking (bfd *                    abfd,
                                         flags);
 
       if (sec == NULL
-         || ! bfd_set_section_alignment (abfd, sec, 2))
+         || !bfd_set_section_alignment (sec, 2))
        return FALSE;
     }
 
@@ -2073,7 +2078,7 @@ bfd_arm_process_before_allocation (bfd *             abfd,
          if (symndx >= obj_conv_table_size (abfd))
            {
              /* xgettext:c-format */
-             _bfd_error_handler (_("%B: illegal symbol index in reloc: %ld"),
+             _bfd_error_handler (_("%pB: illegal symbol index in reloc: %ld"),
                                  abfd, symndx);
              continue;
            }
@@ -2205,7 +2210,8 @@ coff_arm_merge_private_bfd_data (bfd * ibfd, struct bfd_link_info *info)
            {
              _bfd_error_handler
                /* xgettext: c-format */
-               (_("error: %B is compiled for APCS-%d, whereas %B is compiled for APCS-%d"),
+               (_("error: %pB is compiled for APCS-%d, "
+                  "whereas %pB is compiled for APCS-%d"),
                 ibfd, APCS_26_FLAG (ibfd) ? 26 : 32,
                 obfd, APCS_26_FLAG (obfd) ? 26 : 32
                 );
@@ -2218,14 +2224,16 @@ coff_arm_merge_private_bfd_data (bfd * ibfd, struct bfd_link_info *info)
            {
              if (APCS_FLOAT_FLAG (ibfd))
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-error: %B passes floats in float registers, whereas %B passes them in integer registers"),
-                                   ibfd, obfd);
+               _bfd_error_handler
+                 (_("error: %pB passes floats in float registers, "
+                    "whereas %pB passes them in integer registers"),
+                  ibfd, obfd);
              else
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-error: %B passes floats in integer registers, whereas %B passes them in float registers"),
-                                   ibfd, obfd);
+               _bfd_error_handler
+                 (_("error: %pB passes floats in integer registers, "
+                    "whereas %pB passes them in float registers"),
+                  ibfd, obfd);
 
              bfd_set_error (bfd_error_wrong_format);
              return FALSE;
@@ -2235,14 +2243,16 @@ error: %B passes floats in integer registers, whereas %B passes them in float re
            {
              if (PIC_FLAG (ibfd))
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-error: %B is compiled as position independent code, whereas target %B is absolute position"),
-                                   ibfd, obfd);
+               _bfd_error_handler
+                 (_("error: %pB is compiled as position independent code, "
+                    "whereas target %pB is absolute position"),
+                  ibfd, obfd);
              else
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-error: %B is compiled as absolute position code, whereas target %B is position independent"),
-                                   ibfd, obfd);
+               _bfd_error_handler
+                 (_("error: %pB is compiled as absolute position code, "
+                    "whereas target %pB is position independent"),
+                  ibfd, obfd);
 
              bfd_set_error (bfd_error_wrong_format);
              return FALSE;
@@ -2267,14 +2277,15 @@ error: %B is compiled as absolute position code, whereas target %B is position i
            {
              if (INTERWORK_FLAG (ibfd))
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-Warning: %B supports interworking, whereas %B does not"),
+               _bfd_error_handler (_("warning: %pB supports interworking, "
+                                     "whereas %pB does not"),
                                    ibfd, obfd);
              else
                /* xgettext: c-format */
-               _bfd_error_handler (_("\
-Warning: %B does not support interworking, whereas %B does"),
-                                   ibfd, obfd);
+               _bfd_error_handler
+                 (_("warning: %pB does not support interworking, "
+                    "whereas %pB does"),
+                  ibfd, obfd);
            }
        }
       else
@@ -2363,10 +2374,10 @@ _bfd_coff_arm_set_private_flags (bfd * abfd, flagword flags)
   if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
     {
       if (flag)
-       _bfd_error_handler (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
+       _bfd_error_handler (_("warning: not setting interworking flag of %pB since it has already been specified as non-interworking"),
                            abfd);
       else
-       _bfd_error_handler (_("Warning: Clearing the interworking flag of %B due to outside request"),
+       _bfd_error_handler (_("warning: clearing the interworking flag of %pB due to outside request"),
                            abfd);
       flag = 0;
     }
@@ -2423,9 +2434,11 @@ coff_arm_copy_private_bfd_data (bfd * src, bfd * dest)
              if (INTERWORK_FLAG (dest))
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (_("\
-Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
-                                     dest, src);
+                 _bfd_error_handler
+                   (_("warning: clearing the interworking flag of %pB "
+                      "because non-interworking code in %pB has been "
+                      "linked with it"),
+                    dest, src);
                }
 
              SET_INTERWORK_FLAG (dest, 0);
This page took 0.029608 seconds and 4 git commands to generate.