Problem with the SDL2 package in Cygwin
Takashi Yano
takashi.yano@nifty.ne.jp
Sat Oct 25 12:12:47 GMT 2025
On 2025年10月11日 18:51:14 +0000
Thomas Huth wrote:
>> Hi!
>> In the Hatari project (www.hatari-emu.org), we recently hit a problem in the
> CI when we compile Hatari with Cygwin. A couple of weeks ago, everything
> was working still fine:
>> https://cirrus-ci.com/task/4681700988420096
>> Then it suddenly started failing - also for the very same code level of
> Hatari that was working fine before:
>> https://cirrus-ci.com/task/6377222543507456
>> The only difference was that the SDL2 package of Cygwin recently has been
> upgraded from 2.32.8-1 to 2.32.56-1.
>> Christian Zietz, a user of Hatari who has a Windows installation (I don't)
> debugged the issue a little bit and concluded that it's crashing somewhere
> during exit():
>> https://sourceforge.net/p/hatari/mailman/hatari-devel/thread/00253a75-4089-4d8a-846e-8d5c0a4899ee%40gmx.net/#msg59242465
>> He reproduced it with the following small test program:
>> --------------------- 8< ----------------------------------------
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ cat sdltest.c
> #include <stdio.h>
> #include <SDL.h>
>> int main(int arc, char ** argv) {
>> if (SDL_Init( SDL_INIT_VIDEO ) == 0) {
>> printf("SDL_Init succeeded\n");
> printf("Calling SDL_Quit()\n");
> SDL_Quit();
> }
>> return 0;
> }
> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ sdl2-config --version
> 2.32.56
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ gcc -g -O1 -o sdltest sdltest.c -I /usr/include/SDL2/ -lsdl2
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ ./sdltest
> SDL_Init succeeded
> Calling SDL_Quit()
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ ./sdltest > out.txt
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ cat out.txt
>> WDAGUtilityAccount@9f56fa41-fdda-4d08-96da-76c506c9465a /tmp/sdltest
> $ gdb sdltest.exe
> GNU gdb (GDB) (Cygwin 14.2-1) 14.2
> Copyright (C) 2023 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "x86_64-pc-cygwin".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <https://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
> <http://www.gnu.org/software/gdb/documentation/>.
>> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from sdltest.exe...
> (gdb) run
> Starting program: /tmp/sdltest/sdltest.exe
> [New Thread 7024.0x1918]
> [New Thread 7024.0x1210]
> [New Thread 7024.0x1a80]
> [New Thread 7024.0x18d0]
> SDL_Init succeeded
> Calling SDL_Quit()
>> Thread 1 "sdltest" received signal SIGSEGV, Segmentation fault.
> 0x00000003f96f1020 in ?? ()
> (gdb) bt
> #0 0x00000003f96f1020 in ?? ()
> #1 0x00007ffb2a577a63 in __call_exitprocs (code=code@entry=0, d=d@entry=0x0)
> at /usr/src/debug/cygwin-3.6.4-1/newlib/libc/stdlib/__call_atexit.c:123
> #2 0x00007ffb2a5356ce in exit (code=0) at /usr/src/debug/cygwin-3.6.4-1/newlib/libc/stdlib/exit.c:60
> #3 0x00007ffb2a3d6a98 in cygwin_exit (n=0) at /usr/src/debug/cygwin-3.6.4-1/winsup/cygwin/dcrt0.cc:1238
> #4 0x00007ffb2a3d80d4 in dll_crt0_1 () at /usr/src/debug/cygwin-3.6.4-1/winsup/cygwin/dcrt0.cc:1003
> #5 0x00007ffb2a3d5d05 in _cygtls::call2 (this=0x7ffffce00, func=0x7ffb2a3d707c <dll_crt0_1(void*)>, arg=0x0,
> buf=buf@entry=0x7ffffcdf0) at /usr/src/debug/cygwin-3.6.4-1/winsup/cygwin/cygtls.cc:41
> #6 0x00007ffb2a3d5dbb in _cygtls::call (func=<optimized out>, arg=<optimized out>)
> at /usr/src/debug/cygwin-3.6.4-1/winsup/cygwin/cygtls.cc:28
> #7 0x0000000000000000 in ?? ()
> (gdb)
>> --------------------- 8< ----------------------------------------
>> Could someone please have a look?
Thanks for the report.
I looked into this problem, and found this issue is not a bug of
SDL2/SDL3 package.
Attached simple test case also reproduces the same issue.
I also found the following patch against cygwin1.dll resolves
the issue. I'll submit the patch to cygwin-patches mailing list
after aome more review by myself.
diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc
index 1369165c9..42ee73c79 100644
--- a/winsup/cygwin/dll_init.cc
+++ b/winsup/cygwin/dll_init.cc
@@ -584,7 +584,8 @@ dll_list::detach (void *retaddr)
/* Ensure our exception handler is enabled for destructors */
exception protect;
/* Call finalize function if we are not already exiting */
- if (!exit_state)
+ /* Loaded DLLs need finalize function even in the exiting state */
+ if (!exit_state || d->type == DLL_LOAD)
__cxa_finalize (d->handle);
d->run_dtors ();
}
@@ -609,9 +610,10 @@ dll_list::init ()
/* Walk the dll chain, initializing each dll */
dll *d = &start;
dll_global_dtors_recorded = d->next != NULL;
- /* Init linked and early loaded Cygwin DLLs. */
+ /* Init linked Cygwin DLLs. As for loaded DLLs, dll::init() is already
+ called from dlopen(). */
while ((d = d->next))
- if (d->type == DLL_LINK || d->type == DLL_LOAD)
+ if (d->type == DLL_LINK)
d->init ();
}
--
Takashi Yano <takashi.yano@nifty.ne.jp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dll2.c
Type: text/x-csrc
Size: 398 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20251025/5370b3bc/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dll3.c
Type: text/x-csrc
Size: 265 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20251025/5370b3bc/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 57 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20251025/5370b3bc/attachment-0002.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <https://cygwin.com/pipermail/cygwin/attachments/20251025/5370b3bc/attachment.ksh>
More information about the Cygwin
mailing list