blob: 8bb0ddc106bddeacaf0aa31f33daa32c65a5848f [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001/* ===-- 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)
Stephen Hines86277eb2015-03-23 12:06:32 -070031#define CONST_SECTION .const
Stephen Hines6d186232014-11-26 17:56:19 -080032
Stephen Hines2d1fdb22014-05-28 23:58:16 -070033#elif defined(__ELF__)
Stephen Hines6d186232014-11-26 17:56:19 -080034
Stephen Hines2d1fdb22014-05-28 23:58:16 -070035#define HIDDEN(name) .hidden name
36#define LOCAL_LABEL(name) .L_##name
37#define FILE_LEVEL_DIRECTIVE
38#if defined(__arm__)
39#define SYMBOL_IS_FUNC(name) .type name,%function
40#else
41#define SYMBOL_IS_FUNC(name) .type name,@function
42#endif
Stephen Hines86277eb2015-03-23 12:06:32 -070043#define CONST_SECTION .section .rodata
Stephen Hines6d186232014-11-26 17:56:19 -080044
45#else // !__APPLE__ && !__ELF__
46
Stephen Hines86277eb2015-03-23 12:06:32 -070047#define HIDDEN(name)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070048#define LOCAL_LABEL(name) .L ## name
Stephen Hines6d186232014-11-26 17:56:19 -080049#define FILE_LEVEL_DIRECTIVE
Stephen Hines2d1fdb22014-05-28 23:58:16 -070050#define SYMBOL_IS_FUNC(name) \
51 .def name SEPARATOR \
Stephen Hines6a211c52014-07-21 00:49:56 -070052 .scl 2 SEPARATOR \
Stephen Hines2d1fdb22014-05-28 23:58:16 -070053 .type 32 SEPARATOR \
54 .endef
Stephen Hines86277eb2015-03-23 12:06:32 -070055#define CONST_SECTION .section .rdata,"rd"
Stephen Hines6d186232014-11-26 17:56:19 -080056
Stephen Hines2d1fdb22014-05-28 23:58:16 -070057#endif
58
59#if defined(__arm__)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070060#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
61#define ARM_HAS_BX
62#endif
63#if !defined(__ARM_FEATURE_CLZ) && \
64 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
65#define __ARM_FEATURE_CLZ
66#endif
67
68#ifdef ARM_HAS_BX
69#define JMP(r) bx r
70#define JMPc(r, c) bx##c r
71#else
72#define JMP(r) mov pc, r
73#define JMPc(r, c) mov##c pc, r
74#endif
Stephen Hines6d186232014-11-26 17:56:19 -080075
76#if __ARM_ARCH_ISA_THUMB == 2
77#define IT(cond) it cond
78#define ITT(cond) itt cond
79#else
80#define IT(cond)
81#define ITT(cond)
82#endif
83
84#if __ARM_ARCH_ISA_THUMB == 2
85#define WIDE(op) op.w
86#else
87#define WIDE(op) op
88#endif
Stephen Hines2d1fdb22014-05-28 23:58:16 -070089#endif
90
91#define GLUE2(a, b) a##b
92#define GLUE(a, b) GLUE2(a, b)
93#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
94
95#ifdef VISIBILITY_HIDDEN
96#define DECLARE_SYMBOL_VISIBILITY(name) \
97 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
98#else
99#define DECLARE_SYMBOL_VISIBILITY(name)
100#endif
101
102#define DEFINE_COMPILERRT_FUNCTION(name) \
103 FILE_LEVEL_DIRECTIVE SEPARATOR \
104 .globl SYMBOL_NAME(name) SEPARATOR \
105 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
106 DECLARE_SYMBOL_VISIBILITY(name) \
107 SYMBOL_NAME(name):
108
Stephen Hines6d186232014-11-26 17:56:19 -0800109#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
110 FILE_LEVEL_DIRECTIVE SEPARATOR \
111 .globl SYMBOL_NAME(name) SEPARATOR \
112 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
113 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
114 .thumb_func SEPARATOR \
115 SYMBOL_NAME(name):
116
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700117#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
118 FILE_LEVEL_DIRECTIVE SEPARATOR \
119 .globl SYMBOL_NAME(name) SEPARATOR \
120 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
121 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
122 SYMBOL_NAME(name):
123
124#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
125 .globl name SEPARATOR \
126 SYMBOL_IS_FUNC(name) SEPARATOR \
127 HIDDEN(name) SEPARATOR \
128 name:
129
130#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
131 .globl SYMBOL_NAME(name) SEPARATOR \
132 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
133 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
134
135#if defined(__ARM_EABI__)
136#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
137 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
138#else
139#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
140#endif
141
142#ifdef __ELF__
143#define END_COMPILERRT_FUNCTION(name) \
144 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
145#else
146#define END_COMPILERRT_FUNCTION(name)
147#endif
148
149#endif /* COMPILERRT_ASSEMBLY_H */