[compiler-rt] r314052 - [ubsan] Support signal specific options in ubsan

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 19:47:11 PDT 2017


Author: vitalybuka
Date: Fri Sep 22 19:47:11 2017
New Revision: 314052

URL: http://llvm.org/viewvc/llvm-project?rev=314052&view=rev
Log:
[ubsan] Support signal specific options in ubsan

Summary:
Part of https://github.com/google/sanitizers/issues/637

Standalone ubsan needs signal and sigaction handlers and interceptors.
Plugin mode should rely on parent tool.

Reviewers: eugenis, alekseyshl

Subscribers: kubamracek, llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D37895

Added:
    compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.h
Modified:
    compiler-rt/trunk/lib/ubsan/CMakeLists.txt
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc

Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Fri Sep 22 19:47:11 2017
@@ -11,6 +11,7 @@ set(UBSAN_SOURCES
 set(UBSAN_STANDALONE_SOURCES
   ubsan_diag_standalone.cc
   ubsan_init_standalone.cc
+  ubsan_signals_standalone.cc
   )
 
 set(UBSAN_CXXABI_SOURCES
@@ -77,6 +78,7 @@ if(APPLE)
                   RTUbsan_standalone
                   RTSanitizerCommon
                   RTSanitizerCommonLibc
+                  RTInterception
       LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
       PARENT_TARGET ubsan)
   endif()
@@ -144,6 +146,7 @@ else()
               RTSanitizerCommonLibc
               RTUbsan
               RTUbsan_standalone
+              RTInterception
       CFLAGS ${UBSAN_CFLAGS}
       PARENT_TARGET ubsan)
 
@@ -162,6 +165,7 @@ else()
               RTSanitizerCommonLibc
               RTUbsan
               RTUbsan_standalone
+              RTInterception
         CFLAGS ${UBSAN_CFLAGS}
         LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}
         LINK_LIBS ${UBSAN_DYNAMIC_LIBS}

Modified: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc Fri Sep 22 19:47:11 2017
@@ -18,11 +18,17 @@
 
 #include "sanitizer_common/sanitizer_internal_defs.h"
 #include "ubsan_init.h"
+#include "ubsan_signals_standalone.h"
+
+namespace __ubsan {
 
 class UbsanStandaloneInitializer {
  public:
   UbsanStandaloneInitializer() {
-    __ubsan::InitAsStandalone();
+    InitAsStandalone();
+    InitializeDeadlySignals();
   }
 };
 static UbsanStandaloneInitializer ubsan_standalone_initializer;
+
+} // namespace __ubsan

Modified: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc Fri Sep 22 19:47:11 2017
@@ -19,8 +19,19 @@
 
 #include "sanitizer_common/sanitizer_internal_defs.h"
 #include "ubsan_init.h"
+#include "ubsan_signals_standalone.h"
 
 #if SANITIZER_CAN_USE_PREINIT_ARRAY
+
+namespace __ubsan {
+
+static void PreInitAsStandalone() {
+  InitAsStandalone();
+  InitializeDeadlySignals();
+}
+
+} // namespace __ubsan
+
 __attribute__((section(".preinit_array"), used)) void (*__local_ubsan_preinit)(
-    void) = __ubsan::InitAsStandalone;
+    void) = __ubsan::PreInitAsStandalone;
 #endif // SANITIZER_CAN_USE_PREINIT_ARRAY

Added: compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc?rev=314052&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc (added)
+++ compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc Fri Sep 22 19:47:11 2017
@@ -0,0 +1,50 @@
+//=-- ubsan_signals_standalone.cc
+//------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Installs signal handlers and related interceptors for UBSan standalone.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ubsan_platform.h"
+#if CAN_SANITIZE_UB
+#include "interception/interception.h"
+#include "sanitizer_common/sanitizer_stacktrace.h"
+#include "ubsan_diag.h"
+#include "ubsan_init.h"
+
+#define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name)
+#include "sanitizer_common/sanitizer_signal_interceptors.inc"
+
+namespace __ubsan {
+
+static void OnStackUnwind(const SignalContext &sig, const void *,
+                          BufferedStackTrace *stack) {
+  GetStackTraceWithPcBpAndContext(stack, kStackTraceMax, sig.pc, sig.bp,
+                                  sig.context,
+                                  common_flags()->fast_unwind_on_fatal);
+}
+
+static void UBsanOnDeadlySignal(int signo, void *siginfo, void *context) {
+  HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
+}
+
+static bool is_initialized = false;
+
+void InitializeDeadlySignals() {
+  if (is_initialized)
+    return;
+  is_initialized = true;
+  InitializeSignalInterceptors();
+  InstallDeadlySignalHandlers(&UBsanOnDeadlySignal);
+}
+
+} // namespace __ubsan
+
+#endif // CAN_SANITIZE_UB

Added: compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.h?rev=314052&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.h (added)
+++ compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.h Fri Sep 22 19:47:11 2017
@@ -0,0 +1,25 @@
+//=-- ubsan_signals_standalone.h
+//------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Installs signal handlers and related interceptors for UBSan standalone.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef UBSAN_SIGNALS_STANDALONE_H
+#define UBSAN_SIGNALS_STANDALONE_H
+
+namespace __ubsan {
+
+// Initializes signal handlers and interceptors.
+void InitializeDeadlySignals();
+
+} // namespace __ubsan
+
+#endif // UBSAN_SIGNALS_STANDALONE_H

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/allow_user_segv.cc Fri Sep 22 19:47:11 2017
@@ -20,7 +20,6 @@
 // Remove when fixed: https://github.com/google/sanitizers/issues/637
 // XFAIL: msan
 // XFAIL: tsan
-// XFAIL: ubsan
 
 #include <signal.h>
 #include <stdio.h>

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc Fri Sep 22 19:47:11 2017
@@ -7,10 +7,9 @@
 // RUN: env %tool_options='abort_on_error=0, dedup_token_length=3' not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK3 --match-full-lines
 
 // REQUIRES: stable-runtime
-// FIXME: implement SEGV handler in other sanitizers, not just asan.
+// FIXME: implement SEGV handler in other sanitizers.
 // XFAIL: msan
 // XFAIL: tsan
-// XFAIL: ubsan
 
 volatile int *null = 0;
 

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dump_instruction_bytes.cc Fri Sep 22 19:47:11 2017
@@ -11,7 +11,6 @@
 // FIXME: implement in other sanitizers.
 // XFAIL: msan
 // XFAIL: tsan
-// XFAIL: ubsan
 
 int main() {
 #if defined(__x86_64__)

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc?rev=314052&r1=314051&r2=314052&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc Fri Sep 22 19:47:11 2017
@@ -9,7 +9,6 @@
 // FIXME: implement SEGV handler in other sanitizers, not just asan.
 // XFAIL: msan
 // XFAIL: tsan
-// XFAIL: ubsan
 
 #include <sanitizer/common_interface_defs.h>
 #include <stdio.h>




More information about the llvm-commits mailing list