[compiler-rt] [tsan] Add Go support for linux/riscv64 (PR #127295)

Meng Zhuo via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 19:38:21 PST 2025


https://github.com/mengzhuo updated https://github.com/llvm/llvm-project/pull/127295

>From 3965481aa261139d0817512d2e32be235709f58b Mon Sep 17 00:00:00 2001
From: Meng Zhuo <mengzhuo at iscas.ac.cn>
Date: Fri, 14 Feb 2025 22:27:40 +0800
Subject: [PATCH] [tsan] Add Go support for linux/riscv64

---
 compiler-rt/lib/tsan/go/buildgo.sh            |  6 ++++
 compiler-rt/lib/tsan/rtl/tsan_platform.h      | 30 +++++++++++++++++++
 .../lib/tsan/rtl/tsan_platform_linux.cpp      |  6 ++++
 3 files changed, 42 insertions(+)

diff --git a/compiler-rt/lib/tsan/go/buildgo.sh b/compiler-rt/lib/tsan/go/buildgo.sh
index 6871b36c3f510..d9e56402ad48f 100755
--- a/compiler-rt/lib/tsan/go/buildgo.sh
+++ b/compiler-rt/lib/tsan/go/buildgo.sh
@@ -112,6 +112,12 @@ if [ "$GOOS" = "linux" ]; then
 		ARCHCFLAGS="-mips64 -EL"
 	elif [ "$GOARCH" = "mips64" ]; then
 		ARCHCFLAGS="-mips64 -EB"
+	elif [ "$GOARCH" = "riscv64" ]; then
+		if [ "$GORISCV64" = "rva23u64" ]; then
+			ARCHCFLAGS="-march=rv64gcv"
+		else
+			ARCHCFLAGS="-march=rv64gc"
+		fi
 	elif [ "$GOARCH" = "s390x" ]; then
 		SRCS="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
 		ARCHCFLAGS=""
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h
index 377f8aeb8d66e..354f6da6a64a1 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h
@@ -681,6 +681,33 @@ struct MappingGoMips64_47 {
   static const uptr kShadowAdd = 0x200000000000ull;
 };
 
+/* Go on linux/riscv64 (48-bit VMA)
+0000 0001 0000 - 00e0 0000 0000: executable and heap (896 GiB)
+00e0 0000 0000 - 2000 0000 0000: -
+2000 0000 0000 - 2400 0000 0000: shadow - 4 TiB ( ~ 4 * app)
+2400 0000 0000 - 3000 0000 0000: -
+3000 0000 0000 - 3100 0000 0000: metainfo - 1 TiB ( ~ 1 * app)
+3100 0000 0000 - 8000 0000 0000: -
+*/
+struct MappingGoRiscv64 {
+  static const uptr kMetaShadowBeg = 0x300000000000ull;
+  static const uptr kMetaShadowEnd = 0x310000000000ull;
+  static const uptr kShadowBeg = 0x200000000000ull;
+  static const uptr kShadowEnd = 0x240000000000ull;
+  static const uptr kLoAppMemBeg = 0x000000010000ull;
+  static const uptr kLoAppMemEnd = 0x000e00000000ull;
+  static const uptr kMidAppMemBeg = 0;
+  static const uptr kMidAppMemEnd = 0;
+  static const uptr kHiAppMemBeg = 0;
+  static const uptr kHiAppMemEnd = 0;
+  static const uptr kHeapMemBeg = 0;
+  static const uptr kHeapMemEnd = 0;
+  static const uptr kVdsoBeg = 0;
+  static const uptr kShadowMsk = 0;
+  static const uptr kShadowXor = 0;
+  static const uptr kShadowAdd = 0x200000000000ull;
+};
+
 /*
 Go on linux/s390x
 0000 0000 1000 - 1000 0000 0000: executable and heap - 16 TiB
@@ -728,6 +755,8 @@ ALWAYS_INLINE auto SelectMapping(Arg arg) {
   return Func::template Apply<MappingGoAarch64>(arg);
 #  elif defined(__loongarch_lp64)
   return Func::template Apply<MappingGoLoongArch64_47>(arg);
+#  elif SANITIZER_RISCV64
+  return Func::template Apply<MappingGoRiscv64>(arg);
 #  elif SANITIZER_WINDOWS
   return Func::template Apply<MappingGoWindows>(arg);
 #  else
@@ -798,6 +827,7 @@ void ForEachMapping() {
   Func::template Apply<MappingGoAarch64>();
   Func::template Apply<MappingGoLoongArch64_47>();
   Func::template Apply<MappingGoMips64_47>();
+  Func::template Apply<MappingGoRiscv64>();
   Func::template Apply<MappingGoS390x>();
 }
 
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index 3e08a1bece98f..373acd3d95d01 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -373,6 +373,12 @@ void InitializePlatformEarly() {
     Printf("FATAL: Found %zd - Supported 39 and 48\n", vmaSize);
     Die();
   }
+#    else
+  if (vmaSize != 48) {
+    Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
+    Printf("FATAL: Found %zd - Supported 48\n", vmaSize);
+    Die();
+  }
 #    endif
 #  endif
 



More information about the llvm-commits mailing list