blob: 12c13c495509be9e4de865e7ef65861662bc1601 [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
99#else
100#define IT(cond)
101#define ITT(cond)
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000102#endif
103
104#if __ARM_ARCH_ISA_THUMB == 2
105#define WIDE(op) op.w
106#else
Saleem Abdulrasool3a2d6a32014-07-27 02:01:24 +0000107#define WIDE(op) op
108#endif
Weiming Zhaoa78ae8a2017-03-24 17:08:35 +0000109#endif
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000110
111#define GLUE2(a, b) a##b
Anton Korobeynikov3c519902011-04-19 21:22:14 +0000112#define GLUE(a, b) GLUE2(a, b)
113#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
114
Bob Wilsone67004e2012-02-10 16:41:46 +0000115#ifdef VISIBILITY_HIDDEN
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000116#define DECLARE_SYMBOL_VISIBILITY(name) \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000117 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
Daniel Dunbarf665b322010-01-18 22:19:34 +0000118#else
Bob Wilson66cdd222011-08-22 21:49:47 +0000119#define DECLARE_SYMBOL_VISIBILITY(name)
120#endif
121
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000122#define DEFINE_COMPILERRT_FUNCTION(name) \
123 FILE_LEVEL_DIRECTIVE SEPARATOR \
124 .globl SYMBOL_NAME(name) SEPARATOR \
125 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
126 DECLARE_SYMBOL_VISIBILITY(name) \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000127 SYMBOL_NAME(name):
128
Steven Wu84610ba2014-10-04 00:18:59 +0000129#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
130 FILE_LEVEL_DIRECTIVE SEPARATOR \
131 .globl SYMBOL_NAME(name) SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000132 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool48d4e4d2014-10-07 02:39:13 +0000133 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
Saleem Abdulrasool2cf5d822014-10-07 03:00:17 +0000134 .thumb_func SEPARATOR \
Steven Wu84610ba2014-10-04 00:18:59 +0000135 SYMBOL_NAME(name):
136
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000137#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
138 FILE_LEVEL_DIRECTIVE SEPARATOR \
139 .globl SYMBOL_NAME(name) SEPARATOR \
140 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000141 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000142 SYMBOL_NAME(name):
143
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000144#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
145 .globl name SEPARATOR \
146 SYMBOL_IS_FUNC(name) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000147 HIDDEN(name) SEPARATOR \
Daniel Dunbaref898582010-01-18 22:19:20 +0000148 name:
149
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000150#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
151 .globl SYMBOL_NAME(name) SEPARATOR \
152 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool2678d022016-10-28 23:37:50 +0000153 DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000154 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
155
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000156#if defined(__ARM_EABI__)
157#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000158 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
159#else
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000160#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000161#endif
162
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000163#ifdef __ELF__
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000164#define END_COMPILERRT_FUNCTION(name) \
165 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000166#else
167#define END_COMPILERRT_FUNCTION(name)
168#endif
169
Daniel Dunbar7d504782009-10-27 17:49:50 +0000170#endif /* COMPILERRT_ASSEMBLY_H */