Saleem Abdulrasool | 675df58 | 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 | |
| 27 | #if defined(__APPLE__) |
| 28 | #define HIDDEN_DIRECTIVE .private_extern |
| 29 | #else |
| 30 | #define HIDDEN_DIRECTIVE .hidden |
| 31 | #endif |
| 32 | |
| 33 | #define GLUE2(a, b) a ## b |
| 34 | #define GLUE(a, b) GLUE2(a, b) |
| 35 | #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) |
| 36 | |
| 37 | #if defined(__APPLE__) |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 38 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 39 | #define SYMBOL_IS_FUNC(name) |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 40 | #define NO_EXEC_STACK_DIRECTIVE |
| 41 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 42 | #elif defined(__ELF__) |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 43 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 44 | #if defined(__arm__) |
| 45 | #define SYMBOL_IS_FUNC(name) .type name,%function |
| 46 | #else |
| 47 | #define SYMBOL_IS_FUNC(name) .type name,@function |
| 48 | #endif |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 49 | |
Petr Hosek | a60a2d5 | 2016-10-23 21:48:47 +0000 | [diff] [blame^] | 50 | #if defined(__GNU__) || defined(__ANDROID__) || defined(__FreeBSD__) || \ |
| 51 | defined(__Fuchsia__) |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 52 | #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 53 | #else |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 54 | #define NO_EXEC_STACK_DIRECTIVE |
| 55 | #endif |
| 56 | |
| 57 | #else |
| 58 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 59 | #define SYMBOL_IS_FUNC(name) \ |
| 60 | .def name SEPARATOR \ |
| 61 | .scl 2 SEPARATOR \ |
| 62 | .type 32 SEPARATOR \ |
| 63 | .endef |
Saleem Abdulrasool | 6a38e34 | 2016-08-05 21:35:28 +0000 | [diff] [blame] | 64 | |
| 65 | #define NO_EXEC_STACK_DIRECTIVE |
| 66 | |
Saleem Abdulrasool | 675df58 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | #define DEFINE_LIBUNWIND_FUNCTION(name) \ |
| 70 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 71 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 72 | SYMBOL_NAME(name): |
| 73 | |
| 74 | #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ |
| 75 | .globl SYMBOL_NAME(name) SEPARATOR \ |
| 76 | HIDDEN_DIRECTIVE SYMBOL_NAME(name) SEPARATOR \ |
| 77 | SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ |
| 78 | SYMBOL_NAME(name): |
| 79 | |
| 80 | #if defined(__arm__) |
| 81 | #if !defined(__ARM_ARCH) |
| 82 | #define __ARM_ARCH 4 |
| 83 | #endif |
| 84 | |
| 85 | #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 |
| 86 | #define ARM_HAS_BX |
| 87 | #endif |
| 88 | |
| 89 | #ifdef ARM_HAS_BX |
| 90 | #define JMP(r) bx r |
| 91 | #else |
| 92 | #define JMP(r) mov pc, r |
| 93 | #endif |
| 94 | #endif /* __arm__ */ |
| 95 | |
| 96 | #endif /* UNWIND_ASSEMBLY_H */ |