[PATCH] D137477: [lld] Check errors from expanding response files

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 20:47:09 PDT 2022


hans created this revision.
hans added reviewers: thakis, sepavloff.
Herald added a subscriber: emaste.
Herald added a project: All.
hans requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.

Previously the response file expansion code would print the error, but lld would not exit, which was odd.

lld does response file expansion in the different drivers, but it's also done in main() first, so it's enough to check there.

By checking for these errors we would have caught when D136090 <https://reviews.llvm.org/D136090> introduced a bug that made lld print errors for response files which contained "-rpath @foo".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137477

Files:
  lld/test/ELF/basic.s
  lld/tools/lld/lld.cpp


Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -89,7 +89,9 @@
   SmallVector<const char *, 256> expandedArgs(v.data(), v.data() + v.size());
   BumpPtrAllocator a;
   StringSaver saver(a);
-  cl::ExpandResponseFiles(saver, getDefaultQuotingStyle(), expandedArgs);
+  cl::ExpansionContext ECtx(saver.getAllocator(), getDefaultQuotingStyle());
+  if (Error Err = ECtx.expandResponseFiles(expandedArgs))
+    die(toString(std::move(Err)));
   for (auto it = expandedArgs.begin(); it + 1 != expandedArgs.end(); ++it) {
     if (StringRef(*it) != "-m")
       continue;
Index: lld/test/ELF/basic.s
===================================================================
--- lld/test/ELF/basic.s
+++ lld/test/ELF/basic.s
@@ -218,6 +218,12 @@
 # RUN:   --check-prefix=INVRSP
 # INVRSP: invalid response file quoting: patatino
 
+# Test erroring on a recursive response file, but only once.
+# RUN: echo @%t.responsefile > %t.responsefile
+# RUN: not ld.lld %t @%t.responsefile 2>&1 | FileCheck %s --check-prefix=RECRSP
+# RECRSP: recursive expansion of: '{{.*}}.responsefile'
+# RECRSP-NOT: recursive expansion of
+
 # RUN: not ld.lld %t.foo -o /dev/null 2>&1 | \
 # RUN:  FileCheck -DMSG=%errc_ENOENT --check-prefix=MISSING %s
 # MISSING: cannot open {{.*}}.foo: [[MSG]]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137477.473393.patch
Type: text/x-patch
Size: 1366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221105/0a75861c/attachment.bin>


More information about the llvm-commits mailing list