From patchwork Thu Apr 11 17:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1922658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=igTvPuBg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VFmj72nWRz1yYB for ; Fri, 12 Apr 2024 03:22:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DA1E384AB42 for ; Thu, 11 Apr 2024 17:22:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 627CD385840E for ; Thu, 11 Apr 2024 17:21:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 627CD385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 627CD385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712856112; cv=none; b=td9T8b0b0lauAjkIbfV42hFHvBVywxh4uUhY2QSaiODJ9PhWEkYRD1eEs8GrnU0+lvW919LulQ08y7cnrGOGkxgNVFQaUgHDq0rF9tiBJpPnIdMU62Hr8P4qDAv2zqtxS6tHmXbUL3QeWqM1JJiu6/2bQ1WYTd0MALAf2u98V+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712856112; c=relaxed/simple; bh=nrpHvPuxRuOXBq25saeK06vGXavCH9yqHEKNV6FQ7Qs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rlXmXkiOb0TN9vINNhRHtfUDkZY0NlG8vN1JFBSU0p+ZdHtnKiCNq4MVwqBVWddcjIxjzHwWUI2M+xkp5rtdyCVzLZKt+HqXnLVh84VFRefFo1yM9qwk4nqBZ/kSEMycMVzxV8SbntxAA8ztdTLIzswwiYgywFH7e3kywB/rbyk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712856110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sFlQSbKZYsd1fkU3/h53baEzHLr6/cgrN3k20oFJuXE=; b=igTvPuBgc770Dj1iAwvBrFF1jIfmlh+lKe0ah+ZCHD5Xa+QjLU2wueBvLSem+gX0cCDQ43 V04v58z143g1bdFe4sq6txaVX8nxd+FTzR6YahZ3neOvap5Qmatniq/wp5dnEgR1jJjIdu bnmvzZmswrXQGz3p4kxvwOfOtxEqujU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-pQRiS8tDN6CM06LJXWszCg-1; Thu, 11 Apr 2024 13:21:48 -0400 X-MC-Unique: pQRiS8tDN6CM06LJXWszCg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD9161802CE2; Thu, 11 Apr 2024 17:21:47 +0000 (UTC) Received: from localhost (unknown [10.42.28.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CE292026962; Thu, 11 Apr 2024 17:21:47 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Compile std::allocator instantiations as C++20 Date: Thu, 11 Apr 2024 18:15:20 +0100 Message-ID: <20240411172142.587623-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org I'm considering this late patch for gcc-14 to workaround an issue discovered by a recent Clang change. I'm not yet sure if Clang is right to require these symbols. It's not really clear, because always_inline isn't part of the standard so it's not clear how it should interact with explicit instantiations and modules. Exporting these four extra symbols doesn't hurt, even if Clang ends up reverting or revising its change that requires them. Another way to fix it would be to suppress the explicit instantiation declarations in for C++20, so that the compiler always instantiates them implicitly as needed. We do similar things for the explicit instantiations of std::string etc. so that new member functions that aren't in the .so are implicitly instantiated as needed. That would look like this instead: --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -281,7 +281,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. -#if _GLIBCXX_EXTERN_TEMPLATE +#if _GLIBCXX_EXTERN_TEMPLATE && __cplusplus <= 201703L extern template class allocator; extern template class allocator; #endif But we might want to export the new functions from the library eventually anyway, so doing it now (before Clang 19 is released) might be the best option. Thoughts? -- >8 -- This ensures that the new std::allocator::allocate and std::allocator::deallocate functions are included in the explicit instantiation definitions. They're only defined for C++20 and later (because they are needed to support constexpr dynamic allocation) so were not being instantiated when those files were compiled as C++98. This isn't needed for GCC because those functions are marked 'always_inline' and so no extern symbols are needed. But a recent Clang change has meant that always_inline functions do not get exported from modules, and so the extern symbols (which were not previously being instantiated or exported) are needed by Clang. See the Clang issue https://github.com/llvm/llvm-project/issues/86893 for details. The allocator-inst.cc file is changed to include instead of all of , because otherwise it indirectly includes and the implicit instantiations of std::string and std::wstring also instantiate std::allocator and std::allocator, which for some reason suppresses the explicit instantiation definitions of the default constructors in this file. Just including avoids that problem. libstdc++-v3/ChangeLog: * config/abi/pre/gnu.ver: Export new symbols. * src/c++20/Makefile.am: Add allocator-inst.o. * src/c++20/Makefile.in: Regenerate. * src/c++98/allocator-inst.cc: Move to... * src/c++20/allocator-inst.cc: ...here. * src/c++98/Makefile.am: Remove allocator-inst.o. * src/c++98/Makefile.in: Regenerate. --- libstdc++-v3/config/abi/pre/gnu.ver | 4 ++++ libstdc++-v3/src/c++20/Makefile.am | 1 + libstdc++-v3/src/c++20/Makefile.in | 4 +++- libstdc++-v3/src/{c++98 => c++20}/allocator-inst.cc | 2 +- libstdc++-v3/src/c++98/Makefile.am | 1 - libstdc++-v3/src/c++98/Makefile.in | 6 ++---- 6 files changed, 11 insertions(+), 7 deletions(-) rename libstdc++-v3/src/{c++98 => c++20}/allocator-inst.cc (97%) diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 31449b5b87b..ab001048a67 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -2526,6 +2526,10 @@ GLIBCXX_3.4.32 { GLIBCXX_3.4.33 { # std::basic_file::native_handle() _ZNKSt12__basic_fileIcE13native_handleEv; + + # std::allocator<[cw]>::allocate and ::deallocate for C++20 + _ZNSaI[cw]E8allocateE[jmy]; + _ZNSaI[cw]E10deallocateEP[cw][jmy]; } GLIBCXX_3.4.32; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/src/c++20/Makefile.am b/libstdc++-v3/src/c++20/Makefile.am index a24505e5141..f4a06e6de78 100644 --- a/libstdc++-v3/src/c++20/Makefile.am +++ b/libstdc++-v3/src/c++20/Makefile.am @@ -30,6 +30,7 @@ headers = if ENABLE_EXTERN_TEMPLATE # XTEMPLATE_FLAGS = -fno-implicit-templates inst_sources = \ + allocator-inst.cc \ sstream-inst.cc else # XTEMPLATE_FLAGS = diff --git a/libstdc++-v3/src/c++20/Makefile.in b/libstdc++-v3/src/c++20/Makefile.in index 3ec8c5ce804..ec4c5eec026 100644 --- a/libstdc++-v3/src/c++20/Makefile.in +++ b/libstdc++-v3/src/c++20/Makefile.in @@ -122,7 +122,8 @@ CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libc__20convenience_la_LIBADD = am__objects_1 = tzdb.lo -@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = sstream-inst.lo +@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = allocator-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.lo @GLIBCXX_HOSTED_TRUE@am_libc__20convenience_la_OBJECTS = \ @GLIBCXX_HOSTED_TRUE@ $(am__objects_1) $(am__objects_2) libc__20convenience_la_OBJECTS = $(am_libc__20convenience_la_OBJECTS) @@ -430,6 +431,7 @@ headers = # XTEMPLATE_FLAGS = -fno-implicit-templates @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ allocator-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ sstream-inst.cc sources = tzdb.cc diff --git a/libstdc++-v3/src/c++98/allocator-inst.cc b/libstdc++-v3/src/c++20/allocator-inst.cc similarity index 97% rename from libstdc++-v3/src/c++98/allocator-inst.cc rename to libstdc++-v3/src/c++20/allocator-inst.cc index 1d85eabf2bd..622df42bd84 100644 --- a/libstdc++-v3/src/c++98/allocator-inst.cc +++ b/libstdc++-v3/src/c++20/allocator-inst.cc @@ -26,7 +26,7 @@ // ISO C++ 14882: // -#include +#include namespace std _GLIBCXX_VISIBILITY(default) { diff --git a/libstdc++-v3/src/c++98/Makefile.am b/libstdc++-v3/src/c++98/Makefile.am index d12fdf0f121..69616bbaa11 100644 --- a/libstdc++-v3/src/c++98/Makefile.am +++ b/libstdc++-v3/src/c++98/Makefile.am @@ -96,7 +96,6 @@ endif if ENABLE_EXTERN_TEMPLATE # XTEMPLATE_FLAGS = -fno-implicit-templates inst_sources = \ - allocator-inst.cc \ concept-inst.cc \ ext-inst.cc \ misc-inst.cc diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in index 95e909b1049..87d14e04fc5 100644 --- a/libstdc++-v3/src/c++98/Makefile.in +++ b/libstdc++-v3/src/c++98/Makefile.in @@ -130,9 +130,8 @@ am__objects_3 = $(am__objects_2) codecvt_members.lo collate_members.lo \ messages_members.lo monetary_members.lo numeric_members.lo \ time_members.lo am__objects_4 = c++locale.lo -@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_5 = allocator-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ concept-inst.lo ext-inst.lo \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ misc-inst.lo +@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_5 = concept-inst.lo \ +@ENABLE_EXTERN_TEMPLATE_TRUE@ ext-inst.lo misc-inst.lo am__objects_6 = parallel_settings.lo am__objects_7 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \ codecvt.lo complex_io.lo globals_io.lo hash_tr1.lo \ @@ -478,7 +477,6 @@ host_sources_extra = \ # XTEMPLATE_FLAGS = -fno-implicit-templates @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \ -@ENABLE_EXTERN_TEMPLATE_TRUE@ allocator-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ concept-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ ext-inst.cc \ @ENABLE_EXTERN_TEMPLATE_TRUE@ misc-inst.cc