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

2021-11-27 18:26:07 +08:00
 fenglala

编译器: 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 了一圈都没找到怎么解。

1511 次点击
所在节点    C
3 条回复
wudicgi
2021-11-27 18:36:45 +08:00
fenglala
2021-11-27 18:41:44 +08:00
@wudicgi 是个办法,直接去掉-Wstack-protector 或许更直接🐶
ExplorerLog
2021-11-30 20:08:11 +08:00
static ?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/818392

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX