public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch ld]: Close BFDs before linker-plugin's atexit routine is called
@ 2011-02-09 18:52 Kai Tietz
  2011-02-13 10:40 ` Kai Tietz
  2011-02-13 23:25 ` Alan Modra
  0 siblings, 2 replies; 7+ messages in thread
From: Kai Tietz @ 2011-02-09 18:52 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]

Hello,

This is patch addresses the unlink call when lto linker-plugin is
used.  As windows
native doesn't support to unlink still opened files, it fails to do so
as file-descriptors
of bfds aren't closed before atexit routine of plugin gets called.

2011-02-09  Kai Tietz

	* ldmain.c (remove_output): Set output_bfd
	of link_info to nil and close all cached bfds.
	(main): Close output_bfd of link_info and set
	it to nil. Additionally close all cached bfds.

Tested on x86_64-pc-linux-gnu and x86_64-w64-mingw32. Ok for apply?

Regards,
Kai

[-- Attachment #2: ld_release_bfd.txt --]
[-- Type: text/plain, Size: 1118 bytes --]

Index: src/ld/ldmain.c
===================================================================
--- src.orig/ld/ldmain.c	2011-01-18 19:49:25.000000000 +0100
+++ src/ld/ldmain.c	2011-02-09 18:49:38.148905600 +0100
@@ -180,6 +180,8 @@ remove_output (void)
     {
       if (link_info.output_bfd)
 	bfd_cache_close (link_info.output_bfd);
+      link_info.output_bfd = NULL;
+      bfd_cache_close_all ();
       if (delete_output_file_on_failure)
 	unlink_if_ordinary (output_filename);
     }
@@ -489,6 +491,10 @@ main (int argc, char **argv)
 	       output_filename);
 
       /* The file will be removed by remove_output.  */
+      if (link_info.output_bfd)
+	bfd_cache_close (link_info.output_bfd);
+      link_info.output_bfd = NULL;
+      bfd_cache_close_all ();
       xexit (1);
     }
   else
@@ -564,6 +570,10 @@ main (int argc, char **argv)
   /* Prevent remove_output from doing anything, after a successful link.  */
   output_filename = NULL;
 
+  if (link_info.output_bfd)
+    bfd_cache_close (link_info.output_bfd);
+  link_info.output_bfd = NULL;
+  bfd_cache_close_all ();
   xexit (0);
   return 0;
 }

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

end of thread, other threads:[~2011-02-14 10:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09 18:52 [patch ld]: Close BFDs before linker-plugin's atexit routine is called Kai Tietz
2011-02-13 10:40 ` Kai Tietz
2011-02-13 23:25 ` Alan Modra
2011-02-14  6:45   ` Kai Tietz
2011-02-14  9:22     ` Kai Tietz
2011-02-14  9:51       ` Alan Modra
2011-02-14 10:01         ` Kai Tietz

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