Search code examples
linuxdebugginggccstack

Does linux gcc/clang generate debug code to check stack balance?


On windows, VC compiler will generate debug version code with _chkesp implicit functions at the end of function calls, and allocate some 0xCCCCCCCC buffer on the stack to check and prevent stack corruption.

Does gcc/clang has same ability to provide extra stack check/prevention by some command line options? Either additional stack space or stack checkings?


Solution

  • GCC supports the -fstack-protector and -fstack-protector-all options. Note that both are geared toward security hardening rather than debugging. Instead, consider using the GCC/CLANG address sanitizer (ASAN) options (minimal example) or Valgrind (minimal example).