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

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 14:13:41 PDT 2017


mstorsjo updated this revision to Diff 114429.
mstorsjo retitled this revision from "[MinGW] Allow overriding which version of msvcrt to link to" to "[MinGW] Don't link -lmsvcrt if a different msvcrt version is to be linked".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Attempted implementing Reid's suggestion.

On the mingw-w64 mailing list (https://sourceforge.net/p/mingw-w64/mailman/message/36030072/), there were points made that it would be better with some mechanism that controls both linking the right msvcrt version and setting `__MSVCRT_VERSION__` in sync.

And someone pointed out some widely used (but not upstreamed) patches for GCC that adds an option `-mcrtdll` which does pretty much exactly what my `-mmsvcrt` option did in the previous iteration (https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-gcc-git/0006-gcc-7-branch-Windows-New-feature-to-allow-overriding.patch), which in another non-upstreamed patch also is used to set `__MSVCRT_VERSION__` (https://raw.githubusercontent.com/nak5124/build_env/master/gcc_build/patches/gcc/0020-MinGW-w64-Define-__MSVCRT_VERSION__.patch).


https://reviews.llvm.org/D37530

Files:
  lib/Driver/ToolChains/MinGW.cpp
  test/Driver/mingw-msvcrt.c


Index: test/Driver/mingw-msvcrt.c
===================================================================
--- /dev/null
+++ test/Driver/mingw-msvcrt.c
@@ -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"
Index: lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -82,6 +82,9 @@
 
   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");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37530.114429.patch
Type: text/x-patch
Size: 930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170908/ddb13af9/attachment.bin>


More information about the cfe-commits mailing list