]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: stop race instrumentation from clobbering frame pointer
authorKeith Randall <khr@golang.org>
Tue, 11 Aug 2020 20:19:57 +0000 (13:19 -0700)
committerKeith Randall <khr@golang.org>
Sun, 16 Aug 2020 17:05:44 +0000 (17:05 +0000)
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>

src/cmd/compile/internal/gc/racewalk.go
src/cmd/compile/internal/ssa/rewrite.go

index 6f251377c94ea7f215464afcf5ea75de5280d676..35526174010fa361be76e2938900cc2c5067aa80 100644 (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"}
 
index 2152b1675ad23fa64f5569665fbdf2767313d763..e082bb1dfa2f0da087bdc1a4d3952cdcf16cfaa4 100644 (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
 }