[PATCH] D37706: [LLD] [MinGW] Map the -verbose option, implement -### for showing the produced parameters

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 13:34:14 PDT 2017


mstorsjo created this revision.

Pass the -verbose option through to the COFF linker, and show the arguments passed to it. If the -### option is specified, just show the produced argument list and exit, just like in clang.

Replace the first argument with "lld-link" in order to produce a correct command line.


https://reviews.llvm.org/D37706

Files:
  MinGW/Driver.cpp
  MinGW/Options.td
  test/MinGW/driver.s


Index: test/MinGW/driver.s
===================================================================
--- test/MinGW/driver.s
+++ test/MinGW/driver.s
@@ -10,6 +10,11 @@
 # RUN: llvm-readobj %t.exe | FileCheck %s
 # CHECK: File:
 
+# RUN: ld.lld -m i386pep -e main %t.obj -o %t.exe -verbose -### | FileCheck %s -check-prefix CHECK-VERBOSE
+# CHECK-VERBOSE: lld-link -entry:main
+# CHECK-VERBOSE-SAME: -machine:x64 -alternatename:__image_base__=__ImageBase
+# CHECK-VERBOSE-SAME: -verbose
+
 # RUN: ld.lld -m i386pep --entry main %t.obj -o %t.exe --subsystem console
 # RUN: llvm-readobj -file-headers %t.exe | FileCheck %s -check-prefix CHECK-CONSOLE
 # CHECK-CONSOLE: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
Index: MinGW/Options.td
===================================================================
--- MinGW/Options.td
+++ MinGW/Options.td
@@ -17,6 +17,11 @@
 def subs: Separate<["--"], "subsystem">, HelpText<"Specify subsystem">;
 def stack: Separate<["--"], "stack">;
 def outlib: Separate<["--"], "out-implib">, HelpText<"Import library name">;
+def verbose: F<"verbose">, HelpText<"Verbose mode">;
+
+// LLD specific options
+def _HASH_HASH_HASH : Flag<["-"], "###">,
+    HelpText<"Print (but do not run) the commands to run for this compilation">;
 
 // Currently stubs to avoid errors
 def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">;
@@ -27,7 +32,6 @@
 def full_shutdown: Flag<["--"], "full-shutdown">;
 def O: Joined<["-"], "O">, HelpText<"Optimize output file size">;
 def v: Flag<["-"], "v">, HelpText<"Display the version number">;
-def verbose: F<"verbose">, HelpText<"Verbose mode">;
 def version: F<"version">, HelpText<"Display the version number and exit">;
 
 // Alias
Index: MinGW/Driver.cpp
===================================================================
--- MinGW/Driver.cpp
+++ MinGW/Driver.cpp
@@ -124,7 +124,7 @@
   std::vector<std::string> LinkArgs;
   auto Add = [&](const Twine &S) { LinkArgs.push_back(S.str()); };
 
-  Add(ArgsArr[0]);
+  Add("lld-link");
 
   if (auto *A = Args.getLastArg(OPT_entry))
     Add("-entry:" + StringRef(A->getValue()));
@@ -175,6 +175,18 @@
       Add(searchLibrary(A->getValue(), SearchPaths, Args.hasArg(OPT_Bstatic)));
   }
 
+  if (Args.hasArg(OPT_verbose))
+    Add("-verbose");
+
+  if (Args.hasArg(OPT_verbose) || Args.hasArg(OPT__HASH_HASH_HASH)) {
+    for (auto Arg : LinkArgs)
+      outs() << " " << Arg;
+    outs() << "\n";
+  }
+
+  if (Args.hasArg(OPT__HASH_HASH_HASH))
+    return true;
+
   // Repack vector of strings to vector of const char pointers for coff::link.
   std::vector<const char *> Vec;
   for (const std::string &S : LinkArgs)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37706.114672.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170911/9c50f357/attachment.bin>


More information about the llvm-commits mailing list