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

cmd/cgo: cgo build fails with panic building trivial code on M1 Mac (darwin/arm64) #53193

Closed
SamJakob opened this issue Jun 2, 2022 · 4 comments

Comments

@SamJakob
Copy link

SamJakob commented Jun 2, 2022

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

$ go version
go version go1.18.3 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="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/samjakob/Library/Caches/go-build"
GOENV="/Users/samjakob/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=" -mod="
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/samjakob/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/samjakob/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.18.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/samjakob/GolandProjects/TestProject/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gd/xv3ph82d1w16g5hbmvwgvr9h0000gn/T/go-build1374085631=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Created a trivial project and attempted to build it on M1 Mac (darwin/arm64) with go build.
Please see here: https://github.com/SamJakob/go_test_project

What did you expect to see?

Successful build.

What did you see instead?

$ go build
# TestProject
panic: unexpected 32-bit segment

goroutine 1 [running]:
cmd/link/internal/ld.machoCombineDwarf(0x1024fbc88?, 0x140000a8050?, 0x1400008e000, {0x14000e440a0?, 0x1?}, {0x14001040000, 0x53})
        /usr/local/go/src/cmd/link/internal/ld/macho_combine_dwarf.go:218 +0x1024
cmd/link/internal/ld.(*Link).hostlink(0x14000158000)
        /usr/local/go/src/cmd/link/internal/ld/lib.go:1709 +0x4b9c
cmd/link/internal/ld.Main(_, {0x10, 0x20, 0x1, 0x1f, 0x1e, 0x7c00000, {0x10243950c, 0x14}, {0x10243cc69, ...}, ...})
        /usr/local/go/src/cmd/link/internal/ld/main.go:373 +0x143c
main.main()
        /usr/local/go/src/cmd/link/main.go:69 +0xc5c


@erifan
Copy link

erifan commented Jun 2, 2022

I downloaded your code but can't reproduce the issue on my M1 mac.

@SamJakob
Copy link
Author

SamJakob commented Jun 2, 2022

I downloaded your code but can't reproduce the issue on my M1 mac.

Oh weird... I figured it was probably a somewhat niche error because I couldn't find much for it on the internet but honestly not even sure how to go about fixing...

What is your OS version?

@erifan
Copy link

erifan commented Jun 2, 2022

What is your OS version?

20.6.0

@SamJakob
Copy link
Author

SamJakob commented Jun 2, 2022

Closing. Just tried this in another shell (bash) instead of my default (zsh) and it worked, so evidently I have some non-standard compiler or linker in my path.
Thank you!

EDIT: For completeness sake; it was a Homebrew version of LLVM that I had included in my PATH, removing this caused everything to work correctly.
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"

@SamJakob SamJakob closed this as completed Jun 2, 2022
@golang golang locked and limited conversation to collaborators Jun 2, 2023
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

3 participants