blob: eafbe7de619af577d86449a420a53de825fdb553 [file] [log] [blame]
Daniel Dunbar7d504782009-10-27 17:49:50 +00001/* ===-- assembly.h - compiler-rt assembler support macros -----------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant5b791f62010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Daniel Dunbar7d504782009-10-27 17:49:50 +00007 *
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
Daniel Dunbar7d504782009-10-27 17:49:50 +000019#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
Daniel Dunbar7d504782009-10-27 17:49:50 +000020#define SEPARATOR @
Daniel Dunbar7d504782009-10-27 17:49:50 +000021#else
Daniel Dunbar7d504782009-10-27 17:49:50 +000022#define SEPARATOR ;
Daniel Dunbar64a198d2010-01-18 22:19:25 +000023#endif
Daniel Dunbar7d504782009-10-27 17:49:50 +000024
Daniel Dunbar64a198d2010-01-18 22:19:25 +000025#if defined(__APPLE__)
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000026#define HIDDEN(name) .private_extern name
Anton Korobeynikov16536102011-04-19 17:50:09 +000027#define LOCAL_LABEL(name) L_##name
Jonathan Roelofsb351c1a2014-05-12 17:38:36 +000028// tell linker it can break up file at label boundaries
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000029#define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
Joerg Sonnenberger197568a2014-01-14 23:31:23 +000030#define SYMBOL_IS_FUNC(name)
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000031#define CONST_SECTION .const
Bob Wilson115547462014-10-04 20:11:10 +000032
Saleem Abdulrasool590e85b2016-06-22 22:09:42 +000033#define NO_EXEC_STACK_DIRECTIVE
34
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000035#elif defined(__ELF__)
Bob Wilson115547462014-10-04 20:11:10 +000036
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000037#define HIDDEN(name) .hidden name
Anton Korobeynikov16536102011-04-19 17:50:09 +000038#define LOCAL_LABEL(name) .L_##name
Joerg Sonnenberger197568a2014-01-14 23:31:23 +000039#define FILE_LEVEL_DIRECTIVE
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000040#if defined(__arm__)
41#define SYMBOL_IS_FUNC(name) .type name,%function
42#else
43#define SYMBOL_IS_FUNC(name) .type name,@function
44#endif
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000045#define CONST_SECTION .section .rodata
Bob Wilson115547462014-10-04 20:11:10 +000046
Manoj Guptacf0675b2017-05-15 20:41:17 +000047#if defined(__GNUC__) || defined(__ANDROID__) || defined(__FreeBSD__)
Saleem Abdulrasool590e85b2016-06-22 22:09:42 +000048#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
49#else
50#define NO_EXEC_STACK_DIRECTIVE
51#endif
52
Bob Wilson115547462014-10-04 20:11:10 +000053#else // !__APPLE__ && !__ELF__
54
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000055#define HIDDEN(name)
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000056#define LOCAL_LABEL(name) .L ## name
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +000057#define FILE_LEVEL_DIRECTIVE
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000058#define SYMBOL_IS_FUNC(name) \
59 .def name SEPARATOR \
Saleem Abdulrasoold0d16382014-06-21 01:41:21 +000060 .scl 2 SEPARATOR \
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000061 .type 32 SEPARATOR \
62 .endef
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000063#define CONST_SECTION .section .rdata,"rd"
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +000064
Saleem Abdulrasool590e85b2016-06-22 22:09:42 +000065#define NO_EXEC_STACK_DIRECTIVE
66
Daniel Dunbar7d504782009-10-27 17:49:50 +000067#endif
68
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000069#if defined(__arm__)
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000070#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
71#define ARM_HAS_BX
72#endif
Weiming Zhaoa913f7d2016-12-07 18:41:07 +000073#if !defined(__ARM_FEATURE_CLZ) && __ARM_ARCH_ISA_THUMB != 1 && \
74 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000075#define __ARM_FEATURE_CLZ
76#endif
77
78#ifdef ARM_HAS_BX
79#define JMP(r) bx r
Joerg Sonnenberger8f6cf702014-07-20 20:00:26 +000080#define JMPc(r, c) bx##c r
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000081#else
82#define JMP(r) mov pc, r
83#define JMPc(r, c) mov##c pc, r
84#endif
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +000085
Josh Gao1108ae02015-08-21 00:25:37 +000086// pop {pc} can't switch Thumb mode on ARMv4T
87#if __ARM_ARCH >= 5
88#define POP_PC() pop {pc}
89#else
90#define POP_PC() \
91 pop {ip}; \
92 JMP(ip)
93#endif
94
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +000095#if __ARM_ARCH_ISA_THUMB == 2
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +000096#define IT(cond) it cond
97#define ITT(cond) itt cond
98#else
99#define IT(cond)
100#define ITT(cond)
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000101#endif
102
103#if __ARM_ARCH_ISA_THUMB == 2
104#define WIDE(op) op.w
105#else
Saleem Abdulrasool3a2d6a32014-07-27 02:01:24 +0000106#define WIDE(op) op
107#endif
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000108#endif
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000109
110#define GLUE2(a, b) a##b
Anton Korobeynikov3c519902011-04-19 21:22:14 +0000111#define GLUE(a, b) GLUE2(a, b)
112#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
113
Bob Wilsone67004e2012-02-10 16:41:46 +0000114#ifdef VISIBILITY_HIDDEN
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000115#define DECLARE_SYMBOL_VISIBILITY(name) \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000116 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
Daniel Dunbarf665b322010-01-18 22:19:34 +0000117#else
Bob Wilson66cdd222011-08-22 21:49:47 +0000118#define DECLARE_SYMBOL_VISIBILITY(name)
119#endif
120
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000121#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) \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000126 SYMBOL_NAME(name):
127
Steven Wu84610ba2014-10-04 00:18:59 +0000128#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
129 FILE_LEVEL_DIRECTIVE SEPARATOR \
130 .globl SYMBOL_NAME(name) SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000131 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +0000132 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
Saleem Abdulrasool2cf5d822014-10-07 03:00:17 +0000133 .thumb_func SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000134 SYMBOL_NAME(name):
135
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000136#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
137 FILE_LEVEL_DIRECTIVE SEPARATOR \
138 .globl SYMBOL_NAME(name) SEPARATOR \
139 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000140 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000141 SYMBOL_NAME(name):
142
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000143#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
144 .globl name SEPARATOR \
145 SYMBOL_IS_FUNC(name) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000146 HIDDEN(name) SEPARATOR \
Daniel Dunbaref898582010-01-18 22:19:20 +0000147 name:
148
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000149#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
150 .globl SYMBOL_NAME(name) SEPARATOR \
151 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool2678d022016-10-28 23:37:50 +0000152 DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000153 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
154
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000155#if defined(__ARM_EABI__)
156#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000157 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
158#else
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000159#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000160#endif
161
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000162#ifdef __ELF__
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000163#define END_COMPILERRT_FUNCTION(name) \
164 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000165#else
166#define END_COMPILERRT_FUNCTION(name)
167#endif
168
Daniel Dunbar7d504782009-10-27 17:49:50 +0000169#endif /* COMPILERRT_ASSEMBLY_H */