[PATCH] D110904: [lld-macho] Check for errors when the response file doesn't exist.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 21:57:11 PDT 2021


oontvoo created this revision.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110904

Files:
  lld/MachO/DriverUtils.cpp
  lld/test/MachO/reproduce.s


Index: lld/test/MachO/reproduce.s
===================================================================
--- lld/test/MachO/reproduce.s
+++ lld/test/MachO/reproduce.s
@@ -53,6 +53,11 @@
 
 # RUN: cd repro2; ld64.lld @response.txt
 
+## Error case
+# RUN: mkdir -p %t.dir/errors && cd $t.dir/errors && rm -rf foo.txt
+# RUN: not %lld @foo.txt 2>&1 | FileCheck %s --check-prefix=NOFILE
+# NOFILE: error: Error expanding response file: No such file or directory
+
 .globl _main
 _main:
   ret
Index: lld/MachO/DriverUtils.cpp
===================================================================
--- lld/MachO/DriverUtils.cpp
+++ lld/MachO/DriverUtils.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TextAPI/InterfaceFile.h"
 #include "llvm/TextAPI/TextAPIReader.h"
 
@@ -82,7 +83,15 @@
 
   // Expand response files (arguments in the form of @<filename>)
   // and then parse the argument again.
-  cl::ExpandResponseFiles(saver, cl::TokenizeGNUCommandLine, vec);
+  if (llvm::Error Err = cl::ExpandResponseFilesWithError(
+          saver, cl::TokenizeGNUCommandLine, vec,
+          /*MarkEOLs=*/false,
+          /*RelativeNames=*/false,
+          /*CurrentDir=*/llvm::None, *llvm::vfs::getRealFileSystem()))
+    handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
+      error("Error expanding response file: " + Twine(EIB.message()));
+    });
+
   InputArgList args = ParseArgs(vec, missingIndex, missingCount);
 
   // Handle -fatal_warnings early since it converts missing argument warnings


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110904.376423.patch
Type: text/x-patch
Size: 1644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211001/939fdcc0/attachment.bin>


More information about the llvm-commits mailing list