[llvm-commits] [compiler-rt] r165008 - in /compiler-rt/trunk: include/sanitizer/asan_interface.h lib/asan/asan_report.cc lib/asan/asan_rtl.cc lib/asan/lit_tests/on_error_callback.cc lib/asan/tests/asan_noinst_test.cc
Alexey Samsonov
samsonov at google.com
Tue Oct 2 07:06:40 PDT 2012
Author: samsonov
Date: Tue Oct 2 09:06:39 2012
New Revision: 165008
URL: http://llvm.org/viewvc/llvm-project?rev=165008&view=rev
Log:
[ASan] Change __asan_set_on_error_callback to weak overridable __asan_on_error, so that ASan would call the latter even if it finds the error early (i.e. during module initialization)
Added:
compiler-rt/trunk/lib/asan/lit_tests/on_error_callback.cc
Modified:
compiler-rt/trunk/include/sanitizer/asan_interface.h
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
Modified: compiler-rt/trunk/include/sanitizer/asan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/asan_interface.h?rev=165008&r1=165007&r2=165008&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/asan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/asan_interface.h Tue Oct 2 09:06:39 2012
@@ -128,12 +128,11 @@
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
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=165008&r1=165007&r2=165008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Tue Oct 2 09:06:39 2012
@@ -40,8 +40,6 @@
}
}
-static void (*on_error_callback)(void);
-
// ---------------------- Helper functions ----------------------- {{{1
static void PrintBytes(const char *before, uptr *a) {
@@ -293,9 +291,7 @@
}
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_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() {}
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=165008&r1=165007&r2=165008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Oct 2 09:06:39 2012
@@ -241,7 +241,7 @@
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;
Added: compiler-rt/trunk/lib/asan/lit_tests/on_error_callback.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/on_error_callback.cc?rev=165008&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/on_error_callback.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/on_error_callback.cc Tue Oct 2 09:06:39 2012
@@ -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
+}
Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=165008&r1=165007&r2=165008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Tue Oct 2 09:06:39 2012
@@ -530,12 +530,6 @@
__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) \
More information about the llvm-commits
mailing list