From 118ea51e5d4f3618c7e044133049601cd273a17a Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 31 Mar 2025 16:53:47 +0800 Subject: [PATCH] [Compier-RT][HWASAN] Prints the important options of hwasan Signed-off-by: Eric --- compiler-rt/lib/hwasan/hwasan.cpp | 35 +++++++++++++++++-- compiler-rt/lib/hwasan/hwasan_flags.inc | 23 ------------ .../lib/sanitizer_common/sanitizer_flags.inc | 2 ++ 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp index 652ed075150a..36977a73e484 100644 --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -70,6 +70,10 @@ static void RegisterHwasanFlags(FlagParser *parser, Flags *f) { #undef HWASAN_FLAG } +#define APPEND_BOOL_FLAG_CONETENT(defalutFlags, flags, S, param) \ + defalutFlags.append(#S " is "); \ + defalutFlags.append(flags->S == param ? "true. " : "false. "); + static void InitializeFlags() { SetCommonFlagsDefaults(); { @@ -104,9 +108,9 @@ static void InitializeFlags() { cf.handle_sigbus = kHandleSignalNo; cf.handle_abort = kHandleSignalNo; cf.allocator_may_return_null = true; + cf.allow_user_segv_handler = true; cf.log_exe_name = true; - cf.detect_leaks = false; - cf.print_module_map = 2; + cf.print_module_map = 1; cf.intercept_send = false; #endif // OHOS_LOCAL end @@ -144,6 +148,31 @@ static void InitializeFlags() { InitializeCommonFlags(); + // OHOS_LOCAL begin +#if SANITIZER_OHOS + if (common_flags()->verbose_format_important_flags) { + InternalScopedString defalutFlags; + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), + allocator_may_return_null, true); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), handle_abort, + kHandleSignalYes); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), log_exe_name, true); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), handle_segv, + kHandleSignalYes); + defalutFlags.append("print_module_map is "); + defalutFlags.append("%d. ", common_flags()->print_module_map); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), handle_sigbus, + kHandleSignalYes); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), intercept_send, + true); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, common_flags(), + allow_user_segv_handler, true); + APPEND_BOOL_FLAG_CONETENT(defalutFlags, flags(), halt_on_error, true); + Printf("The important option for hwasan is %s\n", defalutFlags.data()); + } +#endif + // OHOS_LOCAL end + if (Verbosity()) ReportUnrecognizedFlags(); if (common_flags()->help) parser.PrintFlagDescriptions(); @@ -203,7 +232,7 @@ void HwasanAtExit() { if (__hwasan::ShouldPrintQuarantineDwillTime()) hwasanThreadList().PrintfAverageQuarantineTime(); // OHOS_LOCAL end - if (common_flags()->print_module_map) + if (common_flags()->print_module_map > 1) DumpProcessMap(); if (flags()->print_stats && (flags()->atexit || hwasan_report_count > 0)) ReportStats(); diff --git a/compiler-rt/lib/hwasan/hwasan_flags.inc b/compiler-rt/lib/hwasan/hwasan_flags.inc index 2853e870bd84..e4719b2b6de1 100644 --- a/compiler-rt/lib/hwasan/hwasan_flags.inc +++ b/compiler-rt/lib/hwasan/hwasan_flags.inc @@ -130,27 +130,4 @@ HWASAN_FLAG( HWASAN_FLAG(bool, enable_heap_quarantine_debug, false, "Enable Hwasan Quarantine Debug Mode.") - -// Default minimum configuration -HWASAN_FLAG(bool, allow_user_segv_handler, true, - "Deprecated. True has no effect, use handle_sigbus=1. If false, " - "handle_*=1 will be upgraded to handle_*=2.") -HWASAN_FLAG(int, detect_odr_violation, 0, - "Default does not detect single defined rule (ODR) violations.") -HWASAN_FLAG(bool, alloc_dealloc_mismatch, false, - "Report errors on malloc/delete, new/free, new/delete[], etc.") -HWASAN_FLAG(bool, detect_container_overflow, false, - "If false, disabling out-of-bounds detection. See " - "https://github.com/google/sanitizers/wiki/" - "AddressSanitizerContainerOverflow") -HWASAN_FLAG( - int, report_globals, 0, - "Controls the way to handle globals (0 - don't detect buffer overflow on " - "globals, 1 - detect buffer overflow, 2 - print data about registered " - "globals).") -HWASAN_FLAG(bool, allow_user_poisoning, true, - "If set, user may manually mark memory regions as poisoned or " - "unpoisoned.") -HWASAN_FLAG(bool, detect_stack_use_after_return, false, - "Disables stack-use-after-return checking at run-time.") // OHOS_LOCAL end \ No newline at end of file diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc index 52c08d8e3ce2..9d2d7c05ad63 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc @@ -279,4 +279,6 @@ COMMON_FLAG(bool, test_only_emulate_no_memorymap, false, // OHOS_LOCAL begin COMMON_FLAG(bool, run_on_tw, false, "If true, no abort.") +COMMON_FLAG(bool, verbose_format_important_flags, false, + "Prints the important options of hwasan.") // OHOS_LOCAL end \ No newline at end of file -- Gitee