sanitize.m4 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. dnl This Source Code Form is subject to the terms of the Mozilla Public
  2. dnl License, v. 2.0. If a copy of the MPL was not distributed with this
  3. dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. AC_DEFUN([MOZ_CONFIG_SANITIZE], [
  5. dnl ========================================================
  6. dnl = Use Address Sanitizer
  7. dnl ========================================================
  8. MOZ_ARG_ENABLE_BOOL(address-sanitizer,
  9. [ --enable-address-sanitizer Enable Address Sanitizer (default=no)],
  10. MOZ_ASAN=1,
  11. MOZ_ASAN= )
  12. if test -n "$MOZ_ASAN"; then
  13. MOZ_LLVM_HACKS=1
  14. if test -n "$CLANG_CL"; then
  15. # Look for the ASan runtime binary
  16. if test "$CPU_ARCH" = "x86_64"; then
  17. MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-x86_64.dll
  18. else
  19. MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-i386.dll
  20. fi
  21. # We use MOZ_PATH_PROG in order to get a Windows style path.
  22. MOZ_PATH_PROG(MOZ_CLANG_RT_ASAN_LIB_PATH, $MOZ_CLANG_RT_ASAN_LIB)
  23. if test -z "$MOZ_CLANG_RT_ASAN_LIB_PATH"; then
  24. AC_MSG_ERROR([Couldn't find $MOZ_CLANG_RT_ASAN_LIB. It should be available in the same location as clang-cl.])
  25. fi
  26. AC_SUBST(MOZ_CLANG_RT_ASAN_LIB_PATH)
  27. # Suppressing errors in recompiled code.
  28. if test "$OS_ARCH" = "WINNT"; then
  29. CFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CFLAGS"
  30. CXXFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CXXFLAGS"
  31. fi
  32. fi
  33. CFLAGS="-fsanitize=address $CFLAGS"
  34. CXXFLAGS="-fsanitize=address $CXXFLAGS"
  35. if test -z "$CLANG_CL"; then
  36. LDFLAGS="-fsanitize=address $LDFLAGS"
  37. fi
  38. AC_DEFINE(MOZ_ASAN)
  39. MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
  40. fi
  41. AC_SUBST(MOZ_ASAN)
  42. dnl ========================================================
  43. dnl = Use Memory Sanitizer
  44. dnl ========================================================
  45. MOZ_ARG_ENABLE_BOOL(memory-sanitizer,
  46. [ --enable-memory-sanitizer Enable Memory Sanitizer (default=no)],
  47. MOZ_MSAN=1,
  48. MOZ_MSAN= )
  49. if test -n "$MOZ_MSAN"; then
  50. MOZ_LLVM_HACKS=1
  51. CFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CFLAGS"
  52. CXXFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CXXFLAGS"
  53. if test -z "$CLANG_CL"; then
  54. LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $LDFLAGS"
  55. fi
  56. AC_DEFINE(MOZ_MSAN)
  57. MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
  58. fi
  59. AC_SUBST(MOZ_MSAN)
  60. dnl ========================================================
  61. dnl = Use Thread Sanitizer
  62. dnl ========================================================
  63. MOZ_ARG_ENABLE_BOOL(thread-sanitizer,
  64. [ --enable-thread-sanitizer Enable Thread Sanitizer (default=no)],
  65. MOZ_TSAN=1,
  66. MOZ_TSAN= )
  67. if test -n "$MOZ_TSAN"; then
  68. MOZ_LLVM_HACKS=1
  69. CFLAGS="-fsanitize=thread $CFLAGS"
  70. CXXFLAGS="-fsanitize=thread $CXXFLAGS"
  71. if test -z "$CLANG_CL"; then
  72. LDFLAGS="-fsanitize=thread $LDFLAGS"
  73. fi
  74. AC_DEFINE(MOZ_TSAN)
  75. MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
  76. fi
  77. AC_SUBST(MOZ_TSAN)
  78. # The LLVM symbolizer is used by all sanitizers
  79. AC_SUBST(LLVM_SYMBOLIZER)
  80. dnl ========================================================
  81. dnl = Enable hacks required for LLVM instrumentations
  82. dnl ========================================================
  83. MOZ_ARG_ENABLE_BOOL(llvm-hacks,
  84. [ --enable-llvm-hacks Enable workarounds required for several LLVM instrumentations (default=no)],
  85. MOZ_LLVM_HACKS=1,
  86. MOZ_LLVM_HACKS= )
  87. if test -n "$MOZ_LLVM_HACKS"; then
  88. MOZ_NO_WLZDEFS=1
  89. MOZ_CFLAGS_NSS=1
  90. fi
  91. AC_SUBST(MOZ_NO_WLZDEFS)
  92. AC_SUBST(MOZ_CFLAGS_NSS)
  93. dnl ========================================================
  94. dnl = Test for whether the compiler is compatible with the
  95. dnl = given sanitize options.
  96. dnl ========================================================
  97. AC_TRY_LINK(,,,AC_MSG_ERROR([compiler is incompatible with sanitize options]))
  98. ])