Commit 3a72d626 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/link: pass -no-pie (if supported) when creating a race-enabled executable.

Fixes #15443

Change-Id: Ia3593104fc1a4255926ae5675c25390604b44b7b
Reviewed-on: https://go-review.googlesource.com/22453
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 55154cf0
......@@ -1204,6 +1204,24 @@ func hostlink() {
argv = append(argv, ldflag...)
if flag_race != 0 {
// 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.
src := filepath.Join(tmpdir, "trivial.c")
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
Ctxt.Diag("WriteFile trivial.c failed: %v", err)
}
cmd := exec.Command(argv[0], "-no-pie", "trivial.c")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
supported := err == nil && !bytes.Contains(out, []byte("unrecognized"))
if supported {
argv = append(argv, "-no-pie")
}
}
for _, p := range strings.Fields(extldflags) {
argv = append(argv, p)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment