From ef85ea9a4fbd65e7df2cef0b058f733dee15a42c Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 6 Oct 2021 13:10:35 -0700 Subject: [PATCH] [msan] Print both shadow and user address before: 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 Shadow map of [0x211000000005, 0x21100000012e), 297 bytes: now: 0x2f60d213ac10[0x7f60d213ac10] 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 Shadow map [0x211000000005, 0x21100000012e) of [0x711000000005, 0x711000000135), 297 bytes: Differential Revision: https://reviews.llvm.org/D111261 --- compiler-rt/lib/msan/msan.cpp | 1 + compiler-rt/lib/msan/msan_report.cpp | 9 ++++++--- .../test/msan/msan_check_mem_is_initialized.cpp | 2 +- compiler-rt/test/msan/msan_dump_shadow.cpp | 4 ++-- compiler-rt/test/msan/msan_print_shadow.cpp | 2 +- compiler-rt/test/msan/msan_print_shadow2.cpp | 12 ++++++------ compiler-rt/test/msan/msan_print_shadow3.cpp | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp index 3c1ae17c7bb3..2202e3446921 100644 --- a/compiler-rt/lib/msan/msan.cpp +++ b/compiler-rt/lib/msan/msan.cpp @@ -515,6 +515,7 @@ void __msan_dump_shadow(const void *x, uptr size) { } unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x); + Printf("%p[%p] ", s, x); for (uptr i = 0; i < size; i++) Printf("%x%x ", s[i] >> 4, s[i] & 0xf); Printf("\n"); diff --git a/compiler-rt/lib/msan/msan_report.cpp b/compiler-rt/lib/msan/msan_report.cpp index 3a7a237dea07..ff3e38c7db9e 100644 --- a/compiler-rt/lib/msan/msan_report.cpp +++ b/compiler-rt/lib/msan/msan_report.cpp @@ -201,15 +201,18 @@ void DescribeMemoryRange(const void *x, uptr size) { Decorator d; Printf("%s", d.Warning()); - Printf("Shadow map of [%p, %p), %zu bytes:\n", + uptr start_x = reinterpret_cast(x); + Printf("Shadow map [%p, %p) of [%p, %p), %zu bytes:\n", reinterpret_cast(start), reinterpret_cast(end), - end - start); + reinterpret_cast(start_x), + reinterpret_cast(start_x + end - start), end - start); Printf("%s", d.Default()); while (s < e) { // Line start. if (pos % 16 == 0) { for (int i = 0; i < 4; ++i) origin_ids[i] = -1; - Printf("%p:", reinterpret_cast(s)); + Printf("%p[%p]:", reinterpret_cast(s), + reinterpret_cast(start_x - start + s)); } // Group start. if (pos % 4 == 0) { diff --git a/compiler-rt/test/msan/msan_check_mem_is_initialized.cpp b/compiler-rt/test/msan/msan_check_mem_is_initialized.cpp index 81f7895f7aea..81752291c7c5 100644 --- a/compiler-rt/test/msan/msan_check_mem_is_initialized.cpp +++ b/compiler-rt/test/msan/msan_check_mem_is_initialized.cpp @@ -16,7 +16,7 @@ int main(void) { #ifdef POSITIVE __msan_check_mem_is_initialized(p + 5, 20); // CHECK: Uninitialized bytes in __msan_check_mem_is_initialized at offset 5 inside [0x{{.*}}, 20) - // CHECK-VERBOSE: Shadow map of [0x{{.*}}, 0x{{.*}}), 20 bytes: + // CHECK-VERBOSE: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 20 bytes: // CHECK-VERBOSE: 0x{{.*}}: ..000000 0000ffff 00000000 00000000 // CHECK-VERBOSE: 0x{{.*}}: 00000000 00...... ........ ........ diff --git a/compiler-rt/test/msan/msan_dump_shadow.cpp b/compiler-rt/test/msan/msan_dump_shadow.cpp index 543fa7013223..48b84ef50f72 100644 --- a/compiler-rt/test/msan/msan_dump_shadow.cpp +++ b/compiler-rt/test/msan/msan_dump_shadow.cpp @@ -18,5 +18,5 @@ int main(void) { return 0; } -// CHECK: ff ff ff ff ff -// CHECK: 00 00 00 +// CHECK: 0x{{[0-9a-f]+}}[0x{{[0-9a-f]+}}] ff ff ff ff ff +// CHECK: 0x{{[0-9a-f]+}}[0x{{[0-9a-f]+}}] 00 00 00 diff --git a/compiler-rt/test/msan/msan_print_shadow.cpp b/compiler-rt/test/msan/msan_print_shadow.cpp index bdee3102c1cc..2782fcd83ed7 100644 --- a/compiler-rt/test/msan/msan_print_shadow.cpp +++ b/compiler-rt/test/msan/msan_print_shadow.cpp @@ -52,7 +52,7 @@ int main(void) { return 0; } -// CHECK: Shadow map of [{{.*}}), 297 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 297 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: ..00ffff 00000000 ffffffff ffffffff // CHECK-NO-ORIGINS: 0x{{.*}}: ffffffff ffffffff ffffffff ffffffff diff --git a/compiler-rt/test/msan/msan_print_shadow2.cpp b/compiler-rt/test/msan/msan_print_shadow2.cpp index 5095081c9655..05c1cb12bef8 100644 --- a/compiler-rt/test/msan/msan_print_shadow2.cpp +++ b/compiler-rt/test/msan/msan_print_shadow2.cpp @@ -22,28 +22,28 @@ int main(void) { return 0; } -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: ff...... ........ ........ ........ // CHECK-ORIGINS: 0x{{.*}}: ff...... ........ ........ ........ |A . . .| // CHECK-ORIGINS: Origin A (origin_id {{.*}}): -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: ..ff.... ........ ........ ........ // CHECK-ORIGINS: 0x{{.*}}: ..ff.... ........ ........ ........ |A . . .| // CHECK-ORIGINS: Origin A (origin_id {{.*}}): -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: ......ff ........ ........ ........ // CHECK-ORIGINS: 0x{{.*}}: ......ff ........ ........ ........ |A . . .| // CHECK-ORIGINS: Origin A (origin_id {{.*}}): -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 1 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 1 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: ......ff ........ ........ ........ // CHECK-ORIGINS: 0x{{.*}}: ......ff ........ ........ ........ |A . . .| // CHECK-ORIGINS: Origin A (origin_id {{.*}}): -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 0 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 0 bytes: -// CHECK: Shadow map of [0x{{.*}}, 0x{{.*}}), 3 bytes: +// CHECK: Shadow map [0x{{.*}}, 0x{{.*}}) of [0x{{.*}}, 0x{{.*}}), 3 bytes: // CHECK-NO-ORIGINS: 0x{{.*}}: 000000.. ........ ........ ........ // CHECK-ORIGINS: 0x{{.*}}: 000000.. ........ ........ ........ |. . . .| diff --git a/compiler-rt/test/msan/msan_print_shadow3.cpp b/compiler-rt/test/msan/msan_print_shadow3.cpp index 410755e5dbaa..d9f55a6eef9a 100644 --- a/compiler-rt/test/msan/msan_print_shadow3.cpp +++ b/compiler-rt/test/msan/msan_print_shadow3.cpp @@ -12,5 +12,5 @@ int main(void) { return 0; } -// CHECK: Shadow map of [{{.*}}), 4 bytes: +// CHECK: Shadow map [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}) of [0x{{[0-9a-f]+}}, 0x{{[0-9a-f]+}}), 4 bytes: // CHECK: 0x{{.*}}: 77654321 ........ ........ ........