diff --git a/misc/cgo/testsanitizers/msan_fail.go b/misc/cgo/testsanitizers/msan_fail.go index 3be656f0d0b..50379a94d7a 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 8df312ab63d..1ec98aac523 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)