gcc canaries:对__stack_chk_guard的未定义引用 [英] gcc canaries : undefined reference to __stack_chk_guard

查看:137
本文介绍了gcc canaries:对__stack_chk_guard的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启用gcc的金丝雀的生成,但是我获得了对__stack_chk_guard的未定义引用.

I'm trying to enable gcc' s canaries' generation but I get an undefined reference to __stack_chk_guard.

来自gcc的关于金丝雀的人:

From gcc's man about 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.

我已经完成了此测试程序:

I've done this test program :

#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的男人所说,我的编译行是:

As said in gcc's man, my compilation line is :

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位

推荐答案

看来, -mstack-protector-guard 选项仅用于向后兼容以前的堆栈保护器工作方式..过去,金丝雀在一个全局变量中.后来将其切换为TLS.您使用的操作系统/libc似乎已删除或从未支持全局变量canary,因此只有TLS起作用.

It would appear that the -mstack-protector-guard option is only for backwards compatibility with how the stack protector worked in the past. In the past the canary was in a global variable. Later it was switched to TLS. It would appear that the operating system / libc you use either removed or never had support for the global variable canary, so only TLS works.

请勿触摸 -mstack-protector-guard 选项,一切正常.当您使用 -fstack-protector-all 时,默认设置应该很好.

Don't touch the -mstack-protector-guard option and everything should work. The default should be fine when you use -fstack-protector-all.

这篇关于gcc canaries:对__stack_chk_guard的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆