]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/unwind-dw2.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / unwind-dw2.c
CommitLineData
52a11cbf 1/* DWARF2 exception handling and frame unwind runtime interface routines.
8d9254fc 2 Copyright (C) 1997-2020 Free Software Foundation, Inc.
52a11cbf 3
1322177d 4 This file is part of GCC.
52a11cbf 5
1322177d
LB
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
748086b7 8 the Free Software Foundation; either version 3, or (at your option)
52a11cbf
RH
9 any later version.
10
1322177d
LB
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.
52a11cbf 15
748086b7
JJ
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.
19
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/>. */
52a11cbf
RH
24
25#include "tconfig.h"
26#include "tsystem.h"
4977bab6
ZW
27#include "coretypes.h"
28#include "tm.h"
852b75ed 29#include "libgcc_tm.h"
a80b0574 30#include "dwarf2.h"
52a11cbf 31#include "unwind.h"
525996eb
KG
32#ifdef __USING_SJLJ_EXCEPTIONS__
33# define NO_SIZE_OF_ENCODED_VALUE
34#endif
e1f9550a 35#include "unwind-pe.h"
52a11cbf
RH
36#include "unwind-dw2-fde.h"
37#include "gthr.h"
f8a57be8 38#include "unwind-dw2.h"
52a11cbf 39
f4e749b4
TT
40#ifdef HAVE_SYS_SDT_H
41#include <sys/sdt.h>
42#endif
43
0d24f4d1 44#ifndef __USING_SJLJ_EXCEPTIONS__
52a11cbf 45
53d68b9f
JM
46#ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
47#define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
52a11cbf 48#else
53d68b9f
JM
49#undef __LIBGCC_STACK_GROWS_DOWNWARD__
50#define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
52a11cbf
RH
51#endif
52
919543ab
AH
53/* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
54#ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
53d68b9f 55#define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
919543ab
AH
56#endif
57
0ec33224
RH
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.
61
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
71 call clobbered.
72
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.
78
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. */
83
84#define UNWIND_COLUMN_IN_RANGE(x) \
53d68b9f 85 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
0ec33224 86
cca2207a
L
87#ifdef REG_VALUE_IN_UNWIND_CONTEXT
88typedef _Unwind_Word _Unwind_Context_Reg_Val;
89
90#ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
91#define ASSUME_EXTENDED_UNWIND_CONTEXT 1
92#endif
93
94static inline _Unwind_Word
95_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
96{
97 return val;
98}
99
100static inline _Unwind_Context_Reg_Val
101_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
102{
103 return val;
104}
105#else
106typedef void *_Unwind_Context_Reg_Val;
107
108static inline _Unwind_Word
109_Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
110{
111 return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
112}
113
114static inline _Unwind_Context_Reg_Val
115_Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
116{
117 return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
118}
119#endif
120
121#ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
122#define ASSUME_EXTENDED_UNWIND_CONTEXT 0
123#endif
124
81a60e6c
JM
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
127 to its caller. */
52a11cbf
RH
128struct _Unwind_Context
129{
53d68b9f 130 _Unwind_Context_Reg_Val reg[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
52a11cbf
RH
131 void *cfa;
132 void *ra;
133 void *lsda;
134 struct dwarf_eh_bases bases;
f8e7718c
JJ
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)
8fc16d72
ST
139 /* Bit reserved on AArch64, return address has been signed with A or B
140 key. */
141#define RA_SIGNED_BIT ((~(_Unwind_Word) 0 >> 3) + 1)
f8e7718c
JJ
142 _Unwind_Word flags;
143 /* 0 for now, can be increased when further fields are added to
144 struct _Unwind_Context. */
145 _Unwind_Word version;
52a11cbf 146 _Unwind_Word args_size;
53d68b9f 147 char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
52a11cbf
RH
148};
149
150/* Byte size of every register managed by these routines. */
53d68b9f 151static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
52a11cbf 152
52a11cbf 153\f
52a11cbf
RH
154/* Read unaligned data from the instruction buffer. */
155
156union unaligned
157{
158 void *p;
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));
166
edbaf6a2
JDA
167static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
168static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
169 _Unwind_FrameState *);
170
52a11cbf 171static inline void *
e1f9550a 172read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
52a11cbf
RH
173
174static inline int
e9d1b155 175read_1u (const void *p) { return *(const unsigned char *) p; }
52a11cbf
RH
176
177static inline int
e9d1b155 178read_1s (const void *p) { return *(const signed char *) p; }
52a11cbf
RH
179
180static inline int
e1f9550a 181read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
52a11cbf
RH
182
183static inline int
e1f9550a 184read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
52a11cbf
RH
185
186static inline unsigned int
e1f9550a 187read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
52a11cbf
RH
188
189static inline int
e1f9550a 190read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
52a11cbf
RH
191
192static inline unsigned long
e1f9550a 193read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
52a11cbf
RH
194
195static inline unsigned long
e1f9550a 196read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
52a11cbf 197\f
f8e7718c
JJ
198static inline _Unwind_Word
199_Unwind_IsSignalFrame (struct _Unwind_Context *context)
200{
201 return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
202}
203
204static inline void
205_Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
206{
207 if (val)
208 context->flags |= SIGNAL_FRAME_BIT;
209 else
210 context->flags &= ~SIGNAL_FRAME_BIT;
211}
212
213static inline _Unwind_Word
214_Unwind_IsExtendedContext (struct _Unwind_Context *context)
215{
cca2207a
L
216 return (ASSUME_EXTENDED_UNWIND_CONTEXT
217 || (context->flags & EXTENDED_CONTEXT_BIT));
f8e7718c
JJ
218}
219\f
dbc3af4f 220/* Get the value of register REGNO as saved in CONTEXT. */
52a11cbf
RH
221
222inline _Unwind_Word
dbc3af4f 223_Unwind_GetGR (struct _Unwind_Context *context, int regno)
52a11cbf 224{
dbc3af4f 225 int size, index;
cca2207a 226 _Unwind_Context_Reg_Val val;
71628aa0 227
282efe1c 228#ifdef DWARF_ZERO_REG
fe95aee9 229 if (regno == DWARF_ZERO_REG)
282efe1c
RH
230 return 0;
231#endif
232
dbc3af4f 233 index = DWARF_REG_TO_UNWIND_COLUMN (regno);
79d0dfa3 234 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
71628aa0 235 size = dwarf_reg_size_table[index];
cca2207a 236 val = context->reg[index];
71628aa0 237
f8e7718c 238 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
cca2207a 239 return _Unwind_Get_Unwind_Word (val);
4469af7a 240
dbc3af4f
RS
241#ifdef DWARF_LAZY_REGISTER_VALUE
242 {
243 _Unwind_Word value;
244 if (DWARF_LAZY_REGISTER_VALUE (regno, &value))
245 return value;
246 }
247#endif
248
52a11cbf 249 /* This will segfault if the register hasn't been saved. */
71628aa0 250 if (size == sizeof(_Unwind_Ptr))
cca2207a 251 return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
79d0dfa3
NS
252 else
253 {
254 gcc_assert (size == sizeof(_Unwind_Word));
cca2207a 255 return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
79d0dfa3 256 }
71628aa0
R
257}
258
259static inline void *
260_Unwind_GetPtr (struct _Unwind_Context *context, int index)
261{
262 return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
52a11cbf
RH
263}
264
378683cf
RH
265/* Get the value of the CFA as saved in CONTEXT. */
266
267_Unwind_Word
268_Unwind_GetCFA (struct _Unwind_Context *context)
269{
9330e977 270 return (_Unwind_Ptr) context->cfa;
378683cf
RH
271}
272
4469af7a 273/* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
52a11cbf
RH
274
275inline void
276_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
277{
71628aa0
R
278 int size;
279 void *ptr;
280
41f3a930 281 index = DWARF_REG_TO_UNWIND_COLUMN (index);
79d0dfa3 282 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
71628aa0 283 size = dwarf_reg_size_table[index];
4469af7a 284
f8e7718c 285 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
4469af7a 286 {
cca2207a 287 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
4469af7a
JJ
288 return;
289 }
290
cca2207a 291 ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
71628aa0
R
292
293 if (size == sizeof(_Unwind_Ptr))
294 * (_Unwind_Ptr *) ptr = val;
71628aa0 295 else
79d0dfa3
NS
296 {
297 gcc_assert (size == sizeof(_Unwind_Word));
298 * (_Unwind_Word *) ptr = val;
299 }
52a11cbf
RH
300}
301
41f3a930
AH
302/* Get the pointer to a register INDEX as saved in CONTEXT. */
303
304static inline void *
305_Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
306{
307 index = DWARF_REG_TO_UNWIND_COLUMN (index);
f8e7718c 308 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
4469af7a 309 return &context->reg[index];
cca2207a 310 return (void *) (_Unwind_Internal_Ptr) context->reg[index];
41f3a930
AH
311}
312
313/* Set the pointer to a register INDEX as saved in CONTEXT. */
314
315static inline void
316_Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
317{
318 index = DWARF_REG_TO_UNWIND_COLUMN (index);
f8e7718c
JJ
319 if (_Unwind_IsExtendedContext (context))
320 context->by_value[index] = 0;
cca2207a 321 context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
41f3a930
AH
322}
323
4469af7a
JJ
324/* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
325
326static inline void
327_Unwind_SetGRValue (struct _Unwind_Context *context, int index,
328 _Unwind_Word val)
329{
330 index = DWARF_REG_TO_UNWIND_COLUMN (index);
331 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
f155bc64
L
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));
4469af7a
JJ
334
335 context->by_value[index] = 1;
cca2207a 336 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
4469af7a
JJ
337}
338
c0220ea4 339/* Return nonzero if register INDEX is stored by value rather than
4469af7a
JJ
340 by reference. */
341
342static inline int
343_Unwind_GRByValue (struct _Unwind_Context *context, int index)
344{
345 index = DWARF_REG_TO_UNWIND_COLUMN (index);
346 return context->by_value[index];
347}
348
52a11cbf
RH
349/* Retrieve the return address for CONTEXT. */
350
351inline _Unwind_Ptr
352_Unwind_GetIP (struct _Unwind_Context *context)
353{
354 return (_Unwind_Ptr) context->ra;
355}
356
754e45a8
JJ
357/* Retrieve the return address and flag whether that IP is before
358 or after first not yet fully executed instruction. */
359
360inline _Unwind_Ptr
361_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
362{
f8e7718c 363 *ip_before_insn = _Unwind_IsSignalFrame (context);
754e45a8
JJ
364 return (_Unwind_Ptr) context->ra;
365}
366
52a11cbf
RH
367/* Overwrite the return address for CONTEXT with VAL. */
368
369inline void
370_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
371{
372 context->ra = (void *) val;
373}
374
375void *
376_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
377{
378 return context->lsda;
379}
380
381_Unwind_Ptr
382_Unwind_GetRegionStart (struct _Unwind_Context *context)
383{
384 return (_Unwind_Ptr) context->bases.func;
385}
386
5dafd282 387void *
5154b05d 388_Unwind_FindEnclosingFunction (void *pc)
5dafd282
AH
389{
390 struct dwarf_eh_bases bases;
f1518966 391 const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
5dafd282
AH
392 if (fde)
393 return bases.func;
394 else
395 return NULL;
396}
397
2a1ee410
RH
398#ifndef __ia64__
399_Unwind_Ptr
400_Unwind_GetDataRelBase (struct _Unwind_Context *context)
401{
402 return (_Unwind_Ptr) context->bases.dbase;
403}
404
405_Unwind_Ptr
406_Unwind_GetTextRelBase (struct _Unwind_Context *context)
407{
408 return (_Unwind_Ptr) context->bases.tbase;
409}
410#endif
8662eb14 411
58cd1d70 412#include "md-unwind-support.h"
52a11cbf
RH
413\f
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. */
417
e1f9550a 418static const unsigned char *
f1518966 419extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
52a11cbf
RH
420 _Unwind_FrameState *fs)
421{
e1f9550a 422 const unsigned char *aug = cie->augmentation;
ca29916b 423 const unsigned char *p = aug + strlen ((const char *)aug) + 1;
e1f9550a 424 const unsigned char *ret = NULL;
f767122b
AK
425 _uleb128_t utmp;
426 _sleb128_t stmp;
52a11cbf 427
5442cf15
MK
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')
431 {
432 fs->eh_ptr = read_pointer (p);
433 p += sizeof (void *);
434 aug += 2;
435 }
436
8f65940d
JJ
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))
441 {
442 if (p[0] != sizeof (void *) || p[1] != 0)
443 return NULL;
444 p += 2;
445 }
446 /* Immediately following this are the code and
52a11cbf 447 data alignment and return address column. */
f767122b
AK
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;
0ef54a47
PB
452 if (cie->version == 1)
453 fs->retaddr_column = *p++;
454 else
f767122b
AK
455 {
456 p = read_uleb128 (p, &utmp);
457 fs->retaddr_column = (_Unwind_Word)utmp;
458 }
e1f9550a 459 fs->lsda_encoding = DW_EH_PE_omit;
52a11cbf
RH
460
461 /* If the augmentation starts with 'z', then a uleb128 immediately
462 follows containing the length of the augmentation field following
463 the size. */
464 if (*aug == 'z')
465 {
a9985a92
JM
466 p = read_uleb128 (p, &utmp);
467 ret = p + utmp;
52a11cbf
RH
468
469 fs->saw_z = 1;
470 ++aug;
471 }
472
473 /* Iterate over recognized augmentation subsequences. */
474 while (*aug != '\0')
475 {
e1f9550a 476 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
5442cf15 477 if (aug[0] == 'L')
e1f9550a
RH
478 {
479 fs->lsda_encoding = *p++;
480 aug += 1;
481 }
482
483 /* "R" indicates a byte indicating how FDE addresses are encoded. */
52a11cbf
RH
484 else if (aug[0] == 'R')
485 {
e1f9550a 486 fs->fde_encoding = *p++;
52a11cbf
RH
487 aug += 1;
488 }
489
e1f9550a 490 /* "P" indicates a personality routine in the CIE augmentation. */
52a11cbf
RH
491 else if (aug[0] == 'P')
492 {
950ccbc4 493 _Unwind_Ptr personality;
b8698a0f 494
950ccbc4
NS
495 p = read_encoded_value (context, *p, p + 1, &personality);
496 fs->personality = (_Unwind_Personality_Fn) personality;
52a11cbf
RH
497 aug += 1;
498 }
499
754e45a8
JJ
500 /* "S" indicates a signal frame. */
501 else if (aug[0] == 'S')
502 {
503 fs->signal_frame = 1;
504 aug += 1;
505 }
8fc16d72
ST
506 /* aarch64 B-key pointer authentication. */
507 else if (aug[0] == 'B')
508 {
509 aug += 1;
510 }
754e45a8 511
52a11cbf
RH
512 /* Otherwise we have an unknown augmentation string.
513 Bail unless we saw a 'z' prefix. */
514 else
515 return ret;
516 }
517
518 return ret ? ret : p;
519}
520
521
522/* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
523 onto the stack to start. */
524
525static _Unwind_Word
e1f9550a 526execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
52a11cbf
RH
527 struct _Unwind_Context *context, _Unwind_Word initial)
528{
2d76cb1a 529 _Unwind_Word stack[64]; /* ??? Assume this is enough. */
52a11cbf
RH
530 int stack_elt;
531
532 stack[0] = initial;
533 stack_elt = 1;
534
535 while (op_ptr < op_end)
536 {
537 enum dwarf_location_atom op = *op_ptr++;
f767122b
AK
538 _Unwind_Word result;
539 _uleb128_t reg, utmp;
540 _sleb128_t offset, stmp;
52a11cbf
RH
541
542 switch (op)
543 {
544 case DW_OP_lit0:
545 case DW_OP_lit1:
546 case DW_OP_lit2:
547 case DW_OP_lit3:
548 case DW_OP_lit4:
549 case DW_OP_lit5:
550 case DW_OP_lit6:
551 case DW_OP_lit7:
552 case DW_OP_lit8:
553 case DW_OP_lit9:
554 case DW_OP_lit10:
555 case DW_OP_lit11:
556 case DW_OP_lit12:
557 case DW_OP_lit13:
558 case DW_OP_lit14:
559 case DW_OP_lit15:
560 case DW_OP_lit16:
561 case DW_OP_lit17:
562 case DW_OP_lit18:
563 case DW_OP_lit19:
564 case DW_OP_lit20:
565 case DW_OP_lit21:
566 case DW_OP_lit22:
567 case DW_OP_lit23:
568 case DW_OP_lit24:
569 case DW_OP_lit25:
570 case DW_OP_lit26:
571 case DW_OP_lit27:
572 case DW_OP_lit28:
573 case DW_OP_lit29:
574 case DW_OP_lit30:
575 case DW_OP_lit31:
576 result = op - DW_OP_lit0;
577 break;
578
579 case DW_OP_addr:
580 result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
581 op_ptr += sizeof (void *);
582 break;
583
b5e9dce1
RH
584 case DW_OP_GNU_encoded_addr:
585 {
586 _Unwind_Ptr presult;
587 op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
588 result = presult;
589 }
590 break;
591
52a11cbf
RH
592 case DW_OP_const1u:
593 result = read_1u (op_ptr);
594 op_ptr += 1;
595 break;
596 case DW_OP_const1s:
597 result = read_1s (op_ptr);
598 op_ptr += 1;
599 break;
600 case DW_OP_const2u:
601 result = read_2u (op_ptr);
602 op_ptr += 2;
603 break;
604 case DW_OP_const2s:
605 result = read_2s (op_ptr);
606 op_ptr += 2;
607 break;
608 case DW_OP_const4u:
609 result = read_4u (op_ptr);
610 op_ptr += 4;
611 break;
612 case DW_OP_const4s:
613 result = read_4s (op_ptr);
614 op_ptr += 4;
615 break;
616 case DW_OP_const8u:
617 result = read_8u (op_ptr);
618 op_ptr += 8;
619 break;
620 case DW_OP_const8s:
621 result = read_8s (op_ptr);
622 op_ptr += 8;
623 break;
624 case DW_OP_constu:
f767122b
AK
625 op_ptr = read_uleb128 (op_ptr, &utmp);
626 result = (_Unwind_Word)utmp;
52a11cbf
RH
627 break;
628 case DW_OP_consts:
a9985a92 629 op_ptr = read_sleb128 (op_ptr, &stmp);
f767122b 630 result = (_Unwind_Sword)stmp;
52a11cbf
RH
631 break;
632
633 case DW_OP_reg0:
634 case DW_OP_reg1:
635 case DW_OP_reg2:
636 case DW_OP_reg3:
637 case DW_OP_reg4:
638 case DW_OP_reg5:
639 case DW_OP_reg6:
640 case DW_OP_reg7:
641 case DW_OP_reg8:
642 case DW_OP_reg9:
643 case DW_OP_reg10:
644 case DW_OP_reg11:
645 case DW_OP_reg12:
646 case DW_OP_reg13:
647 case DW_OP_reg14:
648 case DW_OP_reg15:
649 case DW_OP_reg16:
650 case DW_OP_reg17:
651 case DW_OP_reg18:
652 case DW_OP_reg19:
653 case DW_OP_reg20:
654 case DW_OP_reg21:
655 case DW_OP_reg22:
656 case DW_OP_reg23:
657 case DW_OP_reg24:
658 case DW_OP_reg25:
659 case DW_OP_reg26:
660 case DW_OP_reg27:
661 case DW_OP_reg28:
662 case DW_OP_reg29:
663 case DW_OP_reg30:
664 case DW_OP_reg31:
665 result = _Unwind_GetGR (context, op - DW_OP_reg0);
666 break;
667 case DW_OP_regx:
a9985a92 668 op_ptr = read_uleb128 (op_ptr, &reg);
52a11cbf
RH
669 result = _Unwind_GetGR (context, reg);
670 break;
671
672 case DW_OP_breg0:
673 case DW_OP_breg1:
674 case DW_OP_breg2:
675 case DW_OP_breg3:
676 case DW_OP_breg4:
677 case DW_OP_breg5:
678 case DW_OP_breg6:
679 case DW_OP_breg7:
680 case DW_OP_breg8:
681 case DW_OP_breg9:
682 case DW_OP_breg10:
683 case DW_OP_breg11:
684 case DW_OP_breg12:
685 case DW_OP_breg13:
686 case DW_OP_breg14:
687 case DW_OP_breg15:
688 case DW_OP_breg16:
689 case DW_OP_breg17:
690 case DW_OP_breg18:
691 case DW_OP_breg19:
692 case DW_OP_breg20:
693 case DW_OP_breg21:
694 case DW_OP_breg22:
695 case DW_OP_breg23:
696 case DW_OP_breg24:
697 case DW_OP_breg25:
698 case DW_OP_breg26:
699 case DW_OP_breg27:
700 case DW_OP_breg28:
701 case DW_OP_breg29:
702 case DW_OP_breg30:
703 case DW_OP_breg31:
a9985a92 704 op_ptr = read_sleb128 (op_ptr, &offset);
52a11cbf
RH
705 result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
706 break;
707 case DW_OP_bregx:
a9985a92
JM
708 op_ptr = read_uleb128 (op_ptr, &reg);
709 op_ptr = read_sleb128 (op_ptr, &offset);
f767122b 710 result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
52a11cbf
RH
711 break;
712
713 case DW_OP_dup:
79d0dfa3 714 gcc_assert (stack_elt);
52a11cbf
RH
715 result = stack[stack_elt - 1];
716 break;
717
718 case DW_OP_drop:
79d0dfa3
NS
719 gcc_assert (stack_elt);
720 stack_elt -= 1;
52a11cbf
RH
721 goto no_push;
722
723 case DW_OP_pick:
724 offset = *op_ptr++;
79d0dfa3 725 gcc_assert (offset < stack_elt - 1);
52a11cbf
RH
726 result = stack[stack_elt - 1 - offset];
727 break;
728
729 case DW_OP_over:
79d0dfa3 730 gcc_assert (stack_elt >= 2);
52a11cbf
RH
731 result = stack[stack_elt - 2];
732 break;
733
9dc5c4f5
GK
734 case DW_OP_swap:
735 {
736 _Unwind_Word t;
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;
741 goto no_push;
742 }
743
52a11cbf
RH
744 case DW_OP_rot:
745 {
746 _Unwind_Word t1, t2, t3;
747
79d0dfa3 748 gcc_assert (stack_elt >= 3);
52a11cbf
RH
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;
755 goto no_push;
756 }
757
758 case DW_OP_deref:
759 case DW_OP_deref_size:
760 case DW_OP_abs:
761 case DW_OP_neg:
762 case DW_OP_not:
763 case DW_OP_plus_uconst:
764 /* Unary operations. */
79d0dfa3
NS
765 gcc_assert (stack_elt);
766 stack_elt -= 1;
b8698a0f 767
52a11cbf
RH
768 result = stack[stack_elt];
769
770 switch (op)
771 {
772 case DW_OP_deref:
773 {
a01da83b 774 void *ptr = (void *) (_Unwind_Ptr) result;
52a11cbf
RH
775 result = (_Unwind_Ptr) read_pointer (ptr);
776 }
777 break;
778
779 case DW_OP_deref_size:
780 {
a01da83b 781 void *ptr = (void *) (_Unwind_Ptr) result;
52a11cbf
RH
782 switch (*op_ptr++)
783 {
784 case 1:
785 result = read_1u (ptr);
786 break;
787 case 2:
788 result = read_2u (ptr);
789 break;
790 case 4:
791 result = read_4u (ptr);
792 break;
793 case 8:
794 result = read_8u (ptr);
795 break;
796 default:
79d0dfa3 797 gcc_unreachable ();
52a11cbf
RH
798 }
799 }
800 break;
801
802 case DW_OP_abs:
803 if ((_Unwind_Sword) result < 0)
804 result = -result;
805 break;
806 case DW_OP_neg:
807 result = -result;
808 break;
809 case DW_OP_not:
810 result = ~result;
811 break;
812 case DW_OP_plus_uconst:
a9985a92 813 op_ptr = read_uleb128 (op_ptr, &utmp);
f767122b 814 result += (_Unwind_Word)utmp;
52a11cbf 815 break;
5ed3149c
ZW
816
817 default:
79d0dfa3 818 gcc_unreachable ();
52a11cbf
RH
819 }
820 break;
821
822 case DW_OP_and:
823 case DW_OP_div:
824 case DW_OP_minus:
825 case DW_OP_mod:
826 case DW_OP_mul:
827 case DW_OP_or:
828 case DW_OP_plus:
7a706738
AM
829 case DW_OP_shl:
830 case DW_OP_shr:
831 case DW_OP_shra:
832 case DW_OP_xor:
52a11cbf
RH
833 case DW_OP_le:
834 case DW_OP_ge:
835 case DW_OP_eq:
836 case DW_OP_lt:
837 case DW_OP_gt:
838 case DW_OP_ne:
839 {
840 /* Binary operations. */
841 _Unwind_Word first, second;
79d0dfa3
NS
842 gcc_assert (stack_elt >= 2);
843 stack_elt -= 2;
b8698a0f 844
41077ce4
KH
845 second = stack[stack_elt];
846 first = stack[stack_elt + 1];
847
848 switch (op)
849 {
850 case DW_OP_and:
851 result = second & first;
852 break;
853 case DW_OP_div:
854 result = (_Unwind_Sword) second / (_Unwind_Sword) first;
855 break;
856 case DW_OP_minus:
857 result = second - first;
858 break;
859 case DW_OP_mod:
80c35b40 860 result = second % first;
41077ce4
KH
861 break;
862 case DW_OP_mul:
863 result = second * first;
864 break;
865 case DW_OP_or:
866 result = second | first;
867 break;
868 case DW_OP_plus:
869 result = second + first;
870 break;
871 case DW_OP_shl:
872 result = second << first;
873 break;
874 case DW_OP_shr:
875 result = second >> first;
876 break;
877 case DW_OP_shra:
878 result = (_Unwind_Sword) second >> first;
879 break;
880 case DW_OP_xor:
881 result = second ^ first;
882 break;
883 case DW_OP_le:
4793ad6b 884 result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
41077ce4
KH
885 break;
886 case DW_OP_ge:
4793ad6b 887 result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
41077ce4
KH
888 break;
889 case DW_OP_eq:
4793ad6b 890 result = (_Unwind_Sword) second == (_Unwind_Sword) first;
41077ce4
KH
891 break;
892 case DW_OP_lt:
4793ad6b 893 result = (_Unwind_Sword) second < (_Unwind_Sword) first;
41077ce4
KH
894 break;
895 case DW_OP_gt:
4793ad6b 896 result = (_Unwind_Sword) second > (_Unwind_Sword) first;
41077ce4
KH
897 break;
898 case DW_OP_ne:
4793ad6b 899 result = (_Unwind_Sword) second != (_Unwind_Sword) first;
41077ce4
KH
900 break;
901
902 default:
79d0dfa3 903 gcc_unreachable ();
41077ce4 904 }
52a11cbf
RH
905 }
906 break;
907
908 case DW_OP_skip:
909 offset = read_2s (op_ptr);
910 op_ptr += 2;
911 op_ptr += offset;
912 goto no_push;
913
914 case DW_OP_bra:
79d0dfa3
NS
915 gcc_assert (stack_elt);
916 stack_elt -= 1;
b8698a0f 917
52a11cbf
RH
918 offset = read_2s (op_ptr);
919 op_ptr += 2;
920 if (stack[stack_elt] != 0)
921 op_ptr += offset;
922 goto no_push;
923
924 case DW_OP_nop:
925 goto no_push;
926
927 default:
79d0dfa3 928 gcc_unreachable ();
52a11cbf
RH
929 }
930
931 /* Most things push a result value. */
79d0dfa3 932 gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
9c80ff25 933 stack[stack_elt++] = result;
52a11cbf
RH
934 no_push:;
935 }
936
937 /* We were executing this program to get a value. It should be
938 at top of stack. */
79d0dfa3
NS
939 gcc_assert (stack_elt);
940 stack_elt -= 1;
52a11cbf
RH
941 return stack[stack_elt];
942}
943
944
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. */
948
949static void
e1f9550a
RH
950execute_cfa_program (const unsigned char *insn_ptr,
951 const unsigned char *insn_end,
952 struct _Unwind_Context *context,
953 _Unwind_FrameState *fs)
52a11cbf
RH
954{
955 struct frame_state_reg_info *unused_rs = NULL;
956
957 /* Don't allow remember/restore between CIE and FDE programs. */
958 fs->regs.prev = NULL;
959
7d8ac293
JM
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
754e45a8
JJ
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 <=. */
f8e7718c
JJ
969 while (insn_ptr < insn_end
970 && fs->pc < context->ra + _Unwind_IsSignalFrame (context))
52a11cbf
RH
971 {
972 unsigned char insn = *insn_ptr++;
f767122b
AK
973 _uleb128_t reg, utmp;
974 _sleb128_t offset, stmp;
52a11cbf 975
f0451e26 976 if ((insn & 0xc0) == DW_CFA_advance_loc)
52a11cbf 977 fs->pc += (insn & 0x3f) * fs->code_align;
f0451e26 978 else if ((insn & 0xc0) == DW_CFA_offset)
52a11cbf
RH
979 {
980 reg = insn & 0x3f;
a9985a92 981 insn_ptr = read_uleb128 (insn_ptr, &utmp);
e9d1b155 982 offset = (_Unwind_Sword) utmp * fs->data_align;
0ec33224
RH
983 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
984 if (UNWIND_COLUMN_IN_RANGE (reg))
985 {
986 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
987 fs->regs.reg[reg].loc.offset = offset;
988 }
52a11cbf 989 }
f0451e26 990 else if ((insn & 0xc0) == DW_CFA_restore)
52a11cbf
RH
991 {
992 reg = insn & 0x3f;
0ec33224
RH
993 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
994 if (UNWIND_COLUMN_IN_RANGE (reg))
995 fs->regs.reg[reg].how = REG_UNSAVED;
52a11cbf
RH
996 }
997 else switch (insn)
998 {
999 case DW_CFA_set_loc:
950ccbc4
NS
1000 {
1001 _Unwind_Ptr pc;
b8698a0f 1002
950ccbc4
NS
1003 insn_ptr = read_encoded_value (context, fs->fde_encoding,
1004 insn_ptr, &pc);
1005 fs->pc = (void *) pc;
1006 }
52a11cbf
RH
1007 break;
1008
1009 case DW_CFA_advance_loc1:
9e800206 1010 fs->pc += read_1u (insn_ptr) * fs->code_align;
52a11cbf
RH
1011 insn_ptr += 1;
1012 break;
1013 case DW_CFA_advance_loc2:
9e800206 1014 fs->pc += read_2u (insn_ptr) * fs->code_align;
52a11cbf
RH
1015 insn_ptr += 2;
1016 break;
1017 case DW_CFA_advance_loc4:
9e800206 1018 fs->pc += read_4u (insn_ptr) * fs->code_align;
52a11cbf
RH
1019 insn_ptr += 4;
1020 break;
1021
1022 case DW_CFA_offset_extended:
a9985a92
JM
1023 insn_ptr = read_uleb128 (insn_ptr, &reg);
1024 insn_ptr = read_uleb128 (insn_ptr, &utmp);
e9d1b155 1025 offset = (_Unwind_Sword) utmp * fs->data_align;
0ec33224
RH
1026 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1027 if (UNWIND_COLUMN_IN_RANGE (reg))
1028 {
1029 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1030 fs->regs.reg[reg].loc.offset = offset;
1031 }
52a11cbf
RH
1032 break;
1033
1034 case DW_CFA_restore_extended:
a9985a92 1035 insn_ptr = read_uleb128 (insn_ptr, &reg);
f8a57be8
GK
1036 /* FIXME, this is wrong; the CIE might have said that the
1037 register was saved somewhere. */
0ec33224
RH
1038 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1039 if (UNWIND_COLUMN_IN_RANGE (reg))
1040 fs->regs.reg[reg].how = REG_UNSAVED;
52a11cbf
RH
1041 break;
1042
52a11cbf 1043 case DW_CFA_same_value:
cb25b0ce 1044 insn_ptr = read_uleb128 (insn_ptr, &reg);
0ec33224
RH
1045 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1046 if (UNWIND_COLUMN_IN_RANGE (reg))
1047 fs->regs.reg[reg].how = REG_UNSAVED;
cb25b0ce
BK
1048 break;
1049
54f5943c
JJ
1050 case DW_CFA_undefined:
1051 insn_ptr = read_uleb128 (insn_ptr, &reg);
0ec33224
RH
1052 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1053 if (UNWIND_COLUMN_IN_RANGE (reg))
1054 fs->regs.reg[reg].how = REG_UNDEFINED;
54f5943c
JJ
1055 break;
1056
52a11cbf
RH
1057 case DW_CFA_nop:
1058 break;
1059
1060 case DW_CFA_register:
1061 {
f767122b 1062 _uleb128_t reg2;
a9985a92
JM
1063 insn_ptr = read_uleb128 (insn_ptr, &reg);
1064 insn_ptr = read_uleb128 (insn_ptr, &reg2);
0ec33224
RH
1065 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1066 if (UNWIND_COLUMN_IN_RANGE (reg))
1067 {
1068 fs->regs.reg[reg].how = REG_SAVED_REG;
1069 fs->regs.reg[reg].loc.reg = (_Unwind_Word)reg2;
1070 }
52a11cbf
RH
1071 }
1072 break;
41077ce4 1073
52a11cbf
RH
1074 case DW_CFA_remember_state:
1075 {
1076 struct frame_state_reg_info *new_rs;
1077 if (unused_rs)
1078 {
1079 new_rs = unused_rs;
1080 unused_rs = unused_rs->prev;
1081 }
1082 else
2c82eecc 1083 new_rs = alloca (sizeof (struct frame_state_reg_info));
52a11cbf
RH
1084
1085 *new_rs = fs->regs;
1086 fs->regs.prev = new_rs;
1087 }
1088 break;
1089
1090 case DW_CFA_restore_state:
1091 {
1092 struct frame_state_reg_info *old_rs = fs->regs.prev;
1093 fs->regs = *old_rs;
1094 old_rs->prev = unused_rs;
1095 unused_rs = old_rs;
1096 }
1097 break;
1098
1099 case DW_CFA_def_cfa:
a9985a92 1100 insn_ptr = read_uleb128 (insn_ptr, &utmp);
f767122b
AK
1101 fs->regs.cfa_reg = (_Unwind_Word)utmp;
1102 insn_ptr = read_uleb128 (insn_ptr, &utmp);
1103 fs->regs.cfa_offset = (_Unwind_Word)utmp;
6673f90b 1104 fs->regs.cfa_how = CFA_REG_OFFSET;
52a11cbf
RH
1105 break;
1106
1107 case DW_CFA_def_cfa_register:
f767122b
AK
1108 insn_ptr = read_uleb128 (insn_ptr, &utmp);
1109 fs->regs.cfa_reg = (_Unwind_Word)utmp;
6673f90b 1110 fs->regs.cfa_how = CFA_REG_OFFSET;
52a11cbf
RH
1111 break;
1112
1113 case DW_CFA_def_cfa_offset:
a9985a92 1114 insn_ptr = read_uleb128 (insn_ptr, &utmp);
6673f90b 1115 fs->regs.cfa_offset = utmp;
52a11cbf
RH
1116 /* cfa_how deliberately not set. */
1117 break;
1118
1119 case DW_CFA_def_cfa_expression:
6673f90b
NF
1120 fs->regs.cfa_exp = insn_ptr;
1121 fs->regs.cfa_how = CFA_EXP;
9c80ff25 1122 insn_ptr = read_uleb128 (insn_ptr, &utmp);
a9985a92 1123 insn_ptr += utmp;
52a11cbf
RH
1124 break;
1125
1126 case DW_CFA_expression:
a9985a92 1127 insn_ptr = read_uleb128 (insn_ptr, &reg);
0ec33224
RH
1128 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1129 if (UNWIND_COLUMN_IN_RANGE (reg))
1130 {
1131 fs->regs.reg[reg].how = REG_SAVED_EXP;
1132 fs->regs.reg[reg].loc.exp = insn_ptr;
1133 }
9c80ff25 1134 insn_ptr = read_uleb128 (insn_ptr, &utmp);
a9985a92 1135 insn_ptr += utmp;
52a11cbf
RH
1136 break;
1137
4469af7a 1138 /* Dwarf3. */
52a11cbf 1139 case DW_CFA_offset_extended_sf:
a9985a92
JM
1140 insn_ptr = read_uleb128 (insn_ptr, &reg);
1141 insn_ptr = read_sleb128 (insn_ptr, &stmp);
1142 offset = stmp * fs->data_align;
0ec33224
RH
1143 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1144 if (UNWIND_COLUMN_IN_RANGE (reg))
1145 {
1146 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1147 fs->regs.reg[reg].loc.offset = offset;
1148 }
52a11cbf 1149 break;
41077ce4 1150
52a11cbf 1151 case DW_CFA_def_cfa_sf:
f767122b
AK
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;
6673f90b
NF
1156 fs->regs.cfa_how = CFA_REG_OFFSET;
1157 fs->regs.cfa_offset *= fs->data_align;
52a11cbf
RH
1158 break;
1159
1160 case DW_CFA_def_cfa_offset_sf:
f767122b
AK
1161 insn_ptr = read_sleb128 (insn_ptr, &stmp);
1162 fs->regs.cfa_offset = (_Unwind_Sword)stmp;
6673f90b 1163 fs->regs.cfa_offset *= fs->data_align;
52a11cbf
RH
1164 /* cfa_how deliberately not set. */
1165 break;
1166
4469af7a
JJ
1167 case DW_CFA_val_offset:
1168 insn_ptr = read_uleb128 (insn_ptr, &reg);
1169 insn_ptr = read_uleb128 (insn_ptr, &utmp);
1170 offset = (_Unwind_Sword) utmp * fs->data_align;
0ec33224
RH
1171 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1172 if (UNWIND_COLUMN_IN_RANGE (reg))
1173 {
1174 fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
1175 fs->regs.reg[reg].loc.offset = offset;
1176 }
4469af7a
JJ
1177 break;
1178
1179 case DW_CFA_val_offset_sf:
1180 insn_ptr = read_uleb128 (insn_ptr, &reg);
1181 insn_ptr = read_sleb128 (insn_ptr, &stmp);
1182 offset = stmp * fs->data_align;
0ec33224
RH
1183 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1184 if (UNWIND_COLUMN_IN_RANGE (reg))
1185 {
1186 fs->regs.reg[reg].how = REG_SAVED_VAL_OFFSET;
1187 fs->regs.reg[reg].loc.offset = offset;
1188 }
4469af7a
JJ
1189 break;
1190
1191 case DW_CFA_val_expression:
1192 insn_ptr = read_uleb128 (insn_ptr, &reg);
0ec33224
RH
1193 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1194 if (UNWIND_COLUMN_IN_RANGE (reg))
1195 {
1196 fs->regs.reg[reg].how = REG_SAVED_VAL_EXP;
1197 fs->regs.reg[reg].loc.exp = insn_ptr;
1198 }
4469af7a
JJ
1199 insn_ptr = read_uleb128 (insn_ptr, &utmp);
1200 insn_ptr += utmp;
1201 break;
1202
52a11cbf 1203 case DW_CFA_GNU_window_save:
a876231c 1204#if defined (__aarch64__) && !defined (__ILP32__)
5636faf2
JW
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;
1208#else
52a11cbf 1209 /* ??? Hardcoded for SPARC register window configuration. */
53d68b9f 1210 if (__LIBGCC_DWARF_FRAME_REGISTERS__ >= 32)
fbd28bc3
JJ
1211 for (reg = 16; reg < 32; ++reg)
1212 {
1213 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1214 fs->regs.reg[reg].loc.offset = (reg - 16) * sizeof (void *);
1215 }
5636faf2 1216#endif
52a11cbf
RH
1217 break;
1218
1219 case DW_CFA_GNU_args_size:
f767122b
AK
1220 insn_ptr = read_uleb128 (insn_ptr, &utmp);
1221 context->args_size = (_Unwind_Word)utmp;
52a11cbf
RH
1222 break;
1223
1224 case DW_CFA_GNU_negative_offset_extended:
1225 /* Obsoleted by DW_CFA_offset_extended_sf, but used by
1226 older PowerPC code. */
a9985a92
JM
1227 insn_ptr = read_uleb128 (insn_ptr, &reg);
1228 insn_ptr = read_uleb128 (insn_ptr, &utmp);
e9d1b155 1229 offset = (_Unwind_Word) utmp * fs->data_align;
0ec33224
RH
1230 reg = DWARF_REG_TO_UNWIND_COLUMN (reg);
1231 if (UNWIND_COLUMN_IN_RANGE (reg))
1232 {
1233 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
1234 fs->regs.reg[reg].loc.offset = -offset;
1235 }
52a11cbf
RH
1236 break;
1237
1238 default:
79d0dfa3 1239 gcc_unreachable ();
52a11cbf
RH
1240 }
1241 }
1242}
1243\f
81a60e6c
JM
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. */
1248
52a11cbf
RH
1249static _Unwind_Reason_Code
1250uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1251{
f1518966
AJ
1252 const struct dwarf_fde *fde;
1253 const struct dwarf_cie *cie;
e1f9550a 1254 const unsigned char *aug, *insn, *end;
52a11cbf
RH
1255
1256 memset (fs, 0, sizeof (*fs));
1257 context->args_size = 0;
1258 context->lsda = 0;
1259
ed80cd68
RH
1260 if (context->ra == 0)
1261 return _URC_END_OF_STACK;
1262
f8e7718c 1263 fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
754e45a8 1264 &context->bases);
52a11cbf
RH
1265 if (fde == NULL)
1266 {
8662eb14 1267#ifdef MD_FALLBACK_FRAME_STATE_FOR
52a11cbf
RH
1268 /* Couldn't find frame unwind info for this function. Try a
1269 target-specific fallback mechanism. This will necessarily
e3aafbad 1270 not provide a personality routine or LSDA. */
8662eb14 1271 return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
52a11cbf
RH
1272#else
1273 return _URC_END_OF_STACK;
1274#endif
1275 }
1276
e1f9550a 1277 fs->pc = context->bases.func;
52a11cbf
RH
1278
1279 cie = get_cie (fde);
1280 insn = extract_cie_info (cie, context, fs);
1281 if (insn == NULL)
1282 /* CIE contained unknown augmentation. */
1283 return _URC_FATAL_PHASE1_ERROR;
1284
1285 /* First decode all the insns in the CIE. */
5f754896 1286 end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
52a11cbf
RH
1287 execute_cfa_program (insn, end, context, fs);
1288
1289 /* Locate augmentation for the fde. */
5f754896 1290 aug = (const unsigned char *) fde + sizeof (*fde);
e1f9550a 1291 aug += 2 * size_of_encoded_value (fs->fde_encoding);
52a11cbf
RH
1292 insn = NULL;
1293 if (fs->saw_z)
1294 {
f767122b 1295 _uleb128_t i;
52a11cbf
RH
1296 aug = read_uleb128 (aug, &i);
1297 insn = aug + i;
1298 }
e1f9550a 1299 if (fs->lsda_encoding != DW_EH_PE_omit)
950ccbc4
NS
1300 {
1301 _Unwind_Ptr lsda;
b8698a0f 1302
950ccbc4
NS
1303 aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
1304 context->lsda = (void *) lsda;
1305 }
52a11cbf
RH
1306
1307 /* Then the insns in the FDE up to our target PC. */
1308 if (insn == NULL)
1309 insn = aug;
5f754896 1310 end = (const unsigned char *) next_fde (fde);
52a11cbf
RH
1311 execute_cfa_program (insn, end, context, fs);
1312
1313 return _URC_NO_REASON;
1314}
5442cf15
MK
1315\f
1316typedef struct frame_state
1317{
1318 void *cfa;
1319 void *eh_ptr;
1320 long cfa_offset;
1321 long args_size;
919543ab 1322 long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
5442cf15
MK
1323 unsigned short cfa_reg;
1324 unsigned short retaddr_column;
919543ab 1325 char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
5442cf15
MK
1326} frame_state;
1327
1328struct frame_state * __frame_state_for (void *, struct frame_state *);
1329
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. */
1333
1334struct frame_state *
1335__frame_state_for (void *pc_target, struct frame_state *state_in)
1336{
1337 struct _Unwind_Context context;
1338 _Unwind_FrameState fs;
1339 int reg;
1340
1341 memset (&context, 0, sizeof (struct _Unwind_Context));
cca2207a
L
1342 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1343 context.flags = EXTENDED_CONTEXT_BIT;
5442cf15
MK
1344 context.ra = pc_target + 1;
1345
1346 if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
1347 return 0;
52a11cbf 1348
5442cf15
MK
1349 /* We have no way to pass a location expression for the CFA to our
1350 caller. It wouldn't understand it anyway. */
6673f90b 1351 if (fs.regs.cfa_how == CFA_EXP)
5442cf15 1352 return 0;
52a11cbf 1353
919543ab 1354 for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
5442cf15
MK
1355 {
1356 state_in->saved[reg] = fs.regs.reg[reg].how;
1357 switch (state_in->saved[reg])
1358 {
1359 case REG_SAVED_REG:
1360 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
1361 break;
1362 case REG_SAVED_OFFSET:
1363 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
1364 break;
1365 default:
1366 state_in->reg_or_offset[reg] = 0;
1367 break;
1368 }
1369 }
1370
6673f90b
NF
1371 state_in->cfa_offset = fs.regs.cfa_offset;
1372 state_in->cfa_reg = fs.regs.cfa_reg;
5442cf15
MK
1373 state_in->retaddr_column = fs.retaddr_column;
1374 state_in->args_size = context.args_size;
1375 state_in->eh_ptr = fs.eh_ptr;
1376
1377 return state_in;
1378}
1379\f
71628aa0
R
1380typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
1381
1382static inline void
1383_Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
4469af7a 1384 _Unwind_SpTmp *tmp_sp)
71628aa0
R
1385{
1386 int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
b8698a0f 1387
71628aa0
R
1388 if (size == sizeof(_Unwind_Ptr))
1389 tmp_sp->ptr = (_Unwind_Ptr) cfa;
71628aa0 1390 else
79d0dfa3
NS
1391 {
1392 gcc_assert (size == sizeof(_Unwind_Word));
1393 tmp_sp->word = (_Unwind_Ptr) cfa;
1394 }
71628aa0
R
1395 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
1396}
1397
52a11cbf
RH
1398static void
1399uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1400{
1401 struct _Unwind_Context orig_context = *context;
1402 void *cfa;
1403 long i;
1404
53d68b9f 1405#ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
9c80ff25
RH
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.
1411
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.
1414
8b689196
RH
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. */
34dc173c 1420
71628aa0 1421 _Unwind_SpTmp tmp_sp;
34dc173c 1422
8b689196 1423 if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
71628aa0 1424 _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
8b689196 1425 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
34dc173c 1426#endif
9c80ff25 1427
52a11cbf 1428 /* Compute this frame's CFA. */
6673f90b 1429 switch (fs->regs.cfa_how)
52a11cbf
RH
1430 {
1431 case CFA_REG_OFFSET:
6673f90b
NF
1432 cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
1433 cfa += fs->regs.cfa_offset;
52a11cbf
RH
1434 break;
1435
1436 case CFA_EXP:
52a11cbf 1437 {
6673f90b 1438 const unsigned char *exp = fs->regs.cfa_exp;
f767122b 1439 _uleb128_t len;
52a11cbf
RH
1440
1441 exp = read_uleb128 (exp, &len);
1442 cfa = (void *) (_Unwind_Ptr)
9c80ff25 1443 execute_stack_op (exp, exp + len, &orig_context, 0);
52a11cbf
RH
1444 break;
1445 }
1446
1447 default:
79d0dfa3 1448 gcc_unreachable ();
52a11cbf
RH
1449 }
1450 context->cfa = cfa;
1451
1452 /* Compute the addresses of all registers saved in this frame. */
53d68b9f 1453 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__ + 1; ++i)
52a11cbf
RH
1454 switch (fs->regs.reg[i].how)
1455 {
1456 case REG_UNSAVED:
54f5943c 1457 case REG_UNDEFINED:
52a11cbf 1458 break;
9c80ff25 1459
52a11cbf 1460 case REG_SAVED_OFFSET:
9c80ff25
RH
1461 _Unwind_SetGRPtr (context, i,
1462 (void *) (cfa + fs->regs.reg[i].loc.offset));
52a11cbf 1463 break;
9c80ff25 1464
52a11cbf 1465 case REG_SAVED_REG:
4469af7a
JJ
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));
1470 else
1471 _Unwind_SetGRPtr (context, i,
1472 _Unwind_GetGRPtr (&orig_context,
1473 fs->regs.reg[i].loc.reg));
52a11cbf 1474 break;
9c80ff25 1475
52a11cbf
RH
1476 case REG_SAVED_EXP:
1477 {
e1f9550a 1478 const unsigned char *exp = fs->regs.reg[i].loc.exp;
f767122b 1479 _uleb128_t len;
52a11cbf
RH
1480 _Unwind_Ptr val;
1481
1482 exp = read_uleb128 (exp, &len);
1483 val = execute_stack_op (exp, exp + len, &orig_context,
1484 (_Unwind_Ptr) cfa);
41f3a930 1485 _Unwind_SetGRPtr (context, i, (void *) val);
52a11cbf
RH
1486 }
1487 break;
4469af7a
JJ
1488
1489 case REG_SAVED_VAL_OFFSET:
1490 _Unwind_SetGRValue (context, i,
1491 (_Unwind_Internal_Ptr)
1492 (cfa + fs->regs.reg[i].loc.offset));
1493 break;
1494
1495 case REG_SAVED_VAL_EXP:
1496 {
1497 const unsigned char *exp = fs->regs.reg[i].loc.exp;
f767122b 1498 _uleb128_t len;
4469af7a
JJ
1499 _Unwind_Ptr val;
1500
1501 exp = read_uleb128 (exp, &len);
1502 val = execute_stack_op (exp, exp + len, &orig_context,
1503 (_Unwind_Ptr) cfa);
1504 _Unwind_SetGRValue (context, i, val);
1505 }
1506 break;
52a11cbf 1507 }
fc4767bb 1508
f8e7718c 1509 _Unwind_SetSignalFrame (context, fs->signal_frame);
754e45a8 1510
8662eb14 1511#ifdef MD_FROB_UPDATE_CONTEXT
fc4767bb 1512 MD_FROB_UPDATE_CONTEXT (context, fs);
8662eb14 1513#endif
52a11cbf
RH
1514}
1515
81a60e6c
JM
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. */
1520
52a11cbf
RH
1521static void
1522uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1523{
1524 uw_update_context_1 (context, fs);
1525
54f5943c
JJ
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
1533 == REG_UNDEFINED)
1534 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1535 stack frame. */
1536 context->ra = 0;
1537 else
5636faf2
JW
1538 {
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);
1545#endif
1546 }
52a11cbf 1547}
60aef23e
DJ
1548
1549static void
1550uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1551{
1552 uw_update_context (context, fs);
1553}
52a11cbf
RH
1554\f
1555/* Fill in CONTEXT for top-of-stack. The only valid registers at this
1556 level will be the return address and the CFA. */
41077ce4 1557
a01da83b
KH
1558#define uw_init_context(CONTEXT) \
1559 do \
1560 { \
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)); \
1566 } \
1567 while (0)
52a11cbf 1568
71628aa0
R
1569static inline void
1570init_dwarf_reg_size_table (void)
1571{
1572 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
1573}
1574
e5b258a4 1575static void __attribute__((noinline))
52a11cbf
RH
1576uw_init_context_1 (struct _Unwind_Context *context,
1577 void *outer_cfa, void *outer_ra)
1578{
1579 void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
5636faf2
JW
1580#ifdef MD_POST_EXTRACT_ROOT_ADDR
1581 ra = MD_POST_EXTRACT_ROOT_ADDR (ra);
1582#endif
52a11cbf 1583 _Unwind_FrameState fs;
71628aa0 1584 _Unwind_SpTmp sp_slot;
79d0dfa3 1585 _Unwind_Reason_Code code;
52a11cbf
RH
1586
1587 memset (context, 0, sizeof (struct _Unwind_Context));
1588 context->ra = ra;
cca2207a
L
1589 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1590 context->flags = EXTENDED_CONTEXT_BIT;
52a11cbf 1591
79d0dfa3
NS
1592 code = uw_frame_state_for (context, &fs);
1593 gcc_assert (code == _URC_NO_REASON);
52a11cbf 1594
71628aa0
R
1595#if __GTHREADS
1596 {
1597 static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
1598 if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
7bec3e84 1599 && dwarf_reg_size_table[0] == 0)
71628aa0
R
1600 init_dwarf_reg_size_table ();
1601 }
1602#else
1603 if (dwarf_reg_size_table[0] == 0)
1604 init_dwarf_reg_size_table ();
1605#endif
1606
52a11cbf 1607 /* Force the frame state to use the known cfa value. */
71628aa0 1608 _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
6673f90b
NF
1609 fs.regs.cfa_how = CFA_REG_OFFSET;
1610 fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
1611 fs.regs.cfa_offset = 0;
52a11cbf
RH
1612
1613 uw_update_context_1 (context, &fs);
1614
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);
5636faf2
JW
1619#ifdef MD_POST_EXTRACT_ROOT_ADDR
1620 context->ra = MD_POST_EXTRACT_ROOT_ADDR (context->ra);
1621#endif
52a11cbf
RH
1622}
1623
934f5b42
JJ
1624static void _Unwind_DebugHook (void *, void *)
1625 __attribute__ ((__noinline__, __used__, __noclone__));
e455776a
TT
1626
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
1630 transferred. */
1631static void
1632_Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
1633 void *handler __attribute__ ((__unused__)))
1634{
f4e749b4
TT
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);
1639#else
e455776a 1640 asm ("");
f4e749b4 1641#endif
e455776a 1642}
52a11cbf 1643
5636faf2
JW
1644/* Frob exception handler's address kept in TARGET before installing into
1645 CURRENT context. */
1646
1647static inline void *
1648uw_frob_return_addr (struct _Unwind_Context *current
1649 __attribute__ ((__unused__)),
1650 struct _Unwind_Context *target)
1651{
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);
1655#endif
1656 return ret_addr;
1657}
1658
52a11cbf
RH
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
6a10fff4
IT
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
1664 technology. */
52a11cbf 1665
6a10fff4 1666#define uw_install_context(CURRENT, TARGET, FRAMES) \
e455776a
TT
1667 do \
1668 { \
1669 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
5636faf2 1670 void *handler = uw_frob_return_addr ((CURRENT), (TARGET)); \
e455776a 1671 _Unwind_DebugHook ((TARGET)->cfa, handler); \
6a10fff4 1672 _Unwind_Frames_Extra (FRAMES); \
e455776a
TT
1673 __builtin_eh_return (offset, handler); \
1674 } \
a01da83b 1675 while (0)
52a11cbf 1676
52a11cbf
RH
1677static long
1678uw_install_context_1 (struct _Unwind_Context *current,
1679 struct _Unwind_Context *target)
1680{
1681 long i;
9d8646d7
PB
1682 _Unwind_SpTmp sp_slot;
1683
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 ()))
4469af7a 1687 _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
52a11cbf 1688
53d68b9f 1689 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__; ++i)
52a11cbf 1690 {
cca2207a
L
1691 void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
1692 void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
41f3a930 1693
4469af7a
JJ
1694 gcc_assert (current->by_value[i] == 0);
1695 if (target->by_value[i] && c)
1696 {
1697 _Unwind_Word w;
1698 _Unwind_Ptr p;
1699 if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
1700 {
1701 w = (_Unwind_Internal_Ptr) t;
1702 memcpy (c, &w, sizeof (_Unwind_Word));
1703 }
1704 else
1705 {
1706 gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
1707 p = (_Unwind_Internal_Ptr) t;
1708 memcpy (c, &p, sizeof (_Unwind_Ptr));
1709 }
1710 }
1711 else if (t && c && t != c)
52a11cbf
RH
1712 memcpy (c, t, dwarf_reg_size_table[i]);
1713 }
1714
9d8646d7
PB
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 ()))
1719 {
1720 void *target_cfa;
34dc173c 1721
71628aa0 1722 target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
9d8646d7
PB
1723
1724 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
53d68b9f 1725 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
9d8646d7
PB
1726 return target_cfa - current->cfa + target->args_size;
1727 else
1728 return current->cfa - target_cfa - target->args_size;
1729 }
34dc173c 1730 return 0;
52a11cbf
RH
1731}
1732
1733static inline _Unwind_Ptr
1734uw_identify_context (struct _Unwind_Context *context)
1735{
d809253a
EB
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. */
53d68b9f 1739 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
d809253a
EB
1740 return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
1741 else
1742 return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
52a11cbf
RH
1743}
1744
1745
1746#include "unwind.inc"
1747
443728bb
L
1748#if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1749alias (_Unwind_Backtrace);
1750alias (_Unwind_DeleteException);
1751alias (_Unwind_FindEnclosingFunction);
443728bb
L
1752alias (_Unwind_ForcedUnwind);
1753alias (_Unwind_GetDataRelBase);
1754alias (_Unwind_GetTextRelBase);
1755alias (_Unwind_GetCFA);
1756alias (_Unwind_GetGR);
1757alias (_Unwind_GetIP);
1758alias (_Unwind_GetLanguageSpecificData);
1759alias (_Unwind_GetRegionStart);
1760alias (_Unwind_RaiseException);
1761alias (_Unwind_Resume);
1762alias (_Unwind_Resume_or_Rethrow);
1763alias (_Unwind_SetGR);
1764alias (_Unwind_SetIP);
1765#endif
1766
52a11cbf 1767#endif /* !USING_SJLJ_EXCEPTIONS */