sanitizer_flags.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //===-- sanitizer_flags.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. // This file describes common flags available in all sanitizers.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef COMMON_FLAG
  13. #error "Define COMMON_FLAG prior to including this file!"
  14. #endif
  15. // COMMON_FLAG(Type, Name, DefaultValue, Description)
  16. // Supported types: bool, const char *, int, uptr.
  17. // Default value must be a compile-time constant.
  18. // Description must be a string literal.
  19. COMMON_FLAG(
  20. bool, symbolize, true,
  21. "If set, use the online symbolizer from common sanitizer runtime to turn "
  22. "virtual addresses to file/line locations.")
  23. COMMON_FLAG(
  24. const char *, external_symbolizer_path, nullptr,
  25. "Path to external symbolizer. If empty, the tool will search $PATH for "
  26. "the symbolizer.")
  27. COMMON_FLAG(
  28. bool, allow_addr2line, false,
  29. "If set, allows online symbolizer to run addr2line binary to symbolize "
  30. "stack traces (addr2line will only be used if llvm-symbolizer binary is "
  31. "unavailable.")
  32. COMMON_FLAG(const char *, strip_path_prefix, "",
  33. "Strips this prefix from file paths in error reports.")
  34. COMMON_FLAG(bool, fast_unwind_on_check, false,
  35. "If available, use the fast frame-pointer-based unwinder on "
  36. "internal CHECK failures.")
  37. COMMON_FLAG(bool, fast_unwind_on_fatal, false,
  38. "If available, use the fast frame-pointer-based unwinder on fatal "
  39. "errors.")
  40. // ARM thumb/thumb2 frame pointer is inconsistent on GCC and Clang [1]
  41. // and fast-unwider is also unreliable with mixing arm and thumb code [2].
  42. // [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92172
  43. // [2] https://bugs.llvm.org/show_bug.cgi?id=44158
  44. COMMON_FLAG(bool, fast_unwind_on_malloc,
  45. !(SANITIZER_LINUX && !SANITIZER_ANDROID && SANITIZER_ARM),
  46. "If available, use the fast frame-pointer-based unwinder on "
  47. "malloc/free.")
  48. COMMON_FLAG(bool, handle_ioctl, false, "Intercept and handle ioctl requests.")
  49. COMMON_FLAG(int, malloc_context_size, 1,
  50. "Max number of stack frames kept for each allocation/deallocation.")
  51. COMMON_FLAG(
  52. const char *, log_path, nullptr,
  53. "Write logs to \"log_path.pid\". The special values are \"stdout\" and "
  54. "\"stderr\". If unspecified, defaults to \"stderr\".")
  55. COMMON_FLAG(
  56. bool, log_exe_name, false,
  57. "Mention name of executable when reporting error and "
  58. "append executable name to logs (as in \"log_path.exe_name.pid\").")
  59. COMMON_FLAG(const char *, log_suffix, nullptr,
  60. "String to append to log file name, e.g. \".txt\".")
  61. COMMON_FLAG(
  62. bool, log_to_syslog, (bool)SANITIZER_ANDROID || (bool)SANITIZER_APPLE,
  63. "Write all sanitizer output to syslog in addition to other means of "
  64. "logging.")
  65. COMMON_FLAG(
  66. int, verbosity, 0,
  67. "Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).")
  68. COMMON_FLAG(bool, strip_env, true,
  69. "Whether to remove the sanitizer from DYLD_INSERT_LIBRARIES to "
  70. "avoid passing it to children on Apple platforms. Default is true.")
  71. COMMON_FLAG(bool, verify_interceptors, true,
  72. "Verify that interceptors are working on Apple platforms. Default "
  73. "is true.")
  74. COMMON_FLAG(bool, detect_leaks, !SANITIZER_APPLE, "Enable memory leak detection.")
  75. COMMON_FLAG(
  76. bool, leak_check_at_exit, true,
  77. "Invoke leak checking in an atexit handler. Has no effect if "
  78. "detect_leaks=false, or if __lsan_do_leak_check() is called before the "
  79. "handler has a chance to run.")
  80. COMMON_FLAG(bool, allocator_may_return_null, false,
  81. "If false, the allocator will crash instead of returning 0 on "
  82. "out-of-memory.")
  83. COMMON_FLAG(bool, print_summary, true,
  84. "If false, disable printing error summaries in addition to error "
  85. "reports.")
  86. COMMON_FLAG(int, print_module_map, 0,
  87. "Print the process module map where supported (0 - don't print, "
  88. "1 - print only once before process exits, 2 - print after each "
  89. "report).")
  90. COMMON_FLAG(bool, check_printf, true, "Check printf arguments.")
  91. #define COMMON_FLAG_HANDLE_SIGNAL_HELP(signal) \
  92. "Controls custom tool's " #signal " handler (0 - do not registers the " \
  93. "handler, 1 - register the handler and allow user to set own, " \
  94. "2 - registers the handler and block user from changing it). "
  95. COMMON_FLAG(HandleSignalMode, handle_segv, kHandleSignalYes,
  96. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGSEGV))
  97. COMMON_FLAG(HandleSignalMode, handle_sigbus, kHandleSignalYes,
  98. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGBUS))
  99. COMMON_FLAG(HandleSignalMode, handle_abort, kHandleSignalNo,
  100. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGABRT))
  101. COMMON_FLAG(HandleSignalMode, handle_sigill, kHandleSignalNo,
  102. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGILL))
  103. COMMON_FLAG(HandleSignalMode, handle_sigtrap, kHandleSignalNo,
  104. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGTRAP))
  105. COMMON_FLAG(HandleSignalMode, handle_sigfpe, kHandleSignalYes,
  106. COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGFPE))
  107. #undef COMMON_FLAG_HANDLE_SIGNAL_HELP
  108. COMMON_FLAG(bool, allow_user_segv_handler, true,
  109. "Deprecated. True has no effect, use handle_sigbus=1. If false, "
  110. "handle_*=1 will be upgraded to handle_*=2.")
  111. COMMON_FLAG(bool, use_sigaltstack, true,
  112. "If set, uses alternate stack for signal handling.")
  113. COMMON_FLAG(bool, detect_deadlocks, true,
  114. "If set, deadlock detection is enabled.")
  115. COMMON_FLAG(
  116. uptr, clear_shadow_mmap_threshold, 64 * 1024,
  117. "Large shadow regions are zero-filled using mmap(NORESERVE) instead of "
  118. "memset(). This is the threshold size in bytes.")
  119. COMMON_FLAG(const char *, color, "auto",
  120. "Colorize reports: (always|never|auto).")
  121. COMMON_FLAG(
  122. bool, legacy_pthread_cond, false,
  123. "Enables support for dynamic libraries linked with libpthread 2.2.5.")
  124. COMMON_FLAG(bool, intercept_tls_get_addr, false, "Intercept __tls_get_addr.")
  125. COMMON_FLAG(bool, help, false, "Print the flag descriptions.")
  126. COMMON_FLAG(uptr, mmap_limit_mb, 0,
  127. "Limit the amount of mmap-ed memory (excluding shadow) in Mb; "
  128. "not a user-facing flag, used mosly for testing the tools")
  129. COMMON_FLAG(uptr, hard_rss_limit_mb, 0,
  130. "Hard RSS limit in Mb."
  131. " If non-zero, a background thread is spawned at startup"
  132. " which periodically reads RSS and aborts the process if the"
  133. " limit is reached")
  134. COMMON_FLAG(uptr, soft_rss_limit_mb, 0,
  135. "Soft RSS limit in Mb."
  136. " If non-zero, a background thread is spawned at startup"
  137. " which periodically reads RSS. If the limit is reached"
  138. " all subsequent malloc/new calls will fail or return NULL"
  139. " (depending on the value of allocator_may_return_null)"
  140. " until the RSS goes below the soft limit."
  141. " This limit does not affect memory allocations other than"
  142. " malloc/new.")
  143. COMMON_FLAG(uptr, max_allocation_size_mb, 0,
  144. "If non-zero, malloc/new calls larger than this size will return "
  145. "nullptr (or crash if allocator_may_return_null=false).")
  146. COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")
  147. COMMON_FLAG(s32, allocator_release_to_os_interval_ms,
  148. ((bool)SANITIZER_FUCHSIA || (bool)SANITIZER_WINDOWS) ? -1 : 5000,
  149. "Only affects a 64-bit allocator. If set, tries to release unused "
  150. "memory to the OS, but not more often than this interval (in "
  151. "milliseconds). Negative values mean do not attempt to release "
  152. "memory to the OS.\n")
  153. COMMON_FLAG(bool, can_use_proc_maps_statm, true,
  154. "If false, do not attempt to read /proc/maps/statm."
  155. " Mostly useful for testing sanitizers.")
  156. COMMON_FLAG(
  157. bool, coverage, false,
  158. "If set, coverage information will be dumped at program shutdown (if the "
  159. "coverage instrumentation was enabled at compile time).")
  160. COMMON_FLAG(const char *, coverage_dir, ".",
  161. "Target directory for coverage dumps. Defaults to the current "
  162. "directory.")
  163. COMMON_FLAG(const char *, cov_8bit_counters_out, "",
  164. "If non-empty, write 8bit counters to this file. ")
  165. COMMON_FLAG(const char *, cov_pcs_out, "",
  166. "If non-empty, write the coverage pc table to this file. ")
  167. COMMON_FLAG(bool, full_address_space, false,
  168. "Sanitize complete address space; "
  169. "by default kernel area on 32-bit platforms will not be sanitized")
  170. COMMON_FLAG(bool, print_suppressions, true,
  171. "Print matched suppressions at exit.")
  172. COMMON_FLAG(
  173. bool, disable_coredump, (SANITIZER_WORDSIZE == 64) && !SANITIZER_GO,
  174. "Disable core dumping. By default, disable_coredump=1 on 64-bit to avoid"
  175. " dumping a 16T+ core file. Ignored on OSes that don't dump core by"
  176. " default and for sanitizers that don't reserve lots of virtual memory.")
  177. COMMON_FLAG(bool, use_madv_dontdump, true,
  178. "If set, instructs kernel to not store the (huge) shadow "
  179. "in core file.")
  180. COMMON_FLAG(bool, symbolize_inline_frames, true,
  181. "Print inlined frames in stacktraces. Defaults to true.")
  182. COMMON_FLAG(bool, demangle, true, "Print demangled symbols.")
  183. COMMON_FLAG(bool, symbolize_vs_style, false,
  184. "Print file locations in Visual Studio style (e.g: "
  185. " file(10,42): ...")
  186. COMMON_FLAG(int, dedup_token_length, 0,
  187. "If positive, after printing a stack trace also print a short "
  188. "string token based on this number of frames that will simplify "
  189. "deduplication of the reports. "
  190. "Example: 'DEDUP_TOKEN: foo-bar-main'. Default is 0.")
  191. COMMON_FLAG(const char *, stack_trace_format, "DEFAULT",
  192. "Format string used to render stack frames. "
  193. "See sanitizer_stacktrace_printer.h for the format description. "
  194. "Use DEFAULT to get default format.")
  195. COMMON_FLAG(int, compress_stack_depot, 0,
  196. "Compress stack depot to save memory.")
  197. COMMON_FLAG(bool, no_huge_pages_for_shadow, true,
  198. "If true, the shadow is not allowed to use huge pages. ")
  199. COMMON_FLAG(bool, strict_string_checks, false,
  200. "If set check that string arguments are properly null-terminated")
  201. COMMON_FLAG(bool, intercept_strstr, true,
  202. "If set, uses custom wrappers for strstr and strcasestr functions "
  203. "to find more errors.")
  204. COMMON_FLAG(bool, intercept_strspn, true,
  205. "If set, uses custom wrappers for strspn and strcspn function "
  206. "to find more errors.")
  207. COMMON_FLAG(bool, intercept_strtok, true,
  208. "If set, uses a custom wrapper for the strtok function "
  209. "to find more errors.")
  210. COMMON_FLAG(bool, intercept_strpbrk, true,
  211. "If set, uses custom wrappers for strpbrk function "
  212. "to find more errors.")
  213. COMMON_FLAG(
  214. bool, intercept_strcmp, true,
  215. "If set, uses custom wrappers for strcmp functions to find more errors.")
  216. COMMON_FLAG(bool, intercept_strlen, true,
  217. "If set, uses custom wrappers for strlen and strnlen functions "
  218. "to find more errors.")
  219. COMMON_FLAG(bool, intercept_strndup, true,
  220. "If set, uses custom wrappers for strndup functions "
  221. "to find more errors.")
  222. COMMON_FLAG(bool, intercept_strchr, true,
  223. "If set, uses custom wrappers for strchr, strchrnul, and strrchr "
  224. "functions to find more errors.")
  225. COMMON_FLAG(bool, intercept_memcmp, true,
  226. "If set, uses custom wrappers for memcmp function "
  227. "to find more errors.")
  228. COMMON_FLAG(bool, strict_memcmp, true,
  229. "If true, assume that memcmp(p1, p2, n) always reads n bytes before "
  230. "comparing p1 and p2.")
  231. COMMON_FLAG(bool, intercept_memmem, true,
  232. "If set, uses a wrapper for memmem() to find more errors.")
  233. COMMON_FLAG(bool, intercept_intrin, true,
  234. "If set, uses custom wrappers for memset/memcpy/memmove "
  235. "intrinsics to find more errors.")
  236. COMMON_FLAG(bool, intercept_stat, true,
  237. "If set, uses custom wrappers for *stat functions "
  238. "to find more errors.")
  239. COMMON_FLAG(bool, intercept_send, true,
  240. "If set, uses custom wrappers for send* functions "
  241. "to find more errors.")
  242. COMMON_FLAG(bool, decorate_proc_maps, (bool)SANITIZER_ANDROID,
  243. "If set, decorate sanitizer mappings in /proc/self/maps with "
  244. "user-readable names")
  245. COMMON_FLAG(int, exitcode, 1, "Override the program exit status if the tool "
  246. "found an error")
  247. COMMON_FLAG(
  248. bool, abort_on_error, (bool)SANITIZER_ANDROID || (bool)SANITIZER_APPLE,
  249. "If set, the tool calls abort() instead of _exit() after printing the "
  250. "error report.")
  251. COMMON_FLAG(bool, suppress_equal_pcs, true,
  252. "Deduplicate multiple reports for single source location in "
  253. "halt_on_error=false mode (asan only).")
  254. COMMON_FLAG(bool, print_cmdline, false, "Print command line on crash "
  255. "(asan only).")
  256. COMMON_FLAG(bool, html_cov_report, false, "Generate html coverage report.")
  257. COMMON_FLAG(const char *, sancov_path, "sancov", "Sancov tool location.")
  258. COMMON_FLAG(bool, dump_instruction_bytes, false,
  259. "If true, dump 16 bytes starting at the instruction that caused SEGV")
  260. COMMON_FLAG(bool, dump_registers, true,
  261. "If true, dump values of CPU registers when SEGV happens. Only "
  262. "available on OS X for now.")
  263. COMMON_FLAG(bool, detect_write_exec, false,
  264. "If true, triggers warning when writable-executable pages requests "
  265. "are being made")
  266. COMMON_FLAG(bool, test_only_emulate_no_memorymap, false,
  267. "TEST ONLY fail to read memory mappings to emulate sanitized "
  268. "\"init\"")