Support non-regular output files.

This patch enables something like "-o /dev/null".
Previouly, it failed because such files cannot be renamed.

Differential Revision: https://reviews.llvm.org/D28010

llvm-svn: 291496
This commit is contained in:
Rui Ueyama 2017-01-09 23:07:05 +00:00
parent 8c5c7ffb8d
commit 817c9d66f0
2 changed files with 7 additions and 4 deletions

View File

@ -1635,10 +1635,12 @@ static void unlinkAsync(StringRef Path) {
// Path as a new file. If we do that in a different thread, the new
// thread can remove the new file.
SmallString<128> TempPath;
if (auto EC = sys::fs::createUniqueFile(Path + "tmp%%%%%%%%", TempPath))
fatal(EC, "createUniqueFile failed");
if (auto EC = sys::fs::rename(Path, TempPath))
fatal(EC, "rename failed");
if (sys::fs::createUniqueFile(Path + "tmp%%%%%%%%", TempPath))
return;
if (sys::fs::rename(Path, TempPath)) {
sys::fs::remove(TempPath);
return;
}
// Remove TempPath in background.
std::thread([=] { ::remove(TempPath.str().str().c_str()); }).detach();

View File

@ -4,6 +4,7 @@
# RUN: ld.lld %t -o %t2
# RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \
# RUN: | FileCheck %s
# RUN: ld.lld %t -o /dev/null
# exits with return code 42 on linux
.globl _start