cmd/go: value of -buildmode in buildinfo can differ from what is used in build ID
#63,559 opened on Oct 15, 2023
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
What version of Go are you using (go version)?
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
What did you do?
Built two binaries from identical source code, passing -buildmode=default to the first and -buildmode=exe to the second.
What did you expect to see?
Both binaries should be identical and have the same hash.
What did you see instead?
The binaries hashes differed, though using xbindiff showed that the build ID was the only difference between them. It seems that the buildmode that is actually used is included in binaries build information (exe in both cases), but the exact value of -buildmode as passed to go build is used when creating the build ID. To make reproducing binaries easier I think the same buildmode value that is used in the embedded build information should be used when creating the build ID.
Currently it can be very difficult to tell what value of -buildmode was passed at build time when you only have a Go binary and no information on its build process. This change would make it easier to reproduce Go binaries using the embedded build information as a guide.