2003-09-09 Jeff Johnston <jjohnstn@redhat.com>
[deliverable/binutils-gdb.git] / bfd / peicode.h
index c20e9a3dfbd5abcb35ecb03c0afb0113b7ff9e4a..b3c1f29910b4aef4a184773f8866ea1f45e8a1c1 100644 (file)
@@ -1,31 +1,29 @@
 /* Support for the generic parts of PE/PEI, for BFD.
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Cygnus Solutions.
 
-This file is part of BFD, the Binary File Descriptor library.
+   This file is part of BFD, the Binary File Descriptor library.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-/*
-Most of this hacked by  Steve Chamberlain,
+/* Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com
 
-PE/PEI rearrangement (and code added): Donn Terry
-                                       Softway Systems, Inc.
-*/
+   PE/PEI rearrangement (and code added): Donn Terry
+                                       Softway Systems, Inc.  */
 
 /* Hey look, some documentation [and in a place you expect to find it]!
 
@@ -53,12 +51,11 @@ PE/PEI rearrangement (and code added): Donn Terry
 
    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.
-*/
+   wasting too much time.  */
 
 #include "libpei.h"
 
-static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
+static bfd_boolean (*pe_saved_coff_bfd_print_private_bfd_data)
     PARAMS ((bfd *, PTR)) =
 #ifndef coff_bfd_print_private_bfd_data
      NULL;
@@ -67,10 +64,10 @@ static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
 #undef coff_bfd_print_private_bfd_data
 #endif
 
-static boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
+static bfd_boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
 #define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
 
-static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
+static bfd_boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
     PARAMS ((bfd *, bfd *)) =
 #ifndef coff_bfd_copy_private_bfd_data
      NULL;
@@ -79,7 +76,7 @@ static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
 #undef coff_bfd_copy_private_bfd_data
 #endif
 
-static boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+static bfd_boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
 #define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
 
 #define coff_mkobject      pe_mkobject
@@ -91,7 +88,7 @@ static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
 #endif
 static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
 static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
-static boolean pe_mkobject PARAMS ((bfd *));
+static bfd_boolean pe_mkobject PARAMS ((bfd *));
 static PTR pe_mkobject_hook PARAMS ((bfd *, PTR, PTR));
 
 #ifdef COFF_IMAGE_WITH_PE
@@ -139,7 +136,7 @@ static void               pe_ILF_make_a_reloc     PARAMS ((pe_ILF_vars *, bfd_vm
 static void               pe_ILF_make_a_symbol    PARAMS ((pe_ILF_vars *, const char *, const char *, asection_ptr, flagword));
 static void               pe_ILF_save_relocs      PARAMS ((pe_ILF_vars *, asection_ptr));
 static void              pe_ILF_make_a_symbol_reloc  PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct symbol_cache_entry **, unsigned int));
-static boolean            pe_ILF_build_a_bfd      PARAMS ((bfd *, unsigned int, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
+static bfd_boolean        pe_ILF_build_a_bfd      PARAMS ((bfd *, unsigned int, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
 static const bfd_target * pe_ILF_object_p         PARAMS ((bfd *));
 static const bfd_target * pe_bfd_object_p        PARAMS ((bfd *));
 #endif /* COFF_IMAGE_WITH_PE */
@@ -259,12 +256,17 @@ coff_swap_scnhdr_in (abfd, ext, in)
     }
 
 #ifndef COFF_NO_HACK_SCNHDR_SIZE
-  /* If this section holds uninitialized data, use the virtual size
-     (stored in s_paddr) instead of the physical size.  */
-  if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
-      && (scnhdr_int->s_paddr > 0))
+  /* If this section holds uninitialized data and is from an object file
+     or from an executable image that has not initialized the field,
+     or if the physical size is padded, use the virtual size (stored in
+     s_paddr) instead.  */
+  if (scnhdr_int->s_paddr > 0
+      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
+          && (! bfd_pe_executable_p (abfd) || scnhdr_int->s_size == 0))
+          || scnhdr_int->s_size > scnhdr_int->s_paddr))
     {
       scnhdr_int->s_size = scnhdr_int->s_paddr;
+
       /* This code used to set scnhdr_int->s_paddr to 0.  However,
          coff_set_alignment_hook stores s_paddr in virt_size, which
          only works if it correctly holds the virtual size of the
@@ -273,7 +275,7 @@ coff_swap_scnhdr_in (abfd, ext, in)
 #endif
 }
 
-static boolean
+static bfd_boolean
 pe_mkobject (abfd)
      bfd * abfd;
 {
@@ -283,7 +285,7 @@ pe_mkobject (abfd)
   abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
 
   if (abfd->tdata.pe_obj_data == 0)
-    return false;
+    return FALSE;
 
   pe = pe_data (abfd);
 
@@ -299,7 +301,7 @@ pe_mkobject (abfd)
   pe->target_subsystem = PEI_TARGET_SUBSYSTEM;
 #endif
 
-  return true;
+  return TRUE;
 }
 
 /* Create the COFF backend specific information.  */
@@ -355,7 +357,7 @@ pe_mkobject_hook (abfd, filehdr, aouthdr)
   return (PTR) pe;
 }
 
-static boolean
+static bfd_boolean
 pe_print_private_bfd_data (abfd, vfile)
      bfd *abfd;
      PTR vfile;
@@ -363,7 +365,7 @@ pe_print_private_bfd_data (abfd, vfile)
   FILE *file = (FILE *) vfile;
 
   if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
-    return false;
+    return FALSE;
 
   if (pe_saved_coff_bfd_print_private_bfd_data != NULL)
     {
@@ -372,23 +374,23 @@ pe_print_private_bfd_data (abfd, vfile)
       return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Copy any private info we understand from the input bfd
    to the output bfd.  */
 
-static boolean
+static bfd_boolean
 pe_bfd_copy_private_bfd_data (ibfd, obfd)
      bfd *ibfd, *obfd;
 {
   if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
-    return false;
+    return FALSE;
 
   if (pe_saved_coff_bfd_copy_private_bfd_data)
     return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
 
-  return true;
+  return TRUE;
 }
 
 #define coff_bfd_copy_private_section_data \
@@ -518,7 +520,7 @@ pe_ILF_save_relocs (pe_ILF_vars * vars,
     abort ();
 
   coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
-  coff_section_data (vars->abfd, sec)->keep_relocs = true;
+  coff_section_data (vars->abfd, sec)->keep_relocs = TRUE;
 
   sec->relocation  = vars->reltab;
   sec->reloc_count = vars->relcount;
@@ -610,7 +612,7 @@ pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
 #if 0 /* See comment above.  */
   sym->symbol.value   = 0;
   sym->symbol.udata.i = 0;
-  sym->done_lineno    = false;
+  sym->done_lineno    = FALSE;
   sym->lineno         = NULL;
 #endif
 
@@ -753,7 +755,7 @@ static jump_table jtab[] =
 #endif
 
 /* Build a full BFD from the information supplied in a ILF object.  */
-static boolean
+static bfd_boolean
 pe_ILF_build_a_bfd (bfd *           abfd,
                    unsigned int    magic,
                    bfd_byte *      symbol_name,
@@ -784,12 +786,12 @@ pe_ILF_build_a_bfd (bfd *           abfd,
       /* XXX code yet to be written.  */
       _bfd_error_handler (_("%s: Unhandled import type; %x"),
                          bfd_archive_filename (abfd), import_type);
-      return false;
+      return FALSE;
 
     default:
       _bfd_error_handler (_("%s: Unrecognised import type; %x"),
                          bfd_archive_filename (abfd), import_type);
-      return false;
+      return FALSE;
     }
 
   switch (import_name_type)
@@ -803,7 +805,7 @@ pe_ILF_build_a_bfd (bfd *           abfd,
     default:
       _bfd_error_handler (_("%s: Unrecognised import name type; %x"),
                          bfd_archive_filename (abfd), import_name_type);
-      return false;
+      return FALSE;
     }
 
   /* Initialise local variables.
@@ -815,7 +817,7 @@ pe_ILF_build_a_bfd (bfd *           abfd,
      so allocate all the space that we will need right now.  */
   ptr = bfd_zalloc (abfd, (bfd_size_type) ILF_DATA_SIZE);
   if (ptr == NULL)
-    return false;
+    return FALSE;
 
   /* Create a bfd_in_memory structure.  */
   vars.bim = (struct bfd_in_memory *) ptr;
@@ -875,7 +877,7 @@ pe_ILF_build_a_bfd (bfd *           abfd,
   id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
   id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
   if (id4 == NULL || id5 == NULL)
-    return false;
+    return FALSE;
 
   /* Fill in the contents of these sections.  */
   if (import_name_type == IMPORT_ORDINAL)
@@ -894,7 +896,7 @@ pe_ILF_build_a_bfd (bfd *           abfd,
       /* Create .idata$6 - the Hint Name Table.  */
       id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
       if (id6 == NULL)
-       return false;
+       return FALSE;
 
       /* If necessary, trim the import symbol name.  */
       symbol = symbol_name;
@@ -950,7 +952,7 @@ pe_ILF_build_a_bfd (bfd *           abfd,
       /* Create the .text section.  */
       text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
       if (text == NULL)
-       return false;
+       return FALSE;
 
       /* Copy in the jump code.  */
       memcpy (text->contents, jtab[i].data, jtab[i].size);
@@ -999,10 +1001,10 @@ pe_ILF_build_a_bfd (bfd *           abfd,
 
   if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
       || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
-    return false;
+    return FALSE;
 
   if (bfd_coff_mkobject_hook (abfd, (PTR) & internal_f, NULL) == NULL)
-    return false;
+    return FALSE;
 
   coff_data (abfd)->pe = 1;
 #ifdef THUMBPEMAGIC
@@ -1053,17 +1055,17 @@ pe_ILF_build_a_bfd (bfd *           abfd,
   obj_raw_syment_count (abfd) = vars.sym_index;
 
   obj_coff_external_syms (abfd) = (PTR) vars.esym_table;
-  obj_coff_keep_syms (abfd) = true;
+  obj_coff_keep_syms (abfd) = TRUE;
 
   obj_convert (abfd) = vars.sym_table;
   obj_conv_table_size (abfd) = vars.sym_index;
 
   obj_coff_strings (abfd) = vars.string_table;
-  obj_coff_keep_strings (abfd) = true;
+  obj_coff_keep_strings (abfd) = TRUE;
 
   abfd->flags |= HAS_SYMS;
 
-  return true;
+  return TRUE;
 }
 
 /* We have detected a Image Library Format archive element.
@@ -1207,7 +1209,10 @@ _("%s: Recognised but unhandled machine type (0x%x) in Import Library Format arc
     return NULL;
 
   if (bfd_bread (ptr, size, abfd) != size)
-    return NULL;
+    {
+      bfd_release (abfd, ptr);
+      return NULL;
+    }
 
   symbol_name = ptr;
   source_dll  = ptr + strlen (ptr) + 1;
@@ -1219,14 +1224,17 @@ _("%s: Recognised but unhandled machine type (0x%x) in Import Library Format arc
        (_("%s: string not null terminated in ILF object file."),
         bfd_archive_filename (abfd));
       bfd_set_error (bfd_error_malformed_archive);
-
+      bfd_release (abfd, ptr);
       return NULL;
     }
 
   /* Now construct the bfd.  */
   if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
                            source_dll, ordinal, types))
-    return NULL;
+    {
+      bfd_release (abfd, ptr);
+      return NULL;
+    }
 
   return abfd->xvec;
 }
This page took 0.043529 seconds and 4 git commands to generate.