Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 1 | /* ===-- assembly.h - compiler-rt assembler support macros -----------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 19 | #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 20 | #define SEPARATOR @ |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 21 | #else |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 22 | #define SEPARATOR ; |
Daniel Dunbar | 64a198d | 2010-01-18 22:19:25 +0000 | [diff] [blame] | 23 | #endif |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 64a198d | 2010-01-18 22:19:25 +0000 | [diff] [blame] | 25 | #if defined(__APPLE__) |
Saleem Abdulrasool | 9a614bd | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 26 | #define HIDDEN(name) .private_extern name |
Anton Korobeynikov | 1653610 | 2011-04-19 17:50:09 +0000 | [diff] [blame] | 27 | #define LOCAL_LABEL(name) L_##name |
Jonathan Roelofs | b351c1a | 2014-05-12 17:38:36 +0000 | [diff] [blame] | 28 | // tell linker it can break up file at label boundaries |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 29 | #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols |
Joerg Sonnenberger | 197568a | 2014-01-14 23:31:23 +0000 | [diff] [blame] | 30 | #define SYMBOL_IS_FUNC(name) |
Saleem Abdulrasool | 1fe0c18 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 31 | #define CONST_SECTION .const |
Bob Wilson | 11554746 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 32 | |
Saleem Abdulrasool | 590e85b | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 33 | #define NO_EXEC_STACK_DIRECTIVE |
| 34 | |
Saleem Abdulrasool | dd9b034 | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 35 | #elif defined(__ELF__) |
Bob Wilson | 11554746 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 36 | |
Saleem Abdulrasool | 9a614bd | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 37 | #define HIDDEN(name) .hidden name |
Anton Korobeynikov | 1653610 | 2011-04-19 17:50:09 +0000 | [diff] [blame] | 38 | #define LOCAL_LABEL(name) .L_##name |
Joerg Sonnenberger | 197568a | 2014-01-14 23:31:23 +0000 | [diff] [blame] | 39 | #define FILE_LEVEL_DIRECTIVE |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 40 | #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 Abdulrasool | 1fe0c18 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 45 | #define CONST_SECTION .section .rodata |
Bob Wilson | 11554746 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 46 | |
Manoj Gupta | 2361a39 | 2017-05-15 23:13:54 +0000 | [diff] [blame] | 47 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
| 48 | defined(__linux__) |
Saleem Abdulrasool | 590e85b | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 49 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
| 50 | #else |
| 51 | #define NO_EXEC_STACK_DIRECTIVE |
| 52 | #endif |
| 53 | |
Bob Wilson | 11554746 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 54 | #else // !__APPLE__ && !__ELF__ |
| 55 | |
Saleem Abdulrasool | 1fe0c18 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 56 | #define HIDDEN(name) |
Saleem Abdulrasool | dd9b034 | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 57 | #define LOCAL_LABEL(name) .L ## name |
Saleem Abdulrasool | 48d4e4d | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 58 | #define FILE_LEVEL_DIRECTIVE |
Saleem Abdulrasool | dd9b034 | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 59 | #define SYMBOL_IS_FUNC(name) \ |
| 60 | .def name SEPARATOR \ |
Saleem Abdulrasool | d0d1638 | 2014-06-21 01:41:21 +0000 | [diff] [blame] | 61 | .scl 2 SEPARATOR \ |
Saleem Abdulrasool | dd9b034 | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 62 | .type 32 SEPARATOR \ |
| 63 | .endef |
Saleem Abdulrasool | 1fe0c18 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 64 | #define CONST_SECTION .section .rdata,"rd" |
Saleem Abdulrasool | 48d4e4d | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 65 | |
Saleem Abdulrasool | 590e85b | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 66 | #define NO_EXEC_STACK_DIRECTIVE |
| 67 | |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
Joerg Sonnenberger | 1f8cb3e | 2014-01-24 13:39:51 +0000 | [diff] [blame] | 70 | #if defined(__arm__) |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros: |
| 74 | * - for '-mthumb -march=armv6' compiler defines '__thumb__' |
| 75 | * - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__' |
| 76 | */ |
| 77 | #if defined(__thumb2__) || defined(__thumb__) |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 78 | #define DEFINE_CODE_STATE .thumb SEPARATOR |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 79 | #define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR |
| 80 | #if defined(__thumb2__) |
| 81 | #define USE_THUMB_2 |
| 82 | #define IT(cond) it cond |
| 83 | #define ITT(cond) itt cond |
| 84 | #define ITE(cond) ite cond |
| 85 | #else |
| 86 | #define USE_THUMB_1 |
| 87 | #define IT(cond) |
| 88 | #define ITT(cond) |
| 89 | #define ITE(cond) |
| 90 | #endif // defined(__thumb__2) |
| 91 | #else // !defined(__thumb2__) && !defined(__thumb__) |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 92 | #define DEFINE_CODE_STATE .arm SEPARATOR |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 93 | #define DECLARE_FUNC_ENCODING |
| 94 | #define IT(cond) |
| 95 | #define ITT(cond) |
| 96 | #define ITE(cond) |
| 97 | #endif |
| 98 | |
| 99 | #if defined(USE_THUMB_1) && defined(USE_THUMB_2) |
| 100 | #error "USE_THUMB_1 and USE_THUMB_2 can't be defined together." |
| 101 | #endif |
| 102 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 103 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
| 104 | #define ARM_HAS_BX |
| 105 | #endif |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 106 | #if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \ |
Weiming Zhao | a913f7d | 2016-12-07 18:41:07 +0000 | [diff] [blame] | 107 | (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__))) |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 108 | #define __ARM_FEATURE_CLZ |
| 109 | #endif |
| 110 | |
| 111 | #ifdef ARM_HAS_BX |
| 112 | #define JMP(r) bx r |
Joerg Sonnenberger | 8f6cf70 | 2014-07-20 20:00:26 +0000 | [diff] [blame] | 113 | #define JMPc(r, c) bx##c r |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 114 | #else |
| 115 | #define JMP(r) mov pc, r |
| 116 | #define JMPc(r, c) mov##c pc, r |
| 117 | #endif |
Saleem Abdulrasool | b6690c3 | 2014-07-27 02:01:20 +0000 | [diff] [blame] | 118 | |
Josh Gao | 1108ae0 | 2015-08-21 00:25:37 +0000 | [diff] [blame] | 119 | // pop {pc} can't switch Thumb mode on ARMv4T |
| 120 | #if __ARM_ARCH >= 5 |
| 121 | #define POP_PC() pop {pc} |
| 122 | #else |
| 123 | #define POP_PC() \ |
| 124 | pop {ip}; \ |
| 125 | JMP(ip) |
| 126 | #endif |
| 127 | |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 128 | #if defined(USE_THUMB_2) |
Weiming Zhao | a78ae8a | 2017-03-24 17:08:35 +0000 | [diff] [blame] | 129 | #define WIDE(op) op.w |
| 130 | #else |
Saleem Abdulrasool | 3a2d6a3 | 2014-07-27 02:01:24 +0000 | [diff] [blame] | 131 | #define WIDE(op) op |
| 132 | #endif |
Weiming Zhao | 1c617be | 2017-08-14 21:44:33 +0000 | [diff] [blame] | 133 | #else // !defined(__arm) |
| 134 | #define DECLARE_FUNC_ENCODING |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 135 | #define DEFINE_CODE_STATE |
Weiming Zhao | a78ae8a | 2017-03-24 17:08:35 +0000 | [diff] [blame] | 136 | #endif |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 137 | |
| 138 | #define GLUE2(a, b) a##b |
Anton Korobeynikov | 3c51990 | 2011-04-19 21:22:14 +0000 | [diff] [blame] | 139 | #define GLUE(a, b) GLUE2(a, b) |
| 140 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
| 141 | |
Bob Wilson | e67004e | 2012-02-10 16:41:46 +0000 | [diff] [blame] | 142 | #ifdef VISIBILITY_HIDDEN |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 143 | #define DECLARE_SYMBOL_VISIBILITY(name) \ |
Saleem Abdulrasool | 9a614bd | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 144 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR |
Daniel Dunbar | f665b32 | 2010-01-18 22:19:34 +0000 | [diff] [blame] | 145 | #else |
Bob Wilson | 66cdd22 | 2011-08-22 21:49:47 +0000 | [diff] [blame] | 146 | #define DECLARE_SYMBOL_VISIBILITY(name) |
| 147 | #endif |
| 148 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 149 | #define DEFINE_COMPILERRT_FUNCTION(name) \ |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 150 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 151 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 152 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 153 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 154 | DECLARE_SYMBOL_VISIBILITY(name) \ |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 155 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 156 | SYMBOL_NAME(name): |
| 157 | |
Steven Wu | 84610ba | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 158 | #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 159 | DEFINE_CODE_STATE \ |
Steven Wu | 84610ba | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 160 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 161 | .globl SYMBOL_NAME(name) SEPARATOR \ |
Steven Wu | 84610ba | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 162 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | 48d4e4d | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 163 | DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ |
Saleem Abdulrasool | 2cf5d82 | 2014-10-07 03:00:17 +0000 | [diff] [blame] | 164 | .thumb_func SEPARATOR \ |
Steven Wu | 84610ba | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 165 | SYMBOL_NAME(name): |
| 166 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 167 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 168 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 169 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 170 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 171 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | 9a614bd | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 172 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 173 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 174 | SYMBOL_NAME(name): |
| 175 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 176 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ |
Manoj Gupta | e2ff2ba | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 177 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 178 | .globl name SEPARATOR \ |
| 179 | SYMBOL_IS_FUNC(name) SEPARATOR \ |
Saleem Abdulrasool | 9a614bd | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 180 | HIDDEN(name) SEPARATOR \ |
Weiming Zhao | 8bf1572 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 181 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | ef89858 | 2010-01-18 22:19:20 +0000 | [diff] [blame] | 182 | name: |
| 183 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 184 | #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ |
| 185 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 186 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | 2678d02 | 2016-10-28 23:37:50 +0000 | [diff] [blame] | 187 | DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \ |
Anton Korobeynikov | 75e3c19 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 188 | .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR |
| 189 | |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 190 | #if defined(__ARM_EABI__) |
| 191 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ |
Anton Korobeynikov | 75e3c19 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 192 | DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) |
| 193 | #else |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 194 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) |
Anton Korobeynikov | 75e3c19 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
Joerg Sonnenberger | 25468a2a | 2014-01-23 18:31:46 +0000 | [diff] [blame] | 197 | #ifdef __ELF__ |
Saleem Abdulrasool | da2c2ce | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 198 | #define END_COMPILERRT_FUNCTION(name) \ |
| 199 | .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) |
Joerg Sonnenberger | 25468a2a | 2014-01-23 18:31:46 +0000 | [diff] [blame] | 200 | #else |
| 201 | #define END_COMPILERRT_FUNCTION(name) |
| 202 | #endif |
| 203 | |
Daniel Dunbar | 7d50478 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 204 | #endif /* COMPILERRT_ASSEMBLY_H */ |