golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.02k stars 17.54k forks source link

x/mobile/cmd/gomobile: bind command fails with "direct call too far" with 100 MB executable file #39143

Open Shagrat2 opened 4 years ago

Shagrat2 commented 4 years ago

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

$ go version
go version go1.13.11 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/ivan/Library/Caches/go-build"
GOENV="/Users/ivan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ivan/workspace/golang"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/3q/lnsctb9j41qc0f06wj7g0tjw0000gn/T/go-build885895559=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

gomobile bind -v -a -target=ios \
    -ldflags "-s -w \
    -X 'qxxx/Sxxl/SRVData.IOS=YES' \
    -X 'qxxx/sxxc/qkernel.CLibVer=$NOW' \
    -X 'qxxx/sxxc/qkernel.CLibTitle=$NOWTITLE' \
    -X 'qxxx/sxxc/qkernel.CLoadURL=$LOADURL'" \
    -tags "note full"

What did you see instead?

runtime/cgo
golang.org/x/mobile/internal/mobileinit
net
# github.com/mattn/go-sqlite3
sqlite3-binding.c:33220:8: warning: "gethostuuid() is disabled." [-W#warnings]
github.com/mattn/go-sqlite3
qxxx/Sxxl/SRVData
qxxx/Sxxl/SDLibrary
gobind
# gobind
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388635
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388639
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388645
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388651
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388657
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388718
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388726
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388732
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388763
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388768
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388772
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388775
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388779
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388783
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388785
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388789
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388672
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388803
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388808
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388814
qxxx/sxxs/v.z/vz.(*TEcu).Espsnsclbr90: direct call too far -8388820
/usr/local/go/pkg/tool/darwin_amd64/link: too many errors
gomobile: darwin-arm: go build -tags qnote RELEASE ios -v -gcflags -trimpath=/Users/xx/workspace/golang/src/qxxx -ldflags -s -w     -X 'qxxx/SDLocal/SRVData.IOS=YES'     -X 'qxxx/sxxc/qkernel.CLibVer=1909192208'     -X 'qxxx/sxxc/qkernel.CLibTitle=2019.09.19 22:08 Release'     -X 'qxxx/sxxc/qkernel.CLoadURL=https://sxxc.online' -buildmode=c-archive -o /var/folders/3q/lnsctb9j41qc0f06wj7g0tjw0000gn/T/gomobile-work-818468499/sdlibrary-arm.a ./gobind failed: exit status 2
cagedmantis commented 4 years ago

/cc @hyangah

hyangah commented 4 years ago

@cherrymui Can you please help with this linker error?

cherrymui commented 4 years ago

This is 32-bit darwin/arm right?

The linker inserts trampolines for far calls, but it is possible that we missed some cases. It would be good to know what the call target is, in particular, whether it is a regular Go function, or a C function, or something like a PLT stub (which I think there may be some problem)?

32-bit darwin/arm port is removed in Go 1.15, though.

cherrymui commented 4 years ago

(A quick workaround for this could be changing the calls to function pointer calls, like, instead of pkg.F(), do fn := pkg.F; fn()).

Shagrat2 commented 4 years ago

This is 32-bit darwin/arm right?

The linker inserts trampolines for far calls, but it is possible that we missed some cases. It would be good to know what the call target is, in particular, whether it is a regular Go function, or a C function, or something like a PLT stub (which I think there may be some problem)?

32-bit darwin/arm port is removed in Go 1.15, though.

Why 32 bit? https://en.wikipedia.org/wiki/Apple-designed_processors Compile for A7 and newer, is a 64bit arm

(*TEcu).Espsnsclbr90 - is GO struct function in my code. But the function is taken randomly

cherrymui commented 4 years ago

@Shagrat2 I don't know, I'm just asking.

Based on the error message, gomobile: darwin-arm, it looks like 32-bit ARM to me. We use the name arm64 for 64-bit ARM.

Shagrat2 commented 4 years ago

(A quick workaround for this could be changing the calls to function pointer calls, like, instead of pkg.F(), do fn := pkg.F; fn()).

This workaround failed