-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version
)?
go version go1.11rc1 linux/amd64
Does this issue reproduce with the latest release?
Doesn't seem to happen in go 1.10, but it does occur in 1.11rc1.
What operating system and processor architecture are you using (go env
)?
Used docker run -it golang:stretch-rc
to grab a clean repro env.
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
What did you do?
The go compiler produces a non-deterministic small.a output when run on the following minimized test program:
package small
func A(arg interface{}) {
_ = arg.(interface{ Func() int32 })
_ = arg.(interface{ Func() int32 })
// two is sufficient for nondeterminism, but let's add more to make it more likely
_ = arg.(interface{ Func() int32 })
_ = arg.(interface{ Func() int32 })
_ = arg.(interface{ Func() int32 })
_ = arg.(interface{ Func() int32 })
_ = arg.(interface{ Func() int32 })
}
To demonstrate:
for i in {1..20}; do
go tool compile -p small -linkobj small.a small.go &&
sha1sum small.a
done | sort |uniq -c
What did you expect to see?
The go compiler produces the same output each time it is run, since it receives the same inputs.
The little script above should only see one hash from the 20 small.a
files.
What did you see instead?
The go compiler produces nondeterministic output
5 0429fb2b8ff3754684ba5aa6a686ddf97459c6e2 small.a
3 0c9eb51706182c0e3fc15d79b6f0b8be9648ef94 small.a
5 1d7d836a2294347da9c458c158459888902ac5c2 small.a
1 2b4600b551a9c60d717fe593e8cb4765bcdbf0ce small.a
1 429d2d81b645796682ca194287d45765c1703620 small.a
3 9b26abdd35e4094758423d392c69bf57e7a76bb3 small.a
2 ee0b1fb89dff9f5e26f33284e55e5826679e8f83 small.a
Notes
I did a fair amount of digging into the problem because it piqued my interest and have a patch that I believe fixes it. I'll upload that shortly.
The problem seems to be in the generated DWARF debug info containing a line number for the return variable "~r0" for the generated conversion function. It seems to non-deterministically be one of any of the lines that the conversion happens on.