"Stack protector enabled but no compiler support" appears when compiling the driver module [workaround]

Source: Internet
Author: User

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

    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

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

    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

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

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

    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,%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,%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

"Stack protector enabled but no compiler support" appears when compiling the driver module [workaround]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.