llvm/compiler-rt/lib/builtins/assembly.h

//===-- assembly.h - compiler-rt assembler support macros -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines macros for use in compiler-rt assembler source.
// This file is not part of the interface of this library.
//
//===----------------------------------------------------------------------===//

#ifndef COMPILERRT_ASSEMBLY_H
#define COMPILERRT_ASSEMBLY_H

#if defined(__linux__) && defined(__CET__)
#if __has_include(<cet.h>)
#include <cet.h>
#endif
#endif

#if defined(__APPLE__) && defined(__aarch64__)
#define SEPARATOR
#else
#define SEPARATOR
#endif

#if defined(__APPLE__)
#define HIDDEN
#define LOCAL_LABEL
// tell linker it can break up file at label boundaries
#define FILE_LEVEL_DIRECTIVE
#define SYMBOL_IS_FUNC
#define CONST_SECTION

#define NO_EXEC_STACK_DIRECTIVE

#elif defined(__ELF__)

#define HIDDEN(name)
#define LOCAL_LABEL(name)
#define FILE_LEVEL_DIRECTIVE
#if defined(__arm__) || defined(__aarch64__)
#define SYMBOL_IS_FUNC
#else
#define SYMBOL_IS_FUNC(name)
#endif
#define CONST_SECTION

#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) ||        \
    defined(__linux__)
#define NO_EXEC_STACK_DIRECTIVE
#else
#define NO_EXEC_STACK_DIRECTIVE
#endif

#else // !__APPLE__ && !__ELF__

#define HIDDEN
#define LOCAL_LABEL
#define FILE_LEVEL_DIRECTIVE
#define SYMBOL_IS_FUNC
#define CONST_SECTION

#define NO_EXEC_STACK_DIRECTIVE

#endif

#if defined(__arm__) || defined(__aarch64__)
#define FUNC_ALIGN
#else
#define FUNC_ALIGN
#endif

// BTI and PAC gnu property note
#define NT_GNU_PROPERTY_TYPE_0
#define GNU_PROPERTY_AARCH64_FEATURE_1_AND
#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI
#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC

#if defined(__ARM_FEATURE_BTI_DEFAULT)
#define BTI_FLAG
#else
#define BTI_FLAG
#endif

#if __ARM_FEATURE_PAC_DEFAULT & 3
#define PAC_FLAG
#else
#define PAC_FLAG
#endif

#define GNU_PROPERTY(type, value)

#if BTI_FLAG != 0
#define BTI_C
#define BTI_J
#else
#define BTI_C
#define BTI_J
#endif

#if (BTI_FLAG | PAC_FLAG) != 0
#define GNU_PROPERTY_BTI_PAC
#else
#define GNU_PROPERTY_BTI_PAC
#endif

#if defined(__clang__) || defined(__GCC_HAVE_DWARF2_CFI_ASM)
#define CFI_START
#define CFI_END
#else
#define CFI_START
#define CFI_END
#endif

#if defined(__arm__)

// Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros:
// - for '-mthumb -march=armv6' compiler defines '__thumb__'
// - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__'
#if defined(__thumb2__) || defined(__thumb__)
#define DEFINE_CODE_STATE
#define DECLARE_FUNC_ENCODING
#if defined(__thumb2__)
#define USE_THUMB_2
#define IT
#define ITT
#define ITE
#else
#define USE_THUMB_1
#define IT
#define ITT
#define ITE
#endif // defined(__thumb__2)
#else // !defined(__thumb2__) && !defined(__thumb__)
#define DEFINE_CODE_STATE
#define DECLARE_FUNC_ENCODING
#define IT
#define ITT
#define ITE
#endif

#if defined(USE_THUMB_1) && defined(USE_THUMB_2)
#error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."
#endif

#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
#define ARM_HAS_BX
#endif
#if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) &&  \
    (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
#define __ARM_FEATURE_CLZ
#endif

#ifdef ARM_HAS_BX
#define JMP
#define JMPc
#else
#define JMP
#define JMPc
#endif

// pop {pc} can't switch Thumb mode on ARMv4T
#if __ARM_ARCH >= 5
#define POP_PC
#else
#define POP_PC
#endif

#if defined(USE_THUMB_2)
#define WIDE
#else
#define WIDE
#endif
#else // !defined(__arm)
#define DECLARE_FUNC_ENCODING
#define DEFINE_CODE_STATE
#endif

#define GLUE2_(a, b)
#define GLUE(a, b)
#define GLUE2(a, b)
#define GLUE3_(a, b, c)
#define GLUE3(a, b, c)
#define GLUE4_(a, b, c, d)
#define GLUE4(a, b, c, d)

#define SYMBOL_NAME(name)

#ifdef VISIBILITY_HIDDEN
#define DECLARE_SYMBOL_VISIBILITY(name)
#define DECLARE_SYMBOL_VISIBILITY_UNMANGLED(name)
#else
#define DECLARE_SYMBOL_VISIBILITY
#define DECLARE_SYMBOL_VISIBILITY_UNMANGLED
#endif

#define DEFINE_COMPILERRT_FUNCTION(name)

#define DEFINE_COMPILERRT_THUMB_FUNCTION(name)

#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name)

#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name)

#define DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(name)

#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target)

#if defined(__ARM_EABI__)
#define DEFINE_AEABI_FUNCTION_ALIAS
#else
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
#endif

#ifdef __ELF__
#define END_COMPILERRT_FUNCTION(name)
#define END_COMPILERRT_OUTLINE_FUNCTION(name)
#else
#define END_COMPILERRT_FUNCTION
#define END_COMPILERRT_OUTLINE_FUNCTION
#endif

#endif // COMPILERRT_ASSEMBLY_H