Skip to content

Commit

Permalink
[lld] Check errors from expanding response files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zmodem committed Nov 7, 2022
1 parent 265a730 commit 19a7939
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lld/test/ELF/basic.s
Expand Up @@ -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]]
Expand Down
4 changes: 3 additions & 1 deletion lld/tools/lld/lld.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 19a7939

Please sign in to comment.