[lld] 19a7939 - [lld] Check errors from expanding response files

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 09:28:59 PST 2022


Author: Hans Wennborg
Date: 2022-11-07T18:28:33+01:00
New Revision: 19a7939404a3b932c26cd2a6a29f0669acebd702

URL: https://github.com/llvm/llvm-project/commit/19a7939404a3b932c26cd2a6a29f0669acebd702
DIFF: https://github.com/llvm/llvm-project/commit/19a7939404a3b932c26cd2a6a29f0669acebd702.diff

LOG: [lld] Check errors from expanding response files

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
introduced a bug that made lld print errors for response files which
contained "-rpath @foo".

Differental revision: https://reviews.llvm.org/D137477

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/basic.s b/lld/test/ELF/basic.s
index 33c01944b7c1b..587fd1641500a 100644
--- a/lld/test/ELF/basic.s
+++ b/lld/test/ELF/basic.s
@@ -218,6 +218,12 @@ _start:
 # 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]]

diff  --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp
index b0e28d15fa29e..700c0b770e201 100644
--- a/lld/tools/lld/lld.cpp
+++ b/lld/tools/lld/lld.cpp
@@ -89,7 +89,9 @@ static bool isPETarget(std::vector<const char *> &v) {
   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;


        


More information about the llvm-commits mailing list