Go version
go version go1.22.5 darwin/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/issue/Library/Caches/go-build'
GOENV='/Users/issue/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/issue/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/issue/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/issue/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-amd64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/issue/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-amd64/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/issue/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0f/c1bl7l1x6dv059bdrrrtpvm000w3mf/T/go-build2248375764=/tmp/go-build -gno-record-gcc-switches -fno-common'
What did you do?
Description
When building a c-archive using the command go build -buildmode=c-archive on Intel-based macOS 14.6 (version 23G80) with Xcode 15.4 (Build version 15F31d), the resulting archive file is invalid.
Reproduction Steps
go build -buildmode=c-archive -o hello.a golang.org/x/mobile/example/basic
- A file named
hello.a
is successfully created xcodebuild -create-xcframework -library hello.a -output hello.xcframework
xcodebuild
fails witherror: unable to find any architecture information in the binary at '/Users/issue/hello.a': Unknown header: 0x50000000
What did you see happen?
xcodebuild
complains that the hello.a
is not a valid binary.
lipo -info hello.a
output:Non-fat file: hello.a is architecture: x86_64
file hello.a
output:hello.a: current ar archive
hexdump -n80 -C hello.a
to show the first 80 bytes:00000000 21 3c 61 72 63 68 3e 0a 2f 20 20 20 20 20 20 20 |!<arch>./ | 00000010 20 20 20 20 20 20 20 20 30 20 20 20 20 20 20 20 | 0 | 00000020 20 20 20 20 30 20 20 20 20 20 30 20 20 20 20 20 | 0 0 | 00000030 30 20 20 20 20 20 20 20 32 34 30 30 20 20 20 20 |0 2400 | 00000040 20 20 60 0a 00 00 00 50 00 00 09 a4 00 00 09 a4 | `....P........|
What did you expect to see?
The go build
command should produce a valid c-archive so xcodebuild -create-xcframework -library hello.a -output hello.xcframework
could successfully creates the "hello.xcframework": xcframework successfully written out to: /Users/issue/hello.xcframework
.
lipo -info hello.a
output:Non-fat file: hello.a is architecture: x86_64
file hello.a
output:hello.a: current ar archive random library
hexdump -n80 -C hello.a
to show the first 80 bytes (compare these numbers with the ones above):00000000 21 3c 61 72 63 68 3e 0a 23 31 2f 32 30 20 20 20 |!<arch>.#1/20 | 00000010 20 20 20 20 20 20 20 20 31 37 32 32 35 33 38 34 | 17225384| 00000020 36 36 20 20 35 30 31 20 20 20 32 30 20 20 20 20 |66 501 20 | 00000030 31 30 30 36 34 34 20 20 32 37 32 34 20 20 20 20 |100644 2724 | 00000040 20 20 60 0a 5f 5f 2e 53 59 4d 44 45 46 20 53 4f | `.__.SYMDEF SO|
This issues appears to be a platform-specific issue related to Intel macOS 14.6, it is not observed on "Intel macOS 13" or "Apple Silicon macOS 14".
Comment From: gabyhelp
Related Issues and Documentation
- cmd/cgo: failed to run c-archive library built for iOS #41177
- cmd/link: wrong c-archive architecture using GNU binutils ar on macOS Mojave 10.14.1 #28796
- cgo -buildmode=c-archive out ar file not current ar archive random library at macOS #47546 (closed)
- CGO seems to force x86 on Apple Silicon #46724 (closed)
- x/mobile/cmd/gomobile: gomobile bind fails with Xcode 15 #63141 (closed)
- cmd/cgo: does not compile for iOS simulator arm64 #57442
- cmd/go: cross-compiling for Linux x86_64 with CGO -race enabled failed on macOS Mojave (Darwin) #30863 (closed)
- x/mobile: building for iOS Simulator, but linking in object file built for iOS, for architecture arm64. #45805
- cmd/cgo: building c-archive with function pointer works with Go 1.14, but not 1.15 and beyond #44648
- cmd/go: Go 1.8.x cannot build executables for darwin_arm and darwin_arm64 on macOS, but Go 1.7.x could #20456 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: jyyi1
Root cause found, I have GNU ar
installed (included in binutils
), after deleting that, it works.