[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA
From: |
Bruno Haible |
Subject: |
Re: bug in check for stack growth direction in _AC_LIBOBJ_ALLOCA |
Date: |
Mon, 20 Jun 2011 23:15:42 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> Hmm, we'll need to backport this improved stack-direction testing to
> gnulib and libsigsegv, then
This is true for gnulib's alloca.c and c-stack.c.
The code in libsigsegv already contains a counter-measure against
tail recursion elimination:
------------------------------------ foo.c ------------------------------------
#include <stdio.h>
int
get_stack_direction ()
{
auto char dummy;
static char *dummyaddr = (char *)0;
if (dummyaddr != (char *)0)
return &dummy > dummyaddr ? 1 : &dummy < dummyaddr ? -1 : 0;
else
{
dummyaddr = &dummy;
{
int result = get_stack_direction ();
/* The next assignment avoids tail recursion elimination
(IRIX 6.4 CC). */
dummyaddr = (char *)0;
return result;
}
}
}
int
main ()
{
printf ("%d\n", get_stack_direction ());
return 0;
}
-------------------------------------------------------------------------------
But it doesn't prevent it safely! With gcc-4.6.0 for x86 and -O3 optimization,
I get the wrong result:
$ /arch/x86-linux/gnu-inst-gcc/4.6.0/bin/gcc -O2 foo.c
$ ./a.out
-1
$ /arch/x86-linux/gnu-inst-gcc/4.6.0/bin/gcc -O3 foo.c
$ ./a.out
1
Bruno
--
In memoriam Neda Agha-Soltan <http://en.wikipedia.org/wiki/Neda_Agha-Soltan>