]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make GOSSAHASH package-sensitive, also append to log files
authorDavid Chase <drchase@google.com>
Wed, 5 Aug 2020 14:26:57 +0000 (10:26 -0400)
committerDavid Chase <drchase@google.com>
Mon, 24 Aug 2020 02:38:18 +0000 (02:38 +0000)
Turns out if your failure is in a function with a name like "Reset()"
there will be a lot of hits on the same hashcode.  Adding package sensitivity
solves this problem.

In additionm, it turned out that in the case that a logfile was specified
for the GOSSAHASH logging, that it was opened in create mode, which meant
that multiple compiler invocations would reset the file to zero length.
Opening in append mode works better; the automated harness
(github.com/dr2chase/gossahash) takes care of truncating the file before use.

Change-Id: I5601bc280faa94cbd507d302448831849db6c842
Reviewed-on: https://go-review.googlesource.com/c/go/+/246937
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/func.go

index 956569b86f379d9af03ff8549250a1f36877b218..c8fb013ad0a021b3dec61d8ff2d5156a55920f6d 100644 (file)
@@ -329,8 +329,8 @@ func buildssa(fn *Node, worker int) *ssa.Func {
        s.f.Config = ssaConfig
        s.f.Cache = &ssaCaches[worker]
        s.f.Cache.Reset()
-       s.f.DebugTest = s.f.DebugHashMatch("GOSSAHASH", name)
        s.f.Name = name
+       s.f.DebugTest = s.f.DebugHashMatch("GOSSAHASH")
        s.f.PrintOrHtmlSSA = printssa
        if fn.Func.Pragma&Nosplit != 0 {
                s.f.NoSplit = true
@@ -6863,6 +6863,10 @@ func (e *ssafn) SetWBPos(pos src.XPos) {
        e.curfn.Func.setWBPos(pos)
 }
 
+func (e *ssafn) MyImportPath() string {
+       return myimportpath
+}
+
 func (n *Node) Typ() *types.Type {
        return n.Type
 }
index fdff3bbdeb2508ab5090f2e679a3c7ee98ea6d92..4b2f06def11ff689186f3af5af788cd7269bfe7f 100644 (file)
@@ -173,6 +173,9 @@ type Frontend interface {
        // SetWBPos indicates that a write barrier has been inserted
        // in this function at position pos.
        SetWBPos(pos src.XPos)
+
+       // MyImportPath provides the import name (roughly, the package) for the function being compiled.
+       MyImportPath() string
 }
 
 // interface used to hold a *gc.Node (a stack variable).
index a94cce48a41408133d97165cb6b2bd336c1be59e..51665c60e2783b2212ab49c031ccf57a1f3e69ab 100644 (file)
@@ -146,6 +146,10 @@ func (d DummyFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t
 func (d DummyFrontend) Warnl(_ src.XPos, msg string, args ...interface{})  { d.t.Logf(msg, args...) }
 func (d DummyFrontend) Debug_checknil() bool                               { return false }
 
+func (d DummyFrontend) MyImportPath() string {
+       return "my/import/path"
+}
+
 var dummyTypes Types
 
 func init() {
index 9e40b6214c140cfa8a25985753b2c918918aa433..6718b778e1d73549764c211d235eb0cbb254120b 100644 (file)
@@ -678,7 +678,8 @@ func (f *Func) invalidateCFG() {
 //  GSHS_LOGFILE
 // or standard out if that is empty or there is an error
 // opening the file.
-func (f *Func) DebugHashMatch(evname, name string) bool {
+func (f *Func) DebugHashMatch(evname string) bool {
+       name := f.fe.MyImportPath() + "." + f.Name
        evhash := os.Getenv(evname)
        switch evhash {
        case "":
@@ -727,7 +728,7 @@ func (f *Func) logDebugHashMatch(evname, name string) {
                file = os.Stdout
                if tmpfile := os.Getenv("GSHS_LOGFILE"); tmpfile != "" {
                        var err error
-                       file, err = os.Create(tmpfile)
+                       file, err = os.OpenFile(tmpfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
                        if err != nil {
                                f.Fatalf("could not open hash-testing logfile %s", tmpfile)
                        }