#!/bin/bash # Displays supported ASAN options # gcc 4.9.2 does not support ASAN_OPTIONS=help=1 # It was merged to gcc at 2014-05-22 # https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7d752f28b590bbad13c877c2aa7f5f8de2cdff10 : ${CC:=clang} gcc_ver=$("$CC" --version | awk 'NR==1 && $1=="gcc" { print $3 }') if [[ $gcc_ver == 4.9.* ]]; then CC=clang fi # Colors for keywords CON=$(tput bold; tput setaf 3) COFF=$(tput sgr0) gcc_4_9_sanitizer_common=" allocator_may_return_null detect_leaks external_symbolizer_path fast_unwind_on_fatal fast_unwind_on_malloc handle_ioctl leak_check_at_exit log_path malloc_context_size print_summary strip_path_prefix symbolize verbosity " gcc_4_9_asan_opts=" $gcc_4_9_sanitizer_common abort_on_error alloc_dealloc_mismatch allow_reexec allow_user_poisoning allow_user_segv_handler atexit check_initialization_order check_malloc_usable_size coverage debug detect_stack_use_after_return disable_core exitcode handle_segv mac_ignore_invalid_free malloc_fill_byte max_malloc_fill_size poison_heap poison_partial print_full_thread_history print_legend print_stats quarantine_size redzone replace_intrin replace_str report_globals sleep_before_dying strict_init_order strict_memcmp uar_stack_size_log unmap_shadow_on_exit use_sigaltstack " tmp=$(mktemp) trap 'rm "$tmp"' EXIT echo 'int main(void){ return 0; }' | $CC -fsanitize=address -x c - -o "$tmp" ASAN_OPTIONS=help=1 "$tmp" 2>&1 | gawk -vgcc_4_9_asan_opts="$gcc_4_9_asan_opts" -vgcc_ver="$gcc_ver" ' BEGIN { n = split(gcc_4_9_asan_opts, gcc49_opts_); split("", gcc49_opts); for (i = 1; i <= n; i++) { gcc49_opts[gcc49_opts_[i]] = 1; } split("", desc); } /^\t[^\t]/ { name = $1; } /^\t\t- / { desc[name] = $0; } END { asorti(desc, desc_indices); for (i in desc_indices) { word = desc_indices[i]; suffix = ""; if (!gcc49_opts[word]) { suffix = " [!gcc49]"; } print "\t" word suffix; print desc[word]; } } ' | sed -r "s/^(\\t)([a-z0-9_]+)/\\1${CON}\\2${COFF}/"