[llvm-commits] [compiler-rt] r171111 - in /compiler-rt/trunk/lib/asan: asan_allocator2.cc asan_malloc_linux.cc tests/asan_test.cc

Kostya Serebryany kcc at google.com
Wed Dec 26 04:20:35 PST 2012


Author: kcc
Date: Wed Dec 26 06:20:35 2012
New Revision: 171111

URL: http://llvm.org/viewvc/llvm-project?rev=171111&view=rev
Log:
[asan] asan_allocator2: do not align the requested size to the redzone size (saves a bit more memory)

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator2.cc
    compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
    compiler-rt/trunk/lib/asan/tests/asan_test.cc

Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=171111&r1=171110&r2=171111&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Wed Dec 26 06:20:35 2012
@@ -202,8 +202,8 @@
     return (u32*)(Beg() + kChunkHeader2Size);
   }
   uptr FreeStackSize() {
-    uptr available = Max(RoundUpTo(UsedSize(), SHADOW_GRANULARITY),
-                         (uptr)RZLog2Size(rz_log));
+    if (user_requested_size < kChunkHeader2Size) return 0;
+    uptr available = RoundUpTo(user_requested_size, SHADOW_GRANULARITY);
     return (available - kChunkHeader2Size) / sizeof(u32);
   }
 };
@@ -317,7 +317,9 @@
                       AllocType alloc_type) {
   Init();
   CHECK(stack);
-  if (alignment < 8) alignment = 8;
+  const uptr min_alignment = SHADOW_GRANULARITY;
+  if (alignment < min_alignment)
+    alignment = min_alignment;
   if (size == 0) {
     if (alignment <= kReturnOnZeroMalloc)
       return reinterpret_cast<void *>(kReturnOnZeroMalloc);
@@ -327,9 +329,11 @@
   CHECK(IsPowerOfTwo(alignment));
   uptr rz_log = ComputeRZLog(size);
   uptr rz_size = RZLog2Size(rz_log);
-  uptr rounded_size = RoundUpTo(size, rz_size);
+  uptr rounded_size = RoundUpTo(size, alignment);
+  if (rounded_size < kChunkHeader2Size)
+    rounded_size = kChunkHeader2Size;
   uptr needed_size = rounded_size + rz_size;
-  if (alignment > rz_size)
+  if (alignment > min_alignment)
     needed_size += alignment;
   bool using_primary_allocator = true;
   // If we are allocating from the secondary allocator, there will be no
@@ -338,7 +342,7 @@
     needed_size += rz_size;
     using_primary_allocator = false;
   }
-  CHECK(IsAligned(needed_size, rz_size));
+  CHECK(IsAligned(needed_size, min_alignment));
   if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize) {
     Report("WARNING: AddressSanitizer failed to allocate %p bytes\n",
            (void*)size);

Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=171111&r1=171110&r2=171111&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Wed Dec 26 06:20:35 2012
@@ -20,6 +20,7 @@
 #include "asan_internal.h"
 #include "asan_stack.h"
 #include "asan_thread_registry.h"
+#include "sanitizer/asan_interface.h"
 
 #if ASAN_ANDROID
 DECLARE_REAL_AND_INTERCEPTOR(void*, malloc, uptr size)
@@ -143,9 +144,7 @@
 }
 
 INTERCEPTOR(void, malloc_stats, void) {
-  Printf("AddressSanitizer malloc_stats()\n");
-  Printf("  total mmapped: %zdM\n",
-         asanThreadRegistry().GetHeapSize() >> 20);
+  __asan_print_accumulated_stats();
 }
 
 #endif  // __linux__

Modified: compiler-rt/trunk/lib/asan/tests/asan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test.cc?rev=171111&r1=171110&r2=171111&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc Wed Dec 26 06:20:35 2012
@@ -251,7 +251,7 @@
     for (int i = 0; i < (int)(size - sizeof(T) + 1); i++)
       oob_test<T>(size, i);
 
-    for (int i = size - sizeof(T) + 1; i <= (int)(size + 3 * sizeof(T)); i++) {
+    for (int i = size - sizeof(T) + 1; i <= (int)(size + 2 * sizeof(T)); i++) {
       const char *str =
           "is located.*%d byte.*to the right";
       int off = i >= size ? (i - size) : 0;





More information about the llvm-commits mailing list