X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gold%2Fdescriptors.cc;h=2016b7ff8661324df7db17ee7ef2cf08738b3f69;hb=9ec85a27138aefcd3fc35ddbd7727f384fe299b1;hp=3d059e2c222ed79a02157d282d9a2d70d4ddce55;hpb=7f055c204a4371154123a1816fbec9855ee60ad5;p=platform%2Fupstream%2Fbinutils.git diff --git a/gold/descriptors.cc b/gold/descriptors.cc index 3d059e2..2016b7f 100644 --- a/gold/descriptors.cc +++ b/gold/descriptors.cc @@ -1,6 +1,6 @@ // descriptors.cc -- manage file descriptors for gold -// Copyright 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008-2014 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -23,6 +23,7 @@ #include "gold.h" #include +#include #include #include #include @@ -31,16 +32,26 @@ #include "options.h" #include "gold-threads.h" #include "descriptors.h" +#include "binary-io.h" + +// O_CLOEXEC is only available on newer systems. +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif // Very old systems may not define FD_CLOEXEC. #ifndef FD_CLOEXEC #define FD_CLOEXEC 1 #endif -// O_CLOEXEC is only available on newer systems. -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 +static inline void +set_close_on_exec(int fd ATTRIBUTE_UNUSED) +{ +// Mingw does not define F_SETFD. +#ifdef F_SETFD + fcntl(fd, F_SETFD, FD_CLOEXEC); #endif +} namespace gold { @@ -98,6 +109,9 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode) // require callers to pass it. flags |= O_CLOEXEC; + // Always open the file as a binary file. + flags |= O_BINARY; + int new_descriptor = ::open(name, flags, mode); if (new_descriptor < 0 && errno != ENFILE @@ -108,8 +122,7 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode) { Hold_lock hl(*this->lock_); - gold_error(_("file %s was removed during the link"), - this->open_descriptors_[descriptor].name); + gold_error(_("file %s was removed during the link"), name); } errno = ENOENT; @@ -129,7 +142,7 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode) if (O_CLOEXEC == 0 && parameters->options_valid() && parameters->options().has_plugins()) - fcntl(new_descriptor, F_SETFD, FD_CLOEXEC); + set_close_on_exec(new_descriptor); { Hold_optional_lock hl(this->lock_); @@ -238,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;