mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: for -buildmode=exe pass -no-pie to external linker
On some systems the external linker defaults to PIE. On some systems DT_TEXTREL does not work correctly. When both are true we have a bad situation: any Go program built with the default buildmode (exe) that uses external linking will fail to run. Fix this by passing -no-pie to the external linker, if the option is supported. Fixes #17847. Change-Id: I9b5ff97825d8b7f494f96d29c4c04f72b53dbf4e Reviewed-on: https://go-review.googlesource.com/33106 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
0631f292d3
commit
53aec79ce0
1 changed files with 8 additions and 13 deletions
|
|
@ -1134,21 +1134,16 @@ func (l *Link) hostlink() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sanitizers := *flagRace
|
|
||||||
|
|
||||||
for _, flag := range ldflag {
|
|
||||||
if strings.HasPrefix(flag, "-fsanitize=") {
|
|
||||||
sanitizers = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
argv = append(argv, ldflag...)
|
argv = append(argv, ldflag...)
|
||||||
|
|
||||||
if sanitizers {
|
// When building a program with the default -buildmode=exe the
|
||||||
// On a system where the toolchain creates position independent
|
// gc compiler generates code requires DT_TEXTREL in a
|
||||||
// executables by default, tsan/msan/asan/etc initialization can
|
// position independent executable (PIE). On systems where the
|
||||||
// fail. So we pass -no-pie here, but support for that flag is quite
|
// toolchain creates PIEs by default, and where DT_TEXTREL
|
||||||
// new and we test for its support first.
|
// does not work, the resulting programs will not run. See
|
||||||
|
// issue #17847. To avoid this problem pass -no-pie to the
|
||||||
|
// toolchain if it is supported.
|
||||||
|
if Buildmode == BuildmodeExe {
|
||||||
src := filepath.Join(*flagTmpdir, "trivial.c")
|
src := filepath.Join(*flagTmpdir, "trivial.c")
|
||||||
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
|
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
|
||||||
Errorf(nil, "WriteFile trivial.c failed: %v", err)
|
Errorf(nil, "WriteFile trivial.c failed: %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue