* config.sub (case $basic_machine): Add tic80 entries.
[deliverable/binutils-gdb.git] / bfd / peicode.h
index 1797e80f9a2ab2db13f1a6038528ea6e6a0383ad..19c01501e4268e376af93e2a8e4f7472f7a532eb 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for the generic parts of most COFF variants, for BFD.
-   Copyright 1995 Free Software Foundation, Inc.
+   Copyright 1995, 1996 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -23,7 +23,34 @@ Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com
 */
 
-
+/* Hey look, some documentation [and in a place you expect to find it]!
+
+   The main reference for the pei format is "Microsoft Portable Executable
+   and Common Object File Format Specification 4.1".  Get it if you need to
+   do some serious hacking on this code.
+
+   Another reference:
+   "Peering Inside the PE: A Tour of the Win32 Portable Executable
+   File Format", MSJ 1994, Volume 9.
+
+   The *sole* difference between the pe format and the pei format is that the
+   latter has an MSDOS 2.0 .exe header on the front that prints the message
+   "This app must be run under Windows." (or some such).
+   (FIXME: Whether that statement is *really* true or not is unknown.
+   Are there more subtle differences between pe and pei formats?
+   For now assume there aren't.  If you find one, then for God sakes
+   document it here!)
+
+   The Microsoft docs use the word "image" instead of "executable" because
+   the former can also refer to a DLL (shared library).  Confusion can arise
+   because the `i' in `pei' also refers to "image".  The `pe' format can
+   also create images (i.e. executables), it's just that to run on a win32
+   system you need to use the pei format.
+
+   FIXME: Please add more docs here so the next poor fool that has to hack
+   on this code has a chance of getting something accomplished without
+   wasting too much time.
+*/
 
 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
 #define coff_mkobject pe_mkobject
@@ -213,7 +240,7 @@ coff_swap_reloc_out (abfd, src, dst)
 #ifdef SWAP_OUT_RELOC_EXTRA
   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
 #endif
-  return sizeof(struct external_reloc);
+  return RELSZ;
 }
 
 
@@ -241,7 +268,6 @@ coff_swap_filehdr_in (abfd, src, dst)
     }
   else 
     {
-      filehdr_dst->f_symptr = 0;
       filehdr_dst->f_nsyms = 0;
       filehdr_dst->f_flags &= ~HAS_SYMS;
     }
@@ -377,7 +403,7 @@ coff_swap_filehdr_out (abfd, in, out)
 
 
 
-  return sizeof(FILHDR);
+  return FILHSZ;
 }
 #else
 
@@ -399,7 +425,7 @@ coff_swap_filehdr_out (abfd, in, out)
   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);
 
-  return sizeof(FILHDR);
+  return FILHSZ;
 }
 
 #endif
@@ -494,7 +520,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
@@ -535,6 +561,12 @@ 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);
+      in->x_scn.x_checksum = bfd_h_get_32 (abfd,
+                                          (bfd_byte *) ext->x_scn.x_checksum);
+      in->x_scn.x_associated =
+       bfd_h_get_16 (abfd, (bfd_byte *) ext->x_scn.x_associated);
+      in->x_scn.x_comdat = bfd_h_get_8 (abfd,
+                                       (bfd_byte *) ext->x_scn.x_comdat);
       return;
     }
     break;
@@ -545,7 +577,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);
@@ -603,7 +635,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);
+    return AUXESZ;
 
 
   case C_STAT:
@@ -615,7 +647,13 @@ 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);
+      bfd_h_put_32 (abfd, in->x_scn.x_checksum,
+                   (bfd_byte *) ext->x_scn.x_checksum);
+      bfd_h_put_16 (abfd, in->x_scn.x_associated,
+                   (bfd_byte *) ext->x_scn.x_associated);
+      bfd_h_put_8 (abfd, in->x_scn.x_comdat,
+                  (bfd_byte *) ext->x_scn.x_comdat);
+      return AUXESZ;
     }
     break;
   }
@@ -625,7 +663,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);
@@ -654,7 +692,7 @@ 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);
+  return AUXESZ;
 }
 
 
@@ -683,7 +721,7 @@ 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;
 }
 
 
@@ -772,7 +810,7 @@ static void add_data_entry (abfd, aout, idx, name, base)
   if (sec != NULL)
     {
       aout->DataDirectory[idx].VirtualAddress = sec->vma - base;
-      aout->DataDirectory[idx].Size = sec->_cooked_size;
+      aout->DataDirectory[idx].Size = pei_section_data (abfd, sec)->virt_size;
       sec->flags |= SEC_DATA;
     }
 }
@@ -849,11 +887,6 @@ coff_swap_aouthdr_out (abfd, in, out)
       {
        int rounded = FA(sec->_raw_size);
 
-       if (strcmp(sec->name,".junk") == 0)
-         {
-           continue;
-         }
-
        if (sec->flags & SEC_DATA) 
          dsize += rounded;
        if (sec->flags & SEC_CODE)
@@ -941,7 +974,7 @@ coff_swap_aouthdr_out (abfd, in, out)
       }
   }
 
-  return sizeof(AOUTHDR);
+  return AOUTSZ;
 }
 
 static void
@@ -990,7 +1023,7 @@ 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;
   bfd_vma ps;
   bfd_vma ss;
 
@@ -1059,7 +1092,6 @@ coff_swap_scnhdr_out (abfd, in, out)
     else if (strcmp (scnhdr_int->s_name, ".rdata") == 0
             || strcmp (scnhdr_int->s_name, ".edata") == 0)
       flags =  IMAGE_SCN_MEM_READ | SEC_DATA;     
-    /* ppc-nt additions */
     else if (strcmp (scnhdr_int->s_name, ".pdata") == 0)
       flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES |
                          IMAGE_SCN_MEM_READ ;
@@ -1071,9 +1103,8 @@ coff_swap_scnhdr_out (abfd, in, out)
     else if (strcmp (scnhdr_int->s_name, ".ydata") == 0)
       flags =  IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES |
               IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ;
-    else if (strcmp (scnhdr_int->s_name, ".drectve") == 0)
+    else if (strncmp (scnhdr_int->s_name, ".drectve", strlen(".drectve")) == 0)
       flags =  IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE ;
-    /* end of ppc-nt additions */
 #ifdef POWERPC_LE_PE
     else if (strncmp (scnhdr_int->s_name, ".stabstr", strlen(".stabstr")) == 0)
       {
@@ -1265,7 +1296,7 @@ pe_print_idata(abfd, vfile)
        }
 
       /* the image base is present in the section->vma */
-      dll = data + dll_name + adj;
+      dll = (char *) data + dll_name + adj;
       fprintf(file, "\n\tDLL Name: %s\n", dll);
       fprintf(file, "\tvma:  Ordinal  Member-Name\n");
 
@@ -1280,7 +1311,7 @@ pe_print_idata(abfd, vfile)
            break;
          ordinal = bfd_get_16(abfd,
                               data + member + adj);
-         member_name = data + member + adj + 2;
+         member_name = (char *) data + member + adj + 2;
          fprintf(file, "\t%04lx\t %4d  %s\n",
                  member, ordinal, member_name);
        }
@@ -1316,7 +1347,7 @@ pe_print_idata(abfd, vfile)
                    {
                      ordinal = bfd_get_16(abfd,
                                           data + iat_member + adj);
-                     member_name = data + iat_member + adj + 2;
+                     member_name = (char *) data + iat_member + adj + 2;
                      fprintf(file, "\t%04lx\t %4d  %s\n",
                              iat_member, ordinal, member_name);
                    }
@@ -1510,7 +1541,7 @@ pe_print_edata(abfd, vfile)
                                    edt.npt_addr
                                    + (i*4) + adj);
       
-      char *name = data + name_ptr + adj;
+      char *name = (char *) data + name_ptr + adj;
 
       bfd_vma ord = bfd_get_16(abfd, 
                                    data + 
@@ -1669,8 +1700,7 @@ pe_print_reloc(abfd, vfile)
     return true;
 
   fprintf(file,
-         "\n\nPE File Base Relocations (interpreted .reloc"
-         " section contents)\n");
+         "\n\nPE File Base Relocations (interpreted .reloc section contents)\n");
 
   data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
   datasize = bfd_section_size (abfd, section);
@@ -1866,3 +1896,45 @@ pe_bfd_copy_private_bfd_data (ibfd, obfd)
 
   return true;
 }
+
+#ifdef COFF_IMAGE_WITH_PE
+
+/* Copy private section data.  */
+
+#define coff_bfd_copy_private_section_data pe_bfd_copy_private_section_data
+
+static boolean pe_bfd_copy_private_section_data
+  PARAMS ((bfd *, asection *, bfd *, asection *));
+
+static boolean
+pe_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
+     bfd *ibfd;
+     asection *isec;
+     bfd *obfd;
+     asection *osec;
+{
+  if (coff_section_data (ibfd, isec) != NULL
+      && pei_section_data (ibfd, isec) != NULL)
+    {
+      if (coff_section_data (obfd, osec) == NULL)
+       {
+         osec->used_by_bfd =
+           (PTR) bfd_zalloc (obfd, sizeof (struct coff_section_tdata));
+         if (osec->used_by_bfd == NULL)
+           return false;
+       }
+      if (pei_section_data (obfd, osec) == NULL)
+       {
+         coff_section_data (obfd, osec)->tdata =
+           (PTR) bfd_zalloc (obfd, sizeof (struct pei_section_tdata));
+         if (coff_section_data (obfd, osec)->tdata == NULL)
+           return false;
+       }
+      pei_section_data (obfd, osec)->virt_size =
+       pei_section_data (ibfd, isec)->virt_size;
+    }
+
+  return true;
+}
+
+#endif
This page took 0.052134 seconds and 4 git commands to generate.