[lld] r361016 - [MinGW] Implement the -v and --version flags for the MinGW driver

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 04:07:42 PDT 2019


Author: mstorsjo
Date: Fri May 17 04:07:42 2019
New Revision: 361016

URL: http://llvm.org/viewvc/llvm-project?rev=361016&view=rev
Log:
[MinGW] Implement the -v and --version flags for the MinGW driver

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

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

Modified: lld/trunk/MinGW/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Driver.cpp?rev=361016&r1=361015&r2=361016&view=diff
==============================================================================
--- lld/trunk/MinGW/Driver.cpp (original)
+++ lld/trunk/MinGW/Driver.cpp Fri May 17 04:07:42 2019
@@ -30,6 +30,7 @@
 
 #include "lld/Common/Driver.h"
 #include "lld/Common/ErrorHandler.h"
+#include "lld/Common/Version.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
@@ -139,6 +140,21 @@ bool mingw::link(ArrayRef<const char *>
     return true;
   }
 
+  // A note about "compatible with GNU linkers" message: this is a hack for
+  // scripts generated by GNU Libtool 2.4.6 (released in February 2014 and
+  // still the newest version in March 2017) or earlier to recognize LLD as
+  // a GNU compatible linker. As long as an output for the -v option
+  // contains "GNU" or "with BFD", they recognize us as GNU-compatible.
+  if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version))
+    message(getLLDVersion() + " (compatible with GNU linkers)");
+
+  // The behavior of -v or --version is a bit strange, but this is
+  // needed for compatibility with GNU linkers.
+  if (Args.hasArg(OPT_v) && !Args.hasArg(OPT_INPUT) && !Args.hasArg(OPT_l))
+    return true;
+  if (Args.hasArg(OPT_version))
+    return true;
+
   if (!Args.hasArg(OPT_INPUT) && !Args.hasArg(OPT_l))
     fatal("no input files");
 

Modified: lld/trunk/MinGW/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Options.td?rev=361016&r1=361015&r2=361016&view=diff
==============================================================================
--- lld/trunk/MinGW/Options.td (original)
+++ lld/trunk/MinGW/Options.td Fri May 17 04:07:42 2019
@@ -48,7 +48,9 @@ def strip_debug: F<"strip-debug">,
     HelpText<"Omit all debug information, but keep symbol information">;
 def whole_archive: F<"whole-archive">,
     HelpText<"Include all object files for following archives">;
+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">;
 def require_defined: S<"require-defined">,
     HelpText<"Force symbol to be added to symbol table as an undefined one">;
 def require_defined_eq: J<"require-defined=">, Alias<require_defined>;
@@ -90,5 +92,3 @@ def: J<"plugin-opt=">;
 def: J<"sysroot">;
 def: F<"start-group">;
 def: F<"tsaware">;
-def: Flag<["-"], "v">;
-def: F<"version">;

Modified: lld/trunk/test/MinGW/driver.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/MinGW/driver.test?rev=361016&r1=361015&r2=361016&view=diff
==============================================================================
--- lld/trunk/test/MinGW/driver.test (original)
+++ lld/trunk/test/MinGW/driver.test Fri May 17 04:07:42 2019
@@ -169,3 +169,8 @@ TIMESTAMP-NOT: -timestamp:0
 RUN: ld.lld -### -m i386pep foo.o -appcontainer | FileCheck -check-prefix APPCONTAINER %s
 RUN: ld.lld -### -m i386pep foo.o --appcontainer | FileCheck -check-prefix APPCONTAINER %s
 APPCONTAINER: -appcontainer
+
+# RUN: ld.lld -m i386pep --version 2>&1 | FileCheck -check-prefix=VERSION %s
+# RUN: ld.lld -m i386pep -v 2>&1 | FileCheck -check-prefix=VERSION %s
+# RUN: not ld.lld -m i386pep -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s
+# VERSION: LLD {{.*}} (compatible with GNU linkers)




More information about the llvm-commits mailing list