Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 1 | /* ===-- 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 Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 27 | #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 Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 32 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 33 | #define SYMBOL_IS_FUNC(name) |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 34 | #define HIDDEN_SYMBOL(name) .private_extern name |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 35 | #define NO_EXEC_STACK_DIRECTIVE |
| 36 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 37 | #elif defined(__ELF__) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 38 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 39 | #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 Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 44 | #define HIDDEN_SYMBOL(name) .hidden name |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 45 | |
Manoj Gupta | d8b7915 | 2017-05-16 20:18:57 +0000 | [diff] [blame] | 46 | #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ |
| 47 | defined(__linux__) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 48 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 49 | #else |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 50 | #define NO_EXEC_STACK_DIRECTIVE |
| 51 | #endif |
| 52 | |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 53 | #elif defined(_WIN32) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 54 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 55 | #define SYMBOL_IS_FUNC(name) \ |
| 56 | .def name SEPARATOR \ |
| 57 | .scl 2 SEPARATOR \ |
| 58 | .type 32 SEPARATOR \ |
| 59 | .endef |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 60 | #define HIDDEN_SYMBOL(name) |
Saleem Abdulrasool | 85e5b23 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 61 | |
| 62 | #define NO_EXEC_STACK_DIRECTIVE |
| 63 | |
Martin Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 64 | #else |
| 65 | |
| 66 | #error Unsupported target |
| 67 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 68 | #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 Storsjo | 6038ed3 | 2017-10-22 19:39:26 +0000 | [diff] [blame^] | 77 | HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 78 | 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 */ |