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

Go 1.16 beta1: ios/amd64 build fails #43343

Closed
marten-seemann opened this issue Dec 23, 2020 · 23 comments
Closed

Go 1.16 beta1: ios/amd64 build fails #43343

marten-seemann opened this issue Dec 23, 2020 · 23 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@marten-seemann
Copy link
Contributor

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

$ go version
go version go1.16beta1 darwin/amd64

What did you do?

I have a cross-compilation test which I run on CI. It builds a binary for all supported GOOS / GOARCH combinations (as reported by go tool dist list).

Using Go 1.15.x, GOOS=ios GOARCH=amd64 is unsupported:

cmd/go: unsupported GOOS/GOARCH pair ios/amd64

Go 1.16 apparently adds support, but building fails. On my Mac, the error message is the following:

❯ GOOS=ios GOARCH=amd64 go build example/main.go
# command-line-arguments
loadinternal: cannot find runtime/cgo

On CI (GitHub Actions), I'm getting the following failure:

# command-line-arguments
loadinternal: cannot find runtime/cgo
/opt/hostedtoolcache/go/1.16.0-beta1/x64/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find 1144: No such file or directory
/tmp/go-link-046955828/go.o: file not recognized: file format not recognized
collect2: error: ld returned 1 exit status

Not sure what exactly this means, nor do I particularly care about building for this architecture. However, if go tool dist list lists this as a support combination, I would have expected the build to succeed.

What did you expect to see?

go build should succeed.

What did you see instead?

go build failed, see above.

@egonelbre
Copy link
Contributor

Maybe you need an explicit CGO_ENABLED=1?

@marten-seemann
Copy link
Contributor Author

The code I’m building doesn’t use cgo, and the build settings I’m using work fine for all other combinations.

@egonelbre
Copy link
Contributor

Ah, now I understand. It's using amd64 and not arm64.

https://github.com/golang/go/tree/master/misc/ios has instructions how to use it.

@egonelbre
Copy link
Contributor

Also using CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build example.go does work on the tip and with go1.16beta1. So it seems CGO_ENABLED is required, regardless whether you are using C.

@egonelbre
Copy link
Contributor

CC @eliasnaur.

@egonelbre
Copy link
Contributor

Maybe it needs to make CGO_ENABLED default to 1 for that platform or throw an error when it has not been enabled -- no clue where it should go though.

@eliasnaur
Copy link
Contributor

I'm not sure either. CC @cherrymui.

@cherrymui
Copy link
Member

Yeah, CGO_ENABLED needs to be set to 1, because currently the ios port requires external linking, which uses the C linker.

loadinternal: cannot find runtime/cgo

This is not an error. It should generate the executable and it probably runs fine.

CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build example.go does work on the tip and with go1.16beta1.

Could you explain what doesn't work?

@cherrymui
Copy link
Member

CGO_ENABLED is default to 0 for cross-compilation. It may be reasonable to error out on ports require cgo.

@egonelbre
Copy link
Contributor

@cherrymui Erroring sounds less "risky" because it can be made to work later. I would create a change, but I have no clue where the appropriate place would be. (Also, probably faster if someone else who knows where and how to exactly restrict it.)

@cherrymui
Copy link
Member

Erroring sounds less "risky" because it can be made to work later.

Yeah, I think it shouldn't be hard to make internal linking work for iOS, then you don't need the C linker. Maybe in Go 1.17. Not sure it is that useful, though, since for actual iOS apps I think it generally needs some C (or other language) part.

That said, I think it's been the case for quite a while (CGO_ENABLED stuff for cross-compilation). As we're late in the release cycle, maybe it's better to do the erroring behavior in Go 1.17. This probably will be in cmd/go, but I'm not sure exactly where. Issue #31544 might be relevant (about the loadinternal message).

@cherrymui
Copy link
Member

@egonelbre could you clarify if CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build works? (This is the primary issue) On my Mac it works fine.

$ CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build hello.go
$ ./hello
hello

@dmitshur dmitshur added mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 23, 2020
@egonelbre
Copy link
Contributor

@churrymui Yes CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build works.

The main issue is that GOOS=ios GOARCH=amd64 go build gives a really weird error - so it would be better to print out CGO_ENABLED=1 is required for ios/amd64 or alternatively add CGO_ENABLED=1 automatically.

@enty8080
Copy link

@cherrymui:

root@Ivans-Air work # ls
build.sh	main-ios	main.go
root@Ivans-Air work # rm main-ios
root@Ivans-Air work # CGO_ENABLED=1 GOOS=ios GOARCH=amd64 go build main.go 
# runtime/cgo
gcc_darwin_amd64.c:62:15: error: unknown token in expression
<inline asm>:1:12: note: instantiated into assembly here
gcc_darwin_amd64.c:62:15: error: invalid operand
<inline asm>:1:12: note: instantiated into assembly here
root@Ivans-Air work # ls
build.sh	main.go

What I should do with this?

@eliasnaur
Copy link
Contributor

@enty8080 your go build command worked for egonelbre and cherrymui, so what's unusual about your setup? Are you building on an iDevice? What does go env say, and what about clang -v?

@enty8080
Copy link

enty8080 commented Dec 26, 2020

@eliasnaur root@Ivans-Air work # means that I building from MacBook Air.

go version

go version go1.16beta1 darwin/arm64

clang -v

Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/enty8080/Library/Caches/go-build"
GOENV="/Users/enty8080/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/enty8080/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/enty8080/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mp/l216mspj1r793n3f2zhh8vg40000gn/T/go-build1298098095=/tmp/go-build -gno-record-gcc-switches -fno-common"

@eliasnaur
Copy link
Contributor

I don't know the reason for your error. FWIW, Rob may have had the same issue:

I also have to set CGO_ENABLED=0 because of an assembly language syntax error (something about [reg] notation) that stops the build.

@enty8080
Copy link

@eliasnaur I am using latest MacBook Air:
Screenshot 2020-12-26 at 15 38 58

@cherrymui
Copy link
Member

See https://tip.golang.org/misc/ios/README . For cross compilation in general, you need to set CC to the C cross compiler.

@enty8080
Copy link

@cherrymui Thanks, I answered here #43371

@gopherbot
Copy link

Change https://golang.org/cl/280154 mentions this issue: doc/go1.16: reference misc/ios/README for how to build iOS programs

@gopherbot
Copy link

Change https://golang.org/cl/280153 mentions this issue: misc/ios: add to README how to build ios executables

gopherbot pushed a commit that referenced this issue Dec 29, 2020
Updates #43371, #43343.

Change-Id: I19386269245f2c20345c6cac7560089b8223e9f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/280153
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
gopherbot pushed a commit that referenced this issue Dec 29, 2020
Updates #43371, #43343.

Change-Id: Ib89b809a5220717507272453ea86224d1928dd36
Reviewed-on: https://go-review.googlesource.com/c/go/+/280154
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@cherrymui
Copy link
Member

From #43343 (comment) the ios/amd64 build works, so this issue is resolved.

I'll look into erroring out when cgo is not enabled (not necessarily in this release, though).

trianglesphere pushed a commit to celo-org/celo-blockchain that referenced this issue Sep 23, 2021
This might fix the issue when running ios builds.
See golang/go#43343
@golang golang locked and limited conversation to collaborators Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants