From bbfe638fcf260323ede6c76956899346061d8df6 Mon Sep 17 00:00:00 2001 From: liuguangfeng Date: Mon, 25 Nov 2024 19:27:14 +0800 Subject: [PATCH 1/2] [sanitizer] gwp_asan test case fix Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/IB6XRN?from=project-issue Signed-off-by: liuguangfeng --- compiler-rt/test/gwp_asan/backtrace.c | 8 +++----- compiler-rt/test/gwp_asan/lit.cfg.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/compiler-rt/test/gwp_asan/backtrace.c b/compiler-rt/test/gwp_asan/backtrace.c index f4be7305bfb7..57a507b918a6 100644 --- a/compiler-rt/test/gwp_asan/backtrace.c +++ b/compiler-rt/test/gwp_asan/backtrace.c @@ -28,10 +28,8 @@ __attribute__((noinline)) void touch_mem(void *ptr) { // CHECK: allocate_mem int main() { - for (unsigned i = 0; i < 0x10000; ++i) { - void *ptr = allocate_mem(); - free_mem(ptr); - touch_mem(ptr); - } + void *ptr = allocate_mem(); + free_mem(ptr); + touch_mem(ptr); return 0; } diff --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py index 58658a4551dc..848135a2f900 100644 --- a/compiler-rt/test/gwp_asan/lit.cfg.py +++ b/compiler-rt/test/gwp_asan/lit.cfg.py @@ -44,7 +44,7 @@ config.substitutions.append(( # Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is # enabled and that it samples every allocation. -default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1' +default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1:GWP_ASAN_MaxSimultaneousAllocations=500' config.environment['SCUDO_OPTIONS'] = default_gwp_asan_options default_gwp_asan_options += ':' -- Gitee From 5ad0761949a7b785f944319edf7ab43db9a6b826 Mon Sep 17 00:00:00 2001 From: liuguangfeng Date: Thu, 28 Nov 2024 10:21:04 +0800 Subject: [PATCH 2/2] [sanitizer] gwp_asan test case fix gwp_asan test case fix Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/IB6XRN?from=project-issue Test:gwp_asan test Signed-off-by: liuguangfeng --- .../lib/gwp_asan/optional/backtrace_ohos.cpp | 15 +++++++++------ compiler-rt/test/gwp_asan/backtrace.c | 12 ++++++++++++ compiler-rt/test/gwp_asan/lit.cfg.py | 7 ++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp index 4ac52449b7d7..ad9ceddbb1b3 100644 --- a/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp +++ b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp @@ -17,9 +17,12 @@ extern "C" char **backtrace_symbols(void *const *trace, size_t len); #include "print_backtrace_linux_libc.inc" +// Consistent with musl extern "C" GWP_ASAN_WEAK size_t -libc_gwp_asan_unwind_fast(size_t *frame_buf, size_t max_record_stack, - __attribute__((unused)) void *signal_context); +libc_gwp_asan_unwind_fast(size_t *frame_buf, size_t max_record_stack); + +extern "C" GWP_ASAN_WEAK size_t +libc_gwp_asan_unwind_segv(size_t *frame_buf, size_t max_record_stack, void *signal_context); namespace gwp_asan { namespace backtrace { @@ -30,14 +33,14 @@ options::Backtrace_t getBacktraceFunction() { assert(&libc_gwp_asan_unwind_fast && "libc_gwp_asan_unwind_fast wasn't provided from musl."); return [](size_t *frame_buf, size_t max_record_stack) { - return libc_gwp_asan_unwind_fast(frame_buf, max_record_stack, nullptr); + return libc_gwp_asan_unwind_fast(frame_buf, max_record_stack); }; } PrintBacktrace_t getPrintBacktraceFunction() { return PrintBacktrace; } SegvBacktrace_t getSegvBacktraceFunction() { - assert(&libc_gwp_asan_unwind_fast && - "libc_gwp_asan_unwind_fast wasn't provided from musl."); - return libc_gwp_asan_unwind_fast; + assert(&libc_gwp_asan_unwind_segv && + "libc_gwp_asan_unwind_segv wasn't provided from musl."); + return libc_gwp_asan_unwind_segv; } } // namespace backtrace diff --git a/compiler-rt/test/gwp_asan/backtrace.c b/compiler-rt/test/gwp_asan/backtrace.c index 57a507b918a6..1f8d781d9437 100644 --- a/compiler-rt/test/gwp_asan/backtrace.c +++ b/compiler-rt/test/gwp_asan/backtrace.c @@ -28,8 +28,20 @@ __attribute__((noinline)) void touch_mem(void *ptr) { // CHECK: allocate_mem int main() { +// OHOS_LOCAL begin +#ifdef __OHOS__ + // Tested in OHOS, it can be detected with just one execution, without the need for multiple loops. + // If the number of loops is too high, it may cause all slots to be occupied void *ptr = allocate_mem(); free_mem(ptr); touch_mem(ptr); +#else + for (unsigned i = 0; i < 0x10000; ++i) { + void *ptr = allocate_mem(); + free_mem(ptr); + touch_mem(ptr); + } +#endif +// OHOS_LOCAL end return 0; } diff --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py index 848135a2f900..8140916128cf 100644 --- a/compiler-rt/test/gwp_asan/lit.cfg.py +++ b/compiler-rt/test/gwp_asan/lit.cfg.py @@ -44,7 +44,12 @@ config.substitutions.append(( # Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is # enabled and that it samples every allocation. -default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1:GWP_ASAN_MaxSimultaneousAllocations=500' +if config.host_os == 'OHOS': # OHOS_LOCAL + # The default value for GWP_ASAN_MaxSimulataneousAllocations is 16, which is not sufficient for gwp-asan testing + # in OHOS, resulting in many test cases being unable to trigger gwp-asan detection. + default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1:GWP_ASAN_MaxSimultaneousAllocations=500' +else: + default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1' config.environment['SCUDO_OPTIONS'] = default_gwp_asan_options default_gwp_asan_options += ':' -- Gitee