FIX EOF detection in PT_IO-based to_xfer_partial implementation.
[deliverable/binutils-gdb.git] / bfd / pef.c
index bb59724e9e96b384c05827f2acd5c10ea0d8d80a..4829851fcaa9f09a410232fb7e1e0088bb0a0cdc 100644 (file)
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -1,6 +1,5 @@
 /* PEF support for BFD.
 /* PEF support for BFD.
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright 1999-2014 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
 
    This file is part of BFD, the Binary File Descriptor library.
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+/* PEF (Preferred Executable Format) is the binary file format for late
+   classic Mac OS versions (before Darwin).  It is supported by both m68k
+   and PowerPc.  It is also called CFM (Code Fragment Manager).  */
+
 #include "sysdep.h"
 #include "safe-ctype.h"
 #include "pef.h"
 #include "sysdep.h"
 #include "safe-ctype.h"
 #include "pef.h"
@@ -48,6 +51,7 @@
 #define bfd_pef_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_pef_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_pef_bfd_gc_sections                     bfd_generic_gc_sections
 #define bfd_pef_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_pef_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_pef_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_pef_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_pef_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_pef_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
 #define bfd_pef_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_pef_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
@@ -57,6 +61,8 @@
 #define bfd_pef_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define bfd_pef_bfd_link_add_symbols                _bfd_generic_link_add_symbols
 #define bfd_pef_bfd_link_just_syms                  _bfd_generic_link_just_syms
 #define bfd_pef_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define bfd_pef_bfd_link_add_symbols                _bfd_generic_link_add_symbols
 #define bfd_pef_bfd_link_just_syms                  _bfd_generic_link_just_syms
+#define bfd_pef_bfd_copy_link_hash_symbol_type \
+  _bfd_generic_copy_link_hash_symbol_type
 #define bfd_pef_bfd_final_link                      _bfd_generic_final_link
 #define bfd_pef_bfd_link_split_section              _bfd_generic_link_split_section
 #define bfd_pef_get_section_contents_in_window      _bfd_generic_get_section_contents_in_window
 #define bfd_pef_bfd_final_link                      _bfd_generic_final_link
 #define bfd_pef_bfd_link_split_section              _bfd_generic_link_split_section
 #define bfd_pef_get_section_contents_in_window      _bfd_generic_get_section_contents_in_window
@@ -361,7 +367,7 @@ bfd_pef_parse_imported_symbol (bfd *abfd ATTRIBUTE_UNUSED,
   BFD_ASSERT (len == 4);
 
   value = bfd_getb32 (buf);
   BFD_ASSERT (len == 4);
 
   value = bfd_getb32 (buf);
-  symbol->class = value >> 24;
+  symbol->symbol_class = value >> 24;
   symbol->name = value & 0x00ffffff;
 
   return 0;
   symbol->name = value & 0x00ffffff;
 
   return 0;
@@ -500,10 +506,9 @@ bfd_pef_scan_start_address (bfd *abfd)
 }
 
 int
 }
 
 int
-bfd_pef_scan (abfd, header, mdata)
-     bfd *abfd;
-     bfd_pef_header *header;
-     bfd_pef_data_struct *mdata;
+bfd_pef_scan (bfd *abfd,
+             bfd_pef_header *header,
+             bfd_pef_data_struct *mdata)
 {
   unsigned int i;
   enum bfd_architecture cputype;
 {
   unsigned int i;
   enum bfd_architecture cputype;
@@ -514,8 +519,8 @@ bfd_pef_scan (abfd, header, mdata)
   bfd_pef_convert_architecture (header->architecture, &cputype, &cpusubtype);
   if (cputype == bfd_arch_unknown)
     {
   bfd_pef_convert_architecture (header->architecture, &cputype, &cpusubtype);
   if (cputype == bfd_arch_unknown)
     {
-      fprintf (stderr, "bfd_pef_scan: unknown architecture 0x%lx\n",
-              header->architecture);
+      (*_bfd_error_handler) (_("bfd_pef_scan: unknown architecture 0x%lx"),
+                              header->architecture);
       return -1;
     }
   bfd_set_arch_mach (abfd, cputype, cpusubtype);
       return -1;
     }
   bfd_set_arch_mach (abfd, cputype, cpusubtype);
@@ -577,34 +582,28 @@ bfd_pef_read_header (bfd *abfd, bfd_pef_header *header)
 static const bfd_target *
 bfd_pef_object_p (bfd *abfd)
 {
 static const bfd_target *
 bfd_pef_object_p (bfd *abfd)
 {
-  struct bfd_preserve preserve;
   bfd_pef_header header;
   bfd_pef_header header;
+  bfd_pef_data_struct *mdata;
 
 
-  preserve.marker = NULL;
   if (bfd_pef_read_header (abfd, &header) != 0)
     goto wrong;
 
   if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2)
     goto wrong;
 
   if (bfd_pef_read_header (abfd, &header) != 0)
     goto wrong;
 
   if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2)
     goto wrong;
 
-  preserve.marker = bfd_zalloc (abfd, sizeof (bfd_pef_data_struct));
-  if (preserve.marker == NULL
-      || !bfd_preserve_save (abfd, &preserve))
+  mdata = (bfd_pef_data_struct *) bfd_zalloc (abfd, sizeof (*mdata));
+  if (mdata == NULL)
     goto fail;
 
     goto fail;
 
-  if (bfd_pef_scan (abfd, &header,
-                   (bfd_pef_data_struct *) preserve.marker) != 0)
+  if (bfd_pef_scan (abfd, &header, mdata))
     goto wrong;
 
     goto wrong;
 
-  bfd_preserve_finish (abfd, &preserve);
   return abfd->xvec;
 
  wrong:
   bfd_set_error (bfd_error_wrong_format);
 
  fail:
   return abfd->xvec;
 
  wrong:
   bfd_set_error (bfd_error_wrong_format);
 
  fail:
-  if (preserve.marker != NULL)
-    bfd_preserve_restore (abfd, &preserve);
   return NULL;
 }
 
   return NULL;
 }
 
@@ -728,14 +727,11 @@ bfd_pef_parse_function_stubs (bfd *abfd,
                              asymbol **csym)
 {
   const char *const sprefix = "__stub_";
                              asymbol **csym)
 {
   const char *const sprefix = "__stub_";
-
   size_t codepos = 0;
   unsigned long count = 0;
   size_t codepos = 0;
   unsigned long count = 0;
-
   bfd_pef_loader_header header;
   bfd_pef_imported_library *libraries = NULL;
   bfd_pef_imported_symbol *imports = NULL;
   bfd_pef_loader_header header;
   bfd_pef_imported_library *libraries = NULL;
   bfd_pef_imported_symbol *imports = NULL;
-
   unsigned long i;
   int ret;
 
   unsigned long i;
   int ret;
 
@@ -781,8 +777,7 @@ bfd_pef_parse_function_stubs (bfd *abfd,
       asymbol sym;
       const char *symname;
       char *name;
       asymbol sym;
       const char *symname;
       char *name;
-      unsigned long index;
-      int ret;
+      unsigned long sym_index;
 
       if (csym && (csym[count] == NULL))
        break;
 
       if (csym && (csym[count] == NULL))
        break;
@@ -800,14 +795,14 @@ bfd_pef_parse_function_stubs (bfd *abfd,
       if ((codepos + 4) > codelen)
        break;
 
       if ((codepos + 4) > codelen)
        break;
 
-      ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &index);
+      ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &sym_index);
       if (ret < 0)
        {
          codepos += 24;
          continue;
        }
 
       if (ret < 0)
        {
          codepos += 24;
          continue;
        }
 
-      if (index >= header.total_imported_symbol_count)
+      if (sym_index >= header.total_imported_symbol_count)
        {
          codepos += 24;
          continue;
        {
          codepos += 24;
          continue;
@@ -817,12 +812,12 @@ bfd_pef_parse_function_stubs (bfd *abfd,
        size_t max, namelen;
        const char *s;
 
        size_t max, namelen;
        const char *s;
 
-       if (loaderlen < (header.loader_strings_offset + imports[index].name))
+       if (loaderlen < (header.loader_strings_offset + imports[sym_index].name))
          goto error;
 
          goto error;
 
-       max = loaderlen - (header.loader_strings_offset + imports[index].name);
+       max = loaderlen - (header.loader_strings_offset + imports[sym_index].name);
        symname = (char *) loaderbuf;
        symname = (char *) loaderbuf;
-       symname += header.loader_strings_offset + imports[index].name;
+       symname += header.loader_strings_offset + imports[sym_index].name;
        namelen = 0;
        for (s = symname; s < (symname + max); s++)
          {
        namelen = 0;
        for (s = symname; s < (symname + max); s++)
          {
@@ -1017,6 +1012,7 @@ const bfd_target pef_vec =
   0,                           /* Symbol_leading_char.  */
   ' ',                         /* AR_pad_char.  */
   16,                          /* AR_max_namelen.  */
   0,                           /* Symbol_leading_char.  */
   ' ',                         /* AR_pad_char.  */
   16,                          /* AR_max_namelen.  */
+  0,                           /* match priority.  */
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* Data.  */
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* Data.  */
@@ -1068,11 +1064,11 @@ const bfd_target pef_vec =
 static int
 bfd_pef_xlib_read_header (bfd *abfd, bfd_pef_xlib_header *header)
 {
 static int
 bfd_pef_xlib_read_header (bfd *abfd, bfd_pef_xlib_header *header)
 {
-  unsigned char buf[76];
+  unsigned char buf[80];
 
   bfd_seek (abfd, 0, SEEK_SET);
 
 
   bfd_seek (abfd, 0, SEEK_SET);
 
-  if (bfd_bread ((void *) buf, 76, abfd) != 76)
+  if (bfd_bread ((void *) buf, sizeof buf, abfd) != sizeof buf)
     return -1;
 
   header->tag1 = bfd_getb32 (buf);
     return -1;
 
   header->tag1 = bfd_getb32 (buf);
@@ -1121,7 +1117,6 @@ bfd_pef_xlib_scan (bfd *abfd, bfd_pef_xlib_header *header)
 static const bfd_target *
 bfd_pef_xlib_object_p (bfd *abfd)
 {
 static const bfd_target *
 bfd_pef_xlib_object_p (bfd *abfd)
 {
-  struct bfd_preserve preserve;
   bfd_pef_xlib_header header;
 
   if (bfd_pef_xlib_read_header (abfd, &header) != 0)
   bfd_pef_xlib_header header;
 
   if (bfd_pef_xlib_read_header (abfd, &header) != 0)
@@ -1138,20 +1133,12 @@ bfd_pef_xlib_object_p (bfd *abfd)
       return NULL;
     }
 
       return NULL;
     }
 
-  if (! bfd_preserve_save (abfd, &preserve))
-    {
-      bfd_set_error (bfd_error_wrong_format);
-      return NULL;
-    }
-
   if (bfd_pef_xlib_scan (abfd, &header) != 0)
     {
   if (bfd_pef_xlib_scan (abfd, &header) != 0)
     {
-      bfd_preserve_restore (abfd, &preserve);
       bfd_set_error (bfd_error_wrong_format);
       return NULL;
     }
 
       bfd_set_error (bfd_error_wrong_format);
       return NULL;
     }
 
-  bfd_preserve_finish (abfd, &preserve);
   return abfd->xvec;
 }
 
   return abfd->xvec;
 }
 
@@ -1169,6 +1156,7 @@ const bfd_target pef_xlib_vec =
   0,                           /* Symbol_leading_char.  */
   ' ',                         /* AR_pad_char.  */
   16,                          /* AR_max_namelen.  */
   0,                           /* Symbol_leading_char.  */
   ' ',                         /* AR_pad_char.  */
   16,                          /* AR_max_namelen.  */
+  0,                           /* match priority.  */
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* Data.  */
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* Data.  */
This page took 0.026717 seconds and 4 git commands to generate.