r314138 - [MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked

Martin Storsjo via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 12:24:45 PDT 2017


Author: mstorsjo
Date: Mon Sep 25 12:24:45 2017
New Revision: 314138

URL: http://llvm.org/viewvc/llvm-project?rev=314138&view=rev
Log:
[MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked

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

Added:
    cfe/trunk/test/Driver/mingw-msvcrt.c
Modified:
    cfe/trunk/lib/Driver/ToolChains/MinGW.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MinGW.cpp?rev=314138&r1=314137&r2=314138&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp Mon Sep 25 12:24:45 2017
@@ -82,6 +82,9 @@ void tools::MinGW::Linker::AddLibGCC(con
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
+  for (auto Lib : Args.getAllArgValues(options::OPT_l))
+    if (StringRef(Lib).startswith("msvcr") || Lib == "ucrtbase")
+      return;
   CmdArgs.push_back("-lmsvcrt");
 }
 

Added: cfe/trunk/test/Driver/mingw-msvcrt.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mingw-msvcrt.c?rev=314138&view=auto
==============================================================================
--- cfe/trunk/test/Driver/mingw-msvcrt.c (added)
+++ cfe/trunk/test/Driver/mingw-msvcrt.c Mon Sep 25 12:24:45 2017
@@ -0,0 +1,5 @@
+// RUN: %clang -v -target i686-pc-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_DEFAULT %s
+// RUN: %clang -v -target i686-pc-windows-gnu -lmsvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s
+
+// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32"
+// CHECK_MSVCR120: "-lmingwex" "-ladvapi32"




More information about the cfe-commits mailing list