blob: 2b2269cc05f47a793f8a223aa5be5915ba0e4863 [file] [log] [blame]
Saleem Abdulrasool17552662015-04-24 19:39:17 +00001/* ===-- 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
Saleem Abdulrasool17552662015-04-24 19:39:17 +000027#define GLUE2(a, b) a ## b
28#define GLUE(a, b) GLUE2(a, b)
29#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
30
31#if defined(__APPLE__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000032
Saleem Abdulrasool17552662015-04-24 19:39:17 +000033#define SYMBOL_IS_FUNC(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000034#define HIDDEN_SYMBOL(name) .private_extern name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000035#define NO_EXEC_STACK_DIRECTIVE
36
Saleem Abdulrasool17552662015-04-24 19:39:17 +000037#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000038
Saleem Abdulrasool17552662015-04-24 19:39:17 +000039#if defined(__arm__)
40#define SYMBOL_IS_FUNC(name) .type name,%function
41#else
42#define SYMBOL_IS_FUNC(name) .type name,@function
43#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +000044#define HIDDEN_SYMBOL(name) .hidden name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000045
Manoj Guptad8b79152017-05-16 20:18:57 +000046#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
47 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000048#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +000049#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000050#define NO_EXEC_STACK_DIRECTIVE
51#endif
52
Martin Storsjo6038ed32017-10-22 19:39:26 +000053#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000054
Saleem Abdulrasool17552662015-04-24 19:39:17 +000055#define SYMBOL_IS_FUNC(name) \
56 .def name SEPARATOR \
57 .scl 2 SEPARATOR \
58 .type 32 SEPARATOR \
59 .endef
Martin Storsjo6038ed32017-10-22 19:39:26 +000060#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000061
62#define NO_EXEC_STACK_DIRECTIVE
63
Martin Storsjo6038ed32017-10-22 19:39:26 +000064#else
65
66#error Unsupported target
67
Saleem Abdulrasool17552662015-04-24 19:39:17 +000068#endif
69
70#define DEFINE_LIBUNWIND_FUNCTION(name) \
71 .globl SYMBOL_NAME(name) SEPARATOR \
72 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
73 SYMBOL_NAME(name):
74
75#define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \
76 .globl SYMBOL_NAME(name) SEPARATOR \
Martin Storsjo6038ed32017-10-22 19:39:26 +000077 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool17552662015-04-24 19:39:17 +000078 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
79 SYMBOL_NAME(name):
80
81#if defined(__arm__)
82#if !defined(__ARM_ARCH)
83#define __ARM_ARCH 4
84#endif
85
86#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
87#define ARM_HAS_BX
88#endif
89
90#ifdef ARM_HAS_BX
91#define JMP(r) bx r
92#else
93#define JMP(r) mov pc, r
94#endif
95#endif /* __arm__ */
96
97#endif /* UNWIND_ASSEMBLY_H */