[newlib-cygwin/main] Cygwin: Fix SEH and signal handling on AArch64
Corinna Vinschen via Cygwin-cvs <[email protected]> Mon, 30 Mar 2026 08:32:30 +0000 (GMT)
| Newsgroups | gmane.os.cygwin.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D2a953c1837c= b331568c19b472e2c48d72c78d8b8 commit 2a953c1837cb331568c19b472e2c48d72c78d8b8 Author: Igor Podgainoi <[email protected]> AuthorDate: Fri Mar 27 12:43:12 2026 +0000 Commit: Corinna Vinschen <[email protected]> CommitDate: Mon Mar 30 10:21:15 2026 +0200 Cygwin: Fix SEH and signal handling on AArch64 =20 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. =20 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. =20 This patch prevents an epilogue from appearing before _main_tls->call on AArch64 by inserting a compiler barrier after _main_tls->call. =20 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 =20 Signed-off-by: Evgeny Karpov <[email protected]> Signed-off-by: Igor Podgainoi <[email protected]> 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 =3D &_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 } =20 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. */ =20 #if defined (__aarch64__) #define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP= 8_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_RECORDPvP= 8_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") =20 class exception {