From patchwork Sat May 27 10:14:12 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: 99814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp242901vqr; Sat, 27 May 2023 03:15:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53nGhj6mQhz8nI6O4j+3gQQla04diR0OG3mUgueLtWNzMsbkndqDmE7Fj1ds82ecSJZOyr X-Received: by 2002:a17:906:58d3:b0:973:9522:c678 with SMTP id e19-20020a17090658d300b009739522c678mr4075502ejs.44.1685182545663; Sat, 27 May 2023 03:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685182545; cv=none; d=google.com; s=arc-20160816; b=0QElCV8JVwLNzKG6zps7uS0Ogtt+/7i4B1JOVx0O3MYgmnp3sYzz2Gc9aulYrAK2Fp lH9P133cKuOjvUcp54H/ILS/5NVwIjzeB/SvLwqd/MSpaM4cOgTZd8fXFkbrC8zWkzhS efaxzf4qvSQNeZh4SAn81W0rv0YNkFasRs1C+LbU4E7HzKBMFDyeG2MXCkvz2512TnIq XUvTJFeY1Z8T79iWODMcVj4RQLfvlx3yOl9RywbjB7a+PnyCRXlZvvNebvxrOi/Ox/h6 TD16m7Z91t+99sexdeJOyeQipDopc2EgWaOd6sD74EjAglYv7+ckWgaIies+FGkPG+A2 H5sg== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Os4G2xq3Fv6mVDGlBQVKe9HKqCWjxN3a5PfacZuCon4=; b=LSwLxfqyB85uD5nvoJ7KIh9KEE3P+Zmedm5cP6Wt0BeRPXMQfmxtYxsKyy23NGAxR7 DXyl19OlkHmX5ZLkeVHBGAZXZ+epNEwuw1dlLr7s5FMWncQ3zsjNkURrDOeAhPO9g92I 1t8EuJnVRWhMVhl9cI693SryLGNdorNL3QNCRiyjI2JeO1fD2ylUDO02jUqbJVeg9/I3 COLc+tIrPbCFfgln8ompJ7czXtVQuz8PLK62mImE5OKAEufnqCuuUyhn5Fik7BBTpGaz UQq0a0UY39/ShFjMOUiCXd1zaCdUh0uc7fbu9oxcZAVfa6nxj/MAAMO50A9wd7c/i4Ph bMCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="NBNCOm/M"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v5-20020aa7d9c5000000b00506985655f0si1442742eds.355.2023.05.27.03.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 03:15:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="NBNCOm/M"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 64E343856DDE for ; Sat, 27 May 2023 10:15:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64E343856DDE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685182543; bh=Os4G2xq3Fv6mVDGlBQVKe9HKqCWjxN3a5PfacZuCon4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NBNCOm/M58xmv6gXnHrro2IumkiGyPj8bLxkWLYnyzxR0RBZMhi6QLqQssYcrfNhU wB3dEhmUw7hGmNVayNKwg8AV2llYnaedhSYTubqJ8luUPB2Usxmen+8LhnXPPRwTUd SkdMJYesQu3LlpZiopLb0J0Ptn8jkk1bSGEFqV7M= 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 899FA3858C74 for ; Sat, 27 May 2023 10:14:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 899FA3858C74 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1C8C60A28; Sat, 27 May 2023 10:14:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3429C433EF; Sat, 27 May 2023 10:14:54 +0000 (UTC) Received: by pali.im (Postfix) id C5D34947; Sat, 27 May 2023 12:14:51 +0200 (CEST) To: gcc-patches@gcc.gnu.org Cc: Jonathan Yong <10walls@gmail.com> Subject: [PATCH] Add MinGW option -mcrtdll= for choosing C RunTime DLL library Date: Sat, 27 May 2023 12:14:12 +0200 Message-Id: <20230527101412.19562-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 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?1767041973212129774?= 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. --- gcc/config/i386/mingw-w64.h | 22 +++++++++++++++++++++- gcc/config/i386/mingw.opt | 4 ++++ gcc/config/i386/mingw32.h | 28 ++++++++++++++++++++++++---- gcc/doc/invoke.texi | 21 ++++++++++++++++++++- 4 files changed, 69 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..32e3f504b22a 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,25 @@ 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 (or file copy) to the other 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. +This option is available for MinGW targets. + @opindex mdll @item -mdll This option is available for Cygwin and MinGW targets. It