]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: if -msan, pass -fsanitize=memory to cgo builds
authorIan Lance Taylor <iant@golang.org>
Wed, 21 Oct 2015 22:18:52 +0000 (15:18 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 21 Oct 2015 23:52:23 +0000 (23:52 +0000)
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 <crawshaw@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/testsanitizers/msan_fail.go
src/cmd/go/build.go

index 3be656f0d0ba9216cde219bcc2a002293c344439..50379a94d7ab5f229c92f222fa4b4a50ef3a2bb1 100644 (file)
@@ -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);
   }
 }
 */
index 8df312ab63d1e28834efaad614c5f07ff5020b4a..1ec98aac523529163a4e5f4c33028d5777e622c0 100644 (file)
@@ -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)