[ERROR] SIGSEGV: segmentation violation when running zrok on M5 Mac

Summary

Pre-built zrok binaries (I’ve tried both v1.x and v2.0.2) crash with a SIGSEGV during package initialization on my M5 Mac. They work on my M1 Mac.

Steps to reproduce

# Download v2.0.2 darwin_arm64 tarball from releases page
tar xzf zrok_2.0.2_darwin_arm64.tar.gz
sudo mv zrok2 /usr/local/bin/
sudo chmod +x /usr/local/bin/zrok2
xattr -d com.apple.quarantine /usr/local/bin/zrok2 2>/dev/null || true
zrok2 version

On an M1 Mac, the output of these steps is the “zrok v2.0.2’ ASCII art and version number.

On an M5 Mac, the output of these steps is...

SIGSEGV: segmentation violation
PC=0x1853531a8 m=0 sigcode=2 addr=0x0
signal arrived during cgo execution

goroutine 1 gp=0x272ad09f61e0 m=0 mp=0x10630cf00 [syscall, locked to thread]:
runtime.cgocall(0x1029f9b50, 0x272ad0adfe08)
	/Users/runner/hostedtoolcache/go/1.26.2/x64/src/runtime/cgocall.go:167 +0x44
github.com/shoenig/go-m1cpu._Cfunc_initialize()
	_cgo_gotypes.go:138 +0x2c
github.com/shoenig/go-m1cpu.init.0()
	/Users/runner/go/pkg/mod/github.com/shoenig/go-m1cpu@v0.1.6/cpu.go:148 +0x1c
runtime.doInit1(0x1061795c0)

/Users/runner/hostedtoolcache/go/1.26.2/x64/src/runtime/proc.go:8103 +0xc4
runtime.main()
	
/Users/runner/hostedtoolcache/go/1.26.2/x64/src/runtime/proc.go:258 +0x244

Diagnosis

The crash is at package init time inside go-m1cpu's cgo initialize call, which uses sysctlbyname to query CPU feature flags. M5 likely returns values the library's pre-M5 version doesn't account for, causing a null pointer dereference on the C side.

This appears to be the same class of issue as a previously reported and resolved M5 init-time crash in the ziti CLI.