|
26 | 26 | //===----------------------------------------------------------------------===//
|
27 | 27 |
|
28 | 28 | #include "lld/Common/Driver.h"
|
| 29 | +#include "lld/Common/Memory.h" |
29 | 30 | #include "llvm/ADT/STLExtras.h"
|
| 31 | +#include "llvm/ADT/SmallVector.h" |
30 | 32 | #include "llvm/ADT/StringSwitch.h"
|
| 33 | +#include "llvm/ADT/Triple.h" |
31 | 34 | #include "llvm/ADT/Twine.h"
|
| 35 | +#include "llvm/Support/CommandLine.h" |
32 | 36 | #include "llvm/Support/InitLLVM.h"
|
33 | 37 | #include "llvm/Support/Path.h"
|
34 | 38 | #include <cstdlib>
|
@@ -59,12 +63,30 @@ static Flavor getFlavor(StringRef S) {
|
59 | 63 | .Default(Invalid);
|
60 | 64 | }
|
61 | 65 |
|
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) { |
63 | 77 | for (auto It = V.begin(); It + 1 != V.end(); ++It) {
|
64 | 78 | if (StringRef(*It) != "-m")
|
65 | 79 | 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)); |
68 | 90 | }
|
69 | 91 | return false;
|
70 | 92 | }
|
|
0 commit comments