From c7add46792e5f40ac5aa384dffab921d4feda189 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:29:42 +0000 Subject: [PATCH 1/3] mingw-w64-v8: fix abseil MinGW thread-identity aliasing crash and enable Win32Waiter Agent-Logs-Url: https://github.com/r-windows/ucrt-libs/sessions/fb4070fb-25bb-4f73-bf17-b4b1eec84261 Co-authored-by: jeroen <216319+jeroen@users.noreply.github.com> --- .../017-abseil-mingw-thread-fixes.patch | 73 +++++++++++++++++++ mingw-w64-v8/PKGBUILD | 3 + 2 files changed, 76 insertions(+) create mode 100644 mingw-w64-v8/017-abseil-mingw-thread-fixes.patch diff --git a/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch b/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch new file mode 100644 index 0000000..06de4bc --- /dev/null +++ b/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch @@ -0,0 +1,73 @@ +From: fix abseil MinGW thread-identity and waiter issues + +Two related fixes for abseil-cpp when built with MinGW-w64: + +1. Force ABSL_THREAD_IDENTITY_MODE_USE_CPP11 on MinGW. + + On MinGW, abseil selects ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC + because it is excluded from the _WIN32 && !__MINGW32__ CPP11 branch. In + POSIX_SETSPECIFIC mode ClearCurrentThreadIdentity() is a no-op (only an + assert in Release builds). It relies entirely on the pthread runtime + clearing the key value before invoking the destructor. With MinGW's + winpthreads and threads created via _beginthreadex (as V8 does), that + guarantee can fail: the dying thread's TLS slot is not always cleared + before ReclaimThreadIdentity() returns the identity to the free list. A + new thread then allocates that same identity, but the old thread still has + a live TLS reference to it. When V8's WASM engine creates many worker + threads (14.x regression vs 11.x) the race becomes frequent enough to + trigger the abseil Mutex assertion: + Check waitp->thread->waitp == nullptr failed: waiting when shouldn't be + + In CPP11 mode ClearCurrentThreadIdentity() sets thread_identity_ptr=nullptr + before the identity is recycled, closing the aliasing window. This is + already the mode used by MSVC (_WIN32 && !__MINGW32__); we extend it to + cover MinGW as well. + +2. Enable Win32Waiter for MinGW. + + abseil explicitly excludes MinGW from Win32Waiter (which uses the native + SRWLOCK / CONDITION_VARIABLE APIs), falling back to StdcppWaiter. Modern + MinGW-w64 as shipped by MSYS2 fully supports these Vista+ APIs. Using + Win32Waiter avoids the StdcppWaiter's stale waiter_count_/wakeup_count_ + fields on identity reuse (because those fields can be non-zero when an + identity is recycled), and also gives better performance. + +diff --git a/absl/base/internal/thread_identity.h b/absl/base/internal/thread_identity.h +--- a/absl/base/internal/thread_identity.h ++++ b/absl/base/internal/thread_identity.h +@@ -268,6 +268,14 @@ ABSL_NAMESPACE_END + #ifdef ABSL_THREAD_IDENTITY_MODE + #error ABSL_THREAD_IDENTITY_MODE cannot be directly set + #elif defined(ABSL_FORCE_THREAD_IDENTITY_MODE) + #define ABSL_THREAD_IDENTITY_MODE ABSL_FORCE_THREAD_IDENTITY_MODE ++#elif defined(__MINGW32__) && defined(ABSL_HAVE_THREAD_LOCAL) ++// MinGW's winpthreads does not reliably clear pthread TLS before calling key ++// destructors for _beginthreadex-created threads (as used by V8). Use C++11 ++// thread_local so that ClearCurrentThreadIdentity() sets thread_identity_ptr ++// to nullptr before the identity is placed on the free list, preventing a ++// second thread from aliasing the same ThreadIdentity object. ++#define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 + #elif defined(_WIN32) && !defined(__MINGW32__) + #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 + #elif defined(__APPLE__) && defined(ABSL_HAVE_THREAD_LOCAL) +diff --git a/absl/synchronization/internal/win32_waiter.h b/absl/synchronization/internal/win32_waiter.h +--- a/absl/synchronization/internal/win32_waiter.h ++++ b/absl/synchronization/internal/win32_waiter.h +@@ -21,8 +21,8 @@ + #endif + +-#if defined(_WIN32) && !defined(__MINGW32__) && \ +- _WIN32_WINNT >= _WIN32_WINNT_VISTA ++// MinGW-w64 ships SRWLOCK/CONDITION_VARIABLE support; enable Win32Waiter. ++#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA + + #include "absl/base/config.h" + #include "absl/synchronization/internal/kernel_timeout.h" +@@ -67,7 +67,6 @@ ABSL_NAMESPACE_END + } // namespace absl + +-#endif // defined(_WIN32) && !defined(__MINGW32__) && +- // _WIN32_WINNT >= _WIN32_WINNT_VISTA ++#endif // defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA + + #endif // ABSL_SYNCHRONIZATION_INTERNAL_WIN32_WAITER_H_ diff --git a/mingw-w64-v8/PKGBUILD b/mingw-w64-v8/PKGBUILD index 153d574..1975839 100644 --- a/mingw-w64-v8/PKGBUILD +++ b/mingw-w64-v8/PKGBUILD @@ -51,6 +51,7 @@ source=("https://github.com/v8/v8/archive/refs/tags/${pkgver}.tar.gz" "014-heap-use-proper-sources.patch" "015-abseil-build-as-static-lib.patch" "016-zlib-use-system-lib.patch" + "017-abseil-mingw-thread-fixes.patch" "icu.gn" "zlib.gn" "v8_libbase.pc" @@ -87,6 +88,7 @@ sha256sums=('9967736b8381fdf34de72c3f84eebbdb30a867cb94d9a8ff6993504549cc65b5' '2415e05518836b1b3f4c0ca9f993145ba5d9d406ce47d6c7c3cb2fa76fba7c72' '250ca72be5d93c91d23c07478275fcbc09a3f6012a90c44b8af92f9c3e18938b' 'a4275f41723cc990f2f43559ce716100830a8ce3f38e4878f6bf36d70d47b646' + 'bb3367090f9592381c5ae37c99a44767993dfb2108564dcc9fd5704e104f5a33' 'e1bc88af48143f29f5805b8ac5d77addef1b09318d1f5f127a9281872c00303b' '7e1e39a3dc69632f7bf9182c92405186ce709aca921cf0abefadb6fa8b825510' '71ac09cff81a983c63cbeee405a18b092655e6c608da1ede3aacc568edb80b39' @@ -115,6 +117,7 @@ prepare() { echo ":: Patching abseil-cpp directory" cd "${srcdir}"/abseil-cpp patch -p1 -i "${srcdir}"/015-abseil-build-as-static-lib.patch + patch -p1 -i "${srcdir}"/017-abseil-mingw-thread-fixes.patch ln -sf "${srcdir}"/abseil-cpp "${srcdir}"/${_realname}-${pkgver}/third_party echo ":: Patching zlib directory" From 39fd4020fa220c2b75561155a452a15eb32573c0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:45:57 +0000 Subject: [PATCH 2/3] mingw-w64-v8: fix broken abseil patch (correct hunk headers and sha256sum) Agent-Logs-Url: https://github.com/r-windows/ucrt-libs/sessions/eca5d309-9fb0-41a8-bdbe-3c483f431c10 Co-authored-by: jeroen <216319+jeroen@users.noreply.github.com> --- .../017-abseil-mingw-thread-fixes.patch | 60 +++---------------- mingw-w64-v8/PKGBUILD | 2 +- 2 files changed, 10 insertions(+), 52 deletions(-) diff --git a/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch b/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch index 06de4bc..5f21f09 100644 --- a/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch +++ b/mingw-w64-v8/017-abseil-mingw-thread-fixes.patch @@ -1,73 +1,31 @@ -From: fix abseil MinGW thread-identity and waiter issues - -Two related fixes for abseil-cpp when built with MinGW-w64: - -1. Force ABSL_THREAD_IDENTITY_MODE_USE_CPP11 on MinGW. - - On MinGW, abseil selects ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC - because it is excluded from the _WIN32 && !__MINGW32__ CPP11 branch. In - POSIX_SETSPECIFIC mode ClearCurrentThreadIdentity() is a no-op (only an - assert in Release builds). It relies entirely on the pthread runtime - clearing the key value before invoking the destructor. With MinGW's - winpthreads and threads created via _beginthreadex (as V8 does), that - guarantee can fail: the dying thread's TLS slot is not always cleared - before ReclaimThreadIdentity() returns the identity to the free list. A - new thread then allocates that same identity, but the old thread still has - a live TLS reference to it. When V8's WASM engine creates many worker - threads (14.x regression vs 11.x) the race becomes frequent enough to - trigger the abseil Mutex assertion: - Check waitp->thread->waitp == nullptr failed: waiting when shouldn't be - - In CPP11 mode ClearCurrentThreadIdentity() sets thread_identity_ptr=nullptr - before the identity is recycled, closing the aliasing window. This is - already the mode used by MSVC (_WIN32 && !__MINGW32__); we extend it to - cover MinGW as well. - -2. Enable Win32Waiter for MinGW. - - abseil explicitly excludes MinGW from Win32Waiter (which uses the native - SRWLOCK / CONDITION_VARIABLE APIs), falling back to StdcppWaiter. Modern - MinGW-w64 as shipped by MSYS2 fully supports these Vista+ APIs. Using - Win32Waiter avoids the StdcppWaiter's stale waiter_count_/wakeup_count_ - fields on identity reuse (because those fields can be non-zero when an - identity is recycled), and also gives better performance. - -diff --git a/absl/base/internal/thread_identity.h b/absl/base/internal/thread_identity.h --- a/absl/base/internal/thread_identity.h +++ b/absl/base/internal/thread_identity.h -@@ -268,6 +268,14 @@ ABSL_NAMESPACE_END - #ifdef ABSL_THREAD_IDENTITY_MODE +@@ -217,6 +217,8 @@ #error ABSL_THREAD_IDENTITY_MODE cannot be directly set #elif defined(ABSL_FORCE_THREAD_IDENTITY_MODE) #define ABSL_THREAD_IDENTITY_MODE ABSL_FORCE_THREAD_IDENTITY_MODE +#elif defined(__MINGW32__) && defined(ABSL_HAVE_THREAD_LOCAL) -+// MinGW's winpthreads does not reliably clear pthread TLS before calling key -+// destructors for _beginthreadex-created threads (as used by V8). Use C++11 -+// thread_local so that ClearCurrentThreadIdentity() sets thread_identity_ptr -+// to nullptr before the identity is placed on the free list, preventing a -+// second thread from aliasing the same ThreadIdentity object. +#define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 #elif defined(_WIN32) && !defined(__MINGW32__) #define ABSL_THREAD_IDENTITY_MODE ABSL_THREAD_IDENTITY_MODE_USE_CPP11 #elif defined(__APPLE__) && defined(ABSL_HAVE_THREAD_LOCAL) -diff --git a/absl/synchronization/internal/win32_waiter.h b/absl/synchronization/internal/win32_waiter.h --- a/absl/synchronization/internal/win32_waiter.h +++ b/absl/synchronization/internal/win32_waiter.h -@@ -21,8 +21,8 @@ +@@ -20,7 +20,7 @@ + #include #endif -#if defined(_WIN32) && !defined(__MINGW32__) && \ -- _WIN32_WINNT >= _WIN32_WINNT_VISTA -+// MinGW-w64 ships SRWLOCK/CONDITION_VARIABLE support; enable Win32Waiter. -+#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA ++#if defined(_WIN32) && \ + _WIN32_WINNT >= _WIN32_WINNT_VISTA #include "absl/base/config.h" - #include "absl/synchronization/internal/kernel_timeout.h" -@@ -67,7 +67,6 @@ ABSL_NAMESPACE_END +@@ -66,7 +66,7 @@ + ABSL_NAMESPACE_END } // namespace absl -#endif // defined(_WIN32) && !defined(__MINGW32__) && -- // _WIN32_WINNT >= _WIN32_WINNT_VISTA -+#endif // defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA ++#endif // defined(_WIN32) && + // _WIN32_WINNT >= _WIN32_WINNT_VISTA #endif // ABSL_SYNCHRONIZATION_INTERNAL_WIN32_WAITER_H_ diff --git a/mingw-w64-v8/PKGBUILD b/mingw-w64-v8/PKGBUILD index 1975839..2e3e62c 100644 --- a/mingw-w64-v8/PKGBUILD +++ b/mingw-w64-v8/PKGBUILD @@ -88,7 +88,7 @@ sha256sums=('9967736b8381fdf34de72c3f84eebbdb30a867cb94d9a8ff6993504549cc65b5' '2415e05518836b1b3f4c0ca9f993145ba5d9d406ce47d6c7c3cb2fa76fba7c72' '250ca72be5d93c91d23c07478275fcbc09a3f6012a90c44b8af92f9c3e18938b' 'a4275f41723cc990f2f43559ce716100830a8ce3f38e4878f6bf36d70d47b646' - 'bb3367090f9592381c5ae37c99a44767993dfb2108564dcc9fd5704e104f5a33' + '012b2c89ed2933080d8cc49e3654b7c98c96346c445a77a21df18e27b6215abe' 'e1bc88af48143f29f5805b8ac5d77addef1b09318d1f5f127a9281872c00303b' '7e1e39a3dc69632f7bf9182c92405186ce709aca921cf0abefadb6fa8b825510' '71ac09cff81a983c63cbeee405a18b092655e6c608da1ede3aacc568edb80b39' From 10cae194e19c7256fb891d02ce4e37099204717a Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Mon, 13 Apr 2026 22:23:31 +0200 Subject: [PATCH 3/3] Bump v8 version --- mingw-w64-v8/PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mingw-w64-v8/PKGBUILD b/mingw-w64-v8/PKGBUILD index 2e3e62c..746c941 100644 --- a/mingw-w64-v8/PKGBUILD +++ b/mingw-w64-v8/PKGBUILD @@ -4,7 +4,7 @@ _realname=v8 pkgbase=mingw-w64-${_realname} pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}" -pkgver=14.6.202.26 +pkgver=14.6.202.33 pkgrel=2 pkgdesc="Fast and modern Javascript engine (mingw-w64)" arch=('any') @@ -59,7 +59,7 @@ source=("https://github.com/v8/v8/archive/refs/tags/${pkgver}.tar.gz" "v8.pc" "disable-cet.diff" "mingw-printf.diff") -sha256sums=('9967736b8381fdf34de72c3f84eebbdb30a867cb94d9a8ff6993504549cc65b5' +sha256sums=('c467f6745a9066905c5c2d9f1e22e426e1f1cc89365219ee14a17fb78839536f' 'SKIP' 'SKIP' 'SKIP'