Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/link: put toolchain version in binary #13507
It would be nice to have a robust mechanism to tell what version of Go built a particular binary.
See go-nuts thread: https://groups.google.com/forum/#!topic/golang-nuts/XIDDj75ngMc
If the binary happens to call runtime.Version, then the version of Go is stored in runtime.buildVersion. If it doesn't call runtime.Version, runtime.buildVersion is dead-symbol eliminated.
We could teach cmd/link not to remove this symbol even if it is dead. Probably better is to just reference runtime.buildVersion from some always-used code (schedinit?). That way it will always be available in the binary, easily extracted with gdb.
@randall77 i'd like to see this as well. A few years ago I suggested (cannot find the issue # anymore) that runtime.Version be printed in panic output. Doing this would solve the problem of keeping runtime.buildVersion alive, and also avoid having to much about with gdb to find the version string.
we already have https://golang.org/cl/117040043
It's now called runtime/internal/sys.BuildVersion
(gdb) p 'runtime/internal/sys.BuildVersion'
The variable will never be eliminated due to its
Go 1.6 is the first version that the string is moved to
…sion So that there is a uniformed way to retrieve Go version from a Go binary, starting from Go 1.4 (see https://golang.org/cl/117040043) Updates #13507. Change-Id: Iaa2b14fca2d8c4d883d3824e2efc82b3e6fe2624 Reviewed-on: https://go-review.googlesource.com/17459 Reviewed-by: Keith Randall <email@example.com>