Skip to content

Commit 6d63725

Browse files
committed
[tsan] Add Go support for linux/riscv64
1 parent 63113cf commit 6d63725

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

compiler-rt/lib/tsan/go/buildgo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ if [ "$GOOS" = "linux" ]; then
112112
ARCHCFLAGS="-mips64 -EL"
113113
elif [ "$GOARCH" = "mips64" ]; then
114114
ARCHCFLAGS="-mips64 -EB"
115+
elif [ "$GOARCH" = "riscv64" ]; then
116+
if [ "$GORISCV64" = "rva23u64" ]; then
117+
ARCHCFLAGS="-march=rv64gcv"
118+
else
119+
ARCHCFLAGS="-march=rv64gc"
120+
fi
115121
elif [ "$GOARCH" = "s390x" ]; then
116122
SRCS="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
117123
ARCHCFLAGS=""

compiler-rt/lib/tsan/rtl/tsan_platform.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,33 @@ struct MappingGoMips64_47 {
681681
static const uptr kShadowAdd = 0x200000000000ull;
682682
};
683683

684+
/* Go on linux/riscv64 (48-bit VMA)
685+
0000 0001 0000 - 00e0 0000 0000: executable and heap (896 GiB)
686+
00e0 0000 0000 - 2000 0000 0000: -
687+
2000 0000 0000 - 2400 0000 0000: shadow - 4 TiB ( ~ 4 * app)
688+
2400 0000 0000 - 3000 0000 0000: -
689+
3000 0000 0000 - 3100 0000 0000: metainfo - 1 TiB ( ~ 1 * app)
690+
3100 0000 0000 - 8000 0000 0000: -
691+
*/
692+
struct MappingGoRiscv64 {
693+
static const uptr kMetaShadowBeg = 0x300000000000ull;
694+
static const uptr kMetaShadowEnd = 0x310000000000ull;
695+
static const uptr kShadowBeg = 0x200000000000ull;
696+
static const uptr kShadowEnd = 0x240000000000ull;
697+
static const uptr kLoAppMemBeg = 0x000000010000ull;
698+
static const uptr kLoAppMemEnd = 0x000e00000000ull;
699+
static const uptr kMidAppMemBeg = 0;
700+
static const uptr kMidAppMemEnd = 0;
701+
static const uptr kHiAppMemBeg = 0;
702+
static const uptr kHiAppMemEnd = 0;
703+
static const uptr kHeapMemBeg = 0;
704+
static const uptr kHeapMemEnd = 0;
705+
static const uptr kVdsoBeg = 0;
706+
static const uptr kShadowMsk = 0;
707+
static const uptr kShadowXor = 0;
708+
static const uptr kShadowAdd = 0x200000000000ull;
709+
};
710+
684711
/*
685712
Go on linux/s390x
686713
0000 0000 1000 - 1000 0000 0000: executable and heap - 16 TiB
@@ -728,6 +755,8 @@ ALWAYS_INLINE auto SelectMapping(Arg arg) {
728755
return Func::template Apply<MappingGoAarch64>(arg);
729756
# elif defined(__loongarch_lp64)
730757
return Func::template Apply<MappingGoLoongArch64_47>(arg);
758+
# elif SANITIZER_RISCV64
759+
return Func::template Apply<MappingGoRiscv64>(arg);
731760
# elif SANITIZER_WINDOWS
732761
return Func::template Apply<MappingGoWindows>(arg);
733762
# else
@@ -798,6 +827,7 @@ void ForEachMapping() {
798827
Func::template Apply<MappingGoAarch64>();
799828
Func::template Apply<MappingGoLoongArch64_47>();
800829
Func::template Apply<MappingGoMips64_47>();
830+
Func::template Apply<MappingGoRiscv64>();
801831
Func::template Apply<MappingGoS390x>();
802832
}
803833

compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ void InitializePlatformEarly() {
373373
Printf("FATAL: Found %zd - Supported 39 and 48\n", vmaSize);
374374
Die();
375375
}
376+
# else
377+
if (vmaSize != 48) {
378+
Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
379+
Printf("FATAL: Found %zd - Supported 48\n", vmaSize);
380+
Die();
381+
}
376382
# endif
377383
# endif
378384

0 commit comments

Comments
 (0)