[compiler-rt] 76910f9 - [tsan][RISCV] Add Go support for linux/riscv64 (#127295)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 02:27:51 PST 2025
Author: Meng Zhuo
Date: 2025-02-28T18:27:48+08:00
New Revision: 76910f914cdd4b86b28e0d5852155244ee47dc53
URL: https://github.com/llvm/llvm-project/commit/76910f914cdd4b86b28e0d5852155244ee47dc53
DIFF: https://github.com/llvm/llvm-project/commit/76910f914cdd4b86b28e0d5852155244ee47dc53.diff
LOG: [tsan][RISCV] Add Go support for linux/riscv64 (#127295)
This is needed to support race detector in Golang.
See also: https://github.com/golang/go/issues/64345
Added:
Modified:
compiler-rt/lib/tsan/go/buildgo.sh
compiler-rt/lib/tsan/rtl/tsan_platform.h
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
Removed:
################################################################################
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