1 /* ===-- assembly.h - compiler-rt assembler support macros -----------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file defines macros for use in compiler-rt assembler source.
11 * This file is not part of the interface of this library.
13 * ===----------------------------------------------------------------------===
16 #ifndef COMPILERRT_ASSEMBLY_H
17 #define COMPILERRT_ASSEMBLY_H
19 #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
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 #define CONST_SECTION .const
33 #define NO_EXEC_STACK_DIRECTIVE
35 #elif defined(__ELF__)
37 #define HIDDEN(name) .hidden name
38 #define LOCAL_LABEL(name) .L_##name
39 #define FILE_LEVEL_DIRECTIVE
41 #define SYMBOL_IS_FUNC(name) .type name,%function
43 #define SYMBOL_IS_FUNC(name) .type name,@function
45 #define CONST_SECTION .section .rodata
47 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
49 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
51 #define NO_EXEC_STACK_DIRECTIVE
54 #else // !__APPLE__ && !__ELF__
57 #define LOCAL_LABEL(name) .L ## name
58 #define FILE_LEVEL_DIRECTIVE
59 #define SYMBOL_IS_FUNC(name) \
64 #define CONST_SECTION .section .rdata,"rd"
66 #define NO_EXEC_STACK_DIRECTIVE
73 * Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros:
74 * - for '-mthumb -march=armv6' compiler defines '__thumb__'
75 * - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__'
77 #if defined(__thumb2__) || defined(__thumb__)
78 #define DEFINE_CODE_STATE .thumb SEPARATOR
79 #define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR
80 #if defined(__thumb2__)
82 #define IT(cond) it cond
83 #define ITT(cond) itt cond
84 #define ITE(cond) ite cond
90 #endif // defined(__thumb__2)
91 #else // !defined(__thumb2__) && !defined(__thumb__)
92 #define DEFINE_CODE_STATE .arm SEPARATOR
93 #define DECLARE_FUNC_ENCODING
99 #if defined(USE_THUMB_1) && defined(USE_THUMB_2)
100 #error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."
103 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
106 #if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \
107 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
108 #define __ARM_FEATURE_CLZ
113 #define JMPc(r, c) bx##c r
115 #define JMP(r) mov pc, r
116 #define JMPc(r, c) mov##c pc, r
119 // pop {pc} can't switch Thumb mode on ARMv4T
121 #define POP_PC() pop {pc}
128 #if defined(USE_THUMB_2)
129 #define WIDE(op) op.w
133 #else // !defined(__arm)
134 #define DECLARE_FUNC_ENCODING
135 #define DEFINE_CODE_STATE
138 #define GLUE2(a, b) a##b
139 #define GLUE(a, b) GLUE2(a, b)
140 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
142 #ifdef VISIBILITY_HIDDEN
143 #define DECLARE_SYMBOL_VISIBILITY(name) \
144 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
146 #define DECLARE_SYMBOL_VISIBILITY(name)
149 #define DEFINE_COMPILERRT_FUNCTION(name) \
151 FILE_LEVEL_DIRECTIVE SEPARATOR \
152 .globl SYMBOL_NAME(name) SEPARATOR \
153 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
154 DECLARE_SYMBOL_VISIBILITY(name) \
155 DECLARE_FUNC_ENCODING \
158 #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
160 FILE_LEVEL_DIRECTIVE SEPARATOR \
161 .globl SYMBOL_NAME(name) SEPARATOR \
162 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
163 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
164 .thumb_func SEPARATOR \
167 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
169 FILE_LEVEL_DIRECTIVE SEPARATOR \
170 .globl SYMBOL_NAME(name) SEPARATOR \
171 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
172 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
173 DECLARE_FUNC_ENCODING \
176 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
178 .globl name SEPARATOR \
179 SYMBOL_IS_FUNC(name) SEPARATOR \
180 HIDDEN(name) SEPARATOR \
181 DECLARE_FUNC_ENCODING \
184 #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
185 .globl SYMBOL_NAME(name) SEPARATOR \
186 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
187 DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
188 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
190 #if defined(__ARM_EABI__)
191 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
192 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
194 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
198 #define END_COMPILERRT_FUNCTION(name) \
199 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
201 #define END_COMPILERRT_FUNCTION(name)
204 #endif /* COMPILERRT_ASSEMBLY_H */