Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb12396

Browse files
committedJun 10, 2019
[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 llvm-svn: 362977
1 parent 78c0d75 commit bb12396

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed
 

‎lld/MinGW/Driver.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030

3131
#include "lld/Common/Driver.h"
3232
#include "lld/Common/ErrorHandler.h"
33+
#include "lld/Common/Memory.h"
3334
#include "lld/Common/Version.h"
3435
#include "llvm/ADT/ArrayRef.h"
3536
#include "llvm/ADT/Optional.h"
3637
#include "llvm/ADT/StringExtras.h"
3738
#include "llvm/ADT/StringRef.h"
39+
#include "llvm/ADT/Triple.h"
3840
#include "llvm/Option/Arg.h"
3941
#include "llvm/Option/ArgList.h"
4042
#include "llvm/Option/Option.h"
@@ -86,11 +88,18 @@ static void printHelp(const char *Argv0) {
8688
outs() << "\n";
8789
}
8890

91+
static cl::TokenizerCallback getQuotingStyle() {
92+
if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
93+
return cl::TokenizeWindowsCommandLine;
94+
return cl::TokenizeGNUCommandLine;
95+
}
96+
8997
opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> Argv) {
9098
unsigned MissingIndex;
9199
unsigned MissingCount;
92100

93101
SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
102+
cl::ExpandResponseFiles(Saver, getQuotingStyle(), Vec);
94103
opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);
95104

96105
if (MissingCount)

‎lld/test/MinGW/driver.test

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ X86-SAME: -machine:x86
44
X86-SAME: -alternatename:__image_base__=___ImageBase
55
X86-SAME: foo.o
66

7+
RUN: echo "-### foo.o -m i386pe" > %t.rsp
8+
RUN: ld.lld @%t.rsp | FileCheck -check-prefix=X86 %s
9+
710
RUN: ld.lld -### foo.o -m i386pep | FileCheck -check-prefix=X64 %s
811
X64: -out:a.exe
912
X64-SAME: -machine:x64

‎lld/tools/lld/lld.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
//===----------------------------------------------------------------------===//
2727

2828
#include "lld/Common/Driver.h"
29+
#include "lld/Common/Memory.h"
2930
#include "llvm/ADT/STLExtras.h"
31+
#include "llvm/ADT/SmallVector.h"
3032
#include "llvm/ADT/StringSwitch.h"
33+
#include "llvm/ADT/Triple.h"
3134
#include "llvm/ADT/Twine.h"
35+
#include "llvm/Support/CommandLine.h"
3236
#include "llvm/Support/InitLLVM.h"
3337
#include "llvm/Support/Path.h"
3438
#include <cstdlib>
@@ -59,12 +63,30 @@ static Flavor getFlavor(StringRef S) {
5963
.Default(Invalid);
6064
}
6165

62-
static bool isPETarget(const std::vector<const char *> &V) {
66+
static cl::TokenizerCallback getDefaultQuotingStyle() {
67+
if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
68+
return cl::TokenizeWindowsCommandLine;
69+
return cl::TokenizeGNUCommandLine;
70+
}
71+
72+
static bool isPETargetName(StringRef S) {
73+
return S == "i386pe" || S == "i386pep" || S == "thumb2pe" || S == "arm64pe";
74+
}
75+
76+
static bool isPETarget(std::vector<const char *> &V) {
6377
for (auto It = V.begin(); It + 1 != V.end(); ++It) {
6478
if (StringRef(*It) != "-m")
6579
continue;
66-
StringRef S = *(It + 1);
67-
return S == "i386pe" || S == "i386pep" || S == "thumb2pe" || S == "arm64pe";
80+
return isPETargetName(*(It + 1));
81+
}
82+
// Expand response files (arguments in the form of @<filename>)
83+
// to allow detecting the -m argument from arguments in them.
84+
SmallVector<const char *, 256> ExpandedArgs(V.data(), V.data() + V.size());
85+
cl::ExpandResponseFiles(Saver, getDefaultQuotingStyle(), ExpandedArgs);
86+
for (auto It = ExpandedArgs.begin(); It + 1 != ExpandedArgs.end(); ++It) {
87+
if (StringRef(*It) != "-m")
88+
continue;
89+
return isPETargetName(*(It + 1));
6890
}
6991
return false;
7092
}

0 commit comments

Comments
 (0)
Failed to load comments.