Commit 36dcd51bbd for qemu.org
commit 36dcd51bbd87168879a29620e8bbefe678d82c12
Author: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Date: Mon Nov 30 15:11:53 2026 -0700
meson.build: windows-arm64 build fix, use _setjmpex instead of (removed) __mingw_setjmp
mingw-w64 removed __mingw_setjmp for aarch64, as its usage was
replaced by _setjmpex, which has the same functionality:
https://github.com/mingw-w64/mingw-w64/commit/326b51ef75c4dde099edb063a573b7d114a93af1
This change reached MSYS2 with toolchain update a few days ago,
mingw-w64-clang-aarch64-crt14.0.0.r757.g7dceb7d77, and configure now
fails on windows-arm64:
ld.lld: error: undefined symbol: __mingw_setjmp
../meson.build:3226:4: ERROR: Problem encountered: mingw must provide
setjmp/longjmp for windows-arm64
_setjmpex is provided by the Windows CRT, so this works with
both older and newer mingw-w64 versions.
Reviewed-by: Mohamed Mediouni <mohamed.mediouni@linaro.org>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/5052
Link: https://lore.kernel.org/qemu-devel/20261130221153.1182504-1-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
diff --git a/include/system/os-win32.h b/include/system/os-win32.h
index 22d72babdf..f3896763cd 100644
--- a/include/system/os-win32.h
+++ b/include/system/os-win32.h
@@ -56,19 +56,21 @@ extern "C" {
/*
* On windows-arm64, setjmp is available in only one variant, and longjmp always
* does stack unwinding. This crash with generated code.
- * Thus, we use another implementation of setjmp (not windows one), coming from
+ * Thus, we use another implementation of longjmp (not windows one), coming from
* mingw, which never performs stack unwinding.
+ *
+ * mingw used to provide __mingw_setjmp, but it was removed in favor of
+ * _setjmpex(env, NULL):
+ * https://github.com/mingw-w64/mingw-w64/commit/326b51ef75c4dde099edb063a573b7d114a93af1
*/
#undef setjmp
#undef longjmp
/*
- * These functions are not declared in setjmp.h because __aarch64__ defines
- * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a,
- * which gets linked automatically.
+ * __mingw_longjmp is not always declared in setjmp.h, but it is defined in
+ * libmingwex.a, which gets linked automatically.
*/
-int __mingw_setjmp(jmp_buf);
void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
-#define setjmp(env) __mingw_setjmp(env)
+#define setjmp(env) _setjmpex(env, NULL)
#define longjmp(env, val) __mingw_longjmp(env, val)
#elif defined(_WIN64)
/*
diff --git a/meson.build b/meson.build
index f8dd3926dd..35e10d8cf1 100644
--- a/meson.build
+++ b/meson.build
@@ -3209,15 +3209,15 @@ endif
if host_os == 'windows'
mingw_has_setjmp_longjmp = cc.links('''
#include <setjmp.h>
+ #include <stddef.h>
int main(void) {
/*
- * These functions are not available in setjmp header, but may be
+ * __mingw_longjmp is not always declared in setjmp header, but may be
* available at link time, from libmingwex.a.
*/
- extern int __mingw_setjmp(jmp_buf);
extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
jmp_buf env;
- __mingw_setjmp(env);
+ _setjmpex(env, NULL);
__mingw_longjmp(env, 0);
}
''', name: 'mingw setjmp and longjmp')