我想要启用gcc的canaries生成,但是出现了对__stack_chk_guard的未定义引用。
来自gcc关于canaries的手册:
-mstack-protector-guard=guard
Generate stack protection code using canary at guard. Supported locations are global for
global canary or tls for per-thread canary in the TLS block (the default). This option
has effect only when -fstack-protector or -fstack-protector-all is specified.
These -m switches are supported in addition to the above on x86-64 processors in 64-bit
environments.
我已经完成了这个测试程序:
#define VALUE 2048
int main()
{
char arr[VALUE];
int i;
for (i = 0; i < VALUE + 15; i++) // "i < VALUE + 15" is to test if canaries works but the code doesn't compile anymore with "i < 10"
arr[i] = '0';
return 0;
}
如gcc的手册中所述,我的编译命令行是:
gcc main.c -fstack-protector-all -mstack-protector-guard=global
但我收到以下错误信息:
/tmp/ccXxxxVd.o: In function `main':
main.c:(.text+0xe): undefined reference to `__stack_chk_guard'
main.c:(.text+0x51): undefined reference to `__stack_chk_guard'
collect2: error: ld returned 1 exit status
我该如何消除这个错误?
编辑:
- 操作系统:Ubuntu 14.10 Utopic
- 架构:x86-64
- 环境:64位