[PATCH] D144830: [asan darwin] Allow clients to implement `__sanitizer_report_error_summary`

Dave MacLachlan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 09:16:47 PST 2023


dmaclach updated this revision to Diff 502684.
dmaclach added a comment.

Added test in asan. There wasn't an easy spot to put it in the sanitizer_common tests because I wanted to verify that the actual sanitizer libraries  were calling through correctly when `__sanitizer_report_error_summary` was overridden.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144830/new/

https://reviews.llvm.org/D144830

Files:
  compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
  compiler-rt/test/asan/TestCases/report_error_summary.cpp


Index: compiler-rt/test/asan/TestCases/report_error_summary.cpp
===================================================================
--- /dev/null
+++ compiler-rt/test/asan/TestCases/report_error_summary.cpp
@@ -0,0 +1,16 @@
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+void __sanitizer_report_error_summary(const char *summary) {
+  fprintf(stderr, "__sanitizer_report_error_summary - %s\n", summary);
+  fflush(stderr);
+}
+
+int main() {
+  char *x = new char[20];
+  delete[] x;
+  return x[0];
+  // CHECK: __sanitizer_report_error_summary - SUMMARY: AddressSanitizer: heap-use-after-free {{.*}}report_error_summary.cpp:[[@LINE-2]]{{.*}} main
+}
Index: compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -989,7 +989,7 @@
   // "wrap_puts" within our own dylib.
   Dl_info info_puts, info_runtime;
   RAW_CHECK(dladdr(dlsym(RTLD_DEFAULT, "puts"), &info_puts));
-  RAW_CHECK(dladdr((void *)__sanitizer_report_error_summary, &info_runtime));
+  RAW_CHECK(dladdr((void*)&VerifyInterceptorsWorking, &info_runtime));
   if (internal_strcmp(info_puts.dli_fname, info_runtime.dli_fname) != 0) {
     Report(
         "ERROR: Interceptors are not working. This may be because %s is "
@@ -1039,7 +1039,7 @@
     return;
 
   Dl_info info;
-  RAW_CHECK(dladdr((void *)__sanitizer_report_error_summary, &info));
+  RAW_CHECK(dladdr((void*)&StripEnv, &info));
   const char *dylib_name = StripModuleName(info.dli_fname);
   bool lib_is_in_env = internal_strstr(dyld_insert_libraries, dylib_name);
   if (!lib_is_in_env)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144830.502684.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230306/5b676892/attachment.bin>


More information about the llvm-commits mailing list