autoconf
[Top][All Lists]
Advanced

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

Re: Stack direction check fails with optimizations


From: Matthew Woehlke
Subject: Re: Stack direction check fails with optimizations
Date: Wed, 13 Dec 2006 11:40:08 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.0

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]