Gomobile bind failed: duplicate symbol

I have this simple file:

$ cat goTest.go 
package goTest

type Hello interface {
	SayHello()
}

func CallJava(h Hello) {
	h.SayHello()
}

I did a go mod init goTest in the directory.
And then I do a gomobile bind which failed:

$ gomobile bind -target=android -v
write /tmp/gomobile-work-794247297/src/go.mod
go: downloading golang.org/x/mobile v0.0.0-20200801112145-973feb4309de
go: found goTest in goTest v0.0.0-00010101000000-000000000000
runtime/cgo
# runtime/cgo
ld: error: duplicate symbol: x_cgo_inittls
>>> defined at gcc_android.c:90
>>>            $WORK/b040/_x003.o:(x_cgo_inittls)
>>> defined at gcc_linux_arm.c:13
>>>            $WORK/b040/_x006.o:(.bss+0x4)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gomobile: go build -v -buildmode=c-shared -o=/tmp/gomobile-work-794247297/android/src/main/jniLibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 2

My system:

  • 5.9.8-arch1-1 #1 SMP PREEMPT Tue, 10 Nov 2020 22:44:11 +0000 x86_64 GNU/Linux

  • go version go1.15.5 linux/amd64

  • gcc (GCC) 10.2.0

    $ go env
    GO111MODULE=""
    GOARCH=“amd64”
    GOBIN=""
    GOCACHE="/home/rems14/.cache/go-build"
    GOENV="/home/rems14/.config/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH=“amd64”
    GOHOSTOS=“linux”
    GOINSECURE=""
    GOMODCACHE="/home/rems14/go/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS=“linux”
    GOPATH="/home/rems14/go"
    GOPRIVATE=""
    GOPROXY=“https://proxy.golang.org,direct”
    GOROOT="/usr/lib/go"
    GOSUMDB=“sum.golang.org
    GOTMPDIR=""
    GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
    GCCGO=“gccgo”
    AR=“ar”
    CC=“gcc”
    CXX=“g++”
    CGO_ENABLED=“1”
    GOMOD="/home/rems14/test/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build471762076=/tmp/go-build -gno-record-gcc-switches"

    $ env | grep PATH
    PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/rems14/go/bin:/usr/lib/go/bin:/home/rems14/Android/Sdk/build-tools/30.0.2:/home/rems14/Android/Sdk/platform-tools:/home/rems14/Android/Sdk/ndk/22.0.6917172
    GOPATH=/home/rems14/go

    $ env | grep ANDROID
    ANDROID_NDK_HOME=/home/rems14/Android/Sdk/ndk/22.0.6917172
    ANDROID_HOME=/home/rems14/Android/Sdk

Steps I tried:

  • change go version to 1.15.3 (I know this version works on another PC) and remove ~/go directory
  • change gcc version to 9

duplicate here: https://github.com/golang/go/issues/42655