]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix racy setting of gc's Config.Race
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 21 Aug 2018 09:26:45 +0000 (10:26 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 21 Aug 2018 12:29:21 +0000 (12:29 +0000)
ssaConfig.Race was being set by many goroutines concurrently, resulting
in a data race seen below. This was very likely introduced by CL 121235.

WARNING: DATA RACE
Write at 0x00c000344408 by goroutine 12:
  cmd/compile/internal/gc.buildssa()
      /workdir/go/src/cmd/compile/internal/gc/ssa.go:134 +0x7a8
  cmd/compile/internal/gc.compileSSA()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:259 +0x5d
  cmd/compile/internal/gc.compileFunctions.func2()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:323 +0x5a

Previous write at 0x00c000344408 by goroutine 11:
  cmd/compile/internal/gc.buildssa()
      /workdir/go/src/cmd/compile/internal/gc/ssa.go:134 +0x7a8
  cmd/compile/internal/gc.compileSSA()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:259 +0x5d
  cmd/compile/internal/gc.compileFunctions.func2()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:323 +0x5a

Goroutine 12 (running) created at:
  cmd/compile/internal/gc.compileFunctions()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:321 +0x39b
  cmd/compile/internal/gc.Main()
      /workdir/go/src/cmd/compile/internal/gc/main.go:651 +0x437d
  main.main()
      /workdir/go/src/cmd/compile/main.go:51 +0x100

Goroutine 11 (running) created at:
  cmd/compile/internal/gc.compileFunctions()
      /workdir/go/src/cmd/compile/internal/gc/pgen.go:321 +0x39b
  cmd/compile/internal/gc.Main()
      /workdir/go/src/cmd/compile/internal/gc/main.go:651 +0x437d
  main.main()
      /workdir/go/src/cmd/compile/main.go:51 +0x100

Instead, set up the field exactly once as part of initssaconfig.

Change-Id: I2c30c6b1cf92b8fd98e7cb5c2e10c526467d0b0a
Reviewed-on: https://go-review.googlesource.com/130375
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
src/cmd/compile/internal/gc/ssa.go

index 199e4d9072944d2f791a7c9d5516dcf7feafb5e7..7b254698b793c30f32a65d0f5465043a39e9c1ee 100644 (file)
@@ -49,6 +49,7 @@ func initssaconfig() {
                ssaConfig.Set387(thearch.Use387)
        }
        ssaConfig.SoftFloat = thearch.SoftFloat
+       ssaConfig.Race = flag_race
        ssaCaches = make([]ssa.Cache, nBackendWorkers)
 
        // Set up some runtime functions we'll need to call.
@@ -131,7 +132,6 @@ func buildssa(fn *Node, worker int) *ssa.Func {
        s.f.Cache = &ssaCaches[worker]
        s.f.Cache.Reset()
        s.f.DebugTest = s.f.DebugHashMatch("GOSSAHASH", name)
-       s.f.Config.Race = flag_race
        s.f.Name = name
        if fn.Func.Pragma&Nosplit != 0 {
                s.f.NoSplit = true