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