Subject: Re: g++ 3.4.0 cygwin, codegen SSE & alignement issues
From: [email-masked] (Ross Ridge)
To: [email-masked]
Cc: [email-masked]
Date: Wed, 28 Apr 2004 05:06:39 -0400 (EDT)

tbp wrote:
>Building an app of mine (multithreaded) with something like -O3 -march=k8
>the binary died with an illegal instruction. The offending instruction
>was a 'movaps %xmm0, 0x40(%esp)' with an unaligned esp.  As that was
>on a secondary thread after some external calls (opengl and so on)
>i thought it had to do with some cygwin/ABI issue or something.

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).
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.
 
>And 1hour ago i got g++ to produce that sequence (same app,
>slightly different compilation switches like -mfpmath=sse,387): 'xorps
>0x435d7c,%xmm1' That one is clearly wrong and doesn't have to do with
>stack alignment.

This is a GCC and/or Binutils (as/ld) bug.  GCC puts constants in the
".rdata" section, but this section only 4-byte aligned.

>Take note that my app doesn't generate sse1/2 on its own, it all comes
>from gcc.

Well, that makes the workaround simple, just use the "-mno-sse",
"-mno-sse2" options, don't use the "-mfpmath=sse" option and GCC shouldn't
generate any SSE1/2 instructions.

						Ross Ridge

-- 
 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  [email-masked]
-()-/()/  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/