go/go/analysis/passes
Keith Randall 3288bc1ea1 go/analysis: add frame pointer check for vet
Our calling convention requires BP to be preserved (it is
callee-save).  But that only happened with the introduction of
framepointers in 1.5. Furthermore, nothing checks it, so there is
assembly from before and since which violates the calling
convention. The frame pointer is not used by Go, but only by kernel
traceback code (for sampled profiling), so no one noticed.  Also, the
frame pointer tends to "fix itself", since after it is clobbered by an
assembly function f, the calling function fixes the frame pointer up
when that function returns.

I've fixed the stdlib, CLs 248260, 248261, 248262.

This CL is a simple check, intended to be used in vet, to catch
assembly that violates the calling convention by overwriting the
frame pointer without saving/restoring it. It is not intended to
catch all violations, just ones that are easy to find.

We look for a write to the frame pointer before any use of the frame
pointer or any control flow instruction. In such a situation, there's
no way the code could restore the value of BP before returning. This
analysis is very conservative; it gives up in lots of cases. False
positive should be very rare, though.

Possible false positives:

 // looks like a write to BP, but isn't.
CMPQ  BP, BP

// BP actually isn't clobbered, just swapped with AX.
XORQ  AX, BP
XORQ  BP, AX
XORQ  AX, BP

The first is unlikely, as it is using the contents of an incoming
register, which is junk. The second is a general problem of op=
assembly operations that are indistiguishable in syntax from =
operations.  But anything other than the swap above also depends on
the incoming junk value in BP. The swap itself is pointless (XCHQ
works better).

Change-Id: Ie9d91ab3396409486f7022380ad46ac76c3fbed4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248686
Trust: Keith Randall <khr@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Keith Randall <khr@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-11-02 19:21:40 +00:00
..
asmdecl go/analysis/passes/asmdecl: permit return jump without writing to results 2020-10-29 13:53:53 +00:00
assign go/analysis/analysistest: expand testing to handle suggested fixes 2020-03-26 19:47:25 +00:00
atomic go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
atomicalign analysis/passes: consolidate imports helper 2020-01-22 00:26:20 +00:00
bools go/analysis/passes: ensure diagnostic-reporting analyses have exported Doc 2019-11-18 20:21:56 +00:00
buildssa go/analysis/passes/nilness: degenerate nil condition checker 2018-10-19 00:59:45 +00:00
buildtag go/analysis: add IgnoredFiles, check ignored files in buildtag check 2020-10-13 17:44:05 +00:00
cgocall analysis/passes: consolidate imports helper 2020-01-22 00:26:20 +00:00
composite go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
copylock go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
ctrlflow go/analysis: handle common nil pointers 2019-08-24 21:01:00 +00:00
deepequalerrors go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
errorsas go/analysis/passes/errorsas: clarify message 2020-03-03 19:44:43 +00:00
findcall go/analysis/analysistest: expand testing to handle suggested fixes 2020-03-26 19:47:25 +00:00
framepointer go/analysis: add frame pointer check for vet 2020-11-02 19:21:40 +00:00
httpresponse analysis/passes: consolidate imports helper 2020-01-22 00:26:20 +00:00
ifaceassert Revert "Revert "go/analysis: add pass to check for impossible interface-to-interface type assertions"" 2020-02-21 22:42:23 +00:00
inspect go/analysis/passes/inspect: fix incorrect example 2019-10-23 14:34:23 +00:00
internal/analysisutil analysis/passes: consolidate imports helper 2020-01-22 00:26:20 +00:00
loopclosure go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
lostcancel go/analysis/passes/lostcancel: fix typo 2019-11-19 22:05:02 +00:00
nilfunc go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
nilness go/analysis/passes/nilness: detecting panic with provably nil values 2020-03-02 15:56:37 +00:00
pkgfact go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
printf go/analysis/passes/printf: allow %O in format strings 2020-05-26 22:44:56 +00:00
shadow go/analysis: add package docs for findcall, printf, and shadow 2019-12-26 23:03:02 +00:00
shift go/analysis/passes: ensure diagnostic-reporting analyses have exported Doc 2019-11-18 20:21:56 +00:00
sortslice go/analysis: add sortslice pass 2019-09-14 23:59:51 +00:00
stdmethods go/analysis: rename reportNodef to ReportRangef 2019-10-28 19:16:33 +00:00
stringintconv go/analysis: improve error message for string(int) warning 2020-06-16 13:34:36 +00:00
structtag go/analysis/passes/structtag: ignore warning if tag should be ignored 2020-08-10 15:05:53 +00:00
testinggoroutine analysis/passes: consolidate imports helper 2020-01-22 00:26:20 +00:00
tests go/analysis/passes/tests: add pointer to where test name conventions are specified 2019-05-29 20:33:03 +00:00
unmarshal go/analysis/passes/unmarshal: Add check for asn1.Unmarshal 2020-07-22 15:42:47 +00:00
unreachable go/analysis/passes/unreachable: add suggested-fix to remove dead code 2020-03-27 18:58:09 +00:00
unsafeptr x/tools/go/analysis/passes/unsafeptr: report Header misuse 2020-10-16 18:50:37 +00:00
unusedresult unusedresult.go: Include context.With* functions 2020-09-01 15:31:17 +00:00
README go/analysis/internal/checker: analysis driver based on go/packages 2018-09-26 01:25:07 +00:00

README

This directory does not contain a Go package,
but acts as a container for various analyses
that implement the golang.org/x/tools/go/analysis
API and may be imported into an analysis tool.

By convention, each package foo provides the analysis,
and each command foo/cmd/foo provides a standalone driver.