blob: 3b1e6e6d01d7ae3c6849854f0d27049d2b8a223e [file] [log] [blame]
Saleem Abdulrasool17552662015-04-24 19:39:17 +00001/* ===-- assembly.h - libUnwind assembler support macros -------------------===
2 *
Chandler Carruth61860a52019-01-19 10:56:40 +00003 * 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
Saleem Abdulrasool17552662015-04-24 19:39:17 +00006 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file defines macros for use in libUnwind assembler source.
10 * This file is not part of the interface of this library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
14
15#ifndef UNWIND_ASSEMBLY_H
16#define UNWIND_ASSEMBLY_H
17
Martin Storsjo8338b0a2018-01-02 22:11:30 +000018#if defined(__powerpc64__)
19#define SEPARATOR ;
Martin Storsjo6518fcb2018-01-16 20:54:10 +000020#define PPC64_OFFS_SRR0 0
21#define PPC64_OFFS_CR 272
22#define PPC64_OFFS_XER 280
23#define PPC64_OFFS_LR 288
24#define PPC64_OFFS_CTR 296
25#define PPC64_OFFS_VRSAVE 304
26#define PPC64_OFFS_FP 312
27#define PPC64_OFFS_V 824
28#ifdef _ARCH_PWR8
29#define PPC64_HAS_VMX
30#endif
Fangrui Song1b5cb742020-04-09 14:09:43 -070031#elif defined(__APPLE__) && defined(__aarch64__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000032#define SEPARATOR %%
33#else
34#define SEPARATOR ;
35#endif
36
Martin Storsjo8a6fc692019-05-16 06:49:13 +000037#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
38#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
39#define PPC64_OPD2 SEPARATOR \
40 .p2align 3 SEPARATOR \
41 .quad .Lfunc_begin0 SEPARATOR \
42 .quad .TOC.@tocbase SEPARATOR \
43 .quad 0 SEPARATOR \
44 .text SEPARATOR \
45.Lfunc_begin0:
46#else
47#define PPC64_OPD1
48#define PPC64_OPD2
49#endif
50
Daniel Kissb4416852020-09-29 15:50:19 +020051#if defined(__ARM_FEATURE_BTI_DEFAULT)
52 .pushsection ".note.gnu.property", "a" SEPARATOR \
53 .balign 8 SEPARATOR \
54 .long 4 SEPARATOR \
55 .long 0x10 SEPARATOR \
56 .long 0x5 SEPARATOR \
57 .asciz "GNU" SEPARATOR \
58 .long 0xc0000000 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ \
59 .long 4 SEPARATOR \
60 .long 3 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI AND */ \
61 /* GNU_PROPERTY_AARCH64_FEATURE_1_PAC */ \
62 .long 0 SEPARATOR \
63 .popsection SEPARATOR
64#define AARCH64_BTI bti c
65#else
66#define AARCH64_BTI
67#endif
68
Saleem Abdulrasool17552662015-04-24 19:39:17 +000069#define GLUE2(a, b) a ## b
70#define GLUE(a, b) GLUE2(a, b)
71#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
72
73#if defined(__APPLE__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000074
Saleem Abdulrasool17552662015-04-24 19:39:17 +000075#define SYMBOL_IS_FUNC(name)
Charles Davisc5094702018-08-31 18:11:48 +000076#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000077#define HIDDEN_SYMBOL(name) .private_extern name
Petr Hosek9bbfad52019-04-03 21:50:03 +000078#define WEAK_SYMBOL(name) .weak_reference name
79#define WEAK_ALIAS(name, aliasname) \
Petr Hosek2ec9ffc2019-04-04 03:36:35 +000080 .globl SYMBOL_NAME(aliasname) SEPARATOR \
Petr Hosek9bbfad52019-04-03 21:50:03 +000081 WEAK_SYMBOL(aliasname) SEPARATOR \
82 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
83
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000084#define NO_EXEC_STACK_DIRECTIVE
85
Saleem Abdulrasool17552662015-04-24 19:39:17 +000086#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000087
Saleem Abdulrasool17552662015-04-24 19:39:17 +000088#if defined(__arm__)
89#define SYMBOL_IS_FUNC(name) .type name,%function
90#else
91#define SYMBOL_IS_FUNC(name) .type name,@function
92#endif
Charles Davisc5094702018-08-31 18:11:48 +000093#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000094#define HIDDEN_SYMBOL(name) .hidden name
Petr Hosek9bbfad52019-04-03 21:50:03 +000095#define WEAK_SYMBOL(name) .weak name
Brian Cainb432c472020-04-09 00:14:02 -050096
97#if defined(__hexagon__)
98#define WEAK_ALIAS(name, aliasname) \
99 WEAK_SYMBOL(aliasname) SEPARATOR \
100 .equiv SYMBOL_NAME(aliasname), SYMBOL_NAME(name)
101#else
Petr Hosek9bbfad52019-04-03 21:50:03 +0000102#define WEAK_ALIAS(name, aliasname) \
103 WEAK_SYMBOL(aliasname) SEPARATOR \
104 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
Brian Cainb432c472020-04-09 00:14:02 -0500105#endif
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000106
Manoj Guptad8b79152017-05-16 20:18:57 +0000107#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
108 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000109#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000110#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000111#define NO_EXEC_STACK_DIRECTIVE
112#endif
113
Martin Storsjo6038ed32017-10-22 19:39:26 +0000114#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000115
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000116#define SYMBOL_IS_FUNC(name) \
117 .def name SEPARATOR \
118 .scl 2 SEPARATOR \
119 .type 32 SEPARATOR \
120 .endef
Petr Hosek9bbfad52019-04-03 21:50:03 +0000121#define EXPORT_SYMBOL2(name) \
122 .section .drectve,"yn" SEPARATOR \
123 .ascii "-export:", #name, "\0" SEPARATOR \
Charles Davisc5094702018-08-31 18:11:48 +0000124 .text
Martin Storsjocf47ba62018-12-11 07:34:14 +0000125#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
126#define EXPORT_SYMBOL(name)
127#else
Charles Davisc5094702018-08-31 18:11:48 +0000128#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
Martin Storsjocf47ba62018-12-11 07:34:14 +0000129#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +0000130#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000131
Petr Hosek9bbfad52019-04-03 21:50:03 +0000132#if defined(__MINGW32__)
133#define WEAK_ALIAS(name, aliasname) \
134 .globl SYMBOL_NAME(aliasname) SEPARATOR \
135 EXPORT_SYMBOL(aliasname) SEPARATOR \
136 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
137#else
138#define WEAK_ALIAS3(name, aliasname) \
139 .section .drectve,"yn" SEPARATOR \
140 .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \
141 .text
142#define WEAK_ALIAS2(name, aliasname) \
143 WEAK_ALIAS3(name, aliasname)
144#define WEAK_ALIAS(name, aliasname) \
145 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
146 WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname))
147#endif
148
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000149#define NO_EXEC_STACK_DIRECTIVE
150
Daniel Cederman9f2f07a2019-01-14 10:15:20 +0000151#elif defined(__sparc__)
152
Martin Storsjo6038ed32017-10-22 19:39:26 +0000153#else
154
155#error Unsupported target
156
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000157#endif
158
Petr Hosek9bbfad52019-04-03 21:50:03 +0000159#define DEFINE_LIBUNWIND_FUNCTION(name) \
160 .globl SYMBOL_NAME(name) SEPARATOR \
161 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
162 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Martin Storsjo8a6fc692019-05-16 06:49:13 +0000163 PPC64_OPD1 \
164 SYMBOL_NAME(name): \
Daniel Kissb4416852020-09-29 15:50:19 +0200165 PPC64_OPD2 \
166 AARCH64_BTI
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000167
168#if defined(__arm__)
169#if !defined(__ARM_ARCH)
170#define __ARM_ARCH 4
171#endif
172
173#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
174#define ARM_HAS_BX
175#endif
176
177#ifdef ARM_HAS_BX
178#define JMP(r) bx r
179#else
180#define JMP(r) mov pc, r
181#endif
182#endif /* __arm__ */
183
184#endif /* UNWIND_ASSEMBLY_H */