[uClinux-dev] detecting stack overflow

Jun Sun jsun at junsun.net
Sat Feb 21 19:23:56 EST 2009


On Fri, Feb 20, 2009 at 06:34:41PM -0500, Mike Frysinger wrote:
> On Friday 20 February 2009 18:19:51 Jun Sun wrote:
> > Recently we have hit some nasty problems that applications have
> > stack overflow. Our system is no-mmu so that the problems just
> > creaps up in all weired ways.
> >
> > I was wondering whether it is possible to add stack overflow
> > detection to kernel (or we already have it?).
> >
> > Basically kernel knows the stack size when a thread is created.
> > It just writes some magic words at the end of stack. When the thread
> > is freed, it will check again to see if the magic words are still
> > there. If not, the stack is probably correcupted.  It is a common
> > technique in RTOS.
> 
> it doesnt really make sense to have the stack checking in the kernel.  the 
> kernel creates the application stack, but it has nothing to do really with 
> thread stacks.  plus, by the time "the thread is freed", having a blown stack 
> is too late and most likely useless to know.
> 
> gcc-4.x already implements SSP support.  see if your arch supports it.  
> otherwise check out mudflap.
> -mike

Mudflap looks pretty powerful. I assume -heur-stack-bound would achieve
simiilar goal?

My compiler is arm-linux gcc 3.4. Unfortunately when I pass 
-fmudflap to the compiler, it complains:

ucfront-gcc arm-linux-gcc  -g -pipe -msoft-float -fno-common -fno-builtin -Wall   -DEMBED -D__PIC__ -fpic -msingle-pic-base -Dlinux -D__linux__ -Dunix -D__uClinux__ -fmudflap -c -o mem-test.o mem-test.c
cc1: error: unrecognized command line option "-fmudflap"

Do I need to build the toolchain differently to support mudflap? Any
pointers?

Cheers.

Jun



More information about the uClinux-dev mailing list