Repository navigation
build: stop passing three linker flags that set nothing - #357
Merged
Merged
Conversation
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
# Conflicts: # CHANGELOG.md
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.
Closes #353.
Makefile'sLDFLAGSinjected-X main.Version,-X main.Commitand-X main.BuildTime. None of those symbols exist —cmd/objectfs/main.godeclares the version as an untyped constant, which the linker cannot rewrite, so all three were accepted and silently ignored: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 threego buildlines 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.ymlalready 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 avar, which contradicts that authority.VERSION,COMMITandBUILD_TIMEremain real Makefile variables —make versionprints 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
--versiondoes not print them, so today it would produce values nothing displays.One correction to this release's own changelog
The
[#198]entry already inUnreleasedsaid 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
grep -rn "main\.Version\|main\.Commit\|main\.BuildTime"across*.go,*.md,Makefile,*.ymlandDockerfilenow returns only prose that explains why the symbols do not exist — no live-Xflag anywhere.markdownlintunchanged on both edited files (CHANGELOG.md361,OBJECTFS.md72).