blob: 606cf2c92b312a5d850865312f83739f79d07cfc [file] [log] [blame]
Saleem Abdulrasool17552662015-04-24 19:39:17 +00001/* ===-- assembly.h - libUnwind assembler support macros -------------------===
2 *
Chandler Carruth61860a52019-01-19 10:56:40 +00003 * 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
Saleem Abdulrasool17552662015-04-24 19:39:17 +00006 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file defines macros for use in libUnwind assembler source.
10 * This file is not part of the interface of this library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
14
15#ifndef UNWIND_ASSEMBLY_H
16#define UNWIND_ASSEMBLY_H
17
Martin Storsjo8338b0a2018-01-02 22:11:30 +000018#if defined(__powerpc64__)
19#define SEPARATOR ;
Martin Storsjo6518fcb2018-01-16 20:54:10 +000020#define PPC64_OFFS_SRR0 0
21#define PPC64_OFFS_CR 272
22#define PPC64_OFFS_XER 280
23#define PPC64_OFFS_LR 288
24#define PPC64_OFFS_CTR 296
25#define PPC64_OFFS_VRSAVE 304
26#define PPC64_OFFS_FP 312
27#define PPC64_OFFS_V 824
28#ifdef _ARCH_PWR8
29#define PPC64_HAS_VMX
30#endif
Martin Storsjo8338b0a2018-01-02 22:11:30 +000031#elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000032#define SEPARATOR @
33#elif defined(__arm64__)
34#define SEPARATOR %%
35#else
36#define SEPARATOR ;
37#endif
38
Saleem Abdulrasool17552662015-04-24 19:39:17 +000039#define GLUE2(a, b) a ## b
40#define GLUE(a, b) GLUE2(a, b)
41#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
42
43#if defined(__APPLE__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000044
Saleem Abdulrasool17552662015-04-24 19:39:17 +000045#define SYMBOL_IS_FUNC(name)
Charles Davisc5094702018-08-31 18:11:48 +000046#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000047#define HIDDEN_SYMBOL(name) .private_extern name
Petr Hosek9bbfad52019-04-03 21:50:03 +000048#define WEAK_SYMBOL(name) .weak_reference name
49#define WEAK_ALIAS(name, aliasname) \
50 WEAK_SYMBOL(aliasname) SEPARATOR \
51 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
52
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000053#define NO_EXEC_STACK_DIRECTIVE
54
Saleem Abdulrasool17552662015-04-24 19:39:17 +000055#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000056
Saleem Abdulrasool17552662015-04-24 19:39:17 +000057#if defined(__arm__)
58#define SYMBOL_IS_FUNC(name) .type name,%function
59#else
60#define SYMBOL_IS_FUNC(name) .type name,@function
61#endif
Charles Davisc5094702018-08-31 18:11:48 +000062#define EXPORT_SYMBOL(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000063#define HIDDEN_SYMBOL(name) .hidden name
Petr Hosek9bbfad52019-04-03 21:50:03 +000064#define WEAK_SYMBOL(name) .weak name
65#define WEAK_ALIAS(name, aliasname) \
66 WEAK_SYMBOL(aliasname) SEPARATOR \
67 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000068
Manoj Guptad8b79152017-05-16 20:18:57 +000069#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
70 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000071#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +000072#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000073#define NO_EXEC_STACK_DIRECTIVE
74#endif
75
Martin Storsjo6038ed32017-10-22 19:39:26 +000076#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000077
Saleem Abdulrasool17552662015-04-24 19:39:17 +000078#define SYMBOL_IS_FUNC(name) \
79 .def name SEPARATOR \
80 .scl 2 SEPARATOR \
81 .type 32 SEPARATOR \
82 .endef
Petr Hosek9bbfad52019-04-03 21:50:03 +000083#define EXPORT_SYMBOL2(name) \
84 .section .drectve,"yn" SEPARATOR \
85 .ascii "-export:", #name, "\0" SEPARATOR \
Charles Davisc5094702018-08-31 18:11:48 +000086 .text
Martin Storsjocf47ba62018-12-11 07:34:14 +000087#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
88#define EXPORT_SYMBOL(name)
89#else
Charles Davisc5094702018-08-31 18:11:48 +000090#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
Martin Storsjocf47ba62018-12-11 07:34:14 +000091#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +000092#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000093
Petr Hosek9bbfad52019-04-03 21:50:03 +000094#if defined(__MINGW32__)
95#define WEAK_ALIAS(name, aliasname) \
96 .globl SYMBOL_NAME(aliasname) SEPARATOR \
97 EXPORT_SYMBOL(aliasname) SEPARATOR \
98 SYMBOL_NAME(aliasname) = SYMBOL_NAME(name)
99#else
100#define WEAK_ALIAS3(name, aliasname) \
101 .section .drectve,"yn" SEPARATOR \
102 .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \
103 .text
104#define WEAK_ALIAS2(name, aliasname) \
105 WEAK_ALIAS3(name, aliasname)
106#define WEAK_ALIAS(name, aliasname) \
107 EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \
108 WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname))
109#endif
110
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +0000111#define NO_EXEC_STACK_DIRECTIVE
112
Daniel Cederman9f2f07a2019-01-14 10:15:20 +0000113#elif defined(__sparc__)
114
Martin Storsjo6038ed32017-10-22 19:39:26 +0000115#else
116
117#error Unsupported target
118
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000119#endif
120
Petr Hosek9bbfad52019-04-03 21:50:03 +0000121#define DEFINE_LIBUNWIND_FUNCTION(name) \
122 .globl SYMBOL_NAME(name) SEPARATOR \
123 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
124 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000125 SYMBOL_NAME(name):
126
127#if defined(__arm__)
128#if !defined(__ARM_ARCH)
129#define __ARM_ARCH 4
130#endif
131
132#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
133#define ARM_HAS_BX
134#endif
135
136#ifdef ARM_HAS_BX
137#define JMP(r) bx r
138#else
139#define JMP(r) mov pc, r
140#endif
141#endif /* __arm__ */
142
143#endif /* UNWIND_ASSEMBLY_H */