编译驱动模块时,出现“stack protector enabled but no compiler support”[解决办法]【转】

简介: 转自:http://blog.chinaunix.net/uid-26847859-id-3297170.html 原文地址:编译驱动模块时,出现“stack protector enabled but no compiler support”[解决办法] 作者:cjunsking 写驱动程序,...

转自:http://blog.chinaunix.net/uid-26847859-id-3297170.html

原文地址:编译驱动模块时,出现“stack protector enabled but no compiler support”[解决办法] 作者:cjunsking

写驱动程序,编译驱动模块时,出现

“make[1]: Entering directory `/usr/src/linux-headers-2.6.32-5-amd64'

/usr/src/linux-headers-2.6.32-5-common/arch/x86/Makefile:81: stack protector enabled but no compiler support” - stack protector启用,但编译器不支持

 

解决方法1: (除去栈保护支持)

1. 修改 /usr/src/linux-header-xxx/目录下的文件.config,找到CONFIG_CC_STACKPROTECTOR,注释掉

2. 同样的办法修改/usr/src/linux-header-xxx/include/config/auto.conf

 

解决方法2: (保留栈保护功能)

在/usr/src/linux-headers-2.6.32-5-common/arch/x86/Makefile中有

 

 

  1. ifdef CONFIG_CC_STACKPROTECTOR
  2. cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
  3. ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(biarch)),y)
  4. stackp-y := -fstack-protector
  5. KBUILD_CFLAGS += $(stackp-y)
  6. else
  7. $(warning stack protector enabled but no compiler support)
  8. endif
  9. endif

 

 

判断编译器是否支持stack-protector的是/usr/src/linux-headers-2.6.32-5-common/scripts/gcc-x86_$(BITS)-has-stack-protector.sh文件(针对32/64位机器,有不同的文件)

 

 

点击(此处)折叠或打开

  1. #!/bin/sh
  2. echo "" | $* -S -xc -c -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs"
  3. if [ "$?" -eq "0" ] ; then
  4. echo y
  5. else
  6. echo n
  7. fi

 

 

这个文件中判断gcc是否支持fstack-protector的方法是,查看""生成的支持栈保护的汇编码中是否含有"%gs"。大家可以通过实验来观察区别,而这个文件中的判断与实际的相反。故将这两个文件中的y和n互换位置即可。

 

实验:  Debian6.0.5/Linux 2.6.32-5-amd64/gcc 4.4.5

源代码: (test_stack_protector.c)

    int foo(void) { char X[200]; return 3; }

 

编译结果:

(1)  gcc -S -fstack-protector -o stack test_stack_protector.c

stack:

------------------------------------------------------------

 

  1. .file"test_stack_protector.c"
  2. .text
  3. .globl foo
  4. .typefoo, @function
  5. foo:
  6. pushl %ebp
  7. movl %esp, %ebp
  8. subl $216, %esp
  9. movl %gs:20, %eax
  10. movl %eax, -12(%ebp)
  11. xorl %eax, %eax
  12. movl $3, %eax
  13. movl -12(%ebp), %edx
  14. xorl %gs:20, %edx
  15. je .L3
  16. call __stack_chk_fail
  17. .L3:
  18. leave
  19. ret
  20. .sizefoo, .-foo
  21. .ident"GCC: (Debian 4.4.5-8) 4.4.5"
  22. .section.note.GNU-stack,"",@progbits

 

 

(2)   gcc -S -fno-stack-protector -o nostack test_stack_protector.c 

nostack:

------------------------------------------------------------

 

    1. .file"test_stack_protector.c"
    2. .text
    3. .globl foo
    4. .typefoo, @function
    5. foo:
    6. pushl %ebp
    7. movl %esp, %ebp
    8. subl $208, %esp
    9. movl $3, %eax
    10. leave
    11. ret
    12. .sizefoo, .-foo
    13. .ident"GCC: (Debian 4.4.5-8) 4.4.5"
    14. .section.note.GNU-stack,"",@progbits
【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
监控 Linux 调度
浅谈GPU虚拟化技术(四)- GPU分片虚拟化
作者:郑晓,龙欣,弹性计算异构计算项目组 让各位久等了,阿里小二这就开始上新菜:“GPU分片虚拟化”。 对于“分片”的理解,相信大家已经不陌生了。此处的分片从两个维度上来定义:其一,是对GPU在时间片段上的划分,与CPU的进程调度类似,一个物理GPU的计算engine在几个vGPU之间共享,而调...
22261 1
|
存储 JSON API
Pydantic:目前最流行的Python数据验证库
在处理来自系统外部的数据,如API、终端用户输入或其他来源时,我们必须牢记开发中的一条基本原则:“永远不要相信用户的输入”。 因此,我们必须对这些数据进行严格的检查和验证,确保它们被适当地格式化和标准化。这样做的目的是为了确保这些数据符合我们的程序所需的输入规范,从而保障项目能够正确且高效地运行。
|
安全 Linux 测试技术
VFIO中介设备 【ChatGPT】
VFIO中介设备 【ChatGPT】
|
Ubuntu Java 程序员
手把手教你搭建自己的git+gerrit代码评审服务器
搭建自己的git+gerrit代码评审服务器
2452 0
手把手教你搭建自己的git+gerrit代码评审服务器
|
9天前
|
云安全 监控 安全
|
14天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1563 8
|
8天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
516 15