[PATCH] New -fstack-check implementation (1/n)

Eric Botcazou ebotcazou@adacore.com
Tue Nov 28 17:29:00 GMT 2006


> It's certainly of great interest to Java.  Is the design of this
> documented somewhere?

There are a few bits in the manual of the GCC internals, in the section
"14.9.3 Specifying How Stack Checking is Done"

> I presume there must be some run-time support as well as these compiler
> modifications. 

Definitely, and it has been present in the gcc/ada directory for a long time.

If the target has a MMU and the OS uses guard pages, the compiler emits probes 
before any stack allocations.  Upon reaching the guard pages, the signal will 
be caught by __gnat_error_handler (gcc/ada/init.c) and turned into a regular 
exception.  We (try to) make sure that there is enough room left on the stack 
for the unwinding machinery to propagate this exception.

Otherwise (no MMU or no guard pages, e.g. x86{-64}/Linux), we keep track in 
the runtime of the stack usage for every thread (of course the primary thread 
is special) and the compiler emits explicit calls to the runtime before any 
stack allocations.  It's then up to the runtime to raise the exception 
directly (gcc/ada/s-stchop.ad[sb]).

-- 
Eric Botcazou



More information about the Gcc-patches mailing list