• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NO_EXEC_STACK_DIRECTIVE
49 
50 #elif defined(__ELF__)
51 
52 #if defined(__arm__)
53 #define SYMBOL_IS_FUNC(name) .type name,%function
54 #else
55 #define SYMBOL_IS_FUNC(name) .type name,@function
56 #endif
57 #define EXPORT_SYMBOL(name)
58 #define HIDDEN_SYMBOL(name) .hidden name
59 
60 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
61     defined(__linux__)
62 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
63 #else
64 #define NO_EXEC_STACK_DIRECTIVE
65 #endif
66 
67 #elif defined(_WIN32)
68 
69 #define SYMBOL_IS_FUNC(name)                                                   \
70   .def name SEPARATOR                                                          \
71     .scl 2 SEPARATOR                                                           \
72     .type 32 SEPARATOR                                                         \
73   .endef
74 #define EXPORT_SYMBOL2(name)                              \
75   .section .drectve,"yn" SEPARATOR                        \
76   .ascii "-export:", #name, "\0" SEPARATOR                \
77   .text
78 #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
79 #define EXPORT_SYMBOL(name)
80 #else
81 #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
82 #endif
83 #define HIDDEN_SYMBOL(name)
84 
85 #define NO_EXEC_STACK_DIRECTIVE
86 
87 #elif defined(__sparc__)
88 
89 #else
90 
91 #error Unsupported target
92 
93 #endif
94 
95 #define DEFINE_LIBUNWIND_FUNCTION(name)                   \
96   .globl SYMBOL_NAME(name) SEPARATOR                      \
97   EXPORT_SYMBOL(name) SEPARATOR                           \
98   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR             \
99   SYMBOL_NAME(name):
100 
101 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)           \
102   .globl SYMBOL_NAME(name) SEPARATOR                      \
103   HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR              \
104   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR             \
105   SYMBOL_NAME(name):
106 
107 #if defined(__arm__)
108 #if !defined(__ARM_ARCH)
109 #define __ARM_ARCH 4
110 #endif
111 
112 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
113 #define ARM_HAS_BX
114 #endif
115 
116 #ifdef ARM_HAS_BX
117 #define JMP(r) bx r
118 #else
119 #define JMP(r) mov pc, r
120 #endif
121 #endif /* __arm__ */
122 
123 #endif /* UNWIND_ASSEMBLY_H */
124