Write driver, when compiling driver module, appears
"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 PR Otector enabled, but the compiler does not support
Workaround 1: (Remove stack protection support)
1. Modify the files in the/usr/src/linux-header-xxx/directory. config, find config_cc_stackprotector, comment out
2. The same approach modifies/usr/src/linux-header-xxx/include/config/auto.conf
Workaround 2: (Preserve the stack protection function)
There are/usr/src/linux-headers-2.6.32-5-common/arch/x86/makefile in the
- Ifdef config_cc_stackprotector
- CC_HAS_SP: = $ (Srctree)/scripts/gcc-x86_$ (BITS)-has-stack-protector.sh
- Ifeq ($ (Shell $ (Config_shell) $ (CC_HAS_SP) $ (CC) $ (biarch)), y)
- Stackp-y: =-fstack-protector
- Kbuild_cflags + = $ (stackp-y)
- Else
- $ (Warning stack protector enabled but no compiler support)
- endif
- endif
Determines whether the compiler supports Stack-protector/usr/src/linux-headers-2.6.32-5-common/scripts/gcc-x86_$ (BITS)- has-stack-protector.sh files (for 32/64-bit machines, with different files)
Click ( here) to collapse or open
- #!/bin/sh
- echo "" | $*-s-xc-c-o0-fstack-protector--o-2>/dev/null | Grep-q "%gs"
- If ["$?"-eq "0"]; Then
- Echo y
- Else
- echo N
- Fi
The method in this file to determine if GCC supports fstack-protector is to see if "%gs" is included in the compiled code that generates the support stack protection. You can observe the difference by experiment, and the judgment in this file is the opposite of the actual one. Therefore, the two files in the Y and N interchange position can be.
Experiment: Debian6.0.5/linux 2.6.32-5-AMD64/GCC 4.4.5
Source code: (TEST_STACK_PROTECTOR.C)
int foo (void) {char x[200]; return 3;}
Compilation Result:
(1) gcc-s-fstack-protector-o stack test_stack_protector.c
Stack
------------------------------------------------------------
- . File "Test_stack_protector.c"
- . text
- . globl Foo
- . Typefoo, @function
- Foo:
- PUSHL%EBP
- MOVL%esp,%EBP
- Subl $216,%esp
- MOVL%gs:20,%eax
- Movl%eax, -12 (%EBP)
- Xorl%eax,%eax
- MOVL,%eax
- Movl-12 (%EBP),%edx
- Xorl%gs:20,%edx
- JE. L3
- Call __stack_chk_fail
- . L3:
- Leave
- Ret
- . Sizefoo,.-foo
- . Ident "GCC: (Debian 4.4.5-8) 4.4.5"
- . Section.note.gnu-stack, "", @progbits
(2) gcc-s-fno-stack-protector-o nostack test_stack_protector.c
Nostack:
------------------------------------------------------------
- . File "Test_stack_protector.c"
- . text
- . globl Foo
- . Typefoo, @function
- Foo:
- PUSHL%EBP
- MOVL%esp,%EBP
- Subl $208,%esp
- MOVL,%eax
- Leave
- Ret
- . Sizefoo,.-foo
- . Ident "GCC: (Debian 4.4.5-8) 4.4.5"
- . Section.note.gnu-stack, "", @progbits
"Stack protector enabled but no compiler support" appears when compiling the driver module [workaround]