Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame^] | 1 | /* ===-- assembly.h - compiler-rt assembler support macros -----------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
| 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
| 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 | |
| 19 | #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) |
| 20 | #define SEPARATOR @ |
| 21 | #else |
| 22 | #define SEPARATOR ; |
| 23 | #endif |
| 24 | |
| 25 | #if defined(__APPLE__) |
| 26 | #define HIDDEN(name) .private_extern name |
| 27 | #define LOCAL_LABEL(name) L_##name |
| 28 | // tell linker it can break up file at label boundaries |
| 29 | #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols |
| 30 | #define SYMBOL_IS_FUNC(name) |
| 31 | #define CONST_SECTION .const |
| 32 | |
| 33 | #define NO_EXEC_STACK_DIRECTIVE |
| 34 | |
| 35 | #elif defined(__ELF__) |
| 36 | |
| 37 | #define HIDDEN(name) .hidden name |
| 38 | #define LOCAL_LABEL(name) .L_##name |
| 39 | #define FILE_LEVEL_DIRECTIVE |
| 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 |
| 45 | #define CONST_SECTION .section .rodata |
| 46 | |
| 47 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
| 48 | defined(__linux__) |
| 49 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
| 50 | #else |
| 51 | #define NO_EXEC_STACK_DIRECTIVE |
| 52 | #endif |
| 53 | |
| 54 | #else // !__APPLE__ && !__ELF__ |
| 55 | |
| 56 | #define HIDDEN(name) |
| 57 | #define LOCAL_LABEL(name) .L ## name |
| 58 | #define FILE_LEVEL_DIRECTIVE |
| 59 | #define SYMBOL_IS_FUNC(name) \ |
| 60 | .def name SEPARATOR \ |
| 61 | .scl 2 SEPARATOR \ |
| 62 | .type 32 SEPARATOR \ |
| 63 | .endef |
| 64 | #define CONST_SECTION .section .rdata,"rd" |
| 65 | |
| 66 | #define NO_EXEC_STACK_DIRECTIVE |
| 67 | |
| 68 | #endif |
| 69 | |
| 70 | #if defined(__arm__) |
| 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__) |
| 78 | #define DEFINE_CODE_STATE .thumb SEPARATOR |
| 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__) |
| 92 | #define DEFINE_CODE_STATE .arm SEPARATOR |
| 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 | |
| 103 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
| 104 | #define ARM_HAS_BX |
| 105 | #endif |
| 106 | #if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \ |
| 107 | (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__))) |
| 108 | #define __ARM_FEATURE_CLZ |
| 109 | #endif |
| 110 | |
| 111 | #ifdef ARM_HAS_BX |
| 112 | #define JMP(r) bx r |
| 113 | #define JMPc(r, c) bx##c r |
| 114 | #else |
| 115 | #define JMP(r) mov pc, r |
| 116 | #define JMPc(r, c) mov##c pc, r |
| 117 | #endif |
| 118 | |
| 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 | |
| 128 | #if defined(USE_THUMB_2) |
| 129 | #define WIDE(op) op.w |
| 130 | #else |
| 131 | #define WIDE(op) op |
| 132 | #endif |
| 133 | #else // !defined(__arm) |
| 134 | #define DECLARE_FUNC_ENCODING |
| 135 | #define DEFINE_CODE_STATE |
| 136 | #endif |
| 137 | |
| 138 | #define GLUE2(a, b) a##b |
| 139 | #define GLUE(a, b) GLUE2(a, b) |
| 140 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
| 141 | |
| 142 | #ifdef VISIBILITY_HIDDEN |
| 143 | #define DECLARE_SYMBOL_VISIBILITY(name) \ |
| 144 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR |
| 145 | #else |
| 146 | #define DECLARE_SYMBOL_VISIBILITY(name) |
| 147 | #endif |
| 148 | |
| 149 | #define DEFINE_COMPILERRT_FUNCTION(name) \ |
| 150 | DEFINE_CODE_STATE \ |
| 151 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 152 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 153 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 154 | DECLARE_SYMBOL_VISIBILITY(name) \ |
| 155 | DECLARE_FUNC_ENCODING \ |
| 156 | SYMBOL_NAME(name): |
| 157 | |
| 158 | #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ |
| 159 | DEFINE_CODE_STATE \ |
| 160 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 161 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 162 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 163 | DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ |
| 164 | .thumb_func SEPARATOR \ |
| 165 | SYMBOL_NAME(name): |
| 166 | |
| 167 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ |
| 168 | DEFINE_CODE_STATE \ |
| 169 | FILE_LEVEL_DIRECTIVE SEPARATOR \ |
| 170 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 171 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 172 | HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ |
| 173 | DECLARE_FUNC_ENCODING \ |
| 174 | SYMBOL_NAME(name): |
| 175 | |
| 176 | #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ |
| 177 | DEFINE_CODE_STATE \ |
| 178 | .globl name SEPARATOR \ |
| 179 | SYMBOL_IS_FUNC(name) SEPARATOR \ |
| 180 | HIDDEN(name) SEPARATOR \ |
| 181 | DECLARE_FUNC_ENCODING \ |
| 182 | name: |
| 183 | |
| 184 | #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ |
| 185 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 186 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 187 | DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \ |
| 188 | .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR |
| 189 | |
| 190 | #if defined(__ARM_EABI__) |
| 191 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ |
| 192 | DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) |
| 193 | #else |
| 194 | #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) |
| 195 | #endif |
| 196 | |
| 197 | #ifdef __ELF__ |
| 198 | #define END_COMPILERRT_FUNCTION(name) \ |
| 199 | .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) |
| 200 | #else |
| 201 | #define END_COMPILERRT_FUNCTION(name) |
| 202 | #endif |
| 203 | |
| 204 | #endif /* COMPILERRT_ASSEMBLY_H */ |