[compiler-rt] [sanitizer] Warn if allocator size exceeds max user virtual address (PR #152428)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 19:49:51 PDT 2025


https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/152428

>From 79257323d56de59269979c6727e82886e67c7377 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 7 Aug 2025 02:16:47 +0000
Subject: [PATCH 1/2] [sanitizer] Warn if allocator size exceeds max user
 virtual address

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).
---
 .../sanitizer_common/sanitizer_allocator_primary64.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 51ac1b6ae4975..56d40c19b0f0c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -113,6 +113,18 @@ 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);
+    if (TotalSpaceSize >= MaxAddr)
+      VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
+              TotalSpaceSize, MaxAddr);
+    // We can't easily adjust the requested heap size, because kSpaceSize is
+    // const (for optimization) and used throughout the code.
+
     PremappedHeap = heap_start != 0;
     if (PremappedHeap) {
       CHECK(!kUsingConstantSpaceBeg);

>From 9b747cd9fec5e3596be73bce15d70815e307ff7b Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Thu, 7 Aug 2025 02:49:22 +0000
Subject: [PATCH 2/2] Clarify warning

---
 .../sanitizer_common/sanitizer_allocator_primary64.h   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
index 56d40c19b0f0c..11fb5f5b92e17 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
@@ -119,12 +119,14 @@ class SizeClassAllocator64 {
     VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
     VReport(3, "Total space size for primary allocator: 0x%zx\n",
             TotalSpaceSize);
-    if (TotalSpaceSize >= MaxAddr)
+    if (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);
-    // We can't easily adjust the requested heap size, because kSpaceSize is
-    // const (for optimization) and used throughout the code.
-
+      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