go: MacOS M1 can not run binary with go build, CODE SIGNING

Go version

go version go1.21.4 darwin/arm64

Reproducibility

  • Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tt/Library/Caches/go-build'
GOENV='/Users/tt/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tt/workspace/code/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tt/workspace/code/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/Users/tt/workspace/tools/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tt/workspace/tools/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/rq/424y01rs27982pm0_238_t180000gn/T/go-build2771029319=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go build to create binary, then program can not work by CODE SIGNING

image

image

but if I use go run xxx, this can work sucessfully.

What did you expect to see?

What did you see instead?

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Can you please try:

rm gotraceui
gotip build ./cmd/gotraceui
./gotraceui

Sometimes the signing/blessing bits get confused, especially if a file has been replaced in-place. Such as what happened to me in #56599. Explicitly rm’ing it helps reset things. That could also explain why gotip run works.

sounds like the solution is to use the latest release. for future bug report, we’d appreciate if the reported versions in the initial report reflected those that had the issue.

The go versions I have used on my computer are 1.18 and 1.20, and the most recent one I have used is 1.20.

For a simple hello world program, go 1.21 can compile and run go build normally. And I also discovered today that if I add -ldflags -w after go build, the previous program can also be run using go 1.21.

go build -ldflags -w -o xxx .
./xxx

@Nasfame