[compiler-rt] 9faac93 - [sanitizer] Warn if allocator size exceeds max user virtual address (#152428)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 7 14:36:48 PDT 2025
Author: Thurston Dang
Date: 2025-08-07T14:36:45-07:00
New Revision: 9faac938e1b03ea23e7212550860f8b8001757e1
URL: https://github.com/llvm/llvm-project/commit/9faac938e1b03ea23e7212550860f8b8001757e1
DIFF: https://github.com/llvm/llvm-project/commit/9faac938e1b03ea23e7212550860f8b8001757e1.diff
LOG: [sanitizer] Warn if allocator size exceeds max user virtual address (#152428)
This warns the user of incompatible configurations, such as 39-bit and
42-bit VMAs for AArch64 non-Android Linux ASan
(https://github.com/llvm/llvm-project/issues/145259).
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 51ac1b6ae4975..b39eb1538cbcd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -113,6 +113,24 @@ class SizeClassAllocator64 {
// ~(uptr)0.
void Init(s32 release_to_os_interval_ms, uptr heap_start = 0) {
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
+
+ uptr MaxAddr = GetMaxUserVirtualAddress();
+ // VReport does not call the sanitizer allocator.
+ VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
+ VReport(3, "Total space size for primary allocator: 0x%zx\n",
+ TotalSpaceSize);
+ // TODO: revise the check if we ever configure sanitizers to deliberately
+ // map beyond the 2**48 barrier (note that Linux pretends the VMA is
+ // limited to 48-bit for backwards compatibility, but allows apps to
+ // explicitly specify an address beyond that).
+ if (heap_start + TotalSpaceSize >= MaxAddr) {
+ // We can't easily adjust the requested heap size, because kSpaceSize is
+ // const (for optimization) and used throughout the code.
+ VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
+ TotalSpaceSize, MaxAddr);
+ VReport(
+ 0, "Try using a kernel that allows a larger virtual address space\n");
+ }
PremappedHeap = heap_start != 0;
if (PremappedHeap) {
CHECK(!kUsingConstantSpaceBeg);
More information about the llvm-commits
mailing list