Skip to content
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

cmd/go: missing __tsan_* functions in cross-compiled windows/amd64 race build #42382

Closed
BenLubar opened this issue Nov 4, 2020 · 7 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@BenLubar
Copy link

BenLubar commented Nov 4, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.3 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/ben/go/bin"
GOCACHE="/home/ben/.cache/go-build"
GOENV="/home/ben/.config/go/env"
GOEXE=".exe"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ben/.golang-path/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="windows"
GOPATH="/home/ben/.golang-path"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="x86_64-w64-mingw32-ar"
CC="x86_64-w64-mingw32-gcc"
CXX="x86_64-w64-mingw32-g++"
CGO_ENABLED="1"
GOMOD="/home/ben/src/testapp/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="-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build693552172=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.15.3 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.15.3
uname -sr: Linux 5.8.0-25-generic
Distributor ID: Ubuntu
Description:    Ubuntu 20.10
Release:        20.10
Codename:       groovy
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.32-0ubuntu3) release release version 2.32.
gdb --version: GNU gdb (Ubuntu 9.2-0ubuntu2) 9.2

What did you do?

ben@urist:~/src/testapp$ ls
main.go
ben@urist:~/src/testapp$ go mod init testapp
go: creating new go.mod: module testapp
ben@urist:~/src/testapp$ cat main.go 
package main

import "fmt"

func main() {
        fmt.Println("Test")
}
ben@urist:~/src/testapp$ GOOS=windows go build
ben@urist:~/src/testapp$ wine ./testapp.exe 
Test
ben@urist:~/src/testapp$ GOOS=windows go build -race
# testapp
runtime.mallocgc: relocation target __tsan_malloc not defined
runtime.runfinq: relocation target __tsan_finalizer_goroutine not defined
runtime.(*mspan).sweep: relocation target __tsan_free not defined
runtime.goexit1: relocation target __tsan_go_end not defined
runtime.gfget: relocation target __tsan_malloc not defined
runtime.(*p).init: relocation target __tsan_proc_create not defined
runtime.(*p).destroy: relocation target __tsan_proc_destroy not defined
runtime.(*p).destroy: relocation target __tsan_go_end not defined
runtime.RaceDisable: relocation target __tsan_go_ignore_sync_begin not defined
runtime.RaceEnable: relocation target __tsan_go_ignore_sync_end not defined
runtime.raceinit: relocation target __tsan_init not defined
runtime.raceinit: relocation target __tsan_map_shadow not defined
runtime.racefini: relocation target __tsan_fini not defined
runtime.racemapshadow: relocation target __tsan_map_shadow not defined
runtime.racegostart: relocation target __tsan_go_start not defined
runtime.raceacquireg: relocation target __tsan_acquire not defined
runtime.raceacquirectx: relocation target __tsan_acquire not defined
runtime.racereleaseg: relocation target __tsan_release not defined
runtime.racereleasemergeg: relocation target __tsan_release_merge not defined
runtime.stackalloc: relocation target __tsan_malloc not defined
racefuncenter: relocation target __tsan_func_enter not defined
/usr/local/go/pkg/tool/linux_amd64/link: too many errors
unexpected fault address 0x7f9bd320b000
fatal error: fault

I'm using gcc-mingw-w64-x86-64 version 9.3.0-7ubuntu1+22~exp1ubuntu4 from the Ubuntu Groovy universe repo, and Go 1.15.3 from https://golang.org/dl/. I was previously using the version of Go from the longsleep PPA, where I was able to successfully build with -race, but that has not been updated to 1.15.3 yet.

@cherrymui
Copy link
Member

-race mode requires cgo. You need to set CGO_ENABLED=1 (which is default to 0 when cross-compilation) and CC to a cross C compiler.

(I wonder why the go command doesn't just fail. On my machine it fails like

$ GOOS=windows go build -race 
go build: -race requires cgo

)

@BenLubar
Copy link
Author

BenLubar commented Nov 4, 2020

Same result (apart from the temp directory) with

package main

// #include <stdlib.h>
// #include <stdio.h>
import "C"
import "unsafe"

func main() {
        cstr := C.CString("Test")
        defer C.free(unsafe.Pointer(cstr))

        C.puts(cstr)
}

@cherrymui
Copy link
Member

cherrymui commented Nov 5, 2020

Could you paste the exact command you run and its output? Maybe do go build -race -x to print more information. Thanks.

Also, do you have any of CC, CGO_ENABLED, and GOFLAGS set in your environment?

@BenLubar
Copy link
Author

BenLubar commented Nov 6, 2020

I have a wrapper script that sets some environment variables for cross compiling.

ben@urist:~/src/testapp$ alias go
alias go='go_wrapper'
ben@urist:~/src/testapp$ GOOS=windows bash -x ~/bin/go_wrapper build -race -x
+ case $(go env GOOS) in
++ go env GOOS
+ case $(go env GOARCH) in
++ go env GOARCH
+ export CGO_ENABLED=1
+ CGO_ENABLED=1
+ export AR=x86_64-w64-mingw32-ar
+ AR=x86_64-w64-mingw32-ar
+ export CC=x86_64-w64-mingw32-gcc
+ CC=x86_64-w64-mingw32-gcc
+ export CXX=x86_64-w64-mingw32-g++
+ CXX=x86_64-w64-mingw32-g++
+ exec go build -race -x
WORK=/tmp/go-build600318297
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg.link << 'EOF' # internal
packagefile testapp=/home/ben/.cache/go-build/19/1908dd04fd326123473acca68f53bc324ae00766bc7fbe608d44f84f20b1771e-d
packagefile fmt=/usr/local/go/pkg/windows_amd64_race/fmt.a
packagefile runtime=/usr/local/go/pkg/windows_amd64_race/runtime.a
packagefile runtime/race=/usr/local/go/pkg/windows_amd64_race/runtime/race.a
packagefile errors=/usr/local/go/pkg/windows_amd64_race/errors.a
packagefile internal/fmtsort=/usr/local/go/pkg/windows_amd64_race/internal/fmtsort.a
packagefile io=/usr/local/go/pkg/windows_amd64_race/io.a
packagefile math=/usr/local/go/pkg/windows_amd64_race/math.a
packagefile os=/usr/local/go/pkg/windows_amd64_race/os.a
packagefile reflect=/usr/local/go/pkg/windows_amd64_race/reflect.a
packagefile strconv=/usr/local/go/pkg/windows_amd64_race/strconv.a
packagefile sync=/usr/local/go/pkg/windows_amd64_race/sync.a
packagefile unicode/utf8=/usr/local/go/pkg/windows_amd64_race/unicode/utf8.a
packagefile internal/bytealg=/usr/local/go/pkg/windows_amd64_race/internal/bytealg.a
packagefile internal/cpu=/usr/local/go/pkg/windows_amd64_race/internal/cpu.a
packagefile runtime/internal/atomic=/usr/local/go/pkg/windows_amd64_race/runtime/internal/atomic.a
packagefile runtime/internal/math=/usr/local/go/pkg/windows_amd64_race/runtime/internal/math.a
packagefile runtime/internal/sys=/usr/local/go/pkg/windows_amd64_race/runtime/internal/sys.a
packagefile runtime/cgo=/usr/local/go/pkg/windows_amd64_race/runtime/cgo.a
packagefile internal/reflectlite=/usr/local/go/pkg/windows_amd64_race/internal/reflectlite.a
packagefile sort=/usr/local/go/pkg/windows_amd64_race/sort.a
packagefile math/bits=/usr/local/go/pkg/windows_amd64_race/math/bits.a
packagefile internal/oserror=/usr/local/go/pkg/windows_amd64_race/internal/oserror.a
packagefile internal/poll=/usr/local/go/pkg/windows_amd64_race/internal/poll.a
packagefile internal/syscall/execenv=/usr/local/go/pkg/windows_amd64_race/internal/syscall/execenv.a
packagefile internal/syscall/windows=/usr/local/go/pkg/windows_amd64_race/internal/syscall/windows.a
packagefile internal/testlog=/usr/local/go/pkg/windows_amd64_race/internal/testlog.a
packagefile sync/atomic=/usr/local/go/pkg/windows_amd64_race/sync/atomic.a
packagefile syscall=/usr/local/go/pkg/windows_amd64_race/syscall.a
packagefile time=/usr/local/go/pkg/windows_amd64_race/time.a
packagefile unicode/utf16=/usr/local/go/pkg/windows_amd64_race/unicode/utf16.a
packagefile internal/unsafeheader=/usr/local/go/pkg/windows_amd64_race/internal/unsafeheader.a
packagefile unicode=/usr/local/go/pkg/windows_amd64_race/unicode.a
packagefile internal/race=/usr/local/go/pkg/windows_amd64_race/internal/race.a
packagefile internal/syscall/windows/sysdll=/usr/local/go/pkg/windows_amd64_race/internal/syscall/windows/sysdll.a
packagefile internal/syscall/windows/registry=/usr/local/go/pkg/windows_amd64_race/internal/syscall/windows/registry.a
EOF
mkdir -p $WORK/b001/exe/
cd .
/usr/local/go/pkg/tool/linux_amd64/link -o $WORK/b001/exe/a.out.exe -importcfg $WORK/b001/importcfg.link -installsuffix race -buildmode=pie -buildid=91CZfwTNXTnSMN_Xvhc5/XmDwFHDG44ebI2Y131zS/EftoGLSH8We2LILhVofs/91CZfwTNXTnSMN_Xvhc5 -race -extld=x86_64-w64-mingw32-gcc /home/ben/.cache/go-build/19/1908dd04fd326123473acca68f53bc324ae00766bc7fbe608d44f84f20b1771e-d
# testapp
runtime.mallocgc: relocation target __tsan_malloc not defined
runtime.runfinq: relocation target __tsan_finalizer_goroutine not defined
runtime.(*mspan).sweep: relocation target __tsan_free not defined
runtime.goexit1: relocation target __tsan_go_end not defined
runtime.gfget: relocation target __tsan_malloc not defined
runtime.(*p).init: relocation target __tsan_proc_create not defined
runtime.(*p).destroy: relocation target __tsan_proc_destroy not defined
runtime.(*p).destroy: relocation target __tsan_go_end not defined
runtime.RaceDisable: relocation target __tsan_go_ignore_sync_begin not defined
runtime.RaceEnable: relocation target __tsan_go_ignore_sync_end not defined
runtime.raceinit: relocation target __tsan_init not defined
runtime.raceinit: relocation target __tsan_map_shadow not defined
runtime.racefini: relocation target __tsan_fini not defined
runtime.racemapshadow: relocation target __tsan_map_shadow not defined
runtime.racegostart: relocation target __tsan_go_start not defined
runtime.raceacquireg: relocation target __tsan_acquire not defined
runtime.raceacquirectx: relocation target __tsan_acquire not defined
runtime.racereleaseg: relocation target __tsan_release not defined
runtime.racereleasemergeg: relocation target __tsan_release_merge not defined
runtime.stackalloc: relocation target __tsan_malloc not defined
racefuncenter: relocation target __tsan_func_enter not defined
/usr/local/go/pkg/tool/linux_amd64/link: too many errors
unexpected fault address 0x7f31571907e8
fatal error: fault

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 6, 2020
@toothrot toothrot added this to the Backlog milestone Nov 6, 2020
@toothrot toothrot changed the title missing __tsan_* functions in cross-compiled windows/amd64 race build cmd/go: missing __tsan_* functions in cross-compiled windows/amd64 race build Nov 6, 2020
@AlexRouSg
Copy link
Contributor

@BenLubar Saw you post on slack and decided to dig into this.

The gist is you are missing the file go\src\runtime\race\race_windows_amd64.syso.
For some reason the .syso files needed to cross compile in race mode are deleted when doing a release.

The easiest way to get this file seems to be to copy from the windows release.

@BenLubar
Copy link
Author

Can confirm successfully being able to build with GOOS=windows and -race if I copy the syso files from go.git/src/runtime/race/*.syso to /usr/local/go/src/runtime/race/*.syso

@seankhliao
Copy link
Member

Closing as this was an intentional change in CL 144281

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

6 participants