[llvm-commits] [compiler-rt] r147788 - in /compiler-rt/trunk/lib/asan: Makefile.old asan_internal.h asan_linux.cc asan_mac.cc asan_posix.cc asan_rtl.cc asan_thread.cc

Kostya Serebryany kcc at google.com
Mon Jan 9 11:18:27 PST 2012


Author: kcc
Date: Mon Jan  9 13:18:27 2012
New Revision: 147788

URL: http://llvm.org/viewvc/llvm-project?rev=147788&view=rev
Log:
[asan] refactoring: move some common linux/mac code to asan_posix.cc

Added:
    compiler-rt/trunk/lib/asan/asan_posix.cc
Modified:
    compiler-rt/trunk/lib/asan/Makefile.old
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_linux.cc
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_thread.cc

Modified: compiler-rt/trunk/lib/asan/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/Makefile.old?rev=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/Makefile.old (original)
+++ compiler-rt/trunk/lib/asan/Makefile.old Mon Jan  9 13:18:27 2012
@@ -191,6 +191,7 @@
 	    $(BIN)/asan_malloc_linux$(SUFF).o \
 	    $(BIN)/asan_malloc_mac$(SUFF).o \
 	    $(BIN)/asan_poisoning$(SUFF).o  \
+	    $(BIN)/asan_posix$(SUFF).o  \
 	    $(BIN)/asan_printf$(SUFF).o  \
 	    $(BIN)/asan_stack$(SUFF).o  \
 	    $(BIN)/asan_stats$(SUFF).o  \

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon Jan  9 13:18:27 2012
@@ -107,6 +107,7 @@
 int AsanClose(int fd);
 
 bool AsanInterceptsSignal(int signum);
+void InstallSignalHandlers();
 
 // Opens the file 'file_name" and reads up to 'max_len' bytes.
 // The resulting buffer is mmaped and stored in '*buff'.

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Mon Jan  9 13:18:27 2012
@@ -276,13 +276,6 @@
   CHECK(AddrIsInStack((uintptr_t)&attr));
 }
 
-void AsanDisableCoreDumper() {
-  struct rlimit nocore;
-  nocore.rlim_cur = 0;
-  nocore.rlim_max = 0;
-  setrlimit(RLIMIT_CORE, &nocore);
-}
-
 }  // namespace __asan
 
 #endif  // __linux__

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Mon Jan  9 13:18:27 2012
@@ -131,13 +131,6 @@
   CHECK(AddrIsInStack((uintptr_t)&local));
 }
 
-void AsanDisableCoreDumper() {
-  struct rlimit nocore;
-  nocore.rlim_cur = 0;
-  nocore.rlim_max = 0;
-  setrlimit(RLIMIT_CORE, &nocore);
-}
-
 // Support for the following functions from libdispatch on Mac OS:
 //   dispatch_async_f()
 //   dispatch_async()

Added: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=147788&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (added)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Mon Jan  9 13:18:27 2012
@@ -0,0 +1,68 @@
+//===-- asan_linux.cc -----------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// Posix-specific details.
+//===----------------------------------------------------------------------===//
+#if defined(__linux__) || defined(__APPLE__)
+
+#include "asan_internal.h"
+#include "asan_interceptors.h"
+#include "asan_stack.h"
+#include "asan_thread_registry.h"
+
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+namespace __asan {
+
+static void MaybeInstallSigaction(int signum,
+                                  void (*handler)(int, siginfo_t *, void *)) {
+  if (!AsanInterceptsSignal(signum))
+    return;
+  struct sigaction sigact;
+  real_memset(&sigact, 0, sizeof(sigact));
+  sigact.sa_sigaction = handler;
+  sigact.sa_flags = SA_SIGINFO;
+  CHECK(0 == real_sigaction(signum, &sigact, 0));
+}
+
+static void     ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
+  uintptr_t addr = (uintptr_t)siginfo->si_addr;
+  // Write the first message using the bullet-proof write.
+  if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) ASAN_DIE;
+  uintptr_t pc, sp, bp;
+  GetPcSpBp(context, &pc, &sp, &bp);
+  Report("ERROR: AddressSanitizer crashed on unknown address %p"
+         " (pc %p sp %p bp %p T%d)\n",
+         addr, pc, sp, bp,
+         asanThreadRegistry().GetCurrentTidOrMinusOne());
+  Printf("AddressSanitizer can not provide additional info. ABORTING\n");
+  GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, false, pc, bp);
+  stack.PrintStack();
+  ShowStatsAndAbort();
+}
+
+void InstallSignalHandlers() {
+  MaybeInstallSigaction(SIGSEGV, ASAN_OnSIGSEGV);
+  MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV);
+}
+
+void AsanDisableCoreDumper() {
+  struct rlimit nocore;
+  nocore.rlim_cur = 0;
+  nocore.rlim_max = 0;
+  setrlimit(RLIMIT_CORE, &nocore);
+}
+
+}  // namespace __asan
+
+#endif  // __linux__ || __APPLE_

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=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Jan  9 13:18:27 2012
@@ -24,8 +24,6 @@
 #include "asan_thread.h"
 #include "asan_thread_registry.h"
 
-#include <pthread.h>
-#include <signal.h>
 #include <string.h>
 
 namespace __asan {
@@ -45,7 +43,6 @@
 int    FLAG_report_globals;
 size_t FLAG_malloc_context_size = kMallocContextSize;
 uintptr_t FLAG_large_malloc;
-bool   FLAG_lazy_shadow;
 bool   FLAG_handle_segv;
 bool   FLAG_replace_str;
 bool   FLAG_replace_intrin;
@@ -124,17 +121,6 @@
   return NULL;  // Not found.
 }
 
-static void MaybeInstallSigaction(int signum,
-                                  void (*handler)(int, siginfo_t *, void *)) {
-  if (!AsanInterceptsSignal(signum))
-    return;
-  struct sigaction sigact;
-  real_memset(&sigact, 0, sizeof(sigact));
-  sigact.sa_sigaction = handler;
-  sigact.sa_flags = SA_SIGINFO;
-  CHECK(0 == real_sigaction(signum, &sigact, 0));
-}
-
 // ---------------------- mmap -------------------- {{{1
 void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) {
   Report("ERROR: AddressSanitizer failed to allocate "
@@ -235,30 +221,6 @@
 }
 
 // -------------------------- Run-time entry ------------------- {{{1
-static void     ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
-  uintptr_t addr = (uintptr_t)siginfo->si_addr;
-  if (AddrIsInShadow(addr) && FLAG_lazy_shadow) {
-    // We traped on access to a shadow address. Just map a large chunk around
-    // this address.
-    const uintptr_t chunk_size = kPageSize << 10;  // 4M
-    uintptr_t chunk = addr & ~(chunk_size - 1);
-    AsanMmapFixedReserve(chunk, chunk_size);
-    return;
-  }
-  // Write the first message using the bullet-proof write.
-  if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) ASAN_DIE;
-  uintptr_t pc, sp, bp;
-  GetPcSpBp(context, &pc, &sp, &bp);
-  Report("ERROR: AddressSanitizer crashed on unknown address %p"
-         " (pc %p sp %p bp %p T%d)\n",
-         addr, pc, sp, bp,
-         asanThreadRegistry().GetCurrentTidOrMinusOne());
-  Printf("AddressSanitizer can not provide additional info. ABORTING\n");
-  GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, false, pc, bp);
-  stack.PrintStack();
-  ShowStatsAndAbort();
-}
-
 // exported functions
 #define ASAN_REPORT_ERROR(type, is_write, size)                     \
 extern "C" void __asan_report_ ## type ## size(uintptr_t addr)      \
@@ -318,8 +280,7 @@
 }
 
 void CheckFailed(const char *cond, const char *file, int line) {
-  Report("CHECK failed: %s at %s:%d, pthread_self=%p\n",
-         cond, file, line, pthread_self());
+  Report("CHECK failed: %s at %s:%d\n", cond, file, line);
   PRINT_CURRENT_STACK();
   ShowStatsAndAbort();
 }
@@ -454,7 +415,6 @@
   FLAG_atexit = IntFlagValue(options, "atexit=", 0);
   FLAG_poison_shadow = IntFlagValue(options, "poison_shadow=", 1);
   FLAG_report_globals = IntFlagValue(options, "report_globals=", 1);
-  FLAG_lazy_shadow = IntFlagValue(options, "lazy_shadow=", 0);
   FLAG_handle_segv = IntFlagValue(options, "handle_segv=", ASAN_NEEDS_SEGV);
   FLAG_symbolize = IntFlagValue(options, "symbolize=", 1);
   FLAG_demangle = IntFlagValue(options, "demangle=", 1);
@@ -479,9 +439,7 @@
   InitializeAsanInterceptors();
 
   ReplaceSystemMalloc();
-
-  MaybeInstallSigaction(SIGSEGV, ASAN_OnSIGSEGV);
-  MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV);
+  InstallSignalHandlers();
 
   if (FLAG_v) {
     Printf("|| `[%p, %p]` || HighMem    ||\n", kHighMemBeg, kHighMemEnd);
@@ -513,14 +471,12 @@
   }
 
   {
-    if (!FLAG_lazy_shadow) {
-      if (kLowShadowBeg != kLowShadowEnd) {
-        // mmap the low shadow plus one page.
-        ReserveShadowMemoryRange(kLowShadowBeg - kPageSize, kLowShadowEnd);
-      }
-      // mmap the high shadow.
-      ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd);
+    if (kLowShadowBeg != kLowShadowEnd) {
+      // mmap the low shadow plus one page.
+      ReserveShadowMemoryRange(kLowShadowBeg - kPageSize, kLowShadowEnd);
     }
+    // mmap the high shadow.
+    ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd);
     // protect the gap
     void *prot = AsanMprotect(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
     CHECK(prot == (void*)kShadowGapBeg);

Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=147788&r1=147787&r2=147788&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Mon Jan  9 13:18:27 2012
@@ -17,10 +17,6 @@
 #include "asan_thread.h"
 #include "asan_mapping.h"
 
-#include <pthread.h>
-#include <stdlib.h>
-#include <string.h>
-
 namespace __asan {
 
 AsanThread::AsanThread(LinkerInitialized x)
@@ -58,9 +54,9 @@
   fake_stack_.Init(stack_size());
   if (FLAG_v >= 1) {
     int local = 0;
-    Report("T%d: stack [%p,%p) size 0x%lx; local=%p, pthread_self=%p\n",
+    Report("T%d: stack [%p,%p) size 0x%lx; local=%p\n",
            tid(), stack_bottom_, stack_top_,
-           stack_top_ - stack_bottom_, &local, pthread_self());
+           stack_top_ - stack_bottom_, &local);
   }
 
   CHECK(AddrIsInMem(stack_bottom_));





More information about the llvm-commits mailing list