Skip to content

reflect: method ABI and value ABI do not align #46696

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

Closed
reusee opened this issue Jun 11, 2021 · 5 comments
Closed

reflect: method ABI and value ABI do not align #46696

reusee opened this issue Jun 11, 2021 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@reusee
Copy link

reusee commented Jun 11, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17beta1 windows/amd64

Does this issue reproduce with the latest release?

No

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\reus\AppData\Local\go-build
set GOENV=C:\Users\reus\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\reus\go\pkg\mod
set GONOPROXY=github.com/reusee/*
set GONOSUMDB=github.com/reusee/*
set GOOS=windows
set GOPATH=C:\Users\reus\go
set GOPRIVATE=github.com/reusee/*
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\reus\sdk\go1.17beta1
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\reus\sdk\go1.17beta1\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17beta1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\reus\AppData\Local\Temp\go-build1901699100=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version go1.17beta1 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.17beta1

What did you do?

run


package main

import (
        "reflect"
)

type Foo struct{}

func (_ Foo) Foo(
        _ Bar,
        _ Bar,
        _ Baz,
        _ Baz,
        _ Baz,
        _ Bar,
        _ Qux,
) {
}

type Bar interface{}

type Baz func()

type Qux int

func main() {
        f := reflect.ValueOf(Foo{}).MethodByName("Foo").Interface()
        reflect.ValueOf(f).Call([]reflect.Value{
                reflect.ValueOf(Bar(42)),
                reflect.ValueOf(Bar(42)),
                reflect.ValueOf(Baz(nil)),
                reflect.ValueOf(Baz(nil)),
                reflect.ValueOf(Baz(nil)),
                reflect.ValueOf(Bar(42)),
                reflect.ValueOf(Qux(0)),
        })
}

What did you expect to see?

No panic

What did you see instead?

panic: method ABI and value ABI do not align                                                                                                                                                                                                                              goroutine 1 [running]:
reflect.callMethod(0xc000060040, 0xc00007d640, 0xc00007d518, 0xc00007d520)
        C:/Users/reus/sdk/go1.17beta1/src/reflect/value.go:969 +0x894
reflect.Value.call({0x6b18e0, 0xc000060040, 0x48}, {0x6bd1ee, 0x4}, {0xc00007dec8, 0x7, 0x6b18e0})
        C:/Users/reus/sdk/go1.17beta1/src/reflect/value.go:543 +0x814
reflect.Value.Call({0x6b18e0, 0xc000060040, 0x60}, {0xc00007dec8, 0x7, 0x7})
        C:/Users/reus/sdk/go1.17beta1/src/reflect/value.go:339 +0xc5
main.main()
        C:/Users/reus/a.go:30 +0x885
exit status 2
@ianlancetaylor
Copy link
Member

This panics in 1.17 but runs without error in earlier releases, so marking as a release blocker.

CC @mknyszek

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jun 11, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.17 milestone Jun 11, 2021
@mknyszek mknyszek self-assigned this Jun 11, 2021
@mknyszek
Copy link
Contributor

Thanks for the small reproducer. Looking into it.

@mknyszek
Copy link
Contributor

Slightly smaller reproducer:

package main

import (
	"fmt"
	"reflect"
)

type Foo struct{}

func (_ Foo) Foo(
	_ Bar,
	_ Bar,
	_ Baz,
	_ Baz,
	_ Baz,
	_ Bar,
	z Qux,
) int {
	return int(z)
}

type Bar interface{}

type Baz func()

type Qux int

func main() {
	f := reflect.ValueOf(Foo{}).MethodByName("Foo").Interface().(func(Bar, Bar, Baz, Baz, Baz, Bar, Qux) int)
	fmt.Println(f(Bar(42), Bar(42), Baz(nil), Baz(nil), Baz(nil), Bar(42), Qux(0)))
}

The failure is in the method value call, not the latter reflect call.

@mknyszek
Copy link
Contributor

I see the problem. In the "value" ABI the Qux-typed argument is stack-allocated, but in the "method" ABI, the argument before it (which is 16 bytes together) ends up on the stack, leaving a register free for the Qux-typed argument. callMethod erroneously assumes that this case can't happen.

Fix incoming.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/327089 mentions this issue: reflect: handle stack-to-register translation in callMethod

@mknyszek mknyszek added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 11, 2021
@golang golang locked and limited conversation to collaborators Jun 12, 2022
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

4 participants