[compiler-rt] 28dc3aa - [asan darwin] Allow clients to implement `__sanitizer_report_error_summary`

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 16:37:56 PST 2023


Author: Dave MacLachlan
Date: 2023-03-06T16:37:45-08:00
New Revision: 28dc3aa7bc9f20f7f283663d63744ed4785a6e7b

URL: https://github.com/llvm/llvm-project/commit/28dc3aa7bc9f20f7f283663d63744ed4785a6e7b
DIFF: https://github.com/llvm/llvm-project/commit/28dc3aa7bc9f20f7f283663d63744ed4785a6e7b.diff

LOG: [asan darwin] Allow clients to implement `__sanitizer_report_error_summary`

`__sanitizer_report_error_summary` is declared `llvm/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h` as being able to be overridden by the client. On darwin the sanitizer runtime uses this symbol to find references to the sanitizer libraries, so if you override it you end up with the error `=ERROR: Interceptors are not working. This may be because AddressSanitizer is loaded too late (e.g. via dlopen). Please launch the executable with:` at launch time.

Replace uses of `__sanitizer_report_error_summary` for finding the sanitizer libraries with using the address of a local function.

Reviewed By: yln, vitalybuka

Differential Revision: https://reviews.llvm.org/D144830

Added: 
    compiler-rt/test/asan/TestCases/report_error_summary.cpp

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index 23c4c6619de82..fa04fdad18e35 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -989,7 +989,7 @@ static void VerifyInterceptorsWorking() {
   // "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 @@ static void StripEnv() {
     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)

diff  --git a/compiler-rt/test/asan/TestCases/report_error_summary.cpp b/compiler-rt/test/asan/TestCases/report_error_summary.cpp
new file mode 100644
index 0000000000000..f9d0310bf62a7
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/report_error_summary.cpp
@@ -0,0 +1,17 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+extern "C" void __sanitizer_report_error_summary(const char *summary) {
+  fprintf(stderr, "test_report_error_summary\n", summary);
+  // CHECK: test_report_error_summary
+  fflush(stderr);
+}
+
+char *x;
+
+int main() {
+  x = new char[20];
+  delete[] x;
+  return x[0];
+}


        


More information about the llvm-commits mailing list