From 23f7398671280c7f2493796f9b22d7bf70fb38d2 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Thu, 8 Aug 2019 01:21:46 +0000 Subject: [PATCH] cmd/go/internal/work: use pie link mode when using MSAN on arm64 Currently, when running the "CC=clang go run -msan misc/cgo/ testsanitizers/testdata/msan.go" command on arm64, it will report an error and the error is reported by llvm/compiler-rt/ lib/msan and it is "Make sure to compile with -fPIE and to link with -pie". This CL fixes this issue, using PIE link mode when using MSAN on arm64. This CL also updates the related document and go build help message. Fixes #33712 Change-Id: I0cc9d95f3fa264d6c042c27a40ccbb82826922fb Reviewed-on: https://go-review.googlesource.com/c/go/+/190482 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot 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 | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index ebbead5d31..2caa8e78f4 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -110,11 +110,13 @@ // The default is the number of CPUs available. // -race // enable data race detection. -// Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64. +// Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64, +// linux/ppc64le and linux/arm64 (only for 48-bit VMA). // -msan // enable interoperation with memory sanitizer. // Supported only on linux/amd64, linux/arm64 // and only with Clang/LLVM as the host C compiler. +// On linux/arm64, pie build mode will be used. // -v // print the names of packages as they are compiled. // -work diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 9305b2d859..9d6fa0c25b 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -62,11 +62,13 @@ and test commands: The default is the number of CPUs available. -race enable data race detection. - Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64. + Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64, + linux/ppc64le and linux/arm64 (only for 48-bit VMA). -msan enable interoperation with memory sanitizer. Supported only on linux/amd64, linux/arm64 and only with Clang/LLVM as the host C compiler. + On linux/arm64, pie build mode will be used. -v print the names of packages as they are compiled. -work diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index c220d87123..548e73515f 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -60,6 +60,11 @@ 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" { + cfg.BuildBuildmode = "pie" + } } modeFlag := "-" + mode