-
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
runtime/pprof: Go build ID is not recorded in pprof profiles, only GNU build ID #68652
Comments
I agree, we should be including a build-id in the profile for pure Go binaries.
I wonder if this would break any tools that expect a GNU build ID? Most cgo programs should have a GNU build ID, so the build ID present in profiles would change from those. That said, I'm not sure if any tools actually look at build ID in profiles. From your last paragraph, am I understanding correctly that you'd prefer we always generate a GNU build id, and use that instead of the Go build ID? We got close with https://go.dev/cl/511475, but IIRC there was some issue with convergence in toolchain binaries that prevented it from being default (cc @cherrymui may recall better?). |
I think that's what I would prefer. Otherwise this becomes a (number of profiling / debugging tools) x (number of languages) problem. For example, we know now that An alternative would be to teach all profilers and debuggers to compute their own build ID to become independent of any ELF notes, but that is also nuanced - e.g. Linux perf in system-wide mode can observe events in hundreds of files, computing a custom hash of a binary will have to either be partial (e.g. first N bytes of the binary) or have potentially high overhead since a full scan of hundreds of binaries can put some pressure on the system. Also, a custom build ID wouldn't be compatible with build ID in debuginfo packages which is often critical to symbolize system libraries, so a fallback to GNU build ID would have to exist in most profilers anyway. |
CC @golang/runtime |
That would be great. But even then I wonder whether runtime/pprof should still support the Go build ID since someone coudl turn off the GNU build ID generation. Though the priority of that support would be much lower than now. Personally I would prefer if Go would only support GNU build ID but I don't know why the Go build ID was added in the first place. Plus taking it away is probably impossible in practice now since users may depend on it. |
The Go build ID is introduced for the Go toolchain's own build cache and reproducibility. It wants a portable format that is not tied to ELF. And it also has multiple components, like an action ID and a content ID, and some flexibility as the Go toolchain evolves. So using ELF build ID for that purpose would be difficult. The Go build ID is not intended to be used by anything outside of the Go toolchain. Yeah, one could turn GNU build ID off, or overwrite it. Technically one could also turn off the Go build ID (the linker's |
I see. If the Go build ID is not intended to be used outside the Go toolchain then getting the GNU build ID enabled by default seems like the right path forward. And perhaps when that happens, this issue can simply be closed as WAI. |
Change https://go.dev/cl/618601 mentions this issue: |
Go version
1.22.5
Output of
go env
in your module/workspace:What did you do?
I'm using this self-profiling toy program:
When I build it with
go build main.go
, I can see that, as expected by default, this pure Go binary only has the Go build ID and not the GNU build ID:Unexpectedly, when I run this program, the recorded profile does not capture the build ID:
If I ask Go linker to generate the GNU build ID for the binary using the
-B gobuildid
linker flag added in #61469, then the profile records the build ID as expected:What did you see happen?
See above.
What did you expect to see?
This happens because src/runtime/pprof/elf.go only reads the GNU build ID, not the Go build ID. I would expect instead to see runtime/pprof record the Go build ID when it's present and fall back to the GNU build ID when the Go build ID is missing. This would be similar to the behavior of the
file
utility.A related issue is that as far as I know Linux perf has its own logic for extracting the build ID as well and it does not record the Go build ID either. I think we in general should be careful with introducing private extensions to recording build ID in the binary since this may have cascade effects on the compatibility of existing profiling and debugging toolchains. It would be good if everything would just record the build ID as the standard GNU build ID.
The text was updated successfully, but these errors were encountered: