From d26d5a0a3dcaea5ef7b17073c3a4d436b29c2866 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 12 Aug 2021 19:55:59 +0200 Subject: [PATCH] msan: clean up and enable format string checking Depends on D107981. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D107982 --- compiler-rt/lib/msan/CMakeLists.txt | 3 --- compiler-rt/lib/msan/msan.cpp | 2 +- compiler-rt/lib/msan/msan_linux.cpp | 10 +++++----- compiler-rt/lib/msan/msan_report.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler-rt/lib/msan/CMakeLists.txt b/compiler-rt/lib/msan/CMakeLists.txt index d6523d412aff..b115f68db3e2 100644 --- a/compiler-rt/lib/msan/CMakeLists.txt +++ b/compiler-rt/lib/msan/CMakeLists.txt @@ -40,9 +40,6 @@ endif() # Prevent clang from generating libc calls. append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding MSAN_RTL_CFLAGS) -# Too many existing bugs, needs cleanup. -append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format MSAN_RTL_CFLAGS) - set(MSAN_RUNTIME_LIBRARIES) # Static runtime library. diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp index 4fa772fdcb6e..3c1ae17c7bb3 100644 --- a/compiler-rt/lib/msan/msan.cpp +++ b/compiler-rt/lib/msan/msan.cpp @@ -604,7 +604,7 @@ void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) { id = Origin::CreateStackOrigin(idx).raw_id(); *id_ptr = id; if (print) - Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc); + Printf("First time: idx=%d id=%d %s 0x%zx \n", idx, id, descr + 4, pc); } if (print) Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id); diff --git a/compiler-rt/lib/msan/msan_linux.cpp b/compiler-rt/lib/msan/msan_linux.cpp index d5baee38e710..c27e66661d22 100644 --- a/compiler-rt/lib/msan/msan_linux.cpp +++ b/compiler-rt/lib/msan/msan_linux.cpp @@ -37,7 +37,7 @@ namespace __msan { void ReportMapRange(const char *descr, uptr beg, uptr size) { if (size > 0) { uptr end = beg + size - 1; - VPrintf(1, "%s : %p - %p\n", descr, beg, end); + VPrintf(1, "%s : 0x%zx - 0x%zx\n", descr, beg, end); } } @@ -45,7 +45,7 @@ static bool CheckMemoryRangeAvailability(uptr beg, uptr size) { if (size > 0) { uptr end = beg + size - 1; if (!MemoryRangeIsAvailable(beg, end)) { - Printf("FATAL: Memory range %p - %p is not available.\n", beg, end); + Printf("FATAL: Memory range 0x%zx - 0x%zx is not available.\n", beg, end); return false; } } @@ -65,8 +65,8 @@ static bool ProtectMemoryRange(uptr beg, uptr size, const char *name) { } if ((uptr)addr != beg) { uptr end = beg + size - 1; - Printf("FATAL: Cannot protect memory range %p - %p (%s).\n", beg, end, - name); + Printf("FATAL: Cannot protect memory range 0x%zx - 0x%zx (%s).\n", beg, + end, name); return false; } } @@ -115,7 +115,7 @@ bool InitShadow(bool init_origins) { if (!MEM_IS_APP(&__msan_init)) { Printf("FATAL: Code %p is out of application range. Non-PIE build?\n", - (uptr)&__msan_init); + &__msan_init); return false; } diff --git a/compiler-rt/lib/msan/msan_report.cpp b/compiler-rt/lib/msan/msan_report.cpp index e10d9eb62231..ea8608e569e7 100644 --- a/compiler-rt/lib/msan/msan_report.cpp +++ b/compiler-rt/lib/msan/msan_report.cpp @@ -201,13 +201,15 @@ void DescribeMemoryRange(const void *x, uptr size) { Decorator d; Printf("%s", d.Warning()); - Printf("Shadow map of [%p, %p), %zu bytes:\n", start, end, end - start); + Printf("Shadow map of [%p, %p), %zu bytes:\n", + reinterpret_cast(start), reinterpret_cast(end), + 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:", s); + Printf("%p:", reinterpret_cast(s)); } // Group start. if (pos % 4 == 0) {