[PATCH] D37530: [MinGW] Allow overriding which version of msvcrt to link to

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 6 13:21:12 PDT 2017


mstorsjo created this revision.

This allows linking to e.g. msvcr120.dll or ucrtbase.dll instead of the unversioned (and officially unsupported) msvcrt.dll. In GCC setups, this can be overridden by using custom spec files, but this isn't supported in clang.

This is just an initial attempt at implementing this - suggestions are most welcome.


https://reviews.llvm.org/D37530

Files:
  include/clang/Driver/Options.td
  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 -mmsvcrt=msvcr120 -### %s 2>&1 | FileCheck -check-prefix=CHECK_MSVCR120 %s
+
+// CHECK_DEFAULT: "-lmingwex" "-lmsvcrt"
+// CHECK_MSVCR120: "-lmingwex" "-lmsvcr120"
Index: lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -82,7 +82,8 @@
 
   CmdArgs.push_back("-lmoldname");
   CmdArgs.push_back("-lmingwex");
-  CmdArgs.push_back("-lmsvcrt");
+  CmdArgs.push_back(Args.MakeArgString(
+      "-l" + Args.getLastArgValue(options::OPT_mmsvcrt_EQ, "msvcrt")));
 }
 
 void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
@@ -157,7 +158,7 @@
     if (Args.hasArg(options::OPT_mdll) || Args.hasArg(options::OPT_shared)) {
       CmdArgs.push_back("-e");
       if (TC.getArch() == llvm::Triple::x86)
-        CmdArgs.push_back("_DllMainCRTStartup at 12");
+        CmdArgs.push_back("DllMainCRTStartup at 12");
       else
         CmdArgs.push_back("DllMainCRTStartup");
       CmdArgs.push_back("--enable-auto-image-base");
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1710,6 +1710,7 @@
 def mdll : Joined<["-"], "mdll">, Group<m_Group>, Flags<[DriverOption]>;
 def municode : Joined<["-"], "municode">, Group<m_Group>, Flags<[DriverOption]>;
 def mthreads : Joined<["-"], "mthreads">, Group<m_Group>, Flags<[DriverOption]>;
+def mmsvcrt_EQ : Joined<["-"], "mmsvcrt=">, Group<m_Group>, Flags<[DriverOption]>;
 def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group<m_Group>;
 def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group<m_Group>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37530.114059.patch
Type: text/x-patch
Size: 2081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170906/78a8af78/attachment-0001.bin>


More information about the cfe-commits mailing list