blob: f2f7c848307e248127da04b0c75e1677ddf74b6a [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
Fangrui Song1b5cb742020-04-09 14:09:43 -070028#elif defined(__APPLE__) && defined(__aarch64__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000029#define SEPARATOR %%
30#else
31#define SEPARATOR ;
32#endif
33
Martin Storsjo8a6fc692019-05-16 06:49:13 +000034#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
35#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
36#define PPC64_OPD2 SEPARATOR \
37 .p2align 3 SEPARATOR \
38 .quad .Lfunc_begin0 SEPARATOR \
39 .quad .TOC.@tocbase SEPARATOR \
40 .quad 0 SEPARATOR \
41 .text SEPARATOR \
42.Lfunc_begin0:
43#else
44#define PPC64_OPD1
45#define PPC64_OPD2
46#endif
47
Daniel Kissb4416852020-09-29 15:50:19 +020048#if defined(__ARM_FEATURE_BTI_DEFAULT)
49 .pushsection ".note.gnu.property", "a" SEPARATOR \
50 .balign 8 SEPARATOR \
51 .long 4 SEPARATOR \
52 .long 0x10 SEPARATOR \
53 .long 0x5 SEPARATOR \
54 .asciz "GNU" SEPARATOR \
55 .long 0xc0000000 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ \
56 .long 4 SEPARATOR \
57 .long 3 SEPARATOR /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI AND */ \
58 /* GNU_PROPERTY_AARCH64_FEATURE_1_PAC */ \
59 .long 0 SEPARATOR \
60 .popsection SEPARATOR
61#define AARCH64_BTI bti c
62#else
63#define AARCH64_BTI
64#endif
65
Saleem Abdulrasool17552662015-04-24 19:39:17 +000066#define GLUE2(a, b) a ## b
67#define GLUE(a, b) GLUE2(a, b)
68#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
69
70#if defined(__APPLE__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000071
Saleem Abdulrasool17552662015-04-24 19:39:17 +000072#define SYMBOL_IS_FUNC(name)
Charles Davisc5094702018-08-31 18:11:48 +000073#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000074#define HIDDEN_SYMBOL(name) .private_extern name
Petr Hosek9bbfad52019-04-03 21:50:03 +000075#define WEAK_SYMBOL(name) .weak_reference name
76#define WEAK_ALIAS(name, aliasname) \
Petr Hosek2ec9ffc2019-04-04 03:36:35 +000077 .globl SYMBOL_NAME(aliasname) SEPARATOR \
Petr Hosek9bbfad52019-04-03 21:50:03 +000078 WEAK_SYMBOL(aliasname) SEPARATOR \
79 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
80
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000081#define NO_EXEC_STACK_DIRECTIVE
82
Saleem Abdulrasool17552662015-04-24 19:39:17 +000083#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000084
Saleem Abdulrasool17552662015-04-24 19:39:17 +000085#if defined(__arm__)
86#define SYMBOL_IS_FUNC(name) .type name,%function
87#else
88#define SYMBOL_IS_FUNC(name) .type name,@function
89#endif
Charles Davisc5094702018-08-31 18:11:48 +000090#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000091#define HIDDEN_SYMBOL(name) .hidden name
Petr Hosek9bbfad52019-04-03 21:50:03 +000092#define WEAK_SYMBOL(name) .weak name
Brian Cainb432c472020-04-09 00:14:02 -050093
94#if defined(__hexagon__)
95#define WEAK_ALIAS(name, aliasname) \
96 WEAK_SYMBOL(aliasname) SEPARATOR \
97 .equiv SYMBOL_NAME(aliasname), SYMBOL_NAME(name)
98#else
Petr Hosek9bbfad52019-04-03 21:50:03 +000099#define WEAK_ALIAS(name, aliasname) \
100 WEAK_SYMBOL(aliasname) SEPARATOR \
101 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
Brian Cainb432c472020-04-09 00:14:02 -0500102#endif
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000103
Manoj Guptad8b79152017-05-16 20:18:57 +0000104#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
105 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000106#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000107#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000108#define NO_EXEC_STACK_DIRECTIVE
109#endif
110
Martin Storsjo6038ed32017-10-22 19:39:26 +0000111#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000112
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000113#define SYMBOL_IS_FUNC(name) \
114 .def name SEPARATOR \
115 .scl 2 SEPARATOR \
116 .type 32 SEPARATOR \
117 .endef
Petr Hosek9bbfad52019-04-03 21:50:03 +0000118#define EXPORT_SYMBOL2(name) \
119 .section .drectve,"yn" SEPARATOR \
120 .ascii "-export:", #name, "\0" SEPARATOR \
Charles Davisc5094702018-08-31 18:11:48 +0000121 .text
Martin Storsjocf47ba62018-12-11 07:34:14 +0000122#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
123#define EXPORT_SYMBOL(name)
124#else
Charles Davisc5094702018-08-31 18:11:48 +0000125#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
Martin Storsjocf47ba62018-12-11 07:34:14 +0000126#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +0000127#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000128
Petr Hosek9bbfad52019-04-03 21:50:03 +0000129#if defined(__MINGW32__)
130#define WEAK_ALIAS(name, aliasname) \
131 .globl SYMBOL_NAME(aliasname) SEPARATOR \
132 EXPORT_SYMBOL(aliasname) SEPARATOR \
133 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
134#else
135#define WEAK_ALIAS3(name, aliasname) \
136 .section .drectve,"yn" SEPARATOR \
137 .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \
138 .text
139#define WEAK_ALIAS2(name, aliasname) \
140 WEAK_ALIAS3(name, aliasname)
141#define WEAK_ALIAS(name, aliasname) \
142 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
143 WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname))
144#endif
145
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000146#define NO_EXEC_STACK_DIRECTIVE
147
Daniel Cederman9f2f07a2019-01-14 10:15:20 +0000148#elif defined(__sparc__)
149
Martin Storsjo6038ed32017-10-22 19:39:26 +0000150#else
151
152#error Unsupported target
153
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000154#endif
155
Petr Hosek9bbfad52019-04-03 21:50:03 +0000156#define DEFINE_LIBUNWIND_FUNCTION(name) \
157 .globl SYMBOL_NAME(name) SEPARATOR \
158 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
159 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Martin Storsjo8a6fc692019-05-16 06:49:13 +0000160 PPC64_OPD1 \
161 SYMBOL_NAME(name): \
Daniel Kissb4416852020-09-29 15:50:19 +0200162 PPC64_OPD2 \
163 AARCH64_BTI
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000164
165#if defined(__arm__)
166#if !defined(__ARM_ARCH)
167#define __ARM_ARCH 4
168#endif
169
170#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
171#define ARM_HAS_BX
172#endif
173
174#ifdef ARM_HAS_BX
175#define JMP(r) bx r
176#else
177#define JMP(r) mov pc, r
178#endif
179#endif /* __arm__ */
180
181#endif /* UNWIND_ASSEMBLY_H */