[PATCH] D63024: [LLD] [Driver] Look for -flavor/-m in response files as well

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 12:59:42 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk.
Herald added a project: LLVM.

This should fix PR42135.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D63024

Files:
  test/MinGW/driver.test
  tools/lld/lld.cpp


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 <cstdlib>
@@ -59,7 +62,7 @@
       .Default(Invalid);
 }
 
-static bool isPETarget(const std::vector<const char *> &V) {
+static bool isPETarget(const SmallVector<const char *, 256> &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<const char *> &V) {
+static Flavor parseFlavor(SmallVector<const char *, 256> &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<const char *> Args(Argv, Argv + Argc);
-  switch (parseFlavor(Args)) {
+  // Expand response files (arguments in the form of @<filename>)
+  // to allow deducing the flavor or PE -m argument from arguments in them.
+  SmallVector<const char *, 256> 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());
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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63024.203603.patch
Type: text/x-patch
Size: 2498 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190607/77285b62/attachment.bin>


More information about the llvm-commits mailing list