Next: , Previous: Exception Handling, Up: Stack and Calling


17.10.3 指定如何进行栈检查

GCC将检查栈引用是否位于栈的边界里,如果指定了-fstack-check, 使用三种方式的之一:

  1. 如果STACK_CHECK_BUILTIN宏的值为非0, 则GCC将假设你已经安排了在配置文件的合适的地方进行栈检查,例如, 在TARGET_ASM_FUNCTION_PROLOGUE中。GCC将不再做其它特殊的处理。
  2. If STACK_CHECK_BUILTIN is zero and the value of the STACK_CHECK_STATIC_BUILTIN macro is nonzero, GCC will assume that you have arranged for static stack checking (checking of the static stack frame of functions) to be done at appropriate places in the configuration files. GCC will only emit code to do dynamic stack checking (checking on dynamic stack allocations) using the third approach below.
  3. 如果上面两种方式都不是,则GCC将生成代码来周期的“探测”栈指针, 使用下面定义的宏的值。

If neither STACK_CHECK_BUILTIN nor STACK_CHECK_STATIC_BUILTIN is defined, GCC will change its allocation strategy for large objects if the option -fstack-check is specified: they will always be allocated dynamically if their size exceeds STACK_CHECK_MAX_VAR_SIZE bytes.

— Macro: STACK_CHECK_BUILTIN

A nonzero value if stack checking is done by the configuration files in a machine-dependent manner. You should define this macro if stack checking is required by the ABI of your machine or if you would like to do stack checking in some more efficient way than the generic approach. The default value of this macro is zero. 一个非0值,如果栈检查按照机器相关的方式通过配置文件来完成。 你应该定义该宏,如果栈检查被你的机器的ABI要求, 或者你想让栈检查使用比GCC可移植方式更有效的方法。该宏的缺省值为0。

— Macro: STACK_CHECK_STATIC_BUILTIN

A nonzero value if static stack checking is done by the configuration files in a machine-dependent manner. You should define this macro if you would like to do static stack checking in some more efficient way than the generic approach. The default value of this macro is zero.

— Macro: STACK_CHECK_PROBE_INTERVAL_EXP

An integer specifying the interval at which GCC must generate stack probe instructions, defined as 2 raised to this integer. You will normally define this macro so that the interval be no larger than the size of the “guard pages” at the end of a stack area. The default value of 12 (4096-byte interval) is suitable for most systems.

— Macro: STACK_CHECK_MOVING_SP

An integer which is nonzero if GCC should move the stack pointer page by page when doing probes. This can be necessary on systems where the stack pointer contains the bottom address of the memory area accessible to the executing thread at any point in time. In this situation an alternate signal stack is required in order to be able to recover from a stack overflow. The default value of this macro is zero.

— Macro: STACK_CHECK_PROTECT

The number of bytes of stack needed to recover from a stack overflow, for languages where such a recovery is supported. The default value of 75 words with the setjmp/longjmp-based exception handling mechanism and 8192 bytes with other exception handling mechanisms should be adequate for most machines.

The following macros are relevant only if neither STACK_CHECK_BUILTIN nor STACK_CHECK_STATIC_BUILTIN is defined; you can omit them altogether in the opposite case.

— Macro: STACK_CHECK_MAX_FRAME_SIZE

一个栈帧的最大大小,以字节为单位。 GCC将生成探测指令在非叶子函数来确保栈中至少这么多大小的字节是可用的。 如果一个栈帧大于该大小,则栈检查将不可靠并且GCC将产生一个警告。缺省值被选择, 使得GCC只生成一条指令,在大多数系统上。你通常不应该修改该宏的缺省值。

— Macro: STACK_CHECK_FIXED_FRAME_SIZE

GCC使用该值来生成上面的警告消息。其表示函数使用的固定的帧数量, 不包括用于任何被调用者保存的寄存器,临时变量和用户变量的空间。 你只需要指定该数量的上界并且通常使用缺省值,4个字。

— Macro: STACK_CHECK_MAX_VAR_SIZE

为当用户指定-fstack-check时,GCC将在栈帧的固定域放入的对象的最大大小, 以字节为单位。GCC根据上面的宏来计算缺省值并且你通常不需要覆盖缺省值。