blob: ba099cbe809e02e53ff81e977f377282213d9335 [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
Martin Storsjo8338b0a2018-01-02 22:11:30 +000019#if defined(__powerpc64__)
20#define SEPARATOR ;
21#elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000022#define SEPARATOR @
23#elif defined(__arm64__)
24#define SEPARATOR %%
25#else
26#define SEPARATOR ;
27#endif
28
Saleem Abdulrasool17552662015-04-24 19:39:17 +000029#define GLUE2(a, b) a ## b
30#define GLUE(a, b) GLUE2(a, b)
31#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
32
33#if defined(__APPLE__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000034
Saleem Abdulrasool17552662015-04-24 19:39:17 +000035#define SYMBOL_IS_FUNC(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000036#define HIDDEN_SYMBOL(name) .private_extern name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000037#define NO_EXEC_STACK_DIRECTIVE
38
Saleem Abdulrasool17552662015-04-24 19:39:17 +000039#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000040
Saleem Abdulrasool17552662015-04-24 19:39:17 +000041#if defined(__arm__)
42#define SYMBOL_IS_FUNC(name) .type name,%function
43#else
44#define SYMBOL_IS_FUNC(name) .type name,@function
45#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +000046#define HIDDEN_SYMBOL(name) .hidden name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000047
Manoj Guptad8b79152017-05-16 20:18:57 +000048#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
49 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000050#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +000051#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000052#define NO_EXEC_STACK_DIRECTIVE
53#endif
54
Martin Storsjo6038ed32017-10-22 19:39:26 +000055#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000056
Saleem Abdulrasool17552662015-04-24 19:39:17 +000057#define SYMBOL_IS_FUNC(name) \
58 .def name SEPARATOR \
59 .scl 2 SEPARATOR \
60 .type 32 SEPARATOR \
61 .endef
Martin Storsjo6038ed32017-10-22 19:39:26 +000062#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000063
64#define NO_EXEC_STACK_DIRECTIVE
65
Martin Storsjo6038ed32017-10-22 19:39:26 +000066#else
67
68#error Unsupported target
69
Saleem Abdulrasool17552662015-04-24 19:39:17 +000070#endif
71
72#define DEFINE_LIBUNWIND_FUNCTION(name) \
73 .globl SYMBOL_NAME(name) SEPARATOR \
74 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
75 SYMBOL_NAME(name):
76
77#define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \
78 .globl SYMBOL_NAME(name) SEPARATOR \
Martin Storsjo6038ed32017-10-22 19:39:26 +000079 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool17552662015-04-24 19:39:17 +000080 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
81 SYMBOL_NAME(name):
82
83#if defined(__arm__)
84#if !defined(__ARM_ARCH)
85#define __ARM_ARCH 4
86#endif
87
88#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
89#define ARM_HAS_BX
90#endif
91
92#ifdef ARM_HAS_BX
93#define JMP(r) bx r
94#else
95#define JMP(r) mov pc, r
96#endif
97#endif /* __arm__ */
98
99#endif /* UNWIND_ASSEMBLY_H */