Commit 817c9d66 authored by Rui Ueyama's avatar Rui Ueyama
Browse files

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
parent 8c5c7ffb
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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();
+1 −0
Original line number Diff line number Diff line
@@ -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