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