From: Michael Hudson-Doyle Date: Wed, 4 Apr 2018 22:07:41 +0000 (+1200) Subject: [release-branch.go1.10] cmd/link: do not pass -no-pie to host linker when -linkshared... X-Git-Tag: go1.10.2~7 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=abccc7a9b51372c67a0bc60159e8bf43ae77d102;p=gostls13.git [release-branch.go1.10] cmd/link: do not pass -no-pie to host linker when -linkshared is passed As the comment above the code I'm changing says, when building with -buildmode=exe, the default compiler flags produce code incompatible with PIE. But when -linkshared is passed, the default compiler flags are not used so this does not apply. And now I've found a system (linux/arm64 with glibc 2.27) where this combination of flags causes a problem, albeit for reasons I don't really understand, so stop passing -no-pie when -linkshared is passed. Fixes golang/go#24873 Change-Id: I412ec7941dc0cb89e6d1b171fc29288aadcb9f20 Reviewed-on: https://go-review.googlesource.com/104815 Run-TryBot: Michael Hudson-Doyle TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor (cherry picked from commit 2d26a65f8f1a6fcb0948803589061d99b94fa993) Reviewed-on: https://go-review.googlesource.com/110035 Run-TryBot: Andrew Bonventre --- diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 6dcaf64122..8a45825c65 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1265,7 +1265,7 @@ func (ctxt *Link) hostlink() { // 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 ctxt.BuildMode == BuildModeExe { + if ctxt.BuildMode == BuildModeExe && !ctxt.linkShared { src := filepath.Join(*flagTmpdir, "trivial.c") if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil { Errorf(nil, "WriteFile trivial.c failed: %v", err)