[compiler-rt] r280885 - [sanitizer] Fix a conflict between abort_on_error and handle_abort.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 7 16:40:53 PDT 2016
Author: eugenis
Date: Wed Sep 7 18:40:53 2016
New Revision: 280885
URL: http://llvm.org/viewvc/llvm-project?rev=280885&view=rev
Log:
[sanitizer] Fix a conflict between abort_on_error and handle_abort.
Reset the SIGABRT signal handler before calling abort().
Also, change the error message when catching SIGABRT to say "ABRT"
instead of "SEGV".
Added:
compiler-rt/trunk/test/asan/TestCases/Posix/handle_abort_on_error.cc
Modified:
compiler-rt/trunk/lib/asan/asan_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=280885&r1=280884&r2=280885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Wed Sep 7 18:40:53 2016
@@ -88,6 +88,8 @@ void AsanOnDeadlySignal(int signo, void
ReportDeadlySignal("FPE", sig);
else if (signo == SIGILL)
ReportDeadlySignal("ILL", sig);
+ else if (signo == SIGABRT)
+ ReportDeadlySignal("ABRT", sig);
else
ReportDeadlySignal("SEGV", sig);
}
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=280885&r1=280884&r2=280885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Wed Sep 7 18:40:53 2016
@@ -44,6 +44,8 @@
#define MAP_NORESERVE 0
#endif
+typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
+
namespace __sanitizer {
u32 GetUid() {
@@ -126,6 +128,14 @@ void SleepForMillis(int millis) {
}
void Abort() {
+ // If we are handling SIGABRT, unhandle it first.
+ if (IsHandledDeadlySignal(SIGABRT)) {
+ struct sigaction sigact;
+ internal_memset(&sigact, 0, sizeof(sigact));
+ sigact.sa_sigaction = (sa_sigaction_t)SIG_DFL;
+ internal_sigaction(SIGABRT, &sigact, nullptr);
+ }
+
abort();
}
@@ -170,7 +180,6 @@ void UnsetAlternateSignalStack() {
UnmapOrDie(oldstack.ss_sp, oldstack.ss_size);
}
-typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
static void MaybeInstallSigaction(int signum,
SignalHandlerType handler) {
if (!IsHandledDeadlySignal(signum))
Added: compiler-rt/trunk/test/asan/TestCases/Posix/handle_abort_on_error.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/handle_abort_on_error.cc?rev=280885&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/handle_abort_on_error.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/handle_abort_on_error.cc Wed Sep 7 18:40:53 2016
@@ -0,0 +1,9 @@
+// Regression test: this used to abort() in SIGABRT handler in an infinite loop.
+// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=handle_abort=1,abort_on_error=1 not --crash %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+
+int main() {
+ abort();
+ // CHECK: ERROR: AddressSanitizer: ABRT
+}
More information about the llvm-commits
mailing list