blob: b15da52345c804f29ea1c751c28dc4152bb052dc [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 Gupta2361a392017-05-15 23:13:54 +000047#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
48 defined(__linux__)
Saleem Abdulrasool590e85b2016-06-22 22:09:42 +000049#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
50#else
51#define NO_EXEC_STACK_DIRECTIVE
52#endif
53
Bob Wilson115547462014-10-04 20:11:10 +000054#else // !__APPLE__ && !__ELF__
55
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000056#define HIDDEN(name)
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000057#define LOCAL_LABEL(name) .L ## name
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +000058#define FILE_LEVEL_DIRECTIVE
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000059#define SYMBOL_IS_FUNC(name) \
60 .def name SEPARATOR \
Saleem Abdulrasoold0d16382014-06-21 01:41:21 +000061 .scl 2 SEPARATOR \
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000062 .type 32 SEPARATOR \
63 .endef
Saleem Abdulrasool1fe0c182014-12-10 02:36:22 +000064#define CONST_SECTION .section .rdata,"rd"
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +000065
Saleem Abdulrasool590e85b2016-06-22 22:09:42 +000066#define NO_EXEC_STACK_DIRECTIVE
67
Daniel Dunbar7d504782009-10-27 17:49:50 +000068#endif
69
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000070#if defined(__arm__)
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000071#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
72#define ARM_HAS_BX
73#endif
Weiming Zhaoa913f7d2016-12-07 18:41:07 +000074#if !defined(__ARM_FEATURE_CLZ) && __ARM_ARCH_ISA_THUMB != 1 && \
75 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000076#define __ARM_FEATURE_CLZ
77#endif
78
79#ifdef ARM_HAS_BX
80#define JMP(r) bx r
Joerg Sonnenberger8f6cf702014-07-20 20:00:26 +000081#define JMPc(r, c) bx##c r
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000082#else
83#define JMP(r) mov pc, r
84#define JMPc(r, c) mov##c pc, r
85#endif
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +000086
Josh Gao1108ae02015-08-21 00:25:37 +000087// pop {pc} can't switch Thumb mode on ARMv4T
88#if __ARM_ARCH >= 5
89#define POP_PC() pop {pc}
90#else
91#define POP_PC() \
92 pop {ip}; \
93 JMP(ip)
94#endif
95
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +000096#if __ARM_ARCH_ISA_THUMB == 2
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +000097#define IT(cond) it cond
98#define ITT(cond) itt cond
Jonathan Roelofsdc62b802017-05-24 15:53:24 +000099#define ITE(cond) ite cond
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +0000100#else
101#define IT(cond)
102#define ITT(cond)
Jonathan Roelofsdc62b802017-05-24 15:53:24 +0000103#define ITE(cond)
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000104#endif
105
106#if __ARM_ARCH_ISA_THUMB == 2
107#define WIDE(op) op.w
108#else
Saleem Abdulrasool3a2d6a32014-07-27 02:01:24 +0000109#define WIDE(op) op
110#endif
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000111#endif
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000112
113#define GLUE2(a, b) a##b
Anton Korobeynikov3c519902011-04-19 21:22:14 +0000114#define GLUE(a, b) GLUE2(a, b)
115#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
116
Bob Wilsone67004e2012-02-10 16:41:46 +0000117#ifdef VISIBILITY_HIDDEN
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000118#define DECLARE_SYMBOL_VISIBILITY(name) \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000119 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
Daniel Dunbarf665b322010-01-18 22:19:34 +0000120#else
Bob Wilson66cdd222011-08-22 21:49:47 +0000121#define DECLARE_SYMBOL_VISIBILITY(name)
122#endif
123
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000124#define DEFINE_COMPILERRT_FUNCTION(name) \
125 FILE_LEVEL_DIRECTIVE SEPARATOR \
126 .globl SYMBOL_NAME(name) SEPARATOR \
127 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
128 DECLARE_SYMBOL_VISIBILITY(name) \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000129 SYMBOL_NAME(name):
130
Steven Wu84610ba2014-10-04 00:18:59 +0000131#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
132 FILE_LEVEL_DIRECTIVE SEPARATOR \
133 .globl SYMBOL_NAME(name) SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000134 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +0000135 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
Saleem Abdulrasool2cf5d822014-10-07 03:00:17 +0000136 .thumb_func SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000137 SYMBOL_NAME(name):
138
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000139#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
140 FILE_LEVEL_DIRECTIVE SEPARATOR \
141 .globl SYMBOL_NAME(name) SEPARATOR \
142 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000143 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000144 SYMBOL_NAME(name):
145
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000146#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
147 .globl name SEPARATOR \
148 SYMBOL_IS_FUNC(name) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000149 HIDDEN(name) SEPARATOR \
Daniel Dunbaref898582010-01-18 22:19:20 +0000150 name:
151
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000152#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
153 .globl SYMBOL_NAME(name) SEPARATOR \
154 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool2678d022016-10-28 23:37:50 +0000155 DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000156 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
157
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000158#if defined(__ARM_EABI__)
159#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000160 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
161#else
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000162#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000163#endif
164
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000165#ifdef __ELF__
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000166#define END_COMPILERRT_FUNCTION(name) \
167 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000168#else
169#define END_COMPILERRT_FUNCTION(name)
170#endif
171
Daniel Dunbar7d504782009-10-27 17:49:50 +0000172#endif /* COMPILERRT_ASSEMBLY_H */