We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2087

Summary: No _chkstk implementation
Product: SDL Reporter: norfanin
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: cdifan
Version: 2.0.0   
Hardware: x86   
OS: Windows (All)   

Description norfanin 2013-09-05 10:25:56 UTC
On Windows, if SDL is compiled targeting x86 and without a C runtime library the SDL_stlib.c defines a _chkstk symbol, but there are no actual instructions for this function.

This is not a problem if SDL is compiled as a dynamic library as it doesn't seem to generate any _chkstk calls. However, people want to link it statically now and their code might generate those calls which will cause the application to terminate pretty fast.

I would recommend everyone to compile SDL 2.0.0 with HAVE_LIBC defined and the Visual C++ runtime library when using MSVC and linking SDL statically on Windows x86.

Writing an actual implementation probably requires some knowledge about the Microsoft implementation. Copying theirs obviously has licensing issues.

Here's the disassembly that shows the issue in code form.

--- src\stdlib\sdl_stdlib.c -----------------------
SDL_toupper:
 mov         eax,dword ptr [esp+4]  
 lea         ecx,[eax-61h]  
 cmp         ecx,19h  
 ja          SDL_toupper+0Fh (0CC15DFh)  
 add         eax,0FFFFFFE0h  
 ret  
SDL_tolower:
 mov         eax,dword ptr [esp+4]  
 lea         ecx,[eax-41h]  
 cmp         ecx,19h  
 ja          SDL_tolower+0Fh (0CC15EFh)  
 add         eax,20h  
 ret  
_chkstk:
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
 int         3  
_ftol:
 push        ebp  
 mov         ebp,esp  
 sub         esp,20h  
 and         esp,0FFFFFFF0h  
 fld         st(0)  
 fst         dword ptr [esp+18h]  
 fistp       qword ptr [esp+10h]
Comment 1 CD-i Fan 2013-09-23 18:30:53 UTC
If you define HAVE_LIBC, SDL_stdlib.c will not define a _chkstk symbol.
Comment 2 Sam Lantinga 2013-09-28 06:12:38 UTC
Yes, if you compile it as a static library, you should compile with HAVE_LIBC defined.

Thanks!
Comment 3 norfanin 2013-09-28 07:34:07 UTC
And for the case where SDL is a DLL and has no VC++ runtime library? Are the SDL developers just going to be very careful to write code that never emits _chkstk calls? I guess it works with the current version. I'm just worried that this is going to be really annoying for someone in the future.