[compiler-rt] Changes to support running tests for Windows arm64 asan (PR #66973)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 11:26:46 PST 2023
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/66973
>From 98bc7ed0ac5831fc9e75ec7a2d5ec02446545bff Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzon at farzon.org>
Date: Wed, 20 Sep 2023 22:58:08 -0400
Subject: [PATCH 1/2] Changes to support running tests for Windows arm64 asan
1. Differentiate SANITIZER_WINDOWS64 for x64 and arm64. 2. turn off
interception tests that expect x86 assembly.
---
compiler-rt/lib/interception/interception_win.cpp | 12 +++++++++---
.../lib/interception/tests/interception_win_test.cpp | 6 ++++++
.../lib/sanitizer_common/sanitizer_platform.h | 8 ++++++++
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 1b681ada37b170d..4c6ba12f6c93d8f 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -431,7 +431,9 @@ static uptr AllocateMemoryForTrampoline(uptr image_address, size_t size) {
// The following prologues cannot be patched because of the short jump
// jumping to the patching region.
-#if SANITIZER_WINDOWS64
+// Note: The jump byte array below is x86_64 assembly.
+
+# if SANITIZER_WINDOWS_x64
// ntdll!wcslen in Win11
// 488bc1 mov rax,rcx
// 0fb710 movzx edx,word ptr [rax]
@@ -462,7 +464,11 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
return 4;
#endif
-#if SANITIZER_WINDOWS64
+ // Note: kPrologueWithShortJump1 and kPrologueWithShortJump2 are
+ // x86_64 assembly. Adding the preprocessor check here because the
+ // variable declaration are not enabled if building for arm64.
+
+# if SANITIZER_WINDOWS_x64
if (memcmp((u8*)address, kPrologueWithShortJump1,
sizeof(kPrologueWithShortJump1)) == 0 ||
memcmp((u8*)address, kPrologueWithShortJump2,
@@ -544,7 +550,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
return 7;
}
-#if SANITIZER_WINDOWS64
+#if SANITIZER_WINDOWS_x64
switch (*(u8*)address) {
case 0xA1: // A1 XX XX XX XX XX XX XX XX :
// movabs eax, dword ptr ds:[XXXXXXXX]
diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp
index 9159ce405f2dc49..9d93587690542b8 100644
--- a/compiler-rt/lib/interception/tests/interception_win_test.cpp
+++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp
@@ -18,6 +18,11 @@
#if !SANITIZER_DEBUG
#if SANITIZER_WINDOWS
+// Note: Disabling these tests for arm64 since
+// the only assembly assumed is x86 and x86_64.
+
+#if !SANITIZER_WINDOWS_ARM64
+
#include <stdarg.h>
#define WIN32_LEAN_AND_MEAN
@@ -793,5 +798,6 @@ TEST(Interception, EmptyExportTable) {
} // namespace __interception
+#endif // !SANITIZER_WINDOWS_ARM64
#endif // SANITIZER_WINDOWS
#endif // #if !SANITIZER_DEBUG
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index 3e1b078a0212f5e..49d8a67cc12db3f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -260,6 +260,14 @@
# define SANITIZER_ARM64 0
#endif
+#if SANITIZER_WINDOWS64 && SANITIZER_ARM64
+# define SANITIZER_WINDOWS_ARM64 1
+# define SANITIZER_WINDOWS_x64 0
+#else
+# define SANITIZER_WINDOWS_ARM64 0
+# define SANITIZER_WINDOWS_x64 1
+#endif
+
#if SANITIZER_SOLARIS && SANITIZER_WORDSIZE == 32
# define SANITIZER_SOLARIS32 1
#else
>From 0e1cc493d3eae14dc388fe1fdcde431b08c177ed Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzon at farzon.com>
Date: Mon, 13 Nov 2023 14:26:26 -0500
Subject: [PATCH 2/2] apply clang format
---
compiler-rt/lib/interception/interception_win.cpp | 2 +-
.../lib/interception/tests/interception_win_test.cpp | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 4c6ba12f6c93d8f..da1d10f2731e9b1 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -550,7 +550,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
return 7;
}
-#if SANITIZER_WINDOWS_x64
+# if SANITIZER_WINDOWS_x64
switch (*(u8*)address) {
case 0xA1: // A1 XX XX XX XX XX XX XX XX :
// movabs eax, dword ptr ds:[XXXXXXXX]
diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp
index 9d93587690542b8..c8e5744071a9e6d 100644
--- a/compiler-rt/lib/interception/tests/interception_win_test.cpp
+++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp
@@ -21,12 +21,12 @@
// Note: Disabling these tests for arm64 since
// the only assembly assumed is x86 and x86_64.
-#if !SANITIZER_WINDOWS_ARM64
+# if !SANITIZER_WINDOWS_ARM64
-#include <stdarg.h>
+# include <stdarg.h>
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
namespace __interception {
namespace {
@@ -798,6 +798,6 @@ TEST(Interception, EmptyExportTable) {
} // namespace __interception
-#endif // !SANITIZER_WINDOWS_ARM64
+# endif // !SANITIZER_WINDOWS_ARM64
#endif // SANITIZER_WINDOWS
#endif // #if !SANITIZER_DEBUG
More information about the llvm-commits
mailing list