Ross Ridge wrote: > Normally it's not a problem, but if you have any callbacks in your code > (eg. the one that starts the secondary thread) that are called by library > functions not compiled with GCC, then the stack can get misaligned.
tbp wrote: > Every library under my control were recompiled with gcc3.4 and more > specifically SDL that i used to spawn those threads. Apparently the code that SDL calls to create the threads doesn't create threads with aligned stacks. If SDL is using Cygwin functions to create threads but these functions are creating threads that don't have 16-byte aligned stacks then this is a Cygwin problem. > > It's an ABI incompatiblity issue, GCC expects a 16-byte aligned stack, > > but the Windows ABI, to the extent one actually exists, only assumes > > a 4-byte aligned stack (and even that's not a strict requirement). > Is there an official or semi official way to fix it or do i have to > insert something like "mov esp, eax; and 0x15, eax; sub eax, esp" where > it helps? You need to write an assembler function (you can't use inline assembly to fix this problem reliably) for each callback function in your code that's called *directly* by a function that's not compile with GCC. Something like this: .global _new_thread_callback_align_stack _new_thread_callback_align_stack: pushl %ebp movl %esp,%ebp subl $4*2, %esp /* subtract total size of all args */ andl $~15, %esp /* align stack */ movl 8(%ebp),%eax /* incoming arg 1 */ movl %eax,(%esp) /* outgoing arg 1 */ movl 12(%ebp),%eax /* incoming arg 2 */ movl %eax,4(%esp) /* outgoing arg 2 */ call _new_thread_callback leave ret > PS: I've never found out how to build a 'cygming special' binary from > gcc sources, i can only make a cygwin or mingw. What's the trick? Download and compile the Cygwin modified sources. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/u/rridge/ db // -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/