]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/unwind-dw2.c
aarch64: Add bfloat16_t support for aarch64
[thirdparty/gcc.git] / libgcc / unwind-dw2.c
1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
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.
15
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/>. */
24
25 #include "tconfig.h"
26 #include "tsystem.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "libgcc_tm.h"
30 #include "dwarf2.h"
31 #include "unwind.h"
32 #ifdef __USING_SJLJ_EXCEPTIONS__
33 # define NO_SIZE_OF_ENCODED_VALUE
34 #endif
35 #include "unwind-pe.h"
36 #include "unwind-dw2-fde.h"
37 #include "gthr.h"
38 #include "unwind-dw2.h"
39 #include <stddef.h>
40
41 #ifdef HAVE_SYS_SDT_H
42 #include <sys/sdt.h>
43 #endif
44
45 #ifndef __USING_SJLJ_EXCEPTIONS__
46
47 #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
48 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
49 #else
50 #undef __LIBGCC_STACK_GROWS_DOWNWARD__
51 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
52 #endif
53
54 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
55 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
56 #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
57 #endif
58
59 /* ??? For the public function interfaces, we tend to gcc_assert that the
60 column numbers are in range. For the dwarf2 unwind info this does happen,
61 although so far in a case that doesn't actually matter.
62
63 See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
64 the call-saved xmm registers and annotates them. We havn't bothered
65 providing support for the xmm registers for the x86_64 port primarily
66 because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
67 SEH instead. Adding the support for unix targets would generally be a
68 waste. However, some runtime libraries supplied with ICC do contain such
69 an unorthodox transition, as well as the unwind info to match. This loss
70 of register restoration doesn't matter in practice, because the exception
71 is caught in the native unix abi, where all of the xmm registers are
72 call clobbered.
73
74 Ideally, we'd record some bit to notice when we're failing to restore some
75 register recorded in the unwind info, but to do that we need annotation on
76 the unix->ms abi edge, so that we know when the register data may be
77 discarded. And since this edge is also within the ICC library, we're
78 unlikely to be able to get the new annotation.
79
80 Barring a magic solution to restore the ms abi defined 128-bit xmm registers
81 (as distictly opposed to the full runtime width) without causing extra
82 overhead for normal unix abis, the best solution seems to be to simply
83 ignore unwind data for unknown columns. */
84
85 #define UNWIND_COLUMN_IN_RANGE(x) \
86 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
87
88 #ifdef REG_VALUE_IN_UNWIND_CONTEXT
89 typedef _Unwind_Word _Unwind_Context_Reg_Val;
90
91 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
92 #define ASSUME_EXTENDED_UNWIND_CONTEXT 1
93 #endif
94
95 static inline _Unwind_Word
96 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
97 {
98 return val;
99 }
100
101 static inline _Unwind_Context_Reg_Val
102 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
103 {
104 return val;
105 }
106 #else
107 typedef void *_Unwind_Context_Reg_Val;
108
109 static inline _Unwind_Word
110 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
111 {
112 return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
113 }
114
115 static inline _Unwind_Context_Reg_Val
116 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
117 {
118 return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
119 }
120 #endif
121
122 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
123 #define ASSUME_EXTENDED_UNWIND_CONTEXT 0
124 #endif
125
126 /* This is the register and unwind state for a particular frame. This
127 provides the information necessary to unwind up past a frame and return
128 to its caller. */
129 struct _Unwind_Context
130 {
131 _Unwind_Context_Reg_Val reg[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
132 void *cfa;
133 void *ra;
134 void *lsda;
135 struct dwarf_eh_bases bases;
136 /* Signal frame context. */
137 #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
138 /* Context which has version/args_size/by_value fields. */
139 #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
140 _Unwind_Word flags;
141 /* 0 for now, can be increased when further fields are added to
142 struct _Unwind_Context. */
143 _Unwind_Word version;
144 _Unwind_Word args_size;
145 char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
146 };
147
148 /* Byte size of every register managed by these routines. */
149 static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
150
151 \f
152 /* Read unaligned data from the instruction buffer. */
153
154 union unaligned
155 {
156 void *p;
157 unsigned u2 __attribute__ ((mode (HI)));
158 unsigned u4 __attribute__ ((mode (SI)));
159 unsigned u8 __attribute__ ((mode (DI)));
160 signed s2 __attribute__ ((mode (HI)));
161 signed s4 __attribute__ ((mode (SI)));
162 signed s8 __attribute__ ((mode (DI)));
163 } __attribute__ ((packed));
164
165 static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
166 static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
167 _Unwind_FrameState *);
168
169 static inline void *
170 read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
171
172 static inline int
173 read_1u (const void *p) { return *(const unsigned char *) p; }
174
175 static inline int
176 read_1s (const void *p) { return *(const signed char *) p; }
177
178 static inline int
179 read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
180
181 static inline int
182 read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
183
184 static inline unsigned int
185 read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
186
187 static inline int
188 read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
189
190 static inline unsigned long
191 read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
192
193 static inline unsigned long
194 read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
195 \f
196 static inline _Unwind_Word
197 _Unwind_IsSignalFrame (struct _Unwind_Context *context)
198 {
199 return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
200 }
201
202 static inline void
203 _Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
204 {
205 if (val)
206 context->flags |= SIGNAL_FRAME_BIT;
207 else
208 context->flags &= ~SIGNAL_FRAME_BIT;
209 }
210
211 static inline _Unwind_Word
212 _Unwind_IsExtendedContext (struct _Unwind_Context *context)
213 {
214 return (ASSUME_EXTENDED_UNWIND_CONTEXT
215 || (context->flags & EXTENDED_CONTEXT_BIT));
216 }
217 \f
218 /* Get the value of register REGNO as saved in CONTEXT. */
219
220 inline _Unwind_Word
221 _Unwind_GetGR (struct _Unwind_Context *context, int regno)
222 {
223 int size, index;
224 _Unwind_Context_Reg_Val val;
225
226 #ifdef DWARF_ZERO_REG
227 if (regno == DWARF_ZERO_REG)
228 return 0;
229 #endif
230
231 index = DWARF_REG_TO_UNWIND_COLUMN (regno);
232 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
233 size = dwarf_reg_size_table[index];
234 val = context->reg[index];
235
236 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
237 return _Unwind_Get_Unwind_Word (val);
238
239 #ifdef DWARF_LAZY_REGISTER_VALUE
240 {
241 _Unwind_Word value;
242 if (DWARF_LAZY_REGISTER_VALUE (regno, &value))
243 return value;
244 }
245 #endif
246
247 /* This will segfault if the register hasn't been saved. */
248 if (size == sizeof(_Unwind_Ptr))
249 return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
250 else
251 {
252 gcc_assert (size == sizeof(_Unwind_Word));
253 return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
254 }
255 }
256
257 static inline void *
258 _Unwind_GetPtr (struct _Unwind_Context *context, int index)
259 {
260 return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
261 }
262
263 /* Get the value of the CFA as saved in CONTEXT. */
264
265 _Unwind_Word
266 _Unwind_GetCFA (struct _Unwind_Context *context)
267 {
268 return (_Unwind_Ptr) context->cfa;
269 }
270
271 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
272
273 inline void
274 _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
275 {
276 int size;
277 void *ptr;
278
279 index = DWARF_REG_TO_UNWIND_COLUMN (index);
280 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
281 size = dwarf_reg_size_table[index];
282
283 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
284 {
285 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
286 return;
287 }
288
289 ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
290
291 if (size == sizeof(_Unwind_Ptr))
292 * (_Unwind_Ptr *) ptr = val;
293 else
294 {
295 gcc_assert (size == sizeof(_Unwind_Word));
296 * (_Unwind_Word *) ptr = val;
297 }
298 }
299
300 /* Get the pointer to a register INDEX as saved in CONTEXT. */
301
302 static inline void *
303 _Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
304 {
305 index = DWARF_REG_TO_UNWIND_COLUMN (index);
306 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
307 return &context->reg[index];
308 return (void *) (_Unwind_Internal_Ptr) context->reg[index];
309 }
310
311 /* Set the pointer to a register INDEX as saved in CONTEXT. */
312
313 static inline void
314 _Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
315 {
316 index = DWARF_REG_TO_UNWIND_COLUMN (index);
317 if (_Unwind_IsExtendedContext (context))
318 context->by_value[index] = 0;
319 context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
320 }
321
322 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
323
324 static inline void
325 _Unwind_SetGRValue (struct _Unwind_Context *context, int index,
326 _Unwind_Word val)
327 {
328 index = DWARF_REG_TO_UNWIND_COLUMN (index);
329 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
330 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
331 gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val));
332
333 context->by_value[index] = 1;
334 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
335 }
336
337 /* Return nonzero if register INDEX is stored by value rather than
338 by reference. */
339
340 static inline int
341 _Unwind_GRByValue (struct _Unwind_Context *context, int index)
342 {
343 index = DWARF_REG_TO_UNWIND_COLUMN (index);
344 return context->by_value[index];
345 }
346
347 /* Retrieve the return address for CONTEXT. */
348
349 inline _Unwind_Ptr
350 _Unwind_GetIP (struct _Unwind_Context *context)
351 {
352 return (_Unwind_Ptr) context->ra;
353 }
354
355 /* Retrieve the return address and flag whether that IP is before
356 or after first not yet fully executed instruction. */
357
358 inline _Unwind_Ptr
359 _Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
360 {
361 *ip_before_insn = _Unwind_IsSignalFrame (context);
362 return (_Unwind_Ptr) context->ra;
363 }
364
365 /* Overwrite the return address for CONTEXT with VAL. */
366
367 inline void
368 _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
369 {
370 context->ra = (void *) val;
371 }
372
373 void *
374 _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
375 {
376 return context->lsda;
377 }
378
379 _Unwind_Ptr
380 _Unwind_GetRegionStart (struct _Unwind_Context *context)
381 {
382 return (_Unwind_Ptr) context->bases.func;
383 }
384
385 void *
386 _Unwind_FindEnclosingFunction (void *pc)
387 {
388 struct dwarf_eh_bases bases;
389 const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
390 if (fde)
391 return bases.func;
392 else
393 return NULL;
394 }
395
396 #ifndef __ia64__
397 _Unwind_Ptr
398 _Unwind_GetDataRelBase (struct _Unwind_Context *context)
399 {
400 return (_Unwind_Ptr) context->bases.dbase;
401 }
402
403 _Unwind_Ptr
404 _Unwind_GetTextRelBase (struct _Unwind_Context *context)
405 {
406 return (_Unwind_Ptr) context->bases.tbase;
407 }
408 #endif
409
410 #include "md-unwind-support.h"
411 \f
412 /* Extract any interesting information from the CIE for the translation
413 unit F belongs to. Return a pointer to the byte after the augmentation,
414 or NULL if we encountered an undecipherable augmentation. */
415
416 static const unsigned char *
417 extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
418 _Unwind_FrameState *fs)
419 {
420 const unsigned char *aug = cie->augmentation;
421 const unsigned char *p = aug + strlen ((const char *)aug) + 1;
422 const unsigned char *ret = NULL;
423 _uleb128_t utmp;
424 _sleb128_t stmp;
425
426 /* g++ v2 "eh" has pointer immediately following augmentation string,
427 so it must be handled first. */
428 if (aug[0] == 'e' && aug[1] == 'h')
429 {
430 fs->eh_ptr = read_pointer (p);
431 p += sizeof (void *);
432 aug += 2;
433 }
434
435 /* After the augmentation resp. pointer for "eh" augmentation
436 follows for CIE version >= 4 address size byte and
437 segment size byte. */
438 if (__builtin_expect (cie->version >= 4, 0))
439 {
440 if (p[0] != sizeof (void *) || p[1] != 0)
441 return NULL;
442 p += 2;
443 }
444 /* Immediately following this are the code and
445 data alignment and return address column. */
446 p = read_uleb128 (p, &utmp);
447 fs->code_align = (_Unwind_Word)utmp;
448 p = read_sleb128 (p, &stmp);
449 fs->data_align = (_Unwind_Sword)stmp;
450 if (cie->version == 1)
451 fs->retaddr_column = *p++;
452 else
453 {
454 p = read_uleb128 (p, &utmp);
455 fs->retaddr_column = (_Unwind_Word)utmp;
456 }
457 fs->lsda_encoding = DW_EH_PE_omit;
458
459 /* If the augmentation starts with 'z', then a uleb128 immediately
460 follows containing the length of the augmentation field following
461 the size. */
462 if (*aug == 'z')
463 {
464 p = read_uleb128 (p, &utmp);
465 ret = p + utmp;
466
467 fs->saw_z = 1;
468 ++aug;
469 }
470
471 /* Iterate over recognized augmentation subsequences. */
472 while (*aug != '\0')
473 {
474 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
475 if (aug[0] == 'L')
476 {
477 fs->lsda_encoding = *p++;
478 aug += 1;
479 }
480
481 /* "R" indicates a byte indicating how FDE addresses are encoded. */
482 else if (aug[0] == 'R')
483 {
484 fs->fde_encoding = *p++;
485 aug += 1;
486 }
487
488 /* "P" indicates a personality routine in the CIE augmentation. */
489 else if (aug[0] == 'P')
490 {
491 _Unwind_Ptr personality;
492
493 p = read_encoded_value (context, *p, p + 1, &personality);
494 fs->personality = (_Unwind_Personality_Fn) personality;
495 aug += 1;
496 }
497
498 /* "S" indicates a signal frame. */
499 else if (aug[0] == 'S')
500 {
501 fs->signal_frame = 1;
502 aug += 1;
503 }
504 /* aarch64 B-key pointer authentication. */
505 else if (aug[0] == 'B')
506 {
507 aug += 1;
508 }
509
510 /* Otherwise we have an unknown augmentation string.
511 Bail unless we saw a 'z' prefix. */
512 else
513 return ret;
514 }
515
516 return ret ? ret : p;
517 }
518
519
520 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
521 onto the stack to start. */
522
523 static _Unwind_Word
524 execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
525 struct _Unwind_Context *context, _Unwind_Word initial)
526 {
527 _Unwind_Word stack[64]; /* ??? Assume this is enough. */
528 int stack_elt;
529
530 stack[0] = initial;
531 stack_elt = 1;
532
533 while (op_ptr < op_end)
534 {
535 enum dwarf_location_atom op = *op_ptr++;
536 _Unwind_Word result;
537 _uleb128_t reg, utmp;
538 _sleb128_t offset, stmp;
539
540 switch (op)
541 {
542 case DW_OP_lit0:
543 case DW_OP_lit1:
544 case DW_OP_lit2:
545 case DW_OP_lit3:
546 case DW_OP_lit4:
547 case DW_OP_lit5:
548 case DW_OP_lit6:
549 case DW_OP_lit7:
550 case DW_OP_lit8:
551 case DW_OP_lit9:
552 case DW_OP_lit10:
553 case DW_OP_lit11:
554 case DW_OP_lit12:
555 case DW_OP_lit13:
556 case DW_OP_lit14:
557 case DW_OP_lit15:
558 case DW_OP_lit16:
559 case DW_OP_lit17:
560 case DW_OP_lit18:
561 case DW_OP_lit19:
562 case DW_OP_lit20:
563 case DW_OP_lit21:
564 case DW_OP_lit22:
565 case DW_OP_lit23:
566 case DW_OP_lit24:
567 case DW_OP_lit25:
568 case DW_OP_lit26:
569 case DW_OP_lit27:
570 case DW_OP_lit28:
571 case DW_OP_lit29:
572 case DW_OP_lit30:
573 case DW_OP_lit31:
574 result = op - DW_OP_lit0;
575 break;
576
577 case DW_OP_addr:
578 result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
579 op_ptr += sizeof (void *);
580 break;
581
582 case DW_OP_GNU_encoded_addr:
583 {
584 _Unwind_Ptr presult;
585 op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
586 result = presult;
587 }
588 break;
589
590 case DW_OP_const1u:
591 result = read_1u (op_ptr);
592 op_ptr += 1;
593 break;
594 case DW_OP_const1s:
595 result = read_1s (op_ptr);
596 op_ptr += 1;
597 break;
598 case DW_OP_const2u:
599 result = read_2u (op_ptr);
600 op_ptr += 2;
601 break;
602 case DW_OP_const2s:
603 result = read_2s (op_ptr);
604 op_ptr += 2;
605 break;
606 case DW_OP_const4u:
607 result = read_4u (op_ptr);
608 op_ptr += 4;
609 break;
610 case DW_OP_const4s:
611 result = read_4s (op_ptr);
612 op_ptr += 4;
613 break;
614 case DW_OP_const8u:
615 result = read_8u (op_ptr);
616 op_ptr += 8;
617 break;
618 case DW_OP_const8s:
619 result = read_8s (op_ptr);
620 op_ptr += 8;
621 break;
622 case DW_OP_constu:
623 op_ptr = read_uleb128 (op_ptr, &utmp);
624 result = (_Unwind_Word)utmp;
625 break;
626 case DW_OP_consts:
627 op_ptr = read_sleb128 (op_ptr, &stmp);
628 result = (_Unwind_Sword)stmp;
629 break;
630
631 case DW_OP_reg0:
632 case DW_OP_reg1:
633 case DW_OP_reg2:
634 case DW_OP_reg3:
635 case DW_OP_reg4:
636 case DW_OP_reg5:
637 case DW_OP_reg6:
638 case DW_OP_reg7:
639 case DW_OP_reg8:
640 case DW_OP_reg9:
641 case DW_OP_reg10:
642 case DW_OP_reg11:
643 case DW_OP_reg12:
644 case DW_OP_reg13:
645 case DW_OP_reg14:
646 case DW_OP_reg15:
647 case DW_OP_reg16:
648 case DW_OP_reg17:
649 case DW_OP_reg18:
650 case DW_OP_reg19:
651 case DW_OP_reg20:
652 case DW_OP_reg21:
653 case DW_OP_reg22:
654 case DW_OP_reg23:
655 case DW_OP_reg24:
656 case DW_OP_reg25:
657 case DW_OP_reg26:
658 case DW_OP_reg27:
659 case DW_OP_reg28:
660 case DW_OP_reg29:
661 case DW_OP_reg30:
662 case DW_OP_reg31:
663 result = _Unwind_GetGR (context, op - DW_OP_reg0);
664 break;
665 case DW_OP_regx:
666 op_ptr = read_uleb128 (op_ptr, &reg);
667 result = _Unwind_GetGR (context, reg);
668 break;
669
670 case DW_OP_breg0:
671 case DW_OP_breg1:
672 case DW_OP_breg2:
673 case DW_OP_breg3:
674 case DW_OP_breg4:
675 case DW_OP_breg5:
676 case DW_OP_breg6:
677 case DW_OP_breg7:
678 case DW_OP_breg8:
679 case DW_OP_breg9:
680 case DW_OP_breg10:
681 case DW_OP_breg11:
682 case DW_OP_breg12:
683 case DW_OP_breg13:
684 case DW_OP_breg14:
685 case DW_OP_breg15:
686 case DW_OP_breg16:
687 case DW_OP_breg17:
688 case DW_OP_breg18:
689 case DW_OP_breg19:
690 case DW_OP_breg20:
691 case DW_OP_breg21:
692 case DW_OP_breg22:
693 case DW_OP_breg23:
694 case DW_OP_breg24:
695 case DW_OP_breg25:
696 case DW_OP_breg26:
697 case DW_OP_breg27:
698 case DW_OP_breg28:
699 case DW_OP_breg29:
700 case DW_OP_breg30:
701 case DW_OP_breg31:
702 op_ptr = read_sleb128 (op_ptr, &offset);
703 result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
704 break;
705 case DW_OP_bregx:
706 op_ptr = read_uleb128 (op_ptr, &reg);
707 op_ptr = read_sleb128 (op_ptr, &offset);
708 result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
709 break;
710
711 case DW_OP_dup:
712 gcc_assert (stack_elt);
713 result = stack[stack_elt - 1];
714 break;
715
716 case DW_OP_drop:
717 gcc_assert (stack_elt);
718 stack_elt -= 1;
719 goto no_push;
720
721 case DW_OP_pick:
722 offset = *op_ptr++;
723 gcc_assert (offset < stack_elt - 1);
724 result = stack[stack_elt - 1 - offset];
725 break;
726
727 case DW_OP_over:
728 gcc_assert (stack_elt >= 2);
729 result = stack[stack_elt - 2];
730 break;
731
732 case DW_OP_swap:
733 {
734 _Unwind_Word t;
735 gcc_assert (stack_elt >= 2);
736 t = stack[stack_elt - 1];
737 stack[stack_elt - 1] = stack[stack_elt - 2];
738 stack[stack_elt - 2] = t;
739 goto no_push;
740 }
741
742 case DW_OP_rot:
743 {
744 _Unwind_Word t1, t2, t3;
745
746 gcc_assert (stack_elt >= 3);
747 t1 = stack[stack_elt - 1];
748 t2 = stack[stack_elt - 2];
749 t3 = stack[stack_elt - 3];
750 stack[stack_elt - 1] = t2;
751 stack[stack_elt - 2] = t3;
752 stack[stack_elt - 3] = t1;
753 goto no_push;
754 }
755
756 case DW_OP_deref:
757 case DW_OP_deref_size:
758 case DW_OP_abs:
759 case DW_OP_neg:
760 case DW_OP_not:
761 case DW_OP_plus_uconst:
762 /* Unary operations. */
763 gcc_assert (stack_elt);
764 stack_elt -= 1;
765
766 result = stack[stack_elt];
767
768 switch (op)
769 {
770 case DW_OP_deref:
771 {
772 void *ptr = (void *) (_Unwind_Ptr) result;
773 result = (_Unwind_Ptr) read_pointer (ptr);
774 }
775 break;
776
777 case DW_OP_deref_size:
778 {
779 void *ptr = (void *) (_Unwind_Ptr) result;
780 switch (*op_ptr++)
781 {
782 case 1:
783 result = read_1u (ptr);
784 break;
785 case 2:
786 result = read_2u (ptr);
787 break;
788 case 4:
789 result = read_4u (ptr);
790 break;
791 case 8:
792 result = read_8u (ptr);
793 break;
794 default:
795 gcc_unreachable ();
796 }
797 }
798 break;
799
800 case DW_OP_abs:
801 if ((_Unwind_Sword) result < 0)
802 result = -result;
803 break;
804 case DW_OP_neg:
805 result = -result;
806 break;
807 case DW_OP_not:
808 result = ~result;
809 break;
810 case DW_OP_plus_uconst:
811 op_ptr = read_uleb128 (op_ptr, &utmp);
812 result += (_Unwind_Word)utmp;
813 break;
814
815 default:
816 gcc_unreachable ();
817 }
818 break;
819
820 case DW_OP_and:
821 case DW_OP_div:
822 case DW_OP_minus:
823 case DW_OP_mod:
824 case DW_OP_mul:
825 case DW_OP_or:
826 case DW_OP_plus:
827 case DW_OP_shl:
828 case DW_OP_shr:
829 case DW_OP_shra:
830 case DW_OP_xor:
831 case DW_OP_le:
832 case DW_OP_ge:
833 case DW_OP_eq:
834 case DW_OP_lt:
835 case DW_OP_gt:
836 case DW_OP_ne:
837 {
838 /* Binary operations. */
839 _Unwind_Word first, second;
840 gcc_assert (stack_elt >= 2);
841 stack_elt -= 2;
842
843 second = stack[stack_elt];
844 first = stack[stack_elt + 1];
845
846 switch (op)
847 {
848 case DW_OP_and:
849 result = second & first;
850 break;
851 case DW_OP_div:
852 result = (_Unwind_Sword) second / (_Unwind_Sword) first;
853 break;
854 case DW_OP_minus:
855 result = second - first;
856 break;
857 case DW_OP_mod:
858 result = second % first;
859 break;
860 case DW_OP_mul:
861 result = second * first;
862 break;
863 case DW_OP_or:
864 result = second | first;
865 break;
866 case DW_OP_plus:
867 result = second + first;
868 break;
869 case DW_OP_shl:
870 result = second << first;
871 break;
872 case DW_OP_shr:
873 result = second >> first;
874 break;
875 case DW_OP_shra:
876 result = (_Unwind_Sword) second >> first;
877 break;
878 case DW_OP_xor:
879 result = second ^ first;
880 break;
881 case DW_OP_le:
882 result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
883 break;
884 case DW_OP_ge:
885 result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
886 break;
887 case DW_OP_eq:
888 result = (_Unwind_Sword) second == (_Unwind_Sword) first;
889 break;
890 case DW_OP_lt:
891 result = (_Unwind_Sword) second < (_Unwind_Sword) first;
892 break;
893 case DW_OP_gt:
894 result = (_Unwind_Sword) second > (_Unwind_Sword) first;
895 break;
896 case DW_OP_ne:
897 result = (_Unwind_Sword) second != (_Unwind_Sword) first;
898 break;
899
900 default:
901 gcc_unreachable ();
902 }
903 }
904 break;
905
906 case DW_OP_skip:
907 offset = read_2s (op_ptr);
908 op_ptr += 2;
909 op_ptr += offset;
910 goto no_push;
911
912 case DW_OP_bra:
913 gcc_assert (stack_elt);
914 stack_elt -= 1;
915
916 offset = read_2s (op_ptr);
917 op_ptr += 2;
918 if (stack[stack_elt] != 0)
919 op_ptr += offset;
920 goto no_push;
921
922 case DW_OP_nop:
923 goto no_push;
924
925 default:
926 gcc_unreachable ();
927 }
928
929 /* Most things push a result value. */
930 gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
931 stack[stack_elt++] = result;
932 no_push:;
933 }
934
935 /* We were executing this program to get a value. It should be
936 at top of stack. */
937 gcc_assert (stack_elt);
938 stack_elt -= 1;
939 return stack[stack_elt];
940 }
941
942
943 /* Decode DWARF 2 call frame information. Takes pointers the
944 instruction sequence to decode, current register information and
945 CIE info, and the PC range to evaluate. */
946
947 static void __attribute__ ((__noinline__))
948 execute_cfa_program_generic (const unsigned char *insn_ptr,
949 const unsigned char *insn_end,
950 struct _Unwind_Context *context,
951 _Unwind_FrameState *fs)
952 {
953 #define DATA_ALIGN fs->data_align
954 #define CODE_ALIGN fs->code_align
955 #include "unwind-dw2-execute_cfa.h"
956 }
957
958 static inline void
959 execute_cfa_program_specialized (const unsigned char *insn_ptr,
960 const unsigned char *insn_end,
961 struct _Unwind_Context *context,
962 _Unwind_FrameState *fs)
963 {
964 #define DATA_ALIGN __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__
965 /* GCC always uses 1 even on architectures with a fixed instruction
966 width. */
967 #define CODE_ALIGN 1
968 #include "unwind-dw2-execute_cfa.h"
969 }
970
971 static void
972 execute_cfa_program (const unsigned char *insn_ptr,
973 const unsigned char *insn_end,
974 struct _Unwind_Context *context,
975 _Unwind_FrameState *fs)
976 {
977 if (fs->data_align == __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__
978 && fs->code_align == 1)
979 execute_cfa_program_specialized (insn_ptr, insn_end, context, fs);
980 else
981 execute_cfa_program_generic (insn_ptr, insn_end, context, fs);
982 }
983
984 \f
985 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
986 its caller and decode it into FS. This function also sets the
987 args_size and lsda members of CONTEXT, as they are really information
988 about the caller's frame. */
989
990 static _Unwind_Reason_Code
991 uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
992 {
993 const struct dwarf_fde *fde;
994 const struct dwarf_cie *cie;
995 const unsigned char *aug, *insn, *end;
996
997 memset (&fs->regs.how[0], 0,
998 sizeof (*fs) - offsetof (_Unwind_FrameState, regs.how[0]));
999 context->args_size = 0;
1000 context->lsda = 0;
1001
1002 if (context->ra == 0)
1003 return _URC_END_OF_STACK;
1004
1005 fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
1006 &context->bases);
1007 if (fde == NULL)
1008 {
1009 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1010 /* Couldn't find frame unwind info for this function. Try a
1011 target-specific fallback mechanism. This will necessarily
1012 not provide a personality routine or LSDA. */
1013 return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
1014 #else
1015 return _URC_END_OF_STACK;
1016 #endif
1017 }
1018
1019 fs->pc = context->bases.func;
1020
1021 cie = get_cie (fde);
1022 insn = extract_cie_info (cie, context, fs);
1023 if (insn == NULL)
1024 /* CIE contained unknown augmentation. */
1025 return _URC_FATAL_PHASE1_ERROR;
1026
1027 /* First decode all the insns in the CIE. */
1028 end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
1029 execute_cfa_program (insn, end, context, fs);
1030
1031 /* Locate augmentation for the fde. */
1032 aug = (const unsigned char *) fde + sizeof (*fde);
1033 aug += 2 * size_of_encoded_value (fs->fde_encoding);
1034 insn = NULL;
1035 if (fs->saw_z)
1036 {
1037 _uleb128_t i;
1038 aug = read_uleb128 (aug, &i);
1039 insn = aug + i;
1040 }
1041 if (fs->lsda_encoding != DW_EH_PE_omit)
1042 {
1043 _Unwind_Ptr lsda;
1044
1045 aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
1046 context->lsda = (void *) lsda;
1047 }
1048
1049 /* Then the insns in the FDE up to our target PC. */
1050 if (insn == NULL)
1051 insn = aug;
1052 end = (const unsigned char *) next_fde (fde);
1053 execute_cfa_program (insn, end, context, fs);
1054
1055 return _URC_NO_REASON;
1056 }
1057 \f
1058 typedef struct frame_state
1059 {
1060 void *cfa;
1061 void *eh_ptr;
1062 long cfa_offset;
1063 long args_size;
1064 long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1065 unsigned short cfa_reg;
1066 unsigned short retaddr_column;
1067 char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1068 } frame_state;
1069
1070 struct frame_state * __frame_state_for (void *, struct frame_state *);
1071
1072 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
1073 a given PC_TARGET. The caller should allocate a local variable of
1074 `struct frame_state' and pass its address to STATE_IN. */
1075
1076 struct frame_state *
1077 __frame_state_for (void *pc_target, struct frame_state *state_in)
1078 {
1079 struct _Unwind_Context context;
1080 _Unwind_FrameState fs;
1081 int reg;
1082
1083 memset (&context, 0, sizeof (struct _Unwind_Context));
1084 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1085 context.flags = EXTENDED_CONTEXT_BIT;
1086 context.ra = pc_target + 1;
1087
1088 if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
1089 return 0;
1090
1091 /* We have no way to pass a location expression for the CFA to our
1092 caller. It wouldn't understand it anyway. */
1093 if (fs.regs.cfa_how == CFA_EXP)
1094 return 0;
1095
1096 for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
1097 {
1098 state_in->saved[reg] = fs.regs.how[reg];
1099 switch (state_in->saved[reg])
1100 {
1101 case REG_SAVED_REG:
1102 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
1103 break;
1104 case REG_SAVED_OFFSET:
1105 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
1106 break;
1107 default:
1108 state_in->reg_or_offset[reg] = 0;
1109 break;
1110 }
1111 }
1112
1113 state_in->cfa_offset = fs.regs.cfa_offset;
1114 state_in->cfa_reg = fs.regs.cfa_reg;
1115 state_in->retaddr_column = fs.retaddr_column;
1116 state_in->args_size = context.args_size;
1117 state_in->eh_ptr = fs.eh_ptr;
1118
1119 return state_in;
1120 }
1121 \f
1122 typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
1123
1124 static inline void
1125 _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
1126 _Unwind_SpTmp *tmp_sp)
1127 {
1128 int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
1129
1130 if (size == sizeof(_Unwind_Ptr))
1131 tmp_sp->ptr = (_Unwind_Ptr) cfa;
1132 else
1133 {
1134 gcc_assert (size == sizeof(_Unwind_Word));
1135 tmp_sp->word = (_Unwind_Ptr) cfa;
1136 }
1137 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
1138 }
1139
1140 static void
1141 uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1142 {
1143 struct _Unwind_Context orig_context = *context;
1144 void *cfa;
1145 long i;
1146
1147 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
1148 /* Special handling here: Many machines do not use a frame pointer,
1149 and track the CFA only through offsets from the stack pointer from
1150 one frame to the next. In this case, the stack pointer is never
1151 stored, so it has no saved address in the context. What we do
1152 have is the CFA from the previous stack frame.
1153
1154 In very special situations (such as unwind info for signal return),
1155 there may be location expressions that use the stack pointer as well.
1156
1157 Do this conditionally for one frame. This allows the unwind info
1158 for one frame to save a copy of the stack pointer from the previous
1159 frame, and be able to use much easier CFA mechanisms to do it.
1160 Always zap the saved stack pointer value for the next frame; carrying
1161 the value over from one frame to another doesn't make sense. */
1162
1163 _Unwind_SpTmp tmp_sp;
1164
1165 if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
1166 _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
1167 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
1168 #endif
1169
1170 /* Compute this frame's CFA. */
1171 switch (fs->regs.cfa_how)
1172 {
1173 case CFA_REG_OFFSET:
1174 cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
1175 cfa += fs->regs.cfa_offset;
1176 break;
1177
1178 case CFA_EXP:
1179 {
1180 const unsigned char *exp = fs->regs.cfa_exp;
1181 _uleb128_t len;
1182
1183 exp = read_uleb128 (exp, &len);
1184 cfa = (void *) (_Unwind_Ptr)
1185 execute_stack_op (exp, exp + len, &orig_context, 0);
1186 break;
1187 }
1188
1189 default:
1190 gcc_unreachable ();
1191 }
1192 context->cfa = cfa;
1193
1194 /* Compute the addresses of all registers saved in this frame. */
1195 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__ + 1; ++i)
1196 switch (fs->regs.how[i])
1197 {
1198 case REG_UNSAVED:
1199 case REG_UNDEFINED:
1200 case REG_UNSAVED_ARCHEXT:
1201 break;
1202
1203 case REG_SAVED_OFFSET:
1204 _Unwind_SetGRPtr (context, i,
1205 (void *) (cfa + fs->regs.reg[i].loc.offset));
1206 break;
1207
1208 case REG_SAVED_REG:
1209 if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg))
1210 _Unwind_SetGRValue (context, i,
1211 _Unwind_GetGR (&orig_context,
1212 fs->regs.reg[i].loc.reg));
1213 else
1214 _Unwind_SetGRPtr (context, i,
1215 _Unwind_GetGRPtr (&orig_context,
1216 fs->regs.reg[i].loc.reg));
1217 break;
1218
1219 case REG_SAVED_EXP:
1220 {
1221 const unsigned char *exp = fs->regs.reg[i].loc.exp;
1222 _uleb128_t len;
1223 _Unwind_Ptr val;
1224
1225 exp = read_uleb128 (exp, &len);
1226 val = execute_stack_op (exp, exp + len, &orig_context,
1227 (_Unwind_Ptr) cfa);
1228 _Unwind_SetGRPtr (context, i, (void *) val);
1229 }
1230 break;
1231
1232 case REG_SAVED_VAL_OFFSET:
1233 _Unwind_SetGRValue (context, i,
1234 (_Unwind_Internal_Ptr)
1235 (cfa + fs->regs.reg[i].loc.offset));
1236 break;
1237
1238 case REG_SAVED_VAL_EXP:
1239 {
1240 const unsigned char *exp = fs->regs.reg[i].loc.exp;
1241 _uleb128_t len;
1242 _Unwind_Ptr val;
1243
1244 exp = read_uleb128 (exp, &len);
1245 val = execute_stack_op (exp, exp + len, &orig_context,
1246 (_Unwind_Ptr) cfa);
1247 _Unwind_SetGRValue (context, i, val);
1248 }
1249 break;
1250 }
1251
1252 _Unwind_SetSignalFrame (context, fs->signal_frame);
1253
1254 #ifdef MD_FROB_UPDATE_CONTEXT
1255 MD_FROB_UPDATE_CONTEXT (context, fs);
1256 #endif
1257 }
1258
1259 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1260 of its caller. Update CONTEXT to refer to the caller as well. Note
1261 that the args_size and lsda members are not updated here, but later in
1262 uw_frame_state_for. */
1263
1264 static void
1265 uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1266 {
1267 uw_update_context_1 (context, fs);
1268
1269 /* In general this unwinder doesn't make any distinction between
1270 undefined and same_value rule. Call-saved registers are assumed
1271 to have same_value rule by default and explicit undefined
1272 rule is handled like same_value. The only exception is
1273 DW_CFA_undefined on retaddr_column which is supposed to
1274 mark outermost frame in DWARF 3. */
1275 if (fs->regs.how[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)]
1276 == REG_UNDEFINED)
1277 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1278 stack frame. */
1279 context->ra = 0;
1280 else
1281 {
1282 /* Compute the return address now, since the return address column
1283 can change from frame to frame. */
1284 void *ret_addr;
1285 #ifdef MD_DEMANGLE_RETURN_ADDR
1286 _Unwind_Word ra = _Unwind_GetGR (context, fs->retaddr_column);
1287 ret_addr = MD_DEMANGLE_RETURN_ADDR (context, fs, ra);
1288 #else
1289 ret_addr = _Unwind_GetPtr (context, fs->retaddr_column);
1290 #endif
1291 context->ra = __builtin_extract_return_addr (ret_addr);
1292 }
1293 }
1294
1295 static void
1296 uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1297 {
1298 uw_update_context (context, fs);
1299 }
1300 \f
1301 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1302 level will be the return address and the CFA. */
1303
1304 #define uw_init_context(CONTEXT) \
1305 do \
1306 { \
1307 /* Do any necessary initialization to access arbitrary stack frames. \
1308 On the SPARC, this means flushing the register windows. */ \
1309 __builtin_unwind_init (); \
1310 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1311 __builtin_return_address (0)); \
1312 } \
1313 while (0)
1314
1315 static inline void
1316 init_dwarf_reg_size_table (void)
1317 {
1318 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
1319 }
1320
1321 static void __attribute__((noinline))
1322 uw_init_context_1 (struct _Unwind_Context *context,
1323 void *outer_cfa, void *outer_ra)
1324 {
1325 void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
1326 _Unwind_FrameState fs;
1327 _Unwind_SpTmp sp_slot;
1328 _Unwind_Reason_Code code;
1329
1330 memset (context, 0, sizeof (struct _Unwind_Context));
1331 context->ra = ra;
1332 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1333 context->flags = EXTENDED_CONTEXT_BIT;
1334
1335 code = uw_frame_state_for (context, &fs);
1336 gcc_assert (code == _URC_NO_REASON);
1337
1338 #if __GTHREADS
1339 {
1340 static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
1341 if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
1342 && dwarf_reg_size_table[0] == 0)
1343 init_dwarf_reg_size_table ();
1344 }
1345 #else
1346 if (dwarf_reg_size_table[0] == 0)
1347 init_dwarf_reg_size_table ();
1348 #endif
1349
1350 /* Force the frame state to use the known cfa value. */
1351 _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
1352 fs.regs.cfa_how = CFA_REG_OFFSET;
1353 fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
1354 fs.regs.cfa_offset = 0;
1355
1356 uw_update_context_1 (context, &fs);
1357
1358 /* If the return address column was saved in a register in the
1359 initialization context, then we can't see it in the given
1360 call frame data. So have the initialization context tell us. */
1361 context->ra = __builtin_extract_return_addr (outer_ra);
1362 }
1363
1364 static void _Unwind_DebugHook (void *, void *)
1365 __attribute__ ((__noinline__, __used__, __noclone__));
1366
1367 /* This function is called during unwinding. It is intended as a hook
1368 for a debugger to intercept exceptions. CFA is the CFA of the
1369 target frame. HANDLER is the PC to which control will be
1370 transferred. */
1371 static void
1372 _Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
1373 void *handler __attribute__ ((__unused__)))
1374 {
1375 /* We only want to use stap probes starting with v3. Earlier
1376 versions added too much startup cost. */
1377 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
1378 STAP_PROBE2 (libgcc, unwind, cfa, handler);
1379 #else
1380 asm ("");
1381 #endif
1382 }
1383
1384 /* Install TARGET into CURRENT so that we can return to it. This is a
1385 macro because __builtin_eh_return must be invoked in the context of
1386 our caller. FRAMES is a number of frames to be unwind.
1387 _Unwind_Frames_Extra is a macro to do additional work during unwinding
1388 if needed, for example shadow stack pointer adjustment for Intel CET
1389 technology. */
1390
1391 #define uw_install_context(CURRENT, TARGET, FRAMES) \
1392 do \
1393 { \
1394 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1395 void *handler = __builtin_frob_return_addr ((TARGET)->ra); \
1396 _Unwind_DebugHook ((TARGET)->cfa, handler); \
1397 _Unwind_Frames_Extra (FRAMES); \
1398 __builtin_eh_return (offset, handler); \
1399 } \
1400 while (0)
1401
1402 static long
1403 uw_install_context_1 (struct _Unwind_Context *current,
1404 struct _Unwind_Context *target)
1405 {
1406 long i;
1407 _Unwind_SpTmp sp_slot;
1408
1409 /* If the target frame does not have a saved stack pointer,
1410 then set up the target's CFA. */
1411 if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
1412 _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
1413
1414 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__; ++i)
1415 {
1416 void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
1417 void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
1418
1419 gcc_assert (current->by_value[i] == 0);
1420 if (target->by_value[i] && c)
1421 {
1422 _Unwind_Word w;
1423 _Unwind_Ptr p;
1424 if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
1425 {
1426 w = (_Unwind_Internal_Ptr) t;
1427 memcpy (c, &w, sizeof (_Unwind_Word));
1428 }
1429 else
1430 {
1431 gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
1432 p = (_Unwind_Internal_Ptr) t;
1433 memcpy (c, &p, sizeof (_Unwind_Ptr));
1434 }
1435 }
1436 else if (t && c && t != c)
1437 memcpy (c, t, dwarf_reg_size_table[i]);
1438 }
1439
1440 /* If the current frame doesn't have a saved stack pointer, then we
1441 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1442 pointer value reloaded. */
1443 if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ()))
1444 {
1445 void *target_cfa;
1446
1447 target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
1448
1449 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1450 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
1451 return target_cfa - current->cfa + target->args_size;
1452 else
1453 return current->cfa - target_cfa - target->args_size;
1454 }
1455 return 0;
1456 }
1457
1458 static inline _Unwind_Ptr
1459 uw_identify_context (struct _Unwind_Context *context)
1460 {
1461 /* The CFA is not sufficient to disambiguate the context of a function
1462 interrupted by a signal before establishing its frame and the context
1463 of the signal itself. */
1464 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
1465 return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
1466 else
1467 return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
1468 }
1469
1470
1471 #include "unwind.inc"
1472
1473 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1474 alias (_Unwind_Backtrace);
1475 alias (_Unwind_DeleteException);
1476 alias (_Unwind_FindEnclosingFunction);
1477 alias (_Unwind_ForcedUnwind);
1478 alias (_Unwind_GetDataRelBase);
1479 alias (_Unwind_GetTextRelBase);
1480 alias (_Unwind_GetCFA);
1481 alias (_Unwind_GetGR);
1482 alias (_Unwind_GetIP);
1483 alias (_Unwind_GetLanguageSpecificData);
1484 alias (_Unwind_GetRegionStart);
1485 alias (_Unwind_RaiseException);
1486 alias (_Unwind_Resume);
1487 alias (_Unwind_Resume_or_Rethrow);
1488 alias (_Unwind_SetGR);
1489 alias (_Unwind_SetIP);
1490 #endif
1491
1492 #endif /* !USING_SJLJ_EXCEPTIONS */