C语言 这个错误是什么意思:`somefile.c:200: error: the frame size of 1032 bytes is大于1024 bytes`?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2450845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:51:42  来源:igfitidea点击:

What does this error mean: `somefile.c:200: error: the frame size of 1032 bytes is larger than 1024 bytes`?

cgccbuildmakefilecompiler-errors

提问by Pierre-Antoine LaFayette

During a make, I'm seeing an error along the lines of:

在 make 过程中,我看到以下错误:

cc1: warnings being treated as errors
somefile.c:200: error: the frame size of 1032 bytes is larger than 1024 bytes

The line number points to the closing brace of a c function that has a signature like this:

行号指向 ac 函数的右大括号,其签名如下:

void trace(SomeEnum1 p1, SomeEnum2 p2, char* format, ...) {
    char strBuffer[1024];
    ...

The function prints some stuff into the buffer.

该函数将一些内容打印到缓冲区中。

Anyone know what this type of error means in general?

任何人都知道这种类型的错误通常意味着什么?

回答by fbrereto

I'm guessing there's some large buffer in that routine that is stack-allocated; this is likely causing the stack frame of that function to exceed 1024 bytes, which seems to be some compiler-enforced limit for the architecture upon which you are building. Possible solutions would include passing a compiler flag to relax the warning, expand the upper limit of the stack size, or dynamically allocating the buffer.

我猜在该例程中有一些大缓冲区是堆栈分配的;这可能会导致该函数的堆栈帧超过 1024 字节,这似乎是您正在构建的体系结构的编译器强制限制。可能的解决方案包括传递编译器标志以放松警告、扩展堆栈大小的上限或动态分配缓冲区。

回答by Pierre-Antoine LaFayette

Here is the GCC documentation referring to this warning:

以下是 GCC 文档中提及此警告的内容:

STACK_CHECK_MAX_FRAME_SIZE

STACK_CHECK_MAX_FRAME_SIZE

The maximum size of a stack frame, in bytes. GNU CC will generate probe instructions in non-leaf functions to ensure at least this many bytes of stack are available. If a stack frame is larger than this size, stack checking will not be reliable and GNU CC will issue a warning. The default is chosen so that GNU CC only generates one instruction on most systems. You should normally not change the default value of this macro.

堆栈帧的最大大小,以字节为单位。GNU CC 将在非叶函数中生成探测指令,以确保至少有这么多字节的堆栈可用。如果堆栈帧大于此大小,堆栈检查将不可靠并且 GNU CC 将发出警告。选择默认值以便 GNU CC 在大多数系统上只生成一条指令。通常不应更改此宏的默认值。

From http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_17.html#SEC214

来自http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_17.html#SEC214