sanitizer_options.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. //
  5. // This file contains the default options for various compiler-based dynamic
  6. // tools.
  7. #include "build/build_config.h"
  8. #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
  9. defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
  10. defined(UNDEFINED_SANITIZER)
  11. // The callbacks we define here will be called from the sanitizer runtime, but
  12. // aren't referenced from the Chrome executable. We must ensure that those
  13. // callbacks are not sanitizer-instrumented, and that they aren't stripped by
  14. // the linker.
  15. #define SANITIZER_HOOK_ATTRIBUTE \
  16. extern "C" \
  17. __attribute__((no_sanitize("address", "memory", "thread", "undefined"))) \
  18. __attribute__((visibility("default"))) \
  19. __attribute__((used))
  20. // Functions returning default options are declared weak in the tools' runtime
  21. // libraries. To make the linker pick the strong replacements for those
  22. // functions from this module, we explicitly force its inclusion by passing
  23. // -Wl,-u_sanitizer_options_link_helper
  24. // SANITIZER_HOOK_ATTRIBUTE instead of just `extern "C"` solely to make the
  25. // symbol externally visible, for ToolsSanityTest.LinksSanitizerOptions.
  26. SANITIZER_HOOK_ATTRIBUTE void _sanitizer_options_link_helper() {}
  27. #endif
  28. #if defined(ADDRESS_SANITIZER)
  29. // Default options for AddressSanitizer in various configurations:
  30. // strip_path_prefix=/../../ - prefixes up to and including this
  31. // substring will be stripped from source file paths in symbolized reports
  32. // fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder
  33. // to print error reports. V8 doesn't generate debug info for the JIT code,
  34. // so the slow unwinder may not work properly.
  35. // detect_stack_use_after_return=1 - use fake stack to delay the reuse of
  36. // stack allocations and detect stack-use-after-return errors.
  37. // symbolize=1 - enable in-process symbolization.
  38. // external_symbolizer_path=... - provides the path to llvm-symbolizer
  39. // relative to the main executable
  40. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  41. const char kAsanDefaultOptions[] =
  42. "strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
  43. "detect_stack_use_after_return=1 symbolize=1 detect_leaks=0 "
  44. "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
  45. "bin/llvm-symbolizer";
  46. #elif BUILDFLAG(IS_APPLE)
  47. const char* kAsanDefaultOptions =
  48. "strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
  49. "detect_stack_use_after_return=1 ";
  50. #elif BUILDFLAG(IS_WIN)
  51. const char* kAsanDefaultOptions =
  52. "strip_path_prefix=\\..\\..\\ fast_unwind_on_fatal=1 "
  53. "detect_stack_use_after_return=1 symbolize=1 "
  54. "external_symbolizer_path=%d/../../third_party/"
  55. "llvm-build/Release+Asserts/bin/llvm-symbolizer.exe";
  56. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  57. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE) || \
  58. BUILDFLAG(IS_WIN)
  59. // Allow NaCl to override the default asan options.
  60. extern const char* kAsanDefaultOptionsNaCl;
  61. __attribute__((weak)) const char* kAsanDefaultOptionsNaCl = nullptr;
  62. SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() {
  63. if (kAsanDefaultOptionsNaCl)
  64. return kAsanDefaultOptionsNaCl;
  65. return kAsanDefaultOptions;
  66. }
  67. extern char kASanDefaultSuppressions[];
  68. SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_suppressions() {
  69. return kASanDefaultSuppressions;
  70. }
  71. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE)
  72. // || BUILDFLAG(IS_WIN)
  73. #endif // ADDRESS_SANITIZER
  74. #if defined(THREAD_SANITIZER) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
  75. // Default options for ThreadSanitizer in various configurations:
  76. // second_deadlock_stack=1 - more verbose deadlock reports.
  77. // report_signal_unsafe=0 - do not report async-signal-unsafe functions
  78. // called from signal handlers.
  79. // report_thread_leaks=0 - do not report unjoined threads at the end of
  80. // the program execution.
  81. // print_suppressions=1 - print the list of matched suppressions.
  82. // history_size=7 - make the history buffer proportional to 2^7 (the maximum
  83. // value) to keep more stack traces.
  84. // strip_path_prefix=/../../ - prefixes up to and including this
  85. // substring will be stripped from source file paths in symbolized reports.
  86. // external_symbolizer_path=... - provides the path to llvm-symbolizer
  87. // relative to the main executable
  88. const char kTsanDefaultOptions[] =
  89. "second_deadlock_stack=1 report_signal_unsafe=0 "
  90. "report_thread_leaks=0 print_suppressions=1 history_size=7 "
  91. "strip_path_prefix=/../../ external_symbolizer_path=%d/../../third_party/"
  92. "llvm-build/Release+Asserts/bin/llvm-symbolizer";
  93. SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() {
  94. return kTsanDefaultOptions;
  95. }
  96. extern char kTSanDefaultSuppressions[];
  97. SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() {
  98. return kTSanDefaultSuppressions;
  99. }
  100. #endif // defined(THREAD_SANITIZER) && (BUILDFLAG(IS_LINUX) ||
  101. // BUILDFLAG(IS_CHROMEOS))
  102. #if defined(MEMORY_SANITIZER)
  103. // Default options for MemorySanitizer:
  104. // strip_path_prefix=/../../ - prefixes up to and including this
  105. // substring will be stripped from source file paths in symbolized reports.
  106. // external_symbolizer_path=... - provides the path to llvm-symbolizer
  107. // relative to the main executable
  108. const char kMsanDefaultOptions[] =
  109. "strip_path_prefix=/../../ "
  110. #if !BUILDFLAG(IS_APPLE)
  111. "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
  112. "bin/llvm-symbolizer"
  113. #endif
  114. ;
  115. SANITIZER_HOOK_ATTRIBUTE const char *__msan_default_options() {
  116. return kMsanDefaultOptions;
  117. }
  118. #endif // MEMORY_SANITIZER
  119. #if defined(LEAK_SANITIZER)
  120. // Default options for LeakSanitizer:
  121. // strip_path_prefix=/../../ - prefixes up to and including this
  122. // substring will be stripped from source file paths in symbolized reports.
  123. // external_symbolizer_path=... - provides the path to llvm-symbolizer
  124. // relative to the main executable
  125. // use_poisoned=1 - Scan poisoned memory. This is useful for Oilpan (C++
  126. // garbage collection) which wants to exclude its managed memory from being
  127. // reported as leaks (through root regions) and also temporarily poisons
  128. // memory regions before calling destructors of objects to avoid destructors
  129. // cross-referencing memory in other objects. Main thread termination in
  130. // Blink is not graceful and leak checks may be emitted at any time, which
  131. // means that the garbage collector may be in a state with poisoned memory,
  132. // leading to false-positive reports.
  133. const char kLsanDefaultOptions[] =
  134. "strip_path_prefix=/../../ use_poisoned=1 "
  135. #if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA)
  136. "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
  137. "bin/llvm-symbolizer "
  138. #endif
  139. #if defined(ARCH_CPU_64_BITS)
  140. // When pointer compression in V8 is enabled the external pointers in the
  141. // heap are guaranteed to be only 4 bytes aligned. So we need this option
  142. // in order to ensure that LSAN will find all the external pointers.
  143. // TODO(crbug.com/328552): see updates from 2019.
  144. "use_unaligned=1 "
  145. #endif // ARCH_CPU_64_BITS
  146. ;
  147. SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() {
  148. return kLsanDefaultOptions;
  149. }
  150. // TODO(https://fxbug.dev/102967): Remove when Fuchsia supports
  151. // module-name-based and function-name-based suppression.
  152. #if !BUILDFLAG(IS_FUCHSIA)
  153. extern char kLSanDefaultSuppressions[];
  154. SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() {
  155. return kLSanDefaultSuppressions;
  156. }
  157. #endif // !BUILDFLAG(IS_FUCHSIA)
  158. #endif // LEAK_SANITIZER
  159. #if defined(UNDEFINED_SANITIZER)
  160. // Default options for UndefinedBehaviorSanitizer:
  161. // print_stacktrace=1 - print the stacktrace when UBSan reports an error.
  162. const char kUbsanDefaultOptions[] =
  163. "print_stacktrace=1 strip_path_prefix=/../../ "
  164. #if !BUILDFLAG(IS_APPLE)
  165. "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
  166. "bin/llvm-symbolizer"
  167. #endif
  168. ;
  169. SANITIZER_HOOK_ATTRIBUTE const char* __ubsan_default_options() {
  170. return kUbsanDefaultOptions;
  171. }
  172. #endif // UNDEFINED_SANITIZER