Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 1 | /* ===-- assembly.h - libUnwind assembler support macros -------------------=== |
| 2 | * |
Chandler Carruth | 61860a5 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | * 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 Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 6 | * |
| 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 Storsjo | 8338b0a | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 18 | #if defined(__powerpc64__) |
| 19 | #define SEPARATOR ; |
Martin Storsjo | 6518fcb | 2018-01-16 20:54:10 +0000 | [diff] [blame] | 20 | #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 Storsjo | 8338b0a | 2018-01-02 22:11:30 +0000 | [diff] [blame] | 31 | #elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 32 | #define SEPARATOR @ |
| 33 | #elif defined(__arm64__) |
| 34 | #define SEPARATOR %% |
| 35 | #else |
| 36 | #define SEPARATOR ; |
| 37 | #endif |
| 38 | |
Martin Storsjo | 8a6fc69 | 2019-05-16 06:49:13 +0000 | [diff] [blame^] | 39 | #if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1) |
| 40 | #define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR |
| 41 | #define PPC64_OPD2 SEPARATOR \ |
| 42 | .p2align 3 SEPARATOR \ |
| 43 | .quad .Lfunc_begin0 SEPARATOR \ |
| 44 | .quad .TOC.@tocbase SEPARATOR \ |
| 45 | .quad 0 SEPARATOR \ |
| 46 | .text SEPARATOR \ |
| 47 | .Lfunc_begin0: |
| 48 | #else |
| 49 | #define PPC64_OPD1 |
| 50 | #define PPC64_OPD2 |
| 51 | #endif |
| 52 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 53 | #define GLUE2(a, b) a ## b |
| 54 | #define GLUE(a, b) GLUE2(a, b) |
| 55 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
| 56 | |
| 57 | #if defined(__APPLE__) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 58 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 59 | #define SYMBOL_IS_FUNC(name) |
Charles Davis | c509470 | 2018-08-31 18:11:48 +0000 | [diff] [blame] | 60 | #define EXPORT_SYMBOL(name) |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame] | 61 | #define HIDDEN_SYMBOL(name) .private_extern name |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 62 | #define WEAK_SYMBOL(name) .weak_reference name |
| 63 | #define WEAK_ALIAS(name, aliasname) \ |
Petr Hosek | 2ec9ffc | 2019-04-04 03:36:35 +0000 | [diff] [blame] | 64 | .globl SYMBOL_NAME(aliasname) SEPARATOR \ |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 65 | WEAK_SYMBOL(aliasname) SEPARATOR \ |
| 66 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
| 67 | |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 68 | #define NO_EXEC_STACK_DIRECTIVE |
| 69 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 70 | #elif defined(__ELF__) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 71 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 72 | #if defined(__arm__) |
| 73 | #define SYMBOL_IS_FUNC(name) .type name,%function |
| 74 | #else |
| 75 | #define SYMBOL_IS_FUNC(name) .type name,@function |
| 76 | #endif |
Charles Davis | c509470 | 2018-08-31 18:11:48 +0000 | [diff] [blame] | 77 | #define EXPORT_SYMBOL(name) |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame] | 78 | #define HIDDEN_SYMBOL(name) .hidden name |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 79 | #define WEAK_SYMBOL(name) .weak name |
| 80 | #define WEAK_ALIAS(name, aliasname) \ |
| 81 | WEAK_SYMBOL(aliasname) SEPARATOR \ |
| 82 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 83 | |
Manoj Gupta | d8b7915 | 2017-05-16 20:18:57 +0000 | [diff] [blame] | 84 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
| 85 | defined(__linux__) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 86 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 87 | #else |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 88 | #define NO_EXEC_STACK_DIRECTIVE |
| 89 | #endif |
| 90 | |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame] | 91 | #elif defined(_WIN32) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 92 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 93 | #define SYMBOL_IS_FUNC(name) \ |
| 94 | .def name SEPARATOR \ |
| 95 | .scl 2 SEPARATOR \ |
| 96 | .type 32 SEPARATOR \ |
| 97 | .endef |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 98 | #define EXPORT_SYMBOL2(name) \ |
| 99 | .section .drectve,"yn" SEPARATOR \ |
| 100 | .ascii "-export:", #name, "\0" SEPARATOR \ |
Charles Davis | c509470 | 2018-08-31 18:11:48 +0000 | [diff] [blame] | 101 | .text |
Martin Storsjo | cf47ba6 | 2018-12-11 07:34:14 +0000 | [diff] [blame] | 102 | #if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS) |
| 103 | #define EXPORT_SYMBOL(name) |
| 104 | #else |
Charles Davis | c509470 | 2018-08-31 18:11:48 +0000 | [diff] [blame] | 105 | #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) |
Martin Storsjo | cf47ba6 | 2018-12-11 07:34:14 +0000 | [diff] [blame] | 106 | #endif |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame] | 107 | #define HIDDEN_SYMBOL(name) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 108 | |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 109 | #if defined(__MINGW32__) |
| 110 | #define WEAK_ALIAS(name, aliasname) \ |
| 111 | .globl SYMBOL_NAME(aliasname) SEPARATOR \ |
| 112 | EXPORT_SYMBOL(aliasname) SEPARATOR \ |
| 113 | SYMBOL_NAME(aliasname) = SYMBOL_NAME(name) |
| 114 | #else |
| 115 | #define WEAK_ALIAS3(name, aliasname) \ |
| 116 | .section .drectve,"yn" SEPARATOR \ |
| 117 | .ascii "-alternatename:", #aliasname, "=", #name, "\0" SEPARATOR \ |
| 118 | .text |
| 119 | #define WEAK_ALIAS2(name, aliasname) \ |
| 120 | WEAK_ALIAS3(name, aliasname) |
| 121 | #define WEAK_ALIAS(name, aliasname) \ |
| 122 | EXPORT_SYMBOL(SYMBOL_NAME(aliasname)) SEPARATOR \ |
| 123 | WEAK_ALIAS2(SYMBOL_NAME(name), SYMBOL_NAME(aliasname)) |
| 124 | #endif |
| 125 | |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 126 | #define NO_EXEC_STACK_DIRECTIVE |
| 127 | |
Daniel Cederman | 9f2f07a | 2019-01-14 10:15:20 +0000 | [diff] [blame] | 128 | #elif defined(__sparc__) |
| 129 | |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame] | 130 | #else |
| 131 | |
| 132 | #error Unsupported target |
| 133 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 136 | #define DEFINE_LIBUNWIND_FUNCTION(name) \ |
| 137 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 138 | HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ |
| 139 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
Martin Storsjo | 8a6fc69 | 2019-05-16 06:49:13 +0000 | [diff] [blame^] | 140 | PPC64_OPD1 \ |
| 141 | SYMBOL_NAME(name): \ |
| 142 | PPC64_OPD2 |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 143 | |
| 144 | #if defined(__arm__) |
| 145 | #if !defined(__ARM_ARCH) |
| 146 | #define __ARM_ARCH 4 |
| 147 | #endif |
| 148 | |
| 149 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
| 150 | #define ARM_HAS_BX |
| 151 | #endif |
| 152 | |
| 153 | #ifdef ARM_HAS_BX |
| 154 | #define JMP(r) bx r |
| 155 | #else |
| 156 | #define JMP(r) mov pc, r |
| 157 | #endif |
| 158 | #endif /* __arm__ */ |
| 159 | |
| 160 | #endif /* UNWIND_ASSEMBLY_H */ |