1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:50:04 -07:00

cmd/compile: stop race instrumentation from clobbering frame pointer

There is an optimization rule that removes calls to racefuncenter and
racefuncexit, if there are no other race calls in the function. The
rule removes the call to racefuncenter, but it does *not* remove the
store of its argument to the outargs section of the frame. If the
outargs section is now size 0 (because the calls to racefuncenter/exit
were the only calls), then that argument store clobbers the frame
pointer instead.

The fix is to remove the argument store when removing the call to
racefuncenter.  (Racefuncexit doesn't have an argument.)

Change-Id: I183ec4d92bbb4920200e1be27b7b8f66b89a2a0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/248262
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Keith Randall 2020-08-11 13:19:57 -07:00
parent 01f99b4e95
commit 8c39bbf9c9
2 changed files with 10 additions and 1 deletions

View File

@ -42,7 +42,7 @@ var omit_pkgs = []string{
"internal/cpu",
}
// Only insert racefuncenterfp/racefuncexit into the following packages.
// Don't insert racefuncenterfp/racefuncexit into the following packages.
// Memory accesses in the packages are either uninteresting or will cause false positives.
var norace_inst_pkgs = []string{"sync", "sync/atomic"}

View File

@ -1379,6 +1379,15 @@ func needRaceCleanup(sym Sym, v *Value) bool {
}
}
}
if symNamed(sym, "runtime.racefuncenter") {
// If we're removing racefuncenter, remove its argument as well.
if v.Args[0].Op != OpStore {
return false
}
mem := v.Args[0].Args[2]
v.Args[0].reset(OpCopy)
v.Args[0].AddArg(mem)
}
return true
}