[sanitizer][msan] The LLVM part of the LoongArch memory sanitizer implementation
authorzhanglimin <zhanglimin@loongson.cn>
Thu, 29 Jun 2023 03:40:22 +0000 (11:40 +0800)
committerzhanglimin <zhanglimin@loongson.cn>
Thu, 29 Jun 2023 03:41:27 +0000 (11:41 +0800)
This patch enabled msan in LLVM and fixed all failing tests in
check-msan.

It does not add VarArgHelper implementation on LoongArch, which
will be done separately later. And it adds a test for VarArgNoOpHelper,
which is based on the X86 one.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152692

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll [new file with mode: 0644]

index 204b262..83d9004 100644 (file)
@@ -439,6 +439,14 @@ static const MemoryMapParams Linux_AArch64_MemoryMapParams = {
     0x0200000000000, // OriginBase
 };
 
+// loongarch64 Linux
+static const MemoryMapParams Linux_LoongArch64_MemoryMapParams = {
+    0,              // AndMask (not used)
+    0x500000000000, // XorMask
+    0,              // ShadowBase (not used)
+    0x100000000000, // OriginBase
+};
+
 // aarch64 FreeBSD
 static const MemoryMapParams FreeBSD_AArch64_MemoryMapParams = {
     0x1800000000000, // AndMask
@@ -496,6 +504,11 @@ static const PlatformMemoryMapParams Linux_ARM_MemoryMapParams = {
     &Linux_AArch64_MemoryMapParams,
 };
 
+static const PlatformMemoryMapParams Linux_LoongArch_MemoryMapParams = {
+    nullptr,
+    &Linux_LoongArch64_MemoryMapParams,
+};
+
 static const PlatformMemoryMapParams FreeBSD_ARM_MemoryMapParams = {
     nullptr,
     &FreeBSD_AArch64_MemoryMapParams,
@@ -1017,6 +1030,9 @@ void MemorySanitizer::initializeModule(Module &M) {
       case Triple::aarch64_be:
         MapParams = Linux_ARM_MemoryMapParams.bits64;
         break;
+      case Triple::loongarch64:
+        MapParams = Linux_LoongArch_MemoryMapParams.bits64;
+        break;
       default:
         report_fatal_error("unsupported architecture");
       }
diff --git a/llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll b/llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll
new file mode 100644 (file)
index 0000000..dcbe2a2
--- /dev/null
@@ -0,0 +1,14 @@
+; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1
+; Test that code using va_start can be compiled on LoongArch.
+
+target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
+target triple = "loongarch64-unknown-linux-gnu"
+
+define void @VaStart(ptr %s, ...) {
+entry:
+  %vl = alloca ptr, align 4
+  call void @llvm.va_start(ptr %vl)
+  ret void
+}
+
+declare void @llvm.va_start(ptr)