<div style="font-family: arial, helvetica, sans-serif"><font size="2">Yea, next commit will fix it... <br><br><div class="gmail_quote">On Fri, Jun 22, 2012 at 2:57 PM, Dmitry Vyukov <span dir="ltr"><<a href="mailto:dvyukov@google.com" target="_blank">dvyukov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:arial,helvetica,sans-serif"><font size="2"><br><br><div class="gmail_quote"><div><div class="h5">
On Thu, Jun 21, 2012 at 2:04 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kcc<br>
Date: Thu Jun 21 05:04:36 2012<br>
New Revision: 158913<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=158913&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=158913&view=rev</a><br>
Log:<br>
[tsan] first step in implementing a custom allocator for tsan (and msan) which saves precious shadow<br>
<br>
Added:<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h<br>
compiler-rt/trunk/lib/sanitizer_common/tests/<br>
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc<br>
Modified:<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
compiler-rt/trunk/lib/tsan/Makefile.old<br>
<br>
Added: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h?rev=158913&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h?rev=158913&view=auto</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h (added)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h Thu Jun 21 05:04:36 2012<br>
@@ -0,0 +1,80 @@<br>
+//===-- sanitizer_allocator64.h ---------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+// Specialized allocator which works only in 64-bit address space.<br>
+// To be used by ThreadSanitizer, MemorySanitizer and possibly other tools.<br>
+// The main feature of this allocator is that the header is located far away<br>
+// from the user memory region, so that the tool does not use extra shadow<br>
+// for the header.<br>
+//<br>
+// Status: not yet ready.<br>
+//===----------------------------------------------------------------------===//<br>
+#ifndef SANITIZER_ALLOCATOR_H<br>
+#define SANITIZER_ALLOCATOR_H<br>
+<br>
+#include "sanitizer_common.h"<br>
+#include "sanitizer_internal_defs.h"<br>
+<br>
+namespace __sanitizer {<br>
+<br>
+// Maps size class to size and back.<br>
+class DefaultSizeClassMap {<br>
+ private:<br>
+ // Here we use a spline composed of 5 polynomials of oder 1.<br>
+ // The first size class is l0, then the classes go with step s0<br>
+ // untill they reach l1, after which they go with step s1 and so on.<br>
+ // Steps should be powers of two for cheap division.<br>
+ // The size of the last size class should be a power of two.<br>
+ // There should be at most 256 size classes.<br>
+ static const uptr l0 = 1 << 4;<br>
+ static const uptr l1 = 1 << 9;<br>
+ static const uptr l2 = 1 << 12;<br>
+ static const uptr l3 = 1 << 15;<br>
+ static const uptr l4 = 1 << 18;<br>
+ static const uptr l5 = 1 << 21;<br>
+<br>
+ static const uptr s0 = 1 << 4;<br>
+ static const uptr s1 = 1 << 6;<br>
+ static const uptr s2 = 1 << 9;<br>
+ static const uptr s3 = 1 << 12;<br>
+ static const uptr s4 = 1 << 15;<br>
+<br>
+ static const uptr u0 = 0 + (l1 - l0) / s0;<br>
+ static const uptr u1 = u0 + (l2 - l1) / s1;<br>
+ static const uptr u2 = u1 + (l3 - l2) / s2;<br>
+ static const uptr u3 = u2 + (l4 - l3) / s3;<br>
+ static const uptr u4 = u3 + (l5 - l4) / s4;<br>
+<br>
+ public:<br>
+ static const uptr kNumClasses = u4 + 1;<br>
+ static const uptr kMaxSize = l5;<br>
+<br>
+ COMPILER_CHECK(kNumClasses <= 256);<br>
+ COMPILER_CHECK((kMaxSize & (kMaxSize - 1)) == 0);<br>
+<br>
+ static uptr Size(uptr size_class) {<br>
+ if (size_class <= u0) return l0 + s0 * (size_class - 0);<br>
+ if (size_class <= u1) return l1 + s1 * (size_class - u0);<br>
+ if (size_class <= u2) return l2 + s2 * (size_class - u1);<br>
+ if (size_class <= u3) return l3 + s3 * (size_class - u2);<br>
+ if (size_class <= u4) return l4 + s4 * (size_class - u3);<br>
+ return 0;<br>
+ }<br>
+ static uptr Class(uptr size) {<br>
+ if (size <= l1) return 0 + (size - l0 + s0 - 1) / s0;<br>
+ if (size <= l2) return u0 + (size - l1 + s1 - 1) / s1;<br>
+ if (size <= l3) return u1 + (size - l2 + s2 - 1) / s2;<br>
+ if (size <= l4) return u2 + (size - l3 + s3 - 1) / s3;<br>
+ if (size <= l5) return u3 + (size - l4 + s4 - 1) / s4;<br>
+ return 0;<br>
+ }<br>
+};<br>
+<br>
+} // namespace __sanitizer<br>
+<br>
+#endif // SANITIZER_ALLOCATOR_H<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=158913&r1=158912&r2=158913&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=158913&r1=158912&r2=158913&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Thu Jun 21 05:04:36 2012<br>
@@ -107,6 +107,12 @@<br>
<br>
#define UNIMPLEMENTED() CHECK("unimplemented" && 0)<br>
<br>
+#define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)<br>
+<br>
+#define IMPL_PASTE(a, b) a##b<br>
+#define IMPL_COMPILER_ASSERT(pred, line) \<br>
+ typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1];<br>
+<br>
// Limits for integral types. We have to redefine it in case we don't<br>
// have stdint.h (like in Visual Studio 9).<br>
#if __WORDSIZE == 64<br>
<br>
Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc?rev=158913&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc?rev=158913&view=auto</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc (added)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator64_test.cc Thu Jun 21 05:04:36 2012<br>
@@ -0,0 +1,43 @@<br>
+//===-- sanitizer_allocator64_test.cc -------------------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+// Tests for sanitizer_allocator64.h.<br>
+//===----------------------------------------------------------------------===//<br>
+#include "sanitizer_common/sanitizer_allocator64.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+TEST(SanitizerCommon, DefaultSizeClassMap) {<br>
+ typedef DefaultSizeClassMap SCMap;<br>
+<br>
+ for (uptr i = 0; i < SCMap::kNumClasses; i++) {<br>
+ // printf("% 3ld: % 5ld (%4lx); ", i, SCMap::Size(i), SCMap::Size(i));<br>
+ printf("c%ld => %ld ", i, SCMap::Size(i));<br></blockquote><div><br></div></div></div><div>Can we have less output by default?</div><div><div class="h5"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if ((i % 8) == 7)<br>
+ printf("\n");<br>
+ }<br>
+ printf("\n");<br>
+<br>
+ for (uptr c = 0; c < SCMap::kNumClasses; c++) {<br>
+ uptr s = SCMap::Size(c);<br>
+ CHECK_EQ(SCMap::Class(s), c);<br>
+ if (c != SCMap::kNumClasses - 1)<br>
+ CHECK_EQ(SCMap::Class(s + 1), c + 1);<br>
+ CHECK_EQ(SCMap::Class(s - 1), c);<br>
+ if (c)<br>
+ CHECK_GT(SCMap::Size(c), SCMap::Size(c-1));<br>
+ }<br>
+ CHECK_EQ(SCMap::Class(SCMap::kMaxSize + 1), 0);<br>
+<br>
+ for (uptr s = 1; s <= SCMap::kMaxSize; s++) {<br>
+ uptr c = SCMap::Class(s);<br>
+ CHECK_LT(c, SCMap::kNumClasses);<br>
+ CHECK_GE(SCMap::Size(c), s);<br>
+ if (c > 0)<br>
+ CHECK_LT(SCMap::Size(c-1), s);<br>
+ }<br>
+}<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/Makefile.old<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=158913&r1=158912&r2=158913&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=158913&r1=158912&r2=158913&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/Makefile.old (original)<br>
+++ compiler-rt/trunk/lib/tsan/Makefile.old Thu Jun 21 05:04:36 2012<br>
@@ -21,7 +21,7 @@<br>
RTL_TEST_OBJ=$(patsubst %.cc,%.o,$(RTL_TEST_SRC))<br>
UNIT_TEST_SRC=$(wildcard unit_tests/*_test.cc)<br>
UNIT_TEST_OBJ=$(patsubst %.cc,%.o,$(UNIT_TEST_SRC))<br>
-UNIT_TEST_HDR=$(wildcard rtl/*.h)<br>
+UNIT_TEST_HDR=$(wildcard rtl/*.h) $(wildcard ../sanitizer_common/*.h)<br>
<br>
INCLUDES=-Irtl -I.. $(GTEST_INCLUDE)<br>
<br>
@@ -44,9 +44,6 @@<br>
%.o: %.cc $(UNIT_TEST_HDR)<br>
$(CXX) $(CXXFLAGS) $(CFLAGS) $(INCLUDES) -o $@ -c $<<br>
<br>
-#rtl_tests/%.o: rtl_tests/%.cc $(LIBTSAN_HEADERS)<br>
-# $(CXX) $(CXXFLAGS) $(CFLAGS) $(INCLUDES) -o $@ -c $<<br>
-<br>
tsan_test: $(TEST_OBJ) $(UNIT_TEST_OBJ) $(RTL_TEST_OBJ) \<br>
$(SANITIZER_COMMON_TESTS_OBJ) $(LIBTSAN) $(GTEST_LIB)<br>
$(CXX) $^ -o $@ $(LDFLAGS)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div><br></font></div>
</blockquote></div><br></font></div>