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 #elif defined(__ELF__) 34 35 #define HIDDEN(name) .hidden name 36 #define LOCAL_LABEL(name) .L_##name 37 #define FILE_LEVEL_DIRECTIVE 38 #if defined(__arm__) 39 #define SYMBOL_IS_FUNC(name) .type name,%function 40 #else 41 #define SYMBOL_IS_FUNC(name) .type name,@function 42 #endif 43 #define CONST_SECTION .section .rodata 44 45 #else // !__APPLE__ && !__ELF__ 46 47 #define HIDDEN(name) 48 #define LOCAL_LABEL(name) .L ## name 49 #define FILE_LEVEL_DIRECTIVE 50 #define SYMBOL_IS_FUNC(name) \ 51 .def name SEPARATOR \ 52 .scl 2 SEPARATOR \ 53 .type 32 SEPARATOR \ 54 .endef 55 #define CONST_SECTION .section .rdata,"rd" 56 57 #endif 58 59 #if defined(__arm__) 60 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 61 #define ARM_HAS_BX 62 #endif 63 #if !defined(__ARM_FEATURE_CLZ) && \ 64 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__))) 65 #define __ARM_FEATURE_CLZ 66 #endif 67 68 #ifdef ARM_HAS_BX 69 #define JMP(r) bx r 70 #define JMPc(r, c) bx##c r 71 #else 72 #define JMP(r) mov pc, r 73 #define JMPc(r, c) mov##c pc, r 74 #endif 75 76 #if __ARM_ARCH_ISA_THUMB == 2 77 #define IT(cond) it cond 78 #define ITT(cond) itt cond 79 #else 80 #define IT(cond) 81 #define ITT(cond) 82 #endif 83 84 #if __ARM_ARCH_ISA_THUMB == 2 85 #define WIDE(op) op.w 86 #else 87 #define WIDE(op) op 88 #endif 89 #endif 90 91 #define GLUE2(a, b) a##b 92 #define GLUE(a, b) GLUE2(a, b) 93 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) 94 95 #ifdef VISIBILITY_HIDDEN 96 #define DECLARE_SYMBOL_VISIBILITY(name) \ 97 HIDDEN(SYMBOL_NAME(name)) SEPARATOR 98 #else 99 #define DECLARE_SYMBOL_VISIBILITY(name) 100 #endif 101 102 #define DEFINE_COMPILERRT_FUNCTION(name) \ 103 FILE_LEVEL_DIRECTIVE SEPARATOR \ 104 .globl SYMBOL_NAME(name) SEPARATOR \ 105 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 106 DECLARE_SYMBOL_VISIBILITY(name) \ 107 SYMBOL_NAME(name): 108 109 #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ 110 FILE_LEVEL_DIRECTIVE SEPARATOR \ 111 .globl SYMBOL_NAME(name) SEPARATOR \ 112 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 113 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ 114 .thumb_func SEPARATOR \ 115 SYMBOL_NAME(name): 116 117 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ 118 FILE_LEVEL_DIRECTIVE SEPARATOR \ 119 .globl SYMBOL_NAME(name) SEPARATOR \ 120 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 121 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ 122 SYMBOL_NAME(name): 123 124 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ 125 .globl name SEPARATOR \ 126 SYMBOL_IS_FUNC(name) SEPARATOR \ 127 HIDDEN(name) SEPARATOR \ 128 name: 129 130 #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ 131 .globl SYMBOL_NAME(name) SEPARATOR \ 132 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 133 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR 134 135 #if defined(__ARM_EABI__) 136 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ 137 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) 138 #else 139 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) 140 #endif 141 142 #ifdef __ELF__ 143 #define END_COMPILERRT_FUNCTION(name) \ 144 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) 145 #else 146 #define END_COMPILERRT_FUNCTION(name) 147 #endif 148 149 #endif /* COMPILERRT_ASSEMBLY_H */ 150