[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:55:22 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 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=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>
>From b276e33fbc2e8992338f1e9e41cb24e2197060b3 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 11 Jul 2024 21:52:35 -0700
Subject: [PATCH 2/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20introduced=20through=20rebase?=
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_report.cpp | 3 +--
compiler-rt/test/asan/TestCases/debug_mapping.cpp | 4 ++--
4 files changed, 5 insertions(+), 6 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_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/asan/TestCases/debug_mapping.cpp b/compiler-rt/test/asan/TestCases/debug_mapping.cpp
index 40083f02853fc..9c8ab468bedd9 100644
--- a/compiler-rt/test/asan/TestCases/debug_mapping.cpp
+++ b/compiler-rt/test/asan/TestCases/debug_mapping.cpp
@@ -14,7 +14,7 @@
// printed because of verbosity=1
// CHECK: SHADOW_SCALE: [[SCALE:[0-9]+]]
-// CHECK: SHADOW_OFFSET: [[OFFSET:0x[0-9a-f]+]]
+// CHECK: SHADOW_OFFSET: 0x{{0*}}[[OFFSET:[0-9a-f]+]]
int main() {
size_t scale, offset;
@@ -24,7 +24,7 @@ int main() {
fprintf(stderr, "offset: 0x" PTR "\n", (void*)offset);
// CHECK: scale: [[SCALE]]
- // CHECK: offset: [[OFFSET]]
+ // CHECK: offset: 0x{{0*}}[[OFFSET]]
return 0;
}
>From 91e2d434a6e3e83f794f12d116f5b48e0c821a2f Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 11 Jul 2024 21:55:12 -0700
Subject: [PATCH 3/3] rebase
Created using spr 1.3.4
---
compiler-rt/lib/asan/asan_descriptions.cpp | 2 +-
compiler-rt/lib/asan/asan_rtl.cpp | 2 +-
compiler-rt/lib/hwasan/hwasan_report.cpp | 3 ++-
compiler-rt/test/asan/TestCases/debug_mapping.cpp | 4 ++--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index 1c2f20a76343b..05a277cfa0a84 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("' (%p) of size %zu\n", (void *)g.beg, g.size);
+ str.AppendF("' (0x%zx) of size %zu\n", 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 d42a75e9e5211..c484e086a5ef7 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: %p\n", (void *)ASAN_SHADOW_OFFSET);
+ Printf("SHADOW_OFFSET: 0x%zx\n", (uptr)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_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 503784b6c4532..9fbf38ae6a1f4 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -328,7 +328,8 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
break;
uptr pc_mask = (1ULL << 48) - 1;
uptr pc = record & pc_mask;
- frame_desc.AppendF(" record_addr:%p record:0x%zx", record_addr, record);
+ frame_desc.AppendF(" record_addr:0x%zx record:0x%zx",
+ reinterpret_cast<uptr>(record_addr), record);
SymbolizedStackHolder symbolized_stack(
Symbolizer::GetOrInit()->SymbolizePC(pc));
const SymbolizedStack *frame = symbolized_stack.get();
diff --git a/compiler-rt/test/asan/TestCases/debug_mapping.cpp b/compiler-rt/test/asan/TestCases/debug_mapping.cpp
index 9c8ab468bedd9..40083f02853fc 100644
--- a/compiler-rt/test/asan/TestCases/debug_mapping.cpp
+++ b/compiler-rt/test/asan/TestCases/debug_mapping.cpp
@@ -14,7 +14,7 @@
// printed because of verbosity=1
// CHECK: SHADOW_SCALE: [[SCALE:[0-9]+]]
-// CHECK: SHADOW_OFFSET: 0x{{0*}}[[OFFSET:[0-9a-f]+]]
+// CHECK: SHADOW_OFFSET: [[OFFSET:0x[0-9a-f]+]]
int main() {
size_t scale, offset;
@@ -24,7 +24,7 @@ int main() {
fprintf(stderr, "offset: 0x" PTR "\n", (void*)offset);
// CHECK: scale: [[SCALE]]
- // CHECK: offset: 0x{{0*}}[[OFFSET]]
+ // CHECK: offset: [[OFFSET]]
return 0;
}
More information about the llvm-commits
mailing list