mirror of
https://github.com/golang/go
synced 2024-11-12 04:50:21 -07:00
cmd/link: suppress PIE whenever externally linking with a sanitizer
golang.org/issue/15443 complained that a race-enabled PIE binary crashed at startup, but other ways of linking in tsan (or other sanitizers) such as #cgo CFLAGS: -fsanitize=thread #cgo LDFLAGS: -fsanitize=thread have the same problem. Pass -no-pie to the host linker (if supported) if any -fsanitizer=foo cgo LDFLAG is seen when linking. Fixes #15887 Change-Id: Id799770f8d045f6f40fa8c463563937a5748d1a8 Reviewed-on: https://go-review.googlesource.com/23535 Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
2a6544b604
commit
2c1791b13b
@ -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...)
|
argv = append(argv, ldflag...)
|
||||||
|
|
||||||
if flag_race != 0 {
|
if sanitizers {
|
||||||
// On a system where the toolchain creates position independent
|
// On a system where the toolchain creates position independent
|
||||||
// executables by default, tsan initialization can fail. So we pass
|
// executables by default, tsan/msan/asan/etc initialization can
|
||||||
// -no-pie here, but support for that flag is quite new and we test
|
// fail. So we pass -no-pie here, but support for that flag is quite
|
||||||
// for its support first.
|
// new and we test for its support first.
|
||||||
src := filepath.Join(tmpdir, "trivial.c")
|
src := filepath.Join(tmpdir, "trivial.c")
|
||||||
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
|
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
|
||||||
Ctxt.Diag("WriteFile trivial.c failed: %v", err)
|
Ctxt.Diag("WriteFile trivial.c failed: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user