Index: src/ld/ldmain.c =================================================================== --- src.orig/ld/ldmain.c 2011-02-10 09:47:59.000000000 +0100 +++ src/ld/ldmain.c 2011-02-14 10:13:39.624526400 +0100 @@ -173,13 +173,22 @@ static struct bfd_link_callbacks link_ca struct bfd_link_info link_info; +void +ld_close_bfds (void) +{ + if (link_info.output_bfd) + bfd_cache_close (link_info.output_bfd); + link_info.output_bfd = NULL; + bfd_cache_close_all (); +} + static void remove_output (void) { + ld_close_bfds (); + if (output_filename) { - if (link_info.output_bfd) - bfd_cache_close (link_info.output_bfd); if (delete_output_file_on_failure) unlink_if_ordinary (output_filename); } Index: src/ld/ldmain.h =================================================================== --- src.orig/ld/ldmain.h 2009-12-14 10:33:59.000000000 +0100 +++ src/ld/ldmain.h 2011-02-14 10:14:04.499526400 +0100 @@ -45,5 +45,6 @@ extern int overflow_cutoff_limit; extern void add_ysym (const char *); extern void add_wrap (const char *); extern void add_keepsyms_file (const char *); +extern void ld_close_bfds (void); #endif Index: src/ld/plugin.c =================================================================== --- src.orig/ld/plugin.c 2011-02-10 09:47:59.000000000 +0100 +++ src/ld/plugin.c 2011-02-14 10:15:38.608901400 +0100 @@ -824,6 +824,10 @@ static void plugin_call_cleanup (void) { plugin_t *curplug = plugins_list; + + /* Close all BFDs, so that unlink can operate on all targets. */ + ld_close_bfds (); + while (curplug) { if (curplug->cleanup_handler && !curplug->cleanup_done)