gcc-3.4.2 or libpthread bug?

James E Wilson wilson@specifixinc.com
Tue Sep 14 21:52:00 GMT 2004


Peter Seiderer wrote:
> the following attached testprogramm gives a SIGSEGV when compiled
> with gcc-3.4.2 and '-march=pentium4 -O2' on my Linux box (Suse-8.2),
> I think because of a misaligned movapd.
> Is it a gcc or a libpthread bug?

I think it could be argued that both are broken.

Gcc is broken because it is emitting SSE vector instructions even though 
you didn't ask for them and the ABI doesn't support them.  The problem 
is in the i386.md negdf2 pattern which emits a movapd if TARGET_SSE2 is 
true, and -march=pentium4 turns on TARGET_SSE2.  The 32-bit x86 ABI says 
that the stack has only 32-bit alignment, so it is not safe to use these 
instructions behind the user's back.

I see two possible ways to fix this.  One is to change the code so that 
TARGET_SSE2 is only enabled for 32-bit code if the user specifies 
-msse2.  This would then be double checked against the CPU target to 
make sure the CPU supports it.  There needs to be a distinction here 
between whether the processor supports the feature, and whether the user 
asked for it to be used.

The other possible solution is to modify the negdf2 pattern to check 
TARGET_64BIT (or something equivalent), so that we only emit movapd when 
we know that it is safe.  This is simpler, and probably better.

It can also be argued that libpthread is broken.  Although the ABI only 
requires 32-bit alignment, new processor features such as SSE require 
64-bit alignment for some instructions, and hence if you want to be able 
to use all processor features, you must align stacks to 64-bits even 
though the ABI only requires 32-bits.

I'd suggest filing a bug report into bugzilla if you haven't already 
done so, so we can track the problem.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



More information about the Gcc mailing list