2009/7/2 Ian Lance Taylor <iant@xxxxxxxxxx>: > The intention is that if the stack is not mapped, the store will trigger > a fault--an access to an invalid memory address. Based on the address, > the OS will recognize that this access is to the stack, and will > automatically increase the stack size. Or, if that is not possible, the > OS will halt the program. > > I suspect that -fstack-check does not do what you think it does. It > doesn't check that you are using the stack correctly. It checks that > you do not run past the end of the stack. This avoids a certain class > of errors which can arise when using functions with very large stack > frames in a multi-threaded program: such functions can accidentally skip > into the stack frame of a different thread. > > Ian > $cat stack_check.c ------------------------------- void foo() { char buf[8]; int a = rand(); buf[0] = 0; buf[1] = 1; buf[2] = 2; buf[3] = 3; buf[4] = 4; buf[5] = 5; buf[6] = 6; buf[7] = 7; buf[8] = 8; } int main(int argc, char *argv[]) { srand(time(NULL)); foo(); return 0; } ------------------------------- $gcc -fstack-check stack_check.c $./a.exe 9 [main] a 2796 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped) On i386 arch, gcc is smart enough to check if the stack is corrupted. I wonder if there is some way to do this on MIPS. PRC Jul 2,2009