1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
27 #include "coretypes.h"
29 #include "libgcc_tm.h"
32 #ifdef __USING_SJLJ_EXCEPTIONS__
33 # define NO_SIZE_OF_ENCODED_VALUE
35 #include "unwind-pe.h"
36 #include "unwind-dw2-fde.h"
38 #include "unwind-dw2.h"
44 #ifndef __USING_SJLJ_EXCEPTIONS__
46 #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
47 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
49 #undef __LIBGCC_STACK_GROWS_DOWNWARD__
50 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
53 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
54 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
55 #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
58 /* ??? For the public function interfaces, we tend to gcc_assert that the
59 column numbers are in range. For the dwarf2 unwind info this does happen,
60 although so far in a case that doesn't actually matter.
62 See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
63 the call-saved xmm registers and annotates them. We havn't bothered
64 providing support for the xmm registers for the x86_64 port primarily
65 because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
66 SEH instead. Adding the support for unix targets would generally be a
67 waste. However, some runtime libraries supplied with ICC do contain such
68 an unorthodox transition, as well as the unwind info to match. This loss
69 of register restoration doesn't matter in practice, because the exception
70 is caught in the native unix abi, where all of the xmm registers are
73 Ideally, we'd record some bit to notice when we're failing to restore some
74 register recorded in the unwind info, but to do that we need annotation on
75 the unix->ms abi edge, so that we know when the register data may be
76 discarded. And since this edge is also within the ICC library, we're
77 unlikely to be able to get the new annotation.
79 Barring a magic solution to restore the ms abi defined 128-bit xmm registers
80 (as distictly opposed to the full runtime width) without causing extra
81 overhead for normal unix abis, the best solution seems to be to simply
82 ignore unwind data for unknown columns. */
84 #define UNWIND_COLUMN_IN_RANGE(x) \
85 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
87 #ifdef REG_VALUE_IN_UNWIND_CONTEXT
88 typedef _Unwind_Word _Unwind_Context_Reg_Val
;
90 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
91 #define ASSUME_EXTENDED_UNWIND_CONTEXT 1
94 static inline _Unwind_Word
95 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val
)
100 static inline _Unwind_Context_Reg_Val
101 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val
)
106 typedef void *_Unwind_Context_Reg_Val
;
108 static inline _Unwind_Word
109 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val
)
111 return (_Unwind_Word
) (_Unwind_Internal_Ptr
) val
;
114 static inline _Unwind_Context_Reg_Val
115 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val
)
117 return (_Unwind_Context_Reg_Val
) (_Unwind_Internal_Ptr
) val
;
121 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
122 #define ASSUME_EXTENDED_UNWIND_CONTEXT 0
125 /* This is the register and unwind state for a particular frame. This
126 provides the information necessary to unwind up past a frame and return
128 struct _Unwind_Context
130 _Unwind_Context_Reg_Val reg
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
134 struct dwarf_eh_bases bases
;
135 /* Signal frame context. */
136 #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
137 /* Context which has version/args_size/by_value fields. */
138 #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
139 /* Bit reserved on AArch64, return address has been signed with A or B
141 #define RA_SIGNED_BIT ((~(_Unwind_Word) 0 >> 3) + 1)
143 /* 0 for now, can be increased when further fields are added to
144 struct _Unwind_Context. */
145 _Unwind_Word version
;
146 _Unwind_Word args_size
;
147 char by_value
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
150 /* Byte size of every register managed by these routines. */
151 static unsigned char dwarf_reg_size_table
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
154 /* Read unaligned data from the instruction buffer. */
159 unsigned u2
__attribute__ ((mode (HI
)));
160 unsigned u4
__attribute__ ((mode (SI
)));
161 unsigned u8
__attribute__ ((mode (DI
)));
162 signed s2
__attribute__ ((mode (HI
)));
163 signed s4
__attribute__ ((mode (SI
)));
164 signed s8
__attribute__ ((mode (DI
)));
165 } __attribute__ ((packed
));
167 static void uw_update_context (struct _Unwind_Context
*, _Unwind_FrameState
*);
168 static _Unwind_Reason_Code
uw_frame_state_for (struct _Unwind_Context
*,
169 _Unwind_FrameState
*);
172 read_pointer (const void *p
) { const union unaligned
*up
= p
; return up
->p
; }
175 read_1u (const void *p
) { return *(const unsigned char *) p
; }
178 read_1s (const void *p
) { return *(const signed char *) p
; }
181 read_2u (const void *p
) { const union unaligned
*up
= p
; return up
->u2
; }
184 read_2s (const void *p
) { const union unaligned
*up
= p
; return up
->s2
; }
186 static inline unsigned int
187 read_4u (const void *p
) { const union unaligned
*up
= p
; return up
->u4
; }
190 read_4s (const void *p
) { const union unaligned
*up
= p
; return up
->s4
; }
192 static inline unsigned long
193 read_8u (const void *p
) { const union unaligned
*up
= p
; return up
->u8
; }
195 static inline unsigned long
196 read_8s (const void *p
) { const union unaligned
*up
= p
; return up
->s8
; }
198 static inline _Unwind_Word
199 _Unwind_IsSignalFrame (struct _Unwind_Context
*context
)
201 return (context
->flags
& SIGNAL_FRAME_BIT
) ? 1 : 0;
205 _Unwind_SetSignalFrame (struct _Unwind_Context
*context
, int val
)
208 context
->flags
|= SIGNAL_FRAME_BIT
;
210 context
->flags
&= ~SIGNAL_FRAME_BIT
;
213 static inline _Unwind_Word
214 _Unwind_IsExtendedContext (struct _Unwind_Context
*context
)
216 return (ASSUME_EXTENDED_UNWIND_CONTEXT
217 || (context
->flags
& EXTENDED_CONTEXT_BIT
));
220 /* Get the value of register REGNO as saved in CONTEXT. */
223 _Unwind_GetGR (struct _Unwind_Context
*context
, int regno
)
226 _Unwind_Context_Reg_Val val
;
228 #ifdef DWARF_ZERO_REG
229 if (regno
== DWARF_ZERO_REG
)
233 index
= DWARF_REG_TO_UNWIND_COLUMN (regno
);
234 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
235 size
= dwarf_reg_size_table
[index
];
236 val
= context
->reg
[index
];
238 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
239 return _Unwind_Get_Unwind_Word (val
);
241 #ifdef DWARF_LAZY_REGISTER_VALUE
244 if (DWARF_LAZY_REGISTER_VALUE (regno
, &value
))
249 /* This will segfault if the register hasn't been saved. */
250 if (size
== sizeof(_Unwind_Ptr
))
251 return * (_Unwind_Ptr
*) (_Unwind_Internal_Ptr
) val
;
254 gcc_assert (size
== sizeof(_Unwind_Word
));
255 return * (_Unwind_Word
*) (_Unwind_Internal_Ptr
) val
;
260 _Unwind_GetPtr (struct _Unwind_Context
*context
, int index
)
262 return (void *)(_Unwind_Ptr
) _Unwind_GetGR (context
, index
);
265 /* Get the value of the CFA as saved in CONTEXT. */
268 _Unwind_GetCFA (struct _Unwind_Context
*context
)
270 return (_Unwind_Ptr
) context
->cfa
;
273 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
276 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
281 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
282 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
283 size
= dwarf_reg_size_table
[index
];
285 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
287 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
291 ptr
= (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
293 if (size
== sizeof(_Unwind_Ptr
))
294 * (_Unwind_Ptr
*) ptr
= val
;
297 gcc_assert (size
== sizeof(_Unwind_Word
));
298 * (_Unwind_Word
*) ptr
= val
;
302 /* Get the pointer to a register INDEX as saved in CONTEXT. */
305 _Unwind_GetGRPtr (struct _Unwind_Context
*context
, int index
)
307 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
308 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
309 return &context
->reg
[index
];
310 return (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
313 /* Set the pointer to a register INDEX as saved in CONTEXT. */
316 _Unwind_SetGRPtr (struct _Unwind_Context
*context
, int index
, void *p
)
318 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
319 if (_Unwind_IsExtendedContext (context
))
320 context
->by_value
[index
] = 0;
321 context
->reg
[index
] = (_Unwind_Context_Reg_Val
) (_Unwind_Internal_Ptr
) p
;
324 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
327 _Unwind_SetGRValue (struct _Unwind_Context
*context
, int index
,
330 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
331 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
332 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
333 gcc_assert (dwarf_reg_size_table
[index
] <= sizeof (_Unwind_Context_Reg_Val
));
335 context
->by_value
[index
] = 1;
336 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
339 /* Return nonzero if register INDEX is stored by value rather than
343 _Unwind_GRByValue (struct _Unwind_Context
*context
, int index
)
345 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
346 return context
->by_value
[index
];
349 /* Retrieve the return address for CONTEXT. */
352 _Unwind_GetIP (struct _Unwind_Context
*context
)
354 return (_Unwind_Ptr
) context
->ra
;
357 /* Retrieve the return address and flag whether that IP is before
358 or after first not yet fully executed instruction. */
361 _Unwind_GetIPInfo (struct _Unwind_Context
*context
, int *ip_before_insn
)
363 *ip_before_insn
= _Unwind_IsSignalFrame (context
);
364 return (_Unwind_Ptr
) context
->ra
;
367 /* Overwrite the return address for CONTEXT with VAL. */
370 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
372 context
->ra
= (void *) val
;
376 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
378 return context
->lsda
;
382 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
384 return (_Unwind_Ptr
) context
->bases
.func
;
388 _Unwind_FindEnclosingFunction (void *pc
)
390 struct dwarf_eh_bases bases
;
391 const struct dwarf_fde
*fde
= _Unwind_Find_FDE (pc
-1, &bases
);
400 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
)
402 return (_Unwind_Ptr
) context
->bases
.dbase
;
406 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
)
408 return (_Unwind_Ptr
) context
->bases
.tbase
;
412 #include "md-unwind-support.h"
414 /* Extract any interesting information from the CIE for the translation
415 unit F belongs to. Return a pointer to the byte after the augmentation,
416 or NULL if we encountered an undecipherable augmentation. */
418 static const unsigned char *
419 extract_cie_info (const struct dwarf_cie
*cie
, struct _Unwind_Context
*context
,
420 _Unwind_FrameState
*fs
)
422 const unsigned char *aug
= cie
->augmentation
;
423 const unsigned char *p
= aug
+ strlen ((const char *)aug
) + 1;
424 const unsigned char *ret
= NULL
;
428 /* g++ v2 "eh" has pointer immediately following augmentation string,
429 so it must be handled first. */
430 if (aug
[0] == 'e' && aug
[1] == 'h')
432 fs
->eh_ptr
= read_pointer (p
);
433 p
+= sizeof (void *);
437 /* After the augmentation resp. pointer for "eh" augmentation
438 follows for CIE version >= 4 address size byte and
439 segment size byte. */
440 if (__builtin_expect (cie
->version
>= 4, 0))
442 if (p
[0] != sizeof (void *) || p
[1] != 0)
446 /* Immediately following this are the code and
447 data alignment and return address column. */
448 p
= read_uleb128 (p
, &utmp
);
449 fs
->code_align
= (_Unwind_Word
)utmp
;
450 p
= read_sleb128 (p
, &stmp
);
451 fs
->data_align
= (_Unwind_Sword
)stmp
;
452 if (cie
->version
== 1)
453 fs
->retaddr_column
= *p
++;
456 p
= read_uleb128 (p
, &utmp
);
457 fs
->retaddr_column
= (_Unwind_Word
)utmp
;
459 fs
->lsda_encoding
= DW_EH_PE_omit
;
461 /* If the augmentation starts with 'z', then a uleb128 immediately
462 follows containing the length of the augmentation field following
466 p
= read_uleb128 (p
, &utmp
);
473 /* Iterate over recognized augmentation subsequences. */
476 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
479 fs
->lsda_encoding
= *p
++;
483 /* "R" indicates a byte indicating how FDE addresses are encoded. */
484 else if (aug
[0] == 'R')
486 fs
->fde_encoding
= *p
++;
490 /* "P" indicates a personality routine in the CIE augmentation. */
491 else if (aug
[0] == 'P')
493 _Unwind_Ptr personality
;
495 p
= read_encoded_value (context
, *p
, p
+ 1, &personality
);
496 fs
->personality
= (_Unwind_Personality_Fn
) personality
;
500 /* "S" indicates a signal frame. */
501 else if (aug
[0] == 'S')
503 fs
->signal_frame
= 1;
506 /* aarch64 B-key pointer authentication. */
507 else if (aug
[0] == 'B')
512 /* Otherwise we have an unknown augmentation string.
513 Bail unless we saw a 'z' prefix. */
518 return ret
? ret
: p
;
522 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
523 onto the stack to start. */
526 execute_stack_op (const unsigned char *op_ptr
, const unsigned char *op_end
,
527 struct _Unwind_Context
*context
, _Unwind_Word initial
)
529 _Unwind_Word stack
[64]; /* ??? Assume this is enough. */
535 while (op_ptr
< op_end
)
537 enum dwarf_location_atom op
= *op_ptr
++;
539 _uleb128_t reg
, utmp
;
540 _sleb128_t offset
, stmp
;
576 result
= op
- DW_OP_lit0
;
580 result
= (_Unwind_Word
) (_Unwind_Ptr
) read_pointer (op_ptr
);
581 op_ptr
+= sizeof (void *);
584 case DW_OP_GNU_encoded_addr
:
587 op_ptr
= read_encoded_value (context
, *op_ptr
, op_ptr
+1, &presult
);
593 result
= read_1u (op_ptr
);
597 result
= read_1s (op_ptr
);
601 result
= read_2u (op_ptr
);
605 result
= read_2s (op_ptr
);
609 result
= read_4u (op_ptr
);
613 result
= read_4s (op_ptr
);
617 result
= read_8u (op_ptr
);
621 result
= read_8s (op_ptr
);
625 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
626 result
= (_Unwind_Word
)utmp
;
629 op_ptr
= read_sleb128 (op_ptr
, &stmp
);
630 result
= (_Unwind_Sword
)stmp
;
665 result
= _Unwind_GetGR (context
, op
- DW_OP_reg0
);
668 op_ptr
= read_uleb128 (op_ptr
, ®
);
669 result
= _Unwind_GetGR (context
, reg
);
704 op_ptr
= read_sleb128 (op_ptr
, &offset
);
705 result
= _Unwind_GetGR (context
, op
- DW_OP_breg0
) + offset
;
708 op_ptr
= read_uleb128 (op_ptr
, ®
);
709 op_ptr
= read_sleb128 (op_ptr
, &offset
);
710 result
= _Unwind_GetGR (context
, reg
) + (_Unwind_Word
)offset
;
714 gcc_assert (stack_elt
);
715 result
= stack
[stack_elt
- 1];
719 gcc_assert (stack_elt
);
725 gcc_assert (offset
< stack_elt
- 1);
726 result
= stack
[stack_elt
- 1 - offset
];
730 gcc_assert (stack_elt
>= 2);
731 result
= stack
[stack_elt
- 2];
737 gcc_assert (stack_elt
>= 2);
738 t
= stack
[stack_elt
- 1];
739 stack
[stack_elt
- 1] = stack
[stack_elt
- 2];
740 stack
[stack_elt
- 2] = t
;
746 _Unwind_Word t1
, t2
, t3
;
748 gcc_assert (stack_elt
>= 3);
749 t1
= stack
[stack_elt
- 1];
750 t2
= stack
[stack_elt
- 2];
751 t3
= stack
[stack_elt
- 3];
752 stack
[stack_elt
- 1] = t2
;
753 stack
[stack_elt
- 2] = t3
;
754 stack
[stack_elt
- 3] = t1
;
759 case DW_OP_deref_size
:
763 case DW_OP_plus_uconst
:
764 /* Unary operations. */
765 gcc_assert (stack_elt
);
768 result
= stack
[stack_elt
];
774 void *ptr
= (void *) (_Unwind_Ptr
) result
;
775 result
= (_Unwind_Ptr
) read_pointer (ptr
);
779 case DW_OP_deref_size
:
781 void *ptr
= (void *) (_Unwind_Ptr
) result
;
785 result
= read_1u (ptr
);
788 result
= read_2u (ptr
);
791 result
= read_4u (ptr
);
794 result
= read_8u (ptr
);
803 if ((_Unwind_Sword
) result
< 0)
812 case DW_OP_plus_uconst
:
813 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
814 result
+= (_Unwind_Word
)utmp
;
840 /* Binary operations. */
841 _Unwind_Word first
, second
;
842 gcc_assert (stack_elt
>= 2);
845 second
= stack
[stack_elt
];
846 first
= stack
[stack_elt
+ 1];
851 result
= second
& first
;
854 result
= (_Unwind_Sword
) second
/ (_Unwind_Sword
) first
;
857 result
= second
- first
;
860 result
= second
% first
;
863 result
= second
* first
;
866 result
= second
| first
;
869 result
= second
+ first
;
872 result
= second
<< first
;
875 result
= second
>> first
;
878 result
= (_Unwind_Sword
) second
>> first
;
881 result
= second
^ first
;
884 result
= (_Unwind_Sword
) second
<= (_Unwind_Sword
) first
;
887 result
= (_Unwind_Sword
) second
>= (_Unwind_Sword
) first
;
890 result
= (_Unwind_Sword
) second
== (_Unwind_Sword
) first
;
893 result
= (_Unwind_Sword
) second
< (_Unwind_Sword
) first
;
896 result
= (_Unwind_Sword
) second
> (_Unwind_Sword
) first
;
899 result
= (_Unwind_Sword
) second
!= (_Unwind_Sword
) first
;
909 offset
= read_2s (op_ptr
);
915 gcc_assert (stack_elt
);
918 offset
= read_2s (op_ptr
);
920 if (stack
[stack_elt
] != 0)
931 /* Most things push a result value. */
932 gcc_assert ((size_t) stack_elt
< sizeof(stack
)/sizeof(*stack
));
933 stack
[stack_elt
++] = result
;
937 /* We were executing this program to get a value. It should be
939 gcc_assert (stack_elt
);
941 return stack
[stack_elt
];
945 /* Decode DWARF 2 call frame information. Takes pointers the
946 instruction sequence to decode, current register information and
947 CIE info, and the PC range to evaluate. */
950 execute_cfa_program (const unsigned char *insn_ptr
,
951 const unsigned char *insn_end
,
952 struct _Unwind_Context
*context
,
953 _Unwind_FrameState
*fs
)
955 struct frame_state_reg_info
*unused_rs
= NULL
;
957 /* Don't allow remember/restore between CIE and FDE programs. */
958 fs
->regs
.prev
= NULL
;
960 /* The comparison with the return address uses < rather than <= because
961 we are only interested in the effects of code before the call; for a
962 noreturn function, the return address may point to unrelated code with
963 a different stack configuration that we are not interested in. We
964 assume that the call itself is unwind info-neutral; if not, or if
965 there are delay instructions that adjust the stack, these must be
966 reflected at the point immediately before the call insn.
967 In signal frames, return address is after last completed instruction,
968 so we add 1 to return address to make the comparison <=. */
969 while (insn_ptr
< insn_end
970 && fs
->pc
< context
->ra
+ _Unwind_IsSignalFrame (context
))
972 unsigned char insn
= *insn_ptr
++;
973 _uleb128_t reg
, utmp
;
974 _sleb128_t offset
, stmp
;
976 if ((insn
& 0xc0) == DW_CFA_advance_loc
)
977 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
978 else if ((insn
& 0xc0) == DW_CFA_offset
)
981 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
982 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
983 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
984 if (UNWIND_COLUMN_IN_RANGE (reg
))
986 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
987 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
990 else if ((insn
& 0xc0) == DW_CFA_restore
)
993 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
994 if (UNWIND_COLUMN_IN_RANGE (reg
))
995 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
1003 insn_ptr
= read_encoded_value (context
, fs
->fde_encoding
,
1005 fs
->pc
= (void *) pc
;
1009 case DW_CFA_advance_loc1
:
1010 fs
->pc
+= read_1u (insn_ptr
) * fs
->code_align
;
1013 case DW_CFA_advance_loc2
:
1014 fs
->pc
+= read_2u (insn_ptr
) * fs
->code_align
;
1017 case DW_CFA_advance_loc4
:
1018 fs
->pc
+= read_4u (insn_ptr
) * fs
->code_align
;
1022 case DW_CFA_offset_extended
:
1023 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1024 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1025 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1026 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1027 if (UNWIND_COLUMN_IN_RANGE (reg
))
1029 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1030 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1034 case DW_CFA_restore_extended
:
1035 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1036 /* FIXME, this is wrong; the CIE might have said that the
1037 register was saved somewhere. */
1038 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1039 if (UNWIND_COLUMN_IN_RANGE (reg
))
1040 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
1043 case DW_CFA_same_value
:
1044 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1045 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1046 if (UNWIND_COLUMN_IN_RANGE (reg
))
1047 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
1050 case DW_CFA_undefined
:
1051 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1052 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1053 if (UNWIND_COLUMN_IN_RANGE (reg
))
1054 fs
->regs
.reg
[reg
].how
= REG_UNDEFINED
;
1060 case DW_CFA_register
:
1063 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1064 insn_ptr
= read_uleb128 (insn_ptr
, ®2
);
1065 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1066 if (UNWIND_COLUMN_IN_RANGE (reg
))
1068 fs
->regs
.reg
[reg
].how
= REG_SAVED_REG
;
1069 fs
->regs
.reg
[reg
].loc
.reg
= (_Unwind_Word
)reg2
;
1074 case DW_CFA_remember_state
:
1076 struct frame_state_reg_info
*new_rs
;
1080 unused_rs
= unused_rs
->prev
;
1083 new_rs
= alloca (sizeof (struct frame_state_reg_info
));
1086 fs
->regs
.prev
= new_rs
;
1090 case DW_CFA_restore_state
:
1092 struct frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
1094 old_rs
->prev
= unused_rs
;
1099 case DW_CFA_def_cfa
:
1100 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1101 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1102 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1103 fs
->regs
.cfa_offset
= (_Unwind_Word
)utmp
;
1104 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1107 case DW_CFA_def_cfa_register
:
1108 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1109 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1110 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1113 case DW_CFA_def_cfa_offset
:
1114 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1115 fs
->regs
.cfa_offset
= utmp
;
1116 /* cfa_how deliberately not set. */
1119 case DW_CFA_def_cfa_expression
:
1120 fs
->regs
.cfa_exp
= insn_ptr
;
1121 fs
->regs
.cfa_how
= CFA_EXP
;
1122 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1126 case DW_CFA_expression
:
1127 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1128 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1129 if (UNWIND_COLUMN_IN_RANGE (reg
))
1131 fs
->regs
.reg
[reg
].how
= REG_SAVED_EXP
;
1132 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1134 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1139 case DW_CFA_offset_extended_sf
:
1140 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1141 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1142 offset
= stmp
* fs
->data_align
;
1143 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1144 if (UNWIND_COLUMN_IN_RANGE (reg
))
1146 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1147 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1151 case DW_CFA_def_cfa_sf
:
1152 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1153 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1154 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1155 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1156 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1157 fs
->regs
.cfa_offset
*= fs
->data_align
;
1160 case DW_CFA_def_cfa_offset_sf
:
1161 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1162 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1163 fs
->regs
.cfa_offset
*= fs
->data_align
;
1164 /* cfa_how deliberately not set. */
1167 case DW_CFA_val_offset
:
1168 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1169 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1170 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1171 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1172 if (UNWIND_COLUMN_IN_RANGE (reg
))
1174 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_OFFSET
;
1175 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1179 case DW_CFA_val_offset_sf
:
1180 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1181 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1182 offset
= stmp
* fs
->data_align
;
1183 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1184 if (UNWIND_COLUMN_IN_RANGE (reg
))
1186 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_OFFSET
;
1187 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1191 case DW_CFA_val_expression
:
1192 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1193 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1194 if (UNWIND_COLUMN_IN_RANGE (reg
))
1196 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_EXP
;
1197 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1199 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1203 case DW_CFA_GNU_window_save
:
1204 #if defined (__aarch64__) && !defined (__ILP32__)
1205 /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle
1206 return address signing status. */
1207 fs
->regs
.reg
[DWARF_REGNUM_AARCH64_RA_STATE
].loc
.offset
^= 1;
1209 /* ??? Hardcoded for SPARC register window configuration. */
1210 if (__LIBGCC_DWARF_FRAME_REGISTERS__
>= 32)
1211 for (reg
= 16; reg
< 32; ++reg
)
1213 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1214 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * sizeof (void *);
1219 case DW_CFA_GNU_args_size
:
1220 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1221 context
->args_size
= (_Unwind_Word
)utmp
;
1224 case DW_CFA_GNU_negative_offset_extended
:
1225 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1226 older PowerPC code. */
1227 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1228 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1229 offset
= (_Unwind_Word
) utmp
* fs
->data_align
;
1230 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1231 if (UNWIND_COLUMN_IN_RANGE (reg
))
1233 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1234 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
1244 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
1245 its caller and decode it into FS. This function also sets the
1246 args_size and lsda members of CONTEXT, as they are really information
1247 about the caller's frame. */
1249 static _Unwind_Reason_Code
1250 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1252 const struct dwarf_fde
*fde
;
1253 const struct dwarf_cie
*cie
;
1254 const unsigned char *aug
, *insn
, *end
;
1256 memset (fs
, 0, sizeof (*fs
));
1257 context
->args_size
= 0;
1260 if (context
->ra
== 0)
1261 return _URC_END_OF_STACK
;
1263 fde
= _Unwind_Find_FDE (context
->ra
+ _Unwind_IsSignalFrame (context
) - 1,
1267 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1268 /* Couldn't find frame unwind info for this function. Try a
1269 target-specific fallback mechanism. This will necessarily
1270 not provide a personality routine or LSDA. */
1271 return MD_FALLBACK_FRAME_STATE_FOR (context
, fs
);
1273 return _URC_END_OF_STACK
;
1277 fs
->pc
= context
->bases
.func
;
1279 cie
= get_cie (fde
);
1280 insn
= extract_cie_info (cie
, context
, fs
);
1282 /* CIE contained unknown augmentation. */
1283 return _URC_FATAL_PHASE1_ERROR
;
1285 /* First decode all the insns in the CIE. */
1286 end
= (const unsigned char *) next_fde ((const struct dwarf_fde
*) cie
);
1287 execute_cfa_program (insn
, end
, context
, fs
);
1289 /* Locate augmentation for the fde. */
1290 aug
= (const unsigned char *) fde
+ sizeof (*fde
);
1291 aug
+= 2 * size_of_encoded_value (fs
->fde_encoding
);
1296 aug
= read_uleb128 (aug
, &i
);
1299 if (fs
->lsda_encoding
!= DW_EH_PE_omit
)
1303 aug
= read_encoded_value (context
, fs
->lsda_encoding
, aug
, &lsda
);
1304 context
->lsda
= (void *) lsda
;
1307 /* Then the insns in the FDE up to our target PC. */
1310 end
= (const unsigned char *) next_fde (fde
);
1311 execute_cfa_program (insn
, end
, context
, fs
);
1313 return _URC_NO_REASON
;
1316 typedef struct frame_state
1322 long reg_or_offset
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1323 unsigned short cfa_reg
;
1324 unsigned short retaddr_column
;
1325 char saved
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1328 struct frame_state
* __frame_state_for (void *, struct frame_state
*);
1330 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
1331 a given PC_TARGET. The caller should allocate a local variable of
1332 `struct frame_state' and pass its address to STATE_IN. */
1334 struct frame_state
*
1335 __frame_state_for (void *pc_target
, struct frame_state
*state_in
)
1337 struct _Unwind_Context context
;
1338 _Unwind_FrameState fs
;
1341 memset (&context
, 0, sizeof (struct _Unwind_Context
));
1342 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1343 context
.flags
= EXTENDED_CONTEXT_BIT
;
1344 context
.ra
= pc_target
+ 1;
1346 if (uw_frame_state_for (&context
, &fs
) != _URC_NO_REASON
)
1349 /* We have no way to pass a location expression for the CFA to our
1350 caller. It wouldn't understand it anyway. */
1351 if (fs
.regs
.cfa_how
== CFA_EXP
)
1354 for (reg
= 0; reg
< PRE_GCC3_DWARF_FRAME_REGISTERS
+ 1; reg
++)
1356 state_in
->saved
[reg
] = fs
.regs
.reg
[reg
].how
;
1357 switch (state_in
->saved
[reg
])
1360 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.reg
;
1362 case REG_SAVED_OFFSET
:
1363 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.offset
;
1366 state_in
->reg_or_offset
[reg
] = 0;
1371 state_in
->cfa_offset
= fs
.regs
.cfa_offset
;
1372 state_in
->cfa_reg
= fs
.regs
.cfa_reg
;
1373 state_in
->retaddr_column
= fs
.retaddr_column
;
1374 state_in
->args_size
= context
.args_size
;
1375 state_in
->eh_ptr
= fs
.eh_ptr
;
1380 typedef union { _Unwind_Ptr ptr
; _Unwind_Word word
; } _Unwind_SpTmp
;
1383 _Unwind_SetSpColumn (struct _Unwind_Context
*context
, void *cfa
,
1384 _Unwind_SpTmp
*tmp_sp
)
1386 int size
= dwarf_reg_size_table
[__builtin_dwarf_sp_column ()];
1388 if (size
== sizeof(_Unwind_Ptr
))
1389 tmp_sp
->ptr
= (_Unwind_Ptr
) cfa
;
1392 gcc_assert (size
== sizeof(_Unwind_Word
));
1393 tmp_sp
->word
= (_Unwind_Ptr
) cfa
;
1395 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), tmp_sp
);
1399 uw_update_context_1 (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1401 struct _Unwind_Context orig_context
= *context
;
1405 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
1406 /* Special handling here: Many machines do not use a frame pointer,
1407 and track the CFA only through offsets from the stack pointer from
1408 one frame to the next. In this case, the stack pointer is never
1409 stored, so it has no saved address in the context. What we do
1410 have is the CFA from the previous stack frame.
1412 In very special situations (such as unwind info for signal return),
1413 there may be location expressions that use the stack pointer as well.
1415 Do this conditionally for one frame. This allows the unwind info
1416 for one frame to save a copy of the stack pointer from the previous
1417 frame, and be able to use much easier CFA mechanisms to do it.
1418 Always zap the saved stack pointer value for the next frame; carrying
1419 the value over from one frame to another doesn't make sense. */
1421 _Unwind_SpTmp tmp_sp
;
1423 if (!_Unwind_GetGRPtr (&orig_context
, __builtin_dwarf_sp_column ()))
1424 _Unwind_SetSpColumn (&orig_context
, context
->cfa
, &tmp_sp
);
1425 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), NULL
);
1428 /* Compute this frame's CFA. */
1429 switch (fs
->regs
.cfa_how
)
1431 case CFA_REG_OFFSET
:
1432 cfa
= _Unwind_GetPtr (&orig_context
, fs
->regs
.cfa_reg
);
1433 cfa
+= fs
->regs
.cfa_offset
;
1438 const unsigned char *exp
= fs
->regs
.cfa_exp
;
1441 exp
= read_uleb128 (exp
, &len
);
1442 cfa
= (void *) (_Unwind_Ptr
)
1443 execute_stack_op (exp
, exp
+ len
, &orig_context
, 0);
1452 /* Compute the addresses of all registers saved in this frame. */
1453 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
+ 1; ++i
)
1454 switch (fs
->regs
.reg
[i
].how
)
1460 case REG_SAVED_OFFSET
:
1461 _Unwind_SetGRPtr (context
, i
,
1462 (void *) (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1466 if (_Unwind_GRByValue (&orig_context
, fs
->regs
.reg
[i
].loc
.reg
))
1467 _Unwind_SetGRValue (context
, i
,
1468 _Unwind_GetGR (&orig_context
,
1469 fs
->regs
.reg
[i
].loc
.reg
));
1471 _Unwind_SetGRPtr (context
, i
,
1472 _Unwind_GetGRPtr (&orig_context
,
1473 fs
->regs
.reg
[i
].loc
.reg
));
1478 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1482 exp
= read_uleb128 (exp
, &len
);
1483 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1485 _Unwind_SetGRPtr (context
, i
, (void *) val
);
1489 case REG_SAVED_VAL_OFFSET
:
1490 _Unwind_SetGRValue (context
, i
,
1491 (_Unwind_Internal_Ptr
)
1492 (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1495 case REG_SAVED_VAL_EXP
:
1497 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1501 exp
= read_uleb128 (exp
, &len
);
1502 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1504 _Unwind_SetGRValue (context
, i
, val
);
1509 _Unwind_SetSignalFrame (context
, fs
->signal_frame
);
1511 #ifdef MD_FROB_UPDATE_CONTEXT
1512 MD_FROB_UPDATE_CONTEXT (context
, fs
);
1516 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1517 of its caller. Update CONTEXT to refer to the caller as well. Note
1518 that the args_size and lsda members are not updated here, but later in
1519 uw_frame_state_for. */
1522 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1524 uw_update_context_1 (context
, fs
);
1526 /* In general this unwinder doesn't make any distinction between
1527 undefined and same_value rule. Call-saved registers are assumed
1528 to have same_value rule by default and explicit undefined
1529 rule is handled like same_value. The only exception is
1530 DW_CFA_undefined on retaddr_column which is supposed to
1531 mark outermost frame in DWARF 3. */
1532 if (fs
->regs
.reg
[DWARF_REG_TO_UNWIND_COLUMN (fs
->retaddr_column
)].how
1534 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1539 /* Compute the return address now, since the return address column
1540 can change from frame to frame. */
1541 context
->ra
= __builtin_extract_return_addr
1542 (_Unwind_GetPtr (context
, fs
->retaddr_column
));
1543 #ifdef MD_POST_EXTRACT_FRAME_ADDR
1544 context
->ra
= MD_POST_EXTRACT_FRAME_ADDR (context
, fs
, context
->ra
);
1550 uw_advance_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1552 uw_update_context (context
, fs
);
1555 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1556 level will be the return address and the CFA. */
1558 #define uw_init_context(CONTEXT) \
1561 /* Do any necessary initialization to access arbitrary stack frames. \
1562 On the SPARC, this means flushing the register windows. */ \
1563 __builtin_unwind_init (); \
1564 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1565 __builtin_return_address (0)); \
1570 init_dwarf_reg_size_table (void)
1572 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table
);
1575 static void __attribute__((noinline
))
1576 uw_init_context_1 (struct _Unwind_Context
*context
,
1577 void *outer_cfa
, void *outer_ra
)
1579 void *ra
= __builtin_extract_return_addr (__builtin_return_address (0));
1580 #ifdef MD_POST_EXTRACT_ROOT_ADDR
1581 ra
= MD_POST_EXTRACT_ROOT_ADDR (ra
);
1583 _Unwind_FrameState fs
;
1584 _Unwind_SpTmp sp_slot
;
1585 _Unwind_Reason_Code code
;
1587 memset (context
, 0, sizeof (struct _Unwind_Context
));
1589 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1590 context
->flags
= EXTENDED_CONTEXT_BIT
;
1592 code
= uw_frame_state_for (context
, &fs
);
1593 gcc_assert (code
== _URC_NO_REASON
);
1597 static __gthread_once_t once_regsizes
= __GTHREAD_ONCE_INIT
;
1598 if (__gthread_once (&once_regsizes
, init_dwarf_reg_size_table
) != 0
1599 && dwarf_reg_size_table
[0] == 0)
1600 init_dwarf_reg_size_table ();
1603 if (dwarf_reg_size_table
[0] == 0)
1604 init_dwarf_reg_size_table ();
1607 /* Force the frame state to use the known cfa value. */
1608 _Unwind_SetSpColumn (context
, outer_cfa
, &sp_slot
);
1609 fs
.regs
.cfa_how
= CFA_REG_OFFSET
;
1610 fs
.regs
.cfa_reg
= __builtin_dwarf_sp_column ();
1611 fs
.regs
.cfa_offset
= 0;
1613 uw_update_context_1 (context
, &fs
);
1615 /* If the return address column was saved in a register in the
1616 initialization context, then we can't see it in the given
1617 call frame data. So have the initialization context tell us. */
1618 context
->ra
= __builtin_extract_return_addr (outer_ra
);
1619 #ifdef MD_POST_EXTRACT_ROOT_ADDR
1620 context
->ra
= MD_POST_EXTRACT_ROOT_ADDR (context
->ra
);
1624 static void _Unwind_DebugHook (void *, void *)
1625 __attribute__ ((__noinline__
, __used__
, __noclone__
));
1627 /* This function is called during unwinding. It is intended as a hook
1628 for a debugger to intercept exceptions. CFA is the CFA of the
1629 target frame. HANDLER is the PC to which control will be
1632 _Unwind_DebugHook (void *cfa
__attribute__ ((__unused__
)),
1633 void *handler
__attribute__ ((__unused__
)))
1635 /* We only want to use stap probes starting with v3. Earlier
1636 versions added too much startup cost. */
1637 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
1638 STAP_PROBE2 (libgcc
, unwind
, cfa
, handler
);
1644 /* Frob exception handler's address kept in TARGET before installing into
1647 static inline void *
1648 uw_frob_return_addr (struct _Unwind_Context
*current
1649 __attribute__ ((__unused__
)),
1650 struct _Unwind_Context
*target
)
1652 void *ret_addr
= __builtin_frob_return_addr (target
->ra
);
1653 #ifdef MD_POST_FROB_EH_HANDLER_ADDR
1654 ret_addr
= MD_POST_FROB_EH_HANDLER_ADDR (current
, target
, ret_addr
);
1659 /* Install TARGET into CURRENT so that we can return to it. This is a
1660 macro because __builtin_eh_return must be invoked in the context of
1661 our caller. FRAMES is a number of frames to be unwind.
1662 _Unwind_Frames_Extra is a macro to do additional work during unwinding
1663 if needed, for example shadow stack pointer adjustment for Intel CET
1666 #define uw_install_context(CURRENT, TARGET, FRAMES) \
1669 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1670 void *handler = uw_frob_return_addr ((CURRENT), (TARGET)); \
1671 _Unwind_DebugHook ((TARGET)->cfa, handler); \
1672 _Unwind_Frames_Extra (FRAMES); \
1673 __builtin_eh_return (offset, handler); \
1678 uw_install_context_1 (struct _Unwind_Context
*current
,
1679 struct _Unwind_Context
*target
)
1682 _Unwind_SpTmp sp_slot
;
1684 /* If the target frame does not have a saved stack pointer,
1685 then set up the target's CFA. */
1686 if (!_Unwind_GetGRPtr (target
, __builtin_dwarf_sp_column ()))
1687 _Unwind_SetSpColumn (target
, target
->cfa
, &sp_slot
);
1689 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
; ++i
)
1691 void *c
= (void *) (_Unwind_Internal_Ptr
) current
->reg
[i
];
1692 void *t
= (void *) (_Unwind_Internal_Ptr
)target
->reg
[i
];
1694 gcc_assert (current
->by_value
[i
] == 0);
1695 if (target
->by_value
[i
] && c
)
1699 if (dwarf_reg_size_table
[i
] == sizeof (_Unwind_Word
))
1701 w
= (_Unwind_Internal_Ptr
) t
;
1702 memcpy (c
, &w
, sizeof (_Unwind_Word
));
1706 gcc_assert (dwarf_reg_size_table
[i
] == sizeof (_Unwind_Ptr
));
1707 p
= (_Unwind_Internal_Ptr
) t
;
1708 memcpy (c
, &p
, sizeof (_Unwind_Ptr
));
1711 else if (t
&& c
&& t
!= c
)
1712 memcpy (c
, t
, dwarf_reg_size_table
[i
]);
1715 /* If the current frame doesn't have a saved stack pointer, then we
1716 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1717 pointer value reloaded. */
1718 if (!_Unwind_GetGRPtr (current
, __builtin_dwarf_sp_column ()))
1722 target_cfa
= _Unwind_GetPtr (target
, __builtin_dwarf_sp_column ());
1724 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1725 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1726 return target_cfa
- current
->cfa
+ target
->args_size
;
1728 return current
->cfa
- target_cfa
- target
->args_size
;
1733 static inline _Unwind_Ptr
1734 uw_identify_context (struct _Unwind_Context
*context
)
1736 /* The CFA is not sufficient to disambiguate the context of a function
1737 interrupted by a signal before establishing its frame and the context
1738 of the signal itself. */
1739 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1740 return _Unwind_GetCFA (context
) - _Unwind_IsSignalFrame (context
);
1742 return _Unwind_GetCFA (context
) + _Unwind_IsSignalFrame (context
);
1746 #include "unwind.inc"
1748 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1749 alias (_Unwind_Backtrace
);
1750 alias (_Unwind_DeleteException
);
1751 alias (_Unwind_FindEnclosingFunction
);
1752 alias (_Unwind_ForcedUnwind
);
1753 alias (_Unwind_GetDataRelBase
);
1754 alias (_Unwind_GetTextRelBase
);
1755 alias (_Unwind_GetCFA
);
1756 alias (_Unwind_GetGR
);
1757 alias (_Unwind_GetIP
);
1758 alias (_Unwind_GetLanguageSpecificData
);
1759 alias (_Unwind_GetRegionStart
);
1760 alias (_Unwind_RaiseException
);
1761 alias (_Unwind_Resume
);
1762 alias (_Unwind_Resume_or_Rethrow
);
1763 alias (_Unwind_SetGR
);
1764 alias (_Unwind_SetIP
);
1767 #endif /* !USING_SJLJ_EXCEPTIONS */