Skip to content

[tsan][RISCV] Add Go support for linux/riscv64 #127295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler-rt/lib/tsan/go/buildgo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
30 changes: 30 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>();
}

Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down