From patchwork Wed Jun 14 16:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 108022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp61000vqr; Wed, 14 Jun 2023 09:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eRnyjDYqsRBVx0rwQydVkfgcc5u9QNNs0WzV/9Vf2m3I7rZa5+/Qieh17VQucG/BlFmzW X-Received: by 2002:a17:906:fd84:b0:977:bf09:279 with SMTP id xa4-20020a170906fd8400b00977bf090279mr15448837ejb.41.1686759075423; Wed, 14 Jun 2023 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686759075; cv=none; d=google.com; s=arc-20160816; b=pmTiJXYH174wigQFrlXLM0Z+QK/9MlBVbHT8Gkh3FgG21UMqdREbABbz7xT2Vfx3zY Tp9hr//xhBwHPehHksX1yMsVulZORAznbAfx85TS+ZT7uc8zIlXQIgYC0CvdiVBKqpTF XlBO2CF5HFsvtaJSJHLJN13bM0JK3k4TmbGAxnni3ZiYsV9kgkspVT7R6HdxggXhy/KQ G/8/YaRYEIVckuEGvwitv1+d3HlZlQAmIwK3FLBggEEmXGyUCag5pNLkAPACXkMlrNqD 4c6AOBpL5vEFbmHUqpUT1zcFKgQR1D0VVTyOWUOYdFITSL1QoyWDSlupuZ6lvMWnw78y mZ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5wpGXPqJ+dysYcdk+szlCKtnuxEY2vHAawtVUBJ4cyk=; b=BShpNFR8LJh2YHYhzbx36OiPkUbEAJS3KXHtH/tbWEXkEYx/LUku/iXVQZRdqMGArr AhlPeRorCK3LMo97PExZ0qoeXfhfgEKF3g+zqeNLeaQDMJiqv05uyg58HY+//gGaXpeC iO0WfP32TDVt+IygGKHE+fDdqOeEochy6z8Zppi/6ibUVos2pX9eloXXCj3fVcO4Gp1E QjBoqTMpxsHHo8PLSwocQb3734/ZthffWTAerLXKmffbI4Bexq7xMBC810PwQCwt8FHe W6x1R2LPSwKksPjvESGiHPXX3cs+svc5cve6ElExlYdcMTwI8tD1uQmml+EN1PIGYEK2 B9oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YCC+P7MQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l20-20020a170906079400b0097885f7cce8si8228988ejc.972.2023.06.14.09.11.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 09:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YCC+P7MQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB7773857B9B for ; Wed, 14 Jun 2023 16:11:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB7773857B9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686759060; bh=5wpGXPqJ+dysYcdk+szlCKtnuxEY2vHAawtVUBJ4cyk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YCC+P7MQtXxQAphF2Dw1UcoJk/l5tFaunXkVwUar8cJ2l26p0RDyJGdZO+OEcDbhk DNc947uscR+GE/K3Rvn3GE4geCoOUCuXixMW/AsRTt8QCbgku3nz357QIiNfBti0is T1L761/9WnLZsnuiATNFBk4QoBY1n17k2WDmzMcs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by sourceware.org (Postfix) with ESMTPS id 6CCF93858C20 for ; Wed, 14 Jun 2023 16:10:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CCF93858C20 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 780D163DCF; Wed, 14 Jun 2023 16:10:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B73AC433CB; Wed, 14 Jun 2023 16:10:15 +0000 (UTC) Received: by pali.im (Postfix) id 861B47FA; Wed, 14 Jun 2023 18:10:12 +0200 (CEST) To: gcc-patches@gcc.gnu.org Cc: Jonathan Yong <10walls@gmail.com> Subject: [PATCH v2] Add MinGW option -mcrtdll= for choosing C RunTime DLL library Date: Wed, 14 Jun 2023 18:09:17 +0200 Message-Id: <20230614160917.13046-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230527101412.19562-1-pali@kernel.org> References: <20230527101412.19562-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Pali_Roh=C3=A1r_via_Gcc-patches?= From: =?utf-8?q?Pali_Roh=C3=A1r?= Reply-To: =?utf-8?q?Pali_Roh=C3=A1r?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767041973212129774?= X-GMAIL-MSGID: =?utf-8?q?1768695084450997069?= It adjust preprocess, compile and link flags, which allows to change default -lmsvcrt library by another provided by MinGW runtime. gcc/ * config/i386/mingw-w64.h (CPP_SPEC): Adjust for -mcrtdll=. (REAL_LIBGCC_SPEC): New define. * config/i386/mingw.opt: Add mcrtdll= * config/i386/mingw32.h (CPP_SPEC): Adjust for -mcrtdll=. (REAL_LIBGCC_SPEC): Adjust for -mcrtdll=. (STARTFILE_SPEC): Adjust for -mcrtdll=. * doc/invoke.texi: Add mcrtdll= documentation. --- Changes in v2: * Fixed doc/invoke.texi documentation --- gcc/config/i386/mingw-w64.h | 22 +++++++++++++++++++++- gcc/config/i386/mingw.opt | 4 ++++ gcc/config/i386/mingw32.h | 28 ++++++++++++++++++++++++---- gcc/doc/invoke.texi | 24 +++++++++++++++++++++++- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h index 3a21cec3f8cd..0146ed4f793e 100644 --- a/gcc/config/i386/mingw-w64.h +++ b/gcc/config/i386/mingw-w64.h @@ -25,7 +25,27 @@ along with GCC; see the file COPYING3. If not see #define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \ "%{municode:-DUNICODE} " \ "%{" SPEC_PTHREAD1 ":-D_REENTRANT} " \ - "%{" SPEC_PTHREAD2 ":-U_REENTRANT} " + "%{" SPEC_PTHREAD2 ":-U_REENTRANT} " \ + "%{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} " + +#undef REAL_LIBGCC_SPEC +#define REAL_LIBGCC_SPEC \ + "%{mthreads:-lmingwthrd} -lmingw32 \ + " SHARED_LIBGCC_SPEC " \ + -lmingwex %{!mcrtdll=*:-lmsvcrt} %{mcrtdll=*:-l%*} \ + -lkernel32 " MCFGTHREAD_SPEC #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ diff --git a/gcc/config/i386/mingw.opt b/gcc/config/i386/mingw.opt index 0ae026a66bd6..dd66a50aec00 100644 --- a/gcc/config/i386/mingw.opt +++ b/gcc/config/i386/mingw.opt @@ -18,6 +18,10 @@ ; along with GCC; see the file COPYING3. If not see ; . +mcrtdll= +Target RejectNegative Joined +Preprocess, compile or link with specified C RunTime DLL library. + pthread Driver diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h index 6a55baaa4587..a1ee001983a7 100644 --- a/gcc/config/i386/mingw32.h +++ b/gcc/config/i386/mingw32.h @@ -89,7 +89,20 @@ along with GCC; see the file COPYING3. If not see #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. */ @@ -184,11 +197,18 @@ along with GCC; see the file COPYING3. If not see #define REAL_LIBGCC_SPEC \ "%{mthreads:-lmingwthrd} -lmingw32 \ " SHARED_LIBGCC_SPEC " \ - -lmoldname -lmingwex -lmsvcrt -lkernel32 " MCFGTHREAD_SPEC + %{mcrtdll=crtdll*:-lcoldname} %{!mcrtdll=crtdll*:-lmoldname} \ + -lmingwex %{!mcrtdll=*:-lmsvcrt} %{mcrtdll=*:-l%*} \ + -lkernel32 " MCFGTHREAD_SPEC #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; \ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b92b85760279..f276f6f80a97 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1458,7 +1458,7 @@ See RS/6000 and PowerPC Options. -munroll-only-small-loops -mlam=@var{choice}} @emph{x86 Windows Options} -@gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll +@gccoptlist{-mconsole -mcrtdll=@var{library} -mcygwin -mno-cygwin -mdll -mnop-fun-dllimport -mthread -municode -mwin32 -mwindows -fno-set-stack-executable} @@ -34202,6 +34202,28 @@ required for console applications. This option is available for Cygwin and MinGW targets and is enabled by default on those targets. +@opindex mcrtdll +@item -mcrtdll=@var{library} +Preprocess, compile or link with specified C RunTime DLL @var{library}. +This option adjust predefined macros @code{__CRTDLL__}, @code{__MSVCRT__} +and @code{__MSVCRT_VERSION__} for specified CRT @var{library}, choose +start file for CRT @var{library} and link with CRT @var{library}. +Recognized CRT library names for proprocessor are: +@code{crtdll}, @code{msvcrt10}, @code{msvcrt20}, @code{msvcrt40}, +@code{msvcrt-os}, @code{msvcr70}, @code{msvcr80}, @code{msvcr90}, +@code{msvcr100}, @code{msvcr110}, @code{msvcr120} and @code{ucrt}. +If this options is not specified then the default MinGW import library +@code{msvcrt} is used for linking and no other adjustment for +preprocessor is done. MinGW import library @code{msvcrt} is just a +symlink to (or a copy of) another MinGW CRT import library +chosen during MinGW compilation. MinGW import library @code{msvcrt-os} +is for Windows system CRT DLL library @code{msvcrt.dll} and +in most cases is the default MinGW import library. +Generally speaking, changing the CRT DLL requires recompiling +the entire MinGW CRT. This option is for experimental and testing +purposes only. +This option is available for MinGW targets. + @opindex mdll @item -mdll This option is available for Cygwin and MinGW targets. It