Skip to content

fix(build): stamp the GNU build-ID with the release commit SHA (#651) - #652

Merged
bpalermo merged 2 commits into
mainfrom
fix/651-stamped-build-id
Sep 1, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/651-stamped-build-id

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

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.

  • A 20-byte git commit SHA-1 is exactly the width of a GNU build-ID descriptor, so it drops in without changing the ELF layout.
  • It matches upstream Envoy's own convention — every stock Envoy in the fleet carries a 20-byte sha1 equal to its source SHA — and it's the mechanism Envoy already ships (envoy_cc_binary(stamped = True)).
  • Symbol uploads become keyed by a value you can look up: given a build-ID from a flamegraph you know the exact commit, and given a release you know what to upload, without needing the artifact in hand.

Mechanism

Go binaries (//tools/buildid). rules_go links 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, hence the constant 498919af… note on every binary the repo has ever produced. rules_go does not stamp-expand gc_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.sh gains STABLE_GIT_COMMIT (stable, so it is cache-key material — the volatile GIT_COMMIT stays 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-id descriptor and overwrites its 20 bytes with the commit. Nothing else in the image moves — verified byte-for-byte in a unit test.
  • It reads ctx.info_file (stable-status.txt), not ctx.version_file (that one is volatile and would let a stale build-ID survive a cache hit).
  • bazel/img/go_multi_arch_image.bzl pipes 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-cni is 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_status already emits BUILD_SCM_REVISION as git rev-parse HEAD, so no new plumbing. This replaces the toolchain's implicit 16-byte md5 uuid. It 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.

Guarantees

  1. Two different commits ⇒ two different build-IDs. Demonstrated below across three successive local commits.
  2. Rebuilding the same commit ⇒ the same build-ID. The id comes from the stable status, so the remote cache stays warm; a new commit re-runs only the ~1 s copy action, never a compile or a link.
  3. Non-stamped builds keep working. Everything is gated on a --stamp config_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 run and bazel test are unchanged. The tool also copies unchanged when the status has no resolvable commit or the input isn't an ELF at all.
  4. Remote-cache friendly. ctx.info_file is 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 of bazel build //..., so bazel-diff picks it up on any PR that touches those binaries, and publish.yaml re-states it under --stamp and prints the per-binary report.
  • //integration:build_id_test (proxy) — asserts the linked Envoy's .note.gnu.build-id equals the id the linker was handed. Reads the note with od + awk so it needs no binutils on the runner or the RBE executor, and costs no extra compile (//:envoy is 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-id for the same check locally.

Validation

Go side — fully validated locally. readelf -n on a --stamp build:

$ git rev-parse HEAD
e84ad3b74dd023bbaeb6c3a28382e59deed07a73

$ readelf -n bazel-bin/agent/cmd/agent/agent_image_stamped_binary
Displaying notes found in: .note.gnu.build-id
  GNU  0x00000014  NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: e84ad3b74dd023bbaeb6c3a28382e59deed07a73

$ readelf -n bazel-bin/agent/cmd/agent/agent_/agent    # the unstamped go_binary
    Build ID: 498919aff001d8366249403a2544fba2d833084f

Guarantee 1 across three successive commits on this branch — aaae36d3… → 06643598… → e84ad3b7…, each time equal to HEAD, while the unstamped binary stayed 498919af….

Extracted from the actual image layers (cni-install, both ELFs):

ex/cni-install:             Build ID: <release commit>
ex/opt/cni/bin/aether-cni:  Build ID: <release commit>

bazel test //... (unit + container-structure) green; --config=lint green; gazelle and make format clean.

Proxy side — mechanism validated structurally, no full Envoy compile (that is a multi-hour build; deliberately not run):

  • bazel aquery 'mnemonic("CppLink", //:envoy)' in proxy/ 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.ldscript produces --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.
  • The linker semantics were confirmed independently: linking a trivial program with -Wl,@<that ldscript> yields Build ID: <the commit> verbatim.
  • //integration:build_id_test analyzes cleanly (bazel cquery --output=build), and the $(rootpath …) → runfiles-cwd contract it relies on was proven with a throwaway sh_test in the same workspace (since removed).
  • check_build_id.sh itself 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_test runs 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:

  • The old debuginfo for 498919af… was already deleted from Pyroscope (it would have served wrong offsets); nothing to clean up.
  • The agent binary can be uploaded again. Per the standing procedure, re-upload only when an image digest actually moves (images publish only when their Bazel deps change), keying off the chart's pinned digest, not the tag:
cid=$(docker create --platform linux/arm64 <image@digest>); docker cp $cid:<path> ./bin; docker rm $cid
kubectl -n o11y port-forward svc/pyroscope 14040:4040 &
docker run --rm --network host -v $PWD:/w --entrypoint profilecli grafana/pyroscope:2.2.1 \
  debuginfo upload --url=http://127.0.0.1:14040 /w/bin      # idempotent; `debuginfo list` to verify
  • One agent-binary upload still covers agent / supervisor / mesh-dns comms (one multi-call ELF), but the standalone mesh-dns image and the cni plugin are separate ELFs with their own build-IDs — upload them separately if their native frames matter.
  • The proxy's build-ID changes shape (16-byte md5 → 20-byte commit sha1) on its next publish, so its existing upload will no longer match and must be re-done then.
  • Uploads are now safe: a stale upload can no longer shadow a newer build, because the IDs differ.

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

bpalermo and others added 2 commits August 31, 2026 09:03
…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
bpalermo merged commit 4aabff2 into main Sep 1, 2026
17 checks passed
@bpalermo
bpalermo deleted the fix/651-stamped-build-id branch September 1, 2026 00:03
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent binary GNU build-ID is constant across different builds — breaks profile symbolization by build-ID

1 participant