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

runtime: cgoCheckPointer fatal error: can't happen #70016

Closed
004helix opened this issue Oct 23, 2024 · 4 comments
Closed

runtime: cgoCheckPointer fatal error: can't happen #70016

004helix opened this issue Oct 23, 2024 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@004helix
Copy link

Go version

go version go1.23.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.23'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.23/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/user/git/vsis_bridge/src/bridge/go.mod'
GOWORK='/home/user/git/vsis_bridge/src/bridge/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1230936848=/tmp/go-build -gno-record-gcc-switches'

What did you do?

main.go

package main

// void test(void *a) {}
import "C"
import "unsafe"

func errBufPtr(buf *[256]byte) unsafe.Pointer {
	return unsafe.Pointer(&buf[0])
}

func main() {
	buf := new([256]byte)

	// run ok
	C.test(errBufPtr(buf))

	// panic: fatal error: can't happen
	C.test(unsafe.Pointer(&buf[0]))
}

What did you see happen?

$ go run main.go

fatal error: can't happen

goroutine 1 gp=0xc0000061c0 m=0 mp=0x4fbe40 [running]:
runtime.throw({0x47efcd?, 0x4fbe40?})
        /usr/local/go1.23/src/runtime/panic.go:1067 +0x48 fp=0xc000080ea8 sp=0xc000080e78 pc=0x460048
runtime.cgoCheckPointer({0x4718a0, 0xc00010e200}, {0x470a20, 0xc00010e200})
        /usr/local/go1.23/src/runtime/cgocall.go:567 +0x185 fp=0xc000080ef0 sp=0xc000080ea8 pc=0x45d6a5
main.main.func2(0x4f9b20?)
        /home/user/tmp/main.go:18 +0x2e fp=0xc000080f28 sp=0xc000080ef0 pc=0x46aa6e
main.main()
        /home/user/tmp/main.go:18 +0x33 fp=0xc000080f50 sp=0xc000080f28 pc=0x46aa13
runtime.main()
        /usr/local/go1.23/src/runtime/proc.go:272 +0x28b fp=0xc000080fe0 sp=0xc000080f50 pc=0x43370b
runtime.goexit({})
        /usr/local/go1.23/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000080fe8 sp=0xc000080fe0 pc=0x4664a1

goroutine 2 gp=0xc000006c40 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go1.23/src/runtime/proc.go:424 +0xce fp=0xc000068fa8 sp=0xc000068f88 pc=0x46012e
runtime.goparkunlock(...)
        /usr/local/go1.23/src/runtime/proc.go:430
runtime.forcegchelper()
        /usr/local/go1.23/src/runtime/proc.go:337 +0xb3 fp=0xc000068fe0 sp=0xc000068fa8 pc=0x433a53
runtime.goexit({})
        /usr/local/go1.23/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000068fe8 sp=0xc000068fe0 pc=0x4664a1
created by runtime.init.7 in goroutine 1
        /usr/local/go1.23/src/runtime/proc.go:325 +0x1a

goroutine 3 gp=0xc000007180 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go1.23/src/runtime/proc.go:424 +0xce fp=0xc000069780 sp=0xc000069760 pc=0x46012e
runtime.goparkunlock(...)
        /usr/local/go1.23/src/runtime/proc.go:430
runtime.bgsweep(0xc00001e200)
        /usr/local/go1.23/src/runtime/mgcsweep.go:277 +0x94 fp=0xc0000697c8 sp=0xc000069780 pc=0x41fa34
runtime.gcenable.gowrap1()
        /usr/local/go1.23/src/runtime/mgc.go:203 +0x25 fp=0xc0000697e0 sp=0xc0000697c8 pc=0x4143c5
runtime.goexit({})
        /usr/local/go1.23/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc0000697e8 sp=0xc0000697e0 pc=0x4664a1
created by runtime.gcenable in goroutine 1
        /usr/local/go1.23/src/runtime/mgc.go:203 +0x66

goroutine 4 gp=0xc000007340 m=nil [GC scavenge wait]:
runtime.gopark(0xc00001e200?, 0x49bc20?, 0x1?, 0x0?, 0xc000007340?)
        /usr/local/go1.23/src/runtime/proc.go:424 +0xce fp=0xc000069f78 sp=0xc000069f58 pc=0x46012e
runtime.goparkunlock(...)
        /usr/local/go1.23/src/runtime/proc.go:430
runtime.(*scavengerState).park(0x4fb0a0)
        /usr/local/go1.23/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000069fa8 sp=0xc000069f78 pc=0x41d469
runtime.bgscavenge(0xc00001e200)
        /usr/local/go1.23/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000069fc8 sp=0xc000069fa8 pc=0x41d9dc
runtime.gcenable.gowrap2()
        /usr/local/go1.23/src/runtime/mgc.go:204 +0x25 fp=0xc000069fe0 sp=0xc000069fc8 pc=0x414365
runtime.goexit({})
        /usr/local/go1.23/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000069fe8 sp=0xc000069fe0 pc=0x4664a1
created by runtime.gcenable in goroutine 1
        /usr/local/go1.23/src/runtime/mgc.go:204 +0xa5
exit status 2

What did you expect to see?

run without error

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 23, 2024
@randall77
Copy link
Contributor

I can reproduce at tip on Darwin.

@ianlancetaylor The runtime is not expecting a *[256]byte typed second argument to cgoCheckPointer.

@ianlancetaylor
Copy link
Member

Thanks for providing a simple standalone test case.

Sent https://go.dev/cl/621576 to fix this.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621576 mentions this issue: runtime: support cgo index into pointer-to-array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

5 participants