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(__ANDROID__) || defined(__FreeBSD__) 48 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits 49 #else 50 #define NO_EXEC_STACK_DIRECTIVE 51 #endif 52 53 #else // !__APPLE__ && !__ELF__ 54 55 #define HIDDEN(name) 56 #define LOCAL_LABEL(name) .L ## name 57 #define FILE_LEVEL_DIRECTIVE 58 #define SYMBOL_IS_FUNC(name) \ 59 .def name SEPARATOR \ 60 .scl 2 SEPARATOR \ 61 .type 32 SEPARATOR \ 62 .endef 63 #define CONST_SECTION .section .rdata,"rd" 64 65 #define NO_EXEC_STACK_DIRECTIVE 66 67 #endif 68 69 #if defined(__arm__) 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 86 // pop {pc} can't switch Thumb mode on ARMv4T 87 #if __ARM_ARCH >= 5 88 #define POP_PC() pop {pc} 89 #else 90 #define POP_PC() \ 91 pop {ip}; \ 92 JMP(ip) 93 #endif 94 95 #if __ARM_ARCH_ISA_THUMB == 2 96 #define IT(cond) it cond 97 #define ITT(cond) itt cond 98 #else 99 #define IT(cond) 100 #define ITT(cond) 101 #endif 102 103 #if __ARM_ARCH_ISA_THUMB == 2 104 #define WIDE(op) op.w 105 #else 106 #define WIDE(op) op 107 #endif 108 #endif 109 110 #define GLUE2(a, b) a##b 111 #define GLUE(a, b) GLUE2(a, b) 112 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) 113 114 #ifdef VISIBILITY_HIDDEN 115 #define DECLARE_SYMBOL_VISIBILITY(name) \ 116 HIDDEN(SYMBOL_NAME(name)) SEPARATOR 117 #else 118 #define DECLARE_SYMBOL_VISIBILITY(name) 119 #endif 120 121 #define DEFINE_COMPILERRT_FUNCTION(name) \ 122 FILE_LEVEL_DIRECTIVE SEPARATOR \ 123 .globl SYMBOL_NAME(name) SEPARATOR \ 124 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 125 DECLARE_SYMBOL_VISIBILITY(name) \ 126 SYMBOL_NAME(name): 127 128 #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ 129 FILE_LEVEL_DIRECTIVE SEPARATOR \ 130 .globl SYMBOL_NAME(name) SEPARATOR \ 131 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 132 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ 133 .thumb_func SEPARATOR \ 134 SYMBOL_NAME(name): 135 136 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ 137 FILE_LEVEL_DIRECTIVE SEPARATOR \ 138 .globl SYMBOL_NAME(name) SEPARATOR \ 139 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 140 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ 141 SYMBOL_NAME(name): 142 143 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ 144 .globl name SEPARATOR \ 145 SYMBOL_IS_FUNC(name) SEPARATOR \ 146 HIDDEN(name) SEPARATOR \ 147 name: 148 149 #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ 150 .globl SYMBOL_NAME(name) SEPARATOR \ 151 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 152 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR 153 154 #if defined(__ARM_EABI__) 155 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ 156 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) 157 #else 158 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) 159 #endif 160 161 #ifdef __ELF__ 162 #define END_COMPILERRT_FUNCTION(name) \ 163 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) 164 #else 165 #define END_COMPILERRT_FUNCTION(name) 166 #endif 167 168 #endif /* COMPILERRT_ASSEMBLY_H */ 169