[compiler-rt] r225337 - [asan] add flag quarantine_size_mb, deprecate quarantine_size
Kostya Serebryany
kcc at google.com
Tue Jan 6 18:37:52 PST 2015
Author: kcc
Date: Tue Jan 6 20:37:52 2015
New Revision: 225337
URL: http://llvm.org/viewvc/llvm-project?rev=225337&view=rev
Log:
[asan] add flag quarantine_size_mb, deprecate quarantine_size
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/quarantine_size_mb.cc
Modified:
compiler-rt/trunk/lib/asan/asan_allocator.cc
compiler-rt/trunk/lib/asan/asan_flags.cc
compiler-rt/trunk/lib/asan/asan_flags.inc
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
compiler-rt/trunk/test/asan/TestCases/Posix/tsd_dtor_leak.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Tue Jan 6 20:37:52 2015
@@ -206,7 +206,7 @@ QuarantineCache *GetQuarantineCache(Asan
}
void AllocatorOptions::SetFrom(const Flags *f, const CommonFlags *cf) {
- quarantine_size_mb = f->quarantine_size >> 20;
+ quarantine_size_mb = f->quarantine_size_mb;
min_redzone = f->redzone;
max_redzone = f->max_redzone;
may_return_null = cf->allocator_may_return_null;
@@ -214,7 +214,7 @@ void AllocatorOptions::SetFrom(const Fla
}
void AllocatorOptions::CopyTo(Flags *f, CommonFlags *cf) {
- f->quarantine_size = (int)quarantine_size_mb << 20;
+ f->quarantine_size_mb = quarantine_size_mb;
f->redzone = min_redzone;
f->max_redzone = max_redzone;
cf->allocator_may_return_null = may_return_null;
Modified: compiler-rt/trunk/lib/asan/asan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.cc?rev=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.cc Tue Jan 6 20:37:52 2015
@@ -64,6 +64,7 @@ void InitializeFlags(Flags *f) {
OverrideCommonFlags(cf);
}
+ const int kDefaultQuarantineSizeMb = (ASAN_LOW_MEMORY) ? 1UL << 6 : 1UL << 8;
f->SetDefaults();
// Override from compile definition.
@@ -118,6 +119,18 @@ void InitializeFlags(Flags *f) {
CHECK_LE(f->max_redzone, 2048);
CHECK(IsPowerOfTwo(f->redzone));
CHECK(IsPowerOfTwo(f->max_redzone));
+
+ // quarantine_size is deprecated but we still honor it.
+ // quarantine_size can not be used together with quarantine_size_mb.
+ if (f->quarantine_size >= 0 && f->quarantine_size_mb >= 0) {
+ Report("%s: please use either 'quarantine_size' (deprecated) or "
+ "quarantine_size_mb, but not both\n", SanitizerToolName);
+ Die();
+ }
+ if (f->quarantine_size >= 0)
+ f->quarantine_size_mb = f->quarantine_size >> 20;
+ if (f->quarantine_size_mb < 0)
+ f->quarantine_size_mb = kDefaultQuarantineSizeMb;
}
} // namespace __asan
Modified: compiler-rt/trunk/lib/asan/asan_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.inc?rev=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.inc (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.inc Tue Jan 6 20:37:52 2015
@@ -17,8 +17,10 @@
// ASAN_FLAG(Type, Name, DefaultValue, Description)
// See COMMON_FLAG in sanitizer_flags.inc for more details.
-ASAN_FLAG(int, quarantine_size, (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28,
- "Size (in bytes) of quarantine used to detect use-after-free "
+ASAN_FLAG(int, quarantine_size, -1,
+ "Deprecated, please use quarantine_size_mb.")
+ASAN_FLAG(int, quarantine_size_mb, -1,
+ "Size (in Mb) of quarantine used to detect use-after-free "
"errors. Lower value may reduce memory usage but increase the "
"chance of false negatives.")
ASAN_FLAG(int, redzone, 16,
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=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan 6 20:37:52 2015
@@ -281,7 +281,7 @@ static void PrintAddressSpaceLayout() {
Printf("\n");
Printf("redzone=%zu\n", (uptr)flags()->redzone);
Printf("max_redzone=%zu\n", (uptr)flags()->max_redzone);
- Printf("quarantine_size=%zuM\n", (uptr)flags()->quarantine_size >> 20);
+ Printf("quarantine_size_mb=%zuM\n", (uptr)flags()->quarantine_size_mb);
Printf("malloc_context_size=%zu\n",
(uptr)common_flags()->malloc_context_size);
Added: compiler-rt/trunk/test/asan/TestCases/Linux/quarantine_size_mb.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/quarantine_size_mb.cc?rev=225337&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/quarantine_size_mb.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/quarantine_size_mb.cc Tue Jan 6 20:37:52 2015
@@ -0,0 +1,24 @@
+// Test quarantine_size_mb (and the deprecated quarantine_size)
+// RUN: %clangxx_asan %s -o %t
+// RUN: ASAN_OPTIONS=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: ASAN_OPTIONS=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: ASAN_OPTIONS=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
+// RUN: ASAN_OPTIONS=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: ASAN_OPTIONS=hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+#include <string.h>
+char *g;
+
+static const int kNumAllocs = 1 << 11;
+static const int kAllocSize = 1 << 20;
+
+int main() {
+ for (int i = 0; i < kNumAllocs; i++) {
+ g = new char[kAllocSize];
+ memset(g, -1, kAllocSize);
+ delete [] (g);
+ }
+}
+
+// Q10: quarantine_size_mb=10M
+// BOTH: please use either 'quarantine_size' (deprecated) or quarantine_size_mb, but not both
+// RSS_LIMIT: AddressSanitizer: hard rss limit exhausted
Modified: compiler-rt/trunk/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc?rev=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc Tue Jan 6 20:37:52 2015
@@ -2,7 +2,7 @@
// RUN: %clangxx_asan %s -o %t
// The memory is released only when the deallocated chunk leaves the quarantine,
// otherwise the mmap(p, ...) call overwrites the malloc header.
-// RUN: ASAN_OPTIONS=quarantine_size=1 %run %t
+// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
#include <assert.h>
#include <string.h>
Modified: compiler-rt/trunk/test/asan/TestCases/Posix/tsd_dtor_leak.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/tsd_dtor_leak.cc?rev=225337&r1=225336&r2=225337&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/tsd_dtor_leak.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/tsd_dtor_leak.cc Tue Jan 6 20:37:52 2015
@@ -1,7 +1,7 @@
// Regression test for a leak in tsd:
// https://code.google.com/p/address-sanitizer/issues/detail?id=233
// RUN: %clangxx_asan -O1 %s -pthread -o %t
-// RUN: ASAN_OPTIONS=quarantine_size=1 %run %t
+// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,22 +25,17 @@ void Dtor(void *tsd) {
int main() {
assert(0 == pthread_key_create(&tsd_key, Dtor));
- size_t old_heap_size = 0;
+ pthread_t t;
+ for (int i = 0; i < 3; i++) {
+ pthread_create(&t, 0, Thread, 0);
+ pthread_join(t, 0);
+ }
+ size_t old_heap_size = __sanitizer_get_heap_size();
for (int i = 0; i < 10; i++) {
- pthread_t t;
pthread_create(&t, 0, Thread, 0);
pthread_join(t, 0);
size_t new_heap_size = __sanitizer_get_heap_size();
fprintf(stderr, "heap size: new: %zd old: %zd\n", new_heap_size, old_heap_size);
- if (old_heap_size)
- assert(old_heap_size == new_heap_size);
-#if defined(__FreeBSD__)
- // On FreeBSD SYSCALL(sched_yielld) allocates some more space during the
- // 2nd attempt.
- if (i > 0)
- old_heap_size = new_heap_size;
-#else
- old_heap_size = new_heap_size;
-#endif
+ assert(old_heap_size == new_heap_size);
}
}
More information about the llvm-commits
mailing list