[PATCH] bfd: Close the thin archive file descriptor

H.J. Lu hjl.tools@gmail.com
Mon Jul 26 13:21:31 GMT 2021


Close the thin archive file descriptor since it can't be used directly
to access archive members.  This avoids running out of file descriptors
on thin archives with many archive members.

	PR ld/28138
	* plugin.c (bfd_plugin_close_file_descriptor): Close the thin
	archive file descriptor.
---
 bfd/plugin.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bfd/plugin.c b/bfd/plugin.c
index 6cfa2b66470..066c96581a2 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -291,6 +291,14 @@ bfd_plugin_close_file_descriptor (bfd *abfd, int fd)
 	     && !bfd_is_thin_archive (abfd->my_archive))
 	abfd = abfd->my_archive;
 
+      /* Close the thin archive file descriptor since it can't be used
+         directly to access archive members.  */
+      if (abfd->my_archive && bfd_is_thin_archive (abfd->my_archive))
+	{
+	  close (fd);
+	  return;
+	}
+
       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.  */
-- 
2.31.1



More information about the Binutils mailing list