[newlib-cygwin/main] Cygwin: Fix SEH and signal handling on AArch64
Corinna Vinschen
corinna@sourceware.org
Mon Mar 30 08:32:30 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2a953c1837cb331568c19b472e2c48d72c78d8b8
commit 2a953c1837cb331568c19b472e2c48d72c78d8b8
Author: Igor Podgainoi <Igor.Podgainoi@arm.com>
AuthorDate: Fri Mar 27 12:43:12 2026 +0000
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Mon Mar 30 10:21:15 2026 +0200
Cygwin: Fix SEH and signal handling on AArch64
This patch adds the SEH_CODE macro (defined in exception.h), allowing
a single EXCEPTION_HANDLER_DATA metadata definition to be used on both
AArch64 and x86_64 architectures.
It also fixes an issue related to stack replacement in _dll_crt0 that
impacts SEH and signal handling, where due to an epilogue optimization
on AArch64 the epilogue might appear before _main_tls->call. However,
after the stack replacement this optimization becomes broken.
This patch prevents an epilogue from appearing before _main_tls->call
on AArch64 by inserting a compiler barrier after _main_tls->call.
Tests fixed on AArch64:
winsup.api/mmaptest03.exe
winsup.api/shmtest.exe (partially)
winsup.api/ltp/mmap05.exe
winsup.api/ltp/munmap01.exe
winsup.api/ltp/munmap02.exe
Signed-off-by: Evgeny Karpov <evgeny.karpov@arm.com>
Signed-off-by: Igor Podgainoi <igor.podgainoi@arm.com>
Diff:
---
winsup/cygwin/dcrt0.cc | 6 ++++++
winsup/cygwin/local_includes/exception.h | 13 ++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index e080aa41bca2..e7a837673018 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -1065,6 +1065,12 @@ _dll_crt0 ()
fesetenv (FE_DFL_ENV);
_main_tls = &_my_tls;
_main_tls->call ((DWORD (*) (void *, void *)) dll_crt0_1, NULL);
+#if defined(__aarch64__)
+ /* Add a compiler barrier to prevent the epilogue from appearing before
+ _main_tls->call. The epilogue optimization should not be applied after
+ the stack replacement. */
+ __asm__ ("");
+#endif
}
void
diff --git a/winsup/cygwin/local_includes/exception.h b/winsup/cygwin/local_includes/exception.h
index b26f8ba170a2..fdc4d3e400b6 100644
--- a/winsup/cygwin/local_includes/exception.h
+++ b/winsup/cygwin/local_includes/exception.h
@@ -10,9 +10,13 @@ details. */
#if defined (__aarch64__)
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
-#define EXCEPTION_HANDLER_DATA
-#else
+/* An SEH directive that switches back to the code section. */
+#define SEH_CODE ".text"
+#elif defined(__x86_64__)
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
+#define SEH_CODE ".seh_code"
+#endif
+
#define EXCEPTION_HANDLER_DATA \
asm volatile ("\n\
1: \n\
@@ -21,9 +25,8 @@ details. */
@except \n\
.seh_handlerdata \n\
.long 1 \n\
- .rva 1b, 2f, 2f, 2f \n\
- .seh_code \n")
-#endif
+ .rva 1b, 2f, 2f, 2f \n"\
+ SEH_CODE " \n")
class exception
{
More information about the Cygwin-cvs
mailing list