This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

stack alignment bug in gcc 2.95.1


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]