Repository navigation
fix(build): derive the GNU build-ID from binary content so every released binary is unique (#653) - #654
Merged
Conversation
…#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
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
This was referenced Sep 1, 2026
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 #653. Amends the mechanism #652 shipped.
The collision
#651/#652 fixed build-to-build build-ID constancy by stamping the note with the
release commit SHA. But a GNU build-ID identifies a linked object, not a source
revision, and one aether commit produces seven released ELFs — so all seven ended
up with one ID. Verified on the artifacts published from
4aabff2:agent@sha256:47fa37d8…4aabff27ace47e82c0df2e637e99e253442dc5a8mesh-dns@sha256:2e186f02…registrar@sha256:b3fc0d97…controller@sha256:47a3383b…cni-install@sha256:bee97fb5…/opt/cni/bin/aether-proxy:4aabff27…Pyroscope keys symbol lookup solely by build-ID, so uploading debuginfo for
any one of these would make the symbolizer resolve all seven against it — six of
them wrong, silently, with plausible-looking frames. Symbol upload has been
blocked on this.
Why a content hash, not a per-target-namespaced stamp
The issue's option 2 (
sha1(commit || target_label)) would also givedistinctness, but the content hash (option 1) wins on three counts:
ld --build-id=sha1computes natively and whatdebuginfod conventions assume. Both toolchains in this repo can produce it: the
proxy gets it straight from lld, the Go binaries from a 20-byte note rewrite
that hashes the same thing.
confirm the note belongs to that binary. A namespaced stamp is an assertion you
have to trust; a content hash is a proof. The CI guard exploits this directly.
to apply to a new target — it falls out of hashing different bytes.
Release traceability does not need the ELF note and does not live there: it lives
in the
--stampx_defs version information baked into the binaries and in theimage tags. The note is the symbolizer's key and nothing else.
Mechanism
Go binaries —
//tools/buildid. rules_go links with-buildid=redactedandGo ≥1.24 derives
.note.gnu.build-idfrom that constant, so the plaingo_binarystill carries498919aff001d8366249403a2544fba2d833084f. Thepost-link note rewrite from #652 stays; only the value changes:
Zeroing the descriptor is what makes the value well defined — it is the one field
the hash is about to overwrite, so excluding it removes the circular dependency
and makes writing the ID idempotent. The descriptor is exactly a SHA-1 wide,
so it is patched in place and no other byte of the image moves. All of that is
documented in the tool's package comment and covered by unit tests
(
TestContentBuildIDIsSHA1OfTheZeroedImage,…IsDeterministic,…IsIdempotent,…IsPairwiseDistinct,…ReplacesOnlyTheDescriptor).The stable-status dependency is dropped. A content hash needs no workspace
status, so
ctx.info_file, the--stampconfig_setting,stamp_select()andthe
STABLE_GIT_COMMITvariable #652 added are all gone, and the rewrite isunconditional. That is the cleaner end state, and strictly better than gating it:
constant, so what CI validates is what releases ship;
commit invalidated all seven stamping actions; now nothing invalidates unless
the binary itself changes.
--stampstill does what it always did for charts and x_defs; it simply nolonger has anything to do with build-IDs.
Proxy —
proxy/.envoy_cc_binary(stamped = True)is dropped (that isEnvoy's commit-SHA ldscript, i.e. exactly the #653 shape) in favour of
--build-id=sha1, lld's own content hash of the linked output.It is passed as
build --linkopt=-Wl,--build-id=sha1inproxy/.bazelrc, notas
linkoptson//:envoy:envoy_cc_binarydoesif not linkopts: linkopts = _envoy_linkopts(), so passing any target linkoptswould silently replace Envoy's defaults (
-pthread -lrt -ldl -Wl,-z,relro,-z,now --hash-style=gnu -pie -Wl,-E). A--linkoptcomposes instead of replacing —which is how
envoy.bazelrcitself passes-fuse-ld=lld. The hermetic toolchainalready supplies
-Wl,--build-id=md5earlier on the link line; lld honours thelast
--build-id, so ours wins and widens the note from 16 to the conventional20 bytes.
The four properties
outside the descriptor hash differently. Asserted directly by
//tools/buildid:release_build_idsover the six released Go ELFs, and by aunit test.
commit changes a binary's bytes, its ID moves. Honestly: a commit that leaves a
given binary byte-identical keeps that binary's ID — and that is correct and
desirable, not a regression. The previously uploaded symbols are still exactly
the right ones for those bytes, and re-uploading dedupes.
timestamps, no status files, no per-invocation state. Reproducible and
remote-cache friendly.
real IDs rather than a byte-identical copy of the constant-ID binary.
CI guards
//tools/buildid:release_build_ids(inverted from fix(build): stamp the GNU build-ID with the release commit SHA (#651) #652, which asserted eachID equals the stamp — precisely the condition that guaranteed the collision).
It now asserts, over the six released Go ELFs (agent, mesh-dns, cni-install, the
aether-cniplugin, controller, registrar): every note present and 20 bytes;every note equal to the SHA-1 recomputed from that binary's own content
(self-verification); and all notes pairwise distinct. It needs no
--stamp, soit holds in every configuration, is part of
bazel build //...(hencebazel-diff on PRs), and is re-stated by
publish.yaml.//integration:build_id_test(proxy) — was "equals the ldscript"; nowasserts the shipped Envoy carries a
.note.gnu.build-id, that its descriptor isexactly 20 bytes (the SHA-1 shape: the toolchain's md5 is 16,
fastis 8), andthat it is not all-zero. It deliberately does not recompute the digest: lld's
--build-id=sha1is a tree hash over its output buffer — an internal linkerdetail, not a published function of the file — so recomputing it in a shell test
would pin an lld implementation detail. (I confirmed that empirically against
the hermetic lld 18.1.8 before deciding.)
proxy-release.yml— the ldscript grep is replaced by an analysis-onlybazel aquery 'mnemonic("CppLink", //:envoy)'assertion that the last--build-idon the link command line is--build-id=sha1. Composed with thetest above, that pins the published binary's note to lld's content hash. No
extra compile; the ~150 MB binary never leaves the executor.
make check-build-idfor the same report locally.Validation
Go side — fully validated locally. Six released ELFs, one build,
readelf -n:Six binaries, six distinct IDs (the plain
go_binaryalongside them still reads498919af…). Self-verification recomputed independently of the tool (athrowaway Python script re-deriving
sha1(image with the descriptor zeroed)fromeach shipped file): all six match their note.
cni/internal/cmd/root.gomovedcni-installfrom629c246b…toe37d2e04…; reverting restored629c246b…exactly (which is also property 3).
--stampand--nostampbuilds both self-verify and are bothpairwise distinct. Interesting and correct: under
--stampthe four binariesthat embed x_defs version data get different IDs (their bytes differ), while
cni-installandaether-cni, which embed none, keep the identical ID. That isproperty 2's honest caveat, visible in miniature.
buildid setrun twice more over analready-written ELF produced byte-identical files and the same ID all three
times.
buildid verifyon twocopies of the same binary fails with
build-ID 629c246b… is shared by 2 binaries: ….bazel test //...green (89 tests).--config=cilint green.make gazelleandmake formatclean.Proxy side — validated structurally; no full Envoy compile (multi-hour;
deliberately not run):
bazel aquery 'mnemonic("CppLink", //:envoy)'shows'-Wl,--build-id=sha1'onthe link command line, after the toolchain's
'-Wl,--build-id=md5', withEnvoy's own defaults intact (
-Wl,-z,relro,-z,now,'-Wl,--hash-style=gnu',-pie) and thegnu_build_id.ldscriptgone. This is what proves both that theflag reaches the link and that dropping
stamped = Truedid not disturb therest of the link.
this workspace:
--build-id=sha1yields a 20-byte note; a later--build-id=sha1overrides an earlier
--build-id=md5and produces the identical id; relinkingidentical input reproduces the id; a different program gets a different id.
check_build_id.shwas exercised against real lld output for every branch:sha1(pass),md5(fails, "16-byte descriptor"),fast(fails, "8-byte"),no
--build-id(fails, "carries no .note.gnu.build-id"), an all-zero hexstringid (fails), a missing file, and a non-ELF.
--build-idordering assertion the release workflow runs was verifiedagainst the real aquery output.
Awaits the proxy CI leg: the end-to-end assertion on a compiled Envoy —
//integration:build_id_testplus the aquery check — which runs on the firstproxy PR/release build. It is gated, not assumed.
Operational note (Pyroscope)
After this lands, all seven binaries are individually uploadable — each one's
debuginfo resolves only its own samples.
4aabff2-era upload exists and none must ever be made. Wedeliberately withheld the
4aabff2artifacts precisely because of thiscollision; the earlier poisoned
498919af…upload was already deleted. Uploadinga
4aabff2-era binary now would install one symbol table for all seven ELFs.15e3b073…proxy upload predates the stamp and is unaffected;the proxy's ID changes on its next publish, so it will need re-uploading then.
moves, keying off the chart's pinned digest rather than the tag. Because the ID
is now content-derived, an unchanged binary keeps its ID and the upload dedupes.
aether-cni, controller and registrar are sixseparate ELFs with six separate IDs; upload each one whose 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