[compiler-rt] [NFC][memprof] Use %p to print addresses (PR #98577)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 21:52:33 PDT 2024


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/98577

>From 057d76e402235c54ac247ee8b27834c92dabeed0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 11 Jul 2024 18:49:22 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/asan/asan_descriptions.cpp    |  2 +-
 compiler-rt/lib/asan/asan_rtl.cpp             |  2 +-
 compiler-rt/lib/hwasan/hwasan_linux.cpp       |  9 ++++++++
 compiler-rt/lib/hwasan/hwasan_report.cpp      |  3 +--
 .../hwasan/TestCases/Linux/fixed-shadow.c     | 21 +++++++++++--------
 5 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index 05a277cfa0a84..1c2f20a76343b 100644
--- a/compiler-rt/lib/asan/asan_descriptions.cpp
+++ b/compiler-rt/lib/asan/asan_descriptions.cpp
@@ -292,7 +292,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
   str.AppendF(" global variable '%s' defined in '",
               MaybeDemangleGlobalName(g.name));
   PrintGlobalLocation(&str, g, /*print_module_name=*/false);
-  str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
+  str.AppendF("' (%p) of size %zu\n", (void *)g.beg, g.size);
   str.Append(d.Default());
   PrintGlobalNameIfASCII(&str, g);
   Printf("%s", str.data());
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp
index c484e086a5ef7..d42a75e9e5211 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -382,7 +382,7 @@ void PrintAddressSpaceLayout() {
 
   Printf("SHADOW_SCALE: %d\n", (int)ASAN_SHADOW_SCALE);
   Printf("SHADOW_GRANULARITY: %d\n", (int)ASAN_SHADOW_GRANULARITY);
-  Printf("SHADOW_OFFSET: 0x%zx\n", (uptr)ASAN_SHADOW_OFFSET);
+  Printf("SHADOW_OFFSET: %p\n", (void *)ASAN_SHADOW_OFFSET);
   CHECK(ASAN_SHADOW_SCALE >= 3 && ASAN_SHADOW_SCALE <= 7);
   if (kMidMemBeg)
     CHECK(kMidShadowBeg > kLowShadowEnd &&
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index 0a23ffc9fa1ba..68294b5962569 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -109,6 +109,15 @@ static void InitializeShadowBaseAddress(uptr shadow_size_bytes) {
   // FIXME: Android should init flags before shadow.
   if (!SANITIZER_ANDROID && flags()->fixed_shadow_base != (uptr)-1) {
     __hwasan_shadow_memory_dynamic_address = flags()->fixed_shadow_base;
+    uptr beg = __hwasan_shadow_memory_dynamic_address;
+    uptr end = beg + shadow_size_bytes;
+    if (!MemoryRangeIsAvailable(beg, end)) {
+      Report(
+          "FATAL: HWAddressSanitizer: Shadow range %p-%p is not available.\n",
+          (void *)beg, (void *)end);
+      DumpProcessMap();
+      CHECK(MemoryRangeIsAvailable(beg, end));
+    }
   } else {
     __hwasan_shadow_memory_dynamic_address =
         FindDynamicShadowStart(shadow_size_bytes);
diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 9fbf38ae6a1f4..503784b6c4532 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -328,8 +328,7 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
       break;
     uptr pc_mask = (1ULL << 48) - 1;
     uptr pc = record & pc_mask;
-    frame_desc.AppendF("  record_addr:0x%zx record:0x%zx",
-                       reinterpret_cast<uptr>(record_addr), record);
+    frame_desc.AppendF("  record_addr:%p record:0x%zx", record_addr, record);
     SymbolizedStackHolder symbolized_stack(
         Symbolizer::GetOrInit()->SymbolizePC(pc));
     const SymbolizedStack *frame = symbolized_stack.get();
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/fixed-shadow.c b/compiler-rt/test/hwasan/TestCases/Linux/fixed-shadow.c
index ab6ff52027926..e450c100959d1 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/fixed-shadow.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/fixed-shadow.c
@@ -1,15 +1,19 @@
 // Test fixed shadow base functionality.
 //
 // Default compiler instrumentation works with any shadow base (dynamic or fixed).
-// RUN: %clang_hwasan %s -o %t && %run %t
-// RUN: %clang_hwasan %s -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t
-// RUN: %clang_hwasan %s -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
+// RUN: %clang_hwasan %s -o %t
+// RUN: %run %t
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
 //
 // If -hwasan-mapping-offset is set, then the fixed_shadow_base needs to match.
-// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t
-// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t
-// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t && HWASAN_OPTIONS=fixed_shadow_base=4398046511104 not %run %t
-// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t && HWASAN_OPTIONS=fixed_shadow_base=263878495698944 not %run %t
+// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=263878495698944 -o %t
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 not %run %t
+
+// RUN: %clang_hwasan %s -mllvm -hwasan-mapping-offset=4398046511104 -o %t
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=4398046511104 %run %t 2>%t.out || (cat %t.out | FileCheck %s)
+// RUN: HWASAN_OPTIONS=fixed_shadow_base=263878495698944 not %run %t
 //
 // Note: if fixed_shadow_base is not set, compiler-rt will dynamically choose a
 // shadow base, which has a tiny but non-zero probability of matching the
@@ -22,8 +26,7 @@
 //
 // UNSUPPORTED: android
 
-// FIXME: SEGV on Ubuntu 24.04. Looking.
-// UNSUPPORTED: linux
+// CHECK: FATAL: HWAddressSanitizer: Shadow range {{.*}} is not available
 
 #include <assert.h>
 #include <sanitizer/allocator_interface.h>



More information about the llvm-commits mailing list