mirror of
https://github.com/golang/go
synced 2024-11-23 22:00:11 -07:00
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: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
55154cf0b2
commit
3a72d626a8
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user