]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/config/aarch64/aarch64-unwind.h
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / aarch64 / aarch64-unwind.h
1 /* Copyright (C) 2017-2024 Free Software Foundation, Inc.
2 Contributed by ARM Ltd.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 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 #if !defined (AARCH64_UNWIND_H) && !defined (__ILP32__)
26 #define AARCH64_UNWIND_H
27
28 #define DWARF_REGNUM_AARCH64_RA_STATE 34
29
30 #define MD_DEMANGLE_RETURN_ADDR(context, fs, addr) \
31 aarch64_demangle_return_addr (context, fs, addr)
32
33 static inline int
34 aarch64_cie_signed_with_b_key (struct _Unwind_Context *context)
35 {
36 const struct dwarf_fde *fde = _Unwind_Find_FDE (context->bases.func,
37 &context->bases);
38 if (fde != NULL)
39 {
40 const struct dwarf_cie *cie = get_cie (fde);
41 if (cie != NULL)
42 {
43 const unsigned char *aug_str = cie->augmentation;
44 return __builtin_strchr ((const char *) aug_str,
45 'B') == NULL ? 0 : 1;
46 }
47 }
48 return 0;
49 }
50
51 /* Do AArch64 private extraction on ADDR_WORD based on context info CONTEXT and
52 unwind frame info FS. If ADDR_WORD is signed, we do address authentication
53 on it using CFA of current frame. */
54
55 static inline void *
56 aarch64_demangle_return_addr (struct _Unwind_Context *context,
57 _Unwind_FrameState *fs,
58 _Unwind_Word addr_word)
59 {
60 void *addr = (void *)addr_word;
61 const int reg = DWARF_REGNUM_AARCH64_RA_STATE;
62
63 if (fs->regs.how[reg] == REG_UNSAVED)
64 return addr;
65
66 /* Return-address signing state is toggled by DW_CFA_GNU_window_save (where
67 REG_UNSAVED/REG_UNSAVED_ARCHEXT means RA signing is disabled/enabled),
68 or set by a DW_CFA_expression. */
69 if (fs->regs.how[reg] == REG_UNSAVED_ARCHEXT
70 || (_Unwind_GetGR (context, reg) & 0x1) != 0)
71 {
72 _Unwind_Word salt = (_Unwind_Word) context->cfa;
73 if (aarch64_cie_signed_with_b_key (context) != 0)
74 return __builtin_aarch64_autib1716 (addr, salt);
75 return __builtin_aarch64_autia1716 (addr, salt);
76 }
77
78 return addr;
79 }
80
81 /* SME runtime function local to libgcc, streaming compatible
82 and preserves more registers than the base PCS requires, but
83 we don't rely on that here. */
84 __attribute__ ((visibility ("hidden")))
85 void __libgcc_arm_za_disable (void);
86
87 /* Disable the SME ZA state in case an unwound frame used the ZA
88 lazy saving scheme. */
89 #undef _Unwind_Frames_Extra
90 #define _Unwind_Frames_Extra(x) \
91 do \
92 { \
93 __libgcc_arm_za_disable (); \
94 } \
95 while (0)
96
97 #endif /* defined AARCH64_UNWIND_H && defined __ILP32__ */