[compiler-rt] [memprof] Switch allocator to dynamic base address (PR #98510)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 19:11:55 PDT 2024
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/98510
>From 81ed94aaf5f8ab385fbb1adbad8dd70dfb1267d6 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 11 Jul 2024 17:55:39 +0000
Subject: [PATCH 1/2] [memprof] Switch allocator to dynamic base address
memprof_rtl.cpp calls InitializeShadowMemory() - which dynamically/"randomly" chooses a base address for the shadow mapping - prior to InitializeAllocator(). If we are unlucky, the shadow memory may be mapped in the same region where the allocator wants to be.
This patch fixes the issue by changing the allocator to dynamically choosing a base address, as suggested by Vitaly. For comparison, HWASan already dynamically chooses the base addresses for the shadow mapping and allocator.
The "unlucky" failure was observed on a new buildbot (https://lab.llvm.org/buildbot/#/builders/66/builds/1361/steps/17/logs/stdio).
---
compiler-rt/lib/memprof/memprof_allocator.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/memprof/memprof_allocator.h b/compiler-rt/lib/memprof/memprof_allocator.h
index 89e924f80d41a..ee8034b366b67 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.h
+++ b/compiler-rt/lib/memprof/memprof_allocator.h
@@ -49,7 +49,7 @@ struct MemprofMapUnmapCallback {
#if SANITIZER_APPLE
constexpr uptr kAllocatorSpace = 0x600000000000ULL;
#else
-constexpr uptr kAllocatorSpace = 0x500000000000ULL;
+constexpr uptr kAllocatorSpace = ~(uptr)0;
#endif
constexpr uptr kAllocatorSize = 0x40000000000ULL; // 4T.
typedef DefaultSizeClassMap SizeClassMap;
>From e0dc2ab619be043b8843fcf240356c1e596d9419 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at gmail.com>
Date: Thu, 11 Jul 2024 19:11:47 -0700
Subject: [PATCH 2/2] Apply to Apple as well
---
compiler-rt/lib/memprof/memprof_allocator.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/compiler-rt/lib/memprof/memprof_allocator.h b/compiler-rt/lib/memprof/memprof_allocator.h
index ee8034b366b67..6d898f06f7e42 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.h
+++ b/compiler-rt/lib/memprof/memprof_allocator.h
@@ -46,11 +46,7 @@ struct MemprofMapUnmapCallback {
void OnUnmap(uptr p, uptr size) const;
};
-#if SANITIZER_APPLE
-constexpr uptr kAllocatorSpace = 0x600000000000ULL;
-#else
constexpr uptr kAllocatorSpace = ~(uptr)0;
-#endif
constexpr uptr kAllocatorSize = 0x40000000000ULL; // 4T.
typedef DefaultSizeClassMap SizeClassMap;
template <typename AddressSpaceViewTy>
More information about the llvm-commits
mailing list