tests, tools: every inline-asm LVO call lists all four scratch registers; CI gate (#70) - #86
Merged
Merged
Conversation
…ers; CI gate (#70) An LVO may destroy d0, d1, a0 and a1. An extended asm statement that lists one of them only as an input lets GCC reuse a value the call has overwritten, which is how #68 passed a stale recvfrom address. tools/check-lvo-clobbers.sh (python in check-lvo-clobbers.py) scans src/ and tests/ for asm statements whose template calls through a6 and reports each one whose outputs and clobbers leave out a scratch register. It reads register declarations through object-like macros (BSD_SCRATCH, NETDEV_REG_A1) from the file and its "..." includes, and skips top-level asm. Output is key=value, exit 1 on any site. It is wired into stage_host next to check-lvo-matrix.sh, registered in check-gates-wired.sh, and added to the shellcheck list. Validation: 58c5c4f (the tree the issue scanned): 415 statements, 31 flagged. All 16 shipped sites match the issue's missing sets exactly, and tests/sockopt/sockopt_test.c:332 (pre-#68) is flagged missing=a1. src/tools/toolsock.c alone: 22 statements, 0 flagged. The issue's 77 included 46 false positives: 43 BSD_SCRATCH macro sites, apidrill's TH() macro, and the top-level asm in genet.c and netdev_cache.c. The 14 real test sites on main are fixed: a register that is also an input becomes an output (dummy "=r", or "+r" as in #71), one that is not becomes a clobber. udpdrill's recvfrom and getsockopt helpers had the #68 shape (a1). before (7fa3df3): statements=415 files=50 flagged=14 after: statements=415 files=50 flagged=0 Fixes #70 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #70
Steps 2 and 3 of #70: the scanner is a CI gate, and the remaining test sites are fixed.
Gate.
tools/check-lvo-clobbers.shrunstools/check-lvo-clobbers.pyover src/ and tests/. It flags every extended asm statement that calls through a6 and does not list d0, d1, a0 and a1 as outputs or clobbers. It reads register declarations through object-like macros (BSD_SCRATCH,NETDEV_REG_A1) from the file and from its"..."includes, and it skips top-level asm. Output is key=value, and the exit code is 1 on any flagged site. The gate runs instage_hostnext tocheck-lvo-matrix.sh, is registered incheck-gates-wired.sh, and is on the shellcheck list.Validation
src/tools/toolsock.calonetests/sockopt/sockopt_test.c:332(pre-sockopt_test: the recvfrom helper declares a1 clobbered #68) is flaggedmissing=a1.BSD_SCRATCHmacro sites in ipv6_socket_test, sockopt_test and udpdrillTH()macro, which lists all eight registersFixes (14 test sites). A missing register that is also an input becomes an output: a dummy
"=r", or"+r"as in #71. A missing register that is not an input becomes a clobber.Repro:
tools/check-lvo-clobbers.sh; echo $?🤖 Generated with Claude Code