[llvm-commits] [compiler-rt] r153641 - in /compiler-rt/trunk/lib/asan: asan_interceptors.cc asan_interceptors.h asan_mac.cc asan_malloc_mac.cc

Alexander Potapenko glider at google.com
Thu Mar 29 05:20:47 PDT 2012


Author: glider
Date: Thu Mar 29 07:20:47 2012
New Revision: 153641

URL: http://llvm.org/viewvc/llvm-project?rev=153641&view=rev
Log:
Add internal_memset and replace the uses of REAL(memset) with it where the performance allows.


Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/asan/asan_interceptors.h
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_malloc_mac.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=153641&r1=153640&r2=153641&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Thu Mar 29 07:20:47 2012
@@ -267,6 +267,19 @@
   return 0;
 }
 
+// Should not be used in performance-critical places.
+void* internal_memset(void* s, int c, size_t n) {
+  // The next line prevents Clang from making a call to memset() instead of the
+  // loop below.
+  // FIXME: building the runtime with -ffreestanding is a better idea. However
+  // there currently are linktime problems due to PR12396.
+  char volatile *t = (char*)s;
+  for (size_t i = 0; i < n; ++i, ++t) {
+    *t = c;
+  }
+  return s;
+}
+
 char *internal_strstr(const char *haystack, const char *needle) {
   // This is O(N^2), but we are not using it in hot places.
   size_t len1 = internal_strlen(haystack);
@@ -497,7 +510,7 @@
 }
 
 INTERCEPTOR(void*, memset, void *block, int c, size_t size) {
-  // memset is called inside INTERCEPT_FUNCTION on Mac.
+  // memset is called inside Printf.
   if (asan_init_is_running) {
     return REAL(memset)(block, c, size);
   }

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=153641&r1=153640&r2=153641&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Thu Mar 29 07:20:47 2012
@@ -36,6 +36,7 @@
 size_t internal_strnlen(const char *s, size_t maxlen);
 char* internal_strchr(const char *s, int c);
 void* internal_memchr(const void* s, int c, size_t n);
+void* internal_memset(void *s, int c, size_t n);
 int internal_memcmp(const void* s1, const void* s2, size_t n);
 char *internal_strstr(const char *haystack, const char *needle);
 char *internal_strncat(char *dst, const char *src, size_t n);

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=153641&r1=153640&r2=153641&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Thu Mar 29 07:20:47 2012
@@ -386,9 +386,18 @@
     if (island_allocator_pos != (void*)kIslandBeg) {
       return KERN_NO_SPACE;
     }
+    if (FLAG_v) {
+      Report("Mapped pages %p--%p for branch islands.\n",
+             kIslandBeg, kIslandEnd);
+    }
+    // Should not be very performance-critical.
+    internal_memset(island_allocator_pos, 0xCC, kIslandEnd - kIslandBeg);
   };
   *ptr = island_allocator_pos;
   island_allocator_pos = (char*)island_allocator_pos + kPageSize;
+  if (FLAG_v) {
+    Report("Branch island allocated at %p\n", *ptr);
+  }
   return err_none;
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=153641&r1=153640&r2=153641&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Thu Mar 29 07:20:47 2012
@@ -313,7 +313,8 @@
 namespace __asan {
 void ReplaceSystemMalloc() {
   static malloc_introspection_t asan_introspection;
-  REAL(memset)(&asan_introspection, 0, sizeof(asan_introspection));
+  // Ok to use internal_memset, these places are not performance-critical.
+  internal_memset(&asan_introspection, 0, sizeof(asan_introspection));
 
   asan_introspection.enumerator = &mi_enumerator;
   asan_introspection.good_size = &mi_good_size;
@@ -324,7 +325,7 @@
   asan_introspection.force_unlock = &mi_force_unlock;
 
   static malloc_zone_t asan_zone;
-  REAL(memset)(&asan_zone, 0, sizeof(malloc_zone_t));
+  internal_memset(&asan_zone, 0, sizeof(malloc_zone_t));
 
   // Start with a version 4 zone which is used for OS X 10.4 and 10.5.
   asan_zone.version = 4;





More information about the llvm-commits mailing list