Skip to content

Commit 53aec79

Browse files
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Crawshaw <[email protected]>
1 parent 0631f29 commit 53aec79

File tree

1 file changed

+8
-13
lines changed
  • src/cmd/link/internal/ld

1 file changed

+8
-13
lines changed

src/cmd/link/internal/ld/lib.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -1134,21 +1134,16 @@ func (l *Link) hostlink() {
11341134
}
11351135
}
11361136

1137-
sanitizers := *flagRace
1138-
1139-
for _, flag := range ldflag {
1140-
if strings.HasPrefix(flag, "-fsanitize=") {
1141-
sanitizers = true
1142-
}
1143-
}
1144-
11451137
argv = append(argv, ldflag...)
11461138

1147-
if sanitizers {
1148-
// On a system where the toolchain creates position independent
1149-
// executables by default, tsan/msan/asan/etc initialization can
1150-
// fail. So we pass -no-pie here, but support for that flag is quite
1151-
// new and we test for its support first.
1139+
// When building a program with the default -buildmode=exe the
1140+
// gc compiler generates code requires DT_TEXTREL in a
1141+
// position independent executable (PIE). On systems where the
1142+
// toolchain creates PIEs by default, and where DT_TEXTREL
1143+
// does not work, the resulting programs will not run. See
1144+
// issue #17847. To avoid this problem pass -no-pie to the
1145+
// toolchain if it is supported.
1146+
if Buildmode == BuildmodeExe {
11521147
src := filepath.Join(*flagTmpdir, "trivial.c")
11531148
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
11541149
Errorf(nil, "WriteFile trivial.c failed: %v", err)

0 commit comments

Comments
 (0)