ubsan: moxie: left shift of negative value
[deliverable/binutils-gdb.git] / bfd / coff-stgo32.c
index a43bf14f048ceeee5655fe50dc348b501fcf6dfb..59d24275add89adf8741b35ea52af7043cb2ebd5 100644 (file)
@@ -1,6 +1,5 @@
 /* BFD back-end for Intel 386 COFF files (DJGPP variant with a stub).
-   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1997-2019 Free Software Foundation, Inc.
    Written by Robert Hoehne.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -36,7 +35,7 @@
    To be compatible with any existing executables I have fixed this
    here and NOT in the DJGPP startup code.  */
 
-#define TARGET_SYM             go32stubbedcoff_vec
+#define TARGET_SYM             i386_coff_go32stubbed_vec
 #define TARGET_NAME            "coff-go32-exe"
 #define TARGET_UNDERSCORE      '_'
 #define COFF_GO32_EXE
 { COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
 
+#include "sysdep.h"
 #include "bfd.h"
 
-/* At first the prototypes.  */
+/* All that ..._PRE and ...POST functions are called from the corresponding
+   coff_swap... functions. The ...PRE functions are called at the beginning
+   of the function and the ...POST functions at the end of the swap routines.  */
 
 static void
-adjust_filehdr_in_post PARAMS ((bfd *, PTR, PTR));
+adjust_filehdr_in_post  (bfd *, void *, void *);
 static void
-adjust_filehdr_out_pre PARAMS ((bfd *, PTR, PTR));
+adjust_filehdr_out_pre  (bfd *, void *, void *);
 static void
-adjust_filehdr_out_post PARAMS ((bfd *, PTR, PTR));
+adjust_filehdr_out_post  (bfd *, void *, void *);
 static void
-adjust_scnhdr_in_post PARAMS ((bfd *, PTR, PTR));
+adjust_scnhdr_in_post  (bfd *, void *, void *);
 static void
-adjust_scnhdr_out_pre PARAMS ((bfd *, PTR, PTR));
+adjust_scnhdr_out_pre  (bfd *, void *, void *);
 static void
-adjust_scnhdr_out_post PARAMS ((bfd *, PTR, PTR));
+adjust_scnhdr_out_post (bfd *, void *, void *);
 static void
-adjust_aux_in_post PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+adjust_aux_in_post (bfd *, void *, int, int, int, int, void *);
 static void
-adjust_aux_out_pre PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+adjust_aux_out_pre (bfd *, void *, int, int, int, int, void *);
 static void
-adjust_aux_out_post PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+adjust_aux_out_post (bfd *, void *, int, int, int, int, void *);
 static void
-create_go32_stub PARAMS ((bfd *));
-
-/* All that ..._PRE and ...POST functions are called from the corresponding
-   coff_swap... functions. The ...PRE functions are called at the beginning
-   of the function and the ...POST functions at the end of the swap routines.  */
+create_go32_stub (bfd *);
 
 #define COFF_ADJUST_FILEHDR_IN_POST adjust_filehdr_in_post
 #define COFF_ADJUST_FILEHDR_OUT_PRE adjust_filehdr_out_pre
@@ -95,16 +93,20 @@ create_go32_stub PARAMS ((bfd *));
 #define COFF_ADJUST_AUX_OUT_PRE adjust_aux_out_pre
 #define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post
 
+static const bfd_target *go32_check_format (bfd *);
+
+#define COFF_CHECK_FORMAT go32_check_format
+
 static bfd_boolean
-  go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+  go32_stubbed_coff_bfd_copy_private_bfd_data (bfd *, bfd *);
 
 #define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
 
 #include "coff-i386.c"
 
-/* This macro is used, because I cannot assume the endianess of the
+/* This macro is used, because I cannot assume the endianness of the
    host system.  */
-#define _H(index) (H_GET_16 (abfd, (header+index*2)))
+#define _H(index) (H_GET_16 (abfd, (header + index * 2)))
 
 /* These bytes are a 2048-byte DOS executable, which loads the COFF
    image into memory and then runs it. It is called 'stub'.  */
@@ -128,10 +130,9 @@ static const unsigned char stub_bytes[GO32_STUBSIZE] =
   if (val != 0) val += diff
 
 static void
-adjust_filehdr_in_post  (abfd, src, dst)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR src;
-     PTR dst;
+adjust_filehdr_in_post  (bfd *  abfd ATTRIBUTE_UNUSED,
+                        void * src,
+                        void * dst)
 {
   FILHDR *filehdr_src = (FILHDR *) src;
   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
@@ -146,10 +147,7 @@ adjust_filehdr_in_post  (abfd, src, dst)
 }
 
 static void
-adjust_filehdr_out_pre  (abfd, in, out)
-     bfd *abfd;
-     PTR in;
-     PTR out;
+adjust_filehdr_out_pre  (bfd * abfd, void * in, void * out)
 {
   struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
   FILHDR *filehdr_out = (FILHDR *) out;
@@ -168,10 +166,9 @@ adjust_filehdr_out_pre  (abfd, in, out)
 }
 
 static void
-adjust_filehdr_out_post  (abfd, in, out)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR in;
-     PTR out ATTRIBUTE_UNUSED;
+adjust_filehdr_out_post  (bfd *  abfd ATTRIBUTE_UNUSED,
+                         void * in,
+                         void * out ATTRIBUTE_UNUSED)
 {
   struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
   /* Undo the above change.  */
@@ -179,10 +176,9 @@ adjust_filehdr_out_post  (abfd, in, out)
 }
 
 static void
-adjust_scnhdr_in_post  (abfd, ext, in)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR ext ATTRIBUTE_UNUSED;
-     PTR in;
+adjust_scnhdr_in_post  (bfd *  abfd ATTRIBUTE_UNUSED,
+                       void * ext ATTRIBUTE_UNUSED,
+                       void * in)
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
 
@@ -192,10 +188,9 @@ adjust_scnhdr_in_post  (abfd, ext, in)
 }
 
 static void
-adjust_scnhdr_out_pre  (abfd, in, out)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR in;
-     PTR out ATTRIBUTE_UNUSED;
+adjust_scnhdr_out_pre  (bfd *  abfd ATTRIBUTE_UNUSED,
+                       void * in,
+                       void * out ATTRIBUTE_UNUSED)
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
 
@@ -205,10 +200,9 @@ adjust_scnhdr_out_pre  (abfd, in, out)
 }
 
 static void
-adjust_scnhdr_out_post (abfd, in, out)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR in;
-     PTR out ATTRIBUTE_UNUSED;
+adjust_scnhdr_out_post (bfd *  abfd ATTRIBUTE_UNUSED,
+                       void * in,
+                       void * out ATTRIBUTE_UNUSED)
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
 
@@ -218,54 +212,54 @@ adjust_scnhdr_out_post (abfd, in, out)
 }
 
 static void
-adjust_aux_in_post  (abfd, ext1, type, class, indx, numaux, in1)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR ext1 ATTRIBUTE_UNUSED;
-     int type;
-     int class;
-     int indx ATTRIBUTE_UNUSED;
-     int numaux ATTRIBUTE_UNUSED;
-     PTR in1;
+adjust_aux_in_post (bfd * abfd ATTRIBUTE_UNUSED,
+                   void * ext1 ATTRIBUTE_UNUSED,
+                   int type,
+                   int in_class,
+                   int indx ATTRIBUTE_UNUSED,
+                   int numaux ATTRIBUTE_UNUSED,
+                   void * in1)
 {
   union internal_auxent *in = (union internal_auxent *) in1;
 
-  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
+  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
+      || ISTAG (in_class))
     {
       ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, GO32_STUBSIZE);
     }
 }
 
 static void
-adjust_aux_out_pre  (abfd, inp, type, class, indx, numaux, extp)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR inp;
-     int type;
-     int class;
-     int indx ATTRIBUTE_UNUSED;
-     int numaux ATTRIBUTE_UNUSED;
-     PTR extp ATTRIBUTE_UNUSED;
+adjust_aux_out_pre (bfd *abfd ATTRIBUTE_UNUSED,
+                   void * inp,
+                   int type,
+                   int in_class,
+                   int indx ATTRIBUTE_UNUSED,
+                   int numaux ATTRIBUTE_UNUSED,
+                   void * extp ATTRIBUTE_UNUSED)
 {
   union internal_auxent *in = (union internal_auxent *) inp;
 
-  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
+  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
+      || ISTAG (in_class))
     {
       ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, -GO32_STUBSIZE);
     }
 }
 
 static void
-adjust_aux_out_post (abfd, inp, type, class, indx, numaux, extp)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     PTR inp;
-     int type;
-     int class;
-     int indx ATTRIBUTE_UNUSED;
-     int numaux ATTRIBUTE_UNUSED;
-     PTR extp ATTRIBUTE_UNUSED;
+adjust_aux_out_post (bfd *abfd ATTRIBUTE_UNUSED,
+                    void * inp,
+                    int type,
+                    int in_class,
+                    int indx ATTRIBUTE_UNUSED,
+                    int numaux ATTRIBUTE_UNUSED,
+                    void * extp ATTRIBUTE_UNUSED)
 {
   union internal_auxent *in = (union internal_auxent *) inp;
 
-  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
+  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
+      || ISTAG (in_class))
     {
       ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, GO32_STUBSIZE);
     }
@@ -284,8 +278,7 @@ adjust_aux_out_post (abfd, inp, type, class, indx, numaux, extp)
    is taken.  */
 
 static void
-create_go32_stub (abfd)
-     bfd *abfd;
+create_go32_stub (bfd *abfd)
 {
   /* Do it only once.  */
   if (coff_data (abfd)->go32stub == NULL)
@@ -325,13 +318,13 @@ create_go32_stub (abfd)
          goto stub_end;
        }
       /* Compute the size of the stub (it is every thing up
-         to the beginning of the coff image).  */
+        to the beginning of the coff image).  */
       coff_start = (long) _H (2) * 512L;
       if (_H (1))
        coff_start += (long) _H (1) - 512L;
 
       /* Currently there is only a fixed stub size of 2048 bytes
-         supported.  */
+        supported.  */
       if (coff_start != 2048)
        {
          close (f);
@@ -386,9 +379,7 @@ stub_end:
    to the new obfd.  */
 
 static bfd_boolean
-go32_stubbed_coff_bfd_copy_private_bfd_data  (ibfd, obfd)
-     bfd *ibfd;
-     bfd *obfd;
+go32_stubbed_coff_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 {
   /* Check if both are the same targets.  */
   if (ibfd->xvec != obfd->xvec)
@@ -411,3 +402,23 @@ go32_stubbed_coff_bfd_copy_private_bfd_data  (ibfd, obfd)
 
   return TRUE;
 }
+
+/* coff_object_p only checks 2 bytes F_MAGIC at GO32_STUBSIZE inside the file
+   which is too fragile.  */
+
+static const bfd_target *
+go32_check_format (bfd *abfd)
+{
+  char mz[2];
+
+  if (bfd_bread (mz, 2, abfd) != 2 || mz[0] != 'M' || mz[1] != 'Z')
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return NULL;
+    }
+
+  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
+    return NULL;
+
+  return coff_object_p (abfd);
+}
This page took 0.027226 seconds and 4 git commands to generate.