From e56c93f07b445d1c123b1c46483db2d214af8cc3 Mon Sep 17 00:00:00 2001 From: Dmitri Goutnik Date: Wed, 8 Jun 2022 10:55:42 -0500 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor --- src/cmd/go/alldocs.go | 4 ++-- src/cmd/go/internal/work/build.go | 4 ++-- src/cmd/go/internal/work/init.go | 6 +++--- src/internal/platform/supported.go | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 6a348dbb75..a8206c475c 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -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. diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 6a83ec6232..d27d114d91 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -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. diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 458a81bead..cfd5a505d3 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -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" } } diff --git a/src/internal/platform/supported.go b/src/internal/platform/supported.go index c9264c03ee..fddc544123 100644 --- a/src/internal/platform/supported.go +++ b/src/internal/platform/supported.go @@ -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 } -- 2.50.0