Skip to content

build: stop passing three linker flags that set nothing - #357

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/dead-ldflags-353
Aug 5, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/dead-ldflags-353

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #353.

Makefile's LDFLAGS injected -X main.Version, -X main.Commit and -X main.BuildTime. None of those symbols exist — cmd/objectfs/main.go declares the version as an untyped constant, which the linker cannot rewrite, so all three were accepted and silently ignored:

$ go build -ldflags="-s -w -X main.Version=FAKE-VERSION" -o /tmp/probe ./cmd/objectfs
$ /tmp/probe --version
objectfs version 0.11.0

Six targets share that variable — build, build-all, build-linux, build-darwin, install, package — so each passed three dead symbols. OBJECTFS.md's build-configuration example showed the same injection, and its three go build lines targeted . rather than ./cmd/objectfs, which is not a main package and would not have built as written; both are corrected.

Why dropped rather than made real

This is the choice .github/workflows/release.yml already made, and explains at its build step: the constant is the documented single authority for the version (CLAUDE.md), so a release asserts that it and the git tag agree rather than overwriting it at link time and leaving the source disagreeing with the shipped artifact. Making the flags work would mean moving the version to a var, which contradicts that authority.

VERSION, COMMIT and BUILD_TIME remain real Makefile variables — make version prints all three and the packaging targets name archives with them. They just do not reach the binary, and no comment now claims they do.

Whether the binary should report its commit and build time at all is left open as a separate question. Neither has a constant to disagree with, so there is a genuine argument for injecting those two — but --version does not print them, so today it would produce values nothing displays.

One correction to this release's own changelog

The [#198] entry already in Unreleased said these two copies "survive" and were filed rather than fixed. This PR makes that false, so it now points at the new entry instead of contradicting it in the same section.

Verification

$ make build && ./bin/objectfs --version
objectfs version 0.11.0
$ make version
Version: v0.11.0-55-g90e951a-dirty
Commit: 90e951a
Build Time: 2026-08-05_03:41:01AM

grep -rn "main\.Version\|main\.Commit\|main\.BuildTime" across *.go, *.md, Makefile, *.yml and Dockerfile now returns only prose that explains why the symbols do not exist — no live -X flag anywhere. markdownlint unchanged on both edited files (CHANGELOG.md 361, OBJECTFS.md 72).

Makefile's LDFLAGS injected -X main.Version, -X main.Commit and
-X main.BuildTime. None of those symbols exist. cmd/objectfs/main.go
declares the version as an untyped constant, and the linker cannot rewrite
a constant, so all three were accepted and silently ignored:

  $ go build -ldflags="-s -w -X main.Version=FAKE-VERSION" \
      -o /tmp/probe ./cmd/objectfs
  $ /tmp/probe --version
  objectfs version 0.11.0

Six targets share that variable — build, build-all, build-linux,
build-darwin, install and package — so each passed three dead symbols.
OBJECTFS.md's build-configuration example showed the same injection, and
its three `go build` lines targeted `.` rather than ./cmd/objectfs, which
is not a main package and would not have built as written.

Dropped rather than made real. That is the choice release.yml already made
and explains at its build step: the constant is the documented single
authority for the version, so a release should assert that it and the git
tag agree rather than overwrite it at link time and leave the source
disagreeing with the artifact. Making the flags work would mean moving the
version to a var, which contradicts that authority.

VERSION, COMMIT and BUILD_TIME remain real Makefile variables. `make
version` prints all three and the packaging targets name archives with
them; they just do not reach the binary, and no comment now claims they
do. Verified: make build succeeds, ./bin/objectfs --version reports the
constant, make version prints all three.

The #198 entry already in this release's changelog said these two copies
"survive" and were filed rather than fixed. That is no longer true, so it
is corrected to point at the entry above rather than left contradicting
it in the same section.

Whether the binary should report its commit and build time at all is a
separate question, left open: neither has a constant to disagree with, so
there is a real argument for injecting those two — but --version does not
print them, so today it would produce values nothing displays.

Closes #353
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: low Nice to have, low urgency area: build Build system, compilation, packaging labels Aug 5, 2026
@scttfrdmn scttfrdmn added this to the Future Work milestone Aug 5, 2026
@scttfrdmn scttfrdmn added area: docs Documentation content and structure effort: xs Extra small effort - <2 hours labels Aug 5, 2026
@scttfrdmn
scttfrdmn merged commit 55e8249 into main Aug 5, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the fix/dead-ldflags-353 branch August 5, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build system, compilation, packaging area: docs Documentation content and structure effort: xs Extra small effort - <2 hours priority: low Nice to have, low urgency type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: Makefile and OBJECTFS.md inject a main.Version that does not exist

1 participant