Join GitHub today
GitHub is home to over 36 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