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
This commit is contained in:
Dmitry Vyukov 2021-07-11 14:51:58 +02:00
parent de59f56440
commit fde34d9f89
1 changed files with 7 additions and 31 deletions

View File

@ -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