1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997-2018 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 key. */
140 #define RA_A_SIGNED_BIT ((~(_Unwind_Word) 0 >> 3) + 1)
142 /* 0 for now, can be increased when further fields are added to
143 struct _Unwind_Context. */
144 _Unwind_Word version
;
145 _Unwind_Word args_size
;
146 char by_value
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
149 /* Byte size of every register managed by these routines. */
150 static unsigned char dwarf_reg_size_table
[__LIBGCC_DWARF_FRAME_REGISTERS__
+1];
153 /* Read unaligned data from the instruction buffer. */
158 unsigned u2
__attribute__ ((mode (HI
)));
159 unsigned u4
__attribute__ ((mode (SI
)));
160 unsigned u8
__attribute__ ((mode (DI
)));
161 signed s2
__attribute__ ((mode (HI
)));
162 signed s4
__attribute__ ((mode (SI
)));
163 signed s8
__attribute__ ((mode (DI
)));
164 } __attribute__ ((packed
));
166 static void uw_update_context (struct _Unwind_Context
*, _Unwind_FrameState
*);
167 static _Unwind_Reason_Code
uw_frame_state_for (struct _Unwind_Context
*,
168 _Unwind_FrameState
*);
171 read_pointer (const void *p
) { const union unaligned
*up
= p
; return up
->p
; }
174 read_1u (const void *p
) { return *(const unsigned char *) p
; }
177 read_1s (const void *p
) { return *(const signed char *) p
; }
180 read_2u (const void *p
) { const union unaligned
*up
= p
; return up
->u2
; }
183 read_2s (const void *p
) { const union unaligned
*up
= p
; return up
->s2
; }
185 static inline unsigned int
186 read_4u (const void *p
) { const union unaligned
*up
= p
; return up
->u4
; }
189 read_4s (const void *p
) { const union unaligned
*up
= p
; return up
->s4
; }
191 static inline unsigned long
192 read_8u (const void *p
) { const union unaligned
*up
= p
; return up
->u8
; }
194 static inline unsigned long
195 read_8s (const void *p
) { const union unaligned
*up
= p
; return up
->s8
; }
197 static inline _Unwind_Word
198 _Unwind_IsSignalFrame (struct _Unwind_Context
*context
)
200 return (context
->flags
& SIGNAL_FRAME_BIT
) ? 1 : 0;
204 _Unwind_SetSignalFrame (struct _Unwind_Context
*context
, int val
)
207 context
->flags
|= SIGNAL_FRAME_BIT
;
209 context
->flags
&= ~SIGNAL_FRAME_BIT
;
212 static inline _Unwind_Word
213 _Unwind_IsExtendedContext (struct _Unwind_Context
*context
)
215 return (ASSUME_EXTENDED_UNWIND_CONTEXT
216 || (context
->flags
& EXTENDED_CONTEXT_BIT
));
219 /* Get the value of register INDEX as saved in CONTEXT. */
222 _Unwind_GetGR (struct _Unwind_Context
*context
, int index
)
225 _Unwind_Context_Reg_Val val
;
227 #ifdef DWARF_ZERO_REG
228 if (index
== DWARF_ZERO_REG
)
232 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
233 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
234 size
= dwarf_reg_size_table
[index
];
235 val
= context
->reg
[index
];
237 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
238 return _Unwind_Get_Unwind_Word (val
);
240 /* This will segfault if the register hasn't been saved. */
241 if (size
== sizeof(_Unwind_Ptr
))
242 return * (_Unwind_Ptr
*) (_Unwind_Internal_Ptr
) val
;
245 gcc_assert (size
== sizeof(_Unwind_Word
));
246 return * (_Unwind_Word
*) (_Unwind_Internal_Ptr
) val
;
251 _Unwind_GetPtr (struct _Unwind_Context
*context
, int index
)
253 return (void *)(_Unwind_Ptr
) _Unwind_GetGR (context
, index
);
256 /* Get the value of the CFA as saved in CONTEXT. */
259 _Unwind_GetCFA (struct _Unwind_Context
*context
)
261 return (_Unwind_Ptr
) context
->cfa
;
264 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
267 _Unwind_SetGR (struct _Unwind_Context
*context
, int index
, _Unwind_Word val
)
272 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
273 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
274 size
= dwarf_reg_size_table
[index
];
276 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
278 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
282 ptr
= (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
284 if (size
== sizeof(_Unwind_Ptr
))
285 * (_Unwind_Ptr
*) ptr
= val
;
288 gcc_assert (size
== sizeof(_Unwind_Word
));
289 * (_Unwind_Word
*) ptr
= val
;
293 /* Get the pointer to a register INDEX as saved in CONTEXT. */
296 _Unwind_GetGRPtr (struct _Unwind_Context
*context
, int index
)
298 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
299 if (_Unwind_IsExtendedContext (context
) && context
->by_value
[index
])
300 return &context
->reg
[index
];
301 return (void *) (_Unwind_Internal_Ptr
) context
->reg
[index
];
304 /* Set the pointer to a register INDEX as saved in CONTEXT. */
307 _Unwind_SetGRPtr (struct _Unwind_Context
*context
, int index
, void *p
)
309 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
310 if (_Unwind_IsExtendedContext (context
))
311 context
->by_value
[index
] = 0;
312 context
->reg
[index
] = (_Unwind_Context_Reg_Val
) (_Unwind_Internal_Ptr
) p
;
315 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
318 _Unwind_SetGRValue (struct _Unwind_Context
*context
, int index
,
321 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
322 gcc_assert (index
< (int) sizeof(dwarf_reg_size_table
));
323 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
324 gcc_assert (dwarf_reg_size_table
[index
] <= sizeof (_Unwind_Context_Reg_Val
));
326 context
->by_value
[index
] = 1;
327 context
->reg
[index
] = _Unwind_Get_Unwind_Context_Reg_Val (val
);
330 /* Return nonzero if register INDEX is stored by value rather than
334 _Unwind_GRByValue (struct _Unwind_Context
*context
, int index
)
336 index
= DWARF_REG_TO_UNWIND_COLUMN (index
);
337 return context
->by_value
[index
];
340 /* Retrieve the return address for CONTEXT. */
343 _Unwind_GetIP (struct _Unwind_Context
*context
)
345 return (_Unwind_Ptr
) context
->ra
;
348 /* Retrieve the return address and flag whether that IP is before
349 or after first not yet fully executed instruction. */
352 _Unwind_GetIPInfo (struct _Unwind_Context
*context
, int *ip_before_insn
)
354 *ip_before_insn
= _Unwind_IsSignalFrame (context
);
355 return (_Unwind_Ptr
) context
->ra
;
358 /* Overwrite the return address for CONTEXT with VAL. */
361 _Unwind_SetIP (struct _Unwind_Context
*context
, _Unwind_Ptr val
)
363 context
->ra
= (void *) val
;
367 _Unwind_GetLanguageSpecificData (struct _Unwind_Context
*context
)
369 return context
->lsda
;
373 _Unwind_GetRegionStart (struct _Unwind_Context
*context
)
375 return (_Unwind_Ptr
) context
->bases
.func
;
379 _Unwind_FindEnclosingFunction (void *pc
)
381 struct dwarf_eh_bases bases
;
382 const struct dwarf_fde
*fde
= _Unwind_Find_FDE (pc
-1, &bases
);
391 _Unwind_GetDataRelBase (struct _Unwind_Context
*context
)
393 return (_Unwind_Ptr
) context
->bases
.dbase
;
397 _Unwind_GetTextRelBase (struct _Unwind_Context
*context
)
399 return (_Unwind_Ptr
) context
->bases
.tbase
;
403 #include "md-unwind-support.h"
405 /* Extract any interesting information from the CIE for the translation
406 unit F belongs to. Return a pointer to the byte after the augmentation,
407 or NULL if we encountered an undecipherable augmentation. */
409 static const unsigned char *
410 extract_cie_info (const struct dwarf_cie
*cie
, struct _Unwind_Context
*context
,
411 _Unwind_FrameState
*fs
)
413 const unsigned char *aug
= cie
->augmentation
;
414 const unsigned char *p
= aug
+ strlen ((const char *)aug
) + 1;
415 const unsigned char *ret
= NULL
;
419 /* g++ v2 "eh" has pointer immediately following augmentation string,
420 so it must be handled first. */
421 if (aug
[0] == 'e' && aug
[1] == 'h')
423 fs
->eh_ptr
= read_pointer (p
);
424 p
+= sizeof (void *);
428 /* After the augmentation resp. pointer for "eh" augmentation
429 follows for CIE version >= 4 address size byte and
430 segment size byte. */
431 if (__builtin_expect (cie
->version
>= 4, 0))
433 if (p
[0] != sizeof (void *) || p
[1] != 0)
437 /* Immediately following this are the code and
438 data alignment and return address column. */
439 p
= read_uleb128 (p
, &utmp
);
440 fs
->code_align
= (_Unwind_Word
)utmp
;
441 p
= read_sleb128 (p
, &stmp
);
442 fs
->data_align
= (_Unwind_Sword
)stmp
;
443 if (cie
->version
== 1)
444 fs
->retaddr_column
= *p
++;
447 p
= read_uleb128 (p
, &utmp
);
448 fs
->retaddr_column
= (_Unwind_Word
)utmp
;
450 fs
->lsda_encoding
= DW_EH_PE_omit
;
452 /* If the augmentation starts with 'z', then a uleb128 immediately
453 follows containing the length of the augmentation field following
457 p
= read_uleb128 (p
, &utmp
);
464 /* Iterate over recognized augmentation subsequences. */
467 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
470 fs
->lsda_encoding
= *p
++;
474 /* "R" indicates a byte indicating how FDE addresses are encoded. */
475 else if (aug
[0] == 'R')
477 fs
->fde_encoding
= *p
++;
481 /* "P" indicates a personality routine in the CIE augmentation. */
482 else if (aug
[0] == 'P')
484 _Unwind_Ptr personality
;
486 p
= read_encoded_value (context
, *p
, p
+ 1, &personality
);
487 fs
->personality
= (_Unwind_Personality_Fn
) personality
;
491 /* "S" indicates a signal frame. */
492 else if (aug
[0] == 'S')
494 fs
->signal_frame
= 1;
498 /* Otherwise we have an unknown augmentation string.
499 Bail unless we saw a 'z' prefix. */
504 return ret
? ret
: p
;
508 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
509 onto the stack to start. */
512 execute_stack_op (const unsigned char *op_ptr
, const unsigned char *op_end
,
513 struct _Unwind_Context
*context
, _Unwind_Word initial
)
515 _Unwind_Word stack
[64]; /* ??? Assume this is enough. */
521 while (op_ptr
< op_end
)
523 enum dwarf_location_atom op
= *op_ptr
++;
525 _uleb128_t reg
, utmp
;
526 _sleb128_t offset
, stmp
;
562 result
= op
- DW_OP_lit0
;
566 result
= (_Unwind_Word
) (_Unwind_Ptr
) read_pointer (op_ptr
);
567 op_ptr
+= sizeof (void *);
570 case DW_OP_GNU_encoded_addr
:
573 op_ptr
= read_encoded_value (context
, *op_ptr
, op_ptr
+1, &presult
);
579 result
= read_1u (op_ptr
);
583 result
= read_1s (op_ptr
);
587 result
= read_2u (op_ptr
);
591 result
= read_2s (op_ptr
);
595 result
= read_4u (op_ptr
);
599 result
= read_4s (op_ptr
);
603 result
= read_8u (op_ptr
);
607 result
= read_8s (op_ptr
);
611 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
612 result
= (_Unwind_Word
)utmp
;
615 op_ptr
= read_sleb128 (op_ptr
, &stmp
);
616 result
= (_Unwind_Sword
)stmp
;
651 result
= _Unwind_GetGR (context
, op
- DW_OP_reg0
);
654 op_ptr
= read_uleb128 (op_ptr
, ®
);
655 result
= _Unwind_GetGR (context
, reg
);
690 op_ptr
= read_sleb128 (op_ptr
, &offset
);
691 result
= _Unwind_GetGR (context
, op
- DW_OP_breg0
) + offset
;
694 op_ptr
= read_uleb128 (op_ptr
, ®
);
695 op_ptr
= read_sleb128 (op_ptr
, &offset
);
696 result
= _Unwind_GetGR (context
, reg
) + (_Unwind_Word
)offset
;
700 gcc_assert (stack_elt
);
701 result
= stack
[stack_elt
- 1];
705 gcc_assert (stack_elt
);
711 gcc_assert (offset
< stack_elt
- 1);
712 result
= stack
[stack_elt
- 1 - offset
];
716 gcc_assert (stack_elt
>= 2);
717 result
= stack
[stack_elt
- 2];
723 gcc_assert (stack_elt
>= 2);
724 t
= stack
[stack_elt
- 1];
725 stack
[stack_elt
- 1] = stack
[stack_elt
- 2];
726 stack
[stack_elt
- 2] = t
;
732 _Unwind_Word t1
, t2
, t3
;
734 gcc_assert (stack_elt
>= 3);
735 t1
= stack
[stack_elt
- 1];
736 t2
= stack
[stack_elt
- 2];
737 t3
= stack
[stack_elt
- 3];
738 stack
[stack_elt
- 1] = t2
;
739 stack
[stack_elt
- 2] = t3
;
740 stack
[stack_elt
- 3] = t1
;
745 case DW_OP_deref_size
:
749 case DW_OP_plus_uconst
:
750 /* Unary operations. */
751 gcc_assert (stack_elt
);
754 result
= stack
[stack_elt
];
760 void *ptr
= (void *) (_Unwind_Ptr
) result
;
761 result
= (_Unwind_Ptr
) read_pointer (ptr
);
765 case DW_OP_deref_size
:
767 void *ptr
= (void *) (_Unwind_Ptr
) result
;
771 result
= read_1u (ptr
);
774 result
= read_2u (ptr
);
777 result
= read_4u (ptr
);
780 result
= read_8u (ptr
);
789 if ((_Unwind_Sword
) result
< 0)
798 case DW_OP_plus_uconst
:
799 op_ptr
= read_uleb128 (op_ptr
, &utmp
);
800 result
+= (_Unwind_Word
)utmp
;
826 /* Binary operations. */
827 _Unwind_Word first
, second
;
828 gcc_assert (stack_elt
>= 2);
831 second
= stack
[stack_elt
];
832 first
= stack
[stack_elt
+ 1];
837 result
= second
& first
;
840 result
= (_Unwind_Sword
) second
/ (_Unwind_Sword
) first
;
843 result
= second
- first
;
846 result
= second
% first
;
849 result
= second
* first
;
852 result
= second
| first
;
855 result
= second
+ first
;
858 result
= second
<< first
;
861 result
= second
>> first
;
864 result
= (_Unwind_Sword
) second
>> first
;
867 result
= second
^ first
;
870 result
= (_Unwind_Sword
) second
<= (_Unwind_Sword
) first
;
873 result
= (_Unwind_Sword
) second
>= (_Unwind_Sword
) first
;
876 result
= (_Unwind_Sword
) second
== (_Unwind_Sword
) first
;
879 result
= (_Unwind_Sword
) second
< (_Unwind_Sword
) first
;
882 result
= (_Unwind_Sword
) second
> (_Unwind_Sword
) first
;
885 result
= (_Unwind_Sword
) second
!= (_Unwind_Sword
) first
;
895 offset
= read_2s (op_ptr
);
901 gcc_assert (stack_elt
);
904 offset
= read_2s (op_ptr
);
906 if (stack
[stack_elt
] != 0)
917 /* Most things push a result value. */
918 gcc_assert ((size_t) stack_elt
< sizeof(stack
)/sizeof(*stack
));
919 stack
[stack_elt
++] = result
;
923 /* We were executing this program to get a value. It should be
925 gcc_assert (stack_elt
);
927 return stack
[stack_elt
];
931 /* Decode DWARF 2 call frame information. Takes pointers the
932 instruction sequence to decode, current register information and
933 CIE info, and the PC range to evaluate. */
936 execute_cfa_program (const unsigned char *insn_ptr
,
937 const unsigned char *insn_end
,
938 struct _Unwind_Context
*context
,
939 _Unwind_FrameState
*fs
)
941 struct frame_state_reg_info
*unused_rs
= NULL
;
943 /* Don't allow remember/restore between CIE and FDE programs. */
944 fs
->regs
.prev
= NULL
;
946 /* The comparison with the return address uses < rather than <= because
947 we are only interested in the effects of code before the call; for a
948 noreturn function, the return address may point to unrelated code with
949 a different stack configuration that we are not interested in. We
950 assume that the call itself is unwind info-neutral; if not, or if
951 there are delay instructions that adjust the stack, these must be
952 reflected at the point immediately before the call insn.
953 In signal frames, return address is after last completed instruction,
954 so we add 1 to return address to make the comparison <=. */
955 while (insn_ptr
< insn_end
956 && fs
->pc
< context
->ra
+ _Unwind_IsSignalFrame (context
))
958 unsigned char insn
= *insn_ptr
++;
959 _uleb128_t reg
, utmp
;
960 _sleb128_t offset
, stmp
;
962 if ((insn
& 0xc0) == DW_CFA_advance_loc
)
963 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
964 else if ((insn
& 0xc0) == DW_CFA_offset
)
967 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
968 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
969 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
970 if (UNWIND_COLUMN_IN_RANGE (reg
))
972 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
973 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
976 else if ((insn
& 0xc0) == DW_CFA_restore
)
979 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
980 if (UNWIND_COLUMN_IN_RANGE (reg
))
981 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
989 insn_ptr
= read_encoded_value (context
, fs
->fde_encoding
,
991 fs
->pc
= (void *) pc
;
995 case DW_CFA_advance_loc1
:
996 fs
->pc
+= read_1u (insn_ptr
) * fs
->code_align
;
999 case DW_CFA_advance_loc2
:
1000 fs
->pc
+= read_2u (insn_ptr
) * fs
->code_align
;
1003 case DW_CFA_advance_loc4
:
1004 fs
->pc
+= read_4u (insn_ptr
) * fs
->code_align
;
1008 case DW_CFA_offset_extended
:
1009 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1010 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1011 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1012 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1013 if (UNWIND_COLUMN_IN_RANGE (reg
))
1015 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1016 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1020 case DW_CFA_restore_extended
:
1021 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1022 /* FIXME, this is wrong; the CIE might have said that the
1023 register was saved somewhere. */
1024 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1025 if (UNWIND_COLUMN_IN_RANGE (reg
))
1026 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
1029 case DW_CFA_same_value
:
1030 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1031 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1032 if (UNWIND_COLUMN_IN_RANGE (reg
))
1033 fs
->regs
.reg
[reg
].how
= REG_UNSAVED
;
1036 case DW_CFA_undefined
:
1037 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1038 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1039 if (UNWIND_COLUMN_IN_RANGE (reg
))
1040 fs
->regs
.reg
[reg
].how
= REG_UNDEFINED
;
1046 case DW_CFA_register
:
1049 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1050 insn_ptr
= read_uleb128 (insn_ptr
, ®2
);
1051 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1052 if (UNWIND_COLUMN_IN_RANGE (reg
))
1054 fs
->regs
.reg
[reg
].how
= REG_SAVED_REG
;
1055 fs
->regs
.reg
[reg
].loc
.reg
= (_Unwind_Word
)reg2
;
1060 case DW_CFA_remember_state
:
1062 struct frame_state_reg_info
*new_rs
;
1066 unused_rs
= unused_rs
->prev
;
1069 new_rs
= alloca (sizeof (struct frame_state_reg_info
));
1072 fs
->regs
.prev
= new_rs
;
1076 case DW_CFA_restore_state
:
1078 struct frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
1080 old_rs
->prev
= unused_rs
;
1085 case DW_CFA_def_cfa
:
1086 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1087 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1088 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1089 fs
->regs
.cfa_offset
= (_Unwind_Word
)utmp
;
1090 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1093 case DW_CFA_def_cfa_register
:
1094 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1095 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1096 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1099 case DW_CFA_def_cfa_offset
:
1100 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1101 fs
->regs
.cfa_offset
= utmp
;
1102 /* cfa_how deliberately not set. */
1105 case DW_CFA_def_cfa_expression
:
1106 fs
->regs
.cfa_exp
= insn_ptr
;
1107 fs
->regs
.cfa_how
= CFA_EXP
;
1108 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1112 case DW_CFA_expression
:
1113 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1114 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1115 if (UNWIND_COLUMN_IN_RANGE (reg
))
1117 fs
->regs
.reg
[reg
].how
= REG_SAVED_EXP
;
1118 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1120 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1125 case DW_CFA_offset_extended_sf
:
1126 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1127 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1128 offset
= stmp
* fs
->data_align
;
1129 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1130 if (UNWIND_COLUMN_IN_RANGE (reg
))
1132 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1133 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1137 case DW_CFA_def_cfa_sf
:
1138 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1139 fs
->regs
.cfa_reg
= (_Unwind_Word
)utmp
;
1140 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1141 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1142 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
1143 fs
->regs
.cfa_offset
*= fs
->data_align
;
1146 case DW_CFA_def_cfa_offset_sf
:
1147 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1148 fs
->regs
.cfa_offset
= (_Unwind_Sword
)stmp
;
1149 fs
->regs
.cfa_offset
*= fs
->data_align
;
1150 /* cfa_how deliberately not set. */
1153 case DW_CFA_val_offset
:
1154 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1155 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1156 offset
= (_Unwind_Sword
) utmp
* fs
->data_align
;
1157 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1158 if (UNWIND_COLUMN_IN_RANGE (reg
))
1160 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_OFFSET
;
1161 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1165 case DW_CFA_val_offset_sf
:
1166 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1167 insn_ptr
= read_sleb128 (insn_ptr
, &stmp
);
1168 offset
= stmp
* fs
->data_align
;
1169 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1170 if (UNWIND_COLUMN_IN_RANGE (reg
))
1172 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_OFFSET
;
1173 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
1177 case DW_CFA_val_expression
:
1178 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1179 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1180 if (UNWIND_COLUMN_IN_RANGE (reg
))
1182 fs
->regs
.reg
[reg
].how
= REG_SAVED_VAL_EXP
;
1183 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
1185 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1189 case DW_CFA_GNU_window_save
:
1190 #if defined (__aarch64__) && !defined (__ILP32__)
1191 /* This CFA is multiplexed with Sparc. On AArch64 it's used to toggle
1192 return address signing status. */
1193 fs
->regs
.reg
[DWARF_REGNUM_AARCH64_RA_STATE
].loc
.offset
^= 1;
1195 /* ??? Hardcoded for SPARC register window configuration. */
1196 if (__LIBGCC_DWARF_FRAME_REGISTERS__
>= 32)
1197 for (reg
= 16; reg
< 32; ++reg
)
1199 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1200 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * sizeof (void *);
1205 case DW_CFA_GNU_args_size
:
1206 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1207 context
->args_size
= (_Unwind_Word
)utmp
;
1210 case DW_CFA_GNU_negative_offset_extended
:
1211 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1212 older PowerPC code. */
1213 insn_ptr
= read_uleb128 (insn_ptr
, ®
);
1214 insn_ptr
= read_uleb128 (insn_ptr
, &utmp
);
1215 offset
= (_Unwind_Word
) utmp
* fs
->data_align
;
1216 reg
= DWARF_REG_TO_UNWIND_COLUMN (reg
);
1217 if (UNWIND_COLUMN_IN_RANGE (reg
))
1219 fs
->regs
.reg
[reg
].how
= REG_SAVED_OFFSET
;
1220 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
1230 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
1231 its caller and decode it into FS. This function also sets the
1232 args_size and lsda members of CONTEXT, as they are really information
1233 about the caller's frame. */
1235 static _Unwind_Reason_Code
1236 uw_frame_state_for (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1238 const struct dwarf_fde
*fde
;
1239 const struct dwarf_cie
*cie
;
1240 const unsigned char *aug
, *insn
, *end
;
1242 memset (fs
, 0, sizeof (*fs
));
1243 context
->args_size
= 0;
1246 if (context
->ra
== 0)
1247 return _URC_END_OF_STACK
;
1249 fde
= _Unwind_Find_FDE (context
->ra
+ _Unwind_IsSignalFrame (context
) - 1,
1253 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1254 /* Couldn't find frame unwind info for this function. Try a
1255 target-specific fallback mechanism. This will necessarily
1256 not provide a personality routine or LSDA. */
1257 return MD_FALLBACK_FRAME_STATE_FOR (context
, fs
);
1259 return _URC_END_OF_STACK
;
1263 fs
->pc
= context
->bases
.func
;
1265 cie
= get_cie (fde
);
1266 insn
= extract_cie_info (cie
, context
, fs
);
1268 /* CIE contained unknown augmentation. */
1269 return _URC_FATAL_PHASE1_ERROR
;
1271 /* First decode all the insns in the CIE. */
1272 end
= (const unsigned char *) next_fde ((const struct dwarf_fde
*) cie
);
1273 execute_cfa_program (insn
, end
, context
, fs
);
1275 /* Locate augmentation for the fde. */
1276 aug
= (const unsigned char *) fde
+ sizeof (*fde
);
1277 aug
+= 2 * size_of_encoded_value (fs
->fde_encoding
);
1282 aug
= read_uleb128 (aug
, &i
);
1285 if (fs
->lsda_encoding
!= DW_EH_PE_omit
)
1289 aug
= read_encoded_value (context
, fs
->lsda_encoding
, aug
, &lsda
);
1290 context
->lsda
= (void *) lsda
;
1293 /* Then the insns in the FDE up to our target PC. */
1296 end
= (const unsigned char *) next_fde (fde
);
1297 execute_cfa_program (insn
, end
, context
, fs
);
1299 return _URC_NO_REASON
;
1302 typedef struct frame_state
1308 long reg_or_offset
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1309 unsigned short cfa_reg
;
1310 unsigned short retaddr_column
;
1311 char saved
[PRE_GCC3_DWARF_FRAME_REGISTERS
+1];
1314 struct frame_state
* __frame_state_for (void *, struct frame_state
*);
1316 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
1317 a given PC_TARGET. The caller should allocate a local variable of
1318 `struct frame_state' and pass its address to STATE_IN. */
1320 struct frame_state
*
1321 __frame_state_for (void *pc_target
, struct frame_state
*state_in
)
1323 struct _Unwind_Context context
;
1324 _Unwind_FrameState fs
;
1327 memset (&context
, 0, sizeof (struct _Unwind_Context
));
1328 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1329 context
.flags
= EXTENDED_CONTEXT_BIT
;
1330 context
.ra
= pc_target
+ 1;
1332 if (uw_frame_state_for (&context
, &fs
) != _URC_NO_REASON
)
1335 /* We have no way to pass a location expression for the CFA to our
1336 caller. It wouldn't understand it anyway. */
1337 if (fs
.regs
.cfa_how
== CFA_EXP
)
1340 for (reg
= 0; reg
< PRE_GCC3_DWARF_FRAME_REGISTERS
+ 1; reg
++)
1342 state_in
->saved
[reg
] = fs
.regs
.reg
[reg
].how
;
1343 switch (state_in
->saved
[reg
])
1346 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.reg
;
1348 case REG_SAVED_OFFSET
:
1349 state_in
->reg_or_offset
[reg
] = fs
.regs
.reg
[reg
].loc
.offset
;
1352 state_in
->reg_or_offset
[reg
] = 0;
1357 state_in
->cfa_offset
= fs
.regs
.cfa_offset
;
1358 state_in
->cfa_reg
= fs
.regs
.cfa_reg
;
1359 state_in
->retaddr_column
= fs
.retaddr_column
;
1360 state_in
->args_size
= context
.args_size
;
1361 state_in
->eh_ptr
= fs
.eh_ptr
;
1366 typedef union { _Unwind_Ptr ptr
; _Unwind_Word word
; } _Unwind_SpTmp
;
1369 _Unwind_SetSpColumn (struct _Unwind_Context
*context
, void *cfa
,
1370 _Unwind_SpTmp
*tmp_sp
)
1372 int size
= dwarf_reg_size_table
[__builtin_dwarf_sp_column ()];
1374 if (size
== sizeof(_Unwind_Ptr
))
1375 tmp_sp
->ptr
= (_Unwind_Ptr
) cfa
;
1378 gcc_assert (size
== sizeof(_Unwind_Word
));
1379 tmp_sp
->word
= (_Unwind_Ptr
) cfa
;
1381 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), tmp_sp
);
1385 uw_update_context_1 (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1387 struct _Unwind_Context orig_context
= *context
;
1391 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
1392 /* Special handling here: Many machines do not use a frame pointer,
1393 and track the CFA only through offsets from the stack pointer from
1394 one frame to the next. In this case, the stack pointer is never
1395 stored, so it has no saved address in the context. What we do
1396 have is the CFA from the previous stack frame.
1398 In very special situations (such as unwind info for signal return),
1399 there may be location expressions that use the stack pointer as well.
1401 Do this conditionally for one frame. This allows the unwind info
1402 for one frame to save a copy of the stack pointer from the previous
1403 frame, and be able to use much easier CFA mechanisms to do it.
1404 Always zap the saved stack pointer value for the next frame; carrying
1405 the value over from one frame to another doesn't make sense. */
1407 _Unwind_SpTmp tmp_sp
;
1409 if (!_Unwind_GetGRPtr (&orig_context
, __builtin_dwarf_sp_column ()))
1410 _Unwind_SetSpColumn (&orig_context
, context
->cfa
, &tmp_sp
);
1411 _Unwind_SetGRPtr (context
, __builtin_dwarf_sp_column (), NULL
);
1414 /* Compute this frame's CFA. */
1415 switch (fs
->regs
.cfa_how
)
1417 case CFA_REG_OFFSET
:
1418 cfa
= _Unwind_GetPtr (&orig_context
, fs
->regs
.cfa_reg
);
1419 cfa
+= fs
->regs
.cfa_offset
;
1424 const unsigned char *exp
= fs
->regs
.cfa_exp
;
1427 exp
= read_uleb128 (exp
, &len
);
1428 cfa
= (void *) (_Unwind_Ptr
)
1429 execute_stack_op (exp
, exp
+ len
, &orig_context
, 0);
1438 /* Compute the addresses of all registers saved in this frame. */
1439 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
+ 1; ++i
)
1440 switch (fs
->regs
.reg
[i
].how
)
1446 case REG_SAVED_OFFSET
:
1447 _Unwind_SetGRPtr (context
, i
,
1448 (void *) (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1452 if (_Unwind_GRByValue (&orig_context
, fs
->regs
.reg
[i
].loc
.reg
))
1453 _Unwind_SetGRValue (context
, i
,
1454 _Unwind_GetGR (&orig_context
,
1455 fs
->regs
.reg
[i
].loc
.reg
));
1457 _Unwind_SetGRPtr (context
, i
,
1458 _Unwind_GetGRPtr (&orig_context
,
1459 fs
->regs
.reg
[i
].loc
.reg
));
1464 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1468 exp
= read_uleb128 (exp
, &len
);
1469 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1471 _Unwind_SetGRPtr (context
, i
, (void *) val
);
1475 case REG_SAVED_VAL_OFFSET
:
1476 _Unwind_SetGRValue (context
, i
,
1477 (_Unwind_Internal_Ptr
)
1478 (cfa
+ fs
->regs
.reg
[i
].loc
.offset
));
1481 case REG_SAVED_VAL_EXP
:
1483 const unsigned char *exp
= fs
->regs
.reg
[i
].loc
.exp
;
1487 exp
= read_uleb128 (exp
, &len
);
1488 val
= execute_stack_op (exp
, exp
+ len
, &orig_context
,
1490 _Unwind_SetGRValue (context
, i
, val
);
1495 _Unwind_SetSignalFrame (context
, fs
->signal_frame
);
1497 #ifdef MD_FROB_UPDATE_CONTEXT
1498 MD_FROB_UPDATE_CONTEXT (context
, fs
);
1502 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1503 of its caller. Update CONTEXT to refer to the caller as well. Note
1504 that the args_size and lsda members are not updated here, but later in
1505 uw_frame_state_for. */
1508 uw_update_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1510 uw_update_context_1 (context
, fs
);
1512 /* In general this unwinder doesn't make any distinction between
1513 undefined and same_value rule. Call-saved registers are assumed
1514 to have same_value rule by default and explicit undefined
1515 rule is handled like same_value. The only exception is
1516 DW_CFA_undefined on retaddr_column which is supposed to
1517 mark outermost frame in DWARF 3. */
1518 if (fs
->regs
.reg
[DWARF_REG_TO_UNWIND_COLUMN (fs
->retaddr_column
)].how
1520 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1525 /* Compute the return address now, since the return address column
1526 can change from frame to frame. */
1527 context
->ra
= __builtin_extract_return_addr
1528 (_Unwind_GetPtr (context
, fs
->retaddr_column
));
1529 #ifdef MD_POST_EXTRACT_FRAME_ADDR
1530 context
->ra
= MD_POST_EXTRACT_FRAME_ADDR (context
, fs
, context
->ra
);
1536 uw_advance_context (struct _Unwind_Context
*context
, _Unwind_FrameState
*fs
)
1538 uw_update_context (context
, fs
);
1541 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1542 level will be the return address and the CFA. */
1544 #define uw_init_context(CONTEXT) \
1547 /* Do any necessary initialization to access arbitrary stack frames. \
1548 On the SPARC, this means flushing the register windows. */ \
1549 __builtin_unwind_init (); \
1550 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1551 __builtin_return_address (0)); \
1556 init_dwarf_reg_size_table (void)
1558 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table
);
1561 static void __attribute__((noinline
))
1562 uw_init_context_1 (struct _Unwind_Context
*context
,
1563 void *outer_cfa
, void *outer_ra
)
1565 void *ra
= __builtin_extract_return_addr (__builtin_return_address (0));
1566 #ifdef MD_POST_EXTRACT_ROOT_ADDR
1567 ra
= MD_POST_EXTRACT_ROOT_ADDR (ra
);
1569 _Unwind_FrameState fs
;
1570 _Unwind_SpTmp sp_slot
;
1571 _Unwind_Reason_Code code
;
1573 memset (context
, 0, sizeof (struct _Unwind_Context
));
1575 if (!ASSUME_EXTENDED_UNWIND_CONTEXT
)
1576 context
->flags
= EXTENDED_CONTEXT_BIT
;
1578 code
= uw_frame_state_for (context
, &fs
);
1579 gcc_assert (code
== _URC_NO_REASON
);
1583 static __gthread_once_t once_regsizes
= __GTHREAD_ONCE_INIT
;
1584 if (__gthread_once (&once_regsizes
, init_dwarf_reg_size_table
) != 0
1585 && dwarf_reg_size_table
[0] == 0)
1586 init_dwarf_reg_size_table ();
1589 if (dwarf_reg_size_table
[0] == 0)
1590 init_dwarf_reg_size_table ();
1593 /* Force the frame state to use the known cfa value. */
1594 _Unwind_SetSpColumn (context
, outer_cfa
, &sp_slot
);
1595 fs
.regs
.cfa_how
= CFA_REG_OFFSET
;
1596 fs
.regs
.cfa_reg
= __builtin_dwarf_sp_column ();
1597 fs
.regs
.cfa_offset
= 0;
1599 uw_update_context_1 (context
, &fs
);
1601 /* If the return address column was saved in a register in the
1602 initialization context, then we can't see it in the given
1603 call frame data. So have the initialization context tell us. */
1604 context
->ra
= __builtin_extract_return_addr (outer_ra
);
1605 #ifdef MD_POST_EXTRACT_ROOT_ADDR
1606 context
->ra
= MD_POST_EXTRACT_ROOT_ADDR (context
->ra
);
1610 static void _Unwind_DebugHook (void *, void *)
1611 __attribute__ ((__noinline__
, __used__
, __noclone__
));
1613 /* This function is called during unwinding. It is intended as a hook
1614 for a debugger to intercept exceptions. CFA is the CFA of the
1615 target frame. HANDLER is the PC to which control will be
1618 _Unwind_DebugHook (void *cfa
__attribute__ ((__unused__
)),
1619 void *handler
__attribute__ ((__unused__
)))
1621 /* We only want to use stap probes starting with v3. Earlier
1622 versions added too much startup cost. */
1623 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
1624 STAP_PROBE2 (libgcc
, unwind
, cfa
, handler
);
1630 /* Frob exception handler's address kept in TARGET before installing into
1633 static inline void *
1634 uw_frob_return_addr (struct _Unwind_Context
*current
1635 __attribute__ ((__unused__
)),
1636 struct _Unwind_Context
*target
)
1638 void *ret_addr
= __builtin_frob_return_addr (target
->ra
);
1639 #ifdef MD_POST_FROB_EH_HANDLER_ADDR
1640 ret_addr
= MD_POST_FROB_EH_HANDLER_ADDR (current
, target
, ret_addr
);
1645 /* Install TARGET into CURRENT so that we can return to it. This is a
1646 macro because __builtin_eh_return must be invoked in the context of
1647 our caller. FRAMES is a number of frames to be unwind.
1648 _Unwind_Frames_Extra is a macro to do additional work during unwinding
1649 if needed, for example shadow stack pointer adjustment for Intel CET
1652 #define uw_install_context(CURRENT, TARGET, FRAMES) \
1655 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1656 void *handler = uw_frob_return_addr ((CURRENT), (TARGET)); \
1657 _Unwind_DebugHook ((TARGET)->cfa, handler); \
1658 _Unwind_Frames_Extra (FRAMES); \
1659 __builtin_eh_return (offset, handler); \
1664 uw_install_context_1 (struct _Unwind_Context
*current
,
1665 struct _Unwind_Context
*target
)
1668 _Unwind_SpTmp sp_slot
;
1670 /* If the target frame does not have a saved stack pointer,
1671 then set up the target's CFA. */
1672 if (!_Unwind_GetGRPtr (target
, __builtin_dwarf_sp_column ()))
1673 _Unwind_SetSpColumn (target
, target
->cfa
, &sp_slot
);
1675 for (i
= 0; i
< __LIBGCC_DWARF_FRAME_REGISTERS__
; ++i
)
1677 void *c
= (void *) (_Unwind_Internal_Ptr
) current
->reg
[i
];
1678 void *t
= (void *) (_Unwind_Internal_Ptr
)target
->reg
[i
];
1680 gcc_assert (current
->by_value
[i
] == 0);
1681 if (target
->by_value
[i
] && c
)
1685 if (dwarf_reg_size_table
[i
] == sizeof (_Unwind_Word
))
1687 w
= (_Unwind_Internal_Ptr
) t
;
1688 memcpy (c
, &w
, sizeof (_Unwind_Word
));
1692 gcc_assert (dwarf_reg_size_table
[i
] == sizeof (_Unwind_Ptr
));
1693 p
= (_Unwind_Internal_Ptr
) t
;
1694 memcpy (c
, &p
, sizeof (_Unwind_Ptr
));
1697 else if (t
&& c
&& t
!= c
)
1698 memcpy (c
, t
, dwarf_reg_size_table
[i
]);
1701 /* If the current frame doesn't have a saved stack pointer, then we
1702 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1703 pointer value reloaded. */
1704 if (!_Unwind_GetGRPtr (current
, __builtin_dwarf_sp_column ()))
1708 target_cfa
= _Unwind_GetPtr (target
, __builtin_dwarf_sp_column ());
1710 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1711 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1712 return target_cfa
- current
->cfa
+ target
->args_size
;
1714 return current
->cfa
- target_cfa
- target
->args_size
;
1719 static inline _Unwind_Ptr
1720 uw_identify_context (struct _Unwind_Context
*context
)
1722 /* The CFA is not sufficient to disambiguate the context of a function
1723 interrupted by a signal before establishing its frame and the context
1724 of the signal itself. */
1725 if (__LIBGCC_STACK_GROWS_DOWNWARD__
)
1726 return _Unwind_GetCFA (context
) - _Unwind_IsSignalFrame (context
);
1728 return _Unwind_GetCFA (context
) + _Unwind_IsSignalFrame (context
);
1732 #include "unwind.inc"
1734 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1735 alias (_Unwind_Backtrace
);
1736 alias (_Unwind_DeleteException
);
1737 alias (_Unwind_FindEnclosingFunction
);
1738 alias (_Unwind_ForcedUnwind
);
1739 alias (_Unwind_GetDataRelBase
);
1740 alias (_Unwind_GetTextRelBase
);
1741 alias (_Unwind_GetCFA
);
1742 alias (_Unwind_GetGR
);
1743 alias (_Unwind_GetIP
);
1744 alias (_Unwind_GetLanguageSpecificData
);
1745 alias (_Unwind_GetRegionStart
);
1746 alias (_Unwind_RaiseException
);
1747 alias (_Unwind_Resume
);
1748 alias (_Unwind_Resume_or_Rethrow
);
1749 alias (_Unwind_SetGR
);
1750 alias (_Unwind_SetIP
);
1753 #endif /* !USING_SJLJ_EXCEPTIONS */