1 /* ===-- assembly.h - compiler-rt assembler support macros -----------------===
2  *
3  *                     The LLVM Compiler Infrastructure
4  *
5  * This file is dual licensed under the MIT and the University of Illinois Open
6  * Source Licenses. See LICENSE.TXT for details.
7  *
8  * ===----------------------------------------------------------------------===
9  *
10  * This file defines macros for use in compiler-rt assembler source.
11  * This file is not part of the interface of this library.
12  *
13  * ===----------------------------------------------------------------------===
14  */
15 
16 #ifndef COMPILERRT_ASSEMBLY_H
17 #define COMPILERRT_ASSEMBLY_H
18 
19 #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
20 #define SEPARATOR @
21 #else
22 #define SEPARATOR ;
23 #endif
24 
25 #if defined(__APPLE__)
26 #define HIDDEN(name) .private_extern name
27 #define LOCAL_LABEL(name) L_##name
28 // tell linker it can break up file at label boundaries
29 #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
30 #define SYMBOL_IS_FUNC(name)
31 #elif defined(__ELF__)
32 #define HIDDEN(name) .hidden name
33 #define LOCAL_LABEL(name) .L_##name
34 #define FILE_LEVEL_DIRECTIVE
35 #if defined(__arm__)
36 #define SYMBOL_IS_FUNC(name) .type name,%function
37 #else
38 #define SYMBOL_IS_FUNC(name) .type name,@function
39 #endif
40 #else
41 #define HIDDEN_DIRECTIVE(name)
42 #define LOCAL_LABEL(name) .L ## name
43 #define SYMBOL_IS_FUNC(name)                                                   \
44   .def name SEPARATOR                                                          \
45     .scl 2 SEPARATOR                                                           \
46     .type 32 SEPARATOR                                                         \
47   .endef
48 #define FILE_LEVEL_DIRECTIVE
49 #endif
50 
51 #if defined(__arm__)
52 #ifndef __ARM_ARCH
53 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) ||                     \
54     defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) ||                    \
55     defined(__ARM_ARCH_7EM__)
56 #define __ARM_ARCH 7
57 #endif
58 #endif
59 
60 #ifndef __ARM_ARCH
61 #if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) ||                     \
62     defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) ||                    \
63     defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6ZM__)
64 #define __ARM_ARCH 6
65 #endif
66 #endif
67 
68 #ifndef __ARM_ARCH
69 #if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) ||                     \
70     defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)
71 #define __ARM_ARCH 5
72 #endif
73 #endif
74 
75 #ifndef __ARM_ARCH
76 #define __ARM_ARCH 4
77 #endif
78 
79 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
80 #define ARM_HAS_BX
81 #endif
82 #if !defined(__ARM_FEATURE_CLZ) &&                                             \
83     (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
84 #define __ARM_FEATURE_CLZ
85 #endif
86 
87 #ifdef ARM_HAS_BX
88 #define JMP(r) bx r
89 #define JMPc(r, c) bx##c r
90 #else
91 #define JMP(r) mov pc, r
92 #define JMPc(r, c) mov##c pc, r
93 #endif
94 
95 #if __ARM_ARCH_ISA_THUMB == 2
96 #define IT(cond)  it cond
97 #define ITT(cond) itt cond
98 #else
99 #define IT(cond)
100 #define ITT(cond)
101 #endif
102 
103 #if __ARM_ARCH_ISA_THUMB == 2
104 #define WIDE(op) op.w
105 #else
106 #define WIDE(op) op
107 #endif
108 #endif
109 
110 #define GLUE2(a, b) a##b
111 #define GLUE(a, b) GLUE2(a, b)
112 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
113 
114 #ifdef VISIBILITY_HIDDEN
115 #define DECLARE_SYMBOL_VISIBILITY(name)                                        \
116   HIDDEN(SYMBOL_NAME(name)) SEPARATOR
117 #else
118 #define DECLARE_SYMBOL_VISIBILITY(name)
119 #endif
120 
121 #define DEFINE_COMPILERRT_FUNCTION(name)                                       \
122   FILE_LEVEL_DIRECTIVE SEPARATOR                                               \
123   .globl SYMBOL_NAME(name) SEPARATOR                                           \
124   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR                                  \
125   DECLARE_SYMBOL_VISIBILITY(name)                                              \
126   SYMBOL_NAME(name):
127 
128 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name)                               \
129   FILE_LEVEL_DIRECTIVE SEPARATOR                                               \
130   .globl SYMBOL_NAME(name) SEPARATOR                                           \
131   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR                                  \
132   HIDDEN(SYMBOL_NAME(name)) SEPARATOR                                          \
133   SYMBOL_NAME(name):
134 
135 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name)                     \
136   .globl name SEPARATOR                                                        \
137   SYMBOL_IS_FUNC(name) SEPARATOR                                               \
138   HIDDEN(name) SEPARATOR                                                       \
139   name:
140 
141 #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target)                         \
142   .globl SYMBOL_NAME(name) SEPARATOR                                           \
143   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR                                  \
144   .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
145 
146 #if defined(__ARM_EABI__)
147 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)                          \
148   DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
149 #else
150 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
151 #endif
152 
153 #ifdef __ELF__
154 #define END_COMPILERRT_FUNCTION(name)                                          \
155   .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
156 #else
157 #define END_COMPILERRT_FUNCTION(name)
158 #endif
159 
160 #endif /* COMPILERRT_ASSEMBLY_H */
161