Repository navigation
fix(build): stamp the GNU build-ID with the release commit SHA (#651) - #652
Merged
Merged
Conversation
…ommit SHA rules_go links every Go binary with `-buildid=redacted`, and since Go 1.24 the Go linker derives `.note.gnu.build-id` from that constant by default (`-B gobuildid`). A constant input yields a constant note, so every aether Go binary ever built carries the same GNU build-ID — 498919aff001d8366249403a2544fba2d833084f — regardless of what code is in it. The eBPF profiling pipeline joins samples to symbols solely by build-ID, so a symbol upload for release N silently served wrong offsets for release N+1 (#651): misattributed frames, no error. rules_go does not stamp-expand `gc_linkopts`, so `-B 0x<sha>` cannot be fed to the linker from the workspace status. Instead //tools/buildid rewrites the note after the link: its descriptor is exactly 20 bytes, the width of a git commit SHA-1, so the release commit drops in without moving a single other byte. - bazel/workspace_status.sh: add STABLE_GIT_COMMIT (stable, so it is cache-key material and the stamping action re-runs exactly when the commit changes). - tools/buildid: the ELF note patcher plus `stamped_build_id` (stamp) and `build_id_check` (verify) rules, gated on a `--stamp` config_setting. - bazel/img/go_multi_arch_image.bzl: every ELF entering an image — the entry binary and every extra layer file, i.e. the CNI plugin too — goes through `stamped_build_id`. `--nostamp` builds get a byte-identical copy, so dev and PR-CI behaviour is unchanged. - //tools/buildid:release_build_ids is the acceptance guard: it fails the build if a released binary has no build-ID note, or (under --stamp) if the note is not the release commit. Built by `//...` and re-stated in publish.yaml. - Makefile: --stamp on the push targets, plus `make check-build-id`. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…mmit SHA The custom Envoy currently takes whatever build-ID the hermetic LLVM toolchain defaults to (a 16-byte md5 uuid). It is unique per link, so it does not have the agent's collision problem — but it says nothing about which commit produced the binary, so a symbol upload cannot be keyed to a release, and it is 16 bytes where every stock upstream Envoy in the fleet carries a 20-byte sha1 equal to its source SHA. `envoy_cc_binary(stamped = True)` is Envoy's own mechanism for exactly this: it links with `-Wl,@$(location @envoy//bazel:gnu_build_id.ldscript)`, a generated response file holding `--build-id=0x<BUILD_SCM_REVISION>`. Our //bazel/get_workspace_status already emits BUILD_SCM_REVISION as `git rev-parse HEAD`, so the binary's build-ID becomes this repo's release commit — the same convention upstream Envoy releases use, and the same value the Go binaries now carry (#651). - //integration:build_id_test asserts the linked binary's .note.gnu.build-id equals the id the linker was handed. It reads the ELF note with od+awk, so it needs no binutils on the runner or the RBE executor, and it costs no extra compile (//:envoy is already built for //:image_test). - proxy-release.yml verifies, BEFORE the push, that the ldscript the linker consumed says --build-id=0x<github.sha>; composed with the test above that pins the published binary's build-ID to the release commit. Only the one-line ldscript is fetched locally — the 150 MB binary stays on the executor. This also supersedes the "pin --build-id=sha1 in proxy/.bazelrc" follow-up from the symbolization plan: an explicitly stamped id is strictly more useful than a content hash. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo
added a commit
that referenced
this pull request
Sep 1, 2026
…ased binary is unique (#653) (#654) * fix(build): derive each Go binary's GNU build-ID from its own content (#653) #652 stamped the note with the release commit SHA, which made every binary produced by a commit share one build-ID — seven released ELFs, one ID. Pyroscope keys symbol lookup solely by build-ID, so uploading debuginfo for one of them would silently resolve all seven against it. Symbol upload has been blocked on this. A GNU build-ID identifies a linked object, not a source revision. The note now holds the binary's own content hash: build_id = sha1(image bytes, with the 20-byte descriptor field zeroed) Zeroing the descriptor before hashing is what makes the value well defined — it is the field the hash is about to overwrite — and it makes writing the ID idempotent, which is in turn what lets the guard recompute and check it. The descriptor is exactly a sha1 wide, so it is patched in place. The stable-status dependency is gone: a content hash needs no workspace status, so ctx.info_file, the --stamp config_setting, stamp_select() and the STABLE_GIT_COMMIT variable are all removed and the rewrite is unconditional. Dev and PR-CI builds now get correct, unique IDs instead of the rules_go constant, and the action's cache key is just (input binary, tool) — a new commit no longer invalidates all seven rewrites. --stamp keeps doing what it does for charts and x_defs; it just has nothing to do with build-IDs any more. //tools/buildid:release_build_ids is inverted accordingly. It asserted that each ID equals the stamp — precisely the condition that guaranteed the collision. It now asserts, over the six released Go ELFs, that every note is present, equals the sha1 recomputed from that binary's own bytes (self-verification), and is shared with no other binary. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr * fix(proxy): give the custom Envoy an lld content-hash build-ID (#653) envoy_cc_binary(stamped = True) links with --build-id=0x<BUILD_SCM_REVISION>, i.e. the source commit — the same shape that made all seven released aether binaries share one GNU build-ID (#653). Upstream gets away with it because they ship one binary per commit. Replace it with --build-id=sha1, lld's own content hash of the linked output: unique by construction, reproducible for identical inputs, and impossible to collide with the six Go binaries. It goes on the command line via --linkopt in proxy/.bazelrc rather than as `linkopts` on //:envoy, because envoy_cc_binary does `if not linkopts: linkopts = _envoy_linkopts()` — passing target linkopts would silently drop Envoy's own defaults (-pthread, -lrt, -ldl, -z relro/now, --hash-style=gnu, -pie, -Wl,-E). envoy.bazelrc passes -fuse-ld=lld the same way. The hermetic toolchain already supplies -Wl,--build-id=md5 earlier on the link line; lld honours the last --build-id, so ours wins and widens the note from 16 to the conventional 20 bytes. - //integration:build_id_test no longer compares against the ldscript (gone). It asserts the shipped Envoy has a .note.gnu.build-id, that the descriptor is exactly 20 bytes — the sha1 shape, which the toolchain's md5 (16) and `fast` (8) cannot produce — and that it is not all-zero. It deliberately does not recompute the digest: lld's sha1 build-ID is a tree hash over its output buffer, an internal linker detail rather than a published function of the file. - proxy-release.yml replaces the ldscript grep with an analysis-only `bazel aquery 'mnemonic("CppLink", //:envoy)'` assertion that the LAST --build-id on the link command line is --build-id=sha1. Composed with the test above that pins the published binary's note to lld's content hash, at no extra compile cost. Validated structurally (no full Envoy compile): aquery shows '-Wl,--build-id=sha1' after the toolchain's md5, with Envoy's own link defaults intact and gnu_build_id.ldscript gone. lld 18.1.8 semantics — 20-byte note, last flag wins, reproducible, distinct per program — confirmed against the hermetic toolchain, and check_build_id.sh was exercised against real sha1/md5/fast/no-id /zero-id/non-ELF inputs. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr --------- Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #651.
Why stamp (rather than "make it a content hash")
The issue's desired end state was
--build-id=sha1(content hash). Per explicit direction this lands the stronger form instead: the build-ID is the release commit SHA.envoy_cc_binary(stamped = True)).Mechanism
Go binaries (
//tools/buildid). rules_go links with-buildid=redacted, and since Go 1.24 the Go linker derives.note.gnu.build-idfrom that constant by default (-B gobuildid) — a constant input, hence the constant498919af…note on every binary the repo has ever produced. rules_go does not stamp-expandgc_linkopts, so-B 0x<sha>cannot be fed to the linker from the workspace status. So a small Starlark rule rewrites the note after the link:bazel/workspace_status.shgainsSTABLE_GIT_COMMIT(stable, so it is cache-key material — the volatileGIT_COMMITstays for rules_img tags).stamped_build_id(tools/buildid/defs.bzl) runs a stdlib-only Go tool that parses the ELF section header table, locates the.note.gnu.build-iddescriptor and overwrites its 20 bytes with the commit. Nothing else in the image moves — verified byte-for-byte in a unit test.ctx.info_file(stable-status.txt), notctx.version_file(that one is volatile and would let a stale build-ID survive a cache hit).bazel/img/go_multi_arch_image.bzlpipes every ELF that enters an image through it: the entrypoint binary and every extra layer file, so the CNI plugin at/opt/cni/bin/aether-cniis covered too.Proxy (
proxy/). Adopts Envoy's own mechanism:envoy_cc_binary(stamped = True)links with-Wl,@$(location @envoy//bazel:gnu_build_id.ldscript), a generated response file holding--build-id=0x<BUILD_SCM_REVISION>.proxy/bazel/get_workspace_statusalready emitsBUILD_SCM_REVISIONasgit rev-parse HEAD, so no new plumbing. This replaces the toolchain's implicit 16-byte md5 uuid. It also supersedes the "pin--build-id=sha1inproxy/.bazelrc" follow-up from the symbolization plan — an explicitly stamped id is strictly more useful than a content hash.Guarantees
--stampconfig_setting(the same one rules_go uses).--nostamp— every dev build and every PR-CI build — gets a byte-identical copy of the plain binary;bazel runandbazel testare unchanged. The tool also copies unchanged when the status has no resolvable commit or the input isn't an ELF at all.ctx.info_fileis precisely the input designed for this: only the stamping action is invalidated by a commit change.CI guards
//tools/buildid:release_build_ids— a build-time check over the six binaries that ship in released images (agent, mesh-dns, cni-install, the CNI plugin, controller, registrar). It fails the build if any lacks a build-ID note or, under--stamp, if the note isn't the release commit. It's part ofbazel build //..., so bazel-diff picks it up on any PR that touches those binaries, andpublish.yamlre-states it under--stampand prints the per-binary report.//integration:build_id_test(proxy) — asserts the linked Envoy's.note.gnu.build-idequals the id the linker was handed. Reads the note withod+awkso it needs no binutils on the runner or the RBE executor, and costs no extra compile (//:envoyis already built for//:image_test).proxy-release.yml— before the push, asserts the ldscript the linker consumed says--build-id=0x<github.sha>. Composed with the test above, that pins the published binary to the release commit. Only the one-line ldscript is fetched locally; the ~150 MB binary stays on the executor.make check-build-idfor the same check locally.Validation
Go side — fully validated locally.
readelf -non a--stampbuild:Guarantee 1 across three successive commits on this branch —
aaae36d3…→06643598…→e84ad3b7…, each time equal toHEAD, while the unstamped binary stayed498919af….Extracted from the actual image layers (
cni-install, both ELFs):bazel test //...(unit + container-structure) green;--config=lintgreen; gazelle andmake formatclean.Proxy side — mechanism validated structurally, no full Envoy compile (that is a multi-hour build; deliberately not run):
bazel aquery 'mnemonic("CppLink", //:envoy)'inproxy/confirms the link action now carries-Wl,@bazel-out/k8-fastbuild/bin/external/envoy/bazel/gnu_build_id.ldscript, with the ldscript declared as an action input.bazel build @envoy//bazel:gnu_build_id.ldscriptproduces--build-id=0x<this repo's HEAD>— the genrule resolves against our workspace status, and it built on RBE, so the status files stage correctly on the executor.-Wl,@<that ldscript>yieldsBuild ID: <the commit>verbatim.//integration:build_id_testanalyzes cleanly (bazel cquery --output=build), and the$(rootpath …)→ runfiles-cwd contract it relies on was proven with a throwawaysh_testin the same workspace (since removed).check_build_id.shitself was exercised against real ELFs: match, mismatch, presence-only, ldscript-expected form, missing file, non-ELF, and the whole-file fallback path — all correct.Awaits the next real proxy build: the end-to-end assertion that the compiled Envoy's note equals the ldscript value. That is exactly what
//integration:build_id_testruns on the first proxy PR/release, so it is gated, not assumed.Operational note (Pyroscope)
After this lands, each release's binaries get fresh, distinct build-IDs — which is the point, and it changes the symbol-upload workflow:
498919af…was already deleted from Pyroscope (it would have served wrong offsets); nothing to clean up.mesh-dnsimage and thecniplugin are separate ELFs with their own build-IDs — upload them separately if their native frames matter.Not touched
No
charts/changes, so no chart version bump. The cluster was not touched.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr