]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: pass -no-pie (if supported) when creating a race-enabled executable.
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 26 Apr 2016 09:37:49 +0000 (21:37 +1200)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 26 Apr 2016 21:05:14 +0000 (21:05 +0000)
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: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/lib.go

index f7b9b79c2f78635694da1af57d6205186b4b059e..53428bb1c6f45695119c12958788ada8d4d3cd25 100644 (file)
@@ -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)