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

ios/arm64 executable: must specify a minimum supported OS version. #43371

Closed
enty8080 opened this issue Dec 24, 2020 · 22 comments
Closed

ios/arm64 executable: must specify a minimum supported OS version. #43371

enty8080 opened this issue Dec 24, 2020 · 22 comments

Comments

@enty8080
Copy link

enty8080 commented Dec 24, 2020

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

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

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="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="ios"
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="0"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mp/l216mspj1r793n3f2zhh8vg40000gn/T/go-build2420543642=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

On my Mac:

# export GOOS=ios
# export GOARCH=arm64
# go build main.go

What did you expect to see?

I expected to executable successfully executed in my jailbroken iOS terminal.

What did you see instead?

On my iOS device:

$ ./main
dyld: MH_EXECUTE binaries must specify a minimum supported OS version
Abort trap 6

iOS: 13.3.3 (arm64)
macOS: Big Sur

@mengzhuo
Copy link
Contributor

cc @cherrymui

@dmitshur
Copy link
Contributor

dmitshur commented Dec 25, 2020

Have you considered using the gomobile tool to build the binary, instead of the go tool directly? gomobile is higher level and should address this kind of issue.

If you’re using go build directly, does it help if you set CGO_CFLAGS=-miphoneos-version-min=10.0 (and possibly also CGO_CXXFLAGS, CGO_LDFLAGS)?

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/280313 mentions this issue: cmd/link/internal: specify LC_VERSION_MIN_IPHONEOS for iOS builds

@eliasnaur
Copy link
Contributor

@enty8080 does CL 280313 linked above work for you?

@enty8080
Copy link
Author

@dmitshur gomobile does not works for me. It returns: can't find package command-line-tools.

@enty8080
Copy link
Author

@eliasnaur Yes, when this (https://golang.org/cl/280313) will be added?

@enty8080
Copy link
Author

@eliasnaur @dmitshur @cherrymui Also look at this please #43378

@eliasnaur
Copy link
Contributor

@eliasnaur Yes, when this (https://golang.org/cl/280313) will be added?

Go is in a freeze for Go 1.16, so it's up to the release team to decide whether something like CL 280313 should go in 1.16 or 1.17.

@enty8080
Copy link
Author

enty8080 commented Dec 25, 2020

@eliasnaur Also I faced this error:

root@Ivans-Air work # ls
build.sh	main.go
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

Solution from #43343 not works for me.

For ios/arm64 works well.

@cherrymui
Copy link
Member

See https://tip.golang.org/misc/ios/README . Does it work with GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC=$(go env GOROOT)/misc/ios/clangwrap.sh go build (or amd64)? Thanks.

@enty8080
Copy link
Author

@cherrymui yes it compiles successfully with this clangwrap. Thanks. But there is another problem with MH_EXECUTE

$ ./main
dyld: MH_EXECUTE binaries must specify a minimum supported OS version
Abort trap 6

@cherrymui
Copy link
Member

@enty8080 What platform you are targeting, arm64 or amd64? How do you run the binary? Does the output binary has an LC_VERSION_MIN_IPHONEOS load command? (you can see it by running otool -l <binary> | grep VERSION_MIN) Thanks.

@enty8080
Copy link
Author

enty8080 commented Dec 28, 2020

@cherrymui Sorry, I tested old binary. Now it works fine. Thanks.

NOTE: On iOS device before running executable you should ldid -S <file> or Killed: 9 error appears.

@enty8080
Copy link
Author

@cherrymui Close issue?

@cherrymui
Copy link
Member

@enty8080 thanks for confirming! Yeah, we can close this. I'll see if I can make it better documented.

NOTE: On iOS device before running executable you should ldid -S or Killed: 9 error appears.

@eliasnaur do you think there is anything actionable for Go about this? Thanks.

@eliasnaur
Copy link
Contributor

@cherrymui, would you like to review https://go-review.googlesource.com/c/go/+/280313/? Porbably not for Go 1.16, but good for when GOOS=ios can produce working internally linked binaries.

@dmitshur
Copy link
Contributor

dmitshur commented Dec 28, 2020

Is it better/easier to document this somewhere, or update the gomobile build subcommand to perform this step and point people to use it?

As far as I can tell, the main purpose of gomobile build is to create functional iOS/Android applications. If it's no longer suitable for that purpose, perhaps we should consider making it clear that it's deprecated/non-functional and point to a better alternative (e.g., using the go command with additional documented steps).

@eliasnaur
Copy link
Contributor

eliasnaur commented Dec 28, 2020

@dmitshur gomobile can produce mobile applications with gomobile build, however that mode is very limited. It's primary use is for generating convenient bridges from Go to ObjC/Swift and Java with the gomobile bind mode.

So I think it's a mistake to consider gomobile the way to build for mobile. For example, Gio doesn't use gomobile at all.

EDIT: It is true that go build binaries are of limited use on mobile platforms. However, that's caused by the dominant use-cases on mobile (apps with GUIs) rather than a fundamental issue with the go tool.

@dmitshur
Copy link
Contributor

@eliasnaur Thanks. I've edited my comment above to clarify it's specifically about gomobile's build subcommand.

@cherrymui
Copy link
Member

@cherrymui, would you like to review https://go-review.googlesource.com/c/go/+/280313/? Porbably not for Go 1.16, but good for when GOOS=ios can produce working internally linked binaries.

Done. Yeah, it will be needed when we enable internal linking for ios.

@gopherbot
Copy link
Contributor

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
Contributor

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 <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
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 <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
@golang golang locked and limited conversation to collaborators Dec 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants