gccint: Stack Checking

1 
1 18.9.3 Specifying How Stack Checking is Done
1 --------------------------------------------
1 
1 GCC will check that stack references are within the boundaries of the
1 stack, if the option '-fstack-check' is specified, in one of three ways:
1 
1   1. If the value of the 'STACK_CHECK_BUILTIN' macro is nonzero, GCC
1      will assume that you have arranged for full stack checking to be
1      done at appropriate places in the configuration files.  GCC will
1      not do other special processing.
1 
1   2. If 'STACK_CHECK_BUILTIN' is zero and the value of the
1      'STACK_CHECK_STATIC_BUILTIN' macro is nonzero, GCC will assume that
1      you have arranged for static stack checking (checking of the static
1      stack frame of functions) to be done at appropriate places in the
1      configuration files.  GCC will only emit code to do dynamic stack
1      checking (checking on dynamic stack allocations) using the third
1      approach below.
1 
1   3. If neither of the above are true, GCC will generate code to
1      periodically "probe" the stack pointer using the values of the
1      macros defined below.
1 
1  If neither STACK_CHECK_BUILTIN nor STACK_CHECK_STATIC_BUILTIN is
1 defined, GCC will change its allocation strategy for large objects if
1 the option '-fstack-check' is specified: they will always be allocated
1 dynamically if their size exceeds 'STACK_CHECK_MAX_VAR_SIZE' bytes.
1 
1  -- Macro: STACK_CHECK_BUILTIN
1      A nonzero value if stack checking is done by the configuration
1      files in a machine-dependent manner.  You should define this macro
1      if stack checking is required by the ABI of your machine or if you
1      would like to do stack checking in some more efficient way than the
1      generic approach.  The default value of this macro is zero.
1 
1  -- Macro: STACK_CHECK_STATIC_BUILTIN
1      A nonzero value if static stack checking is done by the
1      configuration files in a machine-dependent manner.  You should
1      define this macro if you would like to do static stack checking in
1      some more efficient way than the generic approach.  The default
1      value of this macro is zero.
1 
1  -- Macro: STACK_CHECK_PROBE_INTERVAL_EXP
1      An integer specifying the interval at which GCC must generate stack
1      probe instructions, defined as 2 raised to this integer.  You will
1      normally define this macro so that the interval be no larger than
1      the size of the "guard pages" at the end of a stack area.  The
1      default value of 12 (4096-byte interval) is suitable for most
1      systems.
1 
1  -- Macro: STACK_CHECK_MOVING_SP
1      An integer which is nonzero if GCC should move the stack pointer
1      page by page when doing probes.  This can be necessary on systems
1      where the stack pointer contains the bottom address of the memory
1      area accessible to the executing thread at any point in time.  In
1      this situation an alternate signal stack is required in order to be
1      able to recover from a stack overflow.  The default value of this
1      macro is zero.
1 
1  -- Macro: STACK_CHECK_PROTECT
1      The number of bytes of stack needed to recover from a stack
1      overflow, for languages where such a recovery is supported.  The
1      default value of 4KB/8KB with the 'setjmp'/'longjmp'-based
1      exception handling mechanism and 8KB/12KB with other exception
1      handling mechanisms should be adequate for most architectures and
1      operating systems.
1 
1  The following macros are relevant only if neither STACK_CHECK_BUILTIN
1 nor STACK_CHECK_STATIC_BUILTIN is defined; you can omit them altogether
1 in the opposite case.
1 
1  -- Macro: STACK_CHECK_MAX_FRAME_SIZE
1      The maximum size of a stack frame, in bytes.  GCC will generate
1      probe instructions in non-leaf functions to ensure at least this
1      many bytes of stack are available.  If a stack frame is larger than
1      this size, stack checking will not be reliable and GCC will issue a
1      warning.  The default is chosen so that GCC only generates one
1      instruction on most systems.  You should normally not change the
1      default value of this macro.
1 
1  -- Macro: STACK_CHECK_FIXED_FRAME_SIZE
1      GCC uses this value to generate the above warning message.  It
1      represents the amount of fixed frame used by a function, not
1      including space for any callee-saved registers, temporaries and
1      user variables.  You need only specify an upper bound for this
1      amount and will normally use the default of four words.
1 
1  -- Macro: STACK_CHECK_MAX_VAR_SIZE
1      The maximum size, in bytes, of an object that GCC will place in the
1      fixed area of the stack frame when the user specifies
1      '-fstack-check'.  GCC computed the default from the values of the
1      above macros and you will normally not need to override that
1      default.
1 
1  -- Target Hook: bool TARGET_STACK_CLASH_PROTECTION_FINAL_DYNAMIC_PROBE
1           (rtx RESIDUAL)
1      Some targets make optimistic assumptions about the state of stack
1      probing when they emit their prologues.  On such targets a probe
1      into the end of any dynamically allocated space is likely required
1      for safety against stack clash style attacks.  Define this variable
1      to return nonzero if such a probe is required or zero otherwise.
1      You need not define this macro if it would always have the value
1      zero.
1