Re: Stack direction check fails with optimizations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ralf Wildenhues wrote:
* Peter O'Gorman wrote on Tue, Dec 12, 2006 at 01:26:42PM CET:
There is a test to check the stack direction when building the
replacement alloca. This test returns bad results with optimizations:
[...]
  exit (find_stack_direction () < 0);

It also fails with -xO2 on HPUX11.23/IA64. I realize that both these
platforms have alloca so the autoconf test will never be run, but am
wondering if any of the gurus on this list can come up with any ideas
for a working test with optimizations. The problem is, of course, that
the compiler inlines everything when optimizing so the results are
not valid.

I think the ISO C answer is that a guaranteed working test is not
possible: you may not compare pointers to distinct objects.

In practice, you can make optimization harder by adding a second
translation unit which has an intermediate function that is called
by and calls itself find_stack_direction.  But that's nowhere near
bulletproof, with compilers that do link-time optimization.

What about invoking the function indirectly, i.e. declare a pointer to the function, set it to the function, and call the function via the pointer? I'm sure there are some tricks that can be done to ensure that the compiler isn't so clever that it can optimize even this (like, say, have two functionally identical yet distinct versions of the function, and pick one based on some unpredictable data such as the process' pid or the existence of some particular environment variable ).

--
Matthew
"unsubscribe me plz!!" -- Newbies



_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux