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: compiler crash compiling call to runtime.memmove #30061

Closed
ianlancetaylor opened this issue Feb 1, 2019 · 2 comments
Closed

cmd/compile: compiler crash compiling call to runtime.memmove #30061

ianlancetaylor opened this issue Feb 1, 2019 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

The compiler seems to recognize calls to runtime.memmove specially, and crashes when compiling code that calls it.

package p

import "unsafe"

//go:linkname memmove runtime.memmove
func memmove(to, from unsafe.Pointer, n uintptr)

var V1, V2 int

func F() {
	memmove(unsafe.Pointer(&V1), unsafe.Pointer(&V2), unsafe.Sizeof(int(0)))
}
> go build ~/foo.go
# command-line-arguments
<autogenerated>:1: internal compiler error: Type.Elem UNSAFEPTR

goroutine 34 [running]:
runtime/debug.Stack(0xf81b00, 0xc00000e018, 0x0)
	/home/iant/go/src/runtime/debug/stack.go:24 +0x9d
cmd/compile/internal/gc.Fatalf(0xdd3a25, 0xc, 0xc0004fe030, 0x1, 0x1)
	/home/iant/go/src/cmd/compile/internal/gc/subr.go:190 +0x293
cmd/compile/internal/types.(*Type).Elem(0xc000065e60, 0xc000000815)
	/home/iant/go/src/cmd/compile/internal/types/type.go:796 +0xff
cmd/compile/internal/ssa.rewriteValuegeneric_OpStaticCall_0(0xc0003ad1b8, 0x0)
	/home/iant/go/src/cmd/compile/internal/ssa/rewritegeneric.go:27433 +0x634
cmd/compile/internal/ssa.rewriteValuegeneric(0xc0003ad1b8, 0x0)
	/home/iant/go/src/cmd/compile/internal/ssa/rewritegeneric.go:415 +0x20a5
cmd/compile/internal/ssa.applyRewrite(0xc0004f0000, 0xdf3d08, 0xdf3d70)
	/home/iant/go/src/cmd/compile/internal/ssa/rewrite.go:80 +0x35f
cmd/compile/internal/ssa.opt(0xc0004f0000)
	/home/iant/go/src/cmd/compile/internal/ssa/opt.go:9 +0x43
cmd/compile/internal/ssa.Compile(0xc0004f0000)
	/home/iant/go/src/cmd/compile/internal/ssa/compile.go:90 +0x46f
cmd/compile/internal/gc.buildssa(0xc0000ca420, 0x1, 0x0)
	/home/iant/go/src/cmd/compile/internal/gc/ssa.go:233 +0xbe9
cmd/compile/internal/gc.compileSSA(0xc0000ca420, 0x1)
	/home/iant/go/src/cmd/compile/internal/gc/pgen.go:299 +0x4d
cmd/compile/internal/gc.compileFunctions.func2(0xc0004aa6c0, 0xc0004b6120, 0x1)
	/home/iant/go/src/cmd/compile/internal/gc/pgen.go:364 +0x49
created by cmd/compile/internal/gc.compileFunctions
	/home/iant/go/src/cmd/compile/internal/gc/pgen.go:362 +0x129
@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Feb 1, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Feb 1, 2019
@randall77
Copy link
Contributor

The compiler is trying to find the element type of an unsafe pointer.
We're not expecting someone to linkname memmove like this...
Should be easy to fix, just disable the rule in this case (the rule converts memmove calls to direct load/store instructions).

@randall77 randall77 self-assigned this Feb 1, 2019
@gopherbot
Copy link

Change https://golang.org/cl/160826 mentions this issue: cmd/compile: fix crash when memmove argument is not the right type

nebulabox pushed a commit to nebulabox/go that referenced this issue Feb 18, 2019
Make sure the argument to memmove is of pointer type before we try to
get the element type.

This has been noticed for code that uses unsafe+linkname so it can
call runtime.memmove. Probably not the best thing to allow, but the
code is out there and we'd rather not break it unnecessarily.

Fixes golang#30061

Change-Id: I334a8453f2e293959fd742044c43fbe93f0b3d31
Reviewed-on: https://go-review.googlesource.com/c/160826
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
nebulabox pushed a commit to nebulabox/go that referenced this issue Feb 20, 2019
Make sure the argument to memmove is of pointer type before we try to
get the element type.

This has been noticed for code that uses unsafe+linkname so it can
call runtime.memmove. Probably not the best thing to allow, but the
code is out there and we'd rather not break it unnecessarily.

Fixes golang#30061

Change-Id: I334a8453f2e293959fd742044c43fbe93f0b3d31
Reviewed-on: https://go-review.googlesource.com/c/160826
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Feb 1, 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. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants