go: x/mobile: gomobile build fails for iOS targets
What version of Go are you using (go version)?
$ go version go version go1.12 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
macOS Mojave 10.14.5 (18F132)
go env Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/dan/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/dan/go" GOPROXY="" GORACE="" GOROOT="/usr/local/Cellar/go/1.12/libexec" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" 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/pv/rmyyshm95r78n31p86nnbznw0000gn/T/go-build908091193=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
$ go get golang.org/x/mobile/cmd/gomobile
$ go get -d golang.org/x/mobile/example/basic
$ gomobile build -bundleid basic.app -target=ios golang.org/x/mobile/example/basic
Note: the wiki instructions leave out the -bundleid parameter even though it appears to be required.
Output
gomobile: go build -tags ios -ldflags=-w -o=/var/folders/pv/rmyyshm95r78n31p86nnbznw0000gn/T/gomobile-work-749904680/arm golang.org/x/mobile/example/basic failed: exit status 2 # golang.org/x/mobile/app darwin_ios.m:139:77: warning: null passed to a callee that requires a non-null argument [-Wnonnull] # golang.org/x/mobile/example/basic /usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64/link: running /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed: exit status 1 ld: -headerpad and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together clang: error: linker command failed with exit code 1 (use -v to see invocation
What did you expect to see?
See https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-ios.
The build command will build an application bundle, named basic.app.
What did you see instead?
gomobile: go build -tags ios -ldflags=-w -o=/var/folders/pv/rmyyshm95r78n31p86nnbznw0000gn/T/gomobile-work-749904680/arm golang.org/x/mobile/example/basic failed: exit status 2
# golang.org/x/mobile/app
darwin_ios.m:139:77: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
# golang.org/x/mobile/example/basic
/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64/link: running /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed: exit status 1
ld: -headerpad and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
clang: error: linker command failed with exit code 1 (use -v to see invocation
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 43 (33 by maintainers)
Commits related to this issue
- cmd/link/internal/ld: remove flags incompatible with -fembed-bitcode The flags -headerpad, -Wl,-no_pie and -pagezero_size are incompatible with the -fembed-bitcode flag used by `gomobile build`. Than... — committed to golang/go by eliasnaur 5 years ago
- cmd/link: enable PIE on darwin/arm We used to pass -no_pie to external linker on darwin/arm, which is incompatible with -fembed-bitcode. CL 201358 attempted to remove the -no_pie flag, but it resulte... — committed to golang/go by cherrymui 5 years ago
- cmd/link/internal/ld: omit bitcode-incompatible flags on iOS simulator The -Wl,-headerpad, -Wl,-no_pie, -Wl,-pagezero_size flags are incompatible with the bitcode-related flags used for iOS. We alre... — committed to golang/go by eliasnaur 5 years ago
- cmd/link/internal/ld: set MachO platform to PLATFORM_IOS on iOS CL 205340 changed the linker to skip certain flags when linking for iOS. However, for host linking on iOS (such as on the Corellium dar... — committed to golang/go by eliasnaur 5 years ago
- cmd/gomobile: disable bitcode on Go 1.13 or older iOS's bitcode conflicts with headerpad on Go 1.13 or older. This problem is fixed on Go 1.14. This CL disables bitcode only on Go 1.13 or older. Fi... — committed to fyne-io/fyne by hajimehoshi 4 years ago
- cmd/gomobile: disable bitcode on Go 1.13 or older iOS's bitcode conflicts with headerpad on Go 1.13 or older. This problem is fixed on Go 1.14. This CL disables bitcode only on Go 1.13 or older. Fi... — committed to fyne-io/fyne by hajimehoshi 4 years ago
- cmd/gomobile: disable bitcode on Go 1.13 or older iOS's bitcode conflicts with headerpad on Go 1.13 or older. This problem is fixed on Go 1.14. This CL disables bitcode only on Go 1.13 or older. Fi... — committed to imWildCat/go-mobile by hajimehoshi 4 years ago
- cmd/gomobile: disable bitcode on Go 1.13 or older iOS's bitcode conflicts with headerpad on Go 1.13 or older. This problem is fixed on Go 1.14. This CL disables bitcode only on Go 1.13 or older. Fi... — committed to imWildCat/go-mobile by hajimehoshi 4 years ago
I did some digging and found that the answer to my own question is: nothing changed, but
gomobile buildmode broke with my bitcode-enabling CL168062. Presumably I testedgomobile bindbut failed to testgomobile buildwhen preparing that CL.gomobile buildbuilds an iOS executable, whilegomobile bindbuilds a C archive (using buildmode=c-archive). Building an iOS executable with-fembed-bitcodeis not compatible with the flagscmd/linkpass to the host linker; I’ve found-headerpad,-pagezero_sizeand-fno_pieto be incompatible.It seems to me the fix is to figure out why
cmd/linkneeds to pass the incompatible flags, and if it doesn’t, remove or replace them with bitcode compatible flags. Removing the incomptable flags succeeded in producing a binary but I haven’t run it nor tried to upload it to the App Store for verification.The next best fix is to work around the issue and switch
gomobile buildto use thebuildmode=c-archivelikegomobile bind. As a side effect,gomobile buildwill be much more similar togomobile bind, decreasing the likelyhood of future breaks.The easiest workaround is for
gomobile buildto omit-fembed-bitcode. The downside is that executables built this way will not have bitcode enabled. Since bitcode is not (yet) a requirement for iOS, I don’t think missing bitcode matters.CL 189857 implements the third option, except that it also omits the flag for
gomobile bindwhich is wrong.I don’t know how to create a PR for gomobile, so here is a consolidated patch file instead…
gomobile.diff.txt
Aha, the problem seems to be that the go tools we are using force -headerpad and that bitcode is now enabled by default and these conflict. The following patch to gomobile fixed it for me 😎.