public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: Check archive only for archive member
@ 2021-07-06 13:31 H.J. Lu
  2021-07-07 14:40 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2021-07-06 13:31 UTC (permalink / raw)
  To: binutils

Since plugin_maybe_claim calls bfd_close on the original input BFD if it
isn't an archive member, pass NULL to bfd_plugin_close_file_descriptor
to indicate that the BFD isn't an archive member.

bfd/

	PR ld/18028
	* plugin.c (bfd_plugin_close_file_descriptor): Check archive
	only of abfd != NULL.
	(try_claim): Pass NULL to bfd_plugin_close_file_descriptor if
	it isn't an archive member.

ld/

	PR ld/18028
	* plugin.c (plugin_input_file): Add comments for abfd and ibfd.
	(plugin_object_p): Set input->ibfd to NULL if it isn't an
	archive member.
---
 bfd/plugin.c | 25 +++++++++++++------------
 ld/plugin.c  |  4 +++-
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/bfd/plugin.c b/bfd/plugin.c
index b3d6739dabb..6cfa2b66470 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -277,27 +277,26 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
   return 1;
 }
 
-/* Close the plugin file descriptor.  */
+/* Close the plugin file descriptor FD.  If ABFD isn't NULL, it is an
+   archive member.   */
 
 void
 bfd_plugin_close_file_descriptor (bfd *abfd, int fd)
 {
-  bfd *iobfd;
-
-  iobfd = abfd;
-  while (iobfd->my_archive
-	 && !bfd_is_thin_archive (iobfd->my_archive))
-    iobfd = iobfd->my_archive;
-  if (iobfd == abfd)
+  if (abfd == NULL)
     close (fd);
   else
     {
-      iobfd->archive_plugin_fd_open_count--;
+      while (abfd->my_archive
+	     && !bfd_is_thin_archive (abfd->my_archive))
+	abfd = abfd->my_archive;
+
+      abfd->archive_plugin_fd_open_count--;
       /* Dup the archive plugin file descriptor for later use, which
 	 will be closed by _bfd_archive_close_and_cleanup.  */
-      if (iobfd->archive_plugin_fd_open_count == 0)
+      if (abfd->archive_plugin_fd_open_count == 0)
 	{
-	  iobfd->archive_plugin_fd = dup (fd);
+	  abfd->archive_plugin_fd = dup (fd);
 	  close (fd);
 	}
     }
@@ -314,7 +313,9 @@ try_claim (bfd *abfd)
       && current_plugin->claim_file)
     {
       current_plugin->claim_file (&file, &claimed);
-      bfd_plugin_close_file_descriptor (abfd, file.fd);
+      bfd_plugin_close_file_descriptor ((abfd->my_archive != NULL
+					 ? abfd : NULL),
+					file.fd);
     }
 
   return claimed;
diff --git a/ld/plugin.c b/ld/plugin.c
index bb369f46955..b91a958b812 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -102,7 +102,9 @@ typedef struct view_buffer
    pointer.  */
 typedef struct plugin_input_file
 {
+  /* The dummy BFD.  */
   bfd *abfd;
+  /* The original input BFD.  Non-NULL if it is an archive member.  */
   bfd *ibfd;
   view_buffer_t view_buffer;
   char *name;
@@ -1220,7 +1222,7 @@ plugin_object_p (bfd *ibfd)
 
   file.handle = input;
   input->abfd = abfd;
-  input->ibfd = ibfd;
+  input->ibfd = ibfd->my_archive != NULL ? ibfd : NULL;
   input->view_buffer.addr = NULL;
   input->view_buffer.filesize = 0;
   input->view_buffer.offset = 0;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ld: Check archive only for archive member
  2021-07-06 13:31 [PATCH] ld: Check archive only for archive member H.J. Lu
@ 2021-07-07 14:40 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2021-07-07 14:40 UTC (permalink / raw)
  To: H.J. Lu, binutils

Hi H.J.

> bfd/
> 
> 	PR ld/18028
> 	* plugin.c (bfd_plugin_close_file_descriptor): Check archive
> 	only of abfd != NULL.
> 	(try_claim): Pass NULL to bfd_plugin_close_file_descriptor if
> 	it isn't an archive member.
> 
> ld/
> 
> 	PR ld/18028
> 	* plugin.c (plugin_input_file): Add comments for abfd and ibfd.
> 	(plugin_object_p): Set input->ibfd to NULL if it isn't an
> 	archive member.

Approved - please apply to the branch and mainline.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-07 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 13:31 [PATCH] ld: Check archive only for archive member H.J. Lu
2021-07-07 14:40 ` Nick Clifton

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).