From 1d09248ee5e012e4a4f44a916d20b48ec0370953 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Fri, 9 Mar 2018 15:00:32 +0100 Subject: [PATCH 1/3] runtime/cgo: Add initial NetBSD Thread Sanitizer support Recognize NetBSD in: - go/internal/work/init.go - race.bash - runtime/race/race.go Add __ps_strings symbol in runtime/cgo/netbsd.go as this is used internally in the TSan library for NetBSD and used for ReExec(). Tested on NetBSD/amd64 v. 8.99.12. Around 98% tests are passing for the ./race.bash target. --- src/cmd/go/internal/work/init.go | 4 ++-- src/race.bash | 7 ++++++- src/runtime/cgo/netbsd.go | 2 ++ src/runtime/race/race.go | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 7f894f5c6dce20..1df996352125b8 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -43,8 +43,8 @@ func instrumentInit() { fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch) os.Exit(2) } - if cfg.Goarch != "amd64" || cfg.Goos != "linux" && cfg.Goos != "freebsd" && cfg.Goos != "darwin" && cfg.Goos != "windows" { - fmt.Fprintf(os.Stderr, "go %s: -race and -msan are only supported on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) + if cfg.Goarch != "amd64" || cfg.Goos != "linux" && cfg.Goos != "freebsd" && cfg.Goos != "netbsd" && cfg.Goos != "darwin" && cfg.Goos != "windows" { + fmt.Fprintf(os.Stderr, "go %s: -race and -msan are only supported on linux/amd64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) os.Exit(2) } diff --git a/src/race.bash b/src/race.bash index adf2297c2fd5b0..84b8df24c78747 100755 --- a/src/race.bash +++ b/src/race.bash @@ -9,7 +9,7 @@ set -e function usage { - echo 'race detector is only supported on linux/amd64, freebsd/amd64 and darwin/amd64' 1>&2 + echo 'race detector is only supported on linux/amd64, freebsd/amd64, netbsd/amd64 and darwin/amd64' 1>&2 exit 1 } @@ -30,6 +30,11 @@ case $(uname) in usage fi ;; +"NetBSD") + if [ $(uname -m) != "amd64" ]; then + usage + fi + ;; *) usage ;; diff --git a/src/runtime/cgo/netbsd.go b/src/runtime/cgo/netbsd.go index 2cecd0c57a3620..74d0aed014b251 100644 --- a/src/runtime/cgo/netbsd.go +++ b/src/runtime/cgo/netbsd.go @@ -14,6 +14,8 @@ import _ "unsafe" // for go:linkname //go:linkname _environ environ //go:linkname _progname __progname +//go:linkname ___ps_strings __ps_strings var _environ uintptr var _progname uintptr +var ___ps_strings uintptr diff --git a/src/runtime/race/race.go b/src/runtime/race/race.go index 15e20112a8d36b..ac479fd65aa20b 100644 --- a/src/runtime/race/race.go +++ b/src/runtime/race/race.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build race,linux,amd64 race,freebsd,amd64 race,darwin,amd64 race,windows,amd64 +// +build race,linux,amd64 race,freebsd,amd64 race,netbsd,amd64 race,darwin,amd64 race,windows,amd64 package race From ad2f207a8f4de64fcfa4fdb11017df2239202f2f Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sun, 1 Jul 2018 01:28:12 +0200 Subject: [PATCH 2/3] Update init.go --- src/cmd/go/internal/work/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index f77d23bcc6cece..1556ae0bf7f535 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -48,7 +48,7 @@ func instrumentInit() { 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]) - os.Exit(2) net + os.Exit(2) case "linux/amd64", "linux/ppc64le", "freebsd/amd64", "netbsd/amd64", "darwin/amd64", "windows/amd64": // race supported on these platforms } From d6e082707b9b18df1fe63f723666f4d2eb5e6cfe Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Sun, 1 Jul 2018 01:29:07 +0200 Subject: [PATCH 3/3] Update init.go --- src/cmd/go/internal/work/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 1556ae0bf7f535..608f5648a42c1e 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -47,7 +47,7 @@ func instrumentInit() { platform := 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) case "linux/amd64", "linux/ppc64le", "freebsd/amd64", "netbsd/amd64", "darwin/amd64", "windows/amd64": // race supported on these platforms