Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | //===-- sanitizer_asm.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Various support for assemebler. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | // Some toolchains do not support .cfi asm directives, so we have to hide |
| 15 | // them inside macros. |
| 16 | #if defined(__clang__) || \ |
| 17 | (defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)) |
| 18 | // GCC defined __GCC_HAVE_DWARF2_CFI_ASM if it supports CFI. |
| 19 | // Clang seems to support CFI by default (or not?). |
| 20 | // We need two versions of macros: for inline asm and standalone asm files. |
| 21 | # define CFI_INL_ADJUST_CFA_OFFSET(n) ".cfi_adjust_cfa_offset " #n ";" |
| 22 | |
| 23 | # define CFI_STARTPROC .cfi_startproc |
| 24 | # define CFI_ENDPROC .cfi_endproc |
| 25 | # define CFI_ADJUST_CFA_OFFSET(n) .cfi_adjust_cfa_offset n |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 26 | # define CFI_DEF_CFA_OFFSET(n) .cfi_def_cfa_offset n |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 27 | # define CFI_REL_OFFSET(reg, n) .cfi_rel_offset reg, n |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 28 | # define CFI_OFFSET(reg, n) .cfi_offset reg, n |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | # define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 30 | # define CFI_DEF_CFA(reg, n) .cfi_def_cfa reg, n |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | # define CFI_RESTORE(reg) .cfi_restore reg |
| 32 | |
| 33 | #else // No CFI |
| 34 | # define CFI_INL_ADJUST_CFA_OFFSET(n) |
| 35 | # define CFI_STARTPROC |
| 36 | # define CFI_ENDPROC |
| 37 | # define CFI_ADJUST_CFA_OFFSET(n) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 38 | # define CFI_DEF_CFA_OFFSET(n) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 39 | # define CFI_REL_OFFSET(reg, n) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 40 | # define CFI_OFFSET(reg, n) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 41 | # define CFI_DEF_CFA_REGISTER(reg) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 42 | # define CFI_DEF_CFA(reg, n) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 43 | # define CFI_RESTORE(reg) |
| 44 | #endif |
| 45 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 46 | #if !defined(__APPLE__) |
| 47 | # define ASM_HIDDEN(symbol) .hidden symbol |
| 48 | # define ASM_TYPE_FUNCTION(symbol) .type symbol, @function |
| 49 | # define ASM_SIZE(symbol) .size symbol, .-symbol |
| 50 | # define ASM_TSAN_SYMBOL(symbol) symbol |
| 51 | # define ASM_TSAN_SYMBOL_INTERCEPTOR(symbol) symbol |
| 52 | #else |
| 53 | # define ASM_HIDDEN(symbol) |
| 54 | # define ASM_TYPE_FUNCTION(symbol) |
| 55 | # define ASM_SIZE(symbol) |
| 56 | # define ASM_TSAN_SYMBOL(symbol) _##symbol |
| 57 | # define ASM_TSAN_SYMBOL_INTERCEPTOR(symbol) _wrap_##symbol |
| 58 | #endif |