Skip to content
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

Open
podtserkovskiy opened this issue Sep 18, 2024 · 5 comments
Labels
Milestone

Comments

@podtserkovskiy
Copy link
Contributor

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 with modinfo section.

Then this data can be accessed via readelf/etc, go version or debug/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 and debug/buildinfo.

Alternatively cmd/ld can have a flag like -buildsetting key:value to enable us (and go 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) to cmd/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.

@gopherbot gopherbot added this to the Proposal milestone Sep 18, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@ianlancetaylor
Copy link
Contributor

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?

@podtserkovskiy
Copy link
Contributor Author

What kind of data do you want to add?

Data like binary-name, build-id, vcs-revision, build-context, etc.

Who exactly is going to retrieve that data?

Our internal tools that read binaries during their lifecycle.

Adding a new custom section and adding additional data to the .go.buildinfo section sound like two different things.

Yes and if we add data to ".go.buildinfo" we also need to integrate our tools with it.
If we add a custom section we can read it without extra modifications in our tools the same way we read buildinfo added to C/C++/etc binaries.

@ianlancetaylor
Copy link
Contributor

Note that on Linux systems and other ELF-based systems you can add sections to a binary yourself using objcopy --add-section.

@podtserkovskiy
Copy link
Contributor Author

Note that on Linux systems and other ELF-based systems you can add sections to a binary yourself using objcopy --add-section.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants