1 | /* ===-- assembly.h - libUnwind assembler support macros -------------------=== |
2 | * |
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 |
6 | * |
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 | |
18 | #if defined(__powerpc64__) |
19 | #define SEPARATOR ; |
20 | #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 |
31 | #elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) |
32 | #define SEPARATOR @ |
33 | #elif defined(__arm64__) |
34 | #define SEPARATOR %% |
35 | #else |
36 | #define SEPARATOR ; |
37 | #endif |
38 | |
39 | #define GLUE2(a, b) a ## b |
40 | #define GLUE(a, b) GLUE2(a, b) |
41 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
42 | |
43 | #if defined(__APPLE__) |
44 | |
45 | #define SYMBOL_IS_FUNC(name) |
46 | #define EXPORT_SYMBOL(name) |
47 | #define HIDDEN_SYMBOL(name) .private_extern name |
48 | #define WEAK_SYMBOL(name) .weak_reference name |
49 | #define WEAK_ALIAS(name, aliasname) \ |
50 | .globl SYMBOL_NAME(aliasname) SEPARATOR \ |
51 | WEAK_SYMBOL(aliasname) SEPARATOR \ |
52 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
53 | |
54 | #define NO_EXEC_STACK_DIRECTIVE |
55 | |
56 | #elif defined(__ELF__) |
57 | |
58 | #if defined(__arm__) |
59 | #define SYMBOL_IS_FUNC(name) .type name,%function |
60 | #else |
61 | #define SYMBOL_IS_FUNC(name) .type name,@function |
62 | #endif |
63 | #define EXPORT_SYMBOL(name) |
64 | #define HIDDEN_SYMBOL(name) .hidden name |
65 | #define WEAK_SYMBOL(name) .weak name |
66 | #define WEAK_ALIAS(name, aliasname) \ |
67 | WEAK_SYMBOL(aliasname) SEPARATOR \ |
68 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
69 | |
70 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
71 | defined(__linux__) |
72 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
73 | #else |
74 | #define NO_EXEC_STACK_DIRECTIVE |
75 | #endif |
76 | |
77 | #elif defined(_WIN32) |
78 | |
79 | #define SYMBOL_IS_FUNC(name) \ |
80 | .def name SEPARATOR \ |
81 | .scl 2 SEPARATOR \ |
82 | .type 32 SEPARATOR \ |
83 | .endef |
84 | #define EXPORT_SYMBOL2(name) \ |
85 | .section .drectve,"yn" SEPARATOR \ |
86 | .ascii "-export:", #name, "\0" SEPARATOR \ |
87 | .text |
88 | #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) |
89 | #define EXPORT_SYMBOL(name) |
90 | #else |
91 | #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) |
92 | #endif |
93 | #define HIDDEN_SYMBOL(name) |
94 | |
95 | #if defined(__MINGW32__) |
96 | #define WEAK_ALIAS(name, aliasname) \ |
97 | .globl SYMBOL_NAME(aliasname) SEPARATOR \ |
98 | EXPORT_SYMBOL(aliasname) SEPARATOR \ |
99 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
100 | #else |
101 | #define WEAK_ALIAS3(name, aliasname) \ |
102 | .section .drectve,"yn" SEPARATOR \ |
103 | .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \ |
104 | .text |
105 | #define WEAK_ALIAS2(name, aliasname) \ |
106 | WEAK_ALIAS3(name, aliasname) |
107 | #define WEAK_ALIAS(name, aliasname) \ |
108 | EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ |
109 | WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname)) |
110 | #endif |
111 | |
112 | #define NO_EXEC_STACK_DIRECTIVE |
113 | |
114 | #elif defined(__sparc__) |
115 | |
116 | #else |
117 | |
118 | #error Unsupported target |
119 | |
120 | #endif |
121 | |
122 | #define DEFINE_LIBUNWIND_FUNCTION(name) \ |
123 | .globl SYMBOL_NAME(name) SEPARATOR \ |
124 | HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ |
125 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
126 | SYMBOL_NAME(name): |
127 | |
128 | #if defined(__arm__) |
129 | #if !defined(__ARM_ARCH) |
130 | #define __ARM_ARCH 4 |
131 | #endif |
132 | |
133 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
134 | #define ARM_HAS_BX |
135 | #endif |
136 | |
137 | #ifdef ARM_HAS_BX |
138 | #define JMP(r) bx r |
139 | #else |
140 | #define JMP(r) mov pc, r |
141 | #endif |
142 | #endif /* __arm__ */ |
143 | |
144 | #endif /* UNWIND_ASSEMBLY_H */ |
145 | |