Index: descriptors.cc =================================================================== RCS file: /cvs/src/src/gold/descriptors.cc,v retrieving revision 1.11 diff -u -p -r1.11 descriptors.cc --- descriptors.cc 1 Nov 2012 22:43:26 -0000 1.11 +++ descriptors.cc 9 Feb 2013 01:55:40 -0000 @@ -251,6 +251,28 @@ Descriptors::close_some_descriptor() return false; } +// Close all the descriptors open for reading. + +void +Descriptors::close_all() +{ + Hold_optional_lock hl(this->lock_); + + for (size_t i = 0; i < this->open_descriptors_.size(); i++) + { + Open_descriptor* pod = &this->open_descriptors_[i]; + if (pod->name != NULL && !pod->inuse && !pod->is_write) + { + if (::close(i) < 0) + gold_warning(_("while closing %s: %s"), pod->name, strerror(errno)); + pod->name = NULL; + pod->stack_next = -1; + pod->is_on_stack = false; + } + } + this->stack_top_ = -1; +} + // The single global variable which manages descriptors. Descriptors descriptors; Index: descriptors.h =================================================================== RCS file: /cvs/src/src/gold/descriptors.h,v retrieving revision 1.5 diff -u -p -r1.5 descriptors.h --- descriptors.h 24 Mar 2009 04:50:32 -0000 1.5 +++ descriptors.h 9 Feb 2013 01:55:40 -0000 @@ -1,6 +1,6 @@ // descriptors.h -- manage file descriptors for gold -*- C++ -*- -// Copyright 2008, 2009 Free Software Foundation, Inc. +// Copyright 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -56,6 +56,10 @@ class Descriptors void release(int descriptor, bool permanent); + // Close all the descriptors open for reading. + void + close_all(); + private: // Information kept for a descriptor. struct Open_descriptor @@ -104,6 +108,10 @@ inline void release_descriptor(int descriptor, bool permanent) { descriptors.release(descriptor, permanent); } +inline void +close_all_descriptors() +{ descriptors.close_all(); } + } // End namespace gold. #endif // !defined(GOLD_DESCRIPTORS_H) Index: plugin.cc =================================================================== RCS file: /cvs/src/src/gold/plugin.cc,v retrieving revision 1.56 diff -u -p -r1.56 plugin.cc --- plugin.cc 11 Jan 2013 14:36:36 -0000 1.56 +++ plugin.cc 9 Feb 2013 01:55:40 -0000 @@ -71,6 +71,7 @@ dlerror(void) #include "target.h" #include "readsyms.h" #include "symtab.h" +#include "descriptors.h" #include "elfcpp.h" namespace gold @@ -697,6 +698,14 @@ Plugin_manager::layout_deferred_objects( void Plugin_manager::cleanup() { + if (this->any_added_) + { + // If any input files were added, close all the input files. + // This is because the plugin may want to remove them, and on + // Windows you are not allowed to remove an open file. + close_all_descriptors(); + } + for (this->current_ = this->plugins_.begin(); this->current_ != this->plugins_.end(); ++this->current_)