-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/go: add compiler flags, relevant env vars to 'go version -m' output #35667
Comments
This could get arbitrarily complex. We already have the first two rows in the table, accessible using Generalizing to JSON will just make the binaries bigger and create more work for existing parsers, for very little benefit. Generalizing to arbitrary metadata similarly adds complexity with not much benefit. I think we should probably stop where we have stopped. |
Is there a way that apps could opt-in to this scheme? Perhaps by defining a const string (in arbitrary format) and then passing its name to a build flag to be sited at a known or locatable offset? |
@rsc - as you outlined, some of the data is already available with Tools (not necessarily implemented in Go) which operate on application meta information have to deal with all sorts of technologies. Performance monitoring tools and vulnerability scanners supervise production systems. This reasoning led us to propose JSON formatted build meta information. The very minor increase in binary size is in our view outweight by its extendability, standardization, and availability of proven parsers. But JSON format is in no terms a mandatory requirement. If size is a roadblock, it can be substituted with another, more lightweight format.
Thus, we think the proposal adds significant benefits to Go, by bringing it en par with other technologies. |
When you say "en par with other technologies" which technologies are you thinking of? If other languages are providing this kind of information we should consider doing what they do rather than inventing something new. Note that for specific purposes the linker's |
@ianlancetaylor [disclaimer - I am co-author of the proposal] To my knowledge - no standardized deployment mechanism or defined set of meta information that Go could directly re-use exists. We tried to compile a set of properties, that seemed reasonable for In shortcoming of a better mechanism, we did propose to follow the Different technologies use very divergent schemes and formats. Many technologies simply leverage from not being bound to a specific file format (like ELF or PE). Others, from being backed Node.js has package.json file, which defines a rich set of information (name, version, license, .Net manifest files contain a quite rich set of meta information (referenced assemblies, version, Java has a subset of the proposed information in its manifest file. |
OK, so to summarize, the proposal was to put the following in the binary in a new section:
The first two are already present in the binary and don't need to be duplicated. (They can be extracted by parsing the binary or by running That leaves compiler information (basically, the go command-line options). It seems like we could plausibly write that down too. I've wanted it at least once in the last month. That would just be a single new line in the existing format, not a whole new section. If we refocus this discussion to be adding go command command-line flags, does that address the initial request well enough? |
@rsc, thanks for the summary and considering the proposal.
JSON format would have mitigated these technical dependencies. As correctly stated, we do not have specific use cases for user defined data.
Would you consider to include environment variables (e.g. CGO_ENABLED) which impact the build process, too? |
Note that there is a parser today at https://rsc.io/goversion/version. We could move that somewhere in golang.org/x. Many programs will be just fine shelling out to Yes, the idea is that we'd add relevant go command line flags. We could look into relevant go environment variables too, but we don't want to break reproducible builds, so we shouldn't write down things like GOPATH, which might mention temporary directories. |
The compiler flags are already saved in the DW_AT_producer attribute in debug_info. |
@rsc, thanks for the parser reference and proposal to add JSON formatted output. Although we cannot use it directly for our use case, it can serve as a reference for our parser implementation. Moving the parser to |
I've retitled based on the discussion above. Based on the discussion this seems like a likely accept. @bradfitz is also filing a separate issue to discuss whether we should have version information from the current VCS working directory. |
No change in consensus, so accepted. |
Is this done now at head?
|
I think it is, someone should close this issue. |
This is a proposal to add extensive build meta information to Go binaries for various use cases like:
Currently it is hard to retrieve meta information from Go binaries - either information is missing completely or extraction requires extensive parsing of the binary file. The following table lists existing metadata entities and the mechanism required to extract the information.
runtime.buildVersion
(type string)runtime/debug.modinfo
(type string)This proposal is to provision extended build time meta information to Go binaries. Reading the information from binaries shall be trivial.
Go already provisions go.buildid hash string into Go binaries and provides tools to read that information from the binary.
go.buildid is provisioned in PT_NOTE segment for ELF based systems (see note sections (2-4)). In case of executable file formats which do not define appropriate mechanisms for enclosing meta information (like e.g. Windows PE),
go.buildid
is added as non-instruction bytes at the very beginning of the.text
segment.Thus, a portable mechanism for meta information provisioning is already in place and can be re-used for build meta information. The proposed name for build meta information is
go.metadata
and it should be added after the existinggo.buildid
entry.go.metadata
formatThe proposed format for
go.metadata
is JSON. JSON is extensible and Go has first class JSON parsing support. The following sample shows what meta information of a simple Go binary may look like:go.metadata
shall validate against the JSON schema attached to this issue.The text was updated successfully, but these errors were encountered: