build: guard and verify deadcode test-main roots - #2388
Conversation
b6088e6 to
3d026cf
Compare
There was a problem hiding this comment.
Review: guard deadcode pruning when main.main is absent
The guard is small, well-scoped, and correct in intent: when the Go executable entry root is missing from package metadata (as with generated test mains), it skips method pruning rather than emitting a smaller binary that crashes at startup. The helper name reads cleanly, the verbose diagnostic matches the check, and the new tests assert on concrete IR/diagnostic output. Performance and security passes found nothing of concern.
Two substantive points below. Both are non-blocking.
Also worth a brief comment (minor): the guard keys only on main.main while dceEntryRootCandidates seeds both main.init and main.main; and the os.Stderr swap in TestApplyDeadcodeDropOverridesSkipsMissingGoEntryRoot is safe only because no test in this package uses t.Parallel(). Neither needs changing today.
3d026cf to
5a5595f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared with |
Summary
main.mainis absent from package metadata.main.initandmain.mainroots.Motivation
#2370 restored the generated test main to the
mainABI identity. Before that fix, whole-program method analysis could not resolve the executable roots and could remove methods required bytesting.M.Run. The resulting binary was smaller but invalid; the reproducedDustin_humanizebinary crashed at startup withunreachable method called.This PR makes the metadata invariant fail-safe. It also prevents the opposite regression: merely disabling method pruning would retain the dead method and fail the new symbol assertion.
The normal post-#2370 path is unchanged, so this PR is a correctness guard and regression test rather than a size optimization.
Size validation
Published Linux Bent results for
Dustin_humanize:testing.M.RunCorrect test-main deadcode drop removes 1,440,632 B, or 27.5%, relative to disabling deadcode drop. The old result was another 216,848 B smaller only because it removed live code.
For the new regression fixture on macOS arm64:
That is a reduction of 1,192,848 B, or 25.6%. The optimized binary passes, retains the init-only and test-only live methods, and does not contain
deadAnswer.Drop.Testing
go test -tags=dev ./internal/build ./internal/deadcode ./internal/meta -count=1applyDeadcodeDropOverrides91.7%,hasDCEExecutableRoot100%testing.M.Run