[compiler-rt] f018246 - [scudo][standalone] Enabled SCUDO_DEBUG for tests + fixes

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 08:34:22 PST 2019


Author: Kostya Kortchinsky
Date: 2019-11-15T08:33:57-08:00
New Revision: f018246c20481d222af4bab1868e8903c35c73d2

URL: https://github.com/llvm/llvm-project/commit/f018246c20481d222af4bab1868e8903c35c73d2
DIFF: https://github.com/llvm/llvm-project/commit/f018246c20481d222af4bab1868e8903c35c73d2.diff

LOG: [scudo][standalone] Enabled SCUDO_DEBUG for tests + fixes

Summary:
`SCUDO_DEBUG` was not enabled for unit tests, meaning the `DCHECK`s
were never tripped. While turning this on, I discovered that a few
of those not-exercised checks were actually wrong. This CL addresses
those incorrect checks.

Not that to work in tests `CHECK_IMPL` has to explicitely use the
`scudo` namespace. Also changes a C cast to a C++ cast.

Reviewers: hctim, pcc, cferris, eugenis, vitalybuka

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D70276

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/combined.h
    compiler-rt/lib/scudo/standalone/internal_defs.h
    compiler-rt/lib/scudo/standalone/secondary.h
    compiler-rt/lib/scudo/standalone/size_class_map.h
    compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
    compiler-rt/lib/scudo/standalone/vector.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 2f8d82b58db3..f4fa5d4b99ad 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -222,7 +222,7 @@ template <class Params> class Allocator {
     if (UNLIKELY(!isAligned(UserPtr, Alignment))) {
       const uptr AlignedUserPtr = roundUpTo(UserPtr, Alignment);
       const uptr Offset = AlignedUserPtr - UserPtr;
-      DCHECK_GT(Offset, 2 * sizeof(u32));
+      DCHECK_GE(Offset, 2 * sizeof(u32));
       // The BlockMarker has no security purpose, but is specifically meant for
       // the chunk iteration function that can be used in debugging situations.
       // It is the only situation where we have to locate the start of a chunk

diff  --git a/compiler-rt/lib/scudo/standalone/internal_defs.h b/compiler-rt/lib/scudo/standalone/internal_defs.h
index 64ed238ebfec..f80c0f621a46 100644
--- a/compiler-rt/lib/scudo/standalone/internal_defs.h
+++ b/compiler-rt/lib/scudo/standalone/internal_defs.h
@@ -84,12 +84,12 @@ void NORETURN reportCheckFailed(const char *File, int Line,
 
 #define CHECK_IMPL(C1, Op, C2)                                                 \
   do {                                                                         \
-    u64 V1 = (u64)(C1);                                                        \
-    u64 V2 = (u64)(C2);                                                        \
+    scudo::u64 V1 = (scudo::u64)(C1);                                          \
+    scudo::u64 V2 = (scudo::u64)(C2);                                          \
     if (UNLIKELY(!(V1 Op V2))) {                                               \
-      reportCheckFailed(__FILE__, __LINE__, "(" #C1 ") " #Op " (" #C2 ")", V1, \
-                        V2);                                                   \
-      die();                                                                   \
+      scudo::reportCheckFailed(__FILE__, __LINE__,                             \
+                               "(" #C1 ") " #Op " (" #C2 ")", V1, V2);         \
+      scudo::die();                                                            \
     }                                                                          \
   } while (false)
 

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index bca783a3b602..f288fc7d7592 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -114,7 +114,7 @@ template <uptr MaxFreeListSize>
 void *MapAllocator<MaxFreeListSize>::allocate(uptr Size, uptr AlignmentHint,
                                               uptr *BlockEnd,
                                               bool ZeroContents) {
-  DCHECK_GT(Size, AlignmentHint);
+  DCHECK_GE(Size, AlignmentHint);
   const uptr PageSize = getPageSizeCached();
   const uptr RoundedSize =
       roundUpTo(Size + LargeBlock::getHeaderSize(), PageSize);

diff  --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h
index dfef0865b9d9..59d6ede57ed2 100644
--- a/compiler-rt/lib/scudo/standalone/size_class_map.h
+++ b/compiler-rt/lib/scudo/standalone/size_class_map.h
@@ -120,7 +120,8 @@ class SizeClassMap {
       if (C < LargestClassId)
         CHECK_EQ(getClassIdBySize(S + 1), C + 1);
       CHECK_EQ(getClassIdBySize(S - 1), C);
-      CHECK_GT(getSizeByClassId(C), getSizeByClassId(C - 1));
+      if (C - 1 != BatchClassId)
+        CHECK_GT(getSizeByClassId(C), getSizeByClassId(C - 1));
     }
     // Do not perform the loop if the maximum size is too large.
     if (MaxSizeLog > 19)
@@ -129,7 +130,7 @@ class SizeClassMap {
       const uptr C = getClassIdBySize(S);
       CHECK_LT(C, NumClasses);
       CHECK_GE(getSizeByClassId(C), S);
-      if (C > 0)
+      if (C - 1 != BatchClassId)
         CHECK_LT(getSizeByClassId(C - 1), S);
     }
   }

diff  --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
index f26a85050964..e3b2073d166b 100644
--- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SCUDO_UNITTEST_CFLAGS
   -I${COMPILER_RT_SOURCE_DIR}/lib
   -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone
   -DGTEST_HAS_RTTI=0
+  -DSCUDO_DEBUG=1
   # Extra flags for the C++ tests
   # TODO(kostyak): find a way to make -fsized-deallocation work
   -Wno-mismatched-new-delete)

diff  --git a/compiler-rt/lib/scudo/standalone/vector.h b/compiler-rt/lib/scudo/standalone/vector.h
index 3cb4005ed29c..6ca350a25771 100644
--- a/compiler-rt/lib/scudo/standalone/vector.h
+++ b/compiler-rt/lib/scudo/standalone/vector.h
@@ -84,7 +84,8 @@ template <typename T> class VectorNoCtor {
     DCHECK_LE(Size, NewCapacity);
     const uptr NewCapacityBytes =
         roundUpTo(NewCapacity * sizeof(T), getPageSizeCached());
-    T *NewData = (T *)map(nullptr, NewCapacityBytes, "scudo:vector");
+    T *NewData =
+        reinterpret_cast<T *>(map(nullptr, NewCapacityBytes, "scudo:vector"));
     if (Data) {
       memcpy(NewData, Data, Size * sizeof(T));
       unmap(Data, CapacityBytes);


        


More information about the llvm-commits mailing list