Skip to content

Commit 817c9d6

Browse files
committed
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
1 parent 8c5c7ff commit 817c9d6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lld/ELF/Writer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,12 @@ static void unlinkAsync(StringRef Path) {
16351635
// Path as a new file. If we do that in a different thread, the new
16361636
// thread can remove the new file.
16371637
SmallString<128> TempPath;
1638-
if (auto EC = sys::fs::createUniqueFile(Path + "tmp%%%%%%%%", TempPath))
1639-
fatal(EC, "createUniqueFile failed");
1640-
if (auto EC = sys::fs::rename(Path, TempPath))
1641-
fatal(EC, "rename failed");
1638+
if (sys::fs::createUniqueFile(Path + "tmp%%%%%%%%", TempPath))
1639+
return;
1640+
if (sys::fs::rename(Path, TempPath)) {
1641+
sys::fs::remove(TempPath);
1642+
return;
1643+
}
16421644

16431645
// Remove TempPath in background.
16441646
std::thread([=] { ::remove(TempPath.str().str().c_str()); }).detach();

lld/test/ELF/basic.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# RUN: ld.lld %t -o %t2
55
# RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \
66
# RUN: | FileCheck %s
7+
# RUN: ld.lld %t -o /dev/null
78

89
# exits with return code 42 on linux
910
.globl _start

0 commit comments

Comments
 (0)