Index: test/MinGW/driver.test =================================================================== --- test/MinGW/driver.test +++ test/MinGW/driver.test @@ -4,6 +4,9 @@ X86-SAME: -alternatename:__image_base__=___ImageBase X86-SAME: foo.o +RUN: echo "-flavor gnu -### foo.o -m i386pe" > %t.rsp +RUN: 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 Index: tools/lld/lld.cpp =================================================================== --- tools/lld/lld.cpp +++ tools/lld/lld.cpp @@ -26,9 +26,12 @@ //===----------------------------------------------------------------------===// #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/Twine.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/Path.h" #include @@ -59,7 +62,7 @@ .Default(Invalid); } -static bool isPETarget(const std::vector &V) { +static bool isPETarget(const SmallVector &V) { for (auto It = V.begin(); It + 1 != V.end(); ++It) { if (StringRef(*It) != "-m") continue; @@ -91,7 +94,7 @@ return Invalid; } -static Flavor parseFlavor(std::vector &V) { +static Flavor parseFlavor(SmallVector &V) { // Parse -flavor option. if (V.size() > 1 && V[1] == StringRef("-flavor")) { if (V.size() <= 2) @@ -124,10 +127,17 @@ InitLLVM X(Argc, Argv); std::vector Args(Argv, Argv + Argc); - switch (parseFlavor(Args)) { + // Expand response files (arguments in the form of @) + // to allow deducing the flavor or PE -m argument from arguments in them. + SmallVector ExpandedArgs(Args.data(), + Args.data() + Args.size()); + // The exact kind of quoting/escaping used should hopefully not matter + // for deducing the flavor and -m argument. + cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, ExpandedArgs); + switch (parseFlavor(ExpandedArgs)) { case Gnu: - if (isPETarget(Args)) - return !mingw::link(Args); + if (isPETarget(ExpandedArgs)) + return !mingw::link(ExpandedArgs); return !elf::link(Args, canExitEarly()); case WinLink: return !coff::link(Args, canExitEarly());