blob: f58def16e185c6d5a68325f28d20ce9cf8484337 [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
27#if defined(__APPLE__)
28#define HIDDEN_DIRECTIVE .private_extern
Martin Storsjo4c1f84d2017-10-11 20:06:18 +000029#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
Saleem Abdulrasool17552662015-04-24 19:39:17 +000037#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__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000046
Saleem Abdulrasool17552662015-04-24 19:39:17 +000047#define SYMBOL_IS_FUNC(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000048#define NO_EXEC_STACK_DIRECTIVE
49
Saleem Abdulrasool17552662015-04-24 19:39:17 +000050#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000051
Saleem Abdulrasool17552662015-04-24 19:39:17 +000052#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
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000057
Manoj Guptad8b79152017-05-16 20:18:57 +000058#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
59 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000060#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +000061#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000062#define NO_EXEC_STACK_DIRECTIVE
63#endif
64
65#else
66
Saleem Abdulrasool17552662015-04-24 19:39:17 +000067#define SYMBOL_IS_FUNC(name) \
68 .def name SEPARATOR \
69 .scl 2 SEPARATOR \
70 .type 32 SEPARATOR \
71 .endef
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000072
73#define NO_EXEC_STACK_DIRECTIVE
74
Saleem Abdulrasool17552662015-04-24 19:39:17 +000075#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 */