Commit c1807989 authored by Daniel Martí's avatar Daniel Martí

cmd/compile: fix racy setting of gc's Config.Race

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: 's avatarDave Cheney <dave@cheney.net>
parent 30d3ebe3
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment