xref: /freebsd/contrib/llvm-project/compiler-rt/lib/asan/asan_flags.inc (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric//===-- asan_flags.inc ------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric//
90b57cec5SDimitry Andric// ASan runtime flags.
100b57cec5SDimitry Andric//
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric#ifndef ASAN_FLAG
130b57cec5SDimitry Andric# error "Define ASAN_FLAG prior to including this file!"
140b57cec5SDimitry Andric#endif
150b57cec5SDimitry Andric
160b57cec5SDimitry Andric// ASAN_FLAG(Type, Name, DefaultValue, Description)
170b57cec5SDimitry Andric// See COMMON_FLAG in sanitizer_flags.inc for more details.
180b57cec5SDimitry Andric
190b57cec5SDimitry AndricASAN_FLAG(int, quarantine_size, -1,
200b57cec5SDimitry Andric            "Deprecated, please use quarantine_size_mb.")
210b57cec5SDimitry AndricASAN_FLAG(int, quarantine_size_mb, -1,
220b57cec5SDimitry Andric          "Size (in Mb) of quarantine used to detect use-after-free "
230b57cec5SDimitry Andric          "errors. Lower value may reduce memory usage but increase the "
240b57cec5SDimitry Andric          "chance of false negatives.")
250b57cec5SDimitry AndricASAN_FLAG(int, thread_local_quarantine_size_kb, -1,
260b57cec5SDimitry Andric          "Size (in Kb) of thread local quarantine used to detect "
270b57cec5SDimitry Andric          "use-after-free errors. Lower value may reduce memory usage but "
280b57cec5SDimitry Andric          "increase the chance of false negatives. It is not advised to go "
290b57cec5SDimitry Andric          "lower than 64Kb, otherwise frequent transfers to global quarantine "
300b57cec5SDimitry Andric          "might affect performance.")
310b57cec5SDimitry AndricASAN_FLAG(int, redzone, 16,
320b57cec5SDimitry Andric          "Minimal size (in bytes) of redzones around heap objects. "
330b57cec5SDimitry Andric          "Requirement: redzone >= 16, is a power of two.")
340b57cec5SDimitry AndricASAN_FLAG(int, max_redzone, 2048,
350b57cec5SDimitry Andric          "Maximal size (in bytes) of redzones around heap objects.")
360b57cec5SDimitry AndricASAN_FLAG(
370b57cec5SDimitry Andric    bool, debug, false,
380b57cec5SDimitry Andric    "If set, prints some debugging information and does additional checks.")
390b57cec5SDimitry AndricASAN_FLAG(
400b57cec5SDimitry Andric    int, report_globals, 1,
410b57cec5SDimitry Andric    "Controls the way to handle globals (0 - don't detect buffer overflow on "
420b57cec5SDimitry Andric    "globals, 1 - detect buffer overflow, 2 - print data about registered "
430b57cec5SDimitry Andric    "globals).")
440b57cec5SDimitry AndricASAN_FLAG(bool, check_initialization_order, false,
450b57cec5SDimitry Andric          "If set, attempts to catch initialization order issues.")
460b57cec5SDimitry AndricASAN_FLAG(
470b57cec5SDimitry Andric    bool, replace_str, true,
480b57cec5SDimitry Andric    "If set, uses custom wrappers and replacements for libc string functions "
490b57cec5SDimitry Andric    "to find more errors.")
500b57cec5SDimitry AndricASAN_FLAG(bool, replace_intrin, true,
510b57cec5SDimitry Andric          "If set, uses custom wrappers for memset/memcpy/memmove intrinsics.")
52*81ad6265SDimitry AndricASAN_FLAG(bool, detect_stack_use_after_return,
53*81ad6265SDimitry Andric          SANITIZER_LINUX && !SANITIZER_ANDROID,
540b57cec5SDimitry Andric          "Enables stack-use-after-return checking at run-time.")
550b57cec5SDimitry AndricASAN_FLAG(int, min_uar_stack_size_log, 16,  // We can't do smaller anyway.
560b57cec5SDimitry Andric          "Minimum fake stack size log.")
570b57cec5SDimitry AndricASAN_FLAG(int, max_uar_stack_size_log,
580b57cec5SDimitry Andric          20, // 1Mb per size class, i.e. ~11Mb per thread
590b57cec5SDimitry Andric          "Maximum fake stack size log.")
600b57cec5SDimitry AndricASAN_FLAG(bool, uar_noreserve, false,
610b57cec5SDimitry Andric          "Use mmap with 'noreserve' flag to allocate fake stack.")
620b57cec5SDimitry AndricASAN_FLAG(
630b57cec5SDimitry Andric    int, max_malloc_fill_size, 0x1000,  // By default, fill only the first 4K.
640b57cec5SDimitry Andric    "ASan allocator flag. max_malloc_fill_size is the maximal amount of "
650b57cec5SDimitry Andric    "bytes that will be filled with malloc_fill_byte on malloc.")
660b57cec5SDimitry AndricASAN_FLAG(
670b57cec5SDimitry Andric    int, max_free_fill_size, 0,
680b57cec5SDimitry Andric    "ASan allocator flag. max_free_fill_size is the maximal amount of "
690b57cec5SDimitry Andric    "bytes that will be filled with free_fill_byte during free.")
700b57cec5SDimitry AndricASAN_FLAG(int, malloc_fill_byte, 0xbe,
710b57cec5SDimitry Andric          "Value used to fill the newly allocated memory.")
720b57cec5SDimitry AndricASAN_FLAG(int, free_fill_byte, 0x55,
730b57cec5SDimitry Andric          "Value used to fill deallocated memory.")
740b57cec5SDimitry AndricASAN_FLAG(bool, allow_user_poisoning, true,
750b57cec5SDimitry Andric          "If set, user may manually mark memory regions as poisoned or "
760b57cec5SDimitry Andric          "unpoisoned.")
770b57cec5SDimitry AndricASAN_FLAG(
780b57cec5SDimitry Andric    int, sleep_before_dying, 0,
790b57cec5SDimitry Andric    "Number of seconds to sleep between printing an error report and "
800b57cec5SDimitry Andric    "terminating the program. Useful for debugging purposes (e.g. when one "
810b57cec5SDimitry Andric    "needs to attach gdb).")
820b57cec5SDimitry AndricASAN_FLAG(
830b57cec5SDimitry Andric    int, sleep_after_init, 0,
840b57cec5SDimitry Andric    "Number of seconds to sleep after AddressSanitizer is initialized. "
850b57cec5SDimitry Andric    "Useful for debugging purposes (e.g. when one needs to attach gdb).")
86*81ad6265SDimitry AndricASAN_FLAG(
87*81ad6265SDimitry Andric    int, sleep_before_init, 0,
88*81ad6265SDimitry Andric    "Number of seconds to sleep before AddressSanitizer starts initializing. "
89*81ad6265SDimitry Andric    "Useful for debugging purposes (e.g. when one needs to attach gdb).")
900b57cec5SDimitry AndricASAN_FLAG(bool, check_malloc_usable_size, true,
910b57cec5SDimitry Andric          "Allows the users to work around the bug in Nvidia drivers prior to "
920b57cec5SDimitry Andric          "295.*.")
930b57cec5SDimitry AndricASAN_FLAG(bool, unmap_shadow_on_exit, false,
940b57cec5SDimitry Andric          "If set, explicitly unmaps the (huge) shadow at exit.")
95fe6060f1SDimitry AndricASAN_FLAG(bool, protect_shadow_gap, true, "If set, mprotect the shadow gap")
960b57cec5SDimitry AndricASAN_FLAG(bool, print_stats, false,
970b57cec5SDimitry Andric          "Print various statistics after printing an error message or if "
980b57cec5SDimitry Andric          "atexit=1.")
990b57cec5SDimitry AndricASAN_FLAG(bool, print_legend, true, "Print the legend for the shadow bytes.")
1000b57cec5SDimitry AndricASAN_FLAG(bool, print_scariness, false,
1010b57cec5SDimitry Andric          "Print the scariness score. Experimental.")
1020b57cec5SDimitry AndricASAN_FLAG(bool, atexit, false,
1030b57cec5SDimitry Andric          "If set, prints ASan exit stats even after program terminates "
1040b57cec5SDimitry Andric          "successfully.")
1050b57cec5SDimitry AndricASAN_FLAG(
1060b57cec5SDimitry Andric    bool, print_full_thread_history, true,
1070b57cec5SDimitry Andric    "If set, prints thread creation stacks for the threads involved in the "
1080b57cec5SDimitry Andric    "report and their ancestors up to the main thread.")
1090b57cec5SDimitry AndricASAN_FLAG(
1100b57cec5SDimitry Andric    bool, poison_heap, true,
1110b57cec5SDimitry Andric    "Poison (or not) the heap memory on [de]allocation. Zero value is useful "
1120b57cec5SDimitry Andric    "for benchmarking the allocator or instrumentator.")
1130b57cec5SDimitry AndricASAN_FLAG(bool, poison_partial, true,
1140b57cec5SDimitry Andric          "If true, poison partially addressable 8-byte aligned words "
1150b57cec5SDimitry Andric          "(default=true). This flag affects heap and global buffers, but not "
1160b57cec5SDimitry Andric          "stack buffers.")
1170b57cec5SDimitry AndricASAN_FLAG(bool, poison_array_cookie, true,
1180b57cec5SDimitry Andric          "Poison (or not) the array cookie after operator new[].")
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric// Turn off alloc/dealloc mismatch checker on Mac and Windows for now.
1210b57cec5SDimitry Andric// https://github.com/google/sanitizers/issues/131
1220b57cec5SDimitry Andric// https://github.com/google/sanitizers/issues/309
1230b57cec5SDimitry Andric// TODO(glider,timurrrr): Fix known issues and enable this back.
1240b57cec5SDimitry AndricASAN_FLAG(bool, alloc_dealloc_mismatch,
125*81ad6265SDimitry Andric          !SANITIZER_APPLE && !SANITIZER_WINDOWS && !SANITIZER_ANDROID,
1260b57cec5SDimitry Andric          "Report errors on malloc/delete, new/free, new/delete[], etc.")
1270b57cec5SDimitry Andric
1280b57cec5SDimitry AndricASAN_FLAG(bool, new_delete_type_mismatch, true,
1290b57cec5SDimitry Andric          "Report errors on mismatch between size of new and delete.")
1300b57cec5SDimitry AndricASAN_FLAG(
1310b57cec5SDimitry Andric    bool, strict_init_order, false,
1320b57cec5SDimitry Andric    "If true, assume that dynamic initializers can never access globals from "
1330b57cec5SDimitry Andric    "other modules, even if the latter are already initialized.")
1340b57cec5SDimitry AndricASAN_FLAG(
1350b57cec5SDimitry Andric    bool, start_deactivated, false,
1360b57cec5SDimitry Andric    "If true, ASan tweaks a bunch of other flags (quarantine, redzone, heap "
1370b57cec5SDimitry Andric    "poisoning) to reduce memory consumption as much as possible, and "
1380b57cec5SDimitry Andric    "restores them to original values when the first instrumented module is "
1390b57cec5SDimitry Andric    "loaded into the process. This is mainly intended to be used on "
1400b57cec5SDimitry Andric    "Android. ")
1410b57cec5SDimitry AndricASAN_FLAG(
1420b57cec5SDimitry Andric    int, detect_invalid_pointer_pairs, 0,
1430b57cec5SDimitry Andric    "If >= 2, detect operations like <, <=, >, >= and - on invalid pointer "
1440b57cec5SDimitry Andric    "pairs (e.g. when pointers belong to different objects); "
1450b57cec5SDimitry Andric    "If == 1, detect invalid operations only when both pointers are non-null.")
14668d75effSDimitry AndricASAN_FLAG(bool, detect_container_overflow, true,
1470b57cec5SDimitry Andric          "If true, honor the container overflow annotations. See "
14868d75effSDimitry Andric          "https://github.com/google/sanitizers/wiki/"
14968d75effSDimitry Andric          "AddressSanitizerContainerOverflow")
1500b57cec5SDimitry AndricASAN_FLAG(int, detect_odr_violation, 2,
1510b57cec5SDimitry Andric          "If >=2, detect violation of One-Definition-Rule (ODR); "
1520b57cec5SDimitry Andric          "If ==1, detect ODR-violation only if the two variables "
1530b57cec5SDimitry Andric          "have different sizes")
1540b57cec5SDimitry AndricASAN_FLAG(const char *, suppressions, "", "Suppressions file name.")
1550b57cec5SDimitry AndricASAN_FLAG(bool, halt_on_error, true,
1560b57cec5SDimitry Andric          "Crash the program after printing the first error report "
1570b57cec5SDimitry Andric          "(WARNING: USE AT YOUR OWN RISK!)")
1580b57cec5SDimitry AndricASAN_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true,
1590b57cec5SDimitry Andric          "realloc(p, 0) is equivalent to free(p) by default (Same as the "
1600b57cec5SDimitry Andric          "POSIX standard). If set to false, realloc(p, 0) will return a "
1610b57cec5SDimitry Andric          "pointer to an allocated space which can not be used.")
1620b57cec5SDimitry AndricASAN_FLAG(bool, verify_asan_link_order, true,
1630b57cec5SDimitry Andric          "Check position of ASan runtime in library list (needs to be disabled"
1640b57cec5SDimitry Andric          " when other library has to be preloaded system-wide)")
16568d75effSDimitry AndricASAN_FLAG(
16668d75effSDimitry Andric    bool, windows_hook_rtl_allocators, false,
1670b57cec5SDimitry Andric    "(Windows only) enable hooking of Rtl(Allocate|Free|Size|ReAllocate)Heap.")
168