public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl@lucon.org>
To: binutils@sources.redhat.com
Subject: Re: PATCH: PR binutils/5299: Duplicated sections for COFF/PE
Date: Mon, 12 Nov 2007 14:36:00 -0000	[thread overview]
Message-ID: <20071112143623.GA18601@lucon.org> (raw)
In-Reply-To: <20071112012136.GD13318@bubble.grove.modra.org>

On Mon, Nov 12, 2007 at 11:51:36AM +1030, Alan Modra wrote:
> On Sat, Nov 10, 2007 at 07:52:16AM -0800, H.J. Lu wrote:
> > 	PR binutils/5299
> > 	* peicode.h (pe_bfd_object_p): Save and restore previous
> > 	sections if needed.
> 
> You should use bfd_preserve_save/restore here, I think.
> 

Here is the updatd patch.


H.J.
----
2007-11-12  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/5299
	* peicode.h (pe_bfd_object_p): Save and restore previous bfd
	state when calling coff_object_p.

--- bfd/peicode.h.dup	2007-07-12 11:59:24.000000000 -0700
+++ bfd/peicode.h	2007-11-12 06:31:15.000000000 -0800
@@ -1263,6 +1263,7 @@ pe_bfd_object_p (bfd * abfd)
   struct external_PEI_IMAGE_hdr image_hdr;
   file_ptr offset;
   const bfd_target *target;
+  struct bfd_preserve preserve;
 
   /* Detect if this a Microsoft Import Library Format element.  */
   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
@@ -1327,6 +1328,10 @@ pe_bfd_object_p (bfd * abfd)
       return NULL;
     }
 
+  preserve.marker = NULL;
+  if (! bfd_preserve_save (abfd, &preserve))
+    return NULL;
+
   target = coff_object_p (abfd);
   if (target)
     {
@@ -1344,7 +1349,10 @@ pe_bfd_object_p (bfd * abfd)
 
       /* Don't check PE vs. EFI if arch is unknown.  */
       if (arch == arch_type_unknown)
-	return target;
+	{
+	  bfd_preserve_finish (abfd, &preserve);
+	  return target;
+	}
 
       for (target_ptr = bfd_target_vector; *target_ptr != NULL;
 	   target_ptr++)
@@ -1361,8 +1369,10 @@ pe_bfd_object_p (bfd * abfd)
 
 	      if (efi)
 		{
+no_match:
 		  /* TARGET_PTR is an EFI backend.  Don't match
 		     TARGET with a EFI file.  */
+		  bfd_preserve_restore (abfd, &preserve);
 		  bfd_set_error (bfd_error_wrong_format);
 		  return NULL;
 		}
@@ -1377,12 +1387,15 @@ pe_bfd_object_p (bfd * abfd)
 		{
 		  /* TARGET_PTR is a PE backend.  Don't match
 		     TARGET with a PE file.  */
-		  bfd_set_error (bfd_error_wrong_format);
-		  return NULL;
+		  goto no_match;
 		}
 	    }
 	}
+
+      bfd_preserve_finish (abfd, &preserve);
     }
+  else
+    bfd_preserve_restore (abfd, &preserve);
 
   return target;
 }

  reply	other threads:[~2007-11-12 14:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-10 15:52 H.J. Lu
2007-11-12  1:21 ` Alan Modra
2007-11-12 14:36   ` H.J. Lu [this message]
2007-11-12 21:30     ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071112143623.GA18601@lucon.org \
    --to=hjl@lucon.org \
    --cc=binutils@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).