gccint: Frame Layout

1 
1 18.9.1 Basic Stack Layout
1 -------------------------
1 
1 Here is the basic stack layout.
1 
1  -- Macro: STACK_GROWS_DOWNWARD
1      Define this macro to be true if pushing a word onto the stack moves
1      the stack pointer to a smaller address, and false otherwise.
1 
1  -- Macro: STACK_PUSH_CODE
1      This macro defines the operation used when something is pushed on
1      the stack.  In RTL, a push operation will be '(set (mem
1      (STACK_PUSH_CODE (reg sp))) ...)'
1 
1      The choices are 'PRE_DEC', 'POST_DEC', 'PRE_INC', and 'POST_INC'.
1      Which of these is correct depends on the stack direction and on
1      whether the stack pointer points to the last item on the stack or
1      whether it points to the space for the next item on the stack.
1 
1      The default is 'PRE_DEC' when 'STACK_GROWS_DOWNWARD' is true, which
1      is almost always right, and 'PRE_INC' otherwise, which is often
1      wrong.
1 
1  -- Macro: FRAME_GROWS_DOWNWARD
1      Define this macro to nonzero value if the addresses of local
1      variable slots are at negative offsets from the frame pointer.
1 
1  -- Macro: ARGS_GROW_DOWNWARD
1      Define this macro if successive arguments to a function occupy
1      decreasing addresses on the stack.
1 
1  -- Target Hook: HOST_WIDE_INT TARGET_STARTING_FRAME_OFFSET (void)
1      This hook returns the offset from the frame pointer to the first
1      local variable slot to be allocated.  If 'FRAME_GROWS_DOWNWARD', it
1      is the offset to _end_ of the first slot allocated, otherwise it is
1      the offset to _beginning_ of the first slot allocated.  The default
1      implementation returns 0.
1 
1  -- Macro: STACK_ALIGNMENT_NEEDED
1      Define to zero to disable final alignment of the stack during
1      reload.  The nonzero default for this macro is suitable for most
1      ports.
1 
1      On ports where 'TARGET_STARTING_FRAME_OFFSET' is nonzero or where
1      there is a register save block following the local block that
1      doesn't require alignment to 'STACK_BOUNDARY', it may be beneficial
1      to disable stack alignment and do it in the backend.
1 
1  -- Macro: STACK_POINTER_OFFSET
1      Offset from the stack pointer register to the first location at
1      which outgoing arguments are placed.  If not specified, the default
1      value of zero is used.  This is the proper value for most machines.
1 
1      If 'ARGS_GROW_DOWNWARD', this is the offset to the location above
1      the first location at which outgoing arguments are placed.
1 
1  -- Macro: FIRST_PARM_OFFSET (FUNDECL)
1      Offset from the argument pointer register to the first argument's
1      address.  On some machines it may depend on the data type of the
1      function.
1 
1      If 'ARGS_GROW_DOWNWARD', this is the offset to the location above
1      the first argument's address.
1 
1  -- Macro: STACK_DYNAMIC_OFFSET (FUNDECL)
1      Offset from the stack pointer register to an item dynamically
1      allocated on the stack, e.g., by 'alloca'.
1 
1      The default value for this macro is 'STACK_POINTER_OFFSET' plus the
1      length of the outgoing arguments.  The default is correct for most
1      machines.  See 'function.c' for details.
1 
1  -- Macro: INITIAL_FRAME_ADDRESS_RTX
1      A C expression whose value is RTL representing the address of the
1      initial stack frame.  This address is passed to 'RETURN_ADDR_RTX'
1      and 'DYNAMIC_CHAIN_ADDRESS'.  If you don't define this macro, a
1      reasonable default value will be used.  Define this macro in order
1      to make frame pointer elimination work in the presence of
1      '__builtin_frame_address (count)' and '__builtin_return_address
1      (count)' for 'count' not equal to zero.
1 
1  -- Macro: DYNAMIC_CHAIN_ADDRESS (FRAMEADDR)
1      A C expression whose value is RTL representing the address in a
1      stack frame where the pointer to the caller's frame is stored.
1      Assume that FRAMEADDR is an RTL expression for the address of the
1      stack frame itself.
1 
1      If you don't define this macro, the default is to return the value
1      of FRAMEADDR--that is, the stack frame address is also the address
1      of the stack word that points to the previous frame.
1 
1  -- Macro: SETUP_FRAME_ADDRESSES
1      A C expression that produces the machine-specific code to setup the
1      stack so that arbitrary frames can be accessed.  For example, on
1      the SPARC, we must flush all of the register windows to the stack
1      before we can access arbitrary stack frames.  You will seldom need
1      to define this macro.  The default is to do nothing.
1 
1  -- Target Hook: rtx TARGET_BUILTIN_SETJMP_FRAME_VALUE (void)
1      This target hook should return an rtx that is used to store the
1      address of the current frame into the built in 'setjmp' buffer.
1      The default value, 'virtual_stack_vars_rtx', is correct for most
1      machines.  One reason you may need to define this target hook is if
1      'hard_frame_pointer_rtx' is the appropriate value on your machine.
1 
1  -- Macro: FRAME_ADDR_RTX (FRAMEADDR)
1      A C expression whose value is RTL representing the value of the
1      frame address for the current frame.  FRAMEADDR is the frame
1      pointer of the current frame.  This is used for
1      __builtin_frame_address.  You need only define this macro if the
1      frame address is not the same as the frame pointer.  Most machines
1      do not need to define it.
1 
1  -- Macro: RETURN_ADDR_RTX (COUNT, FRAMEADDR)
1      A C expression whose value is RTL representing the value of the
1      return address for the frame COUNT steps up from the current frame,
1      after the prologue.  FRAMEADDR is the frame pointer of the COUNT
1      frame, or the frame pointer of the COUNT - 1 frame if
1      'RETURN_ADDR_IN_PREVIOUS_FRAME' is nonzero.
1 
1      The value of the expression must always be the correct address when
1      COUNT is zero, but may be 'NULL_RTX' if there is no way to
1      determine the return address of other frames.
1 
1  -- Macro: RETURN_ADDR_IN_PREVIOUS_FRAME
1      Define this macro to nonzero value if the return address of a
1      particular stack frame is accessed from the frame pointer of the
1      previous stack frame.  The zero default for this macro is suitable
1      for most ports.
1 
1  -- Macro: INCOMING_RETURN_ADDR_RTX
1      A C expression whose value is RTL representing the location of the
1      incoming return address at the beginning of any function, before
1      the prologue.  This RTL is either a 'REG', indicating that the
1      return value is saved in 'REG', or a 'MEM' representing a location
1      in the stack.
1 
1      You only need to define this macro if you want to support call
1      frame debugging information like that provided by DWARF 2.
1 
1      If this RTL is a 'REG', you should also define
1      'DWARF_FRAME_RETURN_COLUMN' to 'DWARF_FRAME_REGNUM (REGNO)'.
1 
1  -- Macro: DWARF_ALT_FRAME_RETURN_COLUMN
1      A C expression whose value is an integer giving a DWARF 2 column
1      number that may be used as an alternative return column.  The
1      column must not correspond to any gcc hard register (that is, it
1      must not be in the range of 'DWARF_FRAME_REGNUM').
1 
1      This macro can be useful if 'DWARF_FRAME_RETURN_COLUMN' is set to a
1      general register, but an alternative column needs to be used for
1      signal frames.  Some targets have also used different frame return
1      columns over time.
1 
1  -- Macro: DWARF_ZERO_REG
1      A C expression whose value is an integer giving a DWARF 2 register
1      number that is considered to always have the value zero.  This
1      should only be defined if the target has an architected zero
1      register, and someone decided it was a good idea to use that
1      register number to terminate the stack backtrace.  New ports should
1      avoid this.
1 
1  -- Target Hook: void TARGET_DWARF_HANDLE_FRAME_UNSPEC (const char
1           *LABEL, rtx PATTERN, int INDEX)
1      This target hook allows the backend to emit frame-related insns
1      that contain UNSPECs or UNSPEC_VOLATILEs.  The DWARF 2 call frame
1      debugging info engine will invoke it on insns of the form
1           (set (reg) (unspec [...] UNSPEC_INDEX))
1      and
1           (set (reg) (unspec_volatile [...] UNSPECV_INDEX)).
1      to let the backend emit the call frame instructions.  LABEL is the
1      CFI label attached to the insn, PATTERN is the pattern of the insn
1      and INDEX is 'UNSPEC_INDEX' or 'UNSPECV_INDEX'.
1 
1  -- Target Hook: unsigned int TARGET_DWARF_POLY_INDETERMINATE_VALUE
1           (unsigned int I, unsigned int *FACTOR, int *OFFSET)
1      Express the value of 'poly_int' indeterminate I as a DWARF
1      expression, with I counting from 1.  Return the number of a DWARF
1      register R and set '*FACTOR' and '*OFFSET' such that the value of
1      the indeterminate is:
1           value_of(R) / FACTOR - OFFSET
1 
1      A target only needs to define this hook if it sets
1      'NUM_POLY_INT_COEFFS' to a value greater than 1.
1 
1  -- Macro: INCOMING_FRAME_SP_OFFSET
1      A C expression whose value is an integer giving the offset, in
1      bytes, from the value of the stack pointer register to the top of
1      the stack frame at the beginning of any function, before the
1      prologue.  The top of the frame is defined to be the value of the
1      stack pointer in the previous frame, just before the call
1      instruction.
1 
1      You only need to define this macro if you want to support call
1      frame debugging information like that provided by DWARF 2.
1 
1  -- Macro: DEFAULT_INCOMING_FRAME_SP_OFFSET
1      Like 'INCOMING_FRAME_SP_OFFSET', but must be the same for all
1      functions of the same ABI, and when using GAS '.cfi_*' directives
1      must also agree with the default CFI GAS emits.  Define this macro
1      only if 'INCOMING_FRAME_SP_OFFSET' can have different values
1      between different functions of the same ABI or when
1      'INCOMING_FRAME_SP_OFFSET' does not agree with GAS default CFI.
1 
1  -- Macro: ARG_POINTER_CFA_OFFSET (FUNDECL)
1      A C expression whose value is an integer giving the offset, in
1      bytes, from the argument pointer to the canonical frame address
1      (cfa).  The final value should coincide with that calculated by
1      'INCOMING_FRAME_SP_OFFSET'.  Which is unfortunately not usable
1      during virtual register instantiation.
1 
1      The default value for this macro is 'FIRST_PARM_OFFSET (fundecl) +
1      crtl->args.pretend_args_size', which is correct for most machines;
1      in general, the arguments are found immediately before the stack
1      frame.  Note that this is not the case on some targets that save
1      registers into the caller's frame, such as SPARC and rs6000, and so
1      such targets need to define this macro.
1 
1      You only need to define this macro if the default is incorrect, and
1      you want to support call frame debugging information like that
1      provided by DWARF 2.
1 
1  -- Macro: FRAME_POINTER_CFA_OFFSET (FUNDECL)
1      If defined, a C expression whose value is an integer giving the
1      offset in bytes from the frame pointer to the canonical frame
1      address (cfa).  The final value should coincide with that
1      calculated by 'INCOMING_FRAME_SP_OFFSET'.
1 
1      Normally the CFA is calculated as an offset from the argument
1      pointer, via 'ARG_POINTER_CFA_OFFSET', but if the argument pointer
1      is variable due to the ABI, this may not be possible.  If this
1      macro is defined, it implies that the virtual register
1      instantiation should be based on the frame pointer instead of the
1      argument pointer.  Only one of 'FRAME_POINTER_CFA_OFFSET' and
1      'ARG_POINTER_CFA_OFFSET' should be defined.
1 
1  -- Macro: CFA_FRAME_BASE_OFFSET (FUNDECL)
1      If defined, a C expression whose value is an integer giving the
1      offset in bytes from the canonical frame address (cfa) to the frame
1      base used in DWARF 2 debug information.  The default is zero.  A
1      different value may reduce the size of debug information on some
1      ports.
1