Skip to content

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

Closed

Description

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

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Oct 17, 2019
  2. added this to the Go1.14 milestone on Oct 17, 2019
  3. self-assigned this
    on Oct 17, 2019
  4. mdempsky commented on Oct 17, 2019

    @mdempsky
    ContributorAuthor

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

  5. mdempsky commented on Oct 17, 2019

    @mdempsky
    ContributorAuthor

    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.

  6. gopherbot commented on Oct 17, 2019

    @gopherbot
    Contributor

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

  7. locked and limited conversation to collaborators on Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions