]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libsanitizer/builtins/assembly.h
1 //===-- assembly.h - compiler-rt assembler support macros -----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines macros for use in compiler-rt assembler source.
10 // This file is not part of the interface of this library.
12 //===----------------------------------------------------------------------===//
14 #ifndef COMPILERRT_ASSEMBLY_H
15 #define COMPILERRT_ASSEMBLY_H
17 #if defined(__APPLE__) && defined(__aarch64__)
23 #if defined(__APPLE__)
24 #define HIDDEN(name) .private_extern name
25 #define LOCAL_LABEL(name) L_##name
26 // tell linker it can break up file at label boundaries
27 #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
28 #define SYMBOL_IS_FUNC(name)
29 #define CONST_SECTION .const
31 #define NO_EXEC_STACK_DIRECTIVE
33 #elif defined(__ELF__)
35 #define HIDDEN(name) .hidden name
36 #define LOCAL_LABEL(name) .L_##name
37 #define FILE_LEVEL_DIRECTIVE
38 #if defined(__arm__) || defined(__aarch64__)
39 #define SYMBOL_IS_FUNC(name) .type name,%function
41 #define SYMBOL_IS_FUNC(name) .type name,@function
43 #define CONST_SECTION .section .rodata
45 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
47 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
49 #define NO_EXEC_STACK_DIRECTIVE
52 #else // !__APPLE__ && !__ELF__
55 #define LOCAL_LABEL(name) .L ## name
56 #define FILE_LEVEL_DIRECTIVE
57 #define SYMBOL_IS_FUNC(name) \
62 #define CONST_SECTION .section .rdata,"rd"
64 #define NO_EXEC_STACK_DIRECTIVE
68 #if defined(__arm__) || defined(__aarch64__)
76 // BTI and PAC gnu property note
77 #define NT_GNU_PROPERTY_TYPE_0 5
78 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
79 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI 1
80 #define GNU_PROPERTY_AARCH64_FEATURE_1_PAC 2
82 #if defined(__ARM_FEATURE_BTI_DEFAULT)
83 #define BTI_FLAG GNU_PROPERTY_AARCH64_FEATURE_1_BTI
88 #if __ARM_FEATURE_PAC_DEFAULT & 3
89 #define PAC_FLAG GNU_PROPERTY_AARCH64_FEATURE_1_PAC
94 #define GNU_PROPERTY(type, value) \
95 .pushsection .note.gnu.property, "a" SEPARATOR \
96 .p2align 3 SEPARATOR \
99 .word NT_GNU_PROPERTY_TYPE_0 SEPARATOR \
100 .asciz "GNU" SEPARATOR \
101 .word type SEPARATOR \
103 .word value SEPARATOR \
108 #define BTI_C hint #34
109 #define BTI_J hint #36
115 #if (BTI_FLAG | PAC_FLAG) != 0
116 #define GNU_PROPERTY_BTI_PAC \
117 GNU_PROPERTY(GNU_PROPERTY_AARCH64_FEATURE_1_AND, BTI_FLAG | PAC_FLAG)
119 #define GNU_PROPERTY_BTI_PAC
122 #if defined(__clang__) || defined(__GCC_HAVE_DWARF2_CFI_ASM)
123 #define CFI_START .cfi_startproc
124 #define CFI_END .cfi_endproc
132 // Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros:
133 // - for '-mthumb -march=armv6' compiler defines '__thumb__'
134 // - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__'
135 #if defined(__thumb2__) || defined(__thumb__)
136 #define DEFINE_CODE_STATE .thumb SEPARATOR
137 #define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR
138 #if defined(__thumb2__)
140 #define IT(cond) it cond
141 #define ITT(cond) itt cond
142 #define ITE(cond) ite cond
148 #endif // defined(__thumb__2)
149 #else // !defined(__thumb2__) && !defined(__thumb__)
150 #define DEFINE_CODE_STATE .arm SEPARATOR
151 #define DECLARE_FUNC_ENCODING
157 #if defined(USE_THUMB_1) && defined(USE_THUMB_2)
158 #error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."
161 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
164 #if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \
165 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
166 #define __ARM_FEATURE_CLZ
171 #define JMPc(r, c) bx##c r
173 #define JMP(r) mov pc, r
174 #define JMPc(r, c) mov##c pc, r
177 // pop {pc} can't switch Thumb mode on ARMv4T
179 #define POP_PC() pop {pc}
186 #if defined(USE_THUMB_2)
187 #define WIDE(op) op.w
191 #else // !defined(__arm)
192 #define DECLARE_FUNC_ENCODING
193 #define DEFINE_CODE_STATE
196 #define GLUE2_(a, b) a##b
197 #define GLUE(a, b) GLUE2_(a, b)
198 #define GLUE2(a, b) GLUE2_(a, b)
199 #define GLUE3_(a, b, c) a##b##c
200 #define GLUE3(a, b, c) GLUE3_(a, b, c)
201 #define GLUE4_(a, b, c, d) a##b##c##d
202 #define GLUE4(a, b, c, d) GLUE4_(a, b, c, d)
204 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
206 #ifdef VISIBILITY_HIDDEN
207 #define DECLARE_SYMBOL_VISIBILITY(name) \
208 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
209 #define DECLARE_SYMBOL_VISIBILITY_UNMANGLED(name) \
210 HIDDEN(name) SEPARATOR
212 #define DECLARE_SYMBOL_VISIBILITY(name)
213 #define DECLARE_SYMBOL_VISIBILITY_UNMANGLED(name)
216 #define DEFINE_COMPILERRT_FUNCTION(name) \
218 FILE_LEVEL_DIRECTIVE SEPARATOR \
219 .globl SYMBOL_NAME(name) SEPARATOR \
220 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
221 DECLARE_SYMBOL_VISIBILITY(name) \
222 DECLARE_FUNC_ENCODING \
225 #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
227 FILE_LEVEL_DIRECTIVE SEPARATOR \
228 .globl SYMBOL_NAME(name) SEPARATOR \
229 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
230 DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
231 .thumb_func SEPARATOR \
234 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
236 FILE_LEVEL_DIRECTIVE SEPARATOR \
237 .globl SYMBOL_NAME(name) SEPARATOR \
238 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
239 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
240 DECLARE_FUNC_ENCODING \
243 #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
245 .globl name SEPARATOR \
246 SYMBOL_IS_FUNC(name) SEPARATOR \
247 HIDDEN(name) SEPARATOR \
248 DECLARE_FUNC_ENCODING \
251 #define DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(name) \
254 .globl name SEPARATOR \
255 SYMBOL_IS_FUNC(name) SEPARATOR \
256 DECLARE_SYMBOL_VISIBILITY_UNMANGLED(name) SEPARATOR \
257 CFI_START SEPARATOR \
258 DECLARE_FUNC_ENCODING \
259 name: SEPARATOR BTI_C
261 #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
262 .globl SYMBOL_NAME(name) SEPARATOR \
263 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
264 DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
265 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
267 #if defined(__ARM_EABI__)
268 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
269 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
271 #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
275 #define END_COMPILERRT_FUNCTION(name) \
276 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
277 #define END_COMPILERRT_OUTLINE_FUNCTION(name) \
279 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
281 #define END_COMPILERRT_FUNCTION(name)
282 #define END_COMPILERRT_OUTLINE_FUNCTION(name) \
286 #endif // COMPILERRT_ASSEMBLY_H