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: debug/buildinfo: export errNotGoExe #67845

Open
hdonnay opened this issue Jun 5, 2024 · 4 comments
Open

proposal: debug/buildinfo: export errNotGoExe #67845

hdonnay opened this issue Jun 5, 2024 · 4 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Proposal
Milestone

Comments

@hdonnay
Copy link

hdonnay commented Jun 5, 2024

Go version

go1.23-9b43bfbc51

Output of go env in your module/workspace:

N/A

What did you do?

Resorted to //go:linkname tricks to get at this value. (link)

What did you see happen?

N/A

What did you expect to see?

Without exporting buildinfo.errNotGoExe, a user must effectively re-implement the debug/buildinfo package to determine if an executable is a Go executable and if so, read data to hand to runtime/debug.ParseBuildInfo. If the user doesn't want to copy the logic that decodes the .go.buildinfo (or equivalent) section, the executable ends up needing to be parsed twice to check for the section and magic string.1 Additionally, a user would be unable to use the internal/saferio helper.

Returning an exported error (or an error that evaluates correctly to a sentinel error with errors.Is) allows a caller to distinguish between a file that should have valid build info (!errors.Is(err, buildinfo.errNotGoExe)) and a file that's not expected to (errors.Is(err, buildinfo.errNotGoExe)) when the process can't "know" that a-priori.

Footnotes

  1. Because sections may be compressed, something like a bitstring search over the file isn't a reliable rule-in/rule-out criteria. To look for a Go-specific section (like .go.buildinfo or .note.go.buildid in the case of ELF) requires parsing the binary and throwing that work away to have debug/buildinfo parse it again.

@mknyszek
Copy link
Contributor

mknyszek commented Jun 5, 2024

I'm not sure who the right owner of this is. I see mainly Go command people have edited this package, so I'm directing to y'all. Please feel free to update the issue if I'm wrong.

CC @matloob @samthanawalla

@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest Issues asking for a new feature that does not need a proposal. GoCommand cmd/go labels Jun 5, 2024
@mknyszek mknyszek added this to the Backlog milestone Jun 5, 2024
@matloob
Copy link
Contributor

matloob commented Jun 27, 2024

I'm not opposed to this. I think it would require going through the proposal process because it's an API change to the standard library

@matloob
Copy link
Contributor

matloob commented Jul 2, 2024

@hdonnay do you want to turn this into a proposal issue?

@hdonnay
Copy link
Author

hdonnay commented Jul 2, 2024

Yeah, I'll attempt it when I get some time.

@seankhliao seankhliao changed the title debug/buildinfo: export sentinel equivalent to errNotGoExe proposal: debug/buildinfo: export errNotGoExe Jul 2, 2024
@seankhliao seankhliao modified the milestones: Backlog, Proposal Jul 2, 2024
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Proposal
Projects
Status: Incoming
Development

No branches or pull requests

5 participants