]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: only support -race and -msan where they work
authorIan Lance Taylor <iant@golang.org>
Sat, 30 Jun 2018 04:14:47 +0000 (21:14 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 21 Aug 2018 03:38:27 +0000 (03:38 +0000)
Consolidate decision about whether -race and -msan options are
supported in cmd/internal/sys. Use consolidated functions in
cmd/compile and cmd/go. Use a copy of them in cmd/dist; cmd/dist can't
import cmd/internal/sys because Go 1.4 doesn't have it.

Fixes #24315

Change-Id: I9cecaed4895eb1a2a49379b4848db40de66d32a9
Reviewed-on: https://go-review.googlesource.com/121816
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/main.go
src/cmd/dist/test.go
src/cmd/go/go_test.go
src/cmd/go/internal/work/init.go
src/cmd/internal/sys/supported.go [new file with mode: 0644]
test/fixedbugs/issue13265.go
test/fixedbugs/issue15091.go
test/fixedbugs/issue16008.go
test/fixedbugs/issue17449.go
test/fixedbugs/issue24651a.go

index da6f800ccd5d96d1615e377e42f839b6a94544a4..3fd89873d17491fde7257517ea9bd80e5ecd0c69 100644 (file)
@@ -216,14 +216,18 @@ func Main(archInit func(*Arch)) {
        flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
        objabi.Flagcount("live", "debug liveness analysis", &debuglive)
        objabi.Flagcount("m", "print optimization decisions", &Debug['m'])
-       flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
+       if sys.MSanSupported(objabi.GOOS, objabi.GOARCH) {
+               flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
+       }
        flag.BoolVar(&dolinkobj, "dolinkobj", true, "generate linker-specific objects; if false, some invalid code may compile")
        flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
        flag.StringVar(&outfile, "o", "", "write output to `file`")
        flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
        flag.BoolVar(&writearchive, "pack", false, "write to file.a instead of file.o")
        objabi.Flagcount("r", "debug generated wrappers", &Debug['r'])
-       flag.BoolVar(&flag_race, "race", false, "enable race detector")
+       if sys.RaceDetectorSupported(objabi.GOOS, objabi.GOARCH) {
+               flag.BoolVar(&flag_race, "race", false, "enable race detector")
+       }
        objabi.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
        flag.StringVar(&pathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
        flag.BoolVar(&safemode, "u", false, "reject unsafe code")
index 448c7867a143ccb4d05872b7c2777e94bfbd3274..3d0ef284484d4ee87ead449850ece91964eabbab 100644 (file)
@@ -705,7 +705,7 @@ func (t *tester) registerTests() {
                if gohostos == "linux" && goarch == "amd64" {
                        t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", "main.go")
                }
-               if goos == "linux" && (goarch == "amd64" || goarch == "arm64") {
+               if mSanSupported(goos, goarch) {
                        t.registerHostTest("testsanitizers/msan", "../misc/cgo/testsanitizers", "misc/cgo/testsanitizers", ".")
                }
                if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
@@ -1329,13 +1329,21 @@ func (t *tester) hasSwig() bool {
 }
 
 func (t *tester) raceDetectorSupported() bool {
-       switch gohostos {
-       case "linux", "darwin", "freebsd", "windows":
-               // The race detector doesn't work on Alpine Linux:
-               // golang.org/issue/14481
-               return t.cgoEnabled && (goarch == "amd64" || goarch == "ppc64le") && gohostos == goos && !isAlpineLinux()
+       if gohostos != goos {
+               return false
        }
-       return false
+       if !t.cgoEnabled {
+               return false
+       }
+       if !raceDetectorSupported(goos, goarch) {
+               return false
+       }
+       // The race detector doesn't work on Alpine Linux:
+       // golang.org/issue/14481
+       if isAlpineLinux() {
+               return false
+       }
+       return true
 }
 
 func isAlpineLinux() bool {
@@ -1450,3 +1458,26 @@ func (t *tester) packageHasBenchmarks(pkg string) bool {
        }
        return false
 }
+
+// raceDetectorSupported is a copy of the function
+// cmd/internal/sys.RaceDetectorSupported, which can't be used here
+// because cmd/dist has to be buildable by Go 1.4.
+func raceDetectorSupported(goos, goarch string) bool {
+       switch goos {
+       case "linux", "darwin", "freebsd", "netbsd", "windows":
+               return goarch == "amd64" || goarch == "ppc64le"
+       default:
+               return false
+       }
+}
+
+// mSanSupported is a copy of the function cmd/internal/sys.MSanSupported,
+// which can't be used here because cmd/dist has to be buildable by Go 1.4.
+func mSanSupported(goos, goarch string) bool {
+       switch goos {
+       case "linux":
+               return goarch == "amd64" || goarch == "arm64"
+       default:
+               return false
+       }
+}
index ada1ddde3bbb7380657097f2b6c13743aafe22af..6bd0609eaffda6ab0bc65e879ef07d41b307b761 100644 (file)
@@ -6,6 +6,7 @@ package main_test
 
 import (
        "bytes"
+       "cmd/internal/sys"
        "debug/elf"
        "debug/macho"
        "flag"
@@ -209,15 +210,13 @@ func TestMain(m *testing.M) {
                }
                testGOCACHE = strings.TrimSpace(string(out))
 
-               // As of Sept 2017, MSan is only supported on linux/amd64.
-               // https://github.com/google/sanitizers/wiki/MemorySanitizer#getting-memorysanitizer
-               canMSan = canCgo && runtime.GOOS == "linux" && runtime.GOARCH == "amd64"
-
-               switch runtime.GOOS {
-               case "linux", "darwin", "freebsd", "windows":
-                       // The race detector doesn't work on Alpine Linux:
-                       // golang.org/issue/14481
-                       canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux() && runtime.Compiler != "gccgo"
+               canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH)
+               canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
+               // The race detector doesn't work on Alpine Linux:
+               // golang.org/issue/14481
+               // gccgo does not support the race detector.
+               if isAlpineLinux() || runtime.Compiler == "gccgo" {
+                       canRace = false
                }
        }
        // Don't let these environment variables confuse the test.
index eb9981533875706c9b059ad035603747b12239ca..3f6252ed84b7f32ba5bab76cc42b5a6a6f457811 100644 (file)
@@ -10,6 +10,7 @@ import (
        "cmd/go/internal/base"
        "cmd/go/internal/cfg"
        "cmd/go/internal/load"
+       "cmd/internal/sys"
        "flag"
        "fmt"
        "os"
@@ -42,18 +43,14 @@ func instrumentInit() {
                fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0])
                os.Exit(2)
        }
-       if cfg.BuildMSan && (cfg.Goos != "linux" || cfg.Goarch != "amd64" && cfg.Goarch != "arm64") {
+       if cfg.BuildMSan && !sys.MSanSupported(cfg.Goos, cfg.Goarch) {
                fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
                os.Exit(2)
        }
        if cfg.BuildRace {
-               platform := cfg.Goos + "/" + cfg.Goarch
-               switch platform {
-               default:
+               if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
                        fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0])
                        os.Exit(2)
-               case "linux/amd64", "linux/ppc64le", "freebsd/amd64", "netbsd/amd64", "darwin/amd64", "windows/amd64":
-                       // race supported on these platforms
                }
        }
        mode := "race"
diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go
new file mode 100644 (file)
index 0000000..22dec70
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sys
+
+// RaceDetectorSupported reports whether goos/goarch supports the race
+// detector. There is a copy of this function in cmd/dist/test.go.
+func RaceDetectorSupported(goos, goarch string) bool {
+       switch goos {
+       case "linux":
+               return goarch == "amd64" || goarch == "ppc64le"
+       case "darwin", "freebsd", "netbsd", "windows":
+               return goarch == "amd64"
+       default:
+               return false
+       }
+}
+
+// MSanSupported reports whether goos/goarch supports the memory
+// sanitizer option. There is a copy of this function in cmd/dist/test.go.
+func MSanSupported(goos, goarch string) bool {
+       switch goos {
+       case "linux":
+               return goarch == "amd64" || goarch == "arm64"
+       default:
+               return false
+       }
+}
index 3036ba7c24408a3b17f1e9dba9784f3314b72c56..3e16cee6e75a5d06fa7ae785b934be4055b027e5 100644 (file)
@@ -1,4 +1,5 @@
 // errorcheck -0 -race
+// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
 
 // Copyright 2017 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 00fb473d6a27e5004b60c0c2b06b82e80b897078..678e7911c80232437f713df41b768d11b4382151 100644 (file)
@@ -1,4 +1,5 @@
 // errorcheck -0 -race
+// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 0e369efcbbf2aef5ea879e660415c9568ab024e9..45457cdb7f5682e34974bcbb553d902f12cb0bf7 100644 (file)
@@ -1,4 +1,5 @@
 // errorcheck -0 -race
+// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 23029178e8dcf772cb2d981ad0904f35aba87275..51cc8eaa06d855be87902ebb61e525cb016c4b1c 100644 (file)
@@ -1,4 +1,5 @@
 // errorcheck -0 -race
+// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 5f63635a2a81433d4f0158f96a419eb3f3532e95..b12b0cce29b1e40aca6ddb55c67fdec5385837fb 100644 (file)
@@ -1,4 +1,5 @@
 //errorcheck -0 -race -m -m
+// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
 
 // Copyright 2018 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style