mirror of https://github.com/golang/go.git
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`")
|
flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
|
||||||
objabi.Flagcount("live", "debug liveness analysis", &debuglive)
|
objabi.Flagcount("live", "debug liveness analysis", &debuglive)
|
||||||
objabi.Flagcount("m", "print optimization decisions", &Debug['m'])
|
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(&dolinkobj, "dolinkobj", true, "generate linker-specific objects; if false, some invalid code may compile")
|
||||||
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
||||||
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
||||||
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
|
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
|
||||||
flag.BoolVar(&writearchive, "pack", false, "write to file.a instead of file.o")
|
flag.BoolVar(&writearchive, "pack", false, "write to file.a instead of file.o")
|
||||||
objabi.Flagcount("r", "debug generated wrappers", &Debug['r'])
|
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'])
|
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.StringVar(&pathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
|
||||||
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
|
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
|
||||||
|
|
|
||||||
|
|
@ -705,7 +705,7 @@ func (t *tester) registerTests() {
|
||||||
if gohostos == "linux" && goarch == "amd64" {
|
if gohostos == "linux" && goarch == "amd64" {
|
||||||
t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", "main.go")
|
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", ".")
|
t.registerHostTest("testsanitizers/msan", "../misc/cgo/testsanitizers", "misc/cgo/testsanitizers", ".")
|
||||||
}
|
}
|
||||||
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
|
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
|
||||||
|
|
@ -1329,13 +1329,21 @@ func (t *tester) hasSwig() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tester) raceDetectorSupported() bool {
|
func (t *tester) raceDetectorSupported() bool {
|
||||||
switch gohostos {
|
if gohostos != goos {
|
||||||
case "linux", "darwin", "freebsd", "windows":
|
return false
|
||||||
// The race detector doesn't work on Alpine Linux:
|
|
||||||
// golang.org/issue/14481
|
|
||||||
return t.cgoEnabled && (goarch == "amd64" || goarch == "ppc64le") && gohostos == goos && !isAlpineLinux()
|
|
||||||
}
|
}
|
||||||
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 {
|
func isAlpineLinux() bool {
|
||||||
|
|
@ -1450,3 +1458,26 @@ func (t *tester) packageHasBenchmarks(pkg string) bool {
|
||||||
}
|
}
|
||||||
return false
|
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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"cmd/internal/sys"
|
||||||
"debug/elf"
|
"debug/elf"
|
||||||
"debug/macho"
|
"debug/macho"
|
||||||
"flag"
|
"flag"
|
||||||
|
|
@ -209,15 +210,13 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
testGOCACHE = strings.TrimSpace(string(out))
|
testGOCACHE = strings.TrimSpace(string(out))
|
||||||
|
|
||||||
// As of Sept 2017, MSan is only supported on linux/amd64.
|
canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH)
|
||||||
// https://github.com/google/sanitizers/wiki/MemorySanitizer#getting-memorysanitizer
|
canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
|
||||||
canMSan = canCgo && runtime.GOOS == "linux" && runtime.GOARCH == "amd64"
|
// The race detector doesn't work on Alpine Linux:
|
||||||
|
// golang.org/issue/14481
|
||||||
switch runtime.GOOS {
|
// gccgo does not support the race detector.
|
||||||
case "linux", "darwin", "freebsd", "windows":
|
if isAlpineLinux() || runtime.Compiler == "gccgo" {
|
||||||
// The race detector doesn't work on Alpine Linux:
|
canRace = false
|
||||||
// golang.org/issue/14481
|
|
||||||
canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux() && runtime.Compiler != "gccgo"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't let these environment variables confuse the test.
|
// Don't let these environment variables confuse the test.
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"cmd/go/internal/base"
|
"cmd/go/internal/base"
|
||||||
"cmd/go/internal/cfg"
|
"cmd/go/internal/cfg"
|
||||||
"cmd/go/internal/load"
|
"cmd/go/internal/load"
|
||||||
|
"cmd/internal/sys"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -42,18 +43,14 @@ func instrumentInit() {
|
||||||
fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0])
|
fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0])
|
||||||
os.Exit(2)
|
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)
|
fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
if cfg.BuildRace {
|
if cfg.BuildRace {
|
||||||
platform := cfg.Goos + "/" + cfg.Goarch
|
if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
|
||||||
switch platform {
|
|
||||||
default:
|
|
||||||
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])
|
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)
|
os.Exit(2)
|
||||||
case "linux/amd64", "linux/ppc64le", "freebsd/amd64", "netbsd/amd64", "darwin/amd64", "windows/amd64":
|
|
||||||
// race supported on these platforms
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mode := "race"
|
mode := "race"
|
||||||
|
|
|
||||||
|
|
@ -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
|
// errorcheck -0 -race
|
||||||
|
// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
|
||||||
|
|
||||||
// Copyright 2017 The Go Authors. All rights reserved.
|
// Copyright 2017 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// errorcheck -0 -race
|
// errorcheck -0 -race
|
||||||
|
// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
|
||||||
|
|
||||||
// Copyright 2016 The Go Authors. All rights reserved.
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// errorcheck -0 -race
|
// errorcheck -0 -race
|
||||||
|
// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
|
||||||
|
|
||||||
// Copyright 2016 The Go Authors. All rights reserved.
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// errorcheck -0 -race
|
// errorcheck -0 -race
|
||||||
|
// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
|
||||||
|
|
||||||
// Copyright 2016 The Go Authors. All rights reserved.
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
//errorcheck -0 -race -m -m
|
//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.
|
// Copyright 2018 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue