Tue Jun 16 13:06:21 1998 Alan Modra <alan@spri.levels.unisa.edu.au>
[binutils-gdb.git] / bfd / peicode.h
index 5b52a92d5f71588ed67acdce16a319826502840c..0183f98ca5c40e1d0188f8a708dab01bf843b90c 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for the generic parts of most COFF variants, for BFD.
 /* Support for the generic parts of most COFF variants, for BFD.
-   Copyright 1995 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -23,19 +23,58 @@ Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com
 */
 
                        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.
+*/
 
 
-
+#ifdef coff_bfd_print_private_bfd_data
+static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
+     PARAMS ((bfd *, PTR))
+     = coff_bfd_print_private_bfd_data;
+#undef coff_bfd_print_private_bfd_data
+#else
+static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
+     PARAMS ((bfd *, PTR))
+     = NULL;
+#endif
 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
-#define coff_mkobject pe_mkobject
-#define coff_mkobject_hook pe_mkobject_hook
 
 
+#define coff_mkobject      pe_mkobject
+#define coff_mkobject_hook pe_mkobject_hook
 
 #ifndef GET_FCN_LNNOPTR
 
 #ifndef GET_FCN_LNNOPTR
-#define GET_FCN_LNNOPTR(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
+#define GET_FCN_LNNOPTR(abfd, ext) \
+     bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
 #endif
 
 #ifndef GET_FCN_ENDNDX
 #endif
 
 #ifndef GET_FCN_ENDNDX
-#define GET_FCN_ENDNDX(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
+#define GET_FCN_ENDNDX(abfd, ext)  \
+       bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
 #endif
 
 #ifndef PUT_FCN_LNNOPTR
 #endif
 
 #ifndef PUT_FCN_LNNOPTR
@@ -165,7 +204,31 @@ Most of this hacked by  Steve Chamberlain,
 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
 #endif
 
 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
 #endif
 
-
+static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_reloc_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));
+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));
+static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
+static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
+static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR));
+static void add_data_entry
+  PARAMS ((bfd *, struct internal_extra_pe_aouthdr *, int, char *, bfd_vma));
+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 boolean pe_print_idata PARAMS ((bfd *, PTR));
+static boolean pe_print_edata PARAMS ((bfd *, PTR));
+static boolean pe_print_pdata PARAMS ((bfd *, PTR));
+static boolean pe_print_reloc PARAMS ((bfd *, PTR));
+static boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
+static boolean pe_mkobject PARAMS ((bfd *));
+static PTR pe_mkobject_hook PARAMS ((bfd *, PTR, PTR));
+static boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
 
 /**********************************************************************/
 
 
 /**********************************************************************/
 
@@ -187,7 +250,6 @@ coff_swap_reloc_in (abfd, src, dst)
   reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
                                             (bfd_byte *) reloc_src->r_offset);
 #endif
   reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
                                             (bfd_byte *) reloc_src->r_offset);
 #endif
-
 }
 
 
 }
 
 
@@ -213,7 +275,7 @@ coff_swap_reloc_out (abfd, src, dst)
 #ifdef SWAP_OUT_RELOC_EXTRA
   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
 #endif
 #ifdef SWAP_OUT_RELOC_EXTRA
   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
 #endif
-  return sizeof(struct external_reloc);
+  return RELSZ;
 }
 
 
 }
 
 
@@ -228,13 +290,25 @@ coff_swap_filehdr_in (abfd, src, dst)
   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);
   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);
-  filehdr_dst->f_symptr =
-    bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr);
+
   filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
   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);
   filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
+  filehdr_dst->f_symptr = bfd_h_get_32 (abfd, (bfd_byte *) filehdr_src->f_symptr);
+
+  /* Other people's tools sometimes generate headers with an nsyms but
+     a zero symptr.  */
+  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
+    {
+      filehdr_dst->f_nsyms = 0;
+      filehdr_dst->f_flags |= F_LSYMS;
+    }
+
+  filehdr_dst->f_opthdr = bfd_h_get_16(abfd, 
+                                      (bfd_byte *)filehdr_src-> f_opthdr);
 }
 
 }
 
+#ifdef COFF_IMAGE_WITH_PE
+
 static  unsigned int
 coff_swap_filehdr_out (abfd, in, out)
      bfd       *abfd;
 static  unsigned int
 coff_swap_filehdr_out (abfd, in, out)
      bfd       *abfd;
@@ -309,7 +383,6 @@ 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);
 
   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);
 
-
   /* put in extra dos header stuff.  This data remains essentially
      constant, it just has to be tacked on to the beginning of all exes 
      for NT */
   /* put in extra dos header stuff.  This data remains essentially
      constant, it just has to be tacked on to the beginning of all exes 
      for NT */
@@ -361,9 +434,32 @@ coff_swap_filehdr_out (abfd, in, out)
 
 
 
 
 
 
-  return sizeof(FILHDR);
+  return FILHSZ;
+}
+#else
+
+static  unsigned int
+coff_swap_filehdr_out (abfd, in, out)
+     bfd       *abfd;
+     PTR       in;
+     PTR       out;
+{
+  struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
+  FILHDR *filehdr_out = (FILHDR *)out;
+
+  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);
+  PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
+                     (bfd_byte *) filehdr_out->f_symptr);
+  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);
+
+  return FILHSZ;
 }
 
 }
 
+#endif
 
 
 static void
 
 
 static void
@@ -386,6 +482,7 @@ coff_swap_sym_in (abfd, ext1, in1)
     memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
 #endif
   }
     memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
 #endif
   }
+
   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value); 
   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
   if (sizeof(ext->e_type) == 2){
   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value); 
   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
   if (sizeof(ext->e_type) == 2){
@@ -415,6 +512,10 @@ coff_swap_sym_in (abfd, ext1, in1)
     /*    else */
     /*      in->n_scnum = 2; */
   }
     /*    else */
     /*      in->n_scnum = 2; */
   }
+
+#ifdef coff_swap_sym_in_hook
+  coff_swap_sym_in_hook(abfd, ext1, in1);
+#endif
 }
 
 static unsigned int
 }
 
 static unsigned int
@@ -436,6 +537,7 @@ coff_swap_sym_out (abfd, inp, extp)
     memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
 #endif
   }
     memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
 #endif
   }
+
   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
   if (sizeof(ext->e_type) == 2)
   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
   if (sizeof(ext->e_type) == 2)
@@ -448,7 +550,8 @@ 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);
     }
   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
 }
 
 static void
@@ -489,6 +592,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_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;
       return;
     }
     break;
@@ -499,7 +608,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
 
   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);
     {
       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);
@@ -557,7 +666,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
     }
       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
 #endif
     }
-    return sizeof (AUXENT);
+    return AUXESZ;
 
 
   case C_STAT:
 
 
   case C_STAT:
@@ -569,7 +678,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);
       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;
   }
     }
     break;
   }
@@ -579,7 +694,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
 
   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);
     {
       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);
@@ -608,7 +723,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);
     }
 
       PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
     }
 
-  return sizeof(AUXENT);
+  return AUXESZ;
 }
 
 
 }
 
 
@@ -637,7 +752,7 @@ coff_swap_lineno_out (abfd, inp, outp)
          ext->l_addr.l_symndx);
 
   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
          ext->l_addr.l_symndx);
 
   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
-  return sizeof(struct external_lineno);
+  return LINESZ;
 }
 
 
 }
 
 
@@ -669,47 +784,66 @@ coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
     GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
 
   a = &aouthdr_int->pe;
     GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
 
   a = &aouthdr_int->pe;
-  a->ImageBase = bfd_h_get_32 (abfd, src->ImageBase);
-  a->SectionAlignment = bfd_h_get_32 (abfd, src->SectionAlignment);
-  a->FileAlignment = bfd_h_get_32 (abfd, src->FileAlignment);
+  a->ImageBase = bfd_h_get_32 (abfd, (bfd_byte *) src->ImageBase);
+  a->SectionAlignment = bfd_h_get_32 (abfd, (bfd_byte *) src->SectionAlignment);
+  a->FileAlignment = bfd_h_get_32 (abfd, (bfd_byte *) src->FileAlignment);
   a->MajorOperatingSystemVersion = 
   a->MajorOperatingSystemVersion = 
-    bfd_h_get_16 (abfd, src->MajorOperatingSystemVersion);
+    bfd_h_get_16 (abfd, (bfd_byte *) src->MajorOperatingSystemVersion);
   a->MinorOperatingSystemVersion = 
   a->MinorOperatingSystemVersion = 
-    bfd_h_get_16 (abfd, src->MinorOperatingSystemVersion);
-  a->MajorImageVersion = bfd_h_get_16 (abfd, src->MajorImageVersion);
-  a->MinorImageVersion = bfd_h_get_16 (abfd, src->MinorImageVersion);
-  a->MajorSubsystemVersion = bfd_h_get_16 (abfd, src->MajorSubsystemVersion);
-  a->MinorSubsystemVersion = bfd_h_get_16 (abfd, src->MinorSubsystemVersion);
-  a->Reserved1 = bfd_h_get_32 (abfd, src->Reserved1);
-  a->SizeOfImage = bfd_h_get_32 (abfd, src->SizeOfImage);
-  a->SizeOfHeaders = bfd_h_get_32 (abfd, src->SizeOfHeaders);
-  a->CheckSum = bfd_h_get_32 (abfd, src->CheckSum);
-  a->Subsystem = bfd_h_get_16 (abfd, src->Subsystem);
-  a->DllCharacteristics = bfd_h_get_16 (abfd, src->DllCharacteristics);
-  a->SizeOfStackReserve = bfd_h_get_32 (abfd, src->SizeOfStackReserve);
-  a->SizeOfStackCommit = bfd_h_get_32 (abfd, src->SizeOfStackCommit);
-  a->SizeOfHeapReserve = bfd_h_get_32 (abfd, src->SizeOfHeapReserve);
-  a->SizeOfHeapCommit = bfd_h_get_32 (abfd, src->SizeOfHeapCommit);
-  a->LoaderFlags = bfd_h_get_32 (abfd, src->LoaderFlags);
-  a->NumberOfRvaAndSizes = bfd_h_get_32 (abfd, src->NumberOfRvaAndSizes);
+    bfd_h_get_16 (abfd, (bfd_byte *) src->MinorOperatingSystemVersion);
+  a->MajorImageVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MajorImageVersion);
+  a->MinorImageVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MinorImageVersion);
+  a->MajorSubsystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MajorSubsystemVersion);
+  a->MinorSubsystemVersion = bfd_h_get_16 (abfd, (bfd_byte *) src->MinorSubsystemVersion);
+  a->Reserved1 = bfd_h_get_32 (abfd, (bfd_byte *) src->Reserved1);
+  a->SizeOfImage = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfImage);
+  a->SizeOfHeaders = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfHeaders);
+  a->CheckSum = bfd_h_get_32 (abfd, (bfd_byte *) src->CheckSum);
+  a->Subsystem = bfd_h_get_16 (abfd, (bfd_byte *) src->Subsystem);
+  a->DllCharacteristics = bfd_h_get_16 (abfd, (bfd_byte *) src->DllCharacteristics);
+  a->SizeOfStackReserve = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfStackReserve);
+  a->SizeOfStackCommit = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfStackCommit);
+  a->SizeOfHeapReserve = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfHeapReserve);
+  a->SizeOfHeapCommit = bfd_h_get_32 (abfd, (bfd_byte *) src->SizeOfHeapCommit);
+  a->LoaderFlags = bfd_h_get_32 (abfd, (bfd_byte *) src->LoaderFlags);
+  a->NumberOfRvaAndSizes = bfd_h_get_32 (abfd, (bfd_byte *) src->NumberOfRvaAndSizes);
 
   {
     int idx;
     for (idx=0; idx < 16; idx++)
       {
        a->DataDirectory[idx].VirtualAddress =
 
   {
     int idx;
     for (idx=0; idx < 16; idx++)
       {
        a->DataDirectory[idx].VirtualAddress =
-         bfd_h_get_32 (abfd, src->DataDirectory[idx][0]);
+         bfd_h_get_32 (abfd, (bfd_byte *) src->DataDirectory[idx][0]);
        a->DataDirectory[idx].Size =
        a->DataDirectory[idx].Size =
-         bfd_h_get_32 (abfd, src->DataDirectory[idx][1]);
+         bfd_h_get_32 (abfd, (bfd_byte *) src->DataDirectory[idx][1]);
       }
   }
 
   if (aouthdr_int->entry)
       }
   }
 
   if (aouthdr_int->entry)
-    aouthdr_int->entry += a->ImageBase;
+    {
+      aouthdr_int->entry += a->ImageBase;
+      aouthdr_int->entry &= 0xffffffff;
+    }
   if (aouthdr_int->tsize) 
   if (aouthdr_int->tsize) 
-    aouthdr_int->text_start += a->ImageBase;
+    {
+      aouthdr_int->text_start += a->ImageBase;
+      aouthdr_int->text_start &= 0xffffffff;
+    }
   if (aouthdr_int->dsize) 
   if (aouthdr_int->dsize) 
-    aouthdr_int->data_start += a->ImageBase;
+    {
+      aouthdr_int->data_start += a->ImageBase;
+      aouthdr_int->data_start &= 0xffffffff;
+    }
+
+#ifdef POWERPC_LE_PE
+  /* These three fields are normally set up by ppc_relocate_section.
+     In the case of reading a file in, we can pick them up from
+     the DataDirectory.
+  */
+  first_thunk_address = a->DataDirectory[12].VirtualAddress ;
+  thunk_size = a->DataDirectory[12].Size;
+  import_table_size = a->DataDirectory[1].Size;
+#endif
 }
 
 
 }
 
 
@@ -723,15 +857,16 @@ static void add_data_entry (abfd, aout, idx, name, base)
   asection *sec = bfd_get_section_by_name (abfd, name);
 
   /* add import directory information if it exists */
   asection *sec = bfd_get_section_by_name (abfd, name);
 
   /* add import directory information if it exists */
-  if (sec != NULL)
+  if (sec != NULL
+      && coff_section_data (abfd, sec) != NULL
+      && pei_section_data (abfd, sec) != NULL)
     {
     {
-      aout->DataDirectory[idx].VirtualAddress = sec->lma - base;
-      aout->DataDirectory[idx].Size = sec->_raw_size;
+      aout->DataDirectory[idx].VirtualAddress = (sec->vma - base) & 0xffffffff;
+      aout->DataDirectory[idx].Size = pei_section_data (abfd, sec)->virt_size;
       sec->flags |= SEC_DATA;
     }
 }
 
       sec->flags |= SEC_DATA;
     }
 }
 
-
 static unsigned int
 coff_swap_aouthdr_out (abfd, in, out)
      bfd       *abfd;
 static unsigned int
 coff_swap_aouthdr_out (abfd, in, out)
      bfd       *abfd;
@@ -747,11 +882,20 @@ coff_swap_aouthdr_out (abfd, in, out)
   bfd_vma ib = extra->ImageBase ;
 
   if (aouthdr_in->tsize) 
   bfd_vma ib = extra->ImageBase ;
 
   if (aouthdr_in->tsize) 
-    aouthdr_in->text_start -= ib;
+    {
+      aouthdr_in->text_start -= ib;
+      aouthdr_in->text_start &= 0xffffffff;
+    }
   if (aouthdr_in->dsize) 
   if (aouthdr_in->dsize) 
-    aouthdr_in->data_start -= ib;
+    {
+      aouthdr_in->data_start -= ib;
+      aouthdr_in->data_start &= 0xffffffff;
+    }
   if (aouthdr_in->entry) 
   if (aouthdr_in->entry) 
-    aouthdr_in->entry -= ib;
+    {
+      aouthdr_in->entry -= ib;
+      aouthdr_in->entry &= 0xffffffff;
+    }
 
 #define FA(x)  (((x) + fa -1 ) & (- fa))
 #define SA(x)  (((x) + sa -1 ) & (- sa))
 
 #define FA(x)  (((x) + fa -1 ) & (- fa))
 #define SA(x)  (((x) + sa -1 ) & (- sa))
@@ -769,15 +913,41 @@ coff_swap_aouthdr_out (abfd, in, out)
   add_data_entry (abfd, extra, 0, ".edata", ib);
   add_data_entry (abfd, extra, 1, ".idata", ib);
   add_data_entry (abfd, extra, 2, ".rsrc" ,ib);
   add_data_entry (abfd, extra, 0, ".edata", ib);
   add_data_entry (abfd, extra, 1, ".idata", ib);
   add_data_entry (abfd, extra, 2, ".rsrc" ,ib);
+
+#ifdef POWERPC_LE_PE
+  /* FIXME: do other PE platforms use this? */
+  add_data_entry (abfd, extra, 3, ".pdata" ,ib);
+#endif
+
   add_data_entry (abfd, extra, 5, ".reloc", ib);
   add_data_entry (abfd, extra, 5, ".reloc", ib);
+
+#ifdef POWERPC_LE_PE
+  /* On the PPC NT system, this field is set up as follows. It is
+     not an "officially" reserved field, so it currently has no title.
+     first_thunk_address is idata$5, and the thunk_size is the size
+     of the idata$5 chunk of the idata section.
+  */
+  extra->DataDirectory[12].VirtualAddress = first_thunk_address;
+  extra->DataDirectory[12].Size = thunk_size;
+
+  /* On the PPC NT system, the size of the directory entry is not the
+     size of the entire section. It's actually offset to the end of 
+     the idata$3 component of the idata section. This is the size of
+     the entire import table. (also known as the start of idata$4)
+  */
+  extra->DataDirectory[1].Size = import_table_size;
+#endif
+
   {
     asection *sec;
     bfd_vma dsize= 0;
     bfd_vma isize = SA(abfd->sections->filepos);
     bfd_vma tsize= 0;
   {
     asection *sec;
     bfd_vma dsize= 0;
     bfd_vma isize = SA(abfd->sections->filepos);
     bfd_vma tsize= 0;
+
     for (sec = abfd->sections; sec; sec = sec->next)
       {
        int rounded = FA(sec->_raw_size);
     for (sec = abfd->sections; sec; sec = sec->next)
       {
        int rounded = FA(sec->_raw_size);
+
        if (sec->flags & SEC_DATA) 
          dsize += rounded;
        if (sec->flags & SEC_CODE)
        if (sec->flags & SEC_DATA) 
          dsize += rounded;
        if (sec->flags & SEC_CODE)
@@ -792,13 +962,22 @@ coff_swap_aouthdr_out (abfd, in, out)
 
   extra->SizeOfHeaders = abfd->sections->filepos;
   bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->standard.magic);
 
   extra->SizeOfHeaders = abfd->sections->filepos;
   bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->standard.magic);
-  bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->standard.vstamp);
+
+#ifdef POWERPC_LE_PE
+  /* this little piece of magic sets the "linker version" field to 2.60 */
+  bfd_h_put_16(abfd, 2  + 60 * 256, (bfd_byte *) aouthdr_out->standard.vstamp);
+#else
+  /* this little piece of magic sets the "linker version" field to 2.55 */
+  bfd_h_put_16(abfd, 2  + 55 * 256, (bfd_byte *) aouthdr_out->standard.vstamp);
+#endif
+
   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->standard.tsize);
   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->standard.dsize);
   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->standard.bsize);
   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->standard.entry);
   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
                          (bfd_byte *) aouthdr_out->standard.text_start);
   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->standard.tsize);
   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->standard.dsize);
   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->standard.bsize);
   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->standard.entry);
   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
                          (bfd_byte *) aouthdr_out->standard.text_start);
+
   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
                          (bfd_byte *) aouthdr_out->standard.data_start);
 
   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
                          (bfd_byte *) aouthdr_out->standard.data_start);
 
@@ -856,8 +1035,7 @@ coff_swap_aouthdr_out (abfd, in, out)
       }
   }
 
       }
   }
 
-
-  return sizeof(AOUTHDR);
+  return AOUTSZ;
 }
 
 static void
 }
 
 static void
@@ -890,43 +1068,55 @@ static void
   if (scnhdr_int->s_vaddr != 0) 
     {
       scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
   if (scnhdr_int->s_vaddr != 0) 
     {
       scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
+      scnhdr_int->s_vaddr &= 0xffffffff;
+    }
+  if (strcmp (scnhdr_int->s_name, _BSS) == 0) 
+    {
+      scnhdr_int->s_size = scnhdr_int->s_paddr;
+      scnhdr_int->s_paddr = 0;
     }
 }
 
 static unsigned int
     }
 }
 
 static unsigned int
- coff_swap_scnhdr_out (abfd, in, out)
-bfd       *abfd;
-PTR    in;
-PTR    out;
+coff_swap_scnhdr_out (abfd, in, out)
+     bfd       *abfd;
+     PTR       in;
+     PTR       out;
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
   SCNHDR *scnhdr_ext = (SCNHDR *)out;
 {
   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
   SCNHDR *scnhdr_ext = (SCNHDR *)out;
-  unsigned int ret = sizeof (SCNHDR);
-  bfd_vma s;
+  unsigned int ret = SCNHSZ;
+  bfd_vma ps;
+  bfd_vma ss;
 
   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
 
 
   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
 
-
   PUT_SCNHDR_VADDR (abfd, 
   PUT_SCNHDR_VADDR (abfd, 
-                   (scnhdr_int->s_vaddr 
-                    - pe_data(abfd)->pe_opthdr.ImageBase),
+                   ((scnhdr_int->s_vaddr 
+                     - pe_data(abfd)->pe_opthdr.ImageBase)
+                    & 0xffffffff),
                    (bfd_byte *) scnhdr_ext->s_vaddr);
 
                    (bfd_byte *) scnhdr_ext->s_vaddr);
 
-  /* Note that we're really stuffing in the raw size into here. */
-
-
-  PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
-                   (bfd_byte *) scnhdr_ext->s_size);
-
   /* NT wants the size data to be rounded up to the next NT_FILE_ALIGNMENT
      value except for the BSS section, its s_size should be 0 */
 
   /* NT wants the size data to be rounded up to the next NT_FILE_ALIGNMENT
      value except for the BSS section, its s_size should be 0 */
 
+
   if (strcmp (scnhdr_int->s_name, _BSS) == 0) 
   if (strcmp (scnhdr_int->s_name, _BSS) == 0) 
-    s = 0;
+    {
+      ps = scnhdr_int->s_size;
+      ss = 0;
+    }
   else
   else
-    s = scnhdr_int->s_paddr;
+    {
+      ps = scnhdr_int->s_paddr;
+      ss = scnhdr_int->s_size;
+    }
+
+  PUT_SCNHDR_SIZE (abfd, ss,
+                  (bfd_byte *) scnhdr_ext->s_size);
+
 
 
-  PUT_SCNHDR_PADDR (abfd, s, (bfd_byte *) scnhdr_ext->s_paddr);
+  PUT_SCNHDR_PADDR (abfd, ps, (bfd_byte *) scnhdr_ext->s_paddr);
 
   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
                     (bfd_byte *) scnhdr_ext->s_scnptr);
 
   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
                     (bfd_byte *) scnhdr_ext->s_scnptr);
@@ -944,22 +1134,50 @@ PTR      out;
      section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
      (0x02000000).  Also, the resource data should also be read and
      writable.  */
      section data is ever generated, we must add IMAGE_SCN_MEM_DISCARDABLE
      (0x02000000).  Also, the resource data should also be read and
      writable.  */
+
+  /* FIXME: alignment is also encoded in this field, at least on ppc (krk) */
+  /* FIXME: even worse, I don't see how to get the original alignment field*/
+  /*        back...                                                        */
+
+  /* FIXME: Basing this on section names is bogus.  Also, this should
+     be in sec_to_styp_flags.  */
+
   {
     int flags = scnhdr_int->s_flags;
     if (strcmp (scnhdr_int->s_name, ".data")  == 0 ||
        strcmp (scnhdr_int->s_name, ".CRT")   == 0 ||
   {
     int flags = scnhdr_int->s_flags;
     if (strcmp (scnhdr_int->s_name, ".data")  == 0 ||
        strcmp (scnhdr_int->s_name, ".CRT")   == 0 ||
-       strcmp (scnhdr_int->s_name, ".rsrc")  == 0 ||
        strcmp (scnhdr_int->s_name, ".bss")   == 0)
       flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
     else if (strcmp (scnhdr_int->s_name, ".text") == 0)
       flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
     else if (strcmp (scnhdr_int->s_name, ".reloc") == 0)
        strcmp (scnhdr_int->s_name, ".bss")   == 0)
       flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
     else if (strcmp (scnhdr_int->s_name, ".text") == 0)
       flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
     else if (strcmp (scnhdr_int->s_name, ".reloc") == 0)
-      flags = SEC_DATA| IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE;
+      flags = (SEC_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
+              | IMAGE_SCN_MEM_SHARED);
     else if (strcmp (scnhdr_int->s_name, ".idata") == 0)
       flags = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | SEC_DATA;     
     else if (strcmp (scnhdr_int->s_name, ".rdata") == 0
             || strcmp (scnhdr_int->s_name, ".edata") == 0)
       flags =  IMAGE_SCN_MEM_READ | SEC_DATA;     
     else if (strcmp (scnhdr_int->s_name, ".idata") == 0)
       flags = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | SEC_DATA;     
     else if (strcmp (scnhdr_int->s_name, ".rdata") == 0
             || strcmp (scnhdr_int->s_name, ".edata") == 0)
       flags =  IMAGE_SCN_MEM_READ | SEC_DATA;     
+    else if (strcmp (scnhdr_int->s_name, ".pdata") == 0)
+      flags = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES |
+                         IMAGE_SCN_MEM_READ ;
+    /* Remember this field is a max of 8 chars, so the null is _not_ there
+       for an 8 character name like ".reldata". (yep. Stupid bug) */
+    else if (strncmp (scnhdr_int->s_name, ".reldata", 8) == 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, ".ydata") == 0)
+      flags =  IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_8BYTES |
+              IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE ;
+    else if (strncmp (scnhdr_int->s_name, ".drectve", 8) == 0)
+      flags =  IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE ;
+    else if (strncmp (scnhdr_int->s_name, ".stab", 5) == 0)
+      flags |= (IMAGE_SCN_LNK_INFO | IMAGE_SCN_MEM_DISCARDABLE
+               | IMAGE_SCN_MEM_SHARED | IMAGE_SCN_MEM_READ);
+    else if (strcmp (scnhdr_int->s_name, ".rsrc")  == 0)
+      flags |= IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_SHARED;
+    else
+      flags |= IMAGE_SCN_MEM_READ;
 
     bfd_h_put_32(abfd, flags, (bfd_byte *) scnhdr_ext->s_flags);
   }
 
     bfd_h_put_32(abfd, flags, (bfd_byte *) scnhdr_ext->s_flags);
   }
@@ -968,7 +1186,7 @@ PTR        out;
     bfd_h_put_16(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
   else
     {
     bfd_h_put_16(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
   else
     {
-      (*_bfd_error_handler) ("%s: line number overflow: 0x%lx > 0xffff",
+      (*_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);
                             bfd_get_filename (abfd),
                             scnhdr_int->s_nlnno);
       bfd_set_error (bfd_error_file_truncated);
@@ -979,7 +1197,7 @@ PTR        out;
     bfd_h_put_16(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
   else
     {
     bfd_h_put_16(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
   else
     {
-      (*_bfd_error_handler) ("%s: reloc overflow: 0x%lx > 0xffff",
+      (*_bfd_error_handler) (_("%s: reloc overflow: 0x%lx > 0xffff"),
                             bfd_get_filename (abfd),
                             scnhdr_int->s_nreloc);
       bfd_set_error (bfd_error_file_truncated);
                             bfd_get_filename (abfd),
                             scnhdr_int->s_nreloc);
       bfd_set_error (bfd_error_file_truncated);
@@ -988,23 +1206,743 @@ PTR     out;
     }
   return ret;
 }
     }
   return ret;
 }
+
+static char * dir_names[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] = 
+{
+  N_ ("Export Directory [.edata (or where ever we found it)]"),
+  N_ ("Import Directory [parts of .idata]"),
+  N_ ("Resource Directory [.rsrc]"),
+  N_ ("Exception Directory [.pdata]"),
+  N_ ("Security Directory"),
+  N_ ("Base Relocation Directory [.reloc]"),
+  N_ ("Debug Directory"),
+  N_ ("Description Directory"),
+  N_ ("Special Directory"),
+  N_ ("Thread Storage Directory [.tls]"),
+  N_ ("Load Configuration Directory"),
+  N_ ("Bound Import Directory"),
+  N_ ("Import Address Table Directory"),
+  N_ ("Reserved"),
+  N_ ("Reserved"),
+  N_ ("Reserved")
+};
+
 /**********************************************************************/
 /**********************************************************************/
+static boolean
+pe_print_idata(abfd, vfile)
+     bfd *abfd;
+     PTR vfile;
+{
+  FILE *file = (FILE *) vfile;
+  bfd_byte *data = 0;
+  asection *section = bfd_get_section_by_name (abfd, ".idata");
+  unsigned long adj;
+
+#ifdef POWERPC_LE_PE
+  asection *rel_section = bfd_get_section_by_name (abfd, ".reldata");
+#endif
+
+  bfd_size_type datasize;
+  bfd_size_type dataoff;
+  bfd_size_type secsize;
+  bfd_size_type i;
+  bfd_size_type start, stop;
+  int onaline = 20;
+
+  pe_data_type *pe = pe_data (abfd);
+  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
+
+  if (section != NULL)
+    {
+      datasize = bfd_section_size (abfd, section);
+      dataoff = 0;
+
+      if (datasize == 0)
+       return true;
+    }
+  else
+    {
+      bfd_vma addr, size;
+
+      addr = extra->DataDirectory[1].VirtualAddress;
+      size = extra->DataDirectory[1].Size;
+
+      if (addr == 0 || size == 0)
+       return true;
+
+      for (section = abfd->sections; section != NULL; section = section->next)
+       {
+         if (section->vma - extra->ImageBase <= addr
+             && ((section->vma - extra->ImageBase
+                  + bfd_section_size (abfd, section))
+                 >= addr + size))
+           break;
+       }
+      if (section == NULL)
+       return true;
+
+      /* For some reason the import table size is not reliable.  The
+         import data will extend past the indicated size, and before
+         the indicated address.  */
+      dataoff = addr - (section->vma - extra->ImageBase);
+      datasize = size;
+    }
+
+#ifdef POWERPC_LE_PE
+  if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0)
+    {
+      /* The toc address can be found by taking the starting address,
+        which on the PPC locates a function descriptor. The descriptor
+        consists of the function code starting address followed by the
+        address of the toc. The starting address we get from the bfd,
+        and the descriptor is supposed to be in the .reldata section. 
+      */
+
+      bfd_vma loadable_toc_address;
+      bfd_vma toc_address;
+      bfd_vma start_address;
+      bfd_byte *data = 0;
+      int offset;
+      data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, 
+                                                                rel_section));
+      if (data == NULL && bfd_section_size (abfd, rel_section) != 0)
+       return false;
+
+      datasize = bfd_section_size (abfd, rel_section);
+  
+      bfd_get_section_contents (abfd, 
+                               rel_section, 
+                               (PTR) data, 0, 
+                               bfd_section_size (abfd, rel_section));
+
+      offset = abfd->start_address - rel_section->vma;
+
+      start_address = bfd_get_32(abfd, data+offset);
+      loadable_toc_address = bfd_get_32(abfd, data+offset+4);
+      toc_address = loadable_toc_address - 32768;
+
+      fprintf(file,
+             _("\nFunction descriptor located at the start address: %04lx\n"),
+             (unsigned long int) (abfd->start_address));
+      fprintf (file,
+              _("\tcode-base %08lx toc (loadable/actual) %08lx/%08lx\n"), 
+              start_address, loadable_toc_address, toc_address);
+    }
+  else 
+    {
+      fprintf(file,
+             _("\nNo reldata section! Function descriptor not decoded.\n"));
+    }
+#endif
+
+  fprintf(file,
+         _("\nThe Import Tables (interpreted .idata section contents)\n"));
+  fprintf(file,
+         _(" vma:            Hint    Time      Forward  DLL       First\n"));
+  fprintf(file,
+         _("                 Table   Stamp     Chain    Name      Thunk\n"));
+
+  secsize = bfd_section_size (abfd, section);
+  data = (bfd_byte *) bfd_malloc (secsize);
+  if (data == NULL && secsize != 0)
+    return false;
+
+  if (! bfd_get_section_contents (abfd, section, (PTR) data, 0, secsize))
+    return false;
+
+  adj = (extra->ImageBase - section->vma) & 0xffffffff;
+
+  start = dataoff;
+  stop = dataoff + datasize;
+  for (i = start; i < stop; i += onaline)
+    {
+      bfd_vma hint_addr;
+      bfd_vma time_stamp;
+      bfd_vma forward_chain;
+      bfd_vma dll_name;
+      bfd_vma first_thunk;
+      int idx = 0;
+      bfd_size_type j;
+      char *dll;
+
+      fprintf (file,
+              " %08lx\t", 
+              (unsigned long int) (i + section->vma + dataoff));
+      
+      if (i+20 > stop)
+       {
+         /* check stuff */
+         ;
+       }
+      
+      hint_addr = bfd_get_32(abfd, data+i);
+      time_stamp = bfd_get_32(abfd, data+i+4);
+      forward_chain = bfd_get_32(abfd, data+i+8);
+      dll_name = bfd_get_32(abfd, data+i+12);
+      first_thunk = bfd_get_32(abfd, data+i+16);
+      
+      fprintf(file, "%08lx %08lx %08lx %08lx %08lx\n",
+             hint_addr,
+             time_stamp,
+             forward_chain,
+             dll_name,
+             first_thunk);
+
+      if (hint_addr == 0 && first_thunk == 0)
+       break;
+
+      /* the image base is present in the section->vma */
+      dll = (char *) data + dll_name + adj;
+      fprintf(file, _("\n\tDLL Name: %s\n"), dll);
+
+      if (hint_addr != 0)
+       {
+         fprintf (file, _("\tvma:  Hint/Ord Member-Name\n"));
+
+         idx = hint_addr + adj;
+
+         for (j = 0; j < stop; j += 4)
+           {
+             unsigned long member = bfd_get_32 (abfd, data + idx + j);
+
+             if (member == 0)
+               break;
+             if (member & 0x80000000)
+               fprintf (file, "\t%04lx\t %4lu", member,
+                        member & 0x7fffffff);
+             else
+               {
+                 int ordinal;
+                 char *member_name;
+
+                 ordinal = bfd_get_16 (abfd, data + member + adj);
+                 member_name = (char *) data + member + adj + 2;
+                 fprintf (file, "\t%04lx\t %4d  %s",
+                          member, ordinal, member_name);
+               }
+
+             /* If the time stamp is not zero, the import address
+                 table holds actual addresses.  */
+             if (time_stamp != 0
+                 && first_thunk != 0
+                 && first_thunk != hint_addr)
+               fprintf (file, "\t%04lx",
+                        bfd_get_32 (abfd, data + first_thunk + adj + j));
+
+             fprintf (file, "\n");
+           }
+       }
+
+      if (hint_addr != first_thunk && time_stamp == 0)
+       {
+         int differ = 0;
+         int idx2;
+
+         idx2 = first_thunk + adj;
+
+         for (j=0;j<stop;j+=4)
+           {
+             int ordinal;
+             char *member_name;
+             bfd_vma hint_member = 0;
+             bfd_vma iat_member;
+
+             if (hint_addr != 0)
+               hint_member = bfd_get_32 (abfd, data + idx + j);
+             iat_member = bfd_get_32 (abfd, data + idx2 + j);
+
+             if (hint_addr == 0 && iat_member == 0)
+               break;
+
+             if (hint_addr == 0 || hint_member != iat_member)
+               {
+                 if (differ == 0)
+                   {
+                     fprintf (file, 
+                              _("\tThe Import Address Table (difference found)\n"));
+                     fprintf(file, _("\tvma:  Hint/Ord Member-Name\n"));
+                     differ = 1;
+                   }
+                 if (iat_member == 0)
+                   {
+                     fprintf(file,
+                             _("\t>>> Ran out of IAT members!\n"));
+                   }
+                 else 
+                   {
+                     ordinal = bfd_get_16(abfd,
+                                          data + iat_member + adj);
+                     member_name = (char *) data + iat_member + adj + 2;
+                     fprintf(file, "\t%04lx\t %4d  %s\n",
+                             iat_member, ordinal, member_name);
+                   }
+               }
+
+             if (hint_addr != 0 && hint_member == 0)
+               break;
+           }
+         if (differ == 0)
+           {
+             fprintf(file,
+                     _("\tThe Import Address Table is identical\n"));
+           }
+       }
+
+      fprintf(file, "\n");
+
+    }
+
+  free (data);
+
+  return true;
+}
+
+static boolean
+pe_print_edata (abfd, vfile)
+     bfd *abfd;
+     PTR vfile;
+{
+  FILE *file = (FILE *) vfile;
+  bfd_byte *data = 0;
+  asection *section = bfd_get_section_by_name (abfd, ".edata");
+
+  bfd_size_type datasize;
+  bfd_size_type dataoff;
+  bfd_size_type i;
+
+  int adj;
+  struct EDT_type 
+    {
+      long export_flags;             /* reserved - should be zero */
+      long time_stamp;
+      short major_ver;
+      short minor_ver;
+      bfd_vma name;                  /* rva - relative to image base */
+      long base;                     /* ordinal base */
+      unsigned long num_functions;   /* Number in the export address table */
+      unsigned long num_names;       /* Number in the name pointer table */
+      bfd_vma eat_addr;    /* rva to the export address table */
+      bfd_vma npt_addr;        /* rva to the Export Name Pointer Table */
+      bfd_vma ot_addr; /* rva to the Ordinal Table */
+    } edt;
+
+  pe_data_type *pe = pe_data (abfd);
+  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
+
+  if (section != NULL)
+    {
+      datasize = bfd_section_size (abfd, section);
+      dataoff = 0;
+    }
+  else
+    {
+      bfd_vma addr, size;
+
+      addr = extra->DataDirectory[0].VirtualAddress;
+      size = extra->DataDirectory[0].Size;
+
+      if (addr == 0 || size == 0)
+       return true;
+
+      for (section = abfd->sections; section != NULL; section = section->next)
+       {
+         if (section->vma - extra->ImageBase <= addr
+             && ((section->vma - extra->ImageBase
+                  + bfd_section_size (abfd, section))
+                 >= addr + size))
+           break;
+       }
+      if (section == NULL)
+       return true;
+
+      datasize = size;
+      dataoff = addr - (section->vma - extra->ImageBase);
+    }
+
+  data = (bfd_byte *) bfd_malloc (datasize);
+  if (data == NULL && datasize != 0)
+    return false;
+
+  if (! bfd_get_section_contents (abfd, section, (PTR) data, dataoff,
+                                 datasize))
+    return false;
+
+  /* Go get Export Directory Table */
+  edt.export_flags   = bfd_get_32(abfd, data+0); 
+  edt.time_stamp     = bfd_get_32(abfd, data+4);
+  edt.major_ver      = bfd_get_16(abfd, data+8);
+  edt.minor_ver      = bfd_get_16(abfd, data+10);
+  edt.name           = bfd_get_32(abfd, data+12);
+  edt.base           = bfd_get_32(abfd, data+16);
+  edt.num_functions  = bfd_get_32(abfd, data+20); 
+  edt.num_names      = bfd_get_32(abfd, data+24); 
+  edt.eat_addr       = bfd_get_32(abfd, data+28);
+  edt.npt_addr       = bfd_get_32(abfd, data+32); 
+  edt.ot_addr        = bfd_get_32(abfd, data+36);
+
+  adj = (extra->ImageBase - (section->vma + dataoff)) & 0xffffffff;
+
+
+  /* Dump the EDT first first */
+  fprintf(file,
+         _("\nThe Export Tables (interpreted .edata section contents)\n\n"));
+
+  fprintf(file,
+         _("Export Flags \t\t\t%lx\n"), (unsigned long) edt.export_flags);
+
+  fprintf(file,
+         _("Time/Date stamp \t\t%lx\n"), (unsigned long) edt.time_stamp);
+
+  fprintf(file,
+         _("Major/Minor \t\t\t%d/%d\n"), edt.major_ver, edt.minor_ver);
+
+  fprintf (file,
+          _("Name \t\t\t\t"));
+  fprintf_vma (file, edt.name);
+  fprintf (file,
+          " %s\n", data + edt.name + adj);
+
+  fprintf(file,
+         _("Ordinal Base \t\t\t%ld\n"), edt.base);
+
+  fprintf(file,
+         _("Number in:\n"));
+
+  fprintf(file,
+         _("\tExport Address Table \t\t%lx\n"),
+         edt.num_functions);
+
+  fprintf(file,
+         _("\t[Name Pointer/Ordinal] Table\t%lu\n"), edt.num_names);
+
+  fprintf(file,
+         _("Table Addresses\n"));
+
+  fprintf (file,
+          _("\tExport Address Table \t\t"));
+  fprintf_vma (file, edt.eat_addr);
+  fprintf (file, "\n");
+
+  fprintf (file,
+         _("\tName Pointer Table \t\t"));
+  fprintf_vma (file, edt.npt_addr);
+  fprintf (file, "\n");
+
+  fprintf (file,
+          _("\tOrdinal Table \t\t\t"));
+  fprintf_vma (file, edt.ot_addr);
+  fprintf (file, "\n");
+
+  
+  /* The next table to find si the Export Address Table. It's basically
+     a list of pointers that either locate a function in this dll, or
+     forward the call to another dll. Something like:
+      typedef union 
+      {
+        long export_rva;
+        long forwarder_rva;
+      } export_address_table_entry;
+  */
+
+  fprintf(file,
+         _("\nExport Address Table -- Ordinal Base %ld\n"),
+         edt.base);
+
+  for (i = 0; i < edt.num_functions; ++i)
+    {
+      bfd_vma eat_member = bfd_get_32 (abfd, 
+                                      data + edt.eat_addr + (i * 4) + adj);
+      bfd_vma eat_actual = (extra->ImageBase + eat_member) & 0xffffffff;
+      bfd_vma edata_start = bfd_get_section_vma (abfd,section) + dataoff;
+      bfd_vma edata_end = edata_start + datasize;
+
+      if (eat_member == 0)
+       continue;
+
+      if (edata_start < eat_actual && eat_actual < edata_end) 
+       {
+         /* this rva is to a name (forwarding function) in our section */
+         /* Should locate a function descriptor */
+         fprintf(file,
+                 "\t[%4ld] +base[%4ld] %04lx %s -- %s\n", 
+                 (long) i, (long) (i + edt.base), eat_member,
+                 "Forwarder RVA", data + eat_member + adj);
+       }
+      else
+       {
+         /* Should locate a function descriptor in the reldata section */
+         fprintf(file,
+                 "\t[%4ld] +base[%4ld] %04lx %s\n", 
+                 (long) i, (long) (i + edt.base), eat_member, "Export RVA");
+       }
+    }
+
+  /* The Export Name Pointer Table is paired with the Export Ordinal Table */
+  /* Dump them in parallel for clarity */
+  fprintf(file,
+         _("\n[Ordinal/Name Pointer] Table\n"));
+
+  for (i = 0; i < edt.num_names; ++i)
+    {
+      bfd_vma name_ptr = bfd_get_32(abfd, 
+                                   data + 
+                                   edt.npt_addr
+                                   + (i*4) + adj);
+      
+      char *name = (char *) data + name_ptr + adj;
+
+      bfd_vma ord = bfd_get_16(abfd, 
+                                   data + 
+                                   edt.ot_addr
+                                   + (i*2) + adj);
+      fprintf(file,
+             "\t[%4ld] %s\n", (long) ord, name);
+
+    }
+
+  free (data);
+
+  return true;
+}
+
+static boolean
+pe_print_pdata (abfd, vfile)
+     bfd  *abfd;
+     PTR vfile;
+{
+  FILE *file = (FILE *) vfile;
+  bfd_byte *data = 0;
+  asection *section = bfd_get_section_by_name (abfd, ".pdata");
+  bfd_size_type datasize = 0;
+  bfd_size_type i;
+  bfd_size_type start, stop;
+  int onaline = 20;
+
+  if (section == 0)
+    return true;
+
+  stop = bfd_section_size (abfd, section);
+  if ((stop % onaline) != 0)
+    fprintf (file, _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
+            (long)stop, onaline);
+
+  fprintf(file,
+         _("\nThe Function Table (interpreted .pdata section contents)\n"));
+  fprintf(file,
+         _(" vma:\t\tBegin    End      EH       EH       PrologEnd\n"));
+  fprintf(file,
+         _("     \t\tAddress  Address  Handler  Data     Address\n"));
+
+  if (bfd_section_size (abfd, section) == 0)
+    return true;
+
+  data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));
+  datasize = bfd_section_size (abfd, section);
+  if (data == NULL && datasize != 0)
+    return false;
+
+  bfd_get_section_contents (abfd, 
+                           section, 
+                           (PTR) data, 0, 
+                           bfd_section_size (abfd, section));
+
+  start = 0;
+
+  for (i = start; i < stop; i += onaline)
+    {
+      bfd_vma begin_addr;
+      bfd_vma end_addr;
+      bfd_vma eh_handler;
+      bfd_vma eh_data;
+      bfd_vma prolog_end_addr;
+
+      if (i+20 > stop)
+         break;
+      
+      begin_addr = bfd_get_32(abfd, data+i);
+      end_addr = bfd_get_32(abfd, data+i+4);
+      eh_handler = bfd_get_32(abfd, data+i+8);
+      eh_data = bfd_get_32(abfd, data+i+12);
+      prolog_end_addr = bfd_get_32(abfd, data+i+16);
+      
+      if (begin_addr == 0 && end_addr == 0 && eh_handler == 0
+         && eh_data == 0 && prolog_end_addr == 0)
+       {
+         /* We are probably into the padding of the
+            section now */
+         break;
+       }
+
+      fprintf (file,
+              " %08lx\t", 
+              (unsigned long int) (i + section->vma));
+
+      fprintf(file, "%08lx %08lx %08lx %08lx %08lx",
+             begin_addr,
+             end_addr,
+             eh_handler,
+             eh_data,
+             prolog_end_addr);
+
+#ifdef POWERPC_LE_PE
+      if (eh_handler == 0 && eh_data != 0)
+       {
+         /* Special bits here, although the meaning may */
+         /* be a little mysterious. The only one I know */
+         /* for sure is 0x03.                           */
+         /* Code Significance                           */
+         /* 0x00 None                                   */
+         /* 0x01 Register Save Millicode                */
+         /* 0x02 Register Restore Millicode             */
+         /* 0x03 Glue Code Sequence                     */
+         switch (eh_data)
+           {
+           case 0x01:
+             fprintf(file, _(" Register save millicode"));
+             break;
+           case 0x02:
+             fprintf(file, _(" Register restore millicode"));
+             break;
+           case 0x03:
+             fprintf(file, _(" Glue code sequence"));
+             break;
+           default:
+             break;
+           }
+       }
+#endif    
+      fprintf(file, "\n");
+    }
+
+  free (data);
+
+  return true;
+}
+
+static const char *tbl[6] =
+{
+"ABSOLUTE",
+"HIGH",
+"LOW",
+"HIGHLOW",
+"HIGHADJ",
+"MIPS_JMPADDR"
+};
+
+static boolean
+pe_print_reloc (abfd, vfile)
+     bfd *abfd;
+     PTR vfile;
+{
+  FILE *file = (FILE *) vfile;
+  bfd_byte *data = 0;
+  asection *section = bfd_get_section_by_name (abfd, ".reloc");
+  bfd_size_type datasize = 0;
+  bfd_size_type i;
+  bfd_size_type start, stop;
+
+  if (section == 0)
+    return true;
+
+  if (bfd_section_size (abfd, section) == 0)
+    return true;
+
+  fprintf(file,
+         _("\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);
+  if (data == NULL && datasize != 0)
+    return false;
+
+  bfd_get_section_contents (abfd, 
+                           section, 
+                           (PTR) data, 0, 
+                           bfd_section_size (abfd, section));
+
+  start = 0;
+
+  stop = bfd_section_size (abfd, section);
+
+  for (i = start; i < stop;)
+    {
+      int j;
+      bfd_vma virtual_address;
+      long number, size;
+
+      /* The .reloc section is a sequence of blocks, with a header consisting
+        of two 32 bit quantities, followed by a number of 16 bit entries */
+
+      virtual_address = bfd_get_32(abfd, data+i);
+      size = bfd_get_32(abfd, data+i+4);
+      number = (size - 8) / 2;
+
+      if (size == 0) 
+       {
+         break;
+       }
+
+      fprintf (file,
+              _("\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n"),
+              virtual_address, size, size, number);
+
+      for (j = 0; j < number; ++j)
+       {
+         unsigned short e = bfd_get_16(abfd, data + i + 8 + j*2);
+         int t =   (e & 0xF000) >> 12;
+         int off = e & 0x0FFF;
+
+         if (t > 5) 
+           abort();
+
+         fprintf(file,
+                 _("\treloc %4d offset %4x [%4lx] %s\n"), 
+                 j, off, (long) (off + virtual_address), tbl[t]);
+         
+       }
+      i += size;
+    }
+
+  free (data);
+
+  return true;
+}
+
 static boolean
 pe_print_private_bfd_data (abfd, vfile)
 static boolean
 pe_print_private_bfd_data (abfd, vfile)
-     bfd*abfd;
-     void *vfile;
+     bfd *abfd;
+     PTR vfile;
 {
 {
-  FILE *file = vfile;
+  FILE *file = (FILE *) vfile;
   int j;
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
   int j;
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
-  fprintf (file,"ImageBase\t\t");
+
+  /* The MS dumpbin program reportedly ands with 0xff0f before
+     printing the characteristics field.  Not sure why.  No reason to
+     emulate it here.  */
+  fprintf (file, _("\nCharacteristics 0x%x\n"), pe->real_flags);
+#undef PF
+#define PF(x, y)    if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); }
+  PF (F_RELFLG, "relocations stripped");
+  PF (F_EXEC, "executable");
+  PF (F_LNNO, "line numbers stripped");
+  PF (F_LSYMS, "symbols stripped");
+  PF (0x80, "little endian");
+  PF (F_AR32WR, "32 bit words");
+  PF (0x200, "debugging information removed");
+  PF (0x1000, "system file");
+  PF (F_DLL, "DLL");
+  PF (0x8000, "big endian");
+#undef PF
+
+  fprintf (file,"\nImageBase\t\t");
   fprintf_vma (file, i->ImageBase);
   fprintf_vma (file, i->ImageBase);
-  fprintf (file,"SectionAlignment\t");
+  fprintf (file,"\nSectionAlignment\t");
   fprintf_vma (file, i->SectionAlignment);
   fprintf_vma (file, i->SectionAlignment);
-  fprintf (file,"FileAlignment\t\t");
+  fprintf (file,"\nFileAlignment\t\t");
   fprintf_vma (file, i->FileAlignment);
   fprintf_vma (file, i->FileAlignment);
-  fprintf (file,"MajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion);
+  fprintf (file,"\nMajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion);
   fprintf (file,"MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion);
   fprintf (file,"MajorImageVersion\t%d\n", i->MajorImageVersion);
   fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion);
   fprintf (file,"MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion);
   fprintf (file,"MajorImageVersion\t%d\n", i->MajorImageVersion);
   fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion);
@@ -1018,20 +1956,34 @@ pe_print_private_bfd_data (abfd, vfile)
   fprintf (file,"DllCharacteristics\t%08x\n", i->DllCharacteristics);
   fprintf (file,"SizeOfStackReserve\t");
   fprintf_vma (file, i->SizeOfStackReserve);
   fprintf (file,"DllCharacteristics\t%08x\n", i->DllCharacteristics);
   fprintf (file,"SizeOfStackReserve\t");
   fprintf_vma (file, i->SizeOfStackReserve);
-  fprintf (file,"SizeOfStackCommit\t");
+  fprintf (file,"\nSizeOfStackCommit\t");
   fprintf_vma (file, i->SizeOfStackCommit);
   fprintf_vma (file, i->SizeOfStackCommit);
-  fprintf (file,"SizeOfHeapReserve\t");
+  fprintf (file,"\nSizeOfHeapReserve\t");
   fprintf_vma (file, i->SizeOfHeapReserve);
   fprintf_vma (file, i->SizeOfHeapReserve);
-  fprintf (file,"SizeOfHeapCommit\t");
+  fprintf (file,"\nSizeOfHeapCommit\t");
   fprintf_vma (file, i->SizeOfHeapCommit);
   fprintf_vma (file, i->SizeOfHeapCommit);
-  fprintf (file,"LoaderFlags\t\t%08lx\n", i->LoaderFlags);
+  fprintf (file,"\nLoaderFlags\t\t%08lx\n", i->LoaderFlags);
   fprintf (file,"NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes);
 
   fprintf (file,"NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes);
 
+  fprintf (file,"\nThe Data Directory\n");
   for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++) 
     {
   for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++) 
     {
-      fprintf (file, "Entry %2d ", j);
+      fprintf (file, "Entry %1x ", j);
       fprintf_vma (file, i->DataDirectory[j].VirtualAddress);
       fprintf_vma (file, i->DataDirectory[j].VirtualAddress);
-      fprintf (file, " %08lx\n", i->DataDirectory[j].Size);
+      fprintf (file, " %08lx ", i->DataDirectory[j].Size);
+      fprintf (file, "%s\n", dir_names[j]);
+    }
+
+  pe_print_idata (abfd, vfile);
+  pe_print_edata (abfd, vfile);
+  pe_print_pdata (abfd, vfile);
+  pe_print_reloc (abfd, vfile);
+
+  if (pe_saved_coff_bfd_print_private_bfd_data != NULL)
+    {
+      fputc ('\n', file);
+  
+      return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
     }
 
   return true;
     }
 
   return true;
@@ -1042,16 +1994,16 @@ pe_mkobject (abfd)
      bfd * abfd;
 {
   pe_data_type *pe;
      bfd * abfd;
 {
   pe_data_type *pe;
-
   abfd->tdata.pe_obj_data = 
     (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type));
   abfd->tdata.pe_obj_data = 
     (struct pe_tdata *) bfd_zalloc (abfd, sizeof (pe_data_type));
+
   if (abfd->tdata.pe_obj_data == 0)
   if (abfd->tdata.pe_obj_data == 0)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return false;
-    }
-  pe =pe_data (abfd);
+    return false;
+
+  pe = pe_data (abfd);
+
   pe->coff.pe = 1;
   pe->coff.pe = 1;
+  pe->in_reloc_p = in_reloc_p;
   return true;
 }
 
   return true;
 }
 
@@ -1069,9 +2021,7 @@ pe_mkobject_hook (abfd, filehdr, aouthdr)
     return NULL;
 
   pe = pe_data (abfd);
     return NULL;
 
   pe = pe_data (abfd);
-
   pe->coff.sym_filepos = internal_f->f_symptr;
   pe->coff.sym_filepos = internal_f->f_symptr;
-
   /* These members communicate important constants about the symbol
      table to GDB's symbol-reading code.  These `constants'
      unfortunately vary among coff implementations...  */
   /* These members communicate important constants about the symbol
      table to GDB's symbol-reading code.  These `constants'
      unfortunately vary among coff implementations...  */
@@ -1087,10 +2037,101 @@ pe_mkobject_hook (abfd, filehdr, aouthdr)
     obj_conv_table_size (abfd) =
       internal_f->f_nsyms;
 
     obj_conv_table_size (abfd) =
       internal_f->f_nsyms;
 
-  pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe;
+  pe->real_flags = internal_f->f_flags;
+
+  if ((internal_f->f_flags & F_DLL) != 0)
+    pe->dll = 1;
+
+#ifdef COFF_IMAGE_WITH_PE
+  if (aouthdr) 
+    pe->pe_opthdr = ((struct internal_aouthdr *)aouthdr)->pe;
+#endif
+
+#ifdef ARM 
+  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
+    coff_data (abfd) ->flags = 0;
+#endif
+  
   return (PTR) pe;
 }
 
 
 
   return (PTR) pe;
 }
 
 
 
+/* Copy any private info we understand from the input bfd
+   to the output bfd.  */
+
+#ifdef coff_bfd_copy_private_bfd_data
+static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
+     PARAMS ((bfd *, bfd *))
+     = coff_bfd_copy_private_bfd_data;
+#undef coff_bfd_copy_private_bfd_data
+#else
+static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
+     PARAMS ((bfd *, bfd *))
+     = NULL;
+#endif
+#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
+
+static boolean
+pe_bfd_copy_private_bfd_data (ibfd, obfd)
+     bfd *ibfd, *obfd;
+{
+  /* One day we may try to grok other private data.  */
+  if (ibfd->xvec->flavour != bfd_target_coff_flavour
+      || obfd->xvec->flavour != bfd_target_coff_flavour)
+    return true;
+
+  pe_data (obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr;
+  pe_data (obfd)->dll = pe_data (ibfd)->dll;
+
+  if (pe_saved_coff_bfd_copy_private_bfd_data)
+    return pe_saved_coff_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 (bfd_get_flavour (ibfd) != bfd_target_coff_flavour
+      || bfd_get_flavour (obfd) != bfd_target_coff_flavour)
+    return true;
+
+  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