public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc parameter -mcrtdll= for choosing Windows C RunTime DLL library
@ 2022-11-20 12:53 Pali Rohár
  2022-11-20 13:36 ` [Mingw-w64-public] " LIU Hao
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Pali Rohár @ 2022-11-20 12:53 UTC (permalink / raw)
  To: gcc, mingw-w64-public

Hello! I would like to propose a new parameter for gcc: -mcrtdll= to
allow specifying against which Windows C Runtime library should be
binary linked. On Windows there are more crt libraries and currently gcc
links to libmsvcrt.a which is in most cases symlink to libmsvcrt-os.a
(but can be changed, e.g. during mingw-w64 building). mingw-w64 project
already builds import .a library for every crt dll library (from the old
crtdll.dll up to the new ucrtbase.dll), so it is ready for usage. Simple
patch for gcc which implements -mcrtdll parameter is below. Note that on
internet are other very similar patches for -mcrtdll= parameters and
some are parts of custom mingw32 / mingw-w64 gcc builds. What do you
think? Could gcc have "official" support for -mcrtdll= parameter?


--- gcc/config/i386/cygming.opt	2022-02-06 21:00:05.377656896 +0100
+++ gcc/config/i386/cygming.opt	2022-02-06 21:04:06.690995944 +0100
@@ -22,6 +22,10 @@ mconsole
 Target RejectNegative
 Create console application.
 
+mcrtdll=
+Target RejectNegative Joined
+Link with specified C RunTime DLL library.
+
 mdll
 Target RejectNegative
 Generate code for a DLL.
--- gcc/config/i386/mingw32.h	2022-01-16 17:28:31.157999097 +0100
+++ gcc/config/i386/mingw32.h	2022-01-16 17:36:03.552856726 +0100
@@ -95,7 +95,20 @@ along with GCC; see the file COPYING3.
 #undef CPP_SPEC
 #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
 		 "%{" SPEC_PTHREAD1 ":-D_REENTRANT} " \
-		 "%{" SPEC_PTHREAD2 ": } "
+		 "%{" SPEC_PTHREAD2 ": } " \
+		 "%{mcrtdll=crtdll*:-U__MSVCRT__ -D__CRTDLL__} " \
+		 "%{mcrtdll=msvcrt10*:-D__MSVCRT_VERSION__=0x100} " \
+		 "%{mcrtdll=msvcrt20*:-D__MSVCRT_VERSION__=0x200} " \
+		 "%{mcrtdll=msvcrt40*:-D__MSVCRT_VERSION__=0x400} " \
+		 "%{mcrtdll=msvcrt-os*:-D__MSVCRT_VERSION__=0x700} " \
+		 "%{mcrtdll=msvcr70*:-D__MSVCRT_VERSION__=0x700} " \
+		 "%{mcrtdll=msvcr71*:-D__MSVCRT_VERSION__=0x701} " \
+		 "%{mcrtdll=msvcr80*:-D__MSVCRT_VERSION__=0x800} " \
+		 "%{mcrtdll=msvcr90*:-D__MSVCRT_VERSION__=0x900} " \
+		 "%{mcrtdll=msvcr100*:-D__MSVCRT_VERSION__=0xA00} " \
+		 "%{mcrtdll=msvcr110*:-D__MSVCRT_VERSION__=0xB00} " \
+		 "%{mcrtdll=msvcr120*:-D__MSVCRT_VERSION__=0xC00} " \
+		 "%{mcrtdll=ucrt*:-D_UCRT} "
 
 /* For Windows applications, include more libraries, but always include
    kernel32.  */
@@ -185,11 +198,16 @@ along with GCC; see the file COPYING3.
 #define REAL_LIBGCC_SPEC \
   "%{mthreads:-lmingwthrd} -lmingw32 \
    " SHARED_LIBGCC_SPEC " \
-   -lmoldname -lmingwex -lmsvcrt -lkernel32"
+   -lmoldname -lmingwex %{!mcrtdll=*:-lmsvcrt} %{mcrtdll=*:-l%*} -lkernel32"
 
 #undef STARTFILE_SPEC
-#define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
-  %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \
+#define STARTFILE_SPEC " \
+  %{shared|mdll:%{mcrtdll=crtdll*:dllcrt1%O%s}} \
+  %{shared|mdll:%{!mcrtdll=crtdll*:dllcrt2%O%s}} \
+  %{!shared:%{!mdll:%{mcrtdll=crtdll*:crt1%O%s}}} \
+  %{!shared:%{!mdll:%{!mcrtdll=crtdll*:crt2%O%s}}} \
+  %{pg:%{mcrtdll=crtdll*:gcrt1%O%s}} \
+  %{pg:%{!mcrtdll=crtdll*:gcrt2%O%s}} \
   crtbegin.o%s \
   %{fvtable-verify=none:%s; \
     fvtable-verify=preinit:vtv_start.o%s; \


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-05-08  3:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20 12:53 gcc parameter -mcrtdll= for choosing Windows C RunTime DLL library Pali Rohár
2022-11-20 13:36 ` [Mingw-w64-public] " LIU Hao
2022-11-20 15:06   ` Pali Rohár
2022-11-21  5:21     ` LIU Hao
2022-11-26 19:09       ` Pali Rohár
2022-11-27  1:06         ` sotrdg sotrdg
2022-11-20 14:45 ` Eli Zaretskii
2022-11-20 15:04   ` Pali Rohár
2022-11-20 15:23     ` Eli Zaretskii
2022-11-20 15:44       ` Pali Rohár
2022-11-20 15:58         ` Eli Zaretskii
2022-11-20 16:19           ` [Mingw-w64-public] " ralph engels
2022-11-20 16:20           ` Matthew Brett
2022-11-20 21:22 ` Martin Storsjö
2022-12-04 12:16 ` Pali Rohár
2022-12-04 12:48   ` LIU Hao
2023-04-21 16:23     ` Pali Rohár
2023-05-06 10:45       ` Pali Rohár
2023-05-08  3:44         ` LIU Hao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).