[lld] r312944 - [MinGW] Map the -verbose option, implement -### for showing the produced parameters

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 13:43:39 PDT 2017


Author: mstorsjo
Date: Mon Sep 11 13:43:39 2017
New Revision: 312944

URL: http://llvm.org/viewvc/llvm-project?rev=312944&view=rev
Log:
[MinGW] Map the -verbose option, implement -### for showing the produced parameters

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.

Differential Revision: https://reviews.llvm.org/D37706

Modified:
    lld/trunk/MinGW/Driver.cpp
    lld/trunk/MinGW/Options.td
    lld/trunk/test/MinGW/driver.s

Modified: lld/trunk/MinGW/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Driver.cpp?rev=312944&r1=312943&r2=312944&view=diff
==============================================================================
--- lld/trunk/MinGW/Driver.cpp (original)
+++ lld/trunk/MinGW/Driver.cpp Mon Sep 11 13:43:39 2017
@@ -14,6 +14,7 @@
 #include "lld/Driver/Driver.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
@@ -124,7 +125,7 @@ bool link(ArrayRef<const char *> ArgsArr
   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 +176,15 @@ bool link(ArrayRef<const char *> ArgsArr
       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))
+    outs() << llvm::join(LinkArgs, " ") << "\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)

Modified: lld/trunk/MinGW/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Options.td?rev=312944&r1=312943&r2=312944&view=diff
==============================================================================
--- lld/trunk/MinGW/Options.td (original)
+++ lld/trunk/MinGW/Options.td Mon Sep 11 13:43:39 2017
@@ -17,6 +17,11 @@ def shared: F<"shared">, HelpText<"Build
 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 enable_auto_image_base: Flag<["--"],
 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

Modified: lld/trunk/test/MinGW/driver.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/MinGW/driver.s?rev=312944&r1=312943&r2=312944&view=diff
==============================================================================
--- lld/trunk/test/MinGW/driver.s (original)
+++ lld/trunk/test/MinGW/driver.s Mon Sep 11 13:43:39 2017
@@ -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)




More information about the llvm-commits mailing list