[compiler-rt] r236474 - [asan] under handle_abort=1 option intercept SIGABRT in addition to SIGSEGV/SIGBUS. Among other things this will allow to set up a death callback for SIGABRT and thus properly handle assert() in lib/Fuzzer

Kostya Serebryany kcc at google.com
Mon May 4 18:37:33 PDT 2015


Author: kcc
Date: Mon May  4 20:37:33 2015
New Revision: 236474

URL: http://llvm.org/viewvc/llvm-project?rev=236474&view=rev
Log:
[asan] under handle_abort=1 option intercept SIGABRT in addition to SIGSEGV/SIGBUS. Among other things this will allow to set up a death callback for SIGABRT and thus properly handle assert() in lib/Fuzzer

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=236474&r1=236473&r2=236474&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Mon May  4 20:37:33 2015
@@ -67,8 +67,9 @@ COMMON_FLAG(bool, print_summary, true,
             "reports.")
 COMMON_FLAG(bool, check_printf, true, "Check printf arguments.")
 COMMON_FLAG(bool, handle_segv, SANITIZER_NEEDS_SEGV,
-            "If set, registers the tool's custom SEGV handler (both SIGBUS and "
-            "SIGSEGV on OSX).")
+            "If set, registers the tool's custom SIGSEGV/SIGBUS handler.")
+COMMON_FLAG(bool, handle_abort, false,
+            "If set, registers the tool's custom SIGABRT handler.")
 COMMON_FLAG(bool, allow_user_segv_handler, false,
             "If set, allows user to register a SEGV handler even if the tool "
             "registers one.")

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=236474&r1=236473&r2=236474&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon May  4 20:37:33 2015
@@ -907,6 +907,8 @@ void GetExtraActivationFlags(char *buf,
 #endif
 
 bool IsDeadlySignal(int signum) {
+  if (common_flags()->handle_abort)
+    return signum == SIGABRT;
   return (signum == SIGSEGV || signum == SIGBUS) && common_flags()->handle_segv;
 }
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=236474&r1=236473&r2=236474&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Mon May  4 20:37:33 2015
@@ -178,6 +178,7 @@ void InstallDeadlySignalHandlers(SignalH
   if (common_flags()->use_sigaltstack) SetAlternateSignalStack();
   MaybeInstallSigaction(SIGSEGV, handler);
   MaybeInstallSigaction(SIGBUS, handler);
+  MaybeInstallSigaction(SIGABRT, handler);
 }
 #endif  // SANITIZER_GO
 

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc?rev=236474&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/assert.cc Mon May  4 20:37:33 2015
@@ -0,0 +1,24 @@
+// Test the handle_abort option.
+// RUN: %clang %s -o %t
+// RUN:                              not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
+// RUN: %tool_options=handle_abort=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
+// RUN: %tool_options=handle_abort=1 not         %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
+// FIXME: implement in other sanitizers, not just asan.
+// XFAIL: msan
+// XFAIL: lsan
+// XFAIL: tsan
+#include <assert.h>
+#include <stdio.h>
+#include <sanitizer/asan_interface.h>
+
+void death() {
+  fprintf(stderr, "DEATH CALLBACK\n");
+}
+
+int main(int argc, char **argv) {
+  __sanitizer_set_death_callback(death);
+  assert(argc == 100);
+}
+// CHECK1: ERROR: {{.*}}Sanitizer:
+// CHECK1: DEATH CALLBACK
+// CHECK0-NOT: Sanitizer





More information about the llvm-commits mailing list