This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
stack alignment bug in gcc 2.95.1
- To: gcc-bugs at gcc dot gnu dot org
- Subject: stack alignment bug in gcc 2.95.1
- From: stevenj at hunsmac dot mit dot edu (Steven G. Johnson)
- Date: Wed, 27 Oct 1999 15:48:12 -0400
- Cc: athena at fftw dot org, hjl at gnu dot org, stevenj at mit dot edu
I have encountered a case where gcc 2.95.1 does not correctly align
the stack to a multiple of 16 bytes (or even 8 bytes), even though
it is supposed to do so by default on x86 (according to the documentation
for -mpreferred-stack-boundary). This causes a large performance
penalty for accessing misaligned double variables. I have a small
test program exhibiting the bug, listed below.
gcc version: 2.95.1
system: Linux/x86 (Pentium II and III), Redhat 5.2, kernel 2.0.36
compiler options:
gcc -O -malign-double align_bug.c -o align_bug -lm && ./align_bug
The source code for align_bug.c is listed below (it doesn't use the
preprocessor so this is the same as the preprocessed output). Pay
special attention to function blah(), which declares a double variable
foobar and calls abort() if the address of foobar is not a multiple
of 8. Thus, when foobar is misaligned (which it should never be if
gcc were operating correctly), the program coredumps.
Thanks for any help or suggestions!
Cordially,
Steven G. Johnson
struct yuck {
int blechh;
};
int one(void)
{
return 1;
}
struct yuck ick(void)
{
struct yuck y;
y.blechh = 3;
return y;
}
void blah(int foo)
{
double foobar;
if ((((long) &foobar) & 0x7)) abort();
}
int main(void)
{
struct yuck y;
y = ick();
blah(one());
return 0;
}