본문 바로가기

Engineering/Etc

stack 깨질때 gcc compile 옵션

728x90

스택깨질때 gcc 컴파일 옵션


http://gcc.gnu.org/onlinedocs/gcc-4.2.3/gcc/Optimize-Options.html


- 디버깅 할때 스택이 깨지는 경우 또는 stack overflow 를 막기 위해 다음 옵션 사용

- mac os 에서는 디폴트로 사용됨


-fstack-protector
Emit extra code to check for buffer overflows, such as stack smashing attacks. This is done by adding a guard variable to functions with vulnerable objects. This includes functions that call alloca, and functions with buffers larger than 8 bytes. The guards are initialized when a function is entered and then checked when the function exits. If a guard check fails, an error message is printed and the program exits.