From e188222a409898159abfdb2fcb1c70c42fd49a3b Mon Sep 17 00:00:00 2001 From: guzhihao4 Date: Wed, 16 Oct 2024 10:17:41 +0800 Subject: [PATCH] [Sanitizer]Fix deadlock in report If sanitizer opens log_path file failed, reporting file will stcuk. Directly exit if opening log_path file failed. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IAXEZX Signed-off-by: guzhihao4 Change-Id: I13d30ae2d686f328f39ea32694291e9210a34160 --- compiler-rt/lib/sanitizer_common/sanitizer_file.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp index 7ef499ce07b1..dd791d190c2c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp @@ -21,6 +21,8 @@ #include "sanitizer_file.h" # include "sanitizer_interface_internal.h" +extern "C" SANITIZER_WEAK_ATTRIBUTE int musl_log(const char *fmt, ...); + namespace __sanitizer { void CatastrophicErrorWrite(const char *buffer, uptr length) { @@ -71,7 +73,14 @@ void ReportFile::ReopenIfNecessary() { char errmsg[100]; internal_snprintf(errmsg, sizeof(errmsg), " (reason: %d)", err); WriteToFile(kStderrFd, errmsg, internal_strlen(errmsg)); +#if SANITIZER_OHOS // OHOS_LOCAL + if (&musl_log) { + musl_log("%s %s %s\n", ErrorMsgPrefix, full_path, errmsg); + } + internal__exit(common_flags()->exitcode); +#else Die(); +#endif } fd_pid = pid; } -- Gitee