[compiler-rt] 4cad17d - [DFSan] [compiler-rt] leave BufferedStackTrace uninit

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 15:19:48 PDT 2024


Author: Florian Mayer
Date: 2024-08-07T15:19:26-07:00
New Revision: 4cad17de794ccd186d50ff669e78215eccecaaa7

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

LOG: [DFSan] [compiler-rt] leave BufferedStackTrace uninit

Otherwise we have to memset 2040 bytes (255 * 8) for each call

Pull Request: https://github.com/llvm/llvm-project/pull/102252

Added: 
    

Modified: 
    compiler-rt/lib/dfsan/dfsan.cpp
    compiler-rt/lib/dfsan/dfsan_allocator.cpp
    compiler-rt/lib/dfsan/dfsan_new_delete.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/dfsan/dfsan.cpp b/compiler-rt/lib/dfsan/dfsan.cpp
index 302e3c3032ac5..360288cb88f34 100644
--- a/compiler-rt/lib/dfsan/dfsan.cpp
+++ b/compiler-rt/lib/dfsan/dfsan.cpp
@@ -195,7 +195,7 @@ static dfsan_origin GetOriginIfTainted(uptr addr, uptr size) {
 // random freezes in forking applications as well as in signal handlers.
 // DFSan supports only Linux. So we do not restrict the store context size.
 #define GET_STORE_STACK_TRACE_PC_BP(pc, bp) \
-  BufferedStackTrace stack;                 \
+  UNINITIALIZED BufferedStackTrace stack;                 \
   stack.Unwind(pc, bp, nullptr, true, flags().store_context_size);
 
 #define PRINT_CALLER_STACK_TRACE        \

diff  --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
index 682df8c6e0346..81ea91580a989 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
@@ -95,13 +95,13 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
              size);
       return nullptr;
     }
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
   }
   if (UNLIKELY(IsRssLimitExceeded())) {
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportRssLimitExceeded(&stack);
   }
   DFsanThread *t = GetCurrentThread();
@@ -118,7 +118,7 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
     SetAllocatorOutOfMemory();
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportOutOfMemory(size, &stack);
   }
   Metadata *meta =
@@ -175,7 +175,7 @@ void *DFsanCalloc(uptr nmemb, uptr size) {
   if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportCallocOverflow(nmemb, size, &stack);
   }
   return DFsanAllocate(nmemb * size, sizeof(u64), true /*zeroise*/);
@@ -232,7 +232,7 @@ void *dfsan_reallocarray(void *ptr, uptr nmemb, uptr size) {
     errno = errno_ENOMEM;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportReallocArrayOverflow(nmemb, size, &stack);
   }
   return dfsan_realloc(ptr, nmemb * size);
@@ -249,7 +249,7 @@ void *dfsan_pvalloc(uptr size) {
     errno = errno_ENOMEM;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportPvallocOverflow(size, &stack);
   }
   // pvalloc(0) should allocate one page.
@@ -262,7 +262,7 @@ void *dfsan_aligned_alloc(uptr alignment, uptr size) {
     errno = errno_EINVAL;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidAlignedAllocAlignment(size, alignment, &stack);
   }
   return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/));
@@ -273,7 +273,7 @@ void *dfsan_memalign(uptr alignment, uptr size) {
     errno = errno_EINVAL;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidAllocationAlignment(alignment, &stack);
   }
   return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/));
@@ -283,7 +283,7 @@ int dfsan_posix_memalign(void **memptr, uptr alignment, uptr size) {
   if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) {
     if (AllocatorMayReturnNull())
       return errno_EINVAL;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidPosixMemalignAlignment(alignment, &stack);
   }
   void *ptr = DFsanAllocate(size, alignment, false /*zeroise*/);

diff  --git a/compiler-rt/lib/dfsan/dfsan_new_delete.cpp b/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
index 7ac906e81077d..4482e22951040 100644
--- a/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
@@ -30,14 +30,14 @@ enum class align_val_t : size_t {};
 #define OPERATOR_NEW_BODY(nothrow)   \
   void *res = dfsan_malloc(size);    \
   if (!nothrow && UNLIKELY(!res)) {  \
-    BufferedStackTrace stack;        \
+    UNINITIALIZED BufferedStackTrace stack;        \
     ReportOutOfMemory(size, &stack); \
   }                                  \
   return res
 #define OPERATOR_NEW_BODY_ALIGN(nothrow)         \
   void *res = dfsan_memalign((uptr)align, size); \
   if (!nothrow && UNLIKELY(!res)) {              \
-    BufferedStackTrace stack;                    \
+    UNINITIALIZED BufferedStackTrace stack;                    \
     ReportOutOfMemory(size, &stack);             \
   }                                              \
   return res;


        


More information about the llvm-commits mailing list