Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AddressSanitizerFlags

chefmax edited this pageMay 15, 2019 ·25 revisions

Compiler flags

flagdescription
-fsanitize=addressEnableAddressSanitizer
-fno-omit-frame-pointerLeave frame pointers. Allows the fast unwinder to function properly.
-fsanitize-blacklist=pathPass ablacklist file
-fno-commonDo not treat global variable in C as common variables (allows ASan to instrument them)

ASan-specific compile-time flags are passed via clang flag-mllvm <flag>. In most cases you don't need them.

flagdefaultdescription
-asan-stack1Detect overflow/underflow for stack objects
-asan-globals1Detect overflow/underflow for global objects
-asan-use-private-alias0Use private aliases for global objects

Run-time flags

Most run-time flags are passed toAddressSanitizer viaASAN_OPTIONS environment variable like this:

ASAN_OPTIONS=verbosity=1:malloc_context_size=20 ./a.out

but you could also embed default flags in the source code by implementing __asan_default_options function:

const char *__asan_default_options() {  return "verbosity=1:malloc_context_size=20";}

Note that the list below list may be (and probably is) incomplete. Also older versions of ASan may not support some of the listed flags. To get the idea of what's supported in your version, run

ASAN_OPTIONS=help=1 ./a.out

For the list of common sanitizer options seeSanitizerCommonFlags

FlagDefault valueDescription
quarantine_size-1Deprecated, please use quarantine_size_mb.
quarantine_size_mb256 (16 on iOS or Android)Size (in Mb) of quarantine used to detect use-after-free errors. Lower value may reduce memory usage but increase the chance of false negatives.
redzone16Minimal size (in bytes) of redzones around heap objects. Requirement: redzone >= 16, is a power of two.
max_redzone2048Maximal size (in bytes) of redzones around heap objects.
debugfalseIf set, prints some debugging information and does additional checks.
report_globals1Controls the way to handle globals (0 - don't detect buffer overflow on globals, 1 - detect buffer overflow, 2 - print data about registered globals).
check_initialization_orderfalseIf set, attempts to catch initialization order issues.
replace_strtrueIf set, uses custom wrappers and replacements for libc string functions to find more errors.
replace_intrintrueIf set, uses custom wrappers for memset/memcpy/memmove intinsics.
detect_stack_use_after_returnfalseEnables stack-use-after-return checking at run-time.
min_uar_stack_size_log16Minimum fake stack size log.
max_uar_stack_size_log20Maximum fake stack size log.
uar_noreservefalseUse mmap with 'noreserve' flag to allocate fake stack.
max_malloc_fill_size4096ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes that will be filled with malloc_fill_byte on malloc.
malloc_fill_byte0xbeValue used to fill the newly allocated memory.
allow_user_poisoningtrueIf set, user may manually mark memory regions as poisoned or unpoisoned.
sleep_before_dying0Number of seconds to sleep between printing an error report and terminating the program. Useful for debugging purposes (e.g. when one needs to attach gdb).
check_malloc_usable_sizetrueAllows the users to work around the bug in Nvidia drivers prior to 295.*.
unmap_shadow_on_exitfalseIf set, explicitly unmaps the (huge) shadow at exit.
protect_shadow_gaptrueIf set, mprotect the shadow gap
print_statsfalsePrint various statistics after printing an error message or if atexit=1.
print_legendtruePrint the legend for the shadow bytes.
atexitfalseIf set, prints ASan exit stats even after program terminates successfully.
print_full_thread_historytrueIf set, prints thread creation stacks for the threads involved in the report and their ancestors up to the main thread.
poison_heaptruePoison (or not) the heap memory on [de]allocation. Zero value is useful for benchmarking the allocator or instrumentator.
poison_partialtrueIf true, poison partially addressable 8-byte aligned words (default=true). This flag affects heap and global buffers, but not stack buffers.
poison_array_cookietruePoison (or not) the array cookie after operator new[].
alloc_dealloc_mismatchtrue (false on Darwin and Windows)Report errors on malloc/delete, new/free, new/delete[], etc.
new_delete_type_mismatchtrueReport errors on mismatch betwen size of new and delete.
strict_init_orderfalseIf true, assume that dynamic initializers can never access globals from other modules, even if the latter are already initialized.
strict_string_checksfalseIf true, check that string arguments are properly null-terminated.
start_deactivatedfalseIf true, ASan tweaks a bunch of other flags (quarantine, redzone, heap poisoning) to reduce memory consumption as much as possible, and restores them to original values when the first instrumented module is loaded into the process. This is mainly intended to be used on Android.
detect_invalid_pointer_pairs0If non-zero, try to detect operations like <, <=, >, >= and - on invalid pointer pairs (e.g. when pointers belong to different objects). The bigger the value the harder we try.
detect_container_overflowtrueIf true, honor the container overflow annotations. SeeContainerOverflow
detect_odr_violation2If >=2, detect violation of One-Definition-Rule (ODR); If ==1, detect ODR-violation only if the two variables have different sizes
dump_instruction_bytesfalseIf true, dump 16 bytes starting at the instruction that caused SEGV
suppressions""Suppressions file name.
halt_on_errortrueCrash the program after printing the first error report (WARNING: USE AT YOUR OWN RISK!). The flag has effect only if code was compiled with -fsanitize-recover=address compile option.
log_pathstderrWrite logs tolog_path.pid. The special values arestdout andstderr
use_odr_indicatorfalseUse special ODR indicator symbol for ODR violation detection.
allocator_frees_and_returns_
null_on_realloc_zero
truerealloc(p, 0) is equivalent to free(p) by default (Same as the POSIX standard). If set to false, realloc(p, 0) will return a pointer to an allocated space which can not be used.
verify_asan_link_ordertrueCheck position of ASan runtime in library list (needs to be disabled when other library has to be preloaded system-wide)

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp