Path: blob/master/libs/compiler-rt/lib/builtins/assembly.h
4395 views
/* ===-- assembly.h - compiler-rt assembler support macros -----------------===1*2* The LLVM Compiler Infrastructure3*4* This file is dual licensed under the MIT and the University of Illinois Open5* Source Licenses. See LICENSE.TXT for details.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*/1415#ifndef COMPILERRT_ASSEMBLY_H16#define COMPILERRT_ASSEMBLY_H1718#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)19#define SEPARATOR @20#else21#define SEPARATOR ;22#endif2324#if defined(__APPLE__)25#define HIDDEN(name) .private_extern name26#define LOCAL_LABEL(name) L_##name27// tell linker it can break up file at label boundaries28#define FILE_LEVEL_DIRECTIVE .subsections_via_symbols29#define SYMBOL_IS_FUNC(name)30#define CONST_SECTION .const3132#define NO_EXEC_STACK_DIRECTIVE3334#elif defined(__ELF__)3536#define HIDDEN(name) .hidden name37#define LOCAL_LABEL(name) .L_##name38#define FILE_LEVEL_DIRECTIVE39#if defined(__arm__)40#define SYMBOL_IS_FUNC(name) .type name,%function41#else42#define SYMBOL_IS_FUNC(name) .type name,@function43#endif44#define CONST_SECTION .section .rodata4546#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \47defined(__linux__)48#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits49#else50#define NO_EXEC_STACK_DIRECTIVE51#endif5253#else // !__APPLE__ && !__ELF__5455#define HIDDEN(name)56#define LOCAL_LABEL(name) .L ## name57#define FILE_LEVEL_DIRECTIVE58#define SYMBOL_IS_FUNC(name) \59.def name SEPARATOR \60.scl 2 SEPARATOR \61.type 32 SEPARATOR \62.endef63#define CONST_SECTION .section .rdata,"rd"6465#define NO_EXEC_STACK_DIRECTIVE6667#endif6869#if defined(__arm__)7071/*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__)77#define DEFINE_CODE_STATE .thumb SEPARATOR78#define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR79#if defined(__thumb2__)80#define USE_THUMB_281#define IT(cond) it cond82#define ITT(cond) itt cond83#define ITE(cond) ite cond84#else85#define USE_THUMB_186#define IT(cond)87#define ITT(cond)88#define ITE(cond)89#endif // defined(__thumb__2)90#else // !defined(__thumb2__) && !defined(__thumb__)91#define DEFINE_CODE_STATE .arm SEPARATOR92#define DECLARE_FUNC_ENCODING93#define IT(cond)94#define ITT(cond)95#define ITE(cond)96#endif9798#if defined(USE_THUMB_1) && defined(USE_THUMB_2)99#error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."100#endif101102#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5103#define ARM_HAS_BX104#endif105#if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \106(__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))107#define __ARM_FEATURE_CLZ108#endif109110#ifdef ARM_HAS_BX111#define JMP(r) bx r112#define JMPc(r, c) bx##c r113#else114#define JMP(r) mov pc, r115#define JMPc(r, c) mov##c pc, r116#endif117118// pop {pc} can't switch Thumb mode on ARMv4T119#if __ARM_ARCH >= 5120#define POP_PC() pop {pc}121#else122#define POP_PC() \123pop {ip}; \124JMP(ip)125#endif126127#if defined(USE_THUMB_2)128#define WIDE(op) op.w129#else130#define WIDE(op) op131#endif132#else // !defined(__arm)133#define DECLARE_FUNC_ENCODING134#define DEFINE_CODE_STATE135#endif136137#define GLUE2(a, b) a##b138#define GLUE(a, b) GLUE2(a, b)139#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)140141#ifdef VISIBILITY_HIDDEN142#define DECLARE_SYMBOL_VISIBILITY(name) \143HIDDEN(SYMBOL_NAME(name)) SEPARATOR144#else145#define DECLARE_SYMBOL_VISIBILITY(name)146#endif147148#define DEFINE_COMPILERRT_FUNCTION(name) \149DEFINE_CODE_STATE \150FILE_LEVEL_DIRECTIVE SEPARATOR \151.globl SYMBOL_NAME(name) SEPARATOR \152SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \153DECLARE_SYMBOL_VISIBILITY(name) \154DECLARE_FUNC_ENCODING \155SYMBOL_NAME(name):156157#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \158DEFINE_CODE_STATE \159FILE_LEVEL_DIRECTIVE SEPARATOR \160.globl SYMBOL_NAME(name) SEPARATOR \161SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \162DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \163.thumb_func SEPARATOR \164SYMBOL_NAME(name):165166#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \167DEFINE_CODE_STATE \168FILE_LEVEL_DIRECTIVE SEPARATOR \169.globl SYMBOL_NAME(name) SEPARATOR \170SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \171HIDDEN(SYMBOL_NAME(name)) SEPARATOR \172DECLARE_FUNC_ENCODING \173SYMBOL_NAME(name):174175#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \176DEFINE_CODE_STATE \177.globl name SEPARATOR \178SYMBOL_IS_FUNC(name) SEPARATOR \179HIDDEN(name) SEPARATOR \180DECLARE_FUNC_ENCODING \181name:182183#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \184.globl SYMBOL_NAME(name) SEPARATOR \185SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \186DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \187.set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR188189#if defined(__ARM_EABI__)190#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \191DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)192#else193#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)194#endif195196#ifdef __ELF__197#define END_COMPILERRT_FUNCTION(name) \198.size SYMBOL_NAME(name), . - SYMBOL_NAME(name)199#else200#define END_COMPILERRT_FUNCTION(name)201#endif202203#endif /* COMPILERRT_ASSEMBLY_H */204205206