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: zero padding rule in runtime.structToFFI is out of sync #55146

Closed
melonedo opened this issue Sep 19, 2022 · 2 comments
Closed

gccgo: zero padding rule in runtime.structToFFI is out of sync #55146

melonedo opened this issue Sep 19, 2022 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@melonedo
Copy link

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

$ go version
go version go1.18.2 linux/amd64

Does this issue reproduce with the latest release?

Yes, tested on GCC 12.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/melonedo/.cache/go-build"
GOENV="/home/melonedo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/melonedo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/melonedo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/melonedo/fuzzTest/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build557955963=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go run -compiler gccgo issue.go on code:

package main

import "fmt"
import "reflect"

type Empty struct {
}

type StillEmpty struct {
  x Empty
}

type LastBlankEmpty struct {
  a int64
  b int64
  _ Empty
}

//go:noinline
func check1(a StillEmpty, b int64) bool {
	return b == 1
}

//go:noinline
func check2(x LastBlankEmpty) bool {
	return x.a == 1 && x.b == 2
}

func main() {
  empty := StillEmpty{}
  r1 := check1(empty, 1)
  r2 := reflect.ValueOf(check1).Call([]reflect.Value{reflect.ValueOf(empty), reflect.ValueOf(int64(1))})[0].Interface().(bool)
  fmt.Println(r1, r2)
  x := LastBlankEmpty{a: 1, b: 2}
  r3 := check2(x)
  r4 := reflect.ValueOf(check2).Call([]reflect.Value{reflect.ValueOf(x)})[0].Interface().(bool)
  fmt.Println(r3, r4)
}

What did you expect to see?

true true
true true

What did you see instead?

true false
true false

A fix has been proposed at https://go-review.googlesource.com/c/gofrontend/+/431735.

@gopherbot gopherbot added this to the Gccgo milestone Sep 19, 2022
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 19, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/431735 mentions this issue: gofrontend: synchronize empty struct handling

gopherbot pushed a commit to golang/gofrontend that referenced this issue Sep 27, 2022
In GCCGO and gollvm, the logic for allocating one byte for the last field is:
1. the last field has zero size
2. the struct itself does not have zero size
3. the last field is not blank
this commit adds the last two conditions to runtime.structToFFI.

For golang/go#55146

Change-Id: Iabc3ee09e7f14fab037fd197a9658b099c419904
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/431735
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
nstester pushed a commit to nstester/gcc that referenced this issue Sep 27, 2022
In GCCGO and gollvm, the logic for allocating one byte for the last field is:
1. the last field has zero size
2. the struct itself does not have zero size
3. the last field is not blank
this commit adds the last two conditions to runtime.structToFFI.

For golang/go#55146

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/431735
@melonedo
Copy link
Author

Fixed, thanks!

@golang golang locked and limited conversation to collaborators Oct 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants