1998-09-08 Jason Molenda (jsm@bugshack.cygnus.com)
[deliverable/binutils-gdb.git] / bfd / coffswap.h
index 75bbf32221cd48a3d42f0d6b1f669bf842312928..28c441545dd9542dae44c8c9547a868f90c6ec0b 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic COFF swapping routines, for BFD.
-   Copyright 1990, 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
+   Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -169,6 +169,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
 #endif
 
+static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
+static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
+static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_filehdr_out PARAMS ((bfd *, PTR, PTR));
+#ifndef NO_COFF_RELOCS
+static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
+#endif /* NO_COFF_RELOCS */
+#ifndef NO_COFF_SYMBOLS
+static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
+static void coff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+static unsigned int coff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
+#endif /* NO_COFF_SYMBOLS */
+#ifndef NO_COFF_LINENOS
+static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
+#endif /* NO_COFF_LINENOS */
+
 #ifndef NO_COFF_RELOCS
 
 static void
@@ -196,7 +217,6 @@ coff_swap_reloc_in (abfd, src, dst)
 #endif
 }
 
-
 static unsigned int
 coff_swap_reloc_out (abfd, src, dst)
      bfd       *abfd;
@@ -225,7 +245,7 @@ coff_swap_reloc_out (abfd, src, dst)
   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
 #endif
 
-  return sizeof(struct external_reloc);
+  return RELSZ;
 }
 
 #endif /* NO_COFF_RELOCS */
@@ -238,6 +258,9 @@ coff_swap_filehdr_in (abfd, src, dst)
 {
   FILHDR *filehdr_src = (FILHDR *) src;
   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
+#ifdef COFF_ADJUST_FILEHDR_IN_PRE
+  COFF_ADJUST_FILEHDR_IN_PRE (abfd, src, dst);
+#endif
   filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
   filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
   filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
@@ -246,6 +269,15 @@ coff_swap_filehdr_in (abfd, src, dst)
   filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
   filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
   filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
+/* start-sanitize-tic80 */
+#ifdef TIC80_TARGET_ID
+  filehdr_dst->f_target_id = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_target_id);
+#endif
+/* end-sanitize-tic80 */
+
+#ifdef COFF_ADJUST_FILEHDR_IN_POST
+  COFF_ADJUST_FILEHDR_IN_POST (abfd, src, dst);
+#endif
 }
 
 static  unsigned int
@@ -257,6 +289,9 @@ coff_swap_filehdr_out (abfd, in, out)
   struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
   FILHDR *filehdr_out = (FILHDR *)out;
 
+#ifdef COFF_ADJUST_FILEHDR_OUT_PRE
+  COFF_ADJUST_FILEHDR_OUT_PRE (abfd, in, out);
+#endif
   bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
   bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
   bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
@@ -265,8 +300,16 @@ coff_swap_filehdr_out (abfd, in, out)
   bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
   bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
   bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
+/* start-sanitize-tic80 */
+#ifdef TIC80_TARGET_ID
+  bfd_h_put_16(abfd, filehdr_in->f_target_id, (bfd_byte *) filehdr_out->f_target_id);
+#endif
+/* end-sanitize-tic80 */
 
-  return sizeof(FILHDR);
+#ifdef COFF_ADJUST_FILEHDR_OUT_POST
+  COFF_ADJUST_FILEHDR_OUT_POST (abfd, in, out);
+#endif
+  return FILHSZ;
 }
 
 
@@ -335,7 +378,7 @@ coff_swap_sym_out (abfd, inp, extp)
       }
   bfd_h_put_8(abfd,  in->n_sclass , ext->e_sclass);
   bfd_h_put_8(abfd,  in->n_numaux , ext->e_numaux);
-  return sizeof(SYMENT);
+  return SYMESZ;
 }
 
 static void
@@ -351,6 +394,9 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
   AUXENT    *ext = (AUXENT *)ext1;
   union internal_auxent *in = (union internal_auxent *)in1;
 
+#ifdef COFF_ADJUST_AUX_IN_PRE
+  COFF_ADJUST_AUX_IN_PRE (abfd, ext1, type, class, indx, numaux, in1);
+#endif
   switch (class) {
     case C_FILE:
       if (ext->x_file.x_fname[0] == 0) {
@@ -364,7 +410,7 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
            memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
 #endif
          }
-      return;
+      goto end;
 
       /* RS/6000 "csect" auxents */
 #ifdef RS6000COFF_C
@@ -383,7 +429,7 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
          in->x_csect.x_smclas   = bfd_h_get_8  (abfd, ext->x_csect.x_smclas);
          in->x_csect.x_stab     = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
          in->x_csect.x_snstab   = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
-         return;
+         goto end;
        }
       break;
 #endif
@@ -397,7 +443,14 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
          in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
          in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
          in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
-         return;
+
+         /* PE defines some extra fields; we zero them out for
+             safety.  */
+         in->x_scn.x_checksum = 0;
+         in->x_scn.x_associated = 0;
+         in->x_scn.x_comdat = 0;
+
+         goto end;
        }
       break;
     }
@@ -407,7 +460,7 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
   in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
 #endif
 
-  if (class == C_BLOCK || ISFCN (type) || ISTAG (class))
+  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
     {
       in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
       in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
@@ -434,6 +487,11 @@ coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
     in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
     in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
   }
+
+end:
+#ifdef COFF_ADJUST_AUX_IN_POST
+  COFF_ADJUST_AUX_IN_POST (abfd, ext1, type, class, indx, numaux, in1);
+#endif
 }
 
 static unsigned int
@@ -449,6 +507,9 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
   union internal_auxent *in = (union internal_auxent *)inp;
   AUXENT *ext = (AUXENT *)extp;
 
+#ifdef COFF_ADJUST_AUX_OUT_PRE
+  COFF_ADJUST_AUX_OUT_PRE (abfd, inp, type, class, indx, numaux, extp);
+#endif
   memset((PTR)ext, 0, AUXESZ);
   switch (class) {
   case C_FILE:
@@ -465,7 +526,7 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
 #endif
     }
-    return sizeof (AUXENT);
+    goto end;
 
 #ifdef RS6000COFF_C
   /* RS/6000 "csect" auxents */
@@ -483,7 +544,7 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
        PUTBYTE (abfd, in->x_csect.x_smclas,    ext->x_csect.x_smclas);
        PUTWORD (abfd, in->x_csect.x_stab,      ext->x_csect.x_stab);
        PUTHALF (abfd, in->x_csect.x_snstab,    ext->x_csect.x_snstab);
-       return sizeof (AUXENT);
+       goto end;
       }
     break;
 #endif
@@ -497,7 +558,7 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
       PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
       PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
       PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
-      return sizeof (AUXENT);
+      goto end;
     }
     break;
   }
@@ -507,7 +568,7 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
   bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
 #endif
 
-  if (class == C_BLOCK || ISFCN (type) || ISTAG (class))
+  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
     {
       PUT_FCN_LNNOPTR(abfd,  in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
       PUT_FCN_ENDNDX(abfd,  in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
@@ -536,7 +597,11 @@ coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
       PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
     }
 
-  return sizeof(AUXENT);
+end:
+#ifdef COFF_ADJUST_AUX_OUT_POST
+  COFF_ADJUST_AUX_OUT_POST (abfd, inp, type, class, indx, numaux, extp);
+#endif
+  return AUXESZ;
 }
 
 #endif /* NO_COFF_SYMBOLS */
@@ -568,12 +633,11 @@ coff_swap_lineno_out (abfd, inp, outp)
          ext->l_addr.l_symndx);
 
   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
-  return sizeof(struct external_lineno);
+  return LINESZ;
 }
 
 #endif /* NO_COFF_LINENOS */
 
-
 static void
 coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
      bfd            *abfd;
@@ -621,6 +685,7 @@ coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
   aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
   aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
   aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
+  aouthdr_int->o_cputype = bfd_h_get_16(abfd, aouthdr_ext->o_cputype);
   aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
   aouthdr_int->o_maxdata = bfd_h_get_32(abfd, aouthdr_ext->o_maxdata);
 #endif
@@ -678,9 +743,9 @@ coff_swap_aouthdr_out (abfd, in, out)
   bfd_h_put_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext);
   bfd_h_put_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata);
   bfd_h_put_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype);
+  bfd_h_put_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype);
   bfd_h_put_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
   bfd_h_put_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
-  memset (aouthdr_out->o_resv1, 0, sizeof aouthdr_out->o_resv1);
   memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2);
 #endif
 
@@ -704,7 +769,7 @@ coff_swap_aouthdr_out (abfd, in, out)
   bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
 #endif
 
-  return sizeof(AOUTHDR);
+  return AOUTSZ;
 }
 
 static void
@@ -716,6 +781,9 @@ coff_swap_scnhdr_in (abfd, ext, in)
   SCNHDR *scnhdr_ext = (SCNHDR *) ext;
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
 
+#ifdef COFF_ADJUST_SCNHDR_IN_PRE
+  COFF_ADJUST_SCNHDR_IN_PRE (abfd, ext, in);
+#endif
   memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
   scnhdr_int->s_vaddr =
     GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
@@ -741,6 +809,9 @@ coff_swap_scnhdr_in (abfd, ext, in)
 #ifdef I960
   scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
 #endif
+#ifdef COFF_ADJUST_SCNHDR_IN_POST
+  COFF_ADJUST_SCNHDR_IN_POST (abfd, ext, in);
+#endif
 }
 
 static unsigned int
@@ -751,8 +822,11 @@ coff_swap_scnhdr_out (abfd, in, out)
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
   SCNHDR *scnhdr_ext = (SCNHDR *)out;
-  unsigned int ret = sizeof (SCNHDR);
+  unsigned int ret = SCNHSZ;
 
+#ifdef COFF_ADJUST_SCNHDR_OUT_PRE
+  COFF_ADJUST_SCNHDR_OUT_PRE (abfd, in, out);
+#endif
   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
 
   PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
@@ -779,20 +853,27 @@ coff_swap_scnhdr_out (abfd, in, out)
     PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
   else
     {
-      (*_bfd_error_handler) ("%s: line number overflow: 0x%lx > 0xffff",
-                            bfd_get_filename (abfd),
-                            scnhdr_int->s_nlnno);
-      bfd_set_error (bfd_error_file_truncated);
+      char buf[sizeof (scnhdr_int->s_name) + 1];
+
+      memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
+      buf[sizeof (scnhdr_int->s_name)] = '\0';
+      (*_bfd_error_handler)
+       ("%s: warning: %s: line number overflow: 0x%lx > 0xffff",
+        bfd_get_filename (abfd),
+        buf, scnhdr_int->s_nlnno);
       PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nlnno);
-      ret = 0;
     }
   if (scnhdr_int->s_nreloc <= 0xffff)
     PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
   else
     {
-      (*_bfd_error_handler) ("%s: reloc overflow: 0x%lx > 0xffff",
+      char buf[sizeof (scnhdr_int->s_name) + 1];
+
+      memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
+      buf[sizeof (scnhdr_int->s_name)] = '\0';
+      (*_bfd_error_handler) ("%s: %s: reloc overflow: 0x%lx > 0xffff",
                             bfd_get_filename (abfd),
-                            scnhdr_int->s_nreloc);
+                            buf, scnhdr_int->s_nreloc);
       bfd_set_error (bfd_error_file_truncated);
       PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nreloc);
       ret = 0;
@@ -801,6 +882,9 @@ coff_swap_scnhdr_out (abfd, in, out)
 
 #if defined(I960)
   PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
+#endif
+#ifdef COFF_ADJUST_SCNHDR_OUT_POST
+  COFF_ADJUST_SCNHDR_OUT_POST (abfd, in, out);
 #endif
   return ret;
 }
This page took 0.027814 seconds and 4 git commands to generate.