sanitizer_asm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //===-- sanitizer_asm.h -----------------------------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Various support for assembler.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. // Some toolchains do not support .cfi asm directives, so we have to hide
  13. // them inside macros.
  14. #if defined(__clang__) || \
  15. (defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM))
  16. // GCC defined __GCC_HAVE_DWARF2_CFI_ASM if it supports CFI.
  17. // Clang seems to support CFI by default (or not?).
  18. // We need two versions of macros: for inline asm and standalone asm files.
  19. # define CFI_INL_ADJUST_CFA_OFFSET(n) ".cfi_adjust_cfa_offset " #n ";"
  20. # define CFI_STARTPROC .cfi_startproc
  21. # define CFI_ENDPROC .cfi_endproc
  22. # define CFI_ADJUST_CFA_OFFSET(n) .cfi_adjust_cfa_offset n
  23. # define CFI_DEF_CFA_OFFSET(n) .cfi_def_cfa_offset n
  24. # define CFI_REL_OFFSET(reg, n) .cfi_rel_offset reg, n
  25. # define CFI_OFFSET(reg, n) .cfi_offset reg, n
  26. # define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg
  27. # define CFI_DEF_CFA(reg, n) .cfi_def_cfa reg, n
  28. # define CFI_RESTORE(reg) .cfi_restore reg
  29. #else // No CFI
  30. # define CFI_INL_ADJUST_CFA_OFFSET(n)
  31. # define CFI_STARTPROC
  32. # define CFI_ENDPROC
  33. # define CFI_ADJUST_CFA_OFFSET(n)
  34. # define CFI_DEF_CFA_OFFSET(n)
  35. # define CFI_REL_OFFSET(reg, n)
  36. # define CFI_OFFSET(reg, n)
  37. # define CFI_DEF_CFA_REGISTER(reg)
  38. # define CFI_DEF_CFA(reg, n)
  39. # define CFI_RESTORE(reg)
  40. #endif
  41. #if !defined(__APPLE__)
  42. # define ASM_HIDDEN(symbol) .hidden symbol
  43. # define ASM_TYPE_FUNCTION(symbol) .type symbol, %function
  44. # define ASM_SIZE(symbol) .size symbol, .-symbol
  45. # define ASM_SYMBOL(symbol) symbol
  46. # define ASM_SYMBOL_INTERCEPTOR(symbol) symbol
  47. # define ASM_WRAPPER_NAME(symbol) __interceptor_##symbol
  48. #else
  49. # define ASM_HIDDEN(symbol)
  50. # define ASM_TYPE_FUNCTION(symbol)
  51. # define ASM_SIZE(symbol)
  52. # define ASM_SYMBOL(symbol) _##symbol
  53. # define ASM_SYMBOL_INTERCEPTOR(symbol) _wrap_##symbol
  54. # define ASM_WRAPPER_NAME(symbol) __interceptor_##symbol
  55. #endif
  56. #if defined(__ELF__) && (defined(__GNU__) || defined(__FreeBSD__) || \
  57. defined(__Fuchsia__) || defined(__linux__))
  58. // clang-format off
  59. #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
  60. // clang-format on
  61. #else
  62. #define NO_EXEC_STACK_DIRECTIVE
  63. #endif
  64. #if (defined(__x86_64__) || defined(__i386__)) && defined(__has_include) && __has_include(<cet.h>)
  65. #include <cet.h>
  66. #endif
  67. #ifndef _CET_ENDBR
  68. #define _CET_ENDBR
  69. #endif