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/compile: C.malloc fails with -d=checkptr #34968

Closed
mdempsky opened this issue Oct 17, 2019 · 3 comments
Closed

cmd/compile: C.malloc fails with -d=checkptr #34968

mdempsky opened this issue Oct 17, 2019 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

$ cat malloc.go
package main

// #include <stdlib.h>
import "C"

func main() {
	println(C.malloc(1000))
}
$ go run -gcflags=all=-d=checkptr malloc.go
fatal error: runtime: C malloc failed

goroutine 1 [running]:
runtime.throw(0x47aea6, 0x18)
	/usr/local/google/home/mdempsky/wd/go/src/runtime/panic.go:774 +0x72 fp=0xc000082708 sp=0xc0000826d8 pc=0x426122
main._cgo_cmalloc(0x3e8, 0x0)
	_cgo_gotypes.go:55 +0x91 fp=0xc000082738 sp=0xc000082708 pc=0x4576a1
main._Cfunc__CMalloc(...)
	_cgo_gotypes.go:40
main.main()
	/tmp/malloc.go:7 +0x2a fp=0xc000082760 sp=0xc000082738 pc=0x4576da
...
@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 17, 2019
@mdempsky mdempsky added this to the Go1.14 milestone Oct 17, 2019
@mdempsky mdempsky self-assigned this Oct 17, 2019
@mdempsky
Copy link
Member Author

Looks like checkptr instrumentation needs to be skipped for //go:cgo_unsafe_args functions.

@mdempsky
Copy link
Member Author

mdempsky commented Oct 17, 2019

Ah, it's because of CL 201781.

cgo depends on the ability to take the address of its parameters on the stack, and know that they'll all be contiguous there. But CL 201781 caused them to start being heap allocated because of the unsafe.Pointer(&p0) conversion.

Easy fix is to make //go:cgo_unsafe_args imply //go:nocheckptr so that this behavior is disabled.

@gopherbot
Copy link

Change https://golang.org/cl/201823 mentions this issue: cmd/compile: disable checkptr for //go:cgo_unsafe_args functions

@golang golang locked and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants