From patchwork Thu Jan 12 21:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1725527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=XNS2MQDM; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NtHJZ03pLz23fd for ; Fri, 13 Jan 2023 08:10:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39FEA38493F9 for ; Thu, 12 Jan 2023 21:10:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39FEA38493F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673557832; bh=0FPWuiZHUmAgScZsexn9rScn0wRQgaCfdXrkClPls5g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XNS2MQDMTrDX0My8eemcIbfp/EzY2D8KPUdt+UlHWnMvJs8mc0m+rkwOaAJwfayx0 68iLUSPIKRyZtIzM3+2PyMJTOyfUY8HUaJLA1BiPyv5W9dy2gvslDI71IpZy8a3i0l 0/k//gDHGLvS0aQiY64hZJRyYZa+IHeQft3Ao1hA= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 03D4B3858C66 for ; Thu, 12 Jan 2023 21:10:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03D4B3858C66 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-f1OL_ISTMtG18tZIsulcyQ-1; Thu, 12 Jan 2023 16:10:11 -0500 X-MC-Unique: f1OL_ISTMtG18tZIsulcyQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D1493811F3D; Thu, 12 Jan 2023 21:10:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 007DD2166B26; Thu, 12 Jan 2023 21:10:10 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Eric Botcazou , Jonathan Yong <10walls@gmail.com> Subject: [PATCH] libstdc++: Fix unintended layout change to std::basic_filebuf [PR108331] Date: Thu, 12 Jan 2023 21:10:10 +0000 Message-Id: <20230112211010.932966-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux. Bootstrapped x86_64-w64-mingw32 with both --enable-threads=posix and --enable-threads=win32. I need a libgcc or mingw maintainer to approve the gthr-win32.h part. OK for trunk? -- >8 -- GCC 13 has a new implementation of gthr-win32.h which supports C++11 mutexes, threads etc. but this causes an unintended ABI break. The __gthread_mutex_t type is always used in std::basic_filebuf even in C++98, so independent of whether C++11 sync primitives work or not. Because that type changed for the win32 thread model, we have a layout change in std::basic_filebuf. The member is completely unused, it just gets passed to the std::__basic_file constructor and ignored. So we don't need that mutex to actually work, we just need its layout to not change. Introduce a new __gthr_win32_legacy_mutex_t struct in gthr-win32.h with the old layout, and conditionally use that in std::basic_filebuf. PR libstdc++/108331 libgcc/ChangeLog: * config/i386/gthr-win32.h (__gthr_win32_legacy_mutex_t): New struct matching the previous __gthread_mutex_t struct. (__GTHREAD_LEGACY_MUTEX_T): Define. libstdc++-v3/ChangeLog: * config/io/c_io_stdio.h (__c_lock): Define as a typedef for __GTHREAD_LEGACY_MUTEX_T if defined. --- libgcc/config/i386/gthr-win32.h | 8 ++++++++ libstdc++-v3/config/io/c_io_stdio.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/libgcc/config/i386/gthr-win32.h b/libgcc/config/i386/gthr-win32.h index 146357fa436..050c7a21fcc 100644 --- a/libgcc/config/i386/gthr-win32.h +++ b/libgcc/config/i386/gthr-win32.h @@ -381,6 +381,14 @@ typedef struct timespec __gthread_time_t; #define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function #define __GTHREAD_TIME_INIT {0, 0} +// Libstdc++ std::basic_filebuf needs the old definition of __gthread_mutex_t +// for layout purposes, but doesn't actually use it. +typedef struct { + long __unused1; + void *__unused2; +} __gthr_win32_legacy_mutex_t; +#define __GTHREAD_LEGACY_MUTEX_T __gthr_win32_legacy_mutex_t + #if defined (_WIN32) && !defined(__CYGWIN__) #define MINGW32_SUPPORTS_MT_EH 1 /* Mingw runtime >= v0.3 provides a magic variable that is set to nonzero diff --git a/libstdc++-v3/config/io/c_io_stdio.h b/libstdc++-v3/config/io/c_io_stdio.h index 1a5e05a844a..e9e6e3ef4d8 100644 --- a/libstdc++-v3/config/io/c_io_stdio.h +++ b/libstdc++-v3/config/io/c_io_stdio.h @@ -39,7 +39,14 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#ifdef __GTHREAD_LEGACY_MUTEX_T + // The layout of __gthread_mutex_t changed in GCC 13, but libstdc++ doesn't + // actually use the basic_filebuf::_M_lock member, so define it consistently + // with the old __gthread_mutex_t to avoid an unnecessary layout change: + typedef __GTHREAD_LEGACY_MUTEX_T __c_lock; +#else typedef __gthread_mutex_t __c_lock; +#endif // for basic_file.h typedef FILE __c_file;