[lld] r362977 - [Driver] Look for -m in response files as well
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 13:10:10 PDT 2019
Author: mstorsjo
Date: Mon Jun 10 13:10:10 2019
New Revision: 362977
URL: http://llvm.org/viewvc/llvm-project?rev=362977&view=rev
Log:
[Driver] Look for -m in response files as well
Also expand response files in the MinGW driver.
This should fix PR42135.
Differential Revision: https://reviews.llvm.org/D63024
Modified:
lld/trunk/MinGW/Driver.cpp
lld/trunk/test/MinGW/driver.test
lld/trunk/tools/lld/lld.cpp
Modified: lld/trunk/MinGW/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Driver.cpp?rev=362977&r1=362976&r2=362977&view=diff
==============================================================================
--- lld/trunk/MinGW/Driver.cpp (original)
+++ lld/trunk/MinGW/Driver.cpp Mon Jun 10 13:10:10 2019
@@ -30,11 +30,13 @@
#include "lld/Common/Driver.h"
#include "lld/Common/ErrorHandler.h"
+#include "lld/Common/Memory.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
@@ -86,11 +88,18 @@ static void printHelp(const char *Argv0)
outs() << "\n";
}
+static cl::TokenizerCallback getQuotingStyle() {
+ if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
+ return cl::TokenizeWindowsCommandLine;
+ return cl::TokenizeGNUCommandLine;
+}
+
opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> Argv) {
unsigned MissingIndex;
unsigned MissingCount;
SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
+ cl::ExpandResponseFiles(Saver, getQuotingStyle(), Vec);
opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);
if (MissingCount)
Modified: lld/trunk/test/MinGW/driver.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/MinGW/driver.test?rev=362977&r1=362976&r2=362977&view=diff
==============================================================================
--- lld/trunk/test/MinGW/driver.test (original)
+++ lld/trunk/test/MinGW/driver.test Mon Jun 10 13:10:10 2019
@@ -4,6 +4,9 @@ X86-SAME: -machine:x86
X86-SAME: -alternatename:__image_base__=___ImageBase
X86-SAME: foo.o
+RUN: echo "-### foo.o -m i386pe" > %t.rsp
+RUN: ld.lld @%t.rsp | FileCheck -check-prefix=X86 %s
+
RUN: ld.lld -### foo.o -m i386pep | FileCheck -check-prefix=X64 %s
X64: -out:a.exe
X64-SAME: -machine:x64
Modified: lld/trunk/tools/lld/lld.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld/lld.cpp?rev=362977&r1=362976&r2=362977&view=diff
==============================================================================
--- lld/trunk/tools/lld/lld.cpp (original)
+++ lld/trunk/tools/lld/lld.cpp Mon Jun 10 13:10:10 2019
@@ -26,9 +26,13 @@
//===----------------------------------------------------------------------===//
#include "lld/Common/Driver.h"
+#include "lld/Common/Memory.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include <cstdlib>
@@ -59,12 +63,30 @@ static Flavor getFlavor(StringRef S) {
.Default(Invalid);
}
-static bool isPETarget(const std::vector<const char *> &V) {
+static cl::TokenizerCallback getDefaultQuotingStyle() {
+ if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
+ return cl::TokenizeWindowsCommandLine;
+ return cl::TokenizeGNUCommandLine;
+}
+
+static bool isPETargetName(StringRef S) {
+ return S == "i386pe" || S == "i386pep" || S == "thumb2pe" || S == "arm64pe";
+}
+
+static bool isPETarget(std::vector<const char *> &V) {
for (auto It = V.begin(); It + 1 != V.end(); ++It) {
if (StringRef(*It) != "-m")
continue;
- StringRef S = *(It + 1);
- return S == "i386pe" || S == "i386pep" || S == "thumb2pe" || S == "arm64pe";
+ return isPETargetName(*(It + 1));
+ }
+ // Expand response files (arguments in the form of @<filename>)
+ // to allow detecting the -m argument from arguments in them.
+ SmallVector<const char *, 256> ExpandedArgs(V.data(), V.data() + V.size());
+ cl::ExpandResponseFiles(Saver, getDefaultQuotingStyle(), ExpandedArgs);
+ for (auto It = ExpandedArgs.begin(); It + 1 != ExpandedArgs.end(); ++It) {
+ if (StringRef(*It) != "-m")
+ continue;
+ return isPETargetName(*(It + 1));
}
return false;
}
More information about the llvm-commits
mailing list