blob: 5d22607f22a2dca42497f2f4fe618a223df3cfe4 [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)
Daniel Dunbar64a198d2010-01-18 22:19:25 +000031#else
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000032#define HIDDEN(name) .hidden name
Anton Korobeynikov16536102011-04-19 17:50:09 +000033#define LOCAL_LABEL(name) .L_##name
Joerg Sonnenberger197568a2014-01-14 23:31:23 +000034#define FILE_LEVEL_DIRECTIVE
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000035#if defined(__arm__)
36#define SYMBOL_IS_FUNC(name) .type name,%function
37#else
38#define SYMBOL_IS_FUNC(name) .type name,@function
39#endif
Daniel Dunbar7d504782009-10-27 17:49:50 +000040#endif
41
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000042#if defined(__arm__)
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000043#ifndef __ARM_ARCH
44#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
45 defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || \
46 defined(__ARM_ARCH_7EM__)
47#define __ARM_ARCH 7
48#endif
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000049#endif
50
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000051#ifndef __ARM_ARCH
52#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
53 defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \
54 defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6ZM__)
55#define __ARM_ARCH 6
56#endif
57#endif
58
59#ifndef __ARM_ARCH
60#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \
61 defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)
62#define __ARM_ARCH 5
63#endif
64#endif
65
66#ifndef __ARM_ARCH
67#define __ARM_ARCH 4
68#endif
69
70#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
71#define ARM_HAS_BX
72#endif
73#if !defined(__ARM_FEATURE_CLZ) && \
74 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
75#define __ARM_FEATURE_CLZ
76#endif
77
78#ifdef ARM_HAS_BX
79#define JMP(r) bx r
80#define JMPc(r, c) bx##c r
81#else
82#define JMP(r) mov pc, r
83#define JMPc(r, c) mov##c pc, r
84#endif
85#endif
86
87#define GLUE2(a, b) a##b
Anton Korobeynikov3c519902011-04-19 21:22:14 +000088#define GLUE(a, b) GLUE2(a, b)
89#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
90
Bob Wilsone67004e2012-02-10 16:41:46 +000091#ifdef VISIBILITY_HIDDEN
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000092#define DECLARE_SYMBOL_VISIBILITY(name) \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000093 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
Daniel Dunbarf665b322010-01-18 22:19:34 +000094#else
Bob Wilson66cdd222011-08-22 21:49:47 +000095#define DECLARE_SYMBOL_VISIBILITY(name)
96#endif
97
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000098#define DEFINE_COMPILERRT_FUNCTION(name) \
99 FILE_LEVEL_DIRECTIVE SEPARATOR \
100 .globl SYMBOL_NAME(name) SEPARATOR \
101 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
102 DECLARE_SYMBOL_VISIBILITY(name) \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000103 SYMBOL_NAME(name):
104
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000105#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
106 FILE_LEVEL_DIRECTIVE SEPARATOR \
107 .globl SYMBOL_NAME(name) SEPARATOR \
108 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000109 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000110 SYMBOL_NAME(name):
111
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000112#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
113 .globl name SEPARATOR \
114 SYMBOL_IS_FUNC(name) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000115 HIDDEN(name) SEPARATOR \
Daniel Dunbaref898582010-01-18 22:19:20 +0000116 name:
117
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000118#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
119 .globl SYMBOL_NAME(name) SEPARATOR \
120 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000121 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
122
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000123#if defined(__ARM_EABI__)
124#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000125 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
126#else
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000127#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000128#endif
129
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000130#ifdef __ELF__
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000131#define END_COMPILERRT_FUNCTION(name) \
132 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000133#else
134#define END_COMPILERRT_FUNCTION(name)
135#endif
136
Daniel Dunbar7d504782009-10-27 17:49:50 +0000137#endif /* COMPILERRT_ASSEMBLY_H */