-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile,runtime: race support for riscv64 #64345
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
Comments
I can setup a linux-riscv64-race builder(LUCI) for you. |
Thanks @mengzhuo, appreciate if you could handle that 🙏 |
@mengzhuo I tried compiling the syso file for riscv64 with CC=clang and got stuck in this part: runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LBB438_37 (type=291 (R_RISCV_ADD32) stype=1 (STEXT))
runtime/race(.rodata): unexpected relocation type 295 (R_RISCV_SUB32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LJTI438_0 (type=295 (R_RISCV_SUB32) stype=9 (SRODATA))runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LBB438_169 (type=291 (R_RISCV_ADD32) stype=1 (STEXT))
runtime/race(.rodata): unexpected relocation type 295 (R_RISCV_SUB32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LJTI438_0 (type=295 (R_RISCV_SUB32) stype=9 (SRODATA))runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LBB438_169 (type=291 (R_RISCV_ADD32) stype=1 (STEXT))
runtime/race(.rodata): unexpected relocation type 295 (R_RISCV_SUB32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LJTI438_0 (type=295 (R_RISCV_SUB32) stype=9 (SRODATA))runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LBB438_169 (type=291 (R_RISCV_ADD32) stype=1 (STEXT))
runtime/race(.rodata): unexpected relocation type 295 (R_RISCV_SUB32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LJTI438_0 (type=295 (R_RISCV_SUB32) stype=9 (SRODATA))runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LBB438_169 (type=291 (R_RISCV_ADD32) stype=1 (STEXT))
runtime/race(.rodata): unexpected relocation type 295 (R_RISCV_SUB32)
runtime/race(.rodata): unsupported dynamic relocation for symbol .LJTI438_0 (type=295 (R_RISCV_SUB32) stype=9 (SRODATA))runtime/race(.rodata): unexpected relocation type 291 (R_RISCV_ADD32)
/home/ubuntu/git/go/pkg/tool/linux_riscv64/link: too many errors Maybe I have to use some specific compiler flag? I see that these relocations are currently supported in the go linker |
@mauri870 that looks like the riscv64 linker is missing handling for some relocation types - do you have a branch handy that I can build/test from? |
@4a6f656c I have some changes in one of my branches, hopefully you can still build from it, if not then let me know: https://github.com/golang/go/compare/master...mauri870:go:feature/race-riscv64?expand=1 Edit: If you wanna compile the syso file yourself, then you have to get a hold of a llvm copy and then |
@mauri870 I've added the missing relocation handling to the internal linker and fixed up some other aspects of the riscv64 race code: https://github.com/4a6f656c/go/tree/riscv64-race We can now call into the TSAN code, however it fails on the call to
At a first guess, this looks like it is using the 48-bit VMA mapping even though it is running on a 39-bit VMA platform. |
@4a6f656c Error 12 is ENOMEM, perhaps you are running out of memory on this machine? Looking at the riscv64 tsan commit in llvm the |
The issue is caused by the fact that there is no Go mapping configuration for riscv64, which means we're falling through to the default. I've pushed some further fixes to https://github.com/4a6f656c/go/tree/riscv64-race which makes the Go side of things correct, however even with a Go riscv64 mapping added to llvm, I've not been able to get it to detect races (the Go code is instrumented correctly and calls into the race detector code). The next step is to figure out the correct TSAN mappings for riscv64 in VMA 39 and VMA 48 modes (and we'll likely need to adjust Go's |
After some work on @4a6f656c 's riscv64-race branch, it's working now. But it requires llvm/llvm-project#127295 to be merged first. |
Great. I did try this out on QEMU and it did indeed detect a race. Is there any reason why the llvm patch seems to be sv48 only? When I tried the patch on my VF2 running Ubuntu 24.04 I got
|
TSAN shadow memory requires at least 4 times of app VM. You can check this memory mappings: https://github.com/llvm/llvm-project/pull/127295/files#diff-2c1abce7a33228a6123799fcd314048c1a4df96d93dbad00e2b614a7ee4dde53R684-R690 |
Getting it working on sv48 is great progress, however I think we'll need to figure out a way to get it working on sv39... otherwise it is going to be of limited use and difficult to test via a race builder. |
This is needed to support race detector in Golang. See also: golang/go#64345
This is needed to support race detector in Golang. See also: golang/go#64345
This is needed to support race detector in Golang. See also: golang/go#64345
Does this pass an |
No. The race test always failed with difference testcase :( To figure out what problem is, |
There was a previous issue requesting support for riscv64 (#58739), but it was closed because upstream support in LLVM was lacking.
On Oct 6 support for riscv64 was finally merged into the LLVM tree.
I propose we reconsider adding race detector support to Risc-V. From the top of my head this would require:
Happy to work on this for the early stage of Go 1.23.
cc @golang/runtime @golang/riscv64
The text was updated successfully, but these errors were encountered: