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
Assignees
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Oct 17, 2019

$ 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 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

This comment has been minimized.

Copy link
Member Author

@mdempsky mdempsky commented Oct 17, 2019

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

@mdempsky

This comment has been minimized.

Copy link
Member Author

@mdempsky 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 17, 2019

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

@gopherbot gopherbot closed this in 8c6876e Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.