mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
cmd/compile: only support -race and -msan where they work
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>
This commit is contained in:
parent
d58f3e6fea
commit
7e64377903
|
@ -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")
|
||||
|
|
45
src/cmd/dist/test.go
vendored
45
src/cmd/dist/test.go
vendored
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
29
src/cmd/internal/sys/supported.go
Normal file
29
src/cmd/internal/sys/supported.go
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue