V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fenglala
V2EX  ›  C

请教各位,如何解决 warning: stack protector not protecting local variables: variable length buffer

  •  
  •   fenglala · Nov 27, 2021 · 2809 views
    This topic created in 1623 days ago, the information mentioned may be changed or developed.

    编译器: https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-eabi/gcc-linaro-7.5.0-2019.12-x86_64_arm-eabi.tar.xz

    test.c:

    struct Foo{
        char a[32]; // 32 and above will produce warning, but 31 and below will not
        char d[9]; // 9 and above will produce warning, but 8 and below will not
    };
    
    int main()
    {
        struct Foo foo = {0};
        (void)(foo);
        return 0;
    }
    

    编译命令及输出:

    $ arm-eabi-gcc -Wstack-protector -fstack-protector-all -fstack-check -o test test.c
    test.c: In function ‘main’:
    test.c:6:5: warning: stack protector not protecting local variables: variable length buffer [-Wstack-protector]
     int main()
         ^~~~
    

    实际代码中的结构体类似上文的 Foo ,我不能改,但是 main 我可以改,请问怎么改 main 能解决这个 warning ?

    感谢各位!

    各位也可以去 https://stackoverflow.com/questions/70133887/how-can-i-fix-warning-stack-protector-not-protecting-local-variables-variable 上回答,我 Google 了一圈都没找到怎么解。

    3 replies    2021-11-30 20:08:11 +08:00
    fenglala
        2
    fenglala  
    OP
       Nov 27, 2021
    @wudicgi 是个办法,直接去掉-Wstack-protector 或许更直接🐶
    ExplorerLog
        3
    ExplorerLog  
       Nov 30, 2021
    static ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3448 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 10:57 · PVG 18:57 · LAX 03:57 · JFK 06:57
    ♥ Do have faith in what you're doing.