cmd/go: enable -msan on freebsd/amd64

Enable -msan flag on freebsd/amd64 and amend PIE comment in
internal/work/init.go to indicate that MSAN requires PIE on all platforms
except linux/amd64.

R=go1.20

For #53298

Change-Id: I93d94efa95d7f292c23c433fb1d3f4301d820bde
Reviewed-on: https://go-review.googlesource.com/c/go/+/411275
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Dmitri Goutnik 2022-06-08 10:55:42 -05:00
parent 5fde02e312
commit e56c93f07b
4 changed files with 9 additions and 7 deletions

View file

@ -114,9 +114,9 @@
// linux/ppc64le and linux/arm64 (only for 48-bit VMA).
// -msan
// enable interoperation with memory sanitizer.
// Supported only on linux/amd64, linux/arm64
// Supported only on linux/amd64, linux/arm64, freebsd/amd64
// and only with Clang/LLVM as the host C compiler.
// On linux/arm64, pie build mode will be used.
// PIE build mode will be used on all platforms except linux/amd64.
// -asan
// enable interoperation with address sanitizer.
// Supported only on linux/arm64, linux/amd64.

View file

@ -71,9 +71,9 @@ and test commands:
linux/ppc64le and linux/arm64 (only for 48-bit VMA).
-msan
enable interoperation with memory sanitizer.
Supported only on linux/amd64, linux/arm64
Supported only on linux/amd64, linux/arm64, freebsd/amd64
and only with Clang/LLVM as the host C compiler.
On linux/arm64, pie build mode will be used.
PIE build mode will be used on all platforms except linux/amd64.
-asan
enable interoperation with address sanitizer.
Supported only on linux/arm64, linux/amd64.

View file

@ -149,9 +149,9 @@ func instrumentInit() {
mode := "race"
if cfg.BuildMSan {
mode = "msan"
// MSAN does not support non-PIE binaries on ARM64.
// See issue #33712 for details.
if cfg.Goos == "linux" && cfg.Goarch == "arm64" && cfg.BuildBuildmode == "default" {
// MSAN needs PIE on all platforms except linux/amd64.
// https://github.com/llvm/llvm-project/blob/llvmorg-13.0.1/clang/lib/Driver/SanitizerArgs.cpp#L621
if cfg.BuildBuildmode == "default" && (cfg.Goos != "linux" || cfg.Goarch != "amd64") {
cfg.BuildBuildmode = "pie"
}
}

View file

@ -29,6 +29,8 @@ func MSanSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "arm64"
case "freebsd":
return goarch == "amd64"
default:
return false
}