From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2BF153858D37; Mon, 9 Jan 2023 11:36:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BF153858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673264210; bh=xtMOgkv22pGJuZ78KUCV5HQoe0dvq0Pl3Mz8f+RIJf0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xIN5WOmo0fNo/ifGGdGMg+WeMwgEhLNnTKlNDPrnUVLALpJ+/9jFIiYQSrYze0wUa LoTnZm0r4saFpk8+MNIkQAZb8USE2V3SzORcPpKmQdXe+Qs3eGG+0FEBpGriQL3iR/ jVLu0LWZ61vT3E8nwzm1hpXxGVqoL7FPiJ3UIq5A= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108331] [13 Regression] ABI break of std::__c_file and std::fstream for win32 thread model of GCC for windows Date: Mon, 09 Jan 2023 11:36:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108331 --- Comment #4 from Jonathan Wakely --- That would be more flexible, but I'm not sure this is a problem that will happen again. This is a particular case where we have a completely unused member variable that just needs a specific layout. It occurs to me libstdc++ could just check the GCC_GTHR_WIN32_H include gua= rd, although an explicitly-defined macro with a documented purpose (even if just via a comment) would be less fragile. How's this? diff --git a/libgcc/config/i386/gthr-win32.h b/libgcc/config/i386/gthr-win3= 2.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_mute= x_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 >=3D 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++ does= n't + // actually use the basic_filebuf::_M_lock member, so define it consiste= ntly + // 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;=