diff options
| author | Kostya Serebryany <kcc@google.com> | 2012-12-26 12:20:35 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2012-12-26 12:20:35 +0000 |
| commit | 390cf94f88b6cf6fb1900239cb48df6b046bff3a (patch) | |
| tree | d469563cfd1c09abb5128be6172f1c656a471700 | |
| parent | 5eb5bf8b46dd8f3e6f27b6d9ab0cead92e0bede9 (diff) | |
| download | bcm5719-llvm-390cf94f88b6cf6fb1900239cb48df6b046bff3a.tar.gz bcm5719-llvm-390cf94f88b6cf6fb1900239cb48df6b046bff3a.zip | |
[asan] asan_allocator2: do not align the requested size to the redzone size (saves a bit more memory)
llvm-svn: 171111
| -rw-r--r-- | compiler-rt/lib/asan/asan_allocator2.cc | 16 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_malloc_linux.cc | 5 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/tests/asan_test.cc | 2 |
3 files changed, 13 insertions, 10 deletions
diff --git a/compiler-rt/lib/asan/asan_allocator2.cc b/compiler-rt/lib/asan/asan_allocator2.cc index 745d7e4c2a4..425ce858591 100644 --- a/compiler-rt/lib/asan/asan_allocator2.cc +++ b/compiler-rt/lib/asan/asan_allocator2.cc @@ -202,8 +202,8 @@ struct AsanChunk: ChunkBase { 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 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack, 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 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack, 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 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack, 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); diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cc b/compiler-rt/lib/asan/asan_malloc_linux.cc index dabd9513fb9..b95cfe3149b 100644 --- a/compiler-rt/lib/asan/asan_malloc_linux.cc +++ b/compiler-rt/lib/asan/asan_malloc_linux.cc @@ -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*, pvalloc, uptr size) { } INTERCEPTOR(void, malloc_stats, void) { - Printf("AddressSanitizer malloc_stats()\n"); - Printf(" total mmapped: %zdM\n", - asanThreadRegistry().GetHeapSize() >> 20); + __asan_print_accumulated_stats(); } #endif // __linux__ diff --git a/compiler-rt/lib/asan/tests/asan_test.cc b/compiler-rt/lib/asan/tests/asan_test.cc index 60f67a1beb9..f9cc6644506 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cc +++ b/compiler-rt/lib/asan/tests/asan_test.cc @@ -251,7 +251,7 @@ void OOBTest() { 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; |

