1 /* ===-- assembly.h - libUnwind assembler support macros -------------------===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 * ===----------------------------------------------------------------------===
9 * This file defines macros for use in libUnwind assembler source.
10 * This file is not part of the interface of this library.
12 * ===----------------------------------------------------------------------===
15 #ifndef UNWIND_ASSEMBLY_H
16 #define UNWIND_ASSEMBLY_H
18 #if defined(__linux__) && defined(__CET__)
20 #define _LIBUNWIND_CET_ENDBR _CET_ENDBR
22 #define _LIBUNWIND_CET_ENDBR
25 #if defined(__powerpc64__)
27 #define PPC64_OFFS_SRR0 0
28 #define PPC64_OFFS_CR 272
29 #define PPC64_OFFS_XER 280
30 #define PPC64_OFFS_LR 288
31 #define PPC64_OFFS_CTR 296
32 #define PPC64_OFFS_VRSAVE 304
33 #define PPC64_OFFS_FP 312
34 #define PPC64_OFFS_V 824
35 #elif defined(__APPLE__) && defined(__aarch64__)
37 #elif defined(__riscv)
38 # define RISCV_ISIZE (__riscv_xlen / 8)
39 # define RISCV_FOFFSET (RISCV_ISIZE * 32)
40 # if defined(__riscv_flen)
41 # define RISCV_FSIZE (__riscv_flen / 8)
44 # if __riscv_xlen == 64
47 # elif __riscv_xlen == 32
51 # error "Unsupported __riscv_xlen"
54 # if defined(__riscv_flen)
55 # if __riscv_flen == 64
58 # elif __riscv_flen == 32
62 # error "Unsupported __riscv_flen"
70 #if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1) && \
72 #define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
73 #define PPC64_OPD2 SEPARATOR \
74 .p2align 3 SEPARATOR \
75 .quad .Lfunc_begin0 SEPARATOR \
76 .quad .TOC.@tocbase SEPARATOR \
85 #if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
86 .pushsection
".note.gnu.property", "a" SEPARATOR \
89 .long 0x10 SEPARATOR \
91 .asciz
"GNU" SEPARATOR \
92 .long 0xc0000000 SEPARATOR
/* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ \
94 .long 3 SEPARATOR
/* GNU_PROPERTY_AARCH64_FEATURE_1_BTI AND */ \
95 /* GNU_PROPERTY_AARCH64_FEATURE_1_PAC */ \
98 #define AARCH64_BTI bti c
103 #if !defined(__aarch64__)
104 #ifdef __ARM_FEATURE_PAC_DEFAULT
105 .eabi_attribute Tag_PAC_extension
, 2
106 .eabi_attribute Tag_PACRET_use
, 1
108 #ifdef __ARM_FEATURE_BTI_DEFAULT
109 .eabi_attribute Tag_BTI_extension
, 1
110 .eabi_attribute Tag_BTI_use
, 1
114 #define GLUE2(a, b) a ## b
115 #define GLUE(a, b) GLUE2(a, b)
116 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
118 #if defined(__APPLE__)
120 #define SYMBOL_IS_FUNC(name)
121 #define HIDDEN_SYMBOL(name) .private_extern name
122 #if defined(_LIBUNWIND_HIDE_SYMBOLS)
123 #define EXPORT_SYMBOL(name) HIDDEN_SYMBOL(name)
125 #define EXPORT_SYMBOL(name)
127 #define WEAK_ALIAS(name, aliasname) \
128 .globl SYMBOL_NAME(aliasname) SEPARATOR \
129 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
130 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
132 #define NO_EXEC_STACK_DIRECTIVE
134 #elif defined(__ELF__)
137 #define SYMBOL_IS_FUNC(name) .type name,%function
139 #define SYMBOL_IS_FUNC(name) .type name,@function
141 #define HIDDEN_SYMBOL(name) .hidden name
142 #if defined(_LIBUNWIND_HIDE_SYMBOLS)
143 #define EXPORT_SYMBOL(name) HIDDEN_SYMBOL(name)
145 #define EXPORT_SYMBOL(name)
147 #define WEAK_SYMBOL(name) .weak name
149 #if defined(__hexagon__)
150 #define WEAK_ALIAS(name, aliasname) \
151 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
152 WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
153 .equiv SYMBOL_NAME(aliasname), SYMBOL_NAME(name)
155 #define WEAK_ALIAS(name, aliasname) \
156 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
157 WEAK_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
158 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
161 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
163 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
165 #define NO_EXEC_STACK_DIRECTIVE
168 #elif defined(_WIN32)
170 #define SYMBOL_IS_FUNC(name) \
171 .def name SEPARATOR \
175 #define EXPORT_SYMBOL2(name) \
176 .section .drectve,"yn" SEPARATOR \
177 .ascii "-export:", #name, "\0" SEPARATOR \
179 #if defined(_LIBUNWIND_HIDE_SYMBOLS)
180 #define EXPORT_SYMBOL(name)
182 #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
184 #define HIDDEN_SYMBOL(name)
186 #if defined(__MINGW32__)
187 #define WEAK_ALIAS(name, aliasname) \
188 .globl SYMBOL_NAME(aliasname) SEPARATOR \
189 EXPORT_SYMBOL(aliasname) SEPARATOR \
190 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
192 #define WEAK_ALIAS3(name, aliasname) \
193 .section .drectve,"yn" SEPARATOR \
194 .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \
196 #define WEAK_ALIAS2(name, aliasname) \
197 WEAK_ALIAS3(name, aliasname)
198 #define WEAK_ALIAS(name, aliasname) \
199 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
200 WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname))
203 #define NO_EXEC_STACK_DIRECTIVE
205 #elif defined(__sparc__)
209 #if defined(__powerpc64__)
211 #define CSECT_ALIGN 3
214 #define CSECT_ALIGN 2
218 #define DEFINE_LIBUNWIND_FUNCTION_AND_WEAK_ALIAS(name, aliasname) \
219 .csect .text[PR], 2 SEPARATOR \
220 .csect .name[PR], 2 SEPARATOR \
221 .globl name[DS] SEPARATOR \
222 .globl .name[PR] SEPARATOR \
224 .csect name[DS], CSECT_ALIGN SEPARATOR \
226 .vbyte VBYTE_LEN, .name[PR] SEPARATOR \
227 .vbyte VBYTE_LEN, TOC[TC0] SEPARATOR \
228 .vbyte VBYTE_LEN, 0 SEPARATOR \
229 .weak aliasname SEPARATOR \
230 .weak .aliasname SEPARATOR \
231 .csect .name[PR], 2 SEPARATOR \
234 #define WEAK_ALIAS(name, aliasname)
235 #define NO_EXEC_STACK_DIRECTIVE
240 #error Unsupported target
246 #define DEFINE_LIBUNWIND_FUNCTION(name) \
247 .globl name[DS] SEPARATOR \
248 .globl .name SEPARATOR \
250 .csect name[DS], CSECT_ALIGN SEPARATOR \
251 .vbyte VBYTE_LEN, .name SEPARATOR \
252 .vbyte VBYTE_LEN, TOC[TC0] SEPARATOR \
253 .vbyte VBYTE_LEN, 0 SEPARATOR \
254 .csect .text[PR], 2 SEPARATOR \
258 #define DEFINE_LIBUNWIND_FUNCTION(name) \
259 .globl SYMBOL_NAME(name) SEPARATOR \
260 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
261 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
269 #if !defined(__ARM_ARCH)
273 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
280 #define JMP(r) mov pc, r
284 #if defined(__powerpc__)
285 #define PPC_LEFT_SHIFT(index) << (index)
288 #endif /* UNWIND_ASSEMBLY_H */