From 085288e5757769a1070bc5886f986a02ffb77c49 Mon Sep 17 00:00:00 2001 From: wei xiao Date: Fri, 16 Dec 2016 16:47:19 +0800 Subject: [PATCH] Backport of: https://go-review.googlesource.com/#/c/33106/ --- 1.6/alpine/17847.patch | 33 +++++++++++++++++++++++++++++++++ 1.6/alpine/Dockerfile | 3 +++ 1.7/alpine/17847.patch | 33 +++++++++++++++++++++++++++++++++ 1.7/alpine/Dockerfile | 3 +++ 4 files changed, 72 insertions(+) create mode 100644 1.6/alpine/17847.patch create mode 100644 1.7/alpine/17847.patch diff --git a/1.6/alpine/17847.patch b/1.6/alpine/17847.patch new file mode 100644 index 00000000..7fb74f20 --- /dev/null +++ b/1.6/alpine/17847.patch @@ -0,0 +1,33 @@ +diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go +index bdfa056..27c0eda 100644 +--- a/src/cmd/link/internal/ld/lib.go ++++ b/src/cmd/link/internal/ld/lib.go +@@ -1173,6 +1173,28 @@ func hostlink() { + + argv = append(argv, ldflag...) + ++ // When building a program with the default -buildmode=exe the ++ // gc compiler generates code requires DT_TEXTREL in a ++ // position independent executable (PIE). On systems where the ++ // toolchain creates PIEs by default, and where DT_TEXTREL ++ // 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(tmpdir, "trivial.c") ++ if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil { ++ fmt.Errorf("WriteFile trivial.c failed: %v", err) ++ } ++ cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c") ++ cmd.Dir = tmpdir ++ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...) ++ 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) + diff --git a/1.6/alpine/Dockerfile b/1.6/alpine/Dockerfile index 6b522a0b..6ab3a3a2 100644 --- a/1.6/alpine/Dockerfile +++ b/1.6/alpine/Dockerfile @@ -8,6 +8,8 @@ ENV GOLANG_SRC_SHA256 6326aeed5f86cf18f16d6dc831405614f855e2d416a91fd3fdc334f772 # https://golang.org/issue/14851 COPY no-pic.patch / +# https://golang.org/issue/17847 +COPY 17847.patch / RUN set -ex \ && apk add --no-cache --virtual .build-deps \ @@ -25,6 +27,7 @@ RUN set -ex \ && rm golang.tar.gz \ && cd /usr/local/go/src \ && patch -p2 -i /no-pic.patch \ + && patch -p2 -i /17847.patch \ && ./make.bash \ \ && rm -rf /*.patch \ diff --git a/1.7/alpine/17847.patch b/1.7/alpine/17847.patch new file mode 100644 index 00000000..de9c7537 --- /dev/null +++ b/1.7/alpine/17847.patch @@ -0,0 +1,33 @@ +diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go +index 14f4fa9..bf2de57 100644 +--- a/src/cmd/link/internal/ld/lib.go ++++ b/src/cmd/link/internal/ld/lib.go +@@ -1251,6 +1251,28 @@ func hostlink() { + } + } + ++ // When building a program with the default -buildmode=exe the ++ // gc compiler generates code requires DT_TEXTREL in a ++ // position independent executable (PIE). On systems where the ++ // toolchain creates PIEs by default, and where DT_TEXTREL ++ // 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(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], "-c", "-no-pie", "trivial.c") ++ cmd.Dir = tmpdir ++ cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...) ++ 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) + diff --git a/1.7/alpine/Dockerfile b/1.7/alpine/Dockerfile index 279b7c61..b1627d97 100644 --- a/1.7/alpine/Dockerfile +++ b/1.7/alpine/Dockerfile @@ -8,6 +8,8 @@ ENV GOLANG_SRC_SHA256 79430a0027a09b0b3ad57e214c4c1acfdd7af290961dd08d322818895a # https://golang.org/issue/14851 COPY no-pic.patch / +# https://golang.org/issue/17847 +COPY 17847.patch / RUN set -ex \ && apk add --no-cache --virtual .build-deps \ @@ -25,6 +27,7 @@ RUN set -ex \ && rm golang.tar.gz \ && cd /usr/local/go/src \ && patch -p2 -i /no-pic.patch \ + && patch -p2 -i /17847.patch \ && ./make.bash \ \ && rm -rf /*.patch \