[compiler-rt] fde34d9 - sanitizer_common: remove debugging logic from the internal allocator

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 12 04:02:44 PDT 2021


Author: Dmitry Vyukov
Date: 2021-07-12T13:02:38+02:00
New Revision: fde34d9f891b92539e0e8eff96057390ee7b1bdf

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

LOG: sanitizer_common: remove debugging logic from the internal allocator

The internal allocator adds 8-byte header for debugging purposes.
The problem with it is that it's not possible to allocate nicely-sized
objects without a significant overhead. For example, if we allocate
512-byte objects, that will be rounded up to 768 or something.
This logic migrated from tsan where it was added during initial development,
I don't remember that it ever caught anything (we don't do bugs!).
Remove it so that it's possible to allocate nicely-sized objects
without overheads.

Reviewed By: melver

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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
index 3157b35ffaf8..bcb7370a7906 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
@@ -137,14 +137,6 @@ static void RawInternalFree(void *ptr, InternalAllocatorCache *cache) {
 
 #endif  // SANITIZER_GO || defined(SANITIZER_USE_MALLOC)
 
-namespace {
-const u64 kBlockMagic = 0x6A6CB03ABCEBC041ull;
-
-struct BlockHeader {
-  u64 magic;
-};
-}  // namespace
-
 static void NORETURN ReportInternalAllocatorOutOfMemory(uptr requested_size) {
   SetAllocatorOutOfMemory();
   Report("FATAL: %s: internal allocator is out of memory trying to allocate "
@@ -153,28 +145,17 @@ static void NORETURN ReportInternalAllocatorOutOfMemory(uptr requested_size) {
 }
 
 void *InternalAlloc(uptr size, InternalAllocatorCache *cache, uptr alignment) {
-  uptr s = size + sizeof(BlockHeader);
-  if (s < size)
-    return nullptr;
-  BlockHeader *p = (BlockHeader *)RawInternalAlloc(s, cache, alignment);
+  void *p = RawInternalAlloc(size, cache, alignment);
   if (UNLIKELY(!p))
-    ReportInternalAllocatorOutOfMemory(s);
-  p->magic = kBlockMagic;
-  return p + 1;
+    ReportInternalAllocatorOutOfMemory(size);
+  return p;
 }
 
 void *InternalRealloc(void *addr, uptr size, InternalAllocatorCache *cache) {
-  if (!addr)
-    return InternalAlloc(size, cache);
-  uptr s = size + sizeof(BlockHeader);
-  if (s < size)
-    return nullptr;
-  BlockHeader *p = (BlockHeader *)addr - 1;
-  CHECK_EQ(kBlockMagic, p->magic);
-  p = (BlockHeader *)RawInternalRealloc(p, s, cache);
+  void *p = RawInternalRealloc(addr, size, cache);
   if (UNLIKELY(!p))
-    ReportInternalAllocatorOutOfMemory(s);
-  return p + 1;
+    ReportInternalAllocatorOutOfMemory(size);
+  return p;
 }
 
 void *InternalReallocArray(void *addr, uptr count, uptr size,
@@ -203,12 +184,7 @@ void *InternalCalloc(uptr count, uptr size, InternalAllocatorCache *cache) {
 }
 
 void InternalFree(void *addr, InternalAllocatorCache *cache) {
-  if (!addr)
-    return;
-  BlockHeader *p = (BlockHeader *)addr - 1;
-  CHECK_EQ(kBlockMagic, p->magic);
-  p->magic = 0;
-  RawInternalFree(p, cache);
+  RawInternalFree(addr, cache);
 }
 
 // LowLevelAllocator


        


More information about the llvm-commits mailing list