Don't open the file again in the gold plugin. To be able to do this, update

MemoryBuffer::getOpenFile to not close the file descriptor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125128 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2011-02-08 22:40:47 +00:00
parent 971b83b67a
commit b4cc031a3e
8 changed files with 58 additions and 21 deletions

View File

@ -179,14 +179,6 @@ public:
sys::Path::UnMapFilePages(getBufferStart(), getBufferSize());
}
};
/// FileCloser - RAII object to make sure an FD gets closed properly.
class FileCloser {
int FD;
public:
explicit FileCloser(int FD) : FD(FD) {}
~FileCloser() { ::close(FD); }
};
}
error_code MemoryBuffer::getFile(StringRef Filename,
@ -208,15 +200,14 @@ error_code MemoryBuffer::getFile(const char *Filename,
if (FD == -1) {
return error_code(errno, posix_category());
}
return getOpenFile(FD, Filename, result, FileSize);
error_code ret = getOpenFile(FD, Filename, result, FileSize);
close(FD);
return ret;
}
error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
OwningPtr<MemoryBuffer> &result,
int64_t FileSize) {
FileCloser FC(FD); // Close FD on return.
// If we don't know the file size, use fstat to find out. fstat on an open
// file descriptor is cheaper than stat on a random path.
if (FileSize == -1) {