1 /* ===-- assembly.h - libUnwind 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 libUnwind assembler source.
11  * This file is not part of the interface of this library.
12  *
13  * ===----------------------------------------------------------------------===
14  */
15 
16 #ifndef UNWIND_ASSEMBLY_H
17 #define UNWIND_ASSEMBLY_H
18 
19 #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
20 #define SEPARATOR @
21 #elif defined(__arm64__)
22 #define SEPARATOR %%
23 #else
24 #define SEPARATOR ;
25 #endif
26 
27 #if defined(__APPLE__)
28 #define HIDDEN_DIRECTIVE .private_extern
29 #elif defined(_WIN32)
30 // In the COFF object file format, there's no attributes for a global,
31 // non-static symbol to make it somehow hidden. So on windows, we don't
32 // want to set this at all. To avoid conditionals in
33 // DEFINE_LIBUNWIND_PRIVATE_FUNCTION below, make it .globl (which it already
34 // is, defined in the same DEFINE_LIBUNWIND_PRIVATE_FUNCTION macro; the
35 // duplicate .globl directives are harmless).
36 #define HIDDEN_DIRECTIVE .globl
37 #else
38 #define HIDDEN_DIRECTIVE .hidden
39 #endif
40 
41 #define GLUE2(a, b) a ## b
42 #define GLUE(a, b) GLUE2(a, b)
43 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
44 
45 #if defined(__APPLE__)
46 
47 #define SYMBOL_IS_FUNC(name)
48 #define NO_EXEC_STACK_DIRECTIVE
49 
50 #elif defined(__ELF__)
51 
52 #if defined(__arm__)
53 #define SYMBOL_IS_FUNC(name) .type name,%function
54 #else
55 #define SYMBOL_IS_FUNC(name) .type name,@function
56 #endif
57 
58 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
59     defined(__linux__)
60 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
61 #else
62 #define NO_EXEC_STACK_DIRECTIVE
63 #endif
64 
65 #else
66 
67 #define SYMBOL_IS_FUNC(name)                                                   \
68   .def name SEPARATOR                                                          \
69     .scl 2 SEPARATOR                                                           \
70     .type 32 SEPARATOR                                                         \
71   .endef
72 
73 #define NO_EXEC_STACK_DIRECTIVE
74 
75 #endif
76 
77 #define DEFINE_LIBUNWIND_FUNCTION(name)                   \
78   .globl SYMBOL_NAME(name) SEPARATOR                      \
79   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR             \
80   SYMBOL_NAME(name):
81 
82 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)           \
83   .globl SYMBOL_NAME(name) SEPARATOR                      \
84   HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR            \
85   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR             \
86   SYMBOL_NAME(name):
87 
88 #if defined(__arm__)
89 #if !defined(__ARM_ARCH)
90 #define __ARM_ARCH 4
91 #endif
92 
93 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
94 #define ARM_HAS_BX
95 #endif
96 
97 #ifdef ARM_HAS_BX
98 #define JMP(r) bx r
99 #else
100 #define JMP(r) mov pc, r
101 #endif
102 #endif /* __arm__ */
103 
104 #endif /* UNWIND_ASSEMBLY_H */
105