blob: c28970534cc42dbfe955105c502f7c6da53049ef [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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080076// pop {pc} can't switch Thumb mode on ARMv4T
77#if __ARM_ARCH >= 5
78#define POP_PC() pop {pc}
79#else
80#define POP_PC() \
81 pop {ip}; \
82 JMP(ip)
83#endif
84
Stephen Hines6d186232014-11-26 17:56:19 -080085#if __ARM_ARCH_ISA_THUMB == 2
86#define IT(cond) it cond
87#define ITT(cond) itt cond
88#else
89#define IT(cond)
90#define ITT(cond)
91#endif
92
93#if __ARM_ARCH_ISA_THUMB == 2
94#define WIDE(op) op.w
95#else
96#define WIDE(op) op
97#endif
Stephen Hines2d1fdb22014-05-28 23:58:16 -070098#endif
99
100#define GLUE2(a, b) a##b
101#define GLUE(a, b) GLUE2(a, b)
102#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
103
104#ifdef VISIBILITY_HIDDEN
105#define DECLARE_SYMBOL_VISIBILITY(name) \
106 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
107#else
108#define DECLARE_SYMBOL_VISIBILITY(name)
109#endif
110
111#define DEFINE_COMPILERRT_FUNCTION(name) \
112 FILE_LEVEL_DIRECTIVE SEPARATOR \
113 .globl SYMBOL_NAME(name) SEPARATOR \
114 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
115 DECLARE_SYMBOL_VISIBILITY(name) \
116 SYMBOL_NAME(name):
117
Stephen Hines6d186232014-11-26 17:56:19 -0800118#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
119 FILE_LEVEL_DIRECTIVE SEPARATOR \
120 .globl SYMBOL_NAME(name) SEPARATOR \
121 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
122 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
123 .thumb_func SEPARATOR \
124 SYMBOL_NAME(name):
125
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700126#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
127 FILE_LEVEL_DIRECTIVE SEPARATOR \
128 .globl SYMBOL_NAME(name) SEPARATOR \
129 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
130 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
131 SYMBOL_NAME(name):
132
133#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
134 .globl name SEPARATOR \
135 SYMBOL_IS_FUNC(name) SEPARATOR \
136 HIDDEN(name) SEPARATOR \
137 name:
138
139#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
140 .globl SYMBOL_NAME(name) SEPARATOR \
141 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
142 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
143
144#if defined(__ARM_EABI__)
145#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
146 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
147#else
148#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
149#endif
150
151#ifdef __ELF__
152#define END_COMPILERRT_FUNCTION(name) \
153 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
154#else
155#define END_COMPILERRT_FUNCTION(name)
156#endif
157
158#endif /* COMPILERRT_ASSEMBLY_H */