1278497Sdim//===-- sanitizer_flags.h ---------------------------------------*- C++ -*-===//
2278497Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6278497Sdim//
7278497Sdim//===----------------------------------------------------------------------===//
8278497Sdim//
9278497Sdim// This file describes common flags available in all sanitizers.
10278497Sdim//
11278497Sdim//===----------------------------------------------------------------------===//
12296417Sdim
13278497Sdim#ifndef COMMON_FLAG
14278497Sdim#error "Define COMMON_FLAG prior to including this file!"
15278497Sdim#endif
16278497Sdim
17278497Sdim// COMMON_FLAG(Type, Name, DefaultValue, Description)
18278497Sdim// Supported types: bool, const char *, int, uptr.
19278497Sdim// Default value must be a compile-time constant.
20278497Sdim// Description must be a string literal.
21278497Sdim
22278497SdimCOMMON_FLAG(
23278497Sdim    bool, symbolize, true,
24278497Sdim    "If set, use the online symbolizer from common sanitizer runtime to turn "
25278497Sdim    "virtual addresses to file/line locations.")
26278497SdimCOMMON_FLAG(
27296417Sdim    const char *, external_symbolizer_path, nullptr,
28278497Sdim    "Path to external symbolizer. If empty, the tool will search $PATH for "
29278497Sdim    "the symbolizer.")
30278497SdimCOMMON_FLAG(
31278497Sdim    bool, allow_addr2line, false,
32278497Sdim    "If set, allows online symbolizer to run addr2line binary to symbolize "
33278497Sdim    "stack traces (addr2line will only be used if llvm-symbolizer binary is "
34278497Sdim    "unavailable.")
35278497SdimCOMMON_FLAG(const char *, strip_path_prefix, "",
36278497Sdim            "Strips this prefix from file paths in error reports.")
37278497SdimCOMMON_FLAG(bool, fast_unwind_on_check, false,
38278497Sdim            "If available, use the fast frame-pointer-based unwinder on "
39278497Sdim            "internal CHECK failures.")
40278497SdimCOMMON_FLAG(bool, fast_unwind_on_fatal, false,
41278497Sdim            "If available, use the fast frame-pointer-based unwinder on fatal "
42278497Sdim            "errors.")
43278497SdimCOMMON_FLAG(bool, fast_unwind_on_malloc, true,
44278497Sdim            "If available, use the fast frame-pointer-based unwinder on "
45278497Sdim            "malloc/free.")
46278497SdimCOMMON_FLAG(bool, handle_ioctl, false, "Intercept and handle ioctl requests.")
47278497SdimCOMMON_FLAG(int, malloc_context_size, 1,
48278497Sdim            "Max number of stack frames kept for each allocation/deallocation.")
49278497SdimCOMMON_FLAG(
50278497Sdim    const char *, log_path, "stderr",
51278497Sdim    "Write logs to \"log_path.pid\". The special values are \"stdout\" and "
52278497Sdim    "\"stderr\". The default is \"stderr\".")
53278497SdimCOMMON_FLAG(
54288943Sdim    bool, log_exe_name, false,
55288943Sdim    "Mention name of executable when reporting error and "
56288943Sdim    "append executable name to logs (as in \"log_path.exe_name.pid\").")
57288943SdimCOMMON_FLAG(
58341825Sdim    bool, log_to_syslog, (bool)SANITIZER_ANDROID || (bool)SANITIZER_MAC,
59296417Sdim    "Write all sanitizer output to syslog in addition to other means of "
60296417Sdim    "logging.")
61296417SdimCOMMON_FLAG(
62278497Sdim    int, verbosity, 0,
63278497Sdim    "Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output).")
64327952SdimCOMMON_FLAG(bool, strip_env, 1,
65327952Sdim            "Whether to remove the sanitizer from DYLD_INSERT_LIBRARIES to "
66327952Sdim            "avoid passing it to children. Default is true.")
67321369SdimCOMMON_FLAG(bool, detect_leaks, !SANITIZER_MAC, "Enable memory leak detection.")
68278497SdimCOMMON_FLAG(
69278497Sdim    bool, leak_check_at_exit, true,
70278497Sdim    "Invoke leak checking in an atexit handler. Has no effect if "
71278497Sdim    "detect_leaks=false, or if __lsan_do_leak_check() is called before the "
72278497Sdim    "handler has a chance to run.")
73278497SdimCOMMON_FLAG(bool, allocator_may_return_null, false,
74278497Sdim            "If false, the allocator will crash instead of returning 0 on "
75278497Sdim            "out-of-memory.")
76278497SdimCOMMON_FLAG(bool, print_summary, true,
77278497Sdim            "If false, disable printing error summaries in addition to error "
78278497Sdim            "reports.")
79314564SdimCOMMON_FLAG(int, print_module_map, 0,
80321369Sdim            "OS X only (0 - don't print, 1 - print only once before process "
81321369Sdim            "exits, 2 - print after each report).")
82278497SdimCOMMON_FLAG(bool, check_printf, true, "Check printf arguments.")
83321369Sdim#define COMMON_FLAG_HANDLE_SIGNAL_HELP(signal) \
84321369Sdim    "Controls custom tool's " #signal " handler (0 - do not registers the " \
85321369Sdim    "handler, 1 - register the handler and allow user to set own, " \
86321369Sdim    "2 - registers the handler and block user from changing it). "
87321369SdimCOMMON_FLAG(HandleSignalMode, handle_segv, kHandleSignalYes,
88321369Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGSEGV))
89321369SdimCOMMON_FLAG(HandleSignalMode, handle_sigbus, kHandleSignalYes,
90321369Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGBUS))
91321369SdimCOMMON_FLAG(HandleSignalMode, handle_abort, kHandleSignalNo,
92321369Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGABRT))
93321369SdimCOMMON_FLAG(HandleSignalMode, handle_sigill, kHandleSignalNo,
94321369Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGILL))
95341825SdimCOMMON_FLAG(HandleSignalMode, handle_sigtrap, kHandleSignalNo,
96341825Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGTRAP))
97321369SdimCOMMON_FLAG(HandleSignalMode, handle_sigfpe, kHandleSignalYes,
98321369Sdim            COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGFPE))
99321369Sdim#undef COMMON_FLAG_HANDLE_SIGNAL_HELP
100321369SdimCOMMON_FLAG(bool, allow_user_segv_handler, true,
101321369Sdim            "Deprecated. True has no effect, use handle_sigbus=1. If false, "
102321369Sdim            "handle_*=1 will be upgraded to handle_*=2.")
103278497SdimCOMMON_FLAG(bool, use_sigaltstack, true,
104278497Sdim            "If set, uses alternate stack for signal handling.")
105344779SdimCOMMON_FLAG(bool, detect_deadlocks, true,
106278497Sdim            "If set, deadlock detection is enabled.")
107278497SdimCOMMON_FLAG(
108278497Sdim    uptr, clear_shadow_mmap_threshold, 64 * 1024,
109278497Sdim    "Large shadow regions are zero-filled using mmap(NORESERVE) instead of "
110278497Sdim    "memset(). This is the threshold size in bytes.")
111278497SdimCOMMON_FLAG(const char *, color, "auto",
112278497Sdim            "Colorize reports: (always|never|auto).")
113278497SdimCOMMON_FLAG(
114278497Sdim    bool, legacy_pthread_cond, false,
115278497Sdim    "Enables support for dynamic libraries linked with libpthread 2.2.5.")
116278497SdimCOMMON_FLAG(bool, intercept_tls_get_addr, false, "Intercept __tls_get_addr.")
117278497SdimCOMMON_FLAG(bool, help, false, "Print the flag descriptions.")
118278497SdimCOMMON_FLAG(uptr, mmap_limit_mb, 0,
119278497Sdim            "Limit the amount of mmap-ed memory (excluding shadow) in Mb; "
120278497Sdim            "not a user-facing flag, used mosly for testing the tools")
121278497SdimCOMMON_FLAG(uptr, hard_rss_limit_mb, 0,
122278497Sdim            "Hard RSS limit in Mb."
123278497Sdim            " If non-zero, a background thread is spawned at startup"
124278497Sdim            " which periodically reads RSS and aborts the process if the"
125278497Sdim            " limit is reached")
126278497SdimCOMMON_FLAG(uptr, soft_rss_limit_mb, 0,
127278497Sdim            "Soft RSS limit in Mb."
128278497Sdim            " If non-zero, a background thread is spawned at startup"
129278497Sdim            " which periodically reads RSS. If the limit is reached"
130278497Sdim            " all subsequent malloc/new calls will fail or return NULL"
131278497Sdim            " (depending on the value of allocator_may_return_null)"
132278497Sdim            " until the RSS goes below the soft limit."
133278497Sdim            " This limit does not affect memory allocations other than"
134278497Sdim            " malloc/new.")
135360784SdimCOMMON_FLAG(uptr, max_allocation_size_mb, 0,
136360784Sdim            "If non-zero, malloc/new calls larger than this size will return "
137360784Sdim            "nullptr (or crash if allocator_may_return_null=false).")
138314564SdimCOMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")
139341825SdimCOMMON_FLAG(s32, allocator_release_to_os_interval_ms,
140341825Sdim            ((bool)SANITIZER_FUCHSIA || (bool)SANITIZER_WINDOWS) ? -1 : 5000,
141327952Sdim            "Only affects a 64-bit allocator. If set, tries to release unused "
142327952Sdim            "memory to the OS, but not more often than this interval (in "
143327952Sdim            "milliseconds). Negative values mean do not attempt to release "
144327952Sdim            "memory to the OS.\n")
145278497SdimCOMMON_FLAG(bool, can_use_proc_maps_statm, true,
146278497Sdim            "If false, do not attempt to read /proc/maps/statm."
147278497Sdim            " Mostly useful for testing sanitizers.")
148278497SdimCOMMON_FLAG(
149278497Sdim    bool, coverage, false,
150278497Sdim    "If set, coverage information will be dumped at program shutdown (if the "
151278497Sdim    "coverage instrumentation was enabled at compile time).")
152278497SdimCOMMON_FLAG(const char *, coverage_dir, ".",
153278497Sdim            "Target directory for coverage dumps. Defaults to the current "
154278497Sdim            "directory.")
155278497SdimCOMMON_FLAG(bool, full_address_space, false,
156278497Sdim            "Sanitize complete address space; "
157278497Sdim            "by default kernel area on 32-bit platforms will not be sanitized")
158278497SdimCOMMON_FLAG(bool, print_suppressions, true,
159278497Sdim            "Print matched suppressions at exit.")
160278497SdimCOMMON_FLAG(
161314564Sdim    bool, disable_coredump, (SANITIZER_WORDSIZE == 64) && !SANITIZER_GO,
162314564Sdim    "Disable core dumping. By default, disable_coredump=1 on 64-bit to avoid"
163314564Sdim    " dumping a 16T+ core file. Ignored on OSes that don't dump core by"
164314564Sdim    " default and for sanitizers that don't reserve lots of virtual memory.")
165278497SdimCOMMON_FLAG(bool, use_madv_dontdump, true,
166278497Sdim          "If set, instructs kernel to not store the (huge) shadow "
167278497Sdim          "in core file.")
168278497SdimCOMMON_FLAG(bool, symbolize_inline_frames, true,
169278497Sdim            "Print inlined frames in stacktraces. Defaults to true.")
170288943SdimCOMMON_FLAG(bool, symbolize_vs_style, false,
171288943Sdim            "Print file locations in Visual Studio style (e.g: "
172288943Sdim            " file(10,42): ...")
173309124SdimCOMMON_FLAG(int, dedup_token_length, 0,
174309124Sdim            "If positive, after printing a stack trace also print a short "
175309124Sdim            "string token based on this number of frames that will simplify "
176309124Sdim            "deduplication of the reports. "
177309124Sdim            "Example: 'DEDUP_TOKEN: foo-bar-main'. Default is 0.")
178278497SdimCOMMON_FLAG(const char *, stack_trace_format, "DEFAULT",
179278497Sdim            "Format string used to render stack frames. "
180278497Sdim            "See sanitizer_stacktrace_printer.h for the format description. "
181278497Sdim            "Use DEFAULT to get default format.")
182278497SdimCOMMON_FLAG(bool, no_huge_pages_for_shadow, true,
183278497Sdim            "If true, the shadow is not allowed to use huge pages. ")
184288943SdimCOMMON_FLAG(bool, strict_string_checks, false,
185288943Sdim            "If set check that string arguments are properly null-terminated")
186288943SdimCOMMON_FLAG(bool, intercept_strstr, true,
187288943Sdim            "If set, uses custom wrappers for strstr and strcasestr functions "
188288943Sdim            "to find more errors.")
189288943SdimCOMMON_FLAG(bool, intercept_strspn, true,
190288943Sdim            "If set, uses custom wrappers for strspn and strcspn function "
191288943Sdim            "to find more errors.")
192321369SdimCOMMON_FLAG(bool, intercept_strtok, true,
193321369Sdim            "If set, uses a custom wrapper for the strtok function "
194321369Sdim            "to find more errors.")
195288943SdimCOMMON_FLAG(bool, intercept_strpbrk, true,
196288943Sdim            "If set, uses custom wrappers for strpbrk function "
197288943Sdim            "to find more errors.")
198309124SdimCOMMON_FLAG(bool, intercept_strlen, true,
199309124Sdim            "If set, uses custom wrappers for strlen and strnlen functions "
200309124Sdim            "to find more errors.")
201321369SdimCOMMON_FLAG(bool, intercept_strndup, true,
202321369Sdim            "If set, uses custom wrappers for strndup functions "
203321369Sdim            "to find more errors.")
204309124SdimCOMMON_FLAG(bool, intercept_strchr, true,
205309124Sdim            "If set, uses custom wrappers for strchr, strchrnul, and strrchr "
206309124Sdim            "functions to find more errors.")
207296417SdimCOMMON_FLAG(bool, intercept_memcmp, true,
208296417Sdim            "If set, uses custom wrappers for memcmp function "
209296417Sdim            "to find more errors.")
210296417SdimCOMMON_FLAG(bool, strict_memcmp, true,
211296417Sdim          "If true, assume that memcmp(p1, p2, n) always reads n bytes before "
212296417Sdim          "comparing p1 and p2.")
213309124SdimCOMMON_FLAG(bool, intercept_memmem, true,
214309124Sdim            "If set, uses a wrapper for memmem() to find more errors.")
215309124SdimCOMMON_FLAG(bool, intercept_intrin, true,
216309124Sdim            "If set, uses custom wrappers for memset/memcpy/memmove "
217309124Sdim            "intrinsics to find more errors.")
218309124SdimCOMMON_FLAG(bool, intercept_stat, true,
219309124Sdim            "If set, uses custom wrappers for *stat functions "
220309124Sdim            "to find more errors.")
221309124SdimCOMMON_FLAG(bool, intercept_send, true,
222309124Sdim            "If set, uses custom wrappers for send* functions "
223309124Sdim            "to find more errors.")
224353358SdimCOMMON_FLAG(bool, decorate_proc_maps, (bool)SANITIZER_ANDROID,
225353358Sdim            "If set, decorate sanitizer mappings in /proc/self/maps with "
226353358Sdim            "user-readable names")
227296417SdimCOMMON_FLAG(int, exitcode, 1, "Override the program exit status if the tool "
228296417Sdim                              "found an error")
229296417SdimCOMMON_FLAG(
230341825Sdim    bool, abort_on_error, (bool)SANITIZER_ANDROID || (bool)SANITIZER_MAC,
231296417Sdim    "If set, the tool calls abort() instead of _exit() after printing the "
232296417Sdim    "error report.")
233296417SdimCOMMON_FLAG(bool, suppress_equal_pcs, true,
234296417Sdim            "Deduplicate multiple reports for single source location in "
235296417Sdim            "halt_on_error=false mode (asan only).")
236309124SdimCOMMON_FLAG(bool, print_cmdline, false, "Print command line on crash "
237309124Sdim            "(asan only).")
238309124SdimCOMMON_FLAG(bool, html_cov_report, false, "Generate html coverage report.")
239309124SdimCOMMON_FLAG(const char *, sancov_path, "sancov", "Sancov tool location.")
240327952SdimCOMMON_FLAG(bool, dump_instruction_bytes, false,
241327952Sdim          "If true, dump 16 bytes starting at the instruction that caused SEGV")
242327952SdimCOMMON_FLAG(bool, dump_registers, true,
243327952Sdim          "If true, dump values of CPU registers when SEGV happens. Only "
244327952Sdim          "available on OS X for now.")
245341825SdimCOMMON_FLAG(bool, detect_write_exec, false,
246341825Sdim          "If true, triggers warning when writable-executable pages requests "
247341825Sdim          "are being made")
248344779SdimCOMMON_FLAG(bool, test_only_emulate_no_memorymap, false,
249344779Sdim            "TEST ONLY fail to read memory mappings to emulate sanitized "
250344779Sdim            "\"init\"")
251