delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/04/28/18:46:35

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Subject: Re: g++ 3.4.0 cygwin, codegen SSE & alignement issues
In-Reply-To: <408FCABF.2050702@ompf.org>
To: gcc AT ompf DOT org
Date: Wed, 28 Apr 2004 18:46:15 -0400 (EDT)
Cc: Ross Ridge <rridge AT csclub DOT uwaterloo DOT ca>, cygwin AT cygwin DOT com
MIME-Version: 1.0
Message-Id: <20040428224615.2B667A8663@perpugilliam.csclub.uwaterloo.ca>
From: rridge AT csclub DOT uwaterloo DOT ca (Ross Ridge)

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]  rridge AT csclub DOT uwaterloo DOT ca
-()-/()/  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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019