public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-5143] libstdc++: Fix unintended layout change to std::basic_filebuf [PR108331] Date: Fri, 13 Jan 2023 13:42:43 +0000 (GMT) [thread overview] Message-ID: <20230113134243.E9D1D3858C39@sourceware.org> (raw) https://gcc.gnu.org/g:e2fc12a5dafadf15d804e1d2541528296e97a847 commit r13-5143-ge2fc12a5dafadf15d804e1d2541528296e97a847 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Jan 12 10:40:49 2023 +0000 libstdc++: Fix unintended layout change to std::basic_filebuf [PR108331] 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. Diff: --- 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;
reply other threads:[~2023-01-13 13:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230113134243.E9D1D3858C39@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).