Skip to content

Commit 28dc3aa

Browse files
Dave MacLachlanvitalybuka
authored andcommitted
[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
1 parent aa728ff commit 28dc3aa

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ static void VerifyInterceptorsWorking() {
989989
// "wrap_puts" within our own dylib.
990990
Dl_info info_puts, info_runtime;
991991
RAW_CHECK(dladdr(dlsym(RTLD_DEFAULT, "puts"), &info_puts));
992-
RAW_CHECK(dladdr((void *)__sanitizer_report_error_summary, &info_runtime));
992+
RAW_CHECK(dladdr((void *)&VerifyInterceptorsWorking, &info_runtime));
993993
if (internal_strcmp(info_puts.dli_fname, info_runtime.dli_fname) != 0) {
994994
Report(
995995
"ERROR: Interceptors are not working. This may be because %s is "
@@ -1039,7 +1039,7 @@ static void StripEnv() {
10391039
return;
10401040

10411041
Dl_info info;
1042-
RAW_CHECK(dladdr((void *)__sanitizer_report_error_summary, &info));
1042+
RAW_CHECK(dladdr((void *)&StripEnv, &info));
10431043
const char *dylib_name = StripModuleName(info.dli_fname);
10441044
bool lib_is_in_env = internal_strstr(dyld_insert_libraries, dylib_name);
10451045
if (!lib_is_in_env)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
3+
#include <stdio.h>
4+
5+
extern "C" void __sanitizer_report_error_summary(const char *summary) {
6+
fprintf(stderr, "test_report_error_summary\n", summary);
7+
// CHECK: test_report_error_summary
8+
fflush(stderr);
9+
}
10+
11+
char *x;
12+
13+
int main() {
14+
x = new char[20];
15+
delete[] x;
16+
return x[0];
17+
}

0 commit comments

Comments
 (0)