Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 1 | /* ===-- assembly.h - compiler-rt assembler support macros -----------------=== |
| 2 | * |
Chandler Carruth | 7a739a0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | * See https://llvm.org/LICENSE.txt for license information. |
| 5 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 6 | * |
| 7 | * ===----------------------------------------------------------------------=== |
| 8 | * |
| 9 | * This file defines macros for use in compiler-rt assembler source. |
| 10 | * This file is not part of the interface of this library. |
| 11 | * |
| 12 | * ===----------------------------------------------------------------------=== |
| 13 | */ |
| 14 | |
| 15 | #ifndef COMPILERRT_ASSEMBLY_H |
| 16 | #define COMPILERRT_ASSEMBLY_H |
| 17 | |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 18 | #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 19 | #define SEPARATOR @ |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 20 | #else |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 21 | #define SEPARATOR ; |
Daniel Dunbar | 4c01bb7 | 2010-01-18 22:19:25 +0000 | [diff] [blame] | 22 | #endif |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | 4c01bb7 | 2010-01-18 22:19:25 +0000 | [diff] [blame] | 24 | #if defined(__APPLE__) |
Saleem Abdulrasool | 81ee118 | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 25 | #define HIDDEN(name) .private_extern name |
Anton Korobeynikov | 647fc73 | 2011-04-19 17:50:09 +0000 | [diff] [blame] | 26 | #define LOCAL_LABEL(name) L_##name |
Jonathan Roelofs | 238b9fd | 2014-05-12 17:38:36 +0000 | [diff] [blame] | 27 | // tell linker it can break up file at label boundaries |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 28 | #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols |
Joerg Sonnenberger | 8a0ba55 | 2014-01-14 23:31:23 +0000 | [diff] [blame] | 29 | #define SYMBOL_IS_FUNC(name) |
Saleem Abdulrasool | 8a21df0 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 30 | #define CONST_SECTION .const |
Bob Wilson | 751f962 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 31 | |
Saleem Abdulrasool | 4c71a47 | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 32 | #define NO_EXEC_STACK_DIRECTIVE |
| 33 | |
Saleem Abdulrasool | 4040fbc | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 34 | #elif defined(__ELF__) |
Bob Wilson | 751f962 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 35 | |
Saleem Abdulrasool | 81ee118 | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 36 | #define HIDDEN(name) .hidden name |
Anton Korobeynikov | 647fc73 | 2011-04-19 17:50:09 +0000 | [diff] [blame] | 37 | #define LOCAL_LABEL(name) .L_##name |
Joerg Sonnenberger | 8a0ba55 | 2014-01-14 23:31:23 +0000 | [diff] [blame] | 38 | #define FILE_LEVEL_DIRECTIVE |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 39 | #if defined(__arm__) |
| 40 | #define SYMBOL_IS_FUNC(name) .type name,%function |
| 41 | #else |
| 42 | #define SYMBOL_IS_FUNC(name) .type name,@function |
| 43 | #endif |
Saleem Abdulrasool | 8a21df0 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 44 | #define CONST_SECTION .section .rodata |
Bob Wilson | 751f962 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 45 | |
Manoj Gupta | 0bbb557 | 2017-05-15 23:13:54 +0000 | [diff] [blame] | 46 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
| 47 | defined(__linux__) |
Saleem Abdulrasool | 4c71a47 | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 48 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
| 49 | #else |
| 50 | #define NO_EXEC_STACK_DIRECTIVE |
| 51 | #endif |
| 52 | |
Bob Wilson | 751f962 | 2014-10-04 20:11:10 +0000 | [diff] [blame] | 53 | #else // !__APPLE__ && !__ELF__ |
| 54 | |
Saleem Abdulrasool | 8a21df0 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 55 | #define HIDDEN(name) |
Saleem Abdulrasool | 4040fbc | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 56 | #define LOCAL_LABEL(name) .L ## name |
Saleem Abdulrasool | d87d6b7 | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 57 | #define FILE_LEVEL_DIRECTIVE |
Saleem Abdulrasool | 4040fbc | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 58 | #define SYMBOL_IS_FUNC(name) \ |
| 59 | .def name SEPARATOR \ |
Saleem Abdulrasool | 56d7431 | 2014-06-21 01:41:21 +0000 | [diff] [blame] | 60 | .scl 2 SEPARATOR \ |
Saleem Abdulrasool | 4040fbc | 2014-05-18 18:39:15 +0000 | [diff] [blame] | 61 | .type 32 SEPARATOR \ |
| 62 | .endef |
Saleem Abdulrasool | 8a21df0 | 2014-12-10 02:36:22 +0000 | [diff] [blame] | 63 | #define CONST_SECTION .section .rdata,"rd" |
Saleem Abdulrasool | d87d6b7 | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 64 | |
Saleem Abdulrasool | 4c71a47 | 2016-06-22 22:09:42 +0000 | [diff] [blame] | 65 | #define NO_EXEC_STACK_DIRECTIVE |
| 66 | |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
Joerg Sonnenberger | 734059a | 2014-01-24 13:39:51 +0000 | [diff] [blame] | 69 | #if defined(__arm__) |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros: |
| 73 | * - for '-mthumb -march=armv6' compiler defines '__thumb__' |
| 74 | * - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__' |
| 75 | */ |
| 76 | #if defined(__thumb2__) || defined(__thumb__) |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 77 | #define DEFINE_CODE_STATE .thumb SEPARATOR |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 78 | #define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR |
| 79 | #if defined(__thumb2__) |
| 80 | #define USE_THUMB_2 |
| 81 | #define IT(cond) it cond |
| 82 | #define ITT(cond) itt cond |
| 83 | #define ITE(cond) ite cond |
| 84 | #else |
| 85 | #define USE_THUMB_1 |
| 86 | #define IT(cond) |
| 87 | #define ITT(cond) |
| 88 | #define ITE(cond) |
| 89 | #endif // defined(__thumb__2) |
| 90 | #else // !defined(__thumb2__) && !defined(__thumb__) |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 91 | #define DEFINE_CODE_STATE .arm SEPARATOR |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 92 | #define DECLARE_FUNC_ENCODING |
| 93 | #define IT(cond) |
| 94 | #define ITT(cond) |
| 95 | #define ITE(cond) |
| 96 | #endif |
| 97 | |
| 98 | #if defined(USE_THUMB_1) && defined(USE_THUMB_2) |
| 99 | #error "USE_THUMB_1 and USE_THUMB_2 can't be defined together." |
| 100 | #endif |
| 101 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 102 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
| 103 | #define ARM_HAS_BX |
| 104 | #endif |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 105 | #if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \ |
Weiming Zhao | 86a022a | 2016-12-07 18:41:07 +0000 | [diff] [blame] | 106 | (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__))) |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 107 | #define __ARM_FEATURE_CLZ |
| 108 | #endif |
| 109 | |
| 110 | #ifdef ARM_HAS_BX |
| 111 | #define JMP(r) bx r |
Joerg Sonnenberger | 344b05d | 2014-07-20 20:00:26 +0000 | [diff] [blame] | 112 | #define JMPc(r, c) bx##c r |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 113 | #else |
| 114 | #define JMP(r) mov pc, r |
| 115 | #define JMPc(r, c) mov##c pc, r |
| 116 | #endif |
Saleem Abdulrasool | 57c07d8 | 2014-07-27 02:01:20 +0000 | [diff] [blame] | 117 | |
Josh Gao | 8a444fa | 2015-08-21 00:25:37 +0000 | [diff] [blame] | 118 | // pop {pc} can't switch Thumb mode on ARMv4T |
| 119 | #if __ARM_ARCH >= 5 |
| 120 | #define POP_PC() pop {pc} |
| 121 | #else |
| 122 | #define POP_PC() \ |
| 123 | pop {ip}; \ |
| 124 | JMP(ip) |
| 125 | #endif |
| 126 | |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 127 | #if defined(USE_THUMB_2) |
Weiming Zhao | 9736f90 | 2017-03-24 17:08:35 +0000 | [diff] [blame] | 128 | #define WIDE(op) op.w |
| 129 | #else |
Saleem Abdulrasool | 69ddd1d | 2014-07-27 02:01:24 +0000 | [diff] [blame] | 130 | #define WIDE(op) op |
| 131 | #endif |
Weiming Zhao | 6a52c89 | 2017-08-14 21:44:33 +0000 | [diff] [blame] | 132 | #else // !defined(__arm) |
| 133 | #define DECLARE_FUNC_ENCODING |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 134 | #define DEFINE_CODE_STATE |
Weiming Zhao | 9736f90 | 2017-03-24 17:08:35 +0000 | [diff] [blame] | 135 | #endif |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 136 | |
| 137 | #define GLUE2(a, b) a##b |
Anton Korobeynikov | e294935 | 2011-04-19 21:22:14 +0000 | [diff] [blame] | 138 | #define GLUE(a, b) GLUE2(a, b) |
| 139 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
| 140 | |
Bob Wilson | 36c2425 | 2012-02-10 16:41:46 +0000 | [diff] [blame] | 141 | #ifdef VISIBILITY_HIDDEN |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 142 | #define DECLARE_SYMBOL_VISIBILITY(name) \ |
Saleem Abdulrasool | 81ee118 | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 143 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR |
Daniel Dunbar | 6a571fb | 2010-01-18 22:19:34 +0000 | [diff] [blame] | 144 | #else |
Bob Wilson | 41ae71d | 2011-08-22 21:49:47 +0000 | [diff] [blame] | 145 | #define DECLARE_SYMBOL_VISIBILITY(name) |
| 146 | #endif |
| 147 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 148 | #define DEFINE_COMPILERRT_FUNCTION(name) \ |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 149 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 150 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 151 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 152 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 153 | DECLARE_SYMBOL_VISIBILITY(name) \ |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 154 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 155 | SYMBOL_NAME(name): |
| 156 | |
Steven Wu | 1dcfa4d | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 157 | #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 158 | DEFINE_CODE_STATE \ |
Steven Wu | 1dcfa4d | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 159 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 160 | .globl SYMBOL_NAME(name) SEPARATOR \ |
Steven Wu | 1dcfa4d | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 161 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | d87d6b7 | 2014-10-07 02:39:13 +0000 | [diff] [blame] | 162 | DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ |
Saleem Abdulrasool | 11d42c1 | 2014-10-07 03:00:17 +0000 | [diff] [blame] | 163 | .thumb_func SEPARATOR \ |
Steven Wu | 1dcfa4d | 2014-10-04 00:18:59 +0000 | [diff] [blame] | 164 | SYMBOL_NAME(name): |
| 165 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 166 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 167 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 168 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 169 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 170 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | 81ee118 | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 171 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 172 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 173 | SYMBOL_NAME(name): |
| 174 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 175 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ |
Manoj Gupta | 4ce970d | 2017-10-02 20:56:49 +0000 | [diff] [blame] | 176 | DEFINE_CODE_STATE \ |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 177 | .globl name SEPARATOR \ |
| 178 | SYMBOL_IS_FUNC(name) SEPARATOR \ |
Saleem Abdulrasool | 81ee118 | 2014-05-18 18:39:10 +0000 | [diff] [blame] | 179 | HIDDEN(name) SEPARATOR \ |
Weiming Zhao | 4ae44f4 | 2017-08-14 20:48:47 +0000 | [diff] [blame] | 180 | DECLARE_FUNC_ENCODING \ |
Daniel Dunbar | e136da9 | 2010-01-18 22:19:20 +0000 | [diff] [blame] | 181 | name: |
| 182 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 183 | #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ |
| 184 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 185 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | b11de00 | 2016-10-28 23:37:50 +0000 | [diff] [blame] | 186 | DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \ |
Anton Korobeynikov | 37b97d1 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 187 | .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR |
| 188 | |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 189 | #if defined(__ARM_EABI__) |
| 190 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ |
Anton Korobeynikov | 37b97d1 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 191 | DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) |
| 192 | #else |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 193 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) |
Anton Korobeynikov | 37b97d1 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 194 | #endif |
| 195 | |
Joerg Sonnenberger | c16ed3d | 2014-01-23 18:31:46 +0000 | [diff] [blame] | 196 | #ifdef __ELF__ |
Saleem Abdulrasool | 5f81c70 | 2014-05-16 06:16:21 +0000 | [diff] [blame] | 197 | #define END_COMPILERRT_FUNCTION(name) \ |
| 198 | .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) |
Joerg Sonnenberger | c16ed3d | 2014-01-23 18:31:46 +0000 | [diff] [blame] | 199 | #else |
| 200 | #define END_COMPILERRT_FUNCTION(name) |
| 201 | #endif |
| 202 | |
Daniel Dunbar | 19336a2 | 2009-10-27 17:49:50 +0000 | [diff] [blame] | 203 | #endif /* COMPILERRT_ASSEMBLY_H */ |