Skip to content

Conversation

@palves
Copy link
Contributor

@palves palves commented Dec 10, 2024

unordered_dense.h fails to compile on Windows/MinGW with GCC >= 13 with thread model win32, and _WIN32_WINNT < 0x600 (Vista), in CFLAGS/CXXFLAGS. E.g., GDB defines _WIN32_WINNT to 0x501, and it fails to build with GCC 14.2 like so:

   CXX    ada-exp.o
 In file included from /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/shared_mutex:42,
		  from /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/memory_resource:66,
		  from /home/pedro/gdb/src/gdb/../gdbsupport/unordered_dense.h:104,
		  from /home/pedro/gdb/src/gdb/../gdbsupport/unordered_map.h:21,
		  from /home/pedro/gdb/src/gdb/gdbtypes.h:53,
		  from /home/pedro/gdb/src/gdb/expression.h:23,
		  from /home/pedro/gdb/src/gdb/ada-exp.y:40:
 /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/bits/std_mutex.h:164:5: error: '__gthread_cond_t' does not name a type; did you mean '__gthread_once_t'?
   164 |     __gthread_cond_t* native_handle() noexcept { return &_M_cond; }
       |     ^~~~~~~~~~~~~~~~
       |     __gthread_once_t
 (... snip other instances of same ...)

The problem is that unordered_dense.h includes <memory_resource>, which uses std::mutex, and thus needs to include <mutex>. (See https://quuxplusone.github.io/blog/2018/06/05/libcpp-memory-resource, "Notice that synchronized_pool_resource contains a mutex, which means that <memory_resource> effectively must include <mutex>.")

GCC 13 rewrote the win32 thread model support, and in that rewrite, support for __gthread_cond_t in std_mutex.h became conditional on _WIN32_WINNT >= 0x600.

GCC/libstdc++ also has <experimental/memory_resource> so with this patch, such a configuration takes that branch and succeeds, because <experimental/memory_resource> does not include <mutex>.

Tested with MinGW-w64 GCC 14.2, posix and win32 models.
Tested with MinGW-w64 GCC 10.1, posix and win32 models.
Tested with GNU/Linux GCC 11.4.0.

@palves palves force-pushed the palves/mingw-win32-model branch from b931c00 to d6ce051 Compare December 10, 2024 21:00
unordered_dense.h fails to compile on Windows/MinGW with GCC >= 13
with thread model win32, and _WIN32_WINNT < 0x600 (Vista), in
CFLAGS/CXXFLAGS.  E.g., GDB defines _WIN32_WINNT to 0x501, and it
fails to build with GCC 14.2 like so:

   CXX    ada-exp.o
 In file included from /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/shared_mutex:42,
		  from /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/memory_resource:66,
		  from /home/pedro/gdb/src/gdb/../gdbsupport/unordered_dense.h:104,
		  from /home/pedro/gdb/src/gdb/../gdbsupport/unordered_map.h:21,
		  from /home/pedro/gdb/src/gdb/gdbtypes.h:53,
		  from /home/pedro/gdb/src/gdb/expression.h:23,
		  from /home/pedro/gdb/src/gdb/ada-exp.y:40:
 /opt/xpack-mingw-w64-gcc-14.2.0-1/x86_64-w64-mingw32/include/c++/14.2.0/bits/std_mutex.h:164:5: error: '__gthread_cond_t' does not name a type; did you mean '__gthread_once_t'?
   164 |     __gthread_cond_t* native_handle() noexcept { return &_M_cond; }
       |     ^~~~~~~~~~~~~~~~
       |     __gthread_once_t
 (... snip other instances of same ...)

The problem is that unordered_dense.h includes <memory_resource>,
which uses std::mutex, and thus needs to include <mutex>.  (See
<https://quuxplusone.github.io/blog/2018/06/05/libcpp-memory-resource>,
"Notice that synchronized_pool_resource contains a mutex, which means
that <memory_resource> effectively must include <mutex>.")

GCC 13 rewrote the win32 thread model support, and in that rewrite,
support for __gthread_cond_t in std_mutex.h became conditional on
_WIN32_WINNT >= 0x600.

GCC/libstdc++ also has <experimental/memory_resource> so with this
patch, such a configuration takes that branch and succeeds, because
<experimental/memory_resource> does not include <mutex>.

Tested with MinGW-w64 GCC 14.2, posix and win32 models.
Tested with MinGW-w64 GCC 10.1, posix and win32 models.
Tested with GNU/Linux GCC 11.4.0.
@martinus martinus force-pushed the palves/mingw-win32-model branch from d6ce051 to d2589d8 Compare October 6, 2025 11:58
@martinus
Copy link
Owner

martinus commented Oct 6, 2025

Thanks, and sorry it took me so long

@martinus martinus merged commit 0314c5f into martinus:main Oct 6, 2025
4 checks passed
kraj pushed a commit to kraj/binutils-gdb that referenced this pull request Oct 8, 2025
This version brings a fix made by Pedro [1] to fix compilation on some
Windows systems.

[1] martinus/unordered_dense#132

Change-Id: I5cedec0e644074e2274346ecc1c73e5be00f84b0
saagarjha pushed a commit to ahjragaas/binutils-gdb that referenced this pull request Oct 27, 2025
This version brings a fix made by Pedro [1] to fix compilation on some
Windows systems.

[1] martinus/unordered_dense#132

Change-Id: I5cedec0e644074e2274346ecc1c73e5be00f84b0
Approved-By: Tom Tromey <tom@tromey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants