[PATCH] New -fstack-check implementation

H.J. Lu hjl.tools@gmail.com
Sat Mar 29 23:39:00 GMT 2008


On Sat, Mar 29, 2008 at 11:14:23PM +0100, Eric Botcazou wrote:
> Hi,
> 
> Due to popular demand :-), I'm again submitting the new stack checking 
> implementation that we have been using at AdaCore for a few years now.
> 
> Previous submissions:
>   http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01239.html
>   http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01846.html
> 
> But, contrary to the above submissions, this one contains the full set of 
> changes (modulo some adjustments in the Ada runtime and *-unwind.h files for 
> non-Linux platforms).
> 
> -fstack-check is broken in the 4.x series of compilers in the sense that you 
> cannot recover from a stack overflow condition (for example in Ada).  It's a 
> regression from the 3.x series although there were bugs in that series too.
> 
> Moreover, the original implementation comes with several drawbacks:
> - modified allocation strategy for large objects: they will always be
> allocated dynamically if their size exceeds a fixed threshold.
> - fixed limit on the size of the static frame of functions: when it is
> topped by a particular function, stack checking is not reliable and
> a warning is issued by the compiler.
> - inefficiency: because of both the modified allocation strategy and the
> generic implementation, the performances of the code are unnecessarily 
> hampered.
> 
> We are proposing a new implementation that eliminates the aforementioned 
> drawbacks.  It is based on partial support code in the architecture 
> back-ends, modelled on what the Alpha back-end already has because of the 
> requirement of the Tru64 ABI.  We implemented it on Alpha/Tru64, x86/Linux, 
> x86/Solaris, x86/FreeBSD, x86/Windows, x86/VxWorks, x86/LynxOS, x86-64/Linux, 
> MIPS/IRIX (n32), SPARC/Solaris, SPARC64/Solaris, PA/HP-UX, PowerPC/AIX, 
> PowerPC/VxWorks, PowerPC/LynxOS, IA-64/Linux and IA-64/HP-UX in 3.4.x, 4.1.x 
> and 4.3.x based compilers.
> 
> The new mechanism doesn't eliminate the old one, the option -fold-stack-check 
> even makes it possible to select the latter when the former is available.  On 
> architectures without specific support code, -fstack-check is equivalent to 
> -fold-stack-check.
> 
> Tested on i586-suse-linux.  Although the changes are mostly orthogonal to the 
> rest of the compiler, suggestions are welcome as to what the best procedure 
> for integrating this patch in the compiler would be.
> 
> 

Does it work with stack alignment? You can check out stack alignment
branch at

svn://gcc.gnu.org/svn/gcc/branches/stack

We are planning to merge it to mainline at stage 1.

Thanks.


H.J.



More information about the Gcc-patches mailing list