From 372d5a5073db929b0cd1d43f9f76011901ddbe31 Mon Sep 17 00:00:00 2001 From: Sukhikh Alexander Date: Tue, 14 Nov 2023 16:03:21 +0300 Subject: [PATCH] Initial gwp-asan support for OHOS Signed-off-by: Sukhikh Alexander --- compiler-rt/cmake/config-ix.cmake | 2 +- compiler-rt/lib/gwp_asan/CMakeLists.txt | 11 ++++++++- .../lib/gwp_asan/optional/backtrace_ohos.cpp | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index a631ae4e86c3..bea474d581a2 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -861,7 +861,7 @@ endif() # TODO(hctim): Enable this on Android again. Looks like it's causing a SIGSEGV # for Scudo and GWP-ASan, further testing needed. if (GWP_ASAN_SUPPORTED_ARCH AND COMPILER_RT_BUILD_GWP_ASAN AND - OS_NAME MATCHES "Linux") + OS_NAME MATCHES "Linux|OHOS") set(COMPILER_RT_HAS_GWP_ASAN TRUE) else() set(COMPILER_RT_HAS_GWP_ASAN FALSE) diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt index bb5b2902f99d..a16cad3ea2fb 100644 --- a/compiler-rt/lib/gwp_asan/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt @@ -90,12 +90,21 @@ if (COMPILER_RT_HAS_GWP_ASAN) ADDITIONAL_HEADERS ${GWP_ASAN_OPTIONS_PARSER_HEADERS} CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) + # OHOS_LOCAL begin + if (OHOS) + set(BACKTRACE_SUPPORT_SOURCES optional/backtrace_ohos.cpp) + else() + set(BACKTRACE_SUPPORT_SOURCES optional/backtrace_linux_libc.cpp) + endif() + # As above, build the pre-implemented optional backtrace support libraries. add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES optional/backtrace_linux_libc.cpp + SOURCES ${BACKTRACE_SUPPORT_SOURCES} ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} CFLAGS ${GWP_ASAN_CFLAGS}) + #OHOS_LOCAL end + add_compiler_rt_object_libraries(RTGwpAsanSegvHandler ARCHS ${GWP_ASAN_SUPPORTED_ARCH} SOURCES optional/segv_handler_posix.cpp diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp new file mode 100644 index 000000000000..9e8468e04a02 --- /dev/null +++ b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp @@ -0,0 +1,24 @@ +//===-- backtrace_fuchsia.cpp -----------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "gwp_asan/optional/backtrace.h" + +#include + +namespace gwp_asan { +namespace backtrace { + +options::Backtrace_t getBacktraceFunction() { + return gwp_asan_unwind_fast; +} + +PrintBacktrace_t getPrintBacktraceFunction() { return gwp_asan_printf_back_trace; } +SegvBacktrace_t getSegvBacktraceFunction() { return gwp_asan_unwind_fast; } + +} // namespace backtrace +} // namespace gwp_asan -- Gitee