diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index ded5ac6de08..14f4fa9aad1 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1222,13 +1222,21 @@ func hostlink() { } } + sanitizers := flag_race != 0 + + for _, flag := range ldflag { + if strings.HasPrefix(flag, "-fsanitize=") { + sanitizers = true + } + } + argv = append(argv, ldflag...) - if flag_race != 0 { + if sanitizers { // On a system where the toolchain creates position independent - // executables by default, tsan initialization can fail. So we pass - // -no-pie here, but support for that flag is quite new and we test - // for its support first. + // executables by default, tsan/msan/asan/etc initialization can + // fail. So we pass -no-pie here, but support for that flag is quite + // new and we test for its support first. src := filepath.Join(tmpdir, "trivial.c") if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil { Ctxt.Diag("WriteFile trivial.c failed: %v", err)