-
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
proposal: cmd/link/internal/ld: Add custom data to "go:buildinfo" section or add custom sections #69525
Comments
Related Issues and Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
What is the goal? Adding a new custom section and adding additional data to the .go.buildinfo section sound like two different things. What kind of data do you want to add? Who exactly is going to retrieve that data? |
Data like binary-name, build-id, vcs-revision, build-context, etc.
Our internal tools that read binaries during their lifecycle.
Yes and if we add data to ".go.buildinfo" we also need to integrate our tools with it. |
Note that on Linux systems and other ELF-based systems you can add sections to a binary yourself using |
That's a good option, but I suspect we need something similar for MacOS/Windows. I'll try to understand if we really need it. |
It seems like |
Thanks for following up. |
Proposal Details
I work on go-rules for Buck2 and miss an option to add BuildInfo information that can be retrieved from a go binary without executing it with tools like
readelf
,go version
or similar.Bazel have a similar request from its users.
I'm happy to do a PR in Go 😀
Implementation ideas
1. Re-use "go:buildinfo" section
Buck/Bazel can add information the same way as
go build
does by supplying-importcfg
withmodinfo
section.Then this data can be accessed via
readelf
/etc,go version
ordebug/buildinfo.BuildInfo.Settings
field.The
BuildSetting
is a key-value structure and can be used for Buck/Bazel data or user provided data.This doesn't require any changes in Golang project code, just confirmation from you that we can "rely" on this behaviour of
cmd/ld
anddebug/buildinfo
.Alternatively
cmd/ld
can have a flag like-buildsetting key:value
to enable us (andgo build
users via-ldflags
option) to add custom data to this structure.2. Add custom sections
Add a new flag
-section name:value
(or-section name:value_filepath
) tocmd/ld
to enable linker to put arbitrary data into binaries.In this case a user can define its of format for this data but also will need to implement their own tools to read data.
The text was updated successfully, but these errors were encountered: