diff options
| -rw-r--r-- | compiler-rt/include/sanitizer/asan_interface.h | 11 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_report.cc | 13 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/lit_tests/on_error_callback.cc | 16 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/tests/asan_noinst_test.cc | 6 |
5 files changed, 27 insertions, 21 deletions
diff --git a/compiler-rt/include/sanitizer/asan_interface.h b/compiler-rt/include/sanitizer/asan_interface.h index 787e8116c9d..788e90f4cca 100644 --- a/compiler-rt/include/sanitizer/asan_interface.h +++ b/compiler-rt/include/sanitizer/asan_interface.h @@ -128,12 +128,11 @@ extern "C" { void __asan_set_error_report_callback(void (*callback)(const char*)) SANITIZER_INTERFACE_ATTRIBUTE; - // Sets the callback to be called right when ASan detects an error. - // This can be used to notice cases when ASan detects an error, but the - // program crashes before ASan report is printed. - // Passing 0 unsets the callback. - void __asan_set_on_error_callback(void (*callback)(void)) - SANITIZER_INTERFACE_ATTRIBUTE; + // User may provide function that would be called right when ASan detects + // an error. This can be used to notice cases when ASan detects an error, but + // the program crashes before ASan report is printed. + void __asan_on_error() + SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; // User may provide its own implementation for symbolization function. // It should print the description of instruction at address "pc" to diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 5baba45808e..4b7baa686e5 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -40,8 +40,6 @@ void AppendToErrorMessageBuffer(const char *buffer) { } } -static void (*on_error_callback)(void); - // ---------------------- Helper functions ----------------------- {{{1 static void PrintBytes(const char *before, uptr *a) { @@ -293,9 +291,7 @@ class ScopedInErrorReport { } Die(); } - if (on_error_callback) { - on_error_callback(); - } + __asan_on_error(); reporting_thread_tid = asanThreadRegistry().GetCurrentTidOrInvalid(); Printf("====================================================" "=============\n"); @@ -492,6 +488,7 @@ void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) { } } -void NOINLINE __asan_set_on_error_callback(void (*callback)(void)) { - on_error_callback = callback; -} +// Provide default implementation of __asan_on_error that does nothing +// and may be overriden by user. +SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE NOINLINE +void __asan_on_error() {} diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index c7aedb28b3f..14667e641d4 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -241,7 +241,7 @@ static NOINLINE void force_interface_symbols() { case 27: __asan_set_error_exit_code(0); break; case 28: __asan_stack_free(0, 0, 0); break; case 29: __asan_stack_malloc(0, 0); break; - case 30: __asan_set_on_error_callback(0); break; + case 30: __asan_on_error(); break; case 31: __asan_default_options(); break; case 32: __asan_before_dynamic_init(0, 0); break; case 33: __asan_after_dynamic_init(); break; diff --git a/compiler-rt/lib/asan/lit_tests/on_error_callback.cc b/compiler-rt/lib/asan/lit_tests/on_error_callback.cc new file mode 100644 index 00000000000..bb94d9fb579 --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/on_error_callback.cc @@ -0,0 +1,16 @@ +// RUN: %clangxx_asan -O2 %s -o %t && %t 2>&1 | FileCheck %s + +#include <stdio.h> +#include <stdlib.h> + +extern "C" +void __asan_on_error() { + fprintf(stderr, "__asan_on_error called"); +} + +int main() { + char *x = (char*)malloc(10 * sizeof(char)); + free(x); + return x[5]; + // CHECK: __asan_on_error called +} diff --git a/compiler-rt/lib/asan/tests/asan_noinst_test.cc b/compiler-rt/lib/asan/tests/asan_noinst_test.cc index 037af9e8365..5b286b7bf60 100644 --- a/compiler-rt/lib/asan/tests/asan_noinst_test.cc +++ b/compiler-rt/lib/asan/tests/asan_noinst_test.cc @@ -530,12 +530,6 @@ TEST(AddressSanitizerInterface, DeathCallbackTest) { __asan_set_death_callback(NULL); } -TEST(AddressSanitizerInterface, OnErrorCallbackTest) { - __asan_set_on_error_callback(MyDeathCallback); - EXPECT_DEATH(DoDoubleFree(), "MyDeathCallback.*double-free"); - __asan_set_on_error_callback(NULL); -} - static const char* kUseAfterPoisonErrorMessage = "use-after-poison"; #define GOOD_ACCESS(ptr, offset) \ |

