1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997-2022 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"
45 #ifndef __USING_SJLJ_EXCEPTIONS__
47 #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
48 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
50 #undef __LIBGCC_STACK_GROWS_DOWNWARD__
51 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
54 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
55 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
56 #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
59 /* ??? For the public function interfaces, we tend to gcc_assert that the
60 column numbers are in range. For the dwarf2 unwind info this does happen,
61 although so far in a case that doesn't actually matter.
63 See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
64 the call-saved xmm registers and annotates them. We havn't bothered
65 providing support for the xmm registers for the x86_64 port primarily
66 because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
67 SEH instead. Adding the support for unix targets would generally be a
68 waste. However, some runtime libraries supplied with ICC do contain such
69 an unorthodox transition, as well as the unwind info to match. This loss
70 of register restoration doesn't matter in practice, because the exception
71 is caught in the native unix abi, where all of the xmm registers are
74 Ideally, we'd record some bit to notice when we're failing to restore some
75 register recorded in the unwind info, but to do that we need annotation on
76 the unix->ms abi edge, so that we know when the register data may be
77 discarded. And since this edge is also within the ICC library, we're
78 unlikely to be able to get the new annotation.
80 Barring a magic solution to restore the ms abi defined 128-bit xmm registers
81 (as distictly opposed to the full runtime width) without causing extra
82 overhead for normal unix abis, the best solution seems to be to simply
83 ignore unwind data for unknown columns. */
85 #define UNWIND_COLUMN_IN_RANGE(x) \
86 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
88 #ifdef REG_VALUE_IN_UNWIND_CONTEXT
89 typedef _Unwind_Word _Unwind_Context_Reg_Val
;
91 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
92 #define ASSUME_EXTENDED_UNWIND_CONTEXT 1
95 static inline _Unwind_Word
96 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val
)
101 static inline _Unwind_Context_Reg_Val
102 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val
)
107 typedef void *_Unwind_Context_Reg_Val
;
109 static inline _Unwind_Word
110 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val
)
112 return (_Unwind_Word
) (_Unwind_Internal_Ptr
) val
;
115 static inline _Unwind_Context_Reg_Val
116 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val
)
118 return (_Unwind_Context_Reg_Val
) (_Unwind_Internal_Ptr
) val
;
122 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
123 #define ASSUME_EXTENDED_UNWIND_CONTEXT 0
126 /* This is the register and unwind state for a particular frame. This
127 provides the information necessary to unwind up past a frame and return
129 struct _Unwind_Context
131 _Unwind_Context_Reg_Val reg
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
135 struct dwarf_eh_bases bases
;
136 /* Signal frame context. */
137 #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
138 /* Context which has version/args_size/by_value fields. */
139 #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
140 /* Bit reserved on AArch64, return address has been signed with A or B
142 #define RA_SIGNED_BIT ((~(_Unwind_Word) 0 >> 3) + 1)
144 /* 0 for now, can be increased when further fields are added to
145 struct _Unwind_Context. */
146 _Unwind_Word version
;
147 _Unwind_Word args_size
;
148 char by_value
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
151 #ifdef __LIBGCC_DWARF_REG_SIZES_CONSTANT__
152 static inline unsigned char
153 dwarf_reg_size (int index
__attribute__ ((__unused__
)))
155 return __LIBGCC_DWARF_REG_SIZES_CONSTANT__
;
158 /* Byte size of every register managed by these routines. */
159 static unsigned char dwarf_reg_size_table
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
162 static inline unsigned char
163 dwarf_reg_size (unsigned index
)
165 gcc_assert (index
< sizeof (dwarf_reg_size_table
));
166 return dwarf_reg_size_table
[index
];
171 /* Read unaligned data from the instruction buffer. */
176 unsigned u2
__attribute__ ((mode (HI
)));
177 unsigned u4
__attribute__ ((mode (SI
)));
178 unsigned u8
__attribute__ ((mode (DI
)));
179 signed s2
__attribute__ ((mode (HI
)));
180 signed s4
__attribute__ ((mode (SI
)));
181 signed s8
__attribute__ ((mode (DI
)));
182 } __attribute__ ((packed
));
184 static void uw_update_context (struct _Unwind_Context
*, _Unwind_FrameState
*);
185 static _Unwind_Reason_Code
uw_frame_state_for (struct _Unwind_Context
*,
186 _Unwind_FrameState
*);
189 read_pointer (const void *p
) { const union unaligned
*up
= p
; return up
->p
; }
192 read_1u (const void *p
) { return *(const unsigned char *) p
; }
195 read_1s (const void *p
) { return *(const signed char *) p
; }
198 read_2u (const void *p
) { const union unaligned
*up
= p
; return up
->u2
; }
201 read_2s (const void *p
) { const union unaligned
*up
= p
; return up
->s2
; }
203 static inline unsigned int
204 read_4u (const void *p
) { const union unaligned
*up
= p
; return up
->u4
; }
207 read_4s (const void *p
) { const union unaligned
*up
= p
; return up
->s4
; }
209 static inline unsigned long
210 read_8u (const void *p
) { const union unaligned
*up
= p
; return up
->u8
; }
212 static inline unsigned long
213 read_8s (const void *p
) { const union unaligned
*up
= p
; return up
->s8
; }
215 static inline _Unwind_Word
216 _Unwind_IsSignalFrame (struct _Unwind_Context
*context
)
218 return (context
->flags
& SIGNAL_FRAME_BIT
) ? 1 : 0;
222 _Unwind_SetSignalFrame (struct _Unwind_Context
*context
, int val
)
225 context
->flags
|= SIGNAL_FRAME_BIT
;
227 context
->flags
&= ~SIGNAL_FRAME_BIT
;
230 static inline _Unwind_Word
231 _Unwind_IsExtendedContext (struct _Unwind_Context
*context
)
233 return (ASSUME_EXTENDED_UNWIND_CONTEXT
234 || (context
->flags
& EXTENDED_CONTEXT_BIT
));
237 /* Get the value of register REGNO as saved in CONTEXT. */
240 _Unwind_GetGR (struct _Unwind_Context
*context
, int regno
)
243 _Unwind_Context_Reg_Val val
;
245 #ifdef DWARF_ZERO_REG
246 if (regno
== DWARF_ZERO_REG
)
250 index
= DWARF_REG_TO_UNWIND_COLUMN (regno
);
251 size
= dwarf_reg_size (index
);
252 val
= context
->reg
[index
];
254 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
255 return _Unwind_Get_Unwind_Word (val
);
257 #ifdef DWARF_LAZY_REGISTER_VALUE
260 if (DWARF_LAZY_REGISTER_VALUE (regno
, &value
))
265 /* This will segfault if the register hasn't been saved. */
266 if (size
== sizeof(_Unwind_Ptr
))
267 return * (_Unwind_Ptr
*) (_Unwind_Internal_Ptr
) val
;
270 gcc_assert (size
== sizeof(_Unwind_Word
));
271 return * (_Unwind_Word
*) (_Unwind_Internal_Ptr
) val
;
276 _Unwind_GetPtr (struct _Unwind_Context
*context
, int index
)
278 return (void *)(_Unwind_Ptr
) _Unwind_GetGR (context
, index
);
281 /* Get the value of the CFA as saved in CONTEXT. */
284 _Unwind_GetCFA (struct _Unwind_Context
*context
)
286 return (_Unwind_Ptr
) context
->cfa
;
289 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
292 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
297 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
298 size
= dwarf_reg_size (index
);
300 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
302 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
306 ptr
= (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
308 if (size
== sizeof(_Unwind_Ptr
))
309 * (_Unwind_Ptr
*) ptr
= val
;
312 gcc_assert (size
== sizeof(_Unwind_Word
));
313 * (_Unwind_Word
*) ptr
= val
;
317 /* Get the pointer to a register INDEX as saved in CONTEXT. */
320 _Unwind_GetGRPtr (struct _Unwind_Context
*context
, int index
)
322 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
323 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
324 return &context
->reg
[index
];
325 return (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
328 /* Set the pointer to a register INDEX as saved in CONTEXT. */
331 _Unwind_SetGRPtr (struct _Unwind_Context
*context
, int index
, void *p
)
333 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
334 if (_Unwind_IsExtendedContext (context
))
335 context
->by_value
[index
] = 0;
336 context
->reg
[index
] = (_Unwind_Context_Reg_Val
) (_Unwind_Internal_Ptr
) p
;
339 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
342 _Unwind_SetGRValue (struct _Unwind_Context
*context
, int index
,
345 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
346 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
347 gcc_assert (dwarf_reg_size (index
) <= sizeof (_Unwind_Context_Reg_Val
));
349 context
->by_value
[index
] = 1;
350 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
353 /* Return nonzero if register INDEX is stored by value rather than
357 _Unwind_GRByValue (struct _Unwind_Context
*context
, int index
)
359 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
360 return context
->by_value
[index
];
363 /* Retrieve the return address for CONTEXT. */
366 _Unwind_GetIP (struct _Unwind_Context
*context
)
368 return (_Unwind_Ptr
) context
->ra
;
371 /* Retrieve the return address and flag whether that IP is before
372 or after first not yet fully executed instruction. */
375 _Unwind_GetIPInfo (struct _Unwind_Context
*context
, int *ip_before_insn
)
377 *ip_before_insn
= _Unwind_IsSignalFrame (context
);
378 return (_Unwind_Ptr
) context
->ra
;
381 /* Overwrite the return address for CONTEXT with VAL. */
384 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
386 context
->ra
= (void *) val
;
390 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
392 return context
->lsda
;
396 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
398 return (_Unwind_Ptr
) context
->bases
.func
;
402 _Unwind_FindEnclosingFunction (void *pc
)
404 struct dwarf_eh_bases bases
;
405 const struct dwarf_fde
*fde
= _Unwind_Find_FDE (pc
-1, &bases
);
414 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
)
416 return (_Unwind_Ptr
) context
->bases
.dbase
;
420 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
)
422 return (_Unwind_Ptr
) context
->bases
.tbase
;
426 #include "md-unwind-support.h"
428 /* Extract any interesting information from the CIE for the translation
429 unit F belongs to. Return a pointer to the byte after the augmentation,
430 or NULL if we encountered an undecipherable augmentation. */
432 static const unsigned char *
433 extract_cie_info (const struct dwarf_cie
*cie
, struct _Unwind_Context
*context
,
434 _Unwind_FrameState
*fs
)
436 const unsigned char *aug
= cie
->augmentation
;
437 const unsigned char *p
= aug
+ strlen ((const char *)aug
) + 1;
438 const unsigned char *ret
= NULL
;
442 /* g++ v2 "eh" has pointer immediately following augmentation string,
443 so it must be handled first. */
444 if (aug
[0] == 'e' && aug
[1] == 'h')
446 fs
->eh_ptr
= read_pointer (p
);
447 p
+= sizeof (void *);
451 /* After the augmentation resp. pointer for "eh" augmentation
452 follows for CIE version >= 4 address size byte and
453 segment size byte. */
454 if (__builtin_expect (cie
->version
>= 4, 0))
456 if (p
[0] != sizeof (void *) || p
[1] != 0)
460 /* Immediately following this are the code and
461 data alignment and return address column. */
462 p
= read_uleb128 (p
, &utmp
);
463 fs
->code_align
= (_Unwind_Word
)utmp
;
464 p
= read_sleb128 (p
, &stmp
);
465 fs
->data_align
= (_Unwind_Sword
)stmp
;
466 if (cie
->version
== 1)
467 fs
->retaddr_column
= *p
++;
470 p
= read_uleb128 (p
, &utmp
);
471 fs
->retaddr_column
= (_Unwind_Word
)utmp
;
473 fs
->lsda_encoding
= DW_EH_PE_omit
;
475 /* If the augmentation starts with 'z', then a uleb128 immediately
476 follows containing the length of the augmentation field following
480 p
= read_uleb128 (p
, &utmp
);
487 /* Iterate over recognized augmentation subsequences. */
490 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
493 fs
->lsda_encoding
= *p
++;
497 /* "R" indicates a byte indicating how FDE addresses are encoded. */
498 else if (aug
[0] == 'R')
500 fs
->fde_encoding
= *p
++;
504 /* "P" indicates a personality routine in the CIE augmentation. */
505 else if (aug
[0] == 'P')
507 _Unwind_Ptr personality
;
509 p
= read_encoded_value (context
, *p
, p
+ 1, &personality
);
510 fs
->personality
= (_Unwind_Personality_Fn
) personality
;
514 /* "S" indicates a signal frame. */
515 else if (aug
[0] == 'S')
517 fs
->signal_frame
= 1;
520 /* aarch64 B-key pointer authentication. */
521 else if (aug
[0] == 'B')
526 /* Otherwise we have an unknown augmentation string.
527 Bail unless we saw a 'z' prefix. */
532 return ret
? ret
: p
;
536 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
537 onto the stack to start. */
540 execute_stack_op (const unsigned char *op_ptr
, const unsigned char *op_end
,
541 struct _Unwind_Context
*context
, _Unwind_Word initial
)
543 _Unwind_Word stack
[64]; /* ??? Assume this is enough. */
549 while (op_ptr
< op_end
)
551 enum dwarf_location_atom op
= *op_ptr
++;
553 _uleb128_t reg
, utmp
;
554 _sleb128_t offset
, stmp
;
590 result
= op
- DW_OP_lit0
;
594 result
= (_Unwind_Word
) (_Unwind_Ptr
) read_pointer (op_ptr
);
595 op_ptr
+= sizeof (void *);
598 case DW_OP_GNU_encoded_addr
:
601 op_ptr
= read_encoded_value (context
, *op_ptr
, op_ptr
+1, &presult
);
607 result
= read_1u (op_ptr
);
611 result
= read_1s (op_ptr
);
615 result
= read_2u (op_ptr
);
619 result
= read_2s (op_ptr
);
623 result
= read_4u (op_ptr
);
627 result
= read_4s (op_ptr
);
631 result
= read_8u (op_ptr
);
635 result
= read_8s (op_ptr
);
639 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
640 result
= (_Unwind_Word
)utmp
;
643 op_ptr
= read_sleb128 (op_ptr
, &stmp
);
644 result
= (_Unwind_Sword
)stmp
;
679 result
= _Unwind_GetGR (context
, op
- DW_OP_reg0
);
682 op_ptr
= read_uleb128 (op_ptr
, ®
);
683 result
= _Unwind_GetGR (context
, reg
);
718 op_ptr
= read_sleb128 (op_ptr
, &offset
);
719 result
= _Unwind_GetGR (context
, op
- DW_OP_breg0
) + offset
;
722 op_ptr
= read_uleb128 (op_ptr
, ®
);
723 op_ptr
= read_sleb128 (op_ptr
, &offset
);
724 result
= _Unwind_GetGR (context
, reg
) + (_Unwind_Word
)offset
;
728 gcc_assert (stack_elt
);
729 result
= stack
[stack_elt
- 1];
733 gcc_assert (stack_elt
);
739 gcc_assert (offset
< stack_elt
- 1);
740 result
= stack
[stack_elt
- 1 - offset
];
744 gcc_assert (stack_elt
>= 2);
745 result
= stack
[stack_elt
- 2];
751 gcc_assert (stack_elt
>= 2);
752 t
= stack
[stack_elt
- 1];
753 stack
[stack_elt
- 1] = stack
[stack_elt
- 2];
754 stack
[stack_elt
- 2] = t
;
760 _Unwind_Word t1
, t2
, t3
;
762 gcc_assert (stack_elt
>= 3);
763 t1
= stack
[stack_elt
- 1];
764 t2
= stack
[stack_elt
- 2];
765 t3
= stack
[stack_elt
- 3];
766 stack
[stack_elt
- 1] = t2
;
767 stack
[stack_elt
- 2] = t3
;
768 stack
[stack_elt
- 3] = t1
;
773 case DW_OP_deref_size
:
777 case DW_OP_plus_uconst
:
778 /* Unary operations. */
779 gcc_assert (stack_elt
);
782 result
= stack
[stack_elt
];
788 void *ptr
= (void *) (_Unwind_Ptr
) result
;
789 result
= (_Unwind_Ptr
) read_pointer (ptr
);
793 case DW_OP_deref_size
:
795 void *ptr
= (void *) (_Unwind_Ptr
) result
;
799 result
= read_1u (ptr
);
802 result
= read_2u (ptr
);
805 result
= read_4u (ptr
);
808 result
= read_8u (ptr
);
817 if ((_Unwind_Sword
) result
< 0)
826 case DW_OP_plus_uconst
:
827 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
828 result
+= (_Unwind_Word
)utmp
;
854 /* Binary operations. */
855 _Unwind_Word first
, second
;
856 gcc_assert (stack_elt
>= 2);
859 second
= stack
[stack_elt
];
860 first
= stack
[stack_elt
+ 1];
865 result
= second
& first
;
868 result
= (_Unwind_Sword
) second
/ (_Unwind_Sword
) first
;
871 result
= second
- first
;
874 result
= second
% first
;
877 result
= second
* first
;
880 result
= second
| first
;
883 result
= second
+ first
;
886 result
= second
<< first
;
889 result
= second
>> first
;
892 result
= (_Unwind_Sword
) second
>> first
;
895 result
= second
^ first
;
898 result
= (_Unwind_Sword
) second
<= (_Unwind_Sword
) first
;
901 result
= (_Unwind_Sword
) second
>= (_Unwind_Sword
) first
;
904 result
= (_Unwind_Sword
) second
== (_Unwind_Sword
) first
;
907 result
= (_Unwind_Sword
) second
< (_Unwind_Sword
) first
;
910 result
= (_Unwind_Sword
) second
> (_Unwind_Sword
) first
;
913 result
= (_Unwind_Sword
) second
!= (_Unwind_Sword
) first
;
923 offset
= read_2s (op_ptr
);
929 gcc_assert (stack_elt
);
932 offset
= read_2s (op_ptr
);
934 if (stack
[stack_elt
] != 0)
945 /* Most things push a result value. */
946 gcc_assert ((size_t) stack_elt
< sizeof(stack
)/sizeof(*stack
));
947 stack
[stack_elt
++] = result
;
951 /* We were executing this program to get a value. It should be
953 gcc_assert (stack_elt
);
955 return stack
[stack_elt
];
959 /* Decode DWARF 2 call frame information. Takes pointers the
960 instruction sequence to decode, current register information and
961 CIE info, and the PC range to evaluate. */
964 execute_cfa_program (const unsigned char *insn_ptr
,
965 const unsigned char *insn_end
,
966 struct _Unwind_Context
*context
,
967 _Unwind_FrameState
*fs
)
969 struct frame_state_reg_info
*unused_rs
= NULL
;
971 /* Don't allow remember/restore between CIE and FDE programs. */
972 fs
->regs
.prev
= NULL
;
974 /* The comparison with the return address uses < rather than <= because
975 we are only interested in the effects of code before the call; for a
976 noreturn function, the return address may point to unrelated code with
977 a different stack configuration that we are not interested in. We
978 assume that the call itself is unwind info-neutral; if not, or if
979 there are delay instructions that adjust the stack, these must be
980 reflected at the point immediately before the call insn.
981 In signal frames, return address is after last completed instruction,
982 so we add 1 to return address to make the comparison <=. */
983 while (insn_ptr
< insn_end
984 && fs
->pc
< context
->ra
+ _Unwind_IsSignalFrame (context
))
986 unsigned char insn
= *insn_ptr
++;
987 _uleb128_t reg
, utmp
;
988 _sleb128_t offset
, stmp
;
990 if ((insn
& 0xc0) == DW_CFA_advance_loc
)
991 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
992 else if ((insn
& 0xc0) == DW_CFA_offset
)
995 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
996 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
997 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
998 if (UNWIND_COLUMN_IN_RANGE (reg
))
1000 fs
->regs
.how
[reg
] = REG_SAVED_OFFSET
;
1001 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1004 else if ((insn
& 0xc0) == DW_CFA_restore
)
1007 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1008 if (UNWIND_COLUMN_IN_RANGE (reg
))
1009 fs
->regs
.how
[reg
] = REG_UNSAVED
;
1013 case DW_CFA_set_loc
:
1017 insn_ptr
= read_encoded_value (context
, fs
->fde_encoding
,
1019 fs
->pc
= (void *) pc
;
1023 case DW_CFA_advance_loc1
:
1024 fs
->pc
+= read_1u (insn_ptr
) * fs
->code_align
;
1027 case DW_CFA_advance_loc2
:
1028 fs
->pc
+= read_2u (insn_ptr
) * fs
->code_align
;
1031 case DW_CFA_advance_loc4
:
1032 fs
->pc
+= read_4u (insn_ptr
) * fs
->code_align
;
1036 case DW_CFA_offset_extended
:
1037 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1038 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1039 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1040 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1041 if (UNWIND_COLUMN_IN_RANGE (reg
))
1043 fs
->regs
.how
[reg
] = REG_SAVED_OFFSET
;
1044 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1048 case DW_CFA_restore_extended
:
1049 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1050 /* FIXME, this is wrong; the CIE might have said that the
1051 register was saved somewhere. */
1052 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1053 if (UNWIND_COLUMN_IN_RANGE (reg
))
1054 fs
->regs
.how
[reg
] = REG_UNSAVED
;
1057 case DW_CFA_same_value
:
1058 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1059 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1060 if (UNWIND_COLUMN_IN_RANGE (reg
))
1061 fs
->regs
.how
[reg
] = REG_UNSAVED
;
1064 case DW_CFA_undefined
:
1065 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1066 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1067 if (UNWIND_COLUMN_IN_RANGE (reg
))
1068 fs
->regs
.how
[reg
] = REG_UNDEFINED
;
1074 case DW_CFA_register
:
1077 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1078 insn_ptr
= read_uleb128 (insn_ptr
, ®2
);
1079 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1080 if (UNWIND_COLUMN_IN_RANGE (reg
))
1082 fs
->regs
.how
[reg
] = REG_SAVED_REG
;
1083 fs
->regs
.reg
[reg
].loc
.reg
= (_Unwind_Word
)reg2
;
1088 case DW_CFA_remember_state
:
1090 struct frame_state_reg_info
*new_rs
;
1094 unused_rs
= unused_rs
->prev
;
1097 new_rs
= alloca (sizeof (struct frame_state_reg_info
));
1100 fs
->regs
.prev
= new_rs
;
1104 case DW_CFA_restore_state
:
1106 struct frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
1108 old_rs
->prev
= unused_rs
;
1113 case DW_CFA_def_cfa
:
1114 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1115 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1116 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1117 fs
->regs
.cfa_offset
= (_Unwind_Word
)utmp
;
1118 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1121 case DW_CFA_def_cfa_register
:
1122 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1123 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1124 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1127 case DW_CFA_def_cfa_offset
:
1128 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1129 fs
->regs
.cfa_offset
= utmp
;
1130 /* cfa_how deliberately not set. */
1133 case DW_CFA_def_cfa_expression
:
1134 fs
->regs
.cfa_exp
= insn_ptr
;
1135 fs
->regs
.cfa_how
= CFA_EXP
;
1136 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1140 case DW_CFA_expression
:
1141 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1142 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1143 if (UNWIND_COLUMN_IN_RANGE (reg
))
1145 fs
->regs
.how
[reg
] = REG_SAVED_EXP
;
1146 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1148 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1153 case DW_CFA_offset_extended_sf
:
1154 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1155 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1156 offset
= stmp
* fs
->data_align
;
1157 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1158 if (UNWIND_COLUMN_IN_RANGE (reg
))
1160 fs
->regs
.how
[reg
] = REG_SAVED_OFFSET
;
1161 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1165 case DW_CFA_def_cfa_sf
:
1166 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1167 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1168 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1169 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1170 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1171 fs
->regs
.cfa_offset
*= fs
->data_align
;
1174 case DW_CFA_def_cfa_offset_sf
:
1175 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1176 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1177 fs
->regs
.cfa_offset
*= fs
->data_align
;
1178 /* cfa_how deliberately not set. */
1181 case DW_CFA_val_offset
:
1182 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1183 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1184 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1185 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1186 if (UNWIND_COLUMN_IN_RANGE (reg
))
1188 fs
->regs
.how
[reg
] = REG_SAVED_VAL_OFFSET
;
1189 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1193 case DW_CFA_val_offset_sf
:
1194 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1195 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1196 offset
= stmp
* fs
->data_align
;
1197 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1198 if (UNWIND_COLUMN_IN_RANGE (reg
))
1200 fs
->regs
.how
[reg
] = REG_SAVED_VAL_OFFSET
;
1201 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1205 case DW_CFA_val_expression
:
1206 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1207 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1208 if (UNWIND_COLUMN_IN_RANGE (reg
))
1210 fs
->regs
.how
[reg
] = REG_SAVED_VAL_EXP
;
1211 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1213 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1217 case DW_CFA_GNU_window_save
:
1218 #if defined (__aarch64__) && !defined (__ILP32__)
1219 /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle
1220 return address signing status. */
1221 reg
= DWARF_REGNUM_AARCH64_RA_STATE
;
1222 gcc_assert (fs
->regs
.how
[reg
] == REG_UNSAVED
);
1223 fs
->regs
.reg
[reg
].loc
.offset
^= 1;
1225 /* ??? Hardcoded for SPARC register window configuration. */
1226 if (__LIBGCC_DWARF_FRAME_REGISTERS__
>= 32)
1227 for (reg
= 16; reg
< 32; ++reg
)
1229 fs
->regs
.how
[reg
] = REG_SAVED_OFFSET
;
1230 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * sizeof (void *);
1235 case DW_CFA_GNU_args_size
:
1236 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1237 context
->args_size
= (_Unwind_Word
)utmp
;
1240 case DW_CFA_GNU_negative_offset_extended
:
1241 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1242 older PowerPC code. */
1243 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1244 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1245 offset
= (_Unwind_Word
) utmp
* fs
->data_align
;
1246 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1247 if (UNWIND_COLUMN_IN_RANGE (reg
))
1249 fs
->regs
.how
[reg
] = REG_SAVED_OFFSET
;
1250 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
1260 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
1261 its caller and decode it into FS. This function also sets the
1262 args_size and lsda members of CONTEXT, as they are really information
1263 about the caller's frame. */
1265 static _Unwind_Reason_Code
1266 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1268 const struct dwarf_fde
*fde
;
1269 const struct dwarf_cie
*cie
;
1270 const unsigned char *aug
, *insn
, *end
;
1272 memset (&fs
->regs
.how
[0], 0,
1273 sizeof (*fs
) - offsetof (_Unwind_FrameState
, regs
.how
[0]));
1274 context
->args_size
= 0;
1277 if (context
->ra
== 0)
1278 return _URC_END_OF_STACK
;
1280 fde
= _Unwind_Find_FDE (context
->ra
+ _Unwind_IsSignalFrame (context
) - 1,
1284 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1285 /* Couldn't find frame unwind info for this function. Try a
1286 target-specific fallback mechanism. This will necessarily
1287 not provide a personality routine or LSDA. */
1288 return MD_FALLBACK_FRAME_STATE_FOR (context
, fs
);
1290 return _URC_END_OF_STACK
;
1294 fs
->pc
= context
->bases
.func
;
1296 cie
= get_cie (fde
);
1297 insn
= extract_cie_info (cie
, context
, fs
);
1299 /* CIE contained unknown augmentation. */
1300 return _URC_FATAL_PHASE1_ERROR
;
1302 /* First decode all the insns in the CIE. */
1303 end
= (const unsigned char *) next_fde ((const struct dwarf_fde
*) cie
);
1304 execute_cfa_program (insn
, end
, context
, fs
);
1306 /* Locate augmentation for the fde. */
1307 aug
= (const unsigned char *) fde
+ sizeof (*fde
);
1308 aug
+= 2 * size_of_encoded_value (fs
->fde_encoding
);
1313 aug
= read_uleb128 (aug
, &i
);
1316 if (fs
->lsda_encoding
!= DW_EH_PE_omit
)
1320 aug
= read_encoded_value (context
, fs
->lsda_encoding
, aug
, &lsda
);
1321 context
->lsda
= (void *) lsda
;
1324 /* Then the insns in the FDE up to our target PC. */
1327 end
= (const unsigned char *) next_fde (fde
);
1328 execute_cfa_program (insn
, end
, context
, fs
);
1330 return _URC_NO_REASON
;
1333 typedef struct frame_state
1339 long reg_or_offset
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1340 unsigned short cfa_reg
;
1341 unsigned short retaddr_column
;
1342 char saved
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1345 struct frame_state
* __frame_state_for (void *, struct frame_state
*);
1347 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
1348 a given PC_TARGET. The caller should allocate a local variable of
1349 `struct frame_state' and pass its address to STATE_IN. */
1351 struct frame_state
*
1352 __frame_state_for (void *pc_target
, struct frame_state
*state_in
)
1354 struct _Unwind_Context context
;
1355 _Unwind_FrameState fs
;
1358 memset (&context
, 0, sizeof (struct _Unwind_Context
));
1359 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1360 context
.flags
= EXTENDED_CONTEXT_BIT
;
1361 context
.ra
= pc_target
+ 1;
1363 if (uw_frame_state_for (&context
, &fs
) != _URC_NO_REASON
)
1366 /* We have no way to pass a location expression for the CFA to our
1367 caller. It wouldn't understand it anyway. */
1368 if (fs
.regs
.cfa_how
== CFA_EXP
)
1371 for (reg
= 0; reg
< PRE_GCC3_DWARF_FRAME_REGISTERS
+ 1; reg
++)
1373 state_in
->saved
[reg
] = fs
.regs
.how
[reg
];
1374 switch (state_in
->saved
[reg
])
1377 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.reg
;
1379 case REG_SAVED_OFFSET
:
1380 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.offset
;
1383 state_in
->reg_or_offset
[reg
] = 0;
1388 state_in
->cfa_offset
= fs
.regs
.cfa_offset
;
1389 state_in
->cfa_reg
= fs
.regs
.cfa_reg
;
1390 state_in
->retaddr_column
= fs
.retaddr_column
;
1391 state_in
->args_size
= context
.args_size
;
1392 state_in
->eh_ptr
= fs
.eh_ptr
;
1397 typedef union { _Unwind_Ptr ptr
; _Unwind_Word word
; } _Unwind_SpTmp
;
1400 _Unwind_SetSpColumn (struct _Unwind_Context
*context
, void *cfa
,
1401 _Unwind_SpTmp
*tmp_sp
)
1403 int size
= dwarf_reg_size (__builtin_dwarf_sp_column ());
1405 if (size
== sizeof(_Unwind_Ptr
))
1406 tmp_sp
->ptr
= (_Unwind_Ptr
) cfa
;
1409 gcc_assert (size
== sizeof(_Unwind_Word
));
1410 tmp_sp
->word
= (_Unwind_Ptr
) cfa
;
1412 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), tmp_sp
);
1416 uw_update_context_1 (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1418 struct _Unwind_Context orig_context
= *context
;
1422 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
1423 /* Special handling here: Many machines do not use a frame pointer,
1424 and track the CFA only through offsets from the stack pointer from
1425 one frame to the next. In this case, the stack pointer is never
1426 stored, so it has no saved address in the context. What we do
1427 have is the CFA from the previous stack frame.
1429 In very special situations (such as unwind info for signal return),
1430 there may be location expressions that use the stack pointer as well.
1432 Do this conditionally for one frame. This allows the unwind info
1433 for one frame to save a copy of the stack pointer from the previous
1434 frame, and be able to use much easier CFA mechanisms to do it.
1435 Always zap the saved stack pointer value for the next frame; carrying
1436 the value over from one frame to another doesn't make sense. */
1438 _Unwind_SpTmp tmp_sp
;
1440 if (!_Unwind_GetGRPtr (&orig_context
, __builtin_dwarf_sp_column ()))
1441 _Unwind_SetSpColumn (&orig_context
, context
->cfa
, &tmp_sp
);
1442 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), NULL
);
1445 /* Compute this frame's CFA. */
1446 switch (fs
->regs
.cfa_how
)
1448 case CFA_REG_OFFSET
:
1449 cfa
= _Unwind_GetPtr (&orig_context
, fs
->regs
.cfa_reg
);
1450 cfa
+= fs
->regs
.cfa_offset
;
1455 const unsigned char *exp
= fs
->regs
.cfa_exp
;
1458 exp
= read_uleb128 (exp
, &len
);
1459 cfa
= (void *) (_Unwind_Ptr
)
1460 execute_stack_op (exp
, exp
+ len
, &orig_context
, 0);
1469 /* Compute the addresses of all registers saved in this frame. */
1470 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
+ 1; ++i
)
1471 switch (fs
->regs
.how
[i
])
1477 case REG_SAVED_OFFSET
:
1478 _Unwind_SetGRPtr (context
, i
,
1479 (void *) (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1483 if (_Unwind_GRByValue (&orig_context
, fs
->regs
.reg
[i
].loc
.reg
))
1484 _Unwind_SetGRValue (context
, i
,
1485 _Unwind_GetGR (&orig_context
,
1486 fs
->regs
.reg
[i
].loc
.reg
));
1488 _Unwind_SetGRPtr (context
, i
,
1489 _Unwind_GetGRPtr (&orig_context
,
1490 fs
->regs
.reg
[i
].loc
.reg
));
1495 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1499 exp
= read_uleb128 (exp
, &len
);
1500 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1502 _Unwind_SetGRPtr (context
, i
, (void *) val
);
1506 case REG_SAVED_VAL_OFFSET
:
1507 _Unwind_SetGRValue (context
, i
,
1508 (_Unwind_Internal_Ptr
)
1509 (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1512 case REG_SAVED_VAL_EXP
:
1514 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1518 exp
= read_uleb128 (exp
, &len
);
1519 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1521 _Unwind_SetGRValue (context
, i
, val
);
1526 _Unwind_SetSignalFrame (context
, fs
->signal_frame
);
1528 #ifdef MD_FROB_UPDATE_CONTEXT
1529 MD_FROB_UPDATE_CONTEXT (context
, fs
);
1533 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1534 of its caller. Update CONTEXT to refer to the caller as well. Note
1535 that the args_size and lsda members are not updated here, but later in
1536 uw_frame_state_for. */
1539 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1541 uw_update_context_1 (context
, fs
);
1543 /* In general this unwinder doesn't make any distinction between
1544 undefined and same_value rule. Call-saved registers are assumed
1545 to have same_value rule by default and explicit undefined
1546 rule is handled like same_value. The only exception is
1547 DW_CFA_undefined on retaddr_column which is supposed to
1548 mark outermost frame in DWARF 3. */
1549 if (fs
->regs
.how
[DWARF_REG_TO_UNWIND_COLUMN (fs
->retaddr_column
)]
1551 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1556 /* Compute the return address now, since the return address column
1557 can change from frame to frame. */
1559 #ifdef MD_DEMANGLE_RETURN_ADDR
1560 _Unwind_Word ra
= _Unwind_GetGR (context
, fs
->retaddr_column
);
1561 ret_addr
= MD_DEMANGLE_RETURN_ADDR (context
, fs
, ra
);
1563 ret_addr
= _Unwind_GetPtr (context
, fs
->retaddr_column
);
1565 context
->ra
= __builtin_extract_return_addr (ret_addr
);
1570 uw_advance_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1572 uw_update_context (context
, fs
);
1575 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1576 level will be the return address and the CFA. */
1578 #define uw_init_context(CONTEXT) \
1581 /* Do any necessary initialization to access arbitrary stack frames. \
1582 On the SPARC, this means flushing the register windows. */ \
1583 __builtin_unwind_init (); \
1584 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1585 __builtin_return_address (0)); \
1589 #ifndef __LIBGCC_DWARF_REG_SIZES_CONSTANT__
1591 init_dwarf_reg_size_table (void)
1593 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table
);
1597 static void __attribute__((noinline
))
1598 uw_init_context_1 (struct _Unwind_Context
*context
,
1599 void *outer_cfa
, void *outer_ra
)
1601 void *ra
= __builtin_extract_return_addr (__builtin_return_address (0));
1602 _Unwind_FrameState fs
;
1603 _Unwind_SpTmp sp_slot
;
1604 _Unwind_Reason_Code code
;
1606 memset (context
, 0, sizeof (struct _Unwind_Context
));
1608 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1609 context
->flags
= EXTENDED_CONTEXT_BIT
;
1611 code
= uw_frame_state_for (context
, &fs
);
1612 gcc_assert (code
== _URC_NO_REASON
);
1614 #ifndef __LIBGCC_DWARF_REG_SIZES_CONSTANT__
1617 static __gthread_once_t once_regsizes
= __GTHREAD_ONCE_INIT
;
1618 if (__gthread_once (&once_regsizes
, init_dwarf_reg_size_table
) != 0
1619 && dwarf_reg_size_table
[0] == 0)
1620 init_dwarf_reg_size_table ();
1623 if (dwarf_reg_size_table
[0] == 0)
1624 init_dwarf_reg_size_table ();
1628 /* Force the frame state to use the known cfa value. */
1629 _Unwind_SetSpColumn (context
, outer_cfa
, &sp_slot
);
1630 fs
.regs
.cfa_how
= CFA_REG_OFFSET
;
1631 fs
.regs
.cfa_reg
= __builtin_dwarf_sp_column ();
1632 fs
.regs
.cfa_offset
= 0;
1634 uw_update_context_1 (context
, &fs
);
1636 /* If the return address column was saved in a register in the
1637 initialization context, then we can't see it in the given
1638 call frame data. So have the initialization context tell us. */
1639 context
->ra
= __builtin_extract_return_addr (outer_ra
);
1642 static void _Unwind_DebugHook (void *, void *)
1643 __attribute__ ((__noinline__
, __used__
, __noclone__
));
1645 /* This function is called during unwinding. It is intended as a hook
1646 for a debugger to intercept exceptions. CFA is the CFA of the
1647 target frame. HANDLER is the PC to which control will be
1650 _Unwind_DebugHook (void *cfa
__attribute__ ((__unused__
)),
1651 void *handler
__attribute__ ((__unused__
)))
1653 /* We only want to use stap probes starting with v3. Earlier
1654 versions added too much startup cost. */
1655 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
1656 STAP_PROBE2 (libgcc
, unwind
, cfa
, handler
);
1662 /* Install TARGET into CURRENT so that we can return to it. This is a
1663 macro because __builtin_eh_return must be invoked in the context of
1664 our caller. FRAMES is a number of frames to be unwind.
1665 _Unwind_Frames_Extra is a macro to do additional work during unwinding
1666 if needed, for example shadow stack pointer adjustment for Intel CET
1669 #define uw_install_context(CURRENT, TARGET, FRAMES) \
1672 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1673 void *handler = __builtin_frob_return_addr ((TARGET)->ra); \
1674 _Unwind_DebugHook ((TARGET)->cfa, handler); \
1675 _Unwind_Frames_Extra (FRAMES); \
1676 __builtin_eh_return (offset, handler); \
1681 uw_install_context_1 (struct _Unwind_Context
*current
,
1682 struct _Unwind_Context
*target
)
1685 _Unwind_SpTmp sp_slot
;
1687 /* If the target frame does not have a saved stack pointer,
1688 then set up the target's CFA. */
1689 if (!_Unwind_GetGRPtr (target
, __builtin_dwarf_sp_column ()))
1690 _Unwind_SetSpColumn (target
, target
->cfa
, &sp_slot
);
1692 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
; ++i
)
1694 void *c
= (void *) (_Unwind_Internal_Ptr
) current
->reg
[i
];
1695 void *t
= (void *) (_Unwind_Internal_Ptr
)target
->reg
[i
];
1697 gcc_assert (current
->by_value
[i
] == 0);
1698 if (target
->by_value
[i
] && c
)
1702 if (dwarf_reg_size (i
) == sizeof (_Unwind_Word
))
1704 w
= (_Unwind_Internal_Ptr
) t
;
1705 memcpy (c
, &w
, sizeof (_Unwind_Word
));
1709 gcc_assert (dwarf_reg_size (i
) == sizeof (_Unwind_Ptr
));
1710 p
= (_Unwind_Internal_Ptr
) t
;
1711 memcpy (c
, &p
, sizeof (_Unwind_Ptr
));
1714 else if (t
&& c
&& t
!= c
)
1715 memcpy (c
, t
, dwarf_reg_size (i
));
1718 /* If the current frame doesn't have a saved stack pointer, then we
1719 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1720 pointer value reloaded. */
1721 if (!_Unwind_GetGRPtr (current
, __builtin_dwarf_sp_column ()))
1725 target_cfa
= _Unwind_GetPtr (target
, __builtin_dwarf_sp_column ());
1727 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1728 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1729 return target_cfa
- current
->cfa
+ target
->args_size
;
1731 return current
->cfa
- target_cfa
- target
->args_size
;
1736 static inline _Unwind_Ptr
1737 uw_identify_context (struct _Unwind_Context
*context
)
1739 /* The CFA is not sufficient to disambiguate the context of a function
1740 interrupted by a signal before establishing its frame and the context
1741 of the signal itself. */
1742 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1743 return _Unwind_GetCFA (context
) - _Unwind_IsSignalFrame (context
);
1745 return _Unwind_GetCFA (context
) + _Unwind_IsSignalFrame (context
);
1749 #include "unwind.inc"
1751 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1752 alias (_Unwind_Backtrace
);
1753 alias (_Unwind_DeleteException
);
1754 alias (_Unwind_FindEnclosingFunction
);
1755 alias (_Unwind_ForcedUnwind
);
1756 alias (_Unwind_GetDataRelBase
);
1757 alias (_Unwind_GetTextRelBase
);
1758 alias (_Unwind_GetCFA
);
1759 alias (_Unwind_GetGR
);
1760 alias (_Unwind_GetIP
);
1761 alias (_Unwind_GetLanguageSpecificData
);
1762 alias (_Unwind_GetRegionStart
);
1763 alias (_Unwind_RaiseException
);
1764 alias (_Unwind_Resume
);
1765 alias (_Unwind_Resume_or_Rethrow
);
1766 alias (_Unwind_SetGR
);
1767 alias (_Unwind_SetIP
);
1770 #endif /* !USING_SJLJ_EXCEPTIONS */