Open
Description
What version of Go are you using (go version
)?
master
as of the opening of this issue
$ go version go version devel +5adaa1290e Thu Jun 11 06:04:57 2020 +0000 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/steeve/Library/Caches/go-build" GOENV="/Users/steeve/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/steeve/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/steeve/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/Users/steeve/code/github.com/znly/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/Users/steeve/code/github.com/znly/go/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/steeve/code/github.com/znly/go/src/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bs/51dlb_nn5k35xq9qfsxv9wc00000gr/T/go-build749515592=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Since darwin/amd64
and linux/arm64
are supported, I figure I'd give it a shot. Applied this patch to try and "enable" the race detector on ios/arm64
:
diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go
index c27b3b986d..00faf49f8a 100644
--- a/src/cmd/internal/sys/supported.go
+++ b/src/cmd/internal/sys/supported.go
@@ -13,8 +13,10 @@ func RaceDetectorSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
- case "darwin", "freebsd", "netbsd", "windows":
+ case "freebsd", "netbsd", "windows":
return goarch == "amd64"
+ case "darwin":
+ return goarch == "amd64" || goarch == "arm64"
default:
return false
}
What did you expect to see?
Hopefully a successful build with the race detector enabled.
What did you see instead?
The linker fails/crashes with the following:
Use --sandbox_debug to see verbose messages from the sandbox
runtime.rt0_go: missing section for runtime.tls_g
runtime.load_g: missing section for runtime.tls_g
runtime.save_g: missing section for runtime.tls_g
runtime.rt0_go: reloc 3 (R_ADDRARM64) to non-macho symbol runtime.tls_g type=37 (STLSBSS)
runtime.rt0_go: unsupported obj reloc 3 (R_ADDRARM64)/8 to runtime.tls_g
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x2 pc=0x1213e6e]
goroutine 1 [running]:
cmd/link/internal/arm64.machoreloc1(0x1473b20, 0xc0000b6070, 0xc0049bd000, 0xc005222c40, 0x642e4, 0x1)
/Users/steeve/code/github.com/znly/go/src/cmd/link/internal/arm64/asm.go:388 +0x4ce
cmd/link/internal/ld.machorelocsect(0xc000071880, 0xc0000b62a0, 0xc001a50000, 0x4279, 0x4279)
/Users/steeve/code/github.com/znly/go/src/cmd/link/internal/ld/macho.go:1067 +0x18c
cmd/link/internal/ld.Machoemitreloc(0xc000071880)
/Users/steeve/code/github.com/znly/go/src/cmd/link/internal/ld/macho.go:1081 +0xca
cmd/link/internal/arm64.asmb2(0xc000071880)
/Users/steeve/code/github.com/znly/go/src/cmd/link/internal/arm64/asm.go:912 +0x5a5
cmd/link/internal/ld.Main(0x1473b20, 0x10, 0x20, 0x1, 0x1f, 0x1e, 0x12d3faa, 0x14, 0x12d767f, 0x1a, ...)
/Users/steeve/code/github.com/znly/go/src/cmd/link/internal/ld/main.go:349 +0x1509
main.main()
/Users/steeve/code/github.com/znly/go/src/cmd/link/main.go:68 +0x1dc
link: error running subcommand: exit status 2
Mainly opening this issue so the discussion can be had.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Triage Backlog
Milestone
Relationships
Development
No branches or pull requests
Activity
randall77 commentedon Jun 11, 2020
You might want to look at https://go-review.googlesource.com/c/go/+/237057 which enables the race detector on openbsd/amd64. Particularly, getting the race detector library working would be a first step (maybe it already works on darwin/arm64? Not sure).
@dvyukov
dvyukov commentedon Jun 11, 2020
ThreadSanitizer works on darwin/arm64 for C/C++ IIRC, but some spot fixing may be required for Go.
This is the corresponding change to ThreadSanitizer:
https://reviews.llvm.org/D80469
At the very least the same will be required for darwin/arm64. If it works (build succeeds) then it will possible to copy the syso file into Go and do testing.
steeve commentedon Jun 11, 2020
Thanks to @randall77, I updated the diff to the following, unfortunately with same errors:
steeve commentedon Jun 11, 2020
Oh! I didn't see that tsan was shipped as a
.syso
file!steeve commentedon Jun 11, 2020
@dvyukov I am struggling to find how to 1. build only tsan and 2. cross compile it (as it seems the toolchain,
buildgo.sh
, expects the host and target to be the same). Would you have any pointers by chance? Thanks!dvyukov commentedon Jun 11, 2020
buildgo.sh
builds only tsan (for Go).randall77 commentedon Jun 11, 2020
We normally build the syso files using the racebuild tool. It's mentioned in runtime/race/README.
You'll just need to add a section to racebuild.go for the target architecture. You'll probably have to start with running the commands in the new section by hand on the target to make sure they work, as the racebuild tool runs everything inside a gomote, which makes it hard to debug.
steeve commentedon Jun 11, 2020
Thank you @dvyukov. Somehow this morning I couldn't make it work, but I do now.
It seems all I need now is to find the correct mapping for Go on
darwin/arm64
, it's complaining it can't findkHiAppMemEnd
:The offending part is:
Indeed, look at
tsan_platform.h
, I see:So I'm not really sure how this builds on
linux/arm64
.Still digging. Thank you folks for the precious help! I'm feeling this might just work soon!
steeve commentedon Jun 11, 2020
@randall77 That's great information thank you.
steeve commentedon Jun 11, 2020
Ah got it it's because of
SANITIZER_MAC
. It seems I'll have to comment that out whenSANITIZER_GO
is present.steeve commentedon Jun 11, 2020
Getting close:
steeve commentedon Jun 11, 2020
I was missing libc++. It worked:
Now I'm gonna try it in Go, but so far it's not looking bad.
steeve commentedon Jun 11, 2020
I Go to recognize the
.syso
, however, the linker is still crashing, so I think some additional work is needed:steeve commentedon Jun 11, 2020
If anyone wants to investigate
The diff to Go
The (dirty) diff to LLVM
The pre-built syso file
race_darwin_arm64.syso.zip