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

gccgo: reflect.Value.Call fails with struct with empty struct field #26335

Closed
ianlancetaylor opened this issue Jul 11, 2018 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

This test case crashes when compiled with gccgo. The parameter s is read from the wrong position on the stack. The problem is most likely that the empty struct field in large leads to a disagreement between the Go code and libffi.

package main

import (
	"fmt"
	"reflect"
)

type large struct {
	f1, f2, f3, f4 *byte
	empty struct{}
}

func F(str string, l large, s []string) {
	if len(s) != 1 || s[0] != "hi" {
		fmt.Printf("bad value for s: %v\n", s)
		panic("bad slice")
	}
}

func main() {
	params := []reflect.Value{
		reflect.ValueOf("str"),
		reflect.ValueOf(large{}),
		reflect.ValueOf([]string{"hi"}),
	}
	reflect.ValueOf(F).Call(params)
}
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 11, 2018
@ianlancetaylor ianlancetaylor added this to the Gccgo milestone Jul 11, 2018
@gopherbot
Copy link

Change https://golang.org/cl/123316 mentions this issue: test: add test case that failed with gccgo

@gopherbot
Copy link

Change https://golang.org/cl/123335 mentions this issue: runtime: skip zero-sized fields in structs when converting to FFI

gopherbot pushed a commit that referenced this issue Jul 11, 2018
Updates #26335

Change-Id: Ibfb1e232a0c66fa699842c8908ae5ff0f5d2177d
Reviewed-on: https://go-review.googlesource.com/123316
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
hubot pushed a commit to gcc-mirror/gcc that referenced this issue Jul 13, 2018
    
    The libffi library doesn't understand zero-sized objects.
    When we see a zero-sized field in a struct, just skip it when
    converting to the FFI data structures. There is no value to pass in
    any case, so not telling libffi about the field doesn't affect
    anything.
    
    The test case for this is https://golang.org/cl/123316.
    
    Fixes golang/go#26335
    
    Reviewed-on: https://go-review.googlesource.com/123335


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@262651 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Jul 13, 2019
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