gcc -fstack protector 原理

zephyr s32k144

linux上见到过stack protector的call stack 打印知道它依赖编译器的支持, 没想到zephyr上也添加了支持

摘自gcc官网对这个编译选项的解释:

-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.

-fstack-protector-all

Like -fstack-protector except that all functions are protected.

zephyr上面该config的名字是CONFIG_STACK_CANARIES

该config的详细依赖与详细解释参考zephyr官网:

https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_STACK_CANARIES.html?highlight=config_stack_canaries

打开这个config后制造一次踩栈实验

对比asm文件

你可能感兴趣的:(ARM,C语言,编译原理)