Make LLD work even if the current directory is not writable.
authorRui Ueyama <ruiu@google.com>
Wed, 26 Apr 2017 16:15:07 +0000 (16:15 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 26 Apr 2017 16:15:07 +0000 (16:15 +0000)
llvm-svn: 301423

lld/ELF/Filesystem.cpp
lld/test/ELF/driver-access.test [new file with mode: 0644]

index 0b9cea9..b63d521 100644 (file)
@@ -70,5 +70,7 @@ void elf::unlinkAsync(StringRef Path) {
 // is called. We use that class without calling commit() to predict
 // if the given file is writable.
 std::error_code elf::tryCreateFile(StringRef Path) {
+  if (Path.empty())
+    return std::error_code();
   return FileOutputBuffer::create(Path, 1).getError();
 }
diff --git a/lld/test/ELF/driver-access.test b/lld/test/ELF/driver-access.test
new file mode 100644 (file)
index 0000000..3c976a6
--- /dev/null
@@ -0,0 +1,14 @@
+# REQUIRES: x86, shell
+# Make sure that LLD works even if the current directory is not writable.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe
+
+# RUN: mkdir -p %t.dir
+# RUN: chmod 100 %t.dir
+# RUN: cd %t.dir
+# RUN: ld.lld %t.o -o %t.exe
+
+.globl _start
+_start:
+  nop