]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/target-macros/stack-layout-and-calling-conventions/exception-handling-support.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / target-macros / stack-layout-and-calling-conventions / exception-handling-support.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: exception handling
7
8.. _exception-handling:
9
10Exception Handling Support
11^^^^^^^^^^^^^^^^^^^^^^^^^^
12
13.. c:macro:: EH_RETURN_DATA_REGNO (N)
14
15 A C expression whose value is the :samp:`{N}` th register number used for
16 data by exception handlers, or ``INVALID_REGNUM`` if fewer than
17 :samp:`{N}` registers are usable.
18
19 The exception handling library routines communicate with the exception
20 handlers via a set of agreed upon registers. Ideally these registers
21 should be call-clobbered; it is possible to use call-saved registers,
22 but may negatively impact code size. The target must support at least
23 2 data registers, but should define 4 if there are enough free registers.
24
25 You must define this macro if you want to support call frame exception
26 handling like that provided by DWARF 2.
27
28.. c:macro:: EH_RETURN_STACKADJ_RTX
29
30 A C expression whose value is RTL representing a location in which
31 to store a stack adjustment to be applied before function return.
32 This is used to unwind the stack to an exception handler's call frame.
33 It will be assigned zero on code paths that return normally.
34
35 Typically this is a call-clobbered hard register that is otherwise
36 untouched by the epilogue, but could also be a stack slot.
37
38 Do not define this macro if the stack pointer is saved and restored
39 by the regular prolog and epilog code in the call frame itself; in
40 this case, the exception handling library routines will update the
41 stack location to be restored in place. Otherwise, you must define
42 this macro if you want to support call frame exception handling like
43 that provided by DWARF 2.
44
45.. c:macro:: EH_RETURN_HANDLER_RTX
46
47 A C expression whose value is RTL representing a location in which
48 to store the address of an exception handler to which we should
49 return. It will not be assigned on code paths that return normally.
50
51 Typically this is the location in the call frame at which the normal
52 return address is stored. For targets that return by popping an
53 address off the stack, this might be a memory address just below
54 the *target* call frame rather than inside the current call
55 frame. If defined, ``EH_RETURN_STACKADJ_RTX`` will have already
56 been assigned, so it may be used to calculate the location of the
57 target call frame.
58
59 Some targets have more complex requirements than storing to an
60 address calculable during initial code generation. In that case
61 the ``eh_return`` instruction pattern should be used instead.
62
63 If you want to support call frame exception handling, you must
64 define either this macro or the ``eh_return`` instruction pattern.
65
66.. c:macro:: RETURN_ADDR_OFFSET
67
68 If defined, an integer-valued C expression for which rtl will be generated
69 to add it to the exception handler address before it is searched in the
70 exception handling tables, and to subtract it again from the address before
71 using it to return to the exception handler.
72
73.. c:macro:: ASM_PREFERRED_EH_DATA_FORMAT (code, global)
74
75 This macro chooses the encoding of pointers embedded in the exception
76 handling sections. If at all possible, this should be defined such
77 that the exception handling section will not require dynamic relocations,
78 and so may be read-only.
79
80 :samp:`{code}` is 0 for data, 1 for code labels, 2 for function pointers.
81 :samp:`{global}` is true if the symbol may be affected by dynamic relocations.
82 The macro should return a combination of the ``DW_EH_PE_*`` defines
83 as found in :samp:`dwarf2.h`.
84
85 If this macro is not defined, pointers will not be encoded but
86 represented directly.
87
88.. c:macro:: ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX (file, encoding, size, addr, done)
89
90 This macro allows the target to emit whatever special magic is required
91 to represent the encoding chosen by ``ASM_PREFERRED_EH_DATA_FORMAT``.
92 Generic code takes care of pc-relative and indirect encodings; this must
93 be defined if the target uses text-relative or data-relative encodings.
94
95 This is a C statement that branches to :samp:`{done}` if the format was
96 handled. :samp:`{encoding}` is the format chosen, :samp:`{size}` is the number
97 of bytes that the format occupies, :samp:`{addr}` is the ``SYMBOL_REF``
98 to be emitted.
99
100.. c:macro:: MD_FALLBACK_FRAME_STATE_FOR (context, fs)
101
102 This macro allows the target to add CPU and operating system specific
103 code to the call-frame unwinder for use when there is no unwind data
104 available. The most common reason to implement this macro is to unwind
105 through signal frames.
106
107 This macro is called from ``uw_frame_state_for`` in
108 :samp:`unwind-dw2.c`, :samp:`unwind-dw2-xtensa.c` and
109 :samp:`unwind-ia64.c`. :samp:`{context}` is an ``_Unwind_Context`` ;
110 :samp:`{fs}` is an ``_Unwind_FrameState``. Examine ``context->ra``
111 for the address of the code being executed and ``context->cfa`` for
112 the stack pointer value. If the frame can be decoded, the register
113 save addresses should be updated in :samp:`{fs}` and the macro should
114 evaluate to ``_URC_NO_REASON``. If the frame cannot be decoded,
115 the macro should evaluate to ``_URC_END_OF_STACK``.
116
117 For proper signal handling in Java this macro is accompanied by
118 ``MAKE_THROW_FRAME``, defined in :samp:`libjava/include/*-signal.h` headers.
119
120.. c:macro:: MD_HANDLE_UNWABI (context, fs)
121
122 This macro allows the target to add operating system specific code to the
123 call-frame unwinder to handle the IA-64 ``.unwabi`` unwinding directive,
124 usually used for signal or interrupt frames.
125
126 This macro is called from ``uw_update_context`` in libgcc's
127 :samp:`unwind-ia64.c`. :samp:`{context}` is an ``_Unwind_Context`` ;
128 :samp:`{fs}` is an ``_Unwind_FrameState``. Examine ``fs->unwabi``
129 for the abi and context in the ``.unwabi`` directive. If the
130 ``.unwabi`` directive can be handled, the register save addresses should
131 be updated in :samp:`{fs}`.
132
133.. c:macro:: TARGET_USES_WEAK_UNWIND_INFO
134
135 A C expression that evaluates to true if the target requires unwind
136 info to be given comdat linkage. Define it to be ``1`` if comdat
3ed1b4ce 137 linkage is necessary. The default is ``0``.