From 029c760c7be0d11563ac69fbc0ca5fd98a5cbc2b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 21 Oct 2015 15:18:52 -0700 Subject: [PATCH] cmd/go: if -msan, pass -fsanitize=memory to cgo builds Also fix the msan_fail test. It was bogus, since it always aborted one way or another. Change-Id: Ic693327d1bddb7bc5c7d859ac047fc93cb9b5b1c Reviewed-on: https://go-review.googlesource.com/16172 Reviewed-by: David Crawshaw Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- misc/cgo/testsanitizers/msan_fail.go | 3 ++- src/cmd/go/build.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/misc/cgo/testsanitizers/msan_fail.go b/misc/cgo/testsanitizers/msan_fail.go index 3be656f0d0..50379a94d7 100644 --- a/misc/cgo/testsanitizers/msan_fail.go +++ b/misc/cgo/testsanitizers/msan_fail.go @@ -13,7 +13,8 @@ void f(int32_t *p, int n) { void g(int32_t *p, int n) { if (p[4] != 1) { - abort(); + // We shouldn't get here; msan should stop us first. + exit(0); } } */ diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 8df312ab63..1ec98aac52 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -2893,6 +2893,11 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi cgoLDFLAGS = append(cgoLDFLAGS, "-lobjc") } + if buildMSan && p.ImportPath != "runtime/cgo" { + cgoCFLAGS = append([]string{"-fsanitize=memory"}, cgoCFLAGS...) + cgoLDFLAGS = append([]string{"-fsanitize=memory"}, cgoLDFLAGS...) + } + // Allows including _cgo_export.h from .[ch] files in the package. cgoCPPFLAGS = append(cgoCPPFLAGS, "-I", obj) -- 2.50.0